diff options
author | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-11 14:26:42 +0000 |
---|---|---|
committer | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-11 14:26:42 +0000 |
commit | 5d474ff6e09b20d734a6074cbca3477bebcf76a9 (patch) | |
tree | 7a934f99247a5dd6276084370996dba2ee402446 /chrome/browser | |
parent | e4eec96d49686a9b90fc9c0dafc510af3a712726 (diff) | |
download | chromium_src-5d474ff6e09b20d734a6074cbca3477bebcf76a9.zip chromium_src-5d474ff6e09b20d734a6074cbca3477bebcf76a9.tar.gz chromium_src-5d474ff6e09b20d734a6074cbca3477bebcf76a9.tar.bz2 |
Revert 117210 - Show error message when downloading a plug-in installer fails.
Also, don't try to directly download Flash Player from http://fpdownload.macromedia.com/get/flashplayer/current/install_flash_player.exe anymore.
TBR=arv@chromium.org
BUG=62079
TEST=Go to http://www/~bauerb/no_crawl/test/install_plugin.html, turn off your network and click on "Get Plug-in". You should see an error.
Review URL: http://codereview.chromium.org/9149004
TBR=bauerb@chromium.org
Review URL: http://codereview.chromium.org/9190005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@117214 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/chrome_plugin_message_filter.cc | 13 | ||||
-rw-r--r-- | chrome/browser/chrome_plugin_message_filter.h | 6 | ||||
-rw-r--r-- | chrome/browser/plugin_download_helper.cc | 59 | ||||
-rw-r--r-- | chrome/browser/plugin_download_helper.h | 14 | ||||
-rw-r--r-- | chrome/browser/plugin_download_helper_unittest.cc | 120 | ||||
-rw-r--r-- | chrome/browser/plugin_installer.cc | 7 | ||||
-rw-r--r-- | chrome/browser/plugin_installer.h | 1 | ||||
-rw-r--r-- | chrome/browser/plugin_installer_observer.cc | 2 | ||||
-rw-r--r-- | chrome/browser/plugin_installer_observer.h | 3 | ||||
-rw-r--r-- | chrome/browser/plugin_observer.cc | 4 | ||||
-rw-r--r-- | chrome/browser/plugin_test.cc | 100 | ||||
-rw-r--r-- | chrome/browser/resources/plugins_win.json | 3 |
12 files changed, 132 insertions, 200 deletions
diff --git a/chrome/browser/chrome_plugin_message_filter.cc b/chrome/browser/chrome_plugin_message_filter.cc index 072cee3..dadb400 100644 --- a/chrome/browser/chrome_plugin_message_filter.cc +++ b/chrome/browser/chrome_plugin_message_filter.cc @@ -85,13 +85,12 @@ void ChromePluginMessageFilter::OnDownloadUrlOnUIThread( download_url_helper->InitiateDownload( GURL(url), host->GetBrowserContext()->GetRequestContext(), - base::Bind(&ChromePluginMessageFilter::PluginDownloadFinished, - caller_window), - base::Bind(&ChromePluginMessageFilter::PluginDownloadError)); + base::Bind(&ChromePluginMessageFilter::OnPluginDownloadFinished, + caller_window)); } // static -void ChromePluginMessageFilter::PluginDownloadFinished( +void ChromePluginMessageFilter::OnPluginDownloadFinished( gfx::NativeWindow caller_window, const FilePath& response_file) { FilePath::StringType path = response_file.value(); @@ -107,12 +106,6 @@ void ChromePluginMessageFilter::PluginDownloadFinished( reinterpret_cast<LPARAM>(&download_file_data)); } } - -// static -void ChromePluginMessageFilter::PluginDownloadError( - const std::string& error) { - NOTREACHED() << error; -} #endif // OS_WIN void ChromePluginMessageFilter::OnGetPluginFinderUrl( diff --git a/chrome/browser/chrome_plugin_message_filter.h b/chrome/browser/chrome_plugin_message_filter.h index 99d5834..b0d50ab 100644 --- a/chrome/browser/chrome_plugin_message_filter.h +++ b/chrome/browser/chrome_plugin_message_filter.h @@ -41,11 +41,9 @@ class ChromePluginMessageFilter : public IPC::ChannelProxy::MessageFilter, static void OnDownloadUrlOnUIThread(const std::string& url, gfx::NativeWindow caller_window, int render_process_id); - static void PluginDownloadFinished(gfx::NativeWindow caller_window, - const FilePath& response_file); - static void PluginDownloadError(const std::string& error); + static void OnPluginDownloadFinished(gfx::NativeWindow caller_window, + const FilePath& response_file); #endif - void OnGetPluginFinderUrl(std::string* plugin_finder_url); void OnMissingPluginStatus(int status, int render_process_id, diff --git a/chrome/browser/plugin_download_helper.cc b/chrome/browser/plugin_download_helper.cc index faf17dd..f153356 100644 --- a/chrome/browser/plugin_download_helper.cc +++ b/chrome/browser/plugin_download_helper.cc @@ -6,7 +6,6 @@ #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" @@ -14,7 +13,6 @@ #include "net/url_request/url_request_status.h" using content::BrowserThread; -using content::URLFetcher; PluginDownloadUrlHelper::PluginDownloadUrlHelper() { } @@ -25,44 +23,34 @@ PluginDownloadUrlHelper::~PluginDownloadUrlHelper() { void PluginDownloadUrlHelper::InitiateDownload( const GURL& download_url, net::URLRequestContextGetter* request_context, - const DownloadFinishedCallback& finished_callback, - const ErrorCallback& error_callback) { + const DownloadFinishedCallback& 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)); + callback_ = callback; + download_file_fetcher_.reset(content::URLFetcher::Create( + download_url_, content::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) { +void PluginDownloadUrlHelper::OnURLFetchComplete( + const content::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; + if (status.is_success()) { + 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::RunCallback, + base::Unretained(this))); + } else { + NOTREACHED() << "Failed to download the plugin installer: " + << net::ErrorToString(status.error()); + RunCallback(); } - 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() { @@ -83,12 +71,7 @@ void PluginDownloadUrlHelper::RenameDownloadedFile() { } } -void PluginDownloadUrlHelper::RunFinishedCallback() { - download_finished_callback_.Run(downloaded_file_); - delete this; -} - -void PluginDownloadUrlHelper::RunErrorCallback(const std::string& msg) { - error_callback_.Run(msg); +void PluginDownloadUrlHelper::RunCallback() { + callback_.Run(downloaded_file_); delete this; } diff --git a/chrome/browser/plugin_download_helper.h b/chrome/browser/plugin_download_helper.h index 8340888..83036a3 100644 --- a/chrome/browser/plugin_download_helper.h +++ b/chrome/browser/plugin_download_helper.h @@ -26,15 +26,13 @@ class URLRequestContextGetter; 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); + const DownloadFinishedCallback& callback); // content::URLFetcherDelegate virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; @@ -44,11 +42,8 @@ class PluginDownloadUrlHelper : public content::URLFetcherDelegate { // 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); + // Runs the callback and deletes itself. + void RunCallback(); // The download file request initiated by the plugin. scoped_ptr<content::URLFetcher> download_file_fetcher_; @@ -56,8 +51,7 @@ class PluginDownloadUrlHelper : public content::URLFetcherDelegate { GURL download_url_; FilePath downloaded_file_; - DownloadFinishedCallback download_finished_callback_; - ErrorCallback error_callback_; + DownloadFinishedCallback callback_; DISALLOW_COPY_AND_ASSIGN(PluginDownloadUrlHelper); }; diff --git a/chrome/browser/plugin_download_helper_unittest.cc b/chrome/browser/plugin_download_helper_unittest.cc deleted file mode 100644 index 3c581b8..0000000 --- a/chrome/browser/plugin_download_helper_unittest.cc +++ /dev/null @@ -1,120 +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/test/base/ui_test_utils.h" -#include "content/test/test_browser_thread.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() { - initial_download_path_ = ui_test_utils::GetTestUrl( - FilePath(FILE_PATH_LITERAL("plugin")), - FilePath(FILE_PATH_LITERAL("flash.html"))); - 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_ms()); - } - - 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_installer.cc b/chrome/browser/plugin_installer.cc index 0316412..bbdfa6e 100644 --- a/chrome/browser/plugin_installer.cc +++ b/chrome/browser/plugin_installer.cc @@ -46,8 +46,7 @@ void PluginInstaller::StartInstalling( downloader->InitiateDownload( plugin_url_, request_context, - base::Bind(&PluginInstaller::DidFinishDownload, base::Unretained(this)), - base::Bind(&PluginInstaller::DownloadError, base::Unretained(this))); + base::Bind(&PluginInstaller::DidFinishDownload, base::Unretained(this))); } void PluginInstaller::DidFinishDownload(const FilePath& downloaded_file) { @@ -57,7 +56,3 @@ void PluginInstaller::DidFinishDownload(const FilePath& downloaded_file) { FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DidFinishDownload()); platform_util::OpenItem(downloaded_file); } - -void PluginInstaller::DownloadError(const std::string& msg) { - FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadError(msg)); -} diff --git a/chrome/browser/plugin_installer.h b/chrome/browser/plugin_installer.h index 514d919..eef0ca5 100644 --- a/chrome/browser/plugin_installer.h +++ b/chrome/browser/plugin_installer.h @@ -57,7 +57,6 @@ class PluginInstaller { private: void DidFinishDownload(const FilePath& downloaded_file); - void DownloadError(const std::string& msg); State state_; ObserverList<PluginInstallerObserver> observers_; diff --git a/chrome/browser/plugin_installer_observer.cc b/chrome/browser/plugin_installer_observer.cc index 72284c7..ed210ec 100644 --- a/chrome/browser/plugin_installer_observer.cc +++ b/chrome/browser/plugin_installer_observer.cc @@ -23,5 +23,3 @@ void PluginInstallerObserver::DidStartDownload() { void PluginInstallerObserver::DidFinishDownload() { } -void PluginInstallerObserver::DownloadError(const std::string& message) { -} diff --git a/chrome/browser/plugin_installer_observer.h b/chrome/browser/plugin_installer_observer.h index 1d95afd..ac5f881 100644 --- a/chrome/browser/plugin_installer_observer.h +++ b/chrome/browser/plugin_installer_observer.h @@ -6,8 +6,6 @@ #define CHROME_BROWSER_PLUGIN_INSTALLER_OBSERVER_H_ #pragma once -#include <string> - class PluginInstaller; class PluginInstallerObserver { @@ -23,7 +21,6 @@ class PluginInstallerObserver { virtual void DidStartDownload(); virtual void DidFinishDownload(); - virtual void DownloadError(const std::string& message); // 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 fbf4f84..365e054 100644 --- a/chrome/browser/plugin_observer.cc +++ b/chrome/browser/plugin_observer.cc @@ -383,10 +383,6 @@ class PluginObserver::MissingPluginHost : public PluginInstallerObserver { observer_->Send(new ChromeViewMsg_FinishedDownloadingPlugin(routing_id_)); } - virtual void DownloadError(const std::string& msg) OVERRIDE { - observer_->Send(new ChromeViewMsg_ErrorDownloadingPlugin(routing_id_, msg)); - } - private: // Weak pointer; owns us. PluginObserver* observer_; diff --git a/chrome/browser/plugin_test.cc b/chrome/browser/plugin_test.cc index d4639e1..711ef0d 100644 --- a/chrome/browser/plugin_test.cc +++ b/chrome/browser/plugin_test.cc @@ -27,7 +27,9 @@ #include <string> +#include "base/file_path.h" #include "base/file_util.h" +#include "base/message_loop.h" #include "base/path_service.h" #include "base/test/test_timeouts.h" #include "chrome/browser/plugin_download_helper.h" @@ -38,7 +40,10 @@ #include "chrome/test/base/ui_test_utils.h" #include "chrome/test/ui/ui_test.h" #include "content/browser/net/url_request_mock_http_job.h" +#include "content/test/test_browser_thread.h" #include "net/base/net_util.h" +#include "net/url_request/url_request_context_getter.h" +#include "net/url_request/url_request_test_util.h" #include "third_party/npapi/bindings/npapi.h" #include "webkit/plugins/npapi/plugin_constants_win.h" #include "webkit/plugins/npapi/plugin_list.h" @@ -246,3 +251,98 @@ TEST_F(PluginTest, Silverlight) { TestTimeouts::action_max_timeout_ms(), false); } #endif // defined(OS_WIN) + +#if !defined(OS_CHROMEOS) +namespace { + +class TestURLRequestContextGetter : public net::URLRequestContextGetter { + public: + explicit 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() { + initial_download_path_ = PluginTest::GetTestUrl("flash.html", "", false); + download_helper_ = new PluginDownloadUrlHelper(); + TestURLRequestContextGetter* context_getter = + new TestURLRequestContextGetter; + download_helper_->InitiateDownload( + initial_download_path_, + context_getter, + base::Bind(&PluginInstallerDownloadTest::OnDownloadCompleted, + base::Unretained(this))); + + message_loop_.PostDelayedTask( + FROM_HERE, MessageLoop::QuitClosure(), + TestTimeouts::action_max_timeout_ms()); + } + + void OnDownloadCompleted(const FilePath& download_path) { + success_ = true; + final_download_path_ = download_path; + 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(); + + EXPECT_TRUE(success()); + EXPECT_TRUE(initial_download_path().BaseName().value() == + final_download_path().BaseName().value()); +} +#endif // !defined(OS_CHROMEOS) diff --git a/chrome/browser/resources/plugins_win.json b/chrome/browser/resources/plugins_win.json index 0bda3ae..0aaf512 100644 --- a/chrome/browser/resources/plugins_win.json +++ b/chrome/browser/resources/plugins_win.json @@ -63,8 +63,7 @@ "name": "Adobe Flash Player", "identifier": "adobe-flash-player", "help_url": "https://support.google.com/chrome/?p=plugin_flash", - "url": "http://get.adobe.com/flashplayer/", - "displayurl": true + "url": "http://fpdownload.adobe.com/get/flashplayer/current/install_flash_player.exe" }, { "mime_types": [ |