Bug 1334257: Assure that TIPMessageHandler hooks may not be instantiated more than once; r?jimm draft
authorAaron Klotz <aklotz@mozilla.com>
Thu, 26 Jan 2017 15:30:44 -0700
changeset 466928 4287fdc8ec361ec1206af291457543f37863efab
parent 465527 8ff550409e1d1f8b54f6f7f115545dbef857be0b
child 543575 ab599f8df29dabc96d407a64bd6ef678c92d42d5
push id43057
push useraklotz@mozilla.com
push dateThu, 26 Jan 2017 22:31:38 +0000
reviewersjimm
bugs1334257
milestone54.0a1
Bug 1334257: Assure that TIPMessageHandler hooks may not be instantiated more than once; r?jimm MozReview-Commit-ID: LiDQ9yUzGTK
widget/windows/nsWindow.cpp
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -409,21 +409,24 @@ public:
   {
     if (mHook) {
       ::UnhookWindowsHookEx(mHook);
     }
   }
 
   static void Initialize()
   {
-    MOZ_ASSERT(!sInstance);
     if (!IsWin8OrLater()) {
       return;
     }
 
+    if (sInstance) {
+      return;
+    }
+
     sInstance = new TIPMessageHandler();
     ClearOnShutdown(&sInstance);
   }
 
   static bool IsA11yBlocked()
   {
     if (!sInstance) {
       return false;
@@ -447,31 +450,32 @@ private:
     mMessages[4] = ::RegisterWindowMessage(L"ProgrammabilityCaretVisibility");
     mMessages[5] = ::RegisterWindowMessage(L"CaretTrackingUpdateIPHidden");
     mMessages[6] = ::RegisterWindowMessage(L"CaretTrackingUpdateIPInfo");
 
     mHook = ::SetWindowsHookEx(WH_GETMESSAGE, &TIPHook, nullptr,
                                ::GetCurrentThreadId());
     MOZ_ASSERT(mHook);
 
-    if (!IsWin10OrLater()) {
+    if (!IsWin10OrLater() && !sProcessCaretEventsStub) {
       // tiptsf loads when STA COM is first initialized, so it should be present
       sTipTsfInterceptor.Init("tiptsf.dll");
       DebugOnly<bool> ok = sTipTsfInterceptor.AddHook("ProcessCaretEvents",
           reinterpret_cast<intptr_t>(&ProcessCaretEventsHook),
           (void**) &sProcessCaretEventsStub);
       MOZ_ASSERT(ok);
     }
 
-    MOZ_ASSERT(!sSendMessageTimeoutWStub);
-    sUser32Intercept.Init("user32.dll");
-    DebugOnly<bool> hooked = sUser32Intercept.AddHook("SendMessageTimeoutW",
-        reinterpret_cast<intptr_t>(&SendMessageTimeoutWHook),
-        (void**) &sSendMessageTimeoutWStub);
-    MOZ_ASSERT(hooked);
+    if (!sSendMessageTimeoutWStub) {
+      sUser32Intercept.Init("user32.dll");
+      DebugOnly<bool> hooked = sUser32Intercept.AddHook("SendMessageTimeoutW",
+          reinterpret_cast<intptr_t>(&SendMessageTimeoutWHook),
+          (void**) &sSendMessageTimeoutWStub);
+      MOZ_ASSERT(hooked);
+    }
   }
 
   class MOZ_RAII A11yInstantiationBlocker
   {
   public:
     A11yInstantiationBlocker()
     {
       if (!TIPMessageHandler::sInstance) {