Commit 68b63bc6 authored by ibraaaa@google.com's avatar ibraaaa@google.com

1st CL in a series to remove PluginGroup. Updates PluginList.

This is the first CL in a series that aims at removing PluginGroup class and moving harded coded group definition data to .json config files. This CL updates PluginList class with new methods not relying on PluginGroup class, these methods are to be called by upper layer methods instead of PluginGroup dependent methods. Changes in upper layer will be introduced in upcoming CLs. The last CL in the series should remove PluginGroup class and all its dependencies.


BUG=124396

Review URL: https://chromiumcodereview.appspot.com/10860044

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152399 0039d316-1c4b-4281-b951-d872f2087c98
parent a9e0d141
...@@ -29,11 +29,19 @@ bool MockPluginList::GetPluginsNoRefresh( ...@@ -29,11 +29,19 @@ bool MockPluginList::GetPluginsNoRefresh(
return true; return true;
} }
// TODO(ibraaaa): DELETE. http://crbug.com/124396
void MockPluginList::LoadPluginsInternal( void MockPluginList::LoadPluginsInternal(
ScopedVector<PluginGroup>* plugin_groups) { ScopedVector<PluginGroup>* plugin_groups) {
for (size_t i = 0; i < plugins_to_load_.size(); ++i) for (size_t i = 0; i < plugins_to_load_.size(); ++i)
AddToPluginGroups(plugins_to_load_[i], plugin_groups); AddToPluginGroups(plugins_to_load_[i], plugin_groups);
} }
void MockPluginList::LoadPluginsIntoPluginListInternal(
std::vector<webkit::WebPluginInfo>* plugins) {
for (size_t i = 0; i < plugins_to_load_.size(); ++i) {
plugins->push_back(plugins_to_load_[i]);
}
}
} // npapi } // npapi
} // webkit } // webkit
...@@ -29,8 +29,13 @@ class MockPluginList : public PluginList { ...@@ -29,8 +29,13 @@ class MockPluginList : public PluginList {
std::vector<WebPluginInfo> plugins_to_load_; std::vector<WebPluginInfo> plugins_to_load_;
// PluginList methods: // PluginList methods:
// TODO(ibraaaa): DELETE. http://crbug.com/124396
virtual void LoadPluginsInternal( virtual void LoadPluginsInternal(
ScopedVector<PluginGroup>* plugin_groups) OVERRIDE; ScopedVector<PluginGroup>* plugin_groups) OVERRIDE;
virtual void LoadPluginsIntoPluginListInternal(
std::vector<webkit::WebPluginInfo>* plugins) OVERRIDE;
}; };
} // npapi } // npapi
......
...@@ -53,6 +53,7 @@ bool AllowMimeTypeMismatch(const std::string& orig_mime_type, ...@@ -53,6 +53,7 @@ bool AllowMimeTypeMismatch(const std::string& orig_mime_type,
namespace webkit { namespace webkit {
namespace npapi { namespace npapi {
// TODO(ibraaaa): DELETE all hardcoded definitions. http://crbug.com/124396
// Note: If you change the plug-in definitions here, also update // Note: If you change the plug-in definitions here, also update
// chrome/browser/resources/plugins_*.json correspondingly! // chrome/browser/resources/plugins_*.json correspondingly!
// In particular, the identifier needs to be kept in sync. // In particular, the identifier needs to be kept in sync.
...@@ -290,6 +291,7 @@ PluginList::PluginList() ...@@ -290,6 +291,7 @@ PluginList::PluginList()
ARRAYSIZE_UNSAFE(kGroupDefinitions)); ARRAYSIZE_UNSAFE(kGroupDefinitions));
} }
// TODO(ibraaaa): DELETE and add a different one. http://crbug.com/124396
PluginList::PluginList(const PluginGroupDefinition* definitions, PluginList::PluginList(const PluginGroupDefinition* definitions,
size_t num_definitions) size_t num_definitions)
: :
...@@ -301,6 +303,7 @@ PluginList::PluginList(const PluginGroupDefinition* definitions, ...@@ -301,6 +303,7 @@ PluginList::PluginList(const PluginGroupDefinition* definitions,
AddHardcodedPluginGroups(definitions, num_definitions); AddHardcodedPluginGroups(definitions, num_definitions);
} }
// TODO(ibraaaa): DELETE. http://crbug.com/124396
PluginGroup* PluginList::CreatePluginGroup( PluginGroup* PluginList::CreatePluginGroup(
const webkit::WebPluginInfo& web_plugin_info) const { const webkit::WebPluginInfo& web_plugin_info) const {
for (size_t i = 0; i < hardcoded_plugin_groups_.size(); ++i) { for (size_t i = 0; i < hardcoded_plugin_groups_.size(); ++i) {
...@@ -311,6 +314,7 @@ PluginGroup* PluginList::CreatePluginGroup( ...@@ -311,6 +314,7 @@ PluginGroup* PluginList::CreatePluginGroup(
return PluginGroup::FromWebPluginInfo(web_plugin_info); return PluginGroup::FromWebPluginInfo(web_plugin_info);
} }
// TODO(ibraaaa): DELETE. http://crbug.com/124396
void PluginList::LoadPluginsInternal(ScopedVector<PluginGroup>* plugin_groups) { void PluginList::LoadPluginsInternal(ScopedVector<PluginGroup>* plugin_groups) {
base::Closure will_load_callback; base::Closure will_load_callback;
{ {
...@@ -331,6 +335,27 @@ void PluginList::LoadPluginsInternal(ScopedVector<PluginGroup>* plugin_groups) { ...@@ -331,6 +335,27 @@ void PluginList::LoadPluginsInternal(ScopedVector<PluginGroup>* plugin_groups) {
} }
} }
void PluginList::LoadPluginsIntoPluginListInternal(
std::vector<webkit::WebPluginInfo>* plugins) {
base::Closure will_load_callback;
{
base::AutoLock lock(lock_);
will_load_callback = will_load_plugins_callback_;
}
if (!will_load_callback.is_null())
will_load_callback.Run();
std::vector<FilePath> plugin_paths;
GetPluginPathsToLoad(&plugin_paths);
for (std::vector<FilePath>::const_iterator it = plugin_paths.begin();
it != plugin_paths.end();
++it) {
WebPluginInfo plugin_info;
LoadPluginIntoPluginList(*it, plugins, &plugin_info);
}
}
void PluginList::LoadPlugins() { void PluginList::LoadPlugins() {
{ {
base::AutoLock lock(lock_); base::AutoLock lock(lock_);
...@@ -340,18 +365,25 @@ void PluginList::LoadPlugins() { ...@@ -340,18 +365,25 @@ void PluginList::LoadPlugins() {
loading_state_ = LOADING_STATE_REFRESHING; loading_state_ = LOADING_STATE_REFRESHING;
} }
ScopedVector<PluginGroup> new_plugin_groups; ScopedVector<PluginGroup> new_plugin_groups; // TODO(ibraaaa): DELETE
// Do the actual loading of the plugins.
LoadPluginsInternal(&new_plugin_groups); // TODO(ibraaaa): DELETE
std::vector<webkit::WebPluginInfo> new_plugins;
// Do the actual loading of the plugins. // Do the actual loading of the plugins.
LoadPluginsInternal(&new_plugin_groups); LoadPluginsIntoPluginListInternal(&new_plugins);
base::AutoLock lock(lock_); base::AutoLock lock(lock_);
plugin_groups_.swap(new_plugin_groups); plugin_groups_.swap(new_plugin_groups); // TODO(ibraaaa): DELETE
plugins_list_.swap(new_plugins);
// If we haven't been invalidated in the mean time, mark the plug-in list as // If we haven't been invalidated in the mean time, mark the plug-in list as
// up-to-date. // up-to-date.
if (loading_state_ != LOADING_STATE_NEEDS_REFRESH) if (loading_state_ != LOADING_STATE_NEEDS_REFRESH)
loading_state_ = LOADING_STATE_UP_TO_DATE; loading_state_ = LOADING_STATE_UP_TO_DATE;
} }
// TODO(ibraaaa): DELETE. http://crbug.com/124396
bool PluginList::LoadPlugin(const FilePath& path, bool PluginList::LoadPlugin(const FilePath& path,
ScopedVector<PluginGroup>* plugin_groups, ScopedVector<PluginGroup>* plugin_groups,
WebPluginInfo* plugin_info) { WebPluginInfo* plugin_info) {
...@@ -382,6 +414,37 @@ bool PluginList::LoadPlugin(const FilePath& path, ...@@ -382,6 +414,37 @@ bool PluginList::LoadPlugin(const FilePath& path,
return true; return true;
} }
bool PluginList::LoadPluginIntoPluginList(
const FilePath& path,
std::vector<webkit::WebPluginInfo>* plugins,
WebPluginInfo* plugin_info) {
LOG_IF(ERROR, PluginList::DebugPluginLoading())
<< "Loading plugin " << path.value();
const PluginEntryPoints* entry_points;
if (!ReadPluginInfo(path, plugin_info, &entry_points))
return false;
if (!ShouldLoadPluginUsingPluginList(*plugin_info, plugins))
return false;
#if defined(OS_WIN) && !defined(NDEBUG)
if (path.BaseName().value() != L"npspy.dll") // Make an exception for NPSPY
#endif
{
for (size_t i = 0; i < plugin_info->mime_types.size(); ++i) {
// TODO: don't load global handlers for now.
// 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 == "*")
return false;
}
}
plugins->push_back(*plugin_info);
return true;
}
void PluginList::GetPluginPathsToLoad(std::vector<FilePath>* plugin_paths) { void PluginList::GetPluginPathsToLoad(std::vector<FilePath>* plugin_paths) {
// Don't want to hold the lock while loading new plugins, so we don't block // Don't want to hold the lock while loading new plugins, so we don't block
// other methods if they're called on other threads. // other methods if they're called on other threads.
...@@ -416,6 +479,7 @@ void PluginList::GetPluginPathsToLoad(std::vector<FilePath>* plugin_paths) { ...@@ -416,6 +479,7 @@ void PluginList::GetPluginPathsToLoad(std::vector<FilePath>* plugin_paths) {
#endif #endif
} }
// TODO(ibraaaa): DELETE. http://crbug.com/124396
const std::vector<PluginGroup*>& PluginList::GetHardcodedPluginGroups() const { const std::vector<PluginGroup*>& PluginList::GetHardcodedPluginGroups() const {
return hardcoded_plugin_groups_.get(); return hardcoded_plugin_groups_.get();
} }
...@@ -426,12 +490,16 @@ void PluginList::SetPlugins(const std::vector<webkit::WebPluginInfo>& plugins) { ...@@ -426,12 +490,16 @@ void PluginList::SetPlugins(const std::vector<webkit::WebPluginInfo>& plugins) {
DCHECK_NE(LOADING_STATE_REFRESHING, loading_state_); DCHECK_NE(LOADING_STATE_REFRESHING, loading_state_);
loading_state_ = LOADING_STATE_UP_TO_DATE; loading_state_ = LOADING_STATE_UP_TO_DATE;
// TODO(ibraaaa): DELETE
plugin_groups_.clear(); plugin_groups_.clear();
for (std::vector<webkit::WebPluginInfo>::const_iterator it = plugins.begin(); for (std::vector<webkit::WebPluginInfo>::const_iterator it = plugins.begin();
it != plugins.end(); it != plugins.end();
++it) { ++it) {
AddToPluginGroups(*it, &plugin_groups_); AddToPluginGroups(*it, &plugin_groups_);
} } // END OF DELETE
plugins_list_.clear();
plugins_list_.insert(plugins_list_.end(), plugins.begin(), plugins.end());
} }
void PluginList::set_will_load_plugins_callback(const base::Closure& callback) { void PluginList::set_will_load_plugins_callback(const base::Closure& callback) {
...@@ -442,21 +510,14 @@ void PluginList::set_will_load_plugins_callback(const base::Closure& callback) { ...@@ -442,21 +510,14 @@ void PluginList::set_will_load_plugins_callback(const base::Closure& callback) {
void PluginList::GetPlugins(std::vector<WebPluginInfo>* plugins) { void PluginList::GetPlugins(std::vector<WebPluginInfo>* plugins) {
LoadPlugins(); LoadPlugins();
base::AutoLock lock(lock_); base::AutoLock lock(lock_);
for (size_t i = 0; i < plugin_groups_.size(); ++i) { plugins->insert(plugins->end(), plugins_list_.begin(), plugins_list_.end());
const std::vector<webkit::WebPluginInfo>& gr_plugins =
plugin_groups_[i]->web_plugin_infos();
plugins->insert(plugins->end(), gr_plugins.begin(), gr_plugins.end());
}
} }
bool PluginList::GetPluginsNoRefresh( bool PluginList::GetPluginsNoRefresh(
std::vector<webkit::WebPluginInfo>* plugins) { std::vector<webkit::WebPluginInfo>* plugins) {
base::AutoLock lock(lock_); base::AutoLock lock(lock_);
for (size_t i = 0; i < plugin_groups_.size(); ++i) { plugins->insert(plugins->end(), plugins_list_.begin(), plugins_list_.end());
const std::vector<webkit::WebPluginInfo>& gr_plugins =
plugin_groups_[i]->web_plugin_infos();
plugins->insert(plugins->end(), gr_plugins.begin(), gr_plugins.end());
}
return loading_state_ == LOADING_STATE_UP_TO_DATE; return loading_state_ == LOADING_STATE_UP_TO_DATE;
} }
...@@ -482,17 +543,13 @@ void PluginList::GetPluginInfoArray( ...@@ -482,17 +543,13 @@ void PluginList::GetPluginInfoArray(
std::set<FilePath> visited_plugins; std::set<FilePath> visited_plugins;
// Add in plugins by mime type. // Add in plugins by mime type.
for (size_t i = 0; i < plugin_groups_.size(); ++i) { for (size_t i = 0; i < plugins_list_.size(); ++i) {
const std::vector<webkit::WebPluginInfo>& plugins = if (SupportsType(plugins_list_[i], mime_type, allow_wildcard)) {
plugin_groups_[i]->web_plugin_infos(); FilePath path = plugins_list_[i].path;
for (size_t i = 0; i < plugins.size(); ++i) { if (visited_plugins.insert(path).second) {
if (SupportsType(plugins[i], mime_type, allow_wildcard)) { info->push_back(plugins_list_[i]);
FilePath path = plugins[i].path; if (actual_mime_types)
if (visited_plugins.insert(path).second) { actual_mime_types->push_back(mime_type);
info->push_back(plugins[i]);
if (actual_mime_types)
actual_mime_types->push_back(mime_type);
}
} }
} }
} }
...@@ -503,24 +560,21 @@ void PluginList::GetPluginInfoArray( ...@@ -503,24 +560,21 @@ void PluginList::GetPluginInfoArray(
if (last_dot != std::string::npos) { if (last_dot != std::string::npos) {
std::string extension = StringToLowerASCII(std::string(path, last_dot+1)); std::string extension = StringToLowerASCII(std::string(path, last_dot+1));
std::string actual_mime_type; std::string actual_mime_type;
for (size_t i = 0; i < plugin_groups_.size(); ++i) { for (size_t i = 0; i < plugins_list_.size(); ++i) {
const std::vector<webkit::WebPluginInfo>& plugins = if (SupportsExtension(plugins_list_[i], extension, &actual_mime_type)) {
plugin_groups_[i]->web_plugin_infos(); FilePath path = plugins_list_[i].path;
for (size_t i = 0; i < plugins.size(); ++i) { if (visited_plugins.insert(path).second &&
if (SupportsExtension(plugins[i], extension, &actual_mime_type)) { AllowMimeTypeMismatch(mime_type, actual_mime_type)) {
FilePath path = plugins[i].path; info->push_back(plugins_list_[i]);
if (visited_plugins.insert(path).second && if (actual_mime_types)
AllowMimeTypeMismatch(mime_type, actual_mime_type)) { actual_mime_types->push_back(actual_mime_type);
info->push_back(plugins[i]);
if (actual_mime_types)
actual_mime_types->push_back(actual_mime_type);
}
} }
} }
} }
} }
} }
// TODO(ibraaaa): DELETE. http://crbug.com/124396
void PluginList::GetPluginGroups( void PluginList::GetPluginGroups(
bool load_if_necessary, bool load_if_necessary,
std::vector<PluginGroup>* plugin_groups) { std::vector<PluginGroup>* plugin_groups) {
...@@ -536,6 +590,7 @@ void PluginList::GetPluginGroups( ...@@ -536,6 +590,7 @@ void PluginList::GetPluginGroups(
} }
} }
// TODO(ibraaaa): DELETE. http://crbug.com/124396
PluginGroup* PluginList::GetPluginGroup( PluginGroup* PluginList::GetPluginGroup(
const webkit::WebPluginInfo& web_plugin_info) { const webkit::WebPluginInfo& web_plugin_info) {
base::AutoLock lock(lock_); base::AutoLock lock(lock_);
...@@ -553,6 +608,7 @@ PluginGroup* PluginList::GetPluginGroup( ...@@ -553,6 +608,7 @@ PluginGroup* PluginList::GetPluginGroup(
return group; return group;
} }
// TODO(ibraaaa): DELETE. http://crbug.com/124396
string16 PluginList::GetPluginGroupName(const std::string& identifier) { string16 PluginList::GetPluginGroupName(const std::string& identifier) {
for (size_t i = 0; i < plugin_groups_.size(); ++i) { for (size_t i = 0; i < plugin_groups_.size(); ++i) {
if (plugin_groups_[i]->identifier() == identifier) if (plugin_groups_[i]->identifier() == identifier)
...@@ -561,6 +617,7 @@ string16 PluginList::GetPluginGroupName(const std::string& identifier) { ...@@ -561,6 +617,7 @@ string16 PluginList::GetPluginGroupName(const std::string& identifier) {
return string16(); return string16();
} }
// TODO(ibraaaa): DELETE. http://crbug.com/124396
void PluginList::AddHardcodedPluginGroups( void PluginList::AddHardcodedPluginGroups(
const PluginGroupDefinition* group_definitions, const PluginGroupDefinition* group_definitions,
size_t num_group_definitions) { size_t num_group_definitions) {
...@@ -570,6 +627,7 @@ void PluginList::AddHardcodedPluginGroups( ...@@ -570,6 +627,7 @@ void PluginList::AddHardcodedPluginGroups(
} }
} }
// TODO(ibraaaa): DELETE. http://crbug.com/124396
PluginGroup* PluginList::AddToPluginGroups( PluginGroup* PluginList::AddToPluginGroups(
const webkit::WebPluginInfo& web_plugin_info, const webkit::WebPluginInfo& web_plugin_info,
ScopedVector<PluginGroup>* plugin_groups) { ScopedVector<PluginGroup>* plugin_groups) {
...@@ -635,6 +693,21 @@ bool PluginList::SupportsExtension(const webkit::WebPluginInfo& plugin, ...@@ -635,6 +693,21 @@ bool PluginList::SupportsExtension(const webkit::WebPluginInfo& plugin,
return false; return false;
} }
/*static*/
bool PluginList::RemovePlugin(const FilePath& filename,
std::vector<webkit::WebPluginInfo>* plugins) {
bool did_remove = false;
for (size_t i = 0; i < plugins->size();) {
if ((*plugins)[i].path == filename) {
plugins->erase(plugins->begin() + i);
did_remove = true;
} else {
i++;
}
}
return did_remove;
}
PluginList::~PluginList() { PluginList::~PluginList() {
} }
......
...@@ -148,32 +148,43 @@ class WEBKIT_PLUGINS_EXPORT PluginList { ...@@ -148,32 +148,43 @@ class WEBKIT_PLUGINS_EXPORT PluginList {
std::vector<webkit::WebPluginInfo>* info, std::vector<webkit::WebPluginInfo>* info,
std::vector<std::string>* actual_mime_types); std::vector<std::string>* actual_mime_types);
// TODO(ibraaaa): DELETE. http://crbug.com/124396
// Populates the given vector with all available plugin groups. If // Populates the given vector with all available plugin groups. If
// |load_if_necessary| is true, this will potentially load the plugin list // |load_if_necessary| is true, this will potentially load the plugin list
// synchronously. // synchronously.
void GetPluginGroups(bool load_if_necessary, void GetPluginGroups(bool load_if_necessary,
std::vector<PluginGroup>* plugin_groups); std::vector<PluginGroup>* plugin_groups);
// TODO(ibraaaa): DELETE. http://crbug.com/124396
// Returns a copy of the PluginGroup corresponding to the given WebPluginInfo. // Returns a copy of the PluginGroup corresponding to the given WebPluginInfo.
// The caller takes ownership of the returned PluginGroup. // The caller takes ownership of the returned PluginGroup.
PluginGroup* GetPluginGroup(const webkit::WebPluginInfo& web_plugin_info); PluginGroup* GetPluginGroup(const webkit::WebPluginInfo& web_plugin_info);
// TODO(ibraaaa): DELETE. http://crbug.com/124396
// Returns the name of the PluginGroup with the given identifier. // Returns the name of the PluginGroup with the given identifier.
// If no such group exists, an empty string is returned. // If no such group exists, an empty string is returned.
string16 GetPluginGroupName(const std::string& identifier); string16 GetPluginGroupName(const std::string& identifier);
// TODO(ibraaaa): DELETE. http://crbug.com/124396
// Load a specific plugin with full path. Return true iff loading the plug-in // Load a specific plugin with full path. Return true iff loading the plug-in
// was successful. // was successful.
bool LoadPlugin(const FilePath& filename, bool LoadPlugin(const FilePath& filename,
ScopedVector<PluginGroup>* plugin_groups, ScopedVector<PluginGroup>* plugin_groups,
webkit::WebPluginInfo* plugin_info); webkit::WebPluginInfo* plugin_info);
// Load a specific plugin with full path. Return true iff loading the plug-in
// was successful.
bool LoadPluginIntoPluginList(const FilePath& filename,
std::vector<webkit::WebPluginInfo>* plugins,
webkit::WebPluginInfo* plugin_info);
// 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.
// Computes a list of all plugins to potentially load from all sources. // Computes a list of all plugins to potentially load from all sources.
void GetPluginPathsToLoad(std::vector<FilePath>* plugin_paths); void GetPluginPathsToLoad(std::vector<FilePath>* plugin_paths);
// TODO(ibraaaa): DELETE. http://crbug.com/124396
// Returns the list of hardcoded plug-in groups for testing. // Returns the list of hardcoded plug-in groups for testing.
const std::vector<PluginGroup*>& GetHardcodedPluginGroups() const; const std::vector<PluginGroup*>& GetHardcodedPluginGroups() const;
...@@ -185,10 +196,12 @@ class WEBKIT_PLUGINS_EXPORT PluginList { ...@@ -185,10 +196,12 @@ class WEBKIT_PLUGINS_EXPORT PluginList {
virtual ~PluginList(); virtual ~PluginList();
protected: protected:
// TODO(ibraaaa): DELETE and add a different one. http://crbug.com/124396
// This constructor is used in unit tests to override the platform-dependent // This constructor is used in unit tests to override the platform-dependent
// real-world plugin group definitions with custom ones. // real-world plugin group definitions with custom ones.
PluginList(const PluginGroupDefinition* definitions, size_t num_definitions); PluginList(const PluginGroupDefinition* definitions, size_t num_definitions);
// TODO(ibraaaa): DELETE. http://crbug.com/124396
// Adds the given WebPluginInfo to its corresponding group, creating it if // Adds the given WebPluginInfo to its corresponding group, creating it if
// necessary, and returns the group. // necessary, and returns the group.
PluginGroup* AddToPluginGroups(const webkit::WebPluginInfo& web_plugin_info, PluginGroup* AddToPluginGroups(const webkit::WebPluginInfo& web_plugin_info,
...@@ -213,11 +226,13 @@ class WEBKIT_PLUGINS_EXPORT PluginList { ...@@ -213,11 +226,13 @@ class WEBKIT_PLUGINS_EXPORT PluginList {
// Constructors are private for singletons. // Constructors are private for singletons.
PluginList(); PluginList();
// TODO(ibraaaa): DELETE. http://crbug.com/124396
// Creates PluginGroups for the hardcoded group definitions, and stores them // Creates PluginGroups for the hardcoded group definitions, and stores them
// in |hardcoded_plugin_groups_|. // in |hardcoded_plugin_groups_|.
void AddHardcodedPluginGroups(const PluginGroupDefinition* group_definitions, void AddHardcodedPluginGroups(const PluginGroupDefinition* group_definitions,
size_t num_group_definitions); size_t num_group_definitions);
// TODO(ibraaaa): DELETE. http://crbug.com/124396
// Creates a new PluginGroup either from a hardcoded group definition, or from // Creates a new PluginGroup either from a hardcoded group definition, or from
// the plug-in information. // the plug-in information.
// Caller takes ownership of the returned PluginGroup. // Caller takes ownership of the returned PluginGroup.
...@@ -228,6 +243,11 @@ class WEBKIT_PLUGINS_EXPORT PluginList { ...@@ -228,6 +243,11 @@ class WEBKIT_PLUGINS_EXPORT PluginList {
// test classes can mock these out. // test classes can mock these out.
virtual void LoadPluginsInternal(ScopedVector<PluginGroup>* plugin_groups); virtual void LoadPluginsInternal(ScopedVector<PluginGroup>* plugin_groups);
// Implements all IO dependent operations of the LoadPlugins method so that
// test classes can mock these out.
virtual void LoadPluginsIntoPluginListInternal(
std::vector<webkit::WebPluginInfo>* plugins);
// Load all plugins from the default plugins directory. // Load all plugins from the default plugins directory.
void LoadPlugins(); void LoadPlugins();
...@@ -235,12 +255,20 @@ class WEBKIT_PLUGINS_EXPORT PluginList { ...@@ -235,12 +255,20 @@ class WEBKIT_PLUGINS_EXPORT PluginList {
// load in that directory. // load in that directory.
void GetPluginsInDir(const FilePath& path, std::vector<FilePath>* plugins); void GetPluginsInDir(const FilePath& path, std::vector<FilePath>* plugins);
// TODO(ibraaaa): DELETE. http://crbug.com/124396
// Returns true if we should load the given plugin, or false otherwise. // Returns true if we should load the given plugin, or false otherwise.
// |plugins| is the list of plugins we have crawled in the current plugin // |plugins| is the list of plugins we have crawled in the current plugin
// loading run. // loading run.
bool ShouldLoadPlugin(const webkit::WebPluginInfo& info, bool ShouldLoadPlugin(const webkit::WebPluginInfo& info,
ScopedVector<PluginGroup>* plugins); ScopedVector<PluginGroup>* plugins);
// Returns true if we should load the given plugin, or false otherwise.
// |plugins| is the list of plugins we have crawled in the current plugin
// loading run.
bool ShouldLoadPluginUsingPluginList(
const webkit::WebPluginInfo& info,
std::vector<webkit::WebPluginInfo>* plugins);
// Returns true if the plugin supports |mime_type|. |mime_type| should be all // Returns true if the plugin supports |mime_type|. |mime_type| should be all
// lower case. // lower case.
bool SupportsType(const webkit::WebPluginInfo& plugin, bool SupportsType(const webkit::WebPluginInfo& plugin,
...@@ -255,6 +283,10 @@ class WEBKIT_PLUGINS_EXPORT PluginList { ...@@ -255,6 +283,10 @@ class WEBKIT_PLUGINS_EXPORT PluginList {
const std::string& extension, const std::string& extension,
std::string* actual_mime_type); std::string* actual_mime_type);
// Removes a plug-in from |plugins_list_| by its path.
static bool RemovePlugin(const FilePath& filename,
std::vector<webkit::WebPluginInfo>* plugins);
// //
// Platform functions // Platform functions
// //
...@@ -293,6 +325,7 @@ class WEBKIT_PLUGINS_EXPORT PluginList { ...@@ -293,6 +325,7 @@ class WEBKIT_PLUGINS_EXPORT PluginList {
// Holds information about internal plugins. // Holds information about internal plugins.
std::vector<InternalPlugin> internal_plugins_; std::vector<InternalPlugin> internal_plugins_;
// TODO(ibraaaa): DELETE. http://crbug.com/124396
// Holds the currently available plugin groups. // Holds the currently available plugin groups.
ScopedVector<PluginGroup> plugin_groups_; ScopedVector<PluginGroup> plugin_groups_;
...@@ -300,6 +333,9 @@ class WEBKIT_PLUGINS_EXPORT PluginList { ...@@ -300,6 +333,9 @@ class WEBKIT_PLUGINS_EXPORT PluginList {
// This should only be modified during construction of the PluginList. // This should only be modified during construction of the PluginList.
ScopedVector<PluginGroup> hardcoded_plugin_groups_; ScopedVector<PluginGroup> hardcoded_plugin_groups_;
// A list holding all plug-ins.
std::vector<webkit::WebPluginInfo> plugins_list_;
// Callback that is invoked whenever the PluginList will reload the plugins. // Callback that is invoked whenever the PluginList will reload the plugins.
base::Closure will_load_plugins_callback_; base::Closure will_load_plugins_callback_;
......
...@@ -87,10 +87,17 @@ void PluginList::GetPluginsInDir( ...@@ -87,10 +87,17 @@ void PluginList::GetPluginsInDir(
} }
} }
// TODO(ibraaaa): DELETE. http://crbug.com/124396
bool PluginList::ShouldLoadPlugin(const WebPluginInfo& info, bool PluginList::ShouldLoadPlugin(const WebPluginInfo& info,
ScopedVector<PluginGroup>* plugin_groups) { ScopedVector<PluginGroup>* plugin_groups) {
return !IsBlacklistedPlugin(info); return !IsBlacklistedPlugin(info);
} }
bool PluginList::ShouldLoadPluginUsingPluginList(
const WebPluginInfo& info,
std::vector<webkit::WebPluginInfo>* plugins) {
return !IsBlacklistedPlugin(info);
}
} // namespace npapi } // namespace npapi
} // namespace webkit } // namespace webkit
...@@ -266,6 +266,7 @@ void PluginList::GetPluginsInDir( ...@@ -266,6 +266,7 @@ void PluginList::GetPluginsInDir(
} }
} }
// TODO(ibraaaa): DELETE. http://crbug.com/124396
bool PluginList::ShouldLoadPlugin(const WebPluginInfo& info, bool PluginList::ShouldLoadPlugin(const WebPluginInfo& info,
ScopedVector<PluginGroup>* plugin_groups) { ScopedVector<PluginGroup>* plugin_groups) {
LOG_IF(ERROR, PluginList::DebugPluginLoading()) LOG_IF(ERROR, PluginList::DebugPluginLoading())
...@@ -300,5 +301,35 @@ bool PluginList::ShouldLoadPlugin(const WebPluginInfo& info, ...@@ -300,5 +301,35 @@ bool PluginList::ShouldLoadPlugin(const WebPluginInfo& info,
return true; return true;
} }
bool PluginList::ShouldLoadPluginUsingPluginList(
const WebPluginInfo& info, std::vector<webkit::WebPluginInfo>* plugins) {
LOG_IF(ERROR, PluginList::DebugPluginLoading())
<< "Considering " << info.path.value() << " (" << info.name << ")";
if (IsUndesirablePlugin(info)) {
LOG_IF(ERROR, PluginList::DebugPluginLoading())
<< info.path.value() << " is undesirable.";
// See if we have a better version of this plugin.
for (size_t j = 0; j < plugins->size(); ++j) {
if ((*plugins)[j].name == info.name &&
!IsUndesirablePlugin((*plugins)[j])) {
// Skip the current undesirable one so we can use the better one
// we just found.
LOG_IF(ERROR, PluginList::DebugPluginLoading())
<< "Skipping " << info.path.value() << ", preferring "
<< (*plugins)[j].path.value();
return false;
}
}
}
// TODO(evanm): prefer the newest version of flash, etc. here?
VLOG_IF(1, PluginList::DebugPluginLoading()) << "Using " << info.path.value();
return true;
}
} // namespace npapi } // namespace npapi
} // namespace webkit } // namespace webkit
...@@ -335,8 +335,10 @@ bool IsNewerVersion(const std::wstring& a, const std::wstring& b) { ...@@ -335,8 +335,10 @@ bool IsNewerVersion(const std::wstring& a, const std::wstring& b) {
return false; return false;
} }
bool PluginList::ShouldLoadPlugin(const webkit::WebPluginInfo& info, // TODO(ibraaaa): DELETE. http://crbug.com/124396
ScopedVector<PluginGroup>* plugin_groups) { bool PluginList::ShouldLoadPlugin(
const webkit::WebPluginInfo& info,
ScopedVector<PluginGroup>* plugin_groups) {
// Version check // Version check
for (size_t i = 0; i < plugin_groups->size(); ++i) { for (size_t i = 0; i < plugin_groups->size(); ++i) {
...@@ -442,5 +444,103 @@ bool PluginList::ShouldLoadPlugin(const webkit::WebPluginInfo& info, ...@@ -442,5 +444,103 @@ bool PluginList::ShouldLoadPlugin(const webkit::WebPluginInfo& info,
return load_plugin; return load_plugin;
} }
bool PluginList::ShouldLoadPluginUsingPluginList(
const webkit::WebPluginInfo& info,
std::vector<webkit::WebPluginInfo>* plugins) {
// Version check
for (size_t j = 0; j < plugins->size(); ++j) {
FilePath::StringType plugin1 =
StringToLowerASCII((*plugins)[j].path.BaseName().value());
FilePath::StringType plugin2 =
StringToLowerASCII(info.path.BaseName().value());
if ((plugin1 == plugin2 && HaveSharedMimeType((*plugins)[j], info)) ||
(plugin1 == kJavaDeploy1 && plugin2 == kJavaDeploy2) ||
(plugin1 == kJavaDeploy2 && plugin2 == kJavaDeploy1)) {
if (!IsNewerVersion((*plugins)[j].version, info.version))
return false; // We have loaded a plugin whose version is newer.
PluginList::RemovePlugin((*plugins)[j].path, plugins);
break;
}
}
// Troublemakers
FilePath::StringType filename =
StringToLowerASCII(info.path.BaseName().value());
// Depends on XPCOM.
if (filename == kMozillaActiveXPlugin)
return false;
// Disable the Yahoo Application State plugin as it crashes the plugin
// process on return from NPObjectStub::OnInvoke. Please refer to
// http://b/issue?id=1372124 for more information.
if (filename == kYahooApplicationStatePlugin)
return false;
// Disable the WangWang protocol handler plugin (npww.dll) as it crashes
// chrome during shutdown. Firefox also disables this plugin.
// Please refer to http://code.google.com/p/chromium/issues/detail?id=3953
// for more information.
if (filename == kWanWangProtocolHandlerPlugin)
return false;
// We only work with newer versions of the Java plugin which use NPAPI only
// and don't depend on XPCOM.
if (filename == kJavaPlugin1 || filename == kJavaPlugin2) {
std::vector<FilePath::StringType> ver;
base::SplitString(info.version, '.', &ver);
int major, minor, update;
if (ver.size() == 4 &&
base::StringToInt(ver[0], &major) &&
base::StringToInt(ver[1], &minor) &&
base::StringToInt(ver[2], &update)) {
if (major == 6 && minor == 0 && update < 120)
return false; // Java SE6 Update 11 or older.
}
}
if (base::win::IsMetroProcess()) {
// In metro mode we only allow pepper plugins.
if (info.type == WebPluginInfo::PLUGIN_TYPE_NPAPI)
return false;
}
// Special WMP handling
// If both the new and old WMP plugins exist, only load the new one.
if (filename == kNewWMPPlugin) {
if (dont_load_new_wmp_)
return false;
for (size_t j = 0; j < plugins->size(); ++j) {
if ((*plugins)[j].path.BaseName().value() == kOldWMPPlugin) {
PluginList::RemovePlugin((*plugins)[j].path, plugins);
break;
}
}
} else if (filename == kOldWMPPlugin) {
for (size_t j = 0; j < plugins->size(); ++j) {
if ((*plugins)[j].path.BaseName().value() == kNewWMPPlugin)
return false;
}
}
HMODULE plugin_dll = NULL;
bool load_plugin = true;
// The plugin list could contain a 64 bit plugin which we cannot load.
for (size_t i = 0; i < internal_plugins_.size(); ++i) {
if (info.path == internal_plugins_[i].info.path)
continue;
if (file_util::PathExists(info.path) && (!IsValid32BitImage(info.path)))
load_plugin = false;
break;
}
return load_plugin;
}
} // namespace npapi } // namespace npapi
} // namespace webkit } // namespace webkit
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