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