| 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 23 matching lines...) Expand all Loading... |
| 34 #include "content/public/browser/notification_details.h" | 34 #include "content/public/browser/notification_details.h" |
| 35 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
| 36 #include "content/public/browser/notification_source.h" | 36 #include "content/public/browser/notification_source.h" |
| 37 #include "googleurl/src/gurl.h" | 37 #include "googleurl/src/gurl.h" |
| 38 #include "net/base/escape.h" | 38 #include "net/base/escape.h" |
| 39 | 39 |
| 40 using content::BrowserThread; | 40 using content::BrowserThread; |
| 41 using content::DownloadId; | 41 using content::DownloadId; |
| 42 using content::DownloadItem; | 42 using content::DownloadItem; |
| 43 using content::NavigationController; | 43 using content::NavigationController; |
| 44 using content::DownloadUrlParameters; |
| 44 | 45 |
| 45 namespace { | 46 namespace { |
| 46 | 47 |
| 47 // Key used to attach the Approval to the DownloadItem. | 48 // Key used to attach the Approval to the DownloadItem. |
| 48 const char kApprovalKey[] = "extensions.webstore_installer"; | 49 const char kApprovalKey[] = "extensions.webstore_installer"; |
| 49 | 50 |
| 50 const char kInvalidIdError[] = "Invalid id"; | 51 const char kInvalidIdError[] = "Invalid id"; |
| 51 const char kNoBrowserError[] = "No browser found"; | 52 const char kNoBrowserError[] = "No browser found"; |
| 52 const char kDownloadDirectoryError[] = "Could not create download directory"; | 53 const char kDownloadDirectoryError[] = "Could not create download directory"; |
| 53 const char kDownloadCanceledError[] = "Download canceled"; | 54 const char kDownloadCanceledError[] = "Download canceled"; |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 if (flags_ & FLAG_INLINE_INSTALL) | 291 if (flags_ & FLAG_INLINE_INSTALL) |
| 291 referrer = GURL(extension_urls::GetWebstoreItemDetailURLPrefix() + id_); | 292 referrer = GURL(extension_urls::GetWebstoreItemDetailURLPrefix() + id_); |
| 292 | 293 |
| 293 content::DownloadSaveInfo save_info; | 294 content::DownloadSaveInfo save_info; |
| 294 save_info.file_path = file; | 295 save_info.file_path = file; |
| 295 | 296 |
| 296 // The download url for the given extension is contained in |download_url_|. | 297 // The download url for the given extension is contained in |download_url_|. |
| 297 // We will navigate the current tab to this url to start the download. The | 298 // We will navigate the current tab to this url to start the download. The |
| 298 // download system will then pass the crx to the CrxInstaller. | 299 // download system will then pass the crx to the CrxInstaller. |
| 299 download_util::RecordDownloadSource( | 300 download_util::RecordDownloadSource( |
| 300 download_util::INITIATED_BY_WEBSTORE_INSTALLER); | 301 download_util::INITIATED_BY_WEBSTORE_INSTALLER); |
| 301 profile_->GetDownloadManager()->DownloadUrl( | 302 DownloadUrlParameters* params = DownloadUrlParameters::FromWebContents( |
| 302 download_url_, referrer, "", | 303 controller_->GetWebContents(), download_url_, save_info); |
| 303 false, -1, save_info, controller_->GetWebContents(), | 304 params->set_referrer(referrer); |
| 304 base::Bind(&WebstoreInstaller::OnDownloadStarted, this)); | 305 params->set_callback(base::Bind(&WebstoreInstaller::OnDownloadStarted, this)); |
| 306 profile_->GetDownloadManager()->DownloadUrl(params); |
| 305 } | 307 } |
| 306 | 308 |
| 307 void WebstoreInstaller::ReportFailure(const std::string& error) { | 309 void WebstoreInstaller::ReportFailure(const std::string& error) { |
| 308 if (delegate_) { | 310 if (delegate_) { |
| 309 delegate_->OnExtensionInstallFailure(id_, error); | 311 delegate_->OnExtensionInstallFailure(id_, error); |
| 310 delegate_ = NULL; | 312 delegate_ = NULL; |
| 311 } | 313 } |
| 312 | 314 |
| 313 Release(); // Balanced in Start(). | 315 Release(); // Balanced in Start(). |
| 314 } | 316 } |
| 315 | 317 |
| 316 void WebstoreInstaller::ReportSuccess() { | 318 void WebstoreInstaller::ReportSuccess() { |
| 317 if (delegate_) { | 319 if (delegate_) { |
| 318 delegate_->OnExtensionInstallSuccess(id_); | 320 delegate_->OnExtensionInstallSuccess(id_); |
| 319 delegate_ = NULL; | 321 delegate_ = NULL; |
| 320 } | 322 } |
| 321 | 323 |
| 322 Release(); // Balanced in Start(). | 324 Release(); // Balanced in Start(). |
| 323 } | 325 } |
| OLD | NEW |