dom/plugins/ipc/PluginProcessParent.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/plugins/PluginProcessParent.h"
michael@0 8
michael@0 9 #include "base/string_util.h"
michael@0 10 #include "base/process_util.h"
michael@0 11
michael@0 12 #include "mozilla/ipc/BrowserProcessSubThread.h"
michael@0 13 #include "mozilla/plugins/PluginMessageUtils.h"
michael@0 14
michael@0 15 using std::vector;
michael@0 16 using std::string;
michael@0 17
michael@0 18 using mozilla::ipc::BrowserProcessSubThread;
michael@0 19 using mozilla::ipc::GeckoChildProcessHost;
michael@0 20 using mozilla::plugins::PluginProcessParent;
michael@0 21 using base::ProcessArchitecture;
michael@0 22
michael@0 23 template<>
michael@0 24 struct RunnableMethodTraits<PluginProcessParent>
michael@0 25 {
michael@0 26 static void RetainCallee(PluginProcessParent* obj) { }
michael@0 27 static void ReleaseCallee(PluginProcessParent* obj) { }
michael@0 28 };
michael@0 29
michael@0 30 PluginProcessParent::PluginProcessParent(const std::string& aPluginFilePath) :
michael@0 31 GeckoChildProcessHost(GeckoProcessType_Plugin),
michael@0 32 mPluginFilePath(aPluginFilePath)
michael@0 33 {
michael@0 34 }
michael@0 35
michael@0 36 PluginProcessParent::~PluginProcessParent()
michael@0 37 {
michael@0 38 }
michael@0 39
michael@0 40 bool
michael@0 41 PluginProcessParent::Launch(int32_t timeoutMs)
michael@0 42 {
michael@0 43 ProcessArchitecture currentArchitecture = base::GetCurrentProcessArchitecture();
michael@0 44 uint32_t containerArchitectures = GetSupportedArchitecturesForProcessType(GeckoProcessType_Plugin);
michael@0 45
michael@0 46 uint32_t pluginLibArchitectures = currentArchitecture;
michael@0 47 #ifdef XP_MACOSX
michael@0 48 nsresult rv = GetArchitecturesForBinary(mPluginFilePath.c_str(), &pluginLibArchitectures);
michael@0 49 if (NS_FAILED(rv)) {
michael@0 50 // If the call failed just assume that we want the current architecture.
michael@0 51 pluginLibArchitectures = currentArchitecture;
michael@0 52 }
michael@0 53 #endif
michael@0 54
michael@0 55 ProcessArchitecture selectedArchitecture = currentArchitecture;
michael@0 56 if (!(pluginLibArchitectures & containerArchitectures & currentArchitecture)) {
michael@0 57 // Prefererence in order: x86_64, i386, PPC. The only particularly important thing
michael@0 58 // about this order is that we'll prefer 64-bit architectures first.
michael@0 59 if (base::PROCESS_ARCH_X86_64 & pluginLibArchitectures & containerArchitectures) {
michael@0 60 selectedArchitecture = base::PROCESS_ARCH_X86_64;
michael@0 61 }
michael@0 62 else if (base::PROCESS_ARCH_I386 & pluginLibArchitectures & containerArchitectures) {
michael@0 63 selectedArchitecture = base::PROCESS_ARCH_I386;
michael@0 64 }
michael@0 65 else if (base::PROCESS_ARCH_PPC & pluginLibArchitectures & containerArchitectures) {
michael@0 66 selectedArchitecture = base::PROCESS_ARCH_PPC;
michael@0 67 }
michael@0 68 else if (base::PROCESS_ARCH_ARM & pluginLibArchitectures & containerArchitectures) {
michael@0 69 selectedArchitecture = base::PROCESS_ARCH_ARM;
michael@0 70 }
michael@0 71 else {
michael@0 72 return false;
michael@0 73 }
michael@0 74 }
michael@0 75
michael@0 76 vector<string> args;
michael@0 77 args.push_back(MungePluginDsoPath(mPluginFilePath));
michael@0 78 return SyncLaunch(args, timeoutMs, selectedArchitecture);
michael@0 79 }
michael@0 80
michael@0 81 void
michael@0 82 PluginProcessParent::Delete()
michael@0 83 {
michael@0 84 MessageLoop* currentLoop = MessageLoop::current();
michael@0 85 MessageLoop* ioLoop = XRE_GetIOMessageLoop();
michael@0 86
michael@0 87 if (currentLoop == ioLoop) {
michael@0 88 delete this;
michael@0 89 return;
michael@0 90 }
michael@0 91
michael@0 92 ioLoop->PostTask(FROM_HERE,
michael@0 93 NewRunnableMethod(this, &PluginProcessParent::Delete));
michael@0 94 }

mercurial