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

Unified Diff: chrome/browser/extensions/webstore_installer.cc

Issue 145873003: Fix for 165634 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/webstore_installer.cc
diff --git a/chrome/browser/extensions/webstore_installer.cc b/chrome/browser/extensions/webstore_installer.cc
index 237dadc0cf809fc803f0969a92873a9a71cb5c5f..b5f80009ba232cafc204043b5735566445b45913 100644
--- a/chrome/browser/extensions/webstore_installer.cc
+++ b/chrome/browser/extensions/webstore_installer.cc
@@ -63,7 +63,8 @@ using content::BrowserContext;
using content::BrowserThread;
using content::DownloadItem;
using content::DownloadManager;
-using content::NavigationController;
+using content::WebContents;
+using content::WebContentsObserver;
using content::DownloadUrlParameters;
namespace {
@@ -244,13 +245,13 @@ const WebstoreInstaller::Approval* WebstoreInstaller::GetAssociatedApproval(
WebstoreInstaller::WebstoreInstaller(Profile* profile,
Delegate* delegate,
- NavigationController* controller,
+ WebContents* web_contents,
const std::string& id,
scoped_ptr<Approval> approval,
InstallSource source)
- : profile_(profile),
+ : WebContentsObserver(web_contents),
+ profile_(profile),
delegate_(delegate),
- controller_(controller),
id_(id),
install_source_(source),
download_item_(NULL),
@@ -258,7 +259,7 @@ WebstoreInstaller::WebstoreInstaller(Profile* profile,
total_modules_(0),
download_started_(false) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK(controller_);
+ DCHECK(web_contents);
registrar_.Add(this, chrome::NOTIFICATION_CRX_INSTALLER_DONE,
content::NotificationService::AllSources());
@@ -406,7 +407,6 @@ void WebstoreInstaller::SetDownloadDirectoryForTests(
}
WebstoreInstaller::~WebstoreInstaller() {
- controller_ = NULL;
if (download_item_) {
download_item_->RemoveObserver(this);
download_item_ = NULL;
@@ -558,37 +558,18 @@ void WebstoreInstaller::DownloadCrx(
void WebstoreInstaller::StartDownload(const base::FilePath& file) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DownloadManager* download_manager =
- BrowserContext::GetDownloadManager(profile_);
- if (file.empty()) {
+ if (!web_contents()) {
ReportFailure(kDownloadDirectoryError, FAILURE_REASON_OTHER);
return;
}
+
+ DownloadManager* download_manager =
+ BrowserContext::GetDownloadManager(profile_);
if (!download_manager) {
ReportFailure(kDownloadDirectoryError, FAILURE_REASON_OTHER);
return;
}
- if (!controller_) {
- ReportFailure(kDownloadDirectoryError, FAILURE_REASON_OTHER);
- return;
- }
- if (!controller_->GetWebContents()) {
- ReportFailure(kDownloadDirectoryError, FAILURE_REASON_OTHER);
- return;
- }
- if (!controller_->GetWebContents()->GetRenderProcessHost()) {
- ReportFailure(kDownloadDirectoryError, FAILURE_REASON_OTHER);
- return;
- }
- if (!controller_->GetWebContents()->GetRenderViewHost()) {
- ReportFailure(kDownloadDirectoryError, FAILURE_REASON_OTHER);
- return;
- }
- if (!controller_->GetBrowserContext()) {
- ReportFailure(kDownloadDirectoryError, FAILURE_REASON_OTHER);
- return;
- }
- if (!controller_->GetBrowserContext()->GetResourceContext()) {
+ if (file.empty()) {
ReportFailure(kDownloadDirectoryError, FAILURE_REASON_OTHER);
return;
}
@@ -597,21 +578,21 @@ void WebstoreInstaller::StartDownload(const base::FilePath& file) {
// We will navigate the current tab to this url to start the download. The
// download system will then pass the crx to the CrxInstaller.
RecordDownloadSource(DOWNLOAD_INITIATED_BY_WEBSTORE_INSTALLER);
- int render_process_host_id =
- controller_->GetWebContents()->GetRenderProcessHost()->GetID();
+ int render_process_host_id = web_contents()->GetRenderProcessHost()->GetID();
int render_view_host_routing_id =
- controller_->GetWebContents()->GetRenderViewHost()->GetRoutingID();
+ web_contents()->GetRenderViewHost()->GetRoutingID();
+ content::NavigationController& controller = web_contents()->GetController();
content::ResourceContext* resource_context =
- controller_->GetBrowserContext()->GetResourceContext();
+ controller.GetBrowserContext()->GetResourceContext();
scoped_ptr<DownloadUrlParameters> params(new DownloadUrlParameters(
download_url_,
render_process_host_id,
render_view_host_routing_id ,
resource_context));
params->set_file_path(file);
- if (controller_->GetVisibleEntry())
+ if (controller.GetVisibleEntry())
params->set_referrer(
- content::Referrer(controller_->GetVisibleEntry()->GetURL(),
+ content::Referrer(controller.GetVisibleEntry()->GetURL(),
blink::WebReferrerPolicyDefault));
params->set_callback(base::Bind(&WebstoreInstaller::OnDownloadStarted, this));
download_manager->DownloadUrl(params.Pass());

Powered by Google App Engine
This is Rietveld 408576698