| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <tuple> |
| 10 | 11 |
| 11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 12 #include "base/debug/crash_logging.h" | 13 #include "base/debug/crash_logging.h" |
| 13 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 14 #include "base/json/json_reader.h" | 15 #include "base/json/json_reader.h" |
| 15 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
| 16 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 17 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 18 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/string_split.h" | 20 #include "base/strings/string_split.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 44 #include "ui/base/layout.h" | 45 #include "ui/base/layout.h" |
| 45 #include "ui/base/resource/resource_bundle.h" | 46 #include "ui/base/resource/resource_bundle.h" |
| 46 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 47 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
| 47 | 48 |
| 48 #if defined(OS_LINUX) | 49 #if defined(OS_LINUX) |
| 49 #include <fcntl.h> | 50 #include <fcntl.h> |
| 50 #include "chrome/common/component_flash_hint_file_linux.h" | 51 #include "chrome/common/component_flash_hint_file_linux.h" |
| 51 #endif // defined(OS_LINUX) | 52 #endif // defined(OS_LINUX) |
| 52 | 53 |
| 53 #if defined(OS_WIN) | 54 #if defined(OS_WIN) |
| 54 #include "base/win/registry.h" | |
| 55 #include "base/win/windows_version.h" | 55 #include "base/win/windows_version.h" |
| 56 #endif | 56 #endif |
| 57 | 57 |
| 58 #if !defined(DISABLE_NACL) | 58 #if !defined(DISABLE_NACL) |
| 59 #include "components/nacl/common/nacl_constants.h" | 59 #include "components/nacl/common/nacl_constants.h" |
| 60 #include "components/nacl/common/nacl_process_type.h" | 60 #include "components/nacl/common/nacl_process_type.h" |
| 61 #include "components/nacl/common/nacl_sandbox_type.h" | 61 #include "components/nacl/common/nacl_sandbox_type.h" |
| 62 #endif | 62 #endif |
| 63 | 63 |
| 64 #if defined(ENABLE_EXTENSIONS) | 64 #if defined(ENABLE_EXTENSIONS) |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 widevine_cdm.permissions = kWidevineCdmPluginPermissions; | 191 widevine_cdm.permissions = kWidevineCdmPluginPermissions; |
| 192 plugins->push_back(widevine_cdm); | 192 plugins->push_back(widevine_cdm); |
| 193 | 193 |
| 194 skip_widevine_cdm_file_check = true; | 194 skip_widevine_cdm_file_check = true; |
| 195 } | 195 } |
| 196 } | 196 } |
| 197 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS) && | 197 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS) && |
| 198 // !defined(WIDEVINE_CDM_IS_COMPONENT) | 198 // !defined(WIDEVINE_CDM_IS_COMPONENT) |
| 199 } | 199 } |
| 200 | 200 |
| 201 // Creates a PepperPluginInfo for the specified plugin. |
| 202 // |path| is the full path to the plugin. |
| 203 // |version| is a string representation of the plugin version. |
| 204 // |is_debug| is whether the plugin is the debug version or not. |
| 205 // |is_external| is whether the plugin is supplied external to Chrome e.g. a |
| 206 // system installation of Adobe Flash. |
| 207 // |is_bundled| distinguishes between component updated plugin and a bundled |
| 208 // plugin. |
| 201 content::PepperPluginInfo CreatePepperFlashInfo(const base::FilePath& path, | 209 content::PepperPluginInfo CreatePepperFlashInfo(const base::FilePath& path, |
| 202 const std::string& version, | 210 const std::string& version, |
| 203 bool is_debug) { | 211 bool is_debug, |
| 212 bool is_external, |
| 213 bool is_bundled) { |
| 204 content::PepperPluginInfo plugin; | 214 content::PepperPluginInfo plugin; |
| 205 | 215 |
| 206 plugin.is_out_of_process = true; | 216 plugin.is_out_of_process = true; |
| 207 plugin.name = content::kFlashPluginName; | 217 plugin.name = content::kFlashPluginName; |
| 208 plugin.path = path; | 218 plugin.path = path; |
| 219 #if defined(OS_WIN) |
| 220 plugin.is_on_local_drive = !base::IsOnNetworkDrive(path); |
| 221 #endif |
| 209 plugin.permissions = chrome::kPepperFlashPermissions; | 222 plugin.permissions = chrome::kPepperFlashPermissions; |
| 210 plugin.is_debug = is_debug; | 223 plugin.is_debug = is_debug; |
| 224 plugin.is_external = is_external; |
| 225 plugin.is_bundled = is_bundled; |
| 211 | 226 |
| 212 std::vector<std::string> flash_version_numbers = base::SplitString( | 227 std::vector<std::string> flash_version_numbers = base::SplitString( |
| 213 version, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | 228 version, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 214 if (flash_version_numbers.size() < 1) | 229 if (flash_version_numbers.size() < 1) |
| 215 flash_version_numbers.push_back("11"); | 230 flash_version_numbers.push_back("11"); |
| 216 if (flash_version_numbers.size() < 2) | 231 if (flash_version_numbers.size() < 2) |
| 217 flash_version_numbers.push_back("2"); | 232 flash_version_numbers.push_back("2"); |
| 218 if (flash_version_numbers.size() < 3) | 233 if (flash_version_numbers.size() < 3) |
| 219 flash_version_numbers.push_back("999"); | 234 flash_version_numbers.push_back("999"); |
| 220 if (flash_version_numbers.size() < 4) | 235 if (flash_version_numbers.size() < 4) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 243 if (flash_path.empty()) | 258 if (flash_path.empty()) |
| 244 return; | 259 return; |
| 245 | 260 |
| 246 // Also get the version from the command-line. Should be something like 11.2 | 261 // Also get the version from the command-line. Should be something like 11.2 |
| 247 // or 11.2.123.45. | 262 // or 11.2.123.45. |
| 248 std::string flash_version = | 263 std::string flash_version = |
| 249 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 264 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 250 switches::kPpapiFlashVersion); | 265 switches::kPpapiFlashVersion); |
| 251 | 266 |
| 252 plugins->push_back( | 267 plugins->push_back( |
| 253 CreatePepperFlashInfo(base::FilePath(flash_path), flash_version, false)); | 268 CreatePepperFlashInfo(base::FilePath(flash_path), |
| 269 flash_version, false, true, false)); |
| 254 } | 270 } |
| 255 | 271 |
| 256 #if defined(OS_LINUX) | 272 #if defined(OS_LINUX) |
| 257 // This function tests if DIR_USER_DATA can be accessed, as a simple check to | 273 // This function tests if DIR_USER_DATA can be accessed, as a simple check to |
| 258 // see if the zygote has been sandboxed at this point. | 274 // see if the zygote has been sandboxed at this point. |
| 259 bool IsUserDataDirAvailable() { | 275 bool IsUserDataDirAvailable() { |
| 260 base::FilePath user_data_dir; | 276 base::FilePath user_data_dir; |
| 261 return PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 277 return PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 262 } | 278 } |
| 263 | 279 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 277 &version)) { | 293 &version)) { |
| 278 // Test if the file can be mapped as executable. If the user's home | 294 // Test if the file can be mapped as executable. If the user's home |
| 279 // directory is mounted noexec, the component flash plugin will not load. | 295 // directory is mounted noexec, the component flash plugin will not load. |
| 280 // By testing for this, Chrome can fallback to the bundled flash plugin. | 296 // By testing for this, Chrome can fallback to the bundled flash plugin. |
| 281 if (!component_flash_hint_file::TestExecutableMapping(flash_path)) { | 297 if (!component_flash_hint_file::TestExecutableMapping(flash_path)) { |
| 282 LOG(WARNING) << "The component updated flash plugin could not be " | 298 LOG(WARNING) << "The component updated flash plugin could not be " |
| 283 "mapped as executable. Attempting to fallback to the " | 299 "mapped as executable. Attempting to fallback to the " |
| 284 "bundled or system plugin."; | 300 "bundled or system plugin."; |
| 285 return false; | 301 return false; |
| 286 } | 302 } |
| 287 *plugin = CreatePepperFlashInfo(flash_path, version, false); | 303 *plugin = CreatePepperFlashInfo(flash_path, version, false, false, false); |
| 288 return true; | 304 return true; |
| 289 } | 305 } |
| 290 LOG(ERROR) | 306 LOG(ERROR) |
| 291 << "Failed to locate and load the component updated flash plugin."; | 307 << "Failed to locate and load the component updated flash plugin."; |
| 292 } | 308 } |
| 293 #endif // defined(FLAPPER_AVAILABLE) | 309 #endif // defined(FLAPPER_AVAILABLE) |
| 294 return false; | 310 return false; |
| 295 } | 311 } |
| 296 #endif // defined(OS_LINUX) | 312 #endif // defined(OS_LINUX) |
| 297 | 313 |
| 298 bool GetBundledPepperFlash(content::PepperPluginInfo* plugin) { | 314 bool GetBundledPepperFlash(content::PepperPluginInfo* plugin) { |
| 299 #if defined(FLAPPER_AVAILABLE) | 315 #if defined(FLAPPER_AVAILABLE) |
| 300 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 316 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 301 | 317 |
| 302 // Ignore bundled Pepper Flash if there is Pepper Flash specified from the | 318 // Ignore bundled Pepper Flash if there is Pepper Flash specified from the |
| 303 // command-line. | 319 // command-line. |
| 304 if (command_line->HasSwitch(switches::kPpapiFlashPath)) | 320 if (command_line->HasSwitch(switches::kPpapiFlashPath)) |
| 305 return false; | 321 return false; |
| 306 | 322 |
| 307 bool force_disable = | 323 bool force_disable = |
| 308 command_line->HasSwitch(switches::kDisableBundledPpapiFlash); | 324 command_line->HasSwitch(switches::kDisableBundledPpapiFlash); |
| 309 if (force_disable) | 325 if (force_disable) |
| 310 return false; | 326 return false; |
| 311 | 327 |
| 312 base::FilePath flash_path; | 328 base::FilePath flash_path; |
| 313 if (!PathService::Get(chrome::FILE_PEPPER_FLASH_PLUGIN, &flash_path)) | 329 if (!PathService::Get(chrome::FILE_PEPPER_FLASH_PLUGIN, &flash_path)) |
| 314 return false; | 330 return false; |
| 315 | 331 |
| 316 *plugin = CreatePepperFlashInfo(flash_path, FLAPPER_VERSION_STRING, false); | 332 *plugin = CreatePepperFlashInfo(flash_path, FLAPPER_VERSION_STRING, false, |
| 333 false, true); |
| 317 return true; | 334 return true; |
| 318 #else | 335 #else |
| 319 return false; | 336 return false; |
| 320 #endif // FLAPPER_AVAILABLE | 337 #endif // FLAPPER_AVAILABLE |
| 321 } | 338 } |
| 322 | 339 |
| 323 bool IsSystemFlashScriptDebuggerPresent() { | |
| 324 #if defined(OS_WIN) | |
| 325 const wchar_t kFlashRegistryRoot[] = | |
| 326 L"SOFTWARE\\Macromedia\\FlashPlayerPepper"; | |
| 327 const wchar_t kIsDebuggerValueName[] = L"isScriptDebugger"; | |
| 328 | |
| 329 base::win::RegKey path_key(HKEY_LOCAL_MACHINE, kFlashRegistryRoot, KEY_READ); | |
| 330 DWORD debug_value; | |
| 331 if (path_key.ReadValueDW(kIsDebuggerValueName, &debug_value) != ERROR_SUCCESS) | |
| 332 return false; | |
| 333 | |
| 334 return (debug_value == 1); | |
| 335 #else | |
| 336 // TODO(wfh): implement this on OS X and Linux. crbug.com/497996. | |
| 337 return false; | |
| 338 #endif | |
| 339 } | |
| 340 | |
| 341 bool GetSystemPepperFlash(content::PepperPluginInfo* plugin) { | 340 bool GetSystemPepperFlash(content::PepperPluginInfo* plugin) { |
| 342 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 341 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 343 bool system_flash_is_debug = IsSystemFlashScriptDebuggerPresent(); | |
| 344 | |
| 345 #if defined(FLAPPER_AVAILABLE) | |
| 346 // If flapper is available, only try the system plugin if either: | |
| 347 // --disable-bundled-ppapi-flash is specified, or the system debugger is the | |
| 348 // Flash Script Debugger. | |
| 349 if (!(command_line->HasSwitch(switches::kDisableBundledPpapiFlash) || | |
| 350 system_flash_is_debug)) { | |
| 351 return false; | |
| 352 } | |
| 353 #endif // defined(FLAPPER_AVAILABLE) | |
| 354 | |
| 355 // Do not try and find System Pepper Flash if there is a specific path on | 342 // Do not try and find System Pepper Flash if there is a specific path on |
| 356 // the commmand-line. | 343 // the commmand-line. |
| 357 if (command_line->HasSwitch(switches::kPpapiFlashPath)) | 344 if (command_line->HasSwitch(switches::kPpapiFlashPath)) |
| 358 return false; | 345 return false; |
| 359 | 346 |
| 360 base::FilePath flash_filename; | 347 base::FilePath flash_filename; |
| 361 if (!PathService::Get(chrome::FILE_PEPPER_FLASH_SYSTEM_PLUGIN, | 348 if (!PathService::Get(chrome::FILE_PEPPER_FLASH_SYSTEM_PLUGIN, |
| 362 &flash_filename)) | 349 &flash_filename)) |
| 363 return false; | 350 return false; |
| 364 | 351 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 376 if (!manifest_value.get()) | 363 if (!manifest_value.get()) |
| 377 return false; | 364 return false; |
| 378 base::DictionaryValue* manifest = NULL; | 365 base::DictionaryValue* manifest = NULL; |
| 379 if (!manifest_value->GetAsDictionary(&manifest)) | 366 if (!manifest_value->GetAsDictionary(&manifest)) |
| 380 return false; | 367 return false; |
| 381 | 368 |
| 382 Version version; | 369 Version version; |
| 383 if (!chrome::CheckPepperFlashManifest(*manifest, &version)) | 370 if (!chrome::CheckPepperFlashManifest(*manifest, &version)) |
| 384 return false; | 371 return false; |
| 385 | 372 |
| 386 *plugin = CreatePepperFlashInfo(flash_filename, version.GetString(), | 373 *plugin = CreatePepperFlashInfo(flash_filename, |
| 387 system_flash_is_debug); | 374 version.GetString(), |
| 375 chrome::IsSystemFlashScriptDebuggerPresent(), |
| 376 true, |
| 377 false); |
| 388 return true; | 378 return true; |
| 389 } | 379 } |
| 390 #endif // defined(ENABLE_PLUGINS) | 380 #endif // defined(ENABLE_PLUGINS) |
| 391 | 381 |
| 392 std::string GetProduct() { | 382 std::string GetProduct() { |
| 393 return version_info::GetProductNameAndVersionForUserAgent(); | 383 return version_info::GetProductNameAndVersionForUserAgent(); |
| 394 } | 384 } |
| 395 | 385 |
| 396 } // namespace | 386 } // namespace |
| 397 | 387 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 #elif defined(OS_POSIX) | 447 #elif defined(OS_POSIX) |
| 458 base::debug::SetCrashKeyValue(crash_keys::kGPUVendor, gpu_info.gl_vendor); | 448 base::debug::SetCrashKeyValue(crash_keys::kGPUVendor, gpu_info.gl_vendor); |
| 459 base::debug::SetCrashKeyValue(crash_keys::kGPURenderer, gpu_info.gl_renderer); | 449 base::debug::SetCrashKeyValue(crash_keys::kGPURenderer, gpu_info.gl_renderer); |
| 460 #endif | 450 #endif |
| 461 } | 451 } |
| 462 | 452 |
| 463 #if defined(ENABLE_PLUGINS) | 453 #if defined(ENABLE_PLUGINS) |
| 464 // static | 454 // static |
| 465 content::PepperPluginInfo* ChromeContentClient::FindMostRecentPlugin( | 455 content::PepperPluginInfo* ChromeContentClient::FindMostRecentPlugin( |
| 466 const std::vector<content::PepperPluginInfo*>& plugins) { | 456 const std::vector<content::PepperPluginInfo*>& plugins) { |
| 467 auto it = std::max_element( | 457 if (plugins.empty()) |
| 468 plugins.begin(), plugins.end(), | 458 return nullptr; |
| 469 [](content::PepperPluginInfo* x, content::PepperPluginInfo* y) { | 459 |
| 470 Version version_x(x->version); | 460 using PluginSortKey = std::tuple<base::Version, bool, bool, bool, bool>; |
| 471 Version version_y(y->version); | 461 |
| 472 DCHECK(version_x.IsValid() && version_y.IsValid()); | 462 std::map<PluginSortKey, content::PepperPluginInfo*> plugin_map; |
| 473 if (version_x == version_y) | 463 |
| 474 return !x->is_debug && y->is_debug; | 464 for (const auto& plugin : plugins) { |
| 475 return version_x < version_y; | 465 Version version(plugin->version); |
| 476 }); | 466 DCHECK(version.IsValid()); |
| 477 return it != plugins.end() ? *it : nullptr; | 467 plugin_map[PluginSortKey(version, plugin->is_debug, |
| 468 plugin->is_bundled, plugin->is_on_local_drive, |
| 469 !plugin->is_external)] = plugin; |
| 470 } |
| 471 |
| 472 return plugin_map.rbegin()->second; |
| 478 } | 473 } |
| 479 #endif // defined(ENABLE_PLUGINS) | 474 #endif // defined(ENABLE_PLUGINS) |
| 480 | 475 |
| 481 void ChromeContentClient::AddPepperPlugins( | 476 void ChromeContentClient::AddPepperPlugins( |
| 482 std::vector<content::PepperPluginInfo>* plugins) { | 477 std::vector<content::PepperPluginInfo>* plugins) { |
| 483 #if defined(ENABLE_PLUGINS) | 478 #if defined(ENABLE_PLUGINS) |
| 484 ComputeBuiltInPlugins(plugins); | 479 ComputeBuiltInPlugins(plugins); |
| 485 AddPepperFlashFromCommandLine(plugins); | 480 AddPepperFlashFromCommandLine(plugins); |
| 486 | 481 |
| 487 #if defined(OS_LINUX) | 482 #if defined(OS_LINUX) |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 #if defined(ENABLE_EXTENSIONS) | 635 #if defined(ENABLE_EXTENSIONS) |
| 641 return extensions::IsIsolateExtensionsEnabled(); | 636 return extensions::IsIsolateExtensionsEnabled(); |
| 642 #else | 637 #else |
| 643 return false; | 638 return false; |
| 644 #endif | 639 #endif |
| 645 } | 640 } |
| 646 | 641 |
| 647 base::StringPiece ChromeContentClient::GetOriginTrialPublicKey() { | 642 base::StringPiece ChromeContentClient::GetOriginTrialPublicKey() { |
| 648 return origin_trial_key_manager_.GetPublicKey(); | 643 return origin_trial_key_manager_.GetPublicKey(); |
| 649 } | 644 } |
| OLD | NEW |