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

Side by Side Diff: chrome/browser/plugin_installer.cc

Issue 10388253: Revert 138502 - Move version metadata from PluginGroup into PluginInstaller. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/plugin_installer.h ('k') | chrome/browser/plugin_installer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 "chrome/browser/download/download_service.h" 11 #include "chrome/browser/download/download_service.h"
12 #include "chrome/browser/download/download_service_factory.h" 12 #include "chrome/browser/download/download_service_factory.h"
13 #include "chrome/browser/download/download_util.h" 13 #include "chrome/browser/download/download_util.h"
14 #include "chrome/browser/platform_util.h" 14 #include "chrome/browser/platform_util.h"
15 #include "chrome/browser/plugin_installer_observer.h" 15 #include "chrome/browser/plugin_installer_observer.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
18 #include "content/public/browser/browser_context.h" 18 #include "content/public/browser/browser_context.h"
19 #include "content/public/browser/download_id.h" 19 #include "content/public/browser/download_id.h"
20 #include "content/public/browser/download_item.h" 20 #include "content/public/browser/download_item.h"
21 #include "content/public/browser/download_manager.h" 21 #include "content/public/browser/download_manager.h"
22 #include "content/public/browser/download_save_info.h" 22 #include "content/public/browser/download_save_info.h"
23 #include "content/public/browser/render_process_host.h" 23 #include "content/public/browser/render_process_host.h"
24 #include "content/public/browser/render_view_host.h" 24 #include "content/public/browser/render_view_host.h"
25 #include "content/public/browser/resource_dispatcher_host.h" 25 #include "content/public/browser/resource_dispatcher_host.h"
26 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
27 #include "net/url_request/url_request.h" 27 #include "net/url_request/url_request.h"
28 #include "webkit/plugins/npapi/plugin_group.h"
29 28
30 using content::BrowserThread; 29 using content::BrowserThread;
31 using content::DownloadItem; 30 using content::DownloadItem;
32 using content::ResourceDispatcherHost; 31 using content::ResourceDispatcherHost;
33 32
34 namespace { 33 namespace {
35 34
36 void BeginDownload( 35 void BeginDownload(
37 const GURL& url, 36 const GURL& url,
38 content::ResourceContext* resource_context, 37 content::ResourceContext* resource_context,
(...skipping 14 matching lines...) Expand all
53 content::DownloadSaveInfo(), 52 content::DownloadSaveInfo(),
54 callback); 53 callback);
55 54
56 if (error != net::OK) { 55 if (error != net::OK) {
57 BrowserThread::PostTask( 56 BrowserThread::PostTask(
58 BrowserThread::UI, FROM_HERE, 57 BrowserThread::UI, FROM_HERE,
59 base::Bind(callback, content::DownloadId::Invalid(), error)); 58 base::Bind(callback, content::DownloadId::Invalid(), error));
60 } 59 }
61 } 60 }
62 61
63 } // namespace 62 }
64 63
65 PluginInstaller::PluginInstaller(const std::string& identifier, 64 PluginInstaller::PluginInstaller(const std::string& identifier,
65 const GURL& plugin_url,
66 const GURL& help_url,
66 const string16& name, 67 const string16& name,
67 bool url_for_display, 68 bool url_for_display,
68 const GURL& plugin_url, 69 bool requires_authorization)
69 const GURL& help_url) 70 : state_(kStateIdle),
70 : identifier_(identifier), 71 identifier_(identifier),
72 plugin_url_(plugin_url),
73 help_url_(help_url),
71 name_(name), 74 name_(name),
72 url_for_display_(url_for_display), 75 url_for_display_(url_for_display),
73 plugin_url_(plugin_url), 76 requires_authorization_(requires_authorization) {
74 help_url_(help_url),
75 state_(INSTALLER_STATE_IDLE) {
76 } 77 }
77 78
78 PluginInstaller::~PluginInstaller() { 79 PluginInstaller::~PluginInstaller() {
79 } 80 }
80 81
81 void PluginInstaller::AddVersion(const Version& version,
82 SecurityStatus status) {
83 DCHECK(versions_.find(version) == versions_.end());
84 versions_[version] = status;
85 }
86
87 PluginInstaller::SecurityStatus PluginInstaller::GetSecurityStatus(
88 const webkit::WebPluginInfo& plugin) const {
89 // If there are no versions defined, the plug-in is alway considered
90 // up-to-date.
91 if (versions_.empty())
92 return SECURITY_STATUS_UP_TO_DATE;
93
94 scoped_ptr<Version> version(
95 webkit::npapi::PluginGroup::CreateVersionFromString(plugin.version));
96 if (!version.get())
97 version.reset(new Version("0"));
98
99 // |lower_bound| returns the latest version that is not newer than |version|.
100 std::map<Version, SecurityStatus, VersionComparator>::const_iterator it =
101 versions_.lower_bound(*version);
102 // If there is at least one version defined, everything older than the oldest
103 // defined version is considered out-of-date.
104 if (it == versions_.end())
105 return SECURITY_STATUS_OUT_OF_DATE;
106
107 return it->second;
108 }
109
110 bool PluginInstaller::VersionComparator::operator() (const Version& lhs,
111 const Version& rhs) const {
112 // Keep versions ordered by newest (biggest) first.
113 return lhs.CompareTo(rhs) > 0;
114 }
115
116 // static
117 bool PluginInstaller::ParseSecurityStatus(
118 const std::string& status_str,
119 PluginInstaller::SecurityStatus* status) {
120 if (status_str == "up_to_date")
121 *status = SECURITY_STATUS_UP_TO_DATE;
122 else if (status_str == "out_of_date")
123 *status = SECURITY_STATUS_OUT_OF_DATE;
124 else if (status_str == "requires_authorization")
125 *status = SECURITY_STATUS_REQUIRES_AUTHORIZATION;
126 else
127 return false;
128
129 return true;
130 }
131
132 void PluginInstaller::OnDownloadUpdated(DownloadItem* download) { 82 void PluginInstaller::OnDownloadUpdated(DownloadItem* download) {
133 DownloadItem::DownloadState state = download->GetState(); 83 DownloadItem::DownloadState state = download->GetState();
134 switch (state) { 84 switch (state) {
135 case DownloadItem::IN_PROGRESS: 85 case DownloadItem::IN_PROGRESS:
136 return; 86 return;
137 case DownloadItem::COMPLETE: { 87 case DownloadItem::COMPLETE: {
138 DCHECK_EQ(INSTALLER_STATE_DOWNLOADING, state_); 88 DCHECK_EQ(kStateDownloading, state_);
139 state_ = INSTALLER_STATE_IDLE; 89 state_ = kStateIdle;
140 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, 90 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_,
141 DownloadFinished()); 91 DownloadFinished());
142 break; 92 break;
143 } 93 }
144 case DownloadItem::CANCELLED: { 94 case DownloadItem::CANCELLED: {
145 DownloadCancelled(); 95 DownloadCancelled();
146 break; 96 break;
147 } 97 }
148 case DownloadItem::REMOVING: { 98 case DownloadItem::REMOVING: {
149 DCHECK_EQ(INSTALLER_STATE_DOWNLOADING, state_); 99 DCHECK_EQ(kStateDownloading, state_);
150 state_ = INSTALLER_STATE_IDLE; 100 state_ = kStateIdle;
151 break; 101 break;
152 } 102 }
153 case DownloadItem::INTERRUPTED: { 103 case DownloadItem::INTERRUPTED: {
154 content::DownloadInterruptReason reason = download->GetLastReason(); 104 content::DownloadInterruptReason reason = download->GetLastReason();
155 DownloadError(content::InterruptReasonDebugString(reason)); 105 DownloadError(content::InterruptReasonDebugString(reason));
156 break; 106 break;
157 } 107 }
158 case DownloadItem::MAX_DOWNLOAD_STATE: { 108 case DownloadItem::MAX_DOWNLOAD_STATE: {
159 NOTREACHED(); 109 NOTREACHED();
160 return; 110 return;
(...skipping 20 matching lines...) Expand all
181 void PluginInstaller::AddWeakObserver(WeakPluginInstallerObserver* observer) { 131 void PluginInstaller::AddWeakObserver(WeakPluginInstallerObserver* observer) {
182 weak_observers_.AddObserver(observer); 132 weak_observers_.AddObserver(observer);
183 } 133 }
184 134
185 void PluginInstaller::RemoveWeakObserver( 135 void PluginInstaller::RemoveWeakObserver(
186 WeakPluginInstallerObserver* observer) { 136 WeakPluginInstallerObserver* observer) {
187 weak_observers_.RemoveObserver(observer); 137 weak_observers_.RemoveObserver(observer);
188 } 138 }
189 139
190 void PluginInstaller::StartInstalling(TabContentsWrapper* wrapper) { 140 void PluginInstaller::StartInstalling(TabContentsWrapper* wrapper) {
191 DCHECK_EQ(INSTALLER_STATE_IDLE, state_); 141 DCHECK(state_ == kStateIdle);
192 DCHECK(!url_for_display_); 142 DCHECK(!url_for_display_);
193 state_ = INSTALLER_STATE_DOWNLOADING; 143 state_ = kStateDownloading;
194 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadStarted()); 144 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadStarted());
195 content::WebContents* web_contents = wrapper->web_contents(); 145 content::WebContents* web_contents = wrapper->web_contents();
196 DownloadService* download_service = 146 DownloadService* download_service =
197 DownloadServiceFactory::GetForProfile(wrapper->profile()); 147 DownloadServiceFactory::GetForProfile(wrapper->profile());
198 download_util::RecordDownloadSource( 148 download_util::RecordDownloadSource(
199 download_util::INITIATED_BY_PLUGIN_INSTALLER); 149 download_util::INITIATED_BY_PLUGIN_INSTALLER);
200 BrowserThread::PostTask( 150 BrowserThread::PostTask(
201 BrowserThread::IO, FROM_HERE, 151 BrowserThread::IO, FROM_HERE,
202 base::Bind(&BeginDownload, 152 base::Bind(&BeginDownload,
203 plugin_url_, 153 plugin_url_,
(...skipping 16 matching lines...) Expand all
220 DownloadError(msg); 170 DownloadError(msg);
221 return; 171 return;
222 } 172 }
223 DownloadItem* download_item = 173 DownloadItem* download_item =
224 dlm->GetActiveDownloadItem(download_id.local()); 174 dlm->GetActiveDownloadItem(download_id.local());
225 download_item->SetOpenWhenComplete(true); 175 download_item->SetOpenWhenComplete(true);
226 download_item->AddObserver(this); 176 download_item->AddObserver(this);
227 } 177 }
228 178
229 void PluginInstaller::OpenDownloadURL(content::WebContents* web_contents) { 179 void PluginInstaller::OpenDownloadURL(content::WebContents* web_contents) {
230 DCHECK_EQ(INSTALLER_STATE_IDLE, state_); 180 DCHECK(state_ == kStateIdle);
231 DCHECK(url_for_display_); 181 DCHECK(url_for_display_);
232 web_contents->OpenURL(content::OpenURLParams( 182 web_contents->OpenURL(content::OpenURLParams(
233 plugin_url_, 183 plugin_url_,
234 content::Referrer(web_contents->GetURL(), 184 content::Referrer(web_contents->GetURL(),
235 WebKit::WebReferrerPolicyDefault), 185 WebKit::WebReferrerPolicyDefault),
236 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED, false)); 186 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED, false));
237 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadFinished()); 187 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadFinished());
238 } 188 }
239 189
240 void PluginInstaller::DownloadError(const std::string& msg) { 190 void PluginInstaller::DownloadError(const std::string& msg) {
241 DCHECK_EQ(INSTALLER_STATE_DOWNLOADING, state_); 191 DCHECK(state_ == kStateDownloading);
242 state_ = INSTALLER_STATE_IDLE; 192 state_ = kStateIdle;
243 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadError(msg)); 193 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadError(msg));
244 } 194 }
245 195
246 void PluginInstaller::DownloadCancelled() { 196 void PluginInstaller::DownloadCancelled() {
247 DCHECK_EQ(INSTALLER_STATE_DOWNLOADING, state_); 197 DCHECK(state_ == kStateDownloading);
248 state_ = INSTALLER_STATE_IDLE; 198 state_ = kStateIdle;
249 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadCancelled()); 199 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadCancelled());
250 } 200 }
OLDNEW
« no previous file with comments | « chrome/browser/plugin_installer.h ('k') | chrome/browser/plugin_installer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698