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/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "content/shell/browser/shell_browser_context.h" | 27 #include "content/shell/browser/shell_browser_context.h" |
28 #include "content/shell/browser/shell_browser_main_parts.h" | 28 #include "content/shell/browser/shell_browser_main_parts.h" |
29 #include "content/shell/browser/shell_devtools_manager_delegate.h" | 29 #include "content/shell/browser/shell_devtools_manager_delegate.h" |
30 #include "content/shell/browser/shell_net_log.h" | 30 #include "content/shell/browser/shell_net_log.h" |
31 #include "content/shell/browser/shell_quota_permission_context.h" | 31 #include "content/shell/browser/shell_quota_permission_context.h" |
32 #include "content/shell/browser/shell_resource_dispatcher_host_delegate.h" | 32 #include "content/shell/browser/shell_resource_dispatcher_host_delegate.h" |
33 #include "content/shell/browser/shell_web_contents_view_delegate_creator.h" | 33 #include "content/shell/browser/shell_web_contents_view_delegate_creator.h" |
34 #include "content/shell/common/shell_messages.h" | 34 #include "content/shell/common/shell_messages.h" |
35 #include "content/shell/common/shell_switches.h" | 35 #include "content/shell/common/shell_switches.h" |
36 #include "content/shell/renderer/layout_test/blink_test_helpers.h" | 36 #include "content/shell/renderer/layout_test/blink_test_helpers.h" |
| 37 #include "gin/v8_initializer.h" |
37 #include "net/url_request/url_request_context_getter.h" | 38 #include "net/url_request/url_request_context_getter.h" |
38 #include "url/gurl.h" | 39 #include "url/gurl.h" |
39 | 40 |
40 #if defined(OS_ANDROID) | 41 #if defined(OS_ANDROID) |
41 #include "base/android/path_utils.h" | 42 #include "base/android/path_utils.h" |
42 #include "components/crash/browser/crash_dump_manager_android.h" | 43 #include "components/crash/browser/crash_dump_manager_android.h" |
43 #include "content/shell/android/shell_descriptors.h" | 44 #include "content/shell/android/shell_descriptors.h" |
44 #endif | 45 #endif |
45 | 46 |
46 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 47 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 122 |
122 ShellContentBrowserClient* ShellContentBrowserClient::Get() { | 123 ShellContentBrowserClient* ShellContentBrowserClient::Get() { |
123 return g_browser_client; | 124 return g_browser_client; |
124 } | 125 } |
125 | 126 |
126 void ShellContentBrowserClient::SetSwapProcessesForRedirect(bool swap) { | 127 void ShellContentBrowserClient::SetSwapProcessesForRedirect(bool swap) { |
127 g_swap_processes_for_redirect = swap; | 128 g_swap_processes_for_redirect = swap; |
128 } | 129 } |
129 | 130 |
130 ShellContentBrowserClient::ShellContentBrowserClient() | 131 ShellContentBrowserClient::ShellContentBrowserClient() |
131 : shell_browser_main_parts_(NULL) { | 132 : |
| 133 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 134 v8_natives_fd_(-1), |
| 135 v8_snapshot_fd_(-1), |
| 136 #endif // OS_POSIX && !OS_MACOSX |
| 137 shell_browser_main_parts_(NULL) { |
132 DCHECK(!g_browser_client); | 138 DCHECK(!g_browser_client); |
133 g_browser_client = this; | 139 g_browser_client = this; |
134 } | 140 } |
135 | 141 |
136 ShellContentBrowserClient::~ShellContentBrowserClient() { | 142 ShellContentBrowserClient::~ShellContentBrowserClient() { |
137 g_browser_client = NULL; | 143 g_browser_client = NULL; |
138 } | 144 } |
139 | 145 |
140 BrowserMainParts* ShellContentBrowserClient::CreateBrowserMainParts( | 146 BrowserMainParts* ShellContentBrowserClient::CreateBrowserMainParts( |
141 const MainFunctionParams& parameters) { | 147 const MainFunctionParams& parameters) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 url::kDataScheme, | 199 url::kDataScheme, |
194 url::kFileScheme, | 200 url::kFileScheme, |
195 }; | 201 }; |
196 for (size_t i = 0; i < arraysize(kProtocolList); ++i) { | 202 for (size_t i = 0; i < arraysize(kProtocolList); ++i) { |
197 if (url.scheme() == kProtocolList[i]) | 203 if (url.scheme() == kProtocolList[i]) |
198 return true; | 204 return true; |
199 } | 205 } |
200 return false; | 206 return false; |
201 } | 207 } |
202 | 208 |
| 209 void ShellContentBrowserClient::AppendMappedFileCommandLineSwitches( |
| 210 base::CommandLine* command_line) { |
| 211 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 212 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
| 213 std::string process_type = |
| 214 command_line->GetSwitchValueASCII(switches::kProcessType); |
| 215 if (process_type != switches::kZygoteProcess) { |
| 216 DCHECK(natives_fd_exists()); |
| 217 command_line->AppendSwitch(::switches::kV8NativesPassedByFD); |
| 218 if (snapshot_fd_exists()) |
| 219 command_line->AppendSwitch(::switches::kV8SnapshotPassedByFD); |
| 220 } |
| 221 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 222 #endif // OS_POSIX && !OS_MACOSX |
| 223 } |
| 224 |
203 void ShellContentBrowserClient::AppendExtraCommandLineSwitches( | 225 void ShellContentBrowserClient::AppendExtraCommandLineSwitches( |
204 base::CommandLine* command_line, | 226 base::CommandLine* command_line, |
205 int child_process_id) { | 227 int child_process_id) { |
206 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 228 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
207 switches::kRunLayoutTest)) | 229 switches::kRunLayoutTest)) |
208 command_line->AppendSwitch(switches::kRunLayoutTest); | 230 command_line->AppendSwitch(switches::kRunLayoutTest); |
209 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 231 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
210 switches::kEnableFontAntialiasing)) | 232 switches::kEnableFontAntialiasing)) |
211 command_line->AppendSwitch(switches::kEnableFontAntialiasing); | 233 command_line->AppendSwitch(switches::kEnableFontAntialiasing); |
212 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 234 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 params.url, | 341 params.url, |
320 nullptr, | 342 nullptr, |
321 gfx::Size())->web_contents()); | 343 gfx::Size())->web_contents()); |
322 } | 344 } |
323 | 345 |
324 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 346 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
325 void ShellContentBrowserClient::GetAdditionalMappedFilesForChildProcess( | 347 void ShellContentBrowserClient::GetAdditionalMappedFilesForChildProcess( |
326 const base::CommandLine& command_line, | 348 const base::CommandLine& command_line, |
327 int child_process_id, | 349 int child_process_id, |
328 FileDescriptorInfo* mappings) { | 350 FileDescriptorInfo* mappings) { |
| 351 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
| 352 if (!natives_fd_exists()) { |
| 353 int v8_natives_fd = -1; |
| 354 int v8_snapshot_fd = -1; |
| 355 if (gin::V8Initializer::OpenV8FilesForChildProcesses(&v8_natives_fd, |
| 356 &v8_snapshot_fd)) { |
| 357 v8_natives_fd_.reset(v8_natives_fd); |
| 358 v8_snapshot_fd_.reset(v8_snapshot_fd); |
| 359 } |
| 360 } |
| 361 // V8 can't start up without the source of the natives, but it can |
| 362 // start up (slower) without the snapshot. |
| 363 DCHECK(natives_fd_exists()); |
| 364 mappings->Share(kV8NativesDataDescriptor, v8_natives_fd_.get()); |
| 365 mappings->Share(kV8SnapshotDataDescriptor, v8_snapshot_fd_.get()); |
| 366 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 367 |
329 #if defined(OS_ANDROID) | 368 #if defined(OS_ANDROID) |
330 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; | 369 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; |
331 base::FilePath pak_file; | 370 base::FilePath pak_file; |
332 bool r = PathService::Get(base::DIR_ANDROID_APP_DATA, &pak_file); | 371 bool r = PathService::Get(base::DIR_ANDROID_APP_DATA, &pak_file); |
333 CHECK(r); | 372 CHECK(r); |
334 pak_file = pak_file.Append(FILE_PATH_LITERAL("paks")); | 373 pak_file = pak_file.Append(FILE_PATH_LITERAL("paks")); |
335 pak_file = pak_file.Append(FILE_PATH_LITERAL("content_shell.pak")); | 374 pak_file = pak_file.Append(FILE_PATH_LITERAL("content_shell.pak")); |
336 | 375 |
337 base::File f(pak_file, flags); | 376 base::File f(pak_file, flags); |
338 if (!f.IsValid()) { | 377 if (!f.IsValid()) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 ShellBrowserContext* | 433 ShellBrowserContext* |
395 ShellContentBrowserClient::ShellBrowserContextForBrowserContext( | 434 ShellContentBrowserClient::ShellBrowserContextForBrowserContext( |
396 BrowserContext* content_browser_context) { | 435 BrowserContext* content_browser_context) { |
397 if (content_browser_context == browser_context()) | 436 if (content_browser_context == browser_context()) |
398 return browser_context(); | 437 return browser_context(); |
399 DCHECK_EQ(content_browser_context, off_the_record_browser_context()); | 438 DCHECK_EQ(content_browser_context, off_the_record_browser_context()); |
400 return off_the_record_browser_context(); | 439 return off_the_record_browser_context(); |
401 } | 440 } |
402 | 441 |
403 } // namespace content | 442 } // namespace content |
OLD | NEW |