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/lazy_instance.h"
14 #include "base/path_service.h"
15 #include "base/prefs/pref_service.h"
16 #include "base/prefs/scoped_user_pref_update.h"
17 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/utf_string_conversions.h"
19 #include "base/threading/sequenced_worker_pool.h"
20 #include "chrome/browser/browser_about_handler.h"
21 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/browser_shutdown.h"
23 #include "chrome/browser/browsing_data/browsing_data_helper.h"
24 #include "chrome/browser/browsing_data/browsing_data_remover.h"
25 #include "chrome/browser/character_encoding.h"
26 #include "chrome/browser/chrome_content_browser_client_parts.h"
27 #include "chrome/browser/chrome_net_benchmarking_message_filter.h"
28 #include "chrome/browser/chrome_quota_permission_context.h"
29 #include "chrome/browser/content_settings/content_settings_utils.h"
30 #include "chrome/browser/content_settings/cookie_settings.h"
31 #include "chrome/browser/content_settings/host_content_settings_map.h"
32 #include "chrome/browser/content_settings/permission_request_id.h"
33 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
34 #include "chrome/browser/defaults.h"
35 #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
36 #include "chrome/browser/download/download_prefs.h"
37 #include "chrome/browser/font_family_cache.h"
38 #include "chrome/browser/geolocation/chrome_access_token_store.h"
39 #include "chrome/browser/geolocation/geolocation_permission_context.h"
40 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h"
41 #include "chrome/browser/media/cast_transport_host_filter.h"
42 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
43 #include "chrome/browser/media/midi_permission_context.h"
44 #include "chrome/browser/media/midi_permission_context_factory.h"
45 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
46 #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
47 #include "chrome/browser/net/chrome_net_log.h"
48 #include "chrome/browser/notifications/desktop_notification_service.h"
49 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
50 #include "chrome/browser/platform_util.h"
51 #include "chrome/browser/plugins/plugin_info_message_filter.h"
52 #include "chrome/browser/prerender/prerender_final_status.h"
53 #include "chrome/browser/prerender/prerender_manager.h"
54 #include "chrome/browser/prerender/prerender_manager_factory.h"
55 #include "chrome/browser/prerender/prerender_message_filter.h"
56 #include "chrome/browser/prerender/prerender_tracker.h"
57 #include "chrome/browser/printing/printing_message_filter.h"
58 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
59 #include "chrome/browser/profiles/profile.h"
60 #include "chrome/browser/profiles/profile_io_data.h"
61 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
62 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
63 #include "chrome/browser/search/instant_service.h"
64 #include "chrome/browser/search/instant_service_factory.h"
65 #include "chrome/browser/search/search.h"
66 #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
67 #include "chrome/browser/signin/principals_message_filter.h"
68 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
69 #include "chrome/browser/speech/tts_controller.h"
70 #include "chrome/browser/speech/tts_message_filter.h"
71 #include "chrome/browser/ssl/ssl_add_certificate.h"
72 #include "chrome/browser/ssl/ssl_blocking_page.h"
73 #include "chrome/browser/ssl/ssl_client_certificate_selector.h"
74 #include "chrome/browser/tab_contents/tab_util.h"
75 #include "chrome/browser/ui/blocked_content/blocked_window_params.h"
76 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
77 #include "chrome/browser/ui/chrome_select_file_policy.h"
78 #include "chrome/browser/ui/sync/sync_promo_ui.h"
79 #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
80 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
81 #include "chrome/common/chrome_constants.h"
82 #include "chrome/common/chrome_paths.h"
83 #include "chrome/common/chrome_switches.h"
84 #include "chrome/common/env_vars.h"
85 #include "chrome/common/logging_chrome.h"
86 #include "chrome/common/pepper_permission_util.h"
87 #include "chrome/common/pref_names.h"
88 #include "chrome/common/render_messages.h"
89 #include "chrome/common/url_constants.h"
90 #include "chrome/grit/generated_resources.h"
91 #include "chrome/installer/util/google_update_settings.h"
92 #include "chromeos/chromeos_constants.h"
93 #include "components/cdm/browser/cdm_message_filter_android.h"
94 #include "components/cloud_devices/common/cloud_devices_switches.h"
95 #include "components/content_settings/core/browser/content_settings_provider.h"
96 #include "components/content_settings/core/common/content_settings.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_CHROMEOS)
178 #include "chrome/browser/signin/chrome_signin_client.h"
179 #include "chrome/browser/signin/chrome_signin_client_factory.h"
180 #include "chrome/browser/signin/signin_manager_factory.h"
181 #include "components/signin/core/browser/signin_manager.h"
184 #if defined(TOOLKIT_VIEWS)
185 #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
188 #if defined(USE_ATHENA)
189 #include "chrome/browser/ui/views/athena/chrome_browser_main_extra_parts_athena.h"
190 #elif defined(USE_ASH)
191 #include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
194 #if defined(USE_AURA)
195 #include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
199 #include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
202 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
203 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
206 #if !defined(DISABLE_NACL)
207 #include "components/nacl/browser/nacl_browser.h"
208 #include "components/nacl/browser/nacl_host_message_filter.h"
209 #include "components/nacl/browser/nacl_process_host.h"
210 #include "components/nacl/common/nacl_process_type.h"
211 #include "components/nacl/common/nacl_switches.h"
214 #if defined(ENABLE_EXTENSIONS)
215 #include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
216 #include "chrome/browser/extensions/extension_service.h"
217 #include "chrome/browser/extensions/extension_util.h"
218 #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
219 #include "extensions/browser/extension_system.h"
220 #include "extensions/browser/guest_view/guest_view_base.h"
221 #include "extensions/browser/guest_view/guest_view_manager.h"
222 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
223 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
224 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
225 #include "extensions/browser/suggest_permission_util.h"
226 #include "extensions/common/constants.h"
227 #include "extensions/common/extension.h"
228 #include "extensions/common/extension_set.h"
229 #include "extensions/common/manifest_handlers/background_info.h"
230 #include "extensions/common/manifest_handlers/shared_module_info.h"
231 #include "extensions/common/permissions/permissions_data.h"
232 #include "extensions/common/permissions/socket_permission.h"
233 #include "extensions/common/switches.h"
236 #if defined(ENABLE_SPELLCHECK)
237 #include "chrome/browser/spellchecker/spellcheck_message_filter.h"
240 #if defined(ENABLE_WEBRTC)
241 #include "chrome/browser/media/webrtc_logging_handler_host.h"
244 using base::FileDescriptor
;
245 using blink::WebWindowFeatures
;
246 using content::AccessTokenStore
;
247 using content::BrowserThread
;
248 using content::BrowserURLHandler
;
249 using content::ChildProcessSecurityPolicy
;
250 using content::QuotaPermissionContext
;
251 using content::RenderFrameHost
;
252 using content::RenderViewHost
;
253 using content::ResourceType
;
254 using content::SiteInstance
;
255 using content::WebContents
;
256 using content::WebPreferences
;
257 using message_center::NotifierId
;
259 #if defined(OS_POSIX)
260 using content::FileDescriptorInfo
;
263 #if defined(ENABLE_EXTENSIONS)
264 using extensions::APIPermission
;
265 using extensions::ChromeContentBrowserClientExtensionsPart
;
266 using extensions::Extension
;
267 using extensions::InfoMap
;
268 using extensions::Manifest
;
273 // Cached version of the locale so we can return the locale on the I/O
275 base::LazyInstance
<std::string
> g_io_thread_application_locale
;
277 #if defined(ENABLE_PLUGINS)
278 // TODO(teravest): Add renderer-side API-specific checking for these APIs so
279 // that blanket permission isn't granted to all dev channel APIs for these.
280 // http://crbug.com/386743
281 const char* const kPredefinedAllowedDevChannelOrigins
[] = {
282 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/383937
283 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/383937
286 const char* const kPredefinedAllowedFileHandleOrigins
[] = {
287 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
288 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
291 const char* const kPredefinedAllowedSocketOrigins
[] = {
292 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
293 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
294 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
295 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
296 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
297 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
298 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
299 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
300 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
301 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
302 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
303 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
304 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
305 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
306 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
307 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
308 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
309 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
310 "4EB74897CB187C7633357C2FE832E0AD6A44883A", // see crbug.com/234789
311 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
312 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
313 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
317 // Returns a copy of the given url with its host set to given host and path set
318 // to given path. Other parts of the url will be the same.
319 GURL
ReplaceURLHostAndPath(const GURL
& url
,
320 const std::string
& host
,
321 const std::string
& path
) {
322 url::Replacements
<char> replacements
;
323 replacements
.SetHost(host
.c_str(), url::Component(0, host
.length()));
324 replacements
.SetPath(path
.c_str(), url::Component(0, path
.length()));
325 return url
.ReplaceComponents(replacements
);
328 // Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
329 GURL
AddUberHost(const GURL
& url
) {
330 const std::string uber_host
= chrome::kChromeUIUberHost
;
331 const std::string new_path
= url
.host() + url
.path();
333 return ReplaceURLHostAndPath(url
, uber_host
, new_path
);
336 // If url->host() is "chrome" and url->path() has characters other than the
337 // first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
338 // returns true. Otherwise returns false.
339 bool RemoveUberHost(GURL
* url
) {
340 if (url
->host() != chrome::kChromeUIUberHost
)
343 if (url
->path().empty() || url
->path() == "/")
346 const std::string old_path
= url
->path();
348 const std::string::size_type separator
= old_path
.find('/', 1);
349 std::string new_host
;
350 std::string new_path
;
351 if (separator
== std::string::npos
) {
352 new_host
= old_path
.substr(1);
354 new_host
= old_path
.substr(1, separator
- 1);
355 new_path
= old_path
.substr(separator
);
358 // Do not allow URLs with paths empty before the first slash since we can't
359 // have an empty host. (e.g "foo://chrome//")
360 if (new_host
.empty())
363 *url
= ReplaceURLHostAndPath(*url
, new_host
, new_path
);
365 DCHECK(url
->is_valid());
370 // Handles rewriting Web UI URLs.
371 bool HandleWebUI(GURL
* url
, content::BrowserContext
* browser_context
) {
372 // Do not handle special URLs such as "about:foo"
373 if (!url
->host().empty()) {
374 const GURL chrome_url
= AddUberHost(*url
);
376 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
378 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
379 browser_context
, chrome_url
))
383 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
384 browser_context
, *url
))
387 #if defined(OS_CHROMEOS)
388 // Special case : in ChromeOS in Guest mode bookmarks and history are
389 // disabled for security reasons. New tab page explains the reasons, so
390 // we redirect user to new tab page.
391 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
392 if (url
->SchemeIs(content::kChromeUIScheme
) &&
393 (url
->DomainIs(chrome::kChromeUIBookmarksHost
) ||
394 url
->DomainIs(chrome::kChromeUIHistoryHost
))) {
395 // Rewrite with new tab URL
396 *url
= GURL(chrome::kChromeUINewTabURL
);
404 // Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
406 bool HandleWebUIReverse(GURL
* url
, content::BrowserContext
* browser_context
) {
407 if (!url
->is_valid() || !url
->SchemeIs(content::kChromeUIScheme
))
410 return RemoveUberHost(url
);
413 bool CertMatchesFilter(const net::X509Certificate
& cert
,
414 const base::DictionaryValue
& filter
) {
415 // TODO(markusheintz): This is the minimal required filter implementation.
416 // Implement a better matcher.
418 // An empty filter matches any client certificate since no requirements are
423 std::string common_name
;
424 if (filter
.GetString("ISSUER.CN", &common_name
) &&
425 (cert
.issuer().common_name
== common_name
)) {
431 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
432 breakpad::CrashHandlerHostLinux
* CreateCrashHandlerHost(
433 const std::string
& process_type
) {
434 base::FilePath dumps_path
;
435 PathService::Get(chrome::DIR_CRASH_DUMPS
, &dumps_path
);
437 ANNOTATE_SCOPED_MEMORY_LEAK
;
438 bool upload
= (getenv(env_vars::kHeadless
) == NULL
);
439 breakpad::CrashHandlerHostLinux
* crash_handler
=
440 new breakpad::CrashHandlerHostLinux(process_type
, dumps_path
, upload
);
441 crash_handler
->StartUploaderThread();
442 return crash_handler
;
446 int GetCrashSignalFD(const CommandLine
& command_line
) {
447 // Extensions have the same process type as renderers.
448 if (command_line
.HasSwitch(extensions::switches::kExtensionProcess
)) {
449 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
451 crash_handler
= CreateCrashHandlerHost("extension");
452 return crash_handler
->GetDeathSignalSocket();
455 std::string process_type
=
456 command_line
.GetSwitchValueASCII(switches::kProcessType
);
458 if (process_type
== switches::kRendererProcess
) {
459 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
461 crash_handler
= CreateCrashHandlerHost(process_type
);
462 return crash_handler
->GetDeathSignalSocket();
465 if (process_type
== switches::kPluginProcess
) {
466 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
468 crash_handler
= CreateCrashHandlerHost(process_type
);
469 return crash_handler
->GetDeathSignalSocket();
472 if (process_type
== switches::kPpapiPluginProcess
) {
473 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
475 crash_handler
= CreateCrashHandlerHost(process_type
);
476 return crash_handler
->GetDeathSignalSocket();
479 if (process_type
== switches::kGpuProcess
) {
480 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
482 crash_handler
= CreateCrashHandlerHost(process_type
);
483 return crash_handler
->GetDeathSignalSocket();
488 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
490 #if !defined(OS_CHROMEOS)
491 GURL
GetEffectiveURLForSignin(const GURL
& url
) {
492 CHECK(SigninManager::IsWebBasedSigninFlowURL(url
));
494 GURL
effective_url(SigninManager::kChromeSigninEffectiveSite
);
495 // Copy the path because the argument to SetPathStr must outlive
496 // the Replacements object.
497 const std::string
path_copy(url
.path());
498 GURL::Replacements replacements
;
499 replacements
.SetPathStr(path_copy
);
500 effective_url
= effective_url
.ReplaceComponents(replacements
);
501 return effective_url
;
505 void SetApplicationLocaleOnIOThread(const std::string
& locale
) {
506 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
507 g_io_thread_application_locale
.Get() = locale
;
510 void HandleBlockedPopupOnUIThread(const BlockedWindowParams
& params
) {
511 WebContents
* tab
= tab_util::GetWebContentsByID(params
.render_process_id(),
516 prerender::PrerenderContents
* prerender_contents
=
517 prerender::PrerenderContents::FromWebContents(tab
);
518 if (prerender_contents
) {
519 prerender_contents
->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW
);
523 PopupBlockerTabHelper
* popup_helper
=
524 PopupBlockerTabHelper::FromWebContents(tab
);
527 popup_helper
->AddBlockedPopup(params
);
530 #if defined(OS_ANDROID)
532 void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams
& params
) {
533 WebContents
* web_contents
=
534 tab_util::GetWebContentsByID(params
.render_process_id(),
539 SingleTabModeTabHelper::FromWebContents(web_contents
)->HandleOpenUrl(params
);
542 float GetDeviceScaleAdjustment() {
543 static const float kMinFSM
= 1.05f
;
544 static const int kWidthForMinFSM
= 320;
545 static const float kMaxFSM
= 1.3f
;
546 static const int kWidthForMaxFSM
= 800;
548 gfx::DeviceDisplayInfo info
;
549 int minWidth
= info
.GetSmallestDIPWidth();
551 if (minWidth
<= kWidthForMinFSM
)
553 if (minWidth
>= kWidthForMaxFSM
)
556 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
557 float ratio
= static_cast<float>(minWidth
- kWidthForMinFSM
) /
558 (kWidthForMaxFSM
- kWidthForMinFSM
);
559 return ratio
* (kMaxFSM
- kMinFSM
) + kMinFSM
;
562 #endif // defined(OS_ANDROID)
564 #if defined(ENABLE_EXTENSIONS)
565 // By default, JavaScript and images are enabled in guest content.
566 void GetGuestViewDefaultContentSettingRules(
568 RendererContentSettingRules
* rules
) {
569 rules
->image_rules
.push_back(
570 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
571 ContentSettingsPattern::Wildcard(),
572 CONTENT_SETTING_ALLOW
,
576 rules
->script_rules
.push_back(
577 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
578 ContentSettingsPattern::Wildcard(),
579 CONTENT_SETTING_ALLOW
,
583 #endif // defined(ENALBE_EXTENSIONS)
589 ChromeContentBrowserClient::ChromeContentBrowserClient()
590 : prerender_tracker_(NULL
),
591 weak_factory_(this) {
592 #if defined(ENABLE_PLUGINS)
593 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedDevChannelOrigins
); ++i
)
594 allowed_dev_channel_origins_
.insert(kPredefinedAllowedDevChannelOrigins
[i
]);
595 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedFileHandleOrigins
); ++i
)
596 allowed_file_handle_origins_
.insert(kPredefinedAllowedFileHandleOrigins
[i
]);
597 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedSocketOrigins
); ++i
)
598 allowed_socket_origins_
.insert(kPredefinedAllowedSocketOrigins
[i
]);
601 #if !defined(OS_ANDROID)
602 TtsExtensionEngine
* tts_extension_engine
= TtsExtensionEngine::GetInstance();
603 TtsController::GetInstance()->SetTtsEngineDelegate(tts_extension_engine
);
606 #if defined(ENABLE_EXTENSIONS)
607 extra_parts_
.push_back(new ChromeContentBrowserClientExtensionsPart
);
611 ChromeContentBrowserClient::~ChromeContentBrowserClient() {
612 for (int i
= static_cast<int>(extra_parts_
.size()) - 1; i
>= 0; --i
)
613 delete extra_parts_
[i
];
614 extra_parts_
.clear();
618 void ChromeContentBrowserClient::RegisterProfilePrefs(
619 user_prefs::PrefRegistrySyncable
* registry
) {
620 registry
->RegisterBooleanPref(
621 prefs::kDisable3DAPIs
,
623 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
624 registry
->RegisterBooleanPref(
625 prefs::kEnableHyperlinkAuditing
,
627 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
628 registry
->RegisterListPref(
629 prefs::kEnableDeprecatedWebPlatformFeatures
,
630 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
634 void ChromeContentBrowserClient::SetApplicationLocale(
635 const std::string
& locale
) {
636 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
638 // This object is guaranteed to outlive all threads so we don't have to
639 // worry about the lack of refcounting and can just post as Unretained.
641 // The common case is that this function is called early in Chrome startup
642 // before any threads are created (it will also be called later if the user
643 // changes the pref). In this case, there will be no threads created and
644 // posting will fail. When there are no threads, we can just set the string
645 // without worrying about threadsafety.
646 if (!BrowserThread::PostTask(BrowserThread::IO
, FROM_HERE
,
647 base::Bind(&SetApplicationLocaleOnIOThread
, locale
))) {
648 g_io_thread_application_locale
.Get() = locale
;
652 content::BrowserMainParts
* ChromeContentBrowserClient::CreateBrowserMainParts(
653 const content::MainFunctionParams
& parameters
) {
654 ChromeBrowserMainParts
* main_parts
;
655 // Construct the Main browser parts based on the OS type.
657 main_parts
= new ChromeBrowserMainPartsWin(parameters
);
658 #elif defined(OS_MACOSX)
659 main_parts
= new ChromeBrowserMainPartsMac(parameters
);
660 #elif defined(OS_CHROMEOS)
661 main_parts
= new chromeos::ChromeBrowserMainPartsChromeos(parameters
);
662 #elif defined(OS_LINUX)
663 main_parts
= new ChromeBrowserMainPartsLinux(parameters
);
664 #elif defined(OS_ANDROID)
665 main_parts
= new ChromeBrowserMainPartsAndroid(parameters
);
666 #elif defined(OS_POSIX)
667 main_parts
= new ChromeBrowserMainPartsPosix(parameters
);
670 main_parts
= new ChromeBrowserMainParts(parameters
);
673 chrome::AddProfilesExtraParts(main_parts
);
675 // Construct additional browser parts. Stages are called in the order in
676 // which they are added.
677 #if defined(TOOLKIT_VIEWS)
678 main_parts
->AddParts(new ChromeBrowserMainExtraPartsViews());
681 // TODO(oshima): Athena on chrome currently requires USE_ASH to build.
682 // We should reduce the dependency as much as possible.
683 #if defined(USE_ATHENA)
684 main_parts
->AddParts(CreateChromeBrowserMainExtraPartsAthena());
685 #elif defined(USE_ASH)
686 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAsh());
689 #if defined(USE_AURA)
690 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAura());
694 main_parts
->AddParts(new ChromeBrowserMainExtraPartsX11());
697 chrome::AddMetricsExtraParts(main_parts
);
702 std::string
ChromeContentBrowserClient::GetStoragePartitionIdForSite(
703 content::BrowserContext
* browser_context
,
705 std::string partition_id
;
707 // The partition ID for webview guest processes is the string value of its
708 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
709 if (site
.SchemeIs(content::kGuestScheme
)) {
710 partition_id
= site
.spec();
711 } else if (site
.GetOrigin().spec() == kChromeUIChromeSigninURL
) {
712 // Chrome signin page has an embedded iframe of extension and web content,
713 // thus it must be isolated from other webUI pages.
714 partition_id
= site
.GetOrigin().spec();
717 DCHECK(IsValidStoragePartitionId(browser_context
, partition_id
));
721 bool ChromeContentBrowserClient::IsValidStoragePartitionId(
722 content::BrowserContext
* browser_context
,
723 const std::string
& partition_id
) {
724 // The default ID is empty and is always valid.
725 if (partition_id
.empty())
728 return GURL(partition_id
).is_valid();
731 void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
732 content::BrowserContext
* browser_context
,
735 std::string
* partition_domain
,
736 std::string
* partition_name
,
738 // Default to the browser-wide storage partition and override based on |site|
740 partition_domain
->clear();
741 partition_name
->clear();
744 bool success
= false;
745 #if defined(ENABLE_EXTENSIONS)
746 success
= extensions::WebViewGuest::GetGuestPartitionConfigForSite(
747 site
, partition_domain
, partition_name
, in_memory
);
749 if (!success
&& site
.SchemeIs(extensions::kExtensionScheme
)) {
750 // If |can_be_default| is false, the caller is stating that the |site|
751 // should be parsed as if it had isolated storage. In particular it is
752 // important to NOT check ExtensionService for the is_storage_isolated()
753 // attribute because this code path is run during Extension uninstall
754 // to do cleanup after the Extension has already been unloaded from the
756 bool is_isolated
= !can_be_default
;
757 if (can_be_default
) {
758 if (extensions::util::SiteHasIsolatedStorage(site
, browser_context
))
763 CHECK(site
.has_host());
764 // For extensions with isolated storage, the the host of the |site| is
765 // the |partition_domain|. The |in_memory| and |partition_name| are only
766 // used in guest schemes so they are cleared here.
767 *partition_domain
= site
.host();
769 partition_name
->clear();
775 if (!success
&& (site
.GetOrigin().spec() == kChromeUIChromeSigninURL
)) {
776 // Chrome signin page has an embedded iframe of extension and web content,
777 // thus it must be isolated from other webUI pages.
778 *partition_domain
= chrome::kChromeUIChromeSigninHost
;
781 // Assert that if |can_be_default| is false, the code above must have found a
782 // non-default partition. If this fails, the caller has a serious logic
783 // error about which StoragePartition they expect to be in and it is not
785 CHECK(can_be_default
|| !partition_domain
->empty());
788 content::WebContentsViewDelegate
*
789 ChromeContentBrowserClient::GetWebContentsViewDelegate(
790 content::WebContents
* web_contents
) {
791 return chrome::CreateWebContentsViewDelegate(web_contents
);
794 void ChromeContentBrowserClient::RenderProcessWillLaunch(
795 content::RenderProcessHost
* host
) {
796 int id
= host
->GetID();
797 Profile
* profile
= Profile::FromBrowserContext(host
->GetBrowserContext());
798 net::URLRequestContextGetter
* context
=
799 profile
->GetRequestContextForRenderProcess(id
);
801 host
->AddFilter(new ChromeRenderMessageFilter(id
, profile
));
802 #if defined(ENABLE_PLUGINS)
803 host
->AddFilter(new PluginInfoMessageFilter(id
, profile
));
805 host
->AddFilter(new cast::CastTransportHostFilter
);
806 #if defined(ENABLE_PRINTING)
807 host
->AddFilter(new printing::PrintingMessageFilter(id
, profile
));
809 host
->AddFilter(new SearchProviderInstallStateMessageFilter(id
, profile
));
810 #if defined(ENABLE_SPELLCHECK)
811 host
->AddFilter(new SpellCheckMessageFilter(id
));
813 #if defined(OS_MACOSX)
814 host
->AddFilter(new SpellCheckMessageFilterMac(id
));
816 host
->AddFilter(new ChromeNetBenchmarkingMessageFilter(profile
, context
));
817 host
->AddFilter(new prerender::PrerenderMessageFilter(id
, profile
));
818 host
->AddFilter(new TtsMessageFilter(id
, host
->GetBrowserContext()));
819 #if defined(ENABLE_WEBRTC)
820 WebRtcLoggingHandlerHost
* webrtc_logging_handler_host
=
821 new WebRtcLoggingHandlerHost(profile
);
822 host
->SetWebRtcLogMessageCallback(base::Bind(
823 &WebRtcLoggingHandlerHost::LogMessage
, webrtc_logging_handler_host
));
824 host
->AddFilter(webrtc_logging_handler_host
);
825 host
->SetUserData(host
, new base::UserDataAdapter
<WebRtcLoggingHandlerHost
>(
826 webrtc_logging_handler_host
));
828 #if !defined(DISABLE_NACL)
829 host
->AddFilter(new nacl::NaClHostMessageFilter(
830 id
, profile
->IsOffTheRecord(),
834 #if defined(OS_ANDROID)
835 host
->AddFilter(new cdm::CdmMessageFilterAndroid());
837 if (switches::IsEnableAccountConsistency())
838 host
->AddFilter(new PrincipalsMessageFilter(id
));
840 host
->Send(new ChromeViewMsg_SetIsIncognitoProcess(
841 profile
->IsOffTheRecord()));
843 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
844 extra_parts_
[i
]->RenderProcessWillLaunch(host
);
846 RendererContentSettingRules rules
;
847 if (host
->IsIsolatedGuest()) {
848 #if defined(ENABLE_EXTENSIONS)
849 GetGuestViewDefaultContentSettingRules(profile
->IsOffTheRecord(), &rules
);
854 GetRendererContentSettingRules(
855 profile
->GetHostContentSettingsMap(), &rules
);
857 host
->Send(new ChromeViewMsg_SetContentSettingRules(rules
));
860 GURL
ChromeContentBrowserClient::GetEffectiveURL(
861 content::BrowserContext
* browser_context
, const GURL
& url
) {
862 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
866 // If the input |url| should be assigned to the Instant renderer, make its
867 // effective URL distinct from other URLs on the search provider's domain.
868 if (chrome::ShouldAssignURLToInstantRenderer(url
, profile
))
869 return chrome::GetEffectiveURLForInstant(url
, profile
);
871 #if !defined(OS_CHROMEOS)
872 // If the input |url| should be assigned to the Signin renderer, make its
873 // effective URL distinct from other URLs on the signin service's domain.
874 // Note that the signin renderer will be allowed to sign the user in to
876 if (SigninManager::IsWebBasedSigninFlowURL(url
))
877 return GetEffectiveURLForSignin(url
);
880 #if defined(ENABLE_EXTENSIONS)
881 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(
888 bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
889 content::BrowserContext
* browser_context
, const GURL
& effective_url
) {
890 // Non-extension, non-Instant URLs should generally use
891 // process-per-site-instance. Because we expect to use the effective URL,
892 // URLs for hosted apps (apart from bookmark apps) should have an extension
895 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
899 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url
, profile
))
902 #if !defined(OS_CHROMEOS)
903 if (SigninManager::IsWebBasedSigninFlowURL(effective_url
))
907 #if defined(ENABLE_EXTENSIONS)
908 return ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
909 profile
, effective_url
);
915 // These are treated as WebUI schemes but do not get WebUI bindings. Also,
916 // view-source is allowed for these schemes.
917 void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
918 std::vector
<std::string
>* additional_schemes
) {
919 additional_schemes
->push_back(chrome::kChromeSearchScheme
);
920 additional_schemes
->push_back(dom_distiller::kDomDistillerScheme
);
923 void ChromeContentBrowserClient::GetAdditionalWebUIHostsToIgnoreParititionCheck(
924 std::vector
<std::string
>* hosts
) {
925 hosts
->push_back(chrome::kChromeUIExtensionIconHost
);
926 hosts
->push_back(chrome::kChromeUIFaviconHost
);
927 hosts
->push_back(chrome::kChromeUIThemeHost
);
928 hosts
->push_back(chrome::kChromeUIThumbnailHost
);
929 hosts
->push_back(chrome::kChromeUIThumbnailHost2
);
930 hosts
->push_back(chrome::kChromeUIThumbnailListHost
);
933 net::URLRequestContextGetter
*
934 ChromeContentBrowserClient::CreateRequestContext(
935 content::BrowserContext
* browser_context
,
936 content::ProtocolHandlerMap
* protocol_handlers
,
937 content::URLRequestInterceptorScopedVector request_interceptors
) {
938 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
939 return profile
->CreateRequestContext(protocol_handlers
,
940 request_interceptors
.Pass());
943 net::URLRequestContextGetter
*
944 ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
945 content::BrowserContext
* browser_context
,
946 const base::FilePath
& partition_path
,
948 content::ProtocolHandlerMap
* protocol_handlers
,
949 content::URLRequestInterceptorScopedVector request_interceptors
) {
950 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
951 return profile
->CreateRequestContextForStoragePartition(
955 request_interceptors
.Pass());
958 bool ChromeContentBrowserClient::IsHandledURL(const GURL
& url
) {
959 return ProfileIOData::IsHandledURL(url
);
962 bool ChromeContentBrowserClient::CanCommitURL(
963 content::RenderProcessHost
* process_host
,
965 #if defined(ENABLE_EXTENSIONS)
966 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(
973 bool ChromeContentBrowserClient::ShouldAllowOpenURL(
974 content::SiteInstance
* site_instance
, const GURL
& url
) {
975 GURL from_url
= site_instance
->GetSiteURL();
977 #if defined(ENABLE_EXTENSIONS)
979 if (ChromeContentBrowserClientExtensionsPart::ShouldAllowOpenURL(
980 site_instance
, from_url
, url
, &result
))
984 // Do not allow chrome://chrome-signin navigate to other chrome:// URLs, since
985 // the signin page may host untrusted web content.
986 if (from_url
.GetOrigin().spec() == chrome::kChromeUIChromeSigninURL
&&
987 url
.SchemeIs(content::kChromeUIScheme
) &&
988 url
.host() != chrome::kChromeUIChromeSigninHost
) {
989 VLOG(1) << "Blocked navigation to " << url
.spec() << " from "
990 << chrome::kChromeUIChromeSigninURL
;
997 bool ChromeContentBrowserClient::IsSuitableHost(
998 content::RenderProcessHost
* process_host
,
999 const GURL
& site_url
) {
1001 Profile::FromBrowserContext(process_host
->GetBrowserContext());
1002 // This may be NULL during tests. In that case, just assume any site can
1007 // Instant URLs should only be in the instant process and instant process
1008 // should only have Instant URLs.
1009 InstantService
* instant_service
=
1010 InstantServiceFactory::GetForProfile(profile
);
1011 if (instant_service
) {
1012 bool is_instant_process
= instant_service
->IsInstantProcess(
1013 process_host
->GetID());
1014 bool should_be_in_instant_process
=
1015 chrome::ShouldAssignURLToInstantRenderer(site_url
, profile
);
1016 if (is_instant_process
|| should_be_in_instant_process
)
1017 return is_instant_process
&& should_be_in_instant_process
;
1020 #if !defined(OS_CHROMEOS)
1021 SigninClient
* signin_client
=
1022 ChromeSigninClientFactory::GetForProfile(profile
);
1023 if (signin_client
&& signin_client
->IsSigninProcess(process_host
->GetID()))
1024 return SigninManager::IsWebBasedSigninFlowURL(site_url
);
1027 #if defined(ENABLE_EXTENSIONS)
1028 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1029 profile
, process_host
, site_url
);
1035 bool ChromeContentBrowserClient::MayReuseHost(
1036 content::RenderProcessHost
* process_host
) {
1037 // If there is currently a prerender in progress for the host provided,
1038 // it may not be shared. We require prerenders to be by themselves in a
1039 // separate process, so that we can monitor their resource usage, and so that
1040 // we can track the cookies that they change.
1041 Profile
* profile
= Profile::FromBrowserContext(
1042 process_host
->GetBrowserContext());
1043 prerender::PrerenderManager
* prerender_manager
=
1044 prerender::PrerenderManagerFactory::GetForProfile(profile
);
1045 if (prerender_manager
&&
1046 !prerender_manager
->MayReuseProcessHost(process_host
)) {
1053 bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1054 content::BrowserContext
* browser_context
, const GURL
& url
) {
1055 // It has to be a valid URL for us to check for an extension.
1056 if (!url
.is_valid())
1059 #if defined(ENABLE_EXTENSIONS)
1060 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1061 return ChromeContentBrowserClientExtensionsPart::
1062 ShouldTryToUseExistingProcessHost(
1069 void ChromeContentBrowserClient::SiteInstanceGotProcess(
1070 SiteInstance
* site_instance
) {
1071 CHECK(site_instance
->HasProcess());
1073 Profile
* profile
= Profile::FromBrowserContext(
1074 site_instance
->GetBrowserContext());
1078 // Remember the ID of the Instant process to signal the renderer process
1079 // on startup in |AppendExtraCommandLineSwitches| below.
1080 if (chrome::ShouldAssignURLToInstantRenderer(
1081 site_instance
->GetSiteURL(), profile
)) {
1082 InstantService
* instant_service
=
1083 InstantServiceFactory::GetForProfile(profile
);
1084 if (instant_service
)
1085 instant_service
->AddInstantProcess(site_instance
->GetProcess()->GetID());
1088 #if !defined(OS_CHROMEOS)
1089 // We only expect there to be one signin process as we use process-per-site
1090 // for signin URLs. The signin process will be cleared from SigninManager
1091 // when the renderer is destroyed.
1092 if (SigninManager::IsWebBasedSigninFlowURL(site_instance
->GetSiteURL())) {
1093 SigninClient
* signin_client
=
1094 ChromeSigninClientFactory::GetForProfile(profile
);
1096 signin_client
->SetSigninProcess(site_instance
->GetProcess()->GetID());
1097 #if defined(ENABLE_EXTENSIONS)
1098 ChromeContentBrowserClientExtensionsPart::SetSigninProcess(site_instance
);
1103 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
1104 extra_parts_
[i
]->SiteInstanceGotProcess(site_instance
);
1107 void ChromeContentBrowserClient::SiteInstanceDeleting(
1108 SiteInstance
* site_instance
) {
1109 if (!site_instance
->HasProcess())
1112 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
1113 extra_parts_
[i
]->SiteInstanceDeleting(site_instance
);
1116 bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
1117 SiteInstance
* site_instance
,
1118 const GURL
& current_url
,
1119 const GURL
& new_url
) {
1120 #if defined(ENABLE_EXTENSIONS)
1121 return ChromeContentBrowserClientExtensionsPart::
1122 ShouldSwapBrowsingInstancesForNavigation(
1123 site_instance
, current_url
, new_url
);
1129 bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1130 content::ResourceContext
* resource_context
, const GURL
& current_url
,
1131 const GURL
& new_url
) {
1132 #if defined(ENABLE_EXTENSIONS)
1133 return ChromeContentBrowserClientExtensionsPart::
1134 ShouldSwapProcessesForRedirect(resource_context
, current_url
, new_url
);
1140 bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL
& url
) {
1141 return !url
.SchemeIs(chrome::kChromeNativeScheme
);
1144 std::string
ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1145 const std::string
& alias_name
) {
1146 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name
);
1151 bool IsAutoReloadEnabled() {
1152 // Fetch the field trial, even though we don't use it. Calling FindFullName()
1153 // causes the field-trial mechanism to report which group we're in, which
1154 // might reflect a hard disable or hard enable via flag, both of which have
1155 // their own field trial groups. This lets us know what percentage of users
1156 // manually enable or disable auto-reload.
1157 std::string group
= base::FieldTrialList::FindFullName(
1158 "AutoReloadExperiment");
1159 const CommandLine
& browser_command_line
= *CommandLine::ForCurrentProcess();
1160 if (browser_command_line
.HasSwitch(switches::kEnableOfflineAutoReload
))
1162 if (browser_command_line
.HasSwitch(switches::kDisableOfflineAutoReload
))
1167 bool IsAutoReloadVisibleOnlyEnabled() {
1168 // See the block comment in IsAutoReloadEnabled().
1169 std::string group
= base::FieldTrialList::FindFullName(
1170 "AutoReloadVisibleOnlyExperiment");
1171 const CommandLine
& browser_command_line
= *CommandLine::ForCurrentProcess();
1172 if (browser_command_line
.HasSwitch(
1173 switches::kEnableOfflineAutoReloadVisibleOnly
)) {
1176 if (browser_command_line
.HasSwitch(
1177 switches::kDisableOfflineAutoReloadVisibleOnly
)) {
1185 void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1186 CommandLine
* command_line
, int child_process_id
) {
1187 #if defined(OS_POSIX)
1188 if (breakpad::IsCrashReporterEnabled()) {
1189 scoped_ptr
<metrics::ClientInfo
> client_info
=
1190 GoogleUpdateSettings::LoadMetricsClientInfo();
1191 command_line
->AppendSwitchASCII(switches::kEnableCrashReporter
,
1192 client_info
? client_info
->client_id
1195 #endif // defined(OS_POSIX)
1197 if (logging::DialogsAreSuppressed())
1198 command_line
->AppendSwitch(switches::kNoErrorDialogs
);
1200 std::string process_type
=
1201 command_line
->GetSwitchValueASCII(switches::kProcessType
);
1202 const CommandLine
& browser_command_line
= *CommandLine::ForCurrentProcess();
1204 static const char* const kCommonSwitchNames
[] = {
1205 switches::kUserAgent
,
1206 switches::kUserDataDir
, // Make logs go to the right file.
1208 command_line
->CopySwitchesFrom(browser_command_line
, kCommonSwitchNames
,
1209 arraysize(kCommonSwitchNames
));
1211 #if defined(ENABLE_IPC_FUZZER)
1212 static const char* const kIpcFuzzerSwitches
[] = {
1213 switches::kIpcFuzzerTestcase
,
1215 command_line
->CopySwitchesFrom(browser_command_line
, kIpcFuzzerSwitches
,
1216 arraysize(kIpcFuzzerSwitches
));
1219 #if defined(OS_CHROMEOS)
1220 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
1221 base::FilePath homedir
;
1222 PathService::Get(base::DIR_HOME
, &homedir
);
1223 command_line
->AppendSwitchASCII(chromeos::switches::kHomedir
,
1224 homedir
.value().c_str());
1227 if (process_type
== switches::kRendererProcess
) {
1228 content::RenderProcessHost
* process
=
1229 content::RenderProcessHost::FromID(child_process_id
);
1231 process
? Profile::FromBrowserContext(process
->GetBrowserContext())
1233 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
1234 extra_parts_
[i
]->AppendExtraRendererCommandLineSwitches(
1235 command_line
, process
, profile
);
1238 #if defined(OS_CHROMEOS)
1239 const std::string
& login_profile
=
1240 browser_command_line
.GetSwitchValueASCII(
1241 chromeos::switches::kLoginProfile
);
1242 if (!login_profile
.empty())
1243 command_line
->AppendSwitchASCII(
1244 chromeos::switches::kLoginProfile
, login_profile
);
1247 #if defined(ENABLE_WEBRTC)
1248 MaybeCopyDisableWebRtcEncryptionSwitch(command_line
,
1249 browser_command_line
,
1250 VersionInfo::GetChannel());
1254 PrefService
* prefs
= profile
->GetPrefs();
1255 // Currently this pref is only registered if applied via a policy.
1256 if (prefs
->HasPrefPath(prefs::kDisable3DAPIs
) &&
1257 prefs
->GetBoolean(prefs::kDisable3DAPIs
)) {
1258 // Turn this policy into a command line switch.
1259 command_line
->AppendSwitch(switches::kDisable3DAPIs
);
1262 const base::ListValue
* switches
=
1263 prefs
->GetList(prefs::kEnableDeprecatedWebPlatformFeatures
);
1265 // Enable any deprecated features that have been re-enabled by policy.
1266 for (base::ListValue::const_iterator it
= switches
->begin();
1267 it
!= switches
->end(); ++it
) {
1268 std::string switch_to_enable
;
1269 if ((*it
)->GetAsString(&switch_to_enable
))
1270 command_line
->AppendSwitch(switch_to_enable
);
1274 // Disable client-side phishing detection in the renderer if it is
1275 // disabled in the Profile preferences or the browser process.
1276 if (!prefs
->GetBoolean(prefs::kSafeBrowsingEnabled
) ||
1277 !g_browser_process
->safe_browsing_detection_service()) {
1278 command_line
->AppendSwitch(
1279 switches::kDisableClientSidePhishingDetection
);
1282 InstantService
* instant_service
=
1283 InstantServiceFactory::GetForProfile(profile
);
1284 if (instant_service
&&
1285 instant_service
->IsInstantProcess(process
->GetID()))
1286 command_line
->AppendSwitch(switches::kInstantProcess
);
1288 #if !defined(OS_CHROMEOS)
1289 SigninClient
* signin_client
=
1290 ChromeSigninClientFactory::GetForProfile(profile
);
1291 if (signin_client
&& signin_client
->IsSigninProcess(process
->GetID()))
1292 command_line
->AppendSwitch(switches::kSigninProcess
);
1296 if (IsAutoReloadEnabled())
1297 command_line
->AppendSwitch(switches::kEnableOfflineAutoReload
);
1298 if (IsAutoReloadVisibleOnlyEnabled()) {
1299 command_line
->AppendSwitch(
1300 switches::kEnableOfflineAutoReloadVisibleOnly
);
1304 // Enable load stale cache if this session is in the field trial or
1305 // the user explicitly enabled it. Note that as far as the renderer
1306 // is concerned, the feature is enabled if-and-only-if the
1307 // kEnableOfflineLoadStaleCache flag is on the command line;
1308 // the yes/no/default behavior is only at the browser command line
1311 // Command line switches override
1312 if (browser_command_line
.HasSwitch(
1313 switches::kEnableOfflineLoadStaleCache
)) {
1314 command_line
->AppendSwitch(switches::kEnableOfflineLoadStaleCache
);
1315 } else if (!browser_command_line
.HasSwitch(
1316 switches::kDisableOfflineLoadStaleCache
)) {
1318 base::FieldTrialList::FindFullName("LoadStaleCacheExperiment");
1320 if (group
== "Enabled")
1321 command_line
->AppendSwitch(switches::kEnableOfflineLoadStaleCache
);
1325 // Please keep this in alphabetical order.
1326 static const char* const kSwitchNames
[] = {
1327 autofill::switches::kDisableIgnoreAutocompleteOff
,
1328 autofill::switches::kDisablePasswordGeneration
,
1329 autofill::switches::kEnablePasswordGeneration
,
1330 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration
,
1331 #if defined(ENABLE_EXTENSIONS)
1332 extensions::switches::kAllowHTTPBackgroundPage
,
1333 extensions::switches::kAllowLegacyExtensionManifests
,
1334 extensions::switches::kEnableAppView
,
1335 extensions::switches::kEnableAppWindowControls
,
1336 extensions::switches::kEnableEmbeddedExtensionOptions
,
1337 extensions::switches::kEnableExperimentalExtensionApis
,
1338 extensions::switches::kEnableScriptsRequireAction
,
1339 extensions::switches::kExtensionsOnChromeURLs
,
1340 extensions::switches::kWhitelistedExtensionID
,
1342 switches::kAppsCheckoutURL
,
1343 switches::kAppsGalleryURL
,
1344 switches::kCloudPrintURL
,
1345 switches::kCloudPrintXmppEndpoint
,
1346 switches::kDisableBundledPpapiFlash
,
1347 switches::kEnableBenchmarking
,
1348 switches::kEnableNaCl
,
1349 #if !defined(DISABLE_NACL)
1350 switches::kEnableNaClDebug
,
1351 switches::kEnableNaClNonSfiMode
,
1353 switches::kEnableNetBenchmarking
,
1354 switches::kEnableShowModalDialog
,
1355 switches::kEnableStreamlinedHostedApps
,
1356 switches::kEnableWebBasedSignin
,
1357 switches::kMessageLoopHistogrammer
,
1358 switches::kOutOfProcessPdf
,
1359 switches::kPlaybackMode
,
1360 switches::kPpapiFlashArgs
,
1361 switches::kPpapiFlashPath
,
1362 switches::kPpapiFlashVersion
,
1363 switches::kProfilingAtStart
,
1364 switches::kProfilingFile
,
1365 switches::kProfilingFlush
,
1366 switches::kRecordMode
,
1367 translate::switches::kTranslateSecurityOrigin
,
1370 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1371 arraysize(kSwitchNames
));
1372 } else if (process_type
== switches::kUtilityProcess
) {
1373 #if defined(ENABLE_EXTENSIONS)
1374 static const char* const kSwitchNames
[] = {
1375 extensions::switches::kAllowHTTPBackgroundPage
,
1376 extensions::switches::kEnableExperimentalExtensionApis
,
1377 extensions::switches::kExtensionsOnChromeURLs
,
1378 extensions::switches::kWhitelistedExtensionID
,
1381 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1382 arraysize(kSwitchNames
));
1384 } else if (process_type
== switches::kPluginProcess
) {
1385 #if defined(OS_CHROMEOS)
1386 static const char* const kSwitchNames
[] = {
1387 chromeos::switches::kLoginProfile
,
1390 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1391 arraysize(kSwitchNames
));
1393 } else if (process_type
== switches::kZygoteProcess
) {
1394 static const char* const kSwitchNames
[] = {
1395 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
1396 switches::kDisableBundledPpapiFlash
,
1397 #if !defined(DISABLE_NACL)
1398 switches::kEnableNaClNonSfiMode
,
1399 switches::kNaClDangerousNoSandboxNonSfi
,
1401 switches::kPpapiFlashPath
,
1402 switches::kPpapiFlashVersion
,
1405 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1406 arraysize(kSwitchNames
));
1407 } else if (process_type
== switches::kGpuProcess
) {
1408 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1409 // because GPU is expected to be unreliable.
1410 if (browser_command_line
.HasSwitch(switches::kIgnoreGpuBlacklist
) &&
1411 !command_line
->HasSwitch(switches::kDisableBreakpad
))
1412 command_line
->AppendSwitch(switches::kDisableBreakpad
);
1415 // The command line switch kEnableBenchmarking needs to be specified along
1416 // with the kEnableStatsTable switch to ensure that the stats table global
1417 // is initialized correctly.
1418 if (command_line
->HasSwitch(switches::kEnableBenchmarking
))
1419 DCHECK(command_line
->HasSwitch(switches::kEnableStatsTable
));
1422 std::string
ChromeContentBrowserClient::GetApplicationLocale() {
1423 if (BrowserThread::CurrentlyOn(BrowserThread::IO
))
1424 return g_io_thread_application_locale
.Get();
1425 return g_browser_process
->GetApplicationLocale();
1428 std::string
ChromeContentBrowserClient::GetAcceptLangs(
1429 content::BrowserContext
* context
) {
1430 Profile
* profile
= Profile::FromBrowserContext(context
);
1431 return profile
->GetPrefs()->GetString(prefs::kAcceptLanguages
);
1434 const gfx::ImageSkia
* ChromeContentBrowserClient::GetDefaultFavicon() {
1435 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
1436 return rb
.GetNativeImageNamed(IDR_DEFAULT_FAVICON
).ToImageSkia();
1439 bool ChromeContentBrowserClient::AllowAppCache(
1440 const GURL
& manifest_url
,
1441 const GURL
& first_party
,
1442 content::ResourceContext
* context
) {
1443 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1444 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1445 return io_data
->GetCookieSettings()->
1446 IsSettingCookieAllowed(manifest_url
, first_party
);
1449 bool ChromeContentBrowserClient::AllowGetCookie(
1451 const GURL
& first_party
,
1452 const net::CookieList
& cookie_list
,
1453 content::ResourceContext
* context
,
1454 int render_process_id
,
1455 int render_frame_id
) {
1456 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1457 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1458 bool allow
= io_data
->GetCookieSettings()->
1459 IsReadingCookieAllowed(url
, first_party
);
1461 BrowserThread::PostTask(
1462 BrowserThread::UI
, FROM_HERE
,
1463 base::Bind(&TabSpecificContentSettings::CookiesRead
, render_process_id
,
1464 render_frame_id
, url
, first_party
, cookie_list
, !allow
, true));
1468 bool ChromeContentBrowserClient::AllowSetCookie(
1470 const GURL
& first_party
,
1471 const std::string
& cookie_line
,
1472 content::ResourceContext
* context
,
1473 int render_process_id
,
1474 int render_frame_id
,
1475 net::CookieOptions
* options
) {
1476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1477 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1478 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1479 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, first_party
);
1481 if (prerender_tracker_
) {
1482 prerender_tracker_
->OnCookieChangedForURL(
1484 context
->GetRequestContext()->cookie_store()->GetCookieMonster(),
1488 BrowserThread::PostTask(
1489 BrowserThread::UI
, FROM_HERE
,
1490 base::Bind(&TabSpecificContentSettings::CookieChanged
, render_process_id
,
1491 render_frame_id
, url
, first_party
, cookie_line
, *options
,
1496 bool ChromeContentBrowserClient::AllowSaveLocalState(
1497 content::ResourceContext
* context
) {
1498 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1499 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1500 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1501 ContentSetting setting
= cookie_settings
->GetDefaultCookieSetting(NULL
);
1503 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1504 // Could we even support per-origin settings?
1505 return setting
!= CONTENT_SETTING_SESSION_ONLY
;
1508 bool ChromeContentBrowserClient::AllowWorkerDatabase(
1510 const base::string16
& name
,
1511 const base::string16
& display_name
,
1512 unsigned long estimated_size
,
1513 content::ResourceContext
* context
,
1514 const std::vector
<std::pair
<int, int> >& render_frames
) {
1515 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1516 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1517 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1518 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1520 // Record access to database for potential display in UI.
1521 std::vector
<std::pair
<int, int> >::const_iterator i
;
1522 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1523 BrowserThread::PostTask(
1524 BrowserThread::UI
, FROM_HERE
,
1525 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed
,
1526 i
->first
, i
->second
, url
, name
, display_name
, !allow
));
1532 void ChromeContentBrowserClient::AllowWorkerFileSystem(
1534 content::ResourceContext
* context
,
1535 const std::vector
<std::pair
<int, int> >& render_frames
,
1536 base::Callback
<void(bool)> callback
) {
1537 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1538 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1539 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1540 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1542 #if defined(ENABLE_EXTENSIONS)
1543 GuestPermissionRequestHelper(url
, render_frames
, callback
, allow
);
1545 FileSystemAccessed(url
, render_frames
, callback
, allow
);
1549 #if defined(ENABLE_EXTENSIONS)
1550 void ChromeContentBrowserClient::GuestPermissionRequestHelper(
1552 const std::vector
<std::pair
<int, int> >& render_frames
,
1553 base::Callback
<void(bool)> callback
,
1555 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::IO
));
1556 std::vector
<std::pair
<int, int> >::const_iterator i
;
1557 std::map
<int, int> process_map
;
1558 std::map
<int, int>::const_iterator it
;
1559 bool has_web_view_guest
= false;
1560 // Record access to file system for potential display in UI.
1561 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1562 if (process_map
.find(i
->first
) != process_map
.end())
1565 process_map
.insert(std::pair
<int, int>(i
->first
, i
->second
));
1567 if (extensions::WebViewRendererState::GetInstance()->IsGuest(i
->first
))
1568 has_web_view_guest
= true;
1570 if (!has_web_view_guest
) {
1571 FileSystemAccessed(url
, render_frames
, callback
, allow
);
1574 DCHECK_EQ(1U, process_map
.size());
1575 it
= process_map
.begin();
1576 BrowserThread::PostTask(
1579 base::Bind(&ChromeContentBrowserClient::
1580 RequestFileSystemPermissionOnUIThread
,
1585 base::Bind(&ChromeContentBrowserClient::FileSystemAccessed
,
1586 weak_factory_
.GetWeakPtr(),
1592 void ChromeContentBrowserClient::RequestFileSystemPermissionOnUIThread(
1593 int render_process_id
,
1594 int render_frame_id
,
1596 bool allowed_by_default
,
1597 const base::Callback
<void(bool)>& callback
) {
1598 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::UI
));
1599 extensions::WebViewPermissionHelper
* web_view_permission_helper
=
1600 extensions::WebViewPermissionHelper::FromFrameID(
1601 render_process_id
, render_frame_id
);
1602 web_view_permission_helper
->RequestFileSystemPermission(url
,
1608 void ChromeContentBrowserClient::FileSystemAccessed(
1610 const std::vector
<std::pair
<int, int> >& render_frames
,
1611 base::Callback
<void(bool)> callback
,
1613 // Record access to file system for potential display in UI.
1614 std::vector
<std::pair
<int, int> >::const_iterator i
;
1615 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1616 BrowserThread::PostTask(
1619 base::Bind(&TabSpecificContentSettings::FileSystemAccessed
,
1620 i
->first
, i
->second
, url
, !allow
));
1622 callback
.Run(allow
);
1625 bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1627 const base::string16
& name
,
1628 content::ResourceContext
* context
,
1629 const std::vector
<std::pair
<int, int> >& render_frames
) {
1630 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1631 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1632 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1633 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1635 // Record access to IndexedDB for potential display in UI.
1636 std::vector
<std::pair
<int, int> >::const_iterator i
;
1637 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1638 BrowserThread::PostTask(
1639 BrowserThread::UI
, FROM_HERE
,
1640 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed
,
1641 i
->first
, i
->second
, url
, name
, !allow
));
1647 net::URLRequestContext
*
1648 ChromeContentBrowserClient::OverrideRequestContextForURL(
1649 const GURL
& url
, content::ResourceContext
* context
) {
1650 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1651 #if defined(ENABLE_EXTENSIONS)
1652 if (url
.SchemeIs(extensions::kExtensionScheme
)) {
1653 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1654 return io_data
->extensions_request_context();
1661 QuotaPermissionContext
*
1662 ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1663 return new ChromeQuotaPermissionContext();
1666 void ChromeContentBrowserClient::AllowCertificateError(
1667 int render_process_id
,
1668 int render_frame_id
,
1670 const net::SSLInfo
& ssl_info
,
1671 const GURL
& request_url
,
1672 ResourceType resource_type
,
1674 bool strict_enforcement
,
1675 bool expired_previous_decision
,
1676 const base::Callback
<void(bool)>& callback
,
1677 content::CertificateRequestResultType
* result
) {
1678 if (resource_type
!= content::RESOURCE_TYPE_MAIN_FRAME
) {
1679 // A sub-resource has a certificate error. The user doesn't really
1680 // have a context for making the right decision, so block the
1681 // request hard, without an info bar to allow showing the insecure
1683 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY
;
1687 // If the tab is being prerendered, cancel the prerender and the request.
1688 content::RenderFrameHost
* render_frame_host
=
1689 content::RenderFrameHost::FromID(render_process_id
, render_frame_id
);
1690 WebContents
* tab
= WebContents::FromRenderFrameHost(render_frame_host
);
1696 prerender::PrerenderContents
* prerender_contents
=
1697 prerender::PrerenderContents::FromWebContents(tab
);
1698 if (prerender_contents
) {
1699 prerender_contents
->Destroy(prerender::FINAL_STATUS_SSL_ERROR
);
1700 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL
;
1704 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
1705 CaptivePortalTabHelper
* captive_portal_tab_helper
=
1706 CaptivePortalTabHelper::FromWebContents(tab
);
1707 if (captive_portal_tab_helper
)
1708 captive_portal_tab_helper
->OnSSLCertError(ssl_info
);
1711 // Otherwise, display an SSL blocking page. The interstitial page takes
1712 // ownership of ssl_blocking_page.
1713 int options_mask
= 0;
1715 options_mask
= SSLBlockingPage::OVERRIDABLE
;
1716 if (strict_enforcement
)
1717 options_mask
= SSLBlockingPage::STRICT_ENFORCEMENT
;
1718 if (expired_previous_decision
)
1719 options_mask
= SSLBlockingPage::EXPIRED_BUT_PREVIOUSLY_ALLOWED
;
1720 SSLBlockingPage
* ssl_blocking_page
= new SSLBlockingPage(
1721 tab
, cert_error
, ssl_info
, request_url
, options_mask
, callback
);
1722 ssl_blocking_page
->Show();
1725 void ChromeContentBrowserClient::SelectClientCertificate(
1726 int render_process_id
,
1727 int render_frame_id
,
1728 const net::HttpNetworkSession
* network_session
,
1729 net::SSLCertRequestInfo
* cert_request_info
,
1730 const base::Callback
<void(net::X509Certificate
*)>& callback
) {
1731 content::RenderFrameHost
* rfh
= content::RenderFrameHost::FromID(
1732 render_process_id
, render_frame_id
);
1733 WebContents
* tab
= WebContents::FromRenderFrameHost(rfh
);
1739 prerender::PrerenderContents
* prerender_contents
=
1740 prerender::PrerenderContents::FromWebContents(tab
);
1741 if (prerender_contents
) {
1742 prerender_contents
->Destroy(
1743 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED
);
1747 GURL
requesting_url("https://" + cert_request_info
->host_and_port
.ToString());
1748 DCHECK(requesting_url
.is_valid())
1749 << "Invalid URL string: https://"
1750 << cert_request_info
->host_and_port
.ToString();
1752 Profile
* profile
= Profile::FromBrowserContext(tab
->GetBrowserContext());
1753 scoped_ptr
<base::Value
> filter(
1754 profile
->GetHostContentSettingsMap()->GetWebsiteSetting(
1757 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE
,
1758 std::string(), NULL
));
1761 // Try to automatically select a client certificate.
1762 if (filter
->IsType(base::Value::TYPE_DICTIONARY
)) {
1763 base::DictionaryValue
* filter_dict
=
1764 static_cast<base::DictionaryValue
*>(filter
.get());
1766 const std::vector
<scoped_refptr
<net::X509Certificate
> >&
1767 all_client_certs
= cert_request_info
->client_certs
;
1768 for (size_t i
= 0; i
< all_client_certs
.size(); ++i
) {
1769 if (CertMatchesFilter(*all_client_certs
[i
].get(), *filter_dict
)) {
1770 // Use the first certificate that is matched by the filter.
1771 callback
.Run(all_client_certs
[i
].get());
1780 chrome::ShowSSLClientCertificateSelector(tab
, network_session
,
1781 cert_request_info
, callback
);
1784 void ChromeContentBrowserClient::AddCertificate(
1785 net::CertificateMimeType cert_type
,
1786 const void* cert_data
,
1788 int render_process_id
,
1789 int render_frame_id
) {
1790 chrome::SSLAddCertificate(cert_type
, cert_data
, cert_size
,
1791 render_process_id
, render_frame_id
);
1794 content::MediaObserver
* ChromeContentBrowserClient::GetMediaObserver() {
1795 return MediaCaptureDevicesDispatcher::GetInstance();
1798 void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1799 const GURL
& source_origin
,
1800 content::RenderFrameHost
* render_frame_host
,
1801 const base::Callback
<void(blink::WebNotificationPermission
)>& callback
) {
1802 #if defined(ENABLE_NOTIFICATIONS)
1803 // Skip showing the infobar if the request comes from an extension, and that
1804 // extension has the 'notify' permission. (If the extension does not have the
1805 // permission, the user will still be prompted.)
1806 Profile
* profile
= Profile::FromBrowserContext(
1807 render_frame_host
->GetSiteInstance()->GetBrowserContext());
1808 DesktopNotificationService
* notification_service
=
1809 DesktopNotificationServiceFactory::GetForProfile(profile
);
1810 #if defined(ENABLE_EXTENSIONS)
1811 InfoMap
* extension_info_map
=
1812 extensions::ExtensionSystem::Get(profile
)->info_map();
1813 const Extension
* extension
= NULL
;
1814 if (extension_info_map
) {
1815 extensions::ExtensionSet extensions
;
1816 extension_info_map
->GetExtensionsWithAPIPermissionForSecurityOrigin(
1818 render_frame_host
->GetProcess()->GetID(),
1819 extensions::APIPermission::kNotifications
,
1821 for (extensions::ExtensionSet::const_iterator iter
= extensions
.begin();
1822 iter
!= extensions
.end(); ++iter
) {
1823 if (notification_service
->IsNotifierEnabled(NotifierId(
1824 NotifierId::APPLICATION
, (*iter
)->id()))) {
1825 extension
= iter
->get();
1830 if (IsExtensionWithPermissionOrSuggestInConsole(
1831 APIPermission::kNotifications
,
1833 render_frame_host
->GetRenderViewHost())) {
1834 callback
.Run(blink::WebNotificationPermissionAllowed
);
1839 WebContents
* web_contents
= WebContents::FromRenderFrameHost(
1841 int render_process_id
= render_frame_host
->GetProcess()->GetID();
1842 const PermissionRequestID
request_id(render_process_id
,
1843 web_contents
->GetRoutingID(),
1847 notification_service
->RequestNotificationPermission(
1851 // TODO(peter): plumb user_gesture over IPC
1860 blink::WebNotificationPermission
1861 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
1862 const GURL
& source_origin
,
1863 content::ResourceContext
* context
,
1864 int render_process_id
) {
1865 #if defined(ENABLE_NOTIFICATIONS)
1866 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1868 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1869 InfoMap
* extension_info_map
= io_data
->GetExtensionInfoMap();
1871 // We want to see if there is an extension that hasn't been manually disabled
1872 // that has the notifications permission and applies to this security origin.
1873 // First, get the list of extensions with permission for the origin.
1874 extensions::ExtensionSet extensions
;
1875 extension_info_map
->GetExtensionsWithAPIPermissionForSecurityOrigin(
1878 extensions::APIPermission::kNotifications
,
1880 for (extensions::ExtensionSet::const_iterator iter
= extensions
.begin();
1881 iter
!= extensions
.end(); ++iter
) {
1882 // Then, check to see if it's been disabled by the user.
1883 if (!extension_info_map
->AreNotificationsDisabled((*iter
)->id()))
1884 return blink::WebNotificationPermissionAllowed
;
1887 // No enabled extensions exist, so check the normal host content settings.
1888 HostContentSettingsMap
* host_content_settings_map
=
1889 io_data
->GetHostContentSettingsMap();
1890 ContentSetting setting
= host_content_settings_map
->GetContentSetting(
1893 CONTENT_SETTINGS_TYPE_NOTIFICATIONS
,
1894 NO_RESOURCE_IDENTIFIER
);
1896 if (setting
== CONTENT_SETTING_ALLOW
)
1897 return blink::WebNotificationPermissionAllowed
;
1898 if (setting
== CONTENT_SETTING_BLOCK
)
1899 return blink::WebNotificationPermissionDenied
;
1900 return blink::WebNotificationPermissionDefault
;
1902 return blink::WebNotificationPermissionAllowed
;
1906 void ChromeContentBrowserClient::ShowDesktopNotification(
1907 const content::ShowDesktopNotificationHostMsgParams
& params
,
1908 RenderFrameHost
* render_frame_host
,
1909 scoped_ptr
<content::DesktopNotificationDelegate
> delegate
,
1910 base::Closure
* cancel_callback
) {
1911 #if defined(ENABLE_NOTIFICATIONS)
1912 content::RenderProcessHost
* process
= render_frame_host
->GetProcess();
1913 Profile
* profile
= Profile::FromBrowserContext(process
->GetBrowserContext());
1914 DesktopNotificationService
* service
=
1915 DesktopNotificationServiceFactory::GetForProfile(profile
);
1916 service
->ShowDesktopNotification(
1917 params
, render_frame_host
, delegate
.Pass(), cancel_callback
);
1919 profile
->GetHostContentSettingsMap()->UpdateLastUsage(
1920 params
.origin
, params
.origin
, CONTENT_SETTINGS_TYPE_NOTIFICATIONS
);
1926 void ChromeContentBrowserClient::RequestGeolocationPermission(
1927 content::WebContents
* web_contents
,
1929 const GURL
& requesting_frame
,
1931 base::Callback
<void(bool)> result_callback
,
1932 base::Closure
* cancel_callback
) {
1933 GeolocationPermissionContextFactory::GetForProfile(
1934 Profile::FromBrowserContext(web_contents
->GetBrowserContext()))->
1935 RequestGeolocationPermission(web_contents
, bridge_id
,
1936 requesting_frame
, user_gesture
,
1937 result_callback
, cancel_callback
);
1940 void ChromeContentBrowserClient::RequestMidiSysExPermission(
1941 content::WebContents
* web_contents
,
1943 const GURL
& requesting_frame
,
1945 base::Callback
<void(bool)> result_callback
,
1946 base::Closure
* cancel_callback
) {
1947 MidiPermissionContext
* context
=
1948 MidiPermissionContextFactory::GetForProfile(
1949 Profile::FromBrowserContext(web_contents
->GetBrowserContext()));
1950 int renderer_id
= web_contents
->GetRenderProcessHost()->GetID();
1951 int render_view_id
= web_contents
->GetRenderViewHost()->GetRoutingID();
1952 const PermissionRequestID
id(renderer_id
, render_view_id
, bridge_id
, GURL());
1954 context
->RequestPermission(web_contents
, id
, requesting_frame
,
1955 user_gesture
, result_callback
);
1958 void ChromeContentBrowserClient::DidUseGeolocationPermission(
1959 content::WebContents
* web_contents
,
1960 const GURL
& frame_url
,
1961 const GURL
& main_frame_url
) {
1962 Profile::FromBrowserContext(web_contents
->GetBrowserContext())
1963 ->GetHostContentSettingsMap()
1965 frame_url
, main_frame_url
, CONTENT_SETTINGS_TYPE_GEOLOCATION
);
1968 void ChromeContentBrowserClient::RequestProtectedMediaIdentifierPermission(
1969 content::WebContents
* web_contents
,
1971 base::Callback
<void(bool)> result_callback
,
1972 base::Closure
* cancel_callback
) {
1973 #if defined(OS_ANDROID)
1974 ProtectedMediaIdentifierPermissionContext
* context
=
1975 ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(
1976 Profile::FromBrowserContext(web_contents
->GetBrowserContext()));
1977 context
->RequestProtectedMediaIdentifierPermission(web_contents
,
1983 result_callback
.Run(false);
1984 #endif // defined(OS_ANDROID)
1987 bool ChromeContentBrowserClient::CanCreateWindow(
1988 const GURL
& opener_url
,
1989 const GURL
& opener_top_level_frame_url
,
1990 const GURL
& source_origin
,
1991 WindowContainerType container_type
,
1992 const GURL
& target_url
,
1993 const content::Referrer
& referrer
,
1994 WindowOpenDisposition disposition
,
1995 const WebWindowFeatures
& features
,
1997 bool opener_suppressed
,
1998 content::ResourceContext
* context
,
1999 int render_process_id
,
2001 bool* no_javascript_access
) {
2002 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
2004 *no_javascript_access
= false;
2006 // If the opener is trying to create a background window but doesn't have
2007 // the appropriate permission, fail the attempt.
2008 if (container_type
== WINDOW_CONTAINER_TYPE_BACKGROUND
) {
2009 #if defined(ENABLE_EXTENSIONS)
2010 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
2011 InfoMap
* map
= io_data
->GetExtensionInfoMap();
2012 if (!map
->SecurityOriginHasAPIPermission(
2015 APIPermission::kBackground
)) {
2019 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2020 // return a recently installed Extension even if this CanCreateWindow call
2021 // was made by an old copy of the page in a normal web process. That's ok,
2022 // because the permission check above would have caused an early return
2023 // already. We must use the full URL to find hosted apps, though, and not
2025 const Extension
* extension
=
2026 map
->extensions().GetExtensionOrAppByURL(opener_url
);
2027 if (extension
&& !extensions::BackgroundInfo::AllowJSAccess(extension
))
2028 *no_javascript_access
= true;
2034 #if defined(ENABLE_EXTENSIONS)
2035 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
2040 HostContentSettingsMap
* content_settings
=
2041 ProfileIOData::FromResourceContext(context
)->GetHostContentSettingsMap();
2042 BlockedWindowParams
blocked_params(target_url
,
2051 if (!user_gesture
&& !CommandLine::ForCurrentProcess()->HasSwitch(
2052 switches::kDisablePopupBlocking
)) {
2053 if (content_settings
->GetContentSetting(opener_top_level_frame_url
,
2054 opener_top_level_frame_url
,
2055 CONTENT_SETTINGS_TYPE_POPUPS
,
2057 CONTENT_SETTING_ALLOW
) {
2058 BrowserThread::PostTask(BrowserThread::UI
,
2060 base::Bind(&HandleBlockedPopupOnUIThread
,
2066 #if defined(OS_ANDROID)
2067 if (SingleTabModeTabHelper::IsRegistered(render_process_id
, opener_id
)) {
2068 BrowserThread::PostTask(BrowserThread::UI
,
2070 base::Bind(&HandleSingleTabModeBlockOnUIThread
,
2079 void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2080 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
2081 prerender_tracker_
= g_browser_process
->prerender_tracker();
2082 return g_browser_process
->ResourceDispatcherHostCreated();
2085 // TODO(tommi): Rename from Get to Create.
2086 content::SpeechRecognitionManagerDelegate
*
2087 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
2088 return new speech::ChromeSpeechRecognitionManagerDelegate();
2091 net::NetLog
* ChromeContentBrowserClient::GetNetLog() {
2092 return g_browser_process
->net_log();
2095 AccessTokenStore
* ChromeContentBrowserClient::CreateAccessTokenStore() {
2096 return new ChromeAccessTokenStore();
2099 bool ChromeContentBrowserClient::IsFastShutdownPossible() {
2103 void ChromeContentBrowserClient::OverrideWebkitPrefs(
2104 RenderViewHost
* rvh
, const GURL
& url
, WebPreferences
* web_prefs
) {
2105 Profile
* profile
= Profile::FromBrowserContext(
2106 rvh
->GetProcess()->GetBrowserContext());
2107 PrefService
* prefs
= profile
->GetPrefs();
2109 // Fill per-script font preferences. These are not registered on Android
2110 // - http://crbug.com/308033.
2111 #if !defined(OS_ANDROID)
2112 FontFamilyCache::FillFontFamilyMap(profile
,
2113 prefs::kWebKitStandardFontFamilyMap
,
2114 &web_prefs
->standard_font_family_map
);
2115 FontFamilyCache::FillFontFamilyMap(profile
,
2116 prefs::kWebKitFixedFontFamilyMap
,
2117 &web_prefs
->fixed_font_family_map
);
2118 FontFamilyCache::FillFontFamilyMap(profile
,
2119 prefs::kWebKitSerifFontFamilyMap
,
2120 &web_prefs
->serif_font_family_map
);
2121 FontFamilyCache::FillFontFamilyMap(profile
,
2122 prefs::kWebKitSansSerifFontFamilyMap
,
2123 &web_prefs
->sans_serif_font_family_map
);
2124 FontFamilyCache::FillFontFamilyMap(profile
,
2125 prefs::kWebKitCursiveFontFamilyMap
,
2126 &web_prefs
->cursive_font_family_map
);
2127 FontFamilyCache::FillFontFamilyMap(profile
,
2128 prefs::kWebKitFantasyFontFamilyMap
,
2129 &web_prefs
->fantasy_font_family_map
);
2130 FontFamilyCache::FillFontFamilyMap(profile
,
2131 prefs::kWebKitPictographFontFamilyMap
,
2132 &web_prefs
->pictograph_font_family_map
);
2135 web_prefs
->default_font_size
=
2136 prefs
->GetInteger(prefs::kWebKitDefaultFontSize
);
2137 web_prefs
->default_fixed_font_size
=
2138 prefs
->GetInteger(prefs::kWebKitDefaultFixedFontSize
);
2139 web_prefs
->minimum_font_size
=
2140 prefs
->GetInteger(prefs::kWebKitMinimumFontSize
);
2141 web_prefs
->minimum_logical_font_size
=
2142 prefs
->GetInteger(prefs::kWebKitMinimumLogicalFontSize
);
2144 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2146 web_prefs
->javascript_can_open_windows_automatically
=
2147 prefs
->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically
);
2148 web_prefs
->dom_paste_enabled
=
2149 prefs
->GetBoolean(prefs::kWebKitDomPasteEnabled
);
2150 web_prefs
->shrinks_standalone_images_to_fit
=
2151 prefs
->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit
);
2152 web_prefs
->tabs_to_links
= prefs
->GetBoolean(prefs::kWebkitTabsToLinks
);
2154 if (!prefs
->GetBoolean(prefs::kWebKitJavascriptEnabled
))
2155 web_prefs
->javascript_enabled
= false;
2156 if (!prefs
->GetBoolean(prefs::kWebKitWebSecurityEnabled
))
2157 web_prefs
->web_security_enabled
= false;
2158 if (!prefs
->GetBoolean(prefs::kWebKitPluginsEnabled
))
2159 web_prefs
->plugins_enabled
= false;
2160 if (!prefs
->GetBoolean(prefs::kWebKitJavaEnabled
))
2161 web_prefs
->java_enabled
= false;
2162 web_prefs
->loads_images_automatically
=
2163 prefs
->GetBoolean(prefs::kWebKitLoadsImagesAutomatically
);
2165 if (prefs
->GetBoolean(prefs::kDisable3DAPIs
))
2166 web_prefs
->experimental_webgl_enabled
= false;
2168 web_prefs
->allow_displaying_insecure_content
=
2169 prefs
->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent
);
2170 web_prefs
->allow_running_insecure_content
=
2171 prefs
->GetBoolean(prefs::kWebKitAllowRunningInsecureContent
);
2172 #if defined(OS_ANDROID)
2173 web_prefs
->font_scale_factor
=
2174 static_cast<float>(prefs
->GetDouble(prefs::kWebKitFontScaleFactor
));
2175 web_prefs
->device_scale_adjustment
= GetDeviceScaleAdjustment();
2176 web_prefs
->force_enable_zoom
=
2177 prefs
->GetBoolean(prefs::kWebKitForceEnableZoom
);
2180 #if defined(OS_ANDROID)
2181 web_prefs
->password_echo_enabled
=
2182 prefs
->GetBoolean(prefs::kWebKitPasswordEchoEnabled
);
2184 web_prefs
->password_echo_enabled
= browser_defaults::kPasswordEchoEnabled
;
2187 web_prefs
->asynchronous_spell_checking_enabled
= true;
2188 web_prefs
->unified_textchecker_enabled
= true;
2190 web_prefs
->uses_universal_detector
=
2191 prefs
->GetBoolean(prefs::kWebKitUsesUniversalDetector
);
2192 web_prefs
->text_areas_are_resizable
=
2193 prefs
->GetBoolean(prefs::kWebKitTextAreasAreResizable
);
2194 web_prefs
->hyperlink_auditing_enabled
=
2195 prefs
->GetBoolean(prefs::kEnableHyperlinkAuditing
);
2197 // Make sure we will set the default_encoding with canonical encoding name.
2198 web_prefs
->default_encoding
=
2199 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
2200 web_prefs
->default_encoding
);
2201 if (web_prefs
->default_encoding
.empty()) {
2202 prefs
->ClearPref(prefs::kDefaultCharset
);
2203 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2205 DCHECK(!web_prefs
->default_encoding
.empty());
2207 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2208 extra_parts_
[i
]->OverrideWebkitPrefs(rvh
, url
, web_prefs
);
2211 void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2212 BrowserURLHandler
* handler
) {
2213 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2214 extra_parts_
[i
]->BrowserURLHandlerCreated(handler
);
2216 // about: handler. Must come before chrome: handler, since it will
2217 // rewrite about: urls to chrome: URLs and then expect chrome: to
2218 // actually handle them.
2219 handler
->AddHandlerPair(&WillHandleBrowserAboutURL
,
2220 BrowserURLHandler::null_handler());
2222 #if defined(OS_ANDROID)
2223 // Handler to rewrite chrome://newtab on Android.
2224 handler
->AddHandlerPair(&chrome::android::HandleAndroidNewTabURL
,
2225 BrowserURLHandler::null_handler());
2227 // Handler to rewrite chrome://newtab for InstantExtended.
2228 handler
->AddHandlerPair(&chrome::HandleNewTabURLRewrite
,
2229 &chrome::HandleNewTabURLReverseRewrite
);
2232 // chrome: & friends.
2233 handler
->AddHandlerPair(&HandleWebUI
, &HandleWebUIReverse
);
2236 void ChromeContentBrowserClient::ClearCache(RenderViewHost
* rvh
) {
2237 Profile
* profile
= Profile::FromBrowserContext(
2238 rvh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2239 BrowsingDataRemover
* remover
=
2240 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2241 remover
->Remove(BrowsingDataRemover::REMOVE_CACHE
,
2242 BrowsingDataHelper::UNPROTECTED_WEB
);
2243 // BrowsingDataRemover takes care of deleting itself when done.
2246 void ChromeContentBrowserClient::ClearCookies(RenderViewHost
* rvh
) {
2247 Profile
* profile
= Profile::FromBrowserContext(
2248 rvh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2249 BrowsingDataRemover
* remover
=
2250 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2251 int remove_mask
= BrowsingDataRemover::REMOVE_SITE_DATA
;
2252 remover
->Remove(remove_mask
, BrowsingDataHelper::UNPROTECTED_WEB
);
2253 // BrowsingDataRemover takes care of deleting itself when done.
2256 base::FilePath
ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
2257 return DownloadPrefs::GetDefaultDownloadDirectory();
2260 std::string
ChromeContentBrowserClient::GetDefaultDownloadName() {
2261 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME
);
2264 void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2265 content::BrowserPpapiHost
* browser_host
) {
2266 #if defined(ENABLE_PLUGINS)
2267 browser_host
->GetPpapiHost()->AddHostFactoryFilter(
2268 scoped_ptr
<ppapi::host::HostFactory
>(
2269 new ChromeBrowserPepperHostFactory(browser_host
)));
2273 content::BrowserPpapiHost
*
2274 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2275 int plugin_process_id
) {
2276 #if !defined(DISABLE_NACL)
2277 content::BrowserChildProcessHostIterator
iter(PROCESS_TYPE_NACL_LOADER
);
2278 while (!iter
.Done()) {
2279 nacl::NaClProcessHost
* host
= static_cast<nacl::NaClProcessHost
*>(
2280 iter
.GetDelegate());
2281 if (host
->process() &&
2282 host
->process()->GetData().id
== plugin_process_id
) {
2283 // Found the plugin.
2284 return host
->browser_ppapi_host();
2292 bool ChromeContentBrowserClient::AllowPepperSocketAPI(
2293 content::BrowserContext
* browser_context
,
2296 const content::SocketPermissionRequest
* params
) {
2297 #if defined(ENABLE_EXTENSIONS)
2298 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
2299 const extensions::ExtensionSet
* extension_set
= NULL
;
2301 const ExtensionService
* ext_service
=
2302 extensions::ExtensionSystem::Get(profile
)->extension_service();
2304 extension_set
= ext_service
->extensions();
2309 // Access to private socket APIs is controlled by the whitelist.
2310 if (IsExtensionOrSharedModuleWhitelisted(url
, extension_set
,
2311 allowed_socket_origins_
)) {
2315 // Access to public socket APIs is controlled by extension permissions.
2316 if (url
.is_valid() && url
.SchemeIs(extensions::kExtensionScheme
) &&
2318 const Extension
* extension
= extension_set
->GetByID(url
.host());
2320 const extensions::PermissionsData
* permissions_data
=
2321 extension
->permissions_data();
2323 extensions::SocketPermission::CheckParam
check_params(
2324 params
->type
, params
->host
, params
->port
);
2325 if (permissions_data
->CheckAPIPermissionWithParam(
2326 extensions::APIPermission::kSocket
, &check_params
)) {
2329 } else if (permissions_data
->HasAPIPermission(
2330 extensions::APIPermission::kSocket
)) {
2337 // Allow both public and private APIs if the command line says so.
2338 return IsHostAllowedByCommandLine(url
, extension_set
,
2339 switches::kAllowNaClSocketAPI
);
2345 ui::SelectFilePolicy
* ChromeContentBrowserClient::CreateSelectFilePolicy(
2346 WebContents
* web_contents
) {
2347 return new ChromeSelectFilePolicy(web_contents
);
2350 void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2351 std::vector
<std::string
>* additional_allowed_schemes
) {
2352 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2353 additional_allowed_schemes
);
2354 additional_allowed_schemes
->push_back(content::kChromeDevToolsScheme
);
2355 additional_allowed_schemes
->push_back(content::kChromeUIScheme
);
2356 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
2357 extra_parts_
[i
]->GetAdditionalAllowedSchemesForFileSystem(
2358 additional_allowed_schemes
);
2362 void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
2363 std::vector
<storage::URLRequestAutoMountHandler
>* handlers
) {
2364 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2365 extra_parts_
[i
]->GetURLRequestAutoMountHandlers(handlers
);
2368 void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
2369 content::BrowserContext
* browser_context
,
2370 const base::FilePath
& storage_partition_path
,
2371 ScopedVector
<storage::FileSystemBackend
>* additional_backends
) {
2372 #if defined(OS_CHROMEOS)
2373 storage::ExternalMountPoints
* external_mount_points
=
2374 content::BrowserContext::GetMountPoints(browser_context
);
2375 DCHECK(external_mount_points
);
2376 chromeos::FileSystemBackend
* backend
= new chromeos::FileSystemBackend(
2377 new drive::FileSystemBackendDelegate
,
2378 new chromeos::file_system_provider::BackendDelegate
,
2379 new chromeos::MTPFileSystemBackendDelegate(storage_partition_path
),
2380 browser_context
->GetSpecialStoragePolicy(),
2381 external_mount_points
,
2382 storage::ExternalMountPoints::GetSystemInstance());
2383 backend
->AddSystemMountPoints();
2384 DCHECK(backend
->CanHandleType(storage::kFileSystemTypeExternal
));
2385 additional_backends
->push_back(backend
);
2388 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
2389 extra_parts_
[i
]->GetAdditionalFileSystemBackends(
2390 browser_context
, storage_partition_path
, additional_backends
);
2394 #if defined(OS_POSIX) && !defined(OS_MACOSX)
2395 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2396 const CommandLine
& command_line
,
2397 int child_process_id
,
2398 std::vector
<FileDescriptorInfo
>* mappings
) {
2399 #if defined(OS_ANDROID)
2400 base::FilePath data_path
;
2401 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID
, &data_path
);
2402 DCHECK(!data_path
.empty());
2404 int flags
= base::File::FLAG_OPEN
| base::File::FLAG_READ
;
2405 base::FilePath chrome_resources_pak
=
2406 data_path
.AppendASCII("chrome_100_percent.pak");
2407 base::File
file(chrome_resources_pak
, flags
);
2408 DCHECK(file
.IsValid());
2409 mappings
->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor
,
2410 FileDescriptor(file
.Pass())));
2412 const std::string locale
= GetApplicationLocale();
2413 base::FilePath locale_pak
= ResourceBundle::GetSharedInstance().
2414 GetLocaleFilePath(locale
, false);
2415 file
.Initialize(locale_pak
, flags
);
2416 DCHECK(file
.IsValid());
2417 mappings
->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor
,
2418 FileDescriptor(file
.Pass())));
2420 base::FilePath resources_pack_path
;
2421 PathService::Get(chrome::FILE_RESOURCES_PACK
, &resources_pack_path
);
2422 file
.Initialize(resources_pack_path
, flags
);
2423 DCHECK(file
.IsValid());
2424 mappings
->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor
,
2425 FileDescriptor(file
.Pass())));
2427 if (breakpad::IsCrashReporterEnabled()) {
2428 file
= breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile(
2430 if (file
.IsValid()) {
2431 mappings
->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor
,
2432 FileDescriptor(file
.Pass())));
2434 LOG(ERROR
) << "Failed to create file for minidump, crash reporting will "
2435 "be disabled for this process.";
2439 base::FilePath app_data_path
;
2440 PathService::Get(base::DIR_ANDROID_APP_DATA
, &app_data_path
);
2441 DCHECK(!app_data_path
.empty());
2443 flags
= base::File::FLAG_OPEN
| base::File::FLAG_READ
;
2444 base::FilePath icudata_path
=
2445 app_data_path
.AppendASCII("icudtl.dat");
2446 base::File
icudata_file(icudata_path
, flags
);
2447 DCHECK(icudata_file
.IsValid());
2448 mappings
->push_back(FileDescriptorInfo(kAndroidICUDataDescriptor
,
2449 FileDescriptor(icudata_file
.Pass())));
2452 int crash_signal_fd
= GetCrashSignalFD(command_line
);
2453 if (crash_signal_fd
>= 0) {
2454 mappings
->push_back(FileDescriptorInfo(kCrashDumpSignal
,
2455 FileDescriptor(crash_signal_fd
,
2458 #endif // defined(OS_ANDROID)
2460 #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
2463 const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2464 return chrome::kBrowserResourcesDll
;
2467 void ChromeContentBrowserClient::PreSpawnRenderer(
2468 sandbox::TargetPolicy
* policy
,
2470 // This code is duplicated in nacl_exe_win_64.cc.
2471 // Allow the server side of a pipe restricted to the "chrome.nacl."
2472 // namespace so that it cannot impersonate other system or other chrome
2474 sandbox::ResultCode result
= policy
->AddRule(
2475 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES
,
2476 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY
,
2477 L
"\\\\.\\pipe\\chrome.nacl.*");
2478 if (result
!= sandbox::SBOX_ALL_OK
) {
2483 // Renderers need to send named pipe handles and shared memory
2484 // segment handles to NaCl loader processes.
2485 result
= policy
->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES
,
2486 sandbox::TargetPolicy::HANDLES_DUP_ANY
,
2488 if (result
!= sandbox::SBOX_ALL_OK
) {
2495 bool ChromeContentBrowserClient::CheckMediaAccessPermission(
2496 content::BrowserContext
* browser_context
,
2497 const GURL
& security_origin
,
2498 content::MediaStreamType type
) {
2499 return MediaCaptureDevicesDispatcher::GetInstance()
2500 ->CheckMediaAccessPermission(
2501 browser_context
, security_origin
, type
);
2504 content::DevToolsManagerDelegate
*
2505 ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
2506 return new ChromeDevToolsManagerDelegate();
2509 bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2510 content::BrowserContext
* browser_context
,
2512 #if defined(ENABLE_EXTENSIONS)
2513 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
2514 const extensions::ExtensionSet
* extension_set
= NULL
;
2516 const ExtensionService
* ext_service
=
2517 extensions::ExtensionSystem::Get(profile
)->extension_service();
2519 extension_set
= ext_service
->extensions();
2522 return IsExtensionOrSharedModuleWhitelisted(url
, extension_set
,
2523 allowed_file_handle_origins_
) ||
2524 IsHostAllowedByCommandLine(url
, extension_set
,
2525 switches::kAllowNaClFileHandleAPI
);
2531 bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
2532 content::BrowserContext
* browser_context
,
2534 #if defined(ENABLE_EXTENSIONS)
2535 // Allow access for tests.
2536 if (CommandLine::ForCurrentProcess()->HasSwitch(
2537 switches::kEnablePepperTesting
)) {
2541 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
2542 const extensions::ExtensionSet
* extension_set
= NULL
;
2544 const ExtensionService
* ext_service
=
2545 extensions::ExtensionSystem::Get(profile
)->extension_service();
2547 extension_set
= ext_service
->extensions();
2551 // Allow access for whitelisted applications.
2552 if (IsExtensionOrSharedModuleWhitelisted(url
,
2554 allowed_dev_channel_origins_
)) {
2558 chrome::VersionInfo::Channel channel
= chrome::VersionInfo::GetChannel();
2559 // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown"
2560 // releases of Chrome. Permitting "Unknown" allows these APIs to be used on
2561 // Chromium builds as well.
2562 return channel
<= chrome::VersionInfo::CHANNEL_DEV
;
2569 ChromeContentBrowserClient::OverrideCookieStoreForRenderProcess(
2570 int render_process_id
) {
2571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
2572 if (!prerender_tracker_
)
2574 return prerender_tracker_
->GetPrerenderCookieStoreForRenderProcess(
2575 render_process_id
).get();
2578 #if defined(ENABLE_WEBRTC)
2579 void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
2580 CommandLine
* to_command_line
,
2581 const CommandLine
& from_command_line
,
2582 VersionInfo::Channel channel
) {
2583 #if defined(OS_ANDROID)
2584 const VersionInfo::Channel kMaxDisableEncryptionChannel
=
2585 VersionInfo::CHANNEL_BETA
;
2587 const VersionInfo::Channel kMaxDisableEncryptionChannel
=
2588 VersionInfo::CHANNEL_DEV
;
2590 if (channel
<= kMaxDisableEncryptionChannel
) {
2591 static const char* const kWebRtcDevSwitchNames
[] = {
2592 switches::kDisableWebRtcEncryption
,
2594 to_command_line
->CopySwitchesFrom(from_command_line
,
2595 kWebRtcDevSwitchNames
,
2596 arraysize(kWebRtcDevSwitchNames
));
2599 #endif // defined(ENABLE_WEBRTC)
2601 } // namespace chrome