1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 : * vim: sw=4 ts=4 et :
3 : * ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is Mozilla Plugin App.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * Ben Turner <bent.mozilla@gmail.com>.
20 : * Portions created by the Initial Developer are Copyright (C) 2009
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Chris Jones <jones.chris.g@gmail.com>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either the GNU General Public License Version 2 or later (the "GPL"), or
28 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #include "mozilla/plugins/PluginProcessParent.h"
41 :
42 : #include "base/string_util.h"
43 : #include "base/process_util.h"
44 :
45 : #include "mozilla/ipc/BrowserProcessSubThread.h"
46 : #include "mozilla/plugins/PluginMessageUtils.h"
47 :
48 : using std::vector;
49 : using std::string;
50 :
51 : using mozilla::ipc::BrowserProcessSubThread;
52 : using mozilla::ipc::GeckoChildProcessHost;
53 : using mozilla::plugins::PluginProcessParent;
54 : using base::ProcessArchitecture;
55 :
56 : template<>
57 : struct RunnableMethodTraits<PluginProcessParent>
58 0 : {
59 0 : static void RetainCallee(PluginProcessParent* obj) { }
60 0 : static void ReleaseCallee(PluginProcessParent* obj) { }
61 : };
62 :
63 0 : PluginProcessParent::PluginProcessParent(const std::string& aPluginFilePath) :
64 : GeckoChildProcessHost(GeckoProcessType_Plugin),
65 0 : mPluginFilePath(aPluginFilePath)
66 : {
67 0 : }
68 :
69 0 : PluginProcessParent::~PluginProcessParent()
70 : {
71 0 : }
72 :
73 : bool
74 0 : PluginProcessParent::Launch(PRInt32 timeoutMs)
75 : {
76 0 : ProcessArchitecture currentArchitecture = base::GetCurrentProcessArchitecture();
77 0 : uint32 containerArchitectures = GetSupportedArchitecturesForProcessType(GeckoProcessType_Plugin);
78 :
79 0 : uint32 pluginLibArchitectures = currentArchitecture;
80 : #ifdef XP_MACOSX
81 : nsresult rv = GetArchitecturesForBinary(mPluginFilePath.c_str(), &pluginLibArchitectures);
82 : if (NS_FAILED(rv)) {
83 : // If the call failed just assume that we want the current architecture.
84 : pluginLibArchitectures = currentArchitecture;
85 : }
86 : #endif
87 :
88 0 : ProcessArchitecture selectedArchitecture = currentArchitecture;
89 0 : if (!(pluginLibArchitectures & containerArchitectures & currentArchitecture)) {
90 : // Prefererence in order: x86_64, i386, PPC. The only particularly important thing
91 : // about this order is that we'll prefer 64-bit architectures first.
92 0 : if (base::PROCESS_ARCH_X86_64 & pluginLibArchitectures & containerArchitectures) {
93 0 : selectedArchitecture = base::PROCESS_ARCH_X86_64;
94 : }
95 0 : else if (base::PROCESS_ARCH_I386 & pluginLibArchitectures & containerArchitectures) {
96 0 : selectedArchitecture = base::PROCESS_ARCH_I386;
97 : }
98 0 : else if (base::PROCESS_ARCH_PPC & pluginLibArchitectures & containerArchitectures) {
99 0 : selectedArchitecture = base::PROCESS_ARCH_PPC;
100 : }
101 0 : else if (base::PROCESS_ARCH_ARM & pluginLibArchitectures & containerArchitectures) {
102 0 : selectedArchitecture = base::PROCESS_ARCH_ARM;
103 : }
104 : else {
105 0 : return false;
106 : }
107 : }
108 :
109 0 : vector<string> args;
110 0 : args.push_back(MungePluginDsoPath(mPluginFilePath));
111 0 : return SyncLaunch(args, timeoutMs, selectedArchitecture);
112 : }
113 :
114 : void
115 0 : PluginProcessParent::Delete()
116 : {
117 0 : MessageLoop* currentLoop = MessageLoop::current();
118 0 : MessageLoop* ioLoop = XRE_GetIOMessageLoop();
119 :
120 0 : if (currentLoop == ioLoop) {
121 0 : delete this;
122 0 : return;
123 : }
124 :
125 : ioLoop->PostTask(FROM_HERE,
126 0 : NewRunnableMethod(this, &PluginProcessParent::Delete));
127 : }
|