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"
12 #include "base/bind.h"
13 #include "base/bind_helpers.h"
14 #include "base/command_line.h"
15 #include "base/files/scoped_file.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/string_util.h"
22 #include "base/strings/stringprintf.h"
23 #include "base/strings/utf_string_conversions.h"
24 #include "base/thread_task_runner_handle.h"
25 #include "base/threading/sequenced_worker_pool.h"
26 #include "chrome/browser/after_startup_task_utils.h"
27 #include "chrome/browser/browser_about_handler.h"
28 #include "chrome/browser/browser_process.h"
29 #include "chrome/browser/browser_shutdown.h"
30 #include "chrome/browser/browsing_data/browsing_data_helper.h"
31 #include "chrome/browser/browsing_data/browsing_data_remover.h"
32 #include "chrome/browser/character_encoding.h"
33 #include "chrome/browser/chrome_content_browser_client_parts.h"
34 #include "chrome/browser/chrome_net_benchmarking_message_filter.h"
35 #include "chrome/browser/chrome_quota_permission_context.h"
36 #include "chrome/browser/content_settings/cookie_settings_factory.h"
37 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
38 #include "chrome/browser/defaults.h"
39 #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
40 #include "chrome/browser/download/download_prefs.h"
41 #include "chrome/browser/font_family_cache.h"
42 #include "chrome/browser/geolocation/chrome_access_token_store.h"
43 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
44 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
45 #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
46 #include "chrome/browser/net/chrome_net_log.h"
47 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
48 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h"
49 #include "chrome/browser/notifications/platform_notification_service_impl.h"
50 #include "chrome/browser/platform_util.h"
51 #include "chrome/browser/prerender/prerender_final_status.h"
52 #include "chrome/browser/prerender/prerender_manager.h"
53 #include "chrome/browser/prerender/prerender_manager_factory.h"
54 #include "chrome/browser/prerender/prerender_message_filter.h"
55 #include "chrome/browser/printing/printing_message_filter.h"
56 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
57 #include "chrome/browser/profiles/profile.h"
58 #include "chrome/browser/profiles/profile_io_data.h"
59 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
60 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
61 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
62 #include "chrome/browser/safe_browsing/ui_manager.h"
63 #include "chrome/browser/search/instant_service.h"
64 #include "chrome/browser/search/instant_service_factory.h"
65 #include "chrome/browser/search/search.h"
66 #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
67 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
68 #include "chrome/browser/speech/tts_controller.h"
69 #include "chrome/browser/speech/tts_message_filter.h"
70 #include "chrome/browser/ssl/ssl_add_certificate.h"
71 #include "chrome/browser/ssl/ssl_blocking_page.h"
72 #include "chrome/browser/ssl/ssl_cert_reporter.h"
73 #include "chrome/browser/ssl/ssl_client_certificate_selector.h"
74 #include "chrome/browser/ssl/ssl_error_handler.h"
75 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
76 #include "chrome/browser/tab_contents/tab_util.h"
77 #include "chrome/browser/tracing/chrome_tracing_delegate.h"
78 #include "chrome/browser/ui/blocked_content/blocked_window_params.h"
79 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
80 #include "chrome/browser/ui/chrome_select_file_policy.h"
81 #include "chrome/browser/ui/sync/sync_promo_ui.h"
82 #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
83 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
84 #include "chrome/common/channel_info.h"
85 #include "chrome/common/chrome_constants.h"
86 #include "chrome/common/chrome_paths.h"
87 #include "chrome/common/chrome_switches.h"
88 #include "chrome/common/env_vars.h"
89 #include "chrome/common/logging_chrome.h"
90 #include "chrome/common/pepper_permission_util.h"
91 #include "chrome/common/pref_names.h"
92 #include "chrome/common/render_messages.h"
93 #include "chrome/common/url_constants.h"
94 #include "chrome/grit/generated_resources.h"
95 #include "chrome/installer/util/google_update_settings.h"
96 #include "chromeos/chromeos_constants.h"
97 #include "components/cdm/browser/cdm_message_filter_android.h"
98 #include "components/cloud_devices/common/cloud_devices_switches.h"
99 #include "components/content_settings/core/browser/content_settings_utils.h"
100 #include "components/content_settings/core/browser/cookie_settings.h"
101 #include "components/content_settings/core/browser/host_content_settings_map.h"
102 #include "components/content_settings/core/common/content_settings.h"
103 #include "components/data_reduction_proxy/content/browser/data_reduction_proxy_message_filter.h"
104 #include "components/dom_distiller/core/url_constants.h"
105 #include "components/google/core/browser/google_util.h"
106 #include "components/metrics/client_info.h"
107 #include "components/pref_registry/pref_registry_syncable.h"
108 #include "components/rappor/rappor_utils.h"
109 #include "components/signin/core/common/profile_management_switches.h"
110 #include "components/translate/core/common/translate_switches.h"
111 #include "components/url_formatter/url_fixer.h"
112 #include "components/variations/variations_associated_data.h"
113 #include "components/version_info/version_info.h"
114 #include "content/public/browser/browser_child_process_host.h"
115 #include "content/public/browser/browser_main_parts.h"
116 #include "content/public/browser/browser_ppapi_host.h"
117 #include "content/public/browser/browser_thread.h"
118 #include "content/public/browser/browser_url_handler.h"
119 #include "content/public/browser/child_process_data.h"
120 #include "content/public/browser/child_process_security_policy.h"
121 #include "content/public/browser/client_certificate_delegate.h"
122 #include "content/public/browser/render_frame_host.h"
123 #include "content/public/browser/render_process_host.h"
124 #include "content/public/browser/render_view_host.h"
125 #include "content/public/browser/resource_context.h"
126 #include "content/public/browser/site_instance.h"
127 #include "content/public/browser/web_contents.h"
128 #include "content/public/common/child_process_host.h"
129 #include "content/public/common/content_descriptors.h"
130 #include "content/public/common/sandbox_type.h"
131 #include "content/public/common/service_registry.h"
132 #include "content/public/common/url_utils.h"
133 #include "content/public/common/web_preferences.h"
134 #include "device/devices_app/public/cpp/constants.h"
135 #include "device/devices_app/public/cpp/devices_app_factory.h"
136 #include "gin/v8_initializer.h"
137 #include "mojo/application/public/cpp/application_delegate.h"
138 #include "net/base/mime_util.h"
139 #include "net/cookies/canonical_cookie.h"
140 #include "net/cookies/cookie_options.h"
141 #include "net/ssl/ssl_cert_request_info.h"
142 #include "ppapi/host/ppapi_host.h"
143 #include "storage/browser/fileapi/external_mount_points.h"
144 #include "ui/base/l10n/l10n_util.h"
145 #include "ui/base/resource/resource_bundle.h"
146 #include "ui/resources/grit/ui_resources.h"
149 #include "base/win/windows_version.h"
150 #include "chrome/browser/chrome_browser_main_win.h"
151 #include "sandbox/win/src/sandbox_policy.h"
152 #elif defined(OS_MACOSX)
153 #include "chrome/browser/chrome_browser_main_mac.h"
154 #elif defined(OS_CHROMEOS)
155 #include "chrome/browser/chromeos/attestation/platform_verification_impl.h"
156 #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
157 #include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h"
158 #include "chrome/browser/chromeos/file_manager/app_id.h"
159 #include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
160 #include "chrome/browser/chromeos/fileapi/file_system_backend.h"
161 #include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
162 #include "chrome/browser/chromeos/login/startup_utils.h"
163 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
164 #include "chrome/browser/chromeos/system/input_device_settings.h"
165 #include "chromeos/chromeos_switches.h"
166 #include "components/user_manager/user_manager.h"
167 #elif defined(OS_LINUX)
168 #include "chrome/browser/chrome_browser_main_linux.h"
169 #elif defined(OS_ANDROID)
170 #include "chrome/browser/android/new_tab_page_url_handler.h"
171 #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
172 #include "chrome/browser/chrome_browser_main_android.h"
173 #include "chrome/common/descriptors_android.h"
174 #include "components/crash/browser/crash_dump_manager_android.h"
175 #include "components/service_tab_launcher/browser/android/service_tab_launcher.h"
176 #include "ui/base/resource/resource_bundle_android.h"
177 #elif defined(OS_POSIX)
178 #include "chrome/browser/chrome_browser_main_posix.h"
181 #if defined(OS_POSIX) && !defined(OS_MACOSX)
182 #include "base/debug/leak_annotations.h"
183 #include "components/crash/app/breakpad_linux.h"
184 #include "components/crash/browser/crash_handler_host_linux.h"
187 #if defined(OS_ANDROID)
188 #include "ui/base/ui_base_paths.h"
189 #include "ui/gfx/android/device_display_info.h"
192 #if defined(TOOLKIT_VIEWS)
193 #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
197 #include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
200 #if defined(USE_AURA)
201 #include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
205 #include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
208 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
209 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
212 #if !defined(DISABLE_NACL)
213 #include "components/nacl/browser/nacl_browser.h"
214 #include "components/nacl/browser/nacl_host_message_filter.h"
215 #include "components/nacl/browser/nacl_process_host.h"
216 #include "components/nacl/common/nacl_process_type.h"
217 #include "components/nacl/common/nacl_switches.h"
220 #if defined(ENABLE_EXTENSIONS)
221 #include "chrome/browser/accessibility/animation_policy_prefs.h"
222 #include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
223 #include "chrome/browser/media/cast_transport_host_filter.h"
224 #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
225 #include "components/guest_view/browser/guest_view_base.h"
226 #include "components/guest_view/browser/guest_view_manager.h"
227 #include "extensions/browser/extension_registry.h"
228 #include "extensions/browser/extension_util.h"
229 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
230 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
231 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
232 #include "extensions/common/constants.h"
233 #include "extensions/common/extension.h"
234 #include "extensions/common/extension_set.h"
235 #include "extensions/common/manifest_handlers/background_info.h"
236 #include "extensions/common/manifest_handlers/shared_module_info.h"
237 #include "extensions/common/permissions/permissions_data.h"
238 #include "extensions/common/permissions/socket_permission.h"
239 #include "extensions/common/switches.h"
242 #if defined(ENABLE_PLUGINS)
243 #include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
246 #if defined(ENABLE_SPELLCHECK)
247 #include "chrome/browser/spellchecker/spellcheck_message_filter.h"
250 #if defined(USE_BROWSER_SPELLCHECKER)
251 #include "chrome/browser/spellchecker/spellcheck_message_filter_platform.h"
254 #if defined(ENABLE_WEBRTC)
255 #include "chrome/browser/media/webrtc_logging_handler_host.h"
258 #if defined(ENABLE_MEDIA_ROUTER)
259 #include "chrome/browser/media/router/presentation_service_delegate_impl.h"
262 using base::FileDescriptor
;
263 using blink::WebWindowFeatures
;
264 using content::AccessTokenStore
;
265 using content::BrowserThread
;
266 using content::BrowserURLHandler
;
267 using content::ChildProcessSecurityPolicy
;
268 using content::QuotaPermissionContext
;
269 using content::RenderFrameHost
;
270 using content::RenderViewHost
;
271 using content::ResourceType
;
272 using content::SiteInstance
;
273 using content::WebContents
;
274 using content::WebPreferences
;
275 using message_center::NotifierId
;
277 #if defined(OS_POSIX)
278 using content::FileDescriptorInfo
;
281 #if defined(ENABLE_EXTENSIONS)
282 using extensions::APIPermission
;
283 using extensions::ChromeContentBrowserClientExtensionsPart
;
284 using extensions::Extension
;
285 using extensions::InfoMap
;
286 using extensions::Manifest
;
289 #if defined(ENABLE_PLUGINS)
290 using plugins::ChromeContentBrowserClientPluginsPart
;
295 // Cached version of the locale so we can return the locale on the I/O
297 base::LazyInstance
<std::string
> g_io_thread_application_locale
;
299 #if defined(ENABLE_PLUGINS)
300 // TODO(teravest): Add renderer-side API-specific checking for these APIs so
301 // that blanket permission isn't granted to all dev channel APIs for these.
302 // http://crbug.com/386743
303 const char* const kPredefinedAllowedDevChannelOrigins
[] = {
304 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/383937
305 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/383937
308 const char* const kPredefinedAllowedFileHandleOrigins
[] = {
309 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
310 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
313 const char* const kPredefinedAllowedSocketOrigins
[] = {
314 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
315 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
316 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
317 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
318 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
319 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
320 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
321 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
322 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
323 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
324 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
325 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
326 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
327 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
328 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
329 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
330 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
331 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
332 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
333 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
337 // Returns a copy of the given url with its host set to given host and path set
338 // to given path. Other parts of the url will be the same.
339 GURL
ReplaceURLHostAndPath(const GURL
& url
,
340 const std::string
& host
,
341 const std::string
& path
) {
342 url::Replacements
<char> replacements
;
343 replacements
.SetHost(host
.c_str(), url::Component(0, host
.length()));
344 replacements
.SetPath(path
.c_str(), url::Component(0, path
.length()));
345 return url
.ReplaceComponents(replacements
);
348 // Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
349 GURL
AddUberHost(const GURL
& url
) {
350 const std::string uber_host
= chrome::kChromeUIUberHost
;
351 const std::string new_path
= url
.host() + url
.path();
353 return ReplaceURLHostAndPath(url
, uber_host
, new_path
);
356 // If url->host() is "chrome" and url->path() has characters other than the
357 // first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
358 // returns true. Otherwise returns false.
359 bool RemoveUberHost(GURL
* url
) {
360 if (url
->host() != chrome::kChromeUIUberHost
)
363 if (url
->path().empty() || url
->path() == "/")
366 const std::string old_path
= url
->path();
368 const std::string::size_type separator
= old_path
.find('/', 1);
369 std::string new_host
;
370 std::string new_path
;
371 if (separator
== std::string::npos
) {
372 new_host
= old_path
.substr(1);
374 new_host
= old_path
.substr(1, separator
- 1);
375 new_path
= old_path
.substr(separator
);
378 // Do not allow URLs with paths empty before the first slash since we can't
379 // have an empty host. (e.g "foo://chrome//")
380 if (new_host
.empty())
383 *url
= ReplaceURLHostAndPath(*url
, new_host
, new_path
);
385 DCHECK(url
->is_valid());
390 // Handles rewriting Web UI URLs.
391 bool HandleWebUI(GURL
* url
, content::BrowserContext
* browser_context
) {
392 // Do not handle special URLs such as "about:foo"
393 if (!url
->host().empty()) {
394 const GURL chrome_url
= AddUberHost(*url
);
396 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
398 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
399 browser_context
, chrome_url
))
403 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
404 browser_context
, *url
))
407 #if defined(OS_CHROMEOS)
408 // Special case : in ChromeOS in Guest mode bookmarks and history are
409 // disabled for security reasons. New tab page explains the reasons, so
410 // we redirect user to new tab page.
411 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
412 if (url
->SchemeIs(content::kChromeUIScheme
) &&
413 (url
->DomainIs(chrome::kChromeUIBookmarksHost
) ||
414 url
->DomainIs(chrome::kChromeUIHistoryHost
))) {
415 // Rewrite with new tab URL
416 *url
= GURL(chrome::kChromeUINewTabURL
);
424 // Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
426 bool HandleWebUIReverse(GURL
* url
, content::BrowserContext
* browser_context
) {
427 if (!url
->is_valid() || !url
->SchemeIs(content::kChromeUIScheme
))
430 return RemoveUberHost(url
);
433 bool CertMatchesFilter(const net::X509Certificate
& cert
,
434 const base::DictionaryValue
& filter
) {
435 // TODO(markusheintz): This is the minimal required filter implementation.
436 // Implement a better matcher.
438 // An empty filter matches any client certificate since no requirements are
443 std::string common_name
;
444 if (filter
.GetString("ISSUER.CN", &common_name
) &&
445 (cert
.issuer().common_name
== common_name
)) {
451 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
452 breakpad::CrashHandlerHostLinux
* CreateCrashHandlerHost(
453 const std::string
& process_type
) {
454 base::FilePath dumps_path
;
455 PathService::Get(chrome::DIR_CRASH_DUMPS
, &dumps_path
);
457 ANNOTATE_SCOPED_MEMORY_LEAK
;
458 bool upload
= (getenv(env_vars::kHeadless
) == NULL
);
459 breakpad::CrashHandlerHostLinux
* crash_handler
=
460 new breakpad::CrashHandlerHostLinux(process_type
, dumps_path
, upload
);
461 crash_handler
->StartUploaderThread();
462 return crash_handler
;
466 int GetCrashSignalFD(const base::CommandLine
& command_line
) {
467 // Extensions have the same process type as renderers.
468 if (command_line
.HasSwitch(extensions::switches::kExtensionProcess
)) {
469 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
471 crash_handler
= CreateCrashHandlerHost("extension");
472 return crash_handler
->GetDeathSignalSocket();
475 std::string process_type
=
476 command_line
.GetSwitchValueASCII(switches::kProcessType
);
478 if (process_type
== switches::kRendererProcess
) {
479 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
481 crash_handler
= CreateCrashHandlerHost(process_type
);
482 return crash_handler
->GetDeathSignalSocket();
485 if (process_type
== switches::kPluginProcess
) {
486 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
488 crash_handler
= CreateCrashHandlerHost(process_type
);
489 return crash_handler
->GetDeathSignalSocket();
492 if (process_type
== switches::kPpapiPluginProcess
) {
493 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
495 crash_handler
= CreateCrashHandlerHost(process_type
);
496 return crash_handler
->GetDeathSignalSocket();
499 if (process_type
== switches::kGpuProcess
) {
500 static breakpad::CrashHandlerHostLinux
* crash_handler
= NULL
;
502 crash_handler
= CreateCrashHandlerHost(process_type
);
503 return crash_handler
->GetDeathSignalSocket();
508 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
510 void SetApplicationLocaleOnIOThread(const std::string
& locale
) {
511 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
512 g_io_thread_application_locale
.Get() = locale
;
515 void HandleBlockedPopupOnUIThread(const BlockedWindowParams
& params
) {
516 RenderFrameHost
* render_frame_host
= RenderFrameHost::FromID(
517 params
.render_process_id(), params
.opener_render_frame_id());
518 if (!render_frame_host
)
520 WebContents
* tab
= WebContents::FromRenderFrameHost(render_frame_host
);
521 // The tab might already have navigated away. We only need to do this check
522 // for main frames, since the RenderFrameHost for a subframe opener will have
523 // already been deleted if the main frame navigates away.
525 (!render_frame_host
->GetParent() &&
526 tab
->GetMainFrame() != render_frame_host
))
529 prerender::PrerenderContents
* prerender_contents
=
530 prerender::PrerenderContents::FromWebContents(tab
);
531 if (prerender_contents
) {
532 prerender_contents
->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW
);
536 PopupBlockerTabHelper
* popup_helper
=
537 PopupBlockerTabHelper::FromWebContents(tab
);
540 popup_helper
->AddBlockedPopup(params
);
543 // An implementation of the SSLCertReporter interface used by
544 // SSLErrorHandler. Uses the SafeBrowsing UI manager to send invalid
545 // certificate reports.
546 class SafeBrowsingSSLCertReporter
: public SSLCertReporter
{
548 explicit SafeBrowsingSSLCertReporter(
549 const scoped_refptr
<SafeBrowsingUIManager
>& safe_browsing_ui_manager
)
550 : safe_browsing_ui_manager_(safe_browsing_ui_manager
) {}
551 ~SafeBrowsingSSLCertReporter() override
{}
553 // SSLCertReporter implementation
554 void ReportInvalidCertificateChain(
555 const std::string
& serialized_report
) override
{
556 if (safe_browsing_ui_manager_
) {
557 safe_browsing_ui_manager_
->ReportInvalidCertificateChain(
558 serialized_report
, base::Bind(&base::DoNothing
));
563 const scoped_refptr
<SafeBrowsingUIManager
> safe_browsing_ui_manager_
;
566 #if defined(OS_ANDROID)
568 void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams
& params
) {
569 WebContents
* web_contents
= tab_util::GetWebContentsByFrameID(
570 params
.render_process_id(), params
.opener_render_frame_id());
574 SingleTabModeTabHelper::FromWebContents(web_contents
)->HandleOpenUrl(params
);
577 float GetDeviceScaleAdjustment() {
578 static const float kMinFSM
= 1.05f
;
579 static const int kWidthForMinFSM
= 320;
580 static const float kMaxFSM
= 1.3f
;
581 static const int kWidthForMaxFSM
= 800;
583 gfx::DeviceDisplayInfo info
;
584 int minWidth
= info
.GetSmallestDIPWidth();
586 if (minWidth
<= kWidthForMinFSM
)
588 if (minWidth
>= kWidthForMaxFSM
)
591 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
592 float ratio
= static_cast<float>(minWidth
- kWidthForMinFSM
) /
593 (kWidthForMaxFSM
- kWidthForMinFSM
);
594 return ratio
* (kMaxFSM
- kMinFSM
) + kMinFSM
;
597 #endif // defined(OS_ANDROID)
599 #if defined(ENABLE_EXTENSIONS)
600 // By default, JavaScript and images are enabled in guest content.
601 void GetGuestViewDefaultContentSettingRules(
603 RendererContentSettingRules
* rules
) {
604 rules
->image_rules
.push_back(
605 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
606 ContentSettingsPattern::Wildcard(),
607 CONTENT_SETTING_ALLOW
,
611 rules
->script_rules
.push_back(
612 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
613 ContentSettingsPattern::Wildcard(),
614 CONTENT_SETTING_ALLOW
,
618 #endif // defined(ENABLE_EXTENSIONS)
624 ChromeContentBrowserClient::ChromeContentBrowserClient()
626 weak_factory_(this) {
627 #if defined(ENABLE_PLUGINS)
628 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedDevChannelOrigins
); ++i
)
629 allowed_dev_channel_origins_
.insert(kPredefinedAllowedDevChannelOrigins
[i
]);
630 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedFileHandleOrigins
); ++i
)
631 allowed_file_handle_origins_
.insert(kPredefinedAllowedFileHandleOrigins
[i
]);
632 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedSocketOrigins
); ++i
)
633 allowed_socket_origins_
.insert(kPredefinedAllowedSocketOrigins
[i
]);
635 extra_parts_
.push_back(new ChromeContentBrowserClientPluginsPart
);
638 #if !defined(OS_ANDROID)
639 TtsExtensionEngine
* tts_extension_engine
= TtsExtensionEngine::GetInstance();
640 TtsController::GetInstance()->SetTtsEngineDelegate(tts_extension_engine
);
643 #if defined(ENABLE_EXTENSIONS)
644 extra_parts_
.push_back(new ChromeContentBrowserClientExtensionsPart
);
648 ChromeContentBrowserClient::~ChromeContentBrowserClient() {
649 for (int i
= static_cast<int>(extra_parts_
.size()) - 1; i
>= 0; --i
)
650 delete extra_parts_
[i
];
651 extra_parts_
.clear();
655 void ChromeContentBrowserClient::RegisterProfilePrefs(
656 user_prefs::PrefRegistrySyncable
* registry
) {
657 registry
->RegisterBooleanPref(prefs::kDisable3DAPIs
, false);
658 registry
->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing
, true);
659 registry
->RegisterListPref(prefs::kEnableDeprecatedWebPlatformFeatures
);
663 void ChromeContentBrowserClient::SetApplicationLocale(
664 const std::string
& locale
) {
665 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
667 // This object is guaranteed to outlive all threads so we don't have to
668 // worry about the lack of refcounting and can just post as Unretained.
670 // The common case is that this function is called early in Chrome startup
671 // before any threads are created (it will also be called later if the user
672 // changes the pref). In this case, there will be no threads created and
673 // posting will fail. When there are no threads, we can just set the string
674 // without worrying about threadsafety.
675 if (!BrowserThread::PostTask(BrowserThread::IO
, FROM_HERE
,
676 base::Bind(&SetApplicationLocaleOnIOThread
, locale
))) {
677 g_io_thread_application_locale
.Get() = locale
;
681 content::BrowserMainParts
* ChromeContentBrowserClient::CreateBrowserMainParts(
682 const content::MainFunctionParams
& parameters
) {
683 ChromeBrowserMainParts
* main_parts
;
684 // Construct the Main browser parts based on the OS type.
686 main_parts
= new ChromeBrowserMainPartsWin(parameters
);
687 #elif defined(OS_MACOSX)
688 main_parts
= new ChromeBrowserMainPartsMac(parameters
);
689 #elif defined(OS_CHROMEOS)
690 main_parts
= new chromeos::ChromeBrowserMainPartsChromeos(parameters
);
691 #elif defined(OS_LINUX)
692 main_parts
= new ChromeBrowserMainPartsLinux(parameters
);
693 #elif defined(OS_ANDROID)
694 main_parts
= new ChromeBrowserMainPartsAndroid(parameters
);
695 #elif defined(OS_POSIX)
696 main_parts
= new ChromeBrowserMainPartsPosix(parameters
);
699 main_parts
= new ChromeBrowserMainParts(parameters
);
702 chrome::AddProfilesExtraParts(main_parts
);
704 // Construct additional browser parts. Stages are called in the order in
705 // which they are added.
706 #if defined(TOOLKIT_VIEWS)
707 main_parts
->AddParts(new ChromeBrowserMainExtraPartsViews());
710 // TODO(oshima): Athena on chrome currently requires USE_ASH to build.
711 // We should reduce the dependency as much as possible.
713 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAsh());
716 #if defined(USE_AURA)
717 main_parts
->AddParts(new ChromeBrowserMainExtraPartsAura());
721 main_parts
->AddParts(new ChromeBrowserMainExtraPartsX11());
724 chrome::AddMetricsExtraParts(main_parts
);
729 void ChromeContentBrowserClient::PostAfterStartupTask(
730 const tracked_objects::Location
& from_here
,
731 const scoped_refptr
<base::TaskRunner
>& task_runner
,
732 const base::Closure
& task
) {
733 AfterStartupTaskUtils::PostTask(from_here
, task_runner
, task
);
736 std::string
ChromeContentBrowserClient::GetStoragePartitionIdForSite(
737 content::BrowserContext
* browser_context
,
739 std::string partition_id
;
741 // The partition ID for webview guest processes is the string value of its
742 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
743 if (site
.SchemeIs(content::kGuestScheme
)) {
744 partition_id
= site
.spec();
745 } else if (!switches::IsEnableWebviewBasedSignin() &&
746 site
.GetOrigin().spec() == kChromeUIChromeSigninURL
) {
747 // The non-webview Chrome signin page has an embedded iframe of extension
748 // and web content, thus it must be isolated from other webUI pages.
749 partition_id
= site
.GetOrigin().spec();
752 DCHECK(IsValidStoragePartitionId(browser_context
, partition_id
));
756 bool ChromeContentBrowserClient::IsValidStoragePartitionId(
757 content::BrowserContext
* browser_context
,
758 const std::string
& partition_id
) {
759 // The default ID is empty and is always valid.
760 if (partition_id
.empty())
763 return GURL(partition_id
).is_valid();
766 void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
767 content::BrowserContext
* browser_context
,
770 std::string
* partition_domain
,
771 std::string
* partition_name
,
773 // Default to the browser-wide storage partition and override based on |site|
775 partition_domain
->clear();
776 partition_name
->clear();
779 bool success
= false;
780 #if defined(ENABLE_EXTENSIONS)
781 success
= extensions::WebViewGuest::GetGuestPartitionConfigForSite(
782 site
, partition_domain
, partition_name
, in_memory
);
784 if (!success
&& site
.SchemeIs(extensions::kExtensionScheme
)) {
785 // If |can_be_default| is false, the caller is stating that the |site|
786 // should be parsed as if it had isolated storage. In particular it is
787 // important to NOT check ExtensionService for the is_storage_isolated()
788 // attribute because this code path is run during Extension uninstall
789 // to do cleanup after the Extension has already been unloaded from the
791 bool is_isolated
= !can_be_default
;
792 if (can_be_default
) {
793 if (extensions::util::SiteHasIsolatedStorage(site
, browser_context
))
798 CHECK(site
.has_host());
799 // For extensions with isolated storage, the the host of the |site| is
800 // the |partition_domain|. The |in_memory| and |partition_name| are only
801 // used in guest schemes so they are cleared here.
802 *partition_domain
= site
.host();
804 partition_name
->clear();
810 if (!success
&& (!switches::IsEnableWebviewBasedSignin() &&
811 site
.GetOrigin().spec() == kChromeUIChromeSigninURL
)) {
812 // The non-webview Chrome signin page has an embedded iframe of extension
813 // and web content, thus it must be isolated from other webUI pages.
814 *partition_domain
= chrome::kChromeUIChromeSigninHost
;
817 // Assert that if |can_be_default| is false, the code above must have found a
818 // non-default partition. If this fails, the caller has a serious logic
819 // error about which StoragePartition they expect to be in and it is not
821 CHECK(can_be_default
|| !partition_domain
->empty());
824 content::WebContentsViewDelegate
*
825 ChromeContentBrowserClient::GetWebContentsViewDelegate(
826 content::WebContents
* web_contents
) {
827 return chrome::CreateWebContentsViewDelegate(web_contents
);
830 void ChromeContentBrowserClient::RenderProcessWillLaunch(
831 content::RenderProcessHost
* host
) {
832 int id
= host
->GetID();
833 Profile
* profile
= Profile::FromBrowserContext(host
->GetBrowserContext());
834 net::URLRequestContextGetter
* context
=
835 profile
->GetRequestContextForRenderProcess(id
);
837 host
->AddFilter(new ChromeRenderMessageFilter(id
, profile
));
838 #if defined(ENABLE_EXTENSIONS)
839 host
->AddFilter(new cast::CastTransportHostFilter
);
841 #if defined(ENABLE_PRINTING)
842 host
->AddFilter(new printing::PrintingMessageFilter(id
, profile
));
844 host
->AddFilter(new SearchProviderInstallStateMessageFilter(id
, profile
));
845 #if defined(ENABLE_SPELLCHECK)
846 host
->AddFilter(new SpellCheckMessageFilter(id
));
848 #if defined(USE_BROWSER_SPELLCHECKER)
849 host
->AddFilter(new SpellCheckMessageFilterPlatform(id
));
851 host
->AddFilter(new ChromeNetBenchmarkingMessageFilter(profile
, context
));
852 host
->AddFilter(new prerender::PrerenderMessageFilter(id
, profile
));
853 host
->AddFilter(new TtsMessageFilter(host
->GetBrowserContext()));
854 #if defined(ENABLE_WEBRTC)
855 WebRtcLoggingHandlerHost
* webrtc_logging_handler_host
=
856 new WebRtcLoggingHandlerHost(profile
);
857 host
->SetWebRtcLogMessageCallback(base::Bind(
858 &WebRtcLoggingHandlerHost::LogMessage
, webrtc_logging_handler_host
));
859 host
->AddFilter(webrtc_logging_handler_host
);
860 host
->SetUserData(host
, new base::UserDataAdapter
<WebRtcLoggingHandlerHost
>(
861 webrtc_logging_handler_host
));
863 #if !defined(DISABLE_NACL)
864 host
->AddFilter(new nacl::NaClHostMessageFilter(
865 id
, profile
->IsOffTheRecord(),
869 #if defined(OS_ANDROID)
870 host
->AddFilter(new cdm::CdmMessageFilterAndroid());
872 DataReductionProxyChromeSettings
* data_reduction_proxy_settings
=
873 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(profile
);
874 host
->AddFilter(new data_reduction_proxy::DataReductionProxyMessageFilter(
875 data_reduction_proxy_settings
));
877 host
->Send(new ChromeViewMsg_SetIsIncognitoProcess(
878 profile
->IsOffTheRecord()));
880 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
881 extra_parts_
[i
]->RenderProcessWillLaunch(host
);
883 RendererContentSettingRules rules
;
884 if (host
->IsForGuestsOnly()) {
885 #if defined(ENABLE_EXTENSIONS)
886 GetGuestViewDefaultContentSettingRules(profile
->IsOffTheRecord(), &rules
);
891 GetRendererContentSettingRules(
892 profile
->GetHostContentSettingsMap(), &rules
);
894 host
->Send(new ChromeViewMsg_SetContentSettingRules(rules
));
897 GURL
ChromeContentBrowserClient::GetEffectiveURL(
898 content::BrowserContext
* browser_context
, const GURL
& url
) {
899 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
903 // If the input |url| should be assigned to the Instant renderer, make its
904 // effective URL distinct from other URLs on the search provider's domain.
905 if (search::ShouldAssignURLToInstantRenderer(url
, profile
))
906 return search::GetEffectiveURLForInstant(url
, profile
);
908 #if defined(ENABLE_EXTENSIONS)
909 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(
916 bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
917 content::BrowserContext
* browser_context
, const GURL
& effective_url
) {
918 // Non-extension, non-Instant URLs should generally use
919 // process-per-site-instance. Because we expect to use the effective URL,
920 // URLs for hosted apps (apart from bookmark apps) should have an extension
923 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
927 if (search::ShouldUseProcessPerSiteForInstantURL(effective_url
, profile
))
930 #if defined(ENABLE_EXTENSIONS)
931 return ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
932 profile
, effective_url
);
938 bool ChromeContentBrowserClient::ShouldLockToOrigin(const GURL
& effective_url
) {
939 // Don't lock the NTP's process to a single origin for now, since we cannot
940 // map its actual URLs to the effective URL of the site on the IO thread.
941 // TODO(creis, nick): Remove this exception in https://crbug.com/160576.
942 return effective_url
.scheme() != chrome::kChromeSearchScheme
;
945 // These are treated as WebUI schemes but do not get WebUI bindings. Also,
946 // view-source is allowed for these schemes.
947 void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
948 std::vector
<std::string
>* additional_schemes
) {
949 additional_schemes
->push_back(chrome::kChromeSearchScheme
);
950 additional_schemes
->push_back(dom_distiller::kDomDistillerScheme
);
953 void ChromeContentBrowserClient::GetAdditionalWebUIHostsToIgnoreParititionCheck(
954 std::vector
<std::string
>* hosts
) {
955 hosts
->push_back(chrome::kChromeUIExtensionIconHost
);
956 hosts
->push_back(chrome::kChromeUIFaviconHost
);
957 hosts
->push_back(chrome::kChromeUIThemeHost
);
958 hosts
->push_back(chrome::kChromeUIThumbnailHost
);
959 hosts
->push_back(chrome::kChromeUIThumbnailHost2
);
960 hosts
->push_back(chrome::kChromeUIThumbnailListHost
);
963 net::URLRequestContextGetter
*
964 ChromeContentBrowserClient::CreateRequestContext(
965 content::BrowserContext
* browser_context
,
966 content::ProtocolHandlerMap
* protocol_handlers
,
967 content::URLRequestInterceptorScopedVector request_interceptors
) {
968 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
969 return profile
->CreateRequestContext(protocol_handlers
,
970 request_interceptors
.Pass());
973 net::URLRequestContextGetter
*
974 ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
975 content::BrowserContext
* browser_context
,
976 const base::FilePath
& partition_path
,
978 content::ProtocolHandlerMap
* protocol_handlers
,
979 content::URLRequestInterceptorScopedVector request_interceptors
) {
980 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
981 return profile
->CreateRequestContextForStoragePartition(
985 request_interceptors
.Pass());
988 bool ChromeContentBrowserClient::IsHandledURL(const GURL
& url
) {
989 return ProfileIOData::IsHandledURL(url
);
992 bool ChromeContentBrowserClient::CanCommitURL(
993 content::RenderProcessHost
* process_host
,
995 #if defined(ENABLE_EXTENSIONS)
996 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(
1003 bool ChromeContentBrowserClient::IsIllegalOrigin(
1004 content::ResourceContext
* resource_context
,
1005 int child_process_id
,
1006 const GURL
& origin
) {
1007 #if defined(ENABLE_EXTENSIONS)
1008 return ChromeContentBrowserClientExtensionsPart::IsIllegalOrigin(
1009 resource_context
, child_process_id
, origin
);
1015 bool ChromeContentBrowserClient::ShouldAllowOpenURL(
1016 content::SiteInstance
* site_instance
, const GURL
& url
) {
1017 GURL from_url
= site_instance
->GetSiteURL();
1019 #if defined(ENABLE_EXTENSIONS)
1021 if (ChromeContentBrowserClientExtensionsPart::ShouldAllowOpenURL(
1022 site_instance
, from_url
, url
, &result
))
1026 // Do not allow chrome://chrome-signin navigate to other chrome:// URLs, since
1027 // the signin page may host untrusted web content.
1028 if (from_url
.GetOrigin().spec() == chrome::kChromeUIChromeSigninURL
&&
1029 url
.SchemeIs(content::kChromeUIScheme
) &&
1030 url
.host() != chrome::kChromeUIChromeSigninHost
) {
1031 VLOG(1) << "Blocked navigation to " << url
.spec() << " from "
1032 << chrome::kChromeUIChromeSigninURL
;
1039 bool ChromeContentBrowserClient::IsSuitableHost(
1040 content::RenderProcessHost
* process_host
,
1041 const GURL
& site_url
) {
1043 Profile::FromBrowserContext(process_host
->GetBrowserContext());
1044 // This may be NULL during tests. In that case, just assume any site can
1049 // Instant URLs should only be in the instant process and instant process
1050 // should only have Instant URLs.
1051 InstantService
* instant_service
=
1052 InstantServiceFactory::GetForProfile(profile
);
1053 if (instant_service
) {
1054 bool is_instant_process
= instant_service
->IsInstantProcess(
1055 process_host
->GetID());
1056 bool should_be_in_instant_process
=
1057 search::ShouldAssignURLToInstantRenderer(site_url
, profile
);
1058 if (is_instant_process
|| should_be_in_instant_process
)
1059 return is_instant_process
&& should_be_in_instant_process
;
1062 #if defined(ENABLE_EXTENSIONS)
1063 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1064 profile
, process_host
, site_url
);
1070 bool ChromeContentBrowserClient::MayReuseHost(
1071 content::RenderProcessHost
* process_host
) {
1072 // If there is currently a prerender in progress for the host provided,
1073 // it may not be shared. We require prerenders to be by themselves in a
1074 // separate process so that we can monitor their resource usage.
1075 Profile
* profile
= Profile::FromBrowserContext(
1076 process_host
->GetBrowserContext());
1077 prerender::PrerenderManager
* prerender_manager
=
1078 prerender::PrerenderManagerFactory::GetForProfile(profile
);
1079 if (prerender_manager
&&
1080 !prerender_manager
->MayReuseProcessHost(process_host
)) {
1087 bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1088 content::BrowserContext
* browser_context
, const GURL
& url
) {
1089 // It has to be a valid URL for us to check for an extension.
1090 if (!url
.is_valid())
1093 #if defined(ENABLE_EXTENSIONS)
1094 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1095 return ChromeContentBrowserClientExtensionsPart::
1096 ShouldTryToUseExistingProcessHost(
1103 void ChromeContentBrowserClient::SiteInstanceGotProcess(
1104 SiteInstance
* site_instance
) {
1105 CHECK(site_instance
->HasProcess());
1107 Profile
* profile
= Profile::FromBrowserContext(
1108 site_instance
->GetBrowserContext());
1112 // Remember the ID of the Instant process to signal the renderer process
1113 // on startup in |AppendExtraCommandLineSwitches| below.
1114 if (search::ShouldAssignURLToInstantRenderer(site_instance
->GetSiteURL(),
1116 InstantService
* instant_service
=
1117 InstantServiceFactory::GetForProfile(profile
);
1118 if (instant_service
)
1119 instant_service
->AddInstantProcess(site_instance
->GetProcess()->GetID());
1122 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
1123 extra_parts_
[i
]->SiteInstanceGotProcess(site_instance
);
1126 void ChromeContentBrowserClient::SiteInstanceDeleting(
1127 SiteInstance
* site_instance
) {
1128 if (!site_instance
->HasProcess())
1131 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
1132 extra_parts_
[i
]->SiteInstanceDeleting(site_instance
);
1135 bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
1136 SiteInstance
* site_instance
,
1137 const GURL
& current_url
,
1138 const GURL
& new_url
) {
1139 #if defined(ENABLE_EXTENSIONS)
1140 return ChromeContentBrowserClientExtensionsPart::
1141 ShouldSwapBrowsingInstancesForNavigation(
1142 site_instance
, current_url
, new_url
);
1148 bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1149 content::ResourceContext
* resource_context
, const GURL
& current_url
,
1150 const GURL
& new_url
) {
1151 #if defined(ENABLE_EXTENSIONS)
1152 return ChromeContentBrowserClientExtensionsPart::
1153 ShouldSwapProcessesForRedirect(resource_context
, current_url
, new_url
);
1159 bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL
& url
) {
1160 return !url
.SchemeIs(chrome::kChromeNativeScheme
);
1163 std::string
ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1164 const std::string
& alias_name
) {
1165 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name
);
1170 bool IsAutoReloadEnabled() {
1171 // Fetch the field trial, even though we don't use it. Calling FindFullName()
1172 // causes the field-trial mechanism to report which group we're in, which
1173 // might reflect a hard disable or hard enable via flag, both of which have
1174 // their own field trial groups. This lets us know what percentage of users
1175 // manually enable or disable auto-reload.
1176 std::string group
= base::FieldTrialList::FindFullName(
1177 "AutoReloadExperiment");
1178 const base::CommandLine
& browser_command_line
=
1179 *base::CommandLine::ForCurrentProcess();
1180 if (browser_command_line
.HasSwitch(switches::kEnableOfflineAutoReload
))
1182 if (browser_command_line
.HasSwitch(switches::kDisableOfflineAutoReload
))
1187 bool IsAutoReloadVisibleOnlyEnabled() {
1188 // See the block comment in IsAutoReloadEnabled().
1189 std::string group
= base::FieldTrialList::FindFullName(
1190 "AutoReloadVisibleOnlyExperiment");
1191 const base::CommandLine
& browser_command_line
=
1192 *base::CommandLine::ForCurrentProcess();
1193 if (browser_command_line
.HasSwitch(
1194 switches::kEnableOfflineAutoReloadVisibleOnly
)) {
1197 if (browser_command_line
.HasSwitch(
1198 switches::kDisableOfflineAutoReloadVisibleOnly
)) {
1204 void MaybeAppendBlinkSettingsSwitchForFieldTrial(
1205 const base::CommandLine
& browser_command_line
,
1206 base::CommandLine
* command_line
) {
1207 // List of field trials that modify the blink-settings command line flag. No
1208 // two field trials in the list should specify the same keys, otherwise one
1209 // field trial may overwrite another. See Source/core/frame/Settings.in in
1210 // Blink for the list of valid keys.
1211 static const char* const kBlinkSettingsFieldTrials
[] = {
1212 // Keys: backgroundHtmlParserOutstandingTokenLimit
1213 // backgroundHtmlParserPendingTokenLimit
1214 "BackgroundHtmlParserTokenLimits",
1216 // Keys: doHtmlPreloadScanning
1217 "HtmlPreloadScanning",
1219 // Keys: lowPriorityIframes
1220 "LowPriorityIFrames",
1223 std::vector
<std::string
> blink_settings
;
1224 for (const char* field_trial_name
: kBlinkSettingsFieldTrials
) {
1225 // Each blink-settings field trial should include a forcing_flag group,
1226 // to make sure that clients that specify the blink-settings flag on the
1227 // command line are excluded from the experiment groups. To make
1228 // sure we assign clients that specify this flag to the forcing_flag
1229 // group, we must call GetVariationParams for each field trial first
1230 // (for example, before checking HasSwitch() and returning), since
1231 // GetVariationParams has the side-effect of assigning the client to
1232 // a field trial group.
1233 std::map
<std::string
, std::string
> params
;
1234 if (variations::GetVariationParams(field_trial_name
, ¶ms
)) {
1235 for (const auto& param
: params
) {
1236 blink_settings
.push_back(base::StringPrintf(
1237 "%s=%s", param
.first
.c_str(), param
.second
.c_str()));
1242 // Flags for the ResourcePriorities field trial. The settings are
1243 // encoded in the field trial group name instead of as variations
1244 // because the variations code is not accessible from the loader.
1246 // The group name encoding looks like this:
1247 // <descriptiveName>_ABCDE_E2_F_G
1248 // A - fetchDeferLateScripts (1 for true, 0 for false)
1249 // B - fetchIncreaseFontPriority (1 for true, 0 for false)
1250 // C - fetchIncreaseAsyncScriptPriority (1 for true, 0 for false)
1251 // D - fetchIncreasePriorities (1 for true, 0 for false)
1252 // E - fetchEnableLayoutBlockingThreshold (1 for true, 0 for false)
1253 // E2 - fetchLayoutBlockingThreshold (Numeric)
1254 // F - fetchMaxNumDelayableWhileLayoutBlocking (Numeric)
1255 // G - fetchMaxNumDelayableRequests (Numeric)
1257 // Only A-D are relevant to blink and exposed as settings
1258 // Any group names (Control, Default, etc) will not match the pattern or
1259 // flags and will get the default settings which is the expected behavior.
1260 std::string resource_priorities_trial_group
=
1261 base::FieldTrialList::FindFullName("ResourcePriorities");
1262 std::vector
<std::string
> split_group(
1263 base::SplitString(resource_priorities_trial_group
, "_",
1264 base::KEEP_WHITESPACE
, base::SPLIT_WANT_ALL
));
1265 if (split_group
.size() == 5 && split_group
[1].length() == 5) {
1266 if (split_group
[1].at(0) == '1')
1267 blink_settings
.push_back("fetchDeferLateScripts=true");
1268 if (split_group
[1].at(1) == '1')
1269 blink_settings
.push_back("fetchIncreaseFontPriority=true");
1270 if (split_group
[1].at(2) == '1')
1271 blink_settings
.push_back("fetchIncreaseAsyncScriptPriority=true");
1272 if (split_group
[1].at(3) == '1')
1273 blink_settings
.push_back("fetchIncreasePriorities=true");
1276 if (blink_settings
.empty()) {
1280 if (browser_command_line
.HasSwitch(switches::kBlinkSettings
) ||
1281 command_line
->HasSwitch(switches::kBlinkSettings
)) {
1282 // The field trials should be configured to force users that specify the
1283 // blink-settings flag into a group with no params, and we return
1284 // above if no params were specified, so it's an error if we reach
1286 LOG(WARNING
) << "Received field trial params, "
1287 "but blink-settings switch already specified.";
1291 command_line
->AppendSwitchASCII(switches::kBlinkSettings
,
1292 base::JoinString(blink_settings
, ","));
1297 void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1298 base::CommandLine
* command_line
,
1299 int child_process_id
) {
1300 #if defined(OS_MACOSX)
1301 scoped_ptr
<metrics::ClientInfo
> client_info
=
1302 GoogleUpdateSettings::LoadMetricsClientInfo();
1304 command_line
->AppendSwitchASCII(switches::kMetricsClientID
,
1305 client_info
->client_id
);
1307 #elif defined(OS_POSIX)
1308 if (breakpad::IsCrashReporterEnabled()) {
1309 scoped_ptr
<metrics::ClientInfo
> client_info
=
1310 GoogleUpdateSettings::LoadMetricsClientInfo();
1311 command_line
->AppendSwitchASCII(switches::kEnableCrashReporter
,
1312 client_info
? client_info
->client_id
1317 if (logging::DialogsAreSuppressed())
1318 command_line
->AppendSwitch(switches::kNoErrorDialogs
);
1320 std::string process_type
=
1321 command_line
->GetSwitchValueASCII(switches::kProcessType
);
1322 const base::CommandLine
& browser_command_line
=
1323 *base::CommandLine::ForCurrentProcess();
1325 static const char* const kCommonSwitchNames
[] = {
1326 switches::kUserAgent
,
1327 switches::kUserDataDir
, // Make logs go to the right file.
1329 command_line
->CopySwitchesFrom(browser_command_line
, kCommonSwitchNames
,
1330 arraysize(kCommonSwitchNames
));
1332 #if defined(ENABLE_IPC_FUZZER)
1333 static const char* const kIpcFuzzerSwitches
[] = {
1334 switches::kIpcDumpDirectory
,
1335 switches::kIpcFuzzerTestcase
,
1337 command_line
->CopySwitchesFrom(browser_command_line
, kIpcFuzzerSwitches
,
1338 arraysize(kIpcFuzzerSwitches
));
1341 #if defined(OS_CHROMEOS)
1342 static const char* const kChromeOSSwitches
[] = {
1343 switches::kDisableDinosaurEasterEgg
,
1345 command_line
->CopySwitchesFrom(browser_command_line
, kChromeOSSwitches
,
1346 arraysize(kChromeOSSwitches
));
1348 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
1349 base::FilePath homedir
;
1350 PathService::Get(base::DIR_HOME
, &homedir
);
1351 command_line
->AppendSwitchASCII(chromeos::switches::kHomedir
,
1352 homedir
.value().c_str());
1355 if (process_type
== switches::kRendererProcess
) {
1356 content::RenderProcessHost
* process
=
1357 content::RenderProcessHost::FromID(child_process_id
);
1359 process
? Profile::FromBrowserContext(process
->GetBrowserContext())
1361 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
1362 extra_parts_
[i
]->AppendExtraRendererCommandLineSwitches(
1363 command_line
, process
, profile
);
1366 #if defined(OS_CHROMEOS)
1367 const std::string
& login_profile
=
1368 browser_command_line
.GetSwitchValueASCII(
1369 chromeos::switches::kLoginProfile
);
1370 if (!login_profile
.empty())
1371 command_line
->AppendSwitchASCII(
1372 chromeos::switches::kLoginProfile
, login_profile
);
1375 #if defined(ENABLE_WEBRTC)
1376 MaybeCopyDisableWebRtcEncryptionSwitch(command_line
,
1377 browser_command_line
,
1378 chrome::GetChannel());
1382 PrefService
* prefs
= profile
->GetPrefs();
1383 // Currently this pref is only registered if applied via a policy.
1384 if (prefs
->HasPrefPath(prefs::kDisable3DAPIs
) &&
1385 prefs
->GetBoolean(prefs::kDisable3DAPIs
)) {
1386 // Turn this policy into a command line switch.
1387 command_line
->AppendSwitch(switches::kDisable3DAPIs
);
1390 const base::ListValue
* switches
=
1391 prefs
->GetList(prefs::kEnableDeprecatedWebPlatformFeatures
);
1393 // Enable any deprecated features that have been re-enabled by policy.
1394 for (base::ListValue::const_iterator it
= switches
->begin();
1395 it
!= switches
->end(); ++it
) {
1396 std::string switch_to_enable
;
1397 if ((*it
)->GetAsString(&switch_to_enable
))
1398 command_line
->AppendSwitch(switch_to_enable
);
1402 // Disable client-side phishing detection in the renderer if it is
1403 // disabled in the Profile preferences or the browser process.
1404 if (!prefs
->GetBoolean(prefs::kSafeBrowsingEnabled
) ||
1405 !g_browser_process
->safe_browsing_detection_service()) {
1406 command_line
->AppendSwitch(
1407 switches::kDisableClientSidePhishingDetection
);
1410 if (prefs
->GetBoolean(prefs::kPrintPreviewDisabled
))
1411 command_line
->AppendSwitch(switches::kDisablePrintPreview
);
1413 InstantService
* instant_service
=
1414 InstantServiceFactory::GetForProfile(profile
);
1415 if (instant_service
&&
1416 instant_service
->IsInstantProcess(process
->GetID()))
1417 command_line
->AppendSwitch(switches::kInstantProcess
);
1420 if (IsAutoReloadEnabled())
1421 command_line
->AppendSwitch(switches::kEnableOfflineAutoReload
);
1422 if (IsAutoReloadVisibleOnlyEnabled()) {
1423 command_line
->AppendSwitch(
1424 switches::kEnableOfflineAutoReloadVisibleOnly
);
1428 // Enable showing a saved copy if this session is in the field trial
1429 // or the user explicitly enabled it. Note that as far as the
1430 // renderer is concerned, the feature is enabled if-and-only-if
1431 // one of the kEnableShowSavedCopy* switches is on the command
1432 // line; the yes/no/default behavior is only at the browser
1433 // command line level.
1435 // Command line switches override
1436 const std::string
& show_saved_copy_value
=
1437 browser_command_line
.GetSwitchValueASCII(switches::kShowSavedCopy
);
1438 if (show_saved_copy_value
== switches::kEnableShowSavedCopyPrimary
||
1439 show_saved_copy_value
== switches::kEnableShowSavedCopySecondary
||
1440 show_saved_copy_value
== switches::kDisableShowSavedCopy
) {
1441 command_line
->AppendSwitchASCII(switches::kShowSavedCopy
,
1442 show_saved_copy_value
);
1445 base::FieldTrialList::FindFullName("LoadStaleCacheExperiment");
1447 if (group
== "Primary") {
1448 command_line
->AppendSwitchASCII(
1449 switches::kShowSavedCopy
, switches::kEnableShowSavedCopyPrimary
);
1450 } else if (group
== "Secondary") {
1451 command_line
->AppendSwitchASCII(
1452 switches::kShowSavedCopy
,
1453 switches::kEnableShowSavedCopySecondary
);
1458 MaybeAppendBlinkSettingsSwitchForFieldTrial(
1459 browser_command_line
, command_line
);
1461 // Please keep this in alphabetical order.
1462 static const char* const kSwitchNames
[] = {
1463 #if defined(OS_ANDROID)
1464 autofill::switches::kDisableAccessorySuggestionView
,
1465 autofill::switches::kEnableAccessorySuggestionView
,
1467 autofill::switches::kDisableFillOnAccountSelect
,
1468 autofill::switches::kDisablePasswordGeneration
,
1469 autofill::switches::kEnableFillOnAccountSelect
,
1470 autofill::switches::kEnableFillOnAccountSelectNoHighlighting
,
1471 autofill::switches::kEnablePasswordGeneration
,
1472 autofill::switches::kEnableSingleClickAutofill
,
1473 autofill::switches::kEnableSuggestionsWithSubstringMatch
,
1474 autofill::switches::kIgnoreAutocompleteOffForAutofill
,
1475 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration
,
1476 #if defined(ENABLE_EXTENSIONS)
1477 extensions::switches::kAllowHTTPBackgroundPage
,
1478 extensions::switches::kAllowLegacyExtensionManifests
,
1479 extensions::switches::kEnableAppWindowControls
,
1480 extensions::switches::kEnableEmbeddedExtensionOptions
,
1481 extensions::switches::kEnableExperimentalExtensionApis
,
1482 extensions::switches::kExtensionsOnChromeURLs
,
1483 extensions::switches::kWhitelistedExtensionID
,
1485 switches::kAllowInsecureLocalhost
,
1486 switches::kAppsGalleryURL
,
1487 switches::kCloudPrintURL
,
1488 switches::kCloudPrintXmppEndpoint
,
1489 switches::kDisableBundledPpapiFlash
,
1490 switches::kDisableCastStreamingHWEncoding
,
1491 switches::kDisableJavaScriptHarmonyShipping
,
1492 switches::kDisableNewBookmarkApps
,
1493 #if defined(ENABLE_SPELLCHECK) && defined(OS_ANDROID)
1494 switches::kEnableAndroidSpellChecker
,
1496 switches::kEnableBenchmarking
,
1497 switches::kEnableNaCl
,
1498 #if !defined(DISABLE_NACL)
1499 switches::kEnableNaClDebug
,
1500 switches::kEnableNaClNonSfiMode
,
1501 switches::kEnablePNaClSubzero
,
1503 switches::kEnableNetBenchmarking
,
1504 switches::kEnableNewBookmarkApps
,
1505 switches::kEnablePluginPlaceholderShadowDom
,
1506 switches::kJavaScriptHarmony
,
1507 switches::kMessageLoopHistogrammer
,
1508 switches::kPpapiFlashArgs
,
1509 switches::kPpapiFlashPath
,
1510 switches::kPpapiFlashVersion
,
1511 switches::kProfilingAtStart
,
1512 switches::kProfilingFile
,
1513 switches::kProfilingFlush
,
1514 switches::kUnsafelyTreatInsecureOriginAsSecure
,
1515 translate::switches::kTranslateSecurityOrigin
,
1518 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1519 arraysize(kSwitchNames
));
1520 } else if (process_type
== switches::kUtilityProcess
) {
1521 #if defined(ENABLE_EXTENSIONS)
1522 static const char* const kSwitchNames
[] = {
1523 extensions::switches::kAllowHTTPBackgroundPage
,
1524 extensions::switches::kEnableExperimentalExtensionApis
,
1525 extensions::switches::kExtensionsOnChromeURLs
,
1526 extensions::switches::kWhitelistedExtensionID
,
1529 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1530 arraysize(kSwitchNames
));
1532 } else if (process_type
== switches::kPluginProcess
) {
1533 #if defined(OS_CHROMEOS)
1534 static const char* const kSwitchNames
[] = {
1535 chromeos::switches::kLoginProfile
,
1538 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1539 arraysize(kSwitchNames
));
1541 } else if (process_type
== switches::kZygoteProcess
) {
1542 static const char* const kSwitchNames
[] = {
1543 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
1544 switches::kDisableBundledPpapiFlash
,
1545 #if !defined(DISABLE_NACL)
1546 switches::kEnableNaClDebug
,
1547 switches::kEnableNaClNonSfiMode
,
1548 switches::kEnablePNaClSubzero
,
1549 switches::kNaClDangerousNoSandboxNonSfi
,
1550 switches::kUseNaClHelperNonSfi
,
1552 switches::kPpapiFlashPath
,
1553 switches::kPpapiFlashVersion
,
1556 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1557 arraysize(kSwitchNames
));
1558 } else if (process_type
== switches::kGpuProcess
) {
1559 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1560 // because GPU is expected to be unreliable.
1561 if (browser_command_line
.HasSwitch(switches::kIgnoreGpuBlacklist
) &&
1562 !command_line
->HasSwitch(switches::kDisableBreakpad
))
1563 command_line
->AppendSwitch(switches::kDisableBreakpad
);
1566 // The command line switch kEnableBenchmarking needs to be specified along
1567 // with the kEnableStatsTable switch to ensure that the stats table global
1568 // is initialized correctly.
1569 if (command_line
->HasSwitch(switches::kEnableBenchmarking
))
1570 DCHECK(command_line
->HasSwitch(switches::kEnableStatsTable
));
1573 std::string
ChromeContentBrowserClient::GetApplicationLocale() {
1574 if (BrowserThread::CurrentlyOn(BrowserThread::IO
))
1575 return g_io_thread_application_locale
.Get();
1576 return g_browser_process
->GetApplicationLocale();
1579 std::string
ChromeContentBrowserClient::GetAcceptLangs(
1580 content::BrowserContext
* context
) {
1581 Profile
* profile
= Profile::FromBrowserContext(context
);
1582 return profile
->GetPrefs()->GetString(prefs::kAcceptLanguages
);
1585 const gfx::ImageSkia
* ChromeContentBrowserClient::GetDefaultFavicon() {
1586 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
1587 return rb
.GetNativeImageNamed(IDR_DEFAULT_FAVICON
).ToImageSkia();
1590 bool ChromeContentBrowserClient::AllowAppCache(
1591 const GURL
& manifest_url
,
1592 const GURL
& first_party
,
1593 content::ResourceContext
* context
) {
1594 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1595 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1596 return io_data
->GetCookieSettings()->
1597 IsSettingCookieAllowed(manifest_url
, first_party
);
1600 bool ChromeContentBrowserClient::AllowServiceWorker(
1602 const GURL
& first_party_url
,
1603 content::ResourceContext
* context
,
1604 int render_process_id
,
1605 int render_frame_id
) {
1606 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1607 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1608 bool allow
= io_data
->GetCookieSettings()->IsSettingCookieAllowed(
1609 scope
, first_party_url
);
1611 // Record access to database for potential display in UI.
1612 BrowserThread::PostTask(
1613 BrowserThread::UI
, FROM_HERE
,
1614 base::Bind(&TabSpecificContentSettings::ServiceWorkerAccessed
,
1615 render_process_id
, render_frame_id
, scope
, !allow
));
1619 bool ChromeContentBrowserClient::AllowGetCookie(
1621 const GURL
& first_party
,
1622 const net::CookieList
& cookie_list
,
1623 content::ResourceContext
* context
,
1624 int render_process_id
,
1625 int render_frame_id
) {
1626 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1627 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1628 bool allow
= io_data
->GetCookieSettings()->
1629 IsReadingCookieAllowed(url
, first_party
);
1631 BrowserThread::PostTask(
1632 BrowserThread::UI
, FROM_HERE
,
1633 base::Bind(&TabSpecificContentSettings::CookiesRead
, render_process_id
,
1634 render_frame_id
, url
, first_party
, cookie_list
, !allow
));
1638 bool ChromeContentBrowserClient::AllowSetCookie(
1640 const GURL
& first_party
,
1641 const std::string
& cookie_line
,
1642 content::ResourceContext
* context
,
1643 int render_process_id
,
1644 int render_frame_id
,
1645 net::CookieOptions
* options
) {
1646 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1647 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1648 content_settings::CookieSettings
* cookie_settings
=
1649 io_data
->GetCookieSettings();
1650 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, first_party
);
1652 BrowserThread::PostTask(
1653 BrowserThread::UI
, FROM_HERE
,
1654 base::Bind(&TabSpecificContentSettings::CookieChanged
, render_process_id
,
1655 render_frame_id
, url
, first_party
, cookie_line
, *options
,
1660 bool ChromeContentBrowserClient::AllowSaveLocalState(
1661 content::ResourceContext
* context
) {
1662 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1663 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1664 content_settings::CookieSettings
* cookie_settings
=
1665 io_data
->GetCookieSettings();
1666 ContentSetting setting
= cookie_settings
->GetDefaultCookieSetting(NULL
);
1668 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1669 // Could we even support per-origin settings?
1670 return setting
!= CONTENT_SETTING_SESSION_ONLY
;
1673 bool ChromeContentBrowserClient::AllowWorkerDatabase(
1675 const base::string16
& name
,
1676 const base::string16
& display_name
,
1677 unsigned long estimated_size
,
1678 content::ResourceContext
* context
,
1679 const std::vector
<std::pair
<int, int> >& render_frames
) {
1680 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1681 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1682 content_settings::CookieSettings
* cookie_settings
=
1683 io_data
->GetCookieSettings();
1684 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1686 // Record access to database for potential display in UI.
1687 std::vector
<std::pair
<int, int> >::const_iterator i
;
1688 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1689 BrowserThread::PostTask(
1690 BrowserThread::UI
, FROM_HERE
,
1691 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed
,
1692 i
->first
, i
->second
, url
, name
, display_name
, !allow
));
1698 void ChromeContentBrowserClient::AllowWorkerFileSystem(
1700 content::ResourceContext
* context
,
1701 const std::vector
<std::pair
<int, int> >& render_frames
,
1702 base::Callback
<void(bool)> callback
) {
1703 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1704 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1705 content_settings::CookieSettings
* cookie_settings
=
1706 io_data
->GetCookieSettings();
1707 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1709 #if defined(ENABLE_EXTENSIONS)
1710 GuestPermissionRequestHelper(url
, render_frames
, callback
, allow
);
1712 FileSystemAccessed(url
, render_frames
, callback
, allow
);
1716 #if defined(ENABLE_EXTENSIONS)
1717 void ChromeContentBrowserClient::GuestPermissionRequestHelper(
1719 const std::vector
<std::pair
<int, int> >& render_frames
,
1720 base::Callback
<void(bool)> callback
,
1722 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::IO
));
1723 std::vector
<std::pair
<int, int> >::const_iterator i
;
1724 std::map
<int, int> process_map
;
1725 std::map
<int, int>::const_iterator it
;
1726 bool has_web_view_guest
= false;
1727 // Record access to file system for potential display in UI.
1728 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1729 if (process_map
.find(i
->first
) != process_map
.end())
1732 process_map
.insert(std::pair
<int, int>(i
->first
, i
->second
));
1734 if (extensions::WebViewRendererState::GetInstance()->IsGuest(i
->first
))
1735 has_web_view_guest
= true;
1737 if (!has_web_view_guest
) {
1738 FileSystemAccessed(url
, render_frames
, callback
, allow
);
1741 DCHECK_EQ(1U, process_map
.size());
1742 it
= process_map
.begin();
1743 BrowserThread::PostTask(
1746 base::Bind(&ChromeContentBrowserClient::
1747 RequestFileSystemPermissionOnUIThread
,
1752 base::Bind(&ChromeContentBrowserClient::FileSystemAccessed
,
1753 weak_factory_
.GetWeakPtr(),
1759 void ChromeContentBrowserClient::RequestFileSystemPermissionOnUIThread(
1760 int render_process_id
,
1761 int render_frame_id
,
1763 bool allowed_by_default
,
1764 const base::Callback
<void(bool)>& callback
) {
1765 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::UI
));
1766 extensions::WebViewPermissionHelper
* web_view_permission_helper
=
1767 extensions::WebViewPermissionHelper::FromFrameID(
1768 render_process_id
, render_frame_id
);
1769 web_view_permission_helper
->RequestFileSystemPermission(url
,
1775 void ChromeContentBrowserClient::FileSystemAccessed(
1777 const std::vector
<std::pair
<int, int> >& render_frames
,
1778 base::Callback
<void(bool)> callback
,
1780 // Record access to file system for potential display in UI.
1781 std::vector
<std::pair
<int, int> >::const_iterator i
;
1782 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1783 BrowserThread::PostTask(
1786 base::Bind(&TabSpecificContentSettings::FileSystemAccessed
,
1787 i
->first
, i
->second
, url
, !allow
));
1789 callback
.Run(allow
);
1792 bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1794 const base::string16
& name
,
1795 content::ResourceContext
* context
,
1796 const std::vector
<std::pair
<int, int> >& render_frames
) {
1797 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1798 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1799 content_settings::CookieSettings
* cookie_settings
=
1800 io_data
->GetCookieSettings();
1801 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1803 // Record access to IndexedDB for potential display in UI.
1804 std::vector
<std::pair
<int, int> >::const_iterator i
;
1805 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1806 BrowserThread::PostTask(
1807 BrowserThread::UI
, FROM_HERE
,
1808 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed
,
1809 i
->first
, i
->second
, url
, name
, !allow
));
1815 #if defined(ENABLE_WEBRTC)
1816 bool ChromeContentBrowserClient::AllowWebRTCIdentityCache(
1818 const GURL
& first_party_url
,
1819 content::ResourceContext
* context
) {
1820 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
1821 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1822 content_settings::CookieSettings
* cookie_settings
=
1823 io_data
->GetCookieSettings();
1824 return cookie_settings
->IsReadingCookieAllowed(url
, first_party_url
) &&
1825 cookie_settings
->IsSettingCookieAllowed(url
, first_party_url
);
1827 #endif // defined(ENABLE_WEBRTC)
1829 net::URLRequestContext
*
1830 ChromeContentBrowserClient::OverrideRequestContextForURL(
1831 const GURL
& url
, content::ResourceContext
* context
) {
1832 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1833 #if defined(ENABLE_EXTENSIONS)
1834 if (url
.SchemeIs(extensions::kExtensionScheme
)) {
1835 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1836 return io_data
->extensions_request_context();
1843 QuotaPermissionContext
*
1844 ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1845 return new ChromeQuotaPermissionContext();
1848 void ChromeContentBrowserClient::AllowCertificateError(
1849 int render_process_id
,
1850 int render_frame_id
,
1852 const net::SSLInfo
& ssl_info
,
1853 const GURL
& request_url
,
1854 ResourceType resource_type
,
1856 bool strict_enforcement
,
1857 bool expired_previous_decision
,
1858 const base::Callback
<void(bool)>& callback
,
1859 content::CertificateRequestResultType
* result
) {
1860 if (resource_type
!= content::RESOURCE_TYPE_MAIN_FRAME
) {
1861 // A sub-resource has a certificate error. The user doesn't really
1862 // have a context for making the right decision, so block the
1863 // request hard, without an info bar to allow showing the insecure
1865 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY
;
1869 // If the tab is being prerendered, cancel the prerender and the request.
1870 content::RenderFrameHost
* render_frame_host
=
1871 content::RenderFrameHost::FromID(render_process_id
, render_frame_id
);
1872 WebContents
* tab
= WebContents::FromRenderFrameHost(render_frame_host
);
1878 prerender::PrerenderContents
* prerender_contents
=
1879 prerender::PrerenderContents::FromWebContents(tab
);
1880 if (prerender_contents
) {
1881 prerender_contents
->Destroy(prerender::FINAL_STATUS_SSL_ERROR
);
1882 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL
;
1886 // Otherwise, display an SSL blocking page. The interstitial page takes
1887 // ownership of ssl_blocking_page.
1888 int options_mask
= 0;
1890 options_mask
|= SSLBlockingPage::OVERRIDABLE
;
1891 if (strict_enforcement
)
1892 options_mask
|= SSLBlockingPage::STRICT_ENFORCEMENT
;
1893 if (expired_previous_decision
)
1894 options_mask
|= SSLBlockingPage::EXPIRED_BUT_PREVIOUSLY_ALLOWED
;
1896 SafeBrowsingService
* safe_browsing_service
=
1897 g_browser_process
->safe_browsing_service();
1898 scoped_ptr
<SafeBrowsingSSLCertReporter
> cert_reporter(
1899 new SafeBrowsingSSLCertReporter(safe_browsing_service
1900 ? safe_browsing_service
->ui_manager()
1902 SSLErrorHandler::HandleSSLError(tab
, cert_error
, ssl_info
, request_url
,
1903 options_mask
, cert_reporter
.Pass(), callback
);
1906 void ChromeContentBrowserClient::SelectClientCertificate(
1907 content::WebContents
* web_contents
,
1908 net::SSLCertRequestInfo
* cert_request_info
,
1909 scoped_ptr
<content::ClientCertificateDelegate
> delegate
) {
1910 prerender::PrerenderContents
* prerender_contents
=
1911 prerender::PrerenderContents::FromWebContents(web_contents
);
1912 if (prerender_contents
) {
1913 prerender_contents
->Destroy(
1914 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED
);
1918 GURL
requesting_url("https://" + cert_request_info
->host_and_port
.ToString());
1919 DCHECK(requesting_url
.is_valid())
1920 << "Invalid URL string: https://"
1921 << cert_request_info
->host_and_port
.ToString();
1924 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
1925 scoped_ptr
<base::Value
> filter
=
1926 profile
->GetHostContentSettingsMap()->GetWebsiteSetting(
1929 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE
,
1934 // Try to automatically select a client certificate.
1935 if (filter
->IsType(base::Value::TYPE_DICTIONARY
)) {
1936 base::DictionaryValue
* filter_dict
=
1937 static_cast<base::DictionaryValue
*>(filter
.get());
1939 const std::vector
<scoped_refptr
<net::X509Certificate
> >&
1940 all_client_certs
= cert_request_info
->client_certs
;
1941 for (size_t i
= 0; i
< all_client_certs
.size(); ++i
) {
1942 if (CertMatchesFilter(*all_client_certs
[i
].get(), *filter_dict
)) {
1943 // Use the first certificate that is matched by the filter.
1944 delegate
->ContinueWithCertificate(all_client_certs
[i
].get());
1953 chrome::ShowSSLClientCertificateSelector(web_contents
, cert_request_info
,
1957 void ChromeContentBrowserClient::AddCertificate(
1958 net::CertificateMimeType cert_type
,
1959 const void* cert_data
,
1961 int render_process_id
,
1962 int render_frame_id
) {
1963 chrome::SSLAddCertificate(cert_type
, cert_data
, cert_size
,
1964 render_process_id
, render_frame_id
);
1967 content::MediaObserver
* ChromeContentBrowserClient::GetMediaObserver() {
1968 return MediaCaptureDevicesDispatcher::GetInstance();
1971 content::PlatformNotificationService
*
1972 ChromeContentBrowserClient::GetPlatformNotificationService() {
1973 #if defined(ENABLE_NOTIFICATIONS)
1974 return PlatformNotificationServiceImpl::GetInstance();
1981 bool ChromeContentBrowserClient::CanCreateWindow(
1982 const GURL
& opener_url
,
1983 const GURL
& opener_top_level_frame_url
,
1984 const GURL
& source_origin
,
1985 WindowContainerType container_type
,
1986 const GURL
& target_url
,
1987 const content::Referrer
& referrer
,
1988 WindowOpenDisposition disposition
,
1989 const WebWindowFeatures
& features
,
1991 bool opener_suppressed
,
1992 content::ResourceContext
* context
,
1993 int render_process_id
,
1994 int opener_render_view_id
,
1995 int opener_render_frame_id
,
1996 bool* no_javascript_access
) {
1997 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1999 *no_javascript_access
= false;
2001 // If the opener is trying to create a background window but doesn't have
2002 // the appropriate permission, fail the attempt.
2003 if (container_type
== WINDOW_CONTAINER_TYPE_BACKGROUND
) {
2004 #if defined(ENABLE_EXTENSIONS)
2005 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
2006 InfoMap
* map
= io_data
->GetExtensionInfoMap();
2007 if (!map
->SecurityOriginHasAPIPermission(
2010 APIPermission::kBackground
)) {
2014 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2015 // return a recently installed Extension even if this CanCreateWindow call
2016 // was made by an old copy of the page in a normal web process. That's ok,
2017 // because the permission check above would have caused an early return
2018 // already. We must use the full URL to find hosted apps, though, and not
2020 const Extension
* extension
=
2021 map
->extensions().GetExtensionOrAppByURL(opener_url
);
2022 if (extension
&& !extensions::BackgroundInfo::AllowJSAccess(extension
))
2023 *no_javascript_access
= true;
2029 #if defined(ENABLE_EXTENSIONS)
2030 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
2035 HostContentSettingsMap
* content_settings
=
2036 ProfileIOData::FromResourceContext(context
)->GetHostContentSettingsMap();
2037 BlockedWindowParams
blocked_params(target_url
,
2044 opener_render_frame_id
);
2046 if (!user_gesture
&&
2047 !base::CommandLine::ForCurrentProcess()->HasSwitch(
2048 switches::kDisablePopupBlocking
)) {
2049 if (content_settings
->GetContentSetting(opener_top_level_frame_url
,
2050 opener_top_level_frame_url
,
2051 CONTENT_SETTINGS_TYPE_POPUPS
,
2053 CONTENT_SETTING_ALLOW
) {
2054 BrowserThread::PostTask(BrowserThread::UI
,
2056 base::Bind(&HandleBlockedPopupOnUIThread
,
2062 #if defined(OS_ANDROID)
2063 if (SingleTabModeTabHelper::IsRegistered(render_process_id
,
2064 opener_render_view_id
)) {
2065 BrowserThread::PostTask(BrowserThread::UI
,
2067 base::Bind(&HandleSingleTabModeBlockOnUIThread
,
2076 void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2077 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
2078 return g_browser_process
->ResourceDispatcherHostCreated();
2081 content::SpeechRecognitionManagerDelegate
*
2082 ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
2083 return new speech::ChromeSpeechRecognitionManagerDelegate();
2086 net::NetLog
* ChromeContentBrowserClient::GetNetLog() {
2087 return g_browser_process
->net_log();
2090 AccessTokenStore
* ChromeContentBrowserClient::CreateAccessTokenStore() {
2091 return new ChromeAccessTokenStore();
2094 bool ChromeContentBrowserClient::IsFastShutdownPossible() {
2098 void ChromeContentBrowserClient::OverrideWebkitPrefs(
2099 RenderViewHost
* rvh
, WebPreferences
* web_prefs
) {
2100 Profile
* profile
= Profile::FromBrowserContext(
2101 rvh
->GetProcess()->GetBrowserContext());
2102 PrefService
* prefs
= profile
->GetPrefs();
2104 // Fill per-script font preferences. These are not registered on Android
2105 // - http://crbug.com/308033.
2106 #if !defined(OS_ANDROID)
2107 FontFamilyCache::FillFontFamilyMap(profile
,
2108 prefs::kWebKitStandardFontFamilyMap
,
2109 &web_prefs
->standard_font_family_map
);
2110 FontFamilyCache::FillFontFamilyMap(profile
,
2111 prefs::kWebKitFixedFontFamilyMap
,
2112 &web_prefs
->fixed_font_family_map
);
2113 FontFamilyCache::FillFontFamilyMap(profile
,
2114 prefs::kWebKitSerifFontFamilyMap
,
2115 &web_prefs
->serif_font_family_map
);
2116 FontFamilyCache::FillFontFamilyMap(profile
,
2117 prefs::kWebKitSansSerifFontFamilyMap
,
2118 &web_prefs
->sans_serif_font_family_map
);
2119 FontFamilyCache::FillFontFamilyMap(profile
,
2120 prefs::kWebKitCursiveFontFamilyMap
,
2121 &web_prefs
->cursive_font_family_map
);
2122 FontFamilyCache::FillFontFamilyMap(profile
,
2123 prefs::kWebKitFantasyFontFamilyMap
,
2124 &web_prefs
->fantasy_font_family_map
);
2125 FontFamilyCache::FillFontFamilyMap(profile
,
2126 prefs::kWebKitPictographFontFamilyMap
,
2127 &web_prefs
->pictograph_font_family_map
);
2130 web_prefs
->default_font_size
=
2131 prefs
->GetInteger(prefs::kWebKitDefaultFontSize
);
2132 web_prefs
->default_fixed_font_size
=
2133 prefs
->GetInteger(prefs::kWebKitDefaultFixedFontSize
);
2134 web_prefs
->minimum_font_size
=
2135 prefs
->GetInteger(prefs::kWebKitMinimumFontSize
);
2136 web_prefs
->minimum_logical_font_size
=
2137 prefs
->GetInteger(prefs::kWebKitMinimumLogicalFontSize
);
2139 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2141 web_prefs
->javascript_can_open_windows_automatically
=
2142 prefs
->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically
);
2143 web_prefs
->dom_paste_enabled
=
2144 prefs
->GetBoolean(prefs::kWebKitDomPasteEnabled
);
2145 web_prefs
->tabs_to_links
= prefs
->GetBoolean(prefs::kWebkitTabsToLinks
);
2147 if (!prefs
->GetBoolean(prefs::kWebKitJavascriptEnabled
))
2148 web_prefs
->javascript_enabled
= false;
2149 if (!prefs
->GetBoolean(prefs::kWebKitWebSecurityEnabled
))
2150 web_prefs
->web_security_enabled
= false;
2151 if (!prefs
->GetBoolean(prefs::kWebKitPluginsEnabled
))
2152 web_prefs
->plugins_enabled
= false;
2153 web_prefs
->loads_images_automatically
=
2154 prefs
->GetBoolean(prefs::kWebKitLoadsImagesAutomatically
);
2156 if (prefs
->GetBoolean(prefs::kDisable3DAPIs
))
2157 web_prefs
->experimental_webgl_enabled
= false;
2159 web_prefs
->allow_displaying_insecure_content
=
2160 prefs
->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent
);
2161 web_prefs
->allow_running_insecure_content
=
2162 prefs
->GetBoolean(prefs::kWebKitAllowRunningInsecureContent
);
2163 #if defined(OS_ANDROID)
2164 web_prefs
->font_scale_factor
=
2165 static_cast<float>(prefs
->GetDouble(prefs::kWebKitFontScaleFactor
));
2166 web_prefs
->device_scale_adjustment
= GetDeviceScaleAdjustment();
2167 web_prefs
->force_enable_zoom
=
2168 prefs
->GetBoolean(prefs::kWebKitForceEnableZoom
);
2171 #if defined(OS_ANDROID)
2172 web_prefs
->password_echo_enabled
=
2173 prefs
->GetBoolean(prefs::kWebKitPasswordEchoEnabled
);
2175 web_prefs
->password_echo_enabled
= browser_defaults::kPasswordEchoEnabled
;
2178 web_prefs
->asynchronous_spell_checking_enabled
= true;
2179 web_prefs
->unified_textchecker_enabled
= true;
2181 web_prefs
->uses_universal_detector
=
2182 prefs
->GetBoolean(prefs::kWebKitUsesUniversalDetector
);
2183 web_prefs
->text_areas_are_resizable
=
2184 prefs
->GetBoolean(prefs::kWebKitTextAreasAreResizable
);
2185 web_prefs
->hyperlink_auditing_enabled
=
2186 prefs
->GetBoolean(prefs::kEnableHyperlinkAuditing
);
2188 #if defined(ENABLE_EXTENSIONS)
2189 std::string image_animation_policy
=
2190 prefs
->GetString(prefs::kAnimationPolicy
);
2191 if (image_animation_policy
== kAnimationPolicyOnce
)
2192 web_prefs
->animation_policy
=
2193 content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE
;
2194 else if (image_animation_policy
== kAnimationPolicyNone
)
2195 web_prefs
->animation_policy
= content::IMAGE_ANIMATION_POLICY_NO_ANIMATION
;
2197 web_prefs
->animation_policy
= content::IMAGE_ANIMATION_POLICY_ALLOWED
;
2200 // Make sure we will set the default_encoding with canonical encoding name.
2201 web_prefs
->default_encoding
=
2202 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
2203 web_prefs
->default_encoding
);
2204 if (web_prefs
->default_encoding
.empty()) {
2205 prefs
->ClearPref(prefs::kDefaultCharset
);
2206 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2208 DCHECK(!web_prefs
->default_encoding
.empty());
2210 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2211 switches::kEnablePotentiallyAnnoyingSecurityFeatures
)) {
2212 web_prefs
->disable_reading_from_canvas
= true;
2213 web_prefs
->strict_mixed_content_checking
= true;
2214 web_prefs
->strict_powerful_feature_restrictions
= true;
2217 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2218 extra_parts_
[i
]->OverrideWebkitPrefs(rvh
, web_prefs
);
2221 void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2222 BrowserURLHandler
* handler
) {
2223 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2224 extra_parts_
[i
]->BrowserURLHandlerCreated(handler
);
2226 // about: handler. Must come before chrome: handler, since it will
2227 // rewrite about: urls to chrome: URLs and then expect chrome: to
2228 // actually handle them. Also relies on a preliminary fixup phase.
2229 handler
->SetFixupHandler(&FixupBrowserAboutURL
);
2230 handler
->AddHandlerPair(&WillHandleBrowserAboutURL
,
2231 BrowserURLHandler::null_handler());
2233 #if defined(OS_ANDROID)
2234 // Handler to rewrite chrome://newtab on Android.
2235 handler
->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL
,
2236 BrowserURLHandler::null_handler());
2238 // Handler to rewrite chrome://newtab for InstantExtended.
2239 handler
->AddHandlerPair(&search::HandleNewTabURLRewrite
,
2240 &search::HandleNewTabURLReverseRewrite
);
2243 // chrome: & friends.
2244 handler
->AddHandlerPair(&HandleWebUI
, &HandleWebUIReverse
);
2247 void ChromeContentBrowserClient::ClearCache(RenderFrameHost
* rfh
) {
2248 Profile
* profile
= Profile::FromBrowserContext(
2249 rfh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2250 BrowsingDataRemover
* remover
=
2251 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2252 remover
->Remove(BrowsingDataRemover::REMOVE_CACHE
,
2253 BrowsingDataHelper::UNPROTECTED_WEB
);
2254 // BrowsingDataRemover takes care of deleting itself when done.
2257 void ChromeContentBrowserClient::ClearCookies(RenderFrameHost
* rfh
) {
2258 Profile
* profile
= Profile::FromBrowserContext(
2259 rfh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2260 BrowsingDataRemover
* remover
=
2261 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2262 int remove_mask
= BrowsingDataRemover::REMOVE_SITE_DATA
;
2263 remover
->Remove(remove_mask
, BrowsingDataHelper::UNPROTECTED_WEB
);
2264 // BrowsingDataRemover takes care of deleting itself when done.
2267 base::FilePath
ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
2268 return DownloadPrefs::GetDefaultDownloadDirectory();
2271 std::string
ChromeContentBrowserClient::GetDefaultDownloadName() {
2272 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME
);
2275 base::FilePath
ChromeContentBrowserClient::GetShaderDiskCacheDirectory() {
2276 base::FilePath user_data_dir
;
2277 PathService::Get(DIR_USER_DATA
, &user_data_dir
);
2278 DCHECK(!user_data_dir
.empty());
2279 return user_data_dir
.Append(FILE_PATH_LITERAL("ShaderCache"));
2282 void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2283 content::BrowserPpapiHost
* browser_host
) {
2284 #if defined(ENABLE_PLUGINS)
2285 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host
);
2289 content::BrowserPpapiHost
*
2290 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2291 int plugin_process_id
) {
2292 #if !defined(DISABLE_NACL)
2293 content::BrowserChildProcessHostIterator
iter(PROCESS_TYPE_NACL_LOADER
);
2294 while (!iter
.Done()) {
2295 nacl::NaClProcessHost
* host
= static_cast<nacl::NaClProcessHost
*>(
2296 iter
.GetDelegate());
2297 if (host
->process() &&
2298 host
->process()->GetData().id
== plugin_process_id
) {
2299 // Found the plugin.
2300 return host
->browser_ppapi_host();
2308 bool ChromeContentBrowserClient::AllowPepperSocketAPI(
2309 content::BrowserContext
* browser_context
,
2312 const content::SocketPermissionRequest
* params
) {
2313 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2314 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
2315 browser_context
, url
, private_api
, params
, allowed_socket_origins_
);
2321 ui::SelectFilePolicy
* ChromeContentBrowserClient::CreateSelectFilePolicy(
2322 WebContents
* web_contents
) {
2323 return new ChromeSelectFilePolicy(web_contents
);
2326 void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2327 std::vector
<std::string
>* additional_allowed_schemes
) {
2328 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2329 additional_allowed_schemes
);
2330 additional_allowed_schemes
->push_back(content::kChromeDevToolsScheme
);
2331 additional_allowed_schemes
->push_back(content::kChromeUIScheme
);
2332 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
2333 extra_parts_
[i
]->GetAdditionalAllowedSchemesForFileSystem(
2334 additional_allowed_schemes
);
2338 void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
2339 std::vector
<storage::URLRequestAutoMountHandler
>* handlers
) {
2340 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2341 extra_parts_
[i
]->GetURLRequestAutoMountHandlers(handlers
);
2344 void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
2345 content::BrowserContext
* browser_context
,
2346 const base::FilePath
& storage_partition_path
,
2347 ScopedVector
<storage::FileSystemBackend
>* additional_backends
) {
2348 #if defined(OS_CHROMEOS)
2349 storage::ExternalMountPoints
* external_mount_points
=
2350 content::BrowserContext::GetMountPoints(browser_context
);
2351 DCHECK(external_mount_points
);
2352 chromeos::FileSystemBackend
* backend
= new chromeos::FileSystemBackend(
2353 new drive::FileSystemBackendDelegate
,
2354 new chromeos::file_system_provider::BackendDelegate
,
2355 new chromeos::MTPFileSystemBackendDelegate(storage_partition_path
),
2356 external_mount_points
,
2357 storage::ExternalMountPoints::GetSystemInstance());
2358 backend
->AddSystemMountPoints();
2359 DCHECK(backend
->CanHandleType(storage::kFileSystemTypeExternal
));
2360 additional_backends
->push_back(backend
);
2363 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
2364 extra_parts_
[i
]->GetAdditionalFileSystemBackends(
2365 browser_context
, storage_partition_path
, additional_backends
);
2369 #if defined(OS_ANDROID)
2370 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2371 const base::CommandLine
& command_line
,
2372 int child_process_id
,
2373 FileDescriptorInfo
* mappings
,
2374 std::map
<int, base::MemoryMappedFile::Region
>* regions
) {
2375 int fd
= ui::GetMainAndroidPackFd(
2376 &(*regions
)[kAndroidUIResourcesPakDescriptor
]);
2377 mappings
->Share(kAndroidUIResourcesPakDescriptor
, fd
);
2379 fd
= ui::GetCommonResourcesPackFd(
2380 &(*regions
)[kAndroidChrome100PercentPakDescriptor
]);
2381 mappings
->Share(kAndroidChrome100PercentPakDescriptor
, fd
);
2383 fd
= ui::GetLocalePackFd(&(*regions
)[kAndroidLocalePakDescriptor
]);
2384 mappings
->Share(kAndroidLocalePakDescriptor
, fd
);
2386 if (breakpad::IsCrashReporterEnabled()) {
2388 breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile(
2390 if (file
.IsValid()) {
2391 mappings
->Transfer(kAndroidMinidumpDescriptor
,
2392 base::ScopedFD(file
.TakePlatformFile()));
2394 LOG(ERROR
) << "Failed to create file for minidump, crash reporting will "
2395 "be disabled for this process.";
2399 base::FilePath app_data_path
;
2400 PathService::Get(base::DIR_ANDROID_APP_DATA
, &app_data_path
);
2401 DCHECK(!app_data_path
.empty());
2403 #elif defined(OS_POSIX) && !defined(OS_MACOSX)
2404 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2405 const base::CommandLine
& command_line
,
2406 int child_process_id
,
2407 FileDescriptorInfo
* mappings
) {
2408 int crash_signal_fd
= GetCrashSignalFD(command_line
);
2409 if (crash_signal_fd
>= 0) {
2410 mappings
->Share(kCrashDumpSignal
, crash_signal_fd
);
2413 #endif // defined(OS_ANDROID)
2416 const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2417 return chrome::kBrowserResourcesDll
;
2420 base::string16
ChromeContentBrowserClient::GetAppContainerSidForSandboxType(
2421 int sandbox_type
) const {
2424 #if defined(GOOGLE_CHROME_BUILD)
2425 const version_info::Channel channel
= chrome::GetChannel();
2427 // It's possible to have a SxS installation running at the same time as a
2428 // non-SxS so isolate them from each other.
2429 if (channel
== version_info::Channel::CANARY
) {
2431 L
"S-1-15-2-3251537155-1984446955-2931258699-841473695-1938553385-"
2435 L
"S-1-15-2-3251537155-1984446955-2931258699-841473695-1938553385-"
2440 L
"S-1-15-2-3251537155-1984446955-2931258699-841473695-1938553385-"
2444 // TODO(wfh): Add support for more process types here. crbug.com/499523
2445 switch (sandbox_type
) {
2446 case content::SANDBOX_TYPE_RENDERER
:
2447 return sid
+ L
"129201922";
2448 case content::SANDBOX_TYPE_UTILITY
:
2449 return base::string16();
2450 case content::SANDBOX_TYPE_GPU
:
2451 return base::string16();
2452 case content::SANDBOX_TYPE_PPAPI
:
2453 return sid
+ L
"129201925";
2454 #if !defined(DISABLE_NACL)
2455 case PROCESS_TYPE_NACL_LOADER
:
2456 return base::string16();
2457 case PROCESS_TYPE_NACL_BROKER
:
2458 return base::string16();
2462 // Should never reach here.
2464 return base::string16();
2467 void ChromeContentBrowserClient::PreSpawnRenderer(
2468 sandbox::TargetPolicy
* policy
,
2470 // This code is duplicated in nacl_exe_win_64.cc.
2471 // Allow the server side of a pipe restricted to the "chrome.nacl."
2472 // namespace so that it cannot impersonate other system or other chrome
2474 sandbox::ResultCode result
= policy
->AddRule(
2475 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES
,
2476 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY
,
2477 L
"\\\\.\\pipe\\chrome.nacl.*");
2478 if (result
!= sandbox::SBOX_ALL_OK
) {
2483 // Renderers need to send named pipe handles and shared memory
2484 // segment handles to NaCl loader processes.
2485 result
= policy
->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES
,
2486 sandbox::TargetPolicy::HANDLES_DUP_ANY
,
2488 if (result
!= sandbox::SBOX_ALL_OK
) {
2495 void ChromeContentBrowserClient::RegisterFrameMojoShellServices(
2496 content::ServiceRegistry
* registry
,
2497 content::RenderFrameHost
* render_frame_host
) {
2498 #if defined(OS_CHROMEOS)
2499 registry
->AddService(
2500 base::Bind(&chromeos::attestation::PlatformVerificationImpl::Create
,
2501 render_frame_host
));
2505 void ChromeContentBrowserClient::RegisterInProcessMojoApplications(
2506 StaticMojoApplicationMap
* apps
) {
2507 #if !defined(OS_ANDROID) && !defined(OS_IOS)
2508 apps
->insert(std::make_pair(GURL(device::kDevicesMojoAppUrl
),
2509 base::Bind(&device::DevicesAppFactory::CreateApp
,
2510 base::ThreadTaskRunnerHandle::Get())));
2514 void ChromeContentBrowserClient::OpenURL(
2515 content::BrowserContext
* browser_context
,
2516 const content::OpenURLParams
& params
,
2517 const base::Callback
<void(content::WebContents
*)>& callback
) {
2518 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
2520 #if !defined(OS_ANDROID) && !defined(OS_IOS)
2521 NavigateParams
nav_params(Profile::FromBrowserContext(browser_context
),
2524 FillNavigateParamsFromOpenURLParams(&nav_params
, params
);
2525 nav_params
.user_gesture
= params
.user_gesture
;
2527 Navigate(&nav_params
);
2528 callback
.Run(nav_params
.target_contents
);
2529 #elif defined(OS_ANDROID)
2530 service_tab_launcher::ServiceTabLauncher::GetInstance()->LaunchTab(
2531 browser_context
, params
, callback
);
2537 content::PresentationServiceDelegate
*
2538 ChromeContentBrowserClient::GetPresentationServiceDelegate(
2539 content::WebContents
* web_contents
) {
2540 #if defined(ENABLE_MEDIA_ROUTER)
2541 if (switches::MediaRouterEnabled()) {
2542 return media_router::PresentationServiceDelegateImpl::
2543 GetOrCreateForWebContents(web_contents
);
2549 void ChromeContentBrowserClient::RecordURLMetric(const std::string
& metric
,
2551 if (url
.is_valid()) {
2552 rappor::SampleDomainAndRegistryFromGURL(g_browser_process
->rappor_service(),
2557 content::DevToolsManagerDelegate
*
2558 ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
2559 return new ChromeDevToolsManagerDelegate();
2562 content::TracingDelegate
* ChromeContentBrowserClient::GetTracingDelegate() {
2563 #if !defined(OS_ANDROID)
2564 return new ChromeTracingDelegate();
2570 bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2571 content::BrowserContext
* browser_context
,
2573 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2574 return ChromeContentBrowserClientPluginsPart::
2575 IsPluginAllowedToCallRequestOSFileHandle(browser_context
, url
,
2576 allowed_file_handle_origins_
);
2582 bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
2583 content::BrowserContext
* browser_context
,
2585 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2586 return ChromeContentBrowserClientPluginsPart::
2587 IsPluginAllowedToUseDevChannelAPIs(browser_context
, url
,
2588 allowed_dev_channel_origins_
);
2594 void ChromeContentBrowserClient::OverridePageVisibilityState(
2595 RenderFrameHost
* render_frame_host
,
2596 blink::WebPageVisibilityState
* visibility_state
) {
2597 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
2599 WebContents
* web_contents
=
2600 WebContents::FromRenderFrameHost(render_frame_host
);
2601 DCHECK(web_contents
);
2604 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
2605 prerender::PrerenderManager
* prerender_manager
=
2606 prerender::PrerenderManagerFactory::GetForProfile(profile
);
2607 if (prerender_manager
&&
2608 prerender_manager
->IsWebContentsPrerendering(web_contents
, nullptr)) {
2609 *visibility_state
= blink::WebPageVisibilityStatePrerender
;
2613 #if defined(ENABLE_WEBRTC)
2614 void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
2615 base::CommandLine
* to_command_line
,
2616 const base::CommandLine
& from_command_line
,
2617 version_info::Channel channel
) {
2618 #if defined(OS_ANDROID)
2619 const version_info::Channel kMaxDisableEncryptionChannel
=
2620 version_info::Channel::BETA
;
2622 const version_info::Channel kMaxDisableEncryptionChannel
=
2623 version_info::Channel::DEV
;
2625 if (channel
<= kMaxDisableEncryptionChannel
) {
2626 static const char* const kWebRtcDevSwitchNames
[] = {
2627 switches::kDisableWebRtcEncryption
,
2629 to_command_line
->CopySwitchesFrom(from_command_line
,
2630 kWebRtcDevSwitchNames
,
2631 arraysize(kWebRtcDevSwitchNames
));
2634 #endif // defined(ENABLE_WEBRTC)
2636 } // namespace chrome