Bug 1095754 - Add platform widget support for providing widget identifiers used in remote widget tracking and hookl this up on gtk and Windows. r=roc
authorJim Mathies <jmathies@mozilla.com>
Thu, 29 Jan 2015 13:41:57 -0600
changeset 226596 0b7e58a519df02da97bd0041763664b873ae3539
parent 226595 ac859b6a5de3cf3d1e42fbe498c7a305e38fd8e1
child 226597 c41ac1e4405ea3a7fd5a127a888ac57d967fbdbb
push id28200
push userkwierso@gmail.com
push dateThu, 29 Jan 2015 23:01:46 +0000
treeherdermozilla-central@4380ed39de3a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1095754
milestone38.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 1095754 - Add platform widget support for providing widget identifiers used in remote widget tracking and hookl this up on gtk and Windows. r=roc
dom/plugins/ipc/PluginWidgetParent.cpp
gfx/layers/ipc/CompositorChild.cpp
widget/gtk/nsWindow.cpp
widget/gtk/nsWindow.h
widget/nsBaseWidget.cpp
widget/nsIWidget.h
widget/windows/nsWindow.cpp
--- a/dom/plugins/ipc/PluginWidgetParent.cpp
+++ b/dom/plugins/ipc/PluginWidgetParent.cpp
@@ -139,36 +139,36 @@ PluginWidgetParent::RecvCreate()
   DebugOnly<nsresult> drv;
   drv = mWidget->EnableDragDrop(true);
   NS_ASSERTION(NS_SUCCEEDED(drv), "widget call failure");
   drv = mWidget->Show(true);
   NS_ASSERTION(NS_SUCCEEDED(drv), "widget call failure");
   drv = mWidget->Enable(true);
   NS_ASSERTION(NS_SUCCEEDED(drv), "widget call failure");
 
-  // This is a special call we make to nsBaseWidget to register this
-  // window as a remote plugin window which is expected to receive
-  // visibility updates from the compositor, which ships this data
-  // over with corresponding layer updates.
-  mWidget->RegisterPluginWindowForRemoteUpdates();
-
 #if defined(MOZ_WIDGET_GTK)
   // For setup, initially GTK code expects 'window' to hold the parent.
   mWrapper->window = mWidget->GetNativeData(NS_NATIVE_PLUGIN_PORT);
   drv = mWrapper->CreateXEmbedWindow(false);
   NS_ASSERTION(NS_SUCCEEDED(drv), "widget call failure");
   mWrapper->SetAllocation();
   PWLOG("Plugin XID=%p\n", (void*)mWrapper->window);
 #elif defined(XP_WIN)
   DebugOnly<DWORD> winres =
     ::SetPropW((HWND)mWidget->GetNativeData(NS_NATIVE_WINDOW),
                kPluginWidgetParentProperty, this);
   NS_ASSERTION(winres, "SetPropW call failure");
 #endif
 
