| 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" |
| 11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
| 12 #include "base/string_number_conversions.h" |
| 13 #include "base/string_util.h" |
| 12 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 13 #include "base/string_util.h" | |
| 14 #include "base/string_number_conversions.h" | |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 17 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 18 #include "chrome/browser/download/download_prefs.h" | 18 #include "chrome/browser/download/download_prefs.h" |
| 19 #include "chrome/browser/download/download_util.h" | 19 #include "chrome/browser/download/download_util.h" |
| 20 #include "chrome/browser/extensions/crx_installer.h" | 20 #include "chrome/browser/extensions/crx_installer.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/tabs/tab_strip_model.h" | 22 #include "chrome/browser/tabs/tab_strip_model.h" |
| 23 #include "chrome/browser/ui/browser_list.h" | 23 #include "chrome/browser/ui/browser_list.h" |
| 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 25 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
| 26 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 27 #include "chrome/common/extensions/extension.h" | 27 #include "chrome/common/extensions/extension.h" |
| 28 #include "chrome/common/extensions/extension_constants.h" | 28 #include "chrome/common/extensions/extension_constants.h" |
| 29 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 30 #include "content/public/browser/download_manager.h" | 30 #include "content/public/browser/download_manager.h" |
| 31 #include "content/public/browser/download_save_info.h" | 31 #include "content/public/browser/download_save_info.h" |
| 32 #include "content/public/browser/download_url_parameters.h" |
| 32 #include "content/public/browser/navigation_controller.h" | 33 #include "content/public/browser/navigation_controller.h" |
| 33 #include "content/public/browser/navigation_entry.h" | 34 #include "content/public/browser/navigation_entry.h" |
| 34 #include "content/public/browser/notification_details.h" | 35 #include "content/public/browser/notification_details.h" |
| 35 #include "content/public/browser/notification_service.h" | 36 #include "content/public/browser/notification_service.h" |
| 36 #include "content/public/browser/notification_source.h" | 37 #include "content/public/browser/notification_source.h" |
| 37 #include "googleurl/src/gurl.h" | 38 #include "googleurl/src/gurl.h" |
| 38 #include "net/base/escape.h" | 39 #include "net/base/escape.h" |
| 39 | 40 |
| 40 using content::BrowserThread; | 41 using content::BrowserThread; |
| 41 using content::DownloadId; | 42 using content::DownloadId; |
| 42 using content::DownloadItem; | 43 using content::DownloadItem; |
| 43 using content::NavigationController; | 44 using content::NavigationController; |
| 45 using content::DownloadUrlParameters; |
| 44 | 46 |
| 45 namespace { | 47 namespace { |
| 46 | 48 |
| 47 // Key used to attach the Approval to the DownloadItem. | 49 // Key used to attach the Approval to the DownloadItem. |
| 48 const char kApprovalKey[] = "extensions.webstore_installer"; | 50 const char kApprovalKey[] = "extensions.webstore_installer"; |
| 49 | 51 |
| 50 const char kInvalidIdError[] = "Invalid id"; | 52 const char kInvalidIdError[] = "Invalid id"; |
| 51 const char kNoBrowserError[] = "No browser found"; | 53 const char kNoBrowserError[] = "No browser found"; |
| 52 const char kDownloadDirectoryError[] = "Could not create download directory"; | 54 const char kDownloadDirectoryError[] = "Could not create download directory"; |
| 53 const char kDownloadCanceledError[] = "Download canceled"; | 55 const char kDownloadCanceledError[] = "Download canceled"; |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 if (flags_ & FLAG_INLINE_INSTALL) | 294 if (flags_ & FLAG_INLINE_INSTALL) |
| 293 referrer = GURL(extension_urls::GetWebstoreItemDetailURLPrefix() + id_); | 295 referrer = GURL(extension_urls::GetWebstoreItemDetailURLPrefix() + id_); |
| 294 | 296 |
| 295 content::DownloadSaveInfo save_info; | 297 content::DownloadSaveInfo save_info; |
| 296 save_info.file_path = file; | 298 save_info.file_path = file; |
| 297 | 299 |
| 298 // 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_|. |
| 299 // 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 |
| 300 // download system will then pass the crx to the CrxInstaller. | 302 // download system will then pass the crx to the CrxInstaller. |
| 301 download_util::RecordDownloadSource( | 303 download_util::RecordDownloadSource( |
| 302 download_util::INITIATED_BY_WEBSTORE_INSTALLER); | 304 download_util::INITIATED_BY_WEBSTORE_INSTALLER); |
| 303 profile_->GetDownloadManager()->DownloadUrl( | 305 scoped_ptr<DownloadUrlParameters> params( |
| 304 download_url_, referrer, "", | 306 DownloadUrlParameters::FromWebContents( |
| 305 false, -1, save_info, controller_->GetWebContents(), | 307 controller_->GetWebContents(), download_url_, save_info)); |
| 306 base::Bind(&WebstoreInstaller::OnDownloadStarted, this)); | 308 params->set_referrer(referrer); |
| 309 params->set_callback(base::Bind(&WebstoreInstaller::OnDownloadStarted, this)); |
| 310 profile_->GetDownloadManager()->DownloadUrl(params.Pass()); |
| 307 } | 311 } |
| 308 | 312 |
| 309 void WebstoreInstaller::ReportFailure(const std::string& error) { | 313 void WebstoreInstaller::ReportFailure(const std::string& error) { |
| 310 if (delegate_) { | 314 if (delegate_) { |
| 311 delegate_->OnExtensionInstallFailure(id_, error); | 315 delegate_->OnExtensionInstallFailure(id_, error); |
| 312 delegate_ = NULL; | 316 delegate_ = NULL; |
| 313 } | 317 } |
| 314 | 318 |
| 315 Release(); // Balanced in Start(). | 319 Release(); // Balanced in Start(). |
| 316 } | 320 } |
| 317 | 321 |
| 318 void WebstoreInstaller::ReportSuccess() { | 322 void WebstoreInstaller::ReportSuccess() { |
| 319 if (delegate_) { | 323 if (delegate_) { |
| 320 delegate_->OnExtensionInstallSuccess(id_); | 324 delegate_->OnExtensionInstallSuccess(id_); |
| 321 delegate_ = NULL; | 325 delegate_ = NULL; |
| 322 } | 326 } |
| 323 | 327 |
| 324 Release(); // Balanced in Start(). | 328 Release(); // Balanced in Start(). |
| 325 } | 329 } |
| OLD | NEW |