Bug 1491576 - Remove the XPCOM registration for nsNativeAppSupportBase; r=mccr8
authorEhsan Akhgari <ehsan@mozilla.com>
Sat, 15 Sep 2018 13:17:11 -0400
changeset 436553 9552ef9a5df03282df032f796fbaa026a1293dfc
parent 436552 b8d0ac50695061fb2488c48a79adb5ad20ed973e
child 436554 081068e0f495118e338fcd16529c2e66eac7bb77
push id34649
push useraciure@mozilla.com
push dateSat, 15 Sep 2018 21:40:43 +0000
treeherdermozilla-central@5d14d1e9f74d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1491576
milestone64.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 1491576 - Remove the XPCOM registration for nsNativeAppSupportBase; r=mccr8 Differential Revision: https://phabricator.services.mozilla.com/D5951
toolkit/xre/MacApplicationDelegate.mm
toolkit/xre/nsAppRunner.cpp
toolkit/xre/nsAppRunner.h
--- a/toolkit/xre/MacApplicationDelegate.mm
+++ b/toolkit/xre/MacApplicationDelegate.mm
@@ -169,17 +169,17 @@ ProcessPendingGetURLAppleEvents()
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 // The method that NSApplication calls upon a request to reopen, such as when
 // the Dock icon is clicked and no windows are open. A "visible" window may be
 // miniaturized, so we can't skip nsCocoaNativeReOpen() if 'flag' is 'true'.
 - (BOOL)applicationShouldHandleReopen:(NSApplication*)theApp hasVisibleWindows:(BOOL)flag
 {
-  nsCOMPtr<nsINativeAppSupport> nas = do_CreateInstance(NS_NATIVEAPPSUPPORT_CONTRACTID);
+  nsCOMPtr<nsINativeAppSupport> nas = NS_GetNativeAppSupport();
   NS_ENSURE_TRUE(nas, NO);
 
   // Go to the common Carbon/Cocoa reopen method.
   nsresult rv = nas->ReOpen();
   NS_ENSURE_SUCCESS(rv, NO);
 
   // NO says we don't want NSApplication to do anything else for us.
   return NO;
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -1394,21 +1394,21 @@ class ScopedXPCOMStartup
 public:
   ScopedXPCOMStartup() :
     mServiceManager(nullptr) { }
   ~ScopedXPCOMStartup();
 
   nsresult Initialize();
   nsresult SetWindowCreator(nsINativeAppSupport* native);
 
-  static nsresult CreateAppSupport(nsISupports* aOuter, REFNSIID aIID, void** aResult);
-
 private:
   nsIServiceManager* mServiceManager;
   static nsINativeAppSupport* gNativeAppSupport;
+
+  friend already_AddRefed<nsINativeAppSupport> NS_GetNativeAppSupport();
 };
 
 ScopedXPCOMStartup::~ScopedXPCOMStartup()
 {
   NS_IF_RELEASE(gNativeAppSupport);
 
   if (mServiceManager) {
 #ifdef XP_MACOSX
@@ -1430,20 +1430,16 @@ ScopedXPCOMStartup::~ScopedXPCOMStartup(
     mServiceManager = nullptr;
   }
 }
 
 // {95d89e3e-a169-41a3-8e56-719978e15b12}
 #define APPINFO_CID \
   { 0x95d89e3e, 0xa169, 0x41a3, { 0x8e, 0x56, 0x71, 0x99, 0x78, 0xe1, 0x5b, 0x12 } }
 
-// {0C4A446C-EE82-41f2-8D04-D366D2C7A7D4}
-static const nsCID kNativeAppSupportCID =
-  { 0xc4a446c, 0xee82, 0x41f2, { 0x8d, 0x4, 0xd3, 0x66, 0xd2, 0xc7, 0xa7, 0xd4 } };
-
 // {5F5E59CE-27BC-47eb-9D1F-B09CA9049836}
 static const nsCID kProfileServiceCID =
   { 0x5f5e59ce, 0x27bc, 0x47eb, { 0x9d, 0x1f, 0xb0, 0x9c, 0xa9, 0x4, 0x98, 0x36 } };
 
 static already_AddRefed<nsIFactory>
 ProfileServiceFactoryConstructor(const mozilla::Module& module, const mozilla::Module::CIDEntry& entry)
 {
   nsCOMPtr<nsIFactory> factory;
@@ -1451,28 +1447,26 @@ ProfileServiceFactoryConstructor(const m
   return factory.forget();
 }
 
 NS_DEFINE_NAMED_CID(APPINFO_CID);
 
 static const mozilla::Module::CIDEntry kXRECIDs[] = {
   { &kAPPINFO_CID, false, nullptr, AppInfoConstructor },
   { &kProfileServiceCID, false, ProfileServiceFactoryConstructor, nullptr },
-  { &kNativeAppSupportCID, false, nullptr, ScopedXPCOMStartup::CreateAppSupport },
   { nullptr }
 };
 
 static const mozilla::Module::ContractIDEntry kXREContracts[] = {
   { XULAPPINFO_SERVICE_CONTRACTID, &kAPPINFO_CID },
   { XULRUNTIME_SERVICE_CONTRACTID, &kAPPINFO_CID },
 #ifdef MOZ_CRASHREPORTER
   { NS_CRASHREPORTER_CONTRACTID, &kAPPINFO_CID },
 #endif // MOZ_CRASHREPORTER
   { NS_PROFILESERVICE_CONTRACTID, &kProfileServiceCID },
-  { NS_NATIVEAPPSUPPORT_CONTRACTID, &kNativeAppSupportCID },
   { nullptr }
 };
 
 static const mozilla::Module kXREModule = {
   mozilla::Module::kVersion,
   kXRECIDs,
   kXREContracts
 };
@@ -1566,26 +1560,24 @@ ScopedXPCOMStartup::SetWindowCreator(nsI
 
   nsCOMPtr<nsIWindowWatcher> wwatch
     (do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   return wwatch->SetWindowCreator(creator);
 }
 
-/* static */ nsresult
-ScopedXPCOMStartup::CreateAppSupport(nsISupports* aOuter, REFNSIID aIID, void** aResult)
+/* static */ already_AddRefed<nsINativeAppSupport>
+NS_GetNativeAppSupport()
 {
-  if (aOuter)
-    return NS_ERROR_NO_AGGREGATION;
-
-  if (!gNativeAppSupport)
-    return NS_ERROR_NOT_INITIALIZED;
-
-  return gNativeAppSupport->QueryInterface(aIID, aResult);
+  if (!ScopedXPCOMStartup::gNativeAppSupport) {
+    return nullptr;
+  }
+
+  return do_AddRef(ScopedXPCOMStartup::gNativeAppSupport);
 }
 
 nsINativeAppSupport* ScopedXPCOMStartup::gNativeAppSupport;
 
 static void DumpArbitraryHelp()
 {
   nsresult rv;
 
--- a/toolkit/xre/nsAppRunner.h
+++ b/toolkit/xre/nsAppRunner.h
@@ -52,16 +52,17 @@ extern nsString gAbsoluteArgv0Path;
 extern bool gIsGtest;
 
 /**
  * Create the nativeappsupport implementation.
  *
  * @note XPCOMInit has not happened yet.
  */
 nsresult NS_CreateNativeAppSupport(nsINativeAppSupport* *aResult);
+already_AddRefed<nsINativeAppSupport> NS_GetNativeAppSupport();
 
 nsresult
 NS_NewToolkitProfileService(nsIToolkitProfileService* *aResult);
 
 nsresult
 NS_NewToolkitProfileFactory(nsIFactory* *aResult);
 
 /**
@@ -105,18 +106,16 @@ UseParentConsole();
 BOOL
 WinLaunchChild(const wchar_t *exePath, int argc,
                char **argv, HANDLE userToken = nullptr,
                HANDLE *hProcess = nullptr);
 
 #define PREF_WIN_REGISTER_APPLICATION_RESTART "toolkit.winRegisterApplicationRestart"
 #endif
 
-#define NS_NATIVEAPPSUPPORT_CONTRACTID "@mozilla.org/toolkit/native-app-support;1"
-
 namespace mozilla {
 namespace startup {
 Result<nsCOMPtr<nsIFile>, nsresult> GetIncompleteStartupFile(nsIFile* aProfLD);
 
 extern GeckoProcessType sChildProcessType;
 } // namespace startup
 
 const char* PlatformBuildID();