Bug 1152353: Repost printer properties completion messages after nsAppShell::ProcessNextNativeEvent. r=jimm a=gchang
authorBob Owen <bobowencode@gmail.com>
Wed, 15 Mar 2017 15:55:50 +0000
changeset 395612 cabc0989190a4bd1343748942e0b8011e4a00c83
parent 395611 f26e2606488b9e01e63bdb8670d22bb8da77b4d2
child 395613 398928fbc827f9cd1c8d6f6a1c385208782e3d3f
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm, gchang
bugs1152353
milestone54.0a2
Bug 1152353: Repost printer properties completion messages after nsAppShell::ProcessNextNativeEvent. r=jimm a=gchang
widget/windows/nsAppShell.cpp
widget/windows/nsAppShell.h
--- a/widget/windows/nsAppShell.cpp
+++ b/widget/windows/nsAppShell.cpp
@@ -20,16 +20,22 @@
 #include "nsIPowerManagerService.h"
 #include "mozilla/StaticPtr.h"
 #include "nsTHashtable.h"
 #include "nsHashKeys.h"
 #include "GeckoProfiler.h"
 #include "nsComponentManagerUtils.h"
 #include "nsITimer.h"
 
+// These are two messages that the code in winspool.drv on Windows 7 explicitly
+// waits for while it is pumping other Windows messages, during display of the
+// Printer Properties dialog.
+#define MOZ_WM_PRINTER_PROPERTIES_COMPLETION 0x5b7a
+#define MOZ_WM_PRINTER_PROPERTIES_FAILURE 0x5b7f
+
 using namespace mozilla;
 using namespace mozilla::widget;
 
 #define WAKE_LOCK_LOG(...) MOZ_LOG(GetWinWakeLockLog(), mozilla::LogLevel::Debug, (__VA_ARGS__))
 PRLogModuleInfo* GetWinWakeLockLog() {
   static PRLogModuleInfo* log = nullptr;
   if (!log) {
     log = PR_NewLogModule("WinWakeLock");
@@ -367,16 +373,25 @@ nsAppShell::ProcessNextNativeEvent(bool 
           uiMessage ? mozilla::HangMonitor::kUIActivity :
                       mozilla::HangMonitor::kActivityNoUIAVail);
 
         if (msg.message >= WM_KEYFIRST && msg.message <= WM_KEYLAST &&
             IMEHandler::ProcessRawKeyMessage(msg)) {
           continue;  // the message is consumed.
         }
 
+        // Store Printer Properties messages for reposting, because they are not
+        // processed by a window procedure, but are explicitly waited for in the
+        // winspool.drv code that will be further up the stack.
+        if (msg.message == MOZ_WM_PRINTER_PROPERTIES_COMPLETION ||
+            msg.message == MOZ_WM_PRINTER_PROPERTIES_FAILURE) {
+          mMsgsToRepost.push_back(msg);
+          continue;
+        }
+
         ::TranslateMessage(&msg);
         ::DispatchMessageW(&msg);
       }
     } else if (mayWait) {
       // Block and wait for any posted application message
       mozilla::HangMonitor::Suspend();
       {
         GeckoProfilerThreadSleepRAII sleep;
@@ -402,8 +417,21 @@ nsAppShell::ProcessNextNativeEvent(bool 
         TimeStamp::NowLoRes() - mLastNativeEventScheduled;
   }
   if (timeSinceLastNativeEventScheduled > nativeEventStarvationLimit) {
     ScheduleNativeEventCallback();
   }
 
   return gotMessage;
 }
+
+nsresult
+nsAppShell::AfterProcessNextEvent(nsIThreadInternal* /* unused */,
+                                  bool /* unused */)
+{
+  if (!mMsgsToRepost.empty()) {
+    for (MSG msg : mMsgsToRepost) {
+      ::PostMessageW(msg.hwnd, msg.message, msg.wParam, msg.lParam);
+    }
+    mMsgsToRepost.clear();
+  }
+  return NS_OK;
+}
--- a/widget/windows/nsAppShell.h
+++ b/widget/windows/nsAppShell.h
@@ -3,16 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsAppShell_h__
 #define nsAppShell_h__
 
 #include "nsBaseAppShell.h"
 #include <windows.h>
+#include <vector>
 #include "mozilla/TimeStamp.h"
 #include "mozilla/Mutex.h"
 
 // The maximum time we allow before forcing a native event callback.
 // In seconds.
 #define NATIVE_EVENT_STARVATION_LIMIT 1
 
 /**
@@ -29,26 +30,30 @@ public:
   typedef mozilla::TimeStamp TimeStamp;
   typedef mozilla::Mutex Mutex;
 
   nsresult Init();
   void DoProcessMoreGeckoEvents();
 
   static UINT GetTaskbarButtonCreatedMessage();
 
+  NS_IMETHOD AfterProcessNextEvent(nsIThreadInternal* thread,
+                                   bool eventWasProcessed) final;
+
 protected:
   NS_IMETHOD Run();
   NS_IMETHOD Exit();
   virtual void ScheduleNativeEventCallback();
   virtual bool ProcessNextNativeEvent(bool mayWait);
   virtual ~nsAppShell();
 
   static LRESULT CALLBACK EventWindowProc(HWND, UINT, WPARAM, LPARAM);
 
 protected:
   HWND mEventWnd;
   bool mNativeCallbackPending;
 
   Mutex mLastNativeEventScheduledMutex;
   TimeStamp mLastNativeEventScheduled;
+  std::vector<MSG> mMsgsToRepost;
 };
 
 #endif // nsAppShell_h__