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 "chrome/browser/chrome_content_browser_client.h" | 5 #include "chrome/browser/chrome_content_browser_client.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/files/scoped_file.h" | 14 #include "base/files/scoped_file.h" |
15 #include "base/i18n/icu_util.h" | |
16 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
17 #include "base/path_service.h" | 16 #include "base/path_service.h" |
18 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
19 #include "base/prefs/scoped_user_pref_update.h" | 18 #include "base/prefs/scoped_user_pref_update.h" |
20 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
21 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
22 #include "base/thread_task_runner_handle.h" | 21 #include "base/thread_task_runner_handle.h" |
23 #include "base/threading/sequenced_worker_pool.h" | 22 #include "base/threading/sequenced_worker_pool.h" |
24 #include "chrome/browser/after_startup_task_utils.h" | 23 #include "chrome/browser/after_startup_task_utils.h" |
25 #include "chrome/browser/browser_about_handler.h" | 24 #include "chrome/browser/browser_about_handler.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 #include "content/public/browser/render_view_host.h" | 117 #include "content/public/browser/render_view_host.h" |
119 #include "content/public/browser/resource_context.h" | 118 #include "content/public/browser/resource_context.h" |
120 #include "content/public/browser/site_instance.h" | 119 #include "content/public/browser/site_instance.h" |
121 #include "content/public/browser/web_contents.h" | 120 #include "content/public/browser/web_contents.h" |
122 #include "content/public/common/child_process_host.h" | 121 #include "content/public/common/child_process_host.h" |
123 #include "content/public/common/content_descriptors.h" | 122 #include "content/public/common/content_descriptors.h" |
124 #include "content/public/common/service_registry.h" | 123 #include "content/public/common/service_registry.h" |
125 #include "content/public/common/url_utils.h" | 124 #include "content/public/common/url_utils.h" |
126 #include "content/public/common/web_preferences.h" | 125 #include "content/public/common/web_preferences.h" |
127 #include "device/devices_app/devices_app.h" | 126 #include "device/devices_app/devices_app.h" |
128 #include "gin/v8_initializer.h" | |
129 #include "net/base/mime_util.h" | 127 #include "net/base/mime_util.h" |
130 #include "net/cookies/canonical_cookie.h" | 128 #include "net/cookies/canonical_cookie.h" |
131 #include "net/cookies/cookie_options.h" | 129 #include "net/cookies/cookie_options.h" |
132 #include "net/ssl/ssl_cert_request_info.h" | 130 #include "net/ssl/ssl_cert_request_info.h" |
133 #include "ppapi/host/ppapi_host.h" | 131 #include "ppapi/host/ppapi_host.h" |
134 #include "storage/browser/fileapi/external_mount_points.h" | 132 #include "storage/browser/fileapi/external_mount_points.h" |
135 #include "ui/base/l10n/l10n_util.h" | 133 #include "ui/base/l10n/l10n_util.h" |
136 #include "ui/base/resource/resource_bundle.h" | 134 #include "ui/base/resource/resource_bundle.h" |
137 #include "ui/resources/grit/ui_resources.h" | 135 #include "ui/resources/grit/ui_resources.h" |
138 | 136 |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 incognito)); | 601 incognito)); |
604 } | 602 } |
605 #endif // defined(ENABLE_EXTENSIONS) | 603 #endif // defined(ENABLE_EXTENSIONS) |
606 | 604 |
607 } // namespace | 605 } // namespace |
608 | 606 |
609 namespace chrome { | 607 namespace chrome { |
610 | 608 |
611 ChromeContentBrowserClient::ChromeContentBrowserClient() | 609 ChromeContentBrowserClient::ChromeContentBrowserClient() |
612 : | 610 : |
613 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
614 v8_natives_fd_(-1), | |
615 v8_snapshot_fd_(-1), | |
616 #endif // OS_POSIX && !OS_MACOSX | |
617 weak_factory_(this) { | 611 weak_factory_(this) { |
618 #if defined(ENABLE_PLUGINS) | 612 #if defined(ENABLE_PLUGINS) |
619 for (size_t i = 0; i < arraysize(kPredefinedAllowedDevChannelOrigins); ++i) | 613 for (size_t i = 0; i < arraysize(kPredefinedAllowedDevChannelOrigins); ++i) |
620 allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]); | 614 allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]); |
621 for (size_t i = 0; i < arraysize(kPredefinedAllowedFileHandleOrigins); ++i) | 615 for (size_t i = 0; i < arraysize(kPredefinedAllowedFileHandleOrigins); ++i) |
622 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]); | 616 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]); |
623 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i) | 617 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i) |
624 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]); | 618 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]); |
625 | 619 |
626 extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart); | 620 extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart); |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1168 } | 1162 } |
1169 if (browser_command_line.HasSwitch( | 1163 if (browser_command_line.HasSwitch( |
1170 switches::kDisableOfflineAutoReloadVisibleOnly)) { | 1164 switches::kDisableOfflineAutoReloadVisibleOnly)) { |
1171 return false; | 1165 return false; |
1172 } | 1166 } |
1173 return true; | 1167 return true; |
1174 } | 1168 } |
1175 | 1169 |
1176 } // namespace | 1170 } // namespace |
1177 | 1171 |
1178 // When Chrome is updated on non-Windows platforms, the new files (like | |
1179 // V8 natives and snapshot) can have the same names as the previous | |
1180 // versions. Since the renderers for an existing Chrome browser process | |
1181 // are likely not compatible with the new files, the browser keeps hold | |
1182 // of the old files using an open fd. This fd is passed to subprocesses | |
1183 // like renderers. Here we add the flag to tell the subprocesses where | |
1184 // to find these file descriptors. | |
1185 void ChromeContentBrowserClient::AppendMappedFileCommandLineSwitches( | |
1186 base::CommandLine* command_line) { | |
1187 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
1188 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | |
1189 std::string process_type = | |
1190 command_line->GetSwitchValueASCII(switches::kProcessType); | |
1191 if (process_type != switches::kZygoteProcess) { | |
1192 // We want to pass the natives by fd because after an update the file may | |
1193 // be updated, but we want the newly launched renderers to get the old one, | |
1194 // opened by the browser when it started. | |
1195 DCHECK(natives_fd_exists()); | |
1196 command_line->AppendSwitch(::switches::kV8NativesPassedByFD); | |
1197 if (snapshot_fd_exists()) | |
1198 command_line->AppendSwitch(::switches::kV8SnapshotPassedByFD); | |
1199 } | |
1200 #endif // V8_USE_EXTERNAL_STARTUP_DATA | |
1201 #endif // OS_POSIX && !OS_MACOSX | |
1202 } | |
1203 | |
1204 void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( | 1172 void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( |
1205 base::CommandLine* command_line, | 1173 base::CommandLine* command_line, |
1206 int child_process_id) { | 1174 int child_process_id) { |
1207 #if defined(OS_MACOSX) | 1175 #if defined(OS_MACOSX) |
1208 scoped_ptr<metrics::ClientInfo> client_info = | 1176 scoped_ptr<metrics::ClientInfo> client_info = |
1209 GoogleUpdateSettings::LoadMetricsClientInfo(); | 1177 GoogleUpdateSettings::LoadMetricsClientInfo(); |
1210 if (client_info) { | 1178 if (client_info) { |
1211 command_line->AppendSwitchASCII(switches::kMetricsClientID, | 1179 command_line->AppendSwitchASCII(switches::kMetricsClientID, |
1212 client_info->client_id); | 1180 client_info->client_id); |
1213 } | 1181 } |
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2239 extra_parts_[i]->GetAdditionalFileSystemBackends( | 2207 extra_parts_[i]->GetAdditionalFileSystemBackends( |
2240 browser_context, storage_partition_path, additional_backends); | 2208 browser_context, storage_partition_path, additional_backends); |
2241 } | 2209 } |
2242 } | 2210 } |
2243 | 2211 |
2244 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 2212 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
2245 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess( | 2213 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess( |
2246 const base::CommandLine& command_line, | 2214 const base::CommandLine& command_line, |
2247 int child_process_id, | 2215 int child_process_id, |
2248 FileDescriptorInfo* mappings) { | 2216 FileDescriptorInfo* mappings) { |
2249 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | |
2250 if (!natives_fd_exists()) { | |
2251 int v8_natives_fd = -1; | |
2252 int v8_snapshot_fd = -1; | |
2253 if (gin::V8Initializer::OpenV8FilesForChildProcesses(&v8_natives_fd, | |
2254 &v8_snapshot_fd)) { | |
2255 v8_natives_fd_.reset(v8_natives_fd); | |
2256 v8_snapshot_fd_.reset(v8_snapshot_fd); | |
2257 } | |
2258 } | |
2259 // V8 can't start up without the source of the natives, but it can | |
2260 // start up (slower) without the snapshot. | |
2261 DCHECK(natives_fd_exists()); | |
2262 mappings->Share(kV8NativesDataDescriptor, v8_natives_fd_.get()); | |
2263 if (snapshot_fd_exists()) | |
2264 mappings->Share(kV8SnapshotDataDescriptor, v8_snapshot_fd_.get()); | |
2265 #endif // V8_USE_EXTERNAL_STARTUP_DATA | |
2266 | |
2267 #if defined(OS_ANDROID) | 2217 #if defined(OS_ANDROID) |
2268 base::FilePath data_path; | 2218 base::FilePath data_path; |
2269 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path); | 2219 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path); |
2270 DCHECK(!data_path.empty()); | 2220 DCHECK(!data_path.empty()); |
2271 | 2221 |
2272 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; | 2222 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; |
2273 base::FilePath chrome_resources_pak = | 2223 base::FilePath chrome_resources_pak = |
2274 data_path.AppendASCII("chrome_100_percent.pak"); | 2224 data_path.AppendASCII("chrome_100_percent.pak"); |
2275 base::File file(chrome_resources_pak, flags); | 2225 base::File file(chrome_resources_pak, flags); |
2276 DCHECK(file.IsValid()); | 2226 DCHECK(file.IsValid()); |
(...skipping 23 matching lines...) Expand all Loading... |
2300 base::ScopedFD(file.TakePlatformFile())); | 2250 base::ScopedFD(file.TakePlatformFile())); |
2301 } else { | 2251 } else { |
2302 LOG(ERROR) << "Failed to create file for minidump, crash reporting will " | 2252 LOG(ERROR) << "Failed to create file for minidump, crash reporting will " |
2303 "be disabled for this process."; | 2253 "be disabled for this process."; |
2304 } | 2254 } |
2305 } | 2255 } |
2306 | 2256 |
2307 base::FilePath app_data_path; | 2257 base::FilePath app_data_path; |
2308 PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path); | 2258 PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path); |
2309 DCHECK(!app_data_path.empty()); | 2259 DCHECK(!app_data_path.empty()); |
2310 | |
2311 flags = base::File::FLAG_OPEN | base::File::FLAG_READ; | |
2312 base::FilePath icudata_path = | |
2313 app_data_path.AppendASCII(base::i18n::kIcuDataFileName); | |
2314 base::File icudata_file(icudata_path, flags); | |
2315 DCHECK(icudata_file.IsValid()); | |
2316 mappings->Transfer(kAndroidICUDataDescriptor, | |
2317 base::ScopedFD(icudata_file.TakePlatformFile())); | |
2318 #else | 2260 #else |
2319 int crash_signal_fd = GetCrashSignalFD(command_line); | 2261 int crash_signal_fd = GetCrashSignalFD(command_line); |
2320 if (crash_signal_fd >= 0) { | 2262 if (crash_signal_fd >= 0) { |
2321 mappings->Share(kCrashDumpSignal, crash_signal_fd); | 2263 mappings->Share(kCrashDumpSignal, crash_signal_fd); |
2322 } | 2264 } |
2323 #endif // defined(OS_ANDROID) | 2265 #endif // defined(OS_ANDROID) |
2324 } | 2266 } |
2325 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) | 2267 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
2326 | 2268 |
2327 #if defined(OS_WIN) | 2269 #if defined(OS_WIN) |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2492 switches::kDisableWebRtcEncryption, | 2434 switches::kDisableWebRtcEncryption, |
2493 }; | 2435 }; |
2494 to_command_line->CopySwitchesFrom(from_command_line, | 2436 to_command_line->CopySwitchesFrom(from_command_line, |
2495 kWebRtcDevSwitchNames, | 2437 kWebRtcDevSwitchNames, |
2496 arraysize(kWebRtcDevSwitchNames)); | 2438 arraysize(kWebRtcDevSwitchNames)); |
2497 } | 2439 } |
2498 } | 2440 } |
2499 #endif // defined(ENABLE_WEBRTC) | 2441 #endif // defined(ENABLE_WEBRTC) |
2500 | 2442 |
2501 } // namespace chrome | 2443 } // namespace chrome |
OLD | NEW |