Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(422)

Side by Side Diff: webkit/plugins/npapi/plugin_list.cc

Issue 10918174: Remove PluginGroup (Closed) Base URL: http://git.chromium.org/chromium/src.git@remove_async_plugin_finder
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/plugins/npapi/plugin_list.h" 5 #include "webkit/plugins/npapi/plugin_list.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 << actual_mime_type << " (expected " << orig_mime_type 46 << actual_mime_type << " (expected " << orig_mime_type
47 << ")"; 47 << ")";
48 return allow; 48 return allow;
49 } 49 }
50 50
51 } 51 }
52 52
53 namespace webkit { 53 namespace webkit {
54 namespace npapi { 54 namespace npapi {
55 55
56 // TODO(ibraaaa): DELETE all hardcoded definitions. http://crbug.com/124396
57 // Note: If you change the plug-in definitions here, also update
58 // chrome/browser/resources/plugins_*.json correspondingly!
59 // In particular, the identifier needs to be kept in sync.
60
61 // Try and share the group definition for plug-ins that are
62 // very consistent across OS'es.
63 #define kFlashDefinition { \
64 "adobe-flash-player", "Adobe Flash Player", "Shockwave Flash" }
65
66 #define kShockwaveDefinition { \
67 "adobe-shockwave", PluginGroup::kShockwaveGroupName, \
68 "Shockwave for Director" }
69
70 #define kSilverlightDefinition { \
71 "silverlight", PluginGroup::kSilverlightGroupName, "Silverlight" }
72
73 #define kChromePdfDefinition { \
74 "google-chrome-pdf", "Chrome PDF Viewer", "Chrome PDF Viewer" }
75
76 #define kGoogleTalkDefinition { \
77 "google-talk", "Google Talk", "Google Talk" }
78
79 #if defined(OS_MACOSX)
80 // Plugin Groups for Mac.
81
82 static const PluginGroupDefinition kGroupDefinitions[] = {
83 kFlashDefinition,
84 { "apple-quicktime", PluginGroup::kQuickTimeGroupName, "QuickTime Plug-in" },
85 { "java-runtime-environment", PluginGroup::kJavaGroupName, "Java" },
86 kSilverlightDefinition,
87 { "flip4mac", "Flip4Mac", "Flip4Mac" },
88 { "divx-player", "DivX Web Player", "DivX Plus Web Player" },
89 { "realplayer", PluginGroup::kRealPlayerGroupName, "RealPlayer" },
90 kShockwaveDefinition,
91 kChromePdfDefinition,
92 kGoogleTalkDefinition,
93 };
94
95 #elif defined(OS_WIN)
96 // TODO(panayiotis): We should group "RealJukebox NS Plugin" with the rest of
97 // the RealPlayer files.
98
99 static const PluginGroupDefinition kGroupDefinitions[] = {
100 kFlashDefinition,
101 { "apple-quicktime", PluginGroup::kQuickTimeGroupName, "QuickTime Plug-in" },
102 { "java-runtime-environment", PluginGroup::kJavaGroupName, "Java" },
103 { "adobe-reader", PluginGroup::kAdobeReaderGroupName, "Adobe Acrobat" },
104 kSilverlightDefinition,
105 kShockwaveDefinition,
106 { "divx-player", "DivX Web Player", "DivX Web Player" },
107 { "realplayer", PluginGroup::kRealPlayerGroupName, "RealPlayer" },
108 { "windows-media-player", PluginGroup::kWindowsMediaPlayerGroupName,
109 "Windows Media Player" },
110 { "microsoft-office", "Microsoft Office", "Microsoft Office" },
111 { "nvidia-3d", "NVIDIA 3D", "NVIDIA 3D" },
112 kChromePdfDefinition,
113 kGoogleTalkDefinition,
114 };
115
116 #elif defined(OS_CHROMEOS)
117 // ChromeOS generally has (autoupdated) system plug-ins and no user-installable
118 // plug-ins, so we just use these definitions for grouping.
119 static const PluginGroupDefinition kGroupDefinitions[] = {
120 kFlashDefinition,
121 kChromePdfDefinition,
122 };
123
124 #else // Most importantly, covers desktop Linux.
125
126 static const PluginGroupDefinition kGroupDefinitions[] = {
127 // Flash on Linux is significant because there isn't yet a built-in Flash
128 // plug-in on the Linux 64-bit version of Chrome.
129 kFlashDefinition,
130 { "java-runtime-environment", PluginGroup::kJavaGroupName, "Java" },
131 { "redhat-icetea-java", "IcedTea", "IcedTea" },
132 kChromePdfDefinition,
133 kGoogleTalkDefinition,
134 };
135 #endif
136
137 // static 56 // static
138 PluginList* PluginList::Singleton() { 57 PluginList* PluginList::Singleton() {
139 return g_singleton.Pointer(); 58 return g_singleton.Pointer();
140 } 59 }
141 60
142 // static 61 // static
143 bool PluginList::DebugPluginLoading() { 62 bool PluginList::DebugPluginLoading() {
144 return CommandLine::ForCurrentProcess()->HasSwitch( 63 return CommandLine::ForCurrentProcess()->HasSwitch(
145 switches::kDebugPluginLoading); 64 switches::kDebugPluginLoading);
146 } 65 }
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 200
282 parsed_mime_types->push_back(mime_type); 201 parsed_mime_types->push_back(mime_type);
283 } 202 }
284 203
285 return true; 204 return true;
286 } 205 }
287 206
288 PluginList::PluginList() 207 PluginList::PluginList()
289 : loading_state_(LOADING_STATE_NEEDS_REFRESH) { 208 : loading_state_(LOADING_STATE_NEEDS_REFRESH) {
290 PlatformInit(); 209 PlatformInit();
291 AddHardcodedPluginGroups(kGroupDefinitions,
292 ARRAYSIZE_UNSAFE(kGroupDefinitions));
293 } 210 }
294 211
295 // TODO(ibraaaa): DELETE and add a different one. http://crbug.com/124396 212 PluginList::PluginList(int skip_platform_init)
296 PluginList::PluginList(const PluginGroupDefinition* definitions,
297 size_t num_definitions)
298 : 213 :
299 #if defined(OS_WIN) 214 #if defined(OS_WIN)
300 dont_load_new_wmp_(false), 215 dont_load_new_wmp_(false),
Bernhard Bauer 2012/09/17 15:18:01 Wait, are we not initializing this member in the d
ibraaaa 2012/09/17 15:44:35 Well, this CL only added it here: https://chromium
Bernhard Bauer 2012/09/17 16:00:54 Yup, that seems wrong. Could you also initialize i
ibraaaa 2012/09/17 16:21:34 Sent seperate CL for this: http://codereview.chrom
301 #endif 216 #endif
302 loading_state_(LOADING_STATE_NEEDS_REFRESH) { 217 loading_state_(LOADING_STATE_NEEDS_REFRESH) {
303 // Don't do platform-dependent initialization in unit tests. 218 // Don't do platform-dependent initialization in unit tests.
304 AddHardcodedPluginGroups(definitions, num_definitions);
305 }
306
307 // TODO(ibraaaa): DELETE. http://crbug.com/124396
308 PluginGroup* PluginList::CreatePluginGroup(
309 const webkit::WebPluginInfo& web_plugin_info) const {
310 for (size_t i = 0; i < hardcoded_plugin_groups_.size(); ++i) {
311 const PluginGroup* group = hardcoded_plugin_groups_[i];
312 if (group->Match(web_plugin_info))
313 return new PluginGroup(*group);
314 }
315 return PluginGroup::FromWebPluginInfo(web_plugin_info);
316 }
317
318 // TODO(ibraaaa): DELETE. http://crbug.com/124396
319 void PluginList::LoadPluginsInternal(ScopedVector<PluginGroup>* plugin_groups) {
320 base::Closure will_load_callback;
321 {
322 base::AutoLock lock(lock_);
323 will_load_callback = will_load_plugins_callback_;
324 }
325 if (!will_load_callback.is_null())
326 will_load_callback.Run();
327
328 std::vector<FilePath> plugin_paths;
329 GetPluginPathsToLoad(&plugin_paths);
330
331 for (std::vector<FilePath>::const_iterator it = plugin_paths.begin();
332 it != plugin_paths.end();
333 ++it) {
334 WebPluginInfo plugin_info;
335 LoadPlugin(*it, plugin_groups, &plugin_info);
336 }
337 } 219 }
338 220
339 void PluginList::LoadPluginsIntoPluginListInternal( 221 void PluginList::LoadPluginsIntoPluginListInternal(
340 std::vector<webkit::WebPluginInfo>* plugins) { 222 std::vector<webkit::WebPluginInfo>* plugins) {
341 base::Closure will_load_callback; 223 base::Closure will_load_callback;
342 { 224 {
343 base::AutoLock lock(lock_); 225 base::AutoLock lock(lock_);
344 will_load_callback = will_load_plugins_callback_; 226 will_load_callback = will_load_plugins_callback_;
345 } 227 }
346 if (!will_load_callback.is_null()) 228 if (!will_load_callback.is_null())
(...skipping 12 matching lines...) Expand all
359 241
360 void PluginList::LoadPlugins() { 242 void PluginList::LoadPlugins() {
361 { 243 {
362 base::AutoLock lock(lock_); 244 base::AutoLock lock(lock_);
363 if (loading_state_ == LOADING_STATE_UP_TO_DATE) 245 if (loading_state_ == LOADING_STATE_UP_TO_DATE)
364 return; 246 return;
365 247
366 loading_state_ = LOADING_STATE_REFRESHING; 248 loading_state_ = LOADING_STATE_REFRESHING;
367 } 249 }
368 250
369 ScopedVector<PluginGroup> new_plugin_groups; // TODO(ibraaaa): DELETE
370 // Do the actual loading of the plugins.
371 LoadPluginsInternal(&new_plugin_groups); // TODO(ibraaaa): DELETE
372
373 std::vector<webkit::WebPluginInfo> new_plugins; 251 std::vector<webkit::WebPluginInfo> new_plugins;
374 // Do the actual loading of the plugins. 252 // Do the actual loading of the plugins.
375 LoadPluginsIntoPluginListInternal(&new_plugins); 253 LoadPluginsIntoPluginListInternal(&new_plugins);
376 254
377 base::AutoLock lock(lock_); 255 base::AutoLock lock(lock_);
378 plugin_groups_.swap(new_plugin_groups); // TODO(ibraaaa): DELETE
379 plugins_list_.swap(new_plugins); 256 plugins_list_.swap(new_plugins);
380 257
381 // If we haven't been invalidated in the mean time, mark the plug-in list as 258 // If we haven't been invalidated in the mean time, mark the plug-in list as
382 // up-to-date. 259 // up-to-date.
383 if (loading_state_ != LOADING_STATE_NEEDS_REFRESH) 260 if (loading_state_ != LOADING_STATE_NEEDS_REFRESH)
384 loading_state_ = LOADING_STATE_UP_TO_DATE; 261 loading_state_ = LOADING_STATE_UP_TO_DATE;
385 } 262 }
386 263
387 // TODO(ibraaaa): DELETE. http://crbug.com/124396
388 bool PluginList::LoadPlugin(const FilePath& path,
389 ScopedVector<PluginGroup>* plugin_groups,
390 WebPluginInfo* plugin_info) {
391 LOG_IF(ERROR, PluginList::DebugPluginLoading())
392 << "Loading plugin " << path.value();
393 const PluginEntryPoints* entry_points;
394
395 if (!ReadPluginInfo(path, plugin_info, &entry_points))
396 return false;
397
398 if (!ShouldLoadPlugin(*plugin_info, plugin_groups))
399 return false;
400
401 #if defined(OS_WIN) && !defined(NDEBUG)
402 if (path.BaseName().value() != L"npspy.dll") // Make an exception for NPSPY
403 #endif
404 {
405 for (size_t i = 0; i < plugin_info->mime_types.size(); ++i) {
406 // TODO: don't load global handlers for now.
407 // WebKit hands to the Plugin before it tries
408 // to handle mimeTypes on its own.
409 const std::string &mime_type = plugin_info->mime_types[i].mime_type;
410 if (mime_type == "*")
411 return false;
412 }
413 }
414 AddToPluginGroups(*plugin_info, plugin_groups);
415 return true;
416 }
417
418 bool PluginList::LoadPluginIntoPluginList( 264 bool PluginList::LoadPluginIntoPluginList(
419 const FilePath& path, 265 const FilePath& path,
420 std::vector<webkit::WebPluginInfo>* plugins, 266 std::vector<webkit::WebPluginInfo>* plugins,
421 WebPluginInfo* plugin_info) { 267 WebPluginInfo* plugin_info) {
422 LOG_IF(ERROR, PluginList::DebugPluginLoading()) 268 LOG_IF(ERROR, PluginList::DebugPluginLoading())
423 << "Loading plugin " << path.value(); 269 << "Loading plugin " << path.value();
424 const PluginEntryPoints* entry_points; 270 const PluginEntryPoints* entry_points;
425 271
426 if (!ReadPluginInfo(path, plugin_info, &entry_points)) 272 if (!ReadPluginInfo(path, plugin_info, &entry_points))
427 return false; 273 return false;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 GetPluginsInDir(extra_plugin_dirs[i], plugin_paths); 319 GetPluginsInDir(extra_plugin_dirs[i], plugin_paths);
474 320
475 for (size_t i = 0; i < directories_to_scan.size(); ++i) 321 for (size_t i = 0; i < directories_to_scan.size(); ++i)
476 GetPluginsInDir(directories_to_scan[i], plugin_paths); 322 GetPluginsInDir(directories_to_scan[i], plugin_paths);
477 323
478 #if defined(OS_WIN) 324 #if defined(OS_WIN)
479 GetPluginPathsFromRegistry(plugin_paths); 325 GetPluginPathsFromRegistry(plugin_paths);
480 #endif 326 #endif
481 } 327 }
482 328
483 // TODO(ibraaaa): DELETE. http://crbug.com/124396
484 const std::vector<PluginGroup*>& PluginList::GetHardcodedPluginGroups() const {
485 return hardcoded_plugin_groups_.get();
486 }
487
488 void PluginList::SetPlugins(const std::vector<webkit::WebPluginInfo>& plugins) { 329 void PluginList::SetPlugins(const std::vector<webkit::WebPluginInfo>& plugins) {
489 base::AutoLock lock(lock_); 330 base::AutoLock lock(lock_);
490 331
491 DCHECK_NE(LOADING_STATE_REFRESHING, loading_state_); 332 DCHECK_NE(LOADING_STATE_REFRESHING, loading_state_);
492 loading_state_ = LOADING_STATE_UP_TO_DATE; 333 loading_state_ = LOADING_STATE_UP_TO_DATE;
493 334
494 // TODO(ibraaaa): DELETE
495 plugin_groups_.clear();
496 for (std::vector<webkit::WebPluginInfo>::const_iterator it = plugins.begin();
497 it != plugins.end();
498 ++it) {
499 AddToPluginGroups(*it, &plugin_groups_);
500 } // END OF DELETE
501
502 plugins_list_.clear(); 335 plugins_list_.clear();
503 plugins_list_.insert(plugins_list_.end(), plugins.begin(), plugins.end()); 336 plugins_list_.insert(plugins_list_.end(), plugins.begin(), plugins.end());
504 } 337 }
505 338
506 void PluginList::set_will_load_plugins_callback(const base::Closure& callback) { 339 void PluginList::set_will_load_plugins_callback(const base::Closure& callback) {
507 base::AutoLock lock(lock_); 340 base::AutoLock lock(lock_);
508 will_load_plugins_callback_ = callback; 341 will_load_plugins_callback_ = callback;
509 } 342 }
510 343
511 void PluginList::GetPlugins(std::vector<WebPluginInfo>* plugins) { 344 void PluginList::GetPlugins(std::vector<WebPluginInfo>* plugins) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 AllowMimeTypeMismatch(mime_type, actual_mime_type)) { 401 AllowMimeTypeMismatch(mime_type, actual_mime_type)) {
569 info->push_back(plugins_list_[i]); 402 info->push_back(plugins_list_[i]);
570 if (actual_mime_types) 403 if (actual_mime_types)
571 actual_mime_types->push_back(actual_mime_type); 404 actual_mime_types->push_back(actual_mime_type);
572 } 405 }
573 } 406 }
574 } 407 }
575 } 408 }
576 } 409 }
577 410
578 // TODO(ibraaaa): DELETE. http://crbug.com/124396
579 void PluginList::GetPluginGroups(
580 bool load_if_necessary,
581 std::vector<PluginGroup>* plugin_groups) {
582 if (load_if_necessary)
583 LoadPlugins();
584 base::AutoLock lock(lock_);
585 plugin_groups->clear();
586 for (size_t i = 0; i < plugin_groups_.size(); ++i) {
587 // In some unit tests we can get confronted with empty groups but in real
588 // world code this if should never be false here.
589 if (!plugin_groups_[i]->IsEmpty())
590 plugin_groups->push_back(*plugin_groups_[i]);
591 }
592 }
593
594 // TODO(ibraaaa): DELETE. http://crbug.com/124396
595 PluginGroup* PluginList::GetPluginGroup(
596 const webkit::WebPluginInfo& web_plugin_info) {
597 base::AutoLock lock(lock_);
598 for (size_t i = 0; i < plugin_groups_.size(); ++i) {
599 const std::vector<webkit::WebPluginInfo>& plugins =
600 plugin_groups_[i]->web_plugin_infos();
601 for (size_t j = 0; j < plugins.size(); ++j) {
602 if (plugins[j].path == web_plugin_info.path) {
603 return new PluginGroup(*plugin_groups_[i]);
604 }
605 }
606 }
607 PluginGroup* group = CreatePluginGroup(web_plugin_info);
608 group->AddPlugin(web_plugin_info);
609 return group;
610 }
611
612 // TODO(ibraaaa): DELETE. http://crbug.com/124396
613 string16 PluginList::GetPluginGroupName(const std::string& identifier) {
614 for (size_t i = 0; i < plugin_groups_.size(); ++i) {
615 if (plugin_groups_[i]->identifier() == identifier)
616 return plugin_groups_[i]->GetGroupName();
617 }
618 return string16();
619 }
620
621 // TODO(ibraaaa): DELETE. http://crbug.com/124396
622 void PluginList::AddHardcodedPluginGroups(
623 const PluginGroupDefinition* group_definitions,
624 size_t num_group_definitions) {
625 for (size_t i = 0; i < num_group_definitions; ++i) {
626 hardcoded_plugin_groups_.push_back(
627 PluginGroup::FromPluginGroupDefinition(group_definitions[i]));
628 }
629 }
630
631 // TODO(ibraaaa): DELETE. http://crbug.com/124396
632 PluginGroup* PluginList::AddToPluginGroups(
633 const webkit::WebPluginInfo& web_plugin_info,
634 ScopedVector<PluginGroup>* plugin_groups) {
635 PluginGroup* group = NULL;
636 for (size_t i = 0; i < plugin_groups->size(); ++i) {
637 if ((*plugin_groups)[i]->Match(web_plugin_info)) {
638 group = (*plugin_groups)[i];
639 break;
640 }
641 }
642 if (!group) {
643 group = CreatePluginGroup(web_plugin_info);
644 std::string identifier = group->identifier();
645 // If the identifier is not unique, use the full path. This means that we
646 // probably won't be able to search for this group by identifier, but at
647 // least it's going to be in the set of plugin groups, and if there
648 // is already a plug-in with the same filename, it's probably going to
649 // handle the same MIME types (and it has a higher priority), so this one
650 // is not going to run anyway.
651 for (size_t i = 0; i < plugin_groups->size(); ++i) {
652 if ((*plugin_groups)[i]->identifier() == identifier) {
653 group->set_identifier(PluginGroup::GetLongIdentifier(web_plugin_info));
654 break;
655 }
656 }
657 plugin_groups->push_back(group);
658 }
659 group->AddPlugin(web_plugin_info);
660 return group;
661 }
662
663 bool PluginList::SupportsType(const webkit::WebPluginInfo& plugin, 411 bool PluginList::SupportsType(const webkit::WebPluginInfo& plugin,
664 const std::string& mime_type, 412 const std::string& mime_type,
665 bool allow_wildcard) { 413 bool allow_wildcard) {
666 // Webkit will ask for a plugin to handle empty mime types. 414 // Webkit will ask for a plugin to handle empty mime types.
667 if (mime_type.empty()) 415 if (mime_type.empty())
668 return false; 416 return false;
669 417
670 for (size_t i = 0; i < plugin.mime_types.size(); ++i) { 418 for (size_t i = 0; i < plugin.mime_types.size(); ++i) {
671 const webkit::WebPluginMimeType& mime_info = plugin.mime_types[i]; 419 const webkit::WebPluginMimeType& mime_info = plugin.mime_types[i];
672 if (net::MatchesMimeType(mime_info.mime_type, mime_type)) { 420 if (net::MatchesMimeType(mime_info.mime_type, mime_type)) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 } 456 }
709 return did_remove; 457 return did_remove;
710 } 458 }
711 459
712 PluginList::~PluginList() { 460 PluginList::~PluginList() {
713 } 461 }
714 462
715 463
716 } // namespace npapi 464 } // namespace npapi
717 } // namespace webkit 465 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698