Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/common/chrome_content_client.h" | 5 #include "chrome/common/chrome_content_client.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | |
|
jln (very slow on Chromium)
2015/08/07 22:27:19
might want to #ifdef this to Linux
Greg K
2015/08/08 00:23:57
Done.
| |
| 8 | |
| 7 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 8 #include "base/debug/crash_logging.h" | 10 #include "base/debug/crash_logging.h" |
| 9 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 10 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 13 #include "base/memory/scoped_vector.h" | |
| 11 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 12 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 13 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
| 15 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 16 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 18 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 19 #include "chrome/common/child_process_logging.h" | 22 #include "chrome/common/child_process_logging.h" |
| 20 #include "chrome/common/chrome_constants.h" | 23 #include "chrome/common/chrome_constants.h" |
| 21 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
| 22 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/component_flash_hint_file.h" | |
| 23 #include "chrome/common/crash_keys.h" | 27 #include "chrome/common/crash_keys.h" |
| 24 #include "chrome/common/pepper_flash.h" | 28 #include "chrome/common/pepper_flash.h" |
| 25 #include "chrome/common/secure_origin_whitelist.h" | 29 #include "chrome/common/secure_origin_whitelist.h" |
| 26 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
| 27 #include "chrome/grit/common_resources.h" | 31 #include "chrome/grit/common_resources.h" |
| 28 #include "components/dom_distiller/core/url_constants.h" | 32 #include "components/dom_distiller/core/url_constants.h" |
| 29 #include "components/version_info/version_info.h" | 33 #include "components/version_info/version_info.h" |
| 30 #include "content/public/common/content_constants.h" | 34 #include "content/public/common/content_constants.h" |
| 31 #include "content/public/common/content_switches.h" | 35 #include "content/public/common/content_switches.h" |
| 32 #include "content/public/common/url_constants.h" | 36 #include "content/public/common/url_constants.h" |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 // Also get the version from the command-line. Should be something like 11.2 | 278 // Also get the version from the command-line. Should be something like 11.2 |
| 275 // or 11.2.123.45. | 279 // or 11.2.123.45. |
| 276 std::string flash_version = | 280 std::string flash_version = |
| 277 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 281 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 278 switches::kPpapiFlashVersion); | 282 switches::kPpapiFlashVersion); |
| 279 | 283 |
| 280 plugins->push_back( | 284 plugins->push_back( |
| 281 CreatePepperFlashInfo(base::FilePath(flash_path), flash_version)); | 285 CreatePepperFlashInfo(base::FilePath(flash_path), flash_version)); |
| 282 } | 286 } |
| 283 | 287 |
| 288 #if defined(OS_LINUX) | |
| 289 bool IsUserDataDirAvailable() { | |
| 290 base::FilePath user_data_dir; | |
| 291 if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) | |
| 292 return false; | |
| 293 return base::PathExists(user_data_dir); | |
| 294 } | |
| 295 | |
| 296 // This method is used on Linux only because of architectural differences in how | |
| 297 // it loads the component updated flash plugin, and not because the other | |
| 298 // platforms do not support component updated flash. On other platforms, the | |
| 299 // component updater sends an IPC message to all threads, at undefined points in | |
| 300 // time, with the URL of the component updated flash. Because the linux zygote | |
| 301 // thread has no access to the file system after it warms up, it must preload | |
| 302 // the component updated flash. | |
| 303 bool GetComponentUpdatedPepperFlash(content::PepperPluginInfo* plugin) { | |
| 304 #if defined(FLAPPER_AVAILABLE) | |
| 305 if (chrome::ComponentFlashHintFile::DoesHintFileExist()) { | |
| 306 base::FilePath flash_path; | |
| 307 std::string version; | |
| 308 if (chrome::ComponentFlashHintFile::VerifyAndReturnFlashLocation( | |
| 309 &flash_path, &version)) { | |
| 310 // Test if the file can be mapped as executable. If the user's home | |
| 311 // directory is mounted noexec, the component flash plugin will not load. | |
| 312 // By testing for this, Chrome can fallback to the bundled flash pluign. | |
|
jln (very slow on Chromium)
2015/08/07 22:27:19
nit: plugin
Greg K
2015/08/08 00:23:57
Done.
| |
| 313 if (!chrome::ComponentFlashHintFile::TestExecutableMapping(flash_path)) { | |
| 314 LOG(WARNING) << "The component updated flash plugin could not be " | |
| 315 "mapped as executable. Attempting to fallback to the " | |
| 316 "bundled or system plugin."; | |
| 317 return false; | |
| 318 } | |
| 319 *plugin = CreatePepperFlashInfo(flash_path, version); | |
| 320 return true; | |
| 321 } else { | |
| 322 LOG(ERROR) | |
| 323 << "Failed to locate and load the component updated flash plugin."; | |
| 324 } | |
| 325 } | |
| 326 #endif // defined(FLAPPER_AVAILABLE) | |
| 327 return false; | |
| 328 } | |
| 329 #endif // defined(OS_LINUX) | |
| 330 | |
| 284 bool GetBundledPepperFlash(content::PepperPluginInfo* plugin) { | 331 bool GetBundledPepperFlash(content::PepperPluginInfo* plugin) { |
| 285 #if defined(FLAPPER_AVAILABLE) | 332 #if defined(FLAPPER_AVAILABLE) |
| 286 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 333 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 287 | 334 |
| 288 // Ignore bundled Pepper Flash if there is Pepper Flash specified from the | 335 // Ignore bundled Pepper Flash if there is Pepper Flash specified from the |
| 289 // command-line. | 336 // command-line. |
| 290 if (command_line->HasSwitch(switches::kPpapiFlashPath)) | 337 if (command_line->HasSwitch(switches::kPpapiFlashPath)) |
| 291 return false; | 338 return false; |
| 292 | 339 |
| 293 bool force_disable = | 340 bool force_disable = |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 451 base::debug::SetCrashKeyValue(crash_keys::kGPUVertexShaderVersion, | 498 base::debug::SetCrashKeyValue(crash_keys::kGPUVertexShaderVersion, |
| 452 gpu_info.vertex_shader_version); | 499 gpu_info.vertex_shader_version); |
| 453 #if defined(OS_MACOSX) | 500 #if defined(OS_MACOSX) |
| 454 base::debug::SetCrashKeyValue(crash_keys::kGPUGLVersion, gpu_info.gl_version); | 501 base::debug::SetCrashKeyValue(crash_keys::kGPUGLVersion, gpu_info.gl_version); |
| 455 #elif defined(OS_POSIX) | 502 #elif defined(OS_POSIX) |
| 456 base::debug::SetCrashKeyValue(crash_keys::kGPUVendor, gpu_info.gl_vendor); | 503 base::debug::SetCrashKeyValue(crash_keys::kGPUVendor, gpu_info.gl_vendor); |
| 457 base::debug::SetCrashKeyValue(crash_keys::kGPURenderer, gpu_info.gl_renderer); | 504 base::debug::SetCrashKeyValue(crash_keys::kGPURenderer, gpu_info.gl_renderer); |
| 458 #endif | 505 #endif |
| 459 } | 506 } |
| 460 | 507 |
| 508 // static | |
| 509 #if defined(ENABLE_PLUGINS) | |
| 510 content::PepperPluginInfo* ChromeContentClient::FindMostRecentPlugin( | |
| 511 std::vector<content::PepperPluginInfo*>& plugins) { | |
| 512 content::PepperPluginInfo* result = nullptr; | |
| 513 auto it = std::max_element( | |
| 514 plugins.begin(), plugins.end(), | |
| 515 [](content::PepperPluginInfo* x, content::PepperPluginInfo* y) { | |
| 516 Version version_x(x->version); | |
| 517 DCHECK(version_x.IsValid()); | |
| 518 return version_x.IsOlderThan(y->version); | |
| 519 }); | |
| 520 if (it != plugins.end()) | |
| 521 result = *it; | |
| 522 return result; | |
| 523 } | |
| 524 #endif // defined(ENABLE_PLUGINS) | |
| 525 | |
| 461 void ChromeContentClient::AddPepperPlugins( | 526 void ChromeContentClient::AddPepperPlugins( |
| 462 std::vector<content::PepperPluginInfo>* plugins) { | 527 std::vector<content::PepperPluginInfo>* plugins) { |
| 463 #if defined(ENABLE_PLUGINS) | 528 #if defined(ENABLE_PLUGINS) |
| 464 ComputeBuiltInPlugins(plugins); | 529 ComputeBuiltInPlugins(plugins); |
| 465 AddPepperFlashFromCommandLine(plugins); | 530 AddPepperFlashFromCommandLine(plugins); |
| 466 | 531 |
| 467 content::PepperPluginInfo plugin; | 532 #if defined(OS_LINUX) |
| 468 if (GetBundledPepperFlash(&plugin)) | 533 // Depending on the sandbox configurtion, the user data directory |
| 469 plugins->push_back(plugin); | 534 // is not always available. If it is not available, do not try and load any |
| 470 if (GetSystemPepperFlash(&plugin)) | 535 // flash plugin. The flash player, if any, preloaded before the sandbox |
| 471 plugins->push_back(plugin); | 536 // initialization will continue to be used. |
| 472 #endif | 537 if (!IsUserDataDirAvailable()) { |
| 538 return; | |
| 539 } | |
| 540 #endif // defined(OS_LINUX) | |
| 541 | |
| 542 ScopedVector<content::PepperPluginInfo> flash_versions; | |
| 543 | |
| 544 #if defined(OS_LINUX) | |
| 545 scoped_ptr<content::PepperPluginInfo> component_flash( | |
| 546 new content::PepperPluginInfo); | |
| 547 if (GetComponentUpdatedPepperFlash(component_flash.get())) | |
| 548 flash_versions.push_back(component_flash.release()); | |
| 549 #endif // defined(OS_LINUX) | |
| 550 | |
| 551 scoped_ptr<content::PepperPluginInfo> bundled_flash( | |
| 552 new content::PepperPluginInfo); | |
| 553 if (GetBundledPepperFlash(bundled_flash.get())) | |
| 554 flash_versions.push_back(bundled_flash.release()); | |
| 555 | |
| 556 scoped_ptr<content::PepperPluginInfo> system_flash( | |
| 557 new content::PepperPluginInfo); | |
| 558 if (GetSystemPepperFlash(system_flash.get())) | |
| 559 flash_versions.push_back(system_flash.release()); | |
| 560 | |
| 561 // This function will return only the most recent version of the flash plugin. | |
| 562 content::PepperPluginInfo* max_flash = | |
| 563 FindMostRecentPlugin(flash_versions.get()); | |
| 564 if (max_flash != nullptr) | |
| 565 plugins->push_back(*max_flash); | |
| 566 #endif // defined(ENABLE_PLUGINS) | |
| 473 } | 567 } |
| 474 | 568 |
| 475 void ChromeContentClient::AddAdditionalSchemes( | 569 void ChromeContentClient::AddAdditionalSchemes( |
| 476 std::vector<std::string>* standard_schemes, | 570 std::vector<std::string>* standard_schemes, |
| 477 std::vector<std::string>* savable_schemes) { | 571 std::vector<std::string>* savable_schemes) { |
| 478 standard_schemes->push_back(extensions::kExtensionScheme); | 572 standard_schemes->push_back(extensions::kExtensionScheme); |
| 479 savable_schemes->push_back(extensions::kExtensionScheme); | 573 savable_schemes->push_back(extensions::kExtensionScheme); |
| 480 standard_schemes->push_back(chrome::kChromeNativeScheme); | 574 standard_schemes->push_back(chrome::kChromeNativeScheme); |
| 481 standard_schemes->push_back(extensions::kExtensionResourceScheme); | 575 standard_schemes->push_back(extensions::kExtensionResourceScheme); |
| 482 savable_schemes->push_back(extensions::kExtensionResourceScheme); | 576 savable_schemes->push_back(extensions::kExtensionResourceScheme); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 schemes->insert(content::kChromeUIScheme); | 646 schemes->insert(content::kChromeUIScheme); |
| 553 schemes->insert(extensions::kExtensionScheme); | 647 schemes->insert(extensions::kExtensionScheme); |
| 554 schemes->insert(extensions::kExtensionResourceScheme); | 648 schemes->insert(extensions::kExtensionResourceScheme); |
| 555 GetSecureOriginWhitelist(origins); | 649 GetSecureOriginWhitelist(origins); |
| 556 } | 650 } |
| 557 | 651 |
| 558 void ChromeContentClient::AddServiceWorkerSchemes( | 652 void ChromeContentClient::AddServiceWorkerSchemes( |
| 559 std::set<std::string>* schemes) { | 653 std::set<std::string>* schemes) { |
| 560 schemes->insert(extensions::kExtensionScheme); | 654 schemes->insert(extensions::kExtensionScheme); |
| 561 } | 655 } |
| OLD | NEW |