adding API to enable plugins to request full screen mode

Change-Id: Ib3373af6ff127399d1d0846ba30a4275da5b3133
diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp
index 07e7633..0885c07 100644
--- a/WebKit/android/jni/WebViewCore.cpp
+++ b/WebKit/android/jni/WebViewCore.cpp
@@ -183,6 +183,7 @@
     jmethodID   m_geolocationPermissionsShowPrompt;
     jmethodID   m_geolocationPermissionsHidePrompt;
     jmethodID   m_addMessageToConsole;
+    jmethodID   m_startFullScreenPluginActivity;
     jmethodID   m_createSurface;
     jmethodID   m_destroySurface;
     AutoJObject object(JNIEnv* env) {
@@ -257,6 +258,7 @@
     m_javaGlue->m_geolocationPermissionsShowPrompt = GetJMethod(env, clazz, "geolocationPermissionsShowPrompt", "(Ljava/lang/String;)V");
     m_javaGlue->m_geolocationPermissionsHidePrompt = GetJMethod(env, clazz, "geolocationPermissionsHidePrompt", "()V");
     m_javaGlue->m_addMessageToConsole = GetJMethod(env, clazz, "addMessageToConsole", "(Ljava/lang/String;ILjava/lang/String;)V");
+    m_javaGlue->m_startFullScreenPluginActivity = GetJMethod(env, clazz, "startFullScreenPluginActivity", "(Ljava/lang/String;Ljava/lang/String;I)V");
     m_javaGlue->m_createSurface = GetJMethod(env, clazz, "createSurface", "(Ljava/lang/String;Ljava/lang/String;IIIII)Landroid/webkit/ViewManager$ChildView;");
     m_javaGlue->m_destroySurface = GetJMethod(env, clazz, "destroySurface", "(Landroid/webkit/ViewManager$ChildView;)V");
 
@@ -2189,15 +2191,28 @@
     view->setBaseBackgroundColor(bcolor);
 }
 
