Chromium Code Reviews| 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) { |
| 53 DCHECK(!callback_.is_null()); | 54 DCHECK(!callback_.is_null()); |
| 54 } | 55 } |
| 55 | 56 |
| 56 base::Closure CreateCallback() { | 57 base::Callback<void(bool)> CreateCallback() { |
| 57 outstanding_callbacks_++; | 58 outstanding_callbacks_++; |
| 58 return base::Bind(&CallbackBarrier::MaybeRunCallback, this); | 59 return base::Bind(&CallbackBarrier::MaybeRunCallback, this); |
| 59 } | 60 } |
| 60 | 61 |
| 61 private: | 62 private: |
| 62 friend class base::RefCountedThreadSafe<CallbackBarrier>; | 63 friend class base::RefCountedThreadSafe<CallbackBarrier>; |
| 63 | 64 |
| 64 ~CallbackBarrier() { | 65 ~CallbackBarrier() { |
| 65 DCHECK(callback_.is_null()); | 66 DCHECK(callback_.is_null()); |
| 66 } | 67 } |
| 67 | 68 |
| 68 void MaybeRunCallback() { | 69 void MaybeRunCallback(bool dummy) { |
|
Bernhard Bauer
2012/08/29 16:53:21
Naming this parameter "dummy" is a bit confusing,
ibraaaa
2012/08/29 17:37:53
If I didn't miss something:
I checked the callers
Bernhard Bauer
2012/08/29 18:10:17
What I meant was that it's weird to return an arbi
ibraaaa
2012/08/29 18:28:19
Ah, I see. My intention was not returning any valu
| |
| 69 DCHECK_GT(outstanding_callbacks_, 0); | 70 DCHECK_GT(outstanding_callbacks_, 0); |
| 70 if (--outstanding_callbacks_ == 0) { | 71 if (--outstanding_callbacks_ == 0) { |
| 71 callback_.Run(); | 72 callback_.Run(dummy); |
| 72 callback_.Reset(); | 73 callback_.Reset(); |
| 73 } | 74 } |
| 74 } | 75 } |
| 75 | 76 |
| 76 base::Closure callback_; | 77 base::Callback<void(bool)> callback_; |
| 77 int outstanding_callbacks_; | 78 int outstanding_callbacks_; |
| 78 }; | 79 }; |
| 79 | 80 |
| 80 } // namespace | 81 } // namespace |
| 81 | 82 |
| 82 // How long to wait to save the plugin enabled information, which might need to | 83 // How long to wait to save the plugin enabled information, which might need to |
| 83 // go to disk. | 84 // go to disk. |
| 84 #define kPluginUpdateDelayMs (60 * 1000) | 85 #define kPluginUpdateDelayMs (60 * 1000) |
| 85 | 86 |
| 86 // static | 87 // static |
| 87 scoped_refptr<PluginPrefs> PluginPrefs::GetForProfile(Profile* profile) { | 88 scoped_refptr<PluginPrefs> PluginPrefs::GetForProfile(Profile* profile) { |
| 88 return PluginPrefsFactory::GetPrefsForProfile(profile); | 89 return PluginPrefsFactory::GetPrefsForProfile(profile); |
| 89 } | 90 } |
| 90 | 91 |
| 91 // static | 92 // static |
| 92 scoped_refptr<PluginPrefs> PluginPrefs::GetForTestingProfile( | 93 scoped_refptr<PluginPrefs> PluginPrefs::GetForTestingProfile( |
| 93 Profile* profile) { | 94 Profile* profile) { |
| 94 return static_cast<PluginPrefs*>( | 95 return static_cast<PluginPrefs*>( |
| 95 PluginPrefsFactory::GetInstance()->SetTestingFactoryAndUse( | 96 PluginPrefsFactory::GetInstance()->SetTestingFactoryAndUse( |
| 96 profile, &PluginPrefsFactory::CreateForTestingProfile).get()); | 97 profile, &PluginPrefsFactory::CreateForTestingProfile).get()); |
| 97 } | 98 } |
| 98 | 99 |
| 99 void PluginPrefs::SetPluginListForTesting( | 100 void PluginPrefs::SetPluginListForTesting( |
| 100 webkit::npapi::PluginList* plugin_list) { | 101 webkit::npapi::PluginList* plugin_list) { |
| 101 plugin_list_ = plugin_list; | 102 plugin_list_ = plugin_list; |
| 102 } | 103 } |
| 103 | 104 |
| 104 void PluginPrefs::EnablePluginGroup(bool enabled, const string16& group_name) { | 105 void PluginPrefs::EnablePluginGroup(bool enabled, const string16& group_name) { |
| 105 PluginService::GetInstance()->GetPluginGroups( | 106 PluginFinder::Get( |
| 106 base::Bind(&PluginPrefs::EnablePluginGroupInternal, | 107 base::Bind(&PluginPrefs::GetPluginFinderForEnablePluginGroup, |
| 107 this, enabled, group_name)); | 108 this, enabled, group_name)); |
| 109 } | |
| 110 | |
| 111 void PluginPrefs::GetPluginFinderForEnablePluginGroup( | |
| 112 bool enabled, | |
| 113 const string16& group_name, | |
| 114 PluginFinder* finder) { | |
| 115 PluginService::GetInstance()->GetPlugins( | |
| 116 base::Bind(&PluginPrefs::EnablePluginGroupInternal, | |
| 117 this, enabled, group_name, finder)); | |
| 108 } | 118 } |
| 109 | 119 |
| 110 void PluginPrefs::EnablePluginGroupInternal( | 120 void PluginPrefs::EnablePluginGroupInternal( |
| 111 bool enabled, | 121 bool enabled, |
| 112 const string16& group_name, | 122 const string16& group_name, |
| 113 const std::vector<webkit::npapi::PluginGroup>& groups) { | 123 PluginFinder* finder, |
| 124 const std::vector<webkit::WebPluginInfo>& plugins) { | |
| 114 base::AutoLock auto_lock(lock_); | 125 base::AutoLock auto_lock(lock_); |
| 115 | 126 |
| 116 // Set the desired state for the group. | 127 // Set the desired state for the group. |
| 117 plugin_group_state_[group_name] = enabled; | 128 plugin_group_state_[group_name] = enabled; |
| 118 | 129 |
| 119 // Update the state for all plug-ins in the group. | 130 // Update the state for all plug-ins in the group. |
| 120 for (size_t i = 0; i < groups.size(); ++i) { | 131 for (size_t i = 0; i < plugins.size(); ++i) { |
| 121 if (groups[i].GetGroupName() != group_name) | 132 PluginInstaller* installer = finder->GetPluginInstaller(plugins[i]); |
| 133 if (group_name != installer->name()) | |
| 122 continue; | 134 continue; |
| 123 const std::vector<webkit::WebPluginInfo>& plugins = | 135 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 } | 136 } |
| 129 | 137 |
| 130 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 138 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 131 base::Bind(&PluginPrefs::OnUpdatePreferences, this, groups)); | 139 base::Bind(&PluginPrefs::OnUpdatePreferences, this, plugins, finder)); |
| 132 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 140 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 133 base::Bind(&PluginPrefs::NotifyPluginStatusChanged, this)); | 141 base::Bind(&PluginPrefs::NotifyPluginStatusChanged, this)); |
| 134 } | 142 } |
| 135 | 143 |
| 136 bool PluginPrefs::CanEnablePlugin(bool enabled, const FilePath& path) { | 144 void PluginPrefs::EnablePluginIfPossibleCallback( |
| 137 webkit::npapi::PluginList* plugin_list = GetPluginList(); | 145 bool enabled, const FilePath& path, |
| 146 const base::Callback<void(bool)>& callback, | |
| 147 PluginFinder* finder) { | |
| 138 webkit::WebPluginInfo plugin; | 148 webkit::WebPluginInfo plugin; |
| 149 bool can_enable = true; | |
| 139 if (PluginService::GetInstance()->GetPluginInfoByPath(path, &plugin)) { | 150 if (PluginService::GetInstance()->GetPluginInfoByPath(path, &plugin)) { |
| 140 scoped_ptr<webkit::npapi::PluginGroup> group( | 151 PluginInstaller* installer = finder->GetPluginInstaller(plugin); |
| 141 plugin_list->GetPluginGroup(plugin)); | |
| 142 PolicyStatus plugin_status = PolicyStatusForPlugin(plugin.name); | 152 PolicyStatus plugin_status = PolicyStatusForPlugin(plugin.name); |
| 143 PolicyStatus group_status = PolicyStatusForPlugin(group->GetGroupName()); | 153 PolicyStatus group_status = PolicyStatusForPlugin(installer->name()); |
| 144 if (enabled) { | 154 if (enabled) { |
| 145 if (plugin_status == POLICY_DISABLED || group_status == POLICY_DISABLED) | 155 if (plugin_status == POLICY_DISABLED || group_status == POLICY_DISABLED) |
| 146 return false; | 156 can_enable = false; |
| 147 } else { | 157 } else { |
| 148 if (plugin_status == POLICY_ENABLED || group_status == POLICY_ENABLED) | 158 if (plugin_status == POLICY_ENABLED || group_status == POLICY_ENABLED) |
| 149 return false; | 159 can_enable = false; |
| 150 } | 160 } |
| 151 } else { | 161 } else { |
| 152 NOTREACHED(); | 162 NOTREACHED(); |
| 153 } | 163 } |
| 154 return true; | 164 |
| 165 if (!can_enable) { | |
| 166 callback.Run(false); | |
| 167 return; | |
| 168 } | |
| 169 | |
| 170 PluginService::GetInstance()->GetPlugins( | |
| 171 base::Bind(&PluginPrefs::EnablePluginInternal, this, | |
| 172 enabled, path, finder, callback)); | |
| 155 } | 173 } |
| 156 | 174 |
| 157 void PluginPrefs::EnablePlugin(bool enabled, const FilePath& path, | 175 void PluginPrefs::EnablePlugin( |
| 158 const base::Closure& callback) { | 176 bool enabled, const FilePath& path, |
| 159 PluginService::GetInstance()->GetPluginGroups( | 177 const base::Callback<void(bool)>& callback) { |
| 160 base::Bind(&PluginPrefs::EnablePluginInternal, this, | 178 PluginFinder::Get(base::Bind(&PluginPrefs::EnablePluginIfPossibleCallback, |
| 161 enabled, path, callback)); | 179 this, enabled, path, callback)); |
| 162 } | 180 } |
| 163 | 181 |
| 164 void PluginPrefs::EnablePluginInternal( | 182 void PluginPrefs::EnablePluginInternal( |
| 165 bool enabled, | 183 bool enabled, |
| 166 const FilePath& path, | 184 const FilePath& path, |
| 167 const base::Closure& callback, | 185 PluginFinder* plugin_finder, |
| 168 const std::vector<webkit::npapi::PluginGroup>& groups) { | 186 const base::Callback<void(bool)>& callback, |
| 187 const std::vector<webkit::WebPluginInfo>& plugins) { | |
| 169 { | 188 { |
| 170 // Set the desired state for the plug-in. | 189 // Set the desired state for the plug-in. |
| 171 base::AutoLock auto_lock(lock_); | 190 base::AutoLock auto_lock(lock_); |
| 172 plugin_state_[path] = enabled; | 191 plugin_state_[path] = enabled; |
| 173 } | 192 } |
| 174 | 193 |
| 175 bool found_group = false; | 194 string16 group_name; |
| 176 for (size_t i = 0; i < groups.size(); ++i) { | 195 for (size_t i = 0; i < plugins.size(); ++i) { |
| 177 bool all_disabled = true; | 196 if (plugins[i].path == path) { |
| 178 const std::vector<webkit::WebPluginInfo>& plugins = | 197 PluginInstaller* installer = |
| 179 groups[i].web_plugin_infos(); | 198 plugin_finder->GetPluginInstaller(plugins[i]); |
| 180 for (size_t j = 0; j < plugins.size(); ++j) { | 199 // set the group name for this plug-in. |
| 181 all_disabled = all_disabled && !IsPluginEnabled(plugins[j]); | 200 group_name = installer->name(); |
| 182 if (plugins[j].path == path) { | 201 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; | 202 break; |
| 192 } | 203 } |
| 193 } | 204 } |
| 194 | 205 |
| 206 bool all_disabled = true; | |
| 207 for (size_t i = 0; i < plugins.size(); ++i) { | |
| 208 PluginInstaller* installer = plugin_finder->GetPluginInstaller(plugins[i]); | |
| 209 DCHECK(!installer->name().empty()); | |
| 210 if (group_name == installer->name()) { | |
| 211 all_disabled = all_disabled && !IsPluginEnabled(plugins[i]); | |
| 212 } | |
| 213 } | |
| 214 | |
| 215 if (!group_name.empty()) { | |
| 216 // Update the state for the corresponding plug-in group. | |
| 217 base::AutoLock auto_lock(lock_); | |
| 218 plugin_group_state_[group_name] = !all_disabled; | |
| 219 } | |
| 220 | |
| 195 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 221 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 196 base::Bind(&PluginPrefs::OnUpdatePreferences, this, groups)); | 222 base::Bind(&PluginPrefs::OnUpdatePreferences, this, |
| 223 plugins, plugin_finder)); | |
| 197 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 224 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 198 base::Bind(&PluginPrefs::NotifyPluginStatusChanged, this)); | 225 base::Bind(&PluginPrefs::NotifyPluginStatusChanged, this)); |
| 199 callback.Run(); | 226 callback.Run(true); |
| 200 } | 227 } |
| 201 | 228 |
| 202 // static | 229 // static |
| 203 void PluginPrefs::EnablePluginGlobally(bool enable, const FilePath& file_path, | 230 void PluginPrefs::EnablePluginGlobally( |
| 204 const base::Closure& callback) { | 231 bool enable, |
| 232 const FilePath& file_path, | |
| 233 const base::Callback<void(bool)>& callback) { | |
| 205 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 206 g_default_plugin_state.Get()[file_path] = enable; | 235 g_default_plugin_state.Get()[file_path] = enable; |
| 207 std::vector<Profile*> profiles = | 236 std::vector<Profile*> profiles = |
| 208 g_browser_process->profile_manager()->GetLoadedProfiles(); | 237 g_browser_process->profile_manager()->GetLoadedProfiles(); |
| 209 scoped_refptr<CallbackBarrier> barrier = new CallbackBarrier(callback); | 238 scoped_refptr<CallbackBarrier> barrier = new CallbackBarrier(callback); |
| 210 for (std::vector<Profile*>::iterator it = profiles.begin(); | 239 for (std::vector<Profile*>::iterator it = profiles.begin(); |
| 211 it != profiles.end(); ++it) { | 240 it != profiles.end(); ++it) { |
| 212 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(*it); | 241 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(*it); |
| 213 DCHECK(plugin_prefs); | 242 DCHECK(plugin_prefs); |
| 214 plugin_prefs->EnablePlugin(enable, file_path, barrier->CreateCallback()); | 243 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; | 533 policy_enabled_plugin_patterns_ = enabled_patterns; |
| 505 } | 534 } |
| 506 | 535 |
| 507 webkit::npapi::PluginList* PluginPrefs::GetPluginList() const { | 536 webkit::npapi::PluginList* PluginPrefs::GetPluginList() const { |
| 508 if (plugin_list_) | 537 if (plugin_list_) |
| 509 return plugin_list_; | 538 return plugin_list_; |
| 510 return PluginService::GetInstance()->GetPluginList(); | 539 return PluginService::GetInstance()->GetPluginList(); |
| 511 } | 540 } |
| 512 | 541 |
| 513 void PluginPrefs::GetPreferencesDataOnFileThread() { | 542 void PluginPrefs::GetPreferencesDataOnFileThread() { |
| 514 std::vector<webkit::npapi::PluginGroup> groups; | 543 PluginFinder::Get( |
| 544 base::Bind(&PluginPrefs::GetPluginFinderForGetPreferencesDataOnFileThread, | |
| 545 this)); | |
| 546 } | |
| 515 | 547 |
| 548 void PluginPrefs::GetPluginFinderForGetPreferencesDataOnFileThread( | |
| 549 PluginFinder* finder) { | |
| 550 std::vector<webkit::WebPluginInfo> plugins; | |
| 516 webkit::npapi::PluginList* plugin_list = GetPluginList(); | 551 webkit::npapi::PluginList* plugin_list = GetPluginList(); |
| 517 plugin_list->GetPluginGroups(false, &groups); | 552 plugin_list->GetPluginsNoRefresh(&plugins); |
| 518 | 553 |
| 519 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 554 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 520 base::Bind(&PluginPrefs::OnUpdatePreferences, this, groups)); | 555 base::Bind(&PluginPrefs::OnUpdatePreferences, this, plugins, finder)); |
| 521 } | 556 } |
| 522 | 557 |
| 523 void PluginPrefs::OnUpdatePreferences( | 558 void PluginPrefs::OnUpdatePreferences( |
| 524 const std::vector<webkit::npapi::PluginGroup>& groups) { | 559 const std::vector<webkit::WebPluginInfo>& plugins, |
| 560 PluginFinder* finder) { | |
| 525 if (!prefs_) | 561 if (!prefs_) |
| 526 return; | 562 return; |
| 527 | 563 |
| 528 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); | 564 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); |
| 529 ListValue* plugins_list = update.Get(); | 565 ListValue* plugins_list = update.Get(); |
| 530 plugins_list->Clear(); | 566 plugins_list->Clear(); |
| 531 | 567 |
| 532 FilePath internal_dir; | 568 FilePath internal_dir; |
| 533 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir)) | 569 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir)) |
| 534 prefs_->SetFilePath(prefs::kPluginsLastInternalDirectory, internal_dir); | 570 prefs_->SetFilePath(prefs::kPluginsLastInternalDirectory, internal_dir); |
| 535 | 571 |
| 536 base::AutoLock auto_lock(lock_); | 572 base::AutoLock auto_lock(lock_); |
| 537 | 573 |
| 574 // Add the plugin files. | |
| 575 std::set<string16> group_names; | |
| 576 for (size_t i = 0; i < plugins.size(); ++i) { | |
| 577 DictionaryValue* summary = new DictionaryValue(); | |
| 578 summary->SetString("path", plugins[i].path.value()); | |
| 579 summary->SetString("name", plugins[i].name); | |
| 580 summary->SetString("version", plugins[i].version); | |
| 581 bool enabled = true; | |
| 582 std::map<FilePath, bool>::iterator it = plugin_state_.find(plugins[i].path); | |
| 583 if (it != plugin_state_.end()) | |
| 584 enabled = it->second; | |
| 585 summary->SetBoolean("enabled", enabled); | |
| 586 plugins_list->Append(summary); | |
| 587 | |
| 588 PluginInstaller* installer = finder->GetPluginInstaller(plugins[i]); | |
| 589 // Insert into a set of all group names. | |
| 590 group_names.insert(installer->name()); | |
| 591 } | |
| 592 | |
| 538 // Add the plug-in groups. | 593 // Add the plug-in groups. |
| 539 for (size_t i = 0; i < groups.size(); ++i) { | 594 for (std::set<string16>::const_iterator it = group_names.begin(); |
| 540 // Add the plugin files to the same list. | 595 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(); | 596 DictionaryValue* summary = new DictionaryValue(); |
| 558 string16 name = groups[i].GetGroupName(); | 597 summary->SetString("name", *it); |
| 559 summary->SetString("name", name); | |
| 560 bool enabled = true; | 598 bool enabled = true; |
| 561 std::map<string16, bool>::iterator it = | 599 std::map<string16, bool>::iterator gstate_it = |
| 562 plugin_group_state_.find(name); | 600 plugin_group_state_.find(*it); |
| 563 if (it != plugin_group_state_.end()) | 601 if (gstate_it != plugin_group_state_.end()) |
| 564 enabled = it->second; | 602 enabled = gstate_it->second; |
| 565 summary->SetBoolean("enabled", enabled); | 603 summary->SetBoolean("enabled", enabled); |
| 566 plugins_list->Append(summary); | 604 plugins_list->Append(summary); |
| 567 } | 605 } |
| 568 } | 606 } |
| 569 | 607 |
| 570 void PluginPrefs::NotifyPluginStatusChanged() { | 608 void PluginPrefs::NotifyPluginStatusChanged() { |
| 571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 609 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 572 content::NotificationService::current()->Notify( | 610 content::NotificationService::current()->Notify( |
| 573 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, | 611 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, |
| 574 content::Source<Profile>(profile_), | 612 content::Source<Profile>(profile_), |
| 575 content::NotificationService::NoDetails()); | 613 content::NotificationService::NoDetails()); |
| 576 } | 614 } |
| OLD | NEW |