Bug 683099 - NS_NATIVE_WINDOW value should not be used as IPC shareable . r=roc
authorOleg Romashin <romaxa@gmail.com>
Wed, 31 Aug 2011 20:01:38 +0100
changeset 76347 e43df9a4b36e65c09b30d853bc645207bff7ed35
parent 76346 220b6e404f1bfb626b7821ba6354c4cd2b502fae
child 76348 de4425a74643cdfcfb6bd909a53de379b3c3003a
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersroc
bugs683099
milestone9.0a1
Bug 683099 - NS_NATIVE_WINDOW value should not be used as IPC shareable . r=roc
dom/ipc/TabParent.cpp
dom/plugins/base/nsPluginInstanceOwner.cpp
widget/public/nsIWidget.h
widget/src/gtk2/nsWindow.cpp
widget/src/qt/nsWindow.cpp
widget/src/windows/nsWindow.cpp
widget/src/xpwidgets/PuppetWidget.cpp
widget/src/xpwidgets/PuppetWidget.h
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -622,17 +622,17 @@ TabParent::RecvGetWidgetNativeData(Windo
     if (document) {
       nsIPresShell* shell = document->GetShell();
       if (shell) {
         nsIViewManager* vm = shell->GetViewManager();
         nsCOMPtr<nsIWidget> widget;
         vm->GetRootWidget(getter_AddRefs(widget));
         if (widget) {
           *aValue = reinterpret_cast<WindowsHandle>(
-            widget->GetNativeData(NS_NATIVE_WINDOW));
+            widget->GetNativeData(NS_NATIVE_SHAREABLE_WINDOW));
           return true;
         }
       }
     }
   }
   return false;
 }
 
--- a/dom/plugins/base/nsPluginInstanceOwner.cpp
+++ b/dom/plugins/base/nsPluginInstanceOwner.cpp
@@ -712,42 +712,23 @@ NS_IMETHODIMP nsPluginInstanceOwner::Get
   nsresult rv = vm->GetRootWidget(getter_AddRefs(widget));            
   if (widget) {
     *pvalue = (void*)widget->GetNativeData(NS_NATIVE_WINDOW);
   } else {
     NS_ASSERTION(widget, "couldn't get doc's widget in getting doc's window handle");
   }
 
   return rv;
-#elif defined(MOZ_WIDGET_GTK2)
+#elif defined(MOZ_WIDGET_GTK2) || defined(MOZ_WIDGET_QT)
   // X11 window managers want the toplevel window for WM_TRANSIENT_FOR.
   nsIWidget* win = mObjectFrame->GetNearestWidget();
   if (!win)
     return NS_ERROR_FAILURE;
-  GdkWindow* gdkWindow = static_cast<GdkWindow*>(win->GetNativeData(NS_NATIVE_WINDOW));
-  if (!gdkWindow)
-    return NS_ERROR_FAILURE;
-  gdkWindow = gdk_window_get_toplevel(gdkWindow);
-#ifdef MOZ_X11
-  *static_cast<Window*>(value) = GDK_WINDOW_XID(gdkWindow);
-#endif
+  *static_cast<Window*>(value) = (long unsigned int)win->GetNativeData(NS_NATIVE_SHAREABLE_WINDOW);
   return NS_OK;
-#elif defined(MOZ_WIDGET_QT)
-  // X11 window managers want the toplevel window for WM_TRANSIENT_FOR.
-  nsIWidget* win = mObjectFrame->GetNearestWidget();
-  if (!win)
-    return NS_ERROR_FAILURE;
-  QWidget* widget = static_cast<QWidget*>(win->GetNativeData(NS_NATIVE_WINDOW));
-  if (!widget)
-    return NS_ERROR_FAILURE;
-#ifdef MOZ_X11
-  *static_cast<Window*>(value) = widget->handle();
-  return NS_OK;
-#endif
-  return NS_ERROR_FAILURE;
 #else
   return NS_ERROR_NOT_IMPLEMENTED;
 #endif
 }
 
 NS_IMETHODIMP nsPluginInstanceOwner::SetEventModel(PRInt32 eventModel)
 {
 #ifdef XP_MACOSX
--- a/widget/public/nsIWidget.h
+++ b/widget/public/nsIWidget.h
@@ -102,16 +102,19 @@ typedef nsEventStatus (* EVENT_CALLBACK)
 #define NS_NATIVE_WIDGET      3
 #define NS_NATIVE_DISPLAY     4
 #define NS_NATIVE_REGION      5
 #define NS_NATIVE_OFFSETX     6
 #define NS_NATIVE_OFFSETY     7
 #define NS_NATIVE_PLUGIN_PORT 8
 #define NS_NATIVE_SCREEN      9
 #define NS_NATIVE_SHELLWIDGET 10      // Get the shell GtkWidget
+// Has to match to NPNVnetscapeWindow, and shareable across processes
+// HWND on Windows and XID on X11
+#define NS_NATIVE_SHAREABLE_WINDOW 11
 #ifdef XP_MACOSX
 #define NS_NATIVE_PLUGIN_PORT_QD    100
 #define NS_NATIVE_PLUGIN_PORT_CG    101
 #endif
 #ifdef XP_WIN
 #define NS_NATIVE_TSF_THREAD_MGR       100
 #define NS_NATIVE_TSF_CATEGORY_MGR     101
 #define NS_NATIVE_TSF_DISPLAY_ATTR_MGR 102
--- a/widget/src/gtk2/nsWindow.cpp
+++ b/widget/src/gtk2/nsWindow.cpp
@@ -1839,16 +1839,19 @@ nsWindow::GetNativeData(PRUint32 aDataTy
         NS_ASSERTION(nsnull != mToolkit, "NULL toolkit, unable to get a GC");
         return (void *)static_cast<nsGTKToolkit *>(mToolkit)->GetSharedGC();
         break;
     }
 
     case NS_NATIVE_SHELLWIDGET:
         return (void *) mShell;
 
+    case NS_NATIVE_SHAREABLE_WINDOW:
+        return (void *) GDK_WINDOW_XID(gdk_window_get_toplevel(mGdkWindow));
+
     default:
         NS_WARNING("nsWindow::GetNativeData called with bad value");
         return nsnull;
     }
 }
 
 NS_IMETHODIMP
 nsWindow::SetTitle(const nsAString& aTitle)
