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"
11 #include "base/bind.h"
12 #include "base/command_line.h"
13 #include "base/files/scoped_file.h"
14 #include "base/i18n/icu_util.h"
15 #include "base/lazy_instance.h"
16 #include "base/path_service.h"
17 #include "base/prefs/pref_service.h"
18 #include "base/prefs/scoped_user_pref_update.h"
19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/utf_string_conversions.h"
21 #include "base/threading/sequenced_worker_pool.h"
22 #include "chrome/browser/browser_about_handler.h"
23 #include "chrome/browser/browser_process.h"
24 #include "chrome/browser/browser_shutdown.h"
25 #include "chrome/browser/browsing_data/browsing_data_helper.h"
26 #include "chrome/browser/browsing_data/browsing_data_remover.h"
27 #include "chrome/browser/character_encoding.h"
28 #include "chrome/browser/chrome_content_browser_client_parts.h"
29 #include "chrome/browser/chrome_net_benchmarking_message_filter.h"
30 #include "chrome/browser/chrome_quota_permission_context.h"
31 #include "chrome/browser/content_settings/cookie_settings.h"
32 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
33 #include "chrome/browser/defaults.h"
34 #include "chrome/browser/download/download_prefs.h"
35 #include "chrome/browser/font_family_cache.h"
36 #include "chrome/browser/geolocation/chrome_access_token_store.h"
37 #include "chrome/browser/geolocation/geolocation_permission_context.h"
38 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h"
39 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
40 #include "chrome/browser/media/midi_permission_context.h"
41 #include "chrome/browser/media/midi_permission_context_factory.h"
42 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
43 #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
44 #include "chrome/browser/net/chrome_net_log.h"
45 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
46 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h"
47 #include "chrome/browser/notifications/desktop_notification_service.h"
48 #include "chrome/browser/notifications/desktop_notification_service_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/push_messaging/push_messaging_permission_context.h"
60 #include "chrome/browser/push_messaging/push_messaging_permission_context_factory.h"
61 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
62 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.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_client_certificate_selector.h"
73 #include "chrome/browser/ssl/ssl_error_handler.h"
74 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
75 #include "chrome/browser/tab_contents/tab_util.h"
76 #include "chrome/browser/tracing/chrome_tracing_delegate.h"
77 #include "chrome/browser/ui/blocked_content/blocked_window_params.h"
78 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
79 #include "chrome/browser/ui/chrome_select_file_policy.h"
80 #include "chrome/browser/ui/sync/sync_promo_ui.h"
81 #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
82 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
83 #include "chrome/common/chrome_constants.h"
84 #include "chrome/common/chrome_paths.h"
85 #include "chrome/common/chrome_switches.h"
86 #include "chrome/common/env_vars.h"
87 #include "chrome/common/logging_chrome.h"
88 #include "chrome/common/pepper_permission_util.h"
89 #include "chrome/common/pref_names.h"
90 #include "chrome/common/render_messages.h"
91 #include "chrome/common/url_constants.h"
92 #include "chrome/grit/generated_resources.h"
93 #include "chrome/installer/util/google_update_settings.h"
94 #include "chromeos/chromeos_constants.h"
95 #include "components/cdm/browser/cdm_message_filter_android.h"
96 #include "components/cloud_devices/common/cloud_devices_switches.h"
97 #include "components/content_settings/core/browser/content_settings_provider.h"
98 #include "components/content_settings/core/browser/content_settings_utils.h"
99 #include "components/content_settings/core/browser/host_content_settings_map.h"
100 #include "components/content_settings/core/common/content_settings.h"
101 #include "components/content_settings/core/common/permission_request_id.h"
102 #include "components/data_reduction_proxy/content/browser/data_reduction_proxy_message_filter.h"
103 #include "components/dom_distiller/core/url_constants.h"
104 #include "components/google/core/browser/google_util.h"
105 #include "components/metrics/client_info.h"
106 #include "components/pref_registry/pref_registry_syncable.h"
107 #include "components/rappor/rappor_utils.h"
108 #include "components/signin/core/common/profile_management_switches.h"
109 #include "components/translate/core/common/translate_switches.h"
110 #include "components/url_fixer/url_fixer.h"
111 #include "content/public/browser/browser_child_process_host.h"
112 #include "content/public/browser/browser_main_parts.h"
113 #include "content/public/browser/browser_ppapi_host.h"
114 #include "content/public/browser/browser_thread.h"
115 #include "content/public/browser/browser_url_handler.h"
116 #include "content/public/browser/child_process_data.h"
117 #include "content/public/browser/child_process_security_policy.h"
118 #include "content/public/browser/client_certificate_delegate.h"
119 #include "content/public/browser/permission_type.h"
120 #include "content/public/browser/render_frame_host.h"
121 #include "content/public/browser/render_process_host.h"
122 #include "content/public/browser/render_view_host.h"
123 #include "content/public/browser/resource_context.h"
124 #include "content/public/browser/site_instance.h"
125 #include "content/public/browser/web_contents.h"
126 #include "content/public/common/child_process_host.h"
127 #include "content/public/common/content_descriptors.h"
128 #include "content/public/common/url_utils.h"
129 #include "content/public/common/web_preferences.h"
130 #include "gin/public/isolate_holder.h"
131 #include "net/base/mime_util.h"
132 #include "net/cookies/canonical_cookie.h"
133 #include "net/cookies/cookie_options.h"
134 #include "net/ssl/ssl_cert_request_info.h"
135 #include "ppapi/host/ppapi_host.h"
136 #include "storage/browser/fileapi/external_mount_points.h"
137 #include "ui/base/l10n/l10n_util.h"
138 #include "ui/base/resource/resource_bundle.h"
139 #include "ui/resources/grit/ui_resources.h"
142 #include "base/win/windows_version.h"
143 #include "chrome/browser/chrome_browser_main_win.h"
144 #include "sandbox/win/src/sandbox_policy.h"
145 #elif defined(OS_MACOSX)
146 #include "chrome/browser/chrome_browser_main_mac.h"
147 #include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
148 #elif defined(OS_CHROMEOS)
149 #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
150 #include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h"
151 #include "chrome/browser/chromeos/file_manager/app_id.h"
152 #include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
153 #include "chrome/browser/chromeos/fileapi/file_system_backend.h"
154 #include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
155 #include "chrome/browser/chromeos/login/startup_utils.h"
156 #include "chrome/browser/chromeos/system/input_device_settings.h"
157 #include "chromeos/chromeos_switches.h"
158 #include "components/user_manager/user_manager.h"
159 #elif defined(OS_LINUX)
160 #include "chrome/browser/chrome_browser_main_linux.h"
161 #elif defined(OS_ANDROID)
162 #include "chrome/browser/android/new_tab_page_url_handler.h"
163 #include "chrome/browser/android/service_tab_launcher.h"
164 #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
165 #include "chrome/browser/chrome_browser_main_android.h"
166 #include "chrome/common/descriptors_android.h"
167 #include "components/crash/browser/crash_dump_manager_android.h"
168 #elif defined(OS_POSIX)
169 #include "chrome/browser/chrome_browser_main_posix.h"
172 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
173 #include "chrome/browser/media/protected_media_identifier_permission_context.h"
174 #include "chrome/browser/media/protected_media_identifier_permission_context_factory.h"
177 #if defined(OS_POSIX) && !defined(OS_MACOSX)
178 #include "base/debug/leak_annotations.h"
179 #include "components/crash/app/breakpad_linux.h"
180 #include "components/crash/browser/crash_handler_host_linux.h"
183 #if defined(OS_ANDROID)
184 #include "ui/base/ui_base_paths.h"
185 #include "ui/gfx/android/device_display_info.h"
188 #if defined(OS_ANDROID)
189 #include "chrome/browser/android/dev_tools_manager_delegate_android.h"
191 #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
194 #if defined(TOOLKIT_VIEWS)
195 #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
199 #include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
202 #if defined(USE_AURA)
203 #include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
207 #include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
210 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
211 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
214 #if !defined(DISABLE_NACL)
215 #include "components/nacl/browser/nacl_browser.h"
216 #include "components/nacl/browser/nacl_host_message_filter.h"
217 #include "components/nacl/browser/nacl_process_host.h"
218 #include "components/nacl/common/nacl_process_type.h"
219 #include "components/nacl/common/nacl_switches.h"
222 #if defined(ENABLE_EXTENSIONS)
223 #include "chrome/browser/accessibility/animation_policy_prefs.h"
224 #include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
225 #include "chrome/browser/extensions/extension_util.h"
226 #include "chrome/browser/media/cast_transport_host_filter.h"
227 #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
228 #include "extensions/browser/extension_registry.h"
229 #include "extensions/browser/guest_view/guest_view_base.h"
230 #include "extensions/browser/guest_view/guest_view_manager.h"
231 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
232 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
233 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
234 #include "extensions/common/constants.h"
235 #include "extensions/common/extension.h"
236 #include "extensions/common/extension_set.h"
237 #include "extensions/common/manifest_handlers/background_info.h"
238 #include "extensions/common/manifest_handlers/shared_module_info.h"
239 #include "extensions/common/permissions/permissions_data.h"
240 #include "extensions/common/permissions/socket_permission.h"
241 #include "extensions/common/switches.h"
244 #if defined(ENABLE_PLUGINS)
245 #include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
248 #if defined(ENABLE_SPELLCHECK)
249 #include "chrome/browser/spellchecker/spellcheck_message_filter.h"
252 #if defined(ENABLE_WEBRTC)
253 #include "chrome/browser/media/webrtc_logging_handler_host.h"
256 using base::FileDescriptor
;
257 using blink::WebWindowFeatures
;
258 using content::AccessTokenStore
;
259 using content::BrowserThread
;
260 using content::BrowserURLHandler
;
261 using content::ChildProcessSecurityPolicy
;
262 using content::QuotaPermissionContext
;
263 using content::RenderFrameHost
;
264 using content::RenderViewHost
;
265 using content::ResourceType
;
266 using content::SiteInstance
;
267 using content::WebContents
;
268 using content::WebPreferences
;
269 using message_center::NotifierId
;
271 #if defined(OS_POSIX)
272 using content::FileDescriptorInfo
;
275 #if defined(ENABLE_EXTENSIONS)
276 using extensions::APIPermission
;
277 using extensions::ChromeContentBrowserClientExtensionsPart
;
278 using extensions::Extension
;
279 using extensions::InfoMap
;
280 using extensions::Manifest
;
283 #if defined(ENABLE_PLUGINS)
284 using plugins::ChromeContentBrowserClientPluginsPart
;
289 // Cached version of the locale so we can return the locale on the I/O
291 base::LazyInstance
<std::string
> g_io_thread_application_locale
;
293 #if defined(ENABLE_PLUGINS)
294 // TODO(teravest): Add renderer-side API-specific checking for these APIs so
295 // that blanket permission isn't granted to all dev channel APIs for these.
296 // http://crbug.com/386743
297 const char* const kPredefinedAllowedDevChannelOrigins
[] = {
298 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/383937
299 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/383937
302 const char* const kPredefinedAllowedFileHandleOrigins
[] = {
303 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
304 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
307 const char* const kPredefinedAllowedSocketOrigins
[] = {
308 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
309 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
310 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
311 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
312 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
313 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
314 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
315 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
316 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
317 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
318 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
319 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
320 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
321 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
322 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
323 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
324 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
325 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
326 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
327 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
331 // Returns a copy of the given url with its host set to given host and path set
332 // to given path. Other parts of the url will be the same.
333 GURL
ReplaceURLHostAndPath(const GURL
& url
,
334 const std::string
& host
,
335 const std::string
& path
) {
336 url::Replacements
<char> replacements
;
337 replacements
.SetHost(host
.c_str(), url::Component(0, host
.length()));
338 replacements
.SetPath(path
.c_str(), url::Component(0, path
.length()));
339 return url
.ReplaceComponents(replacements
);
342 // Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
343 GURL
AddUberHost(const GURL
& url
) {
344 const std::string uber_host
= chrome::kChromeUIUberHost
;
345 const std::string new_path
= url
.host() + url
.path();
347 return ReplaceURLHostAndPath(url
, uber_host
, new_path
);
350 // If url->host() is "chrome" and url->path() has characters other than the
351 // first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
352 // returns true. Otherwise returns false.
353 bool RemoveUberHost(GURL
* url
) {
354 if (url
->host() != chrome::kChromeUIUberHost
)
357 if (url
->path().empty() || url
->path() == "/")
360 const std::string old_path
= url
->path();
362 const std::string::size_type separator
= old_path
.find('/', 1);
363 std::string new_host
;
364 std::string new_path
;
365 if (separator
== std::string::npos
) {
366 new_host
= old_path
.substr(1);
368 new_host
= old_path
.substr(1, separator
- 1);
369 new_path
= old_path
.substr(separator
);
372 // Do not allow URLs with paths empty before the first slash since we can't
373 // have an empty host. (e.g "foo://chrome//")
374 if (new_host
.empty())
377 *url
= ReplaceURLHostAndPath(*url
, new_host
, new_path
);
379 DCHECK(url
->is_valid());
384 // Handles rewriting Web UI URLs.
385 bool HandleWebUI(GURL
* url
, content::BrowserContext
* browser_context
) {
386 // Do not handle special URLs such as "about:foo"
387 if (!url
->host().empty()) {
388 const GURL chrome_url
= AddUberHost(*url
);
390 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
392 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
393 browser_context
, chrome_url
))
397 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
398 browser_context
, *url
))
401 #if defined(OS_CHROMEOS)
402 // Special case : in ChromeOS in Guest mode bookmarks and history are
403 // disabled for security reasons. New tab page explains the reasons, so
404 // we redirect user to new tab page.
405 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
406 if (url
->SchemeIs(content::kChromeUIScheme
) &&
407 (url
->DomainIs(chrome::kChromeUIBookmarksHost
) ||
408 url
->DomainIs(chrome::kChromeUIHistoryHost
))) {
409 // Rewrite with new tab URL
410 *url
= GURL(chrome::kChromeUINewTabURL
);
418 // Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
420 bool HandleWebUIReverse(GURL
* url
, content::BrowserContext
* browser_context
) {
421 if (!url
->is_valid() || !url
->SchemeIs(content::kChromeUIScheme
))
424 return RemoveUberHost(url
);
427 bool CertMatchesFilter(const net::X509Certificate
& cert
,
428 const base::DictionaryValue
& filter
) {
429 // TODO(markusheintz): This is the minimal required filter implementation.
430 // Implement a better matcher.
432 // An empty filter matches any client certificate since no requirements are
437 std::string common_name
;
438 if (filter
.GetString("ISSUER.CN", &common_name
) &&
439 (cert
.issuer().common_name
== common_name
)) {
445 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
446 breakpad::CrashHandlerHostLinux
* CreateCrashHandlerHost(
447 const std::string
& process_type
) {
448 base::FilePath dumps_path
;
449 PathService::Get(chrome::DIR_CRASH_DUMPS
, &dumps_path
);
451 ANNOTATE_SCOPED_MEMORY_LEAK
;
452 bool upload
= (getenv(env_vars::kHeadless
) == NULL
);
453 breakpad::CrashHandlerHostLinux
* crash_handler
=
454 new breakpad::CrashHandlerHostLinux(process_type
, dumps_path
, upload
);
455 crash_handler
->StartUploaderThread();
456 return crash_handler
;
460 int GetCrashSignalFD(const base::CommandLine
& command_line
) {
461 // Extensions have the same process type as renderers.
462 if (command_line
.HasSwitch(extensions::switches::kExtensionProcess
)) {
463 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
465 crash_handler
= CreateCrashHandlerHost("extension");
466 return crash_handler
->GetDeathSignalSocket();
469 std::string process_type
=
470 command_line
.GetSwitchValueASCII(switches::kProcessType
);
472 if (process_type
== switches::kRendererProcess
) {
473 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
475 crash_handler
= CreateCrashHandlerHost(process_type
);
476 return crash_handler
->GetDeathSignalSocket();
479 if (process_type
== switches::kPluginProcess
) {
480 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
482 crash_handler
= CreateCrashHandlerHost(process_type
);
483 return crash_handler
->GetDeathSignalSocket();
486 if (process_type
== switches::kPpapiPluginProcess
) {
487 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
489 crash_handler
= CreateCrashHandlerHost(process_type
);
490 return crash_handler
->GetDeathSignalSocket();
493 if (process_type
== switches::kGpuProcess
) {
494 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
496 crash_handler
= CreateCrashHandlerHost(process_type
);
497 return crash_handler
->GetDeathSignalSocket();
502 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
504 void SetApplicationLocaleOnIOThread(const std::string
& locale
) {
505 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
506 g_io_thread_application_locale
.Get() = locale
;
509 void HandleBlockedPopupOnUIThread(const BlockedWindowParams
& params
) {
510 // TODO(jochen): This code path should use RenderFrameHosts. See
511 // http://crbug.com/431769 for details.
512 RenderViewHost
* render_view_host
=
513 RenderViewHost::FromID(params
.render_process_id(), params
.opener_id());
514 if (!render_view_host
)
516 WebContents
* tab
= WebContents::FromRenderViewHost(render_view_host
);
517 // The tab might already have navigated away.
518 if (!tab
|| tab
->GetRenderViewHost() != render_view_host
)
521 prerender::PrerenderContents
* prerender_contents
=
522 prerender::PrerenderContents::FromWebContents(tab
);
523 if (prerender_contents
) {
524 prerender_contents
->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW
);
528 PopupBlockerTabHelper
* popup_helper
=
529 PopupBlockerTabHelper::FromWebContents(tab
);
532 popup_helper
->AddBlockedPopup(params
);
535 #if defined(OS_ANDROID)
537 void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams
& params
) {
538 WebContents
* web_contents
=
539 tab_util::GetWebContentsByID(params
.render_process_id(),
544 SingleTabModeTabHelper::FromWebContents(web_contents
)->HandleOpenUrl(params
);
547 float GetDeviceScaleAdjustment() {
548 static const float kMinFSM
= 1.05f
;
549 static const int kWidthForMinFSM
= 320;
550 static const float kMaxFSM
= 1.3f
;
551 static const int kWidthForMaxFSM
= 800;
553 gfx::DeviceDisplayInfo info
;
554 int minWidth
= info
.GetSmallestDIPWidth();
556 if (minWidth
<= kWidthForMinFSM
)
558 if (minWidth
>= kWidthForMaxFSM
)
561 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
562 float ratio
= static_cast<float>(minWidth
- kWidthForMinFSM
) /
563 (kWidthForMaxFSM
- kWidthForMinFSM
);
564 return ratio
* (kMaxFSM
- kMinFSM
) + kMinFSM
;
567 #endif // defined(OS_ANDROID)
569 #if defined(ENABLE_EXTENSIONS)
570 // By default, JavaScript and images are enabled in guest content.
571 void GetGuestViewDefaultContentSettingRules(
573 RendererContentSettingRules
* rules
) {
574 rules
->image_rules
.push_back(
575 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
576 ContentSettingsPattern::Wildcard(),
577 CONTENT_SETTING_ALLOW
,
581 rules
->script_rules
.push_back(
582 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
583 ContentSettingsPattern::Wildcard(),
584 CONTENT_SETTING_ALLOW
,
588 #endif // defined(ENALBE_EXTENSIONS)
590 content::PermissionStatus
591 ContentSettingToPermissionStatus(ContentSetting setting
) {
593 case CONTENT_SETTING_ALLOW
:
594 case CONTENT_SETTING_SESSION_ONLY
:
595 return content::PERMISSION_STATUS_GRANTED
;
596 case CONTENT_SETTING_BLOCK
:
597 return content::PERMISSION_STATUS_DENIED
;
598 case CONTENT_SETTING_ASK
:
599 return content::PERMISSION_STATUS_ASK
;
600 case CONTENT_SETTING_DETECT_IMPORTANT_CONTENT
:
601 case CONTENT_SETTING_DEFAULT
:
602 case CONTENT_SETTING_NUM_SETTINGS
:
606 return content::PERMISSION_STATUS_DENIED
;
609 PermissionContextBase
* GetPermissionContext(Profile
* profile
,
610 content::PermissionType permission
) {
611 switch (permission
) {
612 case content::PERMISSION_MIDI_SYSEX
:
613 return MidiPermissionContextFactory::GetForProfile(profile
);
614 case content::PERMISSION_NOTIFICATIONS
:
615 #if defined(ENABLE_NOTIFICATIONS)
616 return DesktopNotificationServiceFactory::GetForProfile(profile
);
621 case content::PERMISSION_GEOLOCATION
:
622 return GeolocationPermissionContextFactory::GetForProfile(profile
);
623 case content::PERMISSION_PROTECTED_MEDIA_IDENTIFIER
:
624 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
625 return ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(
631 case content::PERMISSION_PUSH_MESSAGING
:
632 return PushMessagingPermissionContextFactory::GetForProfile(profile
);
633 case content::PERMISSION_NUM
:
634 NOTREACHED() << "Invalid RequestPermission for " << permission
;
640 // Helper method to translate from Permissions to ContentSettings
641 ContentSettingsType
PermissionToContentSetting(
642 content::PermissionType permission
) {
643 switch (permission
) {
644 case content::PERMISSION_MIDI_SYSEX
:
645 return CONTENT_SETTINGS_TYPE_MIDI_SYSEX
;
646 case content::PERMISSION_PUSH_MESSAGING
:
647 return CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
;
648 case content::PERMISSION_NOTIFICATIONS
:
649 return CONTENT_SETTINGS_TYPE_NOTIFICATIONS
;
650 case content::PERMISSION_GEOLOCATION
:
651 return CONTENT_SETTINGS_TYPE_GEOLOCATION
;
652 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
653 case content::PERMISSION_PROTECTED_MEDIA_IDENTIFIER
:
654 return CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER
;
657 NOTREACHED() << "Unknown content setting for permission " << permission
;
658 return CONTENT_SETTINGS_TYPE_DEFAULT
;
662 void OnRequestPermission(
663 const base::Callback
<void(content::PermissionStatus
)>& callback
,
664 ContentSetting content_setting
) {
665 callback
.Run(ContentSettingToPermissionStatus(content_setting
));
672 ChromeContentBrowserClient::ChromeContentBrowserClient()
674 #if defined(OS_POSIX) && !defined(OS_MACOSX)
677 #endif // OS_POSIX && !OS_MACOSX
678 weak_factory_(this) {
679 #if defined(ENABLE_PLUGINS)
680 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedDevChannelOrigins
); ++i
)
681 allowed_dev_channel_origins_
.insert(kPredefinedAllowedDevChannelOrigins
[i
]);
682 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedFileHandleOrigins
); ++i
)
683 allowed_file_handle_origins_
.insert(kPredefinedAllowedFileHandleOrigins
[i
]);
684 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedSocketOrigins
); ++i
)
685 allowed_socket_origins_
.insert(kPredefinedAllowedSocketOrigins
[i
]);
687 extra_parts_
.push_back(new ChromeContentBrowserClientPluginsPart
);
690 #if !defined(OS_ANDROID)
691 TtsExtensionEngine
* tts_extension_engine
= TtsExtensionEngine::GetInstance();
692 TtsController::GetInstance()->SetTtsEngineDelegate(tts_extension_engine
);
695 #if defined(ENABLE_EXTENSIONS)
696 extra_parts_
.push_back(new ChromeContentBrowserClientExtensionsPart
);
700 ChromeContentBrowserClient::~ChromeContentBrowserClient() {
701 for (int i
= static_cast<int>(extra_parts_
.size()) - 1; i
>= 0; --i
)
702 delete extra_parts_
[i
];
703 extra_parts_
.clear();
707 void ChromeContentBrowserClient::RegisterProfilePrefs(
708 user_prefs::PrefRegistrySyncable
* registry
) {
709 registry
->RegisterBooleanPref(
710 prefs::kDisable3DAPIs
,
712 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
713 registry
->RegisterBooleanPref(
714 prefs::kEnableHyperlinkAuditing
,
716 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
717 registry
->RegisterListPref(
718 prefs::kEnableDeprecatedWebPlatformFeatures
,
719 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
723 void ChromeContentBrowserClient::SetApplicationLocale(
724 const std::string
& locale
) {
725 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
727 // This object is guaranteed to outlive all threads so we don't have to
728 // worry about the lack of refcounting and can just post as Unretained.
730 // The common case is that this function is called early in Chrome startup
731 // before any threads are created (it will also be called later if the user
732 // changes the pref). In this case, there will be no threads created and
733 // posting will fail. When there are no threads, we can just set the string
734 // without worrying about threadsafety.
735 if (!BrowserThread::PostTask(BrowserThread::IO
, FROM_HERE
,
736 base::Bind(&SetApplicationLocaleOnIOThread
, locale
))) {
737 g_io_thread_application_locale
.Get() = locale
;
741 content::BrowserMainParts
* ChromeContentBrowserClient::CreateBrowserMainParts(
742 const content::MainFunctionParams
& parameters
) {
743 ChromeBrowserMainParts
* main_parts
;
744 // Construct the Main browser parts based on the OS type.
746 main_parts
= new ChromeBrowserMainPartsWin(parameters
);
747 #elif defined(OS_MACOSX)
748 main_parts
= new ChromeBrowserMainPartsMac(parameters
);
749 #elif defined(OS_CHROMEOS)
750 main_parts
= new chromeos::ChromeBrowserMainPartsChromeos(parameters
);
751 #elif defined(OS_LINUX)
752 main_parts
= new ChromeBrowserMainPartsLinux(parameters
);
753 #elif defined(OS_ANDROID)
754 main_parts
= new ChromeBrowserMainPartsAndroid(parameters
);
755 #elif defined(OS_POSIX)
756 main_parts
= new ChromeBrowserMainPartsPosix(parameters
);
759 main_parts
= new ChromeBrowserMainParts(parameters
);
762 chrome::AddProfilesExtraParts(main_parts
);
764 // Construct additional browser parts. Stages are called in the order in
765 // which they are added.
766 #if defined(TOOLKIT_VIEWS)
767 main_parts
->AddParts(new ChromeBrowserMainExtraPartsViews());
770 // TODO(oshima): Athena on chrome currently requires USE_ASH to build.
771 // We should reduce the dependency as much as possible.
773 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAsh());
776 #if defined(USE_AURA)
777 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAura());
781 main_parts
->AddParts(new ChromeBrowserMainExtraPartsX11());
784 chrome::AddMetricsExtraParts(main_parts
);
789 std::string
ChromeContentBrowserClient::GetStoragePartitionIdForSite(
790 content::BrowserContext
* browser_context
,
792 std::string partition_id
;
794 // The partition ID for webview guest processes is the string value of its
795 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
796 if (site
.SchemeIs(content::kGuestScheme
)) {
797 partition_id
= site
.spec();
798 } else if (!switches::IsEnableWebviewBasedSignin() &&
799 site
.GetOrigin().spec() == kChromeUIChromeSigninURL
) {
800 // The non-webview Chrome signin page has an embedded iframe of extension
801 // and web content, thus it must be isolated from other webUI pages.
802 partition_id
= site
.GetOrigin().spec();
805 DCHECK(IsValidStoragePartitionId(browser_context
, partition_id
));
809 bool ChromeContentBrowserClient::IsValidStoragePartitionId(
810 content::BrowserContext
* browser_context
,
811 const std::string
& partition_id
) {
812 // The default ID is empty and is always valid.
813 if (partition_id
.empty())
816 return GURL(partition_id
).is_valid();
819 void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
820 content::BrowserContext
* browser_context
,
823 std::string
* partition_domain
,
824 std::string
* partition_name
,
826 // Default to the browser-wide storage partition and override based on |site|
828 partition_domain
->clear();
829 partition_name
->clear();
832 bool success
= false;
833 #if defined(ENABLE_EXTENSIONS)
834 success
= extensions::WebViewGuest::GetGuestPartitionConfigForSite(
835 site
, partition_domain
, partition_name
, in_memory
);
837 if (!success
&& site
.SchemeIs(extensions::kExtensionScheme
)) {
838 // If |can_be_default| is false, the caller is stating that the |site|
839 // should be parsed as if it had isolated storage. In particular it is
840 // important to NOT check ExtensionService for the is_storage_isolated()
841 // attribute because this code path is run during Extension uninstall
842 // to do cleanup after the Extension has already been unloaded from the
844 bool is_isolated
= !can_be_default
;
845 if (can_be_default
) {
846 if (extensions::util::SiteHasIsolatedStorage(site
, browser_context
))
851 CHECK(site
.has_host());
852 // For extensions with isolated storage, the the host of the |site| is
853 // the |partition_domain|. The |in_memory| and |partition_name| are only
854 // used in guest schemes so they are cleared here.
855 *partition_domain
= site
.host();
857 partition_name
->clear();
863 if (!success
&& (!switches::IsEnableWebviewBasedSignin() &&
864 site
.GetOrigin().spec() == kChromeUIChromeSigninURL
)) {
865 // The non-webview Chrome signin page has an embedded iframe of extension
866 // and web content, thus it must be isolated from other webUI pages.
867 *partition_domain
= chrome::kChromeUIChromeSigninHost
;
870 // Assert that if |can_be_default| is false, the code above must have found a
871 // non-default partition. If this fails, the caller has a serious logic
872 // error about which StoragePartition they expect to be in and it is not
874 CHECK(can_be_default
|| !partition_domain
->empty());
877 content::WebContentsViewDelegate
*
878 ChromeContentBrowserClient::GetWebContentsViewDelegate(
879 content::WebContents
* web_contents
) {
880 return chrome::CreateWebContentsViewDelegate(web_contents
);
883 void ChromeContentBrowserClient::RenderProcessWillLaunch(
884 content::RenderProcessHost
* host
) {
885 int id
= host
->GetID();
886 Profile
* profile
= Profile::FromBrowserContext(host
->GetBrowserContext());
887 net::URLRequestContextGetter
* context
=
888 profile
->GetRequestContextForRenderProcess(id
);
890 host
->AddFilter(new ChromeRenderMessageFilter(id
, profile
));
891 #if defined(ENABLE_EXTENSIONS)
892 host
->AddFilter(new cast::CastTransportHostFilter
);
894 #if defined(ENABLE_PRINTING)
895 host
->AddFilter(new printing::PrintingMessageFilter(id
, profile
));
897 host
->AddFilter(new SearchProviderInstallStateMessageFilter(id
, profile
));
898 #if defined(ENABLE_SPELLCHECK)
899 host
->AddFilter(new SpellCheckMessageFilter(id
));
901 #if defined(OS_MACOSX)
902 host
->AddFilter(new SpellCheckMessageFilterMac(id
));
904 host
->AddFilter(new ChromeNetBenchmarkingMessageFilter(profile
, context
));
905 host
->AddFilter(new prerender::PrerenderMessageFilter(id
, profile
));
906 host
->AddFilter(new TtsMessageFilter(id
, host
->GetBrowserContext()));
907 #if defined(ENABLE_WEBRTC)
908 WebRtcLoggingHandlerHost
* webrtc_logging_handler_host
=
909 new WebRtcLoggingHandlerHost(profile
);
910 host
->SetWebRtcLogMessageCallback(base::Bind(
911 &WebRtcLoggingHandlerHost::LogMessage
, webrtc_logging_handler_host
));
912 host
->AddFilter(webrtc_logging_handler_host
);
913 host
->SetUserData(host
, new base::UserDataAdapter
<WebRtcLoggingHandlerHost
>(
914 webrtc_logging_handler_host
));
916 #if !defined(DISABLE_NACL)
917 host
->AddFilter(new nacl::NaClHostMessageFilter(
918 id
, profile
->IsOffTheRecord(),
922 #if defined(OS_ANDROID)
923 host
->AddFilter(new cdm::CdmMessageFilterAndroid());
925 DataReductionProxyChromeSettings
* data_reduction_proxy_settings
=
926 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(profile
);
927 host
->AddFilter(new data_reduction_proxy::DataReductionProxyMessageFilter(
928 data_reduction_proxy_settings
));
930 host
->Send(new ChromeViewMsg_SetIsIncognitoProcess(
931 profile
->IsOffTheRecord()));
933 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
934 extra_parts_
[i
]->RenderProcessWillLaunch(host
);
936 RendererContentSettingRules rules
;
937 if (host
->IsIsolatedGuest()) {
938 #if defined(ENABLE_EXTENSIONS)
939 GetGuestViewDefaultContentSettingRules(profile
->IsOffTheRecord(), &rules
);
944 GetRendererContentSettingRules(
945 profile
->GetHostContentSettingsMap(), &rules
);
947 host
->Send(new ChromeViewMsg_SetContentSettingRules(rules
));
950 GURL
ChromeContentBrowserClient::GetEffectiveURL(
951 content::BrowserContext
* browser_context
, const GURL
& url
) {
952 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
956 // If the input |url| should be assigned to the Instant renderer, make its
957 // effective URL distinct from other URLs on the search provider's domain.
958 if (chrome::ShouldAssignURLToInstantRenderer(url
, profile
))
959 return chrome::GetEffectiveURLForInstant(url
, profile
);
961 #if defined(ENABLE_EXTENSIONS)
962 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(
969 bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
970 content::BrowserContext
* browser_context
, const GURL
& effective_url
) {
971 // Non-extension, non-Instant URLs should generally use
972 // process-per-site-instance. Because we expect to use the effective URL,
973 // URLs for hosted apps (apart from bookmark apps) should have an extension
976 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
980 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url
, profile
))
983 #if defined(ENABLE_EXTENSIONS)
984 return ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
985 profile
, effective_url
);
991 // These are treated as WebUI schemes but do not get WebUI bindings. Also,
992 // view-source is allowed for these schemes.
993 void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
994 std::vector
<std::string
>* additional_schemes
) {
995 additional_schemes
->push_back(chrome::kChromeSearchScheme
);
996 additional_schemes
->push_back(dom_distiller::kDomDistillerScheme
);
999 void ChromeContentBrowserClient::GetAdditionalWebUIHostsToIgnoreParititionCheck(
1000 std::vector
<std::string
>* hosts
) {
1001 hosts
->push_back(chrome::kChromeUIExtensionIconHost
);
1002 hosts
->push_back(chrome::kChromeUIFaviconHost
);
1003 hosts
->push_back(chrome::kChromeUIThemeHost
);
1004 hosts
->push_back(chrome::kChromeUIThumbnailHost
);
1005 hosts
->push_back(chrome::kChromeUIThumbnailHost2
);
1006 hosts
->push_back(chrome::kChromeUIThumbnailListHost
);
1009 net::URLRequestContextGetter
*
1010 ChromeContentBrowserClient::CreateRequestContext(
1011 content::BrowserContext
* browser_context
,
1012 content::ProtocolHandlerMap
* protocol_handlers
,
1013 content::URLRequestInterceptorScopedVector request_interceptors
) {
1014 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1015 return profile
->CreateRequestContext(protocol_handlers
,
1016 request_interceptors
.Pass());
1019 net::URLRequestContextGetter
*
1020 ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
1021 content::BrowserContext
* browser_context
,
1022 const base::FilePath
& partition_path
,
1024 content::ProtocolHandlerMap
* protocol_handlers
,
1025 content::URLRequestInterceptorScopedVector request_interceptors
) {
1026 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1027 return profile
->CreateRequestContextForStoragePartition(
1031 request_interceptors
.Pass());
1034 bool ChromeContentBrowserClient::IsHandledURL(const GURL
& url
) {
1035 return ProfileIOData::IsHandledURL(url
);
1038 bool ChromeContentBrowserClient::CanCommitURL(
1039 content::RenderProcessHost
* process_host
,
1041 #if defined(ENABLE_EXTENSIONS)
1042 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(
1049 bool ChromeContentBrowserClient::ShouldAllowOpenURL(
1050 content::SiteInstance
* site_instance
, const GURL
& url
) {
1051 GURL from_url
= site_instance
->GetSiteURL();
1053 #if defined(ENABLE_EXTENSIONS)
1055 if (ChromeContentBrowserClientExtensionsPart::ShouldAllowOpenURL(
1056 site_instance
, from_url
, url
, &result
))
1060 // Do not allow chrome://chrome-signin navigate to other chrome:// URLs, since
1061 // the signin page may host untrusted web content.
1062 if (from_url
.GetOrigin().spec() == chrome::kChromeUIChromeSigninURL
&&
1063 url
.SchemeIs(content::kChromeUIScheme
) &&
1064 url
.host() != chrome::kChromeUIChromeSigninHost
) {
1065 VLOG(1) << "Blocked navigation to " << url
.spec() << " from "
1066 << chrome::kChromeUIChromeSigninURL
;
1073 bool ChromeContentBrowserClient::IsSuitableHost(
1074 content::RenderProcessHost
* process_host
,
1075 const GURL
& site_url
) {
1077 Profile::FromBrowserContext(process_host
->GetBrowserContext());
1078 // This may be NULL during tests. In that case, just assume any site can
1083 // Instant URLs should only be in the instant process and instant process
1084 // should only have Instant URLs.
1085 InstantService
* instant_service
=
1086 InstantServiceFactory::GetForProfile(profile
);
1087 if (instant_service
) {
1088 bool is_instant_process
= instant_service
->IsInstantProcess(
1089 process_host
->GetID());
1090 bool should_be_in_instant_process
=
1091 chrome::ShouldAssignURLToInstantRenderer(site_url
, profile
);
1092 if (is_instant_process
|| should_be_in_instant_process
)
1093 return is_instant_process
&& should_be_in_instant_process
;
1096 #if defined(ENABLE_EXTENSIONS)
1097 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1098 profile
, process_host
, site_url
);
1104 bool ChromeContentBrowserClient::MayReuseHost(
1105 content::RenderProcessHost
* process_host
) {
1106 // If there is currently a prerender in progress for the host provided,
1107 // it may not be shared. We require prerenders to be by themselves in a
1108 // separate process so that we can monitor their resource usage.
1109 Profile
* profile
= Profile::FromBrowserContext(
1110 process_host
->GetBrowserContext());
1111 prerender::PrerenderManager
* prerender_manager
=
1112 prerender::PrerenderManagerFactory::GetForProfile(profile
);
1113 if (prerender_manager
&&
1114 !prerender_manager
->MayReuseProcessHost(process_host
)) {
1121 bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1122 content::BrowserContext
* browser_context
, const GURL
& url
) {
1123 // It has to be a valid URL for us to check for an extension.
1124 if (!url
.is_valid())
1127 #if defined(ENABLE_EXTENSIONS)
1128 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1129 return ChromeContentBrowserClientExtensionsPart::
1130 ShouldTryToUseExistingProcessHost(
1137 void ChromeContentBrowserClient::SiteInstanceGotProcess(
1138 SiteInstance
* site_instance
) {
1139 CHECK(site_instance
->HasProcess());
1141 Profile
* profile
= Profile::FromBrowserContext(
1142 site_instance
->GetBrowserContext());
1146 // Remember the ID of the Instant process to signal the renderer process
1147 // on startup in |AppendExtraCommandLineSwitches| below.
1148 if (chrome::ShouldAssignURLToInstantRenderer(
1149 site_instance
->GetSiteURL(), profile
)) {
1150 InstantService
* instant_service
=
1151 InstantServiceFactory::GetForProfile(profile
);
1152 if (instant_service
)
1153 instant_service
->AddInstantProcess(site_instance
->GetProcess()->GetID());
1156 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
1157 extra_parts_
[i
]->SiteInstanceGotProcess(site_instance
);
1160 void ChromeContentBrowserClient::SiteInstanceDeleting(
1161 SiteInstance
* site_instance
) {
1162 if (!site_instance
->HasProcess())
1165 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
1166 extra_parts_
[i
]->SiteInstanceDeleting(site_instance
);
1169 bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
1170 SiteInstance
* site_instance
,
1171 const GURL
& current_url
,
1172 const GURL
& new_url
) {
1173 #if defined(ENABLE_EXTENSIONS)
1174 return ChromeContentBrowserClientExtensionsPart::
1175 ShouldSwapBrowsingInstancesForNavigation(
1176 site_instance
, current_url
, new_url
);
1182 bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1183 content::ResourceContext
* resource_context
, const GURL
& current_url
,
1184 const GURL
& new_url
) {
1185 #if defined(ENABLE_EXTENSIONS)
1186 return ChromeContentBrowserClientExtensionsPart::
1187 ShouldSwapProcessesForRedirect(resource_context
, current_url
, new_url
);
1193 bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL
& url
) {
1194 return !url
.SchemeIs(chrome::kChromeNativeScheme
);
1197 std::string
ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1198 const std::string
& alias_name
) {
1199 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name
);
1204 bool IsAutoReloadEnabled() {
1205 // Fetch the field trial, even though we don't use it. Calling FindFullName()
1206 // causes the field-trial mechanism to report which group we're in, which
1207 // might reflect a hard disable or hard enable via flag, both of which have
1208 // their own field trial groups. This lets us know what percentage of users
1209 // manually enable or disable auto-reload.
1210 std::string group
= base::FieldTrialList::FindFullName(
1211 "AutoReloadExperiment");
1212 const base::CommandLine
& browser_command_line
=
1213 *base::CommandLine::ForCurrentProcess();
1214 if (browser_command_line
.HasSwitch(switches::kEnableOfflineAutoReload
))
1216 if (browser_command_line
.HasSwitch(switches::kDisableOfflineAutoReload
))
1221 bool IsAutoReloadVisibleOnlyEnabled() {
1222 // See the block comment in IsAutoReloadEnabled().
1223 std::string group
= base::FieldTrialList::FindFullName(
1224 "AutoReloadVisibleOnlyExperiment");
1225 const base::CommandLine
& browser_command_line
=
1226 *base::CommandLine::ForCurrentProcess();
1227 if (browser_command_line
.HasSwitch(
1228 switches::kEnableOfflineAutoReloadVisibleOnly
)) {
1231 if (browser_command_line
.HasSwitch(
1232 switches::kDisableOfflineAutoReloadVisibleOnly
)) {
1240 void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1241 base::CommandLine
* command_line
,
1242 int child_process_id
) {
1243 #if defined(OS_MACOSX)
1244 scoped_ptr
<metrics::ClientInfo
> client_info
=
1245 GoogleUpdateSettings::LoadMetricsClientInfo();
1247 command_line
->AppendSwitchASCII(switches::kMetricsClientID
,
1248 client_info
->client_id
);
1250 #elif defined(OS_POSIX)
1251 if (breakpad::IsCrashReporterEnabled()) {
1252 scoped_ptr
<metrics::ClientInfo
> client_info
=
1253 GoogleUpdateSettings::LoadMetricsClientInfo();
1254 command_line
->AppendSwitchASCII(switches::kEnableCrashReporter
,
1255 client_info
? client_info
->client_id
1260 if (logging::DialogsAreSuppressed())
1261 command_line
->AppendSwitch(switches::kNoErrorDialogs
);
1263 std::string process_type
=
1264 command_line
->GetSwitchValueASCII(switches::kProcessType
);
1265 const base::CommandLine
& browser_command_line
=
1266 *base::CommandLine::ForCurrentProcess();
1268 static const char* const kCommonSwitchNames
[] = {
1269 switches::kUserAgent
,
1270 switches::kUserDataDir
, // Make logs go to the right file.
1272 command_line
->CopySwitchesFrom(browser_command_line
, kCommonSwitchNames
,
1273 arraysize(kCommonSwitchNames
));
1275 #if defined(ENABLE_IPC_FUZZER)
1276 static const char* const kIpcFuzzerSwitches
[] = {
1277 switches::kIpcDumpDirectory
,
1278 switches::kIpcFuzzerTestcase
,
1280 command_line
->CopySwitchesFrom(browser_command_line
, kIpcFuzzerSwitches
,
1281 arraysize(kIpcFuzzerSwitches
));
1284 #if defined(OS_CHROMEOS)
1285 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
1286 base::FilePath homedir
;
1287 PathService::Get(base::DIR_HOME
, &homedir
);
1288 command_line
->AppendSwitchASCII(chromeos::switches::kHomedir
,
1289 homedir
.value().c_str());
1292 if (process_type
== switches::kRendererProcess
) {
1293 content::RenderProcessHost
* process
=
1294 content::RenderProcessHost::FromID(child_process_id
);
1296 process
? Profile::FromBrowserContext(process
->GetBrowserContext())
1298 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
1299 extra_parts_
[i
]->AppendExtraRendererCommandLineSwitches(
1300 command_line
, process
, profile
);
1303 #if defined(OS_CHROMEOS)
1304 const std::string
& login_profile
=
1305 browser_command_line
.GetSwitchValueASCII(
1306 chromeos::switches::kLoginProfile
);
1307 if (!login_profile
.empty())
1308 command_line
->AppendSwitchASCII(
1309 chromeos::switches::kLoginProfile
, login_profile
);
1312 #if defined(ENABLE_WEBRTC)
1313 MaybeCopyDisableWebRtcEncryptionSwitch(command_line
,
1314 browser_command_line
,
1315 VersionInfo::GetChannel());
1319 PrefService
* prefs
= profile
->GetPrefs();
1320 // Currently this pref is only registered if applied via a policy.
1321 if (prefs
->HasPrefPath(prefs::kDisable3DAPIs
) &&
1322 prefs
->GetBoolean(prefs::kDisable3DAPIs
)) {
1323 // Turn this policy into a command line switch.
1324 command_line
->AppendSwitch(switches::kDisable3DAPIs
);
1327 const base::ListValue
* switches
=
1328 prefs
->GetList(prefs::kEnableDeprecatedWebPlatformFeatures
);
1330 // Enable any deprecated features that have been re-enabled by policy.
1331 for (base::ListValue::const_iterator it
= switches
->begin();
1332 it
!= switches
->end(); ++it
) {
1333 std::string switch_to_enable
;
1334 if ((*it
)->GetAsString(&switch_to_enable
))
1335 command_line
->AppendSwitch(switch_to_enable
);
1339 // Disable client-side phishing detection in the renderer if it is
1340 // disabled in the Profile preferences or the browser process.
1341 if (!prefs
->GetBoolean(prefs::kSafeBrowsingEnabled
) ||
1342 !g_browser_process
->safe_browsing_detection_service()) {
1343 command_line
->AppendSwitch(
1344 switches::kDisableClientSidePhishingDetection
);
1347 if (prefs
->GetBoolean(prefs::kPrintPreviewDisabled
))
1348 command_line
->AppendSwitch(switches::kDisablePrintPreview
);
1350 InstantService
* instant_service
=
1351 InstantServiceFactory::GetForProfile(profile
);
1352 if (instant_service
&&
1353 instant_service
->IsInstantProcess(process
->GetID()))
1354 command_line
->AppendSwitch(switches::kInstantProcess
);
1357 if (IsAutoReloadEnabled())
1358 command_line
->AppendSwitch(switches::kEnableOfflineAutoReload
);
1359 if (IsAutoReloadVisibleOnlyEnabled()) {
1360 command_line
->AppendSwitch(
1361 switches::kEnableOfflineAutoReloadVisibleOnly
);
1365 // Enable showing a saved copy if this session is in the field trial
1366 // or the user explicitly enabled it. Note that as far as the
1367 // renderer is concerned, the feature is enabled if-and-only-if
1368 // one of the kEnableShowSavedCopy* switches is on the command
1369 // line; the yes/no/default behavior is only at the browser
1370 // command line level.
1372 // Command line switches override
1373 const std::string
& show_saved_copy_value
=
1374 browser_command_line
.GetSwitchValueASCII(switches::kShowSavedCopy
);
1375 if (show_saved_copy_value
== switches::kEnableShowSavedCopyPrimary
||
1376 show_saved_copy_value
== switches::kEnableShowSavedCopySecondary
||
1377 show_saved_copy_value
== switches::kDisableShowSavedCopy
) {
1378 command_line
->AppendSwitchASCII(switches::kShowSavedCopy
,
1379 show_saved_copy_value
);
1382 base::FieldTrialList::FindFullName("LoadStaleCacheExperiment");
1384 if (group
== "Primary") {
1385 command_line
->AppendSwitchASCII(
1386 switches::kShowSavedCopy
, switches::kEnableShowSavedCopyPrimary
);
1387 } else if (group
== "Secondary") {
1388 command_line
->AppendSwitchASCII(
1389 switches::kShowSavedCopy
,
1390 switches::kEnableShowSavedCopySecondary
);
1395 // Please keep this in alphabetical order.
1396 static const char* const kSwitchNames
[] = {
1397 autofill::switches::kDisableFillOnAccountSelect
,
1398 autofill::switches::kDisablePasswordGeneration
,
1399 autofill::switches::kEnableFillOnAccountSelect
,
1400 autofill::switches::kEnableFillOnAccountSelectNoHighlighting
,
1401 autofill::switches::kEnablePasswordGeneration
,
1402 autofill::switches::kEnablePasswordSaveOnInPageNavigation
,
1403 autofill::switches::kEnableSingleClickAutofill
,
1404 autofill::switches::kIgnoreAutocompleteOffForAutofill
,
1405 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration
,
1406 autofill::switches::kRespectAutocompleteOffForAutofill
,
1407 #if defined(ENABLE_EXTENSIONS)
1408 extensions::switches::kAllowHTTPBackgroundPage
,
1409 extensions::switches::kAllowLegacyExtensionManifests
,
1410 extensions::switches::kEnableSurfaceWorker
,
1411 extensions::switches::kEnableAppWindowControls
,
1412 extensions::switches::kEnableEmbeddedExtensionOptions
,
1413 extensions::switches::kEnableExperimentalExtensionApis
,
1414 extensions::switches::kExtensionsOnChromeURLs
,
1415 extensions::switches::kWhitelistedExtensionID
,
1417 switches::kAllowInsecureLocalhost
,
1418 switches::kAppsCheckoutURL
,
1419 switches::kAppsGalleryURL
,
1420 switches::kCloudPrintURL
,
1421 switches::kCloudPrintXmppEndpoint
,
1422 switches::kDisableBundledPpapiFlash
,
1423 switches::kDisableCastStreamingHWEncoding
,
1424 switches::kDisableJavaScriptHarmonyShipping
,
1425 switches::kDisableNewBookmarkApps
,
1426 switches::kDisableOutOfProcessPdf
,
1427 switches::kEnableBenchmarking
,
1428 switches::kEnableNaCl
,
1429 #if !defined(DISABLE_NACL)
1430 switches::kEnableNaClDebug
,
1431 switches::kEnableNaClNonSfiMode
,
1433 switches::kEnableNetBenchmarking
,
1434 switches::kEnableNewBookmarkApps
,
1435 switches::kEnableOutOfProcessPdf
,
1436 switches::kEnablePluginPlaceholderShadowDom
,
1437 switches::kJavaScriptHarmony
,
1438 switches::kMessageLoopHistogrammer
,
1439 switches::kPpapiFlashArgs
,
1440 switches::kPpapiFlashPath
,
1441 switches::kPpapiFlashVersion
,
1442 switches::kProfilingAtStart
,
1443 switches::kProfilingFile
,
1444 switches::kProfilingFlush
,
1445 translate::switches::kTranslateSecurityOrigin
,
1448 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1449 arraysize(kSwitchNames
));
1450 } else if (process_type
== switches::kUtilityProcess
) {
1451 #if defined(ENABLE_EXTENSIONS)
1452 static const char* const kSwitchNames
[] = {
1453 extensions::switches::kAllowHTTPBackgroundPage
,
1454 extensions::switches::kEnableExperimentalExtensionApis
,
1455 extensions::switches::kExtensionsOnChromeURLs
,
1456 extensions::switches::kWhitelistedExtensionID
,
1459 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1460 arraysize(kSwitchNames
));
1462 } else if (process_type
== switches::kPluginProcess
) {
1463 #if defined(OS_CHROMEOS)
1464 static const char* const kSwitchNames
[] = {
1465 chromeos::switches::kLoginProfile
,
1468 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1469 arraysize(kSwitchNames
));
1471 } else if (process_type
== switches::kZygoteProcess
) {
1472 static const char* const kSwitchNames
[] = {
1473 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
1474 switches::kDisableBundledPpapiFlash
,
1475 #if !defined(DISABLE_NACL)
1476 switches::kEnableNaClDebug
,
1477 switches::kEnableNaClNonSfiMode
,
1478 switches::kNaClDangerousNoSandboxNonSfi
,
1479 switches::kUseNaClHelperNonSfi
,
1481 switches::kPpapiFlashPath
,
1482 switches::kPpapiFlashVersion
,
1485 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1486 arraysize(kSwitchNames
));
1487 } else if (process_type
== switches::kGpuProcess
) {
1488 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1489 // because GPU is expected to be unreliable.
1490 if (browser_command_line
.HasSwitch(switches::kIgnoreGpuBlacklist
) &&
1491 !command_line
->HasSwitch(switches::kDisableBreakpad
))
1492 command_line
->AppendSwitch(switches::kDisableBreakpad
);
1495 // The command line switch kEnableBenchmarking needs to be specified along
1496 // with the kEnableStatsTable switch to ensure that the stats table global
1497 // is initialized correctly.
1498 if (command_line
->HasSwitch(switches::kEnableBenchmarking
))
1499 DCHECK(command_line
->HasSwitch(switches::kEnableStatsTable
));
1502 std::string
ChromeContentBrowserClient::GetApplicationLocale() {
1503 if (BrowserThread::CurrentlyOn(BrowserThread::IO
))
1504 return g_io_thread_application_locale
.Get();
1505 return g_browser_process
->GetApplicationLocale();
1508 std::string
ChromeContentBrowserClient::GetAcceptLangs(
1509 content::BrowserContext
* context
) {
1510 Profile
* profile
= Profile::FromBrowserContext(context
);
1511 return profile
->GetPrefs()->GetString(prefs::kAcceptLanguages
);
1514 const gfx::ImageSkia
* ChromeContentBrowserClient::GetDefaultFavicon() {
1515 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
1516 return rb
.GetNativeImageNamed(IDR_DEFAULT_FAVICON
).ToImageSkia();
1519 bool ChromeContentBrowserClient::AllowAppCache(
1520 const GURL
& manifest_url
,
1521 const GURL
& first_party
,
1522 content::ResourceContext
* context
) {
1523 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1524 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1525 return io_data
->GetCookieSettings()->
1526 IsSettingCookieAllowed(manifest_url
, first_party
);
1529 bool ChromeContentBrowserClient::AllowServiceWorker(
1531 const GURL
& first_party_url
,
1532 content::ResourceContext
* context
) {
1533 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1534 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1535 return io_data
->GetCookieSettings()->
1536 IsSettingCookieAllowed(scope
, first_party_url
);
1539 bool ChromeContentBrowserClient::AllowGetCookie(
1541 const GURL
& first_party
,
1542 const net::CookieList
& cookie_list
,
1543 content::ResourceContext
* context
,
1544 int render_process_id
,
1545 int render_frame_id
) {
1546 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1547 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1548 bool allow
= io_data
->GetCookieSettings()->
1549 IsReadingCookieAllowed(url
, first_party
);
1551 BrowserThread::PostTask(
1552 BrowserThread::UI
, FROM_HERE
,
1553 base::Bind(&TabSpecificContentSettings::CookiesRead
, render_process_id
,
1554 render_frame_id
, url
, first_party
, cookie_list
, !allow
));
1558 bool ChromeContentBrowserClient::AllowSetCookie(
1560 const GURL
& first_party
,
1561 const std::string
& cookie_line
,
1562 content::ResourceContext
* context
,
1563 int render_process_id
,
1564 int render_frame_id
,
1565 net::CookieOptions
* options
) {
1566 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1567 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1568 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1569 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, first_party
);
1571 BrowserThread::PostTask(
1572 BrowserThread::UI
, FROM_HERE
,
1573 base::Bind(&TabSpecificContentSettings::CookieChanged
, render_process_id
,
1574 render_frame_id
, url
, first_party
, cookie_line
, *options
,
1579 bool ChromeContentBrowserClient::AllowSaveLocalState(
1580 content::ResourceContext
* context
) {
1581 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1582 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1583 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1584 ContentSetting setting
= cookie_settings
->GetDefaultCookieSetting(NULL
);
1586 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1587 // Could we even support per-origin settings?
1588 return setting
!= CONTENT_SETTING_SESSION_ONLY
;
1591 bool ChromeContentBrowserClient::AllowWorkerDatabase(
1593 const base::string16
& name
,
1594 const base::string16
& display_name
,
1595 unsigned long estimated_size
,
1596 content::ResourceContext
* context
,
1597 const std::vector
<std::pair
<int, int> >& render_frames
) {
1598 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1599 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1600 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1601 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1603 // Record access to database for potential display in UI.
1604 std::vector
<std::pair
<int, int> >::const_iterator i
;
1605 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1606 BrowserThread::PostTask(
1607 BrowserThread::UI
, FROM_HERE
,
1608 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed
,
1609 i
->first
, i
->second
, url
, name
, display_name
, !allow
));
1615 void ChromeContentBrowserClient::AllowWorkerFileSystem(
1617 content::ResourceContext
* context
,
1618 const std::vector
<std::pair
<int, int> >& render_frames
,
1619 base::Callback
<void(bool)> callback
) {
1620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1621 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1622 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1623 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1625 #if defined(ENABLE_EXTENSIONS)
1626 GuestPermissionRequestHelper(url
, render_frames
, callback
, allow
);
1628 FileSystemAccessed(url
, render_frames
, callback
, allow
);
1632 #if defined(ENABLE_EXTENSIONS)
1633 void ChromeContentBrowserClient::GuestPermissionRequestHelper(
1635 const std::vector
<std::pair
<int, int> >& render_frames
,
1636 base::Callback
<void(bool)> callback
,
1638 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::IO
));
1639 std::vector
<std::pair
<int, int> >::const_iterator i
;
1640 std::map
<int, int> process_map
;
1641 std::map
<int, int>::const_iterator it
;
1642 bool has_web_view_guest
= false;
1643 // Record access to file system for potential display in UI.
1644 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1645 if (process_map
.find(i
->first
) != process_map
.end())
1648 process_map
.insert(std::pair
<int, int>(i
->first
, i
->second
));
1650 if (extensions::WebViewRendererState::GetInstance()->IsGuest(i
->first
))
1651 has_web_view_guest
= true;
1653 if (!has_web_view_guest
) {
1654 FileSystemAccessed(url
, render_frames
, callback
, allow
);
1657 DCHECK_EQ(1U, process_map
.size());
1658 it
= process_map
.begin();
1659 BrowserThread::PostTask(
1662 base::Bind(&ChromeContentBrowserClient::
1663 RequestFileSystemPermissionOnUIThread
,
1668 base::Bind(&ChromeContentBrowserClient::FileSystemAccessed
,
1669 weak_factory_
.GetWeakPtr(),
1675 void ChromeContentBrowserClient::RequestFileSystemPermissionOnUIThread(
1676 int render_process_id
,
1677 int render_frame_id
,
1679 bool allowed_by_default
,
1680 const base::Callback
<void(bool)>& callback
) {
1681 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::UI
));
1682 extensions::WebViewPermissionHelper
* web_view_permission_helper
=
1683 extensions::WebViewPermissionHelper::FromFrameID(
1684 render_process_id
, render_frame_id
);
1685 web_view_permission_helper
->RequestFileSystemPermission(url
,
1691 void ChromeContentBrowserClient::FileSystemAccessed(
1693 const std::vector
<std::pair
<int, int> >& render_frames
,
1694 base::Callback
<void(bool)> callback
,
1696 // Record access to file system for potential display in UI.
1697 std::vector
<std::pair
<int, int> >::const_iterator i
;
1698 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1699 BrowserThread::PostTask(
1702 base::Bind(&TabSpecificContentSettings::FileSystemAccessed
,
1703 i
->first
, i
->second
, url
, !allow
));
1705 callback
.Run(allow
);
1708 bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1710 const base::string16
& name
,
1711 content::ResourceContext
* context
,
1712 const std::vector
<std::pair
<int, int> >& render_frames
) {
1713 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1714 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1715 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1716 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1718 // Record access to IndexedDB for potential display in UI.
1719 std::vector
<std::pair
<int, int> >::const_iterator i
;
1720 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1721 BrowserThread::PostTask(
1722 BrowserThread::UI
, FROM_HERE
,
1723 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed
,
1724 i
->first
, i
->second
, url
, name
, !allow
));
1730 net::URLRequestContext
*
1731 ChromeContentBrowserClient::OverrideRequestContextForURL(
1732 const GURL
& url
, content::ResourceContext
* context
) {
1733 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1734 #if defined(ENABLE_EXTENSIONS)
1735 if (url
.SchemeIs(extensions::kExtensionScheme
)) {
1736 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1737 return io_data
->extensions_request_context();
1744 QuotaPermissionContext
*
1745 ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1746 return new ChromeQuotaPermissionContext();
1749 void ChromeContentBrowserClient::AllowCertificateError(
1750 int render_process_id
,
1751 int render_frame_id
,
1753 const net::SSLInfo
& ssl_info
,
1754 const GURL
& request_url
,
1755 ResourceType resource_type
,
1757 bool strict_enforcement
,
1758 bool expired_previous_decision
,
1759 const base::Callback
<void(bool)>& callback
,
1760 content::CertificateRequestResultType
* result
) {
1761 if (resource_type
!= content::RESOURCE_TYPE_MAIN_FRAME
) {
1762 // A sub-resource has a certificate error. The user doesn't really
1763 // have a context for making the right decision, so block the
1764 // request hard, without an info bar to allow showing the insecure
1766 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY
;
1770 // If the tab is being prerendered, cancel the prerender and the request.
1771 content::RenderFrameHost
* render_frame_host
=
1772 content::RenderFrameHost::FromID(render_process_id
, render_frame_id
);
1773 WebContents
* tab
= WebContents::FromRenderFrameHost(render_frame_host
);
1779 prerender::PrerenderContents
* prerender_contents
=
1780 prerender::PrerenderContents::FromWebContents(tab
);
1781 if (prerender_contents
) {
1782 prerender_contents
->Destroy(prerender::FINAL_STATUS_SSL_ERROR
);
1783 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL
;
1787 // Otherwise, display an SSL blocking page. The interstitial page takes
1788 // ownership of ssl_blocking_page.
1789 int options_mask
= 0;
1791 options_mask
|= SSLBlockingPage::OVERRIDABLE
;
1792 if (strict_enforcement
)
1793 options_mask
|= SSLBlockingPage::STRICT_ENFORCEMENT
;
1794 if (expired_previous_decision
)
1795 options_mask
|= SSLBlockingPage::EXPIRED_BUT_PREVIOUSLY_ALLOWED
;
1797 SSLErrorHandler::HandleSSLError(
1798 tab
, cert_error
, ssl_info
, request_url
, options_mask
, callback
);
1801 void ChromeContentBrowserClient::SelectClientCertificate(
1802 content::WebContents
* web_contents
,
1803 net::SSLCertRequestInfo
* cert_request_info
,
1804 scoped_ptr
<content::ClientCertificateDelegate
> delegate
) {
1805 prerender::PrerenderContents
* prerender_contents
=
1806 prerender::PrerenderContents::FromWebContents(web_contents
);
1807 if (prerender_contents
) {
1808 prerender_contents
->Destroy(
1809 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED
);
1813 GURL
requesting_url("https://" + cert_request_info
->host_and_port
.ToString());
1814 DCHECK(requesting_url
.is_valid())
1815 << "Invalid URL string: https://"
1816 << cert_request_info
->host_and_port
.ToString();
1819 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
1820 scoped_ptr
<base::Value
> filter
=
1821 profile
->GetHostContentSettingsMap()->GetWebsiteSetting(
1824 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE
,
1829 // Try to automatically select a client certificate.
1830 if (filter
->IsType(base::Value::TYPE_DICTIONARY
)) {
1831 base::DictionaryValue
* filter_dict
=
1832 static_cast<base::DictionaryValue
*>(filter
.get());
1834 const std::vector
<scoped_refptr
<net::X509Certificate
> >&
1835 all_client_certs
= cert_request_info
->client_certs
;
1836 for (size_t i
= 0; i
< all_client_certs
.size(); ++i
) {
1837 if (CertMatchesFilter(*all_client_certs
[i
].get(), *filter_dict
)) {
1838 // Use the first certificate that is matched by the filter.
1839 delegate
->ContinueWithCertificate(all_client_certs
[i
].get());
1848 chrome::ShowSSLClientCertificateSelector(web_contents
, cert_request_info
,
1852 void ChromeContentBrowserClient::AddCertificate(
1853 net::CertificateMimeType cert_type
,
1854 const void* cert_data
,
1856 int render_process_id
,
1857 int render_frame_id
) {
1858 chrome::SSLAddCertificate(cert_type
, cert_data
, cert_size
,
1859 render_process_id
, render_frame_id
);
1862 content::MediaObserver
* ChromeContentBrowserClient::GetMediaObserver() {
1863 return MediaCaptureDevicesDispatcher::GetInstance();
1866 content::PlatformNotificationService
*
1867 ChromeContentBrowserClient::GetPlatformNotificationService() {
1868 #if defined(ENABLE_NOTIFICATIONS)
1869 return PlatformNotificationServiceImpl::GetInstance();
1876 void ChromeContentBrowserClient::RequestPermission(
1877 content::PermissionType permission
,
1878 content::WebContents
* web_contents
,
1880 const GURL
& requesting_frame
,
1882 const base::Callback
<void(content::PermissionStatus
)>& result_callback
) {
1883 int render_process_id
= web_contents
->GetRenderProcessHost()->GetID();
1884 int render_view_id
= web_contents
->GetRenderViewHost()->GetRoutingID();
1885 const PermissionRequestID
request_id(render_process_id
,
1890 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
1891 PermissionContextBase
* context
= GetPermissionContext(profile
, permission
);
1896 context
->RequestPermission(web_contents
, request_id
, requesting_frame
,
1898 base::Bind(&OnRequestPermission
, result_callback
));
1901 content::PermissionStatus
ChromeContentBrowserClient::GetPermissionStatus(
1902 content::PermissionType permission
,
1903 content::BrowserContext
* browser_context
,
1904 const GURL
& requesting_origin
,
1905 const GURL
& embedding_origin
) {
1906 DCHECK(browser_context
);
1907 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1908 PermissionContextBase
* context
= GetPermissionContext(profile
, permission
);
1911 return content::PERMISSION_STATUS_ASK
;
1913 return ContentSettingToPermissionStatus(
1914 context
->GetPermissionStatus(requesting_origin
.GetOrigin(),
1915 embedding_origin
.GetOrigin()));
1918 void ChromeContentBrowserClient::ResetPermission(
1919 content::PermissionType permission
,
1920 content::BrowserContext
* browser_context
,
1921 const GURL
& requesting_origin
,
1922 const GURL
& embedding_origin
) {
1923 DCHECK(browser_context
);
1924 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1925 PermissionContextBase
* context
= GetPermissionContext(profile
, permission
);
1930 context
->ResetPermission(requesting_origin
.GetOrigin(),
1931 embedding_origin
.GetOrigin());
1934 void ChromeContentBrowserClient::CancelPermissionRequest(
1935 content::PermissionType permission
,
1936 content::WebContents
* web_contents
,
1938 const GURL
& requesting_frame
) {
1939 int render_process_id
= web_contents
->GetRenderProcessHost()->GetID();
1940 int render_view_id
= web_contents
->GetRenderViewHost()->GetRoutingID();
1941 const PermissionRequestID
request_id(render_process_id
,
1946 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
1947 PermissionContextBase
* context
= GetPermissionContext(profile
, permission
);
1950 context
->CancelPermissionRequest(web_contents
, request_id
);
1953 void ChromeContentBrowserClient::RegisterPermissionUsage(
1954 content::PermissionType permission
,
1955 content::WebContents
* web_contents
,
1956 const GURL
& frame_url
,
1957 const GURL
& main_frame_url
) {
1958 Profile::FromBrowserContext(web_contents
->GetBrowserContext())
1959 ->GetHostContentSettingsMap()
1961 frame_url
, main_frame_url
, PermissionToContentSetting(permission
));
1964 bool ChromeContentBrowserClient::CanCreateWindow(
1965 const GURL
& opener_url
,
1966 const GURL
& opener_top_level_frame_url
,
1967 const GURL
& source_origin
,
1968 WindowContainerType container_type
,
1969 const GURL
& target_url
,
1970 const content::Referrer
& referrer
,
1971 WindowOpenDisposition disposition
,
1972 const WebWindowFeatures
& features
,
1974 bool opener_suppressed
,
1975 content::ResourceContext
* context
,
1976 int render_process_id
,
1978 bool* no_javascript_access
) {
1979 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1981 *no_javascript_access
= false;
1983 // If the opener is trying to create a background window but doesn't have
1984 // the appropriate permission, fail the attempt.
1985 if (container_type
== WINDOW_CONTAINER_TYPE_BACKGROUND
) {
1986 #if defined(ENABLE_EXTENSIONS)
1987 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1988 InfoMap
* map
= io_data
->GetExtensionInfoMap();
1989 if (!map
->SecurityOriginHasAPIPermission(
1992 APIPermission::kBackground
)) {
1996 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1997 // return a recently installed Extension even if this CanCreateWindow call
1998 // was made by an old copy of the page in a normal web process. That's ok,
1999 // because the permission check above would have caused an early return
2000 // already. We must use the full URL to find hosted apps, though, and not
2002 const Extension
* extension
=
2003 map
->extensions().GetExtensionOrAppByURL(opener_url
);
2004 if (extension
&& !extensions::BackgroundInfo::AllowJSAccess(extension
))
2005 *no_javascript_access
= true;
2011 #if defined(ENABLE_EXTENSIONS)
2012 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
2017 HostContentSettingsMap
* content_settings
=
2018 ProfileIOData::FromResourceContext(context
)->GetHostContentSettingsMap();
2019 BlockedWindowParams
blocked_params(target_url
,
2028 if (!user_gesture
&&
2029 !base::CommandLine::ForCurrentProcess()->HasSwitch(
2030 switches::kDisablePopupBlocking
)) {
2031 if (content_settings
->GetContentSetting(opener_top_level_frame_url
,
2032 opener_top_level_frame_url
,
2033 CONTENT_SETTINGS_TYPE_POPUPS
,
2035 CONTENT_SETTING_ALLOW
) {
2036 BrowserThread::PostTask(BrowserThread::UI
,
2038 base::Bind(&HandleBlockedPopupOnUIThread
,
2044 #if defined(OS_ANDROID)
2045 if (SingleTabModeTabHelper::IsRegistered(render_process_id
, opener_id
)) {
2046 BrowserThread::PostTask(BrowserThread::UI
,
2048 base::Bind(&HandleSingleTabModeBlockOnUIThread
,
2057 void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2058 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
2059 return g_browser_process
->ResourceDispatcherHostCreated();
2062 content::SpeechRecognitionManagerDelegate
*
2063 ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
2064 return new speech::ChromeSpeechRecognitionManagerDelegate();
2067 net::NetLog
* ChromeContentBrowserClient::GetNetLog() {
2068 return g_browser_process
->net_log();
2071 AccessTokenStore
* ChromeContentBrowserClient::CreateAccessTokenStore() {
2072 return new ChromeAccessTokenStore();
2075 bool ChromeContentBrowserClient::IsFastShutdownPossible() {
2079 void ChromeContentBrowserClient::OverrideWebkitPrefs(
2080 RenderViewHost
* rvh
, WebPreferences
* web_prefs
) {
2081 Profile
* profile
= Profile::FromBrowserContext(
2082 rvh
->GetProcess()->GetBrowserContext());
2083 PrefService
* prefs
= profile
->GetPrefs();
2085 // Fill per-script font preferences. These are not registered on Android
2086 // - http://crbug.com/308033.
2087 #if !defined(OS_ANDROID)
2088 FontFamilyCache::FillFontFamilyMap(profile
,
2089 prefs::kWebKitStandardFontFamilyMap
,
2090 &web_prefs
->standard_font_family_map
);
2091 FontFamilyCache::FillFontFamilyMap(profile
,
2092 prefs::kWebKitFixedFontFamilyMap
,
2093 &web_prefs
->fixed_font_family_map
);
2094 FontFamilyCache::FillFontFamilyMap(profile
,
2095 prefs::kWebKitSerifFontFamilyMap
,
2096 &web_prefs
->serif_font_family_map
);
2097 FontFamilyCache::FillFontFamilyMap(profile
,
2098 prefs::kWebKitSansSerifFontFamilyMap
,
2099 &web_prefs
->sans_serif_font_family_map
);
2100 FontFamilyCache::FillFontFamilyMap(profile
,
2101 prefs::kWebKitCursiveFontFamilyMap
,
2102 &web_prefs
->cursive_font_family_map
);
2103 FontFamilyCache::FillFontFamilyMap(profile
,
2104 prefs::kWebKitFantasyFontFamilyMap
,
2105 &web_prefs
->fantasy_font_family_map
);
2106 FontFamilyCache::FillFontFamilyMap(profile
,
2107 prefs::kWebKitPictographFontFamilyMap
,
2108 &web_prefs
->pictograph_font_family_map
);
2111 web_prefs
->default_font_size
=
2112 prefs
->GetInteger(prefs::kWebKitDefaultFontSize
);
2113 web_prefs
->default_fixed_font_size
=
2114 prefs
->GetInteger(prefs::kWebKitDefaultFixedFontSize
);
2115 web_prefs
->minimum_font_size
=
2116 prefs
->GetInteger(prefs::kWebKitMinimumFontSize
);
2117 web_prefs
->minimum_logical_font_size
=
2118 prefs
->GetInteger(prefs::kWebKitMinimumLogicalFontSize
);
2120 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2122 web_prefs
->javascript_can_open_windows_automatically
=
2123 prefs
->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically
);
2124 web_prefs
->dom_paste_enabled
=
2125 prefs
->GetBoolean(prefs::kWebKitDomPasteEnabled
);
2126 web_prefs
->shrinks_standalone_images_to_fit
=
2127 prefs
->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit
);
2128 web_prefs
->tabs_to_links
= prefs
->GetBoolean(prefs::kWebkitTabsToLinks
);
2130 if (!prefs
->GetBoolean(prefs::kWebKitJavascriptEnabled
))
2131 web_prefs
->javascript_enabled
= false;
2132 if (!prefs
->GetBoolean(prefs::kWebKitWebSecurityEnabled
))
2133 web_prefs
->web_security_enabled
= false;
2134 if (!prefs
->GetBoolean(prefs::kWebKitPluginsEnabled
))
2135 web_prefs
->plugins_enabled
= false;
2136 if (!prefs
->GetBoolean(prefs::kWebKitJavaEnabled
))
2137 web_prefs
->java_enabled
= false;
2138 web_prefs
->loads_images_automatically
=
2139 prefs
->GetBoolean(prefs::kWebKitLoadsImagesAutomatically
);
2141 if (prefs
->GetBoolean(prefs::kDisable3DAPIs
))
2142 web_prefs
->experimental_webgl_enabled
= false;
2144 web_prefs
->allow_displaying_insecure_content
=
2145 prefs
->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent
);
2146 web_prefs
->allow_running_insecure_content
=
2147 prefs
->GetBoolean(prefs::kWebKitAllowRunningInsecureContent
);
2148 #if defined(OS_ANDROID)
2149 web_prefs
->font_scale_factor
=
2150 static_cast<float>(prefs
->GetDouble(prefs::kWebKitFontScaleFactor
));
2151 web_prefs
->device_scale_adjustment
= GetDeviceScaleAdjustment();
2152 web_prefs
->force_enable_zoom
=
2153 prefs
->GetBoolean(prefs::kWebKitForceEnableZoom
);
2156 #if defined(OS_ANDROID)
2157 web_prefs
->password_echo_enabled
=
2158 prefs
->GetBoolean(prefs::kWebKitPasswordEchoEnabled
);
2160 web_prefs
->password_echo_enabled
= browser_defaults::kPasswordEchoEnabled
;
2163 web_prefs
->asynchronous_spell_checking_enabled
= true;
2164 web_prefs
->unified_textchecker_enabled
= true;
2166 web_prefs
->uses_universal_detector
=
2167 prefs
->GetBoolean(prefs::kWebKitUsesUniversalDetector
);
2168 web_prefs
->text_areas_are_resizable
=
2169 prefs
->GetBoolean(prefs::kWebKitTextAreasAreResizable
);
2170 web_prefs
->hyperlink_auditing_enabled
=
2171 prefs
->GetBoolean(prefs::kEnableHyperlinkAuditing
);
2173 #if defined(ENABLE_EXTENSIONS)
2174 std::string image_animation_policy
=
2175 prefs
->GetString(prefs::kAnimationPolicy
);
2176 if (image_animation_policy
== kAnimationPolicyOnce
)
2177 web_prefs
->animation_policy
=
2178 content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE
;
2179 else if (image_animation_policy
== kAnimationPolicyNone
)
2180 web_prefs
->animation_policy
= content::IMAGE_ANIMATION_POLICY_NO_ANIMATION
;
2182 web_prefs
->animation_policy
= content::IMAGE_ANIMATION_POLICY_ALLOWED
;
2185 // Make sure we will set the default_encoding with canonical encoding name.
2186 web_prefs
->default_encoding
=
2187 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
2188 web_prefs
->default_encoding
);
2189 if (web_prefs
->default_encoding
.empty()) {
2190 prefs
->ClearPref(prefs::kDefaultCharset
);
2191 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2193 DCHECK(!web_prefs
->default_encoding
.empty());
2195 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2196 switches::kEnablePotentiallyAnnoyingSecurityFeatures
)) {
2197 web_prefs
->disable_reading_from_canvas
= true;
2198 web_prefs
->strict_mixed_content_checking
= true;
2199 web_prefs
->strict_powerful_feature_restrictions
= true;
2202 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2203 extra_parts_
[i
]->OverrideWebkitPrefs(rvh
, web_prefs
);
2206 void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2207 BrowserURLHandler
* handler
) {
2208 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2209 extra_parts_
[i
]->BrowserURLHandlerCreated(handler
);
2211 // about: handler. Must come before chrome: handler, since it will
2212 // rewrite about: urls to chrome: URLs and then expect chrome: to
2213 // actually handle them. Also relies on a preliminary fixup phase.
2214 handler
->SetFixupHandler(&FixupBrowserAboutURL
);
2215 handler
->AddHandlerPair(&WillHandleBrowserAboutURL
,
2216 BrowserURLHandler::null_handler());
2218 #if defined(OS_ANDROID)
2219 // Handler to rewrite chrome://newtab on Android.
2220 handler
->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL
,
2221 BrowserURLHandler::null_handler());
2223 // Handler to rewrite chrome://newtab for InstantExtended.
2224 handler
->AddHandlerPair(&chrome::HandleNewTabURLRewrite
,
2225 &chrome::HandleNewTabURLReverseRewrite
);
2228 // chrome: & friends.
2229 handler
->AddHandlerPair(&HandleWebUI
, &HandleWebUIReverse
);
2232 void ChromeContentBrowserClient::ClearCache(RenderViewHost
* rvh
) {
2233 Profile
* profile
= Profile::FromBrowserContext(
2234 rvh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2235 BrowsingDataRemover
* remover
=
2236 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2237 remover
->Remove(BrowsingDataRemover::REMOVE_CACHE
,
2238 BrowsingDataHelper::UNPROTECTED_WEB
);
2239 // BrowsingDataRemover takes care of deleting itself when done.
2242 void ChromeContentBrowserClient::ClearCookies(RenderViewHost
* rvh
) {
2243 Profile
* profile
= Profile::FromBrowserContext(
2244 rvh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2245 BrowsingDataRemover
* remover
=
2246 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2247 int remove_mask
= BrowsingDataRemover::REMOVE_SITE_DATA
;
2248 remover
->Remove(remove_mask
, BrowsingDataHelper::UNPROTECTED_WEB
);
2249 // BrowsingDataRemover takes care of deleting itself when done.
2252 base::FilePath
ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
2253 return DownloadPrefs::GetDefaultDownloadDirectory();
2256 std::string
ChromeContentBrowserClient::GetDefaultDownloadName() {
2257 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME
);
2260 void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2261 content::BrowserPpapiHost
* browser_host
) {
2262 #if defined(ENABLE_PLUGINS)
2263 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host
);
2267 content::BrowserPpapiHost
*
2268 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2269 int plugin_process_id
) {
2270 #if !defined(DISABLE_NACL)
2271 content::BrowserChildProcessHostIterator
iter(PROCESS_TYPE_NACL_LOADER
);
2272 while (!iter
.Done()) {
2273 nacl::NaClProcessHost
* host
= static_cast<nacl::NaClProcessHost
*>(
2274 iter
.GetDelegate());
2275 if (host
->process() &&
2276 host
->process()->GetData().id
== plugin_process_id
) {
2277 // Found the plugin.
2278 return host
->browser_ppapi_host();
2286 bool ChromeContentBrowserClient::AllowPepperSocketAPI(
2287 content::BrowserContext
* browser_context
,
2290 const content::SocketPermissionRequest
* params
) {
2291 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2292 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
2293 browser_context
, url
, private_api
, params
, allowed_socket_origins_
);
2299 ui::SelectFilePolicy
* ChromeContentBrowserClient::CreateSelectFilePolicy(
2300 WebContents
* web_contents
) {
2301 return new ChromeSelectFilePolicy(web_contents
);
2304 void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2305 std::vector
<std::string
>* additional_allowed_schemes
) {
2306 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2307 additional_allowed_schemes
);
2308 additional_allowed_schemes
->push_back(content::kChromeDevToolsScheme
);
2309 additional_allowed_schemes
->push_back(content::kChromeUIScheme
);
2310 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
2311 extra_parts_
[i
]->GetAdditionalAllowedSchemesForFileSystem(
2312 additional_allowed_schemes
);
2316 void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
2317 std::vector
<storage::URLRequestAutoMountHandler
>* handlers
) {
2318 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2319 extra_parts_
[i
]->GetURLRequestAutoMountHandlers(handlers
);
2322 void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
2323 content::BrowserContext
* browser_context
,
2324 const base::FilePath
& storage_partition_path
,
2325 ScopedVector
<storage::FileSystemBackend
>* additional_backends
) {
2326 #if defined(OS_CHROMEOS)
2327 storage::ExternalMountPoints
* external_mount_points
=
2328 content::BrowserContext::GetMountPoints(browser_context
);
2329 DCHECK(external_mount_points
);
2330 chromeos::FileSystemBackend
* backend
= new chromeos::FileSystemBackend(
2331 new drive::FileSystemBackendDelegate
,
2332 new chromeos::file_system_provider::BackendDelegate
,
2333 new chromeos::MTPFileSystemBackendDelegate(storage_partition_path
),
2334 browser_context
->GetSpecialStoragePolicy(),
2335 external_mount_points
,
2336 storage::ExternalMountPoints::GetSystemInstance());
2337 backend
->AddSystemMountPoints();
2338 DCHECK(backend
->CanHandleType(storage::kFileSystemTypeExternal
));
2339 additional_backends
->push_back(backend
);
2342 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
2343 extra_parts_
[i
]->GetAdditionalFileSystemBackends(
2344 browser_context
, storage_partition_path
, additional_backends
);
2348 #if defined(OS_POSIX) && !defined(OS_MACOSX)
2349 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2350 const base::CommandLine
& command_line
,
2351 int child_process_id
,
2352 FileDescriptorInfo
* mappings
) {
2353 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
2354 if (v8_snapshot_fd_
.get() == -1 && v8_natives_fd_
.get() == -1) {
2355 base::FilePath v8_data_path
;
2356 PathService::Get(gin::IsolateHolder::kV8SnapshotBasePathKey
, &v8_data_path
);
2357 DCHECK(!v8_data_path
.empty());
2359 int file_flags
= base::File::FLAG_OPEN
| base::File::FLAG_READ
;
2360 base::FilePath v8_natives_data_path
=
2361 v8_data_path
.AppendASCII(gin::IsolateHolder::kNativesFileName
);
2362 base::FilePath v8_snapshot_data_path
=
2363 v8_data_path
.AppendASCII(gin::IsolateHolder::kSnapshotFileName
);
2364 base::File
v8_natives_data_file(v8_natives_data_path
, file_flags
);
2365 base::File
v8_snapshot_data_file(v8_snapshot_data_path
, file_flags
);
2366 DCHECK(v8_natives_data_file
.IsValid());
2367 DCHECK(v8_snapshot_data_file
.IsValid());
2368 v8_natives_fd_
.reset(v8_natives_data_file
.TakePlatformFile());
2369 v8_snapshot_fd_
.reset(v8_snapshot_data_file
.TakePlatformFile());
2371 mappings
->Share(kV8NativesDataDescriptor
, v8_natives_fd_
.get());
2372 mappings
->Share(kV8SnapshotDataDescriptor
, v8_snapshot_fd_
.get());
2373 #endif // V8_USE_EXTERNAL_STARTUP_DATA
2375 #if defined(OS_ANDROID)
2376 base::FilePath data_path
;
2377 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID
, &data_path
);
2378 DCHECK(!data_path
.empty());
2380 int flags
= base::File::FLAG_OPEN
| base::File::FLAG_READ
;
2381 base::FilePath chrome_resources_pak
=
2382 data_path
.AppendASCII("chrome_100_percent.pak");
2383 base::File
file(chrome_resources_pak
, flags
);
2384 DCHECK(file
.IsValid());
2385 mappings
->Transfer(kAndroidChrome100PercentPakDescriptor
,
2386 base::ScopedFD(file
.TakePlatformFile()));
2388 const std::string locale
= GetApplicationLocale();
2389 base::FilePath locale_pak
= ResourceBundle::GetSharedInstance().
2390 GetLocaleFilePath(locale
, false);
2391 file
.Initialize(locale_pak
, flags
);
2392 DCHECK(file
.IsValid());
2393 mappings
->Transfer(kAndroidLocalePakDescriptor
,
2394 base::ScopedFD(file
.TakePlatformFile()));
2396 base::FilePath resources_pack_path
;
2397 PathService::Get(chrome::FILE_RESOURCES_PACK
, &resources_pack_path
);
2398 file
.Initialize(resources_pack_path
, flags
);
2399 DCHECK(file
.IsValid());
2400 mappings
->Transfer(kAndroidUIResourcesPakDescriptor
,
2401 base::ScopedFD(file
.TakePlatformFile()));
2403 if (breakpad::IsCrashReporterEnabled()) {
2404 file
= 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 flags
= base::File::FLAG_OPEN
| base::File::FLAG_READ
;
2420 base::FilePath icudata_path
=
2421 app_data_path
.AppendASCII(base::i18n::kIcuDataFileName
);
2422 base::File
icudata_file(icudata_path
, flags
);
2423 DCHECK(icudata_file
.IsValid());
2424 mappings
->Transfer(kAndroidICUDataDescriptor
,
2425 base::ScopedFD(icudata_file
.TakePlatformFile()));
2427 int crash_signal_fd
= GetCrashSignalFD(command_line
);
2428 if (crash_signal_fd
>= 0) {
2429 mappings
->Share(kCrashDumpSignal
, crash_signal_fd
);
2431 #endif // defined(OS_ANDROID)
2433 #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
2436 const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2437 return chrome::kBrowserResourcesDll
;
2440 void ChromeContentBrowserClient::PreSpawnRenderer(
2441 sandbox::TargetPolicy
* policy
,
2443 // This code is duplicated in nacl_exe_win_64.cc.
2444 // Allow the server side of a pipe restricted to the "chrome.nacl."
2445 // namespace so that it cannot impersonate other system or other chrome
2447 sandbox::ResultCode result
= policy
->AddRule(
2448 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES
,
2449 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY
,
2450 L
"\\\\.\\pipe\\chrome.nacl.*");
2451 if (result
!= sandbox::SBOX_ALL_OK
) {
2456 // Renderers need to send named pipe handles and shared memory
2457 // segment handles to NaCl loader processes.
2458 result
= policy
->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES
,
2459 sandbox::TargetPolicy::HANDLES_DUP_ANY
,
2461 if (result
!= sandbox::SBOX_ALL_OK
) {
2468 bool ChromeContentBrowserClient::CheckMediaAccessPermission(
2469 content::BrowserContext
* browser_context
,
2470 const GURL
& security_origin
,
2471 content::MediaStreamType type
) {
2472 return MediaCaptureDevicesDispatcher::GetInstance()
2473 ->CheckMediaAccessPermission(
2474 browser_context
, security_origin
, type
);
2477 void ChromeContentBrowserClient::OpenURL(
2478 content::BrowserContext
* browser_context
,
2479 const content::OpenURLParams
& params
,
2480 const base::Callback
<void(content::WebContents
*)>& callback
) {
2481 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
2483 #if !defined(OS_ANDROID) && !defined(OS_IOS)
2484 NavigateParams
nav_params(Profile::FromBrowserContext(browser_context
),
2487 FillNavigateParamsFromOpenURLParams(&nav_params
, params
);
2488 nav_params
.user_gesture
= params
.user_gesture
;
2490 Navigate(&nav_params
);
2491 callback
.Run(nav_params
.target_contents
);
2492 #elif defined(OS_ANDROID)
2493 chrome::android::ServiceTabLauncher::GetInstance()->LaunchTab(
2494 browser_context
, params
, callback
);
2500 void ChromeContentBrowserClient::RecordURLMetric(const std::string
& metric
,
2502 if (url
.is_valid()) {
2503 rappor::SampleDomainAndRegistryFromGURL(g_browser_process
->rappor_service(),
2508 content::DevToolsManagerDelegate
*
2509 ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
2510 #if defined(OS_ANDROID)
2511 return new DevToolsManagerDelegateAndroid();
2513 return new ChromeDevToolsManagerDelegate();
2517 content::TracingDelegate
* ChromeContentBrowserClient::GetTracingDelegate() {
2518 #if !defined(OS_ANDROID)
2519 return new ChromeTracingDelegate();
2525 bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2526 content::BrowserContext
* browser_context
,
2528 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2529 return ChromeContentBrowserClientPluginsPart::
2530 IsPluginAllowedToCallRequestOSFileHandle(browser_context
, url
,
2531 allowed_file_handle_origins_
);
2537 bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
2538 content::BrowserContext
* browser_context
,
2540 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2541 return ChromeContentBrowserClientPluginsPart::
2542 IsPluginAllowedToUseDevChannelAPIs(browser_context
, url
,
2543 allowed_dev_channel_origins_
);
2549 void ChromeContentBrowserClient::OverridePageVisibilityState(
2550 RenderFrameHost
* render_frame_host
,
2551 blink::WebPageVisibilityState
* visibility_state
) {
2552 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
2554 WebContents
* web_contents
=
2555 WebContents::FromRenderFrameHost(render_frame_host
);
2556 DCHECK(web_contents
);
2559 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
2560 prerender::PrerenderManager
* prerender_manager
=
2561 prerender::PrerenderManagerFactory::GetForProfile(profile
);
2562 if (prerender_manager
&&
2563 prerender_manager
->IsWebContentsPrerendering(web_contents
, nullptr)) {
2564 *visibility_state
= blink::WebPageVisibilityStatePrerender
;
2568 #if defined(ENABLE_WEBRTC)
2569 void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
2570 base::CommandLine
* to_command_line
,
2571 const base::CommandLine
& from_command_line
,
2572 VersionInfo::Channel channel
) {
2573 #if defined(OS_ANDROID)
2574 const VersionInfo::Channel kMaxDisableEncryptionChannel
=
2575 VersionInfo::CHANNEL_BETA
;
2577 const VersionInfo::Channel kMaxDisableEncryptionChannel
=
2578 VersionInfo::CHANNEL_DEV
;
2580 if (channel
<= kMaxDisableEncryptionChannel
) {
2581 static const char* const kWebRtcDevSwitchNames
[] = {
2582 switches::kDisableWebRtcEncryption
,
2584 to_command_line
->CopySwitchesFrom(from_command_line
,
2585 kWebRtcDevSwitchNames
,
2586 arraysize(kWebRtcDevSwitchNames
));
2589 #endif // defined(ENABLE_WEBRTC)
2591 } // namespace chrome