Bug 1277075: Modify parent and child process startup to use mscom::MainThreadRuntime; r?jimm
MozReview-Commit-ID: DpRPrxtgMoO
--- a/dom/ipc/ContentProcess.h
+++ b/dom/ipc/ContentProcess.h
@@ -6,16 +6,20 @@
#ifndef dom_tabs_ContentThread_h
#define dom_tabs_ContentThread_h 1
#include "mozilla/ipc/ProcessChild.h"
#include "mozilla/ipc/ScopedXREEmbed.h"
#include "ContentChild.h"
+#if defined(XP_WIN)
+#include "mozilla/mscom/MainThreadRuntime.h"
+#endif
+
namespace mozilla {
namespace dom {
/**
* ContentProcess is a singleton on the content process which represents
* the main thread where tab instances live.
*/
class ContentProcess : public mozilla::ipc::ProcessChild
@@ -33,16 +37,20 @@ public:
virtual bool Init() override;
virtual void CleanUp() override;
void SetAppDir(const nsACString& aPath);
private:
ContentChild mContent;
mozilla::ipc::ScopedXREEmbed mXREEmbed;
+#if defined(XP_WIN)
+ // This object initializes and configures COM.
+ mozilla::mscom::MainThreadRuntime mCOMRuntime;
+#endif
DISALLOW_EVIL_CONSTRUCTORS(ContentProcess);
};
} // namespace dom
} // namespace mozilla
#endif // ifndef dom_tabs_ContentThread_h
--- a/dom/plugins/ipc/PluginProcessChild.cpp
+++ b/dom/plugins/ipc/PluginProcessChild.cpp
@@ -16,17 +16,16 @@
#if defined(XP_MACOSX)
#include "nsCocoaFeatures.h"
// An undocumented CoreGraphics framework method, present in the same form
// since at least OS X 10.5.
extern "C" CGError CGSSetDebugOptions(int options);
#endif
#ifdef XP_WIN
-#include <objbase.h>
bool ShouldProtectPluginCurrentDirectory(char16ptr_t pluginFilePath);
#if defined(MOZ_SANDBOX)
#define TARGET_SANDBOX_EXPORTS
#include "mozilla/sandboxTarget.h"
#endif
#endif
using mozilla::ipc::IOThreadChild;
@@ -76,22 +75,16 @@ PluginProcessChild::Init()
}
// Values passed to PR_SetEnv() must be seperately allocated.
char* setInterposePtr = strdup(setInterpose.get());
PR_SetEnv(setInterposePtr);
}
}
#endif
-#ifdef XP_WIN
- // Drag-and-drop needs OleInitialize to be called, and Silverlight depends
- // on the host calling CoInitialize (which is called by OleInitialize).
- ::OleInitialize(nullptr);
-#endif
-
// Certain plugins, such as flash, steal the unhandled exception filter
// thus we never get crash reports when they fault. This call fixes it.
message_loop()->set_exception_restoration(true);
std::string pluginFilename;
#if defined(OS_POSIX)
// NB: need to be very careful in ensuring that the first arg
@@ -144,16 +137,13 @@ PluginProcessChild::Init()
}
#endif
return retval;
}
void
PluginProcessChild::CleanUp()
{
-#ifdef XP_WIN
- ::OleUninitialize();
-#endif
nsRegion::ShutdownStatic();
}
} // namespace plugins
} // namespace mozilla
--- a/dom/plugins/ipc/PluginProcessChild.h
+++ b/dom/plugins/ipc/PluginProcessChild.h
@@ -5,16 +5,20 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef dom_plugins_PluginProcessChild_h
#define dom_plugins_PluginProcessChild_h 1
#include "mozilla/ipc/ProcessChild.h"
#include "mozilla/plugins/PluginModuleChild.h"
+#if defined(XP_WIN)
+#include "mozilla/mscom/MainThreadRuntime.h"
+#endif
+
namespace mozilla {
namespace plugins {
//-----------------------------------------------------------------------------
class PluginProcessChild : public mozilla::ipc::ProcessChild {
protected:
typedef mozilla::ipc::ProcessChild ProcessChild;
@@ -30,16 +34,21 @@ public:
virtual void CleanUp() override;
protected:
static PluginProcessChild* current() {
return static_cast<PluginProcessChild*>(ProcessChild::current());
}
private:
+#if defined(XP_WIN)
+ /* Drag-and-drop and Silverlight depend on the host initializing COM.
+ * This object initializes and configures COM. */
+ mozilla::mscom::MainThreadRuntime mCOMRuntime;
+#endif
PluginModuleChild mPlugin;
DISALLOW_EVIL_CONSTRUCTORS(PluginProcessChild);
};
} // namespace plugins
} // namespace mozilla
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -92,16 +92,17 @@
#ifdef XP_WIN
#include "nsIWinAppHelper.h"
#include <windows.h>
#include <intrin.h>
#include <math.h>
#include "cairo/cairo-features.h"
#include "mozilla/WindowsVersion.h"
+#include "mozilla/mscom/MainThreadRuntime.h"
#include "mozilla/widget/AudioSession.h"
#ifndef PROCESS_DEP_ENABLE
#define PROCESS_DEP_ENABLE 0x1
#endif
#endif
#if (defined(XP_WIN) || defined(XP_MACOSX)) && defined(MOZ_CONTENT_SANDBOX)
@@ -4298,16 +4299,24 @@ XREMain::XRE_main(int argc, char* argv[]
rv = XRE_GetBinaryPath(argv[0], getter_AddRefs(binFile));
NS_ENSURE_SUCCESS(rv, 1);
rv = binFile->GetPath(gAbsoluteArgv0Path);
NS_ENSURE_SUCCESS(rv, 1);
mozilla::IOInterposerInit ioInterposerGuard;
+#if defined(XP_WIN)
+ // Some COM settings are global to the process and must be set before any non-
+ // trivial COM is run in the application. Since these settings may affect
+ // stability, we should instantiate COM ASAP so that we can ensure that these
+ // global settings are configured before anything can interfere.
+ mozilla::mscom::MainThreadRuntime msCOMRuntime;
+#endif
+
#if MOZ_WIDGET_GTK == 2
XRE_GlibInit();
#endif
// init
bool exit = false;
int result = XRE_mainInit(&exit);
if (result != 0 || exit)