--- a/widget/src/qt/nsWindow.cpp
+++ b/widget/src/qt/nsWindow.cpp
@@ -812,16 +812,22 @@ nsWindow::GetNativeData(PRUint32 aDataTy
     }
 
     case NS_NATIVE_SHELLWIDGET: {
         QWidget* widget = nsnull;
         if (mWidget && mWidget->scene())
             widget = mWidget->scene()->views()[0]->viewport();
         return (void *) widget;
     }
+
+    case NS_NATIVE_SHAREABLE_WINDOW: {
+        QWidget *widget = GetViewWidget();
+        return widget ? (void*)widget->winId() : nsnull;
+    }
+
     default:
         NS_WARNING("nsWindow::GetNativeData called with bad value");
         return nsnull;
     }
 }
 
 NS_IMETHODIMP
 nsWindow::SetTitle(const nsAString& aTitle)
--- a/widget/src/windows/nsWindow.cpp
+++ b/widget/src/windows/nsWindow.cpp
@@ -2780,16 +2780,17 @@ void* nsWindow::GetNativeData(PRUint32 a
                                       CW_USEDEFAULT,
                                       mWnd,
                                       NULL,
                                       nsToolkit::mDllInstance,
                                       NULL);
     case NS_NATIVE_PLUGIN_PORT:
     case NS_NATIVE_WIDGET:
     case NS_NATIVE_WINDOW:
+    case NS_NATIVE_SHAREABLE_WINDOW:
       return (void*)mWnd;
     case NS_NATIVE_GRAPHIC:
       // XXX:  This is sleezy!!  Remember to Release the DC after using it!
 #ifdef MOZ_XUL
       return (void*)(eTransparencyTransparent == mTransparencyMode) ?
         mMemoryDC : ::GetDC(mWnd);
 #else
       return (void*)::GetDC(mWnd);
--- a/widget/src/xpwidgets/PuppetWidget.cpp
+++ b/widget/src/xpwidgets/PuppetWidget.cpp
@@ -616,10 +616,35 @@ PuppetWidget::GetDPI()
   if (mDPI < 0) {
     NS_ABORT_IF_FALSE(mTabChild, "Need TabChild to get the DPI from!");
     mTabChild->SendGetDPI(&mDPI);
   }
 
   return mDPI;
 }
 
+void*
+PuppetWidget::GetNativeData(PRUint32 aDataType)
+{
+    switch (aDataType) {
+    case NS_NATIVE_SHAREABLE_WINDOW: {
+        NS_ABORT_IF_FALSE(mTabChild, "Need TabChild to get the nativeWindow from!");
+        mozilla::WindowsHandle nativeData = nsnull;
+        mTabChild->SendGetWidgetNativeData(&nativeData);
+        return (void*)nativeData;
+    }
+    case NS_NATIVE_WINDOW:
+    case NS_NATIVE_DISPLAY:
+    case NS_NATIVE_PLUGIN_PORT:
+    case NS_NATIVE_GRAPHIC:
+    case NS_NATIVE_SHELLWIDGET:
+    case NS_NATIVE_WIDGET:
+        NS_WARNING("nsWindow::GetNativeData not implemented for this type");
+        break;
+    default:
+        NS_WARNING("nsWindow::GetNativeData called with bad value");
+        break;
+    }
+    return nsnull;
+}
+
 }  // namespace widget
 }  // namespace mozilla
--- a/widget/src/xpwidgets/PuppetWidget.h
+++ b/widget/src/xpwidgets/PuppetWidget.h
@@ -133,18 +133,17 @@ public:
 
   // This API is going away, steer clear.
   virtual void Scroll(const nsIntPoint& aDelta,
                       const nsTArray<nsIntRect>& aDestRects,
                       const nsTArray<Configuration>& aReconfigureChildren)
   { /* dead man walking */ }
 
   // PuppetWidgets don't have native data, as they're purely nonnative.
-  virtual void* GetNativeData(PRUint32 aDataType)
-  { return nsnull; }
+  virtual void* GetNativeData(PRUint32 aDataType);
   NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent)
   { return NS_ERROR_UNEXPECTED; }
 
   // PuppetWidgets don't have any concept of titles. 
   NS_IMETHOD SetTitle(const nsAString& aTitle)
   { return NS_ERROR_UNEXPECTED; }
   
   // PuppetWidgets are always at <0, 0>.