1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chrome_content_browser_client.h"
11 #include "base/bind.h"
12 #include "base/command_line.h"
13 #include "base/files/scoped_file.h"
14 #include "base/i18n/icu_util.h"
15 #include "base/lazy_instance.h"
16 #include "base/path_service.h"
17 #include "base/prefs/pref_service.h"
18 #include "base/prefs/scoped_user_pref_update.h"
19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/utf_string_conversions.h"
21 #include "base/threading/sequenced_worker_pool.h"
22 #include "chrome/browser/browser_about_handler.h"
23 #include "chrome/browser/browser_process.h"
24 #include "chrome/browser/browser_shutdown.h"
25 #include "chrome/browser/browsing_data/browsing_data_helper.h"
26 #include "chrome/browser/browsing_data/browsing_data_remover.h"
27 #include "chrome/browser/character_encoding.h"
28 #include "chrome/browser/chrome_content_browser_client_parts.h"
29 #include "chrome/browser/chrome_net_benchmarking_message_filter.h"
30 #include "chrome/browser/chrome_quota_permission_context.h"
31 #include "chrome/browser/content_settings/cookie_settings.h"
32 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
33 #include "chrome/browser/defaults.h"
34 #include "chrome/browser/download/download_prefs.h"
35 #include "chrome/browser/font_family_cache.h"
36 #include "chrome/browser/geolocation/chrome_access_token_store.h"
37 #include "chrome/browser/geolocation/geolocation_permission_context.h"
38 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h"
39 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
40 #include "chrome/browser/media/midi_permission_context.h"
41 #include "chrome/browser/media/midi_permission_context_factory.h"
42 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
43 #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
44 #include "chrome/browser/net/chrome_net_log.h"
45 #include "chrome/browser/notifications/desktop_notification_service.h"
46 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
47 #include "chrome/browser/notifications/platform_notification_service_impl.h"
48 #include "chrome/browser/platform_util.h"
49 #include "chrome/browser/prerender/prerender_final_status.h"
50 #include "chrome/browser/prerender/prerender_manager.h"
51 #include "chrome/browser/prerender/prerender_manager_factory.h"
52 #include "chrome/browser/prerender/prerender_message_filter.h"
53 #include "chrome/browser/prerender/prerender_tracker.h"
54 #include "chrome/browser/printing/printing_message_filter.h"
55 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
56 #include "chrome/browser/profiles/profile.h"
57 #include "chrome/browser/profiles/profile_io_data.h"
58 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
59 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
60 #include "chrome/browser/search/instant_service.h"
61 #include "chrome/browser/search/instant_service_factory.h"
62 #include "chrome/browser/search/search.h"
63 #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
64 #include "chrome/browser/services/gcm/push_messaging_permission_context.h"
65 #include "chrome/browser/services/gcm/push_messaging_permission_context_factory.h"
66 #include "chrome/browser/signin/principals_message_filter.h"
67 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
68 #include "chrome/browser/speech/tts_controller.h"
69 #include "chrome/browser/speech/tts_message_filter.h"
70 #include "chrome/browser/ssl/ssl_add_certificate.h"
71 #include "chrome/browser/ssl/ssl_blocking_page.h"
72 #include "chrome/browser/ssl/ssl_client_certificate_selector.h"
73 #include "chrome/browser/ssl/ssl_error_handler.h"
74 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
75 #include "chrome/browser/tab_contents/tab_util.h"
76 #include "chrome/browser/ui/blocked_content/blocked_window_params.h"
77 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
78 #include "chrome/browser/ui/chrome_select_file_policy.h"
79 #include "chrome/browser/ui/sync/sync_promo_ui.h"
80 #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
81 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
82 #include "chrome/common/chrome_constants.h"
83 #include "chrome/common/chrome_paths.h"
84 #include "chrome/common/chrome_switches.h"
85 #include "chrome/common/env_vars.h"
86 #include "chrome/common/logging_chrome.h"
87 #include "chrome/common/pepper_permission_util.h"
88 #include "chrome/common/pref_names.h"
89 #include "chrome/common/render_messages.h"
90 #include "chrome/common/url_constants.h"
91 #include "chrome/grit/generated_resources.h"
92 #include "chrome/installer/util/google_update_settings.h"
93 #include "chromeos/chromeos_constants.h"
94 #include "components/cdm/browser/cdm_message_filter_android.h"
95 #include "components/cloud_devices/common/cloud_devices_switches.h"
96 #include "components/content_settings/core/browser/content_settings_provider.h"
97 #include "components/content_settings/core/browser/content_settings_utils.h"
98 #include "components/content_settings/core/browser/host_content_settings_map.h"
99 #include "components/content_settings/core/common/content_settings.h"
100 #include "components/content_settings/core/common/permission_request_id.h"
101 #include "components/dom_distiller/core/url_constants.h"
102 #include "components/google/core/browser/google_util.h"
103 #include "components/metrics/client_info.h"
104 #include "components/pref_registry/pref_registry_syncable.h"
105 #include "components/signin/core/common/profile_management_switches.h"
106 #include "components/translate/core/common/translate_switches.h"
107 #include "content/public/browser/browser_child_process_host.h"
108 #include "content/public/browser/browser_main_parts.h"
109 #include "content/public/browser/browser_ppapi_host.h"
110 #include "content/public/browser/browser_thread.h"
111 #include "content/public/browser/browser_url_handler.h"
112 #include "content/public/browser/child_process_data.h"
113 #include "content/public/browser/child_process_security_policy.h"
114 #include "content/public/browser/permission_type.h"
115 #include "content/public/browser/render_frame_host.h"
116 #include "content/public/browser/render_process_host.h"
117 #include "content/public/browser/render_view_host.h"
118 #include "content/public/browser/resource_context.h"
119 #include "content/public/browser/site_instance.h"
120 #include "content/public/browser/web_contents.h"
121 #include "content/public/common/child_process_host.h"
122 #include "content/public/common/content_descriptors.h"
123 #include "content/public/common/url_utils.h"
124 #include "content/public/common/web_preferences.h"
125 #include "gin/public/isolate_holder.h"
126 #include "net/base/mime_util.h"
127 #include "net/cookies/canonical_cookie.h"
128 #include "net/cookies/cookie_options.h"
129 #include "net/ssl/ssl_cert_request_info.h"
130 #include "ppapi/host/ppapi_host.h"
131 #include "storage/browser/fileapi/external_mount_points.h"
132 #include "ui/base/l10n/l10n_util.h"
133 #include "ui/base/resource/resource_bundle.h"
134 #include "ui/resources/grit/ui_resources.h"
137 #include "base/win/windows_version.h"
138 #include "chrome/browser/chrome_browser_main_win.h"
139 #include "sandbox/win/src/sandbox_policy.h"
140 #elif defined(OS_MACOSX)
141 #include "chrome/browser/chrome_browser_main_mac.h"
142 #include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
143 #include "components/crash/app/breakpad_mac.h"
144 #elif defined(OS_CHROMEOS)
145 #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
146 #include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h"
147 #include "chrome/browser/chromeos/file_manager/app_id.h"
148 #include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
149 #include "chrome/browser/chromeos/fileapi/file_system_backend.h"
150 #include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
151 #include "chrome/browser/chromeos/login/startup_utils.h"
152 #include "chrome/browser/chromeos/system/input_device_settings.h"
153 #include "chromeos/chromeos_switches.h"
154 #include "components/user_manager/user_manager.h"
155 #elif defined(OS_LINUX)
156 #include "chrome/browser/chrome_browser_main_linux.h"
157 #elif defined(OS_ANDROID)
158 #include "chrome/browser/android/new_tab_page_url_handler.h"
159 #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
160 #include "chrome/browser/chrome_browser_main_android.h"
161 #include "chrome/common/descriptors_android.h"
162 #include "components/crash/browser/crash_dump_manager_android.h"
163 #elif defined(OS_POSIX)
164 #include "chrome/browser/chrome_browser_main_posix.h"
167 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
168 #include "chrome/browser/media/protected_media_identifier_permission_context.h"
169 #include "chrome/browser/media/protected_media_identifier_permission_context_factory.h"
172 #if defined(OS_POSIX) && !defined(OS_MACOSX)
173 #include "base/debug/leak_annotations.h"
174 #include "components/crash/app/breakpad_linux.h"
175 #include "components/crash/browser/crash_handler_host_linux.h"
178 #if defined(OS_ANDROID)
179 #include "ui/base/ui_base_paths.h"
180 #include "ui/gfx/android/device_display_info.h"
183 #if defined(OS_ANDROID)
184 #include "chrome/browser/android/dev_tools_manager_delegate_android.h"
186 #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
189 #if !defined(OS_CHROMEOS)
190 #include "chrome/browser/signin/chrome_signin_client.h"
191 #include "chrome/browser/signin/chrome_signin_client_factory.h"
192 #include "chrome/browser/signin/signin_manager_factory.h"
193 #include "components/signin/core/browser/signin_manager.h"
196 #if defined(TOOLKIT_VIEWS)
197 #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
201 #include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
204 #if defined(USE_AURA)
205 #include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
209 #include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
212 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
213 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
216 #if !defined(DISABLE_NACL)
217 #include "components/nacl/browser/nacl_browser.h"
218 #include "components/nacl/browser/nacl_host_message_filter.h"
219 #include "components/nacl/browser/nacl_process_host.h"
220 #include "components/nacl/common/nacl_process_type.h"
221 #include "components/nacl/common/nacl_switches.h"
224 #if defined(ENABLE_EXTENSIONS)
225 #include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
226 #include "chrome/browser/extensions/extension_util.h"
227 #include "chrome/browser/media/cast_transport_host_filter.h"
228 #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
229 #include "extensions/browser/extension_registry.h"
230 #include "extensions/browser/guest_view/guest_view_base.h"
231 #include "extensions/browser/guest_view/guest_view_manager.h"
232 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
233 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
234 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
235 #include "extensions/common/constants.h"
236 #include "extensions/common/extension.h"
237 #include "extensions/common/extension_set.h"
238 #include "extensions/common/manifest_handlers/background_info.h"
239 #include "extensions/common/manifest_handlers/shared_module_info.h"
240 #include "extensions/common/permissions/permissions_data.h"
241 #include "extensions/common/permissions/socket_permission.h"
242 #include "extensions/common/switches.h"
245 #if defined(ENABLE_PLUGINS)
246 #include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
249 #if defined(ENABLE_SPELLCHECK)
250 #include "chrome/browser/spellchecker/spellcheck_message_filter.h"
253 #if defined(ENABLE_WEBRTC)
254 #include "chrome/browser/media/webrtc_logging_handler_host.h"
257 using base::FileDescriptor
;
258 using blink::WebWindowFeatures
;
259 using content::AccessTokenStore
;
260 using content::BrowserThread
;
261 using content::BrowserURLHandler
;
262 using content::ChildProcessSecurityPolicy
;
263 using content::QuotaPermissionContext
;
264 using content::RenderFrameHost
;
265 using content::RenderViewHost
;
266 using content::ResourceType
;
267 using content::SiteInstance
;
268 using content::WebContents
;
269 using content::WebPreferences
;
270 using message_center::NotifierId
;
272 #if defined(OS_POSIX)
273 using content::FileDescriptorInfo
;
276 #if defined(ENABLE_EXTENSIONS)
277 using extensions::APIPermission
;
278 using extensions::ChromeContentBrowserClientExtensionsPart
;
279 using extensions::Extension
;
280 using extensions::InfoMap
;
281 using extensions::Manifest
;
284 #if defined(ENABLE_PLUGINS)
285 using plugins::ChromeContentBrowserClientPluginsPart
;
290 // Cached version of the locale so we can return the locale on the I/O
292 base::LazyInstance
<std::string
> g_io_thread_application_locale
;
294 #if defined(ENABLE_PLUGINS)
295 // TODO(teravest): Add renderer-side API-specific checking for these APIs so
296 // that blanket permission isn't granted to all dev channel APIs for these.
297 // http://crbug.com/386743
298 const char* const kPredefinedAllowedDevChannelOrigins
[] = {
299 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/383937
300 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/383937
303 const char* const kPredefinedAllowedFileHandleOrigins
[] = {
304 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
305 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
308 const char* const kPredefinedAllowedSocketOrigins
[] = {
309 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
310 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
311 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
312 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
313 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
314 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
315 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
316 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
317 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
318 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
319 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
320 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
321 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
322 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
323 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
324 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
325 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
326 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
327 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
328 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
332 // Returns a copy of the given url with its host set to given host and path set
333 // to given path. Other parts of the url will be the same.
334 GURL
ReplaceURLHostAndPath(const GURL
& url
,
335 const std::string
& host
,
336 const std::string
& path
) {
337 url::Replacements
<char> replacements
;
338 replacements
.SetHost(host
.c_str(), url::Component(0, host
.length()));
339 replacements
.SetPath(path
.c_str(), url::Component(0, path
.length()));
340 return url
.ReplaceComponents(replacements
);
343 // Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
344 GURL
AddUberHost(const GURL
& url
) {
345 const std::string uber_host
= chrome::kChromeUIUberHost
;
346 const std::string new_path
= url
.host() + url
.path();
348 return ReplaceURLHostAndPath(url
, uber_host
, new_path
);
351 // If url->host() is "chrome" and url->path() has characters other than the
352 // first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
353 // returns true. Otherwise returns false.
354 bool RemoveUberHost(GURL
* url
) {
355 if (url
->host() != chrome::kChromeUIUberHost
)
358 if (url
->path().empty() || url
->path() == "/")
361 const std::string old_path
= url
->path();
363 const std::string::size_type separator
= old_path
.find('/', 1);
364 std::string new_host
;
365 std::string new_path
;
366 if (separator
== std::string::npos
) {
367 new_host
= old_path
.substr(1);
369 new_host
= old_path
.substr(1, separator
- 1);
370 new_path
= old_path
.substr(separator
);
373 // Do not allow URLs with paths empty before the first slash since we can't
374 // have an empty host. (e.g "foo://chrome//")
375 if (new_host
.empty())
378 *url
= ReplaceURLHostAndPath(*url
, new_host
, new_path
);
380 DCHECK(url
->is_valid());
385 // Handles rewriting Web UI URLs.
386 bool HandleWebUI(GURL
* url
, content::BrowserContext
* browser_context
) {
387 // Do not handle special URLs such as "about:foo"
388 if (!url
->host().empty()) {
389 const GURL chrome_url
= AddUberHost(*url
);
391 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
393 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
394 browser_context
, chrome_url
))
398 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
399 browser_context
, *url
))
402 #if defined(OS_CHROMEOS)
403 // Special case : in ChromeOS in Guest mode bookmarks and history are
404 // disabled for security reasons. New tab page explains the reasons, so
405 // we redirect user to new tab page.
406 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
407 if (url
->SchemeIs(content::kChromeUIScheme
) &&
408 (url
->DomainIs(chrome::kChromeUIBookmarksHost
) ||
409 url
->DomainIs(chrome::kChromeUIHistoryHost
))) {
410 // Rewrite with new tab URL
411 *url
= GURL(chrome::kChromeUINewTabURL
);
419 // Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
421 bool HandleWebUIReverse(GURL
* url
, content::BrowserContext
* browser_context
) {
422 if (!url
->is_valid() || !url
->SchemeIs(content::kChromeUIScheme
))
425 return RemoveUberHost(url
);
428 bool CertMatchesFilter(const net::X509Certificate
& cert
,
429 const base::DictionaryValue
& filter
) {
430 // TODO(markusheintz): This is the minimal required filter implementation.
431 // Implement a better matcher.
433 // An empty filter matches any client certificate since no requirements are
438 std::string common_name
;
439 if (filter
.GetString("ISSUER.CN", &common_name
) &&
440 (cert
.issuer().common_name
== common_name
)) {
446 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
447 breakpad::CrashHandlerHostLinux
* CreateCrashHandlerHost(
448 const std::string
& process_type
) {
449 base::FilePath dumps_path
;
450 PathService::Get(chrome::DIR_CRASH_DUMPS
, &dumps_path
);
452 ANNOTATE_SCOPED_MEMORY_LEAK
;
453 bool upload
= (getenv(env_vars::kHeadless
) == NULL
);
454 breakpad::CrashHandlerHostLinux
* crash_handler
=
455 new breakpad::CrashHandlerHostLinux(process_type
, dumps_path
, upload
);
456 crash_handler
->StartUploaderThread();
457 return crash_handler
;
461 int GetCrashSignalFD(const base::CommandLine
& command_line
) {
462 // Extensions have the same process type as renderers.
463 if (command_line
.HasSwitch(extensions::switches::kExtensionProcess
)) {
464 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
466 crash_handler
= CreateCrashHandlerHost("extension");
467 return crash_handler
->GetDeathSignalSocket();
470 std::string process_type
=
471 command_line
.GetSwitchValueASCII(switches::kProcessType
);
473 if (process_type
== switches::kRendererProcess
) {
474 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
476 crash_handler
= CreateCrashHandlerHost(process_type
);
477 return crash_handler
->GetDeathSignalSocket();
480 if (process_type
== switches::kPluginProcess
) {
481 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
483 crash_handler
= CreateCrashHandlerHost(process_type
);
484 return crash_handler
->GetDeathSignalSocket();
487 if (process_type
== switches::kPpapiPluginProcess
) {
488 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
490 crash_handler
= CreateCrashHandlerHost(process_type
);
491 return crash_handler
->GetDeathSignalSocket();
494 if (process_type
== switches::kGpuProcess
) {
495 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
497 crash_handler
= CreateCrashHandlerHost(process_type
);
498 return crash_handler
->GetDeathSignalSocket();
503 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
505 #if !defined(OS_CHROMEOS)
506 GURL
GetEffectiveURLForSignin(const GURL
& url
) {
507 CHECK(SigninManager::IsWebBasedSigninFlowURL(url
));
509 GURL
effective_url(SigninManager::kChromeSigninEffectiveSite
);
510 // Copy the path because the argument to SetPathStr must outlive
511 // the Replacements object.
512 const std::string
path_copy(url
.path());
513 GURL::Replacements replacements
;
514 replacements
.SetPathStr(path_copy
);
515 effective_url
= effective_url
.ReplaceComponents(replacements
);
516 return effective_url
;
520 void SetApplicationLocaleOnIOThread(const std::string
& locale
) {
521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
522 g_io_thread_application_locale
.Get() = locale
;
525 void HandleBlockedPopupOnUIThread(const BlockedWindowParams
& params
) {
526 // TODO(jochen): This code path should use RenderFrameHosts. See
527 // http://crbug.com/431769 for details.
528 RenderViewHost
* render_view_host
=
529 RenderViewHost::FromID(params
.render_process_id(), params
.opener_id());
530 if (!render_view_host
)
532 WebContents
* tab
= WebContents::FromRenderViewHost(render_view_host
);
533 // The tab might already have navigated away.
534 if (!tab
|| tab
->GetRenderViewHost() != render_view_host
)
537 prerender::PrerenderContents
* prerender_contents
=
538 prerender::PrerenderContents::FromWebContents(tab
);
539 if (prerender_contents
) {
540 prerender_contents
->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW
);
544 PopupBlockerTabHelper
* popup_helper
=
545 PopupBlockerTabHelper::FromWebContents(tab
);
548 popup_helper
->AddBlockedPopup(params
);
551 #if defined(OS_ANDROID)
553 void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams
& params
) {
554 WebContents
* web_contents
=
555 tab_util::GetWebContentsByID(params
.render_process_id(),
560 SingleTabModeTabHelper::FromWebContents(web_contents
)->HandleOpenUrl(params
);
563 float GetDeviceScaleAdjustment() {
564 static const float kMinFSM
= 1.05f
;
565 static const int kWidthForMinFSM
= 320;
566 static const float kMaxFSM
= 1.3f
;
567 static const int kWidthForMaxFSM
= 800;
569 gfx::DeviceDisplayInfo info
;
570 int minWidth
= info
.GetSmallestDIPWidth();
572 if (minWidth
<= kWidthForMinFSM
)
574 if (minWidth
>= kWidthForMaxFSM
)
577 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
578 float ratio
= static_cast<float>(minWidth
- kWidthForMinFSM
) /
579 (kWidthForMaxFSM
- kWidthForMinFSM
);
580 return ratio
* (kMaxFSM
- kMinFSM
) + kMinFSM
;
583 #endif // defined(OS_ANDROID)
585 #if defined(ENABLE_EXTENSIONS)
586 // By default, JavaScript and images are enabled in guest content.
587 void GetGuestViewDefaultContentSettingRules(
589 RendererContentSettingRules
* rules
) {
590 rules
->image_rules
.push_back(
591 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
592 ContentSettingsPattern::Wildcard(),
593 CONTENT_SETTING_ALLOW
,
597 rules
->script_rules
.push_back(
598 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
599 ContentSettingsPattern::Wildcard(),
600 CONTENT_SETTING_ALLOW
,
604 #endif // defined(ENALBE_EXTENSIONS)
606 content::PermissionStatus
607 ContentSettingToPermissionStatus(ContentSetting setting
) {
609 case CONTENT_SETTING_ALLOW
:
610 case CONTENT_SETTING_SESSION_ONLY
:
611 return content::PERMISSION_STATUS_GRANTED
;
612 case CONTENT_SETTING_BLOCK
:
613 return content::PERMISSION_STATUS_DENIED
;
614 case CONTENT_SETTING_ASK
:
615 return content::PERMISSION_STATUS_ASK
;
616 case CONTENT_SETTING_DETECT_IMPORTANT_CONTENT
:
617 case CONTENT_SETTING_DEFAULT
:
618 case CONTENT_SETTING_NUM_SETTINGS
:
622 return content::PERMISSION_STATUS_DENIED
;
625 PermissionContextBase
* GetPermissionContext(Profile
* profile
,
626 content::PermissionType permission
) {
627 switch (permission
) {
628 case content::PERMISSION_MIDI_SYSEX
:
629 return MidiPermissionContextFactory::GetForProfile(profile
);
630 case content::PERMISSION_NOTIFICATIONS
:
631 #if defined(ENABLE_NOTIFICATIONS)
632 return DesktopNotificationServiceFactory::GetForProfile(profile
);
636 case content::PERMISSION_GEOLOCATION
:
637 return GeolocationPermissionContextFactory::GetForProfile(profile
);
638 case content::PERMISSION_PROTECTED_MEDIA_IDENTIFIER
:
639 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
640 return ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(
646 case content::PERMISSION_PUSH_MESSAGING
:
647 return gcm::PushMessagingPermissionContextFactory::GetForProfile(profile
);
648 case content::PERMISSION_NUM
:
649 NOTREACHED() << "Invalid RequestPermission for " << permission
;
659 ChromeContentBrowserClient::ChromeContentBrowserClient()
660 : prerender_tracker_(NULL
),
661 weak_factory_(this) {
662 #if defined(ENABLE_PLUGINS)
663 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedDevChannelOrigins
); ++i
)
664 allowed_dev_channel_origins_
.insert(kPredefinedAllowedDevChannelOrigins
[i
]);
665 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedFileHandleOrigins
); ++i
)
666 allowed_file_handle_origins_
.insert(kPredefinedAllowedFileHandleOrigins
[i
]);
667 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedSocketOrigins
); ++i
)
668 allowed_socket_origins_
.insert(kPredefinedAllowedSocketOrigins
[i
]);
670 extra_parts_
.push_back(new ChromeContentBrowserClientPluginsPart
);
673 #if !defined(OS_ANDROID)
674 TtsExtensionEngine
* tts_extension_engine
= TtsExtensionEngine::GetInstance();
675 TtsController::GetInstance()->SetTtsEngineDelegate(tts_extension_engine
);
678 #if defined(ENABLE_EXTENSIONS)
679 extra_parts_
.push_back(new ChromeContentBrowserClientExtensionsPart
);
683 ChromeContentBrowserClient::~ChromeContentBrowserClient() {
684 for (int i
= static_cast<int>(extra_parts_
.size()) - 1; i
>= 0; --i
)
685 delete extra_parts_
[i
];
686 extra_parts_
.clear();
690 void ChromeContentBrowserClient::RegisterProfilePrefs(
691 user_prefs::PrefRegistrySyncable
* registry
) {
692 registry
->RegisterBooleanPref(
693 prefs::kDisable3DAPIs
,
695 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
696 registry
->RegisterBooleanPref(
697 prefs::kEnableHyperlinkAuditing
,
699 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
700 registry
->RegisterListPref(
701 prefs::kEnableDeprecatedWebPlatformFeatures
,
702 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
706 void ChromeContentBrowserClient::SetApplicationLocale(
707 const std::string
& locale
) {
708 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
710 // This object is guaranteed to outlive all threads so we don't have to
711 // worry about the lack of refcounting and can just post as Unretained.
713 // The common case is that this function is called early in Chrome startup
714 // before any threads are created (it will also be called later if the user
715 // changes the pref). In this case, there will be no threads created and
716 // posting will fail. When there are no threads, we can just set the string
717 // without worrying about threadsafety.
718 if (!BrowserThread::PostTask(BrowserThread::IO
, FROM_HERE
,
719 base::Bind(&SetApplicationLocaleOnIOThread
, locale
))) {
720 g_io_thread_application_locale
.Get() = locale
;
724 content::BrowserMainParts
* ChromeContentBrowserClient::CreateBrowserMainParts(
725 const content::MainFunctionParams
& parameters
) {
726 ChromeBrowserMainParts
* main_parts
;
727 // Construct the Main browser parts based on the OS type.
729 main_parts
= new ChromeBrowserMainPartsWin(parameters
);
730 #elif defined(OS_MACOSX)
731 main_parts
= new ChromeBrowserMainPartsMac(parameters
);
732 #elif defined(OS_CHROMEOS)
733 main_parts
= new chromeos::ChromeBrowserMainPartsChromeos(parameters
);
734 #elif defined(OS_LINUX)
735 main_parts
= new ChromeBrowserMainPartsLinux(parameters
);
736 #elif defined(OS_ANDROID)
737 main_parts
= new ChromeBrowserMainPartsAndroid(parameters
);
738 #elif defined(OS_POSIX)
739 main_parts
= new ChromeBrowserMainPartsPosix(parameters
);
742 main_parts
= new ChromeBrowserMainParts(parameters
);
745 chrome::AddProfilesExtraParts(main_parts
);
747 // Construct additional browser parts. Stages are called in the order in
748 // which they are added.
749 #if defined(TOOLKIT_VIEWS)
750 main_parts
->AddParts(new ChromeBrowserMainExtraPartsViews());
753 // TODO(oshima): Athena on chrome currently requires USE_ASH to build.
754 // We should reduce the dependency as much as possible.
756 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAsh());
759 #if defined(USE_AURA)
760 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAura());
764 main_parts
->AddParts(new ChromeBrowserMainExtraPartsX11());
767 chrome::AddMetricsExtraParts(main_parts
);
772 std::string
ChromeContentBrowserClient::GetStoragePartitionIdForSite(
773 content::BrowserContext
* browser_context
,
775 std::string partition_id
;
777 // The partition ID for webview guest processes is the string value of its
778 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
779 if (site
.SchemeIs(content::kGuestScheme
)) {
780 partition_id
= site
.spec();
781 } else if (site
.GetOrigin().spec() == kChromeUIChromeSigninURL
&&
782 !switches::IsEnableWebviewBasedSignin()) {
783 // Chrome signin page has an embedded iframe of extension and web content,
784 // thus it must be isolated from other webUI pages.
785 partition_id
= site
.GetOrigin().spec();
788 DCHECK(IsValidStoragePartitionId(browser_context
, partition_id
));
792 bool ChromeContentBrowserClient::IsValidStoragePartitionId(
793 content::BrowserContext
* browser_context
,
794 const std::string
& partition_id
) {
795 // The default ID is empty and is always valid.
796 if (partition_id
.empty())
799 return GURL(partition_id
).is_valid();
802 void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
803 content::BrowserContext
* browser_context
,
806 std::string
* partition_domain
,
807 std::string
* partition_name
,
809 // Default to the browser-wide storage partition and override based on |site|
811 partition_domain
->clear();
812 partition_name
->clear();
815 bool success
= false;
816 #if defined(ENABLE_EXTENSIONS)
817 success
= extensions::WebViewGuest::GetGuestPartitionConfigForSite(
818 site
, partition_domain
, partition_name
, in_memory
);
820 if (!success
&& site
.SchemeIs(extensions::kExtensionScheme
)) {
821 // If |can_be_default| is false, the caller is stating that the |site|
822 // should be parsed as if it had isolated storage. In particular it is
823 // important to NOT check ExtensionService for the is_storage_isolated()
824 // attribute because this code path is run during Extension uninstall
825 // to do cleanup after the Extension has already been unloaded from the
827 bool is_isolated
= !can_be_default
;
828 if (can_be_default
) {
829 if (extensions::util::SiteHasIsolatedStorage(site
, browser_context
))
834 CHECK(site
.has_host());
835 // For extensions with isolated storage, the the host of the |site| is
836 // the |partition_domain|. The |in_memory| and |partition_name| are only
837 // used in guest schemes so they are cleared here.
838 *partition_domain
= site
.host();
840 partition_name
->clear();
846 if (!success
&& (site
.GetOrigin().spec() == kChromeUIChromeSigninURL
) &&
847 !switches::IsEnableWebviewBasedSignin()) {
848 // Chrome signin page has an embedded iframe of extension and web content,
849 // thus it must be isolated from other webUI pages.
850 *partition_domain
= chrome::kChromeUIChromeSigninHost
;
853 // Assert that if |can_be_default| is false, the code above must have found a
854 // non-default partition. If this fails, the caller has a serious logic
855 // error about which StoragePartition they expect to be in and it is not
857 CHECK(can_be_default
|| !partition_domain
->empty());
860 content::WebContentsViewDelegate
*
861 ChromeContentBrowserClient::GetWebContentsViewDelegate(
862 content::WebContents
* web_contents
) {
863 return chrome::CreateWebContentsViewDelegate(web_contents
);
866 void ChromeContentBrowserClient::RenderProcessWillLaunch(
867 content::RenderProcessHost
* host
) {
868 int id
= host
->GetID();
869 Profile
* profile
= Profile::FromBrowserContext(host
->GetBrowserContext());
870 net::URLRequestContextGetter
* context
=
871 profile
->GetRequestContextForRenderProcess(id
);
873 host
->AddFilter(new ChromeRenderMessageFilter(id
, profile
));
874 #if defined(ENABLE_EXTENSIONS)
875 host
->AddFilter(new cast::CastTransportHostFilter
);
877 #if defined(ENABLE_PRINTING)
878 host
->AddFilter(new printing::PrintingMessageFilter(id
, profile
));
880 host
->AddFilter(new SearchProviderInstallStateMessageFilter(id
, profile
));
881 #if defined(ENABLE_SPELLCHECK)
882 host
->AddFilter(new SpellCheckMessageFilter(id
));
884 #if defined(OS_MACOSX)
885 host
->AddFilter(new SpellCheckMessageFilterMac(id
));
887 host
->AddFilter(new ChromeNetBenchmarkingMessageFilter(profile
, context
));
888 host
->AddFilter(new prerender::PrerenderMessageFilter(id
, profile
));
889 host
->AddFilter(new TtsMessageFilter(id
, host
->GetBrowserContext()));
890 #if defined(ENABLE_WEBRTC)
891 WebRtcLoggingHandlerHost
* webrtc_logging_handler_host
=
892 new WebRtcLoggingHandlerHost(profile
);
893 host
->SetWebRtcLogMessageCallback(base::Bind(
894 &WebRtcLoggingHandlerHost::LogMessage
, webrtc_logging_handler_host
));
895 host
->AddFilter(webrtc_logging_handler_host
);
896 host
->SetUserData(host
, new base::UserDataAdapter
<WebRtcLoggingHandlerHost
>(
897 webrtc_logging_handler_host
));
899 #if !defined(DISABLE_NACL)
900 host
->AddFilter(new nacl::NaClHostMessageFilter(
901 id
, profile
->IsOffTheRecord(),
905 #if defined(OS_ANDROID)
906 host
->AddFilter(new cdm::CdmMessageFilterAndroid());
908 if (switches::IsEnableAccountConsistency())
909 host
->AddFilter(new PrincipalsMessageFilter(id
));
911 host
->Send(new ChromeViewMsg_SetIsIncognitoProcess(
912 profile
->IsOffTheRecord()));
914 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
915 extra_parts_
[i
]->RenderProcessWillLaunch(host
);
917 RendererContentSettingRules rules
;
918 if (host
->IsIsolatedGuest()) {
919 #if defined(ENABLE_EXTENSIONS)
920 GetGuestViewDefaultContentSettingRules(profile
->IsOffTheRecord(), &rules
);
925 GetRendererContentSettingRules(
926 profile
->GetHostContentSettingsMap(), &rules
);
928 host
->Send(new ChromeViewMsg_SetContentSettingRules(rules
));
931 GURL
ChromeContentBrowserClient::GetEffectiveURL(
932 content::BrowserContext
* browser_context
, const GURL
& url
) {
933 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
937 // If the input |url| should be assigned to the Instant renderer, make its
938 // effective URL distinct from other URLs on the search provider's domain.
939 if (chrome::ShouldAssignURLToInstantRenderer(url
, profile
))
940 return chrome::GetEffectiveURLForInstant(url
, profile
);
942 #if !defined(OS_CHROMEOS)
943 // If the input |url| should be assigned to the Signin renderer, make its
944 // effective URL distinct from other URLs on the signin service's domain.
945 // Note that the signin renderer will be allowed to sign the user in to
947 if (SigninManager::IsWebBasedSigninFlowURL(url
))
948 return GetEffectiveURLForSignin(url
);
951 #if defined(ENABLE_EXTENSIONS)
952 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(
959 bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
960 content::BrowserContext
* browser_context
, const GURL
& effective_url
) {
961 // Non-extension, non-Instant URLs should generally use
962 // process-per-site-instance. Because we expect to use the effective URL,
963 // URLs for hosted apps (apart from bookmark apps) should have an extension
966 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
970 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url
, profile
))
973 #if !defined(OS_CHROMEOS)
974 if (SigninManager::IsWebBasedSigninFlowURL(effective_url
))
978 #if defined(ENABLE_EXTENSIONS)
979 return ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
980 profile
, effective_url
);
986 // These are treated as WebUI schemes but do not get WebUI bindings. Also,
987 // view-source is allowed for these schemes.
988 void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
989 std::vector
<std::string
>* additional_schemes
) {
990 additional_schemes
->push_back(chrome::kChromeSearchScheme
);
991 additional_schemes
->push_back(dom_distiller::kDomDistillerScheme
);
994 void ChromeContentBrowserClient::GetAdditionalWebUIHostsToIgnoreParititionCheck(
995 std::vector
<std::string
>* hosts
) {
996 hosts
->push_back(chrome::kChromeUIExtensionIconHost
);
997 hosts
->push_back(chrome::kChromeUIFaviconHost
);
998 hosts
->push_back(chrome::kChromeUIThemeHost
);
999 hosts
->push_back(chrome::kChromeUIThumbnailHost
);
1000 hosts
->push_back(chrome::kChromeUIThumbnailHost2
);
1001 hosts
->push_back(chrome::kChromeUIThumbnailListHost
);
1004 net::URLRequestContextGetter
*
1005 ChromeContentBrowserClient::CreateRequestContext(
1006 content::BrowserContext
* browser_context
,
1007 content::ProtocolHandlerMap
* protocol_handlers
,
1008 content::URLRequestInterceptorScopedVector request_interceptors
) {
1009 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1010 return profile
->CreateRequestContext(protocol_handlers
,
1011 request_interceptors
.Pass());
1014 net::URLRequestContextGetter
*
1015 ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
1016 content::BrowserContext
* browser_context
,
1017 const base::FilePath
& partition_path
,
1019 content::ProtocolHandlerMap
* protocol_handlers
,
1020 content::URLRequestInterceptorScopedVector request_interceptors
) {
1021 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1022 return profile
->CreateRequestContextForStoragePartition(
1026 request_interceptors
.Pass());
1029 bool ChromeContentBrowserClient::IsHandledURL(const GURL
& url
) {
1030 return ProfileIOData::IsHandledURL(url
);
1033 bool ChromeContentBrowserClient::CanCommitURL(
1034 content::RenderProcessHost
* process_host
,
1036 #if defined(ENABLE_EXTENSIONS)
1037 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(
1044 bool ChromeContentBrowserClient::ShouldAllowOpenURL(
1045 content::SiteInstance
* site_instance
, const GURL
& url
) {
1046 GURL from_url
= site_instance
->GetSiteURL();
1048 #if defined(ENABLE_EXTENSIONS)
1050 if (ChromeContentBrowserClientExtensionsPart::ShouldAllowOpenURL(
1051 site_instance
, from_url
, url
, &result
))
1055 // Do not allow chrome://chrome-signin navigate to other chrome:// URLs, since
1056 // the signin page may host untrusted web content.
1057 if (from_url
.GetOrigin().spec() == chrome::kChromeUIChromeSigninURL
&&
1058 url
.SchemeIs(content::kChromeUIScheme
) &&
1059 url
.host() != chrome::kChromeUIChromeSigninHost
) {
1060 VLOG(1) << "Blocked navigation to " << url
.spec() << " from "
1061 << chrome::kChromeUIChromeSigninURL
;
1068 bool ChromeContentBrowserClient::IsSuitableHost(
1069 content::RenderProcessHost
* process_host
,
1070 const GURL
& site_url
) {
1072 Profile::FromBrowserContext(process_host
->GetBrowserContext());
1073 // This may be NULL during tests. In that case, just assume any site can
1078 // Instant URLs should only be in the instant process and instant process
1079 // should only have Instant URLs.
1080 InstantService
* instant_service
=
1081 InstantServiceFactory::GetForProfile(profile
);
1082 if (instant_service
) {
1083 bool is_instant_process
= instant_service
->IsInstantProcess(
1084 process_host
->GetID());
1085 bool should_be_in_instant_process
=
1086 chrome::ShouldAssignURLToInstantRenderer(site_url
, profile
);
1087 if (is_instant_process
|| should_be_in_instant_process
)
1088 return is_instant_process
&& should_be_in_instant_process
;
1091 #if !defined(OS_CHROMEOS)
1092 SigninClient
* signin_client
=
1093 ChromeSigninClientFactory::GetForProfile(profile
);
1094 if (signin_client
&& signin_client
->IsSigninProcess(process_host
->GetID()))
1095 return SigninManager::IsWebBasedSigninFlowURL(site_url
);
1098 #if defined(ENABLE_EXTENSIONS)
1099 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1100 profile
, process_host
, site_url
);
1106 bool ChromeContentBrowserClient::MayReuseHost(
1107 content::RenderProcessHost
* process_host
) {
1108 // If there is currently a prerender in progress for the host provided,
1109 // it may not be shared. We require prerenders to be by themselves in a
1110 // separate process, so that we can monitor their resource usage, and so that
1111 // we can track the cookies that they change.
1112 Profile
* profile
= Profile::FromBrowserContext(
1113 process_host
->GetBrowserContext());
1114 prerender::PrerenderManager
* prerender_manager
=
1115 prerender::PrerenderManagerFactory::GetForProfile(profile
);
1116 if (prerender_manager
&&
1117 !prerender_manager
->MayReuseProcessHost(process_host
)) {
1124 bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1125 content::BrowserContext
* browser_context
, const GURL
& url
) {
1126 // It has to be a valid URL for us to check for an extension.
1127 if (!url
.is_valid())
1130 #if defined(ENABLE_EXTENSIONS)
1131 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1132 return ChromeContentBrowserClientExtensionsPart::
1133 ShouldTryToUseExistingProcessHost(
1140 void ChromeContentBrowserClient::SiteInstanceGotProcess(
1141 SiteInstance
* site_instance
) {
1142 CHECK(site_instance
->HasProcess());
1144 Profile
* profile
= Profile::FromBrowserContext(
1145 site_instance
->GetBrowserContext());
1149 // Remember the ID of the Instant process to signal the renderer process
1150 // on startup in |AppendExtraCommandLineSwitches| below.
1151 if (chrome::ShouldAssignURLToInstantRenderer(
1152 site_instance
->GetSiteURL(), profile
)) {
1153 InstantService
* instant_service
=
1154 InstantServiceFactory::GetForProfile(profile
);
1155 if (instant_service
)
1156 instant_service
->AddInstantProcess(site_instance
->GetProcess()->GetID());
1159 #if !defined(OS_CHROMEOS)
1160 // We only expect there to be one signin process as we use process-per-site
1161 // for signin URLs. The signin process will be cleared from SigninManager
1162 // when the renderer is destroyed.
1163 if (SigninManager::IsWebBasedSigninFlowURL(site_instance
->GetSiteURL())) {
1164 SigninClient
* signin_client
=
1165 ChromeSigninClientFactory::GetForProfile(profile
);
1167 signin_client
->SetSigninProcess(site_instance
->GetProcess()->GetID());
1168 #if defined(ENABLE_EXTENSIONS)
1169 ChromeContentBrowserClientExtensionsPart::SetSigninProcess(site_instance
);
1174 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
1175 extra_parts_
[i
]->SiteInstanceGotProcess(site_instance
);
1178 void ChromeContentBrowserClient::SiteInstanceDeleting(
1179 SiteInstance
* site_instance
) {
1180 if (!site_instance
->HasProcess())
1183 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
1184 extra_parts_
[i
]->SiteInstanceDeleting(site_instance
);
1187 bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
1188 SiteInstance
* site_instance
,
1189 const GURL
& current_url
,
1190 const GURL
& new_url
) {
1191 #if defined(ENABLE_EXTENSIONS)
1192 return ChromeContentBrowserClientExtensionsPart::
1193 ShouldSwapBrowsingInstancesForNavigation(
1194 site_instance
, current_url
, new_url
);
1200 bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1201 content::ResourceContext
* resource_context
, const GURL
& current_url
,
1202 const GURL
& new_url
) {
1203 #if defined(ENABLE_EXTENSIONS)
1204 return ChromeContentBrowserClientExtensionsPart::
1205 ShouldSwapProcessesForRedirect(resource_context
, current_url
, new_url
);
1211 bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL
& url
) {
1212 return !url
.SchemeIs(chrome::kChromeNativeScheme
);
1215 std::string
ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1216 const std::string
& alias_name
) {
1217 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name
);
1222 bool IsAutoReloadEnabled() {
1223 // Fetch the field trial, even though we don't use it. Calling FindFullName()
1224 // causes the field-trial mechanism to report which group we're in, which
1225 // might reflect a hard disable or hard enable via flag, both of which have
1226 // their own field trial groups. This lets us know what percentage of users
1227 // manually enable or disable auto-reload.
1228 std::string group
= base::FieldTrialList::FindFullName(
1229 "AutoReloadExperiment");
1230 const base::CommandLine
& browser_command_line
=
1231 *base::CommandLine::ForCurrentProcess();
1232 if (browser_command_line
.HasSwitch(switches::kEnableOfflineAutoReload
))
1234 if (browser_command_line
.HasSwitch(switches::kDisableOfflineAutoReload
))
1239 bool IsAutoReloadVisibleOnlyEnabled() {
1240 // See the block comment in IsAutoReloadEnabled().
1241 std::string group
= base::FieldTrialList::FindFullName(
1242 "AutoReloadVisibleOnlyExperiment");
1243 const base::CommandLine
& browser_command_line
=
1244 *base::CommandLine::ForCurrentProcess();
1245 if (browser_command_line
.HasSwitch(
1246 switches::kEnableOfflineAutoReloadVisibleOnly
)) {
1249 if (browser_command_line
.HasSwitch(
1250 switches::kDisableOfflineAutoReloadVisibleOnly
)) {
1258 void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1259 base::CommandLine
* command_line
,
1260 int child_process_id
) {
1261 #if defined(OS_POSIX)
1262 if (breakpad::IsCrashReporterEnabled()) {
1263 scoped_ptr
<metrics::ClientInfo
> client_info
=
1264 GoogleUpdateSettings::LoadMetricsClientInfo();
1265 command_line
->AppendSwitchASCII(switches::kEnableCrashReporter
,
1266 client_info
? client_info
->client_id
1269 #endif // defined(OS_POSIX)
1271 if (logging::DialogsAreSuppressed())
1272 command_line
->AppendSwitch(switches::kNoErrorDialogs
);
1274 std::string process_type
=
1275 command_line
->GetSwitchValueASCII(switches::kProcessType
);
1276 const base::CommandLine
& browser_command_line
=
1277 *base::CommandLine::ForCurrentProcess();
1279 static const char* const kCommonSwitchNames
[] = {
1280 switches::kUserAgent
,
1281 switches::kUserDataDir
, // Make logs go to the right file.
1283 command_line
->CopySwitchesFrom(browser_command_line
, kCommonSwitchNames
,
1284 arraysize(kCommonSwitchNames
));
1286 #if defined(ENABLE_IPC_FUZZER)
1287 static const char* const kIpcFuzzerSwitches
[] = {
1288 switches::kIpcFuzzerTestcase
,
1290 command_line
->CopySwitchesFrom(browser_command_line
, kIpcFuzzerSwitches
,
1291 arraysize(kIpcFuzzerSwitches
));
1294 #if defined(OS_CHROMEOS)
1295 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
1296 base::FilePath homedir
;
1297 PathService::Get(base::DIR_HOME
, &homedir
);
1298 command_line
->AppendSwitchASCII(chromeos::switches::kHomedir
,
1299 homedir
.value().c_str());
1302 if (process_type
== switches::kRendererProcess
) {
1303 content::RenderProcessHost
* process
=
1304 content::RenderProcessHost::FromID(child_process_id
);
1306 process
? Profile::FromBrowserContext(process
->GetBrowserContext())
1308 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
1309 extra_parts_
[i
]->AppendExtraRendererCommandLineSwitches(
1310 command_line
, process
, profile
);
1313 #if defined(OS_CHROMEOS)
1314 const std::string
& login_profile
=
1315 browser_command_line
.GetSwitchValueASCII(
1316 chromeos::switches::kLoginProfile
);
1317 if (!login_profile
.empty())
1318 command_line
->AppendSwitchASCII(
1319 chromeos::switches::kLoginProfile
, login_profile
);
1322 #if defined(ENABLE_WEBRTC)
1323 MaybeCopyDisableWebRtcEncryptionSwitch(command_line
,
1324 browser_command_line
,
1325 VersionInfo::GetChannel());
1329 PrefService
* prefs
= profile
->GetPrefs();
1330 // Currently this pref is only registered if applied via a policy.
1331 if (prefs
->HasPrefPath(prefs::kDisable3DAPIs
) &&
1332 prefs
->GetBoolean(prefs::kDisable3DAPIs
)) {
1333 // Turn this policy into a command line switch.
1334 command_line
->AppendSwitch(switches::kDisable3DAPIs
);
1337 const base::ListValue
* switches
=
1338 prefs
->GetList(prefs::kEnableDeprecatedWebPlatformFeatures
);
1340 // Enable any deprecated features that have been re-enabled by policy.
1341 for (base::ListValue::const_iterator it
= switches
->begin();
1342 it
!= switches
->end(); ++it
) {
1343 std::string switch_to_enable
;
1344 if ((*it
)->GetAsString(&switch_to_enable
))
1345 command_line
->AppendSwitch(switch_to_enable
);
1349 // Disable client-side phishing detection in the renderer if it is
1350 // disabled in the Profile preferences or the browser process.
1351 if (!prefs
->GetBoolean(prefs::kSafeBrowsingEnabled
) ||
1352 !g_browser_process
->safe_browsing_detection_service()) {
1353 command_line
->AppendSwitch(
1354 switches::kDisableClientSidePhishingDetection
);
1357 if (prefs
->GetBoolean(prefs::kPrintPreviewDisabled
))
1358 command_line
->AppendSwitch(switches::kDisablePrintPreview
);
1360 InstantService
* instant_service
=
1361 InstantServiceFactory::GetForProfile(profile
);
1362 if (instant_service
&&
1363 instant_service
->IsInstantProcess(process
->GetID()))
1364 command_line
->AppendSwitch(switches::kInstantProcess
);
1366 #if !defined(OS_CHROMEOS)
1367 SigninClient
* signin_client
=
1368 ChromeSigninClientFactory::GetForProfile(profile
);
1369 if (signin_client
&& signin_client
->IsSigninProcess(process
->GetID()))
1370 command_line
->AppendSwitch(switches::kSigninProcess
);
1374 if (IsAutoReloadEnabled())
1375 command_line
->AppendSwitch(switches::kEnableOfflineAutoReload
);
1376 if (IsAutoReloadVisibleOnlyEnabled()) {
1377 command_line
->AppendSwitch(
1378 switches::kEnableOfflineAutoReloadVisibleOnly
);
1382 // Enable load stale cache if this session is in the field trial or
1383 // the user explicitly enabled it. Note that as far as the renderer
1384 // is concerned, the feature is enabled if-and-only-if the
1385 // kEnableOfflineLoadStaleCache flag is on the command line;
1386 // the yes/no/default behavior is only at the browser command line
1389 // Command line switches override
1390 if (browser_command_line
.HasSwitch(
1391 switches::kEnableOfflineLoadStaleCache
)) {
1392 command_line
->AppendSwitch(switches::kEnableOfflineLoadStaleCache
);
1393 } else if (!browser_command_line
.HasSwitch(
1394 switches::kDisableOfflineLoadStaleCache
)) {
1396 base::FieldTrialList::FindFullName("LoadStaleCacheExperiment");
1398 if (group
== "Enabled")
1399 command_line
->AppendSwitch(switches::kEnableOfflineLoadStaleCache
);
1403 // Please keep this in alphabetical order.
1404 static const char* const kSwitchNames
[] = {
1405 autofill::switches::kDisableFillOnAccountSelect
,
1406 autofill::switches::kDisablePasswordGeneration
,
1407 autofill::switches::kEnableFillOnAccountSelect
,
1408 autofill::switches::kEnableFillOnAccountSelectNoHighlighting
,
1409 autofill::switches::kEnablePasswordGeneration
,
1410 autofill::switches::kEnablePasswordSaveOnInPageNavigation
,
1411 autofill::switches::kEnableSingleClickAutofill
,
1412 autofill::switches::kIgnoreAutocompleteOffForAutofill
,
1413 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration
,
1414 autofill::switches::kRespectAutocompleteOffForAutofill
,
1415 #if defined(ENABLE_EXTENSIONS)
1416 extensions::switches::kAllowHTTPBackgroundPage
,
1417 extensions::switches::kAllowLegacyExtensionManifests
,
1418 extensions::switches::kEnableSurfaceWorker
,
1419 extensions::switches::kEnableAppWindowControls
,
1420 extensions::switches::kEnableEmbeddedExtensionOptions
,
1421 extensions::switches::kEnableExperimentalExtensionApis
,
1422 extensions::switches::kEnableScriptsRequireAction
,
1423 extensions::switches::kExtensionsOnChromeURLs
,
1424 extensions::switches::kWhitelistedExtensionID
,
1426 switches::kAppsCheckoutURL
,
1427 switches::kAppsGalleryURL
,
1428 switches::kCloudPrintURL
,
1429 switches::kCloudPrintXmppEndpoint
,
1430 switches::kDisableBundledPpapiFlash
,
1431 switches::kDisableCastStreamingHWEncoding
,
1432 switches::kDisableJavaScriptHarmonyShipping
,
1433 switches::kDisableOutOfProcessPdf
,
1434 switches::kEnableBenchmarking
,
1435 switches::kEnableNaCl
,
1436 #if !defined(DISABLE_NACL)
1437 switches::kEnableNaClDebug
,
1438 switches::kEnableNaClNonSfiMode
,
1440 switches::kEnableNetBenchmarking
,
1441 switches::kEnableNewBookmarkApps
,
1442 switches::kEnableOutOfProcessPdf
,
1443 switches::kEnablePluginPlaceholderShadowDom
,
1444 switches::kEnableShowModalDialog
,
1445 switches::kEnableWebBasedSignin
,
1446 switches::kJavaScriptHarmony
,
1447 switches::kMessageLoopHistogrammer
,
1448 switches::kPlaybackMode
,
1449 switches::kPpapiFlashArgs
,
1450 switches::kPpapiFlashPath
,
1451 switches::kPpapiFlashVersion
,
1452 switches::kProfilingAtStart
,
1453 switches::kProfilingFile
,
1454 switches::kProfilingFlush
,
1455 switches::kRecordMode
,
1456 translate::switches::kTranslateSecurityOrigin
,
1459 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1460 arraysize(kSwitchNames
));
1461 } else if (process_type
== switches::kUtilityProcess
) {
1462 #if defined(ENABLE_EXTENSIONS)
1463 static const char* const kSwitchNames
[] = {
1464 extensions::switches::kAllowHTTPBackgroundPage
,
1465 extensions::switches::kEnableExperimentalExtensionApis
,
1466 extensions::switches::kExtensionsOnChromeURLs
,
1467 extensions::switches::kWhitelistedExtensionID
,
1470 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1471 arraysize(kSwitchNames
));
1473 } else if (process_type
== switches::kPluginProcess
) {
1474 #if defined(OS_CHROMEOS)
1475 static const char* const kSwitchNames
[] = {
1476 chromeos::switches::kLoginProfile
,
1479 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1480 arraysize(kSwitchNames
));
1482 } else if (process_type
== switches::kZygoteProcess
) {
1483 static const char* const kSwitchNames
[] = {
1484 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
1485 switches::kDisableBundledPpapiFlash
,
1486 #if !defined(DISABLE_NACL)
1487 switches::kEnableNaClDebug
,
1488 switches::kEnableNaClNonSfiMode
,
1489 switches::kNaClDangerousNoSandboxNonSfi
,
1490 switches::kUseNaClHelperNonSfi
,
1492 switches::kPpapiFlashPath
,
1493 switches::kPpapiFlashVersion
,
1496 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1497 arraysize(kSwitchNames
));
1498 } else if (process_type
== switches::kGpuProcess
) {
1499 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1500 // because GPU is expected to be unreliable.
1501 if (browser_command_line
.HasSwitch(switches::kIgnoreGpuBlacklist
) &&
1502 !command_line
->HasSwitch(switches::kDisableBreakpad
))
1503 command_line
->AppendSwitch(switches::kDisableBreakpad
);
1506 // The command line switch kEnableBenchmarking needs to be specified along
1507 // with the kEnableStatsTable switch to ensure that the stats table global
1508 // is initialized correctly.
1509 if (command_line
->HasSwitch(switches::kEnableBenchmarking
))
1510 DCHECK(command_line
->HasSwitch(switches::kEnableStatsTable
));
1513 std::string
ChromeContentBrowserClient::GetApplicationLocale() {
1514 if (BrowserThread::CurrentlyOn(BrowserThread::IO
))
1515 return g_io_thread_application_locale
.Get();
1516 return g_browser_process
->GetApplicationLocale();
1519 std::string
ChromeContentBrowserClient::GetAcceptLangs(
1520 content::BrowserContext
* context
) {
1521 Profile
* profile
= Profile::FromBrowserContext(context
);
1522 return profile
->GetPrefs()->GetString(prefs::kAcceptLanguages
);
1525 const gfx::ImageSkia
* ChromeContentBrowserClient::GetDefaultFavicon() {
1526 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
1527 return rb
.GetNativeImageNamed(IDR_DEFAULT_FAVICON
).ToImageSkia();
1530 bool ChromeContentBrowserClient::AllowAppCache(
1531 const GURL
& manifest_url
,
1532 const GURL
& first_party
,
1533 content::ResourceContext
* context
) {
1534 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1535 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1536 return io_data
->GetCookieSettings()->
1537 IsSettingCookieAllowed(manifest_url
, first_party
);
1540 bool ChromeContentBrowserClient::AllowServiceWorker(
1542 const GURL
& first_party_url
,
1543 content::ResourceContext
* context
) {
1544 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1545 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1546 return io_data
->GetCookieSettings()->
1547 IsSettingCookieAllowed(scope
, first_party_url
);
1550 bool ChromeContentBrowserClient::AllowGetCookie(
1552 const GURL
& first_party
,
1553 const net::CookieList
& cookie_list
,
1554 content::ResourceContext
* context
,
1555 int render_process_id
,
1556 int render_frame_id
) {
1557 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1558 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1559 bool allow
= io_data
->GetCookieSettings()->
1560 IsReadingCookieAllowed(url
, first_party
);
1562 BrowserThread::PostTask(
1563 BrowserThread::UI
, FROM_HERE
,
1564 base::Bind(&TabSpecificContentSettings::CookiesRead
, render_process_id
,
1565 render_frame_id
, url
, first_party
, cookie_list
, !allow
, true));
1569 bool ChromeContentBrowserClient::AllowSetCookie(
1571 const GURL
& first_party
,
1572 const std::string
& cookie_line
,
1573 content::ResourceContext
* context
,
1574 int render_process_id
,
1575 int render_frame_id
,
1576 net::CookieOptions
* options
) {
1577 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1578 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1579 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1580 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, first_party
);
1582 if (prerender_tracker_
) {
1583 prerender_tracker_
->OnCookieChangedForURL(
1585 context
->GetRequestContext()->cookie_store()->GetCookieMonster(),
1589 BrowserThread::PostTask(
1590 BrowserThread::UI
, FROM_HERE
,
1591 base::Bind(&TabSpecificContentSettings::CookieChanged
, render_process_id
,
1592 render_frame_id
, url
, first_party
, cookie_line
, *options
,
1597 bool ChromeContentBrowserClient::AllowSaveLocalState(
1598 content::ResourceContext
* context
) {
1599 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1600 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1601 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1602 ContentSetting setting
= cookie_settings
->GetDefaultCookieSetting(NULL
);
1604 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1605 // Could we even support per-origin settings?
1606 return setting
!= CONTENT_SETTING_SESSION_ONLY
;
1609 bool ChromeContentBrowserClient::AllowWorkerDatabase(
1611 const base::string16
& name
,
1612 const base::string16
& display_name
,
1613 unsigned long estimated_size
,
1614 content::ResourceContext
* context
,
1615 const std::vector
<std::pair
<int, int> >& render_frames
) {
1616 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1617 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1618 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1619 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1621 // Record access to database for potential display in UI.
1622 std::vector
<std::pair
<int, int> >::const_iterator i
;
1623 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1624 BrowserThread::PostTask(
1625 BrowserThread::UI
, FROM_HERE
,
1626 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed
,
1627 i
->first
, i
->second
, url
, name
, display_name
, !allow
));
1633 void ChromeContentBrowserClient::AllowWorkerFileSystem(
1635 content::ResourceContext
* context
,
1636 const std::vector
<std::pair
<int, int> >& render_frames
,
1637 base::Callback
<void(bool)> callback
) {
1638 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1639 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1640 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1641 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1643 #if defined(ENABLE_EXTENSIONS)
1644 GuestPermissionRequestHelper(url
, render_frames
, callback
, allow
);
1646 FileSystemAccessed(url
, render_frames
, callback
, allow
);
1650 #if defined(ENABLE_EXTENSIONS)
1651 void ChromeContentBrowserClient::GuestPermissionRequestHelper(
1653 const std::vector
<std::pair
<int, int> >& render_frames
,
1654 base::Callback
<void(bool)> callback
,
1656 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::IO
));
1657 std::vector
<std::pair
<int, int> >::const_iterator i
;
1658 std::map
<int, int> process_map
;
1659 std::map
<int, int>::const_iterator it
;
1660 bool has_web_view_guest
= false;
1661 // Record access to file system for potential display in UI.
1662 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1663 if (process_map
.find(i
->first
) != process_map
.end())
1666 process_map
.insert(std::pair
<int, int>(i
->first
, i
->second
));
1668 if (extensions::WebViewRendererState::GetInstance()->IsGuest(i
->first
))
1669 has_web_view_guest
= true;
1671 if (!has_web_view_guest
) {
1672 FileSystemAccessed(url
, render_frames
, callback
, allow
);
1675 DCHECK_EQ(1U, process_map
.size());
1676 it
= process_map
.begin();
1677 BrowserThread::PostTask(
1680 base::Bind(&ChromeContentBrowserClient::
1681 RequestFileSystemPermissionOnUIThread
,
1686 base::Bind(&ChromeContentBrowserClient::FileSystemAccessed
,
1687 weak_factory_
.GetWeakPtr(),
1693 void ChromeContentBrowserClient::RequestFileSystemPermissionOnUIThread(
1694 int render_process_id
,
1695 int render_frame_id
,
1697 bool allowed_by_default
,
1698 const base::Callback
<void(bool)>& callback
) {
1699 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::UI
));
1700 extensions::WebViewPermissionHelper
* web_view_permission_helper
=
1701 extensions::WebViewPermissionHelper::FromFrameID(
1702 render_process_id
, render_frame_id
);
1703 web_view_permission_helper
->RequestFileSystemPermission(url
,
1709 void ChromeContentBrowserClient::FileSystemAccessed(
1711 const std::vector
<std::pair
<int, int> >& render_frames
,
1712 base::Callback
<void(bool)> callback
,
1714 // Record access to file system for potential display in UI.
1715 std::vector
<std::pair
<int, int> >::const_iterator i
;
1716 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1717 BrowserThread::PostTask(
1720 base::Bind(&TabSpecificContentSettings::FileSystemAccessed
,
1721 i
->first
, i
->second
, url
, !allow
));
1723 callback
.Run(allow
);
1726 bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1728 const base::string16
& name
,
1729 content::ResourceContext
* context
,
1730 const std::vector
<std::pair
<int, int> >& render_frames
) {
1731 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1732 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1733 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1734 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1736 // Record access to IndexedDB for potential display in UI.
1737 std::vector
<std::pair
<int, int> >::const_iterator i
;
1738 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1739 BrowserThread::PostTask(
1740 BrowserThread::UI
, FROM_HERE
,
1741 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed
,
1742 i
->first
, i
->second
, url
, name
, !allow
));
1748 net::URLRequestContext
*
1749 ChromeContentBrowserClient::OverrideRequestContextForURL(
1750 const GURL
& url
, content::ResourceContext
* context
) {
1751 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1752 #if defined(ENABLE_EXTENSIONS)
1753 if (url
.SchemeIs(extensions::kExtensionScheme
)) {
1754 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1755 return io_data
->extensions_request_context();
1762 QuotaPermissionContext
*
1763 ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1764 return new ChromeQuotaPermissionContext();
1767 void ChromeContentBrowserClient::AllowCertificateError(
1768 int render_process_id
,
1769 int render_frame_id
,
1771 const net::SSLInfo
& ssl_info
,
1772 const GURL
& request_url
,
1773 ResourceType resource_type
,
1775 bool strict_enforcement
,
1776 bool expired_previous_decision
,
1777 const base::Callback
<void(bool)>& callback
,
1778 content::CertificateRequestResultType
* result
) {
1779 if (resource_type
!= content::RESOURCE_TYPE_MAIN_FRAME
) {
1780 // A sub-resource has a certificate error. The user doesn't really
1781 // have a context for making the right decision, so block the
1782 // request hard, without an info bar to allow showing the insecure
1784 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY
;
1788 // If the tab is being prerendered, cancel the prerender and the request.
1789 content::RenderFrameHost
* render_frame_host
=
1790 content::RenderFrameHost::FromID(render_process_id
, render_frame_id
);
1791 WebContents
* tab
= WebContents::FromRenderFrameHost(render_frame_host
);
1797 prerender::PrerenderContents
* prerender_contents
=
1798 prerender::PrerenderContents::FromWebContents(tab
);
1799 if (prerender_contents
) {
1800 prerender_contents
->Destroy(prerender::FINAL_STATUS_SSL_ERROR
);
1801 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL
;
1805 // Otherwise, display an SSL blocking page. The interstitial page takes
1806 // ownership of ssl_blocking_page.
1807 int options_mask
= 0;
1809 options_mask
|= SSLBlockingPage::OVERRIDABLE
;
1810 if (strict_enforcement
)
1811 options_mask
|= SSLBlockingPage::STRICT_ENFORCEMENT
;
1812 if (expired_previous_decision
)
1813 options_mask
|= SSLBlockingPage::EXPIRED_BUT_PREVIOUSLY_ALLOWED
;
1815 SSLErrorHandler::HandleSSLError(
1816 tab
, cert_error
, ssl_info
, request_url
, options_mask
, callback
);
1819 void ChromeContentBrowserClient::SelectClientCertificate(
1820 int render_process_id
,
1821 int render_frame_id
,
1822 net::SSLCertRequestInfo
* cert_request_info
,
1823 const base::Callback
<void(net::X509Certificate
*)>& callback
) {
1824 content::RenderFrameHost
* rfh
= content::RenderFrameHost::FromID(
1825 render_process_id
, render_frame_id
);
1826 WebContents
* tab
= WebContents::FromRenderFrameHost(rfh
);
1828 // TODO(davidben): This makes the request hang, but returning no certificate
1829 // also breaks. It should abort the request. See https://crbug.com/417092
1833 prerender::PrerenderContents
* prerender_contents
=
1834 prerender::PrerenderContents::FromWebContents(tab
);
1835 if (prerender_contents
) {
1836 prerender_contents
->Destroy(
1837 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED
);
1841 GURL
requesting_url("https://" + cert_request_info
->host_and_port
.ToString());
1842 DCHECK(requesting_url
.is_valid())
1843 << "Invalid URL string: https://"
1844 << cert_request_info
->host_and_port
.ToString();
1846 Profile
* profile
= Profile::FromBrowserContext(tab
->GetBrowserContext());
1847 scoped_ptr
<base::Value
> filter
=
1848 profile
->GetHostContentSettingsMap()->GetWebsiteSetting(
1851 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE
,
1856 // Try to automatically select a client certificate.
1857 if (filter
->IsType(base::Value::TYPE_DICTIONARY
)) {
1858 base::DictionaryValue
* filter_dict
=
1859 static_cast<base::DictionaryValue
*>(filter
.get());
1861 const std::vector
<scoped_refptr
<net::X509Certificate
> >&
1862 all_client_certs
= cert_request_info
->client_certs
;
1863 for (size_t i
= 0; i
< all_client_certs
.size(); ++i
) {
1864 if (CertMatchesFilter(*all_client_certs
[i
].get(), *filter_dict
)) {
1865 // Use the first certificate that is matched by the filter.
1866 callback
.Run(all_client_certs
[i
].get());
1875 chrome::ShowSSLClientCertificateSelector(tab
, cert_request_info
, callback
);
1878 void ChromeContentBrowserClient::AddCertificate(
1879 net::CertificateMimeType cert_type
,
1880 const void* cert_data
,
1882 int render_process_id
,
1883 int render_frame_id
) {
1884 chrome::SSLAddCertificate(cert_type
, cert_data
, cert_size
,
1885 render_process_id
, render_frame_id
);
1888 content::MediaObserver
* ChromeContentBrowserClient::GetMediaObserver() {
1889 return MediaCaptureDevicesDispatcher::GetInstance();
1892 content::PlatformNotificationService
*
1893 ChromeContentBrowserClient::GetPlatformNotificationService() {
1894 #if defined(ENABLE_NOTIFICATIONS)
1895 return PlatformNotificationServiceImpl::GetInstance();
1902 void ChromeContentBrowserClient::RequestPermission(
1903 content::PermissionType permission
,
1904 content::WebContents
* web_contents
,
1906 const GURL
& requesting_frame
,
1908 const base::Callback
<void(bool)>& result_callback
) {
1909 int render_process_id
= web_contents
->GetRenderProcessHost()->GetID();
1910 int render_view_id
= web_contents
->GetRenderViewHost()->GetRoutingID();
1912 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
1914 const PermissionRequestID
request_id(render_process_id
,
1919 switch (permission
) {
1920 case content::PERMISSION_MIDI_SYSEX
:
1921 MidiPermissionContextFactory::GetForProfile(profile
)
1922 ->RequestPermission(web_contents
,
1928 case content::PERMISSION_NOTIFICATIONS
:
1929 #if defined(ENABLE_NOTIFICATIONS)
1930 DesktopNotificationServiceFactory::GetForProfile(profile
)
1931 ->RequestNotificationPermission(web_contents
,
1940 case content::PERMISSION_GEOLOCATION
:
1941 GeolocationPermissionContextFactory::GetForProfile(profile
)
1942 ->RequestPermission(web_contents
,
1944 requesting_frame
.GetOrigin(),
1948 case content::PERMISSION_PROTECTED_MEDIA_IDENTIFIER
:
1949 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
1950 ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(profile
)
1951 ->RequestPermission(web_contents
,
1953 requesting_frame
.GetOrigin(),
1960 case content::PERMISSION_PUSH_MESSAGING
:
1961 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile
)
1962 ->RequestPermission(web_contents
,
1964 requesting_frame
.GetOrigin(),
1968 case content::PERMISSION_NUM
:
1969 NOTREACHED() << "Invalid RequestPermission for " << permission
;
1974 content::PermissionStatus
ChromeContentBrowserClient::GetPermissionStatus(
1975 content::PermissionType permission
,
1976 content::BrowserContext
* browser_context
,
1977 const GURL
& requesting_origin
,
1978 const GURL
& embedding_origin
) {
1979 DCHECK(browser_context
);
1980 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1981 PermissionContextBase
* context
= GetPermissionContext(profile
, permission
);
1984 return content::PERMISSION_STATUS_ASK
;
1986 return ContentSettingToPermissionStatus(
1987 context
->GetPermissionStatus(requesting_origin
.GetOrigin(),
1988 embedding_origin
.GetOrigin()));
1991 void ChromeContentBrowserClient::ResetPermission(
1992 content::PermissionType permission
,
1993 content::BrowserContext
* browser_context
,
1994 const GURL
& requesting_origin
,
1995 const GURL
& embedding_origin
) {
1996 DCHECK(browser_context
);
1997 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1998 PermissionContextBase
* context
= GetPermissionContext(profile
, permission
);
2003 context
->ResetPermission(requesting_origin
.GetOrigin(),
2004 embedding_origin
.GetOrigin());
2007 void ChromeContentBrowserClient::CancelPermissionRequest(
2008 content::PermissionType permission
,
2009 content::WebContents
* web_contents
,
2011 const GURL
& requesting_frame
) {
2012 int render_process_id
= web_contents
->GetRenderProcessHost()->GetID();
2013 int render_view_id
= web_contents
->GetRenderViewHost()->GetRoutingID();
2015 const PermissionRequestID
request_id(render_process_id
,
2020 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
2021 switch (permission
) {
2022 case content::PERMISSION_MIDI_SYSEX
:
2023 MidiPermissionContextFactory::GetForProfile(profile
)
2024 ->CancelPermissionRequest(web_contents
, request_id
);
2026 case content::PERMISSION_NOTIFICATIONS
:
2027 #if defined(ENABLE_NOTIFICATIONS)
2028 DesktopNotificationServiceFactory::GetForProfile(profile
)
2029 ->CancelPermissionRequest(web_contents
, request_id
);
2034 case content::PERMISSION_GEOLOCATION
:
2035 GeolocationPermissionContextFactory::GetForProfile(profile
)
2036 ->CancelPermissionRequest(web_contents
, request_id
);
2038 case content::PERMISSION_PROTECTED_MEDIA_IDENTIFIER
:
2039 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
2040 ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(profile
)
2041 ->CancelPermissionRequest(web_contents
, request_id
);
2046 case content::PERMISSION_PUSH_MESSAGING
:
2047 NOTIMPLEMENTED() << "CancelPermission not implemented for " << permission
;
2049 case content::PERMISSION_NUM
:
2050 NOTREACHED() << "Invalid CancelPermission for " << permission
;
2055 // Helper method to translate from Permissions to ContentSettings
2056 static ContentSettingsType
PermissionToContentSetting(
2057 content::PermissionType permission
) {
2058 switch (permission
) {
2059 case content::PERMISSION_MIDI_SYSEX
:
2060 return CONTENT_SETTINGS_TYPE_MIDI_SYSEX
;
2061 case content::PERMISSION_PUSH_MESSAGING
:
2062 return CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
;
2063 case content::PERMISSION_NOTIFICATIONS
:
2064 return CONTENT_SETTINGS_TYPE_NOTIFICATIONS
;
2065 case content::PERMISSION_GEOLOCATION
:
2066 return CONTENT_SETTINGS_TYPE_GEOLOCATION
;
2067 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
2068 case content::PERMISSION_PROTECTED_MEDIA_IDENTIFIER
:
2069 return CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER
;
2072 NOTREACHED() << "Unknown content setting for permission " << permission
;
2073 return CONTENT_SETTINGS_TYPE_DEFAULT
;
2077 void ChromeContentBrowserClient::RegisterPermissionUsage(
2078 content::PermissionType permission
,
2079 content::WebContents
* web_contents
,
2080 const GURL
& frame_url
,
2081 const GURL
& main_frame_url
) {
2082 Profile::FromBrowserContext(web_contents
->GetBrowserContext())
2083 ->GetHostContentSettingsMap()
2085 frame_url
, main_frame_url
, PermissionToContentSetting(permission
));
2088 bool ChromeContentBrowserClient::CanCreateWindow(
2089 const GURL
& opener_url
,
2090 const GURL
& opener_top_level_frame_url
,
2091 const GURL
& source_origin
,
2092 WindowContainerType container_type
,
2093 const GURL
& target_url
,
2094 const content::Referrer
& referrer
,
2095 WindowOpenDisposition disposition
,
2096 const WebWindowFeatures
& features
,
2098 bool opener_suppressed
,
2099 content::ResourceContext
* context
,
2100 int render_process_id
,
2102 bool* no_javascript_access
) {
2103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
2105 *no_javascript_access
= false;
2107 // If the opener is trying to create a background window but doesn't have
2108 // the appropriate permission, fail the attempt.
2109 if (container_type
== WINDOW_CONTAINER_TYPE_BACKGROUND
) {
2110 #if defined(ENABLE_EXTENSIONS)
2111 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
2112 InfoMap
* map
= io_data
->GetExtensionInfoMap();
2113 if (!map
->SecurityOriginHasAPIPermission(
2116 APIPermission::kBackground
)) {
2120 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2121 // return a recently installed Extension even if this CanCreateWindow call
2122 // was made by an old copy of the page in a normal web process. That's ok,
2123 // because the permission check above would have caused an early return
2124 // already. We must use the full URL to find hosted apps, though, and not
2126 const Extension
* extension
=
2127 map
->extensions().GetExtensionOrAppByURL(opener_url
);
2128 if (extension
&& !extensions::BackgroundInfo::AllowJSAccess(extension
))
2129 *no_javascript_access
= true;
2135 #if defined(ENABLE_EXTENSIONS)
2136 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
2141 HostContentSettingsMap
* content_settings
=
2142 ProfileIOData::FromResourceContext(context
)->GetHostContentSettingsMap();
2143 BlockedWindowParams
blocked_params(target_url
,
2152 if (!user_gesture
&&
2153 !base::CommandLine::ForCurrentProcess()->HasSwitch(
2154 switches::kDisablePopupBlocking
)) {
2155 if (content_settings
->GetContentSetting(opener_top_level_frame_url
,
2156 opener_top_level_frame_url
,
2157 CONTENT_SETTINGS_TYPE_POPUPS
,
2159 CONTENT_SETTING_ALLOW
) {
2160 BrowserThread::PostTask(BrowserThread::UI
,
2162 base::Bind(&HandleBlockedPopupOnUIThread
,
2168 #if defined(OS_ANDROID)
2169 if (SingleTabModeTabHelper::IsRegistered(render_process_id
, opener_id
)) {
2170 BrowserThread::PostTask(BrowserThread::UI
,
2172 base::Bind(&HandleSingleTabModeBlockOnUIThread
,
2181 void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
2183 prerender_tracker_
= g_browser_process
->prerender_tracker();
2184 return g_browser_process
->ResourceDispatcherHostCreated();
2187 content::SpeechRecognitionManagerDelegate
*
2188 ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
2189 return new speech::ChromeSpeechRecognitionManagerDelegate();
2192 net::NetLog
* ChromeContentBrowserClient::GetNetLog() {
2193 return g_browser_process
->net_log();
2196 AccessTokenStore
* ChromeContentBrowserClient::CreateAccessTokenStore() {
2197 return new ChromeAccessTokenStore();
2200 bool ChromeContentBrowserClient::IsFastShutdownPossible() {
2204 void ChromeContentBrowserClient::OverrideWebkitPrefs(
2205 RenderViewHost
* rvh
, const GURL
& url
, WebPreferences
* web_prefs
) {
2206 Profile
* profile
= Profile::FromBrowserContext(
2207 rvh
->GetProcess()->GetBrowserContext());
2208 PrefService
* prefs
= profile
->GetPrefs();
2210 // Fill per-script font preferences. These are not registered on Android
2211 // - http://crbug.com/308033.
2212 #if !defined(OS_ANDROID)
2213 FontFamilyCache::FillFontFamilyMap(profile
,
2214 prefs::kWebKitStandardFontFamilyMap
,
2215 &web_prefs
->standard_font_family_map
);
2216 FontFamilyCache::FillFontFamilyMap(profile
,
2217 prefs::kWebKitFixedFontFamilyMap
,
2218 &web_prefs
->fixed_font_family_map
);
2219 FontFamilyCache::FillFontFamilyMap(profile
,
2220 prefs::kWebKitSerifFontFamilyMap
,
2221 &web_prefs
->serif_font_family_map
);
2222 FontFamilyCache::FillFontFamilyMap(profile
,
2223 prefs::kWebKitSansSerifFontFamilyMap
,
2224 &web_prefs
->sans_serif_font_family_map
);
2225 FontFamilyCache::FillFontFamilyMap(profile
,
2226 prefs::kWebKitCursiveFontFamilyMap
,
2227 &web_prefs
->cursive_font_family_map
);
2228 FontFamilyCache::FillFontFamilyMap(profile
,
2229 prefs::kWebKitFantasyFontFamilyMap
,
2230 &web_prefs
->fantasy_font_family_map
);
2231 FontFamilyCache::FillFontFamilyMap(profile
,
2232 prefs::kWebKitPictographFontFamilyMap
,
2233 &web_prefs
->pictograph_font_family_map
);
2236 web_prefs
->default_font_size
=
2237 prefs
->GetInteger(prefs::kWebKitDefaultFontSize
);
2238 web_prefs
->default_fixed_font_size
=
2239 prefs
->GetInteger(prefs::kWebKitDefaultFixedFontSize
);
2240 web_prefs
->minimum_font_size
=
2241 prefs
->GetInteger(prefs::kWebKitMinimumFontSize
);
2242 web_prefs
->minimum_logical_font_size
=
2243 prefs
->GetInteger(prefs::kWebKitMinimumLogicalFontSize
);
2245 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2247 web_prefs
->javascript_can_open_windows_automatically
=
2248 prefs
->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically
);
2249 web_prefs
->dom_paste_enabled
=
2250 prefs
->GetBoolean(prefs::kWebKitDomPasteEnabled
);
2251 web_prefs
->shrinks_standalone_images_to_fit
=
2252 prefs
->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit
);
2253 web_prefs
->tabs_to_links
= prefs
->GetBoolean(prefs::kWebkitTabsToLinks
);
2255 if (!prefs
->GetBoolean(prefs::kWebKitJavascriptEnabled
))
2256 web_prefs
->javascript_enabled
= false;
2257 if (!prefs
->GetBoolean(prefs::kWebKitWebSecurityEnabled
))
2258 web_prefs
->web_security_enabled
= false;
2259 if (!prefs
->GetBoolean(prefs::kWebKitPluginsEnabled
))
2260 web_prefs
->plugins_enabled
= false;
2261 if (!prefs
->GetBoolean(prefs::kWebKitJavaEnabled
))
2262 web_prefs
->java_enabled
= false;
2263 web_prefs
->loads_images_automatically
=
2264 prefs
->GetBoolean(prefs::kWebKitLoadsImagesAutomatically
);
2266 if (prefs
->GetBoolean(prefs::kDisable3DAPIs
))
2267 web_prefs
->experimental_webgl_enabled
= false;
2269 web_prefs
->allow_displaying_insecure_content
=
2270 prefs
->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent
);
2271 web_prefs
->allow_running_insecure_content
=
2272 prefs
->GetBoolean(prefs::kWebKitAllowRunningInsecureContent
);
2273 #if defined(OS_ANDROID)
2274 web_prefs
->font_scale_factor
=
2275 static_cast<float>(prefs
->GetDouble(prefs::kWebKitFontScaleFactor
));
2276 web_prefs
->device_scale_adjustment
= GetDeviceScaleAdjustment();
2277 web_prefs
->force_enable_zoom
=
2278 prefs
->GetBoolean(prefs::kWebKitForceEnableZoom
);
2281 #if defined(OS_ANDROID)
2282 web_prefs
->password_echo_enabled
=
2283 prefs
->GetBoolean(prefs::kWebKitPasswordEchoEnabled
);
2285 web_prefs
->password_echo_enabled
= browser_defaults::kPasswordEchoEnabled
;
2288 web_prefs
->asynchronous_spell_checking_enabled
= true;
2289 web_prefs
->unified_textchecker_enabled
= true;
2291 web_prefs
->uses_universal_detector
=
2292 prefs
->GetBoolean(prefs::kWebKitUsesUniversalDetector
);
2293 web_prefs
->text_areas_are_resizable
=
2294 prefs
->GetBoolean(prefs::kWebKitTextAreasAreResizable
);
2295 web_prefs
->hyperlink_auditing_enabled
=
2296 prefs
->GetBoolean(prefs::kEnableHyperlinkAuditing
);
2298 // Make sure we will set the default_encoding with canonical encoding name.
2299 web_prefs
->default_encoding
=
2300 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
2301 web_prefs
->default_encoding
);
2302 if (web_prefs
->default_encoding
.empty()) {
2303 prefs
->ClearPref(prefs::kDefaultCharset
);
2304 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2306 DCHECK(!web_prefs
->default_encoding
.empty());
2308 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2309 switches::kEnablePotentiallyAnnoyingSecurityFeatures
)) {
2310 web_prefs
->disable_reading_from_canvas
= true;
2311 web_prefs
->strict_mixed_content_checking
= true;
2312 web_prefs
->strict_powerful_feature_restrictions
= true;
2315 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2316 extra_parts_
[i
]->OverrideWebkitPrefs(rvh
, url
, web_prefs
);
2319 void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2320 BrowserURLHandler
* handler
) {
2321 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2322 extra_parts_
[i
]->BrowserURLHandlerCreated(handler
);
2324 // about: handler. Must come before chrome: handler, since it will
2325 // rewrite about: urls to chrome: URLs and then expect chrome: to
2326 // actually handle them.
2327 handler
->AddHandlerPair(&WillHandleBrowserAboutURL
,
2328 BrowserURLHandler::null_handler());
2330 #if defined(OS_ANDROID)
2331 // Handler to rewrite chrome://newtab on Android.
2332 handler
->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL
,
2333 BrowserURLHandler::null_handler());
2335 // Handler to rewrite chrome://newtab for InstantExtended.
2336 handler
->AddHandlerPair(&chrome::HandleNewTabURLRewrite
,
2337 &chrome::HandleNewTabURLReverseRewrite
);
2340 // chrome: & friends.
2341 handler
->AddHandlerPair(&HandleWebUI
, &HandleWebUIReverse
);
2344 void ChromeContentBrowserClient::ClearCache(RenderViewHost
* rvh
) {
2345 Profile
* profile
= Profile::FromBrowserContext(
2346 rvh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2347 BrowsingDataRemover
* remover
=
2348 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2349 remover
->Remove(BrowsingDataRemover::REMOVE_CACHE
,
2350 BrowsingDataHelper::UNPROTECTED_WEB
);
2351 // BrowsingDataRemover takes care of deleting itself when done.
2354 void ChromeContentBrowserClient::ClearCookies(RenderViewHost
* rvh
) {
2355 Profile
* profile
= Profile::FromBrowserContext(
2356 rvh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2357 BrowsingDataRemover
* remover
=
2358 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2359 int remove_mask
= BrowsingDataRemover::REMOVE_SITE_DATA
;
2360 remover
->Remove(remove_mask
, BrowsingDataHelper::UNPROTECTED_WEB
);
2361 // BrowsingDataRemover takes care of deleting itself when done.
2364 base::FilePath
ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
2365 return DownloadPrefs::GetDefaultDownloadDirectory();
2368 std::string
ChromeContentBrowserClient::GetDefaultDownloadName() {
2369 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME
);
2372 void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2373 content::BrowserPpapiHost
* browser_host
) {
2374 #if defined(ENABLE_PLUGINS)
2375 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host
);
2379 content::BrowserPpapiHost
*
2380 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2381 int plugin_process_id
) {
2382 #if !defined(DISABLE_NACL)
2383 content::BrowserChildProcessHostIterator
iter(PROCESS_TYPE_NACL_LOADER
);
2384 while (!iter
.Done()) {
2385 nacl::NaClProcessHost
* host
= static_cast<nacl::NaClProcessHost
*>(
2386 iter
.GetDelegate());
2387 if (host
->process() &&
2388 host
->process()->GetData().id
== plugin_process_id
) {
2389 // Found the plugin.
2390 return host
->browser_ppapi_host();
2398 bool ChromeContentBrowserClient::AllowPepperSocketAPI(
2399 content::BrowserContext
* browser_context
,
2402 const content::SocketPermissionRequest
* params
) {
2403 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2404 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
2405 browser_context
, url
, private_api
, params
, allowed_socket_origins_
);
2411 ui::SelectFilePolicy
* ChromeContentBrowserClient::CreateSelectFilePolicy(
2412 WebContents
* web_contents
) {
2413 return new ChromeSelectFilePolicy(web_contents
);
2416 void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2417 std::vector
<std::string
>* additional_allowed_schemes
) {
2418 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2419 additional_allowed_schemes
);
2420 additional_allowed_schemes
->push_back(content::kChromeDevToolsScheme
);
2421 additional_allowed_schemes
->push_back(content::kChromeUIScheme
);
2422 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
2423 extra_parts_
[i
]->GetAdditionalAllowedSchemesForFileSystem(
2424 additional_allowed_schemes
);
2428 void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
2429 std::vector
<storage::URLRequestAutoMountHandler
>* handlers
) {
2430 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2431 extra_parts_
[i
]->GetURLRequestAutoMountHandlers(handlers
);
2434 void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
2435 content::BrowserContext
* browser_context
,
2436 const base::FilePath
& storage_partition_path
,
2437 ScopedVector
<storage::FileSystemBackend
>* additional_backends
) {
2438 #if defined(OS_CHROMEOS)
2439 storage::ExternalMountPoints
* external_mount_points
=
2440 content::BrowserContext::GetMountPoints(browser_context
);
2441 DCHECK(external_mount_points
);
2442 chromeos::FileSystemBackend
* backend
= new chromeos::FileSystemBackend(
2443 new drive::FileSystemBackendDelegate
,
2444 new chromeos::file_system_provider::BackendDelegate
,
2445 new chromeos::MTPFileSystemBackendDelegate(storage_partition_path
),
2446 browser_context
->GetSpecialStoragePolicy(),
2447 external_mount_points
,
2448 storage::ExternalMountPoints::GetSystemInstance());
2449 backend
->AddSystemMountPoints();
2450 DCHECK(backend
->CanHandleType(storage::kFileSystemTypeExternal
));
2451 additional_backends
->push_back(backend
);
2454 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
2455 extra_parts_
[i
]->GetAdditionalFileSystemBackends(
2456 browser_context
, storage_partition_path
, additional_backends
);
2460 #if defined(OS_POSIX) && !defined(OS_MACOSX)
2461 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2462 const base::CommandLine
& command_line
,
2463 int child_process_id
,
2464 FileDescriptorInfo
* mappings
) {
2465 #if defined(OS_ANDROID)
2466 base::FilePath data_path
;
2467 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID
, &data_path
);
2468 DCHECK(!data_path
.empty());
2470 int flags
= base::File::FLAG_OPEN
| base::File::FLAG_READ
;
2471 base::FilePath chrome_resources_pak
=
2472 data_path
.AppendASCII("chrome_100_percent.pak");
2473 base::File
file(chrome_resources_pak
, flags
);
2474 DCHECK(file
.IsValid());
2475 mappings
->Transfer(kAndroidChrome100PercentPakDescriptor
,
2476 base::ScopedFD(file
.TakePlatformFile()));
2478 const std::string locale
= GetApplicationLocale();
2479 base::FilePath locale_pak
= ResourceBundle::GetSharedInstance().
2480 GetLocaleFilePath(locale
, false);
2481 file
.Initialize(locale_pak
, flags
);
2482 DCHECK(file
.IsValid());
2483 mappings
->Transfer(kAndroidLocalePakDescriptor
,
2484 base::ScopedFD(file
.TakePlatformFile()));
2486 base::FilePath resources_pack_path
;
2487 PathService::Get(chrome::FILE_RESOURCES_PACK
, &resources_pack_path
);
2488 file
.Initialize(resources_pack_path
, flags
);
2489 DCHECK(file
.IsValid());
2490 mappings
->Transfer(kAndroidUIResourcesPakDescriptor
,
2491 base::ScopedFD(file
.TakePlatformFile()));
2493 if (breakpad::IsCrashReporterEnabled()) {
2494 file
= breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile(
2496 if (file
.IsValid()) {
2497 mappings
->Transfer(kAndroidMinidumpDescriptor
,
2498 base::ScopedFD(file
.TakePlatformFile()));
2500 LOG(ERROR
) << "Failed to create file for minidump, crash reporting will "
2501 "be disabled for this process.";
2505 base::FilePath app_data_path
;
2506 PathService::Get(base::DIR_ANDROID_APP_DATA
, &app_data_path
);
2507 DCHECK(!app_data_path
.empty());
2509 flags
= base::File::FLAG_OPEN
| base::File::FLAG_READ
;
2510 base::FilePath icudata_path
=
2511 app_data_path
.AppendASCII(base::i18n::kIcuDataFileName
);
2512 base::File
icudata_file(icudata_path
, flags
);
2513 DCHECK(icudata_file
.IsValid());
2514 mappings
->Transfer(kAndroidICUDataDescriptor
,
2515 base::ScopedFD(icudata_file
.TakePlatformFile()));
2517 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
2518 base::FilePath v8_data_path
;
2519 PathService::Get(base::DIR_ANDROID_APP_DATA
, &v8_data_path
);
2520 DCHECK(!v8_data_path
.empty());
2522 int file_flags
= base::File::FLAG_OPEN
| base::File::FLAG_READ
;
2523 base::FilePath v8_natives_data_path
=
2524 v8_data_path
.AppendASCII(gin::IsolateHolder::kNativesFileName
);
2525 base::FilePath v8_snapshot_data_path
=
2526 v8_data_path
.AppendASCII(gin::IsolateHolder::kSnapshotFileName
);
2527 base::File
v8_natives_data_file(v8_natives_data_path
, file_flags
);
2528 base::File
v8_snapshot_data_file(v8_snapshot_data_path
, file_flags
);
2529 DCHECK(v8_natives_data_file
.IsValid());
2530 DCHECK(v8_snapshot_data_file
.IsValid());
2531 mappings
->Transfer(kV8NativesDataDescriptor
,
2532 base::ScopedFD(v8_natives_data_file
.TakePlatformFile()));
2533 mappings
->Transfer(kV8SnapshotDataDescriptor
,
2534 base::ScopedFD(v8_snapshot_data_file
.TakePlatformFile()));
2535 #endif // V8_USE_EXTERNAL_STARTUP_DATA
2538 int crash_signal_fd
= GetCrashSignalFD(command_line
);
2539 if (crash_signal_fd
>= 0) {
2540 mappings
->Share(kCrashDumpSignal
, crash_signal_fd
);
2542 #endif // defined(OS_ANDROID)
2544 #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
2547 const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2548 return chrome::kBrowserResourcesDll
;
2551 void ChromeContentBrowserClient::PreSpawnRenderer(
2552 sandbox::TargetPolicy
* policy
,
2554 // This code is duplicated in nacl_exe_win_64.cc.
2555 // Allow the server side of a pipe restricted to the "chrome.nacl."
2556 // namespace so that it cannot impersonate other system or other chrome
2558 sandbox::ResultCode result
= policy
->AddRule(
2559 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES
,
2560 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY
,
2561 L
"\\\\.\\pipe\\chrome.nacl.*");
2562 if (result
!= sandbox::SBOX_ALL_OK
) {
2567 // Renderers need to send named pipe handles and shared memory
2568 // segment handles to NaCl loader processes.
2569 result
= policy
->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES
,
2570 sandbox::TargetPolicy::HANDLES_DUP_ANY
,
2572 if (result
!= sandbox::SBOX_ALL_OK
) {
2579 bool ChromeContentBrowserClient::CheckMediaAccessPermission(
2580 content::BrowserContext
* browser_context
,
2581 const GURL
& security_origin
,
2582 content::MediaStreamType type
) {
2583 return MediaCaptureDevicesDispatcher::GetInstance()
2584 ->CheckMediaAccessPermission(
2585 browser_context
, security_origin
, type
);
2588 content::WebContents
* ChromeContentBrowserClient::OpenURL(
2589 content::BrowserContext
* browser_context
,
2590 const content::OpenURLParams
& params
) {
2591 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
2593 #if !defined(OS_ANDROID) && !defined(OS_IOS)
2594 NavigateParams
nav_params(Profile::FromBrowserContext(browser_context
),
2597 FillNavigateParamsFromOpenURLParams(&nav_params
, params
);
2598 nav_params
.user_gesture
= params
.user_gesture
;
2600 Navigate(&nav_params
);
2601 return nav_params
.target_contents
;
2603 // TODO(mlamouri): write a chrome::Navigate() method for Android and iOS.
2604 // See https://crbug.com/448409.
2606 #endif // !defined(OS_ANDROID) && !defined(OS_IOS)
2609 content::DevToolsManagerDelegate
*
2610 ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
2611 #if defined(OS_ANDROID)
2612 return new DevToolsManagerDelegateAndroid();
2614 return new ChromeDevToolsManagerDelegate();
2618 bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2619 content::BrowserContext
* browser_context
,
2621 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2622 return ChromeContentBrowserClientPluginsPart::
2623 IsPluginAllowedToCallRequestOSFileHandle(browser_context
, url
,
2624 allowed_file_handle_origins_
);
2630 bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
2631 content::BrowserContext
* browser_context
,
2633 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2634 return ChromeContentBrowserClientPluginsPart::
2635 IsPluginAllowedToUseDevChannelAPIs(browser_context
, url
,
2636 allowed_dev_channel_origins_
);
2643 ChromeContentBrowserClient::OverrideCookieStoreForRenderProcess(
2644 int render_process_id
) {
2645 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
2646 if (!prerender_tracker_
)
2648 return prerender_tracker_
->GetPrerenderCookieStoreForRenderProcess(
2649 render_process_id
).get();
2652 void ChromeContentBrowserClient::OverridePageVisibilityState(
2653 RenderFrameHost
* render_frame_host
,
2654 blink::WebPageVisibilityState
* visibility_state
) {
2655 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
2657 WebContents
* web_contents
=
2658 WebContents::FromRenderFrameHost(render_frame_host
);
2659 DCHECK(web_contents
);
2662 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
2663 prerender::PrerenderManager
* prerender_manager
=
2664 prerender::PrerenderManagerFactory::GetForProfile(profile
);
2665 if (prerender_manager
&&
2666 prerender_manager
->IsWebContentsPrerendering(web_contents
, nullptr)) {
2667 *visibility_state
= blink::WebPageVisibilityStatePrerender
;
2671 #if defined(ENABLE_WEBRTC)
2672 void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
2673 base::CommandLine
* to_command_line
,
2674 const base::CommandLine
& from_command_line
,
2675 VersionInfo::Channel channel
) {
2676 #if defined(OS_ANDROID)
2677 const VersionInfo::Channel kMaxDisableEncryptionChannel
=
2678 VersionInfo::CHANNEL_BETA
;
2680 const VersionInfo::Channel kMaxDisableEncryptionChannel
=
2681 VersionInfo::CHANNEL_DEV
;
2683 if (channel
<= kMaxDisableEncryptionChannel
) {
2684 static const char* const kWebRtcDevSwitchNames
[] = {
2685 switches::kDisableWebRtcEncryption
,
2687 to_command_line
->CopySwitchesFrom(from_command_line
,
2688 kWebRtcDevSwitchNames
,
2689 arraysize(kWebRtcDevSwitchNames
));
2692 #endif // defined(ENABLE_WEBRTC)
2694 } // namespace chrome