1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/plugins/ipc/PluginProcessParent.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,94 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: sw=4 ts=4 et : 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "mozilla/plugins/PluginProcessParent.h" 1.11 + 1.12 +#include "base/string_util.h" 1.13 +#include "base/process_util.h" 1.14 + 1.15 +#include "mozilla/ipc/BrowserProcessSubThread.h" 1.16 +#include "mozilla/plugins/PluginMessageUtils.h" 1.17 + 1.18 +using std::vector; 1.19 +using std::string; 1.20 + 1.21 +using mozilla::ipc::BrowserProcessSubThread; 1.22 +using mozilla::ipc::GeckoChildProcessHost; 1.23 +using mozilla::plugins::PluginProcessParent; 1.24 +using base::ProcessArchitecture; 1.25 + 1.26 +template<> 1.27 +struct RunnableMethodTraits<PluginProcessParent> 1.28 +{ 1.29 + static void RetainCallee(PluginProcessParent* obj) { } 1.30 + static void ReleaseCallee(PluginProcessParent* obj) { } 1.31 +}; 1.32 + 1.33 +PluginProcessParent::PluginProcessParent(const std::string& aPluginFilePath) : 1.34 + GeckoChildProcessHost(GeckoProcessType_Plugin), 1.35 + mPluginFilePath(aPluginFilePath) 1.36 +{ 1.37 +} 1.38 + 1.39 +PluginProcessParent::~PluginProcessParent() 1.40 +{ 1.41 +} 1.42 + 1.43 +bool 1.44 +PluginProcessParent::Launch(int32_t timeoutMs) 1.45 +{ 1.46 + ProcessArchitecture currentArchitecture = base::GetCurrentProcessArchitecture(); 1.47 + uint32_t containerArchitectures = GetSupportedArchitecturesForProcessType(GeckoProcessType_Plugin); 1.48 + 1.49 + uint32_t pluginLibArchitectures = currentArchitecture; 1.50 +#ifdef XP_MACOSX 1.51 + nsresult rv = GetArchitecturesForBinary(mPluginFilePath.c_str(), &pluginLibArchitectures); 1.52 + if (NS_FAILED(rv)) { 1.53 + // If the call failed just assume that we want the current architecture. 1.54 + pluginLibArchitectures = currentArchitecture; 1.55 + } 1.56 +#endif 1.57 + 1.58 + ProcessArchitecture selectedArchitecture = currentArchitecture; 1.59 + if (!(pluginLibArchitectures & containerArchitectures & currentArchitecture)) { 1.60 + // Prefererence in order: x86_64, i386, PPC. The only particularly important thing 1.61 + // about this order is that we'll prefer 64-bit architectures first. 1.62 + if (base::PROCESS_ARCH_X86_64 & pluginLibArchitectures & containerArchitectures) { 1.63 + selectedArchitecture = base::PROCESS_ARCH_X86_64; 1.64 + } 1.65 + else if (base::PROCESS_ARCH_I386 & pluginLibArchitectures & containerArchitectures) { 1.66 + selectedArchitecture = base::PROCESS_ARCH_I386; 1.67 + } 1.68 + else if (base::PROCESS_ARCH_PPC & pluginLibArchitectures & containerArchitectures) { 1.69 + selectedArchitecture = base::PROCESS_ARCH_PPC; 1.70 + } 1.71 + else if (base::PROCESS_ARCH_ARM & pluginLibArchitectures & containerArchitectures) { 1.72 + selectedArchitecture = base::PROCESS_ARCH_ARM; 1.73 + } 1.74 + else { 1.75 + return false; 1.76 + } 1.77 + } 1.78 + 1.79 + vector<string> args; 1.80 + args.push_back(MungePluginDsoPath(mPluginFilePath)); 1.81 + return SyncLaunch(args, timeoutMs, selectedArchitecture); 1.82 +} 1.83 + 1.84 +void 1.85 +PluginProcessParent::Delete() 1.86 +{ 1.87 + MessageLoop* currentLoop = MessageLoop::current(); 1.88 + MessageLoop* ioLoop = XRE_GetIOMessageLoop(); 1.89 + 1.90 + if (currentLoop == ioLoop) { 1.91 + delete this; 1.92 + return; 1.93 + } 1.94 + 1.95 + ioLoop->PostTask(FROM_HERE, 1.96 + NewRunnableMethod(this, &PluginProcessParent::Delete)); 1.97 +}