1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chrome_content_browser_client.h"
11 #include "base/bind.h"
12 #include "base/command_line.h"
13 #include "base/lazy_instance.h"
14 #include "base/path_service.h"
15 #include "base/prefs/pref_service.h"
16 #include "base/prefs/scoped_user_pref_update.h"
17 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/utf_string_conversions.h"
19 #include "base/threading/sequenced_worker_pool.h"
20 #include "chrome/browser/app_mode/app_mode_utils.h"
21 #include "chrome/browser/browser_about_handler.h"
22 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/browser_shutdown.h"
24 #include "chrome/browser/browsing_data/browsing_data_helper.h"
25 #include "chrome/browser/browsing_data/browsing_data_remover.h"
26 #include "chrome/browser/character_encoding.h"
27 #include "chrome/browser/chrome_net_benchmarking_message_filter.h"
28 #include "chrome/browser/chrome_quota_permission_context.h"
29 #include "chrome/browser/content_settings/content_settings_utils.h"
30 #include "chrome/browser/content_settings/cookie_settings.h"
31 #include "chrome/browser/content_settings/host_content_settings_map.h"
32 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
33 #include "chrome/browser/defaults.h"
34 #include "chrome/browser/download/download_prefs.h"
35 #include "chrome/browser/extensions/api/web_request/web_request_api.h"
36 #include "chrome/browser/extensions/browser_permissions_policy_delegate.h"
37 #include "chrome/browser/extensions/extension_service.h"
38 #include "chrome/browser/extensions/extension_util.h"
39 #include "chrome/browser/extensions/extension_web_ui.h"
40 #include "chrome/browser/extensions/extension_webkit_preferences.h"
41 #include "chrome/browser/extensions/suggest_permission_util.h"
42 #include "chrome/browser/geolocation/chrome_access_token_store.h"
43 #include "chrome/browser/google/google_util.h"
44 #include "chrome/browser/guest_view/ad_view/ad_view_guest.h"
45 #include "chrome/browser/guest_view/guest_view_base.h"
46 #include "chrome/browser/guest_view/guest_view_constants.h"
47 #include "chrome/browser/guest_view/guest_view_manager.h"
48 #include "chrome/browser/guest_view/web_view/web_view_guest.h"
49 #include "chrome/browser/media/cast_transport_host_filter.h"
50 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
51 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
52 #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
53 #include "chrome/browser/net/chrome_net_log.h"
54 #include "chrome/browser/notifications/desktop_notification_service.h"
55 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
56 #include "chrome/browser/platform_util.h"
57 #include "chrome/browser/plugins/plugin_info_message_filter.h"
58 #include "chrome/browser/prerender/prerender_final_status.h"
59 #include "chrome/browser/prerender/prerender_manager.h"
60 #include "chrome/browser/prerender/prerender_manager_factory.h"
61 #include "chrome/browser/prerender/prerender_message_filter.h"
62 #include "chrome/browser/prerender/prerender_tracker.h"
63 #include "chrome/browser/printing/printing_message_filter.h"
64 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
65 #include "chrome/browser/profiles/profile.h"
66 #include "chrome/browser/profiles/profile_io_data.h"
67 #include "chrome/browser/profiles/profile_manager.h"
68 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
69 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
70 #include "chrome/browser/search/instant_service.h"
71 #include "chrome/browser/search/instant_service_factory.h"
72 #include "chrome/browser/search/search.h"
73 #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
74 #include "chrome/browser/signin/principals_message_filter.h"
75 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
76 #include "chrome/browser/speech/tts_message_filter.h"
77 #include "chrome/browser/ssl/ssl_add_certificate.h"
78 #include "chrome/browser/ssl/ssl_blocking_page.h"
79 #include "chrome/browser/ssl/ssl_tab_helper.h"
80 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
81 #include "chrome/browser/tab_contents/tab_util.h"
82 #include "chrome/browser/ui/blocked_content/blocked_window_params.h"
83 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
84 #include "chrome/browser/ui/chrome_select_file_policy.h"
85 #include "chrome/browser/ui/sync/sync_promo_ui.h"
86 #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
87 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
88 #include "chrome/common/chrome_constants.h"
89 #include "chrome/common/chrome_paths.h"
90 #include "chrome/common/chrome_switches.h"
91 #include "chrome/common/env_vars.h"
92 #include "chrome/common/extensions/extension_process_policy.h"
93 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
94 #include "chrome/common/logging_chrome.h"
95 #include "chrome/common/pepper_permission_util.h"
96 #include "chrome/common/pref_names.h"
97 #include "chrome/common/render_messages.h"
98 #include "chrome/common/url_constants.h"
99 #include "chrome/installer/util/google_update_settings.h"
100 #include "chromeos/chromeos_constants.h"
101 #include "components/cloud_devices/common/cloud_devices_switches.h"
102 #include "components/nacl/browser/nacl_browser.h"
103 #include "components/nacl/browser/nacl_host_message_filter.h"
104 #include "components/nacl/browser/nacl_process_host.h"
105 #include "components/nacl/common/nacl_process_type.h"
106 #include "components/nacl/common/nacl_switches.h"
107 #include "components/signin/core/common/profile_management_switches.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/common/child_process_host.h"
124 #include "content/public/common/content_descriptors.h"
125 #include "content/public/common/url_utils.h"
126 #include "extensions/browser/extension_host.h"
127 #include "extensions/browser/extension_message_filter.h"
128 #include "extensions/browser/extension_registry.h"
129 #include "extensions/browser/extension_system.h"
130 #include "extensions/browser/info_map.h"
131 #include "extensions/browser/process_manager.h"
132 #include "extensions/browser/process_map.h"
133 #include "extensions/browser/view_type_utils.h"
134 #include "extensions/common/constants.h"
135 #include "extensions/common/extension.h"
136 #include "extensions/common/extension_set.h"
137 #include "extensions/common/manifest_handlers/background_info.h"
138 #include "extensions/common/manifest_handlers/shared_module_info.h"
139 #include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
140 #include "extensions/common/permissions/permissions_data.h"
141 #include "extensions/common/permissions/socket_permission.h"
142 #include "extensions/common/switches.h"
143 #include "grit/generated_resources.h"
144 #include "grit/ui_resources.h"
145 #include "net/base/mime_util.h"
146 #include "net/cookies/canonical_cookie.h"
147 #include "net/cookies/cookie_options.h"
148 #include "net/ssl/ssl_cert_request_info.h"
149 #include "ppapi/host/ppapi_host.h"
150 #include "ppapi/shared_impl/ppapi_switches.h"
151 #include "ui/base/l10n/l10n_util.h"
152 #include "ui/base/resource/resource_bundle.h"
153 #include "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/file_system_provider/fileapi/backend_delegate.h"
168 #include "chrome/browser/chromeos/fileapi/file_system_backend.h"
169 #include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
170 #include "chrome/browser/chromeos/login/startup_utils.h"
171 #include "chrome/browser/chromeos/login/user_manager.h"
172 #include "chrome/browser/chromeos/system/input_device_settings.h"
173 #include "chromeos/chromeos_switches.h"
174 #elif defined(OS_LINUX)
175 #include "chrome/browser/chrome_browser_main_linux.h"
176 #elif defined(OS_ANDROID)
177 #include "chrome/browser/android/new_tab_page_url_handler.h"
178 #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
179 #include "chrome/browser/chrome_browser_main_android.h"
180 #include "chrome/browser/media/encrypted_media_message_filter_android.h"
181 #include "chrome/common/descriptors_android.h"
182 #include "components/breakpad/browser/crash_dump_manager_android.h"
183 #elif defined(OS_POSIX)
184 #include "chrome/browser/chrome_browser_main_posix.h"
187 #if defined(OS_POSIX) && !defined(OS_MACOSX)
188 #include "base/debug/leak_annotations.h"
189 #include "base/linux_util.h"
190 #include "components/breakpad/app/breakpad_linux.h"
191 #include "components/breakpad/browser/crash_handler_host_linux.h"
194 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
195 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
198 #if defined(OS_ANDROID)
199 #include "ui/base/ui_base_paths.h"
200 #include "ui/gfx/android/device_display_info.h"
203 #if !defined(OS_CHROMEOS)
204 #include "chrome/browser/signin/chrome_signin_client.h"
205 #include "chrome/browser/signin/chrome_signin_client_factory.h"
206 #include "chrome/browser/signin/signin_manager_factory.h"
207 #include "components/signin/core/browser/signin_manager.h"
210 #if !defined(OS_ANDROID)
211 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
214 #if defined(ENABLE_WEBRTC)
215 #include "chrome/browser/media/webrtc_logging_handler_host.h"
218 #if defined(OS_CHROMEOS)
219 #include "chrome/browser/chromeos/file_manager/app_id.h"
222 #if defined(TOOLKIT_VIEWS)
223 #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
227 #include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
230 #if defined(USE_AURA)
231 #include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
235 #include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
238 #if defined(ENABLE_SPELLCHECK)
239 #include "chrome/browser/spellchecker/spellcheck_message_filter.h"
242 #if defined(ENABLE_SERVICE_DISCOVERY)
243 #include "chrome/browser/local_discovery/storage/privet_filesystem_backend.h"
246 using blink::WebWindowFeatures
;
247 using base::FileDescriptor
;
248 using content::AccessTokenStore
;
249 using content::BrowserChildProcessHostIterator
;
250 using content::BrowserThread
;
251 using content::BrowserURLHandler
;
252 using content::ChildProcessSecurityPolicy
;
253 using content::QuotaPermissionContext
;
254 using content::RenderFrameHost
;
255 using content::RenderViewHost
;
256 using content::SiteInstance
;
257 using content::WebContents
;
258 using extensions::APIPermission
;
259 using extensions::Extension
;
260 using extensions::InfoMap
;
261 using extensions::Manifest
;
262 using message_center::NotifierId
;
264 #if defined(OS_POSIX)
265 using content::FileDescriptorInfo
;
270 // Cached version of the locale so we can return the locale on the I/O
272 base::LazyInstance
<std::string
> g_io_thread_application_locale
;
274 #if defined(ENABLE_PLUGINS)
275 const char* kPredefinedAllowedFileHandleOrigins
[] = {
276 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
277 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
280 const char* kPredefinedAllowedSocketOrigins
[] = {
281 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
282 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
283 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
284 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
285 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
286 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
287 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
288 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
289 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
290 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
291 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
292 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
293 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
294 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
295 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
296 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
297 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
298 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
299 "4EB74897CB187C7633357C2FE832E0AD6A44883A", // see crbug.com/234789
300 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
301 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
302 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
306 // Returns a copy of the given url with its host set to given host and path set
307 // to given path. Other parts of the url will be the same.
308 GURL
ReplaceURLHostAndPath(const GURL
& url
,
309 const std::string
& host
,
310 const std::string
& path
) {
311 url::Replacements
<char> replacements
;
312 replacements
.SetHost(host
.c_str(), url::Component(0, host
.length()));
313 replacements
.SetPath(path
.c_str(), url::Component(0, path
.length()));
314 return url
.ReplaceComponents(replacements
);
317 // Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
318 GURL
AddUberHost(const GURL
& url
) {
319 const std::string uber_host
= chrome::kChromeUIUberHost
;
320 const std::string new_path
= url
.host() + url
.path();
322 return ReplaceURLHostAndPath(url
, uber_host
, new_path
);
325 // If url->host() is "chrome" and url->path() has characters other than the
326 // first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
327 // returns true. Otherwise returns false.
328 bool RemoveUberHost(GURL
* url
) {
329 if (url
->host() != chrome::kChromeUIUberHost
)
332 if (url
->path().empty() || url
->path() == "/")
335 const std::string old_path
= url
->path();
337 const std::string::size_type separator
= old_path
.find('/', 1);
338 std::string new_host
;
339 std::string new_path
;
340 if (separator
== std::string::npos
) {
341 new_host
= old_path
.substr(1);
343 new_host
= old_path
.substr(1, separator
- 1);
344 new_path
= old_path
.substr(separator
);
347 // Do not allow URLs with paths empty before the first slash since we can't
348 // have an empty host. (e.g "foo://chrome//")
349 if (new_host
.empty())
352 *url
= ReplaceURLHostAndPath(*url
, new_host
, new_path
);
354 DCHECK(url
->is_valid());
359 // Handles rewriting Web UI URLs.
360 bool HandleWebUI(GURL
* url
, content::BrowserContext
* browser_context
) {
361 // Do not handle special URLs such as "about:foo"
362 if (!url
->host().empty()) {
363 const GURL chrome_url
= AddUberHost(*url
);
365 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
367 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
368 browser_context
, chrome_url
))
372 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
373 browser_context
, *url
))
376 #if defined(OS_CHROMEOS)
377 // Special case : in ChromeOS in Guest mode bookmarks and history are
378 // disabled for security reasons. New tab page explains the reasons, so
379 // we redirect user to new tab page.
380 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
381 if (url
->SchemeIs(content::kChromeUIScheme
) &&
382 (url
->DomainIs(chrome::kChromeUIBookmarksHost
) ||
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
);
662 void ChromeContentBrowserClient::SetApplicationLocale(
663 const std::string
& locale
) {
664 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
666 // This object is guaranteed to outlive all threads so we don't have to
667 // worry about the lack of refcounting and can just post as Unretained.
669 // The common case is that this function is called early in Chrome startup
670 // before any threads are created (it will also be called later if the user
671 // changes the pref). In this case, there will be no threads created and
672 // posting will fail. When there are no threads, we can just set the string
673 // without worrying about threadsafety.
674 if (!BrowserThread::PostTask(BrowserThread::IO
, FROM_HERE
,
675 base::Bind(&SetApplicationLocaleOnIOThread
, locale
))) {
676 g_io_thread_application_locale
.Get() = locale
;
680 content::BrowserMainParts
* ChromeContentBrowserClient::CreateBrowserMainParts(
681 const content::MainFunctionParams
& parameters
) {
682 ChromeBrowserMainParts
* main_parts
;
683 // Construct the Main browser parts based on the OS type.
685 main_parts
= new ChromeBrowserMainPartsWin(parameters
);
686 #elif defined(OS_MACOSX)
687 main_parts
= new ChromeBrowserMainPartsMac(parameters
);
688 #elif defined(OS_CHROMEOS)
689 main_parts
= new chromeos::ChromeBrowserMainPartsChromeos(parameters
);
690 #elif defined(OS_LINUX)
691 main_parts
= new ChromeBrowserMainPartsLinux(parameters
);
692 #elif defined(OS_ANDROID)
693 main_parts
= new ChromeBrowserMainPartsAndroid(parameters
);
694 #elif defined(OS_POSIX)
695 main_parts
= new ChromeBrowserMainPartsPosix(parameters
);
698 main_parts
= new ChromeBrowserMainParts(parameters
);
701 chrome::AddProfilesExtraParts(main_parts
);
703 // Construct additional browser parts. Stages are called in the order in
704 // which they are added.
705 #if defined(TOOLKIT_VIEWS)
706 main_parts
->AddParts(new ChromeBrowserMainExtraPartsViews());
710 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAsh());
713 #if defined(USE_AURA)
714 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAura());
718 main_parts
->AddParts(new ChromeBrowserMainExtraPartsX11());
721 chrome::AddMetricsExtraParts(main_parts
);
726 std::string
ChromeContentBrowserClient::GetStoragePartitionIdForSite(
727 content::BrowserContext
* browser_context
,
729 std::string partition_id
;
731 // The partition ID for webview guest processes is the string value of its
732 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
733 if (site
.SchemeIs(content::kGuestScheme
)) {
734 partition_id
= site
.spec();
735 } else if (site
.GetOrigin().spec() == kChromeUIChromeSigninURL
) {
736 // Chrome signin page has an embedded iframe of extension and web content,
737 // thus it must be isolated from other webUI pages.
738 partition_id
= site
.GetOrigin().spec();
741 DCHECK(IsValidStoragePartitionId(browser_context
, partition_id
));
745 bool ChromeContentBrowserClient::IsValidStoragePartitionId(
746 content::BrowserContext
* browser_context
,
747 const std::string
& partition_id
) {
748 // The default ID is empty and is always valid.
749 if (partition_id
.empty())
752 return GURL(partition_id
).is_valid();
755 void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
756 content::BrowserContext
* browser_context
,
759 std::string
* partition_domain
,
760 std::string
* partition_name
,
762 // Default to the browser-wide storage partition and override based on |site|
764 partition_domain
->clear();
765 partition_name
->clear();
768 bool success
= GuestViewBase::GetGuestPartitionConfigForSite(
769 site
, partition_domain
, partition_name
, in_memory
);
771 if (!success
&& site
.SchemeIs(extensions::kExtensionScheme
)) {
772 // If |can_be_default| is false, the caller is stating that the |site|
773 // should be parsed as if it had isolated storage. In particular it is
774 // important to NOT check ExtensionService for the is_storage_isolated()
775 // attribute because this code path is run during Extension uninstall
776 // to do cleanup after the Extension has already been unloaded from the
778 bool is_isolated
= !can_be_default
;
779 if (can_be_default
) {
780 if (extensions::util::SiteHasIsolatedStorage(site
, browser_context
))
785 CHECK(site
.has_host());
786 // For extensions with isolated storage, the the host of the |site| is
787 // the |partition_domain|. The |in_memory| and |partition_name| are only
788 // used in guest schemes so they are cleared here.
789 *partition_domain
= site
.host();
791 partition_name
->clear();
793 } else if (site
.GetOrigin().spec() == kChromeUIChromeSigninURL
) {
794 // Chrome signin page has an embedded iframe of extension and web content,
795 // thus it must be isolated from other webUI pages.
796 *partition_domain
= chrome::kChromeUIChromeSigninHost
;
799 // Assert that if |can_be_default| is false, the code above must have found a
800 // non-default partition. If this fails, the caller has a serious logic
801 // error about which StoragePartition they expect to be in and it is not
803 CHECK(can_be_default
|| !partition_domain
->empty());
806 content::WebContentsViewDelegate
*
807 ChromeContentBrowserClient::GetWebContentsViewDelegate(
808 content::WebContents
* web_contents
) {
809 return chrome::CreateWebContentsViewDelegate(web_contents
);
812 void ChromeContentBrowserClient::GuestWebContentsCreated(
813 SiteInstance
* guest_site_instance
,
814 WebContents
* guest_web_contents
,
815 WebContents
* opener_web_contents
,
816 content::BrowserPluginGuestDelegate
** guest_delegate
,
817 scoped_ptr
<base::DictionaryValue
> extra_params
) {
818 if (!guest_site_instance
) {
822 GURL guest_site_url
= guest_site_instance
->GetSiteURL();
823 const std::string
& extension_id
= guest_site_url
.host();
825 Profile
* profile
= Profile::FromBrowserContext(
826 guest_web_contents
->GetBrowserContext());
827 ExtensionService
* service
=
828 extensions::ExtensionSystem::Get(profile
)->extension_service();
834 /// TODO(fsamuel): In the future, certain types of GuestViewBases won't
835 // require extension bindings. At that point, we should clear |extension_id|
836 // instead of exiting early.
837 if (!extension_id
.empty() &&
838 !service
->GetExtensionById(extension_id
, false)) {
843 if (opener_web_contents
) {
844 GuestViewBase
* guest
= GuestViewBase::FromWebContents(opener_web_contents
);
850 // Create a new GuestViewBase of the same type as the opener.
851 *guest_delegate
= GuestViewBase::Create(
854 guest
->GetViewType(),
863 std::string api_type
;
864 extra_params
->GetString(guestview::kParameterApi
, &api_type
);
866 if (api_type
.empty())
870 GuestViewBase::Create(guest_web_contents
,
873 base::WeakPtr
<GuestViewBase
>());
876 void ChromeContentBrowserClient::GuestWebContentsAttached(
877 WebContents
* guest_web_contents
,
878 WebContents
* embedder_web_contents
,
879 const base::DictionaryValue
& extra_params
) {
880 GuestViewBase
* guest
= GuestViewBase::FromWebContents(guest_web_contents
);
882 // It's ok to return here, since we could be running a browser plugin
883 // outside an extension, and don't need to attach a
884 // BrowserPluginGuestDelegate in that case;
885 // e.g. running with flag --enable-browser-plugin-for-all-view-types.
888 guest
->Attach(embedder_web_contents
, extra_params
);
891 void ChromeContentBrowserClient::RenderProcessWillLaunch(
892 content::RenderProcessHost
* host
) {
893 int id
= host
->GetID();
894 Profile
* profile
= Profile::FromBrowserContext(host
->GetBrowserContext());
895 net::URLRequestContextGetter
* context
=
896 profile
->GetRequestContextForRenderProcess(id
);
898 host
->AddFilter(new ChromeRenderMessageFilter(id
, profile
, context
));
899 host
->AddFilter(new extensions::ExtensionMessageFilter(id
, profile
));
900 #if defined(ENABLE_PLUGINS)
901 host
->AddFilter(new PluginInfoMessageFilter(id
, profile
));
903 host
->AddFilter(new cast::CastTransportHostFilter
);
904 #if defined(ENABLE_PRINTING)
905 host
->AddFilter(new PrintingMessageFilter(id
, profile
));
907 host
->AddFilter(new SearchProviderInstallStateMessageFilter(id
, profile
));
908 #if defined(ENABLE_SPELLCHECK)
909 host
->AddFilter(new SpellCheckMessageFilter(id
));
911 #if defined(OS_MACOSX)
912 host
->AddFilter(new SpellCheckMessageFilterMac(id
));
914 host
->AddFilter(new ChromeNetBenchmarkingMessageFilter(profile
, context
));
915 host
->AddFilter(new prerender::PrerenderMessageFilter(id
, profile
));
916 host
->AddFilter(new TtsMessageFilter(id
, profile
));
917 #if defined(ENABLE_WEBRTC)
918 WebRtcLoggingHandlerHost
* webrtc_logging_handler_host
=
919 new WebRtcLoggingHandlerHost(profile
);
920 host
->SetWebRtcLogMessageCallback(base::Bind(
921 &WebRtcLoggingHandlerHost::LogMessage
, webrtc_logging_handler_host
));
922 host
->AddFilter(webrtc_logging_handler_host
);
923 host
->SetUserData(host
, new base::UserDataAdapter
<WebRtcLoggingHandlerHost
>(
924 webrtc_logging_handler_host
));
926 #if !defined(DISABLE_NACL)
927 host
->AddFilter(new nacl::NaClHostMessageFilter(
928 id
, profile
->IsOffTheRecord(),
932 #if defined(OS_ANDROID)
933 host
->AddFilter(new EncryptedMediaMessageFilterAndroid());
935 if (switches::IsNewProfileManagement())
936 host
->AddFilter(new PrincipalsMessageFilter(id
));
938 host
->Send(new ChromeViewMsg_SetIsIncognitoProcess(
939 profile
->IsOffTheRecord()));
941 SendExtensionWebRequestStatusToHost(host
);
943 RendererContentSettingRules rules
;
944 if (host
->IsGuest()) {
945 GuestViewBase::GetDefaultContentSettingRules(&rules
,
946 profile
->IsOffTheRecord());
948 GetRendererContentSettingRules(
949 profile
->GetHostContentSettingsMap(), &rules
);
951 host
->Send(new ChromeViewMsg_SetContentSettingRules(rules
));
954 GURL
ChromeContentBrowserClient::GetEffectiveURL(
955 content::BrowserContext
* browser_context
, const GURL
& url
) {
956 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
960 // If the input |url| should be assigned to the Instant renderer, make its
961 // effective URL distinct from other URLs on the search provider's domain.
962 if (chrome::ShouldAssignURLToInstantRenderer(url
, profile
))
963 return chrome::GetEffectiveURLForInstant(url
, profile
);
965 #if !defined(OS_CHROMEOS)
966 // If the input |url| should be assigned to the Signin renderer, make its
967 // effective URL distinct from other URLs on the signin service's domain.
968 // Note that the signin renderer will be allowed to sign the user in to
970 if (SigninManager::IsWebBasedSigninFlowURL(url
))
971 return GetEffectiveURLForSignin(url
);
974 // If the input |url| is part of an installed app, the effective URL is an
975 // extension URL with the ID of that extension as the host. This has the
976 // effect of grouping apps together in a common SiteInstance.
977 ExtensionService
* extension_service
=
978 extensions::ExtensionSystem::Get(profile
)->extension_service();
979 if (!extension_service
)
982 const Extension
* extension
= extension_service
->extensions()->
983 GetHostedAppByURL(url
);
987 // Bookmark apps do not use the hosted app process model, and should be
988 // treated as normal URLs.
989 if (extension
->from_bookmark())
992 // If the URL is part of an extension's web extent, convert it to an
994 return extension
->GetResourceURL(url
.path());
997 bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
998 content::BrowserContext
* browser_context
, const GURL
& effective_url
) {
999 // Non-extension, non-Instant URLs should generally use
1000 // process-per-site-instance. Because we expect to use the effective URL,
1001 // URLs for hosted apps (apart from bookmark apps) should have an extension
1004 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1008 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url
, profile
))
1011 #if !defined(OS_CHROMEOS)
1012 if (SigninManager::IsWebBasedSigninFlowURL(effective_url
))
1016 if (!effective_url
.SchemeIs(extensions::kExtensionScheme
))
1019 ExtensionService
* extension_service
=
1020 extensions::ExtensionSystem::Get(profile
)->extension_service();
1021 if (!extension_service
)
1024 const Extension
* extension
=
1025 extension_service
->extensions()->GetExtensionOrAppByURL(effective_url
);
1029 // If the URL is part of a hosted app that does not have the background
1030 // permission, or that does not allow JavaScript access to the background
1031 // page, we want to give each instance its own process to improve
1033 if (extension
->GetType() == Manifest::TYPE_HOSTED_APP
) {
1034 if (!extension
->HasAPIPermission(APIPermission::kBackground
) ||
1035 !extensions::BackgroundInfo::AllowJSAccess(extension
)) {
1040 // Hosted apps that have script access to their background page must use
1041 // process per site, since all instances can make synchronous calls to the
1042 // background window. Other extensions should use process per site as well.
1046 // These are treated as WebUI schemes but do not get WebUI bindings. Also,
1047 // view-source is allowed for these schemes.
1048 void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1049 std::vector
<std::string
>* additional_schemes
) {
1050 additional_schemes
->push_back(chrome::kChromeSearchScheme
);
1051 additional_schemes
->push_back(chrome::kDomDistillerScheme
);
1054 void ChromeContentBrowserClient::GetAdditionalWebUIHostsToIgnoreParititionCheck(
1055 std::vector
<std::string
>* hosts
) {
1056 hosts
->push_back(chrome::kChromeUIExtensionIconHost
);
1057 hosts
->push_back(chrome::kChromeUIFaviconHost
);
1058 hosts
->push_back(chrome::kChromeUIThemeHost
);
1059 hosts
->push_back(chrome::kChromeUIThumbnailHost
);
1060 hosts
->push_back(chrome::kChromeUIThumbnailHost2
);
1061 hosts
->push_back(chrome::kChromeUIThumbnailListHost
);
1064 net::URLRequestContextGetter
*
1065 ChromeContentBrowserClient::CreateRequestContext(
1066 content::BrowserContext
* browser_context
,
1067 content::ProtocolHandlerMap
* protocol_handlers
,
1068 content::ProtocolHandlerScopedVector protocol_interceptors
) {
1069 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1070 return profile
->CreateRequestContext(protocol_handlers
,
1071 protocol_interceptors
.Pass());
1074 net::URLRequestContextGetter
*
1075 ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
1076 content::BrowserContext
* browser_context
,
1077 const base::FilePath
& partition_path
,
1079 content::ProtocolHandlerMap
* protocol_handlers
,
1080 content::ProtocolHandlerScopedVector protocol_interceptors
) {
1081 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1082 return profile
->CreateRequestContextForStoragePartition(
1086 protocol_interceptors
.Pass());
1089 bool ChromeContentBrowserClient::IsHandledURL(const GURL
& url
) {
1090 return ProfileIOData::IsHandledURL(url
);
1093 bool ChromeContentBrowserClient::CanCommitURL(
1094 content::RenderProcessHost
* process_host
,
1096 // We need to let most extension URLs commit in any process, since this can
1097 // be allowed due to web_accessible_resources. Most hosted app URLs may also
1098 // load in any process (e.g., in an iframe). However, the Chrome Web Store
1099 // cannot be loaded in iframes and should never be requested outside its
1102 Profile::FromBrowserContext(process_host
->GetBrowserContext());
1103 ExtensionService
* service
=
1104 extensions::ExtensionSystem::Get(profile
)->extension_service();
1107 const Extension
* new_extension
=
1108 service
->extensions()->GetExtensionOrAppByURL(url
);
1109 if (new_extension
&&
1110 new_extension
->is_hosted_app() &&
1111 new_extension
->id() == extension_misc::kWebStoreAppId
&&
1112 !extensions::ProcessMap::Get(profile
)->
1113 Contains(new_extension
->id(), process_host
->GetID())) {
1120 bool ChromeContentBrowserClient::ShouldAllowOpenURL(
1121 content::SiteInstance
* site_instance
, const GURL
& url
) {
1122 GURL from_url
= site_instance
->GetSiteURL();
1123 // Do not allow pages from the web or other extensions navigate to
1124 // non-web-accessible extension resources.
1125 if (url
.SchemeIs(extensions::kExtensionScheme
) &&
1126 (from_url
.SchemeIsHTTPOrHTTPS() ||
1127 from_url
.SchemeIs(extensions::kExtensionScheme
))) {
1128 Profile
* profile
= Profile::FromBrowserContext(
1129 site_instance
->GetProcess()->GetBrowserContext());
1130 ExtensionService
* service
=
1131 extensions::ExtensionSystem::Get(profile
)->extension_service();
1134 const Extension
* extension
=
1135 service
->extensions()->GetExtensionOrAppByURL(url
);
1138 const Extension
* from_extension
=
1139 service
->extensions()->GetExtensionOrAppByURL(
1140 site_instance
->GetSiteURL());
1141 if (from_extension
&& from_extension
->id() == extension
->id())
1144 if (!extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible(
1145 extension
, url
.path()))
1149 // Do not allow chrome://chrome-signin navigate to other chrome:// URLs, since
1150 // the signin page may host untrusted web content.
1151 if (from_url
.GetOrigin().spec() == chrome::kChromeUIChromeSigninURL
&&
1152 url
.SchemeIs(content::kChromeUIScheme
) &&
1153 url
.host() != chrome::kChromeUIChromeSigninHost
) {
1154 VLOG(1) << "Blocked navigation to " << url
.spec() << " from "
1155 << chrome::kChromeUIChromeSigninURL
;
1162 bool ChromeContentBrowserClient::IsSuitableHost(
1163 content::RenderProcessHost
* process_host
,
1164 const GURL
& site_url
) {
1166 Profile::FromBrowserContext(process_host
->GetBrowserContext());
1167 // This may be NULL during tests. In that case, just assume any site can
1172 // Instant URLs should only be in the instant process and instant process
1173 // should only have Instant URLs.
1174 InstantService
* instant_service
=
1175 InstantServiceFactory::GetForProfile(profile
);
1176 if (instant_service
) {
1177 bool is_instant_process
= instant_service
->IsInstantProcess(
1178 process_host
->GetID());
1179 bool should_be_in_instant_process
=
1180 chrome::ShouldAssignURLToInstantRenderer(site_url
, profile
);
1181 if (is_instant_process
|| should_be_in_instant_process
)
1182 return is_instant_process
&& should_be_in_instant_process
;
1185 #if !defined(OS_CHROMEOS)
1186 ChromeSigninClient
* signin_client
=
1187 ChromeSigninClientFactory::GetForProfile(profile
);
1188 if (signin_client
&& signin_client
->IsSigninProcess(process_host
->GetID()))
1189 return SigninManager::IsWebBasedSigninFlowURL(site_url
);
1192 ExtensionService
* service
=
1193 extensions::ExtensionSystem::Get(profile
)->extension_service();
1194 extensions::ProcessMap
* process_map
= extensions::ProcessMap::Get(profile
);
1196 // Don't allow the Task Manager to share a process with anything else.
1197 // Otherwise it can affect the renderers it is observing.
1198 // Note: we could create another RenderProcessHostPrivilege bucket for
1199 // this to allow multiple chrome://tasks instances to share, but that's
1200 // a very unlikely case without serious consequences.
1201 if (site_url
.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL
).GetOrigin())
1204 // These may be NULL during tests. In that case, just assume any site can
1206 if (!service
|| !process_map
)
1209 // Otherwise, just make sure the process privilege matches the privilege
1210 // required by the site.
1211 RenderProcessHostPrivilege privilege_required
=
1212 GetPrivilegeRequiredByUrl(site_url
, service
);
1213 return GetProcessPrivilege(process_host
, process_map
, service
) ==
1217 // This function is trying to limit the amount of processes used by extensions
1218 // with background pages. It uses a globally set percentage of processes to
1219 // run such extensions and if the limit is exceeded, it returns true, to
1220 // indicate to the content module to group extensions together.
1221 bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1222 content::BrowserContext
* browser_context
, const GURL
& url
) {
1223 // It has to be a valid URL for us to check for an extension.
1224 if (!url
.is_valid())
1227 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1228 ExtensionService
* service
= !profile
? NULL
:
1229 extensions::ExtensionSystem::Get(profile
)->extension_service();
1233 // We have to have a valid extension with background page to proceed.
1234 const Extension
* extension
=
1235 service
->extensions()->GetExtensionOrAppByURL(url
);
1238 if (!extensions::BackgroundInfo::HasBackgroundPage(extension
))
1241 std::set
<int> process_ids
;
1242 size_t max_process_count
=
1243 content::RenderProcessHost::GetMaxRendererProcessCount();
1245 // Go through all profiles to ensure we have total count of extension
1246 // processes containing background pages, otherwise one profile can
1247 // starve the other.
1248 std::vector
<Profile
*> profiles
= g_browser_process
->profile_manager()->
1249 GetLoadedProfiles();
1250 for (size_t i
= 0; i
< profiles
.size(); ++i
) {
1251 extensions::ProcessManager
* epm
=
1252 extensions::ExtensionSystem::Get(profiles
[i
])->process_manager();
1253 for (extensions::ProcessManager::const_iterator iter
=
1254 epm
->background_hosts().begin();
1255 iter
!= epm
->background_hosts().end(); ++iter
) {
1256 const extensions::ExtensionHost
* host
= *iter
;
1257 process_ids
.insert(host
->render_process_host()->GetID());
1261 if (process_ids
.size() >
1262 (max_process_count
* chrome::kMaxShareOfExtensionProcesses
)) {
1269 void ChromeContentBrowserClient::SiteInstanceGotProcess(
1270 SiteInstance
* site_instance
) {
1271 CHECK(site_instance
->HasProcess());
1273 Profile
* profile
= Profile::FromBrowserContext(
1274 site_instance
->GetBrowserContext());
1278 // Remember the ID of the Instant process to signal the renderer process
1279 // on startup in |AppendExtraCommandLineSwitches| below.
1280 if (chrome::ShouldAssignURLToInstantRenderer(
1281 site_instance
->GetSiteURL(), profile
)) {
1282 InstantService
* instant_service
=
1283 InstantServiceFactory::GetForProfile(profile
);
1284 if (instant_service
)
1285 instant_service
->AddInstantProcess(site_instance
->GetProcess()->GetID());
1288 #if !defined(OS_CHROMEOS)
1289 // We only expect there to be one signin process as we use process-per-site
1290 // for signin URLs. The signin process will be cleared from SigninManager
1291 // when the renderer is destroyed.
1292 if (SigninManager::IsWebBasedSigninFlowURL(site_instance
->GetSiteURL())) {
1293 ChromeSigninClient
* signin_client
=
1294 ChromeSigninClientFactory::GetForProfile(profile
);
1296 signin_client
->SetSigninProcess(site_instance
->GetProcess()->GetID());
1297 BrowserThread::PostTask(
1300 base::Bind(&InfoMap::SetSigninProcess
,
1301 extensions::ExtensionSystem::Get(profile
)->info_map(),
1302 site_instance
->GetProcess()->GetID()));
1306 ExtensionService
* service
=
1307 extensions::ExtensionSystem::Get(profile
)->extension_service();
1311 const Extension
* extension
= service
->extensions()->GetExtensionOrAppByURL(
1312 site_instance
->GetSiteURL());
1316 extensions::ProcessMap::Get(profile
)
1317 ->Insert(extension
->id(),
1318 site_instance
->GetProcess()->GetID(),
1319 site_instance
->GetId());
1321 BrowserThread::PostTask(
1324 base::Bind(&InfoMap::RegisterExtensionProcess
,
1325 extensions::ExtensionSystem::Get(profile
)->info_map(),
1327 site_instance
->GetProcess()->GetID(),
1328 site_instance
->GetId()));
1331 void ChromeContentBrowserClient::SiteInstanceDeleting(
1332 SiteInstance
* site_instance
) {
1333 if (!site_instance
->HasProcess())
1336 Profile
* profile
= Profile::FromBrowserContext(
1337 site_instance
->GetBrowserContext());
1338 ExtensionService
* service
=
1339 extensions::ExtensionSystem::Get(profile
)->extension_service();
1343 const Extension
* extension
= service
->extensions()->GetExtensionOrAppByURL(
1344 site_instance
->GetSiteURL());
1348 extensions::ProcessMap::Get(profile
)
1349 ->Remove(extension
->id(),
1350 site_instance
->GetProcess()->GetID(),
1351 site_instance
->GetId());
1353 BrowserThread::PostTask(
1356 base::Bind(&InfoMap::UnregisterExtensionProcess
,
1357 extensions::ExtensionSystem::Get(profile
)->info_map(),
1359 site_instance
->GetProcess()->GetID(),
1360 site_instance
->GetId()));
1363 void ChromeContentBrowserClient::WorkerProcessCreated(
1364 SiteInstance
* site_instance
,
1365 int worker_process_id
) {
1366 extensions::ExtensionRegistry
* extension_registry
=
1367 extensions::ExtensionRegistry::Get(site_instance
->GetBrowserContext());
1368 if (!extension_registry
)
1370 const Extension
* extension
=
1371 extension_registry
->enabled_extensions().GetExtensionOrAppByURL(
1372 site_instance
->GetSiteURL());
1375 extensions::ExtensionSystem
* extension_system
=
1376 extensions::ExtensionSystem::Get(site_instance
->GetBrowserContext());
1377 extension_system
->info_map()->RegisterExtensionWorkerProcess(
1380 site_instance
->GetId());
1383 void ChromeContentBrowserClient::WorkerProcessTerminated(
1384 SiteInstance
* site_instance
,
1385 int worker_process_id
) {
1386 extensions::ExtensionSystem
* extension_system
=
1387 extensions::ExtensionSystem::Get(site_instance
->GetBrowserContext());
1388 extension_system
->info_map()->UnregisterExtensionWorkerProcess(
1392 bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
1393 SiteInstance
* site_instance
,
1394 const GURL
& current_url
,
1395 const GURL
& new_url
) {
1396 // If we don't have an ExtensionService, then rely on the SiteInstance logic
1397 // in RenderFrameHostManager to decide when to swap.
1399 Profile::FromBrowserContext(site_instance
->GetBrowserContext());
1400 ExtensionService
* service
=
1401 extensions::ExtensionSystem::Get(profile
)->extension_service();
1405 // We must use a new BrowsingInstance (forcing a process swap and disabling
1406 // scripting by existing tabs) if one of the URLs is an extension and the
1407 // other is not the exact same extension.
1409 // We ignore hosted apps here so that other tabs in their BrowsingInstance can
1410 // use postMessage with them. (The exception is the Chrome Web Store, which
1411 // is a hosted app that requires its own BrowsingInstance.) Navigations
1412 // to/from a hosted app will still trigger a SiteInstance swap in
1413 // RenderFrameHostManager.
1414 const Extension
* current_extension
=
1415 service
->extensions()->GetExtensionOrAppByURL(current_url
);
1416 if (current_extension
&&
1417 current_extension
->is_hosted_app() &&
1418 current_extension
->id() != extension_misc::kWebStoreAppId
)
1419 current_extension
= NULL
;
1421 const Extension
* new_extension
=
1422 service
->extensions()->GetExtensionOrAppByURL(new_url
);
1423 if (new_extension
&&
1424 new_extension
->is_hosted_app() &&
1425 new_extension
->id() != extension_misc::kWebStoreAppId
)
1426 new_extension
= NULL
;
1428 // First do a process check. We should force a BrowsingInstance swap if the
1429 // current process doesn't know about new_extension, even if current_extension
1430 // is somehow the same as new_extension.
1431 extensions::ProcessMap
* process_map
= extensions::ProcessMap::Get(profile
);
1432 if (new_extension
&&
1433 site_instance
->HasProcess() &&
1434 !process_map
->Contains(
1435 new_extension
->id(), site_instance
->GetProcess()->GetID()))
1438 // Otherwise, swap BrowsingInstances if current_extension and new_extension
1440 return current_extension
!= new_extension
;
1443 bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1444 content::ResourceContext
* resource_context
, const GURL
& current_url
,
1445 const GURL
& new_url
) {
1446 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(resource_context
);
1447 return extensions::CrossesExtensionProcessBoundary(
1448 io_data
->GetExtensionInfoMap()->extensions(),
1449 current_url
, new_url
, false);
1452 bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL
& url
) {
1453 return !url
.SchemeIs(chrome::kChromeNativeScheme
);
1456 std::string
ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1457 const std::string
& alias_name
) {
1458 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name
);
1461 void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1462 CommandLine
* command_line
, int child_process_id
) {
1463 #if defined(OS_POSIX)
1464 if (breakpad::IsCrashReporterEnabled()) {
1465 std::string enable_crash_reporter
;
1466 GoogleUpdateSettings::GetMetricsId(&enable_crash_reporter
);
1467 #if !defined(OS_MACOSX)
1468 enable_crash_reporter
+= "," + base::GetLinuxDistro();
1470 command_line
->AppendSwitchASCII(switches::kEnableCrashReporter
,
1471 enable_crash_reporter
);
1475 if (logging::DialogsAreSuppressed())
1476 command_line
->AppendSwitch(switches::kNoErrorDialogs
);
1478 std::string process_type
=
1479 command_line
->GetSwitchValueASCII(switches::kProcessType
);
1480 const CommandLine
& browser_command_line
= *CommandLine::ForCurrentProcess();
1482 static const char* const kCommonSwitchNames
[] = {
1483 switches::kUserAgent
,
1484 switches::kUserDataDir
, // Make logs go to the right file.
1486 command_line
->CopySwitchesFrom(browser_command_line
, kCommonSwitchNames
,
1487 arraysize(kCommonSwitchNames
));
1489 #if defined(ENABLE_IPC_FUZZER)
1490 static const char* const kIpcFuzzerSwitches
[] = {
1491 switches::kIpcFuzzerTestcase
,
1493 command_line
->CopySwitchesFrom(browser_command_line
, kIpcFuzzerSwitches
,
1494 arraysize(kIpcFuzzerSwitches
));
1497 if (process_type
== switches::kRendererProcess
) {
1498 #if defined(OS_CHROMEOS)
1499 const std::string
& login_profile
=
1500 browser_command_line
.GetSwitchValueASCII(
1501 chromeos::switches::kLoginProfile
);
1502 if (!login_profile
.empty())
1503 command_line
->AppendSwitchASCII(
1504 chromeos::switches::kLoginProfile
, login_profile
);
1507 #if defined(ENABLE_WEBRTC)
1508 MaybeCopyDisableWebRtcEncryptionSwitch(command_line
,
1509 browser_command_line
,
1510 VersionInfo::GetChannel());
1513 content::RenderProcessHost
* process
=
1514 content::RenderProcessHost::FromID(child_process_id
);
1516 Profile
* profile
= Profile::FromBrowserContext(
1517 process
->GetBrowserContext());
1519 if (extensions::ProcessMap::Get(profile
)->Contains(process
->GetID()))
1520 command_line
->AppendSwitch(extensions::switches::kExtensionProcess
);
1522 PrefService
* prefs
= profile
->GetPrefs();
1523 // Currently this pref is only registered if applied via a policy.
1524 if (prefs
->HasPrefPath(prefs::kDisable3DAPIs
) &&
1525 prefs
->GetBoolean(prefs::kDisable3DAPIs
)) {
1526 // Turn this policy into a command line switch.
1527 command_line
->AppendSwitch(switches::kDisable3DAPIs
);
1530 // Disable client-side phishing detection in the renderer if it is
1531 // disabled in the Profile preferences or the browser process.
1532 if (!prefs
->GetBoolean(prefs::kSafeBrowsingEnabled
) ||
1533 !g_browser_process
->safe_browsing_detection_service()) {
1534 command_line
->AppendSwitch(
1535 switches::kDisableClientSidePhishingDetection
);
1538 if (!prefs
->GetBoolean(prefs::kPrintPreviewDisabled
))
1539 command_line
->AppendSwitch(switches::kRendererPrintPreview
);
1541 InstantService
* instant_service
=
1542 InstantServiceFactory::GetForProfile(profile
);
1543 if (instant_service
&&
1544 instant_service
->IsInstantProcess(process
->GetID()))
1545 command_line
->AppendSwitch(switches::kInstantProcess
);
1547 #if !defined(OS_CHROMEOS)
1548 ChromeSigninClient
* signin_client
=
1549 ChromeSigninClientFactory::GetForProfile(profile
);
1550 if (signin_client
&& signin_client
->IsSigninProcess(process
->GetID()))
1551 command_line
->AppendSwitch(switches::kSigninProcess
);
1556 // Enable auto-reload if this session is in the field trial or the user
1557 // explicitly enabled it.
1559 base::FieldTrialList::FindFullName("AutoReloadExperiment");
1560 if (group
== "Enabled" ||
1561 browser_command_line
.HasSwitch(switches::kEnableOfflineAutoReload
)) {
1562 command_line
->AppendSwitch(switches::kEnableOfflineAutoReload
);
1567 // Enable load stale cache if this session is in the field trial or
1568 // the user explicitly enabled it.
1570 base::FieldTrialList::FindFullName("LoadStaleCacheExperiment");
1571 if (group
== "Enabled" || browser_command_line
.HasSwitch(
1572 switches::kEnableOfflineLoadStaleCache
)) {
1573 command_line
->AppendSwitch(switches::kEnableOfflineLoadStaleCache
);
1577 // Please keep this in alphabetical order.
1578 static const char* const kSwitchNames
[] = {
1579 autofill::switches::kDisableIgnoreAutocompleteOff
,
1580 autofill::switches::kDisablePasswordGeneration
,
1581 autofill::switches::kEnablePasswordGeneration
,
1582 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration
,
1583 extensions::switches::kAllowHTTPBackgroundPage
,
1584 extensions::switches::kAllowLegacyExtensionManifests
,
1585 extensions::switches::kEnableExperimentalExtensionApis
,
1586 extensions::switches::kExtensionsOnChromeURLs
,
1587 extensions::switches::kWhitelistedExtensionID
,
1588 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO
1590 switches::kAllowNaClFileHandleAPI
,
1591 switches::kAppsCheckoutURL
,
1592 switches::kAppsGalleryURL
,
1593 switches::kCloudPrintURL
,
1594 switches::kCloudPrintXmppEndpoint
,
1595 switches::kDisableBundledPpapiFlash
,
1596 switches::kDisableExtensionsResourceWhitelist
,
1597 switches::kDisablePnacl
,
1598 switches::kDisableScriptedPrintThrottling
,
1599 switches::kEnableAdview
,
1600 switches::kEnableAppWindowControls
,
1601 switches::kEnableBenchmarking
,
1602 switches::kEnableNaCl
,
1603 switches::kEnableNaClDebug
,
1604 switches::kEnableNaClNonSfiMode
,
1605 switches::kEnableNetBenchmarking
,
1606 switches::kEnableStreamlinedHostedApps
,
1607 switches::kEnableWatchdog
,
1608 switches::kMemoryProfiling
,
1609 switches::kMessageLoopHistogrammer
,
1610 switches::kNoJsRandomness
,
1611 switches::kOutOfProcessPdf
,
1612 switches::kPlaybackMode
,
1613 switches::kPpapiFlashArgs
,
1614 switches::kPpapiFlashPath
,
1615 switches::kPpapiFlashVersion
,
1616 switches::kProfilingAtStart
,
1617 switches::kProfilingFile
,
1618 switches::kProfilingFlush
,
1619 switches::kRecordMode
,
1620 switches::kSilentDumpOnDCHECK
,
1621 translate::switches::kTranslateSecurityOrigin
,
1624 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1625 arraysize(kSwitchNames
));
1626 } else if (process_type
== switches::kUtilityProcess
) {
1627 static const char* const kSwitchNames
[] = {
1628 extensions::switches::kAllowHTTPBackgroundPage
,
1629 extensions::switches::kEnableExperimentalExtensionApis
,
1630 extensions::switches::kExtensionsOnChromeURLs
,
1631 extensions::switches::kWhitelistedExtensionID
,
1634 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1635 arraysize(kSwitchNames
));
1636 } else if (process_type
== switches::kPluginProcess
) {
1637 static const char* const kSwitchNames
[] = {
1638 #if defined(OS_CHROMEOS)
1639 chromeos::switches::kLoginProfile
,
1641 switches::kMemoryProfiling
,
1642 switches::kSilentDumpOnDCHECK
,
1645 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1646 arraysize(kSwitchNames
));
1647 } else if (process_type
== switches::kZygoteProcess
) {
1648 static const char* const kSwitchNames
[] = {
1649 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
1650 switches::kDisableBundledPpapiFlash
,
1651 switches::kNaClDangerousNoSandboxNonSfi
,
1652 switches::kPpapiFlashPath
,
1653 switches::kPpapiFlashVersion
,
1656 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1657 arraysize(kSwitchNames
));
1658 } else if (process_type
== switches::kGpuProcess
) {
1659 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1660 // because GPU is expected to be unreliable.
1661 if (browser_command_line
.HasSwitch(switches::kIgnoreGpuBlacklist
) &&
1662 !command_line
->HasSwitch(switches::kDisableBreakpad
))
1663 command_line
->AppendSwitch(switches::kDisableBreakpad
);
1666 // The command line switch kEnableBenchmarking needs to be specified along
1667 // with the kEnableStatsTable switch to ensure that the stats table global
1668 // is initialized correctly.
1669 if (command_line
->HasSwitch(switches::kEnableBenchmarking
))
1670 DCHECK(command_line
->HasSwitch(switches::kEnableStatsTable
));
1673 std::string
ChromeContentBrowserClient::GetApplicationLocale() {
1674 if (BrowserThread::CurrentlyOn(BrowserThread::IO
))
1675 return g_io_thread_application_locale
.Get();
1676 return g_browser_process
->GetApplicationLocale();
1679 std::string
ChromeContentBrowserClient::GetAcceptLangs(
1680 content::BrowserContext
* context
) {
1681 Profile
* profile
= Profile::FromBrowserContext(context
);
1682 return profile
->GetPrefs()->GetString(prefs::kAcceptLanguages
);
1685 gfx::ImageSkia
* ChromeContentBrowserClient::GetDefaultFavicon() {
1686 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
1687 return rb
.GetImageSkiaNamed(IDR_DEFAULT_FAVICON
);
1690 bool ChromeContentBrowserClient::AllowAppCache(
1691 const GURL
& manifest_url
,
1692 const GURL
& first_party
,
1693 content::ResourceContext
* context
) {
1694 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1695 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1696 return io_data
->GetCookieSettings()->
1697 IsSettingCookieAllowed(manifest_url
, first_party
);
1700 bool ChromeContentBrowserClient::AllowGetCookie(
1702 const GURL
& first_party
,
1703 const net::CookieList
& cookie_list
,
1704 content::ResourceContext
* context
,
1705 int render_process_id
,
1706 int render_frame_id
) {
1707 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1708 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1709 bool allow
= io_data
->GetCookieSettings()->
1710 IsReadingCookieAllowed(url
, first_party
);
1712 BrowserThread::PostTask(
1713 BrowserThread::UI
, FROM_HERE
,
1714 base::Bind(&TabSpecificContentSettings::CookiesRead
, render_process_id
,
1715 render_frame_id
, url
, first_party
, cookie_list
, !allow
, true));
1719 bool ChromeContentBrowserClient::AllowSetCookie(
1721 const GURL
& first_party
,
1722 const std::string
& cookie_line
,
1723 content::ResourceContext
* context
,
1724 int render_process_id
,
1725 int render_frame_id
,
1726 net::CookieOptions
* options
) {
1727 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1728 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1729 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1730 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, first_party
);
1732 BrowserThread::PostTask(
1733 BrowserThread::UI
, FROM_HERE
,
1734 base::Bind(&TabSpecificContentSettings::CookieChanged
, render_process_id
,
1735 render_frame_id
, url
, first_party
, cookie_line
, *options
,
1740 bool ChromeContentBrowserClient::AllowSaveLocalState(
1741 content::ResourceContext
* context
) {
1742 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1743 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1744 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1745 ContentSetting setting
= cookie_settings
->GetDefaultCookieSetting(NULL
);
1747 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1748 // Could we even support per-origin settings?
1749 return setting
!= CONTENT_SETTING_SESSION_ONLY
;
1752 bool ChromeContentBrowserClient::AllowWorkerDatabase(
1754 const base::string16
& name
,
1755 const base::string16
& display_name
,
1756 unsigned long estimated_size
,
1757 content::ResourceContext
* context
,
1758 const std::vector
<std::pair
<int, int> >& render_frames
) {
1759 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1760 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1761 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1762 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1764 // Record access to database for potential display in UI.
1765 std::vector
<std::pair
<int, int> >::const_iterator i
;
1766 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1767 BrowserThread::PostTask(
1768 BrowserThread::UI
, FROM_HERE
,
1769 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed
,
1770 i
->first
, i
->second
, url
, name
, display_name
, !allow
));
1776 bool ChromeContentBrowserClient::AllowWorkerFileSystem(
1778 content::ResourceContext
* context
,
1779 const std::vector
<std::pair
<int, int> >& render_frames
) {
1780 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1781 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1782 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1783 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1785 // Record access to file system for potential display in UI.
1786 std::vector
<std::pair
<int, int> >::const_iterator i
;
1787 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1788 BrowserThread::PostTask(
1789 BrowserThread::UI
, FROM_HERE
,
1790 base::Bind(&TabSpecificContentSettings::FileSystemAccessed
,
1791 i
->first
, i
->second
, url
, !allow
));
1797 bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1799 const base::string16
& name
,
1800 content::ResourceContext
* context
,
1801 const std::vector
<std::pair
<int, int> >& render_frames
) {
1802 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1803 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1804 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1805 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1807 // Record access to IndexedDB for potential display in UI.
1808 std::vector
<std::pair
<int, int> >::const_iterator i
;
1809 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1810 BrowserThread::PostTask(
1811 BrowserThread::UI
, FROM_HERE
,
1812 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed
,
1813 i
->first
, i
->second
, url
, name
, !allow
));
1819 net::URLRequestContext
*
1820 ChromeContentBrowserClient::OverrideRequestContextForURL(
1821 const GURL
& url
, content::ResourceContext
* context
) {
1822 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1823 if (url
.SchemeIs(extensions::kExtensionScheme
)) {
1824 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1825 return io_data
->extensions_request_context();
1831 QuotaPermissionContext
*
1832 ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1833 return new ChromeQuotaPermissionContext();
1836 void ChromeContentBrowserClient::AllowCertificateError(
1837 int render_process_id
,
1838 int render_frame_id
,
1840 const net::SSLInfo
& ssl_info
,
1841 const GURL
& request_url
,
1842 ResourceType::Type resource_type
,
1844 bool strict_enforcement
,
1845 const base::Callback
<void(bool)>& callback
,
1846 content::CertificateRequestResultType
* result
) {
1847 if (resource_type
!= ResourceType::MAIN_FRAME
) {
1848 // A sub-resource has a certificate error. The user doesn't really
1849 // have a context for making the right decision, so block the
1850 // request hard, without an info bar to allow showing the insecure
1852 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY
;
1856 // If the tab is being prerendered, cancel the prerender and the request.
1857 content::RenderFrameHost
* render_frame_host
=
1858 content::RenderFrameHost::FromID(render_process_id
, render_frame_id
);
1859 WebContents
* tab
= WebContents::FromRenderFrameHost(render_frame_host
);
1865 prerender::PrerenderContents
* prerender_contents
=
1866 prerender::PrerenderContents::FromWebContents(tab
);
1867 if (prerender_contents
) {
1868 prerender_contents
->Destroy(prerender::FINAL_STATUS_SSL_ERROR
);
1869 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL
;
1873 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
1874 CaptivePortalTabHelper
* captive_portal_tab_helper
=
1875 CaptivePortalTabHelper::FromWebContents(tab
);
1876 if (captive_portal_tab_helper
)
1877 captive_portal_tab_helper
->OnSSLCertError(ssl_info
);
1880 // Otherwise, display an SSL blocking page.
1881 new SSLBlockingPage(tab
, cert_error
, ssl_info
, request_url
, overridable
,
1882 strict_enforcement
, callback
);
1885 void ChromeContentBrowserClient::SelectClientCertificate(
1886 int render_process_id
,
1887 int render_frame_id
,
1888 const net::HttpNetworkSession
* network_session
,
1889 net::SSLCertRequestInfo
* cert_request_info
,
1890 const base::Callback
<void(net::X509Certificate
*)>& callback
) {
1891 content::RenderFrameHost
* rfh
= content::RenderFrameHost::FromID(
1892 render_process_id
, render_frame_id
);
1893 WebContents
* tab
= WebContents::FromRenderFrameHost(rfh
);
1899 prerender::PrerenderContents
* prerender_contents
=
1900 prerender::PrerenderContents::FromWebContents(tab
);
1901 if (prerender_contents
) {
1902 prerender_contents
->Destroy(
1903 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED
);
1907 GURL
requesting_url("https://" + cert_request_info
->host_and_port
.ToString());
1908 DCHECK(requesting_url
.is_valid())
1909 << "Invalid URL string: https://"
1910 << cert_request_info
->host_and_port
.ToString();
1912 Profile
* profile
= Profile::FromBrowserContext(tab
->GetBrowserContext());
1913 scoped_ptr
<base::Value
> filter(
1914 profile
->GetHostContentSettingsMap()->GetWebsiteSetting(
1917 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE
,
1918 std::string(), NULL
));
1921 // Try to automatically select a client certificate.
1922 if (filter
->IsType(base::Value::TYPE_DICTIONARY
)) {
1923 base::DictionaryValue
* filter_dict
=
1924 static_cast<base::DictionaryValue
*>(filter
.get());
1926 const std::vector
<scoped_refptr
<net::X509Certificate
> >&
1927 all_client_certs
= cert_request_info
->client_certs
;
1928 for (size_t i
= 0; i
< all_client_certs
.size(); ++i
) {
1929 if (CertMatchesFilter(*all_client_certs
[i
].get(), *filter_dict
)) {
1930 // Use the first certificate that is matched by the filter.
1931 callback
.Run(all_client_certs
[i
].get());
1940 SSLTabHelper
* ssl_tab_helper
= SSLTabHelper::FromWebContents(tab
);
1941 if (!ssl_tab_helper
) {
1942 // If there is no SSLTabHelper for the given WebContents then we can't
1943 // show the user a dialog to select a client certificate. So we simply
1944 // proceed with no client certificate.
1948 ssl_tab_helper
->ShowClientCertificateRequestDialog(
1949 network_session
, cert_request_info
, callback
);
1952 void ChromeContentBrowserClient::AddCertificate(
1953 net::URLRequest
* request
,
1954 net::CertificateMimeType cert_type
,
1955 const void* cert_data
,
1957 int render_process_id
,
1958 int render_view_id
) {
1959 chrome::SSLAddCertificate(request
, cert_type
, cert_data
, cert_size
,
1960 render_process_id
, render_view_id
);
1963 content::MediaObserver
* ChromeContentBrowserClient::GetMediaObserver() {
1964 return MediaCaptureDevicesDispatcher::GetInstance();
1967 void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1968 const GURL
& source_origin
,
1969 content::RenderFrameHost
* render_frame_host
,
1970 base::Closure
& callback
) {
1971 #if defined(ENABLE_NOTIFICATIONS)
1972 // Skip showing the infobar if the request comes from an extension, and that
1973 // extension has the 'notify' permission. (If the extension does not have the
1974 // permission, the user will still be prompted.)
1975 Profile
* profile
= Profile::FromBrowserContext(
1976 render_frame_host
->GetSiteInstance()->GetBrowserContext());
1977 InfoMap
* extension_info_map
=
1978 extensions::ExtensionSystem::Get(profile
)->info_map();
1979 DesktopNotificationService
* notification_service
=
1980 DesktopNotificationServiceFactory::GetForProfile(profile
);
1981 const Extension
* extension
= NULL
;
1982 if (extension_info_map
) {
1983 extensions::ExtensionSet extensions
;
1984 extension_info_map
->GetExtensionsWithAPIPermissionForSecurityOrigin(
1985 source_origin
, render_frame_host
->GetProcess()->GetID(),
1986 extensions::APIPermission::kNotification
, &extensions
);
1987 for (extensions::ExtensionSet::const_iterator iter
= extensions
.begin();
1988 iter
!= extensions
.end(); ++iter
) {
1989 if (notification_service
->IsNotifierEnabled(NotifierId(
1990 NotifierId::APPLICATION
, (*iter
)->id()))) {
1991 extension
= iter
->get();
1996 if (IsExtensionWithPermissionOrSuggestInConsole(
1997 APIPermission::kNotification
, extension
,
1998 render_frame_host
->GetRenderViewHost())) {
2003 notification_service
->RequestPermission(
2004 source_origin
, render_frame_host
, callback
);
2010 blink::WebNotificationPresenter::Permission
2011 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
2012 const GURL
& source_origin
,
2013 content::ResourceContext
* context
,
2014 int render_process_id
) {
2015 #if defined(ENABLE_NOTIFICATIONS)
2016 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
2018 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
2019 InfoMap
* extension_info_map
= io_data
->GetExtensionInfoMap();
2021 // We want to see if there is an extension that hasn't been manually disabled
2022 // that has the notifications permission and applies to this security origin.
2023 // First, get the list of extensions with permission for the origin.
2024 extensions::ExtensionSet extensions
;
2025 extension_info_map
->GetExtensionsWithAPIPermissionForSecurityOrigin(
2026 source_origin
, render_process_id
,
2027 extensions::APIPermission::kNotification
, &extensions
);
2028 for (extensions::ExtensionSet::const_iterator iter
= extensions
.begin();
2029 iter
!= extensions
.end(); ++iter
) {
2030 // Then, check to see if it's been disabled by the user.
2031 if (!extension_info_map
->AreNotificationsDisabled((*iter
)->id()))
2032 return blink::WebNotificationPresenter::PermissionAllowed
;
2035 // No enabled extensions exist, so check the normal host content settings.
2036 HostContentSettingsMap
* host_content_settings_map
=
2037 io_data
->GetHostContentSettingsMap();
2038 ContentSetting setting
= host_content_settings_map
->GetContentSetting(
2041 CONTENT_SETTINGS_TYPE_NOTIFICATIONS
,
2042 NO_RESOURCE_IDENTIFIER
);
2044 if (setting
== CONTENT_SETTING_ALLOW
)
2045 return blink::WebNotificationPresenter::PermissionAllowed
;
2046 if (setting
== CONTENT_SETTING_BLOCK
)
2047 return blink::WebNotificationPresenter::PermissionDenied
;
2048 return blink::WebNotificationPresenter::PermissionNotAllowed
;
2050 return blink::WebNotificationPresenter::PermissionAllowed
;
2054 void ChromeContentBrowserClient::ShowDesktopNotification(
2055 const content::ShowDesktopNotificationHostMsgParams
& params
,
2056 RenderFrameHost
* render_frame_host
,
2057 content::DesktopNotificationDelegate
* delegate
,
2058 base::Closure
* cancel_callback
) {
2059 #if defined(ENABLE_NOTIFICATIONS)
2060 content::RenderProcessHost
* process
= render_frame_host
->GetProcess();
2061 Profile
* profile
= Profile::FromBrowserContext(process
->GetBrowserContext());
2062 DesktopNotificationService
* service
=
2063 DesktopNotificationServiceFactory::GetForProfile(profile
);
2064 service
->ShowDesktopNotification(
2065 params
, render_frame_host
, delegate
, cancel_callback
);
2071 bool ChromeContentBrowserClient::CanCreateWindow(
2072 const GURL
& opener_url
,
2073 const GURL
& opener_top_level_frame_url
,
2074 const GURL
& source_origin
,
2075 WindowContainerType container_type
,
2076 const GURL
& target_url
,
2077 const content::Referrer
& referrer
,
2078 WindowOpenDisposition disposition
,
2079 const WebWindowFeatures
& features
,
2081 bool opener_suppressed
,
2082 content::ResourceContext
* context
,
2083 int render_process_id
,
2086 bool* no_javascript_access
) {
2087 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
2089 *no_javascript_access
= false;
2091 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
2092 InfoMap
* map
= io_data
->GetExtensionInfoMap();
2094 // If the opener is trying to create a background window but doesn't have
2095 // the appropriate permission, fail the attempt.
2096 if (container_type
== WINDOW_CONTAINER_TYPE_BACKGROUND
) {
2097 if (!map
->SecurityOriginHasAPIPermission(
2100 APIPermission::kBackground
)) {
2104 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2105 // return a recently installed Extension even if this CanCreateWindow call
2106 // was made by an old copy of the page in a normal web process. That's ok,
2107 // because the permission check above would have caused an early return
2108 // already. We must use the full URL to find hosted apps, though, and not
2110 const Extension
* extension
=
2111 map
->extensions().GetExtensionOrAppByURL(opener_url
);
2112 if (extension
&& !extensions::BackgroundInfo::AllowJSAccess(extension
))
2113 *no_javascript_access
= true;
2118 // No new browser window (popup or tab) in app mode.
2119 if (container_type
== WINDOW_CONTAINER_TYPE_NORMAL
&&
2120 chrome::IsRunningInForcedAppMode()) {
2127 HostContentSettingsMap
* content_settings
=
2128 ProfileIOData::FromResourceContext(context
)->GetHostContentSettingsMap();
2129 BlockedWindowParams
blocked_params(target_url
,
2138 if (!user_gesture
&& !CommandLine::ForCurrentProcess()->HasSwitch(
2139 switches::kDisablePopupBlocking
)) {
2140 if (content_settings
->GetContentSetting(opener_top_level_frame_url
,
2141 opener_top_level_frame_url
,
2142 CONTENT_SETTINGS_TYPE_POPUPS
,
2144 CONTENT_SETTING_ALLOW
) {
2145 BrowserThread::PostTask(BrowserThread::UI
,
2147 base::Bind(&HandleBlockedPopupOnUIThread
,
2153 #if defined(OS_ANDROID)
2154 if (SingleTabModeTabHelper::IsRegistered(render_process_id
, opener_id
)) {
2155 BrowserThread::PostTask(BrowserThread::UI
,
2157 base::Bind(&HandleSingleTabModeBlockOnUIThread
,
2166 std::string
ChromeContentBrowserClient::GetWorkerProcessTitle(
2167 const GURL
& url
, content::ResourceContext
* context
) {
2168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
2169 // Check if it's an extension-created worker, in which case we want to use
2170 // the name of the extension.
2171 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
2172 const Extension
* extension
=
2173 io_data
->GetExtensionInfoMap()->extensions().GetByID(url
.host());
2174 return extension
? extension
->name() : std::string();
2177 void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2178 return g_browser_process
->ResourceDispatcherHostCreated();
2181 // TODO(tommi): Rename from Get to Create.
2182 content::SpeechRecognitionManagerDelegate
*
2183 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
2184 return new speech::ChromeSpeechRecognitionManagerDelegate();
2187 net::NetLog
* ChromeContentBrowserClient::GetNetLog() {
2188 return g_browser_process
->net_log();
2191 AccessTokenStore
* ChromeContentBrowserClient::CreateAccessTokenStore() {
2192 return new ChromeAccessTokenStore();
2195 bool ChromeContentBrowserClient::IsFastShutdownPossible() {
2199 void ChromeContentBrowserClient::OverrideWebkitPrefs(
2200 RenderViewHost
* rvh
, const GURL
& url
, WebPreferences
* web_prefs
) {
2201 Profile
* profile
= Profile::FromBrowserContext(
2202 rvh
->GetProcess()->GetBrowserContext());
2203 PrefService
* prefs
= profile
->GetPrefs();
2205 // Fill per-script font preferences. These are not registered on Android
2206 // - http://crbug.com/308033.
2207 #if !defined(OS_ANDROID)
2208 FillFontFamilyMap(prefs
, prefs::kWebKitStandardFontFamilyMap
,
2209 &web_prefs
->standard_font_family_map
);
2210 FillFontFamilyMap(prefs
, prefs::kWebKitFixedFontFamilyMap
,
2211 &web_prefs
->fixed_font_family_map
);
2212 FillFontFamilyMap(prefs
, prefs::kWebKitSerifFontFamilyMap
,
2213 &web_prefs
->serif_font_family_map
);
2214 FillFontFamilyMap(prefs
, prefs::kWebKitSansSerifFontFamilyMap
,
2215 &web_prefs
->sans_serif_font_family_map
);
2216 FillFontFamilyMap(prefs
, prefs::kWebKitCursiveFontFamilyMap
,
2217 &web_prefs
->cursive_font_family_map
);
2218 FillFontFamilyMap(prefs
, prefs::kWebKitFantasyFontFamilyMap
,
2219 &web_prefs
->fantasy_font_family_map
);
2220 FillFontFamilyMap(prefs
, prefs::kWebKitPictographFontFamilyMap
,
2221 &web_prefs
->pictograph_font_family_map
);
2224 web_prefs
->default_font_size
=
2225 prefs
->GetInteger(prefs::kWebKitDefaultFontSize
);
2226 web_prefs
->default_fixed_font_size
=
2227 prefs
->GetInteger(prefs::kWebKitDefaultFixedFontSize
);
2228 web_prefs
->minimum_font_size
=
2229 prefs
->GetInteger(prefs::kWebKitMinimumFontSize
);
2230 web_prefs
->minimum_logical_font_size
=
2231 prefs
->GetInteger(prefs::kWebKitMinimumLogicalFontSize
);
2233 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2235 web_prefs
->javascript_can_open_windows_automatically
=
2236 prefs
->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically
);
2237 web_prefs
->dom_paste_enabled
=
2238 prefs
->GetBoolean(prefs::kWebKitDomPasteEnabled
);
2239 web_prefs
->shrinks_standalone_images_to_fit
=
2240 prefs
->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit
);
2241 const base::DictionaryValue
* inspector_settings
=
2242 prefs
->GetDictionary(prefs::kWebKitInspectorSettings
);
2243 if (inspector_settings
) {
2244 for (base::DictionaryValue::Iterator
iter(*inspector_settings
);
2248 if (iter
.value().GetAsString(&value
)) {
2249 web_prefs
->inspector_settings
.push_back(
2250 std::make_pair(iter
.key(), value
));
2254 web_prefs
->tabs_to_links
= prefs
->GetBoolean(prefs::kWebkitTabsToLinks
);
2256 if (!prefs
->GetBoolean(prefs::kWebKitJavascriptEnabled
))
2257 web_prefs
->javascript_enabled
= false;
2258 if (!prefs
->GetBoolean(prefs::kWebKitWebSecurityEnabled
))
2259 web_prefs
->web_security_enabled
= false;
2260 if (!prefs
->GetBoolean(prefs::kWebKitPluginsEnabled
))
2261 web_prefs
->plugins_enabled
= false;
2262 if (!prefs
->GetBoolean(prefs::kWebKitJavaEnabled
))
2263 web_prefs
->java_enabled
= false;
2264 web_prefs
->loads_images_automatically
=
2265 prefs
->GetBoolean(prefs::kWebKitLoadsImagesAutomatically
);
2267 if (prefs
->GetBoolean(prefs::kDisable3DAPIs
))
2268 web_prefs
->experimental_webgl_enabled
= false;
2270 web_prefs
->allow_displaying_insecure_content
=
2271 prefs
->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent
);
2272 web_prefs
->allow_running_insecure_content
=
2273 prefs
->GetBoolean(prefs::kWebKitAllowRunningInsecureContent
);
2274 #if defined(OS_ANDROID)
2275 web_prefs
->font_scale_factor
=
2276 static_cast<float>(prefs
->GetDouble(prefs::kWebKitFontScaleFactor
));
2277 web_prefs
->device_scale_adjustment
= GetDeviceScaleAdjustment();
2278 web_prefs
->force_enable_zoom
=
2279 prefs
->GetBoolean(prefs::kWebKitForceEnableZoom
);
2282 #if defined(OS_ANDROID)
2283 web_prefs
->password_echo_enabled
=
2284 prefs
->GetBoolean(prefs::kWebKitPasswordEchoEnabled
);
2286 web_prefs
->password_echo_enabled
= browser_defaults::kPasswordEchoEnabled
;
2289 web_prefs
->asynchronous_spell_checking_enabled
= true;
2290 web_prefs
->unified_textchecker_enabled
= true;
2292 web_prefs
->uses_universal_detector
=
2293 prefs
->GetBoolean(prefs::kWebKitUsesUniversalDetector
);
2294 web_prefs
->text_areas_are_resizable
=
2295 prefs
->GetBoolean(prefs::kWebKitTextAreasAreResizable
);
2296 web_prefs
->hyperlink_auditing_enabled
=
2297 prefs
->GetBoolean(prefs::kEnableHyperlinkAuditing
);
2299 // Make sure we will set the default_encoding with canonical encoding name.
2300 web_prefs
->default_encoding
=
2301 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
2302 web_prefs
->default_encoding
);
2303 if (web_prefs
->default_encoding
.empty()) {
2304 prefs
->ClearPref(prefs::kDefaultCharset
);
2305 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2307 DCHECK(!web_prefs
->default_encoding
.empty());
2309 WebContents
* web_contents
= WebContents::FromRenderViewHost(rvh
);
2310 extensions::ViewType view_type
= extensions::GetViewType(web_contents
);
2311 ExtensionService
* service
=
2312 extensions::ExtensionSystem::Get(profile
)->extension_service();
2314 const GURL
& site_url
= rvh
->GetSiteInstance()->GetSiteURL();
2315 const Extension
* extension
=
2316 service
->extensions()->GetByID(site_url
.host());
2317 // Ensure that we are only granting extension preferences to URLs with
2318 // the correct scheme. Without this check, chrome-guest:// schemes used by
2319 // webview tags as well as hosts that happen to match the id of an
2320 // installed extension would get the wrong preferences.
2321 if (site_url
.SchemeIs(extensions::kExtensionScheme
)) {
2322 extension_webkit_preferences::SetPreferences(
2323 extension
, view_type
, web_prefs
);
2328 void ChromeContentBrowserClient::UpdateInspectorSetting(
2329 RenderViewHost
* rvh
, const std::string
& key
, const std::string
& value
) {
2330 content::BrowserContext
* browser_context
=
2331 rvh
->GetProcess()->GetBrowserContext();
2332 DictionaryPrefUpdate
update(
2333 Profile::FromBrowserContext(browser_context
)->GetPrefs(),
2334 prefs::kWebKitInspectorSettings
);
2335 base::DictionaryValue
* inspector_settings
= update
.Get();
2336 inspector_settings
->SetWithoutPathExpansion(
2337 key
, base::Value::CreateStringValue(value
));
2340 void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2341 BrowserURLHandler
* handler
) {
2342 // Add the default URL handlers.
2343 handler
->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride
,
2344 BrowserURLHandler::null_handler());
2345 handler
->AddHandlerPair(BrowserURLHandler::null_handler(),
2346 &ExtensionWebUI::HandleChromeURLOverrideReverse
);
2348 // about: handler. Must come before chrome: handler, since it will
2349 // rewrite about: urls to chrome: URLs and then expect chrome: to
2350 // actually handle them.
2351 handler
->AddHandlerPair(&WillHandleBrowserAboutURL
,
2352 BrowserURLHandler::null_handler());
2354 #if defined(OS_ANDROID)
2355 // Handler to rewrite chrome://newtab on Android.
2356 handler
->AddHandlerPair(&chrome::android::HandleAndroidNewTabURL
,
2357 BrowserURLHandler::null_handler());
2359 // Handler to rewrite chrome://newtab for InstantExtended.
2360 handler
->AddHandlerPair(&chrome::HandleNewTabURLRewrite
,
2361 &chrome::HandleNewTabURLReverseRewrite
);
2364 // chrome: & friends.
2365 handler
->AddHandlerPair(&HandleWebUI
, &HandleWebUIReverse
);
2368 void ChromeContentBrowserClient::ClearCache(RenderViewHost
* rvh
) {
2369 Profile
* profile
= Profile::FromBrowserContext(
2370 rvh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2371 BrowsingDataRemover
* remover
=
2372 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2373 remover
->Remove(BrowsingDataRemover::REMOVE_CACHE
,
2374 BrowsingDataHelper::UNPROTECTED_WEB
);
2375 // BrowsingDataRemover takes care of deleting itself when done.
2378 void ChromeContentBrowserClient::ClearCookies(RenderViewHost
* rvh
) {
2379 Profile
* profile
= Profile::FromBrowserContext(
2380 rvh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2381 BrowsingDataRemover
* remover
=
2382 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2383 int remove_mask
= BrowsingDataRemover::REMOVE_SITE_DATA
;
2384 remover
->Remove(remove_mask
, BrowsingDataHelper::UNPROTECTED_WEB
);
2385 // BrowsingDataRemover takes care of deleting itself when done.
2388 base::FilePath
ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
2389 return DownloadPrefs::GetDefaultDownloadDirectory();
2392 std::string
ChromeContentBrowserClient::GetDefaultDownloadName() {
2393 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME
);
2396 void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2397 content::BrowserPpapiHost
* browser_host
) {
2398 #if defined(ENABLE_PLUGINS)
2399 browser_host
->GetPpapiHost()->AddHostFactoryFilter(
2400 scoped_ptr
<ppapi::host::HostFactory
>(
2401 new ChromeBrowserPepperHostFactory(browser_host
)));
2405 content::BrowserPpapiHost
*
2406 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2407 int plugin_process_id
) {
2408 BrowserChildProcessHostIterator
iter(PROCESS_TYPE_NACL_LOADER
);
2409 while (!iter
.Done()) {
2410 nacl::NaClProcessHost
* host
= static_cast<nacl::NaClProcessHost
*>(
2411 iter
.GetDelegate());
2412 if (host
->process() &&
2413 host
->process()->GetData().id
== plugin_process_id
) {
2414 // Found the plugin.
2415 return host
->browser_ppapi_host();
2422 bool ChromeContentBrowserClient::AllowPepperSocketAPI(
2423 content::BrowserContext
* browser_context
,
2426 const content::SocketPermissionRequest
* params
) {
2427 #if defined(ENABLE_PLUGINS)
2428 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
2429 const extensions::ExtensionSet
* extension_set
= NULL
;
2431 extension_set
= extensions::ExtensionSystem::Get(profile
)->
2432 extension_service()->extensions();
2436 // Access to private socket APIs is controlled by the whitelist.
2437 if (IsExtensionOrSharedModuleWhitelisted(url
, extension_set
,
2438 allowed_socket_origins_
)) {
2442 // Access to public socket APIs is controlled by extension permissions.
2443 if (url
.is_valid() && url
.SchemeIs(extensions::kExtensionScheme
) &&
2445 const Extension
* extension
= extension_set
->GetByID(url
.host());
2448 extensions::SocketPermission::CheckParam
check_params(
2449 params
->type
, params
->host
, params
->port
);
2450 if (extensions::PermissionsData::CheckAPIPermissionWithParam(
2451 extension
, extensions::APIPermission::kSocket
,
2456 if (extensions::PermissionsData::HasAPIPermission(
2457 extension
, extensions::APIPermission::kSocket
)) {
2465 // Allow both public and private APIs if the command line says so.
2466 return IsHostAllowedByCommandLine(url
, extension_set
,
2467 switches::kAllowNaClSocketAPI
);
2473 ui::SelectFilePolicy
* ChromeContentBrowserClient::CreateSelectFilePolicy(
2474 WebContents
* web_contents
) {
2475 return new ChromeSelectFilePolicy(web_contents
);
2478 void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2479 std::vector
<std::string
>* additional_allowed_schemes
) {
2480 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2481 additional_allowed_schemes
);
2482 additional_allowed_schemes
->push_back(content::kChromeDevToolsScheme
);
2483 additional_allowed_schemes
->push_back(content::kChromeUIScheme
);
2484 additional_allowed_schemes
->push_back(extensions::kExtensionScheme
);
2487 void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
2488 std::vector
<fileapi::URLRequestAutoMountHandler
>* handlers
) {
2489 #if !defined(OS_ANDROID)
2490 handlers
->push_back(
2491 base::Bind(MediaFileSystemBackend::AttemptAutoMountForURLRequest
));
2492 #endif // OS_ANDROID
2495 void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
2496 content::BrowserContext
* browser_context
,
2497 const base::FilePath
& storage_partition_path
,
2498 ScopedVector
<fileapi::FileSystemBackend
>* additional_backends
) {
2499 #if !defined(OS_ANDROID)
2500 base::SequencedWorkerPool
* pool
= content::BrowserThread::GetBlockingPool();
2501 additional_backends
->push_back(new MediaFileSystemBackend(
2502 storage_partition_path
,
2503 pool
->GetSequencedTaskRunner(pool
->GetNamedSequenceToken(
2504 MediaFileSystemBackend::kMediaTaskRunnerName
)).get()));
2506 #if defined(OS_CHROMEOS)
2507 fileapi::ExternalMountPoints
* external_mount_points
=
2508 content::BrowserContext::GetMountPoints(browser_context
);
2509 DCHECK(external_mount_points
);
2510 chromeos::FileSystemBackend
* backend
= new chromeos::FileSystemBackend(
2511 new drive::FileSystemBackendDelegate
,
2512 new chromeos::file_system_provider::BackendDelegate
,
2513 new chromeos::MTPFileSystemBackendDelegate(storage_partition_path
),
2514 browser_context
->GetSpecialStoragePolicy(),
2515 external_mount_points
,
2516 fileapi::ExternalMountPoints::GetSystemInstance());
2517 backend
->AddSystemMountPoints();
2518 DCHECK(backend
->CanHandleType(fileapi::kFileSystemTypeExternal
));
2519 additional_backends
->push_back(backend
);
2522 additional_backends
->push_back(
2523 new sync_file_system::SyncFileSystemBackend(
2524 Profile::FromBrowserContext(browser_context
)));
2526 #if defined(ENABLE_SERVICE_DISCOVERY)
2527 if (CommandLine::ForCurrentProcess()->HasSwitch(
2528 switches::kEnablePrivetStorage
)) {
2529 additional_backends
->push_back(
2530 new local_discovery::PrivetFileSystemBackend(
2531 fileapi::ExternalMountPoints::GetSystemInstance(),
2537 #if defined(OS_POSIX) && !defined(OS_MACOSX)
2538 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2539 const CommandLine
& command_line
,
2540 int child_process_id
,
2541 std::vector
<FileDescriptorInfo
>* mappings
) {
2542 #if defined(OS_ANDROID)
2543 base::FilePath data_path
;
2544 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID
, &data_path
);
2545 DCHECK(!data_path
.empty());
2547 int flags
= base::File::FLAG_OPEN
| base::File::FLAG_READ
;
2548 base::FilePath chrome_resources_pak
=
2549 data_path
.AppendASCII("chrome_100_percent.pak");
2550 base::File
file(chrome_resources_pak
, flags
);
2551 DCHECK(file
.IsValid());
2552 mappings
->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor
,
2553 FileDescriptor(file
.Pass())));
2555 const std::string locale
= GetApplicationLocale();
2556 base::FilePath locale_pak
= ResourceBundle::GetSharedInstance().
2557 GetLocaleFilePath(locale
, false);
2558 file
.Initialize(locale_pak
, flags
);
2559 DCHECK(file
.IsValid());
2560 mappings
->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor
,
2561 FileDescriptor(file
.Pass())));
2563 base::FilePath resources_pack_path
;
2564 PathService::Get(chrome::FILE_RESOURCES_PACK
, &resources_pack_path
);
2565 file
.Initialize(resources_pack_path
, flags
);
2566 DCHECK(file
.IsValid());
2567 mappings
->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor
,
2568 FileDescriptor(file
.Pass())));
2570 if (breakpad::IsCrashReporterEnabled()) {
2571 file
= breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile(
2573 if (file
.IsValid()) {
2574 mappings
->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor
,
2575 FileDescriptor(file
.Pass())));
2577 LOG(ERROR
) << "Failed to create file for minidump, crash reporting will "
2578 "be disabled for this process.";
2583 int crash_signal_fd
= GetCrashSignalFD(command_line
);
2584 if (crash_signal_fd
>= 0) {
2585 mappings
->push_back(FileDescriptorInfo(kCrashDumpSignal
,
2586 FileDescriptor(crash_signal_fd
,
2589 #endif // defined(OS_ANDROID)
2591 #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
2594 const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2595 return chrome::kBrowserResourcesDll
;
2598 void ChromeContentBrowserClient::PreSpawnRenderer(
2599 sandbox::TargetPolicy
* policy
,
2601 // This code is duplicated in nacl_exe_win_64.cc.
2602 // Allow the server side of a pipe restricted to the "chrome.nacl."
2603 // namespace so that it cannot impersonate other system or other chrome
2605 sandbox::ResultCode result
= policy
->AddRule(
2606 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES
,
2607 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY
,
2608 L
"\\\\.\\pipe\\chrome.nacl.*");
2609 if (result
!= sandbox::SBOX_ALL_OK
) {
2614 // Renderers need to send named pipe handles and shared memory
2615 // segment handles to NaCl loader processes.
2616 result
= policy
->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES
,
2617 sandbox::TargetPolicy::HANDLES_DUP_ANY
,
2619 if (result
!= sandbox::SBOX_ALL_OK
) {
2626 bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2627 content::BrowserContext
* browser_context
,
2629 #if defined(ENABLE_PLUGINS)
2630 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
2631 const extensions::ExtensionSet
* extension_set
= NULL
;
2633 extension_set
= extensions::ExtensionSystem::Get(profile
)->
2634 extension_service()->extensions();
2636 // TODO(teravest): Populate allowed_file_handle_origins_ when FileIO is moved
2637 // from the renderer to the browser.
2638 return IsExtensionOrSharedModuleWhitelisted(url
, extension_set
,
2639 allowed_file_handle_origins_
) ||
2640 IsHostAllowedByCommandLine(url
, extension_set
,
2641 switches::kAllowNaClFileHandleAPI
);
2647 bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs() {
2648 #if defined(ENABLE_PLUGINS)
2649 // Allow access for tests.
2650 if (CommandLine::ForCurrentProcess()->HasSwitch(
2651 switches::kEnablePepperTesting
)) {
2655 chrome::VersionInfo::Channel channel
= chrome::VersionInfo::GetChannel();
2656 // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown"
2657 // releases of Chrome. Permitting "Unknown" allows these APIs to be used on
2658 // Chromium builds as well.
2659 return channel
<= chrome::VersionInfo::CHANNEL_DEV
;
2665 #if defined(ENABLE_WEBRTC)
2666 void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
2667 CommandLine
* to_command_line
,
2668 const CommandLine
& from_command_line
,
2669 VersionInfo::Channel channel
) {
2670 #if defined(OS_ANDROID)
2671 const VersionInfo::Channel kMaxDisableEncryptionChannel
=
2672 VersionInfo::CHANNEL_BETA
;
2674 const VersionInfo::Channel kMaxDisableEncryptionChannel
=
2675 VersionInfo::CHANNEL_DEV
;
2677 if (channel
<= kMaxDisableEncryptionChannel
) {
2678 static const char* const kWebRtcDevSwitchNames
[] = {
2679 switches::kDisableWebRtcEncryption
,
2681 to_command_line
->CopySwitchesFrom(from_command_line
,
2682 kWebRtcDevSwitchNames
,
2683 arraysize(kWebRtcDevSwitchNames
));
2686 #endif // defined(ENABLE_WEBRTC)
2688 } // namespace chrome