diff options
-rw-r--r-- | chrome/browser/automation/testing_automation_provider.cc | 8 | ||||
-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 | 11 | ||||
-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/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 |
14 files changed, 104 insertions, 105 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index dbbd3a4..d4738f5 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -3019,8 +3019,12 @@ void TestingAutomationProvider::PerformActionOnDownload( this, reply_message, true)); selected_item->OpenDownload(); } else if (action == "toggle_open_files_like_this") { - selected_item->OpenFilesBasedOnExtension( - !selected_item->ShouldOpenFileBasedOnExtension()); + DownloadPrefs* prefs = selected_item->download_manager()->download_prefs(); + FilePath path = selected_item->GetUserVerifiedFilePath(); + if (!selected_item->ShouldOpenFileBasedOnExtension()) + prefs->EnableAutoOpenBasedOnExtension(path); + else + prefs->DisableAutoOpenBasedOnExtension(path); 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 f6f3f13..e89776d 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::RevealFolderInOS(const FilePath& path) { +void ChromeContentBrowserClient::OpenItem(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,6 +435,17 @@ void ChromeContentBrowserClient::RevealFolderInOS(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 aee1a1be..95858ab 100644 --- a/chrome/browser/chrome_content_browser_client.h +++ b/chrome/browser/chrome_content_browser_client.h @@ -51,7 +51,8 @@ class ChromeContentBrowserClient : public content::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/chrome/browser/download/download_shelf_context_menu.cc b/chrome/browser/download/download_shelf_context_menu.cc index 7182e1e..f5e50b9 100644 --- a/chrome/browser/download/download_shelf_context_menu.cc +++ b/chrome/browser/download/download_shelf_context_menu.cc @@ -5,7 +5,9 @@ #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" @@ -59,8 +61,13 @@ void DownloadShelfContextMenu::ExecuteCommand(int command_id) { download_item_->OpenDownload(); break; case ALWAYS_OPEN_TYPE: { - download_item_->OpenFilesBasedOnExtension( - !IsCommandIdChecked(ALWAYS_OPEN_TYPE)); + DownloadPrefs* prefs = + download_item_->download_manager()->download_prefs(); + FilePath path = download_item_->GetUserVerifiedFilePath(); + if (!IsCommandIdChecked(ALWAYS_OPEN_TYPE)) + prefs->EnableAutoOpenBasedOnExtension(path); + else + prefs->DisableAutoOpenBasedOnExtension(path); break; } case CANCEL: diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc index 33b77ab..a363d13 100644 --- a/chrome/browser/download/download_util.cc +++ b/chrome/browser/download/download_util.cc @@ -612,26 +612,6 @@ 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 fb5886d..8b6b1d4 100644 --- a/chrome/browser/download/download_util.h +++ b/chrome/browser/download/download_util.h @@ -181,16 +181,6 @@ 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 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) { |