OLD | NEW |
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 Loading... |
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 = |
38 std::vector<const content::WebPluginInfo*>>; | 39 base::hash_map<std::string, std::vector<const content::WebPluginInfo*>>; |
39 | 40 |
40 namespace { | 41 namespace { |
41 | 42 |
42 // Callback function to process result of EnablePlugin method. | 43 // Callback function to process result of EnablePlugin method. |
43 void AssertPluginEnabled(bool did_enable) { | 44 void AssertPluginEnabled(bool did_enable) { |
44 DCHECK(did_enable); | 45 DCHECK(did_enable); |
45 } | 46 } |
46 | 47 |
47 base::string16 PluginTypeToString(int type) { | 48 base::string16 PluginTypeToString(int type) { |
48 // The type is stored as an |int|, but doing the switch on the right | 49 // The type is stored as an |int|, but doing the switch on the right |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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); |
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 = |
100 file_extensions->Append(new base::StringValue(mime_file_extension)); | 100 mojo::Array<mojo::String>::From(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 PluginsHandler::PluginsHandler( |
111 PluginsHandler::PluginsHandler() : weak_ptr_factory_(this) { | 110 content::WebUI* web_ui, |
112 } | 111 mojo::InterfaceRequest<PluginsHandlerMojo> request) |
113 | 112 : web_ui_(web_ui), |
114 PluginsHandler::~PluginsHandler() { | 113 binding_(this, std::move(request)), |
115 } | 114 weak_ptr_factory_(this) { |
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, chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, |
124 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, | |
125 content::Source<Profile>(profile)); | 120 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 } | 121 } |
143 | 122 |
144 void PluginsHandler::HandleRequestPluginsData(const base::ListValue* args) { | 123 PluginsHandler::~PluginsHandler() {} |
145 LoadPlugins(); | 124 |
| 125 void PluginsHandler::SetPluginEnabled(const mojo::String& plugin_path, |
| 126 bool enable) { |
| 127 Profile* profile = Profile::FromWebUI(web_ui_); |
| 128 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); |
| 129 plugin_prefs->EnablePlugin( |
| 130 enable, base::FilePath(plugin_path.To<base::FilePath::StringType>()), |
| 131 base::Bind(&AssertPluginEnabled)); |
146 } | 132 } |
147 | 133 |
148 void PluginsHandler::HandleEnablePluginMessage(const base::ListValue* args) { | 134 void PluginsHandler::SetPluginGroupEnabled(const mojo::String& group_name, |
149 Profile* profile = Profile::FromWebUI(web_ui()); | 135 bool enable) { |
150 | 136 Profile* profile = Profile::FromWebUI(web_ui_); |
151 // Be robust in accepting badness since plugins display HTML (hence | 137 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); |
152 // JavaScript). | 138 base::string16 group_name_as_string16 = group_name.To<base::string16>(); |
153 if (args->GetSize() != 3) { | 139 plugin_prefs->EnablePluginGroup(enable, group_name_as_string16); |
154 NOTREACHED(); | 140 if (!enable) { |
155 return; | 141 return; |
156 } | 142 } |
157 | 143 |
158 std::string enable_str; | 144 // See http://crbug.com/50105 for background. |
159 std::string is_group_str; | 145 base::string16 adobereader = |
160 if (!args->GetString(1, &enable_str) || !args->GetString(2, &is_group_str)) { | 146 base::ASCIIToUTF16(PluginMetadata::kAdobeReaderGroupName); |
161 NOTREACHED(); | 147 base::string16 internalpdf = |
162 return; | 148 base::ASCIIToUTF16(ChromeContentClient::kPDFPluginName); |
163 } | 149 if (group_name_as_string16 == adobereader) |
164 bool enable = enable_str == "true"; | 150 plugin_prefs->EnablePluginGroup(false, internalpdf); |
165 | 151 else if (group_name_as_string16 == internalpdf) |
166 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); | 152 plugin_prefs->EnablePluginGroup(false, adobereader); |
167 if (is_group_str == "true") { | |
168 base::string16 group_name; | |
169 if (!args->GetString(0, &group_name)) { | |
170 NOTREACHED(); | |
171 return; | |
172 } | |
173 | |
174 plugin_prefs->EnablePluginGroup(enable, group_name); | |
175 if (enable) { | |
176 // See http://crbug.com/50105 for background. | |
177 base::string16 adobereader = base::ASCIIToUTF16( | |
178 PluginMetadata::kAdobeReaderGroupName); | |
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 } | |
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(const mojo::String& plugin, |
214 const base::ListValue* args) { | 164 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(), ContentSettingsPattern::Wildcard(), |
230 ContentSettingsPattern::Wildcard(), | 168 CONTENT_SETTINGS_TYPE_PLUGINS, plugin.get(), |
231 CONTENT_SETTINGS_TYPE_PLUGINS, | |
232 plugin, | |
233 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_DEFAULT); | 169 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_DEFAULT); |
234 | 170 |
235 // Keep track of the whitelist separately, so that we can distinguish plugins | 171 // Keep track of the whitelist separately, so that we can distinguish plugins |
236 // whitelisted by the user from automatically whitelisted ones. | 172 // whitelisted by the user from automatically whitelisted ones. |
237 DictionaryPrefUpdate update(profile->GetPrefs(), | 173 DictionaryPrefUpdate update(profile->GetPrefs(), |
238 prefs::kContentSettingsPluginWhitelist); | 174 prefs::kContentSettingsPluginWhitelist); |
239 update->SetBoolean(plugin, allowed); | 175 update->SetBoolean(plugin, allowed); |
240 } | 176 } |
241 | 177 |
| 178 void PluginsHandler::GetPluginsData(const GetPluginsDataCallback& callback) { |
| 179 if (weak_ptr_factory_.HasWeakPtrs()) |
| 180 return; |
| 181 |
| 182 content::PluginService::GetInstance()->GetPlugins( |
| 183 base::Bind(&PluginsHandler::RespondWithPluginsData, |
| 184 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 185 } |
| 186 |
| 187 void PluginsHandler::SetClientPage(PluginsPageMojoPtr page) { |
| 188 page_ = std::move(page); |
| 189 } |
| 190 |
242 void PluginsHandler::Observe(int type, | 191 void PluginsHandler::Observe(int type, |
243 const content::NotificationSource& source, | 192 const content::NotificationSource& source, |
244 const content::NotificationDetails& details) { | 193 const content::NotificationDetails& details) { |
245 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type); | 194 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type); |
246 LoadPlugins(); | |
247 } | |
248 | 195 |
249 void PluginsHandler::LoadPlugins() { | |
250 if (weak_ptr_factory_.HasWeakPtrs()) | 196 if (weak_ptr_factory_.HasWeakPtrs()) |
251 return; | 197 return; |
252 | 198 |
253 content::PluginService::GetInstance()->GetPlugins( | 199 content::PluginService::GetInstance()->GetPlugins(base::Bind( |
254 base::Bind(&PluginsHandler::PluginsLoaded, | 200 &PluginsHandler::NotifyWithPluginsData, weak_ptr_factory_.GetWeakPtr())); |
255 weak_ptr_factory_.GetWeakPtr())); | |
256 } | 201 } |
257 | 202 |
258 void PluginsHandler::PluginsLoaded( | 203 void PluginsHandler::RespondWithPluginsData( |
| 204 const GetPluginsDataCallback& callback, |
259 const std::vector<WebPluginInfo>& plugins) { | 205 const std::vector<WebPluginInfo>& plugins) { |
260 Profile* profile = Profile::FromWebUI(web_ui()); | 206 callback.Run(GeneratePluginsData(plugins)); |
| 207 } |
| 208 |
| 209 void PluginsHandler::NotifyWithPluginsData( |
| 210 const std::vector<WebPluginInfo>& plugins) { |
| 211 if (page_) |
| 212 page_->OnPluginsUpdated(GeneratePluginsData(plugins)); |
| 213 } |
| 214 |
| 215 mojo::Array<PluginDataPtr> PluginsHandler::GeneratePluginsData( |
| 216 const std::vector<WebPluginInfo>& plugins) { |
| 217 Profile* profile = Profile::FromWebUI(web_ui_); |
261 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); | 218 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); |
262 | 219 |
263 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); | |
264 | |
265 PluginFinder* plugin_finder = PluginFinder::GetInstance(); | 220 PluginFinder* plugin_finder = PluginFinder::GetInstance(); |
266 // Group plugins by identifier. This is done to be able to display | 221 // Group plugins by identifier. This is done to be able to display |
267 // the plugins in UI in a grouped fashion. | 222 // the plugins in UI in a grouped fashion. |
268 PluginGroups groups; | 223 PluginGroups groups; |
269 for (size_t i = 0; i < plugins.size(); ++i) { | 224 for (size_t i = 0; i < plugins.size(); ++i) { |
270 scoped_ptr<PluginMetadata> plugin( | 225 scoped_ptr<PluginMetadata> plugin( |
271 plugin_finder->GetPluginMetadata(plugins[i])); | 226 plugin_finder->GetPluginMetadata(plugins[i])); |
272 groups[plugin->identifier()].push_back(&plugins[i]); | 227 groups[plugin->identifier()].push_back(&plugins[i]); |
273 } | 228 } |
274 | 229 |
275 // Construct DictionaryValues to return to UI. | 230 mojo::Array<PluginDataPtr> plugins_data(0u); |
276 base::ListValue* plugin_groups_data = new base::ListValue(); | 231 |
277 for (PluginGroups::const_iterator it = groups.begin(); | 232 for (PluginGroups::const_iterator it = groups.begin(); it != groups.end(); |
278 it != groups.end(); ++it) { | 233 ++it) { |
| 234 PluginDataPtr plugin_data(PluginData::New()); |
279 const std::vector<const WebPluginInfo*>& group_plugins = it->second; | 235 const std::vector<const WebPluginInfo*>& group_plugins = it->second; |
280 base::ListValue* plugin_files = new base::ListValue(); | 236 |
281 scoped_ptr<PluginMetadata> plugin_metadata( | 237 scoped_ptr<PluginMetadata> plugin_metadata( |
282 plugin_finder->GetPluginMetadata(*group_plugins[0])); | 238 plugin_finder->GetPluginMetadata(*group_plugins[0])); |
283 base::string16 group_name = plugin_metadata->name(); | |
284 std::string group_identifier = plugin_metadata->identifier(); | 239 std::string group_identifier = plugin_metadata->identifier(); |
| 240 plugin_data->id = mojo::String::From(group_identifier); |
| 241 |
| 242 const WebPluginInfo* active_plugin = nullptr; |
285 bool group_enabled = false; | 243 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 | 244 |
290 base::DictionaryValue* plugin_file = new base::DictionaryValue(); | 245 mojo::Array<PluginFilePtr> plugin_files(0u); |
291 plugin_file->SetString("name", group_plugin.name); | 246 for (const auto& group_plugin : group_plugins) { |
292 plugin_file->SetString("description", GetPluginDescription(group_plugin)); | 247 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 | 248 |
298 bool plugin_enabled = plugin_prefs->IsPluginEnabled(group_plugin); | 249 plugin_files.push_back(GeneratePluginFile( |
299 plugin_file->SetString( | 250 *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 | 251 |
| 252 // Update |active_plugin| and |group_enabled|. |
304 if (!active_plugin || (plugin_enabled && !group_enabled)) | 253 if (!active_plugin || (plugin_enabled && !group_enabled)) |
305 active_plugin = &group_plugin; | 254 active_plugin = group_plugin; |
306 group_enabled = plugin_enabled || group_enabled; | 255 group_enabled = plugin_enabled || group_enabled; |
307 } | 256 } |
308 | 257 |
309 base::DictionaryValue* group_data = new base::DictionaryValue(); | 258 plugin_data->enabled_mode = mojo::String::From( |
310 group_data->Set("plugin_files", plugin_files); | 259 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 | 260 |
316 #if defined(ENABLE_PLUGIN_INSTALLATION) | 261 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) { | 262 if (group_enabled) { |
328 const base::DictionaryValue* whitelist = | 263 const base::DictionaryValue* whitelist = |
329 profile->GetPrefs()->GetDictionary( | 264 profile->GetPrefs()->GetDictionary( |
330 prefs::kContentSettingsPluginWhitelist); | 265 prefs::kContentSettingsPluginWhitelist); |
331 whitelist->GetBoolean(group_identifier, &always_allowed); | 266 whitelist->GetBoolean(group_identifier, &plugin_data->always_allowed); |
332 } | 267 } |
333 group_data->SetBoolean("alwaysAllowed", always_allowed); | |
334 | 268 |
335 plugin_groups_data->Append(group_data); | 269 plugin_data->critical = false; |
| 270 plugin_data->update_url = ""; |
| 271 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 272 bool out_of_date = plugin_metadata->GetSecurityStatus(*active_plugin) == |
| 273 PluginMetadata::SECURITY_STATUS_OUT_OF_DATE; |
| 274 plugin_data->critical = out_of_date; |
| 275 plugin_data->update_url = plugin_metadata->plugin_url().spec(); |
| 276 #endif |
| 277 |
| 278 plugin_data->description = mojo::String::From(active_plugin->desc); |
| 279 plugin_data->name = plugin_files[0]->name; |
| 280 plugin_data->plugin_files = std::move(plugin_files); |
| 281 plugin_data->version = mojo::String::From(active_plugin->version); |
| 282 plugins_data.push_back(std::move(plugin_data)); |
336 } | 283 } |
337 base::DictionaryValue results; | 284 |
338 results.Set("plugins", plugin_groups_data); | 285 return plugins_data; |
339 web_ui()->CallJavascriptFunction("returnPluginsData", results); | 286 } |
| 287 |
| 288 PluginFilePtr PluginsHandler::GeneratePluginFile( |
| 289 const WebPluginInfo& plugin, |
| 290 const base::string16& group_name, |
| 291 bool plugin_enabled) const { |
| 292 PluginFilePtr plugin_file(PluginFile::New()); |
| 293 plugin_file->description = mojo::String::From(GetPluginDescription(plugin)); |
| 294 plugin_file->enabled_mode = mojo::String::From( |
| 295 GetPluginEnabledMode(plugin.name, group_name, plugin_enabled)); |
| 296 plugin_file->name = mojo::String::From(plugin.name); |
| 297 plugin_file->path = mojo::String::From(plugin.path.value()); |
| 298 plugin_file->type = mojo::String::From(PluginTypeToString(plugin.type)); |
| 299 plugin_file->version = mojo::String::From(plugin.version); |
| 300 plugin_file->mime_types = GeneratePluginMimeTypes(plugin); |
| 301 |
| 302 return plugin_file; |
340 } | 303 } |
341 | 304 |
342 std::string PluginsHandler::GetPluginEnabledMode( | 305 std::string PluginsHandler::GetPluginEnabledMode( |
343 const base::string16& plugin_name, | 306 const base::string16& plugin_name, |
344 const base::string16& group_name, | 307 const base::string16& group_name, |
345 bool plugin_enabled) const { | 308 bool plugin_enabled) const { |
346 Profile* profile = Profile::FromWebUI(web_ui()); | 309 Profile* profile = Profile::FromWebUI(web_ui_); |
347 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); | 310 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); |
348 PluginPrefs::PolicyStatus plugin_status = | 311 PluginPrefs::PolicyStatus plugin_status = |
349 plugin_prefs->PolicyStatusForPlugin(plugin_name); | 312 plugin_prefs->PolicyStatusForPlugin(plugin_name); |
350 PluginPrefs::PolicyStatus group_status = | 313 PluginPrefs::PolicyStatus group_status = |
351 plugin_prefs->PolicyStatusForPlugin(group_name); | 314 plugin_prefs->PolicyStatusForPlugin(group_name); |
352 | 315 |
353 if (plugin_status == PluginPrefs::POLICY_ENABLED || | 316 if (plugin_status == PluginPrefs::POLICY_ENABLED || |
354 group_status == PluginPrefs::POLICY_ENABLED) { | 317 group_status == PluginPrefs::POLICY_ENABLED) { |
355 return "enabledByPolicy"; | 318 return "enabledByPolicy"; |
356 } | 319 } |
357 if (plugin_status == PluginPrefs::POLICY_DISABLED || | 320 if (plugin_status == PluginPrefs::POLICY_DISABLED || |
358 group_status == PluginPrefs::POLICY_DISABLED) { | 321 group_status == PluginPrefs::POLICY_DISABLED) { |
359 return "disabledByPolicy"; | 322 return "disabledByPolicy"; |
360 } | 323 } |
361 return plugin_enabled ? "enabledByUser" : "disabledByUser"; | 324 return plugin_enabled ? "enabledByUser" : "disabledByUser"; |
362 } | 325 } |
363 | 326 |
364 std::string PluginsHandler::GetPluginGroupEnabledMode( | 327 std::string PluginsHandler::GetPluginGroupEnabledMode( |
365 const base::ListValue& plugin_files, bool group_enabled) const { | 328 const mojo::Array<PluginFilePtr>& plugin_files, |
| 329 bool group_enabled) const { |
366 bool plugins_enabled_by_policy = true; | 330 bool plugins_enabled_by_policy = true; |
367 bool plugins_disabled_by_policy = true; | 331 bool plugins_disabled_by_policy = true; |
368 bool plugins_managed_by_policy = true; | 332 bool plugins_managed_by_policy = true; |
369 | 333 |
370 for (base::ListValue::const_iterator it = plugin_files.begin(); | 334 for (size_t i = 0; i < plugin_files.size(); i++) { |
371 it != plugin_files.end(); ++it) { | 335 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 | 336 |
377 plugins_enabled_by_policy = plugins_enabled_by_policy && | 337 plugins_enabled_by_policy = |
378 plugin_enabled_mode == "enabledByPolicy"; | 338 plugins_enabled_by_policy && plugin_enabled_mode == "enabledByPolicy"; |
379 plugins_disabled_by_policy = plugins_disabled_by_policy && | 339 plugins_disabled_by_policy = |
380 plugin_enabled_mode == "disabledByPolicy"; | 340 plugins_disabled_by_policy && plugin_enabled_mode == "disabledByPolicy"; |
381 plugins_managed_by_policy = plugins_managed_by_policy && | 341 plugins_managed_by_policy = plugins_managed_by_policy && |
382 (plugin_enabled_mode == "enabledByPolicy" || | 342 (plugin_enabled_mode == "enabledByPolicy" || |
383 plugin_enabled_mode == "disabledByPolicy"); | 343 plugin_enabled_mode == "disabledByPolicy"); |
384 } | 344 } |
385 | 345 |
386 if (plugins_enabled_by_policy) | 346 if (plugins_enabled_by_policy) |
387 return "enabledByPolicy"; | 347 return "enabledByPolicy"; |
388 if (plugins_disabled_by_policy) | 348 if (plugins_disabled_by_policy) |
389 return "disabledByPolicy"; | 349 return "disabledByPolicy"; |
390 if (plugins_managed_by_policy) | 350 if (plugins_managed_by_policy) |
391 return "managedByPolicy"; | 351 return "managedByPolicy"; |
392 return group_enabled ? "enabledByUser" : "disabledByUser"; | 352 return group_enabled ? "enabledByUser" : "disabledByUser"; |
393 } | 353 } |
OLD | NEW |