Bug 545760 - '[OOPP] Fix a few bad DefWindowProc messages that slipped through'. WM_SETICON. r=jimm.
authorBen Turner <bent.mozilla@gmail.com>
Thu, 18 Feb 2010 12:11:31 -0800
changeset 38275 ed31386b285cd6600dedb0c12617980ccebfc4db
parent 38274 d77738c37f29d300615955ac59c844ff9e8e463b
child 38276 9a30558d9f8111b975843ddbd62ff35771dd47ff
push idunknown
push userunknown
push dateunknown
reviewersjimm
bugs545760
milestone1.9.3a2pre
Bug 545760 - '[OOPP] Fix a few bad DefWindowProc messages that slipped through'. WM_SETICON. r=jimm.
ipc/glue/WindowsMessageLoop.cpp
ipc/glue/WindowsMessageLoop.h
--- a/ipc/glue/WindowsMessageLoop.cpp
+++ b/ipc/glue/WindowsMessageLoop.cpp
@@ -283,23 +283,27 @@ ProcessOrDeferMessage(HWND hwnd,
       break;
     }
 
     case WM_STYLECHANGED: {
       deferred = new DeferredStyleChangeMessage(hwnd, wParam, lParam);
       break;
     }
 
+    case WM_SETICON: {
+      deferred = new DeferredSetIconMessage(hwnd, uMsg, wParam, lParam);
+      break;
+    }
+
     // Messages that are safe to pass to DefWindowProc go here.
     case WM_ENTERIDLE:
     case WM_GETICON:
     case WM_GETMINMAXINFO:
     case WM_GETTEXT:
     case WM_NCHITTEST:
-    case WM_SETICON:
     case WM_STYLECHANGING:
     case WM_SYNCPAINT: // Intentional fall-through.
     case WM_WINDOWPOSCHANGING: {
       return DefWindowProc(hwnd, uMsg, wParam, lParam);
     }
 
     // Unknown messages only.
     default: {
@@ -1136,8 +1140,40 @@ DeferredStyleChangeMessage::DeferredStyl
   style = reinterpret_cast<STYLESTRUCT*>(aLParam)->styleNew;
 }
 
 void
 DeferredStyleChangeMessage::Run()
 {
   SetWindowLongPtr(hWnd, index, style);
 }
+
+DeferredSetIconMessage::DeferredSetIconMessage(HWND aHWnd,
+                                               UINT aMessage,
+                                               WPARAM aWParam,
+                                               LPARAM aLParam)
+: DeferredSendMessage(aHWnd, aMessage, aWParam, aLParam)
+{
+  NS_ASSERTION(aMessage == WM_SETICON, "Wrong message type!");
+}
+
+void
+DeferredSetIconMessage::Run()
+{
+  AssertWindowIsNotNeutered(hWnd);
+  if (!IsWindow(hWnd)) {
+    NS_ERROR("Invalid window!");
+    return;
+  }
+
+  WNDPROC wndproc =
+    reinterpret_cast<WNDPROC>(GetWindowLongPtr(hWnd, GWLP_WNDPROC));
+  if (!wndproc) {
+    NS_ERROR("Invalid window procedure!");
+    return;
+  }
+
+  HICON hOld = reinterpret_cast<HICON>(
+    CallWindowProc(wndproc, hWnd, message, wParam, lParam));
+  if (hOld) {
+    DestroyIcon(hOld);
+  }
+}
--- a/ipc/glue/WindowsMessageLoop.h
+++ b/ipc/glue/WindowsMessageLoop.h
@@ -178,13 +178,24 @@ public:
   virtual void Run();
 
 private:
   HWND hWnd;
   int index;
   LONG_PTR style;
 };
 
+class DeferredSetIconMessage : public DeferredSendMessage
+{
+public:
+  DeferredSetIconMessage(HWND aHWnd,
+                         UINT aMessage,
+                         WPARAM aWParam,
+                         LPARAM aLParam);
+
+  virtual void Run();
+};
+
 } /* namespace windows */
 } /* namespace ipc */
 } /* namespace mozilla */
 
 #endif /* IPC_GLUE_WINDOWSMESSAGELOOP_H */