Bug 1373739 - Hook HeadlessSound and HeadlessScreenHelper into Windows widgets. r?bdahl draft
authorMichael Smith <michael@spinda.net>
Tue, 11 Jul 2017 14:01:00 -0700
changeset 620653 306d6c5c8a8e1c48c4cfd8b959010841483f8b5e
parent 620652 9bc768274c517cd727f361f2e678ba436a0193a8
child 620654 41e873dc73c139333469f5ed204222bf4f09de5b
push id72121
push userbmo:lists@spinda.net
push dateThu, 03 Aug 2017 18:54:01 +0000
reviewersbdahl
bugs1373739
milestone56.0a1
Bug 1373739 - Hook HeadlessSound and HeadlessScreenHelper into Windows widgets. r?bdahl MozReview-Commit-ID: 1KOlPyLmJaY
widget/windows/nsAppShell.cpp
widget/windows/nsSound.cpp
--- a/widget/windows/nsAppShell.cpp
+++ b/widget/windows/nsAppShell.cpp
@@ -21,16 +21,17 @@
 #include "mozilla/StaticPtr.h"
 #include "nsTHashtable.h"
 #include "nsHashKeys.h"
 #include "GeckoProfiler.h"
 #include "nsComponentManagerUtils.h"
 #include "nsINamed.h"
 #include "nsITimer.h"
 #include "ScreenHelperWin.h"
+#include "HeadlessScreenHelper.h"
 #include "mozilla/widget/ScreenManager.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
 
@@ -247,18 +248,22 @@ nsAppShell::Init()
 
   mEventWnd = CreateWindowW(kWindowClass, L"nsAppShell:EventWindow",
                             0, 0, 0, 10, 10, HWND_MESSAGE, nullptr, module,
                             nullptr);
   NS_ENSURE_STATE(mEventWnd);
 
   if (XRE_IsParentProcess()) {
     ScreenManager& screenManager = ScreenManager::GetSingleton();
-    screenManager.SetHelper(mozilla::MakeUnique<ScreenHelperWin>());
-    ScreenHelperWin::RefreshScreens();
+    if (gfxPlatform::IsHeadless()) {
+      screenManager.SetHelper(mozilla::MakeUnique<HeadlessScreenHelper>());
+    } else {
+      screenManager.SetHelper(mozilla::MakeUnique<ScreenHelperWin>());
+      ScreenHelperWin::RefreshScreens();
+    }
   }
 
   return nsBaseAppShell::Init();
 }
 
 NS_IMETHODIMP
 nsAppShell::Run(void)
 {
--- a/widget/windows/nsSound.cpp
+++ b/widget/windows/nsSound.cpp
@@ -8,16 +8,17 @@
 #include "plstr.h"
 #include <stdio.h>
 #include "nsString.h"
 #include <windows.h>
 
 // mmsystem.h is needed to build with WIN32_LEAN_AND_MEAN
 #include <mmsystem.h>
 
+#include "HeadlessSound.h"
 #include "nsSound.h"
 #include "nsIURL.h"
 #include "nsNetUtil.h"
 #include "nsIChannel.h"
 #include "nsContentUtils.h"
 #include "nsCRT.h"
 #include "nsIObserverService.h"
 
@@ -85,22 +86,26 @@ nsSoundPlayer::~nsSoundPlayer()
 }
 
 mozilla::StaticRefPtr<nsISound> nsSound::sInstance;
 
 /* static */ already_AddRefed<nsISound>
 nsSound::GetInstance()
 {
   if (!sInstance) {
-    RefPtr<nsSound> sound = new nsSound();
-    nsresult rv = sound->CreatePlayerThread();
-    if(NS_WARN_IF(NS_FAILED(rv))) {
-      return nullptr;
+    if (gfxPlatform::IsHeadless()) {
+      sInstance = new widget::HeadlessSound();
+    } else {
+      RefPtr<nsSound> sound = new nsSound();
+      nsresult rv = sound->CreatePlayerThread();
+      if(NS_WARN_IF(NS_FAILED(rv))) {
+        return nullptr;
+      }
+      sInstance = sound.forget();
     }
-    sInstance = sound.forget();
     ClearOnShutdown(&sInstance);
   }
 
   RefPtr<nsISound> service = sInstance;
   return service.forget();
 }
 
 #ifndef SND_PURGE