Bug 1320020 - Remove Unity plugin quirk compatibility. r=aklotz
authorChris Peterson <cpeterson@mozilla.com>
Mon, 28 Nov 2016 22:52:18 -0800
changeset 324642 40e828d5ac43ca22a27c3adea2b01ffa4e062dec
parent 324641 563c1205e1472702c2a9e121cb378beddbcb87e6
child 324643 2ed482c5658daf17a53da846596258348fbf74a2
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersaklotz
bugs1320020
milestone53.0a1
Bug 1320020 - Remove Unity plugin quirk compatibility. r=aklotz
dom/plugins/base/nsPluginHost.cpp
dom/plugins/base/nsPluginTags.cpp
dom/plugins/ipc/PluginInstanceChild.cpp
dom/plugins/ipc/PluginInstanceChild.h
dom/plugins/ipc/PluginQuirks.cpp
dom/plugins/ipc/PluginQuirks.h
--- a/dom/plugins/base/nsPluginHost.cpp
+++ b/dom/plugins/base/nsPluginHost.cpp
@@ -1838,20 +1838,16 @@ nsPluginHost::GetSpecialType(const nsACS
   }
 
   if (aMIMEType.LowerCaseEqualsASCII("application/x-shockwave-flash") ||
       aMIMEType.LowerCaseEqualsASCII("application/futuresplash") ||
       aMIMEType.LowerCaseEqualsASCII("application/x-shockwave-flash-test")) {
     return eSpecialType_Flash;
   }
 
