Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: components/nacl/browser/nacl_broker_host_win.cc

Issue 2081183005: Use ChannelMojo from the browser to NaCl loader process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-ipc-channel-handle
Patch Set: jfhgjdhgjdf Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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()
45 : is_terminating_(false),
46 mojo_child_token_(mojo::edk::GenerateRandomToken()) {
43 process_.reset(content::BrowserChildProcessHost::Create( 47 process_.reset(content::BrowserChildProcessHost::Create(
Mark Seaborn 2016/07/08 20:26:19 It looks like this Create() call could be moved in
Anand Mistry (off Chromium) 2016/07/12 07:26:23 Done.
44 static_cast<content::ProcessType>(PROCESS_TYPE_NACL_BROKER), this)); 48 static_cast<content::ProcessType>(PROCESS_TYPE_NACL_BROKER), this,
49 mojo_child_token_));
45 } 50 }
46 51
47 NaClBrokerHost::~NaClBrokerHost() { 52 NaClBrokerHost::~NaClBrokerHost() {
48 } 53 }
49 54
50 bool NaClBrokerHost::Init() { 55 bool NaClBrokerHost::Init() {
51 // Create the channel that will be used for communicating with the broker. 56 // Create the channel that will be used for communicating with the broker.
52 std::string channel_id = process_->GetHost()->CreateChannel(); 57 std::string mojo_channel_token =
53 if (channel_id.empty()) 58 process_->GetHost()->CreateChannelMojo(mojo_child_token_);
59 if (mojo_channel_token.empty())
54 return false; 60 return false;
55 61
56 // Create the path to the nacl broker/loader executable. 62 // Create the path to the nacl broker/loader executable.
57 base::FilePath nacl_path; 63 base::FilePath nacl_path;
58 if (!NaClBrowser::GetInstance()->GetNaCl64ExePath(&nacl_path)) 64 if (!NaClBrowser::GetInstance()->GetNaCl64ExePath(&nacl_path))
59 return false; 65 return false;
60 66
61 base::CommandLine* cmd_line = new base::CommandLine(nacl_path); 67 base::CommandLine* cmd_line = new base::CommandLine(nacl_path);
62 CopyNaClCommandLineArguments(cmd_line); 68 CopyNaClCommandLineArguments(cmd_line);
63 69
64 cmd_line->AppendSwitchASCII(switches::kProcessType, 70 cmd_line->AppendSwitchASCII(switches::kProcessType,
65 switches::kNaClBrokerProcess); 71 switches::kNaClBrokerProcess);
66 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); 72 cmd_line->AppendSwitchASCII(switches::kMojoChannelToken, mojo_channel_token);
67 if (NaClBrowser::GetDelegate()->DialogsAreSuppressed()) 73 if (NaClBrowser::GetDelegate()->DialogsAreSuppressed())
68 cmd_line->AppendSwitch(switches::kNoErrorDialogs); 74 cmd_line->AppendSwitch(switches::kNoErrorDialogs);
69 75
70 process_->Launch(new NaClBrokerSandboxedProcessLauncherDelegate, 76 process_->Launch(new NaClBrokerSandboxedProcessLauncherDelegate,
71 cmd_line, 77 cmd_line,
72 true); 78 true);
73 return true; 79 return true;
74 } 80 }
75 81
76 bool NaClBrokerHost::OnMessageReceived(const IPC::Message& msg) { 82 bool NaClBrokerHost::OnMessageReceived(const IPC::Message& msg) {
77 bool handled = true; 83 bool handled = true;
78 IPC_BEGIN_MESSAGE_MAP(NaClBrokerHost, msg) 84 IPC_BEGIN_MESSAGE_MAP(NaClBrokerHost, msg)
79 IPC_MESSAGE_HANDLER(NaClProcessMsg_LoaderLaunched, OnLoaderLaunched) 85 IPC_MESSAGE_HANDLER(NaClProcessMsg_LoaderLaunched, OnLoaderLaunched)
80 IPC_MESSAGE_HANDLER(NaClProcessMsg_DebugExceptionHandlerLaunched, 86 IPC_MESSAGE_HANDLER(NaClProcessMsg_DebugExceptionHandlerLaunched,
81 OnDebugExceptionHandlerLaunched) 87 OnDebugExceptionHandlerLaunched)
82 IPC_MESSAGE_UNHANDLED(handled = false) 88 IPC_MESSAGE_UNHANDLED(handled = false)
83 IPC_END_MESSAGE_MAP() 89 IPC_END_MESSAGE_MAP()
84 return handled; 90 return handled;
85 } 91 }
86 92
87 bool NaClBrokerHost::LaunchLoader(const std::string& loader_channel_id) { 93 bool NaClBrokerHost::LaunchLoader(const std::string& loader_channel_id) {
Mark Seaborn 2016/07/08 20:26:19 "token" rather than "id" now?
Anand Mistry (off Chromium) 2016/07/12 07:26:23 Done.
88 return process_->Send( 94 return process_->Send(
89 new NaClProcessMsg_LaunchLoaderThroughBroker(loader_channel_id)); 95 new NaClProcessMsg_LaunchLoaderThroughBroker(loader_channel_id));
90 } 96 }
91 97
92 void NaClBrokerHost::OnLoaderLaunched(const std::string& loader_channel_id, 98 void NaClBrokerHost::OnLoaderLaunched(const std::string& loader_channel_id,
93 base::ProcessHandle handle) { 99 base::ProcessHandle handle) {
94 NaClBrokerService::GetInstance()->OnLoaderLaunched(loader_channel_id, handle); 100 NaClBrokerService::GetInstance()->OnLoaderLaunched(loader_channel_id, handle);
95 } 101 }
96 102
97 bool NaClBrokerHost::LaunchDebugExceptionHandler( 103 bool NaClBrokerHost::LaunchDebugExceptionHandler(
(...skipping 15 matching lines...) Expand all
113 NaClBrokerService::GetInstance()->OnDebugExceptionHandlerLaunched(pid, 119 NaClBrokerService::GetInstance()->OnDebugExceptionHandlerLaunched(pid,
114 success); 120 success);
115 } 121 }
116 122
117 void NaClBrokerHost::StopBroker() { 123 void NaClBrokerHost::StopBroker() {
118 is_terminating_ = true; 124 is_terminating_ = true;
119 process_->Send(new NaClProcessMsg_StopBroker()); 125 process_->Send(new NaClProcessMsg_StopBroker());
120 } 126 }
121 127
122 } // namespace nacl 128 } // namespace nacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698