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