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_linux.h" | |
Lei Zhang
2015/08/14 22:37:07
Rather than including this header here and putting
Greg K
2015/08/17 21:11:57
Done.
| |
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); | |
Lei Zhang
2015/08/14 22:37:07
This isn't necessary. See the DIR_USER_DATA handli
Greg K
2015/08/17 21:11:57
Done.
| |
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::component_flash_hint_file::DoesHintFileExist()) { | |
308 base::FilePath flash_path; | |
309 std::string version; | |
310 if (chrome::component_flash_hint_file::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::component_flash_hint_file::TestExecutableMapping( | |
316 flash_path)) { | |
317 LOG(WARNING) << "The component updated flash plugin could not be " | |
318 "mapped as executable. Attempting to fallback to the " | |
319 "bundled or system plugin."; | |
320 return false; | |
321 } | |
322 *plugin = CreatePepperFlashInfo(flash_path, version); | |
323 return true; | |
324 } else { | |
Lei Zhang
2015/08/14 22:37:07
no need for else if the ablove block returns.
Greg K
2015/08/17 21:11:56
Done.
| |
325 LOG(ERROR) | |
326 << "Failed to locate and load the component updated flash plugin."; | |
327 } | |
328 } | |
329 #endif // defined(FLAPPER_AVAILABLE) | |
330 return false; | |
331 } | |
332 #endif // defined(OS_LINUX) | |
333 | |
284 bool GetBundledPepperFlash(content::PepperPluginInfo* plugin) { | 334 bool GetBundledPepperFlash(content::PepperPluginInfo* plugin) { |
285 #if defined(FLAPPER_AVAILABLE) | 335 #if defined(FLAPPER_AVAILABLE) |
286 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 336 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
287 | 337 |
288 // Ignore bundled Pepper Flash if there is Pepper Flash specified from the | 338 // Ignore bundled Pepper Flash if there is Pepper Flash specified from the |
289 // command-line. | 339 // command-line. |
290 if (command_line->HasSwitch(switches::kPpapiFlashPath)) | 340 if (command_line->HasSwitch(switches::kPpapiFlashPath)) |
291 return false; | 341 return false; |
292 | 342 |
293 bool force_disable = | 343 bool force_disable = |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
451 base::debug::SetCrashKeyValue(crash_keys::kGPUVertexShaderVersion, | 501 base::debug::SetCrashKeyValue(crash_keys::kGPUVertexShaderVersion, |
452 gpu_info.vertex_shader_version); | 502 gpu_info.vertex_shader_version); |
453 #if defined(OS_MACOSX) | 503 #if defined(OS_MACOSX) |
454 base::debug::SetCrashKeyValue(crash_keys::kGPUGLVersion, gpu_info.gl_version); | 504 base::debug::SetCrashKeyValue(crash_keys::kGPUGLVersion, gpu_info.gl_version); |
455 #elif defined(OS_POSIX) | 505 #elif defined(OS_POSIX) |
456 base::debug::SetCrashKeyValue(crash_keys::kGPUVendor, gpu_info.gl_vendor); | 506 base::debug::SetCrashKeyValue(crash_keys::kGPUVendor, gpu_info.gl_vendor); |
457 base::debug::SetCrashKeyValue(crash_keys::kGPURenderer, gpu_info.gl_renderer); | 507 base::debug::SetCrashKeyValue(crash_keys::kGPURenderer, gpu_info.gl_renderer); |
458 #endif | 508 #endif |
459 } | 509 } |
460 | 510 |
511 #if defined(ENABLE_PLUGINS) | |
512 // static | |
513 content::PepperPluginInfo* ChromeContentClient::FindMostRecentPlugin( | |
514 const std::vector<content::PepperPluginInfo*>& plugins) { | |
515 content::PepperPluginInfo* result = nullptr; | |
516 auto it = std::max_element( | |
517 plugins.begin(), plugins.end(), | |
518 [](content::PepperPluginInfo* x, content::PepperPluginInfo* y) { | |
519 Version version_x(x->version); | |
520 DCHECK(version_x.IsValid()); | |
521 return version_x.IsOlderThan(y->version); | |
522 }); | |
523 if (it != plugins.end()) | |
524 result = *it; | |
525 return result; | |
Lei Zhang
2015/08/14 22:37:07
You can use a ternary operator and not even bother
Greg K
2015/08/17 21:11:57
Done.
| |
526 } | |
527 #endif // defined(ENABLE_PLUGINS) | |
528 | |
461 void ChromeContentClient::AddPepperPlugins( | 529 void ChromeContentClient::AddPepperPlugins( |
462 std::vector<content::PepperPluginInfo>* plugins) { | 530 std::vector<content::PepperPluginInfo>* plugins) { |
463 #if defined(ENABLE_PLUGINS) | 531 #if defined(ENABLE_PLUGINS) |
464 ComputeBuiltInPlugins(plugins); | 532 ComputeBuiltInPlugins(plugins); |
465 AddPepperFlashFromCommandLine(plugins); | 533 AddPepperFlashFromCommandLine(plugins); |
466 | 534 |
467 content::PepperPluginInfo plugin; | 535 #if defined(OS_LINUX) |
468 if (GetBundledPepperFlash(&plugin)) | 536 // Depending on the sandbox configurtion, the user data directory |
469 plugins->push_back(plugin); | 537 // is not always available. If it is not available, do not try and load any |
470 if (GetSystemPepperFlash(&plugin)) | 538 // flash plugin. The flash player, if any, preloaded before the sandbox |
471 plugins->push_back(plugin); | 539 // initialization will continue to be used. |
472 #endif | 540 if (!IsUserDataDirAvailable()) { |
541 return; | |
542 } | |
543 #endif // defined(OS_LINUX) | |
544 | |
545 ScopedVector<content::PepperPluginInfo> flash_versions; | |
546 | |
547 #if defined(OS_LINUX) | |
548 scoped_ptr<content::PepperPluginInfo> component_flash( | |
549 new content::PepperPluginInfo); | |
550 if (GetComponentUpdatedPepperFlash(component_flash.get())) | |
551 flash_versions.push_back(component_flash.release()); | |
552 #endif // defined(OS_LINUX) | |
553 | |
554 scoped_ptr<content::PepperPluginInfo> bundled_flash( | |
555 new content::PepperPluginInfo); | |
556 if (GetBundledPepperFlash(bundled_flash.get())) | |
557 flash_versions.push_back(bundled_flash.release()); | |
558 | |
559 scoped_ptr<content::PepperPluginInfo> system_flash( | |
560 new content::PepperPluginInfo); | |
561 if (GetSystemPepperFlash(system_flash.get())) | |
562 flash_versions.push_back(system_flash.release()); | |
563 | |
564 // This function will return only the most recent version of the flash plugin. | |
565 content::PepperPluginInfo* max_flash = | |
566 FindMostRecentPlugin(flash_versions.get()); | |
567 if (max_flash != nullptr) | |
Lei Zhang
2015/08/14 22:37:07
just if (max_flash)
Greg K
2015/08/17 21:11:57
Done.
| |
568 plugins->push_back(*max_flash); | |
569 #endif // defined(ENABLE_PLUGINS) | |
473 } | 570 } |
474 | 571 |
475 void ChromeContentClient::AddAdditionalSchemes( | 572 void ChromeContentClient::AddAdditionalSchemes( |
476 std::vector<std::string>* standard_schemes, | 573 std::vector<std::string>* standard_schemes, |
477 std::vector<std::string>* savable_schemes) { | 574 std::vector<std::string>* savable_schemes) { |
478 standard_schemes->push_back(extensions::kExtensionScheme); | 575 standard_schemes->push_back(extensions::kExtensionScheme); |
479 savable_schemes->push_back(extensions::kExtensionScheme); | 576 savable_schemes->push_back(extensions::kExtensionScheme); |
480 standard_schemes->push_back(chrome::kChromeNativeScheme); | 577 standard_schemes->push_back(chrome::kChromeNativeScheme); |
481 standard_schemes->push_back(extensions::kExtensionResourceScheme); | 578 standard_schemes->push_back(extensions::kExtensionResourceScheme); |
482 savable_schemes->push_back(extensions::kExtensionResourceScheme); | 579 savable_schemes->push_back(extensions::kExtensionResourceScheme); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
552 schemes->insert(content::kChromeUIScheme); | 649 schemes->insert(content::kChromeUIScheme); |
553 schemes->insert(extensions::kExtensionScheme); | 650 schemes->insert(extensions::kExtensionScheme); |
554 schemes->insert(extensions::kExtensionResourceScheme); | 651 schemes->insert(extensions::kExtensionResourceScheme); |
555 GetSecureOriginWhitelist(origins); | 652 GetSecureOriginWhitelist(origins); |
556 } | 653 } |
557 | 654 |
558 void ChromeContentClient::AddServiceWorkerSchemes( | 655 void ChromeContentClient::AddServiceWorkerSchemes( |
559 std::set<std::string>* schemes) { | 656 std::set<std::string>* schemes) { |
560 schemes->insert(extensions::kExtensionScheme); | 657 schemes->insert(extensions::kExtensionScheme); |
561 } | 658 } |
OLD | NEW |