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/lazy_instance.h"
14 #include "base/path_service.h"
15 #include "base/prefs/pref_service.h"
16 #include "base/prefs/scoped_user_pref_update.h"
17 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/utf_string_conversions.h"
19 #include "base/threading/sequenced_worker_pool.h"
20 #include "chrome/browser/app_mode/app_mode_utils.h"
21 #include "chrome/browser/browser_about_handler.h"
22 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/browser_shutdown.h"
24 #include "chrome/browser/browsing_data/browsing_data_helper.h"
25 #include "chrome/browser/browsing_data/browsing_data_remover.h"
26 #include "chrome/browser/character_encoding.h"
27 #include "chrome/browser/chrome_net_benchmarking_message_filter.h"
28 #include "chrome/browser/chrome_quota_permission_context.h"
29 #include "chrome/browser/content_settings/content_settings_utils.h"
30 #include "chrome/browser/content_settings/cookie_settings.h"
31 #include "chrome/browser/content_settings/host_content_settings_map.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/extensions/api/web_request/web_request_api.h"
36 #include "chrome/browser/extensions/browser_permissions_policy_delegate.h"
37 #include "chrome/browser/extensions/extension_service.h"
38 #include "chrome/browser/extensions/extension_util.h"
39 #include "chrome/browser/extensions/extension_web_ui.h"
40 #include "chrome/browser/extensions/extension_webkit_preferences.h"
41 #include "chrome/browser/extensions/suggest_permission_util.h"
42 #include "chrome/browser/geolocation/chrome_access_token_store.h"
43 #include "chrome/browser/google/google_util.h"
44 #include "chrome/browser/guestview/adview/adview_guest.h"
45 #include "chrome/browser/guestview/guestview.h"
46 #include "chrome/browser/guestview/guestview_constants.h"
47 #include "chrome/browser/guestview/webview/webview_guest.h"
48 #include "chrome/browser/local_discovery/storage/privet_filesystem_backend.h"
49 #include "chrome/browser/media/cast_transport_host_filter.h"
50 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
51 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
52 #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
53 #include "chrome/browser/net/chrome_net_log.h"
54 #include "chrome/browser/notifications/desktop_notification_service.h"
55 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
56 #include "chrome/browser/platform_util.h"
57 #include "chrome/browser/plugins/plugin_info_message_filter.h"
58 #include "chrome/browser/prerender/prerender_final_status.h"
59 #include "chrome/browser/prerender/prerender_manager.h"
60 #include "chrome/browser/prerender/prerender_manager_factory.h"
61 #include "chrome/browser/prerender/prerender_message_filter.h"
62 #include "chrome/browser/prerender/prerender_tracker.h"
63 #include "chrome/browser/printing/printing_message_filter.h"
64 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
65 #include "chrome/browser/profiles/profile.h"
66 #include "chrome/browser/profiles/profile_io_data.h"
67 #include "chrome/browser/profiles/profile_manager.h"
68 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
69 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
70 #include "chrome/browser/search/instant_service.h"
71 #include "chrome/browser/search/instant_service_factory.h"
72 #include "chrome/browser/search/search.h"
73 #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
74 #include "chrome/browser/signin/principals_message_filter.h"
75 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
76 #include "chrome/browser/speech/tts_message_filter.h"
77 #include "chrome/browser/ssl/ssl_add_certificate.h"
78 #include "chrome/browser/ssl/ssl_blocking_page.h"
79 #include "chrome/browser/ssl/ssl_tab_helper.h"
80 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
81 #include "chrome/browser/tab_contents/tab_util.h"
82 #include "chrome/browser/ui/blocked_content/blocked_window_params.h"
83 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
84 #include "chrome/browser/ui/chrome_select_file_policy.h"
85 #include "chrome/browser/ui/sync/sync_promo_ui.h"
86 #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
87 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
88 #include "chrome/common/chrome_constants.h"
89 #include "chrome/common/chrome_paths.h"
90 #include "chrome/common/chrome_switches.h"
91 #include "chrome/common/env_vars.h"
92 #include "chrome/common/extensions/extension_process_policy.h"
93 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
94 #include "chrome/common/logging_chrome.h"
95 #include "chrome/common/pepper_permission_util.h"
96 #include "chrome/common/pref_names.h"
97 #include "chrome/common/profile_management_switches.h"
98 #include "chrome/common/render_messages.h"
99 #include "chrome/common/url_constants.h"
100 #include "chrome/installer/util/google_update_settings.h"
101 #include "chromeos/chromeos_constants.h"
102 #include "components/nacl/browser/nacl_browser.h"
103 #include "components/nacl/browser/nacl_host_message_filter.h"
104 #include "components/nacl/browser/nacl_process_host.h"
105 #include "components/nacl/common/nacl_process_type.h"
106 #include "components/nacl/common/nacl_switches.h"
107 #include "components/translate/core/common/translate_switches.h"
108 #include "components/user_prefs/pref_registry_syncable.h"
109 #include "content/public/browser/browser_child_process_host.h"
110 #include "content/public/browser/browser_main_parts.h"
111 #include "content/public/browser/browser_ppapi_host.h"
112 #include "content/public/browser/browser_thread.h"
113 #include "content/public/browser/browser_url_handler.h"
114 #include "content/public/browser/child_process_data.h"
115 #include "content/public/browser/child_process_security_policy.h"
116 #include "content/public/browser/render_frame_host.h"
117 #include "content/public/browser/render_process_host.h"
118 #include "content/public/browser/render_view_host.h"
119 #include "content/public/browser/resource_context.h"
120 #include "content/public/browser/site_instance.h"
121 #include "content/public/browser/web_contents.h"
122 #include "content/public/browser/web_contents_view.h"
123 #include "content/public/common/child_process_host.h"
124 #include "content/public/common/content_descriptors.h"
125 #include "content/public/common/url_utils.h"
126 #include "extensions/browser/extension_host.h"
127 #include "extensions/browser/extension_message_filter.h"
128 #include "extensions/browser/extension_registry.h"
129 #include "extensions/browser/extension_system.h"
130 #include "extensions/browser/info_map.h"
131 #include "extensions/browser/process_manager.h"
132 #include "extensions/browser/process_map.h"
133 #include "extensions/browser/view_type_utils.h"
134 #include "extensions/common/constants.h"
135 #include "extensions/common/extension.h"
136 #include "extensions/common/extension_set.h"
137 #include "extensions/common/manifest_handlers/background_info.h"
138 #include "extensions/common/manifest_handlers/shared_module_info.h"
139 #include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
140 #include "extensions/common/permissions/permissions_data.h"
141 #include "extensions/common/permissions/socket_permission.h"
142 #include "extensions/common/switches.h"
143 #include "grit/generated_resources.h"
144 #include "grit/ui_resources.h"
145 #include "net/base/mime_util.h"
146 #include "net/cookies/canonical_cookie.h"
147 #include "net/cookies/cookie_options.h"
148 #include "net/ssl/ssl_cert_request_info.h"
149 #include "ppapi/host/ppapi_host.h"
150 #include "ppapi/shared_impl/ppapi_switches.h"
151 #include "ui/base/l10n/l10n_util.h"
152 #include "ui/base/resource/resource_bundle.h"
153 #include "ui/message_center/message_center_util.h"
154 #include "webkit/browser/fileapi/external_mount_points.h"
155 #include "webkit/common/webpreferences.h"
158 #include "base/win/windows_version.h"
159 #include "chrome/browser/chrome_browser_main_win.h"
160 #include "sandbox/win/src/sandbox_policy.h"
161 #elif defined(OS_MACOSX)
162 #include "chrome/browser/chrome_browser_main_mac.h"
163 #include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
164 #include "components/breakpad/app/breakpad_mac.h"
165 #elif defined(OS_CHROMEOS)
166 #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
167 #include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h"
168 #include "chrome/browser/chromeos/fileapi/file_system_backend.h"
169 #include "chrome/browser/chromeos/login/startup_utils.h"
170 #include "chrome/browser/chromeos/login/user_manager.h"
171 #include "chrome/browser/chromeos/system/input_device_settings.h"
172 #include "chromeos/chromeos_switches.h"
173 #elif defined(OS_LINUX)
174 #include "chrome/browser/chrome_browser_main_linux.h"
175 #elif defined(OS_ANDROID)
176 #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
177 #include "chrome/browser/chrome_browser_main_android.h"
178 #include "chrome/browser/media/encrypted_media_message_filter_android.h"
179 #include "chrome/common/descriptors_android.h"
180 #include "components/breakpad/browser/crash_dump_manager_android.h"
181 #elif defined(OS_POSIX)
182 #include "chrome/browser/chrome_browser_main_posix.h"
185 #if defined(OS_POSIX) && !defined(OS_MACOSX)
186 #include "base/debug/leak_annotations.h"
187 #include "base/linux_util.h"
188 #include "components/breakpad/app/breakpad_linux.h"
189 #include "components/breakpad/browser/crash_handler_host_linux.h"
192 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
193 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
196 #if defined(OS_ANDROID)
197 #include "ui/base/ui_base_paths.h"
198 #include "ui/gfx/android/device_display_info.h"
201 #if !defined(OS_CHROMEOS)
202 #include "chrome/browser/signin/signin_manager.h"
203 #include "chrome/browser/signin/signin_manager_factory.h"
206 #if !defined(OS_ANDROID)
207 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
210 #if defined(ENABLE_WEBRTC)
211 #include "chrome/browser/media/webrtc_logging_handler_host.h"
214 #if defined(ENABLE_INPUT_SPEECH)
215 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate_bubble_ui.h"
218 #if defined(OS_CHROMEOS)
219 #include "chrome/browser/chromeos/file_manager/app_id.h"
222 #if defined(TOOLKIT_GTK)
223 #include "chrome/browser/ui/gtk/chrome_browser_main_extra_parts_gtk.h"
226 #if defined(TOOLKIT_VIEWS)
227 #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
231 #include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
234 #if defined(USE_AURA)
235 #include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
239 #include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
242 #if defined(ENABLE_SPELLCHECK)
243 #include "chrome/browser/spellchecker/spellcheck_message_filter.h"
246 #if defined(ENABLE_SERVICE_DISCOVERY)
247 #include "chrome/browser/local_discovery/storage/privet_filesystem_backend.h"
250 using blink::WebWindowFeatures
;
251 using base::FileDescriptor
;
252 using content::AccessTokenStore
;
253 using content::BrowserChildProcessHostIterator
;
254 using content::BrowserThread
;
255 using content::BrowserURLHandler
;
256 using content::ChildProcessSecurityPolicy
;
257 using content::QuotaPermissionContext
;
258 using content::RenderViewHost
;
259 using content::SiteInstance
;
260 using content::WebContents
;
261 using extensions::APIPermission
;
262 using extensions::Extension
;
263 using extensions::InfoMap
;
264 using extensions::Manifest
;
265 using message_center::NotifierId
;
267 #if defined(OS_POSIX)
268 using content::FileDescriptorInfo
;
273 // Cached version of the locale so we can return the locale on the I/O
275 base::LazyInstance
<std::string
> g_io_thread_application_locale
;
277 #if defined(ENABLE_PLUGINS)
278 const char* kPredefinedAllowedFileHandleOrigins
[] = {
279 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
280 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
283 const char* kPredefinedAllowedSocketOrigins
[] = {
284 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
285 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
286 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
287 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
288 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
289 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
290 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
291 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
292 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
293 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
294 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
295 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
296 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
297 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
298 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
299 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
300 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
301 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
302 "4EB74897CB187C7633357C2FE832E0AD6A44883A", // see crbug.com/234789
303 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
304 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
305 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
309 // Returns a copy of the given url with its host set to given host and path set
310 // to given path. Other parts of the url will be the same.
311 GURL
ReplaceURLHostAndPath(const GURL
& url
,
312 const std::string
& host
,
313 const std::string
& path
) {
314 url_canon::Replacements
<char> replacements
;
315 replacements
.SetHost(host
.c_str(),
316 url_parse::Component(0, host
.length()));
317 replacements
.SetPath(path
.c_str(),
318 url_parse::Component(0, path
.length()));
319 return url
.ReplaceComponents(replacements
);
322 // Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
323 GURL
AddUberHost(const GURL
& url
) {
324 const std::string uber_host
= chrome::kChromeUIUberHost
;
325 const std::string new_path
= url
.host() + url
.path();
327 return ReplaceURLHostAndPath(url
, uber_host
, new_path
);
330 // If url->host() is "chrome" and url->path() has characters other than the
331 // first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
332 // returns true. Otherwise returns false.
333 bool RemoveUberHost(GURL
* url
) {
334 if (url
->host() != chrome::kChromeUIUberHost
)
337 if (url
->path().empty() || url
->path() == "/")
340 const std::string old_path
= url
->path();
342 const std::string::size_type separator
= old_path
.find('/', 1);
343 std::string new_host
;
344 std::string new_path
;
345 if (separator
== std::string::npos
) {
346 new_host
= old_path
.substr(1);
348 new_host
= old_path
.substr(1, separator
- 1);
349 new_path
= old_path
.substr(separator
);
352 // Do not allow URLs with paths empty before the first slash since we can't
353 // have an empty host. (e.g "foo://chrome//")
354 if (new_host
.empty())
357 *url
= ReplaceURLHostAndPath(*url
, new_host
, new_path
);
359 DCHECK(url
->is_valid());
364 // Handles rewriting Web UI URLs.
365 bool HandleWebUI(GURL
* url
, content::BrowserContext
* browser_context
) {
366 // Do not handle special URLs such as "about:foo"
367 if (!url
->host().empty()) {
368 const GURL chrome_url
= AddUberHost(*url
);
370 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
372 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
373 browser_context
, chrome_url
))
377 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
378 browser_context
, *url
))
381 #if defined(OS_CHROMEOS)
382 // Special case : in ChromeOS in Guest mode bookmarks and history are
383 // disabled for security reasons. New tab page explains the reasons, so
384 // we redirect user to new tab page.
385 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
386 if (url
->SchemeIs(content::kChromeUIScheme
) &&
387 (url
->DomainIs(chrome::kChromeUIBookmarksHost
) ||
388 url
->DomainIs(chrome::kChromeUIHistoryHost
))) {
389 // Rewrite with new tab URL
390 *url
= GURL(chrome::kChromeUINewTabURL
);
398 // Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
400 bool HandleWebUIReverse(GURL
* url
, content::BrowserContext
* browser_context
) {
401 if (!url
->is_valid() || !url
->SchemeIs(content::kChromeUIScheme
))
404 return RemoveUberHost(url
);
407 // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
408 // below. Extension, and isolated apps require different privileges to be
409 // granted to their RenderProcessHosts. This classification allows us to make
410 // sure URLs are served by hosts with the right set of privileges.
411 enum RenderProcessHostPrivilege
{
418 RenderProcessHostPrivilege
GetPrivilegeRequiredByUrl(
420 ExtensionService
* service
) {
421 // Default to a normal renderer cause it is lower privileged. This should only
422 // occur if the URL on a site instance is either malformed, or uninitialized.
423 // If it is malformed, then there is no need for better privileges anyways.
424 // If it is uninitialized, but eventually settles on being an a scheme other
425 // than normal webrenderer, the navigation logic will correct us out of band
430 if (url
.SchemeIs(extensions::kExtensionScheme
)) {
431 const Extension
* extension
=
432 service
->extensions()->GetByID(url
.host());
434 extensions::AppIsolationInfo::HasIsolatedStorage(extension
))
435 return PRIV_ISOLATED
;
436 if (extension
&& extension
->is_hosted_app())
439 return PRIV_EXTENSION
;
445 RenderProcessHostPrivilege
GetProcessPrivilege(
446 content::RenderProcessHost
* process_host
,
447 extensions::ProcessMap
* process_map
,
448 ExtensionService
* service
) {
449 std::set
<std::string
> extension_ids
=
450 process_map
->GetExtensionsInProcess(process_host
->GetID());
451 if (extension_ids
.empty())
454 for (std::set
<std::string
>::iterator iter
= extension_ids
.begin();
455 iter
!= extension_ids
.end(); ++iter
) {
456 const Extension
* extension
= service
->GetExtensionById(*iter
, false);
458 extensions::AppIsolationInfo::HasIsolatedStorage(extension
))
459 return PRIV_ISOLATED
;
460 if (extension
&& extension
->is_hosted_app())
464 return PRIV_EXTENSION
;
467 bool CertMatchesFilter(const net::X509Certificate
& cert
,
468 const base::DictionaryValue
& filter
) {
469 // TODO(markusheintz): This is the minimal required filter implementation.
470 // Implement a better matcher.
472 // An empty filter matches any client certificate since no requirements are
477 std::string common_name
;
478 if (filter
.GetString("ISSUER.CN", &common_name
) &&
479 (cert
.issuer().common_name
== common_name
)) {
485 #if !defined(OS_ANDROID)
486 // Fills |map| with the per-script font prefs under path |map_name|.
487 void FillFontFamilyMap(const PrefService
* prefs
,
488 const char* map_name
,
489 webkit_glue::ScriptFontFamilyMap
* map
) {
490 // TODO: Get rid of the brute-force scan over possible (font family / script)
491 // combinations - see http://crbug.com/308095.
492 for (size_t i
= 0; i
< prefs::kWebKitScriptsForFontFamilyMapsLength
; ++i
) {
493 const char* script
= prefs::kWebKitScriptsForFontFamilyMaps
[i
];
494 std::string pref_name
= base::StringPrintf("%s.%s", map_name
, script
);
495 std::string font_family
= prefs
->GetString(pref_name
.c_str());
496 if (!font_family
.empty())
497 (*map
)[script
] = base::UTF8ToUTF16(font_family
);
501 #if defined(OS_POSIX) && !defined(OS_MACOSX)
502 breakpad::CrashHandlerHostLinux
* CreateCrashHandlerHost(
503 const std::string
& process_type
) {
504 base::FilePath dumps_path
;
505 PathService::Get(chrome::DIR_CRASH_DUMPS
, &dumps_path
);
507 ANNOTATE_SCOPED_MEMORY_LEAK
;
508 breakpad::CrashHandlerHostLinux
* crash_handler
=
509 new breakpad::CrashHandlerHostLinux(
510 process_type
, dumps_path
, getenv(env_vars::kHeadless
) == NULL
);
511 crash_handler
->StartUploaderThread();
512 return crash_handler
;
516 int GetCrashSignalFD(const CommandLine
& command_line
) {
517 if (command_line
.HasSwitch(extensions::switches::kExtensionProcess
)) {
518 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
520 crash_handler
= CreateCrashHandlerHost("extension");
521 return crash_handler
->GetDeathSignalSocket();
524 std::string process_type
=
525 command_line
.GetSwitchValueASCII(switches::kProcessType
);
527 if (process_type
== switches::kRendererProcess
) {
528 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
530 crash_handler
= CreateCrashHandlerHost(process_type
);
531 return crash_handler
->GetDeathSignalSocket();
534 if (process_type
== switches::kPluginProcess
) {
535 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
537 crash_handler
= CreateCrashHandlerHost(process_type
);
538 return crash_handler
->GetDeathSignalSocket();
541 if (process_type
== switches::kPpapiPluginProcess
) {
542 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
544 crash_handler
= CreateCrashHandlerHost(process_type
);
545 return crash_handler
->GetDeathSignalSocket();
548 if (process_type
== switches::kGpuProcess
) {
549 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
551 crash_handler
= CreateCrashHandlerHost(process_type
);
552 return crash_handler
->GetDeathSignalSocket();
557 #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
558 #endif // !defined(OS_ANDROID)
560 #if !defined(OS_CHROMEOS)
561 GURL
GetEffectiveURLForSignin(const GURL
& url
) {
562 CHECK(SigninManager::IsWebBasedSigninFlowURL(url
));
564 GURL
effective_url(SigninManager::kChromeSigninEffectiveSite
);
565 // Copy the path because the argument to SetPathStr must outlive
566 // the Replacements object.
567 const std::string
path_copy(url
.path());
568 GURL::Replacements replacements
;
569 replacements
.SetPathStr(path_copy
);
570 effective_url
= effective_url
.ReplaceComponents(replacements
);
571 return effective_url
;
575 void SetApplicationLocaleOnIOThread(const std::string
& locale
) {
576 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
577 g_io_thread_application_locale
.Get() = locale
;
580 void HandleBlockedPopupOnUIThread(const BlockedWindowParams
& params
) {
581 WebContents
* tab
= tab_util::GetWebContentsByID(params
.render_process_id(),
586 prerender::PrerenderContents
* prerender_contents
=
587 prerender::PrerenderContents::FromWebContents(tab
);
588 if (prerender_contents
) {
589 prerender_contents
->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW
);
593 PopupBlockerTabHelper
* popup_helper
=
594 PopupBlockerTabHelper::FromWebContents(tab
);
597 popup_helper
->AddBlockedPopup(params
);
600 #if defined(OS_ANDROID)
602 void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams
& params
) {
603 WebContents
* web_contents
=
604 tab_util::GetWebContentsByID(params
.render_process_id(),
609 SingleTabModeTabHelper::FromWebContents(web_contents
)->HandleOpenUrl(params
);
612 float GetDeviceScaleAdjustment() {
613 static const float kMinFSM
= 1.05f
;
614 static const int kWidthForMinFSM
= 320;
615 static const float kMaxFSM
= 1.3f
;
616 static const int kWidthForMaxFSM
= 800;
618 gfx::DeviceDisplayInfo info
;
619 int minWidth
= info
.GetSmallestDIPWidth();
621 if (minWidth
<= kWidthForMinFSM
)
623 if (minWidth
>= kWidthForMaxFSM
)
626 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
627 float ratio
= static_cast<float>(minWidth
- kWidthForMinFSM
) /
628 (kWidthForMaxFSM
- kWidthForMinFSM
);
629 return ratio
* (kMaxFSM
- kMinFSM
) + kMinFSM
;
632 #endif // defined(OS_ANDROID)
638 ChromeContentBrowserClient::ChromeContentBrowserClient() {
639 #if defined(ENABLE_PLUGINS)
640 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedFileHandleOrigins
); ++i
)
641 allowed_file_handle_origins_
.insert(kPredefinedAllowedFileHandleOrigins
[i
]);
642 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedSocketOrigins
); ++i
)
643 allowed_socket_origins_
.insert(kPredefinedAllowedSocketOrigins
[i
]);
646 permissions_policy_delegate_
.reset(
647 new extensions::BrowserPermissionsPolicyDelegate());
650 ChromeContentBrowserClient::~ChromeContentBrowserClient() {
654 void ChromeContentBrowserClient::RegisterProfilePrefs(
655 user_prefs::PrefRegistrySyncable
* registry
) {
656 registry
->RegisterBooleanPref(
657 prefs::kDisable3DAPIs
,
659 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
660 registry
->RegisterBooleanPref(
661 prefs::kEnableHyperlinkAuditing
,
663 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
667 void ChromeContentBrowserClient::SetApplicationLocale(
668 const std::string
& locale
) {
669 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
671 // This object is guaranteed to outlive all threads so we don't have to
672 // worry about the lack of refcounting and can just post as Unretained.
674 // The common case is that this function is called early in Chrome startup
675 // before any threads are created (it will also be called later if the user
676 // changes the pref). In this case, there will be no threads created and
677 // posting will fail. When there are no threads, we can just set the string
678 // without worrying about threadsafety.
679 if (!BrowserThread::PostTask(BrowserThread::IO
, FROM_HERE
,
680 base::Bind(&SetApplicationLocaleOnIOThread
, locale
))) {
681 g_io_thread_application_locale
.Get() = locale
;
685 content::BrowserMainParts
* ChromeContentBrowserClient::CreateBrowserMainParts(
686 const content::MainFunctionParams
& parameters
) {
687 ChromeBrowserMainParts
* main_parts
;
688 // Construct the Main browser parts based on the OS type.
690 main_parts
= new ChromeBrowserMainPartsWin(parameters
);
691 #elif defined(OS_MACOSX)
692 main_parts
= new ChromeBrowserMainPartsMac(parameters
);
693 #elif defined(OS_CHROMEOS)
694 main_parts
= new chromeos::ChromeBrowserMainPartsChromeos(parameters
);
695 #elif defined(OS_LINUX)
696 main_parts
= new ChromeBrowserMainPartsLinux(parameters
);
697 #elif defined(OS_ANDROID)
698 main_parts
= new ChromeBrowserMainPartsAndroid(parameters
);
699 #elif defined(OS_POSIX)
700 main_parts
= new ChromeBrowserMainPartsPosix(parameters
);
703 main_parts
= new ChromeBrowserMainParts(parameters
);
706 chrome::AddProfilesExtraParts(main_parts
);
708 // Construct additional browser parts. Stages are called in the order in
709 // which they are added.
710 #if defined(TOOLKIT_GTK)
711 main_parts
->AddParts(new ChromeBrowserMainExtraPartsGtk());
714 #if defined(TOOLKIT_VIEWS)
715 main_parts
->AddParts(new ChromeBrowserMainExtraPartsViews());
719 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAsh());
722 #if defined(USE_AURA)
723 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAura());
727 main_parts
->AddParts(new ChromeBrowserMainExtraPartsX11());
730 chrome::AddMetricsExtraParts(main_parts
);
735 std::string
ChromeContentBrowserClient::GetStoragePartitionIdForSite(
736 content::BrowserContext
* browser_context
,
738 std::string partition_id
;
740 // The partition ID for webview guest processes is the string value of its
741 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
742 if (site
.SchemeIs(content::kGuestScheme
)) {
743 partition_id
= site
.spec();
744 } else if (site
.GetOrigin().spec() == kChromeUIChromeSigninURL
) {
745 // Chrome signin page has an embedded iframe of extension and web content,
746 // thus it must be isolated from other webUI pages.
747 partition_id
= site
.GetOrigin().spec();
750 DCHECK(IsValidStoragePartitionId(browser_context
, partition_id
));
754 bool ChromeContentBrowserClient::IsValidStoragePartitionId(
755 content::BrowserContext
* browser_context
,
756 const std::string
& partition_id
) {
757 // The default ID is empty and is always valid.
758 if (partition_id
.empty())
761 return GURL(partition_id
).is_valid();
764 void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
765 content::BrowserContext
* browser_context
,
768 std::string
* partition_domain
,
769 std::string
* partition_name
,
771 // Default to the browser-wide storage partition and override based on |site|
773 partition_domain
->clear();
774 partition_name
->clear();
777 bool success
= GuestView::GetGuestPartitionConfigForSite(
778 site
, partition_domain
, partition_name
, in_memory
);
780 if (!success
&& site
.SchemeIs(extensions::kExtensionScheme
)) {
781 // If |can_be_default| is false, the caller is stating that the |site|
782 // should be parsed as if it had isolated storage. In particular it is
783 // important to NOT check ExtensionService for the is_storage_isolated()
784 // attribute because this code path is run during Extension uninstall
785 // to do cleanup after the Extension has already been unloaded from the
787 bool is_isolated
= !can_be_default
;
788 if (can_be_default
) {
789 if (extensions::util::SiteHasIsolatedStorage(site
, browser_context
))
794 CHECK(site
.has_host());
795 // For extensions with isolated storage, the the host of the |site| is
796 // the |partition_domain|. The |in_memory| and |partition_name| are only
797 // used in guest schemes so they are cleared here.
798 *partition_domain
= site
.host();
800 partition_name
->clear();
802 } else if (site
.GetOrigin().spec() == kChromeUIChromeSigninURL
) {
803 // Chrome signin page has an embedded iframe of extension and web content,
804 // thus it must be isolated from other webUI pages.
805 *partition_domain
= chrome::kChromeUIChromeSigninHost
;
808 // Assert that if |can_be_default| is false, the code above must have found a
809 // non-default partition. If this fails, the caller has a serious logic
810 // error about which StoragePartition they expect to be in and it is not
812 CHECK(can_be_default
|| !partition_domain
->empty());
815 content::WebContentsViewDelegate
*
816 ChromeContentBrowserClient::GetWebContentsViewDelegate(
817 content::WebContents
* web_contents
) {
818 return chrome::CreateWebContentsViewDelegate(web_contents
);
821 void ChromeContentBrowserClient::GuestWebContentsCreated(
822 SiteInstance
* guest_site_instance
,
823 WebContents
* guest_web_contents
,
824 WebContents
* opener_web_contents
,
825 content::BrowserPluginGuestDelegate
** guest_delegate
,
826 scoped_ptr
<base::DictionaryValue
> extra_params
) {
827 if (!guest_site_instance
) {
831 GURL guest_site_url
= guest_site_instance
->GetSiteURL();
832 const std::string
& extension_id
= guest_site_url
.host();
834 Profile
* profile
= Profile::FromBrowserContext(
835 guest_web_contents
->GetBrowserContext());
836 ExtensionService
* service
=
837 extensions::ExtensionSystem::Get(profile
)->extension_service();
843 /// TODO(fsamuel): In the future, certain types of GuestViews won't require
844 // extension bindings. At that point, we should clear |extension_id| instead
846 if (!service
->GetExtensionById(extension_id
, false) &&
847 !CommandLine::ForCurrentProcess()->HasSwitch(
848 switches::kEnableBrowserPluginForAllViewTypes
)) {
853 if (opener_web_contents
) {
854 GuestView
* guest
= GuestView::FromWebContents(opener_web_contents
);
860 // Create a new GuestView of the same type as the opener.
862 GuestView::Create(guest_web_contents
,
864 guest
->GetViewType());
872 std::string api_type
;
873 extra_params
->GetString(guestview::kParameterApi
, &api_type
);
875 if (api_type
.empty())
879 GuestView::Create(guest_web_contents
,
881 GuestView::GetViewTypeFromString(api_type
));
884 void ChromeContentBrowserClient::GuestWebContentsAttached(
885 WebContents
* guest_web_contents
,
886 WebContents
* embedder_web_contents
,
887 const base::DictionaryValue
& extra_params
) {
889 GuestView
* guest
= GuestView::FromWebContents(guest_web_contents
);
891 // It's ok to return here, since we could be running a browser plugin
892 // outside an extension, and don't need to attach a
893 // BrowserPluginGuestDelegate in that case;
894 // e.g. running with flag --enable-browser-plugin-for-all-view-types.
897 guest
->Attach(embedder_web_contents
, extra_params
);
900 void ChromeContentBrowserClient::RenderProcessWillLaunch(
901 content::RenderProcessHost
* host
) {
902 int id
= host
->GetID();
903 Profile
* profile
= Profile::FromBrowserContext(host
->GetBrowserContext());
904 net::URLRequestContextGetter
* context
=
905 profile
->GetRequestContextForRenderProcess(id
);
907 host
->AddFilter(new ChromeRenderMessageFilter(id
, profile
, context
));
908 host
->AddFilter(new extensions::ExtensionMessageFilter(id
, profile
));
909 #if defined(ENABLE_PLUGINS)
910 host
->AddFilter(new PluginInfoMessageFilter(id
, profile
));
912 host
->AddFilter(new cast::CastTransportHostFilter
);
913 #if defined(ENABLE_PRINTING)
914 host
->AddFilter(new PrintingMessageFilter(id
, profile
));
916 host
->AddFilter(new SearchProviderInstallStateMessageFilter(id
, profile
));
917 #if defined(ENABLE_SPELLCHECK)
918 host
->AddFilter(new SpellCheckMessageFilter(id
));
920 #if defined(OS_MACOSX)
921 host
->AddFilter(new SpellCheckMessageFilterMac(id
));
923 host
->AddFilter(new ChromeNetBenchmarkingMessageFilter(profile
, context
));
924 host
->AddFilter(new prerender::PrerenderMessageFilter(id
, profile
));
925 host
->AddFilter(new TtsMessageFilter(id
, profile
));
926 #if defined(ENABLE_WEBRTC)
927 WebRtcLoggingHandlerHost
* webrtc_logging_handler_host
=
928 new WebRtcLoggingHandlerHost(profile
);
929 host
->SetWebRtcLogMessageCallback(base::Bind(
930 &WebRtcLoggingHandlerHost::LogMessage
, webrtc_logging_handler_host
));
931 host
->AddFilter(webrtc_logging_handler_host
);
932 host
->SetUserData(host
, new base::UserDataAdapter
<WebRtcLoggingHandlerHost
>(
933 webrtc_logging_handler_host
));
935 #if !defined(DISABLE_NACL)
936 host
->AddFilter(new nacl::NaClHostMessageFilter(
937 id
, profile
->IsOffTheRecord(),
941 #if defined(OS_ANDROID)
942 host
->AddFilter(new EncryptedMediaMessageFilterAndroid());
944 if (switches::IsNewProfileManagement())
945 host
->AddFilter(new PrincipalsMessageFilter(id
));
947 host
->Send(new ChromeViewMsg_SetIsIncognitoProcess(
948 profile
->IsOffTheRecord()));
950 SendExtensionWebRequestStatusToHost(host
);
952 RendererContentSettingRules rules
;
953 if (host
->IsGuest()) {
954 GuestView::GetDefaultContentSettingRules(&rules
, profile
->IsOffTheRecord());
956 GetRendererContentSettingRules(
957 profile
->GetHostContentSettingsMap(), &rules
);
959 host
->Send(new ChromeViewMsg_SetContentSettingRules(rules
));
962 GURL
ChromeContentBrowserClient::GetEffectiveURL(
963 content::BrowserContext
* browser_context
, const GURL
& url
) {
964 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
968 // If the input |url| should be assigned to the Instant renderer, make its
969 // effective URL distinct from other URLs on the search provider's domain.
970 if (chrome::ShouldAssignURLToInstantRenderer(url
, profile
))
971 return chrome::GetEffectiveURLForInstant(url
, profile
);
973 #if !defined(OS_CHROMEOS)
974 // If the input |url| should be assigned to the Signin renderer, make its
975 // effective URL distinct from other URLs on the signin service's domain.
976 // Note that the signin renderer will be allowed to sign the user in to
978 if (SigninManager::IsWebBasedSigninFlowURL(url
))
979 return GetEffectiveURLForSignin(url
);
982 // If the input |url| is part of an installed app, the effective URL is an
983 // extension URL with the ID of that extension as the host. This has the
984 // effect of grouping apps together in a common SiteInstance.
985 ExtensionService
* extension_service
=
986 extensions::ExtensionSystem::Get(profile
)->extension_service();
987 if (!extension_service
)
990 const Extension
* extension
= extension_service
->extensions()->
991 GetHostedAppByURL(url
);
995 // Bookmark apps do not use the hosted app process model, and should be
996 // treated as normal URLs.
997 if (extension
->from_bookmark())
1000 // If the URL is part of an extension's web extent, convert it to an
1002 return extension
->GetResourceURL(url
.path());
1005 bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
1006 content::BrowserContext
* browser_context
, const GURL
& effective_url
) {
1007 // Non-extension, non-Instant URLs should generally use
1008 // process-per-site-instance. Because we expect to use the effective URL,
1009 // URLs for hosted apps (apart from bookmark apps) should have an extension
1012 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1016 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url
, profile
))
1019 #if !defined(OS_CHROMEOS)
1020 if (SigninManager::IsWebBasedSigninFlowURL(effective_url
))
1024 if (!effective_url
.SchemeIs(extensions::kExtensionScheme
))
1027 ExtensionService
* extension_service
=
1028 extensions::ExtensionSystem::Get(profile
)->extension_service();
1029 if (!extension_service
)
1032 const Extension
* extension
=
1033 extension_service
->extensions()->GetExtensionOrAppByURL(effective_url
);
1037 // If the URL is part of a hosted app that does not have the background
1038 // permission, or that does not allow JavaScript access to the background
1039 // page, we want to give each instance its own process to improve
1041 if (extension
->GetType() == Manifest::TYPE_HOSTED_APP
) {
1042 if (!extension
->HasAPIPermission(APIPermission::kBackground
) ||
1043 !extensions::BackgroundInfo::AllowJSAccess(extension
)) {
1048 // Hosted apps that have script access to their background page must use
1049 // process per site, since all instances can make synchronous calls to the
1050 // background window. Other extensions should use process per site as well.
1054 // These are treated as WebUI schemes but do not get WebUI bindings. Also,
1055 // view-source is allowed for these schemes.
1056 void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1057 std::vector
<std::string
>* additional_schemes
) {
1058 additional_schemes
->push_back(chrome::kChromeSearchScheme
);
1059 additional_schemes
->push_back(chrome::kDomDistillerScheme
);
1062 void ChromeContentBrowserClient::GetAdditionalWebUIHostsToIgnoreParititionCheck(
1063 std::vector
<std::string
>* hosts
) {
1064 hosts
->push_back(chrome::kChromeUIExtensionIconHost
);
1065 hosts
->push_back(chrome::kChromeUIFaviconHost
);
1066 hosts
->push_back(chrome::kChromeUIThemeHost
);
1067 hosts
->push_back(chrome::kChromeUIThumbnailHost
);
1068 hosts
->push_back(chrome::kChromeUIThumbnailHost2
);
1069 hosts
->push_back(chrome::kChromeUIThumbnailListHost
);
1072 net::URLRequestContextGetter
*
1073 ChromeContentBrowserClient::CreateRequestContext(
1074 content::BrowserContext
* browser_context
,
1075 content::ProtocolHandlerMap
* protocol_handlers
,
1076 content::ProtocolHandlerScopedVector protocol_interceptors
) {
1077 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1078 return profile
->CreateRequestContext(protocol_handlers
,
1079 protocol_interceptors
.Pass());
1082 net::URLRequestContextGetter
*
1083 ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
1084 content::BrowserContext
* browser_context
,
1085 const base::FilePath
& partition_path
,
1087 content::ProtocolHandlerMap
* protocol_handlers
,
1088 content::ProtocolHandlerScopedVector protocol_interceptors
) {
1089 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1090 return profile
->CreateRequestContextForStoragePartition(
1094 protocol_interceptors
.Pass());
1097 bool ChromeContentBrowserClient::IsHandledURL(const GURL
& url
) {
1098 return ProfileIOData::IsHandledURL(url
);
1101 bool ChromeContentBrowserClient::CanCommitURL(
1102 content::RenderProcessHost
* process_host
,
1104 // We need to let most extension URLs commit in any process, since this can
1105 // be allowed due to web_accessible_resources. Most hosted app URLs may also
1106 // load in any process (e.g., in an iframe). However, the Chrome Web Store
1107 // cannot be loaded in iframes and should never be requested outside its
1110 Profile::FromBrowserContext(process_host
->GetBrowserContext());
1111 ExtensionService
* service
=
1112 extensions::ExtensionSystem::Get(profile
)->extension_service();
1115 const Extension
* new_extension
=
1116 service
->extensions()->GetExtensionOrAppByURL(url
);
1117 if (new_extension
&&
1118 new_extension
->is_hosted_app() &&
1119 new_extension
->id() == extension_misc::kWebStoreAppId
&&
1120 !extensions::ProcessMap::Get(profile
)->
1121 Contains(new_extension
->id(), process_host
->GetID())) {
1128 bool ChromeContentBrowserClient::ShouldAllowOpenURL(
1129 content::SiteInstance
* site_instance
, const GURL
& url
) {
1130 GURL from_url
= site_instance
->GetSiteURL();
1131 // Do not allow pages from the web or other extensions navigate to
1132 // non-web-accessible extension resources.
1133 if (url
.SchemeIs(extensions::kExtensionScheme
) &&
1134 (from_url
.SchemeIsHTTPOrHTTPS() ||
1135 from_url
.SchemeIs(extensions::kExtensionScheme
))) {
1136 Profile
* profile
= Profile::FromBrowserContext(
1137 site_instance
->GetProcess()->GetBrowserContext());
1138 ExtensionService
* service
=
1139 extensions::ExtensionSystem::Get(profile
)->extension_service();
1142 const Extension
* extension
=
1143 service
->extensions()->GetExtensionOrAppByURL(url
);
1146 const Extension
* from_extension
=
1147 service
->extensions()->GetExtensionOrAppByURL(
1148 site_instance
->GetSiteURL());
1149 if (from_extension
&& from_extension
->id() == extension
->id())
1152 if (!extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible(
1153 extension
, url
.path()))
1159 bool ChromeContentBrowserClient::IsSuitableHost(
1160 content::RenderProcessHost
* process_host
,
1161 const GURL
& site_url
) {
1163 Profile::FromBrowserContext(process_host
->GetBrowserContext());
1164 // This may be NULL during tests. In that case, just assume any site can
1169 // Instant URLs should only be in the instant process and instant process
1170 // should only have Instant URLs.
1171 InstantService
* instant_service
=
1172 InstantServiceFactory::GetForProfile(profile
);
1173 if (instant_service
) {
1174 bool is_instant_process
= instant_service
->IsInstantProcess(
1175 process_host
->GetID());
1176 bool should_be_in_instant_process
=
1177 chrome::ShouldAssignURLToInstantRenderer(site_url
, profile
);
1178 if (is_instant_process
|| should_be_in_instant_process
)
1179 return is_instant_process
&& should_be_in_instant_process
;
1182 #if !defined(OS_CHROMEOS)
1183 SigninManager
* signin_manager
= SigninManagerFactory::GetForProfile(profile
);
1184 if (signin_manager
&& signin_manager
->IsSigninProcess(process_host
->GetID()))
1185 return SigninManager::IsWebBasedSigninFlowURL(site_url
);
1188 ExtensionService
* service
=
1189 extensions::ExtensionSystem::Get(profile
)->extension_service();
1190 extensions::ProcessMap
* process_map
= extensions::ProcessMap::Get(profile
);
1192 // Don't allow the Task Manager to share a process with anything else.
1193 // Otherwise it can affect the renderers it is observing.
1194 // Note: we could create another RenderProcessHostPrivilege bucket for
1195 // this to allow multiple chrome://tasks instances to share, but that's
1196 // a very unlikely case without serious consequences.
1197 if (site_url
.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL
).GetOrigin())
1200 // These may be NULL during tests. In that case, just assume any site can
1202 if (!service
|| !process_map
)
1205 // Otherwise, just make sure the process privilege matches the privilege
1206 // required by the site.
1207 RenderProcessHostPrivilege privilege_required
=
1208 GetPrivilegeRequiredByUrl(site_url
, service
);
1209 return GetProcessPrivilege(process_host
, process_map
, service
) ==
1213 // This function is trying to limit the amount of processes used by extensions
1214 // with background pages. It uses a globally set percentage of processes to
1215 // run such extensions and if the limit is exceeded, it returns true, to
1216 // indicate to the content module to group extensions together.
1217 bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1218 content::BrowserContext
* browser_context
, const GURL
& url
) {
1219 // It has to be a valid URL for us to check for an extension.
1220 if (!url
.is_valid())
1223 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1224 ExtensionService
* service
= !profile
? NULL
:
1225 extensions::ExtensionSystem::Get(profile
)->extension_service();
1229 // We have to have a valid extension with background page to proceed.
1230 const Extension
* extension
=
1231 service
->extensions()->GetExtensionOrAppByURL(url
);
1234 if (!extensions::BackgroundInfo::HasBackgroundPage(extension
))
1237 std::set
<int> process_ids
;
1238 size_t max_process_count
=
1239 content::RenderProcessHost::GetMaxRendererProcessCount();
1241 // Go through all profiles to ensure we have total count of extension
1242 // processes containing background pages, otherwise one profile can
1243 // starve the other.
1244 std::vector
<Profile
*> profiles
= g_browser_process
->profile_manager()->
1245 GetLoadedProfiles();
1246 for (size_t i
= 0; i
< profiles
.size(); ++i
) {
1247 extensions::ProcessManager
* epm
=
1248 extensions::ExtensionSystem::Get(profiles
[i
])->process_manager();
1249 for (extensions::ProcessManager::const_iterator iter
=
1250 epm
->background_hosts().begin();
1251 iter
!= epm
->background_hosts().end(); ++iter
) {
1252 const extensions::ExtensionHost
* host
= *iter
;
1253 process_ids
.insert(host
->render_process_host()->GetID());
1257 if (process_ids
.size() >
1258 (max_process_count
* chrome::kMaxShareOfExtensionProcesses
)) {
1265 void ChromeContentBrowserClient::SiteInstanceGotProcess(
1266 SiteInstance
* site_instance
) {
1267 CHECK(site_instance
->HasProcess());
1269 Profile
* profile
= Profile::FromBrowserContext(
1270 site_instance
->GetBrowserContext());
1274 // Remember the ID of the Instant process to signal the renderer process
1275 // on startup in |AppendExtraCommandLineSwitches| below.
1276 if (chrome::ShouldAssignURLToInstantRenderer(
1277 site_instance
->GetSiteURL(), profile
)) {
1278 InstantService
* instant_service
=
1279 InstantServiceFactory::GetForProfile(profile
);
1280 if (instant_service
)
1281 instant_service
->AddInstantProcess(site_instance
->GetProcess()->GetID());
1284 #if !defined(OS_CHROMEOS)
1285 // We only expect there to be one signin process as we use process-per-site
1286 // for signin URLs. The signin process will be cleared from SigninManager
1287 // when the renderer is destroyed.
1288 if (SigninManager::IsWebBasedSigninFlowURL(site_instance
->GetSiteURL())) {
1289 SigninManager
* signin_manager
=
1290 SigninManagerFactory::GetForProfile(profile
);
1292 signin_manager
->SetSigninProcess(site_instance
->GetProcess()->GetID());
1293 BrowserThread::PostTask(
1296 base::Bind(&InfoMap::SetSigninProcess
,
1297 extensions::ExtensionSystem::Get(profile
)->info_map(),
1298 site_instance
->GetProcess()->GetID()));
1302 ExtensionService
* service
=
1303 extensions::ExtensionSystem::Get(profile
)->extension_service();
1307 const Extension
* extension
= service
->extensions()->GetExtensionOrAppByURL(
1308 site_instance
->GetSiteURL());
1312 extensions::ProcessMap::Get(profile
)
1313 ->Insert(extension
->id(),
1314 site_instance
->GetProcess()->GetID(),
1315 site_instance
->GetId());
1317 BrowserThread::PostTask(
1320 base::Bind(&InfoMap::RegisterExtensionProcess
,
1321 extensions::ExtensionSystem::Get(profile
)->info_map(),
1323 site_instance
->GetProcess()->GetID(),
1324 site_instance
->GetId()));
1327 void ChromeContentBrowserClient::SiteInstanceDeleting(
1328 SiteInstance
* site_instance
) {
1329 if (!site_instance
->HasProcess())
1332 Profile
* profile
= Profile::FromBrowserContext(
1333 site_instance
->GetBrowserContext());
1334 ExtensionService
* service
=
1335 extensions::ExtensionSystem::Get(profile
)->extension_service();
1339 const Extension
* extension
= service
->extensions()->GetExtensionOrAppByURL(
1340 site_instance
->GetSiteURL());
1344 extensions::ProcessMap::Get(profile
)
1345 ->Remove(extension
->id(),
1346 site_instance
->GetProcess()->GetID(),
1347 site_instance
->GetId());
1349 BrowserThread::PostTask(
1352 base::Bind(&InfoMap::UnregisterExtensionProcess
,
1353 extensions::ExtensionSystem::Get(profile
)->info_map(),
1355 site_instance
->GetProcess()->GetID(),
1356 site_instance
->GetId()));
1359 void ChromeContentBrowserClient::WorkerProcessCreated(
1360 SiteInstance
* site_instance
,
1361 int worker_process_id
) {
1362 extensions::ExtensionRegistry
* extension_registry
=
1363 extensions::ExtensionRegistry::Get(site_instance
->GetBrowserContext());
1364 if (!extension_registry
)
1366 const Extension
* extension
=
1367 extension_registry
->enabled_extensions().GetExtensionOrAppByURL(
1368 site_instance
->GetSiteURL());
1371 extensions::ExtensionSystem
* extension_system
=
1372 extensions::ExtensionSystem::Get(site_instance
->GetBrowserContext());
1373 extension_system
->info_map()->RegisterExtensionWorkerProcess(
1376 site_instance
->GetId());
1379 void ChromeContentBrowserClient::WorkerProcessTerminated(
1380 SiteInstance
* site_instance
,
1381 int worker_process_id
) {
1382 extensions::ExtensionSystem
* extension_system
=
1383 extensions::ExtensionSystem::Get(site_instance
->GetBrowserContext());
1384 extension_system
->info_map()->UnregisterExtensionWorkerProcess(
1388 bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
1389 SiteInstance
* site_instance
,
1390 const GURL
& current_url
,
1391 const GURL
& new_url
) {
1392 // If we don't have an ExtensionService, then rely on the SiteInstance logic
1393 // in RenderFrameHostManager to decide when to swap.
1395 Profile::FromBrowserContext(site_instance
->GetBrowserContext());
1396 ExtensionService
* service
=
1397 extensions::ExtensionSystem::Get(profile
)->extension_service();
1401 // We must use a new BrowsingInstance (forcing a process swap and disabling
1402 // scripting by existing tabs) if one of the URLs is an extension and the
1403 // other is not the exact same extension.
1405 // We ignore hosted apps here so that other tabs in their BrowsingInstance can
1406 // use postMessage with them. (The exception is the Chrome Web Store, which
1407 // is a hosted app that requires its own BrowsingInstance.) Navigations
1408 // to/from a hosted app will still trigger a SiteInstance swap in
1409 // RenderFrameHostManager.
1410 const Extension
* current_extension
=
1411 service
->extensions()->GetExtensionOrAppByURL(current_url
);
1412 if (current_extension
&&
1413 current_extension
->is_hosted_app() &&
1414 current_extension
->id() != extension_misc::kWebStoreAppId
)
1415 current_extension
= NULL
;
1417 const Extension
* new_extension
=
1418 service
->extensions()->GetExtensionOrAppByURL(new_url
);
1419 if (new_extension
&&
1420 new_extension
->is_hosted_app() &&
1421 new_extension
->id() != extension_misc::kWebStoreAppId
)
1422 new_extension
= NULL
;
1424 // First do a process check. We should force a BrowsingInstance swap if the
1425 // current process doesn't know about new_extension, even if current_extension
1426 // is somehow the same as new_extension.
1427 extensions::ProcessMap
* process_map
= extensions::ProcessMap::Get(profile
);
1428 if (new_extension
&&
1429 site_instance
->HasProcess() &&
1430 !process_map
->Contains(
1431 new_extension
->id(), site_instance
->GetProcess()->GetID()))
1434 // Otherwise, swap BrowsingInstances if current_extension and new_extension
1436 return current_extension
!= new_extension
;
1439 bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1440 content::ResourceContext
* resource_context
, const GURL
& current_url
,
1441 const GURL
& new_url
) {
1442 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(resource_context
);
1443 return extensions::CrossesExtensionProcessBoundary(
1444 io_data
->GetExtensionInfoMap()->extensions(),
1445 current_url
, new_url
, false);
1448 bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL
& url
) {
1449 return !url
.SchemeIs(chrome::kChromeNativeScheme
);
1452 std::string
ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1453 const std::string
& alias_name
) {
1454 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name
);
1457 void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1458 CommandLine
* command_line
, int child_process_id
) {
1459 #if defined(OS_POSIX)
1460 if (breakpad::IsCrashReporterEnabled()) {
1461 std::string enable_crash_reporter
;
1462 GoogleUpdateSettings::GetMetricsId(&enable_crash_reporter
);
1463 #if !defined(OS_MACOSX)
1464 enable_crash_reporter
+= "," + base::GetLinuxDistro();
1466 command_line
->AppendSwitchASCII(switches::kEnableCrashReporter
,
1467 enable_crash_reporter
);
1471 if (logging::DialogsAreSuppressed())
1472 command_line
->AppendSwitch(switches::kNoErrorDialogs
);
1474 std::string process_type
=
1475 command_line
->GetSwitchValueASCII(switches::kProcessType
);
1476 const CommandLine
& browser_command_line
= *CommandLine::ForCurrentProcess();
1478 static const char* const kCommonSwitchNames
[] = {
1479 switches::kUserAgent
,
1480 switches::kUserDataDir
, // Make logs go to the right file.
1482 command_line
->CopySwitchesFrom(browser_command_line
, kCommonSwitchNames
,
1483 arraysize(kCommonSwitchNames
));
1485 #if defined(ENABLE_IPC_FUZZER)
1486 static const char* const kIpcFuzzerSwitches
[] = {
1487 switches::kIpcFuzzerTestcase
,
1489 command_line
->CopySwitchesFrom(browser_command_line
, kIpcFuzzerSwitches
,
1490 arraysize(kIpcFuzzerSwitches
));
1493 if (process_type
== switches::kRendererProcess
) {
1494 #if defined(OS_CHROMEOS)
1495 const std::string
& login_profile
=
1496 browser_command_line
.GetSwitchValueASCII(
1497 chromeos::switches::kLoginProfile
);
1498 if (!login_profile
.empty())
1499 command_line
->AppendSwitchASCII(
1500 chromeos::switches::kLoginProfile
, login_profile
);
1503 #if defined(ENABLE_WEBRTC)
1504 MaybeCopyDisableWebRtcEncryptionSwitch(command_line
,
1505 browser_command_line
,
1506 VersionInfo::GetChannel());
1509 content::RenderProcessHost
* process
=
1510 content::RenderProcessHost::FromID(child_process_id
);
1512 Profile
* profile
= Profile::FromBrowserContext(
1513 process
->GetBrowserContext());
1515 if (extensions::ProcessMap::Get(profile
)->Contains(process
->GetID()))
1516 command_line
->AppendSwitch(extensions::switches::kExtensionProcess
);
1518 PrefService
* prefs
= profile
->GetPrefs();
1519 // Currently this pref is only registered if applied via a policy.
1520 if (prefs
->HasPrefPath(prefs::kDisable3DAPIs
) &&
1521 prefs
->GetBoolean(prefs::kDisable3DAPIs
)) {
1522 // Turn this policy into a command line switch.
1523 command_line
->AppendSwitch(switches::kDisable3DAPIs
);
1526 // Disable client-side phishing detection in the renderer if it is
1527 // disabled in the Profile preferences or the browser process.
1528 if (!prefs
->GetBoolean(prefs::kSafeBrowsingEnabled
) ||
1529 !g_browser_process
->safe_browsing_detection_service()) {
1530 command_line
->AppendSwitch(
1531 switches::kDisableClientSidePhishingDetection
);
1534 if (!prefs
->GetBoolean(prefs::kPrintPreviewDisabled
))
1535 command_line
->AppendSwitch(switches::kRendererPrintPreview
);
1537 InstantService
* instant_service
=
1538 InstantServiceFactory::GetForProfile(profile
);
1539 if (instant_service
&&
1540 instant_service
->IsInstantProcess(process
->GetID()))
1541 command_line
->AppendSwitch(switches::kInstantProcess
);
1543 #if !defined(OS_CHROMEOS)
1544 SigninManager
* signin_manager
=
1545 SigninManagerFactory::GetForProfile(profile
);
1546 if (signin_manager
&& signin_manager
->IsSigninProcess(process
->GetID()))
1547 command_line
->AppendSwitch(switches::kSigninProcess
);
1551 // Please keep this in alphabetical order.
1552 static const char* const kSwitchNames
[] = {
1553 autofill::switches::kDisableIgnoreAutocompleteOff
,
1554 autofill::switches::kDisableInteractiveAutocomplete
,
1555 autofill::switches::kDisablePasswordGeneration
,
1556 autofill::switches::kEnableInteractiveAutocomplete
,
1557 autofill::switches::kEnablePasswordGeneration
,
1558 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration
,
1559 extensions::switches::kAllowHTTPBackgroundPage
,
1560 extensions::switches::kAllowLegacyExtensionManifests
,
1561 extensions::switches::kEnableExperimentalExtensionApis
,
1562 extensions::switches::kExtensionsOnChromeURLs
,
1563 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO
1565 switches::kAllowNaClFileHandleAPI
,
1566 switches::kAppsCheckoutURL
,
1567 switches::kAppsGalleryURL
,
1568 switches::kCloudPrintServiceURL
,
1569 switches::kDisableBundledPpapiFlash
,
1570 switches::kDisableExtensionsResourceWhitelist
,
1571 switches::kDisablePnacl
,
1572 switches::kDisableScriptedPrintThrottling
,
1573 switches::kEnableAdview
,
1574 switches::kEnableAppWindowControls
,
1575 switches::kEnableBenchmarking
,
1576 switches::kEnableNaCl
,
1577 switches::kEnableNaClDebug
,
1578 switches::kEnableNaClNonSfiMode
,
1579 switches::kEnableNetBenchmarking
,
1580 switches::kEnableOfflineAutoReload
,
1581 switches::kEnableStreamlinedHostedApps
,
1582 switches::kEnableWatchdog
,
1583 switches::kMemoryProfiling
,
1584 switches::kMessageLoopHistogrammer
,
1585 switches::kNoJsRandomness
,
1586 switches::kOutOfProcessPdf
,
1587 switches::kPlaybackMode
,
1588 switches::kPpapiFlashArgs
,
1589 switches::kPpapiFlashPath
,
1590 switches::kPpapiFlashVersion
,
1591 switches::kProfilingAtStart
,
1592 switches::kProfilingFile
,
1593 switches::kProfilingFlush
,
1594 switches::kRecordMode
,
1595 switches::kSilentDumpOnDCHECK
,
1596 switches::kWhitelistedExtensionID
,
1597 translate::switches::kTranslateSecurityOrigin
,
1600 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1601 arraysize(kSwitchNames
));
1602 } else if (process_type
== switches::kUtilityProcess
) {
1603 static const char* const kSwitchNames
[] = {
1604 extensions::switches::kAllowHTTPBackgroundPage
,
1605 extensions::switches::kEnableExperimentalExtensionApis
,
1606 extensions::switches::kExtensionsOnChromeURLs
,
1607 switches::kWhitelistedExtensionID
,
1610 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1611 arraysize(kSwitchNames
));
1612 } else if (process_type
== switches::kPluginProcess
) {
1613 static const char* const kSwitchNames
[] = {
1614 #if defined(OS_CHROMEOS)
1615 chromeos::switches::kLoginProfile
,
1617 switches::kMemoryProfiling
,
1618 switches::kSilentDumpOnDCHECK
,
1621 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1622 arraysize(kSwitchNames
));
1623 } else if (process_type
== switches::kZygoteProcess
) {
1624 static const char* const kSwitchNames
[] = {
1625 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
1626 switches::kDisableBundledPpapiFlash
,
1627 switches::kPpapiFlashPath
,
1628 switches::kPpapiFlashVersion
,
1631 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1632 arraysize(kSwitchNames
));
1633 } else if (process_type
== switches::kGpuProcess
) {
1634 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1635 // because GPU is expected to be unreliable.
1636 if (browser_command_line
.HasSwitch(switches::kIgnoreGpuBlacklist
) &&
1637 !command_line
->HasSwitch(switches::kDisableBreakpad
))
1638 command_line
->AppendSwitch(switches::kDisableBreakpad
);
1641 // The command line switch kEnableBenchmarking needs to be specified along
1642 // with the kEnableStatsTable switch to ensure that the stats table global
1643 // is initialized correctly.
1644 if (command_line
->HasSwitch(switches::kEnableBenchmarking
))
1645 DCHECK(command_line
->HasSwitch(switches::kEnableStatsTable
));
1648 std::string
ChromeContentBrowserClient::GetApplicationLocale() {
1649 if (BrowserThread::CurrentlyOn(BrowserThread::IO
))
1650 return g_io_thread_application_locale
.Get();
1651 return g_browser_process
->GetApplicationLocale();
1654 std::string
ChromeContentBrowserClient::GetAcceptLangs(
1655 content::BrowserContext
* context
) {
1656 Profile
* profile
= Profile::FromBrowserContext(context
);
1657 return profile
->GetPrefs()->GetString(prefs::kAcceptLanguages
);
1660 gfx::ImageSkia
* ChromeContentBrowserClient::GetDefaultFavicon() {
1661 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
1662 return rb
.GetImageSkiaNamed(IDR_DEFAULT_FAVICON
);
1665 bool ChromeContentBrowserClient::AllowAppCache(
1666 const GURL
& manifest_url
,
1667 const GURL
& first_party
,
1668 content::ResourceContext
* context
) {
1669 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1670 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1671 return io_data
->GetCookieSettings()->
1672 IsSettingCookieAllowed(manifest_url
, first_party
);
1675 bool ChromeContentBrowserClient::AllowGetCookie(
1677 const GURL
& first_party
,
1678 const net::CookieList
& cookie_list
,
1679 content::ResourceContext
* context
,
1680 int render_process_id
,
1681 int render_frame_id
) {
1682 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1683 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1684 bool allow
= io_data
->GetCookieSettings()->
1685 IsReadingCookieAllowed(url
, first_party
);
1687 BrowserThread::PostTask(
1688 BrowserThread::UI
, FROM_HERE
,
1689 base::Bind(&TabSpecificContentSettings::CookiesRead
, render_process_id
,
1690 render_frame_id
, url
, first_party
, cookie_list
, !allow
, true));
1694 bool ChromeContentBrowserClient::AllowSetCookie(
1696 const GURL
& first_party
,
1697 const std::string
& cookie_line
,
1698 content::ResourceContext
* context
,
1699 int render_process_id
,
1700 int render_frame_id
,
1701 net::CookieOptions
* options
) {
1702 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1703 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1704 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1705 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, first_party
);
1707 BrowserThread::PostTask(
1708 BrowserThread::UI
, FROM_HERE
,
1709 base::Bind(&TabSpecificContentSettings::CookieChanged
, render_process_id
,
1710 render_frame_id
, url
, first_party
, cookie_line
, *options
,
1715 bool ChromeContentBrowserClient::AllowSaveLocalState(
1716 content::ResourceContext
* context
) {
1717 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1718 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1719 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1720 ContentSetting setting
= cookie_settings
->GetDefaultCookieSetting(NULL
);
1722 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1723 // Could we even support per-origin settings?
1724 return setting
!= CONTENT_SETTING_SESSION_ONLY
;
1727 bool ChromeContentBrowserClient::AllowWorkerDatabase(
1729 const base::string16
& name
,
1730 const base::string16
& display_name
,
1731 unsigned long estimated_size
,
1732 content::ResourceContext
* context
,
1733 const std::vector
<std::pair
<int, int> >& render_frames
) {
1734 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1735 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1736 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1737 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1739 // Record access to database for potential display in UI.
1740 std::vector
<std::pair
<int, int> >::const_iterator i
;
1741 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1742 BrowserThread::PostTask(
1743 BrowserThread::UI
, FROM_HERE
,
1744 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed
,
1745 i
->first
, i
->second
, url
, name
, display_name
, !allow
));
1751 bool ChromeContentBrowserClient::AllowWorkerFileSystem(
1753 content::ResourceContext
* context
,
1754 const std::vector
<std::pair
<int, int> >& render_frames
) {
1755 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1756 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1757 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1758 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1760 // Record access to file system for potential display in UI.
1761 std::vector
<std::pair
<int, int> >::const_iterator i
;
1762 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1763 BrowserThread::PostTask(
1764 BrowserThread::UI
, FROM_HERE
,
1765 base::Bind(&TabSpecificContentSettings::FileSystemAccessed
,
1766 i
->first
, i
->second
, url
, !allow
));
1772 bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1774 const base::string16
& name
,
1775 content::ResourceContext
* context
,
1776 const std::vector
<std::pair
<int, int> >& render_frames
) {
1777 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1778 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1779 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1780 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1782 // Record access to IndexedDB for potential display in UI.
1783 std::vector
<std::pair
<int, int> >::const_iterator i
;
1784 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1785 BrowserThread::PostTask(
1786 BrowserThread::UI
, FROM_HERE
,
1787 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed
,
1788 i
->first
, i
->second
, url
, name
, !allow
));
1794 net::URLRequestContext
*
1795 ChromeContentBrowserClient::OverrideRequestContextForURL(
1796 const GURL
& url
, content::ResourceContext
* context
) {
1797 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1798 if (url
.SchemeIs(extensions::kExtensionScheme
)) {
1799 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1800 return io_data
->extensions_request_context();
1806 QuotaPermissionContext
*
1807 ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1808 return new ChromeQuotaPermissionContext();
1811 void ChromeContentBrowserClient::AllowCertificateError(
1812 int render_process_id
,
1813 int render_frame_id
,
1815 const net::SSLInfo
& ssl_info
,
1816 const GURL
& request_url
,
1817 ResourceType::Type resource_type
,
1819 bool strict_enforcement
,
1820 const base::Callback
<void(bool)>& callback
,
1821 content::CertificateRequestResultType
* result
) {
1822 if (resource_type
!= ResourceType::MAIN_FRAME
) {
1823 // A sub-resource has a certificate error. The user doesn't really
1824 // have a context for making the right decision, so block the
1825 // request hard, without an info bar to allow showing the insecure
1827 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY
;
1831 // If the tab is being prerendered, cancel the prerender and the request.
1832 content::RenderFrameHost
* render_frame_host
=
1833 content::RenderFrameHost::FromID(render_process_id
, render_frame_id
);
1834 WebContents
* tab
= WebContents::FromRenderFrameHost(render_frame_host
);
1840 prerender::PrerenderContents
* prerender_contents
=
1841 prerender::PrerenderContents::FromWebContents(tab
);
1842 if (prerender_contents
) {
1843 prerender_contents
->Destroy(prerender::FINAL_STATUS_SSL_ERROR
);
1844 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL
;
1848 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
1849 captive_portal::CaptivePortalTabHelper
* captive_portal_tab_helper
=
1850 captive_portal::CaptivePortalTabHelper::FromWebContents(tab
);
1851 if (captive_portal_tab_helper
)
1852 captive_portal_tab_helper
->OnSSLCertError(ssl_info
);
1855 // Otherwise, display an SSL blocking page.
1856 new SSLBlockingPage(tab
, cert_error
, ssl_info
, request_url
, overridable
,
1857 strict_enforcement
, callback
);
1860 void ChromeContentBrowserClient::SelectClientCertificate(
1861 int render_process_id
,
1862 int render_frame_id
,
1863 const net::HttpNetworkSession
* network_session
,
1864 net::SSLCertRequestInfo
* cert_request_info
,
1865 const base::Callback
<void(net::X509Certificate
*)>& callback
) {
1866 content::RenderFrameHost
* rfh
= content::RenderFrameHost::FromID(
1867 render_process_id
, render_frame_id
);
1868 WebContents
* tab
= WebContents::FromRenderFrameHost(rfh
);
1874 prerender::PrerenderContents
* prerender_contents
=
1875 prerender::PrerenderContents::FromWebContents(tab
);
1876 if (prerender_contents
) {
1877 prerender_contents
->Destroy(
1878 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED
);
1882 GURL
requesting_url("https://" + cert_request_info
->host_and_port
.ToString());
1883 DCHECK(requesting_url
.is_valid())
1884 << "Invalid URL string: https://"
1885 << cert_request_info
->host_and_port
.ToString();
1887 Profile
* profile
= Profile::FromBrowserContext(tab
->GetBrowserContext());
1888 scoped_ptr
<base::Value
> filter(
1889 profile
->GetHostContentSettingsMap()->GetWebsiteSetting(
1892 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE
,
1893 std::string(), NULL
));
1896 // Try to automatically select a client certificate.
1897 if (filter
->IsType(base::Value::TYPE_DICTIONARY
)) {
1898 base::DictionaryValue
* filter_dict
=
1899 static_cast<base::DictionaryValue
*>(filter
.get());
1901 const std::vector
<scoped_refptr
<net::X509Certificate
> >&
1902 all_client_certs
= cert_request_info
->client_certs
;
1903 for (size_t i
= 0; i
< all_client_certs
.size(); ++i
) {
1904 if (CertMatchesFilter(*all_client_certs
[i
].get(), *filter_dict
)) {
1905 // Use the first certificate that is matched by the filter.
1906 callback
.Run(all_client_certs
[i
].get());
1915 SSLTabHelper
* ssl_tab_helper
= SSLTabHelper::FromWebContents(tab
);
1916 if (!ssl_tab_helper
) {
1917 // If there is no SSLTabHelper for the given WebContents then we can't
1918 // show the user a dialog to select a client certificate. So we simply
1919 // proceed with no client certificate.
1923 ssl_tab_helper
->ShowClientCertificateRequestDialog(
1924 network_session
, cert_request_info
, callback
);
1927 void ChromeContentBrowserClient::AddCertificate(
1928 net::URLRequest
* request
,
1929 net::CertificateMimeType cert_type
,
1930 const void* cert_data
,
1932 int render_process_id
,
1933 int render_view_id
) {
1934 chrome::SSLAddCertificate(request
, cert_type
, cert_data
, cert_size
,
1935 render_process_id
, render_view_id
);
1938 content::MediaObserver
* ChromeContentBrowserClient::GetMediaObserver() {
1939 return MediaCaptureDevicesDispatcher::GetInstance();
1942 void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1943 const GURL
& source_origin
,
1944 int callback_context
,
1945 int render_process_id
,
1946 int render_view_id
) {
1947 #if defined(ENABLE_NOTIFICATIONS)
1948 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
1949 WebContents
* contents
=
1950 tab_util::GetWebContentsByID(render_process_id
, render_view_id
);
1956 // Skip showing the infobar if the request comes from an extension, and that
1957 // extension has the 'notify' permission. (If the extension does not have the
1958 // permission, the user will still be prompted.)
1959 Profile
* profile
= Profile::FromBrowserContext(contents
->GetBrowserContext());
1960 InfoMap
* extension_info_map
=
1961 extensions::ExtensionSystem::Get(profile
)->info_map();
1962 DesktopNotificationService
* notification_service
=
1963 DesktopNotificationServiceFactory::GetForProfile(profile
);
1964 const Extension
* extension
= NULL
;
1965 if (extension_info_map
) {
1966 extensions::ExtensionSet extensions
;
1967 extension_info_map
->GetExtensionsWithAPIPermissionForSecurityOrigin(
1968 source_origin
, render_process_id
,
1969 extensions::APIPermission::kNotification
, &extensions
);
1970 for (extensions::ExtensionSet::const_iterator iter
= extensions
.begin();
1971 iter
!= extensions
.end(); ++iter
) {
1972 if (notification_service
->IsNotifierEnabled(NotifierId(
1973 NotifierId::APPLICATION
, (*iter
)->id()))) {
1974 extension
= iter
->get();
1979 RenderViewHost
* rvh
=
1980 RenderViewHost::FromID(render_process_id
, render_view_id
);
1981 if (IsExtensionWithPermissionOrSuggestInConsole(
1982 APIPermission::kNotification
, extension
, rvh
)) {
1984 rvh
->DesktopNotificationPermissionRequestDone(callback_context
);
1988 notification_service
->RequestPermission(source_origin
, render_process_id
,
1989 render_view_id
, callback_context
, contents
);
1995 blink::WebNotificationPresenter::Permission
1996 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
1997 const GURL
& source_origin
,
1998 content::ResourceContext
* context
,
1999 int render_process_id
) {
2000 #if defined(ENABLE_NOTIFICATIONS)
2001 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
2003 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
2004 InfoMap
* extension_info_map
= io_data
->GetExtensionInfoMap();
2006 // We want to see if there is an extension that hasn't been manually disabled
2007 // that has the notifications permission and applies to this security origin.
2008 // First, get the list of extensions with permission for the origin.
2009 extensions::ExtensionSet extensions
;
2010 extension_info_map
->GetExtensionsWithAPIPermissionForSecurityOrigin(
2011 source_origin
, render_process_id
,
2012 extensions::APIPermission::kNotification
, &extensions
);
2013 for (extensions::ExtensionSet::const_iterator iter
= extensions
.begin();
2014 iter
!= extensions
.end(); ++iter
) {
2015 // Then, check to see if it's been disabled by the user.
2016 if (!extension_info_map
->AreNotificationsDisabled((*iter
)->id()))
2017 return blink::WebNotificationPresenter::PermissionAllowed
;
2020 // No enabled extensions exist, so check the normal host content settings.
2021 HostContentSettingsMap
* host_content_settings_map
=
2022 io_data
->GetHostContentSettingsMap();
2023 ContentSetting setting
= host_content_settings_map
->GetContentSetting(
2026 CONTENT_SETTINGS_TYPE_NOTIFICATIONS
,
2027 NO_RESOURCE_IDENTIFIER
);
2029 if (setting
== CONTENT_SETTING_ALLOW
)
2030 return blink::WebNotificationPresenter::PermissionAllowed
;
2031 if (setting
== CONTENT_SETTING_BLOCK
)
2032 return blink::WebNotificationPresenter::PermissionDenied
;
2033 return blink::WebNotificationPresenter::PermissionNotAllowed
;
2035 return blink::WebNotificationPresenter::PermissionAllowed
;
2039 void ChromeContentBrowserClient::ShowDesktopNotification(
2040 const content::ShowDesktopNotificationHostMsgParams
& params
,
2041 int render_process_id
,
2044 #if defined(ENABLE_NOTIFICATIONS)
2045 RenderViewHost
* rvh
= RenderViewHost::FromID(
2046 render_process_id
, render_view_id
);
2052 content::RenderProcessHost
* process
= rvh
->GetProcess();
2053 Profile
* profile
= Profile::FromBrowserContext(process
->GetBrowserContext());
2054 DesktopNotificationService
* service
=
2055 DesktopNotificationServiceFactory::GetForProfile(profile
);
2056 service
->ShowDesktopNotification(
2057 params
, render_process_id
, render_view_id
,
2058 worker
? DesktopNotificationService::WorkerNotification
:
2059 DesktopNotificationService::PageNotification
);
2065 void ChromeContentBrowserClient::CancelDesktopNotification(
2066 int render_process_id
,
2068 int notification_id
) {
2069 #if defined(ENABLE_NOTIFICATIONS)
2070 RenderViewHost
* rvh
= RenderViewHost::FromID(
2071 render_process_id
, render_view_id
);
2077 content::RenderProcessHost
* process
= rvh
->GetProcess();
2078 Profile
* profile
= Profile::FromBrowserContext(process
->GetBrowserContext());
2079 DesktopNotificationService
* service
=
2080 DesktopNotificationServiceFactory::GetForProfile(profile
);
2081 service
->CancelDesktopNotification(
2082 render_process_id
, render_view_id
, notification_id
);
2088 bool ChromeContentBrowserClient::CanCreateWindow(
2089 const GURL
& opener_url
,
2090 const GURL
& opener_top_level_frame_url
,
2091 const GURL
& source_origin
,
2092 WindowContainerType container_type
,
2093 const GURL
& target_url
,
2094 const content::Referrer
& referrer
,
2095 WindowOpenDisposition disposition
,
2096 const WebWindowFeatures
& features
,
2098 bool opener_suppressed
,
2099 content::ResourceContext
* context
,
2100 int render_process_id
,
2103 bool* no_javascript_access
) {
2104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
2106 *no_javascript_access
= false;
2108 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
2109 InfoMap
* map
= io_data
->GetExtensionInfoMap();
2111 // If the opener is trying to create a background window but doesn't have
2112 // the appropriate permission, fail the attempt.
2113 if (container_type
== WINDOW_CONTAINER_TYPE_BACKGROUND
) {
2114 if (!map
->SecurityOriginHasAPIPermission(
2117 APIPermission::kBackground
)) {
2121 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2122 // return a recently installed Extension even if this CanCreateWindow call
2123 // was made by an old copy of the page in a normal web process. That's ok,
2124 // because the permission check above would have caused an early return
2125 // already. We must use the full URL to find hosted apps, though, and not
2127 const Extension
* extension
=
2128 map
->extensions().GetExtensionOrAppByURL(opener_url
);
2129 if (extension
&& !extensions::BackgroundInfo::AllowJSAccess(extension
))
2130 *no_javascript_access
= true;
2135 // No new browser window (popup or tab) in app mode.
2136 if (container_type
== WINDOW_CONTAINER_TYPE_NORMAL
&&
2137 chrome::IsRunningInForcedAppMode()) {
2144 HostContentSettingsMap
* content_settings
=
2145 ProfileIOData::FromResourceContext(context
)->GetHostContentSettingsMap();
2146 BlockedWindowParams
blocked_params(target_url
,
2155 if (!user_gesture
&& !CommandLine::ForCurrentProcess()->HasSwitch(
2156 switches::kDisablePopupBlocking
)) {
2157 if (content_settings
->GetContentSetting(opener_top_level_frame_url
,
2158 opener_top_level_frame_url
,
2159 CONTENT_SETTINGS_TYPE_POPUPS
,
2161 CONTENT_SETTING_ALLOW
) {
2162 BrowserThread::PostTask(BrowserThread::UI
,
2164 base::Bind(&HandleBlockedPopupOnUIThread
,
2170 #if defined(OS_ANDROID)
2171 if (SingleTabModeTabHelper::IsRegistered(render_process_id
, opener_id
)) {
2172 BrowserThread::PostTask(BrowserThread::UI
,
2174 base::Bind(&HandleSingleTabModeBlockOnUIThread
,
2183 std::string
ChromeContentBrowserClient::GetWorkerProcessTitle(
2184 const GURL
& url
, content::ResourceContext
* context
) {
2185 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
2186 // Check if it's an extension-created worker, in which case we want to use
2187 // the name of the extension.
2188 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
2189 const Extension
* extension
=
2190 io_data
->GetExtensionInfoMap()->extensions().GetByID(url
.host());
2191 return extension
? extension
->name() : std::string();
2194 void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2195 return g_browser_process
->ResourceDispatcherHostCreated();
2198 // TODO(tommi): Rename from Get to Create.
2199 content::SpeechRecognitionManagerDelegate
*
2200 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
2201 #if defined(ENABLE_INPUT_SPEECH)
2202 return new speech::ChromeSpeechRecognitionManagerDelegateBubbleUI();
2204 // Platforms who don't implement x-webkit-speech (a.k.a INPUT_SPEECH) just
2205 // need the base delegate without the bubble UI.
2206 return new speech::ChromeSpeechRecognitionManagerDelegate();
2210 net::NetLog
* ChromeContentBrowserClient::GetNetLog() {
2211 return g_browser_process
->net_log();
2214 AccessTokenStore
* ChromeContentBrowserClient::CreateAccessTokenStore() {
2215 return new ChromeAccessTokenStore();
2218 bool ChromeContentBrowserClient::IsFastShutdownPossible() {
2222 void ChromeContentBrowserClient::OverrideWebkitPrefs(
2223 RenderViewHost
* rvh
, const GURL
& url
, WebPreferences
* web_prefs
) {
2224 Profile
* profile
= Profile::FromBrowserContext(
2225 rvh
->GetProcess()->GetBrowserContext());
2226 PrefService
* prefs
= profile
->GetPrefs();
2228 // Fill per-script font preferences. These are not registered on Android
2229 // - http://crbug.com/308033.
2230 #if !defined(OS_ANDROID)
2231 FillFontFamilyMap(prefs
, prefs::kWebKitStandardFontFamilyMap
,
2232 &web_prefs
->standard_font_family_map
);
2233 FillFontFamilyMap(prefs
, prefs::kWebKitFixedFontFamilyMap
,
2234 &web_prefs
->fixed_font_family_map
);
2235 FillFontFamilyMap(prefs
, prefs::kWebKitSerifFontFamilyMap
,
2236 &web_prefs
->serif_font_family_map
);
2237 FillFontFamilyMap(prefs
, prefs::kWebKitSansSerifFontFamilyMap
,
2238 &web_prefs
->sans_serif_font_family_map
);
2239 FillFontFamilyMap(prefs
, prefs::kWebKitCursiveFontFamilyMap
,
2240 &web_prefs
->cursive_font_family_map
);
2241 FillFontFamilyMap(prefs
, prefs::kWebKitFantasyFontFamilyMap
,
2242 &web_prefs
->fantasy_font_family_map
);
2243 FillFontFamilyMap(prefs
, prefs::kWebKitPictographFontFamilyMap
,
2244 &web_prefs
->pictograph_font_family_map
);
2247 web_prefs
->default_font_size
=
2248 prefs
->GetInteger(prefs::kWebKitDefaultFontSize
);
2249 web_prefs
->default_fixed_font_size
=
2250 prefs
->GetInteger(prefs::kWebKitDefaultFixedFontSize
);
2251 web_prefs
->minimum_font_size
=
2252 prefs
->GetInteger(prefs::kWebKitMinimumFontSize
);
2253 web_prefs
->minimum_logical_font_size
=
2254 prefs
->GetInteger(prefs::kWebKitMinimumLogicalFontSize
);
2256 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2258 web_prefs
->javascript_can_open_windows_automatically
=
2259 prefs
->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically
);
2260 web_prefs
->dom_paste_enabled
=
2261 prefs
->GetBoolean(prefs::kWebKitDomPasteEnabled
);
2262 web_prefs
->shrinks_standalone_images_to_fit
=
2263 prefs
->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit
);
2264 const base::DictionaryValue
* inspector_settings
=
2265 prefs
->GetDictionary(prefs::kWebKitInspectorSettings
);
2266 if (inspector_settings
) {
2267 for (base::DictionaryValue::Iterator
iter(*inspector_settings
);
2271 if (iter
.value().GetAsString(&value
)) {
2272 web_prefs
->inspector_settings
.push_back(
2273 std::make_pair(iter
.key(), value
));
2277 web_prefs
->tabs_to_links
= prefs
->GetBoolean(prefs::kWebkitTabsToLinks
);
2279 if (!prefs
->GetBoolean(prefs::kWebKitJavascriptEnabled
))
2280 web_prefs
->javascript_enabled
= false;
2281 if (!prefs
->GetBoolean(prefs::kWebKitWebSecurityEnabled
))
2282 web_prefs
->web_security_enabled
= false;
2283 if (!prefs
->GetBoolean(prefs::kWebKitPluginsEnabled
))
2284 web_prefs
->plugins_enabled
= false;
2285 if (!prefs
->GetBoolean(prefs::kWebKitJavaEnabled
))
2286 web_prefs
->java_enabled
= false;
2287 web_prefs
->loads_images_automatically
=
2288 prefs
->GetBoolean(prefs::kWebKitLoadsImagesAutomatically
);
2290 if (prefs
->GetBoolean(prefs::kDisable3DAPIs
))
2291 web_prefs
->experimental_webgl_enabled
= false;
2293 web_prefs
->allow_displaying_insecure_content
=
2294 prefs
->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent
);
2295 web_prefs
->allow_running_insecure_content
=
2296 prefs
->GetBoolean(prefs::kWebKitAllowRunningInsecureContent
);
2297 #if defined(OS_ANDROID)
2298 web_prefs
->font_scale_factor
=
2299 static_cast<float>(prefs
->GetDouble(prefs::kWebKitFontScaleFactor
));
2300 web_prefs
->device_scale_adjustment
= GetDeviceScaleAdjustment();
2301 web_prefs
->force_enable_zoom
=
2302 prefs
->GetBoolean(prefs::kWebKitForceEnableZoom
);
2305 #if defined(OS_ANDROID)
2306 web_prefs
->password_echo_enabled
=
2307 prefs
->GetBoolean(prefs::kWebKitPasswordEchoEnabled
);
2309 web_prefs
->password_echo_enabled
= browser_defaults::kPasswordEchoEnabled
;
2312 web_prefs
->asynchronous_spell_checking_enabled
= true;
2313 web_prefs
->unified_textchecker_enabled
= true;
2315 web_prefs
->uses_universal_detector
=
2316 prefs
->GetBoolean(prefs::kWebKitUsesUniversalDetector
);
2317 web_prefs
->text_areas_are_resizable
=
2318 prefs
->GetBoolean(prefs::kWebKitTextAreasAreResizable
);
2319 web_prefs
->hyperlink_auditing_enabled
=
2320 prefs
->GetBoolean(prefs::kEnableHyperlinkAuditing
);
2322 // Make sure we will set the default_encoding with canonical encoding name.
2323 web_prefs
->default_encoding
=
2324 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
2325 web_prefs
->default_encoding
);
2326 if (web_prefs
->default_encoding
.empty()) {
2327 prefs
->ClearPref(prefs::kDefaultCharset
);
2328 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2330 DCHECK(!web_prefs
->default_encoding
.empty());
2332 WebContents
* web_contents
= WebContents::FromRenderViewHost(rvh
);
2333 extensions::ViewType view_type
= extensions::GetViewType(web_contents
);
2334 ExtensionService
* service
=
2335 extensions::ExtensionSystem::Get(profile
)->extension_service();
2337 const GURL
& site_url
= rvh
->GetSiteInstance()->GetSiteURL();
2338 const Extension
* extension
=
2339 service
->extensions()->GetByID(site_url
.host());
2340 // Ensure that we are only granting extension preferences to URLs with
2341 // the correct scheme. Without this check, chrome-guest:// schemes used by
2342 // webview tags as well as hosts that happen to match the id of an
2343 // installed extension would get the wrong preferences.
2344 if (site_url
.SchemeIs(extensions::kExtensionScheme
)) {
2345 extension_webkit_preferences::SetPreferences(
2346 extension
, view_type
, web_prefs
);
2350 if (view_type
== extensions::VIEW_TYPE_NOTIFICATION
) {
2351 web_prefs
->allow_scripts_to_close_windows
= true;
2352 } else if (view_type
== extensions::VIEW_TYPE_BACKGROUND_CONTENTS
) {
2353 // Disable all kinds of acceleration for background pages.
2354 // See http://crbug.com/96005 and http://crbug.com/96006
2355 web_prefs
->force_compositing_mode
= false;
2356 web_prefs
->accelerated_compositing_enabled
= false;
2359 #if defined(OS_CHROMEOS)
2360 // Override the default of suppressing HW compositing for WebUI pages for the
2361 // file manager, which is implemented using WebUI but wants HW acceleration
2362 // for video decode & render.
2363 if (url
.SchemeIs(extensions::kExtensionScheme
) &&
2364 url
.host() == file_manager::kFileManagerAppId
) {
2365 web_prefs
->accelerated_compositing_enabled
= true;
2366 web_prefs
->accelerated_2d_canvas_enabled
= true;
2371 void ChromeContentBrowserClient::UpdateInspectorSetting(
2372 RenderViewHost
* rvh
, const std::string
& key
, const std::string
& value
) {
2373 content::BrowserContext
* browser_context
=
2374 rvh
->GetProcess()->GetBrowserContext();
2375 DictionaryPrefUpdate
update(
2376 Profile::FromBrowserContext(browser_context
)->GetPrefs(),
2377 prefs::kWebKitInspectorSettings
);
2378 base::DictionaryValue
* inspector_settings
= update
.Get();
2379 inspector_settings
->SetWithoutPathExpansion(
2380 key
, base::Value::CreateStringValue(value
));
2383 void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2384 BrowserURLHandler
* handler
) {
2385 // Add the default URL handlers.
2386 handler
->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride
,
2387 BrowserURLHandler::null_handler());
2388 handler
->AddHandlerPair(BrowserURLHandler::null_handler(),
2389 &ExtensionWebUI::HandleChromeURLOverrideReverse
);
2391 // about: handler. Must come before chrome: handler, since it will
2392 // rewrite about: urls to chrome: URLs and then expect chrome: to
2393 // actually handle them.
2394 handler
->AddHandlerPair(&WillHandleBrowserAboutURL
,
2395 BrowserURLHandler::null_handler());
2397 // Handler to rewrite chrome://newtab for InstantExtended.
2398 handler
->AddHandlerPair(&chrome::HandleNewTabURLRewrite
,
2399 &chrome::HandleNewTabURLReverseRewrite
);
2401 // chrome: & friends.
2402 handler
->AddHandlerPair(&HandleWebUI
, &HandleWebUIReverse
);
2405 void ChromeContentBrowserClient::ClearCache(RenderViewHost
* rvh
) {
2406 Profile
* profile
= Profile::FromBrowserContext(
2407 rvh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2408 BrowsingDataRemover
* remover
=
2409 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2410 remover
->Remove(BrowsingDataRemover::REMOVE_CACHE
,
2411 BrowsingDataHelper::UNPROTECTED_WEB
);
2412 // BrowsingDataRemover takes care of deleting itself when done.
2415 void ChromeContentBrowserClient::ClearCookies(RenderViewHost
* rvh
) {
2416 Profile
* profile
= Profile::FromBrowserContext(
2417 rvh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2418 BrowsingDataRemover
* remover
=
2419 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2420 int remove_mask
= BrowsingDataRemover::REMOVE_SITE_DATA
;
2421 remover
->Remove(remove_mask
, BrowsingDataHelper::UNPROTECTED_WEB
);
2422 // BrowsingDataRemover takes care of deleting itself when done.
2425 base::FilePath
ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
2426 return DownloadPrefs::GetDefaultDownloadDirectory();
2429 std::string
ChromeContentBrowserClient::GetDefaultDownloadName() {
2430 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME
);
2433 void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2434 content::BrowserPpapiHost
* browser_host
) {
2435 #if defined(ENABLE_PLUGINS)
2436 browser_host
->GetPpapiHost()->AddHostFactoryFilter(
2437 scoped_ptr
<ppapi::host::HostFactory
>(
2438 new ChromeBrowserPepperHostFactory(browser_host
)));
2442 content::BrowserPpapiHost
*
2443 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2444 int plugin_process_id
) {
2445 BrowserChildProcessHostIterator
iter(PROCESS_TYPE_NACL_LOADER
);
2446 while (!iter
.Done()) {
2447 nacl::NaClProcessHost
* host
= static_cast<nacl::NaClProcessHost
*>(
2448 iter
.GetDelegate());
2449 if (host
->process() &&
2450 host
->process()->GetData().id
== plugin_process_id
) {
2451 // Found the plugin.
2452 return host
->browser_ppapi_host();
2459 bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2460 content::BrowserContext
* browser_context
, const GURL
& site_url
) {
2461 if (CommandLine::ForCurrentProcess()->HasSwitch(
2462 switches::kEnableBrowserPluginForAllViewTypes
))
2465 if (content::HasWebUIScheme(site_url
))
2468 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
2469 ExtensionService
* service
=
2470 extensions::ExtensionSystem::Get(profile
)->extension_service();
2474 const Extension
* extension
=
2475 service
->extensions()->GetExtensionOrAppByURL(site_url
);
2479 return extension
->HasAPIPermission(APIPermission::kWebView
) ||
2480 extension
->HasAPIPermission(APIPermission::kAdView
);
2483 bool ChromeContentBrowserClient::AllowPepperSocketAPI(
2484 content::BrowserContext
* browser_context
,
2487 const content::SocketPermissionRequest
* params
) {
2488 #if defined(ENABLE_PLUGINS)
2489 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
2490 const extensions::ExtensionSet
* extension_set
= NULL
;
2492 extension_set
= extensions::ExtensionSystem::Get(profile
)->
2493 extension_service()->extensions();
2497 // Access to private socket APIs is controlled by the whitelist.
2498 if (IsExtensionOrSharedModuleWhitelisted(url
, extension_set
,
2499 allowed_socket_origins_
)) {
2503 // Access to public socket APIs is controlled by extension permissions.
2504 if (url
.is_valid() && url
.SchemeIs(extensions::kExtensionScheme
) &&
2506 const Extension
* extension
= extension_set
->GetByID(url
.host());
2509 extensions::SocketPermission::CheckParam
check_params(
2510 params
->type
, params
->host
, params
->port
);
2511 if (extensions::PermissionsData::CheckAPIPermissionWithParam(
2512 extension
, extensions::APIPermission::kSocket
,
2517 if (extensions::PermissionsData::HasAPIPermission(
2518 extension
, extensions::APIPermission::kSocket
)) {
2526 // Allow both public and private APIs if the command line says so.
2527 return IsHostAllowedByCommandLine(url
, extension_set
,
2528 switches::kAllowNaClSocketAPI
);
2534 ui::SelectFilePolicy
* ChromeContentBrowserClient::CreateSelectFilePolicy(
2535 WebContents
* web_contents
) {
2536 return new ChromeSelectFilePolicy(web_contents
);
2539 void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2540 std::vector
<std::string
>* additional_allowed_schemes
) {
2541 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2542 additional_allowed_schemes
);
2543 additional_allowed_schemes
->push_back(content::kChromeDevToolsScheme
);
2544 additional_allowed_schemes
->push_back(content::kChromeUIScheme
);
2545 additional_allowed_schemes
->push_back(extensions::kExtensionScheme
);
2548 void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
2549 std::vector
<fileapi::URLRequestAutoMountHandler
>* handlers
) {
2552 void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
2553 content::BrowserContext
* browser_context
,
2554 const base::FilePath
& storage_partition_path
,
2555 ScopedVector
<fileapi::FileSystemBackend
>* additional_backends
) {
2556 #if !defined(OS_ANDROID)
2557 base::SequencedWorkerPool
* pool
= content::BrowserThread::GetBlockingPool();
2558 additional_backends
->push_back(new MediaFileSystemBackend(
2559 storage_partition_path
,
2560 pool
->GetSequencedTaskRunner(pool
->GetNamedSequenceToken(
2561 MediaFileSystemBackend::kMediaTaskRunnerName
)).get()));
2563 #if defined(OS_CHROMEOS)
2564 fileapi::ExternalMountPoints
* external_mount_points
=
2565 content::BrowserContext::GetMountPoints(browser_context
);
2566 DCHECK(external_mount_points
);
2567 chromeos::FileSystemBackend
* backend
=
2568 new chromeos::FileSystemBackend(
2569 new drive::FileSystemBackendDelegate
,
2570 browser_context
->GetSpecialStoragePolicy(),
2571 external_mount_points
,
2572 fileapi::ExternalMountPoints::GetSystemInstance());
2573 backend
->AddSystemMountPoints();
2574 DCHECK(backend
->CanHandleType(fileapi::kFileSystemTypeExternal
));
2575 additional_backends
->push_back(backend
);
2578 additional_backends
->push_back(
2579 new sync_file_system::SyncFileSystemBackend(
2580 Profile::FromBrowserContext(browser_context
)));
2582 #if defined(ENABLE_SERVICE_DISCOVERY)
2583 if (CommandLine::ForCurrentProcess()->HasSwitch(
2584 switches::kEnablePrivetStorage
)) {
2585 additional_backends
->push_back(
2586 new local_discovery::PrivetFileSystemBackend(
2587 fileapi::ExternalMountPoints::GetSystemInstance(),
2593 #if defined(OS_POSIX) && !defined(OS_MACOSX)
2594 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2595 const CommandLine
& command_line
,
2596 int child_process_id
,
2597 std::vector
<FileDescriptorInfo
>* mappings
) {
2598 #if defined(OS_ANDROID)
2599 base::FilePath data_path
;
2600 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID
, &data_path
);
2601 DCHECK(!data_path
.empty());
2603 int flags
= base::File::FLAG_OPEN
| base::File::FLAG_READ
;
2604 base::FilePath chrome_resources_pak
=
2605 data_path
.AppendASCII("chrome_100_percent.pak");
2606 base::File
file(chrome_resources_pak
, flags
);
2607 DCHECK(file
.IsValid());
2608 mappings
->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor
,
2609 FileDescriptor(file
.Pass())));
2611 const std::string locale
= GetApplicationLocale();
2612 base::FilePath locale_pak
= ResourceBundle::GetSharedInstance().
2613 GetLocaleFilePath(locale
, false);
2614 file
.Initialize(locale_pak
, flags
);
2615 DCHECK(file
.IsValid());
2616 mappings
->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor
,
2617 FileDescriptor(file
.Pass())));
2619 base::FilePath resources_pack_path
;
2620 PathService::Get(chrome::FILE_RESOURCES_PACK
, &resources_pack_path
);
2621 file
.Initialize(resources_pack_path
, flags
);
2622 DCHECK(file
.IsValid());
2623 mappings
->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor
,
2624 FileDescriptor(file
.Pass())));
2626 if (breakpad::IsCrashReporterEnabled()) {
2627 file
= breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile(
2629 if (file
.IsValid()) {
2630 mappings
->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor
,
2631 FileDescriptor(file
.Pass())));
2633 LOG(ERROR
) << "Failed to create file for minidump, crash reporting will "
2634 "be disabled for this process.";
2639 int crash_signal_fd
= GetCrashSignalFD(command_line
);
2640 if (crash_signal_fd
>= 0) {
2641 mappings
->push_back(FileDescriptorInfo(kCrashDumpSignal
,
2642 FileDescriptor(crash_signal_fd
,
2645 #endif // defined(OS_ANDROID)
2647 #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
2650 const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2651 return chrome::kBrowserResourcesDll
;
2654 void ChromeContentBrowserClient::PreSpawnRenderer(
2655 sandbox::TargetPolicy
* policy
,
2657 // This code is duplicated in nacl_exe_win_64.cc.
2658 // Allow the server side of a pipe restricted to the "chrome.nacl."
2659 // namespace so that it cannot impersonate other system or other chrome
2661 sandbox::ResultCode result
= policy
->AddRule(
2662 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES
,
2663 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY
,
2664 L
"\\\\.\\pipe\\chrome.nacl.*");
2665 if (result
!= sandbox::SBOX_ALL_OK
) {
2670 // Renderers need to send named pipe handles and shared memory
2671 // segment handles to NaCl loader processes.
2672 result
= policy
->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES
,
2673 sandbox::TargetPolicy::HANDLES_DUP_ANY
,
2675 if (result
!= sandbox::SBOX_ALL_OK
) {
2682 bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2683 content::BrowserContext
* browser_context
,
2685 #if defined(ENABLE_PLUGINS)
2686 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
2687 const extensions::ExtensionSet
* extension_set
= NULL
;
2689 extension_set
= extensions::ExtensionSystem::Get(profile
)->
2690 extension_service()->extensions();
2692 // TODO(teravest): Populate allowed_file_handle_origins_ when FileIO is moved
2693 // from the renderer to the browser.
2694 return IsExtensionOrSharedModuleWhitelisted(url
, extension_set
,
2695 allowed_file_handle_origins_
) ||
2696 IsHostAllowedByCommandLine(url
, extension_set
,
2697 switches::kAllowNaClFileHandleAPI
);
2703 bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs() {
2704 #if defined(ENABLE_PLUGINS)
2705 // Allow access for tests.
2706 if (CommandLine::ForCurrentProcess()->HasSwitch(
2707 switches::kEnablePepperTesting
)) {
2711 chrome::VersionInfo::Channel channel
= chrome::VersionInfo::GetChannel();
2712 // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown"
2713 // releases of Chrome. Permitting "Unknown" allows these APIs to be used on
2714 // Chromium builds as well.
2715 return channel
<= chrome::VersionInfo::CHANNEL_DEV
;
2721 #if defined(ENABLE_WEBRTC)
2722 void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
2723 CommandLine
* to_command_line
,
2724 const CommandLine
& from_command_line
,
2725 VersionInfo::Channel channel
) {
2726 #if defined(OS_ANDROID)
2727 const VersionInfo::Channel kMaxDisableEncryptionChannel
=
2728 VersionInfo::CHANNEL_BETA
;
2730 const VersionInfo::Channel kMaxDisableEncryptionChannel
=
2731 VersionInfo::CHANNEL_DEV
;
2733 if (channel
<= kMaxDisableEncryptionChannel
) {
2734 static const char* const kWebRtcDevSwitchNames
[] = {
2735 switches::kDisableWebRtcEncryption
,
2737 to_command_line
->CopySwitchesFrom(from_command_line
,
2738 kWebRtcDevSwitchNames
,
2739 arraysize(kWebRtcDevSwitchNames
));
2742 #endif // defined(ENABLE_WEBRTC)
2744 } // namespace chrome