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

Side by Side Diff: chrome/browser/ui/webui/plugins/plugins_handler.cc

Issue 1576183003: chrome://plugins Mojo-ification part 2/2, populating the page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@plugins_mojo1
Patch Set: Rebasing, removing call to AddMojoResources() Created 4 years, 11 months 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/ui/webui/plugins/plugins_handler.h" 5 #include "chrome/browser/ui/webui/plugins/plugins_handler.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 11 matching lines...) Expand all
22 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/common/chrome_content_client.h" 23 #include "chrome/common/chrome_content_client.h"
24 #include "chrome/common/chrome_paths.h" 24 #include "chrome/common/chrome_paths.h"
25 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
26 #include "chrome/grit/generated_resources.h" 26 #include "chrome/grit/generated_resources.h"
27 #include "components/content_settings/core/browser/host_content_settings_map.h" 27 #include "components/content_settings/core/browser/host_content_settings_map.h"
28 #include "content/public/browser/notification_observer.h" 28 #include "content/public/browser/notification_observer.h"
29 #include "content/public/browser/plugin_service.h" 29 #include "content/public/browser/plugin_service.h"
30 #include "content/public/browser/web_ui.h" 30 #include "content/public/browser/web_ui.h"
31 #include "content/public/common/content_constants.h" 31 #include "content/public/common/content_constants.h"
32 #include "mojo/common/common_type_converters.h"
32 #include "ui/base/l10n/l10n_util.h" 33 #include "ui/base/l10n/l10n_util.h"
33 34
34 using content::WebPluginInfo; 35 using content::WebPluginInfo;
35 // Holds grouped plugins. The key is the group identifier and 36 // Holds grouped plugins. The key is the group identifier and
36 // the value is the list of plugins belonging to the group. 37 // the value is the list of plugins belonging to the group.
37 using PluginGroups = base::hash_map<std::string, 38 using PluginGroups = base::hash_map<std::string,
38 std::vector<const content::WebPluginInfo*>>; 39 std::vector<const content::WebPluginInfo*>>;
39 40
40 namespace { 41 namespace {
41 42
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 desc += base::ASCIIToUTF16(" Debug"); 82 desc += base::ASCIIToUTF16(" Debug");
82 #else 83 #else
83 // On Chromium, we can name it what it really is; the system plugin. 84 // On Chromium, we can name it what it really is; the system plugin.
84 desc += base::ASCIIToUTF16(" System"); 85 desc += base::ASCIIToUTF16(" System");
85 #endif 86 #endif
86 } 87 }
87 } 88 }
88 return desc; 89 return desc;
89 } 90 }
90 91
91 scoped_ptr<base::ListValue> GetPluginMimeTypes(const WebPluginInfo& plugin) { 92 mojo::Array<MimeTypePtr> GeneratePluginMimeTypes(const WebPluginInfo& plugin) {
92 scoped_ptr<base::ListValue> mime_types(new base::ListValue()); 93 mojo::Array<MimeTypePtr> mime_types(0u);
Dan Beam 2016/01/26 20:10:43 shouldn't this be initialized with plugin.mime_typ
dpapad 2016/01/26 22:34:48 Does not have to. There are two ways to populate a
93 for (const auto& plugin_mime_type: plugin.mime_types) { 94 for (const auto& plugin_mime_type: plugin.mime_types) {
94 base::DictionaryValue* mime_type = new base::DictionaryValue(); 95 MimeTypePtr mime_type(MimeType::New());
95 mime_type->SetString("mimeType", plugin_mime_type.mime_type); 96 mime_type->description = mojo::String::From(plugin_mime_type.description);
96 mime_type->SetString("description", plugin_mime_type.description);
97 97
98 base::ListValue* file_extensions = new base::ListValue(); 98 mime_type->mime_type = mojo::String::From(plugin_mime_type.mime_type);
99 for (const auto& mime_file_extension : plugin_mime_type.file_extensions) { 99 mime_type->file_extensions = mojo::Array<mojo::String>::From(
100 file_extensions->Append(new base::StringValue(mime_file_extension)); 100 plugin_mime_type.file_extensions);
101 } 101 mime_types.push_back(std::move(mime_type));
102 mime_type->Set("fileExtensions", file_extensions);
103 mime_types->Append(mime_type);
104 } 102 }
103
105 return mime_types; 104 return mime_types;
106 } 105 }
107 106
108 } // namespace 107 } // namespace
109 108
110 109
111 PluginsHandler::PluginsHandler() : weak_ptr_factory_(this) { 110 PluginsHandler::PluginsHandler(
112 } 111 content::WebUI* web_ui,
113 112 mojo::InterfaceRequest<PluginsHandlerMojo> request)
114 PluginsHandler::~PluginsHandler() { 113 : web_ui_(web_ui), binding_(this, std::move(request)),
115 } 114 weak_ptr_factory_(this) {
Dan Beam 2016/01/26 20:10:43 i think the style-guide (or previous reviewers of
dpapad 2016/01/26 22:34:48 Changed (along with other style fixes, just run cl
116 115 Profile* profile = Profile::FromWebUI(web_ui_);
117 void PluginsHandler::RegisterMessages() {
118 Profile* profile = Profile::FromWebUI(web_ui());
119
120 PrefService* prefs = profile->GetPrefs(); 116 PrefService* prefs = profile->GetPrefs();
121 show_details_.Init(prefs::kPluginsShowDetails, prefs); 117 show_details_.Init(prefs::kPluginsShowDetails, prefs);
122 118
123 registrar_.Add(this, 119 registrar_.Add(this,
124 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, 120 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED,
125 content::Source<Profile>(profile)); 121 content::Source<Profile>(profile));
126
127 web_ui()->RegisterMessageCallback("requestPluginsData",
128 base::Bind(&PluginsHandler::HandleRequestPluginsData,
129 base::Unretained(this)));
130 web_ui()->RegisterMessageCallback("enablePlugin",
131 base::Bind(&PluginsHandler::HandleEnablePluginMessage,
132 base::Unretained(this)));
133 web_ui()->RegisterMessageCallback("setPluginAlwaysAllowed",
134 base::Bind(&PluginsHandler::HandleSetPluginAlwaysAllowed,
135 base::Unretained(this)));
136 web_ui()->RegisterMessageCallback("saveShowDetailsToPrefs",
137 base::Bind(&PluginsHandler::HandleSaveShowDetailsToPrefs,
138 base::Unretained(this)));
139 web_ui()->RegisterMessageCallback("getShowDetails",
140 base::Bind(&PluginsHandler::HandleGetShowDetails,
141 base::Unretained(this)));
142 } 122 }
143 123
144 void PluginsHandler::HandleRequestPluginsData(const base::ListValue* args) { 124 PluginsHandler::~PluginsHandler() {
145 LoadPlugins();
146 } 125 }
147 126
148 void PluginsHandler::HandleEnablePluginMessage(const base::ListValue* args) { 127 void PluginsHandler::SetPluginEnabled(
149 Profile* profile = Profile::FromWebUI(web_ui()); 128 const mojo::String& plugin_path, bool enable) {
129 Profile* profile = Profile::FromWebUI(web_ui_);
130 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get();
131 plugin_prefs->EnablePlugin(
132 enable, base::FilePath(plugin_path.To<base::FilePath::StringType>()),
133 base::Bind(&AssertPluginEnabled));
134 }
150 135
151 // Be robust in accepting badness since plugins display HTML (hence 136 void PluginsHandler::SetPluginGroupEnabled(
152 // JavaScript). 137 const mojo::String& group_name, bool enable) {
153 if (args->GetSize() != 3) { 138 Profile* profile = Profile::FromWebUI(web_ui_);
154 NOTREACHED();
155 return;
156 }
157
158 std::string enable_str;
159 std::string is_group_str;
160 if (!args->GetString(1, &enable_str) || !args->GetString(2, &is_group_str)) {
161 NOTREACHED();
162 return;
163 }
164 bool enable = enable_str == "true";
165
166 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); 139 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get();
167 if (is_group_str == "true") { 140 base::string16 group_name_as_string16 = group_name.To<base::string16>();
168 base::string16 group_name; 141 plugin_prefs->EnablePluginGroup(enable, group_name_as_string16);
169 if (!args->GetString(0, &group_name)) { 142 if (enable) {
170 NOTREACHED(); 143 // See http://crbug.com/50105 for background.
171 return; 144 base::string16 adobereader = base::ASCIIToUTF16(
172 } 145 PluginMetadata::kAdobeReaderGroupName);
173 146 base::string16 internalpdf =
174 plugin_prefs->EnablePluginGroup(enable, group_name); 147 base::ASCIIToUTF16(ChromeContentClient::kPDFPluginName);
175 if (enable) { 148 if (group_name_as_string16 == adobereader)
176 // See http://crbug.com/50105 for background. 149 plugin_prefs->EnablePluginGroup(false, internalpdf);
177 base::string16 adobereader = base::ASCIIToUTF16( 150 else if (group_name_as_string16 == internalpdf)
178 PluginMetadata::kAdobeReaderGroupName); 151 plugin_prefs->EnablePluginGroup(false, adobereader);
179 base::string16 internalpdf =
180 base::ASCIIToUTF16(ChromeContentClient::kPDFPluginName);
181 if (group_name == adobereader)
182 plugin_prefs->EnablePluginGroup(false, internalpdf);
183 else if (group_name == internalpdf)
184 plugin_prefs->EnablePluginGroup(false, adobereader);
185 }
186 } else {
187 base::FilePath::StringType file_path;
188 if (!args->GetString(0, &file_path)) {
189 NOTREACHED();
190 return;
191 }
192
193 plugin_prefs->EnablePlugin(enable, base::FilePath(file_path),
194 base::Bind(&AssertPluginEnabled));
195 } 152 }
196 } 153 }
197 154
198 void PluginsHandler::HandleSaveShowDetailsToPrefs( 155 void PluginsHandler::GetShowDetails(const GetShowDetailsCallback& callback) {
199 const base::ListValue* args) { 156 callback.Run(show_details_.GetValue());
200 std::string details_mode;
201 if (!args->GetString(0, &details_mode)) {
202 NOTREACHED();
203 return;
204 }
205 show_details_.SetValue(details_mode == "true");
206 } 157 }
207 158
208 void PluginsHandler::HandleGetShowDetails(const base::ListValue* args) { 159 void PluginsHandler::SaveShowDetailsToPrefs(bool details_mode) {
209 base::FundamentalValue show_details(show_details_.GetValue()); 160 show_details_.SetValue(details_mode);
210 web_ui()->CallJavascriptFunction("loadShowDetailsFromPrefs", show_details);
211 } 161 }
212 162
213 void PluginsHandler::HandleSetPluginAlwaysAllowed( 163 void PluginsHandler::SetPluginAlwaysAllowed(
214 const base::ListValue* args) { 164 const mojo::String& plugin, bool allowed) {
215 // Be robust in the input parameters, but crash in a Debug build. 165 Profile* profile = Profile::FromWebUI(web_ui_);
216 if (args->GetSize() != 2) {
217 NOTREACHED();
218 return;
219 }
220
221 std::string plugin;
222 bool allowed = false;
223 if (!args->GetString(0, &plugin) || !args->GetBoolean(1, &allowed)) {
224 NOTREACHED();
225 return;
226 }
227 Profile* profile = Profile::FromWebUI(web_ui());
228 HostContentSettingsMapFactory::GetForProfile(profile)->SetContentSetting( 166 HostContentSettingsMapFactory::GetForProfile(profile)->SetContentSetting(
229 ContentSettingsPattern::Wildcard(), 167 ContentSettingsPattern::Wildcard(),
230 ContentSettingsPattern::Wildcard(), 168 ContentSettingsPattern::Wildcard(),
231 CONTENT_SETTINGS_TYPE_PLUGINS, 169 CONTENT_SETTINGS_TYPE_PLUGINS,
232 plugin, 170 plugin.get(),
233 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_DEFAULT); 171 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_DEFAULT);
234 172
235 // Keep track of the whitelist separately, so that we can distinguish plugins 173 // Keep track of the whitelist separately, so that we can distinguish plugins
236 // whitelisted by the user from automatically whitelisted ones. 174 // whitelisted by the user from automatically whitelisted ones.
237 DictionaryPrefUpdate update(profile->GetPrefs(), 175 DictionaryPrefUpdate update(profile->GetPrefs(),
238 prefs::kContentSettingsPluginWhitelist); 176 prefs::kContentSettingsPluginWhitelist);
239 update->SetBoolean(plugin, allowed); 177 update->SetBoolean(plugin, allowed);
240 } 178 }
241 179
180 void PluginsHandler::GetPluginsData(const GetPluginsDataCallback& callback) {
181 if (weak_ptr_factory_.HasWeakPtrs())
Dan Beam 2016/01/26 20:10:43 what is this supposed to be doing? seeing if ther
182 return;
183
184 content::PluginService::GetInstance()->GetPlugins(
185 base::Bind(&PluginsHandler::RespondWithPluginsData,
186 weak_ptr_factory_.GetWeakPtr(),
187 callback));
188 }
189
190 void PluginsHandler::SetClientPage(PluginsPageMojoPtr page) {
191 page_ = std::move(page);
192 }
193
242 void PluginsHandler::Observe(int type, 194 void PluginsHandler::Observe(int type,
243 const content::NotificationSource& source, 195 const content::NotificationSource& source,
244 const content::NotificationDetails& details) { 196 const content::NotificationDetails& details) {
245 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type); 197 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type);
246 LoadPlugins();
247 }
248 198
249 void PluginsHandler::LoadPlugins() {
250 if (weak_ptr_factory_.HasWeakPtrs()) 199 if (weak_ptr_factory_.HasWeakPtrs())
251 return; 200 return;
252 201
253 content::PluginService::GetInstance()->GetPlugins( 202 content::PluginService::GetInstance()->GetPlugins(
254 base::Bind(&PluginsHandler::PluginsLoaded, 203 base::Bind(&PluginsHandler::NotifyWithPluginsData,
255 weak_ptr_factory_.GetWeakPtr())); 204 weak_ptr_factory_.GetWeakPtr()));
256 } 205 }
257 206
258 void PluginsHandler::PluginsLoaded( 207 void PluginsHandler::RespondWithPluginsData(
208 const GetPluginsDataCallback& callback,
259 const std::vector<WebPluginInfo>& plugins) { 209 const std::vector<WebPluginInfo>& plugins) {
260 Profile* profile = Profile::FromWebUI(web_ui()); 210 callback.Run(GeneratePluginsData(plugins));
211 }
212
213 void PluginsHandler::NotifyWithPluginsData(
214 const std::vector<WebPluginInfo>& plugins) {
215 page_->OnPluginsUpdated(GeneratePluginsData(plugins));
216 }
217
218 mojo::Array<PluginDataPtr> PluginsHandler::GeneratePluginsData(
219 const std::vector<WebPluginInfo>& plugins) {
220 Profile* profile = Profile::FromWebUI(web_ui_);
261 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); 221 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get();
262 222
263 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard();
264
265 PluginFinder* plugin_finder = PluginFinder::GetInstance(); 223 PluginFinder* plugin_finder = PluginFinder::GetInstance();
266 // Group plugins by identifier. This is done to be able to display 224 // Group plugins by identifier. This is done to be able to display
267 // the plugins in UI in a grouped fashion. 225 // the plugins in UI in a grouped fashion.
268 PluginGroups groups; 226 PluginGroups groups;
269 for (size_t i = 0; i < plugins.size(); ++i) { 227 for (size_t i = 0; i < plugins.size(); ++i) {
270 scoped_ptr<PluginMetadata> plugin( 228 scoped_ptr<PluginMetadata> plugin(
271 plugin_finder->GetPluginMetadata(plugins[i])); 229 plugin_finder->GetPluginMetadata(plugins[i]));
272 groups[plugin->identifier()].push_back(&plugins[i]); 230 groups[plugin->identifier()].push_back(&plugins[i]);
273 } 231 }
274 232
275 // Construct DictionaryValues to return to UI. 233 mojo::Array<PluginDataPtr> plugins_data(0u);
Dan Beam 2016/01/26 20:10:43 init with groups.size()?
dpapad 2016/01/26 22:34:48 See previous response to similar question.
276 base::ListValue* plugin_groups_data = new base::ListValue(); 234
277 for (PluginGroups::const_iterator it = groups.begin(); 235 for (PluginGroups::const_iterator it = groups.begin();
278 it != groups.end(); ++it) { 236 it != groups.end(); ++it) {
237 PluginDataPtr plugin_data(PluginData::New());
279 const std::vector<const WebPluginInfo*>& group_plugins = it->second; 238 const std::vector<const WebPluginInfo*>& group_plugins = it->second;
280 base::ListValue* plugin_files = new base::ListValue(); 239
281 scoped_ptr<PluginMetadata> plugin_metadata( 240 scoped_ptr<PluginMetadata> plugin_metadata(
282 plugin_finder->GetPluginMetadata(*group_plugins[0])); 241 plugin_finder->GetPluginMetadata(*group_plugins[0]));
283 base::string16 group_name = plugin_metadata->name();
284 std::string group_identifier = plugin_metadata->identifier(); 242 std::string group_identifier = plugin_metadata->identifier();
243 plugin_data->id = mojo::String::From(group_identifier);
244
245 const WebPluginInfo* active_plugin = nullptr;
285 bool group_enabled = false; 246 bool group_enabled = false;
286 const WebPluginInfo* active_plugin = NULL;
287 for (size_t j = 0; j < group_plugins.size(); ++j) {
288 const WebPluginInfo& group_plugin = *group_plugins[j];
289 247
290 base::DictionaryValue* plugin_file = new base::DictionaryValue(); 248 mojo::Array<PluginFilePtr> plugin_files(0u);
Dan Beam 2016/01/26 20:10:43 shouldn't this be initialized with group_plugins.s
dpapad 2016/01/26 22:34:48 See previous response to similar question.
291 plugin_file->SetString("name", group_plugin.name); 249 for (const auto& group_plugin: group_plugins) {
292 plugin_file->SetString("description", GetPluginDescription(group_plugin)); 250 bool plugin_enabled = plugin_prefs->IsPluginEnabled(*group_plugin);
293 plugin_file->SetString("path", group_plugin.path.value());
294 plugin_file->SetString("version", group_plugin.version);
295 plugin_file->SetString("type", PluginTypeToString(group_plugin.type));
296 plugin_file->Set("mimeTypes", GetPluginMimeTypes(group_plugin));
297 251
298 bool plugin_enabled = plugin_prefs->IsPluginEnabled(group_plugin); 252 plugin_files.push_back(GeneratePluginFile(
299 plugin_file->SetString( 253 *group_plugin, plugin_metadata->name(), plugin_enabled));
300 "enabledMode",
301 GetPluginEnabledMode(group_plugin.name, group_name, plugin_enabled));
302 plugin_files->Append(plugin_file);
303 254
255 // Update |active_plugin| and |group_enabled|.
304 if (!active_plugin || (plugin_enabled && !group_enabled)) 256 if (!active_plugin || (plugin_enabled && !group_enabled))
305 active_plugin = &group_plugin; 257 active_plugin = group_plugin;
306 group_enabled = plugin_enabled || group_enabled; 258 group_enabled = plugin_enabled || group_enabled;
307 } 259 }
308 260
309 base::DictionaryValue* group_data = new base::DictionaryValue(); 261 plugin_data->enabled_mode = mojo::String::From(
310 group_data->Set("plugin_files", plugin_files); 262 GetPluginGroupEnabledMode(plugin_files, group_enabled));
311 group_data->SetString("name", group_name);
312 group_data->SetString("id", group_identifier);
313 group_data->SetString("description", active_plugin->desc);
314 group_data->SetString("version", active_plugin->version);
315 263
316 #if defined(ENABLE_PLUGIN_INSTALLATION) 264 plugin_data->always_allowed = false;
317 bool out_of_date = plugin_metadata->GetSecurityStatus(*active_plugin) ==
318 PluginMetadata::SECURITY_STATUS_OUT_OF_DATE;
319 group_data->SetBoolean("critical", out_of_date);
320 group_data->SetString("update_url", plugin_metadata->plugin_url().spec());
321 #endif
322
323 group_data->SetString(
324 "enabledMode", GetPluginGroupEnabledMode(*plugin_files, group_enabled));
325
326 bool always_allowed = false;
327 if (group_enabled) { 265 if (group_enabled) {
328 const base::DictionaryValue* whitelist = 266 const base::DictionaryValue* whitelist =
329 profile->GetPrefs()->GetDictionary( 267 profile->GetPrefs()->GetDictionary(
330 prefs::kContentSettingsPluginWhitelist); 268 prefs::kContentSettingsPluginWhitelist);
331 whitelist->GetBoolean(group_identifier, &always_allowed); 269 whitelist->GetBoolean(group_identifier, &plugin_data->always_allowed);
332 } 270 }
333 group_data->SetBoolean("alwaysAllowed", always_allowed);
334 271
335 plugin_groups_data->Append(group_data); 272 plugin_data->critical = false;
273 plugin_data->update_url = "";
274 #if defined(ENABLE_PLUGIN_INSTALLATION)
275 bool out_of_date = plugin_metadata->GetSecurityStatus(*active_plugin) ==
276 PluginMetadata::SECURITY_STATUS_OUT_OF_DATE;
277 plugin_data->critical = out_of_date;
278 plugin_data->update_url = plugin_metadata->plugin_url().spec();
279 #endif
280
281 plugin_data->description = mojo::String::From(active_plugin->desc);
282 plugin_data->name = plugin_files[0]->name;
283 plugin_data->plugin_files = std::move(plugin_files);
284 plugin_data->version = mojo::String::From(active_plugin->version);
285 plugins_data.push_back(std::move(plugin_data));
336 } 286 }
337 base::DictionaryValue results; 287
338 results.Set("plugins", plugin_groups_data); 288 return plugins_data;
339 web_ui()->CallJavascriptFunction("returnPluginsData", results); 289 }
290
291 PluginFilePtr PluginsHandler::GeneratePluginFile(
292 const WebPluginInfo& plugin,
293 const base::string16& group_name,
294 bool plugin_enabled) const {
295 PluginFilePtr plugin_file(PluginFile::New());
296 plugin_file->description = mojo::String::From(
297 GetPluginDescription(plugin));
298 plugin_file->enabled_mode = mojo::String::From(
299 GetPluginEnabledMode(plugin.name, group_name, plugin_enabled));
300 plugin_file->name = mojo::String::From(plugin.name);
301 plugin_file->path = mojo::String::From(plugin.path.value());
302 plugin_file->type = mojo::String::From(
303 PluginTypeToString(plugin.type));
304 plugin_file->version = mojo::String::From(plugin.version);
305 plugin_file->mime_types = GeneratePluginMimeTypes(plugin);
306
307 return plugin_file;
340 } 308 }
341 309
342 std::string PluginsHandler::GetPluginEnabledMode( 310 std::string PluginsHandler::GetPluginEnabledMode(
343 const base::string16& plugin_name, 311 const base::string16& plugin_name,
344 const base::string16& group_name, 312 const base::string16& group_name,
345 bool plugin_enabled) const { 313 bool plugin_enabled) const {
346 Profile* profile = Profile::FromWebUI(web_ui()); 314 Profile* profile = Profile::FromWebUI(web_ui_);
347 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); 315 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get();
348 PluginPrefs::PolicyStatus plugin_status = 316 PluginPrefs::PolicyStatus plugin_status =
349 plugin_prefs->PolicyStatusForPlugin(plugin_name); 317 plugin_prefs->PolicyStatusForPlugin(plugin_name);
350 PluginPrefs::PolicyStatus group_status = 318 PluginPrefs::PolicyStatus group_status =
351 plugin_prefs->PolicyStatusForPlugin(group_name); 319 plugin_prefs->PolicyStatusForPlugin(group_name);
352 320
353 if (plugin_status == PluginPrefs::POLICY_ENABLED || 321 if (plugin_status == PluginPrefs::POLICY_ENABLED ||
354 group_status == PluginPrefs::POLICY_ENABLED) { 322 group_status == PluginPrefs::POLICY_ENABLED) {
355 return "enabledByPolicy"; 323 return "enabledByPolicy";
356 } 324 }
357 if (plugin_status == PluginPrefs::POLICY_DISABLED || 325 if (plugin_status == PluginPrefs::POLICY_DISABLED ||
358 group_status == PluginPrefs::POLICY_DISABLED) { 326 group_status == PluginPrefs::POLICY_DISABLED) {
359 return "disabledByPolicy"; 327 return "disabledByPolicy";
360 } 328 }
361 return plugin_enabled ? "enabledByUser" : "disabledByUser"; 329 return plugin_enabled ? "enabledByUser" : "disabledByUser";
362 } 330 }
363 331
364 std::string PluginsHandler::GetPluginGroupEnabledMode( 332 std::string PluginsHandler::GetPluginGroupEnabledMode(
365 const base::ListValue& plugin_files, bool group_enabled) const { 333 const mojo::Array<PluginFilePtr>& plugin_files,
334 bool group_enabled) const {
366 bool plugins_enabled_by_policy = true; 335 bool plugins_enabled_by_policy = true;
367 bool plugins_disabled_by_policy = true; 336 bool plugins_disabled_by_policy = true;
368 bool plugins_managed_by_policy = true; 337 bool plugins_managed_by_policy = true;
369 338
370 for (base::ListValue::const_iterator it = plugin_files.begin(); 339 for (size_t i = 0; i < plugin_files.size(); i++) {
371 it != plugin_files.end(); ++it) { 340 std::string plugin_enabled_mode = plugin_files[i]->enabled_mode;
372 base::DictionaryValue* plugin_dict;
373 CHECK((*it)->GetAsDictionary(&plugin_dict));
374 std::string plugin_enabled_mode;
375 CHECK(plugin_dict->GetString("enabledMode", &plugin_enabled_mode));
376 341
377 plugins_enabled_by_policy = plugins_enabled_by_policy && 342 plugins_enabled_by_policy = plugins_enabled_by_policy &&
378 plugin_enabled_mode == "enabledByPolicy"; 343 plugin_enabled_mode == "enabledByPolicy";
379 plugins_disabled_by_policy = plugins_disabled_by_policy && 344 plugins_disabled_by_policy = plugins_disabled_by_policy &&
380 plugin_enabled_mode == "disabledByPolicy"; 345 plugin_enabled_mode == "disabledByPolicy";
381 plugins_managed_by_policy = plugins_managed_by_policy && 346 plugins_managed_by_policy = plugins_managed_by_policy &&
382 (plugin_enabled_mode == "enabledByPolicy" || 347 (plugin_enabled_mode == "enabledByPolicy" ||
383 plugin_enabled_mode == "disabledByPolicy"); 348 plugin_enabled_mode == "disabledByPolicy");
384 } 349 }
385 350
386 if (plugins_enabled_by_policy) 351 if (plugins_enabled_by_policy)
387 return "enabledByPolicy"; 352 return "enabledByPolicy";
388 if (plugins_disabled_by_policy) 353 if (plugins_disabled_by_policy)
389 return "disabledByPolicy"; 354 return "disabledByPolicy";
390 if (plugins_managed_by_policy) 355 if (plugins_managed_by_policy)
391 return "managedByPolicy"; 356 return "managedByPolicy";
392 return group_enabled ? "enabledByUser" : "disabledByUser"; 357 return group_enabled ? "enabledByUser" : "disabledByUser";
393 } 358 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698