OLD | NEW |
---|---|
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 "chrome/browser/plugin_installer.h" | 5 #include "chrome/browser/plugin_installer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/process.h" | 10 #include "base/process.h" |
11 #include "base/utf_string_conversions.h" | |
11 #include "chrome/browser/download/download_service.h" | 12 #include "chrome/browser/download/download_service.h" |
12 #include "chrome/browser/download/download_service_factory.h" | 13 #include "chrome/browser/download/download_service_factory.h" |
13 #include "chrome/browser/download/download_util.h" | 14 #include "chrome/browser/download/download_util.h" |
14 #include "chrome/browser/platform_util.h" | 15 #include "chrome/browser/platform_util.h" |
16 #include "chrome/browser/plugin_finder.h" | |
15 #include "chrome/browser/plugin_installer_observer.h" | 17 #include "chrome/browser/plugin_installer_observer.h" |
16 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
18 #include "content/public/browser/browser_context.h" | 20 #include "content/public/browser/browser_context.h" |
19 #include "content/public/browser/download_id.h" | 21 #include "content/public/browser/download_id.h" |
20 #include "content/public/browser/download_item.h" | 22 #include "content/public/browser/download_item.h" |
21 #include "content/public/browser/download_manager.h" | 23 #include "content/public/browser/download_manager.h" |
22 #include "content/public/browser/download_save_info.h" | 24 #include "content/public/browser/download_save_info.h" |
23 #include "content/public/browser/render_process_host.h" | 25 #include "content/public/browser/render_process_host.h" |
24 #include "content/public/browser/render_view_host.h" | 26 #include "content/public/browser/render_view_host.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 base::Bind(callback, content::DownloadId::Invalid(), error)); | 67 base::Bind(callback, content::DownloadId::Invalid(), error)); |
66 } | 68 } |
67 } | 69 } |
68 | 70 |
69 } // namespace | 71 } // namespace |
70 | 72 |
71 PluginInstaller::PluginInstaller(const std::string& identifier, | 73 PluginInstaller::PluginInstaller(const std::string& identifier, |
72 const string16& name, | 74 const string16& name, |
73 bool url_for_display, | 75 bool url_for_display, |
74 const GURL& plugin_url, | 76 const GURL& plugin_url, |
75 const GURL& help_url) | 77 const GURL& help_url, |
78 const string16& group_name_matcher) | |
76 : identifier_(identifier), | 79 : identifier_(identifier), |
77 name_(name), | 80 name_(name), |
81 group_name_matcher_(group_name_matcher), | |
78 url_for_display_(url_for_display), | 82 url_for_display_(url_for_display), |
79 plugin_url_(plugin_url), | 83 plugin_url_(plugin_url), |
80 help_url_(help_url), | 84 help_url_(help_url), |
81 state_(INSTALLER_STATE_IDLE) { | 85 state_(INSTALLER_STATE_IDLE) { |
82 } | 86 } |
83 | 87 |
84 PluginInstaller::~PluginInstaller() { | 88 PluginInstaller::~PluginInstaller() { |
85 } | 89 } |
86 | 90 |
87 void PluginInstaller::AddVersion(const Version& version, | 91 void PluginInstaller::AddVersion(const Version& version, |
88 SecurityStatus status) { | 92 SecurityStatus status) { |
89 DCHECK(versions_.find(version) == versions_.end()); | 93 DCHECK(versions_.find(version) == versions_.end()); |
90 versions_[version] = status; | 94 versions_[version] = status; |
91 } | 95 } |
92 | 96 |
93 PluginInstaller::SecurityStatus PluginInstaller::GetSecurityStatus( | 97 PluginInstaller::SecurityStatus PluginInstaller::GetSecurityStatus( |
94 const webkit::WebPluginInfo& plugin) const { | 98 const webkit::WebPluginInfo& plugin) const { |
95 // If there are no versions defined, the plug-in should require authorization. | 99 // If there are no versions defined, the plug-in should require authorization. |
96 if (versions_.empty()) | 100 if (versions_.empty()) |
97 return SECURITY_STATUS_REQUIRES_AUTHORIZATION; | 101 return SECURITY_STATUS_REQUIRES_AUTHORIZATION; |
98 | 102 |
99 Version version; | 103 Version version; |
100 webkit::npapi::PluginGroup::CreateVersionFromString(plugin.version, &version); | 104 webkit::WebPluginInfo::CreateVersionFromString(plugin.version, &version); |
101 if (!version.IsValid()) | 105 if (!version.IsValid()) |
102 version = Version("0"); | 106 version = Version("0"); |
103 | 107 |
104 // |lower_bound| returns the latest version that is not newer than |version|. | 108 // |lower_bound| returns the latest version that is not newer than |version|. |
105 std::map<Version, SecurityStatus, VersionComparator>::const_iterator it = | 109 std::map<Version, SecurityStatus, VersionComparator>::const_iterator it = |
106 versions_.lower_bound(version); | 110 versions_.lower_bound(version); |
107 // If there is at least one version defined, everything older than the oldest | 111 // If there is at least one version defined, everything older than the oldest |
108 // defined version is considered out-of-date. | 112 // defined version is considered out-of-date. |
109 if (it == versions_.end()) | 113 if (it == versions_.end()) |
110 return SECURITY_STATUS_OUT_OF_DATE; | 114 return SECURITY_STATUS_OUT_OF_DATE; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 DCHECK_EQ(INSTALLER_STATE_DOWNLOADING, state_); | 247 DCHECK_EQ(INSTALLER_STATE_DOWNLOADING, state_); |
244 state_ = INSTALLER_STATE_IDLE; | 248 state_ = INSTALLER_STATE_IDLE; |
245 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadError(msg)); | 249 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadError(msg)); |
246 } | 250 } |
247 | 251 |
248 void PluginInstaller::DownloadCancelled() { | 252 void PluginInstaller::DownloadCancelled() { |
249 DCHECK_EQ(INSTALLER_STATE_DOWNLOADING, state_); | 253 DCHECK_EQ(INSTALLER_STATE_DOWNLOADING, state_); |
250 state_ = INSTALLER_STATE_IDLE; | 254 state_ = INSTALLER_STATE_IDLE; |
251 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadCancelled()); | 255 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadCancelled()); |
252 } | 256 } |
257 | |
258 /*static*/ | |
Bernhard Bauer
2012/08/21 12:30:18
Nit: The rest of the file uses // static.
ibraaaa
2012/08/21 14:26:04
Done.
| |
259 string16 PluginInstaller::GetGroupName(const webkit::WebPluginInfo& plugin) { | |
260 PluginInstaller* plugin_installer = MatchWithConfiguredPlugins(plugin); | |
261 if (plugin_installer != NULL) { | |
Bernhard Bauer
2012/08/21 12:30:18
Nit: Braces aren't required for single-line statem
ibraaaa
2012/08/21 14:26:04
Done.
| |
262 return plugin_installer->name(); | |
263 } | |
264 | |
265 if (!plugin.name.empty()) { | |
266 return plugin.name; | |
267 } | |
268 | |
269 FilePath::StringType path = plugin.path.BaseName().RemoveExtension().value(); | |
270 #if defined(OS_POSIX) | |
271 return UTF8ToUTF16(path); | |
272 #elif defined(OS_WIN) | |
273 return WideToUTF16(path); | |
274 #endif | |
275 } | |
276 | |
277 /*static*/ | |
278 std::string PluginInstaller::GetIdentifier( | |
279 const webkit::WebPluginInfo& plugin) { | |
280 PluginInstaller* plugin_installer = MatchWithConfiguredPlugins(plugin); | |
281 if (plugin_installer != NULL) { | |
282 return plugin_installer->identifier(); | |
283 } | |
284 | |
285 FilePath path = plugin.path; | |
286 #if defined(OS_POSIX) | |
287 return path.BaseName().value(); | |
288 #elif defined(OS_WIN) | |
289 return base::SysWideToUTF8(path.BaseName().value()); | |
290 #endif | |
291 } | |
292 | |
293 /*static*/ | |
294 PluginInstaller* PluginInstaller::MatchWithConfiguredPlugins( | |
295 const webkit::WebPluginInfo& plugin) { | |
296 const std::map<std::string, PluginInstaller*>& plugins = | |
297 PluginFinder::GetInstance()->GetAllPluginInstallers(); | |
Bernhard Bauer
2012/08/21 12:30:18
Ok, this is where stuff gets complicated.
Right n
ibraaaa
2012/08/21 14:26:04
I want to confirm something, places where I need a
Bernhard Bauer
2012/08/21 19:14:52
If by that you mean that we're going to need to ma
| |
298 for (std::map<std::string, PluginInstaller*>::const_iterator it = | |
299 plugins.begin(); it != plugins.end(); ++it) { | |
300 if (plugin.name.find(it->second->group_name_matcher()) == std::string::npos) | |
301 continue; | |
302 return it->second; | |
303 } | |
304 | |
305 // Not found. | |
306 return NULL; | |
307 } | |
OLD | NEW |