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_host.h"
38 #include "chrome/browser/extensions/extension_service.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/chrome_version_info.h"
92 #include "chrome/common/env_vars.h"
93 #include "chrome/common/extensions/extension_process_policy.h"
94 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
95 #include "chrome/common/extensions/permissions/socket_permission.h"
96 #include "chrome/common/logging_chrome.h"
97 #include "chrome/common/pepper_permission_util.h"
98 #include "chrome/common/pref_names.h"
99 #include "chrome/common/profile_management_switches.h"
100 #include "chrome/common/render_messages.h"
101 #include "chrome/common/url_constants.h"
102 #include "chrome/installer/util/google_update_settings.h"
103 #include "chromeos/chromeos_constants.h"
104 #include "components/nacl/browser/nacl_browser.h"
105 #include "components/nacl/browser/nacl_host_message_filter.h"
106 #include "components/nacl/browser/nacl_process_host.h"
107 #include "components/nacl/common/nacl_process_type.h"
108 #include "components/translate/core/common/translate_switches.h"
109 #include "components/user_prefs/pref_registry_syncable.h"
110 #include "content/public/browser/browser_child_process_host.h"
111 #include "content/public/browser/browser_main_parts.h"
112 #include "content/public/browser/browser_ppapi_host.h"
113 #include "content/public/browser/browser_thread.h"
114 #include "content/public/browser/browser_url_handler.h"
115 #include "content/public/browser/child_process_data.h"
116 #include "content/public/browser/child_process_security_policy.h"
117 #include "content/public/browser/render_frame_host.h"
118 #include "content/public/browser/render_process_host.h"
119 #include "content/public/browser/render_view_host.h"
120 #include "content/public/browser/resource_context.h"
121 #include "content/public/browser/site_instance.h"
122 #include "content/public/browser/web_contents.h"
123 #include "content/public/browser/web_contents_view.h"
124 #include "content/public/common/child_process_host.h"
125 #include "content/public/common/content_descriptors.h"
126 #include "content/public/common/url_utils.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/switches.h"
142 #include "grit/generated_resources.h"
143 #include "grit/ui_resources.h"
144 #include "net/base/mime_util.h"
145 #include "net/cookies/canonical_cookie.h"
146 #include "net/cookies/cookie_options.h"
147 #include "net/ssl/ssl_cert_request_info.h"
148 #include "ppapi/host/ppapi_host.h"
149 #include "ppapi/shared_impl/ppapi_switches.h"
150 #include "ui/base/l10n/l10n_util.h"
151 #include "ui/base/resource/resource_bundle.h"
152 #include "ui/message_center/message_center_util.h"
153 #include "webkit/browser/fileapi/external_mount_points.h"
154 #include "webkit/common/webpreferences.h"
157 #include "base/win/windows_version.h"
158 #include "chrome/browser/chrome_browser_main_win.h"
159 #include "sandbox/win/src/sandbox_policy.h"
160 #elif defined(OS_MACOSX)
161 #include "chrome/browser/chrome_browser_main_mac.h"
162 #include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
163 #include "components/breakpad/app/breakpad_mac.h"
164 #elif defined(OS_CHROMEOS)
165 #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
166 #include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h"
167 #include "chrome/browser/chromeos/fileapi/file_system_backend.h"
168 #include "chrome/browser/chromeos/login/startup_utils.h"
169 #include "chrome/browser/chromeos/login/user_manager.h"
170 #include "chrome/browser/chromeos/system/input_device_settings.h"
171 #include "chromeos/chromeos_switches.h"
172 #elif defined(OS_LINUX)
173 #include "chrome/browser/chrome_browser_main_linux.h"
174 #elif defined(OS_ANDROID)
175 #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
176 #include "chrome/browser/chrome_browser_main_android.h"
177 #include "chrome/browser/media/encrypted_media_message_filter_android.h"
178 #include "chrome/common/descriptors_android.h"
179 #include "components/breakpad/browser/crash_dump_manager_android.h"
180 #elif defined(OS_POSIX)
181 #include "chrome/browser/chrome_browser_main_posix.h"
184 #if defined(OS_POSIX) && !defined(OS_MACOSX)
185 #include "base/debug/leak_annotations.h"
186 #include "base/linux_util.h"
187 #include "components/breakpad/app/breakpad_linux.h"
188 #include "components/breakpad/browser/crash_handler_host_linux.h"
191 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
192 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
195 #if defined(OS_ANDROID)
196 #include "ui/base/ui_base_paths.h"
197 #include "ui/gfx/android/device_display_info.h"
200 #if !defined(OS_CHROMEOS)
201 #include "chrome/browser/signin/signin_manager.h"
202 #include "chrome/browser/signin/signin_manager_factory.h"
205 #if !defined(OS_ANDROID)
206 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
209 #if defined(ENABLE_WEBRTC)
210 #include "chrome/browser/media/webrtc_logging_handler_host.h"
213 #if defined(ENABLE_INPUT_SPEECH)
214 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate_bubble_ui.h"
217 #if defined(OS_CHROMEOS)
218 #include "chrome/browser/chromeos/file_manager/app_id.h"
221 #if defined(TOOLKIT_GTK)
222 #include "chrome/browser/ui/gtk/chrome_browser_main_extra_parts_gtk.h"
225 #if defined(TOOLKIT_VIEWS)
226 #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
230 #include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
233 #if defined(USE_AURA)
234 #include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
238 #include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
241 #if defined(ENABLE_SPELLCHECK)
242 #include "chrome/browser/spellchecker/spellcheck_message_filter.h"
245 using blink::WebWindowFeatures
;
246 using base::FileDescriptor
;
247 using content::AccessTokenStore
;
248 using content::BrowserChildProcessHostIterator
;
249 using content::BrowserThread
;
250 using content::BrowserURLHandler
;
251 using content::ChildProcessSecurityPolicy
;
252 using content::FileDescriptorInfo
;
253 using content::QuotaPermissionContext
;
254 using content::RenderViewHost
;
255 using content::SiteInstance
;
256 using content::WebContents
;
257 using extensions::APIPermission
;
258 using extensions::Extension
;
259 using extensions::InfoMap
;
260 using extensions::Manifest
;
261 using message_center::NotifierId
;
265 // Cached version of the locale so we can return the locale on the I/O
267 base::LazyInstance
<std::string
> g_io_thread_application_locale
;
269 #if defined(ENABLE_PLUGINS)
270 const char* kPredefinedAllowedFileHandleOrigins
[] = {
271 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
272 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
275 const char* kPredefinedAllowedSocketOrigins
[] = {
276 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
277 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
278 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
279 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
280 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
281 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
282 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
283 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
284 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
285 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
286 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
287 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
288 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
289 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
290 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
291 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
292 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
293 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
294 "4EB74897CB187C7633357C2FE832E0AD6A44883A", // see crbug.com/234789
295 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
296 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
297 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
301 // Returns a copy of the given url with its host set to given host and path set
302 // to given path. Other parts of the url will be the same.
303 GURL
ReplaceURLHostAndPath(const GURL
& url
,
304 const std::string
& host
,
305 const std::string
& path
) {
306 url_canon::Replacements
<char> replacements
;
307 replacements
.SetHost(host
.c_str(),
308 url_parse::Component(0, host
.length()));
309 replacements
.SetPath(path
.c_str(),
310 url_parse::Component(0, path
.length()));
311 return url
.ReplaceComponents(replacements
);
314 // Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
315 GURL
AddUberHost(const GURL
& url
) {
316 const std::string uber_host
= chrome::kChromeUIUberHost
;
317 const std::string new_path
= url
.host() + url
.path();
319 return ReplaceURLHostAndPath(url
, uber_host
, new_path
);
322 // If url->host() is "chrome" and url->path() has characters other than the
323 // first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
324 // returns true. Otherwise returns false.
325 bool RemoveUberHost(GURL
* url
) {
326 if (url
->host() != chrome::kChromeUIUberHost
)
329 if (url
->path().empty() || url
->path() == "/")
332 const std::string old_path
= url
->path();
334 const std::string::size_type separator
= old_path
.find('/', 1);
335 std::string new_host
;
336 std::string new_path
;
337 if (separator
== std::string::npos
) {
338 new_host
= old_path
.substr(1);
340 new_host
= old_path
.substr(1, separator
- 1);
341 new_path
= old_path
.substr(separator
);
344 // Do not allow URLs with paths empty before the first slash since we can't
345 // have an empty host. (e.g "foo://chrome//")
346 if (new_host
.empty())
349 *url
= ReplaceURLHostAndPath(*url
, new_host
, new_path
);
351 DCHECK(url
->is_valid());
356 // Handles rewriting Web UI URLs.
357 bool HandleWebUI(GURL
* url
, content::BrowserContext
* browser_context
) {
358 // Do not handle special URLs such as "about:foo"
359 if (!url
->host().empty()) {
360 const GURL chrome_url
= AddUberHost(*url
);
362 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
364 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
365 browser_context
, chrome_url
))
369 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
370 browser_context
, *url
))
373 #if defined(OS_CHROMEOS)
374 // Special case : in ChromeOS in Guest mode bookmarks and history are
375 // disabled for security reasons. New tab page explains the reasons, so
376 // we redirect user to new tab page.
377 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
378 if (url
->SchemeIs(content::kChromeUIScheme
) &&
379 (url
->DomainIs(chrome::kChromeUIBookmarksHost
) ||
380 #if defined(ENABLE_ENHANCED_BOOKMARKS)
381 url
->DomainIs(chrome::kChromeUIEnhancedBookmarksHost
) ||
383 url
->DomainIs(chrome::kChromeUIHistoryHost
))) {
384 // Rewrite with new tab URL
385 *url
= GURL(chrome::kChromeUINewTabURL
);
393 // Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
395 bool HandleWebUIReverse(GURL
* url
, content::BrowserContext
* browser_context
) {
396 if (!url
->is_valid() || !url
->SchemeIs(content::kChromeUIScheme
))
399 return RemoveUberHost(url
);
402 // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
403 // below. Extension, and isolated apps require different privileges to be
404 // granted to their RenderProcessHosts. This classification allows us to make
405 // sure URLs are served by hosts with the right set of privileges.
406 enum RenderProcessHostPrivilege
{
413 RenderProcessHostPrivilege
GetPrivilegeRequiredByUrl(
415 ExtensionService
* service
) {
416 // Default to a normal renderer cause it is lower privileged. This should only
417 // occur if the URL on a site instance is either malformed, or uninitialized.
418 // If it is malformed, then there is no need for better privileges anyways.
419 // If it is uninitialized, but eventually settles on being an a scheme other
420 // than normal webrenderer, the navigation logic will correct us out of band
425 if (url
.SchemeIs(extensions::kExtensionScheme
)) {
426 const Extension
* extension
=
427 service
->extensions()->GetByID(url
.host());
429 extensions::AppIsolationInfo::HasIsolatedStorage(extension
))
430 return PRIV_ISOLATED
;
431 if (extension
&& extension
->is_hosted_app())
434 return PRIV_EXTENSION
;
440 RenderProcessHostPrivilege
GetProcessPrivilege(
441 content::RenderProcessHost
* process_host
,
442 extensions::ProcessMap
* process_map
,
443 ExtensionService
* service
) {
444 std::set
<std::string
> extension_ids
=
445 process_map
->GetExtensionsInProcess(process_host
->GetID());
446 if (extension_ids
.empty())
449 for (std::set
<std::string
>::iterator iter
= extension_ids
.begin();
450 iter
!= extension_ids
.end(); ++iter
) {
451 const Extension
* extension
= service
->GetExtensionById(*iter
, false);
453 extensions::AppIsolationInfo::HasIsolatedStorage(extension
))
454 return PRIV_ISOLATED
;
455 if (extension
&& extension
->is_hosted_app())
459 return PRIV_EXTENSION
;
462 bool CertMatchesFilter(const net::X509Certificate
& cert
,
463 const base::DictionaryValue
& filter
) {
464 // TODO(markusheintz): This is the minimal required filter implementation.
465 // Implement a better matcher.
467 // An empty filter matches any client certificate since no requirements are
472 std::string common_name
;
473 if (filter
.GetString("ISSUER.CN", &common_name
) &&
474 (cert
.issuer().common_name
== common_name
)) {
480 #if !defined(OS_ANDROID)
481 // Fills |map| with the per-script font prefs under path |map_name|.
482 void FillFontFamilyMap(const PrefService
* prefs
,
483 const char* map_name
,
484 webkit_glue::ScriptFontFamilyMap
* map
) {
485 // TODO: Get rid of the brute-force scan over possible (font family / script)
486 // combinations - see http://crbug.com/308095.
487 for (size_t i
= 0; i
< prefs::kWebKitScriptsForFontFamilyMapsLength
; ++i
) {
488 const char* script
= prefs::kWebKitScriptsForFontFamilyMaps
[i
];
489 std::string pref_name
= base::StringPrintf("%s.%s", map_name
, script
);
490 std::string font_family
= prefs
->GetString(pref_name
.c_str());
491 if (!font_family
.empty())
492 (*map
)[script
] = base::UTF8ToUTF16(font_family
);
496 #if defined(OS_POSIX) && !defined(OS_MACOSX)
497 breakpad::CrashHandlerHostLinux
* CreateCrashHandlerHost(
498 const std::string
& process_type
) {
499 base::FilePath dumps_path
;
500 PathService::Get(chrome::DIR_CRASH_DUMPS
, &dumps_path
);
502 ANNOTATE_SCOPED_MEMORY_LEAK
;
503 breakpad::CrashHandlerHostLinux
* crash_handler
=
504 new breakpad::CrashHandlerHostLinux(
505 process_type
, dumps_path
, getenv(env_vars::kHeadless
) == NULL
);
506 crash_handler
->StartUploaderThread();
507 return crash_handler
;
511 int GetCrashSignalFD(const CommandLine
& command_line
) {
512 if (command_line
.HasSwitch(extensions::switches::kExtensionProcess
)) {
513 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
515 crash_handler
= CreateCrashHandlerHost("extension");
516 return crash_handler
->GetDeathSignalSocket();
519 std::string process_type
=
520 command_line
.GetSwitchValueASCII(switches::kProcessType
);
522 if (process_type
== switches::kRendererProcess
) {
523 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
525 crash_handler
= CreateCrashHandlerHost(process_type
);
526 return crash_handler
->GetDeathSignalSocket();
529 if (process_type
== switches::kPluginProcess
) {
530 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
532 crash_handler
= CreateCrashHandlerHost(process_type
);
533 return crash_handler
->GetDeathSignalSocket();
536 if (process_type
== switches::kPpapiPluginProcess
) {
537 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
539 crash_handler
= CreateCrashHandlerHost(process_type
);
540 return crash_handler
->GetDeathSignalSocket();
543 if (process_type
== switches::kGpuProcess
) {
544 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
546 crash_handler
= CreateCrashHandlerHost(process_type
);
547 return crash_handler
->GetDeathSignalSocket();
552 #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
553 #endif // !defined(OS_ANDROID)
555 #if !defined(OS_CHROMEOS)
556 GURL
GetEffectiveURLForSignin(const GURL
& url
) {
557 CHECK(SigninManager::IsWebBasedSigninFlowURL(url
));
559 GURL
effective_url(SigninManager::kChromeSigninEffectiveSite
);
560 // Copy the path because the argument to SetPathStr must outlive
561 // the Replacements object.
562 const std::string
path_copy(url
.path());
563 GURL::Replacements replacements
;
564 replacements
.SetPathStr(path_copy
);
565 effective_url
= effective_url
.ReplaceComponents(replacements
);
566 return effective_url
;
570 void SetApplicationLocaleOnIOThread(const std::string
& locale
) {
571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
572 g_io_thread_application_locale
.Get() = locale
;
575 void HandleBlockedPopupOnUIThread(const BlockedWindowParams
& params
) {
576 WebContents
* tab
= tab_util::GetWebContentsByID(params
.render_process_id(),
581 prerender::PrerenderContents
* prerender_contents
=
582 prerender::PrerenderContents::FromWebContents(tab
);
583 if (prerender_contents
) {
584 prerender_contents
->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW
);
588 PopupBlockerTabHelper
* popup_helper
=
589 PopupBlockerTabHelper::FromWebContents(tab
);
592 popup_helper
->AddBlockedPopup(params
);
595 #if defined(OS_ANDROID)
597 void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams
& params
) {
598 WebContents
* web_contents
=
599 tab_util::GetWebContentsByID(params
.render_process_id(),
604 SingleTabModeTabHelper::FromWebContents(web_contents
)->HandleOpenUrl(params
);
607 float GetDeviceScaleAdjustment() {
608 static const float kMinFSM
= 1.05f
;
609 static const int kWidthForMinFSM
= 320;
610 static const float kMaxFSM
= 1.3f
;
611 static const int kWidthForMaxFSM
= 800;
613 gfx::DeviceDisplayInfo info
;
614 int minWidth
= info
.GetSmallestDIPWidth();
616 if (minWidth
<= kWidthForMinFSM
)
618 if (minWidth
>= kWidthForMaxFSM
)
621 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
622 float ratio
= static_cast<float>(minWidth
- kWidthForMinFSM
) /
623 (kWidthForMaxFSM
- kWidthForMinFSM
);
624 return ratio
* (kMaxFSM
- kMinFSM
) + kMinFSM
;
627 #endif // defined(OS_ANDROID)
633 ChromeContentBrowserClient::ChromeContentBrowserClient() {
634 #if defined(ENABLE_PLUGINS)
635 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedFileHandleOrigins
); ++i
)
636 allowed_file_handle_origins_
.insert(kPredefinedAllowedFileHandleOrigins
[i
]);
637 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedSocketOrigins
); ++i
)
638 allowed_socket_origins_
.insert(kPredefinedAllowedSocketOrigins
[i
]);
641 permissions_policy_delegate_
.reset(
642 new extensions::BrowserPermissionsPolicyDelegate());
645 ChromeContentBrowserClient::~ChromeContentBrowserClient() {
649 void ChromeContentBrowserClient::RegisterProfilePrefs(
650 user_prefs::PrefRegistrySyncable
* registry
) {
651 registry
->RegisterBooleanPref(
652 prefs::kDisable3DAPIs
,
654 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
655 registry
->RegisterBooleanPref(
656 prefs::kEnableHyperlinkAuditing
,
658 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
659 registry
->RegisterBooleanPref(
660 prefs::kEnableMemoryInfo
,
662 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
666 void ChromeContentBrowserClient::SetApplicationLocale(
667 const std::string
& locale
) {
668 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
670 // This object is guaranteed to outlive all threads so we don't have to
671 // worry about the lack of refcounting and can just post as Unretained.
673 // The common case is that this function is called early in Chrome startup
674 // before any threads are created (it will also be called later if the user
675 // changes the pref). In this case, there will be no threads created and
676 // posting will fail. When there are no threads, we can just set the string
677 // without worrying about threadsafety.
678 if (!BrowserThread::PostTask(BrowserThread::IO
, FROM_HERE
,
679 base::Bind(&SetApplicationLocaleOnIOThread
, locale
))) {
680 g_io_thread_application_locale
.Get() = locale
;
684 content::BrowserMainParts
* ChromeContentBrowserClient::CreateBrowserMainParts(
685 const content::MainFunctionParams
& parameters
) {
686 ChromeBrowserMainParts
* main_parts
;
687 // Construct the Main browser parts based on the OS type.
689 main_parts
= new ChromeBrowserMainPartsWin(parameters
);
690 #elif defined(OS_MACOSX)
691 main_parts
= new ChromeBrowserMainPartsMac(parameters
);
692 #elif defined(OS_CHROMEOS)
693 main_parts
= new chromeos::ChromeBrowserMainPartsChromeos(parameters
);
694 #elif defined(OS_LINUX)
695 main_parts
= new ChromeBrowserMainPartsLinux(parameters
);
696 #elif defined(OS_ANDROID)
697 main_parts
= new ChromeBrowserMainPartsAndroid(parameters
);
698 #elif defined(OS_POSIX)
699 main_parts
= new ChromeBrowserMainPartsPosix(parameters
);
702 main_parts
= new ChromeBrowserMainParts(parameters
);
705 chrome::AddProfilesExtraParts(main_parts
);
707 // Construct additional browser parts. Stages are called in the order in
708 // which they are added.
709 #if defined(TOOLKIT_GTK)
710 main_parts
->AddParts(new ChromeBrowserMainExtraPartsGtk());
713 #if defined(TOOLKIT_VIEWS)
714 main_parts
->AddParts(new ChromeBrowserMainExtraPartsViews());
718 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAsh());
721 #if defined(USE_AURA)
722 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAura());
726 main_parts
->AddParts(new ChromeBrowserMainExtraPartsX11());
729 chrome::AddMetricsExtraParts(main_parts
);
734 std::string
ChromeContentBrowserClient::GetStoragePartitionIdForSite(
735 content::BrowserContext
* browser_context
,
737 std::string partition_id
;
739 // The partition ID for webview guest processes is the string value of its
740 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
741 if (site
.SchemeIs(content::kGuestScheme
))
742 partition_id
= site
.spec();
744 DCHECK(IsValidStoragePartitionId(browser_context
, partition_id
));
748 bool ChromeContentBrowserClient::IsValidStoragePartitionId(
749 content::BrowserContext
* browser_context
,
750 const std::string
& partition_id
) {
751 // The default ID is empty and is always valid.
752 if (partition_id
.empty())
755 return GURL(partition_id
).is_valid();
758 void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
759 content::BrowserContext
* browser_context
,
762 std::string
* partition_domain
,
763 std::string
* partition_name
,
765 // Default to the browser-wide storage partition and override based on |site|
767 partition_domain
->clear();
768 partition_name
->clear();
771 bool success
= GuestView::GetGuestPartitionConfigForSite(
772 site
, partition_domain
, partition_name
, in_memory
);
774 if (!success
&& site
.SchemeIs(extensions::kExtensionScheme
)) {
775 // If |can_be_default| is false, the caller is stating that the |site|
776 // should be parsed as if it had isolated storage. In particular it is
777 // important to NOT check ExtensionService for the is_storage_isolated()
778 // attribute because this code path is run during Extension uninstall
779 // to do cleanup after the Extension has already been unloaded from the
781 bool is_isolated
= !can_be_default
;
782 if (can_be_default
) {
783 const Extension
* extension
= NULL
;
784 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
785 ExtensionService
* extension_service
=
786 extensions::ExtensionSystem::Get(profile
)->extension_service();
787 if (extension_service
) {
789 extension_service
->extensions()->GetExtensionOrAppByURL(site
);
791 extensions::AppIsolationInfo::HasIsolatedStorage(extension
)) {
798 CHECK(site
.has_host());
799 // For extensions with isolated storage, the the host of the |site| is
800 // the |partition_domain|. The |in_memory| and |partition_name| are only
801 // used in guest schemes so they are cleared here.
802 *partition_domain
= site
.host();
804 partition_name
->clear();
806 } else if (site
.GetOrigin().spec() == kChromeUIChromeSigninURL
) {
807 // Chrome signin page has an embedded iframe of extension and web content,
808 // thus it must be isolated from other webUI pages.
809 *partition_domain
= chrome::kChromeUIChromeSigninHost
;
812 // Assert that if |can_be_default| is false, the code above must have found a
813 // non-default partition. If this fails, the caller has a serious logic
814 // error about which StoragePartition they expect to be in and it is not
816 CHECK(can_be_default
|| !partition_domain
->empty());
819 content::WebContentsViewDelegate
*
820 ChromeContentBrowserClient::GetWebContentsViewDelegate(
821 content::WebContents
* web_contents
) {
822 return chrome::CreateWebContentsViewDelegate(web_contents
);
825 void ChromeContentBrowserClient::GuestWebContentsCreated(
826 SiteInstance
* guest_site_instance
,
827 WebContents
* guest_web_contents
,
828 WebContents
* opener_web_contents
,
829 content::BrowserPluginGuestDelegate
** guest_delegate
,
830 scoped_ptr
<base::DictionaryValue
> extra_params
) {
831 if (!guest_site_instance
) {
835 GURL guest_site_url
= guest_site_instance
->GetSiteURL();
836 const std::string
& extension_id
= guest_site_url
.host();
838 Profile
* profile
= Profile::FromBrowserContext(
839 guest_web_contents
->GetBrowserContext());
840 ExtensionService
* service
=
841 extensions::ExtensionSystem::Get(profile
)->extension_service();
847 /// TODO(fsamuel): In the future, certain types of GuestViews won't require
848 // extension bindings. At that point, we should clear |extension_id| instead
850 if (!service
->GetExtensionById(extension_id
, false) &&
851 !CommandLine::ForCurrentProcess()->HasSwitch(
852 switches::kEnableBrowserPluginForAllViewTypes
)) {
857 if (opener_web_contents
) {
858 GuestView
* guest
= GuestView::FromWebContents(opener_web_contents
);
864 // Create a new GuestView of the same type as the opener.
866 GuestView::Create(guest_web_contents
,
868 guest
->GetViewType());
876 std::string api_type
;
877 extra_params
->GetString(guestview::kParameterApi
, &api_type
);
879 if (api_type
.empty())
883 GuestView::Create(guest_web_contents
,
885 GuestView::GetViewTypeFromString(api_type
));
888 void ChromeContentBrowserClient::GuestWebContentsAttached(
889 WebContents
* guest_web_contents
,
890 WebContents
* embedder_web_contents
,
891 const base::DictionaryValue
& extra_params
) {
893 GuestView
* guest
= GuestView::FromWebContents(guest_web_contents
);
895 // It's ok to return here, since we could be running a browser plugin
896 // outside an extension, and don't need to attach a
897 // BrowserPluginGuestDelegate in that case;
898 // e.g. running with flag --enable-browser-plugin-for-all-view-types.
901 guest
->Attach(embedder_web_contents
, extra_params
);
904 void ChromeContentBrowserClient::RenderProcessWillLaunch(
905 content::RenderProcessHost
* host
) {
906 int id
= host
->GetID();
907 Profile
* profile
= Profile::FromBrowserContext(host
->GetBrowserContext());
908 net::URLRequestContextGetter
* context
=
909 profile
->GetRequestContextForRenderProcess(id
);
911 host
->AddFilter(new ChromeRenderMessageFilter(id
, profile
, context
));
912 host
->AddFilter(new extensions::ExtensionMessageFilter(id
, profile
));
913 #if defined(ENABLE_PLUGINS)
914 host
->AddFilter(new PluginInfoMessageFilter(id
, profile
));
916 host
->AddFilter(new cast::CastTransportHostFilter
);
917 #if defined(ENABLE_PRINTING)
918 host
->AddFilter(new PrintingMessageFilter(id
, profile
));
920 host
->AddFilter(new SearchProviderInstallStateMessageFilter(id
, profile
));
921 #if defined(ENABLE_SPELLCHECK)
922 host
->AddFilter(new SpellCheckMessageFilter(id
));
924 #if defined(OS_MACOSX)
925 host
->AddFilter(new SpellCheckMessageFilterMac(id
));
927 host
->AddFilter(new ChromeNetBenchmarkingMessageFilter(profile
, context
));
928 host
->AddFilter(new prerender::PrerenderMessageFilter(id
, profile
));
929 host
->AddFilter(new TtsMessageFilter(id
, profile
));
930 #if defined(ENABLE_WEBRTC)
931 WebRtcLoggingHandlerHost
* webrtc_logging_handler_host
=
932 new WebRtcLoggingHandlerHost(profile
);
933 host
->SetWebRtcLogMessageCallback(base::Bind(
934 &WebRtcLoggingHandlerHost::LogMessage
, webrtc_logging_handler_host
));
935 host
->AddFilter(webrtc_logging_handler_host
);
936 host
->SetUserData(host
, new base::UserDataAdapter
<WebRtcLoggingHandlerHost
>(
937 webrtc_logging_handler_host
));
939 #if !defined(DISABLE_NACL)
940 host
->AddFilter(new nacl::NaClHostMessageFilter(
941 id
, profile
->IsOffTheRecord(),
945 #if defined(OS_ANDROID)
946 host
->AddFilter(new EncryptedMediaMessageFilterAndroid());
948 if (switches::IsNewProfileManagement())
949 host
->AddFilter(new PrincipalsMessageFilter(id
));
951 host
->Send(new ChromeViewMsg_SetIsIncognitoProcess(
952 profile
->IsOffTheRecord()));
954 SendExtensionWebRequestStatusToHost(host
);
956 RendererContentSettingRules rules
;
957 if (host
->IsGuest()) {
958 GuestView::GetDefaultContentSettingRules(&rules
, profile
->IsOffTheRecord());
960 GetRendererContentSettingRules(
961 profile
->GetHostContentSettingsMap(), &rules
);
963 host
->Send(new ChromeViewMsg_SetContentSettingRules(rules
));
966 GURL
ChromeContentBrowserClient::GetEffectiveURL(
967 content::BrowserContext
* browser_context
, const GURL
& url
) {
968 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
972 // If the input |url| should be assigned to the Instant renderer, make its
973 // effective URL distinct from other URLs on the search provider's domain.
974 if (chrome::ShouldAssignURLToInstantRenderer(url
, profile
))
975 return chrome::GetEffectiveURLForInstant(url
, profile
);
977 #if !defined(OS_CHROMEOS)
978 // If the input |url| should be assigned to the Signin renderer, make its
979 // effective URL distinct from other URLs on the signin service's domain.
980 // Note that the signin renderer will be allowed to sign the user in to
982 if (SigninManager::IsWebBasedSigninFlowURL(url
))
983 return GetEffectiveURLForSignin(url
);
986 // If the input |url| is part of an installed app, the effective URL is an
987 // extension URL with the ID of that extension as the host. This has the
988 // effect of grouping apps together in a common SiteInstance.
989 ExtensionService
* extension_service
=
990 extensions::ExtensionSystem::Get(profile
)->extension_service();
991 if (!extension_service
)
994 const Extension
* extension
= extension_service
->extensions()->
995 GetHostedAppByURL(url
);
999 // Bookmark apps do not use the hosted app process model, and should be
1000 // treated as normal URLs.
1001 if (extension
->from_bookmark())
1004 // If the URL is part of an extension's web extent, convert it to an
1006 return extension
->GetResourceURL(url
.path());
1009 bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
1010 content::BrowserContext
* browser_context
, const GURL
& effective_url
) {
1011 // Non-extension, non-Instant URLs should generally use
1012 // process-per-site-instance. Because we expect to use the effective URL,
1013 // URLs for hosted apps (apart from bookmark apps) should have an extension
1016 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1020 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url
, profile
))
1023 #if !defined(OS_CHROMEOS)
1024 if (SigninManager::IsWebBasedSigninFlowURL(effective_url
))
1028 if (!effective_url
.SchemeIs(extensions::kExtensionScheme
))
1031 ExtensionService
* extension_service
=
1032 extensions::ExtensionSystem::Get(profile
)->extension_service();
1033 if (!extension_service
)
1036 const Extension
* extension
=
1037 extension_service
->extensions()->GetExtensionOrAppByURL(effective_url
);
1041 // If the URL is part of a hosted app that does not have the background
1042 // permission, or that does not allow JavaScript access to the background
1043 // page, we want to give each instance its own process to improve
1045 if (extension
->GetType() == Manifest::TYPE_HOSTED_APP
) {
1046 if (!extension
->HasAPIPermission(APIPermission::kBackground
) ||
1047 !extensions::BackgroundInfo::AllowJSAccess(extension
)) {
1052 // Hosted apps that have script access to their background page must use
1053 // process per site, since all instances can make synchronous calls to the
1054 // background window. Other extensions should use process per site as well.
1058 // These are treated as WebUI schemes but do not get WebUI bindings. Also,
1059 // view-source is allowed for these schemes.
1060 void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1061 std::vector
<std::string
>* additional_schemes
) {
1062 additional_schemes
->push_back(chrome::kChromeSearchScheme
);
1063 additional_schemes
->push_back(chrome::kDomDistillerScheme
);
1066 net::URLRequestContextGetter
*
1067 ChromeContentBrowserClient::CreateRequestContext(
1068 content::BrowserContext
* browser_context
,
1069 content::ProtocolHandlerMap
* protocol_handlers
) {
1070 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1071 return profile
->CreateRequestContext(protocol_handlers
);
1074 net::URLRequestContextGetter
*
1075 ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
1076 content::BrowserContext
* browser_context
,
1077 const base::FilePath
& partition_path
,
1079 content::ProtocolHandlerMap
* protocol_handlers
) {
1080 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1081 return profile
->CreateRequestContextForStoragePartition(
1082 partition_path
, in_memory
, protocol_handlers
);
1085 bool ChromeContentBrowserClient::IsHandledURL(const GURL
& url
) {
1086 return ProfileIOData::IsHandledURL(url
);
1089 bool ChromeContentBrowserClient::CanCommitURL(
1090 content::RenderProcessHost
* process_host
,
1092 // We need to let most extension URLs commit in any process, since this can
1093 // be allowed due to web_accessible_resources. Most hosted app URLs may also
1094 // load in any process (e.g., in an iframe). However, the Chrome Web Store
1095 // cannot be loaded in iframes and should never be requested outside its
1098 Profile::FromBrowserContext(process_host
->GetBrowserContext());
1099 ExtensionService
* service
=
1100 extensions::ExtensionSystem::Get(profile
)->extension_service();
1103 const Extension
* new_extension
=
1104 service
->extensions()->GetExtensionOrAppByURL(url
);
1105 if (new_extension
&&
1106 new_extension
->is_hosted_app() &&
1107 new_extension
->id() == extension_misc::kWebStoreAppId
&&
1108 !extensions::ProcessMap::Get(profile
)->
1109 Contains(new_extension
->id(), process_host
->GetID())) {
1116 bool ChromeContentBrowserClient::ShouldAllowOpenURL(
1117 content::SiteInstance
* site_instance
, const GURL
& url
) {
1118 GURL from_url
= site_instance
->GetSiteURL();
1119 // Do not allow pages from the web or other extensions navigate to
1120 // non-web-accessible extension resources.
1121 if (url
.SchemeIs(extensions::kExtensionScheme
) &&
1122 (from_url
.SchemeIsHTTPOrHTTPS() ||
1123 from_url
.SchemeIs(extensions::kExtensionScheme
))) {
1124 Profile
* profile
= Profile::FromBrowserContext(
1125 site_instance
->GetProcess()->GetBrowserContext());
1126 ExtensionService
* service
=
1127 extensions::ExtensionSystem::Get(profile
)->extension_service();
1130 const Extension
* extension
=
1131 service
->extensions()->GetExtensionOrAppByURL(url
);
1134 const Extension
* from_extension
=
1135 service
->extensions()->GetExtensionOrAppByURL(
1136 site_instance
->GetSiteURL());
1137 if (from_extension
&& from_extension
->id() == extension
->id())
1140 if (!extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible(
1141 extension
, url
.path()))
1147 bool ChromeContentBrowserClient::IsSuitableHost(
1148 content::RenderProcessHost
* process_host
,
1149 const GURL
& site_url
) {
1151 Profile::FromBrowserContext(process_host
->GetBrowserContext());
1152 // This may be NULL during tests. In that case, just assume any site can
1157 // Instant URLs should only be in the instant process and instant process
1158 // should only have Instant URLs.
1159 InstantService
* instant_service
=
1160 InstantServiceFactory::GetForProfile(profile
);
1161 if (instant_service
) {
1162 bool is_instant_process
= instant_service
->IsInstantProcess(
1163 process_host
->GetID());
1164 bool should_be_in_instant_process
=
1165 chrome::ShouldAssignURLToInstantRenderer(site_url
, profile
);
1166 if (is_instant_process
|| should_be_in_instant_process
)
1167 return is_instant_process
&& should_be_in_instant_process
;
1170 #if !defined(OS_CHROMEOS)
1171 SigninManager
* signin_manager
= SigninManagerFactory::GetForProfile(profile
);
1172 if (signin_manager
&& signin_manager
->IsSigninProcess(process_host
->GetID()))
1173 return SigninManager::IsWebBasedSigninFlowURL(site_url
);
1176 ExtensionService
* service
=
1177 extensions::ExtensionSystem::Get(profile
)->extension_service();
1178 extensions::ProcessMap
* process_map
= extensions::ProcessMap::Get(profile
);
1180 // Don't allow the Task Manager to share a process with anything else.
1181 // Otherwise it can affect the renderers it is observing.
1182 // Note: we could create another RenderProcessHostPrivilege bucket for
1183 // this to allow multiple chrome://tasks instances to share, but that's
1184 // a very unlikely case without serious consequences.
1185 if (site_url
.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL
).GetOrigin())
1188 // These may be NULL during tests. In that case, just assume any site can
1190 if (!service
|| !process_map
)
1193 // Otherwise, just make sure the process privilege matches the privilege
1194 // required by the site.
1195 RenderProcessHostPrivilege privilege_required
=
1196 GetPrivilegeRequiredByUrl(site_url
, service
);
1197 return GetProcessPrivilege(process_host
, process_map
, service
) ==
1201 // This function is trying to limit the amount of processes used by extensions
1202 // with background pages. It uses a globally set percentage of processes to
1203 // run such extensions and if the limit is exceeded, it returns true, to
1204 // indicate to the content module to group extensions together.
1205 bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1206 content::BrowserContext
* browser_context
, const GURL
& url
) {
1207 // It has to be a valid URL for us to check for an extension.
1208 if (!url
.is_valid())
1211 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1212 ExtensionService
* service
= !profile
? NULL
:
1213 extensions::ExtensionSystem::Get(profile
)->extension_service();
1217 // We have to have a valid extension with background page to proceed.
1218 const Extension
* extension
=
1219 service
->extensions()->GetExtensionOrAppByURL(url
);
1222 if (!extensions::BackgroundInfo::HasBackgroundPage(extension
))
1225 std::set
<int> process_ids
;
1226 size_t max_process_count
=
1227 content::RenderProcessHost::GetMaxRendererProcessCount();
1229 // Go through all profiles to ensure we have total count of extension
1230 // processes containing background pages, otherwise one profile can
1231 // starve the other.
1232 std::vector
<Profile
*> profiles
= g_browser_process
->profile_manager()->
1233 GetLoadedProfiles();
1234 for (size_t i
= 0; i
< profiles
.size(); ++i
) {
1235 extensions::ProcessManager
* epm
=
1236 extensions::ExtensionSystem::Get(profiles
[i
])->process_manager();
1237 for (extensions::ProcessManager::const_iterator iter
=
1238 epm
->background_hosts().begin();
1239 iter
!= epm
->background_hosts().end(); ++iter
) {
1240 const extensions::ExtensionHost
* host
= *iter
;
1241 process_ids
.insert(host
->render_process_host()->GetID());
1245 if (process_ids
.size() >
1246 (max_process_count
* chrome::kMaxShareOfExtensionProcesses
)) {
1253 void ChromeContentBrowserClient::SiteInstanceGotProcess(
1254 SiteInstance
* site_instance
) {
1255 CHECK(site_instance
->HasProcess());
1257 Profile
* profile
= Profile::FromBrowserContext(
1258 site_instance
->GetBrowserContext());
1262 // Remember the ID of the Instant process to signal the renderer process
1263 // on startup in |AppendExtraCommandLineSwitches| below.
1264 if (chrome::ShouldAssignURLToInstantRenderer(
1265 site_instance
->GetSiteURL(), profile
)) {
1266 InstantService
* instant_service
=
1267 InstantServiceFactory::GetForProfile(profile
);
1268 if (instant_service
)
1269 instant_service
->AddInstantProcess(site_instance
->GetProcess()->GetID());
1272 #if !defined(OS_CHROMEOS)
1273 // We only expect there to be one signin process as we use process-per-site
1274 // for signin URLs. The signin process will be cleared from SigninManager
1275 // when the renderer is destroyed.
1276 if (SigninManager::IsWebBasedSigninFlowURL(site_instance
->GetSiteURL())) {
1277 SigninManager
* signin_manager
=
1278 SigninManagerFactory::GetForProfile(profile
);
1280 signin_manager
->SetSigninProcess(site_instance
->GetProcess()->GetID());
1281 BrowserThread::PostTask(
1284 base::Bind(&InfoMap::SetSigninProcess
,
1285 extensions::ExtensionSystem::Get(profile
)->info_map(),
1286 site_instance
->GetProcess()->GetID()));
1290 ExtensionService
* service
=
1291 extensions::ExtensionSystem::Get(profile
)->extension_service();
1295 const Extension
* extension
= service
->extensions()->GetExtensionOrAppByURL(
1296 site_instance
->GetSiteURL());
1300 extensions::ProcessMap::Get(profile
)
1301 ->Insert(extension
->id(),
1302 site_instance
->GetProcess()->GetID(),
1303 site_instance
->GetId());
1305 BrowserThread::PostTask(
1308 base::Bind(&InfoMap::RegisterExtensionProcess
,
1309 extensions::ExtensionSystem::Get(profile
)->info_map(),
1311 site_instance
->GetProcess()->GetID(),
1312 site_instance
->GetId()));
1315 void ChromeContentBrowserClient::SiteInstanceDeleting(
1316 SiteInstance
* site_instance
) {
1317 if (!site_instance
->HasProcess())
1320 Profile
* profile
= Profile::FromBrowserContext(
1321 site_instance
->GetBrowserContext());
1322 ExtensionService
* service
=
1323 extensions::ExtensionSystem::Get(profile
)->extension_service();
1327 const Extension
* extension
= service
->extensions()->GetExtensionOrAppByURL(
1328 site_instance
->GetSiteURL());
1332 extensions::ProcessMap::Get(profile
)
1333 ->Remove(extension
->id(),
1334 site_instance
->GetProcess()->GetID(),
1335 site_instance
->GetId());
1337 BrowserThread::PostTask(
1340 base::Bind(&InfoMap::UnregisterExtensionProcess
,
1341 extensions::ExtensionSystem::Get(profile
)->info_map(),
1343 site_instance
->GetProcess()->GetID(),
1344 site_instance
->GetId()));
1347 void ChromeContentBrowserClient::WorkerProcessCreated(
1348 SiteInstance
* site_instance
,
1349 int worker_process_id
) {
1350 extensions::ExtensionRegistry
* extension_registry
=
1351 extensions::ExtensionRegistry::Get(site_instance
->GetBrowserContext());
1352 if (!extension_registry
)
1354 const Extension
* extension
=
1355 extension_registry
->enabled_extensions().GetExtensionOrAppByURL(
1356 site_instance
->GetSiteURL());
1359 extensions::ExtensionSystem
* extension_system
=
1360 extensions::ExtensionSystem::Get(site_instance
->GetBrowserContext());
1361 extension_system
->info_map()->RegisterExtensionWorkerProcess(
1364 site_instance
->GetId());
1367 void ChromeContentBrowserClient::WorkerProcessTerminated(
1368 SiteInstance
* site_instance
,
1369 int worker_process_id
) {
1370 extensions::ExtensionSystem
* extension_system
=
1371 extensions::ExtensionSystem::Get(site_instance
->GetBrowserContext());
1372 extension_system
->info_map()->UnregisterExtensionWorkerProcess(
1376 bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
1377 SiteInstance
* site_instance
,
1378 const GURL
& current_url
,
1379 const GURL
& new_url
) {
1380 // If we don't have an ExtensionService, then rely on the SiteInstance logic
1381 // in RenderFrameHostManager to decide when to swap.
1383 Profile::FromBrowserContext(site_instance
->GetBrowserContext());
1384 ExtensionService
* service
=
1385 extensions::ExtensionSystem::Get(profile
)->extension_service();
1389 // We must use a new BrowsingInstance (forcing a process swap and disabling
1390 // scripting by existing tabs) if one of the URLs is an extension and the
1391 // other is not the exact same extension.
1393 // We ignore hosted apps here so that other tabs in their BrowsingInstance can
1394 // use postMessage with them. (The exception is the Chrome Web Store, which
1395 // is a hosted app that requires its own BrowsingInstance.) Navigations
1396 // to/from a hosted app will still trigger a SiteInstance swap in
1397 // RenderFrameHostManager.
1398 const Extension
* current_extension
=
1399 service
->extensions()->GetExtensionOrAppByURL(current_url
);
1400 if (current_extension
&&
1401 current_extension
->is_hosted_app() &&
1402 current_extension
->id() != extension_misc::kWebStoreAppId
)
1403 current_extension
= NULL
;
1405 const Extension
* new_extension
=
1406 service
->extensions()->GetExtensionOrAppByURL(new_url
);
1407 if (new_extension
&&
1408 new_extension
->is_hosted_app() &&
1409 new_extension
->id() != extension_misc::kWebStoreAppId
)
1410 new_extension
= NULL
;
1412 // First do a process check. We should force a BrowsingInstance swap if the
1413 // current process doesn't know about new_extension, even if current_extension
1414 // is somehow the same as new_extension.
1415 extensions::ProcessMap
* process_map
= extensions::ProcessMap::Get(profile
);
1416 if (new_extension
&&
1417 site_instance
->HasProcess() &&
1418 !process_map
->Contains(
1419 new_extension
->id(), site_instance
->GetProcess()->GetID()))
1422 // Otherwise, swap BrowsingInstances if current_extension and new_extension
1424 return current_extension
!= new_extension
;
1427 bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1428 content::ResourceContext
* resource_context
, const GURL
& current_url
,
1429 const GURL
& new_url
) {
1430 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(resource_context
);
1431 return extensions::CrossesExtensionProcessBoundary(
1432 io_data
->GetExtensionInfoMap()->extensions(),
1433 current_url
, new_url
, false);
1436 bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL
& url
) {
1437 return !url
.SchemeIs(chrome::kChromeNativeScheme
);
1440 std::string
ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1441 const std::string
& alias_name
) {
1442 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name
);
1445 void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1446 CommandLine
* command_line
, int child_process_id
) {
1447 #if defined(OS_POSIX)
1448 if (breakpad::IsCrashReporterEnabled()) {
1449 std::string enable_crash_reporter
;
1450 GoogleUpdateSettings::GetMetricsId(&enable_crash_reporter
);
1451 #if !defined(OS_MACOSX)
1452 enable_crash_reporter
+= "," + base::GetLinuxDistro();
1454 command_line
->AppendSwitchASCII(switches::kEnableCrashReporter
,
1455 enable_crash_reporter
);
1459 if (logging::DialogsAreSuppressed())
1460 command_line
->AppendSwitch(switches::kNoErrorDialogs
);
1462 std::string process_type
=
1463 command_line
->GetSwitchValueASCII(switches::kProcessType
);
1464 const CommandLine
& browser_command_line
= *CommandLine::ForCurrentProcess();
1466 static const char* const kCommonSwitchNames
[] = {
1467 switches::kUserDataDir
, // Make logs go to the right file.
1469 command_line
->CopySwitchesFrom(browser_command_line
, kCommonSwitchNames
,
1470 arraysize(kCommonSwitchNames
));
1472 #if defined(ENABLE_IPC_FUZZER)
1473 static const char* const kIpcFuzzerSwitches
[] = {
1474 switches::kIpcFuzzerTestcase
,
1476 command_line
->CopySwitchesFrom(browser_command_line
, kIpcFuzzerSwitches
,
1477 arraysize(kIpcFuzzerSwitches
));
1480 if (process_type
== switches::kRendererProcess
) {
1481 #if defined(OS_CHROMEOS)
1482 const std::string
& login_profile
=
1483 browser_command_line
.GetSwitchValueASCII(
1484 chromeos::switches::kLoginProfile
);
1485 if (!login_profile
.empty())
1486 command_line
->AppendSwitchASCII(
1487 chromeos::switches::kLoginProfile
, login_profile
);
1490 #if defined(ENABLE_WEBRTC)
1491 #if defined(OS_ANDROID)
1492 const VersionInfo::Channel kMaxDisableEncryptionChannel
=
1493 VersionInfo::CHANNEL_BETA
;
1495 const VersionInfo::Channel kMaxDisableEncryptionChannel
=
1496 VersionInfo::CHANNEL_DEV
;
1498 if (VersionInfo::GetChannel() <= kMaxDisableEncryptionChannel
) {
1499 static const char* const kWebRtcDevSwitchNames
[] = {
1500 switches::kDisableWebRtcEncryption
,
1502 command_line
->CopySwitchesFrom(browser_command_line
,
1503 kWebRtcDevSwitchNames
,
1504 arraysize(kWebRtcDevSwitchNames
));
1508 content::RenderProcessHost
* process
=
1509 content::RenderProcessHost::FromID(child_process_id
);
1511 Profile
* profile
= Profile::FromBrowserContext(
1512 process
->GetBrowserContext());
1514 if (extensions::ProcessMap::Get(profile
)->Contains(process
->GetID()))
1515 command_line
->AppendSwitch(extensions::switches::kExtensionProcess
);
1517 PrefService
* prefs
= profile
->GetPrefs();
1518 // Currently this pref is only registered if applied via a policy.
1519 if (prefs
->HasPrefPath(prefs::kDisable3DAPIs
) &&
1520 prefs
->GetBoolean(prefs::kDisable3DAPIs
)) {
1521 // Turn this policy into a command line switch.
1522 command_line
->AppendSwitch(switches::kDisable3DAPIs
);
1525 // Disable client-side phishing detection in the renderer if it is
1526 // disabled in the Profile preferences or the browser process.
1527 if (!prefs
->GetBoolean(prefs::kSafeBrowsingEnabled
) ||
1528 !g_browser_process
->safe_browsing_detection_service()) {
1529 command_line
->AppendSwitch(
1530 switches::kDisableClientSidePhishingDetection
);
1533 if (!prefs
->GetBoolean(prefs::kPrintPreviewDisabled
))
1534 command_line
->AppendSwitch(switches::kRendererPrintPreview
);
1536 InstantService
* instant_service
=
1537 InstantServiceFactory::GetForProfile(profile
);
1538 if (instant_service
&&
1539 instant_service
->IsInstantProcess(process
->GetID()))
1540 command_line
->AppendSwitch(switches::kInstantProcess
);
1542 #if !defined(OS_CHROMEOS)
1543 SigninManager
* signin_manager
=
1544 SigninManagerFactory::GetForProfile(profile
);
1545 if (signin_manager
&& signin_manager
->IsSigninProcess(process
->GetID()))
1546 command_line
->AppendSwitch(switches::kSigninProcess
);
1550 // Please keep this in alphabetical order.
1551 static const char* const kSwitchNames
[] = {
1552 autofill::switches::kDisableIgnoreAutocompleteOff
,
1553 autofill::switches::kDisableInteractiveAutocomplete
,
1554 autofill::switches::kDisablePasswordGeneration
,
1555 autofill::switches::kEnableInteractiveAutocomplete
,
1556 autofill::switches::kEnablePasswordGeneration
,
1557 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration
,
1558 extensions::switches::kAllowHTTPBackgroundPage
,
1559 extensions::switches::kAllowLegacyExtensionManifests
,
1560 extensions::switches::kAllowScriptingGallery
,
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::kEnableNetBenchmarking
,
1578 switches::kEnableStreamlinedHostedApps
,
1579 switches::kEnableWatchdog
,
1580 switches::kMemoryProfiling
,
1581 switches::kMessageLoopHistogrammer
,
1582 switches::kNoJsRandomness
,
1583 switches::kOutOfProcessPdf
,
1584 switches::kPlaybackMode
,
1585 switches::kPpapiFlashArgs
,
1586 switches::kPpapiFlashInProcess
,
1587 switches::kPpapiFlashPath
,
1588 switches::kPpapiFlashVersion
,
1589 switches::kProfilingAtStart
,
1590 switches::kProfilingFile
,
1591 switches::kProfilingFlush
,
1592 switches::kRecordMode
,
1593 switches::kSilentDumpOnDCHECK
,
1594 switches::kWhitelistedExtensionID
,
1595 translate::switches::kTranslateSecurityOrigin
,
1598 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1599 arraysize(kSwitchNames
));
1600 } else if (process_type
== switches::kUtilityProcess
) {
1601 static const char* const kSwitchNames
[] = {
1602 extensions::switches::kAllowHTTPBackgroundPage
,
1603 extensions::switches::kEnableExperimentalExtensionApis
,
1604 extensions::switches::kExtensionsOnChromeURLs
,
1605 switches::kWhitelistedExtensionID
,
1608 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1609 arraysize(kSwitchNames
));
1610 } else if (process_type
== switches::kPluginProcess
) {
1611 static const char* const kSwitchNames
[] = {
1612 #if defined(OS_CHROMEOS)
1613 chromeos::switches::kLoginProfile
,
1615 switches::kMemoryProfiling
,
1616 switches::kSilentDumpOnDCHECK
,
1619 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1620 arraysize(kSwitchNames
));
1621 } else if (process_type
== switches::kZygoteProcess
) {
1622 static const char* const kSwitchNames
[] = {
1623 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
1624 switches::kDisableBundledPpapiFlash
,
1625 switches::kPpapiFlashInProcess
,
1626 switches::kPpapiFlashPath
,
1627 switches::kPpapiFlashVersion
,
1630 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1631 arraysize(kSwitchNames
));
1632 } else if (process_type
== switches::kGpuProcess
) {
1633 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1634 // because GPU is expected to be unreliable.
1635 if (browser_command_line
.HasSwitch(switches::kIgnoreGpuBlacklist
) &&
1636 !command_line
->HasSwitch(switches::kDisableBreakpad
))
1637 command_line
->AppendSwitch(switches::kDisableBreakpad
);
1640 // The command line switch kEnableBenchmarking needs to be specified along
1641 // with the kEnableStatsTable switch to ensure that the stats table global
1642 // is initialized correctly.
1643 if (command_line
->HasSwitch(switches::kEnableBenchmarking
))
1644 DCHECK(command_line
->HasSwitch(switches::kEnableStatsTable
));
1647 std::string
ChromeContentBrowserClient::GetApplicationLocale() {
1648 if (BrowserThread::CurrentlyOn(BrowserThread::IO
))
1649 return g_io_thread_application_locale
.Get();
1650 return g_browser_process
->GetApplicationLocale();
1653 std::string
ChromeContentBrowserClient::GetAcceptLangs(
1654 content::BrowserContext
* context
) {
1655 Profile
* profile
= Profile::FromBrowserContext(context
);
1656 return profile
->GetPrefs()->GetString(prefs::kAcceptLanguages
);
1659 gfx::ImageSkia
* ChromeContentBrowserClient::GetDefaultFavicon() {
1660 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
1661 return rb
.GetImageSkiaNamed(IDR_DEFAULT_FAVICON
);
1664 bool ChromeContentBrowserClient::AllowAppCache(
1665 const GURL
& manifest_url
,
1666 const GURL
& first_party
,
1667 content::ResourceContext
* context
) {
1668 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1669 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1670 return io_data
->GetCookieSettings()->
1671 IsSettingCookieAllowed(manifest_url
, first_party
);
1674 bool ChromeContentBrowserClient::AllowGetCookie(
1676 const GURL
& first_party
,
1677 const net::CookieList
& cookie_list
,
1678 content::ResourceContext
* context
,
1679 int render_process_id
,
1680 int render_frame_id
) {
1681 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1682 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1683 bool allow
= io_data
->GetCookieSettings()->
1684 IsReadingCookieAllowed(url
, first_party
);
1686 BrowserThread::PostTask(
1687 BrowserThread::UI
, FROM_HERE
,
1688 base::Bind(&TabSpecificContentSettings::CookiesRead
, render_process_id
,
1689 render_frame_id
, url
, first_party
, cookie_list
, !allow
));
1693 bool ChromeContentBrowserClient::AllowSetCookie(
1695 const GURL
& first_party
,
1696 const std::string
& cookie_line
,
1697 content::ResourceContext
* context
,
1698 int render_process_id
,
1699 int render_frame_id
,
1700 net::CookieOptions
* options
) {
1701 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1702 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1703 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1704 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, first_party
);
1706 BrowserThread::PostTask(
1707 BrowserThread::UI
, FROM_HERE
,
1708 base::Bind(&TabSpecificContentSettings::CookieChanged
, render_process_id
,
1709 render_frame_id
, url
, first_party
, cookie_line
, *options
,
1714 bool ChromeContentBrowserClient::AllowSaveLocalState(
1715 content::ResourceContext
* context
) {
1716 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1717 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1718 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1719 ContentSetting setting
= cookie_settings
->GetDefaultCookieSetting(NULL
);
1721 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1722 // Could we even support per-origin settings?
1723 return setting
!= CONTENT_SETTING_SESSION_ONLY
;
1726 bool ChromeContentBrowserClient::AllowWorkerDatabase(
1728 const base::string16
& name
,
1729 const base::string16
& display_name
,
1730 unsigned long estimated_size
,
1731 content::ResourceContext
* context
,
1732 const std::vector
<std::pair
<int, int> >& render_frames
) {
1733 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1734 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1735 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1736 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1738 // Record access to database for potential display in UI.
1739 std::vector
<std::pair
<int, int> >::const_iterator i
;
1740 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1741 BrowserThread::PostTask(
1742 BrowserThread::UI
, FROM_HERE
,
1743 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed
,
1744 i
->first
, i
->second
, url
, name
, display_name
, !allow
));
1750 bool ChromeContentBrowserClient::AllowWorkerFileSystem(
1752 content::ResourceContext
* context
,
1753 const std::vector
<std::pair
<int, int> >& render_frames
) {
1754 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1755 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1756 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1757 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1759 // Record access to file system for potential display in UI.
1760 std::vector
<std::pair
<int, int> >::const_iterator i
;
1761 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1762 BrowserThread::PostTask(
1763 BrowserThread::UI
, FROM_HERE
,
1764 base::Bind(&TabSpecificContentSettings::FileSystemAccessed
,
1765 i
->first
, i
->second
, url
, !allow
));
1771 bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1773 const base::string16
& name
,
1774 content::ResourceContext
* context
,
1775 const std::vector
<std::pair
<int, int> >& render_frames
) {
1776 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1777 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1778 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1779 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1781 // Record access to IndexedDB for potential display in UI.
1782 std::vector
<std::pair
<int, int> >::const_iterator i
;
1783 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1784 BrowserThread::PostTask(
1785 BrowserThread::UI
, FROM_HERE
,
1786 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed
,
1787 i
->first
, i
->second
, url
, name
, !allow
));
1793 net::URLRequestContext
*
1794 ChromeContentBrowserClient::OverrideRequestContextForURL(
1795 const GURL
& url
, content::ResourceContext
* context
) {
1796 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1797 if (url
.SchemeIs(extensions::kExtensionScheme
)) {
1798 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1799 return io_data
->extensions_request_context();
1805 QuotaPermissionContext
*
1806 ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1807 return new ChromeQuotaPermissionContext();
1810 void ChromeContentBrowserClient::AllowCertificateError(
1811 int render_process_id
,
1812 int render_frame_id
,
1814 const net::SSLInfo
& ssl_info
,
1815 const GURL
& request_url
,
1816 ResourceType::Type resource_type
,
1818 bool strict_enforcement
,
1819 const base::Callback
<void(bool)>& callback
,
1820 content::CertificateRequestResultType
* result
) {
1821 if (resource_type
!= ResourceType::MAIN_FRAME
) {
1822 // A sub-resource has a certificate error. The user doesn't really
1823 // have a context for making the right decision, so block the
1824 // request hard, without an info bar to allow showing the insecure
1826 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY
;
1830 // If the tab is being prerendered, cancel the prerender and the request.
1831 content::RenderFrameHost
* render_frame_host
=
1832 content::RenderFrameHost::FromID(render_process_id
, render_frame_id
);
1833 WebContents
* tab
= WebContents::FromRenderFrameHost(render_frame_host
);
1839 prerender::PrerenderContents
* prerender_contents
=
1840 prerender::PrerenderContents::FromWebContents(tab
);
1841 if (prerender_contents
) {
1842 prerender_contents
->Destroy(prerender::FINAL_STATUS_SSL_ERROR
);
1843 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL
;
1847 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
1848 captive_portal::CaptivePortalTabHelper
* captive_portal_tab_helper
=
1849 captive_portal::CaptivePortalTabHelper::FromWebContents(tab
);
1850 if (captive_portal_tab_helper
)
1851 captive_portal_tab_helper
->OnSSLCertError(ssl_info
);
1854 // Otherwise, display an SSL blocking page.
1855 new SSLBlockingPage(tab
, cert_error
, ssl_info
, request_url
, overridable
,
1856 strict_enforcement
, callback
);
1859 void ChromeContentBrowserClient::SelectClientCertificate(
1860 int render_process_id
,
1861 int render_frame_id
,
1862 const net::HttpNetworkSession
* network_session
,
1863 net::SSLCertRequestInfo
* cert_request_info
,
1864 const base::Callback
<void(net::X509Certificate
*)>& callback
) {
1865 content::RenderFrameHost
* rfh
= content::RenderFrameHost::FromID(
1866 render_process_id
, render_frame_id
);
1867 WebContents
* tab
= WebContents::FromRenderFrameHost(rfh
);
1873 prerender::PrerenderContents
* prerender_contents
=
1874 prerender::PrerenderContents::FromWebContents(tab
);
1875 if (prerender_contents
) {
1876 prerender_contents
->Destroy(
1877 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED
);
1881 GURL
requesting_url("https://" + cert_request_info
->host_and_port
.ToString());
1882 DCHECK(requesting_url
.is_valid())
1883 << "Invalid URL string: https://"
1884 << cert_request_info
->host_and_port
.ToString();
1886 Profile
* profile
= Profile::FromBrowserContext(tab
->GetBrowserContext());
1887 scoped_ptr
<base::Value
> filter(
1888 profile
->GetHostContentSettingsMap()->GetWebsiteSetting(
1891 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE
,
1892 std::string(), NULL
));
1895 // Try to automatically select a client certificate.
1896 if (filter
->IsType(base::Value::TYPE_DICTIONARY
)) {
1897 base::DictionaryValue
* filter_dict
=
1898 static_cast<base::DictionaryValue
*>(filter
.get());
1900 const std::vector
<scoped_refptr
<net::X509Certificate
> >&
1901 all_client_certs
= cert_request_info
->client_certs
;
1902 for (size_t i
= 0; i
< all_client_certs
.size(); ++i
) {
1903 if (CertMatchesFilter(*all_client_certs
[i
].get(), *filter_dict
)) {
1904 // Use the first certificate that is matched by the filter.
1905 callback
.Run(all_client_certs
[i
].get());
1914 SSLTabHelper
* ssl_tab_helper
= SSLTabHelper::FromWebContents(tab
);
1915 if (!ssl_tab_helper
) {
1916 // If there is no SSLTabHelper for the given WebContents then we can't
1917 // show the user a dialog to select a client certificate. So we simply
1918 // proceed with no client certificate.
1922 ssl_tab_helper
->ShowClientCertificateRequestDialog(
1923 network_session
, cert_request_info
, callback
);
1926 void ChromeContentBrowserClient::AddCertificate(
1927 net::URLRequest
* request
,
1928 net::CertificateMimeType cert_type
,
1929 const void* cert_data
,
1931 int render_process_id
,
1932 int render_view_id
) {
1933 chrome::SSLAddCertificate(request
, cert_type
, cert_data
, cert_size
,
1934 render_process_id
, render_view_id
);
1937 content::MediaObserver
* ChromeContentBrowserClient::GetMediaObserver() {
1938 return MediaCaptureDevicesDispatcher::GetInstance();
1941 void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1942 const GURL
& source_origin
,
1943 int callback_context
,
1944 int render_process_id
,
1945 int render_view_id
) {
1946 #if defined(ENABLE_NOTIFICATIONS)
1947 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
1948 WebContents
* contents
=
1949 tab_util::GetWebContentsByID(render_process_id
, render_view_id
);
1955 // Skip showing the infobar if the request comes from an extension, and that
1956 // extension has the 'notify' permission. (If the extension does not have the
1957 // permission, the user will still be prompted.)
1958 Profile
* profile
= Profile::FromBrowserContext(contents
->GetBrowserContext());
1959 InfoMap
* extension_info_map
=
1960 extensions::ExtensionSystem::Get(profile
)->info_map();
1961 DesktopNotificationService
* notification_service
=
1962 DesktopNotificationServiceFactory::GetForProfile(profile
);
1963 const Extension
* extension
= NULL
;
1964 if (extension_info_map
) {
1965 extensions::ExtensionSet extensions
;
1966 extension_info_map
->GetExtensionsWithAPIPermissionForSecurityOrigin(
1967 source_origin
, render_process_id
,
1968 extensions::APIPermission::kNotification
, &extensions
);
1969 for (extensions::ExtensionSet::const_iterator iter
= extensions
.begin();
1970 iter
!= extensions
.end(); ++iter
) {
1971 if (notification_service
->IsNotifierEnabled(NotifierId(
1972 NotifierId::APPLICATION
, (*iter
)->id()))) {
1973 extension
= iter
->get();
1978 RenderViewHost
* rvh
=
1979 RenderViewHost::FromID(render_process_id
, render_view_id
);
1980 if (IsExtensionWithPermissionOrSuggestInConsole(
1981 APIPermission::kNotification
, extension
, rvh
)) {
1983 rvh
->DesktopNotificationPermissionRequestDone(callback_context
);
1987 notification_service
->RequestPermission(source_origin
, render_process_id
,
1988 render_view_id
, callback_context
, contents
);
1994 blink::WebNotificationPresenter::Permission
1995 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
1996 const GURL
& source_origin
,
1997 content::ResourceContext
* context
,
1998 int render_process_id
) {
1999 #if defined(ENABLE_NOTIFICATIONS)
2000 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
2002 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
2003 InfoMap
* extension_info_map
= io_data
->GetExtensionInfoMap();
2005 // We want to see if there is an extension that hasn't been manually disabled
2006 // that has the notifications permission and applies to this security origin.
2007 // First, get the list of extensions with permission for the origin.
2008 extensions::ExtensionSet extensions
;
2009 extension_info_map
->GetExtensionsWithAPIPermissionForSecurityOrigin(
2010 source_origin
, render_process_id
,
2011 extensions::APIPermission::kNotification
, &extensions
);
2012 for (extensions::ExtensionSet::const_iterator iter
= extensions
.begin();
2013 iter
!= extensions
.end(); ++iter
) {
2014 // Then, check to see if it's been disabled by the user.
2015 if (!extension_info_map
->AreNotificationsDisabled((*iter
)->id()))
2016 return blink::WebNotificationPresenter::PermissionAllowed
;
2019 // No enabled extensions exist, so check the normal host content settings.
2020 HostContentSettingsMap
* host_content_settings_map
=
2021 io_data
->GetHostContentSettingsMap();
2022 ContentSetting setting
= host_content_settings_map
->GetContentSetting(
2025 CONTENT_SETTINGS_TYPE_NOTIFICATIONS
,
2026 NO_RESOURCE_IDENTIFIER
);
2028 if (setting
== CONTENT_SETTING_ALLOW
)
2029 return blink::WebNotificationPresenter::PermissionAllowed
;
2030 if (setting
== CONTENT_SETTING_BLOCK
)
2031 return blink::WebNotificationPresenter::PermissionDenied
;
2032 return blink::WebNotificationPresenter::PermissionNotAllowed
;
2034 return blink::WebNotificationPresenter::PermissionAllowed
;
2038 void ChromeContentBrowserClient::ShowDesktopNotification(
2039 const content::ShowDesktopNotificationHostMsgParams
& params
,
2040 int render_process_id
,
2043 #if defined(ENABLE_NOTIFICATIONS)
2044 RenderViewHost
* rvh
= RenderViewHost::FromID(
2045 render_process_id
, render_view_id
);
2051 content::RenderProcessHost
* process
= rvh
->GetProcess();
2052 Profile
* profile
= Profile::FromBrowserContext(process
->GetBrowserContext());
2053 DesktopNotificationService
* service
=
2054 DesktopNotificationServiceFactory::GetForProfile(profile
);
2055 service
->ShowDesktopNotification(
2056 params
, render_process_id
, render_view_id
,
2057 worker
? DesktopNotificationService::WorkerNotification
:
2058 DesktopNotificationService::PageNotification
);
2064 void ChromeContentBrowserClient::CancelDesktopNotification(
2065 int render_process_id
,
2067 int notification_id
) {
2068 #if defined(ENABLE_NOTIFICATIONS)
2069 RenderViewHost
* rvh
= RenderViewHost::FromID(
2070 render_process_id
, render_view_id
);
2076 content::RenderProcessHost
* process
= rvh
->GetProcess();
2077 Profile
* profile
= Profile::FromBrowserContext(process
->GetBrowserContext());
2078 DesktopNotificationService
* service
=
2079 DesktopNotificationServiceFactory::GetForProfile(profile
);
2080 service
->CancelDesktopNotification(
2081 render_process_id
, render_view_id
, notification_id
);
2087 bool ChromeContentBrowserClient::CanCreateWindow(
2088 const GURL
& opener_url
,
2089 const GURL
& opener_top_level_frame_url
,
2090 const GURL
& source_origin
,
2091 WindowContainerType container_type
,
2092 const GURL
& target_url
,
2093 const content::Referrer
& referrer
,
2094 WindowOpenDisposition disposition
,
2095 const WebWindowFeatures
& features
,
2097 bool opener_suppressed
,
2098 content::ResourceContext
* context
,
2099 int render_process_id
,
2102 bool* no_javascript_access
) {
2103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
2105 *no_javascript_access
= false;
2107 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
2108 InfoMap
* map
= io_data
->GetExtensionInfoMap();
2110 // If the opener is trying to create a background window but doesn't have
2111 // the appropriate permission, fail the attempt.
2112 if (container_type
== WINDOW_CONTAINER_TYPE_BACKGROUND
) {
2113 if (!map
->SecurityOriginHasAPIPermission(
2116 APIPermission::kBackground
)) {
2120 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2121 // return a recently installed Extension even if this CanCreateWindow call
2122 // was made by an old copy of the page in a normal web process. That's ok,
2123 // because the permission check above would have caused an early return
2124 // already. We must use the full URL to find hosted apps, though, and not
2126 const Extension
* extension
=
2127 map
->extensions().GetExtensionOrAppByURL(opener_url
);
2128 if (extension
&& !extensions::BackgroundInfo::AllowJSAccess(extension
))
2129 *no_javascript_access
= true;
2134 // No new browser window (popup or tab) in app mode.
2135 if (container_type
== WINDOW_CONTAINER_TYPE_NORMAL
&&
2136 chrome::IsRunningInForcedAppMode()) {
2143 HostContentSettingsMap
* content_settings
=
2144 ProfileIOData::FromResourceContext(context
)->GetHostContentSettingsMap();
2145 BlockedWindowParams
blocked_params(target_url
,
2154 if (!user_gesture
&& !CommandLine::ForCurrentProcess()->HasSwitch(
2155 switches::kDisablePopupBlocking
)) {
2156 if (content_settings
->GetContentSetting(opener_top_level_frame_url
,
2157 opener_top_level_frame_url
,
2158 CONTENT_SETTINGS_TYPE_POPUPS
,
2160 CONTENT_SETTING_ALLOW
) {
2161 BrowserThread::PostTask(BrowserThread::UI
,
2163 base::Bind(&HandleBlockedPopupOnUIThread
,
2169 #if defined(OS_ANDROID)
2170 if (SingleTabModeTabHelper::IsRegistered(render_process_id
, opener_id
)) {
2171 BrowserThread::PostTask(BrowserThread::UI
,
2173 base::Bind(&HandleSingleTabModeBlockOnUIThread
,
2182 std::string
ChromeContentBrowserClient::GetWorkerProcessTitle(
2183 const GURL
& url
, content::ResourceContext
* context
) {
2184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
2185 // Check if it's an extension-created worker, in which case we want to use
2186 // the name of the extension.
2187 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
2188 const Extension
* extension
=
2189 io_data
->GetExtensionInfoMap()->extensions().GetByID(url
.host());
2190 return extension
? extension
->name() : std::string();
2193 void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2194 return g_browser_process
->ResourceDispatcherHostCreated();
2197 // TODO(tommi): Rename from Get to Create.
2198 content::SpeechRecognitionManagerDelegate
*
2199 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
2200 #if defined(ENABLE_INPUT_SPEECH)
2201 return new speech::ChromeSpeechRecognitionManagerDelegateBubbleUI();
2203 // Platforms who don't implement x-webkit-speech (a.k.a INPUT_SPEECH) just
2204 // need the base delegate without the bubble UI.
2205 return new speech::ChromeSpeechRecognitionManagerDelegate();
2209 net::NetLog
* ChromeContentBrowserClient::GetNetLog() {
2210 return g_browser_process
->net_log();
2213 AccessTokenStore
* ChromeContentBrowserClient::CreateAccessTokenStore() {
2214 return new ChromeAccessTokenStore();
2217 bool ChromeContentBrowserClient::IsFastShutdownPossible() {
2221 void ChromeContentBrowserClient::OverrideWebkitPrefs(
2222 RenderViewHost
* rvh
, const GURL
& url
, WebPreferences
* web_prefs
) {
2223 Profile
* profile
= Profile::FromBrowserContext(
2224 rvh
->GetProcess()->GetBrowserContext());
2225 PrefService
* prefs
= profile
->GetPrefs();
2227 // Fill per-script font preferences. These are not registered on Android
2228 // - http://crbug.com/308033.
2229 #if !defined(OS_ANDROID)
2230 FillFontFamilyMap(prefs
, prefs::kWebKitStandardFontFamilyMap
,
2231 &web_prefs
->standard_font_family_map
);
2232 FillFontFamilyMap(prefs
, prefs::kWebKitFixedFontFamilyMap
,
2233 &web_prefs
->fixed_font_family_map
);
2234 FillFontFamilyMap(prefs
, prefs::kWebKitSerifFontFamilyMap
,
2235 &web_prefs
->serif_font_family_map
);
2236 FillFontFamilyMap(prefs
, prefs::kWebKitSansSerifFontFamilyMap
,
2237 &web_prefs
->sans_serif_font_family_map
);
2238 FillFontFamilyMap(prefs
, prefs::kWebKitCursiveFontFamilyMap
,
2239 &web_prefs
->cursive_font_family_map
);
2240 FillFontFamilyMap(prefs
, prefs::kWebKitFantasyFontFamilyMap
,
2241 &web_prefs
->fantasy_font_family_map
);
2242 FillFontFamilyMap(prefs
, prefs::kWebKitPictographFontFamilyMap
,
2243 &web_prefs
->pictograph_font_family_map
);
2246 web_prefs
->default_font_size
=
2247 prefs
->GetInteger(prefs::kWebKitDefaultFontSize
);
2248 web_prefs
->default_fixed_font_size
=
2249 prefs
->GetInteger(prefs::kWebKitDefaultFixedFontSize
);
2250 web_prefs
->minimum_font_size
=
2251 prefs
->GetInteger(prefs::kWebKitMinimumFontSize
);
2252 web_prefs
->minimum_logical_font_size
=
2253 prefs
->GetInteger(prefs::kWebKitMinimumLogicalFontSize
);
2255 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2257 web_prefs
->javascript_can_open_windows_automatically
=
2258 prefs
->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically
);
2259 web_prefs
->dom_paste_enabled
=
2260 prefs
->GetBoolean(prefs::kWebKitDomPasteEnabled
);
2261 web_prefs
->shrinks_standalone_images_to_fit
=
2262 prefs
->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit
);
2263 const base::DictionaryValue
* inspector_settings
=
2264 prefs
->GetDictionary(prefs::kWebKitInspectorSettings
);
2265 if (inspector_settings
) {
2266 for (base::DictionaryValue::Iterator
iter(*inspector_settings
);
2270 if (iter
.value().GetAsString(&value
)) {
2271 web_prefs
->inspector_settings
.push_back(
2272 std::make_pair(iter
.key(), value
));
2276 web_prefs
->tabs_to_links
= prefs
->GetBoolean(prefs::kWebkitTabsToLinks
);
2278 if (!prefs
->GetBoolean(prefs::kWebKitJavascriptEnabled
))
2279 web_prefs
->javascript_enabled
= false;
2280 if (!prefs
->GetBoolean(prefs::kWebKitWebSecurityEnabled
))
2281 web_prefs
->web_security_enabled
= false;
2282 if (!prefs
->GetBoolean(prefs::kWebKitPluginsEnabled
))
2283 web_prefs
->plugins_enabled
= false;
2284 if (!prefs
->GetBoolean(prefs::kWebKitJavaEnabled
))
2285 web_prefs
->java_enabled
= false;
2286 web_prefs
->loads_images_automatically
=
2287 prefs
->GetBoolean(prefs::kWebKitLoadsImagesAutomatically
);
2289 if (prefs
->GetBoolean(prefs::kDisable3DAPIs
))
2290 web_prefs
->experimental_webgl_enabled
= false;
2292 web_prefs
->memory_info_enabled
=
2293 prefs
->GetBoolean(prefs::kEnableMemoryInfo
);
2294 web_prefs
->allow_displaying_insecure_content
=
2295 prefs
->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent
);
2296 web_prefs
->allow_running_insecure_content
=
2297 prefs
->GetBoolean(prefs::kWebKitAllowRunningInsecureContent
);
2298 #if defined(OS_ANDROID)
2299 web_prefs
->font_scale_factor
=
2300 static_cast<float>(prefs
->GetDouble(prefs::kWebKitFontScaleFactor
));
2301 web_prefs
->device_scale_adjustment
= GetDeviceScaleAdjustment();
2302 web_prefs
->force_enable_zoom
=
2303 prefs
->GetBoolean(prefs::kWebKitForceEnableZoom
);
2306 #if defined(OS_ANDROID)
2307 web_prefs
->password_echo_enabled
=
2308 prefs
->GetBoolean(prefs::kWebKitPasswordEchoEnabled
);
2310 web_prefs
->password_echo_enabled
= browser_defaults::kPasswordEchoEnabled
;
2313 web_prefs
->asynchronous_spell_checking_enabled
= true;
2314 web_prefs
->unified_textchecker_enabled
= true;
2316 web_prefs
->uses_universal_detector
=
2317 prefs
->GetBoolean(prefs::kWebKitUsesUniversalDetector
);
2318 web_prefs
->text_areas_are_resizable
=
2319 prefs
->GetBoolean(prefs::kWebKitTextAreasAreResizable
);
2320 web_prefs
->hyperlink_auditing_enabled
=
2321 prefs
->GetBoolean(prefs::kEnableHyperlinkAuditing
);
2323 // Make sure we will set the default_encoding with canonical encoding name.
2324 web_prefs
->default_encoding
=
2325 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
2326 web_prefs
->default_encoding
);
2327 if (web_prefs
->default_encoding
.empty()) {
2328 prefs
->ClearPref(prefs::kDefaultCharset
);
2329 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2331 DCHECK(!web_prefs
->default_encoding
.empty());
2333 WebContents
* web_contents
= WebContents::FromRenderViewHost(rvh
);
2334 extensions::ViewType view_type
= extensions::GetViewType(web_contents
);
2335 ExtensionService
* service
=
2336 extensions::ExtensionSystem::Get(profile
)->extension_service();
2338 const GURL
& site_url
= rvh
->GetSiteInstance()->GetSiteURL();
2339 const Extension
* extension
=
2340 service
->extensions()->GetByID(site_url
.host());
2341 // Ensure that we are only granting extension preferences to URLs with
2342 // the correct scheme. Without this check, chrome-guest:// schemes used by
2343 // webview tags as well as hosts that happen to match the id of an
2344 // installed extension would get the wrong preferences.
2345 if (site_url
.SchemeIs(extensions::kExtensionScheme
)) {
2346 extension_webkit_preferences::SetPreferences(
2347 extension
, view_type
, web_prefs
);
2351 if (view_type
== extensions::VIEW_TYPE_NOTIFICATION
) {
2352 web_prefs
->allow_scripts_to_close_windows
= true;
2353 } else if (view_type
== extensions::VIEW_TYPE_BACKGROUND_CONTENTS
) {
2354 // Disable all kinds of acceleration for background pages.
2355 // See http://crbug.com/96005 and http://crbug.com/96006
2356 web_prefs
->force_compositing_mode
= false;
2357 web_prefs
->accelerated_compositing_enabled
= false;
2360 #if defined(OS_CHROMEOS)
2361 // Override the default of suppressing HW compositing for WebUI pages for the
2362 // file manager, which is implemented using WebUI but wants HW acceleration
2363 // for video decode & render.
2364 if (url
.SchemeIs(extensions::kExtensionScheme
) &&
2365 url
.host() == file_manager::kFileManagerAppId
) {
2366 web_prefs
->accelerated_compositing_enabled
= true;
2367 web_prefs
->accelerated_2d_canvas_enabled
= true;
2372 void ChromeContentBrowserClient::UpdateInspectorSetting(
2373 RenderViewHost
* rvh
, const std::string
& key
, const std::string
& value
) {
2374 content::BrowserContext
* browser_context
=
2375 rvh
->GetProcess()->GetBrowserContext();
2376 DictionaryPrefUpdate
update(
2377 Profile::FromBrowserContext(browser_context
)->GetPrefs(),
2378 prefs::kWebKitInspectorSettings
);
2379 base::DictionaryValue
* inspector_settings
= update
.Get();
2380 inspector_settings
->SetWithoutPathExpansion(
2381 key
, base::Value::CreateStringValue(value
));
2384 void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2385 BrowserURLHandler
* handler
) {
2386 // Add the default URL handlers.
2387 handler
->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride
,
2388 BrowserURLHandler::null_handler());
2389 handler
->AddHandlerPair(BrowserURLHandler::null_handler(),
2390 &ExtensionWebUI::HandleChromeURLOverrideReverse
);
2392 // about: handler. Must come before chrome: handler, since it will
2393 // rewrite about: urls to chrome: URLs and then expect chrome: to
2394 // actually handle them.
2395 handler
->AddHandlerPair(&WillHandleBrowserAboutURL
,
2396 BrowserURLHandler::null_handler());
2398 // Handler to rewrite chrome://newtab for InstantExtended.
2399 handler
->AddHandlerPair(&chrome::HandleNewTabURLRewrite
,
2400 &chrome::HandleNewTabURLReverseRewrite
);
2402 // chrome: & friends.
2403 handler
->AddHandlerPair(&HandleWebUI
, &HandleWebUIReverse
);
2406 void ChromeContentBrowserClient::ClearCache(RenderViewHost
* rvh
) {
2407 Profile
* profile
= Profile::FromBrowserContext(
2408 rvh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2409 BrowsingDataRemover
* remover
=
2410 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2411 remover
->Remove(BrowsingDataRemover::REMOVE_CACHE
,
2412 BrowsingDataHelper::UNPROTECTED_WEB
);
2413 // BrowsingDataRemover takes care of deleting itself when done.
2416 void ChromeContentBrowserClient::ClearCookies(RenderViewHost
* rvh
) {
2417 Profile
* profile
= Profile::FromBrowserContext(
2418 rvh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2419 BrowsingDataRemover
* remover
=
2420 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2421 int remove_mask
= BrowsingDataRemover::REMOVE_SITE_DATA
;
2422 remover
->Remove(remove_mask
, BrowsingDataHelper::UNPROTECTED_WEB
);
2423 // BrowsingDataRemover takes care of deleting itself when done.
2426 base::FilePath
ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
2427 return DownloadPrefs::GetDefaultDownloadDirectory();
2430 std::string
ChromeContentBrowserClient::GetDefaultDownloadName() {
2431 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME
);
2434 void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2435 content::BrowserPpapiHost
* browser_host
) {
2436 #if defined(ENABLE_PLUGINS)
2437 browser_host
->GetPpapiHost()->AddHostFactoryFilter(
2438 scoped_ptr
<ppapi::host::HostFactory
>(
2439 new ChromeBrowserPepperHostFactory(browser_host
)));
2443 content::BrowserPpapiHost
*
2444 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2445 int plugin_process_id
) {
2446 BrowserChildProcessHostIterator
iter(PROCESS_TYPE_NACL_LOADER
);
2447 while (!iter
.Done()) {
2448 nacl::NaClProcessHost
* host
= static_cast<nacl::NaClProcessHost
*>(
2449 iter
.GetDelegate());
2450 if (host
->process() &&
2451 host
->process()->GetData().id
== plugin_process_id
) {
2452 // Found the plugin.
2453 return host
->browser_ppapi_host();
2460 bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2461 content::BrowserContext
* browser_context
, const GURL
& site_url
) {
2462 if (CommandLine::ForCurrentProcess()->HasSwitch(
2463 switches::kEnableBrowserPluginForAllViewTypes
))
2466 if (content::HasWebUIScheme(site_url
))
2469 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
2470 ExtensionService
* service
=
2471 extensions::ExtensionSystem::Get(profile
)->extension_service();
2475 const Extension
* extension
=
2476 service
->extensions()->GetExtensionOrAppByURL(site_url
);
2480 return extension
->HasAPIPermission(APIPermission::kWebView
) ||
2481 extension
->HasAPIPermission(APIPermission::kAdView
);
2484 bool ChromeContentBrowserClient::AllowPepperSocketAPI(
2485 content::BrowserContext
* browser_context
,
2488 const content::SocketPermissionRequest
* params
) {
2489 #if defined(ENABLE_PLUGINS)
2490 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
2491 const extensions::ExtensionSet
* extension_set
= NULL
;
2493 extension_set
= extensions::ExtensionSystem::Get(profile
)->
2494 extension_service()->extensions();
2498 // Access to private socket APIs is controlled by the whitelist.
2499 if (IsExtensionOrSharedModuleWhitelisted(url
, extension_set
,
2500 allowed_socket_origins_
)) {
2504 // Access to public socket APIs is controlled by extension permissions.
2505 if (url
.is_valid() && url
.SchemeIs(extensions::kExtensionScheme
) &&
2507 const Extension
* extension
= extension_set
->GetByID(url
.host());
2510 extensions::SocketPermission::CheckParam
check_params(
2511 params
->type
, params
->host
, params
->port
);
2512 if (extensions::PermissionsData::CheckAPIPermissionWithParam(
2513 extension
, extensions::APIPermission::kSocket
,
2518 if (extensions::PermissionsData::HasAPIPermission(
2519 extension
, extensions::APIPermission::kSocket
)) {
2527 // Allow both public and private APIs if the command line says so.
2528 return IsHostAllowedByCommandLine(url
, extension_set
,
2529 switches::kAllowNaClSocketAPI
);
2535 ui::SelectFilePolicy
* ChromeContentBrowserClient::CreateSelectFilePolicy(
2536 WebContents
* web_contents
) {
2537 return new ChromeSelectFilePolicy(web_contents
);
2540 void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2541 std::vector
<std::string
>* additional_allowed_schemes
) {
2542 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2543 additional_allowed_schemes
);
2544 additional_allowed_schemes
->push_back(kChromeDevToolsScheme
);
2545 additional_allowed_schemes
->push_back(content::kChromeUIScheme
);
2546 additional_allowed_schemes
->push_back(extensions::kExtensionScheme
);
2549 void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
2550 content::BrowserContext
* browser_context
,
2551 const base::FilePath
& storage_partition_path
,
2552 ScopedVector
<fileapi::FileSystemBackend
>* additional_backends
) {
2553 #if !defined(OS_ANDROID)
2554 base::SequencedWorkerPool
* pool
= content::BrowserThread::GetBlockingPool();
2555 additional_backends
->push_back(new MediaFileSystemBackend(
2556 storage_partition_path
,
2557 pool
->GetSequencedTaskRunner(pool
->GetNamedSequenceToken(
2558 MediaFileSystemBackend::kMediaTaskRunnerName
)).get()));
2560 #if defined(OS_CHROMEOS)
2561 fileapi::ExternalMountPoints
* external_mount_points
=
2562 content::BrowserContext::GetMountPoints(browser_context
);
2563 DCHECK(external_mount_points
);
2564 chromeos::FileSystemBackend
* backend
=
2565 new chromeos::FileSystemBackend(
2566 new drive::FileSystemBackendDelegate
,
2567 browser_context
->GetSpecialStoragePolicy(),
2568 external_mount_points
,
2569 fileapi::ExternalMountPoints::GetSystemInstance());
2570 backend
->AddSystemMountPoints();
2571 DCHECK(backend
->CanHandleType(fileapi::kFileSystemTypeExternal
));
2572 additional_backends
->push_back(backend
);
2575 additional_backends
->push_back(
2576 new sync_file_system::SyncFileSystemBackend(
2577 Profile::FromBrowserContext(browser_context
)));
2579 if (CommandLine::ForCurrentProcess()->HasSwitch(
2580 switches::kEnablePrivetStorage
)) {
2581 additional_backends
->push_back(
2582 new local_discovery::PrivetFileSystemBackend(
2583 fileapi::ExternalMountPoints::GetSystemInstance()));
2587 #if defined(OS_POSIX) && !defined(OS_MACOSX)
2588 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2589 const CommandLine
& command_line
,
2590 int child_process_id
,
2591 std::vector
<FileDescriptorInfo
>* mappings
) {
2592 #if defined(OS_ANDROID)
2593 base::FilePath data_path
;
2594 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID
, &data_path
);
2595 DCHECK(!data_path
.empty());
2597 int flags
= base::PLATFORM_FILE_OPEN
| base::PLATFORM_FILE_READ
;
2598 base::FilePath chrome_resources_pak
=
2599 data_path
.AppendASCII("chrome_100_percent.pak");
2600 base::PlatformFile f
=
2601 base::CreatePlatformFile(chrome_resources_pak
, flags
, NULL
, NULL
);
2602 DCHECK(f
!= base::kInvalidPlatformFileValue
);
2603 mappings
->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor
,
2604 FileDescriptor(f
, true)));
2606 const std::string locale
= GetApplicationLocale();
2607 base::FilePath locale_pak
= ResourceBundle::GetSharedInstance().
2608 GetLocaleFilePath(locale
, false);
2609 f
= base::CreatePlatformFile(locale_pak
, flags
, NULL
, NULL
);
2610 DCHECK(f
!= base::kInvalidPlatformFileValue
);
2611 mappings
->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor
,
2612 FileDescriptor(f
, true)));
2614 base::FilePath resources_pack_path
;
2615 PathService::Get(chrome::FILE_RESOURCES_PACK
, &resources_pack_path
);
2616 f
= base::CreatePlatformFile(resources_pack_path
, flags
, NULL
, NULL
);
2617 DCHECK(f
!= base::kInvalidPlatformFileValue
);
2618 mappings
->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor
,
2619 FileDescriptor(f
, true)));
2621 if (breakpad::IsCrashReporterEnabled()) {
2622 f
= breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile(
2624 if (f
== base::kInvalidPlatformFileValue
) {
2625 LOG(ERROR
) << "Failed to create file for minidump, crash reporting will "
2626 "be disabled for this process.";
2628 mappings
->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor
,
2629 FileDescriptor(f
, true)));
2634 int crash_signal_fd
= GetCrashSignalFD(command_line
);
2635 if (crash_signal_fd
>= 0) {
2636 mappings
->push_back(FileDescriptorInfo(kCrashDumpSignal
,
2637 FileDescriptor(crash_signal_fd
,
2640 #endif // defined(OS_ANDROID)
2642 #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
2645 const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2646 return chrome::kBrowserResourcesDll
;
2649 void ChromeContentBrowserClient::PreSpawnRenderer(
2650 sandbox::TargetPolicy
* policy
,
2652 // This code is duplicated in nacl_exe_win_64.cc.
2653 // Allow the server side of a pipe restricted to the "chrome.nacl."
2654 // namespace so that it cannot impersonate other system or other chrome
2656 sandbox::ResultCode result
= policy
->AddRule(
2657 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES
,
2658 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY
,
2659 L
"\\\\.\\pipe\\chrome.nacl.*");
2660 if (result
!= sandbox::SBOX_ALL_OK
) {
2665 // Renderers need to send named pipe handles and shared memory
2666 // segment handles to NaCl loader processes.
2667 result
= policy
->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES
,
2668 sandbox::TargetPolicy::HANDLES_DUP_ANY
,
2670 if (result
!= sandbox::SBOX_ALL_OK
) {
2677 bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2678 content::BrowserContext
* browser_context
,
2680 #if defined(ENABLE_PLUGINS)
2681 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
2682 const extensions::ExtensionSet
* extension_set
= NULL
;
2684 extension_set
= extensions::ExtensionSystem::Get(profile
)->
2685 extension_service()->extensions();
2687 // TODO(teravest): Populate allowed_file_handle_origins_ when FileIO is moved
2688 // from the renderer to the browser.
2689 return IsExtensionOrSharedModuleWhitelisted(url
, extension_set
,
2690 allowed_file_handle_origins_
) ||
2691 IsHostAllowedByCommandLine(url
, extension_set
,
2692 switches::kAllowNaClFileHandleAPI
);
2698 bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs() {
2699 #if defined(ENABLE_PLUGINS)
2700 // Allow access for tests.
2701 if (CommandLine::ForCurrentProcess()->HasSwitch(
2702 switches::kEnablePepperTesting
)) {
2706 chrome::VersionInfo::Channel channel
= chrome::VersionInfo::GetChannel();
2707 // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown"
2708 // releases of Chrome. Permitting "Unknown" allows these APIs to be used on
2709 // Chromium builds as well.
2710 return channel
<= chrome::VersionInfo::CHANNEL_DEV
;
2717 } // namespace chrome