OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); | 148 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); |
149 FilePath::StringType pdf_path_str = pdf_path.value(); | 149 FilePath::StringType pdf_path_str = pdf_path.value(); |
150 if (!profile->GetPrefs()->GetBoolean(prefs::kPluginsEnabledInternalPDF)) { | 150 if (!profile->GetPrefs()->GetBoolean(prefs::kPluginsEnabledInternalPDF)) { |
151 // We switched to the internal pdf plugin being on by default, and so we | 151 // We switched to the internal pdf plugin being on by default, and so we |
152 // need to force it to be enabled. We only want to do it this once though, | 152 // need to force it to be enabled. We only want to do it this once though, |
153 // i.e. we don't want to enable it again if the user disables it afterwards. | 153 // i.e. we don't want to enable it again if the user disables it afterwards. |
154 profile->GetPrefs()->SetBoolean(prefs::kPluginsEnabledInternalPDF, true); | 154 profile->GetPrefs()->SetBoolean(prefs::kPluginsEnabledInternalPDF, true); |
155 force_enable_internal_pdf = true; | 155 force_enable_internal_pdf = true; |
156 } | 156 } |
157 | 157 |
| 158 bool force_enable_nacl = false; |
| 159 string16 nacl_group_name = |
| 160 ASCIIToUTF16(chrome::ChromeContentClient::kNaClPluginName); |
| 161 // Since the NaCl Plugin changed names between Chrome 13 and 14, we need to |
| 162 // check for both because either could be stored as the plugin group name. |
| 163 string16 old_nacl_group_name = |
| 164 ASCIIToUTF16(chrome::ChromeContentClient::kNaClOldPluginName); |
| 165 FilePath nacl_path; |
| 166 PathService::Get(chrome::FILE_NACL_PLUGIN, &nacl_path); |
| 167 FilePath::StringType nacl_path_str = nacl_path.value(); |
| 168 if (!profile->GetPrefs()->GetBoolean(prefs::kPluginsEnabledNaCl)) { |
| 169 // We switched to the nacl plugin being on by default, and so we need to |
| 170 // force it to be enabled. We only want to do it this once though, i.e. |
| 171 // we don't want to enable it again if the user disables it afterwards. |
| 172 profile->GetPrefs()->SetBoolean(prefs::kPluginsEnabledNaCl, true); |
| 173 force_enable_nacl = true; |
| 174 } |
| 175 |
158 { // Scoped update of prefs::kPluginsPluginsList. | 176 { // Scoped update of prefs::kPluginsPluginsList. |
159 ListPrefUpdate update(profile->GetPrefs(), prefs::kPluginsPluginsList); | 177 ListPrefUpdate update(profile->GetPrefs(), prefs::kPluginsPluginsList); |
160 ListValue* saved_plugins_list = update.Get(); | 178 ListValue* saved_plugins_list = update.Get(); |
161 if (saved_plugins_list && !saved_plugins_list->empty()) { | 179 if (saved_plugins_list && !saved_plugins_list->empty()) { |
162 for (ListValue::const_iterator it = saved_plugins_list->begin(); | 180 for (ListValue::const_iterator it = saved_plugins_list->begin(); |
163 it != saved_plugins_list->end(); | 181 it != saved_plugins_list->end(); |
164 ++it) { | 182 ++it) { |
165 if (!(*it)->IsType(Value::TYPE_DICTIONARY)) { | 183 if (!(*it)->IsType(Value::TYPE_DICTIONARY)) { |
166 LOG(WARNING) << "Invalid entry in " << prefs::kPluginsPluginsList; | 184 LOG(WARNING) << "Invalid entry in " << prefs::kPluginsPluginsList; |
167 continue; // Oops, don't know what to do with this item. | 185 continue; // Oops, don't know what to do with this item. |
(...skipping 21 matching lines...) Expand all Loading... |
189 plugin->SetString("path", path); | 207 plugin->SetString("path", path); |
190 } | 208 } |
191 | 209 |
192 if (FilePath::CompareIgnoreCase(path, pdf_path_str) == 0) { | 210 if (FilePath::CompareIgnoreCase(path, pdf_path_str) == 0) { |
193 if (!enabled && force_enable_internal_pdf) { | 211 if (!enabled && force_enable_internal_pdf) { |
194 enabled = true; | 212 enabled = true; |
195 plugin->SetBoolean("enabled", true); | 213 plugin->SetBoolean("enabled", true); |
196 } | 214 } |
197 | 215 |
198 internal_pdf_enabled = enabled; | 216 internal_pdf_enabled = enabled; |
| 217 } else if (FilePath::CompareIgnoreCase(path, nacl_path_str) == 0) { |
| 218 if (!enabled && force_enable_nacl) { |
| 219 enabled = true; |
| 220 plugin->SetBoolean("enabled", true); |
| 221 } |
199 } | 222 } |
200 | 223 |
201 if (!enabled) | 224 if (!enabled) |
202 webkit::npapi::PluginList::Singleton()->DisablePlugin(plugin_path); | 225 webkit::npapi::PluginList::Singleton()->DisablePlugin(plugin_path); |
203 } else if (!enabled && plugin->GetString("name", &group_name)) { | 226 } else if (!enabled && plugin->GetString("name", &group_name)) { |
204 // Don't disable this group if it's for the pdf plugin and we just | 227 // Don't disable this group if it's for the pdf or nacl plugins and |
205 // forced it on. | 228 // we just forced it on. |
206 if (force_enable_internal_pdf && pdf_group_name == group_name) | 229 if (force_enable_internal_pdf && pdf_group_name == group_name) |
207 continue; | 230 continue; |
| 231 if (force_enable_nacl && (nacl_group_name == group_name || |
| 232 old_nacl_group_name == group_name)) |
| 233 continue; |
208 | 234 |
209 // Otherwise this is a list of groups. | 235 // Otherwise this is a list of groups. |
210 EnablePluginGroup(false, group_name); | 236 EnablePluginGroup(false, group_name); |
211 } | 237 } |
212 } | 238 } |
213 } else { | 239 } else { |
214 // If the saved plugin list is empty, then the call to UpdatePreferences() | 240 // If the saved plugin list is empty, then the call to UpdatePreferences() |
215 // below failed in an earlier run, possibly because the user closed the | 241 // below failed in an earlier run, possibly because the user closed the |
216 // browser too quickly. Try to force enable the internal PDF plugin again. | 242 // browser too quickly. Try to force enable the internal PDF and nacl |
| 243 // plugins again. |
217 force_enable_internal_pdf = true; | 244 force_enable_internal_pdf = true; |
| 245 force_enable_nacl = true; |
218 } | 246 } |
219 } // Scoped update of prefs::kPluginsPluginsList. | 247 } // Scoped update of prefs::kPluginsPluginsList. |
220 | 248 |
221 // Build the set of policy enabled/disabled plugin patterns once and cache it. | 249 // Build the set of policy enabled/disabled plugin patterns once and cache it. |
222 // Don't do this in the constructor, there's no profile available there. | 250 // Don't do this in the constructor, there's no profile available there. |
223 const ListValue* disabled_plugins = | 251 const ListValue* disabled_plugins = |
224 profile->GetPrefs()->GetList(prefs::kPluginsDisabledPlugins); | 252 profile->GetPrefs()->GetList(prefs::kPluginsDisabledPlugins); |
225 const ListValue* disabled_exception_plugins = | 253 const ListValue* disabled_exception_plugins = |
226 profile->GetPrefs()->GetList(prefs::kPluginsDisabledPluginsExceptions); | 254 profile->GetPrefs()->GetList(prefs::kPluginsDisabledPluginsExceptions); |
227 const ListValue* enabled_plugins = | 255 const ListValue* enabled_plugins = |
228 profile->GetPrefs()->GetList(prefs::kPluginsEnabledPlugins); | 256 profile->GetPrefs()->GetList(prefs::kPluginsEnabledPlugins); |
229 UpdatePluginsStateFromPolicy(disabled_plugins, | 257 UpdatePluginsStateFromPolicy(disabled_plugins, |
230 disabled_exception_plugins, | 258 disabled_exception_plugins, |
231 enabled_plugins); | 259 enabled_plugins); |
232 | 260 |
233 registrar_.RemoveAll(); | 261 registrar_.RemoveAll(); |
234 registrar_.Init(profile->GetPrefs()); | 262 registrar_.Init(profile->GetPrefs()); |
235 registrar_.Add(prefs::kPluginsDisabledPlugins, this); | 263 registrar_.Add(prefs::kPluginsDisabledPlugins, this); |
236 registrar_.Add(prefs::kPluginsDisabledPluginsExceptions, this); | 264 registrar_.Add(prefs::kPluginsDisabledPluginsExceptions, this); |
237 registrar_.Add(prefs::kPluginsEnabledPlugins, this); | 265 registrar_.Add(prefs::kPluginsEnabledPlugins, this); |
238 | 266 |
239 if (force_enable_internal_pdf || internal_pdf_enabled) { | 267 if (force_enable_internal_pdf || internal_pdf_enabled) { |
240 // See http://crbug.com/50105 for background. | 268 // See http://crbug.com/50105 for background. |
241 EnablePluginGroup(false, ASCIIToUTF16( | 269 EnablePluginGroup(false, ASCIIToUTF16( |
242 webkit::npapi::PluginGroup::kAdobeReaderGroupName)); | 270 webkit::npapi::PluginGroup::kAdobeReaderGroupName)); |
243 } | 271 } |
244 | 272 |
245 if (force_enable_internal_pdf) { | 273 if (force_enable_internal_pdf || force_enable_nacl) { |
246 // We want to save this, but doing so requires loading the list of plugins, | 274 // We want to save this, but doing so requires loading the list of plugins, |
247 // so do it after a minute as to not impact startup performance. Note that | 275 // so do it after a minute as to not impact startup performance. Note that |
248 // plugins are loaded after 30s by the metrics service. | 276 // plugins are loaded after 30s by the metrics service. |
249 UpdatePreferences(profile, kPluginUpdateDelayMs); | 277 UpdatePreferences(profile, kPluginUpdateDelayMs); |
250 } | 278 } |
251 } | 279 } |
252 | 280 |
253 void PluginUpdater::Shutdown() { | 281 void PluginUpdater::Shutdown() { |
254 registrar_.RemoveAll(); | 282 registrar_.RemoveAll(); |
255 } | 283 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 prefs->RegisterFilePathPref(prefs::kPluginsLastInternalDirectory, | 374 prefs->RegisterFilePathPref(prefs::kPluginsLastInternalDirectory, |
347 internal_dir, | 375 internal_dir, |
348 PrefService::UNSYNCABLE_PREF); | 376 PrefService::UNSYNCABLE_PREF); |
349 prefs->RegisterListPref(prefs::kPluginsDisabledPlugins, | 377 prefs->RegisterListPref(prefs::kPluginsDisabledPlugins, |
350 PrefService::UNSYNCABLE_PREF); | 378 PrefService::UNSYNCABLE_PREF); |
351 prefs->RegisterListPref(prefs::kPluginsDisabledPluginsExceptions, | 379 prefs->RegisterListPref(prefs::kPluginsDisabledPluginsExceptions, |
352 PrefService::UNSYNCABLE_PREF); | 380 PrefService::UNSYNCABLE_PREF); |
353 prefs->RegisterListPref(prefs::kPluginsEnabledPlugins, | 381 prefs->RegisterListPref(prefs::kPluginsEnabledPlugins, |
354 PrefService::UNSYNCABLE_PREF); | 382 PrefService::UNSYNCABLE_PREF); |
355 } | 383 } |
OLD | NEW |