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/content_settings_utils.h"
31 #include "chrome/browser/content_settings/cookie_settings.h"
32 #include "chrome/browser/content_settings/host_content_settings_map.h"
33 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
34 #include "chrome/browser/defaults.h"
35 #include "chrome/browser/download/download_prefs.h"
36 #include "chrome/browser/font_family_cache.h"
37 #include "chrome/browser/geolocation/chrome_access_token_store.h"
38 #include "chrome/browser/geolocation/geolocation_permission_context.h"
39 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h"
40 #include "chrome/browser/media/cast_transport_host_filter.h"
41 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
42 #include "chrome/browser/media/midi_permission_context.h"
43 #include "chrome/browser/media/midi_permission_context_factory.h"
44 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
45 #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
46 #include "chrome/browser/net/chrome_net_log.h"
47 #include "chrome/browser/notifications/desktop_notification_service.h"
48 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
49 #include "chrome/browser/platform_util.h"
50 #include "chrome/browser/plugins/plugin_info_message_filter.h"
51 #include "chrome/browser/prerender/prerender_final_status.h"
52 #include "chrome/browser/prerender/prerender_manager.h"
53 #include "chrome/browser/prerender/prerender_manager_factory.h"
54 #include "chrome/browser/prerender/prerender_message_filter.h"
55 #include "chrome/browser/prerender/prerender_tracker.h"
56 #include "chrome/browser/printing/printing_message_filter.h"
57 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
58 #include "chrome/browser/profiles/profile.h"
59 #include "chrome/browser/profiles/profile_io_data.h"
60 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
61 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
62 #include "chrome/browser/search/instant_service.h"
63 #include "chrome/browser/search/instant_service_factory.h"
64 #include "chrome/browser/search/search.h"
65 #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
66 #include "chrome/browser/signin/principals_message_filter.h"
67 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
68 #include "chrome/browser/speech/tts_controller.h"
69 #include "chrome/browser/speech/tts_message_filter.h"
70 #include "chrome/browser/ssl/ssl_add_certificate.h"
71 #include "chrome/browser/ssl/ssl_blocking_page.h"
72 #include "chrome/browser/ssl/ssl_client_certificate_selector.h"
73 #include "chrome/browser/tab_contents/tab_util.h"
74 #include "chrome/browser/ui/blocked_content/blocked_window_params.h"
75 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
76 #include "chrome/browser/ui/chrome_select_file_policy.h"
77 #include "chrome/browser/ui/sync/sync_promo_ui.h"
78 #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
79 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
80 #include "chrome/common/chrome_constants.h"
81 #include "chrome/common/chrome_paths.h"
82 #include "chrome/common/chrome_switches.h"
83 #include "chrome/common/env_vars.h"
84 #include "chrome/common/logging_chrome.h"
85 #include "chrome/common/pepper_permission_util.h"
86 #include "chrome/common/pref_names.h"
87 #include "chrome/common/render_messages.h"
88 #include "chrome/common/url_constants.h"
89 #include "chrome/grit/generated_resources.h"
90 #include "chrome/installer/util/google_update_settings.h"
91 #include "chromeos/chromeos_constants.h"
92 #include "components/cdm/browser/cdm_message_filter_android.h"
93 #include "components/cloud_devices/common/cloud_devices_switches.h"
94 #include "components/content_settings/core/browser/content_settings_provider.h"
95 #include "components/content_settings/core/common/content_settings.h"
96 #include "components/content_settings/core/common/permission_request_id.h"
97 #include "components/dom_distiller/core/url_constants.h"
98 #include "components/google/core/browser/google_util.h"
99 #include "components/metrics/client_info.h"
100 #include "components/pref_registry/pref_registry_syncable.h"
101 #include "components/signin/core/common/profile_management_switches.h"
102 #include "components/translate/core/common/translate_switches.h"
103 #include "content/public/browser/browser_child_process_host.h"
104 #include "content/public/browser/browser_main_parts.h"
105 #include "content/public/browser/browser_ppapi_host.h"
106 #include "content/public/browser/browser_thread.h"
107 #include "content/public/browser/browser_url_handler.h"
108 #include "content/public/browser/child_process_data.h"
109 #include "content/public/browser/child_process_security_policy.h"
110 #include "content/public/browser/desktop_notification_delegate.h"
111 #include "content/public/browser/render_frame_host.h"
112 #include "content/public/browser/render_process_host.h"
113 #include "content/public/browser/render_view_host.h"
114 #include "content/public/browser/resource_context.h"
115 #include "content/public/browser/site_instance.h"
116 #include "content/public/browser/web_contents.h"
117 #include "content/public/common/child_process_host.h"
118 #include "content/public/common/content_descriptors.h"
119 #include "content/public/common/show_desktop_notification_params.h"
120 #include "content/public/common/url_utils.h"
121 #include "content/public/common/web_preferences.h"
122 #include "net/base/mime_util.h"
123 #include "net/cookies/canonical_cookie.h"
124 #include "net/cookies/cookie_options.h"
125 #include "net/ssl/ssl_cert_request_info.h"
126 #include "ppapi/host/ppapi_host.h"
127 #include "ppapi/shared_impl/ppapi_switches.h"
128 #include "storage/browser/fileapi/external_mount_points.h"
129 #include "ui/base/l10n/l10n_util.h"
130 #include "ui/base/resource/resource_bundle.h"
131 #include "ui/resources/grit/ui_resources.h"
134 #include "base/win/windows_version.h"
135 #include "chrome/browser/chrome_browser_main_win.h"
136 #include "sandbox/win/src/sandbox_policy.h"
137 #elif defined(OS_MACOSX)
138 #include "chrome/browser/chrome_browser_main_mac.h"
139 #include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
140 #include "components/crash/app/breakpad_mac.h"
141 #elif defined(OS_CHROMEOS)
142 #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
143 #include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h"
144 #include "chrome/browser/chromeos/file_manager/app_id.h"
145 #include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
146 #include "chrome/browser/chromeos/fileapi/file_system_backend.h"
147 #include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
148 #include "chrome/browser/chromeos/login/startup_utils.h"
149 #include "chrome/browser/chromeos/system/input_device_settings.h"
150 #include "chromeos/chromeos_switches.h"
151 #include "components/user_manager/user_manager.h"
152 #elif defined(OS_LINUX)
153 #include "chrome/browser/chrome_browser_main_linux.h"
154 #elif defined(OS_ANDROID)
155 #include "chrome/browser/android/new_tab_page_url_handler.h"
156 #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
157 #include "chrome/browser/chrome_browser_main_android.h"
158 #include "chrome/browser/media/protected_media_identifier_permission_context.h"
159 #include "chrome/browser/media/protected_media_identifier_permission_context_factory.h"
160 #include "chrome/common/descriptors_android.h"
161 #include "components/crash/browser/crash_dump_manager_android.h"
162 #elif defined(OS_POSIX)
163 #include "chrome/browser/chrome_browser_main_posix.h"
166 #if defined(OS_POSIX) && !defined(OS_MACOSX)
167 #include "base/debug/leak_annotations.h"
168 #include "components/crash/app/breakpad_linux.h"
169 #include "components/crash/browser/crash_handler_host_linux.h"
172 #if defined(OS_ANDROID)
173 #include "ui/base/ui_base_paths.h"
174 #include "ui/gfx/android/device_display_info.h"
177 #if defined(OS_ANDROID)
178 #include "chrome/browser/android/dev_tools_manager_delegate_android.h"
180 #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
183 #if !defined(OS_CHROMEOS)
184 #include "chrome/browser/signin/chrome_signin_client.h"
185 #include "chrome/browser/signin/chrome_signin_client_factory.h"
186 #include "chrome/browser/signin/signin_manager_factory.h"
187 #include "components/signin/core/browser/signin_manager.h"
190 #if defined(TOOLKIT_VIEWS)
191 #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
194 #if defined(USE_ATHENA)
195 #include "athena/content/public/web_contents_view_delegate_creator.h"
196 #include "chrome/browser/ui/views/athena/chrome_browser_main_extra_parts_athena.h"
197 #elif defined(USE_ASH)
198 #include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
201 #if defined(USE_AURA)
202 #include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
206 #include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
209 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
210 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
213 #if !defined(DISABLE_NACL)
214 #include "components/nacl/browser/nacl_browser.h"
215 #include "components/nacl/browser/nacl_host_message_filter.h"
216 #include "components/nacl/browser/nacl_process_host.h"
217 #include "components/nacl/common/nacl_process_type.h"
218 #include "components/nacl/common/nacl_switches.h"
221 #if defined(ENABLE_EXTENSIONS)
222 #include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
223 #include "chrome/browser/extensions/extension_service.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_system.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_SPELLCHECK)
243 #include "chrome/browser/spellchecker/spellcheck_message_filter.h"
246 #if defined(ENABLE_WEBRTC)
247 #include "chrome/browser/media/webrtc_logging_handler_host.h"
250 using base::FileDescriptor
;
251 using blink::WebWindowFeatures
;
252 using content::AccessTokenStore
;
253 using content::BrowserThread
;
254 using content::BrowserURLHandler
;
255 using content::ChildProcessSecurityPolicy
;
256 using content::QuotaPermissionContext
;
257 using content::RenderFrameHost
;
258 using content::RenderViewHost
;
259 using content::ResourceType
;
260 using content::SiteInstance
;
261 using content::WebContents
;
262 using content::WebPreferences
;
263 using message_center::NotifierId
;
265 #if defined(OS_POSIX)
266 using content::FileDescriptorInfo
;
269 #if defined(ENABLE_EXTENSIONS)
270 using extensions::APIPermission
;
271 using extensions::ChromeContentBrowserClientExtensionsPart
;
272 using extensions::Extension
;
273 using extensions::InfoMap
;
274 using extensions::Manifest
;
279 // Cached version of the locale so we can return the locale on the I/O
281 base::LazyInstance
<std::string
> g_io_thread_application_locale
;
283 #if defined(ENABLE_PLUGINS)
284 // TODO(teravest): Add renderer-side API-specific checking for these APIs so
285 // that blanket permission isn't granted to all dev channel APIs for these.
286 // http://crbug.com/386743
287 const char* const kPredefinedAllowedDevChannelOrigins
[] = {
288 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/383937
289 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/383937
292 const char* const kPredefinedAllowedFileHandleOrigins
[] = {
293 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
294 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
297 const char* const kPredefinedAllowedSocketOrigins
[] = {
298 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
299 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
300 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
301 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
302 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
303 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
304 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
305 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
306 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
307 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
308 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
309 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
310 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
311 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
312 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
313 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
314 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
315 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
316 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
317 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
321 // Returns a copy of the given url with its host set to given host and path set
322 // to given path. Other parts of the url will be the same.
323 GURL
ReplaceURLHostAndPath(const GURL
& url
,
324 const std::string
& host
,
325 const std::string
& path
) {
326 url::Replacements
<char> replacements
;
327 replacements
.SetHost(host
.c_str(), url::Component(0, host
.length()));
328 replacements
.SetPath(path
.c_str(), url::Component(0, path
.length()));
329 return url
.ReplaceComponents(replacements
);
332 // Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
333 GURL
AddUberHost(const GURL
& url
) {
334 const std::string uber_host
= chrome::kChromeUIUberHost
;
335 const std::string new_path
= url
.host() + url
.path();
337 return ReplaceURLHostAndPath(url
, uber_host
, new_path
);
340 // If url->host() is "chrome" and url->path() has characters other than the
341 // first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
342 // returns true. Otherwise returns false.
343 bool RemoveUberHost(GURL
* url
) {
344 if (url
->host() != chrome::kChromeUIUberHost
)
347 if (url
->path().empty() || url
->path() == "/")
350 const std::string old_path
= url
->path();
352 const std::string::size_type separator
= old_path
.find('/', 1);
353 std::string new_host
;
354 std::string new_path
;
355 if (separator
== std::string::npos
) {
356 new_host
= old_path
.substr(1);
358 new_host
= old_path
.substr(1, separator
- 1);
359 new_path
= old_path
.substr(separator
);
362 // Do not allow URLs with paths empty before the first slash since we can't
363 // have an empty host. (e.g "foo://chrome//")
364 if (new_host
.empty())
367 *url
= ReplaceURLHostAndPath(*url
, new_host
, new_path
);
369 DCHECK(url
->is_valid());
374 // Handles rewriting Web UI URLs.
375 bool HandleWebUI(GURL
* url
, content::BrowserContext
* browser_context
) {
376 // Do not handle special URLs such as "about:foo"
377 if (!url
->host().empty()) {
378 const GURL chrome_url
= AddUberHost(*url
);
380 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
382 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
383 browser_context
, chrome_url
))
387 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
388 browser_context
, *url
))
391 #if defined(OS_CHROMEOS)
392 // Special case : in ChromeOS in Guest mode bookmarks and history are
393 // disabled for security reasons. New tab page explains the reasons, so
394 // we redirect user to new tab page.
395 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
396 if (url
->SchemeIs(content::kChromeUIScheme
) &&
397 (url
->DomainIs(chrome::kChromeUIBookmarksHost
) ||
398 url
->DomainIs(chrome::kChromeUIHistoryHost
))) {
399 // Rewrite with new tab URL
400 *url
= GURL(chrome::kChromeUINewTabURL
);
408 // Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
410 bool HandleWebUIReverse(GURL
* url
, content::BrowserContext
* browser_context
) {
411 if (!url
->is_valid() || !url
->SchemeIs(content::kChromeUIScheme
))
414 return RemoveUberHost(url
);
417 bool CertMatchesFilter(const net::X509Certificate
& cert
,
418 const base::DictionaryValue
& filter
) {
419 // TODO(markusheintz): This is the minimal required filter implementation.
420 // Implement a better matcher.
422 // An empty filter matches any client certificate since no requirements are
427 std::string common_name
;
428 if (filter
.GetString("ISSUER.CN", &common_name
) &&
429 (cert
.issuer().common_name
== common_name
)) {
435 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
436 breakpad::CrashHandlerHostLinux
* CreateCrashHandlerHost(
437 const std::string
& process_type
) {
438 base::FilePath dumps_path
;
439 PathService::Get(chrome::DIR_CRASH_DUMPS
, &dumps_path
);
441 ANNOTATE_SCOPED_MEMORY_LEAK
;
442 bool upload
= (getenv(env_vars::kHeadless
) == NULL
);
443 breakpad::CrashHandlerHostLinux
* crash_handler
=
444 new breakpad::CrashHandlerHostLinux(process_type
, dumps_path
, upload
);
445 crash_handler
->StartUploaderThread();
446 return crash_handler
;
450 int GetCrashSignalFD(const CommandLine
& command_line
) {
451 // Extensions have the same process type as renderers.
452 if (command_line
.HasSwitch(extensions::switches::kExtensionProcess
)) {
453 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
455 crash_handler
= CreateCrashHandlerHost("extension");
456 return crash_handler
->GetDeathSignalSocket();
459 std::string process_type
=
460 command_line
.GetSwitchValueASCII(switches::kProcessType
);
462 if (process_type
== switches::kRendererProcess
) {
463 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
465 crash_handler
= CreateCrashHandlerHost(process_type
);
466 return crash_handler
->GetDeathSignalSocket();
469 if (process_type
== switches::kPluginProcess
) {
470 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
472 crash_handler
= CreateCrashHandlerHost(process_type
);
473 return crash_handler
->GetDeathSignalSocket();
476 if (process_type
== switches::kPpapiPluginProcess
) {
477 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
479 crash_handler
= CreateCrashHandlerHost(process_type
);
480 return crash_handler
->GetDeathSignalSocket();
483 if (process_type
== switches::kGpuProcess
) {
484 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
486 crash_handler
= CreateCrashHandlerHost(process_type
);
487 return crash_handler
->GetDeathSignalSocket();
492 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
494 #if !defined(OS_CHROMEOS)
495 GURL
GetEffectiveURLForSignin(const GURL
& url
) {
496 CHECK(SigninManager::IsWebBasedSigninFlowURL(url
));
498 GURL
effective_url(SigninManager::kChromeSigninEffectiveSite
);
499 // Copy the path because the argument to SetPathStr must outlive
500 // the Replacements object.
501 const std::string
path_copy(url
.path());
502 GURL::Replacements replacements
;
503 replacements
.SetPathStr(path_copy
);
504 effective_url
= effective_url
.ReplaceComponents(replacements
);
505 return effective_url
;
509 void SetApplicationLocaleOnIOThread(const std::string
& locale
) {
510 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
511 g_io_thread_application_locale
.Get() = locale
;
514 void HandleBlockedPopupOnUIThread(const BlockedWindowParams
& params
) {
515 WebContents
* tab
= tab_util::GetWebContentsByID(params
.render_process_id(),
520 prerender::PrerenderContents
* prerender_contents
=
521 prerender::PrerenderContents::FromWebContents(tab
);
522 if (prerender_contents
) {
523 prerender_contents
->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW
);
527 PopupBlockerTabHelper
* popup_helper
=
528 PopupBlockerTabHelper::FromWebContents(tab
);
531 popup_helper
->AddBlockedPopup(params
);
534 #if defined(OS_ANDROID)
536 void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams
& params
) {
537 WebContents
* web_contents
=
538 tab_util::GetWebContentsByID(params
.render_process_id(),
543 SingleTabModeTabHelper::FromWebContents(web_contents
)->HandleOpenUrl(params
);
546 float GetDeviceScaleAdjustment() {
547 static const float kMinFSM
= 1.05f
;
548 static const int kWidthForMinFSM
= 320;
549 static const float kMaxFSM
= 1.3f
;
550 static const int kWidthForMaxFSM
= 800;
552 gfx::DeviceDisplayInfo info
;
553 int minWidth
= info
.GetSmallestDIPWidth();
555 if (minWidth
<= kWidthForMinFSM
)
557 if (minWidth
>= kWidthForMaxFSM
)
560 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
561 float ratio
= static_cast<float>(minWidth
- kWidthForMinFSM
) /
562 (kWidthForMaxFSM
- kWidthForMinFSM
);
563 return ratio
* (kMaxFSM
- kMinFSM
) + kMinFSM
;
566 #endif // defined(OS_ANDROID)
568 #if defined(ENABLE_EXTENSIONS)
569 // By default, JavaScript and images are enabled in guest content.
570 void GetGuestViewDefaultContentSettingRules(
572 RendererContentSettingRules
* rules
) {
573 rules
->image_rules
.push_back(
574 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
575 ContentSettingsPattern::Wildcard(),
576 CONTENT_SETTING_ALLOW
,
580 rules
->script_rules
.push_back(
581 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
582 ContentSettingsPattern::Wildcard(),
583 CONTENT_SETTING_ALLOW
,
587 #endif // defined(ENALBE_EXTENSIONS)
593 ChromeContentBrowserClient::ChromeContentBrowserClient()
594 : prerender_tracker_(NULL
),
595 weak_factory_(this) {
596 #if defined(ENABLE_PLUGINS)
597 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedDevChannelOrigins
); ++i
)
598 allowed_dev_channel_origins_
.insert(kPredefinedAllowedDevChannelOrigins
[i
]);
599 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedFileHandleOrigins
); ++i
)
600 allowed_file_handle_origins_
.insert(kPredefinedAllowedFileHandleOrigins
[i
]);
601 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedSocketOrigins
); ++i
)
602 allowed_socket_origins_
.insert(kPredefinedAllowedSocketOrigins
[i
]);
605 #if !defined(OS_ANDROID)
606 TtsExtensionEngine
* tts_extension_engine
= TtsExtensionEngine::GetInstance();
607 TtsController::GetInstance()->SetTtsEngineDelegate(tts_extension_engine
);
610 #if defined(ENABLE_EXTENSIONS)
611 extra_parts_
.push_back(new ChromeContentBrowserClientExtensionsPart
);
615 ChromeContentBrowserClient::~ChromeContentBrowserClient() {
616 for (int i
= static_cast<int>(extra_parts_
.size()) - 1; i
>= 0; --i
)
617 delete extra_parts_
[i
];
618 extra_parts_
.clear();
622 void ChromeContentBrowserClient::RegisterProfilePrefs(
623 user_prefs::PrefRegistrySyncable
* registry
) {
624 registry
->RegisterBooleanPref(
625 prefs::kDisable3DAPIs
,
627 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
628 registry
->RegisterBooleanPref(
629 prefs::kEnableHyperlinkAuditing
,
631 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
632 registry
->RegisterListPref(
633 prefs::kEnableDeprecatedWebPlatformFeatures
,
634 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
638 void ChromeContentBrowserClient::SetApplicationLocale(
639 const std::string
& locale
) {
640 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
642 // This object is guaranteed to outlive all threads so we don't have to
643 // worry about the lack of refcounting and can just post as Unretained.
645 // The common case is that this function is called early in Chrome startup
646 // before any threads are created (it will also be called later if the user
647 // changes the pref). In this case, there will be no threads created and
648 // posting will fail. When there are no threads, we can just set the string
649 // without worrying about threadsafety.
650 if (!BrowserThread::PostTask(BrowserThread::IO
, FROM_HERE
,
651 base::Bind(&SetApplicationLocaleOnIOThread
, locale
))) {
652 g_io_thread_application_locale
.Get() = locale
;
656 content::BrowserMainParts
* ChromeContentBrowserClient::CreateBrowserMainParts(
657 const content::MainFunctionParams
& parameters
) {
658 ChromeBrowserMainParts
* main_parts
;
659 // Construct the Main browser parts based on the OS type.
661 main_parts
= new ChromeBrowserMainPartsWin(parameters
);
662 #elif defined(OS_MACOSX)
663 main_parts
= new ChromeBrowserMainPartsMac(parameters
);
664 #elif defined(OS_CHROMEOS)
665 main_parts
= new chromeos::ChromeBrowserMainPartsChromeos(parameters
);
666 #elif defined(OS_LINUX)
667 main_parts
= new ChromeBrowserMainPartsLinux(parameters
);
668 #elif defined(OS_ANDROID)
669 main_parts
= new ChromeBrowserMainPartsAndroid(parameters
);
670 #elif defined(OS_POSIX)
671 main_parts
= new ChromeBrowserMainPartsPosix(parameters
);
674 main_parts
= new ChromeBrowserMainParts(parameters
);
677 chrome::AddProfilesExtraParts(main_parts
);
679 // Construct additional browser parts. Stages are called in the order in
680 // which they are added.
681 #if defined(TOOLKIT_VIEWS)
682 main_parts
->AddParts(new ChromeBrowserMainExtraPartsViews());
685 // TODO(oshima): Athena on chrome currently requires USE_ASH to build.
686 // We should reduce the dependency as much as possible.
687 #if defined(USE_ATHENA)
688 main_parts
->AddParts(CreateChromeBrowserMainExtraPartsAthena());
689 #elif defined(USE_ASH)
690 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAsh());
693 #if defined(USE_AURA)
694 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAura());
698 main_parts
->AddParts(new ChromeBrowserMainExtraPartsX11());
701 chrome::AddMetricsExtraParts(main_parts
);
706 std::string
ChromeContentBrowserClient::GetStoragePartitionIdForSite(
707 content::BrowserContext
* browser_context
,
709 std::string partition_id
;
711 // The partition ID for webview guest processes is the string value of its
712 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
713 if (site
.SchemeIs(content::kGuestScheme
)) {
714 partition_id
= site
.spec();
715 } else if (site
.GetOrigin().spec() == kChromeUIChromeSigninURL
&&
716 !switches::IsEnableWebviewBasedSignin()) {
717 // Chrome signin page has an embedded iframe of extension and web content,
718 // thus it must be isolated from other webUI pages.
719 partition_id
= site
.GetOrigin().spec();
722 DCHECK(IsValidStoragePartitionId(browser_context
, partition_id
));
726 bool ChromeContentBrowserClient::IsValidStoragePartitionId(
727 content::BrowserContext
* browser_context
,
728 const std::string
& partition_id
) {
729 // The default ID is empty and is always valid.
730 if (partition_id
.empty())
733 return GURL(partition_id
).is_valid();
736 void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
737 content::BrowserContext
* browser_context
,
740 std::string
* partition_domain
,
741 std::string
* partition_name
,
743 // Default to the browser-wide storage partition and override based on |site|
745 partition_domain
->clear();
746 partition_name
->clear();
749 bool success
= false;
750 #if defined(ENABLE_EXTENSIONS)
751 success
= extensions::WebViewGuest::GetGuestPartitionConfigForSite(
752 site
, partition_domain
, partition_name
, in_memory
);
754 if (!success
&& site
.SchemeIs(extensions::kExtensionScheme
)) {
755 // If |can_be_default| is false, the caller is stating that the |site|
756 // should be parsed as if it had isolated storage. In particular it is
757 // important to NOT check ExtensionService for the is_storage_isolated()
758 // attribute because this code path is run during Extension uninstall
759 // to do cleanup after the Extension has already been unloaded from the
761 bool is_isolated
= !can_be_default
;
762 if (can_be_default
) {
763 if (extensions::util::SiteHasIsolatedStorage(site
, browser_context
))
768 CHECK(site
.has_host());
769 // For extensions with isolated storage, the the host of the |site| is
770 // the |partition_domain|. The |in_memory| and |partition_name| are only
771 // used in guest schemes so they are cleared here.
772 *partition_domain
= site
.host();
774 partition_name
->clear();
780 if (!success
&& (site
.GetOrigin().spec() == kChromeUIChromeSigninURL
) &&
781 !switches::IsEnableWebviewBasedSignin()) {
782 // Chrome signin page has an embedded iframe of extension and web content,
783 // thus it must be isolated from other webUI pages.
784 *partition_domain
= chrome::kChromeUIChromeSigninHost
;
787 // Assert that if |can_be_default| is false, the code above must have found a
788 // non-default partition. If this fails, the caller has a serious logic
789 // error about which StoragePartition they expect to be in and it is not
791 CHECK(can_be_default
|| !partition_domain
->empty());
794 content::WebContentsViewDelegate
*
795 ChromeContentBrowserClient::GetWebContentsViewDelegate(
796 content::WebContents
* web_contents
) {
797 #if defined(USE_ATHENA)
798 return athena::CreateWebContentsViewDelegate(web_contents
);
800 return chrome::CreateWebContentsViewDelegate(web_contents
);
804 void ChromeContentBrowserClient::RenderProcessWillLaunch(
805 content::RenderProcessHost
* host
) {
806 int id
= host
->GetID();
807 Profile
* profile
= Profile::FromBrowserContext(host
->GetBrowserContext());
808 net::URLRequestContextGetter
* context
=
809 profile
->GetRequestContextForRenderProcess(id
);
811 host
->AddFilter(new ChromeRenderMessageFilter(id
, profile
));
812 #if defined(ENABLE_PLUGINS)
813 host
->AddFilter(new PluginInfoMessageFilter(id
, profile
));
815 host
->AddFilter(new cast::CastTransportHostFilter
);
816 #if defined(ENABLE_PRINTING)
817 host
->AddFilter(new printing::PrintingMessageFilter(id
, profile
));
819 host
->AddFilter(new SearchProviderInstallStateMessageFilter(id
, profile
));
820 #if defined(ENABLE_SPELLCHECK)
821 host
->AddFilter(new SpellCheckMessageFilter(id
));
823 #if defined(OS_MACOSX)
824 host
->AddFilter(new SpellCheckMessageFilterMac(id
));
826 host
->AddFilter(new ChromeNetBenchmarkingMessageFilter(profile
, context
));
827 host
->AddFilter(new prerender::PrerenderMessageFilter(id
, profile
));
828 host
->AddFilter(new TtsMessageFilter(id
, host
->GetBrowserContext()));
829 #if defined(ENABLE_WEBRTC)
830 WebRtcLoggingHandlerHost
* webrtc_logging_handler_host
=
831 new WebRtcLoggingHandlerHost(profile
);
832 host
->SetWebRtcLogMessageCallback(base::Bind(
833 &WebRtcLoggingHandlerHost::LogMessage
, webrtc_logging_handler_host
));
834 host
->AddFilter(webrtc_logging_handler_host
);
835 host
->SetUserData(host
, new base::UserDataAdapter
<WebRtcLoggingHandlerHost
>(
836 webrtc_logging_handler_host
));
838 #if !defined(DISABLE_NACL)
839 host
->AddFilter(new nacl::NaClHostMessageFilter(
840 id
, profile
->IsOffTheRecord(),
844 #if defined(OS_ANDROID)
845 host
->AddFilter(new cdm::CdmMessageFilterAndroid());
847 if (switches::IsEnableAccountConsistency())
848 host
->AddFilter(new PrincipalsMessageFilter(id
));
850 host
->Send(new ChromeViewMsg_SetIsIncognitoProcess(
851 profile
->IsOffTheRecord()));
853 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
854 extra_parts_
[i
]->RenderProcessWillLaunch(host
);
856 RendererContentSettingRules rules
;
857 if (host
->IsIsolatedGuest()) {
858 #if defined(ENABLE_EXTENSIONS)
859 GetGuestViewDefaultContentSettingRules(profile
->IsOffTheRecord(), &rules
);
864 GetRendererContentSettingRules(
865 profile
->GetHostContentSettingsMap(), &rules
);
867 host
->Send(new ChromeViewMsg_SetContentSettingRules(rules
));
870 GURL
ChromeContentBrowserClient::GetEffectiveURL(
871 content::BrowserContext
* browser_context
, const GURL
& url
) {
872 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
876 // If the input |url| should be assigned to the Instant renderer, make its
877 // effective URL distinct from other URLs on the search provider's domain.
878 if (chrome::ShouldAssignURLToInstantRenderer(url
, profile
))
879 return chrome::GetEffectiveURLForInstant(url
, profile
);
881 #if !defined(OS_CHROMEOS)
882 // If the input |url| should be assigned to the Signin renderer, make its
883 // effective URL distinct from other URLs on the signin service's domain.
884 // Note that the signin renderer will be allowed to sign the user in to
886 if (SigninManager::IsWebBasedSigninFlowURL(url
))
887 return GetEffectiveURLForSignin(url
);
890 #if defined(ENABLE_EXTENSIONS)
891 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(
898 bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
899 content::BrowserContext
* browser_context
, const GURL
& effective_url
) {
900 // Non-extension, non-Instant URLs should generally use
901 // process-per-site-instance. Because we expect to use the effective URL,
902 // URLs for hosted apps (apart from bookmark apps) should have an extension
905 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
909 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url
, profile
))
912 #if !defined(OS_CHROMEOS)
913 if (SigninManager::IsWebBasedSigninFlowURL(effective_url
))
917 #if defined(ENABLE_EXTENSIONS)
918 return ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
919 profile
, effective_url
);
925 // These are treated as WebUI schemes but do not get WebUI bindings. Also,
926 // view-source is allowed for these schemes.
927 void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
928 std::vector
<std::string
>* additional_schemes
) {
929 additional_schemes
->push_back(chrome::kChromeSearchScheme
);
930 additional_schemes
->push_back(dom_distiller::kDomDistillerScheme
);
933 void ChromeContentBrowserClient::GetAdditionalWebUIHostsToIgnoreParititionCheck(
934 std::vector
<std::string
>* hosts
) {
935 hosts
->push_back(chrome::kChromeUIExtensionIconHost
);
936 hosts
->push_back(chrome::kChromeUIFaviconHost
);
937 hosts
->push_back(chrome::kChromeUIThemeHost
);
938 hosts
->push_back(chrome::kChromeUIThumbnailHost
);
939 hosts
->push_back(chrome::kChromeUIThumbnailHost2
);
940 hosts
->push_back(chrome::kChromeUIThumbnailListHost
);
943 net::URLRequestContextGetter
*
944 ChromeContentBrowserClient::CreateRequestContext(
945 content::BrowserContext
* browser_context
,
946 content::ProtocolHandlerMap
* protocol_handlers
,
947 content::URLRequestInterceptorScopedVector request_interceptors
) {
948 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
949 return profile
->CreateRequestContext(protocol_handlers
,
950 request_interceptors
.Pass());
953 net::URLRequestContextGetter
*
954 ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
955 content::BrowserContext
* browser_context
,
956 const base::FilePath
& partition_path
,
958 content::ProtocolHandlerMap
* protocol_handlers
,
959 content::URLRequestInterceptorScopedVector request_interceptors
) {
960 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
961 return profile
->CreateRequestContextForStoragePartition(
965 request_interceptors
.Pass());
968 bool ChromeContentBrowserClient::IsHandledURL(const GURL
& url
) {
969 return ProfileIOData::IsHandledURL(url
);
972 bool ChromeContentBrowserClient::CanCommitURL(
973 content::RenderProcessHost
* process_host
,
975 #if defined(ENABLE_EXTENSIONS)
976 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(
983 bool ChromeContentBrowserClient::ShouldAllowOpenURL(
984 content::SiteInstance
* site_instance
, const GURL
& url
) {
985 GURL from_url
= site_instance
->GetSiteURL();
987 #if defined(ENABLE_EXTENSIONS)
989 if (ChromeContentBrowserClientExtensionsPart::ShouldAllowOpenURL(
990 site_instance
, from_url
, url
, &result
))
994 // Do not allow chrome://chrome-signin navigate to other chrome:// URLs, since
995 // the signin page may host untrusted web content.
996 if (from_url
.GetOrigin().spec() == chrome::kChromeUIChromeSigninURL
&&
997 url
.SchemeIs(content::kChromeUIScheme
) &&
998 url
.host() != chrome::kChromeUIChromeSigninHost
) {
999 VLOG(1) << "Blocked navigation to " << url
.spec() << " from "
1000 << chrome::kChromeUIChromeSigninURL
;
1007 bool ChromeContentBrowserClient::IsSuitableHost(
1008 content::RenderProcessHost
* process_host
,
1009 const GURL
& site_url
) {
1011 Profile::FromBrowserContext(process_host
->GetBrowserContext());
1012 // This may be NULL during tests. In that case, just assume any site can
1017 // Instant URLs should only be in the instant process and instant process
1018 // should only have Instant URLs.
1019 InstantService
* instant_service
=
1020 InstantServiceFactory::GetForProfile(profile
);
1021 if (instant_service
) {
1022 bool is_instant_process
= instant_service
->IsInstantProcess(
1023 process_host
->GetID());
1024 bool should_be_in_instant_process
=
1025 chrome::ShouldAssignURLToInstantRenderer(site_url
, profile
);
1026 if (is_instant_process
|| should_be_in_instant_process
)
1027 return is_instant_process
&& should_be_in_instant_process
;
1030 #if !defined(OS_CHROMEOS)
1031 SigninClient
* signin_client
=
1032 ChromeSigninClientFactory::GetForProfile(profile
);
1033 if (signin_client
&& signin_client
->IsSigninProcess(process_host
->GetID()))
1034 return SigninManager::IsWebBasedSigninFlowURL(site_url
);
1037 #if defined(ENABLE_EXTENSIONS)
1038 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1039 profile
, process_host
, site_url
);
1045 bool ChromeContentBrowserClient::MayReuseHost(
1046 content::RenderProcessHost
* process_host
) {
1047 // If there is currently a prerender in progress for the host provided,
1048 // it may not be shared. We require prerenders to be by themselves in a
1049 // separate process, so that we can monitor their resource usage, and so that
1050 // we can track the cookies that they change.
1051 Profile
* profile
= Profile::FromBrowserContext(
1052 process_host
->GetBrowserContext());
1053 prerender::PrerenderManager
* prerender_manager
=
1054 prerender::PrerenderManagerFactory::GetForProfile(profile
);
1055 if (prerender_manager
&&
1056 !prerender_manager
->MayReuseProcessHost(process_host
)) {
1063 bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1064 content::BrowserContext
* browser_context
, const GURL
& url
) {
1065 // It has to be a valid URL for us to check for an extension.
1066 if (!url
.is_valid())
1069 #if defined(ENABLE_EXTENSIONS)
1070 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1071 return ChromeContentBrowserClientExtensionsPart::
1072 ShouldTryToUseExistingProcessHost(
1079 void ChromeContentBrowserClient::SiteInstanceGotProcess(
1080 SiteInstance
* site_instance
) {
1081 CHECK(site_instance
->HasProcess());
1083 Profile
* profile
= Profile::FromBrowserContext(
1084 site_instance
->GetBrowserContext());
1088 // Remember the ID of the Instant process to signal the renderer process
1089 // on startup in |AppendExtraCommandLineSwitches| below.
1090 if (chrome::ShouldAssignURLToInstantRenderer(
1091 site_instance
->GetSiteURL(), profile
)) {
1092 InstantService
* instant_service
=
1093 InstantServiceFactory::GetForProfile(profile
);
1094 if (instant_service
)
1095 instant_service
->AddInstantProcess(site_instance
->GetProcess()->GetID());
1098 #if !defined(OS_CHROMEOS)
1099 // We only expect there to be one signin process as we use process-per-site
1100 // for signin URLs. The signin process will be cleared from SigninManager
1101 // when the renderer is destroyed.
1102 if (SigninManager::IsWebBasedSigninFlowURL(site_instance
->GetSiteURL())) {
1103 SigninClient
* signin_client
=
1104 ChromeSigninClientFactory::GetForProfile(profile
);
1106 signin_client
->SetSigninProcess(site_instance
->GetProcess()->GetID());
1107 #if defined(ENABLE_EXTENSIONS)
1108 ChromeContentBrowserClientExtensionsPart::SetSigninProcess(site_instance
);
1113 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
1114 extra_parts_
[i
]->SiteInstanceGotProcess(site_instance
);
1117 void ChromeContentBrowserClient::SiteInstanceDeleting(
1118 SiteInstance
* site_instance
) {
1119 if (!site_instance
->HasProcess())
1122 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
1123 extra_parts_
[i
]->SiteInstanceDeleting(site_instance
);
1126 bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
1127 SiteInstance
* site_instance
,
1128 const GURL
& current_url
,
1129 const GURL
& new_url
) {
1130 #if defined(ENABLE_EXTENSIONS)
1131 return ChromeContentBrowserClientExtensionsPart::
1132 ShouldSwapBrowsingInstancesForNavigation(
1133 site_instance
, current_url
, new_url
);
1139 bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1140 content::ResourceContext
* resource_context
, const GURL
& current_url
,
1141 const GURL
& new_url
) {
1142 #if defined(ENABLE_EXTENSIONS)
1143 return ChromeContentBrowserClientExtensionsPart::
1144 ShouldSwapProcessesForRedirect(resource_context
, current_url
, new_url
);
1150 bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL
& url
) {
1151 return !url
.SchemeIs(chrome::kChromeNativeScheme
);
1154 std::string
ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1155 const std::string
& alias_name
) {
1156 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name
);
1161 bool IsAutoReloadEnabled() {
1162 // Fetch the field trial, even though we don't use it. Calling FindFullName()
1163 // causes the field-trial mechanism to report which group we're in, which
1164 // might reflect a hard disable or hard enable via flag, both of which have
1165 // their own field trial groups. This lets us know what percentage of users
1166 // manually enable or disable auto-reload.
1167 std::string group
= base::FieldTrialList::FindFullName(
1168 "AutoReloadExperiment");
1169 const CommandLine
& browser_command_line
= *CommandLine::ForCurrentProcess();
1170 if (browser_command_line
.HasSwitch(switches::kEnableOfflineAutoReload
))
1172 if (browser_command_line
.HasSwitch(switches::kDisableOfflineAutoReload
))
1177 bool IsAutoReloadVisibleOnlyEnabled() {
1178 // See the block comment in IsAutoReloadEnabled().
1179 std::string group
= base::FieldTrialList::FindFullName(
1180 "AutoReloadVisibleOnlyExperiment");
1181 const CommandLine
& browser_command_line
= *CommandLine::ForCurrentProcess();
1182 if (browser_command_line
.HasSwitch(
1183 switches::kEnableOfflineAutoReloadVisibleOnly
)) {
1186 if (browser_command_line
.HasSwitch(
1187 switches::kDisableOfflineAutoReloadVisibleOnly
)) {
1195 void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1196 CommandLine
* command_line
, int child_process_id
) {
1197 #if defined(OS_POSIX)
1198 if (breakpad::IsCrashReporterEnabled()) {
1199 scoped_ptr
<metrics::ClientInfo
> client_info
=
1200 GoogleUpdateSettings::LoadMetricsClientInfo();
1201 command_line
->AppendSwitchASCII(switches::kEnableCrashReporter
,
1202 client_info
? client_info
->client_id
1205 #endif // defined(OS_POSIX)
1207 if (logging::DialogsAreSuppressed())
1208 command_line
->AppendSwitch(switches::kNoErrorDialogs
);
1210 std::string process_type
=
1211 command_line
->GetSwitchValueASCII(switches::kProcessType
);
1212 const CommandLine
& browser_command_line
= *CommandLine::ForCurrentProcess();
1214 static const char* const kCommonSwitchNames
[] = {
1215 switches::kUserAgent
,
1216 switches::kUserDataDir
, // Make logs go to the right file.
1218 command_line
->CopySwitchesFrom(browser_command_line
, kCommonSwitchNames
,
1219 arraysize(kCommonSwitchNames
));
1221 #if defined(ENABLE_IPC_FUZZER)
1222 static const char* const kIpcFuzzerSwitches
[] = {
1223 switches::kIpcFuzzerTestcase
,
1225 command_line
->CopySwitchesFrom(browser_command_line
, kIpcFuzzerSwitches
,
1226 arraysize(kIpcFuzzerSwitches
));
1229 #if defined(OS_CHROMEOS)
1230 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
1231 base::FilePath homedir
;
1232 PathService::Get(base::DIR_HOME
, &homedir
);
1233 command_line
->AppendSwitchASCII(chromeos::switches::kHomedir
,
1234 homedir
.value().c_str());
1237 if (process_type
== switches::kRendererProcess
) {
1238 content::RenderProcessHost
* process
=
1239 content::RenderProcessHost::FromID(child_process_id
);
1241 process
? Profile::FromBrowserContext(process
->GetBrowserContext())
1243 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
1244 extra_parts_
[i
]->AppendExtraRendererCommandLineSwitches(
1245 command_line
, process
, profile
);
1248 #if defined(OS_CHROMEOS)
1249 const std::string
& login_profile
=
1250 browser_command_line
.GetSwitchValueASCII(
1251 chromeos::switches::kLoginProfile
);
1252 if (!login_profile
.empty())
1253 command_line
->AppendSwitchASCII(
1254 chromeos::switches::kLoginProfile
, login_profile
);
1257 #if defined(ENABLE_WEBRTC)
1258 MaybeCopyDisableWebRtcEncryptionSwitch(command_line
,
1259 browser_command_line
,
1260 VersionInfo::GetChannel());
1264 PrefService
* prefs
= profile
->GetPrefs();
1265 // Currently this pref is only registered if applied via a policy.
1266 if (prefs
->HasPrefPath(prefs::kDisable3DAPIs
) &&
1267 prefs
->GetBoolean(prefs::kDisable3DAPIs
)) {
1268 // Turn this policy into a command line switch.
1269 command_line
->AppendSwitch(switches::kDisable3DAPIs
);
1272 const base::ListValue
* switches
=
1273 prefs
->GetList(prefs::kEnableDeprecatedWebPlatformFeatures
);
1275 // Enable any deprecated features that have been re-enabled by policy.
1276 for (base::ListValue::const_iterator it
= switches
->begin();
1277 it
!= switches
->end(); ++it
) {
1278 std::string switch_to_enable
;
1279 if ((*it
)->GetAsString(&switch_to_enable
))
1280 command_line
->AppendSwitch(switch_to_enable
);
1284 // Disable client-side phishing detection in the renderer if it is
1285 // disabled in the Profile preferences or the browser process.
1286 if (!prefs
->GetBoolean(prefs::kSafeBrowsingEnabled
) ||
1287 !g_browser_process
->safe_browsing_detection_service()) {
1288 command_line
->AppendSwitch(
1289 switches::kDisableClientSidePhishingDetection
);
1292 if (prefs
->GetBoolean(prefs::kPrintPreviewDisabled
))
1293 command_line
->AppendSwitch(switches::kDisablePrintPreview
);
1295 InstantService
* instant_service
=
1296 InstantServiceFactory::GetForProfile(profile
);
1297 if (instant_service
&&
1298 instant_service
->IsInstantProcess(process
->GetID()))
1299 command_line
->AppendSwitch(switches::kInstantProcess
);
1301 #if !defined(OS_CHROMEOS)
1302 SigninClient
* signin_client
=
1303 ChromeSigninClientFactory::GetForProfile(profile
);
1304 if (signin_client
&& signin_client
->IsSigninProcess(process
->GetID()))
1305 command_line
->AppendSwitch(switches::kSigninProcess
);
1309 if (IsAutoReloadEnabled())
1310 command_line
->AppendSwitch(switches::kEnableOfflineAutoReload
);
1311 if (IsAutoReloadVisibleOnlyEnabled()) {
1312 command_line
->AppendSwitch(
1313 switches::kEnableOfflineAutoReloadVisibleOnly
);
1317 // Enable load stale cache if this session is in the field trial or
1318 // the user explicitly enabled it. Note that as far as the renderer
1319 // is concerned, the feature is enabled if-and-only-if the
1320 // kEnableOfflineLoadStaleCache flag is on the command line;
1321 // the yes/no/default behavior is only at the browser command line
1324 // Command line switches override
1325 if (browser_command_line
.HasSwitch(
1326 switches::kEnableOfflineLoadStaleCache
)) {
1327 command_line
->AppendSwitch(switches::kEnableOfflineLoadStaleCache
);
1328 } else if (!browser_command_line
.HasSwitch(
1329 switches::kDisableOfflineLoadStaleCache
)) {
1331 base::FieldTrialList::FindFullName("LoadStaleCacheExperiment");
1333 if (group
== "Enabled")
1334 command_line
->AppendSwitch(switches::kEnableOfflineLoadStaleCache
);
1338 // Please keep this in alphabetical order.
1339 static const char* const kSwitchNames
[] = {
1340 autofill::switches::kDisableIgnoreAutocompleteOff
,
1341 autofill::switches::kDisablePasswordGeneration
,
1342 autofill::switches::kEnablePasswordGeneration
,
1343 autofill::switches::kIgnoreAutocompleteOffForAutofill
,
1344 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration
,
1345 #if defined(ENABLE_EXTENSIONS)
1346 extensions::switches::kAllowHTTPBackgroundPage
,
1347 extensions::switches::kAllowLegacyExtensionManifests
,
1348 extensions::switches::kEnableAppWindowControls
,
1349 extensions::switches::kEnableEmbeddedExtensionOptions
,
1350 extensions::switches::kEnableExperimentalExtensionApis
,
1351 extensions::switches::kEnableScriptsRequireAction
,
1352 extensions::switches::kExtensionsOnChromeURLs
,
1353 extensions::switches::kWhitelistedExtensionID
,
1355 switches::kAppsCheckoutURL
,
1356 switches::kAppsGalleryURL
,
1357 switches::kCloudPrintURL
,
1358 switches::kCloudPrintXmppEndpoint
,
1359 switches::kDisableBundledPpapiFlash
,
1360 switches::kEnableBenchmarking
,
1361 switches::kEnableNaCl
,
1362 #if !defined(DISABLE_NACL)
1363 switches::kEnableNaClDebug
,
1364 switches::kEnableNaClNonSfiMode
,
1366 switches::kEnableNetBenchmarking
,
1367 switches::kEnableShowModalDialog
,
1368 switches::kEnableStreamlinedHostedApps
,
1369 switches::kEnableWebBasedSignin
,
1370 switches::kJavaScriptHarmony
,
1371 switches::kMessageLoopHistogrammer
,
1372 switches::kOutOfProcessPdf
,
1373 switches::kPlaybackMode
,
1374 switches::kPpapiFlashArgs
,
1375 switches::kPpapiFlashPath
,
1376 switches::kPpapiFlashVersion
,
1377 switches::kProfilingAtStart
,
1378 switches::kProfilingFile
,
1379 switches::kProfilingFlush
,
1380 switches::kRecordMode
,
1381 translate::switches::kTranslateSecurityOrigin
,
1384 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1385 arraysize(kSwitchNames
));
1386 } else if (process_type
== switches::kUtilityProcess
) {
1387 #if defined(ENABLE_EXTENSIONS)
1388 static const char* const kSwitchNames
[] = {
1389 extensions::switches::kAllowHTTPBackgroundPage
,
1390 extensions::switches::kEnableExperimentalExtensionApis
,
1391 extensions::switches::kExtensionsOnChromeURLs
,
1392 extensions::switches::kWhitelistedExtensionID
,
1395 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1396 arraysize(kSwitchNames
));
1398 } else if (process_type
== switches::kPluginProcess
) {
1399 #if defined(OS_CHROMEOS)
1400 static const char* const kSwitchNames
[] = {
1401 chromeos::switches::kLoginProfile
,
1404 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1405 arraysize(kSwitchNames
));
1407 } else if (process_type
== switches::kZygoteProcess
) {
1408 static const char* const kSwitchNames
[] = {
1409 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
1410 switches::kDisableBundledPpapiFlash
,
1411 #if !defined(DISABLE_NACL)
1412 switches::kEnableNaClNonSfiMode
,
1413 switches::kNaClDangerousNoSandboxNonSfi
,
1415 switches::kPpapiFlashPath
,
1416 switches::kPpapiFlashVersion
,
1419 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1420 arraysize(kSwitchNames
));
1421 } else if (process_type
== switches::kGpuProcess
) {
1422 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1423 // because GPU is expected to be unreliable.
1424 if (browser_command_line
.HasSwitch(switches::kIgnoreGpuBlacklist
) &&
1425 !command_line
->HasSwitch(switches::kDisableBreakpad
))
1426 command_line
->AppendSwitch(switches::kDisableBreakpad
);
1429 // The command line switch kEnableBenchmarking needs to be specified along
1430 // with the kEnableStatsTable switch to ensure that the stats table global
1431 // is initialized correctly.
1432 if (command_line
->HasSwitch(switches::kEnableBenchmarking
))
1433 DCHECK(command_line
->HasSwitch(switches::kEnableStatsTable
));
1436 std::string
ChromeContentBrowserClient::GetApplicationLocale() {
1437 if (BrowserThread::CurrentlyOn(BrowserThread::IO
))
1438 return g_io_thread_application_locale
.Get();
1439 return g_browser_process
->GetApplicationLocale();
1442 std::string
ChromeContentBrowserClient::GetAcceptLangs(
1443 content::BrowserContext
* context
) {
1444 Profile
* profile
= Profile::FromBrowserContext(context
);
1445 return profile
->GetPrefs()->GetString(prefs::kAcceptLanguages
);
1448 const gfx::ImageSkia
* ChromeContentBrowserClient::GetDefaultFavicon() {
1449 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
1450 return rb
.GetNativeImageNamed(IDR_DEFAULT_FAVICON
).ToImageSkia();
1453 bool ChromeContentBrowserClient::AllowAppCache(
1454 const GURL
& manifest_url
,
1455 const GURL
& first_party
,
1456 content::ResourceContext
* context
) {
1457 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1458 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1459 return io_data
->GetCookieSettings()->
1460 IsSettingCookieAllowed(manifest_url
, first_party
);
1463 bool ChromeContentBrowserClient::AllowServiceWorker(
1465 const GURL
& first_party_url
,
1466 content::ResourceContext
* context
) {
1467 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1468 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1469 return io_data
->GetCookieSettings()->
1470 IsSettingCookieAllowed(scope
, first_party_url
);
1473 bool ChromeContentBrowserClient::AllowGetCookie(
1475 const GURL
& first_party
,
1476 const net::CookieList
& cookie_list
,
1477 content::ResourceContext
* context
,
1478 int render_process_id
,
1479 int render_frame_id
) {
1480 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1481 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1482 bool allow
= io_data
->GetCookieSettings()->
1483 IsReadingCookieAllowed(url
, first_party
);
1485 BrowserThread::PostTask(
1486 BrowserThread::UI
, FROM_HERE
,
1487 base::Bind(&TabSpecificContentSettings::CookiesRead
, render_process_id
,
1488 render_frame_id
, url
, first_party
, cookie_list
, !allow
, true));
1492 bool ChromeContentBrowserClient::AllowSetCookie(
1494 const GURL
& first_party
,
1495 const std::string
& cookie_line
,
1496 content::ResourceContext
* context
,
1497 int render_process_id
,
1498 int render_frame_id
,
1499 net::CookieOptions
* options
) {
1500 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1501 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1502 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1503 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, first_party
);
1505 if (prerender_tracker_
) {
1506 prerender_tracker_
->OnCookieChangedForURL(
1508 context
->GetRequestContext()->cookie_store()->GetCookieMonster(),
1512 BrowserThread::PostTask(
1513 BrowserThread::UI
, FROM_HERE
,
1514 base::Bind(&TabSpecificContentSettings::CookieChanged
, render_process_id
,
1515 render_frame_id
, url
, first_party
, cookie_line
, *options
,
1520 bool ChromeContentBrowserClient::AllowSaveLocalState(
1521 content::ResourceContext
* context
) {
1522 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1523 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1524 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1525 ContentSetting setting
= cookie_settings
->GetDefaultCookieSetting(NULL
);
1527 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1528 // Could we even support per-origin settings?
1529 return setting
!= CONTENT_SETTING_SESSION_ONLY
;
1532 bool ChromeContentBrowserClient::AllowWorkerDatabase(
1534 const base::string16
& name
,
1535 const base::string16
& display_name
,
1536 unsigned long estimated_size
,
1537 content::ResourceContext
* context
,
1538 const std::vector
<std::pair
<int, int> >& render_frames
) {
1539 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1540 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1541 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1542 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1544 // Record access to database for potential display in UI.
1545 std::vector
<std::pair
<int, int> >::const_iterator i
;
1546 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1547 BrowserThread::PostTask(
1548 BrowserThread::UI
, FROM_HERE
,
1549 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed
,
1550 i
->first
, i
->second
, url
, name
, display_name
, !allow
));
1556 void ChromeContentBrowserClient::AllowWorkerFileSystem(
1558 content::ResourceContext
* context
,
1559 const std::vector
<std::pair
<int, int> >& render_frames
,
1560 base::Callback
<void(bool)> callback
) {
1561 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1562 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1563 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1564 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1566 #if defined(ENABLE_EXTENSIONS)
1567 GuestPermissionRequestHelper(url
, render_frames
, callback
, allow
);
1569 FileSystemAccessed(url
, render_frames
, callback
, allow
);
1573 #if defined(ENABLE_EXTENSIONS)
1574 void ChromeContentBrowserClient::GuestPermissionRequestHelper(
1576 const std::vector
<std::pair
<int, int> >& render_frames
,
1577 base::Callback
<void(bool)> callback
,
1579 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::IO
));
1580 std::vector
<std::pair
<int, int> >::const_iterator i
;
1581 std::map
<int, int> process_map
;
1582 std::map
<int, int>::const_iterator it
;
1583 bool has_web_view_guest
= false;
1584 // Record access to file system for potential display in UI.
1585 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1586 if (process_map
.find(i
->first
) != process_map
.end())
1589 process_map
.insert(std::pair
<int, int>(i
->first
, i
->second
));
1591 if (extensions::WebViewRendererState::GetInstance()->IsGuest(i
->first
))
1592 has_web_view_guest
= true;
1594 if (!has_web_view_guest
) {
1595 FileSystemAccessed(url
, render_frames
, callback
, allow
);
1598 DCHECK_EQ(1U, process_map
.size());
1599 it
= process_map
.begin();
1600 BrowserThread::PostTask(
1603 base::Bind(&ChromeContentBrowserClient::
1604 RequestFileSystemPermissionOnUIThread
,
1609 base::Bind(&ChromeContentBrowserClient::FileSystemAccessed
,
1610 weak_factory_
.GetWeakPtr(),
1616 void ChromeContentBrowserClient::RequestFileSystemPermissionOnUIThread(
1617 int render_process_id
,
1618 int render_frame_id
,
1620 bool allowed_by_default
,
1621 const base::Callback
<void(bool)>& callback
) {
1622 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::UI
));
1623 extensions::WebViewPermissionHelper
* web_view_permission_helper
=
1624 extensions::WebViewPermissionHelper::FromFrameID(
1625 render_process_id
, render_frame_id
);
1626 web_view_permission_helper
->RequestFileSystemPermission(url
,
1632 void ChromeContentBrowserClient::FileSystemAccessed(
1634 const std::vector
<std::pair
<int, int> >& render_frames
,
1635 base::Callback
<void(bool)> callback
,
1637 // Record access to file system for potential display in UI.
1638 std::vector
<std::pair
<int, int> >::const_iterator i
;
1639 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1640 BrowserThread::PostTask(
1643 base::Bind(&TabSpecificContentSettings::FileSystemAccessed
,
1644 i
->first
, i
->second
, url
, !allow
));
1646 callback
.Run(allow
);
1649 bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1651 const base::string16
& name
,
1652 content::ResourceContext
* context
,
1653 const std::vector
<std::pair
<int, int> >& render_frames
) {
1654 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1655 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1656 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1657 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1659 // Record access to IndexedDB for potential display in UI.
1660 std::vector
<std::pair
<int, int> >::const_iterator i
;
1661 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1662 BrowserThread::PostTask(
1663 BrowserThread::UI
, FROM_HERE
,
1664 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed
,
1665 i
->first
, i
->second
, url
, name
, !allow
));
1671 net::URLRequestContext
*
1672 ChromeContentBrowserClient::OverrideRequestContextForURL(
1673 const GURL
& url
, content::ResourceContext
* context
) {
1674 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1675 #if defined(ENABLE_EXTENSIONS)
1676 if (url
.SchemeIs(extensions::kExtensionScheme
)) {
1677 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1678 return io_data
->extensions_request_context();
1685 QuotaPermissionContext
*
1686 ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1687 return new ChromeQuotaPermissionContext();
1690 void ChromeContentBrowserClient::AllowCertificateError(
1691 int render_process_id
,
1692 int render_frame_id
,
1694 const net::SSLInfo
& ssl_info
,
1695 const GURL
& request_url
,
1696 ResourceType resource_type
,
1698 bool strict_enforcement
,
1699 bool expired_previous_decision
,
1700 const base::Callback
<void(bool)>& callback
,
1701 content::CertificateRequestResultType
* result
) {
1702 if (resource_type
!= content::RESOURCE_TYPE_MAIN_FRAME
) {
1703 // A sub-resource has a certificate error. The user doesn't really
1704 // have a context for making the right decision, so block the
1705 // request hard, without an info bar to allow showing the insecure
1707 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY
;
1711 // If the tab is being prerendered, cancel the prerender and the request.
1712 content::RenderFrameHost
* render_frame_host
=
1713 content::RenderFrameHost::FromID(render_process_id
, render_frame_id
);
1714 WebContents
* tab
= WebContents::FromRenderFrameHost(render_frame_host
);
1720 prerender::PrerenderContents
* prerender_contents
=
1721 prerender::PrerenderContents::FromWebContents(tab
);
1722 if (prerender_contents
) {
1723 prerender_contents
->Destroy(prerender::FINAL_STATUS_SSL_ERROR
);
1724 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL
;
1728 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
1729 CaptivePortalTabHelper
* captive_portal_tab_helper
=
1730 CaptivePortalTabHelper::FromWebContents(tab
);
1731 if (captive_portal_tab_helper
)
1732 captive_portal_tab_helper
->OnSSLCertError(ssl_info
);
1735 // Otherwise, display an SSL blocking page. The interstitial page takes
1736 // ownership of ssl_blocking_page.
1737 int options_mask
= 0;
1739 options_mask
|= SSLBlockingPage::OVERRIDABLE
;
1740 if (strict_enforcement
)
1741 options_mask
|= SSLBlockingPage::STRICT_ENFORCEMENT
;
1742 if (expired_previous_decision
)
1743 options_mask
|= SSLBlockingPage::EXPIRED_BUT_PREVIOUSLY_ALLOWED
;
1744 SSLBlockingPage
* ssl_blocking_page
= new SSLBlockingPage(
1745 tab
, cert_error
, ssl_info
, request_url
, options_mask
, callback
);
1746 ssl_blocking_page
->Show();
1749 void ChromeContentBrowserClient::SelectClientCertificate(
1750 int render_process_id
,
1751 int render_frame_id
,
1752 net::SSLCertRequestInfo
* cert_request_info
,
1753 const base::Callback
<void(net::X509Certificate
*)>& callback
) {
1754 content::RenderFrameHost
* rfh
= content::RenderFrameHost::FromID(
1755 render_process_id
, render_frame_id
);
1756 WebContents
* tab
= WebContents::FromRenderFrameHost(rfh
);
1758 // TODO(davidben): This makes the request hang, but returning no certificate
1759 // also breaks. It should abort the request. See https://crbug.com/417092
1763 prerender::PrerenderContents
* prerender_contents
=
1764 prerender::PrerenderContents::FromWebContents(tab
);
1765 if (prerender_contents
) {
1766 prerender_contents
->Destroy(
1767 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED
);
1771 GURL
requesting_url("https://" + cert_request_info
->host_and_port
.ToString());
1772 DCHECK(requesting_url
.is_valid())
1773 << "Invalid URL string: https://"
1774 << cert_request_info
->host_and_port
.ToString();
1776 Profile
* profile
= Profile::FromBrowserContext(tab
->GetBrowserContext());
1777 scoped_ptr
<base::Value
> filter
=
1778 profile
->GetHostContentSettingsMap()->GetWebsiteSetting(
1781 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE
,
1786 // Try to automatically select a client certificate.
1787 if (filter
->IsType(base::Value::TYPE_DICTIONARY
)) {
1788 base::DictionaryValue
* filter_dict
=
1789 static_cast<base::DictionaryValue
*>(filter
.get());
1791 const std::vector
<scoped_refptr
<net::X509Certificate
> >&
1792 all_client_certs
= cert_request_info
->client_certs
;
1793 for (size_t i
= 0; i
< all_client_certs
.size(); ++i
) {
1794 if (CertMatchesFilter(*all_client_certs
[i
].get(), *filter_dict
)) {
1795 // Use the first certificate that is matched by the filter.
1796 callback
.Run(all_client_certs
[i
].get());
1805 chrome::ShowSSLClientCertificateSelector(tab
, cert_request_info
, callback
);
1808 void ChromeContentBrowserClient::AddCertificate(
1809 net::CertificateMimeType cert_type
,
1810 const void* cert_data
,
1812 int render_process_id
,
1813 int render_frame_id
) {
1814 chrome::SSLAddCertificate(cert_type
, cert_data
, cert_size
,
1815 render_process_id
, render_frame_id
);
1818 content::MediaObserver
* ChromeContentBrowserClient::GetMediaObserver() {
1819 return MediaCaptureDevicesDispatcher::GetInstance();
1822 void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1823 const GURL
& source_origin
,
1824 content::RenderFrameHost
* render_frame_host
,
1825 const base::Callback
<void(blink::WebNotificationPermission
)>& callback
) {
1826 #if defined(ENABLE_NOTIFICATIONS)
1827 // Skip showing the infobar if the request comes from an extension, and that
1828 // extension has the 'notify' permission. (If the extension does not have the
1829 // permission, the user will still be prompted.)
1830 Profile
* profile
= Profile::FromBrowserContext(
1831 render_frame_host
->GetSiteInstance()->GetBrowserContext());
1832 DesktopNotificationService
* notification_service
=
1833 DesktopNotificationServiceFactory::GetForProfile(profile
);
1834 WebContents
* web_contents
= WebContents::FromRenderFrameHost(
1836 int render_process_id
= render_frame_host
->GetProcess()->GetID();
1837 const PermissionRequestID
request_id(render_process_id
,
1838 web_contents
->GetRoutingID(),
1842 notification_service
->RequestNotificationPermission(
1846 // TODO(peter): plumb user_gesture over IPC
1855 blink::WebNotificationPermission
1856 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
1857 const GURL
& source_origin
,
1858 content::ResourceContext
* context
,
1859 int render_process_id
) {
1860 #if defined(ENABLE_NOTIFICATIONS)
1861 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1863 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1864 #if defined(ENABLE_EXTENSIONS)
1865 InfoMap
* extension_info_map
= io_data
->GetExtensionInfoMap();
1867 // We want to see if there is an extension that hasn't been manually disabled
1868 // that has the notifications permission and applies to this security origin.
1869 // First, get the list of extensions with permission for the origin.
1870 extensions::ExtensionSet extensions
;
1871 extension_info_map
->GetExtensionsWithAPIPermissionForSecurityOrigin(
1874 extensions::APIPermission::kNotifications
,
1876 for (extensions::ExtensionSet::const_iterator iter
= extensions
.begin();
1877 iter
!= extensions
.end(); ++iter
) {
1878 // Then, check to see if it's been disabled by the user.
1879 if (!extension_info_map
->AreNotificationsDisabled((*iter
)->id()))
1880 return blink::WebNotificationPermissionAllowed
;
1884 // No enabled extensions exist, so check the normal host content settings.
1885 HostContentSettingsMap
* host_content_settings_map
=
1886 io_data
->GetHostContentSettingsMap();
1887 ContentSetting setting
= host_content_settings_map
->GetContentSetting(
1890 CONTENT_SETTINGS_TYPE_NOTIFICATIONS
,
1891 NO_RESOURCE_IDENTIFIER
);
1893 if (setting
== CONTENT_SETTING_ALLOW
)
1894 return blink::WebNotificationPermissionAllowed
;
1895 if (setting
== CONTENT_SETTING_BLOCK
)
1896 return blink::WebNotificationPermissionDenied
;
1897 return blink::WebNotificationPermissionDefault
;
1899 return blink::WebNotificationPermissionAllowed
;
1903 void ChromeContentBrowserClient::ShowDesktopNotification(
1904 const content::ShowDesktopNotificationHostMsgParams
& params
,
1905 RenderFrameHost
* render_frame_host
,
1906 scoped_ptr
<content::DesktopNotificationDelegate
> delegate
,
1907 base::Closure
* cancel_callback
) {
1908 #if defined(ENABLE_NOTIFICATIONS)
1909 content::RenderProcessHost
* process
= render_frame_host
->GetProcess();
1910 Profile
* profile
= Profile::FromBrowserContext(process
->GetBrowserContext());
1911 DesktopNotificationService
* service
=
1912 DesktopNotificationServiceFactory::GetForProfile(profile
);
1913 service
->ShowDesktopNotification(
1914 params
, render_frame_host
, delegate
.Pass(), cancel_callback
);
1916 profile
->GetHostContentSettingsMap()->UpdateLastUsage(
1917 params
.origin
, params
.origin
, CONTENT_SETTINGS_TYPE_NOTIFICATIONS
);
1923 void ChromeContentBrowserClient::RequestGeolocationPermission(
1924 content::WebContents
* web_contents
,
1926 const GURL
& requesting_frame
,
1928 const base::Callback
<void(bool)>& result_callback
) {
1929 int render_process_id
= web_contents
->GetRenderProcessHost()->GetID();
1930 int render_view_id
= web_contents
->GetRenderViewHost()->GetRoutingID();
1932 const PermissionRequestID
request_id(render_process_id
,
1936 GeolocationPermissionContextFactory::GetForProfile(
1937 Profile::FromBrowserContext(web_contents
->GetBrowserContext()))->
1938 RequestPermission(web_contents
, request_id
,
1939 requesting_frame
.GetOrigin(), user_gesture
,
1943 void ChromeContentBrowserClient::CancelGeolocationPermissionRequest(
1944 content::WebContents
* web_contents
,
1946 const GURL
& requesting_frame
) {
1947 int render_process_id
= web_contents
->GetRenderProcessHost()->GetID();
1948 int render_view_id
= web_contents
->GetRenderViewHost()->GetRoutingID();
1950 const PermissionRequestID
request_id(render_process_id
,
1954 GeolocationPermissionContextFactory::GetForProfile(
1955 Profile::FromBrowserContext(web_contents
->GetBrowserContext()))->
1956 CancelPermissionRequest(web_contents
, request_id
);
1959 void ChromeContentBrowserClient::RequestMidiSysExPermission(
1960 content::WebContents
* web_contents
,
1962 const GURL
& requesting_frame
,
1964 base::Callback
<void(bool)> result_callback
,
1965 base::Closure
* cancel_callback
) {
1966 MidiPermissionContext
* context
=
1967 MidiPermissionContextFactory::GetForProfile(
1968 Profile::FromBrowserContext(web_contents
->GetBrowserContext()));
1969 int renderer_id
= web_contents
->GetRenderProcessHost()->GetID();
1970 int render_view_id
= web_contents
->GetRenderViewHost()->GetRoutingID();
1971 const PermissionRequestID
id(renderer_id
, render_view_id
, bridge_id
, GURL());
1973 context
->RequestPermission(web_contents
, id
, requesting_frame
,
1974 user_gesture
, result_callback
);
1977 void ChromeContentBrowserClient::DidUseGeolocationPermission(
1978 content::WebContents
* web_contents
,
1979 const GURL
& frame_url
,
1980 const GURL
& main_frame_url
) {
1981 Profile::FromBrowserContext(web_contents
->GetBrowserContext())
1982 ->GetHostContentSettingsMap()
1984 frame_url
, main_frame_url
, CONTENT_SETTINGS_TYPE_GEOLOCATION
);
1987 void ChromeContentBrowserClient::RequestProtectedMediaIdentifierPermission(
1988 content::WebContents
* web_contents
,
1990 base::Callback
<void(bool)> result_callback
,
1991 base::Closure
* cancel_callback
) {
1992 #if defined(OS_ANDROID)
1993 ProtectedMediaIdentifierPermissionContext
* context
=
1994 ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(
1995 Profile::FromBrowserContext(web_contents
->GetBrowserContext()));
1996 context
->RequestProtectedMediaIdentifierPermission(web_contents
,
2002 result_callback
.Run(false);
2003 #endif // defined(OS_ANDROID)
2006 bool ChromeContentBrowserClient::CanCreateWindow(
2007 const GURL
& opener_url
,
2008 const GURL
& opener_top_level_frame_url
,
2009 const GURL
& source_origin
,
2010 WindowContainerType container_type
,
2011 const GURL
& target_url
,
2012 const content::Referrer
& referrer
,
2013 WindowOpenDisposition disposition
,
2014 const WebWindowFeatures
& features
,
2016 bool opener_suppressed
,
2017 content::ResourceContext
* context
,
2018 int render_process_id
,
2020 bool* no_javascript_access
) {
2021 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
2023 *no_javascript_access
= false;
2025 // If the opener is trying to create a background window but doesn't have
2026 // the appropriate permission, fail the attempt.
2027 if (container_type
== WINDOW_CONTAINER_TYPE_BACKGROUND
) {
2028 #if defined(ENABLE_EXTENSIONS)
2029 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
2030 InfoMap
* map
= io_data
->GetExtensionInfoMap();
2031 if (!map
->SecurityOriginHasAPIPermission(
2034 APIPermission::kBackground
)) {
2038 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2039 // return a recently installed Extension even if this CanCreateWindow call
2040 // was made by an old copy of the page in a normal web process. That's ok,
2041 // because the permission check above would have caused an early return
2042 // already. We must use the full URL to find hosted apps, though, and not
2044 const Extension
* extension
=
2045 map
->extensions().GetExtensionOrAppByURL(opener_url
);
2046 if (extension
&& !extensions::BackgroundInfo::AllowJSAccess(extension
))
2047 *no_javascript_access
= true;
2053 #if defined(ENABLE_EXTENSIONS)
2054 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
2059 HostContentSettingsMap
* content_settings
=
2060 ProfileIOData::FromResourceContext(context
)->GetHostContentSettingsMap();
2061 BlockedWindowParams
blocked_params(target_url
,
2070 if (!user_gesture
&& !CommandLine::ForCurrentProcess()->HasSwitch(
2071 switches::kDisablePopupBlocking
)) {
2072 if (content_settings
->GetContentSetting(opener_top_level_frame_url
,
2073 opener_top_level_frame_url
,
2074 CONTENT_SETTINGS_TYPE_POPUPS
,
2076 CONTENT_SETTING_ALLOW
) {
2077 BrowserThread::PostTask(BrowserThread::UI
,
2079 base::Bind(&HandleBlockedPopupOnUIThread
,
2085 #if defined(OS_ANDROID)
2086 if (SingleTabModeTabHelper::IsRegistered(render_process_id
, opener_id
)) {
2087 BrowserThread::PostTask(BrowserThread::UI
,
2089 base::Bind(&HandleSingleTabModeBlockOnUIThread
,
2098 void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2099 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
2100 prerender_tracker_
= g_browser_process
->prerender_tracker();
2101 return g_browser_process
->ResourceDispatcherHostCreated();
2104 // TODO(tommi): Rename from Get to Create.
2105 content::SpeechRecognitionManagerDelegate
*
2106 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
2107 return new speech::ChromeSpeechRecognitionManagerDelegate();
2110 net::NetLog
* ChromeContentBrowserClient::GetNetLog() {
2111 return g_browser_process
->net_log();
2114 AccessTokenStore
* ChromeContentBrowserClient::CreateAccessTokenStore() {
2115 return new ChromeAccessTokenStore();
2118 bool ChromeContentBrowserClient::IsFastShutdownPossible() {
2122 void ChromeContentBrowserClient::OverrideWebkitPrefs(
2123 RenderViewHost
* rvh
, const GURL
& url
, WebPreferences
* web_prefs
) {
2124 Profile
* profile
= Profile::FromBrowserContext(
2125 rvh
->GetProcess()->GetBrowserContext());
2126 PrefService
* prefs
= profile
->GetPrefs();
2128 // Fill per-script font preferences. These are not registered on Android
2129 // - http://crbug.com/308033.
2130 #if !defined(OS_ANDROID)
2131 FontFamilyCache::FillFontFamilyMap(profile
,
2132 prefs::kWebKitStandardFontFamilyMap
,
2133 &web_prefs
->standard_font_family_map
);
2134 FontFamilyCache::FillFontFamilyMap(profile
,
2135 prefs::kWebKitFixedFontFamilyMap
,
2136 &web_prefs
->fixed_font_family_map
);
2137 FontFamilyCache::FillFontFamilyMap(profile
,
2138 prefs::kWebKitSerifFontFamilyMap
,
2139 &web_prefs
->serif_font_family_map
);
2140 FontFamilyCache::FillFontFamilyMap(profile
,
2141 prefs::kWebKitSansSerifFontFamilyMap
,
2142 &web_prefs
->sans_serif_font_family_map
);
2143 FontFamilyCache::FillFontFamilyMap(profile
,
2144 prefs::kWebKitCursiveFontFamilyMap
,
2145 &web_prefs
->cursive_font_family_map
);
2146 FontFamilyCache::FillFontFamilyMap(profile
,
2147 prefs::kWebKitFantasyFontFamilyMap
,
2148 &web_prefs
->fantasy_font_family_map
);
2149 FontFamilyCache::FillFontFamilyMap(profile
,
2150 prefs::kWebKitPictographFontFamilyMap
,
2151 &web_prefs
->pictograph_font_family_map
);
2154 web_prefs
->default_font_size
=
2155 prefs
->GetInteger(prefs::kWebKitDefaultFontSize
);
2156 web_prefs
->default_fixed_font_size
=
2157 prefs
->GetInteger(prefs::kWebKitDefaultFixedFontSize
);
2158 web_prefs
->minimum_font_size
=
2159 prefs
->GetInteger(prefs::kWebKitMinimumFontSize
);
2160 web_prefs
->minimum_logical_font_size
=
2161 prefs
->GetInteger(prefs::kWebKitMinimumLogicalFontSize
);
2163 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2165 web_prefs
->javascript_can_open_windows_automatically
=
2166 prefs
->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically
);
2167 web_prefs
->dom_paste_enabled
=
2168 prefs
->GetBoolean(prefs::kWebKitDomPasteEnabled
);
2169 web_prefs
->shrinks_standalone_images_to_fit
=
2170 prefs
->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit
);
2171 web_prefs
->tabs_to_links
= prefs
->GetBoolean(prefs::kWebkitTabsToLinks
);
2173 if (!prefs
->GetBoolean(prefs::kWebKitJavascriptEnabled
))
2174 web_prefs
->javascript_enabled
= false;
2175 if (!prefs
->GetBoolean(prefs::kWebKitWebSecurityEnabled
))
2176 web_prefs
->web_security_enabled
= false;
2177 if (!prefs
->GetBoolean(prefs::kWebKitPluginsEnabled
))
2178 web_prefs
->plugins_enabled
= false;
2179 if (!prefs
->GetBoolean(prefs::kWebKitJavaEnabled
))
2180 web_prefs
->java_enabled
= false;
2181 web_prefs
->loads_images_automatically
=
2182 prefs
->GetBoolean(prefs::kWebKitLoadsImagesAutomatically
);
2184 if (prefs
->GetBoolean(prefs::kDisable3DAPIs
))
2185 web_prefs
->experimental_webgl_enabled
= false;
2187 web_prefs
->allow_displaying_insecure_content
=
2188 prefs
->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent
);
2189 web_prefs
->allow_running_insecure_content
=
2190 prefs
->GetBoolean(prefs::kWebKitAllowRunningInsecureContent
);
2191 #if defined(OS_ANDROID)
2192 web_prefs
->font_scale_factor
=
2193 static_cast<float>(prefs
->GetDouble(prefs::kWebKitFontScaleFactor
));
2194 web_prefs
->device_scale_adjustment
= GetDeviceScaleAdjustment();
2195 web_prefs
->force_enable_zoom
=
2196 prefs
->GetBoolean(prefs::kWebKitForceEnableZoom
);
2199 #if defined(OS_ANDROID)
2200 web_prefs
->password_echo_enabled
=
2201 prefs
->GetBoolean(prefs::kWebKitPasswordEchoEnabled
);
2203 web_prefs
->password_echo_enabled
= browser_defaults::kPasswordEchoEnabled
;
2206 web_prefs
->asynchronous_spell_checking_enabled
= true;
2207 web_prefs
->unified_textchecker_enabled
= true;
2209 web_prefs
->uses_universal_detector
=
2210 prefs
->GetBoolean(prefs::kWebKitUsesUniversalDetector
);
2211 web_prefs
->text_areas_are_resizable
=
2212 prefs
->GetBoolean(prefs::kWebKitTextAreasAreResizable
);
2213 web_prefs
->hyperlink_auditing_enabled
=
2214 prefs
->GetBoolean(prefs::kEnableHyperlinkAuditing
);
2216 // Make sure we will set the default_encoding with canonical encoding name.
2217 web_prefs
->default_encoding
=
2218 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
2219 web_prefs
->default_encoding
);
2220 if (web_prefs
->default_encoding
.empty()) {
2221 prefs
->ClearPref(prefs::kDefaultCharset
);
2222 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2224 DCHECK(!web_prefs
->default_encoding
.empty());
2226 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2227 extra_parts_
[i
]->OverrideWebkitPrefs(rvh
, url
, web_prefs
);
2230 void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2231 BrowserURLHandler
* handler
) {
2232 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2233 extra_parts_
[i
]->BrowserURLHandlerCreated(handler
);
2235 // about: handler. Must come before chrome: handler, since it will
2236 // rewrite about: urls to chrome: URLs and then expect chrome: to
2237 // actually handle them.
2238 handler
->AddHandlerPair(&WillHandleBrowserAboutURL
,
2239 BrowserURLHandler::null_handler());
2241 #if defined(OS_ANDROID)
2242 // Handler to rewrite chrome://newtab on Android.
2243 handler
->AddHandlerPair(&chrome::android::HandleAndroidNewTabURL
,
2244 BrowserURLHandler::null_handler());
2246 // Handler to rewrite chrome://newtab for InstantExtended.
2247 handler
->AddHandlerPair(&chrome::HandleNewTabURLRewrite
,
2248 &chrome::HandleNewTabURLReverseRewrite
);
2251 // chrome: & friends.
2252 handler
->AddHandlerPair(&HandleWebUI
, &HandleWebUIReverse
);
2255 void ChromeContentBrowserClient::ClearCache(RenderViewHost
* rvh
) {
2256 Profile
* profile
= Profile::FromBrowserContext(
2257 rvh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2258 BrowsingDataRemover
* remover
=
2259 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2260 remover
->Remove(BrowsingDataRemover::REMOVE_CACHE
,
2261 BrowsingDataHelper::UNPROTECTED_WEB
);
2262 // BrowsingDataRemover takes care of deleting itself when done.
2265 void ChromeContentBrowserClient::ClearCookies(RenderViewHost
* rvh
) {
2266 Profile
* profile
= Profile::FromBrowserContext(
2267 rvh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2268 BrowsingDataRemover
* remover
=
2269 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2270 int remove_mask
= BrowsingDataRemover::REMOVE_SITE_DATA
;
2271 remover
->Remove(remove_mask
, BrowsingDataHelper::UNPROTECTED_WEB
);
2272 // BrowsingDataRemover takes care of deleting itself when done.
2275 base::FilePath
ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
2276 return DownloadPrefs::GetDefaultDownloadDirectory();
2279 std::string
ChromeContentBrowserClient::GetDefaultDownloadName() {
2280 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME
);
2283 void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2284 content::BrowserPpapiHost
* browser_host
) {
2285 #if defined(ENABLE_PLUGINS)
2286 browser_host
->GetPpapiHost()->AddHostFactoryFilter(
2287 scoped_ptr
<ppapi::host::HostFactory
>(
2288 new ChromeBrowserPepperHostFactory(browser_host
)));
2292 content::BrowserPpapiHost
*
2293 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2294 int plugin_process_id
) {
2295 #if !defined(DISABLE_NACL)
2296 content::BrowserChildProcessHostIterator
iter(PROCESS_TYPE_NACL_LOADER
);
2297 while (!iter
.Done()) {
2298 nacl::NaClProcessHost
* host
= static_cast<nacl::NaClProcessHost
*>(
2299 iter
.GetDelegate());
2300 if (host
->process() &&
2301 host
->process()->GetData().id
== plugin_process_id
) {
2302 // Found the plugin.
2303 return host
->browser_ppapi_host();
2311 bool ChromeContentBrowserClient::AllowPepperSocketAPI(
2312 content::BrowserContext
* browser_context
,
2315 const content::SocketPermissionRequest
* params
) {
2316 #if defined(ENABLE_EXTENSIONS)
2317 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
2318 const extensions::ExtensionSet
* extension_set
= NULL
;
2320 const ExtensionService
* ext_service
=
2321 extensions::ExtensionSystem::Get(profile
)->extension_service();
2323 extension_set
= ext_service
->extensions();
2328 // Access to private socket APIs is controlled by the whitelist.
2329 if (IsExtensionOrSharedModuleWhitelisted(url
, extension_set
,
2330 allowed_socket_origins_
)) {
2334 // Access to public socket APIs is controlled by extension permissions.
2335 if (url
.is_valid() && url
.SchemeIs(extensions::kExtensionScheme
) &&
2337 const Extension
* extension
= extension_set
->GetByID(url
.host());
2339 const extensions::PermissionsData
* permissions_data
=
2340 extension
->permissions_data();
2342 extensions::SocketPermission::CheckParam
check_params(
2343 params
->type
, params
->host
, params
->port
);
2344 if (permissions_data
->CheckAPIPermissionWithParam(
2345 extensions::APIPermission::kSocket
, &check_params
)) {
2348 } else if (permissions_data
->HasAPIPermission(
2349 extensions::APIPermission::kSocket
)) {
2356 // Allow both public and private APIs if the command line says so.
2357 return IsHostAllowedByCommandLine(url
, extension_set
,
2358 switches::kAllowNaClSocketAPI
);
2364 ui::SelectFilePolicy
* ChromeContentBrowserClient::CreateSelectFilePolicy(
2365 WebContents
* web_contents
) {
2366 return new ChromeSelectFilePolicy(web_contents
);
2369 void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2370 std::vector
<std::string
>* additional_allowed_schemes
) {
2371 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2372 additional_allowed_schemes
);
2373 additional_allowed_schemes
->push_back(content::kChromeDevToolsScheme
);
2374 additional_allowed_schemes
->push_back(content::kChromeUIScheme
);
2375 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
2376 extra_parts_
[i
]->GetAdditionalAllowedSchemesForFileSystem(
2377 additional_allowed_schemes
);
2381 void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
2382 std::vector
<storage::URLRequestAutoMountHandler
>* handlers
) {
2383 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2384 extra_parts_
[i
]->GetURLRequestAutoMountHandlers(handlers
);
2387 void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
2388 content::BrowserContext
* browser_context
,
2389 const base::FilePath
& storage_partition_path
,
2390 ScopedVector
<storage::FileSystemBackend
>* additional_backends
) {
2391 #if defined(OS_CHROMEOS)
2392 storage::ExternalMountPoints
* external_mount_points
=
2393 content::BrowserContext::GetMountPoints(browser_context
);
2394 DCHECK(external_mount_points
);
2395 chromeos::FileSystemBackend
* backend
= new chromeos::FileSystemBackend(
2396 new drive::FileSystemBackendDelegate
,
2397 new chromeos::file_system_provider::BackendDelegate
,
2398 new chromeos::MTPFileSystemBackendDelegate(storage_partition_path
),
2399 browser_context
->GetSpecialStoragePolicy(),
2400 external_mount_points
,
2401 storage::ExternalMountPoints::GetSystemInstance());
2402 backend
->AddSystemMountPoints();
2403 DCHECK(backend
->CanHandleType(storage::kFileSystemTypeExternal
));
2404 additional_backends
->push_back(backend
);
2407 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
2408 extra_parts_
[i
]->GetAdditionalFileSystemBackends(
2409 browser_context
, storage_partition_path
, additional_backends
);
2413 #if defined(OS_POSIX) && !defined(OS_MACOSX)
2414 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2415 const CommandLine
& command_line
,
2416 int child_process_id
,
2417 FileDescriptorInfo
* mappings
) {
2418 #if defined(OS_ANDROID)
2419 base::FilePath data_path
;
2420 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID
, &data_path
);
2421 DCHECK(!data_path
.empty());
2423 int flags
= base::File::FLAG_OPEN
| base::File::FLAG_READ
;
2424 base::FilePath chrome_resources_pak
=
2425 data_path
.AppendASCII("chrome_100_percent.pak");
2426 base::File
file(chrome_resources_pak
, flags
);
2427 DCHECK(file
.IsValid());
2428 mappings
->Transfer(kAndroidChrome100PercentPakDescriptor
,
2429 base::ScopedFD(file
.TakePlatformFile()));
2431 const std::string locale
= GetApplicationLocale();
2432 base::FilePath locale_pak
= ResourceBundle::GetSharedInstance().
2433 GetLocaleFilePath(locale
, false);
2434 file
.Initialize(locale_pak
, flags
);
2435 DCHECK(file
.IsValid());
2436 mappings
->Transfer(kAndroidLocalePakDescriptor
,
2437 base::ScopedFD(file
.TakePlatformFile()));
2439 base::FilePath resources_pack_path
;
2440 PathService::Get(chrome::FILE_RESOURCES_PACK
, &resources_pack_path
);
2441 file
.Initialize(resources_pack_path
, flags
);
2442 DCHECK(file
.IsValid());
2443 mappings
->Transfer(kAndroidUIResourcesPakDescriptor
,
2444 base::ScopedFD(file
.TakePlatformFile()));
2446 if (breakpad::IsCrashReporterEnabled()) {
2447 file
= breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile(
2449 if (file
.IsValid()) {
2450 mappings
->Transfer(kAndroidMinidumpDescriptor
,
2451 base::ScopedFD(file
.TakePlatformFile()));
2453 LOG(ERROR
) << "Failed to create file for minidump, crash reporting will "
2454 "be disabled for this process.";
2458 base::FilePath app_data_path
;
2459 PathService::Get(base::DIR_ANDROID_APP_DATA
, &app_data_path
);
2460 DCHECK(!app_data_path
.empty());
2462 flags
= base::File::FLAG_OPEN
| base::File::FLAG_READ
;
2463 base::FilePath icudata_path
=
2464 app_data_path
.AppendASCII("icudtl.dat");
2465 base::File
icudata_file(icudata_path
, flags
);
2466 DCHECK(icudata_file
.IsValid());
2467 mappings
->Transfer(kAndroidICUDataDescriptor
,
2468 base::ScopedFD(icudata_file
.TakePlatformFile()));
2471 int crash_signal_fd
= GetCrashSignalFD(command_line
);
2472 if (crash_signal_fd
>= 0) {
2473 mappings
->Share(kCrashDumpSignal
, crash_signal_fd
);
2475 #endif // defined(OS_ANDROID)
2477 #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
2480 const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2481 return chrome::kBrowserResourcesDll
;
2484 void ChromeContentBrowserClient::PreSpawnRenderer(
2485 sandbox::TargetPolicy
* policy
,
2487 // This code is duplicated in nacl_exe_win_64.cc.
2488 // Allow the server side of a pipe restricted to the "chrome.nacl."
2489 // namespace so that it cannot impersonate other system or other chrome
2491 sandbox::ResultCode result
= policy
->AddRule(
2492 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES
,
2493 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY
,
2494 L
"\\\\.\\pipe\\chrome.nacl.*");
2495 if (result
!= sandbox::SBOX_ALL_OK
) {
2500 // Renderers need to send named pipe handles and shared memory
2501 // segment handles to NaCl loader processes.
2502 result
= policy
->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES
,
2503 sandbox::TargetPolicy::HANDLES_DUP_ANY
,
2505 if (result
!= sandbox::SBOX_ALL_OK
) {
2512 bool ChromeContentBrowserClient::CheckMediaAccessPermission(
2513 content::BrowserContext
* browser_context
,
2514 const GURL
& security_origin
,
2515 content::MediaStreamType type
) {
2516 return MediaCaptureDevicesDispatcher::GetInstance()
2517 ->CheckMediaAccessPermission(
2518 browser_context
, security_origin
, type
);
2521 content::DevToolsManagerDelegate
*
2522 ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
2523 #if defined(OS_ANDROID)
2524 return new DevToolsManagerDelegateAndroid();
2526 return new ChromeDevToolsManagerDelegate();
2530 bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2531 content::BrowserContext
* browser_context
,
2533 #if defined(ENABLE_EXTENSIONS)
2534 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
2535 const extensions::ExtensionSet
* extension_set
= NULL
;
2537 const ExtensionService
* ext_service
=
2538 extensions::ExtensionSystem::Get(profile
)->extension_service();
2540 extension_set
= ext_service
->extensions();
2543 return IsExtensionOrSharedModuleWhitelisted(url
, extension_set
,
2544 allowed_file_handle_origins_
) ||
2545 IsHostAllowedByCommandLine(url
, extension_set
,
2546 switches::kAllowNaClFileHandleAPI
);
2552 bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
2553 content::BrowserContext
* browser_context
,
2555 #if defined(ENABLE_EXTENSIONS)
2556 // Allow access for tests.
2557 if (CommandLine::ForCurrentProcess()->HasSwitch(
2558 switches::kEnablePepperTesting
)) {
2562 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
2563 const extensions::ExtensionSet
* extension_set
= NULL
;
2565 const ExtensionService
* ext_service
=
2566 extensions::ExtensionSystem::Get(profile
)->extension_service();
2568 extension_set
= ext_service
->extensions();
2572 // Allow access for whitelisted applications.
2573 if (IsExtensionOrSharedModuleWhitelisted(url
,
2575 allowed_dev_channel_origins_
)) {
2579 chrome::VersionInfo::Channel channel
= chrome::VersionInfo::GetChannel();
2580 // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown"
2581 // releases of Chrome. Permitting "Unknown" allows these APIs to be used on
2582 // Chromium builds as well.
2583 return channel
<= chrome::VersionInfo::CHANNEL_DEV
;
2590 ChromeContentBrowserClient::OverrideCookieStoreForRenderProcess(
2591 int render_process_id
) {
2592 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
2593 if (!prerender_tracker_
)
2595 return prerender_tracker_
->GetPrerenderCookieStoreForRenderProcess(
2596 render_process_id
).get();
2599 #if defined(ENABLE_WEBRTC)
2600 void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
2601 CommandLine
* to_command_line
,
2602 const CommandLine
& from_command_line
,
2603 VersionInfo::Channel channel
) {
2604 #if defined(OS_ANDROID)
2605 const VersionInfo::Channel kMaxDisableEncryptionChannel
=
2606 VersionInfo::CHANNEL_BETA
;
2608 const VersionInfo::Channel kMaxDisableEncryptionChannel
=
2609 VersionInfo::CHANNEL_DEV
;
2611 if (channel
<= kMaxDisableEncryptionChannel
) {
2612 static const char* const kWebRtcDevSwitchNames
[] = {
2613 switches::kDisableWebRtcEncryption
,
2615 to_command_line
->CopySwitchesFrom(from_command_line
,
2616 kWebRtcDevSwitchNames
,
2617 arraysize(kWebRtcDevSwitchNames
));
2620 #endif // defined(ENABLE_WEBRTC)
2622 } // namespace chrome