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/lazy_instance.h"
15 #include "base/path_service.h"
16 #include "base/prefs/pref_service.h"
17 #include "base/prefs/scoped_user_pref_update.h"
18 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/utf_string_conversions.h"
20 #include "base/threading/sequenced_worker_pool.h"
21 #include "chrome/browser/browser_about_handler.h"
22 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/browser_shutdown.h"
24 #include "chrome/browser/browsing_data/browsing_data_helper.h"
25 #include "chrome/browser/browsing_data/browsing_data_remover.h"
26 #include "chrome/browser/character_encoding.h"
27 #include "chrome/browser/chrome_content_browser_client_parts.h"
28 #include "chrome/browser/chrome_net_benchmarking_message_filter.h"
29 #include "chrome/browser/chrome_quota_permission_context.h"
30 #include "chrome/browser/content_settings/cookie_settings.h"
31 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
32 #include "chrome/browser/defaults.h"
33 #include "chrome/browser/download/download_prefs.h"
34 #include "chrome/browser/font_family_cache.h"
35 #include "chrome/browser/geolocation/chrome_access_token_store.h"
36 #include "chrome/browser/geolocation/geolocation_permission_context.h"
37 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h"
38 #include "chrome/browser/media/cast_transport_host_filter.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/platform_util.h"
48 #include "chrome/browser/prerender/prerender_final_status.h"
49 #include "chrome/browser/prerender/prerender_manager.h"
50 #include "chrome/browser/prerender/prerender_manager_factory.h"
51 #include "chrome/browser/prerender/prerender_message_filter.h"
52 #include "chrome/browser/prerender/prerender_tracker.h"
53 #include "chrome/browser/printing/printing_message_filter.h"
54 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
55 #include "chrome/browser/profiles/profile.h"
56 #include "chrome/browser/profiles/profile_io_data.h"
57 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
58 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
59 #include "chrome/browser/search/instant_service.h"
60 #include "chrome/browser/search/instant_service_factory.h"
61 #include "chrome/browser/search/search.h"
62 #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
63 #include "chrome/browser/services/gcm/push_messaging_permission_context.h"
64 #include "chrome/browser/services/gcm/push_messaging_permission_context_factory.h"
65 #include "chrome/browser/signin/principals_message_filter.h"
66 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
67 #include "chrome/browser/speech/tts_controller.h"
68 #include "chrome/browser/speech/tts_message_filter.h"
69 #include "chrome/browser/ssl/ssl_add_certificate.h"
70 #include "chrome/browser/ssl/ssl_blocking_page.h"
71 #include "chrome/browser/ssl/ssl_client_certificate_selector.h"
72 #include "chrome/browser/tab_contents/tab_util.h"
73 #include "chrome/browser/ui/blocked_content/blocked_window_params.h"
74 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
75 #include "chrome/browser/ui/chrome_select_file_policy.h"
76 #include "chrome/browser/ui/sync/sync_promo_ui.h"
77 #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
78 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
79 #include "chrome/common/chrome_constants.h"
80 #include "chrome/common/chrome_paths.h"
81 #include "chrome/common/chrome_switches.h"
82 #include "chrome/common/env_vars.h"
83 #include "chrome/common/logging_chrome.h"
84 #include "chrome/common/pepper_permission_util.h"
85 #include "chrome/common/pref_names.h"
86 #include "chrome/common/render_messages.h"
87 #include "chrome/common/url_constants.h"
88 #include "chrome/grit/generated_resources.h"
89 #include "chrome/installer/util/google_update_settings.h"
90 #include "chromeos/chromeos_constants.h"
91 #include "components/cdm/browser/cdm_message_filter_android.h"
92 #include "components/cloud_devices/common/cloud_devices_switches.h"
93 #include "components/content_settings/core/browser/content_settings_provider.h"
94 #include "components/content_settings/core/browser/content_settings_utils.h"
95 #include "components/content_settings/core/browser/host_content_settings_map.h"
96 #include "components/content_settings/core/common/content_settings.h"
97 #include "components/content_settings/core/common/permission_request_id.h"
98 #include "components/dom_distiller/core/url_constants.h"
99 #include "components/google/core/browser/google_util.h"
100 #include "components/metrics/client_info.h"
101 #include "components/pref_registry/pref_registry_syncable.h"
102 #include "components/signin/core/common/profile_management_switches.h"
103 #include "components/translate/core/common/translate_switches.h"
104 #include "content/public/browser/browser_child_process_host.h"
105 #include "content/public/browser/browser_main_parts.h"
106 #include "content/public/browser/browser_ppapi_host.h"
107 #include "content/public/browser/browser_thread.h"
108 #include "content/public/browser/browser_url_handler.h"
109 #include "content/public/browser/child_process_data.h"
110 #include "content/public/browser/child_process_security_policy.h"
111 #include "content/public/browser/desktop_notification_delegate.h"
112 #include "content/public/browser/permission_type.h"
113 #include "content/public/browser/render_frame_host.h"
114 #include "content/public/browser/render_process_host.h"
115 #include "content/public/browser/render_view_host.h"
116 #include "content/public/browser/resource_context.h"
117 #include "content/public/browser/site_instance.h"
118 #include "content/public/browser/web_contents.h"
119 #include "content/public/common/child_process_host.h"
120 #include "content/public/common/content_descriptors.h"
121 #include "content/public/common/show_desktop_notification_params.h"
122 #include "content/public/common/url_utils.h"
123 #include "content/public/common/web_preferences.h"
124 #include "net/base/mime_util.h"
125 #include "net/cookies/canonical_cookie.h"
126 #include "net/cookies/cookie_options.h"
127 #include "net/ssl/ssl_cert_request_info.h"
128 #include "ppapi/host/ppapi_host.h"
129 #include "storage/browser/fileapi/external_mount_points.h"
130 #include "ui/base/l10n/l10n_util.h"
131 #include "ui/base/resource/resource_bundle.h"
132 #include "ui/resources/grit/ui_resources.h"
135 #include "base/win/windows_version.h"
136 #include "chrome/browser/chrome_browser_main_win.h"
137 #include "sandbox/win/src/sandbox_policy.h"
138 #elif defined(OS_MACOSX)
139 #include "chrome/browser/chrome_browser_main_mac.h"
140 #include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
141 #include "components/crash/app/breakpad_mac.h"
142 #elif defined(OS_CHROMEOS)
143 #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
144 #include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h"
145 #include "chrome/browser/chromeos/file_manager/app_id.h"
146 #include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
147 #include "chrome/browser/chromeos/fileapi/file_system_backend.h"
148 #include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
149 #include "chrome/browser/chromeos/login/startup_utils.h"
150 #include "chrome/browser/chromeos/system/input_device_settings.h"
151 #include "chromeos/chromeos_switches.h"
152 #include "components/user_manager/user_manager.h"
153 #elif defined(OS_LINUX)
154 #include "chrome/browser/chrome_browser_main_linux.h"
155 #elif defined(OS_ANDROID)
156 #include "chrome/browser/android/new_tab_page_url_handler.h"
157 #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
158 #include "chrome/browser/chrome_browser_main_android.h"
159 #include "chrome/browser/media/protected_media_identifier_permission_context.h"
160 #include "chrome/browser/media/protected_media_identifier_permission_context_factory.h"
161 #include "chrome/common/descriptors_android.h"
162 #include "components/crash/browser/crash_dump_manager_android.h"
163 #elif defined(OS_POSIX)
164 #include "chrome/browser/chrome_browser_main_posix.h"
167 #if defined(OS_POSIX) && !defined(OS_MACOSX)
168 #include "base/debug/leak_annotations.h"
169 #include "components/crash/app/breakpad_linux.h"
170 #include "components/crash/browser/crash_handler_host_linux.h"
173 #if defined(OS_ANDROID)
174 #include "ui/base/ui_base_paths.h"
175 #include "ui/gfx/android/device_display_info.h"
178 #if defined(OS_ANDROID)
179 #include "chrome/browser/android/dev_tools_manager_delegate_android.h"
181 #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
184 #if !defined(OS_CHROMEOS)
185 #include "chrome/browser/signin/chrome_signin_client.h"
186 #include "chrome/browser/signin/chrome_signin_client_factory.h"
187 #include "chrome/browser/signin/signin_manager_factory.h"
188 #include "components/signin/core/browser/signin_manager.h"
191 #if defined(TOOLKIT_VIEWS)
192 #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
195 #if defined(USE_ATHENA)
196 #include "athena/content/public/web_contents_view_delegate_creator.h"
197 #include "chrome/browser/ui/views/athena/chrome_browser_main_extra_parts_athena.h"
198 #elif defined(USE_ASH)
199 #include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
202 #if defined(USE_AURA)
203 #include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
207 #include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
210 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
211 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
214 #if !defined(DISABLE_NACL)
215 #include "components/nacl/browser/nacl_browser.h"
216 #include "components/nacl/browser/nacl_host_message_filter.h"
217 #include "components/nacl/browser/nacl_process_host.h"
218 #include "components/nacl/common/nacl_process_type.h"
219 #include "components/nacl/common/nacl_switches.h"
222 #if defined(ENABLE_EXTENSIONS)
223 #include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
224 #include "chrome/browser/extensions/extension_util.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 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)
607 ChromeContentBrowserClient::ChromeContentBrowserClient()
608 : prerender_tracker_(NULL
),
609 weak_factory_(this) {
610 #if defined(ENABLE_PLUGINS)
611 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedDevChannelOrigins
); ++i
)
612 allowed_dev_channel_origins_
.insert(kPredefinedAllowedDevChannelOrigins
[i
]);
613 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedFileHandleOrigins
); ++i
)
614 allowed_file_handle_origins_
.insert(kPredefinedAllowedFileHandleOrigins
[i
]);
615 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedSocketOrigins
); ++i
)
616 allowed_socket_origins_
.insert(kPredefinedAllowedSocketOrigins
[i
]);
618 extra_parts_
.push_back(new ChromeContentBrowserClientPluginsPart
);
621 #if !defined(OS_ANDROID)
622 TtsExtensionEngine
* tts_extension_engine
= TtsExtensionEngine::GetInstance();
623 TtsController::GetInstance()->SetTtsEngineDelegate(tts_extension_engine
);
626 #if defined(ENABLE_EXTENSIONS)
627 extra_parts_
.push_back(new ChromeContentBrowserClientExtensionsPart
);
631 ChromeContentBrowserClient::~ChromeContentBrowserClient() {
632 for (int i
= static_cast<int>(extra_parts_
.size()) - 1; i
>= 0; --i
)
633 delete extra_parts_
[i
];
634 extra_parts_
.clear();
638 void ChromeContentBrowserClient::RegisterProfilePrefs(
639 user_prefs::PrefRegistrySyncable
* registry
) {
640 registry
->RegisterBooleanPref(
641 prefs::kDisable3DAPIs
,
643 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
644 registry
->RegisterBooleanPref(
645 prefs::kEnableHyperlinkAuditing
,
647 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
648 registry
->RegisterListPref(
649 prefs::kEnableDeprecatedWebPlatformFeatures
,
650 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
654 void ChromeContentBrowserClient::SetApplicationLocale(
655 const std::string
& locale
) {
656 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
658 // This object is guaranteed to outlive all threads so we don't have to
659 // worry about the lack of refcounting and can just post as Unretained.
661 // The common case is that this function is called early in Chrome startup
662 // before any threads are created (it will also be called later if the user
663 // changes the pref). In this case, there will be no threads created and
664 // posting will fail. When there are no threads, we can just set the string
665 // without worrying about threadsafety.
666 if (!BrowserThread::PostTask(BrowserThread::IO
, FROM_HERE
,
667 base::Bind(&SetApplicationLocaleOnIOThread
, locale
))) {
668 g_io_thread_application_locale
.Get() = locale
;
672 content::BrowserMainParts
* ChromeContentBrowserClient::CreateBrowserMainParts(
673 const content::MainFunctionParams
& parameters
) {
674 ChromeBrowserMainParts
* main_parts
;
675 // Construct the Main browser parts based on the OS type.
677 main_parts
= new ChromeBrowserMainPartsWin(parameters
);
678 #elif defined(OS_MACOSX)
679 main_parts
= new ChromeBrowserMainPartsMac(parameters
);
680 #elif defined(OS_CHROMEOS)
681 main_parts
= new chromeos::ChromeBrowserMainPartsChromeos(parameters
);
682 #elif defined(OS_LINUX)
683 main_parts
= new ChromeBrowserMainPartsLinux(parameters
);
684 #elif defined(OS_ANDROID)
685 main_parts
= new ChromeBrowserMainPartsAndroid(parameters
);
686 #elif defined(OS_POSIX)
687 main_parts
= new ChromeBrowserMainPartsPosix(parameters
);
690 main_parts
= new ChromeBrowserMainParts(parameters
);
693 chrome::AddProfilesExtraParts(main_parts
);
695 // Construct additional browser parts. Stages are called in the order in
696 // which they are added.
697 #if defined(TOOLKIT_VIEWS)
698 main_parts
->AddParts(new ChromeBrowserMainExtraPartsViews());
701 // TODO(oshima): Athena on chrome currently requires USE_ASH to build.
702 // We should reduce the dependency as much as possible.
703 #if defined(USE_ATHENA)
704 main_parts
->AddParts(CreateChromeBrowserMainExtraPartsAthena());
705 #elif defined(USE_ASH)
706 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAsh());
709 #if defined(USE_AURA)
710 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAura());
714 main_parts
->AddParts(new ChromeBrowserMainExtraPartsX11());
717 chrome::AddMetricsExtraParts(main_parts
);
722 std::string
ChromeContentBrowserClient::GetStoragePartitionIdForSite(
723 content::BrowserContext
* browser_context
,
725 std::string partition_id
;
727 // The partition ID for webview guest processes is the string value of its
728 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
729 if (site
.SchemeIs(content::kGuestScheme
)) {
730 partition_id
= site
.spec();
731 } else if (site
.GetOrigin().spec() == kChromeUIChromeSigninURL
&&
732 !switches::IsEnableWebviewBasedSignin()) {
733 // Chrome signin page has an embedded iframe of extension and web content,
734 // thus it must be isolated from other webUI pages.
735 partition_id
= site
.GetOrigin().spec();
738 DCHECK(IsValidStoragePartitionId(browser_context
, partition_id
));
742 bool ChromeContentBrowserClient::IsValidStoragePartitionId(
743 content::BrowserContext
* browser_context
,
744 const std::string
& partition_id
) {
745 // The default ID is empty and is always valid.
746 if (partition_id
.empty())
749 return GURL(partition_id
).is_valid();
752 void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
753 content::BrowserContext
* browser_context
,
756 std::string
* partition_domain
,
757 std::string
* partition_name
,
759 // Default to the browser-wide storage partition and override based on |site|
761 partition_domain
->clear();
762 partition_name
->clear();
765 bool success
= false;
766 #if defined(ENABLE_EXTENSIONS)
767 success
= extensions::WebViewGuest::GetGuestPartitionConfigForSite(
768 site
, partition_domain
, partition_name
, in_memory
);
770 if (!success
&& site
.SchemeIs(extensions::kExtensionScheme
)) {
771 // If |can_be_default| is false, the caller is stating that the |site|
772 // should be parsed as if it had isolated storage. In particular it is
773 // important to NOT check ExtensionService for the is_storage_isolated()
774 // attribute because this code path is run during Extension uninstall
775 // to do cleanup after the Extension has already been unloaded from the
777 bool is_isolated
= !can_be_default
;
778 if (can_be_default
) {
779 if (extensions::util::SiteHasIsolatedStorage(site
, browser_context
))
784 CHECK(site
.has_host());
785 // For extensions with isolated storage, the the host of the |site| is
786 // the |partition_domain|. The |in_memory| and |partition_name| are only
787 // used in guest schemes so they are cleared here.
788 *partition_domain
= site
.host();
790 partition_name
->clear();
796 if (!success
&& (site
.GetOrigin().spec() == kChromeUIChromeSigninURL
) &&
797 !switches::IsEnableWebviewBasedSignin()) {
798 // Chrome signin page has an embedded iframe of extension and web content,
799 // thus it must be isolated from other webUI pages.
800 *partition_domain
= chrome::kChromeUIChromeSigninHost
;
803 // Assert that if |can_be_default| is false, the code above must have found a
804 // non-default partition. If this fails, the caller has a serious logic
805 // error about which StoragePartition they expect to be in and it is not
807 CHECK(can_be_default
|| !partition_domain
->empty());
810 content::WebContentsViewDelegate
*
811 ChromeContentBrowserClient::GetWebContentsViewDelegate(
812 content::WebContents
* web_contents
) {
813 #if defined(USE_ATHENA)
814 return athena::CreateWebContentsViewDelegate(web_contents
);
816 return chrome::CreateWebContentsViewDelegate(web_contents
);
820 void ChromeContentBrowserClient::RenderProcessWillLaunch(
821 content::RenderProcessHost
* host
) {
822 int id
= host
->GetID();
823 Profile
* profile
= Profile::FromBrowserContext(host
->GetBrowserContext());
824 net::URLRequestContextGetter
* context
=
825 profile
->GetRequestContextForRenderProcess(id
);
827 host
->AddFilter(new ChromeRenderMessageFilter(id
, profile
));
828 host
->AddFilter(new cast::CastTransportHostFilter
);
829 #if defined(ENABLE_PRINTING)
830 host
->AddFilter(new printing::PrintingMessageFilter(id
, profile
));
832 host
->AddFilter(new SearchProviderInstallStateMessageFilter(id
, profile
));
833 #if defined(ENABLE_SPELLCHECK)
834 host
->AddFilter(new SpellCheckMessageFilter(id
));
836 #if defined(OS_MACOSX)
837 host
->AddFilter(new SpellCheckMessageFilterMac(id
));
839 host
->AddFilter(new ChromeNetBenchmarkingMessageFilter(profile
, context
));
840 host
->AddFilter(new prerender::PrerenderMessageFilter(id
, profile
));
841 host
->AddFilter(new TtsMessageFilter(id
, host
->GetBrowserContext()));
842 #if defined(ENABLE_WEBRTC)
843 WebRtcLoggingHandlerHost
* webrtc_logging_handler_host
=
844 new WebRtcLoggingHandlerHost(profile
);
845 host
->SetWebRtcLogMessageCallback(base::Bind(
846 &WebRtcLoggingHandlerHost::LogMessage
, webrtc_logging_handler_host
));
847 host
->AddFilter(webrtc_logging_handler_host
);
848 host
->SetUserData(host
, new base::UserDataAdapter
<WebRtcLoggingHandlerHost
>(
849 webrtc_logging_handler_host
));
851 #if !defined(DISABLE_NACL)
852 host
->AddFilter(new nacl::NaClHostMessageFilter(
853 id
, profile
->IsOffTheRecord(),
857 #if defined(OS_ANDROID)
858 host
->AddFilter(new cdm::CdmMessageFilterAndroid());
860 if (switches::IsEnableAccountConsistency())
861 host
->AddFilter(new PrincipalsMessageFilter(id
));
863 host
->Send(new ChromeViewMsg_SetIsIncognitoProcess(
864 profile
->IsOffTheRecord()));
866 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
867 extra_parts_
[i
]->RenderProcessWillLaunch(host
);
869 RendererContentSettingRules rules
;
870 if (host
->IsIsolatedGuest()) {
871 #if defined(ENABLE_EXTENSIONS)
872 GetGuestViewDefaultContentSettingRules(profile
->IsOffTheRecord(), &rules
);
877 GetRendererContentSettingRules(
878 profile
->GetHostContentSettingsMap(), &rules
);
880 host
->Send(new ChromeViewMsg_SetContentSettingRules(rules
));
883 GURL
ChromeContentBrowserClient::GetEffectiveURL(
884 content::BrowserContext
* browser_context
, const GURL
& url
) {
885 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
889 // If the input |url| should be assigned to the Instant renderer, make its
890 // effective URL distinct from other URLs on the search provider's domain.
891 if (chrome::ShouldAssignURLToInstantRenderer(url
, profile
))
892 return chrome::GetEffectiveURLForInstant(url
, profile
);
894 #if !defined(OS_CHROMEOS)
895 // If the input |url| should be assigned to the Signin renderer, make its
896 // effective URL distinct from other URLs on the signin service's domain.
897 // Note that the signin renderer will be allowed to sign the user in to
899 if (SigninManager::IsWebBasedSigninFlowURL(url
))
900 return GetEffectiveURLForSignin(url
);
903 #if defined(ENABLE_EXTENSIONS)
904 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(
911 bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
912 content::BrowserContext
* browser_context
, const GURL
& effective_url
) {
913 // Non-extension, non-Instant URLs should generally use
914 // process-per-site-instance. Because we expect to use the effective URL,
915 // URLs for hosted apps (apart from bookmark apps) should have an extension
918 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
922 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url
, profile
))
925 #if !defined(OS_CHROMEOS)
926 if (SigninManager::IsWebBasedSigninFlowURL(effective_url
))
930 #if defined(ENABLE_EXTENSIONS)
931 return ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
932 profile
, effective_url
);
938 // These are treated as WebUI schemes but do not get WebUI bindings. Also,
939 // view-source is allowed for these schemes.
940 void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
941 std::vector
<std::string
>* additional_schemes
) {
942 additional_schemes
->push_back(chrome::kChromeSearchScheme
);
943 additional_schemes
->push_back(dom_distiller::kDomDistillerScheme
);
946 void ChromeContentBrowserClient::GetAdditionalWebUIHostsToIgnoreParititionCheck(
947 std::vector
<std::string
>* hosts
) {
948 hosts
->push_back(chrome::kChromeUIExtensionIconHost
);
949 hosts
->push_back(chrome::kChromeUIFaviconHost
);
950 hosts
->push_back(chrome::kChromeUIThemeHost
);
951 hosts
->push_back(chrome::kChromeUIThumbnailHost
);
952 hosts
->push_back(chrome::kChromeUIThumbnailHost2
);
953 hosts
->push_back(chrome::kChromeUIThumbnailListHost
);
956 net::URLRequestContextGetter
*
957 ChromeContentBrowserClient::CreateRequestContext(
958 content::BrowserContext
* browser_context
,
959 content::ProtocolHandlerMap
* protocol_handlers
,
960 content::URLRequestInterceptorScopedVector request_interceptors
) {
961 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
962 return profile
->CreateRequestContext(protocol_handlers
,
963 request_interceptors
.Pass());
966 net::URLRequestContextGetter
*
967 ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
968 content::BrowserContext
* browser_context
,
969 const base::FilePath
& partition_path
,
971 content::ProtocolHandlerMap
* protocol_handlers
,
972 content::URLRequestInterceptorScopedVector request_interceptors
) {
973 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
974 return profile
->CreateRequestContextForStoragePartition(
978 request_interceptors
.Pass());
981 bool ChromeContentBrowserClient::IsHandledURL(const GURL
& url
) {
982 return ProfileIOData::IsHandledURL(url
);
985 bool ChromeContentBrowserClient::CanCommitURL(
986 content::RenderProcessHost
* process_host
,
988 #if defined(ENABLE_EXTENSIONS)
989 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(
996 bool ChromeContentBrowserClient::ShouldAllowOpenURL(
997 content::SiteInstance
* site_instance
, const GURL
& url
) {
998 GURL from_url
= site_instance
->GetSiteURL();
1000 #if defined(ENABLE_EXTENSIONS)
1002 if (ChromeContentBrowserClientExtensionsPart::ShouldAllowOpenURL(
1003 site_instance
, from_url
, url
, &result
))
1007 // Do not allow chrome://chrome-signin navigate to other chrome:// URLs, since
1008 // the signin page may host untrusted web content.
1009 if (from_url
.GetOrigin().spec() == chrome::kChromeUIChromeSigninURL
&&
1010 url
.SchemeIs(content::kChromeUIScheme
) &&
1011 url
.host() != chrome::kChromeUIChromeSigninHost
) {
1012 VLOG(1) << "Blocked navigation to " << url
.spec() << " from "
1013 << chrome::kChromeUIChromeSigninURL
;
1020 bool ChromeContentBrowserClient::IsSuitableHost(
1021 content::RenderProcessHost
* process_host
,
1022 const GURL
& site_url
) {
1024 Profile::FromBrowserContext(process_host
->GetBrowserContext());
1025 // This may be NULL during tests. In that case, just assume any site can
1030 // Instant URLs should only be in the instant process and instant process
1031 // should only have Instant URLs.
1032 InstantService
* instant_service
=
1033 InstantServiceFactory::GetForProfile(profile
);
1034 if (instant_service
) {
1035 bool is_instant_process
= instant_service
->IsInstantProcess(
1036 process_host
->GetID());
1037 bool should_be_in_instant_process
=
1038 chrome::ShouldAssignURLToInstantRenderer(site_url
, profile
);
1039 if (is_instant_process
|| should_be_in_instant_process
)
1040 return is_instant_process
&& should_be_in_instant_process
;
1043 #if !defined(OS_CHROMEOS)
1044 SigninClient
* signin_client
=
1045 ChromeSigninClientFactory::GetForProfile(profile
);
1046 if (signin_client
&& signin_client
->IsSigninProcess(process_host
->GetID()))
1047 return SigninManager::IsWebBasedSigninFlowURL(site_url
);
1050 #if defined(ENABLE_EXTENSIONS)
1051 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1052 profile
, process_host
, site_url
);
1058 bool ChromeContentBrowserClient::MayReuseHost(
1059 content::RenderProcessHost
* process_host
) {
1060 // If there is currently a prerender in progress for the host provided,
1061 // it may not be shared. We require prerenders to be by themselves in a
1062 // separate process, so that we can monitor their resource usage, and so that
1063 // we can track the cookies that they change.
1064 Profile
* profile
= Profile::FromBrowserContext(
1065 process_host
->GetBrowserContext());
1066 prerender::PrerenderManager
* prerender_manager
=
1067 prerender::PrerenderManagerFactory::GetForProfile(profile
);
1068 if (prerender_manager
&&
1069 !prerender_manager
->MayReuseProcessHost(process_host
)) {
1076 bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1077 content::BrowserContext
* browser_context
, const GURL
& url
) {
1078 // It has to be a valid URL for us to check for an extension.
1079 if (!url
.is_valid())
1082 #if defined(ENABLE_EXTENSIONS)
1083 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1084 return ChromeContentBrowserClientExtensionsPart::
1085 ShouldTryToUseExistingProcessHost(
1092 void ChromeContentBrowserClient::SiteInstanceGotProcess(
1093 SiteInstance
* site_instance
) {
1094 CHECK(site_instance
->HasProcess());
1096 Profile
* profile
= Profile::FromBrowserContext(
1097 site_instance
->GetBrowserContext());
1101 // Remember the ID of the Instant process to signal the renderer process
1102 // on startup in |AppendExtraCommandLineSwitches| below.
1103 if (chrome::ShouldAssignURLToInstantRenderer(
1104 site_instance
->GetSiteURL(), profile
)) {
1105 InstantService
* instant_service
=
1106 InstantServiceFactory::GetForProfile(profile
);
1107 if (instant_service
)
1108 instant_service
->AddInstantProcess(site_instance
->GetProcess()->GetID());
1111 #if !defined(OS_CHROMEOS)
1112 // We only expect there to be one signin process as we use process-per-site
1113 // for signin URLs. The signin process will be cleared from SigninManager
1114 // when the renderer is destroyed.
1115 if (SigninManager::IsWebBasedSigninFlowURL(site_instance
->GetSiteURL())) {
1116 SigninClient
* signin_client
=
1117 ChromeSigninClientFactory::GetForProfile(profile
);
1119 signin_client
->SetSigninProcess(site_instance
->GetProcess()->GetID());
1120 #if defined(ENABLE_EXTENSIONS)
1121 ChromeContentBrowserClientExtensionsPart::SetSigninProcess(site_instance
);
1126 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
1127 extra_parts_
[i
]->SiteInstanceGotProcess(site_instance
);
1130 void ChromeContentBrowserClient::SiteInstanceDeleting(
1131 SiteInstance
* site_instance
) {
1132 if (!site_instance
->HasProcess())
1135 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
1136 extra_parts_
[i
]->SiteInstanceDeleting(site_instance
);
1139 bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
1140 SiteInstance
* site_instance
,
1141 const GURL
& current_url
,
1142 const GURL
& new_url
) {
1143 #if defined(ENABLE_EXTENSIONS)
1144 return ChromeContentBrowserClientExtensionsPart::
1145 ShouldSwapBrowsingInstancesForNavigation(
1146 site_instance
, current_url
, new_url
);
1152 bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1153 content::ResourceContext
* resource_context
, const GURL
& current_url
,
1154 const GURL
& new_url
) {
1155 #if defined(ENABLE_EXTENSIONS)
1156 return ChromeContentBrowserClientExtensionsPart::
1157 ShouldSwapProcessesForRedirect(resource_context
, current_url
, new_url
);
1163 bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL
& url
) {
1164 return !url
.SchemeIs(chrome::kChromeNativeScheme
);
1167 std::string
ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1168 const std::string
& alias_name
) {
1169 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name
);
1174 bool IsAutoReloadEnabled() {
1175 // Fetch the field trial, even though we don't use it. Calling FindFullName()
1176 // causes the field-trial mechanism to report which group we're in, which
1177 // might reflect a hard disable or hard enable via flag, both of which have
1178 // their own field trial groups. This lets us know what percentage of users
1179 // manually enable or disable auto-reload.
1180 std::string group
= base::FieldTrialList::FindFullName(
1181 "AutoReloadExperiment");
1182 const CommandLine
& browser_command_line
= *CommandLine::ForCurrentProcess();
1183 if (browser_command_line
.HasSwitch(switches::kEnableOfflineAutoReload
))
1185 if (browser_command_line
.HasSwitch(switches::kDisableOfflineAutoReload
))
1190 bool IsAutoReloadVisibleOnlyEnabled() {
1191 // See the block comment in IsAutoReloadEnabled().
1192 std::string group
= base::FieldTrialList::FindFullName(
1193 "AutoReloadVisibleOnlyExperiment");
1194 const CommandLine
& browser_command_line
= *CommandLine::ForCurrentProcess();
1195 if (browser_command_line
.HasSwitch(
1196 switches::kEnableOfflineAutoReloadVisibleOnly
)) {
1199 if (browser_command_line
.HasSwitch(
1200 switches::kDisableOfflineAutoReloadVisibleOnly
)) {
1208 void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1209 CommandLine
* command_line
, int child_process_id
) {
1210 #if defined(OS_POSIX)
1211 if (breakpad::IsCrashReporterEnabled()) {
1212 scoped_ptr
<metrics::ClientInfo
> client_info
=
1213 GoogleUpdateSettings::LoadMetricsClientInfo();
1214 command_line
->AppendSwitchASCII(switches::kEnableCrashReporter
,
1215 client_info
? client_info
->client_id
1218 #endif // defined(OS_POSIX)
1220 if (logging::DialogsAreSuppressed())
1221 command_line
->AppendSwitch(switches::kNoErrorDialogs
);
1223 std::string process_type
=
1224 command_line
->GetSwitchValueASCII(switches::kProcessType
);
1225 const CommandLine
& browser_command_line
= *CommandLine::ForCurrentProcess();
1227 static const char* const kCommonSwitchNames
[] = {
1228 switches::kUserAgent
,
1229 switches::kUserDataDir
, // Make logs go to the right file.
1231 command_line
->CopySwitchesFrom(browser_command_line
, kCommonSwitchNames
,
1232 arraysize(kCommonSwitchNames
));
1234 #if defined(ENABLE_IPC_FUZZER)
1235 static const char* const kIpcFuzzerSwitches
[] = {
1236 switches::kIpcFuzzerTestcase
,
1238 command_line
->CopySwitchesFrom(browser_command_line
, kIpcFuzzerSwitches
,
1239 arraysize(kIpcFuzzerSwitches
));
1242 #if defined(OS_CHROMEOS)
1243 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
1244 base::FilePath homedir
;
1245 PathService::Get(base::DIR_HOME
, &homedir
);
1246 command_line
->AppendSwitchASCII(chromeos::switches::kHomedir
,
1247 homedir
.value().c_str());
1250 if (process_type
== switches::kRendererProcess
) {
1251 content::RenderProcessHost
* process
=
1252 content::RenderProcessHost::FromID(child_process_id
);
1254 process
? Profile::FromBrowserContext(process
->GetBrowserContext())
1256 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
1257 extra_parts_
[i
]->AppendExtraRendererCommandLineSwitches(
1258 command_line
, process
, profile
);
1261 #if defined(OS_CHROMEOS)
1262 const std::string
& login_profile
=
1263 browser_command_line
.GetSwitchValueASCII(
1264 chromeos::switches::kLoginProfile
);
1265 if (!login_profile
.empty())
1266 command_line
->AppendSwitchASCII(
1267 chromeos::switches::kLoginProfile
, login_profile
);
1270 #if defined(ENABLE_WEBRTC)
1271 MaybeCopyDisableWebRtcEncryptionSwitch(command_line
,
1272 browser_command_line
,
1273 VersionInfo::GetChannel());
1277 PrefService
* prefs
= profile
->GetPrefs();
1278 // Currently this pref is only registered if applied via a policy.
1279 if (prefs
->HasPrefPath(prefs::kDisable3DAPIs
) &&
1280 prefs
->GetBoolean(prefs::kDisable3DAPIs
)) {
1281 // Turn this policy into a command line switch.
1282 command_line
->AppendSwitch(switches::kDisable3DAPIs
);
1285 const base::ListValue
* switches
=
1286 prefs
->GetList(prefs::kEnableDeprecatedWebPlatformFeatures
);
1288 // Enable any deprecated features that have been re-enabled by policy.
1289 for (base::ListValue::const_iterator it
= switches
->begin();
1290 it
!= switches
->end(); ++it
) {
1291 std::string switch_to_enable
;
1292 if ((*it
)->GetAsString(&switch_to_enable
))
1293 command_line
->AppendSwitch(switch_to_enable
);
1297 // Disable client-side phishing detection in the renderer if it is
1298 // disabled in the Profile preferences or the browser process.
1299 if (!prefs
->GetBoolean(prefs::kSafeBrowsingEnabled
) ||
1300 !g_browser_process
->safe_browsing_detection_service()) {
1301 command_line
->AppendSwitch(
1302 switches::kDisableClientSidePhishingDetection
);
1305 if (prefs
->GetBoolean(prefs::kPrintPreviewDisabled
))
1306 command_line
->AppendSwitch(switches::kDisablePrintPreview
);
1308 InstantService
* instant_service
=
1309 InstantServiceFactory::GetForProfile(profile
);
1310 if (instant_service
&&
1311 instant_service
->IsInstantProcess(process
->GetID()))
1312 command_line
->AppendSwitch(switches::kInstantProcess
);
1314 #if !defined(OS_CHROMEOS)
1315 SigninClient
* signin_client
=
1316 ChromeSigninClientFactory::GetForProfile(profile
);
1317 if (signin_client
&& signin_client
->IsSigninProcess(process
->GetID()))
1318 command_line
->AppendSwitch(switches::kSigninProcess
);
1322 if (IsAutoReloadEnabled())
1323 command_line
->AppendSwitch(switches::kEnableOfflineAutoReload
);
1324 if (IsAutoReloadVisibleOnlyEnabled()) {
1325 command_line
->AppendSwitch(
1326 switches::kEnableOfflineAutoReloadVisibleOnly
);
1330 // Enable load stale cache if this session is in the field trial or
1331 // the user explicitly enabled it. Note that as far as the renderer
1332 // is concerned, the feature is enabled if-and-only-if the
1333 // kEnableOfflineLoadStaleCache flag is on the command line;
1334 // the yes/no/default behavior is only at the browser command line
1337 // Command line switches override
1338 if (browser_command_line
.HasSwitch(
1339 switches::kEnableOfflineLoadStaleCache
)) {
1340 command_line
->AppendSwitch(switches::kEnableOfflineLoadStaleCache
);
1341 } else if (!browser_command_line
.HasSwitch(
1342 switches::kDisableOfflineLoadStaleCache
)) {
1344 base::FieldTrialList::FindFullName("LoadStaleCacheExperiment");
1346 if (group
== "Enabled")
1347 command_line
->AppendSwitch(switches::kEnableOfflineLoadStaleCache
);
1351 // Please keep this in alphabetical order.
1352 static const char* const kSwitchNames
[] = {
1353 autofill::switches::kDisablePasswordGeneration
,
1354 autofill::switches::kEnablePasswordGeneration
,
1355 autofill::switches::kEnableSingleClickAutofill
,
1356 autofill::switches::kIgnoreAutocompleteOffForAutofill
,
1357 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration
,
1358 autofill::switches::kRespectAutocompleteOffForAutofill
,
1359 #if defined(ENABLE_EXTENSIONS)
1360 extensions::switches::kAllowHTTPBackgroundPage
,
1361 extensions::switches::kAllowLegacyExtensionManifests
,
1362 extensions::switches::kEnableAppWindowControls
,
1363 extensions::switches::kEnableEmbeddedExtensionOptions
,
1364 extensions::switches::kEnableExperimentalExtensionApis
,
1365 extensions::switches::kEnableScriptsRequireAction
,
1366 extensions::switches::kExtensionsOnChromeURLs
,
1367 extensions::switches::kWhitelistedExtensionID
,
1369 switches::kAppsCheckoutURL
,
1370 switches::kAppsGalleryURL
,
1371 switches::kCloudPrintURL
,
1372 switches::kCloudPrintXmppEndpoint
,
1373 switches::kDisableBundledPpapiFlash
,
1374 switches::kDisableCastStreamingHWEncoding
,
1375 switches::kDisableJavaScriptHarmonyShipping
,
1376 switches::kDisableOutOfProcessPdf
,
1377 switches::kEnableBenchmarking
,
1378 switches::kEnableNaCl
,
1379 #if !defined(DISABLE_NACL)
1380 switches::kEnableNaClDebug
,
1381 switches::kEnableNaClNonSfiMode
,
1383 switches::kEnableNetBenchmarking
,
1384 switches::kEnableOutOfProcessPdf
,
1385 switches::kEnablePluginPlaceholderShadowDom
,
1386 switches::kEnableShowModalDialog
,
1387 switches::kEnableStreamlinedHostedApps
,
1388 switches::kEnableWebBasedSignin
,
1389 switches::kJavaScriptHarmony
,
1390 switches::kMessageLoopHistogrammer
,
1391 switches::kPlaybackMode
,
1392 switches::kPpapiFlashArgs
,
1393 switches::kPpapiFlashPath
,
1394 switches::kPpapiFlashVersion
,
1395 switches::kProfilingAtStart
,
1396 switches::kProfilingFile
,
1397 switches::kProfilingFlush
,
1398 switches::kRecordMode
,
1399 translate::switches::kTranslateSecurityOrigin
,
1402 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1403 arraysize(kSwitchNames
));
1404 } else if (process_type
== switches::kUtilityProcess
) {
1405 #if defined(ENABLE_EXTENSIONS)
1406 static const char* const kSwitchNames
[] = {
1407 extensions::switches::kAllowHTTPBackgroundPage
,
1408 extensions::switches::kEnableExperimentalExtensionApis
,
1409 extensions::switches::kExtensionsOnChromeURLs
,
1410 extensions::switches::kWhitelistedExtensionID
,
1413 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1414 arraysize(kSwitchNames
));
1416 } else if (process_type
== switches::kPluginProcess
) {
1417 #if defined(OS_CHROMEOS)
1418 static const char* const kSwitchNames
[] = {
1419 chromeos::switches::kLoginProfile
,
1422 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1423 arraysize(kSwitchNames
));
1425 } else if (process_type
== switches::kZygoteProcess
) {
1426 static const char* const kSwitchNames
[] = {
1427 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
1428 switches::kDisableBundledPpapiFlash
,
1429 #if !defined(DISABLE_NACL)
1430 switches::kEnableNaClDebug
,
1431 switches::kEnableNaClNonSfiMode
,
1432 switches::kNaClDangerousNoSandboxNonSfi
,
1433 switches::kUseNaClHelperNonSfi
,
1435 switches::kPpapiFlashPath
,
1436 switches::kPpapiFlashVersion
,
1439 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1440 arraysize(kSwitchNames
));
1441 } else if (process_type
== switches::kGpuProcess
) {
1442 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1443 // because GPU is expected to be unreliable.
1444 if (browser_command_line
.HasSwitch(switches::kIgnoreGpuBlacklist
) &&
1445 !command_line
->HasSwitch(switches::kDisableBreakpad
))
1446 command_line
->AppendSwitch(switches::kDisableBreakpad
);
1449 // The command line switch kEnableBenchmarking needs to be specified along
1450 // with the kEnableStatsTable switch to ensure that the stats table global
1451 // is initialized correctly.
1452 if (command_line
->HasSwitch(switches::kEnableBenchmarking
))
1453 DCHECK(command_line
->HasSwitch(switches::kEnableStatsTable
));
1456 std::string
ChromeContentBrowserClient::GetApplicationLocale() {
1457 if (BrowserThread::CurrentlyOn(BrowserThread::IO
))
1458 return g_io_thread_application_locale
.Get();
1459 return g_browser_process
->GetApplicationLocale();
1462 std::string
ChromeContentBrowserClient::GetAcceptLangs(
1463 content::BrowserContext
* context
) {
1464 Profile
* profile
= Profile::FromBrowserContext(context
);
1465 return profile
->GetPrefs()->GetString(prefs::kAcceptLanguages
);
1468 const gfx::ImageSkia
* ChromeContentBrowserClient::GetDefaultFavicon() {
1469 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
1470 return rb
.GetNativeImageNamed(IDR_DEFAULT_FAVICON
).ToImageSkia();
1473 bool ChromeContentBrowserClient::AllowAppCache(
1474 const GURL
& manifest_url
,
1475 const GURL
& first_party
,
1476 content::ResourceContext
* context
) {
1477 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1478 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1479 return io_data
->GetCookieSettings()->
1480 IsSettingCookieAllowed(manifest_url
, first_party
);
1483 bool ChromeContentBrowserClient::AllowServiceWorker(
1485 const GURL
& first_party_url
,
1486 content::ResourceContext
* context
) {
1487 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1488 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1489 return io_data
->GetCookieSettings()->
1490 IsSettingCookieAllowed(scope
, first_party_url
);
1493 bool ChromeContentBrowserClient::AllowGetCookie(
1495 const GURL
& first_party
,
1496 const net::CookieList
& cookie_list
,
1497 content::ResourceContext
* context
,
1498 int render_process_id
,
1499 int render_frame_id
) {
1500 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1501 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1502 bool allow
= io_data
->GetCookieSettings()->
1503 IsReadingCookieAllowed(url
, first_party
);
1505 BrowserThread::PostTask(
1506 BrowserThread::UI
, FROM_HERE
,
1507 base::Bind(&TabSpecificContentSettings::CookiesRead
, render_process_id
,
1508 render_frame_id
, url
, first_party
, cookie_list
, !allow
, true));
1512 bool ChromeContentBrowserClient::AllowSetCookie(
1514 const GURL
& first_party
,
1515 const std::string
& cookie_line
,
1516 content::ResourceContext
* context
,
1517 int render_process_id
,
1518 int render_frame_id
,
1519 net::CookieOptions
* options
) {
1520 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1521 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1522 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1523 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, first_party
);
1525 if (prerender_tracker_
) {
1526 prerender_tracker_
->OnCookieChangedForURL(
1528 context
->GetRequestContext()->cookie_store()->GetCookieMonster(),
1532 BrowserThread::PostTask(
1533 BrowserThread::UI
, FROM_HERE
,
1534 base::Bind(&TabSpecificContentSettings::CookieChanged
, render_process_id
,
1535 render_frame_id
, url
, first_party
, cookie_line
, *options
,
1540 bool ChromeContentBrowserClient::AllowSaveLocalState(
1541 content::ResourceContext
* context
) {
1542 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1543 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1544 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1545 ContentSetting setting
= cookie_settings
->GetDefaultCookieSetting(NULL
);
1547 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1548 // Could we even support per-origin settings?
1549 return setting
!= CONTENT_SETTING_SESSION_ONLY
;
1552 bool ChromeContentBrowserClient::AllowWorkerDatabase(
1554 const base::string16
& name
,
1555 const base::string16
& display_name
,
1556 unsigned long estimated_size
,
1557 content::ResourceContext
* context
,
1558 const std::vector
<std::pair
<int, int> >& render_frames
) {
1559 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1560 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1561 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1562 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1564 // Record access to database for potential display in UI.
1565 std::vector
<std::pair
<int, int> >::const_iterator i
;
1566 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1567 BrowserThread::PostTask(
1568 BrowserThread::UI
, FROM_HERE
,
1569 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed
,
1570 i
->first
, i
->second
, url
, name
, display_name
, !allow
));
1576 void ChromeContentBrowserClient::AllowWorkerFileSystem(
1578 content::ResourceContext
* context
,
1579 const std::vector
<std::pair
<int, int> >& render_frames
,
1580 base::Callback
<void(bool)> callback
) {
1581 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1582 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1583 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1584 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1586 #if defined(ENABLE_EXTENSIONS)
1587 GuestPermissionRequestHelper(url
, render_frames
, callback
, allow
);
1589 FileSystemAccessed(url
, render_frames
, callback
, allow
);
1593 #if defined(ENABLE_EXTENSIONS)
1594 void ChromeContentBrowserClient::GuestPermissionRequestHelper(
1596 const std::vector
<std::pair
<int, int> >& render_frames
,
1597 base::Callback
<void(bool)> callback
,
1599 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::IO
));
1600 std::vector
<std::pair
<int, int> >::const_iterator i
;
1601 std::map
<int, int> process_map
;
1602 std::map
<int, int>::const_iterator it
;
1603 bool has_web_view_guest
= false;
1604 // Record access to file system for potential display in UI.
1605 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1606 if (process_map
.find(i
->first
) != process_map
.end())
1609 process_map
.insert(std::pair
<int, int>(i
->first
, i
->second
));
1611 if (extensions::WebViewRendererState::GetInstance()->IsGuest(i
->first
))
1612 has_web_view_guest
= true;
1614 if (!has_web_view_guest
) {
1615 FileSystemAccessed(url
, render_frames
, callback
, allow
);
1618 DCHECK_EQ(1U, process_map
.size());
1619 it
= process_map
.begin();
1620 BrowserThread::PostTask(
1623 base::Bind(&ChromeContentBrowserClient::
1624 RequestFileSystemPermissionOnUIThread
,
1629 base::Bind(&ChromeContentBrowserClient::FileSystemAccessed
,
1630 weak_factory_
.GetWeakPtr(),
1636 void ChromeContentBrowserClient::RequestFileSystemPermissionOnUIThread(
1637 int render_process_id
,
1638 int render_frame_id
,
1640 bool allowed_by_default
,
1641 const base::Callback
<void(bool)>& callback
) {
1642 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::UI
));
1643 extensions::WebViewPermissionHelper
* web_view_permission_helper
=
1644 extensions::WebViewPermissionHelper::FromFrameID(
1645 render_process_id
, render_frame_id
);
1646 web_view_permission_helper
->RequestFileSystemPermission(url
,
1652 void ChromeContentBrowserClient::FileSystemAccessed(
1654 const std::vector
<std::pair
<int, int> >& render_frames
,
1655 base::Callback
<void(bool)> callback
,
1657 // Record access to file system for potential display in UI.
1658 std::vector
<std::pair
<int, int> >::const_iterator i
;
1659 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1660 BrowserThread::PostTask(
1663 base::Bind(&TabSpecificContentSettings::FileSystemAccessed
,
1664 i
->first
, i
->second
, url
, !allow
));
1666 callback
.Run(allow
);
1669 bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1671 const base::string16
& name
,
1672 content::ResourceContext
* context
,
1673 const std::vector
<std::pair
<int, int> >& render_frames
) {
1674 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1675 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1676 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1677 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1679 // Record access to IndexedDB for potential display in UI.
1680 std::vector
<std::pair
<int, int> >::const_iterator i
;
1681 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1682 BrowserThread::PostTask(
1683 BrowserThread::UI
, FROM_HERE
,
1684 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed
,
1685 i
->first
, i
->second
, url
, name
, !allow
));
1691 net::URLRequestContext
*
1692 ChromeContentBrowserClient::OverrideRequestContextForURL(
1693 const GURL
& url
, content::ResourceContext
* context
) {
1694 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1695 #if defined(ENABLE_EXTENSIONS)
1696 if (url
.SchemeIs(extensions::kExtensionScheme
)) {
1697 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1698 return io_data
->extensions_request_context();
1705 QuotaPermissionContext
*
1706 ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1707 return new ChromeQuotaPermissionContext();
1710 void ChromeContentBrowserClient::AllowCertificateError(
1711 int render_process_id
,
1712 int render_frame_id
,
1714 const net::SSLInfo
& ssl_info
,
1715 const GURL
& request_url
,
1716 ResourceType resource_type
,
1718 bool strict_enforcement
,
1719 bool expired_previous_decision
,
1720 const base::Callback
<void(bool)>& callback
,
1721 content::CertificateRequestResultType
* result
) {
1722 if (resource_type
!= content::RESOURCE_TYPE_MAIN_FRAME
) {
1723 // A sub-resource has a certificate error. The user doesn't really
1724 // have a context for making the right decision, so block the
1725 // request hard, without an info bar to allow showing the insecure
1727 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY
;
1731 // If the tab is being prerendered, cancel the prerender and the request.
1732 content::RenderFrameHost
* render_frame_host
=
1733 content::RenderFrameHost::FromID(render_process_id
, render_frame_id
);
1734 WebContents
* tab
= WebContents::FromRenderFrameHost(render_frame_host
);
1740 prerender::PrerenderContents
* prerender_contents
=
1741 prerender::PrerenderContents::FromWebContents(tab
);
1742 if (prerender_contents
) {
1743 prerender_contents
->Destroy(prerender::FINAL_STATUS_SSL_ERROR
);
1744 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL
;
1748 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
1749 CaptivePortalTabHelper
* captive_portal_tab_helper
=
1750 CaptivePortalTabHelper::FromWebContents(tab
);
1751 if (captive_portal_tab_helper
)
1752 captive_portal_tab_helper
->OnSSLCertError(ssl_info
);
1755 // Otherwise, display an SSL blocking page. The interstitial page takes
1756 // ownership of ssl_blocking_page.
1757 int options_mask
= 0;
1759 options_mask
|= SSLBlockingPage::OVERRIDABLE
;
1760 if (strict_enforcement
)
1761 options_mask
|= SSLBlockingPage::STRICT_ENFORCEMENT
;
1762 if (expired_previous_decision
)
1763 options_mask
|= SSLBlockingPage::EXPIRED_BUT_PREVIOUSLY_ALLOWED
;
1764 SSLBlockingPage
* ssl_blocking_page
= new SSLBlockingPage(
1765 tab
, cert_error
, ssl_info
, request_url
, options_mask
, callback
);
1766 ssl_blocking_page
->Show();
1769 void ChromeContentBrowserClient::SelectClientCertificate(
1770 int render_process_id
,
1771 int render_frame_id
,
1772 net::SSLCertRequestInfo
* cert_request_info
,
1773 const base::Callback
<void(net::X509Certificate
*)>& callback
) {
1774 content::RenderFrameHost
* rfh
= content::RenderFrameHost::FromID(
1775 render_process_id
, render_frame_id
);
1776 WebContents
* tab
= WebContents::FromRenderFrameHost(rfh
);
1782 prerender::PrerenderContents
* prerender_contents
=
1783 prerender::PrerenderContents::FromWebContents(tab
);
1784 if (prerender_contents
) {
1785 prerender_contents
->Destroy(
1786 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED
);
1790 GURL
requesting_url("https://" + cert_request_info
->host_and_port
.ToString());
1791 DCHECK(requesting_url
.is_valid())
1792 << "Invalid URL string: https://"
1793 << cert_request_info
->host_and_port
.ToString();
1795 Profile
* profile
= Profile::FromBrowserContext(tab
->GetBrowserContext());
1796 scoped_ptr
<base::Value
> filter
=
1797 profile
->GetHostContentSettingsMap()->GetWebsiteSetting(
1800 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE
,
1805 // Try to automatically select a client certificate.
1806 if (filter
->IsType(base::Value::TYPE_DICTIONARY
)) {
1807 base::DictionaryValue
* filter_dict
=
1808 static_cast<base::DictionaryValue
*>(filter
.get());
1810 const std::vector
<scoped_refptr
<net::X509Certificate
> >&
1811 all_client_certs
= cert_request_info
->client_certs
;
1812 for (size_t i
= 0; i
< all_client_certs
.size(); ++i
) {
1813 if (CertMatchesFilter(*all_client_certs
[i
].get(), *filter_dict
)) {
1814 // Use the first certificate that is matched by the filter.
1815 callback
.Run(all_client_certs
[i
].get());
1824 chrome::ShowSSLClientCertificateSelector(tab
, cert_request_info
, callback
);
1827 void ChromeContentBrowserClient::AddCertificate(
1828 net::CertificateMimeType cert_type
,
1829 const void* cert_data
,
1831 int render_process_id
,
1832 int render_frame_id
) {
1833 chrome::SSLAddCertificate(cert_type
, cert_data
, cert_size
,
1834 render_process_id
, render_frame_id
);
1837 content::MediaObserver
* ChromeContentBrowserClient::GetMediaObserver() {
1838 return MediaCaptureDevicesDispatcher::GetInstance();
1841 blink::WebNotificationPermission
1842 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
1843 const GURL
& source_origin
,
1844 content::ResourceContext
* context
,
1845 int render_process_id
) {
1846 #if defined(ENABLE_NOTIFICATIONS)
1847 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1849 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1850 #if defined(ENABLE_EXTENSIONS)
1851 InfoMap
* extension_info_map
= io_data
->GetExtensionInfoMap();
1853 // We want to see if there is an extension that hasn't been manually disabled
1854 // that has the notifications permission and applies to this security origin.
1855 // First, get the list of extensions with permission for the origin.
1856 extensions::ExtensionSet extensions
;
1857 extension_info_map
->GetExtensionsWithAPIPermissionForSecurityOrigin(
1860 extensions::APIPermission::kNotifications
,
1862 for (extensions::ExtensionSet::const_iterator iter
= extensions
.begin();
1863 iter
!= extensions
.end(); ++iter
) {
1864 // Then, check to see if it's been disabled by the user.
1865 if (!extension_info_map
->AreNotificationsDisabled((*iter
)->id()))
1866 return blink::WebNotificationPermissionAllowed
;
1870 // No enabled extensions exist, so check the normal host content settings.
1871 HostContentSettingsMap
* host_content_settings_map
=
1872 io_data
->GetHostContentSettingsMap();
1873 ContentSetting setting
= host_content_settings_map
->GetContentSetting(
1876 CONTENT_SETTINGS_TYPE_NOTIFICATIONS
,
1877 NO_RESOURCE_IDENTIFIER
);
1879 if (setting
== CONTENT_SETTING_ALLOW
)
1880 return blink::WebNotificationPermissionAllowed
;
1881 if (setting
== CONTENT_SETTING_BLOCK
)
1882 return blink::WebNotificationPermissionDenied
;
1883 return blink::WebNotificationPermissionDefault
;
1885 return blink::WebNotificationPermissionAllowed
;
1889 void ChromeContentBrowserClient::ShowDesktopNotification(
1890 const content::ShowDesktopNotificationHostMsgParams
& params
,
1891 content::BrowserContext
* browser_context
,
1892 int render_process_id
,
1893 scoped_ptr
<content::DesktopNotificationDelegate
> delegate
,
1894 base::Closure
* cancel_callback
) {
1895 #if defined(ENABLE_NOTIFICATIONS)
1896 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1899 DesktopNotificationService
* service
=
1900 DesktopNotificationServiceFactory::GetForProfile(profile
);
1903 service
->ShowDesktopNotification(
1904 params
, render_process_id
, delegate
.Pass(), cancel_callback
);
1905 profile
->GetHostContentSettingsMap()->UpdateLastUsage(
1906 params
.origin
, params
.origin
, CONTENT_SETTINGS_TYPE_NOTIFICATIONS
);
1912 void ChromeContentBrowserClient::RequestPermission(
1913 content::PermissionType permission
,
1914 content::WebContents
* web_contents
,
1916 const GURL
& requesting_frame
,
1918 const base::Callback
<void(bool)>& result_callback
) {
1919 int render_process_id
= web_contents
->GetRenderProcessHost()->GetID();
1920 int render_view_id
= web_contents
->GetRenderViewHost()->GetRoutingID();
1922 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
1924 const PermissionRequestID
request_id(render_process_id
,
1929 switch (permission
) {
1930 case content::PERMISSION_MIDI_SYSEX
:
1931 MidiPermissionContextFactory::GetForProfile(profile
)
1932 ->RequestPermission(web_contents
,
1938 case content::PERMISSION_NOTIFICATIONS
:
1939 #if defined(ENABLE_NOTIFICATIONS)
1940 DesktopNotificationServiceFactory::GetForProfile(profile
)
1941 ->RequestNotificationPermission(web_contents
,
1950 case content::PERMISSION_GEOLOCATION
:
1951 GeolocationPermissionContextFactory::GetForProfile(profile
)
1952 ->RequestPermission(web_contents
,
1954 requesting_frame
.GetOrigin(),
1958 case content::PERMISSION_PROTECTED_MEDIA
:
1959 #if defined(OS_ANDROID)
1960 ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(profile
)
1961 ->RequestProtectedMediaIdentifierPermission(
1962 web_contents
, requesting_frame
, result_callback
);
1967 case content::PERMISSION_PUSH_MESSAGING
:
1968 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile
)
1969 ->RequestPermission(web_contents
,
1971 requesting_frame
.GetOrigin(),
1975 case content::PERMISSION_NUM
:
1976 NOTREACHED() << "Invalid RequestPermission for " << permission
;
1981 void ChromeContentBrowserClient::CancelPermissionRequest(
1982 content::PermissionType permission
,
1983 content::WebContents
* web_contents
,
1985 const GURL
& requesting_frame
) {
1986 int render_process_id
= web_contents
->GetRenderProcessHost()->GetID();
1987 int render_view_id
= web_contents
->GetRenderViewHost()->GetRoutingID();
1989 const PermissionRequestID
request_id(render_process_id
,
1994 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
1995 switch (permission
) {
1996 case content::PERMISSION_MIDI_SYSEX
:
1997 MidiPermissionContextFactory::GetForProfile(profile
)
1998 ->CancelPermissionRequest(web_contents
, request_id
);
2000 case content::PERMISSION_NOTIFICATIONS
:
2001 #if defined(ENABLE_NOTIFICATIONS)
2002 DesktopNotificationServiceFactory::GetForProfile(profile
)
2003 ->CancelPermissionRequest(web_contents
, request_id
);
2008 case content::PERMISSION_GEOLOCATION
:
2009 GeolocationPermissionContextFactory::GetForProfile(profile
)
2010 ->CancelPermissionRequest(web_contents
, request_id
);
2012 case content::PERMISSION_PROTECTED_MEDIA
:
2013 #if defined(OS_ANDROID)
2014 ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(profile
)
2015 ->CancelProtectedMediaIdentifierPermissionRequests(
2016 render_process_id
, render_view_id
, requesting_frame
);
2021 case content::PERMISSION_PUSH_MESSAGING
:
2022 NOTIMPLEMENTED() << "CancelPermission not implemented for " << permission
;
2024 case content::PERMISSION_NUM
:
2025 NOTREACHED() << "Invalid CancelPermission for " << permission
;
2030 // Helper method to translate from Permissions to ContentSettings
2031 static ContentSettingsType
PermissionToContentSetting(
2032 content::PermissionType permission
) {
2033 switch (permission
) {
2034 case content::PERMISSION_MIDI_SYSEX
:
2035 return CONTENT_SETTINGS_TYPE_MIDI_SYSEX
;
2036 case content::PERMISSION_PUSH_MESSAGING
:
2037 return CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
;
2038 case content::PERMISSION_NOTIFICATIONS
:
2039 return CONTENT_SETTINGS_TYPE_NOTIFICATIONS
;
2040 case content::PERMISSION_GEOLOCATION
:
2041 return CONTENT_SETTINGS_TYPE_GEOLOCATION
;
2042 #if defined(OS_ANDROID)
2043 case content::PERMISSION_PROTECTED_MEDIA
:
2044 return CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER
;
2047 NOTREACHED() << "Unknown content setting for permission " << permission
;
2048 return CONTENT_SETTINGS_TYPE_DEFAULT
;
2052 void ChromeContentBrowserClient::RegisterPermissionUsage(
2053 content::PermissionType permission
,
2054 content::WebContents
* web_contents
,
2055 const GURL
& frame_url
,
2056 const GURL
& main_frame_url
) {
2057 Profile::FromBrowserContext(web_contents
->GetBrowserContext())
2058 ->GetHostContentSettingsMap()
2060 frame_url
, main_frame_url
, PermissionToContentSetting(permission
));
2063 bool ChromeContentBrowserClient::CanCreateWindow(
2064 const GURL
& opener_url
,
2065 const GURL
& opener_top_level_frame_url
,
2066 const GURL
& source_origin
,
2067 WindowContainerType container_type
,
2068 const GURL
& target_url
,
2069 const content::Referrer
& referrer
,
2070 WindowOpenDisposition disposition
,
2071 const WebWindowFeatures
& features
,
2073 bool opener_suppressed
,
2074 content::ResourceContext
* context
,
2075 int render_process_id
,
2077 bool* no_javascript_access
) {
2078 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
2080 *no_javascript_access
= false;
2082 // If the opener is trying to create a background window but doesn't have
2083 // the appropriate permission, fail the attempt.
2084 if (container_type
== WINDOW_CONTAINER_TYPE_BACKGROUND
) {
2085 #if defined(ENABLE_EXTENSIONS)
2086 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
2087 InfoMap
* map
= io_data
->GetExtensionInfoMap();
2088 if (!map
->SecurityOriginHasAPIPermission(
2091 APIPermission::kBackground
)) {
2095 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2096 // return a recently installed Extension even if this CanCreateWindow call
2097 // was made by an old copy of the page in a normal web process. That's ok,
2098 // because the permission check above would have caused an early return
2099 // already. We must use the full URL to find hosted apps, though, and not
2101 const Extension
* extension
=
2102 map
->extensions().GetExtensionOrAppByURL(opener_url
);
2103 if (extension
&& !extensions::BackgroundInfo::AllowJSAccess(extension
))
2104 *no_javascript_access
= true;
2110 #if defined(ENABLE_EXTENSIONS)
2111 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
2116 HostContentSettingsMap
* content_settings
=
2117 ProfileIOData::FromResourceContext(context
)->GetHostContentSettingsMap();
2118 BlockedWindowParams
blocked_params(target_url
,
2127 if (!user_gesture
&& !CommandLine::ForCurrentProcess()->HasSwitch(
2128 switches::kDisablePopupBlocking
)) {
2129 if (content_settings
->GetContentSetting(opener_top_level_frame_url
,
2130 opener_top_level_frame_url
,
2131 CONTENT_SETTINGS_TYPE_POPUPS
,
2133 CONTENT_SETTING_ALLOW
) {
2134 BrowserThread::PostTask(BrowserThread::UI
,
2136 base::Bind(&HandleBlockedPopupOnUIThread
,
2142 #if defined(OS_ANDROID)
2143 if (SingleTabModeTabHelper::IsRegistered(render_process_id
, opener_id
)) {
2144 BrowserThread::PostTask(BrowserThread::UI
,
2146 base::Bind(&HandleSingleTabModeBlockOnUIThread
,
2155 void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
2157 prerender_tracker_
= g_browser_process
->prerender_tracker();
2158 return g_browser_process
->ResourceDispatcherHostCreated();
2161 content::SpeechRecognitionManagerDelegate
*
2162 ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
2163 return new speech::ChromeSpeechRecognitionManagerDelegate();
2166 net::NetLog
* ChromeContentBrowserClient::GetNetLog() {
2167 return g_browser_process
->net_log();
2170 AccessTokenStore
* ChromeContentBrowserClient::CreateAccessTokenStore() {
2171 return new ChromeAccessTokenStore();
2174 bool ChromeContentBrowserClient::IsFastShutdownPossible() {
2178 void ChromeContentBrowserClient::OverrideWebkitPrefs(
2179 RenderViewHost
* rvh
, const GURL
& url
, WebPreferences
* web_prefs
) {
2180 Profile
* profile
= Profile::FromBrowserContext(
2181 rvh
->GetProcess()->GetBrowserContext());
2182 PrefService
* prefs
= profile
->GetPrefs();
2184 // Fill per-script font preferences. These are not registered on Android
2185 // - http://crbug.com/308033.
2186 #if !defined(OS_ANDROID)
2187 FontFamilyCache::FillFontFamilyMap(profile
,
2188 prefs::kWebKitStandardFontFamilyMap
,
2189 &web_prefs
->standard_font_family_map
);
2190 FontFamilyCache::FillFontFamilyMap(profile
,
2191 prefs::kWebKitFixedFontFamilyMap
,
2192 &web_prefs
->fixed_font_family_map
);
2193 FontFamilyCache::FillFontFamilyMap(profile
,
2194 prefs::kWebKitSerifFontFamilyMap
,
2195 &web_prefs
->serif_font_family_map
);
2196 FontFamilyCache::FillFontFamilyMap(profile
,
2197 prefs::kWebKitSansSerifFontFamilyMap
,
2198 &web_prefs
->sans_serif_font_family_map
);
2199 FontFamilyCache::FillFontFamilyMap(profile
,
2200 prefs::kWebKitCursiveFontFamilyMap
,
2201 &web_prefs
->cursive_font_family_map
);
2202 FontFamilyCache::FillFontFamilyMap(profile
,
2203 prefs::kWebKitFantasyFontFamilyMap
,
2204 &web_prefs
->fantasy_font_family_map
);
2205 FontFamilyCache::FillFontFamilyMap(profile
,
2206 prefs::kWebKitPictographFontFamilyMap
,
2207 &web_prefs
->pictograph_font_family_map
);
2210 web_prefs
->default_font_size
=
2211 prefs
->GetInteger(prefs::kWebKitDefaultFontSize
);
2212 web_prefs
->default_fixed_font_size
=
2213 prefs
->GetInteger(prefs::kWebKitDefaultFixedFontSize
);
2214 web_prefs
->minimum_font_size
=
2215 prefs
->GetInteger(prefs::kWebKitMinimumFontSize
);
2216 web_prefs
->minimum_logical_font_size
=
2217 prefs
->GetInteger(prefs::kWebKitMinimumLogicalFontSize
);
2219 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2221 web_prefs
->javascript_can_open_windows_automatically
=
2222 prefs
->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically
);
2223 web_prefs
->dom_paste_enabled
=
2224 prefs
->GetBoolean(prefs::kWebKitDomPasteEnabled
);
2225 web_prefs
->shrinks_standalone_images_to_fit
=
2226 prefs
->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit
);
2227 web_prefs
->tabs_to_links
= prefs
->GetBoolean(prefs::kWebkitTabsToLinks
);
2229 if (!prefs
->GetBoolean(prefs::kWebKitJavascriptEnabled
))
2230 web_prefs
->javascript_enabled
= false;
2231 if (!prefs
->GetBoolean(prefs::kWebKitWebSecurityEnabled
))
2232 web_prefs
->web_security_enabled
= false;
2233 if (!prefs
->GetBoolean(prefs::kWebKitPluginsEnabled
))
2234 web_prefs
->plugins_enabled
= false;
2235 if (!prefs
->GetBoolean(prefs::kWebKitJavaEnabled
))
2236 web_prefs
->java_enabled
= false;
2237 web_prefs
->loads_images_automatically
=
2238 prefs
->GetBoolean(prefs::kWebKitLoadsImagesAutomatically
);
2240 if (prefs
->GetBoolean(prefs::kDisable3DAPIs
))
2241 web_prefs
->experimental_webgl_enabled
= false;
2243 web_prefs
->allow_displaying_insecure_content
=
2244 prefs
->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent
);
2245 web_prefs
->allow_running_insecure_content
=
2246 prefs
->GetBoolean(prefs::kWebKitAllowRunningInsecureContent
);
2247 #if defined(OS_ANDROID)
2248 web_prefs
->font_scale_factor
=
2249 static_cast<float>(prefs
->GetDouble(prefs::kWebKitFontScaleFactor
));
2250 web_prefs
->device_scale_adjustment
= GetDeviceScaleAdjustment();
2251 web_prefs
->force_enable_zoom
=
2252 prefs
->GetBoolean(prefs::kWebKitForceEnableZoom
);
2255 #if defined(OS_ANDROID)
2256 web_prefs
->password_echo_enabled
=
2257 prefs
->GetBoolean(prefs::kWebKitPasswordEchoEnabled
);
2259 web_prefs
->password_echo_enabled
= browser_defaults::kPasswordEchoEnabled
;
2262 web_prefs
->asynchronous_spell_checking_enabled
= true;
2263 web_prefs
->unified_textchecker_enabled
= true;
2265 web_prefs
->uses_universal_detector
=
2266 prefs
->GetBoolean(prefs::kWebKitUsesUniversalDetector
);
2267 web_prefs
->text_areas_are_resizable
=
2268 prefs
->GetBoolean(prefs::kWebKitTextAreasAreResizable
);
2269 web_prefs
->hyperlink_auditing_enabled
=
2270 prefs
->GetBoolean(prefs::kEnableHyperlinkAuditing
);
2272 // Make sure we will set the default_encoding with canonical encoding name.
2273 web_prefs
->default_encoding
=
2274 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
2275 web_prefs
->default_encoding
);
2276 if (web_prefs
->default_encoding
.empty()) {
2277 prefs
->ClearPref(prefs::kDefaultCharset
);
2278 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2280 DCHECK(!web_prefs
->default_encoding
.empty());
2282 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2283 extra_parts_
[i
]->OverrideWebkitPrefs(rvh
, url
, web_prefs
);
2286 void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2287 BrowserURLHandler
* handler
) {
2288 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2289 extra_parts_
[i
]->BrowserURLHandlerCreated(handler
);
2291 // about: handler. Must come before chrome: handler, since it will
2292 // rewrite about: urls to chrome: URLs and then expect chrome: to
2293 // actually handle them.
2294 handler
->AddHandlerPair(&WillHandleBrowserAboutURL
,
2295 BrowserURLHandler::null_handler());
2297 #if defined(OS_ANDROID)
2298 // Handler to rewrite chrome://newtab on Android.
2299 handler
->AddHandlerPair(&chrome::android::HandleAndroidNewTabURL
,
2300 BrowserURLHandler::null_handler());
2302 // Handler to rewrite chrome://newtab for InstantExtended.
2303 handler
->AddHandlerPair(&chrome::HandleNewTabURLRewrite
,
2304 &chrome::HandleNewTabURLReverseRewrite
);
2307 // chrome: & friends.
2308 handler
->AddHandlerPair(&HandleWebUI
, &HandleWebUIReverse
);
2311 void ChromeContentBrowserClient::ClearCache(RenderViewHost
* rvh
) {
2312 Profile
* profile
= Profile::FromBrowserContext(
2313 rvh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2314 BrowsingDataRemover
* remover
=
2315 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2316 remover
->Remove(BrowsingDataRemover::REMOVE_CACHE
,
2317 BrowsingDataHelper::UNPROTECTED_WEB
);
2318 // BrowsingDataRemover takes care of deleting itself when done.
2321 void ChromeContentBrowserClient::ClearCookies(RenderViewHost
* rvh
) {
2322 Profile
* profile
= Profile::FromBrowserContext(
2323 rvh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2324 BrowsingDataRemover
* remover
=
2325 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2326 int remove_mask
= BrowsingDataRemover::REMOVE_SITE_DATA
;
2327 remover
->Remove(remove_mask
, BrowsingDataHelper::UNPROTECTED_WEB
);
2328 // BrowsingDataRemover takes care of deleting itself when done.
2331 base::FilePath
ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
2332 return DownloadPrefs::GetDefaultDownloadDirectory();
2335 std::string
ChromeContentBrowserClient::GetDefaultDownloadName() {
2336 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME
);
2339 void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2340 content::BrowserPpapiHost
* browser_host
) {
2341 #if defined(ENABLE_PLUGINS)
2342 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host
);
2346 content::BrowserPpapiHost
*
2347 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2348 int plugin_process_id
) {
2349 #if !defined(DISABLE_NACL)
2350 content::BrowserChildProcessHostIterator
iter(PROCESS_TYPE_NACL_LOADER
);
2351 while (!iter
.Done()) {
2352 nacl::NaClProcessHost
* host
= static_cast<nacl::NaClProcessHost
*>(
2353 iter
.GetDelegate());
2354 if (host
->process() &&
2355 host
->process()->GetData().id
== plugin_process_id
) {
2356 // Found the plugin.
2357 return host
->browser_ppapi_host();
2365 bool ChromeContentBrowserClient::AllowPepperSocketAPI(
2366 content::BrowserContext
* browser_context
,
2369 const content::SocketPermissionRequest
* params
) {
2370 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2371 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
2372 browser_context
, url
, private_api
, params
, allowed_socket_origins_
);
2378 ui::SelectFilePolicy
* ChromeContentBrowserClient::CreateSelectFilePolicy(
2379 WebContents
* web_contents
) {
2380 return new ChromeSelectFilePolicy(web_contents
);
2383 void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2384 std::vector
<std::string
>* additional_allowed_schemes
) {
2385 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2386 additional_allowed_schemes
);
2387 additional_allowed_schemes
->push_back(content::kChromeDevToolsScheme
);
2388 additional_allowed_schemes
->push_back(content::kChromeUIScheme
);
2389 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
2390 extra_parts_
[i
]->GetAdditionalAllowedSchemesForFileSystem(
2391 additional_allowed_schemes
);
2395 void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
2396 std::vector
<storage::URLRequestAutoMountHandler
>* handlers
) {
2397 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2398 extra_parts_
[i
]->GetURLRequestAutoMountHandlers(handlers
);
2401 void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
2402 content::BrowserContext
* browser_context
,
2403 const base::FilePath
& storage_partition_path
,
2404 ScopedVector
<storage::FileSystemBackend
>* additional_backends
) {
2405 #if defined(OS_CHROMEOS)
2406 storage::ExternalMountPoints
* external_mount_points
=
2407 content::BrowserContext::GetMountPoints(browser_context
);
2408 DCHECK(external_mount_points
);
2409 chromeos::FileSystemBackend
* backend
= new chromeos::FileSystemBackend(
2410 new drive::FileSystemBackendDelegate
,
2411 new chromeos::file_system_provider::BackendDelegate
,
2412 new chromeos::MTPFileSystemBackendDelegate(storage_partition_path
),
2413 browser_context
->GetSpecialStoragePolicy(),
2414 external_mount_points
,
2415 storage::ExternalMountPoints::GetSystemInstance());
2416 backend
->AddSystemMountPoints();
2417 DCHECK(backend
->CanHandleType(storage::kFileSystemTypeExternal
));
2418 additional_backends
->push_back(backend
);
2421 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
2422 extra_parts_
[i
]->GetAdditionalFileSystemBackends(
2423 browser_context
, storage_partition_path
, additional_backends
);
2427 #if defined(OS_POSIX) && !defined(OS_MACOSX)
2428 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2429 const CommandLine
& command_line
,
2430 int child_process_id
,
2431 FileDescriptorInfo
* mappings
) {
2432 #if defined(OS_ANDROID)
2433 base::FilePath data_path
;
2434 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID
, &data_path
);
2435 DCHECK(!data_path
.empty());
2437 int flags
= base::File::FLAG_OPEN
| base::File::FLAG_READ
;
2438 base::FilePath chrome_resources_pak
=
2439 data_path
.AppendASCII("chrome_100_percent.pak");
2440 base::File
file(chrome_resources_pak
, flags
);
2441 DCHECK(file
.IsValid());
2442 mappings
->Transfer(kAndroidChrome100PercentPakDescriptor
,
2443 base::ScopedFD(file
.TakePlatformFile()));
2445 const std::string locale
= GetApplicationLocale();
2446 base::FilePath locale_pak
= ResourceBundle::GetSharedInstance().
2447 GetLocaleFilePath(locale
, false);
2448 file
.Initialize(locale_pak
, flags
);
2449 DCHECK(file
.IsValid());
2450 mappings
->Transfer(kAndroidLocalePakDescriptor
,
2451 base::ScopedFD(file
.TakePlatformFile()));
2453 base::FilePath resources_pack_path
;
2454 PathService::Get(chrome::FILE_RESOURCES_PACK
, &resources_pack_path
);
2455 file
.Initialize(resources_pack_path
, flags
);
2456 DCHECK(file
.IsValid());
2457 mappings
->Transfer(kAndroidUIResourcesPakDescriptor
,
2458 base::ScopedFD(file
.TakePlatformFile()));
2460 if (breakpad::IsCrashReporterEnabled()) {
2461 file
= breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile(
2463 if (file
.IsValid()) {
2464 mappings
->Transfer(kAndroidMinidumpDescriptor
,
2465 base::ScopedFD(file
.TakePlatformFile()));
2467 LOG(ERROR
) << "Failed to create file for minidump, crash reporting will "
2468 "be disabled for this process.";
2472 base::FilePath app_data_path
;
2473 PathService::Get(base::DIR_ANDROID_APP_DATA
, &app_data_path
);
2474 DCHECK(!app_data_path
.empty());
2476 flags
= base::File::FLAG_OPEN
| base::File::FLAG_READ
;
2477 base::FilePath icudata_path
=
2478 app_data_path
.AppendASCII("icudtl.dat");
2479 base::File
icudata_file(icudata_path
, flags
);
2480 DCHECK(icudata_file
.IsValid());
2481 mappings
->Transfer(kAndroidICUDataDescriptor
,
2482 base::ScopedFD(icudata_file
.TakePlatformFile()));
2484 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
2485 base::FilePath v8_data_path
;
2486 PathService::Get(base::DIR_ANDROID_APP_DATA
, &v8_data_path
);
2487 DCHECK(!v8_data_path
.empty());
2489 int file_flags
= base::File::FLAG_OPEN
| base::File::FLAG_READ
;
2490 base::FilePath v8_natives_data_path
=
2491 v8_data_path
.AppendASCII("natives_blob.bin");
2492 base::FilePath v8_snapshot_data_path
=
2493 v8_data_path
.AppendASCII("snapshot_blob.bin");
2494 base::File
v8_natives_data_file(v8_natives_data_path
, file_flags
);
2495 base::File
v8_snapshot_data_file(v8_snapshot_data_path
, file_flags
);
2496 DCHECK(v8_natives_data_file
.IsValid());
2497 DCHECK(v8_snapshot_data_file
.IsValid());
2498 mappings
->Transfer(kV8NativesDataDescriptor
,
2499 base::ScopedFD(v8_natives_data_file
.TakePlatformFile()));
2500 mappings
->Transfer(kV8SnapshotDataDescriptor
,
2501 base::ScopedFD(v8_snapshot_data_file
.TakePlatformFile()));
2502 #endif // V8_USE_EXTERNAL_STARTUP_DATA
2505 int crash_signal_fd
= GetCrashSignalFD(command_line
);
2506 if (crash_signal_fd
>= 0) {
2507 mappings
->Share(kCrashDumpSignal
, crash_signal_fd
);
2509 #endif // defined(OS_ANDROID)
2511 #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
2514 const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2515 return chrome::kBrowserResourcesDll
;
2518 void ChromeContentBrowserClient::PreSpawnRenderer(
2519 sandbox::TargetPolicy
* policy
,
2521 // This code is duplicated in nacl_exe_win_64.cc.
2522 // Allow the server side of a pipe restricted to the "chrome.nacl."
2523 // namespace so that it cannot impersonate other system or other chrome
2525 sandbox::ResultCode result
= policy
->AddRule(
2526 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES
,
2527 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY
,
2528 L
"\\\\.\\pipe\\chrome.nacl.*");
2529 if (result
!= sandbox::SBOX_ALL_OK
) {
2534 // Renderers need to send named pipe handles and shared memory
2535 // segment handles to NaCl loader processes.
2536 result
= policy
->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES
,
2537 sandbox::TargetPolicy::HANDLES_DUP_ANY
,
2539 if (result
!= sandbox::SBOX_ALL_OK
) {
2546 bool ChromeContentBrowserClient::CheckMediaAccessPermission(
2547 content::BrowserContext
* browser_context
,
2548 const GURL
& security_origin
,
2549 content::MediaStreamType type
) {
2550 return MediaCaptureDevicesDispatcher::GetInstance()
2551 ->CheckMediaAccessPermission(
2552 browser_context
, security_origin
, type
);
2555 content::DevToolsManagerDelegate
*
2556 ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
2557 #if defined(OS_ANDROID)
2558 return new DevToolsManagerDelegateAndroid();
2560 return new ChromeDevToolsManagerDelegate();
2564 bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2565 content::BrowserContext
* browser_context
,
2567 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2568 return ChromeContentBrowserClientPluginsPart::
2569 IsPluginAllowedToCallRequestOSFileHandle(browser_context
, url
,
2570 allowed_file_handle_origins_
);
2576 bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
2577 content::BrowserContext
* browser_context
,
2579 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2580 return ChromeContentBrowserClientPluginsPart::
2581 IsPluginAllowedToUseDevChannelAPIs(browser_context
, url
,
2582 allowed_dev_channel_origins_
);
2589 ChromeContentBrowserClient::OverrideCookieStoreForRenderProcess(
2590 int render_process_id
) {
2591 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
2592 if (!prerender_tracker_
)
2594 return prerender_tracker_
->GetPrerenderCookieStoreForRenderProcess(
2595 render_process_id
).get();
2598 #if defined(ENABLE_WEBRTC)
2599 void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
2600 CommandLine
* to_command_line
,
2601 const CommandLine
& from_command_line
,
2602 VersionInfo::Channel channel
) {
2603 #if defined(OS_ANDROID)
2604 const VersionInfo::Channel kMaxDisableEncryptionChannel
=
2605 VersionInfo::CHANNEL_BETA
;
2607 const VersionInfo::Channel kMaxDisableEncryptionChannel
=
2608 VersionInfo::CHANNEL_DEV
;
2610 if (channel
<= kMaxDisableEncryptionChannel
) {
2611 static const char* const kWebRtcDevSwitchNames
[] = {
2612 switches::kDisableWebRtcEncryption
,
2614 to_command_line
->CopySwitchesFrom(from_command_line
,
2615 kWebRtcDevSwitchNames
,
2616 arraysize(kWebRtcDevSwitchNames
));
2619 #endif // defined(ENABLE_WEBRTC)
2621 } // namespace chrome