Give names to all utility processes.
[chromium-blink-merge.git] / chrome / browser / chrome_content_browser_client.cc
blobecac5318e6152270ecda1330fffb4f18ba9b590c
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
3 // found in the LICENSE file.
5 #include "chrome/browser/chrome_content_browser_client.h"
7 #include <set>
8 #include <utility>
9 #include <vector>
11 #include "base/bind.h"
12 #include "base/command_line.h"
13 #include "base/files/scoped_file.h"
14 #include "base/i18n/icu_util.h"
15 #include "base/lazy_instance.h"
16 #include "base/path_service.h"
17 #include "base/prefs/pref_service.h"
18 #include "base/prefs/scoped_user_pref_update.h"
19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/utf_string_conversions.h"
21 #include "base/threading/sequenced_worker_pool.h"
22 #include "chrome/browser/browser_about_handler.h"
23 #include "chrome/browser/browser_process.h"
24 #include "chrome/browser/browser_shutdown.h"
25 #include "chrome/browser/browsing_data/browsing_data_helper.h"
26 #include "chrome/browser/browsing_data/browsing_data_remover.h"
27 #include "chrome/browser/character_encoding.h"
28 #include "chrome/browser/chrome_content_browser_client_parts.h"
29 #include "chrome/browser/chrome_net_benchmarking_message_filter.h"
30 #include "chrome/browser/chrome_quota_permission_context.h"
31 #include "chrome/browser/content_settings/cookie_settings.h"
32 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
33 #include "chrome/browser/defaults.h"
34 #include "chrome/browser/download/download_prefs.h"
35 #include "chrome/browser/font_family_cache.h"
36 #include "chrome/browser/geolocation/chrome_access_token_store.h"
37 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
38 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
39 #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
40 #include "chrome/browser/net/chrome_net_log.h"
41 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
42 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h"
43 #include "chrome/browser/notifications/platform_notification_service_impl.h"
44 #include "chrome/browser/platform_util.h"
45 #include "chrome/browser/prerender/prerender_final_status.h"
46 #include "chrome/browser/prerender/prerender_manager.h"
47 #include "chrome/browser/prerender/prerender_manager_factory.h"
48 #include "chrome/browser/prerender/prerender_message_filter.h"
49 #include "chrome/browser/printing/printing_message_filter.h"
50 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
51 #include "chrome/browser/profiles/profile.h"
52 #include "chrome/browser/profiles/profile_io_data.h"
53 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
54 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
55 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
56 #include "chrome/browser/search/instant_service.h"
57 #include "chrome/browser/search/instant_service_factory.h"
58 #include "chrome/browser/search/search.h"
59 #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
60 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
61 #include "chrome/browser/speech/tts_controller.h"
62 #include "chrome/browser/speech/tts_message_filter.h"
63 #include "chrome/browser/ssl/ssl_add_certificate.h"
64 #include "chrome/browser/ssl/ssl_blocking_page.h"
65 #include "chrome/browser/ssl/ssl_client_certificate_selector.h"
66 #include "chrome/browser/ssl/ssl_error_handler.h"
67 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
68 #include "chrome/browser/tab_contents/tab_util.h"
69 #include "chrome/browser/tracing/chrome_tracing_delegate.h"
70 #include "chrome/browser/ui/blocked_content/blocked_window_params.h"
71 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
72 #include "chrome/browser/ui/chrome_select_file_policy.h"
73 #include "chrome/browser/ui/sync/sync_promo_ui.h"
74 #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
75 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
76 #include "chrome/common/chrome_constants.h"
77 #include "chrome/common/chrome_paths.h"
78 #include "chrome/common/chrome_switches.h"
79 #include "chrome/common/env_vars.h"
80 #include "chrome/common/logging_chrome.h"
81 #include "chrome/common/pepper_permission_util.h"
82 #include "chrome/common/pref_names.h"
83 #include "chrome/common/render_messages.h"
84 #include "chrome/common/url_constants.h"
85 #include "chrome/grit/generated_resources.h"
86 #include "chrome/installer/util/google_update_settings.h"
87 #include "chromeos/chromeos_constants.h"
88 #include "components/cdm/browser/cdm_message_filter_android.h"
89 #include "components/cloud_devices/common/cloud_devices_switches.h"
90 #include "components/content_settings/core/browser/content_settings_utils.h"
91 #include "components/content_settings/core/browser/host_content_settings_map.h"
92 #include "components/content_settings/core/common/content_settings.h"
93 #include "components/data_reduction_proxy/content/browser/data_reduction_proxy_message_filter.h"
94 #include "components/dom_distiller/core/url_constants.h"
95 #include "components/google/core/browser/google_util.h"
96 #include "components/metrics/client_info.h"
97 #include "components/pref_registry/pref_registry_syncable.h"
98 #include "components/rappor/rappor_utils.h"
99 #include "components/signin/core/common/profile_management_switches.h"
100 #include "components/translate/core/common/translate_switches.h"
101 #include "components/url_fixer/url_fixer.h"
102 #include "content/public/browser/browser_child_process_host.h"
103 #include "content/public/browser/browser_main_parts.h"
104 #include "content/public/browser/browser_ppapi_host.h"
105 #include "content/public/browser/browser_thread.h"
106 #include "content/public/browser/browser_url_handler.h"
107 #include "content/public/browser/child_process_data.h"
108 #include "content/public/browser/child_process_security_policy.h"
109 #include "content/public/browser/client_certificate_delegate.h"
110 #include "content/public/browser/render_frame_host.h"
111 #include "content/public/browser/render_process_host.h"
112 #include "content/public/browser/render_view_host.h"
113 #include "content/public/browser/resource_context.h"
114 #include "content/public/browser/site_instance.h"
115 #include "content/public/browser/web_contents.h"
116 #include "content/public/common/child_process_host.h"
117 #include "content/public/common/content_descriptors.h"
118 #include "content/public/common/url_utils.h"
119 #include "content/public/common/web_preferences.h"
120 #include "gin/v8_initializer.h"
121 #include "net/base/mime_util.h"
122 #include "net/cookies/canonical_cookie.h"
123 #include "net/cookies/cookie_options.h"
124 #include "net/ssl/ssl_cert_request_info.h"
125 #include "ppapi/host/ppapi_host.h"
126 #include "storage/browser/fileapi/external_mount_points.h"
127 #include "ui/base/l10n/l10n_util.h"
128 #include "ui/base/resource/resource_bundle.h"
129 #include "ui/resources/grit/ui_resources.h"
131 #if defined(OS_WIN)
132 #include "base/win/windows_version.h"
133 #include "chrome/browser/chrome_browser_main_win.h"
134 #include "sandbox/win/src/sandbox_policy.h"
135 #elif defined(OS_MACOSX)
136 #include "chrome/browser/chrome_browser_main_mac.h"
137 #include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
138 #elif defined(OS_CHROMEOS)
139 #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
140 #include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h"
141 #include "chrome/browser/chromeos/file_manager/app_id.h"
142 #include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
143 #include "chrome/browser/chromeos/fileapi/file_system_backend.h"
144 #include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
145 #include "chrome/browser/chromeos/login/startup_utils.h"
146 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
147 #include "chrome/browser/chromeos/system/input_device_settings.h"
148 #include "chromeos/chromeos_switches.h"
149 #include "components/user_manager/user_manager.h"
150 #elif defined(OS_LINUX)
151 #include "chrome/browser/chrome_browser_main_linux.h"
152 #elif defined(OS_ANDROID)
153 #include "chrome/browser/android/new_tab_page_url_handler.h"
154 #include "chrome/browser/android/service_tab_launcher.h"
155 #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
156 #include "chrome/browser/chrome_browser_main_android.h"
157 #include "chrome/common/descriptors_android.h"
158 #include "components/crash/browser/crash_dump_manager_android.h"
159 #elif defined(OS_POSIX)
160 #include "chrome/browser/chrome_browser_main_posix.h"
161 #endif
163 #if defined(OS_POSIX) && !defined(OS_MACOSX)
164 #include "base/debug/leak_annotations.h"
165 #include "components/crash/app/breakpad_linux.h"
166 #include "components/crash/browser/crash_handler_host_linux.h"
167 #endif
169 #if defined(OS_ANDROID)
170 #include "ui/base/ui_base_paths.h"
171 #include "ui/gfx/android/device_display_info.h"
172 #endif
174 #if defined(OS_ANDROID)
175 #include "chrome/browser/android/dev_tools_manager_delegate_android.h"
176 #else
177 #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
178 #endif
180 #if defined(TOOLKIT_VIEWS)
181 #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
182 #endif
184 #if defined(USE_ASH)
185 #include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
186 #endif
188 #if defined(USE_AURA)
189 #include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
190 #endif
192 #if defined(USE_X11)
193 #include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
194 #endif
196 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
197 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
198 #endif
200 #if !defined(DISABLE_NACL)
201 #include "components/nacl/browser/nacl_browser.h"
202 #include "components/nacl/browser/nacl_host_message_filter.h"
203 #include "components/nacl/browser/nacl_process_host.h"
204 #include "components/nacl/common/nacl_process_type.h"
205 #include "components/nacl/common/nacl_switches.h"
206 #endif
208 #if defined(ENABLE_EXTENSIONS)
209 #include "chrome/browser/accessibility/animation_policy_prefs.h"
210 #include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
211 #include "chrome/browser/extensions/extension_util.h"
212 #include "chrome/browser/media/cast_transport_host_filter.h"
213 #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
214 #include "extensions/browser/extension_registry.h"
215 #include "extensions/browser/guest_view/guest_view_base.h"
216 #include "extensions/browser/guest_view/guest_view_manager.h"
217 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
218 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
219 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
220 #include "extensions/common/constants.h"
221 #include "extensions/common/extension.h"
222 #include "extensions/common/extension_set.h"
223 #include "extensions/common/manifest_handlers/background_info.h"
224 #include "extensions/common/manifest_handlers/shared_module_info.h"
225 #include "extensions/common/permissions/permissions_data.h"
226 #include "extensions/common/permissions/socket_permission.h"
227 #include "extensions/common/switches.h"
228 #endif
230 #if defined(ENABLE_PLUGINS)
231 #include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
232 #endif
234 #if defined(ENABLE_SPELLCHECK)
235 #include "chrome/browser/spellchecker/spellcheck_message_filter.h"
236 #endif
238 #if defined(ENABLE_WEBRTC)
239 #include "chrome/browser/media/webrtc_logging_handler_host.h"
240 #endif
242 using base::FileDescriptor;
243 using blink::WebWindowFeatures;
244 using content::AccessTokenStore;
245 using content::BrowserThread;
246 using content::BrowserURLHandler;
247 using content::ChildProcessSecurityPolicy;
248 using content::QuotaPermissionContext;
249 using content::RenderFrameHost;
250 using content::RenderViewHost;
251 using content::ResourceType;
252 using content::SiteInstance;
253 using content::WebContents;
254 using content::WebPreferences;
255 using message_center::NotifierId;
257 #if defined(OS_POSIX)
258 using content::FileDescriptorInfo;
259 #endif
261 #if defined(ENABLE_EXTENSIONS)
262 using extensions::APIPermission;
263 using extensions::ChromeContentBrowserClientExtensionsPart;
264 using extensions::Extension;
265 using extensions::InfoMap;
266 using extensions::Manifest;
267 #endif
269 #if defined(ENABLE_PLUGINS)
270 using plugins::ChromeContentBrowserClientPluginsPart;
271 #endif
273 namespace {
275 // Cached version of the locale so we can return the locale on the I/O
276 // thread.
277 base::LazyInstance<std::string> g_io_thread_application_locale;
279 #if defined(ENABLE_PLUGINS)
280 // TODO(teravest): Add renderer-side API-specific checking for these APIs so
281 // that blanket permission isn't granted to all dev channel APIs for these.
282 // http://crbug.com/386743
283 const char* const kPredefinedAllowedDevChannelOrigins[] = {
284 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/383937
285 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/383937
288 const char* const kPredefinedAllowedFileHandleOrigins[] = {
289 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
290 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
293 const char* const kPredefinedAllowedSocketOrigins[] = {
294 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
295 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
296 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
297 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
298 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
299 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
300 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
301 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
302 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
303 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
304 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
305 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
306 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
307 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
308 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
309 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
310 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
311 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
312 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
313 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
315 #endif
317 // Returns a copy of the given url with its host set to given host and path set
318 // to given path. Other parts of the url will be the same.
319 GURL ReplaceURLHostAndPath(const GURL& url,
320 const std::string& host,
321 const std::string& path) {
322 url::Replacements<char> replacements;
323 replacements.SetHost(host.c_str(), url::Component(0, host.length()));
324 replacements.SetPath(path.c_str(), url::Component(0, path.length()));
325 return url.ReplaceComponents(replacements);
328 // Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
329 GURL AddUberHost(const GURL& url) {
330 const std::string uber_host = chrome::kChromeUIUberHost;
331 const std::string new_path = url.host() + url.path();
333 return ReplaceURLHostAndPath(url, uber_host, new_path);
336 // If url->host() is "chrome" and url->path() has characters other than the
337 // first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
338 // returns true. Otherwise returns false.
339 bool RemoveUberHost(GURL* url) {
340 if (url->host() != chrome::kChromeUIUberHost)
341 return false;
343 if (url->path().empty() || url->path() == "/")
344 return false;
346 const std::string old_path = url->path();
348 const std::string::size_type separator = old_path.find('/', 1);
349 std::string new_host;
350 std::string new_path;
351 if (separator == std::string::npos) {
352 new_host = old_path.substr(1);
353 } else {
354 new_host = old_path.substr(1, separator - 1);
355 new_path = old_path.substr(separator);
358 // Do not allow URLs with paths empty before the first slash since we can't
359 // have an empty host. (e.g "foo://chrome//")
360 if (new_host.empty())
361 return false;
363 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
365 DCHECK(url->is_valid());
367 return true;
370 // Handles rewriting Web UI URLs.
371 bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
372 // Do not handle special URLs such as "about:foo"
373 if (!url->host().empty()) {
374 const GURL chrome_url = AddUberHost(*url);
376 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
377 // be called.
378 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
379 browser_context, chrome_url))
380 return true;
383 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
384 browser_context, *url))
385 return false;
387 #if defined(OS_CHROMEOS)
388 // Special case : in ChromeOS in Guest mode bookmarks and history are
389 // disabled for security reasons. New tab page explains the reasons, so
390 // we redirect user to new tab page.
391 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
392 if (url->SchemeIs(content::kChromeUIScheme) &&
393 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
394 url->DomainIs(chrome::kChromeUIHistoryHost))) {
395 // Rewrite with new tab URL
396 *url = GURL(chrome::kChromeUINewTabURL);
399 #endif
401 return true;
404 // Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
405 // "chrome://foo/".
406 bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
407 if (!url->is_valid() || !url->SchemeIs(content::kChromeUIScheme))
408 return false;
410 return RemoveUberHost(url);
413 bool CertMatchesFilter(const net::X509Certificate& cert,
414 const base::DictionaryValue& filter) {
415 // TODO(markusheintz): This is the minimal required filter implementation.
416 // Implement a better matcher.
418 // An empty filter matches any client certificate since no requirements are
419 // specified at all.
420 if (filter.empty())
421 return true;
423 std::string common_name;
424 if (filter.GetString("ISSUER.CN", &common_name) &&
425 (cert.issuer().common_name == common_name)) {
426 return true;
428 return false;
431 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
432 breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
433 const std::string& process_type) {
434 base::FilePath dumps_path;
435 PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
437 ANNOTATE_SCOPED_MEMORY_LEAK;
438 bool upload = (getenv(env_vars::kHeadless) == NULL);
439 breakpad::CrashHandlerHostLinux* crash_handler =
440 new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload);
441 crash_handler->StartUploaderThread();
442 return crash_handler;
446 int GetCrashSignalFD(const base::CommandLine& command_line) {
447 // Extensions have the same process type as renderers.
448 if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) {
449 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
450 if (!crash_handler)
451 crash_handler = CreateCrashHandlerHost("extension");
452 return crash_handler->GetDeathSignalSocket();
455 std::string process_type =
456 command_line.GetSwitchValueASCII(switches::kProcessType);
458 if (process_type == switches::kRendererProcess) {
459 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
460 if (!crash_handler)
461 crash_handler = CreateCrashHandlerHost(process_type);
462 return crash_handler->GetDeathSignalSocket();
465 if (process_type == switches::kPluginProcess) {
466 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
467 if (!crash_handler)
468 crash_handler = CreateCrashHandlerHost(process_type);
469 return crash_handler->GetDeathSignalSocket();
472 if (process_type == switches::kPpapiPluginProcess) {
473 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
474 if (!crash_handler)
475 crash_handler = CreateCrashHandlerHost(process_type);
476 return crash_handler->GetDeathSignalSocket();
479 if (process_type == switches::kGpuProcess) {
480 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
481 if (!crash_handler)
482 crash_handler = CreateCrashHandlerHost(process_type);
483 return crash_handler->GetDeathSignalSocket();
486 return -1;
488 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
490 void SetApplicationLocaleOnIOThread(const std::string& locale) {
491 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
492 g_io_thread_application_locale.Get() = locale;
495 void HandleBlockedPopupOnUIThread(const BlockedWindowParams& params) {
496 // TODO(jochen): This code path should use RenderFrameHosts. See
497 // http://crbug.com/431769 for details.
498 RenderViewHost* render_view_host =
499 RenderViewHost::FromID(params.render_process_id(), params.opener_id());
500 if (!render_view_host)
501 return;
502 WebContents* tab = WebContents::FromRenderViewHost(render_view_host);
503 // The tab might already have navigated away.
504 if (!tab || tab->GetRenderViewHost() != render_view_host)
505 return;
507 prerender::PrerenderContents* prerender_contents =
508 prerender::PrerenderContents::FromWebContents(tab);
509 if (prerender_contents) {
510 prerender_contents->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW);
511 return;
514 PopupBlockerTabHelper* popup_helper =
515 PopupBlockerTabHelper::FromWebContents(tab);
516 if (!popup_helper)
517 return;
518 popup_helper->AddBlockedPopup(params);
521 #if defined(OS_ANDROID)
523 void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams& params) {
524 WebContents* web_contents =
525 tab_util::GetWebContentsByID(params.render_process_id(),
526 params.opener_id());
527 if (!web_contents)
528 return;
530 SingleTabModeTabHelper::FromWebContents(web_contents)->HandleOpenUrl(params);
533 float GetDeviceScaleAdjustment() {
534 static const float kMinFSM = 1.05f;
535 static const int kWidthForMinFSM = 320;
536 static const float kMaxFSM = 1.3f;
537 static const int kWidthForMaxFSM = 800;
539 gfx::DeviceDisplayInfo info;
540 int minWidth = info.GetSmallestDIPWidth();
542 if (minWidth <= kWidthForMinFSM)
543 return kMinFSM;
544 if (minWidth >= kWidthForMaxFSM)
545 return kMaxFSM;
547 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
548 float ratio = static_cast<float>(minWidth - kWidthForMinFSM) /
549 (kWidthForMaxFSM - kWidthForMinFSM);
550 return ratio * (kMaxFSM - kMinFSM) + kMinFSM;
553 #endif // defined(OS_ANDROID)
555 #if defined(ENABLE_EXTENSIONS)
556 // By default, JavaScript and images are enabled in guest content.
557 void GetGuestViewDefaultContentSettingRules(
558 bool incognito,
559 RendererContentSettingRules* rules) {
560 rules->image_rules.push_back(
561 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
562 ContentSettingsPattern::Wildcard(),
563 CONTENT_SETTING_ALLOW,
564 std::string(),
565 incognito));
567 rules->script_rules.push_back(
568 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
569 ContentSettingsPattern::Wildcard(),
570 CONTENT_SETTING_ALLOW,
571 std::string(),
572 incognito));
574 #endif // defined(ENALBE_EXTENSIONS)
576 } // namespace
578 namespace chrome {
580 ChromeContentBrowserClient::ChromeContentBrowserClient()
582 #if defined(OS_POSIX) && !defined(OS_MACOSX)
583 v8_natives_fd_(-1),
584 v8_snapshot_fd_(-1),
585 #endif // OS_POSIX && !OS_MACOSX
586 weak_factory_(this) {
587 #if defined(ENABLE_PLUGINS)
588 for (size_t i = 0; i < arraysize(kPredefinedAllowedDevChannelOrigins); ++i)
589 allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]);
590 for (size_t i = 0; i < arraysize(kPredefinedAllowedFileHandleOrigins); ++i)
591 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]);
592 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
593 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
595 extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart);
596 #endif
598 #if !defined(OS_ANDROID)
599 TtsExtensionEngine* tts_extension_engine = TtsExtensionEngine::GetInstance();
600 TtsController::GetInstance()->SetTtsEngineDelegate(tts_extension_engine);
601 #endif
603 #if defined(ENABLE_EXTENSIONS)
604 extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart);
605 #endif
608 ChromeContentBrowserClient::~ChromeContentBrowserClient() {
609 for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i)
610 delete extra_parts_[i];
611 extra_parts_.clear();
614 // static
615 void ChromeContentBrowserClient::RegisterProfilePrefs(
616 user_prefs::PrefRegistrySyncable* registry) {
617 registry->RegisterBooleanPref(
618 prefs::kDisable3DAPIs,
619 false,
620 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
621 registry->RegisterBooleanPref(
622 prefs::kEnableHyperlinkAuditing,
623 true,
624 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
625 registry->RegisterListPref(
626 prefs::kEnableDeprecatedWebPlatformFeatures,
627 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
630 // static
631 void ChromeContentBrowserClient::SetApplicationLocale(
632 const std::string& locale) {
633 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
635 // This object is guaranteed to outlive all threads so we don't have to
636 // worry about the lack of refcounting and can just post as Unretained.
638 // The common case is that this function is called early in Chrome startup
639 // before any threads are created (it will also be called later if the user
640 // changes the pref). In this case, there will be no threads created and
641 // posting will fail. When there are no threads, we can just set the string
642 // without worrying about threadsafety.
643 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
644 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
645 g_io_thread_application_locale.Get() = locale;
649 content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
650 const content::MainFunctionParams& parameters) {
651 ChromeBrowserMainParts* main_parts;
652 // Construct the Main browser parts based on the OS type.
653 #if defined(OS_WIN)
654 main_parts = new ChromeBrowserMainPartsWin(parameters);
655 #elif defined(OS_MACOSX)
656 main_parts = new ChromeBrowserMainPartsMac(parameters);
657 #elif defined(OS_CHROMEOS)
658 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
659 #elif defined(OS_LINUX)
660 main_parts = new ChromeBrowserMainPartsLinux(parameters);
661 #elif defined(OS_ANDROID)
662 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
663 #elif defined(OS_POSIX)
664 main_parts = new ChromeBrowserMainPartsPosix(parameters);
665 #else
666 NOTREACHED();
667 main_parts = new ChromeBrowserMainParts(parameters);
668 #endif
670 chrome::AddProfilesExtraParts(main_parts);
672 // Construct additional browser parts. Stages are called in the order in
673 // which they are added.
674 #if defined(TOOLKIT_VIEWS)
675 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
676 #endif
678 // TODO(oshima): Athena on chrome currently requires USE_ASH to build.
679 // We should reduce the dependency as much as possible.
680 #if defined(USE_ASH)
681 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
682 #endif
684 #if defined(USE_AURA)
685 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
686 #endif
688 #if defined(USE_X11)
689 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
690 #endif
692 chrome::AddMetricsExtraParts(main_parts);
694 return main_parts;
697 std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
698 content::BrowserContext* browser_context,
699 const GURL& site) {
700 std::string partition_id;
702 // The partition ID for webview guest processes is the string value of its
703 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
704 if (site.SchemeIs(content::kGuestScheme)) {
705 partition_id = site.spec();
706 } else if (!switches::IsEnableWebviewBasedSignin() &&
707 site.GetOrigin().spec() == kChromeUIChromeSigninURL) {
708 // The non-webview Chrome signin page has an embedded iframe of extension
709 // and web content, thus it must be isolated from other webUI pages.
710 partition_id = site.GetOrigin().spec();
713 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
714 return partition_id;
717 bool ChromeContentBrowserClient::IsValidStoragePartitionId(
718 content::BrowserContext* browser_context,
719 const std::string& partition_id) {
720 // The default ID is empty and is always valid.
721 if (partition_id.empty())
722 return true;
724 return GURL(partition_id).is_valid();
727 void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
728 content::BrowserContext* browser_context,
729 const GURL& site,
730 bool can_be_default,
731 std::string* partition_domain,
732 std::string* partition_name,
733 bool* in_memory) {
734 // Default to the browser-wide storage partition and override based on |site|
735 // below.
736 partition_domain->clear();
737 partition_name->clear();
738 *in_memory = false;
740 bool success = false;
741 #if defined(ENABLE_EXTENSIONS)
742 success = extensions::WebViewGuest::GetGuestPartitionConfigForSite(
743 site, partition_domain, partition_name, in_memory);
745 if (!success && site.SchemeIs(extensions::kExtensionScheme)) {
746 // If |can_be_default| is false, the caller is stating that the |site|
747 // should be parsed as if it had isolated storage. In particular it is
748 // important to NOT check ExtensionService for the is_storage_isolated()
749 // attribute because this code path is run during Extension uninstall
750 // to do cleanup after the Extension has already been unloaded from the
751 // ExtensionService.
752 bool is_isolated = !can_be_default;
753 if (can_be_default) {
754 if (extensions::util::SiteHasIsolatedStorage(site, browser_context))
755 is_isolated = true;
758 if (is_isolated) {
759 CHECK(site.has_host());
760 // For extensions with isolated storage, the the host of the |site| is
761 // the |partition_domain|. The |in_memory| and |partition_name| are only
762 // used in guest schemes so they are cleared here.
763 *partition_domain = site.host();
764 *in_memory = false;
765 partition_name->clear();
767 success = true;
769 #endif
771 if (!success && (!switches::IsEnableWebviewBasedSignin() &&
772 site.GetOrigin().spec() == kChromeUIChromeSigninURL)) {
773 // The non-webview Chrome signin page has an embedded iframe of extension
774 // and web content, thus it must be isolated from other webUI pages.
775 *partition_domain = chrome::kChromeUIChromeSigninHost;
778 // Assert that if |can_be_default| is false, the code above must have found a
779 // non-default partition. If this fails, the caller has a serious logic
780 // error about which StoragePartition they expect to be in and it is not
781 // safe to continue.
782 CHECK(can_be_default || !partition_domain->empty());
785 content::WebContentsViewDelegate*
786 ChromeContentBrowserClient::GetWebContentsViewDelegate(
787 content::WebContents* web_contents) {
788 return chrome::CreateWebContentsViewDelegate(web_contents);
791 void ChromeContentBrowserClient::RenderProcessWillLaunch(
792 content::RenderProcessHost* host) {
793 int id = host->GetID();
794 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
795 net::URLRequestContextGetter* context =
796 profile->GetRequestContextForRenderProcess(id);
798 host->AddFilter(new ChromeRenderMessageFilter(id, profile));
799 #if defined(ENABLE_EXTENSIONS)
800 host->AddFilter(new cast::CastTransportHostFilter);
801 #endif
802 #if defined(ENABLE_PRINTING)
803 host->AddFilter(new printing::PrintingMessageFilter(id, profile));
804 #endif
805 host->AddFilter(new SearchProviderInstallStateMessageFilter(id, profile));
806 #if defined(ENABLE_SPELLCHECK)
807 host->AddFilter(new SpellCheckMessageFilter(id));
808 #endif
809 #if defined(OS_MACOSX)
810 host->AddFilter(new SpellCheckMessageFilterMac(id));
811 #endif
812 host->AddFilter(new ChromeNetBenchmarkingMessageFilter(profile, context));
813 host->AddFilter(new prerender::PrerenderMessageFilter(id, profile));
814 host->AddFilter(new TtsMessageFilter(host->GetBrowserContext()));
815 #if defined(ENABLE_WEBRTC)
816 WebRtcLoggingHandlerHost* webrtc_logging_handler_host =
817 new WebRtcLoggingHandlerHost(profile);
818 host->SetWebRtcLogMessageCallback(base::Bind(
819 &WebRtcLoggingHandlerHost::LogMessage, webrtc_logging_handler_host));
820 host->AddFilter(webrtc_logging_handler_host);
821 host->SetUserData(host, new base::UserDataAdapter<WebRtcLoggingHandlerHost>(
822 webrtc_logging_handler_host));
823 #endif
824 #if !defined(DISABLE_NACL)
825 host->AddFilter(new nacl::NaClHostMessageFilter(
826 id, profile->IsOffTheRecord(),
827 profile->GetPath(),
828 context));
829 #endif
830 #if defined(OS_ANDROID)
831 host->AddFilter(new cdm::CdmMessageFilterAndroid());
832 #endif
833 DataReductionProxyChromeSettings* data_reduction_proxy_settings =
834 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(profile);
835 host->AddFilter(new data_reduction_proxy::DataReductionProxyMessageFilter(
836 data_reduction_proxy_settings));
838 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
839 profile->IsOffTheRecord()));
841 for (size_t i = 0; i < extra_parts_.size(); ++i)
842 extra_parts_[i]->RenderProcessWillLaunch(host);
844 RendererContentSettingRules rules;
845 if (host->IsIsolatedGuest()) {
846 #if defined(ENABLE_EXTENSIONS)
847 GetGuestViewDefaultContentSettingRules(profile->IsOffTheRecord(), &rules);
848 #else
849 NOTREACHED();
850 #endif
851 } else {
852 GetRendererContentSettingRules(
853 profile->GetHostContentSettingsMap(), &rules);
855 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
858 GURL ChromeContentBrowserClient::GetEffectiveURL(
859 content::BrowserContext* browser_context, const GURL& url) {
860 Profile* profile = Profile::FromBrowserContext(browser_context);
861 if (!profile)
862 return url;
864 // If the input |url| should be assigned to the Instant renderer, make its
865 // effective URL distinct from other URLs on the search provider's domain.
866 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
867 return chrome::GetEffectiveURLForInstant(url, profile);
869 #if defined(ENABLE_EXTENSIONS)
870 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(
871 profile, url);
872 #else
873 return url;
874 #endif
877 bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
878 content::BrowserContext* browser_context, const GURL& effective_url) {
879 // Non-extension, non-Instant URLs should generally use
880 // process-per-site-instance. Because we expect to use the effective URL,
881 // URLs for hosted apps (apart from bookmark apps) should have an extension
882 // scheme by now.
884 Profile* profile = Profile::FromBrowserContext(browser_context);
885 if (!profile)
886 return false;
888 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
889 return true;
891 #if defined(ENABLE_EXTENSIONS)
892 return ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
893 profile, effective_url);
894 #else
895 return false;
896 #endif
899 // These are treated as WebUI schemes but do not get WebUI bindings. Also,
900 // view-source is allowed for these schemes.
901 void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
902 std::vector<std::string>* additional_schemes) {
903 additional_schemes->push_back(chrome::kChromeSearchScheme);
904 additional_schemes->push_back(dom_distiller::kDomDistillerScheme);
907 void ChromeContentBrowserClient::GetAdditionalWebUIHostsToIgnoreParititionCheck(
908 std::vector<std::string>* hosts) {
909 hosts->push_back(chrome::kChromeUIExtensionIconHost);
910 hosts->push_back(chrome::kChromeUIFaviconHost);
911 hosts->push_back(chrome::kChromeUIThemeHost);
912 hosts->push_back(chrome::kChromeUIThumbnailHost);
913 hosts->push_back(chrome::kChromeUIThumbnailHost2);
914 hosts->push_back(chrome::kChromeUIThumbnailListHost);
917 net::URLRequestContextGetter*
918 ChromeContentBrowserClient::CreateRequestContext(
919 content::BrowserContext* browser_context,
920 content::ProtocolHandlerMap* protocol_handlers,
921 content::URLRequestInterceptorScopedVector request_interceptors) {
922 Profile* profile = Profile::FromBrowserContext(browser_context);
923 return profile->CreateRequestContext(protocol_handlers,
924 request_interceptors.Pass());
927 net::URLRequestContextGetter*
928 ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
929 content::BrowserContext* browser_context,
930 const base::FilePath& partition_path,
931 bool in_memory,
932 content::ProtocolHandlerMap* protocol_handlers,
933 content::URLRequestInterceptorScopedVector request_interceptors) {
934 Profile* profile = Profile::FromBrowserContext(browser_context);
935 return profile->CreateRequestContextForStoragePartition(
936 partition_path,
937 in_memory,
938 protocol_handlers,
939 request_interceptors.Pass());
942 bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
943 return ProfileIOData::IsHandledURL(url);
946 bool ChromeContentBrowserClient::CanCommitURL(
947 content::RenderProcessHost* process_host,
948 const GURL& url) {
949 #if defined(ENABLE_EXTENSIONS)
950 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(
951 process_host, url);
952 #else
953 return true;
954 #endif
957 bool ChromeContentBrowserClient::ShouldAllowOpenURL(
958 content::SiteInstance* site_instance, const GURL& url) {
959 GURL from_url = site_instance->GetSiteURL();
961 #if defined(ENABLE_EXTENSIONS)
962 bool result;
963 if (ChromeContentBrowserClientExtensionsPart::ShouldAllowOpenURL(
964 site_instance, from_url, url, &result))
965 return result;
966 #endif
968 // Do not allow chrome://chrome-signin navigate to other chrome:// URLs, since
969 // the signin page may host untrusted web content.
970 if (from_url.GetOrigin().spec() == chrome::kChromeUIChromeSigninURL &&
971 url.SchemeIs(content::kChromeUIScheme) &&
972 url.host() != chrome::kChromeUIChromeSigninHost) {
973 VLOG(1) << "Blocked navigation to " << url.spec() << " from "
974 << chrome::kChromeUIChromeSigninURL;
975 return false;
978 return true;
981 bool ChromeContentBrowserClient::IsSuitableHost(
982 content::RenderProcessHost* process_host,
983 const GURL& site_url) {
984 Profile* profile =
985 Profile::FromBrowserContext(process_host->GetBrowserContext());
986 // This may be NULL during tests. In that case, just assume any site can
987 // share any host.
988 if (!profile)
989 return true;
991 // Instant URLs should only be in the instant process and instant process
992 // should only have Instant URLs.
993 InstantService* instant_service =
994 InstantServiceFactory::GetForProfile(profile);
995 if (instant_service) {
996 bool is_instant_process = instant_service->IsInstantProcess(
997 process_host->GetID());
998 bool should_be_in_instant_process =
999 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
1000 if (is_instant_process || should_be_in_instant_process)
1001 return is_instant_process && should_be_in_instant_process;
1004 #if defined(ENABLE_EXTENSIONS)
1005 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1006 profile, process_host, site_url);
1007 #else
1008 return true;
1009 #endif
1012 bool ChromeContentBrowserClient::MayReuseHost(
1013 content::RenderProcessHost* process_host) {
1014 // If there is currently a prerender in progress for the host provided,
1015 // it may not be shared. We require prerenders to be by themselves in a
1016 // separate process so that we can monitor their resource usage.
1017 Profile* profile = Profile::FromBrowserContext(
1018 process_host->GetBrowserContext());
1019 prerender::PrerenderManager* prerender_manager =
1020 prerender::PrerenderManagerFactory::GetForProfile(profile);
1021 if (prerender_manager &&
1022 !prerender_manager->MayReuseProcessHost(process_host)) {
1023 return false;
1026 return true;
1029 bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1030 content::BrowserContext* browser_context, const GURL& url) {
1031 // It has to be a valid URL for us to check for an extension.
1032 if (!url.is_valid())
1033 return false;
1035 #if defined(ENABLE_EXTENSIONS)
1036 Profile* profile = Profile::FromBrowserContext(browser_context);
1037 return ChromeContentBrowserClientExtensionsPart::
1038 ShouldTryToUseExistingProcessHost(
1039 profile, url);
1040 #else
1041 return false;
1042 #endif
1045 void ChromeContentBrowserClient::SiteInstanceGotProcess(
1046 SiteInstance* site_instance) {
1047 CHECK(site_instance->HasProcess());
1049 Profile* profile = Profile::FromBrowserContext(
1050 site_instance->GetBrowserContext());
1051 if (!profile)
1052 return;
1054 // Remember the ID of the Instant process to signal the renderer process
1055 // on startup in |AppendExtraCommandLineSwitches| below.
1056 if (chrome::ShouldAssignURLToInstantRenderer(
1057 site_instance->GetSiteURL(), profile)) {
1058 InstantService* instant_service =
1059 InstantServiceFactory::GetForProfile(profile);
1060 if (instant_service)
1061 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1064 for (size_t i = 0; i < extra_parts_.size(); ++i)
1065 extra_parts_[i]->SiteInstanceGotProcess(site_instance);
1068 void ChromeContentBrowserClient::SiteInstanceDeleting(
1069 SiteInstance* site_instance) {
1070 if (!site_instance->HasProcess())
1071 return;
1073 for (size_t i = 0; i < extra_parts_.size(); ++i)
1074 extra_parts_[i]->SiteInstanceDeleting(site_instance);
1077 bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
1078 SiteInstance* site_instance,
1079 const GURL& current_url,
1080 const GURL& new_url) {
1081 #if defined(ENABLE_EXTENSIONS)
1082 return ChromeContentBrowserClientExtensionsPart::
1083 ShouldSwapBrowsingInstancesForNavigation(
1084 site_instance, current_url, new_url);
1085 #else
1086 return false;
1087 #endif
1090 bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1091 content::ResourceContext* resource_context, const GURL& current_url,
1092 const GURL& new_url) {
1093 #if defined(ENABLE_EXTENSIONS)
1094 return ChromeContentBrowserClientExtensionsPart::
1095 ShouldSwapProcessesForRedirect(resource_context, current_url, new_url);
1096 #else
1097 return false;
1098 #endif
1101 bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1102 return !url.SchemeIs(chrome::kChromeNativeScheme);
1105 std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1106 const std::string& alias_name) {
1107 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1110 namespace {
1112 bool IsAutoReloadEnabled() {
1113 // Fetch the field trial, even though we don't use it. Calling FindFullName()
1114 // causes the field-trial mechanism to report which group we're in, which
1115 // might reflect a hard disable or hard enable via flag, both of which have
1116 // their own field trial groups. This lets us know what percentage of users
1117 // manually enable or disable auto-reload.
1118 std::string group = base::FieldTrialList::FindFullName(
1119 "AutoReloadExperiment");
1120 const base::CommandLine& browser_command_line =
1121 *base::CommandLine::ForCurrentProcess();
1122 if (browser_command_line.HasSwitch(switches::kEnableOfflineAutoReload))
1123 return true;
1124 if (browser_command_line.HasSwitch(switches::kDisableOfflineAutoReload))
1125 return false;
1126 return true;
1129 bool IsAutoReloadVisibleOnlyEnabled() {
1130 // See the block comment in IsAutoReloadEnabled().
1131 std::string group = base::FieldTrialList::FindFullName(
1132 "AutoReloadVisibleOnlyExperiment");
1133 const base::CommandLine& browser_command_line =
1134 *base::CommandLine::ForCurrentProcess();
1135 if (browser_command_line.HasSwitch(
1136 switches::kEnableOfflineAutoReloadVisibleOnly)) {
1137 return true;
1139 if (browser_command_line.HasSwitch(
1140 switches::kDisableOfflineAutoReloadVisibleOnly)) {
1141 return false;
1143 return true;
1146 } // namespace
1148 void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1149 base::CommandLine* command_line,
1150 int child_process_id) {
1151 #if defined(OS_MACOSX)
1152 scoped_ptr<metrics::ClientInfo> client_info =
1153 GoogleUpdateSettings::LoadMetricsClientInfo();
1154 if (client_info) {
1155 command_line->AppendSwitchASCII(switches::kMetricsClientID,
1156 client_info->client_id);
1158 #elif defined(OS_POSIX)
1159 if (breakpad::IsCrashReporterEnabled()) {
1160 scoped_ptr<metrics::ClientInfo> client_info =
1161 GoogleUpdateSettings::LoadMetricsClientInfo();
1162 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1163 client_info ? client_info->client_id
1164 : std::string());
1166 #endif
1168 if (logging::DialogsAreSuppressed())
1169 command_line->AppendSwitch(switches::kNoErrorDialogs);
1171 std::string process_type =
1172 command_line->GetSwitchValueASCII(switches::kProcessType);
1173 const base::CommandLine& browser_command_line =
1174 *base::CommandLine::ForCurrentProcess();
1176 static const char* const kCommonSwitchNames[] = {
1177 switches::kUserAgent,
1178 switches::kUserDataDir, // Make logs go to the right file.
1180 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
1181 arraysize(kCommonSwitchNames));
1183 #if defined(ENABLE_IPC_FUZZER)
1184 static const char* const kIpcFuzzerSwitches[] = {
1185 switches::kIpcDumpDirectory,
1186 switches::kIpcFuzzerTestcase,
1188 command_line->CopySwitchesFrom(browser_command_line, kIpcFuzzerSwitches,
1189 arraysize(kIpcFuzzerSwitches));
1190 #endif
1192 #if defined(OS_CHROMEOS)
1193 static const char* const kChromeOSSwitches[] = {
1194 switches::kDisableDinosaurEasterEgg,
1196 command_line->CopySwitchesFrom(browser_command_line, kChromeOSSwitches,
1197 arraysize(kChromeOSSwitches));
1199 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
1200 base::FilePath homedir;
1201 PathService::Get(base::DIR_HOME, &homedir);
1202 command_line->AppendSwitchASCII(chromeos::switches::kHomedir,
1203 homedir.value().c_str());
1204 #endif
1206 if (process_type == switches::kRendererProcess) {
1207 content::RenderProcessHost* process =
1208 content::RenderProcessHost::FromID(child_process_id);
1209 Profile* profile =
1210 process ? Profile::FromBrowserContext(process->GetBrowserContext())
1211 : NULL;
1212 for (size_t i = 0; i < extra_parts_.size(); ++i) {
1213 extra_parts_[i]->AppendExtraRendererCommandLineSwitches(
1214 command_line, process, profile);
1217 #if defined(OS_CHROMEOS)
1218 const std::string& login_profile =
1219 browser_command_line.GetSwitchValueASCII(
1220 chromeos::switches::kLoginProfile);
1221 if (!login_profile.empty())
1222 command_line->AppendSwitchASCII(
1223 chromeos::switches::kLoginProfile, login_profile);
1224 #endif
1226 #if defined(ENABLE_WEBRTC)
1227 MaybeCopyDisableWebRtcEncryptionSwitch(command_line,
1228 browser_command_line,
1229 VersionInfo::GetChannel());
1230 #endif
1232 if (process) {
1233 PrefService* prefs = profile->GetPrefs();
1234 // Currently this pref is only registered if applied via a policy.
1235 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1236 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1237 // Turn this policy into a command line switch.
1238 command_line->AppendSwitch(switches::kDisable3DAPIs);
1241 const base::ListValue* switches =
1242 prefs->GetList(prefs::kEnableDeprecatedWebPlatformFeatures);
1243 if (switches) {
1244 // Enable any deprecated features that have been re-enabled by policy.
1245 for (base::ListValue::const_iterator it = switches->begin();
1246 it != switches->end(); ++it) {
1247 std::string switch_to_enable;
1248 if ((*it)->GetAsString(&switch_to_enable))
1249 command_line->AppendSwitch(switch_to_enable);
1253 // Disable client-side phishing detection in the renderer if it is
1254 // disabled in the Profile preferences or the browser process.
1255 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1256 !g_browser_process->safe_browsing_detection_service()) {
1257 command_line->AppendSwitch(
1258 switches::kDisableClientSidePhishingDetection);
1261 if (prefs->GetBoolean(prefs::kPrintPreviewDisabled))
1262 command_line->AppendSwitch(switches::kDisablePrintPreview);
1264 InstantService* instant_service =
1265 InstantServiceFactory::GetForProfile(profile);
1266 if (instant_service &&
1267 instant_service->IsInstantProcess(process->GetID()))
1268 command_line->AppendSwitch(switches::kInstantProcess);
1271 if (IsAutoReloadEnabled())
1272 command_line->AppendSwitch(switches::kEnableOfflineAutoReload);
1273 if (IsAutoReloadVisibleOnlyEnabled()) {
1274 command_line->AppendSwitch(
1275 switches::kEnableOfflineAutoReloadVisibleOnly);
1279 // Enable showing a saved copy if this session is in the field trial
1280 // or the user explicitly enabled it. Note that as far as the
1281 // renderer is concerned, the feature is enabled if-and-only-if
1282 // one of the kEnableShowSavedCopy* switches is on the command
1283 // line; the yes/no/default behavior is only at the browser
1284 // command line level.
1286 // Command line switches override
1287 const std::string& show_saved_copy_value =
1288 browser_command_line.GetSwitchValueASCII(switches::kShowSavedCopy);
1289 if (show_saved_copy_value == switches::kEnableShowSavedCopyPrimary ||
1290 show_saved_copy_value == switches::kEnableShowSavedCopySecondary ||
1291 show_saved_copy_value == switches::kDisableShowSavedCopy) {
1292 command_line->AppendSwitchASCII(switches::kShowSavedCopy,
1293 show_saved_copy_value);
1294 } else {
1295 std::string group =
1296 base::FieldTrialList::FindFullName("LoadStaleCacheExperiment");
1298 if (group == "Primary") {
1299 command_line->AppendSwitchASCII(
1300 switches::kShowSavedCopy, switches::kEnableShowSavedCopyPrimary);
1301 } else if (group == "Secondary") {
1302 command_line->AppendSwitchASCII(
1303 switches::kShowSavedCopy,
1304 switches::kEnableShowSavedCopySecondary);
1309 // Please keep this in alphabetical order.
1310 static const char* const kSwitchNames[] = {
1311 autofill::switches::kDisableFillOnAccountSelect,
1312 autofill::switches::kDisablePasswordGeneration,
1313 autofill::switches::kEnableFillOnAccountSelect,
1314 autofill::switches::kEnableFillOnAccountSelectNoHighlighting,
1315 autofill::switches::kEnablePasswordGeneration,
1316 autofill::switches::kEnablePasswordSaveOnInPageNavigation,
1317 autofill::switches::kEnableSingleClickAutofill,
1318 autofill::switches::kIgnoreAutocompleteOffForAutofill,
1319 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration,
1320 #if defined(ENABLE_EXTENSIONS)
1321 extensions::switches::kAllowHTTPBackgroundPage,
1322 extensions::switches::kAllowLegacyExtensionManifests,
1323 extensions::switches::kEnableSurfaceWorker,
1324 extensions::switches::kEnableAppWindowControls,
1325 extensions::switches::kEnableEmbeddedExtensionOptions,
1326 extensions::switches::kEnableExperimentalExtensionApis,
1327 extensions::switches::kExtensionsOnChromeURLs,
1328 extensions::switches::kWhitelistedExtensionID,
1329 #endif
1330 switches::kAllowInsecureLocalhost,
1331 switches::kAppsCheckoutURL,
1332 switches::kAppsGalleryURL,
1333 switches::kCloudPrintURL,
1334 switches::kCloudPrintXmppEndpoint,
1335 switches::kDisableBundledPpapiFlash,
1336 switches::kDisableCastStreamingHWEncoding,
1337 switches::kDisableJavaScriptHarmonyShipping,
1338 switches::kDisableNewBookmarkApps,
1339 switches::kDisableOutOfProcessPdf,
1340 switches::kEnableBenchmarking,
1341 switches::kEnableNaCl,
1342 #if !defined(DISABLE_NACL)
1343 switches::kEnableNaClDebug,
1344 switches::kEnableNaClNonSfiMode,
1345 switches::kEnablePNaClSubzero,
1346 #endif
1347 switches::kEnableNetBenchmarking,
1348 switches::kEnableNewBookmarkApps,
1349 switches::kEnableOutOfProcessPdf,
1350 switches::kEnablePluginPlaceholderShadowDom,
1351 switches::kJavaScriptHarmony,
1352 switches::kMessageLoopHistogrammer,
1353 switches::kPpapiFlashArgs,
1354 switches::kPpapiFlashPath,
1355 switches::kPpapiFlashVersion,
1356 switches::kProfilingAtStart,
1357 switches::kProfilingFile,
1358 switches::kProfilingFlush,
1359 translate::switches::kTranslateSecurityOrigin,
1362 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1363 arraysize(kSwitchNames));
1364 } else if (process_type == switches::kUtilityProcess) {
1365 #if defined(ENABLE_EXTENSIONS)
1366 static const char* const kSwitchNames[] = {
1367 extensions::switches::kAllowHTTPBackgroundPage,
1368 extensions::switches::kEnableExperimentalExtensionApis,
1369 extensions::switches::kExtensionsOnChromeURLs,
1370 extensions::switches::kWhitelistedExtensionID,
1373 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1374 arraysize(kSwitchNames));
1375 #endif
1376 } else if (process_type == switches::kPluginProcess) {
1377 #if defined(OS_CHROMEOS)
1378 static const char* const kSwitchNames[] = {
1379 chromeos::switches::kLoginProfile,
1382 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1383 arraysize(kSwitchNames));
1384 #endif
1385 } else if (process_type == switches::kZygoteProcess) {
1386 static const char* const kSwitchNames[] = {
1387 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
1388 switches::kDisableBundledPpapiFlash,
1389 #if !defined(DISABLE_NACL)
1390 switches::kEnableNaClDebug,
1391 switches::kEnableNaClNonSfiMode,
1392 switches::kEnablePNaClSubzero,
1393 switches::kNaClDangerousNoSandboxNonSfi,
1394 switches::kUseNaClHelperNonSfi,
1395 #endif
1396 switches::kPpapiFlashPath,
1397 switches::kPpapiFlashVersion,
1400 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1401 arraysize(kSwitchNames));
1402 } else if (process_type == switches::kGpuProcess) {
1403 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1404 // because GPU is expected to be unreliable.
1405 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1406 !command_line->HasSwitch(switches::kDisableBreakpad))
1407 command_line->AppendSwitch(switches::kDisableBreakpad);
1410 // The command line switch kEnableBenchmarking needs to be specified along
1411 // with the kEnableStatsTable switch to ensure that the stats table global
1412 // is initialized correctly.
1413 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1414 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
1417 std::string ChromeContentBrowserClient::GetApplicationLocale() {
1418 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
1419 return g_io_thread_application_locale.Get();
1420 return g_browser_process->GetApplicationLocale();
1423 std::string ChromeContentBrowserClient::GetAcceptLangs(
1424 content::BrowserContext* context) {
1425 Profile* profile = Profile::FromBrowserContext(context);
1426 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
1429 const gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
1430 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1431 return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).ToImageSkia();
1434 bool ChromeContentBrowserClient::AllowAppCache(
1435 const GURL& manifest_url,
1436 const GURL& first_party,
1437 content::ResourceContext* context) {
1438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1439 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1440 return io_data->GetCookieSettings()->
1441 IsSettingCookieAllowed(manifest_url, first_party);
1444 bool ChromeContentBrowserClient::AllowServiceWorker(
1445 const GURL& scope,
1446 const GURL& first_party_url,
1447 content::ResourceContext* context) {
1448 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1449 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1450 return io_data->GetCookieSettings()->
1451 IsSettingCookieAllowed(scope, first_party_url);
1454 bool ChromeContentBrowserClient::AllowGetCookie(
1455 const GURL& url,
1456 const GURL& first_party,
1457 const net::CookieList& cookie_list,
1458 content::ResourceContext* context,
1459 int render_process_id,
1460 int render_frame_id) {
1461 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1462 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1463 bool allow = io_data->GetCookieSettings()->
1464 IsReadingCookieAllowed(url, first_party);
1466 BrowserThread::PostTask(
1467 BrowserThread::UI, FROM_HERE,
1468 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
1469 render_frame_id, url, first_party, cookie_list, !allow));
1470 return allow;
1473 bool ChromeContentBrowserClient::AllowSetCookie(
1474 const GURL& url,
1475 const GURL& first_party,
1476 const std::string& cookie_line,
1477 content::ResourceContext* context,
1478 int render_process_id,
1479 int render_frame_id,
1480 net::CookieOptions* options) {
1481 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1482 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1483 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1484 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1486 BrowserThread::PostTask(
1487 BrowserThread::UI, FROM_HERE,
1488 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
1489 render_frame_id, url, first_party, cookie_line, *options,
1490 !allow));
1491 return allow;
1494 bool ChromeContentBrowserClient::AllowSaveLocalState(
1495 content::ResourceContext* context) {
1496 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1497 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1498 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1499 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
1501 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1502 // Could we even support per-origin settings?
1503 return setting != CONTENT_SETTING_SESSION_ONLY;
1506 bool ChromeContentBrowserClient::AllowWorkerDatabase(
1507 const GURL& url,
1508 const base::string16& name,
1509 const base::string16& display_name,
1510 unsigned long estimated_size,
1511 content::ResourceContext* context,
1512 const std::vector<std::pair<int, int> >& render_frames) {
1513 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1514 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1515 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1516 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1518 // Record access to database for potential display in UI.
1519 std::vector<std::pair<int, int> >::const_iterator i;
1520 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
1521 BrowserThread::PostTask(
1522 BrowserThread::UI, FROM_HERE,
1523 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1524 i->first, i->second, url, name, display_name, !allow));
1527 return allow;
1530 void ChromeContentBrowserClient::AllowWorkerFileSystem(
1531 const GURL& url,
1532 content::ResourceContext* context,
1533 const std::vector<std::pair<int, int> >& render_frames,
1534 base::Callback<void(bool)> callback) {
1535 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1536 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1537 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1538 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1540 #if defined(ENABLE_EXTENSIONS)
1541 GuestPermissionRequestHelper(url, render_frames, callback, allow);
1542 #else
1543 FileSystemAccessed(url, render_frames, callback, allow);
1544 #endif
1547 #if defined(ENABLE_EXTENSIONS)
1548 void ChromeContentBrowserClient::GuestPermissionRequestHelper(
1549 const GURL& url,
1550 const std::vector<std::pair<int, int> >& render_frames,
1551 base::Callback<void(bool)> callback,
1552 bool allow) {
1553 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::IO));
1554 std::vector<std::pair<int, int> >::const_iterator i;
1555 std::map<int, int> process_map;
1556 std::map<int, int>::const_iterator it;
1557 bool has_web_view_guest = false;
1558 // Record access to file system for potential display in UI.
1559 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
1560 if (process_map.find(i->first) != process_map.end())
1561 continue;
1563 process_map.insert(std::pair<int, int>(i->first, i->second));
1565 if (extensions::WebViewRendererState::GetInstance()->IsGuest(i->first))
1566 has_web_view_guest = true;
1568 if (!has_web_view_guest) {
1569 FileSystemAccessed(url, render_frames, callback, allow);
1570 return;
1572 DCHECK_EQ(1U, process_map.size());
1573 it = process_map.begin();
1574 BrowserThread::PostTask(
1575 BrowserThread::UI,
1576 FROM_HERE,
1577 base::Bind(&ChromeContentBrowserClient::
1578 RequestFileSystemPermissionOnUIThread,
1579 it->first,
1580 it->second,
1581 url,
1582 allow,
1583 base::Bind(&ChromeContentBrowserClient::FileSystemAccessed,
1584 weak_factory_.GetWeakPtr(),
1585 url,
1586 render_frames,
1587 callback)));
1590 void ChromeContentBrowserClient::RequestFileSystemPermissionOnUIThread(
1591 int render_process_id,
1592 int render_frame_id,
1593 const GURL& url,
1594 bool allowed_by_default,
1595 const base::Callback<void(bool)>& callback) {
1596 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::UI));
1597 extensions::WebViewPermissionHelper* web_view_permission_helper =
1598 extensions::WebViewPermissionHelper::FromFrameID(
1599 render_process_id, render_frame_id);
1600 web_view_permission_helper->RequestFileSystemPermission(url,
1601 allowed_by_default,
1602 callback);
1604 #endif
1606 void ChromeContentBrowserClient::FileSystemAccessed(
1607 const GURL& url,
1608 const std::vector<std::pair<int, int> >& render_frames,
1609 base::Callback<void(bool)> callback,
1610 bool allow) {
1611 // Record access to file system for potential display in UI.
1612 std::vector<std::pair<int, int> >::const_iterator i;
1613 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
1614 BrowserThread::PostTask(
1615 BrowserThread::UI,
1616 FROM_HERE,
1617 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1618 i->first, i->second, url, !allow));
1620 callback.Run(allow);
1623 bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1624 const GURL& url,
1625 const base::string16& name,
1626 content::ResourceContext* context,
1627 const std::vector<std::pair<int, int> >& render_frames) {
1628 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1629 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1630 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1631 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1633 // Record access to IndexedDB for potential display in UI.
1634 std::vector<std::pair<int, int> >::const_iterator i;
1635 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
1636 BrowserThread::PostTask(
1637 BrowserThread::UI, FROM_HERE,
1638 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1639 i->first, i->second, url, name, !allow));
1642 return allow;
1645 net::URLRequestContext*
1646 ChromeContentBrowserClient::OverrideRequestContextForURL(
1647 const GURL& url, content::ResourceContext* context) {
1648 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1649 #if defined(ENABLE_EXTENSIONS)
1650 if (url.SchemeIs(extensions::kExtensionScheme)) {
1651 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1652 return io_data->extensions_request_context();
1654 #endif
1656 return NULL;
1659 QuotaPermissionContext*
1660 ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1661 return new ChromeQuotaPermissionContext();
1664 void ChromeContentBrowserClient::AllowCertificateError(
1665 int render_process_id,
1666 int render_frame_id,
1667 int cert_error,
1668 const net::SSLInfo& ssl_info,
1669 const GURL& request_url,
1670 ResourceType resource_type,
1671 bool overridable,
1672 bool strict_enforcement,
1673 bool expired_previous_decision,
1674 const base::Callback<void(bool)>& callback,
1675 content::CertificateRequestResultType* result) {
1676 if (resource_type != content::RESOURCE_TYPE_MAIN_FRAME) {
1677 // A sub-resource has a certificate error. The user doesn't really
1678 // have a context for making the right decision, so block the
1679 // request hard, without an info bar to allow showing the insecure
1680 // content.
1681 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
1682 return;
1685 // If the tab is being prerendered, cancel the prerender and the request.
1686 content::RenderFrameHost* render_frame_host =
1687 content::RenderFrameHost::FromID(render_process_id, render_frame_id);
1688 WebContents* tab = WebContents::FromRenderFrameHost(render_frame_host);
1689 if (!tab) {
1690 NOTREACHED();
1691 return;
1694 prerender::PrerenderContents* prerender_contents =
1695 prerender::PrerenderContents::FromWebContents(tab);
1696 if (prerender_contents) {
1697 prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR);
1698 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
1699 return;
1702 // Otherwise, display an SSL blocking page. The interstitial page takes
1703 // ownership of ssl_blocking_page.
1704 int options_mask = 0;
1705 if (overridable)
1706 options_mask |= SSLBlockingPage::OVERRIDABLE;
1707 if (strict_enforcement)
1708 options_mask |= SSLBlockingPage::STRICT_ENFORCEMENT;
1709 if (expired_previous_decision)
1710 options_mask |= SSLBlockingPage::EXPIRED_BUT_PREVIOUSLY_ALLOWED;
1712 SafeBrowsingService* safe_browsing_service =
1713 g_browser_process->safe_browsing_service();
1714 SSLErrorHandler::HandleSSLError(
1715 tab, cert_error, ssl_info, request_url, options_mask,
1716 safe_browsing_service ? safe_browsing_service->ui_manager().get()
1717 : nullptr,
1718 callback);
1721 void ChromeContentBrowserClient::SelectClientCertificate(
1722 content::WebContents* web_contents,
1723 net::SSLCertRequestInfo* cert_request_info,
1724 scoped_ptr<content::ClientCertificateDelegate> delegate) {
1725 prerender::PrerenderContents* prerender_contents =
1726 prerender::PrerenderContents::FromWebContents(web_contents);
1727 if (prerender_contents) {
1728 prerender_contents->Destroy(
1729 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED);
1730 return;
1733 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
1734 DCHECK(requesting_url.is_valid())
1735 << "Invalid URL string: https://"
1736 << cert_request_info->host_and_port.ToString();
1738 Profile* profile =
1739 Profile::FromBrowserContext(web_contents->GetBrowserContext());
1740 scoped_ptr<base::Value> filter =
1741 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1742 requesting_url,
1743 requesting_url,
1744 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1745 std::string(),
1746 NULL);
1748 if (filter.get()) {
1749 // Try to automatically select a client certificate.
1750 if (filter->IsType(base::Value::TYPE_DICTIONARY)) {
1751 base::DictionaryValue* filter_dict =
1752 static_cast<base::DictionaryValue*>(filter.get());
1754 const std::vector<scoped_refptr<net::X509Certificate> >&
1755 all_client_certs = cert_request_info->client_certs;
1756 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1757 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
1758 // Use the first certificate that is matched by the filter.
1759 delegate->ContinueWithCertificate(all_client_certs[i].get());
1760 return;
1763 } else {
1764 NOTREACHED();
1768 chrome::ShowSSLClientCertificateSelector(web_contents, cert_request_info,
1769 delegate.Pass());
1772 void ChromeContentBrowserClient::AddCertificate(
1773 net::CertificateMimeType cert_type,
1774 const void* cert_data,
1775 size_t cert_size,
1776 int render_process_id,
1777 int render_frame_id) {
1778 chrome::SSLAddCertificate(cert_type, cert_data, cert_size,
1779 render_process_id, render_frame_id);
1782 content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
1783 return MediaCaptureDevicesDispatcher::GetInstance();
1786 content::PlatformNotificationService*
1787 ChromeContentBrowserClient::GetPlatformNotificationService() {
1788 #if defined(ENABLE_NOTIFICATIONS)
1789 return PlatformNotificationServiceImpl::GetInstance();
1790 #else
1791 NOTIMPLEMENTED();
1792 return NULL;
1793 #endif
1796 bool ChromeContentBrowserClient::CanCreateWindow(
1797 const GURL& opener_url,
1798 const GURL& opener_top_level_frame_url,
1799 const GURL& source_origin,
1800 WindowContainerType container_type,
1801 const GURL& target_url,
1802 const content::Referrer& referrer,
1803 WindowOpenDisposition disposition,
1804 const WebWindowFeatures& features,
1805 bool user_gesture,
1806 bool opener_suppressed,
1807 content::ResourceContext* context,
1808 int render_process_id,
1809 int opener_id,
1810 bool* no_javascript_access) {
1811 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1813 *no_javascript_access = false;
1815 // If the opener is trying to create a background window but doesn't have
1816 // the appropriate permission, fail the attempt.
1817 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
1818 #if defined(ENABLE_EXTENSIONS)
1819 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1820 InfoMap* map = io_data->GetExtensionInfoMap();
1821 if (!map->SecurityOriginHasAPIPermission(
1822 source_origin,
1823 render_process_id,
1824 APIPermission::kBackground)) {
1825 return false;
1828 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1829 // return a recently installed Extension even if this CanCreateWindow call
1830 // was made by an old copy of the page in a normal web process. That's ok,
1831 // because the permission check above would have caused an early return
1832 // already. We must use the full URL to find hosted apps, though, and not
1833 // just the origin.
1834 const Extension* extension =
1835 map->extensions().GetExtensionOrAppByURL(opener_url);
1836 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
1837 *no_javascript_access = true;
1838 #endif
1840 return true;
1843 #if defined(ENABLE_EXTENSIONS)
1844 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
1845 render_process_id))
1846 return true;
1847 #endif
1849 HostContentSettingsMap* content_settings =
1850 ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap();
1851 BlockedWindowParams blocked_params(target_url,
1852 referrer,
1853 disposition,
1854 features,
1855 user_gesture,
1856 opener_suppressed,
1857 render_process_id,
1858 opener_id);
1860 if (!user_gesture &&
1861 !base::CommandLine::ForCurrentProcess()->HasSwitch(
1862 switches::kDisablePopupBlocking)) {
1863 if (content_settings->GetContentSetting(opener_top_level_frame_url,
1864 opener_top_level_frame_url,
1865 CONTENT_SETTINGS_TYPE_POPUPS,
1866 std::string()) !=
1867 CONTENT_SETTING_ALLOW) {
1868 BrowserThread::PostTask(BrowserThread::UI,
1869 FROM_HERE,
1870 base::Bind(&HandleBlockedPopupOnUIThread,
1871 blocked_params));
1872 return false;
1876 #if defined(OS_ANDROID)
1877 if (SingleTabModeTabHelper::IsRegistered(render_process_id, opener_id)) {
1878 BrowserThread::PostTask(BrowserThread::UI,
1879 FROM_HERE,
1880 base::Bind(&HandleSingleTabModeBlockOnUIThread,
1881 blocked_params));
1882 return false;
1884 #endif
1886 return true;
1889 void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1890 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1891 return g_browser_process->ResourceDispatcherHostCreated();
1894 content::SpeechRecognitionManagerDelegate*
1895 ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
1896 return new speech::ChromeSpeechRecognitionManagerDelegate();
1899 net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1900 return g_browser_process->net_log();
1903 AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1904 return new ChromeAccessTokenStore();
1907 bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1908 return true;
1911 void ChromeContentBrowserClient::OverrideWebkitPrefs(
1912 RenderViewHost* rvh, WebPreferences* web_prefs) {
1913 Profile* profile = Profile::FromBrowserContext(
1914 rvh->GetProcess()->GetBrowserContext());
1915 PrefService* prefs = profile->GetPrefs();
1917 // Fill per-script font preferences. These are not registered on Android
1918 // - http://crbug.com/308033.
1919 #if !defined(OS_ANDROID)
1920 FontFamilyCache::FillFontFamilyMap(profile,
1921 prefs::kWebKitStandardFontFamilyMap,
1922 &web_prefs->standard_font_family_map);
1923 FontFamilyCache::FillFontFamilyMap(profile,
1924 prefs::kWebKitFixedFontFamilyMap,
1925 &web_prefs->fixed_font_family_map);
1926 FontFamilyCache::FillFontFamilyMap(profile,
1927 prefs::kWebKitSerifFontFamilyMap,
1928 &web_prefs->serif_font_family_map);
1929 FontFamilyCache::FillFontFamilyMap(profile,
1930 prefs::kWebKitSansSerifFontFamilyMap,
1931 &web_prefs->sans_serif_font_family_map);
1932 FontFamilyCache::FillFontFamilyMap(profile,
1933 prefs::kWebKitCursiveFontFamilyMap,
1934 &web_prefs->cursive_font_family_map);
1935 FontFamilyCache::FillFontFamilyMap(profile,
1936 prefs::kWebKitFantasyFontFamilyMap,
1937 &web_prefs->fantasy_font_family_map);
1938 FontFamilyCache::FillFontFamilyMap(profile,
1939 prefs::kWebKitPictographFontFamilyMap,
1940 &web_prefs->pictograph_font_family_map);
1941 #endif
1943 web_prefs->default_font_size =
1944 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
1945 web_prefs->default_fixed_font_size =
1946 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
1947 web_prefs->minimum_font_size =
1948 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
1949 web_prefs->minimum_logical_font_size =
1950 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
1952 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
1954 web_prefs->javascript_can_open_windows_automatically =
1955 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
1956 web_prefs->dom_paste_enabled =
1957 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
1958 web_prefs->shrinks_standalone_images_to_fit =
1959 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1960 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
1962 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
1963 web_prefs->javascript_enabled = false;
1964 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1965 web_prefs->web_security_enabled = false;
1966 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
1967 web_prefs->plugins_enabled = false;
1968 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1969 web_prefs->java_enabled = false;
1970 web_prefs->loads_images_automatically =
1971 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
1973 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1974 web_prefs->experimental_webgl_enabled = false;
1976 web_prefs->allow_displaying_insecure_content =
1977 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1978 web_prefs->allow_running_insecure_content =
1979 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
1980 #if defined(OS_ANDROID)
1981 web_prefs->font_scale_factor =
1982 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1983 web_prefs->device_scale_adjustment = GetDeviceScaleAdjustment();
1984 web_prefs->force_enable_zoom =
1985 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
1986 #endif
1988 #if defined(OS_ANDROID)
1989 web_prefs->password_echo_enabled =
1990 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
1991 #else
1992 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
1993 #endif
1995 web_prefs->asynchronous_spell_checking_enabled = true;
1996 web_prefs->unified_textchecker_enabled = true;
1998 web_prefs->uses_universal_detector =
1999 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
2000 web_prefs->text_areas_are_resizable =
2001 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
2002 web_prefs->hyperlink_auditing_enabled =
2003 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2005 #if defined(ENABLE_EXTENSIONS)
2006 std::string image_animation_policy =
2007 prefs->GetString(prefs::kAnimationPolicy);
2008 if (image_animation_policy == kAnimationPolicyOnce)
2009 web_prefs->animation_policy =
2010 content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE;
2011 else if (image_animation_policy == kAnimationPolicyNone)
2012 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_NO_ANIMATION;
2013 else
2014 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_ALLOWED;
2015 #endif
2017 // Make sure we will set the default_encoding with canonical encoding name.
2018 web_prefs->default_encoding =
2019 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
2020 web_prefs->default_encoding);
2021 if (web_prefs->default_encoding.empty()) {
2022 prefs->ClearPref(prefs::kDefaultCharset);
2023 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
2025 DCHECK(!web_prefs->default_encoding.empty());
2027 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2028 switches::kEnablePotentiallyAnnoyingSecurityFeatures)) {
2029 web_prefs->disable_reading_from_canvas = true;
2030 web_prefs->strict_mixed_content_checking = true;
2031 web_prefs->strict_powerful_feature_restrictions = true;
2034 for (size_t i = 0; i < extra_parts_.size(); ++i)
2035 extra_parts_[i]->OverrideWebkitPrefs(rvh, web_prefs);
2038 void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2039 BrowserURLHandler* handler) {
2040 for (size_t i = 0; i < extra_parts_.size(); ++i)
2041 extra_parts_[i]->BrowserURLHandlerCreated(handler);
2043 // about: handler. Must come before chrome: handler, since it will
2044 // rewrite about: urls to chrome: URLs and then expect chrome: to
2045 // actually handle them. Also relies on a preliminary fixup phase.
2046 handler->SetFixupHandler(&FixupBrowserAboutURL);
2047 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2048 BrowserURLHandler::null_handler());
2050 #if defined(OS_ANDROID)
2051 // Handler to rewrite chrome://newtab on Android.
2052 handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL,
2053 BrowserURLHandler::null_handler());
2054 #else
2055 // Handler to rewrite chrome://newtab for InstantExtended.
2056 handler->AddHandlerPair(&chrome::HandleNewTabURLRewrite,
2057 &chrome::HandleNewTabURLReverseRewrite);
2058 #endif
2060 // chrome: & friends.
2061 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
2064 void ChromeContentBrowserClient::ClearCache(RenderFrameHost* rfh) {
2065 Profile* profile = Profile::FromBrowserContext(
2066 rfh->GetSiteInstance()->GetProcess()->GetBrowserContext());
2067 BrowsingDataRemover* remover =
2068 BrowsingDataRemover::CreateForUnboundedRange(profile);
2069 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2070 BrowsingDataHelper::UNPROTECTED_WEB);
2071 // BrowsingDataRemover takes care of deleting itself when done.
2074 void ChromeContentBrowserClient::ClearCookies(RenderFrameHost* rfh) {
2075 Profile* profile = Profile::FromBrowserContext(
2076 rfh->GetSiteInstance()->GetProcess()->GetBrowserContext());
2077 BrowsingDataRemover* remover =
2078 BrowsingDataRemover::CreateForUnboundedRange(profile);
2079 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
2080 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
2081 // BrowsingDataRemover takes care of deleting itself when done.
2084 base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
2085 return DownloadPrefs::GetDefaultDownloadDirectory();
2088 std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2089 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2092 void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2093 content::BrowserPpapiHost* browser_host) {
2094 #if defined(ENABLE_PLUGINS)
2095 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host);
2096 #endif
2099 content::BrowserPpapiHost*
2100 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2101 int plugin_process_id) {
2102 #if !defined(DISABLE_NACL)
2103 content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
2104 while (!iter.Done()) {
2105 nacl::NaClProcessHost* host = static_cast<nacl::NaClProcessHost*>(
2106 iter.GetDelegate());
2107 if (host->process() &&
2108 host->process()->GetData().id == plugin_process_id) {
2109 // Found the plugin.
2110 return host->browser_ppapi_host();
2112 ++iter;
2114 #endif
2115 return NULL;
2118 bool ChromeContentBrowserClient::AllowPepperSocketAPI(
2119 content::BrowserContext* browser_context,
2120 const GURL& url,
2121 bool private_api,
2122 const content::SocketPermissionRequest* params) {
2123 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2124 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
2125 browser_context, url, private_api, params, allowed_socket_origins_);
2126 #else
2127 return false;
2128 #endif
2131 ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2132 WebContents* web_contents) {
2133 return new ChromeSelectFilePolicy(web_contents);
2136 void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2137 std::vector<std::string>* additional_allowed_schemes) {
2138 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2139 additional_allowed_schemes);
2140 additional_allowed_schemes->push_back(content::kChromeDevToolsScheme);
2141 additional_allowed_schemes->push_back(content::kChromeUIScheme);
2142 for (size_t i = 0; i < extra_parts_.size(); ++i) {
2143 extra_parts_[i]->GetAdditionalAllowedSchemesForFileSystem(
2144 additional_allowed_schemes);
2148 void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
2149 std::vector<storage::URLRequestAutoMountHandler>* handlers) {
2150 for (size_t i = 0; i < extra_parts_.size(); ++i)
2151 extra_parts_[i]->GetURLRequestAutoMountHandlers(handlers);
2154 void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
2155 content::BrowserContext* browser_context,
2156 const base::FilePath& storage_partition_path,
2157 ScopedVector<storage::FileSystemBackend>* additional_backends) {
2158 #if defined(OS_CHROMEOS)
2159 storage::ExternalMountPoints* external_mount_points =
2160 content::BrowserContext::GetMountPoints(browser_context);
2161 DCHECK(external_mount_points);
2162 chromeos::FileSystemBackend* backend = new chromeos::FileSystemBackend(
2163 new drive::FileSystemBackendDelegate,
2164 new chromeos::file_system_provider::BackendDelegate,
2165 new chromeos::MTPFileSystemBackendDelegate(storage_partition_path),
2166 external_mount_points,
2167 storage::ExternalMountPoints::GetSystemInstance());
2168 backend->AddSystemMountPoints();
2169 DCHECK(backend->CanHandleType(storage::kFileSystemTypeExternal));
2170 additional_backends->push_back(backend);
2171 #endif
2173 for (size_t i = 0; i < extra_parts_.size(); ++i) {
2174 extra_parts_[i]->GetAdditionalFileSystemBackends(
2175 browser_context, storage_partition_path, additional_backends);
2179 #if defined(OS_POSIX) && !defined(OS_MACOSX)
2180 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2181 const base::CommandLine& command_line,
2182 int child_process_id,
2183 FileDescriptorInfo* mappings) {
2184 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
2185 if (v8_natives_fd_.get() == -1 || v8_snapshot_fd_.get() == -1) {
2186 int v8_natives_fd = -1;
2187 int v8_snapshot_fd = -1;
2188 if (gin::V8Initializer::OpenV8FilesForChildProcesses(&v8_natives_fd,
2189 &v8_snapshot_fd)) {
2190 v8_natives_fd_.reset(v8_natives_fd);
2191 v8_snapshot_fd_.reset(v8_snapshot_fd);
2194 DCHECK(v8_natives_fd_.get() != -1 && v8_snapshot_fd_.get() != -1);
2195 mappings->Share(kV8NativesDataDescriptor, v8_natives_fd_.get());
2196 mappings->Share(kV8SnapshotDataDescriptor, v8_snapshot_fd_.get());
2197 #endif // V8_USE_EXTERNAL_STARTUP_DATA
2199 #if defined(OS_ANDROID)
2200 base::FilePath data_path;
2201 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2202 DCHECK(!data_path.empty());
2204 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ;
2205 base::FilePath chrome_resources_pak =
2206 data_path.AppendASCII("chrome_100_percent.pak");
2207 base::File file(chrome_resources_pak, flags);
2208 DCHECK(file.IsValid());
2209 mappings->Transfer(kAndroidChrome100PercentPakDescriptor,
2210 base::ScopedFD(file.TakePlatformFile()));
2212 const std::string locale = GetApplicationLocale();
2213 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
2214 GetLocaleFilePath(locale, false);
2215 file.Initialize(locale_pak, flags);
2216 DCHECK(file.IsValid());
2217 mappings->Transfer(kAndroidLocalePakDescriptor,
2218 base::ScopedFD(file.TakePlatformFile()));
2220 base::FilePath resources_pack_path;
2221 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2222 file.Initialize(resources_pack_path, flags);
2223 DCHECK(file.IsValid());
2224 mappings->Transfer(kAndroidUIResourcesPakDescriptor,
2225 base::ScopedFD(file.TakePlatformFile()));
2227 if (breakpad::IsCrashReporterEnabled()) {
2228 file = breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile(
2229 child_process_id);
2230 if (file.IsValid()) {
2231 mappings->Transfer(kAndroidMinidumpDescriptor,
2232 base::ScopedFD(file.TakePlatformFile()));
2233 } else {
2234 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2235 "be disabled for this process.";
2239 base::FilePath app_data_path;
2240 PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path);
2241 DCHECK(!app_data_path.empty());
2243 flags = base::File::FLAG_OPEN | base::File::FLAG_READ;
2244 base::FilePath icudata_path =
2245 app_data_path.AppendASCII(base::i18n::kIcuDataFileName);
2246 base::File icudata_file(icudata_path, flags);
2247 DCHECK(icudata_file.IsValid());
2248 mappings->Transfer(kAndroidICUDataDescriptor,
2249 base::ScopedFD(icudata_file.TakePlatformFile()));
2250 #else
2251 int crash_signal_fd = GetCrashSignalFD(command_line);
2252 if (crash_signal_fd >= 0) {
2253 mappings->Share(kCrashDumpSignal, crash_signal_fd);
2255 #endif // defined(OS_ANDROID)
2257 #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
2259 #if defined(OS_WIN)
2260 const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2261 return chrome::kBrowserResourcesDll;
2264 void ChromeContentBrowserClient::PreSpawnRenderer(
2265 sandbox::TargetPolicy* policy,
2266 bool* success) {
2267 // This code is duplicated in nacl_exe_win_64.cc.
2268 // Allow the server side of a pipe restricted to the "chrome.nacl."
2269 // namespace so that it cannot impersonate other system or other chrome
2270 // service pipes.
2271 sandbox::ResultCode result = policy->AddRule(
2272 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2273 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2274 L"\\\\.\\pipe\\chrome.nacl.*");
2275 if (result != sandbox::SBOX_ALL_OK) {
2276 *success = false;
2277 return;
2280 // Renderers need to send named pipe handles and shared memory
2281 // segment handles to NaCl loader processes.
2282 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2283 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2284 L"File");
2285 if (result != sandbox::SBOX_ALL_OK) {
2286 *success = false;
2287 return;
2290 #endif
2292 bool ChromeContentBrowserClient::CheckMediaAccessPermission(
2293 content::BrowserContext* browser_context,
2294 const GURL& security_origin,
2295 content::MediaStreamType type) {
2296 return MediaCaptureDevicesDispatcher::GetInstance()
2297 ->CheckMediaAccessPermission(
2298 browser_context, security_origin, type);
2301 void ChromeContentBrowserClient::OpenURL(
2302 content::BrowserContext* browser_context,
2303 const content::OpenURLParams& params,
2304 const base::Callback<void(content::WebContents*)>& callback) {
2305 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2307 #if !defined(OS_ANDROID) && !defined(OS_IOS)
2308 NavigateParams nav_params(Profile::FromBrowserContext(browser_context),
2309 params.url,
2310 params.transition);
2311 FillNavigateParamsFromOpenURLParams(&nav_params, params);
2312 nav_params.user_gesture = params.user_gesture;
2314 Navigate(&nav_params);
2315 callback.Run(nav_params.target_contents);
2316 #elif defined(OS_ANDROID)
2317 chrome::android::ServiceTabLauncher::GetInstance()->LaunchTab(
2318 browser_context, params, callback);
2319 #else
2320 NOTIMPLEMENTED();
2321 #endif
2324 void ChromeContentBrowserClient::RecordURLMetric(const std::string& metric,
2325 const GURL& url) {
2326 if (url.is_valid()) {
2327 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(),
2328 metric, url);
2332 content::DevToolsManagerDelegate*
2333 ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
2334 #if defined(OS_ANDROID)
2335 return new DevToolsManagerDelegateAndroid();
2336 #else
2337 return new ChromeDevToolsManagerDelegate();
2338 #endif
2341 content::TracingDelegate* ChromeContentBrowserClient::GetTracingDelegate() {
2342 #if !defined(OS_ANDROID)
2343 return new ChromeTracingDelegate();
2344 #else
2345 return nullptr;
2346 #endif
2349 bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2350 content::BrowserContext* browser_context,
2351 const GURL& url) {
2352 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2353 return ChromeContentBrowserClientPluginsPart::
2354 IsPluginAllowedToCallRequestOSFileHandle(browser_context, url,
2355 allowed_file_handle_origins_);
2356 #else
2357 return false;
2358 #endif
2361 bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
2362 content::BrowserContext* browser_context,
2363 const GURL& url) {
2364 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2365 return ChromeContentBrowserClientPluginsPart::
2366 IsPluginAllowedToUseDevChannelAPIs(browser_context, url,
2367 allowed_dev_channel_origins_);
2368 #else
2369 return false;
2370 #endif
2373 void ChromeContentBrowserClient::OverridePageVisibilityState(
2374 RenderFrameHost* render_frame_host,
2375 blink::WebPageVisibilityState* visibility_state) {
2376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2378 WebContents* web_contents =
2379 WebContents::FromRenderFrameHost(render_frame_host);
2380 DCHECK(web_contents);
2382 Profile* profile =
2383 Profile::FromBrowserContext(web_contents->GetBrowserContext());
2384 prerender::PrerenderManager* prerender_manager =
2385 prerender::PrerenderManagerFactory::GetForProfile(profile);
2386 if (prerender_manager &&
2387 prerender_manager->IsWebContentsPrerendering(web_contents, nullptr)) {
2388 *visibility_state = blink::WebPageVisibilityStatePrerender;
2392 #if defined(ENABLE_WEBRTC)
2393 void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
2394 base::CommandLine* to_command_line,
2395 const base::CommandLine& from_command_line,
2396 VersionInfo::Channel channel) {
2397 #if defined(OS_ANDROID)
2398 const VersionInfo::Channel kMaxDisableEncryptionChannel =
2399 VersionInfo::CHANNEL_BETA;
2400 #else
2401 const VersionInfo::Channel kMaxDisableEncryptionChannel =
2402 VersionInfo::CHANNEL_DEV;
2403 #endif
2404 if (channel <= kMaxDisableEncryptionChannel) {
2405 static const char* const kWebRtcDevSwitchNames[] = {
2406 switches::kDisableWebRtcEncryption,
2408 to_command_line->CopySwitchesFrom(from_command_line,
2409 kWebRtcDevSwitchNames,
2410 arraysize(kWebRtcDevSwitchNames));
2413 #endif // defined(ENABLE_WEBRTC)
2415 } // namespace chrome