OSDN Git Service

Add Plugin API for controling the device power states
authorDerek Sollenberger <djsollen@google.com>
Thu, 27 Jan 2011 22:28:03 +0000 (17:28 -0500)
committerandroid-merger <android-build@android.com>
Fri, 28 Jan 2011 00:53:20 +0000 (16:53 -0800)
This is an initial API that will allow the plugin to request to
keep the screen on.

companion change is in frameworks/base

bug: 3331493
Change-Id: Id807dc3a3e5aaf12fc63558edeceee0d35561768

WebCore/plugins/android/PluginViewAndroid.cpp
WebKit/android/jni/WebViewCore.cpp
WebKit/android/jni/WebViewCore.h
WebKit/android/plugins/ANPSystemInterface.cpp
WebKit/android/plugins/ANPSystem_npapi.h
WebKit/android/plugins/PluginWidgetAndroid.cpp
WebKit/android/plugins/PluginWidgetAndroid.h
WebKit/android/plugins/android_npapi.h

index 122404a..b9d7a4f 100644 (file)
@@ -107,6 +107,7 @@ extern void ANPTypefaceInterfaceV0_Init(ANPInterface* value);
 extern void ANPWindowInterfaceV0_Init(ANPInterface* value);
 extern void ANPWindowInterfaceV1_Init(ANPInterface* value);
 extern void ANPSystemInterfaceV0_Init(ANPInterface* value);
+extern void ANPSystemInterfaceV1_Init(ANPInterface* value);
 extern void ANPOpenGLInterfaceV0_Init(ANPInterface* value);
 extern void ANPVideoInterfaceV0_Init(ANPInterface* value);
 
@@ -134,6 +135,7 @@ static const VarProcPair gVarProcs[] = {
     { VARPROCLINE(WindowInterfaceV0)        },
     { VARPROCLINE(WindowInterfaceV1)        },
     { VARPROCLINE(SystemInterfaceV0)        },
+    { VARPROCLINE(SystemInterfaceV1)        },
     { VARPROCLINE(OpenGLInterfaceV0)        },
     { VARPROCLINE(VideoInterfaceV0)         },
 };
