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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 return false; | 200 return false; |
207 } | 201 } |
208 | 202 |
209 void ShellContentBrowserClient::AppendMappedFileCommandLineSwitches( | 203 void ShellContentBrowserClient::AppendMappedFileCommandLineSwitches( |
210 base::CommandLine* command_line) { | 204 base::CommandLine* command_line) { |
211 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 205 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
212 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | 206 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
213 std::string process_type = | 207 std::string process_type = |
214 command_line->GetSwitchValueASCII(switches::kProcessType); | 208 command_line->GetSwitchValueASCII(switches::kProcessType); |
215 if (process_type != switches::kZygoteProcess) { | 209 if (process_type != switches::kZygoteProcess) { |
216 DCHECK(natives_fd_exists()); | 210 DCHECK(v8_files_.natives_fd.is_valid()); |
217 command_line->AppendSwitch(::switches::kV8NativesPassedByFD); | 211 command_line->AppendSwitch(::switches::kV8NativesPassedByFD); |
218 if (snapshot_fd_exists()) | 212 // V8 can't start up without the source of the natives, but it can |
| 213 // start up (slower) without the snapshot. |
| 214 if (v8_files_.snapshot_fd.is_valid()) { |
219 command_line->AppendSwitch(::switches::kV8SnapshotPassedByFD); | 215 command_line->AppendSwitch(::switches::kV8SnapshotPassedByFD); |
| 216 } |
220 } | 217 } |
221 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 218 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
222 #endif // OS_POSIX && !OS_MACOSX | 219 #endif // OS_POSIX && !OS_MACOSX |
223 } | 220 } |
224 | 221 |
225 void ShellContentBrowserClient::AppendExtraCommandLineSwitches( | 222 void ShellContentBrowserClient::AppendExtraCommandLineSwitches( |
226 base::CommandLine* command_line, | 223 base::CommandLine* command_line, |
227 int child_process_id) { | 224 int child_process_id) { |
228 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 225 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
229 switches::kRunLayoutTest)) | 226 switches::kRunLayoutTest)) |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 343 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
347 void ShellContentBrowserClient::GetAdditionalMappedFilesForChildProcess( | 344 void ShellContentBrowserClient::GetAdditionalMappedFilesForChildProcess( |
348 const base::CommandLine& command_line, | 345 const base::CommandLine& command_line, |
349 int child_process_id, | 346 int child_process_id, |
350 FileDescriptorInfo* mappings | 347 FileDescriptorInfo* mappings |
351 #if defined(OS_ANDROID) | 348 #if defined(OS_ANDROID) |
352 , std::map<int, base::MemoryMappedFile::Region>* regions | 349 , std::map<int, base::MemoryMappedFile::Region>* regions |
353 #endif | 350 #endif |
354 ) { | 351 ) { |
355 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | 352 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
356 if (!natives_fd_exists()) { | 353 if (!v8_files_.natives_fd.is_valid()) { |
357 int v8_natives_fd = -1; | 354 gin::V8Initializer::OpenV8FilesForChildProcesses(&v8_files_); |
358 int v8_snapshot_fd = -1; | |
359 if (gin::V8Initializer::OpenV8FilesForChildProcesses(&v8_natives_fd, | |
360 &v8_snapshot_fd)) { | |
361 v8_natives_fd_.reset(v8_natives_fd); | |
362 v8_snapshot_fd_.reset(v8_snapshot_fd); | |
363 } | |
364 } | 355 } |
365 // V8 can't start up without the source of the natives, but it can | 356 DCHECK(v8_files_.natives_fd.is_valid()); |
366 // start up (slower) without the snapshot. | 357 mappings->Share(kV8NativesDataDescriptor, v8_files_.natives_fd.get()); |
367 DCHECK(natives_fd_exists()); | 358 #if defined(OS_ANDROID) |
368 mappings->Share(kV8NativesDataDescriptor, v8_natives_fd_.get()); | 359 regions->insert( |
369 mappings->Share(kV8SnapshotDataDescriptor, v8_snapshot_fd_.get()); | 360 std::make_pair(kV8NativesDataDescriptor, v8_files_.natives_region)); |
| 361 #endif |
| 362 if (v8_files_.snapshot_fd.is_valid()) { |
| 363 mappings->Share(kV8SnapshotDataDescriptor, v8_files_.snapshot_fd.get()); |
| 364 #if defined(OS_ANDROID) |
| 365 regions->insert( |
| 366 std::make_pair(kV8SnapshotDataDescriptor, v8_files_.snapshot_region)); |
| 367 #endif |
| 368 } |
370 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 369 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
371 | |
372 #if defined(OS_ANDROID) | 370 #if defined(OS_ANDROID) |
373 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; | 371 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; |
374 base::FilePath pak_file; | 372 base::FilePath pak_file; |
375 bool r = PathService::Get(base::DIR_ANDROID_APP_DATA, &pak_file); | 373 bool r = PathService::Get(base::DIR_ANDROID_APP_DATA, &pak_file); |
376 CHECK(r); | 374 CHECK(r); |
377 pak_file = pak_file.Append(FILE_PATH_LITERAL("paks")); | 375 pak_file = pak_file.Append(FILE_PATH_LITERAL("paks")); |
378 pak_file = pak_file.Append(FILE_PATH_LITERAL("content_shell.pak")); | 376 pak_file = pak_file.Append(FILE_PATH_LITERAL("content_shell.pak")); |
379 | 377 |
380 base::File f(pak_file, flags); | 378 base::File f(pak_file, flags); |
381 if (!f.IsValid()) { | 379 if (!f.IsValid()) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 ShellBrowserContext* | 435 ShellBrowserContext* |
438 ShellContentBrowserClient::ShellBrowserContextForBrowserContext( | 436 ShellContentBrowserClient::ShellBrowserContextForBrowserContext( |
439 BrowserContext* content_browser_context) { | 437 BrowserContext* content_browser_context) { |
440 if (content_browser_context == browser_context()) | 438 if (content_browser_context == browser_context()) |
441 return browser_context(); | 439 return browser_context(); |
442 DCHECK_EQ(content_browser_context, off_the_record_browser_context()); | 440 DCHECK_EQ(content_browser_context, off_the_record_browser_context()); |
443 return off_the_record_browser_context(); | 441 return off_the_record_browser_context(); |
444 } | 442 } |
445 | 443 |
446 } // namespace content | 444 } // namespace content |
OLD | NEW |