diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-19 20:49:52 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-19 20:49:52 +0000 |
commit | a0ce3284a4fb3aee664c8ad998fb6c4d4b8d0080 (patch) | |
tree | 2a160a7305bbf6ef8f02249fa2c86af28676263c /content | |
parent | dcc592a99ae6a563a200cf253d1d3856c511582d (diff) | |
download | chromium_src-a0ce3284a4fb3aee664c8ad998fb6c4d4b8d0080.zip chromium_src-a0ce3284a4fb3aee664c8ad998fb6c4d4b8d0080.tar.gz chromium_src-a0ce3284a4fb3aee664c8ad998fb6c4d4b8d0080.tar.bz2 |
Move simple download calls to chrome code to use ContentBrowserClient interface.
BUG=82782
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=97477
Review URL: http://codereview.chromium.org/7670086
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97506 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/browser/content_browser_client.h | 7 | ||||
-rw-r--r-- | content/browser/download/download_item.cc | 83 | ||||
-rw-r--r-- | content/browser/download/download_item.h | 6 | ||||
-rw-r--r-- | content/browser/download/download_manager.cc | 32 | ||||
-rw-r--r-- | content/browser/download/download_resource_handler.h | 6 | ||||
-rw-r--r-- | content/browser/mock_content_browser_client.cc | 5 | ||||
-rw-r--r-- | content/browser/mock_content_browser_client.h | 3 | ||||
-rw-r--r-- | content/browser/renderer_host/browser_render_process_host.cc | 2 |
8 files changed, 75 insertions, 69 deletions
diff --git a/content/browser/content_browser_client.h b/content/browser/content_browser_client.h index 2c5947c..9eee934 100644 --- a/content/browser/content_browser_client.h +++ b/content/browser/content_browser_client.h @@ -158,8 +158,11 @@ class ContentBrowserClient { // Create and return a new quota permission context. virtual QuotaPermissionContext* CreateQuotaPermissionContext() = 0; - // Shows the given path using the OS file manager. - virtual void RevealFolderInOS(const FilePath& path) = 0; + // Open the given file in the desktop's default manner. + virtual void OpenItem(const FilePath& path) = 0; + + // Show the given file in a file manager. If possible, select the file. + virtual void ShowItemInFolder(const FilePath& path) = 0; // Informs the embedder that a certificate error has occured. If overridable // is true, the user can ignore the error and continue. If it's false, then diff --git a/content/browser/download/download_item.cc b/content/browser/download/download_item.cc index 508185d8..277fdc0 100644 --- a/content/browser/download/download_item.cc +++ b/content/browser/download/download_item.cc @@ -17,21 +17,18 @@ #include "chrome/browser/download/download_crx_util.h" #include "chrome/browser/download/download_extensions.h" #include "chrome/browser/download/download_history.h" -#include "chrome/browser/download/download_prefs.h" #include "chrome/browser/download/download_util.h" #include "chrome/browser/extensions/crx_installer.h" #include "chrome/browser/history/download_history_info.h" -#include "chrome/browser/platform_util.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/pref_names.h" #include "content/browser/browser_thread.h" +#include "content/browser/content_browser_client.h" #include "content/browser/download/download_create_info.h" #include "content/browser/download/download_file_manager.h" #include "content/browser/download/download_manager.h" #include "content/browser/download/download_manager_delegate.h" +#include "content/browser/download/download_request_handle.h" #include "content/browser/download/download_stats.h" #include "content/common/notification_source.h" @@ -261,63 +258,45 @@ bool DownloadItem::ShouldOpenFileBasedOnExtension() { GetUserVerifiedFilePath()); } -void DownloadItem::OpenFilesBasedOnExtension(bool open) { - DownloadPrefs* prefs = download_manager_->download_prefs(); - if (open) - prefs->EnableAutoOpenBasedOnExtension(GetUserVerifiedFilePath()); - else - prefs->DisableAutoOpenBasedOnExtension(GetUserVerifiedFilePath()); -} - void DownloadItem::OpenDownload() { // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); if (IsPartialDownload()) { open_when_complete_ = !open_when_complete_; - } else if (IsComplete() && !file_externally_removed_) { - // Ideally, we want to detect errors in opening and report them, but we - // don't generally have the proper interface for that to the external - // program that opens the file. So instead we spawn a check to update - // the UI if the file has been deleted in parallel with the open. - download_manager_->CheckForFileRemoval(this); - opened_ = true; - FOR_EACH_OBSERVER(Observer, observers_, OnDownloadOpened(this)); - - // For testing: If download opening is disabled on this item, - // make the rest of the routine a no-op. - if (!open_enabled_) - return; - - if (is_extension_install()) { - download_crx_util::OpenChromeExtension(download_manager_->profile(), - *this); - return; - } -#if defined(OS_MACOSX) - // Mac OS X requires opening downloads on the UI thread. - platform_util::OpenItem(full_path()); -#else - BrowserThread::PostTask( - BrowserThread::FILE, FROM_HERE, - NewRunnableFunction(&platform_util::OpenItem, full_path())); -#endif + return; + } + + if (!IsComplete() || file_externally_removed_) + return; + + // Ideally, we want to detect errors in opening and report them, but we + // don't generally have the proper interface for that to the external + // program that opens the file. So instead we spawn a check to update + // the UI if the file has been deleted in parallel with the open. + download_manager_->CheckForFileRemoval(this); + opened_ = true; + FOR_EACH_OBSERVER(Observer, observers_, OnDownloadOpened(this)); + + // For testing: If download opening is disabled on this item, + // make the rest of the routine a no-op. + if (!open_enabled_) + return; + + if (is_extension_install()) { + download_crx_util::OpenChromeExtension(download_manager_->profile(), + *this); + return; } + + content::GetContentClient()->browser()->OpenItem(full_path()); } void DownloadItem::ShowDownloadInShell() { // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); -#if defined(OS_MACOSX) - // Mac needs to run this operation on the UI thread. - platform_util::ShowItemInFolder(full_path()); -#else - BrowserThread::PostTask( - BrowserThread::FILE, FROM_HERE, - NewRunnableFunction(&platform_util::ShowItemInFolder, - full_path())); -#endif + content::GetContentClient()->browser()->ShowItemInFolder(full_path()); } void DownloadItem::DangerousDownloadValidated() { @@ -693,8 +672,10 @@ bool DownloadItem::MatchesQuery(const string16& query) const { // "/\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xbd\xa0\xe5\xa5\xbd", // L"/\x4f60\x597d\x4f60\x597d", // "/%E4%BD%A0%E5%A5%BD%E4%BD%A0%E5%A5%BD" - PrefService* prefs = download_manager_->profile()->GetPrefs(); - std::string languages(prefs->GetString(prefs::kAcceptLanguages)); + std::string languages; + TabContents* tab = request_handle_.GetTabContents(); + if (tab) + languages = content::GetContentClient()->browser()->GetAcceptLangs(tab); string16 url_formatted( base::i18n::ToLower(net::FormatUrl(GetURL(), languages))); if (url_formatted.find(query) != string16::npos) diff --git a/content/browser/download/download_item.h b/content/browser/download/download_item.h index 3a90253..a2fd5d4 100644 --- a/content/browser/download/download_item.h +++ b/content/browser/download/download_item.h @@ -145,11 +145,6 @@ class DownloadItem : public NotificationObserver { // Tests if a file type should be opened automatically. bool ShouldOpenFileBasedOnExtension(); - // Registers this file extension for automatic opening upon download - // completion if 'open' is true, or prevents the extension from automatic - // opening if 'open' is false. - void OpenFilesBasedOnExtension(bool open); - // Open the file associated with this download (wait for the download to // complete if it is in progress). void OpenDownload(); @@ -280,6 +275,7 @@ class DownloadItem : public NotificationObserver { base::Time start_time() const { return start_time_; } void set_db_handle(int64 handle) { db_handle_ = handle; } int64 db_handle() const { return db_handle_; } + DownloadManager* download_manager() { return download_manager_; } bool is_paused() const { return is_paused_; } bool open_when_complete() const { return open_when_complete_; } void set_open_when_complete(bool open) { open_when_complete_ = open; } diff --git a/content/browser/download/download_manager.cc b/content/browser/download/download_manager.cc index 8808a10..f84742c 100644 --- a/content/browser/download/download_manager.cc +++ b/content/browser/download/download_manager.cc @@ -11,13 +11,13 @@ #include "base/stl_util.h" #include "base/task.h" #include "build/build_config.h" -#include "chrome/browser/browser_process.h" #include "chrome/browser/download/download_history.h" #include "chrome/browser/download/download_prefs.h" #include "chrome/browser/download/download_util.h" #include "chrome/browser/history/download_history_info.h" #include "chrome/browser/profiles/profile.h" #include "content/browser/browser_thread.h" +#include "content/browser/content_browser_client.h" #include "content/browser/download/download_create_info.h" #include "content/browser/download/download_file_manager.h" #include "content/browser/download/download_item.h" @@ -30,6 +30,29 @@ #include "content/common/content_notification_types.h" #include "content/common/notification_service.h" +namespace { + +void BeginDownload( + const GURL& url, + const GURL& referrer, + const DownloadSaveInfo& save_info, + int render_process_host_id, + int render_view_id, + const content::ResourceContext* context) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + + content::GetContentClient()->browser()->GetResourceDispatcherHost()-> + BeginDownload(url, + referrer, + save_info, + true, // Show "Save as" UI. + render_process_host_id, + render_view_id, + *context); +} + +} // namespace + DownloadManager::DownloadManager(DownloadManagerDelegate* delegate, DownloadStatusUpdater* status_updater) : shutdown_needed_(false), @@ -215,7 +238,8 @@ bool DownloadManager::Init(Profile* profile) { // In test mode, there may be no ResourceDispatcherHost. In this case it's // safe to avoid setting |file_manager_| because we only call a small set of // functions, none of which need it. - ResourceDispatcherHost* rdh = g_browser_process->resource_dispatcher_host(); + ResourceDispatcherHost* rdh = + content::GetContentClient()->browser()->GetResourceDispatcherHost(); if (rdh) { file_manager_ = rdh->download_file_manager(); DCHECK(file_manager_); @@ -715,12 +739,10 @@ void DownloadManager::DownloadUrlToFile(const GURL& url, // We send a pointer to content::ResourceContext, instead of the usual // reference, so that a copy of the object isn't made. BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, - NewRunnableFunction(&download_util::DownloadUrl, + NewRunnableFunction(&BeginDownload, url, referrer, - referrer_charset, save_info, - g_browser_process->resource_dispatcher_host(), tab_contents->GetRenderProcessHost()->id(), tab_contents->render_view_host()->routing_id(), &tab_contents->browser_context()-> diff --git a/content/browser/download/download_resource_handler.h b/content/browser/download/download_resource_handler.h index 7fe55f7..b4cdbd6 100644 --- a/content/browser/download/download_resource_handler.h +++ b/content/browser/download/download_resource_handler.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_BROWSER_RENDERER_HOST_DOWNLOAD_RESOURCE_HANDLER_H_ -#define CONTENT_BROWSER_RENDERER_HOST_DOWNLOAD_RESOURCE_HANDLER_H_ +#ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ +#define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ #pragma once #include <string> @@ -97,4 +97,4 @@ class DownloadResourceHandler : public ResourceHandler { DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); }; -#endif // CONTENT_BROWSER_RENDERER_HOST_DOWNLOAD_RESOURCE_HANDLER_H_ +#endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ diff --git a/content/browser/mock_content_browser_client.cc b/content/browser/mock_content_browser_client.cc index eaae014..c1115e1 100644 --- a/content/browser/mock_content_browser_client.cc +++ b/content/browser/mock_content_browser_client.cc @@ -111,7 +111,10 @@ net::URLRequestContext* MockContentBrowserClient::OverrideRequestContextForURL( return NULL; } -void MockContentBrowserClient::RevealFolderInOS(const FilePath& path) { +void MockContentBrowserClient::OpenItem(const FilePath& path) { +} + +void MockContentBrowserClient::ShowItemInFolder(const FilePath& path) { } void MockContentBrowserClient::AllowCertificateError( diff --git a/content/browser/mock_content_browser_client.h b/content/browser/mock_content_browser_client.h index 956d53e..0c16ce7 100644 --- a/content/browser/mock_content_browser_client.h +++ b/content/browser/mock_content_browser_client.h @@ -53,7 +53,8 @@ class MockContentBrowserClient : public ContentBrowserClient { virtual net::URLRequestContext* OverrideRequestContextForURL( const GURL& url, const content::ResourceContext& context) OVERRIDE; virtual QuotaPermissionContext* CreateQuotaPermissionContext() OVERRIDE; - virtual void RevealFolderInOS(const FilePath& path) OVERRIDE; + virtual void OpenItem(const FilePath& path) OVERRIDE; + virtual void ShowItemInFolder(const FilePath& path) OVERRIDE; virtual void AllowCertificateError( SSLCertErrorHandler* handler, bool overridable, diff --git a/content/browser/renderer_host/browser_render_process_host.cc b/content/browser/renderer_host/browser_render_process_host.cc index 5fbb790..3b06191 100644 --- a/content/browser/renderer_host/browser_render_process_host.cc +++ b/content/browser/renderer_host/browser_render_process_host.cc @@ -938,7 +938,7 @@ void BrowserRenderProcessHost::OnUserMetricsRecordAction( void BrowserRenderProcessHost::OnRevealFolderInOS(const FilePath& path) { // Only honor the request if appropriate persmissions are granted. if (ChildProcessSecurityPolicy::GetInstance()->CanReadFile(id(), path)) - content::GetContentClient()->browser()->RevealFolderInOS(path); + content::GetContentClient()->browser()->OpenItem(path); } void BrowserRenderProcessHost::OnSavedPageAsMHTML(int job_id, bool success) { |