Commit 41da8785 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Modernize for-loops in PluginList.

Change-Id: I0d096d161eb4d98fce431eb9db8cb1df58ddd2c0
Reviewed-on: https://chromium-review.googlesource.com/c/1457019
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#629812}
parent 1385d670
...@@ -37,12 +37,10 @@ bool SupportsType(const WebPluginInfo& plugin, ...@@ -37,12 +37,10 @@ bool SupportsType(const WebPluginInfo& plugin,
if (mime_type.empty()) if (mime_type.empty())
return false; return false;
for (size_t i = 0; i < plugin.mime_types.size(); ++i) { for (const WebPluginMimeType& mime_info : plugin.mime_types) {
const WebPluginMimeType& mime_info = plugin.mime_types[i];
if (net::MatchesMimeType(mime_info.mime_type, mime_type)) { if (net::MatchesMimeType(mime_info.mime_type, mime_type)) {
if (!allow_wildcard && mime_info.mime_type == "*") if (allow_wildcard || mime_info.mime_type != "*")
continue; return true;
return true;
} }
} }
return false; return false;
...@@ -55,10 +53,9 @@ bool SupportsType(const WebPluginInfo& plugin, ...@@ -55,10 +53,9 @@ bool SupportsType(const WebPluginInfo& plugin,
bool SupportsExtension(const WebPluginInfo& plugin, bool SupportsExtension(const WebPluginInfo& plugin,
const std::string& extension, const std::string& extension,
std::string* actual_mime_type) { std::string* actual_mime_type) {
for (size_t i = 0; i < plugin.mime_types.size(); ++i) { for (const WebPluginMimeType& mime_type : plugin.mime_types) {
const WebPluginMimeType& mime_type = plugin.mime_types[i]; for (const std::string& file_extension : mime_type.file_extensions) {
for (size_t j = 0; j < mime_type.file_extensions.size(); ++j) { if (file_extension == extension) {
if (mime_type.file_extensions[j] == extension) {
*actual_mime_type = mime_type.mime_type; *actual_mime_type = mime_type.mime_type;
return true; return true;
} }
...@@ -111,10 +108,8 @@ void PluginList::GetInternalPlugins( ...@@ -111,10 +108,8 @@ void PluginList::GetInternalPlugins(
std::vector<WebPluginInfo>* internal_plugins) { std::vector<WebPluginInfo>* internal_plugins) {
base::AutoLock lock(lock_); base::AutoLock lock(lock_);
for (std::vector<WebPluginInfo>::iterator it = internal_plugins_.begin(); for (const auto& plugin : internal_plugins_)
it != internal_plugins_.end(); ++it) { internal_plugins->push_back(plugin);
internal_plugins->push_back(*it);
}
} }
bool PluginList::ReadPluginInfo(const base::FilePath& filename, bool PluginList::ReadPluginInfo(const base::FilePath& filename,
...@@ -156,10 +151,9 @@ void PluginList::LoadPlugins() { ...@@ -156,10 +151,9 @@ void PluginList::LoadPlugins() {
std::vector<base::FilePath> plugin_paths; std::vector<base::FilePath> plugin_paths;
GetPluginPathsToLoad(&plugin_paths); GetPluginPathsToLoad(&plugin_paths);
for (std::vector<base::FilePath>::const_iterator it = plugin_paths.begin(); for (const base::FilePath& path : plugin_paths) {
it != plugin_paths.end(); ++it) {
WebPluginInfo plugin_info; WebPluginInfo plugin_info;
LoadPluginIntoPluginList(*it, &new_plugins, &plugin_info); LoadPluginIntoPluginList(path, &new_plugins, &plugin_info);
} }
SetPlugins(new_plugins); SetPlugins(new_plugins);
...@@ -172,12 +166,11 @@ bool PluginList::LoadPluginIntoPluginList(const base::FilePath& path, ...@@ -172,12 +166,11 @@ bool PluginList::LoadPluginIntoPluginList(const base::FilePath& path,
return false; return false;
// TODO(piman): Do we still need this after NPAPI removal? // TODO(piman): Do we still need this after NPAPI removal?
for (size_t i = 0; i < plugin_info->mime_types.size(); ++i) { for (const content::WebPluginMimeType& mime_type : plugin_info->mime_types) {
// TODO: don't load global handlers for now. // TODO: don't load global handlers for now.
// WebKit hands to the Plugin before it tries // WebKit hands to the Plugin before it tries
// to handle mimeTypes on its own. // to handle mimeTypes on its own.
const std::string& mime_type = plugin_info->mime_types[i].mime_type; if (mime_type.mime_type == "*")
if (mime_type == "*")
return false; return false;
} }
plugins->push_back(*plugin_info); plugins->push_back(*plugin_info);
...@@ -194,8 +187,7 @@ void PluginList::GetPluginPathsToLoad( ...@@ -194,8 +187,7 @@ void PluginList::GetPluginPathsToLoad(
extra_plugin_paths = extra_plugin_paths_; extra_plugin_paths = extra_plugin_paths_;
} }
for (size_t i = 0; i < extra_plugin_paths.size(); ++i) { for (const base::FilePath& path : extra_plugin_paths) {
const base::FilePath& path = extra_plugin_paths[i];
if (base::ContainsValue(*plugin_paths, path)) if (base::ContainsValue(*plugin_paths, path))
continue; continue;
plugin_paths->push_back(path); plugin_paths->push_back(path);
...@@ -254,11 +246,11 @@ void PluginList::GetPluginInfoArray( ...@@ -254,11 +246,11 @@ void PluginList::GetPluginInfoArray(
std::set<base::FilePath> visited_plugins; std::set<base::FilePath> visited_plugins;
// Add in plugins by mime type. // Add in plugins by mime type.
for (size_t i = 0; i < plugins_list_.size(); ++i) { for (const WebPluginInfo& plugin : plugins_list_) {
if (SupportsType(plugins_list_[i], mime_type, allow_wildcard)) { if (SupportsType(plugin, mime_type, allow_wildcard)) {
base::FilePath path = plugins_list_[i].path; const base::FilePath& path = plugin.path;
if (visited_plugins.insert(path).second) { if (visited_plugins.insert(path).second) {
info->push_back(plugins_list_[i]); info->push_back(plugin);
if (actual_mime_types) if (actual_mime_types)
actual_mime_types->push_back(mime_type); actual_mime_types->push_back(mime_type);
} }
...@@ -273,18 +265,19 @@ void PluginList::GetPluginInfoArray( ...@@ -273,18 +265,19 @@ void PluginList::GetPluginInfoArray(
// as when the user doesn't have the Flash plugin enabled. // as when the user doesn't have the Flash plugin enabled.
std::string path = url.path(); std::string path = url.path();
std::string::size_type last_dot = path.rfind('.'); std::string::size_type last_dot = path.rfind('.');
if (last_dot != std::string::npos && mime_type.empty()) { if (last_dot == std::string::npos || !mime_type.empty())
std::string extension = return;
base::ToLowerASCII(base::StringPiece(path).substr(last_dot + 1));
std::string actual_mime_type; std::string extension =
for (size_t i = 0; i < plugins_list_.size(); ++i) { base::ToLowerASCII(base::StringPiece(path).substr(last_dot + 1));
if (SupportsExtension(plugins_list_[i], extension, &actual_mime_type)) { std::string actual_mime_type;
base::FilePath plugin_path = plugins_list_[i].path; for (const WebPluginInfo& plugin : plugins_list_) {
if (visited_plugins.insert(plugin_path).second) { if (SupportsExtension(plugin, extension, &actual_mime_type)) {
info->push_back(plugins_list_[i]); base::FilePath plugin_path = plugin.path;
if (actual_mime_types) if (visited_plugins.insert(plugin_path).second) {
actual_mime_types->push_back(actual_mime_type); info->push_back(plugin);
} if (actual_mime_types)
actual_mime_types->push_back(actual_mime_type);
} }
} }
} }
...@@ -299,6 +292,6 @@ void PluginList::RemoveExtraPluginPathLocked( ...@@ -299,6 +292,6 @@ void PluginList::RemoveExtraPluginPathLocked(
extra_plugin_paths_.erase(it); extra_plugin_paths_.erase(it);
} }
PluginList::~PluginList() {} PluginList::~PluginList() = default;
} // namespace content } // namespace content
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