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