1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chrome_content_browser_client.h"
11 #include "base/bind.h"
12 #include "base/command_line.h"
13 #include "base/files/scoped_file.h"
14 #include "base/i18n/icu_util.h"
15 #include "base/lazy_instance.h"
16 #include "base/path_service.h"
17 #include "base/prefs/pref_service.h"
18 #include "base/prefs/scoped_user_pref_update.h"
19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/utf_string_conversions.h"
21 #include "base/threading/sequenced_worker_pool.h"
22 #include "chrome/browser/browser_about_handler.h"
23 #include "chrome/browser/browser_process.h"
24 #include "chrome/browser/browser_shutdown.h"
25 #include "chrome/browser/browsing_data/browsing_data_helper.h"
26 #include "chrome/browser/browsing_data/browsing_data_remover.h"
27 #include "chrome/browser/character_encoding.h"
28 #include "chrome/browser/chrome_content_browser_client_parts.h"
29 #include "chrome/browser/chrome_net_benchmarking_message_filter.h"
30 #include "chrome/browser/chrome_quota_permission_context.h"
31 #include "chrome/browser/content_settings/cookie_settings.h"
32 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
33 #include "chrome/browser/defaults.h"
34 #include "chrome/browser/download/download_prefs.h"
35 #include "chrome/browser/font_family_cache.h"
36 #include "chrome/browser/geolocation/chrome_access_token_store.h"
37 #include "chrome/browser/geolocation/geolocation_permission_context.h"
38 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h"
39 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
40 #include "chrome/browser/media/midi_permission_context.h"
41 #include "chrome/browser/media/midi_permission_context_factory.h"
42 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
43 #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
44 #include "chrome/browser/net/chrome_net_log.h"
45 #include "chrome/browser/notifications/desktop_notification_service.h"
46 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
47 #include "chrome/browser/notifications/platform_notification_service_impl.h"
48 #include "chrome/browser/platform_util.h"
49 #include "chrome/browser/prerender/prerender_final_status.h"
50 #include "chrome/browser/prerender/prerender_manager.h"
51 #include "chrome/browser/prerender/prerender_manager_factory.h"
52 #include "chrome/browser/prerender/prerender_message_filter.h"
53 #include "chrome/browser/prerender/prerender_tracker.h"
54 #include "chrome/browser/printing/printing_message_filter.h"
55 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
56 #include "chrome/browser/profiles/profile.h"
57 #include "chrome/browser/profiles/profile_io_data.h"
58 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
59 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
60 #include "chrome/browser/search/instant_service.h"
61 #include "chrome/browser/search/instant_service_factory.h"
62 #include "chrome/browser/search/search.h"
63 #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
64 #include "chrome/browser/services/gcm/push_messaging_permission_context.h"
65 #include "chrome/browser/services/gcm/push_messaging_permission_context_factory.h"
66 #include "chrome/browser/signin/principals_message_filter.h"
67 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
68 #include "chrome/browser/speech/tts_controller.h"
69 #include "chrome/browser/speech/tts_message_filter.h"
70 #include "chrome/browser/ssl/ssl_add_certificate.h"
71 #include "chrome/browser/ssl/ssl_blocking_page.h"
72 #include "chrome/browser/ssl/ssl_client_certificate_selector.h"
73 #include "chrome/browser/ssl/ssl_error_handler.h"
74 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
75 #include "chrome/browser/tab_contents/tab_util.h"
76 #include "chrome/browser/ui/blocked_content/blocked_window_params.h"
77 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
78 #include "chrome/browser/ui/chrome_select_file_policy.h"
79 #include "chrome/browser/ui/sync/sync_promo_ui.h"
80 #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
81 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
82 #include "chrome/common/chrome_constants.h"
83 #include "chrome/common/chrome_paths.h"
84 #include "chrome/common/chrome_switches.h"
85 #include "chrome/common/env_vars.h"
86 #include "chrome/common/logging_chrome.h"
87 #include "chrome/common/pepper_permission_util.h"
88 #include "chrome/common/pref_names.h"
89 #include "chrome/common/render_messages.h"
90 #include "chrome/common/url_constants.h"
91 #include "chrome/grit/generated_resources.h"
92 #include "chrome/installer/util/google_update_settings.h"
93 #include "chromeos/chromeos_constants.h"
94 #include "components/cdm/browser/cdm_message_filter_android.h"
95 #include "components/cloud_devices/common/cloud_devices_switches.h"
96 #include "components/content_settings/core/browser/content_settings_provider.h"
97 #include "components/content_settings/core/browser/content_settings_utils.h"
98 #include "components/content_settings/core/browser/host_content_settings_map.h"
99 #include "components/content_settings/core/common/content_settings.h"
100 #include "components/content_settings/core/common/permission_request_id.h"
101 #include "components/dom_distiller/core/url_constants.h"
102 #include "components/google/core/browser/google_util.h"
103 #include "components/metrics/client_info.h"
104 #include "components/pref_registry/pref_registry_syncable.h"
105 #include "components/signin/core/common/profile_management_switches.h"
106 #include "components/translate/core/common/translate_switches.h"
107 #include "content/public/browser/browser_child_process_host.h"
108 #include "content/public/browser/browser_main_parts.h"
109 #include "content/public/browser/browser_ppapi_host.h"
110 #include "content/public/browser/browser_thread.h"
111 #include "content/public/browser/browser_url_handler.h"
112 #include "content/public/browser/child_process_data.h"
113 #include "content/public/browser/child_process_security_policy.h"
114 #include "content/public/browser/permission_type.h"
115 #include "content/public/browser/render_frame_host.h"
116 #include "content/public/browser/render_process_host.h"
117 #include "content/public/browser/render_view_host.h"
118 #include "content/public/browser/resource_context.h"
119 #include "content/public/browser/site_instance.h"
120 #include "content/public/browser/web_contents.h"
121 #include "content/public/common/child_process_host.h"
122 #include "content/public/common/content_descriptors.h"
123 #include "content/public/common/url_utils.h"
124 #include "content/public/common/web_preferences.h"
125 #include "gin/public/isolate_holder.h"
126 #include "net/base/mime_util.h"
127 #include "net/cookies/canonical_cookie.h"
128 #include "net/cookies/cookie_options.h"
129 #include "net/ssl/ssl_cert_request_info.h"
130 #include "ppapi/host/ppapi_host.h"
131 #include "storage/browser/fileapi/external_mount_points.h"
132 #include "ui/base/l10n/l10n_util.h"
133 #include "ui/base/resource/resource_bundle.h"
134 #include "ui/resources/grit/ui_resources.h"
137 #include "base/win/windows_version.h"
138 #include "chrome/browser/chrome_browser_main_win.h"
139 #include "sandbox/win/src/sandbox_policy.h"
140 #elif defined(OS_MACOSX)
141 #include "chrome/browser/chrome_browser_main_mac.h"
142 #include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
143 #include "components/crash/app/breakpad_mac.h"
144 #elif defined(OS_CHROMEOS)
145 #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
146 #include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h"
147 #include "chrome/browser/chromeos/file_manager/app_id.h"
148 #include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
149 #include "chrome/browser/chromeos/fileapi/file_system_backend.h"
150 #include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
151 #include "chrome/browser/chromeos/login/startup_utils.h"
152 #include "chrome/browser/chromeos/system/input_device_settings.h"
153 #include "chromeos/chromeos_switches.h"
154 #include "components/user_manager/user_manager.h"
155 #elif defined(OS_LINUX)
156 #include "chrome/browser/chrome_browser_main_linux.h"
157 #elif defined(OS_ANDROID)
158 #include "chrome/browser/android/new_tab_page_url_handler.h"
159 #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
160 #include "chrome/browser/chrome_browser_main_android.h"
161 #include "chrome/browser/media/protected_media_identifier_permission_context.h"
162 #include "chrome/browser/media/protected_media_identifier_permission_context_factory.h"
163 #include "chrome/common/descriptors_android.h"
164 #include "components/crash/browser/crash_dump_manager_android.h"
165 #elif defined(OS_POSIX)
166 #include "chrome/browser/chrome_browser_main_posix.h"
169 #if defined(OS_POSIX) && !defined(OS_MACOSX)
170 #include "base/debug/leak_annotations.h"
171 #include "components/crash/app/breakpad_linux.h"
172 #include "components/crash/browser/crash_handler_host_linux.h"
175 #if defined(OS_ANDROID)
176 #include "ui/base/ui_base_paths.h"
177 #include "ui/gfx/android/device_display_info.h"
180 #if defined(OS_ANDROID)
181 #include "chrome/browser/android/dev_tools_manager_delegate_android.h"
183 #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
186 #if !defined(OS_CHROMEOS)
187 #include "chrome/browser/signin/chrome_signin_client.h"
188 #include "chrome/browser/signin/chrome_signin_client_factory.h"
189 #include "chrome/browser/signin/signin_manager_factory.h"
190 #include "components/signin/core/browser/signin_manager.h"
193 #if defined(TOOLKIT_VIEWS)
194 #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
198 #include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
201 #if defined(USE_AURA)
202 #include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
206 #include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
209 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
210 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
213 #if !defined(DISABLE_NACL)
214 #include "components/nacl/browser/nacl_browser.h"
215 #include "components/nacl/browser/nacl_host_message_filter.h"
216 #include "components/nacl/browser/nacl_process_host.h"
217 #include "components/nacl/common/nacl_process_type.h"
218 #include "components/nacl/common/nacl_switches.h"
221 #if defined(ENABLE_EXTENSIONS)
222 #include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
223 #include "chrome/browser/extensions/extension_util.h"
224 #include "chrome/browser/media/cast_transport_host_filter.h"
225 #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
226 #include "extensions/browser/extension_registry.h"
227 #include "extensions/browser/guest_view/guest_view_base.h"
228 #include "extensions/browser/guest_view/guest_view_manager.h"
229 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
230 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
231 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
232 #include "extensions/common/constants.h"
233 #include "extensions/common/extension.h"
234 #include "extensions/common/extension_set.h"
235 #include "extensions/common/manifest_handlers/background_info.h"
236 #include "extensions/common/manifest_handlers/shared_module_info.h"
237 #include "extensions/common/permissions/permissions_data.h"
238 #include "extensions/common/permissions/socket_permission.h"
239 #include "extensions/common/switches.h"
242 #if defined(ENABLE_PLUGINS)
243 #include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
246 #if defined(ENABLE_SPELLCHECK)
247 #include "chrome/browser/spellchecker/spellcheck_message_filter.h"
250 #if defined(ENABLE_WEBRTC)
251 #include "chrome/browser/media/webrtc_logging_handler_host.h"
254 using base::FileDescriptor
;
255 using blink::WebWindowFeatures
;
256 using content::AccessTokenStore
;
257 using content::BrowserThread
;
258 using content::BrowserURLHandler
;
259 using content::ChildProcessSecurityPolicy
;
260 using content::QuotaPermissionContext
;
261 using content::RenderFrameHost
;
262 using content::RenderViewHost
;
263 using content::ResourceType
;
264 using content::SiteInstance
;
265 using content::WebContents
;
266 using content::WebPreferences
;
267 using message_center::NotifierId
;
269 #if defined(OS_POSIX)
270 using content::FileDescriptorInfo
;
273 #if defined(ENABLE_EXTENSIONS)
274 using extensions::APIPermission
;
275 using extensions::ChromeContentBrowserClientExtensionsPart
;
276 using extensions::Extension
;
277 using extensions::InfoMap
;
278 using extensions::Manifest
;
281 #if defined(ENABLE_PLUGINS)
282 using plugins::ChromeContentBrowserClientPluginsPart
;
287 // Cached version of the locale so we can return the locale on the I/O
289 base::LazyInstance
<std::string
> g_io_thread_application_locale
;
291 #if defined(ENABLE_PLUGINS)
292 // TODO(teravest): Add renderer-side API-specific checking for these APIs so
293 // that blanket permission isn't granted to all dev channel APIs for these.
294 // http://crbug.com/386743
295 const char* const kPredefinedAllowedDevChannelOrigins
[] = {
296 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/383937
297 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/383937
300 const char* const kPredefinedAllowedFileHandleOrigins
[] = {
301 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
302 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
305 const char* const kPredefinedAllowedSocketOrigins
[] = {
306 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
307 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
308 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
309 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
310 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
311 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
312 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
313 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
314 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
315 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
316 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
317 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
318 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
319 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
320 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
321 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
322 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
323 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
324 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
325 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
329 // Returns a copy of the given url with its host set to given host and path set
330 // to given path. Other parts of the url will be the same.
331 GURL
ReplaceURLHostAndPath(const GURL
& url
,
332 const std::string
& host
,
333 const std::string
& path
) {
334 url::Replacements
<char> replacements
;
335 replacements
.SetHost(host
.c_str(), url::Component(0, host
.length()));
336 replacements
.SetPath(path
.c_str(), url::Component(0, path
.length()));
337 return url
.ReplaceComponents(replacements
);
340 // Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
341 GURL
AddUberHost(const GURL
& url
) {
342 const std::string uber_host
= chrome::kChromeUIUberHost
;
343 const std::string new_path
= url
.host() + url
.path();
345 return ReplaceURLHostAndPath(url
, uber_host
, new_path
);
348 // If url->host() is "chrome" and url->path() has characters other than the
349 // first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
350 // returns true. Otherwise returns false.
351 bool RemoveUberHost(GURL
* url
) {
352 if (url
->host() != chrome::kChromeUIUberHost
)
355 if (url
->path().empty() || url
->path() == "/")
358 const std::string old_path
= url
->path();
360 const std::string::size_type separator
= old_path
.find('/', 1);
361 std::string new_host
;
362 std::string new_path
;
363 if (separator
== std::string::npos
) {
364 new_host
= old_path
.substr(1);
366 new_host
= old_path
.substr(1, separator
- 1);
367 new_path
= old_path
.substr(separator
);
370 // Do not allow URLs with paths empty before the first slash since we can't
371 // have an empty host. (e.g "foo://chrome//")
372 if (new_host
.empty())
375 *url
= ReplaceURLHostAndPath(*url
, new_host
, new_path
);
377 DCHECK(url
->is_valid());
382 // Handles rewriting Web UI URLs.
383 bool HandleWebUI(GURL
* url
, content::BrowserContext
* browser_context
) {
384 // Do not handle special URLs such as "about:foo"
385 if (!url
->host().empty()) {
386 const GURL chrome_url
= AddUberHost(*url
);
388 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
390 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
391 browser_context
, chrome_url
))
395 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
396 browser_context
, *url
))
399 #if defined(OS_CHROMEOS)
400 // Special case : in ChromeOS in Guest mode bookmarks and history are
401 // disabled for security reasons. New tab page explains the reasons, so
402 // we redirect user to new tab page.
403 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
404 if (url
->SchemeIs(content::kChromeUIScheme
) &&
405 (url
->DomainIs(chrome::kChromeUIBookmarksHost
) ||
406 url
->DomainIs(chrome::kChromeUIHistoryHost
))) {
407 // Rewrite with new tab URL
408 *url
= GURL(chrome::kChromeUINewTabURL
);
416 // Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
418 bool HandleWebUIReverse(GURL
* url
, content::BrowserContext
* browser_context
) {
419 if (!url
->is_valid() || !url
->SchemeIs(content::kChromeUIScheme
))
422 return RemoveUberHost(url
);
425 bool CertMatchesFilter(const net::X509Certificate
& cert
,
426 const base::DictionaryValue
& filter
) {
427 // TODO(markusheintz): This is the minimal required filter implementation.
428 // Implement a better matcher.
430 // An empty filter matches any client certificate since no requirements are
435 std::string common_name
;
436 if (filter
.GetString("ISSUER.CN", &common_name
) &&
437 (cert
.issuer().common_name
== common_name
)) {
443 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
444 breakpad::CrashHandlerHostLinux
* CreateCrashHandlerHost(
445 const std::string
& process_type
) {
446 base::FilePath dumps_path
;
447 PathService::Get(chrome::DIR_CRASH_DUMPS
, &dumps_path
);
449 ANNOTATE_SCOPED_MEMORY_LEAK
;
450 bool upload
= (getenv(env_vars::kHeadless
) == NULL
);
451 breakpad::CrashHandlerHostLinux
* crash_handler
=
452 new breakpad::CrashHandlerHostLinux(process_type
, dumps_path
, upload
);
453 crash_handler
->StartUploaderThread();
454 return crash_handler
;
458 int GetCrashSignalFD(const base::CommandLine
& command_line
) {
459 // Extensions have the same process type as renderers.
460 if (command_line
.HasSwitch(extensions::switches::kExtensionProcess
)) {
461 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
463 crash_handler
= CreateCrashHandlerHost("extension");
464 return crash_handler
->GetDeathSignalSocket();
467 std::string process_type
=
468 command_line
.GetSwitchValueASCII(switches::kProcessType
);
470 if (process_type
== switches::kRendererProcess
) {
471 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
473 crash_handler
= CreateCrashHandlerHost(process_type
);
474 return crash_handler
->GetDeathSignalSocket();
477 if (process_type
== switches::kPluginProcess
) {
478 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
480 crash_handler
= CreateCrashHandlerHost(process_type
);
481 return crash_handler
->GetDeathSignalSocket();
484 if (process_type
== switches::kPpapiPluginProcess
) {
485 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
487 crash_handler
= CreateCrashHandlerHost(process_type
);
488 return crash_handler
->GetDeathSignalSocket();
491 if (process_type
== switches::kGpuProcess
) {
492 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
494 crash_handler
= CreateCrashHandlerHost(process_type
);
495 return crash_handler
->GetDeathSignalSocket();
500 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
502 #if !defined(OS_CHROMEOS)
503 GURL
GetEffectiveURLForSignin(const GURL
& url
) {
504 CHECK(SigninManager::IsWebBasedSigninFlowURL(url
));
506 GURL
effective_url(SigninManager::kChromeSigninEffectiveSite
);
507 // Copy the path because the argument to SetPathStr must outlive
508 // the Replacements object.
509 const std::string
path_copy(url
.path());
510 GURL::Replacements replacements
;
511 replacements
.SetPathStr(path_copy
);
512 effective_url
= effective_url
.ReplaceComponents(replacements
);
513 return effective_url
;
517 void SetApplicationLocaleOnIOThread(const std::string
& locale
) {
518 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
519 g_io_thread_application_locale
.Get() = locale
;
522 void HandleBlockedPopupOnUIThread(const BlockedWindowParams
& params
) {
523 // TODO(jochen): This code path should use RenderFrameHosts. See
524 // http://crbug.com/431769 for details.
525 RenderViewHost
* render_view_host
=
526 RenderViewHost::FromID(params
.render_process_id(), params
.opener_id());
527 if (!render_view_host
)
529 WebContents
* tab
= WebContents::FromRenderViewHost(render_view_host
);
530 // The tab might already have navigated away.
531 if (!tab
|| tab
->GetRenderViewHost() != render_view_host
)
534 prerender::PrerenderContents
* prerender_contents
=
535 prerender::PrerenderContents::FromWebContents(tab
);
536 if (prerender_contents
) {
537 prerender_contents
->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW
);
541 PopupBlockerTabHelper
* popup_helper
=
542 PopupBlockerTabHelper::FromWebContents(tab
);
545 popup_helper
->AddBlockedPopup(params
);
548 #if defined(OS_ANDROID)
550 void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams
& params
) {
551 WebContents
* web_contents
=
552 tab_util::GetWebContentsByID(params
.render_process_id(),
557 SingleTabModeTabHelper::FromWebContents(web_contents
)->HandleOpenUrl(params
);
560 float GetDeviceScaleAdjustment() {
561 static const float kMinFSM
= 1.05f
;
562 static const int kWidthForMinFSM
= 320;
563 static const float kMaxFSM
= 1.3f
;
564 static const int kWidthForMaxFSM
= 800;
566 gfx::DeviceDisplayInfo info
;
567 int minWidth
= info
.GetSmallestDIPWidth();
569 if (minWidth
<= kWidthForMinFSM
)
571 if (minWidth
>= kWidthForMaxFSM
)
574 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
575 float ratio
= static_cast<float>(minWidth
- kWidthForMinFSM
) /
576 (kWidthForMaxFSM
- kWidthForMinFSM
);
577 return ratio
* (kMaxFSM
- kMinFSM
) + kMinFSM
;
580 #endif // defined(OS_ANDROID)
582 #if defined(ENABLE_EXTENSIONS)
583 // By default, JavaScript and images are enabled in guest content.
584 void GetGuestViewDefaultContentSettingRules(
586 RendererContentSettingRules
* rules
) {
587 rules
->image_rules
.push_back(
588 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
589 ContentSettingsPattern::Wildcard(),
590 CONTENT_SETTING_ALLOW
,
594 rules
->script_rules
.push_back(
595 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
596 ContentSettingsPattern::Wildcard(),
597 CONTENT_SETTING_ALLOW
,
601 #endif // defined(ENALBE_EXTENSIONS)
603 content::PermissionStatus
604 ContentSettingToPermissionStatus(ContentSetting setting
) {
606 case CONTENT_SETTING_ALLOW
:
607 case CONTENT_SETTING_SESSION_ONLY
:
608 return content::PERMISSION_STATUS_GRANTED
;
609 case CONTENT_SETTING_BLOCK
:
610 return content::PERMISSION_STATUS_DENIED
;
611 case CONTENT_SETTING_ASK
:
612 return content::PERMISSION_STATUS_ASK
;
613 case CONTENT_SETTING_DETECT_IMPORTANT_CONTENT
:
614 case CONTENT_SETTING_DEFAULT
:
615 case CONTENT_SETTING_NUM_SETTINGS
:
619 return content::PERMISSION_STATUS_DENIED
;
626 ChromeContentBrowserClient::ChromeContentBrowserClient()
627 : prerender_tracker_(NULL
),
628 weak_factory_(this) {
629 #if defined(ENABLE_PLUGINS)
630 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedDevChannelOrigins
); ++i
)
631 allowed_dev_channel_origins_
.insert(kPredefinedAllowedDevChannelOrigins
[i
]);
632 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedFileHandleOrigins
); ++i
)
633 allowed_file_handle_origins_
.insert(kPredefinedAllowedFileHandleOrigins
[i
]);
634 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedSocketOrigins
); ++i
)
635 allowed_socket_origins_
.insert(kPredefinedAllowedSocketOrigins
[i
]);
637 extra_parts_
.push_back(new ChromeContentBrowserClientPluginsPart
);
640 #if !defined(OS_ANDROID)
641 TtsExtensionEngine
* tts_extension_engine
= TtsExtensionEngine::GetInstance();
642 TtsController::GetInstance()->SetTtsEngineDelegate(tts_extension_engine
);
645 #if defined(ENABLE_EXTENSIONS)
646 extra_parts_
.push_back(new ChromeContentBrowserClientExtensionsPart
);
650 ChromeContentBrowserClient::~ChromeContentBrowserClient() {
651 for (int i
= static_cast<int>(extra_parts_
.size()) - 1; i
>= 0; --i
)
652 delete extra_parts_
[i
];
653 extra_parts_
.clear();
657 void ChromeContentBrowserClient::RegisterProfilePrefs(
658 user_prefs::PrefRegistrySyncable
* registry
) {
659 registry
->RegisterBooleanPref(
660 prefs::kDisable3DAPIs
,
662 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
663 registry
->RegisterBooleanPref(
664 prefs::kEnableHyperlinkAuditing
,
666 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
667 registry
->RegisterListPref(
668 prefs::kEnableDeprecatedWebPlatformFeatures
,
669 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
673 void ChromeContentBrowserClient::SetApplicationLocale(
674 const std::string
& locale
) {
675 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
677 // This object is guaranteed to outlive all threads so we don't have to
678 // worry about the lack of refcounting and can just post as Unretained.
680 // The common case is that this function is called early in Chrome startup
681 // before any threads are created (it will also be called later if the user
682 // changes the pref). In this case, there will be no threads created and
683 // posting will fail. When there are no threads, we can just set the string
684 // without worrying about threadsafety.
685 if (!BrowserThread::PostTask(BrowserThread::IO
, FROM_HERE
,
686 base::Bind(&SetApplicationLocaleOnIOThread
, locale
))) {
687 g_io_thread_application_locale
.Get() = locale
;
691 content::BrowserMainParts
* ChromeContentBrowserClient::CreateBrowserMainParts(
692 const content::MainFunctionParams
& parameters
) {
693 ChromeBrowserMainParts
* main_parts
;
694 // Construct the Main browser parts based on the OS type.
696 main_parts
= new ChromeBrowserMainPartsWin(parameters
);
697 #elif defined(OS_MACOSX)
698 main_parts
= new ChromeBrowserMainPartsMac(parameters
);
699 #elif defined(OS_CHROMEOS)
700 main_parts
= new chromeos::ChromeBrowserMainPartsChromeos(parameters
);
701 #elif defined(OS_LINUX)
702 main_parts
= new ChromeBrowserMainPartsLinux(parameters
);
703 #elif defined(OS_ANDROID)
704 main_parts
= new ChromeBrowserMainPartsAndroid(parameters
);
705 #elif defined(OS_POSIX)
706 main_parts
= new ChromeBrowserMainPartsPosix(parameters
);
709 main_parts
= new ChromeBrowserMainParts(parameters
);
712 chrome::AddProfilesExtraParts(main_parts
);
714 // Construct additional browser parts. Stages are called in the order in
715 // which they are added.
716 #if defined(TOOLKIT_VIEWS)
717 main_parts
->AddParts(new ChromeBrowserMainExtraPartsViews());
720 // TODO(oshima): Athena on chrome currently requires USE_ASH to build.
721 // We should reduce the dependency as much as possible.
723 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAsh());
726 #if defined(USE_AURA)
727 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAura());
731 main_parts
->AddParts(new ChromeBrowserMainExtraPartsX11());
734 chrome::AddMetricsExtraParts(main_parts
);
739 std::string
ChromeContentBrowserClient::GetStoragePartitionIdForSite(
740 content::BrowserContext
* browser_context
,
742 std::string partition_id
;
744 // The partition ID for webview guest processes is the string value of its
745 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
746 if (site
.SchemeIs(content::kGuestScheme
)) {
747 partition_id
= site
.spec();
748 } else if (site
.GetOrigin().spec() == kChromeUIChromeSigninURL
&&
749 !switches::IsEnableWebviewBasedSignin()) {
750 // Chrome signin page has an embedded iframe of extension and web content,
751 // thus it must be isolated from other webUI pages.
752 partition_id
= site
.GetOrigin().spec();
755 DCHECK(IsValidStoragePartitionId(browser_context
, partition_id
));
759 bool ChromeContentBrowserClient::IsValidStoragePartitionId(
760 content::BrowserContext
* browser_context
,
761 const std::string
& partition_id
) {
762 // The default ID is empty and is always valid.
763 if (partition_id
.empty())
766 return GURL(partition_id
).is_valid();
769 void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
770 content::BrowserContext
* browser_context
,
773 std::string
* partition_domain
,
774 std::string
* partition_name
,
776 // Default to the browser-wide storage partition and override based on |site|
778 partition_domain
->clear();
779 partition_name
->clear();
782 bool success
= false;
783 #if defined(ENABLE_EXTENSIONS)
784 success
= extensions::WebViewGuest::GetGuestPartitionConfigForSite(
785 site
, partition_domain
, partition_name
, in_memory
);
787 if (!success
&& site
.SchemeIs(extensions::kExtensionScheme
)) {
788 // If |can_be_default| is false, the caller is stating that the |site|
789 // should be parsed as if it had isolated storage. In particular it is
790 // important to NOT check ExtensionService for the is_storage_isolated()
791 // attribute because this code path is run during Extension uninstall
792 // to do cleanup after the Extension has already been unloaded from the
794 bool is_isolated
= !can_be_default
;
795 if (can_be_default
) {
796 if (extensions::util::SiteHasIsolatedStorage(site
, browser_context
))
801 CHECK(site
.has_host());
802 // For extensions with isolated storage, the the host of the |site| is
803 // the |partition_domain|. The |in_memory| and |partition_name| are only
804 // used in guest schemes so they are cleared here.
805 *partition_domain
= site
.host();
807 partition_name
->clear();
813 if (!success
&& (site
.GetOrigin().spec() == kChromeUIChromeSigninURL
) &&
814 !switches::IsEnableWebviewBasedSignin()) {
815 // Chrome signin page has an embedded iframe of extension and web content,
816 // thus it must be isolated from other webUI pages.
817 *partition_domain
= chrome::kChromeUIChromeSigninHost
;
820 // Assert that if |can_be_default| is false, the code above must have found a
821 // non-default partition. If this fails, the caller has a serious logic
822 // error about which StoragePartition they expect to be in and it is not
824 CHECK(can_be_default
|| !partition_domain
->empty());
827 content::WebContentsViewDelegate
*
828 ChromeContentBrowserClient::GetWebContentsViewDelegate(
829 content::WebContents
* web_contents
) {
830 return chrome::CreateWebContentsViewDelegate(web_contents
);
833 void ChromeContentBrowserClient::RenderProcessWillLaunch(
834 content::RenderProcessHost
* host
) {
835 int id
= host
->GetID();
836 Profile
* profile
= Profile::FromBrowserContext(host
->GetBrowserContext());
837 net::URLRequestContextGetter
* context
=
838 profile
->GetRequestContextForRenderProcess(id
);
840 host
->AddFilter(new ChromeRenderMessageFilter(id
, profile
));
841 #if defined(ENABLE_EXTENSIONS)
842 host
->AddFilter(new cast::CastTransportHostFilter
);
844 #if defined(ENABLE_PRINTING)
845 host
->AddFilter(new printing::PrintingMessageFilter(id
, profile
));
847 host
->AddFilter(new SearchProviderInstallStateMessageFilter(id
, profile
));
848 #if defined(ENABLE_SPELLCHECK)
849 host
->AddFilter(new SpellCheckMessageFilter(id
));
851 #if defined(OS_MACOSX)
852 host
->AddFilter(new SpellCheckMessageFilterMac(id
));
854 host
->AddFilter(new ChromeNetBenchmarkingMessageFilter(profile
, context
));
855 host
->AddFilter(new prerender::PrerenderMessageFilter(id
, profile
));
856 host
->AddFilter(new TtsMessageFilter(id
, host
->GetBrowserContext()));
857 #if defined(ENABLE_WEBRTC)
858 WebRtcLoggingHandlerHost
* webrtc_logging_handler_host
=
859 new WebRtcLoggingHandlerHost(profile
);
860 host
->SetWebRtcLogMessageCallback(base::Bind(
861 &WebRtcLoggingHandlerHost::LogMessage
, webrtc_logging_handler_host
));
862 host
->AddFilter(webrtc_logging_handler_host
);
863 host
->SetUserData(host
, new base::UserDataAdapter
<WebRtcLoggingHandlerHost
>(
864 webrtc_logging_handler_host
));
866 #if !defined(DISABLE_NACL)
867 host
->AddFilter(new nacl::NaClHostMessageFilter(
868 id
, profile
->IsOffTheRecord(),
872 #if defined(OS_ANDROID)
873 host
->AddFilter(new cdm::CdmMessageFilterAndroid());
875 if (switches::IsEnableAccountConsistency())
876 host
->AddFilter(new PrincipalsMessageFilter(id
));
878 host
->Send(new ChromeViewMsg_SetIsIncognitoProcess(
879 profile
->IsOffTheRecord()));
881 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
882 extra_parts_
[i
]->RenderProcessWillLaunch(host
);
884 RendererContentSettingRules rules
;
885 if (host
->IsIsolatedGuest()) {
886 #if defined(ENABLE_EXTENSIONS)
887 GetGuestViewDefaultContentSettingRules(profile
->IsOffTheRecord(), &rules
);
892 GetRendererContentSettingRules(
893 profile
->GetHostContentSettingsMap(), &rules
);
895 host
->Send(new ChromeViewMsg_SetContentSettingRules(rules
));
898 GURL
ChromeContentBrowserClient::GetEffectiveURL(
899 content::BrowserContext
* browser_context
, const GURL
& url
) {
900 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
904 // If the input |url| should be assigned to the Instant renderer, make its
905 // effective URL distinct from other URLs on the search provider's domain.
906 if (chrome::ShouldAssignURLToInstantRenderer(url
, profile
))
907 return chrome::GetEffectiveURLForInstant(url
, profile
);
909 #if !defined(OS_CHROMEOS)
910 // If the input |url| should be assigned to the Signin renderer, make its
911 // effective URL distinct from other URLs on the signin service's domain.
912 // Note that the signin renderer will be allowed to sign the user in to
914 if (SigninManager::IsWebBasedSigninFlowURL(url
))
915 return GetEffectiveURLForSignin(url
);
918 #if defined(ENABLE_EXTENSIONS)
919 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(
926 bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
927 content::BrowserContext
* browser_context
, const GURL
& effective_url
) {
928 // Non-extension, non-Instant URLs should generally use
929 // process-per-site-instance. Because we expect to use the effective URL,
930 // URLs for hosted apps (apart from bookmark apps) should have an extension
933 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
937 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url
, profile
))
940 #if !defined(OS_CHROMEOS)
941 if (SigninManager::IsWebBasedSigninFlowURL(effective_url
))
945 #if defined(ENABLE_EXTENSIONS)
946 return ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
947 profile
, effective_url
);
953 // These are treated as WebUI schemes but do not get WebUI bindings. Also,
954 // view-source is allowed for these schemes.
955 void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
956 std::vector
<std::string
>* additional_schemes
) {
957 additional_schemes
->push_back(chrome::kChromeSearchScheme
);
958 additional_schemes
->push_back(dom_distiller::kDomDistillerScheme
);
961 void ChromeContentBrowserClient::GetAdditionalWebUIHostsToIgnoreParititionCheck(
962 std::vector
<std::string
>* hosts
) {
963 hosts
->push_back(chrome::kChromeUIExtensionIconHost
);
964 hosts
->push_back(chrome::kChromeUIFaviconHost
);
965 hosts
->push_back(chrome::kChromeUIThemeHost
);
966 hosts
->push_back(chrome::kChromeUIThumbnailHost
);
967 hosts
->push_back(chrome::kChromeUIThumbnailHost2
);
968 hosts
->push_back(chrome::kChromeUIThumbnailListHost
);
971 net::URLRequestContextGetter
*
972 ChromeContentBrowserClient::CreateRequestContext(
973 content::BrowserContext
* browser_context
,
974 content::ProtocolHandlerMap
* protocol_handlers
,
975 content::URLRequestInterceptorScopedVector request_interceptors
) {
976 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
977 return profile
->CreateRequestContext(protocol_handlers
,
978 request_interceptors
.Pass());
981 net::URLRequestContextGetter
*
982 ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
983 content::BrowserContext
* browser_context
,
984 const base::FilePath
& partition_path
,
986 content::ProtocolHandlerMap
* protocol_handlers
,
987 content::URLRequestInterceptorScopedVector request_interceptors
) {
988 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
989 return profile
->CreateRequestContextForStoragePartition(
993 request_interceptors
.Pass());
996 bool ChromeContentBrowserClient::IsHandledURL(const GURL
& url
) {
997 return ProfileIOData::IsHandledURL(url
);
1000 bool ChromeContentBrowserClient::CanCommitURL(
1001 content::RenderProcessHost
* process_host
,
1003 #if defined(ENABLE_EXTENSIONS)
1004 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(
1011 bool ChromeContentBrowserClient::ShouldAllowOpenURL(
1012 content::SiteInstance
* site_instance
, const GURL
& url
) {
1013 GURL from_url
= site_instance
->GetSiteURL();
1015 #if defined(ENABLE_EXTENSIONS)
1017 if (ChromeContentBrowserClientExtensionsPart::ShouldAllowOpenURL(
1018 site_instance
, from_url
, url
, &result
))
1022 // Do not allow chrome://chrome-signin navigate to other chrome:// URLs, since
1023 // the signin page may host untrusted web content.
1024 if (from_url
.GetOrigin().spec() == chrome::kChromeUIChromeSigninURL
&&
1025 url
.SchemeIs(content::kChromeUIScheme
) &&
1026 url
.host() != chrome::kChromeUIChromeSigninHost
) {
1027 VLOG(1) << "Blocked navigation to " << url
.spec() << " from "
1028 << chrome::kChromeUIChromeSigninURL
;
1035 bool ChromeContentBrowserClient::IsSuitableHost(
1036 content::RenderProcessHost
* process_host
,
1037 const GURL
& site_url
) {
1039 Profile::FromBrowserContext(process_host
->GetBrowserContext());
1040 // This may be NULL during tests. In that case, just assume any site can
1045 // Instant URLs should only be in the instant process and instant process
1046 // should only have Instant URLs.
1047 InstantService
* instant_service
=
1048 InstantServiceFactory::GetForProfile(profile
);
1049 if (instant_service
) {
1050 bool is_instant_process
= instant_service
->IsInstantProcess(
1051 process_host
->GetID());
1052 bool should_be_in_instant_process
=
1053 chrome::ShouldAssignURLToInstantRenderer(site_url
, profile
);
1054 if (is_instant_process
|| should_be_in_instant_process
)
1055 return is_instant_process
&& should_be_in_instant_process
;
1058 #if !defined(OS_CHROMEOS)
1059 SigninClient
* signin_client
=
1060 ChromeSigninClientFactory::GetForProfile(profile
);
1061 if (signin_client
&& signin_client
->IsSigninProcess(process_host
->GetID()))
1062 return SigninManager::IsWebBasedSigninFlowURL(site_url
);
1065 #if defined(ENABLE_EXTENSIONS)
1066 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1067 profile
, process_host
, site_url
);
1073 bool ChromeContentBrowserClient::MayReuseHost(
1074 content::RenderProcessHost
* process_host
) {
1075 // If there is currently a prerender in progress for the host provided,
1076 // it may not be shared. We require prerenders to be by themselves in a
1077 // separate process, so that we can monitor their resource usage, and so that
1078 // we can track the cookies that they change.
1079 Profile
* profile
= Profile::FromBrowserContext(
1080 process_host
->GetBrowserContext());
1081 prerender::PrerenderManager
* prerender_manager
=
1082 prerender::PrerenderManagerFactory::GetForProfile(profile
);
1083 if (prerender_manager
&&
1084 !prerender_manager
->MayReuseProcessHost(process_host
)) {
1091 bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1092 content::BrowserContext
* browser_context
, const GURL
& url
) {
1093 // It has to be a valid URL for us to check for an extension.
1094 if (!url
.is_valid())
1097 #if defined(ENABLE_EXTENSIONS)
1098 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1099 return ChromeContentBrowserClientExtensionsPart::
1100 ShouldTryToUseExistingProcessHost(
1107 void ChromeContentBrowserClient::SiteInstanceGotProcess(
1108 SiteInstance
* site_instance
) {
1109 CHECK(site_instance
->HasProcess());
1111 Profile
* profile
= Profile::FromBrowserContext(
1112 site_instance
->GetBrowserContext());
1116 // Remember the ID of the Instant process to signal the renderer process
1117 // on startup in |AppendExtraCommandLineSwitches| below.
1118 if (chrome::ShouldAssignURLToInstantRenderer(
1119 site_instance
->GetSiteURL(), profile
)) {
1120 InstantService
* instant_service
=
1121 InstantServiceFactory::GetForProfile(profile
);
1122 if (instant_service
)
1123 instant_service
->AddInstantProcess(site_instance
->GetProcess()->GetID());
1126 #if !defined(OS_CHROMEOS)
1127 // We only expect there to be one signin process as we use process-per-site
1128 // for signin URLs. The signin process will be cleared from SigninManager
1129 // when the renderer is destroyed.
1130 if (SigninManager::IsWebBasedSigninFlowURL(site_instance
->GetSiteURL())) {
1131 SigninClient
* signin_client
=
1132 ChromeSigninClientFactory::GetForProfile(profile
);
1134 signin_client
->SetSigninProcess(site_instance
->GetProcess()->GetID());
1135 #if defined(ENABLE_EXTENSIONS)
1136 ChromeContentBrowserClientExtensionsPart::SetSigninProcess(site_instance
);
1141 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
1142 extra_parts_
[i
]->SiteInstanceGotProcess(site_instance
);
1145 void ChromeContentBrowserClient::SiteInstanceDeleting(
1146 SiteInstance
* site_instance
) {
1147 if (!site_instance
->HasProcess())
1150 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
1151 extra_parts_
[i
]->SiteInstanceDeleting(site_instance
);
1154 bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
1155 SiteInstance
* site_instance
,
1156 const GURL
& current_url
,
1157 const GURL
& new_url
) {
1158 #if defined(ENABLE_EXTENSIONS)
1159 return ChromeContentBrowserClientExtensionsPart::
1160 ShouldSwapBrowsingInstancesForNavigation(
1161 site_instance
, current_url
, new_url
);
1167 bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1168 content::ResourceContext
* resource_context
, const GURL
& current_url
,
1169 const GURL
& new_url
) {
1170 #if defined(ENABLE_EXTENSIONS)
1171 return ChromeContentBrowserClientExtensionsPart::
1172 ShouldSwapProcessesForRedirect(resource_context
, current_url
, new_url
);
1178 bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL
& url
) {
1179 return !url
.SchemeIs(chrome::kChromeNativeScheme
);
1182 std::string
ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1183 const std::string
& alias_name
) {
1184 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name
);
1189 bool IsAutoReloadEnabled() {
1190 // Fetch the field trial, even though we don't use it. Calling FindFullName()
1191 // causes the field-trial mechanism to report which group we're in, which
1192 // might reflect a hard disable or hard enable via flag, both of which have
1193 // their own field trial groups. This lets us know what percentage of users
1194 // manually enable or disable auto-reload.
1195 std::string group
= base::FieldTrialList::FindFullName(
1196 "AutoReloadExperiment");
1197 const base::CommandLine
& browser_command_line
=
1198 *base::CommandLine::ForCurrentProcess();
1199 if (browser_command_line
.HasSwitch(switches::kEnableOfflineAutoReload
))
1201 if (browser_command_line
.HasSwitch(switches::kDisableOfflineAutoReload
))
1206 bool IsAutoReloadVisibleOnlyEnabled() {
1207 // See the block comment in IsAutoReloadEnabled().
1208 std::string group
= base::FieldTrialList::FindFullName(
1209 "AutoReloadVisibleOnlyExperiment");
1210 const base::CommandLine
& browser_command_line
=
1211 *base::CommandLine::ForCurrentProcess();
1212 if (browser_command_line
.HasSwitch(
1213 switches::kEnableOfflineAutoReloadVisibleOnly
)) {
1216 if (browser_command_line
.HasSwitch(
1217 switches::kDisableOfflineAutoReloadVisibleOnly
)) {
1225 void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1226 base::CommandLine
* command_line
,
1227 int child_process_id
) {
1228 #if defined(OS_POSIX)
1229 if (breakpad::IsCrashReporterEnabled()) {
1230 scoped_ptr
<metrics::ClientInfo
> client_info
=
1231 GoogleUpdateSettings::LoadMetricsClientInfo();
1232 command_line
->AppendSwitchASCII(switches::kEnableCrashReporter
,
1233 client_info
? client_info
->client_id
1236 #endif // defined(OS_POSIX)
1238 if (logging::DialogsAreSuppressed())
1239 command_line
->AppendSwitch(switches::kNoErrorDialogs
);
1241 std::string process_type
=
1242 command_line
->GetSwitchValueASCII(switches::kProcessType
);
1243 const base::CommandLine
& browser_command_line
=
1244 *base::CommandLine::ForCurrentProcess();
1246 static const char* const kCommonSwitchNames
[] = {
1247 switches::kUserAgent
,
1248 switches::kUserDataDir
, // Make logs go to the right file.
1250 command_line
->CopySwitchesFrom(browser_command_line
, kCommonSwitchNames
,
1251 arraysize(kCommonSwitchNames
));
1253 #if defined(ENABLE_IPC_FUZZER)
1254 static const char* const kIpcFuzzerSwitches
[] = {
1255 switches::kIpcFuzzerTestcase
,
1257 command_line
->CopySwitchesFrom(browser_command_line
, kIpcFuzzerSwitches
,
1258 arraysize(kIpcFuzzerSwitches
));
1261 #if defined(OS_CHROMEOS)
1262 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
1263 base::FilePath homedir
;
1264 PathService::Get(base::DIR_HOME
, &homedir
);
1265 command_line
->AppendSwitchASCII(chromeos::switches::kHomedir
,
1266 homedir
.value().c_str());
1269 if (process_type
== switches::kRendererProcess
) {
1270 content::RenderProcessHost
* process
=
1271 content::RenderProcessHost::FromID(child_process_id
);
1273 process
? Profile::FromBrowserContext(process
->GetBrowserContext())
1275 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
1276 extra_parts_
[i
]->AppendExtraRendererCommandLineSwitches(
1277 command_line
, process
, profile
);
1280 #if defined(OS_CHROMEOS)
1281 const std::string
& login_profile
=
1282 browser_command_line
.GetSwitchValueASCII(
1283 chromeos::switches::kLoginProfile
);
1284 if (!login_profile
.empty())
1285 command_line
->AppendSwitchASCII(
1286 chromeos::switches::kLoginProfile
, login_profile
);
1289 #if defined(ENABLE_WEBRTC)
1290 MaybeCopyDisableWebRtcEncryptionSwitch(command_line
,
1291 browser_command_line
,
1292 VersionInfo::GetChannel());
1296 PrefService
* prefs
= profile
->GetPrefs();
1297 // Currently this pref is only registered if applied via a policy.
1298 if (prefs
->HasPrefPath(prefs::kDisable3DAPIs
) &&
1299 prefs
->GetBoolean(prefs::kDisable3DAPIs
)) {
1300 // Turn this policy into a command line switch.
1301 command_line
->AppendSwitch(switches::kDisable3DAPIs
);
1304 const base::ListValue
* switches
=
1305 prefs
->GetList(prefs::kEnableDeprecatedWebPlatformFeatures
);
1307 // Enable any deprecated features that have been re-enabled by policy.
1308 for (base::ListValue::const_iterator it
= switches
->begin();
1309 it
!= switches
->end(); ++it
) {
1310 std::string switch_to_enable
;
1311 if ((*it
)->GetAsString(&switch_to_enable
))
1312 command_line
->AppendSwitch(switch_to_enable
);
1316 // Disable client-side phishing detection in the renderer if it is
1317 // disabled in the Profile preferences or the browser process.
1318 if (!prefs
->GetBoolean(prefs::kSafeBrowsingEnabled
) ||
1319 !g_browser_process
->safe_browsing_detection_service()) {
1320 command_line
->AppendSwitch(
1321 switches::kDisableClientSidePhishingDetection
);
1324 if (prefs
->GetBoolean(prefs::kPrintPreviewDisabled
))
1325 command_line
->AppendSwitch(switches::kDisablePrintPreview
);
1327 InstantService
* instant_service
=
1328 InstantServiceFactory::GetForProfile(profile
);
1329 if (instant_service
&&
1330 instant_service
->IsInstantProcess(process
->GetID()))
1331 command_line
->AppendSwitch(switches::kInstantProcess
);
1333 #if !defined(OS_CHROMEOS)
1334 SigninClient
* signin_client
=
1335 ChromeSigninClientFactory::GetForProfile(profile
);
1336 if (signin_client
&& signin_client
->IsSigninProcess(process
->GetID()))
1337 command_line
->AppendSwitch(switches::kSigninProcess
);
1341 if (IsAutoReloadEnabled())
1342 command_line
->AppendSwitch(switches::kEnableOfflineAutoReload
);
1343 if (IsAutoReloadVisibleOnlyEnabled()) {
1344 command_line
->AppendSwitch(
1345 switches::kEnableOfflineAutoReloadVisibleOnly
);
1349 // Enable load stale cache if this session is in the field trial or
1350 // the user explicitly enabled it. Note that as far as the renderer
1351 // is concerned, the feature is enabled if-and-only-if the
1352 // kEnableOfflineLoadStaleCache flag is on the command line;
1353 // the yes/no/default behavior is only at the browser command line
1356 // Command line switches override
1357 if (browser_command_line
.HasSwitch(
1358 switches::kEnableOfflineLoadStaleCache
)) {
1359 command_line
->AppendSwitch(switches::kEnableOfflineLoadStaleCache
);
1360 } else if (!browser_command_line
.HasSwitch(
1361 switches::kDisableOfflineLoadStaleCache
)) {
1363 base::FieldTrialList::FindFullName("LoadStaleCacheExperiment");
1365 if (group
== "Enabled")
1366 command_line
->AppendSwitch(switches::kEnableOfflineLoadStaleCache
);
1370 // Please keep this in alphabetical order.
1371 static const char* const kSwitchNames
[] = {
1372 autofill::switches::kDisableFillOnAccountSelect
,
1373 autofill::switches::kDisablePasswordGeneration
,
1374 autofill::switches::kEnableFillOnAccountSelect
,
1375 autofill::switches::kEnableFillOnAccountSelectNoHighlighting
,
1376 autofill::switches::kEnablePasswordGeneration
,
1377 autofill::switches::kEnablePasswordSaveOnInPageNavigation
,
1378 autofill::switches::kEnableSingleClickAutofill
,
1379 autofill::switches::kIgnoreAutocompleteOffForAutofill
,
1380 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration
,
1381 autofill::switches::kRespectAutocompleteOffForAutofill
,
1382 #if defined(ENABLE_EXTENSIONS)
1383 extensions::switches::kAllowHTTPBackgroundPage
,
1384 extensions::switches::kAllowLegacyExtensionManifests
,
1385 extensions::switches::kEnableSurfaceWorker
,
1386 extensions::switches::kEnableAppWindowControls
,
1387 extensions::switches::kEnableEmbeddedExtensionOptions
,
1388 extensions::switches::kEnableExperimentalExtensionApis
,
1389 extensions::switches::kEnableScriptsRequireAction
,
1390 extensions::switches::kExtensionsOnChromeURLs
,
1391 extensions::switches::kWhitelistedExtensionID
,
1393 switches::kAppsCheckoutURL
,
1394 switches::kAppsGalleryURL
,
1395 switches::kCloudPrintURL
,
1396 switches::kCloudPrintXmppEndpoint
,
1397 switches::kDisableBundledPpapiFlash
,
1398 switches::kDisableCastStreamingHWEncoding
,
1399 switches::kDisableJavaScriptHarmonyShipping
,
1400 switches::kDisableOutOfProcessPdf
,
1401 switches::kEnableBenchmarking
,
1402 switches::kEnableNaCl
,
1403 #if !defined(DISABLE_NACL)
1404 switches::kEnableNaClDebug
,
1405 switches::kEnableNaClNonSfiMode
,
1407 switches::kEnableNetBenchmarking
,
1408 switches::kEnableNewBookmarkApps
,
1409 switches::kEnableOutOfProcessPdf
,
1410 switches::kEnablePluginPlaceholderShadowDom
,
1411 switches::kEnableShowModalDialog
,
1412 switches::kEnableWebBasedSignin
,
1413 switches::kJavaScriptHarmony
,
1414 switches::kMessageLoopHistogrammer
,
1415 switches::kPlaybackMode
,
1416 switches::kPpapiFlashArgs
,
1417 switches::kPpapiFlashPath
,
1418 switches::kPpapiFlashVersion
,
1419 switches::kProfilingAtStart
,
1420 switches::kProfilingFile
,
1421 switches::kProfilingFlush
,
1422 switches::kRecordMode
,
1423 translate::switches::kTranslateSecurityOrigin
,
1426 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1427 arraysize(kSwitchNames
));
1428 } else if (process_type
== switches::kUtilityProcess
) {
1429 #if defined(ENABLE_EXTENSIONS)
1430 static const char* const kSwitchNames
[] = {
1431 extensions::switches::kAllowHTTPBackgroundPage
,
1432 extensions::switches::kEnableExperimentalExtensionApis
,
1433 extensions::switches::kExtensionsOnChromeURLs
,
1434 extensions::switches::kWhitelistedExtensionID
,
1437 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1438 arraysize(kSwitchNames
));
1440 } else if (process_type
== switches::kPluginProcess
) {
1441 #if defined(OS_CHROMEOS)
1442 static const char* const kSwitchNames
[] = {
1443 chromeos::switches::kLoginProfile
,
1446 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1447 arraysize(kSwitchNames
));
1449 } else if (process_type
== switches::kZygoteProcess
) {
1450 static const char* const kSwitchNames
[] = {
1451 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
1452 switches::kDisableBundledPpapiFlash
,
1453 #if !defined(DISABLE_NACL)
1454 switches::kEnableNaClDebug
,
1455 switches::kEnableNaClNonSfiMode
,
1456 switches::kNaClDangerousNoSandboxNonSfi
,
1457 switches::kUseNaClHelperNonSfi
,
1459 switches::kPpapiFlashPath
,
1460 switches::kPpapiFlashVersion
,
1463 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1464 arraysize(kSwitchNames
));
1465 } else if (process_type
== switches::kGpuProcess
) {
1466 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1467 // because GPU is expected to be unreliable.
1468 if (browser_command_line
.HasSwitch(switches::kIgnoreGpuBlacklist
) &&
1469 !command_line
->HasSwitch(switches::kDisableBreakpad
))
1470 command_line
->AppendSwitch(switches::kDisableBreakpad
);
1473 // The command line switch kEnableBenchmarking needs to be specified along
1474 // with the kEnableStatsTable switch to ensure that the stats table global
1475 // is initialized correctly.
1476 if (command_line
->HasSwitch(switches::kEnableBenchmarking
))
1477 DCHECK(command_line
->HasSwitch(switches::kEnableStatsTable
));
1480 std::string
ChromeContentBrowserClient::GetApplicationLocale() {
1481 if (BrowserThread::CurrentlyOn(BrowserThread::IO
))
1482 return g_io_thread_application_locale
.Get();
1483 return g_browser_process
->GetApplicationLocale();
1486 std::string
ChromeContentBrowserClient::GetAcceptLangs(
1487 content::BrowserContext
* context
) {
1488 Profile
* profile
= Profile::FromBrowserContext(context
);
1489 return profile
->GetPrefs()->GetString(prefs::kAcceptLanguages
);
1492 const gfx::ImageSkia
* ChromeContentBrowserClient::GetDefaultFavicon() {
1493 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
1494 return rb
.GetNativeImageNamed(IDR_DEFAULT_FAVICON
).ToImageSkia();
1497 bool ChromeContentBrowserClient::AllowAppCache(
1498 const GURL
& manifest_url
,
1499 const GURL
& first_party
,
1500 content::ResourceContext
* context
) {
1501 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1502 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1503 return io_data
->GetCookieSettings()->
1504 IsSettingCookieAllowed(manifest_url
, first_party
);
1507 bool ChromeContentBrowserClient::AllowServiceWorker(
1509 const GURL
& first_party_url
,
1510 content::ResourceContext
* context
) {
1511 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1512 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1513 return io_data
->GetCookieSettings()->
1514 IsSettingCookieAllowed(scope
, first_party_url
);
1517 bool ChromeContentBrowserClient::AllowGetCookie(
1519 const GURL
& first_party
,
1520 const net::CookieList
& cookie_list
,
1521 content::ResourceContext
* context
,
1522 int render_process_id
,
1523 int render_frame_id
) {
1524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1525 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1526 bool allow
= io_data
->GetCookieSettings()->
1527 IsReadingCookieAllowed(url
, first_party
);
1529 BrowserThread::PostTask(
1530 BrowserThread::UI
, FROM_HERE
,
1531 base::Bind(&TabSpecificContentSettings::CookiesRead
, render_process_id
,
1532 render_frame_id
, url
, first_party
, cookie_list
, !allow
, true));
1536 bool ChromeContentBrowserClient::AllowSetCookie(
1538 const GURL
& first_party
,
1539 const std::string
& cookie_line
,
1540 content::ResourceContext
* context
,
1541 int render_process_id
,
1542 int render_frame_id
,
1543 net::CookieOptions
* options
) {
1544 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1545 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1546 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1547 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, first_party
);
1549 if (prerender_tracker_
) {
1550 prerender_tracker_
->OnCookieChangedForURL(
1552 context
->GetRequestContext()->cookie_store()->GetCookieMonster(),
1556 BrowserThread::PostTask(
1557 BrowserThread::UI
, FROM_HERE
,
1558 base::Bind(&TabSpecificContentSettings::CookieChanged
, render_process_id
,
1559 render_frame_id
, url
, first_party
, cookie_line
, *options
,
1564 bool ChromeContentBrowserClient::AllowSaveLocalState(
1565 content::ResourceContext
* context
) {
1566 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1567 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1568 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1569 ContentSetting setting
= cookie_settings
->GetDefaultCookieSetting(NULL
);
1571 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1572 // Could we even support per-origin settings?
1573 return setting
!= CONTENT_SETTING_SESSION_ONLY
;
1576 bool ChromeContentBrowserClient::AllowWorkerDatabase(
1578 const base::string16
& name
,
1579 const base::string16
& display_name
,
1580 unsigned long estimated_size
,
1581 content::ResourceContext
* context
,
1582 const std::vector
<std::pair
<int, int> >& render_frames
) {
1583 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1584 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1585 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1586 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1588 // Record access to database for potential display in UI.
1589 std::vector
<std::pair
<int, int> >::const_iterator i
;
1590 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1591 BrowserThread::PostTask(
1592 BrowserThread::UI
, FROM_HERE
,
1593 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed
,
1594 i
->first
, i
->second
, url
, name
, display_name
, !allow
));
1600 void ChromeContentBrowserClient::AllowWorkerFileSystem(
1602 content::ResourceContext
* context
,
1603 const std::vector
<std::pair
<int, int> >& render_frames
,
1604 base::Callback
<void(bool)> callback
) {
1605 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1606 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1607 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1608 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1610 #if defined(ENABLE_EXTENSIONS)
1611 GuestPermissionRequestHelper(url
, render_frames
, callback
, allow
);
1613 FileSystemAccessed(url
, render_frames
, callback
, allow
);
1617 #if defined(ENABLE_EXTENSIONS)
1618 void ChromeContentBrowserClient::GuestPermissionRequestHelper(
1620 const std::vector
<std::pair
<int, int> >& render_frames
,
1621 base::Callback
<void(bool)> callback
,
1623 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::IO
));
1624 std::vector
<std::pair
<int, int> >::const_iterator i
;
1625 std::map
<int, int> process_map
;
1626 std::map
<int, int>::const_iterator it
;
1627 bool has_web_view_guest
= false;
1628 // Record access to file system for potential display in UI.
1629 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1630 if (process_map
.find(i
->first
) != process_map
.end())
1633 process_map
.insert(std::pair
<int, int>(i
->first
, i
->second
));
1635 if (extensions::WebViewRendererState::GetInstance()->IsGuest(i
->first
))
1636 has_web_view_guest
= true;
1638 if (!has_web_view_guest
) {
1639 FileSystemAccessed(url
, render_frames
, callback
, allow
);
1642 DCHECK_EQ(1U, process_map
.size());
1643 it
= process_map
.begin();
1644 BrowserThread::PostTask(
1647 base::Bind(&ChromeContentBrowserClient::
1648 RequestFileSystemPermissionOnUIThread
,
1653 base::Bind(&ChromeContentBrowserClient::FileSystemAccessed
,
1654 weak_factory_
.GetWeakPtr(),
1660 void ChromeContentBrowserClient::RequestFileSystemPermissionOnUIThread(
1661 int render_process_id
,
1662 int render_frame_id
,
1664 bool allowed_by_default
,
1665 const base::Callback
<void(bool)>& callback
) {
1666 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::UI
));
1667 extensions::WebViewPermissionHelper
* web_view_permission_helper
=
1668 extensions::WebViewPermissionHelper::FromFrameID(
1669 render_process_id
, render_frame_id
);
1670 web_view_permission_helper
->RequestFileSystemPermission(url
,
1676 void ChromeContentBrowserClient::FileSystemAccessed(
1678 const std::vector
<std::pair
<int, int> >& render_frames
,
1679 base::Callback
<void(bool)> callback
,
1681 // Record access to file system for potential display in UI.
1682 std::vector
<std::pair
<int, int> >::const_iterator i
;
1683 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1684 BrowserThread::PostTask(
1687 base::Bind(&TabSpecificContentSettings::FileSystemAccessed
,
1688 i
->first
, i
->second
, url
, !allow
));
1690 callback
.Run(allow
);
1693 bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1695 const base::string16
& name
,
1696 content::ResourceContext
* context
,
1697 const std::vector
<std::pair
<int, int> >& render_frames
) {
1698 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1699 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1700 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1701 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1703 // Record access to IndexedDB for potential display in UI.
1704 std::vector
<std::pair
<int, int> >::const_iterator i
;
1705 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1706 BrowserThread::PostTask(
1707 BrowserThread::UI
, FROM_HERE
,
1708 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed
,
1709 i
->first
, i
->second
, url
, name
, !allow
));
1715 net::URLRequestContext
*
1716 ChromeContentBrowserClient::OverrideRequestContextForURL(
1717 const GURL
& url
, content::ResourceContext
* context
) {
1718 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1719 #if defined(ENABLE_EXTENSIONS)
1720 if (url
.SchemeIs(extensions::kExtensionScheme
)) {
1721 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1722 return io_data
->extensions_request_context();
1729 QuotaPermissionContext
*
1730 ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1731 return new ChromeQuotaPermissionContext();
1734 void ChromeContentBrowserClient::AllowCertificateError(
1735 int render_process_id
,
1736 int render_frame_id
,
1738 const net::SSLInfo
& ssl_info
,
1739 const GURL
& request_url
,
1740 ResourceType resource_type
,
1742 bool strict_enforcement
,
1743 bool expired_previous_decision
,
1744 const base::Callback
<void(bool)>& callback
,
1745 content::CertificateRequestResultType
* result
) {
1746 if (resource_type
!= content::RESOURCE_TYPE_MAIN_FRAME
) {
1747 // A sub-resource has a certificate error. The user doesn't really
1748 // have a context for making the right decision, so block the
1749 // request hard, without an info bar to allow showing the insecure
1751 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY
;
1755 // If the tab is being prerendered, cancel the prerender and the request.
1756 content::RenderFrameHost
* render_frame_host
=
1757 content::RenderFrameHost::FromID(render_process_id
, render_frame_id
);
1758 WebContents
* tab
= WebContents::FromRenderFrameHost(render_frame_host
);
1764 prerender::PrerenderContents
* prerender_contents
=
1765 prerender::PrerenderContents::FromWebContents(tab
);
1766 if (prerender_contents
) {
1767 prerender_contents
->Destroy(prerender::FINAL_STATUS_SSL_ERROR
);
1768 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL
;
1772 // Otherwise, display an SSL blocking page. The interstitial page takes
1773 // ownership of ssl_blocking_page.
1774 int options_mask
= 0;
1776 options_mask
|= SSLBlockingPage::OVERRIDABLE
;
1777 if (strict_enforcement
)
1778 options_mask
|= SSLBlockingPage::STRICT_ENFORCEMENT
;
1779 if (expired_previous_decision
)
1780 options_mask
|= SSLBlockingPage::EXPIRED_BUT_PREVIOUSLY_ALLOWED
;
1782 SSLErrorHandler::HandleSSLError(
1783 tab
, cert_error
, ssl_info
, request_url
, options_mask
, callback
);
1786 void ChromeContentBrowserClient::SelectClientCertificate(
1787 int render_process_id
,
1788 int render_frame_id
,
1789 net::SSLCertRequestInfo
* cert_request_info
,
1790 const base::Callback
<void(net::X509Certificate
*)>& callback
) {
1791 content::RenderFrameHost
* rfh
= content::RenderFrameHost::FromID(
1792 render_process_id
, render_frame_id
);
1793 WebContents
* tab
= WebContents::FromRenderFrameHost(rfh
);
1795 // TODO(davidben): This makes the request hang, but returning no certificate
1796 // also breaks. It should abort the request. See https://crbug.com/417092
1800 prerender::PrerenderContents
* prerender_contents
=
1801 prerender::PrerenderContents::FromWebContents(tab
);
1802 if (prerender_contents
) {
1803 prerender_contents
->Destroy(
1804 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED
);
1808 GURL
requesting_url("https://" + cert_request_info
->host_and_port
.ToString());
1809 DCHECK(requesting_url
.is_valid())
1810 << "Invalid URL string: https://"
1811 << cert_request_info
->host_and_port
.ToString();
1813 Profile
* profile
= Profile::FromBrowserContext(tab
->GetBrowserContext());
1814 scoped_ptr
<base::Value
> filter
=
1815 profile
->GetHostContentSettingsMap()->GetWebsiteSetting(
1818 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE
,
1823 // Try to automatically select a client certificate.
1824 if (filter
->IsType(base::Value::TYPE_DICTIONARY
)) {
1825 base::DictionaryValue
* filter_dict
=
1826 static_cast<base::DictionaryValue
*>(filter
.get());
1828 const std::vector
<scoped_refptr
<net::X509Certificate
> >&
1829 all_client_certs
= cert_request_info
->client_certs
;
1830 for (size_t i
= 0; i
< all_client_certs
.size(); ++i
) {
1831 if (CertMatchesFilter(*all_client_certs
[i
].get(), *filter_dict
)) {
1832 // Use the first certificate that is matched by the filter.
1833 callback
.Run(all_client_certs
[i
].get());
1842 chrome::ShowSSLClientCertificateSelector(tab
, cert_request_info
, callback
);
1845 void ChromeContentBrowserClient::AddCertificate(
1846 net::CertificateMimeType cert_type
,
1847 const void* cert_data
,
1849 int render_process_id
,
1850 int render_frame_id
) {
1851 chrome::SSLAddCertificate(cert_type
, cert_data
, cert_size
,
1852 render_process_id
, render_frame_id
);
1855 content::MediaObserver
* ChromeContentBrowserClient::GetMediaObserver() {
1856 return MediaCaptureDevicesDispatcher::GetInstance();
1859 content::PlatformNotificationService
*
1860 ChromeContentBrowserClient::GetPlatformNotificationService() {
1861 #if defined(ENABLE_NOTIFICATIONS)
1862 return PlatformNotificationServiceImpl::GetInstance();
1869 void ChromeContentBrowserClient::RequestPermission(
1870 content::PermissionType permission
,
1871 content::WebContents
* web_contents
,
1873 const GURL
& requesting_frame
,
1875 const base::Callback
<void(bool)>& result_callback
) {
1876 int render_process_id
= web_contents
->GetRenderProcessHost()->GetID();
1877 int render_view_id
= web_contents
->GetRenderViewHost()->GetRoutingID();
1879 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
1881 const PermissionRequestID
request_id(render_process_id
,
1886 switch (permission
) {
1887 case content::PERMISSION_MIDI_SYSEX
:
1888 MidiPermissionContextFactory::GetForProfile(profile
)
1889 ->RequestPermission(web_contents
,
1895 case content::PERMISSION_NOTIFICATIONS
:
1896 #if defined(ENABLE_NOTIFICATIONS)
1897 DesktopNotificationServiceFactory::GetForProfile(profile
)
1898 ->RequestNotificationPermission(web_contents
,
1907 case content::PERMISSION_GEOLOCATION
:
1908 GeolocationPermissionContextFactory::GetForProfile(profile
)
1909 ->RequestPermission(web_contents
,
1911 requesting_frame
.GetOrigin(),
1915 case content::PERMISSION_PROTECTED_MEDIA
:
1916 #if defined(OS_ANDROID)
1917 ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(profile
)
1918 ->RequestPermission(web_contents
,
1920 requesting_frame
.GetOrigin(),
1927 case content::PERMISSION_PUSH_MESSAGING
:
1928 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile
)
1929 ->RequestPermission(web_contents
,
1931 requesting_frame
.GetOrigin(),
1935 case content::PERMISSION_NUM
:
1936 NOTREACHED() << "Invalid RequestPermission for " << permission
;
1941 content::PermissionStatus
ChromeContentBrowserClient::GetPermissionStatus(
1942 content::PermissionType permission
,
1943 content::BrowserContext
* browser_context
,
1944 const GURL
& requesting_origin
,
1945 const GURL
& embedding_origin
) {
1946 DCHECK(browser_context
);
1947 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1949 PermissionContextBase
* context
= nullptr;
1950 switch (permission
) {
1951 case content::PERMISSION_MIDI_SYSEX
:
1952 context
= MidiPermissionContextFactory::GetForProfile(profile
);
1954 case content::PERMISSION_NOTIFICATIONS
:
1955 #if defined(ENABLE_NOTIFICATIONS)
1956 context
= DesktopNotificationServiceFactory::GetForProfile(profile
);
1961 case content::PERMISSION_GEOLOCATION
:
1962 context
= GeolocationPermissionContextFactory::GetForProfile(profile
);
1964 case content::PERMISSION_PROTECTED_MEDIA
:
1967 case content::PERMISSION_PUSH_MESSAGING
:
1968 context
= gcm::PushMessagingPermissionContextFactory::GetForProfile(
1971 case content::PERMISSION_NUM
:
1972 NOTREACHED() << "Invalid RequestPermission for " << permission
;
1976 ContentSetting result
= context
1977 ? context
->GetPermissionStatus(requesting_origin
.GetOrigin(),
1978 embedding_origin
.GetOrigin())
1979 : CONTENT_SETTING_DEFAULT
;
1981 return ContentSettingToPermissionStatus(result
);
1984 void ChromeContentBrowserClient::CancelPermissionRequest(
1985 content::PermissionType permission
,
1986 content::WebContents
* web_contents
,
1988 const GURL
& requesting_frame
) {
1989 int render_process_id
= web_contents
->GetRenderProcessHost()->GetID();
1990 int render_view_id
= web_contents
->GetRenderViewHost()->GetRoutingID();
1992 const PermissionRequestID
request_id(render_process_id
,
1997 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
1998 switch (permission
) {
1999 case content::PERMISSION_MIDI_SYSEX
:
2000 MidiPermissionContextFactory::GetForProfile(profile
)
2001 ->CancelPermissionRequest(web_contents
, request_id
);
2003 case content::PERMISSION_NOTIFICATIONS
:
2004 #if defined(ENABLE_NOTIFICATIONS)
2005 DesktopNotificationServiceFactory::GetForProfile(profile
)
2006 ->CancelPermissionRequest(web_contents
, request_id
);
2011 case content::PERMISSION_GEOLOCATION
:
2012 GeolocationPermissionContextFactory::GetForProfile(profile
)
2013 ->CancelPermissionRequest(web_contents
, request_id
);
2015 case content::PERMISSION_PROTECTED_MEDIA
:
2016 #if defined(OS_ANDROID)
2017 ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(profile
)
2018 ->CancelPermissionRequest(web_contents
, request_id
);
2023 case content::PERMISSION_PUSH_MESSAGING
:
2024 NOTIMPLEMENTED() << "CancelPermission not implemented for " << permission
;
2026 case content::PERMISSION_NUM
:
2027 NOTREACHED() << "Invalid CancelPermission for " << permission
;
2032 // Helper method to translate from Permissions to ContentSettings
2033 static ContentSettingsType
PermissionToContentSetting(
2034 content::PermissionType permission
) {
2035 switch (permission
) {
2036 case content::PERMISSION_MIDI_SYSEX
:
2037 return CONTENT_SETTINGS_TYPE_MIDI_SYSEX
;
2038 case content::PERMISSION_PUSH_MESSAGING
:
2039 return CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
;
2040 case content::PERMISSION_NOTIFICATIONS
:
2041 return CONTENT_SETTINGS_TYPE_NOTIFICATIONS
;
2042 case content::PERMISSION_GEOLOCATION
:
2043 return CONTENT_SETTINGS_TYPE_GEOLOCATION
;
2044 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
2045 case content::PERMISSION_PROTECTED_MEDIA
:
2046 return CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER
;
2049 NOTREACHED() << "Unknown content setting for permission " << permission
;
2050 return CONTENT_SETTINGS_TYPE_DEFAULT
;
2054 void ChromeContentBrowserClient::RegisterPermissionUsage(
2055 content::PermissionType permission
,
2056 content::WebContents
* web_contents
,
2057 const GURL
& frame_url
,
2058 const GURL
& main_frame_url
) {
2059 Profile::FromBrowserContext(web_contents
->GetBrowserContext())
2060 ->GetHostContentSettingsMap()
2062 frame_url
, main_frame_url
, PermissionToContentSetting(permission
));
2065 bool ChromeContentBrowserClient::CanCreateWindow(
2066 const GURL
& opener_url
,
2067 const GURL
& opener_top_level_frame_url
,
2068 const GURL
& source_origin
,
2069 WindowContainerType container_type
,
2070 const GURL
& target_url
,
2071 const content::Referrer
& referrer
,
2072 WindowOpenDisposition disposition
,
2073 const WebWindowFeatures
& features
,
2075 bool opener_suppressed
,
2076 content::ResourceContext
* context
,
2077 int render_process_id
,
2079 bool* no_javascript_access
) {
2080 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
2082 *no_javascript_access
= false;
2084 // If the opener is trying to create a background window but doesn't have
2085 // the appropriate permission, fail the attempt.
2086 if (container_type
== WINDOW_CONTAINER_TYPE_BACKGROUND
) {
2087 #if defined(ENABLE_EXTENSIONS)
2088 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
2089 InfoMap
* map
= io_data
->GetExtensionInfoMap();
2090 if (!map
->SecurityOriginHasAPIPermission(
2093 APIPermission::kBackground
)) {
2097 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2098 // return a recently installed Extension even if this CanCreateWindow call
2099 // was made by an old copy of the page in a normal web process. That's ok,
2100 // because the permission check above would have caused an early return
2101 // already. We must use the full URL to find hosted apps, though, and not
2103 const Extension
* extension
=
2104 map
->extensions().GetExtensionOrAppByURL(opener_url
);
2105 if (extension
&& !extensions::BackgroundInfo::AllowJSAccess(extension
))
2106 *no_javascript_access
= true;
2112 #if defined(ENABLE_EXTENSIONS)
2113 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
2118 HostContentSettingsMap
* content_settings
=
2119 ProfileIOData::FromResourceContext(context
)->GetHostContentSettingsMap();
2120 BlockedWindowParams
blocked_params(target_url
,
2129 if (!user_gesture
&&
2130 !base::CommandLine::ForCurrentProcess()->HasSwitch(
2131 switches::kDisablePopupBlocking
)) {
2132 if (content_settings
->GetContentSetting(opener_top_level_frame_url
,
2133 opener_top_level_frame_url
,
2134 CONTENT_SETTINGS_TYPE_POPUPS
,
2136 CONTENT_SETTING_ALLOW
) {
2137 BrowserThread::PostTask(BrowserThread::UI
,
2139 base::Bind(&HandleBlockedPopupOnUIThread
,
2145 #if defined(OS_ANDROID)
2146 if (SingleTabModeTabHelper::IsRegistered(render_process_id
, opener_id
)) {
2147 BrowserThread::PostTask(BrowserThread::UI
,
2149 base::Bind(&HandleSingleTabModeBlockOnUIThread
,
2158 void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
2160 prerender_tracker_
= g_browser_process
->prerender_tracker();
2161 return g_browser_process
->ResourceDispatcherHostCreated();
2164 content::SpeechRecognitionManagerDelegate
*
2165 ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
2166 return new speech::ChromeSpeechRecognitionManagerDelegate();
2169 net::NetLog
* ChromeContentBrowserClient::GetNetLog() {
2170 return g_browser_process
->net_log();
2173 AccessTokenStore
* ChromeContentBrowserClient::CreateAccessTokenStore() {
2174 return new ChromeAccessTokenStore();
2177 bool ChromeContentBrowserClient::IsFastShutdownPossible() {
2181 void ChromeContentBrowserClient::OverrideWebkitPrefs(
2182 RenderViewHost
* rvh
, const GURL
& url
, WebPreferences
* web_prefs
) {
2183 Profile
* profile
= Profile::FromBrowserContext(
2184 rvh
->GetProcess()->GetBrowserContext());
2185 PrefService
* prefs
= profile
->GetPrefs();
2187 // Fill per-script font preferences. These are not registered on Android
2188 // - http://crbug.com/308033.
2189 #if !defined(OS_ANDROID)
2190 FontFamilyCache::FillFontFamilyMap(profile
,
2191 prefs::kWebKitStandardFontFamilyMap
,
2192 &web_prefs
->standard_font_family_map
);
2193 FontFamilyCache::FillFontFamilyMap(profile
,
2194 prefs::kWebKitFixedFontFamilyMap
,
2195 &web_prefs
->fixed_font_family_map
);
2196 FontFamilyCache::FillFontFamilyMap(profile
,
2197 prefs::kWebKitSerifFontFamilyMap
,
2198 &web_prefs
->serif_font_family_map
);
2199 FontFamilyCache::FillFontFamilyMap(profile
,
2200 prefs::kWebKitSansSerifFontFamilyMap
,
2201 &web_prefs
->sans_serif_font_family_map
);
2202 FontFamilyCache::FillFontFamilyMap(profile
,
2203 prefs::kWebKitCursiveFontFamilyMap
,
2204 &web_prefs
->cursive_font_family_map
);
2205 FontFamilyCache::FillFontFamilyMap(profile
,
2206 prefs::kWebKitFantasyFontFamilyMap
,
2207 &web_prefs
->fantasy_font_family_map
);
2208 FontFamilyCache::FillFontFamilyMap(profile
,
2209 prefs::kWebKitPictographFontFamilyMap
,
2210 &web_prefs
->pictograph_font_family_map
);
2213 web_prefs
->default_font_size
=
2214 prefs
->GetInteger(prefs::kWebKitDefaultFontSize
);
2215 web_prefs
->default_fixed_font_size
=
2216 prefs
->GetInteger(prefs::kWebKitDefaultFixedFontSize
);
2217 web_prefs
->minimum_font_size
=
2218 prefs
->GetInteger(prefs::kWebKitMinimumFontSize
);
2219 web_prefs
->minimum_logical_font_size
=
2220 prefs
->GetInteger(prefs::kWebKitMinimumLogicalFontSize
);
2222 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2224 web_prefs
->javascript_can_open_windows_automatically
=
2225 prefs
->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically
);
2226 web_prefs
->dom_paste_enabled
=
2227 prefs
->GetBoolean(prefs::kWebKitDomPasteEnabled
);
2228 web_prefs
->shrinks_standalone_images_to_fit
=
2229 prefs
->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit
);
2230 web_prefs
->tabs_to_links
= prefs
->GetBoolean(prefs::kWebkitTabsToLinks
);
2232 if (!prefs
->GetBoolean(prefs::kWebKitJavascriptEnabled
))
2233 web_prefs
->javascript_enabled
= false;
2234 if (!prefs
->GetBoolean(prefs::kWebKitWebSecurityEnabled
))
2235 web_prefs
->web_security_enabled
= false;
2236 if (!prefs
->GetBoolean(prefs::kWebKitPluginsEnabled
))
2237 web_prefs
->plugins_enabled
= false;
2238 if (!prefs
->GetBoolean(prefs::kWebKitJavaEnabled
))
2239 web_prefs
->java_enabled
= false;
2240 web_prefs
->loads_images_automatically
=
2241 prefs
->GetBoolean(prefs::kWebKitLoadsImagesAutomatically
);
2243 if (prefs
->GetBoolean(prefs::kDisable3DAPIs
))
2244 web_prefs
->experimental_webgl_enabled
= false;
2246 web_prefs
->allow_displaying_insecure_content
=
2247 prefs
->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent
);
2248 web_prefs
->allow_running_insecure_content
=
2249 prefs
->GetBoolean(prefs::kWebKitAllowRunningInsecureContent
);
2250 #if defined(OS_ANDROID)
2251 web_prefs
->font_scale_factor
=
2252 static_cast<float>(prefs
->GetDouble(prefs::kWebKitFontScaleFactor
));
2253 web_prefs
->device_scale_adjustment
= GetDeviceScaleAdjustment();
2254 web_prefs
->force_enable_zoom
=
2255 prefs
->GetBoolean(prefs::kWebKitForceEnableZoom
);
2258 #if defined(OS_ANDROID)
2259 web_prefs
->password_echo_enabled
=
2260 prefs
->GetBoolean(prefs::kWebKitPasswordEchoEnabled
);
2262 web_prefs
->password_echo_enabled
= browser_defaults::kPasswordEchoEnabled
;
2265 web_prefs
->asynchronous_spell_checking_enabled
= true;
2266 web_prefs
->unified_textchecker_enabled
= true;
2268 web_prefs
->uses_universal_detector
=
2269 prefs
->GetBoolean(prefs::kWebKitUsesUniversalDetector
);
2270 web_prefs
->text_areas_are_resizable
=
2271 prefs
->GetBoolean(prefs::kWebKitTextAreasAreResizable
);
2272 web_prefs
->hyperlink_auditing_enabled
=
2273 prefs
->GetBoolean(prefs::kEnableHyperlinkAuditing
);
2275 // Make sure we will set the default_encoding with canonical encoding name.
2276 web_prefs
->default_encoding
=
2277 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
2278 web_prefs
->default_encoding
);
2279 if (web_prefs
->default_encoding
.empty()) {
2280 prefs
->ClearPref(prefs::kDefaultCharset
);
2281 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2283 DCHECK(!web_prefs
->default_encoding
.empty());
2285 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2286 switches::kEnablePotentiallyAnnoyingSecurityFeatures
)) {
2287 web_prefs
->disable_reading_from_canvas
= true;
2288 web_prefs
->strict_mixed_content_checking
= true;
2289 web_prefs
->strict_powerful_feature_restrictions
= true;
2292 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2293 extra_parts_
[i
]->OverrideWebkitPrefs(rvh
, url
, web_prefs
);
2296 void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2297 BrowserURLHandler
* handler
) {
2298 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2299 extra_parts_
[i
]->BrowserURLHandlerCreated(handler
);
2301 // about: handler. Must come before chrome: handler, since it will
2302 // rewrite about: urls to chrome: URLs and then expect chrome: to
2303 // actually handle them.
2304 handler
->AddHandlerPair(&WillHandleBrowserAboutURL
,
2305 BrowserURLHandler::null_handler());
2307 #if defined(OS_ANDROID)
2308 // Handler to rewrite chrome://newtab on Android.
2309 handler
->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL
,
2310 BrowserURLHandler::null_handler());
2312 // Handler to rewrite chrome://newtab for InstantExtended.
2313 handler
->AddHandlerPair(&chrome::HandleNewTabURLRewrite
,
2314 &chrome::HandleNewTabURLReverseRewrite
);
2317 // chrome: & friends.
2318 handler
->AddHandlerPair(&HandleWebUI
, &HandleWebUIReverse
);
2321 void ChromeContentBrowserClient::ClearCache(RenderViewHost
* rvh
) {
2322 Profile
* profile
= Profile::FromBrowserContext(
2323 rvh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2324 BrowsingDataRemover
* remover
=
2325 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2326 remover
->Remove(BrowsingDataRemover::REMOVE_CACHE
,
2327 BrowsingDataHelper::UNPROTECTED_WEB
);
2328 // BrowsingDataRemover takes care of deleting itself when done.
2331 void ChromeContentBrowserClient::ClearCookies(RenderViewHost
* rvh
) {
2332 Profile
* profile
= Profile::FromBrowserContext(
2333 rvh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2334 BrowsingDataRemover
* remover
=
2335 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2336 int remove_mask
= BrowsingDataRemover::REMOVE_SITE_DATA
;
2337 remover
->Remove(remove_mask
, BrowsingDataHelper::UNPROTECTED_WEB
);
2338 // BrowsingDataRemover takes care of deleting itself when done.
2341 base::FilePath
ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
2342 return DownloadPrefs::GetDefaultDownloadDirectory();
2345 std::string
ChromeContentBrowserClient::GetDefaultDownloadName() {
2346 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME
);
2349 void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2350 content::BrowserPpapiHost
* browser_host
) {
2351 #if defined(ENABLE_PLUGINS)
2352 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host
);
2356 content::BrowserPpapiHost
*
2357 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2358 int plugin_process_id
) {
2359 #if !defined(DISABLE_NACL)
2360 content::BrowserChildProcessHostIterator
iter(PROCESS_TYPE_NACL_LOADER
);
2361 while (!iter
.Done()) {
2362 nacl::NaClProcessHost
* host
= static_cast<nacl::NaClProcessHost
*>(
2363 iter
.GetDelegate());
2364 if (host
->process() &&
2365 host
->process()->GetData().id
== plugin_process_id
) {
2366 // Found the plugin.
2367 return host
->browser_ppapi_host();
2375 bool ChromeContentBrowserClient::AllowPepperSocketAPI(
2376 content::BrowserContext
* browser_context
,
2379 const content::SocketPermissionRequest
* params
) {
2380 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2381 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
2382 browser_context
, url
, private_api
, params
, allowed_socket_origins_
);
2388 ui::SelectFilePolicy
* ChromeContentBrowserClient::CreateSelectFilePolicy(
2389 WebContents
* web_contents
) {
2390 return new ChromeSelectFilePolicy(web_contents
);
2393 void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2394 std::vector
<std::string
>* additional_allowed_schemes
) {
2395 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2396 additional_allowed_schemes
);
2397 additional_allowed_schemes
->push_back(content::kChromeDevToolsScheme
);
2398 additional_allowed_schemes
->push_back(content::kChromeUIScheme
);
2399 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
2400 extra_parts_
[i
]->GetAdditionalAllowedSchemesForFileSystem(
2401 additional_allowed_schemes
);
2405 void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
2406 std::vector
<storage::URLRequestAutoMountHandler
>* handlers
) {
2407 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2408 extra_parts_
[i
]->GetURLRequestAutoMountHandlers(handlers
);
2411 void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
2412 content::BrowserContext
* browser_context
,
2413 const base::FilePath
& storage_partition_path
,
2414 ScopedVector
<storage::FileSystemBackend
>* additional_backends
) {
2415 #if defined(OS_CHROMEOS)
2416 storage::ExternalMountPoints
* external_mount_points
=
2417 content::BrowserContext::GetMountPoints(browser_context
);
2418 DCHECK(external_mount_points
);
2419 chromeos::FileSystemBackend
* backend
= new chromeos::FileSystemBackend(
2420 new drive::FileSystemBackendDelegate
,
2421 new chromeos::file_system_provider::BackendDelegate
,
2422 new chromeos::MTPFileSystemBackendDelegate(storage_partition_path
),
2423 browser_context
->GetSpecialStoragePolicy(),
2424 external_mount_points
,
2425 storage::ExternalMountPoints::GetSystemInstance());
2426 backend
->AddSystemMountPoints();
2427 DCHECK(backend
->CanHandleType(storage::kFileSystemTypeExternal
));
2428 additional_backends
->push_back(backend
);
2431 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
2432 extra_parts_
[i
]->GetAdditionalFileSystemBackends(
2433 browser_context
, storage_partition_path
, additional_backends
);
2437 #if defined(OS_POSIX) && !defined(OS_MACOSX)
2438 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2439 const base::CommandLine
& command_line
,
2440 int child_process_id
,
2441 FileDescriptorInfo
* mappings
) {
2442 #if defined(OS_ANDROID)
2443 base::FilePath data_path
;
2444 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID
, &data_path
);
2445 DCHECK(!data_path
.empty());
2447 int flags
= base::File::FLAG_OPEN
| base::File::FLAG_READ
;
2448 base::FilePath chrome_resources_pak
=
2449 data_path
.AppendASCII("chrome_100_percent.pak");
2450 base::File
file(chrome_resources_pak
, flags
);
2451 DCHECK(file
.IsValid());
2452 mappings
->Transfer(kAndroidChrome100PercentPakDescriptor
,
2453 base::ScopedFD(file
.TakePlatformFile()));
2455 const std::string locale
= GetApplicationLocale();
2456 base::FilePath locale_pak
= ResourceBundle::GetSharedInstance().
2457 GetLocaleFilePath(locale
, false);
2458 file
.Initialize(locale_pak
, flags
);
2459 DCHECK(file
.IsValid());
2460 mappings
->Transfer(kAndroidLocalePakDescriptor
,
2461 base::ScopedFD(file
.TakePlatformFile()));
2463 base::FilePath resources_pack_path
;
2464 PathService::Get(chrome::FILE_RESOURCES_PACK
, &resources_pack_path
);
2465 file
.Initialize(resources_pack_path
, flags
);
2466 DCHECK(file
.IsValid());
2467 mappings
->Transfer(kAndroidUIResourcesPakDescriptor
,
2468 base::ScopedFD(file
.TakePlatformFile()));
2470 if (breakpad::IsCrashReporterEnabled()) {
2471 file
= breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile(
2473 if (file
.IsValid()) {
2474 mappings
->Transfer(kAndroidMinidumpDescriptor
,
2475 base::ScopedFD(file
.TakePlatformFile()));
2477 LOG(ERROR
) << "Failed to create file for minidump, crash reporting will "
2478 "be disabled for this process.";
2482 base::FilePath app_data_path
;
2483 PathService::Get(base::DIR_ANDROID_APP_DATA
, &app_data_path
);
2484 DCHECK(!app_data_path
.empty());
2486 flags
= base::File::FLAG_OPEN
| base::File::FLAG_READ
;
2487 base::FilePath icudata_path
=
2488 app_data_path
.AppendASCII(base::i18n::kIcuDataFileName
);
2489 base::File
icudata_file(icudata_path
, flags
);
2490 DCHECK(icudata_file
.IsValid());
2491 mappings
->Transfer(kAndroidICUDataDescriptor
,
2492 base::ScopedFD(icudata_file
.TakePlatformFile()));
2494 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
2495 base::FilePath v8_data_path
;
2496 PathService::Get(base::DIR_ANDROID_APP_DATA
, &v8_data_path
);
2497 DCHECK(!v8_data_path
.empty());
2499 int file_flags
= base::File::FLAG_OPEN
| base::File::FLAG_READ
;
2500 base::FilePath v8_natives_data_path
=
2501 v8_data_path
.AppendASCII(gin::IsolateHolder::kNativesFileName
);
2502 base::FilePath v8_snapshot_data_path
=
2503 v8_data_path
.AppendASCII(gin::IsolateHolder::kSnapshotFileName
);
2504 base::File
v8_natives_data_file(v8_natives_data_path
, file_flags
);
2505 base::File
v8_snapshot_data_file(v8_snapshot_data_path
, file_flags
);
2506 DCHECK(v8_natives_data_file
.IsValid());
2507 DCHECK(v8_snapshot_data_file
.IsValid());
2508 mappings
->Transfer(kV8NativesDataDescriptor
,
2509 base::ScopedFD(v8_natives_data_file
.TakePlatformFile()));
2510 mappings
->Transfer(kV8SnapshotDataDescriptor
,
2511 base::ScopedFD(v8_snapshot_data_file
.TakePlatformFile()));
2512 #endif // V8_USE_EXTERNAL_STARTUP_DATA
2515 int crash_signal_fd
= GetCrashSignalFD(command_line
);
2516 if (crash_signal_fd
>= 0) {
2517 mappings
->Share(kCrashDumpSignal
, crash_signal_fd
);
2519 #endif // defined(OS_ANDROID)
2521 #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
2524 const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2525 return chrome::kBrowserResourcesDll
;
2528 void ChromeContentBrowserClient::PreSpawnRenderer(
2529 sandbox::TargetPolicy
* policy
,
2531 // This code is duplicated in nacl_exe_win_64.cc.
2532 // Allow the server side of a pipe restricted to the "chrome.nacl."
2533 // namespace so that it cannot impersonate other system or other chrome
2535 sandbox::ResultCode result
= policy
->AddRule(
2536 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES
,
2537 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY
,
2538 L
"\\\\.\\pipe\\chrome.nacl.*");
2539 if (result
!= sandbox::SBOX_ALL_OK
) {
2544 // Renderers need to send named pipe handles and shared memory
2545 // segment handles to NaCl loader processes.
2546 result
= policy
->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES
,
2547 sandbox::TargetPolicy::HANDLES_DUP_ANY
,
2549 if (result
!= sandbox::SBOX_ALL_OK
) {
2556 bool ChromeContentBrowserClient::CheckMediaAccessPermission(
2557 content::BrowserContext
* browser_context
,
2558 const GURL
& security_origin
,
2559 content::MediaStreamType type
) {
2560 return MediaCaptureDevicesDispatcher::GetInstance()
2561 ->CheckMediaAccessPermission(
2562 browser_context
, security_origin
, type
);
2565 content::DevToolsManagerDelegate
*
2566 ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
2567 #if defined(OS_ANDROID)
2568 return new DevToolsManagerDelegateAndroid();
2570 return new ChromeDevToolsManagerDelegate();
2574 bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2575 content::BrowserContext
* browser_context
,
2577 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2578 return ChromeContentBrowserClientPluginsPart::
2579 IsPluginAllowedToCallRequestOSFileHandle(browser_context
, url
,
2580 allowed_file_handle_origins_
);
2586 bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
2587 content::BrowserContext
* browser_context
,
2589 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2590 return ChromeContentBrowserClientPluginsPart::
2591 IsPluginAllowedToUseDevChannelAPIs(browser_context
, url
,
2592 allowed_dev_channel_origins_
);
2599 ChromeContentBrowserClient::OverrideCookieStoreForRenderProcess(
2600 int render_process_id
) {
2601 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
2602 if (!prerender_tracker_
)
2604 return prerender_tracker_
->GetPrerenderCookieStoreForRenderProcess(
2605 render_process_id
).get();
2608 #if defined(ENABLE_WEBRTC)
2609 void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
2610 base::CommandLine
* to_command_line
,
2611 const base::CommandLine
& from_command_line
,
2612 VersionInfo::Channel channel
) {
2613 #if defined(OS_ANDROID)
2614 const VersionInfo::Channel kMaxDisableEncryptionChannel
=
2615 VersionInfo::CHANNEL_BETA
;
2617 const VersionInfo::Channel kMaxDisableEncryptionChannel
=
2618 VersionInfo::CHANNEL_DEV
;
2620 if (channel
<= kMaxDisableEncryptionChannel
) {
2621 static const char* const kWebRtcDevSwitchNames
[] = {
2622 switches::kDisableWebRtcEncryption
,
2624 to_command_line
->CopySwitchesFrom(from_command_line
,
2625 kWebRtcDevSwitchNames
,
2626 arraysize(kWebRtcDevSwitchNames
));
2629 #endif // defined(ENABLE_WEBRTC)
2631 } // namespace chrome