chrome_content_browser_client.cc revision 2385ea399aae016c0806a4f9ef3c9cfe3d2a39df
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. 4 5#include "chrome/browser/chrome_content_browser_client.h" 6 7#include <set> 8#include <utility> 9#include <vector> 10 11#include "base/bind.h" 12#include "base/command_line.h" 13#include "base/lazy_instance.h" 14#include "base/path_service.h" 15#include "base/prefs/pref_service.h" 16#include "base/strings/string_number_conversions.h" 17#include "base/strings/utf_string_conversions.h" 18#include "base/threading/sequenced_worker_pool.h" 19#include "chrome/app/breakpad_mac.h" 20#include "chrome/browser/app_mode/app_mode_utils.h" 21#include "chrome/browser/browser_about_handler.h" 22#include "chrome/browser/browser_process.h" 23#include "chrome/browser/browser_shutdown.h" 24#include "chrome/browser/browsing_data/browsing_data_helper.h" 25#include "chrome/browser/browsing_data/browsing_data_remover.h" 26#include "chrome/browser/character_encoding.h" 27#include "chrome/browser/chrome_net_benchmarking_message_filter.h" 28#include "chrome/browser/chrome_quota_permission_context.h" 29#include "chrome/browser/content_settings/content_settings_utils.h" 30#include "chrome/browser/content_settings/cookie_settings.h" 31#include "chrome/browser/content_settings/host_content_settings_map.h" 32#include "chrome/browser/content_settings/tab_specific_content_settings.h" 33#include "chrome/browser/defaults.h" 34#include "chrome/browser/download/download_util.h" 35#include "chrome/browser/extensions/activity_log/activity_log.h" 36#include "chrome/browser/extensions/api/web_request/web_request_api.h" 37#include "chrome/browser/extensions/browser_permissions_policy_delegate.h" 38#include "chrome/browser/extensions/extension_host.h" 39#include "chrome/browser/extensions/extension_info_map.h" 40#include "chrome/browser/extensions/extension_process_manager.h" 41#include "chrome/browser/extensions/extension_service.h" 42#include "chrome/browser/extensions/extension_system.h" 43#include "chrome/browser/extensions/extension_web_ui.h" 44#include "chrome/browser/extensions/extension_webkit_preferences.h" 45#include "chrome/browser/extensions/suggest_permission_util.h" 46#include "chrome/browser/geolocation/chrome_access_token_store.h" 47#include "chrome/browser/google/google_util.h" 48#include "chrome/browser/guestview/adview/adview_guest.h" 49#include "chrome/browser/guestview/guestview_constants.h" 50#include "chrome/browser/guestview/webview/webview_guest.h" 51#include "chrome/browser/media/media_capture_devices_dispatcher.h" 52#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h" 53#include "chrome/browser/nacl_host/nacl_host_message_filter.h" 54#include "chrome/browser/nacl_host/nacl_process_host.h" 55#include "chrome/browser/net/chrome_net_log.h" 56#include "chrome/browser/notifications/desktop_notification_service.h" 57#include "chrome/browser/notifications/desktop_notification_service_factory.h" 58#include "chrome/browser/platform_util.h" 59#include "chrome/browser/plugins/plugin_info_message_filter.h" 60#include "chrome/browser/prefs/scoped_user_pref_update.h" 61#include "chrome/browser/prerender/prerender_final_status.h" 62#include "chrome/browser/prerender/prerender_manager.h" 63#include "chrome/browser/prerender/prerender_manager_factory.h" 64#include "chrome/browser/prerender/prerender_message_filter.h" 65#include "chrome/browser/prerender/prerender_tracker.h" 66#include "chrome/browser/printing/printing_message_filter.h" 67#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h" 68#include "chrome/browser/profiles/profile.h" 69#include "chrome/browser/profiles/profile_io_data.h" 70#include "chrome/browser/profiles/profile_manager.h" 71#include "chrome/browser/renderer_host/chrome_render_message_filter.h" 72#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h" 73#include "chrome/browser/search/instant_service.h" 74#include "chrome/browser/search/instant_service_factory.h" 75#include "chrome/browser/search/search.h" 76#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h" 77#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h" 78#include "chrome/browser/speech/tts_message_filter.h" 79#include "chrome/browser/ssl/ssl_add_certificate.h" 80#include "chrome/browser/ssl/ssl_blocking_page.h" 81#include "chrome/browser/ssl/ssl_tab_helper.h" 82#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" 83#include "chrome/browser/tab_contents/tab_util.h" 84#include "chrome/browser/ui/chrome_select_file_policy.h" 85#include "chrome/browser/ui/sync/sync_promo_ui.h" 86#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h" 87#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" 88#include "chrome/browser/user_style_sheet_watcher.h" 89#include "chrome/browser/user_style_sheet_watcher_factory.h" 90#include "chrome/browser/validation_message_message_filter.h" 91#include "chrome/common/child_process_logging.h" 92#include "chrome/common/chrome_constants.h" 93#include "chrome/common/chrome_paths.h" 94#include "chrome/common/chrome_switches.h" 95#include "chrome/common/extensions/background_info.h" 96#include "chrome/common/extensions/extension.h" 97#include "chrome/common/extensions/extension_process_policy.h" 98#include "chrome/common/extensions/extension_set.h" 99#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" 100#include "chrome/common/extensions/manifest_handlers/shared_module_info.h" 101#include "chrome/common/extensions/permissions/permissions_data.h" 102#include "chrome/common/extensions/permissions/socket_permission.h" 103#include "chrome/common/logging_chrome.h" 104#include "chrome/common/pepper_permission_util.h" 105#include "chrome/common/pref_names.h" 106#include "chrome/common/render_messages.h" 107#include "chrome/common/url_constants.h" 108#include "chromeos/chromeos_constants.h" 109#include "components/nacl/common/nacl_process_type.h" 110#include "components/user_prefs/pref_registry_syncable.h" 111#include "content/public/browser/browser_child_process_host.h" 112#include "content/public/browser/browser_main_parts.h" 113#include "content/public/browser/browser_ppapi_host.h" 114#include "content/public/browser/browser_thread.h" 115#include "content/public/browser/browser_url_handler.h" 116#include "content/public/browser/child_process_data.h" 117#include "content/public/browser/child_process_security_policy.h" 118#include "content/public/browser/compositor_util.h" 119#include "content/public/browser/render_process_host.h" 120#include "content/public/browser/render_view_host.h" 121#include "content/public/browser/resource_context.h" 122#include "content/public/browser/site_instance.h" 123#include "content/public/browser/web_contents.h" 124#include "content/public/browser/web_contents_view.h" 125#include "content/public/common/child_process_host.h" 126#include "content/public/common/content_descriptors.h" 127#include "extensions/browser/view_type_utils.h" 128#include "extensions/common/constants.h" 129#include "extensions/common/switches.h" 130#include "grit/generated_resources.h" 131#include "grit/ui_resources.h" 132#include "net/base/escape.h" 133#include "net/base/mime_util.h" 134#include "net/cookies/canonical_cookie.h" 135#include "net/cookies/cookie_options.h" 136#include "net/ssl/ssl_cert_request_info.h" 137#include "ppapi/host/ppapi_host.h" 138#include "ui/base/l10n/l10n_util.h" 139#include "ui/base/resource/resource_bundle.h" 140#include "ui/message_center/message_center_util.h" 141#include "webkit/browser/fileapi/external_mount_points.h" 142#include "webkit/common/webpreferences.h" 143#include "webkit/plugins/plugin_switches.h" 144 145#if defined(OS_WIN) 146#include "chrome/browser/chrome_browser_main_win.h" 147#include "sandbox/win/src/sandbox_policy.h" 148#elif defined(OS_MACOSX) 149#include "chrome/browser/chrome_browser_main_mac.h" 150#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h" 151#elif defined(OS_CHROMEOS) 152#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h" 153#include "chrome/browser/chromeos/drive/file_system_backend_delegate.h" 154#include "chrome/browser/chromeos/fileapi/file_system_backend.h" 155#include "chrome/browser/chromeos/login/startup_utils.h" 156#include "chrome/browser/chromeos/login/user_manager.h" 157#include "chrome/browser/chromeos/system/input_device_settings.h" 158#include "chromeos/chromeos_switches.h" 159#elif defined(OS_LINUX) 160#include "chrome/browser/chrome_browser_main_linux.h" 161#elif defined(OS_ANDROID) 162#include "chrome/browser/android/crash_dump_manager.h" 163#include "chrome/browser/chrome_browser_main_android.h" 164#include "chrome/common/descriptors_android.h" 165#elif defined(OS_POSIX) 166#include "chrome/browser/chrome_browser_main_posix.h" 167#endif 168 169#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID) 170#include "base/linux_util.h" 171#include "chrome/browser/crash_handler_host_linux.h" 172#endif 173 174#if !defined(OS_ANDROID) 175#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" 176#endif 177 178#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) 179#include "chrome/browser/captive_portal/captive_portal_tab_helper.h" 180#endif 181 182#if defined(OS_ANDROID) 183#include "ui/base/ui_base_paths.h" 184#endif 185 186#if defined(USE_NSS) 187#include "chrome/browser/ui/crypto_module_password_dialog.h" 188#endif 189 190#if !defined(OS_CHROMEOS) 191#include "chrome/browser/signin/signin_manager.h" 192#include "chrome/browser/signin/signin_manager_factory.h" 193#endif 194 195#if !defined(OS_ANDROID) 196#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" 197#endif 198 199#if defined(ENABLE_WEBRTC) 200#include "chrome/browser/media/webrtc_logging_handler_host.h" 201#endif 202 203#if defined(ENABLE_INPUT_SPEECH) 204#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate_bubble_ui.h" 205#endif 206 207#if defined(FILE_MANAGER_EXTENSION) 208#include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h" 209#endif 210 211#if defined(TOOLKIT_GTK) 212#include "chrome/browser/ui/gtk/chrome_browser_main_extra_parts_gtk.h" 213#endif 214 215#if defined(TOOLKIT_VIEWS) 216#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h" 217#endif 218 219#if defined(USE_ASH) 220#include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h" 221#endif 222 223#if defined(USE_AURA) 224#include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h" 225#endif 226 227#if defined(USE_X11) 228#include "chrome/browser/chrome_browser_main_extra_parts_x11.h" 229#endif 230 231#if defined(ENABLE_SPELLCHECK) 232#include "chrome/browser/spellchecker/spellcheck_message_filter.h" 233#endif 234 235using WebKit::WebWindowFeatures; 236using base::FileDescriptor; 237using content::AccessTokenStore; 238using content::BrowserChildProcessHostIterator; 239using content::BrowserThread; 240using content::BrowserURLHandler; 241using content::ChildProcessSecurityPolicy; 242using content::FileDescriptorInfo; 243using content::QuotaPermissionContext; 244using content::RenderViewHost; 245using content::SiteInstance; 246using content::WebContents; 247using extensions::APIPermission; 248using extensions::Extension; 249using extensions::Manifest; 250using message_center::NotifierId; 251 252namespace { 253 254// Cached version of the locale so we can return the locale on the I/O 255// thread. 256base::LazyInstance<std::string> g_io_thread_application_locale; 257 258#if defined(ENABLE_PLUGINS) 259const char* kPredefinedAllowedSocketOrigins[] = { 260 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client 261 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client) 262 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126 263 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop 264 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop 265 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop 266 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary 267 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089 268 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099 269 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099 270 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099 271 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099 272 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099 273 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099 274 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514 275 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080 276 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080 277 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789 278 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084 279 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084 280 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084 281}; 282#endif 283 284// Returns a copy of the given url with its host set to given host and path set 285// to given path. Other parts of the url will be the same. 286GURL ReplaceURLHostAndPath(const GURL& url, 287 const std::string& host, 288 const std::string& path) { 289 url_canon::Replacements<char> replacements; 290 replacements.SetHost(host.c_str(), 291 url_parse::Component(0, host.length())); 292 replacements.SetPath(path.c_str(), 293 url_parse::Component(0, path.length())); 294 return url.ReplaceComponents(replacements); 295} 296 297// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/". 298GURL AddUberHost(const GURL& url) { 299 const std::string uber_host = chrome::kChromeUIUberHost; 300 const std::string new_path = url.host() + url.path(); 301 302 return ReplaceURLHostAndPath(url, uber_host, new_path); 303} 304 305// If url->host() is "chrome" and url->path() has characters other than the 306// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and 307// returns true. Otherwise returns false. 308bool RemoveUberHost(GURL* url) { 309 if (url->host() != chrome::kChromeUIUberHost) 310 return false; 311 312 if (url->path().empty() || url->path() == "/") 313 return false; 314 315 const std::string old_path = url->path(); 316 317 const std::string::size_type separator = old_path.find('/', 1); 318 std::string new_host; 319 std::string new_path; 320 if (separator == std::string::npos) { 321 new_host = old_path.substr(1); 322 } else { 323 new_host = old_path.substr(1, separator - 1); 324 new_path = old_path.substr(separator); 325 } 326 327 // Do not allow URLs with paths empty before the first slash since we can't 328 // have an empty host. (e.g "foo://chrome//") 329 if (new_host.empty()) 330 return false; 331 332 *url = ReplaceURLHostAndPath(*url, new_host, new_path); 333 334 DCHECK(url->is_valid()); 335 336 return true; 337} 338 339// Handles rewriting Web UI URLs. 340bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) { 341 // Do not handle special URLs such as "about:foo" 342 if (!url->host().empty()) { 343 const GURL chrome_url = AddUberHost(*url); 344 345 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will 346 // be called. 347 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( 348 browser_context, chrome_url)) 349 return true; 350 } 351 352 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( 353 browser_context, *url)) 354 return false; 355 356#if defined(OS_CHROMEOS) 357 // Special case : in ChromeOS in Guest mode bookmarks and history are 358 // disabled for security reasons. New tab page explains the reasons, so 359 // we redirect user to new tab page. 360 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) { 361 if (url->SchemeIs(chrome::kChromeUIScheme) && 362 (url->DomainIs(chrome::kChromeUIBookmarksHost) || 363 url->DomainIs(chrome::kChromeUIHistoryHost))) { 364 // Rewrite with new tab URL 365 *url = GURL(chrome::kChromeUINewTabURL); 366 } 367 } 368#endif 369 370 // Special case the new tab page. In older versions of Chrome, the new tab 371 // page was hosted at chrome-internal:<blah>. This might be in people's saved 372 // sessions or bookmarks, so we say any URL with that scheme triggers the new 373 // tab page. 374 if (url->SchemeIs(chrome::kChromeInternalScheme)) { 375 // Rewrite it with the proper new tab URL. 376 *url = GURL(chrome::kChromeUINewTabURL); 377 } 378 379 return true; 380} 381 382// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to 383// "chrome://foo/". 384bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) { 385 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme)) 386 return false; 387 388 return RemoveUberHost(url); 389} 390 391// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions 392// below. Extension, and isolated apps require different privileges to be 393// granted to their RenderProcessHosts. This classification allows us to make 394// sure URLs are served by hosts with the right set of privileges. 395enum RenderProcessHostPrivilege { 396 PRIV_NORMAL, 397 PRIV_HOSTED, 398 PRIV_ISOLATED, 399 PRIV_EXTENSION, 400}; 401 402RenderProcessHostPrivilege GetPrivilegeRequiredByUrl( 403 const GURL& url, 404 ExtensionService* service) { 405 // Default to a normal renderer cause it is lower privileged. This should only 406 // occur if the URL on a site instance is either malformed, or uninitialized. 407 // If it is malformed, then there is no need for better privileges anyways. 408 // If it is uninitialized, but eventually settles on being an a scheme other 409 // than normal webrenderer, the navigation logic will correct us out of band 410 // anyways. 411 if (!url.is_valid()) 412 return PRIV_NORMAL; 413 414 if (url.SchemeIs(extensions::kExtensionScheme)) { 415 const Extension* extension = 416 service->extensions()->GetByID(url.host()); 417 if (extension && 418 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) 419 return PRIV_ISOLATED; 420 if (extension && extension->is_hosted_app()) 421 return PRIV_HOSTED; 422 423 return PRIV_EXTENSION; 424 } 425 426 return PRIV_NORMAL; 427} 428 429RenderProcessHostPrivilege GetProcessPrivilege( 430 content::RenderProcessHost* process_host, 431 extensions::ProcessMap* process_map, 432 ExtensionService* service) { 433 std::set<std::string> extension_ids = 434 process_map->GetExtensionsInProcess(process_host->GetID()); 435 if (extension_ids.empty()) 436 return PRIV_NORMAL; 437 438 for (std::set<std::string>::iterator iter = extension_ids.begin(); 439 iter != extension_ids.end(); ++iter) { 440 const Extension* extension = service->GetExtensionById(*iter, false); 441 if (extension && 442 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) 443 return PRIV_ISOLATED; 444 if (extension && extension->is_hosted_app()) 445 return PRIV_HOSTED; 446 } 447 448 return PRIV_EXTENSION; 449} 450 451bool CertMatchesFilter(const net::X509Certificate& cert, 452 const base::DictionaryValue& filter) { 453 // TODO(markusheintz): This is the minimal required filter implementation. 454 // Implement a better matcher. 455 456 // An empty filter matches any client certificate since no requirements are 457 // specified at all. 458 if (filter.empty()) 459 return true; 460 461 std::string common_name; 462 if (filter.GetString("ISSUER.CN", &common_name) && 463 (cert.issuer().common_name == common_name)) { 464 return true; 465 } 466 return false; 467} 468 469// Fills |map| with the per-script font prefs under path |map_name|. 470void FillFontFamilyMap(const PrefService* prefs, 471 const char* map_name, 472 webkit_glue::ScriptFontFamilyMap* map) { 473 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { 474 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; 475 std::string pref_name = base::StringPrintf("%s.%s", map_name, script); 476 std::string font_family = prefs->GetString(pref_name.c_str()); 477 if (!font_family.empty()) 478 (*map)[script] = UTF8ToUTF16(font_family); 479 } 480} 481 482#if defined(OS_POSIX) && !defined(OS_MACOSX) 483int GetCrashSignalFD(const CommandLine& command_line) { 484 if (command_line.HasSwitch(switches::kExtensionProcess)) { 485 ExtensionCrashHandlerHostLinux* crash_handler = 486 ExtensionCrashHandlerHostLinux::GetInstance(); 487 return crash_handler->GetDeathSignalSocket(); 488 } 489 490 std::string process_type = 491 command_line.GetSwitchValueASCII(switches::kProcessType); 492 493 if (process_type == switches::kRendererProcess) 494 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); 495 496 if (process_type == switches::kPluginProcess) 497 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); 498 499 if (process_type == switches::kPpapiPluginProcess) 500 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); 501 502 if (process_type == switches::kGpuProcess) 503 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); 504 505 return -1; 506} 507#endif // defined(OS_POSIX) && !defined(OS_MACOSX) 508 509#if !defined(OS_CHROMEOS) 510GURL GetEffectiveURLForSignin(const GURL& url) { 511 CHECK(SigninManager::IsWebBasedSigninFlowURL(url)); 512 513 GURL effective_url(SigninManager::kChromeSigninEffectiveSite); 514 // Copy the path because the argument to SetPathStr must outlive 515 // the Replacements object. 516 const std::string path_copy(url.path()); 517 GURL::Replacements replacements; 518 replacements.SetPathStr(path_copy); 519 effective_url = effective_url.ReplaceComponents(replacements); 520 return effective_url; 521} 522#endif 523 524void SetApplicationLocaleOnIOThread(const std::string& locale) { 525 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 526 g_io_thread_application_locale.Get() = locale; 527} 528 529#if !defined(OS_ANDROID) 530struct BlockedPopupParams { 531 BlockedPopupParams(const GURL& target_url, 532 const content::Referrer& referrer, 533 WindowOpenDisposition disposition, 534 const WebWindowFeatures& features, 535 bool user_gesture, 536 bool opener_suppressed, 537 int render_process_id, 538 int opener_id) 539 : target_url(target_url), 540 referrer(referrer), 541 disposition(disposition), 542 features(features), 543 user_gesture(user_gesture), 544 opener_suppressed(opener_suppressed), 545 render_process_id(render_process_id), 546 opener_id(opener_id) 547 {} 548 549 GURL target_url; 550 content::Referrer referrer; 551 WindowOpenDisposition disposition; 552 WebWindowFeatures features; 553 bool user_gesture; 554 bool opener_suppressed; 555 int render_process_id; 556 int opener_id; 557}; 558 559void HandleBlockedPopupOnUIThread(const BlockedPopupParams& params) { 560 WebContents* tab = 561 tab_util::GetWebContentsByID(params.render_process_id, params.opener_id); 562 if (!tab) 563 return; 564 565 prerender::PrerenderManager* prerender_manager = 566 prerender::PrerenderManagerFactory::GetForProfile( 567 Profile::FromBrowserContext(tab->GetBrowserContext())); 568 if (prerender_manager) { 569 prerender_manager->DestroyPrerenderForRenderView( 570 params.render_process_id, 571 params.opener_id, 572 prerender::FINAL_STATUS_CREATE_NEW_WINDOW); 573 } 574 575 PopupBlockerTabHelper* popup_helper = 576 PopupBlockerTabHelper::FromWebContents(tab); 577 if (!popup_helper) 578 return; 579 popup_helper->AddBlockedPopup(params.target_url, 580 params.referrer, 581 params.disposition, 582 params.features, 583 params.user_gesture, 584 params.opener_suppressed); 585} 586#endif 587 588} // namespace 589 590namespace chrome { 591 592ChromeContentBrowserClient::ChromeContentBrowserClient() { 593#if defined(ENABLE_PLUGINS) 594 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i) 595 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]); 596#endif 597 598 permissions_policy_delegate_.reset( 599 new extensions::BrowserPermissionsPolicyDelegate()); 600} 601 602ChromeContentBrowserClient::~ChromeContentBrowserClient() { 603} 604 605// static 606void ChromeContentBrowserClient::RegisterProfilePrefs( 607 user_prefs::PrefRegistrySyncable* registry) { 608 registry->RegisterBooleanPref( 609 prefs::kDisable3DAPIs, 610 false, 611 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 612 registry->RegisterBooleanPref( 613 prefs::kEnableHyperlinkAuditing, 614 true, 615 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 616 registry->RegisterBooleanPref( 617 prefs::kEnableMemoryInfo, 618 false, 619 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 620} 621 622// static 623void ChromeContentBrowserClient::SetApplicationLocale( 624 const std::string& locale) { 625 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 626 627 // This object is guaranteed to outlive all threads so we don't have to 628 // worry about the lack of refcounting and can just post as Unretained. 629 // 630 // The common case is that this function is called early in Chrome startup 631 // before any threads are created (it will also be called later if the user 632 // changes the pref). In this case, there will be no threads created and 633 // posting will fail. When there are no threads, we can just set the string 634 // without worrying about threadsafety. 635 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 636 base::Bind(&SetApplicationLocaleOnIOThread, locale))) { 637 g_io_thread_application_locale.Get() = locale; 638 } 639} 640 641content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts( 642 const content::MainFunctionParams& parameters) { 643 ChromeBrowserMainParts* main_parts; 644 // Construct the Main browser parts based on the OS type. 645#if defined(OS_WIN) 646 main_parts = new ChromeBrowserMainPartsWin(parameters); 647#elif defined(OS_MACOSX) 648 main_parts = new ChromeBrowserMainPartsMac(parameters); 649#elif defined(OS_CHROMEOS) 650 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters); 651#elif defined(OS_LINUX) 652 main_parts = new ChromeBrowserMainPartsLinux(parameters); 653#elif defined(OS_ANDROID) 654 main_parts = new ChromeBrowserMainPartsAndroid(parameters); 655#elif defined(OS_POSIX) 656 main_parts = new ChromeBrowserMainPartsPosix(parameters); 657#else 658 NOTREACHED(); 659 main_parts = new ChromeBrowserMainParts(parameters); 660#endif 661 662 chrome::AddProfilesExtraParts(main_parts); 663 664 // Construct additional browser parts. Stages are called in the order in 665 // which they are added. 666#if defined(TOOLKIT_GTK) 667 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk()); 668#endif 669 670#if defined(TOOLKIT_VIEWS) 671 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews()); 672#endif 673 674#if defined(USE_ASH) 675 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh()); 676#endif 677 678#if defined(USE_AURA) 679 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura()); 680#endif 681 682#if defined(USE_X11) 683 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11()); 684#endif 685 686 chrome::AddMetricsExtraParts(main_parts); 687 688 return main_parts; 689} 690 691std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite( 692 content::BrowserContext* browser_context, 693 const GURL& site) { 694 std::string partition_id; 695 696 // The partition ID for webview guest processes is the string value of its 697 // SiteInstance URL - "chrome-guest://app_id/persist?partition". 698 if (site.SchemeIs(chrome::kGuestScheme)) 699 partition_id = site.spec(); 700 701 DCHECK(IsValidStoragePartitionId(browser_context, partition_id)); 702 return partition_id; 703} 704 705bool ChromeContentBrowserClient::IsValidStoragePartitionId( 706 content::BrowserContext* browser_context, 707 const std::string& partition_id) { 708 // The default ID is empty and is always valid. 709 if (partition_id.empty()) 710 return true; 711 712 return GURL(partition_id).is_valid(); 713} 714 715void ChromeContentBrowserClient::GetStoragePartitionConfigForSite( 716 content::BrowserContext* browser_context, 717 const GURL& site, 718 bool can_be_default, 719 std::string* partition_domain, 720 std::string* partition_name, 721 bool* in_memory) { 722 // Default to the browser-wide storage partition and override based on |site| 723 // below. 724 partition_domain->clear(); 725 partition_name->clear(); 726 *in_memory = false; 727 728 // For the webview tag, we create special guest processes, which host the 729 // tag content separately from the main application that embeds the tag. 730 // A webview tag can specify both the partition name and whether the storage 731 // for that partition should be persisted. Each tag gets a SiteInstance with 732 // a specially formatted URL, based on the application it is hosted by and 733 // the partition requested by it. The format for that URL is: 734 // chrome-guest://partition_domain/persist?partition_name 735 if (site.SchemeIs(chrome::kGuestScheme)) { 736 // Since guest URLs are only used for packaged apps, there must be an app 737 // id in the URL. 738 CHECK(site.has_host()); 739 *partition_domain = site.host(); 740 // Since persistence is optional, the path must either be empty or the 741 // literal string. 742 *in_memory = (site.path() != "/persist"); 743 // The partition name is user supplied value, which we have encoded when the 744 // URL was created, so it needs to be decoded. 745 *partition_name = net::UnescapeURLComponent(site.query(), 746 net::UnescapeRule::NORMAL); 747 } else if (site.SchemeIs(extensions::kExtensionScheme)) { 748 // If |can_be_default| is false, the caller is stating that the |site| 749 // should be parsed as if it had isolated storage. In particular it is 750 // important to NOT check ExtensionService for the is_storage_isolated() 751 // attribute because this code path is run during Extension uninstall 752 // to do cleanup after the Extension has already been unloaded from the 753 // ExtensionService. 754 bool is_isolated = !can_be_default; 755 if (can_be_default) { 756 const Extension* extension = NULL; 757 Profile* profile = Profile::FromBrowserContext(browser_context); 758 ExtensionService* extension_service = 759 extensions::ExtensionSystem::Get(profile)->extension_service(); 760 if (extension_service) { 761 extension = 762 extension_service->extensions()->GetExtensionOrAppByURL(site); 763 if (extension && 764 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) { 765 is_isolated = true; 766 } 767 } 768 } 769 770 if (is_isolated) { 771 CHECK(site.has_host()); 772 // For extensions with isolated storage, the the host of the |site| is 773 // the |partition_domain|. The |in_memory| and |partition_name| are only 774 // used in guest schemes so they are cleared here. 775 *partition_domain = site.host(); 776 *in_memory = false; 777 partition_name->clear(); 778 } 779 } 780 781 // Assert that if |can_be_default| is false, the code above must have found a 782 // non-default partition. If this fails, the caller has a serious logic 783 // error about which StoragePartition they expect to be in and it is not 784 // safe to continue. 785 CHECK(can_be_default || !partition_domain->empty()); 786} 787 788content::WebContentsViewDelegate* 789 ChromeContentBrowserClient::GetWebContentsViewDelegate( 790 content::WebContents* web_contents) { 791 return chrome::CreateWebContentsViewDelegate(web_contents); 792} 793 794// Check if the extension activity log is enabled for the profile. 795static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) { 796 // crbug.com/247908 - This should be IsLogEnabled except for an issue 797 // in chrome_frame_net_tests 798 return extensions::ActivityLog::IsLogEnabledOnAnyProfile(); 799} 800 801void ChromeContentBrowserClient::GuestWebContentsCreated( 802 WebContents* guest_web_contents, 803 WebContents* opener_web_contents, 804 content::BrowserPluginGuestDelegate** guest_delegate, 805 scoped_ptr<base::DictionaryValue> extra_params) { 806 if (opener_web_contents) { 807 GuestView* guest = GuestView::FromWebContents(opener_web_contents); 808 if (!guest) { 809 NOTREACHED(); 810 return; 811 } 812 813 switch (guest->GetViewType()) { 814 case GuestView::WEBVIEW: { 815 *guest_delegate = new WebViewGuest(guest_web_contents); 816 break; 817 } 818 case GuestView::ADVIEW: { 819 *guest_delegate = new AdViewGuest(guest_web_contents); 820 break; 821 } 822 default: 823 NOTREACHED(); 824 break; 825 } 826 return; 827 } 828 829 if (!extra_params) { 830 NOTREACHED(); 831 return; 832 } 833 std::string api_type; 834 extra_params->GetString(guestview::kParameterApi, &api_type); 835 836 if (api_type == "adview") { 837 *guest_delegate = new AdViewGuest(guest_web_contents); 838 } else if (api_type == "webview") { 839 *guest_delegate = new WebViewGuest(guest_web_contents); 840 } else { 841 NOTREACHED(); 842 } 843} 844 845void ChromeContentBrowserClient::GuestWebContentsAttached( 846 WebContents* guest_web_contents, 847 WebContents* embedder_web_contents, 848 const base::DictionaryValue& extra_params) { 849 Profile* profile = Profile::FromBrowserContext( 850 embedder_web_contents->GetBrowserContext()); 851 ExtensionService* service = 852 extensions::ExtensionSystem::Get(profile)->extension_service(); 853 if (!service) { 854 NOTREACHED(); 855 return; 856 } 857 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL(); 858 const Extension* extension = 859 service->extensions()->GetExtensionOrAppByURL(url); 860 if (!extension) { 861 // It's ok to return here, since we could be running a browser plugin 862 // outside an extension, and don't need to attach a 863 // BrowserPluginGuestDelegate in that case; 864 // e.g. running with flag --enable-browser-plugin-for-all-view-types. 865 return; 866 } 867 868 GuestView* guest = GuestView::FromWebContents(guest_web_contents); 869 if (!guest) { 870 NOTREACHED(); 871 return; 872 } 873 guest->Attach(embedder_web_contents, 874 extension->id(), 875 extra_params); 876} 877 878void ChromeContentBrowserClient::RenderProcessHostCreated( 879 content::RenderProcessHost* host) { 880 int id = host->GetID(); 881 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); 882 net::URLRequestContextGetter* context = 883 profile->GetRequestContextForRenderProcess(id); 884 885 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter( 886 id, profile, context)); 887#if defined(ENABLE_PLUGINS) 888 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile)); 889#endif 890#if defined(ENABLE_PRINTING) 891 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile)); 892#endif 893 host->GetChannel()->AddFilter( 894 new SearchProviderInstallStateMessageFilter(id, profile)); 895#if defined(ENABLE_SPELLCHECK) 896 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id)); 897#endif 898#if defined(OS_MACOSX) 899 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac(id)); 900#endif 901 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter( 902 id, profile, context)); 903 host->GetChannel()->AddFilter( 904 new prerender::PrerenderMessageFilter(id, profile)); 905 host->GetChannel()->AddFilter(new ValidationMessageMessageFilter(id)); 906 host->GetChannel()->AddFilter(new TtsMessageFilter(id, profile)); 907#if defined(ENABLE_WEBRTC) 908 host->GetChannel()->AddFilter(new WebRtcLoggingHandlerHost()); 909#endif 910#if !defined(DISABLE_NACL) 911 ExtensionInfoMap* extension_info_map = 912 extensions::ExtensionSystem::Get(profile)->info_map(); 913 host->GetChannel()->AddFilter(new NaClHostMessageFilter( 914 id, profile->IsOffTheRecord(), 915 profile->GetPath(), extension_info_map, 916 context)); 917#endif 918 919 host->Send(new ChromeViewMsg_SetIsIncognitoProcess( 920 profile->IsOffTheRecord())); 921 922 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled( 923 IsExtensionActivityLogEnabledForProfile(profile))); 924 925 SendExtensionWebRequestStatusToHost(host); 926 927 RendererContentSettingRules rules; 928 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules); 929 host->Send(new ChromeViewMsg_SetContentSettingRules(rules)); 930} 931 932GURL ChromeContentBrowserClient::GetEffectiveURL( 933 content::BrowserContext* browser_context, const GURL& url) { 934 Profile* profile = Profile::FromBrowserContext(browser_context); 935 if (!profile) 936 return url; 937 938 // If the input |url| should be assigned to the Instant renderer, make its 939 // effective URL distinct from other URLs on the search provider's domain. 940 if (chrome::ShouldAssignURLToInstantRenderer(url, profile)) 941 return chrome::GetEffectiveURLForInstant(url, profile); 942 943#if !defined(OS_CHROMEOS) 944 // If the input |url| should be assigned to the Signin renderer, make its 945 // effective URL distinct from other URLs on the signin service's domain. 946 // Note that the signin renderer will be allowed to sign the user in to 947 // Chrome. 948 if (SigninManager::IsWebBasedSigninFlowURL(url)) 949 return GetEffectiveURLForSignin(url); 950#endif 951 952 // If the input |url| is part of an installed app, the effective URL is an 953 // extension URL with the ID of that extension as the host. This has the 954 // effect of grouping apps together in a common SiteInstance. 955 ExtensionService* extension_service = 956 extensions::ExtensionSystem::Get(profile)->extension_service(); 957 if (!extension_service) 958 return url; 959 960 const Extension* extension = extension_service->extensions()-> 961 GetHostedAppByURL(url); 962 if (!extension) 963 return url; 964 965 // Bookmark apps do not use the hosted app process model, and should be 966 // treated as normal URLs. 967 if (extension->from_bookmark()) 968 return url; 969 970 // If the URL is part of an extension's web extent, convert it to an 971 // extension URL. 972 return extension->GetResourceURL(url.path()); 973} 974 975bool ChromeContentBrowserClient::ShouldUseProcessPerSite( 976 content::BrowserContext* browser_context, const GURL& effective_url) { 977 // Non-extension, non-Instant URLs should generally use 978 // process-per-site-instance. Because we expect to use the effective URL, 979 // URLs for hosted apps (apart from bookmark apps) should have an extension 980 // scheme by now. 981 982 Profile* profile = Profile::FromBrowserContext(browser_context); 983 if (!profile) 984 return false; 985 986 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url, profile)) 987 return true; 988 989#if !defined(OS_CHROMEOS) 990 if (SigninManager::IsWebBasedSigninFlowURL(effective_url)) 991 return true; 992#endif 993 994 if (!effective_url.SchemeIs(extensions::kExtensionScheme)) 995 return false; 996 997 ExtensionService* extension_service = 998 extensions::ExtensionSystem::Get(profile)->extension_service(); 999 if (!extension_service) 1000 return false; 1001 1002 const Extension* extension = 1003 extension_service->extensions()->GetExtensionOrAppByURL(effective_url); 1004 if (!extension) 1005 return false; 1006 1007 // If the URL is part of a hosted app that does not have the background 1008 // permission, or that does not allow JavaScript access to the background 1009 // page, we want to give each instance its own process to improve 1010 // responsiveness. 1011 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) { 1012 if (!extension->HasAPIPermission(APIPermission::kBackground) || 1013 !extensions::BackgroundInfo::AllowJSAccess(extension)) { 1014 return false; 1015 } 1016 } 1017 1018 // Hosted apps that have script access to their background page must use 1019 // process per site, since all instances can make synchronous calls to the 1020 // background window. Other extensions should use process per site as well. 1021 return true; 1022} 1023 1024// These are treated as WebUI schemes but do not get WebUI bindings. 1025void ChromeContentBrowserClient::GetAdditionalWebUISchemes( 1026 std::vector<std::string>* additional_schemes) { 1027 additional_schemes->push_back(chrome::kChromeSearchScheme); 1028} 1029 1030net::URLRequestContextGetter* 1031ChromeContentBrowserClient::CreateRequestContext( 1032 content::BrowserContext* browser_context, 1033 content::ProtocolHandlerMap* protocol_handlers) { 1034 Profile* profile = Profile::FromBrowserContext(browser_context); 1035 return profile->CreateRequestContext(protocol_handlers); 1036} 1037 1038net::URLRequestContextGetter* 1039ChromeContentBrowserClient::CreateRequestContextForStoragePartition( 1040 content::BrowserContext* browser_context, 1041 const base::FilePath& partition_path, 1042 bool in_memory, 1043 content::ProtocolHandlerMap* protocol_handlers) { 1044 Profile* profile = Profile::FromBrowserContext(browser_context); 1045 return profile->CreateRequestContextForStoragePartition( 1046 partition_path, in_memory, protocol_handlers); 1047} 1048 1049bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) { 1050 return ProfileIOData::IsHandledURL(url); 1051} 1052 1053bool ChromeContentBrowserClient::CanCommitURL( 1054 content::RenderProcessHost* process_host, 1055 const GURL& url) { 1056 // We need to let most extension URLs commit in any process, since this can 1057 // be allowed due to web_accessible_resources. Most hosted app URLs may also 1058 // load in any process (e.g., in an iframe). However, the Chrome Web Store 1059 // cannot be loaded in iframes and should never be requested outside its 1060 // process. 1061 Profile* profile = 1062 Profile::FromBrowserContext(process_host->GetBrowserContext()); 1063 ExtensionService* service = 1064 extensions::ExtensionSystem::Get(profile)->extension_service(); 1065 if (!service) 1066 return true; 1067 const Extension* new_extension = 1068 service->extensions()->GetExtensionOrAppByURL(url); 1069 if (new_extension && 1070 new_extension->is_hosted_app() && 1071 new_extension->id() == extension_misc::kWebStoreAppId && 1072 !service->process_map()->Contains(new_extension->id(), 1073 process_host->GetID())) { 1074 return false; 1075 } 1076 1077 return true; 1078} 1079 1080bool ChromeContentBrowserClient::IsSuitableHost( 1081 content::RenderProcessHost* process_host, 1082 const GURL& site_url) { 1083 Profile* profile = 1084 Profile::FromBrowserContext(process_host->GetBrowserContext()); 1085 // This may be NULL during tests. In that case, just assume any site can 1086 // share any host. 1087 if (!profile) 1088 return true; 1089 1090 // Instant URLs should only be in the instant process and instant process 1091 // should only have Instant URLs. 1092 InstantService* instant_service = 1093 InstantServiceFactory::GetForProfile(profile); 1094 if (instant_service) { 1095 bool is_instant_process = instant_service->IsInstantProcess( 1096 process_host->GetID()); 1097 bool should_be_in_instant_process = 1098 chrome::ShouldAssignURLToInstantRenderer(site_url, profile); 1099 if (is_instant_process || should_be_in_instant_process) 1100 return is_instant_process && should_be_in_instant_process; 1101 } 1102 1103#if !defined(OS_CHROMEOS) 1104 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile); 1105 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID())) 1106 return SigninManager::IsWebBasedSigninFlowURL(site_url); 1107#endif 1108 1109 ExtensionService* service = 1110 extensions::ExtensionSystem::Get(profile)->extension_service(); 1111 extensions::ProcessMap* process_map = service->process_map(); 1112 1113 // Don't allow the Task Manager to share a process with anything else. 1114 // Otherwise it can affect the renderers it is observing. 1115 // Note: we could create another RenderProcessHostPrivilege bucket for 1116 // this to allow multiple chrome://tasks instances to share, but that's 1117 // a very unlikely case without serious consequences. 1118 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin()) 1119 return false; 1120 1121 // These may be NULL during tests. In that case, just assume any site can 1122 // share any host. 1123 if (!service || !process_map) 1124 return true; 1125 1126 // Otherwise, just make sure the process privilege matches the privilege 1127 // required by the site. 1128 RenderProcessHostPrivilege privilege_required = 1129 GetPrivilegeRequiredByUrl(site_url, service); 1130 return GetProcessPrivilege(process_host, process_map, service) == 1131 privilege_required; 1132} 1133 1134// This function is trying to limit the amount of processes used by extensions 1135// with background pages. It uses a globally set percentage of processes to 1136// run such extensions and if the limit is exceeded, it returns true, to 1137// indicate to the content module to group extensions together. 1138bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost( 1139 content::BrowserContext* browser_context, const GURL& url) { 1140 // It has to be a valid URL for us to check for an extension. 1141 if (!url.is_valid()) 1142 return false; 1143 1144 Profile* profile = Profile::FromBrowserContext(browser_context); 1145 ExtensionService* service = !profile ? NULL : 1146 extensions::ExtensionSystem::Get(profile)->extension_service(); 1147 if (!service) 1148 return false; 1149 1150 // We have to have a valid extension with background page to proceed. 1151 const Extension* extension = 1152 service->extensions()->GetExtensionOrAppByURL(url); 1153 if (!extension) 1154 return false; 1155 if (!extensions::BackgroundInfo::HasBackgroundPage(extension)) 1156 return false; 1157 1158 std::set<int> process_ids; 1159 size_t max_process_count = 1160 content::RenderProcessHost::GetMaxRendererProcessCount(); 1161 1162 // Go through all profiles to ensure we have total count of extension 1163 // processes containing background pages, otherwise one profile can 1164 // starve the other. 1165 std::vector<Profile*> profiles = g_browser_process->profile_manager()-> 1166 GetLoadedProfiles(); 1167 for (size_t i = 0; i < profiles.size(); ++i) { 1168 ExtensionProcessManager* epm = 1169 extensions::ExtensionSystem::Get(profiles[i])->process_manager(); 1170 for (ExtensionProcessManager::const_iterator iter = 1171 epm->background_hosts().begin(); 1172 iter != epm->background_hosts().end(); ++iter) { 1173 const extensions::ExtensionHost* host = *iter; 1174 process_ids.insert(host->render_process_host()->GetID()); 1175 } 1176 } 1177 1178 if (process_ids.size() > 1179 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) { 1180 return true; 1181 } 1182 1183 return false; 1184} 1185 1186void ChromeContentBrowserClient::SiteInstanceGotProcess( 1187 SiteInstance* site_instance) { 1188 CHECK(site_instance->HasProcess()); 1189 1190 Profile* profile = Profile::FromBrowserContext( 1191 site_instance->GetBrowserContext()); 1192 if (!profile) 1193 return; 1194 1195 // Remember the ID of the Instant process to signal the renderer process 1196 // on startup in |AppendExtraCommandLineSwitches| below. 1197 if (chrome::ShouldAssignURLToInstantRenderer( 1198 site_instance->GetSiteURL(), profile)) { 1199 InstantService* instant_service = 1200 InstantServiceFactory::GetForProfile(profile); 1201 if (instant_service) 1202 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID()); 1203 } 1204 1205#if !defined(OS_CHROMEOS) 1206 // We only expect there to be one signin process as we use process-per-site 1207 // for signin URLs. The signin process will be cleared from SigninManager 1208 // when the renderer is destroyed. 1209 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) { 1210 SigninManager* signin_manager = 1211 SigninManagerFactory::GetForProfile(profile); 1212 if (signin_manager) 1213 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID()); 1214 BrowserThread::PostTask( 1215 BrowserThread::IO, FROM_HERE, 1216 base::Bind(&ExtensionInfoMap::SetSigninProcess, 1217 extensions::ExtensionSystem::Get(profile)->info_map(), 1218 site_instance->GetProcess()->GetID())); 1219 } 1220#endif 1221 1222 ExtensionService* service = 1223 extensions::ExtensionSystem::Get(profile)->extension_service(); 1224 if (!service) 1225 return; 1226 1227 const Extension* extension = service->extensions()->GetExtensionOrAppByURL( 1228 site_instance->GetSiteURL()); 1229 if (!extension) 1230 return; 1231 1232 service->process_map()->Insert(extension->id(), 1233 site_instance->GetProcess()->GetID(), 1234 site_instance->GetId()); 1235 BrowserThread::PostTask( 1236 BrowserThread::IO, FROM_HERE, 1237 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess, 1238 extensions::ExtensionSystem::Get(profile)->info_map(), 1239 extension->id(), 1240 site_instance->GetProcess()->GetID(), 1241 site_instance->GetId())); 1242} 1243 1244void ChromeContentBrowserClient::SiteInstanceDeleting( 1245 SiteInstance* site_instance) { 1246 if (!site_instance->HasProcess()) 1247 return; 1248 1249 Profile* profile = Profile::FromBrowserContext( 1250 site_instance->GetBrowserContext()); 1251 ExtensionService* service = 1252 extensions::ExtensionSystem::Get(profile)->extension_service(); 1253 if (!service) 1254 return; 1255 1256 const Extension* extension = service->extensions()->GetExtensionOrAppByURL( 1257 site_instance->GetSiteURL()); 1258 if (!extension) 1259 return; 1260 1261 service->process_map()->Remove(extension->id(), 1262 site_instance->GetProcess()->GetID(), 1263 site_instance->GetId()); 1264 BrowserThread::PostTask( 1265 BrowserThread::IO, FROM_HERE, 1266 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess, 1267 extensions::ExtensionSystem::Get(profile)->info_map(), 1268 extension->id(), 1269 site_instance->GetProcess()->GetID(), 1270 site_instance->GetId())); 1271} 1272 1273bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation( 1274 SiteInstance* site_instance, 1275 const GURL& current_url, 1276 const GURL& new_url) { 1277 if (current_url.is_empty()) { 1278 // Always choose a new process when navigating to extension URLs. The 1279 // process grouping logic will combine all of a given extension's pages 1280 // into the same process. 1281 if (new_url.SchemeIs(extensions::kExtensionScheme)) 1282 return true; 1283 1284 return false; 1285 } 1286 1287 // Also, we must switch if one is an extension and the other is not the exact 1288 // same extension. 1289 if (current_url.SchemeIs(extensions::kExtensionScheme) || 1290 new_url.SchemeIs(extensions::kExtensionScheme)) { 1291 if (current_url.GetOrigin() != new_url.GetOrigin()) 1292 return true; 1293 } 1294 1295 // The checks below only matter if we can retrieve which extensions are 1296 // installed. 1297 Profile* profile = 1298 Profile::FromBrowserContext(site_instance->GetBrowserContext()); 1299 ExtensionService* service = 1300 extensions::ExtensionSystem::Get(profile)->extension_service(); 1301 if (!service) 1302 return false; 1303 1304 // We must swap if the URL is for an extension and we are not using an 1305 // extension process. 1306 const Extension* new_extension = 1307 service->extensions()->GetExtensionOrAppByURL(new_url); 1308 // Ignore all hosted apps except the Chrome Web Store, since they do not 1309 // require their own BrowsingInstance (e.g., postMessage is ok). 1310 if (new_extension && 1311 new_extension->is_hosted_app() && 1312 new_extension->id() != extension_misc::kWebStoreAppId) 1313 new_extension = NULL; 1314 if (new_extension && 1315 site_instance->HasProcess() && 1316 !service->process_map()->Contains(new_extension->id(), 1317 site_instance->GetProcess()->GetID())) 1318 return true; 1319 1320 return false; 1321} 1322 1323bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect( 1324 content::ResourceContext* resource_context, const GURL& current_url, 1325 const GURL& new_url) { 1326 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); 1327 return extensions::CrossesExtensionProcessBoundary( 1328 io_data->GetExtensionInfoMap()->extensions(), 1329 current_url, new_url, false); 1330} 1331 1332bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) { 1333 return !url.SchemeIs(chrome::kChromeNativeScheme); 1334} 1335 1336std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName( 1337 const std::string& alias_name) { 1338 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name); 1339} 1340 1341void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( 1342 CommandLine* command_line, int child_process_id) { 1343#if defined(OS_MACOSX) 1344 if (IsCrashReporterEnabled()) { 1345 command_line->AppendSwitchASCII(switches::kEnableCrashReporter, 1346 child_process_logging::GetClientId()); 1347 } 1348#elif defined(OS_POSIX) 1349 if (IsCrashReporterEnabled()) { 1350 command_line->AppendSwitchASCII(switches::kEnableCrashReporter, 1351 child_process_logging::GetClientId() + "," + base::GetLinuxDistro()); 1352 } 1353 1354#endif // OS_MACOSX 1355 1356 if (logging::DialogsAreSuppressed()) 1357 command_line->AppendSwitch(switches::kNoErrorDialogs); 1358 1359 std::string process_type = 1360 command_line->GetSwitchValueASCII(switches::kProcessType); 1361 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); 1362 1363 if (browser_command_line.HasSwitch(switches::kChromeFrame)) 1364 command_line->AppendSwitch(switches::kChromeFrame); 1365 1366 if (process_type == switches::kRendererProcess) { 1367 base::FilePath user_data_dir = 1368 browser_command_line.GetSwitchValuePath(switches::kUserDataDir); 1369 if (!user_data_dir.empty()) 1370 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir); 1371#if defined(OS_CHROMEOS) 1372 const std::string& login_profile = 1373 browser_command_line.GetSwitchValueASCII( 1374 chromeos::switches::kLoginProfile); 1375 if (!login_profile.empty()) 1376 command_line->AppendSwitchASCII( 1377 chromeos::switches::kLoginProfile, login_profile); 1378#endif 1379 1380 content::RenderProcessHost* process = 1381 content::RenderProcessHost::FromID(child_process_id); 1382 if (process) { 1383 Profile* profile = Profile::FromBrowserContext( 1384 process->GetBrowserContext()); 1385 ExtensionService* extension_service = 1386 extensions::ExtensionSystem::Get(profile)->extension_service(); 1387 if (extension_service) { 1388 extensions::ProcessMap* process_map = extension_service->process_map(); 1389 if (process_map && process_map->Contains(process->GetID())) 1390 command_line->AppendSwitch(switches::kExtensionProcess); 1391 } 1392 1393 PrefService* prefs = profile->GetPrefs(); 1394 // Currently this pref is only registered if applied via a policy. 1395 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) && 1396 prefs->GetBoolean(prefs::kDisable3DAPIs)) { 1397 // Turn this policy into a command line switch. 1398 command_line->AppendSwitch(switches::kDisable3DAPIs); 1399 } 1400 1401 // Disable client-side phishing detection in the renderer if it is 1402 // disabled in the Profile preferences or the browser process. 1403 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) || 1404 !g_browser_process->safe_browsing_detection_service()) { 1405 command_line->AppendSwitch( 1406 switches::kDisableClientSidePhishingDetection); 1407 } 1408 1409 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled)) 1410 command_line->AppendSwitch(switches::kRendererPrintPreview); 1411 1412 InstantService* instant_service = 1413 InstantServiceFactory::GetForProfile(profile); 1414 if (instant_service && 1415 instant_service->IsInstantProcess(process->GetID())) 1416 command_line->AppendSwitch(switches::kInstantProcess); 1417 1418#if !defined(OS_CHROMEOS) 1419 SigninManager* signin_manager = 1420 SigninManagerFactory::GetForProfile(profile); 1421 if (signin_manager && signin_manager->IsSigninProcess(process->GetID())) 1422 command_line->AppendSwitch(switches::kSigninProcess); 1423#endif 1424 } 1425 1426 if (content::IsThreadedCompositingEnabled()) 1427 command_line->AppendSwitch(switches::kEnableThreadedCompositing); 1428 1429 if (message_center::IsRichNotificationEnabled()) 1430 command_line->AppendSwitch(switches::kDisableHTMLNotifications); 1431 1432 // Please keep this in alphabetical order. 1433 static const char* const kSwitchNames[] = { 1434 autofill::switches::kDisableInteractiveAutocomplete, 1435 autofill::switches::kEnableExperimentalFormFilling, 1436 autofill::switches::kEnableInteractiveAutocomplete, 1437 extensions::switches::kAllowLegacyExtensionManifests, 1438 extensions::switches::kAllowScriptingGallery, 1439 extensions::switches::kEnableExperimentalExtensionApis, 1440 extensions::switches::kExtensionsOnChromeURLs, 1441 switches::kAllowHTTPBackgroundPage, 1442 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO 1443 // to browser. 1444 switches::kAllowNaClFileHandleAPI, 1445 switches::kAppsCheckoutURL, 1446 switches::kAppsGalleryURL, 1447 switches::kCloudPrintServiceURL, 1448 switches::kDebugPrint, 1449 switches::kDisableBundledPpapiFlash, 1450 switches::kDisableExtensionsResourceWhitelist, 1451 switches::kDisablePnacl, 1452 switches::kDisableScriptedPrintThrottling, 1453 switches::kEnableAdview, 1454 switches::kEnableAdviewSrcAttribute, 1455 switches::kEnableAppWindowControls, 1456 switches::kEnableBenchmarking, 1457 switches::kEnableIPCFuzzing, 1458 switches::kEnableNaCl, 1459 switches::kEnableNetBenchmarking, 1460 switches::kEnablePasswordGeneration, 1461 switches::kEnableWatchdog, 1462 switches::kMemoryProfiling, 1463 switches::kMessageLoopHistogrammer, 1464 switches::kNoJsRandomness, 1465 switches::kPlaybackMode, 1466 switches::kPpapiFlashArgs, 1467 switches::kPpapiFlashInProcess, 1468 switches::kPpapiFlashPath, 1469 switches::kPpapiFlashVersion, 1470 switches::kProfilingAtStart, 1471 switches::kProfilingFile, 1472 switches::kProfilingFlush, 1473 switches::kRecordMode, 1474 switches::kSilentDumpOnDCHECK, 1475 switches::kSpdyProxyAuthOrigin, 1476 switches::kWhitelistedExtensionID, 1477 }; 1478 1479 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, 1480 arraysize(kSwitchNames)); 1481 } else if (process_type == switches::kUtilityProcess) { 1482 static const char* const kSwitchNames[] = { 1483 extensions::switches::kEnableExperimentalExtensionApis, 1484 extensions::switches::kExtensionsOnChromeURLs, 1485 switches::kAllowHTTPBackgroundPage, 1486 switches::kWhitelistedExtensionID, 1487 }; 1488 1489 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, 1490 arraysize(kSwitchNames)); 1491 } else if (process_type == switches::kPluginProcess) { 1492 static const char* const kSwitchNames[] = { 1493#if defined(OS_CHROMEOS) 1494 chromeos::switches::kLoginProfile, 1495#endif 1496 switches::kMemoryProfiling, 1497 switches::kSilentDumpOnDCHECK, 1498 switches::kUserDataDir, 1499 }; 1500 1501 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, 1502 arraysize(kSwitchNames)); 1503 } else if (process_type == switches::kZygoteProcess) { 1504 static const char* const kSwitchNames[] = { 1505 switches::kUserDataDir, // Make logs go to the right file. 1506 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox. 1507 switches::kDisableBundledPpapiFlash, 1508 switches::kPpapiFlashInProcess, 1509 switches::kPpapiFlashPath, 1510 switches::kPpapiFlashVersion, 1511 }; 1512 1513 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, 1514 arraysize(kSwitchNames)); 1515 } else if (process_type == switches::kGpuProcess) { 1516 base::FilePath user_data_dir = 1517 browser_command_line.GetSwitchValuePath(switches::kUserDataDir); 1518 if (!user_data_dir.empty()) 1519 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir); 1520 // If --ignore-gpu-blacklist is passed in, don't send in crash reports 1521 // because GPU is expected to be unreliable. 1522 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) && 1523 !command_line->HasSwitch(switches::kDisableBreakpad)) 1524 command_line->AppendSwitch(switches::kDisableBreakpad); 1525 } 1526 1527 // The command line switch kEnableBenchmarking needs to be specified along 1528 // with the kEnableStatsTable switch to ensure that the stats table global 1529 // is initialized correctly. 1530 if (command_line->HasSwitch(switches::kEnableBenchmarking)) 1531 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable)); 1532} 1533 1534std::string ChromeContentBrowserClient::GetApplicationLocale() { 1535 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) 1536 return g_io_thread_application_locale.Get(); 1537 return g_browser_process->GetApplicationLocale(); 1538} 1539 1540std::string ChromeContentBrowserClient::GetAcceptLangs( 1541 content::BrowserContext* context) { 1542 Profile* profile = Profile::FromBrowserContext(context); 1543 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages); 1544} 1545 1546gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() { 1547 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 1548 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON); 1549} 1550 1551bool ChromeContentBrowserClient::AllowAppCache( 1552 const GURL& manifest_url, 1553 const GURL& first_party, 1554 content::ResourceContext* context) { 1555 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1556 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 1557 return io_data->GetCookieSettings()-> 1558 IsSettingCookieAllowed(manifest_url, first_party); 1559} 1560 1561bool ChromeContentBrowserClient::AllowGetCookie( 1562 const GURL& url, 1563 const GURL& first_party, 1564 const net::CookieList& cookie_list, 1565 content::ResourceContext* context, 1566 int render_process_id, 1567 int render_view_id) { 1568 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1569 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 1570 bool allow = io_data->GetCookieSettings()-> 1571 IsReadingCookieAllowed(url, first_party); 1572 1573 BrowserThread::PostTask( 1574 BrowserThread::UI, FROM_HERE, 1575 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id, 1576 render_view_id, url, first_party, cookie_list, !allow)); 1577 return allow; 1578} 1579 1580bool ChromeContentBrowserClient::AllowSetCookie( 1581 const GURL& url, 1582 const GURL& first_party, 1583 const std::string& cookie_line, 1584 content::ResourceContext* context, 1585 int render_process_id, 1586 int render_view_id, 1587 net::CookieOptions* options) { 1588 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1589 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 1590 CookieSettings* cookie_settings = io_data->GetCookieSettings(); 1591 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party); 1592 1593 BrowserThread::PostTask( 1594 BrowserThread::UI, FROM_HERE, 1595 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id, 1596 render_view_id, url, first_party, cookie_line, *options, 1597 !allow)); 1598 return allow; 1599} 1600 1601bool ChromeContentBrowserClient::AllowSaveLocalState( 1602 content::ResourceContext* context) { 1603 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1604 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 1605 CookieSettings* cookie_settings = io_data->GetCookieSettings(); 1606 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL); 1607 1608 // TODO(bauerb): Should we also disallow local state if the default is BLOCK? 1609 // Could we even support per-origin settings? 1610 return setting != CONTENT_SETTING_SESSION_ONLY; 1611} 1612 1613bool ChromeContentBrowserClient::AllowWorkerDatabase( 1614 const GURL& url, 1615 const string16& name, 1616 const string16& display_name, 1617 unsigned long estimated_size, 1618 content::ResourceContext* context, 1619 const std::vector<std::pair<int, int> >& render_views) { 1620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1621 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 1622 CookieSettings* cookie_settings = io_data->GetCookieSettings(); 1623 bool allow = cookie_settings->IsSettingCookieAllowed(url, url); 1624 1625 // Record access to database for potential display in UI. 1626 std::vector<std::pair<int, int> >::const_iterator i; 1627 for (i = render_views.begin(); i != render_views.end(); ++i) { 1628 BrowserThread::PostTask( 1629 BrowserThread::UI, FROM_HERE, 1630 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed, 1631 i->first, i->second, url, name, display_name, !allow)); 1632 } 1633 1634 return allow; 1635} 1636 1637bool ChromeContentBrowserClient::AllowWorkerFileSystem( 1638 const GURL& url, 1639 content::ResourceContext* context, 1640 const std::vector<std::pair<int, int> >& render_views) { 1641 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1642 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 1643 CookieSettings* cookie_settings = io_data->GetCookieSettings(); 1644 bool allow = cookie_settings->IsSettingCookieAllowed(url, url); 1645 1646 // Record access to file system for potential display in UI. 1647 std::vector<std::pair<int, int> >::const_iterator i; 1648 for (i = render_views.begin(); i != render_views.end(); ++i) { 1649 BrowserThread::PostTask( 1650 BrowserThread::UI, FROM_HERE, 1651 base::Bind(&TabSpecificContentSettings::FileSystemAccessed, 1652 i->first, i->second, url, !allow)); 1653 } 1654 1655 return allow; 1656} 1657 1658bool ChromeContentBrowserClient::AllowWorkerIndexedDB( 1659 const GURL& url, 1660 const string16& name, 1661 content::ResourceContext* context, 1662 const std::vector<std::pair<int, int> >& render_views) { 1663 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1664 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 1665 CookieSettings* cookie_settings = io_data->GetCookieSettings(); 1666 bool allow = cookie_settings->IsSettingCookieAllowed(url, url); 1667 1668 // Record access to IndexedDB for potential display in UI. 1669 std::vector<std::pair<int, int> >::const_iterator i; 1670 for (i = render_views.begin(); i != render_views.end(); ++i) { 1671 BrowserThread::PostTask( 1672 BrowserThread::UI, FROM_HERE, 1673 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed, 1674 i->first, i->second, url, name, !allow)); 1675 } 1676 1677 return allow; 1678} 1679 1680net::URLRequestContext* 1681ChromeContentBrowserClient::OverrideRequestContextForURL( 1682 const GURL& url, content::ResourceContext* context) { 1683 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1684 if (url.SchemeIs(extensions::kExtensionScheme)) { 1685 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 1686 return io_data->extensions_request_context(); 1687 } 1688 1689 return NULL; 1690} 1691 1692QuotaPermissionContext* 1693ChromeContentBrowserClient::CreateQuotaPermissionContext() { 1694 return new ChromeQuotaPermissionContext(); 1695} 1696 1697void ChromeContentBrowserClient::AllowCertificateError( 1698 int render_process_id, 1699 int render_view_id, 1700 int cert_error, 1701 const net::SSLInfo& ssl_info, 1702 const GURL& request_url, 1703 ResourceType::Type resource_type, 1704 bool overridable, 1705 bool strict_enforcement, 1706 const base::Callback<void(bool)>& callback, 1707 content::CertificateRequestResultType* result) { 1708 if (resource_type != ResourceType::MAIN_FRAME) { 1709 // A sub-resource has a certificate error. The user doesn't really 1710 // have a context for making the right decision, so block the 1711 // request hard, without an info bar to allow showing the insecure 1712 // content. 1713 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY; 1714 return; 1715 } 1716 1717 // If the tab is being prerendered, cancel the prerender and the request. 1718 WebContents* tab = tab_util::GetWebContentsByID( 1719 render_process_id, render_view_id); 1720 if (!tab) { 1721 NOTREACHED(); 1722 return; 1723 } 1724 prerender::PrerenderManager* prerender_manager = 1725 prerender::PrerenderManagerFactory::GetForProfile( 1726 Profile::FromBrowserContext(tab->GetBrowserContext())); 1727 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab, 1728 NULL)) { 1729 if (prerender_manager->prerender_tracker()->TryCancel( 1730 render_process_id, render_view_id, 1731 prerender::FINAL_STATUS_SSL_ERROR)) { 1732 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL; 1733 return; 1734 } 1735 } 1736 1737#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) 1738 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper = 1739 captive_portal::CaptivePortalTabHelper::FromWebContents(tab); 1740 if (captive_portal_tab_helper) 1741 captive_portal_tab_helper->OnSSLCertError(ssl_info); 1742#endif 1743 1744 // Otherwise, display an SSL blocking page. 1745 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable, 1746 strict_enforcement, callback); 1747} 1748 1749void ChromeContentBrowserClient::SelectClientCertificate( 1750 int render_process_id, 1751 int render_view_id, 1752 const net::HttpNetworkSession* network_session, 1753 net::SSLCertRequestInfo* cert_request_info, 1754 const base::Callback<void(net::X509Certificate*)>& callback) { 1755 WebContents* tab = tab_util::GetWebContentsByID( 1756 render_process_id, render_view_id); 1757 if (!tab) { 1758 NOTREACHED(); 1759 return; 1760 } 1761 1762 GURL requesting_url("https://" + cert_request_info->host_and_port); 1763 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://" 1764 << cert_request_info->host_and_port; 1765 1766 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); 1767 scoped_ptr<Value> filter( 1768 profile->GetHostContentSettingsMap()->GetWebsiteSetting( 1769 requesting_url, 1770 requesting_url, 1771 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, 1772 std::string(), NULL)); 1773 1774 if (filter.get()) { 1775 // Try to automatically select a client certificate. 1776 if (filter->IsType(Value::TYPE_DICTIONARY)) { 1777 DictionaryValue* filter_dict = 1778 static_cast<DictionaryValue*>(filter.get()); 1779 1780 const std::vector<scoped_refptr<net::X509Certificate> >& 1781 all_client_certs = cert_request_info->client_certs; 1782 for (size_t i = 0; i < all_client_certs.size(); ++i) { 1783 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) { 1784 // Use the first certificate that is matched by the filter. 1785 callback.Run(all_client_certs[i].get()); 1786 return; 1787 } 1788 } 1789 } else { 1790 NOTREACHED(); 1791 } 1792 } 1793 1794 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab); 1795 if (!ssl_tab_helper) { 1796 // If there is no SSLTabHelper for the given WebContents then we can't 1797 // show the user a dialog to select a client certificate. So we simply 1798 // proceed with no client certificate. 1799 callback.Run(NULL); 1800 return; 1801 } 1802 ssl_tab_helper->ShowClientCertificateRequestDialog( 1803 network_session, cert_request_info, callback); 1804} 1805 1806void ChromeContentBrowserClient::AddCertificate( 1807 net::URLRequest* request, 1808 net::CertificateMimeType cert_type, 1809 const void* cert_data, 1810 size_t cert_size, 1811 int render_process_id, 1812 int render_view_id) { 1813 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size, 1814 render_process_id, render_view_id); 1815} 1816 1817content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() { 1818 return MediaCaptureDevicesDispatcher::GetInstance(); 1819} 1820 1821void ChromeContentBrowserClient::RequestDesktopNotificationPermission( 1822 const GURL& source_origin, 1823 int callback_context, 1824 int render_process_id, 1825 int render_view_id) { 1826#if defined(ENABLE_NOTIFICATIONS) 1827 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1828 WebContents* contents = 1829 tab_util::GetWebContentsByID(render_process_id, render_view_id); 1830 if (!contents) { 1831 NOTREACHED(); 1832 return; 1833 } 1834 1835 // Skip showing the infobar if the request comes from an extension, and that 1836 // extension has the 'notify' permission. (If the extension does not have the 1837 // permission, the user will still be prompted.) 1838 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); 1839 ExtensionInfoMap* extension_info_map = 1840 extensions::ExtensionSystem::Get(profile)->info_map(); 1841 DesktopNotificationService* notification_service = 1842 DesktopNotificationServiceFactory::GetForProfile(profile); 1843 const Extension* extension = NULL; 1844 if (extension_info_map) { 1845 ExtensionSet extensions; 1846 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin( 1847 source_origin, render_process_id, 1848 extensions::APIPermission::kNotification, &extensions); 1849 for (ExtensionSet::const_iterator iter = extensions.begin(); 1850 iter != extensions.end(); ++iter) { 1851 if (notification_service->IsNotifierEnabled(NotifierId( 1852 NotifierId::APPLICATION, (*iter)->id()))) { 1853 extension = iter->get(); 1854 break; 1855 } 1856 } 1857 } 1858 RenderViewHost* rvh = 1859 RenderViewHost::FromID(render_process_id, render_view_id); 1860 if (IsExtensionWithPermissionOrSuggestInConsole( 1861 APIPermission::kNotification, extension, rvh)) { 1862 if (rvh) 1863 rvh->DesktopNotificationPermissionRequestDone(callback_context); 1864 return; 1865 } 1866 1867 notification_service->RequestPermission(source_origin, render_process_id, 1868 render_view_id, callback_context, contents); 1869#else 1870 NOTIMPLEMENTED(); 1871#endif 1872} 1873 1874WebKit::WebNotificationPresenter::Permission 1875 ChromeContentBrowserClient::CheckDesktopNotificationPermission( 1876 const GURL& source_origin, 1877 content::ResourceContext* context, 1878 int render_process_id) { 1879#if defined(ENABLE_NOTIFICATIONS) 1880 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1881 // Sometimes a notification may be invoked during the shutdown. 1882 // See http://crbug.com/256638 1883 if (browser_shutdown::IsTryingToQuit()) 1884 return WebKit::WebNotificationPresenter::PermissionNotAllowed; 1885 1886 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 1887 1888 DesktopNotificationService* notification_service = 1889 io_data->GetNotificationService(); 1890 if (notification_service) { 1891 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap(); 1892 ExtensionSet extensions; 1893 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin( 1894 source_origin, render_process_id, 1895 extensions::APIPermission::kNotification, &extensions); 1896 for (ExtensionSet::const_iterator iter = extensions.begin(); 1897 iter != extensions.end(); ++iter) { 1898 NotifierId notifier_id(NotifierId::APPLICATION, (*iter)->id()); 1899 if (notification_service->IsNotifierEnabled(notifier_id)) 1900 return WebKit::WebNotificationPresenter::PermissionAllowed; 1901 } 1902 1903 return notification_service->HasPermission(source_origin); 1904 } 1905 1906 return WebKit::WebNotificationPresenter::PermissionNotAllowed; 1907#else 1908 return WebKit::WebNotificationPresenter::PermissionAllowed; 1909#endif 1910} 1911 1912void ChromeContentBrowserClient::ShowDesktopNotification( 1913 const content::ShowDesktopNotificationHostMsgParams& params, 1914 int render_process_id, 1915 int render_view_id, 1916 bool worker) { 1917#if defined(ENABLE_NOTIFICATIONS) 1918 RenderViewHost* rvh = RenderViewHost::FromID( 1919 render_process_id, render_view_id); 1920 if (!rvh) { 1921 NOTREACHED(); 1922 return; 1923 } 1924 1925 content::RenderProcessHost* process = rvh->GetProcess(); 1926 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext()); 1927 DesktopNotificationService* service = 1928 DesktopNotificationServiceFactory::GetForProfile(profile); 1929 service->ShowDesktopNotification( 1930 params, render_process_id, render_view_id, 1931 worker ? DesktopNotificationService::WorkerNotification : 1932 DesktopNotificationService::PageNotification); 1933#else 1934 NOTIMPLEMENTED(); 1935#endif 1936} 1937 1938void ChromeContentBrowserClient::CancelDesktopNotification( 1939 int render_process_id, 1940 int render_view_id, 1941 int notification_id) { 1942#if defined(ENABLE_NOTIFICATIONS) 1943 RenderViewHost* rvh = RenderViewHost::FromID( 1944 render_process_id, render_view_id); 1945 if (!rvh) { 1946 NOTREACHED(); 1947 return; 1948 } 1949 1950 content::RenderProcessHost* process = rvh->GetProcess(); 1951 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext()); 1952 DesktopNotificationService* service = 1953 DesktopNotificationServiceFactory::GetForProfile(profile); 1954 service->CancelDesktopNotification( 1955 render_process_id, render_view_id, notification_id); 1956#else 1957 NOTIMPLEMENTED(); 1958#endif 1959} 1960 1961bool ChromeContentBrowserClient::CanCreateWindow( 1962 const GURL& opener_url, 1963 const GURL& source_origin, 1964 WindowContainerType container_type, 1965 const GURL& target_url, 1966 const content::Referrer& referrer, 1967 WindowOpenDisposition disposition, 1968 const WebWindowFeatures& features, 1969 bool user_gesture, 1970 bool opener_suppressed, 1971 content::ResourceContext* context, 1972 int render_process_id, 1973 bool is_guest, 1974 int opener_id, 1975 bool* no_javascript_access) { 1976 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1977 1978 *no_javascript_access = false; 1979 1980 // If the opener is trying to create a background window but doesn't have 1981 // the appropriate permission, fail the attempt. 1982 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) { 1983 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 1984 ExtensionInfoMap* map = io_data->GetExtensionInfoMap(); 1985 1986 if (!map->SecurityOriginHasAPIPermission( 1987 source_origin, 1988 render_process_id, 1989 APIPermission::kBackground)) { 1990 return false; 1991 } 1992 1993 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may 1994 // return a recently installed Extension even if this CanCreateWindow call 1995 // was made by an old copy of the page in a normal web process. That's ok, 1996 // because the permission check above would have caused an early return 1997 // already. We must use the full URL to find hosted apps, though, and not 1998 // just the origin. 1999 const Extension* extension = 2000 map->extensions().GetExtensionOrAppByURL(opener_url); 2001 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension)) 2002 *no_javascript_access = true; 2003 2004 return true; 2005 } 2006 2007 // No new browser window (popup or tab) in app mode. 2008 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL && 2009 chrome::IsRunningInForcedAppMode()) { 2010 return false; 2011 } 2012 2013#if !defined(OS_ANDROID) 2014 if (CommandLine::ForCurrentProcess()->HasSwitch( 2015 switches::kDisableBetterPopupBlocking)) { 2016 return true; 2017 } 2018 2019 if (is_guest) 2020 return true; 2021 2022 HostContentSettingsMap* content_settings = 2023 ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap(); 2024 2025 if (!user_gesture && !CommandLine::ForCurrentProcess()->HasSwitch( 2026 switches::kDisablePopupBlocking)) { 2027 if (content_settings->GetContentSetting(opener_url, 2028 opener_url, 2029 CONTENT_SETTINGS_TYPE_POPUPS, 2030 std::string()) == 2031 CONTENT_SETTING_ALLOW) { 2032 return true; 2033 } 2034 2035 BrowserThread::PostTask(BrowserThread::UI, 2036 FROM_HERE, 2037 base::Bind(&HandleBlockedPopupOnUIThread, 2038 BlockedPopupParams(target_url, 2039 referrer, 2040 disposition, 2041 features, 2042 user_gesture, 2043 opener_suppressed, 2044 render_process_id, 2045 opener_id))); 2046 return false; 2047 } 2048#endif 2049 2050 return true; 2051} 2052 2053std::string ChromeContentBrowserClient::GetWorkerProcessTitle( 2054 const GURL& url, content::ResourceContext* context) { 2055 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 2056 // Check if it's an extension-created worker, in which case we want to use 2057 // the name of the extension. 2058 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 2059 const Extension* extension = 2060 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host()); 2061 return extension ? extension->name() : std::string(); 2062} 2063 2064void ChromeContentBrowserClient::ResourceDispatcherHostCreated() { 2065 return g_browser_process->ResourceDispatcherHostCreated(); 2066} 2067 2068// TODO(tommi): Rename from Get to Create. 2069content::SpeechRecognitionManagerDelegate* 2070 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() { 2071#if defined(ENABLE_INPUT_SPEECH) 2072 return new speech::ChromeSpeechRecognitionManagerDelegateBubbleUI(); 2073#else 2074 // Platforms who don't implement x-webkit-speech (a.k.a INPUT_SPEECH) just 2075 // need the base delegate without the bubble UI. 2076 return new speech::ChromeSpeechRecognitionManagerDelegate(); 2077#endif 2078} 2079 2080net::NetLog* ChromeContentBrowserClient::GetNetLog() { 2081 return g_browser_process->net_log(); 2082} 2083 2084AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() { 2085 return new ChromeAccessTokenStore(); 2086} 2087 2088bool ChromeContentBrowserClient::IsFastShutdownPossible() { 2089 return true; 2090} 2091 2092void ChromeContentBrowserClient::OverrideWebkitPrefs( 2093 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) { 2094 Profile* profile = Profile::FromBrowserContext( 2095 rvh->GetProcess()->GetBrowserContext()); 2096 PrefService* prefs = profile->GetPrefs(); 2097 2098 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap, 2099 &web_prefs->standard_font_family_map); 2100 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap, 2101 &web_prefs->fixed_font_family_map); 2102 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap, 2103 &web_prefs->serif_font_family_map); 2104 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap, 2105 &web_prefs->sans_serif_font_family_map); 2106 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap, 2107 &web_prefs->cursive_font_family_map); 2108 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap, 2109 &web_prefs->fantasy_font_family_map); 2110 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap, 2111 &web_prefs->pictograph_font_family_map); 2112 2113 web_prefs->default_font_size = 2114 prefs->GetInteger(prefs::kWebKitDefaultFontSize); 2115 web_prefs->default_fixed_font_size = 2116 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize); 2117 web_prefs->minimum_font_size = 2118 prefs->GetInteger(prefs::kWebKitMinimumFontSize); 2119 web_prefs->minimum_logical_font_size = 2120 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize); 2121 2122 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); 2123 2124 web_prefs->javascript_can_open_windows_automatically = 2125 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically); 2126 web_prefs->dom_paste_enabled = 2127 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled); 2128 web_prefs->shrinks_standalone_images_to_fit = 2129 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit); 2130 const DictionaryValue* inspector_settings = 2131 prefs->GetDictionary(prefs::kWebKitInspectorSettings); 2132 if (inspector_settings) { 2133 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd(); 2134 iter.Advance()) { 2135 std::string value; 2136 if (iter.value().GetAsString(&value)) { 2137 web_prefs->inspector_settings.push_back( 2138 std::make_pair(iter.key(), value)); 2139 } 2140 } 2141 } 2142 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks); 2143 2144 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled)) 2145 web_prefs->javascript_enabled = false; 2146 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled)) 2147 web_prefs->web_security_enabled = false; 2148 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled)) 2149 web_prefs->plugins_enabled = false; 2150 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled)) 2151 web_prefs->java_enabled = false; 2152 web_prefs->loads_images_automatically = 2153 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically); 2154 2155 if (prefs->GetBoolean(prefs::kDisable3DAPIs)) 2156 web_prefs->experimental_webgl_enabled = false; 2157 2158 web_prefs->memory_info_enabled = 2159 prefs->GetBoolean(prefs::kEnableMemoryInfo); 2160 web_prefs->allow_displaying_insecure_content = 2161 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent); 2162 web_prefs->allow_running_insecure_content = 2163 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent); 2164#if defined(OS_ANDROID) 2165 web_prefs->font_scale_factor = 2166 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor)); 2167 web_prefs->force_enable_zoom = 2168 prefs->GetBoolean(prefs::kWebKitForceEnableZoom); 2169#endif 2170 2171#if defined(OS_ANDROID) 2172 web_prefs->password_echo_enabled = 2173 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled); 2174#else 2175 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled; 2176#endif 2177 2178#if defined(OS_CHROMEOS) 2179 // Enable password echo during OOBE when keyboard driven flag is set. 2180 if (chromeos::UserManager::IsInitialized() && 2181 !chromeos::UserManager::Get()->IsUserLoggedIn() && 2182 !chromeos::StartupUtils::IsOobeCompleted() && 2183 chromeos::system::keyboard_settings::ForceKeyboardDrivenUINavigation()) { 2184 web_prefs->password_echo_enabled = true; 2185 } 2186#endif 2187 2188#if defined(OS_ANDROID) 2189 web_prefs->user_style_sheet_enabled = false; 2190#else 2191 // The user stylesheet watcher may not exist in a testing profile. 2192 UserStyleSheetWatcher* user_style_sheet_watcher = 2193 UserStyleSheetWatcherFactory::GetForProfile(profile).get(); 2194 if (user_style_sheet_watcher) { 2195 web_prefs->user_style_sheet_enabled = true; 2196 web_prefs->user_style_sheet_location = 2197 user_style_sheet_watcher->user_style_sheet(); 2198 } else { 2199 web_prefs->user_style_sheet_enabled = false; 2200 } 2201#endif 2202 2203 web_prefs->asynchronous_spell_checking_enabled = true; 2204 web_prefs->unified_textchecker_enabled = true; 2205 2206 web_prefs->uses_universal_detector = 2207 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector); 2208 web_prefs->text_areas_are_resizable = 2209 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable); 2210 web_prefs->hyperlink_auditing_enabled = 2211 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing); 2212 2213 // Make sure we will set the default_encoding with canonical encoding name. 2214 web_prefs->default_encoding = 2215 CharacterEncoding::GetCanonicalEncodingNameByAliasName( 2216 web_prefs->default_encoding); 2217 if (web_prefs->default_encoding.empty()) { 2218 prefs->ClearPref(prefs::kDefaultCharset); 2219 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); 2220 } 2221 DCHECK(!web_prefs->default_encoding.empty()); 2222 2223 if (content::IsForceCompositingModeEnabled()) 2224 web_prefs->force_compositing_mode = true; 2225 2226 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); 2227 extensions::ViewType view_type = extensions::GetViewType(web_contents); 2228 ExtensionService* service = 2229 extensions::ExtensionSystem::Get(profile)->extension_service(); 2230 if (service) { 2231 const GURL& url = rvh->GetSiteInstance()->GetSiteURL(); 2232 const Extension* extension = service->extensions()->GetByID(url.host()); 2233 // Ensure that we are only granting extension preferences to URLs with 2234 // the correct scheme. Without this check, chrome-guest:// schemes used by 2235 // webview tags as well as hosts that happen to match the id of an 2236 // installed extension would get the wrong preferences. 2237 if (url.SchemeIs(extensions::kExtensionScheme)) { 2238 extension_webkit_preferences::SetPreferences( 2239 extension, view_type, web_prefs); 2240 } 2241 } 2242 2243 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) { 2244 web_prefs->allow_scripts_to_close_windows = true; 2245 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) { 2246 // Disable all kinds of acceleration for background pages. 2247 // See http://crbug.com/96005 and http://crbug.com/96006 2248 web_prefs->force_compositing_mode = false; 2249 web_prefs->accelerated_compositing_enabled = false; 2250 } 2251 2252#if defined(FILE_MANAGER_EXTENSION) 2253 // Override the default of suppressing HW compositing for WebUI pages for the 2254 // file manager, which is implemented using WebUI but wants HW acceleration 2255 // for video decode & render. 2256 if (url.SchemeIs(extensions::kExtensionScheme) && 2257 url.host() == kFileBrowserDomain) { 2258 web_prefs->accelerated_compositing_enabled = true; 2259 web_prefs->accelerated_2d_canvas_enabled = true; 2260 } 2261#endif 2262} 2263 2264void ChromeContentBrowserClient::UpdateInspectorSetting( 2265 RenderViewHost* rvh, const std::string& key, const std::string& value) { 2266 content::BrowserContext* browser_context = 2267 rvh->GetProcess()->GetBrowserContext(); 2268 DictionaryPrefUpdate update( 2269 Profile::FromBrowserContext(browser_context)->GetPrefs(), 2270 prefs::kWebKitInspectorSettings); 2271 DictionaryValue* inspector_settings = update.Get(); 2272 inspector_settings->SetWithoutPathExpansion(key, 2273 Value::CreateStringValue(value)); 2274} 2275 2276void ChromeContentBrowserClient::BrowserURLHandlerCreated( 2277 BrowserURLHandler* handler) { 2278 // Add the default URL handlers. 2279 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride, 2280 BrowserURLHandler::null_handler()); 2281 handler->AddHandlerPair(BrowserURLHandler::null_handler(), 2282 &ExtensionWebUI::HandleChromeURLOverrideReverse); 2283 2284 // about: handler. Must come before chrome: handler, since it will 2285 // rewrite about: urls to chrome: URLs and then expect chrome: to 2286 // actually handle them. 2287 handler->AddHandlerPair(&WillHandleBrowserAboutURL, 2288 BrowserURLHandler::null_handler()); 2289 2290 // Handler to rewrite chrome://newtab for InstantExtended. 2291 handler->AddHandlerPair(&chrome::HandleNewTabURLRewrite, 2292 &chrome::HandleNewTabURLReverseRewrite); 2293 2294 // chrome: & friends. 2295 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse); 2296} 2297 2298void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) { 2299 Profile* profile = Profile::FromBrowserContext( 2300 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext()); 2301 BrowsingDataRemover* remover = 2302 BrowsingDataRemover::CreateForUnboundedRange(profile); 2303 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, 2304 BrowsingDataHelper::UNPROTECTED_WEB); 2305 // BrowsingDataRemover takes care of deleting itself when done. 2306} 2307 2308void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) { 2309 Profile* profile = Profile::FromBrowserContext( 2310 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext()); 2311 BrowsingDataRemover* remover = 2312 BrowsingDataRemover::CreateForUnboundedRange(profile); 2313 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA; 2314 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB); 2315 // BrowsingDataRemover takes care of deleting itself when done. 2316} 2317 2318base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() { 2319 return download_util::GetDefaultDownloadDirectory(); 2320} 2321 2322std::string ChromeContentBrowserClient::GetDefaultDownloadName() { 2323 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME); 2324} 2325 2326void ChromeContentBrowserClient::DidCreatePpapiPlugin( 2327 content::BrowserPpapiHost* browser_host) { 2328#if defined(ENABLE_PLUGINS) 2329 browser_host->GetPpapiHost()->AddHostFactoryFilter( 2330 scoped_ptr<ppapi::host::HostFactory>( 2331 new ChromeBrowserPepperHostFactory(browser_host))); 2332#endif 2333} 2334 2335content::BrowserPpapiHost* 2336 ChromeContentBrowserClient::GetExternalBrowserPpapiHost( 2337 int plugin_process_id) { 2338 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER); 2339 while (!iter.Done()) { 2340 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate()); 2341 if (host->process() && 2342 host->process()->GetData().id == plugin_process_id) { 2343 // Found the plugin. 2344 return host->browser_ppapi_host(); 2345 } 2346 ++iter; 2347 } 2348 return NULL; 2349} 2350 2351bool ChromeContentBrowserClient::SupportsBrowserPlugin( 2352 content::BrowserContext* browser_context, const GURL& site_url) { 2353 if (CommandLine::ForCurrentProcess()->HasSwitch( 2354 switches::kEnableBrowserPluginForAllViewTypes)) 2355 return true; 2356 2357 Profile* profile = Profile::FromBrowserContext(browser_context); 2358 ExtensionService* service = 2359 extensions::ExtensionSystem::Get(profile)->extension_service(); 2360 if (!service) 2361 return false; 2362 2363 const Extension* extension = 2364 service->extensions()->GetExtensionOrAppByURL(site_url); 2365 if (!extension) 2366 return false; 2367 2368 return extension->HasAPIPermission(APIPermission::kWebView) || 2369 extension->HasAPIPermission(APIPermission::kAdView); 2370} 2371 2372bool ChromeContentBrowserClient::AllowPepperSocketAPI( 2373 content::BrowserContext* browser_context, 2374 const GURL& url, 2375 bool private_api, 2376 const content::SocketPermissionRequest& params) { 2377#if defined(ENABLE_PLUGINS) 2378 Profile* profile = Profile::FromBrowserContext(browser_context); 2379 const ExtensionSet* extension_set = NULL; 2380 if (profile) { 2381 extension_set = extensions::ExtensionSystem::Get(profile)-> 2382 extension_service()->extensions(); 2383 } 2384 2385 if (private_api) { 2386 // Access to private socket APIs is controlled by the whitelist. 2387 if (IsExtensionOrSharedModuleWhitelisted(url, extension_set, 2388 allowed_socket_origins_)) { 2389 return true; 2390 } 2391 } else { 2392 // Access to public socket APIs is controlled by extension permissions. 2393 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) && 2394 extension_set) { 2395 const Extension* extension = extension_set->GetByID(url.host()); 2396 if (extension) { 2397 extensions::SocketPermission::CheckParam check_params( 2398 params.type, params.host, params.port); 2399 if (extensions::PermissionsData::CheckAPIPermissionWithParam( 2400 extension, extensions::APIPermission::kSocket, &check_params)) { 2401 return true; 2402 } 2403 } 2404 } 2405 } 2406 2407 // Allow both public and private APIs if the command line says so. 2408 return IsHostAllowedByCommandLine(url, extension_set, 2409 switches::kAllowNaClSocketAPI); 2410#else 2411 return false; 2412#endif 2413} 2414 2415ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy( 2416 WebContents* web_contents) { 2417 return new ChromeSelectFilePolicy(web_contents); 2418} 2419 2420void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( 2421 std::vector<std::string>* additional_allowed_schemes) { 2422 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( 2423 additional_allowed_schemes); 2424 additional_allowed_schemes->push_back(kChromeUIScheme); 2425 additional_allowed_schemes->push_back(extensions::kExtensionScheme); 2426} 2427 2428void ChromeContentBrowserClient::GetAdditionalFileSystemBackends( 2429 content::BrowserContext* browser_context, 2430 const base::FilePath& storage_partition_path, 2431 ScopedVector<fileapi::FileSystemBackend>* additional_backends) { 2432#if !defined(OS_ANDROID) 2433 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); 2434 additional_backends->push_back(new MediaFileSystemBackend( 2435 storage_partition_path, 2436 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken( 2437 MediaFileSystemBackend::kMediaTaskRunnerName)).get())); 2438#endif 2439#if defined(OS_CHROMEOS) 2440 fileapi::ExternalMountPoints* external_mount_points = 2441 content::BrowserContext::GetMountPoints(browser_context); 2442 DCHECK(external_mount_points); 2443 chromeos::FileSystemBackend* backend = 2444 new chromeos::FileSystemBackend( 2445 new drive::FileSystemBackendDelegate(browser_context), 2446 browser_context->GetSpecialStoragePolicy(), 2447 external_mount_points, 2448 fileapi::ExternalMountPoints::GetSystemInstance()); 2449 backend->AddSystemMountPoints(); 2450 DCHECK(backend->CanHandleType(fileapi::kFileSystemTypeExternal)); 2451 additional_backends->push_back(backend); 2452#endif 2453 2454 additional_backends->push_back(new sync_file_system::SyncFileSystemBackend()); 2455} 2456 2457#if defined(OS_POSIX) && !defined(OS_MACOSX) 2458void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess( 2459 const CommandLine& command_line, 2460 int child_process_id, 2461 std::vector<FileDescriptorInfo>* mappings) { 2462#if defined(OS_ANDROID) 2463 base::FilePath data_path; 2464 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path); 2465 DCHECK(!data_path.empty()); 2466 2467 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ; 2468 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak"); 2469 base::PlatformFile f = 2470 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL); 2471 DCHECK(f != base::kInvalidPlatformFileValue); 2472 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor, 2473 FileDescriptor(f, true))); 2474 2475 base::FilePath chrome_resources_pak = 2476 data_path.AppendASCII("chrome_100_percent.pak"); 2477 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL); 2478 DCHECK(f != base::kInvalidPlatformFileValue); 2479 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor, 2480 FileDescriptor(f, true))); 2481 2482 const std::string locale = GetApplicationLocale(); 2483 base::FilePath locale_pak = ResourceBundle::GetSharedInstance(). 2484 GetLocaleFilePath(locale, false); 2485 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL); 2486 DCHECK(f != base::kInvalidPlatformFileValue); 2487 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor, 2488 FileDescriptor(f, true))); 2489 2490 base::FilePath resources_pack_path; 2491 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); 2492 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL); 2493 DCHECK(f != base::kInvalidPlatformFileValue); 2494 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor, 2495 FileDescriptor(f, true))); 2496 2497 if (IsCrashReporterEnabled()) { 2498 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id); 2499 if (f == base::kInvalidPlatformFileValue) { 2500 LOG(ERROR) << "Failed to create file for minidump, crash reporting will " 2501 "be disabled for this process."; 2502 } else { 2503 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor, 2504 FileDescriptor(f, true))); 2505 } 2506 } 2507 2508#else 2509 int crash_signal_fd = GetCrashSignalFD(command_line); 2510 if (crash_signal_fd >= 0) { 2511 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal, 2512 FileDescriptor(crash_signal_fd, 2513 false))); 2514 } 2515#endif // defined(OS_ANDROID) 2516} 2517#endif // defined(OS_POSIX) && !defined(OS_MACOSX) 2518 2519#if defined(OS_WIN) 2520const wchar_t* ChromeContentBrowserClient::GetResourceDllName() { 2521 return chrome::kBrowserResourcesDll; 2522} 2523 2524void ChromeContentBrowserClient::PreSpawnRenderer( 2525 sandbox::TargetPolicy* policy, 2526 bool* success) { 2527 // This code is duplicated in nacl_exe_win_64.cc. 2528 // Allow the server side of a pipe restricted to the "chrome.nacl." 2529 // namespace so that it cannot impersonate other system or other chrome 2530 // service pipes. 2531 sandbox::ResultCode result = policy->AddRule( 2532 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES, 2533 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY, 2534 L"\\\\.\\pipe\\chrome.nacl.*"); 2535 if (result != sandbox::SBOX_ALL_OK) { 2536 *success = false; 2537 return; 2538 } 2539 2540 // Renderers need to send named pipe handles and shared memory 2541 // segment handles to NaCl loader processes. 2542 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES, 2543 sandbox::TargetPolicy::HANDLES_DUP_ANY, 2544 L"File"); 2545 if (result != sandbox::SBOX_ALL_OK) { 2546 *success = false; 2547 return; 2548 } 2549} 2550#endif 2551 2552#if defined(USE_NSS) 2553crypto::CryptoModuleBlockingPasswordDelegate* 2554 ChromeContentBrowserClient::GetCryptoPasswordDelegate( 2555 const GURL& url) { 2556 return chrome::NewCryptoModuleBlockingDialogDelegate( 2557 chrome::kCryptoModulePasswordKeygen, url.host()); 2558} 2559#endif 2560 2561} // namespace chrome 2562