OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/shell/browser/shell_content_browser_client.h" | 5 #include "content/shell/browser/shell_content_browser_client.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/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/strings/utf_string_conversions.h" |
12 #include "content/public/browser/render_process_host.h" | 13 #include "content/public/browser/render_process_host.h" |
13 #include "content/public/browser/resource_dispatcher_host.h" | 14 #include "content/public/browser/resource_dispatcher_host.h" |
14 #include "content/public/browser/storage_partition.h" | 15 #include "content/public/browser/storage_partition.h" |
15 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
16 #include "content/public/common/url_constants.h" | 17 #include "content/public/common/url_constants.h" |
17 #include "content/shell/browser/shell.h" | 18 #include "content/shell/browser/shell.h" |
18 #include "content/shell/browser/shell_browser_context.h" | 19 #include "content/shell/browser/shell_browser_context.h" |
19 #include "content/shell/browser/shell_browser_main_parts.h" | 20 #include "content/shell/browser/shell_browser_main_parts.h" |
20 #include "content/shell/browser/shell_devtools_delegate.h" | 21 #include "content/shell/browser/shell_devtools_delegate.h" |
21 #include "content/shell/browser/shell_message_filter.h" | 22 #include "content/shell/browser/shell_message_filter.h" |
(...skipping 18 matching lines...) Expand all Loading... |
40 #endif | 41 #endif |
41 | 42 |
42 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 43 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
43 #include "base/debug/leak_annotations.h" | 44 #include "base/debug/leak_annotations.h" |
44 #include "base/platform_file.h" | 45 #include "base/platform_file.h" |
45 #include "components/breakpad/app/breakpad_linux.h" | 46 #include "components/breakpad/app/breakpad_linux.h" |
46 #include "components/breakpad/browser/crash_handler_host_linux.h" | 47 #include "components/breakpad/browser/crash_handler_host_linux.h" |
47 #include "content/public/common/content_descriptors.h" | 48 #include "content/public/common/content_descriptors.h" |
48 #endif | 49 #endif |
49 | 50 |
| 51 #if defined(OS_WIN) |
| 52 #include "content/common/sandbox_win.h" |
| 53 #include "sandbox/win/src/sandbox.h" |
| 54 #endif |
| 55 |
50 namespace content { | 56 namespace content { |
51 | 57 |
52 namespace { | 58 namespace { |
53 | 59 |
54 ShellContentBrowserClient* g_browser_client; | 60 ShellContentBrowserClient* g_browser_client; |
55 bool g_swap_processes_for_redirect = false; | 61 bool g_swap_processes_for_redirect = false; |
56 | 62 |
57 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 63 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
58 breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost( | 64 breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost( |
59 const std::string& process_type) { | 65 const std::string& process_type) { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 } | 224 } |
219 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kCrashDumpsDir)) { | 225 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kCrashDumpsDir)) { |
220 command_line->AppendSwitchPath( | 226 command_line->AppendSwitchPath( |
221 switches::kCrashDumpsDir, | 227 switches::kCrashDumpsDir, |
222 CommandLine::ForCurrentProcess()->GetSwitchValuePath( | 228 CommandLine::ForCurrentProcess()->GetSwitchValuePath( |
223 switches::kCrashDumpsDir)); | 229 switches::kCrashDumpsDir)); |
224 } | 230 } |
225 if (CommandLine::ForCurrentProcess()->HasSwitch( | 231 if (CommandLine::ForCurrentProcess()->HasSwitch( |
226 switches::kEnableLeakDetection)) | 232 switches::kEnableLeakDetection)) |
227 command_line->AppendSwitch(switches::kEnableLeakDetection); | 233 command_line->AppendSwitch(switches::kEnableLeakDetection); |
| 234 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 235 switches::kRegisterFontFiles)) { |
| 236 command_line->AppendSwitchASCII( |
| 237 switches::kRegisterFontFiles, |
| 238 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 239 switches::kRegisterFontFiles)); |
| 240 } |
228 } | 241 } |
229 | 242 |
230 void ShellContentBrowserClient::OverrideWebkitPrefs( | 243 void ShellContentBrowserClient::OverrideWebkitPrefs( |
231 RenderViewHost* render_view_host, | 244 RenderViewHost* render_view_host, |
232 const GURL& url, | 245 const GURL& url, |
233 WebPreferences* prefs) { | 246 WebPreferences* prefs) { |
234 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) | 247 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) |
235 return; | 248 return; |
236 WebKitTestController::Get()->OverrideWebkitPrefs(prefs); | 249 WebKitTestController::Get()->OverrideWebkitPrefs(prefs); |
237 } | 250 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 #else // !defined(OS_ANDROID) | 327 #else // !defined(OS_ANDROID) |
315 int crash_signal_fd = GetCrashSignalFD(command_line); | 328 int crash_signal_fd = GetCrashSignalFD(command_line); |
316 if (crash_signal_fd >= 0) { | 329 if (crash_signal_fd >= 0) { |
317 mappings->push_back(FileDescriptorInfo( | 330 mappings->push_back(FileDescriptorInfo( |
318 kCrashDumpSignal, base::FileDescriptor(crash_signal_fd, false))); | 331 kCrashDumpSignal, base::FileDescriptor(crash_signal_fd, false))); |
319 } | 332 } |
320 #endif // defined(OS_ANDROID) | 333 #endif // defined(OS_ANDROID) |
321 } | 334 } |
322 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) | 335 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
323 | 336 |
| 337 #if defined(OS_WIN) |
| 338 void ShellContentBrowserClient::PreSpawnRenderer(sandbox::TargetPolicy* policy, |
| 339 bool* success) { |
| 340 // Add sideloaded font files for testing. See also DIR_WINDOWS_FONTS |
| 341 // addition in |StartSandboxedProcess|. |
| 342 std::vector<std::string> font_files = GetSideloadFontFiles(); |
| 343 for (std::vector<std::string>::const_iterator i(font_files.begin()); |
| 344 i != font_files.end(); |
| 345 ++i) { |
| 346 policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES, |
| 347 sandbox::TargetPolicy::FILES_ALLOW_READONLY, |
| 348 base::UTF8ToWide(*i).c_str()); |
| 349 } |
| 350 } |
| 351 #endif // OS_WIN |
| 352 |
324 ShellBrowserContext* ShellContentBrowserClient::browser_context() { | 353 ShellBrowserContext* ShellContentBrowserClient::browser_context() { |
325 return shell_browser_main_parts_->browser_context(); | 354 return shell_browser_main_parts_->browser_context(); |
326 } | 355 } |
327 | 356 |
328 ShellBrowserContext* | 357 ShellBrowserContext* |
329 ShellContentBrowserClient::off_the_record_browser_context() { | 358 ShellContentBrowserClient::off_the_record_browser_context() { |
330 return shell_browser_main_parts_->off_the_record_browser_context(); | 359 return shell_browser_main_parts_->off_the_record_browser_context(); |
331 } | 360 } |
332 | 361 |
333 AccessTokenStore* ShellContentBrowserClient::CreateAccessTokenStore() { | 362 AccessTokenStore* ShellContentBrowserClient::CreateAccessTokenStore() { |
334 return new ShellAccessTokenStore(browser_context()); | 363 return new ShellAccessTokenStore(browser_context()); |
335 } | 364 } |
336 | 365 |
337 ShellBrowserContext* | 366 ShellBrowserContext* |
338 ShellContentBrowserClient::ShellBrowserContextForBrowserContext( | 367 ShellContentBrowserClient::ShellBrowserContextForBrowserContext( |
339 BrowserContext* content_browser_context) { | 368 BrowserContext* content_browser_context) { |
340 if (content_browser_context == browser_context()) | 369 if (content_browser_context == browser_context()) |
341 return browser_context(); | 370 return browser_context(); |
342 DCHECK_EQ(content_browser_context, off_the_record_browser_context()); | 371 DCHECK_EQ(content_browser_context, off_the_record_browser_context()); |
343 return off_the_record_browser_context(); | 372 return off_the_record_browser_context(); |
344 } | 373 } |
345 | 374 |
346 } // namespace content | 375 } // namespace content |
OLD | NEW |