Bug 1355147 - Use headless clipboard on macOS. r?jrmuizel draft
authorBrendan Dahl <brendan.dahl@gmail.com>
Wed, 12 Jul 2017 11:52:30 -0700
changeset 617141 ed4538f47409985a052fee874f18003380a8a387
parent 617140 3d52b9f90ffa30e5deb482cbbb2d2e5bea6f90fe
child 639713 0fd5fbfabbb336dd242b8ef41758b903eb2f1fc4
push id70939
push userbmo:bdahl@mozilla.com
push dateFri, 28 Jul 2017 00:20:56 +0000
reviewersjrmuizel
bugs1355147
milestone56.0a1
Bug 1355147 - Use headless clipboard on macOS. r?jrmuizel MozReview-Commit-ID: Fh0GHE34joE
widget/cocoa/nsWidgetFactory.mm
--- a/widget/cocoa/nsWidgetFactory.mm
+++ b/widget/cocoa/nsWidgetFactory.mm
@@ -15,16 +15,18 @@
 #include "nsCocoaWindow.h"
 #include "nsAppShell.h"
 #include "nsAppShellSingleton.h"
 #include "nsFilePicker.h"
 #include "nsColorPicker.h"
 
 #include "nsClipboard.h"
 #include "nsClipboardHelper.h"
+#include "HeadlessClipboard.h"
+#include "gfxPlatform.h"
 #include "nsTransferable.h"
 #include "nsHTMLFormatConverter.h"
 #include "nsDragService.h"
 #include "nsToolkit.h"
 
 #include "nsLookAndFeel.h"
 
 #include "nsSound.h"
@@ -38,24 +40,43 @@
 #include "nsPrintSession.h"
 #include "nsToolkitCompsCID.h"
 
 #include "mozilla/widget/ScreenManager.h"
 
 using namespace mozilla;
 using namespace mozilla::widget;
 
+static nsresult
+nsClipboardConstructor(nsISupports *aOuter, REFNSIID aIID,
+                            void **aResult)
+{
+  nsCOMPtr<nsIClipboard> inst;
+
+  *aResult = nullptr;
+  if (aOuter != nullptr) {
+    return NS_ERROR_NO_AGGREGATION;
+  }
+
+  if (gfxPlatform::IsHeadless()) {
+    inst = new HeadlessClipboard();
+  } else {
+    inst = new nsClipboard();
+  }
+
+  return inst->QueryInterface(aIID, aResult);
+}
+
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsCocoaWindow)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsChildView)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePicker)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsColorPicker)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecX)
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintOptionsX, Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintDialogServiceX, Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintSession, Init)
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIdleServiceX, nsIdleServiceX::GetInstance)
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(ScreenManager, ScreenManager::GetAddRefedSingleton)