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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 !controller_->GetWebContents() || | 342 !controller_->GetWebContents() || |
343 !controller_->GetWebContents()->GetRenderProcessHost() || | 343 !controller_->GetWebContents()->GetRenderProcessHost() || |
344 !controller_->GetWebContents()->GetRenderViewHost() || | 344 !controller_->GetWebContents()->GetRenderViewHost() || |
345 !controller_->GetWebContents()->GetBrowserContext() || | 345 !controller_->GetWebContents()->GetBrowserContext() || |
346 !controller_->GetWebContents()->GetBrowserContext() | 346 !controller_->GetWebContents()->GetBrowserContext() |
347 ->GetResourceContext()) { | 347 ->GetResourceContext()) { |
348 ReportFailure(kDownloadDirectoryError, FAILURE_REASON_OTHER); | 348 ReportFailure(kDownloadDirectoryError, FAILURE_REASON_OTHER); |
349 return; | 349 return; |
350 } | 350 } |
351 | 351 |
352 scoped_ptr<content::DownloadSaveInfo> save_info( | |
353 new content::DownloadSaveInfo()); | |
354 save_info->file_path = file; | |
355 | |
356 // The download url for the given extension is contained in |download_url_|. | 352 // The download url for the given extension is contained in |download_url_|. |
357 // We will navigate the current tab to this url to start the download. The | 353 // We will navigate the current tab to this url to start the download. The |
358 // download system will then pass the crx to the CrxInstaller. | 354 // download system will then pass the crx to the CrxInstaller. |
359 download_util::RecordDownloadSource( | 355 download_util::RecordDownloadSource( |
360 download_util::INITIATED_BY_WEBSTORE_INSTALLER); | 356 download_util::INITIATED_BY_WEBSTORE_INSTALLER); |
361 scoped_ptr<DownloadUrlParameters> params( | 357 scoped_ptr<DownloadUrlParameters> params( |
362 DownloadUrlParameters::FromWebContents( | 358 DownloadUrlParameters::FromWebContents( |
363 controller_->GetWebContents(), download_url_, save_info.Pass())); | 359 controller_->GetWebContents(), download_url_)); |
| 360 params->set_file_path(file); |
364 if (controller_->GetActiveEntry()) | 361 if (controller_->GetActiveEntry()) |
365 params->set_referrer( | 362 params->set_referrer( |
366 content::Referrer(controller_->GetActiveEntry()->GetURL(), | 363 content::Referrer(controller_->GetActiveEntry()->GetURL(), |
367 WebKit::WebReferrerPolicyDefault)); | 364 WebKit::WebReferrerPolicyDefault)); |
368 params->set_callback(base::Bind(&WebstoreInstaller::OnDownloadStarted, this)); | 365 params->set_callback(base::Bind(&WebstoreInstaller::OnDownloadStarted, this)); |
369 download_manager->DownloadUrl(params.Pass()); | 366 download_manager->DownloadUrl(params.Pass()); |
370 } | 367 } |
371 | 368 |
372 void WebstoreInstaller::ReportFailure(const std::string& error, | 369 void WebstoreInstaller::ReportFailure(const std::string& error, |
373 FailureReason reason) { | 370 FailureReason reason) { |
374 if (delegate_) { | 371 if (delegate_) { |
375 delegate_->OnExtensionInstallFailure(id_, error, reason); | 372 delegate_->OnExtensionInstallFailure(id_, error, reason); |
376 delegate_ = NULL; | 373 delegate_ = NULL; |
377 } | 374 } |
378 | 375 |
379 Release(); // Balanced in Start(). | 376 Release(); // Balanced in Start(). |
380 } | 377 } |
381 | 378 |
382 void WebstoreInstaller::ReportSuccess() { | 379 void WebstoreInstaller::ReportSuccess() { |
383 if (delegate_) { | 380 if (delegate_) { |
384 delegate_->OnExtensionInstallSuccess(id_); | 381 delegate_->OnExtensionInstallSuccess(id_); |
385 delegate_ = NULL; | 382 delegate_ = NULL; |
386 } | 383 } |
387 | 384 |
388 Release(); // Balanced in Start(). | 385 Release(); // Balanced in Start(). |
389 } | 386 } |
390 | 387 |
391 } // namespace extensions | 388 } // namespace extensions |
OLD | NEW |