Chromium Code Reviews| 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/browser/plugins/plugin_prefs.h" | 5 #include "chrome/browser/plugins/plugin_prefs.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 if (PathService::Get(chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN, | 52 if (PathService::Get(chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN, |
| 53 &component_updated_pepper_flash_dir) && | 53 &component_updated_pepper_flash_dir) && |
| 54 component_updated_pepper_flash_dir.IsParent(plugin)) { | 54 component_updated_pepper_flash_dir.IsParent(plugin)) { |
| 55 return true; | 55 return true; |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 return false; | 59 return false; |
| 60 } | 60 } |
| 61 | 61 |
| 62 // Returns true if |path| looks like the path to an NPAPI Flash plugin. | |
| 63 bool IsNpapiFlashPath(const base::FilePath& path) { | |
| 64 base::FilePath npapi_flash; | |
| 65 // Check NPAPI Flash is installed. | |
| 66 if (!PathService::Get(chrome::FILE_FLASH_SYSTEM_PLUGIN, &npapi_flash)) | |
| 67 return false; | |
| 68 // Check for same architecture NPAPI Flash. | |
| 69 if (base::FilePath::CompareEqualIgnoreCase(path.value(), npapi_flash.value())) | |
| 70 return true; | |
| 71 #if defined(OS_WIN) | |
| 72 // Fuzzy check for NPAPI Flash on Windows. | |
| 73 base::FilePath::StringType kSwfPrefix = FILE_PATH_LITERAL("NPSWF"); | |
| 74 if (path.BaseName().value().compare(0, kSwfPrefix.size(), kSwfPrefix) == 0) | |
| 75 return true; | |
| 76 #endif | |
| 77 return false; | |
| 78 } | |
| 79 | |
| 80 } // namespace | 62 } // namespace |
| 81 | 63 |
| 82 PluginPrefs::PluginState::PluginState() { | 64 PluginPrefs::PluginState::PluginState() { |
| 83 } | 65 } |
| 84 | 66 |
| 85 PluginPrefs::PluginState::~PluginState() { | 67 PluginPrefs::PluginState::~PluginState() { |
| 86 } | 68 } |
| 87 | 69 |
| 88 bool PluginPrefs::PluginState::Get(const base::FilePath& plugin, | 70 bool PluginPrefs::PluginState::Get(const base::FilePath& plugin, |
| 89 bool* enabled) const { | 71 bool* enabled) const { |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 base::FilePath last_internal_dir = | 321 base::FilePath last_internal_dir = |
| 340 prefs_->GetFilePath(prefs::kPluginsLastInternalDirectory); | 322 prefs_->GetFilePath(prefs::kPluginsLastInternalDirectory); |
| 341 base::FilePath cur_internal_dir; | 323 base::FilePath cur_internal_dir; |
| 342 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &cur_internal_dir) && | 324 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &cur_internal_dir) && |
| 343 cur_internal_dir != last_internal_dir) { | 325 cur_internal_dir != last_internal_dir) { |
| 344 update_internal_dir = true; | 326 update_internal_dir = true; |
| 345 prefs_->SetFilePath( | 327 prefs_->SetFilePath( |
| 346 prefs::kPluginsLastInternalDirectory, cur_internal_dir); | 328 prefs::kPluginsLastInternalDirectory, cur_internal_dir); |
| 347 } | 329 } |
| 348 | 330 |
| 349 bool migrate_to_pepper_flash = false; | |
| 350 #if defined(OS_WIN) || defined(OS_MACOSX) | |
| 351 // If NPAPI Flash is enabled while Pepper Flash is disabled, we would like to | |
| 352 // turn Pepper Flash on. And we want to do it once, when NPAPI is disabled in | |
| 353 // Chrome 45. | |
| 354 // TODO(wfh): Remove this code once it has been run by most users, around | |
| 355 // Chrome 49 or Chrome 50. See crbug.com/514250. | |
| 356 if (!prefs_->GetBoolean(prefs::kNpapiFlashMigratedToPepperFlash)) { | |
| 357 prefs_->SetBoolean(prefs::kNpapiFlashMigratedToPepperFlash, true); | |
| 358 migrate_to_pepper_flash = true; | |
| 359 } | |
| 360 #endif | |
| 361 | |
| 362 { // Scoped update of prefs::kPluginsPluginsList. | 331 { // Scoped update of prefs::kPluginsPluginsList. |
| 363 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); | 332 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); |
| 364 base::ListValue* saved_plugins_list = update.Get(); | 333 base::ListValue* saved_plugins_list = update.Get(); |
| 365 if (saved_plugins_list && !saved_plugins_list->empty()) { | 334 if (saved_plugins_list && !saved_plugins_list->empty()) { |
| 366 // The following four variables are only valid when | 335 for (base::Value* plugin_value : *saved_plugins_list) { |
| 367 // |migrate_to_pepper_flash| is set to true. | 336 if (!plugin_value->IsType(base::Value::TYPE_DICTIONARY)) { |
| 368 base::FilePath pepper_flash; | |
| 369 base::DictionaryValue* pepper_flash_node = NULL; | |
| 370 bool npapi_flash_enabled = false; | |
| 371 if (migrate_to_pepper_flash) { | |
| 372 PathService::Get(chrome::FILE_PEPPER_FLASH_PLUGIN, &pepper_flash); | |
| 373 } | |
| 374 | |
| 375 for (base::ListValue::iterator it = saved_plugins_list->begin(); | |
| 376 it != saved_plugins_list->end(); | |
| 377 ++it) { | |
| 378 if (!(*it)->IsType(base::Value::TYPE_DICTIONARY)) { | |
| 379 LOG(WARNING) << "Invalid entry in " << prefs::kPluginsPluginsList; | 337 LOG(WARNING) << "Invalid entry in " << prefs::kPluginsPluginsList; |
| 380 continue; // Oops, don't know what to do with this item. | 338 continue; // Oops, don't know what to do with this item. |
| 381 } | 339 } |
| 382 | 340 |
| 383 base::DictionaryValue* plugin = | 341 base::DictionaryValue* plugin = |
| 384 static_cast<base::DictionaryValue*>(*it); | 342 reinterpret_cast<base::DictionaryValue*>(plugin_value); |
|
Will Harris
2016/01/27 02:17:01
some code uses reinterpret_cast and some uses stat
Bernhard Bauer
2016/01/27 15:51:43
Urr... no, I think static_cast is the correct one
Will Harris
2016/01/27 17:03:51
okay thanks! Should go and fix these or are these
Bernhard Bauer
2016/01/27 17:08:38
Uh, both? 😄 I think they are effectively safe for
| |
| 385 base::string16 group_name; | 343 base::string16 group_name; |
| 386 bool enabled; | 344 bool enabled; |
| 387 if (!plugin->GetBoolean("enabled", &enabled)) | 345 if (!plugin->GetBoolean("enabled", &enabled)) |
| 388 enabled = true; | 346 enabled = true; |
| 389 | 347 |
| 390 base::FilePath::StringType path; | 348 base::FilePath::StringType path; |
| 391 // The plugin list constains all the plugin files in addition to the | 349 // The plugin list constains all the plugin files in addition to the |
| 392 // plugin groups. | 350 // plugin groups. |
| 393 if (plugin->GetString("path", &path)) { | 351 if (plugin->GetString("path", &path)) { |
| 394 // Files have a path attribute, groups don't. | 352 // Files have a path attribute, groups don't. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 | 384 |
| 427 // If |relative_path| is empty, |plugin_path| is not within | 385 // If |relative_path| is empty, |plugin_path| is not within |
| 428 // |last_internal_dir|. We don't need to update it. | 386 // |last_internal_dir|. We don't need to update it. |
| 429 if (!relative_path.empty()) { | 387 if (!relative_path.empty()) { |
| 430 plugin_path = cur_internal_dir.Append(relative_path); | 388 plugin_path = cur_internal_dir.Append(relative_path); |
| 431 path = plugin_path.value(); | 389 path = plugin_path.value(); |
| 432 plugin->SetString("path", path); | 390 plugin->SetString("path", path); |
| 433 } | 391 } |
| 434 } | 392 } |
| 435 | 393 |
| 436 if (migrate_to_pepper_flash && IsNpapiFlashPath(plugin_path)) { | |
| 437 npapi_flash_enabled = enabled; | |
| 438 } else if (migrate_to_pepper_flash && | |
| 439 base::FilePath::CompareEqualIgnoreCase( | |
| 440 path, pepper_flash.value())) { | |
| 441 if (!enabled) | |
| 442 pepper_flash_node = plugin; | |
| 443 } | |
| 444 | |
| 445 plugin_state_.Set(plugin_path, enabled); | 394 plugin_state_.Set(plugin_path, enabled); |
| 446 } else if (!enabled && plugin->GetString("name", &group_name)) { | 395 } else if (!enabled && plugin->GetString("name", &group_name)) { |
| 447 // Otherwise this is a list of groups. | 396 // Otherwise this is a list of groups. |
| 448 plugin_group_state_[group_name] = false; | 397 plugin_group_state_[group_name] = false; |
| 449 } | 398 } |
| 450 } | 399 } |
| 451 | |
| 452 if (npapi_flash_enabled && pepper_flash_node) { | |
| 453 DCHECK(migrate_to_pepper_flash); | |
| 454 pepper_flash_node->SetBoolean("enabled", true); | |
| 455 plugin_state_.Set(pepper_flash, true); | |
| 456 } | |
| 457 } else { | 400 } else { |
| 458 // If the saved plugin list is empty, then the call to UpdatePreferences() | 401 // If the saved plugin list is empty, then the call to UpdatePreferences() |
| 459 // below failed in an earlier run, possibly because the user closed the | 402 // below failed in an earlier run, possibly because the user closed the |
| 460 // browser too quickly. | 403 // browser too quickly. |
| 461 | 404 |
| 462 // Only want one PDF plugin enabled at a time. See http://crbug.com/50105 | 405 // Only want one PDF plugin enabled at a time. See http://crbug.com/50105 |
| 463 // for background. | 406 // for background. |
| 464 plugin_group_state_[base::ASCIIToUTF16( | 407 plugin_group_state_[base::ASCIIToUTF16( |
| 465 PluginMetadata::kAdobeReaderGroupName)] = false; | 408 PluginMetadata::kAdobeReaderGroupName)] = false; |
| 466 } | 409 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 568 } | 511 } |
| 569 } | 512 } |
| 570 | 513 |
| 571 void PluginPrefs::NotifyPluginStatusChanged() { | 514 void PluginPrefs::NotifyPluginStatusChanged() { |
| 572 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 515 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 573 content::NotificationService::current()->Notify( | 516 content::NotificationService::current()->Notify( |
| 574 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, | 517 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, |
| 575 content::Source<Profile>(profile_), | 518 content::Source<Profile>(profile_), |
| 576 content::NotificationService::NoDetails()); | 519 content::NotificationService::NoDetails()); |
| 577 } | 520 } |
| OLD | NEW |