Bug 1152353: Repost printer properties completion messages after nsAppShell::ProcessNextNativeEvent. r=jimm
authorBob Owen <bobowencode@gmail.com>
Wed, 15 Mar 2017 15:55:50 +0000
changeset 348674 471695817852
parent 348673 24fb27182a1d
child 348675 2f06ca112a30
push id31533
push userkwierso@gmail.com
push dateTue, 21 Mar 2017 23:08:53 +0000
treeherdermozilla-central@8744e9f8eb99 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs1152353
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1152353: Repost printer properties completion messages after nsAppShell::ProcessNextNativeEvent. r=jimm
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__