michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: sw=4 ts=4 et : michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/plugins/PluginProcessParent.h" michael@0: michael@0: #include "base/string_util.h" michael@0: #include "base/process_util.h" michael@0: michael@0: #include "mozilla/ipc/BrowserProcessSubThread.h" michael@0: #include "mozilla/plugins/PluginMessageUtils.h" michael@0: michael@0: using std::vector; michael@0: using std::string; michael@0: michael@0: using mozilla::ipc::BrowserProcessSubThread; michael@0: using mozilla::ipc::GeckoChildProcessHost; michael@0: using mozilla::plugins::PluginProcessParent; michael@0: using base::ProcessArchitecture; michael@0: michael@0: template<> michael@0: struct RunnableMethodTraits michael@0: { michael@0: static void RetainCallee(PluginProcessParent* obj) { } michael@0: static void ReleaseCallee(PluginProcessParent* obj) { } michael@0: }; michael@0: michael@0: PluginProcessParent::PluginProcessParent(const std::string& aPluginFilePath) : michael@0: GeckoChildProcessHost(GeckoProcessType_Plugin), michael@0: mPluginFilePath(aPluginFilePath) michael@0: { michael@0: } michael@0: michael@0: PluginProcessParent::~PluginProcessParent() michael@0: { michael@0: } michael@0: michael@0: bool michael@0: PluginProcessParent::Launch(int32_t timeoutMs) michael@0: { michael@0: ProcessArchitecture currentArchitecture = base::GetCurrentProcessArchitecture(); michael@0: uint32_t containerArchitectures = GetSupportedArchitecturesForProcessType(GeckoProcessType_Plugin); michael@0: michael@0: uint32_t pluginLibArchitectures = currentArchitecture; michael@0: #ifdef XP_MACOSX michael@0: nsresult rv = GetArchitecturesForBinary(mPluginFilePath.c_str(), &pluginLibArchitectures); michael@0: if (NS_FAILED(rv)) { michael@0: // If the call failed just assume that we want the current architecture. michael@0: pluginLibArchitectures = currentArchitecture; michael@0: } michael@0: #endif michael@0: michael@0: ProcessArchitecture selectedArchitecture = currentArchitecture; michael@0: if (!(pluginLibArchitectures & containerArchitectures & currentArchitecture)) { michael@0: // Prefererence in order: x86_64, i386, PPC. The only particularly important thing michael@0: // about this order is that we'll prefer 64-bit architectures first. michael@0: if (base::PROCESS_ARCH_X86_64 & pluginLibArchitectures & containerArchitectures) { michael@0: selectedArchitecture = base::PROCESS_ARCH_X86_64; michael@0: } michael@0: else if (base::PROCESS_ARCH_I386 & pluginLibArchitectures & containerArchitectures) { michael@0: selectedArchitecture = base::PROCESS_ARCH_I386; michael@0: } michael@0: else if (base::PROCESS_ARCH_PPC & pluginLibArchitectures & containerArchitectures) { michael@0: selectedArchitecture = base::PROCESS_ARCH_PPC; michael@0: } michael@0: else if (base::PROCESS_ARCH_ARM & pluginLibArchitectures & containerArchitectures) { michael@0: selectedArchitecture = base::PROCESS_ARCH_ARM; michael@0: } michael@0: else { michael@0: return false; michael@0: } michael@0: } michael@0: michael@0: vector args; michael@0: args.push_back(MungePluginDsoPath(mPluginFilePath)); michael@0: return SyncLaunch(args, timeoutMs, selectedArchitecture); michael@0: } michael@0: michael@0: void michael@0: PluginProcessParent::Delete() michael@0: { michael@0: MessageLoop* currentLoop = MessageLoop::current(); michael@0: MessageLoop* ioLoop = XRE_GetIOMessageLoop(); michael@0: michael@0: if (currentLoop == ioLoop) { michael@0: delete this; michael@0: return; michael@0: } michael@0: michael@0: ioLoop->PostTask(FROM_HERE, michael@0: NewRunnableMethod(this, &PluginProcessParent::Delete)); michael@0: }