+  // This is a special call we make to nsBaseWidget to register this
+  // window as a remote plugin window which is expected to receive
+  // visibility updates from the compositor, which ships this data
+  // over with corresponding layer updates.
+  mWidget->RegisterPluginWindowForRemoteUpdates();
+
   return true;
 }
 
 void
 PluginWidgetParent::ActorDestroy(ActorDestroyReason aWhy)
 {
   mActorDestroyed = true;
   PWLOG("PluginWidgetParent::ActorDestroy()\n");
--- a/gfx/layers/ipc/CompositorChild.cpp
+++ b/gfx/layers/ipc/CompositorChild.cpp
@@ -191,17 +191,22 @@ CompositorChild::RecvUpdatePluginConfigu
   // the main thread is running freely.
   DebugOnly<nsresult> rv;
   MOZ_ASSERT(NS_IsMainThread());
 
   // Tracks visible plugins we update, so we can hide any plugins we don't.
   nsTArray<uintptr_t> visiblePluginIds;
 
   for (uint32_t pluginsIdx = 0; pluginsIdx < aPlugins.Length(); pluginsIdx++) {
-    nsIWidget* widget = nsIWidget::LookupRegisteredPluginWindow(aPlugins[pluginsIdx].windowId());
+    nsIWidget* widget =
+      nsIWidget::LookupRegisteredPluginWindow(aPlugins[pluginsIdx].windowId());
+    if (!widget) {
+      NS_WARNING("Unexpected, plugin id not found!");
+      continue;
+    }
     bool isVisible = aPlugins[pluginsIdx].visible();
     if (widget && !widget->Destroyed()) {
       nsIntRect bounds;
       nsIntRect visibleBounds;
       // If the plugin is visible update it's geometry.
       if (isVisible) {
         // bounds (content origin) - don't pass true to Resize, it triggers a
         // sync paint update to the plugin process on Windows, which happens
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -1047,34 +1047,23 @@ nsWindow::Resize(double aWidth, double a
             NativeResize(width, height, aRepaint);
         }
         else {
             mNeedsResize = true;
         }
     }
 
     NotifyRollupGeometryChange();
+    ResizePluginSocketWidget();
 
     // send a resize notification if this is a toplevel
     if (mIsTopLevel || mListenForResizes) {
         DispatchResized(width, height);
     }
 
-    // e10s specific, a eWindowType_plugin_ipc_chrome holds its own
-    // nsPluginNativeWindowGtk wrapper. We are responsible for
-    // resizing the embedded socket widget.
-    if (mWindowType == eWindowType_plugin_ipc_chrome) {
-        nsPluginNativeWindowGtk* wrapper = (nsPluginNativeWindowGtk*)
-          GetNativeData(NS_NATIVE_PLUGIN_OBJECT_PTR);
-        if (wrapper) {
-            wrapper->width = mBounds.width;
-            wrapper->height = mBounds.height;
-            wrapper->SetAllocation();
-        }
-    }
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWindow::Resize(double aX, double aY, double aWidth, double aHeight,
                  bool aRepaint)
 {
     CSSToLayoutDeviceScale scale = BoundsUseDisplayPixels() ? GetDefaultScale()
@@ -1131,24 +1120,42 @@ nsWindow::Resize(double aX, double aY, d
             NativeResize(x, y, width, height, aRepaint);
         }
         else {
             mNeedsResize = true;
         }
     }
 
     NotifyRollupGeometryChange();
+    ResizePluginSocketWidget();
 
     if (mIsTopLevel || mListenForResizes) {
         DispatchResized(width, height);
     }
 
     return NS_OK;
 }
 
+void
+nsWindow::ResizePluginSocketWidget()
+{
+    // e10s specific, a eWindowType_plugin_ipc_chrome holds its own
+    // nsPluginNativeWindowGtk wrapper. We are responsible for resizing
+    // the embedded socket widget.
+    if (mWindowType == eWindowType_plugin_ipc_chrome) {
+        nsPluginNativeWindowGtk* wrapper = (nsPluginNativeWindowGtk*)
+          GetNativeData(NS_NATIVE_PLUGIN_OBJECT_PTR);
+        if (wrapper) {
+            wrapper->width = mBounds.width;
+            wrapper->height = mBounds.height;
+            wrapper->SetAllocation();
+        }
+    }
+}
+
 NS_IMETHODIMP
 nsWindow::Enable(bool aState)
 {
     mEnabled = aState;
 
     return NS_OK;
 }
 
@@ -1657,16 +1664,25 @@ nsWindow::GetNativeData(uint32_t aDataTy
         return mGdkWindow;
         break;
     }
 
     case NS_NATIVE_PLUGIN_PORT:
         return SetupPluginPort();
         break;
 
+    case NS_NATIVE_PLUGIN_ID:
+        if (!mPluginNativeWindow) {
+          NS_WARNING("no native plugin instance!");
+          return nullptr;
+        }
+        // Return the socket widget XID
+        return (void*)mPluginNativeWindow->window;
+        break;
+
     case NS_NATIVE_DISPLAY:
 #ifdef MOZ_X11
         return GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
 #else
         return nullptr;
 #endif /* MOZ_X11 */
         break;
 
--- a/widget/gtk/nsWindow.h
+++ b/widget/gtk/nsWindow.h
@@ -427,16 +427,19 @@ private:
 
     /**
      * Dispatch accessible window restore event for the top level window
      * accessible.
      */
     void                DispatchRestoreEventAccessible();
 #endif
 
+    // Updates the bounds of the socket widget we manage for remote plugins.
+    void ResizePluginSocketWidget();
+
     // e10s specific - for managing the socket widget this window hosts.
     nsPluginNativeWindowGtk* mPluginNativeWindow;
 
     // The cursor cache
     static GdkCursor   *gsGtkCursorCache[eCursorCount];
 
     // Transparency
     bool         mIsTransparent;
--- a/widget/nsBaseWidget.cpp
+++ b/widget/nsBaseWidget.cpp
@@ -1761,17 +1761,17 @@ nsIWidget::ClearNativeTouchSequence()
 void
 nsBaseWidget::RegisterPluginWindowForRemoteUpdates()
 {
 #if !defined(XP_WIN) && !defined(MOZ_WIDGET_GTK)
   NS_NOTREACHED("nsBaseWidget::RegisterPluginWindowForRemoteUpdates not implemented!");
   return;
 #else
   MOZ_ASSERT(NS_IsMainThread());
-  void* id = GetNativeData(NS_NATIVE_PLUGIN_PORT);
+  void* id = GetNativeData(NS_NATIVE_PLUGIN_ID);
   if (!id) {
     NS_WARNING("This is not a valid native widget!");
     return;
   }
   MOZ_ASSERT(sPluginWidgetList);
   sPluginWidgetList->Put(id, this);
 #endif
 }
@@ -1779,17 +1779,17 @@ nsBaseWidget::RegisterPluginWindowForRem
 void
 nsBaseWidget::UnregisterPluginWindowForRemoteUpdates()
 {
 #if !defined(XP_WIN) && !defined(MOZ_WIDGET_GTK)
   NS_NOTREACHED("nsBaseWidget::UnregisterPluginWindowForRemoteUpdates not implemented!");
   return;
 #else
   MOZ_ASSERT(NS_IsMainThread());
-  void* id = GetNativeData(NS_NATIVE_PLUGIN_PORT);
+  void* id = GetNativeData(NS_NATIVE_PLUGIN_ID);
   if (!id) {
     NS_WARNING("This is not a valid native widget!");
     return;
   }
   MOZ_ASSERT(sPluginWidgetList);
   sPluginWidgetList->Remove(id);
 #endif
 }
--- a/widget/nsIWidget.h
+++ b/widget/nsIWidget.h
@@ -103,16 +103,18 @@ typedef void* nsNativeWidget;
 #define NS_NATIVE_TSF_CATEGORY_MGR     101
 #define NS_NATIVE_TSF_DISPLAY_ATTR_MGR 102
 #define NS_NATIVE_ICOREWINDOW          103 // winrt specific
 #endif
 #if defined(MOZ_WIDGET_GTK)
 // set/get nsPluginNativeWindowGtk, e10s specific
 #define NS_NATIVE_PLUGIN_OBJECT_PTR    104
 #endif
+// See RegisterPluginWindowForRemoteUpdates
+#define NS_NATIVE_PLUGIN_ID            105
 
 #define NS_IWIDGET_IID \
 { 0xa7db3e01, 0xb8fe, 0x4122, \
   { 0xbe, 0xa6, 0x45, 0x6c, 0xdd, 0x85, 0x30, 0x64 } };
 
 /*
  * Window shadow styles
  * Also used for the -moz-window-shadow CSS property
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -2914,16 +2914,17 @@ void* nsWindow::GetNativeData(uint32_t a
                                       CW_USEDEFAULT,
                                       CW_USEDEFAULT,
                                       CW_USEDEFAULT,
                                       CW_USEDEFAULT,
                                       mWnd,
                                       nullptr,
                                       nsToolkit::mDllInstance,
                                       nullptr);
+    case NS_NATIVE_PLUGIN_ID:
     case NS_NATIVE_PLUGIN_PORT:
     case NS_NATIVE_WIDGET:
     case NS_NATIVE_WINDOW:
       return (void*)mWnd;
     case NS_NATIVE_SHAREABLE_WINDOW:
       return (void*) WinUtils::GetTopLevelHWND(mWnd);
     case NS_NATIVE_GRAPHIC:
       // XXX:  This is sleezy!!  Remember to Release the DC after using it!