Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 return plugin_groups_data; | 56 return plugin_groups_data; |
| 57 } | 57 } |
| 58 | 58 |
| 59 void PluginUpdater::EnablePluginGroup(bool enable, const string16& group_name) { | 59 void PluginUpdater::EnablePluginGroup(bool enable, const string16& group_name) { |
| 60 if (PluginGroup::IsPluginNameDisabledByPolicy(group_name)) | 60 if (PluginGroup::IsPluginNameDisabledByPolicy(group_name)) |
| 61 enable = false; | 61 enable = false; |
| 62 NPAPI::PluginList::Singleton()->EnableGroup(enable, group_name); | 62 NPAPI::PluginList::Singleton()->EnableGroup(enable, group_name); |
| 63 NotifyPluginStatusChanged(); | 63 NotifyPluginStatusChanged(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void PluginUpdater::EnablePluginFile(bool enable, | 66 void PluginUpdater::EnablePlugin(bool enable, |
| 67 const FilePath::StringType& path) { | 67 const FilePath::StringType& path, |
| 68 const string16& name) { | |
| 68 FilePath file_path(path); | 69 FilePath file_path(path); |
| 69 if (enable && !PluginGroup::IsPluginPathDisabledByPolicy(file_path)) | 70 if (enable) |
| 70 NPAPI::PluginList::Singleton()->EnablePlugin(file_path); | 71 NPAPI::PluginList::Singleton()->EnablePlugin(file_path, name); |
| 71 else | 72 else |
| 72 NPAPI::PluginList::Singleton()->DisablePlugin(file_path); | 73 NPAPI::PluginList::Singleton()->DisablePlugin(file_path, name); |
| 73 | 74 |
| 74 NotifyPluginStatusChanged(); | 75 NotifyPluginStatusChanged(); |
| 75 } | 76 } |
| 76 | 77 |
| 77 void PluginUpdater::Observe(NotificationType type, | 78 void PluginUpdater::Observe(NotificationType type, |
| 78 const NotificationSource& source, | 79 const NotificationSource& source, |
| 79 const NotificationDetails& details) { | 80 const NotificationDetails& details) { |
| 80 DCHECK_EQ(NotificationType::PREF_CHANGED, type.value); | 81 DCHECK_EQ(NotificationType::PREF_CHANGED, type.value); |
| 81 const std::string* pref_name = Details<std::string>(details).ptr(); | 82 const std::string* pref_name = Details<std::string>(details).ptr(); |
| 82 if (!pref_name) { | 83 if (!pref_name) { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 found_internal_pdf = true; | 183 found_internal_pdf = true; |
| 183 if (!enabled) { | 184 if (!enabled) { |
| 184 if (force_enable_internal_pdf) { | 185 if (force_enable_internal_pdf) { |
| 185 enabled = true; | 186 enabled = true; |
| 186 plugin->SetBoolean("enabled", true); | 187 plugin->SetBoolean("enabled", true); |
| 187 } else if (force_internal_pdf_for_this_run) { | 188 } else if (force_internal_pdf_for_this_run) { |
| 188 enabled = true; | 189 enabled = true; |
| 189 } | 190 } |
| 190 } | 191 } |
| 191 } | 192 } |
| 192 if (!enabled) | 193 if (!enabled) { |
| 193 NPAPI::PluginList::Singleton()->DisablePlugin(plugin_path); | 194 string16 name; |
| 195 plugin->GetString("name", &name); | |
| 196 NPAPI::PluginList::Singleton()->DisablePlugin(plugin_path, name); | |
| 197 } | |
| 194 } else if (!enabled && plugin->GetString("name", &group_name)) { | 198 } else if (!enabled && plugin->GetString("name", &group_name)) { |
| 195 // Don't disable this group if it's for the pdf plugin and we just | 199 // Don't disable this group if it's for the pdf plugin and we just |
| 196 // forced it on. | 200 // forced it on. |
| 197 if (force_enable_internal_pdf && pdf_group_name == group_name) | 201 if (force_enable_internal_pdf && pdf_group_name == group_name) |
| 198 continue; | 202 continue; |
| 199 | 203 |
| 200 // Otherwise this is a list of groups. | 204 // Otherwise this is a list of groups. |
| 201 EnablePluginGroup(false, group_name); | 205 EnablePluginGroup(false, group_name); |
| 202 } | 206 } |
| 203 } | 207 } |
| 204 } | 208 } |
| 205 | 209 |
| 206 // Build the set of policy-disabled plugin patterns once and cache it. | 210 // Build the set of policy-disabled plugin patterns once and cache it. |
| 207 // Don't do this in the constructor, there's no profile available there. | 211 // Don't do this in the constructor, there's no profile available there. |
| 208 const ListValue* plugin_blacklist = | 212 const ListValue* plugin_blacklist = |
| 209 profile->GetPrefs()->GetList(prefs::kPluginsPluginsBlacklist); | 213 profile->GetPrefs()->GetList(prefs::kPluginsPluginsBlacklist); |
| 210 DisablePluginsFromPolicy(plugin_blacklist); | 214 DisablePluginsFromPolicy(plugin_blacklist); |
| 211 | 215 |
| 212 if ((!enable_internal_pdf_ && !found_internal_pdf) && | 216 if ((!enable_internal_pdf_ && !found_internal_pdf) && |
| 213 !force_internal_pdf_for_this_run) { | 217 !force_internal_pdf_for_this_run) { |
| 214 // The internal PDF plugin is disabled by default, and the user hasn't | 218 // The internal PDF plugin is disabled by default, and the user hasn't |
| 215 // overridden the default. | 219 // overridden the default. |
| 216 NPAPI::PluginList::Singleton()->DisablePlugin(pdf_path); | 220 NPAPI::PluginList::Singleton()->DisablePlugin(pdf_path, pdf_group_name); |
| 217 EnablePluginGroup(false, pdf_group_name); | 221 EnablePluginGroup(false, pdf_group_name); |
| 218 } | 222 } |
| 219 | 223 |
| 220 if (force_enable_internal_pdf) { | 224 if (force_enable_internal_pdf) { |
| 221 // See http://crbug.com/50105 for background. | 225 // See http://crbug.com/50105 for background. |
| 222 EnablePluginGroup(false, ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); | 226 EnablePluginGroup(false, ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); |
| 223 | 227 |
| 224 // We want to save this, but doing so requires loading the list of plugins, | 228 // We want to save this, but doing so requires loading the list of plugins, |
| 225 // so do it after a minute as to not impact startup performance. Note that | 229 // so do it after a minute as to not impact startup performance. Note that |
| 226 // plugins are loaded after 30s by the metrics service. | 230 // plugins are loaded after 30s by the metrics service. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 239 void PluginUpdater::GetPreferencesDataOnFileThread(void* profile) { | 243 void PluginUpdater::GetPreferencesDataOnFileThread(void* profile) { |
| 240 std::vector<WebPluginInfo> plugins; | 244 std::vector<WebPluginInfo> plugins; |
| 241 NPAPI::PluginList::Singleton()->GetPlugins(false, &plugins); | 245 NPAPI::PluginList::Singleton()->GetPlugins(false, &plugins); |
| 242 | 246 |
| 243 std::vector<PluginGroup> groups; | 247 std::vector<PluginGroup> groups; |
| 244 NPAPI::PluginList::Singleton()->GetPluginGroups(false, &groups); | 248 NPAPI::PluginList::Singleton()->GetPluginGroups(false, &groups); |
| 245 | 249 |
| 246 BrowserThread::PostTask( | 250 BrowserThread::PostTask( |
| 247 BrowserThread::UI, | 251 BrowserThread::UI, |
| 248 FROM_HERE, | 252 FROM_HERE, |
| 249 NewRunnableFunction( | 253 NewRunnableFunction(&PluginUpdater::OnUpdatePreferences, |
| 250 &PluginUpdater::OnUpdatePreferences, | 254 static_cast<Profile*>(profile), |
| 251 static_cast<Profile*>(profile), plugins, groups)); | 255 plugins, groups)); |
| 252 } | 256 } |
| 253 | 257 |
| 254 void PluginUpdater::OnUpdatePreferences( | 258 void PluginUpdater::OnUpdatePreferences( |
| 255 Profile* profile, | 259 Profile* profile, |
| 256 const std::vector<WebPluginInfo>& plugins, | 260 const std::vector<WebPluginInfo>& plugins, |
| 257 const std::vector<PluginGroup>& groups) { | 261 const std::vector<PluginGroup>& groups) { |
| 258 ListValue* plugins_list = profile->GetPrefs()->GetMutableList( | 262 ListValue* plugins_list = profile->GetPrefs()->GetMutableList( |
| 259 prefs::kPluginsPluginsList); | 263 prefs::kPluginsPluginsList); |
| 260 plugins_list->Clear(); | 264 plugins_list->Clear(); |
| 261 | 265 |
| 262 FilePath internal_dir; | 266 FilePath internal_dir; |
| 263 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir)) | 267 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir)) |
| 264 profile->GetPrefs()->SetFilePath(prefs::kPluginsLastInternalDirectory, | 268 profile->GetPrefs()->SetFilePath(prefs::kPluginsLastInternalDirectory, |
| 265 internal_dir); | 269 internal_dir); |
| 266 | 270 |
| 267 // Add the plugin files. | 271 // Add the plugin files. |
| 268 for (std::vector<WebPluginInfo>::const_iterator it = plugins.begin(); | 272 for (std::vector<WebPluginInfo>::const_iterator it = plugins.begin(); |
| 269 it != plugins.end(); | 273 it != plugins.end(); |
| 270 ++it) { | 274 ++it) { |
| 271 plugins_list->Append(CreatePluginFileSummary(*it)); | 275 DictionaryValue* summary = CreatePluginFileSummary(*it); |
| 276 // If the plugin is disabled only by policy don't store this state in the | |
| 277 // user pref store. | |
| 278 if (!it->IsEnabled() && it->reason == WebPluginInfo::MANAGED) | |
| 279 summary->SetBoolean("enabled", true); | |
| 280 plugins_list->Append(summary); | |
| 272 } | 281 } |
| 273 | 282 |
| 274 // Add the groups as well. | 283 // Add the groups as well. |
| 275 for (size_t i = 0; i < groups.size(); ++i) { | 284 for (std::vector<PluginGroup>::const_iterator it = groups.begin(); |
|
jam
2010/12/17 19:14:45
the old code using a size_t instead of an iterator
pastarmovj
2010/12/20 19:57:37
Done.
| |
| 276 plugins_list->Append(groups[i].GetSummary()); | 285 it != groups.end(); |
| 286 ++it) { | |
| 287 DictionaryValue* summary = it->GetSummary(); | |
| 288 // If the plugin is disabled only by policy don't store this state in the | |
| 289 // user pref store. | |
| 290 if (!it->Enabled() && | |
| 291 PluginGroup::IsPluginNameDisabledByPolicy(it->GetGroupName())) | |
| 292 summary->SetBoolean("enabled", true); | |
| 293 plugins_list->Append(summary); | |
| 277 } | 294 } |
| 278 } | 295 } |
| 279 | 296 |
| 280 void PluginUpdater::NotifyPluginStatusChanged() { | 297 void PluginUpdater::NotifyPluginStatusChanged() { |
| 281 if (notify_pending_) | 298 if (notify_pending_) |
| 282 return; | 299 return; |
| 283 notify_pending_ = true; | 300 notify_pending_ = true; |
| 284 MessageLoop::current()->PostTask( | 301 MessageLoop::current()->PostTask( |
| 285 FROM_HERE, | 302 FROM_HERE, |
| 286 NewRunnableFunction(&PluginUpdater::OnNotifyPluginStatusChanged)); | 303 NewRunnableFunction(&PluginUpdater::OnNotifyPluginStatusChanged)); |
| 287 } | 304 } |
| 288 | 305 |
| 289 void PluginUpdater::OnNotifyPluginStatusChanged() { | 306 void PluginUpdater::OnNotifyPluginStatusChanged() { |
| 290 GetInstance()->notify_pending_ = false; | 307 GetInstance()->notify_pending_ = false; |
| 291 NotificationService::current()->Notify( | 308 NotificationService::current()->Notify( |
| 292 NotificationType::PLUGIN_ENABLE_STATUS_CHANGED, | 309 NotificationType::PLUGIN_ENABLE_STATUS_CHANGED, |
| 293 Source<PluginUpdater>(GetInstance()), | 310 Source<PluginUpdater>(GetInstance()), |
| 294 NotificationService::NoDetails()); | 311 NotificationService::NoDetails()); |
| 295 } | 312 } |
| 296 | 313 |
| 297 /*static*/ | 314 /*static*/ |
| 298 PluginUpdater* PluginUpdater::GetInstance() { | 315 PluginUpdater* PluginUpdater::GetInstance() { |
| 299 return Singleton<PluginUpdater>::get(); | 316 return Singleton<PluginUpdater>::get(); |
| 300 } | 317 } |
| OLD | NEW |