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"
12 #include "base/bind.h"
13 #include "base/bind_helpers.h"
14 #include "base/command_line.h"
15 #include "base/files/scoped_file.h"
16 #include "base/lazy_instance.h"
17 #include "base/path_service.h"
18 #include "base/prefs/pref_service.h"
19 #include "base/prefs/scoped_user_pref_update.h"
20 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/string_util.h"
22 #include "base/strings/stringprintf.h"
23 #include "base/strings/utf_string_conversions.h"
24 #include "base/thread_task_runner_handle.h"
25 #include "base/threading/sequenced_worker_pool.h"
26 #include "chrome/browser/after_startup_task_utils.h"
27 #include "chrome/browser/browser_about_handler.h"
28 #include "chrome/browser/browser_process.h"
29 #include "chrome/browser/browser_shutdown.h"
30 #include "chrome/browser/browsing_data/browsing_data_helper.h"
31 #include "chrome/browser/browsing_data/browsing_data_remover.h"
32 #include "chrome/browser/character_encoding.h"
33 #include "chrome/browser/chrome_content_browser_client_parts.h"
34 #include "chrome/browser/chrome_net_benchmarking_message_filter.h"
35 #include "chrome/browser/chrome_quota_permission_context.h"
36 #include "chrome/browser/content_settings/cookie_settings_factory.h"
37 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
38 #include "chrome/browser/defaults.h"
39 #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
40 #include "chrome/browser/download/download_prefs.h"
41 #include "chrome/browser/font_family_cache.h"
42 #include "chrome/browser/geolocation/chrome_access_token_store.h"
43 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
44 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
45 #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
46 #include "chrome/browser/net/chrome_net_log.h"
47 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
48 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h"
49 #include "chrome/browser/notifications/platform_notification_service_impl.h"
50 #include "chrome/browser/platform_util.h"
51 #include "chrome/browser/prerender/prerender_final_status.h"
52 #include "chrome/browser/prerender/prerender_manager.h"
53 #include "chrome/browser/prerender/prerender_manager_factory.h"
54 #include "chrome/browser/prerender/prerender_message_filter.h"
55 #include "chrome/browser/printing/printing_message_filter.h"
56 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
57 #include "chrome/browser/profiles/profile.h"
58 #include "chrome/browser/profiles/profile_io_data.h"
59 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
60 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
61 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
62 #include "chrome/browser/safe_browsing/ui_manager.h"
63 #include "chrome/browser/search/instant_service.h"
64 #include "chrome/browser/search/instant_service_factory.h"
65 #include "chrome/browser/search/search.h"
66 #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
67 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
68 #include "chrome/browser/speech/tts_controller.h"
69 #include "chrome/browser/speech/tts_message_filter.h"
70 #include "chrome/browser/ssl/ssl_add_certificate.h"
71 #include "chrome/browser/ssl/ssl_blocking_page.h"
72 #include "chrome/browser/ssl/ssl_cert_reporter.h"
73 #include "chrome/browser/ssl/ssl_client_certificate_selector.h"
74 #include "chrome/browser/ssl/ssl_error_handler.h"
75 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
76 #include "chrome/browser/tab_contents/tab_util.h"
77 #include "chrome/browser/tracing/chrome_tracing_delegate.h"
78 #include "chrome/browser/ui/blocked_content/blocked_window_params.h"
79 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
80 #include "chrome/browser/ui/chrome_select_file_policy.h"
81 #include "chrome/browser/ui/sync/sync_promo_ui.h"
82 #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
83 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
84 #include "chrome/common/channel_info.h"
85 #include "chrome/common/chrome_constants.h"
86 #include "chrome/common/chrome_paths.h"
87 #include "chrome/common/chrome_switches.h"
88 #include "chrome/common/env_vars.h"
89 #include "chrome/common/logging_chrome.h"
90 #include "chrome/common/pepper_permission_util.h"
91 #include "chrome/common/pref_names.h"
92 #include "chrome/common/render_messages.h"
93 #include "chrome/common/url_constants.h"
94 #include "chrome/grit/generated_resources.h"
95 #include "chrome/installer/util/google_update_settings.h"
96 #include "chromeos/chromeos_constants.h"
97 #include "components/cdm/browser/cdm_message_filter_android.h"
98 #include "components/cloud_devices/common/cloud_devices_switches.h"
99 #include "components/content_settings/core/browser/content_settings_utils.h"
100 #include "components/content_settings/core/browser/cookie_settings.h"
101 #include "components/content_settings/core/browser/host_content_settings_map.h"
102 #include "components/content_settings/core/common/content_settings.h"
103 #include "components/data_reduction_proxy/content/browser/data_reduction_proxy_message_filter.h"
104 #include "components/dom_distiller/core/url_constants.h"
105 #include "components/google/core/browser/google_util.h"
106 #include "components/metrics/client_info.h"
107 #include "components/pref_registry/pref_registry_syncable.h"
108 #include "components/rappor/rappor_utils.h"
109 #include "components/signin/core/common/profile_management_switches.h"
110 #include "components/translate/core/common/translate_switches.h"
111 #include "components/url_formatter/url_fixer.h"
112 #include "components/variations/variations_associated_data.h"
113 #include "components/version_info/version_info.h"
114 #include "content/public/browser/browser_child_process_host.h"
115 #include "content/public/browser/browser_main_parts.h"
116 #include "content/public/browser/browser_ppapi_host.h"
117 #include "content/public/browser/browser_thread.h"
118 #include "content/public/browser/browser_url_handler.h"
119 #include "content/public/browser/child_process_data.h"
120 #include "content/public/browser/child_process_security_policy.h"
121 #include "content/public/browser/client_certificate_delegate.h"
122 #include "content/public/browser/render_frame_host.h"
123 #include "content/public/browser/render_process_host.h"
124 #include "content/public/browser/render_view_host.h"
125 #include "content/public/browser/resource_context.h"
126 #include "content/public/browser/site_instance.h"
127 #include "content/public/browser/web_contents.h"
128 #include "content/public/common/child_process_host.h"
129 #include "content/public/common/content_descriptors.h"
130 #include "content/public/common/sandbox_type.h"
131 #include "content/public/common/service_registry.h"
132 #include "content/public/common/url_utils.h"
133 #include "content/public/common/web_preferences.h"
134 #include "device/devices_app/public/cpp/constants.h"
135 #include "device/devices_app/public/cpp/devices_app_factory.h"
136 #include "gin/v8_initializer.h"
137 #include "mojo/application/public/cpp/application_delegate.h"
138 #include "net/base/mime_util.h"
139 #include "net/cookies/canonical_cookie.h"
140 #include "net/cookies/cookie_options.h"
141 #include "net/ssl/ssl_cert_request_info.h"
142 #include "ppapi/host/ppapi_host.h"
143 #include "storage/browser/fileapi/external_mount_points.h"
144 #include "ui/base/l10n/l10n_util.h"
145 #include "ui/base/resource/resource_bundle.h"
146 #include "ui/resources/grit/ui_resources.h"
149 #include "base/win/windows_version.h"
150 #include "chrome/browser/chrome_browser_main_win.h"
151 #include "sandbox/win/src/sandbox_policy.h"
152 #elif defined(OS_MACOSX)
153 #include "chrome/browser/chrome_browser_main_mac.h"
154 #elif defined(OS_CHROMEOS)
155 #include "chrome/browser/chromeos/attestation/platform_verification_impl.h"
156 #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
157 #include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h"
158 #include "chrome/browser/chromeos/file_manager/app_id.h"
159 #include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
160 #include "chrome/browser/chromeos/fileapi/file_system_backend.h"
161 #include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
162 #include "chrome/browser/chromeos/login/startup_utils.h"
163 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
164 #include "chrome/browser/chromeos/system/input_device_settings.h"
165 #include "chromeos/chromeos_switches.h"
166 #include "components/user_manager/user_manager.h"
167 #elif defined(OS_LINUX)
168 #include "chrome/browser/chrome_browser_main_linux.h"
169 #elif defined(OS_ANDROID)
170 #include "chrome/browser/android/new_tab_page_url_handler.h"
171 #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
172 #include "chrome/browser/chrome_browser_main_android.h"
173 #include "chrome/common/descriptors_android.h"
174 #include "components/crash/browser/crash_dump_manager_android.h"
175 #include "components/service_tab_launcher/browser/android/service_tab_launcher.h"
176 #include "ui/base/resource/resource_bundle_android.h"
177 #elif defined(OS_POSIX)
178 #include "chrome/browser/chrome_browser_main_posix.h"
181 #if defined(OS_POSIX) && !defined(OS_MACOSX)
182 #include "base/debug/leak_annotations.h"
183 #include "components/crash/app/breakpad_linux.h"
184 #include "components/crash/browser/crash_handler_host_linux.h"
187 #if defined(OS_ANDROID)
188 #include "ui/base/ui_base_paths.h"
189 #include "ui/gfx/android/device_display_info.h"
192 #if defined(TOOLKIT_VIEWS)
193 #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
197 #include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
200 #if defined(USE_AURA)
201 #include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
205 #include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
208 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
209 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
212 #if !defined(DISABLE_NACL)
213 #include "components/nacl/browser/nacl_browser.h"
214 #include "components/nacl/browser/nacl_host_message_filter.h"
215 #include "components/nacl/browser/nacl_process_host.h"
216 #include "components/nacl/common/nacl_process_type.h"
217 #include "components/nacl/common/nacl_switches.h"
220 #if defined(ENABLE_EXTENSIONS)
221 #include "chrome/browser/accessibility/animation_policy_prefs.h"
222 #include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
223 #include "chrome/browser/media/cast_transport_host_filter.h"
224 #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
225 #include "components/guest_view/browser/guest_view_base.h"
226 #include "components/guest_view/browser/guest_view_manager.h"
227 #include "extensions/browser/extension_registry.h"
228 #include "extensions/browser/extension_util.h"
229 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
230 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
231 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
232 #include "extensions/common/constants.h"
233 #include "extensions/common/extension.h"
234 #include "extensions/common/extension_set.h"
235 #include "extensions/common/manifest_handlers/background_info.h"
236 #include "extensions/common/manifest_handlers/shared_module_info.h"
237 #include "extensions/common/permissions/permissions_data.h"
238 #include "extensions/common/permissions/socket_permission.h"
239 #include "extensions/common/switches.h"
242 #if defined(ENABLE_PLUGINS)
243 #include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
246 #if defined(ENABLE_SPELLCHECK)
247 #include "chrome/browser/spellchecker/spellcheck_message_filter.h"
250 #if defined(USE_BROWSER_SPELLCHECKER)
251 #include "chrome/browser/spellchecker/spellcheck_message_filter_platform.h"
254 #if defined(ENABLE_WEBRTC)
255 #include "chrome/browser/media/webrtc_logging_handler_host.h"
258 #if defined(ENABLE_MEDIA_ROUTER)
259 #include "chrome/browser/media/router/presentation_service_delegate_impl.h"
262 using base::FileDescriptor
;
263 using blink::WebWindowFeatures
;
264 using content::AccessTokenStore
;
265 using content::BrowserThread
;
266 using content::BrowserURLHandler
;
267 using content::ChildProcessSecurityPolicy
;
268 using content::QuotaPermissionContext
;
269 using content::RenderFrameHost
;
270 using content::RenderViewHost
;
271 using content::ResourceType
;
272 using content::SiteInstance
;
273 using content::WebContents
;
274 using content::WebPreferences
;
275 using message_center::NotifierId
;
277 #if defined(OS_POSIX)
278 using content::FileDescriptorInfo
;
281 #if defined(ENABLE_EXTENSIONS)
282 using extensions::APIPermission
;
283 using extensions::ChromeContentBrowserClientExtensionsPart
;
284 using extensions::Extension
;
285 using extensions::InfoMap
;
286 using extensions::Manifest
;
289 #if defined(ENABLE_PLUGINS)
290 using plugins::ChromeContentBrowserClientPluginsPart
;
295 // Cached version of the locale so we can return the locale on the I/O
297 base::LazyInstance
<std::string
> g_io_thread_application_locale
;
299 #if defined(ENABLE_PLUGINS)
300 // TODO(teravest): Add renderer-side API-specific checking for these APIs so
301 // that blanket permission isn't granted to all dev channel APIs for these.
302 // http://crbug.com/386743
303 const char* const kPredefinedAllowedDevChannelOrigins
[] = {
304 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/383937
305 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/383937
308 const char* const kPredefinedAllowedFileHandleOrigins
[] = {
309 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
310 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
313 const char* const kPredefinedAllowedSocketOrigins
[] = {
314 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
315 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
316 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
317 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
318 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
319 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
320 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
321 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
322 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
323 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
324 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
325 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
326 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
327 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
328 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
329 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
330 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
331 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
332 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
333 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
337 // Returns a copy of the given url with its host set to given host and path set
338 // to given path. Other parts of the url will be the same.
339 GURL
ReplaceURLHostAndPath(const GURL
& url
,
340 const std::string
& host
,
341 const std::string
& path
) {
342 url::Replacements
<char> replacements
;
343 replacements
.SetHost(host
.c_str(), url::Component(0, host
.length()));
344 replacements
.SetPath(path
.c_str(), url::Component(0, path
.length()));
345 return url
.ReplaceComponents(replacements
);
348 // Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
349 GURL
AddUberHost(const GURL
& url
) {
350 const std::string uber_host
= chrome::kChromeUIUberHost
;
351 const std::string new_path
= url
.host() + url
.path();
353 return ReplaceURLHostAndPath(url
, uber_host
, new_path
);
356 // If url->host() is "chrome" and url->path() has characters other than the
357 // first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
358 // returns true. Otherwise returns false.
359 bool RemoveUberHost(GURL
* url
) {
360 if (url
->host() != chrome::kChromeUIUberHost
)
363 if (url
->path().empty() || url
->path() == "/")
366 const std::string old_path
= url
->path();
368 const std::string::size_type separator
= old_path
.find('/', 1);
369 std::string new_host
;
370 std::string new_path
;
371 if (separator
== std::string::npos
) {
372 new_host
= old_path
.substr(1);
374 new_host
= old_path
.substr(1, separator
- 1);
375 new_path
= old_path
.substr(separator
);
378 // Do not allow URLs with paths empty before the first slash since we can't
379 // have an empty host. (e.g "foo://chrome//")
380 if (new_host
.empty())
383 *url
= ReplaceURLHostAndPath(*url
, new_host
, new_path
);
385 DCHECK(url
->is_valid());
390 // Handles rewriting Web UI URLs.
391 bool HandleWebUI(GURL
* url
, content::BrowserContext
* browser_context
) {
392 // Do not handle special URLs such as "about:foo"
393 if (!url
->host().empty()) {
394 const GURL chrome_url
= AddUberHost(*url
);
396 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
398 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
399 browser_context
, chrome_url
))
403 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
404 browser_context
, *url
))
407 #if defined(OS_CHROMEOS)
408 // Special case : in ChromeOS in Guest mode bookmarks and history are
409 // disabled for security reasons. New tab page explains the reasons, so
410 // we redirect user to new tab page.
411 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
412 if (url
->SchemeIs(content::kChromeUIScheme
) &&
413 (url
->DomainIs(chrome::kChromeUIBookmarksHost
) ||
414 url
->DomainIs(chrome::kChromeUIHistoryHost
))) {
415 // Rewrite with new tab URL
416 *url
= GURL(chrome::kChromeUINewTabURL
);
424 // Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
426 bool HandleWebUIReverse(GURL
* url
, content::BrowserContext
* browser_context
) {
427 if (!url
->is_valid() || !url
->SchemeIs(content::kChromeUIScheme
))
430 return RemoveUberHost(url
);
433 bool CertMatchesFilter(const net::X509Certificate
& cert
,
434 const base::DictionaryValue
& filter
) {
435 // TODO(markusheintz): This is the minimal required filter implementation.
436 // Implement a better matcher.
438 // An empty filter matches any client certificate since no requirements are
443 std::string common_name
;
444 if (filter
.GetString("ISSUER.CN", &common_name
) &&
445 (cert
.issuer().common_name
== common_name
)) {
451 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
452 breakpad::CrashHandlerHostLinux
* CreateCrashHandlerHost(
453 const std::string
& process_type
) {
454 base::FilePath dumps_path
;
455 PathService::Get(chrome::DIR_CRASH_DUMPS
, &dumps_path
);
457 ANNOTATE_SCOPED_MEMORY_LEAK
;
458 bool upload
= (getenv(env_vars::kHeadless
) == NULL
);
459 breakpad::CrashHandlerHostLinux
* crash_handler
=
460 new breakpad::CrashHandlerHostLinux(process_type
, dumps_path
, upload
);
461 crash_handler
->StartUploaderThread();
462 return crash_handler
;
466 int GetCrashSignalFD(const base::CommandLine
& command_line
) {
467 // Extensions have the same process type as renderers.
468 if (command_line
.HasSwitch(extensions::switches::kExtensionProcess
)) {
469 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
471 crash_handler
= CreateCrashHandlerHost("extension");
472 return crash_handler
->GetDeathSignalSocket();
475 std::string process_type
=
476 command_line
.GetSwitchValueASCII(switches::kProcessType
);
478 if (process_type
== switches::kRendererProcess
) {
479 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
481 crash_handler
= CreateCrashHandlerHost(process_type
);
482 return crash_handler
->GetDeathSignalSocket();
485 if (process_type
== switches::kPluginProcess
) {
486 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
488 crash_handler
= CreateCrashHandlerHost(process_type
);
489 return crash_handler
->GetDeathSignalSocket();
492 if (process_type
== switches::kPpapiPluginProcess
) {
493 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
495 crash_handler
= CreateCrashHandlerHost(process_type
);
496 return crash_handler
->GetDeathSignalSocket();
499 if (process_type
== switches::kGpuProcess
) {
500 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
502 crash_handler
= CreateCrashHandlerHost(process_type
);
503 return crash_handler
->GetDeathSignalSocket();
508 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
510 void SetApplicationLocaleOnIOThread(const std::string
& locale
) {
511 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
512 g_io_thread_application_locale
.Get() = locale
;
515 void HandleBlockedPopupOnUIThread(const BlockedWindowParams
& params
) {
516 RenderFrameHost
* render_frame_host
= RenderFrameHost::FromID(
517 params
.render_process_id(), params
.opener_render_frame_id());
518 if (!render_frame_host
)
520 WebContents
* tab
= WebContents::FromRenderFrameHost(render_frame_host
);
521 // The tab might already have navigated away. We only need to do this check
522 // for main frames, since the RenderFrameHost for a subframe opener will have
523 // already been deleted if the main frame navigates away.
525 (!render_frame_host
->GetParent() &&
526 tab
->GetMainFrame() != render_frame_host
))
529 prerender::PrerenderContents
* prerender_contents
=
530 prerender::PrerenderContents::FromWebContents(tab
);
531 if (prerender_contents
) {
532 prerender_contents
->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW
);
536 PopupBlockerTabHelper
* popup_helper
=
537 PopupBlockerTabHelper::FromWebContents(tab
);
540 popup_helper
->AddBlockedPopup(params
);
543 // An implementation of the SSLCertReporter interface used by
544 // SSLErrorHandler. Uses the SafeBrowsing UI manager to send invalid
545 // certificate reports.
546 class SafeBrowsingSSLCertReporter
: public SSLCertReporter
{
548 explicit SafeBrowsingSSLCertReporter(
549 const scoped_refptr
<SafeBrowsingUIManager
>& safe_browsing_ui_manager
)
550 : safe_browsing_ui_manager_(safe_browsing_ui_manager
) {}
551 ~SafeBrowsingSSLCertReporter() override
{}
553 // SSLCertReporter implementation
554 void ReportInvalidCertificateChain(
555 const std::string
& serialized_report
) override
{
556 if (safe_browsing_ui_manager_
) {
557 safe_browsing_ui_manager_
->ReportInvalidCertificateChain(
558 serialized_report
, base::Bind(&base::DoNothing
));
563 const scoped_refptr
<SafeBrowsingUIManager
> safe_browsing_ui_manager_
;
566 #if defined(OS_ANDROID)
568 void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams
& params
) {
569 WebContents
* web_contents
= tab_util::GetWebContentsByFrameID(
570 params
.render_process_id(), params
.opener_render_frame_id());
574 SingleTabModeTabHelper::FromWebContents(web_contents
)->HandleOpenUrl(params
);
577 float GetDeviceScaleAdjustment() {
578 static const float kMinFSM
= 1.05f
;
579 static const int kWidthForMinFSM
= 320;
580 static const float kMaxFSM
= 1.3f
;
581 static const int kWidthForMaxFSM
= 800;
583 gfx::DeviceDisplayInfo info
;
584 int minWidth
= info
.GetSmallestDIPWidth();
586 if (minWidth
<= kWidthForMinFSM
)
588 if (minWidth
>= kWidthForMaxFSM
)
591 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
592 float ratio
= static_cast<float>(minWidth
- kWidthForMinFSM
) /
593 (kWidthForMaxFSM
- kWidthForMinFSM
);
594 return ratio
* (kMaxFSM
- kMinFSM
) + kMinFSM
;
597 #endif // defined(OS_ANDROID)
599 #if defined(ENABLE_EXTENSIONS)
600 // By default, JavaScript and images are enabled in guest content.
601 void GetGuestViewDefaultContentSettingRules(
603 RendererContentSettingRules
* rules
) {
604 rules
->image_rules
.push_back(
605 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
606 ContentSettingsPattern::Wildcard(),
607 CONTENT_SETTING_ALLOW
,
611 rules
->script_rules
.push_back(
612 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
613 ContentSettingsPattern::Wildcard(),
614 CONTENT_SETTING_ALLOW
,
618 #endif // defined(ENABLE_EXTENSIONS)
624 ChromeContentBrowserClient::ChromeContentBrowserClient()
626 weak_factory_(this) {
627 #if defined(ENABLE_PLUGINS)
628 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedDevChannelOrigins
); ++i
)
629 allowed_dev_channel_origins_
.insert(kPredefinedAllowedDevChannelOrigins
[i
]);
630 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedFileHandleOrigins
); ++i
)
631 allowed_file_handle_origins_
.insert(kPredefinedAllowedFileHandleOrigins
[i
]);
632 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedSocketOrigins
); ++i
)
633 allowed_socket_origins_
.insert(kPredefinedAllowedSocketOrigins
[i
]);
635 extra_parts_
.push_back(new ChromeContentBrowserClientPluginsPart
);
638 #if !defined(OS_ANDROID)
639 TtsExtensionEngine
* tts_extension_engine
= TtsExtensionEngine::GetInstance();
640 TtsController::GetInstance()->SetTtsEngineDelegate(tts_extension_engine
);
643 #if defined(ENABLE_EXTENSIONS)
644 extra_parts_
.push_back(new ChromeContentBrowserClientExtensionsPart
);
648 ChromeContentBrowserClient::~ChromeContentBrowserClient() {
649 for (int i
= static_cast<int>(extra_parts_
.size()) - 1; i
>= 0; --i
)
650 delete extra_parts_
[i
];
651 extra_parts_
.clear();
655 void ChromeContentBrowserClient::RegisterProfilePrefs(
656 user_prefs::PrefRegistrySyncable
* registry
) {
657 registry
->RegisterBooleanPref(prefs::kDisable3DAPIs
, false);
658 registry
->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing
, true);
659 registry
->RegisterListPref(prefs::kEnableDeprecatedWebPlatformFeatures
);
663 void ChromeContentBrowserClient::SetApplicationLocale(
664 const std::string
& locale
) {
665 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
667 // This object is guaranteed to outlive all threads so we don't have to
668 // worry about the lack of refcounting and can just post as Unretained.
670 // The common case is that this function is called early in Chrome startup
671 // before any threads are created (it will also be called later if the user
672 // changes the pref). In this case, there will be no threads created and
673 // posting will fail. When there are no threads, we can just set the string
674 // without worrying about threadsafety.
675 if (!BrowserThread::PostTask(BrowserThread::IO
, FROM_HERE
,
676 base::Bind(&SetApplicationLocaleOnIOThread
, locale
))) {
677 g_io_thread_application_locale
.Get() = locale
;
681 content::BrowserMainParts
* ChromeContentBrowserClient::CreateBrowserMainParts(
682 const content::MainFunctionParams
& parameters
) {
683 ChromeBrowserMainParts
* main_parts
;
684 // Construct the Main browser parts based on the OS type.
686 main_parts
= new ChromeBrowserMainPartsWin(parameters
);
687 #elif defined(OS_MACOSX)
688 main_parts
= new ChromeBrowserMainPartsMac(parameters
);
689 #elif defined(OS_CHROMEOS)
690 main_parts
= new chromeos::ChromeBrowserMainPartsChromeos(parameters
);
691 #elif defined(OS_LINUX)
692 main_parts
= new ChromeBrowserMainPartsLinux(parameters
);
693 #elif defined(OS_ANDROID)
694 main_parts
= new ChromeBrowserMainPartsAndroid(parameters
);
695 #elif defined(OS_POSIX)
696 main_parts
= new ChromeBrowserMainPartsPosix(parameters
);
699 main_parts
= new ChromeBrowserMainParts(parameters
);
702 chrome::AddProfilesExtraParts(main_parts
);
704 // Construct additional browser parts. Stages are called in the order in
705 // which they are added.
706 #if defined(TOOLKIT_VIEWS)
707 main_parts
->AddParts(new ChromeBrowserMainExtraPartsViews());
710 // TODO(oshima): Athena on chrome currently requires USE_ASH to build.
711 // We should reduce the dependency as much as possible.
713 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAsh());
716 #if defined(USE_AURA)
717 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAura());
721 main_parts
->AddParts(new ChromeBrowserMainExtraPartsX11());
724 chrome::AddMetricsExtraParts(main_parts
);
729 void ChromeContentBrowserClient::PostAfterStartupTask(
730 const tracked_objects::Location
& from_here
,
731 const scoped_refptr
<base::TaskRunner
>& task_runner
,
732 const base::Closure
& task
) {
733 AfterStartupTaskUtils::PostTask(from_here
, task_runner
, task
);
736 std::string
ChromeContentBrowserClient::GetStoragePartitionIdForSite(
737 content::BrowserContext
* browser_context
,
739 std::string partition_id
;
741 // The partition ID for webview guest processes is the string value of its
742 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
743 if (site
.SchemeIs(content::kGuestScheme
)) {
744 partition_id
= site
.spec();
745 } else if (!switches::IsEnableWebviewBasedSignin() &&
746 site
.GetOrigin().spec() == kChromeUIChromeSigninURL
) {
747 // The non-webview Chrome signin page has an embedded iframe of extension
748 // and web content, thus it must be isolated from other webUI pages.
749 partition_id
= site
.GetOrigin().spec();
752 DCHECK(IsValidStoragePartitionId(browser_context
, partition_id
));
756 bool ChromeContentBrowserClient::IsValidStoragePartitionId(
757 content::BrowserContext
* browser_context
,
758 const std::string
& partition_id
) {
759 // The default ID is empty and is always valid.
760 if (partition_id
.empty())
763 return GURL(partition_id
).is_valid();
766 void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
767 content::BrowserContext
* browser_context
,
770 std::string
* partition_domain
,
771 std::string
* partition_name
,
773 // Default to the browser-wide storage partition and override based on |site|
775 partition_domain
->clear();
776 partition_name
->clear();
779 bool success
= false;
780 #if defined(ENABLE_EXTENSIONS)
781 success
= extensions::WebViewGuest::GetGuestPartitionConfigForSite(
782 site
, partition_domain
, partition_name
, in_memory
);
784 if (!success
&& site
.SchemeIs(extensions::kExtensionScheme
)) {
785 // If |can_be_default| is false, the caller is stating that the |site|
786 // should be parsed as if it had isolated storage. In particular it is
787 // important to NOT check ExtensionService for the is_storage_isolated()
788 // attribute because this code path is run during Extension uninstall
789 // to do cleanup after the Extension has already been unloaded from the
791 bool is_isolated
= !can_be_default
;
792 if (can_be_default
) {
793 if (extensions::util::SiteHasIsolatedStorage(site
, browser_context
))
798 CHECK(site
.has_host());
799 // For extensions with isolated storage, the the host of the |site| is
800 // the |partition_domain|. The |in_memory| and |partition_name| are only
801 // used in guest schemes so they are cleared here.
802 *partition_domain
= site
.host();
804 partition_name
->clear();
810 if (!success
&& (!switches::IsEnableWebviewBasedSignin() &&
811 site
.GetOrigin().spec() == kChromeUIChromeSigninURL
)) {
812 // The non-webview Chrome signin page has an embedded iframe of extension
813 // and web content, thus it must be isolated from other webUI pages.
814 *partition_domain
= chrome::kChromeUIChromeSigninHost
;
817 // Assert that if |can_be_default| is false, the code above must have found a
818 // non-default partition. If this fails, the caller has a serious logic
819 // error about which StoragePartition they expect to be in and it is not
821 CHECK(can_be_default
|| !partition_domain
->empty());
824 content::WebContentsViewDelegate
*
825 ChromeContentBrowserClient::GetWebContentsViewDelegate(
826 content::WebContents
* web_contents
) {
827 return chrome::CreateWebContentsViewDelegate(web_contents
);
830 void ChromeContentBrowserClient::RenderProcessWillLaunch(
831 content::RenderProcessHost
* host
) {
832 int id
= host
->GetID();
833 Profile
* profile
= Profile::FromBrowserContext(host
->GetBrowserContext());
834 net::URLRequestContextGetter
* context
=
835 profile
->GetRequestContextForRenderProcess(id
);
837 host
->AddFilter(new ChromeRenderMessageFilter(id
, profile
));
838 #if defined(ENABLE_EXTENSIONS)
839 host
->AddFilter(new cast::CastTransportHostFilter
);
841 #if defined(ENABLE_PRINTING)
842 host
->AddFilter(new printing::PrintingMessageFilter(id
, profile
));
844 host
->AddFilter(new SearchProviderInstallStateMessageFilter(id
, profile
));
845 #if defined(ENABLE_SPELLCHECK)
846 host
->AddFilter(new SpellCheckMessageFilter(id
));
848 #if defined(USE_BROWSER_SPELLCHECKER)
849 host
->AddFilter(new SpellCheckMessageFilterPlatform(id
));
851 host
->AddFilter(new ChromeNetBenchmarkingMessageFilter(profile
, context
));
852 host
->AddFilter(new prerender::PrerenderMessageFilter(id
, profile
));
853 host
->AddFilter(new TtsMessageFilter(host
->GetBrowserContext()));
854 #if defined(ENABLE_WEBRTC)
855 WebRtcLoggingHandlerHost
* webrtc_logging_handler_host
=
856 new WebRtcLoggingHandlerHost(profile
);
857 host
->SetWebRtcLogMessageCallback(base::Bind(
858 &WebRtcLoggingHandlerHost::LogMessage
, webrtc_logging_handler_host
));
859 host
->AddFilter(webrtc_logging_handler_host
);
860 host
->SetUserData(host
, new base::UserDataAdapter
<WebRtcLoggingHandlerHost
>(
861 webrtc_logging_handler_host
));
863 #if !defined(DISABLE_NACL)
864 host
->AddFilter(new nacl::NaClHostMessageFilter(
865 id
, profile
->IsOffTheRecord(),
869 #if defined(OS_ANDROID)
870 host
->AddFilter(new cdm::CdmMessageFilterAndroid());
872 DataReductionProxyChromeSettings
* data_reduction_proxy_settings
=
873 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(profile
);
874 host
->AddFilter(new data_reduction_proxy::DataReductionProxyMessageFilter(
875 data_reduction_proxy_settings
));
877 host
->Send(new ChromeViewMsg_SetIsIncognitoProcess(
878 profile
->IsOffTheRecord()));
880 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
881 extra_parts_
[i
]->RenderProcessWillLaunch(host
);
883 RendererContentSettingRules rules
;
884 if (host
->IsForGuestsOnly()) {
885 #if defined(ENABLE_EXTENSIONS)
886 GetGuestViewDefaultContentSettingRules(profile
->IsOffTheRecord(), &rules
);
891 GetRendererContentSettingRules(
892 profile
->GetHostContentSettingsMap(), &rules
);
894 host
->Send(new ChromeViewMsg_SetContentSettingRules(rules
));
897 GURL
ChromeContentBrowserClient::GetEffectiveURL(
898 content::BrowserContext
* browser_context
, const GURL
& url
) {
899 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
903 // If the input |url| should be assigned to the Instant renderer, make its
904 // effective URL distinct from other URLs on the search provider's domain.
905 if (search::ShouldAssignURLToInstantRenderer(url
, profile
))
906 return search::GetEffectiveURLForInstant(url
, profile
);
908 #if defined(ENABLE_EXTENSIONS)
909 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(
916 bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
917 content::BrowserContext
* browser_context
, const GURL
& effective_url
) {
918 // Non-extension, non-Instant URLs should generally use
919 // process-per-site-instance. Because we expect to use the effective URL,
920 // URLs for hosted apps (apart from bookmark apps) should have an extension
923 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
927 if (search::ShouldUseProcessPerSiteForInstantURL(effective_url
, profile
))
930 #if defined(ENABLE_EXTENSIONS)
931 return ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
932 profile
, effective_url
);
938 // TODO(creis, nick): https://crbug.com/160576 describes a weakness in our
939 // origin-lock enforcement, where we don't have a way to efficiently know
940 // effective URLs on the IO thread, and wind up killing processes that e.g.
941 // request cookies for their actual URL. This whole function (and its
942 // ExtensionsPart) should be removed once we add that ability to the IO thread.
943 bool ChromeContentBrowserClient::ShouldLockToOrigin(
944 content::BrowserContext
* browser_context
,
945 const GURL
& effective_site_url
) {
946 // Origin lock to the search scheme would kill processes upon legitimate
947 // requests for cookies from the search engine's domain.
948 if (effective_site_url
.SchemeIs(chrome::kChromeSearchScheme
))
951 #if defined(ENABLE_EXTENSIONS)
952 // Disable origin lock if this is an extension/app that applies effective URL
954 if (!ChromeContentBrowserClientExtensionsPart::ShouldLockToOrigin(
955 browser_context
, effective_site_url
)) {
962 // These are treated as WebUI schemes but do not get WebUI bindings. Also,
963 // view-source is allowed for these schemes.
964 void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
965 std::vector
<std::string
>* additional_schemes
) {
966 additional_schemes
->push_back(chrome::kChromeSearchScheme
);
967 additional_schemes
->push_back(dom_distiller::kDomDistillerScheme
);
970 void ChromeContentBrowserClient::GetAdditionalWebUIHostsToIgnoreParititionCheck(
971 std::vector
<std::string
>* hosts
) {
972 hosts
->push_back(chrome::kChromeUIExtensionIconHost
);
973 hosts
->push_back(chrome::kChromeUIFaviconHost
);
974 hosts
->push_back(chrome::kChromeUIThemeHost
);
975 hosts
->push_back(chrome::kChromeUIThumbnailHost
);
976 hosts
->push_back(chrome::kChromeUIThumbnailHost2
);
977 hosts
->push_back(chrome::kChromeUIThumbnailListHost
);
980 net::URLRequestContextGetter
*
981 ChromeContentBrowserClient::CreateRequestContext(
982 content::BrowserContext
* browser_context
,
983 content::ProtocolHandlerMap
* protocol_handlers
,
984 content::URLRequestInterceptorScopedVector request_interceptors
) {
985 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
986 return profile
->CreateRequestContext(protocol_handlers
,
987 request_interceptors
.Pass());
990 net::URLRequestContextGetter
*
991 ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
992 content::BrowserContext
* browser_context
,
993 const base::FilePath
& partition_path
,
995 content::ProtocolHandlerMap
* protocol_handlers
,
996 content::URLRequestInterceptorScopedVector request_interceptors
) {
997 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
998 return profile
->CreateRequestContextForStoragePartition(
1002 request_interceptors
.Pass());
1005 bool ChromeContentBrowserClient::IsHandledURL(const GURL
& url
) {
1006 return ProfileIOData::IsHandledURL(url
);
1009 bool ChromeContentBrowserClient::CanCommitURL(
1010 content::RenderProcessHost
* process_host
,
1012 #if defined(ENABLE_EXTENSIONS)
1013 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(
1020 bool ChromeContentBrowserClient::IsIllegalOrigin(
1021 content::ResourceContext
* resource_context
,
1022 int child_process_id
,
1023 const GURL
& origin
) {
1024 #if defined(ENABLE_EXTENSIONS)
1025 return ChromeContentBrowserClientExtensionsPart::IsIllegalOrigin(
1026 resource_context
, child_process_id
, origin
);
1032 bool ChromeContentBrowserClient::ShouldAllowOpenURL(
1033 content::SiteInstance
* site_instance
, const GURL
& url
) {
1034 GURL from_url
= site_instance
->GetSiteURL();
1036 #if defined(ENABLE_EXTENSIONS)
1038 if (ChromeContentBrowserClientExtensionsPart::ShouldAllowOpenURL(
1039 site_instance
, from_url
, url
, &result
))
1043 // Do not allow chrome://chrome-signin navigate to other chrome:// URLs, since
1044 // the signin page may host untrusted web content.
1045 if (from_url
.GetOrigin().spec() == chrome::kChromeUIChromeSigninURL
&&
1046 url
.SchemeIs(content::kChromeUIScheme
) &&
1047 url
.host() != chrome::kChromeUIChromeSigninHost
) {
1048 VLOG(1) << "Blocked navigation to " << url
.spec() << " from "
1049 << chrome::kChromeUIChromeSigninURL
;
1056 bool ChromeContentBrowserClient::IsSuitableHost(
1057 content::RenderProcessHost
* process_host
,
1058 const GURL
& site_url
) {
1060 Profile::FromBrowserContext(process_host
->GetBrowserContext());
1061 // This may be NULL during tests. In that case, just assume any site can
1066 // Instant URLs should only be in the instant process and instant process
1067 // should only have Instant URLs.
1068 InstantService
* instant_service
=
1069 InstantServiceFactory::GetForProfile(profile
);
1070 if (instant_service
) {
1071 bool is_instant_process
= instant_service
->IsInstantProcess(
1072 process_host
->GetID());
1073 bool should_be_in_instant_process
=
1074 search::ShouldAssignURLToInstantRenderer(site_url
, profile
);
1075 if (is_instant_process
|| should_be_in_instant_process
)
1076 return is_instant_process
&& should_be_in_instant_process
;
1079 #if defined(ENABLE_EXTENSIONS)
1080 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1081 profile
, process_host
, site_url
);
1087 bool ChromeContentBrowserClient::MayReuseHost(
1088 content::RenderProcessHost
* process_host
) {
1089 // If there is currently a prerender in progress for the host provided,
1090 // it may not be shared. We require prerenders to be by themselves in a
1091 // separate process so that we can monitor their resource usage.
1092 Profile
* profile
= Profile::FromBrowserContext(
1093 process_host
->GetBrowserContext());
1094 prerender::PrerenderManager
* prerender_manager
=
1095 prerender::PrerenderManagerFactory::GetForProfile(profile
);
1096 if (prerender_manager
&&
1097 !prerender_manager
->MayReuseProcessHost(process_host
)) {
1104 bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1105 content::BrowserContext
* browser_context
, const GURL
& url
) {
1106 // It has to be a valid URL for us to check for an extension.
1107 if (!url
.is_valid())
1110 #if defined(ENABLE_EXTENSIONS)
1111 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1112 return ChromeContentBrowserClientExtensionsPart::
1113 ShouldTryToUseExistingProcessHost(
1120 void ChromeContentBrowserClient::SiteInstanceGotProcess(
1121 SiteInstance
* site_instance
) {
1122 CHECK(site_instance
->HasProcess());
1124 Profile
* profile
= Profile::FromBrowserContext(
1125 site_instance
->GetBrowserContext());
1129 // Remember the ID of the Instant process to signal the renderer process
1130 // on startup in |AppendExtraCommandLineSwitches| below.
1131 if (search::ShouldAssignURLToInstantRenderer(site_instance
->GetSiteURL(),
1133 InstantService
* instant_service
=
1134 InstantServiceFactory::GetForProfile(profile
);
1135 if (instant_service
)
1136 instant_service
->AddInstantProcess(site_instance
->GetProcess()->GetID());
1139 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
1140 extra_parts_
[i
]->SiteInstanceGotProcess(site_instance
);
1143 void ChromeContentBrowserClient::SiteInstanceDeleting(
1144 SiteInstance
* site_instance
) {
1145 if (!site_instance
->HasProcess())
1148 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
1149 extra_parts_
[i
]->SiteInstanceDeleting(site_instance
);
1152 bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
1153 SiteInstance
* site_instance
,
1154 const GURL
& current_url
,
1155 const GURL
& new_url
) {
1156 #if defined(ENABLE_EXTENSIONS)
1157 return ChromeContentBrowserClientExtensionsPart::
1158 ShouldSwapBrowsingInstancesForNavigation(
1159 site_instance
, current_url
, new_url
);
1165 bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1166 content::ResourceContext
* resource_context
, const GURL
& current_url
,
1167 const GURL
& new_url
) {
1168 #if defined(ENABLE_EXTENSIONS)
1169 return ChromeContentBrowserClientExtensionsPart::
1170 ShouldSwapProcessesForRedirect(resource_context
, current_url
, new_url
);
1176 bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL
& url
) {
1177 return !url
.SchemeIs(chrome::kChromeNativeScheme
);
1180 std::string
ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1181 const std::string
& alias_name
) {
1182 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name
);
1187 bool IsAutoReloadEnabled() {
1188 // Fetch the field trial, even though we don't use it. Calling FindFullName()
1189 // causes the field-trial mechanism to report which group we're in, which
1190 // might reflect a hard disable or hard enable via flag, both of which have
1191 // their own field trial groups. This lets us know what percentage of users
1192 // manually enable or disable auto-reload.
1193 std::string group
= base::FieldTrialList::FindFullName(
1194 "AutoReloadExperiment");
1195 const base::CommandLine
& browser_command_line
=
1196 *base::CommandLine::ForCurrentProcess();
1197 if (browser_command_line
.HasSwitch(switches::kEnableOfflineAutoReload
))
1199 if (browser_command_line
.HasSwitch(switches::kDisableOfflineAutoReload
))
1204 bool IsAutoReloadVisibleOnlyEnabled() {
1205 // See the block comment in IsAutoReloadEnabled().
1206 std::string group
= base::FieldTrialList::FindFullName(
1207 "AutoReloadVisibleOnlyExperiment");
1208 const base::CommandLine
& browser_command_line
=
1209 *base::CommandLine::ForCurrentProcess();
1210 if (browser_command_line
.HasSwitch(
1211 switches::kEnableOfflineAutoReloadVisibleOnly
)) {
1214 if (browser_command_line
.HasSwitch(
1215 switches::kDisableOfflineAutoReloadVisibleOnly
)) {
1221 void MaybeAppendBlinkSettingsSwitchForFieldTrial(
1222 const base::CommandLine
& browser_command_line
,
1223 base::CommandLine
* command_line
) {
1224 // List of field trials that modify the blink-settings command line flag. No
1225 // two field trials in the list should specify the same keys, otherwise one
1226 // field trial may overwrite another. See Source/core/frame/Settings.in in
1227 // Blink for the list of valid keys.
1228 static const char* const kBlinkSettingsFieldTrials
[] = {
1229 // Keys: backgroundHtmlParserOutstandingTokenLimit
1230 // backgroundHtmlParserPendingTokenLimit
1231 "BackgroundHtmlParserTokenLimits",
1233 // Keys: doHtmlPreloadScanning
1234 "HtmlPreloadScanning",
1236 // Keys: lowPriorityIframes
1237 "LowPriorityIFrames",
1240 std::vector
<std::string
> blink_settings
;
1241 for (const char* field_trial_name
: kBlinkSettingsFieldTrials
) {
1242 // Each blink-settings field trial should include a forcing_flag group,
1243 // to make sure that clients that specify the blink-settings flag on the
1244 // command line are excluded from the experiment groups. To make
1245 // sure we assign clients that specify this flag to the forcing_flag
1246 // group, we must call GetVariationParams for each field trial first
1247 // (for example, before checking HasSwitch() and returning), since
1248 // GetVariationParams has the side-effect of assigning the client to
1249 // a field trial group.
1250 std::map
<std::string
, std::string
> params
;
1251 if (variations::GetVariationParams(field_trial_name
, ¶ms
)) {
1252 for (const auto& param
: params
) {
1253 blink_settings
.push_back(base::StringPrintf(
1254 "%s=%s", param
.first
.c_str(), param
.second
.c_str()));
1259 // Flags for the ResourcePriorities field trial. The settings are
1260 // encoded in the field trial group name instead of as variations
1261 // because the variations code is not accessible from the loader.
1263 // The group name encoding looks like this:
1264 // <descriptiveName>_ABCDE_E2_F_G
1265 // A - fetchDeferLateScripts (1 for true, 0 for false)
1266 // B - fetchIncreaseFontPriority (1 for true, 0 for false)
1267 // C - fetchIncreaseAsyncScriptPriority (1 for true, 0 for false)
1268 // D - fetchIncreasePriorities (1 for true, 0 for false)
1269 // E - fetchEnableLayoutBlockingThreshold (1 for true, 0 for false)
1270 // E2 - fetchLayoutBlockingThreshold (Numeric)
1271 // F - fetchMaxNumDelayableWhileLayoutBlocking (Numeric)
1272 // G - fetchMaxNumDelayableRequests (Numeric)
1274 // Only A-D are relevant to blink and exposed as settings
1275 // Any group names (Control, Default, etc) will not match the pattern or
1276 // flags and will get the default settings which is the expected behavior.
1277 std::string resource_priorities_trial_group
=
1278 base::FieldTrialList::FindFullName("ResourcePriorities");
1279 std::vector
<std::string
> split_group(
1280 base::SplitString(resource_priorities_trial_group
, "_",
1281 base::KEEP_WHITESPACE
, base::SPLIT_WANT_ALL
));
1282 if (split_group
.size() == 5 && split_group
[1].length() == 5) {
1283 if (split_group
[1].at(0) == '1')
1284 blink_settings
.push_back("fetchDeferLateScripts=true");
1285 if (split_group
[1].at(1) == '1')
1286 blink_settings
.push_back("fetchIncreaseFontPriority=true");
1287 if (split_group
[1].at(2) == '1')
1288 blink_settings
.push_back("fetchIncreaseAsyncScriptPriority=true");
1289 if (split_group
[1].at(3) == '1')
1290 blink_settings
.push_back("fetchIncreasePriorities=true");
1293 if (blink_settings
.empty()) {
1297 if (browser_command_line
.HasSwitch(switches::kBlinkSettings
) ||
1298 command_line
->HasSwitch(switches::kBlinkSettings
)) {
1299 // The field trials should be configured to force users that specify the
1300 // blink-settings flag into a group with no params, and we return
1301 // above if no params were specified, so it's an error if we reach
1303 LOG(WARNING
) << "Received field trial params, "
1304 "but blink-settings switch already specified.";
1308 command_line
->AppendSwitchASCII(switches::kBlinkSettings
,
1309 base::JoinString(blink_settings
, ","));
1314 void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1315 base::CommandLine
* command_line
,
1316 int child_process_id
) {
1317 #if defined(OS_MACOSX)
1318 scoped_ptr
<metrics::ClientInfo
> client_info
=
1319 GoogleUpdateSettings::LoadMetricsClientInfo();
1321 command_line
->AppendSwitchASCII(switches::kMetricsClientID
,
1322 client_info
->client_id
);
1324 #elif defined(OS_POSIX)
1325 if (breakpad::IsCrashReporterEnabled()) {
1326 scoped_ptr
<metrics::ClientInfo
> client_info
=
1327 GoogleUpdateSettings::LoadMetricsClientInfo();
1328 command_line
->AppendSwitchASCII(switches::kEnableCrashReporter
,
1329 client_info
? client_info
->client_id
1334 if (logging::DialogsAreSuppressed())
1335 command_line
->AppendSwitch(switches::kNoErrorDialogs
);
1337 std::string process_type
=
1338 command_line
->GetSwitchValueASCII(switches::kProcessType
);
1339 const base::CommandLine
& browser_command_line
=
1340 *base::CommandLine::ForCurrentProcess();
1342 static const char* const kCommonSwitchNames
[] = {
1343 switches::kUserAgent
,
1344 switches::kUserDataDir
, // Make logs go to the right file.
1346 command_line
->CopySwitchesFrom(browser_command_line
, kCommonSwitchNames
,
1347 arraysize(kCommonSwitchNames
));
1349 #if defined(ENABLE_IPC_FUZZER)
1350 static const char* const kIpcFuzzerSwitches
[] = {
1351 switches::kIpcDumpDirectory
,
1352 switches::kIpcFuzzerTestcase
,
1354 command_line
->CopySwitchesFrom(browser_command_line
, kIpcFuzzerSwitches
,
1355 arraysize(kIpcFuzzerSwitches
));
1358 #if defined(OS_CHROMEOS)
1359 static const char* const kChromeOSSwitches
[] = {
1360 switches::kDisableDinosaurEasterEgg
,
1362 command_line
->CopySwitchesFrom(browser_command_line
, kChromeOSSwitches
,
1363 arraysize(kChromeOSSwitches
));
1365 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
1366 base::FilePath homedir
;
1367 PathService::Get(base::DIR_HOME
, &homedir
);
1368 command_line
->AppendSwitchASCII(chromeos::switches::kHomedir
,
1369 homedir
.value().c_str());
1372 if (process_type
== switches::kRendererProcess
) {
1373 content::RenderProcessHost
* process
=
1374 content::RenderProcessHost::FromID(child_process_id
);
1376 process
? Profile::FromBrowserContext(process
->GetBrowserContext())
1378 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
1379 extra_parts_
[i
]->AppendExtraRendererCommandLineSwitches(
1380 command_line
, process
, profile
);
1383 #if defined(OS_CHROMEOS)
1384 const std::string
& login_profile
=
1385 browser_command_line
.GetSwitchValueASCII(
1386 chromeos::switches::kLoginProfile
);
1387 if (!login_profile
.empty())
1388 command_line
->AppendSwitchASCII(
1389 chromeos::switches::kLoginProfile
, login_profile
);
1392 #if defined(ENABLE_WEBRTC)
1393 MaybeCopyDisableWebRtcEncryptionSwitch(command_line
,
1394 browser_command_line
,
1395 chrome::GetChannel());
1399 PrefService
* prefs
= profile
->GetPrefs();
1400 // Currently this pref is only registered if applied via a policy.
1401 if (prefs
->HasPrefPath(prefs::kDisable3DAPIs
) &&
1402 prefs
->GetBoolean(prefs::kDisable3DAPIs
)) {
1403 // Turn this policy into a command line switch.
1404 command_line
->AppendSwitch(switches::kDisable3DAPIs
);
1407 const base::ListValue
* switches
=
1408 prefs
->GetList(prefs::kEnableDeprecatedWebPlatformFeatures
);
1410 // Enable any deprecated features that have been re-enabled by policy.
1411 for (base::ListValue::const_iterator it
= switches
->begin();
1412 it
!= switches
->end(); ++it
) {
1413 std::string switch_to_enable
;
1414 if ((*it
)->GetAsString(&switch_to_enable
))
1415 command_line
->AppendSwitch(switch_to_enable
);
1419 // Disable client-side phishing detection in the renderer if it is
1420 // disabled in the Profile preferences or the browser process.
1421 if (!prefs
->GetBoolean(prefs::kSafeBrowsingEnabled
) ||
1422 !g_browser_process
->safe_browsing_detection_service()) {
1423 command_line
->AppendSwitch(
1424 switches::kDisableClientSidePhishingDetection
);
1427 if (prefs
->GetBoolean(prefs::kPrintPreviewDisabled
))
1428 command_line
->AppendSwitch(switches::kDisablePrintPreview
);
1430 InstantService
* instant_service
=
1431 InstantServiceFactory::GetForProfile(profile
);
1432 if (instant_service
&&
1433 instant_service
->IsInstantProcess(process
->GetID()))
1434 command_line
->AppendSwitch(switches::kInstantProcess
);
1437 if (IsAutoReloadEnabled())
1438 command_line
->AppendSwitch(switches::kEnableOfflineAutoReload
);
1439 if (IsAutoReloadVisibleOnlyEnabled()) {
1440 command_line
->AppendSwitch(
1441 switches::kEnableOfflineAutoReloadVisibleOnly
);
1445 // Enable showing a saved copy if this session is in the field trial
1446 // or the user explicitly enabled it. Note that as far as the
1447 // renderer is concerned, the feature is enabled if-and-only-if
1448 // one of the kEnableShowSavedCopy* switches is on the command
1449 // line; the yes/no/default behavior is only at the browser
1450 // command line level.
1452 // Command line switches override
1453 const std::string
& show_saved_copy_value
=
1454 browser_command_line
.GetSwitchValueASCII(switches::kShowSavedCopy
);
1455 if (show_saved_copy_value
== switches::kEnableShowSavedCopyPrimary
||
1456 show_saved_copy_value
== switches::kEnableShowSavedCopySecondary
||
1457 show_saved_copy_value
== switches::kDisableShowSavedCopy
) {
1458 command_line
->AppendSwitchASCII(switches::kShowSavedCopy
,
1459 show_saved_copy_value
);
1462 base::FieldTrialList::FindFullName("LoadStaleCacheExperiment");
1464 if (group
== "Primary") {
1465 command_line
->AppendSwitchASCII(
1466 switches::kShowSavedCopy
, switches::kEnableShowSavedCopyPrimary
);
1467 } else if (group
== "Secondary") {
1468 command_line
->AppendSwitchASCII(
1469 switches::kShowSavedCopy
,
1470 switches::kEnableShowSavedCopySecondary
);
1475 MaybeAppendBlinkSettingsSwitchForFieldTrial(
1476 browser_command_line
, command_line
);
1478 // Please keep this in alphabetical order.
1479 static const char* const kSwitchNames
[] = {
1480 #if defined(OS_ANDROID)
1481 autofill::switches::kDisableAccessorySuggestionView
,
1482 autofill::switches::kEnableAccessorySuggestionView
,
1484 autofill::switches::kDisableFillOnAccountSelect
,
1485 autofill::switches::kDisablePasswordGeneration
,
1486 autofill::switches::kEnableFillOnAccountSelect
,
1487 autofill::switches::kEnableFillOnAccountSelectNoHighlighting
,
1488 autofill::switches::kEnablePasswordGeneration
,
1489 autofill::switches::kEnableSingleClickAutofill
,
1490 autofill::switches::kEnableSuggestionsWithSubstringMatch
,
1491 autofill::switches::kIgnoreAutocompleteOffForAutofill
,
1492 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration
,
1493 #if defined(ENABLE_EXTENSIONS)
1494 extensions::switches::kAllowHTTPBackgroundPage
,
1495 extensions::switches::kAllowLegacyExtensionManifests
,
1496 extensions::switches::kEnableAppWindowControls
,
1497 extensions::switches::kEnableEmbeddedExtensionOptions
,
1498 extensions::switches::kEnableExperimentalExtensionApis
,
1499 extensions::switches::kExtensionsOnChromeURLs
,
1500 extensions::switches::kWhitelistedExtensionID
,
1502 switches::kAllowInsecureLocalhost
,
1503 switches::kAppsGalleryURL
,
1504 switches::kCloudPrintURL
,
1505 switches::kCloudPrintXmppEndpoint
,
1506 switches::kDisableBundledPpapiFlash
,
1507 switches::kDisableCastStreamingHWEncoding
,
1508 switches::kDisableJavaScriptHarmonyShipping
,
1509 switches::kDisableNewBookmarkApps
,
1510 #if defined(ENABLE_SPELLCHECK) && defined(OS_ANDROID)
1511 switches::kEnableAndroidSpellChecker
,
1513 switches::kEnableBenchmarking
,
1514 switches::kEnableNaCl
,
1515 #if !defined(DISABLE_NACL)
1516 switches::kEnableNaClDebug
,
1517 switches::kEnableNaClNonSfiMode
,
1518 switches::kEnablePNaClSubzero
,
1520 switches::kEnableNetBenchmarking
,
1521 switches::kEnableNewBookmarkApps
,
1522 switches::kJavaScriptHarmony
,
1523 switches::kMessageLoopHistogrammer
,
1524 switches::kPpapiFlashArgs
,
1525 switches::kPpapiFlashPath
,
1526 switches::kPpapiFlashVersion
,
1527 switches::kProfilingAtStart
,
1528 switches::kProfilingFile
,
1529 switches::kProfilingFlush
,
1530 switches::kUnsafelyTreatInsecureOriginAsSecure
,
1531 translate::switches::kTranslateSecurityOrigin
,
1534 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1535 arraysize(kSwitchNames
));
1536 } else if (process_type
== switches::kUtilityProcess
) {
1537 #if defined(ENABLE_EXTENSIONS)
1538 static const char* const kSwitchNames
[] = {
1539 extensions::switches::kAllowHTTPBackgroundPage
,
1540 extensions::switches::kEnableExperimentalExtensionApis
,
1541 extensions::switches::kExtensionsOnChromeURLs
,
1542 extensions::switches::kWhitelistedExtensionID
,
1545 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1546 arraysize(kSwitchNames
));
1548 } else if (process_type
== switches::kPluginProcess
) {
1549 #if defined(OS_CHROMEOS)
1550 static const char* const kSwitchNames
[] = {
1551 chromeos::switches::kLoginProfile
,
1554 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1555 arraysize(kSwitchNames
));
1557 } else if (process_type
== switches::kZygoteProcess
) {
1558 static const char* const kSwitchNames
[] = {
1559 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
1560 switches::kDisableBundledPpapiFlash
,
1561 #if !defined(DISABLE_NACL)
1562 switches::kEnableNaClDebug
,
1563 switches::kEnableNaClNonSfiMode
,
1564 switches::kEnablePNaClSubzero
,
1565 switches::kNaClDangerousNoSandboxNonSfi
,
1566 switches::kUseNaClHelperNonSfi
,
1568 switches::kPpapiFlashPath
,
1569 switches::kPpapiFlashVersion
,
1572 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1573 arraysize(kSwitchNames
));
1574 } else if (process_type
== switches::kGpuProcess
) {
1575 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1576 // because GPU is expected to be unreliable.
1577 if (browser_command_line
.HasSwitch(switches::kIgnoreGpuBlacklist
) &&
1578 !command_line
->HasSwitch(switches::kDisableBreakpad
))
1579 command_line
->AppendSwitch(switches::kDisableBreakpad
);
1582 // The command line switch kEnableBenchmarking needs to be specified along
1583 // with the kEnableStatsTable switch to ensure that the stats table global
1584 // is initialized correctly.
1585 if (command_line
->HasSwitch(switches::kEnableBenchmarking
))
1586 DCHECK(command_line
->HasSwitch(switches::kEnableStatsTable
));
1589 std::string
ChromeContentBrowserClient::GetApplicationLocale() {
1590 if (BrowserThread::CurrentlyOn(BrowserThread::IO
))
1591 return g_io_thread_application_locale
.Get();
1592 return g_browser_process
->GetApplicationLocale();
1595 std::string
ChromeContentBrowserClient::GetAcceptLangs(
1596 content::BrowserContext
* context
) {
1597 Profile
* profile
= Profile::FromBrowserContext(context
);
1598 return profile
->GetPrefs()->GetString(prefs::kAcceptLanguages
);
1601 const gfx::ImageSkia
* ChromeContentBrowserClient::GetDefaultFavicon() {
1602 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
1603 return rb
.GetNativeImageNamed(IDR_DEFAULT_FAVICON
).ToImageSkia();
1606 bool ChromeContentBrowserClient::AllowAppCache(
1607 const GURL
& manifest_url
,
1608 const GURL
& first_party
,
1609 content::ResourceContext
* context
) {
1610 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
1611 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1612 return io_data
->GetCookieSettings()->
1613 IsSettingCookieAllowed(manifest_url
, first_party
);
1616 bool ChromeContentBrowserClient::AllowServiceWorker(
1618 const GURL
& first_party_url
,
1619 content::ResourceContext
* context
,
1620 int render_process_id
,
1621 int render_frame_id
) {
1622 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
1623 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1624 bool allow
= io_data
->GetCookieSettings()->IsSettingCookieAllowed(
1625 scope
, first_party_url
);
1627 // Record access to database for potential display in UI.
1628 BrowserThread::PostTask(
1629 BrowserThread::UI
, FROM_HERE
,
1630 base::Bind(&TabSpecificContentSettings::ServiceWorkerAccessed
,
1631 render_process_id
, render_frame_id
, scope
, !allow
));
1635 bool ChromeContentBrowserClient::AllowGetCookie(
1637 const GURL
& first_party
,
1638 const net::CookieList
& cookie_list
,
1639 content::ResourceContext
* context
,
1640 int render_process_id
,
1641 int render_frame_id
) {
1642 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
1643 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1644 bool allow
= io_data
->GetCookieSettings()->
1645 IsReadingCookieAllowed(url
, first_party
);
1647 BrowserThread::PostTask(
1648 BrowserThread::UI
, FROM_HERE
,
1649 base::Bind(&TabSpecificContentSettings::CookiesRead
, render_process_id
,
1650 render_frame_id
, url
, first_party
, cookie_list
, !allow
));
1654 bool ChromeContentBrowserClient::AllowSetCookie(
1656 const GURL
& first_party
,
1657 const std::string
& cookie_line
,
1658 content::ResourceContext
* context
,
1659 int render_process_id
,
1660 int render_frame_id
,
1661 net::CookieOptions
* options
) {
1662 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
1663 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1664 content_settings::CookieSettings
* cookie_settings
=
1665 io_data
->GetCookieSettings();
1666 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, first_party
);
1668 BrowserThread::PostTask(
1669 BrowserThread::UI
, FROM_HERE
,
1670 base::Bind(&TabSpecificContentSettings::CookieChanged
, render_process_id
,
1671 render_frame_id
, url
, first_party
, cookie_line
, *options
,
1676 bool ChromeContentBrowserClient::AllowSaveLocalState(
1677 content::ResourceContext
* context
) {
1678 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
1679 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1680 content_settings::CookieSettings
* cookie_settings
=
1681 io_data
->GetCookieSettings();
1682 ContentSetting setting
= cookie_settings
->GetDefaultCookieSetting(NULL
);
1684 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1685 // Could we even support per-origin settings?
1686 return setting
!= CONTENT_SETTING_SESSION_ONLY
;
1689 bool ChromeContentBrowserClient::AllowWorkerDatabase(
1691 const base::string16
& name
,
1692 const base::string16
& display_name
,
1693 unsigned long estimated_size
,
1694 content::ResourceContext
* context
,
1695 const std::vector
<std::pair
<int, int> >& render_frames
) {
1696 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
1697 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1698 content_settings::CookieSettings
* cookie_settings
=
1699 io_data
->GetCookieSettings();
1700 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1702 // Record access to database for potential display in UI.
1703 std::vector
<std::pair
<int, int> >::const_iterator i
;
1704 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1705 BrowserThread::PostTask(
1706 BrowserThread::UI
, FROM_HERE
,
1707 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed
,
1708 i
->first
, i
->second
, url
, name
, display_name
, !allow
));
1714 void ChromeContentBrowserClient::AllowWorkerFileSystem(
1716 content::ResourceContext
* context
,
1717 const std::vector
<std::pair
<int, int> >& render_frames
,
1718 base::Callback
<void(bool)> callback
) {
1719 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
1720 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1721 content_settings::CookieSettings
* cookie_settings
=
1722 io_data
->GetCookieSettings();
1723 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1725 #if defined(ENABLE_EXTENSIONS)
1726 GuestPermissionRequestHelper(url
, render_frames
, callback
, allow
);
1728 FileSystemAccessed(url
, render_frames
, callback
, allow
);
1732 #if defined(ENABLE_EXTENSIONS)
1733 void ChromeContentBrowserClient::GuestPermissionRequestHelper(
1735 const std::vector
<std::pair
<int, int> >& render_frames
,
1736 base::Callback
<void(bool)> callback
,
1738 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
1739 std::vector
<std::pair
<int, int> >::const_iterator i
;
1740 std::map
<int, int> process_map
;
1741 std::map
<int, int>::const_iterator it
;
1742 bool has_web_view_guest
= false;
1743 // Record access to file system for potential display in UI.
1744 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1745 if (process_map
.find(i
->first
) != process_map
.end())
1748 process_map
.insert(std::pair
<int, int>(i
->first
, i
->second
));
1750 if (extensions::WebViewRendererState::GetInstance()->IsGuest(i
->first
))
1751 has_web_view_guest
= true;
1753 if (!has_web_view_guest
) {
1754 FileSystemAccessed(url
, render_frames
, callback
, allow
);
1757 DCHECK_EQ(1U, process_map
.size());
1758 it
= process_map
.begin();
1759 BrowserThread::PostTask(
1762 base::Bind(&ChromeContentBrowserClient::
1763 RequestFileSystemPermissionOnUIThread
,
1768 base::Bind(&ChromeContentBrowserClient::FileSystemAccessed
,
1769 weak_factory_
.GetWeakPtr(),
1775 void ChromeContentBrowserClient::RequestFileSystemPermissionOnUIThread(
1776 int render_process_id
,
1777 int render_frame_id
,
1779 bool allowed_by_default
,
1780 const base::Callback
<void(bool)>& callback
) {
1781 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
1782 extensions::WebViewPermissionHelper
* web_view_permission_helper
=
1783 extensions::WebViewPermissionHelper::FromFrameID(
1784 render_process_id
, render_frame_id
);
1785 web_view_permission_helper
->RequestFileSystemPermission(url
,
1791 void ChromeContentBrowserClient::FileSystemAccessed(
1793 const std::vector
<std::pair
<int, int> >& render_frames
,
1794 base::Callback
<void(bool)> callback
,
1796 // Record access to file system for potential display in UI.
1797 std::vector
<std::pair
<int, int> >::const_iterator i
;
1798 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1799 BrowserThread::PostTask(
1802 base::Bind(&TabSpecificContentSettings::FileSystemAccessed
,
1803 i
->first
, i
->second
, url
, !allow
));
1805 callback
.Run(allow
);
1808 bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1810 const base::string16
& name
,
1811 content::ResourceContext
* context
,
1812 const std::vector
<std::pair
<int, int> >& render_frames
) {
1813 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
1814 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1815 content_settings::CookieSettings
* cookie_settings
=
1816 io_data
->GetCookieSettings();
1817 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1819 // Record access to IndexedDB for potential display in UI.
1820 std::vector
<std::pair
<int, int> >::const_iterator i
;
1821 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1822 BrowserThread::PostTask(
1823 BrowserThread::UI
, FROM_HERE
,
1824 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed
,
1825 i
->first
, i
->second
, url
, name
, !allow
));
1831 #if defined(ENABLE_WEBRTC)
1832 bool ChromeContentBrowserClient::AllowWebRTCIdentityCache(
1834 const GURL
& first_party_url
,
1835 content::ResourceContext
* context
) {
1836 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
1837 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1838 content_settings::CookieSettings
* cookie_settings
=
1839 io_data
->GetCookieSettings();
1840 return cookie_settings
->IsReadingCookieAllowed(url
, first_party_url
) &&
1841 cookie_settings
->IsSettingCookieAllowed(url
, first_party_url
);
1843 #endif // defined(ENABLE_WEBRTC)
1845 net::URLRequestContext
*
1846 ChromeContentBrowserClient::OverrideRequestContextForURL(
1847 const GURL
& url
, content::ResourceContext
* context
) {
1848 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
1849 #if defined(ENABLE_EXTENSIONS)
1850 if (url
.SchemeIs(extensions::kExtensionScheme
)) {
1851 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1852 return io_data
->extensions_request_context();
1859 QuotaPermissionContext
*
1860 ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1861 return new ChromeQuotaPermissionContext();
1864 void ChromeContentBrowserClient::AllowCertificateError(
1865 int render_process_id
,
1866 int render_frame_id
,
1868 const net::SSLInfo
& ssl_info
,
1869 const GURL
& request_url
,
1870 ResourceType resource_type
,
1872 bool strict_enforcement
,
1873 bool expired_previous_decision
,
1874 const base::Callback
<void(bool)>& callback
,
1875 content::CertificateRequestResultType
* result
) {
1876 if (resource_type
!= content::RESOURCE_TYPE_MAIN_FRAME
) {
1877 // A sub-resource has a certificate error. The user doesn't really
1878 // have a context for making the right decision, so block the
1879 // request hard, without an info bar to allow showing the insecure
1881 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY
;
1885 // If the tab is being prerendered, cancel the prerender and the request.
1886 content::RenderFrameHost
* render_frame_host
=
1887 content::RenderFrameHost::FromID(render_process_id
, render_frame_id
);
1888 WebContents
* tab
= WebContents::FromRenderFrameHost(render_frame_host
);
1894 prerender::PrerenderContents
* prerender_contents
=
1895 prerender::PrerenderContents::FromWebContents(tab
);
1896 if (prerender_contents
) {
1897 prerender_contents
->Destroy(prerender::FINAL_STATUS_SSL_ERROR
);
1898 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL
;
1902 // Otherwise, display an SSL blocking page. The interstitial page takes
1903 // ownership of ssl_blocking_page.
1904 int options_mask
= 0;
1906 options_mask
|= SSLBlockingPage::OVERRIDABLE
;
1907 if (strict_enforcement
)
1908 options_mask
|= SSLBlockingPage::STRICT_ENFORCEMENT
;
1909 if (expired_previous_decision
)
1910 options_mask
|= SSLBlockingPage::EXPIRED_BUT_PREVIOUSLY_ALLOWED
;
1912 SafeBrowsingService
* safe_browsing_service
=
1913 g_browser_process
->safe_browsing_service();
1914 scoped_ptr
<SafeBrowsingSSLCertReporter
> cert_reporter(
1915 new SafeBrowsingSSLCertReporter(safe_browsing_service
1916 ? safe_browsing_service
->ui_manager()
1918 SSLErrorHandler::HandleSSLError(tab
, cert_error
, ssl_info
, request_url
,
1919 options_mask
, cert_reporter
.Pass(), callback
);
1922 void ChromeContentBrowserClient::SelectClientCertificate(
1923 content::WebContents
* web_contents
,
1924 net::SSLCertRequestInfo
* cert_request_info
,
1925 scoped_ptr
<content::ClientCertificateDelegate
> delegate
) {
1926 prerender::PrerenderContents
* prerender_contents
=
1927 prerender::PrerenderContents::FromWebContents(web_contents
);
1928 if (prerender_contents
) {
1929 prerender_contents
->Destroy(
1930 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED
);
1934 GURL
requesting_url("https://" + cert_request_info
->host_and_port
.ToString());
1935 DCHECK(requesting_url
.is_valid())
1936 << "Invalid URL string: https://"
1937 << cert_request_info
->host_and_port
.ToString();
1940 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
1941 scoped_ptr
<base::Value
> filter
=
1942 profile
->GetHostContentSettingsMap()->GetWebsiteSetting(
1945 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE
,
1950 // Try to automatically select a client certificate.
1951 if (filter
->IsType(base::Value::TYPE_DICTIONARY
)) {
1952 base::DictionaryValue
* filter_dict
=
1953 static_cast<base::DictionaryValue
*>(filter
.get());
1955 const std::vector
<scoped_refptr
<net::X509Certificate
> >&
1956 all_client_certs
= cert_request_info
->client_certs
;
1957 for (size_t i
= 0; i
< all_client_certs
.size(); ++i
) {
1958 if (CertMatchesFilter(*all_client_certs
[i
].get(), *filter_dict
)) {
1959 // Use the first certificate that is matched by the filter.
1960 delegate
->ContinueWithCertificate(all_client_certs
[i
].get());
1969 chrome::ShowSSLClientCertificateSelector(web_contents
, cert_request_info
,
1973 void ChromeContentBrowserClient::AddCertificate(
1974 net::CertificateMimeType cert_type
,
1975 const void* cert_data
,
1977 int render_process_id
,
1978 int render_frame_id
) {
1979 chrome::SSLAddCertificate(cert_type
, cert_data
, cert_size
,
1980 render_process_id
, render_frame_id
);
1983 content::MediaObserver
* ChromeContentBrowserClient::GetMediaObserver() {
1984 return MediaCaptureDevicesDispatcher::GetInstance();
1987 content::PlatformNotificationService
*
1988 ChromeContentBrowserClient::GetPlatformNotificationService() {
1989 #if defined(ENABLE_NOTIFICATIONS)
1990 return PlatformNotificationServiceImpl::GetInstance();
1997 bool ChromeContentBrowserClient::CanCreateWindow(
1998 const GURL
& opener_url
,
1999 const GURL
& opener_top_level_frame_url
,
2000 const GURL
& source_origin
,
2001 WindowContainerType container_type
,
2002 const GURL
& target_url
,
2003 const content::Referrer
& referrer
,
2004 WindowOpenDisposition disposition
,
2005 const WebWindowFeatures
& features
,
2007 bool opener_suppressed
,
2008 content::ResourceContext
* context
,
2009 int render_process_id
,
2010 int opener_render_view_id
,
2011 int opener_render_frame_id
,
2012 bool* no_javascript_access
) {
2013 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
2015 *no_javascript_access
= false;
2017 // If the opener is trying to create a background window but doesn't have
2018 // the appropriate permission, fail the attempt.
2019 if (container_type
== WINDOW_CONTAINER_TYPE_BACKGROUND
) {
2020 #if defined(ENABLE_EXTENSIONS)
2021 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
2022 InfoMap
* map
= io_data
->GetExtensionInfoMap();
2023 if (!map
->SecurityOriginHasAPIPermission(
2026 APIPermission::kBackground
)) {
2030 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2031 // return a recently installed Extension even if this CanCreateWindow call
2032 // was made by an old copy of the page in a normal web process. That's ok,
2033 // because the permission check above would have caused an early return
2034 // already. We must use the full URL to find hosted apps, though, and not
2036 const Extension
* extension
=
2037 map
->extensions().GetExtensionOrAppByURL(opener_url
);
2038 if (extension
&& !extensions::BackgroundInfo::AllowJSAccess(extension
))
2039 *no_javascript_access
= true;
2045 #if defined(ENABLE_EXTENSIONS)
2046 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
2051 HostContentSettingsMap
* content_settings
=
2052 ProfileIOData::FromResourceContext(context
)->GetHostContentSettingsMap();
2053 BlockedWindowParams
blocked_params(target_url
,
2060 opener_render_frame_id
);
2062 if (!user_gesture
&&
2063 !base::CommandLine::ForCurrentProcess()->HasSwitch(
2064 switches::kDisablePopupBlocking
)) {
2065 if (content_settings
->GetContentSetting(opener_top_level_frame_url
,
2066 opener_top_level_frame_url
,
2067 CONTENT_SETTINGS_TYPE_POPUPS
,
2069 CONTENT_SETTING_ALLOW
) {
2070 BrowserThread::PostTask(BrowserThread::UI
,
2072 base::Bind(&HandleBlockedPopupOnUIThread
,
2078 #if defined(OS_ANDROID)
2079 if (SingleTabModeTabHelper::IsRegistered(render_process_id
,
2080 opener_render_view_id
)) {
2081 BrowserThread::PostTask(BrowserThread::UI
,
2083 base::Bind(&HandleSingleTabModeBlockOnUIThread
,
2092 void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2093 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
2094 return g_browser_process
->ResourceDispatcherHostCreated();
2097 content::SpeechRecognitionManagerDelegate
*
2098 ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
2099 return new speech::ChromeSpeechRecognitionManagerDelegate();
2102 net::NetLog
* ChromeContentBrowserClient::GetNetLog() {
2103 return g_browser_process
->net_log();
2106 AccessTokenStore
* ChromeContentBrowserClient::CreateAccessTokenStore() {
2107 return new ChromeAccessTokenStore();
2110 bool ChromeContentBrowserClient::IsFastShutdownPossible() {
2114 void ChromeContentBrowserClient::OverrideWebkitPrefs(
2115 RenderViewHost
* rvh
, WebPreferences
* web_prefs
) {
2116 Profile
* profile
= Profile::FromBrowserContext(
2117 rvh
->GetProcess()->GetBrowserContext());
2118 PrefService
* prefs
= profile
->GetPrefs();
2120 // Fill per-script font preferences. These are not registered on Android
2121 // - http://crbug.com/308033.
2122 #if !defined(OS_ANDROID)
2123 FontFamilyCache::FillFontFamilyMap(profile
,
2124 prefs::kWebKitStandardFontFamilyMap
,
2125 &web_prefs
->standard_font_family_map
);
2126 FontFamilyCache::FillFontFamilyMap(profile
,
2127 prefs::kWebKitFixedFontFamilyMap
,
2128 &web_prefs
->fixed_font_family_map
);
2129 FontFamilyCache::FillFontFamilyMap(profile
,
2130 prefs::kWebKitSerifFontFamilyMap
,
2131 &web_prefs
->serif_font_family_map
);
2132 FontFamilyCache::FillFontFamilyMap(profile
,
2133 prefs::kWebKitSansSerifFontFamilyMap
,
2134 &web_prefs
->sans_serif_font_family_map
);
2135 FontFamilyCache::FillFontFamilyMap(profile
,
2136 prefs::kWebKitCursiveFontFamilyMap
,
2137 &web_prefs
->cursive_font_family_map
);
2138 FontFamilyCache::FillFontFamilyMap(profile
,
2139 prefs::kWebKitFantasyFontFamilyMap
,
2140 &web_prefs
->fantasy_font_family_map
);
2141 FontFamilyCache::FillFontFamilyMap(profile
,
2142 prefs::kWebKitPictographFontFamilyMap
,
2143 &web_prefs
->pictograph_font_family_map
);
2146 web_prefs
->default_font_size
=
2147 prefs
->GetInteger(prefs::kWebKitDefaultFontSize
);
2148 web_prefs
->default_fixed_font_size
=
2149 prefs
->GetInteger(prefs::kWebKitDefaultFixedFontSize
);
2150 web_prefs
->minimum_font_size
=
2151 prefs
->GetInteger(prefs::kWebKitMinimumFontSize
);
2152 web_prefs
->minimum_logical_font_size
=
2153 prefs
->GetInteger(prefs::kWebKitMinimumLogicalFontSize
);
2155 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2157 web_prefs
->javascript_can_open_windows_automatically
=
2158 prefs
->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically
);
2159 web_prefs
->dom_paste_enabled
=
2160 prefs
->GetBoolean(prefs::kWebKitDomPasteEnabled
);
2161 web_prefs
->tabs_to_links
= prefs
->GetBoolean(prefs::kWebkitTabsToLinks
);
2163 if (!prefs
->GetBoolean(prefs::kWebKitJavascriptEnabled
))
2164 web_prefs
->javascript_enabled
= false;
2165 if (!prefs
->GetBoolean(prefs::kWebKitWebSecurityEnabled
))
2166 web_prefs
->web_security_enabled
= false;
2167 if (!prefs
->GetBoolean(prefs::kWebKitPluginsEnabled
))
2168 web_prefs
->plugins_enabled
= false;
2169 web_prefs
->loads_images_automatically
=
2170 prefs
->GetBoolean(prefs::kWebKitLoadsImagesAutomatically
);
2172 if (prefs
->GetBoolean(prefs::kDisable3DAPIs
))
2173 web_prefs
->experimental_webgl_enabled
= false;
2175 web_prefs
->allow_displaying_insecure_content
=
2176 prefs
->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent
);
2177 web_prefs
->allow_running_insecure_content
=
2178 prefs
->GetBoolean(prefs::kWebKitAllowRunningInsecureContent
);
2179 #if defined(OS_ANDROID)
2180 web_prefs
->font_scale_factor
=
2181 static_cast<float>(prefs
->GetDouble(prefs::kWebKitFontScaleFactor
));
2182 web_prefs
->device_scale_adjustment
= GetDeviceScaleAdjustment();
2183 web_prefs
->force_enable_zoom
=
2184 prefs
->GetBoolean(prefs::kWebKitForceEnableZoom
);
2187 #if defined(OS_ANDROID)
2188 web_prefs
->password_echo_enabled
=
2189 prefs
->GetBoolean(prefs::kWebKitPasswordEchoEnabled
);
2191 web_prefs
->password_echo_enabled
= browser_defaults::kPasswordEchoEnabled
;
2194 web_prefs
->asynchronous_spell_checking_enabled
= true;
2195 web_prefs
->unified_textchecker_enabled
= true;
2197 web_prefs
->uses_universal_detector
=
2198 prefs
->GetBoolean(prefs::kWebKitUsesUniversalDetector
);
2199 web_prefs
->text_areas_are_resizable
=
2200 prefs
->GetBoolean(prefs::kWebKitTextAreasAreResizable
);
2201 web_prefs
->hyperlink_auditing_enabled
=
2202 prefs
->GetBoolean(prefs::kEnableHyperlinkAuditing
);
2204 #if defined(ENABLE_EXTENSIONS)
2205 std::string image_animation_policy
=
2206 prefs
->GetString(prefs::kAnimationPolicy
);
2207 if (image_animation_policy
== kAnimationPolicyOnce
)
2208 web_prefs
->animation_policy
=
2209 content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE
;
2210 else if (image_animation_policy
== kAnimationPolicyNone
)
2211 web_prefs
->animation_policy
= content::IMAGE_ANIMATION_POLICY_NO_ANIMATION
;
2213 web_prefs
->animation_policy
= content::IMAGE_ANIMATION_POLICY_ALLOWED
;
2216 // Make sure we will set the default_encoding with canonical encoding name.
2217 web_prefs
->default_encoding
=
2218 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
2219 web_prefs
->default_encoding
);
2220 if (web_prefs
->default_encoding
.empty()) {
2221 prefs
->ClearPref(prefs::kDefaultCharset
);
2222 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2224 DCHECK(!web_prefs
->default_encoding
.empty());
2226 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2227 switches::kEnablePotentiallyAnnoyingSecurityFeatures
)) {
2228 web_prefs
->disable_reading_from_canvas
= true;
2229 web_prefs
->strict_mixed_content_checking
= true;
2230 web_prefs
->strict_powerful_feature_restrictions
= true;
2233 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2234 extra_parts_
[i
]->OverrideWebkitPrefs(rvh
, web_prefs
);
2237 void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2238 BrowserURLHandler
* handler
) {
2239 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2240 extra_parts_
[i
]->BrowserURLHandlerCreated(handler
);
2242 // about: handler. Must come before chrome: handler, since it will
2243 // rewrite about: urls to chrome: URLs and then expect chrome: to
2244 // actually handle them. Also relies on a preliminary fixup phase.
2245 handler
->SetFixupHandler(&FixupBrowserAboutURL
);
2246 handler
->AddHandlerPair(&WillHandleBrowserAboutURL
,
2247 BrowserURLHandler::null_handler());
2249 #if defined(OS_ANDROID)
2250 // Handler to rewrite chrome://newtab on Android.
2251 handler
->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL
,
2252 BrowserURLHandler::null_handler());
2254 // Handler to rewrite chrome://newtab for InstantExtended.
2255 handler
->AddHandlerPair(&search::HandleNewTabURLRewrite
,
2256 &search::HandleNewTabURLReverseRewrite
);
2259 // chrome: & friends.
2260 handler
->AddHandlerPair(&HandleWebUI
, &HandleWebUIReverse
);
2263 void ChromeContentBrowserClient::ClearCache(RenderFrameHost
* rfh
) {
2264 Profile
* profile
= Profile::FromBrowserContext(
2265 rfh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2266 BrowsingDataRemover
* remover
=
2267 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2268 remover
->Remove(BrowsingDataRemover::REMOVE_CACHE
,
2269 BrowsingDataHelper::UNPROTECTED_WEB
);
2270 // BrowsingDataRemover takes care of deleting itself when done.
2273 void ChromeContentBrowserClient::ClearCookies(RenderFrameHost
* rfh
) {
2274 Profile
* profile
= Profile::FromBrowserContext(
2275 rfh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2276 BrowsingDataRemover
* remover
=
2277 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2278 int remove_mask
= BrowsingDataRemover::REMOVE_SITE_DATA
;
2279 remover
->Remove(remove_mask
, BrowsingDataHelper::UNPROTECTED_WEB
);
2280 // BrowsingDataRemover takes care of deleting itself when done.
2283 base::FilePath
ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
2284 return DownloadPrefs::GetDefaultDownloadDirectory();
2287 std::string
ChromeContentBrowserClient::GetDefaultDownloadName() {
2288 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME
);
2291 base::FilePath
ChromeContentBrowserClient::GetShaderDiskCacheDirectory() {
2292 base::FilePath user_data_dir
;
2293 PathService::Get(DIR_USER_DATA
, &user_data_dir
);
2294 DCHECK(!user_data_dir
.empty());
2295 return user_data_dir
.Append(FILE_PATH_LITERAL("ShaderCache"));
2298 void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2299 content::BrowserPpapiHost
* browser_host
) {
2300 #if defined(ENABLE_PLUGINS)
2301 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host
);
2305 content::BrowserPpapiHost
*
2306 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2307 int plugin_process_id
) {
2308 #if !defined(DISABLE_NACL)
2309 content::BrowserChildProcessHostIterator
iter(PROCESS_TYPE_NACL_LOADER
);
2310 while (!iter
.Done()) {
2311 nacl::NaClProcessHost
* host
= static_cast<nacl::NaClProcessHost
*>(
2312 iter
.GetDelegate());
2313 if (host
->process() &&
2314 host
->process()->GetData().id
== plugin_process_id
) {
2315 // Found the plugin.
2316 return host
->browser_ppapi_host();
2324 bool ChromeContentBrowserClient::AllowPepperSocketAPI(
2325 content::BrowserContext
* browser_context
,
2328 const content::SocketPermissionRequest
* params
) {
2329 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2330 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
2331 browser_context
, url
, private_api
, params
, allowed_socket_origins_
);
2337 ui::SelectFilePolicy
* ChromeContentBrowserClient::CreateSelectFilePolicy(
2338 WebContents
* web_contents
) {
2339 return new ChromeSelectFilePolicy(web_contents
);
2342 void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2343 std::vector
<std::string
>* additional_allowed_schemes
) {
2344 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2345 additional_allowed_schemes
);
2346 additional_allowed_schemes
->push_back(content::kChromeDevToolsScheme
);
2347 additional_allowed_schemes
->push_back(content::kChromeUIScheme
);
2348 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
2349 extra_parts_
[i
]->GetAdditionalAllowedSchemesForFileSystem(
2350 additional_allowed_schemes
);
2354 void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
2355 std::vector
<storage::URLRequestAutoMountHandler
>* handlers
) {
2356 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2357 extra_parts_
[i
]->GetURLRequestAutoMountHandlers(handlers
);
2360 void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
2361 content::BrowserContext
* browser_context
,
2362 const base::FilePath
& storage_partition_path
,
2363 ScopedVector
<storage::FileSystemBackend
>* additional_backends
) {
2364 #if defined(OS_CHROMEOS)
2365 storage::ExternalMountPoints
* external_mount_points
=
2366 content::BrowserContext::GetMountPoints(browser_context
);
2367 DCHECK(external_mount_points
);
2368 chromeos::FileSystemBackend
* backend
= new chromeos::FileSystemBackend(
2369 new drive::FileSystemBackendDelegate
,
2370 new chromeos::file_system_provider::BackendDelegate
,
2371 new chromeos::MTPFileSystemBackendDelegate(storage_partition_path
),
2372 external_mount_points
,
2373 storage::ExternalMountPoints::GetSystemInstance());
2374 backend
->AddSystemMountPoints();
2375 DCHECK(backend
->CanHandleType(storage::kFileSystemTypeExternal
));
2376 additional_backends
->push_back(backend
);
2379 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
2380 extra_parts_
[i
]->GetAdditionalFileSystemBackends(
2381 browser_context
, storage_partition_path
, additional_backends
);
2385 #if defined(OS_ANDROID)
2386 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2387 const base::CommandLine
& command_line
,
2388 int child_process_id
,
2389 FileDescriptorInfo
* mappings
,
2390 std::map
<int, base::MemoryMappedFile::Region
>* regions
) {
2391 int fd
= ui::GetMainAndroidPackFd(
2392 &(*regions
)[kAndroidUIResourcesPakDescriptor
]);
2393 mappings
->Share(kAndroidUIResourcesPakDescriptor
, fd
);
2395 fd
= ui::GetCommonResourcesPackFd(
2396 &(*regions
)[kAndroidChrome100PercentPakDescriptor
]);
2397 mappings
->Share(kAndroidChrome100PercentPakDescriptor
, fd
);
2399 fd
= ui::GetLocalePackFd(&(*regions
)[kAndroidLocalePakDescriptor
]);
2400 mappings
->Share(kAndroidLocalePakDescriptor
, fd
);
2402 if (breakpad::IsCrashReporterEnabled()) {
2404 breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile(
2406 if (file
.IsValid()) {
2407 mappings
->Transfer(kAndroidMinidumpDescriptor
,
2408 base::ScopedFD(file
.TakePlatformFile()));
2410 LOG(ERROR
) << "Failed to create file for minidump, crash reporting will "
2411 "be disabled for this process.";
2415 base::FilePath app_data_path
;
2416 PathService::Get(base::DIR_ANDROID_APP_DATA
, &app_data_path
);
2417 DCHECK(!app_data_path
.empty());
2419 #elif defined(OS_POSIX) && !defined(OS_MACOSX)
2420 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2421 const base::CommandLine
& command_line
,
2422 int child_process_id
,
2423 FileDescriptorInfo
* mappings
) {
2424 int crash_signal_fd
= GetCrashSignalFD(command_line
);
2425 if (crash_signal_fd
>= 0) {
2426 mappings
->Share(kCrashDumpSignal
, crash_signal_fd
);
2429 #endif // defined(OS_ANDROID)
2432 const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2433 return chrome::kBrowserResourcesDll
;
2436 base::string16
ChromeContentBrowserClient::GetAppContainerSidForSandboxType(
2437 int sandbox_type
) const {
2440 #if defined(GOOGLE_CHROME_BUILD)
2441 const version_info::Channel channel
= chrome::GetChannel();
2443 // It's possible to have a SxS installation running at the same time as a
2444 // non-SxS so isolate them from each other.
2445 if (channel
== version_info::Channel::CANARY
) {
2447 L
"S-1-15-2-3251537155-1984446955-2931258699-841473695-1938553385-"
2451 L
"S-1-15-2-3251537155-1984446955-2931258699-841473695-1938553385-"
2456 L
"S-1-15-2-3251537155-1984446955-2931258699-841473695-1938553385-"
2460 // TODO(wfh): Add support for more process types here. crbug.com/499523
2461 switch (sandbox_type
) {
2462 case content::SANDBOX_TYPE_RENDERER
:
2463 return sid
+ L
"129201922";
2464 case content::SANDBOX_TYPE_UTILITY
:
2465 return base::string16();
2466 case content::SANDBOX_TYPE_GPU
:
2467 return base::string16();
2468 case content::SANDBOX_TYPE_PPAPI
:
2469 return sid
+ L
"129201925";
2470 #if !defined(DISABLE_NACL)
2471 case PROCESS_TYPE_NACL_LOADER
:
2472 return base::string16();
2473 case PROCESS_TYPE_NACL_BROKER
:
2474 return base::string16();
2478 // Should never reach here.
2480 return base::string16();
2483 void ChromeContentBrowserClient::PreSpawnRenderer(
2484 sandbox::TargetPolicy
* policy
,
2486 // This code is duplicated in nacl_exe_win_64.cc.
2487 // Allow the server side of a pipe restricted to the "chrome.nacl."
2488 // namespace so that it cannot impersonate other system or other chrome
2490 sandbox::ResultCode result
= policy
->AddRule(
2491 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES
,
2492 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY
,
2493 L
"\\\\.\\pipe\\chrome.nacl.*");
2494 if (result
!= sandbox::SBOX_ALL_OK
) {
2499 // Renderers need to send named pipe handles and shared memory
2500 // segment handles to NaCl loader processes.
2501 result
= policy
->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES
,
2502 sandbox::TargetPolicy::HANDLES_DUP_ANY
,
2504 if (result
!= sandbox::SBOX_ALL_OK
) {
2511 void ChromeContentBrowserClient::RegisterFrameMojoShellServices(
2512 content::ServiceRegistry
* registry
,
2513 content::RenderFrameHost
* render_frame_host
) {
2514 #if defined(OS_CHROMEOS)
2515 registry
->AddService(
2516 base::Bind(&chromeos::attestation::PlatformVerificationImpl::Create
,
2517 render_frame_host
));
2521 void ChromeContentBrowserClient::RegisterInProcessMojoApplications(
2522 StaticMojoApplicationMap
* apps
) {
2523 #if !defined(OS_ANDROID) && !defined(OS_IOS)
2524 apps
->insert(std::make_pair(GURL(device::kDevicesMojoAppUrl
),
2525 base::Bind(&device::DevicesAppFactory::CreateApp
,
2526 base::ThreadTaskRunnerHandle::Get())));
2530 void ChromeContentBrowserClient::OpenURL(
2531 content::BrowserContext
* browser_context
,
2532 const content::OpenURLParams
& params
,
2533 const base::Callback
<void(content::WebContents
*)>& callback
) {
2534 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
2536 #if !defined(OS_ANDROID) && !defined(OS_IOS)
2537 NavigateParams
nav_params(Profile::FromBrowserContext(browser_context
),
2540 FillNavigateParamsFromOpenURLParams(&nav_params
, params
);
2541 nav_params
.user_gesture
= params
.user_gesture
;
2543 Navigate(&nav_params
);
2544 callback
.Run(nav_params
.target_contents
);
2545 #elif defined(OS_ANDROID)
2546 service_tab_launcher::ServiceTabLauncher::GetInstance()->LaunchTab(
2547 browser_context
, params
, callback
);
2553 content::PresentationServiceDelegate
*
2554 ChromeContentBrowserClient::GetPresentationServiceDelegate(
2555 content::WebContents
* web_contents
) {
2556 #if defined(ENABLE_MEDIA_ROUTER)
2557 if (switches::MediaRouterEnabled() &&
2558 !web_contents
->GetBrowserContext()->IsOffTheRecord()) {
2559 return media_router::PresentationServiceDelegateImpl::
2560 GetOrCreateForWebContents(web_contents
);
2566 void ChromeContentBrowserClient::RecordURLMetric(const std::string
& metric
,
2568 if (url
.is_valid()) {
2569 rappor::SampleDomainAndRegistryFromGURL(g_browser_process
->rappor_service(),
2574 content::DevToolsManagerDelegate
*
2575 ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
2576 return new ChromeDevToolsManagerDelegate();
2579 content::TracingDelegate
* ChromeContentBrowserClient::GetTracingDelegate() {
2580 #if !defined(OS_ANDROID)
2581 return new ChromeTracingDelegate();
2587 bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2588 content::BrowserContext
* browser_context
,
2590 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2591 return ChromeContentBrowserClientPluginsPart::
2592 IsPluginAllowedToCallRequestOSFileHandle(browser_context
, url
,
2593 allowed_file_handle_origins_
);
2599 bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
2600 content::BrowserContext
* browser_context
,
2602 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2603 return ChromeContentBrowserClientPluginsPart::
2604 IsPluginAllowedToUseDevChannelAPIs(browser_context
, url
,
2605 allowed_dev_channel_origins_
);
2611 void ChromeContentBrowserClient::OverridePageVisibilityState(
2612 RenderFrameHost
* render_frame_host
,
2613 blink::WebPageVisibilityState
* visibility_state
) {
2614 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
2616 WebContents
* web_contents
=
2617 WebContents::FromRenderFrameHost(render_frame_host
);
2618 DCHECK(web_contents
);
2621 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
2622 prerender::PrerenderManager
* prerender_manager
=
2623 prerender::PrerenderManagerFactory::GetForProfile(profile
);
2624 if (prerender_manager
&&
2625 prerender_manager
->IsWebContentsPrerendering(web_contents
, nullptr)) {
2626 *visibility_state
= blink::WebPageVisibilityStatePrerender
;
2630 #if defined(ENABLE_WEBRTC)
2631 void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
2632 base::CommandLine
* to_command_line
,
2633 const base::CommandLine
& from_command_line
,
2634 version_info::Channel channel
) {
2635 #if defined(OS_ANDROID)
2636 const version_info::Channel kMaxDisableEncryptionChannel
=
2637 version_info::Channel::BETA
;
2639 const version_info::Channel kMaxDisableEncryptionChannel
=
2640 version_info::Channel::DEV
;
2642 if (channel
<= kMaxDisableEncryptionChannel
) {
2643 static const char* const kWebRtcDevSwitchNames
[] = {
2644 switches::kDisableWebRtcEncryption
,
2646 to_command_line
->CopySwitchesFrom(from_command_line
,
2647 kWebRtcDevSwitchNames
,
2648 arraysize(kWebRtcDevSwitchNames
));
2651 #endif // defined(ENABLE_WEBRTC)
2653 } // namespace chrome