Bug 1388903 - Part 2: Remove PrintDlg Window Parentage in NPAPI Process. r=jimm, a=gchang
authorDavid Parks <dparks@mozilla.com>
Tue, 29 Aug 2017 15:59:34 -0700
changeset 423973 755dff9960436d7feb9b9ee34e0d61f644ad9faa
parent 423972 9c1450703b0a43810727299bec81040573378912
child 423974 7f6aade38935c08c783c23d51160427011f92ef2
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm, gchang
bugs1388903
milestone56.0
Bug 1388903 - Part 2: Remove PrintDlg Window Parentage in NPAPI Process. r=jimm, a=gchang By intercepting the call to PrintDlgW and zeroing out the parent window privided by the caller, we allow the call to run in the NPAPI sandbox.
dom/plugins/ipc/PluginModuleChild.cpp
dom/plugins/ipc/PluginQuirks.cpp
dom/plugins/ipc/PluginQuirks.h
--- a/dom/plugins/ipc/PluginModuleChild.cpp
+++ b/dom/plugins/ipc/PluginModuleChild.cpp
@@ -107,16 +107,19 @@ static WindowsDllInterceptor sComDlg32In
 typedef BOOL (WINAPI *GetOpenFileNameWPtr)(LPOPENFILENAMEW lpofn);
 static GetOpenFileNameWPtr sGetOpenFileNameWPtrStub = nullptr;
 typedef BOOL (WINAPI *GetSaveFileNameWPtr)(LPOPENFILENAMEW lpofn);
 static GetSaveFileNameWPtr sGetSaveFileNameWPtrStub = nullptr;
 
 typedef BOOL (WINAPI *SetCursorPosPtr)(int x, int y);
 static SetCursorPosPtr sSetCursorPosPtrStub = nullptr;
 
+typedef BOOL (WINAPI *PrintDlgWPtr)(LPPRINTDLGW aDlg);
+static PrintDlgWPtr sPrintDlgWPtrStub = nullptr;
+
 #endif
 
 /* static */
 bool
 PluginModuleChild::CreateForContentProcess(Endpoint<PPluginModuleChild>&& aEndpoint)
 {
     auto* child = new PluginModuleChild(false);
     return child->InitForContent(Move(aEndpoint));
@@ -2182,16 +2185,29 @@ PMCGetSaveFileNameW(LPOPENFILENAMEW aLpo
 }
 // static
 BOOL WINAPI
 PMCGetOpenFileNameW(LPOPENFILENAMEW aLpofn)
 {
     return PMCGetFileNameW(OPEN_FUNC, aLpofn);
 }
 
+//static
+BOOL WINAPI
+PMCPrintDlgW(LPPRINTDLGW aDlg)
+{
+  // Zero out the HWND supplied by the plugin.  We are sacrificing window
+  // parentage for the ability to run in the NPAPI sandbox.
+  HWND hwnd = aDlg->hwndOwner;
+  aDlg->hwndOwner = 0;
+  BOOL ret = sPrintDlgWPtrStub(aDlg);
+  aDlg->hwndOwner = hwnd;
+  return ret;
+}
+
 BOOL WINAPI PMCSetCursorPos(int x, int y);
 
 class SetCursorPosTaskData : public PluginThreadTaskData
 {
 public:
     SetCursorPosTaskData(int x, int y) : mX(x), mY(y) {}
     bool RunTask() { return PMCSetCursorPos(mX, mY); }
 private:
@@ -2260,16 +2276,22 @@ PluginModuleChild::AllocPPluginInstanceC
         sComDlg32Intercept.AddHook("GetSaveFileNameW", reinterpret_cast<intptr_t>(PMCGetSaveFileNameW),
                                  (void**) &sGetSaveFileNameWPtrStub);
     }
 
     if (!sGetOpenFileNameWPtrStub) {
         sComDlg32Intercept.AddHook("GetOpenFileNameW", reinterpret_cast<intptr_t>(PMCGetOpenFileNameW),
                                  (void**) &sGetOpenFileNameWPtrStub);
     }
+
+    if ((mQuirks & QUIRK_FLASH_HOOK_PRINTDLGW) &&
+        !sPrintDlgWPtrStub) {
+        sComDlg32Intercept.AddHook("PrintDlgW", reinterpret_cast<intptr_t>(PMCPrintDlgW),
+                                 (void**) &sPrintDlgWPtrStub);
+    }
 #endif
 
     return new PluginInstanceChild(&mFunctions, aMimeType, aNames,
                                    aValues);
 }
 
 void
 PluginModuleChild::InitQuirksModes(const nsCString& aMimeType)
--- a/dom/plugins/ipc/PluginQuirks.cpp
+++ b/dom/plugins/ipc/PluginQuirks.cpp
@@ -24,16 +24,17 @@ int GetQuirksFromMimeTypeAndFilename(con
         quirks |= QUIRK_WINLESS_TRACKPOPUP_HOOK;
         quirks |= QUIRK_FLASH_THROTTLE_WMUSER_EVENTS;
         quirks |= QUIRK_FLASH_HOOK_SETLONGPTR;
         quirks |= QUIRK_FLASH_HOOK_GETWINDOWINFO;
         quirks |= QUIRK_FLASH_FIXUP_MOUSE_CAPTURE;
         quirks |= QUIRK_WINLESS_HOOK_IME;
 #if defined(_M_X64) || defined(__x86_64__)
         quirks |= QUIRK_FLASH_HOOK_GETKEYSTATE;
+        quirks |= QUIRK_FLASH_HOOK_PRINTDLGW;
 #endif
 #endif
     }
 
 #ifdef XP_MACOSX
     // Whitelist Flash to support offline renderer.
     if (specialType == nsPluginHost::eSpecialType_Flash) {
         quirks |= QUIRK_ALLOW_OFFLINE_RENDERER;
--- a/dom/plugins/ipc/PluginQuirks.h
+++ b/dom/plugins/ipc/PluginQuirks.h
@@ -40,16 +40,18 @@ enum PluginQuirks {
   // Work around a Flash bug where it fails to check the error code of a
   // NPN_GetValue(NPNVdocumentOrigin) call before trying to dereference
   // its char* output.
   QUIRK_FLASH_RETURN_EMPTY_DOCUMENT_ORIGIN        = 1 << 10,
   // Win: Hook IMM32 API to handle IME event on windowless plugin
   QUIRK_WINLESS_HOOK_IME                          = 1 << 12,
   // Win: Hook GetKeyState to get keyboard state on sandbox process
   QUIRK_FLASH_HOOK_GETKEYSTATE                    = 1 << 13,
+  // Win: Hook PrintDlgW to show print settings dialog on sandbox process
+  QUIRK_FLASH_HOOK_PRINTDLGW                      = 1 << 14,
 };
 
 int GetQuirksFromMimeTypeAndFilename(const nsCString& aMimeType,
                                      const nsCString& aPluginFilename);
 
 } /* namespace plugins */
 } /* namespace mozilla */