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 /content | |
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
Diffstat (limited to 'content')
-rw-r--r-- | content/browser/plugin_service.cc | 19 | ||||
-rw-r--r-- | content/browser/renderer_host/buffered_resource_handler.cc | 23 | ||||
-rw-r--r-- | content/browser/renderer_host/render_message_filter.cc | 22 |
3 files changed, 43 insertions, 21 deletions
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( |