| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_prefs.h" | 5 #include "chrome/browser/plugin_prefs.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "base/version.h" | 19 #include "base/version.h" |
| 20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/plugin_installer.h" |
| 21 #include "chrome/browser/plugin_prefs_factory.h" | 22 #include "chrome/browser/plugin_prefs_factory.h" |
| 22 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 23 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/profiles/profile_keyed_service.h" | 25 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 25 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
| 26 #include "chrome/common/chrome_content_client.h" | 27 #include "chrome/common/chrome_content_client.h" |
| 27 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
| 28 #include "chrome/common/chrome_paths.h" | 29 #include "chrome/common/chrome_paths.h" |
| 29 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 30 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 31 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
| 32 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
| 33 #include "content/public/browser/plugin_service.h" | 34 #include "content/public/browser/plugin_service.h" |
| 34 #include "webkit/plugins/npapi/plugin_group.h" | 35 #include "webkit/plugins/npapi/plugin_group.h" |
| 35 #include "webkit/plugins/npapi/plugin_list.h" | 36 #include "webkit/plugins/npapi/plugin_list.h" |
| 36 #include "webkit/plugins/webplugininfo.h" | 37 #include "webkit/plugins/webplugininfo.h" |
| 37 | 38 |
| 38 using content::BrowserThread; | 39 using content::BrowserThread; |
| 39 using content::PluginService; | 40 using content::PluginService; |
| 40 | 41 |
| 41 namespace { | 42 namespace { |
| 42 | 43 |
| 43 // Default state for a plug-in (not state of the default plug-in!). | 44 // Default state for a plug-in (not state of the default plug-in!). |
| 44 // Accessed only on the UI thread. | 45 // Accessed only on the UI thread. |
| 45 base::LazyInstance<std::map<FilePath, bool> > g_default_plugin_state = | 46 base::LazyInstance<std::map<FilePath, bool> > g_default_plugin_state = |
| 46 LAZY_INSTANCE_INITIALIZER; | 47 LAZY_INSTANCE_INITIALIZER; |
| 47 | 48 |
| 48 class CallbackBarrier : public base::RefCountedThreadSafe<CallbackBarrier> { | 49 class CallbackBarrier : public base::RefCountedThreadSafe<CallbackBarrier> { |
| 49 public: | 50 public: |
| 50 explicit CallbackBarrier(const base::Closure& callback) | 51 explicit CallbackBarrier(const base::Callback<void(bool)>& callback) |
| 51 : callback_(callback), | 52 : callback_(callback), |
| 52 outstanding_callbacks_(0) { | 53 outstanding_callbacks_(0), |
| 54 did_enable_(true) { |
| 53 DCHECK(!callback_.is_null()); | 55 DCHECK(!callback_.is_null()); |
| 54 } | 56 } |
| 55 | 57 |
| 56 base::Closure CreateCallback() { | 58 base::Callback<void(bool)> CreateCallback() { |
| 57 outstanding_callbacks_++; | 59 outstanding_callbacks_++; |
| 58 return base::Bind(&CallbackBarrier::MaybeRunCallback, this); | 60 return base::Bind(&CallbackBarrier::MaybeRunCallback, this); |
| 59 } | 61 } |
| 60 | 62 |
| 61 private: | 63 private: |
| 62 friend class base::RefCountedThreadSafe<CallbackBarrier>; | 64 friend class base::RefCountedThreadSafe<CallbackBarrier>; |
| 63 | 65 |
| 64 ~CallbackBarrier() { | 66 ~CallbackBarrier() { |
| 65 DCHECK(callback_.is_null()); | 67 DCHECK(callback_.is_null()); |
| 66 } | 68 } |
| 67 | 69 |
| 68 void MaybeRunCallback() { | 70 void MaybeRunCallback(bool did_enable) { |
| 69 DCHECK_GT(outstanding_callbacks_, 0); | 71 DCHECK_GT(outstanding_callbacks_, 0); |
| 72 did_enable_ = did_enable_ && did_enable; |
| 70 if (--outstanding_callbacks_ == 0) { | 73 if (--outstanding_callbacks_ == 0) { |
| 71 callback_.Run(); | 74 callback_.Run(did_enable_); |
| 72 callback_.Reset(); | 75 callback_.Reset(); |
| 73 } | 76 } |
| 74 } | 77 } |
| 75 | 78 |
| 76 base::Closure callback_; | 79 base::Callback<void(bool)> callback_; |
| 77 int outstanding_callbacks_; | 80 int outstanding_callbacks_; |
| 81 bool did_enable_; |
| 78 }; | 82 }; |
| 79 | 83 |
| 80 } // namespace | 84 } // namespace |
| 81 | 85 |
| 82 // How long to wait to save the plugin enabled information, which might need to | 86 // How long to wait to save the plugin enabled information, which might need to |
| 83 // go to disk. | 87 // go to disk. |
| 84 #define kPluginUpdateDelayMs (60 * 1000) | 88 #define kPluginUpdateDelayMs (60 * 1000) |
| 85 | 89 |
| 86 // static | 90 // static |
| 87 scoped_refptr<PluginPrefs> PluginPrefs::GetForProfile(Profile* profile) { | 91 scoped_refptr<PluginPrefs> PluginPrefs::GetForProfile(Profile* profile) { |
| 88 return PluginPrefsFactory::GetPrefsForProfile(profile); | 92 return PluginPrefsFactory::GetPrefsForProfile(profile); |
| 89 } | 93 } |
| 90 | 94 |
| 91 // static | 95 // static |
| 92 scoped_refptr<PluginPrefs> PluginPrefs::GetForTestingProfile( | 96 scoped_refptr<PluginPrefs> PluginPrefs::GetForTestingProfile( |
| 93 Profile* profile) { | 97 Profile* profile) { |
| 94 return static_cast<PluginPrefs*>( | 98 return static_cast<PluginPrefs*>( |
| 95 PluginPrefsFactory::GetInstance()->SetTestingFactoryAndUse( | 99 PluginPrefsFactory::GetInstance()->SetTestingFactoryAndUse( |
| 96 profile, &PluginPrefsFactory::CreateForTestingProfile).get()); | 100 profile, &PluginPrefsFactory::CreateForTestingProfile).get()); |
| 97 } | 101 } |
| 98 | 102 |
| 99 void PluginPrefs::SetPluginListForTesting( | 103 void PluginPrefs::SetPluginListForTesting( |
| 100 webkit::npapi::PluginList* plugin_list) { | 104 webkit::npapi::PluginList* plugin_list) { |
| 101 plugin_list_ = plugin_list; | 105 plugin_list_ = plugin_list; |
| 102 } | 106 } |
| 103 | 107 |
| 104 void PluginPrefs::EnablePluginGroup(bool enabled, const string16& group_name) { | 108 void PluginPrefs::EnablePluginGroup(bool enabled, const string16& group_name) { |
| 105 PluginService::GetInstance()->GetPluginGroups( | 109 PluginFinder::Get( |
| 106 base::Bind(&PluginPrefs::EnablePluginGroupInternal, | 110 base::Bind(&PluginPrefs::GetPluginFinderForEnablePluginGroup, |
| 107 this, enabled, group_name)); | 111 this, enabled, group_name)); |
| 112 } |
| 113 |
| 114 void PluginPrefs::GetPluginFinderForEnablePluginGroup( |
| 115 bool enabled, |
| 116 const string16& group_name, |
| 117 PluginFinder* finder) { |
| 118 PluginService::GetInstance()->GetPlugins( |
| 119 base::Bind(&PluginPrefs::EnablePluginGroupInternal, |
| 120 this, enabled, group_name, finder)); |
| 108 } | 121 } |
| 109 | 122 |
| 110 void PluginPrefs::EnablePluginGroupInternal( | 123 void PluginPrefs::EnablePluginGroupInternal( |
| 111 bool enabled, | 124 bool enabled, |
| 112 const string16& group_name, | 125 const string16& group_name, |
| 113 const std::vector<webkit::npapi::PluginGroup>& groups) { | 126 PluginFinder* finder, |
| 127 const std::vector<webkit::WebPluginInfo>& plugins) { |
| 114 base::AutoLock auto_lock(lock_); | 128 base::AutoLock auto_lock(lock_); |
| 115 | 129 |
| 116 // Set the desired state for the group. | 130 // Set the desired state for the group. |
| 117 plugin_group_state_[group_name] = enabled; | 131 plugin_group_state_[group_name] = enabled; |
| 118 | 132 |
| 119 // Update the state for all plug-ins in the group. | 133 // Update the state for all plug-ins in the group. |
| 120 for (size_t i = 0; i < groups.size(); ++i) { | 134 for (size_t i = 0; i < plugins.size(); ++i) { |
| 121 if (groups[i].GetGroupName() != group_name) | 135 PluginInstaller* installer = finder->GetPluginInstaller(plugins[i]); |
| 136 if (group_name != installer->name()) |
| 122 continue; | 137 continue; |
| 123 const std::vector<webkit::WebPluginInfo>& plugins = | 138 plugin_state_[plugins[i].path] = enabled; |
| 124 groups[i].web_plugin_infos(); | |
| 125 for (size_t j = 0; j < plugins.size(); ++j) | |
| 126 plugin_state_[plugins[j].path] = enabled; | |
| 127 break; | |
| 128 } | 139 } |
| 129 | 140 |
| 130 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 141 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 131 base::Bind(&PluginPrefs::OnUpdatePreferences, this, groups)); | 142 base::Bind(&PluginPrefs::OnUpdatePreferences, this, plugins, finder)); |
| 132 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 143 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 133 base::Bind(&PluginPrefs::NotifyPluginStatusChanged, this)); | 144 base::Bind(&PluginPrefs::NotifyPluginStatusChanged, this)); |
| 134 } | 145 } |
| 135 | 146 |
| 136 bool PluginPrefs::CanEnablePlugin(bool enabled, const FilePath& path) { | 147 void PluginPrefs::EnablePluginIfPossibleCallback( |
| 137 webkit::npapi::PluginList* plugin_list = GetPluginList(); | 148 bool enabled, const FilePath& path, |
| 149 const base::Callback<void(bool)>& callback, |
| 150 PluginFinder* finder) { |
| 138 webkit::WebPluginInfo plugin; | 151 webkit::WebPluginInfo plugin; |
| 152 bool can_enable = true; |
| 139 if (PluginService::GetInstance()->GetPluginInfoByPath(path, &plugin)) { | 153 if (PluginService::GetInstance()->GetPluginInfoByPath(path, &plugin)) { |
| 140 scoped_ptr<webkit::npapi::PluginGroup> group( | 154 PluginInstaller* installer = finder->GetPluginInstaller(plugin); |
| 141 plugin_list->GetPluginGroup(plugin)); | |
| 142 PolicyStatus plugin_status = PolicyStatusForPlugin(plugin.name); | 155 PolicyStatus plugin_status = PolicyStatusForPlugin(plugin.name); |
| 143 PolicyStatus group_status = PolicyStatusForPlugin(group->GetGroupName()); | 156 PolicyStatus group_status = PolicyStatusForPlugin(installer->name()); |
| 144 if (enabled) { | 157 if (enabled) { |
| 145 if (plugin_status == POLICY_DISABLED || group_status == POLICY_DISABLED) | 158 if (plugin_status == POLICY_DISABLED || group_status == POLICY_DISABLED) |
| 146 return false; | 159 can_enable = false; |
| 147 } else { | 160 } else { |
| 148 if (plugin_status == POLICY_ENABLED || group_status == POLICY_ENABLED) | 161 if (plugin_status == POLICY_ENABLED || group_status == POLICY_ENABLED) |
| 149 return false; | 162 can_enable = false; |
| 150 } | 163 } |
| 151 } else { | 164 } else { |
| 152 NOTREACHED(); | 165 NOTREACHED(); |
| 153 } | 166 } |
| 154 return true; | 167 |
| 168 if (!can_enable) { |
| 169 callback.Run(false); |
| 170 return; |
| 171 } |
| 172 |
| 173 PluginService::GetInstance()->GetPlugins( |
| 174 base::Bind(&PluginPrefs::EnablePluginInternal, this, |
| 175 enabled, path, finder, callback)); |
| 155 } | 176 } |
| 156 | 177 |
| 157 void PluginPrefs::EnablePlugin(bool enabled, const FilePath& path, | 178 void PluginPrefs::EnablePlugin( |
| 158 const base::Closure& callback) { | 179 bool enabled, const FilePath& path, |
| 159 PluginService::GetInstance()->GetPluginGroups( | 180 const base::Callback<void(bool)>& callback) { |
| 160 base::Bind(&PluginPrefs::EnablePluginInternal, this, | 181 PluginFinder::Get(base::Bind(&PluginPrefs::EnablePluginIfPossibleCallback, |
| 161 enabled, path, callback)); | 182 this, enabled, path, callback)); |
| 162 } | 183 } |
| 163 | 184 |
| 164 void PluginPrefs::EnablePluginInternal( | 185 void PluginPrefs::EnablePluginInternal( |
| 165 bool enabled, | 186 bool enabled, |
| 166 const FilePath& path, | 187 const FilePath& path, |
| 167 const base::Closure& callback, | 188 PluginFinder* plugin_finder, |
| 168 const std::vector<webkit::npapi::PluginGroup>& groups) { | 189 const base::Callback<void(bool)>& callback, |
| 190 const std::vector<webkit::WebPluginInfo>& plugins) { |
| 169 { | 191 { |
| 170 // Set the desired state for the plug-in. | 192 // Set the desired state for the plug-in. |
| 171 base::AutoLock auto_lock(lock_); | 193 base::AutoLock auto_lock(lock_); |
| 172 plugin_state_[path] = enabled; | 194 plugin_state_[path] = enabled; |
| 173 } | 195 } |
| 174 | 196 |
| 175 bool found_group = false; | 197 string16 group_name; |
| 176 for (size_t i = 0; i < groups.size(); ++i) { | 198 for (size_t i = 0; i < plugins.size(); ++i) { |
| 177 bool all_disabled = true; | 199 if (plugins[i].path == path) { |
| 178 const std::vector<webkit::WebPluginInfo>& plugins = | 200 PluginInstaller* installer = |
| 179 groups[i].web_plugin_infos(); | 201 plugin_finder->GetPluginInstaller(plugins[i]); |
| 180 for (size_t j = 0; j < plugins.size(); ++j) { | 202 // set the group name for this plug-in. |
| 181 all_disabled = all_disabled && !IsPluginEnabled(plugins[j]); | 203 group_name = installer->name(); |
| 182 if (plugins[j].path == path) { | 204 DCHECK_EQ(enabled, IsPluginEnabled(plugins[i])); |
| 183 found_group = true; | |
| 184 DCHECK_EQ(enabled, IsPluginEnabled(plugins[j])); | |
| 185 } | |
| 186 } | |
| 187 if (found_group) { | |
| 188 // Update the state for the corresponding plug-in group. | |
| 189 base::AutoLock auto_lock(lock_); | |
| 190 plugin_group_state_[groups[i].GetGroupName()] = !all_disabled; | |
| 191 break; | 205 break; |
| 192 } | 206 } |
| 193 } | 207 } |
| 194 | 208 |
| 209 bool all_disabled = true; |
| 210 for (size_t i = 0; i < plugins.size(); ++i) { |
| 211 PluginInstaller* installer = plugin_finder->GetPluginInstaller(plugins[i]); |
| 212 DCHECK(!installer->name().empty()); |
| 213 if (group_name == installer->name()) { |
| 214 all_disabled = all_disabled && !IsPluginEnabled(plugins[i]); |
| 215 } |
| 216 } |
| 217 |
| 218 if (!group_name.empty()) { |
| 219 // Update the state for the corresponding plug-in group. |
| 220 base::AutoLock auto_lock(lock_); |
| 221 plugin_group_state_[group_name] = !all_disabled; |
| 222 } |
| 223 |
| 195 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 224 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 196 base::Bind(&PluginPrefs::OnUpdatePreferences, this, groups)); | 225 base::Bind(&PluginPrefs::OnUpdatePreferences, this, |
| 226 plugins, plugin_finder)); |
| 197 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 227 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 198 base::Bind(&PluginPrefs::NotifyPluginStatusChanged, this)); | 228 base::Bind(&PluginPrefs::NotifyPluginStatusChanged, this)); |
| 199 callback.Run(); | 229 callback.Run(true); |
| 200 } | 230 } |
| 201 | 231 |
| 202 // static | 232 // static |
| 203 void PluginPrefs::EnablePluginGlobally(bool enable, const FilePath& file_path, | 233 void PluginPrefs::EnablePluginGlobally( |
| 204 const base::Closure& callback) { | 234 bool enable, |
| 235 const FilePath& file_path, |
| 236 const base::Callback<void(bool)>& callback) { |
| 205 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 206 g_default_plugin_state.Get()[file_path] = enable; | 238 g_default_plugin_state.Get()[file_path] = enable; |
| 207 std::vector<Profile*> profiles = | 239 std::vector<Profile*> profiles = |
| 208 g_browser_process->profile_manager()->GetLoadedProfiles(); | 240 g_browser_process->profile_manager()->GetLoadedProfiles(); |
| 209 scoped_refptr<CallbackBarrier> barrier = new CallbackBarrier(callback); | 241 scoped_refptr<CallbackBarrier> barrier = new CallbackBarrier(callback); |
| 210 for (std::vector<Profile*>::iterator it = profiles.begin(); | 242 for (std::vector<Profile*>::iterator it = profiles.begin(); |
| 211 it != profiles.end(); ++it) { | 243 it != profiles.end(); ++it) { |
| 212 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(*it); | 244 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(*it); |
| 213 DCHECK(plugin_prefs); | 245 DCHECK(plugin_prefs); |
| 214 plugin_prefs->EnablePlugin(enable, file_path, barrier->CreateCallback()); | 246 plugin_prefs->EnablePlugin(enable, file_path, barrier->CreateCallback()); |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 policy_enabled_plugin_patterns_ = enabled_patterns; | 536 policy_enabled_plugin_patterns_ = enabled_patterns; |
| 505 } | 537 } |
| 506 | 538 |
| 507 webkit::npapi::PluginList* PluginPrefs::GetPluginList() const { | 539 webkit::npapi::PluginList* PluginPrefs::GetPluginList() const { |
| 508 if (plugin_list_) | 540 if (plugin_list_) |
| 509 return plugin_list_; | 541 return plugin_list_; |
| 510 return PluginService::GetInstance()->GetPluginList(); | 542 return PluginService::GetInstance()->GetPluginList(); |
| 511 } | 543 } |
| 512 | 544 |
| 513 void PluginPrefs::GetPreferencesDataOnFileThread() { | 545 void PluginPrefs::GetPreferencesDataOnFileThread() { |
| 514 std::vector<webkit::npapi::PluginGroup> groups; | 546 PluginFinder::Get( |
| 547 base::Bind(&PluginPrefs::GetPluginFinderForGetPreferencesDataOnFileThread, |
| 548 this)); |
| 549 } |
| 515 | 550 |
| 551 void PluginPrefs::GetPluginFinderForGetPreferencesDataOnFileThread( |
| 552 PluginFinder* finder) { |
| 553 std::vector<webkit::WebPluginInfo> plugins; |
| 516 webkit::npapi::PluginList* plugin_list = GetPluginList(); | 554 webkit::npapi::PluginList* plugin_list = GetPluginList(); |
| 517 plugin_list->GetPluginGroups(false, &groups); | 555 plugin_list->GetPluginsNoRefresh(&plugins); |
| 518 | 556 |
| 519 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 557 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 520 base::Bind(&PluginPrefs::OnUpdatePreferences, this, groups)); | 558 base::Bind(&PluginPrefs::OnUpdatePreferences, this, plugins, finder)); |
| 521 } | 559 } |
| 522 | 560 |
| 523 void PluginPrefs::OnUpdatePreferences( | 561 void PluginPrefs::OnUpdatePreferences( |
| 524 const std::vector<webkit::npapi::PluginGroup>& groups) { | 562 const std::vector<webkit::WebPluginInfo>& plugins, |
| 563 PluginFinder* finder) { |
| 525 if (!prefs_) | 564 if (!prefs_) |
| 526 return; | 565 return; |
| 527 | 566 |
| 528 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); | 567 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); |
| 529 ListValue* plugins_list = update.Get(); | 568 ListValue* plugins_list = update.Get(); |
| 530 plugins_list->Clear(); | 569 plugins_list->Clear(); |
| 531 | 570 |
| 532 FilePath internal_dir; | 571 FilePath internal_dir; |
| 533 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir)) | 572 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir)) |
| 534 prefs_->SetFilePath(prefs::kPluginsLastInternalDirectory, internal_dir); | 573 prefs_->SetFilePath(prefs::kPluginsLastInternalDirectory, internal_dir); |
| 535 | 574 |
| 536 base::AutoLock auto_lock(lock_); | 575 base::AutoLock auto_lock(lock_); |
| 537 | 576 |
| 577 // Add the plugin files. |
| 578 std::set<string16> group_names; |
| 579 for (size_t i = 0; i < plugins.size(); ++i) { |
| 580 DictionaryValue* summary = new DictionaryValue(); |
| 581 summary->SetString("path", plugins[i].path.value()); |
| 582 summary->SetString("name", plugins[i].name); |
| 583 summary->SetString("version", plugins[i].version); |
| 584 bool enabled = true; |
| 585 std::map<FilePath, bool>::iterator it = plugin_state_.find(plugins[i].path); |
| 586 if (it != plugin_state_.end()) |
| 587 enabled = it->second; |
| 588 summary->SetBoolean("enabled", enabled); |
| 589 plugins_list->Append(summary); |
| 590 |
| 591 PluginInstaller* installer = finder->GetPluginInstaller(plugins[i]); |
| 592 // Insert into a set of all group names. |
| 593 group_names.insert(installer->name()); |
| 594 } |
| 595 |
| 538 // Add the plug-in groups. | 596 // Add the plug-in groups. |
| 539 for (size_t i = 0; i < groups.size(); ++i) { | 597 for (std::set<string16>::const_iterator it = group_names.begin(); |
| 540 // Add the plugin files to the same list. | 598 it != group_names.end(); ++it) { |
| 541 const std::vector<webkit::WebPluginInfo>& plugins = | |
| 542 groups[i].web_plugin_infos(); | |
| 543 for (size_t j = 0; j < plugins.size(); ++j) { | |
| 544 DictionaryValue* summary = new DictionaryValue(); | |
| 545 summary->SetString("path", plugins[j].path.value()); | |
| 546 summary->SetString("name", plugins[j].name); | |
| 547 summary->SetString("version", plugins[j].version); | |
| 548 bool enabled = true; | |
| 549 std::map<FilePath, bool>::iterator it = | |
| 550 plugin_state_.find(plugins[j].path); | |
| 551 if (it != plugin_state_.end()) | |
| 552 enabled = it->second; | |
| 553 summary->SetBoolean("enabled", enabled); | |
| 554 plugins_list->Append(summary); | |
| 555 } | |
| 556 | |
| 557 DictionaryValue* summary = new DictionaryValue(); | 599 DictionaryValue* summary = new DictionaryValue(); |
| 558 string16 name = groups[i].GetGroupName(); | 600 summary->SetString("name", *it); |
| 559 summary->SetString("name", name); | |
| 560 bool enabled = true; | 601 bool enabled = true; |
| 561 std::map<string16, bool>::iterator it = | 602 std::map<string16, bool>::iterator gstate_it = |
| 562 plugin_group_state_.find(name); | 603 plugin_group_state_.find(*it); |
| 563 if (it != plugin_group_state_.end()) | 604 if (gstate_it != plugin_group_state_.end()) |
| 564 enabled = it->second; | 605 enabled = gstate_it->second; |
| 565 summary->SetBoolean("enabled", enabled); | 606 summary->SetBoolean("enabled", enabled); |
| 566 plugins_list->Append(summary); | 607 plugins_list->Append(summary); |
| 567 } | 608 } |
| 568 } | 609 } |
| 569 | 610 |
| 570 void PluginPrefs::NotifyPluginStatusChanged() { | 611 void PluginPrefs::NotifyPluginStatusChanged() { |
| 571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 612 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 572 content::NotificationService::current()->Notify( | 613 content::NotificationService::current()->Notify( |
| 573 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, | 614 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, |
| 574 content::Source<Profile>(profile_), | 615 content::Source<Profile>(profile_), |
| 575 content::NotificationService::NoDetails()); | 616 content::NotificationService::NoDetails()); |
| 576 } | 617 } |
| OLD | NEW |