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 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/debug/crash_logging.h" | 12 #include "base/debug/crash_logging.h" |
13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
14 #include "base/json/json_reader.h" | 14 #include "base/json/json_reader.h" |
15 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
17 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
23 #include "base/tuple.h" | |
23 #include "build/build_config.h" | 24 #include "build/build_config.h" |
24 #include "chrome/common/child_process_logging.h" | 25 #include "chrome/common/child_process_logging.h" |
25 #include "chrome/common/chrome_constants.h" | 26 #include "chrome/common/chrome_constants.h" |
26 #include "chrome/common/chrome_paths.h" | 27 #include "chrome/common/chrome_paths.h" |
27 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
28 #include "chrome/common/crash_keys.h" | 29 #include "chrome/common/crash_keys.h" |
29 #include "chrome/common/pepper_flash.h" | 30 #include "chrome/common/pepper_flash.h" |
30 #include "chrome/common/secure_origin_whitelist.h" | 31 #include "chrome/common/secure_origin_whitelist.h" |
31 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
32 #include "chrome/grit/common_resources.h" | 33 #include "chrome/grit/common_resources.h" |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 widevine_cdm.permissions = kWidevineCdmPluginPermissions; | 192 widevine_cdm.permissions = kWidevineCdmPluginPermissions; |
192 plugins->push_back(widevine_cdm); | 193 plugins->push_back(widevine_cdm); |
193 | 194 |
194 skip_widevine_cdm_file_check = true; | 195 skip_widevine_cdm_file_check = true; |
195 } | 196 } |
196 } | 197 } |
197 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS) && | 198 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS) && |
198 // !defined(WIDEVINE_CDM_IS_COMPONENT) | 199 // !defined(WIDEVINE_CDM_IS_COMPONENT) |
199 } | 200 } |
200 | 201 |
202 // Creates a PepperPluginInfo for the specified plugin. | |
203 // |path| is the full path to the plugin. | |
204 // |version| is a string representation of the plugin version. | |
205 // |is_debug| is whether the plugin is the debug version or not. | |
206 // |is_external| is whether the plugin is supplied external to Chrome e.g. a | |
207 // system installation of Adobe Flash. | |
208 // |is_bundled| distinguishes between component updated plugin and a bundled | |
209 // plugin. | |
201 content::PepperPluginInfo CreatePepperFlashInfo(const base::FilePath& path, | 210 content::PepperPluginInfo CreatePepperFlashInfo(const base::FilePath& path, |
202 const std::string& version, | 211 const std::string& version, |
203 bool is_debug) { | 212 bool is_debug, |
213 bool is_external, | |
214 bool is_bundled) { | |
204 content::PepperPluginInfo plugin; | 215 content::PepperPluginInfo plugin; |
205 | 216 |
206 plugin.is_out_of_process = true; | 217 plugin.is_out_of_process = true; |
207 plugin.name = content::kFlashPluginName; | 218 plugin.name = content::kFlashPluginName; |
208 plugin.path = path; | 219 plugin.path = path; |
220 #if defined(OS_WIN) | |
221 plugin.is_on_local_drive = !base::IsOnNetworkDrive(path); | |
222 #endif | |
209 plugin.permissions = chrome::kPepperFlashPermissions; | 223 plugin.permissions = chrome::kPepperFlashPermissions; |
210 plugin.is_debug = is_debug; | 224 plugin.is_debug = is_debug; |
225 plugin.is_external = is_external; | |
226 plugin.is_bundled = is_bundled; | |
211 | 227 |
212 std::vector<std::string> flash_version_numbers = base::SplitString( | 228 std::vector<std::string> flash_version_numbers = base::SplitString( |
213 version, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | 229 version, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
214 if (flash_version_numbers.size() < 1) | 230 if (flash_version_numbers.size() < 1) |
215 flash_version_numbers.push_back("11"); | 231 flash_version_numbers.push_back("11"); |
216 if (flash_version_numbers.size() < 2) | 232 if (flash_version_numbers.size() < 2) |
217 flash_version_numbers.push_back("2"); | 233 flash_version_numbers.push_back("2"); |
218 if (flash_version_numbers.size() < 3) | 234 if (flash_version_numbers.size() < 3) |
219 flash_version_numbers.push_back("999"); | 235 flash_version_numbers.push_back("999"); |
220 if (flash_version_numbers.size() < 4) | 236 if (flash_version_numbers.size() < 4) |
(...skipping 22 matching lines...) Expand all Loading... | |
243 if (flash_path.empty()) | 259 if (flash_path.empty()) |
244 return; | 260 return; |
245 | 261 |
246 // Also get the version from the command-line. Should be something like 11.2 | 262 // Also get the version from the command-line. Should be something like 11.2 |
247 // or 11.2.123.45. | 263 // or 11.2.123.45. |
248 std::string flash_version = | 264 std::string flash_version = |
249 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 265 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
250 switches::kPpapiFlashVersion); | 266 switches::kPpapiFlashVersion); |
251 | 267 |
252 plugins->push_back( | 268 plugins->push_back( |
253 CreatePepperFlashInfo(base::FilePath(flash_path), flash_version, false)); | 269 CreatePepperFlashInfo(base::FilePath(flash_path), |
270 flash_version, false, true, false)); | |
254 } | 271 } |
255 | 272 |
256 #if defined(OS_LINUX) | 273 #if defined(OS_LINUX) |
257 // This function tests if DIR_USER_DATA can be accessed, as a simple check to | 274 // 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. | 275 // see if the zygote has been sandboxed at this point. |
259 bool IsUserDataDirAvailable() { | 276 bool IsUserDataDirAvailable() { |
260 base::FilePath user_data_dir; | 277 base::FilePath user_data_dir; |
261 return PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 278 return PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
262 } | 279 } |
263 | 280 |
(...skipping 13 matching lines...) Expand all Loading... | |
277 &version)) { | 294 &version)) { |
278 // Test if the file can be mapped as executable. If the user's home | 295 // 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. | 296 // directory is mounted noexec, the component flash plugin will not load. |
280 // By testing for this, Chrome can fallback to the bundled flash plugin. | 297 // By testing for this, Chrome can fallback to the bundled flash plugin. |
281 if (!component_flash_hint_file::TestExecutableMapping(flash_path)) { | 298 if (!component_flash_hint_file::TestExecutableMapping(flash_path)) { |
282 LOG(WARNING) << "The component updated flash plugin could not be " | 299 LOG(WARNING) << "The component updated flash plugin could not be " |
283 "mapped as executable. Attempting to fallback to the " | 300 "mapped as executable. Attempting to fallback to the " |
284 "bundled or system plugin."; | 301 "bundled or system plugin."; |
285 return false; | 302 return false; |
286 } | 303 } |
287 *plugin = CreatePepperFlashInfo(flash_path, version, false); | 304 *plugin = CreatePepperFlashInfo(flash_path, version, false, false, false); |
288 return true; | 305 return true; |
289 } | 306 } |
290 LOG(ERROR) | 307 LOG(ERROR) |
291 << "Failed to locate and load the component updated flash plugin."; | 308 << "Failed to locate and load the component updated flash plugin."; |
292 } | 309 } |
293 #endif // defined(FLAPPER_AVAILABLE) | 310 #endif // defined(FLAPPER_AVAILABLE) |
294 return false; | 311 return false; |
295 } | 312 } |
296 #endif // defined(OS_LINUX) | 313 #endif // defined(OS_LINUX) |
297 | 314 |
298 bool GetBundledPepperFlash(content::PepperPluginInfo* plugin) { | 315 bool GetBundledPepperFlash(content::PepperPluginInfo* plugin) { |
299 #if defined(FLAPPER_AVAILABLE) | 316 #if defined(FLAPPER_AVAILABLE) |
300 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 317 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
301 | 318 |
302 // Ignore bundled Pepper Flash if there is Pepper Flash specified from the | 319 // Ignore bundled Pepper Flash if there is Pepper Flash specified from the |
303 // command-line. | 320 // command-line. |
304 if (command_line->HasSwitch(switches::kPpapiFlashPath)) | 321 if (command_line->HasSwitch(switches::kPpapiFlashPath)) |
305 return false; | 322 return false; |
306 | 323 |
307 bool force_disable = | 324 bool force_disable = |
308 command_line->HasSwitch(switches::kDisableBundledPpapiFlash); | 325 command_line->HasSwitch(switches::kDisableBundledPpapiFlash); |
309 if (force_disable) | 326 if (force_disable) |
310 return false; | 327 return false; |
311 | 328 |
312 base::FilePath flash_path; | 329 base::FilePath flash_path; |
313 if (!PathService::Get(chrome::FILE_PEPPER_FLASH_PLUGIN, &flash_path)) | 330 if (!PathService::Get(chrome::FILE_PEPPER_FLASH_PLUGIN, &flash_path)) |
314 return false; | 331 return false; |
315 | 332 |
316 *plugin = CreatePepperFlashInfo(flash_path, FLAPPER_VERSION_STRING, false); | 333 *plugin = CreatePepperFlashInfo(flash_path, FLAPPER_VERSION_STRING, false, |
334 false, true); | |
317 return true; | 335 return true; |
318 #else | 336 #else |
319 return false; | 337 return false; |
320 #endif // FLAPPER_AVAILABLE | 338 #endif // FLAPPER_AVAILABLE |
321 } | 339 } |
322 | 340 |
323 bool IsSystemFlashScriptDebuggerPresent() { | 341 bool IsSystemFlashScriptDebuggerPresent() { |
324 #if defined(OS_WIN) | 342 #if defined(OS_WIN) |
325 const wchar_t kFlashRegistryRoot[] = | 343 const wchar_t kFlashRegistryRoot[] = |
326 L"SOFTWARE\\Macromedia\\FlashPlayerPepper"; | 344 L"SOFTWARE\\Macromedia\\FlashPlayerPepper"; |
327 const wchar_t kIsDebuggerValueName[] = L"isScriptDebugger"; | 345 const wchar_t kIsDebuggerValueName[] = L"isScriptDebugger"; |
328 | 346 |
329 base::win::RegKey path_key(HKEY_LOCAL_MACHINE, kFlashRegistryRoot, KEY_READ); | 347 base::win::RegKey path_key(HKEY_LOCAL_MACHINE, kFlashRegistryRoot, KEY_READ); |
330 DWORD debug_value; | 348 DWORD debug_value; |
331 if (path_key.ReadValueDW(kIsDebuggerValueName, &debug_value) != ERROR_SUCCESS) | 349 if (path_key.ReadValueDW(kIsDebuggerValueName, &debug_value) != ERROR_SUCCESS) |
332 return false; | 350 return false; |
333 | 351 |
334 return (debug_value == 1); | 352 return (debug_value == 1); |
335 #else | 353 #else |
336 // TODO(wfh): implement this on OS X and Linux. crbug.com/497996. | 354 // TODO(wfh): implement this on OS X and Linux. crbug.com/497996. |
337 return false; | 355 return false; |
338 #endif | 356 #endif |
339 } | 357 } |
340 | 358 |
341 bool GetSystemPepperFlash(content::PepperPluginInfo* plugin) { | 359 bool GetSystemPepperFlash(content::PepperPluginInfo* plugin) { |
342 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 360 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 | 361 // Do not try and find System Pepper Flash if there is a specific path on |
356 // the commmand-line. | 362 // the commmand-line. |
357 if (command_line->HasSwitch(switches::kPpapiFlashPath)) | 363 if (command_line->HasSwitch(switches::kPpapiFlashPath)) |
358 return false; | 364 return false; |
359 | 365 |
360 base::FilePath flash_filename; | 366 base::FilePath flash_filename; |
361 if (!PathService::Get(chrome::FILE_PEPPER_FLASH_SYSTEM_PLUGIN, | 367 if (!PathService::Get(chrome::FILE_PEPPER_FLASH_SYSTEM_PLUGIN, |
362 &flash_filename)) | 368 &flash_filename)) |
363 return false; | 369 return false; |
364 | 370 |
(...skipping 11 matching lines...) Expand all Loading... | |
376 if (!manifest_value.get()) | 382 if (!manifest_value.get()) |
377 return false; | 383 return false; |
378 base::DictionaryValue* manifest = NULL; | 384 base::DictionaryValue* manifest = NULL; |
379 if (!manifest_value->GetAsDictionary(&manifest)) | 385 if (!manifest_value->GetAsDictionary(&manifest)) |
380 return false; | 386 return false; |
381 | 387 |
382 Version version; | 388 Version version; |
383 if (!chrome::CheckPepperFlashManifest(*manifest, &version)) | 389 if (!chrome::CheckPepperFlashManifest(*manifest, &version)) |
384 return false; | 390 return false; |
385 | 391 |
386 *plugin = CreatePepperFlashInfo(flash_filename, version.GetString(), | 392 *plugin = CreatePepperFlashInfo(flash_filename, |
387 system_flash_is_debug); | 393 version.GetString(), |
394 IsSystemFlashScriptDebuggerPresent(), | |
395 true, | |
396 false); | |
388 return true; | 397 return true; |
389 } | 398 } |
390 #endif // defined(ENABLE_PLUGINS) | 399 #endif // defined(ENABLE_PLUGINS) |
391 | 400 |
392 std::string GetProduct() { | 401 std::string GetProduct() { |
393 return version_info::GetProductNameAndVersionForUserAgent(); | 402 return version_info::GetProductNameAndVersionForUserAgent(); |
394 } | 403 } |
395 | 404 |
396 } // namespace | 405 } // namespace |
397 | 406 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
457 #elif defined(OS_POSIX) | 466 #elif defined(OS_POSIX) |
458 base::debug::SetCrashKeyValue(crash_keys::kGPUVendor, gpu_info.gl_vendor); | 467 base::debug::SetCrashKeyValue(crash_keys::kGPUVendor, gpu_info.gl_vendor); |
459 base::debug::SetCrashKeyValue(crash_keys::kGPURenderer, gpu_info.gl_renderer); | 468 base::debug::SetCrashKeyValue(crash_keys::kGPURenderer, gpu_info.gl_renderer); |
460 #endif | 469 #endif |
461 } | 470 } |
462 | 471 |
463 #if defined(ENABLE_PLUGINS) | 472 #if defined(ENABLE_PLUGINS) |
464 // static | 473 // static |
465 content::PepperPluginInfo* ChromeContentClient::FindMostRecentPlugin( | 474 content::PepperPluginInfo* ChromeContentClient::FindMostRecentPlugin( |
466 const std::vector<content::PepperPluginInfo*>& plugins) { | 475 const std::vector<content::PepperPluginInfo*>& plugins) { |
467 auto it = std::max_element( | 476 if (plugins.empty()) |
468 plugins.begin(), plugins.end(), | 477 return nullptr; |
469 [](content::PepperPluginInfo* x, content::PepperPluginInfo* y) { | 478 |
470 Version version_x(x->version); | 479 using PluginSortKey = base::Tuple<base::Version, bool, bool, bool, bool>; |
471 Version version_y(y->version); | 480 |
472 DCHECK(version_x.IsValid() && version_y.IsValid()); | 481 std::map<PluginSortKey, content::PepperPluginInfo*> plugin_map; |
473 if (version_x == version_y) | 482 |
474 return !x->is_debug && y->is_debug; | 483 for (const auto& plugin : plugins) |
475 return version_x < version_y; | 484 plugin_map[PluginSortKey(Version(plugin->version), plugin->is_debug, |
476 }); | 485 plugin->is_bundled, plugin->is_on_local_drive, |
477 return it != plugins.end() ? *it : nullptr; | 486 !plugin->is_external)] = plugin; |
487 | |
488 return plugin_map.rbegin()->second; | |
cpu_(ooo_6.6-7.5)
2016/04/20 19:23:14
mmm... clever but obscure, I don't know what the l
Will Harris
2016/04/20 23:50:21
yup less is implemented by "Compares lhs and rhs l
| |
478 } | 489 } |
479 #endif // defined(ENABLE_PLUGINS) | 490 #endif // defined(ENABLE_PLUGINS) |
480 | 491 |
481 void ChromeContentClient::AddPepperPlugins( | 492 void ChromeContentClient::AddPepperPlugins( |
482 std::vector<content::PepperPluginInfo>* plugins) { | 493 std::vector<content::PepperPluginInfo>* plugins) { |
483 #if defined(ENABLE_PLUGINS) | 494 #if defined(ENABLE_PLUGINS) |
484 ComputeBuiltInPlugins(plugins); | 495 ComputeBuiltInPlugins(plugins); |
485 AddPepperFlashFromCommandLine(plugins); | 496 AddPepperFlashFromCommandLine(plugins); |
486 | 497 |
487 #if defined(OS_LINUX) | 498 #if defined(OS_LINUX) |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
640 #if defined(ENABLE_EXTENSIONS) | 651 #if defined(ENABLE_EXTENSIONS) |
641 return extensions::IsIsolateExtensionsEnabled(); | 652 return extensions::IsIsolateExtensionsEnabled(); |
642 #else | 653 #else |
643 return false; | 654 return false; |
644 #endif | 655 #endif |
645 } | 656 } |
646 | 657 |
647 base::StringPiece ChromeContentClient::GetOriginTrialPublicKey() { | 658 base::StringPiece ChromeContentClient::GetOriginTrialPublicKey() { |
648 return origin_trial_key_manager_.GetPublicKey(); | 659 return origin_trial_key_manager_.GetPublicKey(); |
649 } | 660 } |
OLD | NEW |