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