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