index 0163376..6ba8276 100644 (file)
@@ -291,6 +291,7 @@ struct WebViewCore::JavaGlue {
     jmethodID   m_updateSurface;
     jmethodID   m_destroySurface;
     jmethodID   m_getContext;
+    jmethodID   m_keepScreenOn;
     jmethodID   m_sendFindAgain;
     jmethodID   m_showRect;
     jmethodID   m_centerFitRect;
@@ -340,6 +341,7 @@ WebViewCore::WebViewCore(JNIEnv* env, jobject javaWebViewCore, WebCore::Frame* m
     m_forwardingTouchEvents = false;
 #endif
     m_isPaused = false;
+    m_screenOnCounter = 0;
 
     LOG_ASSERT(m_mainFrame, "Uh oh, somehow a frameview was made without an initial frame!");
 
@@ -387,6 +389,7 @@ WebViewCore::WebViewCore(JNIEnv* env, jobject javaWebViewCore, WebCore::Frame* m
     m_javaGlue->m_updateSurface = GetJMethod(env, clazz, "updateSurface", "(Landroid/webkit/ViewManager$ChildView;IIII)V");
     m_javaGlue->m_destroySurface = GetJMethod(env, clazz, "destroySurface", "(Landroid/webkit/ViewManager$ChildView;)V");
     m_javaGlue->m_getContext = GetJMethod(env, clazz, "getContext", "()Landroid/content/Context;");
+    m_javaGlue->m_keepScreenOn = GetJMethod(env, clazz, "keepScreenOn", "(Z)V");
     m_javaGlue->m_sendFindAgain = GetJMethod(env, clazz, "sendFindAgain", "()V");
     m_javaGlue->m_showRect = GetJMethod(env, clazz, "showRect", "(IIIIIIFFFF)V");
     m_javaGlue->m_centerFitRect = GetJMethod(env, clazz, "centerFitRect", "(IIII)V");
@@ -3710,6 +3713,20 @@ jobject WebViewCore::getContext()
     return result;
 }
 
+void WebViewCore::keepScreenOn(bool screenOn) {
+    if ((screenOn && m_screenOnCounter == 0) || (!screenOn && m_screenOnCounter == 1)) {
+        JNIEnv* env = JSC::Bindings::getJNIEnv();
+        env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_keepScreenOn, screenOn);
+        checkException(env);
+    }
+
+    // update the counter
+    if (screenOn)
+        m_screenOnCounter++;
+    else if (m_screenOnCounter > 0)
+        m_screenOnCounter--;
+}
+
 bool WebViewCore::validNodeAndBounds(Frame* frame, Node* node,
     const IntRect& originalAbsoluteBounds)
 {
index 028a0c7..4357165 100644 (file)
@@ -499,6 +499,9 @@ namespace android {
         // Returns the context (android.content.Context) of the WebView
         jobject getContext();
 
+        // Manages requests to keep the screen on while the WebView is visible
+        void keepScreenOn(bool screenOn);
+
         bool validNodeAndBounds(Frame* , Node* , const IntRect& );
 
         // Make the rect (left, top, width, height) visible. If it can be fully
@@ -643,6 +646,7 @@ namespace android {
         void pluginInvalTimerFired(WebCore::Timer<WebViewCore>*) {
             this->drawPlugins();
         }
+        int m_screenOnCounter;
 
         void doMaxScroll(CacheBuilder::Direction dir);
         SkPicture* rebuildPicture(const SkIRect& inval);
index 959b93d..8510c2e 100644 (file)
@@ -82,6 +82,13 @@ static jclass anp_loadJavaClass(NPP instance, const char* className) {
     return result;
 }
 
+static void anp_setPowerState(NPP instance, ANPPowerState powerState) {
+    WebCore::PluginView* pluginView = pluginViewForInstance(instance);
+    PluginWidgetAndroid* pluginWidget = pluginView->platformPluginWidget();
+
+    pluginWidget->setPowerState(powerState);
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 
 #define ASSIGN(obj, name)   (obj)->name = anp_##name
@@ -92,3 +99,11 @@ void ANPSystemInterfaceV0_Init(ANPInterface* v) {
     ASSIGN(i, getApplicationDataDirectory);
     ASSIGN(i, loadJavaClass);
 }
+
+void ANPSystemInterfaceV1_Init(ANPInterface* v) {
+    // initialize the functions from the previous interface
+    ANPSystemInterfaceV0_Init(v);
+    // add any new functions or override existing functions
+    ANPSystemInterfaceV1* i = reinterpret_cast<ANPSystemInterfaceV1*>(v);
+    ASSIGN(i, setPowerState);
+}
index 6a102a7..5d91cfb 100644 (file)
@@ -47,4 +47,14 @@ struct ANPSystemInterfaceV0 : ANPInterface {
     jclass (*loadJavaClass)(NPP instance, const char* className);
 };
 
+enum ANPPowerStates {
+    kDefault_ANPPowerState  = 0,
+    kScreenOn_ANPPowerState = 1
+};
+typedef int32_t ANPPowerState;
+
+struct ANPSystemInterfaceV1 : ANPSystemInterfaceV0 {
+    void (*setPowerState)(NPP instance, ANPPowerState powerState);
+};
+
 #endif //ANPSystem_npapi_H
index 73fe18a..4dc12a3 100644 (file)
@@ -72,12 +72,14 @@ PluginWidgetAndroid::PluginWidgetAndroid(WebCore::PluginView* view)
     m_acceptEvents = false;
     m_isSurfaceClippedOut = false;
     m_layer = 0;
+    m_powerState = kDefault_ANPPowerState;
 }
 
 PluginWidgetAndroid::~PluginWidgetAndroid() {
     PLUGIN_LOG("%p Deleting Plugin", m_pluginView->instance());
     m_acceptEvents = false;
     if (m_core) {
+        setPowerState(kDefault_ANPPowerState);
         m_core->removePlugin(this);
         if (m_isFullScreen) {
             exitFullScreen(true);
@@ -635,3 +637,28 @@ void PluginWidgetAndroid::requestCenterFitZoom() {
             m_pluginWindow->width, m_pluginWindow->height);
 }
 
+void PluginWidgetAndroid::setPowerState(ANPPowerState powerState) {
+    if(m_powerState == powerState)
+        return;
+
+    // cleanup the old power state
+    switch (m_powerState) {
+        case kDefault_ANPPowerState:
+            break;
+        case kScreenOn_ANPPowerState:
+            m_core->keepScreenOn(false);
+            break;
+    }
+
+    // setup the new power state
+    switch (powerState) {
+        case kDefault_ANPPowerState:
+            break;
+        case kScreenOn_ANPPowerState:
+            m_core->keepScreenOn(true);
+            break;
+    }
+
+    m_powerState = powerState;
+}
+
index fa01b41..9726a22 100644 (file)
@@ -27,6 +27,7 @@
 #define PluginWidgetAndroid_H
 
 #include "android_npapi.h"
+#include "ANPSystem_npapi.h"
 #include "IntPoint.h"
 #include "IntRect.h"
 #include "MediaLayer.h"
@@ -174,6 +175,8 @@ struct PluginWidgetAndroid {
 
     WebCore::MediaLayer* getLayer() const { return m_layer; }
 
+    void setPowerState(ANPPowerState powerState);
+
 private:
     void computeVisiblePluginRect();
     void scrollToVisiblePluginRect();
@@ -198,6 +201,7 @@ private:
     bool                    m_embeddedViewAttached;
     bool                    m_acceptEvents;
     bool                    m_isSurfaceClippedOut;
+    ANPPowerState           m_powerState;
 
     /* We limit the number of rectangles to minimize storage and ensure adequate
        speed.
index dd2dd10..fb13b43 100644 (file)
@@ -124,6 +124,7 @@ typedef uint32_t ANPMatrixFlag;
 #define kOpenGLInterfaceV0_ANPGetValue      ((NPNVariable)1013)
 #define kWindowInterfaceV1_ANPGetValue      ((NPNVariable)1014)
 #define kVideoInterfaceV0_ANPGetValue       ((NPNVariable)1015)
+#define kSystemInterfaceV1_ANPGetValue      ((NPNVariable)1016)
 
 /** queries for the drawing models supported on this device.