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/bind_helpers.h"
13 #include "base/command_line.h"
14 #include "base/files/scoped_file.h"
15 #include "base/i18n/icu_util.h"
16 #include "base/lazy_instance.h"
17 #include "base/path_service.h"
18 #include "base/prefs/pref_service.h"
19 #include "base/prefs/scoped_user_pref_update.h"
20 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/utf_string_conversions.h"
22 #include "base/threading/sequenced_worker_pool.h"
23 #include "chrome/browser/after_startup_task_utils.h"
24 #include "chrome/browser/browser_about_handler.h"
25 #include "chrome/browser/browser_process.h"
26 #include "chrome/browser/browser_shutdown.h"
27 #include "chrome/browser/browsing_data/browsing_data_helper.h"
28 #include "chrome/browser/browsing_data/browsing_data_remover.h"
29 #include "chrome/browser/character_encoding.h"
30 #include "chrome/browser/chrome_content_browser_client_parts.h"
31 #include "chrome/browser/chrome_net_benchmarking_message_filter.h"
32 #include "chrome/browser/chrome_quota_permission_context.h"
33 #include "chrome/browser/content_settings/cookie_settings.h"
34 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
35 #include "chrome/browser/defaults.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/media/media_capture_devices_dispatcher.h"
40 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
41 #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
42 #include "chrome/browser/net/chrome_net_log.h"
43 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
44 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h"
45 #include "chrome/browser/notifications/platform_notification_service_impl.h"
46 #include "chrome/browser/platform_util.h"
47 #include "chrome/browser/prerender/prerender_final_status.h"
48 #include "chrome/browser/prerender/prerender_manager.h"
49 #include "chrome/browser/prerender/prerender_manager_factory.h"
50 #include "chrome/browser/prerender/prerender_message_filter.h"
51 #include "chrome/browser/printing/printing_message_filter.h"
52 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
53 #include "chrome/browser/profiles/profile.h"
54 #include "chrome/browser/profiles/profile_io_data.h"
55 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
56 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
57 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
58 #include "chrome/browser/safe_browsing/ui_manager.h"
59 #include "chrome/browser/search/instant_service.h"
60 #include "chrome/browser/search/instant_service_factory.h"
61 #include "chrome/browser/search/search.h"
62 #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
63 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
64 #include "chrome/browser/speech/tts_controller.h"
65 #include "chrome/browser/speech/tts_message_filter.h"
66 #include "chrome/browser/ssl/ssl_add_certificate.h"
67 #include "chrome/browser/ssl/ssl_blocking_page.h"
68 #include "chrome/browser/ssl/ssl_cert_reporter.h"
69 #include "chrome/browser/ssl/ssl_client_certificate_selector.h"
70 #include "chrome/browser/ssl/ssl_error_handler.h"
71 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
72 #include "chrome/browser/tab_contents/tab_util.h"
73 #include "chrome/browser/tracing/chrome_tracing_delegate.h"
74 #include "chrome/browser/ui/blocked_content/blocked_window_params.h"
75 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
76 #include "chrome/browser/ui/chrome_select_file_policy.h"
77 #include "chrome/browser/ui/sync/sync_promo_ui.h"
78 #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
79 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
80 #include "chrome/common/chrome_constants.h"
81 #include "chrome/common/chrome_paths.h"
82 #include "chrome/common/chrome_switches.h"
83 #include "chrome/common/env_vars.h"
84 #include "chrome/common/logging_chrome.h"
85 #include "chrome/common/pepper_permission_util.h"
86 #include "chrome/common/pref_names.h"
87 #include "chrome/common/render_messages.h"
88 #include "chrome/common/url_constants.h"
89 #include "chrome/grit/generated_resources.h"
90 #include "chrome/installer/util/google_update_settings.h"
91 #include "chromeos/chromeos_constants.h"
92 #include "components/cdm/browser/cdm_message_filter_android.h"
93 #include "components/cloud_devices/common/cloud_devices_switches.h"
94 #include "components/content_settings/core/browser/content_settings_utils.h"
95 #include "components/content_settings/core/browser/host_content_settings_map.h"
96 #include "components/content_settings/core/common/content_settings.h"
97 #include "components/data_reduction_proxy/content/browser/data_reduction_proxy_message_filter.h"
98 #include "components/dom_distiller/core/url_constants.h"
99 #include "components/google/core/browser/google_util.h"
100 #include "components/metrics/client_info.h"
101 #include "components/pref_registry/pref_registry_syncable.h"
102 #include "components/rappor/rappor_utils.h"
103 #include "components/signin/core/common/profile_management_switches.h"
104 #include "components/translate/core/common/translate_switches.h"
105 #include "components/url_fixer/url_fixer.h"
106 #include "content/public/browser/browser_child_process_host.h"
107 #include "content/public/browser/browser_main_parts.h"
108 #include "content/public/browser/browser_ppapi_host.h"
109 #include "content/public/browser/browser_thread.h"
110 #include "content/public/browser/browser_url_handler.h"
111 #include "content/public/browser/child_process_data.h"
112 #include "content/public/browser/child_process_security_policy.h"
113 #include "content/public/browser/client_certificate_delegate.h"
114 #include "content/public/browser/render_frame_host.h"
115 #include "content/public/browser/render_process_host.h"
116 #include "content/public/browser/render_view_host.h"
117 #include "content/public/browser/resource_context.h"
118 #include "content/public/browser/site_instance.h"
119 #include "content/public/browser/web_contents.h"
120 #include "content/public/common/child_process_host.h"
121 #include "content/public/common/content_descriptors.h"
122 #include "content/public/common/url_utils.h"
123 #include "content/public/common/web_preferences.h"
124 #include "gin/v8_initializer.h"
125 #include "net/base/mime_util.h"
126 #include "net/cookies/canonical_cookie.h"
127 #include "net/cookies/cookie_options.h"
128 #include "net/ssl/ssl_cert_request_info.h"
129 #include "ppapi/host/ppapi_host.h"
130 #include "storage/browser/fileapi/external_mount_points.h"
131 #include "ui/base/l10n/l10n_util.h"
132 #include "ui/base/resource/resource_bundle.h"
133 #include "ui/resources/grit/ui_resources.h"
136 #include "base/win/windows_version.h"
137 #include "chrome/browser/chrome_browser_main_win.h"
138 #include "sandbox/win/src/sandbox_policy.h"
139 #elif defined(OS_MACOSX)
140 #include "chrome/browser/chrome_browser_main_mac.h"
141 #include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
142 #elif defined(OS_CHROMEOS)
143 #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
144 #include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h"
145 #include "chrome/browser/chromeos/file_manager/app_id.h"
146 #include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
147 #include "chrome/browser/chromeos/fileapi/file_system_backend.h"
148 #include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
149 #include "chrome/browser/chromeos/login/startup_utils.h"
150 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
151 #include "chrome/browser/chromeos/system/input_device_settings.h"
152 #include "chromeos/chromeos_switches.h"
153 #include "components/user_manager/user_manager.h"
154 #elif defined(OS_LINUX)
155 #include "chrome/browser/chrome_browser_main_linux.h"
156 #elif defined(OS_ANDROID)
157 #include "chrome/browser/android/new_tab_page_url_handler.h"
158 #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
159 #include "chrome/browser/chrome_browser_main_android.h"
160 #include "chrome/common/descriptors_android.h"
161 #include "components/crash/browser/crash_dump_manager_android.h"
162 #include "components/service_tab_launcher/browser/android/service_tab_launcher.h"
163 #elif defined(OS_POSIX)
164 #include "chrome/browser/chrome_browser_main_posix.h"
167 #if defined(OS_POSIX) && !defined(OS_MACOSX)
168 #include "base/debug/leak_annotations.h"
169 #include "components/crash/app/breakpad_linux.h"
170 #include "components/crash/browser/crash_handler_host_linux.h"
173 #if defined(OS_ANDROID)
174 #include "ui/base/ui_base_paths.h"
175 #include "ui/gfx/android/device_display_info.h"
178 #if defined(OS_ANDROID)
179 #include "chrome/browser/android/dev_tools_manager_delegate_android.h"
181 #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
184 #if defined(TOOLKIT_VIEWS)
185 #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
189 #include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
192 #if defined(USE_AURA)
193 #include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
197 #include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
200 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
201 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
204 #if !defined(DISABLE_NACL)
205 #include "components/nacl/browser/nacl_browser.h"
206 #include "components/nacl/browser/nacl_host_message_filter.h"
207 #include "components/nacl/browser/nacl_process_host.h"
208 #include "components/nacl/common/nacl_process_type.h"
209 #include "components/nacl/common/nacl_switches.h"
212 #if defined(ENABLE_EXTENSIONS)
213 #include "chrome/browser/accessibility/animation_policy_prefs.h"
214 #include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
215 #include "chrome/browser/extensions/extension_util.h"
216 #include "chrome/browser/media/cast_transport_host_filter.h"
217 #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
218 #include "extensions/browser/extension_registry.h"
219 #include "extensions/browser/guest_view/guest_view_base.h"
220 #include "extensions/browser/guest_view/guest_view_manager.h"
221 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
222 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
223 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
224 #include "extensions/common/constants.h"
225 #include "extensions/common/extension.h"
226 #include "extensions/common/extension_set.h"
227 #include "extensions/common/manifest_handlers/background_info.h"
228 #include "extensions/common/manifest_handlers/shared_module_info.h"
229 #include "extensions/common/permissions/permissions_data.h"
230 #include "extensions/common/permissions/socket_permission.h"
231 #include "extensions/common/switches.h"
234 #if defined(ENABLE_PLUGINS)
235 #include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
238 #if defined(ENABLE_SPELLCHECK)
239 #include "chrome/browser/spellchecker/spellcheck_message_filter.h"
242 #if defined(ENABLE_WEBRTC)
243 #include "chrome/browser/media/webrtc_logging_handler_host.h"
246 using base::FileDescriptor
;
247 using blink::WebWindowFeatures
;
248 using content::AccessTokenStore
;
249 using content::BrowserThread
;
250 using content::BrowserURLHandler
;
251 using content::ChildProcessSecurityPolicy
;
252 using content::QuotaPermissionContext
;
253 using content::RenderFrameHost
;
254 using content::RenderViewHost
;
255 using content::ResourceType
;
256 using content::SiteInstance
;
257 using content::WebContents
;
258 using content::WebPreferences
;
259 using message_center::NotifierId
;
261 #if defined(OS_POSIX)
262 using content::FileDescriptorInfo
;
265 #if defined(ENABLE_EXTENSIONS)
266 using extensions::APIPermission
;
267 using extensions::ChromeContentBrowserClientExtensionsPart
;
268 using extensions::Extension
;
269 using extensions::InfoMap
;
270 using extensions::Manifest
;
273 #if defined(ENABLE_PLUGINS)
274 using plugins::ChromeContentBrowserClientPluginsPart
;
279 // Cached version of the locale so we can return the locale on the I/O
281 base::LazyInstance
<std::string
> g_io_thread_application_locale
;
283 #if defined(ENABLE_PLUGINS)
284 // TODO(teravest): Add renderer-side API-specific checking for these APIs so
285 // that blanket permission isn't granted to all dev channel APIs for these.
286 // http://crbug.com/386743
287 const char* const kPredefinedAllowedDevChannelOrigins
[] = {
288 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/383937
289 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/383937
292 const char* const kPredefinedAllowedFileHandleOrigins
[] = {
293 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
294 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
297 const char* const kPredefinedAllowedSocketOrigins
[] = {
298 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
299 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
300 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
301 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
302 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
303 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
304 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
305 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
306 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
307 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
308 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
309 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
310 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
311 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
312 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
313 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
314 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
315 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
316 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
317 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
321 // Returns a copy of the given url with its host set to given host and path set
322 // to given path. Other parts of the url will be the same.
323 GURL
ReplaceURLHostAndPath(const GURL
& url
,
324 const std::string
& host
,
325 const std::string
& path
) {
326 url::Replacements
<char> replacements
;
327 replacements
.SetHost(host
.c_str(), url::Component(0, host
.length()));
328 replacements
.SetPath(path
.c_str(), url::Component(0, path
.length()));
329 return url
.ReplaceComponents(replacements
);
332 // Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
333 GURL
AddUberHost(const GURL
& url
) {
334 const std::string uber_host
= chrome::kChromeUIUberHost
;
335 const std::string new_path
= url
.host() + url
.path();
337 return ReplaceURLHostAndPath(url
, uber_host
, new_path
);
340 // If url->host() is "chrome" and url->path() has characters other than the
341 // first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
342 // returns true. Otherwise returns false.
343 bool RemoveUberHost(GURL
* url
) {
344 if (url
->host() != chrome::kChromeUIUberHost
)
347 if (url
->path().empty() || url
->path() == "/")
350 const std::string old_path
= url
->path();
352 const std::string::size_type separator
= old_path
.find('/', 1);
353 std::string new_host
;
354 std::string new_path
;
355 if (separator
== std::string::npos
) {
356 new_host
= old_path
.substr(1);
358 new_host
= old_path
.substr(1, separator
- 1);
359 new_path
= old_path
.substr(separator
);
362 // Do not allow URLs with paths empty before the first slash since we can't
363 // have an empty host. (e.g "foo://chrome//")
364 if (new_host
.empty())
367 *url
= ReplaceURLHostAndPath(*url
, new_host
, new_path
);
369 DCHECK(url
->is_valid());
374 // Handles rewriting Web UI URLs.
375 bool HandleWebUI(GURL
* url
, content::BrowserContext
* browser_context
) {
376 // Do not handle special URLs such as "about:foo"
377 if (!url
->host().empty()) {
378 const GURL chrome_url
= AddUberHost(*url
);
380 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
382 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
383 browser_context
, chrome_url
))
387 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
388 browser_context
, *url
))
391 #if defined(OS_CHROMEOS)
392 // Special case : in ChromeOS in Guest mode bookmarks and history are
393 // disabled for security reasons. New tab page explains the reasons, so
394 // we redirect user to new tab page.
395 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
396 if (url
->SchemeIs(content::kChromeUIScheme
) &&
397 (url
->DomainIs(chrome::kChromeUIBookmarksHost
) ||
398 url
->DomainIs(chrome::kChromeUIHistoryHost
))) {
399 // Rewrite with new tab URL
400 *url
= GURL(chrome::kChromeUINewTabURL
);
408 // Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
410 bool HandleWebUIReverse(GURL
* url
, content::BrowserContext
* browser_context
) {
411 if (!url
->is_valid() || !url
->SchemeIs(content::kChromeUIScheme
))
414 return RemoveUberHost(url
);
417 bool CertMatchesFilter(const net::X509Certificate
& cert
,
418 const base::DictionaryValue
& filter
) {
419 // TODO(markusheintz): This is the minimal required filter implementation.
420 // Implement a better matcher.
422 // An empty filter matches any client certificate since no requirements are
427 std::string common_name
;
428 if (filter
.GetString("ISSUER.CN", &common_name
) &&
429 (cert
.issuer().common_name
== common_name
)) {
435 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
436 breakpad::CrashHandlerHostLinux
* CreateCrashHandlerHost(
437 const std::string
& process_type
) {
438 base::FilePath dumps_path
;
439 PathService::Get(chrome::DIR_CRASH_DUMPS
, &dumps_path
);
441 ANNOTATE_SCOPED_MEMORY_LEAK
;
442 bool upload
= (getenv(env_vars::kHeadless
) == NULL
);
443 breakpad::CrashHandlerHostLinux
* crash_handler
=
444 new breakpad::CrashHandlerHostLinux(process_type
, dumps_path
, upload
);
445 crash_handler
->StartUploaderThread();
446 return crash_handler
;
450 int GetCrashSignalFD(const base::CommandLine
& command_line
) {
451 // Extensions have the same process type as renderers.
452 if (command_line
.HasSwitch(extensions::switches::kExtensionProcess
)) {
453 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
455 crash_handler
= CreateCrashHandlerHost("extension");
456 return crash_handler
->GetDeathSignalSocket();
459 std::string process_type
=
460 command_line
.GetSwitchValueASCII(switches::kProcessType
);
462 if (process_type
== switches::kRendererProcess
) {
463 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
465 crash_handler
= CreateCrashHandlerHost(process_type
);
466 return crash_handler
->GetDeathSignalSocket();
469 if (process_type
== switches::kPluginProcess
) {
470 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
472 crash_handler
= CreateCrashHandlerHost(process_type
);
473 return crash_handler
->GetDeathSignalSocket();
476 if (process_type
== switches::kPpapiPluginProcess
) {
477 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
479 crash_handler
= CreateCrashHandlerHost(process_type
);
480 return crash_handler
->GetDeathSignalSocket();
483 if (process_type
== switches::kGpuProcess
) {
484 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
486 crash_handler
= CreateCrashHandlerHost(process_type
);
487 return crash_handler
->GetDeathSignalSocket();
492 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
494 void SetApplicationLocaleOnIOThread(const std::string
& locale
) {
495 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
496 g_io_thread_application_locale
.Get() = locale
;
499 void HandleBlockedPopupOnUIThread(const BlockedWindowParams
& params
) {
500 // TODO(jochen): This code path should use RenderFrameHosts. See
501 // http://crbug.com/431769 for details.
502 RenderViewHost
* render_view_host
=
503 RenderViewHost::FromID(params
.render_process_id(), params
.opener_id());
504 if (!render_view_host
)
506 WebContents
* tab
= WebContents::FromRenderViewHost(render_view_host
);
507 // The tab might already have navigated away.
508 if (!tab
|| tab
->GetRenderViewHost() != render_view_host
)
511 prerender::PrerenderContents
* prerender_contents
=
512 prerender::PrerenderContents::FromWebContents(tab
);
513 if (prerender_contents
) {
514 prerender_contents
->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW
);
518 PopupBlockerTabHelper
* popup_helper
=
519 PopupBlockerTabHelper::FromWebContents(tab
);
522 popup_helper
->AddBlockedPopup(params
);
525 // An implementation of the SSLCertReporter interface used by
526 // SSLErrorHandler. Uses the SafeBrowsing UI manager to send invalid
527 // certificate reports.
528 class SafeBrowsingSSLCertReporter
: public SSLCertReporter
{
530 explicit SafeBrowsingSSLCertReporter(
531 const scoped_refptr
<SafeBrowsingUIManager
>& safe_browsing_ui_manager
)
532 : safe_browsing_ui_manager_(safe_browsing_ui_manager
) {}
533 ~SafeBrowsingSSLCertReporter() override
{}
535 // SSLCertReporter implementation
536 void ReportInvalidCertificateChain(const std::string
& hostname
,
537 const net::SSLInfo
& ssl_info
) override
{
538 if (safe_browsing_ui_manager_
) {
539 safe_browsing_ui_manager_
->ReportInvalidCertificateChain(
540 hostname
, ssl_info
, base::Bind(&base::DoNothing
));
545 const scoped_refptr
<SafeBrowsingUIManager
> safe_browsing_ui_manager_
;
548 #if defined(OS_ANDROID)
550 void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams
& params
) {
551 WebContents
* web_contents
=
552 tab_util::GetWebContentsByID(params
.render_process_id(),
557 SingleTabModeTabHelper::FromWebContents(web_contents
)->HandleOpenUrl(params
);
560 float GetDeviceScaleAdjustment() {
561 static const float kMinFSM
= 1.05f
;
562 static const int kWidthForMinFSM
= 320;
563 static const float kMaxFSM
= 1.3f
;
564 static const int kWidthForMaxFSM
= 800;
566 gfx::DeviceDisplayInfo info
;
567 int minWidth
= info
.GetSmallestDIPWidth();
569 if (minWidth
<= kWidthForMinFSM
)
571 if (minWidth
>= kWidthForMaxFSM
)
574 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
575 float ratio
= static_cast<float>(minWidth
- kWidthForMinFSM
) /
576 (kWidthForMaxFSM
- kWidthForMinFSM
);
577 return ratio
* (kMaxFSM
- kMinFSM
) + kMinFSM
;
580 #endif // defined(OS_ANDROID)
582 #if defined(ENABLE_EXTENSIONS)
583 // By default, JavaScript and images are enabled in guest content.
584 void GetGuestViewDefaultContentSettingRules(
586 RendererContentSettingRules
* rules
) {
587 rules
->image_rules
.push_back(
588 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
589 ContentSettingsPattern::Wildcard(),
590 CONTENT_SETTING_ALLOW
,
594 rules
->script_rules
.push_back(
595 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
596 ContentSettingsPattern::Wildcard(),
597 CONTENT_SETTING_ALLOW
,
601 #endif // defined(ENABLE_EXTENSIONS)
607 ChromeContentBrowserClient::ChromeContentBrowserClient()
609 #if defined(OS_POSIX) && !defined(OS_MACOSX)
612 #endif // OS_POSIX && !OS_MACOSX
613 weak_factory_(this) {
614 #if defined(ENABLE_PLUGINS)
615 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedDevChannelOrigins
); ++i
)
616 allowed_dev_channel_origins_
.insert(kPredefinedAllowedDevChannelOrigins
[i
]);
617 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedFileHandleOrigins
); ++i
)
618 allowed_file_handle_origins_
.insert(kPredefinedAllowedFileHandleOrigins
[i
]);
619 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedSocketOrigins
); ++i
)
620 allowed_socket_origins_
.insert(kPredefinedAllowedSocketOrigins
[i
]);
622 extra_parts_
.push_back(new ChromeContentBrowserClientPluginsPart
);
625 #if !defined(OS_ANDROID)
626 TtsExtensionEngine
* tts_extension_engine
= TtsExtensionEngine::GetInstance();
627 TtsController::GetInstance()->SetTtsEngineDelegate(tts_extension_engine
);
630 #if defined(ENABLE_EXTENSIONS)
631 extra_parts_
.push_back(new ChromeContentBrowserClientExtensionsPart
);
635 ChromeContentBrowserClient::~ChromeContentBrowserClient() {
636 for (int i
= static_cast<int>(extra_parts_
.size()) - 1; i
>= 0; --i
)
637 delete extra_parts_
[i
];
638 extra_parts_
.clear();
642 void ChromeContentBrowserClient::RegisterProfilePrefs(
643 user_prefs::PrefRegistrySyncable
* registry
) {
644 registry
->RegisterBooleanPref(
645 prefs::kDisable3DAPIs
,
647 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
648 registry
->RegisterBooleanPref(
649 prefs::kEnableHyperlinkAuditing
,
651 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
652 registry
->RegisterListPref(
653 prefs::kEnableDeprecatedWebPlatformFeatures
,
654 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
658 void ChromeContentBrowserClient::SetApplicationLocale(
659 const std::string
& locale
) {
660 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
662 // This object is guaranteed to outlive all threads so we don't have to
663 // worry about the lack of refcounting and can just post as Unretained.
665 // The common case is that this function is called early in Chrome startup
666 // before any threads are created (it will also be called later if the user
667 // changes the pref). In this case, there will be no threads created and
668 // posting will fail. When there are no threads, we can just set the string
669 // without worrying about threadsafety.
670 if (!BrowserThread::PostTask(BrowserThread::IO
, FROM_HERE
,
671 base::Bind(&SetApplicationLocaleOnIOThread
, locale
))) {
672 g_io_thread_application_locale
.Get() = locale
;
676 content::BrowserMainParts
* ChromeContentBrowserClient::CreateBrowserMainParts(
677 const content::MainFunctionParams
& parameters
) {
678 ChromeBrowserMainParts
* main_parts
;
679 // Construct the Main browser parts based on the OS type.
681 main_parts
= new ChromeBrowserMainPartsWin(parameters
);
682 #elif defined(OS_MACOSX)
683 main_parts
= new ChromeBrowserMainPartsMac(parameters
);
684 #elif defined(OS_CHROMEOS)
685 main_parts
= new chromeos::ChromeBrowserMainPartsChromeos(parameters
);
686 #elif defined(OS_LINUX)
687 main_parts
= new ChromeBrowserMainPartsLinux(parameters
);
688 #elif defined(OS_ANDROID)
689 main_parts
= new ChromeBrowserMainPartsAndroid(parameters
);
690 #elif defined(OS_POSIX)
691 main_parts
= new ChromeBrowserMainPartsPosix(parameters
);
694 main_parts
= new ChromeBrowserMainParts(parameters
);
697 chrome::AddProfilesExtraParts(main_parts
);
699 // Construct additional browser parts. Stages are called in the order in
700 // which they are added.
701 #if defined(TOOLKIT_VIEWS)
702 main_parts
->AddParts(new ChromeBrowserMainExtraPartsViews());
705 // TODO(oshima): Athena on chrome currently requires USE_ASH to build.
706 // We should reduce the dependency as much as possible.
708 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAsh());
711 #if defined(USE_AURA)
712 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAura());
716 main_parts
->AddParts(new ChromeBrowserMainExtraPartsX11());
719 chrome::AddMetricsExtraParts(main_parts
);
724 void ChromeContentBrowserClient::PostAfterStartupTask(
725 const tracked_objects::Location
& from_here
,
726 const scoped_refptr
<base::TaskRunner
>& task_runner
,
727 const base::Closure
& task
) {
728 AfterStartupTaskUtils::PostTask(from_here
, task_runner
, task
);
731 std::string
ChromeContentBrowserClient::GetStoragePartitionIdForSite(
732 content::BrowserContext
* browser_context
,
734 std::string partition_id
;
736 // The partition ID for webview guest processes is the string value of its
737 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
738 if (site
.SchemeIs(content::kGuestScheme
)) {
739 partition_id
= site
.spec();
740 } else if (!switches::IsEnableWebviewBasedSignin() &&
741 site
.GetOrigin().spec() == kChromeUIChromeSigninURL
) {
742 // The non-webview Chrome signin page has an embedded iframe of extension
743 // and web content, thus it must be isolated from other webUI pages.
744 partition_id
= site
.GetOrigin().spec();
747 DCHECK(IsValidStoragePartitionId(browser_context
, partition_id
));
751 bool ChromeContentBrowserClient::IsValidStoragePartitionId(
752 content::BrowserContext
* browser_context
,
753 const std::string
& partition_id
) {
754 // The default ID is empty and is always valid.
755 if (partition_id
.empty())
758 return GURL(partition_id
).is_valid();
761 void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
762 content::BrowserContext
* browser_context
,
765 std::string
* partition_domain
,
766 std::string
* partition_name
,
768 // Default to the browser-wide storage partition and override based on |site|
770 partition_domain
->clear();
771 partition_name
->clear();
774 bool success
= false;
775 #if defined(ENABLE_EXTENSIONS)
776 success
= extensions::WebViewGuest::GetGuestPartitionConfigForSite(
777 site
, partition_domain
, partition_name
, in_memory
);
779 if (!success
&& site
.SchemeIs(extensions::kExtensionScheme
)) {
780 // If |can_be_default| is false, the caller is stating that the |site|
781 // should be parsed as if it had isolated storage. In particular it is
782 // important to NOT check ExtensionService for the is_storage_isolated()
783 // attribute because this code path is run during Extension uninstall
784 // to do cleanup after the Extension has already been unloaded from the
786 bool is_isolated
= !can_be_default
;
787 if (can_be_default
) {
788 if (extensions::util::SiteHasIsolatedStorage(site
, browser_context
))
793 CHECK(site
.has_host());
794 // For extensions with isolated storage, the the host of the |site| is
795 // the |partition_domain|. The |in_memory| and |partition_name| are only
796 // used in guest schemes so they are cleared here.
797 *partition_domain
= site
.host();
799 partition_name
->clear();
805 if (!success
&& (!switches::IsEnableWebviewBasedSignin() &&
806 site
.GetOrigin().spec() == kChromeUIChromeSigninURL
)) {
807 // The non-webview Chrome signin page has an embedded iframe of extension
808 // and web content, thus it must be isolated from other webUI pages.
809 *partition_domain
= chrome::kChromeUIChromeSigninHost
;
812 // Assert that if |can_be_default| is false, the code above must have found a
813 // non-default partition. If this fails, the caller has a serious logic
814 // error about which StoragePartition they expect to be in and it is not
816 CHECK(can_be_default
|| !partition_domain
->empty());
819 content::WebContentsViewDelegate
*
820 ChromeContentBrowserClient::GetWebContentsViewDelegate(
821 content::WebContents
* web_contents
) {
822 return chrome::CreateWebContentsViewDelegate(web_contents
);
825 void ChromeContentBrowserClient::RenderProcessWillLaunch(
826 content::RenderProcessHost
* host
) {
827 int id
= host
->GetID();
828 Profile
* profile
= Profile::FromBrowserContext(host
->GetBrowserContext());
829 net::URLRequestContextGetter
* context
=
830 profile
->GetRequestContextForRenderProcess(id
);
832 host
->AddFilter(new ChromeRenderMessageFilter(id
, profile
));
833 #if defined(ENABLE_EXTENSIONS)
834 host
->AddFilter(new cast::CastTransportHostFilter
);
836 #if defined(ENABLE_PRINTING)
837 host
->AddFilter(new printing::PrintingMessageFilter(id
, profile
));
839 host
->AddFilter(new SearchProviderInstallStateMessageFilter(id
, profile
));
840 #if defined(ENABLE_SPELLCHECK)
841 host
->AddFilter(new SpellCheckMessageFilter(id
));
843 #if defined(OS_MACOSX)
844 host
->AddFilter(new SpellCheckMessageFilterMac(id
));
846 host
->AddFilter(new ChromeNetBenchmarkingMessageFilter(profile
, context
));
847 host
->AddFilter(new prerender::PrerenderMessageFilter(id
, profile
));
848 host
->AddFilter(new TtsMessageFilter(host
->GetBrowserContext()));
849 #if defined(ENABLE_WEBRTC)
850 WebRtcLoggingHandlerHost
* webrtc_logging_handler_host
=
851 new WebRtcLoggingHandlerHost(profile
);
852 host
->SetWebRtcLogMessageCallback(base::Bind(
853 &WebRtcLoggingHandlerHost::LogMessage
, webrtc_logging_handler_host
));
854 host
->AddFilter(webrtc_logging_handler_host
);
855 host
->SetUserData(host
, new base::UserDataAdapter
<WebRtcLoggingHandlerHost
>(
856 webrtc_logging_handler_host
));
858 #if !defined(DISABLE_NACL)
859 host
->AddFilter(new nacl::NaClHostMessageFilter(
860 id
, profile
->IsOffTheRecord(),
864 #if defined(OS_ANDROID)
865 host
->AddFilter(new cdm::CdmMessageFilterAndroid());
867 DataReductionProxyChromeSettings
* data_reduction_proxy_settings
=
868 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(profile
);
869 host
->AddFilter(new data_reduction_proxy::DataReductionProxyMessageFilter(
870 data_reduction_proxy_settings
));
872 host
->Send(new ChromeViewMsg_SetIsIncognitoProcess(
873 profile
->IsOffTheRecord()));
875 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
876 extra_parts_
[i
]->RenderProcessWillLaunch(host
);
878 RendererContentSettingRules rules
;
879 if (host
->IsIsolatedGuest()) {
880 #if defined(ENABLE_EXTENSIONS)
881 GetGuestViewDefaultContentSettingRules(profile
->IsOffTheRecord(), &rules
);
886 GetRendererContentSettingRules(
887 profile
->GetHostContentSettingsMap(), &rules
);
889 host
->Send(new ChromeViewMsg_SetContentSettingRules(rules
));
892 GURL
ChromeContentBrowserClient::GetEffectiveURL(
893 content::BrowserContext
* browser_context
, const GURL
& url
) {
894 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
898 // If the input |url| should be assigned to the Instant renderer, make its
899 // effective URL distinct from other URLs on the search provider's domain.
900 if (chrome::ShouldAssignURLToInstantRenderer(url
, profile
))
901 return chrome::GetEffectiveURLForInstant(url
, profile
);
903 #if defined(ENABLE_EXTENSIONS)
904 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(
911 bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
912 content::BrowserContext
* browser_context
, const GURL
& effective_url
) {
913 // Non-extension, non-Instant URLs should generally use
914 // process-per-site-instance. Because we expect to use the effective URL,
915 // URLs for hosted apps (apart from bookmark apps) should have an extension
918 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
922 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url
, profile
))
925 #if defined(ENABLE_EXTENSIONS)
926 return ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
927 profile
, effective_url
);
933 // These are treated as WebUI schemes but do not get WebUI bindings. Also,
934 // view-source is allowed for these schemes.
935 void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
936 std::vector
<std::string
>* additional_schemes
) {
937 additional_schemes
->push_back(chrome::kChromeSearchScheme
);
938 additional_schemes
->push_back(dom_distiller::kDomDistillerScheme
);
941 void ChromeContentBrowserClient::GetAdditionalWebUIHostsToIgnoreParititionCheck(
942 std::vector
<std::string
>* hosts
) {
943 hosts
->push_back(chrome::kChromeUIExtensionIconHost
);
944 hosts
->push_back(chrome::kChromeUIFaviconHost
);
945 hosts
->push_back(chrome::kChromeUIThemeHost
);
946 hosts
->push_back(chrome::kChromeUIThumbnailHost
);
947 hosts
->push_back(chrome::kChromeUIThumbnailHost2
);
948 hosts
->push_back(chrome::kChromeUIThumbnailListHost
);
951 net::URLRequestContextGetter
*
952 ChromeContentBrowserClient::CreateRequestContext(
953 content::BrowserContext
* browser_context
,
954 content::ProtocolHandlerMap
* protocol_handlers
,
955 content::URLRequestInterceptorScopedVector request_interceptors
) {
956 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
957 return profile
->CreateRequestContext(protocol_handlers
,
958 request_interceptors
.Pass());
961 net::URLRequestContextGetter
*
962 ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
963 content::BrowserContext
* browser_context
,
964 const base::FilePath
& partition_path
,
966 content::ProtocolHandlerMap
* protocol_handlers
,
967 content::URLRequestInterceptorScopedVector request_interceptors
) {
968 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
969 return profile
->CreateRequestContextForStoragePartition(
973 request_interceptors
.Pass());
976 bool ChromeContentBrowserClient::IsHandledURL(const GURL
& url
) {
977 return ProfileIOData::IsHandledURL(url
);
980 bool ChromeContentBrowserClient::CanCommitURL(
981 content::RenderProcessHost
* process_host
,
983 #if defined(ENABLE_EXTENSIONS)
984 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(
991 bool ChromeContentBrowserClient::ShouldAllowOpenURL(
992 content::SiteInstance
* site_instance
, const GURL
& url
) {
993 GURL from_url
= site_instance
->GetSiteURL();
995 #if defined(ENABLE_EXTENSIONS)
997 if (ChromeContentBrowserClientExtensionsPart::ShouldAllowOpenURL(
998 site_instance
, from_url
, url
, &result
))
1002 // Do not allow chrome://chrome-signin navigate to other chrome:// URLs, since
1003 // the signin page may host untrusted web content.
1004 if (from_url
.GetOrigin().spec() == chrome::kChromeUIChromeSigninURL
&&
1005 url
.SchemeIs(content::kChromeUIScheme
) &&
1006 url
.host() != chrome::kChromeUIChromeSigninHost
) {
1007 VLOG(1) << "Blocked navigation to " << url
.spec() << " from "
1008 << chrome::kChromeUIChromeSigninURL
;
1015 bool ChromeContentBrowserClient::IsSuitableHost(
1016 content::RenderProcessHost
* process_host
,
1017 const GURL
& site_url
) {
1019 Profile::FromBrowserContext(process_host
->GetBrowserContext());
1020 // This may be NULL during tests. In that case, just assume any site can
1025 // Instant URLs should only be in the instant process and instant process
1026 // should only have Instant URLs.
1027 InstantService
* instant_service
=
1028 InstantServiceFactory::GetForProfile(profile
);
1029 if (instant_service
) {
1030 bool is_instant_process
= instant_service
->IsInstantProcess(
1031 process_host
->GetID());
1032 bool should_be_in_instant_process
=
1033 chrome::ShouldAssignURLToInstantRenderer(site_url
, profile
);
1034 if (is_instant_process
|| should_be_in_instant_process
)
1035 return is_instant_process
&& should_be_in_instant_process
;
1038 #if defined(ENABLE_EXTENSIONS)
1039 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1040 profile
, process_host
, site_url
);
1046 bool ChromeContentBrowserClient::MayReuseHost(
1047 content::RenderProcessHost
* process_host
) {
1048 // If there is currently a prerender in progress for the host provided,
1049 // it may not be shared. We require prerenders to be by themselves in a
1050 // separate process so that we can monitor their resource usage.
1051 Profile
* profile
= Profile::FromBrowserContext(
1052 process_host
->GetBrowserContext());
1053 prerender::PrerenderManager
* prerender_manager
=
1054 prerender::PrerenderManagerFactory::GetForProfile(profile
);
1055 if (prerender_manager
&&
1056 !prerender_manager
->MayReuseProcessHost(process_host
)) {
1063 bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1064 content::BrowserContext
* browser_context
, const GURL
& url
) {
1065 // It has to be a valid URL for us to check for an extension.
1066 if (!url
.is_valid())
1069 #if defined(ENABLE_EXTENSIONS)
1070 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1071 return ChromeContentBrowserClientExtensionsPart::
1072 ShouldTryToUseExistingProcessHost(
1079 void ChromeContentBrowserClient::SiteInstanceGotProcess(
1080 SiteInstance
* site_instance
) {
1081 CHECK(site_instance
->HasProcess());
1083 Profile
* profile
= Profile::FromBrowserContext(
1084 site_instance
->GetBrowserContext());
1088 // Remember the ID of the Instant process to signal the renderer process
1089 // on startup in |AppendExtraCommandLineSwitches| below.
1090 if (chrome::ShouldAssignURLToInstantRenderer(
1091 site_instance
->GetSiteURL(), profile
)) {
1092 InstantService
* instant_service
=
1093 InstantServiceFactory::GetForProfile(profile
);
1094 if (instant_service
)
1095 instant_service
->AddInstantProcess(site_instance
->GetProcess()->GetID());
1098 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
1099 extra_parts_
[i
]->SiteInstanceGotProcess(site_instance
);
1102 void ChromeContentBrowserClient::SiteInstanceDeleting(
1103 SiteInstance
* site_instance
) {
1104 if (!site_instance
->HasProcess())
1107 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
1108 extra_parts_
[i
]->SiteInstanceDeleting(site_instance
);
1111 bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
1112 SiteInstance
* site_instance
,
1113 const GURL
& current_url
,
1114 const GURL
& new_url
) {
1115 #if defined(ENABLE_EXTENSIONS)
1116 return ChromeContentBrowserClientExtensionsPart::
1117 ShouldSwapBrowsingInstancesForNavigation(
1118 site_instance
, current_url
, new_url
);
1124 bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1125 content::ResourceContext
* resource_context
, const GURL
& current_url
,
1126 const GURL
& new_url
) {
1127 #if defined(ENABLE_EXTENSIONS)
1128 return ChromeContentBrowserClientExtensionsPart::
1129 ShouldSwapProcessesForRedirect(resource_context
, current_url
, new_url
);
1135 bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL
& url
) {
1136 return !url
.SchemeIs(chrome::kChromeNativeScheme
);
1139 std::string
ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1140 const std::string
& alias_name
) {
1141 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name
);
1146 bool IsAutoReloadEnabled() {
1147 // Fetch the field trial, even though we don't use it. Calling FindFullName()
1148 // causes the field-trial mechanism to report which group we're in, which
1149 // might reflect a hard disable or hard enable via flag, both of which have
1150 // their own field trial groups. This lets us know what percentage of users
1151 // manually enable or disable auto-reload.
1152 std::string group
= base::FieldTrialList::FindFullName(
1153 "AutoReloadExperiment");
1154 const base::CommandLine
& browser_command_line
=
1155 *base::CommandLine::ForCurrentProcess();
1156 if (browser_command_line
.HasSwitch(switches::kEnableOfflineAutoReload
))
1158 if (browser_command_line
.HasSwitch(switches::kDisableOfflineAutoReload
))
1163 bool IsAutoReloadVisibleOnlyEnabled() {
1164 // See the block comment in IsAutoReloadEnabled().
1165 std::string group
= base::FieldTrialList::FindFullName(
1166 "AutoReloadVisibleOnlyExperiment");
1167 const base::CommandLine
& browser_command_line
=
1168 *base::CommandLine::ForCurrentProcess();
1169 if (browser_command_line
.HasSwitch(
1170 switches::kEnableOfflineAutoReloadVisibleOnly
)) {
1173 if (browser_command_line
.HasSwitch(
1174 switches::kDisableOfflineAutoReloadVisibleOnly
)) {
1182 void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1183 base::CommandLine
* command_line
,
1184 int child_process_id
) {
1185 #if defined(OS_MACOSX)
1186 scoped_ptr
<metrics::ClientInfo
> client_info
=
1187 GoogleUpdateSettings::LoadMetricsClientInfo();
1189 command_line
->AppendSwitchASCII(switches::kMetricsClientID
,
1190 client_info
->client_id
);
1192 #elif defined(OS_POSIX)
1193 if (breakpad::IsCrashReporterEnabled()) {
1194 scoped_ptr
<metrics::ClientInfo
> client_info
=
1195 GoogleUpdateSettings::LoadMetricsClientInfo();
1196 command_line
->AppendSwitchASCII(switches::kEnableCrashReporter
,
1197 client_info
? client_info
->client_id
1202 if (logging::DialogsAreSuppressed())
1203 command_line
->AppendSwitch(switches::kNoErrorDialogs
);
1205 std::string process_type
=
1206 command_line
->GetSwitchValueASCII(switches::kProcessType
);
1207 const base::CommandLine
& browser_command_line
=
1208 *base::CommandLine::ForCurrentProcess();
1210 static const char* const kCommonSwitchNames
[] = {
1211 switches::kUserAgent
,
1212 switches::kUserDataDir
, // Make logs go to the right file.
1214 command_line
->CopySwitchesFrom(browser_command_line
, kCommonSwitchNames
,
1215 arraysize(kCommonSwitchNames
));
1217 #if defined(ENABLE_IPC_FUZZER)
1218 static const char* const kIpcFuzzerSwitches
[] = {
1219 switches::kIpcDumpDirectory
,
1220 switches::kIpcFuzzerTestcase
,
1222 command_line
->CopySwitchesFrom(browser_command_line
, kIpcFuzzerSwitches
,
1223 arraysize(kIpcFuzzerSwitches
));
1226 #if defined(OS_CHROMEOS)
1227 static const char* const kChromeOSSwitches
[] = {
1228 switches::kDisableDinosaurEasterEgg
,
1230 command_line
->CopySwitchesFrom(browser_command_line
, kChromeOSSwitches
,
1231 arraysize(kChromeOSSwitches
));
1233 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
1234 base::FilePath homedir
;
1235 PathService::Get(base::DIR_HOME
, &homedir
);
1236 command_line
->AppendSwitchASCII(chromeos::switches::kHomedir
,
1237 homedir
.value().c_str());
1240 #if defined(OS_POSIX) && !defined(OS_MACOSX)
1241 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
1242 if (process_type
!= switches::kZygoteProcess
) {
1243 command_line
->AppendSwitch(::switches::kV8NativesPassedByFD
);
1244 command_line
->AppendSwitch(::switches::kV8SnapshotPassedByFD
);
1246 #endif // V8_USE_EXTERNAL_STARTUP_DATA
1247 #endif // OS_POSIX && !OS_MACOSX
1249 if (process_type
== switches::kRendererProcess
) {
1250 content::RenderProcessHost
* process
=
1251 content::RenderProcessHost::FromID(child_process_id
);
1253 process
? Profile::FromBrowserContext(process
->GetBrowserContext())
1255 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
1256 extra_parts_
[i
]->AppendExtraRendererCommandLineSwitches(
1257 command_line
, process
, profile
);
1260 #if defined(OS_CHROMEOS)
1261 const std::string
& login_profile
=
1262 browser_command_line
.GetSwitchValueASCII(
1263 chromeos::switches::kLoginProfile
);
1264 if (!login_profile
.empty())
1265 command_line
->AppendSwitchASCII(
1266 chromeos::switches::kLoginProfile
, login_profile
);
1269 #if defined(ENABLE_WEBRTC)
1270 MaybeCopyDisableWebRtcEncryptionSwitch(command_line
,
1271 browser_command_line
,
1272 VersionInfo::GetChannel());
1276 PrefService
* prefs
= profile
->GetPrefs();
1277 // Currently this pref is only registered if applied via a policy.
1278 if (prefs
->HasPrefPath(prefs::kDisable3DAPIs
) &&
1279 prefs
->GetBoolean(prefs::kDisable3DAPIs
)) {
1280 // Turn this policy into a command line switch.
1281 command_line
->AppendSwitch(switches::kDisable3DAPIs
);
1284 const base::ListValue
* switches
=
1285 prefs
->GetList(prefs::kEnableDeprecatedWebPlatformFeatures
);
1287 // Enable any deprecated features that have been re-enabled by policy.
1288 for (base::ListValue::const_iterator it
= switches
->begin();
1289 it
!= switches
->end(); ++it
) {
1290 std::string switch_to_enable
;
1291 if ((*it
)->GetAsString(&switch_to_enable
))
1292 command_line
->AppendSwitch(switch_to_enable
);
1296 // Disable client-side phishing detection in the renderer if it is
1297 // disabled in the Profile preferences or the browser process.
1298 if (!prefs
->GetBoolean(prefs::kSafeBrowsingEnabled
) ||
1299 !g_browser_process
->safe_browsing_detection_service()) {
1300 command_line
->AppendSwitch(
1301 switches::kDisableClientSidePhishingDetection
);
1304 if (prefs
->GetBoolean(prefs::kPrintPreviewDisabled
))
1305 command_line
->AppendSwitch(switches::kDisablePrintPreview
);
1307 InstantService
* instant_service
=
1308 InstantServiceFactory::GetForProfile(profile
);
1309 if (instant_service
&&
1310 instant_service
->IsInstantProcess(process
->GetID()))
1311 command_line
->AppendSwitch(switches::kInstantProcess
);
1314 if (IsAutoReloadEnabled())
1315 command_line
->AppendSwitch(switches::kEnableOfflineAutoReload
);
1316 if (IsAutoReloadVisibleOnlyEnabled()) {
1317 command_line
->AppendSwitch(
1318 switches::kEnableOfflineAutoReloadVisibleOnly
);
1322 // Enable showing a saved copy if this session is in the field trial
1323 // or the user explicitly enabled it. Note that as far as the
1324 // renderer is concerned, the feature is enabled if-and-only-if
1325 // one of the kEnableShowSavedCopy* switches is on the command
1326 // line; the yes/no/default behavior is only at the browser
1327 // command line level.
1329 // Command line switches override
1330 const std::string
& show_saved_copy_value
=
1331 browser_command_line
.GetSwitchValueASCII(switches::kShowSavedCopy
);
1332 if (show_saved_copy_value
== switches::kEnableShowSavedCopyPrimary
||
1333 show_saved_copy_value
== switches::kEnableShowSavedCopySecondary
||
1334 show_saved_copy_value
== switches::kDisableShowSavedCopy
) {
1335 command_line
->AppendSwitchASCII(switches::kShowSavedCopy
,
1336 show_saved_copy_value
);
1339 base::FieldTrialList::FindFullName("LoadStaleCacheExperiment");
1341 if (group
== "Primary") {
1342 command_line
->AppendSwitchASCII(
1343 switches::kShowSavedCopy
, switches::kEnableShowSavedCopyPrimary
);
1344 } else if (group
== "Secondary") {
1345 command_line
->AppendSwitchASCII(
1346 switches::kShowSavedCopy
,
1347 switches::kEnableShowSavedCopySecondary
);
1352 // Please keep this in alphabetical order.
1353 static const char* const kSwitchNames
[] = {
1354 autofill::switches::kDisableFillOnAccountSelect
,
1355 autofill::switches::kDisablePasswordGeneration
,
1356 autofill::switches::kEnableFillOnAccountSelect
,
1357 autofill::switches::kEnableFillOnAccountSelectNoHighlighting
,
1358 autofill::switches::kEnablePasswordGeneration
,
1359 autofill::switches::kEnablePasswordSaveOnInPageNavigation
,
1360 autofill::switches::kEnableSingleClickAutofill
,
1361 autofill::switches::kIgnoreAutocompleteOffForAutofill
,
1362 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration
,
1363 #if defined(ENABLE_EXTENSIONS)
1364 extensions::switches::kAllowHTTPBackgroundPage
,
1365 extensions::switches::kAllowLegacyExtensionManifests
,
1366 extensions::switches::kEnableSurfaceWorker
,
1367 extensions::switches::kEnableAppWindowControls
,
1368 extensions::switches::kEnableEmbeddedExtensionOptions
,
1369 extensions::switches::kEnableExperimentalExtensionApis
,
1370 extensions::switches::kExtensionsOnChromeURLs
,
1371 extensions::switches::kWhitelistedExtensionID
,
1373 switches::kAllowInsecureLocalhost
,
1374 switches::kAppsCheckoutURL
,
1375 switches::kAppsGalleryURL
,
1376 switches::kCloudPrintURL
,
1377 switches::kCloudPrintXmppEndpoint
,
1378 switches::kDisableBundledPpapiFlash
,
1379 switches::kDisableCastStreamingHWEncoding
,
1380 switches::kDisableJavaScriptHarmonyShipping
,
1381 switches::kDisableNewBookmarkApps
,
1382 switches::kDisableOutOfProcessPdf
,
1383 switches::kEnableBenchmarking
,
1384 switches::kEnableNaCl
,
1385 #if !defined(DISABLE_NACL)
1386 switches::kEnableNaClDebug
,
1387 switches::kEnableNaClNonSfiMode
,
1388 switches::kEnablePNaClSubzero
,
1390 switches::kEnableNetBenchmarking
,
1391 switches::kEnableNewBookmarkApps
,
1392 switches::kEnableOutOfProcessPdf
,
1393 switches::kEnablePluginPlaceholderShadowDom
,
1394 switches::kJavaScriptHarmony
,
1395 switches::kMessageLoopHistogrammer
,
1396 switches::kPpapiFlashArgs
,
1397 switches::kPpapiFlashPath
,
1398 switches::kPpapiFlashVersion
,
1399 switches::kProfilingAtStart
,
1400 switches::kProfilingFile
,
1401 switches::kProfilingFlush
,
1402 translate::switches::kTranslateSecurityOrigin
,
1405 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1406 arraysize(kSwitchNames
));
1407 } else if (process_type
== switches::kUtilityProcess
) {
1408 #if defined(ENABLE_EXTENSIONS)
1409 static const char* const kSwitchNames
[] = {
1410 extensions::switches::kAllowHTTPBackgroundPage
,
1411 extensions::switches::kEnableExperimentalExtensionApis
,
1412 extensions::switches::kExtensionsOnChromeURLs
,
1413 extensions::switches::kWhitelistedExtensionID
,
1416 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1417 arraysize(kSwitchNames
));
1419 } else if (process_type
== switches::kPluginProcess
) {
1420 #if defined(OS_CHROMEOS)
1421 static const char* const kSwitchNames
[] = {
1422 chromeos::switches::kLoginProfile
,
1425 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1426 arraysize(kSwitchNames
));
1428 } else if (process_type
== switches::kZygoteProcess
) {
1429 static const char* const kSwitchNames
[] = {
1430 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
1431 switches::kDisableBundledPpapiFlash
,
1432 #if !defined(DISABLE_NACL)
1433 switches::kEnableNaClDebug
,
1434 switches::kEnableNaClNonSfiMode
,
1435 switches::kEnablePNaClSubzero
,
1436 switches::kNaClDangerousNoSandboxNonSfi
,
1437 switches::kUseNaClHelperNonSfi
,
1439 switches::kPpapiFlashPath
,
1440 switches::kPpapiFlashVersion
,
1443 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1444 arraysize(kSwitchNames
));
1445 } else if (process_type
== switches::kGpuProcess
) {
1446 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1447 // because GPU is expected to be unreliable.
1448 if (browser_command_line
.HasSwitch(switches::kIgnoreGpuBlacklist
) &&
1449 !command_line
->HasSwitch(switches::kDisableBreakpad
))
1450 command_line
->AppendSwitch(switches::kDisableBreakpad
);
1453 // The command line switch kEnableBenchmarking needs to be specified along
1454 // with the kEnableStatsTable switch to ensure that the stats table global
1455 // is initialized correctly.
1456 if (command_line
->HasSwitch(switches::kEnableBenchmarking
))
1457 DCHECK(command_line
->HasSwitch(switches::kEnableStatsTable
));
1460 std::string
ChromeContentBrowserClient::GetApplicationLocale() {
1461 if (BrowserThread::CurrentlyOn(BrowserThread::IO
))
1462 return g_io_thread_application_locale
.Get();
1463 return g_browser_process
->GetApplicationLocale();
1466 std::string
ChromeContentBrowserClient::GetAcceptLangs(
1467 content::BrowserContext
* context
) {
1468 Profile
* profile
= Profile::FromBrowserContext(context
);
1469 return profile
->GetPrefs()->GetString(prefs::kAcceptLanguages
);
1472 const gfx::ImageSkia
* ChromeContentBrowserClient::GetDefaultFavicon() {
1473 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
1474 return rb
.GetNativeImageNamed(IDR_DEFAULT_FAVICON
).ToImageSkia();
1477 bool ChromeContentBrowserClient::AllowAppCache(
1478 const GURL
& manifest_url
,
1479 const GURL
& first_party
,
1480 content::ResourceContext
* context
) {
1481 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1482 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1483 return io_data
->GetCookieSettings()->
1484 IsSettingCookieAllowed(manifest_url
, first_party
);
1487 bool ChromeContentBrowserClient::AllowServiceWorker(
1489 const GURL
& first_party_url
,
1490 content::ResourceContext
* context
) {
1491 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1492 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1493 return io_data
->GetCookieSettings()->
1494 IsSettingCookieAllowed(scope
, first_party_url
);
1497 bool ChromeContentBrowserClient::AllowGetCookie(
1499 const GURL
& first_party
,
1500 const net::CookieList
& cookie_list
,
1501 content::ResourceContext
* context
,
1502 int render_process_id
,
1503 int render_frame_id
) {
1504 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1505 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1506 bool allow
= io_data
->GetCookieSettings()->
1507 IsReadingCookieAllowed(url
, first_party
);
1509 BrowserThread::PostTask(
1510 BrowserThread::UI
, FROM_HERE
,
1511 base::Bind(&TabSpecificContentSettings::CookiesRead
, render_process_id
,
1512 render_frame_id
, url
, first_party
, cookie_list
, !allow
));
1516 bool ChromeContentBrowserClient::AllowSetCookie(
1518 const GURL
& first_party
,
1519 const std::string
& cookie_line
,
1520 content::ResourceContext
* context
,
1521 int render_process_id
,
1522 int render_frame_id
,
1523 net::CookieOptions
* options
) {
1524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1525 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1526 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1527 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, first_party
);
1529 BrowserThread::PostTask(
1530 BrowserThread::UI
, FROM_HERE
,
1531 base::Bind(&TabSpecificContentSettings::CookieChanged
, render_process_id
,
1532 render_frame_id
, url
, first_party
, cookie_line
, *options
,
1537 bool ChromeContentBrowserClient::AllowSaveLocalState(
1538 content::ResourceContext
* context
) {
1539 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1540 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1541 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1542 ContentSetting setting
= cookie_settings
->GetDefaultCookieSetting(NULL
);
1544 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1545 // Could we even support per-origin settings?
1546 return setting
!= CONTENT_SETTING_SESSION_ONLY
;
1549 bool ChromeContentBrowserClient::AllowWorkerDatabase(
1551 const base::string16
& name
,
1552 const base::string16
& display_name
,
1553 unsigned long estimated_size
,
1554 content::ResourceContext
* context
,
1555 const std::vector
<std::pair
<int, int> >& render_frames
) {
1556 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1557 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1558 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1559 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1561 // Record access to database for potential display in UI.
1562 std::vector
<std::pair
<int, int> >::const_iterator i
;
1563 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1564 BrowserThread::PostTask(
1565 BrowserThread::UI
, FROM_HERE
,
1566 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed
,
1567 i
->first
, i
->second
, url
, name
, display_name
, !allow
));
1573 void ChromeContentBrowserClient::AllowWorkerFileSystem(
1575 content::ResourceContext
* context
,
1576 const std::vector
<std::pair
<int, int> >& render_frames
,
1577 base::Callback
<void(bool)> callback
) {
1578 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1579 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1580 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1581 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1583 #if defined(ENABLE_EXTENSIONS)
1584 GuestPermissionRequestHelper(url
, render_frames
, callback
, allow
);
1586 FileSystemAccessed(url
, render_frames
, callback
, allow
);
1590 #if defined(ENABLE_EXTENSIONS)
1591 void ChromeContentBrowserClient::GuestPermissionRequestHelper(
1593 const std::vector
<std::pair
<int, int> >& render_frames
,
1594 base::Callback
<void(bool)> callback
,
1596 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::IO
));
1597 std::vector
<std::pair
<int, int> >::const_iterator i
;
1598 std::map
<int, int> process_map
;
1599 std::map
<int, int>::const_iterator it
;
1600 bool has_web_view_guest
= false;
1601 // Record access to file system for potential display in UI.
1602 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1603 if (process_map
.find(i
->first
) != process_map
.end())
1606 process_map
.insert(std::pair
<int, int>(i
->first
, i
->second
));
1608 if (extensions::WebViewRendererState::GetInstance()->IsGuest(i
->first
))
1609 has_web_view_guest
= true;
1611 if (!has_web_view_guest
) {
1612 FileSystemAccessed(url
, render_frames
, callback
, allow
);
1615 DCHECK_EQ(1U, process_map
.size());
1616 it
= process_map
.begin();
1617 BrowserThread::PostTask(
1620 base::Bind(&ChromeContentBrowserClient::
1621 RequestFileSystemPermissionOnUIThread
,
1626 base::Bind(&ChromeContentBrowserClient::FileSystemAccessed
,
1627 weak_factory_
.GetWeakPtr(),
1633 void ChromeContentBrowserClient::RequestFileSystemPermissionOnUIThread(
1634 int render_process_id
,
1635 int render_frame_id
,
1637 bool allowed_by_default
,
1638 const base::Callback
<void(bool)>& callback
) {
1639 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::UI
));
1640 extensions::WebViewPermissionHelper
* web_view_permission_helper
=
1641 extensions::WebViewPermissionHelper::FromFrameID(
1642 render_process_id
, render_frame_id
);
1643 web_view_permission_helper
->RequestFileSystemPermission(url
,
1649 void ChromeContentBrowserClient::FileSystemAccessed(
1651 const std::vector
<std::pair
<int, int> >& render_frames
,
1652 base::Callback
<void(bool)> callback
,
1654 // Record access to file system for potential display in UI.
1655 std::vector
<std::pair
<int, int> >::const_iterator i
;
1656 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1657 BrowserThread::PostTask(
1660 base::Bind(&TabSpecificContentSettings::FileSystemAccessed
,
1661 i
->first
, i
->second
, url
, !allow
));
1663 callback
.Run(allow
);
1666 bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1668 const base::string16
& name
,
1669 content::ResourceContext
* context
,
1670 const std::vector
<std::pair
<int, int> >& render_frames
) {
1671 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1672 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1673 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1674 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1676 // Record access to IndexedDB for potential display in UI.
1677 std::vector
<std::pair
<int, int> >::const_iterator i
;
1678 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1679 BrowserThread::PostTask(
1680 BrowserThread::UI
, FROM_HERE
,
1681 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed
,
1682 i
->first
, i
->second
, url
, name
, !allow
));
1688 net::URLRequestContext
*
1689 ChromeContentBrowserClient::OverrideRequestContextForURL(
1690 const GURL
& url
, content::ResourceContext
* context
) {
1691 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1692 #if defined(ENABLE_EXTENSIONS)
1693 if (url
.SchemeIs(extensions::kExtensionScheme
)) {
1694 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1695 return io_data
->extensions_request_context();
1702 QuotaPermissionContext
*
1703 ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1704 return new ChromeQuotaPermissionContext();
1707 void ChromeContentBrowserClient::AllowCertificateError(
1708 int render_process_id
,
1709 int render_frame_id
,
1711 const net::SSLInfo
& ssl_info
,
1712 const GURL
& request_url
,
1713 ResourceType resource_type
,
1715 bool strict_enforcement
,
1716 bool expired_previous_decision
,
1717 const base::Callback
<void(bool)>& callback
,
1718 content::CertificateRequestResultType
* result
) {
1719 if (resource_type
!= content::RESOURCE_TYPE_MAIN_FRAME
) {
1720 // A sub-resource has a certificate error. The user doesn't really
1721 // have a context for making the right decision, so block the
1722 // request hard, without an info bar to allow showing the insecure
1724 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY
;
1728 // If the tab is being prerendered, cancel the prerender and the request.
1729 content::RenderFrameHost
* render_frame_host
=
1730 content::RenderFrameHost::FromID(render_process_id
, render_frame_id
);
1731 WebContents
* tab
= WebContents::FromRenderFrameHost(render_frame_host
);
1737 prerender::PrerenderContents
* prerender_contents
=
1738 prerender::PrerenderContents::FromWebContents(tab
);
1739 if (prerender_contents
) {
1740 prerender_contents
->Destroy(prerender::FINAL_STATUS_SSL_ERROR
);
1741 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL
;
1745 // Otherwise, display an SSL blocking page. The interstitial page takes
1746 // ownership of ssl_blocking_page.
1747 int options_mask
= 0;
1749 options_mask
|= SSLBlockingPage::OVERRIDABLE
;
1750 if (strict_enforcement
)
1751 options_mask
|= SSLBlockingPage::STRICT_ENFORCEMENT
;
1752 if (expired_previous_decision
)
1753 options_mask
|= SSLBlockingPage::EXPIRED_BUT_PREVIOUSLY_ALLOWED
;
1755 SafeBrowsingService
* safe_browsing_service
=
1756 g_browser_process
->safe_browsing_service();
1757 scoped_ptr
<SafeBrowsingSSLCertReporter
> cert_reporter(
1758 new SafeBrowsingSSLCertReporter(safe_browsing_service
1759 ? safe_browsing_service
->ui_manager()
1761 SSLErrorHandler::HandleSSLError(tab
, cert_error
, ssl_info
, request_url
,
1762 options_mask
, cert_reporter
.Pass(), callback
);
1765 void ChromeContentBrowserClient::SelectClientCertificate(
1766 content::WebContents
* web_contents
,
1767 net::SSLCertRequestInfo
* cert_request_info
,
1768 scoped_ptr
<content::ClientCertificateDelegate
> delegate
) {
1769 prerender::PrerenderContents
* prerender_contents
=
1770 prerender::PrerenderContents::FromWebContents(web_contents
);
1771 if (prerender_contents
) {
1772 prerender_contents
->Destroy(
1773 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED
);
1777 GURL
requesting_url("https://" + cert_request_info
->host_and_port
.ToString());
1778 DCHECK(requesting_url
.is_valid())
1779 << "Invalid URL string: https://"
1780 << cert_request_info
->host_and_port
.ToString();
1783 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
1784 scoped_ptr
<base::Value
> filter
=
1785 profile
->GetHostContentSettingsMap()->GetWebsiteSetting(
1788 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE
,
1793 // Try to automatically select a client certificate.
1794 if (filter
->IsType(base::Value::TYPE_DICTIONARY
)) {
1795 base::DictionaryValue
* filter_dict
=
1796 static_cast<base::DictionaryValue
*>(filter
.get());
1798 const std::vector
<scoped_refptr
<net::X509Certificate
> >&
1799 all_client_certs
= cert_request_info
->client_certs
;
1800 for (size_t i
= 0; i
< all_client_certs
.size(); ++i
) {
1801 if (CertMatchesFilter(*all_client_certs
[i
].get(), *filter_dict
)) {
1802 // Use the first certificate that is matched by the filter.
1803 delegate
->ContinueWithCertificate(all_client_certs
[i
].get());
1812 chrome::ShowSSLClientCertificateSelector(web_contents
, cert_request_info
,
1816 void ChromeContentBrowserClient::AddCertificate(
1817 net::CertificateMimeType cert_type
,
1818 const void* cert_data
,
1820 int render_process_id
,
1821 int render_frame_id
) {
1822 chrome::SSLAddCertificate(cert_type
, cert_data
, cert_size
,
1823 render_process_id
, render_frame_id
);
1826 content::MediaObserver
* ChromeContentBrowserClient::GetMediaObserver() {
1827 return MediaCaptureDevicesDispatcher::GetInstance();
1830 content::PlatformNotificationService
*
1831 ChromeContentBrowserClient::GetPlatformNotificationService() {
1832 #if defined(ENABLE_NOTIFICATIONS)
1833 return PlatformNotificationServiceImpl::GetInstance();
1840 bool ChromeContentBrowserClient::CanCreateWindow(
1841 const GURL
& opener_url
,
1842 const GURL
& opener_top_level_frame_url
,
1843 const GURL
& source_origin
,
1844 WindowContainerType container_type
,
1845 const GURL
& target_url
,
1846 const content::Referrer
& referrer
,
1847 WindowOpenDisposition disposition
,
1848 const WebWindowFeatures
& features
,
1850 bool opener_suppressed
,
1851 content::ResourceContext
* context
,
1852 int render_process_id
,
1854 bool* no_javascript_access
) {
1855 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1857 *no_javascript_access
= false;
1859 // If the opener is trying to create a background window but doesn't have
1860 // the appropriate permission, fail the attempt.
1861 if (container_type
== WINDOW_CONTAINER_TYPE_BACKGROUND
) {
1862 #if defined(ENABLE_EXTENSIONS)
1863 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1864 InfoMap
* map
= io_data
->GetExtensionInfoMap();
1865 if (!map
->SecurityOriginHasAPIPermission(
1868 APIPermission::kBackground
)) {
1872 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1873 // return a recently installed Extension even if this CanCreateWindow call
1874 // was made by an old copy of the page in a normal web process. That's ok,
1875 // because the permission check above would have caused an early return
1876 // already. We must use the full URL to find hosted apps, though, and not
1878 const Extension
* extension
=
1879 map
->extensions().GetExtensionOrAppByURL(opener_url
);
1880 if (extension
&& !extensions::BackgroundInfo::AllowJSAccess(extension
))
1881 *no_javascript_access
= true;
1887 #if defined(ENABLE_EXTENSIONS)
1888 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
1893 HostContentSettingsMap
* content_settings
=
1894 ProfileIOData::FromResourceContext(context
)->GetHostContentSettingsMap();
1895 BlockedWindowParams
blocked_params(target_url
,
1904 if (!user_gesture
&&
1905 !base::CommandLine::ForCurrentProcess()->HasSwitch(
1906 switches::kDisablePopupBlocking
)) {
1907 if (content_settings
->GetContentSetting(opener_top_level_frame_url
,
1908 opener_top_level_frame_url
,
1909 CONTENT_SETTINGS_TYPE_POPUPS
,
1911 CONTENT_SETTING_ALLOW
) {
1912 BrowserThread::PostTask(BrowserThread::UI
,
1914 base::Bind(&HandleBlockedPopupOnUIThread
,
1920 #if defined(OS_ANDROID)
1921 if (SingleTabModeTabHelper::IsRegistered(render_process_id
, opener_id
)) {
1922 BrowserThread::PostTask(BrowserThread::UI
,
1924 base::Bind(&HandleSingleTabModeBlockOnUIThread
,
1933 void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1934 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
1935 return g_browser_process
->ResourceDispatcherHostCreated();
1938 content::SpeechRecognitionManagerDelegate
*
1939 ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
1940 return new speech::ChromeSpeechRecognitionManagerDelegate();
1943 net::NetLog
* ChromeContentBrowserClient::GetNetLog() {
1944 return g_browser_process
->net_log();
1947 AccessTokenStore
* ChromeContentBrowserClient::CreateAccessTokenStore() {
1948 return new ChromeAccessTokenStore();
1951 bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1955 void ChromeContentBrowserClient::OverrideWebkitPrefs(
1956 RenderViewHost
* rvh
, WebPreferences
* web_prefs
) {
1957 Profile
* profile
= Profile::FromBrowserContext(
1958 rvh
->GetProcess()->GetBrowserContext());
1959 PrefService
* prefs
= profile
->GetPrefs();
1961 // Fill per-script font preferences. These are not registered on Android
1962 // - http://crbug.com/308033.
1963 #if !defined(OS_ANDROID)
1964 FontFamilyCache::FillFontFamilyMap(profile
,
1965 prefs::kWebKitStandardFontFamilyMap
,
1966 &web_prefs
->standard_font_family_map
);
1967 FontFamilyCache::FillFontFamilyMap(profile
,
1968 prefs::kWebKitFixedFontFamilyMap
,
1969 &web_prefs
->fixed_font_family_map
);
1970 FontFamilyCache::FillFontFamilyMap(profile
,
1971 prefs::kWebKitSerifFontFamilyMap
,
1972 &web_prefs
->serif_font_family_map
);
1973 FontFamilyCache::FillFontFamilyMap(profile
,
1974 prefs::kWebKitSansSerifFontFamilyMap
,
1975 &web_prefs
->sans_serif_font_family_map
);
1976 FontFamilyCache::FillFontFamilyMap(profile
,
1977 prefs::kWebKitCursiveFontFamilyMap
,
1978 &web_prefs
->cursive_font_family_map
);
1979 FontFamilyCache::FillFontFamilyMap(profile
,
1980 prefs::kWebKitFantasyFontFamilyMap
,
1981 &web_prefs
->fantasy_font_family_map
);
1982 FontFamilyCache::FillFontFamilyMap(profile
,
1983 prefs::kWebKitPictographFontFamilyMap
,
1984 &web_prefs
->pictograph_font_family_map
);
1987 web_prefs
->default_font_size
=
1988 prefs
->GetInteger(prefs::kWebKitDefaultFontSize
);
1989 web_prefs
->default_fixed_font_size
=
1990 prefs
->GetInteger(prefs::kWebKitDefaultFixedFontSize
);
1991 web_prefs
->minimum_font_size
=
1992 prefs
->GetInteger(prefs::kWebKitMinimumFontSize
);
1993 web_prefs
->minimum_logical_font_size
=
1994 prefs
->GetInteger(prefs::kWebKitMinimumLogicalFontSize
);
1996 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
1998 web_prefs
->javascript_can_open_windows_automatically
=
1999 prefs
->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically
);
2000 web_prefs
->dom_paste_enabled
=
2001 prefs
->GetBoolean(prefs::kWebKitDomPasteEnabled
);
2002 web_prefs
->shrinks_standalone_images_to_fit
=
2003 prefs
->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit
);
2004 web_prefs
->tabs_to_links
= prefs
->GetBoolean(prefs::kWebkitTabsToLinks
);
2006 if (!prefs
->GetBoolean(prefs::kWebKitJavascriptEnabled
))
2007 web_prefs
->javascript_enabled
= false;
2008 if (!prefs
->GetBoolean(prefs::kWebKitWebSecurityEnabled
))
2009 web_prefs
->web_security_enabled
= false;
2010 if (!prefs
->GetBoolean(prefs::kWebKitPluginsEnabled
))
2011 web_prefs
->plugins_enabled
= false;
2012 if (!prefs
->GetBoolean(prefs::kWebKitJavaEnabled
))
2013 web_prefs
->java_enabled
= false;
2014 web_prefs
->loads_images_automatically
=
2015 prefs
->GetBoolean(prefs::kWebKitLoadsImagesAutomatically
);
2017 if (prefs
->GetBoolean(prefs::kDisable3DAPIs
))
2018 web_prefs
->experimental_webgl_enabled
= false;
2020 web_prefs
->allow_displaying_insecure_content
=
2021 prefs
->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent
);
2022 web_prefs
->allow_running_insecure_content
=
2023 prefs
->GetBoolean(prefs::kWebKitAllowRunningInsecureContent
);
2024 #if defined(OS_ANDROID)
2025 web_prefs
->font_scale_factor
=
2026 static_cast<float>(prefs
->GetDouble(prefs::kWebKitFontScaleFactor
));
2027 web_prefs
->device_scale_adjustment
= GetDeviceScaleAdjustment();
2028 web_prefs
->force_enable_zoom
=
2029 prefs
->GetBoolean(prefs::kWebKitForceEnableZoom
);
2032 #if defined(OS_ANDROID)
2033 web_prefs
->password_echo_enabled
=
2034 prefs
->GetBoolean(prefs::kWebKitPasswordEchoEnabled
);
2036 web_prefs
->password_echo_enabled
= browser_defaults::kPasswordEchoEnabled
;
2039 web_prefs
->asynchronous_spell_checking_enabled
= true;
2040 web_prefs
->unified_textchecker_enabled
= true;
2042 web_prefs
->uses_universal_detector
=
2043 prefs
->GetBoolean(prefs::kWebKitUsesUniversalDetector
);
2044 web_prefs
->text_areas_are_resizable
=
2045 prefs
->GetBoolean(prefs::kWebKitTextAreasAreResizable
);
2046 web_prefs
->hyperlink_auditing_enabled
=
2047 prefs
->GetBoolean(prefs::kEnableHyperlinkAuditing
);
2049 #if defined(ENABLE_EXTENSIONS)
2050 std::string image_animation_policy
=
2051 prefs
->GetString(prefs::kAnimationPolicy
);
2052 if (image_animation_policy
== kAnimationPolicyOnce
)
2053 web_prefs
->animation_policy
=
2054 content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE
;
2055 else if (image_animation_policy
== kAnimationPolicyNone
)
2056 web_prefs
->animation_policy
= content::IMAGE_ANIMATION_POLICY_NO_ANIMATION
;
2058 web_prefs
->animation_policy
= content::IMAGE_ANIMATION_POLICY_ALLOWED
;
2061 // Make sure we will set the default_encoding with canonical encoding name.
2062 web_prefs
->default_encoding
=
2063 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
2064 web_prefs
->default_encoding
);
2065 if (web_prefs
->default_encoding
.empty()) {
2066 prefs
->ClearPref(prefs::kDefaultCharset
);
2067 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2069 DCHECK(!web_prefs
->default_encoding
.empty());
2071 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2072 switches::kEnablePotentiallyAnnoyingSecurityFeatures
)) {
2073 web_prefs
->disable_reading_from_canvas
= true;
2074 web_prefs
->strict_mixed_content_checking
= true;
2075 web_prefs
->strict_powerful_feature_restrictions
= true;
2078 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2079 extra_parts_
[i
]->OverrideWebkitPrefs(rvh
, web_prefs
);
2082 void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2083 BrowserURLHandler
* handler
) {
2084 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2085 extra_parts_
[i
]->BrowserURLHandlerCreated(handler
);
2087 // about: handler. Must come before chrome: handler, since it will
2088 // rewrite about: urls to chrome: URLs and then expect chrome: to
2089 // actually handle them. Also relies on a preliminary fixup phase.
2090 handler
->SetFixupHandler(&FixupBrowserAboutURL
);
2091 handler
->AddHandlerPair(&WillHandleBrowserAboutURL
,
2092 BrowserURLHandler::null_handler());
2094 #if defined(OS_ANDROID)
2095 // Handler to rewrite chrome://newtab on Android.
2096 handler
->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL
,
2097 BrowserURLHandler::null_handler());
2099 // Handler to rewrite chrome://newtab for InstantExtended.
2100 handler
->AddHandlerPair(&chrome::HandleNewTabURLRewrite
,
2101 &chrome::HandleNewTabURLReverseRewrite
);
2104 // chrome: & friends.
2105 handler
->AddHandlerPair(&HandleWebUI
, &HandleWebUIReverse
);
2108 void ChromeContentBrowserClient::ClearCache(RenderFrameHost
* rfh
) {
2109 Profile
* profile
= Profile::FromBrowserContext(
2110 rfh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2111 BrowsingDataRemover
* remover
=
2112 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2113 remover
->Remove(BrowsingDataRemover::REMOVE_CACHE
,
2114 BrowsingDataHelper::UNPROTECTED_WEB
);
2115 // BrowsingDataRemover takes care of deleting itself when done.
2118 void ChromeContentBrowserClient::ClearCookies(RenderFrameHost
* rfh
) {
2119 Profile
* profile
= Profile::FromBrowserContext(
2120 rfh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2121 BrowsingDataRemover
* remover
=
2122 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2123 int remove_mask
= BrowsingDataRemover::REMOVE_SITE_DATA
;
2124 remover
->Remove(remove_mask
, BrowsingDataHelper::UNPROTECTED_WEB
);
2125 // BrowsingDataRemover takes care of deleting itself when done.
2128 base::FilePath
ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
2129 return DownloadPrefs::GetDefaultDownloadDirectory();
2132 std::string
ChromeContentBrowserClient::GetDefaultDownloadName() {
2133 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME
);
2136 void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2137 content::BrowserPpapiHost
* browser_host
) {
2138 #if defined(ENABLE_PLUGINS)
2139 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host
);
2143 content::BrowserPpapiHost
*
2144 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2145 int plugin_process_id
) {
2146 #if !defined(DISABLE_NACL)
2147 content::BrowserChildProcessHostIterator
iter(PROCESS_TYPE_NACL_LOADER
);
2148 while (!iter
.Done()) {
2149 nacl::NaClProcessHost
* host
= static_cast<nacl::NaClProcessHost
*>(
2150 iter
.GetDelegate());
2151 if (host
->process() &&
2152 host
->process()->GetData().id
== plugin_process_id
) {
2153 // Found the plugin.
2154 return host
->browser_ppapi_host();
2162 bool ChromeContentBrowserClient::AllowPepperSocketAPI(
2163 content::BrowserContext
* browser_context
,
2166 const content::SocketPermissionRequest
* params
) {
2167 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2168 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
2169 browser_context
, url
, private_api
, params
, allowed_socket_origins_
);
2175 ui::SelectFilePolicy
* ChromeContentBrowserClient::CreateSelectFilePolicy(
2176 WebContents
* web_contents
) {
2177 return new ChromeSelectFilePolicy(web_contents
);
2180 void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2181 std::vector
<std::string
>* additional_allowed_schemes
) {
2182 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2183 additional_allowed_schemes
);
2184 additional_allowed_schemes
->push_back(content::kChromeDevToolsScheme
);
2185 additional_allowed_schemes
->push_back(content::kChromeUIScheme
);
2186 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
2187 extra_parts_
[i
]->GetAdditionalAllowedSchemesForFileSystem(
2188 additional_allowed_schemes
);
2192 void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
2193 std::vector
<storage::URLRequestAutoMountHandler
>* handlers
) {
2194 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2195 extra_parts_
[i
]->GetURLRequestAutoMountHandlers(handlers
);
2198 void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
2199 content::BrowserContext
* browser_context
,
2200 const base::FilePath
& storage_partition_path
,
2201 ScopedVector
<storage::FileSystemBackend
>* additional_backends
) {
2202 #if defined(OS_CHROMEOS)
2203 storage::ExternalMountPoints
* external_mount_points
=
2204 content::BrowserContext::GetMountPoints(browser_context
);
2205 DCHECK(external_mount_points
);
2206 chromeos::FileSystemBackend
* backend
= new chromeos::FileSystemBackend(
2207 new drive::FileSystemBackendDelegate
,
2208 new chromeos::file_system_provider::BackendDelegate
,
2209 new chromeos::MTPFileSystemBackendDelegate(storage_partition_path
),
2210 external_mount_points
,
2211 storage::ExternalMountPoints::GetSystemInstance());
2212 backend
->AddSystemMountPoints();
2213 DCHECK(backend
->CanHandleType(storage::kFileSystemTypeExternal
));
2214 additional_backends
->push_back(backend
);
2217 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
2218 extra_parts_
[i
]->GetAdditionalFileSystemBackends(
2219 browser_context
, storage_partition_path
, additional_backends
);
2223 #if defined(OS_POSIX) && !defined(OS_MACOSX)
2224 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2225 const base::CommandLine
& command_line
,
2226 int child_process_id
,
2227 FileDescriptorInfo
* mappings
) {
2228 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
2229 if (v8_natives_fd_
.get() == -1 || v8_snapshot_fd_
.get() == -1) {
2230 int v8_natives_fd
= -1;
2231 int v8_snapshot_fd
= -1;
2232 if (gin::V8Initializer::OpenV8FilesForChildProcesses(&v8_natives_fd
,
2234 v8_natives_fd_
.reset(v8_natives_fd
);
2235 v8_snapshot_fd_
.reset(v8_snapshot_fd
);
2238 DCHECK(v8_natives_fd_
.get() != -1 && v8_snapshot_fd_
.get() != -1);
2239 mappings
->Share(kV8NativesDataDescriptor
, v8_natives_fd_
.get());
2240 mappings
->Share(kV8SnapshotDataDescriptor
, v8_snapshot_fd_
.get());
2241 #endif // V8_USE_EXTERNAL_STARTUP_DATA
2243 #if defined(OS_ANDROID)
2244 base::FilePath data_path
;
2245 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID
, &data_path
);
2246 DCHECK(!data_path
.empty());
2248 int flags
= base::File::FLAG_OPEN
| base::File::FLAG_READ
;
2249 base::FilePath chrome_resources_pak
=
2250 data_path
.AppendASCII("chrome_100_percent.pak");
2251 base::File
file(chrome_resources_pak
, flags
);
2252 DCHECK(file
.IsValid());
2253 mappings
->Transfer(kAndroidChrome100PercentPakDescriptor
,
2254 base::ScopedFD(file
.TakePlatformFile()));
2256 const std::string locale
= GetApplicationLocale();
2257 base::FilePath locale_pak
= ResourceBundle::GetSharedInstance().
2258 GetLocaleFilePath(locale
, false);
2259 file
.Initialize(locale_pak
, flags
);
2260 DCHECK(file
.IsValid());
2261 mappings
->Transfer(kAndroidLocalePakDescriptor
,
2262 base::ScopedFD(file
.TakePlatformFile()));
2264 base::FilePath resources_pack_path
;
2265 PathService::Get(chrome::FILE_RESOURCES_PACK
, &resources_pack_path
);
2266 file
.Initialize(resources_pack_path
, flags
);
2267 DCHECK(file
.IsValid());
2268 mappings
->Transfer(kAndroidUIResourcesPakDescriptor
,
2269 base::ScopedFD(file
.TakePlatformFile()));
2271 if (breakpad::IsCrashReporterEnabled()) {
2272 file
= breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile(
2274 if (file
.IsValid()) {
2275 mappings
->Transfer(kAndroidMinidumpDescriptor
,
2276 base::ScopedFD(file
.TakePlatformFile()));
2278 LOG(ERROR
) << "Failed to create file for minidump, crash reporting will "
2279 "be disabled for this process.";
2283 base::FilePath app_data_path
;
2284 PathService::Get(base::DIR_ANDROID_APP_DATA
, &app_data_path
);
2285 DCHECK(!app_data_path
.empty());
2287 flags
= base::File::FLAG_OPEN
| base::File::FLAG_READ
;
2288 base::FilePath icudata_path
=
2289 app_data_path
.AppendASCII(base::i18n::kIcuDataFileName
);
2290 base::File
icudata_file(icudata_path
, flags
);
2291 DCHECK(icudata_file
.IsValid());
2292 mappings
->Transfer(kAndroidICUDataDescriptor
,
2293 base::ScopedFD(icudata_file
.TakePlatformFile()));
2295 int crash_signal_fd
= GetCrashSignalFD(command_line
);
2296 if (crash_signal_fd
>= 0) {
2297 mappings
->Share(kCrashDumpSignal
, crash_signal_fd
);
2299 #endif // defined(OS_ANDROID)
2301 #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
2304 const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2305 return chrome::kBrowserResourcesDll
;
2308 void ChromeContentBrowserClient::PreSpawnRenderer(
2309 sandbox::TargetPolicy
* policy
,
2311 // This code is duplicated in nacl_exe_win_64.cc.
2312 // Allow the server side of a pipe restricted to the "chrome.nacl."
2313 // namespace so that it cannot impersonate other system or other chrome
2315 sandbox::ResultCode result
= policy
->AddRule(
2316 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES
,
2317 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY
,
2318 L
"\\\\.\\pipe\\chrome.nacl.*");
2319 if (result
!= sandbox::SBOX_ALL_OK
) {
2324 // Renderers need to send named pipe handles and shared memory
2325 // segment handles to NaCl loader processes.
2326 result
= policy
->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES
,
2327 sandbox::TargetPolicy::HANDLES_DUP_ANY
,
2329 if (result
!= sandbox::SBOX_ALL_OK
) {
2336 bool ChromeContentBrowserClient::CheckMediaAccessPermission(
2337 content::BrowserContext
* browser_context
,
2338 const GURL
& security_origin
,
2339 content::MediaStreamType type
) {
2340 return MediaCaptureDevicesDispatcher::GetInstance()
2341 ->CheckMediaAccessPermission(
2342 browser_context
, security_origin
, type
);
2345 void ChromeContentBrowserClient::OpenURL(
2346 content::BrowserContext
* browser_context
,
2347 const content::OpenURLParams
& params
,
2348 const base::Callback
<void(content::WebContents
*)>& callback
) {
2349 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
2351 #if !defined(OS_ANDROID) && !defined(OS_IOS)
2352 NavigateParams
nav_params(Profile::FromBrowserContext(browser_context
),
2355 FillNavigateParamsFromOpenURLParams(&nav_params
, params
);
2356 nav_params
.user_gesture
= params
.user_gesture
;
2358 Navigate(&nav_params
);
2359 callback
.Run(nav_params
.target_contents
);
2360 #elif defined(OS_ANDROID)
2361 service_tab_launcher::ServiceTabLauncher::GetInstance()->LaunchTab(
2362 browser_context
, params
, callback
);
2368 void ChromeContentBrowserClient::RecordURLMetric(const std::string
& metric
,
2370 if (url
.is_valid()) {
2371 rappor::SampleDomainAndRegistryFromGURL(g_browser_process
->rappor_service(),
2376 content::DevToolsManagerDelegate
*
2377 ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
2378 #if defined(OS_ANDROID)
2379 return new DevToolsManagerDelegateAndroid();
2381 return new ChromeDevToolsManagerDelegate();
2385 content::TracingDelegate
* ChromeContentBrowserClient::GetTracingDelegate() {
2386 #if !defined(OS_ANDROID)
2387 return new ChromeTracingDelegate();
2393 bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2394 content::BrowserContext
* browser_context
,
2396 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2397 return ChromeContentBrowserClientPluginsPart::
2398 IsPluginAllowedToCallRequestOSFileHandle(browser_context
, url
,
2399 allowed_file_handle_origins_
);
2405 bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
2406 content::BrowserContext
* browser_context
,
2408 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2409 return ChromeContentBrowserClientPluginsPart::
2410 IsPluginAllowedToUseDevChannelAPIs(browser_context
, url
,
2411 allowed_dev_channel_origins_
);
2417 void ChromeContentBrowserClient::OverridePageVisibilityState(
2418 RenderFrameHost
* render_frame_host
,
2419 blink::WebPageVisibilityState
* visibility_state
) {
2420 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
2422 WebContents
* web_contents
=
2423 WebContents::FromRenderFrameHost(render_frame_host
);
2424 DCHECK(web_contents
);
2427 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
2428 prerender::PrerenderManager
* prerender_manager
=
2429 prerender::PrerenderManagerFactory::GetForProfile(profile
);
2430 if (prerender_manager
&&
2431 prerender_manager
->IsWebContentsPrerendering(web_contents
, nullptr)) {
2432 *visibility_state
= blink::WebPageVisibilityStatePrerender
;
2436 #if defined(ENABLE_WEBRTC)
2437 void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
2438 base::CommandLine
* to_command_line
,
2439 const base::CommandLine
& from_command_line
,
2440 VersionInfo::Channel channel
) {
2441 #if defined(OS_ANDROID)
2442 const VersionInfo::Channel kMaxDisableEncryptionChannel
=
2443 VersionInfo::CHANNEL_BETA
;
2445 const VersionInfo::Channel kMaxDisableEncryptionChannel
=
2446 VersionInfo::CHANNEL_DEV
;
2448 if (channel
<= kMaxDisableEncryptionChannel
) {
2449 static const char* const kWebRtcDevSwitchNames
[] = {
2450 switches::kDisableWebRtcEncryption
,
2452 to_command_line
->CopySwitchesFrom(from_command_line
,
2453 kWebRtcDevSwitchNames
,
2454 arraysize(kWebRtcDevSwitchNames
));
2457 #endif // defined(ENABLE_WEBRTC)
2459 } // namespace chrome