Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(600)

Unified Diff: webkit/plugins/npapi/webplugininfo.cc

Issue 5699005: Policy: Re-enabled plugin still disabled (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up WebPluginInfo and rebased on fixed PluginGroup::InitFrom. Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webkit/plugins/npapi/webplugininfo.cc
diff --git a/webkit/plugins/npapi/webplugininfo.cc b/webkit/plugins/npapi/webplugininfo.cc
index cd5a19f82d1d14f6473d605ee45d05ee2af63723..908a86c04dec7e7319f0ffeabe3ec67a514ab666 100644
--- a/webkit/plugins/npapi/webplugininfo.cc
+++ b/webkit/plugins/npapi/webplugininfo.cc
@@ -4,6 +4,9 @@
#include "webkit/plugins/npapi/webplugininfo.h"
+#include "base/logging.h"
+#include "net/base/mime_util.h"
+
namespace webkit {
namespace npapi {
@@ -11,7 +14,10 @@ WebPluginMimeType::WebPluginMimeType() {}
WebPluginMimeType::~WebPluginMimeType() {}
-WebPluginInfo::WebPluginInfo() : enabled(false) {}
+WebPluginInfo::WebPluginInfo()
+ : enabled(false),
+ reason(USER) {
+}
WebPluginInfo::WebPluginInfo(const WebPluginInfo& rhs)
: name(rhs.name),
@@ -19,7 +25,8 @@ WebPluginInfo::WebPluginInfo(const WebPluginInfo& rhs)
version(rhs.version),
desc(rhs.desc),
mime_types(rhs.mime_types),
- enabled(rhs.enabled) {
+ enabled(rhs.enabled),
+ reason(rhs.reason) {
}
WebPluginInfo::~WebPluginInfo() {}
@@ -31,6 +38,7 @@ WebPluginInfo& WebPluginInfo::operator=(const WebPluginInfo& rhs) {
desc = rhs.desc;
mime_types = rhs.mime_types;
enabled = rhs.enabled;
+ reason = rhs.reason;
return *this;
}
@@ -43,9 +51,90 @@ WebPluginInfo::WebPluginInfo(const string16& fake_name,
version(fake_version),
desc(fake_desc),
mime_types(),
- enabled(true) {
+ enabled(true),
+ reason(USER) {
+}
+
+/* static */
+bool WebPluginInfoUtils::Enable(WebPluginInfo* plugin,
+ WebPluginInfo::Reason new_reason) {
+ // If already enabled just upgrade the reason.
+ if (plugin->enabled) {
+ plugin->reason |= new_reason;
+ return true;
+ } else {
+ // Only changeable if not managed.
+ if (IsManaged(*plugin))
+ return false;
+ plugin->enabled = true;
+ plugin->reason = new_reason;
+ }
+ return true;
+}
+
+/* static */
+bool WebPluginInfoUtils::Disable(WebPluginInfo* plugin,
+ WebPluginInfo::Reason new_reason) {
+ // If already disabled just upgrade the reason.
+ if (!plugin->enabled) {
+ plugin->reason |= new_reason;
+ return true;
+ } else {
+ // Only changeable if not managed.
+ if (IsManaged(*plugin))
+ return false;
+ plugin->enabled = false;
+ plugin->reason = new_reason;
+ }
+ return true;
+}
+
+/* static */
+bool WebPluginInfoUtils::IsEnabled(const WebPluginInfo& plugin) {
+ return plugin.enabled;
+}
+
+/* static */
+bool WebPluginInfoUtils::IsManaged(const WebPluginInfo& plugin) {
+ return (plugin.reason & WebPluginInfo::MANAGED) != 0;
+}
+
+/* static */
+bool WebPluginInfoUtils::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;
+}
+
+/* static */
+bool WebPluginInfoUtils::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;
}
} // namespace npapi
} // namespace webkit
-

Powered by Google App Engine
This is Rietveld 408576698