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

Side by Side Diff: chrome/browser/plugin_updater.cc

Issue 5699005: Policy: Re-enabled plugin still disabled (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added empty group prunning. Created 9 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 | 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 "chrome/browser/plugin_updater.h" 5 #include "chrome/browser/plugin_updater.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 22 matching lines...) Expand all
33 : enable_internal_pdf_(true), 33 : enable_internal_pdf_(true),
34 notify_pending_(false) { 34 notify_pending_(false) {
35 } 35 }
36 36
37 DictionaryValue* PluginUpdater::CreatePluginFileSummary( 37 DictionaryValue* PluginUpdater::CreatePluginFileSummary(
38 const webkit::npapi::WebPluginInfo& plugin) { 38 const webkit::npapi::WebPluginInfo& plugin) {
39 DictionaryValue* data = new DictionaryValue(); 39 DictionaryValue* data = new DictionaryValue();
40 data->SetString("path", plugin.path.value()); 40 data->SetString("path", plugin.path.value());
41 data->SetString("name", plugin.name); 41 data->SetString("name", plugin.name);
42 data->SetString("version", plugin.version); 42 data->SetString("version", plugin.version);
43 data->SetBoolean("enabled", plugin.enabled); 43 data->SetBoolean("enabled", webkit::npapi::IsPluginEnabled(plugin));
44 return data; 44 return data;
45 } 45 }
46 46
47 // static 47 // static
48 ListValue* PluginUpdater::GetPluginGroupsData() { 48 ListValue* PluginUpdater::GetPluginGroupsData() {
49 std::vector<webkit::npapi::PluginGroup> plugin_groups; 49 std::vector<webkit::npapi::PluginGroup> plugin_groups;
50 webkit::npapi::PluginList::Singleton()->GetPluginGroups(true, &plugin_groups); 50 webkit::npapi::PluginList::Singleton()->GetPluginGroups(true, &plugin_groups);
51 51
52 // Construct DictionaryValues to return to the UI 52 // Construct DictionaryValues to return to the UI
53 ListValue* plugin_groups_data = new ListValue(); 53 ListValue* plugin_groups_data = new ListValue();
54 for (size_t i = 0; i < plugin_groups.size(); ++i) { 54 for (size_t i = 0; i < plugin_groups.size(); ++i) {
55 plugin_groups_data->Append(plugin_groups[i].GetDataForUI()); 55 plugin_groups_data->Append(plugin_groups[i].GetDataForUI());
56 } 56 }
57 return plugin_groups_data; 57 return plugin_groups_data;
58 } 58 }
59 59
60 void PluginUpdater::EnablePluginGroup(bool enable, const string16& group_name) { 60 void PluginUpdater::EnablePluginGroup(bool enable, const string16& group_name) {
61 if (webkit::npapi::PluginGroup::IsPluginNameDisabledByPolicy(group_name))
62 enable = false;
63 webkit::npapi::PluginList::Singleton()->EnableGroup(enable, group_name); 61 webkit::npapi::PluginList::Singleton()->EnableGroup(enable, group_name);
64 NotifyPluginStatusChanged(); 62 NotifyPluginStatusChanged();
65 } 63 }
66 64
67 void PluginUpdater::EnablePluginFile(bool enable, 65 void PluginUpdater::EnablePlugin(bool enable,
68 const FilePath::StringType& path) { 66 const FilePath::StringType& path) {
69 FilePath file_path(path); 67 FilePath file_path(path);
70 if (enable && 68 if (enable)
71 !webkit::npapi::PluginGroup::IsPluginPathDisabledByPolicy(file_path))
72 webkit::npapi::PluginList::Singleton()->EnablePlugin(file_path); 69 webkit::npapi::PluginList::Singleton()->EnablePlugin(file_path);
73 else 70 else
74 webkit::npapi::PluginList::Singleton()->DisablePlugin(file_path); 71 webkit::npapi::PluginList::Singleton()->DisablePlugin(file_path);
75 72
76 NotifyPluginStatusChanged(); 73 NotifyPluginStatusChanged();
77 } 74 }
78 75
79 void PluginUpdater::Observe(NotificationType type, 76 void PluginUpdater::Observe(NotificationType type,
80 const NotificationSource& source, 77 const NotificationSource& source,
81 const NotificationDetails& details) { 78 const NotificationDetails& details) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 found_internal_pdf = true; 182 found_internal_pdf = true;
186 if (!enabled) { 183 if (!enabled) {
187 if (force_enable_internal_pdf) { 184 if (force_enable_internal_pdf) {
188 enabled = true; 185 enabled = true;
189 plugin->SetBoolean("enabled", true); 186 plugin->SetBoolean("enabled", true);
190 } else if (force_internal_pdf_for_this_run) { 187 } else if (force_internal_pdf_for_this_run) {
191 enabled = true; 188 enabled = true;
192 } 189 }
193 } 190 }
194 } 191 }
195 if (!enabled) 192 if (!enabled) {
jam 2011/01/19 20:22:09 nit: no need to add the brace brackets, to be cons
pastarmovj 2011/01/19 23:39:17 Done.
196 webkit::npapi::PluginList::Singleton()->DisablePlugin(plugin_path); 193 webkit::npapi::PluginList::Singleton()->DisablePlugin(plugin_path);
194 }
197 } else if (!enabled && plugin->GetString("name", &group_name)) { 195 } else if (!enabled && plugin->GetString("name", &group_name)) {
198 // Don't disable this group if it's for the pdf plugin and we just 196 // Don't disable this group if it's for the pdf plugin and we just
199 // forced it on. 197 // forced it on.
200 if (force_enable_internal_pdf && pdf_group_name == group_name) 198 if (force_enable_internal_pdf && pdf_group_name == group_name)
201 continue; 199 continue;
202 200
203 // Otherwise this is a list of groups. 201 // Otherwise this is a list of groups.
204 EnablePluginGroup(false, group_name); 202 EnablePluginGroup(false, group_name);
205 } 203 }
206 } 204 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 void PluginUpdater::GetPreferencesDataOnFileThread(void* profile) { 241 void PluginUpdater::GetPreferencesDataOnFileThread(void* profile) {
244 std::vector<webkit::npapi::WebPluginInfo> plugins; 242 std::vector<webkit::npapi::WebPluginInfo> plugins;
245 webkit::npapi::PluginList::Singleton()->GetPlugins(false, &plugins); 243 webkit::npapi::PluginList::Singleton()->GetPlugins(false, &plugins);
246 244
247 std::vector<webkit::npapi::PluginGroup> groups; 245 std::vector<webkit::npapi::PluginGroup> groups;
248 webkit::npapi::PluginList::Singleton()->GetPluginGroups(false, &groups); 246 webkit::npapi::PluginList::Singleton()->GetPluginGroups(false, &groups);
249 247
250 BrowserThread::PostTask( 248 BrowserThread::PostTask(
251 BrowserThread::UI, 249 BrowserThread::UI,
252 FROM_HERE, 250 FROM_HERE,
253 NewRunnableFunction( 251 NewRunnableFunction(&PluginUpdater::OnUpdatePreferences,
254 &PluginUpdater::OnUpdatePreferences, 252 static_cast<Profile*>(profile),
255 static_cast<Profile*>(profile), plugins, groups)); 253 plugins, groups));
256 } 254 }
257 255
258 void PluginUpdater::OnUpdatePreferences( 256 void PluginUpdater::OnUpdatePreferences(
259 Profile* profile, 257 Profile* profile,
260 const std::vector<webkit::npapi::WebPluginInfo>& plugins, 258 const std::vector<webkit::npapi::WebPluginInfo>& plugins,
261 const std::vector<webkit::npapi::PluginGroup>& groups) { 259 const std::vector<webkit::npapi::PluginGroup>& groups) {
262 ListValue* plugins_list = profile->GetPrefs()->GetMutableList( 260 ListValue* plugins_list = profile->GetPrefs()->GetMutableList(
263 prefs::kPluginsPluginsList); 261 prefs::kPluginsPluginsList);
264 plugins_list->Clear(); 262 plugins_list->Clear();
265 263
266 FilePath internal_dir; 264 FilePath internal_dir;
267 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir)) 265 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir))
268 profile->GetPrefs()->SetFilePath(prefs::kPluginsLastInternalDirectory, 266 profile->GetPrefs()->SetFilePath(prefs::kPluginsLastInternalDirectory,
269 internal_dir); 267 internal_dir);
270 268
271 // Add the plugin files. 269 // Add the plugin files.
272 for (std::vector<webkit::npapi::WebPluginInfo>::const_iterator it = 270 for (size_t i = 0; i < plugins.size(); ++i) {
273 plugins.begin(); 271 DictionaryValue* summary = CreatePluginFileSummary(plugins[i]);
274 it != plugins.end(); 272 // If the plugin is disabled only by policy don't store this state in the
275 ++it) { 273 // user pref store.
276 plugins_list->Append(CreatePluginFileSummary(*it)); 274 if (plugins[i].enabled ==
275 webkit::npapi::WebPluginInfo::USER_ENABLED_POLICY_DISABLED) {
276 summary->SetBoolean("enabled", true);
277 }
278 bool enabled_val;
279 summary->GetBoolean("enabled", &enabled_val);
280 plugins_list->Append(summary);
277 } 281 }
278 282
279 // Add the groups as well. 283 // Add the groups as well.
280 for (size_t i = 0; i < groups.size(); ++i) { 284 for (size_t i = 0; i < groups.size(); ++i) {
281 plugins_list->Append(groups[i].GetSummary()); 285 DictionaryValue* summary = groups[i].GetSummary();
286 // If the plugin is disabled only by policy don't store this state in the
287 // user pref store.
288 if (!groups[i].Enabled() &&
289 webkit::npapi::PluginGroup::IsPluginNameDisabledByPolicy(
290 groups[i].GetGroupName()))
291 summary->SetBoolean("enabled", true);
292 plugins_list->Append(summary);
282 } 293 }
283 } 294 }
284 295
285 void PluginUpdater::NotifyPluginStatusChanged() { 296 void PluginUpdater::NotifyPluginStatusChanged() {
286 if (notify_pending_) 297 if (notify_pending_)
287 return; 298 return;
288 notify_pending_ = true; 299 notify_pending_ = true;
289 MessageLoop::current()->PostTask( 300 MessageLoop::current()->PostTask(
290 FROM_HERE, 301 FROM_HERE,
291 NewRunnableFunction(&PluginUpdater::OnNotifyPluginStatusChanged)); 302 NewRunnableFunction(&PluginUpdater::OnNotifyPluginStatusChanged));
292 } 303 }
293 304
294 void PluginUpdater::OnNotifyPluginStatusChanged() { 305 void PluginUpdater::OnNotifyPluginStatusChanged() {
295 GetInstance()->notify_pending_ = false; 306 GetInstance()->notify_pending_ = false;
296 NotificationService::current()->Notify( 307 NotificationService::current()->Notify(
297 NotificationType::PLUGIN_ENABLE_STATUS_CHANGED, 308 NotificationType::PLUGIN_ENABLE_STATUS_CHANGED,
298 Source<PluginUpdater>(GetInstance()), 309 Source<PluginUpdater>(GetInstance()),
299 NotificationService::NoDetails()); 310 NotificationService::NoDetails());
300 } 311 }
301 312
302 /*static*/ 313 /*static*/
303 PluginUpdater* PluginUpdater::GetInstance() { 314 PluginUpdater* PluginUpdater::GetInstance() {
304 return Singleton<PluginUpdater>::get(); 315 return Singleton<PluginUpdater>::get();
305 } 316 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698