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" | |
38 #include "net/url_request/url_request_context_getter.h" | 37 #include "net/url_request/url_request_context_getter.h" |
39 #include "url/gurl.h" | 38 #include "url/gurl.h" |
40 | 39 |
41 #if defined(OS_ANDROID) | 40 #if defined(OS_ANDROID) |
42 #include "base/android/path_utils.h" | 41 #include "base/android/path_utils.h" |
43 #include "components/crash/browser/crash_dump_manager_android.h" | 42 #include "components/crash/browser/crash_dump_manager_android.h" |
44 #include "content/shell/android/shell_descriptors.h" | 43 #include "content/shell/android/shell_descriptors.h" |
45 #endif | 44 #endif |
46 | 45 |
47 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 46 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 121 |
123 ShellContentBrowserClient* ShellContentBrowserClient::Get() { | 122 ShellContentBrowserClient* ShellContentBrowserClient::Get() { |
124 return g_browser_client; | 123 return g_browser_client; |
125 } | 124 } |
126 | 125 |
127 void ShellContentBrowserClient::SetSwapProcessesForRedirect(bool swap) { | 126 void ShellContentBrowserClient::SetSwapProcessesForRedirect(bool swap) { |
128 g_swap_processes_for_redirect = swap; | 127 g_swap_processes_for_redirect = swap; |
129 } | 128 } |
130 | 129 |
131 ShellContentBrowserClient::ShellContentBrowserClient() | 130 ShellContentBrowserClient::ShellContentBrowserClient() |
132 : | 131 : shell_browser_main_parts_(NULL) { |
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) { | |
138 DCHECK(!g_browser_client); | 132 DCHECK(!g_browser_client); |
139 g_browser_client = this; | 133 g_browser_client = this; |
140 } | 134 } |
141 | 135 |
142 ShellContentBrowserClient::~ShellContentBrowserClient() { | 136 ShellContentBrowserClient::~ShellContentBrowserClient() { |
143 g_browser_client = NULL; | 137 g_browser_client = NULL; |
144 } | 138 } |
145 | 139 |
146 BrowserMainParts* ShellContentBrowserClient::CreateBrowserMainParts( | 140 BrowserMainParts* ShellContentBrowserClient::CreateBrowserMainParts( |
147 const MainFunctionParams& parameters) { | 141 const MainFunctionParams& parameters) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 url::kDataScheme, | 193 url::kDataScheme, |
200 url::kFileScheme, | 194 url::kFileScheme, |
201 }; | 195 }; |
202 for (size_t i = 0; i < arraysize(kProtocolList); ++i) { | 196 for (size_t i = 0; i < arraysize(kProtocolList); ++i) { |
203 if (url.scheme() == kProtocolList[i]) | 197 if (url.scheme() == kProtocolList[i]) |
204 return true; | 198 return true; |
205 } | 199 } |
206 return false; | 200 return false; |
207 } | 201 } |
208 | 202 |
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 | |
225 void ShellContentBrowserClient::AppendExtraCommandLineSwitches( | 203 void ShellContentBrowserClient::AppendExtraCommandLineSwitches( |
226 base::CommandLine* command_line, | 204 base::CommandLine* command_line, |
227 int child_process_id) { | 205 int child_process_id) { |
228 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 206 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
229 switches::kRunLayoutTest)) { | 207 switches::kRunLayoutTest)) { |
230 command_line->AppendSwitch(switches::kRunLayoutTest); | 208 command_line->AppendSwitch(switches::kRunLayoutTest); |
231 } | 209 } |
232 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 210 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
233 switches::kDumpLineBoxTrees)) { | 211 switches::kDumpLineBoxTrees)) { |
234 command_line->AppendSwitch(switches::kDumpLineBoxTrees); | 212 command_line->AppendSwitch(switches::kDumpLineBoxTrees); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 params.url, | 328 params.url, |
351 nullptr, | 329 nullptr, |
352 gfx::Size())->web_contents()); | 330 gfx::Size())->web_contents()); |
353 } | 331 } |
354 | 332 |
355 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 333 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
356 void ShellContentBrowserClient::GetAdditionalMappedFilesForChildProcess( | 334 void ShellContentBrowserClient::GetAdditionalMappedFilesForChildProcess( |
357 const base::CommandLine& command_line, | 335 const base::CommandLine& command_line, |
358 int child_process_id, | 336 int child_process_id, |
359 FileDescriptorInfo* mappings) { | 337 FileDescriptorInfo* mappings) { |
360 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | |
361 if (!natives_fd_exists()) { | |
362 int v8_natives_fd = -1; | |
363 int v8_snapshot_fd = -1; | |
364 if (gin::V8Initializer::OpenV8FilesForChildProcesses(&v8_natives_fd, | |
365 &v8_snapshot_fd)) { | |
366 v8_natives_fd_.reset(v8_natives_fd); | |
367 v8_snapshot_fd_.reset(v8_snapshot_fd); | |
368 } | |
369 } | |
370 // V8 can't start up without the source of the natives, but it can | |
371 // start up (slower) without the snapshot. | |
372 DCHECK(natives_fd_exists()); | |
373 mappings->Share(kV8NativesDataDescriptor, v8_natives_fd_.get()); | |
374 mappings->Share(kV8SnapshotDataDescriptor, v8_snapshot_fd_.get()); | |
375 #endif // V8_USE_EXTERNAL_STARTUP_DATA | |
376 | |
377 #if defined(OS_ANDROID) | 338 #if defined(OS_ANDROID) |
378 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; | 339 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; |
379 base::FilePath pak_file; | 340 base::FilePath pak_file; |
380 bool r = PathService::Get(base::DIR_ANDROID_APP_DATA, &pak_file); | 341 bool r = PathService::Get(base::DIR_ANDROID_APP_DATA, &pak_file); |
381 CHECK(r); | 342 CHECK(r); |
382 pak_file = pak_file.Append(FILE_PATH_LITERAL("paks")); | 343 pak_file = pak_file.Append(FILE_PATH_LITERAL("paks")); |
383 pak_file = pak_file.Append(FILE_PATH_LITERAL("content_shell.pak")); | 344 pak_file = pak_file.Append(FILE_PATH_LITERAL("content_shell.pak")); |
384 | 345 |
385 base::File f(pak_file, flags); | 346 base::File f(pak_file, flags); |
386 if (!f.IsValid()) { | 347 if (!f.IsValid()) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 ShellBrowserContext* | 403 ShellBrowserContext* |
443 ShellContentBrowserClient::ShellBrowserContextForBrowserContext( | 404 ShellContentBrowserClient::ShellBrowserContextForBrowserContext( |
444 BrowserContext* content_browser_context) { | 405 BrowserContext* content_browser_context) { |
445 if (content_browser_context == browser_context()) | 406 if (content_browser_context == browser_context()) |
446 return browser_context(); | 407 return browser_context(); |
447 DCHECK_EQ(content_browser_context, off_the_record_browser_context()); | 408 DCHECK_EQ(content_browser_context, off_the_record_browser_context()); |
448 return off_the_record_browser_context(); | 409 return off_the_record_browser_context(); |
449 } | 410 } |
450 | 411 |
451 } // namespace content | 412 } // namespace content |
OLD | NEW |