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 "content/browser/worker_host/worker_process_host.h" | 5 #include "content/browser/worker_host/worker_process_host.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... | |
40 #include "content/browser/worker_host/worker_message_filter.h" | 40 #include "content/browser/worker_host/worker_message_filter.h" |
41 #include "content/browser/worker_host/worker_service_impl.h" | 41 #include "content/browser/worker_host/worker_service_impl.h" |
42 #include "content/common/child_process_host_impl.h" | 42 #include "content/common/child_process_host_impl.h" |
43 #include "content/common/view_messages.h" | 43 #include "content/common/view_messages.h" |
44 #include "content/common/worker_messages.h" | 44 #include "content/common/worker_messages.h" |
45 #include "content/public/browser/browser_thread.h" | 45 #include "content/public/browser/browser_thread.h" |
46 #include "content/public/browser/content_browser_client.h" | 46 #include "content/public/browser/content_browser_client.h" |
47 #include "content/public/browser/user_metrics.h" | 47 #include "content/public/browser/user_metrics.h" |
48 #include "content/public/common/content_switches.h" | 48 #include "content/public/common/content_switches.h" |
49 #include "content/public/common/result_codes.h" | 49 #include "content/public/common/result_codes.h" |
50 #include "content/public/common/sandboxed_process_launcher_delegate.h" | |
50 #include "ipc/ipc_switches.h" | 51 #include "ipc/ipc_switches.h" |
51 #include "net/base/mime_util.h" | 52 #include "net/base/mime_util.h" |
52 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 53 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
53 #include "net/url_request/url_request_context_getter.h" | 54 #include "net/url_request/url_request_context_getter.h" |
54 #include "ui/base/ui_base_switches.h" | 55 #include "ui/base/ui_base_switches.h" |
55 #include "webkit/browser/fileapi/file_system_context.h" | 56 #include "webkit/browser/fileapi/file_system_context.h" |
56 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" | 57 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" |
57 #include "webkit/common/resource_type.h" | 58 #include "webkit/common/resource_type.h" |
58 | 59 |
59 #if defined(OS_WIN) | 60 #if defined(OS_WIN) |
60 #include "content/common/sandbox_win.h" | 61 #include "content/common/sandbox_win.h" |
61 #include "content/public/common/sandboxed_process_launcher_delegate.h" | |
62 #endif | 62 #endif |
63 | 63 |
64 namespace content { | 64 namespace content { |
65 namespace { | 65 namespace { |
66 | 66 |
67 #if defined(OS_WIN) | 67 #if defined(OS_WIN) |
68 // NOTE: changes to this class need to be reviewed by the security team. | 68 // NOTE: changes to this class need to be reviewed by the security team. |
69 class WorkerSandboxedProcessLauncherDelegate | 69 class WorkerSandboxedProcessLauncherDelegate |
70 : public content::SandboxedProcessLauncherDelegate { | 70 : public content::SandboxedProcessLauncherDelegate { |
71 public: | 71 public: |
72 WorkerSandboxedProcessLauncherDelegate() {} | 72 WorkerSandboxedProcessLauncherDelegate(ChildProcessHost* /*host*/) {} |
73 virtual ~WorkerSandboxedProcessLauncherDelegate() {} | 73 virtual ~WorkerSandboxedProcessLauncherDelegate() {} |
74 | 74 |
75 virtual void PreSpawnTarget(sandbox::TargetPolicy* policy, | 75 virtual void PreSpawnTarget(sandbox::TargetPolicy* policy, |
76 bool* success) { | 76 bool* success) { |
77 AddBaseHandleClosePolicy(policy); | 77 AddBaseHandleClosePolicy(policy); |
78 } | 78 } |
79 }; | 79 }; |
80 | |
81 #elif defined(OS_POSIX) | |
82 // NOTE: changes to this class need to be reviewed by the security team. | |
jam
2014/02/26 19:47:52
ditto
aberent
2014/02/28 08:51:07
Done.
| |
83 class WorkerSandboxedProcessLauncherDelegate | |
84 : public content::SandboxedProcessLauncherDelegate { | |
85 public: | |
86 WorkerSandboxedProcessLauncherDelegate(ChildProcessHost* host) | |
87 : ipc_fd_(host->TakeClientFileDescriptor()) {} | |
88 | |
89 virtual ~WorkerSandboxedProcessLauncherDelegate() {} | |
90 | |
91 virtual bool UseZygote() OVERRIDE { | |
92 | |
93 // If debugging the child then disable the zigote | |
94 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
95 switches::kWaitForDebuggerChildren)) { | |
96 // Look to pass-on the kWaitForDebugger flag. | |
97 std::string value = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
98 switches::kWaitForDebuggerChildren); | |
99 if (value.empty() || value == switches::kWorkerProcess) { | |
100 return false; | |
101 } | |
102 } | |
103 | |
104 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDebugChildren)) { | |
105 // Look to pass-on the kDebugOnStart flag. | |
106 std::string value = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
107 switches::kDebugChildren); | |
108 if (value.empty() || value == switches::kWorkerProcess) { | |
109 // launches a new xterm, and runs the worker process in gdb, reading | |
110 // optional commands from gdb_chrome file in the working directory. | |
111 return false; | |
112 } | |
113 } | |
jam
2014/02/26 19:47:52
this method body looks like a copy of the code tha
aberent
2014/02/28 08:51:07
Done. BTW I am slightly puzzled as to why there is
jam
2014/02/28 18:07:43
it's probably an oversight..
| |
114 return true; | |
115 } | |
116 virtual int IpcFd() OVERRIDE { | |
117 return ipc_fd_; | |
118 } | |
119 private: | |
120 int ipc_fd_; | |
121 }; | |
80 #endif // OS_WIN | 122 #endif // OS_WIN |
81 | 123 |
82 // Notifies RenderViewHost that one or more worker objects crashed. | 124 // Notifies RenderViewHost that one or more worker objects crashed. |
83 void WorkerCrashCallback(int render_process_unique_id, int render_frame_id) { | 125 void WorkerCrashCallback(int render_process_unique_id, int render_frame_id) { |
84 RenderFrameHostImpl* host = | 126 RenderFrameHostImpl* host = |
85 RenderFrameHostImpl::FromID(render_process_unique_id, render_frame_id); | 127 RenderFrameHostImpl::FromID(render_process_unique_id, render_frame_id); |
86 if (host) | 128 if (host) |
87 host->delegate()->WorkerCrashed(host); | 129 host->delegate()->WorkerCrashed(host); |
88 } | 130 } |
89 | 131 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 #if defined(OS_MACOSX) | 229 #if defined(OS_MACOSX) |
188 switches::kEnableSandboxLogging, | 230 switches::kEnableSandboxLogging, |
189 #endif | 231 #endif |
190 switches::kJavaScriptFlags, | 232 switches::kJavaScriptFlags, |
191 switches::kNoSandbox | 233 switches::kNoSandbox |
192 }; | 234 }; |
193 cmd_line->CopySwitchesFrom(*CommandLine::ForCurrentProcess(), kSwitchNames, | 235 cmd_line->CopySwitchesFrom(*CommandLine::ForCurrentProcess(), kSwitchNames, |
194 arraysize(kSwitchNames)); | 236 arraysize(kSwitchNames)); |
195 | 237 |
196 #if defined(OS_POSIX) | 238 #if defined(OS_POSIX) |
197 bool use_zygote = true; | |
198 | |
199 if (CommandLine::ForCurrentProcess()->HasSwitch( | 239 if (CommandLine::ForCurrentProcess()->HasSwitch( |
200 switches::kWaitForDebuggerChildren)) { | 240 switches::kWaitForDebuggerChildren)) { |
201 // Look to pass-on the kWaitForDebugger flag. | 241 // Look to pass-on the kWaitForDebugger flag. |
202 std::string value = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 242 std::string value = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
203 switches::kWaitForDebuggerChildren); | 243 switches::kWaitForDebuggerChildren); |
204 if (value.empty() || value == switches::kWorkerProcess) { | 244 if (value.empty() || value == switches::kWorkerProcess) { |
205 cmd_line->AppendSwitch(switches::kWaitForDebugger); | 245 cmd_line->AppendSwitch(switches::kWaitForDebugger); |
206 use_zygote = false; | |
207 } | 246 } |
208 } | 247 } |
209 | 248 |
210 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDebugChildren)) { | 249 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDebugChildren)) { |
211 // Look to pass-on the kDebugOnStart flag. | 250 // Look to pass-on the kDebugOnStart flag. |
212 std::string value = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 251 std::string value = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
213 switches::kDebugChildren); | 252 switches::kDebugChildren); |
214 if (value.empty() || value == switches::kWorkerProcess) { | 253 if (value.empty() || value == switches::kWorkerProcess) { |
215 // launches a new xterm, and runs the worker process in gdb, reading | 254 // launches a new xterm, and runs the worker process in gdb, reading |
216 // optional commands from gdb_chrome file in the working directory. | 255 // optional commands from gdb_chrome file in the working directory. |
217 cmd_line->PrependWrapper("xterm -e gdb -x gdb_chrome --args"); | 256 cmd_line->PrependWrapper("xterm -e gdb -x gdb_chrome --args"); |
218 use_zygote = false; | |
219 } | 257 } |
220 } | 258 } |
221 #endif | 259 #endif |
222 | 260 |
223 process_->Launch( | 261 process_->Launch( |
224 #if defined(OS_WIN) | 262 new WorkerSandboxedProcessLauncherDelegate(process_->GetHost()), |
225 new WorkerSandboxedProcessLauncherDelegate, | |
226 false, | |
227 #elif defined(OS_POSIX) | |
228 use_zygote, | |
229 base::EnvironmentMap(), | |
230 #endif | |
231 cmd_line); | 263 cmd_line); |
232 | 264 |
233 ChildProcessSecurityPolicyImpl::GetInstance()->AddWorker( | 265 ChildProcessSecurityPolicyImpl::GetInstance()->AddWorker( |
234 process_->GetData().id, render_process_id); | 266 process_->GetData().id, render_process_id); |
235 CreateMessageFilters(render_process_id); | 267 CreateMessageFilters(render_process_id); |
236 | 268 |
237 BrowserThread::PostTask( | 269 BrowserThread::PostTask( |
238 BrowserThread::UI, FROM_HERE, | 270 BrowserThread::UI, FROM_HERE, |
239 base::Bind(&WorkerCreatedCallback, | 271 base::Bind(&WorkerCreatedCallback, |
240 render_process_id, | 272 render_process_id, |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
808 return false; | 840 return false; |
809 } | 841 } |
810 | 842 |
811 WorkerProcessHost::WorkerInstance::FilterInfo | 843 WorkerProcessHost::WorkerInstance::FilterInfo |
812 WorkerProcessHost::WorkerInstance::GetFilter() const { | 844 WorkerProcessHost::WorkerInstance::GetFilter() const { |
813 DCHECK(NumFilters() == 1); | 845 DCHECK(NumFilters() == 1); |
814 return *filters_.begin(); | 846 return *filters_.begin(); |
815 } | 847 } |
816 | 848 |
817 } // namespace content | 849 } // namespace content |
OLD | NEW |