Bug 1363567 - 1. Remove addPluginView/removePluginView methods; r=rbarker
authorJim Chen <nchen@mozilla.com>
Mon, 15 May 2017 23:11:17 -0400
changeset 406671 06142f9787e7643cae17dced089d4ebd37ec1bbc
parent 406670 e4607267bb9ff933edac5090ef5798d8538cea09
child 406672 8f9d8749eb5ef4d9d156426435c5f17a20b75601
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrbarker
bugs1363567
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1363567 - 1. Remove addPluginView/removePluginView methods; r=rbarker Remove the addPluginView and removePluginView methods from GeckoInterface. Instead, move the JNI calls directly to GeckoApp itself. GeckoApp then uses GeckoActivityMonitor to find the current activity, instead of using GeckoAppShell.getGeckoInterface(). MozReview-Commit-ID: 7ym8kuElADV
dom/plugins/base/nsPluginInstanceOwner.cpp
mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/BaseGeckoInterface.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
widget/android/GeneratedJNIWrappers.cpp
widget/android/GeneratedJNIWrappers.h
widget/android/fennec/FennecJNIWrappers.cpp
widget/android/fennec/FennecJNIWrappers.h
--- a/dom/plugins/base/nsPluginInstanceOwner.cpp
+++ b/dom/plugins/base/nsPluginInstanceOwner.cpp
@@ -86,16 +86,17 @@ static NS_DEFINE_CID(kAppShellCID, NS_AP
 #include <gdk/gdk.h>
 #include <gtk/gtk.h>
 #endif
 
 #ifdef MOZ_WIDGET_ANDROID
 #include "ANPBase.h"
 #include "AndroidBridge.h"
 #include "ClientLayerManager.h"
+#include "FennecJNIWrappers.h"
 #include "nsWindow.h"
 
 static nsPluginInstanceOwner* sFullScreenInstance = nullptr;
 
 using namespace mozilla::dom;
 
 #include <android/log.h>
 #define LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "GeckoPlugins" , ## args)
@@ -1542,31 +1543,31 @@ bool nsPluginInstanceOwner::AddPluginVie
     mJavaView = mInstance->GetJavaSurface();
 
     if (!mJavaView)
       return false;
 
     mJavaView = (void*)jni::GetGeckoThreadEnv()->NewGlobalRef((jobject)mJavaView);
   }
 
-  if (mFullScreen) {
-    java::GeckoAppShell::AddFullScreenPluginView(jni::Object::Ref::From(jobject(mJavaView)));
+  if (mFullScreen && jni::IsFennec()) {
+    java::GeckoApp::AddPluginView(jni::Object::Ref::From(jobject(mJavaView)));
     sFullScreenInstance = this;
   }
 
   return true;
 }
 
 void nsPluginInstanceOwner::RemovePluginView()
 {
   if (!mInstance || !mJavaView)
     return;
 
-  if (mFullScreen) {
-    java::GeckoAppShell::RemoveFullScreenPluginView(jni::Object::Ref::From(jobject(mJavaView)));
+  if (mFullScreen && jni::IsFennec()) {
+    java::GeckoApp::RemovePluginView(jni::Object::Ref::From(jobject(mJavaView)));
   }
   jni::GetGeckoThreadEnv()->DeleteGlobalRef((jobject)mJavaView);
   mJavaView = nullptr;
 
   if (mFullScreen)
     sFullScreenInstance = nullptr;
 }
 
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -3,16 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko;
 
 import org.mozilla.gecko.AppConstants.Versions;
 import org.mozilla.gecko.GeckoProfileDirectories.NoMozillaDirectoryException;
 import org.mozilla.gecko.annotation.RobocopTarget;
+import org.mozilla.gecko.annotation.WrapForJNI;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.db.UrlAnnotations;
 import org.mozilla.gecko.gfx.BitmapUtils;
 import org.mozilla.gecko.gfx.FullScreenState;
 import org.mozilla.gecko.gfx.LayerView;
 import org.mozilla.gecko.health.HealthRecorder;
 import org.mozilla.gecko.health.SessionInformation;
 import org.mozilla.gecko.health.StubbedHealthRecorder;
@@ -1010,26 +1011,31 @@ public abstract class GeckoApp extends G
 
 
         FrameLayout decor = (FrameLayout)getWindow().getDecorView();
         decor.addView(mFullScreenPluginContainer, layoutParams);
 
         mFullScreenPluginView = view;
     }
 
