Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: sw=4 ts=4 et :
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/plugins/PluginProcessParent.h"
9 #include "base/string_util.h"
10 #include "base/process_util.h"
12 #include "mozilla/ipc/BrowserProcessSubThread.h"
13 #include "mozilla/plugins/PluginMessageUtils.h"
15 using std::vector;
16 using std::string;
18 using mozilla::ipc::BrowserProcessSubThread;
19 using mozilla::ipc::GeckoChildProcessHost;
20 using mozilla::plugins::PluginProcessParent;
21 using base::ProcessArchitecture;
23 template<>
24 struct RunnableMethodTraits<PluginProcessParent>
25 {
26 static void RetainCallee(PluginProcessParent* obj) { }
27 static void ReleaseCallee(PluginProcessParent* obj) { }
28 };
30 PluginProcessParent::PluginProcessParent(const std::string& aPluginFilePath) :
31 GeckoChildProcessHost(GeckoProcessType_Plugin),
32 mPluginFilePath(aPluginFilePath)
33 {
34 }
36 PluginProcessParent::~PluginProcessParent()
37 {
38 }
40 bool
41 PluginProcessParent::Launch(int32_t timeoutMs)
42 {
43 ProcessArchitecture currentArchitecture = base::GetCurrentProcessArchitecture();
44 uint32_t containerArchitectures = GetSupportedArchitecturesForProcessType(GeckoProcessType_Plugin);
46 uint32_t pluginLibArchitectures = currentArchitecture;
47 #ifdef XP_MACOSX
48 nsresult rv = GetArchitecturesForBinary(mPluginFilePath.c_str(), &pluginLibArchitectures);
49 if (NS_FAILED(rv)) {
50 // If the call failed just assume that we want the current architecture.
51 pluginLibArchitectures = currentArchitecture;
52 }
53 #endif
55 ProcessArchitecture selectedArchitecture = currentArchitecture;
56 if (!(pluginLibArchitectures & containerArchitectures & currentArchitecture)) {
57 // Prefererence in order: x86_64, i386, PPC. The only particularly important thing
58 // about this order is that we'll prefer 64-bit architectures first.
59 if (base::PROCESS_ARCH_X86_64 & pluginLibArchitectures & containerArchitectures) {
60 selectedArchitecture = base::PROCESS_ARCH_X86_64;
61 }
62 else if (base::PROCESS_ARCH_I386 & pluginLibArchitectures & containerArchitectures) {
63 selectedArchitecture = base::PROCESS_ARCH_I386;
64 }
65 else if (base::PROCESS_ARCH_PPC & pluginLibArchitectures & containerArchitectures) {
66 selectedArchitecture = base::PROCESS_ARCH_PPC;
67 }
68 else if (base::PROCESS_ARCH_ARM & pluginLibArchitectures & containerArchitectures) {
69 selectedArchitecture = base::PROCESS_ARCH_ARM;
70 }
71 else {
72 return false;
73 }
74 }
76 vector<string> args;
77 args.push_back(MungePluginDsoPath(mPluginFilePath));
78 return SyncLaunch(args, timeoutMs, selectedArchitecture);
79 }
81 void
82 PluginProcessParent::Delete()
83 {
84 MessageLoop* currentLoop = MessageLoop::current();
85 MessageLoop* ioLoop = XRE_GetIOMessageLoop();
87 if (currentLoop == ioLoop) {
88 delete this;
89 return;
90 }
92 ioLoop->PostTask(FROM_HERE,
93 NewRunnableMethod(this, &PluginProcessParent::Delete));
94 }