diff options
author | gspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-12 06:50:08 +0000 |
---|---|---|
committer | gspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-12 06:50:08 +0000 |
commit | 20a793eb518ccc6503f6521e0ebc806e8e686a06 (patch) | |
tree | 60f5ad1a91f7f0be1767afa7938a23cc84f12eed /webkit | |
parent | efd7ab46d727bad8ca7cf08f83b16f0ada6d9375 (diff) | |
download | chromium_src-20a793eb518ccc6503f6521e0ebc806e8e686a06.zip chromium_src-20a793eb518ccc6503f6521e0ebc806e8e686a06.tar.gz chromium_src-20a793eb518ccc6503f6521e0ebc806e8e686a06.tar.bz2 |
This changes GetPluginInfo so that we can request a list of plugins that match the criterion (mime type/url) instead of just the first one that matches.
This is in preparation for implementing a way for us to switch which flash plugin we select based on a whitelist of domains.
BUG=http://crosbug.com/7403
TEST=ran chrome unit_tests, ran chromeos version of chrome, passed trybots.
Review URL: http://codereview.chromium.org/3530017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62261 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/plugins/plugin_list.cc | 162 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_list.h | 42 | ||||
-rw-r--r-- | webkit/support/webkit_support.cc | 3 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_webview_delegate.cc | 6 |
4 files changed, 115 insertions, 98 deletions
diff --git a/webkit/glue/plugins/plugin_list.cc b/webkit/glue/plugins/plugin_list.cc index f312ab8..30e74b1 100644 --- a/webkit/glue/plugins/plugin_list.cc +++ b/webkit/glue/plugins/plugin_list.cc @@ -307,65 +307,6 @@ void PluginList::LoadPlugin(const FilePath& path, plugins->push_back(plugin_info); } -bool PluginList::FindPlugin(const std::string& mime_type, - bool allow_wildcard, - WebPluginInfo* info) { - DCHECK(mime_type == StringToLowerASCII(mime_type)); - - LoadPlugins(false); - AutoLock lock(lock_); - for (size_t i = 0; i < plugins_.size(); ++i) { - if (plugins_[i].enabled && - SupportsType(plugins_[i], mime_type, allow_wildcard)) { - *info = plugins_[i]; - return true; - } - } - - return false; -} - -bool PluginList::FindDisabledPlugin(const std::string& mime_type, - bool allow_wildcard, - WebPluginInfo* info) { - DCHECK(mime_type == StringToLowerASCII(mime_type)); - - LoadPlugins(false); - AutoLock lock(lock_); - for (size_t i = 0; i < plugins_.size(); ++i) { - if (!plugins_[i].enabled && - SupportsType(plugins_[i], mime_type, allow_wildcard)) { - *info = plugins_[i]; - return true; - } - } - - return false; -} - -bool PluginList::FindPlugin(const GURL &url, - std::string* actual_mime_type, - WebPluginInfo* info) { - LoadPlugins(false); - AutoLock lock(lock_); - std::string path = url.path(); - std::string::size_type last_dot = path.rfind('.'); - if (last_dot == std::string::npos) - return false; - - std::string extension = StringToLowerASCII(std::string(path, last_dot+1)); - - for (size_t i = 0; i < plugins_.size(); ++i) { - if (plugins_[i].enabled && - SupportsExtension(plugins_[i], extension, actual_mime_type)) { - *info = plugins_[i]; - return true; - } - } - - return false; -} - bool PluginList::SupportsType(const WebPluginInfo& info, const std::string &mime_type, bool allow_wildcard) { @@ -424,20 +365,109 @@ void PluginList::GetEnabledPlugins(bool refresh, } } +void PluginList::GetPluginInfoArray(const GURL& url, + const std::string& mime_type, + bool allow_wildcard, + std::vector<WebPluginInfo>* info, + std::vector<std::string>* actual_mime_types) { + DCHECK(mime_type == StringToLowerASCII(mime_type)); + DCHECK(info); + + LoadPlugins(false); + AutoLock lock(lock_); + info->clear(); + if (actual_mime_types) + actual_mime_types->clear(); + + std::set<FilePath> visited_plugins; + + // Add in enabled plugins by mime type. + WebPluginInfo default_plugin; + for (size_t i = 0; i < plugins_.size(); ++i) { + if (plugins_[i].enabled && + SupportsType(plugins_[i], mime_type, allow_wildcard)) { + FilePath path = plugins_[i].path; + if (path.value() != kDefaultPluginLibraryName && + visited_plugins.insert(path).second) { + info->push_back(plugins_[i]); + if (actual_mime_types) + actual_mime_types->push_back(mime_type); + } + } + } + + // Add in enabled plugins by url. + std::string path = url.path(); + std::string::size_type last_dot = path.rfind('.'); + if (last_dot != std::string::npos) { + std::string extension = StringToLowerASCII(std::string(path, last_dot+1)); + std::string actual_mime_type; + for (size_t i = 0; i < plugins_.size(); ++i) { + if (plugins_[i].enabled && + SupportsExtension(plugins_[i], extension, &actual_mime_type)) { + FilePath path = plugins_[i].path; + if (path.value() != kDefaultPluginLibraryName && + visited_plugins.insert(path).second) { + info->push_back(plugins_[i]); + if (actual_mime_types) + actual_mime_types->push_back(actual_mime_type); + } + } + } + } + + // Add in disabled plugins by mime type. + for (size_t i = 0; i < plugins_.size(); ++i) { + if (!plugins_[i].enabled && + SupportsType(plugins_[i], mime_type, allow_wildcard)) { + FilePath path = plugins_[i].path; + if (path.value() != kDefaultPluginLibraryName && + visited_plugins.insert(path).second) { + info->push_back(plugins_[i]); + if (actual_mime_types) + actual_mime_types->push_back(mime_type); + } + } + } + + // Add the default plugin at the end if it supports the mime type given. + if (!plugins_.empty()) { + const WebPluginInfo& default_info = plugins_.back(); + DCHECK(default_info.path.value() == kDefaultPluginLibraryName); + if (SupportsType(default_info, mime_type, allow_wildcard)) { + info->push_back(default_info); + if (actual_mime_types) + actual_mime_types->push_back(mime_type); + } + } +} + bool PluginList::GetPluginInfo(const GURL& url, const std::string& mime_type, bool allow_wildcard, WebPluginInfo* info, std::string* actual_mime_type) { - bool found = FindPlugin(mime_type, allow_wildcard, info); - if (!found || (info->path.value() == kDefaultPluginLibraryName)) { - if (FindPlugin(url, actual_mime_type, info) || - FindDisabledPlugin(mime_type, allow_wildcard, info)) { - found = true; + 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 found; + return false; } bool PluginList::GetPluginInfoByPath(const FilePath& plugin_path, diff --git a/webkit/glue/plugins/plugin_list.h b/webkit/glue/plugins/plugin_list.h index 2ab0b0a..25b903b 100644 --- a/webkit/glue/plugins/plugin_list.h +++ b/webkit/glue/plugins/plugin_list.h @@ -133,12 +133,24 @@ class PluginList { // Get all the enabled plugins. void GetEnabledPlugins(bool refresh, std::vector<WebPluginInfo>* plugins); - // Returns true if a plugin is found for the given url and mime type - // (including disabled plugins, for which |info->enabled| is false). - // The mime type which corresponds to the URL is optionally returned - // back. - // The allow_wildcard parameter controls whether this function returns - // plugins which support wildcard mime types (* as the mime type). + // Returns a list in |info| containing plugins that are found for + // the given url and mime type (including disabled plugins, for + // which |info->enabled| is false). The mime type which corresponds + // to the URL is optionally returned back in |actual_mime_types| (if + // it is non-NULL), one for each of the plugin info objects found. + // The |allow_wildcard| parameter controls whether this function + // returns plugins which support wildcard mime types (* as the mime + // 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. + void GetPluginInfoArray(const GURL& url, + const std::string& mime_type, + bool allow_wildcard, + 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, @@ -217,24 +229,6 @@ class PluginList { // list of disabled groups as well. bool ShouldDisableGroup(const string16& group_name); - // Find a plugin by mime type; only searches enabled plugins. - // The allow_wildcard parameter controls whether this function returns - // plugins which support wildcard mime types (* as the mime type) - bool FindPlugin(const std::string &mime_type, - bool allow_wildcard, - WebPluginInfo* info); - - // Just like |FindPlugin| but it only looks at the disabled plug-ins. - bool FindDisabledPlugin(const std::string &mime_type, - bool allow_wildcard, - WebPluginInfo* info); - - // Find a plugin by extension; only searches enabled plugins. Returns the - // corresponding mime type. - bool FindPlugin(const GURL &url, - std::string* actual_mime_type, - WebPluginInfo* info); - // Like GetPluginGroups above, but works on a given vector of plugins. static void GetPluginGroups(const std::vector<WebPluginInfo>* plugins, PluginMap* plugin_groups); diff --git a/webkit/support/webkit_support.cc b/webkit/support/webkit_support.cc index e9c516a..f0e3f85 100644 --- a/webkit/support/webkit_support.cc +++ b/webkit/support/webkit_support.cc @@ -256,9 +256,6 @@ WebPlugin* CreateWebPlugin(WebFrame* frame, return NULL; } - if (actual_mime_type.empty()) - actual_mime_type = params.mimeType.utf8(); - return new WebPluginImplWithPageDelegate( frame, params, info.path, actual_mime_type); } diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc index 4fe8d69..41bf9d3 100644 --- a/webkit/tools/test_shell/test_webview_delegate.cc +++ b/webkit/tools/test_shell/test_webview_delegate.cc @@ -702,12 +702,8 @@ WebPlugin* TestWebViewDelegate::createPlugin( std::string actual_mime_type; if (!NPAPI::PluginList::Singleton()->GetPluginInfo( params.url, params.mimeType.utf8(), allow_wildcard, &info, - &actual_mime_type) || !info.enabled) { + &actual_mime_type) || !info.enabled) return NULL; - } - - if (actual_mime_type.empty()) - actual_mime_type = params.mimeType.utf8(); return new webkit_glue::WebPluginImpl( frame, params, info.path, actual_mime_type, AsWeakPtr()); |