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> | |
| 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" |
| 11 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 12 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 13 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
| 15 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 16 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 18 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 19 #include "chrome/common/child_process_logging.h" | 21 #include "chrome/common/child_process_logging.h" |
| 20 #include "chrome/common/chrome_constants.h" | 22 #include "chrome/common/chrome_constants.h" |
| 21 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
| 22 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/common/component_flash_hint_file.h" | |
| 23 #include "chrome/common/crash_keys.h" | 26 #include "chrome/common/crash_keys.h" |
| 24 #include "chrome/common/pepper_flash.h" | 27 #include "chrome/common/pepper_flash.h" |
| 25 #include "chrome/common/secure_origin_whitelist.h" | 28 #include "chrome/common/secure_origin_whitelist.h" |
| 26 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
| 27 #include "chrome/grit/common_resources.h" | 30 #include "chrome/grit/common_resources.h" |
| 28 #include "components/dom_distiller/core/url_constants.h" | 31 #include "components/dom_distiller/core/url_constants.h" |
| 29 #include "components/version_info/version_info.h" | 32 #include "components/version_info/version_info.h" |
| 30 #include "content/public/common/content_constants.h" | 33 #include "content/public/common/content_constants.h" |
| 31 #include "content/public/common/content_switches.h" | 34 #include "content/public/common/content_switches.h" |
| 32 #include "content/public/common/url_constants.h" | 35 #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 | 277 // Also get the version from the command-line. Should be something like 11.2 |
| 275 // or 11.2.123.45. | 278 // or 11.2.123.45. |
| 276 std::string flash_version = | 279 std::string flash_version = |
| 277 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 280 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 278 switches::kPpapiFlashVersion); | 281 switches::kPpapiFlashVersion); |
| 279 | 282 |
| 280 plugins->push_back( | 283 plugins->push_back( |
| 281 CreatePepperFlashInfo(base::FilePath(flash_path), flash_version)); | 284 CreatePepperFlashInfo(base::FilePath(flash_path), flash_version)); |
| 282 } | 285 } |
| 283 | 286 |
| 287 #if defined(OS_LINUX) | |
| 288 bool IsUserDataDirAvailable() { | |
| 289 base::FilePath user_data_dir; | |
| 290 if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) | |
| 291 return false; | |
| 292 return base::PathExists(user_data_dir); | |
| 293 } | |
| 294 | |
| 295 // This method is used on Linux only because of architectural differences in how | |
| 296 // it loads the component updated flash plugin, and not because the other | |
| 297 // platforms do not support component updated flash. On other platforms, the | |
| 298 // component updater sends an IPC message to all threads, at undefined points in | |
| 299 // time, with the URL of the component updated flash. Because the linux zygote | |
| 300 // thread has no access to the file system after it warms up, it must preload | |
| 301 // the component updated flash. | |
| 302 bool GetComponentUpdatedPepperFlash(content::PepperPluginInfo* plugin) { | |
| 303 #if defined(FLAPPER_AVAILABLE) | |
| 304 if (chrome::ComponentFlashHintFile::DoesHintFileExist()) { | |
| 305 base::FilePath flash_path; | |
| 306 std::string version; | |
| 307 const bool verified = | |
| 308 chrome::ComponentFlashHintFile::VerifyAndReturnFlashLocation( | |
| 309 &flash_path, &version); | |
| 310 // In case the user's home directory is mounted NOEXEC, or the plugin could | |
|
jln (very slow on Chromium)
2015/08/06 18:48:14
s/NOEXEC/noexec/
Greg K
2015/08/07 21:15:28
Done.
| |
| 311 // not be verified, do not use the plugin. | |
|
jln (very slow on Chromium)
2015/08/06 18:48:14
Log an error if !verified?
Greg K
2015/08/07 21:15:28
Yes, although it's misleading because that functio
| |
| 312 if (verified && | |
| 313 chrome::ComponentFlashHintFile::TestExecutableMapping(flash_path)) { | |
|
jln (very slow on Chromium)
2015/08/06 18:48:14
Explain why it's useful to bail early in case we c
Greg K
2015/08/07 21:15:28
Done.
| |
| 314 *plugin = CreatePepperFlashInfo(flash_path, version); | |
| 315 return true; | |
| 316 } | |
| 317 } | |
| 318 return false; | |
| 319 #else | |
| 320 return false; | |
|
jln (very slow on Chromium)
2015/08/06 18:48:14
Nit: return false outside of the #if #else seems a
Greg K
2015/08/07 21:15:28
Done.
| |
| 321 #endif // defined(FLAPPER_AVAILABLE) | |
| 322 } | |
| 323 #endif // defined(OS_LINUX) | |
| 324 | |
| 284 bool GetBundledPepperFlash(content::PepperPluginInfo* plugin) { | 325 bool GetBundledPepperFlash(content::PepperPluginInfo* plugin) { |
| 285 #if defined(FLAPPER_AVAILABLE) | 326 #if defined(FLAPPER_AVAILABLE) |
| 286 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 327 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 287 | 328 |
| 288 // Ignore bundled Pepper Flash if there is Pepper Flash specified from the | 329 // Ignore bundled Pepper Flash if there is Pepper Flash specified from the |
| 289 // command-line. | 330 // command-line. |
| 290 if (command_line->HasSwitch(switches::kPpapiFlashPath)) | 331 if (command_line->HasSwitch(switches::kPpapiFlashPath)) |
| 291 return false; | 332 return false; |
| 292 | 333 |
| 293 bool force_disable = | 334 bool force_disable = |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 457 base::debug::SetCrashKeyValue(crash_keys::kGPURenderer, gpu_info.gl_renderer); | 498 base::debug::SetCrashKeyValue(crash_keys::kGPURenderer, gpu_info.gl_renderer); |
| 458 #endif | 499 #endif |
| 459 } | 500 } |
| 460 | 501 |
| 461 void ChromeContentClient::AddPepperPlugins( | 502 void ChromeContentClient::AddPepperPlugins( |
| 462 std::vector<content::PepperPluginInfo>* plugins) { | 503 std::vector<content::PepperPluginInfo>* plugins) { |
| 463 #if defined(ENABLE_PLUGINS) | 504 #if defined(ENABLE_PLUGINS) |
| 464 ComputeBuiltInPlugins(plugins); | 505 ComputeBuiltInPlugins(plugins); |
| 465 AddPepperFlashFromCommandLine(plugins); | 506 AddPepperFlashFromCommandLine(plugins); |
| 466 | 507 |
| 467 content::PepperPluginInfo plugin; | 508 #if defined(OS_LINUX) |
| 468 if (GetBundledPepperFlash(&plugin)) | 509 // Depending on the sandbox configurtion, the user data directory |
| 469 plugins->push_back(plugin); | 510 // is not always available. If it is not available, do not try and load and |
| 470 if (GetSystemPepperFlash(&plugin)) | 511 // flash plugin. It may incorrectly try to load the system flash plugin in |
| 471 plugins->push_back(plugin); | 512 // this case. |
|
jln (very slow on Chromium)
2015/08/06 18:48:14
What happens in this case? Is it falling back to t
Greg K
2015/08/07 21:15:28
I clarified that it will continue to use whatever
| |
| 472 #endif | 513 if (!IsUserDataDirAvailable()) { |
| 514 return; | |
| 515 } | |
| 516 #endif // defined(OS_LINUX) | |
| 517 | |
| 518 std::vector<content::PepperPluginInfo*> flash_versions; | |
|
jln (very slow on Chromium)
2015/08/06 18:48:14
This is a little strange because this vector will
Greg K
2015/08/07 21:15:28
Done.
| |
| 519 | |
| 520 #if defined(OS_LINUX) | |
| 521 content::PepperPluginInfo component_flash; | |
| 522 if (GetComponentUpdatedPepperFlash(&component_flash)) | |
| 523 flash_versions.push_back(&component_flash); | |
| 524 #endif // defined(OS_LINUX) | |
| 525 | |
| 526 content::PepperPluginInfo bundled_flash; | |
|
jln (very slow on Chromium)
2015/08/06 18:48:14
How is this logic affecting other platforms than L
Greg K
2015/08/07 21:15:28
Will do, answer: it shouldn't affect other platfor
| |
| 527 if (GetBundledPepperFlash(&bundled_flash)) | |
| 528 flash_versions.push_back(&bundled_flash); | |
| 529 | |
| 530 content::PepperPluginInfo system_flash; | |
| 531 if (GetSystemPepperFlash(&system_flash)) | |
| 532 flash_versions.push_back(&system_flash); | |
| 533 | |
| 534 // Now sort the list and add the most recent flash plugin to the plugins list. | |
| 535 std::sort(flash_versions.begin(), flash_versions.end(), | |
|
jln (very slow on Chromium)
2015/08/06 18:48:14
I wonder if version comparison shouldn't be it's o
Greg K
2015/08/07 21:15:28
Done.
| |
| 536 [](content::PepperPluginInfo* x, content::PepperPluginInfo* y) { | |
| 537 Version version_x(x->version); | |
| 538 DCHECK(version_x.IsValid()); | |
| 539 return version_x.IsOlderThan(y->version); | |
| 540 }); | |
| 541 // Use the last element in the list, which will be the most recent flash. | |
| 542 if (flash_versions.size() > 0) | |
|
jln (very slow on Chromium)
2015/08/06 18:48:14
It looks like you only need max_element, not a ful
Greg K
2015/08/07 21:15:28
Done.
| |
| 543 plugins->push_back(*flash_versions.back()); | |
| 544 #endif // defined(ENABLE_PLUGINS) | |
| 473 } | 545 } |
| 474 | 546 |
| 475 void ChromeContentClient::AddAdditionalSchemes( | 547 void ChromeContentClient::AddAdditionalSchemes( |
| 476 std::vector<std::string>* standard_schemes, | 548 std::vector<std::string>* standard_schemes, |
| 477 std::vector<std::string>* savable_schemes) { | 549 std::vector<std::string>* savable_schemes) { |
| 478 standard_schemes->push_back(extensions::kExtensionScheme); | 550 standard_schemes->push_back(extensions::kExtensionScheme); |
| 479 savable_schemes->push_back(extensions::kExtensionScheme); | 551 savable_schemes->push_back(extensions::kExtensionScheme); |
| 480 standard_schemes->push_back(chrome::kChromeNativeScheme); | 552 standard_schemes->push_back(chrome::kChromeNativeScheme); |
| 481 standard_schemes->push_back(extensions::kExtensionResourceScheme); | 553 standard_schemes->push_back(extensions::kExtensionResourceScheme); |
| 482 savable_schemes->push_back(extensions::kExtensionResourceScheme); | 554 savable_schemes->push_back(extensions::kExtensionResourceScheme); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 schemes->insert(content::kChromeUIScheme); | 624 schemes->insert(content::kChromeUIScheme); |
| 553 schemes->insert(extensions::kExtensionScheme); | 625 schemes->insert(extensions::kExtensionScheme); |
| 554 schemes->insert(extensions::kExtensionResourceScheme); | 626 schemes->insert(extensions::kExtensionResourceScheme); |
| 555 GetSecureOriginWhitelist(origins); | 627 GetSecureOriginWhitelist(origins); |
| 556 } | 628 } |
| 557 | 629 |
| 558 void ChromeContentClient::AddServiceWorkerSchemes( | 630 void ChromeContentClient::AddServiceWorkerSchemes( |
| 559 std::set<std::string>* schemes) { | 631 std::set<std::string>* schemes) { |
| 560 schemes->insert(extensions::kExtensionScheme); | 632 schemes->insert(extensions::kExtensionScheme); |
| 561 } | 633 } |
| OLD | NEW |