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_fixer/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 // These are treated as WebUI schemes but do not get WebUI bindings. Also,
939 // view-source is allowed for these schemes.
940 void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
941 std::vector
<std::string
>* additional_schemes
) {
942 additional_schemes
->push_back(chrome::kChromeSearchScheme
);
943 additional_schemes
->push_back(dom_distiller::kDomDistillerScheme
);
946 void ChromeContentBrowserClient::GetAdditionalWebUIHostsToIgnoreParititionCheck(
947 std::vector
<std::string
>* hosts
) {
948 hosts
->push_back(chrome::kChromeUIExtensionIconHost
);
949 hosts
->push_back(chrome::kChromeUIFaviconHost
);
950 hosts
->push_back(chrome::kChromeUIThemeHost
);
951 hosts
->push_back(chrome::kChromeUIThumbnailHost
);
952 hosts
->push_back(chrome::kChromeUIThumbnailHost2
);
953 hosts
->push_back(chrome::kChromeUIThumbnailListHost
);
956 net::URLRequestContextGetter
*
957 ChromeContentBrowserClient::CreateRequestContext(
958 content::BrowserContext
* browser_context
,
959 content::ProtocolHandlerMap
* protocol_handlers
,
960 content::URLRequestInterceptorScopedVector request_interceptors
) {
961 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
962 return profile
->CreateRequestContext(protocol_handlers
,
963 request_interceptors
.Pass());
966 net::URLRequestContextGetter
*
967 ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
968 content::BrowserContext
* browser_context
,
969 const base::FilePath
& partition_path
,
971 content::ProtocolHandlerMap
* protocol_handlers
,
972 content::URLRequestInterceptorScopedVector request_interceptors
) {
973 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
974 return profile
->CreateRequestContextForStoragePartition(
978 request_interceptors
.Pass());
981 bool ChromeContentBrowserClient::IsHandledURL(const GURL
& url
) {
982 return ProfileIOData::IsHandledURL(url
);
985 bool ChromeContentBrowserClient::CanCommitURL(
986 content::RenderProcessHost
* process_host
,
988 #if defined(ENABLE_EXTENSIONS)
989 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(
996 bool ChromeContentBrowserClient::ShouldAllowOpenURL(
997 content::SiteInstance
* site_instance
, const GURL
& url
) {
998 GURL from_url
= site_instance
->GetSiteURL();
1000 #if defined(ENABLE_EXTENSIONS)
1002 if (ChromeContentBrowserClientExtensionsPart::ShouldAllowOpenURL(
1003 site_instance
, from_url
, url
, &result
))
1007 // Do not allow chrome://chrome-signin navigate to other chrome:// URLs, since
1008 // the signin page may host untrusted web content.
1009 if (from_url
.GetOrigin().spec() == chrome::kChromeUIChromeSigninURL
&&
1010 url
.SchemeIs(content::kChromeUIScheme
) &&
1011 url
.host() != chrome::kChromeUIChromeSigninHost
) {
1012 VLOG(1) << "Blocked navigation to " << url
.spec() << " from "
1013 << chrome::kChromeUIChromeSigninURL
;
1020 bool ChromeContentBrowserClient::IsSuitableHost(
1021 content::RenderProcessHost
* process_host
,
1022 const GURL
& site_url
) {
1024 Profile::FromBrowserContext(process_host
->GetBrowserContext());
1025 // This may be NULL during tests. In that case, just assume any site can
1030 // Instant URLs should only be in the instant process and instant process
1031 // should only have Instant URLs.
1032 InstantService
* instant_service
=
1033 InstantServiceFactory::GetForProfile(profile
);
1034 if (instant_service
) {
1035 bool is_instant_process
= instant_service
->IsInstantProcess(
1036 process_host
->GetID());
1037 bool should_be_in_instant_process
=
1038 search::ShouldAssignURLToInstantRenderer(site_url
, profile
);
1039 if (is_instant_process
|| should_be_in_instant_process
)
1040 return is_instant_process
&& should_be_in_instant_process
;
1043 #if defined(ENABLE_EXTENSIONS)
1044 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1045 profile
, process_host
, site_url
);
1051 bool ChromeContentBrowserClient::MayReuseHost(
1052 content::RenderProcessHost
* process_host
) {
1053 // If there is currently a prerender in progress for the host provided,
1054 // it may not be shared. We require prerenders to be by themselves in a
1055 // separate process so that we can monitor their resource usage.
1056 Profile
* profile
= Profile::FromBrowserContext(
1057 process_host
->GetBrowserContext());
1058 prerender::PrerenderManager
* prerender_manager
=
1059 prerender::PrerenderManagerFactory::GetForProfile(profile
);
1060 if (prerender_manager
&&
1061 !prerender_manager
->MayReuseProcessHost(process_host
)) {
1068 bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1069 content::BrowserContext
* browser_context
, const GURL
& url
) {
1070 // It has to be a valid URL for us to check for an extension.
1071 if (!url
.is_valid())
1074 #if defined(ENABLE_EXTENSIONS)
1075 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
1076 return ChromeContentBrowserClientExtensionsPart::
1077 ShouldTryToUseExistingProcessHost(
1084 void ChromeContentBrowserClient::SiteInstanceGotProcess(
1085 SiteInstance
* site_instance
) {
1086 CHECK(site_instance
->HasProcess());
1088 Profile
* profile
= Profile::FromBrowserContext(
1089 site_instance
->GetBrowserContext());
1093 // Remember the ID of the Instant process to signal the renderer process
1094 // on startup in |AppendExtraCommandLineSwitches| below.
1095 if (search::ShouldAssignURLToInstantRenderer(site_instance
->GetSiteURL(),
1097 InstantService
* instant_service
=
1098 InstantServiceFactory::GetForProfile(profile
);
1099 if (instant_service
)
1100 instant_service
->AddInstantProcess(site_instance
->GetProcess()->GetID());
1103 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
1104 extra_parts_
[i
]->SiteInstanceGotProcess(site_instance
);
1107 void ChromeContentBrowserClient::SiteInstanceDeleting(
1108 SiteInstance
* site_instance
) {
1109 if (!site_instance
->HasProcess())
1112 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
1113 extra_parts_
[i
]->SiteInstanceDeleting(site_instance
);
1116 bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
1117 SiteInstance
* site_instance
,
1118 const GURL
& current_url
,
1119 const GURL
& new_url
) {
1120 #if defined(ENABLE_EXTENSIONS)
1121 return ChromeContentBrowserClientExtensionsPart::
1122 ShouldSwapBrowsingInstancesForNavigation(
1123 site_instance
, current_url
, new_url
);
1129 bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1130 content::ResourceContext
* resource_context
, const GURL
& current_url
,
1131 const GURL
& new_url
) {
1132 #if defined(ENABLE_EXTENSIONS)
1133 return ChromeContentBrowserClientExtensionsPart::
1134 ShouldSwapProcessesForRedirect(resource_context
, current_url
, new_url
);
1140 bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL
& url
) {
1141 return !url
.SchemeIs(chrome::kChromeNativeScheme
);
1144 std::string
ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1145 const std::string
& alias_name
) {
1146 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name
);
1151 bool IsAutoReloadEnabled() {
1152 // Fetch the field trial, even though we don't use it. Calling FindFullName()
1153 // causes the field-trial mechanism to report which group we're in, which
1154 // might reflect a hard disable or hard enable via flag, both of which have
1155 // their own field trial groups. This lets us know what percentage of users
1156 // manually enable or disable auto-reload.
1157 std::string group
= base::FieldTrialList::FindFullName(
1158 "AutoReloadExperiment");
1159 const base::CommandLine
& browser_command_line
=
1160 *base::CommandLine::ForCurrentProcess();
1161 if (browser_command_line
.HasSwitch(switches::kEnableOfflineAutoReload
))
1163 if (browser_command_line
.HasSwitch(switches::kDisableOfflineAutoReload
))
1168 bool IsAutoReloadVisibleOnlyEnabled() {
1169 // See the block comment in IsAutoReloadEnabled().
1170 std::string group
= base::FieldTrialList::FindFullName(
1171 "AutoReloadVisibleOnlyExperiment");
1172 const base::CommandLine
& browser_command_line
=
1173 *base::CommandLine::ForCurrentProcess();
1174 if (browser_command_line
.HasSwitch(
1175 switches::kEnableOfflineAutoReloadVisibleOnly
)) {
1178 if (browser_command_line
.HasSwitch(
1179 switches::kDisableOfflineAutoReloadVisibleOnly
)) {
1185 void MaybeAppendBlinkSettingsSwitchForFieldTrial(
1186 const base::CommandLine
& browser_command_line
,
1187 base::CommandLine
* command_line
) {
1188 // List of field trials that modify the blink-settings command line flag. No
1189 // two field trials in the list should specify the same keys, otherwise one
1190 // field trial may overwrite another. See Source/core/frame/Settings.in in
1191 // Blink for the list of valid keys.
1192 static const char* const kBlinkSettingsFieldTrials
[] = {
1193 // Keys: backgroundHtmlParserOutstandingTokenLimit
1194 // backgroundHtmlParserPendingTokenLimit
1195 "BackgroundHtmlParserTokenLimits",
1197 // Keys: doHtmlPreloadScanning
1198 "HtmlPreloadScanning",
1200 // Keys: lowPriorityIframes
1201 "LowPriorityIFrames",
1204 std::vector
<std::string
> blink_settings
;
1205 for (const char* field_trial_name
: kBlinkSettingsFieldTrials
) {
1206 // Each blink-settings field trial should include a forcing_flag group,
1207 // to make sure that clients that specify the blink-settings flag on the
1208 // command line are excluded from the experiment groups. To make
1209 // sure we assign clients that specify this flag to the forcing_flag
1210 // group, we must call GetVariationParams for each field trial first
1211 // (for example, before checking HasSwitch() and returning), since
1212 // GetVariationParams has the side-effect of assigning the client to
1213 // a field trial group.
1214 std::map
<std::string
, std::string
> params
;
1215 if (variations::GetVariationParams(field_trial_name
, ¶ms
)) {
1216 for (const auto& param
: params
) {
1217 blink_settings
.push_back(base::StringPrintf(
1218 "%s=%s", param
.first
.c_str(), param
.second
.c_str()));
1222 if (blink_settings
.empty()) {
1226 if (browser_command_line
.HasSwitch(switches::kBlinkSettings
) ||
1227 command_line
->HasSwitch(switches::kBlinkSettings
)) {
1228 // The field trial is configured to force users that specify the
1229 // blink-settings flag into a group with no params, and we return
1230 // above if no params were specified, so it's an error if we reach
1232 LOG(WARNING
) << "Received field trial params, "
1233 "but blink-settings switch already specified.";
1237 command_line
->AppendSwitchASCII(switches::kBlinkSettings
,
1238 base::JoinString(blink_settings
, ","));
1243 void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1244 base::CommandLine
* command_line
,
1245 int child_process_id
) {
1246 #if defined(OS_MACOSX)
1247 scoped_ptr
<metrics::ClientInfo
> client_info
=
1248 GoogleUpdateSettings::LoadMetricsClientInfo();
1250 command_line
->AppendSwitchASCII(switches::kMetricsClientID
,
1251 client_info
->client_id
);
1253 #elif defined(OS_POSIX)
1254 if (breakpad::IsCrashReporterEnabled()) {
1255 scoped_ptr
<metrics::ClientInfo
> client_info
=
1256 GoogleUpdateSettings::LoadMetricsClientInfo();
1257 command_line
->AppendSwitchASCII(switches::kEnableCrashReporter
,
1258 client_info
? client_info
->client_id
1263 if (logging::DialogsAreSuppressed())
1264 command_line
->AppendSwitch(switches::kNoErrorDialogs
);
1266 std::string process_type
=
1267 command_line
->GetSwitchValueASCII(switches::kProcessType
);
1268 const base::CommandLine
& browser_command_line
=
1269 *base::CommandLine::ForCurrentProcess();
1271 static const char* const kCommonSwitchNames
[] = {
1272 switches::kUserAgent
,
1273 switches::kUserDataDir
, // Make logs go to the right file.
1275 command_line
->CopySwitchesFrom(browser_command_line
, kCommonSwitchNames
,
1276 arraysize(kCommonSwitchNames
));
1278 #if defined(ENABLE_IPC_FUZZER)
1279 static const char* const kIpcFuzzerSwitches
[] = {
1280 switches::kIpcDumpDirectory
,
1281 switches::kIpcFuzzerTestcase
,
1283 command_line
->CopySwitchesFrom(browser_command_line
, kIpcFuzzerSwitches
,
1284 arraysize(kIpcFuzzerSwitches
));
1287 #if defined(OS_CHROMEOS)
1288 static const char* const kChromeOSSwitches
[] = {
1289 switches::kDisableDinosaurEasterEgg
,
1291 command_line
->CopySwitchesFrom(browser_command_line
, kChromeOSSwitches
,
1292 arraysize(kChromeOSSwitches
));
1294 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
1295 base::FilePath homedir
;
1296 PathService::Get(base::DIR_HOME
, &homedir
);
1297 command_line
->AppendSwitchASCII(chromeos::switches::kHomedir
,
1298 homedir
.value().c_str());
1301 if (process_type
== switches::kRendererProcess
) {
1302 content::RenderProcessHost
* process
=
1303 content::RenderProcessHost::FromID(child_process_id
);
1305 process
? Profile::FromBrowserContext(process
->GetBrowserContext())
1307 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
1308 extra_parts_
[i
]->AppendExtraRendererCommandLineSwitches(
1309 command_line
, process
, profile
);
1312 #if defined(OS_CHROMEOS)
1313 const std::string
& login_profile
=
1314 browser_command_line
.GetSwitchValueASCII(
1315 chromeos::switches::kLoginProfile
);
1316 if (!login_profile
.empty())
1317 command_line
->AppendSwitchASCII(
1318 chromeos::switches::kLoginProfile
, login_profile
);
1321 #if defined(ENABLE_WEBRTC)
1322 MaybeCopyDisableWebRtcEncryptionSwitch(command_line
,
1323 browser_command_line
,
1324 chrome::GetChannel());
1328 PrefService
* prefs
= profile
->GetPrefs();
1329 // Currently this pref is only registered if applied via a policy.
1330 if (prefs
->HasPrefPath(prefs::kDisable3DAPIs
) &&
1331 prefs
->GetBoolean(prefs::kDisable3DAPIs
)) {
1332 // Turn this policy into a command line switch.
1333 command_line
->AppendSwitch(switches::kDisable3DAPIs
);
1336 const base::ListValue
* switches
=
1337 prefs
->GetList(prefs::kEnableDeprecatedWebPlatformFeatures
);
1339 // Enable any deprecated features that have been re-enabled by policy.
1340 for (base::ListValue::const_iterator it
= switches
->begin();
1341 it
!= switches
->end(); ++it
) {
1342 std::string switch_to_enable
;
1343 if ((*it
)->GetAsString(&switch_to_enable
))
1344 command_line
->AppendSwitch(switch_to_enable
);
1348 // Disable client-side phishing detection in the renderer if it is
1349 // disabled in the Profile preferences or the browser process.
1350 if (!prefs
->GetBoolean(prefs::kSafeBrowsingEnabled
) ||
1351 !g_browser_process
->safe_browsing_detection_service()) {
1352 command_line
->AppendSwitch(
1353 switches::kDisableClientSidePhishingDetection
);
1356 if (prefs
->GetBoolean(prefs::kPrintPreviewDisabled
))
1357 command_line
->AppendSwitch(switches::kDisablePrintPreview
);
1359 InstantService
* instant_service
=
1360 InstantServiceFactory::GetForProfile(profile
);
1361 if (instant_service
&&
1362 instant_service
->IsInstantProcess(process
->GetID()))
1363 command_line
->AppendSwitch(switches::kInstantProcess
);
1366 if (IsAutoReloadEnabled())
1367 command_line
->AppendSwitch(switches::kEnableOfflineAutoReload
);
1368 if (IsAutoReloadVisibleOnlyEnabled()) {
1369 command_line
->AppendSwitch(
1370 switches::kEnableOfflineAutoReloadVisibleOnly
);
1374 // Enable showing a saved copy if this session is in the field trial
1375 // or the user explicitly enabled it. Note that as far as the
1376 // renderer is concerned, the feature is enabled if-and-only-if
1377 // one of the kEnableShowSavedCopy* switches is on the command
1378 // line; the yes/no/default behavior is only at the browser
1379 // command line level.
1381 // Command line switches override
1382 const std::string
& show_saved_copy_value
=
1383 browser_command_line
.GetSwitchValueASCII(switches::kShowSavedCopy
);
1384 if (show_saved_copy_value
== switches::kEnableShowSavedCopyPrimary
||
1385 show_saved_copy_value
== switches::kEnableShowSavedCopySecondary
||
1386 show_saved_copy_value
== switches::kDisableShowSavedCopy
) {
1387 command_line
->AppendSwitchASCII(switches::kShowSavedCopy
,
1388 show_saved_copy_value
);
1391 base::FieldTrialList::FindFullName("LoadStaleCacheExperiment");
1393 if (group
== "Primary") {
1394 command_line
->AppendSwitchASCII(
1395 switches::kShowSavedCopy
, switches::kEnableShowSavedCopyPrimary
);
1396 } else if (group
== "Secondary") {
1397 command_line
->AppendSwitchASCII(
1398 switches::kShowSavedCopy
,
1399 switches::kEnableShowSavedCopySecondary
);
1404 MaybeAppendBlinkSettingsSwitchForFieldTrial(
1405 browser_command_line
, command_line
);
1407 // Please keep this in alphabetical order.
1408 static const char* const kSwitchNames
[] = {
1409 autofill::switches::kDisableFillOnAccountSelect
,
1410 autofill::switches::kDisablePasswordGeneration
,
1411 autofill::switches::kEnableAccessorySuggestionView
,
1412 autofill::switches::kEnableFillOnAccountSelect
,
1413 autofill::switches::kEnableFillOnAccountSelectNoHighlighting
,
1414 autofill::switches::kEnablePasswordGeneration
,
1415 autofill::switches::kEnableSingleClickAutofill
,
1416 autofill::switches::kEnableSuggestionsWithSubstringMatch
,
1417 autofill::switches::kIgnoreAutocompleteOffForAutofill
,
1418 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration
,
1419 #if defined(ENABLE_EXTENSIONS)
1420 extensions::switches::kAllowHTTPBackgroundPage
,
1421 extensions::switches::kAllowLegacyExtensionManifests
,
1422 extensions::switches::kEnableSurfaceWorker
,
1423 extensions::switches::kEnableAppWindowControls
,
1424 extensions::switches::kEnableEmbeddedExtensionOptions
,
1425 extensions::switches::kEnableExperimentalExtensionApis
,
1426 extensions::switches::kExtensionsOnChromeURLs
,
1427 extensions::switches::kWhitelistedExtensionID
,
1429 switches::kAllowInsecureLocalhost
,
1430 switches::kAppsCheckoutURL
,
1431 switches::kAppsGalleryURL
,
1432 switches::kCloudPrintURL
,
1433 switches::kCloudPrintXmppEndpoint
,
1434 switches::kDisableBundledPpapiFlash
,
1435 switches::kDisableCastStreamingHWEncoding
,
1436 switches::kDisableJavaScriptHarmonyShipping
,
1437 switches::kDisableNewBookmarkApps
,
1438 switches::kEnableBenchmarking
,
1439 switches::kEnableNaCl
,
1440 #if !defined(DISABLE_NACL)
1441 switches::kEnableNaClDebug
,
1442 switches::kEnableNaClNonSfiMode
,
1443 switches::kEnablePNaClSubzero
,
1445 switches::kEnableNetBenchmarking
,
1446 switches::kEnableNewBookmarkApps
,
1447 switches::kEnablePluginPlaceholderShadowDom
,
1448 switches::kJavaScriptHarmony
,
1449 switches::kMessageLoopHistogrammer
,
1450 switches::kPpapiFlashArgs
,
1451 switches::kPpapiFlashPath
,
1452 switches::kPpapiFlashVersion
,
1453 switches::kProfilingAtStart
,
1454 switches::kProfilingFile
,
1455 switches::kProfilingFlush
,
1456 switches::kUnsafelyTreatInsecureOriginAsSecure
,
1457 translate::switches::kTranslateSecurityOrigin
,
1460 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1461 arraysize(kSwitchNames
));
1462 } else if (process_type
== switches::kUtilityProcess
) {
1463 #if defined(ENABLE_EXTENSIONS)
1464 static const char* const kSwitchNames
[] = {
1465 extensions::switches::kAllowHTTPBackgroundPage
,
1466 extensions::switches::kEnableExperimentalExtensionApis
,
1467 extensions::switches::kExtensionsOnChromeURLs
,
1468 extensions::switches::kWhitelistedExtensionID
,
1471 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1472 arraysize(kSwitchNames
));
1474 } else if (process_type
== switches::kPluginProcess
) {
1475 #if defined(OS_CHROMEOS)
1476 static const char* const kSwitchNames
[] = {
1477 chromeos::switches::kLoginProfile
,
1480 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1481 arraysize(kSwitchNames
));
1483 } else if (process_type
== switches::kZygoteProcess
) {
1484 static const char* const kSwitchNames
[] = {
1485 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
1486 switches::kDisableBundledPpapiFlash
,
1487 #if !defined(DISABLE_NACL)
1488 switches::kEnableNaClDebug
,
1489 switches::kEnableNaClNonSfiMode
,
1490 switches::kEnablePNaClSubzero
,
1491 switches::kNaClDangerousNoSandboxNonSfi
,
1492 switches::kUseNaClHelperNonSfi
,
1494 switches::kPpapiFlashPath
,
1495 switches::kPpapiFlashVersion
,
1498 command_line
->CopySwitchesFrom(browser_command_line
, kSwitchNames
,
1499 arraysize(kSwitchNames
));
1500 } else if (process_type
== switches::kGpuProcess
) {
1501 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1502 // because GPU is expected to be unreliable.
1503 if (browser_command_line
.HasSwitch(switches::kIgnoreGpuBlacklist
) &&
1504 !command_line
->HasSwitch(switches::kDisableBreakpad
))
1505 command_line
->AppendSwitch(switches::kDisableBreakpad
);
1508 // The command line switch kEnableBenchmarking needs to be specified along
1509 // with the kEnableStatsTable switch to ensure that the stats table global
1510 // is initialized correctly.
1511 if (command_line
->HasSwitch(switches::kEnableBenchmarking
))
1512 DCHECK(command_line
->HasSwitch(switches::kEnableStatsTable
));
1515 std::string
ChromeContentBrowserClient::GetApplicationLocale() {
1516 if (BrowserThread::CurrentlyOn(BrowserThread::IO
))
1517 return g_io_thread_application_locale
.Get();
1518 return g_browser_process
->GetApplicationLocale();
1521 std::string
ChromeContentBrowserClient::GetAcceptLangs(
1522 content::BrowserContext
* context
) {
1523 Profile
* profile
= Profile::FromBrowserContext(context
);
1524 return profile
->GetPrefs()->GetString(prefs::kAcceptLanguages
);
1527 const gfx::ImageSkia
* ChromeContentBrowserClient::GetDefaultFavicon() {
1528 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
1529 return rb
.GetNativeImageNamed(IDR_DEFAULT_FAVICON
).ToImageSkia();
1532 bool ChromeContentBrowserClient::AllowAppCache(
1533 const GURL
& manifest_url
,
1534 const GURL
& first_party
,
1535 content::ResourceContext
* context
) {
1536 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1537 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1538 return io_data
->GetCookieSettings()->
1539 IsSettingCookieAllowed(manifest_url
, first_party
);
1542 bool ChromeContentBrowserClient::AllowServiceWorker(
1544 const GURL
& first_party_url
,
1545 content::ResourceContext
* context
,
1546 int render_process_id
,
1547 int render_frame_id
) {
1548 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1549 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1550 bool allow
= io_data
->GetCookieSettings()->IsSettingCookieAllowed(
1551 scope
, first_party_url
);
1553 // Record access to database for potential display in UI.
1554 BrowserThread::PostTask(
1555 BrowserThread::UI
, FROM_HERE
,
1556 base::Bind(&TabSpecificContentSettings::ServiceWorkerAccessed
,
1557 render_process_id
, render_frame_id
, scope
, !allow
));
1561 bool ChromeContentBrowserClient::AllowGetCookie(
1563 const GURL
& first_party
,
1564 const net::CookieList
& cookie_list
,
1565 content::ResourceContext
* context
,
1566 int render_process_id
,
1567 int render_frame_id
) {
1568 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1569 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1570 bool allow
= io_data
->GetCookieSettings()->
1571 IsReadingCookieAllowed(url
, first_party
);
1573 BrowserThread::PostTask(
1574 BrowserThread::UI
, FROM_HERE
,
1575 base::Bind(&TabSpecificContentSettings::CookiesRead
, render_process_id
,
1576 render_frame_id
, url
, first_party
, cookie_list
, !allow
));
1580 bool ChromeContentBrowserClient::AllowSetCookie(
1582 const GURL
& first_party
,
1583 const std::string
& cookie_line
,
1584 content::ResourceContext
* context
,
1585 int render_process_id
,
1586 int render_frame_id
,
1587 net::CookieOptions
* options
) {
1588 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1589 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1590 content_settings::CookieSettings
* cookie_settings
=
1591 io_data
->GetCookieSettings();
1592 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, first_party
);
1594 BrowserThread::PostTask(
1595 BrowserThread::UI
, FROM_HERE
,
1596 base::Bind(&TabSpecificContentSettings::CookieChanged
, render_process_id
,
1597 render_frame_id
, url
, first_party
, cookie_line
, *options
,
1602 bool ChromeContentBrowserClient::AllowSaveLocalState(
1603 content::ResourceContext
* context
) {
1604 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1605 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1606 content_settings::CookieSettings
* cookie_settings
=
1607 io_data
->GetCookieSettings();
1608 ContentSetting setting
= cookie_settings
->GetDefaultCookieSetting(NULL
);
1610 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1611 // Could we even support per-origin settings?
1612 return setting
!= CONTENT_SETTING_SESSION_ONLY
;
1615 bool ChromeContentBrowserClient::AllowWorkerDatabase(
1617 const base::string16
& name
,
1618 const base::string16
& display_name
,
1619 unsigned long estimated_size
,
1620 content::ResourceContext
* context
,
1621 const std::vector
<std::pair
<int, int> >& render_frames
) {
1622 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1623 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1624 content_settings::CookieSettings
* cookie_settings
=
1625 io_data
->GetCookieSettings();
1626 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1628 // Record access to database for potential display in UI.
1629 std::vector
<std::pair
<int, int> >::const_iterator i
;
1630 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1631 BrowserThread::PostTask(
1632 BrowserThread::UI
, FROM_HERE
,
1633 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed
,
1634 i
->first
, i
->second
, url
, name
, display_name
, !allow
));
1640 void ChromeContentBrowserClient::AllowWorkerFileSystem(
1642 content::ResourceContext
* context
,
1643 const std::vector
<std::pair
<int, int> >& render_frames
,
1644 base::Callback
<void(bool)> callback
) {
1645 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1646 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1647 content_settings::CookieSettings
* cookie_settings
=
1648 io_data
->GetCookieSettings();
1649 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1651 #if defined(ENABLE_EXTENSIONS)
1652 GuestPermissionRequestHelper(url
, render_frames
, callback
, allow
);
1654 FileSystemAccessed(url
, render_frames
, callback
, allow
);
1658 #if defined(ENABLE_EXTENSIONS)
1659 void ChromeContentBrowserClient::GuestPermissionRequestHelper(
1661 const std::vector
<std::pair
<int, int> >& render_frames
,
1662 base::Callback
<void(bool)> callback
,
1664 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::IO
));
1665 std::vector
<std::pair
<int, int> >::const_iterator i
;
1666 std::map
<int, int> process_map
;
1667 std::map
<int, int>::const_iterator it
;
1668 bool has_web_view_guest
= false;
1669 // Record access to file system for potential display in UI.
1670 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1671 if (process_map
.find(i
->first
) != process_map
.end())
1674 process_map
.insert(std::pair
<int, int>(i
->first
, i
->second
));
1676 if (extensions::WebViewRendererState::GetInstance()->IsGuest(i
->first
))
1677 has_web_view_guest
= true;
1679 if (!has_web_view_guest
) {
1680 FileSystemAccessed(url
, render_frames
, callback
, allow
);
1683 DCHECK_EQ(1U, process_map
.size());
1684 it
= process_map
.begin();
1685 BrowserThread::PostTask(
1688 base::Bind(&ChromeContentBrowserClient::
1689 RequestFileSystemPermissionOnUIThread
,
1694 base::Bind(&ChromeContentBrowserClient::FileSystemAccessed
,
1695 weak_factory_
.GetWeakPtr(),
1701 void ChromeContentBrowserClient::RequestFileSystemPermissionOnUIThread(
1702 int render_process_id
,
1703 int render_frame_id
,
1705 bool allowed_by_default
,
1706 const base::Callback
<void(bool)>& callback
) {
1707 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::UI
));
1708 extensions::WebViewPermissionHelper
* web_view_permission_helper
=
1709 extensions::WebViewPermissionHelper::FromFrameID(
1710 render_process_id
, render_frame_id
);
1711 web_view_permission_helper
->RequestFileSystemPermission(url
,
1717 void ChromeContentBrowserClient::FileSystemAccessed(
1719 const std::vector
<std::pair
<int, int> >& render_frames
,
1720 base::Callback
<void(bool)> callback
,
1722 // Record access to file system for potential display in UI.
1723 std::vector
<std::pair
<int, int> >::const_iterator i
;
1724 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1725 BrowserThread::PostTask(
1728 base::Bind(&TabSpecificContentSettings::FileSystemAccessed
,
1729 i
->first
, i
->second
, url
, !allow
));
1731 callback
.Run(allow
);
1734 bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1736 const base::string16
& name
,
1737 content::ResourceContext
* context
,
1738 const std::vector
<std::pair
<int, int> >& render_frames
) {
1739 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1740 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1741 content_settings::CookieSettings
* cookie_settings
=
1742 io_data
->GetCookieSettings();
1743 bool allow
= cookie_settings
->IsSettingCookieAllowed(url
, url
);
1745 // Record access to IndexedDB for potential display in UI.
1746 std::vector
<std::pair
<int, int> >::const_iterator i
;
1747 for (i
= render_frames
.begin(); i
!= render_frames
.end(); ++i
) {
1748 BrowserThread::PostTask(
1749 BrowserThread::UI
, FROM_HERE
,
1750 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed
,
1751 i
->first
, i
->second
, url
, name
, !allow
));
1757 #if defined(ENABLE_WEBRTC)
1758 bool ChromeContentBrowserClient::AllowWebRTCIdentityCache(
1760 const GURL
& first_party_url
,
1761 content::ResourceContext
* context
) {
1762 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
1763 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1764 content_settings::CookieSettings
* cookie_settings
=
1765 io_data
->GetCookieSettings();
1766 return cookie_settings
->IsReadingCookieAllowed(url
, first_party_url
) &&
1767 cookie_settings
->IsSettingCookieAllowed(url
, first_party_url
);
1769 #endif // defined(ENABLE_WEBRTC)
1771 net::URLRequestContext
*
1772 ChromeContentBrowserClient::OverrideRequestContextForURL(
1773 const GURL
& url
, content::ResourceContext
* context
) {
1774 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1775 #if defined(ENABLE_EXTENSIONS)
1776 if (url
.SchemeIs(extensions::kExtensionScheme
)) {
1777 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1778 return io_data
->extensions_request_context();
1785 QuotaPermissionContext
*
1786 ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1787 return new ChromeQuotaPermissionContext();
1790 void ChromeContentBrowserClient::AllowCertificateError(
1791 int render_process_id
,
1792 int render_frame_id
,
1794 const net::SSLInfo
& ssl_info
,
1795 const GURL
& request_url
,
1796 ResourceType resource_type
,
1798 bool strict_enforcement
,
1799 bool expired_previous_decision
,
1800 const base::Callback
<void(bool)>& callback
,
1801 content::CertificateRequestResultType
* result
) {
1802 if (resource_type
!= content::RESOURCE_TYPE_MAIN_FRAME
) {
1803 // A sub-resource has a certificate error. The user doesn't really
1804 // have a context for making the right decision, so block the
1805 // request hard, without an info bar to allow showing the insecure
1807 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY
;
1811 // If the tab is being prerendered, cancel the prerender and the request.
1812 content::RenderFrameHost
* render_frame_host
=
1813 content::RenderFrameHost::FromID(render_process_id
, render_frame_id
);
1814 WebContents
* tab
= WebContents::FromRenderFrameHost(render_frame_host
);
1820 prerender::PrerenderContents
* prerender_contents
=
1821 prerender::PrerenderContents::FromWebContents(tab
);
1822 if (prerender_contents
) {
1823 prerender_contents
->Destroy(prerender::FINAL_STATUS_SSL_ERROR
);
1824 *result
= content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL
;
1828 // Otherwise, display an SSL blocking page. The interstitial page takes
1829 // ownership of ssl_blocking_page.
1830 int options_mask
= 0;
1832 options_mask
|= SSLBlockingPage::OVERRIDABLE
;
1833 if (strict_enforcement
)
1834 options_mask
|= SSLBlockingPage::STRICT_ENFORCEMENT
;
1835 if (expired_previous_decision
)
1836 options_mask
|= SSLBlockingPage::EXPIRED_BUT_PREVIOUSLY_ALLOWED
;
1838 SafeBrowsingService
* safe_browsing_service
=
1839 g_browser_process
->safe_browsing_service();
1840 scoped_ptr
<SafeBrowsingSSLCertReporter
> cert_reporter(
1841 new SafeBrowsingSSLCertReporter(safe_browsing_service
1842 ? safe_browsing_service
->ui_manager()
1844 SSLErrorHandler::HandleSSLError(tab
, cert_error
, ssl_info
, request_url
,
1845 options_mask
, cert_reporter
.Pass(), callback
);
1848 void ChromeContentBrowserClient::SelectClientCertificate(
1849 content::WebContents
* web_contents
,
1850 net::SSLCertRequestInfo
* cert_request_info
,
1851 scoped_ptr
<content::ClientCertificateDelegate
> delegate
) {
1852 prerender::PrerenderContents
* prerender_contents
=
1853 prerender::PrerenderContents::FromWebContents(web_contents
);
1854 if (prerender_contents
) {
1855 prerender_contents
->Destroy(
1856 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED
);
1860 GURL
requesting_url("https://" + cert_request_info
->host_and_port
.ToString());
1861 DCHECK(requesting_url
.is_valid())
1862 << "Invalid URL string: https://"
1863 << cert_request_info
->host_and_port
.ToString();
1866 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
1867 scoped_ptr
<base::Value
> filter
=
1868 profile
->GetHostContentSettingsMap()->GetWebsiteSetting(
1871 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE
,
1876 // Try to automatically select a client certificate.
1877 if (filter
->IsType(base::Value::TYPE_DICTIONARY
)) {
1878 base::DictionaryValue
* filter_dict
=
1879 static_cast<base::DictionaryValue
*>(filter
.get());
1881 const std::vector
<scoped_refptr
<net::X509Certificate
> >&
1882 all_client_certs
= cert_request_info
->client_certs
;
1883 for (size_t i
= 0; i
< all_client_certs
.size(); ++i
) {
1884 if (CertMatchesFilter(*all_client_certs
[i
].get(), *filter_dict
)) {
1885 // Use the first certificate that is matched by the filter.
1886 delegate
->ContinueWithCertificate(all_client_certs
[i
].get());
1895 chrome::ShowSSLClientCertificateSelector(web_contents
, cert_request_info
,
1899 void ChromeContentBrowserClient::AddCertificate(
1900 net::CertificateMimeType cert_type
,
1901 const void* cert_data
,
1903 int render_process_id
,
1904 int render_frame_id
) {
1905 chrome::SSLAddCertificate(cert_type
, cert_data
, cert_size
,
1906 render_process_id
, render_frame_id
);
1909 content::MediaObserver
* ChromeContentBrowserClient::GetMediaObserver() {
1910 return MediaCaptureDevicesDispatcher::GetInstance();
1913 content::PlatformNotificationService
*
1914 ChromeContentBrowserClient::GetPlatformNotificationService() {
1915 #if defined(ENABLE_NOTIFICATIONS)
1916 return PlatformNotificationServiceImpl::GetInstance();
1923 bool ChromeContentBrowserClient::CanCreateWindow(
1924 const GURL
& opener_url
,
1925 const GURL
& opener_top_level_frame_url
,
1926 const GURL
& source_origin
,
1927 WindowContainerType container_type
,
1928 const GURL
& target_url
,
1929 const content::Referrer
& referrer
,
1930 WindowOpenDisposition disposition
,
1931 const WebWindowFeatures
& features
,
1933 bool opener_suppressed
,
1934 content::ResourceContext
* context
,
1935 int render_process_id
,
1936 int opener_render_view_id
,
1937 int opener_render_frame_id
,
1938 bool* no_javascript_access
) {
1939 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
1941 *no_javascript_access
= false;
1943 // If the opener is trying to create a background window but doesn't have
1944 // the appropriate permission, fail the attempt.
1945 if (container_type
== WINDOW_CONTAINER_TYPE_BACKGROUND
) {
1946 #if defined(ENABLE_EXTENSIONS)
1947 ProfileIOData
* io_data
= ProfileIOData::FromResourceContext(context
);
1948 InfoMap
* map
= io_data
->GetExtensionInfoMap();
1949 if (!map
->SecurityOriginHasAPIPermission(
1952 APIPermission::kBackground
)) {
1956 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1957 // return a recently installed Extension even if this CanCreateWindow call
1958 // was made by an old copy of the page in a normal web process. That's ok,
1959 // because the permission check above would have caused an early return
1960 // already. We must use the full URL to find hosted apps, though, and not
1962 const Extension
* extension
=
1963 map
->extensions().GetExtensionOrAppByURL(opener_url
);
1964 if (extension
&& !extensions::BackgroundInfo::AllowJSAccess(extension
))
1965 *no_javascript_access
= true;
1971 #if defined(ENABLE_EXTENSIONS)
1972 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
1977 HostContentSettingsMap
* content_settings
=
1978 ProfileIOData::FromResourceContext(context
)->GetHostContentSettingsMap();
1979 BlockedWindowParams
blocked_params(target_url
,
1986 opener_render_frame_id
);
1988 if (!user_gesture
&&
1989 !base::CommandLine::ForCurrentProcess()->HasSwitch(
1990 switches::kDisablePopupBlocking
)) {
1991 if (content_settings
->GetContentSetting(opener_top_level_frame_url
,
1992 opener_top_level_frame_url
,
1993 CONTENT_SETTINGS_TYPE_POPUPS
,
1995 CONTENT_SETTING_ALLOW
) {
1996 BrowserThread::PostTask(BrowserThread::UI
,
1998 base::Bind(&HandleBlockedPopupOnUIThread
,
2004 #if defined(OS_ANDROID)
2005 if (SingleTabModeTabHelper::IsRegistered(render_process_id
,
2006 opener_render_view_id
)) {
2007 BrowserThread::PostTask(BrowserThread::UI
,
2009 base::Bind(&HandleSingleTabModeBlockOnUIThread
,
2018 void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2019 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
2020 return g_browser_process
->ResourceDispatcherHostCreated();
2023 content::SpeechRecognitionManagerDelegate
*
2024 ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
2025 return new speech::ChromeSpeechRecognitionManagerDelegate();
2028 net::NetLog
* ChromeContentBrowserClient::GetNetLog() {
2029 return g_browser_process
->net_log();
2032 AccessTokenStore
* ChromeContentBrowserClient::CreateAccessTokenStore() {
2033 return new ChromeAccessTokenStore();
2036 bool ChromeContentBrowserClient::IsFastShutdownPossible() {
2040 void ChromeContentBrowserClient::OverrideWebkitPrefs(
2041 RenderViewHost
* rvh
, WebPreferences
* web_prefs
) {
2042 Profile
* profile
= Profile::FromBrowserContext(
2043 rvh
->GetProcess()->GetBrowserContext());
2044 PrefService
* prefs
= profile
->GetPrefs();
2046 // Fill per-script font preferences. These are not registered on Android
2047 // - http://crbug.com/308033.
2048 #if !defined(OS_ANDROID)
2049 FontFamilyCache::FillFontFamilyMap(profile
,
2050 prefs::kWebKitStandardFontFamilyMap
,
2051 &web_prefs
->standard_font_family_map
);
2052 FontFamilyCache::FillFontFamilyMap(profile
,
2053 prefs::kWebKitFixedFontFamilyMap
,
2054 &web_prefs
->fixed_font_family_map
);
2055 FontFamilyCache::FillFontFamilyMap(profile
,
2056 prefs::kWebKitSerifFontFamilyMap
,
2057 &web_prefs
->serif_font_family_map
);
2058 FontFamilyCache::FillFontFamilyMap(profile
,
2059 prefs::kWebKitSansSerifFontFamilyMap
,
2060 &web_prefs
->sans_serif_font_family_map
);
2061 FontFamilyCache::FillFontFamilyMap(profile
,
2062 prefs::kWebKitCursiveFontFamilyMap
,
2063 &web_prefs
->cursive_font_family_map
);
2064 FontFamilyCache::FillFontFamilyMap(profile
,
2065 prefs::kWebKitFantasyFontFamilyMap
,
2066 &web_prefs
->fantasy_font_family_map
);
2067 FontFamilyCache::FillFontFamilyMap(profile
,
2068 prefs::kWebKitPictographFontFamilyMap
,
2069 &web_prefs
->pictograph_font_family_map
);
2072 web_prefs
->default_font_size
=
2073 prefs
->GetInteger(prefs::kWebKitDefaultFontSize
);
2074 web_prefs
->default_fixed_font_size
=
2075 prefs
->GetInteger(prefs::kWebKitDefaultFixedFontSize
);
2076 web_prefs
->minimum_font_size
=
2077 prefs
->GetInteger(prefs::kWebKitMinimumFontSize
);
2078 web_prefs
->minimum_logical_font_size
=
2079 prefs
->GetInteger(prefs::kWebKitMinimumLogicalFontSize
);
2081 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2083 web_prefs
->javascript_can_open_windows_automatically
=
2084 prefs
->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically
);
2085 web_prefs
->dom_paste_enabled
=
2086 prefs
->GetBoolean(prefs::kWebKitDomPasteEnabled
);
2087 web_prefs
->tabs_to_links
= prefs
->GetBoolean(prefs::kWebkitTabsToLinks
);
2089 if (!prefs
->GetBoolean(prefs::kWebKitJavascriptEnabled
))
2090 web_prefs
->javascript_enabled
= false;
2091 if (!prefs
->GetBoolean(prefs::kWebKitWebSecurityEnabled
))
2092 web_prefs
->web_security_enabled
= false;
2093 if (!prefs
->GetBoolean(prefs::kWebKitPluginsEnabled
))
2094 web_prefs
->plugins_enabled
= false;
2095 if (!prefs
->GetBoolean(prefs::kWebKitJavaEnabled
))
2096 web_prefs
->java_enabled
= false;
2097 web_prefs
->loads_images_automatically
=
2098 prefs
->GetBoolean(prefs::kWebKitLoadsImagesAutomatically
);
2100 if (prefs
->GetBoolean(prefs::kDisable3DAPIs
))
2101 web_prefs
->experimental_webgl_enabled
= false;
2103 web_prefs
->allow_displaying_insecure_content
=
2104 prefs
->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent
);
2105 web_prefs
->allow_running_insecure_content
=
2106 prefs
->GetBoolean(prefs::kWebKitAllowRunningInsecureContent
);
2107 #if defined(OS_ANDROID)
2108 web_prefs
->font_scale_factor
=
2109 static_cast<float>(prefs
->GetDouble(prefs::kWebKitFontScaleFactor
));
2110 web_prefs
->device_scale_adjustment
= GetDeviceScaleAdjustment();
2111 web_prefs
->force_enable_zoom
=
2112 prefs
->GetBoolean(prefs::kWebKitForceEnableZoom
);
2115 #if defined(OS_ANDROID)
2116 web_prefs
->password_echo_enabled
=
2117 prefs
->GetBoolean(prefs::kWebKitPasswordEchoEnabled
);
2119 web_prefs
->password_echo_enabled
= browser_defaults::kPasswordEchoEnabled
;
2122 web_prefs
->asynchronous_spell_checking_enabled
= true;
2123 web_prefs
->unified_textchecker_enabled
= true;
2125 web_prefs
->uses_universal_detector
=
2126 prefs
->GetBoolean(prefs::kWebKitUsesUniversalDetector
);
2127 web_prefs
->text_areas_are_resizable
=
2128 prefs
->GetBoolean(prefs::kWebKitTextAreasAreResizable
);
2129 web_prefs
->hyperlink_auditing_enabled
=
2130 prefs
->GetBoolean(prefs::kEnableHyperlinkAuditing
);
2132 #if defined(ENABLE_EXTENSIONS)
2133 std::string image_animation_policy
=
2134 prefs
->GetString(prefs::kAnimationPolicy
);
2135 if (image_animation_policy
== kAnimationPolicyOnce
)
2136 web_prefs
->animation_policy
=
2137 content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE
;
2138 else if (image_animation_policy
== kAnimationPolicyNone
)
2139 web_prefs
->animation_policy
= content::IMAGE_ANIMATION_POLICY_NO_ANIMATION
;
2141 web_prefs
->animation_policy
= content::IMAGE_ANIMATION_POLICY_ALLOWED
;
2144 // Make sure we will set the default_encoding with canonical encoding name.
2145 web_prefs
->default_encoding
=
2146 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
2147 web_prefs
->default_encoding
);
2148 if (web_prefs
->default_encoding
.empty()) {
2149 prefs
->ClearPref(prefs::kDefaultCharset
);
2150 web_prefs
->default_encoding
= prefs
->GetString(prefs::kDefaultCharset
);
2152 DCHECK(!web_prefs
->default_encoding
.empty());
2154 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2155 switches::kEnablePotentiallyAnnoyingSecurityFeatures
)) {
2156 web_prefs
->disable_reading_from_canvas
= true;
2157 web_prefs
->strict_mixed_content_checking
= true;
2158 web_prefs
->strict_powerful_feature_restrictions
= true;
2161 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2162 extra_parts_
[i
]->OverrideWebkitPrefs(rvh
, web_prefs
);
2165 void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2166 BrowserURLHandler
* handler
) {
2167 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2168 extra_parts_
[i
]->BrowserURLHandlerCreated(handler
);
2170 // about: handler. Must come before chrome: handler, since it will
2171 // rewrite about: urls to chrome: URLs and then expect chrome: to
2172 // actually handle them. Also relies on a preliminary fixup phase.
2173 handler
->SetFixupHandler(&FixupBrowserAboutURL
);
2174 handler
->AddHandlerPair(&WillHandleBrowserAboutURL
,
2175 BrowserURLHandler::null_handler());
2177 #if defined(OS_ANDROID)
2178 // Handler to rewrite chrome://newtab on Android.
2179 handler
->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL
,
2180 BrowserURLHandler::null_handler());
2182 // Handler to rewrite chrome://newtab for InstantExtended.
2183 handler
->AddHandlerPair(&search::HandleNewTabURLRewrite
,
2184 &search::HandleNewTabURLReverseRewrite
);
2187 // chrome: & friends.
2188 handler
->AddHandlerPair(&HandleWebUI
, &HandleWebUIReverse
);
2191 void ChromeContentBrowserClient::ClearCache(RenderFrameHost
* rfh
) {
2192 Profile
* profile
= Profile::FromBrowserContext(
2193 rfh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2194 BrowsingDataRemover
* remover
=
2195 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2196 remover
->Remove(BrowsingDataRemover::REMOVE_CACHE
,
2197 BrowsingDataHelper::UNPROTECTED_WEB
);
2198 // BrowsingDataRemover takes care of deleting itself when done.
2201 void ChromeContentBrowserClient::ClearCookies(RenderFrameHost
* rfh
) {
2202 Profile
* profile
= Profile::FromBrowserContext(
2203 rfh
->GetSiteInstance()->GetProcess()->GetBrowserContext());
2204 BrowsingDataRemover
* remover
=
2205 BrowsingDataRemover::CreateForUnboundedRange(profile
);
2206 int remove_mask
= BrowsingDataRemover::REMOVE_SITE_DATA
;
2207 remover
->Remove(remove_mask
, BrowsingDataHelper::UNPROTECTED_WEB
);
2208 // BrowsingDataRemover takes care of deleting itself when done.
2211 base::FilePath
ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
2212 return DownloadPrefs::GetDefaultDownloadDirectory();
2215 std::string
ChromeContentBrowserClient::GetDefaultDownloadName() {
2216 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME
);
2219 void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2220 content::BrowserPpapiHost
* browser_host
) {
2221 #if defined(ENABLE_PLUGINS)
2222 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host
);
2226 content::BrowserPpapiHost
*
2227 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2228 int plugin_process_id
) {
2229 #if !defined(DISABLE_NACL)
2230 content::BrowserChildProcessHostIterator
iter(PROCESS_TYPE_NACL_LOADER
);
2231 while (!iter
.Done()) {
2232 nacl::NaClProcessHost
* host
= static_cast<nacl::NaClProcessHost
*>(
2233 iter
.GetDelegate());
2234 if (host
->process() &&
2235 host
->process()->GetData().id
== plugin_process_id
) {
2236 // Found the plugin.
2237 return host
->browser_ppapi_host();
2245 bool ChromeContentBrowserClient::AllowPepperSocketAPI(
2246 content::BrowserContext
* browser_context
,
2249 const content::SocketPermissionRequest
* params
) {
2250 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2251 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
2252 browser_context
, url
, private_api
, params
, allowed_socket_origins_
);
2258 ui::SelectFilePolicy
* ChromeContentBrowserClient::CreateSelectFilePolicy(
2259 WebContents
* web_contents
) {
2260 return new ChromeSelectFilePolicy(web_contents
);
2263 void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2264 std::vector
<std::string
>* additional_allowed_schemes
) {
2265 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2266 additional_allowed_schemes
);
2267 additional_allowed_schemes
->push_back(content::kChromeDevToolsScheme
);
2268 additional_allowed_schemes
->push_back(content::kChromeUIScheme
);
2269 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
2270 extra_parts_
[i
]->GetAdditionalAllowedSchemesForFileSystem(
2271 additional_allowed_schemes
);
2275 void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
2276 std::vector
<storage::URLRequestAutoMountHandler
>* handlers
) {
2277 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
)
2278 extra_parts_
[i
]->GetURLRequestAutoMountHandlers(handlers
);
2281 void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
2282 content::BrowserContext
* browser_context
,
2283 const base::FilePath
& storage_partition_path
,
2284 ScopedVector
<storage::FileSystemBackend
>* additional_backends
) {
2285 #if defined(OS_CHROMEOS)
2286 storage::ExternalMountPoints
* external_mount_points
=
2287 content::BrowserContext::GetMountPoints(browser_context
);
2288 DCHECK(external_mount_points
);
2289 chromeos::FileSystemBackend
* backend
= new chromeos::FileSystemBackend(
2290 new drive::FileSystemBackendDelegate
,
2291 new chromeos::file_system_provider::BackendDelegate
,
2292 new chromeos::MTPFileSystemBackendDelegate(storage_partition_path
),
2293 external_mount_points
,
2294 storage::ExternalMountPoints::GetSystemInstance());
2295 backend
->AddSystemMountPoints();
2296 DCHECK(backend
->CanHandleType(storage::kFileSystemTypeExternal
));
2297 additional_backends
->push_back(backend
);
2300 for (size_t i
= 0; i
< extra_parts_
.size(); ++i
) {
2301 extra_parts_
[i
]->GetAdditionalFileSystemBackends(
2302 browser_context
, storage_partition_path
, additional_backends
);
2306 #if defined(OS_ANDROID)
2307 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2308 const base::CommandLine
& command_line
,
2309 int child_process_id
,
2310 FileDescriptorInfo
* mappings
,
2311 std::map
<int, base::MemoryMappedFile::Region
>* regions
) {
2312 int fd
= ui::GetMainAndroidPackFd(
2313 &(*regions
)[kAndroidUIResourcesPakDescriptor
]);
2314 mappings
->Share(kAndroidUIResourcesPakDescriptor
, fd
);
2316 fd
= ui::GetCommonResourcesPackFd(
2317 &(*regions
)[kAndroidChrome100PercentPakDescriptor
]);
2318 mappings
->Share(kAndroidChrome100PercentPakDescriptor
, fd
);
2320 fd
= ui::GetLocalePackFd(&(*regions
)[kAndroidLocalePakDescriptor
]);
2321 mappings
->Share(kAndroidLocalePakDescriptor
, fd
);
2323 if (breakpad::IsCrashReporterEnabled()) {
2325 breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile(
2327 if (file
.IsValid()) {
2328 mappings
->Transfer(kAndroidMinidumpDescriptor
,
2329 base::ScopedFD(file
.TakePlatformFile()));
2331 LOG(ERROR
) << "Failed to create file for minidump, crash reporting will "
2332 "be disabled for this process.";
2336 base::FilePath app_data_path
;
2337 PathService::Get(base::DIR_ANDROID_APP_DATA
, &app_data_path
);
2338 DCHECK(!app_data_path
.empty());
2340 #elif defined(OS_POSIX) && !defined(OS_MACOSX)
2341 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2342 const base::CommandLine
& command_line
,
2343 int child_process_id
,
2344 FileDescriptorInfo
* mappings
) {
2345 int crash_signal_fd
= GetCrashSignalFD(command_line
);
2346 if (crash_signal_fd
>= 0) {
2347 mappings
->Share(kCrashDumpSignal
, crash_signal_fd
);
2350 #endif // defined(OS_ANDROID)
2353 const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2354 return chrome::kBrowserResourcesDll
;
2357 base::string16
ChromeContentBrowserClient::GetAppContainerSidForSandboxType(
2358 int sandbox_type
) const {
2361 #if defined(GOOGLE_CHROME_BUILD)
2362 const version_info::Channel channel
= chrome::GetChannel();
2364 // It's possible to have a SxS installation running at the same time as a
2365 // non-SxS so isolate them from each other.
2366 if (channel
== version_info::Channel::CANARY
) {
2368 L
"S-1-15-2-3251537155-1984446955-2931258699-841473695-1938553385-"
2372 L
"S-1-15-2-3251537155-1984446955-2931258699-841473695-1938553385-"
2377 L
"S-1-15-2-3251537155-1984446955-2931258699-841473695-1938553385-"
2381 // TODO(wfh): Add support for more process types here. crbug.com/499523
2382 switch (sandbox_type
) {
2383 case content::SANDBOX_TYPE_RENDERER
:
2384 return sid
+ L
"129201922";
2385 case content::SANDBOX_TYPE_UTILITY
:
2386 return base::string16();
2387 case content::SANDBOX_TYPE_GPU
:
2388 return base::string16();
2389 case content::SANDBOX_TYPE_PPAPI
:
2390 return sid
+ L
"129201925";
2391 #if !defined(DISABLE_NACL)
2392 case PROCESS_TYPE_NACL_LOADER
:
2393 return base::string16();
2394 case PROCESS_TYPE_NACL_BROKER
:
2395 return base::string16();
2399 // Should never reach here.
2401 return base::string16();
2404 void ChromeContentBrowserClient::PreSpawnRenderer(
2405 sandbox::TargetPolicy
* policy
,
2407 // This code is duplicated in nacl_exe_win_64.cc.
2408 // Allow the server side of a pipe restricted to the "chrome.nacl."
2409 // namespace so that it cannot impersonate other system or other chrome
2411 sandbox::ResultCode result
= policy
->AddRule(
2412 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES
,
2413 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY
,
2414 L
"\\\\.\\pipe\\chrome.nacl.*");
2415 if (result
!= sandbox::SBOX_ALL_OK
) {
2420 // Renderers need to send named pipe handles and shared memory
2421 // segment handles to NaCl loader processes.
2422 result
= policy
->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES
,
2423 sandbox::TargetPolicy::HANDLES_DUP_ANY
,
2425 if (result
!= sandbox::SBOX_ALL_OK
) {
2432 void ChromeContentBrowserClient::RegisterFrameMojoShellServices(
2433 content::ServiceRegistry
* registry
,
2434 content::RenderFrameHost
* render_frame_host
) {
2435 #if defined(OS_CHROMEOS)
2436 registry
->AddService(
2437 base::Bind(&chromeos::attestation::PlatformVerificationImpl::Create
,
2438 render_frame_host
));
2442 void ChromeContentBrowserClient::RegisterInProcessMojoApplications(
2443 StaticMojoApplicationMap
* apps
) {
2444 #if !defined(OS_ANDROID) && !defined(OS_IOS)
2445 apps
->insert(std::make_pair(GURL(device::kDevicesMojoAppUrl
),
2446 base::Bind(&device::DevicesAppFactory::CreateApp
,
2447 base::ThreadTaskRunnerHandle::Get())));
2451 void ChromeContentBrowserClient::OpenURL(
2452 content::BrowserContext
* browser_context
,
2453 const content::OpenURLParams
& params
,
2454 const base::Callback
<void(content::WebContents
*)>& callback
) {
2455 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
2457 #if !defined(OS_ANDROID) && !defined(OS_IOS)
2458 NavigateParams
nav_params(Profile::FromBrowserContext(browser_context
),
2461 FillNavigateParamsFromOpenURLParams(&nav_params
, params
);
2462 nav_params
.user_gesture
= params
.user_gesture
;
2464 Navigate(&nav_params
);
2465 callback
.Run(nav_params
.target_contents
);
2466 #elif defined(OS_ANDROID)
2467 service_tab_launcher::ServiceTabLauncher::GetInstance()->LaunchTab(
2468 browser_context
, params
, callback
);
2474 content::PresentationServiceDelegate
*
2475 ChromeContentBrowserClient::GetPresentationServiceDelegate(
2476 content::WebContents
* web_contents
) {
2477 #if defined(ENABLE_MEDIA_ROUTER)
2478 if (switches::MediaRouterEnabled()) {
2479 return media_router::PresentationServiceDelegateImpl::
2480 GetOrCreateForWebContents(web_contents
);
2486 void ChromeContentBrowserClient::RecordURLMetric(const std::string
& metric
,
2488 if (url
.is_valid()) {
2489 rappor::SampleDomainAndRegistryFromGURL(g_browser_process
->rappor_service(),
2494 content::DevToolsManagerDelegate
*
2495 ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
2496 return new ChromeDevToolsManagerDelegate();
2499 content::TracingDelegate
* ChromeContentBrowserClient::GetTracingDelegate() {
2500 #if !defined(OS_ANDROID)
2501 return new ChromeTracingDelegate();
2507 bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2508 content::BrowserContext
* browser_context
,
2510 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2511 return ChromeContentBrowserClientPluginsPart::
2512 IsPluginAllowedToCallRequestOSFileHandle(browser_context
, url
,
2513 allowed_file_handle_origins_
);
2519 bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
2520 content::BrowserContext
* browser_context
,
2522 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2523 return ChromeContentBrowserClientPluginsPart::
2524 IsPluginAllowedToUseDevChannelAPIs(browser_context
, url
,
2525 allowed_dev_channel_origins_
);
2531 void ChromeContentBrowserClient::OverridePageVisibilityState(
2532 RenderFrameHost
* render_frame_host
,
2533 blink::WebPageVisibilityState
* visibility_state
) {
2534 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
2536 WebContents
* web_contents
=
2537 WebContents::FromRenderFrameHost(render_frame_host
);
2538 DCHECK(web_contents
);
2541 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
2542 prerender::PrerenderManager
* prerender_manager
=
2543 prerender::PrerenderManagerFactory::GetForProfile(profile
);
2544 if (prerender_manager
&&
2545 prerender_manager
->IsWebContentsPrerendering(web_contents
, nullptr)) {
2546 *visibility_state
= blink::WebPageVisibilityStatePrerender
;
2550 #if defined(ENABLE_WEBRTC)
2551 void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
2552 base::CommandLine
* to_command_line
,
2553 const base::CommandLine
& from_command_line
,
2554 version_info::Channel channel
) {
2555 #if defined(OS_ANDROID)
2556 const version_info::Channel kMaxDisableEncryptionChannel
=
2557 version_info::Channel::BETA
;
2559 const version_info::Channel kMaxDisableEncryptionChannel
=
2560 version_info::Channel::DEV
;
2562 if (channel
<= kMaxDisableEncryptionChannel
) {
2563 static const char* const kWebRtcDevSwitchNames
[] = {
2564 switches::kDisableWebRtcEncryption
,
2566 to_command_line
->CopySwitchesFrom(from_command_line
,
2567 kWebRtcDevSwitchNames
,
2568 arraysize(kWebRtcDevSwitchNames
));
2571 #endif // defined(ENABLE_WEBRTC)
2573 } // namespace chrome