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

Side by Side Diff: webkit/glue/plugins/webplugininfo.cc

Issue 5699005: Policy: Re-enabled plugin still disabled (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More fixes and cleanups. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/glue/plugins/webplugininfo.h" 5 #include "webkit/glue/plugins/webplugininfo.h"
6 6
7 #include "base/logging.h"
8 #include "net/base/mime_util.h"
9
7 WebPluginMimeType::WebPluginMimeType() {} 10 WebPluginMimeType::WebPluginMimeType() {}
8 11
9 WebPluginMimeType::~WebPluginMimeType() {} 12 WebPluginMimeType::~WebPluginMimeType() {}
10 13
11 WebPluginInfo::WebPluginInfo() : enabled(false) {} 14 WebPluginInfo::WebPluginInfo()
15 : enabled(false),
16 reason(USER),
17 priority(0) {
18 }
12 19
13 WebPluginInfo::WebPluginInfo(const WebPluginInfo& rhs) 20 WebPluginInfo::WebPluginInfo(const WebPluginInfo& rhs)
14 : name(rhs.name), 21 : name(rhs.name),
15 path(rhs.path), 22 path(rhs.path),
16 version(rhs.version), 23 version(rhs.version),
17 desc(rhs.desc), 24 desc(rhs.desc),
18 mime_types(rhs.mime_types), 25 mime_types(rhs.mime_types),
19 enabled(rhs.enabled) { 26 enabled(rhs.enabled),
27 reason(rhs.reason),
28 priority(rhs.priority) {
20 } 29 }
21 30
22 WebPluginInfo::~WebPluginInfo() {} 31 WebPluginInfo::~WebPluginInfo() {}
23 32
24 WebPluginInfo& WebPluginInfo::operator=(const WebPluginInfo& rhs) { 33 WebPluginInfo& WebPluginInfo::operator=(const WebPluginInfo& rhs) {
25 name = rhs.name; 34 name = rhs.name;
26 path = rhs.path; 35 path = rhs.path;
27 version = rhs.version; 36 version = rhs.version;
28 desc = rhs.desc; 37 desc = rhs.desc;
29 mime_types = rhs.mime_types; 38 mime_types = rhs.mime_types;
30 enabled = rhs.enabled; 39 enabled = rhs.enabled;
40 reason = rhs.reason;
41 priority = rhs.priority;
31 return *this; 42 return *this;
32 } 43 }
33 44
34 WebPluginInfo::WebPluginInfo(const string16& fake_name, 45 WebPluginInfo::WebPluginInfo(const string16& fake_name,
46 const FilePath& fake_path,
35 const string16& fake_version, 47 const string16& fake_version,
36 const string16& fake_desc) 48 const string16& fake_desc)
37 : name(fake_name), 49 : name(fake_name),
38 path(), 50 path(fake_path),
39 version(fake_version), 51 version(fake_version),
40 desc(fake_desc), 52 desc(fake_desc),
41 mime_types(), 53 mime_types(),
42 enabled(true) { 54 enabled(true),
55 reason(USER),
56 priority(0) {
43 } 57 }
44 58
59 bool WebPluginInfo::Enable(WebPluginInfo::Reason new_reason) {
60 // If already enabled just upgrade the reason.
61 if (enabled) {
62 reason |= new_reason;
63 return true;
64 } else {
65 // Only changeable if not managed.
66 if (IsManaged(reason))
67 return false;
68 enabled = true;
69 reason = new_reason;
70 }
71 return true;
72 }
73
74 bool WebPluginInfo::Disable(WebPluginInfo::Reason new_reason) {
75 // If already disabled just upgrade the reason.
76 if (!enabled) {
77 reason |= new_reason;
78 return true;
79 } else {
80 // Only changeable if not managed.
81 if (IsManaged(reason))
82 return false;
83 enabled = false;
84 reason = new_reason;
85 }
86 return true;
87 }
88
89 bool WebPluginInfo::SupportsType(const std::string& mime_type,
90 bool allow_wildcard) const {
91 // Webkit will ask for a plugin to handle empty mime types.
92 if (mime_type.empty())
93 return false;
94
95 for (size_t i = 0; i < mime_types.size(); ++i) {
96 const WebPluginMimeType& mime_info = mime_types[i];
97 if (net::MatchesMimeType(mime_info.mime_type, mime_type)) {
98 if (!allow_wildcard && mime_info.mime_type == "*")
99 continue;
100 return true;
101 }
102 }
103 return false;
104 }
105
106 bool WebPluginInfo::SupportsExtension(const std::string& extension,
107 std::string* actual_mime_type) const {
108 for (size_t i = 0; i < mime_types.size(); ++i) {
109 const WebPluginMimeType& mime_type = mime_types[i];
110 for (size_t j = 0; j < mime_type.file_extensions.size(); ++j) {
111 if (mime_type.file_extensions[j] == extension) {
112 if (actual_mime_type)
113 *actual_mime_type = mime_type.mime_type;
114 return true;
115 }
116 }
117 }
118
119 return false;
120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698