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

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

Issue 10918174: Remove PluginGroup (Closed) Base URL: http://git.chromium.org/chromium/src.git@remove_async_plugin_finder
Patch Set: fix conflicts Created 8 years, 2 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
« no previous file with comments | « webkit/plugins/npapi/plugin_group.h ('k') | webkit/plugins/npapi/plugin_list.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <algorithm>
6
7 #include "webkit/plugins/npapi/plugin_group.h"
8
9 #include "base/memory/linked_ptr.h"
10 #include "base/string_split.h"
11 #include "base/string_util.h"
12 #include "base/sys_string_conversions.h"
13 #include "base/utf_string_conversions.h"
14 #include "base/values.h"
15 #include "base/version.h"
16 #include "webkit/plugins/npapi/plugin_list.h"
17 #include "webkit/plugins/webplugininfo.h"
18
19 namespace webkit {
20 namespace npapi {
21
22 // static
23 const char PluginGroup::kAdobeReaderGroupName[] = "Adobe Reader";
24 const char PluginGroup::kJavaGroupName[] = "Java(TM)";
25 const char PluginGroup::kQuickTimeGroupName[] = "QuickTime Player";
26 const char PluginGroup::kShockwaveGroupName[] = "Adobe Shockwave Player";
27 const char PluginGroup::kRealPlayerGroupName[] = "RealPlayer";
28 const char PluginGroup::kSilverlightGroupName[] = "Silverlight";
29 const char PluginGroup::kWindowsMediaPlayerGroupName[] = "Windows Media Player";
30
31 PluginGroup::PluginGroup(const string16& group_name,
32 const string16& name_matcher,
33 const std::string& identifier)
34 : identifier_(identifier),
35 group_name_(group_name),
36 name_matcher_(name_matcher) {
37 }
38
39 void PluginGroup::InitFrom(const PluginGroup& other) {
40 identifier_ = other.identifier_;
41 group_name_ = other.group_name_;
42 name_matcher_ = other.name_matcher_;
43 web_plugin_infos_ = other.web_plugin_infos_;
44 }
45
46 PluginGroup::PluginGroup(const PluginGroup& other) {
47 InitFrom(other);
48 }
49
50 PluginGroup& PluginGroup::operator=(const PluginGroup& other) {
51 InitFrom(other);
52 return *this;
53 }
54
55 /*static*/
56 PluginGroup* PluginGroup::FromPluginGroupDefinition(
57 const PluginGroupDefinition& definition) {
58 return new PluginGroup(ASCIIToUTF16(definition.name),
59 ASCIIToUTF16(definition.name_matcher),
60 definition.identifier);
61 }
62
63 PluginGroup::~PluginGroup() { }
64
65 /*static*/
66 std::string PluginGroup::GetIdentifier(const WebPluginInfo& wpi) {
67 #if defined(OS_POSIX)
68 return wpi.path.BaseName().value();
69 #elif defined(OS_WIN)
70 return base::SysWideToUTF8(wpi.path.BaseName().value());
71 #endif
72 }
73
74 /*static*/
75 std::string PluginGroup::GetLongIdentifier(const WebPluginInfo& wpi) {
76 #if defined(OS_POSIX)
77 return wpi.path.value();
78 #elif defined(OS_WIN)
79 return base::SysWideToUTF8(wpi.path.value());
80 #endif
81 }
82
83 /*static*/
84 PluginGroup* PluginGroup::FromWebPluginInfo(const WebPluginInfo& wpi) {
85 // Create a matcher from the name of this plugin.
86 return new PluginGroup(wpi.name, wpi.name,
87 GetIdentifier(wpi));
88 }
89
90 bool PluginGroup::Match(const WebPluginInfo& plugin) const {
91 if (name_matcher_.empty()) {
92 return false;
93 }
94
95 // Look for the name matcher anywhere in the plugin name.
96 if (plugin.name.find(name_matcher_) == string16::npos) {
97 return false;
98 }
99
100 return true;
101 }
102
103 void PluginGroup::AddPlugin(const WebPluginInfo& plugin) {
104 // Check if this group already contains this plugin.
105 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) {
106 if (FilePath::CompareEqualIgnoreCase(web_plugin_infos_[i].path.value(),
107 plugin.path.value())) {
108 return;
109 }
110 }
111 web_plugin_infos_.push_back(plugin);
112 }
113
114 bool PluginGroup::RemovePlugin(const FilePath& filename) {
115 bool did_remove = false;
116 for (size_t i = 0; i < web_plugin_infos_.size();) {
117 if (web_plugin_infos_[i].path == filename) {
118 web_plugin_infos_.erase(web_plugin_infos_.begin() + i);
119 did_remove = true;
120 } else {
121 i++;
122 }
123 }
124 return did_remove;
125 }
126
127 string16 PluginGroup::GetGroupName() const {
128 if (!group_name_.empty())
129 return group_name_;
130 DCHECK_EQ(1u, web_plugin_infos_.size());
131 FilePath::StringType path =
132 web_plugin_infos_[0].path.BaseName().RemoveExtension().value();
133 #if defined(OS_POSIX)
134 return UTF8ToUTF16(path);
135 #elif defined(OS_WIN)
136 return WideToUTF16(path);
137 #endif
138 }
139
140 bool PluginGroup::ContainsPlugin(const FilePath& path) const {
141 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) {
142 if (web_plugin_infos_[i].path == path)
143 return true;
144 }
145 return false;
146 }
147
148 bool PluginGroup::IsEmpty() const {
149 return web_plugin_infos_.empty();
150 }
151
152 } // namespace npapi
153 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/npapi/plugin_group.h ('k') | webkit/plugins/npapi/plugin_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698