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 #ifndef COMPONENTS_NACL_BROWSER_NACL_PROCESS_HOST_H_ | 5 #ifndef COMPONENTS_NACL_BROWSER_NACL_PROCESS_HOST_H_ |
6 #define COMPONENTS_NACL_BROWSER_NACL_PROCESS_HOST_H_ | 6 #define COMPONENTS_NACL_BROWSER_NACL_PROCESS_HOST_H_ |
7 | 7 |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 | 9 |
| 10 #include <string> |
| 11 #include <utility> |
| 12 #include <vector> |
| 13 |
10 #include "base/files/file.h" | 14 #include "base/files/file.h" |
11 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
12 #include "base/files/file_util_proxy.h" | 16 #include "base/files/file_util_proxy.h" |
13 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
14 #include "base/memory/shared_memory.h" | 18 #include "base/memory/shared_memory.h" |
15 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
16 #include "base/message_loop/message_loop.h" | 20 #include "base/message_loop/message_loop.h" |
17 #include "base/process/process.h" | 21 #include "base/process/process.h" |
18 #include "components/nacl/common/nacl_types.h" | 22 #include "components/nacl/common/nacl_types.h" |
19 #include "content/public/browser/browser_child_process_host_delegate.h" | 23 #include "content/public/browser/browser_child_process_host_delegate.h" |
(...skipping 19 matching lines...) Expand all Loading... |
39 void* AllocateAddressSpaceASLR(base::ProcessHandle process, size_t size); | 43 void* AllocateAddressSpaceASLR(base::ProcessHandle process, size_t size); |
40 | 44 |
41 // Represents the browser side of the browser <--> NaCl communication | 45 // Represents the browser side of the browser <--> NaCl communication |
42 // channel. There will be one NaClProcessHost per NaCl process | 46 // channel. There will be one NaClProcessHost per NaCl process |
43 // The browser is responsible for starting the NaCl process | 47 // The browser is responsible for starting the NaCl process |
44 // when requested by the renderer. | 48 // when requested by the renderer. |
45 // After that, most of the communication is directly between NaCl plugin | 49 // After that, most of the communication is directly between NaCl plugin |
46 // running in the renderer and NaCl processes. | 50 // running in the renderer and NaCl processes. |
47 class NaClProcessHost : public content::BrowserChildProcessHostDelegate { | 51 class NaClProcessHost : public content::BrowserChildProcessHostDelegate { |
48 public: | 52 public: |
| 53 class ResourceFileInfo; |
49 // manifest_url: the URL of the manifest of the Native Client plugin being | 54 // manifest_url: the URL of the manifest of the Native Client plugin being |
50 // executed. | 55 // executed. |
51 // nexe_file: A file that corresponds to the nexe module to be loaded. | 56 // nexe_file: A file that corresponds to the nexe module to be loaded. |
52 // nexe_token: A cache validation token for nexe_file. | 57 // nexe_token: A cache validation token for nexe_file. |
53 // permissions: PPAPI permissions, to control access to private APIs. | 58 // permissions: PPAPI permissions, to control access to private APIs. |
54 // render_view_id: RenderView routing id, to control access to private APIs. | 59 // render_view_id: RenderView routing id, to control access to private APIs. |
55 // permission_bits: controls which interfaces the NaCl plugin can use. | 60 // permission_bits: controls which interfaces the NaCl plugin can use. |
56 // uses_nonsfi_mode: whether the program should be loaded under non-SFI mode. | 61 // uses_nonsfi_mode: whether the program should be loaded under non-SFI mode. |
57 // off_the_record: was the process launched from an incognito renderer? | 62 // off_the_record: was the process launched from an incognito renderer? |
58 // process_type: the type of NaCl process. | 63 // process_type: the type of NaCl process. |
59 // profile_directory: is the path of current profile directory. | 64 // profile_directory: is the path of current profile directory. |
60 NaClProcessHost(const GURL& manifest_url, | 65 NaClProcessHost( |
61 base::File nexe_file, | 66 const GURL& manifest_url, |
62 const NaClFileToken& nexe_token, | 67 base::File nexe_file, |
63 ppapi::PpapiPermissions permissions, | 68 const NaClFileToken& nexe_token, |
64 int render_view_id, | 69 scoped_ptr<ResourceFileInfo[]> resource_files_info, |
65 uint32 permission_bits, | 70 size_t resource_files_info_len_, |
66 bool uses_nonsfi_mode, | 71 ppapi::PpapiPermissions permissions, |
67 bool off_the_record, | 72 int render_view_id, |
68 NaClAppProcessType process_type, | 73 uint32 permission_bits, |
69 const base::FilePath& profile_directory); | 74 bool uses_nonsfi_mode, |
| 75 bool off_the_record, |
| 76 NaClAppProcessType process_type, |
| 77 const base::FilePath& profile_directory); |
70 ~NaClProcessHost() override; | 78 ~NaClProcessHost() override; |
71 | 79 |
72 void OnProcessCrashed(int exit_status) override; | 80 void OnProcessCrashed(int exit_status) override; |
73 | 81 |
74 // Do any minimal work that must be done at browser startup. | 82 // Do any minimal work that must be done at browser startup. |
75 static void EarlyStartup(); | 83 static void EarlyStartup(); |
76 | 84 |
77 // Specifies throttling time in milliseconds for PpapiHostMsg_Keepalive IPCs. | 85 // Specifies throttling time in milliseconds for PpapiHostMsg_Keepalive IPCs. |
78 static void SetPpapiKeepAliveThrottleForTesting(unsigned milliseconds); | 86 static void SetPpapiKeepAliveThrottleForTesting(unsigned milliseconds); |
79 | 87 |
80 // Initialize the new NaCl process. Result is returned by sending ipc | 88 // Initialize the new NaCl process. Result is returned by sending ipc |
81 // message reply_msg. | 89 // message reply_msg. |
82 void Launch(NaClHostMessageFilter* nacl_host_message_filter, | 90 void Launch(NaClHostMessageFilter* nacl_host_message_filter, |
83 IPC::Message* reply_msg, | 91 IPC::Message* reply_msg, |
84 const base::FilePath& manifest_path); | 92 const base::FilePath& manifest_path); |
85 | 93 |
86 void OnChannelConnected(int32 peer_pid) override; | 94 void OnChannelConnected(int32 peer_pid) override; |
87 | 95 |
88 #if defined(OS_WIN) | 96 #if defined(OS_WIN) |
89 void OnProcessLaunchedByBroker(base::ProcessHandle handle); | 97 void OnProcessLaunchedByBroker(base::ProcessHandle handle); |
90 void OnDebugExceptionHandlerLaunchedByBroker(bool success); | 98 void OnDebugExceptionHandlerLaunchedByBroker(bool success); |
91 #endif | 99 #endif |
92 | 100 |
93 bool Send(IPC::Message* msg); | 101 bool Send(IPC::Message* msg); |
94 | 102 |
95 content::BrowserChildProcessHost* process() { return process_.get(); } | 103 content::BrowserChildProcessHost* process() { return process_.get(); } |
96 content::BrowserPpapiHost* browser_ppapi_host() { return ppapi_host_.get(); } | 104 content::BrowserPpapiHost* browser_ppapi_host() { return ppapi_host_.get(); } |
97 | 105 |
| 106 class ResourceFileInfo { |
| 107 MOVE_ONLY_TYPE_FOR_CPP_03(ResourceFileInfo, RValue); |
| 108 public: |
| 109 ResourceFileInfo(); |
| 110 ResourceFileInfo(base::File file, |
| 111 const NaClFileToken& file_token, |
| 112 const std::string& file_key); |
| 113 ~ResourceFileInfo(); |
| 114 |
| 115 ResourceFileInfo(RValue other); |
| 116 ResourceFileInfo& operator=(RValue other); |
| 117 |
| 118 base::File file() { return file_.Pass(); } |
| 119 const NaClFileToken& file_token() const { return file_token_; } |
| 120 const std::string& file_key() const { return file_key_; } |
| 121 |
| 122 private: |
| 123 base::File file_; |
| 124 NaClFileToken file_token_; |
| 125 std::string file_key_; |
| 126 }; |
| 127 |
98 private: | 128 private: |
99 bool LaunchNaClGdb(); | 129 bool LaunchNaClGdb(); |
100 | 130 |
101 // Mark the process as using a particular GDB debug stub port and notify | 131 // Mark the process as using a particular GDB debug stub port and notify |
102 // listeners (if the port is not kGdbDebugStubPortUnknown). | 132 // listeners (if the port is not kGdbDebugStubPortUnknown). |
103 void SetDebugStubPort(int port); | 133 void SetDebugStubPort(int port); |
104 | 134 |
105 #if defined(OS_POSIX) | 135 #if defined(OS_POSIX) |
106 // Create bound TCP socket in the browser process so that the NaCl GDB debug | 136 // Create bound TCP socket in the browser process so that the NaCl GDB debug |
107 // stub can use it to accept incoming connections even when the Chrome sandbox | 137 // stub can use it to accept incoming connections even when the Chrome sandbox |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // created. | 205 // created. |
176 void OnPpapiChannelsCreated( | 206 void OnPpapiChannelsCreated( |
177 const IPC::ChannelHandle& browser_channel_handle, | 207 const IPC::ChannelHandle& browser_channel_handle, |
178 const IPC::ChannelHandle& ppapi_renderer_channel_handle, | 208 const IPC::ChannelHandle& ppapi_renderer_channel_handle, |
179 const IPC::ChannelHandle& trusted_renderer_channel_handle, | 209 const IPC::ChannelHandle& trusted_renderer_channel_handle, |
180 const IPC::ChannelHandle& manifest_service_channel_handle); | 210 const IPC::ChannelHandle& manifest_service_channel_handle); |
181 | 211 |
182 GURL manifest_url_; | 212 GURL manifest_url_; |
183 base::File nexe_file_; | 213 base::File nexe_file_; |
184 NaClFileToken nexe_token_; | 214 NaClFileToken nexe_token_; |
| 215 scoped_ptr<ResourceFileInfo[]> resource_files_info_; |
| 216 size_t resource_files_info_len_; |
185 | 217 |
186 ppapi::PpapiPermissions permissions_; | 218 ppapi::PpapiPermissions permissions_; |
187 | 219 |
188 #if defined(OS_WIN) | 220 #if defined(OS_WIN) |
189 // This field becomes true when the broker successfully launched | 221 // This field becomes true when the broker successfully launched |
190 // the NaCl loader. | 222 // the NaCl loader. |
191 bool process_launched_by_broker_; | 223 bool process_launched_by_broker_; |
192 #endif | 224 #endif |
193 // The NaClHostMessageFilter that requested this NaCl process. We use | 225 // The NaClHostMessageFilter that requested this NaCl process. We use |
194 // this for sending the reply once the process has started. | 226 // this for sending the reply once the process has started. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 base::File socket_for_sel_ldr_; | 268 base::File socket_for_sel_ldr_; |
237 | 269 |
238 base::WeakPtrFactory<NaClProcessHost> weak_factory_; | 270 base::WeakPtrFactory<NaClProcessHost> weak_factory_; |
239 | 271 |
240 DISALLOW_COPY_AND_ASSIGN(NaClProcessHost); | 272 DISALLOW_COPY_AND_ASSIGN(NaClProcessHost); |
241 }; | 273 }; |
242 | 274 |
243 } // namespace nacl | 275 } // namespace nacl |
244 | 276 |
245 #endif // COMPONENTS_NACL_BROWSER_NACL_PROCESS_HOST_H_ | 277 #endif // COMPONENTS_NACL_BROWSER_NACL_PROCESS_HOST_H_ |
OLD | NEW |