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