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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 base::FilePath cur_internal_dir; | 321 base::FilePath cur_internal_dir; |
322 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &cur_internal_dir) && | 322 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &cur_internal_dir) && |
323 cur_internal_dir != last_internal_dir) { | 323 cur_internal_dir != last_internal_dir) { |
324 update_internal_dir = true; | 324 update_internal_dir = true; |
325 prefs_->SetFilePath( | 325 prefs_->SetFilePath( |
326 prefs::kPluginsLastInternalDirectory, cur_internal_dir); | 326 prefs::kPluginsLastInternalDirectory, cur_internal_dir); |
327 } | 327 } |
328 | 328 |
329 bool migrate_to_pepper_flash = false; | 329 bool migrate_to_pepper_flash = false; |
330 #if defined(OS_WIN) || defined(OS_MACOSX) | 330 #if defined(OS_WIN) || defined(OS_MACOSX) |
331 // If bundled NPAPI Flash is enabled while Pepper Flash is disabled, we | 331 // If NPAPI Flash is enabled while Pepper Flash is disabled, we would like to |
332 // would like to turn Pepper Flash on. And we only want to do it once. | 332 // turn Pepper Flash on. And we want to do it once, when NPAPI is disabled in |
333 // TODO(yzshen): Remove all |migrate_to_pepper_flash|-related code after it | 333 // M45. |
Bernhard Bauer
2015/07/27 10:08:33
Can you add a TODO to remove this again at a defin
Will Harris
2015/07/27 16:08:36
Done.
| |
334 // has been run once by most users. (Maybe Chrome 24 or Chrome 25.) | 334 if (!prefs_->GetBoolean(prefs::kNpapiFlashMigratedToPepperFlash)) { |
335 // NOTE(shess): Keep in mind that Mac is on a different schedule. | 335 prefs_->SetBoolean(prefs::kNpapiFlashMigratedToPepperFlash, true); |
336 if (!prefs_->GetBoolean(prefs::kPluginsMigratedToPepperFlash)) { | |
337 prefs_->SetBoolean(prefs::kPluginsMigratedToPepperFlash, true); | |
338 migrate_to_pepper_flash = true; | 336 migrate_to_pepper_flash = true; |
339 } | 337 } |
340 #endif | 338 #endif |
341 | 339 |
342 bool remove_component_pepper_flash_settings = false; | |
343 // If component-updated Pepper Flash is disabled, we would like to remove that | |
344 // settings item. And we only want to do it once. (Please see the comments of | |
345 // kPluginsRemovedOldComponentPepperFlashSettings for why.) | |
346 // TODO(yzshen): Remove all |remove_component_pepper_flash_settings|-related | |
347 // code after it has been run once by most users. | |
348 if (!prefs_->GetBoolean( | |
349 prefs::kPluginsRemovedOldComponentPepperFlashSettings)) { | |
350 prefs_->SetBoolean(prefs::kPluginsRemovedOldComponentPepperFlashSettings, | |
351 true); | |
352 remove_component_pepper_flash_settings = true; | |
353 } | |
354 | |
355 { // Scoped update of prefs::kPluginsPluginsList. | 340 { // Scoped update of prefs::kPluginsPluginsList. |
356 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); | 341 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); |
357 base::ListValue* saved_plugins_list = update.Get(); | 342 base::ListValue* saved_plugins_list = update.Get(); |
358 if (saved_plugins_list && !saved_plugins_list->empty()) { | 343 if (saved_plugins_list && !saved_plugins_list->empty()) { |
359 // The following four variables are only valid when | 344 // The following four variables are only valid when |
360 // |migrate_to_pepper_flash| is set to true. | 345 // |migrate_to_pepper_flash| is set to true. |
361 base::FilePath npapi_flash; | 346 base::FilePath npapi_flash; |
362 base::FilePath pepper_flash; | 347 base::FilePath pepper_flash; |
363 base::DictionaryValue* pepper_flash_node = NULL; | 348 base::DictionaryValue* pepper_flash_node = NULL; |
364 bool npapi_flash_enabled = false; | 349 bool npapi_flash_enabled = false; |
365 if (migrate_to_pepper_flash) { | 350 if (migrate_to_pepper_flash) { |
366 PathService::Get(chrome::FILE_FLASH_PLUGIN, &npapi_flash); | 351 PathService::Get(chrome::FILE_FLASH_SYSTEM_PLUGIN, &npapi_flash); |
367 PathService::Get(chrome::FILE_PEPPER_FLASH_PLUGIN, &pepper_flash); | 352 PathService::Get(chrome::FILE_PEPPER_FLASH_PLUGIN, &pepper_flash); |
368 } | 353 } |
369 | 354 |
370 // Used when |remove_component_pepper_flash_settings| is set to true. | |
371 base::ListValue::iterator component_pepper_flash_node = | |
372 saved_plugins_list->end(); | |
373 | |
374 for (base::ListValue::iterator it = saved_plugins_list->begin(); | 355 for (base::ListValue::iterator it = saved_plugins_list->begin(); |
375 it != saved_plugins_list->end(); | 356 it != saved_plugins_list->end(); |
376 ++it) { | 357 ++it) { |
377 if (!(*it)->IsType(base::Value::TYPE_DICTIONARY)) { | 358 if (!(*it)->IsType(base::Value::TYPE_DICTIONARY)) { |
378 LOG(WARNING) << "Invalid entry in " << prefs::kPluginsPluginsList; | 359 LOG(WARNING) << "Invalid entry in " << prefs::kPluginsPluginsList; |
379 continue; // Oops, don't know what to do with this item. | 360 continue; // Oops, don't know what to do with this item. |
380 } | 361 } |
381 | 362 |
382 base::DictionaryValue* plugin = | 363 base::DictionaryValue* plugin = |
383 static_cast<base::DictionaryValue*>(*it); | 364 static_cast<base::DictionaryValue*>(*it); |
384 base::string16 group_name; | 365 base::string16 group_name; |
385 bool enabled; | 366 bool enabled; |
386 if (!plugin->GetBoolean("enabled", &enabled)) | 367 if (!plugin->GetBoolean("enabled", &enabled)) |
387 enabled = true; | 368 enabled = true; |
388 | 369 |
389 base::FilePath::StringType path; | 370 base::FilePath::StringType path; |
390 // The plugin list constains all the plugin files in addition to the | 371 // The plugin list constains all the plugin files in addition to the |
391 // plugin groups. | 372 // plugin groups. |
392 if (plugin->GetString("path", &path)) { | 373 if (plugin->GetString("path", &path)) { |
393 // Files have a path attribute, groups don't. | 374 // Files have a path attribute, groups don't. |
394 base::FilePath plugin_path(path); | 375 base::FilePath plugin_path(path); |
395 | 376 |
396 // The path to the intenral plugin directory changes everytime Chrome | 377 // The path to the internal plugin directory changes everytime Chrome |
397 // is auto-updated, since it contains the current version number. For | 378 // is auto-updated, since it contains the current version number. For |
398 // example, it changes from foobar\Chrome\Application\21.0.1180.83 to | 379 // example, it changes from foobar\Chrome\Application\21.0.1180.83 to |
399 // foobar\Chrome\Application\21.0.1180.89. | 380 // foobar\Chrome\Application\21.0.1180.89. |
400 // However, we would like the settings of internal plugins to persist | 381 // However, we would like the settings of internal plugins to persist |
401 // across Chrome updates. Therefore, we need to recognize those paths | 382 // across Chrome updates. Therefore, we need to recognize those paths |
402 // that are within the previous internal plugin directory, and update | 383 // that are within the previous internal plugin directory, and update |
403 // them in the prefs accordingly. | 384 // them in the prefs accordingly. |
404 if (update_internal_dir) { | 385 if (update_internal_dir) { |
405 base::FilePath relative_path; | 386 base::FilePath relative_path; |
406 | 387 |
(...skipping 18 matching lines...) Expand all Loading... | |
425 | 406 |
426 // If |relative_path| is empty, |plugin_path| is not within | 407 // If |relative_path| is empty, |plugin_path| is not within |
427 // |last_internal_dir|. We don't need to update it. | 408 // |last_internal_dir|. We don't need to update it. |
428 if (!relative_path.empty()) { | 409 if (!relative_path.empty()) { |
429 plugin_path = cur_internal_dir.Append(relative_path); | 410 plugin_path = cur_internal_dir.Append(relative_path); |
430 path = plugin_path.value(); | 411 path = plugin_path.value(); |
431 plugin->SetString("path", path); | 412 plugin->SetString("path", path); |
432 } | 413 } |
433 } | 414 } |
434 | 415 |
435 if (migrate_to_pepper_flash && | 416 if (migrate_to_pepper_flash && base::FilePath::CompareEqualIgnoreCase( |
436 base::FilePath::CompareEqualIgnoreCase( | 417 path, npapi_flash.value())) { |
437 path, npapi_flash.value())) { | |
438 npapi_flash_enabled = enabled; | 418 npapi_flash_enabled = enabled; |
439 } else if (migrate_to_pepper_flash && | 419 } else if (migrate_to_pepper_flash && |
440 base::FilePath::CompareEqualIgnoreCase( | 420 base::FilePath::CompareEqualIgnoreCase( |
441 path, pepper_flash.value())) { | 421 path, pepper_flash.value())) { |
442 if (!enabled) | 422 if (!enabled) |
443 pepper_flash_node = plugin; | 423 pepper_flash_node = plugin; |
444 } else if (remove_component_pepper_flash_settings && | |
445 IsComponentUpdatedPepperFlash(plugin_path)) { | |
446 if (!enabled) { | |
447 component_pepper_flash_node = it; | |
448 // Skip setting |enabled| into |plugin_state_|. | |
449 continue; | |
450 } | |
451 } | 424 } |
452 | 425 |
453 plugin_state_.Set(plugin_path, enabled); | 426 plugin_state_.Set(plugin_path, enabled); |
454 } else if (!enabled && plugin->GetString("name", &group_name)) { | 427 } else if (!enabled && plugin->GetString("name", &group_name)) { |
455 // Otherwise this is a list of groups. | 428 // Otherwise this is a list of groups. |
456 plugin_group_state_[group_name] = false; | 429 plugin_group_state_[group_name] = false; |
457 } | 430 } |
458 } | 431 } |
459 | 432 |
460 if (npapi_flash_enabled && pepper_flash_node) { | 433 if (npapi_flash_enabled && pepper_flash_node) { |
461 DCHECK(migrate_to_pepper_flash); | 434 DCHECK(migrate_to_pepper_flash); |
462 pepper_flash_node->SetBoolean("enabled", true); | 435 pepper_flash_node->SetBoolean("enabled", true); |
463 plugin_state_.Set(pepper_flash, true); | 436 plugin_state_.Set(pepper_flash, true); |
464 } | 437 } |
465 | |
466 if (component_pepper_flash_node != saved_plugins_list->end()) { | |
467 DCHECK(remove_component_pepper_flash_settings); | |
468 saved_plugins_list->Erase(component_pepper_flash_node, NULL); | |
469 } | |
470 } else { | 438 } else { |
471 // If the saved plugin list is empty, then the call to UpdatePreferences() | 439 // If the saved plugin list is empty, then the call to UpdatePreferences() |
472 // below failed in an earlier run, possibly because the user closed the | 440 // below failed in an earlier run, possibly because the user closed the |
473 // browser too quickly. | 441 // browser too quickly. |
474 | 442 |
475 // Only want one PDF plugin enabled at a time. See http://crbug.com/50105 | 443 // Only want one PDF plugin enabled at a time. See http://crbug.com/50105 |
476 // for background. | 444 // for background. |
477 plugin_group_state_[base::ASCIIToUTF16( | 445 plugin_group_state_[base::ASCIIToUTF16( |
478 PluginMetadata::kAdobeReaderGroupName)] = false; | 446 PluginMetadata::kAdobeReaderGroupName)] = false; |
479 } | 447 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
581 } | 549 } |
582 } | 550 } |
583 | 551 |
584 void PluginPrefs::NotifyPluginStatusChanged() { | 552 void PluginPrefs::NotifyPluginStatusChanged() { |
585 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 553 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
586 content::NotificationService::current()->Notify( | 554 content::NotificationService::current()->Notify( |
587 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, | 555 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, |
588 content::Source<Profile>(profile_), | 556 content::Source<Profile>(profile_), |
589 content::NotificationService::NoDetails()); | 557 content::NotificationService::NoDetails()); |
590 } | 558 } |
OLD | NEW |