diff options
20 files changed, 139 insertions, 240 deletions
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc index 54d937b..fb9fb7b 100644 --- a/chrome/browser/download/download_manager.cc +++ b/chrome/browser/download/download_manager.cc @@ -33,8 +33,6 @@ #include "chrome/browser/tab_contents/tab_util.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_list.h" -#include "chrome/browser/ui/download/download_tab_helper.h" -#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/chrome_paths.h" #include "content/browser/browser_thread.h" #include "content/browser/renderer_host/render_process_host.h" @@ -1071,23 +1069,20 @@ void DownloadManager::ShowDownloadInBrowser( // get this start completion event. If it does, tell the origin TabContents // to display its download shelf. TabContents* contents = process_handle->GetTabContents(); - TabContentsWrapper* wrapper = NULL; - if (contents) - wrapper = TabContentsWrapper::GetCurrentWrapperForContents(contents); // If the contents no longer exists, we start the download in the last active // browser. This is not ideal but better than fully hiding the download from // the user. - if (!wrapper) { + if (!contents) { Browser* last_active = BrowserList::GetLastActive(); if (last_active) - wrapper = last_active->GetSelectedTabContentsWrapper(); + contents = last_active->GetSelectedTabContents(); } - if (!wrapper) + if (!contents) return; - wrapper->download_tab_helper()->OnStartDownload(download); + contents->OnStartDownload(download); } // Clears the last download path, used to initialize "save as" dialogs. diff --git a/chrome/browser/download/download_request_limiter.cc b/chrome/browser/download/download_request_limiter.cc index b39e1f6..579c172 100644 --- a/chrome/browser/download/download_request_limiter.cc +++ b/chrome/browser/download/download_request_limiter.cc @@ -12,8 +12,6 @@ #include "content/browser/tab_contents/navigation_entry.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents_delegate.h" -#include "chrome/browser/ui/download/download_tab_helper.h" -#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "content/common/notification_source.h" // TabDownloadState ------------------------------------------------------------ @@ -258,9 +256,7 @@ void DownloadRequestLimiter::CanDownloadImpl( // FYI: Chrome Frame overrides CanDownload in ExternalTabContainer in order // to cancel the download operation in chrome and let the host browser // take care of it. - TabContentsWrapper* wrapper = - TabContentsWrapper::GetCurrentWrapperForContents(originating_tab); - if (!wrapper->download_tab_helper()->CanDownload(request_id)) { + if (!originating_tab->CanDownload(request_id)) { ScheduleNotification(callback, false); return; } diff --git a/chrome/browser/download/download_request_limiter_unittest.cc b/chrome/browser/download/download_request_limiter_unittest.cc index 9cdb3c3..d4422d1 100644 --- a/chrome/browser/download/download_request_limiter_unittest.cc +++ b/chrome/browser/download/download_request_limiter_unittest.cc @@ -1,23 +1,23 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2008 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/download/download_request_limiter.h" -#include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" #include "chrome/test/testing_profile.h" #include "content/browser/browser_thread.h" +#include "content/browser/renderer_host/test_render_view_host.h" #include "content/browser/tab_contents/navigation_controller.h" #include "testing/gtest/include/gtest/gtest.h" class DownloadRequestLimiterTest - : public TabContentsWrapperTestHarness, + : public RenderViewHostTestHarness, public DownloadRequestLimiter::Callback { public: DownloadRequestLimiterTest() : io_thread_(BrowserThread::IO, &message_loop_) { } virtual void SetUp() { - TabContentsWrapperTestHarness::SetUp(); + RenderViewHostTestHarness::SetUp(); allow_download_ = true; ask_allow_count_ = cancel_count_ = continue_count_ = 0; @@ -30,7 +30,7 @@ class DownloadRequestLimiterTest virtual void TearDown() { DownloadRequestLimiter::SetTestingDelegate(NULL); - TabContentsWrapperTestHarness::TearDown(); + RenderViewHostTestHarness::TearDown(); } virtual void ContinueDownload() { diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc index d18099c..cf9d4dc 100644 --- a/chrome/browser/download/save_package.cc +++ b/chrome/browser/download/save_package.cc @@ -34,7 +34,6 @@ #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/tab_contents/tab_util.h" -#include "chrome/browser/ui/download/download_tab_helper.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/pref_names.h" @@ -327,7 +326,7 @@ bool SavePackage::Init() { // to be alive as long as the Profile is alive. download_manager->SavePageAsDownloadStarted(download_); - wrapper_->download_tab_helper()->OnStartDownload(download_); + tab_contents()->OnStartDownload(download_); // Check save type and process the save page job. if (save_type_ == SAVE_AS_COMPLETE_HTML) { diff --git a/chrome/browser/external_tab_container_win.cc b/chrome/browser/external_tab_container_win.cc index 1ba4ee1..b3787d7 100644 --- a/chrome/browser/external_tab_container_win.cc +++ b/chrome/browser/external_tab_container_win.cc @@ -159,7 +159,6 @@ bool ExternalTabContainer::Init(Profile* profile, } tab_contents_->tab_contents()->set_delegate(this); - tab_contents_->download_tab_helper()->set_delegate(this); tab_contents_->tab_contents()-> GetMutableRendererPrefs()->browser_handles_top_level_requests = @@ -540,6 +539,26 @@ bool ExternalTabContainer::TakeFocus(bool reverse) { return true; } +bool ExternalTabContainer::CanDownload(int request_id) { + if (load_requests_via_automation_) { + if (automation_) { + // In case the host needs to show UI that needs to take the focus. + ::AllowSetForegroundWindow(ASFW_ANY); + + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, + NewRunnableMethod(automation_resource_message_filter_.get(), + &AutomationResourceMessageFilter::SendDownloadRequestToHost, + 0, tab_handle_, request_id)); + } + } else { + DLOG(WARNING) << "Downloads are only supported with host browser network " + "stack enabled."; + } + + // Never allow downloads. + return false; +} + void ExternalTabContainer::ShowPageInfo(Profile* profile, const GURL& url, const NavigationEntry::SSLStatus& ssl, @@ -765,34 +784,6 @@ void ExternalTabContainer::Observe(NotificationType type, } //////////////////////////////////////////////////////////////////////////////// -// ExternalTabContainer, DownloadTabHelperDelegate overrides: - -bool ExternalTabContainer::CanDownload(int request_id) { - if (load_requests_via_automation_) { - if (automation_) { - // In case the host needs to show UI that needs to take the focus. - ::AllowSetForegroundWindow(ASFW_ANY); - - BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, - NewRunnableMethod(automation_resource_message_filter_.get(), - &AutomationResourceMessageFilter::SendDownloadRequestToHost, - 0, tab_handle_, request_id)); - } - } else { - DLOG(WARNING) << "Downloads are only supported with host browser network " - "stack enabled."; - } - - // Never allow downloads. - return false; -} - -void ExternalTabContainer::OnStartDownload(DownloadItem* download, - TabContentsWrapper* tab) { -} - - -//////////////////////////////////////////////////////////////////////////////// // ExternalTabContainer, views::WidgetWin overrides: LRESULT ExternalTabContainer::OnCreate(LPCREATESTRUCT create_struct) { diff --git a/chrome/browser/external_tab_container_win.h b/chrome/browser/external_tab_container_win.h index d6c73c0..2e82237 100644 --- a/chrome/browser/external_tab_container_win.h +++ b/chrome/browser/external_tab_container_win.h @@ -14,7 +14,6 @@ #include "base/memory/scoped_ptr.h" #include "chrome/browser/automation/automation_resource_message_filter.h" #include "chrome/browser/net/chrome_url_request_context.h" -#include "chrome/browser/ui/download/download_tab_helper_delegate.h" #include "chrome/browser/ui/views/frame/browser_bubble_host.h" #include "chrome/browser/ui/views/infobars/infobar_container.h" #include "chrome/browser/ui/views/unhandled_keyboard_event_handler.h" @@ -42,7 +41,6 @@ class ViewProp; // external process. This class provides the FocusManger needed by the // TabContents as well as an implementation of TabContentsDelegate. class ExternalTabContainer : public TabContentsDelegate, - public DownloadTabHelperDelegate, public NotificationObserver, public views::WidgetWin, public base::RefCounted<ExternalTabContainer>, @@ -144,6 +142,8 @@ class ExternalTabContainer : public TabContentsDelegate, virtual bool TakeFocus(bool reverse); + virtual bool CanDownload(int request_id); + virtual bool OnGoToEntryOffset(int offset); virtual void ShowPageInfo(Profile* profile, @@ -173,11 +173,6 @@ class ExternalTabContainer : public TabContentsDelegate, const NotificationSource& source, const NotificationDetails& details); - // Overridden from DownloadTabHelperDelegate: - virtual bool CanDownload(int request_id) OVERRIDE; - virtual void OnStartDownload(DownloadItem* download, - TabContentsWrapper* tab) OVERRIDE; - // Returns the ExternalTabContainer instance associated with the cookie // passed in. It also erases the corresponding reference from the map. // Returns NULL if we fail to find the cookie in the map. diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc index f686ecb..ca99bea 100644 --- a/chrome/browser/instant/instant_loader.cc +++ b/chrome/browser/instant/instant_loader.cc @@ -21,8 +21,6 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" -#include "chrome/browser/ui/download/download_tab_helper.h" -#include "chrome/browser/ui/download/download_tab_helper_delegate.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/render_messages.h" @@ -144,8 +142,7 @@ void InstantLoader::FrameLoadObserver::Observe( class InstantLoader::TabContentsDelegateImpl : public TabContentsDelegate, public NotificationObserver, - public TabContentsObserver, - public DownloadTabHelperDelegate { + public TabContentsObserver { public: explicit TabContentsDelegateImpl(InstantLoader* loader); @@ -211,6 +208,7 @@ class InstantLoader::TabContentsDelegateImpl // instant result when the drag ends, so that during the drag the page won't // move around. virtual void DragEnded() OVERRIDE; + virtual bool CanDownload(int request_id) OVERRIDE; virtual void HandleMouseUp() OVERRIDE; virtual void HandleMouseActivate() OVERRIDE; virtual bool OnGoToEntryOffset(int offset) OVERRIDE; @@ -222,11 +220,6 @@ class InstantLoader::TabContentsDelegateImpl // TabContentsObserver: virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; - // DownloadTabHelperDelegate: - virtual bool CanDownload(int request_id) OVERRIDE; - virtual void OnStartDownload(DownloadItem* download, - TabContentsWrapper* tab) OVERRIDE; - private: typedef std::vector<scoped_refptr<history::HistoryAddPageArgs> > AddPageVector; @@ -518,6 +511,11 @@ void InstantLoader::TabContentsDelegateImpl::DragEnded() { CommitFromMouseReleaseIfNecessary(); } +bool InstantLoader::TabContentsDelegateImpl::CanDownload(int request_id) { + // Downloads are disabled. + return false; +} + void InstantLoader::TabContentsDelegateImpl::HandleMouseUp() { CommitFromMouseReleaseIfNecessary(); } @@ -562,16 +560,6 @@ bool InstantLoader::TabContentsDelegateImpl::OnMessageReceived( return handled; } -bool InstantLoader::TabContentsDelegateImpl::CanDownload(int request_id) { - // Downloads are disabled. - return false; -} - -void InstantLoader::TabContentsDelegateImpl::OnStartDownload( - DownloadItem* download, TabContentsWrapper* tab) { - // Downloads are disabled. -} - void InstantLoader::TabContentsDelegateImpl::OnSetSuggestions( int32 page_id, const std::vector<std::string>& suggestions, @@ -822,7 +810,6 @@ TabContentsWrapper* InstantLoader::ReleasePreviewContents( #endif } preview_contents_->tab_contents()->set_delegate(NULL); - preview_contents_->download_tab_helper()->set_delegate(NULL); ready_ = false; } update_bounds_timer_.Stop(); @@ -985,7 +972,7 @@ void InstantLoader::SendBoundsToPage(bool force_if_waiting) { if (preview_contents_.get() && is_showing_instant() && (force_if_waiting || !is_waiting_for_load())) { last_omnibox_bounds_ = omnibox_bounds_; - RenderViewHost* host = preview_contents_->render_view_host(); + RenderViewHost*host = preview_contents_->render_view_host(); host->Send(new ViewMsg_SearchBoxResize( host->routing_id(), GetOmniboxBoundsInTermsOfPreview())); } @@ -1006,8 +993,6 @@ void InstantLoader::CreatePreviewContents(TabContentsWrapper* tab_contents) { preview_tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); new_contents->set_delegate(preview_tab_contents_delegate_.get()); - preview_contents_->download_tab_helper()->set_delegate( - preview_tab_contents_delegate_.get()); gfx::Rect tab_bounds; tab_contents->view()->GetContainerBounds(&tab_bounds); diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index 9d77927..d560e48 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -3299,6 +3299,51 @@ int Browser::GetExtraRenderViewHeight() const { return window_->GetExtraRenderViewHeight(); } +void Browser::OnStartDownload(DownloadItem* download, TabContents* tab) { + if (!window()) + return; + +#if defined(OS_CHROMEOS) + // Don't show content browser for extension/theme downloads from gallery. + if (download->is_extension_install()) { + ExtensionService* service = profile_->GetExtensionService(); + if (service && service->IsDownloadFromGallery(download->url(), + download->referrer_url())) { + return; + } + } + // Open the Active Downloads ui for chromeos. + ActiveDownloadsUI::OpenPopup(profile_); +#else + // GetDownloadShelf creates the download shelf if it was not yet created. + window()->GetDownloadShelf()->AddDownload(new DownloadItemModel(download)); + + // Don't show the animation for "Save file" downloads. + if (download->total_bytes() <= 0) + return; + + // For non-theme extensions, we don't show the download animation. + if (download->is_extension_install() && + !ExtensionService::IsDownloadFromMiniGallery(download->url())) + return; + + TabContents* current_tab = GetSelectedTabContents(); + // We make this check for the case of minimized windows, unit tests, etc. + if (platform_util::IsVisible(current_tab->GetNativeView()) && + ui::Animation::ShouldRenderRichAnimation()) { + DownloadStartedAnimation::Show(current_tab); + } +#endif + + // If the download occurs in a new tab, close it. + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(tab); + if (tab->controller().IsInitialNavigation() && + GetConstrainingContentsWrapper(wrapper) == wrapper && tab_count() > 1) { + CloseContents(tab); + } +} + void Browser::ShowPageInfo(Profile* profile, const GURL& url, const NavigationEntry::SSLStatus& ssl, @@ -3438,56 +3483,6 @@ void Browser::URLStarredChanged(TabContentsWrapper* source, bool starred) { } /////////////////////////////////////////////////////////////////////////////// -// Browser, DownloadTabHelperDelegate implementation: - -bool Browser::CanDownload(int request_id) { - return true; -} - -void Browser::OnStartDownload(DownloadItem* download, TabContentsWrapper* tab) { - if (!window()) - return; - -#if defined(OS_CHROMEOS) - // Don't show content browser for extension/theme downloads from gallery. - if (download->is_extension_install()) { - ExtensionService* service = profile_->GetExtensionService(); - if (service && service->IsDownloadFromGallery(download->url(), - download->referrer_url())) { - return; - } - } - // Open the Active Downloads ui for chromeos. - ActiveDownloadsUI::OpenPopup(profile_); -#else - // GetDownloadShelf creates the download shelf if it was not yet created. - window()->GetDownloadShelf()->AddDownload(new DownloadItemModel(download)); - - // Don't show the animation for "Save file" downloads. - if (download->total_bytes() <= 0) - return; - - // For non-theme extensions, we don't show the download animation. - if (download->is_extension_install() && - !ExtensionService::IsDownloadFromMiniGallery(download->url())) - return; - - TabContents* current_tab = GetSelectedTabContents(); - // We make this check for the case of minimized windows, unit tests, etc. - if (platform_util::IsVisible(current_tab->GetNativeView()) && - ui::Animation::ShouldRenderRichAnimation()) { - DownloadStartedAnimation::Show(current_tab); - } -#endif - - // If the download occurs in a new tab, close it. - if (tab->tab_contents()->controller().IsInitialNavigation() && - GetConstrainingContentsWrapper(tab) == tab && tab_count() > 1) { - CloseContents(tab->tab_contents()); - } -} - -/////////////////////////////////////////////////////////////////////////////// // Browser, SelectFileDialog::Listener implementation: void Browser::FileSelected(const FilePath& path, int index, void* params) { @@ -4397,7 +4392,6 @@ void Browser::SetAsDelegate(TabContentsWrapper* tab, Browser* delegate) { // ...and all the helpers. tab->blocked_content_tab_helper()->set_delegate(delegate); tab->bookmark_tab_helper()->set_delegate(delegate); - tab->download_tab_helper()->set_delegate(delegate); tab->search_engine_tab_helper()->set_delegate(delegate); } diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h index 17296a1..9406d68 100644 --- a/chrome/browser/ui/browser.h +++ b/chrome/browser/ui/browser.h @@ -31,7 +31,6 @@ #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper_delegate.h" #include "chrome/browser/ui/bookmarks/bookmark_tab_helper_delegate.h" #include "chrome/browser/ui/browser_navigator.h" -#include "chrome/browser/ui/download/download_tab_helper_delegate.h" #include "chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h" #include "chrome/browser/ui/shell_dialogs.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" @@ -69,7 +68,6 @@ class Browser : public TabHandlerDelegate, public SearchEngineTabHelperDelegate, public BlockedContentTabHelperDelegate, public BookmarkTabHelperDelegate, - public DownloadTabHelperDelegate, public PageNavigator, public CommandUpdater::CommandUpdaterDelegate, public NotificationObserver, @@ -813,6 +811,7 @@ class Browser : public TabHandlerDelegate, virtual void SetFocusToLocationBar(bool select_all); virtual void RenderWidgetShowing(); virtual int GetExtraRenderViewHeight() const; + virtual void OnStartDownload(DownloadItem* download, TabContents* tab); virtual void ShowPageInfo(Profile* profile, const GURL& url, const NavigationEntry::SSLStatus& ssl, @@ -859,12 +858,6 @@ class Browser : public TabHandlerDelegate, virtual void URLStarredChanged(TabContentsWrapper* source, bool starred) OVERRIDE; - // Overridden from DownloadTabHelperDelegate: - virtual bool CanDownload(int request_id) OVERRIDE; - virtual void OnStartDownload(DownloadItem* download, - TabContentsWrapper* tab) OVERRIDE; - - // Overridden from SelectFileDialog::Listener: virtual void FileSelected(const FilePath& path, int index, void* params); diff --git a/chrome/browser/ui/download/download_tab_helper.cc b/chrome/browser/ui/download/download_tab_helper.cc index 54a95de..505bbc1 100644 --- a/chrome/browser/ui/download/download_tab_helper.cc +++ b/chrome/browser/ui/download/download_tab_helper.cc @@ -4,14 +4,9 @@ #include "chrome/browser/ui/download/download_tab_helper.h" -#include "chrome/browser/browser_process.h" #include "chrome/browser/download/download_manager.h" -#include "chrome/browser/download/download_request_limiter.h" #include "chrome/browser/download/download_util.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" -#include "chrome/browser/ui/blocked_content/blocked_content_tab_helper_delegate.h" -#include "chrome/browser/ui/download/download_tab_helper_delegate.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/render_messages.h" #include "content/browser/tab_contents/tab_contents.h" @@ -19,8 +14,7 @@ DownloadTabHelper::DownloadTabHelper(TabContentsWrapper* tab_contents) : TabContentsObserver(tab_contents->tab_contents()), - tab_contents_wrapper_(tab_contents), - delegate_(NULL) { + tab_contents_wrapper_(tab_contents) { DCHECK(tab_contents); } @@ -68,31 +62,6 @@ bool DownloadTabHelper::SavePage(const FilePath& main_file, return save_package_->Init(); } -bool DownloadTabHelper::CanDownload(int request_id) { - if (delegate_) - return delegate_->CanDownload(request_id); - return true; -} - -void DownloadTabHelper::OnStartDownload(DownloadItem* download) { - DCHECK(download); - - BlockedContentTabHelperDelegate* blocked_content_delegate = - tab_contents_wrapper_->blocked_content_tab_helper()->delegate(); - if (!blocked_content_delegate) - return; - - // Download in a constrained popup is shown in the tab that opened it. - TabContentsWrapper* tab_contents = - blocked_content_delegate->GetConstrainingContentsWrapper( - tab_contents_wrapper_); - - if (tab_contents && tab_contents->download_tab_helper()->delegate()) { - tab_contents->download_tab_helper()->delegate()->OnStartDownload( - download, tab_contents_wrapper_); - } -} - bool DownloadTabHelper::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(DownloadTabHelper, message) @@ -103,9 +72,3 @@ bool DownloadTabHelper::OnMessageReceived(const IPC::Message& message) { return handled; } -void DownloadTabHelper::DidGetUserGesture() { - DownloadRequestLimiter* limiter = - g_browser_process->download_request_limiter(); - if (limiter) - limiter->OnUserGesture(tab_contents()); -} diff --git a/chrome/browser/ui/download/download_tab_helper.h b/chrome/browser/ui/download/download_tab_helper.h index ac55913..24ab7fc 100644 --- a/chrome/browser/ui/download/download_tab_helper.h +++ b/chrome/browser/ui/download/download_tab_helper.h @@ -10,8 +10,6 @@ #include "chrome/browser/download/save_package.h" #include "content/browser/tab_contents/tab_contents_observer.h" -class DownloadItem; -class DownloadTabHelperDelegate; class TabContentsWrapper; // Per-tab download controller. Handles dealing with various per-tab download @@ -21,9 +19,6 @@ class DownloadTabHelper : public TabContentsObserver { explicit DownloadTabHelper(TabContentsWrapper* tab_contents); virtual ~DownloadTabHelper(); - DownloadTabHelperDelegate* delegate() const { return delegate_; } - void set_delegate(DownloadTabHelperDelegate* d) { delegate_ = d; } - // Prepare for saving the current web page to disk. void OnSavePage(); @@ -40,17 +35,9 @@ class DownloadTabHelper : public TabContentsObserver { // Returns the SavePackage which manages the page saving job. May be NULL. SavePackage* save_package() const { return save_package_.get(); } - // Notifies the delegate that a download is about to be started. - // This notification is fired before a local temporary file has been created. - bool CanDownload(int request_id); - - // Notifies the delegate that a download started. - void OnStartDownload(DownloadItem* download); - private: // TabContentsObserver overrides. virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; - virtual void DidGetUserGesture() OVERRIDE; // SavePackage, lazily created. scoped_refptr<SavePackage> save_package_; @@ -58,10 +45,6 @@ class DownloadTabHelper : public TabContentsObserver { // Owning TabContentsWrapper. TabContentsWrapper* tab_contents_wrapper_; - // Delegate for notifying our owner (usually Browser) about stuff. Not owned - // by us. - DownloadTabHelperDelegate* delegate_; - DISALLOW_COPY_AND_ASSIGN(DownloadTabHelper); }; diff --git a/chrome/browser/ui/download/download_tab_helper_delegate.cc b/chrome/browser/ui/download/download_tab_helper_delegate.cc deleted file mode 100644 index 1a37873..0000000 --- a/chrome/browser/ui/download/download_tab_helper_delegate.cc +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) 2011 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/ui/download/download_tab_helper_delegate.h" - -DownloadTabHelperDelegate::~DownloadTabHelperDelegate() { -} diff --git a/chrome/browser/ui/download/download_tab_helper_delegate.h b/chrome/browser/ui/download/download_tab_helper_delegate.h deleted file mode 100644 index 88adaec..0000000 --- a/chrome/browser/ui/download/download_tab_helper_delegate.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2011 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_UI_DOWNLOAD_DOWNLOAD_TAB_HELPER_DELEGATE_H_ -#define CHROME_BROWSER_UI_DOWNLOAD_DOWNLOAD_TAB_HELPER_DELEGATE_H_ -#pragma once - -#include "base/basictypes.h" - -class DownloadItem; -class TabContentsWrapper; - -// Objects implement this interface to get notified about changes in the -// DownloadTabHelper and to provide necessary functionality. -class DownloadTabHelperDelegate { - public: - virtual bool CanDownload(int request_id) = 0; - - virtual void OnStartDownload(DownloadItem* download, - TabContentsWrapper* tab) = 0; - - protected: - virtual ~DownloadTabHelperDelegate(); -}; - -#endif // CHROME_BROWSER_UI_DOWNLOAD_DOWNLOAD_TAB_HELPER_DELEGATE_H_ diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 876f13d..6e63639 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2561,8 +2561,6 @@ 'browser/ui/crypto_module_password_dialog_openssl.cc', 'browser/ui/download/download_tab_helper.cc', 'browser/ui/download/download_tab_helper.h', - 'browser/ui/download/download_tab_helper_delegate.cc', - 'browser/ui/download/download_tab_helper_delegate.h', 'browser/ui/find_bar/find_bar.h', 'browser/ui/find_bar/find_bar_controller.cc', 'browser/ui/find_bar/find_bar_controller.h', diff --git a/content/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc index b4aee7c..d51e63e 100644 --- a/content/browser/tab_contents/tab_contents.cc +++ b/content/browser/tab_contents/tab_contents.cc @@ -13,9 +13,11 @@ #include "base/string_util.h" #include "base/time.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_shutdown.h" #include "chrome/browser/debugger/devtools_manager.h" #include "chrome/browser/defaults.h" +#include "chrome/browser/download/download_request_limiter.h" #include "chrome/browser/external_protocol_handler.h" #include "chrome/browser/history/history.h" #include "chrome/browser/load_from_memory_cache_details.h" @@ -854,6 +856,26 @@ bool TabContents::ShouldShowBookmarkBar() { false : render_manager_.web_ui()->force_bookmark_bar_visible(); } +bool TabContents::CanDownload(int request_id) { + TabContentsDelegate* d = delegate(); + if (d) + return d->CanDownload(request_id); + return true; +} + +void TabContents::OnStartDownload(DownloadItem* download) { + DCHECK(download); + + if (!delegate()) + return; + + // Download in a constrained popup is shown in the tab that opened it. + TabContents* tab_contents = delegate()->GetConstrainingContents(this); + + if (tab_contents && tab_contents->delegate()) + tab_contents->delegate()->OnStartDownload(download, this); +} + void TabContents::WillClose(ConstrainedWindow* window) { ConstrainedWindowList::iterator i( std::find(child_windows_.begin(), child_windows_.end(), window)); @@ -1932,8 +1954,11 @@ WebPreferences TabContents::GetWebkitPrefs() { } void TabContents::OnUserGesture() { - // Notify observers. - FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidGetUserGesture()); + // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this. + DownloadRequestLimiter* limiter = + g_browser_process->download_request_limiter(); + if (limiter) + limiter->OnUserGesture(this); ExternalProtocolHandler::PermitLaunchUrl(); } diff --git a/content/browser/tab_contents/tab_contents.h b/content/browser/tab_contents/tab_contents.h index 99c25cf..f38ca63 100644 --- a/content/browser/tab_contents/tab_contents.h +++ b/content/browser/tab_contents/tab_contents.h @@ -44,12 +44,13 @@ namespace history { class HistoryAddPageArgs; } +class WebUI; +class DownloadItem; class Extension; class InfoBarDelegate; class LoadNotificationDetails; class PluginObserver; class Profile; -struct RendererPreferences; class RenderViewHost; class SessionStorageNamespace; class SiteInstance; @@ -58,11 +59,11 @@ class TabContentsDelegate; class TabContentsObserver; class TabContentsSSLHelper; class TabContentsView; -struct ThumbnailScore; class URLPattern; +struct RendererPreferences; +struct ThumbnailScore; struct ViewHostMsg_FrameNavigate_Params; struct WebPreferences; -class WebUI; // Describes what goes in the main content area of a tab. TabContents is // the only type of TabContents, and these should be merged together. @@ -388,6 +389,13 @@ class TabContents : public PageNavigator, // Returns true if a Bookmark Bar should be shown for this tab. virtual bool ShouldShowBookmarkBar(); + // Notifies the delegate that a download is about to be started. + // This notification is fired before a local temporary file has been created. + bool CanDownload(int request_id); + + // Notifies the delegate that a download started. + void OnStartDownload(DownloadItem* download); + // Called when a ConstrainedWindow we own is about to be closed. void WillClose(ConstrainedWindow* window); diff --git a/content/browser/tab_contents/tab_contents_delegate.cc b/content/browser/tab_contents/tab_contents_delegate.cc index 27f94e1..378c48e 100644 --- a/content/browser/tab_contents/tab_contents_delegate.cc +++ b/content/browser/tab_contents/tab_contents_delegate.cc @@ -93,6 +93,14 @@ int TabContentsDelegate::GetExtraRenderViewHeight() const { return 0; } +bool TabContentsDelegate::CanDownload(int request_id) { + return true; +} + +void TabContentsDelegate::OnStartDownload(DownloadItem* download, + TabContents* tab) { +} + bool TabContentsDelegate::HandleContextMenu(const ContextMenuParams& params) { return false; } diff --git a/content/browser/tab_contents/tab_contents_delegate.h b/content/browser/tab_contents/tab_contents_delegate.h index fc9d4e4..e0c95ac 100644 --- a/content/browser/tab_contents/tab_contents_delegate.h +++ b/content/browser/tab_contents/tab_contents_delegate.h @@ -26,6 +26,7 @@ class HistoryAddPageArgs; } struct ContextMenuParams; +class DownloadItem; class GURL; class HtmlDialogUIDelegate; struct NativeWebKeyboardEvent; @@ -201,6 +202,10 @@ class TabContentsDelegate { // This is used to make painting look smoother. virtual int GetExtraRenderViewHeight() const; + virtual bool CanDownload(int request_id); + + virtual void OnStartDownload(DownloadItem* download, TabContents* tab); + // Returns true if the context menu operation was handled by the delegate. virtual bool HandleContextMenu(const ContextMenuParams& params); diff --git a/content/browser/tab_contents/tab_contents_observer.cc b/content/browser/tab_contents/tab_contents_observer.cc index 4342aa1..3056608 100644 --- a/content/browser/tab_contents/tab_contents_observer.cc +++ b/content/browser/tab_contents/tab_contents_observer.cc @@ -70,9 +70,6 @@ void TabContentsObserver::DocumentLoadedInFrame(int64 frame_id) { void TabContentsObserver::DidFinishLoad(int64 frame_id) { } -void TabContentsObserver::DidGetUserGesture() { -} - void TabContentsObserver::DidStartLoading() { } diff --git a/content/browser/tab_contents/tab_contents_observer.h b/content/browser/tab_contents/tab_contents_observer.h index d8598c7..cc73b4f 100644 --- a/content/browser/tab_contents/tab_contents_observer.h +++ b/content/browser/tab_contents/tab_contents_observer.h @@ -68,7 +68,6 @@ class TabContentsObserver : public IPC::Channel::Listener, int error_code); virtual void DocumentLoadedInFrame(int64 frame_id); virtual void DidFinishLoad(int64 frame_id); - virtual void DidGetUserGesture(); virtual void DidStartLoading(); virtual void DidStopLoading(); |