Commit a2eb1878 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Better encapsulate content::PluginList.

Make methods private when possible. Move methods that can go into an
anonymous namespace into one.

Change-Id: Ia921b6539aae45ce145c6a4583ebdbb7b9611707
Reviewed-on: https://chromium-review.googlesource.com/1174996Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583325}
parent ef705b67
...@@ -27,6 +27,45 @@ namespace { ...@@ -27,6 +27,45 @@ namespace {
base::LazyInstance<PluginList>::DestructorAtExit g_singleton = base::LazyInstance<PluginList>::DestructorAtExit g_singleton =
LAZY_INSTANCE_INITIALIZER; LAZY_INSTANCE_INITIALIZER;
// Returns true if the plugin supports |mime_type|. |mime_type| should be all
// lower case.
bool SupportsType(const WebPluginInfo& plugin,
const std::string& mime_type,
bool allow_wildcard) {
// Webkit will ask for a plugin to handle empty mime types.
if (mime_type.empty())
return false;
for (size_t i = 0; i < plugin.mime_types.size(); ++i) {
const WebPluginMimeType& mime_info = plugin.mime_types[i];
if (net::MatchesMimeType(mime_info.mime_type, mime_type)) {
if (!allow_wildcard && mime_info.mime_type == "*")
continue;
return true;
}
}
return false;
}
// Returns true if the given plugin supports a given file extension.
// |extension| should be all lower case. |actual_mime_type| will be set to the
// MIME type if found. The MIME type which corresponds to the extension is
// optionally returned back.
bool SupportsExtension(const WebPluginInfo& plugin,
const std::string& extension,
std::string* actual_mime_type) {
for (size_t i = 0; i < plugin.mime_types.size(); ++i) {
const WebPluginMimeType& mime_type = plugin.mime_types[i];
for (size_t j = 0; j < mime_type.file_extensions.size(); ++j) {
if (mime_type.file_extensions[j] == extension) {
*actual_mime_type = mime_type.mime_type;
return true;
}
}
}
return false;
}
} // namespace } // namespace
// static // static
...@@ -256,40 +295,6 @@ void PluginList::GetPluginInfoArray( ...@@ -256,40 +295,6 @@ void PluginList::GetPluginInfoArray(
} }
} }
bool PluginList::SupportsType(const WebPluginInfo& plugin,
const std::string& mime_type,
bool allow_wildcard) {
// Webkit will ask for a plugin to handle empty mime types.
if (mime_type.empty())
return false;
for (size_t i = 0; i < plugin.mime_types.size(); ++i) {
const WebPluginMimeType& mime_info = plugin.mime_types[i];
if (net::MatchesMimeType(mime_info.mime_type, mime_type)) {
if (!allow_wildcard && mime_info.mime_type == "*")
continue;
return true;
}
}
return false;
}
bool PluginList::SupportsExtension(const WebPluginInfo& plugin,
const std::string& extension,
std::string* actual_mime_type) {
for (size_t i = 0; i < plugin.mime_types.size(); ++i) {
const WebPluginMimeType& mime_type = plugin.mime_types[i];
for (size_t j = 0; j < mime_type.file_extensions.size(); ++j) {
if (mime_type.file_extensions[j] == extension) {
if (actual_mime_type)
*actual_mime_type = mime_type.mime_type;
return true;
}
}
}
return false;
}
void PluginList::RemoveExtraPluginPathLocked( void PluginList::RemoveExtraPluginPathLocked(
const base::FilePath& plugin_path) { const base::FilePath& plugin_path) {
lock_.AssertAcquired(); lock_.AssertAcquired();
......
...@@ -41,12 +41,6 @@ class CONTENT_EXPORT PluginList { ...@@ -41,12 +41,6 @@ class CONTENT_EXPORT PluginList {
// Gets the one instance of the PluginList. // Gets the one instance of the PluginList.
static PluginList* Singleton(); static PluginList* Singleton();
// Returns true if the plugin supports |mime_type|. |mime_type| should be all
// lower case.
static bool SupportsType(const WebPluginInfo& plugin,
const std::string& mime_type,
bool allow_wildcard);
// Cause the plugin list to refresh next time they are accessed, regardless // Cause the plugin list to refresh next time they are accessed, regardless
// of whether they are already loaded. // of whether they are already loaded.
void RefreshPlugins(); void RefreshPlugins();
...@@ -66,12 +60,6 @@ class CONTENT_EXPORT PluginList { ...@@ -66,12 +60,6 @@ class CONTENT_EXPORT PluginList {
// Gets a list of all the registered internal plugins. // Gets a list of all the registered internal plugins.
void GetInternalPlugins(std::vector<WebPluginInfo>* plugins); void GetInternalPlugins(std::vector<WebPluginInfo>* plugins);
// Creates a WebPluginInfo structure given a plugin's path. On success
// returns true, with the information being put into "info".
// Returns false if the library couldn't be found, or if it's not a plugin.
bool ReadPluginInfo(const base::FilePath& filename,
WebPluginInfo* info);
// Get all the plugins synchronously, loading them if necessary. // Get all the plugins synchronously, loading them if necessary.
void GetPlugins(std::vector<WebPluginInfo>* plugins); void GetPlugins(std::vector<WebPluginInfo>* plugins);
...@@ -98,11 +86,20 @@ class CONTENT_EXPORT PluginList { ...@@ -98,11 +86,20 @@ class CONTENT_EXPORT PluginList {
std::vector<WebPluginInfo>* info, std::vector<WebPluginInfo>* info,
std::vector<std::string>* actual_mime_types); std::vector<std::string>* actual_mime_types);
// Load a specific plugin with full path. Return true iff loading the plugin void set_will_load_plugins_callback(const base::Closure& callback);
// was successful.
bool LoadPluginIntoPluginList(const base::FilePath& filename, private:
std::vector<WebPluginInfo>* plugins, enum LoadingState {
WebPluginInfo* plugin_info); LOADING_STATE_NEEDS_REFRESH,
LOADING_STATE_REFRESHING,
LOADING_STATE_UP_TO_DATE,
};
friend class PluginListTest;
friend struct base::LazyInstanceTraitsBase<PluginList>;
PluginList();
~PluginList();
// The following functions are used to support probing for WebPluginInfo // The following functions are used to support probing for WebPluginInfo
// using a different instance of this class. // using a different instance of this class.
...@@ -120,37 +117,24 @@ class CONTENT_EXPORT PluginList { ...@@ -120,37 +117,24 @@ class CONTENT_EXPORT PluginList {
// Clears the internal list of Plugins and copies them from the vector. // Clears the internal list of Plugins and copies them from the vector.
void SetPlugins(const std::vector<WebPluginInfo>& plugins); void SetPlugins(const std::vector<WebPluginInfo>& plugins);
void set_will_load_plugins_callback(const base::Closure& callback);
virtual ~PluginList();
private:
enum LoadingState {
LOADING_STATE_NEEDS_REFRESH,
LOADING_STATE_REFRESHING,
LOADING_STATE_UP_TO_DATE,
};
friend class PluginListTest;
friend struct base::LazyInstanceTraitsBase<PluginList>;
PluginList();
// Load all plugins from the default plugins directory. // Load all plugins from the default plugins directory.
void LoadPlugins(); void LoadPlugins();
// Returns true if the given plugin supports a given file extension.
// |extension| should be all lower case. If |mime_type| is not NULL, it will
// be set to the MIME type if found. The MIME type which corresponds to the
// extension is optionally returned back.
bool SupportsExtension(const WebPluginInfo& plugin,
const std::string& extension,
std::string* actual_mime_type);
// Removes |plugin_path| from the list of extra plugin paths. Should only be // Removes |plugin_path| from the list of extra plugin paths. Should only be
// called while holding |lock_|. // called while holding |lock_|.
void RemoveExtraPluginPathLocked(const base::FilePath& plugin_path); void RemoveExtraPluginPathLocked(const base::FilePath& plugin_path);
// Creates a WebPluginInfo structure given a plugin's path. On success
// returns true, with the information being put into "info".
// Returns false if the library couldn't be found, or if it's not a plugin.
bool ReadPluginInfo(const base::FilePath& filename, WebPluginInfo* info);
// Load a specific plugin with full path. Return true iff loading the plugin
// was successful.
bool LoadPluginIntoPluginList(const base::FilePath& filename,
std::vector<WebPluginInfo>* plugins,
WebPluginInfo* plugin_info);
// //
// Internals // Internals
// //
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment