diff options
author | wez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-19 17:55:42 +0000 |
---|---|---|
committer | wez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-19 17:55:42 +0000 |
commit | 61b2503325818c6ed8b4c983a342598c09d90d11 (patch) | |
tree | 68a14eb22ef489bcc48ad0e974c70a9f3287990a | |
parent | bbc81ba76805f35e7b9ce4fe5bb9355c5011d5ee (diff) | |
download | chromium_src-61b2503325818c6ed8b4c983a342598c09d90d11.zip chromium_src-61b2503325818c6ed8b4c983a342598c09d90d11.tar.gz chromium_src-61b2503325818c6ed8b4c983a342598c09d90d11.tar.bz2 |
Revert 97477 - Move simple download calls to chrome code to use ContentBrowserClient interface.
BUG=82782
Review URL: http://codereview.chromium.org/7670086
TBR=jam@chromium.org
Review URL: http://codereview.chromium.org/7697002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97478 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/automation/testing_automation_provider.cc | 5 | ||||
-rw-r--r-- | chrome/browser/chrome_content_browser_client.cc | 13 | ||||
-rw-r--r-- | chrome/browser/chrome_content_browser_client.h | 3 | ||||
-rw-r--r-- | chrome/browser/download/download_shelf_context_menu.cc | 15 | ||||
-rw-r--r-- | chrome/browser/download/download_shelf_context_menu.h | 5 | ||||
-rw-r--r-- | chrome/browser/download/download_util.cc | 20 | ||||
-rw-r--r-- | chrome/browser/download/download_util.h | 10 | ||||
-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/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 |
14 files changed, 102 insertions, 107 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index ad67018..e41a701 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -44,7 +44,6 @@ #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/debugger/devtools_window.h" #include "chrome/browser/download/download_prefs.h" -#include "chrome/browser/download/download_shelf_context_menu.h" #include "chrome/browser/download/save_package_file_picker.h" #include "chrome/browser/extensions/extension_host.h" #include "chrome/browser/extensions/extension_service.h" @@ -3020,8 +3019,8 @@ void TestingAutomationProvider::PerformActionOnDownload( this, reply_message, true)); selected_item->OpenDownload(); } else if (action == "toggle_open_files_like_this") { - DownloadShelfContextMenu::OpenFilesBasedOnExtension( - selected_item, !selected_item->ShouldOpenFileBasedOnExtension()); + selected_item->OpenFilesBasedOnExtension( + !selected_item->ShouldOpenFileBasedOnExtension()); AutomationJSONReply(this, reply_message).SendSuccess(NULL); } else if (action == "remove") { download_manager->AddObserver( diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index e89776d..f6f3f13 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -423,7 +423,7 @@ ChromeContentBrowserClient::CreateQuotaPermissionContext() { return new ChromeQuotaPermissionContext(); } -void ChromeContentBrowserClient::OpenItem(const FilePath& path) { +void ChromeContentBrowserClient::RevealFolderInOS(const FilePath& path) { // On Mac, this call needs to be done on the UI thread. On other platforms, // do it on the FILE thread so we don't slow down UI. #if defined(OS_MACOSX) @@ -435,17 +435,6 @@ void ChromeContentBrowserClient::OpenItem(const FilePath& path) { #endif } -void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) { -#if defined(OS_MACOSX) - // Mac needs to run this operation on the UI thread. - platform_util::ShowItemInFolder(path); -#else - BrowserThread::PostTask( - BrowserThread::FILE, FROM_HERE, - NewRunnableFunction(&platform_util::ShowItemInFolder, path)); -#endif -} - void ChromeContentBrowserClient::AllowCertificateError( SSLCertErrorHandler* handler, bool overridable, diff --git a/chrome/browser/chrome_content_browser_client.h b/chrome/browser/chrome_content_browser_client.h index 95858ab..aee1a1be 100644 --- a/chrome/browser/chrome_content_browser_client.h +++ b/chrome/browser/chrome_content_browser_client.h @@ -51,8 +51,7 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient { virtual net::URLRequestContext* OverrideRequestContextForURL( const GURL& url, const content::ResourceContext& context) OVERRIDE; virtual QuotaPermissionContext* CreateQuotaPermissionContext() OVERRIDE; - virtual void OpenItem(const FilePath& path) OVERRIDE; - virtual void ShowItemInFolder(const FilePath& path) OVERRIDE; + virtual void RevealFolderInOS(const FilePath& path) OVERRIDE; virtual void AllowCertificateError( SSLCertErrorHandler* handler, bool overridable, diff --git a/chrome/browser/download/download_shelf_context_menu.cc b/chrome/browser/download/download_shelf_context_menu.cc index 839bc1b..7182e1e 100644 --- a/chrome/browser/download/download_shelf_context_menu.cc +++ b/chrome/browser/download/download_shelf_context_menu.cc @@ -5,23 +5,12 @@ #include "chrome/browser/download/download_shelf_context_menu.h" #include "chrome/browser/download/download_item_model.h" -#include "chrome/browser/download/download_prefs.h" #include "content/browser/download/download_item.h" -#include "content/browser/download/download_manager.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" DownloadShelfContextMenu::~DownloadShelfContextMenu() {} -void DownloadShelfContextMenu::OpenFilesBasedOnExtension(DownloadItem* item, - bool open) { - DownloadPrefs* prefs = item->download_manager()->download_prefs(); - if (open) - prefs->EnableAutoOpenBasedOnExtension(item->GetUserVerifiedFilePath()); - else - prefs->DisableAutoOpenBasedOnExtension(item->GetUserVerifiedFilePath()); -} - DownloadShelfContextMenu::DownloadShelfContextMenu( BaseDownloadItemModel* download_model) : download_model_(download_model), @@ -70,8 +59,8 @@ void DownloadShelfContextMenu::ExecuteCommand(int command_id) { download_item_->OpenDownload(); break; case ALWAYS_OPEN_TYPE: { - OpenFilesBasedOnExtension(download_item_, - !IsCommandIdChecked(ALWAYS_OPEN_TYPE)); + download_item_->OpenFilesBasedOnExtension( + !IsCommandIdChecked(ALWAYS_OPEN_TYPE)); break; } case CANCEL: diff --git a/chrome/browser/download/download_shelf_context_menu.h b/chrome/browser/download/download_shelf_context_menu.h index 82ee567..3e7c47d 100644 --- a/chrome/browser/download/download_shelf_context_menu.h +++ b/chrome/browser/download/download_shelf_context_menu.h @@ -33,11 +33,6 @@ class DownloadShelfContextMenu : public ui::SimpleMenuModel::Delegate { DownloadItem* download_item() const { return download_item_; } void set_download_item(DownloadItem* item) { download_item_ = item; } - // Registers the file's extension for automatic opening upon download - // completion if 'open' is true, or prevents the extension from automatic - // opening if 'open' is false. - static void OpenFilesBasedOnExtension(DownloadItem* item, bool open); - protected: explicit DownloadShelfContextMenu(BaseDownloadItemModel* download_model); diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc index a363d13..33b77ab 100644 --- a/chrome/browser/download/download_util.cc +++ b/chrome/browser/download/download_util.cc @@ -612,6 +612,26 @@ int GetUniquePathNumber(const FilePath& path) { return -1; } +void DownloadUrl( + const GURL& url, + const GURL& referrer, + const std::string& referrer_charset, + const DownloadSaveInfo& save_info, + ResourceDispatcherHost* rdh, + int render_process_host_id, + int render_view_id, + const content::ResourceContext* context) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + + rdh->BeginDownload(url, + referrer, + save_info, + true, // Show "Save as" UI. + render_process_host_id, + render_view_id, + *context); +} + int GetUniquePathNumberWithCrDownload(const FilePath& path) { if (!file_util::PathExists(path) && !file_util::PathExists(GetCrDownloadPath(path))) diff --git a/chrome/browser/download/download_util.h b/chrome/browser/download/download_util.h index 8b6b1d4..fb5886d 100644 --- a/chrome/browser/download/download_util.h +++ b/chrome/browser/download/download_util.h @@ -181,6 +181,16 @@ void AppendNumberToPath(FilePath* path, int number); // a number, -1 is returned. int GetUniquePathNumber(const FilePath& path); +// Download the URL. Must be called on the IO thread. +void DownloadUrl(const GURL& url, + const GURL& referrer, + const std::string& referrer_charset, + const DownloadSaveInfo& save_info, + ResourceDispatcherHost* rdh, + int render_process_host_id, + int render_view_id, + const content::ResourceContext* context); + // Same as GetUniquePathNumber, except that it also checks the existence // of its .crdownload intermediate path. // If |path| does not exist, 0 is returned. If it fails to find such diff --git a/content/browser/content_browser_client.h b/content/browser/content_browser_client.h index 9eee934..2c5947c 100644 --- a/content/browser/content_browser_client.h +++ b/content/browser/content_browser_client.h @@ -158,11 +158,8 @@ class ContentBrowserClient { // Create and return a new quota permission context. virtual QuotaPermissionContext* CreateQuotaPermissionContext() = 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; + // Shows the given path using the OS file manager. + virtual void RevealFolderInOS(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 277fdc0..508185d8 100644 --- a/content/browser/download/download_item.cc +++ b/content/browser/download/download_item.cc @@ -17,18 +17,21 @@ #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" @@ -258,45 +261,63 @@ 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_; - 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; + } 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 } - - 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)); - content::GetContentClient()->browser()->ShowItemInFolder(full_path()); +#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 } void DownloadItem::DangerousDownloadValidated() { @@ -672,10 +693,8 @@ 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" - std::string languages; - TabContents* tab = request_handle_.GetTabContents(); - if (tab) - languages = content::GetContentClient()->browser()->GetAcceptLangs(tab); + PrefService* prefs = download_manager_->profile()->GetPrefs(); + std::string languages(prefs->GetString(prefs::kAcceptLanguages)); 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 a2fd5d4..3a90253 100644 --- a/content/browser/download/download_item.h +++ b/content/browser/download/download_item.h @@ -145,6 +145,11 @@ 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(); @@ -275,7 +280,6 @@ 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 f84742c..8808a10 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,29 +30,6 @@ #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), @@ -238,8 +215,7 @@ 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 = - content::GetContentClient()->browser()->GetResourceDispatcherHost(); + ResourceDispatcherHost* rdh = g_browser_process->resource_dispatcher_host(); if (rdh) { file_manager_ = rdh->download_file_manager(); DCHECK(file_manager_); @@ -739,10 +715,12 @@ 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(&BeginDownload, + NewRunnableFunction(&download_util::DownloadUrl, 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/mock_content_browser_client.cc b/content/browser/mock_content_browser_client.cc index c1115e1..eaae014 100644 --- a/content/browser/mock_content_browser_client.cc +++ b/content/browser/mock_content_browser_client.cc @@ -111,10 +111,7 @@ net::URLRequestContext* MockContentBrowserClient::OverrideRequestContextForURL( return NULL; } -void MockContentBrowserClient::OpenItem(const FilePath& path) { -} - -void MockContentBrowserClient::ShowItemInFolder(const FilePath& path) { +void MockContentBrowserClient::RevealFolderInOS(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 0c16ce7..956d53e 100644 --- a/content/browser/mock_content_browser_client.h +++ b/content/browser/mock_content_browser_client.h @@ -53,8 +53,7 @@ class MockContentBrowserClient : public ContentBrowserClient { virtual net::URLRequestContext* OverrideRequestContextForURL( const GURL& url, const content::ResourceContext& context) OVERRIDE; virtual QuotaPermissionContext* CreateQuotaPermissionContext() OVERRIDE; - virtual void OpenItem(const FilePath& path) OVERRIDE; - virtual void ShowItemInFolder(const FilePath& path) OVERRIDE; + virtual void RevealFolderInOS(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 256fb91..4807523 100644 --- a/content/browser/renderer_host/browser_render_process_host.cc +++ b/content/browser/renderer_host/browser_render_process_host.cc @@ -922,7 +922,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()->OpenItem(path); + content::GetContentClient()->browser()->RevealFolderInOS(path); } void BrowserRenderProcessHost::OnSavedPageAsMHTML(int job_id, bool success) { |