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/extensions/webstore_installer.h" | 5 #include "chrome/browser/extensions/webstore_installer.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 118 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
119 base::Bind(callback, file)); | 119 base::Bind(callback, file)); |
120 } | 120 } |
121 | 121 |
122 } // namespace | 122 } // namespace |
123 | 123 |
124 WebstoreInstaller::Approval::Approval() | 124 WebstoreInstaller::Approval::Approval() |
125 : profile(NULL), | 125 : profile(NULL), |
126 use_app_installed_bubble(false), | 126 use_app_installed_bubble(false), |
127 skip_post_install_ui(false), | 127 skip_post_install_ui(false) { |
128 skip_install_dialog(false) { | |
129 } | |
130 | |
131 scoped_ptr<WebstoreInstaller::Approval> | |
132 WebstoreInstaller::Approval::CreateWithInstallPrompt(Profile* profile) { | |
133 scoped_ptr<Approval> result(new Approval()); | |
134 result->profile = profile; | |
135 return result.Pass(); | |
136 } | |
137 | |
138 scoped_ptr<WebstoreInstaller::Approval> | |
139 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( | |
140 Profile* profile, | |
141 const std::string& extension_id, | |
142 scoped_ptr<base::DictionaryValue> parsed_manifest) { | |
143 scoped_ptr<Approval> result(new Approval()); | |
144 result->extension_id = extension_id; | |
145 result->profile = profile; | |
146 result->parsed_manifest = parsed_manifest.Pass(); | |
147 result->skip_install_dialog = true; | |
148 return result.Pass(); | |
149 } | 128 } |
150 | 129 |
151 WebstoreInstaller::Approval::~Approval() {} | 130 WebstoreInstaller::Approval::~Approval() {} |
152 | 131 |
153 const WebstoreInstaller::Approval* WebstoreInstaller::GetAssociatedApproval( | 132 const WebstoreInstaller::Approval* WebstoreInstaller::GetAssociatedApproval( |
154 const DownloadItem& download) { | 133 const DownloadItem& download) { |
155 return static_cast<const Approval*>(download.GetExternalData(kApprovalKey)); | 134 return static_cast<const Approval*>(download.GetExternalData(kApprovalKey)); |
156 } | 135 } |
157 | 136 |
158 WebstoreInstaller::WebstoreInstaller(Profile* profile, | 137 WebstoreInstaller::WebstoreInstaller(Profile* profile, |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 } | 278 } |
300 | 279 |
301 void WebstoreInstaller::StartDownload(const FilePath& file) { | 280 void WebstoreInstaller::StartDownload(const FilePath& file) { |
302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 281 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
303 | 282 |
304 if (file.empty()) { | 283 if (file.empty()) { |
305 ReportFailure(kDownloadDirectoryError); | 284 ReportFailure(kDownloadDirectoryError); |
306 return; | 285 return; |
307 } | 286 } |
308 | 287 |
| 288 // TODO(mihaip): For inline installs, we pretend like the referrer is the |
| 289 // gallery, even though this could be an inline install, in order to pass the |
| 290 // checks in ExtensionService::IsDownloadFromGallery. We should instead pass |
| 291 // the real referrer, track if this is an inline install in the whitelist |
| 292 // entry and look that up when checking that this is a valid download. |
| 293 GURL referrer = controller_->GetActiveEntry()->GetURL(); |
| 294 if (flags_ & FLAG_INLINE_INSTALL) |
| 295 referrer = GURL(extension_urls::GetWebstoreItemDetailURLPrefix() + id_); |
| 296 |
309 content::DownloadSaveInfo save_info; | 297 content::DownloadSaveInfo save_info; |
310 save_info.file_path = file; | 298 save_info.file_path = file; |
311 | 299 |
312 // The download url for the given extension is contained in |download_url_|. | 300 // The download url for the given extension is contained in |download_url_|. |
313 // We will navigate the current tab to this url to start the download. The | 301 // We will navigate the current tab to this url to start the download. The |
314 // download system will then pass the crx to the CrxInstaller. | 302 // download system will then pass the crx to the CrxInstaller. |
315 download_util::RecordDownloadSource( | 303 download_util::RecordDownloadSource( |
316 download_util::INITIATED_BY_WEBSTORE_INSTALLER); | 304 download_util::INITIATED_BY_WEBSTORE_INSTALLER); |
317 scoped_ptr<DownloadUrlParameters> params( | 305 scoped_ptr<DownloadUrlParameters> params( |
318 DownloadUrlParameters::FromWebContents( | 306 DownloadUrlParameters::FromWebContents( |
319 controller_->GetWebContents(), download_url_, save_info)); | 307 controller_->GetWebContents(), download_url_, save_info)); |
320 params->set_referrer(controller_->GetActiveEntry()->GetURL()); | 308 params->set_referrer(referrer); |
321 params->set_callback(base::Bind(&WebstoreInstaller::OnDownloadStarted, this)); | 309 params->set_callback(base::Bind(&WebstoreInstaller::OnDownloadStarted, this)); |
322 profile_->GetDownloadManager()->DownloadUrl(params.Pass()); | 310 profile_->GetDownloadManager()->DownloadUrl(params.Pass()); |
323 } | 311 } |
324 | 312 |
325 void WebstoreInstaller::ReportFailure(const std::string& error) { | 313 void WebstoreInstaller::ReportFailure(const std::string& error) { |
326 if (delegate_) { | 314 if (delegate_) { |
327 delegate_->OnExtensionInstallFailure(id_, error); | 315 delegate_->OnExtensionInstallFailure(id_, error); |
328 delegate_ = NULL; | 316 delegate_ = NULL; |
329 } | 317 } |
330 | 318 |
331 Release(); // Balanced in Start(). | 319 Release(); // Balanced in Start(). |
332 } | 320 } |
333 | 321 |
334 void WebstoreInstaller::ReportSuccess() { | 322 void WebstoreInstaller::ReportSuccess() { |
335 if (delegate_) { | 323 if (delegate_) { |
336 delegate_->OnExtensionInstallSuccess(id_); | 324 delegate_->OnExtensionInstallSuccess(id_); |
337 delegate_ = NULL; | 325 delegate_ = NULL; |
338 } | 326 } |
339 | 327 |
340 Release(); // Balanced in Start(). | 328 Release(); // Balanced in Start(). |
341 } | 329 } |
OLD | NEW |