diff options
31 files changed, 656 insertions, 1155 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index 4ad0a90..c3d2fd9 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -3536,12 +3536,9 @@ void TestingAutomationProvider::EnablePlugin(Browser* browser, if (!args->GetString("path", &path)) { reply.SendError("path not specified."); return; - } else if (!webkit::npapi::PluginList::Singleton()->EnablePlugin( - FilePath(path))) { - reply.SendError(StringPrintf("Could not enable plugin for path %s.", - path.c_str())); - return; } + PluginPrefs::GetForProfile(browser->profile())->EnablePlugin( + true, FilePath(path)); reply.SendSuccess(NULL); } @@ -3556,12 +3553,9 @@ void TestingAutomationProvider::DisablePlugin(Browser* browser, if (!args->GetString("path", &path)) { reply.SendError("path not specified."); return; - } else if (!webkit::npapi::PluginList::Singleton()->DisablePlugin( - FilePath(path))) { - reply.SendError(StringPrintf("Could not disable plugin for path %s.", - path.c_str())); - return; } + PluginPrefs::GetForProfile(browser->profile())->EnablePlugin( + false, FilePath(path)); reply.SendSuccess(NULL); } diff --git a/chrome/browser/chromeos/gview_request_interceptor_unittest.cc b/chrome/browser/chromeos/gview_request_interceptor_unittest.cc index 97eb568..33662b7 100644 --- a/chrome/browser/chromeos/gview_request_interceptor_unittest.cc +++ b/chrome/browser/chromeos/gview_request_interceptor_unittest.cc @@ -71,6 +71,7 @@ class GViewRequestInterceptorTest : public testing::Test { public: GViewRequestInterceptorTest() : ui_thread_(BrowserThread::UI, &message_loop_), + file_thread_(BrowserThread::FILE, &message_loop_), io_thread_(BrowserThread::IO, &message_loop_) {} virtual void SetUp() { @@ -96,6 +97,7 @@ class GViewRequestInterceptorTest : public testing::Test { } virtual void TearDown() { + plugin_prefs_->ShutdownOnUIThread(); content::ResourceContext* resource_context = content::MockResourceContext::GetInstance(); net::URLRequestContext* request_context = @@ -110,7 +112,6 @@ class GViewRequestInterceptorTest : public testing::Test { void RegisterPDFPlugin() { webkit::WebPluginInfo info; info.path = pdf_path_; - info.enabled = webkit::WebPluginInfo::USER_ENABLED_POLICY_UNMANAGED; webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin(info); webkit::npapi::PluginList::Singleton()->RefreshPlugins(); } @@ -166,6 +167,7 @@ class GViewRequestInterceptorTest : public testing::Test { protected: MessageLoopForIO message_loop_; BrowserThread ui_thread_; + BrowserThread file_thread_; BrowserThread io_thread_; TestingPrefService prefs_; scoped_refptr<PluginPrefs> plugin_prefs_; @@ -197,7 +199,7 @@ TEST_F(GViewRequestInterceptorTest, DoNotInterceptDownload) { TEST_F(GViewRequestInterceptorTest, DoNotInterceptPdfWhenEnabled) { SetPDFPluginLoadedState(true); - webkit::npapi::PluginList::Singleton()->EnablePlugin(pdf_path_); + plugin_prefs_->EnablePlugin(true, pdf_path_); net::URLRequest request(GURL("http://foo.com/file.pdf"), &test_delegate_); SetupRequest(&request); @@ -209,7 +211,7 @@ TEST_F(GViewRequestInterceptorTest, DoNotInterceptPdfWhenEnabled) { TEST_F(GViewRequestInterceptorTest, InterceptPdfWhenDisabled) { SetPDFPluginLoadedState(true); - webkit::npapi::PluginList::Singleton()->DisablePlugin(pdf_path_); + plugin_prefs_->EnablePlugin(false, pdf_path_); net::URLRequest request(GURL("http://foo.com/file.pdf"), &test_delegate_); SetupRequest(&request); diff --git a/chrome/browser/component_updater/pepper_flash_component_installer.cc b/chrome/browser/component_updater/pepper_flash_component_installer.cc index 6c44558..20d7294 100644 --- a/chrome/browser/component_updater/pepper_flash_component_installer.cc +++ b/chrome/browser/component_updater/pepper_flash_component_installer.cc @@ -16,6 +16,7 @@ #include "base/stringprintf.h" #include "base/values.h" #include "chrome/browser/component_updater/component_updater_service.h" +#include "chrome/browser/plugin_prefs.h" #include "chrome/common/chrome_paths.h" #include "content/browser/browser_thread.h" #include "content/common/pepper_plugin_registry.h" @@ -107,7 +108,6 @@ bool SupportsPepperInterface(const char* interface_name) { bool MakePepperFlashPluginInfo(const FilePath& flash_path, const Version& flash_version, bool out_of_process, - bool enabled, PepperPluginInfo* plugin_info) { if (!flash_version.IsValid()) return false; @@ -119,7 +119,6 @@ bool MakePepperFlashPluginInfo(const FilePath& flash_path, plugin_info->is_out_of_process = out_of_process; plugin_info->path = flash_path; plugin_info->name = kFlashPluginName; - plugin_info->enabled = enabled; // The description is like "Shockwave Flash 10.2 r154". plugin_info->description = StringPrintf("%s %d.%d r%d", @@ -143,8 +142,9 @@ void RegisterPepperFlashWithChrome(const FilePath& path, DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); PepperPluginInfo plugin_info; // Register it as out-of-process and disabled. - if (!MakePepperFlashPluginInfo(path, version, true, false, &plugin_info)) + if (!MakePepperFlashPluginInfo(path, version, true, &plugin_info)) return; + PluginPrefs::EnablePluginGlobally(false, plugin_info.path); webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin( plugin_info.ToWebPluginInfo()); webkit::npapi::PluginList::Singleton()->RefreshPlugins(); diff --git a/chrome/browser/pdf_unsupported_feature.cc b/chrome/browser/pdf_unsupported_feature.cc index 1a91a39..9fb0747 100644 --- a/chrome/browser/pdf_unsupported_feature.cc +++ b/chrome/browser/pdf_unsupported_feature.cc @@ -7,9 +7,9 @@ #include "base/utf_string_conversions.h" #include "base/values.h" #include "base/version.h" +#include "chrome/browser/chrome_plugin_service_filter.h" #include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/plugin_prefs.h" -#include "chrome/browser/chrome_plugin_service_filter.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/tab_contents/chrome_interstitial_page.h" @@ -116,14 +116,13 @@ string16 PDFEnableAdobeReaderInfoBarDelegate::GetMessageText() const { void PDFEnableAdobeReaderInfoBarDelegate::OnYes() { UserMetrics::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarOK")); - webkit::npapi::PluginList::Singleton()->EnableGroup(false, - ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName)); Profile* profile = Profile::FromBrowserContext(tab_contents_->browser_context()); PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); plugin_prefs->EnablePluginGroup( true, ASCIIToUTF16(webkit::npapi::PluginGroup::kAdobeReaderGroupName)); - plugin_prefs->UpdatePreferences(0); + plugin_prefs->EnablePluginGroup( + false, ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName)); } void PDFEnableAdobeReaderInfoBarDelegate::OnNo() { @@ -142,11 +141,9 @@ void OpenUsingReader(TabContentsWrapper* tab, InfoBarDelegate* old_delegate, InfoBarDelegate* new_delegate) { WebPluginInfo plugin = reader_plugin; - // The plugin is disabled, so enable it to get around the renderer check. - // Also give it a new version so that the renderer doesn't show the blocked + // Give the plugin a new version so that the renderer doesn't show the blocked // plugin UI if it's vulnerable, since we already went through the // interstitial. - plugin.enabled = WebPluginInfo::USER_ENABLED; plugin.version = ASCIIToUTF16("11.0.0.0"); ChromePluginServiceFilter::GetInstance()->OverridePluginForTab( @@ -284,11 +281,12 @@ PDFUnsupportedFeatureInfoBarDelegate::PDFUnsupportedFeatureInfoBarDelegate( } UserMetrics::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarShown")); - std::vector<WebPluginInfo> plugins = reader_group->web_plugin_infos(); + const std::vector<WebPluginInfo>& plugins = + reader_group->web_plugin_infos(); DCHECK_EQ(plugins.size(), 1u); reader_webplugininfo_ = plugins[0]; - reader_vulnerable_ = reader_group->IsVulnerable(); + reader_vulnerable_ = reader_group->IsVulnerable(reader_webplugininfo_); if (!reader_vulnerable_) { scoped_ptr<Version> version(PluginGroup::CreateVersionFromString( reader_webplugininfo_.version)); @@ -382,8 +380,11 @@ void PDFHasUnsupportedFeature(TabContentsWrapper* tab) { string16 reader_group_name(ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); // If the Reader plugin is disabled by policy, don't prompt them. - if (PluginGroup::IsPluginNameDisabledByPolicy(reader_group_name)) + PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(tab->profile()); + if (plugin_prefs->PolicyStatusForPlugin(reader_group_name) == + PluginPrefs::POLICY_DISABLED) { return; + } PluginGroup* reader_group = NULL; std::vector<PluginGroup> plugin_groups; diff --git a/chrome/browser/plugin_exceptions_table_model_unittest.cc b/chrome/browser/plugin_exceptions_table_model_unittest.cc index 3c59fd7..f37c6c1 100644 --- a/chrome/browser/plugin_exceptions_table_model_unittest.cc +++ b/chrome/browser/plugin_exceptions_table_model_unittest.cc @@ -93,8 +93,6 @@ class PluginExceptionsTableModelTest : public testing::Test { webkit::WebPluginInfo foo_plugin; foo_plugin.path = FilePath(FILE_PATH_LITERAL("a-foo")); foo_plugin.name = ASCIIToUTF16("FooPlugin"); - foo_plugin.enabled = - webkit::WebPluginInfo::USER_ENABLED_POLICY_UNMANAGED; scoped_ptr<webkit::npapi::PluginGroup> foo_group( webkit::npapi::PluginGroup::FromWebPluginInfo(foo_plugin)); plugins.push_back(*foo_group); @@ -102,8 +100,6 @@ class PluginExceptionsTableModelTest : public testing::Test { webkit::WebPluginInfo bar_plugin; bar_plugin.path = FilePath(FILE_PATH_LITERAL("b-bar")); bar_plugin.name = ASCIIToUTF16("BarPlugin"); - bar_plugin.enabled = - webkit::WebPluginInfo::USER_ENABLED_POLICY_UNMANAGED; scoped_ptr<webkit::npapi::PluginGroup> bar_group( webkit::npapi::PluginGroup::FromWebPluginInfo(bar_plugin)); plugins.push_back(*bar_group); diff --git a/chrome/browser/plugin_prefs.cc b/chrome/browser/plugin_prefs.cc index 50d1d42..a60a28b 100644 --- a/chrome/browser/plugin_prefs.cc +++ b/chrome/browser/plugin_prefs.cc @@ -7,19 +7,23 @@ #include <string> #include "base/command_line.h" +#include "base/lazy_instance.h" #include "base/memory/scoped_ptr.h" #include "base/memory/singleton.h" #include "base/message_loop.h" #include "base/path_service.h" +#include "base/string_util.h" #include "base/utf_string_conversions.h" #include "base/values.h" #include "base/version.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/scoped_user_pref_update.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_dependency_manager.h" #include "chrome/browser/profiles/profile_keyed_service.h" #include "chrome/browser/profiles/profile_keyed_service_factory.h" +#include "chrome/browser/profiles/profile_manager.h" #include "chrome/common/chrome_content_client.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_paths.h" @@ -27,6 +31,7 @@ #include "chrome/common/pref_names.h" #include "content/browser/browser_thread.h" #include "content/common/notification_service.h" +#include "webkit/plugins/npapi/plugin_group.h" #include "webkit/plugins/npapi/plugin_list.h" #include "webkit/plugins/webplugininfo.h" @@ -49,6 +54,11 @@ class PluginPrefsWrapper : public ProfileKeyedService { scoped_refptr<PluginPrefs> plugin_prefs_; }; +// Default state for a plug-in (not state of the default plug-in!). +// Accessed only on the UI thread. +base::LazyInstance<std::map<FilePath, bool> > g_default_plugin_state( + base::LINKER_INITIALIZED); + } // How long to wait to save the plugin enabled information, which might need to @@ -61,6 +71,10 @@ class PluginPrefs::Factory : public ProfileKeyedServiceFactory { PluginPrefsWrapper* GetWrapperForProfile(Profile* profile); + // Factory function for use with + // ProfileKeyedServiceFactory::SetTestingFactory. + static ProfileKeyedService* CreateWrapperForProfile(Profile* profile); + private: friend struct DefaultSingletonTraits<Factory>; @@ -89,31 +103,138 @@ PluginPrefs* PluginPrefs::GetForProfile(Profile* profile) { return wrapper->plugin_prefs(); } -DictionaryValue* PluginPrefs::CreatePluginFileSummary( - const webkit::WebPluginInfo& plugin) { - DictionaryValue* data = new DictionaryValue(); - data->SetString("path", plugin.path.value()); - data->SetString("name", plugin.name); - data->SetString("version", plugin.version); - data->SetBoolean("enabled", IsPluginEnabled(plugin)); - return data; +// static +PluginPrefs* PluginPrefs::GetForTestingProfile(Profile* profile) { + ProfileKeyedService* wrapper = + Factory::GetInstance()->SetTestingFactoryAndUse( + profile, &Factory::CreateWrapperForProfile); + return static_cast<PluginPrefsWrapper*>(wrapper)->plugin_prefs(); } -void PluginPrefs::EnablePluginGroup(bool enable, const string16& group_name) { - webkit::npapi::PluginList::Singleton()->EnableGroup(enable, group_name); - NotifyPluginStatusChanged(); +void PluginPrefs::EnablePluginGroup(bool enabled, const string16& group_name) { + if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { + BrowserThread::PostTask( + BrowserThread::FILE, FROM_HERE, + NewRunnableMethod(this, &PluginPrefs::EnablePluginGroup, + enabled, group_name)); + return; + } + + webkit::npapi::PluginList* plugin_list = + webkit::npapi::PluginList::Singleton(); + std::vector<webkit::npapi::PluginGroup> groups; + plugin_list->GetPluginGroups(true, &groups); + + base::AutoLock auto_lock(lock_); + + // Set the desired state for the group. + plugin_group_state_[group_name] = enabled; + + // Update the state for all plug-ins in the group. + for (size_t i = 0; i < groups.size(); ++i) { + if (groups[i].GetGroupName() != group_name) + continue; + const std::vector<webkit::WebPluginInfo>& plugins = + groups[i].web_plugin_infos(); + for (size_t j = 0; j < plugins.size(); ++j) + plugin_state_[plugins[j].path] = enabled; + break; + } + + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, + NewRunnableMethod(this, &PluginPrefs::OnUpdatePreferences, groups)); + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, + NewRunnableMethod(this, &PluginPrefs::NotifyPluginStatusChanged)); } -void PluginPrefs::EnablePlugin(bool enable, const FilePath& path) { - if (enable) - webkit::npapi::PluginList::Singleton()->EnablePlugin(path); - else - webkit::npapi::PluginList::Singleton()->DisablePlugin(path); +void PluginPrefs::EnablePlugin(bool enabled, const FilePath& path) { + if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { + BrowserThread::PostTask( + BrowserThread::FILE, FROM_HERE, + NewRunnableMethod(this, &PluginPrefs::EnablePlugin, enabled, path)); + return; + } - NotifyPluginStatusChanged(); + { + // Set the desired state for the plug-in. + base::AutoLock auto_lock(lock_); + plugin_state_[path] = enabled; + } + + webkit::npapi::PluginList* plugin_list = + webkit::npapi::PluginList::Singleton(); + std::vector<webkit::npapi::PluginGroup> groups; + plugin_list->GetPluginGroups(true, &groups); + + bool found_group = false; + for (size_t i = 0; i < groups.size(); ++i) { + bool all_disabled = true; + const std::vector<webkit::WebPluginInfo>& plugins = + groups[i].web_plugin_infos(); + for (size_t j = 0; j < plugins.size(); ++j) { + all_disabled = all_disabled && !IsPluginEnabled(plugins[j]); + if (plugins[j].path == path) { + found_group = true; + DCHECK_EQ(enabled, IsPluginEnabled(plugins[j])); + } + } + if (found_group) { + // Update the state for the corresponding plug-in group. + base::AutoLock auto_lock(lock_); + plugin_group_state_[groups[i].GetGroupName()] = !all_disabled; + break; + } + } + + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, + NewRunnableMethod(this, &PluginPrefs::OnUpdatePreferences, groups)); + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, + NewRunnableMethod(this, &PluginPrefs::NotifyPluginStatusChanged)); +} + +// static +void PluginPrefs::EnablePluginGlobally(bool enable, const FilePath& file_path) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + g_default_plugin_state.Get()[file_path] = enable; + std::vector<Profile*> profiles = + g_browser_process->profile_manager()->GetLoadedProfiles(); + for (std::vector<Profile*>::iterator it = profiles.begin(); + it != profiles.end(); ++it) { + PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(*it); + DCHECK(plugin_prefs); + plugin_prefs->EnablePlugin(enable, file_path); + } +} + +PluginPrefs::PolicyStatus PluginPrefs::PolicyStatusForPlugin( + const string16& name) { + base::AutoLock auto_lock(lock_); + if (IsStringMatchedInSet(name, policy_enabled_plugin_patterns_)) { + return POLICY_ENABLED; + } else if (IsStringMatchedInSet(name, policy_disabled_plugin_patterns_) && + !IsStringMatchedInSet( + name, policy_disabled_plugin_exception_patterns_)) { + return POLICY_DISABLED; + } else { + return NO_POLICY; + } } bool PluginPrefs::IsPluginEnabled(const webkit::WebPluginInfo& plugin) { + scoped_ptr<webkit::npapi::PluginGroup> group( + webkit::npapi::PluginList::Singleton()->GetPluginGroup(plugin)); + string16 group_name = group->GetGroupName(); + + // Check if the plug-in or its group is enabled by policy. + PolicyStatus plugin_status = PolicyStatusForPlugin(plugin.name); + PolicyStatus group_status = PolicyStatusForPlugin(group_name); + if (plugin_status == POLICY_ENABLED || group_status == POLICY_ENABLED) + return true; + + // Check if the plug-in or its group is disabled by policy. + if (plugin_status == POLICY_DISABLED || group_status == POLICY_DISABLED) + return false; + // 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. @@ -123,12 +244,27 @@ bool PluginPrefs::IsPluginEnabled(const webkit::WebPluginInfo& plugin) { CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableNaCl)) { return true; } - return webkit::IsPluginEnabled(plugin); + + base::AutoLock auto_lock(lock_); + // Check user preferences for the plug-in. + std::map<FilePath, bool>::iterator plugin_it = + plugin_state_.find(plugin.path); + if (plugin_it != plugin_state_.end()) + return plugin_it->second; + + // Check user preferences for the plug-in group. + std::map<string16, bool>::iterator group_it( + plugin_group_state_.find(plugin.name)); + if (group_it != plugin_group_state_.end()) + return group_it->second; + + // Default to enabled. + return true; } void PluginPrefs::Observe(int type, - const NotificationSource& source, - const NotificationDetails& details) { + const NotificationSource& source, + const NotificationDetails& details) { DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); const std::string* pref_name = Details<std::string>(details).ptr(); if (!pref_name) { @@ -136,39 +272,39 @@ void PluginPrefs::Observe(int type, return; } DCHECK_EQ(prefs_, Source<PrefService>(source).ptr()); - if (*pref_name == prefs::kPluginsDisabledPlugins || - *pref_name == prefs::kPluginsDisabledPluginsExceptions || - *pref_name == prefs::kPluginsEnabledPlugins) { - const ListValue* disabled_list = - prefs_->GetList(prefs::kPluginsDisabledPlugins); - const ListValue* exceptions_list = - prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions); - const ListValue* enabled_list = - prefs_->GetList(prefs::kPluginsEnabledPlugins); - UpdatePluginsStateFromPolicy(disabled_list, exceptions_list, enabled_list); + if (*pref_name == prefs::kPluginsDisabledPlugins) { + base::AutoLock auto_lock(lock_); + ListValueToStringSet(prefs_->GetList(prefs::kPluginsDisabledPlugins), + &policy_disabled_plugin_patterns_); + } else if (*pref_name == prefs::kPluginsDisabledPluginsExceptions) { + base::AutoLock auto_lock(lock_); + ListValueToStringSet( + prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions), + &policy_disabled_plugin_exception_patterns_); + } else if (*pref_name == prefs::kPluginsEnabledPlugins) { + base::AutoLock auto_lock(lock_); + ListValueToStringSet(prefs_->GetList(prefs::kPluginsEnabledPlugins), + &policy_enabled_plugin_patterns_); + } else { + NOTREACHED(); } + NotifyPluginStatusChanged(); } -void PluginPrefs::UpdatePluginsStateFromPolicy( - const ListValue* disabled_list, - const ListValue* exceptions_list, - const ListValue* enabled_list) { - std::set<string16> disabled_plugin_patterns; - std::set<string16> disabled_plugin_exception_patterns; - std::set<string16> enabled_plugin_patterns; - - ListValueToStringSet(disabled_list, &disabled_plugin_patterns); - ListValueToStringSet(exceptions_list, &disabled_plugin_exception_patterns); - ListValueToStringSet(enabled_list, &enabled_plugin_patterns); - - webkit::npapi::PluginGroup::SetPolicyEnforcedPluginPatterns( - disabled_plugin_patterns, - disabled_plugin_exception_patterns, - enabled_plugin_patterns); +/*static*/ +bool PluginPrefs::IsStringMatchedInSet(const string16& name, + const std::set<string16>& pattern_set) { + std::set<string16>::const_iterator pattern(pattern_set.begin()); + while (pattern != pattern_set.end()) { + if (MatchPattern(name, *pattern)) + return true; + ++pattern; + } - NotifyPluginStatusChanged(); + return false; } +/* static */ void PluginPrefs::ListValueToStringSet(const ListValue* src, std::set<string16>* dest) { DCHECK(src); @@ -277,8 +413,7 @@ void PluginPrefs::SetPrefs(PrefService* prefs) { } } - if (!enabled) - webkit::npapi::PluginList::Singleton()->DisablePlugin(plugin_path); + plugin_state_[plugin_path] = enabled; } else if (!enabled && plugin->GetString("name", &group_name)) { // Don't disable this group if it's for the pdf or nacl plugins and // we just forced it on. @@ -289,7 +424,7 @@ void PluginPrefs::SetPrefs(PrefService* prefs) { continue; // Otherwise this is a list of groups. - EnablePluginGroup(false, group_name); + plugin_group_state_[group_name] = false; } } } else { @@ -304,17 +439,14 @@ void PluginPrefs::SetPrefs(PrefService* prefs) { // Build the set of policy enabled/disabled plugin patterns once and cache it. // Don't do this in the constructor, there's no profile available there. - const ListValue* disabled_plugins = - prefs_->GetList(prefs::kPluginsDisabledPlugins); - const ListValue* disabled_exception_plugins = - prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions); - const ListValue* enabled_plugins = - prefs_->GetList(prefs::kPluginsEnabledPlugins); - UpdatePluginsStateFromPolicy(disabled_plugins, - disabled_exception_plugins, - enabled_plugins); + ListValueToStringSet(prefs_->GetList(prefs::kPluginsDisabledPlugins), + &policy_disabled_plugin_patterns_); + ListValueToStringSet( + prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions), + &policy_disabled_plugin_exception_patterns_); + ListValueToStringSet(prefs_->GetList(prefs::kPluginsEnabledPlugins), + &policy_enabled_plugin_patterns_); - registrar_.RemoveAll(); registrar_.Init(prefs_); registrar_.Add(prefs::kPluginsDisabledPlugins, this); registrar_.Add(prefs::kPluginsDisabledPluginsExceptions, this); @@ -322,16 +454,22 @@ void PluginPrefs::SetPrefs(PrefService* prefs) { if (force_enable_internal_pdf || internal_pdf_enabled) { // See http://crbug.com/50105 for background. - EnablePluginGroup(false, ASCIIToUTF16( - webkit::npapi::PluginGroup::kAdobeReaderGroupName)); + plugin_group_state_[ASCIIToUTF16( + webkit::npapi::PluginGroup::kAdobeReaderGroupName)] = false; } if (force_enable_internal_pdf || force_enable_nacl) { // We want to save this, but doing so requires loading the list of plugins, // so do it after a minute as to not impact startup performance. Note that // plugins are loaded after 30s by the metrics service. - UpdatePreferences(kPluginUpdateDelayMs); + BrowserThread::PostDelayedTask( + BrowserThread::FILE, + FROM_HERE, + NewRunnableMethod(this, &PluginPrefs::GetPreferencesDataOnFileThread), + kPluginUpdateDelayMs); } + + NotifyPluginStatusChanged(); } void PluginPrefs::ShutdownOnUIThread() { @@ -349,47 +487,51 @@ PluginPrefsWrapper* PluginPrefs::Factory::GetWrapperForProfile( return static_cast<PluginPrefsWrapper*>(GetServiceForProfile(profile, true)); } +// static +ProfileKeyedService* PluginPrefs::Factory::CreateWrapperForProfile( + Profile* profile) { + return GetInstance()->BuildServiceInstanceFor(profile); +} + PluginPrefs::Factory::Factory() : ProfileKeyedServiceFactory(ProfileDependencyManager::GetInstance()) { } ProfileKeyedService* PluginPrefs::Factory::BuildServiceInstanceFor( - Profile* profile) const { + Profile* profile) const { scoped_refptr<PluginPrefs> plugin_prefs(new PluginPrefs()); plugin_prefs->SetPrefs(profile->GetPrefs()); return new PluginPrefsWrapper(plugin_prefs); } -PluginPrefs::PluginPrefs() : prefs_(NULL), notify_pending_(false) { +PluginPrefs::PluginPrefs() : plugin_state_(g_default_plugin_state.Get()), + prefs_(NULL) { } PluginPrefs::~PluginPrefs() { } -void PluginPrefs::UpdatePreferences(int delay_ms) { - BrowserThread::PostDelayedTask( - BrowserThread::FILE, - FROM_HERE, - NewRunnableMethod(this, &PluginPrefs::GetPreferencesDataOnFileThread), - delay_ms); +void PluginPrefs::SetPolicyEnforcedPluginPatterns( + const std::set<string16>& disabled_patterns, + const std::set<string16>& disabled_exception_patterns, + const std::set<string16>& enabled_patterns) { + policy_disabled_plugin_patterns_ = disabled_patterns; + policy_disabled_plugin_exception_patterns_ = disabled_exception_patterns; + policy_enabled_plugin_patterns_ = enabled_patterns; } void PluginPrefs::GetPreferencesDataOnFileThread() { - std::vector<webkit::WebPluginInfo> plugins; std::vector<webkit::npapi::PluginGroup> groups; webkit::npapi::PluginList* plugin_list = webkit::npapi::PluginList::Singleton(); - plugin_list->GetPlugins(&plugins); plugin_list->GetPluginGroups(false, &groups); BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, - NewRunnableMethod(this, &PluginPrefs::OnUpdatePreferences, - plugins, groups)); + NewRunnableMethod(this, &PluginPrefs::OnUpdatePreferences, groups)); } void PluginPrefs::OnUpdatePreferences( - std::vector<webkit::WebPluginInfo> plugins, std::vector<webkit::npapi::PluginGroup> groups) { if (!prefs_) return; @@ -402,44 +544,42 @@ void PluginPrefs::OnUpdatePreferences( if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir)) prefs_->SetFilePath(prefs::kPluginsLastInternalDirectory, internal_dir); - // Add the plugin files. - for (size_t i = 0; i < plugins.size(); ++i) { - DictionaryValue* summary = CreatePluginFileSummary(plugins[i]); - // If the plugin is managed by policy, store the user preferred state - // instead. - if (plugins[i].enabled & webkit::WebPluginInfo::MANAGED_MASK) { - bool user_enabled = - (plugins[i].enabled & webkit::WebPluginInfo::USER_MASK) == - webkit::WebPluginInfo::USER_ENABLED; - summary->SetBoolean("enabled", user_enabled); - } - plugins_list->Append(summary); - } + base::AutoLock auto_lock(lock_); - // Add the groups as well. + // Add the plug-in groups. for (size_t i = 0; i < groups.size(); ++i) { - DictionaryValue* summary = groups[i].GetSummary(); - // If the plugin is disabled only by policy don't store this state in the - // user pref store. - if (!groups[i].Enabled() && - webkit::npapi::PluginGroup::IsPluginNameDisabledByPolicy( - groups[i].GetGroupName())) - summary->SetBoolean("enabled", true); + // Add the plugin files to the same list. + const std::vector<webkit::WebPluginInfo>& plugins = + groups[i].web_plugin_infos(); + for (size_t j = 0; j < plugins.size(); ++j) { + DictionaryValue* summary = new DictionaryValue(); + summary->SetString("path", plugins[j].path.value()); + summary->SetString("name", plugins[j].name); + summary->SetString("version", plugins[j].version); + bool enabled = true; + std::map<FilePath, bool>::iterator it = + plugin_state_.find(plugins[j].path); + if (it != plugin_state_.end()) + enabled = it->second; + summary->SetBoolean("enabled", enabled); plugins_list->Append(summary); + } + + DictionaryValue* summary = new DictionaryValue(); + string16 name = groups[i].GetGroupName(); + summary->SetString("name", name); + bool enabled = true; + std::map<string16, bool>::iterator it = + plugin_group_state_.find(name); + if (it != plugin_group_state_.end()) + enabled = it->second; + summary->SetBoolean("enabled", enabled); + plugins_list->Append(summary); } } void PluginPrefs::NotifyPluginStatusChanged() { - if (notify_pending_) - return; - notify_pending_ = true; - MessageLoop::current()->PostTask( - FROM_HERE, - NewRunnableMethod(this, &PluginPrefs::OnNotifyPluginStatusChanged)); -} - -void PluginPrefs::OnNotifyPluginStatusChanged() { - notify_pending_ = false; + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); NotificationService::current()->Notify( chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, Source<PluginPrefs>(this), diff --git a/chrome/browser/plugin_prefs.h b/chrome/browser/plugin_prefs.h index d55a600..ecfd585 100644 --- a/chrome/browser/plugin_prefs.h +++ b/chrome/browser/plugin_prefs.h @@ -6,12 +6,14 @@ #define CHROME_BROWSER_PLUGIN_PREFS_H_ #pragma once +#include <map> #include <set> #include <vector> #include "base/basictypes.h" #include "base/file_path.h" #include "base/memory/ref_counted.h" +#include "base/synchronization/lock.h" #include "chrome/browser/prefs/pref_change_registrar.h" #include "content/common/notification_observer.h" @@ -37,11 +39,16 @@ class PluginGroup; // This class stores information about whether a plug-in or a plug-in group is // enabled or disabled. -// Except for the |IsPluginEnabled| method, it should only be used on the UI -// thread. +// Except where otherwise noted, it can be used on every thread. class PluginPrefs : public base::RefCountedThreadSafe<PluginPrefs>, public NotificationObserver { public: + enum PolicyStatus { + NO_POLICY = 0, // Neither enabled or disabled by policy. + POLICY_ENABLED, + POLICY_DISABLED, + }; + // Initializes the factory for this class for dependency tracking. // This should be called before the first profile is created. static void Initialize(); @@ -49,77 +56,96 @@ class PluginPrefs : public base::RefCountedThreadSafe<PluginPrefs>, // Returns the instance associated with |profile|, creating it if necessary. static PluginPrefs* GetForProfile(Profile* profile); + // Usually the PluginPrefs associated with a TestingProfile is NULL. + // This method overrides that for a given TestingProfile, returning the newly + // created PluginPrefs object. + static PluginPrefs* GetForTestingProfile(Profile* profile); + // Creates a new instance. This method should only be used for testing. PluginPrefs(); // Associates this instance with |prefs|. This enables or disables // plugin groups as defined by the user's preferences. + // This method should only be called on the UI thread. void SetPrefs(PrefService* prefs); + // Detaches from the PrefService before it is destroyed. + // As the name says, this method should only be called on the UI thread. + void ShutdownOnUIThread(); + // Enable or disable a plugin group. void EnablePluginGroup(bool enable, const string16& group_name); // Enable or disable a specific plugin file. void EnablePlugin(bool enable, const FilePath& file_path); + // Enable or disable a plug-in in all profiles. This sets a default for + // profiles which are created later as well. + // This method should only be called on the UI thread. + static void EnablePluginGlobally(bool enable, const FilePath& file_path); + + // Returns whether there is a policy enabling or disabling plug-ins of the + // given name. + PolicyStatus PolicyStatusForPlugin(const string16& name); + // Returns whether the plugin is enabled or not. bool IsPluginEnabled(const webkit::WebPluginInfo& plugin); - // Write the enable/disable status to the user's preference file. - void UpdatePreferences(int delay_ms); + // Registers the preferences used by this class. + // This method should only be called on the UI thread. + static void RegisterPrefs(PrefService* prefs); - // NotificationObserver method overrides + // NotificationObserver method override. virtual void Observe(int type, const NotificationSource& source, - const NotificationDetails& details); - - static void RegisterPrefs(PrefService* prefs); - - void ShutdownOnUIThread(); + const NotificationDetails& details) OVERRIDE; private: friend class base::RefCountedThreadSafe<PluginPrefs>; + friend class PluginPrefsTest; class Factory; virtual ~PluginPrefs(); + // Allows unit tests to directly set enforced plug-in patterns. + void SetPolicyEnforcedPluginPatterns( + const std::set<string16>& disabled_patterns, + const std::set<string16>& disabled_exception_patterns, + const std::set<string16>& enabled_patterns); + // Called on the file thread to get the data necessary to update the saved // preferences. void GetPreferencesDataOnFileThread(); // Called on the UI thread with the plugin data to save the preferences. - void OnUpdatePreferences(std::vector<webkit::WebPluginInfo> plugins, - std::vector<webkit::npapi::PluginGroup> groups); + void OnUpdatePreferences(std::vector<webkit::npapi::PluginGroup> groups); - // 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. + // Sends the notification that plugin data has changed. void NotifyPluginStatusChanged(); - // Used for the post task to notify that plugin enabled status changed. - void OnNotifyPluginStatusChanged(); + static void ListValueToStringSet(const base::ListValue* src, + std::set<string16>* dest); + + // Checks if |name| matches any of the patterns in |pattern_set|. + static bool IsStringMatchedInSet(const string16& name, + const std::set<string16>& pattern_set); - base::DictionaryValue* CreatePluginFileSummary( - const webkit::WebPluginInfo& plugin); + // Guards access to the following data structures. + mutable base::Lock lock_; - // Force plugins to be enabled or disabled due to policy. - // |disabled_list| contains the list of StringValues of the names of the - // policy-disabled plugins, |exceptions_list| the policy-allowed plugins, - // and |enabled_list| the policy-enabled plugins. - void UpdatePluginsStateFromPolicy(const base::ListValue* disabled_list, - const base::ListValue* exceptions_list, - const base::ListValue* enabled_list); + std::map<FilePath, bool> plugin_state_; + std::map<string16, bool> plugin_group_state_; - void ListValueToStringSet(const base::ListValue* src, - std::set<string16>* dest); + std::set<string16> policy_disabled_plugin_patterns_; + std::set<string16> policy_disabled_plugin_exception_patterns_; + std::set<string16> policy_enabled_plugin_patterns_; - // Weak pointer, owned by the profile. + // Weak pointer, owned by the profile (which owns us). PrefService* prefs_; PrefChangeRegistrar registrar_; - bool notify_pending_; - DISALLOW_COPY_AND_ASSIGN(PluginPrefs); }; diff --git a/chrome/browser/plugin_prefs_unittest.cc b/chrome/browser/plugin_prefs_unittest.cc new file mode 100644 index 0000000..934d478 --- /dev/null +++ b/chrome/browser/plugin_prefs_unittest.cc @@ -0,0 +1,160 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/plugin_prefs.h" + +#include "base/utf_string_conversions.h" +#include "chrome/test/base/testing_browser_process.h" +#include "chrome/test/base/testing_profile.h" +#include "chrome/test/base/testing_profile_manager.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "webkit/plugins/webplugininfo.h" + +class PluginPrefsTest : public ::testing::Test { + public: + virtual void SetUp() OVERRIDE { + plugin_prefs_ = new PluginPrefs(); + } + + void SetPolicyEnforcedPluginPatterns( + const std::set<string16>& disabled, + const std::set<string16>& disabled_exceptions, + const std::set<string16>& enabled) { + plugin_prefs_->SetPolicyEnforcedPluginPatterns( + disabled, disabled_exceptions, enabled); + } + + protected: + scoped_refptr<PluginPrefs> plugin_prefs_; +}; + +TEST_F(PluginPrefsTest, DisabledByPolicy) { + std::set<string16> disabled_plugins; + disabled_plugins.insert(ASCIIToUTF16("Disable this!")); + disabled_plugins.insert(ASCIIToUTF16("*Google*")); + SetPolicyEnforcedPluginPatterns(disabled_plugins, + std::set<string16>(), + std::set<string16>()); + + EXPECT_EQ(PluginPrefs::NO_POLICY, + plugin_prefs_->PolicyStatusForPlugin(ASCIIToUTF16("42"))); + EXPECT_EQ(PluginPrefs::POLICY_DISABLED, + plugin_prefs_->PolicyStatusForPlugin( + ASCIIToUTF16("Disable this!"))); + EXPECT_EQ(PluginPrefs::POLICY_DISABLED, + plugin_prefs_->PolicyStatusForPlugin(ASCIIToUTF16("Google Earth"))); +} + +TEST_F(PluginPrefsTest, EnabledByPolicy) { + std::set<string16> enabled_plugins; + enabled_plugins.insert(ASCIIToUTF16("Enable that!")); + enabled_plugins.insert(ASCIIToUTF16("PDF*")); + SetPolicyEnforcedPluginPatterns(std::set<string16>(), + std::set<string16>(), + enabled_plugins); + + EXPECT_EQ(PluginPrefs::NO_POLICY, + plugin_prefs_->PolicyStatusForPlugin(ASCIIToUTF16("42"))); + EXPECT_EQ(PluginPrefs::POLICY_ENABLED, + plugin_prefs_->PolicyStatusForPlugin(ASCIIToUTF16("Enable that!"))); + EXPECT_EQ(PluginPrefs::POLICY_ENABLED, + plugin_prefs_->PolicyStatusForPlugin(ASCIIToUTF16("PDF Reader"))); +} + +TEST_F(PluginPrefsTest, EnabledAndDisabledByPolicy) { + const string16 k42(ASCIIToUTF16("42")); + const string16 kEnabled(ASCIIToUTF16("Enabled")); + const string16 kEnabled2(ASCIIToUTF16("Enabled 2")); + const string16 kEnabled3(ASCIIToUTF16("Enabled 3")); + const string16 kException(ASCIIToUTF16("Exception")); + const string16 kException2(ASCIIToUTF16("Exception 2")); + const string16 kGoogleMars(ASCIIToUTF16("Google Mars")); + const string16 kGoogleEarth(ASCIIToUTF16("Google Earth")); + + std::set<string16> disabled_plugins; + std::set<string16> disabled_plugins_exceptions; + std::set<string16> enabled_plugins; + + disabled_plugins.insert(kEnabled); + disabled_plugins_exceptions.insert(kEnabled); + enabled_plugins.insert(kEnabled); + + disabled_plugins_exceptions.insert(kException); + + disabled_plugins.insert(kEnabled2); + enabled_plugins.insert(kEnabled2); + + disabled_plugins.insert(kException2); + disabled_plugins_exceptions.insert(kException2); + + disabled_plugins_exceptions.insert(kEnabled3); + enabled_plugins.insert(kEnabled3); + + SetPolicyEnforcedPluginPatterns(disabled_plugins, + disabled_plugins_exceptions, + enabled_plugins); + + EXPECT_EQ(PluginPrefs::NO_POLICY, plugin_prefs_->PolicyStatusForPlugin(k42)); + + EXPECT_EQ(PluginPrefs::POLICY_ENABLED, + plugin_prefs_->PolicyStatusForPlugin(kEnabled)); + EXPECT_EQ(PluginPrefs::POLICY_ENABLED, + plugin_prefs_->PolicyStatusForPlugin(kEnabled2)); + EXPECT_EQ(PluginPrefs::POLICY_ENABLED, + plugin_prefs_->PolicyStatusForPlugin(kEnabled3)); + + EXPECT_EQ(PluginPrefs::NO_POLICY, + plugin_prefs_->PolicyStatusForPlugin(kException)); + EXPECT_EQ(PluginPrefs::NO_POLICY, + plugin_prefs_->PolicyStatusForPlugin(kException2)); + + disabled_plugins.clear(); + disabled_plugins_exceptions.clear(); + enabled_plugins.clear(); + + disabled_plugins.insert(ASCIIToUTF16("*")); + disabled_plugins_exceptions.insert(ASCIIToUTF16("*Google*")); + enabled_plugins.insert(kGoogleEarth); + + SetPolicyEnforcedPluginPatterns(disabled_plugins, + disabled_plugins_exceptions, + enabled_plugins); + + EXPECT_EQ(PluginPrefs::POLICY_ENABLED, + plugin_prefs_->PolicyStatusForPlugin(kGoogleEarth)); + EXPECT_EQ(PluginPrefs::NO_POLICY, + plugin_prefs_->PolicyStatusForPlugin(kGoogleMars)); + EXPECT_EQ(PluginPrefs::POLICY_DISABLED, + plugin_prefs_->PolicyStatusForPlugin(k42)); +} + +TEST_F(PluginPrefsTest, DisableGlobally) { + MessageLoop message_loop; + BrowserThread ui_thread(BrowserThread::UI, &message_loop); + BrowserThread file_thread(BrowserThread::FILE, &message_loop); + + TestingBrowserProcess* browser_process = + static_cast<TestingBrowserProcess*>(g_browser_process); + TestingProfileManager profile_manager(browser_process); + ASSERT_TRUE(profile_manager.SetUp()); + + TestingProfile* profile_1 = + profile_manager.CreateTestingProfile("Profile 1"); + PluginPrefs* plugin_prefs = PluginPrefs::GetForTestingProfile(profile_1); + ASSERT_TRUE(plugin_prefs); + + webkit::WebPluginInfo plugin(ASCIIToUTF16("Foo"), + FilePath(FILE_PATH_LITERAL("/path/too/foo")), + ASCIIToUTF16("1.0.0"), + ASCIIToUTF16("Foo plug-in")); + PluginPrefs::EnablePluginGlobally(false, plugin.path); + + EXPECT_FALSE(plugin_prefs->IsPluginEnabled(plugin)); + + TestingProfile* profile_2 = + profile_manager.CreateTestingProfile("Profile 2"); + PluginPrefs* plugin_prefs_2 = PluginPrefs::GetForTestingProfile(profile_2); + ASSERT_TRUE(plugin_prefs); + EXPECT_FALSE(plugin_prefs_2->IsPluginEnabled(plugin)); +} diff --git a/chrome/browser/printing/print_preview_tab_controller.cc b/chrome/browser/printing/print_preview_tab_controller.cc index aeb32b9..1557e0d 100644 --- a/chrome/browser/printing/print_preview_tab_controller.cc +++ b/chrome/browser/printing/print_preview_tab_controller.cc @@ -52,11 +52,11 @@ void EnableInternalPDFPluginForTab(TabContentsWrapper* preview_tab) { } } if (internal_pdf_group) { - std::vector<WebPluginInfo> plugins = internal_pdf_group->web_plugin_infos(); + const std::vector<WebPluginInfo>& plugins = + internal_pdf_group->web_plugin_infos(); DCHECK_EQ(plugins.size(), 1U); webkit::WebPluginInfo plugin = plugins[0]; - plugin.enabled = WebPluginInfo::USER_ENABLED; ChromePluginServiceFilter::GetInstance()->OverridePluginForTab( preview_tab->render_view_host()->process()->id(), preview_tab->render_view_host()->routing_id(), diff --git a/chrome/browser/ui/webui/plugins_ui.cc b/chrome/browser/ui/webui/plugins_ui.cc index 710f423..a4f0dfe 100644 --- a/chrome/browser/ui/webui/plugins_ui.cc +++ b/chrome/browser/ui/webui/plugins_ui.cc @@ -36,6 +36,9 @@ #include "ui/base/resource/resource_bundle.h" #include "webkit/plugins/npapi/plugin_list.h" +using webkit::npapi::PluginGroup; +using webkit::WebPluginInfo; + namespace { ChromeWebUIDataSource* CreatePluginsUIHTMLSource(bool enable_controls) { @@ -125,17 +128,17 @@ class PluginsDOMHandler : public WebUIMessageHandler, private: // Loads the plugins on the FILE thread. static void LoadPluginsOnFileThread( - std::vector<webkit::npapi::PluginGroup>* groups, Task* task); + std::vector<PluginGroup>* groups, Task* task); // Used in conjunction with ListWrapper to avoid any memory leaks. static void EnsurePluginGroupsDeleted( - std::vector<webkit::npapi::PluginGroup>* groups); + std::vector<PluginGroup>* groups); // Call this to start getting the plugins on the UI thread. void LoadPlugins(); // Called on the UI thread when the plugin information is ready. - void PluginsLoaded(const std::vector<webkit::npapi::PluginGroup>* groups); + void PluginsLoaded(const std::vector<PluginGroup>* groups); NotificationRegistrar registrar_; @@ -181,13 +184,6 @@ void PluginsDOMHandler::HandleRequestPluginsData(const ListValue* args) { void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) { Profile* profile = Profile::FromWebUI(web_ui_); - // If a non-first-profile user tries to trigger these methods sneakily, - // forbid it. -#if !defined(OS_CHROMEOS) - if (!profile->GetOriginalProfile()->first_launched()) - return; -#endif - // Be robust in accepting badness since plug-ins display HTML (hence // JavaScript). if (args->GetSize() != 3) @@ -209,27 +205,20 @@ void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) { if (enable) { // See http://crbug.com/50105 for background. string16 adobereader = ASCIIToUTF16( - webkit::npapi::PluginGroup::kAdobeReaderGroupName); + PluginGroup::kAdobeReaderGroupName); string16 internalpdf = ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName); - if (group_name == adobereader) { + if (group_name == adobereader) plugin_prefs->EnablePluginGroup(false, internalpdf); - } else if (group_name == internalpdf) { + else if (group_name == internalpdf) plugin_prefs->EnablePluginGroup(false, adobereader); - } } } else { FilePath::StringType file_path; if (!args->GetString(0, &file_path)) return; - plugin_prefs->EnablePlugin(enable, FilePath(file_path)); } - - // 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 - // plugin. <http://crbug.com/39101> - plugin_prefs->UpdatePreferences(0); } void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) { @@ -254,7 +243,7 @@ void PluginsDOMHandler::Observe(int type, } void PluginsDOMHandler::LoadPluginsOnFileThread( - std::vector<webkit::npapi::PluginGroup>* groups, + std::vector<PluginGroup>* groups, Task* task) { webkit::npapi::PluginList::Singleton()->GetPluginGroups(true, groups); @@ -267,7 +256,7 @@ void PluginsDOMHandler::LoadPluginsOnFileThread( } void PluginsDOMHandler::EnsurePluginGroupsDeleted( - std::vector<webkit::npapi::PluginGroup>* groups) { + std::vector<PluginGroup>* groups) { delete groups; } @@ -275,8 +264,7 @@ void PluginsDOMHandler::LoadPlugins() { if (!get_plugins_factory_.empty()) return; - std::vector<webkit::npapi::PluginGroup>* groups = - new std::vector<webkit::npapi::PluginGroup>; + std::vector<PluginGroup>* groups = new std::vector<PluginGroup>; Task* task = get_plugins_factory_.NewRunnableMethod( &PluginsDOMHandler::PluginsLoaded, groups); @@ -287,13 +275,103 @@ void PluginsDOMHandler::LoadPlugins() { &PluginsDOMHandler::LoadPluginsOnFileThread, groups, task)); } -void PluginsDOMHandler::PluginsLoaded( - const std::vector<webkit::npapi::PluginGroup>* groups) { +void PluginsDOMHandler::PluginsLoaded(const std::vector<PluginGroup>* groups) { + PluginPrefs* plugin_prefs = + PluginPrefs::GetForProfile(Profile::FromWebUI(web_ui_)); + + bool all_plugins_enabled_by_policy = true; + bool all_plugins_disabled_by_policy = true; + // 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. + ListValue* plugin_files = new ListValue(); + const PluginGroup& group = (*groups)[i]; + string16 group_name = group.GetGroupName(); + bool group_enabled = false; + const WebPluginInfo* active_plugin = NULL; + for (size_t j = 0; j < group.web_plugin_infos().size(); ++j) { + const WebPluginInfo& group_plugin = group.web_plugin_infos()[j]; + + DictionaryValue* plugin_file = new DictionaryValue(); + plugin_file->SetString("name", group_plugin.name); + plugin_file->SetString("description", group_plugin.desc); + plugin_file->SetString("path", group_plugin.path.value()); + plugin_file->SetString("version", group_plugin.version); + + ListValue* mime_types = new ListValue(); + const std::vector<webkit::WebPluginMimeType>& plugin_mime_types = + group_plugin.mime_types; + for (size_t k = 0; k < plugin_mime_types.size(); ++k) { + DictionaryValue* mime_type = new DictionaryValue(); + mime_type->SetString("mimeType", plugin_mime_types[k].mime_type); + mime_type->SetString("description", plugin_mime_types[k].description); + + ListValue* file_extensions = new ListValue(); + const std::vector<std::string>& mime_file_extensions = + plugin_mime_types[k].file_extensions; + for (size_t l = 0; l < mime_file_extensions.size(); ++l) + file_extensions->Append(new StringValue(mime_file_extensions[l])); + mime_type->Set("fileExtensions", file_extensions); + + mime_types->Append(mime_type); + } + plugin_file->Set("mimeTypes", mime_types); + + bool plugin_enabled = plugin_prefs->IsPluginEnabled(group_plugin); + + if (!active_plugin || (plugin_enabled && !group_enabled)) + active_plugin = &group_plugin; + group_enabled = plugin_enabled || group_enabled; + + std::string enabled_mode; + PluginPrefs::PolicyStatus plugin_status = + plugin_prefs->PolicyStatusForPlugin(group_plugin.name); + PluginPrefs::PolicyStatus group_status = + plugin_prefs->PolicyStatusForPlugin(group_name); + if (plugin_status == PluginPrefs::POLICY_ENABLED || + group_status == PluginPrefs::POLICY_ENABLED) { + enabled_mode = "enabledByPolicy"; + } else { + all_plugins_enabled_by_policy = false; + if (plugin_status == PluginPrefs::POLICY_DISABLED || + group_status == PluginPrefs::POLICY_DISABLED) { + enabled_mode = "disabledByPolicy"; + } else { + all_plugins_disabled_by_policy = false; + if (plugin_enabled) { + enabled_mode = "enabledByUser"; + } else { + enabled_mode = "disabledByUser"; + } + } + } + plugin_file->SetString("enabledMode", enabled_mode); + + plugin_files->Append(plugin_file); + } + DictionaryValue* group_data = new DictionaryValue(); + + group_data->Set("plugin_files", plugin_files); + group_data->SetString("name", group_name); + group_data->SetString("description", active_plugin->desc); + group_data->SetString("version", active_plugin->version); + group_data->SetBoolean("critical", group.IsVulnerable(*active_plugin)); + group_data->SetString("update_url", group.GetUpdateURL()); + + std::string enabled_mode; + if (all_plugins_enabled_by_policy) { + enabled_mode = "enabledByPolicy"; + } else if (all_plugins_disabled_by_policy) { + enabled_mode = "disabledByPolicy"; + } else if (group_enabled) { + enabled_mode = "enabledByUser"; + } else { + enabled_mode = "disabledByUser"; + } + group_data->SetString("enabledMode", enabled_mode); + + plugin_groups_data->Append(group_data); } DictionaryValue results; results.Set("plugins", plugin_groups_data); @@ -312,11 +390,9 @@ PluginsUI::PluginsUI(TabContents* contents) : ChromeWebUI(contents) { AddMessageHandler((new PluginsDOMHandler())->Attach(this)); // Set up the chrome://plugins/ source. + // TODO(bauerb): Remove |enable_controls| & co. bool enable_controls = true; Profile* profile = Profile::FromBrowserContext(contents->browser_context()); -#if !defined(OS_CHROMEOS) - enable_controls = profile->GetOriginalProfile()->first_launched(); -#endif profile->GetChromeURLDataManager()->AddDataSource( CreatePluginsUIHTMLSource(enable_controls)); } diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 067b18c..380bc4a 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1348,6 +1348,7 @@ 'browser/password_manager/password_store_win_unittest.cc', 'browser/password_manager/password_store_x_unittest.cc', 'browser/plugin_exceptions_table_model_unittest.cc', + 'browser/plugin_prefs_unittest.cc', 'browser/policy/asynchronous_policy_loader_unittest.cc', 'browser/policy/asynchronous_policy_provider_unittest.cc', 'browser/policy/asynchronous_policy_test_base.cc', diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc index e8c6d57..5b64ee4 100644 --- a/chrome/renderer/chrome_content_renderer_client.cc +++ b/chrome/renderer/chrome_content_renderer_client.cc @@ -331,9 +331,8 @@ WebPlugin* ChromeContentRendererClient::CreatePluginImpl( return NULL; } - const webkit::npapi::PluginGroup* group = - webkit::npapi::PluginList::Singleton()->GetPluginGroup(info); - DCHECK(group != NULL); + scoped_ptr<webkit::npapi::PluginGroup> group( + webkit::npapi::PluginList::Singleton()->GetPluginGroup(info)); ContentSetting plugin_setting = CONTENT_SETTING_DEFAULT; std::string resource; @@ -356,14 +355,14 @@ WebPlugin* ChromeContentRendererClient::CreatePluginImpl( ContentSetting outdated_policy = CONTENT_SETTING_ASK; ContentSetting authorize_policy = CONTENT_SETTING_ASK; - if (group->IsVulnerable() || group->RequiresAuthorization()) { + if (group->IsVulnerable(info) || group->RequiresAuthorization(info)) { // These policies are dynamic and can changed at runtime, so they aren't // cached here. render_view->Send(new ChromeViewHostMsg_GetPluginPolicies( &outdated_policy, &authorize_policy)); } - if (group->IsVulnerable()) { + if (group->IsVulnerable(info)) { if (outdated_policy == CONTENT_SETTING_ASK || outdated_policy == CONTENT_SETTING_BLOCK) { if (outdated_policy == CONTENT_SETTING_ASK) { @@ -383,7 +382,7 @@ WebPlugin* ChromeContentRendererClient::CreatePluginImpl( ContentSetting host_setting = observer->GetContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS); - if (group->RequiresAuthorization() && + if (group->RequiresAuthorization(info) && authorize_policy == CONTENT_SETTING_ASK && (plugin_setting == CONTENT_SETTING_ALLOW || plugin_setting == CONTENT_SETTING_ASK) && diff --git a/content/common/pepper_plugin_registry.cc b/content/common/pepper_plugin_registry.cc index 9fb1381..5bb2f29 100644 --- a/content/common/pepper_plugin_registry.cc +++ b/content/common/pepper_plugin_registry.cc @@ -89,22 +89,12 @@ webkit::WebPluginInfo PepperPluginInfo::ToWebPluginInfo() const { info.desc = ASCIIToUTF16(description); info.mime_types = mime_types; - webkit::WebPluginInfo::EnabledStates enabled_state = - webkit::WebPluginInfo::USER_ENABLED_POLICY_UNMANAGED; - - if (!enabled) { - enabled_state = - webkit::WebPluginInfo::USER_DISABLED_POLICY_UNMANAGED; - } - - info.enabled = enabled_state; return info; } PepperPluginInfo::PepperPluginInfo() : is_internal(false), - is_out_of_process(false), - enabled(true) { + is_out_of_process(false) { } PepperPluginInfo::~PepperPluginInfo() { @@ -119,7 +109,6 @@ bool MakePepperPluginInfo(const webkit::WebPluginInfo& webplugin_info, webplugin_info.type == webkit::WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS; - pepper_info->enabled = webkit::IsPluginEnabled(webplugin_info); pepper_info->path = FilePath(webplugin_info.path); pepper_info->name = UTF16ToASCII(webplugin_info.name); pepper_info->description = UTF16ToASCII(webplugin_info.desc); diff --git a/content/common/pepper_plugin_registry.h b/content/common/pepper_plugin_registry.h index ee2404a4..b3b94ab 100644 --- a/content/common/pepper_plugin_registry.h +++ b/content/common/pepper_plugin_registry.h @@ -33,9 +33,6 @@ struct CONTENT_EXPORT PepperPluginInfo { // True when this plugin should be run out of process. Defaults to false. bool is_out_of_process; - // Whether the plugin is enabled. Defaults to true. - bool enabled; - FilePath path; // Internal plugins have "internal-[name]" as path. std::string name; std::string description; diff --git a/content/common/view_messages.h b/content/common/view_messages.h index 1165ffc..e2612c2e 100644 --- a/content/common/view_messages.h +++ b/content/common/view_messages.h @@ -466,7 +466,6 @@ IPC_STRUCT_TRAITS_BEGIN(webkit::WebPluginInfo) IPC_STRUCT_TRAITS_MEMBER(version) IPC_STRUCT_TRAITS_MEMBER(desc) IPC_STRUCT_TRAITS_MEMBER(mime_types) - IPC_STRUCT_TRAITS_MEMBER(enabled) IPC_STRUCT_TRAITS_MEMBER(type) IPC_STRUCT_TRAITS_END() diff --git a/webkit/plugins/npapi/plugin_group.cc b/webkit/plugins/npapi/plugin_group.cc index 1f5745e..b0c89f4 100644 --- a/webkit/plugins/npapi/plugin_group.cc +++ b/webkit/plugins/npapi/plugin_group.cc @@ -27,83 +27,6 @@ const char* PluginGroup::kRealPlayerGroupName = "RealPlayer"; const char* PluginGroup::kSilverlightGroupName = "Silverlight"; const char* PluginGroup::kWindowsMediaPlayerGroupName = "Windows Media Player"; -/*static*/ -std::set<string16>* PluginGroup::policy_disabled_plugin_patterns_; -/*static*/ -std::set<string16>* PluginGroup::policy_disabled_plugin_exception_patterns_; -/*static*/ -std::set<string16>* PluginGroup::policy_enabled_plugin_patterns_; - -/*static*/ -void PluginGroup::SetPolicyEnforcedPluginPatterns( - const std::set<string16>& plugins_disabled, - const std::set<string16>& plugins_disabled_exceptions, - const std::set<string16>& plugins_enabled) { - if (!policy_disabled_plugin_patterns_) - policy_disabled_plugin_patterns_ = new std::set<string16>(plugins_disabled); - else - *policy_disabled_plugin_patterns_ = plugins_disabled; - - if (!policy_disabled_plugin_exception_patterns_) - policy_disabled_plugin_exception_patterns_ = - new std::set<string16>(plugins_disabled_exceptions); - else - *policy_disabled_plugin_exception_patterns_ = plugins_disabled_exceptions; - - if (!policy_enabled_plugin_patterns_) - policy_enabled_plugin_patterns_ = new std::set<string16>(plugins_enabled); - else - *policy_enabled_plugin_patterns_ = plugins_enabled; -} - -/*static*/ -bool PluginGroup::IsStringMatchedInSet(const string16& name, - const std::set<string16>* pattern_set) { - if (!pattern_set) - return false; - - std::set<string16>::const_iterator pattern(pattern_set->begin()); - while (pattern != pattern_set->end()) { - if (MatchPattern(name, *pattern)) - return true; - ++pattern; - } - - return false; -} - -/*static*/ -bool PluginGroup::IsPluginNameDisabledByPolicy(const string16& plugin_name) { - // A plugin that matches some "disabled" pattern but also matches an "enabled" - // pattern will be enabled. Example: disable "*", enable "Flash, Java". - // Same for matching an "exception" pattern. - return IsStringMatchedInSet(plugin_name, policy_disabled_plugin_patterns_) && - !IsStringMatchedInSet(plugin_name, policy_enabled_plugin_patterns_) && - !IsStringMatchedInSet(plugin_name, - policy_disabled_plugin_exception_patterns_); -} - -/*static*/ -bool PluginGroup::IsPluginFileNameDisabledByPolicy(const string16& plugin_name, - const string16& group_name) { - // This handles a specific plugin within a group that is allowed, - // but whose name matches a disabled pattern. - // Example: disable "*", exception "Java". - bool group_has_exception = IsStringMatchedInSet( - group_name, - policy_disabled_plugin_exception_patterns_); - - return !IsPluginNameEnabledByPolicy(plugin_name) && - !group_has_exception && - IsPluginNameDisabledByPolicy(plugin_name); -} - -/*static*/ -bool PluginGroup::IsPluginNameEnabledByPolicy(const string16& plugin_name) { - // There are no exceptions to enabled plugins. - return IsStringMatchedInSet(plugin_name, policy_enabled_plugin_patterns_); -} - VersionRange::VersionRange(const VersionRangeDefinition& definition) : low_str(definition.version_matcher_low), high_str(definition.version_matcher_high), @@ -145,20 +68,15 @@ PluginGroup::PluginGroup(const string16& group_name, : identifier_(identifier), group_name_(group_name), name_matcher_(name_matcher), - update_url_(update_url), - enabled_(false), - version_(Version::GetVersionFromString("0")) { + update_url_(update_url) { } void PluginGroup::InitFrom(const PluginGroup& other) { identifier_ = other.identifier_; group_name_ = other.group_name_; name_matcher_ = other.name_matcher_; - description_ = other.description_; update_url_ = other.update_url_; - enabled_ = other.enabled_; version_ranges_ = other.version_ranges_; - version_.reset(other.version_->Clone()); web_plugin_infos_ = other.web_plugin_infos_; } @@ -256,33 +174,6 @@ Version* PluginGroup::CreateVersionFromString(const string16& version_string) { return Version::GetVersionFromString(version); } -void PluginGroup::UpdateActivePlugin(const WebPluginInfo& plugin) { - // A group is enabled if any of the files are enabled. - if (IsPluginEnabled(plugin)) { - // The description of the group needs update either when it's state is - // about to change to enabled or if has never been set. - if (!enabled_ || description_.empty()) - UpdateDescriptionAndVersion(plugin); - // In case an enabled plugin has been added to a group that is currently - // disabled then we should enable the group. - if (!enabled_) - enabled_ = true; - } else { - // If this is the first plugin and it's disabled, - // use its description for now. - if (description_.empty()) - UpdateDescriptionAndVersion(plugin); - } -} - -void PluginGroup::UpdateDescriptionAndVersion(const WebPluginInfo& plugin) { - description_ = plugin.desc; - if (Version* new_version = CreateVersionFromString(plugin.version)) - version_.reset(new_version); - else - version_.reset(Version::GetVersionFromString("0")); -} - void PluginGroup::AddPlugin(const WebPluginInfo& plugin) { // Check if this group already contains this plugin. for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { @@ -292,58 +183,21 @@ void PluginGroup::AddPlugin(const WebPluginInfo& plugin) { } } web_plugin_infos_.push_back(plugin); - UpdateActivePlugin(web_plugin_infos_.back()); } bool PluginGroup::RemovePlugin(const FilePath& filename) { bool did_remove = false; - ResetGroupState(); for (size_t i = 0; i < web_plugin_infos_.size();) { if (web_plugin_infos_[i].path == filename) { web_plugin_infos_.erase(web_plugin_infos_.begin() + i); did_remove = true; } else { - UpdateActivePlugin(web_plugin_infos_[i]); i++; } } return did_remove; } -bool PluginGroup::EnablePlugin(const FilePath& filename) { - bool did_enable = false; - ResetGroupState(); - for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { - if (web_plugin_infos_[i].path == filename) { - did_enable = Enable( - &web_plugin_infos_[i], - IsPluginNameEnabledByPolicy(web_plugin_infos_[i].name) ? - WebPluginInfo::USER_ENABLED_POLICY_ENABLED : - WebPluginInfo::USER_ENABLED); - } - UpdateActivePlugin(web_plugin_infos_[i]); - } - return did_enable; -} - -bool PluginGroup::DisablePlugin(const FilePath& filename) { - bool did_disable = false; - ResetGroupState(); - for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { - if (web_plugin_infos_[i].path == filename) { - // We are only called for user intervention however we should respect a - // policy that might as well be active on this plugin. - did_disable = Disable( - &web_plugin_infos_[i], - IsPluginNameDisabledByPolicy(web_plugin_infos_[i].name) ? - WebPluginInfo::USER_DISABLED_POLICY_DISABLED : - WebPluginInfo::USER_DISABLED); - } - UpdateActivePlugin(web_plugin_infos_[i]); - } - return did_disable; -} - string16 PluginGroup::GetGroupName() const { if (!group_name_.empty()) return group_name_; @@ -365,91 +219,6 @@ bool PluginGroup::ContainsPlugin(const FilePath& path) const { return false; } - -DictionaryValue* PluginGroup::GetSummary() const { - DictionaryValue* result = new DictionaryValue(); - result->SetString("name", GetGroupName()); - result->SetBoolean("enabled", enabled_); - return result; -} - -DictionaryValue* PluginGroup::GetDataForUI() const { - string16 name = GetGroupName(); - DictionaryValue* result = new DictionaryValue(); - result->SetString("name", name); - result->SetString("description", description_); - result->SetString("version", version_->GetString()); - result->SetString("update_url", update_url_); - result->SetBoolean("critical", IsVulnerable()); - - bool group_disabled_by_policy = IsPluginNameDisabledByPolicy(name); - bool group_enabled_by_policy = IsPluginNameEnabledByPolicy(name); - ListValue* plugin_files = new ListValue(); - bool all_plugins_disabled_by_policy = true; - bool all_plugins_enabled_by_policy = true; - for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { - DictionaryValue* plugin_file = new DictionaryValue(); - plugin_file->SetString("name", web_plugin_infos_[i].name); - plugin_file->SetString("description", web_plugin_infos_[i].desc); - plugin_file->SetString("path", web_plugin_infos_[i].path.value()); - plugin_file->SetString("version", web_plugin_infos_[i].version); - - bool plugin_disabled_by_policy = group_disabled_by_policy || - ((web_plugin_infos_[i].enabled & WebPluginInfo::POLICY_DISABLED) != 0); - bool plugin_enabled_by_policy = group_enabled_by_policy || - ((web_plugin_infos_[i].enabled & WebPluginInfo::POLICY_ENABLED) != 0); - - if (!plugin_disabled_by_policy) - all_plugins_disabled_by_policy = false; - if (!plugin_enabled_by_policy) - all_plugins_enabled_by_policy = false; - - if (plugin_disabled_by_policy) { - plugin_file->SetString("enabledMode", "disabledByPolicy"); - } else if (plugin_enabled_by_policy) { - plugin_file->SetString("enabledMode", "enabledByPolicy"); - } else { - plugin_file->SetString( - "enabledMode", IsPluginEnabled(web_plugin_infos_[i]) ? - "enabledByUser" : "disabledByUser"); - } - - ListValue* mime_types = new ListValue(); - const std::vector<WebPluginMimeType>& plugin_mime_types = - web_plugin_infos_[i].mime_types; - for (size_t j = 0; j < plugin_mime_types.size(); ++j) { - DictionaryValue* mime_type = new DictionaryValue(); - mime_type->SetString("mimeType", plugin_mime_types[j].mime_type); - mime_type->SetString("description", plugin_mime_types[j].description); - - ListValue* file_extensions = new ListValue(); - const std::vector<std::string>& mime_file_extensions = - plugin_mime_types[j].file_extensions; - for (size_t k = 0; k < mime_file_extensions.size(); ++k) - file_extensions->Append(new StringValue(mime_file_extensions[k])); - mime_type->Set("fileExtensions", file_extensions); - - mime_types->Append(mime_type); - } - plugin_file->Set("mimeTypes", mime_types); - - plugin_files->Append(plugin_file); - } - - if (group_disabled_by_policy || all_plugins_disabled_by_policy) { - result->SetString("enabledMode", "disabledByPolicy"); - } else if (group_enabled_by_policy || all_plugins_enabled_by_policy) { - result->SetString("enabledMode", "enabledByPolicy"); - } else { - result->SetString("enabledMode", enabled_ ? - "enabledByUser" : - "disabledByUser"); - } - result->Set("plugin_files", plugin_files); - - return result; -} - /*static*/ bool PluginGroup::IsVersionInRange(const Version& version, const VersionRange& range) { @@ -472,34 +241,26 @@ bool PluginGroup::IsPluginOutdated(const Version& plugin_version, return false; } -bool PluginGroup::IsWhitelisted() const { - for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { - if (web_plugin_infos_[i].enabled & WebPluginInfo::POLICY_ENABLED) - return true; - } - return false; -} - // Returns true if the latest version of this plugin group is vulnerable. -bool PluginGroup::IsVulnerable() const { - // A plugin isn't considered vulnerable if it's explicitly whitelisted. - if (IsWhitelisted()) +bool PluginGroup::IsVulnerable(const WebPluginInfo& plugin) const { + scoped_ptr<Version> version(CreateVersionFromString(plugin.version)); + if (!version.get()) return false; for (size_t i = 0; i < version_ranges_.size(); ++i) { - if (IsPluginOutdated(*version_, version_ranges_[i])) + if (IsPluginOutdated(*version, version_ranges_[i])) return true; } return false; } -bool PluginGroup::RequiresAuthorization() const { - // A plugin doesn't require authorization if it's explicitly whitelisted. - if (IsWhitelisted()) +bool PluginGroup::RequiresAuthorization(const WebPluginInfo& plugin) const { + scoped_ptr<Version> version(CreateVersionFromString(plugin.version)); + if (!version.get()) return false; for (size_t i = 0; i < version_ranges_.size(); ++i) { - if (IsVersionInRange(*version_, version_ranges_[i]) && + if (IsVersionInRange(*version, version_ranges_[i]) && version_ranges_[i].requires_authorization) return true; } @@ -510,114 +271,5 @@ bool PluginGroup::IsEmpty() const { return web_plugin_infos_.empty(); } -bool PluginGroup::EnableGroup(bool enable) { - bool group_disabled_by_policy = IsPluginNameDisabledByPolicy(group_name_); - bool group_enabled_by_policy = IsPluginNameEnabledByPolicy(group_name_); - - // We can't enable nor disable groups controlled by policy. - if ((group_disabled_by_policy && enable) || - (group_enabled_by_policy && !enable)) - return false; - - ResetGroupState(); - for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { - bool policy_enabled = - IsPluginNameEnabledByPolicy(web_plugin_infos_[i].name); - bool policy_disabled = - IsPluginFileNameDisabledByPolicy(web_plugin_infos_[i].name, - group_name_); - if (policy_disabled) { - Disable(&web_plugin_infos_[i], WebPluginInfo::POLICY_DISABLED); - } else if (policy_enabled) { - Enable(&web_plugin_infos_[i], WebPluginInfo::POLICY_ENABLED); - } else if (enable) { - Enable(&web_plugin_infos_[i], WebPluginInfo::USER_ENABLED); - } else { - Disable(&web_plugin_infos_[i], WebPluginInfo::USER_DISABLED); - } - UpdateActivePlugin(web_plugin_infos_[i]); - } - return enabled_ == enable; -} - -void PluginGroup::EnforceGroupPolicy() { - bool group_disabled_by_policy = IsPluginNameDisabledByPolicy(group_name_); - bool group_enabled_by_policy = IsPluginNameEnabledByPolicy(group_name_); - - ResetGroupState(); - for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { - bool policy_enabled = - group_enabled_by_policy || - IsPluginNameEnabledByPolicy(web_plugin_infos_[i].name); - bool policy_disabled = - !policy_enabled && - (group_disabled_by_policy || - IsPluginFileNameDisabledByPolicy(web_plugin_infos_[i].name, - group_name_)); - if (policy_disabled) { - Disable(&web_plugin_infos_[i], WebPluginInfo::POLICY_DISABLED); - } else if (policy_enabled) { - Enable(&web_plugin_infos_[i], WebPluginInfo::POLICY_ENABLED); - } else { - // If not managed, use the user's preference. - if ((web_plugin_infos_[i].enabled & WebPluginInfo::USER_MASK) == - WebPluginInfo::USER_ENABLED) { - Enable(&web_plugin_infos_[i], WebPluginInfo::POLICY_UNMANAGED); - } else { - Disable(&web_plugin_infos_[i], WebPluginInfo::POLICY_UNMANAGED); - } - } - UpdateActivePlugin(web_plugin_infos_[i]); - } -} - -void PluginGroup::ResetGroupState() { - enabled_ = false; - description_.clear(); - version_.reset(Version::GetVersionFromString("0")); -} - -/*static*/ -bool PluginGroup::SetPluginState(WebPluginInfo* plugin, - int new_reason, - bool state_changes) { - // If we are only stripping the policy then mask the policy bits. - if (new_reason == WebPluginInfo::POLICY_UNMANAGED) { - plugin->enabled &= WebPluginInfo::USER_MASK; - return true; - } - if (new_reason & WebPluginInfo::MANAGED_MASK) { - // Policy-enforced change: preserve the user's preference, and override - // a possible previous policy flag. - plugin->enabled = (plugin->enabled & WebPluginInfo::USER_MASK) | new_reason; - } else if (state_changes && (plugin->enabled & WebPluginInfo::MANAGED_MASK)) { - // Refuse change when managed. - return false; - } else { - // Accept the user update, but keep the policy flag if present. - plugin->enabled = (plugin->enabled & WebPluginInfo::MANAGED_MASK) | - new_reason; - } - return true; -} - -/*static*/ -bool PluginGroup::Enable(WebPluginInfo* plugin, int new_reason) { - DCHECK(new_reason == WebPluginInfo::USER_ENABLED || - new_reason == WebPluginInfo::POLICY_ENABLED || - new_reason == WebPluginInfo::USER_ENABLED_POLICY_ENABLED || - new_reason == WebPluginInfo::POLICY_UNMANAGED); - return SetPluginState(plugin, new_reason, !IsPluginEnabled(*plugin)); -} - -/*static*/ -bool PluginGroup::Disable(WebPluginInfo* plugin, int new_reason) { - DCHECK(new_reason == WebPluginInfo::USER_DISABLED || - new_reason == WebPluginInfo::POLICY_DISABLED || - new_reason == WebPluginInfo::USER_DISABLED_POLICY_DISABLED || - new_reason == WebPluginInfo::POLICY_UNMANAGED); - return SetPluginState(plugin, new_reason, IsPluginEnabled(*plugin)); -} - } // namespace npapi } // namespace webkit diff --git a/webkit/plugins/npapi/plugin_group.h b/webkit/plugins/npapi/plugin_group.h index da80db8..e721b3b 100644 --- a/webkit/plugins/npapi/plugin_group.h +++ b/webkit/plugins/npapi/plugin_group.h @@ -6,8 +6,6 @@ #define WEBKIT_PLUGINS_NPAPI_PLUGIN_GROUP_H_ #pragma once -#include <map> -#include <set> #include <string> #include <vector> @@ -97,24 +95,6 @@ class PluginGroup { PluginGroup& operator=(const PluginGroup& other); - // Configures the set of plugin name patterns for enabling and disabling - // plugins via enterprise configuration management. - static void SetPolicyEnforcedPluginPatterns( - const std::set<string16>& plugins_disabled, - const std::set<string16>& plugins_disabled_exceptions, - const std::set<string16>& plugins_enabled); - - // Tests whether |plugin_name| is disabled by policy. - static bool IsPluginNameDisabledByPolicy(const string16& plugin_name); - - // Tests whether |plugin_name| within the plugin group |group_name| is - // disabled by policy. - static bool IsPluginFileNameDisabledByPolicy(const string16& plugin_name, - const string16& group_name); - - // Tests whether |plugin_name| is enabled by policy. - static bool IsPluginNameEnabledByPolicy(const string16& plugin_name); - // Returns true if the given plugin matches this group. bool Match(const webkit::WebPluginInfo& plugin) const; @@ -124,24 +104,6 @@ class PluginGroup { // Removes a plugin from the group by its path. bool RemovePlugin(const FilePath& filename); - // The two following functions enable/disable a plugin given its filename. The - // function returns true if the plugin could be enabled/disabled. Plugins - // might not get enabled/disabled if they are controlled by policy or are - // already in the wanted state. - bool EnablePlugin(const FilePath& filename); - bool DisablePlugin(const FilePath& filename); - - // Enables/disables this group. This enables/disables all plugins in the - // group. - bool EnableGroup(bool enable); - - // Checks whether the group should be disabled/enabled by a policy and puts - // it in the needed state. Updates all contained plugins too. - void EnforceGroupPolicy(); - - // Returns whether the plugin group is enabled or not. - bool Enabled() const { return enabled_; } - // Returns a unique identifier for this group, if one is defined, or the empty // string otherwise. const std::string& identifier() const { return identifier_; } @@ -155,36 +117,21 @@ class PluginGroup { // is empty. string16 GetGroupName() const; - // Returns all plugins added to the group. - const std::vector<webkit::WebPluginInfo>& web_plugins_info() const { - return web_plugin_infos_; - } - // Checks whether a plugin exists in the group with the given path. bool ContainsPlugin(const FilePath& path) const; - // Returns the description of the highest-priority plug-in in the group. - const string16& description() const { return description_; } - - // Returns a DictionaryValue with data to display in the UI. - base::DictionaryValue* GetDataForUI() const; - - // Returns a DictionaryValue with data to save in the preferences. - base::DictionaryValue* GetSummary() const; - // Returns the update URL. std::string GetUpdateURL() const { return update_url_; } // Returns true if this plugin group is whitelisted. bool IsWhitelisted() const; - // Returns true if the highest-priority plugin in this group has known - // security problems. - bool IsVulnerable() const; + // Returns true if |plugin| in this group has known security problems. + bool IsVulnerable(const WebPluginInfo& plugin) const; - // Returns true if this plug-in group always requires user authorization - // to run. - bool RequiresAuthorization() const; + // Returns true if |plugin| in this plug-in group always requires user + // authorization to run. + bool RequiresAuthorization(const WebPluginInfo& plugin) const; // Check if the group has no plugins. Could happen after a reload if the plug- // in has disappeared from the pc (or in the process of updating). @@ -194,7 +141,7 @@ class PluginGroup { // in accepting weird version strings than Version::GetFromString(). static Version* CreateVersionFromString(const string16& version_string); - std::vector<webkit::WebPluginInfo> web_plugin_infos() { + const std::vector<webkit::WebPluginInfo>& web_plugin_infos() const { return web_plugin_infos_; } @@ -237,54 +184,17 @@ class PluginGroup { void InitFrom(const PluginGroup& other); - // Set the description and version for this plugin group from the - // given plug-in. - void UpdateDescriptionAndVersion(const webkit::WebPluginInfo& plugin); - - // Updates the active plugin in the group. The active plugin is the first - // enabled one, or if all plugins are disabled, simply the first one. - void UpdateActivePlugin(const webkit::WebPluginInfo& plugin); - - // Resets the group state to its default value (as if the group was empty). - // After calling this method, calling |UpdateActivePlugin| with all plugins - // in a row will correctly set the group state. - void ResetGroupState(); - - // Enables the plugin if not already enabled and if policy allows it to. - // Returns true on success. Does not update the group state. - static bool Enable(webkit::WebPluginInfo* plugin, int reason); - - // Disables the plugin if not already disabled and if policy allows it to. - // Returns true on success. Does not update the group state. - static bool Disable(webkit::WebPluginInfo* plugin, int reason); - - // Helper function to implement the functions above. - static bool SetPluginState(webkit::WebPluginInfo* plugin, - int new_reason, - bool state_changes); - // Returns a non-const vector of all plugins in the group. This is only used // by PluginList. std::vector<webkit::WebPluginInfo>& GetPluginsContainer() { return web_plugin_infos_; } - // Checks if |name| matches any of the patterns in |pattern_set|. - static bool IsStringMatchedInSet(const string16& name, - const std::set<string16>* pattern_set); - - static std::set<string16>* policy_disabled_plugin_patterns_; - static std::set<string16>* policy_disabled_plugin_exception_patterns_; - static std::set<string16>* policy_enabled_plugin_patterns_; - std::string identifier_; string16 group_name_; string16 name_matcher_; - string16 description_; std::string update_url_; - bool enabled_; std::vector<VersionRange> version_ranges_; - scoped_ptr<Version> version_; std::vector<webkit::WebPluginInfo> web_plugin_infos_; }; diff --git a/webkit/plugins/npapi/plugin_group_unittest.cc b/webkit/plugins/npapi/plugin_group_unittest.cc index 8f9bf50..a9e1c1c 100644 --- a/webkit/plugins/npapi/plugin_group_unittest.cc +++ b/webkit/plugins/npapi/plugin_group_unittest.cc @@ -87,12 +87,6 @@ class PluginGroupTest : public testing::Test { static PluginGroup* CreatePluginGroup(const WebPluginInfo& wpi) { return PluginGroup::FromWebPluginInfo(wpi); } - protected: - virtual void TearDown() { - PluginGroup::SetPolicyEnforcedPluginPatterns(std::set<string16>(), - std::set<string16>(), - std::set<string16>()); - } }; TEST_F(PluginGroupTest, PluginGroupMatch) { @@ -102,7 +96,7 @@ TEST_F(PluginGroupTest, PluginGroupMatch) { EXPECT_TRUE(group->Match(kPlugin3045r)); EXPECT_FALSE(group->Match(kPluginNoVersion)); group->AddPlugin(kPlugin3045); - EXPECT_FALSE(group->IsVulnerable()); + EXPECT_FALSE(group->IsVulnerable(kPlugin3045)); group.reset(PluginGroupTest::CreatePluginGroup(kPluginDef)); EXPECT_FALSE(group->Match(kPluginNoVersion)); @@ -126,45 +120,6 @@ TEST_F(PluginGroupTest, PluginGroupMatchCorrectVersion) { EXPECT_TRUE(group->Match(kPlugin4043)); } -TEST_F(PluginGroupTest, PluginGroupDescription) { - string16 desc3043(ASCIIToUTF16("MyPlugin version 3.0.43")); - string16 desc3045(ASCIIToUTF16("MyPlugin version 3.0.45")); - - PluginGroupDefinition plugindefs[] = - { kPluginDef, kPluginDef3, kPluginDef34 }; - for (size_t i = 0; i < arraysize(plugindefs); ++i) { - WebPluginInfo plugin3043(kPlugin3043); - WebPluginInfo plugin3045(kPlugin3045); - { - scoped_ptr<PluginGroup> group(PluginGroupTest::CreatePluginGroup( - plugindefs[i])); - EXPECT_TRUE(group->Match(plugin3043)); - group->AddPlugin(plugin3043); - EXPECT_EQ(desc3043, group->description()); - EXPECT_TRUE(group->IsVulnerable()); - EXPECT_TRUE(group->Match(plugin3045)); - group->AddPlugin(plugin3045); - EXPECT_EQ(desc3043, group->description()); - EXPECT_TRUE(group->IsVulnerable()); - } - { - // Disable the second plugin. - plugin3045.enabled = - webkit::WebPluginInfo::USER_DISABLED_POLICY_UNMANAGED; - scoped_ptr<PluginGroup> group(PluginGroupTest::CreatePluginGroup( - plugindefs[i])); - EXPECT_TRUE(group->Match(plugin3043)); - group->AddPlugin(plugin3043); - EXPECT_EQ(desc3043, group->description()); - EXPECT_TRUE(group->IsVulnerable()); - EXPECT_TRUE(group->Match(plugin3045)); - group->AddPlugin(plugin3045); - EXPECT_EQ(desc3043, group->description()); - EXPECT_TRUE(group->IsVulnerable()); - } - } -} - TEST_F(PluginGroupTest, PluginGroupDefinition) { for (size_t i = 0; i < arraysize(kPluginDefinitions); ++i) { scoped_ptr<PluginGroup> def_group( @@ -188,117 +143,12 @@ TEST_F(PluginGroupTest, VersionExtraction) { }; for (size_t i = 0; i < arraysize(versions); i++) { - const WebPluginInfo plugin = WebPluginInfo( - ASCIIToUTF16("Blah Plugin"), FilePath(FILE_PATH_LITERAL("blahfile")), - ASCIIToUTF16(versions[i][0]), string16()); - scoped_ptr<PluginGroup> group(PluginGroupTest::CreatePluginGroup(plugin)); - EXPECT_TRUE(group->Match(plugin)); - group->AddPlugin(plugin); - scoped_ptr<DictionaryValue> data(group->GetDataForUI()); - std::string version; - data->GetString("version", &version); - EXPECT_EQ(versions[i][1], version); + scoped_ptr<Version> version(PluginGroup::CreateVersionFromString( + ASCIIToUTF16(versions[i][0]))); + EXPECT_STREQ(versions[i][1], version->GetString().c_str()); } } -TEST_F(PluginGroupTest, DisabledByPolicy) { - std::set<string16> disabled_plugins; - disabled_plugins.insert(ASCIIToUTF16("Disable this!")); - disabled_plugins.insert(ASCIIToUTF16("*Google*")); - PluginGroup::SetPolicyEnforcedPluginPatterns(disabled_plugins, - std::set<string16>(), - std::set<string16>()); - - EXPECT_FALSE(PluginGroup::IsPluginNameDisabledByPolicy(ASCIIToUTF16("42"))); - EXPECT_TRUE(PluginGroup::IsPluginNameDisabledByPolicy( - ASCIIToUTF16("Disable this!"))); - EXPECT_TRUE(PluginGroup::IsPluginNameDisabledByPolicy( - ASCIIToUTF16("Google Earth"))); -} - -TEST_F(PluginGroupTest, EnabledByPolicy) { - std::set<string16> enabled_plugins; - enabled_plugins.insert(ASCIIToUTF16("Enable that!")); - enabled_plugins.insert(ASCIIToUTF16("PDF*")); - PluginGroup::SetPolicyEnforcedPluginPatterns(std::set<string16>(), - std::set<string16>(), - enabled_plugins); - - EXPECT_FALSE(PluginGroup::IsPluginNameEnabledByPolicy(ASCIIToUTF16("42"))); - EXPECT_TRUE(PluginGroup::IsPluginNameEnabledByPolicy( - ASCIIToUTF16("Enable that!"))); - EXPECT_TRUE(PluginGroup::IsPluginNameEnabledByPolicy( - ASCIIToUTF16("PDF Reader"))); -} - -TEST_F(PluginGroupTest, EnabledAndDisabledByPolicy) { - const string16 k42(ASCIIToUTF16("42")); - const string16 kEnabled(ASCIIToUTF16("Enabled")); - const string16 kEnabled2(ASCIIToUTF16("Enabled 2")); - const string16 kEnabled3(ASCIIToUTF16("Enabled 3")); - const string16 kException(ASCIIToUTF16("Exception")); - const string16 kException2(ASCIIToUTF16("Exception 2")); - const string16 kGoogleMars(ASCIIToUTF16("Google Mars")); - const string16 kGoogleEarth(ASCIIToUTF16("Google Earth")); - - std::set<string16> disabled_plugins; - std::set<string16> disabled_plugins_exceptions; - std::set<string16> enabled_plugins; - - disabled_plugins.insert(kEnabled); - disabled_plugins_exceptions.insert(kEnabled); - enabled_plugins.insert(kEnabled); - - disabled_plugins_exceptions.insert(kException); - - disabled_plugins.insert(kEnabled2); - enabled_plugins.insert(kEnabled2); - - disabled_plugins.insert(kException2); - disabled_plugins_exceptions.insert(kException2); - - disabled_plugins_exceptions.insert(kEnabled3); - enabled_plugins.insert(kEnabled3); - - PluginGroup::SetPolicyEnforcedPluginPatterns(disabled_plugins, - disabled_plugins_exceptions, - enabled_plugins); - - EXPECT_FALSE(PluginGroup::IsPluginNameEnabledByPolicy(k42)); - EXPECT_FALSE(PluginGroup::IsPluginNameDisabledByPolicy(k42)); - - EXPECT_TRUE(PluginGroup::IsPluginNameEnabledByPolicy(kEnabled)); - EXPECT_FALSE(PluginGroup::IsPluginNameDisabledByPolicy(kEnabled)); - EXPECT_TRUE(PluginGroup::IsPluginNameEnabledByPolicy(kEnabled2)); - EXPECT_FALSE(PluginGroup::IsPluginNameDisabledByPolicy(kEnabled2)); - EXPECT_TRUE(PluginGroup::IsPluginNameEnabledByPolicy(kEnabled3)); - EXPECT_FALSE(PluginGroup::IsPluginNameDisabledByPolicy(kEnabled3)); - - EXPECT_FALSE(PluginGroup::IsPluginNameEnabledByPolicy(kException)); - EXPECT_FALSE(PluginGroup::IsPluginNameDisabledByPolicy(kException)); - EXPECT_FALSE(PluginGroup::IsPluginNameEnabledByPolicy(kException2)); - EXPECT_FALSE(PluginGroup::IsPluginNameDisabledByPolicy(kException2)); - - disabled_plugins.clear(); - disabled_plugins_exceptions.clear(); - enabled_plugins.clear(); - - disabled_plugins.insert(ASCIIToUTF16("*")); - disabled_plugins_exceptions.insert(ASCIIToUTF16("*Google*")); - enabled_plugins.insert(kGoogleEarth); - - PluginGroup::SetPolicyEnforcedPluginPatterns(disabled_plugins, - disabled_plugins_exceptions, - enabled_plugins); - - EXPECT_TRUE(PluginGroup::IsPluginNameEnabledByPolicy(kGoogleEarth)); - EXPECT_FALSE(PluginGroup::IsPluginNameDisabledByPolicy(kGoogleEarth)); - EXPECT_FALSE(PluginGroup::IsPluginNameEnabledByPolicy(kGoogleMars)); - EXPECT_FALSE(PluginGroup::IsPluginNameDisabledByPolicy(kGoogleMars)); - EXPECT_FALSE(PluginGroup::IsPluginNameEnabledByPolicy(k42)); - EXPECT_TRUE(PluginGroup::IsPluginNameDisabledByPolicy(k42)); -} - TEST_F(PluginGroupTest, IsVulnerable) { // Adobe Reader 10 VersionRangeDefinition adobe_reader_version_range[] = { @@ -318,8 +168,8 @@ TEST_F(PluginGroupTest, IsVulnerable) { adobe_reader_plugin_def)); group->AddPlugin(adobe_reader_plugin); PluginGroup group_copy(*group); // Exercise the copy constructor. - EXPECT_FALSE(group_copy.IsVulnerable()); - EXPECT_FALSE(group_copy.RequiresAuthorization()); + EXPECT_FALSE(group_copy.IsVulnerable(adobe_reader_plugin)); + EXPECT_FALSE(group_copy.RequiresAuthorization(adobe_reader_plugin)); // Silverlight 4 VersionRangeDefinition silverlight_version_range[] = { @@ -336,62 +186,8 @@ TEST_F(PluginGroupTest, IsVulnerable) { ASCIIToUTF16("silverlight 4")); group.reset(PluginGroupTest::CreatePluginGroup(silverlight_plugin_def)); group->AddPlugin(silverlight_plugin); - EXPECT_FALSE(PluginGroup(*group).IsVulnerable()); - EXPECT_TRUE(PluginGroup(*group).RequiresAuthorization()); -} - -TEST_F(PluginGroupTest, WhitelistedIsNotVulnerable) { - VersionRangeDefinition version_range[] = { - { "0", "6", "5.0", true } - }; - PluginGroupDefinition plugin_def = { - "nativehtml5", "NativeHTML5", "NativeHTML5", version_range, - arraysize(version_range), - "http://bugzilla.mozilla.org/show_bug.cgi?id=649408" }; - WebPluginInfo plugin(ASCIIToUTF16("NativeHTML5"), - FilePath(FILE_PATH_LITERAL("/native.so")), - ASCIIToUTF16("4.0"), - ASCIIToUTF16("NativeHTML5")); - scoped_ptr<PluginGroup> group(PluginGroupTest::CreatePluginGroup(plugin_def)); - group->AddPlugin(plugin); - - EXPECT_TRUE(group->IsVulnerable()); - EXPECT_TRUE(group->RequiresAuthorization()); - - std::set<string16> enabled_plugins; - enabled_plugins.insert(ASCIIToUTF16("NativeHTML5")); - PluginGroup::SetPolicyEnforcedPluginPatterns(std::set<string16>(), - std::set<string16>(), - enabled_plugins); - group->EnforceGroupPolicy(); - - EXPECT_FALSE(group->IsVulnerable()); - EXPECT_FALSE(group->RequiresAuthorization()); -} - -TEST_F(PluginGroupTest, MultipleVersions) { - scoped_ptr<PluginGroup> group( - PluginGroupTest::CreatePluginGroup(kPluginDef3)); - group->AddPlugin(kPlugin3044); - group->AddPlugin(kPlugin3043); - EXPECT_EQ(kPlugin3044.desc, group->description()); - EXPECT_FALSE(group->IsVulnerable()); - - group->DisablePlugin(kPlugin3044.path); - EXPECT_EQ(kPlugin3043.desc, group->description()); - EXPECT_TRUE(group->IsVulnerable()); - - EXPECT_TRUE(group->EnableGroup(false)); - EXPECT_EQ(kPlugin3044.desc, group->description()); - EXPECT_FALSE(group->IsVulnerable()); - - EXPECT_TRUE(group->RemovePlugin(kPlugin3044.path)); - EXPECT_EQ(kPlugin3043.desc, group->description()); - EXPECT_TRUE(group->IsVulnerable()); - - EXPECT_TRUE(group->RemovePlugin(kPlugin3043.path)); - EXPECT_TRUE(group->IsEmpty()); - EXPECT_EQ(string16(), group->description()); + EXPECT_FALSE(PluginGroup(*group).IsVulnerable(silverlight_plugin)); + EXPECT_TRUE(PluginGroup(*group).RequiresAuthorization(silverlight_plugin)); } } // namespace npapi diff --git a/webkit/plugins/npapi/plugin_lib_mac.mm b/webkit/plugins/npapi/plugin_lib_mac.mm index fe11197..542b43d 100644 --- a/webkit/plugins/npapi/plugin_lib_mac.mm +++ b/webkit/plugins/npapi/plugin_lib_mac.mm @@ -125,7 +125,6 @@ bool ReadPlistPluginInfo(const FilePath& filename, CFBundleRef bundle, info->desc = base::SysNSStringToUTF16(plugin_desc); else info->desc = UTF8ToUTF16(filename.BaseName().value()); - info->enabled = WebPluginInfo::USER_ENABLED; return true; } diff --git a/webkit/plugins/npapi/plugin_lib_posix.cc b/webkit/plugins/npapi/plugin_lib_posix.cc index 641b6cd..64afcd2 100644 --- a/webkit/plugins/npapi/plugin_lib_posix.cc +++ b/webkit/plugins/npapi/plugin_lib_posix.cc @@ -162,7 +162,6 @@ bool PluginLib::ReadWebPluginInfo(const FilePath& filename, } info->path = filename; - info->enabled = WebPluginInfo::USER_ENABLED; // Attempt to swap in the wrapped plugin if this is nspluginwrapper. UnwrapNSPluginWrapper(&dl, &info->path); diff --git a/webkit/plugins/npapi/plugin_lib_win.cc b/webkit/plugins/npapi/plugin_lib_win.cc index ccdb4b6..224e1c3 100644 --- a/webkit/plugins/npapi/plugin_lib_win.cc +++ b/webkit/plugins/npapi/plugin_lib_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -38,7 +38,6 @@ bool PluginLib::ReadWebPluginInfo(const FilePath &filename, info->desc = version_info->file_description(); info->version = version_info->file_version(); info->path = filename; - info->enabled = WebPluginInfo::USER_ENABLED_POLICY_UNMANAGED; // TODO(evan): Move the ParseMimeTypes code inline once Pepper is updated. if (!PluginList::ParseMimeTypes( diff --git a/webkit/plugins/npapi/plugin_list.cc b/webkit/plugins/npapi/plugin_list.cc index 45160fc..a7f6dd4 100644 --- a/webkit/plugins/npapi/plugin_list.cc +++ b/webkit/plugins/npapi/plugin_list.cc @@ -230,7 +230,6 @@ void PluginList::RegisterInternalPlugin(const FilePath& filename, plugin.info.name = ASCIIToUTF16(name); plugin.info.version = ASCIIToUTF16("1"); plugin.info.desc = ASCIIToUTF16(description); - plugin.info.enabled = webkit::WebPluginInfo::USER_ENABLED_POLICY_UNMANAGED; webkit::WebPluginMimeType mime_type; mime_type.mime_type = mime_type_str; @@ -408,51 +407,6 @@ void PluginList::LoadPlugins() { LoadPluginsInternal(&new_plugin_groups); base::AutoLock lock(lock_); - // Grab all plugins that were found before to copy enabled statuses. - std::vector<webkit::WebPluginInfo> old_plugins; - for (size_t i = 0; i < plugin_groups_.size(); ++i) { - const std::vector<webkit::WebPluginInfo>& gr_plugins = - plugin_groups_[i]->web_plugins_info(); - old_plugins.insert(old_plugins.end(), gr_plugins.begin(), gr_plugins.end()); - } - // Disable all of the plugins and plugin groups that are disabled by policy. - for (size_t i = 0; i < new_plugin_groups.size(); ++i) { - PluginGroup* group = new_plugin_groups[i]; - string16 group_name = group->GetGroupName(); - - std::vector<webkit::WebPluginInfo>& gr_plugins = - group->GetPluginsContainer(); - for (size_t j = 0; j < gr_plugins.size(); ++j) { - int plugin_found = -1; - for (size_t k = 0; k < old_plugins.size(); ++k) { - if (gr_plugins[j].path == old_plugins[k].path) { - plugin_found = k; - break; - } - } - if (plugin_found >= 0) - gr_plugins[j].enabled = old_plugins[plugin_found].enabled; - // Set the disabled flag of all plugins scheduled for disabling. - if (plugins_to_disable_.find(gr_plugins[j].path) != - plugins_to_disable_.end()) { - group->DisablePlugin(gr_plugins[j].path); - } - } - - if (group->IsEmpty()) { - new_plugin_groups.erase(new_plugin_groups.begin() + i); - --i; - continue; - } - - group->EnforceGroupPolicy(); - } - // We flush the list of prematurely disabled plugins after the load has - // finished. If for some reason a plugin reappears on a second load it is - // going to be loaded normally. This is only true for non-policy controlled - // plugins though. - plugins_to_disable_.clear(); - plugin_groups_.swap(new_plugin_groups); } @@ -493,7 +447,7 @@ void PluginList::GetPlugins(std::vector<WebPluginInfo>* plugins) { base::AutoLock lock(lock_); for (size_t i = 0; i < plugin_groups_.size(); ++i) { const std::vector<webkit::WebPluginInfo>& gr_plugins = - plugin_groups_[i]->web_plugins_info(); + plugin_groups_[i]->web_plugin_infos(); plugins->insert(plugins->end(), gr_plugins.begin(), gr_plugins.end()); } } @@ -522,7 +476,7 @@ void PluginList::GetPluginInfoArray( // Add in plugins by mime type. for (size_t i = 0; i < plugin_groups_.size(); ++i) { const std::vector<webkit::WebPluginInfo>& plugins = - plugin_groups_[i]->web_plugins_info(); + plugin_groups_[i]->web_plugin_infos(); for (size_t i = 0; i < plugins.size(); ++i) { if (SupportsType(plugins[i], mime_type, allow_wildcard)) { FilePath path = plugins[i].path; @@ -544,7 +498,7 @@ void PluginList::GetPluginInfoArray( std::string actual_mime_type; for (size_t i = 0; i < plugin_groups_.size(); ++i) { const std::vector<webkit::WebPluginInfo>& plugins = - plugin_groups_[i]->web_plugins_info(); + plugin_groups_[i]->web_plugin_infos(); for (size_t i = 0; i < plugins.size(); ++i) { if (SupportsExtension(plugins[i], extension, &actual_mime_type)) { FilePath path = plugins[i].path; @@ -569,9 +523,9 @@ void PluginList::GetPluginInfoArray( if (plugin_groups_[i]->identifier().compare( kDefaultPluginLibraryName) == 0) { #endif - DCHECK_NE(0U, plugin_groups_[i]->web_plugins_info().size()); + DCHECK_NE(0U, plugin_groups_[i]->web_plugin_infos().size()); const webkit::WebPluginInfo& default_info = - plugin_groups_[i]->web_plugins_info()[0]; + plugin_groups_[i]->web_plugin_infos()[0]; if (SupportsType(default_info, mime_type, allow_wildcard)) { info->push_back(default_info); if (actual_mime_types) @@ -587,7 +541,7 @@ bool PluginList::GetPluginInfoByPath(const FilePath& plugin_path, base::AutoLock lock(lock_); for (size_t i = 0; i < plugin_groups_.size(); ++i) { const std::vector<webkit::WebPluginInfo>& plugins = - plugin_groups_[i]->web_plugins_info(); + plugin_groups_[i]->web_plugin_infos(); for (size_t i = 0; i < plugins.size(); ++i) { if (plugins[i].path == plugin_path) { *info = plugins[i]; @@ -614,10 +568,10 @@ void PluginList::GetPluginGroups( } } -const PluginGroup* PluginList::GetPluginGroup( +PluginGroup* PluginList::GetPluginGroup( const webkit::WebPluginInfo& web_plugin_info) { base::AutoLock lock(lock_); - return AddToPluginGroups(web_plugin_info, &plugin_groups_); + return new PluginGroup(*AddToPluginGroups(web_plugin_info, &plugin_groups_)); } string16 PluginList::GetPluginGroupName(const std::string& identifier) { @@ -670,60 +624,9 @@ PluginGroup* PluginList::AddToPluginGroups( plugin_groups->push_back(group); } group->AddPlugin(web_plugin_info); - // If group is scheduled for disabling do that now and remove it from the - // list. - if (groups_to_disable_.erase(group->GetGroupName())) - group->EnableGroup(false); return group; } -bool PluginList::EnablePlugin(const FilePath& filename) { - base::AutoLock lock(lock_); - for (size_t i = 0; i < plugin_groups_.size(); ++i) { - if (plugin_groups_[i]->ContainsPlugin(filename)) - return plugin_groups_[i]->EnablePlugin(filename); - } - // Non existing plugin is being enabled. Check if it has been disabled before - // and remove it. - return (plugins_to_disable_.erase(filename) != 0); -} - -bool PluginList::DisablePlugin(const FilePath& filename) { - base::AutoLock lock(lock_); - for (size_t i = 0; i < plugin_groups_.size(); ++i) { - if (plugin_groups_[i]->ContainsPlugin(filename)) - return plugin_groups_[i]->DisablePlugin(filename); - } - // Non existing plugin is being disabled. Queue the plugin so that on the next - // load plugins call they will be disabled. - plugins_to_disable_.insert(filename); - return true; -} - -bool PluginList::EnableGroup(bool enable, const string16& group_name) { - base::AutoLock lock(lock_); - PluginGroup* group = NULL; - for (size_t i = 0; i < plugin_groups_.size(); ++i) { - if (!plugin_groups_[i]->IsEmpty() && - plugin_groups_[i]->GetGroupName().find(group_name) != string16::npos) { - group = plugin_groups_[i]; - break; - } - } - if (!group) { - // Non existing group is being enabled. Queue the group so that on the next - // load plugins call they will be disabled. - if (!enable) { - groups_to_disable_.insert(group_name); - return true; - } else { - return (groups_to_disable_.erase(group_name) != 0); - } - } - - return group->EnableGroup(enable); -} - bool PluginList::SupportsType(const webkit::WebPluginInfo& plugin, const std::string& mime_type, bool allow_wildcard) { diff --git a/webkit/plugins/npapi/plugin_list.h b/webkit/plugins/npapi/plugin_list.h index 4f17bdb..640ccbd 100644 --- a/webkit/plugins/npapi/plugin_list.h +++ b/webkit/plugins/npapi/plugin_list.h @@ -150,16 +150,10 @@ class PluginList { void GetPluginGroups(bool load_if_necessary, std::vector<PluginGroup>* plugin_groups); - // Returns the PluginGroup corresponding to the given WebPluginInfo. If no - // such group exists, it is created and added to the cache. - // Beware: when calling this from the Browser process, the group that the - // returned pointer points to might disappear suddenly. This happens when - // |RefreshPlugins()| is called and then |LoadPlugins()| is triggered by a - // call to |GetPlugins()|, |GetEnabledPlugins()|, |GetPluginInfoArray()|, - // |GetPluginInfoByPath()|, or |GetPluginGroups(true, _)|. It is the caller's - // responsibility to make sure this doesn't happen. - const PluginGroup* GetPluginGroup( - const webkit::WebPluginInfo& web_plugin_info); + // Returns a copy of the PluginGroup corresponding to the given WebPluginInfo. + // If no such group exists, it is created and added to the cache. + // The caller takes ownership of the returned PluginGroup. + PluginGroup* GetPluginGroup(const webkit::WebPluginInfo& web_plugin_info); // Returns the name of the PluginGroup with the given identifier. // If no such group exists, an empty string is returned. @@ -175,24 +169,6 @@ class PluginList { void LoadPlugin(const FilePath& filename, ScopedVector<PluginGroup>* plugin_groups); - // Enable a specific plugin, specified by path. Returns |true| iff a plugin - // currently in the plugin list was actually enabled as a result; regardless - // of return value, if a plugin is found in the future with the given name, it - // will be enabled. - bool EnablePlugin(const FilePath& filename); - - // Disable a specific plugin, specified by path. Returns |true| iff a plugin - // currently in the plugin list was actually disabled as a result; regardless - // of return value, if a plugin is found in the future with the given name, it - // will be disabled. - bool DisablePlugin(const FilePath& filename); - - // Enable/disable a plugin group, specified by group_name. Returns |true| iff - // a plugin currently in the plugin list was actually enabled/disabled as a - // result; regardless of return value, if a plugin is found in the future with - // the given name, it will be enabled/disabled. - bool EnableGroup(bool enable, const string16& name); - virtual ~PluginList(); protected: @@ -240,12 +216,6 @@ class PluginList { bool ShouldLoadPlugin(const webkit::WebPluginInfo& info, ScopedVector<PluginGroup>* plugins); - // Return whether a plug-in group with the given name should be disabled, - // either because it already is on the list of disabled groups, or because it - // is blacklisted by a policy. In the latter case, add the plugin group to the - // list of disabled groups as well. - bool ShouldDisableGroup(const string16& group_name); - // Returns true if the plugin supports |mime_type|. |mime_type| should be all // lower case. bool SupportsType(const webkit::WebPluginInfo& plugin, @@ -308,18 +278,6 @@ class PluginList { // Holds the currently available plugin groups. ScopedVector<PluginGroup> plugin_groups_; - // The set of plugins that have been scheduled for disabling once they get - // loaded. This list is used in LoadPlugins and pruned after it. Contains - // plugins that were either disabled by the user (prefs are loaded before - // plugins) or disabled by a policy. - std::set<FilePath> plugins_to_disable_; - // Equivalent to the |plugins_to_disable_| this is the set of groups - // scheduled for disabling once they appear. This list is never completely - // pruned but all groups that do get created are removed from it. New groups - // might get added if they should be pruned because of plugins getting removed - // for example. - std::set<string16> groups_to_disable_; - // Need synchronization for the above members since this object can be // accessed on multiple threads. base::Lock lock_; diff --git a/webkit/plugins/npapi/plugin_list_mac.mm b/webkit/plugins/npapi/plugin_list_mac.mm index b142b2c..361691a 100644 --- a/webkit/plugins/npapi/plugin_list_mac.mm +++ b/webkit/plugins/npapi/plugin_list_mac.mm @@ -107,7 +107,7 @@ bool PluginList::ShouldLoadPlugin(const WebPluginInfo& info, // encounter earlier must override plugins we encounter later) for (size_t i = 0; i < plugin_groups->size(); ++i) { const std::vector<WebPluginInfo>& plugins = - (*plugin_groups)[i]->web_plugins_info(); + (*plugin_groups)[i]->web_plugin_infos(); for (size_t j = 0; j < plugins.size(); ++j) { if (plugins[j].path.BaseName() == info.path.BaseName()) { return false; // Already have a loaded plugin higher in the hierarchy. diff --git a/webkit/plugins/npapi/plugin_list_posix.cc b/webkit/plugins/npapi/plugin_list_posix.cc index 9d35898..246f859 100644 --- a/webkit/plugins/npapi/plugin_list_posix.cc +++ b/webkit/plugins/npapi/plugin_list_posix.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -248,7 +248,7 @@ bool PluginList::ShouldLoadPlugin(const WebPluginInfo& info, // See if we have a better version of this plugin. for (size_t i = 0; i < plugin_groups->size(); ++i) { const std::vector<WebPluginInfo>& plugins = - (*plugin_groups)[i]->web_plugins_info(); + (*plugin_groups)[i]->web_plugin_infos(); for (size_t j = 0; j < plugins.size(); ++j) { if (plugins[j].name == info.name && !IsUndesirablePlugin(plugins[j])) { diff --git a/webkit/plugins/npapi/plugin_list_unittest.cc b/webkit/plugins/npapi/plugin_list_unittest.cc index a86f699a..8fd63b0 100644 --- a/webkit/plugins/npapi/plugin_list_unittest.cc +++ b/webkit/plugins/npapi/plugin_list_unittest.cc @@ -13,21 +13,18 @@ namespace npapi { namespace { -bool Equals(const WebPluginInfo& a, const WebPluginInfo& b, - bool care_about_enabled_status) { +bool Equals(const WebPluginInfo& a, const WebPluginInfo& b) { return (a.name == b.name && a.path == b.path && a.version == b.version && - a.desc == b.desc && - (!care_about_enabled_status || a.enabled == b.enabled)); + a.desc == b.desc); } bool Contains(const std::vector<WebPluginInfo>& list, - const WebPluginInfo& plugin, - bool care_about_enabled_status) { + const WebPluginInfo& plugin) { for (std::vector<WebPluginInfo>::const_iterator it = list.begin(); it != list.end(); ++it) { - if (Equals(*it, plugin, care_about_enabled_status)) + if (Equals(*it, plugin)) return true; } return false; @@ -60,8 +57,6 @@ class PluginListTest : public testing::Test { } virtual void SetUp() { - bar_plugin_.enabled = WebPluginInfo::USER_DISABLED_POLICY_UNMANAGED; - plugin_list_.DisablePlugin(bar_plugin_.path); plugin_list_.AddPluginToLoad(foo_plugin_); plugin_list_.AddPluginToLoad(bar_plugin_); } @@ -76,26 +71,20 @@ TEST_F(PluginListTest, GetPlugins) { std::vector<WebPluginInfo> plugins; plugin_list_.GetPlugins(&plugins); EXPECT_EQ(2u, plugins.size()); - EXPECT_TRUE(Contains(plugins, foo_plugin_, true)); - EXPECT_TRUE(Contains(plugins, bar_plugin_, true)); + EXPECT_TRUE(Contains(plugins, foo_plugin_)); + EXPECT_TRUE(Contains(plugins, bar_plugin_)); } TEST_F(PluginListTest, GetPluginGroup) { - const PluginGroup* foo_group = plugin_list_.GetPluginGroup(foo_plugin_); + scoped_ptr<PluginGroup> foo_group(plugin_list_.GetPluginGroup(foo_plugin_)); EXPECT_EQ(ASCIIToUTF16(kFooGroupName), foo_group->GetGroupName()); - EXPECT_TRUE(foo_group->Enabled()); - // The second request should return a pointer to the same instance. - const PluginGroup* foo_group2 = plugin_list_.GetPluginGroup(foo_plugin_); - EXPECT_EQ(foo_group, foo_group2); - const PluginGroup* bar_group = plugin_list_.GetPluginGroup(bar_plugin_); - EXPECT_FALSE(bar_group->Enabled()); } TEST_F(PluginListTest, EmptyGroup) { std::vector<PluginGroup> groups; plugin_list_.GetPluginGroups(false, &groups); for (size_t i = 0; i < groups.size(); ++i) - EXPECT_GE(1U, groups[i].web_plugins_info().size()); + EXPECT_GE(1U, groups[i].web_plugin_infos().size()); } TEST_F(PluginListTest, BadPluginDescription) { @@ -110,61 +99,20 @@ TEST_F(PluginListTest, BadPluginDescription) { plugin_list_.RefreshPlugins(); std::vector<WebPluginInfo> plugins; plugin_list_.GetPlugins(&plugins); - ASSERT_TRUE(Contains(plugins, plugin_3043, true)); -} - -TEST_F(PluginListTest, DisableAndEnableBeforeLoad) { - WebPluginInfo plugin_3043(ASCIIToUTF16("MyPlugin"), - FilePath(FILE_PATH_LITERAL("/myplugin.3.0.43")), - ASCIIToUTF16("3.0.43"), - ASCIIToUTF16("MyPlugin version 3.0.43")); - WebPluginInfo plugin_3045(ASCIIToUTF16("MyPlugin"), - FilePath(FILE_PATH_LITERAL("/myplugin.3.0.45")), - ASCIIToUTF16("3.0.45"), - ASCIIToUTF16("MyPlugin version 3.0.45")); - // Disable the first one and disable and then enable the second one. - EXPECT_TRUE(plugin_list_.DisablePlugin(plugin_3043.path)); - EXPECT_TRUE(plugin_list_.DisablePlugin(plugin_3045.path)); - EXPECT_TRUE(plugin_list_.EnablePlugin(plugin_3045.path)); - // Simulate loading of the plugins. - plugin_list_.ClearPluginsToLoad(); - plugin_list_.AddPluginToLoad(plugin_3043); - plugin_list_.AddPluginToLoad(plugin_3045); - // Now we should have them in the state we specified above. - plugin_list_.RefreshPlugins(); - std::vector<WebPluginInfo> plugins; - plugin_list_.GetPlugins(&plugins); - plugin_3043.enabled = WebPluginInfo::USER_DISABLED_POLICY_UNMANAGED; - ASSERT_TRUE(Contains(plugins, plugin_3043, true)); - ASSERT_TRUE(Contains(plugins, plugin_3045, true)); + ASSERT_TRUE(Contains(plugins, plugin_3043)); } TEST_F(PluginListTest, HardcodedGroups) { std::vector<PluginGroup> groups; plugin_list_.GetPluginGroups(true, &groups); ASSERT_EQ(2u, groups.size()); - EXPECT_TRUE(groups[0].Enabled()); - EXPECT_EQ(1u, groups[0].web_plugins_info().size()); + EXPECT_EQ(1u, groups[0].web_plugin_infos().size()); EXPECT_TRUE(groups[0].ContainsPlugin(FilePath(kFooPath))); EXPECT_EQ(kFooIdentifier, groups[0].identifier()); - EXPECT_FALSE(groups[1].Enabled()); - EXPECT_EQ(1u, groups[1].web_plugins_info().size()); + EXPECT_EQ(1u, groups[1].web_plugin_infos().size()); EXPECT_TRUE(groups[1].ContainsPlugin(FilePath(kBarPath))); EXPECT_EQ("bar.plugin", groups[1].identifier()); } -TEST_F(PluginListTest, DisableBeforeLoad) { - // Test that a plugin group that was disabled before plugins are loaded stays - // disabled afterwards. - - EXPECT_TRUE(plugin_list_.EnableGroup(false, ASCIIToUTF16(kFooGroupName))); - - plugin_list_.RefreshPlugins(); - std::vector<WebPluginInfo> plugins; - plugin_list_.GetPlugins(&plugins); - ASSERT_EQ(2u, plugins.size()); - ASSERT_EQ(WebPluginInfo::USER_DISABLED_POLICY_UNMANAGED, plugins[0].enabled); -} - } // namespace npapi } // namespace webkit diff --git a/webkit/plugins/npapi/plugin_list_win.cc b/webkit/plugins/npapi/plugin_list_win.cc index b739771..0f832e9 100644 --- a/webkit/plugins/npapi/plugin_list_win.cc +++ b/webkit/plugins/npapi/plugin_list_win.cc @@ -358,7 +358,7 @@ bool PluginList::ShouldLoadPlugin(const webkit::WebPluginInfo& info, for (size_t i = 0; i < plugin_groups->size(); ++i) { const std::vector<webkit::WebPluginInfo>& plugins = - (*plugin_groups)[i]->web_plugins_info(); + (*plugin_groups)[i]->web_plugin_infos(); for (size_t j = 0; j < plugins.size(); ++j) { std::wstring plugin1 = StringToLowerASCII(plugins[j].path.BaseName().value()); @@ -420,7 +420,7 @@ bool PluginList::ShouldLoadPlugin(const webkit::WebPluginInfo& info, for (size_t i = 0; i < plugin_groups->size(); ++i) { const std::vector<webkit::WebPluginInfo>& plugins = - (*plugin_groups)[i]->web_plugins_info(); + (*plugin_groups)[i]->web_plugin_infos(); for (size_t j = 0; j < plugins.size(); ++j) { if (plugins[j].path.BaseName().value() == kOldWMPPlugin) { (*plugin_groups)[i]->RemovePlugin(plugins[j].path); @@ -431,7 +431,7 @@ bool PluginList::ShouldLoadPlugin(const webkit::WebPluginInfo& info, } else if (filename == kOldWMPPlugin) { for (size_t i = 0; i < plugin_groups->size(); ++i) { const std::vector<webkit::WebPluginInfo>& plugins = - (*plugin_groups)[i]->web_plugins_info(); + (*plugin_groups)[i]->web_plugin_infos(); for (size_t j = 0; j < plugins.size(); ++j) { if (plugins[j].path.BaseName().value() == kNewWMPPlugin) return false; diff --git a/webkit/plugins/webplugininfo.cc b/webkit/plugins/webplugininfo.cc index 0bdc255..031dd40 100644 --- a/webkit/plugins/webplugininfo.cc +++ b/webkit/plugins/webplugininfo.cc @@ -22,8 +22,7 @@ WebPluginMimeType::WebPluginMimeType(const std::string& m, WebPluginMimeType::~WebPluginMimeType() {} -WebPluginInfo::WebPluginInfo() - : enabled(USER_DISABLED_POLICY_UNMANAGED), type(PLUGIN_TYPE_NPAPI) { +WebPluginInfo::WebPluginInfo() : type(PLUGIN_TYPE_NPAPI) { } WebPluginInfo::WebPluginInfo(const WebPluginInfo& rhs) @@ -32,7 +31,6 @@ WebPluginInfo::WebPluginInfo(const WebPluginInfo& rhs) version(rhs.version), desc(rhs.desc), mime_types(rhs.mime_types), - enabled(rhs.enabled), type(rhs.type) { } @@ -44,7 +42,6 @@ WebPluginInfo& WebPluginInfo::operator=(const WebPluginInfo& rhs) { version = rhs.version; desc = rhs.desc; mime_types = rhs.mime_types; - enabled = rhs.enabled; type = rhs.type; return *this; } @@ -58,15 +55,9 @@ WebPluginInfo::WebPluginInfo(const string16& fake_name, version(fake_version), desc(fake_desc), mime_types(), - enabled(USER_ENABLED_POLICY_UNMANAGED), type(PLUGIN_TYPE_NPAPI) { } -bool IsPluginEnabled(const WebPluginInfo& plugin) { - return ((plugin.enabled & WebPluginInfo::POLICY_ENABLED) || - plugin.enabled == WebPluginInfo::USER_ENABLED_POLICY_UNMANAGED); -} - bool IsPepperPlugin(const WebPluginInfo& plugin) { return ((plugin.type == WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS ) || plugin.type == WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS); diff --git a/webkit/plugins/webplugininfo.h b/webkit/plugins/webplugininfo.h index d39c4cd..b7bb4d3 100644 --- a/webkit/plugins/webplugininfo.h +++ b/webkit/plugins/webplugininfo.h @@ -38,32 +38,6 @@ struct WebPluginMimeType { // Describes an available NPAPI or Pepper plugin. struct WebPluginInfo { - // Defines the possible enabled state a plugin can have. - // The enum values actually represent a 3-bit bitfield : - // |PE|PD|U| - where |PE|PD| is policy state and U is user state. - // PE == 1 means the plugin is forced to enabled state by policy - // PD == 1 means the plugin is forced to disabled by policy - // PE and PD CAN'T be both 1 but can be both 0 which mean no policy is set. - // U == 1 means the user has disabled the plugin. - // Because the plugin user state might have been changed before a policy was - // introduced the user state might contradict the policy state in which case - // the policy has precedence. - enum EnabledStates { - USER_ENABLED = 0, - USER_DISABLED = 1 << 0, - POLICY_DISABLED = 1 << 1, - POLICY_ENABLED = 1 << 2, - USER_ENABLED_POLICY_UNMANAGED = USER_ENABLED, - USER_ENABLED_POLICY_DISABLED = USER_ENABLED| POLICY_DISABLED, - USER_ENABLED_POLICY_ENABLED = USER_ENABLED | POLICY_ENABLED, - USER_DISABLED_POLICY_UNMANAGED = USER_DISABLED, - USER_DISABLED_POLICY_DISABLED = USER_DISABLED | POLICY_DISABLED, - USER_DISABLED_POLICY_ENABLED = USER_DISABLED | POLICY_ENABLED, - USER_MASK = USER_DISABLED, - MANAGED_MASK = POLICY_DISABLED | POLICY_ENABLED, - POLICY_UNMANAGED = -1 - }; - enum PluginType { PLUGIN_TYPE_NPAPI, PLUGIN_TYPE_PEPPER_IN_PROCESS, @@ -96,16 +70,10 @@ struct WebPluginInfo { // A list of all the mime types that this plugin supports. std::vector<WebPluginMimeType> mime_types; - // Enabled state of the plugin. See the EnabledStates enum. - int enabled; - // Plugin type. See the PluginType enum. int type; }; -// Checks whether a plugin is enabled either by the user or by policy. -bool IsPluginEnabled(const WebPluginInfo& plugin); - // Checks whether a plugin is a Pepper plugin, enabled or disabled. bool IsPepperPlugin(const WebPluginInfo& plugin); diff --git a/webkit/support/webkit_support_glue.cc b/webkit/support/webkit_support_glue.cc index 501356e..0f85ff4 100644 --- a/webkit/support/webkit_support_glue.cc +++ b/webkit/support/webkit_support_glue.cc @@ -30,7 +30,6 @@ void GetPlugins(bool refresh, webkit::WebPluginInfo plugin_info = plugins->at(i); for (size_t j = 0; j < arraysize(kPluginBlackList); ++j) { if (plugin_info.path.BaseName() == FilePath(kPluginBlackList[j])) { - webkit::npapi::PluginList::Singleton()->DisablePlugin(plugin_info.path); plugins->erase(plugins->begin() + i); } } diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc index 7c78dbc..38e83ca 100644 --- a/webkit/tools/test_shell/test_shell.cc +++ b/webkit/tools/test_shell/test_shell.cc @@ -675,7 +675,6 @@ void GetPlugins(bool refresh, webkit::WebPluginInfo plugin_info = plugins->at(i); for (size_t j = 0; j < arraysize(kPluginBlackList); ++j) { if (plugin_info.path.BaseName() == FilePath(kPluginBlackList[j])) { - webkit::npapi::PluginList::Singleton()->DisablePlugin(plugin_info.path); plugins->erase(plugins->begin() + i); } } |