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/browser_about_handler.h"
24 #include "chrome/browser/browser_process.h"
25 #include "chrome/browser/browser_shutdown.h"
26 #include "chrome/browser/browsing_data/browsing_data_helper.h"
27 #include "chrome/browser/browsing_data/browsing_data_remover.h"
28 #include "chrome/browser/character_encoding.h"
29 #include "chrome/browser/chrome_content_browser_client_parts.h"
30 #include "chrome/browser/chrome_net_benchmarking_message_filter.h"
31 #include "chrome/browser/chrome_quota_permission_context.h"
32 #include "chrome/browser/content_settings/cookie_settings.h"
33 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
34 #include "chrome/browser/defaults.h"
35 #include "chrome/browser/download/download_prefs.h"
36 #include "chrome/browser/font_family_cache.h"
37 #include "chrome/browser/geolocation/chrome_access_token_store.h"
38 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
39 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
40 #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
41 #include "chrome/browser/net/chrome_net_log.h"
42 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
43 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h"
44 #include "chrome/browser/notifications/platform_notification_service_impl.h"
45 #include "chrome/browser/platform_util.h"
46 #include "chrome/browser/prerender/prerender_final_status.h"
47 #include "chrome/browser/prerender/prerender_manager.h"
48 #include "chrome/browser/prerender/prerender_manager_factory.h"
49 #include "chrome/browser/prerender/prerender_message_filter.h"
50 #include "chrome/browser/printing/printing_message_filter.h"
51 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
52 #include "chrome/browser/profiles/profile.h"
53 #include "chrome/browser/profiles/profile_io_data.h"
54 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
55 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
56 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
57 #include "chrome/browser/safe_browsing/ui_manager.h"
58 #include "chrome/browser/search/instant_service.h"
59 #include "chrome/browser/search/instant_service_factory.h"
60 #include "chrome/browser/search/search.h"
61 #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
62 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
63 #include "chrome/browser/speech/tts_controller.h"
64 #include "chrome/browser/speech/tts_message_filter.h"
65 #include "chrome/browser/ssl/ssl_add_certificate.h"
66 #include "chrome/browser/ssl/ssl_blocking_page.h"
67 #include "chrome/browser/ssl/ssl_cert_reporter.h"
68 #include "chrome/browser/ssl/ssl_client_certificate_selector.h"
69 #include "chrome/browser/ssl/ssl_error_handler.h"
70 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
71 #include "chrome/browser/tab_contents/tab_util.h"
72 #include "chrome/browser/tracing/chrome_tracing_delegate.h"
73 #include "chrome/browser/ui/blocked_content/blocked_window_params.h"
74 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
75 #include "chrome/browser/ui/chrome_select_file_policy.h"
76 #include "chrome/browser/ui/sync/sync_promo_ui.h"
77 #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
78 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
79 #include "chrome/common/chrome_constants.h"
80 #include "chrome/common/chrome_paths.h"
81 #include "chrome/common/chrome_switches.h"
82 #include "chrome/common/env_vars.h"
83 #include "chrome/common/logging_chrome.h"
84 #include "chrome/common/pepper_permission_util.h"
85 #include "chrome/common/pref_names.h"
86 #include "chrome/common/render_messages.h"
87 #include "chrome/common/url_constants.h"
88 #include "chrome/grit/generated_resources.h"
89 #include "chrome/installer/util/google_update_settings.h"
90 #include "chromeos/chromeos_constants.h"
91 #include "components/cdm/browser/cdm_message_filter_android.h"
92 #include "components/cloud_devices/common/cloud_devices_switches.h"
93 #include "components/content_settings/core/browser/content_settings_utils.h"
94 #include "components/content_settings/core/browser/host_content_settings_map.h"
95 #include "components/content_settings/core/common/content_settings.h"
96 #include "components/data_reduction_proxy/content/browser/data_reduction_proxy_message_filter.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/rappor/rappor_utils.h"
102 #include "components/signin/core/common/profile_management_switches.h"
103 #include "components/translate/core/common/translate_switches.h"
104 #include "components/url_fixer/url_fixer.h"
105 #include "content/public/browser/browser_child_process_host.h"
106 #include "content/public/browser/browser_main_parts.h"
107 #include "content/public/browser/browser_ppapi_host.h"
108 #include "content/public/browser/browser_thread.h"
109 #include "content/public/browser/browser_url_handler.h"
110 #include "content/public/browser/child_process_data.h"
111 #include "content/public/browser/child_process_security_policy.h"
112 #include "content/public/browser/client_certificate_delegate.h"
113 #include "content/public/browser/render_frame_host.h"
114 #include "content/public/browser/render_process_host.h"
115 #include "content/public/browser/render_view_host.h"
116 #include "content/public/browser/resource_context.h"
117 #include "content/public/browser/site_instance.h"
118 #include "content/public/browser/web_contents.h"
119 #include "content/public/common/child_process_host.h"
120 #include "content/public/common/content_descriptors.h"
121 #include "content/public/common/url_utils.h"
122 #include "content/public/common/web_preferences.h"
123 #include "gin/v8_initializer.h"
124 #include "net/base/mime_util.h"
125 #include "net/cookies/canonical_cookie.h"
126 #include "net/cookies/cookie_options.h"
127 #include "net/ssl/ssl_cert_request_info.h"
128 #include "ppapi/host/ppapi_host.h"
129 #include "storage/browser/fileapi/external_mount_points.h"
130 #include "ui/base/l10n/l10n_util.h"
131 #include "ui/base/resource/resource_bundle.h"
132 #include "ui/resources/grit/ui_resources.h"
135 #include "base/win/windows_version.h"
136 #include "chrome/browser/chrome_browser_main_win.h"
137 #include "sandbox/win/src/sandbox_policy.h"
138 #elif defined(OS_MACOSX)
139 #include "chrome/browser/chrome_browser_main_mac.h"
140 #include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
141 #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/policy/browser_policy_connector_chromeos.h"
150 #include "chrome/browser/chromeos/system/input_device_settings.h"
151 #include "chromeos/chromeos_switches.h"
152 #include "components/user_manager/user_manager.h"
153 #elif defined(OS_LINUX)
154 #include "chrome/browser/chrome_browser_main_linux.h"
155 #elif defined(OS_ANDROID)
156 #include "chrome/browser/android/new_tab_page_url_handler.h"
157 #include "chrome/browser/android/service_tab_launcher.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 #elif defined(OS_POSIX)
163 #include "chrome/browser/chrome_browser_main_posix.h"
166 #if defined(OS_POSIX) && !defined(OS_MACOSX)
167 #include "base/debug/leak_annotations.h"
168 #include "components/crash/app/breakpad_linux.h"
169 #include "components/crash/browser/crash_handler_host_linux.h"
172 #if defined(OS_ANDROID)
173 #include "ui/base/ui_base_paths.h"
174 #include "ui/gfx/android/device_display_info.h"
177 #if defined(OS_ANDROID)
178 #include "chrome/browser/android/dev_tools_manager_delegate_android.h"
180 #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
183 #if defined(TOOLKIT_VIEWS)
184 #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
188 #include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
191 #if defined(USE_AURA)
192 #include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
196 #include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
199 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
200 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
203 #if !defined(DISABLE_NACL)
204 #include "components/nacl/browser/nacl_browser.h"
205 #include "components/nacl/browser/nacl_host_message_filter.h"
206 #include "components/nacl/browser/nacl_process_host.h"
207 #include "components/nacl/common/nacl_process_type.h"
208 #include "components/nacl/common/nacl_switches.h"
211 #if defined(ENABLE_EXTENSIONS)
212 #include "chrome/browser/accessibility/animation_policy_prefs.h"
213 #include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
214 #include "chrome/browser/extensions/extension_util.h"
215 #include "chrome/browser/media/cast_transport_host_filter.h"
216 #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
217 #include "extensions/browser/extension_registry.h"
218 #include "extensions/browser/guest_view/guest_view_base.h"
219 #include "extensions/browser/guest_view/guest_view_manager.h"
220 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
221 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
222 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
223 #include "extensions/common/constants.h"
224 #include "extensions/common/extension.h"
225 #include "extensions/common/extension_set.h"
226 #include "extensions/common/manifest_handlers/background_info.h"
227 #include "extensions/common/manifest_handlers/shared_module_info.h"
228 #include "extensions/common/permissions/permissions_data.h"
229 #include "extensions/common/permissions/socket_permission.h"
230 #include "extensions/common/switches.h"
233 #if defined(ENABLE_PLUGINS)
234 #include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
237 #if defined(ENABLE_SPELLCHECK)
238 #include "chrome/browser/spellchecker/spellcheck_message_filter.h"
241 #if defined(ENABLE_WEBRTC)
242 #include "chrome/browser/media/webrtc_logging_handler_host.h"
245 using base::FileDescriptor
;
246 using blink::WebWindowFeatures
;
247 using content::AccessTokenStore
;
248 using content::BrowserThread
;
249 using content::BrowserURLHandler
;
250 using content::ChildProcessSecurityPolicy
;
251 using content::QuotaPermissionContext
;
252 using content::RenderFrameHost
;
253 using content::RenderViewHost
;
254 using content::ResourceType
;
255 using content::SiteInstance
;
256 using content::WebContents
;
257 using content::WebPreferences
;
258 using message_center::NotifierId
;
260 #if defined(OS_POSIX)
261 using content::FileDescriptorInfo
;
264 #if defined(ENABLE_EXTENSIONS)
265 using extensions::APIPermission
;
266 using extensions::ChromeContentBrowserClientExtensionsPart
;
267 using extensions::Extension
;
268 using extensions::InfoMap
;
269 using extensions::Manifest
;
272 #if defined(ENABLE_PLUGINS)
273 using plugins::ChromeContentBrowserClientPluginsPart
;
278 // Cached version of the locale so we can return the locale on the I/O
280 base::LazyInstance
<std::string
> g_io_thread_application_locale
;
282 #if defined(ENABLE_PLUGINS)
283 // TODO(teravest): Add renderer-side API-specific checking for these APIs so
284 // that blanket permission isn't granted to all dev channel APIs for these.
285 // http://crbug.com/386743
286 const char* const kPredefinedAllowedDevChannelOrigins
[] = {
287 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/383937
288 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/383937
291 const char* const kPredefinedAllowedFileHandleOrigins
[] = {
292 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
293 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
296 const char* const kPredefinedAllowedSocketOrigins
[] = {
297 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
298 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
299 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
300 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
301 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
302 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
303 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
304 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
305 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
306 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
307 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
308 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
309 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
310 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
311 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
312 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
313 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
314 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
315 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
316 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
320 // Returns a copy of the given url with its host set to given host and path set
321 // to given path. Other parts of the url will be the same.
322 GURL
ReplaceURLHostAndPath(const GURL
& url
,
323 const std::string
& host
,
324 const std::string
& path
) {
325 url::Replacements
<char> replacements
;
326 replacements
.SetHost(host
.c_str(), url::Component(0, host
.length()));
327 replacements
.SetPath(path
.c_str(), url::Component(0, path
.length()));
328 return url
.ReplaceComponents(replacements
);
331 // Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
332 GURL
AddUberHost(const GURL
& url
) {
333 const std::string uber_host
= chrome::kChromeUIUberHost
;
334 const std::string new_path
= url
.host() + url
.path();
336 return ReplaceURLHostAndPath(url
, uber_host
, new_path
);
339 // If url->host() is "chrome" and url->path() has characters other than the
340 // first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
341 // returns true. Otherwise returns false.
342 bool RemoveUberHost(GURL
* url
) {
343 if (url
->host() != chrome::kChromeUIUberHost
)
346 if (url
->path().empty() || url
->path() == "/")
349 const std::string old_path
= url
->path();
351 const std::string::size_type separator
= old_path
.find('/', 1);
352 std::string new_host
;
353 std::string new_path
;
354 if (separator
== std::string::npos
) {
355 new_host
= old_path
.substr(1);
357 new_host
= old_path
.substr(1, separator
- 1);
358 new_path
= old_path
.substr(separator
);
361 // Do not allow URLs with paths empty before the first slash since we can't
362 // have an empty host. (e.g "foo://chrome//")
363 if (new_host
.empty())
366 *url
= ReplaceURLHostAndPath(*url
, new_host
, new_path
);
368 DCHECK(url
->is_valid());
373 // Handles rewriting Web UI URLs.
374 bool HandleWebUI(GURL
* url
, content::BrowserContext
* browser_context
) {
375 // Do not handle special URLs such as "about:foo"
376 if (!url
->host().empty()) {
377 const GURL chrome_url
= AddUberHost(*url
);
379 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
381 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
382 browser_context
, chrome_url
))
386 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
387 browser_context
, *url
))
390 #if defined(OS_CHROMEOS)
391 // Special case : in ChromeOS in Guest mode bookmarks and history are
392 // disabled for security reasons. New tab page explains the reasons, so
393 // we redirect user to new tab page.
394 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
395 if (url
->SchemeIs(content::kChromeUIScheme
) &&
396 (url
->DomainIs(chrome::kChromeUIBookmarksHost
) ||
397 url
->DomainIs(chrome::kChromeUIHistoryHost
))) {
398 // Rewrite with new tab URL
399 *url
= GURL(chrome::kChromeUINewTabURL
);
407 // Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
409 bool HandleWebUIReverse(GURL
* url
, content::BrowserContext
* browser_context
) {
410 if (!url
->is_valid() || !url
->SchemeIs(content::kChromeUIScheme
))
413 return RemoveUberHost(url
);
416 bool CertMatchesFilter(const net::X509Certificate
& cert
,
417 const base::DictionaryValue
& filter
) {
418 // TODO(markusheintz): This is the minimal required filter implementation.
419 // Implement a better matcher.
421 // An empty filter matches any client certificate since no requirements are
426 std::string common_name
;
427 if (filter
.GetString("ISSUER.CN", &common_name
) &&
428 (cert
.issuer().common_name
== common_name
)) {
434 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
435 breakpad::CrashHandlerHostLinux
* CreateCrashHandlerHost(
436 const std::string
& process_type
) {
437 base::FilePath dumps_path
;
438 PathService::Get(chrome::DIR_CRASH_DUMPS
, &dumps_path
);
440 ANNOTATE_SCOPED_MEMORY_LEAK
;
441 bool upload
= (getenv(env_vars::kHeadless
) == NULL
);
442 breakpad::CrashHandlerHostLinux
* crash_handler
=
443 new breakpad::CrashHandlerHostLinux(process_type
, dumps_path
, upload
);
444 crash_handler
->StartUploaderThread();
445 return crash_handler
;
449 int GetCrashSignalFD(const base::CommandLine
& command_line
) {
450 // Extensions have the same process type as renderers.
451 if (command_line
.HasSwitch(extensions::switches::kExtensionProcess
)) {
452 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
454 crash_handler
= CreateCrashHandlerHost("extension");
455 return crash_handler
->GetDeathSignalSocket();
458 std::string process_type
=
459 command_line
.GetSwitchValueASCII(switches::kProcessType
);
461 if (process_type
== switches::kRendererProcess
) {
462 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
464 crash_handler
= CreateCrashHandlerHost(process_type
);
465 return crash_handler
->GetDeathSignalSocket();
468 if (process_type
== switches::kPluginProcess
) {
469 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
471 crash_handler
= CreateCrashHandlerHost(process_type
);
472 return crash_handler
->GetDeathSignalSocket();
475 if (process_type
== switches::kPpapiPluginProcess
) {
476 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
478 crash_handler
= CreateCrashHandlerHost(process_type
);
479 return crash_handler
->GetDeathSignalSocket();
482 if (process_type
== switches::kGpuProcess
) {
483 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
485 crash_handler
= CreateCrashHandlerHost(process_type
);
486 return crash_handler
->GetDeathSignalSocket();
491 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
493 void SetApplicationLocaleOnIOThread(const std::string
& locale
) {
494 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
495 g_io_thread_application_locale
.Get() = locale
;
498 void HandleBlockedPopupOnUIThread(const BlockedWindowParams
& params
) {
499 // TODO(jochen): This code path should use RenderFrameHosts. See
500 // http://crbug.com/431769 for details.
501 RenderViewHost
* render_view_host
=
502 RenderViewHost::FromID(params
.render_process_id(), params
.opener_id());
503 if (!render_view_host
)
505 WebContents
* tab
= WebContents::FromRenderViewHost(render_view_host
);
506 // The tab might already have navigated away.
507 if (!tab
|| tab
->GetRenderViewHost() != render_view_host
)
510 prerender::PrerenderContents
* prerender_contents
=
511 prerender::PrerenderContents::FromWebContents(tab
);
512 if (prerender_contents
) {
513 prerender_contents
->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW
);
517 PopupBlockerTabHelper
* popup_helper
=
518 PopupBlockerTabHelper::FromWebContents(tab
);
521 popup_helper
->AddBlockedPopup(params
);
524 // An implementation of the SSLCertReporter interface used by
525 // SSLErrorHandler. Uses the SafeBrowsing UI manager to send invalid
526 // certificate reports.
527 class SafeBrowsingSSLCertReporter
: public SSLCertReporter
{
529 explicit SafeBrowsingSSLCertReporter(
530 const scoped_refptr
<SafeBrowsingUIManager
>& safe_browsing_ui_manager
)
531 : safe_browsing_ui_manager_(safe_browsing_ui_manager
) {}
532 ~SafeBrowsingSSLCertReporter() override
{}
534 // SSLCertReporter implementation
535 void ReportInvalidCertificateChain(const std::string
& hostname
,
536 const net::SSLInfo
& ssl_info
) override
{
537 if (safe_browsing_ui_manager_
) {
538 safe_browsing_ui_manager_
->ReportInvalidCertificateChain(
539 hostname
, ssl_info
, base::Bind(&base::DoNothing
));
544 const scoped_refptr
<SafeBrowsingUIManager
> safe_browsing_ui_manager_
;
547 #if defined(OS_ANDROID)
549 void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams
& params
) {
550 WebContents
* web_contents
=
551 tab_util::GetWebContentsByID(params
.render_process_id(),
556 SingleTabModeTabHelper::FromWebContents(web_contents
)->HandleOpenUrl(params
);
559 float GetDeviceScaleAdjustment() {
560 static const float kMinFSM
= 1.05f
;
561 static const int kWidthForMinFSM
= 320;
562 static const float kMaxFSM
= 1.3f
;
563 static const int kWidthForMaxFSM
= 800;
565 gfx::DeviceDisplayInfo info
;
566 int minWidth
= info
.GetSmallestDIPWidth();
568 if (minWidth
<= kWidthForMinFSM
)
570 if (minWidth
>= kWidthForMaxFSM
)
573 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
574 float ratio
= static_cast<float>(minWidth
- kWidthForMinFSM
) /
575 (kWidthForMaxFSM
- kWidthForMinFSM
);
576 return ratio
* (kMaxFSM
- kMinFSM
) + kMinFSM
;
579 #endif // defined(OS_ANDROID)
581 #if defined(ENABLE_EXTENSIONS)
582 // By default, JavaScript and images are enabled in guest content.
583 void GetGuestViewDefaultContentSettingRules(
585 RendererContentSettingRules
* rules
) {
586 rules
->image_rules
.push_back(
587 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
588 ContentSettingsPattern::Wildcard(),
589 CONTENT_SETTING_ALLOW
,
593 rules
->script_rules
.push_back(
594 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
595 ContentSettingsPattern::Wildcard(),
596 CONTENT_SETTING_ALLOW
,
600 #endif // defined(ENABLE_EXTENSIONS)
606 ChromeContentBrowserClient::ChromeContentBrowserClient()
608 #if defined(OS_POSIX) && !defined(OS_MACOSX)
611 #endif // OS_POSIX && !OS_MACOSX
612 weak_factory_(this) {
613 #if defined(ENABLE_PLUGINS)
614 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedDevChannelOrigins
); ++i
)
615 allowed_dev_channel_origins_
.insert(kPredefinedAllowedDevChannelOrigins
[i
]);
616 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedFileHandleOrigins
); ++i
)
617 allowed_file_handle_origins_
.insert(kPredefinedAllowedFileHandleOrigins
[i
]);
618 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedSocketOrigins
); ++i
)
619 allowed_socket_origins_
.insert(kPredefinedAllowedSocketOrigins
[i
]);
621 extra_parts_
.push_back(new ChromeContentBrowserClientPluginsPart
);
624 #if !defined(OS_ANDROID)
625 TtsExtensionEngine
* tts_extension_engine
= TtsExtensionEngine::GetInstance();
626 TtsController::GetInstance()->SetTtsEngineDelegate(tts_extension_engine
);
629 #if defined(ENABLE_EXTENSIONS)
630 extra_parts_
.push_back(new ChromeContentBrowserClientExtensionsPart
);
634 ChromeContentBrowserClient::~ChromeContentBrowserClient() {
635 for (int i
= static_cast<int>(extra_parts_
.size()) - 1; i
>= 0; --i
)
636 delete extra_parts_
[i
];
637 extra_parts_
.clear();
641 void ChromeContentBrowserClient::RegisterProfilePrefs(
642 user_prefs::PrefRegistrySyncable
* registry
) {
643 registry
->RegisterBooleanPref(
644 prefs::kDisable3DAPIs
,
646 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
647 registry
->RegisterBooleanPref(
648 prefs::kEnableHyperlinkAuditing
,
650 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
651 registry
->RegisterListPref(
652 prefs::kEnableDeprecatedWebPlatformFeatures
,
653 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
657 void ChromeContentBrowserClient::SetApplicationLocale(
658 const std::string
& locale
) {
659 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
661 // This object is guaranteed to outlive all threads so we don't have to
662 // worry about the lack of refcounting and can just post as Unretained.
664 // The common case is that this function is called early in Chrome startup
665 // before any threads are created (it will also be called later if the user
666 // changes the pref). In this case, there will be no threads created and
667 // posting will fail. When there are no threads, we can just set the string
668 // without worrying about threadsafety.
669 if (!BrowserThread::PostTask(BrowserThread::IO
, FROM_HERE
,
670 base::Bind(&SetApplicationLocaleOnIOThread
, locale
))) {
671 g_io_thread_application_locale
.Get() = locale
;
675 content::BrowserMainParts
* ChromeContentBrowserClient::CreateBrowserMainParts(
676 const content::MainFunctionParams
& parameters
) {
677 ChromeBrowserMainParts
* main_parts
;
678 // Construct the Main browser parts based on the OS type.
680 main_parts
= new ChromeBrowserMainPartsWin(parameters
);
681 #elif defined(OS_MACOSX)
682 main_parts
= new ChromeBrowserMainPartsMac(parameters
);
683 #elif defined(OS_CHROMEOS)
684 main_parts
= new chromeos::ChromeBrowserMainPartsChromeos(parameters
);
685 #elif defined(OS_LINUX)
686 main_parts
= new ChromeBrowserMainPartsLinux(parameters
);
687 #elif defined(OS_ANDROID)
688 main_parts
= new ChromeBrowserMainPartsAndroid(parameters
);
689 #elif defined(OS_POSIX)
690 main_parts
= new ChromeBrowserMainPartsPosix(parameters
);
693 main_parts
= new ChromeBrowserMainParts(parameters
);
696 chrome::AddProfilesExtraParts(main_parts
);
698 // Construct additional browser parts. Stages are called in the order in
699 // which they are added.
700 #if defined(TOOLKIT_VIEWS)
701 main_parts
->AddParts(new ChromeBrowserMainExtraPartsViews());
704 // TODO(oshima): Athena on chrome currently requires USE_ASH to build.
705 // We should reduce the dependency as much as possible.
707 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAsh());
710 #if defined(USE_AURA)
711 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAura());
715 main_parts
->AddParts(new ChromeBrowserMainExtraPartsX11());
718 chrome::AddMetricsExtraParts(main_parts
);
723 std::string
ChromeContentBrowserClient::GetStoragePartitionIdForSite(
724 content::BrowserContext
* browser_context
,
726 std::string partition_id
;
728 // The partition ID for webview guest processes is the string value of its
729 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
730 if (site
.SchemeIs(content::kGuestScheme
)) {
731 partition_id
= site
.spec();
732 } else if (!switches::IsEnableWebviewBasedSignin() &&
733 site
.GetOrigin().spec() == kChromeUIChromeSigninURL
) {
734 // The non-webview Chrome signin page has an embedded iframe of extension
735 // and web content, thus it must be isolated from other webUI pages.
736 partition_id
= site
.GetOrigin().spec();
739 DCHECK(IsValidStoragePartitionId(browser_context
, partition_id
));
743 bool ChromeContentBrowserClient::IsValidStoragePartitionId(
744 content::BrowserContext
* browser_context
,
745 const std::string
& partition_id
) {
746 // The default ID is empty and is always valid.
747 if (partition_id
.empty())
750 return GURL(partition_id
).is_valid();
753 void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
754 content::BrowserContext
* browser_context
,
757 std::string
* partition_domain
,
758 std::string
* partition_name
,
760 // Default to the browser-wide storage partition and override based on |site|
762 partition_domain
->clear();
763 partition_name
->clear();
766 bool success
= false;
767 #if defined(ENABLE_EXTENSIONS)
768 success
= extensions::WebViewGuest::GetGuestPartitionConfigForSite(
769 site
, partition_domain
, partition_name
, in_memory
);
771 if (!success
&& site
.SchemeIs(extensions::kExtensionScheme
)) {
772 // If |can_be_default| is false, the caller is stating that the |site|
773 // should be parsed as if it had isolated storage. In particular it is
774 // important to NOT check ExtensionService for the is_storage_isolated()
775 // attribute because this code path is run during Extension uninstall
776 // to do cleanup after the Extension has already been unloaded from the
778 bool is_isolated
= !can_be_default
;
779 if (can_be_default
) {
780 if (extensions::util::SiteHasIsolatedStorage(site
, browser_context
))
785 CHECK(site
.has_host());
786 // For extensions with isolated storage, the the host of the |site| is
787 // the |partition_domain|. The |in_memory| and |partition_name| are only
788 // used in guest schemes so they are cleared here.
789 *partition_domain
= site
.host();
791 partition_name
->clear();
797 if (!success
&& (!switches::IsEnableWebviewBasedSignin() &&
798 site
.GetOrigin().spec() == kChromeUIChromeSigninURL
)) {
799 // The non-webview Chrome signin page has an embedded iframe of extension
800 // and web content, thus it must be isolated from other webUI pages.
801 *partition_domain
= chrome::kChromeUIChromeSigninHost
;
804 // Assert that if |can_be_default| is false, the code above must have found a
805 // non-default partition. If this fails, the caller has a serious logic
806 // error about which StoragePartition they expect to be in and it is not
808 CHECK(can_be_default
|| !partition_domain
->empty());
811 content::WebContentsViewDelegate
*
812 ChromeContentBrowserClient::GetWebContentsViewDelegate(
813 content::WebContents
* web_contents
) {
814 return chrome::CreateWebContentsViewDelegate(web_contents
);
817 void ChromeContentBrowserClient::RenderProcessWillLaunch(
818 content::RenderProcessHost
* host
) {
819 int id
= host
->GetID();
820 Profile
* profile
= Profile::FromBrowserContext(host
->GetBrowserContext());
821 net::URLRequestContextGetter
* context
=
822 profile
->GetRequestContextForRenderProcess(id
);
824 host
->AddFilter(new ChromeRenderMessageFilter(id
, profile
));
825 #if defined(ENABLE_EXTENSIONS)
826 host
->AddFilter(new cast::CastTransportHostFilter
);
828 #if defined(ENABLE_PRINTING)
829 host
->AddFilter(new printing::PrintingMessageFilter(id
, profile
));
831 host
->AddFilter(new SearchProviderInstallStateMessageFilter(id
, profile
));
832 #if defined(ENABLE_SPELLCHECK)
833 host
->AddFilter(new SpellCheckMessageFilter(id
));
835 #if defined(OS_MACOSX)
836 host
->AddFilter(new SpellCheckMessageFilterMac(id
));
838 host
->AddFilter(new ChromeNetBenchmarkingMessageFilter(profile
, context
));
839 host
->AddFilter(new prerender::PrerenderMessageFilter(id
, profile
));
840 host
->AddFilter(new TtsMessageFilter(host
->GetBrowserContext()));
841 #if defined(ENABLE_WEBRTC)
842 WebRtcLoggingHandlerHost
* webrtc_logging_handler_host
=
843 new WebRtcLoggingHandlerHost(profile
);
844 host
->SetWebRtcLogMessageCallback(base::Bind(
845 &WebRtcLoggingHandlerHost::LogMessage
, webrtc_logging_handler_host
));
846 host
->AddFilter(webrtc_logging_handler_host
);
847 host
->SetUserData(host
, new base::UserDataAdapter
<WebRtcLoggingHandlerHost
>(
848 webrtc_logging_handler_host
));
850 #if !defined(DISABLE_NACL)
851 host
->AddFilter(new nacl::NaClHostMessageFilter(
852 id
, profile
->IsOffTheRecord(),
856 #if defined(OS_ANDROID)
857 host
->AddFilter(new cdm::CdmMessageFilterAndroid());
859 DataReductionProxyChromeSettings
* data_reduction_proxy_settings
=
860 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(profile
);
861 host
->AddFilter(new data_reduction_proxy::DataReductionProxyMessageFilter(
862 data_reduction_proxy_settings
));
864 host
->Send(new ChromeViewMsg_SetIsIncognitoProcess(
865 profile
->IsOffTheRecord()));
867 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
868 extra_parts_
[i
]->RenderProcessWillLaunch(host
);
870 RendererContentSettingRules rules
;
871 if (host
->IsIsolatedGuest()) {
872 #if defined(ENABLE_EXTENSIONS)
873 GetGuestViewDefaultContentSettingRules(profile
->IsOffTheRecord(), &rules
);
878 GetRendererContentSettingRules(
879 profile
->GetHostContentSettingsMap(), &rules
);
881 host
->Send(new ChromeViewMsg_SetContentSettingRules(rules
));
884 GURL
ChromeContentBrowserClient::GetEffectiveURL(
885 content::BrowserContext
* browser_context
, const GURL
& url
) {
886 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
890 // If the input |url| should be assigned to the Instant renderer, make its
891 // effective URL distinct from other URLs on the search provider's domain.
892 if (chrome::ShouldAssignURLToInstantRenderer(url
, profile
))
893 return chrome::GetEffectiveURLForInstant(url
, profile
);
895 #if defined(ENABLE_EXTENSIONS)
896 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(
903 bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
904 content::BrowserContext
* browser_context
, const GURL
& effective_url
) {
905 // Non-extension, non-Instant URLs should generally use
906 // process-per-site-instance. Because we expect to use the effective URL,
907 // URLs for hosted apps (apart from bookmark apps) should have an extension
910 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
914 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url
, profile
))
917 #if defined(ENABLE_EXTENSIONS)
918 return ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
919 profile
, effective_url
);
925 // These are treated as WebUI schemes but do not get WebUI bindings. Also,
926 // view-source is allowed for these schemes.
927 void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
928 std::vector
<std::string
>* additional_schemes
) {
929 additional_schemes
->push_back(chrome::kChromeSearchScheme
);
930 additional_schemes
->push_back(dom_distiller::kDomDistillerScheme
);
933 void ChromeContentBrowserClient::GetAdditionalWebUIHostsToIgnoreParititionCheck(
934 std::vector
<std::string
>* hosts
) {
935 hosts
->push_back(chrome::kChromeUIExtensionIconHost
);
936 hosts
->push_back(chrome::kChromeUIFaviconHost
);
937 hosts
->push_back(chrome::kChromeUIThemeHost
);
938 hosts
->push_back(chrome::kChromeUIThumbnailHost
);
939 hosts
->push_back(chrome::kChromeUIThumbnailHost2
);
940 hosts
->push_back(chrome::kChromeUIThumbnailListHost
);
943 net::URLRequestContextGetter
*
944 ChromeContentBrowserClient::CreateRequestContext(
945 content::BrowserContext
* browser_context
,
946 content::ProtocolHandlerMap
* protocol_handlers
,
947 content::URLRequestInterceptorScopedVector request_interceptors
) {
948 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
949 return profile
->CreateRequestContext(protocol_handlers
,
950 request_interceptors
.Pass());
953 net::URLRequestContextGetter
*
954 ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
955 content::BrowserContext
* browser_context
,
956 const base::FilePath
& partition_path
,
958 content::ProtocolHandlerMap
* protocol_handlers
,
959 content::URLRequestInterceptorScopedVector request_interceptors
) {
960 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
961 return profile
->CreateRequestContextForStoragePartition(
965 request_interceptors
.Pass());
968 bool ChromeContentBrowserClient::IsHandledURL(const GURL
& url
) {
969 return ProfileIOData::IsHandledURL(url
);
972 bool ChromeContentBrowserClient::CanCommitURL(
973 content::RenderProcessHost
* process_host
,
975 #if defined(ENABLE_EXTENSIONS)
976 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(
983 bool ChromeContentBrowserClient::ShouldAllowOpenURL(
984 content::SiteInstance
* site_instance
, const GURL
& url
) {
985 GURL from_url
= site_instance
->GetSiteURL();
987 #if defined(ENABLE_EXTENSIONS)
989 if (ChromeContentBrowserClientExtensionsPart::ShouldAllowOpenURL(
990 site_instance
, from_url
, url
, &result
))
994 // Do not allow chrome://chrome-signin navigate to other chrome:// URLs, since
995 // the signin page may host untrusted web content.
996 if (from_url
.GetOrigin().spec() == chrome::kChromeUIChromeSigninURL
&&
997 url
.SchemeIs(content::kChromeUIScheme
) &&
998 url
.host() != chrome::kChromeUIChromeSigninHost
) {
999 VLOG(1) << "Blocked navigation to " << url
.spec() << " from "
1000 << chrome::kChromeUIChromeSigninURL
;
1007 bool ChromeContentBrowserClient::IsSuitableHost(
1008 content::RenderProcessHost
* process_host
,
1009 const GURL
& site_url
) {
1011 Profile::FromBrowserContext(process_host
->GetBrowserContext());
1012 // This may be NULL during tests. In that case, just assume any site can
1017 // Instant URLs should only be in the instant process and instant process
1018 // should only have Instant URLs.
1019 InstantService
* instant_service
=
1020 InstantServiceFactory::GetForProfile(profile
);
1021 if (instant_service
) {
1022 bool is_instant_process
= instant_service
->IsInstantProcess(
1023 process_host
->GetID());
1024 bool should_be_in_instant_process
=
1025 chrome::ShouldAssignURLToInstantRenderer(site_url
, profile
);
1026 if (is_instant_process
|| should_be_in_instant_process
)
1027 return is_instant_process
&& should_be_in_instant_process
;
1030 #if defined(ENABLE_EXTENSIONS)
1031 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1032 profile
, process_host
, site_url
);
1038 bool ChromeContentBrowserClient::MayReuseHost(
1039 content::RenderProcessHost
* process_host
) {
1040 // If there is currently a prerender in progress for the host provided,
1041 // it may not be shared. We require prerenders to be by themselves in a
1042 // separate process so that we can monitor their resource usage.
1043 Profile
* profile
= Profile::FromBrowserContext(
1044 process_host
->GetBrowserContext());
1045 prerender::PrerenderManager
* prerender_manager
=
1046 prerender::PrerenderManagerFactory::GetForProfile(profile
);
1047 if (prerender_manager
&&
1048 !prerender_manager
->MayReuseProcessHost(process_host
)) {
1055 bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1056 content::BrowserContext
* browser_context
, const GURL
& url
) {
1057 // It has to be a valid URL for us to check for an extension.
1058 if (!url
.is_valid())
1061 #if defined(ENABLE_EXTENSIONS)
1062 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1063 return ChromeContentBrowserClientExtensionsPart::
1064 ShouldTryToUseExistingProcessHost(
1071 void ChromeContentBrowserClient::SiteInstanceGotProcess(
1072 SiteInstance
* site_instance
) {
1073 CHECK(site_instance
->HasProcess());
1075 Profile
* profile
= Profile::FromBrowserContext(
1076 site_instance
->GetBrowserContext());
1080 // Remember the ID of the Instant process to signal the renderer process
1081 // on startup in |AppendExtraCommandLineSwitches| below.
1082 if (chrome::ShouldAssignURLToInstantRenderer(
1083 site_instance
->GetSiteURL(), profile
)) {
1084 InstantService
* instant_service
=
1085 InstantServiceFactory::GetForProfile(profile
);
1086 if (instant_service
)
1087 instant_service
->AddInstantProcess(site_instance
->GetProcess()->GetID());
1090 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
1091 extra_parts_
[i
]->SiteInstanceGotProcess(site_instance
);
1094 void ChromeContentBrowserClient::SiteInstanceDeleting(
1095 SiteInstance
* site_instance
) {
1096 if (!site_instance
->HasProcess())
1099 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
1100 extra_parts_
[i
]->SiteInstanceDeleting(site_instance
);
1103 bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
1104 SiteInstance
* site_instance
,
1105 const GURL
& current_url
,
1106 const GURL
& new_url
) {
1107 #if defined(ENABLE_EXTENSIONS)
1108 return ChromeContentBrowserClientExtensionsPart::
1109 ShouldSwapBrowsingInstancesForNavigation(
1110 site_instance
, current_url
, new_url
);
1116 bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1117 content::ResourceContext
* resource_context
, const GURL
& current_url
,
1118 const GURL
& new_url
) {
1119 #if defined(ENABLE_EXTENSIONS)
1120 return ChromeContentBrowserClientExtensionsPart::
1121 ShouldSwapProcessesForRedirect(resource_context
, current_url
, new_url
);
1127 bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL
& url
) {
1128 return !url
.SchemeIs(chrome::kChromeNativeScheme
);
1131 std::string
ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1132 const std::string
& alias_name
) {
1133 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name
);
1138 bool IsAutoReloadEnabled() {
1139 // Fetch the field trial, even though we don't use it. Calling FindFullName()
1140 // causes the field-trial mechanism to report which group we're in, which
1141 // might reflect a hard disable or hard enable via flag, both of which have
1142 // their own field trial groups. This lets us know what percentage of users
1143 // manually enable or disable auto-reload.
1144 std::string group
= base::FieldTrialList::FindFullName(
1145 "AutoReloadExperiment");
1146 const base::CommandLine
& browser_command_line
=
1147 *base::CommandLine::ForCurrentProcess();
1148 if (browser_command_line
.HasSwitch(switches::kEnableOfflineAutoReload
))
1150 if (browser_command_line
.HasSwitch(switches::kDisableOfflineAutoReload
))
1155 bool IsAutoReloadVisibleOnlyEnabled() {
1156 // See the block comment in IsAutoReloadEnabled().
1157 std::string group
= base::FieldTrialList::FindFullName(
1158 "AutoReloadVisibleOnlyExperiment");
1159 const base::CommandLine
& browser_command_line
=
1160 *base::CommandLine::ForCurrentProcess();
1161 if (browser_command_line
.HasSwitch(
1162 switches::kEnableOfflineAutoReloadVisibleOnly
)) {
1165 if (browser_command_line
.HasSwitch(
1166 switches::kDisableOfflineAutoReloadVisibleOnly
)) {
1174 void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1175 base::CommandLine
* command_line
,
1176 int child_process_id
) {
1177 #if defined(OS_MACOSX)
1178 scoped_ptr
<metrics::ClientInfo
> client_info
=
1179 GoogleUpdateSettings::LoadMetricsClientInfo();
1181 command_line
->AppendSwitchASCII(switches::kMetricsClientID
,
1182 client_info
->client_id
);
1184 #elif defined(OS_POSIX)
1185 if (breakpad::IsCrashReporterEnabled()) {
1186 scoped_ptr
<metrics::ClientInfo
> client_info
=
1187 GoogleUpdateSettings::LoadMetricsClientInfo();
1188 command_line
->AppendSwitchASCII(switches::kEnableCrashReporter
,
1189 client_info
? client_info
->client_id
1194 if (logging::DialogsAreSuppressed())
1195 command_line
->AppendSwitch(switches::kNoErrorDialogs
);
1197 std::string process_type
=
1198 command_line
->GetSwitchValueASCII(switches::kProcessType
);
1199 const base::CommandLine
& browser_command_line
=
1200 *base::CommandLine::ForCurrentProcess();
1202 static const char* const kCommonSwitchNames
[] = {
1203 switches::kUserAgent
,
1204 switches::kUserDataDir
, // Make logs go to the right file.
1206 command_line
->CopySwitchesFrom(browser_command_line
, kCommonSwitchNames
,
1207 arraysize(kCommonSwitchNames
));
1209 #if defined(ENABLE_IPC_FUZZER)
1210 static const char* const kIpcFuzzerSwitches
[] = {
1211 switches::kIpcDumpDirectory
,
1212 switches::kIpcFuzzerTestcase
,
1214 command_line
->CopySwitchesFrom(browser_command_line
, kIpcFuzzerSwitches
,
1215 arraysize(kIpcFuzzerSwitches
));
1218 #if defined(OS_CHROMEOS)
1219 static const char* const kChromeOSSwitches
[] = {
1220 switches::kDisableDinosaurEasterEgg
,
1222 command_line
->CopySwitchesFrom(browser_command_line
, kChromeOSSwitches
,
1223 arraysize(kChromeOSSwitches
));
1225 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
1226 base::FilePath homedir
;
1227 PathService::Get(base::DIR_HOME
, &homedir
);
1228 command_line
->AppendSwitchASCII(chromeos::switches::kHomedir
,
1229 homedir
.value().c_str());
1232 #if defined(OS_POSIX) && !defined(OS_MACOSX)
1233 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
1234 if (process_type
!= switches::kZygoteProcess
) {
1235 command_line
->AppendSwitch(::switches::kV8NativesPassedByFD
);
1236 command_line
->AppendSwitch(::switches::kV8SnapshotPassedByFD
);
1238 #endif // V8_USE_EXTERNAL_STARTUP_DATA
1239 #endif // OS_POSIX && !OS_MACOSX
1241 if (process_type
== switches::kRendererProcess
) {
1242 content::RenderProcessHost
* process
=
1243 content::RenderProcessHost::FromID(child_process_id
);
1245 process
? Profile::FromBrowserContext(process
->GetBrowserContext())
1247 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
1248 extra_parts_
[i
]->AppendExtraRendererCommandLineSwitches(
1249 command_line
, process
, profile
);
1252 #if defined(OS_CHROMEOS)
1253 const std::string
& login_profile
=
1254 browser_command_line
.GetSwitchValueASCII(
1255 chromeos::switches::kLoginProfile
);
1256 if (!login_profile
.empty())
1257 command_line
->AppendSwitchASCII(
1258 chromeos::switches::kLoginProfile
, login_profile
);
1261 #if defined(ENABLE_WEBRTC)
1262 MaybeCopyDisableWebRtcEncryptionSwitch(command_line
,
1263 browser_command_line
,
1264 VersionInfo::GetChannel());
1268 PrefService
* prefs
= profile
->GetPrefs();
1269 // Currently this pref is only registered if applied via a policy.
1270 if (prefs
->HasPrefPath(prefs::kDisable3DAPIs
) &&
1271 prefs
->GetBoolean(prefs::kDisable3DAPIs
)) {
1272 // Turn this policy into a command line switch.
1273 command_line
->AppendSwitch(switches::kDisable3DAPIs
);
1276 const base::ListValue
* switches
=
1277 prefs
->GetList(prefs::kEnableDeprecatedWebPlatformFeatures
);
1279 // Enable any deprecated features that have been re-enabled by policy.
1280 for (base::ListValue::const_iterator it
= switches
->begin();
1281 it
!= switches
->end(); ++it
) {
1282 std::string switch_to_enable
;
1283 if ((*it
)->GetAsString(&switch_to_enable
))
1284 command_line
->AppendSwitch(switch_to_enable
);
1288 // Disable client-side phishing detection in the renderer if it is
1289 // disabled in the Profile preferences or the browser process.
1290 if (!prefs
->GetBoolean(prefs::kSafeBrowsingEnabled
) ||
1291 !g_browser_process
->safe_browsing_detection_service()) {
1292 command_line
->AppendSwitch(
1293 switches::kDisableClientSidePhishingDetection
);
1296 if (prefs
->GetBoolean(prefs::kPrintPreviewDisabled
))
1297 command_line
->AppendSwitch(switches::kDisablePrintPreview
);
1299 InstantService
* instant_service
=
1300 InstantServiceFactory::GetForProfile(profile
);
1301 if (instant_service
&&
1302 instant_service
->IsInstantProcess(process
->GetID()))
1303 command_line
->AppendSwitch(switches::kInstantProcess
);
1306 if (IsAutoReloadEnabled())
1307 command_line
->AppendSwitch(switches::kEnableOfflineAutoReload
);
1308 if (IsAutoReloadVisibleOnlyEnabled()) {
1309 command_line
->AppendSwitch(
1310 switches::kEnableOfflineAutoReloadVisibleOnly
);
1314 // Enable showing a saved copy if this session is in the field trial
1315 // or the user explicitly enabled it. Note that as far as the
1316 // renderer is concerned, the feature is enabled if-and-only-if
1317 // one of the kEnableShowSavedCopy* switches is on the command
1318 // line; the yes/no/default behavior is only at the browser
1319 // command line level.
1321 // Command line switches override
1322 const std::string
& show_saved_copy_value
=
1323 browser_command_line
.GetSwitchValueASCII(switches::kShowSavedCopy
);
1324 if (show_saved_copy_value
== switches::kEnableShowSavedCopyPrimary
||
1325 show_saved_copy_value
== switches::kEnableShowSavedCopySecondary
||
1326 show_saved_copy_value
== switches::kDisableShowSavedCopy
) {
1327 command_line
->AppendSwitchASCII(switches::kShowSavedCopy
,
1328 show_saved_copy_value
);
1331 base::FieldTrialList::FindFullName("LoadStaleCacheExperiment");
1333 if (group
== "Primary") {
1334 command_line
->AppendSwitchASCII(
1335 switches::kShowSavedCopy
, switches::kEnableShowSavedCopyPrimary
);
1336 } else if (group
== "Secondary") {
1337 command_line
->AppendSwitchASCII(
1338 switches::kShowSavedCopy
,
1339 switches::kEnableShowSavedCopySecondary
);
1344 // Please keep this in alphabetical order.
1345 static const char* const kSwitchNames
[] = {
1346 autofill::switches::kDisableFillOnAccountSelect
,
1347 autofill::switches::kDisablePasswordGeneration
,
1348 autofill::switches::kEnableFillOnAccountSelect
,
1349 autofill::switches::kEnableFillOnAccountSelectNoHighlighting
,
1350 autofill::switches::kEnablePasswordGeneration
,
1351 autofill::switches::kEnablePasswordSaveOnInPageNavigation
,
1352 autofill::switches::kEnableSingleClickAutofill
,
1353 autofill::switches::kIgnoreAutocompleteOffForAutofill
,
1354 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration
,
1355 #if defined(ENABLE_EXTENSIONS)
1356 extensions::switches::kAllowHTTPBackgroundPage
,
1357 extensions::switches::kAllowLegacyExtensionManifests
,
1358 extensions::switches::kEnableSurfaceWorker
,
1359 extensions::switches::kEnableAppWindowControls
,
1360 extensions::switches::kEnableEmbeddedExtensionOptions
,
1361 extensions::switches::kEnableExperimentalExtensionApis
,
1362 extensions::switches::kExtensionsOnChromeURLs
,
1363 extensions::switches::kWhitelistedExtensionID
,
1365 switches::kAllowInsecureLocalhost
,
1366 switches::kAppsCheckoutURL
,
1367 switches::kAppsGalleryURL
,
1368 switches::kCloudPrintURL
,
1369 switches::kCloudPrintXmppEndpoint
,
1370 switches::kDisableBundledPpapiFlash
,
1371 switches::kDisableCastStreamingHWEncoding
,
1372 switches::kDisableJavaScriptHarmonyShipping
,
1373 switches::kDisableNewBookmarkApps
,
1374 switches::kDisableOutOfProcessPdf
,
1375 switches::kEnableBenchmarking
,
1376 switches::kEnableNaCl
,
1377 #if !defined(DISABLE_NACL)
1378 switches::kEnableNaClDebug
,
1379 switches::kEnableNaClNonSfiMode
,
1380 switches::kEnablePNaClSubzero
,
1382 switches::kEnableNetBenchmarking
,
1383 switches::kEnableNewBookmarkApps
,
1384 switches::kEnableOutOfProcessPdf
,
1385 switches::kEnablePluginPlaceholderShadowDom
,
1386 switches::kJavaScriptHarmony
,
1387 switches::kMessageLoopHistogrammer
,
1388 switches::kPpapiFlashArgs
,
1389 switches::kPpapiFlashPath
,
1390 switches::kPpapiFlashVersion
,
1391 switches::kProfilingAtStart
,
1392 switches::kProfilingFile
,
1393 switches::kProfilingFlush
,
1394 translate::switches::kTranslateSecurityOrigin
,
1397 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1398 arraysize(kSwitchNames
));
1399 } else if (process_type
== switches::kUtilityProcess
) {
1400 #if defined(ENABLE_EXTENSIONS)
1401 static const char* const kSwitchNames
[] = {
1402 extensions::switches::kAllowHTTPBackgroundPage
,
1403 extensions::switches::kEnableExperimentalExtensionApis
,
1404 extensions::switches::kExtensionsOnChromeURLs
,
1405 extensions::switches::kWhitelistedExtensionID
,
1408 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1409 arraysize(kSwitchNames
));
1411 } else if (process_type
== switches::kPluginProcess
) {
1412 #if defined(OS_CHROMEOS)
1413 static const char* const kSwitchNames
[] = {
1414 chromeos::switches::kLoginProfile
,
1417 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1418 arraysize(kSwitchNames
));
1420 } else if (process_type
== switches::kZygoteProcess
) {
1421 static const char* const kSwitchNames
[] = {
1422 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
1423 switches::kDisableBundledPpapiFlash
,
1424 #if !defined(DISABLE_NACL)
1425 switches::kEnableNaClDebug
,
1426 switches::kEnableNaClNonSfiMode
,
1427 switches::kEnablePNaClSubzero
,
1428 switches::kNaClDangerousNoSandboxNonSfi
,
1429 switches::kUseNaClHelperNonSfi
,
1431 switches::kPpapiFlashPath
,
1432 switches::kPpapiFlashVersion
,
1435 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1436 arraysize(kSwitchNames
));
1437 } else if (process_type
== switches::kGpuProcess
) {
1438 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1439 // because GPU is expected to be unreliable.
1440 if (browser_command_line
.HasSwitch(switches::kIgnoreGpuBlacklist
) &&
1441 !command_line
->HasSwitch(switches::kDisableBreakpad
))
1442 command_line
->AppendSwitch(switches::kDisableBreakpad
);
1445 // The command line switch kEnableBenchmarking needs to be specified along
1446 // with the kEnableStatsTable switch to ensure that the stats table global
1447 // is initialized correctly.
1448 if (command_line
->HasSwitch(switches::kEnableBenchmarking
))
1449 DCHECK(command_line
->HasSwitch(switches::kEnableStatsTable
));
1452 std::string
ChromeContentBrowserClient::GetApplicationLocale() {
1453 if (BrowserThread::CurrentlyOn(BrowserThread::IO
))
1454 return g_io_thread_application_locale
.Get();
1455 return g_browser_process
->GetApplicationLocale();
1458 std::string
ChromeContentBrowserClient::GetAcceptLangs(
1459 content::BrowserContext
* context
) {
1460 Profile
* profile
= Profile::FromBrowserContext(context
);
1461 return profile
->GetPrefs()->GetString(prefs::kAcceptLanguages
);
1464 const gfx::ImageSkia
* ChromeContentBrowserClient::GetDefaultFavicon() {
1465 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
1466 return rb
.GetNativeImageNamed(IDR_DEFAULT_FAVICON
).ToImageSkia();
1469 bool ChromeContentBrowserClient::AllowAppCache(
1470 const GURL
& manifest_url
,
1471 const GURL
& first_party
,
1472 content::ResourceContext
* context
) {
1473 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1474 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1475 return io_data
->GetCookieSettings()->
1476 IsSettingCookieAllowed(manifest_url
, first_party
);
1479 bool ChromeContentBrowserClient::AllowServiceWorker(
1481 const GURL
& first_party_url
,
1482 content::ResourceContext
* context
) {
1483 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1484 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1485 return io_data
->GetCookieSettings()->
1486 IsSettingCookieAllowed(scope
, first_party_url
);
1489 bool ChromeContentBrowserClient::AllowGetCookie(
1491 const GURL
& first_party
,
1492 const net::CookieList
& cookie_list
,
1493 content::ResourceContext
* context
,
1494 int render_process_id
,
1495 int render_frame_id
) {
1496 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1497 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1498 bool allow
= io_data
->GetCookieSettings()->
1499 IsReadingCookieAllowed(url
, first_party
);
1501 BrowserThread::PostTask(
1502 BrowserThread::UI
, FROM_HERE
,
1503 base::Bind(&TabSpecificContentSettings::CookiesRead
, render_process_id
,
1504 render_frame_id
, url
, first_party
, cookie_list
, !allow
));
1508 bool ChromeContentBrowserClient::AllowSetCookie(
1510 const GURL
& first_party
,
1511 const std::string
& cookie_line
,
1512 content::ResourceContext
* context
,
1513 int render_process_id
,
1514 int render_frame_id
,
1515 net::CookieOptions
* options
) {
1516 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1517 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1518 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1519 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, first_party
);
1521 BrowserThread::PostTask(
1522 BrowserThread::UI
, FROM_HERE
,
1523 base::Bind(&TabSpecificContentSettings::CookieChanged
, render_process_id
,
1524 render_frame_id
, url
, first_party
, cookie_line
, *options
,
1529 bool ChromeContentBrowserClient::AllowSaveLocalState(
1530 content::ResourceContext
* context
) {
1531 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1532 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1533 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1534 ContentSetting setting
= cookie_settings
->GetDefaultCookieSetting(NULL
);
1536 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1537 // Could we even support per-origin settings?
1538 return setting
!= CONTENT_SETTING_SESSION_ONLY
;
1541 bool ChromeContentBrowserClient::AllowWorkerDatabase(
1543 const base::string16
& name
,
1544 const base::string16
& display_name
,
1545 unsigned long estimated_size
,
1546 content::ResourceContext
* context
,
1547 const std::vector
<std::pair
<int, int> >& render_frames
) {
1548 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1549 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1550 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1551 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1553 // Record access to database for potential display in UI.
1554 std::vector
<std::pair
<int, int> >::const_iterator i
;
1555 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1556 BrowserThread::PostTask(
1557 BrowserThread::UI
, FROM_HERE
,
1558 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed
,
1559 i
->first
, i
->second
, url
, name
, display_name
, !allow
));
1565 void ChromeContentBrowserClient::AllowWorkerFileSystem(
1567 content::ResourceContext
* context
,
1568 const std::vector
<std::pair
<int, int> >& render_frames
,
1569 base::Callback
<void(bool)> callback
) {
1570 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1571 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1572 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1573 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1575 #if defined(ENABLE_EXTENSIONS)
1576 GuestPermissionRequestHelper(url
, render_frames
, callback
, allow
);
1578 FileSystemAccessed(url
, render_frames
, callback
, allow
);
1582 #if defined(ENABLE_EXTENSIONS)
1583 void ChromeContentBrowserClient::GuestPermissionRequestHelper(
1585 const std::vector
<std::pair
<int, int> >& render_frames
,
1586 base::Callback
<void(bool)> callback
,
1588 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::IO
));
1589 std::vector
<std::pair
<int, int> >::const_iterator i
;
1590 std::map
<int, int> process_map
;
1591 std::map
<int, int>::const_iterator it
;
1592 bool has_web_view_guest
= false;
1593 // Record access to file system for potential display in UI.
1594 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1595 if (process_map
.find(i
->first
) != process_map
.end())
1598 process_map
.insert(std::pair
<int, int>(i
->first
, i
->second
));
1600 if (extensions::WebViewRendererState::GetInstance()->IsGuest(i
->first
))
1601 has_web_view_guest
= true;
1603 if (!has_web_view_guest
) {
1604 FileSystemAccessed(url
, render_frames
, callback
, allow
);
1607 DCHECK_EQ(1U, process_map
.size());
1608 it
= process_map
.begin();
1609 BrowserThread::PostTask(
1612 base::Bind(&ChromeContentBrowserClient::
1613 RequestFileSystemPermissionOnUIThread
,
1618 base::Bind(&ChromeContentBrowserClient::FileSystemAccessed
,
1619 weak_factory_
.GetWeakPtr(),
1625 void ChromeContentBrowserClient::RequestFileSystemPermissionOnUIThread(
1626 int render_process_id
,
1627 int render_frame_id
,
1629 bool allowed_by_default
,
1630 const base::Callback
<void(bool)>& callback
) {
1631 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::UI
));
1632 extensions::WebViewPermissionHelper
* web_view_permission_helper
=
1633 extensions::WebViewPermissionHelper::FromFrameID(
1634 render_process_id
, render_frame_id
);
1635 web_view_permission_helper
->RequestFileSystemPermission(url
,
1641 void ChromeContentBrowserClient::FileSystemAccessed(
1643 const std::vector
<std::pair
<int, int> >& render_frames
,
1644 base::Callback
<void(bool)> callback
,
1646 // Record access to file system for potential display in UI.
1647 std::vector
<std::pair
<int, int> >::const_iterator i
;
1648 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1649 BrowserThread::PostTask(
1652 base::Bind(&TabSpecificContentSettings::FileSystemAccessed
,
1653 i
->first
, i
->second
, url
, !allow
));
1655 callback
.Run(allow
);
1658 bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1660 const base::string16
& name
,
1661 content::ResourceContext
* context
,
1662 const std::vector
<std::pair
<int, int> >& render_frames
) {
1663 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1664 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1665 CookieSettings
* cookie_settings
= io_data
->GetCookieSettings();
1666 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1668 // Record access to IndexedDB for potential display in UI.
1669 std::vector
<std::pair
<int, int> >::const_iterator i
;
1670 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1671 BrowserThread::PostTask(
1672 BrowserThread::UI
, FROM_HERE
,
1673 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed
,
1674 i
->first
, i
->second
, url
, name
, !allow
));
1680 net::URLRequestContext
*
1681 ChromeContentBrowserClient::OverrideRequestContextForURL(
1682 const GURL
& url
, content::ResourceContext
* context
) {
1683 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1684 #if defined(ENABLE_EXTENSIONS)
1685 if (url
.SchemeIs(extensions::kExtensionScheme
)) {
1686 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1687 return io_data
->extensions_request_context();
1694 QuotaPermissionContext
*
1695 ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1696 return new ChromeQuotaPermissionContext();
1699 void ChromeContentBrowserClient::AllowCertificateError(
1700 int render_process_id
,
1701 int render_frame_id
,
1703 const net::SSLInfo
& ssl_info
,
1704 const GURL
& request_url
,
1705 ResourceType resource_type
,
1707 bool strict_enforcement
,
1708 bool expired_previous_decision
,
1709 const base::Callback
<void(bool)>& callback
,
1710 content::CertificateRequestResultType
* result
) {
1711 if (resource_type
!= content::RESOURCE_TYPE_MAIN_FRAME
) {
1712 // A sub-resource has a certificate error. The user doesn't really
1713 // have a context for making the right decision, so block the
1714 // request hard, without an info bar to allow showing the insecure
1716 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY
;
1720 // If the tab is being prerendered, cancel the prerender and the request.
1721 content::RenderFrameHost
* render_frame_host
=
1722 content::RenderFrameHost::FromID(render_process_id
, render_frame_id
);
1723 WebContents
* tab
= WebContents::FromRenderFrameHost(render_frame_host
);
1729 prerender::PrerenderContents
* prerender_contents
=
1730 prerender::PrerenderContents::FromWebContents(tab
);
1731 if (prerender_contents
) {
1732 prerender_contents
->Destroy(prerender::FINAL_STATUS_SSL_ERROR
);
1733 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL
;
1737 // Otherwise, display an SSL blocking page. The interstitial page takes
1738 // ownership of ssl_blocking_page.
1739 int options_mask
= 0;
1741 options_mask
|= SSLBlockingPage::OVERRIDABLE
;
1742 if (strict_enforcement
)
1743 options_mask
|= SSLBlockingPage::STRICT_ENFORCEMENT
;
1744 if (expired_previous_decision
)
1745 options_mask
|= SSLBlockingPage::EXPIRED_BUT_PREVIOUSLY_ALLOWED
;
1747 SafeBrowsingService
* safe_browsing_service
=
1748 g_browser_process
->safe_browsing_service();
1749 scoped_ptr
<SafeBrowsingSSLCertReporter
> cert_reporter(
1750 new SafeBrowsingSSLCertReporter(safe_browsing_service
1751 ? safe_browsing_service
->ui_manager()
1753 SSLErrorHandler::HandleSSLError(tab
, cert_error
, ssl_info
, request_url
,
1754 options_mask
, cert_reporter
.Pass(), callback
);
1757 void ChromeContentBrowserClient::SelectClientCertificate(
1758 content::WebContents
* web_contents
,
1759 net::SSLCertRequestInfo
* cert_request_info
,
1760 scoped_ptr
<content::ClientCertificateDelegate
> delegate
) {
1761 prerender::PrerenderContents
* prerender_contents
=
1762 prerender::PrerenderContents::FromWebContents(web_contents
);
1763 if (prerender_contents
) {
1764 prerender_contents
->Destroy(
1765 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED
);
1769 GURL
requesting_url("https://" + cert_request_info
->host_and_port
.ToString());
1770 DCHECK(requesting_url
.is_valid())
1771 << "Invalid URL string: https://"
1772 << cert_request_info
->host_and_port
.ToString();
1775 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
1776 scoped_ptr
<base::Value
> filter
=
1777 profile
->GetHostContentSettingsMap()->GetWebsiteSetting(
1780 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE
,
1785 // Try to automatically select a client certificate.
1786 if (filter
->IsType(base::Value::TYPE_DICTIONARY
)) {
1787 base::DictionaryValue
* filter_dict
=
1788 static_cast<base::DictionaryValue
*>(filter
.get());
1790 const std::vector
<scoped_refptr
<net::X509Certificate
> >&
1791 all_client_certs
= cert_request_info
->client_certs
;
1792 for (size_t i
= 0; i
< all_client_certs
.size(); ++i
) {
1793 if (CertMatchesFilter(*all_client_certs
[i
].get(), *filter_dict
)) {
1794 // Use the first certificate that is matched by the filter.
1795 delegate
->ContinueWithCertificate(all_client_certs
[i
].get());
1804 chrome::ShowSSLClientCertificateSelector(web_contents
, cert_request_info
,
1808 void ChromeContentBrowserClient::AddCertificate(
1809 net::CertificateMimeType cert_type
,
1810 const void* cert_data
,
1812 int render_process_id
,
1813 int render_frame_id
) {
1814 chrome::SSLAddCertificate(cert_type
, cert_data
, cert_size
,
1815 render_process_id
, render_frame_id
);
1818 content::MediaObserver
* ChromeContentBrowserClient::GetMediaObserver() {
1819 return MediaCaptureDevicesDispatcher::GetInstance();
1822 content::PlatformNotificationService
*
1823 ChromeContentBrowserClient::GetPlatformNotificationService() {
1824 #if defined(ENABLE_NOTIFICATIONS)
1825 return PlatformNotificationServiceImpl::GetInstance();
1832 bool ChromeContentBrowserClient::CanCreateWindow(
1833 const GURL
& opener_url
,
1834 const GURL
& opener_top_level_frame_url
,
1835 const GURL
& source_origin
,
1836 WindowContainerType container_type
,
1837 const GURL
& target_url
,
1838 const content::Referrer
& referrer
,
1839 WindowOpenDisposition disposition
,
1840 const WebWindowFeatures
& features
,
1842 bool opener_suppressed
,
1843 content::ResourceContext
* context
,
1844 int render_process_id
,
1846 bool* no_javascript_access
) {
1847 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1849 *no_javascript_access
= false;
1851 // If the opener is trying to create a background window but doesn't have
1852 // the appropriate permission, fail the attempt.
1853 if (container_type
== WINDOW_CONTAINER_TYPE_BACKGROUND
) {
1854 #if defined(ENABLE_EXTENSIONS)
1855 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1856 InfoMap
* map
= io_data
->GetExtensionInfoMap();
1857 if (!map
->SecurityOriginHasAPIPermission(
1860 APIPermission::kBackground
)) {
1864 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1865 // return a recently installed Extension even if this CanCreateWindow call
1866 // was made by an old copy of the page in a normal web process. That's ok,
1867 // because the permission check above would have caused an early return
1868 // already. We must use the full URL to find hosted apps, though, and not
1870 const Extension
* extension
=
1871 map
->extensions().GetExtensionOrAppByURL(opener_url
);
1872 if (extension
&& !extensions::BackgroundInfo::AllowJSAccess(extension
))
1873 *no_javascript_access
= true;
1879 #if defined(ENABLE_EXTENSIONS)
1880 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
1885 HostContentSettingsMap
* content_settings
=
1886 ProfileIOData::FromResourceContext(context
)->GetHostContentSettingsMap();
1887 BlockedWindowParams
blocked_params(target_url
,
1896 if (!user_gesture
&&
1897 !base::CommandLine::ForCurrentProcess()->HasSwitch(
1898 switches::kDisablePopupBlocking
)) {
1899 if (content_settings
->GetContentSetting(opener_top_level_frame_url
,
1900 opener_top_level_frame_url
,
1901 CONTENT_SETTINGS_TYPE_POPUPS
,
1903 CONTENT_SETTING_ALLOW
) {
1904 BrowserThread::PostTask(BrowserThread::UI
,
1906 base::Bind(&HandleBlockedPopupOnUIThread
,
1912 #if defined(OS_ANDROID)
1913 if (SingleTabModeTabHelper::IsRegistered(render_process_id
, opener_id
)) {
1914 BrowserThread::PostTask(BrowserThread::UI
,
1916 base::Bind(&HandleSingleTabModeBlockOnUIThread
,
1925 void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1926 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
1927 return g_browser_process
->ResourceDispatcherHostCreated();
1930 content::SpeechRecognitionManagerDelegate
*
1931 ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
1932 return new speech::ChromeSpeechRecognitionManagerDelegate();
1935 net::NetLog
* ChromeContentBrowserClient::GetNetLog() {
1936 return g_browser_process
->net_log();
1939 AccessTokenStore
* ChromeContentBrowserClient::CreateAccessTokenStore() {
1940 return new ChromeAccessTokenStore();
1943 bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1947 void ChromeContentBrowserClient::OverrideWebkitPrefs(
1948 RenderViewHost
* rvh
, WebPreferences
* web_prefs
) {
1949 Profile
* profile
= Profile::FromBrowserContext(
1950 rvh
->GetProcess()->GetBrowserContext());
1951 PrefService
* prefs
= profile
->GetPrefs();
1953 // Fill per-script font preferences. These are not registered on Android
1954 // - http://crbug.com/308033.
1955 #if !defined(OS_ANDROID)
1956 FontFamilyCache::FillFontFamilyMap(profile
,
1957 prefs::kWebKitStandardFontFamilyMap
,
1958 &web_prefs
->standard_font_family_map
);
1959 FontFamilyCache::FillFontFamilyMap(profile
,
1960 prefs::kWebKitFixedFontFamilyMap
,
1961 &web_prefs
->fixed_font_family_map
);
1962 FontFamilyCache::FillFontFamilyMap(profile
,
1963 prefs::kWebKitSerifFontFamilyMap
,
1964 &web_prefs
->serif_font_family_map
);
1965 FontFamilyCache::FillFontFamilyMap(profile
,
1966 prefs::kWebKitSansSerifFontFamilyMap
,
1967 &web_prefs
->sans_serif_font_family_map
);
1968 FontFamilyCache::FillFontFamilyMap(profile
,
1969 prefs::kWebKitCursiveFontFamilyMap
,
1970 &web_prefs
->cursive_font_family_map
);
1971 FontFamilyCache::FillFontFamilyMap(profile
,
1972 prefs::kWebKitFantasyFontFamilyMap
,
1973 &web_prefs
->fantasy_font_family_map
);
1974 FontFamilyCache::FillFontFamilyMap(profile
,
1975 prefs::kWebKitPictographFontFamilyMap
,
1976 &web_prefs
->pictograph_font_family_map
);
1979 web_prefs
->default_font_size
=
1980 prefs
->GetInteger(prefs::kWebKitDefaultFontSize
);
1981 web_prefs
->default_fixed_font_size
=
1982 prefs
->GetInteger(prefs::kWebKitDefaultFixedFontSize
);
1983 web_prefs
->minimum_font_size
=
1984 prefs
->GetInteger(prefs::kWebKitMinimumFontSize
);
1985 web_prefs
->minimum_logical_font_size
=
1986 prefs
->GetInteger(prefs::kWebKitMinimumLogicalFontSize
);
1988 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
1990 web_prefs
->javascript_can_open_windows_automatically
=
1991 prefs
->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically
);
1992 web_prefs
->dom_paste_enabled
=
1993 prefs
->GetBoolean(prefs::kWebKitDomPasteEnabled
);
1994 web_prefs
->shrinks_standalone_images_to_fit
=
1995 prefs
->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit
);
1996 web_prefs
->tabs_to_links
= prefs
->GetBoolean(prefs::kWebkitTabsToLinks
);
1998 if (!prefs
->GetBoolean(prefs::kWebKitJavascriptEnabled
))
1999 web_prefs
->javascript_enabled
= false;
2000 if (!prefs
->GetBoolean(prefs::kWebKitWebSecurityEnabled
))
2001 web_prefs
->web_security_enabled
= false;
2002 if (!prefs
->GetBoolean(prefs::kWebKitPluginsEnabled
))
2003 web_prefs
->plugins_enabled
= false;
2004 if (!prefs
->GetBoolean(prefs::kWebKitJavaEnabled
))
2005 web_prefs
->java_enabled
= false;
2006 web_prefs
->loads_images_automatically
=
2007 prefs
->GetBoolean(prefs::kWebKitLoadsImagesAutomatically
);
2009 if (prefs
->GetBoolean(prefs::kDisable3DAPIs
))
2010 web_prefs
->experimental_webgl_enabled
= false;
2012 web_prefs
->allow_displaying_insecure_content
=
2013 prefs
->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent
);
2014 web_prefs
->allow_running_insecure_content
=
2015 prefs
->GetBoolean(prefs::kWebKitAllowRunningInsecureContent
);
2016 #if defined(OS_ANDROID)
2017 web_prefs
->font_scale_factor
=
2018 static_cast<float>(prefs
->GetDouble(prefs::kWebKitFontScaleFactor
));
2019 web_prefs
->device_scale_adjustment
= GetDeviceScaleAdjustment();
2020 web_prefs
->force_enable_zoom
=
2021 prefs
->GetBoolean(prefs::kWebKitForceEnableZoom
);
2024 #if defined(OS_ANDROID)
2025 web_prefs
->password_echo_enabled
=
2026 prefs
->GetBoolean(prefs::kWebKitPasswordEchoEnabled
);
2028 web_prefs
->password_echo_enabled
= browser_defaults::kPasswordEchoEnabled
;
2031 web_prefs
->asynchronous_spell_checking_enabled
= true;
2032 web_prefs
->unified_textchecker_enabled
= true;
2034 web_prefs
->uses_universal_detector
=
2035 prefs
->GetBoolean(prefs::kWebKitUsesUniversalDetector
);
2036 web_prefs
->text_areas_are_resizable
=
2037 prefs
->GetBoolean(prefs::kWebKitTextAreasAreResizable
);
2038 web_prefs
->hyperlink_auditing_enabled
=
2039 prefs
->GetBoolean(prefs::kEnableHyperlinkAuditing
);
2041 #if defined(ENABLE_EXTENSIONS)
2042 std::string image_animation_policy
=
2043 prefs
->GetString(prefs::kAnimationPolicy
);
2044 if (image_animation_policy
== kAnimationPolicyOnce
)
2045 web_prefs
->animation_policy
=
2046 content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE
;
2047 else if (image_animation_policy
== kAnimationPolicyNone
)
2048 web_prefs
->animation_policy
= content::IMAGE_ANIMATION_POLICY_NO_ANIMATION
;
2050 web_prefs
->animation_policy
= content::IMAGE_ANIMATION_POLICY_ALLOWED
;
2053 // Make sure we will set the default_encoding with canonical encoding name.
2054 web_prefs
->default_encoding
=
2055 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
2056 web_prefs
->default_encoding
);
2057 if (web_prefs
->default_encoding
.empty()) {
2058 prefs
->ClearPref(prefs::kDefaultCharset
);
2059 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2061 DCHECK(!web_prefs
->default_encoding
.empty());
2063 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2064 switches::kEnablePotentiallyAnnoyingSecurityFeatures
)) {
2065 web_prefs
->disable_reading_from_canvas
= true;
2066 web_prefs
->strict_mixed_content_checking
= true;
2067 web_prefs
->strict_powerful_feature_restrictions
= true;
2070 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2071 extra_parts_
[i
]->OverrideWebkitPrefs(rvh
, web_prefs
);
2074 void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2075 BrowserURLHandler
* handler
) {
2076 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2077 extra_parts_
[i
]->BrowserURLHandlerCreated(handler
);
2079 // about: handler. Must come before chrome: handler, since it will
2080 // rewrite about: urls to chrome: URLs and then expect chrome: to
2081 // actually handle them. Also relies on a preliminary fixup phase.
2082 handler
->SetFixupHandler(&FixupBrowserAboutURL
);
2083 handler
->AddHandlerPair(&WillHandleBrowserAboutURL
,
2084 BrowserURLHandler::null_handler());
2086 #if defined(OS_ANDROID)
2087 // Handler to rewrite chrome://newtab on Android.
2088 handler
->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL
,
2089 BrowserURLHandler::null_handler());
2091 // Handler to rewrite chrome://newtab for InstantExtended.
2092 handler
->AddHandlerPair(&chrome::HandleNewTabURLRewrite
,
2093 &chrome::HandleNewTabURLReverseRewrite
);
2096 // chrome: & friends.
2097 handler
->AddHandlerPair(&HandleWebUI
, &HandleWebUIReverse
);
2100 void ChromeContentBrowserClient::ClearCache(RenderFrameHost
* rfh
) {
2101 Profile
* profile
= Profile::FromBrowserContext(
2102 rfh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2103 BrowsingDataRemover
* remover
=
2104 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2105 remover
->Remove(BrowsingDataRemover::REMOVE_CACHE
,
2106 BrowsingDataHelper::UNPROTECTED_WEB
);
2107 // BrowsingDataRemover takes care of deleting itself when done.
2110 void ChromeContentBrowserClient::ClearCookies(RenderFrameHost
* rfh
) {
2111 Profile
* profile
= Profile::FromBrowserContext(
2112 rfh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2113 BrowsingDataRemover
* remover
=
2114 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2115 int remove_mask
= BrowsingDataRemover::REMOVE_SITE_DATA
;
2116 remover
->Remove(remove_mask
, BrowsingDataHelper::UNPROTECTED_WEB
);
2117 // BrowsingDataRemover takes care of deleting itself when done.
2120 base::FilePath
ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
2121 return DownloadPrefs::GetDefaultDownloadDirectory();
2124 std::string
ChromeContentBrowserClient::GetDefaultDownloadName() {
2125 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME
);
2128 void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2129 content::BrowserPpapiHost
* browser_host
) {
2130 #if defined(ENABLE_PLUGINS)
2131 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host
);
2135 content::BrowserPpapiHost
*
2136 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2137 int plugin_process_id
) {
2138 #if !defined(DISABLE_NACL)
2139 content::BrowserChildProcessHostIterator
iter(PROCESS_TYPE_NACL_LOADER
);
2140 while (!iter
.Done()) {
2141 nacl::NaClProcessHost
* host
= static_cast<nacl::NaClProcessHost
*>(
2142 iter
.GetDelegate());
2143 if (host
->process() &&
2144 host
->process()->GetData().id
== plugin_process_id
) {
2145 // Found the plugin.
2146 return host
->browser_ppapi_host();
2154 bool ChromeContentBrowserClient::AllowPepperSocketAPI(
2155 content::BrowserContext
* browser_context
,
2158 const content::SocketPermissionRequest
* params
) {
2159 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2160 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
2161 browser_context
, url
, private_api
, params
, allowed_socket_origins_
);
2167 ui::SelectFilePolicy
* ChromeContentBrowserClient::CreateSelectFilePolicy(
2168 WebContents
* web_contents
) {
2169 return new ChromeSelectFilePolicy(web_contents
);
2172 void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2173 std::vector
<std::string
>* additional_allowed_schemes
) {
2174 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2175 additional_allowed_schemes
);
2176 additional_allowed_schemes
->push_back(content::kChromeDevToolsScheme
);
2177 additional_allowed_schemes
->push_back(content::kChromeUIScheme
);
2178 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
2179 extra_parts_
[i
]->GetAdditionalAllowedSchemesForFileSystem(
2180 additional_allowed_schemes
);
2184 void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
2185 std::vector
<storage::URLRequestAutoMountHandler
>* handlers
) {
2186 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2187 extra_parts_
[i
]->GetURLRequestAutoMountHandlers(handlers
);
2190 void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
2191 content::BrowserContext
* browser_context
,
2192 const base::FilePath
& storage_partition_path
,
2193 ScopedVector
<storage::FileSystemBackend
>* additional_backends
) {
2194 #if defined(OS_CHROMEOS)
2195 storage::ExternalMountPoints
* external_mount_points
=
2196 content::BrowserContext::GetMountPoints(browser_context
);
2197 DCHECK(external_mount_points
);
2198 chromeos::FileSystemBackend
* backend
= new chromeos::FileSystemBackend(
2199 new drive::FileSystemBackendDelegate
,
2200 new chromeos::file_system_provider::BackendDelegate
,
2201 new chromeos::MTPFileSystemBackendDelegate(storage_partition_path
),
2202 external_mount_points
,
2203 storage::ExternalMountPoints::GetSystemInstance());
2204 backend
->AddSystemMountPoints();
2205 DCHECK(backend
->CanHandleType(storage::kFileSystemTypeExternal
));
2206 additional_backends
->push_back(backend
);
2209 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
2210 extra_parts_
[i
]->GetAdditionalFileSystemBackends(
2211 browser_context
, storage_partition_path
, additional_backends
);
2215 #if defined(OS_POSIX) && !defined(OS_MACOSX)
2216 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2217 const base::CommandLine
& command_line
,
2218 int child_process_id
,
2219 FileDescriptorInfo
* mappings
) {
2220 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
2221 if (v8_natives_fd_
.get() == -1 || v8_snapshot_fd_
.get() == -1) {
2222 int v8_natives_fd
= -1;
2223 int v8_snapshot_fd
= -1;
2224 if (gin::V8Initializer::OpenV8FilesForChildProcesses(&v8_natives_fd
,
2226 v8_natives_fd_
.reset(v8_natives_fd
);
2227 v8_snapshot_fd_
.reset(v8_snapshot_fd
);
2230 DCHECK(v8_natives_fd_
.get() != -1 && v8_snapshot_fd_
.get() != -1);
2231 mappings
->Share(kV8NativesDataDescriptor
, v8_natives_fd_
.get());
2232 mappings
->Share(kV8SnapshotDataDescriptor
, v8_snapshot_fd_
.get());
2233 #endif // V8_USE_EXTERNAL_STARTUP_DATA
2235 #if defined(OS_ANDROID)
2236 base::FilePath data_path
;
2237 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID
, &data_path
);
2238 DCHECK(!data_path
.empty());
2240 int flags
= base::File::FLAG_OPEN
| base::File::FLAG_READ
;
2241 base::FilePath chrome_resources_pak
=
2242 data_path
.AppendASCII("chrome_100_percent.pak");
2243 base::File
file(chrome_resources_pak
, flags
);
2244 DCHECK(file
.IsValid());
2245 mappings
->Transfer(kAndroidChrome100PercentPakDescriptor
,
2246 base::ScopedFD(file
.TakePlatformFile()));
2248 const std::string locale
= GetApplicationLocale();
2249 base::FilePath locale_pak
= ResourceBundle::GetSharedInstance().
2250 GetLocaleFilePath(locale
, false);
2251 file
.Initialize(locale_pak
, flags
);
2252 DCHECK(file
.IsValid());
2253 mappings
->Transfer(kAndroidLocalePakDescriptor
,
2254 base::ScopedFD(file
.TakePlatformFile()));
2256 base::FilePath resources_pack_path
;
2257 PathService::Get(chrome::FILE_RESOURCES_PACK
, &resources_pack_path
);
2258 file
.Initialize(resources_pack_path
, flags
);
2259 DCHECK(file
.IsValid());
2260 mappings
->Transfer(kAndroidUIResourcesPakDescriptor
,
2261 base::ScopedFD(file
.TakePlatformFile()));
2263 if (breakpad::IsCrashReporterEnabled()) {
2264 file
= breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile(
2266 if (file
.IsValid()) {
2267 mappings
->Transfer(kAndroidMinidumpDescriptor
,
2268 base::ScopedFD(file
.TakePlatformFile()));
2270 LOG(ERROR
) << "Failed to create file for minidump, crash reporting will "
2271 "be disabled for this process.";
2275 base::FilePath app_data_path
;
2276 PathService::Get(base::DIR_ANDROID_APP_DATA
, &app_data_path
);
2277 DCHECK(!app_data_path
.empty());
2279 flags
= base::File::FLAG_OPEN
| base::File::FLAG_READ
;
2280 base::FilePath icudata_path
=
2281 app_data_path
.AppendASCII(base::i18n::kIcuDataFileName
);
2282 base::File
icudata_file(icudata_path
, flags
);
2283 DCHECK(icudata_file
.IsValid());
2284 mappings
->Transfer(kAndroidICUDataDescriptor
,
2285 base::ScopedFD(icudata_file
.TakePlatformFile()));
2287 int crash_signal_fd
= GetCrashSignalFD(command_line
);
2288 if (crash_signal_fd
>= 0) {
2289 mappings
->Share(kCrashDumpSignal
, crash_signal_fd
);
2291 #endif // defined(OS_ANDROID)
2293 #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
2296 const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2297 return chrome::kBrowserResourcesDll
;
2300 void ChromeContentBrowserClient::PreSpawnRenderer(
2301 sandbox::TargetPolicy
* policy
,
2303 // This code is duplicated in nacl_exe_win_64.cc.
2304 // Allow the server side of a pipe restricted to the "chrome.nacl."
2305 // namespace so that it cannot impersonate other system or other chrome
2307 sandbox::ResultCode result
= policy
->AddRule(
2308 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES
,
2309 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY
,
2310 L
"\\\\.\\pipe\\chrome.nacl.*");
2311 if (result
!= sandbox::SBOX_ALL_OK
) {
2316 // Renderers need to send named pipe handles and shared memory
2317 // segment handles to NaCl loader processes.
2318 result
= policy
->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES
,
2319 sandbox::TargetPolicy::HANDLES_DUP_ANY
,
2321 if (result
!= sandbox::SBOX_ALL_OK
) {
2328 bool ChromeContentBrowserClient::CheckMediaAccessPermission(
2329 content::BrowserContext
* browser_context
,
2330 const GURL
& security_origin
,
2331 content::MediaStreamType type
) {
2332 return MediaCaptureDevicesDispatcher::GetInstance()
2333 ->CheckMediaAccessPermission(
2334 browser_context
, security_origin
, type
);
2337 void ChromeContentBrowserClient::OpenURL(
2338 content::BrowserContext
* browser_context
,
2339 const content::OpenURLParams
& params
,
2340 const base::Callback
<void(content::WebContents
*)>& callback
) {
2341 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
2343 #if !defined(OS_ANDROID) && !defined(OS_IOS)
2344 NavigateParams
nav_params(Profile::FromBrowserContext(browser_context
),
2347 FillNavigateParamsFromOpenURLParams(&nav_params
, params
);
2348 nav_params
.user_gesture
= params
.user_gesture
;
2350 Navigate(&nav_params
);
2351 callback
.Run(nav_params
.target_contents
);
2352 #elif defined(OS_ANDROID)
2353 chrome::android::ServiceTabLauncher::GetInstance()->LaunchTab(
2354 browser_context
, params
, callback
);
2360 void ChromeContentBrowserClient::RecordURLMetric(const std::string
& metric
,
2362 if (url
.is_valid()) {
2363 rappor::SampleDomainAndRegistryFromGURL(g_browser_process
->rappor_service(),
2368 content::DevToolsManagerDelegate
*
2369 ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
2370 #if defined(OS_ANDROID)
2371 return new DevToolsManagerDelegateAndroid();
2373 return new ChromeDevToolsManagerDelegate();
2377 content::TracingDelegate
* ChromeContentBrowserClient::GetTracingDelegate() {
2378 #if !defined(OS_ANDROID)
2379 return new ChromeTracingDelegate();
2385 bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2386 content::BrowserContext
* browser_context
,
2388 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2389 return ChromeContentBrowserClientPluginsPart::
2390 IsPluginAllowedToCallRequestOSFileHandle(browser_context
, url
,
2391 allowed_file_handle_origins_
);
2397 bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
2398 content::BrowserContext
* browser_context
,
2400 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2401 return ChromeContentBrowserClientPluginsPart::
2402 IsPluginAllowedToUseDevChannelAPIs(browser_context
, url
,
2403 allowed_dev_channel_origins_
);
2409 void ChromeContentBrowserClient::OverridePageVisibilityState(
2410 RenderFrameHost
* render_frame_host
,
2411 blink::WebPageVisibilityState
* visibility_state
) {
2412 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
2414 WebContents
* web_contents
=
2415 WebContents::FromRenderFrameHost(render_frame_host
);
2416 DCHECK(web_contents
);
2419 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
2420 prerender::PrerenderManager
* prerender_manager
=
2421 prerender::PrerenderManagerFactory::GetForProfile(profile
);
2422 if (prerender_manager
&&
2423 prerender_manager
->IsWebContentsPrerendering(web_contents
, nullptr)) {
2424 *visibility_state
= blink::WebPageVisibilityStatePrerender
;
2428 #if defined(ENABLE_WEBRTC)
2429 void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
2430 base::CommandLine
* to_command_line
,
2431 const base::CommandLine
& from_command_line
,
2432 VersionInfo::Channel channel
) {
2433 #if defined(OS_ANDROID)
2434 const VersionInfo::Channel kMaxDisableEncryptionChannel
=
2435 VersionInfo::CHANNEL_BETA
;
2437 const VersionInfo::Channel kMaxDisableEncryptionChannel
=
2438 VersionInfo::CHANNEL_DEV
;
2440 if (channel
<= kMaxDisableEncryptionChannel
) {
2441 static const char* const kWebRtcDevSwitchNames
[] = {
2442 switches::kDisableWebRtcEncryption
,
2444 to_command_line
->CopySwitchesFrom(from_command_line
,
2445 kWebRtcDevSwitchNames
,
2446 arraysize(kWebRtcDevSwitchNames
));
2449 #endif // defined(ENABLE_WEBRTC)
2451 } // namespace chrome