Bug 933099: Banish <windows.h> from nsGlobalWindow.cpp. r=bz
authorKyle Huey <khuey@kylehuey.com>
Tue, 05 Nov 2013 22:16:25 +0800
changeset 153570 aab2a2b73b900689ad2b16dcd7f3ba694c4fcf2e
parent 153569 092df4b7af995cc635a0a7fd8d638cd7cb44a2cc
child 153571 782ffc958634445db5a6b765e9898426422a66c1
push id35831
push userkhuey@mozilla.com
push dateTue, 05 Nov 2013 14:21:16 +0000
treeherdermozilla-inbound@599442dc0da7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs933099
milestone28.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 933099: Banish <windows.h> from nsGlobalWindow.cpp. r=bz
dom/base/nsGlobalWindow.cpp
dom/interfaces/base/nsITabChild.idl
dom/ipc/TabChild.cpp
dom/ipc/TabChild.h
dom/system/nsDeviceSensors.h
dom/time/TimeChangeObserver.cpp
dom/time/TimeChangeObserver.h
xpcom/base/Debug.cpp
xpcom/base/Debug.h
xpcom/base/moz.build
xpcom/system/nsIDeviceSensors.idl
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -51,37 +51,26 @@
 #include "nsEventListenerManager.h"
 #include "mozilla/dom/BarProps.h"
 #include "nsContentCID.h"
 #include "nsLayoutStatics.h"
 #include "nsCCUncollectableMarker.h"
 #include "mozilla/dom/workers/Workers.h"
 #include "nsJSPrincipals.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/Debug.h"
 #include "mozilla/MouseEvents.h"
 
 // Interfaces Needed
 #include "nsIFrame.h"
 #include "nsCanvasFrame.h"
 #include "nsIWidget.h"
 #include "nsIWidgetListener.h"
 #include "nsIBaseWindow.h"
-#include "nsDeviceSensors.h"
-
-#ifdef XP_WIN
-// Thanks so much, Microsoft and the people who pull in windows.h via
-// random silly headers! :(
-#ifdef GetClassName
-#undef GetClassName
-#endif // GetClassName
-#ifdef CreateEvent
-#undef CreateEvent
-#endif
-#endif // XP_WIN
-
+#include "nsIDeviceSensors.h"
 #include "nsIContent.h"
 #include "nsIDocShell.h"
 #include "nsIDocCharset.h"
 #include "nsIDocument.h"
 #include "Crypto.h"
 #ifndef MOZ_DISABLE_CRYPTOLEGACY
 #include "nsIDOMCryptoLegacy.h"
 #endif
@@ -214,17 +203,17 @@
 #include "nsDOMEventTargetHelper.h"
 #include "prrng.h"
 #include "nsSandboxFlags.h"
 #include "TimeChangeObserver.h"
 #include "mozilla/dom/AudioContext.h"
 #include "mozilla/dom/BrowserElementDictionariesBinding.h"
 #include "mozilla/dom/FunctionBinding.h"
 #include "mozilla/dom/WindowBinding.h"
-#include "mozilla/dom/TabChild.h"
+#include "nsITabChild.h"
 #include "nsIDOMMediaQueryList.h"
 
 #ifdef MOZ_WEBSPEECH
 #include "mozilla/dom/SpeechSynthesis.h"
 #endif
 
 #ifdef MOZ_JSDEBUGGER
 #include "jsdIDebuggerService.h"