-  if (aMIMEType.LowerCaseEqualsASCII("application/vnd.unity")) {
-    return eSpecialType_Unity;
-  }
-
   // Java registers variants of its MIME with parameters, e.g.
   // application/x-java-vm;version=1.3
   const nsACString &noParam = Substring(aMIMEType, 0, aMIMEType.FindChar(';'));
 
   // The java mime pref may well not be one of these,
   // e.g. application/x-java-test used in the test suite
   nsAdoptingCString javaMIME = Preferences::GetCString(kPrefJavaMIME);
   if ((!javaMIME.IsEmpty() && noParam.LowerCaseEqualsASCII(javaMIME)) ||
--- a/dom/plugins/base/nsPluginTags.cpp
+++ b/dom/plugins/base/nsPluginTags.cpp
@@ -363,17 +363,16 @@ void nsPluginTag::InitMime(const char* c
       case nsPluginHost::eSpecialType_Flash:
         // VLC sometimes claims to implement the Flash MIME type, and we want
         // to allow users to control that separately from Adobe Flash.
         if (Name().EqualsLiteral("Shockwave Flash")) {
           mIsFlashPlugin = true;
           mSupportsAsyncInit = true;
         }
         break;
-      case nsPluginHost::eSpecialType_Unity:
       case nsPluginHost::eSpecialType_Test:
         mSupportsAsyncInit = true;
         break;
       case nsPluginHost::eSpecialType_None:
       default:
 #ifndef RELEASE_OR_BETA
         // Allow async init for all plugins on Nightly and Aurora
         mSupportsAsyncInit = true;
--- a/dom/plugins/ipc/PluginInstanceChild.cpp
+++ b/dom/plugins/ipc/PluginInstanceChild.cpp
@@ -158,18 +158,16 @@ PluginInstanceChild::PluginInstanceChild
 #if defined(OS_WIN)
     , mPluginWindowHWND(0)
     , mPluginWndProc(0)
     , mPluginParentHWND(0)
     , mCachedWinlessPluginHWND(0)
     , mWinlessPopupSurrogateHWND(0)
     , mWinlessThrottleOldWndProc(0)
     , mWinlessHiddenMsgHWND(0)
-    , mUnityGetMessageHook(NULL)
-    , mUnitySendMessageHook(NULL)
 #endif // OS_WIN
     , mAsyncCallMutex("PluginInstanceChild::mAsyncCallMutex")
 #if defined(MOZ_WIDGET_COCOA)
 #if defined(__i386__)
     , mEventModel(NPEventModelCarbon)
 #endif
     , mShColorSpace(nullptr)
     , mShContext(nullptr)
@@ -205,33 +203,27 @@ PluginInstanceChild::PluginInstanceChild
     mWsInfo.display = nullptr;
     mXtClient.top_widget = nullptr;
 #else
     mWsInfo.display = DefaultXDisplay();
 #endif
 #endif // MOZ_X11 && XP_UNIX && !XP_MACOSX
 #if defined(OS_WIN)
     InitPopupMenuHook();
-    if (GetQuirks() & QUIRK_UNITY_FIXUP_MOUSE_CAPTURE) {
-        SetUnityHooks();
-    }
     InitImm32Hook();
 #endif // OS_WIN
 }
 
 PluginInstanceChild::~PluginInstanceChild()
 {
 #if defined(OS_WIN)
     NS_ASSERTION(!mPluginWindowHWND, "Destroying PluginInstanceChild without NPP_Destroy?");
-    if (GetQuirks() & QUIRK_UNITY_FIXUP_MOUSE_CAPTURE) {
-        ClearUnityHooks();
-    }
     // In the event that we registered for audio device changes, stop.
-    PluginModuleChild* chromeInstance = PluginModuleChild::GetChrome();
-    if (chromeInstance) {
+    PluginModuleChild* chromeInstance = PluginModuleChild::GetChrome();
+    if (chromeInstance) {
       NPError rv = chromeInstance->PluginRequiresAudioDeviceChanges(this, false);
     }
 #endif
 #if defined(MOZ_WIDGET_COCOA)
     if (mShColorSpace) {
         ::CGColorSpaceRelease(mShColorSpace);
     }
     if (mShContext) {
@@ -2090,149 +2082,16 @@ PluginInstanceChild::HookSetWindowLongPt
         sUser32Intercept.AddHook("SetWindowLongA", reinterpret_cast<intptr_t>(SetWindowLongAHook),
                                  (void**) &sUser32SetWindowLongAHookStub);
     if (!sUser32SetWindowLongWHookStub)
         sUser32Intercept.AddHook("SetWindowLongW", reinterpret_cast<intptr_t>(SetWindowLongWHook),
                                  (void**) &sUser32SetWindowLongWHookStub);
 #endif
 }
 
-class SetCaptureHookData
-{
-public:
-    explicit SetCaptureHookData(HWND aHwnd)
-        : mHwnd(aHwnd)
-        , mHaveRect(false)
-    {
-        MOZ_ASSERT(aHwnd);
-        mHaveRect = !!GetClientRect(aHwnd, &mCaptureRect);
-    }
-
-    /**
-     * @return true if capture was released
-     */
-    bool HandleMouseMsg(const MSG& aMsg)
-    {
-        // If the window belongs to Unity, the mouse button is up, and the mouse
-        // has moved outside the client rect of the Unity window, release capture.
-        if (aMsg.hwnd != mHwnd || !mHaveRect) {
-            return false;
-        }
-        if (aMsg.message != WM_MOUSEMOVE && aMsg.message != WM_LBUTTONUP) {
-            return false;
-        }
-        if ((aMsg.message == WM_MOUSEMOVE && (aMsg.wParam & MK_LBUTTON))) {
-            return false;
-        }
-        POINT pt = { GET_X_LPARAM(aMsg.lParam), GET_Y_LPARAM(aMsg.lParam) };
-        if (PtInRect(&mCaptureRect, pt)) {
-            return false;
-        }
-        return !!ReleaseCapture();
-    }
-
-    bool IsUnityLosingCapture(const CWPSTRUCT& aInfo) const
-    {
-        return aInfo.message == WM_CAPTURECHANGED &&
-               aInfo.hwnd == mHwnd;
-    }
-
-private:
-    HWND mHwnd;
-    bool mHaveRect;
-    RECT mCaptureRect;
-};
-
-static StaticAutoPtr<SetCaptureHookData> sSetCaptureHookData;
-typedef HWND (WINAPI* User32SetCapture)(HWND);
-static User32SetCapture sUser32SetCaptureHookStub = nullptr;
-
-HWND WINAPI
-PluginInstanceChild::SetCaptureHook(HWND aHwnd)
-{
-    // Don't do anything unless aHwnd belongs to Unity
-    wchar_t className[256] = {0};
-    int numChars = GetClassNameW(aHwnd, className, ArrayLength(className));
-    NS_NAMED_LITERAL_STRING(unityClassName, "Unity.WebPlayer");
-    if (numChars == unityClassName.Length() && unityClassName == wwc(className)) {
-        sSetCaptureHookData = new SetCaptureHookData(aHwnd);
-    }
-    return sUser32SetCaptureHookStub(aHwnd);
-}
-
-void
-PluginInstanceChild::SetUnityHooks()
-{
-    if (!(GetQuirks() & QUIRK_UNITY_FIXUP_MOUSE_CAPTURE)) {
-        return;
-    }
-
-    sUser32Intercept.Init("user32.dll");
-    if (!sUser32SetCaptureHookStub) {
-        sUser32Intercept.AddHook("SetCapture",
-                                 reinterpret_cast<intptr_t>(SetCaptureHook),
-                                 (void**) &sUser32SetCaptureHookStub);
-    }
-    if (!mUnityGetMessageHook) {
-        mUnityGetMessageHook = SetWindowsHookEx(WH_GETMESSAGE,
-                                                &UnityGetMessageHookProc, NULL,
-                                                GetCurrentThreadId());
-    }
-    if (!mUnitySendMessageHook) {
-        mUnitySendMessageHook = SetWindowsHookEx(WH_CALLWNDPROC,
-                                                 &UnitySendMessageHookProc,
-                                                 NULL, GetCurrentThreadId());
-    }
-}
-
-void
-PluginInstanceChild::ClearUnityHooks()
-{
-    if (mUnityGetMessageHook) {
-        UnhookWindowsHookEx(mUnityGetMessageHook);
-        mUnityGetMessageHook = NULL;
-    }
-    if (mUnitySendMessageHook) {
-        UnhookWindowsHookEx(mUnitySendMessageHook);
-        mUnitySendMessageHook = NULL;
-    }
-    sSetCaptureHookData = nullptr;
-}
-
-LRESULT CALLBACK
-PluginInstanceChild::UnityGetMessageHookProc(int aCode, WPARAM aWparam,
-                                             LPARAM aLParam)
-{
-    if (aCode >= 0) {
-        MSG* info = reinterpret_cast<MSG*>(aLParam);
-        MOZ_ASSERT(info);
-        if (sSetCaptureHookData && sSetCaptureHookData->HandleMouseMsg(*info)) {
-            sSetCaptureHookData = nullptr;
-        }
-    }
-
-    return CallNextHookEx(0, aCode, aWparam, aLParam);
-}
-
-LRESULT CALLBACK
-PluginInstanceChild::UnitySendMessageHookProc(int aCode, WPARAM aWparam,
-                                              LPARAM aLParam)
-{
-    if (aCode >= 0) {
-        CWPSTRUCT* info = reinterpret_cast<CWPSTRUCT*>(aLParam);
-        MOZ_ASSERT(info);
-        if (sSetCaptureHookData &&
-            sSetCaptureHookData->IsUnityLosingCapture(*info)) {
-            sSetCaptureHookData = nullptr;
-        }
-    }
-
-    return CallNextHookEx(0, aCode, aWparam, aLParam);
-}
-
 /* windowless track popup menu helpers */
 
 BOOL
 WINAPI
 PluginInstanceChild::TrackPopupHookProc(HMENU hMenu,
                                         UINT uFlags,
                                         int x,
                                         int y,
--- a/dom/plugins/ipc/PluginInstanceChild.h
+++ b/dom/plugins/ipc/PluginInstanceChild.h
@@ -313,18 +313,16 @@ private:
     void SizePluginWindow(int width, int height);
     int16_t WinlessHandleEvent(NPEvent& event);
     void CreateWinlessPopupSurrogate();
     void DestroyWinlessPopupSurrogate();
     void InitPopupMenuHook();
     void SetupFlashMsgThrottle();
     void UnhookWinlessFlashThrottle();
     void HookSetWindowLongPtr();
-    void SetUnityHooks();
-    void ClearUnityHooks();
     void InitImm32Hook();
     static inline bool SetWindowLongHookCheck(HWND hWnd,
                                                 int nIndex,
                                                 LONG_PTR newLong);
     void FlashThrottleMessage(HWND, UINT, WPARAM, LPARAM, bool);
     static LRESULT CALLBACK DummyWindowProc(HWND hWnd,
                                             UINT message,
                                             WPARAM wParam,
@@ -335,19 +333,16 @@ private:
                                              LPARAM lParam);
     static BOOL WINAPI TrackPopupHookProc(HMENU hMenu,
                                           UINT uFlags,
                                           int x,
                                           int y,
                                           int nReserved,
                                           HWND hWnd,
                                           CONST RECT *prcRect);
-    static HWND WINAPI SetCaptureHook(HWND aHwnd);
-    static LRESULT CALLBACK UnityGetMessageHookProc(int aCode, WPARAM aWparam, LPARAM aLParam);
-    static LRESULT CALLBACK UnitySendMessageHookProc(int aCode, WPARAM aWparam, LPARAM aLParam);
     static BOOL CALLBACK EnumThreadWindowsCallback(HWND hWnd,
                                                    LPARAM aParam);
     static LRESULT CALLBACK WinlessHiddenFlashWndProc(HWND hWnd,
                                                       UINT message,
                                                       WPARAM wParam,
                                                       LPARAM lParam);
 #ifdef _WIN64
     static LONG_PTR WINAPI SetWindowLongPtrAHook(HWND hWnd,
@@ -470,18 +465,16 @@ private:
     WNDPROC mPluginWndProc;
     HWND mPluginParentHWND;
     int mNestedEventLevelDepth;
     HWND mCachedWinlessPluginHWND;
     HWND mWinlessPopupSurrogateHWND;
     nsIntPoint mPluginSize;
     WNDPROC mWinlessThrottleOldWndProc;
     HWND mWinlessHiddenMsgHWND;
-    HHOOK mUnityGetMessageHook;
-    HHOOK mUnitySendMessageHook;
 #endif
 
     friend class ChildAsyncCall;
 
     Mutex mAsyncCallMutex;
     nsTArray<ChildAsyncCall*> mPendingAsyncCalls;
     nsTArray<nsAutoPtr<ChildTimer> > mTimers;
 
--- a/dom/plugins/ipc/PluginQuirks.cpp
+++ b/dom/plugins/ipc/PluginQuirks.cpp
@@ -36,22 +36,16 @@ int GetQuirksFromMimeTypeAndFilename(con
 #ifdef XP_MACOSX
     // Whitelist Flash to support offline renderer.
     if (specialType == nsPluginHost::eSpecialType_Flash) {
         quirks |= QUIRK_ALLOW_OFFLINE_RENDERER;
     }
 #endif
 
 #ifdef OS_WIN
-    if (specialType == nsPluginHost::eSpecialType_Unity) {
-        quirks |= QUIRK_UNITY_FIXUP_MOUSE_CAPTURE;
-    }
-#endif
-
-#ifdef OS_WIN
     if (specialType == nsPluginHost::eSpecialType_Test) {
         quirks |= QUIRK_WINLESS_HOOK_IME;
     }
 #endif
 
     return quirks;
 }
 
--- a/dom/plugins/ipc/PluginQuirks.h
+++ b/dom/plugins/ipc/PluginQuirks.h
@@ -36,18 +36,16 @@ enum PluginQuirks {
   QUIRK_FLASH_FIXUP_MOUSE_CAPTURE                 = 1 << 6,
   // Mac: Allow the plugin to use offline renderer mode.
   // Use this only if the plugin is certified the support the offline renderer.
   QUIRK_ALLOW_OFFLINE_RENDERER                    = 1 << 9,
   // 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: Addresses a Unity bug with mouse capture.
-  QUIRK_UNITY_FIXUP_MOUSE_CAPTURE                 = 1 << 11,
   // 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,
 };
 
 int GetQuirksFromMimeTypeAndFilename(const nsCString& aMimeType,
                                      const nsCString& aPluginFilename);