dom/plugins/ipc/PluginProcessChild.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * vim: sw=4 ts=4 et :
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "mozilla/ipc/IOThreadChild.h"
michael@0 8 #include "mozilla/plugins/PluginProcessChild.h"
michael@0 9
michael@0 10 #include "prlink.h"
michael@0 11
michael@0 12 #include "base/command_line.h"
michael@0 13 #include "base/string_util.h"
michael@0 14 #include "chrome/common/chrome_switches.h"
michael@0 15
michael@0 16 #if defined(XP_MACOSX)
michael@0 17 #include "nsCocoaFeatures.h"
michael@0 18 // An undocumented CoreGraphics framework method, present in the same form
michael@0 19 // since at least OS X 10.5.
michael@0 20 extern "C" CGError CGSSetDebugOptions(int options);
michael@0 21 #endif
michael@0 22
michael@0 23 #ifdef XP_WIN
michael@0 24 #include <objbase.h>
michael@0 25 bool ShouldProtectPluginCurrentDirectory(char16ptr_t pluginFilePath);
michael@0 26 #endif
michael@0 27
michael@0 28 using mozilla::ipc::IOThreadChild;
michael@0 29
michael@0 30 #ifdef OS_WIN
michael@0 31 #include "nsSetDllDirectory.h"
michael@0 32 #include <algorithm>
michael@0 33
michael@0 34 namespace {
michael@0 35
michael@0 36 std::size_t caseInsensitiveFind(std::string aHaystack, std::string aNeedle) {
michael@0 37 std::transform(aHaystack.begin(), aHaystack.end(), aHaystack.begin(), ::tolower);
michael@0 38 std::transform(aNeedle.begin(), aNeedle.end(), aNeedle.begin(), ::tolower);
michael@0 39 return aHaystack.find(aNeedle);
michael@0 40 }
michael@0 41
michael@0 42 }
michael@0 43 #endif
michael@0 44
michael@0 45 namespace mozilla {
michael@0 46 namespace plugins {
michael@0 47
michael@0 48
michael@0 49 bool
michael@0 50 PluginProcessChild::Init()
michael@0 51 {
michael@0 52 #if defined(XP_MACOSX)
michael@0 53 // Remove the trigger for "dyld interposing" that we added in
michael@0 54 // GeckoChildProcessHost::PerformAsyncLaunchInternal(), in the host
michael@0 55 // process just before we were launched. Dyld interposing will still
michael@0 56 // happen in our process (the plugin child process). But we don't want
michael@0 57 // it to happen in any processes that the plugin might launch from our
michael@0 58 // process.
michael@0 59 nsCString interpose(PR_GetEnv("DYLD_INSERT_LIBRARIES"));
michael@0 60 if (!interpose.IsEmpty()) {
michael@0 61 // If we added the path to libplugin_child_interpose.dylib to an
michael@0 62 // existing DYLD_INSERT_LIBRARIES, we appended it to the end, after a
michael@0 63 // ":" path seperator.
michael@0 64 int32_t lastSeparatorPos = interpose.RFind(":");
michael@0 65 int32_t lastTriggerPos = interpose.RFind("libplugin_child_interpose.dylib");
michael@0 66 bool needsReset = false;
michael@0 67 if (lastTriggerPos != -1) {
michael@0 68 if (lastSeparatorPos == -1) {
michael@0 69 interpose.Truncate();
michael@0 70 needsReset = true;
michael@0 71 } else if (lastTriggerPos > lastSeparatorPos) {
michael@0 72 interpose.SetLength(lastSeparatorPos);
michael@0 73 needsReset = true;
michael@0 74 }
michael@0 75 }
michael@0 76 if (needsReset) {
michael@0 77 nsCString setInterpose("DYLD_INSERT_LIBRARIES=");
michael@0 78 if (!interpose.IsEmpty()) {
michael@0 79 setInterpose.Append(interpose);
michael@0 80 }
michael@0 81 // Values passed to PR_SetEnv() must be seperately allocated.
michael@0 82 char* setInterposePtr = strdup(setInterpose.get());
michael@0 83 PR_SetEnv(setInterposePtr);
michael@0 84 }
michael@0 85 }
michael@0 86 #endif
michael@0 87
michael@0 88 #ifdef XP_WIN
michael@0 89 // Drag-and-drop needs OleInitialize to be called, and Silverlight depends
michael@0 90 // on the host calling CoInitialize (which is called by OleInitialize).
michael@0 91 ::OleInitialize(nullptr);
michael@0 92 #endif
michael@0 93
michael@0 94 // Certain plugins, such as flash, steal the unhandled exception filter
michael@0 95 // thus we never get crash reports when they fault. This call fixes it.
michael@0 96 message_loop()->set_exception_restoration(true);
michael@0 97
michael@0 98 std::string pluginFilename;
michael@0 99
michael@0 100 #if defined(OS_POSIX)
michael@0 101 // NB: need to be very careful in ensuring that the first arg
michael@0 102 // (after the binary name) here is indeed the plugin module path.
michael@0 103 // Keep in sync with dom/plugins/PluginModuleParent.
michael@0 104 std::vector<std::string> values = CommandLine::ForCurrentProcess()->argv();
michael@0 105 NS_ABORT_IF_FALSE(values.size() >= 2, "not enough args");
michael@0 106
michael@0 107 pluginFilename = UnmungePluginDsoPath(values[1]);
michael@0 108
michael@0 109 #elif defined(OS_WIN)
michael@0 110 std::vector<std::wstring> values =
michael@0 111 CommandLine::ForCurrentProcess()->GetLooseValues();
michael@0 112 NS_ABORT_IF_FALSE(values.size() >= 1, "not enough loose args");
michael@0 113
michael@0 114 if (ShouldProtectPluginCurrentDirectory(values[0].c_str())) {
michael@0 115 SanitizeEnvironmentVariables();
michael@0 116 SetDllDirectory(L"");
michael@0 117 }
michael@0 118
michael@0 119 pluginFilename = WideToUTF8(values[0]);
michael@0 120 #else
michael@0 121 # error Sorry
michael@0 122 #endif
michael@0 123
michael@0 124 if (NS_FAILED(nsRegion::InitStatic())) {
michael@0 125 NS_ERROR("Could not initialize nsRegion");
michael@0 126 return false;
michael@0 127 }
michael@0 128
michael@0 129 bool retval = mPlugin.Init(pluginFilename, ParentHandle(),
michael@0 130 IOThreadChild::message_loop(),
michael@0 131 IOThreadChild::channel());
michael@0 132 #if defined(XP_MACOSX)
michael@0 133 if (nsCocoaFeatures::OnYosemiteOrLater()) {
michael@0 134 // Explicitly turn off CGEvent logging. This works around bug 1092855.
michael@0 135 // If there are already CGEvents in the log, turning off logging also
michael@0 136 // causes those events to be written to disk. But at this point no
michael@0 137 // CGEvents have yet been processed. CGEvents are events (usually
michael@0 138 // input events) pulled from the WindowServer. An option of 0x80000008
michael@0 139 // turns on CGEvent logging.
michael@0 140 CGSSetDebugOptions(0x80000007);
michael@0 141 }
michael@0 142 #endif
michael@0 143 return retval;
michael@0 144 }
michael@0 145
michael@0 146 void
michael@0 147 PluginProcessChild::CleanUp()
michael@0 148 {
michael@0 149 #ifdef XP_WIN
michael@0 150 ::OleUninitialize();
michael@0 151 #endif
michael@0 152 nsRegion::ShutdownStatic();
michael@0 153 }
michael@0 154
michael@0 155 } // namespace plugins
michael@0 156 } // namespace mozilla

mercurial