@@ -5674,19 +5663,17 @@ nsGlobalWindow::Dump(const nsAString& aS
     if (*c == '\r')
       *c = '\n';
     c++;
   }
 #endif
 
   if (cstr) {
 #ifdef XP_WIN
-    if (IsDebuggerPresent()) {
-      OutputDebugStringA(cstr);
-    }
+    PrintToDebugger(cstr);
 #endif
 #ifdef ANDROID
     __android_log_write(ANDROID_LOG_INFO, "GeckoDump", cstr);
 #endif
     FILE *fp = gDumpFile ? gDumpFile : stdout;
     fputs(cstr, fp);
     fflush(fp);
     nsMemory::Free(cstr);
@@ -6223,17 +6210,17 @@ nsGlobalWindow::Focus(ErrorResult& aErro
     if (frameElement) {
       uint32_t flags = nsIFocusManager::FLAG_NOSCROLL;
       if (canFocus)
         flags |= nsIFocusManager::FLAG_RAISE;
       aError = fm->SetFocus(frameElement, flags);
     }
     return;
   }
-  if (TabChild *child = TabChild::GetFrom(this)) {
+  if (nsCOMPtr<nsITabChild> child = do_GetInterface(mDocShell)) {
     child->SendRequestFocus(canFocus);
     return;
   }
   if (canFocus) {
     // if there is no parent, this must be a toplevel window, so raise the
     // window if canFocus is true
     aError = fm->SetActiveWindow(this);
   }
@@ -12559,23 +12546,23 @@ nsGlobalWindow::SetHasGamepadEventListen
   if (aHasGamepad) {
     EnableGamepadUpdates();
   }
 }
 
 void
 nsGlobalWindow::EnableTimeChangeNotifications()
 {
-  nsSystemTimeChangeObserver::AddWindowListener(this);
+  mozilla::time::AddWindowListener(this);
 }
 
 void
 nsGlobalWindow::DisableTimeChangeNotifications()
 {
-  nsSystemTimeChangeObserver::RemoveWindowListener(this);
+  mozilla::time::RemoveWindowListener(this);
 }
 
 static PLDHashOperator
 CollectSizeAndListenerCount(
   nsPtrHashKey<nsDOMEventTargetHelper> *aEntry,
   void *arg)
 {
   nsWindowSizes* windowSizes = static_cast<nsWindowSizes*>(arg);
@@ -13207,8 +13194,12 @@ nsGlobalWindow::DisableNetworkEvent(uint
 #define WINDOW_ONLY_EVENT EVENT
 #define TOUCH_EVENT EVENT
 #include "nsEventNameList.h"
 #undef TOUCH_EVENT
 #undef WINDOW_ONLY_EVENT
 #undef BEFOREUNLOAD_EVENT
 #undef ERROR_EVENT
 #undef EVENT
+
+#ifdef _WINDOWS_
+#error "Never include windows.h in this file!"
+#endif
--- a/dom/interfaces/base/nsITabChild.idl
+++ b/dom/interfaces/base/nsITabChild.idl
@@ -1,15 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
 
 #include "domstubs.idl"
 interface nsIContentFrameMessageManager;
 
-// Sole purpose is to be able to identify the concrete class nsTabChild
-[uuid(bf1eddf9-731b-4a4b-bd65-9a712a892832)]
+[uuid( 60146bc6-31d8-450b-a9eb-4000b6403d5c)]
 interface nsITabChild : nsISupports
 {
   readonly attribute nsIContentFrameMessageManager messageManager;
+
+  [notxpcom] void sendRequestFocus(in boolean canFocus);
 };
 
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -66,16 +66,20 @@
 #include "PuppetWidget.h"
 #include "StructuredCloneUtils.h"
 #include "nsViewportInfo.h"
 #include "JavaScriptChild.h"
 #include "APZCCallbackHelper.h"
 #include "nsILoadContext.h"
 #include "ipc/nsGUIEventIPC.h"
 
+#ifdef DEBUG
+#include "PCOMContentPermissionRequestChild.h"
+#endif /* DEBUG */
+
 #define BROWSER_ELEMENT_CHILD_SCRIPT \
     NS_LITERAL_STRING("chrome://global/content/BrowserElementChild.js")
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::dom::ipc;
 using namespace mozilla::ipc;
 using namespace mozilla::layers;
@@ -1136,16 +1140,30 @@ TabChild::ArraysToParams(const Infallibl
       aParams->SetInt(i, aIntParams[i]);
     }
     for (int32_t j = 0; uint32_t(j) < aStringParams.Length(); ++j) {
       aParams->SetString(j, aStringParams[j].get());
     }
   }
 }
 
+#ifdef DEBUG
+PContentPermissionRequestChild*
+TabChild:: SendPContentPermissionRequestConstructor(PContentPermissionRequestChild* aActor,
+                                                    const nsCString& aType,
+                                                    const nsCString& aAccess,
+                                                    const IPC::Principal& aPrincipal)
+{
+  PCOMContentPermissionRequestChild* child = static_cast<PCOMContentPermissionRequestChild*>(aActor);
+  PContentPermissionRequestChild* request = PBrowserChild::SendPContentPermissionRequestConstructor(aActor, aType, aAccess, aPrincipal);
+  child->mIPCOpen = true;
+  return request;
+}
+#endif /* DEBUG */
+
 void
 TabChild::DestroyWindow()
 {
     nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(mWebNav);
     if (baseWindow)
         baseWindow->Destroy();
 
     // NB: the order of mWidget->Destroy() and mRemoteFrame->Destroy()
@@ -2354,16 +2372,22 @@ TabChild::GetMessageManager(nsIContentFr
   if (mTabChildGlobal) {
     NS_ADDREF(*aResult = mTabChildGlobal);
     return NS_OK;
   }
   *aResult = nullptr;
   return NS_ERROR_FAILURE;
 }
 
+void
+TabChild::SendRequestFocus(bool aCanFocus)
+{
+  PBrowserChild::SendRequestFocus(aCanFocus);
+}
+
 PIndexedDBChild*
 TabChild::AllocPIndexedDBChild(
                             const nsCString& aGroup,
                             const nsCString& aASCIIOrigin, bool* /* aAllowed */)
 {
   NS_NOTREACHED("Should never get here!");
   return nullptr;
 }
--- a/dom/ipc/TabChild.h
+++ b/dom/ipc/TabChild.h
@@ -3,19 +3,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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 mozilla_dom_TabChild_h
 #define mozilla_dom_TabChild_h
 
 #include "mozilla/dom/PBrowserChild.h"
-#ifdef DEBUG
-#include "PCOMContentPermissionRequestChild.h"
-#endif /* DEBUG */
 #include "nsIWebNavigation.h"
 #include "nsCOMPtr.h"
 #include "nsAutoPtr.h"
 #include "nsEventDispatcher.h"
 #include "nsIWebBrowserChrome2.h"
 #include "nsIEmbeddingSiteWindow.h"
 #include "nsIWebBrowserChromeFocus.h"
 #include "nsIDOMEventListener.h"
@@ -265,26 +262,21 @@ public:
     static void ParamsToArrays(nsIDialogParamBlock* aParams,
                                InfallibleTArray<int>& aIntParams,
                                InfallibleTArray<nsString>& aStringParams);
     static void ArraysToParams(const InfallibleTArray<int>& aIntParams,
                                const InfallibleTArray<nsString>& aStringParams,
                                nsIDialogParamBlock* aParams);
 
 #ifdef DEBUG
-    virtual PContentPermissionRequestChild* SendPContentPermissionRequestConstructor(PContentPermissionRequestChild* aActor,
-                                                                                     const nsCString& aType,
-                                                                                     const nsCString& aAccess,
-                                                                                     const IPC::Principal& aPrincipal)
-    {
-      PCOMContentPermissionRequestChild* child = static_cast<PCOMContentPermissionRequestChild*>(aActor);
-      PContentPermissionRequestChild* request = PBrowserChild::SendPContentPermissionRequestConstructor(aActor, aType, aAccess, aPrincipal);
-      child->mIPCOpen = true;
-      return request;
-    }
+    virtual PContentPermissionRequestChild*
+    SendPContentPermissionRequestConstructor(PContentPermissionRequestChild* aActor,
+                                             const nsCString& aType,
+                                             const nsCString& aAccess,
+                                             const IPC::Principal& aPrincipal);
 #endif /* DEBUG */
 
     virtual PContentPermissionRequestChild* AllocPContentPermissionRequestChild(const nsCString& aType,
                                                                                 const nsCString& aAccess,
                                                                                 const IPC::Principal& aPrincipal);
     virtual bool DeallocPContentPermissionRequestChild(PContentPermissionRequestChild* actor);
 
     virtual POfflineCacheUpdateChild* AllocPOfflineCacheUpdateChild(
--- a/dom/system/nsDeviceSensors.h
+++ b/dom/system/nsDeviceSensors.h
@@ -13,22 +13,16 @@
 #include "nsITimer.h"
 #include "nsIDOMDeviceOrientationEvent.h"
 #include "nsIDOMDeviceMotionEvent.h"
 #include "nsDOMDeviceMotionEvent.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/HalSensor.h"
 #include "nsDataHashtable.h"
 
-#define NS_DEVICE_SENSORS_CID \
-{ 0xecba5203, 0x77da, 0x465a, \
-{ 0x86, 0x5e, 0x78, 0xb7, 0xaf, 0x10, 0xd8, 0xf7 } }
-
-#define NS_DEVICE_SENSORS_CONTRACTID "@mozilla.org/devicesensors;1"
-
 class nsIDOMWindow;
 
 namespace mozilla {
 namespace dom {
 class EventTarget;
 }
 }
 
--- a/dom/time/TimeChangeObserver.cpp
+++ b/dom/time/TimeChangeObserver.cpp
@@ -1,27 +1,56 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
 #include "TimeChangeObserver.h"
+#include "mozilla/Hal.h"
+#include "mozilla/Observer.h"
+#include "mozilla/HalTypes.h"
+#include "nsWeakPtr.h"
+#include "nsTObserverArray.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "mozilla/Services.h"
 #include "mozilla/StaticPtr.h"
 #include "nsPIDOMWindow.h"
 #include "nsDOMEvent.h"
 #include "nsContentUtils.h"
 #include "nsIObserverService.h"
 #include "nsIDocument.h"
 
 using namespace mozilla;
 using namespace mozilla::hal;
 using namespace mozilla::services;
 
+class nsSystemTimeChangeObserver : public SystemClockChangeObserver,
+                                   public SystemTimezoneChangeObserver
+{
+  typedef nsTObserverArray<nsWeakPtr> ListenerArray;
+public:
+  static nsSystemTimeChangeObserver* GetInstance();
+  virtual ~nsSystemTimeChangeObserver();
+
+  // Implementing hal::SystemClockChangeObserver::Notify()
+  void Notify(const int64_t& aClockDeltaMS);
+
+  // Implementing hal::SystemTimezoneChangeObserver::Notify()
+  void Notify(
+    const mozilla::hal::SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo);
+
+  nsresult AddWindowListenerImpl(nsPIDOMWindow* aWindow);
+  nsresult RemoveWindowListenerImpl(nsPIDOMWindow* aWindow);
+
+private:
+  nsSystemTimeChangeObserver() { };
+  ListenerArray mWindowListeners;
+  void FireMozTimeChangeEvent();
+};
+
 StaticAutoPtr<nsSystemTimeChangeObserver> sObserver;
 
 nsSystemTimeChangeObserver* nsSystemTimeChangeObserver::GetInstance()
 {
   if (!sObserver) {
     sObserver = new nsSystemTimeChangeObserver();
     ClearOnShutdown(&sObserver);
   }
@@ -74,19 +103,19 @@ nsSystemTimeChangeObserver::Notify(const
 void
 nsSystemTimeChangeObserver::Notify(
   const SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo)
 {
   FireMozTimeChangeEvent();
 }
 
 nsresult
-nsSystemTimeChangeObserver::AddWindowListener(nsPIDOMWindow* aWindow)
+mozilla::time::AddWindowListener(nsPIDOMWindow* aWindow)
 {
-  return GetInstance()->AddWindowListenerImpl(aWindow);
+  return nsSystemTimeChangeObserver::GetInstance()->AddWindowListenerImpl(aWindow);
 }
 
 nsresult
 nsSystemTimeChangeObserver::AddWindowListenerImpl(nsPIDOMWindow* aWindow)
 {
   if (!aWindow) {
     return NS_ERROR_ILLEGAL_VALUE;
   }
@@ -111,23 +140,23 @@ nsSystemTimeChangeObserver::AddWindowLis
     RegisterSystemTimezoneChangeObserver(sObserver);
   }
 
   mWindowListeners.AppendElement(windowWeakRef);
   return NS_OK;
 }
 
 nsresult
-nsSystemTimeChangeObserver::RemoveWindowListener(nsPIDOMWindow* aWindow)
+mozilla::time::RemoveWindowListener(nsPIDOMWindow* aWindow)
 {
   if (!sObserver) {
     return NS_OK;
   }
 
-  return GetInstance()->RemoveWindowListenerImpl(aWindow);
+  return nsSystemTimeChangeObserver::GetInstance()->RemoveWindowListenerImpl(aWindow);
 }
 
 nsresult
 nsSystemTimeChangeObserver::RemoveWindowListenerImpl(nsPIDOMWindow* aWindow)
 {
   if (!aWindow) {
     return NS_OK;
   }
--- a/dom/time/TimeChangeObserver.h
+++ b/dom/time/TimeChangeObserver.h
@@ -1,44 +1,22 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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 _mozilla_time_change_observer_h_
 #define _mozilla_time_change_observer_h_
 
-#include "mozilla/Hal.h"
-#include "mozilla/Observer.h"
-#include "mozilla/HalTypes.h"
-#include "nsPIDOMWindow.h"
-#include "nsWeakPtr.h"
-#include "nsTObserverArray.h"
+#include "nscore.h"
 
-typedef mozilla::Observer<int64_t> SystemClockChangeObserver;
-typedef mozilla::Observer<mozilla::hal::SystemTimezoneChangeInformation> SystemTimezoneChangeObserver;
+class nsPIDOMWindow;
 
-class nsSystemTimeChangeObserver : public SystemClockChangeObserver,
-                                   public SystemTimezoneChangeObserver
-{
-  typedef nsTObserverArray<nsWeakPtr> ListenerArray;
-public:
-  static nsSystemTimeChangeObserver* GetInstance();
-  virtual ~nsSystemTimeChangeObserver();
-
-  // Implementing hal::SystemClockChangeObserver::Notify()
-  void Notify(const int64_t& aClockDeltaMS);
+namespace mozilla {
+namespace time {
 
-  // Implementing hal::SystemTimezoneChangeObserver::Notify()
-  void Notify(
-    const mozilla::hal::SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo);
+nsresult AddWindowListener(nsPIDOMWindow* aWindow);
+nsresult RemoveWindowListener(nsPIDOMWindow* aWindow);
 
-  static nsresult AddWindowListener(nsPIDOMWindow* aWindow);
-  static nsresult RemoveWindowListener(nsPIDOMWindow* aWindow);
-private:
-  nsresult AddWindowListenerImpl(nsPIDOMWindow* aWindow);
-  nsresult RemoveWindowListenerImpl(nsPIDOMWindow* aWindow);
-  nsSystemTimeChangeObserver() { };
-  ListenerArray mWindowListeners;
-  void FireMozTimeChangeEvent();
-};
+} // namespace time
+} // namespace mozilla
 
 #endif //_mozilla_time_change_observer_h_
new file mode 100644
--- /dev/null
+++ b/xpcom/base/Debug.cpp
@@ -0,0 +1,21 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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/. */
+
+#include "mozilla/Debug.h"
+
+#ifdef XP_WIN
+#include <windows.h>
+#endif
+
+#ifdef XP_WIN
+
+void mozilla::PrintToDebugger(const char* aStr)
+{
+  if (::IsDebuggerPresent()) {
+    ::OutputDebugStringA(aStr);
+  }
+}
+
+#endif
new file mode 100644
--- /dev/null
+++ b/xpcom/base/Debug.h
@@ -0,0 +1,20 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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 mozilla_Debug_h__
+#define mozilla_Debug_h__
+
+namespace mozilla {
+
+#ifdef XP_WIN
+
+// Print aStr to a debugger if the debugger is attached.
+void PrintToDebugger(const char* aStr);
+
+#endif
+
+} // namespace mozilla
+
+#endif // mozilla_Debug_h__
--- a/xpcom/base/moz.build
+++ b/xpcom/base/moz.build
@@ -70,32 +70,34 @@ if CONFIG['OS_ARCH'] == 'WINNT':
     if CONFIG['MOZ_DEBUG']:
         EXPORTS += ['pure.h']
         SOURCES += ['pure_api.c']
 
 EXPORTS.mozilla += [
     'AvailableMemoryTracker.h',
     'ClearOnShutdown.h',
     'CycleCollectedJSRuntime.h',
+    'Debug.h',
     'nsMemoryInfoDumper.h',
     'StackWalk.h',
     'StaticMutex.h',
     'StaticPtr.h',
     'VisualEventTracer.h',
 ]
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     EXPORTS.mozilla += [
         'WindowsVersion.h',
     ]
 
 SOURCES += [
     'AvailableMemoryTracker.cpp',
     'ClearOnShutdown.cpp',
     'CycleCollectedJSRuntime.cpp',
+    'Debug.cpp',
     'nsConsoleMessage.cpp',
     'nsConsoleService.cpp',
     'nsCycleCollector.cpp',
     'nsDebugImpl.cpp',
     'nsErrorService.cpp',
     'nsGZFileWriter.cpp',
     'nsInterfaceRequestorAgg.cpp',
     'nsMemoryImpl.cpp',
--- a/xpcom/system/nsIDeviceSensors.idl
+++ b/xpcom/system/nsIDeviceSensors.idl
@@ -34,8 +34,18 @@ interface nsIDeviceSensors : nsISupports
 
   // Holds pointers, not AddRef objects -- it is up to the caller
   // to call RemoveWindowListener before the window is deleted.
 
   [noscript] void addWindowListener(in unsigned long aType, in nsIDOMWindow aWindow);
   [noscript] void removeWindowListener(in unsigned long aType, in nsIDOMWindow aWindow);
   [noscript] void removeWindowAsListener(in nsIDOMWindow aWindow);
 };
+
+%{C++
+
+#define NS_DEVICE_SENSORS_CID \
+{ 0xecba5203, 0x77da, 0x465a, \
+{ 0x86, 0x5e, 0x78, 0xb7, 0xaf, 0x10, 0xd8, 0xf7 } }
+
+#define NS_DEVICE_SENSORS_CONTRACTID "@mozilla.org/devicesensors;1"
+
+%}