-    @Override
-    public void addPluginView(final View view) {
-
+    @WrapForJNI(calledFrom = "gecko")
+    private static void addPluginView(final View view) {
+        final Activity activity = GeckoActivityMonitor.getInstance().getCurrentActivity();
+        if (!(activity instanceof GeckoApp)) {
+            return;
+        }
+
+        final GeckoApp geckoApp = (GeckoApp) activity;
         if (ThreadUtils.isOnUiThread()) {
-            addFullScreenPluginView(view);
+            geckoApp.addFullScreenPluginView(view);
         } else {
             ThreadUtils.postToUiThread(new Runnable() {
                 @Override
                 public void run() {
-                    addFullScreenPluginView(view);
+                    geckoApp.addFullScreenPluginView(view);
                 }
             });
         }
     }
 
     /* package */ void removeFullScreenPluginView(View view) {
         if (mFullScreenPluginView == null) {
             Log.w(LOGTAG, "Don't have a fullscreen plugin view");
@@ -1056,25 +1062,31 @@ public abstract class GeckoApp extends G
         decor.removeView(mFullScreenPluginContainer);
 
         mFullScreenPluginView = null;
 
         GeckoScreenOrientation.getInstance().unlock();
         setFullScreen(false);
     }
 
-    @Override
-    public void removePluginView(final View view) {
+    @WrapForJNI(calledFrom = "gecko")
+    private static void removePluginView(final View view) {
+        final Activity activity = GeckoActivityMonitor.getInstance().getCurrentActivity();
+        if (!(activity instanceof GeckoApp)) {
+            return;
+        }
+
+        final GeckoApp geckoApp = (GeckoApp) activity;
         if (ThreadUtils.isOnUiThread()) {
-            removePluginView(view);
+            geckoApp.removeFullScreenPluginView(view);
         } else {
             ThreadUtils.postToUiThread(new Runnable() {
                 @Override
                 public void run() {
-                    removeFullScreenPluginView(view);
+                    geckoApp.removeFullScreenPluginView(view);
                 }
             });
         }
     }
 
     private void showSetImageResult(final boolean success, final int message, final String path) {
         ThreadUtils.postToUiThread(new Runnable() {
             @Override
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/BaseGeckoInterface.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/BaseGeckoInterface.java
@@ -22,24 +22,16 @@ public class BaseGeckoInterface implemen
         eventDispatcher = new EventDispatcher();
     }
 
     @Override
     public EventDispatcher getAppEventDispatcher() {
         return eventDispatcher;
     }
 
-    // Bug 908779: Implement this
-    @Override
-    public void addPluginView(final View view) {}
-
-    // Bug 908781: Implement this
-    @Override
-    public void removePluginView(final View view) {}
-
     @Override
     public void enableOrientationListener() {}
 
     @Override
     public void disableOrientationListener() {}
 
     // Bug 908786: Implement this
     @Override
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
@@ -1382,28 +1382,16 @@ public class GeckoAppShell
         catch (Exception e) {
             return true;
         }
     }
 
     @WrapForJNI(calledFrom = "ui", dispatchTo = "gecko")
     public static native void onFullScreenPluginHidden(View view);
 
-    @WrapForJNI(calledFrom = "gecko")
-    private static void addFullScreenPluginView(View view) {
-        if (getGeckoInterface() != null)
-             getGeckoInterface().addPluginView(view);
-    }
-
-    @WrapForJNI(calledFrom = "gecko")
-    private static void removeFullScreenPluginView(View view) {
-        if (getGeckoInterface() != null)
-            getGeckoInterface().removePluginView(view);
-    }
-
     /**
      * A plugin that wish to be loaded in the WebView must provide this permission
      * in their AndroidManifest.xml.
      */
     public static final String PLUGIN_ACTION = "android.webkit.PLUGIN";
     public static final String PLUGIN_PERMISSION = "android.webkit.permission.PLUGIN";
 
     private static final String PLUGIN_SYSTEM_LIB = "/system/lib/plugins/";
@@ -1657,18 +1645,16 @@ public class GeckoAppShell
         public void onPause();
         public void onResume();
         public void onOrientationChanged();
     }
 
     public interface GeckoInterface {
         public @NonNull EventDispatcher getAppEventDispatcher();
 
-        public void addPluginView(View view);
-        public void removePluginView(final View view);
         public void enableOrientationListener();
         public void disableOrientationListener();
         public void addAppStateListener(AppStateListener listener);
         public void removeAppStateListener(AppStateListener listener);
         public void notifyWakeLockChanged(String topic, String state);
         public boolean areTabsShown();
         public AbsoluteLayout getPluginContainer();
         public void invalidateOptionsMenu();
--- a/widget/android/GeneratedJNIWrappers.cpp
+++ b/widget/android/GeneratedJNIWrappers.cpp
@@ -100,24 +100,16 @@ constexpr char EventDispatcher::NativeCa
 constexpr char EventDispatcher::NativeCallbackDelegate::SendError_t::signature[];
 
 constexpr char EventDispatcher::NativeCallbackDelegate::SendSuccess_t::name[];
 constexpr char EventDispatcher::NativeCallbackDelegate::SendSuccess_t::signature[];
 
 const char GeckoAppShell::name[] =
         "org/mozilla/gecko/GeckoAppShell";
 
-constexpr char GeckoAppShell::AddFullScreenPluginView_t::name[];
-constexpr char GeckoAppShell::AddFullScreenPluginView_t::signature[];
-
-auto GeckoAppShell::AddFullScreenPluginView(mozilla::jni::Object::Param a0) -> void
-{
-    return mozilla::jni::Method<AddFullScreenPluginView_t>::Call(GeckoAppShell::Context(), nullptr, a0);
-}
-
 constexpr char GeckoAppShell::CancelVibrate_t::name[];
 constexpr char GeckoAppShell::CancelVibrate_t::signature[];
 
 auto GeckoAppShell::CancelVibrate() -> void
 {
     return mozilla::jni::Method<CancelVibrate_t>::Call(GeckoAppShell::Context(), nullptr);
 }
 
@@ -574,24 +566,16 @@ auto GeckoAppShell::OpenUriExternal(mozi
 constexpr char GeckoAppShell::PerformHapticFeedback_t::name[];
 constexpr char GeckoAppShell::PerformHapticFeedback_t::signature[];
 
 auto GeckoAppShell::PerformHapticFeedback(bool a0) -> void
 {
     return mozilla::jni::Method<PerformHapticFeedback_t>::Call(GeckoAppShell::Context(), nullptr, a0);
 }
 
-constexpr char GeckoAppShell::RemoveFullScreenPluginView_t::name[];
-constexpr char GeckoAppShell::RemoveFullScreenPluginView_t::signature[];
-
-auto GeckoAppShell::RemoveFullScreenPluginView(mozilla::jni::Object::Param a0) -> void
-{
-    return mozilla::jni::Method<RemoveFullScreenPluginView_t>::Call(GeckoAppShell::Context(), nullptr, a0);
-}
-
 constexpr char GeckoAppShell::ReportJavaCrash_t::name[];
 constexpr char GeckoAppShell::ReportJavaCrash_t::signature[];
 
 constexpr char GeckoAppShell::SetScreenDepthOverride_t::name[];
 constexpr char GeckoAppShell::SetScreenDepthOverride_t::signature[];
 
 auto GeckoAppShell::SetScreenDepthOverride(int32_t a0) -> void
 {
--- a/widget/android/GeneratedJNIWrappers.h
+++ b/widget/android/GeneratedJNIWrappers.h
@@ -370,36 +370,16 @@ class GeckoAppShell : public mozilla::jn
 {
 public:
     static const char name[];
 
     explicit GeckoAppShell(const Context& ctx) : ObjectBase<GeckoAppShell>(ctx) {}
 
     class CameraCallback;
 
-    struct AddFullScreenPluginView_t {
-        typedef GeckoAppShell Owner;
-        typedef void ReturnType;
-        typedef void SetterType;
-        typedef mozilla::jni::Args<
-                mozilla::jni::Object::Param> Args;
-        static constexpr char name[] = "addFullScreenPluginView";
-        static constexpr char signature[] =
-                "(Landroid/view/View;)V";
-        static const bool isStatic = true;
-        static const mozilla::jni::ExceptionMode exceptionMode =
-                mozilla::jni::ExceptionMode::ABORT;
-        static const mozilla::jni::CallingThread callingThread =
-                mozilla::jni::CallingThread::GECKO;
-        static const mozilla::jni::DispatchTarget dispatchTarget =
-                mozilla::jni::DispatchTarget::CURRENT;
-    };
-
-    static auto AddFullScreenPluginView(mozilla::jni::Object::Param) -> void;
-
     struct CancelVibrate_t {
         typedef GeckoAppShell Owner;
         typedef void ReturnType;
         typedef void SetterType;
         typedef mozilla::jni::Args<> Args;
         static constexpr char name[] = "cancelVibrate";
         static constexpr char signature[] =
                 "()V";
@@ -1619,36 +1599,16 @@ public:
         static const mozilla::jni::CallingThread callingThread =
                 mozilla::jni::CallingThread::GECKO;
         static const mozilla::jni::DispatchTarget dispatchTarget =
                 mozilla::jni::DispatchTarget::CURRENT;
     };
 
     static auto PerformHapticFeedback(bool) -> void;
 
-    struct RemoveFullScreenPluginView_t {
-        typedef GeckoAppShell Owner;
-        typedef void ReturnType;
-        typedef void SetterType;
-        typedef mozilla::jni::Args<
-                mozilla::jni::Object::Param> Args;
-        static constexpr char name[] = "removeFullScreenPluginView";
-        static constexpr char signature[] =
-                "(Landroid/view/View;)V";
-        static const bool isStatic = true;
-        static const mozilla::jni::ExceptionMode exceptionMode =
-                mozilla::jni::ExceptionMode::ABORT;
-        static const mozilla::jni::CallingThread callingThread =
-                mozilla::jni::CallingThread::GECKO;
-        static const mozilla::jni::DispatchTarget dispatchTarget =
-                mozilla::jni::DispatchTarget::CURRENT;
-    };
-
-    static auto RemoveFullScreenPluginView(mozilla::jni::Object::Param) -> void;
-
     struct ReportJavaCrash_t {
         typedef GeckoAppShell Owner;
         typedef void ReturnType;
         typedef void SetterType;
         typedef mozilla::jni::Args<
                 mozilla::jni::Throwable::Param,
                 mozilla::jni::String::Param> Args;
         static constexpr char name[] = "reportJavaCrash";
--- a/widget/android/fennec/FennecJNIWrappers.cpp
+++ b/widget/android/fennec/FennecJNIWrappers.cpp
@@ -36,16 +36,35 @@ auto DownloadsIntegration::GetTemporaryD
 constexpr char DownloadsIntegration::ScanMedia_t::name[];
 constexpr char DownloadsIntegration::ScanMedia_t::signature[];
 
 auto DownloadsIntegration::ScanMedia(mozilla::jni::String::Param a0, mozilla::jni::String::Param a1) -> void
 {
     return mozilla::jni::Method<ScanMedia_t>::Call(DownloadsIntegration::Context(), nullptr, a0, a1);
 }
 
+const char GeckoApp::name[] =
+        "org/mozilla/gecko/GeckoApp";
+
+constexpr char GeckoApp::AddPluginView_t::name[];
+constexpr char GeckoApp::AddPluginView_t::signature[];
+
+auto GeckoApp::AddPluginView(mozilla::jni::Object::Param a0) -> void
+{
+    return mozilla::jni::Method<AddPluginView_t>::Call(GeckoApp::Context(), nullptr, a0);
+}
+
+constexpr char GeckoApp::RemovePluginView_t::name[];
+constexpr char GeckoApp::RemovePluginView_t::signature[];
+
+auto GeckoApp::RemovePluginView(mozilla::jni::Object::Param a0) -> void
+{
+    return mozilla::jni::Method<RemovePluginView_t>::Call(GeckoApp::Context(), nullptr, a0);
+}
+
 const char GeckoJavaSampler::name[] =
         "org/mozilla/gecko/GeckoJavaSampler";
 
 constexpr char GeckoJavaSampler::GetFrameName_t::name[];
 constexpr char GeckoJavaSampler::GetFrameName_t::signature[];
 
 auto GeckoJavaSampler::GetFrameName(int32_t a0, int32_t a1, int32_t a2) -> mozilla::jni::String::LocalRef
 {
--- a/widget/android/fennec/FennecJNIWrappers.h
+++ b/widget/android/fennec/FennecJNIWrappers.h
@@ -124,16 +124,69 @@ public:
 
     static auto ScanMedia(mozilla::jni::String::Param, mozilla::jni::String::Param) -> void;
 
     static const mozilla::jni::CallingThread callingThread =
             mozilla::jni::CallingThread::GECKO;
 
 };
 
+class GeckoApp : public mozilla::jni::ObjectBase<GeckoApp>
+{
+public:
+    static const char name[];
+
+    explicit GeckoApp(const Context& ctx) : ObjectBase<GeckoApp>(ctx) {}
+
+    struct AddPluginView_t {
+        typedef GeckoApp Owner;
+        typedef void ReturnType;
+        typedef void SetterType;
+        typedef mozilla::jni::Args<
+                mozilla::jni::Object::Param> Args;
+        static constexpr char name[] = "addPluginView";
+        static constexpr char signature[] =
+                "(Landroid/view/View;)V";
+        static const bool isStatic = true;
+        static const mozilla::jni::ExceptionMode exceptionMode =
+                mozilla::jni::ExceptionMode::ABORT;
+        static const mozilla::jni::CallingThread callingThread =
+                mozilla::jni::CallingThread::GECKO;
+        static const mozilla::jni::DispatchTarget dispatchTarget =
+                mozilla::jni::DispatchTarget::CURRENT;
+    };
+
+    static auto AddPluginView(mozilla::jni::Object::Param) -> void;
+
+    struct RemovePluginView_t {
+        typedef GeckoApp Owner;
+        typedef void ReturnType;
+        typedef void SetterType;
+        typedef mozilla::jni::Args<
+                mozilla::jni::Object::Param> Args;
+        static constexpr char name[] = "removePluginView";
+        static constexpr char signature[] =
+                "(Landroid/view/View;)V";
+        static const bool isStatic = true;
+        static const mozilla::jni::ExceptionMode exceptionMode =
+                mozilla::jni::ExceptionMode::ABORT;
+        static const mozilla::jni::CallingThread callingThread =
+                mozilla::jni::CallingThread::GECKO;
+        static const mozilla::jni::DispatchTarget dispatchTarget =
+                mozilla::jni::DispatchTarget::CURRENT;
+    };
+
+    static auto RemovePluginView(mozilla::jni::Object::Param) -> void;
+
+    static const mozilla::jni::CallingThread callingThread =
+            mozilla::jni::CallingThread::ANY;
+
+    template<class Impl> class Natives;
+};
+
 class GeckoJavaSampler : public mozilla::jni::ObjectBase<GeckoJavaSampler>
 {
 public:
     static const char name[];
 
     explicit GeckoJavaSampler(const Context& ctx) : ObjectBase<GeckoJavaSampler>(ctx) {}
 
     struct GetFrameName_t {