diff options
author | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-10 13:20:36 +0000 |
---|---|---|
committer | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-10 13:20:36 +0000 |
commit | 1a86f75dffd931514c1db92725c47e727682de5a (patch) | |
tree | 5e200670869a2825567c645fa865422c2193287c /chrome | |
parent | ac2d85013a3f8908cefc12fca0dcb40a526e6c39 (diff) | |
download | chromium_src-1a86f75dffd931514c1db92725c47e727682de5a.zip chromium_src-1a86f75dffd931514c1db92725c47e727682de5a.tar.gz chromium_src-1a86f75dffd931514c1db92725c47e727682de5a.tar.bz2 |
Use regular download mechanism to download and open plug-in installer files.
As downloads can now be cancelled as well, add a DownloadCancelled callback to PluginInstallerObserver, and rename the others to be consistent in naming.
BUG=110484
TEST=none
Review URL: http://codereview.chromium.org/9370018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121439 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/app/generated_resources.grd | 3 | ||||
-rw-r--r-- | chrome/browser/plugin_download_helper.cc | 94 | ||||
-rw-r--r-- | chrome/browser/plugin_download_helper.h | 65 | ||||
-rw-r--r-- | chrome/browser/plugin_download_helper_unittest.cc | 122 | ||||
-rw-r--r-- | chrome/browser/plugin_infobar_delegates.cc | 28 | ||||
-rw-r--r-- | chrome/browser/plugin_infobar_delegates.h | 10 | ||||
-rw-r--r-- | chrome/browser/plugin_installer.cc | 138 | ||||
-rw-r--r-- | chrome/browser/plugin_installer.h | 19 | ||||
-rw-r--r-- | chrome/browser/plugin_installer_observer.cc | 7 | ||||
-rw-r--r-- | chrome/browser/plugin_installer_observer.h | 5 | ||||
-rw-r--r-- | chrome/browser/plugin_observer.cc | 36 | ||||
-rw-r--r-- | chrome/browser/plugin_test.cc | 1 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 2 | ||||
-rw-r--r-- | chrome/common/render_messages.h | 4 | ||||
-rw-r--r-- | chrome/renderer/plugins/plugin_placeholder.cc | 8 | ||||
-rw-r--r-- | chrome/renderer/plugins/plugin_placeholder.h | 1 |
17 files changed, 202 insertions, 343 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index d2889d9..e9c03a9 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -5309,6 +5309,9 @@ Because search results are requested even while you're typing your query, your d <message name="IDS_PLUGIN_DOWNLOAD_ERROR_SHORT" desc="The placeholder text when there was an error download a missing plug-in."> There was an error downloading the plug-in. Sorry :-/ </message> + <message name="IDS_PLUGIN_DOWNLOAD_CANCELLED" desc="The placeholder text when the user cancelled downloading the plug-in."> + The plug-in download was cancelled. + </message> <message name="IDS_PLUGIN_INSTALLING" desc="The placeholder text when installing a missing plug-in."> After installing the plug-in, reload the page. </message> diff --git a/chrome/browser/plugin_download_helper.cc b/chrome/browser/plugin_download_helper.cc deleted file mode 100644 index faf17dd..0000000 --- a/chrome/browser/plugin_download_helper.cc +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/plugin_download_helper.h" - -#include "base/bind.h" -#include "base/file_util.h" -#include "base/stringprintf.h" -#include "base/message_loop_proxy.h" -#include "content/public/browser/browser_thread.h" -#include "content/public/common/url_fetcher.h" -#include "net/base/net_errors.h" -#include "net/url_request/url_request_status.h" - -using content::BrowserThread; -using content::URLFetcher; - -PluginDownloadUrlHelper::PluginDownloadUrlHelper() { -} - -PluginDownloadUrlHelper::~PluginDownloadUrlHelper() { -} - -void PluginDownloadUrlHelper::InitiateDownload( - const GURL& download_url, - net::URLRequestContextGetter* request_context, - const DownloadFinishedCallback& finished_callback, - const ErrorCallback& error_callback) { - download_url_ = download_url; - download_finished_callback_ = finished_callback; - error_callback_ = error_callback; - download_file_fetcher_.reset(URLFetcher::Create( - download_url_, URLFetcher::GET, this)); - download_file_fetcher_->SetRequestContext(request_context); - download_file_fetcher_->SaveResponseToTemporaryFile( - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); - download_file_fetcher_->Start(); -} - -void PluginDownloadUrlHelper::OnURLFetchComplete(const URLFetcher* source) { - net::URLRequestStatus status = source->GetStatus(); - if (!status.is_success()) { - RunErrorCallback(base::StringPrintf("Error %d: %s", - status.error(), - net::ErrorToString(status.error()))); - return; - } - int response_code = source->GetResponseCode(); - if (response_code != 200 && - response_code != URLFetcher::RESPONSE_CODE_INVALID) { - // If we don't get a HTTP response code, the URL request either failed - // (which should be covered by the status check above) or the fetched URL - // was a file: URL (in unit tests for example), in which case it's fine. - RunErrorCallback(base::StringPrintf("HTTP status %d", response_code)); - return; - } - bool success = source->GetResponseAsFilePath(true, &downloaded_file_); - DCHECK(success); - BrowserThread::PostTaskAndReply( - BrowserThread::FILE, FROM_HERE, - base::Bind(&PluginDownloadUrlHelper::RenameDownloadedFile, - base::Unretained(this)), - base::Bind(&PluginDownloadUrlHelper::RunFinishedCallback, - base::Unretained(this))); -} - -void PluginDownloadUrlHelper::RenameDownloadedFile() { - FilePath new_download_file_path = - downloaded_file_.DirName().AppendASCII( - download_file_fetcher_->GetURL().ExtractFileName()); - - file_util::Delete(new_download_file_path, false); - - if (file_util::ReplaceFile(downloaded_file_, - new_download_file_path)) { - downloaded_file_ = new_download_file_path; - } else { - DPLOG(ERROR) << "Failed to rename file: " - << downloaded_file_.value() - << " to file: " - << new_download_file_path.value(); - } -} - -void PluginDownloadUrlHelper::RunFinishedCallback() { - download_finished_callback_.Run(downloaded_file_); - delete this; -} - -void PluginDownloadUrlHelper::RunErrorCallback(const std::string& msg) { - error_callback_.Run(msg); - delete this; -} diff --git a/chrome/browser/plugin_download_helper.h b/chrome/browser/plugin_download_helper.h deleted file mode 100644 index 8340888..0000000 --- a/chrome/browser/plugin_download_helper.h +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_PLUGIN_DOWNLOAD_HELPER_H_ -#define CHROME_BROWSER_PLUGIN_DOWNLOAD_HELPER_H_ -#pragma once - -#include "base/callback.h" -#include "base/file_path.h" -#include "base/memory/scoped_ptr.h" -#include "content/public/common/url_fetcher_delegate.h" -#include "googleurl/src/gurl.h" - -namespace base { -class MessageLoopProxy; -} - -namespace net { -class URLRequestContextGetter; -} - -// The PluginDownloadUrlHelper is used to handle one download URL request -// from the plugin. Each download request is handled by a new instance -// of this class. -class PluginDownloadUrlHelper : public content::URLFetcherDelegate { - public: - typedef base::Callback<void(const FilePath&)> DownloadFinishedCallback; - typedef base::Callback<void(const std::string&)> ErrorCallback; - - PluginDownloadUrlHelper(); - virtual ~PluginDownloadUrlHelper(); - - void InitiateDownload(const GURL& download_url, - net::URLRequestContextGetter* request_context, - const DownloadFinishedCallback& callback, - const ErrorCallback& error_callback); - - // content::URLFetcherDelegate - virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; - - private: - // Renames the file (which was downloaded to a temporary file) to the filename - // of the download URL. - void RenameDownloadedFile(); - - // Runs the success callback and deletes itself. - void RunFinishedCallback(); - - // Runs the error callback and deletes itself. - void RunErrorCallback(const std::string& error); - - // The download file request initiated by the plugin. - scoped_ptr<content::URLFetcher> download_file_fetcher_; - - GURL download_url_; - FilePath downloaded_file_; - - DownloadFinishedCallback download_finished_callback_; - ErrorCallback error_callback_; - - DISALLOW_COPY_AND_ASSIGN(PluginDownloadUrlHelper); -}; - -#endif // CHROME_BROWSER_PLUGIN_DOWNLOAD_HELPER_H_ diff --git a/chrome/browser/plugin_download_helper_unittest.cc b/chrome/browser/plugin_download_helper_unittest.cc deleted file mode 100644 index 7df0d24..0000000 --- a/chrome/browser/plugin_download_helper_unittest.cc +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/plugin_download_helper.h" - -#include "base/bind.h" -#include "base/file_path.h" -#include "base/message_loop.h" -#include "base/test/test_timeouts.h" -#include "chrome/common/chrome_paths.h" -#include "content/test/test_browser_thread.h" -#include "net/base/net_util.h" -#include "net/url_request/url_request_context.h" -#include "net/url_request/url_request_context_getter.h" -#include "net/url_request/url_request_test_util.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -class TestURLRequestContextGetter : public net::URLRequestContextGetter { - public: - TestURLRequestContextGetter() - : io_message_loop_proxy_(base::MessageLoopProxy::current()) { - } - - virtual net::URLRequestContext* GetURLRequestContext() { - if (!context_) - context_ = new TestURLRequestContext(); - return context_; - } - virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const { - return io_message_loop_proxy_; - } - - protected: - scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; - - private: - virtual ~TestURLRequestContextGetter() {} - - scoped_refptr<net::URLRequestContext> context_; -}; - -} // namespace - -// This class provides functionality to test the plugin installer download -// file functionality. -class PluginInstallerDownloadTest : public testing::Test { - public: - PluginInstallerDownloadTest() - : message_loop_(MessageLoop::TYPE_IO), - file_thread_(content::BrowserThread::FILE, &message_loop_), - download_helper_(NULL), - success_(false) {} - ~PluginInstallerDownloadTest() {} - - void Start() { - FilePath path; - PathService::Get(chrome::DIR_TEST_DATA, &path); - initial_download_path_ = net::FilePathToFileURL( - path.AppendASCII("download-test1.lib")); - download_helper_ = new PluginDownloadUrlHelper(); - TestURLRequestContextGetter* context_getter = - new TestURLRequestContextGetter; - download_helper_->InitiateDownload( - initial_download_path_, - context_getter, - base::Bind(&PluginInstallerDownloadTest::OnDownloadCompleted, - base::Unretained(this)), - base::Bind(&PluginInstallerDownloadTest::OnDownloadError, - base::Unretained(this))); - - message_loop_.PostDelayedTask( - FROM_HERE, MessageLoop::QuitClosure(), - TestTimeouts::action_max_timeout()); - } - - void OnDownloadCompleted(const FilePath& download_path) { - success_ = true; - final_download_path_ = download_path; - message_loop_.Quit(); - download_helper_ = NULL; - } - - void OnDownloadError(const std::string& error) { - ADD_FAILURE() << error; - message_loop_.Quit(); - download_helper_ = NULL; - } - - FilePath final_download_path() const { - return final_download_path_; - } - - FilePath initial_download_path() const { - return final_download_path_; - } - - bool success() const { - return success_; - } - - private: - MessageLoop message_loop_; - content::TestBrowserThread file_thread_; - FilePath final_download_path_; - PluginDownloadUrlHelper* download_helper_; - bool success_; - GURL initial_download_path_; -}; - -// This test validates that the plugin downloader downloads the specified file -// to a temporary path with the same file name. -TEST_F(PluginInstallerDownloadTest, PluginInstallerDownloadPathTest) { - Start(); - MessageLoop::current()->Run(); - - ASSERT_TRUE(success()); - EXPECT_TRUE(initial_download_path().BaseName().value() == - final_download_path().BaseName().value()); -} diff --git a/chrome/browser/plugin_infobar_delegates.cc b/chrome/browser/plugin_infobar_delegates.cc index f911ffe..5940568 100644 --- a/chrome/browser/plugin_infobar_delegates.cc +++ b/chrome/browser/plugin_infobar_delegates.cc @@ -219,7 +219,7 @@ bool OutdatedPluginInfoBarDelegate::Accept() { if (installer()->url_for_display()) { installer()->OpenDownloadURL(web_contents); } else { - installer()->StartInstalling(web_contents); + installer()->StartInstalling(observer_->tab_contents_wrapper()); } return false; } @@ -243,19 +243,23 @@ bool OutdatedPluginInfoBarDelegate::LinkClicked( return PluginInfoBarDelegate::LinkClicked(disposition); } -void OutdatedPluginInfoBarDelegate::DidStartDownload() { +void OutdatedPluginInfoBarDelegate::DownloadStarted() { ReplaceWithInfoBar(l10n_util::GetStringUTF16(IDS_PLUGIN_DOWNLOADING)); } -void OutdatedPluginInfoBarDelegate::DidFinishDownload() { - ReplaceWithInfoBar(l10n_util::GetStringUTF16(IDS_PLUGIN_UPDATING)); -} - void OutdatedPluginInfoBarDelegate::DownloadError(const std::string& message) { ReplaceWithInfoBar( l10n_util::GetStringUTF16(IDS_PLUGIN_DOWNLOAD_ERROR_SHORT)); } +void OutdatedPluginInfoBarDelegate::DownloadCancelled() { + ReplaceWithInfoBar(l10n_util::GetStringUTF16(IDS_PLUGIN_DOWNLOAD_CANCELLED)); +} + +void OutdatedPluginInfoBarDelegate::DownloadFinished() { + ReplaceWithInfoBar(l10n_util::GetStringUTF16(IDS_PLUGIN_UPDATING)); +} + void OutdatedPluginInfoBarDelegate::OnlyWeakObserversLeft() { if (owner()) owner()->RemoveInfoBar(this); @@ -357,13 +361,12 @@ bool PluginInstallerInfoBarDelegate::LinkClicked( return false; } -void PluginInstallerInfoBarDelegate::DidStartDownload() { +void PluginInstallerInfoBarDelegate::DownloadStarted() { ReplaceWithInfoBar(l10n_util::GetStringUTF16(IDS_PLUGIN_DOWNLOADING)); } -void PluginInstallerInfoBarDelegate::DidFinishDownload() { - ReplaceWithInfoBar(l10n_util::GetStringUTF16( - new_install_ ? IDS_PLUGIN_INSTALLING : IDS_PLUGIN_UPDATING)); +void PluginInstallerInfoBarDelegate::DownloadCancelled() { + ReplaceWithInfoBar(l10n_util::GetStringUTF16(IDS_PLUGIN_DOWNLOAD_CANCELLED)); } void PluginInstallerInfoBarDelegate::DownloadError(const std::string& message) { @@ -371,6 +374,11 @@ void PluginInstallerInfoBarDelegate::DownloadError(const std::string& message) { l10n_util::GetStringUTF16(IDS_PLUGIN_DOWNLOAD_ERROR_SHORT)); } +void PluginInstallerInfoBarDelegate::DownloadFinished() { + ReplaceWithInfoBar(l10n_util::GetStringUTF16( + new_install_ ? IDS_PLUGIN_INSTALLING : IDS_PLUGIN_UPDATING)); +} + void PluginInstallerInfoBarDelegate::OnlyWeakObserversLeft() { if (owner()) owner()->RemoveInfoBar(this); diff --git a/chrome/browser/plugin_infobar_delegates.h b/chrome/browser/plugin_infobar_delegates.h index 2f1bf761..355dc1f 100644 --- a/chrome/browser/plugin_infobar_delegates.h +++ b/chrome/browser/plugin_infobar_delegates.h @@ -90,9 +90,10 @@ class OutdatedPluginInfoBarDelegate : public PluginInfoBarDelegate, virtual std::string GetLearnMoreURL() const OVERRIDE; // PluginInstallerObserver: - virtual void DidStartDownload() OVERRIDE; - virtual void DidFinishDownload() OVERRIDE; + virtual void DownloadStarted() OVERRIDE; virtual void DownloadError(const std::string& message) OVERRIDE; + virtual void DownloadCancelled() OVERRIDE; + virtual void DownloadFinished() OVERRIDE; // WeakPluginInstallerObserver: virtual void OnlyWeakObserversLeft() OVERRIDE; @@ -143,9 +144,10 @@ class PluginInstallerInfoBarDelegate : public ConfirmInfoBarDelegate, virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; // PluginInstallerObserver: - virtual void DidStartDownload() OVERRIDE; - virtual void DidFinishDownload() OVERRIDE; + virtual void DownloadStarted() OVERRIDE; virtual void DownloadError(const std::string& message) OVERRIDE; + virtual void DownloadCancelled() OVERRIDE; + virtual void DownloadFinished() OVERRIDE; // WeakPluginInstallerObserver: virtual void OnlyWeakObserversLeft() OVERRIDE; diff --git a/chrome/browser/plugin_installer.cc b/chrome/browser/plugin_installer.cc index a69b06c..39643e4 100644 --- a/chrome/browser/plugin_installer.cc +++ b/chrome/browser/plugin_installer.cc @@ -6,14 +6,55 @@ #include "base/bind.h" #include "base/bind_helpers.h" +#include "base/file_util.h" #include "base/process.h" +#include "chrome/browser/download/download_service_factory.h" +#include "chrome/browser/download/download_service.h" #include "chrome/browser/platform_util.h" -#include "chrome/browser/plugin_download_helper.h" #include "chrome/browser/plugin_installer_observer.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" +#include "content/browser/download/download_types.h" +#include "content/browser/renderer_host/render_view_host.h" +#include "content/browser/renderer_host/resource_dispatcher_host.h" +#include "content/public/browser/download_id.h" +#include "content/public/browser/download_manager.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/web_contents.h" +#include "content/public/browser/download_item.h" +#include "content/public/browser/render_process_host.h" + +using content::BrowserThread; +using content::DownloadItem; + +namespace { + +void BeginDownload(const GURL& url, + ResourceDispatcherHost* rdh, + content::ResourceContext* resource_context, + int render_process_host_id, + int render_view_host_routing_id, + const DownloadResourceHandler::OnStartedCallback& callback) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + + scoped_ptr<net::URLRequest> request( + new net::URLRequest(url, rdh)); + net::Error error = rdh->BeginDownload( + request.Pass(), + true, // prefer_cache + DownloadSaveInfo(), + callback, + render_process_host_id, + render_view_host_routing_id, + resource_context); + + if (error != net::OK) { + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind(callback, content::DownloadId::Invalid(), error)); + } +} -PluginInstaller::~PluginInstaller() { } PluginInstaller::PluginInstaller(const std::string& identifier, @@ -29,6 +70,46 @@ PluginInstaller::PluginInstaller(const std::string& identifier, url_for_display_(url_for_display) { } +PluginInstaller::~PluginInstaller() { +} + +void PluginInstaller::OnDownloadUpdated(DownloadItem* download) { + DownloadItem::DownloadState state = download->GetState(); + switch (state) { + case DownloadItem::IN_PROGRESS: + return; + case DownloadItem::COMPLETE: { + DCHECK_EQ(kStateDownloading, state_); + state_ = kStateIdle; + FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, + DownloadFinished()); + break; + } + case DownloadItem::CANCELLED: { + DownloadCancelled(); + break; + } + case DownloadItem::REMOVING: { + DCHECK_EQ(kStateDownloading, state_); + state_ = kStateIdle; + break; + } + case DownloadItem::INTERRUPTED: { + InterruptReason reason = download->GetLastReason(); + DownloadError(InterruptReasonDebugString(reason)); + break; + } + case DownloadItem::MAX_DOWNLOAD_STATE: { + NOTREACHED(); + return; + } + } + download->RemoveObserver(this); +} + +void PluginInstaller::OnDownloadOpened(DownloadItem* download) { +} + void PluginInstaller::AddObserver(PluginInstallerObserver* observer) { observers_.AddObserver(observer); } @@ -50,18 +131,41 @@ void PluginInstaller::RemoveWeakObserver( weak_observers_.RemoveObserver(observer); } -void PluginInstaller::StartInstalling(content::WebContents* web_contents) { +void PluginInstaller::StartInstalling(TabContentsWrapper* wrapper) { DCHECK(state_ == kStateIdle); DCHECK(!url_for_display_); state_ = kStateDownloading; - FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DidStartDownload()); - // |downloader| will delete itself after running the callback. - PluginDownloadUrlHelper* downloader = new PluginDownloadUrlHelper(); - downloader->InitiateDownload( - plugin_url_, - web_contents->GetBrowserContext()->GetRequestContext(), - base::Bind(&PluginInstaller::DidFinishDownload, base::Unretained(this)), - base::Bind(&PluginInstaller::DownloadError, base::Unretained(this))); + FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadStarted()); + content::WebContents* web_contents = wrapper->web_contents(); + DownloadService* download_service = + DownloadServiceFactory::GetForProfile(wrapper->profile()); + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&BeginDownload, + plugin_url_, ResourceDispatcherHost::Get(), + wrapper->profile()->GetResourceContext(), + web_contents->GetRenderProcessHost()->GetID(), + web_contents->GetRenderViewHost()->routing_id(), + base::Bind(&PluginInstaller::DownloadStarted, + base::Unretained(this), + make_scoped_refptr( + download_service->GetDownloadManager())))); +} + +void PluginInstaller::DownloadStarted( + scoped_refptr<content::DownloadManager> dlm, + content::DownloadId download_id, + net::Error error) { + if (error != net::OK) { + std::string msg = + base::StringPrintf("Error %d: %s", error, net::ErrorToString(error)); + DownloadError(msg); + return; + } + DownloadItem* download_item = + dlm->GetActiveDownloadItem(download_id.local()); + download_item->SetOpenWhenComplete(true); + download_item->AddObserver(this); } void PluginInstaller::OpenDownloadURL(content::WebContents* web_contents) { @@ -72,19 +176,17 @@ void PluginInstaller::OpenDownloadURL(content::WebContents* web_contents) { content::Referrer(web_contents->GetURL(), WebKit::WebReferrerPolicyDefault), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED, false)); - FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DidFinishDownload()); + FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadFinished()); } -void PluginInstaller::DidFinishDownload(const FilePath& downloaded_file) { +void PluginInstaller::DownloadError(const std::string& msg) { DCHECK(state_ == kStateDownloading); state_ = kStateIdle; - DVLOG(1) << "Plug-in installer is at \"" << downloaded_file.value() << "\""; - FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DidFinishDownload()); - platform_util::OpenItem(downloaded_file); + FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadError(msg)); } -void PluginInstaller::DownloadError(const std::string& msg) { +void PluginInstaller::DownloadCancelled() { DCHECK(state_ == kStateDownloading); state_ = kStateIdle; - FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadError(msg)); + FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadCancelled()); } diff --git a/chrome/browser/plugin_installer.h b/chrome/browser/plugin_installer.h index a405354..0b43113 100644 --- a/chrome/browser/plugin_installer.h +++ b/chrome/browser/plugin_installer.h @@ -9,16 +9,20 @@ #include "base/observer_list.h" #include "base/string16.h" #include "googleurl/src/gurl.h" +#include "content/public/browser/download_id.h" +#include "content/public/browser/download_item.h" +#include "net/base/net_errors.h" class FilePath; class PluginInstallerObserver; +class TabContentsWrapper; class WeakPluginInstallerObserver; namespace content { class WebContents; } -class PluginInstaller { +class PluginInstaller : public content::DownloadItem::Observer { public: enum State { kStateIdle, @@ -30,7 +34,11 @@ class PluginInstaller { const GURL& help_url, const string16& name, bool url_for_display); - ~PluginInstaller(); + virtual ~PluginInstaller(); + + virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE; + + virtual void OnDownloadOpened(content::DownloadItem* download) OVERRIDE; void AddObserver(PluginInstallerObserver* observer); void RemoveObserver(PluginInstallerObserver* observer); @@ -64,11 +72,14 @@ class PluginInstaller { // Starts downloading the download URL and opens the downloaded file // when finished. This method should only be called if |url_for_display| // returns false. - void StartInstalling(content::WebContents* web_contents); + void StartInstalling(TabContentsWrapper* wrapper); private: - void DidFinishDownload(const FilePath& downloaded_file); + void DownloadStarted(scoped_refptr<content::DownloadManager> dlm, + content::DownloadId download_id, + net::Error error); void DownloadError(const std::string& msg); + void DownloadCancelled(); State state_; ObserverList<PluginInstallerObserver> observers_; diff --git a/chrome/browser/plugin_installer_observer.cc b/chrome/browser/plugin_installer_observer.cc index 419f60e..32cba97 100644 --- a/chrome/browser/plugin_installer_observer.cc +++ b/chrome/browser/plugin_installer_observer.cc @@ -15,15 +15,18 @@ PluginInstallerObserver::~PluginInstallerObserver() { installer_->RemoveObserver(this); } -void PluginInstallerObserver::DidStartDownload() { +void PluginInstallerObserver::DownloadStarted() { } -void PluginInstallerObserver::DidFinishDownload() { +void PluginInstallerObserver::DownloadFinished() { } void PluginInstallerObserver::DownloadError(const std::string& message) { } +void PluginInstallerObserver::DownloadCancelled() { +} + WeakPluginInstallerObserver::WeakPluginInstallerObserver( PluginInstaller* installer) : PluginInstallerObserver(installer) { installer->AddWeakObserver(this); diff --git a/chrome/browser/plugin_installer_observer.h b/chrome/browser/plugin_installer_observer.h index b9b228a..f1f28d0 100644 --- a/chrome/browser/plugin_installer_observer.h +++ b/chrome/browser/plugin_installer_observer.h @@ -21,9 +21,10 @@ class PluginInstallerObserver { private: friend class PluginInstaller; - virtual void DidStartDownload(); - virtual void DidFinishDownload(); + virtual void DownloadStarted(); + virtual void DownloadFinished(); virtual void DownloadError(const std::string& message); + virtual void DownloadCancelled(); // Weak pointer; Owned by PluginFinder, which is a singleton. PluginInstaller* installer_; diff --git a/chrome/browser/plugin_observer.cc b/chrome/browser/plugin_observer.cc index 85bffaa..1a93d4d 100644 --- a/chrome/browser/plugin_observer.cc +++ b/chrome/browser/plugin_observer.cc @@ -48,7 +48,7 @@ namespace { class ConfirmInstallDialogDelegate : public TabModalConfirmDialogDelegate, public WeakPluginInstallerObserver { public: - ConfirmInstallDialogDelegate(WebContents* web_contents, + ConfirmInstallDialogDelegate(TabContentsWrapper* wrapper, PluginInstaller* installer); // TabModalConfirmDialogDelegate methods: @@ -58,20 +58,20 @@ class ConfirmInstallDialogDelegate : public TabModalConfirmDialogDelegate, virtual void OnAccepted() OVERRIDE; virtual void OnCanceled() OVERRIDE; - // PluginInstallerObserver methods: - virtual void DidStartDownload() OVERRIDE; + // WeakPluginInstallerObserver methods: + virtual void DownloadStarted() OVERRIDE; virtual void OnlyWeakObserversLeft() OVERRIDE; private: - content::WebContents* web_contents_; + TabContentsWrapper* wrapper_; }; ConfirmInstallDialogDelegate::ConfirmInstallDialogDelegate( - WebContents* web_contents, + TabContentsWrapper* wrapper, PluginInstaller* installer) - : TabModalConfirmDialogDelegate(web_contents), + : TabModalConfirmDialogDelegate(wrapper->web_contents()), WeakPluginInstallerObserver(installer), - web_contents_(web_contents) { + wrapper_(wrapper) { } string16 ConfirmInstallDialogDelegate::GetTitle() { @@ -90,13 +90,13 @@ string16 ConfirmInstallDialogDelegate::GetAcceptButtonTitle() { } void ConfirmInstallDialogDelegate::OnAccepted() { - installer()->StartInstalling(web_contents_); + installer()->StartInstalling(wrapper_); } void ConfirmInstallDialogDelegate::OnCanceled() { } -void ConfirmInstallDialogDelegate::DidStartDownload() { +void ConfirmInstallDialogDelegate::DownloadStarted() { Cancel(); } @@ -125,25 +125,29 @@ class PluginObserver::PluginPlaceholderHost : public PluginInstallerObserver { break; } case PluginInstaller::kStateDownloading: { - DidStartDownload(); + DownloadStarted(); break; } } } // PluginInstallerObserver methods: - virtual void DidStartDownload() OVERRIDE { + virtual void DownloadStarted() OVERRIDE { observer_->Send(new ChromeViewMsg_StartedDownloadingPlugin(routing_id_)); } - virtual void DidFinishDownload() OVERRIDE { - observer_->Send(new ChromeViewMsg_FinishedDownloadingPlugin(routing_id_)); - } - virtual void DownloadError(const std::string& msg) OVERRIDE { observer_->Send(new ChromeViewMsg_ErrorDownloadingPlugin(routing_id_, msg)); } + virtual void DownloadCancelled() OVERRIDE { + observer_->Send(new ChromeViewMsg_CancelledDownloadingPlugin(routing_id_)); + } + + virtual void DownloadFinished() OVERRIDE { + observer_->Send(new ChromeViewMsg_FinishedDownloadingPlugin(routing_id_)); + } + private: // Weak pointer; owns us. PluginObserver* observer_; @@ -252,7 +256,7 @@ void PluginObserver::InstallMissingPlugin(PluginInstaller* installer) { installer->OpenDownloadURL(web_contents()); } else { browser::ShowTabModalConfirmDialog( - new ConfirmInstallDialogDelegate(web_contents(), installer), + new ConfirmInstallDialogDelegate(tab_contents_, installer), tab_contents_); } } diff --git a/chrome/browser/plugin_test.cc b/chrome/browser/plugin_test.cc index e0105a3..0a4ccc1 100644 --- a/chrome/browser/plugin_test.cc +++ b/chrome/browser/plugin_test.cc @@ -30,7 +30,6 @@ #include "base/file_util.h" #include "base/path_service.h" #include "base/test/test_timeouts.h" -#include "chrome/browser/plugin_download_helper.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_paths.h" #include "chrome/test/automation/automation_proxy.h" diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index de78ed7..714e875e 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1812,8 +1812,6 @@ 'browser/platform_util_win.cc', 'browser/plugin_data_remover_helper.cc', 'browser/plugin_data_remover_helper.h', - 'browser/plugin_download_helper.cc', - 'browser/plugin_download_helper.h', 'browser/plugin_finder.cc', 'browser/plugin_finder.h', 'browser/plugin_installer.cc', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 8388d99..98722d6 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1558,7 +1558,6 @@ 'browser/password_manager/password_store_mac_unittest.cc', 'browser/password_manager/password_store_win_unittest.cc', 'browser/password_manager/password_store_x_unittest.cc', - 'browser/plugin_download_helper_unittest.cc', 'browser/plugin_finder_unittest.cc', 'browser/plugin_prefs_unittest.cc', 'browser/policy/asynchronous_policy_loader_unittest.cc', @@ -2169,7 +2168,6 @@ 'sources/': [ ['exclude', '^browser/password_manager/native_backend_gnome_x_unittest.cc'], ['exclude', '^browser/password_manager/native_backend_kwallet_x_unittest.cc'], - ['exclude', '^browser/plugin_download_helper_unittest.cc'], ['exclude', '^browser/safe_browsing/download_protection_service_unittest.cc' ], ], }, { # else: chromeos == 0 diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index 1649487..d6186b7 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -460,6 +460,10 @@ IPC_MESSAGE_ROUTED1(ChromeViewMsg_ErrorDownloadingPlugin, std::string /* message */) #endif // defined(ENABLE_PLUGIN_INSTALLATION) +// Notifies a missing plug-in placeholder that the user cancelled downloading +// the plug-in. +IPC_MESSAGE_ROUTED0(ChromeViewMsg_CancelledDownloadingPlugin) + // Tells the browser to open chrome://plugins in a new tab. We use a separate // message because renderer processes aren't allowed to directly navigate to // chrome:// URLs. diff --git a/chrome/renderer/plugins/plugin_placeholder.cc b/chrome/renderer/plugins/plugin_placeholder.cc index f49fc72..5d2d269 100644 --- a/chrome/renderer/plugins/plugin_placeholder.cc +++ b/chrome/renderer/plugins/plugin_placeholder.cc @@ -206,6 +206,8 @@ bool PluginPlaceholder::OnMessageReceived(const IPC::Message& message) { OnFinishedDownloadingPlugin) IPC_MESSAGE_HANDLER(ChromeViewMsg_ErrorDownloadingPlugin, OnErrorDownloadingPlugin) + IPC_MESSAGE_HANDLER(ChromeViewMsg_CancelledDownloadingPlugin, + OnCancelledDownloadingPlugin) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -318,7 +320,11 @@ void PluginPlaceholder::OnFinishedDownloadingPlugin() { void PluginPlaceholder::OnErrorDownloadingPlugin(const std::string& error) { SetMessage(l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOAD_ERROR, - UTF8ToUTF16(error))); + UTF8ToUTF16(error))); +} + +void PluginPlaceholder::OnCancelledDownloadingPlugin() { + SetMessage(l10n_util::GetStringUTF16(IDS_PLUGIN_DOWNLOAD_CANCELLED)); } #endif // defined(ENABLE_PLUGIN_INSTALLATION) diff --git a/chrome/renderer/plugins/plugin_placeholder.h b/chrome/renderer/plugins/plugin_placeholder.h index 3034c6b..c70de24 100644 --- a/chrome/renderer/plugins/plugin_placeholder.h +++ b/chrome/renderer/plugins/plugin_placeholder.h @@ -116,6 +116,7 @@ class PluginPlaceholder : public content::RenderViewObserver, void OnStartedDownloadingPlugin(); void OnFinishedDownloadingPlugin(); void OnErrorDownloadingPlugin(const std::string& error); + void OnCancelledDownloadingPlugin(); #endif void SetMessage(const string16& message); |