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 "webkit/glue/plugins/plugin_list.h" | 5 #include "webkit/glue/plugins/plugin_list.h" |
6 | 6 |
7 #include <tchar.h> | 7 #include <tchar.h> |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 // the plugins are found. We are going to copy this as well. | 238 // the plugins are found. We are going to copy this as well. |
239 GetAcrobatDirectory(&dirs); | 239 GetAcrobatDirectory(&dirs); |
240 GetQuicktimeDirectory(&dirs); | 240 GetQuicktimeDirectory(&dirs); |
241 GetWindowsMediaDirectory(&dirs); | 241 GetWindowsMediaDirectory(&dirs); |
242 | 242 |
243 for (std::set<FilePath>::iterator i = dirs.begin(); i != dirs.end(); ++i) | 243 for (std::set<FilePath>::iterator i = dirs.begin(); i != dirs.end(); ++i) |
244 plugin_dirs->push_back(*i); | 244 plugin_dirs->push_back(*i); |
245 } | 245 } |
246 | 246 |
247 void PluginList::LoadPluginsFromDir(const FilePath &path, | 247 void PluginList::LoadPluginsFromDir(const FilePath &path, |
248 std::vector<WebPluginInfo>* plugins, | 248 std::vector<WebPluginInfo*>* plugins, |
249 std::set<FilePath>* visited_plugins) { | 249 std::set<FilePath>* visited_plugins) { |
250 WIN32_FIND_DATA find_file_data; | 250 WIN32_FIND_DATA find_file_data; |
251 HANDLE find_handle; | 251 HANDLE find_handle; |
252 | 252 |
253 std::wstring dir = path.value(); | 253 std::wstring dir = path.value(); |
254 // FindFirstFile requires that you specify a wildcard for directories. | 254 // FindFirstFile requires that you specify a wildcard for directories. |
255 dir.append(L"\\NP*.DLL"); | 255 dir.append(L"\\NP*.DLL"); |
256 | 256 |
257 find_handle = FindFirstFile(dir.c_str(), &find_file_data); | 257 find_handle = FindFirstFile(dir.c_str(), &find_file_data); |
258 if (find_handle == INVALID_HANDLE_VALUE) | 258 if (find_handle == INVALID_HANDLE_VALUE) |
259 return; | 259 return; |
260 | 260 |
261 do { | 261 do { |
262 if (!(find_file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { | 262 if (!(find_file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { |
263 FilePath filename = path.Append(find_file_data.cFileName); | 263 FilePath filename = path.Append(find_file_data.cFileName); |
264 LoadPlugin(filename, plugins); | 264 LoadPlugin(filename, plugins); |
265 visited_plugins->insert(filename); | 265 visited_plugins->insert(filename); |
266 } | 266 } |
267 } while (FindNextFile(find_handle, &find_file_data) != 0); | 267 } while (FindNextFile(find_handle, &find_file_data) != 0); |
268 | 268 |
269 DCHECK(GetLastError() == ERROR_NO_MORE_FILES); | 269 DCHECK(GetLastError() == ERROR_NO_MORE_FILES); |
270 FindClose(find_handle); | 270 FindClose(find_handle); |
271 } | 271 } |
272 | 272 |
273 void PluginList::LoadPluginsFromRegistry( | 273 void PluginList::LoadPluginsFromRegistry(std::set<FilePath>* visited_plugins, |
274 std::vector<WebPluginInfo>* plugins, | 274 std::vector<WebPluginInfo*>* plugins) { |
275 std::set<FilePath>* visited_plugins) { | |
276 std::set<FilePath> plugin_dirs; | 275 std::set<FilePath> plugin_dirs; |
277 | 276 |
278 GetPluginsInRegistryDirectory( | 277 GetPluginsInRegistryDirectory( |
279 HKEY_CURRENT_USER, kRegistryMozillaPlugins, &plugin_dirs); | 278 HKEY_CURRENT_USER, kRegistryMozillaPlugins, &plugin_dirs); |
280 GetPluginsInRegistryDirectory( | 279 GetPluginsInRegistryDirectory( |
281 HKEY_LOCAL_MACHINE, kRegistryMozillaPlugins, &plugin_dirs); | 280 HKEY_LOCAL_MACHINE, kRegistryMozillaPlugins, &plugin_dirs); |
282 | 281 |
283 for (std::set<FilePath>::iterator i = plugin_dirs.begin(); | 282 for (std::set<FilePath>::iterator i = plugin_dirs.begin(); |
284 i != plugin_dirs.end(); ++i) { | 283 i != plugin_dirs.end(); ++i) { |
285 LoadPlugin(*i, plugins); | 284 LoadPlugin(*i, plugins); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 | 322 |
324 if (cur_a > cur_b) | 323 if (cur_a > cur_b) |
325 return false; | 324 return false; |
326 if (cur_a < cur_b) | 325 if (cur_a < cur_b) |
327 return true; | 326 return true; |
328 } | 327 } |
329 return false; | 328 return false; |
330 } | 329 } |
331 | 330 |
332 bool PluginList::ShouldLoadPlugin(const WebPluginInfo& info, | 331 bool PluginList::ShouldLoadPlugin(const WebPluginInfo& info, |
333 std::vector<WebPluginInfo>* plugins) { | 332 std::vector<WebPluginInfo*>* plugins) { |
334 // Version check | 333 // Version check |
335 | 334 |
336 for (size_t i = 0; i < plugins->size(); ++i) { | 335 for (std::vector<WebPluginInfo*>::iterator it = plugins->begin(); |
jam
2010/12/15 18:25:50
I think the former code is more readable. please
pastarmovj
2010/12/15 21:56:04
Actually I only tried to bring in some consistency
| |
336 it != plugins->end(); | |
337 ++it) { | |
337 std::wstring plugin1 = | 338 std::wstring plugin1 = |
338 StringToLowerASCII((*plugins)[i].path.BaseName().ToWStringHack()); | 339 StringToLowerASCII((*it)->path.BaseName().ToWStringHack()); |
339 std::wstring plugin2 = | 340 std::wstring plugin2 = |
340 StringToLowerASCII(info.path.BaseName().ToWStringHack()); | 341 StringToLowerASCII(info.path.BaseName().ToWStringHack()); |
341 if ((plugin1 == plugin2 && HaveSharedMimeType((*plugins)[i], info)) || | 342 if ((plugin1 == plugin2 && HaveSharedMimeType(**it, info)) || |
342 (plugin1 == kJavaDeploy1 && plugin2 == kJavaDeploy2) || | 343 (plugin1 == kJavaDeploy1 && plugin2 == kJavaDeploy2) || |
343 (plugin1 == kJavaDeploy2 && plugin2 == kJavaDeploy1)) { | 344 (plugin1 == kJavaDeploy2 && plugin2 == kJavaDeploy1)) { |
344 if (!IsNewerVersion((*plugins)[i].version, info.version)) | 345 if (!IsNewerVersion((*it)->version, info.version)) |
345 return false; // We have loaded a plugin whose version is newer. | 346 return false; // We have loaded a plugin whose version is newer. |
346 | 347 |
347 plugins->erase(plugins->begin() + i); | 348 // TODO(pastarmovj): We can't just remove it like that. We could possibly |
349 // disable it first. | |
350 plugins->erase(it); | |
348 break; | 351 break; |
349 } | 352 } |
350 } | 353 } |
351 | 354 |
352 // Troublemakers | 355 // Troublemakers |
353 | 356 |
354 std::wstring filename = StringToLowerASCII(info.path.BaseName().value()); | 357 std::wstring filename = StringToLowerASCII(info.path.BaseName().value()); |
355 // Depends on XPCOM. | 358 // Depends on XPCOM. |
356 if (filename == kMozillaActiveXPlugin) | 359 if (filename == kMozillaActiveXPlugin) |
357 return false; | 360 return false; |
(...skipping 26 matching lines...) Expand all Loading... | |
384 } | 387 } |
385 } | 388 } |
386 | 389 |
387 // Special WMP handling | 390 // Special WMP handling |
388 | 391 |
389 // If both the new and old WMP plugins exist, only load the new one. | 392 // If both the new and old WMP plugins exist, only load the new one. |
390 if (filename == kNewWMPPlugin) { | 393 if (filename == kNewWMPPlugin) { |
391 if (dont_load_new_wmp_) | 394 if (dont_load_new_wmp_) |
392 return false; | 395 return false; |
393 | 396 |
394 for (size_t i = 0; i < plugins->size(); ++i) { | 397 for (std::vector<WebPluginInfo*>::iterator it = plugins->begin(); |
jam
2010/12/15 18:25:50
ditto
| |
395 if ((*plugins)[i].path.BaseName().value() == kOldWMPPlugin) { | 398 it != plugins->end(); |
396 plugins->erase(plugins->begin() + i); | 399 ++it) { |
400 if ((*it)->path.BaseName().value() == kOldWMPPlugin) { | |
401 // TODO(pastarmovj): We can't just remove it like that. We could | |
402 // possibly disable it first. | |
403 plugins->erase(it); | |
397 break; | 404 break; |
398 } | 405 } |
399 } | 406 } |
400 } else if (filename == kOldWMPPlugin) { | 407 } else if (filename == kOldWMPPlugin) { |
401 for (size_t i = 0; i < plugins->size(); ++i) { | 408 for (std::vector<WebPluginInfo*>::iterator it = plugins->begin(); |
jam
2010/12/15 18:25:50
ditto
| |
402 if ((*plugins)[i].path.BaseName().value() == kNewWMPPlugin) | 409 it != plugins->end(); |
410 ++it) { | |
411 if ((*it)->path.BaseName().value() == kNewWMPPlugin) | |
403 return false; | 412 return false; |
404 } | 413 } |
405 } | 414 } |
406 | 415 |
407 return true; | 416 return true; |
408 } | 417 } |
409 | 418 |
410 } // namespace NPAPI | 419 } // namespace NPAPI |
OLD | NEW |