diff options
20 files changed, 240 insertions, 139 deletions
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc index fb9fb7b..54d937b 100644 --- a/chrome/browser/download/download_manager.cc +++ b/chrome/browser/download/download_manager.cc @@ -33,6 +33,8 @@ #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" @@ -1069,20 +1071,23 @@ 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 (!contents) { + if (!wrapper) { Browser* last_active = BrowserList::GetLastActive(); if (last_active) - contents = last_active->GetSelectedTabContents(); + wrapper = last_active->GetSelectedTabContentsWrapper(); } - if (!contents) + if (!wrapper) return; - contents->OnStartDownload(download); + wrapper->download_tab_helper()->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 579c172..b39e1f6 100644 --- a/chrome/browser/download/download_request_limiter.cc +++ b/chrome/browser/download/download_request_limiter.cc @@ -12,6 +12,8 @@ #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 ------------------------------------------------------------ @@ -256,7 +258,9 @@ 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. - if (!originating_tab->CanDownload(request_id)) { + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(originating_tab); + if (!wrapper->download_tab_helper()->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 d4422d1..9cdb3c3 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) 2006-2008 The Chromium Authors. All rights reserved. +// 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/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 RenderViewHostTestHarness, + : public TabContentsWrapperTestHarness, public DownloadRequestLimiter::Callback { public: DownloadRequestLimiterTest() : io_thread_(BrowserThread::IO, &message_loop_) { } virtual void SetUp() { - RenderViewHostTestHarness::SetUp(); + TabContentsWrapperTestHarness::SetUp(); allow_download_ = true; ask_allow_count_ = cancel_count_ = continue_count_ = 0; @@ -30,7 +30,7 @@ class DownloadRequestLimiterTest virtual void TearDown() { DownloadRequestLimiter::SetTestingDelegate(NULL); - RenderViewHostTestHarness::TearDown(); + TabContentsWrapperTestHarness::TearDown(); } virtual void ContinueDownload() { diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc index cf9d4dc..d18099c 100644 --- a/chrome/browser/download/save_package.cc +++ b/chrome/browser/download/save_package.cc @@ -34,6 +34,7 @@ #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" @@ -326,7 +327,7 @@ bool SavePackage::Init() { // to be alive as long as the Profile is alive. download_manager->SavePageAsDownloadStarted(download_); - tab_contents()->OnStartDownload(download_); + wrapper_->download_tab_helper()->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 b3787d7..1ba4ee1 100644 --- a/chrome/browser/external_tab_container_win.cc +++ b/chrome/browser/external_tab_container_win.cc @@ -159,6 +159,7 @@ 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 = @@ -539,26 +540,6 @@ 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, @@ -784,6 +765,34 @@ 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 2e82237..d6c73c0 100644 --- a/chrome/browser/external_tab_container_win.h +++ b/chrome/browser/external_tab_container_win.h @@ -14,6 +14,7 @@ #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" @@ -41,6 +42,7 @@ 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>, @@ -142,8 +144,6 @@ 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,6 +173,11 @@ 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 ca99bea..f686ecb 100644 --- a/chrome/browser/instant/instant_loader.cc +++ b/chrome/browser/instant/instant_loader.cc @@ -21,6 +21,8 @@ #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" @@ -142,7 +144,8 @@ void InstantLoader::FrameLoadObserver::Observe( class InstantLoader::TabContentsDelegateImpl : public TabContentsDelegate, public NotificationObserver, - public TabContentsObserver { + public TabContentsObserver, + public DownloadTabHelperDelegate { public: explicit TabContentsDelegateImpl(InstantLoader* loader); @@ -208,7 +211,6 @@ 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; @@ -220,6 +222,11 @@ 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; @@ -511,11 +518,6 @@ void InstantLoader::TabContentsDelegateImpl::DragEnded() { CommitFromMouseReleaseIfNecessary(); } -bool InstantLoader::TabContentsDelegateImpl::CanDownload(int request_id) { - // Downloads are disabled. - return false; -} - void InstantLoader::TabContentsDelegateImpl::HandleMouseUp() { CommitFromMouseReleaseIfNecessary(); } @@ -560,6 +562,16 @@ 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, @@ -810,6 +822,7 @@ 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(); @@ -972,7 +985,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())); } @@ -993,6 +1006,8 @@ 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 d560e48..9d77927 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -3299,51 +3299,6 @@ 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, @@ -3483,6 +3438,56 @@ 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) { @@ -4392,6 +4397,7 @@ 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 9406d68..17296a1 100644 --- a/chrome/browser/ui/browser.h +++ b/chrome/browser/ui/browser.h @@ -31,6 +31,7 @@ #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" @@ -68,6 +69,7 @@ class Browser : public TabHandlerDelegate, public SearchEngineTabHelperDelegate, public BlockedContentTabHelperDelegate, public BookmarkTabHelperDelegate, + public DownloadTabHelperDelegate, public PageNavigator, public CommandUpdater::CommandUpdaterDelegate, public NotificationObserver, @@ -811,7 +813,6 @@ 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, @@ -858,6 +859,12 @@ 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 505bbc1..54a95de 100644 --- a/chrome/browser/ui/download/download_tab_helper.cc +++ b/chrome/browser/ui/download/download_tab_helper.cc @@ -4,9 +4,14 @@ #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" @@ -14,7 +19,8 @@ DownloadTabHelper::DownloadTabHelper(TabContentsWrapper* tab_contents) : TabContentsObserver(tab_contents->tab_contents()), - tab_contents_wrapper_(tab_contents) { + tab_contents_wrapper_(tab_contents), + delegate_(NULL) { DCHECK(tab_contents); } @@ -62,6 +68,31 @@ 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) @@ -72,3 +103,9 @@ 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 24ab7fc..ac55913 100644 --- a/chrome/browser/ui/download/download_tab_helper.h +++ b/chrome/browser/ui/download/download_tab_helper.h @@ -10,6 +10,8 @@ #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 @@ -19,6 +21,9 @@ 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(); @@ -35,9 +40,17 @@ 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_; @@ -45,6 +58,10 @@ 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 new file mode 100644 index 0000000..1a37873 --- /dev/null +++ b/chrome/browser/ui/download/download_tab_helper_delegate.cc @@ -0,0 +1,8 @@ +// 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 new file mode 100644 index 0000000..88adaec --- /dev/null +++ b/chrome/browser/ui/download/download_tab_helper_delegate.h @@ -0,0 +1,27 @@ +// 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 6e63639..876f13d 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2561,6 +2561,8 @@ '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 d51e63e..b4aee7c 100644 --- a/content/browser/tab_contents/tab_contents.cc +++ b/content/browser/tab_contents/tab_contents.cc @@ -13,11 +13,9 @@ #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" @@ -856,26 +854,6 @@ 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)); @@ -1954,11 +1932,8 @@ WebPreferences TabContents::GetWebkitPrefs() { } void TabContents::OnUserGesture() { - // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this. - DownloadRequestLimiter* limiter = - g_browser_process->download_request_limiter(); - if (limiter) - limiter->OnUserGesture(this); + // Notify observers. + FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidGetUserGesture()); ExternalProtocolHandler::PermitLaunchUrl(); } diff --git a/content/browser/tab_contents/tab_contents.h b/content/browser/tab_contents/tab_contents.h index f38ca63..99c25cf 100644 --- a/content/browser/tab_contents/tab_contents.h +++ b/content/browser/tab_contents/tab_contents.h @@ -44,13 +44,12 @@ 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; @@ -59,11 +58,11 @@ class TabContentsDelegate; class TabContentsObserver; class TabContentsSSLHelper; class TabContentsView; -class URLPattern; -struct RendererPreferences; struct ThumbnailScore; +class URLPattern; 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. @@ -389,13 +388,6 @@ 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 378c48e..27f94e1 100644 --- a/content/browser/tab_contents/tab_contents_delegate.cc +++ b/content/browser/tab_contents/tab_contents_delegate.cc @@ -93,14 +93,6 @@ 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 e0c95ac..fc9d4e4 100644 --- a/content/browser/tab_contents/tab_contents_delegate.h +++ b/content/browser/tab_contents/tab_contents_delegate.h @@ -26,7 +26,6 @@ class HistoryAddPageArgs; } struct ContextMenuParams; -class DownloadItem; class GURL; class HtmlDialogUIDelegate; struct NativeWebKeyboardEvent; @@ -202,10 +201,6 @@ 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 3056608..4342aa1 100644 --- a/content/browser/tab_contents/tab_contents_observer.cc +++ b/content/browser/tab_contents/tab_contents_observer.cc @@ -70,6 +70,9 @@ 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 cc73b4f..d8598c7 100644 --- a/content/browser/tab_contents/tab_contents_observer.h +++ b/content/browser/tab_contents/tab_contents_observer.h @@ -68,6 +68,7 @@ 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(); |