Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / chrome_content_browser_client.cc
blobb038682ea64612c240f80cdc62f03df4d850737c
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"
7 #include <set>
8 #include <utility>
9 #include <vector>
11 #include "base/bind.h"
12 #include "base/command_line.h"
13 #include "base/files/scoped_file.h"
14 #include "base/i18n/icu_util.h"
15 #include "base/lazy_instance.h"
16 #include "base/path_service.h"
17 #include "base/prefs/pref_service.h"
18 #include "base/prefs/scoped_user_pref_update.h"
19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/utf_string_conversions.h"
21 #include "base/threading/sequenced_worker_pool.h"
22 #include "chrome/browser/browser_about_handler.h"
23 #include "chrome/browser/browser_process.h"
24 #include "chrome/browser/browser_shutdown.h"
25 #include "chrome/browser/browsing_data/browsing_data_helper.h"
26 #include "chrome/browser/browsing_data/browsing_data_remover.h"
27 #include "chrome/browser/character_encoding.h"
28 #include "chrome/browser/chrome_content_browser_client_parts.h"
29 #include "chrome/browser/chrome_net_benchmarking_message_filter.h"
30 #include "chrome/browser/chrome_quota_permission_context.h"
31 #include "chrome/browser/content_settings/cookie_settings.h"
32 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
33 #include "chrome/browser/defaults.h"
34 #include "chrome/browser/download/download_prefs.h"
35 #include "chrome/browser/font_family_cache.h"
36 #include "chrome/browser/geolocation/chrome_access_token_store.h"
37 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
38 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
39 #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
40 #include "chrome/browser/net/chrome_net_log.h"
41 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
42 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h"
43 #include "chrome/browser/notifications/platform_notification_service_impl.h"
44 #include "chrome/browser/platform_util.h"
45 #include "chrome/browser/prerender/prerender_final_status.h"
46 #include "chrome/browser/prerender/prerender_manager.h"
47 #include "chrome/browser/prerender/prerender_manager_factory.h"
48 #include "chrome/browser/prerender/prerender_message_filter.h"
49 #include "chrome/browser/printing/printing_message_filter.h"
50 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
51 #include "chrome/browser/profiles/profile.h"
52 #include "chrome/browser/profiles/profile_io_data.h"
53 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
54 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
55 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
56 #include "chrome/browser/search/instant_service.h"
57 #include "chrome/browser/search/instant_service_factory.h"
58 #include "chrome/browser/search/search.h"
59 #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
60 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
61 #include "chrome/browser/speech/tts_controller.h"
62 #include "chrome/browser/speech/tts_message_filter.h"
63 #include "chrome/browser/ssl/ssl_add_certificate.h"
64 #include "chrome/browser/ssl/ssl_blocking_page.h"
65 #include "chrome/browser/ssl/ssl_client_certificate_selector.h"
66 #include "chrome/browser/ssl/ssl_error_handler.h"
67 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
68 #include "chrome/browser/tab_contents/tab_util.h"
69 #include "chrome/browser/tracing/chrome_tracing_delegate.h"
70 #include "chrome/browser/ui/blocked_content/blocked_window_params.h"
71 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
72 #include "chrome/browser/ui/chrome_select_file_policy.h"
73 #include "chrome/browser/ui/sync/sync_promo_ui.h"
74 #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
75 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
76 #include "chrome/common/chrome_constants.h"
77 #include "chrome/common/chrome_paths.h"
78 #include "chrome/common/chrome_switches.h"
79 #include "chrome/common/env_vars.h"
80 #include "chrome/common/logging_chrome.h"
81 #include "chrome/common/pepper_permission_util.h"
82 #include "chrome/common/pref_names.h"
83 #include "chrome/common/render_messages.h"
84 #include "chrome/common/url_constants.h"
85 #include "chrome/grit/generated_resources.h"
86 #include "chrome/installer/util/google_update_settings.h"
87 #include "chromeos/chromeos_constants.h"
88 #include "components/cdm/browser/cdm_message_filter_android.h"
89 #include "components/cloud_devices/common/cloud_devices_switches.h"
90 #include "components/content_settings/core/browser/content_settings_utils.h"
91 #include "components/content_settings/core/browser/host_content_settings_map.h"
92 #include "components/content_settings/core/common/content_settings.h"
93 #include "components/data_reduction_proxy/content/browser/data_reduction_proxy_message_filter.h"
94 #include "components/dom_distiller/core/url_constants.h"
95 #include "components/google/core/browser/google_util.h"
96 #include "components/metrics/client_info.h"
97 #include "components/pref_registry/pref_registry_syncable.h"
98 #include "components/rappor/rappor_utils.h"
99 #include "components/signin/core/common/profile_management_switches.h"
100 #include "components/translate/core/common/translate_switches.h"
101 #include "components/url_fixer/url_fixer.h"
102 #include "content/public/browser/browser_child_process_host.h"
103 #include "content/public/browser/browser_main_parts.h"
104 #include "content/public/browser/browser_ppapi_host.h"
105 #include "content/public/browser/browser_thread.h"
106 #include "content/public/browser/browser_url_handler.h"
107 #include "content/public/browser/child_process_data.h"
108 #include "content/public/browser/child_process_security_policy.h"
109 #include "content/public/browser/client_certificate_delegate.h"
110 #include "content/public/browser/render_frame_host.h"
111 #include "content/public/browser/render_process_host.h"
112 #include "content/public/browser/render_view_host.h"
113 #include "content/public/browser/resource_context.h"
114 #include "content/public/browser/site_instance.h"
115 #include "content/public/browser/web_contents.h"
116 #include "content/public/common/child_process_host.h"
117 #include "content/public/common/content_descriptors.h"
118 #include "content/public/common/url_utils.h"
119 #include "content/public/common/web_preferences.h"
120 #include "gin/public/isolate_holder.h"
121 #include "net/base/mime_util.h"
122 #include "net/cookies/canonical_cookie.h"
123 #include "net/cookies/cookie_options.h"
124 #include "net/ssl/ssl_cert_request_info.h"
125 #include "ppapi/host/ppapi_host.h"
126 #include "storage/browser/fileapi/external_mount_points.h"
127 #include "ui/base/l10n/l10n_util.h"
128 #include "ui/base/resource/resource_bundle.h"
129 #include "ui/resources/grit/ui_resources.h"
131 #if defined(OS_WIN)
132 #include "base/win/windows_version.h"
133 #include "chrome/browser/chrome_browser_main_win.h"
134 #include "sandbox/win/src/sandbox_policy.h"
135 #elif defined(OS_MACOSX)
136 #include "chrome/browser/chrome_browser_main_mac.h"
137 #include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
138 #elif defined(OS_CHROMEOS)
139 #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
140 #include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h"
141 #include "chrome/browser/chromeos/file_manager/app_id.h"
142 #include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
143 #include "chrome/browser/chromeos/fileapi/file_system_backend.h"
144 #include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
145 #include "chrome/browser/chromeos/login/startup_utils.h"
146 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
147 #include "chrome/browser/chromeos/system/input_device_settings.h"
148 #include "chromeos/chromeos_switches.h"
149 #include "components/user_manager/user_manager.h"
150 #elif defined(OS_LINUX)
151 #include "chrome/browser/chrome_browser_main_linux.h"
152 #elif defined(OS_ANDROID)
153 #include "chrome/browser/android/new_tab_page_url_handler.h"
154 #include "chrome/browser/android/service_tab_launcher.h"
155 #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
156 #include "chrome/browser/chrome_browser_main_android.h"
157 #include "chrome/common/descriptors_android.h"
158 #include "components/crash/browser/crash_dump_manager_android.h"
159 #elif defined(OS_POSIX)
160 #include "chrome/browser/chrome_browser_main_posix.h"
161 #endif
163 #if defined(OS_POSIX) && !defined(OS_MACOSX)
164 #include "base/debug/leak_annotations.h"
165 #include "components/crash/app/breakpad_linux.h"
166 #include "components/crash/browser/crash_handler_host_linux.h"
167 #endif
169 #if defined(OS_ANDROID)
170 #include "ui/base/ui_base_paths.h"
171 #include "ui/gfx/android/device_display_info.h"
172 #endif
174 #if defined(OS_ANDROID)
175 #include "chrome/browser/android/dev_tools_manager_delegate_android.h"
176 #else
177 #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
178 #endif
180 #if defined(TOOLKIT_VIEWS)
181 #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
182 #endif
184 #if defined(USE_ASH)
185 #include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
186 #endif
188 #if defined(USE_AURA)
189 #include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
190 #endif
192 #if defined(USE_X11)
193 #include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
194 #endif
196 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
197 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
198 #endif
200 #if !defined(DISABLE_NACL)
201 #include "components/nacl/browser/nacl_browser.h"
202 #include "components/nacl/browser/nacl_host_message_filter.h"
203 #include "components/nacl/browser/nacl_process_host.h"
204 #include "components/nacl/common/nacl_process_type.h"
205 #include "components/nacl/common/nacl_switches.h"
206 #endif
208 #if defined(ENABLE_EXTENSIONS)
209 #include "chrome/browser/accessibility/animation_policy_prefs.h"
210 #include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
211 #include "chrome/browser/extensions/extension_util.h"
212 #include "chrome/browser/media/cast_transport_host_filter.h"
213 #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
214 #include "extensions/browser/extension_registry.h"
215 #include "extensions/browser/guest_view/guest_view_base.h"
216 #include "extensions/browser/guest_view/guest_view_manager.h"
217 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
218 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
219 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
220 #include "extensions/common/constants.h"
221 #include "extensions/common/extension.h"
222 #include "extensions/common/extension_set.h"
223 #include "extensions/common/manifest_handlers/background_info.h"
224 #include "extensions/common/manifest_handlers/shared_module_info.h"
225 #include "extensions/common/permissions/permissions_data.h"
226 #include "extensions/common/permissions/socket_permission.h"
227 #include "extensions/common/switches.h"
228 #endif
230 #if defined(ENABLE_PLUGINS)
231 #include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
232 #endif
234 #if defined(ENABLE_SPELLCHECK)
235 #include "chrome/browser/spellchecker/spellcheck_message_filter.h"
236 #endif
238 #if defined(ENABLE_WEBRTC)
239 #include "chrome/browser/media/webrtc_logging_handler_host.h"
240 #endif
242 using base::FileDescriptor;
243 using blink::WebWindowFeatures;
244 using content::AccessTokenStore;
245 using content::BrowserThread;
246 using content::BrowserURLHandler;
247 using content::ChildProcessSecurityPolicy;
248 using content::QuotaPermissionContext;
249 using content::RenderFrameHost;
250 using content::RenderViewHost;
251 using content::ResourceType;
252 using content::SiteInstance;
253 using content::WebContents;
254 using content::WebPreferences;
255 using message_center::NotifierId;
257 #if defined(OS_POSIX)
258 using content::FileDescriptorInfo;
259 #endif
261 #if defined(ENABLE_EXTENSIONS)
262 using extensions::APIPermission;
263 using extensions::ChromeContentBrowserClientExtensionsPart;
264 using extensions::Extension;
265 using extensions::InfoMap;
266 using extensions::Manifest;
267 #endif
269 #if defined(ENABLE_PLUGINS)
270 using plugins::ChromeContentBrowserClientPluginsPart;
271 #endif
273 namespace {
275 // Cached version of the locale so we can return the locale on the I/O
276 // thread.
277 base::LazyInstance<std::string> g_io_thread_application_locale;
279 #if defined(ENABLE_PLUGINS)
280 // TODO(teravest): Add renderer-side API-specific checking for these APIs so
281 // that blanket permission isn't granted to all dev channel APIs for these.
282 // http://crbug.com/386743
283 const char* const kPredefinedAllowedDevChannelOrigins[] = {
284 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/383937
285 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/383937
288 const char* const kPredefinedAllowedFileHandleOrigins[] = {
289 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
290 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
293 const char* const kPredefinedAllowedSocketOrigins[] = {
294 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
295 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
296 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
297 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
298 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
299 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
300 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
301 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
302 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
303 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
304 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
305 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
306 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
307 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
308 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
309 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
310 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
311 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
312 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
313 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
315 #endif
317 // Returns a copy of the given url with its host set to given host and path set
318 // to given path. Other parts of the url will be the same.
319 GURL ReplaceURLHostAndPath(const GURL& url,
320 const std::string& host,
321 const std::string& path) {
322 url::Replacements<char> replacements;
323 replacements.SetHost(host.c_str(), url::Component(0, host.length()));
324 replacements.SetPath(path.c_str(), url::Component(0, path.length()));
325 return url.ReplaceComponents(replacements);
328 // Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
329 GURL AddUberHost(const GURL& url) {
330 const std::string uber_host = chrome::kChromeUIUberHost;
331 const std::string new_path = url.host() + url.path();
333 return ReplaceURLHostAndPath(url, uber_host, new_path);
336 // If url->host() is "chrome" and url->path() has characters other than the
337 // first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
338 // returns true. Otherwise returns false.
339 bool RemoveUberHost(GURL* url) {
340 if (url->host() != chrome::kChromeUIUberHost)
341 return false;
343 if (url->path().empty() || url->path() == "/")
344 return false;
346 const std::string old_path = url->path();
348 const std::string::size_type separator = old_path.find('/', 1);
349 std::string new_host;
350 std::string new_path;
351 if (separator == std::string::npos) {
352 new_host = old_path.substr(1);
353 } else {
354 new_host = old_path.substr(1, separator - 1);
355 new_path = old_path.substr(separator);
358 // Do not allow URLs with paths empty before the first slash since we can't
359 // have an empty host. (e.g "foo://chrome//")
360 if (new_host.empty())
361 return false;
363 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
365 DCHECK(url->is_valid());
367 return true;
370 // Handles rewriting Web UI URLs.
371 bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
372 // Do not handle special URLs such as "about:foo"
373 if (!url->host().empty()) {
374 const GURL chrome_url = AddUberHost(*url);
376 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
377 // be called.
378 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
379 browser_context, chrome_url))
380 return true;
383 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
384 browser_context, *url))
385 return false;
387 #if defined(OS_CHROMEOS)
388 // Special case : in ChromeOS in Guest mode bookmarks and history are
389 // disabled for security reasons. New tab page explains the reasons, so
390 // we redirect user to new tab page.
391 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
392 if (url->SchemeIs(content::kChromeUIScheme) &&
393 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
394 url->DomainIs(chrome::kChromeUIHistoryHost))) {
395 // Rewrite with new tab URL
396 *url = GURL(chrome::kChromeUINewTabURL);
399 #endif
401 return true;
404 // Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
405 // "chrome://foo/".
406 bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
407 if (!url->is_valid() || !url->SchemeIs(content::kChromeUIScheme))
408 return false;
410 return RemoveUberHost(url);
413 bool CertMatchesFilter(const net::X509Certificate& cert,
414 const base::DictionaryValue& filter) {
415 // TODO(markusheintz): This is the minimal required filter implementation.
416 // Implement a better matcher.
418 // An empty filter matches any client certificate since no requirements are
419 // specified at all.
420 if (filter.empty())
421 return true;
423 std::string common_name;
424 if (filter.GetString("ISSUER.CN", &common_name) &&
425 (cert.issuer().common_name == common_name)) {
426 return true;
428 return false;
431 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
432 breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
433 const std::string& process_type) {
434 base::FilePath dumps_path;
435 PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
437 ANNOTATE_SCOPED_MEMORY_LEAK;
438 bool upload = (getenv(env_vars::kHeadless) == NULL);
439 breakpad::CrashHandlerHostLinux* crash_handler =
440 new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload);
441 crash_handler->StartUploaderThread();
442 return crash_handler;
446 int GetCrashSignalFD(const base::CommandLine& command_line) {
447 // Extensions have the same process type as renderers.
448 if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) {
449 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
450 if (!crash_handler)
451 crash_handler = CreateCrashHandlerHost("extension");
452 return crash_handler->GetDeathSignalSocket();
455 std::string process_type =
456 command_line.GetSwitchValueASCII(switches::kProcessType);
458 if (process_type == switches::kRendererProcess) {
459 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
460 if (!crash_handler)
461 crash_handler = CreateCrashHandlerHost(process_type);
462 return crash_handler->GetDeathSignalSocket();
465 if (process_type == switches::kPluginProcess) {
466 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
467 if (!crash_handler)
468 crash_handler = CreateCrashHandlerHost(process_type);
469 return crash_handler->GetDeathSignalSocket();
472 if (process_type == switches::kPpapiPluginProcess) {
473 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
474 if (!crash_handler)
475 crash_handler = CreateCrashHandlerHost(process_type);
476 return crash_handler->GetDeathSignalSocket();
479 if (process_type == switches::kGpuProcess) {
480 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
481 if (!crash_handler)
482 crash_handler = CreateCrashHandlerHost(process_type);
483 return crash_handler->GetDeathSignalSocket();
486 return -1;
488 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
490 void SetApplicationLocaleOnIOThread(const std::string& locale) {
491 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
492 g_io_thread_application_locale.Get() = locale;
495 void HandleBlockedPopupOnUIThread(const BlockedWindowParams& params) {
496 // TODO(jochen): This code path should use RenderFrameHosts. See
497 // http://crbug.com/431769 for details.
498 RenderViewHost* render_view_host =
499 RenderViewHost::FromID(params.render_process_id(), params.opener_id());
500 if (!render_view_host)
501 return;
502 WebContents* tab = WebContents::FromRenderViewHost(render_view_host);
503 // The tab might already have navigated away.
504 if (!tab || tab->GetRenderViewHost() != render_view_host)
505 return;
507 prerender::PrerenderContents* prerender_contents =
508 prerender::PrerenderContents::FromWebContents(tab);
509 if (prerender_contents) {
510 prerender_contents->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW);
511 return;
514 PopupBlockerTabHelper* popup_helper =
515 PopupBlockerTabHelper::FromWebContents(tab);
516 if (!popup_helper)
517 return;
518 popup_helper->AddBlockedPopup(params);
521 #if defined(OS_ANDROID)
523 void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams& params) {
524 WebContents* web_contents =
525 tab_util::GetWebContentsByID(params.render_process_id(),
526 params.opener_id());
527 if (!web_contents)
528 return;
530 SingleTabModeTabHelper::FromWebContents(web_contents)->HandleOpenUrl(params);
533 float GetDeviceScaleAdjustment() {
534 static const float kMinFSM = 1.05f;
535 static const int kWidthForMinFSM = 320;
536 static const float kMaxFSM = 1.3f;
537 static const int kWidthForMaxFSM = 800;
539 gfx::DeviceDisplayInfo info;
540 int minWidth = info.GetSmallestDIPWidth();
542 if (minWidth <= kWidthForMinFSM)
543 return kMinFSM;
544 if (minWidth >= kWidthForMaxFSM)
545 return kMaxFSM;
547 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
548 float ratio = static_cast<float>(minWidth - kWidthForMinFSM) /
549 (kWidthForMaxFSM - kWidthForMinFSM);
550 return ratio * (kMaxFSM - kMinFSM) + kMinFSM;
553 #endif // defined(OS_ANDROID)
555 #if defined(ENABLE_EXTENSIONS)
556 // By default, JavaScript and images are enabled in guest content.
557 void GetGuestViewDefaultContentSettingRules(
558 bool incognito,
559 RendererContentSettingRules* rules) {
560 rules->image_rules.push_back(
561 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
562 ContentSettingsPattern::Wildcard(),
563 CONTENT_SETTING_ALLOW,
564 std::string(),
565 incognito));
567 rules->script_rules.push_back(
568 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
569 ContentSettingsPattern::Wildcard(),
570 CONTENT_SETTING_ALLOW,
571 std::string(),
572 incognito));
574 #endif // defined(ENALBE_EXTENSIONS)
576 } // namespace
578 namespace chrome {
580 ChromeContentBrowserClient::ChromeContentBrowserClient()
582 #if defined(OS_POSIX) && !defined(OS_MACOSX)
583 v8_natives_fd_(-1),
584 v8_snapshot_fd_(-1),
585 #endif // OS_POSIX && !OS_MACOSX
586 weak_factory_(this) {
587 #if defined(ENABLE_PLUGINS)
588 for (size_t i = 0; i < arraysize(kPredefinedAllowedDevChannelOrigins); ++i)
589 allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]);
590 for (size_t i = 0; i < arraysize(kPredefinedAllowedFileHandleOrigins); ++i)
591 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]);
592 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
593 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
595 extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart);
596 #endif
598 #if !defined(OS_ANDROID)
599 TtsExtensionEngine* tts_extension_engine = TtsExtensionEngine::GetInstance();
600 TtsController::GetInstance()->SetTtsEngineDelegate(tts_extension_engine);
601 #endif
603 #if defined(ENABLE_EXTENSIONS)
604 extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart);
605 #endif
608 ChromeContentBrowserClient::~ChromeContentBrowserClient() {
609 for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i)
610 delete extra_parts_[i];
611 extra_parts_.clear();
614 // static
615 void ChromeContentBrowserClient::RegisterProfilePrefs(
616 user_prefs::PrefRegistrySyncable* registry) {
617 registry->RegisterBooleanPref(
618 prefs::kDisable3DAPIs,
619 false,
620 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
621 registry->RegisterBooleanPref(
622 prefs::kEnableHyperlinkAuditing,
623 true,
624 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
625 registry->RegisterListPref(
626 prefs::kEnableDeprecatedWebPlatformFeatures,
627 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
630 // static
631 void ChromeContentBrowserClient::SetApplicationLocale(
632 const std::string& locale) {
633 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
635 // This object is guaranteed to outlive all threads so we don't have to
636 // worry about the lack of refcounting and can just post as Unretained.
638 // The common case is that this function is called early in Chrome startup
639 // before any threads are created (it will also be called later if the user
640 // changes the pref). In this case, there will be no threads created and
641 // posting will fail. When there are no threads, we can just set the string
642 // without worrying about threadsafety.
643 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
644 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
645 g_io_thread_application_locale.Get() = locale;
649 content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
650 const content::MainFunctionParams& parameters) {
651 ChromeBrowserMainParts* main_parts;
652 // Construct the Main browser parts based on the OS type.
653 #if defined(OS_WIN)
654 main_parts = new ChromeBrowserMainPartsWin(parameters);
655 #elif defined(OS_MACOSX)
656 main_parts = new ChromeBrowserMainPartsMac(parameters);
657 #elif defined(OS_CHROMEOS)
658 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
659 #elif defined(OS_LINUX)
660 main_parts = new ChromeBrowserMainPartsLinux(parameters);
661 #elif defined(OS_ANDROID)
662 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
663 #elif defined(OS_POSIX)
664 main_parts = new ChromeBrowserMainPartsPosix(parameters);
665 #else
666 NOTREACHED();
667 main_parts = new ChromeBrowserMainParts(parameters);
668 #endif
670 chrome::AddProfilesExtraParts(main_parts);
672 // Construct additional browser parts. Stages are called in the order in
673 // which they are added.
674 #if defined(TOOLKIT_VIEWS)
675 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
676 #endif
678 // TODO(oshima): Athena on chrome currently requires USE_ASH to build.
679 // We should reduce the dependency as much as possible.
680 #if defined(USE_ASH)
681 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
682 #endif
684 #if defined(USE_AURA)
685 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
686 #endif
688 #if defined(USE_X11)
689 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
690 #endif
692 chrome::AddMetricsExtraParts(main_parts);
694 return main_parts;
697 std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
698 content::BrowserContext* browser_context,
699 const GURL& site) {
700 std::string partition_id;
702 // The partition ID for webview guest processes is the string value of its
703 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
704 if (site.SchemeIs(content::kGuestScheme)) {
705 partition_id = site.spec();
706 } else if (!switches::IsEnableWebviewBasedSignin() &&
707 site.GetOrigin().spec() == kChromeUIChromeSigninURL) {
708 // The non-webview Chrome signin page has an embedded iframe of extension
709 // and web content, thus it must be isolated from other webUI pages.
710 partition_id = site.GetOrigin().spec();
713 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
714 return partition_id;
717 bool ChromeContentBrowserClient::IsValidStoragePartitionId(
718 content::BrowserContext* browser_context,
719 const std::string& partition_id) {
720 // The default ID is empty and is always valid.
721 if (partition_id.empty())
722 return true;
724 return GURL(partition_id).is_valid();
727 void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
728 content::BrowserContext* browser_context,
729 const GURL& site,
730 bool can_be_default,
731 std::string* partition_domain,
732 std::string* partition_name,
733 bool* in_memory) {
734 // Default to the browser-wide storage partition and override based on |site|
735 // below.
736 partition_domain->clear();
737 partition_name->clear();
738 *in_memory = false;
740 bool success = false;
741 #if defined(ENABLE_EXTENSIONS)
742 success = extensions::WebViewGuest::GetGuestPartitionConfigForSite(
743 site, partition_domain, partition_name, in_memory);
745 if (!success && site.SchemeIs(extensions::kExtensionScheme)) {
746 // If |can_be_default| is false, the caller is stating that the |site|
747 // should be parsed as if it had isolated storage. In particular it is
748 // important to NOT check ExtensionService for the is_storage_isolated()
749 // attribute because this code path is run during Extension uninstall
750 // to do cleanup after the Extension has already been unloaded from the
751 // ExtensionService.
752 bool is_isolated = !can_be_default;
753 if (can_be_default) {
754 if (extensions::util::SiteHasIsolatedStorage(site, browser_context))
755 is_isolated = true;
758 if (is_isolated) {
759 CHECK(site.has_host());
760 // For extensions with isolated storage, the the host of the |site| is
761 // the |partition_domain|. The |in_memory| and |partition_name| are only
762 // used in guest schemes so they are cleared here.
763 *partition_domain = site.host();
764 *in_memory = false;
765 partition_name->clear();
767 success = true;
769 #endif
771 if (!success && (!switches::IsEnableWebviewBasedSignin() &&
772 site.GetOrigin().spec() == kChromeUIChromeSigninURL)) {
773 // The non-webview Chrome signin page has an embedded iframe of extension
774 // and web content, thus it must be isolated from other webUI pages.
775 *partition_domain = chrome::kChromeUIChromeSigninHost;
778 // Assert that if |can_be_default| is false, the code above must have found a
779 // non-default partition. If this fails, the caller has a serious logic
780 // error about which StoragePartition they expect to be in and it is not
781 // safe to continue.
782 CHECK(can_be_default || !partition_domain->empty());
785 content::WebContentsViewDelegate*
786 ChromeContentBrowserClient::GetWebContentsViewDelegate(
787 content::WebContents* web_contents) {
788 return chrome::CreateWebContentsViewDelegate(web_contents);
791 void ChromeContentBrowserClient::RenderProcessWillLaunch(
792 content::RenderProcessHost* host) {
793 int id = host->GetID();
794 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
795 net::URLRequestContextGetter* context =
796 profile->GetRequestContextForRenderProcess(id);
798 host->AddFilter(new ChromeRenderMessageFilter(id, profile));
799 #if defined(ENABLE_EXTENSIONS)
800 host->AddFilter(new cast::CastTransportHostFilter);
801 #endif
802 #if defined(ENABLE_PRINTING)
803 host->AddFilter(new printing::PrintingMessageFilter(id, profile));
804 #endif
805 host->AddFilter(new SearchProviderInstallStateMessageFilter(id, profile));
806 #if defined(ENABLE_SPELLCHECK)
807 host->AddFilter(new SpellCheckMessageFilter(id));
808 #endif
809 #if defined(OS_MACOSX)
810 host->AddFilter(new SpellCheckMessageFilterMac(id));
811 #endif
812 host->AddFilter(new ChromeNetBenchmarkingMessageFilter(profile, context));
813 host->AddFilter(new prerender::PrerenderMessageFilter(id, profile));
814 host->AddFilter(new TtsMessageFilter(id, host->GetBrowserContext()));
815 #if defined(ENABLE_WEBRTC)
816 WebRtcLoggingHandlerHost* webrtc_logging_handler_host =
817 new WebRtcLoggingHandlerHost(profile);
818 host->SetWebRtcLogMessageCallback(base::Bind(
819 &WebRtcLoggingHandlerHost::LogMessage, webrtc_logging_handler_host));
820 host->AddFilter(webrtc_logging_handler_host);
821 host->SetUserData(host, new base::UserDataAdapter<WebRtcLoggingHandlerHost>(
822 webrtc_logging_handler_host));
823 #endif
824 #if !defined(DISABLE_NACL)
825 host->AddFilter(new nacl::NaClHostMessageFilter(
826 id, profile->IsOffTheRecord(),
827 profile->GetPath(),
828 context));
829 #endif
830 #if defined(OS_ANDROID)
831 host->AddFilter(new cdm::CdmMessageFilterAndroid());
832 #endif
833 DataReductionProxyChromeSettings* data_reduction_proxy_settings =
834 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(profile);
835 host->AddFilter(new data_reduction_proxy::DataReductionProxyMessageFilter(
836 data_reduction_proxy_settings));
838 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
839 profile->IsOffTheRecord()));
841 for (size_t i = 0; i < extra_parts_.size(); ++i)
842 extra_parts_[i]->RenderProcessWillLaunch(host);
844 RendererContentSettingRules rules;
845 if (host->IsIsolatedGuest()) {
846 #if defined(ENABLE_EXTENSIONS)
847 GetGuestViewDefaultContentSettingRules(profile->IsOffTheRecord(), &rules);
848 #else
849 NOTREACHED();
850 #endif
851 } else {
852 GetRendererContentSettingRules(
853 profile->GetHostContentSettingsMap(), &rules);
855 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
858 GURL ChromeContentBrowserClient::GetEffectiveURL(
859 content::BrowserContext* browser_context, const GURL& url) {
860 Profile* profile = Profile::FromBrowserContext(browser_context);
861 if (!profile)
862 return url;
864 // If the input |url| should be assigned to the Instant renderer, make its
865 // effective URL distinct from other URLs on the search provider's domain.
866 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
867 return chrome::GetEffectiveURLForInstant(url, profile);
869 #if defined(ENABLE_EXTENSIONS)
870 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(
871 profile, url);
872 #else
873 return url;
874 #endif
877 bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
878 content::BrowserContext* browser_context, const GURL& effective_url) {
879 // Non-extension, non-Instant URLs should generally use
880 // process-per-site-instance. Because we expect to use the effective URL,
881 // URLs for hosted apps (apart from bookmark apps) should have an extension
882 // scheme by now.
884 Profile* profile = Profile::FromBrowserContext(browser_context);
885 if (!profile)
886 return false;
888 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
889 return true;
891 #if defined(ENABLE_EXTENSIONS)
892 return ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
893 profile, effective_url);
894 #else
895 return false;
896 #endif
899 // These are treated as WebUI schemes but do not get WebUI bindings. Also,
900 // view-source is allowed for these schemes.
901 void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
902 std::vector<std::string>* additional_schemes) {
903 additional_schemes->push_back(chrome::kChromeSearchScheme);
904 additional_schemes->push_back(dom_distiller::kDomDistillerScheme);
907 void ChromeContentBrowserClient::GetAdditionalWebUIHostsToIgnoreParititionCheck(
908 std::vector<std::string>* hosts) {
909 hosts->push_back(chrome::kChromeUIExtensionIconHost);
910 hosts->push_back(chrome::kChromeUIFaviconHost);
911 hosts->push_back(chrome::kChromeUIThemeHost);
912 hosts->push_back(chrome::kChromeUIThumbnailHost);
913 hosts->push_back(chrome::kChromeUIThumbnailHost2);
914 hosts->push_back(chrome::kChromeUIThumbnailListHost);
917 net::URLRequestContextGetter*
918 ChromeContentBrowserClient::CreateRequestContext(
919 content::BrowserContext* browser_context,
920 content::ProtocolHandlerMap* protocol_handlers,
921 content::URLRequestInterceptorScopedVector request_interceptors) {
922 Profile* profile = Profile::FromBrowserContext(browser_context);
923 return profile->CreateRequestContext(protocol_handlers,
924 request_interceptors.Pass());
927 net::URLRequestContextGetter*
928 ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
929 content::BrowserContext* browser_context,
930 const base::FilePath& partition_path,
931 bool in_memory,
932 content::ProtocolHandlerMap* protocol_handlers,
933 content::URLRequestInterceptorScopedVector request_interceptors) {
934 Profile* profile = Profile::FromBrowserContext(browser_context);
935 return profile->CreateRequestContextForStoragePartition(
936 partition_path,
937 in_memory,
938 protocol_handlers,
939 request_interceptors.Pass());
942 bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
943 return ProfileIOData::IsHandledURL(url);
946 bool ChromeContentBrowserClient::CanCommitURL(
947 content::RenderProcessHost* process_host,
948 const GURL& url) {
949 #if defined(ENABLE_EXTENSIONS)
950 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(
951 process_host, url);
952 #else
953 return true;
954 #endif
957 bool ChromeContentBrowserClient::ShouldAllowOpenURL(
958 content::SiteInstance* site_instance, const GURL& url) {
959 GURL from_url = site_instance->GetSiteURL();
961 #if defined(ENABLE_EXTENSIONS)
962 bool result;
963 if (ChromeContentBrowserClientExtensionsPart::ShouldAllowOpenURL(
964 site_instance, from_url, url, &result))
965 return result;
966 #endif
968 // Do not allow chrome://chrome-signin navigate to other chrome:// URLs, since
969 // the signin page may host untrusted web content.
970 if (from_url.GetOrigin().spec() == chrome::kChromeUIChromeSigninURL &&
971 url.SchemeIs(content::kChromeUIScheme) &&
972 url.host() != chrome::kChromeUIChromeSigninHost) {
973 VLOG(1) << "Blocked navigation to " << url.spec() << " from "
974 << chrome::kChromeUIChromeSigninURL;
975 return false;
978 return true;
981 bool ChromeContentBrowserClient::IsSuitableHost(
982 content::RenderProcessHost* process_host,
983 const GURL& site_url) {
984 Profile* profile =
985 Profile::FromBrowserContext(process_host->GetBrowserContext());
986 // This may be NULL during tests. In that case, just assume any site can
987 // share any host.
988 if (!profile)
989 return true;
991 // Instant URLs should only be in the instant process and instant process
992 // should only have Instant URLs.
993 InstantService* instant_service =
994 InstantServiceFactory::GetForProfile(profile);
995 if (instant_service) {
996 bool is_instant_process = instant_service->IsInstantProcess(
997 process_host->GetID());
998 bool should_be_in_instant_process =
999 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
1000 if (is_instant_process || should_be_in_instant_process)
1001 return is_instant_process && should_be_in_instant_process;
1004 #if defined(ENABLE_EXTENSIONS)
1005 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1006 profile, process_host, site_url);
1007 #else
1008 return true;
1009 #endif
1012 bool ChromeContentBrowserClient::MayReuseHost(
1013 content::RenderProcessHost* process_host) {
1014 // If there is currently a prerender in progress for the host provided,
1015 // it may not be shared. We require prerenders to be by themselves in a
1016 // separate process so that we can monitor their resource usage.
1017 Profile* profile = Profile::FromBrowserContext(
1018 process_host->GetBrowserContext());
1019 prerender::PrerenderManager* prerender_manager =
1020 prerender::PrerenderManagerFactory::GetForProfile(profile);
1021 if (prerender_manager &&
1022 !prerender_manager->MayReuseProcessHost(process_host)) {
1023 return false;
1026 return true;
1029 bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1030 content::BrowserContext* browser_context, const GURL& url) {
1031 // It has to be a valid URL for us to check for an extension.
1032 if (!url.is_valid())
1033 return false;
1035 #if defined(ENABLE_EXTENSIONS)
1036 Profile* profile = Profile::FromBrowserContext(browser_context);
1037 return ChromeContentBrowserClientExtensionsPart::
1038 ShouldTryToUseExistingProcessHost(
1039 profile, url);
1040 #else
1041 return false;
1042 #endif
1045 void ChromeContentBrowserClient::SiteInstanceGotProcess(
1046 SiteInstance* site_instance) {
1047 CHECK(site_instance->HasProcess());
1049 Profile* profile = Profile::FromBrowserContext(
1050 site_instance->GetBrowserContext());
1051 if (!profile)
1052 return;
1054 // Remember the ID of the Instant process to signal the renderer process
1055 // on startup in |AppendExtraCommandLineSwitches| below.
1056 if (chrome::ShouldAssignURLToInstantRenderer(
1057 site_instance->GetSiteURL(), profile)) {
1058 InstantService* instant_service =
1059 InstantServiceFactory::GetForProfile(profile);
1060 if (instant_service)
1061 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1064 for (size_t i = 0; i < extra_parts_.size(); ++i)
1065 extra_parts_[i]->SiteInstanceGotProcess(site_instance);
1068 void ChromeContentBrowserClient::SiteInstanceDeleting(
1069 SiteInstance* site_instance) {
1070 if (!site_instance->HasProcess())
1071 return;
1073 for (size_t i = 0; i < extra_parts_.size(); ++i)
1074 extra_parts_[i]->SiteInstanceDeleting(site_instance);
1077 bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
1078 SiteInstance* site_instance,
1079 const GURL& current_url,
1080 const GURL& new_url) {
1081 #if defined(ENABLE_EXTENSIONS)
1082 return ChromeContentBrowserClientExtensionsPart::
1083 ShouldSwapBrowsingInstancesForNavigation(
1084 site_instance, current_url, new_url);
1085 #else
1086 return false;
1087 #endif
1090 bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1091 content::ResourceContext* resource_context, const GURL& current_url,
1092 const GURL& new_url) {
1093 #if defined(ENABLE_EXTENSIONS)
1094 return ChromeContentBrowserClientExtensionsPart::
1095 ShouldSwapProcessesForRedirect(resource_context, current_url, new_url);
1096 #else
1097 return false;
1098 #endif
1101 bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1102 return !url.SchemeIs(chrome::kChromeNativeScheme);
1105 std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1106 const std::string& alias_name) {
1107 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1110 namespace {
1112 bool IsAutoReloadEnabled() {
1113 // Fetch the field trial, even though we don't use it. Calling FindFullName()
1114 // causes the field-trial mechanism to report which group we're in, which
1115 // might reflect a hard disable or hard enable via flag, both of which have
1116 // their own field trial groups. This lets us know what percentage of users
1117 // manually enable or disable auto-reload.
1118 std::string group = base::FieldTrialList::FindFullName(
1119 "AutoReloadExperiment");
1120 const base::CommandLine& browser_command_line =
1121 *base::CommandLine::ForCurrentProcess();
1122 if (browser_command_line.HasSwitch(switches::kEnableOfflineAutoReload))
1123 return true;
1124 if (browser_command_line.HasSwitch(switches::kDisableOfflineAutoReload))
1125 return false;
1126 return true;
1129 bool IsAutoReloadVisibleOnlyEnabled() {
1130 // See the block comment in IsAutoReloadEnabled().
1131 std::string group = base::FieldTrialList::FindFullName(
1132 "AutoReloadVisibleOnlyExperiment");
1133 const base::CommandLine& browser_command_line =
1134 *base::CommandLine::ForCurrentProcess();
1135 if (browser_command_line.HasSwitch(
1136 switches::kEnableOfflineAutoReloadVisibleOnly)) {
1137 return true;
1139 if (browser_command_line.HasSwitch(
1140 switches::kDisableOfflineAutoReloadVisibleOnly)) {
1141 return false;
1143 return true;
1146 } // namespace
1148 void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1149 base::CommandLine* command_line,
1150 int child_process_id) {
1151 #if defined(OS_MACOSX)
1152 scoped_ptr<metrics::ClientInfo> client_info =
1153 GoogleUpdateSettings::LoadMetricsClientInfo();
1154 if (client_info) {
1155 command_line->AppendSwitchASCII(switches::kMetricsClientID,
1156 client_info->client_id);
1158 #elif defined(OS_POSIX)
1159 if (breakpad::IsCrashReporterEnabled()) {
1160 scoped_ptr<metrics::ClientInfo> client_info =
1161 GoogleUpdateSettings::LoadMetricsClientInfo();
1162 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1163 client_info ? client_info->client_id
1164 : std::string());
1166 #endif
1168 if (logging::DialogsAreSuppressed())
1169 command_line->AppendSwitch(switches::kNoErrorDialogs);
1171 std::string process_type =
1172 command_line->GetSwitchValueASCII(switches::kProcessType);
1173 const base::CommandLine& browser_command_line =
1174 *base::CommandLine::ForCurrentProcess();
1176 static const char* const kCommonSwitchNames[] = {
1177 switches::kUserAgent,
1178 switches::kUserDataDir, // Make logs go to the right file.
1180 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
1181 arraysize(kCommonSwitchNames));
1183 #if defined(ENABLE_IPC_FUZZER)
1184 static const char* const kIpcFuzzerSwitches[] = {
1185 switches::kIpcDumpDirectory,
1186 switches::kIpcFuzzerTestcase,
1188 command_line->CopySwitchesFrom(browser_command_line, kIpcFuzzerSwitches,
1189 arraysize(kIpcFuzzerSwitches));
1190 #endif
1192 #if defined(OS_CHROMEOS)
1193 static const char* const kChromeOSSwitches[] = {
1194 switches::kDisableDinosaurEasterEgg,
1196 command_line->CopySwitchesFrom(browser_command_line, kChromeOSSwitches,
1197 arraysize(kChromeOSSwitches));
1199 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
1200 base::FilePath homedir;
1201 PathService::Get(base::DIR_HOME, &homedir);
1202 command_line->AppendSwitchASCII(chromeos::switches::kHomedir,
1203 homedir.value().c_str());
1204 #endif
1206 if (process_type == switches::kRendererProcess) {
1207 content::RenderProcessHost* process =
1208 content::RenderProcessHost::FromID(child_process_id);
1209 Profile* profile =
1210 process ? Profile::FromBrowserContext(process->GetBrowserContext())
1211 : NULL;
1212 for (size_t i = 0; i < extra_parts_.size(); ++i) {
1213 extra_parts_[i]->AppendExtraRendererCommandLineSwitches(
1214 command_line, process, profile);
1217 #if defined(OS_CHROMEOS)
1218 const std::string& login_profile =
1219 browser_command_line.GetSwitchValueASCII(
1220 chromeos::switches::kLoginProfile);
1221 if (!login_profile.empty())
1222 command_line->AppendSwitchASCII(
1223 chromeos::switches::kLoginProfile, login_profile);
1224 #endif
1226 #if defined(ENABLE_WEBRTC)
1227 MaybeCopyDisableWebRtcEncryptionSwitch(command_line,
1228 browser_command_line,
1229 VersionInfo::GetChannel());
1230 #endif
1232 if (process) {
1233 PrefService* prefs = profile->GetPrefs();
1234 // Currently this pref is only registered if applied via a policy.
1235 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1236 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1237 // Turn this policy into a command line switch.
1238 command_line->AppendSwitch(switches::kDisable3DAPIs);
1241 const base::ListValue* switches =
1242 prefs->GetList(prefs::kEnableDeprecatedWebPlatformFeatures);
1243 if (switches) {
1244 // Enable any deprecated features that have been re-enabled by policy.
1245 for (base::ListValue::const_iterator it = switches->begin();
1246 it != switches->end(); ++it) {
1247 std::string switch_to_enable;
1248 if ((*it)->GetAsString(&switch_to_enable))
1249 command_line->AppendSwitch(switch_to_enable);
1253 // Disable client-side phishing detection in the renderer if it is
1254 // disabled in the Profile preferences or the browser process.
1255 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1256 !g_browser_process->safe_browsing_detection_service()) {
1257 command_line->AppendSwitch(
1258 switches::kDisableClientSidePhishingDetection);
1261 if (prefs->GetBoolean(prefs::kPrintPreviewDisabled))
1262 command_line->AppendSwitch(switches::kDisablePrintPreview);
1264 InstantService* instant_service =
1265 InstantServiceFactory::GetForProfile(profile);
1266 if (instant_service &&
1267 instant_service->IsInstantProcess(process->GetID()))
1268 command_line->AppendSwitch(switches::kInstantProcess);
1271 if (IsAutoReloadEnabled())
1272 command_line->AppendSwitch(switches::kEnableOfflineAutoReload);
1273 if (IsAutoReloadVisibleOnlyEnabled()) {
1274 command_line->AppendSwitch(
1275 switches::kEnableOfflineAutoReloadVisibleOnly);
1279 // Enable showing a saved copy if this session is in the field trial
1280 // or the user explicitly enabled it. Note that as far as the
1281 // renderer is concerned, the feature is enabled if-and-only-if
1282 // one of the kEnableShowSavedCopy* switches is on the command
1283 // line; the yes/no/default behavior is only at the browser
1284 // command line level.
1286 // Command line switches override
1287 const std::string& show_saved_copy_value =
1288 browser_command_line.GetSwitchValueASCII(switches::kShowSavedCopy);
1289 if (show_saved_copy_value == switches::kEnableShowSavedCopyPrimary ||
1290 show_saved_copy_value == switches::kEnableShowSavedCopySecondary ||
1291 show_saved_copy_value == switches::kDisableShowSavedCopy) {
1292 command_line->AppendSwitchASCII(switches::kShowSavedCopy,
1293 show_saved_copy_value);
1294 } else {
1295 std::string group =
1296 base::FieldTrialList::FindFullName("LoadStaleCacheExperiment");
1298 if (group == "Primary") {
1299 command_line->AppendSwitchASCII(
1300 switches::kShowSavedCopy, switches::kEnableShowSavedCopyPrimary);
1301 } else if (group == "Secondary") {
1302 command_line->AppendSwitchASCII(
1303 switches::kShowSavedCopy,
1304 switches::kEnableShowSavedCopySecondary);
1309 // Please keep this in alphabetical order.
1310 static const char* const kSwitchNames[] = {
1311 autofill::switches::kDisableFillOnAccountSelect,
1312 autofill::switches::kDisablePasswordGeneration,
1313 autofill::switches::kEnableFillOnAccountSelect,
1314 autofill::switches::kEnableFillOnAccountSelectNoHighlighting,
1315 autofill::switches::kEnablePasswordGeneration,
1316 autofill::switches::kEnablePasswordSaveOnInPageNavigation,
1317 autofill::switches::kEnableSingleClickAutofill,
1318 autofill::switches::kIgnoreAutocompleteOffForAutofill,
1319 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration,
1320 autofill::switches::kRespectAutocompleteOffForAutofill,
1321 #if defined(ENABLE_EXTENSIONS)
1322 extensions::switches::kAllowHTTPBackgroundPage,
1323 extensions::switches::kAllowLegacyExtensionManifests,
1324 extensions::switches::kEnableSurfaceWorker,
1325 extensions::switches::kEnableAppWindowControls,
1326 extensions::switches::kEnableEmbeddedExtensionOptions,
1327 extensions::switches::kEnableExperimentalExtensionApis,
1328 extensions::switches::kExtensionsOnChromeURLs,
1329 extensions::switches::kWhitelistedExtensionID,
1330 #endif
1331 switches::kAllowInsecureLocalhost,
1332 switches::kAppsCheckoutURL,
1333 switches::kAppsGalleryURL,
1334 switches::kCloudPrintURL,
1335 switches::kCloudPrintXmppEndpoint,
1336 switches::kDisableBundledPpapiFlash,
1337 switches::kDisableCastStreamingHWEncoding,
1338 switches::kDisableJavaScriptHarmonyShipping,
1339 switches::kDisableNewBookmarkApps,
1340 switches::kDisableOutOfProcessPdf,
1341 switches::kEnableBenchmarking,
1342 switches::kEnableNaCl,
1343 #if !defined(DISABLE_NACL)
1344 switches::kEnableNaClDebug,
1345 switches::kEnableNaClNonSfiMode,
1346 switches::kEnablePNaClSubzero,
1347 #endif
1348 switches::kEnableNetBenchmarking,
1349 switches::kEnableNewBookmarkApps,
1350 switches::kEnableOutOfProcessPdf,
1351 switches::kEnablePluginPlaceholderShadowDom,
1352 switches::kJavaScriptHarmony,
1353 switches::kMessageLoopHistogrammer,
1354 switches::kPpapiFlashArgs,
1355 switches::kPpapiFlashPath,
1356 switches::kPpapiFlashVersion,
1357 switches::kProfilingAtStart,
1358 switches::kProfilingFile,
1359 switches::kProfilingFlush,
1360 translate::switches::kTranslateSecurityOrigin,
1363 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1364 arraysize(kSwitchNames));
1365 } else if (process_type == switches::kUtilityProcess) {
1366 #if defined(ENABLE_EXTENSIONS)
1367 static const char* const kSwitchNames[] = {
1368 extensions::switches::kAllowHTTPBackgroundPage,
1369 extensions::switches::kEnableExperimentalExtensionApis,
1370 extensions::switches::kExtensionsOnChromeURLs,
1371 extensions::switches::kWhitelistedExtensionID,
1374 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1375 arraysize(kSwitchNames));
1376 #endif
1377 } else if (process_type == switches::kPluginProcess) {
1378 #if defined(OS_CHROMEOS)
1379 static const char* const kSwitchNames[] = {
1380 chromeos::switches::kLoginProfile,
1383 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1384 arraysize(kSwitchNames));
1385 #endif
1386 } else if (process_type == switches::kZygoteProcess) {
1387 static const char* const kSwitchNames[] = {
1388 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
1389 switches::kDisableBundledPpapiFlash,
1390 #if !defined(DISABLE_NACL)
1391 switches::kEnableNaClDebug,
1392 switches::kEnableNaClNonSfiMode,
1393 switches::kEnablePNaClSubzero,
1394 switches::kNaClDangerousNoSandboxNonSfi,
1395 switches::kUseNaClHelperNonSfi,
1396 #endif
1397 switches::kPpapiFlashPath,
1398 switches::kPpapiFlashVersion,
1401 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1402 arraysize(kSwitchNames));
1403 } else if (process_type == switches::kGpuProcess) {
1404 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1405 // because GPU is expected to be unreliable.
1406 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1407 !command_line->HasSwitch(switches::kDisableBreakpad))
1408 command_line->AppendSwitch(switches::kDisableBreakpad);
1411 // The command line switch kEnableBenchmarking needs to be specified along
1412 // with the kEnableStatsTable switch to ensure that the stats table global
1413 // is initialized correctly.
1414 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1415 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
1418 std::string ChromeContentBrowserClient::GetApplicationLocale() {
1419 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
1420 return g_io_thread_application_locale.Get();
1421 return g_browser_process->GetApplicationLocale();
1424 std::string ChromeContentBrowserClient::GetAcceptLangs(
1425 content::BrowserContext* context) {
1426 Profile* profile = Profile::FromBrowserContext(context);
1427 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
1430 const gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
1431 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1432 return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).ToImageSkia();
1435 bool ChromeContentBrowserClient::AllowAppCache(
1436 const GURL& manifest_url,
1437 const GURL& first_party,
1438 content::ResourceContext* context) {
1439 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1440 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1441 return io_data->GetCookieSettings()->
1442 IsSettingCookieAllowed(manifest_url, first_party);
1445 bool ChromeContentBrowserClient::AllowServiceWorker(
1446 const GURL& scope,
1447 const GURL& first_party_url,
1448 content::ResourceContext* context) {
1449 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1450 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1451 return io_data->GetCookieSettings()->
1452 IsSettingCookieAllowed(scope, first_party_url);
1455 bool ChromeContentBrowserClient::AllowGetCookie(
1456 const GURL& url,
1457 const GURL& first_party,
1458 const net::CookieList& cookie_list,
1459 content::ResourceContext* context,
1460 int render_process_id,
1461 int render_frame_id) {
1462 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1463 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1464 bool allow = io_data->GetCookieSettings()->
1465 IsReadingCookieAllowed(url, first_party);
1467 BrowserThread::PostTask(
1468 BrowserThread::UI, FROM_HERE,
1469 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
1470 render_frame_id, url, first_party, cookie_list, !allow));
1471 return allow;
1474 bool ChromeContentBrowserClient::AllowSetCookie(
1475 const GURL& url,
1476 const GURL& first_party,
1477 const std::string& cookie_line,
1478 content::ResourceContext* context,
1479 int render_process_id,
1480 int render_frame_id,
1481 net::CookieOptions* options) {
1482 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1483 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1484 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1485 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1487 BrowserThread::PostTask(
1488 BrowserThread::UI, FROM_HERE,
1489 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
1490 render_frame_id, url, first_party, cookie_line, *options,
1491 !allow));
1492 return allow;
1495 bool ChromeContentBrowserClient::AllowSaveLocalState(
1496 content::ResourceContext* context) {
1497 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1498 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1499 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1500 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
1502 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1503 // Could we even support per-origin settings?
1504 return setting != CONTENT_SETTING_SESSION_ONLY;
1507 bool ChromeContentBrowserClient::AllowWorkerDatabase(
1508 const GURL& url,
1509 const base::string16& name,
1510 const base::string16& display_name,
1511 unsigned long estimated_size,
1512 content::ResourceContext* context,
1513 const std::vector<std::pair<int, int> >& render_frames) {
1514 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1515 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1516 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1517 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1519 // Record access to database for potential display in UI.
1520 std::vector<std::pair<int, int> >::const_iterator i;
1521 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
1522 BrowserThread::PostTask(
1523 BrowserThread::UI, FROM_HERE,
1524 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1525 i->first, i->second, url, name, display_name, !allow));
1528 return allow;
1531 void ChromeContentBrowserClient::AllowWorkerFileSystem(
1532 const GURL& url,
1533 content::ResourceContext* context,
1534 const std::vector<std::pair<int, int> >& render_frames,
1535 base::Callback<void(bool)> callback) {
1536 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1537 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1538 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1539 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1541 #if defined(ENABLE_EXTENSIONS)
1542 GuestPermissionRequestHelper(url, render_frames, callback, allow);
1543 #else
1544 FileSystemAccessed(url, render_frames, callback, allow);
1545 #endif
1548 #if defined(ENABLE_EXTENSIONS)
1549 void ChromeContentBrowserClient::GuestPermissionRequestHelper(
1550 const GURL& url,
1551 const std::vector<std::pair<int, int> >& render_frames,
1552 base::Callback<void(bool)> callback,
1553 bool allow) {
1554 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::IO));
1555 std::vector<std::pair<int, int> >::const_iterator i;
1556 std::map<int, int> process_map;
1557 std::map<int, int>::const_iterator it;
1558 bool has_web_view_guest = false;
1559 // Record access to file system for potential display in UI.
1560 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
1561 if (process_map.find(i->first) != process_map.end())
1562 continue;
1564 process_map.insert(std::pair<int, int>(i->first, i->second));
1566 if (extensions::WebViewRendererState::GetInstance()->IsGuest(i->first))
1567 has_web_view_guest = true;
1569 if (!has_web_view_guest) {
1570 FileSystemAccessed(url, render_frames, callback, allow);
1571 return;
1573 DCHECK_EQ(1U, process_map.size());
1574 it = process_map.begin();
1575 BrowserThread::PostTask(
1576 BrowserThread::UI,
1577 FROM_HERE,
1578 base::Bind(&ChromeContentBrowserClient::
1579 RequestFileSystemPermissionOnUIThread,
1580 it->first,
1581 it->second,
1582 url,
1583 allow,
1584 base::Bind(&ChromeContentBrowserClient::FileSystemAccessed,
1585 weak_factory_.GetWeakPtr(),
1586 url,
1587 render_frames,
1588 callback)));
1591 void ChromeContentBrowserClient::RequestFileSystemPermissionOnUIThread(
1592 int render_process_id,
1593 int render_frame_id,
1594 const GURL& url,
1595 bool allowed_by_default,
1596 const base::Callback<void(bool)>& callback) {
1597 DCHECK(BrowserThread:: CurrentlyOn(BrowserThread::UI));
1598 extensions::WebViewPermissionHelper* web_view_permission_helper =
1599 extensions::WebViewPermissionHelper::FromFrameID(
1600 render_process_id, render_frame_id);
1601 web_view_permission_helper->RequestFileSystemPermission(url,
1602 allowed_by_default,
1603 callback);
1605 #endif
1607 void ChromeContentBrowserClient::FileSystemAccessed(
1608 const GURL& url,
1609 const std::vector<std::pair<int, int> >& render_frames,
1610 base::Callback<void(bool)> callback,
1611 bool allow) {
1612 // Record access to file system for potential display in UI.
1613 std::vector<std::pair<int, int> >::const_iterator i;
1614 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
1615 BrowserThread::PostTask(
1616 BrowserThread::UI,
1617 FROM_HERE,
1618 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1619 i->first, i->second, url, !allow));
1621 callback.Run(allow);
1624 bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1625 const GURL& url,
1626 const base::string16& name,
1627 content::ResourceContext* context,
1628 const std::vector<std::pair<int, int> >& render_frames) {
1629 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1630 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1631 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1632 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1634 // Record access to IndexedDB for potential display in UI.
1635 std::vector<std::pair<int, int> >::const_iterator i;
1636 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
1637 BrowserThread::PostTask(
1638 BrowserThread::UI, FROM_HERE,
1639 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1640 i->first, i->second, url, name, !allow));
1643 return allow;
1646 net::URLRequestContext*
1647 ChromeContentBrowserClient::OverrideRequestContextForURL(
1648 const GURL& url, content::ResourceContext* context) {
1649 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1650 #if defined(ENABLE_EXTENSIONS)
1651 if (url.SchemeIs(extensions::kExtensionScheme)) {
1652 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1653 return io_data->extensions_request_context();
1655 #endif
1657 return NULL;
1660 QuotaPermissionContext*
1661 ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1662 return new ChromeQuotaPermissionContext();
1665 void ChromeContentBrowserClient::AllowCertificateError(
1666 int render_process_id,
1667 int render_frame_id,
1668 int cert_error,
1669 const net::SSLInfo& ssl_info,
1670 const GURL& request_url,
1671 ResourceType resource_type,
1672 bool overridable,
1673 bool strict_enforcement,
1674 bool expired_previous_decision,
1675 const base::Callback<void(bool)>& callback,
1676 content::CertificateRequestResultType* result) {
1677 if (resource_type != content::RESOURCE_TYPE_MAIN_FRAME) {
1678 // A sub-resource has a certificate error. The user doesn't really
1679 // have a context for making the right decision, so block the
1680 // request hard, without an info bar to allow showing the insecure
1681 // content.
1682 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
1683 return;
1686 // If the tab is being prerendered, cancel the prerender and the request.
1687 content::RenderFrameHost* render_frame_host =
1688 content::RenderFrameHost::FromID(render_process_id, render_frame_id);
1689 WebContents* tab = WebContents::FromRenderFrameHost(render_frame_host);
1690 if (!tab) {
1691 NOTREACHED();
1692 return;
1695 prerender::PrerenderContents* prerender_contents =
1696 prerender::PrerenderContents::FromWebContents(tab);
1697 if (prerender_contents) {
1698 prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR);
1699 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
1700 return;
1703 // Otherwise, display an SSL blocking page. The interstitial page takes
1704 // ownership of ssl_blocking_page.
1705 int options_mask = 0;
1706 if (overridable)
1707 options_mask |= SSLBlockingPage::OVERRIDABLE;
1708 if (strict_enforcement)
1709 options_mask |= SSLBlockingPage::STRICT_ENFORCEMENT;
1710 if (expired_previous_decision)
1711 options_mask |= SSLBlockingPage::EXPIRED_BUT_PREVIOUSLY_ALLOWED;
1713 SafeBrowsingService* safe_browsing_service =
1714 g_browser_process->safe_browsing_service();
1715 SSLErrorHandler::HandleSSLError(
1716 tab, cert_error, ssl_info, request_url, options_mask,
1717 safe_browsing_service ? safe_browsing_service->ui_manager().get()
1718 : nullptr,
1719 callback);
1722 void ChromeContentBrowserClient::SelectClientCertificate(
1723 content::WebContents* web_contents,
1724 net::SSLCertRequestInfo* cert_request_info,
1725 scoped_ptr<content::ClientCertificateDelegate> delegate) {
1726 prerender::PrerenderContents* prerender_contents =
1727 prerender::PrerenderContents::FromWebContents(web_contents);
1728 if (prerender_contents) {
1729 prerender_contents->Destroy(
1730 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED);
1731 return;
1734 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
1735 DCHECK(requesting_url.is_valid())
1736 << "Invalid URL string: https://"
1737 << cert_request_info->host_and_port.ToString();
1739 Profile* profile =
1740 Profile::FromBrowserContext(web_contents->GetBrowserContext());
1741 scoped_ptr<base::Value> filter =
1742 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1743 requesting_url,
1744 requesting_url,
1745 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1746 std::string(),
1747 NULL);
1749 if (filter.get()) {
1750 // Try to automatically select a client certificate.
1751 if (filter->IsType(base::Value::TYPE_DICTIONARY)) {
1752 base::DictionaryValue* filter_dict =
1753 static_cast<base::DictionaryValue*>(filter.get());
1755 const std::vector<scoped_refptr<net::X509Certificate> >&
1756 all_client_certs = cert_request_info->client_certs;
1757 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1758 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
1759 // Use the first certificate that is matched by the filter.
1760 delegate->ContinueWithCertificate(all_client_certs[i].get());
1761 return;
1764 } else {
1765 NOTREACHED();
1769 chrome::ShowSSLClientCertificateSelector(web_contents, cert_request_info,
1770 delegate.Pass());
1773 void ChromeContentBrowserClient::AddCertificate(
1774 net::CertificateMimeType cert_type,
1775 const void* cert_data,
1776 size_t cert_size,
1777 int render_process_id,
1778 int render_frame_id) {
1779 chrome::SSLAddCertificate(cert_type, cert_data, cert_size,
1780 render_process_id, render_frame_id);
1783 content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
1784 return MediaCaptureDevicesDispatcher::GetInstance();
1787 content::PlatformNotificationService*
1788 ChromeContentBrowserClient::GetPlatformNotificationService() {
1789 #if defined(ENABLE_NOTIFICATIONS)
1790 return PlatformNotificationServiceImpl::GetInstance();
1791 #else
1792 NOTIMPLEMENTED();
1793 return NULL;
1794 #endif
1797 bool ChromeContentBrowserClient::CanCreateWindow(
1798 const GURL& opener_url,
1799 const GURL& opener_top_level_frame_url,
1800 const GURL& source_origin,
1801 WindowContainerType container_type,
1802 const GURL& target_url,
1803 const content::Referrer& referrer,
1804 WindowOpenDisposition disposition,
1805 const WebWindowFeatures& features,
1806 bool user_gesture,
1807 bool opener_suppressed,
1808 content::ResourceContext* context,
1809 int render_process_id,
1810 int opener_id,
1811 bool* no_javascript_access) {
1812 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1814 *no_javascript_access = false;
1816 // If the opener is trying to create a background window but doesn't have
1817 // the appropriate permission, fail the attempt.
1818 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
1819 #if defined(ENABLE_EXTENSIONS)
1820 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1821 InfoMap* map = io_data->GetExtensionInfoMap();
1822 if (!map->SecurityOriginHasAPIPermission(
1823 source_origin,
1824 render_process_id,
1825 APIPermission::kBackground)) {
1826 return false;
1829 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1830 // return a recently installed Extension even if this CanCreateWindow call
1831 // was made by an old copy of the page in a normal web process. That's ok,
1832 // because the permission check above would have caused an early return
1833 // already. We must use the full URL to find hosted apps, though, and not
1834 // just the origin.
1835 const Extension* extension =
1836 map->extensions().GetExtensionOrAppByURL(opener_url);
1837 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
1838 *no_javascript_access = true;
1839 #endif
1841 return true;
1844 #if defined(ENABLE_EXTENSIONS)
1845 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
1846 render_process_id))
1847 return true;
1848 #endif
1850 HostContentSettingsMap* content_settings =
1851 ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap();
1852 BlockedWindowParams blocked_params(target_url,
1853 referrer,
1854 disposition,
1855 features,
1856 user_gesture,
1857 opener_suppressed,
1858 render_process_id,
1859 opener_id);
1861 if (!user_gesture &&
1862 !base::CommandLine::ForCurrentProcess()->HasSwitch(
1863 switches::kDisablePopupBlocking)) {
1864 if (content_settings->GetContentSetting(opener_top_level_frame_url,
1865 opener_top_level_frame_url,
1866 CONTENT_SETTINGS_TYPE_POPUPS,
1867 std::string()) !=
1868 CONTENT_SETTING_ALLOW) {
1869 BrowserThread::PostTask(BrowserThread::UI,
1870 FROM_HERE,
1871 base::Bind(&HandleBlockedPopupOnUIThread,
1872 blocked_params));
1873 return false;
1877 #if defined(OS_ANDROID)
1878 if (SingleTabModeTabHelper::IsRegistered(render_process_id, opener_id)) {
1879 BrowserThread::PostTask(BrowserThread::UI,
1880 FROM_HERE,
1881 base::Bind(&HandleSingleTabModeBlockOnUIThread,
1882 blocked_params));
1883 return false;
1885 #endif
1887 return true;
1890 void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1891 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1892 return g_browser_process->ResourceDispatcherHostCreated();
1895 content::SpeechRecognitionManagerDelegate*
1896 ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
1897 return new speech::ChromeSpeechRecognitionManagerDelegate();
1900 net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1901 return g_browser_process->net_log();
1904 AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1905 return new ChromeAccessTokenStore();
1908 bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1909 return true;
1912 void ChromeContentBrowserClient::OverrideWebkitPrefs(
1913 RenderViewHost* rvh, WebPreferences* web_prefs) {
1914 Profile* profile = Profile::FromBrowserContext(
1915 rvh->GetProcess()->GetBrowserContext());
1916 PrefService* prefs = profile->GetPrefs();
1918 // Fill per-script font preferences. These are not registered on Android
1919 // - http://crbug.com/308033.
1920 #if !defined(OS_ANDROID)
1921 FontFamilyCache::FillFontFamilyMap(profile,
1922 prefs::kWebKitStandardFontFamilyMap,
1923 &web_prefs->standard_font_family_map);
1924 FontFamilyCache::FillFontFamilyMap(profile,
1925 prefs::kWebKitFixedFontFamilyMap,
1926 &web_prefs->fixed_font_family_map);
1927 FontFamilyCache::FillFontFamilyMap(profile,
1928 prefs::kWebKitSerifFontFamilyMap,
1929 &web_prefs->serif_font_family_map);
1930 FontFamilyCache::FillFontFamilyMap(profile,
1931 prefs::kWebKitSansSerifFontFamilyMap,
1932 &web_prefs->sans_serif_font_family_map);
1933 FontFamilyCache::FillFontFamilyMap(profile,
1934 prefs::kWebKitCursiveFontFamilyMap,
1935 &web_prefs->cursive_font_family_map);
1936 FontFamilyCache::FillFontFamilyMap(profile,
1937 prefs::kWebKitFantasyFontFamilyMap,
1938 &web_prefs->fantasy_font_family_map);
1939 FontFamilyCache::FillFontFamilyMap(profile,
1940 prefs::kWebKitPictographFontFamilyMap,
1941 &web_prefs->pictograph_font_family_map);
1942 #endif
1944 web_prefs->default_font_size =
1945 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
1946 web_prefs->default_fixed_font_size =
1947 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
1948 web_prefs->minimum_font_size =
1949 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
1950 web_prefs->minimum_logical_font_size =
1951 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
1953 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
1955 web_prefs->javascript_can_open_windows_automatically =
1956 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
1957 web_prefs->dom_paste_enabled =
1958 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
1959 web_prefs->shrinks_standalone_images_to_fit =
1960 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1961 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
1963 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
1964 web_prefs->javascript_enabled = false;
1965 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1966 web_prefs->web_security_enabled = false;
1967 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
1968 web_prefs->plugins_enabled = false;
1969 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1970 web_prefs->java_enabled = false;
1971 web_prefs->loads_images_automatically =
1972 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
1974 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1975 web_prefs->experimental_webgl_enabled = false;
1977 web_prefs->allow_displaying_insecure_content =
1978 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1979 web_prefs->allow_running_insecure_content =
1980 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
1981 #if defined(OS_ANDROID)
1982 web_prefs->font_scale_factor =
1983 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1984 web_prefs->device_scale_adjustment = GetDeviceScaleAdjustment();
1985 web_prefs->force_enable_zoom =
1986 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
1987 #endif
1989 #if defined(OS_ANDROID)
1990 web_prefs->password_echo_enabled =
1991 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
1992 #else
1993 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
1994 #endif
1996 web_prefs->asynchronous_spell_checking_enabled = true;
1997 web_prefs->unified_textchecker_enabled = true;
1999 web_prefs->uses_universal_detector =
2000 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
2001 web_prefs->text_areas_are_resizable =
2002 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
2003 web_prefs->hyperlink_auditing_enabled =
2004 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2006 #if defined(ENABLE_EXTENSIONS)
2007 std::string image_animation_policy =
2008 prefs->GetString(prefs::kAnimationPolicy);
2009 if (image_animation_policy == kAnimationPolicyOnce)
2010 web_prefs->animation_policy =
2011 content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE;
2012 else if (image_animation_policy == kAnimationPolicyNone)
2013 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_NO_ANIMATION;
2014 else
2015 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_ALLOWED;
2016 #endif
2018 // Make sure we will set the default_encoding with canonical encoding name.
2019 web_prefs->default_encoding =
2020 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
2021 web_prefs->default_encoding);
2022 if (web_prefs->default_encoding.empty()) {
2023 prefs->ClearPref(prefs::kDefaultCharset);
2024 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
2026 DCHECK(!web_prefs->default_encoding.empty());
2028 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2029 switches::kEnablePotentiallyAnnoyingSecurityFeatures)) {
2030 web_prefs->disable_reading_from_canvas = true;
2031 web_prefs->strict_mixed_content_checking = true;
2032 web_prefs->strict_powerful_feature_restrictions = true;
2035 for (size_t i = 0; i < extra_parts_.size(); ++i)
2036 extra_parts_[i]->OverrideWebkitPrefs(rvh, web_prefs);
2039 void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2040 BrowserURLHandler* handler) {
2041 for (size_t i = 0; i < extra_parts_.size(); ++i)
2042 extra_parts_[i]->BrowserURLHandlerCreated(handler);
2044 // about: handler. Must come before chrome: handler, since it will
2045 // rewrite about: urls to chrome: URLs and then expect chrome: to
2046 // actually handle them. Also relies on a preliminary fixup phase.
2047 handler->SetFixupHandler(&FixupBrowserAboutURL);
2048 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2049 BrowserURLHandler::null_handler());
2051 #if defined(OS_ANDROID)
2052 // Handler to rewrite chrome://newtab on Android.
2053 handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL,
2054 BrowserURLHandler::null_handler());
2055 #else
2056 // Handler to rewrite chrome://newtab for InstantExtended.
2057 handler->AddHandlerPair(&chrome::HandleNewTabURLRewrite,
2058 &chrome::HandleNewTabURLReverseRewrite);
2059 #endif
2061 // chrome: & friends.
2062 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
2065 void ChromeContentBrowserClient::ClearCache(RenderFrameHost* rfh) {
2066 Profile* profile = Profile::FromBrowserContext(
2067 rfh->GetSiteInstance()->GetProcess()->GetBrowserContext());
2068 BrowsingDataRemover* remover =
2069 BrowsingDataRemover::CreateForUnboundedRange(profile);
2070 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2071 BrowsingDataHelper::UNPROTECTED_WEB);
2072 // BrowsingDataRemover takes care of deleting itself when done.
2075 void ChromeContentBrowserClient::ClearCookies(RenderFrameHost* rfh) {
2076 Profile* profile = Profile::FromBrowserContext(
2077 rfh->GetSiteInstance()->GetProcess()->GetBrowserContext());
2078 BrowsingDataRemover* remover =
2079 BrowsingDataRemover::CreateForUnboundedRange(profile);
2080 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
2081 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
2082 // BrowsingDataRemover takes care of deleting itself when done.
2085 base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
2086 return DownloadPrefs::GetDefaultDownloadDirectory();
2089 std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2090 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2093 void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2094 content::BrowserPpapiHost* browser_host) {
2095 #if defined(ENABLE_PLUGINS)
2096 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host);
2097 #endif
2100 content::BrowserPpapiHost*
2101 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2102 int plugin_process_id) {
2103 #if !defined(DISABLE_NACL)
2104 content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
2105 while (!iter.Done()) {
2106 nacl::NaClProcessHost* host = static_cast<nacl::NaClProcessHost*>(
2107 iter.GetDelegate());
2108 if (host->process() &&
2109 host->process()->GetData().id == plugin_process_id) {
2110 // Found the plugin.
2111 return host->browser_ppapi_host();
2113 ++iter;
2115 #endif
2116 return NULL;
2119 bool ChromeContentBrowserClient::AllowPepperSocketAPI(
2120 content::BrowserContext* browser_context,
2121 const GURL& url,
2122 bool private_api,
2123 const content::SocketPermissionRequest* params) {
2124 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2125 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
2126 browser_context, url, private_api, params, allowed_socket_origins_);
2127 #else
2128 return false;
2129 #endif
2132 ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2133 WebContents* web_contents) {
2134 return new ChromeSelectFilePolicy(web_contents);
2137 void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2138 std::vector<std::string>* additional_allowed_schemes) {
2139 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2140 additional_allowed_schemes);
2141 additional_allowed_schemes->push_back(content::kChromeDevToolsScheme);
2142 additional_allowed_schemes->push_back(content::kChromeUIScheme);
2143 for (size_t i = 0; i < extra_parts_.size(); ++i) {
2144 extra_parts_[i]->GetAdditionalAllowedSchemesForFileSystem(
2145 additional_allowed_schemes);
2149 void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
2150 std::vector<storage::URLRequestAutoMountHandler>* handlers) {
2151 for (size_t i = 0; i < extra_parts_.size(); ++i)
2152 extra_parts_[i]->GetURLRequestAutoMountHandlers(handlers);
2155 void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
2156 content::BrowserContext* browser_context,
2157 const base::FilePath& storage_partition_path,
2158 ScopedVector<storage::FileSystemBackend>* additional_backends) {
2159 #if defined(OS_CHROMEOS)
2160 storage::ExternalMountPoints* external_mount_points =
2161 content::BrowserContext::GetMountPoints(browser_context);
2162 DCHECK(external_mount_points);
2163 chromeos::FileSystemBackend* backend = new chromeos::FileSystemBackend(
2164 new drive::FileSystemBackendDelegate,
2165 new chromeos::file_system_provider::BackendDelegate,
2166 new chromeos::MTPFileSystemBackendDelegate(storage_partition_path),
2167 external_mount_points,
2168 storage::ExternalMountPoints::GetSystemInstance());
2169 backend->AddSystemMountPoints();
2170 DCHECK(backend->CanHandleType(storage::kFileSystemTypeExternal));
2171 additional_backends->push_back(backend);
2172 #endif
2174 for (size_t i = 0; i < extra_parts_.size(); ++i) {
2175 extra_parts_[i]->GetAdditionalFileSystemBackends(
2176 browser_context, storage_partition_path, additional_backends);
2180 #if defined(OS_POSIX) && !defined(OS_MACOSX)
2181 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2182 const base::CommandLine& command_line,
2183 int child_process_id,
2184 FileDescriptorInfo* mappings) {
2185 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
2186 if (v8_snapshot_fd_.get() == -1 && v8_natives_fd_.get() == -1) {
2187 base::FilePath v8_data_path;
2188 PathService::Get(gin::IsolateHolder::kV8SnapshotBasePathKey, &v8_data_path);
2189 DCHECK(!v8_data_path.empty());
2191 int file_flags = base::File::FLAG_OPEN | base::File::FLAG_READ;
2192 base::FilePath v8_natives_data_path =
2193 v8_data_path.AppendASCII(gin::IsolateHolder::kNativesFileName);
2194 base::FilePath v8_snapshot_data_path =
2195 v8_data_path.AppendASCII(gin::IsolateHolder::kSnapshotFileName);
2196 base::File v8_natives_data_file(v8_natives_data_path, file_flags);
2197 base::File v8_snapshot_data_file(v8_snapshot_data_path, file_flags);
2198 DCHECK(v8_natives_data_file.IsValid());
2199 DCHECK(v8_snapshot_data_file.IsValid());
2200 v8_natives_fd_.reset(v8_natives_data_file.TakePlatformFile());
2201 v8_snapshot_fd_.reset(v8_snapshot_data_file.TakePlatformFile());
2203 mappings->Share(kV8NativesDataDescriptor, v8_natives_fd_.get());
2204 mappings->Share(kV8SnapshotDataDescriptor, v8_snapshot_fd_.get());
2205 #endif // V8_USE_EXTERNAL_STARTUP_DATA
2207 #if defined(OS_ANDROID)
2208 base::FilePath data_path;
2209 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2210 DCHECK(!data_path.empty());
2212 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ;
2213 base::FilePath chrome_resources_pak =
2214 data_path.AppendASCII("chrome_100_percent.pak");
2215 base::File file(chrome_resources_pak, flags);
2216 DCHECK(file.IsValid());
2217 mappings->Transfer(kAndroidChrome100PercentPakDescriptor,
2218 base::ScopedFD(file.TakePlatformFile()));
2220 const std::string locale = GetApplicationLocale();
2221 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
2222 GetLocaleFilePath(locale, false);
2223 file.Initialize(locale_pak, flags);
2224 DCHECK(file.IsValid());
2225 mappings->Transfer(kAndroidLocalePakDescriptor,
2226 base::ScopedFD(file.TakePlatformFile()));
2228 base::FilePath resources_pack_path;
2229 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2230 file.Initialize(resources_pack_path, flags);
2231 DCHECK(file.IsValid());
2232 mappings->Transfer(kAndroidUIResourcesPakDescriptor,
2233 base::ScopedFD(file.TakePlatformFile()));
2235 if (breakpad::IsCrashReporterEnabled()) {
2236 file = breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile(
2237 child_process_id);
2238 if (file.IsValid()) {
2239 mappings->Transfer(kAndroidMinidumpDescriptor,
2240 base::ScopedFD(file.TakePlatformFile()));
2241 } else {
2242 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2243 "be disabled for this process.";
2247 base::FilePath app_data_path;
2248 PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path);
2249 DCHECK(!app_data_path.empty());
2251 flags = base::File::FLAG_OPEN | base::File::FLAG_READ;
2252 base::FilePath icudata_path =
2253 app_data_path.AppendASCII(base::i18n::kIcuDataFileName);
2254 base::File icudata_file(icudata_path, flags);
2255 DCHECK(icudata_file.IsValid());
2256 mappings->Transfer(kAndroidICUDataDescriptor,
2257 base::ScopedFD(icudata_file.TakePlatformFile()));
2258 #else
2259 int crash_signal_fd = GetCrashSignalFD(command_line);
2260 if (crash_signal_fd >= 0) {
2261 mappings->Share(kCrashDumpSignal, crash_signal_fd);
2263 #endif // defined(OS_ANDROID)
2265 #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
2267 #if defined(OS_WIN)
2268 const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2269 return chrome::kBrowserResourcesDll;
2272 void ChromeContentBrowserClient::PreSpawnRenderer(
2273 sandbox::TargetPolicy* policy,
2274 bool* success) {
2275 // This code is duplicated in nacl_exe_win_64.cc.
2276 // Allow the server side of a pipe restricted to the "chrome.nacl."
2277 // namespace so that it cannot impersonate other system or other chrome
2278 // service pipes.
2279 sandbox::ResultCode result = policy->AddRule(
2280 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2281 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2282 L"\\\\.\\pipe\\chrome.nacl.*");
2283 if (result != sandbox::SBOX_ALL_OK) {
2284 *success = false;
2285 return;
2288 // Renderers need to send named pipe handles and shared memory
2289 // segment handles to NaCl loader processes.
2290 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2291 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2292 L"File");
2293 if (result != sandbox::SBOX_ALL_OK) {
2294 *success = false;
2295 return;
2298 #endif
2300 bool ChromeContentBrowserClient::CheckMediaAccessPermission(
2301 content::BrowserContext* browser_context,
2302 const GURL& security_origin,
2303 content::MediaStreamType type) {
2304 return MediaCaptureDevicesDispatcher::GetInstance()
2305 ->CheckMediaAccessPermission(
2306 browser_context, security_origin, type);
2309 void ChromeContentBrowserClient::OpenURL(
2310 content::BrowserContext* browser_context,
2311 const content::OpenURLParams& params,
2312 const base::Callback<void(content::WebContents*)>& callback) {
2313 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2315 #if !defined(OS_ANDROID) && !defined(OS_IOS)
2316 NavigateParams nav_params(Profile::FromBrowserContext(browser_context),
2317 params.url,
2318 params.transition);
2319 FillNavigateParamsFromOpenURLParams(&nav_params, params);
2320 nav_params.user_gesture = params.user_gesture;
2322 Navigate(&nav_params);
2323 callback.Run(nav_params.target_contents);
2324 #elif defined(OS_ANDROID)
2325 chrome::android::ServiceTabLauncher::GetInstance()->LaunchTab(
2326 browser_context, params, callback);
2327 #else
2328 NOTIMPLEMENTED();
2329 #endif
2332 void ChromeContentBrowserClient::RecordURLMetric(const std::string& metric,
2333 const GURL& url) {
2334 if (url.is_valid()) {
2335 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(),
2336 metric, url);
2340 content::DevToolsManagerDelegate*
2341 ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
2342 #if defined(OS_ANDROID)
2343 return new DevToolsManagerDelegateAndroid();
2344 #else
2345 return new ChromeDevToolsManagerDelegate();
2346 #endif
2349 content::TracingDelegate* ChromeContentBrowserClient::GetTracingDelegate() {
2350 #if !defined(OS_ANDROID)
2351 return new ChromeTracingDelegate();
2352 #else
2353 return nullptr;
2354 #endif
2357 bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2358 content::BrowserContext* browser_context,
2359 const GURL& url) {
2360 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2361 return ChromeContentBrowserClientPluginsPart::
2362 IsPluginAllowedToCallRequestOSFileHandle(browser_context, url,
2363 allowed_file_handle_origins_);
2364 #else
2365 return false;
2366 #endif
2369 bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
2370 content::BrowserContext* browser_context,
2371 const GURL& url) {
2372 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2373 return ChromeContentBrowserClientPluginsPart::
2374 IsPluginAllowedToUseDevChannelAPIs(browser_context, url,
2375 allowed_dev_channel_origins_);
2376 #else
2377 return false;
2378 #endif
2381 void ChromeContentBrowserClient::OverridePageVisibilityState(
2382 RenderFrameHost* render_frame_host,
2383 blink::WebPageVisibilityState* visibility_state) {
2384 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2386 WebContents* web_contents =
2387 WebContents::FromRenderFrameHost(render_frame_host);
2388 DCHECK(web_contents);
2390 Profile* profile =
2391 Profile::FromBrowserContext(web_contents->GetBrowserContext());
2392 prerender::PrerenderManager* prerender_manager =
2393 prerender::PrerenderManagerFactory::GetForProfile(profile);
2394 if (prerender_manager &&
2395 prerender_manager->IsWebContentsPrerendering(web_contents, nullptr)) {
2396 *visibility_state = blink::WebPageVisibilityStatePrerender;
2400 #if defined(ENABLE_WEBRTC)
2401 void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
2402 base::CommandLine* to_command_line,
2403 const base::CommandLine& from_command_line,
2404 VersionInfo::Channel channel) {
2405 #if defined(OS_ANDROID)
2406 const VersionInfo::Channel kMaxDisableEncryptionChannel =
2407 VersionInfo::CHANNEL_BETA;
2408 #else
2409 const VersionInfo::Channel kMaxDisableEncryptionChannel =
2410 VersionInfo::CHANNEL_DEV;
2411 #endif
2412 if (channel <= kMaxDisableEncryptionChannel) {
2413 static const char* const kWebRtcDevSwitchNames[] = {
2414 switches::kDisableWebRtcEncryption,
2416 to_command_line->CopySwitchesFrom(from_command_line,
2417 kWebRtcDevSwitchNames,
2418 arraysize(kWebRtcDevSwitchNames));
2421 #endif // defined(ENABLE_WEBRTC)
2423 } // namespace chrome