Commit dd86101d authored by mnissler@chromium.org's avatar mnissler@chromium.org

Revert r96364, it's breaking a NaCl test.

TEST=
BUG=
TBR=bauerb@chromium.org

Review URL: http://codereview.chromium.org/7627001

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96430 0039d316-1c4b-4281-b951-d872f2087c98
parent eb4c6af0
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/string_number_conversions.h" #include "base/string_number_conversions.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/plugin_updater.h"
#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h" #include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/common/chrome_content_client.h" #include "chrome/common/chrome_content_client.h"
...@@ -724,10 +725,21 @@ void FlagsState::SetExperimentEnabled( ...@@ -724,10 +725,21 @@ void FlagsState::SetExperimentEnabled(
DCHECK(e); DCHECK(e);
if (e->type == Experiment::SINGLE_VALUE) { if (e->type == Experiment::SINGLE_VALUE) {
if (enable) if (enable) {
enabled_experiments.insert(internal_name); enabled_experiments.insert(internal_name);
else // If enabling NaCl, make sure the plugin is also enabled. See bug
// http://code.google.com/p/chromium/issues/detail?id=81010 for more
// information.
// TODO(dspringer): When NaCl is on by default, remove this code.
if (internal_name == switches::kEnableNaCl) {
PluginUpdater* plugin_updater = PluginUpdater::GetInstance();
string16 nacl_plugin_name =
ASCIIToUTF16(chrome::ChromeContentClient::kNaClPluginName);
plugin_updater->EnablePluginGroup(true, nacl_plugin_name);
}
} else {
enabled_experiments.erase(internal_name); enabled_experiments.erase(internal_name);
}
} else { } else {
if (enable) { if (enable) {
// Enable the first choice. // Enable the first choice.
......
...@@ -59,7 +59,6 @@ ...@@ -59,7 +59,6 @@
#include "chrome/browser/password_manager/password_store.h" #include "chrome/browser/password_manager/password_store.h"
#include "chrome/browser/password_manager/password_store_change.h" #include "chrome/browser/password_manager/password_store_change.h"
#include "chrome/browser/platform_util.h" #include "chrome/browser/platform_util.h"
#include "chrome/browser/plugin_prefs.h"
#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
...@@ -3404,7 +3403,6 @@ void TestingAutomationProvider::GetPluginsInfo( ...@@ -3404,7 +3403,6 @@ void TestingAutomationProvider::GetPluginsInfo(
} }
std::vector<webkit::npapi::WebPluginInfo> plugins; std::vector<webkit::npapi::WebPluginInfo> plugins;
webkit::npapi::PluginList::Singleton()->GetPlugins(&plugins); webkit::npapi::PluginList::Singleton()->GetPlugins(&plugins);
PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile());
ListValue* items = new ListValue; ListValue* items = new ListValue;
for (std::vector<webkit::npapi::WebPluginInfo>::const_iterator it = for (std::vector<webkit::npapi::WebPluginInfo>::const_iterator it =
plugins.begin(); plugins.begin();
...@@ -3415,7 +3413,7 @@ void TestingAutomationProvider::GetPluginsInfo( ...@@ -3415,7 +3413,7 @@ void TestingAutomationProvider::GetPluginsInfo(
item->SetString("path", it->path.value()); item->SetString("path", it->path.value());
item->SetString("version", it->version); item->SetString("version", it->version);
item->SetString("desc", it->desc); item->SetString("desc", it->desc);
item->SetBoolean("enabled", plugin_prefs->IsPluginEnabled(*it)); item->SetBoolean("enabled", webkit::npapi::IsPluginEnabled(*it));
// Add info about mime types. // Add info about mime types.
ListValue* mime_types = new ListValue(); ListValue* mime_types = new ListValue();
for (std::vector<webkit::npapi::WebPluginMimeType>::const_iterator type_it = for (std::vector<webkit::npapi::WebPluginMimeType>::const_iterator type_it =
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#include "chrome/browser/metrics/histogram_synchronizer.h" #include "chrome/browser/metrics/histogram_synchronizer.h"
#include "chrome/browser/net/predictor_api.h" #include "chrome/browser/net/predictor_api.h"
#include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/net/url_fixer_upper.h"
#include "chrome/browser/plugin_prefs.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/browser_dialogs.h"
...@@ -1114,9 +1113,8 @@ std::string AboutVersionStrings(DictionaryValue* localized_strings, ...@@ -1114,9 +1113,8 @@ std::string AboutVersionStrings(DictionaryValue* localized_strings,
GURL(), "application/x-shockwave-flash", false, NULL, &info_array, NULL); GURL(), "application/x-shockwave-flash", false, NULL, &info_array, NULL);
string16 flash_version = string16 flash_version =
l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLED_PLUGIN); l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLED_PLUGIN);
PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile);
for (size_t i = 0; i < info_array.size(); ++i) { for (size_t i = 0; i < info_array.size(); ++i) {
if (plugin_prefs->IsPluginEnabled(info_array[i])) { if (webkit::npapi::IsPluginEnabled(info_array[i])) {
flash_version = info_array[i].version; flash_version = info_array[i].version;
break; break;
} }
......
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
#include "chrome/browser/net/chrome_net_log.h" #include "chrome/browser/net/chrome_net_log.h"
#include "chrome/browser/net/predictor_api.h" #include "chrome/browser/net/predictor_api.h"
#include "chrome/browser/net/sdch_dictionary_fetcher.h" #include "chrome/browser/net/sdch_dictionary_fetcher.h"
#include "chrome/browser/plugin_prefs.h" #include "chrome/browser/plugin_updater.h"
#include "chrome/browser/policy/browser_policy_connector.h" #include "chrome/browser/policy/browser_policy_connector.h"
#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/prefs/pref_value_store.h" #include "chrome/browser/prefs/pref_value_store.h"
...@@ -1906,6 +1906,9 @@ int BrowserMain(const MainFunctionParams& parameters) { ...@@ -1906,6 +1906,9 @@ int BrowserMain(const MainFunctionParams& parameters) {
browser_process->google_url_tracker(); browser_process->google_url_tracker();
browser_process->intranet_redirect_detector(); browser_process->intranet_redirect_detector();
// Do initialize the plug-in service (and related preferences).
PluginUpdater::GetInstance()->SetProfile(profile);
// Prepare for memory caching of SDCH dictionaries. // Prepare for memory caching of SDCH dictionaries.
// Perform A/B test to measure global impact of SDCH support. // Perform A/B test to measure global impact of SDCH support.
// Set up a field trial to see what disabling SDCH does to latency of page // Set up a field trial to see what disabling SDCH does to latency of page
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "chrome/browser/first_run/upgrade_util.h" #include "chrome/browser/first_run/upgrade_util.h"
#include "chrome/browser/jankometer.h" #include "chrome/browser/jankometer.h"
#include "chrome/browser/metrics/metrics_service.h" #include "chrome/browser/metrics/metrics_service.h"
#include "chrome/browser/plugin_updater.h"
#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/service/service_process_control.h" #include "chrome/browser/service/service_process_control.h"
...@@ -145,6 +146,8 @@ void Shutdown() { ...@@ -145,6 +146,8 @@ void Shutdown() {
chrome_browser_net::SavePredictorStateForNextStartupAndTrim(user_prefs); chrome_browser_net::SavePredictorStateForNextStartupAndTrim(user_prefs);
PluginUpdater::GetInstance()->Shutdown();
MetricsService* metrics = g_browser_process->metrics_service(); MetricsService* metrics = g_browser_process->metrics_service();
if (metrics) if (metrics)
metrics->RecordCompletedSessionEnd(); metrics->RecordCompletedSessionEnd();
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "chrome/browser/net/gaia/gaia_oauth_fetcher.h" #include "chrome/browser/net/gaia/gaia_oauth_fetcher.h"
#include "chrome/browser/net/gaia/token_service.h" #include "chrome/browser/net/gaia/token_service.h"
#include "chrome/browser/net/preconnect.h" #include "chrome/browser/net/preconnect.h"
#include "chrome/browser/plugin_updater.h"
#include "chrome/browser/policy/browser_policy_connector.h" #include "chrome/browser/policy/browser_policy_connector.h"
#include "chrome/browser/prefs/pref_member.h" #include "chrome/browser/prefs/pref_member.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -547,6 +548,9 @@ void LoginUtilsImpl::OnProfileCreated(Profile* user_profile, Status status) { ...@@ -547,6 +548,9 @@ void LoginUtilsImpl::OnProfileCreated(Profile* user_profile, Status status) {
btl->AddLoginTimeMarker("TPMOwn-End", false); btl->AddLoginTimeMarker("TPMOwn-End", false);
} }
// Enable/disable plugins based on user preferences.
PluginUpdater::GetInstance()->SetProfile(user_profile);
// We suck. This is a hack since we do not have the enterprise feature // We suck. This is a hack since we do not have the enterprise feature
// done yet to pull down policies from the domain admin. We'll take this // done yet to pull down policies from the domain admin. We'll take this
// out when we get that done properly. // out when we get that done properly.
......
...@@ -291,7 +291,6 @@ void MetricsLog::WritePluginList( ...@@ -291,7 +291,6 @@ void MetricsLog::WritePluginList(
#endif #endif
WriteAttribute("filename", CreateBase64Hash(filename_bytes)); WriteAttribute("filename", CreateBase64Hash(filename_bytes));
WriteAttribute("version", UTF16ToUTF8(iter->version)); WriteAttribute("version", UTF16ToUTF8(iter->version));
// TODO(bauerb): Plug-in state is per-profile.
WriteIntAttribute("disabled", !webkit::npapi::IsPluginEnabled(*iter)); WriteIntAttribute("disabled", !webkit::npapi::IsPluginEnabled(*iter));
} }
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "base/version.h" #include "base/version.h"
#include "chrome/browser/plugin_prefs.h" #include "chrome/browser/plugin_updater.h"
#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/tab_contents/chrome_interstitial_page.h" #include "chrome/browser/tab_contents/chrome_interstitial_page.h"
...@@ -114,12 +114,12 @@ void PDFEnableAdobeReaderInfoBarDelegate::OnYes() { ...@@ -114,12 +114,12 @@ void PDFEnableAdobeReaderInfoBarDelegate::OnYes() {
UserMetrics::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarOK")); UserMetrics::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarOK"));
webkit::npapi::PluginList::Singleton()->EnableGroup(false, webkit::npapi::PluginList::Singleton()->EnableGroup(false,
ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName)); ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName));
PluginUpdater* plugin_updater = PluginUpdater::GetInstance();
plugin_updater->EnablePluginGroup(true,
ASCIIToUTF16(webkit::npapi::PluginGroup::kAdobeReaderGroupName));
Profile* profile = Profile* profile =
Profile::FromBrowserContext(tab_contents_->browser_context()); Profile::FromBrowserContext(tab_contents_->browser_context());
PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); plugin_updater->UpdatePreferences(profile, 0);
plugin_prefs->EnablePluginGroup(
true, ASCIIToUTF16(webkit::npapi::PluginGroup::kAdobeReaderGroupName));
plugin_prefs->UpdatePreferences(0);
} }
void PDFEnableAdobeReaderInfoBarDelegate::OnNo() { void PDFEnableAdobeReaderInfoBarDelegate::OnNo() {
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_PLUGIN_PREFS_H_ #ifndef CHROME_BROWSER_PLUGIN_UPDATER_H_
#define CHROME_BROWSER_PLUGIN_PREFS_H_ #define CHROME_BROWSER_PLUGIN_UPDATER_H_
#pragma once #pragma once
#include <set> #include <set>
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/file_path.h" #include "base/file_path.h"
#include "base/memory/ref_counted.h" #include "base/memory/singleton.h"
#include "chrome/browser/prefs/pref_change_registrar.h" #include "chrome/browser/prefs/pref_change_registrar.h"
#include "content/common/notification_observer.h" #include "content/common/notification_observer.h"
...@@ -19,10 +19,6 @@ class NotificationDetails; ...@@ -19,10 +19,6 @@ class NotificationDetails;
class NotificationSource; class NotificationSource;
class Profile; class Profile;
namespace content {
class ResourceContext;
}
namespace base { namespace base {
class DictionaryValue; class DictionaryValue;
class ListValue; class ListValue;
...@@ -35,68 +31,59 @@ struct WebPluginInfo; ...@@ -35,68 +31,59 @@ struct WebPluginInfo;
} }
} }
// This class stores information about whether a plug-in or a plug-in group is class PluginUpdater : public NotificationObserver {
// enabled or disabled.
// Except for the |IsPluginEnabled| method, it should only be used on the UI
// thread.
class PluginPrefs : public base::RefCountedThreadSafe<PluginPrefs>,
public NotificationObserver {
public: public:
// Initializes the factory for this class for dependency tracking. // Get a list of all the plugin groups. The caller should take ownership
// This should be called before the first profile is created. // of the returned ListValue.
static void Initialize(); static base::ListValue* GetPluginGroupsData();
static PluginPrefs* GetForProfile(Profile* profile);
// Enable or disable a plugin group. // Enable or disable a plugin group.
void EnablePluginGroup(bool enable, const string16& group_name); void EnablePluginGroup(bool enable, const string16& group_name);
// Enable or disable a specific plugin file. // Enable or disable a specific plugin file.
void EnablePlugin(bool enable, const FilePath& file_path); void EnablePlugin(bool enable, const FilePath::StringType& file_path);
// Returns whether the plugin is enabled or not. // Associates the PluginUpdater with |profile|. This enables or disables
bool IsPluginEnabled(const webkit::npapi::WebPluginInfo& plugin); // plugin groups as defined by the user's preferences.
void SetProfile(Profile* profile);
// Called at shutdown before the profile is destroyed.
void Shutdown();
// Write the enable/disable status to the user's preference file. // Write the enable/disable status to the user's preference file.
void UpdatePreferences(int delay_ms); void UpdatePreferences(Profile* profile, int delay_ms);
// NotificationObserver method overrides // NotificationObserver method overrides
virtual void Observe(int type, virtual void Observe(int type,
const NotificationSource& source, const NotificationSource& source,
const NotificationDetails& details); const NotificationDetails& details);
static void RegisterPrefs(PrefService* prefs); static PluginUpdater* GetInstance();
void ShutdownOnUIThread(); static void RegisterPrefs(PrefService* prefs);
private: private:
friend class base::RefCountedThreadSafe<PluginPrefs>; PluginUpdater();
virtual ~PluginUpdater() {}
class Factory;
PluginPrefs();
virtual ~PluginPrefs();
// Associates the PluginPrefs with |profile|. This enables or disables
// plugin groups as defined by the user's preferences.
void SetProfile(Profile* profile);
// Called on the file thread to get the data necessary to update the saved // Called on the file thread to get the data necessary to update the saved
// preferences. // preferences. The profile pointer is only to be passed to the UI thread.
void GetPreferencesDataOnFileThread(); static void GetPreferencesDataOnFileThread(void* profile);
// Called on the UI thread with the plugin data to save the preferences. // Called on the UI thread with the plugin data to save the preferences.
void OnUpdatePreferences(std::vector<webkit::npapi::WebPluginInfo> plugins, static void OnUpdatePreferences(
std::vector<webkit::npapi::PluginGroup> groups); Profile* profile,
const std::vector<webkit::npapi::WebPluginInfo>& plugins,
const std::vector<webkit::npapi::PluginGroup>& groups);
// Queues sending the notification that plugin data has changed. This is done // Queues sending the notification that plugin data has changed. This is done
// so that if a bunch of changes happen, we only send one notification. // so that if a bunch of changes happen, we only send one notification.
void NotifyPluginStatusChanged(); void NotifyPluginStatusChanged();
// Used for the post task to notify that plugin enabled status changed. // Used for the post task to notify that plugin enabled status changed.
void OnNotifyPluginStatusChanged(); static void OnNotifyPluginStatusChanged();
base::DictionaryValue* CreatePluginFileSummary( static base::DictionaryValue* CreatePluginFileSummary(
const webkit::npapi::WebPluginInfo& plugin); const webkit::npapi::WebPluginInfo& plugin);
// Force plugins to be enabled or disabled due to policy. // Force plugins to be enabled or disabled due to policy.
...@@ -110,14 +97,14 @@ class PluginPrefs : public base::RefCountedThreadSafe<PluginPrefs>, ...@@ -110,14 +97,14 @@ class PluginPrefs : public base::RefCountedThreadSafe<PluginPrefs>,
void ListValueToStringSet(const base::ListValue* src, void ListValueToStringSet(const base::ListValue* src,
std::set<string16>* dest); std::set<string16>* dest);
// Weak pointer, owned by the profile. // Needed to allow singleton instantiation using private constructor.
PrefService* prefs_; friend struct DefaultSingletonTraits<PluginUpdater>;
PrefChangeRegistrar registrar_; PrefChangeRegistrar registrar_;
bool notify_pending_; bool notify_pending_;
DISALLOW_COPY_AND_ASSIGN(PluginPrefs); DISALLOW_COPY_AND_ASSIGN(PluginUpdater);
}; };
#endif // CHROME_BROWSER_PLUGIN_PREFS_H_ #endif // CHROME_BROWSER_PLUGIN_UPDATER_H_
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
#include "chrome/browser/notifications/notification_ui_manager.h" #include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/page_info_model.h" #include "chrome/browser/page_info_model.h"
#include "chrome/browser/password_manager/password_manager.h" #include "chrome/browser/password_manager/password_manager.h"
#include "chrome/browser/plugin_prefs.h" #include "chrome/browser/plugin_updater.h"
#include "chrome/browser/policy/cloud_policy_subsystem.h" #include "chrome/browser/policy/cloud_policy_subsystem.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/prefs/session_startup_pref.h" #include "chrome/browser/prefs/session_startup_pref.h"
...@@ -156,8 +156,8 @@ void RegisterUserPrefs(PrefService* user_prefs) { ...@@ -156,8 +156,8 @@ void RegisterUserPrefs(PrefService* user_prefs) {
ExtensionsUI::RegisterUserPrefs(user_prefs); ExtensionsUI::RegisterUserPrefs(user_prefs);
IncognitoModePrefs::RegisterUserPrefs(user_prefs); IncognitoModePrefs::RegisterUserPrefs(user_prefs);
NewTabUI::RegisterUserPrefs(user_prefs); NewTabUI::RegisterUserPrefs(user_prefs);
PluginPrefs::RegisterPrefs(user_prefs);
PluginsUI::RegisterUserPrefs(user_prefs); PluginsUI::RegisterUserPrefs(user_prefs);
PluginUpdater::RegisterPrefs(user_prefs);
ProfileImpl::RegisterUserPrefs(user_prefs); ProfileImpl::RegisterUserPrefs(user_prefs);
PromoResourceService::RegisterUserPrefs(user_prefs); PromoResourceService::RegisterUserPrefs(user_prefs);
HostContentSettingsMap::RegisterUserPrefs(user_prefs); HostContentSettingsMap::RegisterUserPrefs(user_prefs);
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include <iterator> #include <iterator>
#include "chrome/browser/background/background_contents_service_factory.h" #include "chrome/browser/background/background_contents_service_factory.h"
#include "chrome/browser/plugin_prefs.h"
#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h" #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h"
#include "chrome/browser/profiles/profile_keyed_service.h" #include "chrome/browser/profiles/profile_keyed_service.h"
#include "chrome/browser/profiles/profile_keyed_service_factory.h" #include "chrome/browser/profiles/profile_keyed_service_factory.h"
...@@ -37,7 +36,6 @@ void AssertFactoriesBuilt() { ...@@ -37,7 +36,6 @@ void AssertFactoriesBuilt() {
if (!g_initialized) { if (!g_initialized) {
BackgroundContentsServiceFactory::GetInstance(); BackgroundContentsServiceFactory::GetInstance();
CloudPrintProxyServiceFactory::GetInstance(); CloudPrintProxyServiceFactory::GetInstance();
PluginPrefs::Initialize();
SessionServiceFactory::GetInstance(); SessionServiceFactory::GetInstance();
TabRestoreServiceFactory::GetInstance(); TabRestoreServiceFactory::GetInstance();
TemplateURLServiceFactory::GetInstance(); TemplateURLServiceFactory::GetInstance();
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include "base/path_service.h" #include "base/path_service.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/plugin_prefs.h" #include "chrome/browser/plugin_updater.h"
#include "chrome/browser/prefs/pref_member.h" #include "chrome/browser/prefs/pref_member.h"
#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -122,19 +122,23 @@ class PluginsDOMHandler : public WebUIMessageHandler, ...@@ -122,19 +122,23 @@ class PluginsDOMHandler : public WebUIMessageHandler,
const NotificationDetails& details) OVERRIDE; const NotificationDetails& details) OVERRIDE;
private: private:
// This extra wrapper is used to ensure we don't leak the ListValue* pointer
// if the PluginsDOMHandler object goes away before the task on the UI thread
// to give it the plugin list runs.
struct ListWrapper {
ListValue* list;
};
// Loads the plugins on the FILE thread. // Loads the plugins on the FILE thread.
static void LoadPluginsOnFileThread( static void LoadPluginsOnFileThread(ListWrapper* wrapper, Task* task);
std::vector<webkit::npapi::PluginGroup>* groups, Task* task);
// Used in conjunction with ListWrapper to avoid any memory leaks. // Used in conjunction with ListWrapper to avoid any memory leaks.
static void EnsurePluginGroupsDeleted( static void EnsureListDeleted(ListWrapper* wrapper);
std::vector<webkit::npapi::PluginGroup>* groups);
// Call this to start getting the plugins on the UI thread. // Call this to start getting the plugins on the UI thread.
void LoadPlugins(); void LoadPlugins();
// Called on the UI thread when the plugin information is ready. // Called on the UI thread when the plugin information is ready.
void PluginsLoaded(const std::vector<webkit::npapi::PluginGroup>* groups); void PluginsLoaded(ListWrapper* wrapper);
NotificationRegistrar registrar_; NotificationRegistrar registrar_;
...@@ -157,7 +161,7 @@ PluginsDOMHandler::PluginsDOMHandler() ...@@ -157,7 +161,7 @@ PluginsDOMHandler::PluginsDOMHandler()
WebUIMessageHandler* PluginsDOMHandler::Attach(WebUI* web_ui) { WebUIMessageHandler* PluginsDOMHandler::Attach(WebUI* web_ui) {
PrefService* prefs = Profile::FromWebUI(web_ui)->GetPrefs(); PrefService* prefs = Profile::FromWebUI(web_ui)->GetPrefs();
show_details_.Init(prefs::kPluginsShowDetails, prefs, NULL); show_details_.Init(prefs::kPluginsShowDetails, prefs, this);
return WebUIMessageHandler::Attach(web_ui); return WebUIMessageHandler::Attach(web_ui);
} }
...@@ -198,13 +202,13 @@ void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) { ...@@ -198,13 +202,13 @@ void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) {
return; return;
bool enable = enable_str == "true"; bool enable = enable_str == "true";
PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); PluginUpdater* plugin_updater = PluginUpdater::GetInstance();
if (is_group_str == "true") { if (is_group_str == "true") {
string16 group_name; string16 group_name;
if (!args->GetString(0, &group_name)) if (!args->GetString(0, &group_name))
return; return;
plugin_prefs->EnablePluginGroup(enable, group_name); plugin_updater->EnablePluginGroup(enable, group_name);
if (enable) { if (enable) {
// See http://crbug.com/50105 for background. // See http://crbug.com/50105 for background.
string16 adobereader = ASCIIToUTF16( string16 adobereader = ASCIIToUTF16(
...@@ -212,9 +216,9 @@ void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) { ...@@ -212,9 +216,9 @@ void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) {
string16 internalpdf = string16 internalpdf =
ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName); ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName);
if (group_name == adobereader) { if (group_name == adobereader) {
plugin_prefs->EnablePluginGroup(false, internalpdf); plugin_updater->EnablePluginGroup(false, internalpdf);
} else if (group_name == internalpdf) { } else if (group_name == internalpdf) {
plugin_prefs->EnablePluginGroup(false, adobereader); plugin_updater->EnablePluginGroup(false, adobereader);
} }
} }
} else { } else {
...@@ -222,13 +226,13 @@ void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) { ...@@ -222,13 +226,13 @@ void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) {
if (!args->GetString(0, &file_path)) if (!args->GetString(0, &file_path))
return; return;
plugin_prefs->EnablePlugin(enable, FilePath(file_path)); plugin_updater->EnablePlugin(enable, file_path);
} }
// TODO(viettrungluu): We might also want to ensure that the plugins // TODO(viettrungluu): We might also want to ensure that the plugins
// list is always written to prefs even when the user hasn't disabled a // list is always written to prefs even when the user hasn't disabled a
// plugin. <http://crbug.com/39101> // plugin. <http://crbug.com/39101>
plugin_prefs->UpdatePreferences(0); plugin_updater->UpdatePreferences(profile, 0);
} }
void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) { void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) {
...@@ -252,50 +256,41 @@ void PluginsDOMHandler::Observe(int type, ...@@ -252,50 +256,41 @@ void PluginsDOMHandler::Observe(int type,
LoadPlugins(); LoadPlugins();
} }
void PluginsDOMHandler::LoadPluginsOnFileThread( void PluginsDOMHandler::LoadPluginsOnFileThread(ListWrapper* wrapper,
std::vector<webkit::npapi::PluginGroup>* groups, Task* task) {
Task* task) { wrapper->list = PluginUpdater::GetInstance()->GetPluginGroupsData();
webkit::npapi::PluginList::Singleton()->GetPluginGroups(true, groups);
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, task); BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, task);
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, BrowserThread::UI,
FROM_HERE, FROM_HERE,
NewRunnableFunction(&PluginsDOMHandler::EnsurePluginGroupsDeleted, NewRunnableFunction(&PluginsDOMHandler::EnsureListDeleted, wrapper));
groups));
} }
void PluginsDOMHandler::EnsurePluginGroupsDeleted( void PluginsDOMHandler::EnsureListDeleted(ListWrapper* wrapper) {
std::vector<webkit::npapi::PluginGroup>* groups) { delete wrapper->list;
delete groups; delete wrapper;
} }
void PluginsDOMHandler::LoadPlugins() { void PluginsDOMHandler::LoadPlugins() {
if (!get_plugins_factory_.empty()) if (!get_plugins_factory_.empty())
return; return;
std::vector<webkit::npapi::PluginGroup>* groups = ListWrapper* wrapper = new ListWrapper;
new std::vector<webkit::npapi::PluginGroup>; wrapper->list = NULL;
Task* task = get_plugins_factory_.NewRunnableMethod( Task* task = get_plugins_factory_.NewRunnableMethod(
&PluginsDOMHandler::PluginsLoaded, groups); &PluginsDOMHandler::PluginsLoaded, wrapper);
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::FILE, BrowserThread::FILE,
FROM_HERE, FROM_HERE,
NewRunnableFunction( NewRunnableFunction(
&PluginsDOMHandler::LoadPluginsOnFileThread, groups, task)); &PluginsDOMHandler::LoadPluginsOnFileThread, wrapper, task));
} }
void PluginsDOMHandler::PluginsLoaded( void PluginsDOMHandler::PluginsLoaded(ListWrapper* wrapper) {
const std::vector<webkit::npapi::PluginGroup>* groups) {
// Construct DictionaryValues to return to the UI
ListValue* plugin_groups_data = new ListValue();
for (size_t i = 0; i < groups->size(); ++i) {
plugin_groups_data->Append((*groups)[i].GetDataForUI());
// TODO(bauerb): Fetch plugin enabled state from PluginPrefs.
}
DictionaryValue results; DictionaryValue results;
results.Set("plugins", plugin_groups_data); results.Set("plugins", wrapper->list);
wrapper->list = NULL; // So it doesn't get deleted.
web_ui_->CallJavascriptFunction("returnPluginsData", results); web_ui_->CallJavascriptFunction("returnPluginsData", results);
} }
......
...@@ -1642,8 +1642,8 @@ ...@@ -1642,8 +1642,8 @@
'browser/plugin_installer_infobar_delegate.h', 'browser/plugin_installer_infobar_delegate.h',
'browser/plugin_observer.cc', 'browser/plugin_observer.cc',
'browser/plugin_observer.h', 'browser/plugin_observer.h',
'browser/plugin_prefs.cc', 'browser/plugin_updater.cc',
'browser/plugin_prefs.h', 'browser/plugin_updater.h',
'browser/policy/asynchronous_policy_loader.cc', 'browser/policy/asynchronous_policy_loader.cc',
'browser/policy/asynchronous_policy_loader.h', 'browser/policy/asynchronous_policy_loader.h',
'browser/policy/asynchronous_policy_provider.cc', 'browser/policy/asynchronous_policy_provider.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment