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" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "base/version.h" | 16 #include "base/version.h" |
17 #include "chrome/browser/browser_thread.h" | 17 #include "chrome/browser/browser_thread.h" |
18 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/notification_service.h" | 22 #include "chrome/common/notification_service.h" |
23 #include "chrome/common/pepper_plugin_registry.h" | 23 #include "chrome/common/pepper_plugin_registry.h" |
24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
25 #include "webkit/glue/plugins/webplugininfo.h" | 25 #include "webkit/plugins/npapi/plugin_list.h" |
| 26 #include "webkit/plugins/npapi/webplugininfo.h" |
26 | 27 |
27 // How long to wait to save the plugin enabled information, which might need to | 28 // How long to wait to save the plugin enabled information, which might need to |
28 // go to disk. | 29 // go to disk. |
29 #define kPluginUpdateDelayMs (60 * 1000) | 30 #define kPluginUpdateDelayMs (60 * 1000) |
30 | 31 |
31 PluginUpdater::PluginUpdater() | 32 PluginUpdater::PluginUpdater() |
32 : enable_internal_pdf_(true), | 33 : enable_internal_pdf_(true), |
33 notify_pending_(false) { | 34 notify_pending_(false) { |
34 } | 35 } |
35 | 36 |
36 DictionaryValue* PluginUpdater::CreatePluginFileSummary( | 37 DictionaryValue* PluginUpdater::CreatePluginFileSummary( |
37 const WebPluginInfo& plugin) { | 38 const webkit::npapi::WebPluginInfo& plugin) { |
38 DictionaryValue* data = new DictionaryValue(); | 39 DictionaryValue* data = new DictionaryValue(); |
39 data->SetString("path", plugin.path.value()); | 40 data->SetString("path", plugin.path.value()); |
40 data->SetString("name", plugin.name); | 41 data->SetString("name", plugin.name); |
41 data->SetString("version", plugin.version); | 42 data->SetString("version", plugin.version); |
42 data->SetBoolean("enabled", plugin.enabled); | 43 data->SetBoolean("enabled", plugin.enabled); |
43 return data; | 44 return data; |
44 } | 45 } |
45 | 46 |
46 // static | 47 // static |
47 ListValue* PluginUpdater::GetPluginGroupsData() { | 48 ListValue* PluginUpdater::GetPluginGroupsData() { |
48 std::vector<PluginGroup> plugin_groups; | 49 std::vector<webkit::npapi::PluginGroup> plugin_groups; |
49 NPAPI::PluginList::Singleton()->GetPluginGroups(true, &plugin_groups); | 50 webkit::npapi::PluginList::Singleton()->GetPluginGroups(true, &plugin_groups); |
50 | 51 |
51 // Construct DictionaryValues to return to the UI | 52 // Construct DictionaryValues to return to the UI |
52 ListValue* plugin_groups_data = new ListValue(); | 53 ListValue* plugin_groups_data = new ListValue(); |
53 for (size_t i = 0; i < plugin_groups.size(); ++i) { | 54 for (size_t i = 0; i < plugin_groups.size(); ++i) { |
54 plugin_groups_data->Append(plugin_groups[i].GetDataForUI()); | 55 plugin_groups_data->Append(plugin_groups[i].GetDataForUI()); |
55 } | 56 } |
56 return plugin_groups_data; | 57 return plugin_groups_data; |
57 } | 58 } |
58 | 59 |
59 void PluginUpdater::EnablePluginGroup(bool enable, const string16& group_name) { | 60 void PluginUpdater::EnablePluginGroup(bool enable, const string16& group_name) { |
60 if (PluginGroup::IsPluginNameDisabledByPolicy(group_name)) | 61 if (webkit::npapi::PluginGroup::IsPluginNameDisabledByPolicy(group_name)) |
61 enable = false; | 62 enable = false; |
62 NPAPI::PluginList::Singleton()->EnableGroup(enable, group_name); | 63 webkit::npapi::PluginList::Singleton()->EnableGroup(enable, group_name); |
63 NotifyPluginStatusChanged(); | 64 NotifyPluginStatusChanged(); |
64 } | 65 } |
65 | 66 |
66 void PluginUpdater::EnablePluginFile(bool enable, | 67 void PluginUpdater::EnablePluginFile(bool enable, |
67 const FilePath::StringType& path) { | 68 const FilePath::StringType& path) { |
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 !webkit::npapi::PluginGroup::IsPluginPathDisabledByPolicy(file_path)) |
| 72 webkit::npapi::PluginList::Singleton()->EnablePlugin(file_path); |
71 else | 73 else |
72 NPAPI::PluginList::Singleton()->DisablePlugin(file_path); | 74 webkit::npapi::PluginList::Singleton()->DisablePlugin(file_path); |
73 | 75 |
74 NotifyPluginStatusChanged(); | 76 NotifyPluginStatusChanged(); |
75 } | 77 } |
76 | 78 |
77 void PluginUpdater::Observe(NotificationType type, | 79 void PluginUpdater::Observe(NotificationType type, |
78 const NotificationSource& source, | 80 const NotificationSource& source, |
79 const NotificationDetails& details) { | 81 const NotificationDetails& details) { |
80 DCHECK_EQ(NotificationType::PREF_CHANGED, type.value); | 82 DCHECK_EQ(NotificationType::PREF_CHANGED, type.value); |
81 const std::string* pref_name = Details<std::string>(details).ptr(); | 83 const std::string* pref_name = Details<std::string>(details).ptr(); |
82 if (!pref_name) { | 84 if (!pref_name) { |
(...skipping 15 matching lines...) Expand all Loading... |
98 if (plugin_names) { | 100 if (plugin_names) { |
99 ListValue::const_iterator end(plugin_names->end()); | 101 ListValue::const_iterator end(plugin_names->end()); |
100 for (ListValue::const_iterator current(plugin_names->begin()); | 102 for (ListValue::const_iterator current(plugin_names->begin()); |
101 current != end; ++current) { | 103 current != end; ++current) { |
102 string16 plugin_name; | 104 string16 plugin_name; |
103 if ((*current)->GetAsString(&plugin_name)) { | 105 if ((*current)->GetAsString(&plugin_name)) { |
104 policy_disabled_plugin_patterns.insert(plugin_name); | 106 policy_disabled_plugin_patterns.insert(plugin_name); |
105 } | 107 } |
106 } | 108 } |
107 } | 109 } |
108 PluginGroup::SetPolicyDisabledPluginPatterns(policy_disabled_plugin_patterns); | 110 webkit::npapi::PluginGroup::SetPolicyDisabledPluginPatterns( |
| 111 policy_disabled_plugin_patterns); |
109 | 112 |
110 NotifyPluginStatusChanged(); | 113 NotifyPluginStatusChanged(); |
111 } | 114 } |
112 | 115 |
113 void PluginUpdater::DisablePluginGroupsFromPrefs(Profile* profile) { | 116 void PluginUpdater::DisablePluginGroupsFromPrefs(Profile* profile) { |
114 bool update_internal_dir = false; | 117 bool update_internal_dir = false; |
115 FilePath last_internal_dir = | 118 FilePath last_internal_dir = |
116 profile->GetPrefs()->GetFilePath(prefs::kPluginsLastInternalDirectory); | 119 profile->GetPrefs()->GetFilePath(prefs::kPluginsLastInternalDirectory); |
117 FilePath cur_internal_dir; | 120 FilePath cur_internal_dir; |
118 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &cur_internal_dir) && | 121 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &cur_internal_dir) && |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 if (!enabled) { | 186 if (!enabled) { |
184 if (force_enable_internal_pdf) { | 187 if (force_enable_internal_pdf) { |
185 enabled = true; | 188 enabled = true; |
186 plugin->SetBoolean("enabled", true); | 189 plugin->SetBoolean("enabled", true); |
187 } else if (force_internal_pdf_for_this_run) { | 190 } else if (force_internal_pdf_for_this_run) { |
188 enabled = true; | 191 enabled = true; |
189 } | 192 } |
190 } | 193 } |
191 } | 194 } |
192 if (!enabled) | 195 if (!enabled) |
193 NPAPI::PluginList::Singleton()->DisablePlugin(plugin_path); | 196 webkit::npapi::PluginList::Singleton()->DisablePlugin(plugin_path); |
194 } else if (!enabled && plugin->GetString("name", &group_name)) { | 197 } else if (!enabled && plugin->GetString("name", &group_name)) { |
195 // Don't disable this group if it's for the pdf plugin and we just | 198 // Don't disable this group if it's for the pdf plugin and we just |
196 // forced it on. | 199 // forced it on. |
197 if (force_enable_internal_pdf && pdf_group_name == group_name) | 200 if (force_enable_internal_pdf && pdf_group_name == group_name) |
198 continue; | 201 continue; |
199 | 202 |
200 // Otherwise this is a list of groups. | 203 // Otherwise this is a list of groups. |
201 EnablePluginGroup(false, group_name); | 204 EnablePluginGroup(false, group_name); |
202 } | 205 } |
203 } | 206 } |
204 } | 207 } |
205 | 208 |
206 // Build the set of policy-disabled plugin patterns once and cache it. | 209 // 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. | 210 // Don't do this in the constructor, there's no profile available there. |
208 const ListValue* plugin_blacklist = | 211 const ListValue* plugin_blacklist = |
209 profile->GetPrefs()->GetList(prefs::kPluginsPluginsBlacklist); | 212 profile->GetPrefs()->GetList(prefs::kPluginsPluginsBlacklist); |
210 DisablePluginsFromPolicy(plugin_blacklist); | 213 DisablePluginsFromPolicy(plugin_blacklist); |
211 | 214 |
212 if ((!enable_internal_pdf_ && !found_internal_pdf) && | 215 if ((!enable_internal_pdf_ && !found_internal_pdf) && |
213 !force_internal_pdf_for_this_run) { | 216 !force_internal_pdf_for_this_run) { |
214 // The internal PDF plugin is disabled by default, and the user hasn't | 217 // The internal PDF plugin is disabled by default, and the user hasn't |
215 // overridden the default. | 218 // overridden the default. |
216 NPAPI::PluginList::Singleton()->DisablePlugin(pdf_path); | 219 webkit::npapi::PluginList::Singleton()->DisablePlugin(pdf_path); |
217 EnablePluginGroup(false, pdf_group_name); | 220 EnablePluginGroup(false, pdf_group_name); |
218 } | 221 } |
219 | 222 |
220 if (force_enable_internal_pdf) { | 223 if (force_enable_internal_pdf) { |
221 // See http://crbug.com/50105 for background. | 224 // See http://crbug.com/50105 for background. |
222 EnablePluginGroup(false, ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); | 225 EnablePluginGroup(false, ASCIIToUTF16( |
| 226 webkit::npapi::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. |
227 UpdatePreferences(profile, kPluginUpdateDelayMs); | 231 UpdatePreferences(profile, kPluginUpdateDelayMs); |
228 } | 232 } |
229 } | 233 } |
230 | 234 |
231 void PluginUpdater::UpdatePreferences(Profile* profile, int delay_ms) { | 235 void PluginUpdater::UpdatePreferences(Profile* profile, int delay_ms) { |
232 BrowserThread::PostDelayedTask( | 236 BrowserThread::PostDelayedTask( |
233 BrowserThread::FILE, | 237 BrowserThread::FILE, |
234 FROM_HERE, | 238 FROM_HERE, |
235 NewRunnableFunction( | 239 NewRunnableFunction( |
236 &PluginUpdater::GetPreferencesDataOnFileThread, profile), delay_ms); | 240 &PluginUpdater::GetPreferencesDataOnFileThread, profile), delay_ms); |
237 } | 241 } |
238 | 242 |
239 void PluginUpdater::GetPreferencesDataOnFileThread(void* profile) { | 243 void PluginUpdater::GetPreferencesDataOnFileThread(void* profile) { |
240 std::vector<WebPluginInfo> plugins; | 244 std::vector<webkit::npapi::WebPluginInfo> plugins; |
241 NPAPI::PluginList::Singleton()->GetPlugins(false, &plugins); | 245 webkit::npapi::PluginList::Singleton()->GetPlugins(false, &plugins); |
242 | 246 |
243 std::vector<PluginGroup> groups; | 247 std::vector<webkit::npapi::PluginGroup> groups; |
244 NPAPI::PluginList::Singleton()->GetPluginGroups(false, &groups); | 248 webkit::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( |
250 &PluginUpdater::OnUpdatePreferences, | 254 &PluginUpdater::OnUpdatePreferences, |
251 static_cast<Profile*>(profile), plugins, groups)); | 255 static_cast<Profile*>(profile), 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<webkit::npapi::WebPluginInfo>& plugins, |
257 const std::vector<PluginGroup>& groups) { | 261 const std::vector<webkit::npapi::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<webkit::npapi::WebPluginInfo>::const_iterator it = |
| 273 plugins.begin(); |
269 it != plugins.end(); | 274 it != plugins.end(); |
270 ++it) { | 275 ++it) { |
271 plugins_list->Append(CreatePluginFileSummary(*it)); | 276 plugins_list->Append(CreatePluginFileSummary(*it)); |
272 } | 277 } |
273 | 278 |
274 // Add the groups as well. | 279 // Add the groups as well. |
275 for (size_t i = 0; i < groups.size(); ++i) { | 280 for (size_t i = 0; i < groups.size(); ++i) { |
276 // Don't save preferences for vulnerable pugins. | 281 // Don't save preferences for vulnerable pugins. |
277 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 282 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
278 switches::kDisableOutdatedPlugins) || | 283 switches::kDisableOutdatedPlugins) || |
(...skipping 17 matching lines...) Expand all Loading... |
296 NotificationService::current()->Notify( | 301 NotificationService::current()->Notify( |
297 NotificationType::PLUGIN_ENABLE_STATUS_CHANGED, | 302 NotificationType::PLUGIN_ENABLE_STATUS_CHANGED, |
298 Source<PluginUpdater>(GetInstance()), | 303 Source<PluginUpdater>(GetInstance()), |
299 NotificationService::NoDetails()); | 304 NotificationService::NoDetails()); |
300 } | 305 } |
301 | 306 |
302 /*static*/ | 307 /*static*/ |
303 PluginUpdater* PluginUpdater::GetInstance() { | 308 PluginUpdater* PluginUpdater::GetInstance() { |
304 return Singleton<PluginUpdater>::get(); | 309 return Singleton<PluginUpdater>::get(); |
305 } | 310 } |
OLD | NEW |