diff options
author | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-29 08:21:28 +0000 |
---|---|---|
committer | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-29 08:21:28 +0000 |
commit | 685980787980c7be0dd1f8b83900718c8e2634f2 (patch) | |
tree | 8d5e3d52426658543f7ac025f9cb44afd0b9c531 | |
parent | 02601778c9535f4b23c084794204d6ee2bd0fa86 (diff) | |
download | chromium_src-685980787980c7be0dd1f8b83900718c8e2634f2.zip chromium_src-685980787980c7be0dd1f8b83900718c8e2634f2.tar.gz chromium_src-685980787980c7be0dd1f8b83900718c8e2634f2.tar.bz2 |
PluginList cleanup to fix a race condition and decrease the API surface for future refactorings:
* Remove "webkit/glue/plugins/plugin_list.h" includes in favor of "webkit/npapi/plugins/plugin_list.h"
* Remove |refresh| parameter from |GetPlugins| in favor of calling |RefreshPlugins| beforehand.
* Remove |GetPluginInfo| in favor of calling |GetPluginInfoArray| and looking for the first enabled plug-in.
* Remove |GetEnabledPlugins| in favor of calling |GetPlugins| and filtering out disabled plugins.
* Remove |stale| in favor of an outparameter to |GetPluginInfoArray|, to remove the race condition.
BUG=69516,80794
TEST=none
Review URL: http://codereview.chromium.org/7497030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94641 0039d316-1c4b-4281-b951-d872f2087c98
24 files changed, 124 insertions, 184 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index bc65b84..d892388 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -3389,7 +3389,7 @@ void TestingAutomationProvider::GetPluginsInfo( return; } std::vector<webkit::npapi::WebPluginInfo> plugins; - webkit::npapi::PluginList::Singleton()->GetPlugins(false, &plugins); + webkit::npapi::PluginList::Singleton()->GetPlugins(&plugins); ListValue* items = new ListValue; for (std::vector<webkit::npapi::WebPluginInfo>::const_iterator it = plugins.begin(); diff --git a/chrome/browser/browser_about_handler.cc b/chrome/browser/browser_about_handler.cc index c8a266e..7515700 100644 --- a/chrome/browser/browser_about_handler.cc +++ b/chrome/browser/browser_about_handler.cc @@ -59,7 +59,7 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" #include "webkit/glue/webkit_glue.h" -#include "webkit/glue/plugins/plugin_list.h" +#include "webkit/plugins/npapi/plugin_list.h" #include "webkit/plugins/npapi/webplugininfo.h" #ifdef CHROME_V8 @@ -1108,7 +1108,7 @@ std::string AboutVersionStrings(DictionaryValue* localized_strings, // Obtain the version of the first enabled Flash plugin. std::vector<webkit::npapi::WebPluginInfo> info_array; webkit::npapi::PluginList::Singleton()->GetPluginInfoArray( - GURL(), "application/x-shockwave-flash", false, &info_array, NULL); + GURL(), "application/x-shockwave-flash", false, NULL, &info_array, NULL); string16 flash_version = l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLED_PLUGIN); for (size_t i = 0; i < info_array.size(); ++i) { diff --git a/chrome/browser/chromeos/gview_request_interceptor.cc b/chrome/browser/chromeos/gview_request_interceptor.cc index fe98c15..6d176ec 100644 --- a/chrome/browser/chromeos/gview_request_interceptor.cc +++ b/chrome/browser/chromeos/gview_request_interceptor.cc @@ -6,6 +6,8 @@ #include "base/file_path.h" #include "base/path_service.h" +#include "chrome/browser/profiles/profile_io_data.h" +#include "chrome/browser/plugin_prefs.h" #include "chrome/common/chrome_paths.h" #include "googleurl/src/gurl.h" #include "net/base/escape.h" diff --git a/chrome/browser/chromeos/gview_request_interceptor_unittest.cc b/chrome/browser/chromeos/gview_request_interceptor_unittest.cc index f841bf5..5e573fe 100644 --- a/chrome/browser/chromeos/gview_request_interceptor_unittest.cc +++ b/chrome/browser/chromeos/gview_request_interceptor_unittest.cc @@ -15,7 +15,7 @@ #include "net/url_request/url_request_test_job.h" #include "net/url_request/url_request_test_util.h" #include "testing/gtest/include/gtest/gtest.h" -#include "webkit/glue/plugins/plugin_list.h" +#include "webkit/plugins/npapi/plugin_list.h" namespace chromeos { diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc index b3039d7..a1f4c1a 100644 --- a/chrome/browser/metrics/metrics_service.cc +++ b/chrome/browser/metrics/metrics_service.cc @@ -341,7 +341,7 @@ class MetricsService::InitTask : public Task { virtual void Run() { std::vector<webkit::npapi::WebPluginInfo> plugins; - webkit::npapi::PluginList::Singleton()->GetPlugins(false, &plugins); + webkit::npapi::PluginList::Singleton()->GetPlugins(&plugins); std::string hardware_class; // Empty string by default. #if defined(OS_CHROMEOS) chromeos::system::StatisticsProvider::GetInstance()->GetMachineStatistic( diff --git a/chrome/browser/plugin_data_remover.cc b/chrome/browser/plugin_data_remover.cc index ac5a5cf..e17254e 100644 --- a/chrome/browser/plugin_data_remover.cc +++ b/chrome/browser/plugin_data_remover.cc @@ -168,20 +168,20 @@ void PluginDataRemover::SignalDone() { bool PluginDataRemover::IsSupported() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); bool allow_wildcard = false; - webkit::npapi::WebPluginInfo plugin; - std::string mime_type; - if (!webkit::npapi::PluginList::Singleton()->GetPluginInfo( - GURL(), kFlashMimeType, allow_wildcard, &plugin, &mime_type)) { + std::vector<webkit::npapi::WebPluginInfo> plugins; + webkit::npapi::PluginList::Singleton()->GetPluginInfoArray( + GURL(), kFlashMimeType, allow_wildcard, NULL, &plugins, NULL); + std::vector<webkit::npapi::WebPluginInfo>::iterator plugin = plugins.begin(); + if (plugin == plugins.end()) return false; - } scoped_ptr<Version> version( - webkit::npapi::PluginGroup::CreateVersionFromString(plugin.version)); + webkit::npapi::PluginGroup::CreateVersionFromString(plugin->version)); scoped_ptr<Version> min_version(Version::GetVersionFromString( CommandLine::ForCurrentProcess()->GetSwitchValueASCII( switches::kMinClearSiteDataFlashVersion))); if (!min_version.get()) min_version.reset(Version::GetVersionFromString(kMinFlashVersion)); - return webkit::npapi::IsPluginEnabled(plugin) && + return webkit::npapi::IsPluginEnabled(*plugin) && version.get() && min_version->CompareTo(*version) == -1; } diff --git a/chrome/browser/plugin_data_remover_helper.h b/chrome/browser/plugin_data_remover_helper.h index dec4f41..7cd37af 100644 --- a/chrome/browser/plugin_data_remover_helper.h +++ b/chrome/browser/plugin_data_remover_helper.h @@ -25,7 +25,7 @@ class PluginDataRemoverHelper : public NotificationObserver { // Binds this object to the |pref_name| preference in |prefs|, notifying // |observer| if the value changes. - // This fires off a request to the NPAPI::PluginList (via PluginDataRemover) + // This fires off a request to the PluginList (via PluginDataRemover) // on the FILE thread to get the list of installed plug-ins. void Init(const char* pref_name, PrefService* prefs, diff --git a/chrome/browser/plugin_updater.cc b/chrome/browser/plugin_updater.cc index bd12749..887fba8 100644 --- a/chrome/browser/plugin_updater.cc +++ b/chrome/browser/plugin_updater.cc @@ -264,7 +264,7 @@ void PluginUpdater::UpdatePreferences(Profile* profile, int delay_ms) { void PluginUpdater::GetPreferencesDataOnFileThread(void* profile) { std::vector<webkit::npapi::WebPluginInfo> plugins; - webkit::npapi::PluginList::Singleton()->GetPlugins(false, &plugins); + webkit::npapi::PluginList::Singleton()->GetPlugins(&plugins); std::vector<webkit::npapi::PluginGroup> groups; webkit::npapi::PluginList::Singleton()->GetPluginGroups(false, &groups); diff --git a/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.mm b/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.mm index b8975c5..32f2549 100644 --- a/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.mm +++ b/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.mm @@ -9,7 +9,6 @@ #include "base/sys_string_conversions.h" #include "base/utf_string_conversions.h" #include "chrome/browser/content_settings/host_content_settings_map.h" -#include "chrome/browser/plugin_updater.h" #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h" #import "chrome/browser/ui/cocoa/info_bubble_view.h" @@ -18,7 +17,7 @@ #include "skia/ext/skia_utils_mac.h" #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" #include "ui/base/l10n/l10n_util.h" -#include "webkit/glue/plugins/plugin_list.h" +#include "webkit/plugins/npapi/plugin_list.h" namespace { @@ -243,7 +242,7 @@ NSTextField* LabelWithFrame(NSString* text, const NSRect& frame) { for (std::set<std::string>::iterator it = plugins.begin(); it != plugins.end(); ++it) { NSString* name = SysUTF16ToNSString( - NPAPI::PluginList::Singleton()->GetPluginGroupName(*it)); + webkit::npapi::PluginList::Singleton()->GetPluginGroupName(*it)); if ([name length] == 0) name = base::SysUTF8ToNSString(*it); [pluginArray addObject:name]; diff --git a/chrome/browser/ui/cocoa/drag_util.mm b/chrome/browser/ui/cocoa/drag_util.mm index 3a0d580..88c746b 100644 --- a/chrome/browser/ui/cocoa/drag_util.mm +++ b/chrome/browser/ui/cocoa/drag_util.mm @@ -79,11 +79,15 @@ static BOOL IsSupportedFileURL(const GURL& url) { return YES; // Check whether there is a plugin that supports the mime type. (e.g. PDF) - webkit::npapi::PluginList* list = webkit::npapi::PluginList::Singleton(); - webkit::npapi::WebPluginInfo info; - if (!list->stale() && - list->GetPluginInfo(GURL(), mime_type, false, &info, NULL)) { - return webkit::npapi::IsPluginEnabled(info); + // TODO(bauerb): This possibly uses stale information, but it's guaranteed not + // to do disk access. + bool stale = false; + std::vector<webkit::npapi::WebPluginInfo> info_array; + webkit::npapi::PluginList::Singleton()->GetPluginInfoArray( + url, mime_type, false, &stale, &info_array, NULL); + for (size_t i = 0; i < info_array.size(); ++i) { + if (webkit::npapi::IsPluginEnabled(info_array[i])) + return true; } return NO; diff --git a/chrome/browser/ui/views/content_setting_bubble_contents.cc b/chrome/browser/ui/views/content_setting_bubble_contents.cc index b3c28ac..e0b505a 100644 --- a/chrome/browser/ui/views/content_setting_bubble_contents.cc +++ b/chrome/browser/ui/views/content_setting_bubble_contents.cc @@ -10,7 +10,6 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/content_settings/host_content_settings_map.h" -#include "chrome/browser/plugin_updater.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" #include "chrome/browser/ui/views/browser_dialogs.h" @@ -28,7 +27,7 @@ #include "views/controls/separator.h" #include "views/layout/grid_layout.h" #include "views/layout/layout_constants.h" -#include "webkit/glue/plugins/plugin_list.h" +#include "webkit/plugins/npapi/plugin_list.h" #if defined(TOOLKIT_USES_GTK) #include "ui/gfx/gtk_util.h" @@ -206,7 +205,7 @@ void ContentSettingBubbleContents::InitControlLayout() { for (std::set<std::string>::const_iterator it = plugins.begin(); it != plugins.end(); ++it) { std::wstring name = UTF16ToWide( - NPAPI::PluginList::Singleton()->GetPluginGroupName(*it)); + webkit::npapi::PluginList::Singleton()->GetPluginGroupName(*it)); if (name.empty()) name = UTF8ToWide(*it); layout->StartRow(0, single_column_set_id); diff --git a/chrome/browser/ui/webui/flash_ui.cc b/chrome/browser/ui/webui/flash_ui.cc index a456eaf..bcf7cff 100644 --- a/chrome/browser/ui/webui/flash_ui.cc +++ b/chrome/browser/ui/webui/flash_ui.cc @@ -26,7 +26,7 @@ #include "grit/theme_resources.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" -#include "webkit/glue/plugins/plugin_list.h" +#include "webkit/plugins/npapi/plugin_list.h" #include "webkit/plugins/npapi/webplugininfo.h" #if defined(OS_WIN) @@ -223,7 +223,7 @@ void FlashDOMHandler::MaybeRespondToPage() { // Obtain the version of the Flash plugins. std::vector<webkit::npapi::WebPluginInfo> info_array; webkit::npapi::PluginList::Singleton()->GetPluginInfoArray( - GURL(), "application/x-shockwave-flash", false, &info_array, NULL); + GURL(), "application/x-shockwave-flash", false, NULL, &info_array, NULL); string16 flash_version; if (info_array.empty()) { AddPair(list, ASCIIToUTF16("Flash plugin"), "Disabled"); diff --git a/content/browser/plugin_service.cc b/content/browser/plugin_service.cc index d090917..154d062 100644 --- a/content/browser/plugin_service.cc +++ b/content/browser/plugin_service.cc @@ -323,7 +323,7 @@ void PluginService::GetAllowedPluginForOpenChannelToPlugin( bool found = GetPluginInfo( render_process_id, render_view_id, url, mime_type, &info, NULL); FilePath plugin_path; - if (found && webkit::npapi::IsPluginEnabled(info)) + if (found) plugin_path = FilePath(info.path); // Now we jump back to the IO thread to finish opening the channel. @@ -355,7 +355,6 @@ bool PluginService::GetPluginInfo(int render_process_id, // GetPluginInfoArray may need to load the plugins, so we need to be // on the FILE thread. DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); - bool allow_wildcard = true; { base::AutoLock auto_lock(overridden_plugins_lock_); for (size_t i = 0; i < overridden_plugins_.size(); ++i) { @@ -369,8 +368,20 @@ bool PluginService::GetPluginInfo(int render_process_id, } } } - return webkit::npapi::PluginList::Singleton()->GetPluginInfo( - url, mime_type, allow_wildcard, info, actual_mime_type); + bool allow_wildcard = true; + std::vector<webkit::npapi::WebPluginInfo> plugins; + std::vector<std::string> mime_types; + webkit::npapi::PluginList::Singleton()->GetPluginInfoArray( + url, mime_type, allow_wildcard, NULL, &plugins, &mime_types); + for (size_t i = 0; i < plugins.size(); ++i) { + if (webkit::npapi::IsPluginEnabled(plugins[i])) { + *info = plugins[i]; + if (actual_mime_type) + *actual_mime_type = mime_types[i]; + return true; + } + } + return false; } void PluginService::OnWaitableEventSignaled( diff --git a/content/browser/renderer_host/buffered_resource_handler.cc b/content/browser/renderer_host/buffered_resource_handler.cc index 5c79d7b..8626682 100644 --- a/content/browser/renderer_host/buffered_resource_handler.cc +++ b/content/browser/renderer_host/buffered_resource_handler.cc @@ -386,21 +386,26 @@ bool BufferedResourceHandler::ShouldDownload(bool* need_plugin_list) { if (net::IsSupportedMimeType(type)) return false; + // Finally, check the plugin list. + bool allow_wildcard = false; + bool stale = false; + std::vector<webkit::npapi::WebPluginInfo> plugins; + webkit::npapi::PluginList::Singleton()->GetPluginInfoArray( + request_->url(), type, allow_wildcard, &stale, &plugins, NULL); if (need_plugin_list) { - if (webkit::npapi::PluginList::Singleton()->stale()) { + if (stale) { *need_plugin_list = true; return true; } } else { - DCHECK(!webkit::npapi::PluginList::Singleton()->stale()); + DCHECK(!stale); } - // Finally, check the plugin list. - webkit::npapi::WebPluginInfo info; - bool allow_wildcard = false; - return !webkit::npapi::PluginList::Singleton()->GetPluginInfo( - GURL(), type, allow_wildcard, &info, NULL) || - !webkit::npapi::IsPluginEnabled(info); + for (size_t i = 0; i < plugins.size(); ++i) { + if (webkit::npapi::IsPluginEnabled(plugins[i])) + return false; + } + return true; } void BufferedResourceHandler::UseAlternateResourceHandler( @@ -436,7 +441,7 @@ void BufferedResourceHandler::UseAlternateResourceHandler( void BufferedResourceHandler::LoadPlugins() { std::vector<webkit::npapi::WebPluginInfo> plugins; - webkit::npapi::PluginList::Singleton()->GetPlugins(false, &plugins); + webkit::npapi::PluginList::Singleton()->GetPlugins(&plugins); BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, diff --git a/content/browser/renderer_host/render_message_filter.cc b/content/browser/renderer_host/render_message_filter.cc index de6d129..0e076ca 100644 --- a/content/browser/renderer_host/render_message_filter.cc +++ b/content/browser/renderer_host/render_message_filter.cc @@ -522,16 +522,22 @@ void RenderMessageFilter::OnGetPlugins( // is accumulated by doing multiple reads from disk. This effect is // multiplied when we have several pages requesting this operation. if (refresh) { - const base::TimeDelta threshold = base::TimeDelta::FromSeconds( - kPluginsRefreshThresholdInSeconds); - const base::TimeTicks now = base::TimeTicks::Now(); - if (now - last_plugin_refresh_time_ < threshold) - refresh = false; // Ignore refresh request; threshold not exceeded yet. - else - last_plugin_refresh_time_ = now; + const base::TimeDelta threshold = base::TimeDelta::FromSeconds( + kPluginsRefreshThresholdInSeconds); + const base::TimeTicks now = base::TimeTicks::Now(); + if (now - last_plugin_refresh_time_ >= threshold) { + // Only refresh if the threshold hasn't been exceeded yet. + webkit::npapi::PluginList::Singleton()->RefreshPlugins(); + last_plugin_refresh_time_ = now; + } } - webkit::npapi::PluginList::Singleton()->GetEnabledPlugins(refresh, plugins); + std::vector<webkit::npapi::WebPluginInfo> all_plugins; + webkit::npapi::PluginList::Singleton()->GetPlugins(&all_plugins); + for (size_t i = 0; i < all_plugins.size(); ++i) { + if (webkit::npapi::IsPluginEnabled(all_plugins[i])) + plugins->push_back(all_plugins[i]); + } } void RenderMessageFilter::OnGetPluginInfo( diff --git a/webkit/plugins/npapi/plugin_list.cc b/webkit/plugins/npapi/plugin_list.cc index 6441a76..1fae6b3 100644 --- a/webkit/plugins/npapi/plugin_list.cc +++ b/webkit/plugins/npapi/plugin_list.cc @@ -397,10 +397,10 @@ void PluginList::LoadPluginsInternal(ScopedVector<PluginGroup>* plugin_groups) { LoadPlugin(FilePath(kDefaultPluginLibraryName), plugin_groups); } -void PluginList::LoadPlugins(bool refresh) { +void PluginList::LoadPlugins() { { base::AutoLock lock(lock_); - if (!refresh && !plugins_need_refresh_) + if (!plugins_need_refresh_) return; } @@ -482,7 +482,7 @@ void PluginList::LoadPlugin(const FilePath& path, // WebKit hands to the Plugin before it tries // to handle mimeTypes on its own. const std::string &mime_type = plugin_info.mime_types[i].mime_type; - if (mime_type == "*" ) + if (mime_type == "*") return; } } @@ -491,9 +491,8 @@ void PluginList::LoadPlugin(const FilePath& path, AddToPluginGroups(plugin_info, plugin_groups); } -void PluginList::GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { - LoadPlugins(refresh); - +void PluginList::GetPlugins(std::vector<WebPluginInfo>* plugins) { + LoadPlugins(); base::AutoLock lock(lock_); for (size_t i = 0; i < plugin_groups_.size(); ++i) { const std::vector<WebPluginInfo>& gr_plugins = @@ -502,33 +501,21 @@ void PluginList::GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { } } -void PluginList::GetEnabledPlugins(bool refresh, - std::vector<WebPluginInfo>* plugins) { - LoadPlugins(refresh); - - plugins->clear(); - base::AutoLock lock(lock_); - for (size_t i = 0; i < plugin_groups_.size(); ++i) { - const std::vector<WebPluginInfo>& gr_plugins = - plugin_groups_[i]->web_plugins_info(); - for (size_t i = 0; i < gr_plugins.size(); ++i) { - if (IsPluginEnabled(gr_plugins[i])) - plugins->push_back(gr_plugins[i]); - } - } -} - void PluginList::GetPluginInfoArray( const GURL& url, const std::string& mime_type, bool allow_wildcard, + bool* use_stale, std::vector<WebPluginInfo>* info, std::vector<std::string>* actual_mime_types) { DCHECK(mime_type == StringToLowerASCII(mime_type)); DCHECK(info); - LoadPlugins(false); + if (!use_stale) + LoadPlugins(); base::AutoLock lock(lock_); + if (use_stale) + *use_stale = plugins_need_refresh_; info->clear(); if (actual_mime_types) actual_mime_types->clear(); @@ -617,38 +604,9 @@ void PluginList::GetPluginInfoArray( } } -bool PluginList::GetPluginInfo(const GURL& url, - const std::string& mime_type, - bool allow_wildcard, - WebPluginInfo* info, - std::string* actual_mime_type) { - DCHECK(info); - std::vector<WebPluginInfo> info_list; - - // GetPluginInfoArray has slightly less work to do if we can pass - // NULL for the mime type list... - if (actual_mime_type) { - std::vector<std::string> mime_type_list; - GetPluginInfoArray( - url, mime_type, allow_wildcard, &info_list, &mime_type_list); - if (!info_list.empty()) { - *info = info_list[0]; - *actual_mime_type = mime_type_list[0]; - return true; - } - } else { - GetPluginInfoArray(url, mime_type, allow_wildcard, &info_list, NULL); - if (!info_list.empty()) { - *info = info_list[0]; - return true; - } - } - return false; -} - bool PluginList::GetPluginInfoByPath(const FilePath& plugin_path, WebPluginInfo* info) { - LoadPlugins(false); + LoadPlugins(); base::AutoLock lock(lock_); for (size_t i = 0; i < plugin_groups_.size(); ++i) { const std::vector<WebPluginInfo>& plugins = @@ -668,7 +626,7 @@ void PluginList::GetPluginGroups( bool load_if_necessary, std::vector<PluginGroup>* plugin_groups) { if (load_if_necessary) - LoadPlugins(false); + LoadPlugins(); base::AutoLock lock(lock_); plugin_groups->clear(); for (size_t i = 0; i < plugin_groups_.size(); ++i) { diff --git a/webkit/plugins/npapi/plugin_list.h b/webkit/plugins/npapi/plugin_list.h index e575a91..46c0bf6 100644 --- a/webkit/plugins/npapi/plugin_list.h +++ b/webkit/plugins/npapi/plugin_list.h @@ -118,10 +118,7 @@ class PluginList { std::vector<WebPluginMimeType>* parsed_mime_types); // Get all the plugins. - void GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins); - - // Get all the enabled plugins. - void GetEnabledPlugins(bool refresh, std::vector<WebPluginInfo>* plugins); + void GetPlugins(std::vector<WebPluginInfo>* plugins); // Returns a list in |info| containing plugins that are found for // the given url and mime type (including disabled plugins, for @@ -133,20 +130,16 @@ class PluginList { // type). The |info| parameter is required to be non-NULL. The // list is in order of "most desirable" to "least desirable", // meaning that the default plugin is at the end of the list. + // If |use_stale| is NULL, this will load the plug-in list if necessary. + // If it is not NULL, the plug-in list will not be loaded, and |*use_stale| + // will be true iff the plug-in list was stale. void GetPluginInfoArray(const GURL& url, const std::string& mime_type, bool allow_wildcard, + bool* use_stale, std::vector<WebPluginInfo>* info, std::vector<std::string>* actual_mime_types); - // Returns the first item from the list returned in GetPluginInfo in |info|. - // Returns true if it found a match. |actual_mime_type| may be NULL. - bool GetPluginInfo(const GURL& url, - const std::string& mime_type, - bool allow_wildcard, - WebPluginInfo* info, - std::string* actual_mime_type); - // Get plugin info by plugin path (including disabled plugins). Returns true // if the plugin is found and WebPluginInfo has been filled in |info|. bool GetPluginInfoByPath(const FilePath& plugin_path, @@ -203,10 +196,6 @@ class PluginList { // version. void DisableOutdatedPluginGroups(); - // Returns true if the plugin list is stale, i.e. it will need to be - // (re)loaded on the next access. - bool stale() { return plugins_need_refresh_; } - virtual ~PluginList(); protected: @@ -238,7 +227,7 @@ class PluginList { virtual void LoadPluginsInternal(ScopedVector<PluginGroup>* plugin_groups); // Load all plugins from the default plugins directory - void LoadPlugins(bool refresh); + void LoadPlugins(); // Load all plugins from a specific directory. // |plugins| is updated with loaded plugin information. diff --git a/webkit/plugins/npapi/plugin_list_unittest.cc b/webkit/plugins/npapi/plugin_list_unittest.cc index 785fc3c..0782eb8 100644 --- a/webkit/plugins/npapi/plugin_list_unittest.cc +++ b/webkit/plugins/npapi/plugin_list_unittest.cc @@ -74,19 +74,12 @@ class PluginListTest : public testing::Test { TEST_F(PluginListTest, GetPlugins) { std::vector<WebPluginInfo> plugins; - plugin_list_.GetPlugins(false, &plugins); + plugin_list_.GetPlugins(&plugins); EXPECT_EQ(2u, plugins.size()); EXPECT_TRUE(Contains(plugins, foo_plugin_, true)); EXPECT_TRUE(Contains(plugins, bar_plugin_, true)); } -TEST_F(PluginListTest, GetEnabledPlugins) { - std::vector<WebPluginInfo> plugins; - plugin_list_.GetEnabledPlugins(false, &plugins); - EXPECT_EQ(1u, plugins.size()); - EXPECT_TRUE(Contains(plugins, foo_plugin_, true)); -} - TEST_F(PluginListTest, GetPluginGroup) { const PluginGroup* foo_group = plugin_list_.GetPluginGroup(foo_plugin_); EXPECT_EQ(ASCIIToUTF16(kFooGroupName), foo_group->GetGroupName()); @@ -98,41 +91,6 @@ TEST_F(PluginListTest, GetPluginGroup) { EXPECT_FALSE(bar_group->Enabled()); } -TEST_F(PluginListTest, EnableDisablePlugin) { - // Disable "foo" plugin. - plugin_list_.DisablePlugin(foo_plugin_.path); - std::vector<WebPluginInfo> plugins; - plugin_list_.GetEnabledPlugins(false, &plugins); - EXPECT_FALSE(Contains(plugins, foo_plugin_, false)); - const PluginGroup* foo_group = plugin_list_.GetPluginGroup(foo_plugin_); - EXPECT_FALSE(foo_group->Enabled()); - // Enable "bar" plugin. - plugin_list_.EnablePlugin(bar_plugin_.path); - plugin_list_.GetEnabledPlugins(false, &plugins); - EXPECT_TRUE(Contains(plugins, bar_plugin_, false)); - const PluginGroup* bar_group = plugin_list_.GetPluginGroup(bar_plugin_); - EXPECT_TRUE(bar_group->Enabled()); -} - -TEST_F(PluginListTest, EnableGroup) { - // Disable "foo" plugin group. - const PluginGroup* foo_group = plugin_list_.GetPluginGroup(foo_plugin_); - EXPECT_TRUE(foo_group->Enabled()); - EXPECT_TRUE(plugin_list_.EnableGroup(false, foo_group->GetGroupName())); - EXPECT_FALSE(foo_group->Enabled()); - std::vector<WebPluginInfo> plugins; - plugin_list_.GetEnabledPlugins(false, &plugins); - EXPECT_EQ(0u, plugins.size()); - EXPECT_FALSE(Contains(plugins, foo_plugin_, false)); - // Enable "bar" plugin group. - const PluginGroup* bar_group = plugin_list_.GetPluginGroup(bar_plugin_); - EXPECT_FALSE(bar_group->Enabled()); - plugin_list_.EnableGroup(true, bar_group->GetGroupName()); - EXPECT_TRUE(bar_group->Enabled()); - plugin_list_.GetEnabledPlugins(false, &plugins); - EXPECT_TRUE(Contains(plugins, bar_plugin_, false)); -} - TEST_F(PluginListTest, EmptyGroup) { std::vector<PluginGroup> groups; plugin_list_.GetPluginGroups(false, &groups); @@ -157,8 +115,9 @@ TEST_F(PluginListTest, DisableOutdated) { plugin_list_.AddPluginToLoad(plugin_3043); plugin_list_.AddPluginToLoad(plugin_3045); // Enfore the load to run. + plugin_list_.RefreshPlugins(); std::vector<WebPluginInfo> plugins; - plugin_list_.GetPlugins(true, &plugins); + plugin_list_.GetPlugins(&plugins); PluginGroup* group_3043 = const_cast<PluginGroup*>(plugin_list_.GetPluginGroup(plugin_3043)); const PluginGroup* group_3045 = plugin_list_.GetPluginGroup(plugin_3045); @@ -181,8 +140,9 @@ TEST_F(PluginListTest, BadPluginDescription) { plugin_list_.ClearPluginsToLoad(); plugin_list_.AddPluginToLoad(plugin_3043); // Now we should have them in the state we specified above. + plugin_list_.RefreshPlugins(); std::vector<WebPluginInfo> plugins; - plugin_list_.GetPlugins(true, &plugins); + plugin_list_.GetPlugins(&plugins); ASSERT_TRUE(Contains(plugins, plugin_3043, true)); } @@ -204,8 +164,9 @@ TEST_F(PluginListTest, DisableAndEnableBeforeLoad) { 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(true, &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)); @@ -231,8 +192,9 @@ TEST_F(PluginListTest, DisableBeforeLoad) { EXPECT_TRUE(plugin_list_.EnableGroup(false, ASCIIToUTF16(kFooGroupName))); + plugin_list_.RefreshPlugins(); std::vector<WebPluginInfo> plugins; - plugin_list_.GetPlugins(true, &plugins); + plugin_list_.GetPlugins(&plugins); ASSERT_EQ(2u, plugins.size()); ASSERT_EQ(WebPluginInfo::USER_DISABLED_POLICY_UNMANAGED, plugins[0].enabled); } diff --git a/webkit/support/webkit_support.cc b/webkit/support/webkit_support.cc index 87381b8..139c4b4 100644 --- a/webkit/support/webkit_support.cc +++ b/webkit/support/webkit_support.cc @@ -281,16 +281,16 @@ WebKit::WebKitClient* GetWebKitClient() { WebPlugin* CreateWebPlugin(WebFrame* frame, const WebPluginParams& params) { const bool kAllowWildcard = true; - webkit::npapi::WebPluginInfo info; - std::string actual_mime_type; - if (!webkit::npapi::PluginList::Singleton()->GetPluginInfo( - params.url, params.mimeType.utf8(), kAllowWildcard, &info, - &actual_mime_type) || !webkit::npapi::IsPluginEnabled(info)) { + std::vector<webkit::npapi::WebPluginInfo> plugins; + std::vector<std::string> mime_types; + webkit::npapi::PluginList::Singleton()->GetPluginInfoArray( + params.url, params.mimeType.utf8(), kAllowWildcard, + NULL, &plugins, &mime_types); + if (plugins.empty()) return NULL; - } return new WebPluginImplWithPageDelegate( - frame, params, info.path, actual_mime_type); + frame, params, plugins.front().path, mime_types.front()); } WebKit::WebMediaPlayer* CreateMediaPlayer(WebFrame* frame, diff --git a/webkit/support/webkit_support_glue.cc b/webkit/support/webkit_support_glue.cc index 02a2233..ef67877 100644 --- a/webkit/support/webkit_support_glue.cc +++ b/webkit/support/webkit_support_glue.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. @@ -16,7 +16,9 @@ namespace webkit_glue { void GetPlugins(bool refresh, std::vector<webkit::npapi::WebPluginInfo>* plugins) { - webkit::npapi::PluginList::Singleton()->GetPlugins(refresh, plugins); + if (refresh) + webkit::npapi::PluginList::Singleton()->RefreshPlugins(); + webkit::npapi::PluginList::Singleton()->GetPlugins(plugins); // Don't load the forked npapi_layout_test_plugin in DRT, we only want to // use the upstream version TestNetscapePlugIn. const FilePath::StringType kPluginBlackList[] = { diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc index 651635c..46d9184 100644 --- a/webkit/tools/test_shell/test_shell.cc +++ b/webkit/tools/test_shell/test_shell.cc @@ -685,7 +685,9 @@ bool GetFontTable(int fd, uint32_t table, uint8_t* output, void GetPlugins(bool refresh, std::vector<webkit::npapi::WebPluginInfo>* plugins) { - webkit::npapi::PluginList::Singleton()->GetPlugins(refresh, plugins); + if (refresh) + webkit::npapi::PluginList::Singleton()->RefreshPlugins(); + webkit::npapi::PluginList::Singleton()->GetPlugins(plugins); // Don't load the forked TestNetscapePlugIn in the chromium code, use // the copy in webkit.org's repository instead. const FilePath::StringType kPluginBlackList[] = { diff --git a/webkit/tools/test_shell/test_shell_gtk.cc b/webkit/tools/test_shell/test_shell_gtk.cc index b94da99..e4a638b 100644 --- a/webkit/tools/test_shell/test_shell_gtk.cc +++ b/webkit/tools/test_shell/test_shell_gtk.cc @@ -26,10 +26,10 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" #include "ui/base/resource/resource_bundle.h" -#include "webkit/glue/plugins/plugin_list.h" #include "webkit/glue/resource_loader_bridge.h" #include "webkit/glue/webkit_glue.h" #include "webkit/glue/webpreferences.h" +#include "webkit/plugins/npapi/plugin_list.h" #include "webkit/tools/test_shell/test_navigation_controller.h" #include "webkit/tools/test_shell/test_webview_delegate.h" diff --git a/webkit/tools/test_shell/test_shell_win.cc b/webkit/tools/test_shell/test_shell_win.cc index fffd48d..3b3c3b9 100644 --- a/webkit/tools/test_shell/test_shell_win.cc +++ b/webkit/tools/test_shell/test_shell_win.cc @@ -32,7 +32,7 @@ #include "ui/base/win/hwnd_util.h" #include "webkit/glue/webkit_glue.h" #include "webkit/glue/webpreferences.h" -#include "webkit/glue/plugins/plugin_list.h" +#include "webkit/plugins/npapi/plugin_list.h" #include "webkit/tools/test_shell/resource.h" #include "webkit/tools/test_shell/test_navigation_controller.h" #include "webkit/tools/test_shell/test_shell_devtools_agent.h" diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc index 61cc860..d327006 100644 --- a/webkit/tools/test_shell/test_webview_delegate.cc +++ b/webkit/tools/test_shell/test_webview_delegate.cc @@ -592,15 +592,16 @@ WebScreenInfo TestWebViewDelegate::screenInfo() { WebPlugin* TestWebViewDelegate::createPlugin(WebFrame* frame, const WebPluginParams& params) { bool allow_wildcard = true; - webkit::npapi::WebPluginInfo info; - std::string actual_mime_type; - if (!webkit::npapi::PluginList::Singleton()->GetPluginInfo( - params.url, params.mimeType.utf8(), allow_wildcard, &info, - &actual_mime_type) || !webkit::npapi::IsPluginEnabled(info)) + std::vector<webkit::npapi::WebPluginInfo> plugins; + std::vector<std::string> mime_types; + webkit::npapi::PluginList::Singleton()->GetPluginInfoArray( + params.url, params.mimeType.utf8(), allow_wildcard, + NULL, &plugins, &mime_types); + if (plugins.empty()) return NULL; return new webkit::npapi::WebPluginImpl( - frame, params, info.path, actual_mime_type, AsWeakPtr()); + frame, params, plugins.front().path, mime_types.front(), AsWeakPtr()); } WebWorker* TestWebViewDelegate::createWorker(WebFrame* frame, |