OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/nacl/browser/nacl_broker_host_win.h" | 5 #include "components/nacl/browser/nacl_broker_host_win.h" |
6 | 6 |
7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "components/nacl/browser/nacl_broker_service_win.h" | 10 #include "components/nacl/browser/nacl_broker_service_win.h" |
11 #include "components/nacl/browser/nacl_browser.h" | 11 #include "components/nacl/browser/nacl_browser.h" |
12 #include "components/nacl/common/nacl_cmd_line.h" | 12 #include "components/nacl/common/nacl_cmd_line.h" |
13 #include "components/nacl/common/nacl_messages.h" | 13 #include "components/nacl/common/nacl_messages.h" |
14 #include "components/nacl/common/nacl_process_type.h" | 14 #include "components/nacl/common/nacl_process_type.h" |
15 #include "components/nacl/common/nacl_switches.h" | 15 #include "components/nacl/common/nacl_switches.h" |
16 #include "content/public/browser/browser_child_process_host.h" | 16 #include "content/public/browser/browser_child_process_host.h" |
17 #include "content/public/browser/child_process_data.h" | 17 #include "content/public/browser/child_process_data.h" |
18 #include "content/public/common/child_process_host.h" | 18 #include "content/public/common/child_process_host.h" |
19 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
| 20 #include "content/public/common/mojo_channel_switches.h" |
20 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 21 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
21 #include "ipc/ipc_switches.h" | 22 #include "ipc/ipc_switches.h" |
| 23 #include "mojo/edk/embedder/embedder.h" |
22 | 24 |
23 namespace { | 25 namespace { |
24 // NOTE: changes to this class need to be reviewed by the security team. | 26 // NOTE: changes to this class need to be reviewed by the security team. |
25 class NaClBrokerSandboxedProcessLauncherDelegate | 27 class NaClBrokerSandboxedProcessLauncherDelegate |
26 : public content::SandboxedProcessLauncherDelegate { | 28 : public content::SandboxedProcessLauncherDelegate { |
27 public: | 29 public: |
28 NaClBrokerSandboxedProcessLauncherDelegate() {} | 30 NaClBrokerSandboxedProcessLauncherDelegate() {} |
29 ~NaClBrokerSandboxedProcessLauncherDelegate() override {} | 31 ~NaClBrokerSandboxedProcessLauncherDelegate() override {} |
30 | 32 |
31 bool ShouldSandbox() override { | 33 bool ShouldSandbox() override { |
32 return false; | 34 return false; |
33 } | 35 } |
34 | 36 |
35 private: | 37 private: |
36 DISALLOW_COPY_AND_ASSIGN(NaClBrokerSandboxedProcessLauncherDelegate); | 38 DISALLOW_COPY_AND_ASSIGN(NaClBrokerSandboxedProcessLauncherDelegate); |
37 }; | 39 }; |
38 } // namespace | 40 } // namespace |
39 | 41 |
40 namespace nacl { | 42 namespace nacl { |
41 | 43 |
42 NaClBrokerHost::NaClBrokerHost() : is_terminating_(false) { | 44 NaClBrokerHost::NaClBrokerHost() : is_terminating_(false) { |
43 process_.reset(content::BrowserChildProcessHost::Create( | |
44 static_cast<content::ProcessType>(PROCESS_TYPE_NACL_BROKER), this)); | |
45 } | 45 } |
46 | 46 |
47 NaClBrokerHost::~NaClBrokerHost() { | 47 NaClBrokerHost::~NaClBrokerHost() { |
48 } | 48 } |
49 | 49 |
50 bool NaClBrokerHost::Init() { | 50 bool NaClBrokerHost::Init() { |
| 51 const std::string mojo_child_token = mojo::edk::GenerateRandomToken(); |
| 52 DCHECK(!process_); |
| 53 process_.reset(content::BrowserChildProcessHost::Create( |
| 54 static_cast<content::ProcessType>(PROCESS_TYPE_NACL_BROKER), this, |
| 55 mojo_child_token)); |
| 56 |
51 // Create the channel that will be used for communicating with the broker. | 57 // Create the channel that will be used for communicating with the broker. |
52 std::string channel_id = process_->GetHost()->CreateChannel(); | 58 const std::string mojo_channel_token = |
53 if (channel_id.empty()) | 59 process_->GetHost()->CreateChannelMojo(mojo_child_token); |
| 60 if (mojo_channel_token.empty()) |
54 return false; | 61 return false; |
55 | 62 |
56 // Create the path to the nacl broker/loader executable. | 63 // Create the path to the nacl broker/loader executable. |
57 base::FilePath nacl_path; | 64 base::FilePath nacl_path; |
58 if (!NaClBrowser::GetInstance()->GetNaCl64ExePath(&nacl_path)) | 65 if (!NaClBrowser::GetInstance()->GetNaCl64ExePath(&nacl_path)) |
59 return false; | 66 return false; |
60 | 67 |
61 base::CommandLine* cmd_line = new base::CommandLine(nacl_path); | 68 base::CommandLine* cmd_line = new base::CommandLine(nacl_path); |
62 CopyNaClCommandLineArguments(cmd_line); | 69 CopyNaClCommandLineArguments(cmd_line); |
63 | 70 |
64 cmd_line->AppendSwitchASCII(switches::kProcessType, | 71 cmd_line->AppendSwitchASCII(switches::kProcessType, |
65 switches::kNaClBrokerProcess); | 72 switches::kNaClBrokerProcess); |
66 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); | 73 cmd_line->AppendSwitchASCII(switches::kMojoChannelToken, mojo_channel_token); |
67 if (NaClBrowser::GetDelegate()->DialogsAreSuppressed()) | 74 if (NaClBrowser::GetDelegate()->DialogsAreSuppressed()) |
68 cmd_line->AppendSwitch(switches::kNoErrorDialogs); | 75 cmd_line->AppendSwitch(switches::kNoErrorDialogs); |
69 | 76 |
70 process_->Launch(new NaClBrokerSandboxedProcessLauncherDelegate, | 77 process_->Launch(new NaClBrokerSandboxedProcessLauncherDelegate, |
71 cmd_line, | 78 cmd_line, |
72 true); | 79 true); |
73 return true; | 80 return true; |
74 } | 81 } |
75 | 82 |
76 bool NaClBrokerHost::OnMessageReceived(const IPC::Message& msg) { | 83 bool NaClBrokerHost::OnMessageReceived(const IPC::Message& msg) { |
77 bool handled = true; | 84 bool handled = true; |
78 IPC_BEGIN_MESSAGE_MAP(NaClBrokerHost, msg) | 85 IPC_BEGIN_MESSAGE_MAP(NaClBrokerHost, msg) |
79 IPC_MESSAGE_HANDLER(NaClProcessMsg_LoaderLaunched, OnLoaderLaunched) | 86 IPC_MESSAGE_HANDLER(NaClProcessMsg_LoaderLaunched, OnLoaderLaunched) |
80 IPC_MESSAGE_HANDLER(NaClProcessMsg_DebugExceptionHandlerLaunched, | 87 IPC_MESSAGE_HANDLER(NaClProcessMsg_DebugExceptionHandlerLaunched, |
81 OnDebugExceptionHandlerLaunched) | 88 OnDebugExceptionHandlerLaunched) |
82 IPC_MESSAGE_UNHANDLED(handled = false) | 89 IPC_MESSAGE_UNHANDLED(handled = false) |
83 IPC_END_MESSAGE_MAP() | 90 IPC_END_MESSAGE_MAP() |
84 return handled; | 91 return handled; |
85 } | 92 } |
86 | 93 |
87 bool NaClBrokerHost::LaunchLoader(const std::string& loader_channel_id) { | 94 bool NaClBrokerHost::LaunchLoader(const std::string& loader_channel_token) { |
88 return process_->Send( | 95 return process_->Send( |
89 new NaClProcessMsg_LaunchLoaderThroughBroker(loader_channel_id)); | 96 new NaClProcessMsg_LaunchLoaderThroughBroker(loader_channel_token)); |
90 } | 97 } |
91 | 98 |
92 void NaClBrokerHost::OnLoaderLaunched(const std::string& loader_channel_id, | 99 void NaClBrokerHost::OnLoaderLaunched(const std::string& loader_channel_token, |
93 base::ProcessHandle handle) { | 100 base::ProcessHandle handle) { |
94 NaClBrokerService::GetInstance()->OnLoaderLaunched(loader_channel_id, handle); | 101 NaClBrokerService::GetInstance()->OnLoaderLaunched(loader_channel_token, |
| 102 handle); |
95 } | 103 } |
96 | 104 |
97 bool NaClBrokerHost::LaunchDebugExceptionHandler( | 105 bool NaClBrokerHost::LaunchDebugExceptionHandler( |
98 int32_t pid, | 106 int32_t pid, |
99 base::ProcessHandle process_handle, | 107 base::ProcessHandle process_handle, |
100 const std::string& startup_info) { | 108 const std::string& startup_info) { |
101 base::ProcessHandle broker_process = process_->GetData().handle; | 109 base::ProcessHandle broker_process = process_->GetData().handle; |
102 base::ProcessHandle handle_in_broker_process; | 110 base::ProcessHandle handle_in_broker_process; |
103 if (!DuplicateHandle(::GetCurrentProcess(), process_handle, | 111 if (!DuplicateHandle(::GetCurrentProcess(), process_handle, |
104 broker_process, &handle_in_broker_process, | 112 broker_process, &handle_in_broker_process, |
105 0, /* bInheritHandle= */ FALSE, DUPLICATE_SAME_ACCESS)) | 113 0, /* bInheritHandle= */ FALSE, DUPLICATE_SAME_ACCESS)) |
106 return false; | 114 return false; |
107 return process_->Send(new NaClProcessMsg_LaunchDebugExceptionHandler( | 115 return process_->Send(new NaClProcessMsg_LaunchDebugExceptionHandler( |
108 pid, handle_in_broker_process, startup_info)); | 116 pid, handle_in_broker_process, startup_info)); |
109 } | 117 } |
110 | 118 |
111 void NaClBrokerHost::OnDebugExceptionHandlerLaunched(int32_t pid, | 119 void NaClBrokerHost::OnDebugExceptionHandlerLaunched(int32_t pid, |
112 bool success) { | 120 bool success) { |
113 NaClBrokerService::GetInstance()->OnDebugExceptionHandlerLaunched(pid, | 121 NaClBrokerService::GetInstance()->OnDebugExceptionHandlerLaunched(pid, |
114 success); | 122 success); |
115 } | 123 } |
116 | 124 |
117 void NaClBrokerHost::StopBroker() { | 125 void NaClBrokerHost::StopBroker() { |
118 is_terminating_ = true; | 126 is_terminating_ = true; |
119 process_->Send(new NaClProcessMsg_StopBroker()); | 127 process_->Send(new NaClProcessMsg_StopBroker()); |
120 } | 128 } |
121 | 129 |
122 } // namespace nacl | 130 } // namespace nacl |
OLD | NEW |