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/metrics/rappor/sampling.h"
44 #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
45 #include "chrome/browser/net/chrome_net_log.h"
46 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
47 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h"
48 #include "chrome/browser/notifications/desktop_notification_service.h"
49 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
50 #include "chrome/browser/notifications/platform_notification_service_impl.h"
51 #include "chrome/browser/platform_util.h"
52 #include "chrome/browser/prerender/prerender_final_status.h"
53 #include "chrome/browser/prerender/prerender_manager.h"
54 #include "chrome/browser/prerender/prerender_manager_factory.h"
55 #include "chrome/browser/prerender/prerender_message_filter.h"
56 #include "chrome/browser/printing/printing_message_filter.h"
57 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
58 #include "chrome/browser/profiles/profile.h"
59 #include "chrome/browser/profiles/profile_io_data.h"
60 #include "chrome/browser/push_messaging/push_messaging_permission_context.h"
61 #include "chrome/browser/push_messaging/push_messaging_permission_context_factory.h"
62 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
63 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
64 #include "chrome/browser/search/instant_service.h"
65 #include "chrome/browser/search/instant_service_factory.h"
66 #include "chrome/browser/search/search.h"
67 #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
68 #include "chrome/browser/signin/principals_message_filter.h"
69 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
70 #include "chrome/browser/speech/tts_controller.h"
71 #include "chrome/browser/speech/tts_message_filter.h"
72 #include "chrome/browser/ssl/ssl_add_certificate.h"
73 #include "chrome/browser/ssl/ssl_blocking_page.h"
74 #include "chrome/browser/ssl/ssl_client_certificate_selector.h"
75 #include "chrome/browser/ssl/ssl_error_handler.h"
76 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
77 #include "chrome/browser/tab_contents/tab_util.h"
78 #include "chrome/browser/tracing/chrome_tracing_delegate.h"
79 #include "chrome/browser/ui/blocked_content/blocked_window_params.h"
80 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
81 #include "chrome/browser/ui/chrome_select_file_policy.h"
82 #include "chrome/browser/ui/sync/sync_promo_ui.h"
83 #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
84 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
85 #include "chrome/common/chrome_constants.h"
86 #include "chrome/common/chrome_paths.h"
87 #include "chrome/common/chrome_switches.h"
88 #include "chrome/common/env_vars.h"
89 #include "chrome/common/logging_chrome.h"
90 #include "chrome/common/pepper_permission_util.h"
91 #include "chrome/common/pref_names.h"
92 #include "chrome/common/render_messages.h"
93 #include "chrome/common/url_constants.h"
94 #include "chrome/grit/generated_resources.h"
95 #include "chrome/installer/util/google_update_settings.h"
96 #include "chromeos/chromeos_constants.h"
97 #include "components/cdm/browser/cdm_message_filter_android.h"
98 #include "components/cloud_devices/common/cloud_devices_switches.h"
99 #include "components/content_settings/core/browser/content_settings_provider.h"
100 #include "components/content_settings/core/browser/content_settings_utils.h"
101 #include "components/content_settings/core/browser/host_content_settings_map.h"
102 #include "components/content_settings/core/common/content_settings.h"
103 #include "components/content_settings/core/common/permission_request_id.h"
104 #include "components/data_reduction_proxy/content/browser/data_reduction_proxy_message_filter.h"
105 #include "components/dom_distiller/core/url_constants.h"
106 #include "components/google/core/browser/google_util.h"
107 #include "components/metrics/client_info.h"
108 #include "components/pref_registry/pref_registry_syncable.h"
109 #include "components/signin/core/common/profile_management_switches.h"
110 #include "components/translate/core/common/translate_switches.h"
111 #include "components/url_fixer/url_fixer.h"
112 #include "content/public/browser/browser_child_process_host.h"
113 #include "content/public/browser/browser_main_parts.h"
114 #include "content/public/browser/browser_ppapi_host.h"
115 #include "content/public/browser/browser_thread.h"
116 #include "content/public/browser/browser_url_handler.h"
117 #include "content/public/browser/child_process_data.h"
118 #include "content/public/browser/child_process_security_policy.h"
119 #include "content/public/browser/permission_type.h"
120 #include "content/public/browser/render_frame_host.h"
121 #include "content/public/browser/render_process_host.h"
122 #include "content/public/browser/render_view_host.h"
123 #include "content/public/browser/resource_context.h"
124 #include "content/public/browser/site_instance.h"
125 #include "content/public/browser/web_contents.h"
126 #include "content/public/common/child_process_host.h"
127 #include "content/public/common/content_descriptors.h"
128 #include "content/public/common/url_utils.h"
129 #include "content/public/common/web_preferences.h"
130 #include "gin/public/isolate_holder.h"
131 #include "net/base/mime_util.h"
132 #include "net/cookies/canonical_cookie.h"
133 #include "net/cookies/cookie_options.h"
134 #include "net/ssl/ssl_cert_request_info.h"
135 #include "ppapi/host/ppapi_host.h"
136 #include "storage/browser/fileapi/external_mount_points.h"
137 #include "ui/base/l10n/l10n_util.h"
138 #include "ui/base/resource/resource_bundle.h"
139 #include "ui/resources/grit/ui_resources.h"
142 #include "base/win/windows_version.h"
143 #include "chrome/browser/chrome_browser_main_win.h"
144 #include "sandbox/win/src/sandbox_policy.h"
145 #elif defined(OS_MACOSX)
146 #include "chrome/browser/chrome_browser_main_mac.h"
147 #include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
148 #include "components/crash/app/breakpad_mac.h"
149 #elif defined(OS_CHROMEOS)
150 #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
151 #include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h"
152 #include "chrome/browser/chromeos/file_manager/app_id.h"
153 #include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
154 #include "chrome/browser/chromeos/fileapi/file_system_backend.h"
155 #include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
156 #include "chrome/browser/chromeos/login/startup_utils.h"
157 #include "chrome/browser/chromeos/system/input_device_settings.h"
158 #include "chromeos/chromeos_switches.h"
159 #include "components/user_manager/user_manager.h"
160 #elif defined(OS_LINUX)
161 #include "chrome/browser/chrome_browser_main_linux.h"
162 #elif defined(OS_ANDROID)
163 #include "chrome/browser/android/new_tab_page_url_handler.h"
164 #include "chrome/browser/android/service_tab_launcher.h"
165 #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
166 #include "chrome/browser/chrome_browser_main_android.h"
167 #include "chrome/common/descriptors_android.h"
168 #include "components/crash/browser/crash_dump_manager_android.h"
169 #elif defined(OS_POSIX)
170 #include "chrome/browser/chrome_browser_main_posix.h"
173 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
174 #include "chrome/browser/media/protected_media_identifier_permission_context.h"
175 #include "chrome/browser/media/protected_media_identifier_permission_context_factory.h"
178 #if defined(OS_POSIX) && !defined(OS_MACOSX)
179 #include "base/debug/leak_annotations.h"
180 #include "components/crash/app/breakpad_linux.h"
181 #include "components/crash/browser/crash_handler_host_linux.h"
184 #if defined(OS_ANDROID)
185 #include "ui/base/ui_base_paths.h"
186 #include "ui/gfx/android/device_display_info.h"
189 #if defined(OS_ANDROID)
190 #include "chrome/browser/android/dev_tools_manager_delegate_android.h"
192 #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
195 #if !defined(OS_CHROMEOS)
196 #include "chrome/browser/signin/chrome_signin_client.h"
197 #include "chrome/browser/signin/chrome_signin_client_factory.h"
198 #include "chrome/browser/signin/signin_manager_factory.h"
199 #include "components/signin/core/browser/signin_manager.h"
202 #if defined(TOOLKIT_VIEWS)
203 #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
207 #include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
210 #if defined(USE_AURA)
211 #include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
215 #include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
218 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
219 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
222 #if !defined(DISABLE_NACL)
223 #include "components/nacl/browser/nacl_browser.h"
224 #include "components/nacl/browser/nacl_host_message_filter.h"
225 #include "components/nacl/browser/nacl_process_host.h"
226 #include "components/nacl/common/nacl_process_type.h"
227 #include "components/nacl/common/nacl_switches.h"
230 #if defined(ENABLE_EXTENSIONS)
231 #include "chrome/browser/accessibility/animation_policy_prefs.h"
232 #include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
233 #include "chrome/browser/extensions/extension_util.h"
234 #include "chrome/browser/media/cast_transport_host_filter.h"
235 #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
236 #include "extensions/browser/extension_registry.h"
237 #include "extensions/browser/guest_view/guest_view_base.h"
238 #include "extensions/browser/guest_view/guest_view_manager.h"
239 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
240 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
241 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
242 #include "extensions/common/constants.h"
243 #include "extensions/common/extension.h"
244 #include "extensions/common/extension_set.h"
245 #include "extensions/common/manifest_handlers/background_info.h"
246 #include "extensions/common/manifest_handlers/shared_module_info.h"
247 #include "extensions/common/permissions/permissions_data.h"
248 #include "extensions/common/permissions/socket_permission.h"
249 #include "extensions/common/switches.h"
252 #if defined(ENABLE_PLUGINS)
253 #include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
256 #if defined(ENABLE_SPELLCHECK)
257 #include "chrome/browser/spellchecker/spellcheck_message_filter.h"
260 #if defined(ENABLE_WEBRTC)
261 #include "chrome/browser/media/webrtc_logging_handler_host.h"
264 using base::FileDescriptor
;
265 using blink::WebWindowFeatures
;
266 using content::AccessTokenStore
;
267 using content::BrowserThread
;
268 using content::BrowserURLHandler
;
269 using content::ChildProcessSecurityPolicy
;
270 using content::QuotaPermissionContext
;
271 using content::RenderFrameHost
;
272 using content::RenderViewHost
;
273 using content::ResourceType
;
274 using content::SiteInstance
;
275 using content::WebContents
;
276 using content::WebPreferences
;
277 using message_center::NotifierId
;
279 #if defined(OS_POSIX)
280 using content::FileDescriptorInfo
;
283 #if defined(ENABLE_EXTENSIONS)
284 using extensions::APIPermission
;
285 using extensions::ChromeContentBrowserClientExtensionsPart
;
286 using extensions::Extension
;
287 using extensions::InfoMap
;
288 using extensions::Manifest
;
291 #if defined(ENABLE_PLUGINS)
292 using plugins::ChromeContentBrowserClientPluginsPart
;
297 // Cached version of the locale so we can return the locale on the I/O
299 base::LazyInstance
<std::string
> g_io_thread_application_locale
;
301 #if defined(ENABLE_PLUGINS)
302 // TODO(teravest): Add renderer-side API-specific checking for these APIs so
303 // that blanket permission isn't granted to all dev channel APIs for these.
304 // http://crbug.com/386743
305 const char* const kPredefinedAllowedDevChannelOrigins
[] = {
306 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/383937
307 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/383937
310 const char* const kPredefinedAllowedFileHandleOrigins
[] = {
311 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
312 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
315 const char* const kPredefinedAllowedSocketOrigins
[] = {
316 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
317 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
318 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
319 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
320 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
321 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
322 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
323 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
324 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
325 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
326 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
327 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
328 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
329 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
330 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
331 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
332 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
333 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
334 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
335 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
339 // Returns a copy of the given url with its host set to given host and path set
340 // to given path. Other parts of the url will be the same.
341 GURL
ReplaceURLHostAndPath(const GURL
& url
,
342 const std::string
& host
,
343 const std::string
& path
) {
344 url::Replacements
<char> replacements
;
345 replacements
.SetHost(host
.c_str(), url::Component(0, host
.length()));
346 replacements
.SetPath(path
.c_str(), url::Component(0, path
.length()));
347 return url
.ReplaceComponents(replacements
);
350 // Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
351 GURL
AddUberHost(const GURL
& url
) {
352 const std::string uber_host
= chrome::kChromeUIUberHost
;
353 const std::string new_path
= url
.host() + url
.path();
355 return ReplaceURLHostAndPath(url
, uber_host
, new_path
);
358 // If url->host() is "chrome" and url->path() has characters other than the
359 // first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
360 // returns true. Otherwise returns false.
361 bool RemoveUberHost(GURL
* url
) {
362 if (url
->host() != chrome::kChromeUIUberHost
)
365 if (url
->path().empty() || url
->path() == "/")
368 const std::string old_path
= url
->path();
370 const std::string::size_type separator
= old_path
.find('/', 1);
371 std::string new_host
;
372 std::string new_path
;
373 if (separator
== std::string::npos
) {
374 new_host
= old_path
.substr(1);
376 new_host
= old_path
.substr(1, separator
- 1);
377 new_path
= old_path
.substr(separator
);
380 // Do not allow URLs with paths empty before the first slash since we can't
381 // have an empty host. (e.g "foo://chrome//")
382 if (new_host
.empty())
385 *url
= ReplaceURLHostAndPath(*url
, new_host
, new_path
);
387 DCHECK(url
->is_valid());
392 // Handles rewriting Web UI URLs.
393 bool HandleWebUI(GURL
* url
, content::BrowserContext
* browser_context
) {
394 // Do not handle special URLs such as "about:foo"
395 if (!url
->host().empty()) {
396 const GURL chrome_url
= AddUberHost(*url
);
398 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
400 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
401 browser_context
, chrome_url
))
405 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
406 browser_context
, *url
))
409 #if defined(OS_CHROMEOS)
410 // Special case : in ChromeOS in Guest mode bookmarks and history are
411 // disabled for security reasons. New tab page explains the reasons, so
412 // we redirect user to new tab page.
413 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
414 if (url
->SchemeIs(content::kChromeUIScheme
) &&
415 (url
->DomainIs(chrome::kChromeUIBookmarksHost
) ||
416 url
->DomainIs(chrome::kChromeUIHistoryHost
))) {
417 // Rewrite with new tab URL
418 *url
= GURL(chrome::kChromeUINewTabURL
);
426 // Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
428 bool HandleWebUIReverse(GURL
* url
, content::BrowserContext
* browser_context
) {
429 if (!url
->is_valid() || !url
->SchemeIs(content::kChromeUIScheme
))
432 return RemoveUberHost(url
);
435 bool CertMatchesFilter(const net::X509Certificate
& cert
,
436 const base::DictionaryValue
& filter
) {
437 // TODO(markusheintz): This is the minimal required filter implementation.
438 // Implement a better matcher.
440 // An empty filter matches any client certificate since no requirements are
445 std::string common_name
;
446 if (filter
.GetString("ISSUER.CN", &common_name
) &&
447 (cert
.issuer().common_name
== common_name
)) {
453 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
454 breakpad::CrashHandlerHostLinux
* CreateCrashHandlerHost(
455 const std::string
& process_type
) {
456 base::FilePath dumps_path
;
457 PathService::Get(chrome::DIR_CRASH_DUMPS
, &dumps_path
);
459 ANNOTATE_SCOPED_MEMORY_LEAK
;
460 bool upload
= (getenv(env_vars::kHeadless
) == NULL
);
461 breakpad::CrashHandlerHostLinux
* crash_handler
=
462 new breakpad::CrashHandlerHostLinux(process_type
, dumps_path
, upload
);
463 crash_handler
->StartUploaderThread();
464 return crash_handler
;
468 int GetCrashSignalFD(const base::CommandLine
& command_line
) {
469 // Extensions have the same process type as renderers.
470 if (command_line
.HasSwitch(extensions::switches::kExtensionProcess
)) {
471 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
473 crash_handler
= CreateCrashHandlerHost("extension");
474 return crash_handler
->GetDeathSignalSocket();
477 std::string process_type
=
478 command_line
.GetSwitchValueASCII(switches::kProcessType
);
480 if (process_type
== switches::kRendererProcess
) {
481 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
483 crash_handler
= CreateCrashHandlerHost(process_type
);
484 return crash_handler
->GetDeathSignalSocket();
487 if (process_type
== switches::kPluginProcess
) {
488 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
490 crash_handler
= CreateCrashHandlerHost(process_type
);
491 return crash_handler
->GetDeathSignalSocket();
494 if (process_type
== switches::kPpapiPluginProcess
) {
495 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
497 crash_handler
= CreateCrashHandlerHost(process_type
);
498 return crash_handler
->GetDeathSignalSocket();
501 if (process_type
== switches::kGpuProcess
) {
502 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
504 crash_handler
= CreateCrashHandlerHost(process_type
);
505 return crash_handler
->GetDeathSignalSocket();
510 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
512 #if !defined(OS_CHROMEOS)
513 GURL
GetEffectiveURLForSignin(const GURL
& url
) {
514 CHECK(SigninManager::IsWebBasedSigninFlowURL(url
));
516 GURL
effective_url(SigninManager::kChromeSigninEffectiveSite
);
517 // Copy the path because the argument to SetPathStr must outlive
518 // the Replacements object.
519 const std::string
path_copy(url
.path());
520 GURL::Replacements replacements
;
521 replacements
.SetPathStr(path_copy
);
522 effective_url
= effective_url
.ReplaceComponents(replacements
);
523 return effective_url
;
527 void SetApplicationLocaleOnIOThread(const std::string
& locale
) {
528 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
529 g_io_thread_application_locale
.Get() = locale
;
532 void HandleBlockedPopupOnUIThread(const BlockedWindowParams
& params
) {
533 // TODO(jochen): This code path should use RenderFrameHosts. See
534 // http://crbug.com/431769 for details.
535 RenderViewHost
* render_view_host
=
536 RenderViewHost::FromID(params
.render_process_id(), params
.opener_id());
537 if (!render_view_host
)
539 WebContents
* tab
= WebContents::FromRenderViewHost(render_view_host
);
540 // The tab might already have navigated away.
541 if (!tab
|| tab
->GetRenderViewHost() != render_view_host
)
544 prerender::PrerenderContents
* prerender_contents
=
545 prerender::PrerenderContents::FromWebContents(tab
);
546 if (prerender_contents
) {
547 prerender_contents
->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW
);
551 PopupBlockerTabHelper
* popup_helper
=
552 PopupBlockerTabHelper::FromWebContents(tab
);
555 popup_helper
->AddBlockedPopup(params
);
558 #if defined(OS_ANDROID)
560 void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams
& params
) {
561 WebContents
* web_contents
=
562 tab_util::GetWebContentsByID(params
.render_process_id(),
567 SingleTabModeTabHelper::FromWebContents(web_contents
)->HandleOpenUrl(params
);
570 float GetDeviceScaleAdjustment() {
571 static const float kMinFSM
= 1.05f
;
572 static const int kWidthForMinFSM
= 320;
573 static const float kMaxFSM
= 1.3f
;
574 static const int kWidthForMaxFSM
= 800;
576 gfx::DeviceDisplayInfo info
;
577 int minWidth
= info
.GetSmallestDIPWidth();
579 if (minWidth
<= kWidthForMinFSM
)
581 if (minWidth
>= kWidthForMaxFSM
)
584 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
585 float ratio
= static_cast<float>(minWidth
- kWidthForMinFSM
) /
586 (kWidthForMaxFSM
- kWidthForMinFSM
);
587 return ratio
* (kMaxFSM
- kMinFSM
) + kMinFSM
;
590 #endif // defined(OS_ANDROID)
592 #if defined(ENABLE_EXTENSIONS)
593 // By default, JavaScript and images are enabled in guest content.
594 void GetGuestViewDefaultContentSettingRules(
596 RendererContentSettingRules
* rules
) {
597 rules
->image_rules
.push_back(
598 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
599 ContentSettingsPattern::Wildcard(),
600 CONTENT_SETTING_ALLOW
,
604 rules
->script_rules
.push_back(
605 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
606 ContentSettingsPattern::Wildcard(),
607 CONTENT_SETTING_ALLOW
,
611 #endif // defined(ENALBE_EXTENSIONS)
613 content::PermissionStatus
614 ContentSettingToPermissionStatus(ContentSetting setting
) {
616 case CONTENT_SETTING_ALLOW
:
617 case CONTENT_SETTING_SESSION_ONLY
:
618 return content::PERMISSION_STATUS_GRANTED
;
619 case CONTENT_SETTING_BLOCK
:
620 return content::PERMISSION_STATUS_DENIED
;
621 case CONTENT_SETTING_ASK
:
622 return content::PERMISSION_STATUS_ASK
;
623 case CONTENT_SETTING_DETECT_IMPORTANT_CONTENT
:
624 case CONTENT_SETTING_DEFAULT
:
625 case CONTENT_SETTING_NUM_SETTINGS
:
629 return content::PERMISSION_STATUS_DENIED
;
632 PermissionContextBase
* GetPermissionContext(Profile
* profile
,
633 content::PermissionType permission
) {
634 switch (permission
) {
635 case content::PERMISSION_MIDI_SYSEX
:
636 return MidiPermissionContextFactory::GetForProfile(profile
);
637 case content::PERMISSION_NOTIFICATIONS
:
638 #if defined(ENABLE_NOTIFICATIONS)
639 return DesktopNotificationServiceFactory::GetForProfile(profile
);
644 case content::PERMISSION_GEOLOCATION
:
645 return GeolocationPermissionContextFactory::GetForProfile(profile
);
646 case content::PERMISSION_PROTECTED_MEDIA_IDENTIFIER
:
647 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
648 return ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(
654 case content::PERMISSION_PUSH_MESSAGING
:
655 return PushMessagingPermissionContextFactory::GetForProfile(profile
);
656 case content::PERMISSION_NUM
:
657 NOTREACHED() << "Invalid RequestPermission for " << permission
;
663 // Helper method to translate from Permissions to ContentSettings
664 ContentSettingsType
PermissionToContentSetting(
665 content::PermissionType permission
) {
666 switch (permission
) {
667 case content::PERMISSION_MIDI_SYSEX
:
668 return CONTENT_SETTINGS_TYPE_MIDI_SYSEX
;
669 case content::PERMISSION_PUSH_MESSAGING
:
670 return CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
;
671 case content::PERMISSION_NOTIFICATIONS
:
672 return CONTENT_SETTINGS_TYPE_NOTIFICATIONS
;
673 case content::PERMISSION_GEOLOCATION
:
674 return CONTENT_SETTINGS_TYPE_GEOLOCATION
;
675 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
676 case content::PERMISSION_PROTECTED_MEDIA_IDENTIFIER
:
677 return CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER
;
680 NOTREACHED() << "Unknown content setting for permission " << permission
;
681 return CONTENT_SETTINGS_TYPE_DEFAULT
;
685 void OnRequestPermission(
686 const base::Callback
<void(content::PermissionStatus
)>& callback
,
687 ContentSetting content_setting
) {
688 callback
.Run(ContentSettingToPermissionStatus(content_setting
));
695 ChromeContentBrowserClient::ChromeContentBrowserClient()
697 #if defined(OS_POSIX) && !defined(OS_MACOSX)
700 #endif // OS_POSIX && !OS_MACOSX
701 weak_factory_(this) {
702 #if defined(ENABLE_PLUGINS)
703 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedDevChannelOrigins
); ++i
)
704 allowed_dev_channel_origins_
.insert(kPredefinedAllowedDevChannelOrigins
[i
]);
705 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedFileHandleOrigins
); ++i
)
706 allowed_file_handle_origins_
.insert(kPredefinedAllowedFileHandleOrigins
[i
]);
707 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedSocketOrigins
); ++i
)
708 allowed_socket_origins_
.insert(kPredefinedAllowedSocketOrigins
[i
]);
710 extra_parts_
.push_back(new ChromeContentBrowserClientPluginsPart
);
713 #if !defined(OS_ANDROID)
714 TtsExtensionEngine
* tts_extension_engine
= TtsExtensionEngine::GetInstance();
715 TtsController::GetInstance()->SetTtsEngineDelegate(tts_extension_engine
);
718 #if defined(ENABLE_EXTENSIONS)
719 extra_parts_
.push_back(new ChromeContentBrowserClientExtensionsPart
);
723 ChromeContentBrowserClient::~ChromeContentBrowserClient() {
724 for (int i
= static_cast<int>(extra_parts_
.size()) - 1; i
>= 0; --i
)
725 delete extra_parts_
[i
];
726 extra_parts_
.clear();
730 void ChromeContentBrowserClient::RegisterProfilePrefs(
731 user_prefs::PrefRegistrySyncable
* registry
) {
732 registry
->RegisterBooleanPref(
733 prefs::kDisable3DAPIs
,
735 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
736 registry
->RegisterBooleanPref(
737 prefs::kEnableHyperlinkAuditing
,
739 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
740 registry
->RegisterListPref(
741 prefs::kEnableDeprecatedWebPlatformFeatures
,
742 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
746 void ChromeContentBrowserClient::SetApplicationLocale(
747 const std::string
& locale
) {
748 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
750 // This object is guaranteed to outlive all threads so we don't have to
751 // worry about the lack of refcounting and can just post as Unretained.
753 // The common case is that this function is called early in Chrome startup
754 // before any threads are created (it will also be called later if the user
755 // changes the pref). In this case, there will be no threads created and
756 // posting will fail. When there are no threads, we can just set the string
757 // without worrying about threadsafety.
758 if (!BrowserThread::PostTask(BrowserThread::IO
, FROM_HERE
,
759 base::Bind(&SetApplicationLocaleOnIOThread
, locale
))) {
760 g_io_thread_application_locale
.Get() = locale
;
764 content::BrowserMainParts
* ChromeContentBrowserClient::CreateBrowserMainParts(
765 const content::MainFunctionParams
& parameters
) {
766 ChromeBrowserMainParts
* main_parts
;
767 // Construct the Main browser parts based on the OS type.
769 main_parts
= new ChromeBrowserMainPartsWin(parameters
);
770 #elif defined(OS_MACOSX)
771 main_parts
= new ChromeBrowserMainPartsMac(parameters
);
772 #elif defined(OS_CHROMEOS)
773 main_parts
= new chromeos::ChromeBrowserMainPartsChromeos(parameters
);
774 #elif defined(OS_LINUX)
775 main_parts
= new ChromeBrowserMainPartsLinux(parameters
);
776 #elif defined(OS_ANDROID)
777 main_parts
= new ChromeBrowserMainPartsAndroid(parameters
);
778 #elif defined(OS_POSIX)
779 main_parts
= new ChromeBrowserMainPartsPosix(parameters
);
782 main_parts
= new ChromeBrowserMainParts(parameters
);
785 chrome::AddProfilesExtraParts(main_parts
);
787 // Construct additional browser parts. Stages are called in the order in
788 // which they are added.
789 #if defined(TOOLKIT_VIEWS)
790 main_parts
->AddParts(new ChromeBrowserMainExtraPartsViews());
793 // TODO(oshima): Athena on chrome currently requires USE_ASH to build.
794 // We should reduce the dependency as much as possible.
796 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAsh());
799 #if defined(USE_AURA)
800 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAura());
804 main_parts
->AddParts(new ChromeBrowserMainExtraPartsX11());
807 chrome::AddMetricsExtraParts(main_parts
);
812 std::string
ChromeContentBrowserClient::GetStoragePartitionIdForSite(
813 content::BrowserContext
* browser_context
,
815 std::string partition_id
;
817 // The partition ID for webview guest processes is the string value of its
818 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
819 if (site
.SchemeIs(content::kGuestScheme
)) {
820 partition_id
= site
.spec();
821 } else if (site
.GetOrigin().spec() == kChromeUIChromeSigninURL
) {
822 // Chrome signin page has an embedded iframe of extension and web content,
823 // thus it must be isolated from other webUI pages.
824 partition_id
= site
.GetOrigin().spec();
827 DCHECK(IsValidStoragePartitionId(browser_context
, partition_id
));
831 bool ChromeContentBrowserClient::IsValidStoragePartitionId(
832 content::BrowserContext
* browser_context
,
833 const std::string
& partition_id
) {
834 // The default ID is empty and is always valid.
835 if (partition_id
.empty())
838 return GURL(partition_id
).is_valid();
841 void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
842 content::BrowserContext
* browser_context
,
845 std::string
* partition_domain
,
846 std::string
* partition_name
,
848 // Default to the browser-wide storage partition and override based on |site|
850 partition_domain
->clear();
851 partition_name
->clear();
854 bool success
= false;
855 #if defined(ENABLE_EXTENSIONS)
856 success
= extensions::WebViewGuest::GetGuestPartitionConfigForSite(
857 site
, partition_domain
, partition_name
, in_memory
);
859 if (!success
&& site
.SchemeIs(extensions::kExtensionScheme
)) {
860 // If |can_be_default| is false, the caller is stating that the |site|
861 // should be parsed as if it had isolated storage. In particular it is
862 // important to NOT check ExtensionService for the is_storage_isolated()
863 // attribute because this code path is run during Extension uninstall
864 // to do cleanup after the Extension has already been unloaded from the
866 bool is_isolated
= !can_be_default
;
867 if (can_be_default
) {
868 if (extensions::util::SiteHasIsolatedStorage(site
, browser_context
))
873 CHECK(site
.has_host());
874 // For extensions with isolated storage, the the host of the |site| is
875 // the |partition_domain|. The |in_memory| and |partition_name| are only
876 // used in guest schemes so they are cleared here.
877 *partition_domain
= site
.host();
879 partition_name
->clear();
885 if (!success
&& (site
.GetOrigin().spec() == kChromeUIChromeSigninURL
)) {
886 // Chrome signin page has an embedded iframe of extension and web content,
887 // thus it must be isolated from other webUI pages.
888 *partition_domain
= chrome::kChromeUIChromeSigninHost
;
891 // Assert that if |can_be_default| is false, the code above must have found a
892 // non-default partition. If this fails, the caller has a serious logic
893 // error about which StoragePartition they expect to be in and it is not
895 CHECK(can_be_default
|| !partition_domain
->empty());
898 content::WebContentsViewDelegate
*
899 ChromeContentBrowserClient::GetWebContentsViewDelegate(
900 content::WebContents
* web_contents
) {
901 return chrome::CreateWebContentsViewDelegate(web_contents
);
904 void ChromeContentBrowserClient::RenderProcessWillLaunch(
905 content::RenderProcessHost
* host
) {
906 int id
= host
->GetID();
907 Profile
* profile
= Profile::FromBrowserContext(host
->GetBrowserContext());
908 net::URLRequestContextGetter
* context
=
909 profile
->GetRequestContextForRenderProcess(id
);
911 host
->AddFilter(new ChromeRenderMessageFilter(id
, profile
));
912 #if defined(ENABLE_EXTENSIONS)
913 host
->AddFilter(new cast::CastTransportHostFilter
);
915 #if defined(ENABLE_PRINTING)
916 host
->AddFilter(new printing::PrintingMessageFilter(id
, profile
));
918 host
->AddFilter(new SearchProviderInstallStateMessageFilter(id
, profile
));
919 #if defined(ENABLE_SPELLCHECK)
920 host
->AddFilter(new SpellCheckMessageFilter(id
));
922 #if defined(OS_MACOSX)
923 host
->AddFilter(new SpellCheckMessageFilterMac(id
));
925 host
->AddFilter(new ChromeNetBenchmarkingMessageFilter(profile
, context
));
926 host
->AddFilter(new prerender::PrerenderMessageFilter(id
, profile
));
927 host
->AddFilter(new TtsMessageFilter(id
, host
->GetBrowserContext()));
928 #if defined(ENABLE_WEBRTC)
929 WebRtcLoggingHandlerHost
* webrtc_logging_handler_host
=
930 new WebRtcLoggingHandlerHost(profile
);
931 host
->SetWebRtcLogMessageCallback(base::Bind(
932 &WebRtcLoggingHandlerHost::LogMessage
, webrtc_logging_handler_host
));
933 host
->AddFilter(webrtc_logging_handler_host
);
934 host
->SetUserData(host
, new base::UserDataAdapter
<WebRtcLoggingHandlerHost
>(
935 webrtc_logging_handler_host
));
937 #if !defined(DISABLE_NACL)
938 host
->AddFilter(new nacl::NaClHostMessageFilter(
939 id
, profile
->IsOffTheRecord(),
943 #if defined(OS_ANDROID)
944 host
->AddFilter(new cdm::CdmMessageFilterAndroid());
946 if (switches::IsEnableAccountConsistency())
947 host
->AddFilter(new PrincipalsMessageFilter(id
));
949 DataReductionProxyChromeSettings
* data_reduction_proxy_settings
=
950 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(profile
);
951 host
->AddFilter(new data_reduction_proxy::DataReductionProxyMessageFilter(
952 data_reduction_proxy_settings
));
954 host
->Send(new ChromeViewMsg_SetIsIncognitoProcess(
955 profile
->IsOffTheRecord()));
957 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
958 extra_parts_
[i
]->RenderProcessWillLaunch(host
);
960 RendererContentSettingRules rules
;
961 if (host
->IsIsolatedGuest()) {
962 #if defined(ENABLE_EXTENSIONS)
963 GetGuestViewDefaultContentSettingRules(profile
->IsOffTheRecord(), &rules
);
968 GetRendererContentSettingRules(
969 profile
->GetHostContentSettingsMap(), &rules
);
971 host
->Send(new ChromeViewMsg_SetContentSettingRules(rules
));
974 GURL
ChromeContentBrowserClient::GetEffectiveURL(
975 content::BrowserContext
* browser_context
, const GURL
& url
) {
976 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
980 // If the input |url| should be assigned to the Instant renderer, make its
981 // effective URL distinct from other URLs on the search provider's domain.
982 if (chrome::ShouldAssignURLToInstantRenderer(url
, profile
))
983 return chrome::GetEffectiveURLForInstant(url
, profile
);
985 #if !defined(OS_CHROMEOS)
986 // If the input |url| should be assigned to the Signin renderer, make its
987 // effective URL distinct from other URLs on the signin service's domain.
988 // Note that the signin renderer will be allowed to sign the user in to
990 if (SigninManager::IsWebBasedSigninFlowURL(url
))
991 return GetEffectiveURLForSignin(url
);
994 #if defined(ENABLE_EXTENSIONS)
995 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(
1002 bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
1003 content::BrowserContext
* browser_context
, const GURL
& effective_url
) {
1004 // Non-extension, non-Instant URLs should generally use
1005 // process-per-site-instance. Because we expect to use the effective URL,
1006 // URLs for hosted apps (apart from bookmark apps) should have an extension
1009 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1013 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url
, profile
))
1016 #if !defined(OS_CHROMEOS)
1017 if (SigninManager::IsWebBasedSigninFlowURL(effective_url
))
1021 #if defined(ENABLE_EXTENSIONS)
1022 return ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
1023 profile
, effective_url
);
1029 // These are treated as WebUI schemes but do not get WebUI bindings. Also,
1030 // view-source is allowed for these schemes.
1031 void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1032 std::vector
<std::string
>* additional_schemes
) {
1033 additional_schemes
->push_back(chrome::kChromeSearchScheme
);
1034 additional_schemes
->push_back(dom_distiller::kDomDistillerScheme
);
1037 void ChromeContentBrowserClient::GetAdditionalWebUIHostsToIgnoreParititionCheck(
1038 std::vector
<std::string
>* hosts
) {
1039 hosts
->push_back(chrome::kChromeUIExtensionIconHost
);
1040 hosts
->push_back(chrome::kChromeUIFaviconHost
);
1041 hosts
->push_back(chrome::kChromeUIThemeHost
);
1042 hosts
->push_back(chrome::kChromeUIThumbnailHost
);
1043 hosts
->push_back(chrome::kChromeUIThumbnailHost2
);
1044 hosts
->push_back(chrome::kChromeUIThumbnailListHost
);
1047 net::URLRequestContextGetter
*
1048 ChromeContentBrowserClient::CreateRequestContext(
1049 content::BrowserContext
* browser_context
,
1050 content::ProtocolHandlerMap
* protocol_handlers
,
1051 content::URLRequestInterceptorScopedVector request_interceptors
) {
1052 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1053 return profile
->CreateRequestContext(protocol_handlers
,
1054 request_interceptors
.Pass());
1057 net::URLRequestContextGetter
*
1058 ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
1059 content::BrowserContext
* browser_context
,
1060 const base::FilePath
& partition_path
,
1062 content::ProtocolHandlerMap
* protocol_handlers
,
1063 content::URLRequestInterceptorScopedVector request_interceptors
) {
1064 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1065 return profile
->CreateRequestContextForStoragePartition(
1069 request_interceptors
.Pass());
1072 bool ChromeContentBrowserClient::IsHandledURL(const GURL
& url
) {
1073 return ProfileIOData::IsHandledURL(url
);
1076 bool ChromeContentBrowserClient::CanCommitURL(
1077 content::RenderProcessHost
* process_host
,
1079 #if defined(ENABLE_EXTENSIONS)
1080 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(
1087 bool ChromeContentBrowserClient::ShouldAllowOpenURL(
1088 content::SiteInstance
* site_instance
, const GURL
& url
) {
1089 GURL from_url
= site_instance
->GetSiteURL();
1091 #if defined(ENABLE_EXTENSIONS)
1093 if (ChromeContentBrowserClientExtensionsPart::ShouldAllowOpenURL(
1094 site_instance
, from_url
, url
, &result
))
1098 // Do not allow chrome://chrome-signin navigate to other chrome:// URLs, since
1099 // the signin page may host untrusted web content.
1100 if (from_url
.GetOrigin().spec() == chrome::kChromeUIChromeSigninURL
&&
1101 url
.SchemeIs(content::kChromeUIScheme
) &&
1102 url
.host() != chrome::kChromeUIChromeSigninHost
) {
1103 VLOG(1) << "Blocked navigation to " << url
.spec() << " from "
1104 << chrome::kChromeUIChromeSigninURL
;
1111 bool ChromeContentBrowserClient::IsSuitableHost(
1112 content::RenderProcessHost
* process_host
,
1113 const GURL
& site_url
) {
1115 Profile::FromBrowserContext(process_host
->GetBrowserContext());
1116 // This may be NULL during tests. In that case, just assume any site can
1121 // Instant URLs should only be in the instant process and instant process
1122 // should only have Instant URLs.
1123 InstantService
* instant_service
=
1124 InstantServiceFactory::GetForProfile(profile
);
1125 if (instant_service
) {
1126 bool is_instant_process
= instant_service
->IsInstantProcess(
1127 process_host
->GetID());
1128 bool should_be_in_instant_process
=
1129 chrome::ShouldAssignURLToInstantRenderer(site_url
, profile
);
1130 if (is_instant_process
|| should_be_in_instant_process
)
1131 return is_instant_process
&& should_be_in_instant_process
;
1134 #if !defined(OS_CHROMEOS)
1135 SigninClient
* signin_client
=
1136 ChromeSigninClientFactory::GetForProfile(profile
);
1137 if (signin_client
&& signin_client
->IsSigninProcess(process_host
->GetID()))
1138 return SigninManager::IsWebBasedSigninFlowURL(site_url
);
1141 #if defined(ENABLE_EXTENSIONS)
1142 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1143 profile
, process_host
, site_url
);
1149 bool ChromeContentBrowserClient::MayReuseHost(
1150 content::RenderProcessHost
* process_host
) {
1151 // If there is currently a prerender in progress for the host provided,
1152 // it may not be shared. We require prerenders to be by themselves in a
1153 // separate process so that we can monitor their resource usage.
1154 Profile
* profile
= Profile::FromBrowserContext(
1155 process_host
->GetBrowserContext());
1156 prerender::PrerenderManager
* prerender_manager
=
1157 prerender::PrerenderManagerFactory::GetForProfile(profile
);
1158 if (prerender_manager
&&
1159 !prerender_manager
->MayReuseProcessHost(process_host
)) {
1166 bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1167 content::BrowserContext
* browser_context
, const GURL
& url
) {
1168 // It has to be a valid URL for us to check for an extension.
1169 if (!url
.is_valid())
1172 #if defined(ENABLE_EXTENSIONS)
1173 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1174 return ChromeContentBrowserClientExtensionsPart::
1175 ShouldTryToUseExistingProcessHost(
1182 void ChromeContentBrowserClient::SiteInstanceGotProcess(
1183 SiteInstance
* site_instance
) {
1184 CHECK(site_instance
->HasProcess());
1186 Profile
* profile
= Profile::FromBrowserContext(
1187 site_instance
->GetBrowserContext());
1191 // Remember the ID of the Instant process to signal the renderer process
1192 // on startup in |AppendExtraCommandLineSwitches| below.
1193 if (chrome::ShouldAssignURLToInstantRenderer(
1194 site_instance
->GetSiteURL(), profile
)) {
1195 InstantService
* instant_service
=
1196 InstantServiceFactory::GetForProfile(profile
);
1197 if (instant_service
)
1198 instant_service
->AddInstantProcess(site_instance
->GetProcess()->GetID());
1201 #if !defined(OS_CHROMEOS)
1202 // We only expect there to be one signin process as we use process-per-site
1203 // for signin URLs. The signin process will be cleared from SigninManager
1204 // when the renderer is destroyed.
1205 if (SigninManager::IsWebBasedSigninFlowURL(site_instance
->GetSiteURL())) {
1206 SigninClient
* signin_client
=
1207 ChromeSigninClientFactory::GetForProfile(profile
);
1209 signin_client
->SetSigninProcess(site_instance
->GetProcess()->GetID());
1210 #if defined(ENABLE_EXTENSIONS)
1211 ChromeContentBrowserClientExtensionsPart::SetSigninProcess(site_instance
);
1216 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
1217 extra_parts_
[i
]->SiteInstanceGotProcess(site_instance
);
1220 void ChromeContentBrowserClient::SiteInstanceDeleting(
1221 SiteInstance
* site_instance
) {
1222 if (!site_instance
->HasProcess())
1225 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
1226 extra_parts_
[i
]->SiteInstanceDeleting(site_instance
);
1229 bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
1230 SiteInstance
* site_instance
,
1231 const GURL
& current_url
,
1232 const GURL
& new_url
) {
1233 #if defined(ENABLE_EXTENSIONS)
1234 return ChromeContentBrowserClientExtensionsPart::
1235 ShouldSwapBrowsingInstancesForNavigation(
1236 site_instance
, current_url
, new_url
);
1242 bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1243 content::ResourceContext
* resource_context
, const GURL
& current_url
,
1244 const GURL
& new_url
) {
1245 #if defined(ENABLE_EXTENSIONS)
1246 return ChromeContentBrowserClientExtensionsPart::
1247 ShouldSwapProcessesForRedirect(resource_context
, current_url
, new_url
);
1253 bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL
& url
) {
1254 return !url
.SchemeIs(chrome::kChromeNativeScheme
);
1257 std::string
ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1258 const std::string
& alias_name
) {
1259 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name
);
1264 bool IsAutoReloadEnabled() {
1265 // Fetch the field trial, even though we don't use it. Calling FindFullName()
1266 // causes the field-trial mechanism to report which group we're in, which
1267 // might reflect a hard disable or hard enable via flag, both of which have
1268 // their own field trial groups. This lets us know what percentage of users
1269 // manually enable or disable auto-reload.
1270 std::string group
= base::FieldTrialList::FindFullName(
1271 "AutoReloadExperiment");
1272 const base::CommandLine
& browser_command_line
=
1273 *base::CommandLine::ForCurrentProcess();
1274 if (browser_command_line
.HasSwitch(switches::kEnableOfflineAutoReload
))
1276 if (browser_command_line
.HasSwitch(switches::kDisableOfflineAutoReload
))
1281 bool IsAutoReloadVisibleOnlyEnabled() {
1282 // See the block comment in IsAutoReloadEnabled().
1283 std::string group
= base::FieldTrialList::FindFullName(
1284 "AutoReloadVisibleOnlyExperiment");
1285 const base::CommandLine
& browser_command_line
=
1286 *base::CommandLine::ForCurrentProcess();
1287 if (browser_command_line
.HasSwitch(
1288 switches::kEnableOfflineAutoReloadVisibleOnly
)) {
1291 if (browser_command_line
.HasSwitch(
1292 switches::kDisableOfflineAutoReloadVisibleOnly
)) {
1300 void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1301 base::CommandLine
* command_line
,
1302 int child_process_id
) {
1303 #if defined(OS_POSIX)
1304 if (breakpad::IsCrashReporterEnabled()) {
1305 scoped_ptr
<metrics::ClientInfo
> client_info
=
1306 GoogleUpdateSettings::LoadMetricsClientInfo();
1307 command_line
->AppendSwitchASCII(switches::kEnableCrashReporter
,
1308 client_info
? client_info
->client_id
1311 #endif // defined(OS_POSIX)
1313 if (logging::DialogsAreSuppressed())
1314 command_line
->AppendSwitch(switches::kNoErrorDialogs
);
1316 std::string process_type
=
1317 command_line
->GetSwitchValueASCII(switches::kProcessType
);
1318 const base::CommandLine
& browser_command_line
=
1319 *base::CommandLine::ForCurrentProcess();
1321 static const char* const kCommonSwitchNames
[] = {
1322 switches::kUserAgent
,
1323 switches::kUserDataDir
, // Make logs go to the right file.
1325 command_line
->CopySwitchesFrom(browser_command_line
, kCommonSwitchNames
,
1326 arraysize(kCommonSwitchNames
));
1328 #if defined(ENABLE_IPC_FUZZER)
1329 static const char* const kIpcFuzzerSwitches
[] = {
1330 switches::kIpcFuzzerTestcase
,
1332 command_line
->CopySwitchesFrom(browser_command_line
, kIpcFuzzerSwitches
,
1333 arraysize(kIpcFuzzerSwitches
));
1336 #if defined(OS_CHROMEOS)
1337 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
1338 base::FilePath homedir
;
1339 PathService::Get(base::DIR_HOME
, &homedir
);
1340 command_line
->AppendSwitchASCII(chromeos::switches::kHomedir
,
1341 homedir
.value().c_str());
1344 if (process_type
== switches::kRendererProcess
) {
1345 content::RenderProcessHost
* process
=
1346 content::RenderProcessHost::FromID(child_process_id
);
1348 process
? Profile::FromBrowserContext(process
->GetBrowserContext())
1350 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
1351 extra_parts_
[i
]->AppendExtraRendererCommandLineSwitches(
1352 command_line
, process
, profile
);
1355 #if defined(OS_CHROMEOS)
1356 const std::string
& login_profile
=
1357 browser_command_line
.GetSwitchValueASCII(
1358 chromeos::switches::kLoginProfile
);
1359 if (!login_profile
.empty())
1360 command_line
->AppendSwitchASCII(
1361 chromeos::switches::kLoginProfile
, login_profile
);
1364 #if defined(ENABLE_WEBRTC)
1365 MaybeCopyDisableWebRtcEncryptionSwitch(command_line
,
1366 browser_command_line
,
1367 VersionInfo::GetChannel());
1371 PrefService
* prefs
= profile
->GetPrefs();
1372 // Currently this pref is only registered if applied via a policy.
1373 if (prefs
->HasPrefPath(prefs::kDisable3DAPIs
) &&
1374 prefs
->GetBoolean(prefs::kDisable3DAPIs
)) {
1375 // Turn this policy into a command line switch.
1376 command_line
->AppendSwitch(switches::kDisable3DAPIs
);
1379 const base::ListValue
* switches
=
1380 prefs
->GetList(prefs::kEnableDeprecatedWebPlatformFeatures
);
1382 // Enable any deprecated features that have been re-enabled by policy.
1383 for (base::ListValue::const_iterator it
= switches
->begin();
1384 it
!= switches
->end(); ++it
) {
1385 std::string switch_to_enable
;
1386 if ((*it
)->GetAsString(&switch_to_enable
))
1387 command_line
->AppendSwitch(switch_to_enable
);
1391 // Disable client-side phishing detection in the renderer if it is
1392 // disabled in the Profile preferences or the browser process.
1393 if (!prefs
->GetBoolean(prefs::kSafeBrowsingEnabled
) ||
1394 !g_browser_process
->safe_browsing_detection_service()) {
1395 command_line
->AppendSwitch(
1396 switches::kDisableClientSidePhishingDetection
);
1399 if (prefs
->GetBoolean(prefs::kPrintPreviewDisabled
))
1400 command_line
->AppendSwitch(switches::kDisablePrintPreview
);
1402 InstantService
* instant_service
=
1403 InstantServiceFactory::GetForProfile(profile
);
1404 if (instant_service
&&
1405 instant_service
->IsInstantProcess(process
->GetID()))
1406 command_line
->AppendSwitch(switches::kInstantProcess
);
1408 #if !defined(OS_CHROMEOS)
1409 SigninClient
* signin_client
=
1410 ChromeSigninClientFactory::GetForProfile(profile
);
1411 if (signin_client
&& signin_client
->IsSigninProcess(process
->GetID()))
1412 command_line
->AppendSwitch(switches::kSigninProcess
);
1416 if (IsAutoReloadEnabled())
1417 command_line
->AppendSwitch(switches::kEnableOfflineAutoReload
);
1418 if (IsAutoReloadVisibleOnlyEnabled()) {
1419 command_line
->AppendSwitch(
1420 switches::kEnableOfflineAutoReloadVisibleOnly
);
1424 // Enable load stale cache if this session is in the field trial or
1425 // the user explicitly enabled it. Note that as far as the renderer
1426 // is concerned, the feature is enabled if-and-only-if the
1427 // kEnableOfflineLoadStaleCache flag is on the command line;
1428 // the yes/no/default behavior is only at the browser command line
1431 // Command line switches override
1432 if (browser_command_line
.HasSwitch(
1433 switches::kEnableOfflineLoadStaleCache
)) {
1434 command_line
->AppendSwitch(switches::kEnableOfflineLoadStaleCache
);
1435 } else if (!browser_command_line
.HasSwitch(
1436 switches::kDisableOfflineLoadStaleCache
)) {
1438 base::FieldTrialList::FindFullName("LoadStaleCacheExperiment");
1440 if (group
== "Enabled")
1441 command_line
->AppendSwitch(switches::kEnableOfflineLoadStaleCache
);
1445 // Please keep this in alphabetical order.
1446 static const char* const kSwitchNames
[] = {
1447 autofill::switches::kDisableFillOnAccountSelect
,
1448 autofill::switches::kDisablePasswordGeneration
,
1449 autofill::switches::kEnableFillOnAccountSelect
,
1450 autofill::switches::kEnableFillOnAccountSelectNoHighlighting
,
1451 autofill::switches::kEnablePasswordGeneration
,
1452 autofill::switches::kEnablePasswordSaveOnInPageNavigation
,
1453 autofill::switches::kEnableSingleClickAutofill
,
1454 autofill::switches::kIgnoreAutocompleteOffForAutofill
,
1455 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration
,
1456 autofill::switches::kRespectAutocompleteOffForAutofill
,
1457 #if defined(ENABLE_EXTENSIONS)
1458 extensions::switches::kAllowHTTPBackgroundPage
,
1459 extensions::switches::kAllowLegacyExtensionManifests
,
1460 extensions::switches::kEnableSurfaceWorker
,
1461 extensions::switches::kEnableAppWindowControls
,
1462 extensions::switches::kEnableEmbeddedExtensionOptions
,
1463 extensions::switches::kEnableExperimentalExtensionApis
,
1464 extensions::switches::kExtensionsOnChromeURLs
,
1465 extensions::switches::kWhitelistedExtensionID
,
1467 switches::kAllowInsecureLocalhost
,
1468 switches::kAppsCheckoutURL
,
1469 switches::kAppsGalleryURL
,
1470 switches::kCloudPrintURL
,
1471 switches::kCloudPrintXmppEndpoint
,
1472 switches::kDisableBundledPpapiFlash
,
1473 switches::kDisableCastStreamingHWEncoding
,
1474 switches::kDisableJavaScriptHarmonyShipping
,
1475 switches::kDisableNewBookmarkApps
,
1476 switches::kDisableOutOfProcessPdf
,
1477 switches::kEnableBenchmarking
,
1478 switches::kEnableNaCl
,
1479 #if !defined(DISABLE_NACL)
1480 switches::kEnableNaClDebug
,
1481 switches::kEnableNaClNonSfiMode
,
1483 switches::kEnableNetBenchmarking
,
1484 switches::kEnableNewBookmarkApps
,
1485 switches::kEnableOutOfProcessPdf
,
1486 switches::kEnablePluginPlaceholderShadowDom
,
1487 switches::kJavaScriptHarmony
,
1488 switches::kMessageLoopHistogrammer
,
1489 switches::kPlaybackMode
,
1490 switches::kPpapiFlashArgs
,
1491 switches::kPpapiFlashPath
,
1492 switches::kPpapiFlashVersion
,
1493 switches::kProfilingAtStart
,
1494 switches::kProfilingFile
,
1495 switches::kProfilingFlush
,
1496 switches::kRecordMode
,
1497 translate::switches::kTranslateSecurityOrigin
,
1500 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1501 arraysize(kSwitchNames
));
1502 } else if (process_type
== switches::kUtilityProcess
) {
1503 #if defined(ENABLE_EXTENSIONS)
1504 static const char* const kSwitchNames
[] = {
1505 extensions::switches::kAllowHTTPBackgroundPage
,
1506 extensions::switches::kEnableExperimentalExtensionApis
,
1507 extensions::switches::kExtensionsOnChromeURLs
,
1508 extensions::switches::kWhitelistedExtensionID
,
1511 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1512 arraysize(kSwitchNames
));
1514 } else if (process_type
== switches::kPluginProcess
) {
1515 #if defined(OS_CHROMEOS)
1516 static const char* const kSwitchNames
[] = {
1517 chromeos::switches::kLoginProfile
,
1520 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1521 arraysize(kSwitchNames
));
1523 } else if (process_type
== switches::kZygoteProcess
) {
1524 static const char* const kSwitchNames
[] = {
1525 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
1526 switches::kDisableBundledPpapiFlash
,
1527 #if !defined(DISABLE_NACL)
1528 switches::kEnableNaClDebug
,
1529 switches::kEnableNaClNonSfiMode
,
1530 switches::kNaClDangerousNoSandboxNonSfi
,
1531 switches::kUseNaClHelperNonSfi
,
1533 switches::kPpapiFlashPath
,
1534 switches::kPpapiFlashVersion
,
1537 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1538 arraysize(kSwitchNames
));
1539 } else if (process_type
== switches::kGpuProcess
) {
1540 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1541 // because GPU is expected to be unreliable.
1542 if (browser_command_line
.HasSwitch(switches::kIgnoreGpuBlacklist
) &&
1543 !command_line
->HasSwitch(switches::kDisableBreakpad
))
1544 command_line
->AppendSwitch(switches::kDisableBreakpad
);
1547 // The command line switch kEnableBenchmarking needs to be specified along
1548 // with the kEnableStatsTable switch to ensure that the stats table global
1549 // is initialized correctly.
1550 if (command_line
->HasSwitch(switches::kEnableBenchmarking
))
1551 DCHECK(command_line
->HasSwitch(switches::kEnableStatsTable
));
1554 std::string
ChromeContentBrowserClient::GetApplicationLocale() {
1555 if (BrowserThread::CurrentlyOn(BrowserThread::IO
))
1556 return g_io_thread_application_locale
.Get();
1557 return g_browser_process
->GetApplicationLocale();
1560 std::string
ChromeContentBrowserClient::GetAcceptLangs(
1561 content::BrowserContext
* context
) {
1562 Profile
* profile
= Profile::FromBrowserContext(context
);
1563 return profile
->GetPrefs()->GetString(prefs::kAcceptLanguages
);
1566 const gfx::ImageSkia
* ChromeContentBrowserClient::GetDefaultFavicon() {
1567 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
1568 return rb
.GetNativeImageNamed(IDR_DEFAULT_FAVICON
).ToImageSkia();
1571 bool ChromeContentBrowserClient::AllowAppCache(
1572 const GURL
& manifest_url
,
1573 const GURL
& first_party
,
1574 content::ResourceContext
* context
) {
1575 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1576 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1577 return io_data
->GetCookieSettings()->
1578 IsSettingCookieAllowed(manifest_url
, first_party
);
1581 bool ChromeContentBrowserClient::AllowServiceWorker(
1583 const GURL
& first_party_url
,
1584 content::ResourceContext
* context
) {
1585 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1586 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1587 return io_data
->GetCookieSettings()->
1588 IsSettingCookieAllowed(scope
, first_party_url
);
1591 bool ChromeContentBrowserClient::AllowGetCookie(
1593 const GURL
& first_party
,
1594 const net::CookieList
& cookie_list
,
1595 content::ResourceContext
* context
,
1596 int render_process_id
,
1597 int render_frame_id
) {
1598 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1599 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1600 bool allow
= io_data
->GetCookieSettings()->
1601 IsReadingCookieAllowed(url
, first_party
);
1603 BrowserThread::PostTask(
1604 BrowserThread::UI
, FROM_HERE
,
1605 base::Bind(&TabSpecificContentSettings::CookiesRead
, render_process_id
,
1606 render_frame_id
, url
, first_party
, cookie_list
, !allow
, true));
1610 bool ChromeContentBrowserClient::AllowSetCookie(
1612 const GURL
& first_party
,
1613 const std::string
& cookie_line
,
1614 content::ResourceContext
* context
,
1615 int render_process_id
,
1616 int render_frame_id
,
1617 net::CookieOptions
* options
) {
1618 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1619 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1620 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1621 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, first_party
);
1623 BrowserThread::PostTask(
1624 BrowserThread::UI
, FROM_HERE
,
1625 base::Bind(&TabSpecificContentSettings::CookieChanged
, render_process_id
,
1626 render_frame_id
, url
, first_party
, cookie_line
, *options
,
1631 bool ChromeContentBrowserClient::AllowSaveLocalState(
1632 content::ResourceContext
* context
) {
1633 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1634 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1635 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1636 ContentSetting setting
= cookie_settings
->GetDefaultCookieSetting(NULL
);
1638 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1639 // Could we even support per-origin settings?
1640 return setting
!= CONTENT_SETTING_SESSION_ONLY
;
1643 bool ChromeContentBrowserClient::AllowWorkerDatabase(
1645 const base::string16
& name
,
1646 const base::string16
& display_name
,
1647 unsigned long estimated_size
,
1648 content::ResourceContext
* context
,
1649 const std::vector
<std::pair
<int, int> >& render_frames
) {
1650 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1651 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1652 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1653 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1655 // Record access to database for potential display in UI.
1656 std::vector
<std::pair
<int, int> >::const_iterator i
;
1657 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1658 BrowserThread::PostTask(
1659 BrowserThread::UI
, FROM_HERE
,
1660 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed
,
1661 i
->first
, i
->second
, url
, name
, display_name
, !allow
));
1667 void ChromeContentBrowserClient::AllowWorkerFileSystem(
1669 content::ResourceContext
* context
,
1670 const std::vector
<std::pair
<int, int> >& render_frames
,
1671 base::Callback
<void(bool)> callback
) {
1672 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1673 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1674 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1675 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1677 #if defined(ENABLE_EXTENSIONS)
1678 GuestPermissionRequestHelper(url
, render_frames
, callback
, allow
);
1680 FileSystemAccessed(url
, render_frames
, callback
, allow
);
1684 #if defined(ENABLE_EXTENSIONS)
1685 void ChromeContentBrowserClient::GuestPermissionRequestHelper(
1687 const std::vector
<std::pair
<int, int> >& render_frames
,
1688 base::Callback
<void(bool)> callback
,
1690 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::IO
));
1691 std::vector
<std::pair
<int, int> >::const_iterator i
;
1692 std::map
<int, int> process_map
;
1693 std::map
<int, int>::const_iterator it
;
1694 bool has_web_view_guest
= false;
1695 // Record access to file system for potential display in UI.
1696 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1697 if (process_map
.find(i
->first
) != process_map
.end())
1700 process_map
.insert(std::pair
<int, int>(i
->first
, i
->second
));
1702 if (extensions::WebViewRendererState::GetInstance()->IsGuest(i
->first
))
1703 has_web_view_guest
= true;
1705 if (!has_web_view_guest
) {
1706 FileSystemAccessed(url
, render_frames
, callback
, allow
);
1709 DCHECK_EQ(1U, process_map
.size());
1710 it
= process_map
.begin();
1711 BrowserThread::PostTask(
1714 base::Bind(&ChromeContentBrowserClient::
1715 RequestFileSystemPermissionOnUIThread
,
1720 base::Bind(&ChromeContentBrowserClient::FileSystemAccessed
,
1721 weak_factory_
.GetWeakPtr(),
1727 void ChromeContentBrowserClient::RequestFileSystemPermissionOnUIThread(
1728 int render_process_id
,
1729 int render_frame_id
,
1731 bool allowed_by_default
,
1732 const base::Callback
<void(bool)>& callback
) {
1733 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::UI
));
1734 extensions::WebViewPermissionHelper
* web_view_permission_helper
=
1735 extensions::WebViewPermissionHelper::FromFrameID(
1736 render_process_id
, render_frame_id
);
1737 web_view_permission_helper
->RequestFileSystemPermission(url
,
1743 void ChromeContentBrowserClient::FileSystemAccessed(
1745 const std::vector
<std::pair
<int, int> >& render_frames
,
1746 base::Callback
<void(bool)> callback
,
1748 // Record access to file system for potential display in UI.
1749 std::vector
<std::pair
<int, int> >::const_iterator i
;
1750 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1751 BrowserThread::PostTask(
1754 base::Bind(&TabSpecificContentSettings::FileSystemAccessed
,
1755 i
->first
, i
->second
, url
, !allow
));
1757 callback
.Run(allow
);
1760 bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1762 const base::string16
& name
,
1763 content::ResourceContext
* context
,
1764 const std::vector
<std::pair
<int, int> >& render_frames
) {
1765 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1766 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1767 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1768 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1770 // Record access to IndexedDB for potential display in UI.
1771 std::vector
<std::pair
<int, int> >::const_iterator i
;
1772 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1773 BrowserThread::PostTask(
1774 BrowserThread::UI
, FROM_HERE
,
1775 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed
,
1776 i
->first
, i
->second
, url
, name
, !allow
));
1782 net::URLRequestContext
*
1783 ChromeContentBrowserClient::OverrideRequestContextForURL(
1784 const GURL
& url
, content::ResourceContext
* context
) {
1785 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1786 #if defined(ENABLE_EXTENSIONS)
1787 if (url
.SchemeIs(extensions::kExtensionScheme
)) {
1788 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1789 return io_data
->extensions_request_context();
1796 QuotaPermissionContext
*
1797 ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1798 return new ChromeQuotaPermissionContext();
1801 void ChromeContentBrowserClient::AllowCertificateError(
1802 int render_process_id
,
1803 int render_frame_id
,
1805 const net::SSLInfo
& ssl_info
,
1806 const GURL
& request_url
,
1807 ResourceType resource_type
,
1809 bool strict_enforcement
,
1810 bool expired_previous_decision
,
1811 const base::Callback
<void(bool)>& callback
,
1812 content::CertificateRequestResultType
* result
) {
1813 if (resource_type
!= content::RESOURCE_TYPE_MAIN_FRAME
) {
1814 // A sub-resource has a certificate error. The user doesn't really
1815 // have a context for making the right decision, so block the
1816 // request hard, without an info bar to allow showing the insecure
1818 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY
;
1822 // If the tab is being prerendered, cancel the prerender and the request.
1823 content::RenderFrameHost
* render_frame_host
=
1824 content::RenderFrameHost::FromID(render_process_id
, render_frame_id
);
1825 WebContents
* tab
= WebContents::FromRenderFrameHost(render_frame_host
);
1831 prerender::PrerenderContents
* prerender_contents
=
1832 prerender::PrerenderContents::FromWebContents(tab
);
1833 if (prerender_contents
) {
1834 prerender_contents
->Destroy(prerender::FINAL_STATUS_SSL_ERROR
);
1835 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL
;
1839 // Otherwise, display an SSL blocking page. The interstitial page takes
1840 // ownership of ssl_blocking_page.
1841 int options_mask
= 0;
1843 options_mask
|= SSLBlockingPage::OVERRIDABLE
;
1844 if (strict_enforcement
)
1845 options_mask
|= SSLBlockingPage::STRICT_ENFORCEMENT
;
1846 if (expired_previous_decision
)
1847 options_mask
|= SSLBlockingPage::EXPIRED_BUT_PREVIOUSLY_ALLOWED
;
1849 SSLErrorHandler::HandleSSLError(
1850 tab
, cert_error
, ssl_info
, request_url
, options_mask
, callback
);
1853 void ChromeContentBrowserClient::SelectClientCertificate(
1854 int render_process_id
,
1855 int render_frame_id
,
1856 net::SSLCertRequestInfo
* cert_request_info
,
1857 const base::Callback
<void(net::X509Certificate
*)>& callback
) {
1858 content::RenderFrameHost
* rfh
= content::RenderFrameHost::FromID(
1859 render_process_id
, render_frame_id
);
1860 WebContents
* tab
= WebContents::FromRenderFrameHost(rfh
);
1862 // TODO(davidben): This makes the request hang, but returning no certificate
1863 // also breaks. It should abort the request. See https://crbug.com/417092
1867 prerender::PrerenderContents
* prerender_contents
=
1868 prerender::PrerenderContents::FromWebContents(tab
);
1869 if (prerender_contents
) {
1870 prerender_contents
->Destroy(
1871 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED
);
1875 GURL
requesting_url("https://" + cert_request_info
->host_and_port
.ToString());
1876 DCHECK(requesting_url
.is_valid())
1877 << "Invalid URL string: https://"
1878 << cert_request_info
->host_and_port
.ToString();
1880 Profile
* profile
= Profile::FromBrowserContext(tab
->GetBrowserContext());
1881 scoped_ptr
<base::Value
> filter
=
1882 profile
->GetHostContentSettingsMap()->GetWebsiteSetting(
1885 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE
,
1890 // Try to automatically select a client certificate.
1891 if (filter
->IsType(base::Value::TYPE_DICTIONARY
)) {
1892 base::DictionaryValue
* filter_dict
=
1893 static_cast<base::DictionaryValue
*>(filter
.get());
1895 const std::vector
<scoped_refptr
<net::X509Certificate
> >&
1896 all_client_certs
= cert_request_info
->client_certs
;
1897 for (size_t i
= 0; i
< all_client_certs
.size(); ++i
) {
1898 if (CertMatchesFilter(*all_client_certs
[i
].get(), *filter_dict
)) {
1899 // Use the first certificate that is matched by the filter.
1900 callback
.Run(all_client_certs
[i
].get());
1909 chrome::ShowSSLClientCertificateSelector(tab
, cert_request_info
, callback
);
1912 void ChromeContentBrowserClient::AddCertificate(
1913 net::CertificateMimeType cert_type
,
1914 const void* cert_data
,
1916 int render_process_id
,
1917 int render_frame_id
) {
1918 chrome::SSLAddCertificate(cert_type
, cert_data
, cert_size
,
1919 render_process_id
, render_frame_id
);
1922 content::MediaObserver
* ChromeContentBrowserClient::GetMediaObserver() {
1923 return MediaCaptureDevicesDispatcher::GetInstance();
1926 content::PlatformNotificationService
*
1927 ChromeContentBrowserClient::GetPlatformNotificationService() {
1928 #if defined(ENABLE_NOTIFICATIONS)
1929 return PlatformNotificationServiceImpl::GetInstance();
1936 void ChromeContentBrowserClient::RequestPermission(
1937 content::PermissionType permission
,
1938 content::WebContents
* web_contents
,
1940 const GURL
& requesting_frame
,
1942 const base::Callback
<void(content::PermissionStatus
)>& result_callback
) {
1943 int render_process_id
= web_contents
->GetRenderProcessHost()->GetID();
1944 int render_view_id
= web_contents
->GetRenderViewHost()->GetRoutingID();
1945 const PermissionRequestID
request_id(render_process_id
,
1950 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
1951 PermissionContextBase
* context
= GetPermissionContext(profile
, permission
);
1956 context
->RequestPermission(web_contents
, request_id
, requesting_frame
,
1958 base::Bind(&OnRequestPermission
, result_callback
));
1961 content::PermissionStatus
ChromeContentBrowserClient::GetPermissionStatus(
1962 content::PermissionType permission
,
1963 content::BrowserContext
* browser_context
,
1964 const GURL
& requesting_origin
,
1965 const GURL
& embedding_origin
) {
1966 DCHECK(browser_context
);
1967 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1968 PermissionContextBase
* context
= GetPermissionContext(profile
, permission
);
1971 return content::PERMISSION_STATUS_ASK
;
1973 return ContentSettingToPermissionStatus(
1974 context
->GetPermissionStatus(requesting_origin
.GetOrigin(),
1975 embedding_origin
.GetOrigin()));
1978 void ChromeContentBrowserClient::ResetPermission(
1979 content::PermissionType permission
,
1980 content::BrowserContext
* browser_context
,
1981 const GURL
& requesting_origin
,
1982 const GURL
& embedding_origin
) {
1983 DCHECK(browser_context
);
1984 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1985 PermissionContextBase
* context
= GetPermissionContext(profile
, permission
);
1990 context
->ResetPermission(requesting_origin
.GetOrigin(),
1991 embedding_origin
.GetOrigin());
1994 void ChromeContentBrowserClient::CancelPermissionRequest(
1995 content::PermissionType permission
,
1996 content::WebContents
* web_contents
,
1998 const GURL
& requesting_frame
) {
1999 int render_process_id
= web_contents
->GetRenderProcessHost()->GetID();
2000 int render_view_id
= web_contents
->GetRenderViewHost()->GetRoutingID();
2001 const PermissionRequestID
request_id(render_process_id
,
2006 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
2007 PermissionContextBase
* context
= GetPermissionContext(profile
, permission
);
2010 context
->CancelPermissionRequest(web_contents
, request_id
);
2013 void ChromeContentBrowserClient::RegisterPermissionUsage(
2014 content::PermissionType permission
,
2015 content::WebContents
* web_contents
,
2016 const GURL
& frame_url
,
2017 const GURL
& main_frame_url
) {
2018 Profile::FromBrowserContext(web_contents
->GetBrowserContext())
2019 ->GetHostContentSettingsMap()
2021 frame_url
, main_frame_url
, PermissionToContentSetting(permission
));
2024 bool ChromeContentBrowserClient::CanCreateWindow(
2025 const GURL
& opener_url
,
2026 const GURL
& opener_top_level_frame_url
,
2027 const GURL
& source_origin
,
2028 WindowContainerType container_type
,
2029 const GURL
& target_url
,
2030 const content::Referrer
& referrer
,
2031 WindowOpenDisposition disposition
,
2032 const WebWindowFeatures
& features
,
2034 bool opener_suppressed
,
2035 content::ResourceContext
* context
,
2036 int render_process_id
,
2038 bool* no_javascript_access
) {
2039 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
2041 *no_javascript_access
= false;
2043 // If the opener is trying to create a background window but doesn't have
2044 // the appropriate permission, fail the attempt.
2045 if (container_type
== WINDOW_CONTAINER_TYPE_BACKGROUND
) {
2046 #if defined(ENABLE_EXTENSIONS)
2047 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
2048 InfoMap
* map
= io_data
->GetExtensionInfoMap();
2049 if (!map
->SecurityOriginHasAPIPermission(
2052 APIPermission::kBackground
)) {
2056 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2057 // return a recently installed Extension even if this CanCreateWindow call
2058 // was made by an old copy of the page in a normal web process. That's ok,
2059 // because the permission check above would have caused an early return
2060 // already. We must use the full URL to find hosted apps, though, and not
2062 const Extension
* extension
=
2063 map
->extensions().GetExtensionOrAppByURL(opener_url
);
2064 if (extension
&& !extensions::BackgroundInfo::AllowJSAccess(extension
))
2065 *no_javascript_access
= true;
2071 #if defined(ENABLE_EXTENSIONS)
2072 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
2077 HostContentSettingsMap
* content_settings
=
2078 ProfileIOData::FromResourceContext(context
)->GetHostContentSettingsMap();
2079 BlockedWindowParams
blocked_params(target_url
,
2088 if (!user_gesture
&&
2089 !base::CommandLine::ForCurrentProcess()->HasSwitch(
2090 switches::kDisablePopupBlocking
)) {
2091 if (content_settings
->GetContentSetting(opener_top_level_frame_url
,
2092 opener_top_level_frame_url
,
2093 CONTENT_SETTINGS_TYPE_POPUPS
,
2095 CONTENT_SETTING_ALLOW
) {
2096 BrowserThread::PostTask(BrowserThread::UI
,
2098 base::Bind(&HandleBlockedPopupOnUIThread
,
2104 #if defined(OS_ANDROID)
2105 if (SingleTabModeTabHelper::IsRegistered(render_process_id
, opener_id
)) {
2106 BrowserThread::PostTask(BrowserThread::UI
,
2108 base::Bind(&HandleSingleTabModeBlockOnUIThread
,
2117 void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
2119 return g_browser_process
->ResourceDispatcherHostCreated();
2122 content::SpeechRecognitionManagerDelegate
*
2123 ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
2124 return new speech::ChromeSpeechRecognitionManagerDelegate();
2127 net::NetLog
* ChromeContentBrowserClient::GetNetLog() {
2128 return g_browser_process
->net_log();
2131 AccessTokenStore
* ChromeContentBrowserClient::CreateAccessTokenStore() {
2132 return new ChromeAccessTokenStore();
2135 bool ChromeContentBrowserClient::IsFastShutdownPossible() {
2139 void ChromeContentBrowserClient::OverrideWebkitPrefs(
2140 RenderViewHost
* rvh
, WebPreferences
* web_prefs
) {
2141 Profile
* profile
= Profile::FromBrowserContext(
2142 rvh
->GetProcess()->GetBrowserContext());
2143 PrefService
* prefs
= profile
->GetPrefs();
2145 // Fill per-script font preferences. These are not registered on Android
2146 // - http://crbug.com/308033.
2147 #if !defined(OS_ANDROID)
2148 FontFamilyCache::FillFontFamilyMap(profile
,
2149 prefs::kWebKitStandardFontFamilyMap
,
2150 &web_prefs
->standard_font_family_map
);
2151 FontFamilyCache::FillFontFamilyMap(profile
,
2152 prefs::kWebKitFixedFontFamilyMap
,
2153 &web_prefs
->fixed_font_family_map
);
2154 FontFamilyCache::FillFontFamilyMap(profile
,
2155 prefs::kWebKitSerifFontFamilyMap
,
2156 &web_prefs
->serif_font_family_map
);
2157 FontFamilyCache::FillFontFamilyMap(profile
,
2158 prefs::kWebKitSansSerifFontFamilyMap
,
2159 &web_prefs
->sans_serif_font_family_map
);
2160 FontFamilyCache::FillFontFamilyMap(profile
,
2161 prefs::kWebKitCursiveFontFamilyMap
,
2162 &web_prefs
->cursive_font_family_map
);
2163 FontFamilyCache::FillFontFamilyMap(profile
,
2164 prefs::kWebKitFantasyFontFamilyMap
,
2165 &web_prefs
->fantasy_font_family_map
);
2166 FontFamilyCache::FillFontFamilyMap(profile
,
2167 prefs::kWebKitPictographFontFamilyMap
,
2168 &web_prefs
->pictograph_font_family_map
);
2171 web_prefs
->default_font_size
=
2172 prefs
->GetInteger(prefs::kWebKitDefaultFontSize
);
2173 web_prefs
->default_fixed_font_size
=
2174 prefs
->GetInteger(prefs::kWebKitDefaultFixedFontSize
);
2175 web_prefs
->minimum_font_size
=
2176 prefs
->GetInteger(prefs::kWebKitMinimumFontSize
);
2177 web_prefs
->minimum_logical_font_size
=
2178 prefs
->GetInteger(prefs::kWebKitMinimumLogicalFontSize
);
2180 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2182 web_prefs
->javascript_can_open_windows_automatically
=
2183 prefs
->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically
);
2184 web_prefs
->dom_paste_enabled
=
2185 prefs
->GetBoolean(prefs::kWebKitDomPasteEnabled
);
2186 web_prefs
->shrinks_standalone_images_to_fit
=
2187 prefs
->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit
);
2188 web_prefs
->tabs_to_links
= prefs
->GetBoolean(prefs::kWebkitTabsToLinks
);
2190 if (!prefs
->GetBoolean(prefs::kWebKitJavascriptEnabled
))
2191 web_prefs
->javascript_enabled
= false;
2192 if (!prefs
->GetBoolean(prefs::kWebKitWebSecurityEnabled
))
2193 web_prefs
->web_security_enabled
= false;
2194 if (!prefs
->GetBoolean(prefs::kWebKitPluginsEnabled
))
2195 web_prefs
->plugins_enabled
= false;
2196 if (!prefs
->GetBoolean(prefs::kWebKitJavaEnabled
))
2197 web_prefs
->java_enabled
= false;
2198 web_prefs
->loads_images_automatically
=
2199 prefs
->GetBoolean(prefs::kWebKitLoadsImagesAutomatically
);
2201 if (prefs
->GetBoolean(prefs::kDisable3DAPIs
))
2202 web_prefs
->experimental_webgl_enabled
= false;
2204 web_prefs
->allow_displaying_insecure_content
=
2205 prefs
->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent
);
2206 web_prefs
->allow_running_insecure_content
=
2207 prefs
->GetBoolean(prefs::kWebKitAllowRunningInsecureContent
);
2208 #if defined(OS_ANDROID)
2209 web_prefs
->font_scale_factor
=
2210 static_cast<float>(prefs
->GetDouble(prefs::kWebKitFontScaleFactor
));
2211 web_prefs
->device_scale_adjustment
= GetDeviceScaleAdjustment();
2212 web_prefs
->force_enable_zoom
=
2213 prefs
->GetBoolean(prefs::kWebKitForceEnableZoom
);
2216 #if defined(OS_ANDROID)
2217 web_prefs
->password_echo_enabled
=
2218 prefs
->GetBoolean(prefs::kWebKitPasswordEchoEnabled
);
2220 web_prefs
->password_echo_enabled
= browser_defaults::kPasswordEchoEnabled
;
2223 web_prefs
->asynchronous_spell_checking_enabled
= true;
2224 web_prefs
->unified_textchecker_enabled
= true;
2226 web_prefs
->uses_universal_detector
=
2227 prefs
->GetBoolean(prefs::kWebKitUsesUniversalDetector
);
2228 web_prefs
->text_areas_are_resizable
=
2229 prefs
->GetBoolean(prefs::kWebKitTextAreasAreResizable
);
2230 web_prefs
->hyperlink_auditing_enabled
=
2231 prefs
->GetBoolean(prefs::kEnableHyperlinkAuditing
);
2233 #if defined(ENABLE_EXTENSIONS)
2234 std::string image_animation_policy
=
2235 prefs
->GetString(prefs::kAnimationPolicy
);
2236 if (image_animation_policy
== kAnimationPolicyOnce
)
2237 web_prefs
->animation_policy
=
2238 content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE
;
2239 else if (image_animation_policy
== kAnimationPolicyNone
)
2240 web_prefs
->animation_policy
= content::IMAGE_ANIMATION_POLICY_NO_ANIMATION
;
2242 web_prefs
->animation_policy
= content::IMAGE_ANIMATION_POLICY_ALLOWED
;
2245 // Make sure we will set the default_encoding with canonical encoding name.
2246 web_prefs
->default_encoding
=
2247 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
2248 web_prefs
->default_encoding
);
2249 if (web_prefs
->default_encoding
.empty()) {
2250 prefs
->ClearPref(prefs::kDefaultCharset
);
2251 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2253 DCHECK(!web_prefs
->default_encoding
.empty());
2255 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2256 switches::kEnablePotentiallyAnnoyingSecurityFeatures
)) {
2257 web_prefs
->disable_reading_from_canvas
= true;
2258 web_prefs
->strict_mixed_content_checking
= true;
2259 web_prefs
->strict_powerful_feature_restrictions
= true;
2262 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2263 extra_parts_
[i
]->OverrideWebkitPrefs(rvh
, web_prefs
);
2266 void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2267 BrowserURLHandler
* handler
) {
2268 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2269 extra_parts_
[i
]->BrowserURLHandlerCreated(handler
);
2271 // about: handler. Must come before chrome: handler, since it will
2272 // rewrite about: urls to chrome: URLs and then expect chrome: to
2273 // actually handle them. Also relies on a preliminary fixup phase.
2274 handler
->SetFixupHandler(&FixupBrowserAboutURL
);
2275 handler
->AddHandlerPair(&WillHandleBrowserAboutURL
,
2276 BrowserURLHandler::null_handler());
2278 #if defined(OS_ANDROID)
2279 // Handler to rewrite chrome://newtab on Android.
2280 handler
->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL
,
2281 BrowserURLHandler::null_handler());
2283 // Handler to rewrite chrome://newtab for InstantExtended.
2284 handler
->AddHandlerPair(&chrome::HandleNewTabURLRewrite
,
2285 &chrome::HandleNewTabURLReverseRewrite
);
2288 // chrome: & friends.
2289 handler
->AddHandlerPair(&HandleWebUI
, &HandleWebUIReverse
);
2292 void ChromeContentBrowserClient::ClearCache(RenderViewHost
* rvh
) {
2293 Profile
* profile
= Profile::FromBrowserContext(
2294 rvh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2295 BrowsingDataRemover
* remover
=
2296 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2297 remover
->Remove(BrowsingDataRemover::REMOVE_CACHE
,
2298 BrowsingDataHelper::UNPROTECTED_WEB
);
2299 // BrowsingDataRemover takes care of deleting itself when done.
2302 void ChromeContentBrowserClient::ClearCookies(RenderViewHost
* rvh
) {
2303 Profile
* profile
= Profile::FromBrowserContext(
2304 rvh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2305 BrowsingDataRemover
* remover
=
2306 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2307 int remove_mask
= BrowsingDataRemover::REMOVE_SITE_DATA
;
2308 remover
->Remove(remove_mask
, BrowsingDataHelper::UNPROTECTED_WEB
);
2309 // BrowsingDataRemover takes care of deleting itself when done.
2312 base::FilePath
ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
2313 return DownloadPrefs::GetDefaultDownloadDirectory();
2316 std::string
ChromeContentBrowserClient::GetDefaultDownloadName() {
2317 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME
);
2320 void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2321 content::BrowserPpapiHost
* browser_host
) {
2322 #if defined(ENABLE_PLUGINS)
2323 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host
);
2327 content::BrowserPpapiHost
*
2328 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2329 int plugin_process_id
) {
2330 #if !defined(DISABLE_NACL)
2331 content::BrowserChildProcessHostIterator
iter(PROCESS_TYPE_NACL_LOADER
);
2332 while (!iter
.Done()) {
2333 nacl::NaClProcessHost
* host
= static_cast<nacl::NaClProcessHost
*>(
2334 iter
.GetDelegate());
2335 if (host
->process() &&
2336 host
->process()->GetData().id
== plugin_process_id
) {
2337 // Found the plugin.
2338 return host
->browser_ppapi_host();
2346 bool ChromeContentBrowserClient::AllowPepperSocketAPI(
2347 content::BrowserContext
* browser_context
,
2350 const content::SocketPermissionRequest
* params
) {
2351 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2352 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
2353 browser_context
, url
, private_api
, params
, allowed_socket_origins_
);
2359 ui::SelectFilePolicy
* ChromeContentBrowserClient::CreateSelectFilePolicy(
2360 WebContents
* web_contents
) {
2361 return new ChromeSelectFilePolicy(web_contents
);
2364 void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2365 std::vector
<std::string
>* additional_allowed_schemes
) {
2366 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2367 additional_allowed_schemes
);
2368 additional_allowed_schemes
->push_back(content::kChromeDevToolsScheme
);
2369 additional_allowed_schemes
->push_back(content::kChromeUIScheme
);
2370 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
2371 extra_parts_
[i
]->GetAdditionalAllowedSchemesForFileSystem(
2372 additional_allowed_schemes
);
2376 void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
2377 std::vector
<storage::URLRequestAutoMountHandler
>* handlers
) {
2378 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2379 extra_parts_
[i
]->GetURLRequestAutoMountHandlers(handlers
);
2382 void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
2383 content::BrowserContext
* browser_context
,
2384 const base::FilePath
& storage_partition_path
,
2385 ScopedVector
<storage::FileSystemBackend
>* additional_backends
) {
2386 #if defined(OS_CHROMEOS)
2387 storage::ExternalMountPoints
* external_mount_points
=
2388 content::BrowserContext::GetMountPoints(browser_context
);
2389 DCHECK(external_mount_points
);
2390 chromeos::FileSystemBackend
* backend
= new chromeos::FileSystemBackend(
2391 new drive::FileSystemBackendDelegate
,
2392 new chromeos::file_system_provider::BackendDelegate
,
2393 new chromeos::MTPFileSystemBackendDelegate(storage_partition_path
),
2394 browser_context
->GetSpecialStoragePolicy(),
2395 external_mount_points
,
2396 storage::ExternalMountPoints::GetSystemInstance());
2397 backend
->AddSystemMountPoints();
2398 DCHECK(backend
->CanHandleType(storage::kFileSystemTypeExternal
));
2399 additional_backends
->push_back(backend
);
2402 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
2403 extra_parts_
[i
]->GetAdditionalFileSystemBackends(
2404 browser_context
, storage_partition_path
, additional_backends
);
2408 #if defined(OS_POSIX) && !defined(OS_MACOSX)
2409 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2410 const base::CommandLine
& command_line
,
2411 int child_process_id
,
2412 FileDescriptorInfo
* mappings
) {
2413 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
2414 if (v8_snapshot_fd_
.get() == -1 && v8_natives_fd_
.get() == -1) {
2415 base::FilePath v8_data_path
;
2416 PathService::Get(gin::IsolateHolder::kV8SnapshotBasePathKey
, &v8_data_path
);
2417 DCHECK(!v8_data_path
.empty());
2419 int file_flags
= base::File::FLAG_OPEN
| base::File::FLAG_READ
;
2420 base::FilePath v8_natives_data_path
=
2421 v8_data_path
.AppendASCII(gin::IsolateHolder::kNativesFileName
);
2422 base::FilePath v8_snapshot_data_path
=
2423 v8_data_path
.AppendASCII(gin::IsolateHolder::kSnapshotFileName
);
2424 base::File
v8_natives_data_file(v8_natives_data_path
, file_flags
);
2425 base::File
v8_snapshot_data_file(v8_snapshot_data_path
, file_flags
);
2426 DCHECK(v8_natives_data_file
.IsValid());
2427 DCHECK(v8_snapshot_data_file
.IsValid());
2428 v8_natives_fd_
.reset(v8_natives_data_file
.TakePlatformFile());
2429 v8_snapshot_fd_
.reset(v8_snapshot_data_file
.TakePlatformFile());
2431 mappings
->Share(kV8NativesDataDescriptor
, v8_natives_fd_
.get());
2432 mappings
->Share(kV8SnapshotDataDescriptor
, v8_snapshot_fd_
.get());
2433 #endif // V8_USE_EXTERNAL_STARTUP_DATA
2435 #if defined(OS_ANDROID)
2436 base::FilePath data_path
;
2437 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID
, &data_path
);
2438 DCHECK(!data_path
.empty());
2440 int flags
= base::File::FLAG_OPEN
| base::File::FLAG_READ
;
2441 base::FilePath chrome_resources_pak
=
2442 data_path
.AppendASCII("chrome_100_percent.pak");
2443 base::File
file(chrome_resources_pak
, flags
);
2444 DCHECK(file
.IsValid());
2445 mappings
->Transfer(kAndroidChrome100PercentPakDescriptor
,
2446 base::ScopedFD(file
.TakePlatformFile()));
2448 const std::string locale
= GetApplicationLocale();
2449 base::FilePath locale_pak
= ResourceBundle::GetSharedInstance().
2450 GetLocaleFilePath(locale
, false);
2451 file
.Initialize(locale_pak
, flags
);
2452 DCHECK(file
.IsValid());
2453 mappings
->Transfer(kAndroidLocalePakDescriptor
,
2454 base::ScopedFD(file
.TakePlatformFile()));
2456 base::FilePath resources_pack_path
;
2457 PathService::Get(chrome::FILE_RESOURCES_PACK
, &resources_pack_path
);
2458 file
.Initialize(resources_pack_path
, flags
);
2459 DCHECK(file
.IsValid());
2460 mappings
->Transfer(kAndroidUIResourcesPakDescriptor
,
2461 base::ScopedFD(file
.TakePlatformFile()));
2463 if (breakpad::IsCrashReporterEnabled()) {
2464 file
= breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile(
2466 if (file
.IsValid()) {
2467 mappings
->Transfer(kAndroidMinidumpDescriptor
,
2468 base::ScopedFD(file
.TakePlatformFile()));
2470 LOG(ERROR
) << "Failed to create file for minidump, crash reporting will "
2471 "be disabled for this process.";
2475 base::FilePath app_data_path
;
2476 PathService::Get(base::DIR_ANDROID_APP_DATA
, &app_data_path
);
2477 DCHECK(!app_data_path
.empty());
2479 flags
= base::File::FLAG_OPEN
| base::File::FLAG_READ
;
2480 base::FilePath icudata_path
=
2481 app_data_path
.AppendASCII(base::i18n::kIcuDataFileName
);
2482 base::File
icudata_file(icudata_path
, flags
);
2483 DCHECK(icudata_file
.IsValid());
2484 mappings
->Transfer(kAndroidICUDataDescriptor
,
2485 base::ScopedFD(icudata_file
.TakePlatformFile()));
2487 int crash_signal_fd
= GetCrashSignalFD(command_line
);
2488 if (crash_signal_fd
>= 0) {
2489 mappings
->Share(kCrashDumpSignal
, crash_signal_fd
);
2491 #endif // defined(OS_ANDROID)
2493 #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
2496 const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2497 return chrome::kBrowserResourcesDll
;
2500 void ChromeContentBrowserClient::PreSpawnRenderer(
2501 sandbox::TargetPolicy
* policy
,
2503 // This code is duplicated in nacl_exe_win_64.cc.
2504 // Allow the server side of a pipe restricted to the "chrome.nacl."
2505 // namespace so that it cannot impersonate other system or other chrome
2507 sandbox::ResultCode result
= policy
->AddRule(
2508 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES
,
2509 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY
,
2510 L
"\\\\.\\pipe\\chrome.nacl.*");
2511 if (result
!= sandbox::SBOX_ALL_OK
) {
2516 // Renderers need to send named pipe handles and shared memory
2517 // segment handles to NaCl loader processes.
2518 result
= policy
->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES
,
2519 sandbox::TargetPolicy::HANDLES_DUP_ANY
,
2521 if (result
!= sandbox::SBOX_ALL_OK
) {
2528 bool ChromeContentBrowserClient::CheckMediaAccessPermission(
2529 content::BrowserContext
* browser_context
,
2530 const GURL
& security_origin
,
2531 content::MediaStreamType type
) {
2532 return MediaCaptureDevicesDispatcher::GetInstance()
2533 ->CheckMediaAccessPermission(
2534 browser_context
, security_origin
, type
);
2537 void ChromeContentBrowserClient::OpenURL(
2538 content::BrowserContext
* browser_context
,
2539 const content::OpenURLParams
& params
,
2540 const base::Callback
<void(content::WebContents
*)>& callback
) {
2541 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
2543 #if !defined(OS_ANDROID) && !defined(OS_IOS)
2544 NavigateParams
nav_params(Profile::FromBrowserContext(browser_context
),
2547 FillNavigateParamsFromOpenURLParams(&nav_params
, params
);
2548 nav_params
.user_gesture
= params
.user_gesture
;
2550 Navigate(&nav_params
);
2551 callback
.Run(nav_params
.target_contents
);
2552 #elif defined(OS_ANDROID)
2553 chrome::android::ServiceTabLauncher::GetInstance()->LaunchTab(
2554 browser_context
, params
, callback
);
2560 void ChromeContentBrowserClient::RecordURLMetric(const std::string
& metric
,
2563 rappor::SampleDomainAndRegistryFromGURL(metric
, url
);
2566 content::DevToolsManagerDelegate
*
2567 ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
2568 #if defined(OS_ANDROID)
2569 return new DevToolsManagerDelegateAndroid();
2571 return new ChromeDevToolsManagerDelegate();
2575 content::TracingDelegate
* ChromeContentBrowserClient::GetTracingDelegate() {
2576 #if !defined(OS_ANDROID)
2577 return new ChromeTracingDelegate();
2583 bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2584 content::BrowserContext
* browser_context
,
2586 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2587 return ChromeContentBrowserClientPluginsPart::
2588 IsPluginAllowedToCallRequestOSFileHandle(browser_context
, url
,
2589 allowed_file_handle_origins_
);
2595 bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
2596 content::BrowserContext
* browser_context
,
2598 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2599 return ChromeContentBrowserClientPluginsPart::
2600 IsPluginAllowedToUseDevChannelAPIs(browser_context
, url
,
2601 allowed_dev_channel_origins_
);
2607 void ChromeContentBrowserClient::OverridePageVisibilityState(
2608 RenderFrameHost
* render_frame_host
,
2609 blink::WebPageVisibilityState
* visibility_state
) {
2610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
2612 WebContents
* web_contents
=
2613 WebContents::FromRenderFrameHost(render_frame_host
);
2614 DCHECK(web_contents
);
2617 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
2618 prerender::PrerenderManager
* prerender_manager
=
2619 prerender::PrerenderManagerFactory::GetForProfile(profile
);
2620 if (prerender_manager
&&
2621 prerender_manager
->IsWebContentsPrerendering(web_contents
, nullptr)) {
2622 *visibility_state
= blink::WebPageVisibilityStatePrerender
;
2626 #if defined(ENABLE_WEBRTC)
2627 void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
2628 base::CommandLine
* to_command_line
,
2629 const base::CommandLine
& from_command_line
,
2630 VersionInfo::Channel channel
) {
2631 #if defined(OS_ANDROID)
2632 const VersionInfo::Channel kMaxDisableEncryptionChannel
=
2633 VersionInfo::CHANNEL_BETA
;
2635 const VersionInfo::Channel kMaxDisableEncryptionChannel
=
2636 VersionInfo::CHANNEL_DEV
;
2638 if (channel
<= kMaxDisableEncryptionChannel
) {
2639 static const char* const kWebRtcDevSwitchNames
[] = {
2640 switches::kDisableWebRtcEncryption
,
2642 to_command_line
->CopySwitchesFrom(from_command_line
,
2643 kWebRtcDevSwitchNames
,
2644 arraysize(kWebRtcDevSwitchNames
));
2647 #endif // defined(ENABLE_WEBRTC)
2649 } // namespace chrome