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) | |
68 // NOTE: changes to this class need to be reviewed by the security team. | 67 // NOTE: changes to this class need to be reviewed by the security team. |
69 class WorkerSandboxedProcessLauncherDelegate | 68 class WorkerSandboxedProcessLauncherDelegate |
70 : public content::SandboxedProcessLauncherDelegate { | 69 : public content::SandboxedProcessLauncherDelegate { |
71 public: | 70 public: |
72 WorkerSandboxedProcessLauncherDelegate() {} | 71 WorkerSandboxedProcessLauncherDelegate(ChildProcessHost* host, |
| 72 bool debugging_child) |
| 73 #if defined(OS_POSIX) |
| 74 : ipc_fd_(host->TakeClientFileDescriptor()), |
| 75 debugging_child_(debugging_child) |
| 76 #endif // OS_POSIX |
| 77 {} |
| 78 |
73 virtual ~WorkerSandboxedProcessLauncherDelegate() {} | 79 virtual ~WorkerSandboxedProcessLauncherDelegate() {} |
74 | 80 |
| 81 #if defined(OS_WIN) |
75 virtual void PreSpawnTarget(sandbox::TargetPolicy* policy, | 82 virtual void PreSpawnTarget(sandbox::TargetPolicy* policy, |
76 bool* success) { | 83 bool* success) { |
77 AddBaseHandleClosePolicy(policy); | 84 AddBaseHandleClosePolicy(policy); |
78 } | 85 } |
| 86 #elif defined(OS_POSIX) |
| 87 virtual bool ShouldUseZygote() OVERRIDE { |
| 88 return !debugging_child_; |
| 89 } |
| 90 virtual int GetIpcFd() OVERRIDE { |
| 91 return ipc_fd_; |
| 92 } |
| 93 #endif // OS_WIN |
| 94 |
| 95 private: |
| 96 #if defined(OS_POSIX) |
| 97 int ipc_fd_; |
| 98 bool debugging_child_; |
| 99 #endif // OS_POSIX |
79 }; | 100 }; |
80 #endif // OS_WIN | |
81 | 101 |
82 // Notifies RenderViewHost that one or more worker objects crashed. | 102 // Notifies RenderViewHost that one or more worker objects crashed. |
83 void WorkerCrashCallback(int render_process_unique_id, int render_frame_id) { | 103 void WorkerCrashCallback(int render_process_unique_id, int render_frame_id) { |
84 RenderFrameHostImpl* host = | 104 RenderFrameHostImpl* host = |
85 RenderFrameHostImpl::FromID(render_process_unique_id, render_frame_id); | 105 RenderFrameHostImpl::FromID(render_process_unique_id, render_frame_id); |
86 if (host) | 106 if (host) |
87 host->delegate()->WorkerCrashed(host); | 107 host->delegate()->WorkerCrashed(host); |
88 } | 108 } |
89 | 109 |
90 void WorkerCreatedCallback(int render_process_id, | 110 void WorkerCreatedCallback(int render_process_id, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 switches::kEnableServiceWorker, | 206 switches::kEnableServiceWorker, |
187 #if defined(OS_MACOSX) | 207 #if defined(OS_MACOSX) |
188 switches::kEnableSandboxLogging, | 208 switches::kEnableSandboxLogging, |
189 #endif | 209 #endif |
190 switches::kJavaScriptFlags, | 210 switches::kJavaScriptFlags, |
191 switches::kNoSandbox | 211 switches::kNoSandbox |
192 }; | 212 }; |
193 cmd_line->CopySwitchesFrom(*CommandLine::ForCurrentProcess(), kSwitchNames, | 213 cmd_line->CopySwitchesFrom(*CommandLine::ForCurrentProcess(), kSwitchNames, |
194 arraysize(kSwitchNames)); | 214 arraysize(kSwitchNames)); |
195 | 215 |
| 216 bool debugging_child = false; |
196 #if defined(OS_POSIX) | 217 #if defined(OS_POSIX) |
197 bool use_zygote = true; | |
198 | |
199 if (CommandLine::ForCurrentProcess()->HasSwitch( | 218 if (CommandLine::ForCurrentProcess()->HasSwitch( |
200 switches::kWaitForDebuggerChildren)) { | 219 switches::kWaitForDebuggerChildren)) { |
201 // Look to pass-on the kWaitForDebugger flag. | 220 // Look to pass-on the kWaitForDebugger flag. |
202 std::string value = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 221 std::string value = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
203 switches::kWaitForDebuggerChildren); | 222 switches::kWaitForDebuggerChildren); |
204 if (value.empty() || value == switches::kWorkerProcess) { | 223 if (value.empty() || value == switches::kWorkerProcess) { |
205 cmd_line->AppendSwitch(switches::kWaitForDebugger); | 224 cmd_line->AppendSwitch(switches::kWaitForDebugger); |
206 use_zygote = false; | 225 debugging_child = true; |
207 } | 226 } |
208 } | 227 } |
209 | 228 |
210 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDebugChildren)) { | 229 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDebugChildren)) { |
211 // Look to pass-on the kDebugOnStart flag. | 230 // Look to pass-on the kDebugOnStart flag. |
212 std::string value = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 231 std::string value = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
213 switches::kDebugChildren); | 232 switches::kDebugChildren); |
214 if (value.empty() || value == switches::kWorkerProcess) { | 233 if (value.empty() || value == switches::kWorkerProcess) { |
215 // launches a new xterm, and runs the worker process in gdb, reading | 234 // launches a new xterm, and runs the worker process in gdb, reading |
216 // optional commands from gdb_chrome file in the working directory. | 235 // optional commands from gdb_chrome file in the working directory. |
217 cmd_line->PrependWrapper("xterm -e gdb -x gdb_chrome --args"); | 236 cmd_line->PrependWrapper("xterm -e gdb -x gdb_chrome --args"); |
218 use_zygote = false; | 237 debugging_child = true; |
219 } | 238 } |
220 } | 239 } |
221 #endif | 240 #endif |
222 | 241 |
223 process_->Launch( | 242 process_->Launch( |
224 #if defined(OS_WIN) | 243 new WorkerSandboxedProcessLauncherDelegate(process_->GetHost(), |
225 new WorkerSandboxedProcessLauncherDelegate, | 244 debugging_child), |
226 false, | |
227 #elif defined(OS_POSIX) | |
228 use_zygote, | |
229 base::EnvironmentMap(), | |
230 #endif | |
231 cmd_line); | 245 cmd_line); |
232 | 246 |
233 ChildProcessSecurityPolicyImpl::GetInstance()->AddWorker( | 247 ChildProcessSecurityPolicyImpl::GetInstance()->AddWorker( |
234 process_->GetData().id, render_process_id); | 248 process_->GetData().id, render_process_id); |
235 CreateMessageFilters(render_process_id); | 249 CreateMessageFilters(render_process_id); |
236 | 250 |
237 BrowserThread::PostTask( | 251 BrowserThread::PostTask( |
238 BrowserThread::UI, FROM_HERE, | 252 BrowserThread::UI, FROM_HERE, |
239 base::Bind(&WorkerCreatedCallback, | 253 base::Bind(&WorkerCreatedCallback, |
240 render_process_id, | 254 render_process_id, |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 return false; | 822 return false; |
809 } | 823 } |
810 | 824 |
811 WorkerProcessHost::WorkerInstance::FilterInfo | 825 WorkerProcessHost::WorkerInstance::FilterInfo |
812 WorkerProcessHost::WorkerInstance::GetFilter() const { | 826 WorkerProcessHost::WorkerInstance::GetFilter() const { |
813 DCHECK(NumFilters() == 1); | 827 DCHECK(NumFilters() == 1); |
814 return *filters_.begin(); | 828 return *filters_.begin(); |
815 } | 829 } |
816 | 830 |
817 } // namespace content | 831 } // namespace content |
OLD | NEW |