-jobject WebViewCore::createSurface(const char* packageName, const char* className,
+void WebViewCore::startFullScreenPluginActivity(const char* libName,
+                                                const char* className, NPP npp)
+{
+    JNIEnv* env = JSC::Bindings::getJNIEnv();
+
+    jstring libString = env->NewStringUTF(libName);
+    jstring classString = env->NewStringUTF(className);
+    env->CallVoidMethod(m_javaGlue->object(env).get(),
+                        m_javaGlue->m_startFullScreenPluginActivity,
+                        libString, classString, (int) npp);
+    checkException(env);
+}
+
+jobject WebViewCore::createSurface(const char* libName, const char* className,
                                    NPP npp, int x, int y, int width, int height)
 {
     JNIEnv* env = JSC::Bindings::getJNIEnv();
 
-    jstring packageString = env->NewStringUTF(packageName);
+    jstring libString = env->NewStringUTF(libName);
     jstring classString = env->NewStringUTF(className);
     jobject result = env->CallObjectMethod(m_javaGlue->object(env).get(),
-                                           m_javaGlue->m_createSurface, packageString,
+                                           m_javaGlue->m_createSurface, libString,
                                            classString,(int) npp, x, y, width, height);
     checkException(env);
     return result;
diff --git a/WebKit/android/jni/WebViewCore.h b/WebKit/android/jni/WebViewCore.h
index cf1d21f..7dd8763 100644
--- a/WebKit/android/jni/WebViewCore.h
+++ b/WebKit/android/jni/WebViewCore.h
@@ -365,8 +365,12 @@
         // Notify the Java side that webkit is requesting a keyboard
         void requestKeyboard(bool);
 
-        // Creates a SurfaceView for a plugin
-        jobject createSurface(const char* packageName, const char* className,
+        // Creates a full screen surface (i.e. View on an Activity) for a plugin
+        void startFullScreenPluginActivity(const char* libName,
+                                           const char* className, NPP npp);
+
+        // Creates a Surface (i.e. View) for a plugin
+        jobject createSurface(const char* libName, const char* className,
                               NPP npp, int x, int y, int width, int height);
 
         // Destroys a SurfaceView for a plugin
diff --git a/WebKit/android/plugins/ANPWindowInterface.cpp b/WebKit/android/plugins/ANPWindowInterface.cpp
index 41e00e9..7a2f94c 100644
--- a/WebKit/android/plugins/ANPWindowInterface.cpp
+++ b/WebKit/android/plugins/ANPWindowInterface.cpp
@@ -73,6 +73,11 @@
     core->requestKeyboard(value);
 }
 
+static void anp_requestFullScreen(NPP instance) {
+    PluginView* pluginView = pluginViewForInstance(instance);
+    pluginView->platformPluginWidget()->requestFullScreenMode();
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 
 #define ASSIGN(obj, name)   (obj)->name = anp_##name
@@ -86,5 +91,6 @@
     ASSIGN(i, clearVisibleRects);
     ASSIGN(i, showKeyboard);
     ASSIGN(i, unlock);
+    ASSIGN(i, requestFullScreen);
 }
 
diff --git a/WebKit/android/plugins/PluginWidgetAndroid.cpp b/WebKit/android/plugins/PluginWidgetAndroid.cpp
index 81e9650..fdc4016 100644
--- a/WebKit/android/plugins/PluginWidgetAndroid.cpp
+++ b/WebKit/android/plugins/PluginWidgetAndroid.cpp
@@ -34,6 +34,7 @@
 #include "ScrollView.h"
 #include "SkANP.h"
 #include "SkFlipPixelRef.h"
+#include "SkString.h"
 #include "WebViewCore.h"
 
 PluginWidgetAndroid::PluginWidgetAndroid(WebCore::PluginView* view)
@@ -75,48 +76,21 @@
                          : SkBitmap::kRGB_565_Config;
 }
 
-/*
- * Returns the name of the apk that contains this plugin. The caller is
- * responsible for calling free(...) on the char* that is returned.
- */
-static char* getPackageName(PluginPackage* pluginPackage) {
-
-    // get the directory where the plugin library is stored. The structure of
-    // the path looks like /data/app/plugin.package.name/lib.
-    const char* pluginDir = pluginPackage->parentDirectory().latin1().data();
-
-    // trim "/lib" off the directory name and store in tempString
-    int length = strlen(pluginDir) - 4; // -4 for "/lib"
-    char* tempString = (char*) malloc(length + 1); // +1 for null termination
-    strncpy(tempString, pluginDir, length);
-    tempString[length] = '\0';
-
-    // find the final '/' in tempString
-    char* result = strrchr(tempString, '/');
-
-    char* packageName = NULL;
-    if (result) {
-        // duplicate the tempString without the leading '/'
-        packageName = strdup(result+1);
-    }
-
-    // free extra memory and return the package name
-    free(tempString);
-    return packageName;
-}
-
 void PluginWidgetAndroid::setWindow(NPWindow* window, bool isTransparent) {
     m_pluginWindow = window;
 
     if (m_drawingModel == kSurface_ANPDrawingModel) {
         if (!m_childView) {
             IntPoint docPoint = frameToDocumentCoords(window->x, window->y);
-            char* packageName = getPackageName(m_pluginView->plugin());
-            m_childView = m_core->createSurface(packageName, m_javaClassName,
+
+            const String& libName = m_pluginView->plugin()->path();
+            SkString skLibName;
+            skLibName.setUTF16(libName.characters(), libName.length());
+
+            m_childView = m_core->createSurface(skLibName.c_str(), m_javaClassName,
                                                 m_pluginView->instance(),
                                                 docPoint.x(), docPoint.y(),
                                                 window->width, window->height);
-            free(packageName);
         }
     } else {
         m_flipPixelRef->safeUnref();
@@ -142,6 +116,20 @@
     return (m_javaClassName != NULL);
 }
 
+void PluginWidgetAndroid::requestFullScreenMode() {
+
+    if (!m_javaClassName) {
+        return;
+    }
+
+    const String& libName = m_pluginView->plugin()->path();
+    SkString skLibName;
+    skLibName.setUTF16(libName.characters(), libName.length());
+
+    m_core->startFullScreenPluginActivity(skLibName.c_str(), m_javaClassName,
+                                          m_pluginView->instance());
+}
+
 bool PluginWidgetAndroid::setDrawingModel(ANPDrawingModel model) {
 
     // disallow the surface drawing model if no java class name has been given
diff --git a/WebKit/android/plugins/PluginWidgetAndroid.h b/WebKit/android/plugins/PluginWidgetAndroid.h
index aaf6f96..9fc2209 100644
--- a/WebKit/android/plugins/PluginWidgetAndroid.h
+++ b/WebKit/android/plugins/PluginWidgetAndroid.h
@@ -131,6 +131,12 @@
      */
     void setVisibleRects(const ANPRectI rects[], int32_t count);
 
+    /** Called when a plugin wishes to enter into full screen mode. The plugin's
+        Java class (set using setPluginStubJavaClassName(...)) will be called
+        asynchronously to provide a View to be displayed in full screen.
+     */
+    void requestFullScreenMode();
+
 private:
     WebCore::IntPoint frameToDocumentCoords(int frameX, int frameY) const;
     void computeVisibleFrameRect();
diff --git a/WebKit/android/plugins/android_npapi.h b/WebKit/android/plugins/android_npapi.h
index 5218031..95ab889 100644
--- a/WebKit/android/plugins/android_npapi.h
+++ b/WebKit/android/plugins/android_npapi.h
@@ -659,6 +659,11 @@
         physical keyboard is active.
      */
     void    (*showKeyboard)(NPP instance, bool value);
+    /** Called when a plugin wishes to enter into full screen mode. The plugin's
+        Java class (set using kSetPluginStubJavaClassName_ANPSetValue) will be
+        called asynchronously to provide a View object to be displayed full screen.
+     */
+    void    (*requestFullScreen)(NPP instance);
 };
 
 ///////////////////////////////////////////////////////////////////////////////