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