diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-14 20:12:50 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-14 20:12:50 +0000 |
commit | 58db2f88917448f794deeee45868137d9098339a (patch) | |
tree | 0aa9feba219c093223542830c3e9951aa8f63ec1 /chrome/browser | |
parent | 66814bb0eb9fd82cb6acd58ddc9292555bd98322 (diff) | |
download | chromium_src-58db2f88917448f794deeee45868137d9098339a.zip chromium_src-58db2f88917448f794deeee45868137d9098339a.tar.gz chromium_src-58db2f88917448f794deeee45868137d9098339a.tar.bz2 |
Make the multiple download request dialog an infobar.
The icon is a placeholder until Glen makes a pretty one.
BUG=24047
TEST=go to skypher.com/SkyLined/Repro/Chrome/carpet bombing/repro.html
allow, deny, closing infobar, and closing tab all work as expected
Review URL: http://codereview.chromium.org/275011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29006 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
13 files changed, 213 insertions, 486 deletions
diff --git a/chrome/browser/cocoa/download_request_dialog_delegate_mac.h b/chrome/browser/cocoa/download_request_dialog_delegate_mac.h deleted file mode 100644 index f12ae19..0000000 --- a/chrome/browser/cocoa/download_request_dialog_delegate_mac.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) 2009 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_DOWNLOAD_DOWNLOAD_REQUEST_DIALOG_DELEGATE_MAC_H_ -#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_DIALOG_DELEGATE_MAC_H_ - -#include "base/scoped_nsobject.h" -#include "base/scoped_ptr.h" -#include "chrome/browser/cocoa/constrained_window_mac.h" -#include "chrome/browser/download/download_request_dialog_delegate.h" -#include "chrome/browser/download/download_request_manager.h" - -@class SheetCallback; -class TabContents; - -class DownloadRequestDialogDelegateMac : public DownloadRequestDialogDelegate, - public ConstrainedWindowMacDelegateSystemSheet { - public: - DownloadRequestDialogDelegateMac(TabContents* tab, - DownloadRequestManager::TabDownloadState* host); - - // Implement ConstrainedWindowMacDelegateSystemSheet. - virtual void DeleteDelegate(); - - // Called when the sheet is done. - void SheetDidEnd(int returnCode); - - private: - // DownloadRequestDialogDelegate methods. - virtual void CloseWindow(); - - // The ConstrainedWindow that is hosting our DownloadRequestDialog. - ConstrainedWindow* window_; - - // Has a button on the sheet been clicked? - bool responded_; - - DISALLOW_COPY_AND_ASSIGN(DownloadRequestDialogDelegateMac); -}; - -#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_DIALOG_DELEGATE_MAC_H_ - diff --git a/chrome/browser/cocoa/download_request_dialog_delegate_mac.mm b/chrome/browser/cocoa/download_request_dialog_delegate_mac.mm deleted file mode 100644 index 4f5e29a..0000000 --- a/chrome/browser/cocoa/download_request_dialog_delegate_mac.mm +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright (c) 2009 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/cocoa/download_request_dialog_delegate_mac.h" - -#import <Cocoa/Cocoa.h> - -#include "app/l10n_util_mac.h" -#include "app/message_box_flags.h" -#include "base/sys_string_conversions.h" -#include "chrome/browser/tab_contents/constrained_window.h" -#include "chrome/browser/tab_contents/tab_contents.h" -#include "grit/generated_resources.h" - -@interface SheetCallback : NSObject { - DownloadRequestDialogDelegateMac* target_; // weak -} -- (id)initWithTarget:(DownloadRequestDialogDelegateMac*)target; -- (void) alertDidEnd:(NSAlert *)alert - returnCode:(int)returnCode - contextInfo:(void *)contextInfo; -@end - -@implementation SheetCallback -- (id)initWithTarget:(DownloadRequestDialogDelegateMac*)target { - if ((self = [super init]) != nil) { - target_ = target; - } - return self; -} -- (void)alertDidEnd:(NSAlert *)alert - returnCode:(int)returnCode - contextInfo:(void *)contextInfo { - target_->SheetDidEnd(returnCode); -} -@end - - -// static -DownloadRequestDialogDelegate* DownloadRequestDialogDelegate::Create( - TabContents* tab, - DownloadRequestManager::TabDownloadState* host) { - return new DownloadRequestDialogDelegateMac(tab, host); -} - -DownloadRequestDialogDelegateMac::DownloadRequestDialogDelegateMac( - TabContents* tab, - DownloadRequestManager::TabDownloadState* host) - : DownloadRequestDialogDelegate(host), - ConstrainedWindowMacDelegateSystemSheet( - [[[SheetCallback alloc] initWithTarget:this] autorelease], - @selector(alertDidEnd:returnCode:contextInfo:)), - responded_(false) { - - // Set up alert. - NSAlert* alert = [[[NSAlert alloc] init] autorelease]; - [alert addButtonWithTitle: - l10n_util::GetNSStringWithFixup(IDS_MULTI_DOWNLOAD_WARNING_ALLOW)]; - NSButton* denyButton = [alert addButtonWithTitle: - l10n_util::GetNSStringWithFixup(IDS_MULTI_DOWNLOAD_WARNING_DENY)]; - [alert setMessageText: - l10n_util::GetNSStringWithFixup(IDS_MULTI_DOWNLOAD_WARNING)]; - [alert setAlertStyle:NSInformationalAlertStyle]; - - // Cocoa automatically gives ESC as a key equivalent to buttons with the text - // "Cancel". Since we use a different text, we have to set this ourselves. - NSString* escapeKey = @"\e"; - [denyButton setKeyEquivalent:escapeKey]; - - set_sheet(alert); - - // Display alert in a per-tab sheet. - window_ = tab->CreateConstrainedDialog(this); -} - -void DownloadRequestDialogDelegateMac::CloseWindow() { - window_->CloseConstrainedWindow(); -} - -void DownloadRequestDialogDelegateMac::DeleteDelegate() { - if (is_sheet_open()) { - // Close sheet if it's still open. - [NSApp endSheet:[(NSAlert*)sheet() window]]; // calls SheetDidEnd(). - DCHECK(responded_); - } - if (!responded_) { - // Happens if the sheet was never visible. - responded_ = true; - DoCancel(); - } - DCHECK(!host_); - delete this; -} - -void DownloadRequestDialogDelegateMac::SheetDidEnd(int returnCode) { - DCHECK(!responded_); - if (returnCode == NSAlertFirstButtonReturn) { - DoAccept(); - } else { - DoCancel(); - } - responded_ = true; -} diff --git a/chrome/browser/download/download_request_dialog_delegate.h b/chrome/browser/download/download_request_dialog_delegate.h deleted file mode 100644 index af4ad20..0000000 --- a/chrome/browser/download/download_request_dialog_delegate.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 2006-2009 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_DOWNLOAD_DOWNLOAD_REQUEST_DIALOG_DELEGATE_H_ -#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_DIALOG_DELEGATE_H_ - -#include "base/basictypes.h" - -#include "chrome/browser/download/download_request_manager.h" - -// DownloadRequestDialogDelegate is the dialog implementation used to prompt the -// the user as to whether they want to allow multiple downloads. -// DownloadRequestDialogDelegate delegates the allow/cancel methods to the -// TabDownloadState. -// -// TabDownloadState does not directly act as a dialog delegate because -// the dialog may outlive the TabDownloadState object. -class DownloadRequestDialogDelegate { - public: - // This factory method constructs a DownloadRequestDialogDelegate in a - // platform-specific way. - static DownloadRequestDialogDelegate* Create(TabContents* tab, - DownloadRequestManager::TabDownloadState* host); - - void set_host(DownloadRequestManager::TabDownloadState* host) { - host_ = host; - } - - // Closes the prompt. - virtual void CloseWindow() = 0; - - protected: - explicit DownloadRequestDialogDelegate( - DownloadRequestManager::TabDownloadState* host) : host_(host) { } - - virtual ~DownloadRequestDialogDelegate() { } - - virtual bool DoCancel() { - if (host_) - host_->Cancel(); - return true; - } - - virtual bool DoAccept() { - if (host_) - host_->Accept(); - return true; - } - - // The TabDownloadState we're displaying the dialog for. May be null. - DownloadRequestManager::TabDownloadState* host_; - - DISALLOW_COPY_AND_ASSIGN(DownloadRequestDialogDelegate); -}; - -#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_DIALOG_DELEGATE_H_ diff --git a/chrome/browser/download/download_request_dialog_delegate_win.cc b/chrome/browser/download/download_request_dialog_delegate_win.cc deleted file mode 100644 index 6129af6..0000000 --- a/chrome/browser/download/download_request_dialog_delegate_win.cc +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) 2006-2009 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_dialog_delegate_win.h" - -#include "app/l10n_util.h" -#include "app/message_box_flags.h" -#include "chrome/browser/tab_contents/constrained_window.h" -#include "chrome/browser/tab_contents/tab_contents.h" -#include "grit/generated_resources.h" -#include "views/controls/message_box_view.h" - -// static -DownloadRequestDialogDelegate* DownloadRequestDialogDelegate::Create( - TabContents* tab, - DownloadRequestManager::TabDownloadState* host) { - return new DownloadRequestDialogDelegateWin(tab, host); -} - -DownloadRequestDialogDelegateWin::DownloadRequestDialogDelegateWin( - TabContents* tab, - DownloadRequestManager::TabDownloadState* host) - : DownloadRequestDialogDelegate(host) { - message_view_ = new MessageBoxView( - MessageBoxFlags::kIsConfirmMessageBox, - l10n_util::GetString(IDS_MULTI_DOWNLOAD_WARNING), - std::wstring()); - window_ = tab->CreateConstrainedDialog(this); -} - -void DownloadRequestDialogDelegateWin::CloseWindow() { - window_->CloseConstrainedWindow(); -} - -bool DownloadRequestDialogDelegateWin::Cancel() { - return DoCancel(); -} - -bool DownloadRequestDialogDelegateWin::Accept() { - return DoAccept(); -} - -views::View* DownloadRequestDialogDelegateWin::GetContentsView() { - return message_view_; -} - -std::wstring DownloadRequestDialogDelegateWin::GetDialogButtonLabel( - MessageBoxFlags::DialogButton button) const { - if (button == MessageBoxFlags::DIALOGBUTTON_OK) - return l10n_util::GetString(IDS_MULTI_DOWNLOAD_WARNING_ALLOW); - if (button == MessageBoxFlags::DIALOGBUTTON_CANCEL) - return l10n_util::GetString(IDS_MULTI_DOWNLOAD_WARNING_DENY); - return std::wstring(); -} - -void DownloadRequestDialogDelegateWin::DeleteDelegate() { - DCHECK(!host_); - delete this; -} diff --git a/chrome/browser/download/download_request_dialog_delegate_win.h b/chrome/browser/download/download_request_dialog_delegate_win.h deleted file mode 100644 index 387dce7..0000000 --- a/chrome/browser/download/download_request_dialog_delegate_win.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2006-2009 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_DOWNLOAD_DOWNLOAD_REQUEST_DIALOG_DELEGATE_WIN_H_ -#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_DIALOG_DELEGATE_WIN_H_ - -#include "base/basictypes.h" - -#include "chrome/browser/download/download_request_dialog_delegate.h" -#include "chrome/browser/download/download_request_manager.h" -#include "views/window/dialog_delegate.h" - -class ConstrainedWindow; -class MessageBoxView; -class TabContents; - -class DownloadRequestDialogDelegateWin : public DownloadRequestDialogDelegate, - public views::DialogDelegate { - public: - DownloadRequestDialogDelegateWin(TabContents* tab, - DownloadRequestManager::TabDownloadState* host); - - private: - // DownloadRequestDialogDelegate methods. - virtual void CloseWindow(); - // DialogDelegate methods. - virtual bool Cancel(); - virtual bool Accept(); - virtual views::View* GetContentsView(); - virtual std::wstring GetDialogButtonLabel( - MessageBoxFlags::DialogButton button) const; - virtual int GetDefaultDialogButton() const { - return MessageBoxFlags::DIALOGBUTTON_CANCEL; - } - virtual void DeleteDelegate(); - - MessageBoxView* message_view_; - - ConstrainedWindow* window_; - - DISALLOW_COPY_AND_ASSIGN(DownloadRequestDialogDelegateWin); -}; - -#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_DIALOG_DELEGATE_WIN_H_ diff --git a/chrome/browser/download/download_request_infobar_delegate.cc b/chrome/browser/download/download_request_infobar_delegate.cc new file mode 100644 index 0000000..3a6aa5d --- /dev/null +++ b/chrome/browser/download/download_request_infobar_delegate.cc @@ -0,0 +1,65 @@ +// Copyright (c) 2009 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_infobar_delegate.h" + +#include "app/l10n_util.h" +#include "app/resource_bundle.h" +#include "chrome/browser/tab_contents/tab_contents.h" +#include "grit/generated_resources.h" +#include "grit/theme_resources.h" + +DownloadRequestInfoBarDelegate::DownloadRequestInfoBarDelegate(TabContents* tab, + DownloadRequestManager::TabDownloadState* host) + : ConfirmInfoBarDelegate(tab), + host_(host) { + if (tab) + tab->AddInfoBar(this); +} + +DownloadRequestInfoBarDelegate::~DownloadRequestInfoBarDelegate() { +} + +void DownloadRequestInfoBarDelegate::InfoBarClosed() { + Cancel(); + // This will delete us. + ConfirmInfoBarDelegate::InfoBarClosed(); +} + +std::wstring DownloadRequestInfoBarDelegate::GetMessageText() const { + return l10n_util::GetString(IDS_MULTI_DOWNLOAD_WARNING); +} + +SkBitmap* DownloadRequestInfoBarDelegate::GetIcon() const { + return ResourceBundle::GetSharedInstance().GetBitmapNamed( + IDR_INFOBAR_MULTIPLE_DOWNLOADS); +} + +int DownloadRequestInfoBarDelegate::GetButtons() const { + return BUTTON_OK | BUTTON_CANCEL; +} + +std::wstring DownloadRequestInfoBarDelegate::GetButtonLabel( + ConfirmInfoBarDelegate::InfoBarButton button) const { + if (button == BUTTON_OK) + return l10n_util::GetString(IDS_MULTI_DOWNLOAD_WARNING_ALLOW); + else + return l10n_util::GetString(IDS_MULTI_DOWNLOAD_WARNING_DENY); +} + +bool DownloadRequestInfoBarDelegate::Accept() { + if (host_) { + host_->Accept(); + host_ = NULL; + } + return true; +} + +bool DownloadRequestInfoBarDelegate::Cancel() { + if (host_) { + host_->Cancel(); + host_ = NULL; + } + return true; +} diff --git a/chrome/browser/download/download_request_infobar_delegate.h b/chrome/browser/download/download_request_infobar_delegate.h new file mode 100644 index 0000000..112c2e2 --- /dev/null +++ b/chrome/browser/download/download_request_infobar_delegate.h @@ -0,0 +1,50 @@ +// Copyright (c) 2009 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_DOWNLOAD_DOWNLOAD_REQUEST_INFOBAR_DELEGATE_H_ +#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_INFOBAR_DELEGATE_H_ + +#include "base/basictypes.h" +#include "chrome/browser/download/download_request_manager.h" +#include "chrome/browser/tab_contents/infobar_delegate.h" + +class TabContents; + +// An infobar delegate that presents the user with a choice to allow or deny +// multiple downloads from the same site. This confirmation step protects +// against "carpet-bombing", where a malicious site forces multiple downloads +// on an unsuspecting user. +class DownloadRequestInfoBarDelegate : public ConfirmInfoBarDelegate { + public: + DownloadRequestInfoBarDelegate( + TabContents* tab, DownloadRequestManager::TabDownloadState* host); + + virtual ~DownloadRequestInfoBarDelegate(); + + void set_host(DownloadRequestManager::TabDownloadState* host) { + host_ = host; + } + + virtual void InfoBarClosed(); + + virtual std::wstring GetMessageText() const; + + virtual SkBitmap* GetIcon() const; + + virtual int GetButtons() const; + + virtual std::wstring GetButtonLabel( + ConfirmInfoBarDelegate::InfoBarButton button) const; + + virtual bool Accept(); + + virtual bool Cancel(); + + private: + DownloadRequestManager::TabDownloadState* host_; + + DISALLOW_COPY_AND_ASSIGN(DownloadRequestInfoBarDelegate); +}; + +#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_INFOBAR_DELEGATE_H_ diff --git a/chrome/browser/download/download_request_infobar_delegate_unittest.cc b/chrome/browser/download/download_request_infobar_delegate_unittest.cc new file mode 100644 index 0000000..663f8b7 --- /dev/null +++ b/chrome/browser/download/download_request_infobar_delegate_unittest.cc @@ -0,0 +1,66 @@ +// Copyright (c) 2009 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_infobar_delegate.h" +#include "chrome/browser/download/download_request_manager.h" +#include "testing/gtest/include/gtest/gtest.h" + +class MockTabDownloadState : public DownloadRequestManager::TabDownloadState { + public: + MockTabDownloadState() : responded_(false), accepted_(false) { + } + + virtual ~MockTabDownloadState() { + EXPECT_TRUE(responded_); + } + + virtual void Accept() { + EXPECT_FALSE(responded_); + responded_ = true; + accepted_ = true; + } + + virtual void Cancel() { + EXPECT_FALSE(responded_); + responded_ = true; + accepted_ = false; + } + + bool responded() { + return responded_; + } + + bool accepted() { + return responded_ && accepted_; + } + + private: + // True if we have gotten some sort of response. + bool responded_; + + // True if we have gotten a Accept response. Meaningless if |responded_| is + // not true. + bool accepted_; +}; + +TEST(DownloadRequestInfobar, AcceptTest) { + MockTabDownloadState state; + DownloadRequestInfoBarDelegate infobar(NULL, &state); + infobar.Accept(); + EXPECT_TRUE(state.accepted()); +} + +TEST(DownloadRequestInfobar, CancelTest) { + MockTabDownloadState state; + DownloadRequestInfoBarDelegate infobar(NULL, &state); + infobar.Cancel(); + EXPECT_FALSE(state.accepted()); +} + +TEST(DownloadRequestInfobar, CloseTest) { + MockTabDownloadState state; + DownloadRequestInfoBarDelegate infobar(NULL, &state); + infobar.InfoBarClosed(); + EXPECT_FALSE(state.accepted()); +} diff --git a/chrome/browser/download/download_request_manager.cc b/chrome/browser/download/download_request_manager.cc index 83811e2..98a20ff 100644 --- a/chrome/browser/download/download_request_manager.cc +++ b/chrome/browser/download/download_request_manager.cc @@ -6,7 +6,7 @@ #include "base/message_loop.h" #include "base/thread.h" -#include "chrome/browser/download/download_request_dialog_delegate.h" +#include "chrome/browser/download/download_request_infobar_delegate.h" #include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/tab_contents_delegate.h" @@ -23,7 +23,7 @@ DownloadRequestManager::TabDownloadState::TabDownloadState( : host_(host), controller_(controller), status_(DownloadRequestManager::ALLOW_ONE_DOWNLOAD), - dialog_delegate_(NULL) { + infobar_(NULL) { Source<NavigationController> notification_source(controller); registrar_.Add(this, NotificationType::NAV_ENTRY_PENDING, notification_source); @@ -39,8 +39,8 @@ DownloadRequestManager::TabDownloadState::~TabDownloadState() { // We should only be destroyed after the callbacks have been notified. DCHECK(callbacks_.empty()); - // And we should have closed the message box. - DCHECK(!dialog_delegate_); + // And we should have closed the infobar. + DCHECK(!infobar_); } void DownloadRequestManager::TabDownloadState::OnUserGesture() { @@ -69,7 +69,7 @@ void DownloadRequestManager::TabDownloadState::PromptUserForDownload( if (DownloadRequestManager::delegate_) { NotifyCallbacks(DownloadRequestManager::delegate_->ShouldAllowDownload()); } else { - dialog_delegate_ = DownloadRequestDialogDelegate::Create(tab, this); + infobar_ = new DownloadRequestInfoBarDelegate(tab, this); } } @@ -109,13 +109,8 @@ void DownloadRequestManager::TabDownloadState::Observe( return; } - if (is_showing_prompt()) { - // We're prompting the user and they navigated away. Close the popup and - // cancel the downloads. - dialog_delegate_->CloseWindow(); - // After switch we'll notify callbacks and get deleted. - } else if (status_ == DownloadRequestManager::ALLOW_ALL_DOWNLOADS || - status_ == DownloadRequestManager::DOWNLOADS_NOT_ALLOWED) { + if (status_ == DownloadRequestManager::ALLOW_ALL_DOWNLOADS || + status_ == DownloadRequestManager::DOWNLOADS_NOT_ALLOWED) { // User has either allowed all downloads or canceled all downloads. Only // reset the download state if the user is navigating to a different // host (or host is empty). @@ -123,8 +118,7 @@ void DownloadRequestManager::TabDownloadState::Observe( entry->url().host() == initial_page_host_) { return; } - } // else case: we're not prompting user and user hasn't allowed or - // disallowed downloads, break so that we get deleted after switch. + } break; } @@ -142,10 +136,10 @@ void DownloadRequestManager::TabDownloadState::Observe( } void DownloadRequestManager::TabDownloadState::NotifyCallbacks(bool allow) { - if (dialog_delegate_) { + if (infobar_) { // Reset the delegate so we don't get notified again. - dialog_delegate_->set_host(NULL); - dialog_delegate_ = NULL; + infobar_->set_host(NULL); + infobar_ = NULL; } status_ = allow ? DownloadRequestManager::ALLOW_ALL_DOWNLOADS : diff --git a/chrome/browser/download/download_request_manager.h b/chrome/browser/download/download_request_manager.h index f9351c8..8844de7 100644 --- a/chrome/browser/download/download_request_manager.h +++ b/chrome/browser/download/download_request_manager.h @@ -13,7 +13,7 @@ #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" -class DownloadRequestDialogDelegate; +class DownloadRequestInfoBarDelegate; class MessageLoop; class NavigationController; class TabContents; @@ -60,8 +60,7 @@ class DownloadRequestManager : }; // TabDownloadState maintains the download state for a particular tab. - // TabDownloadState installs observers to update the download status - // appropriately. Additionally TabDownloadState prompts the user as necessary. + // TabDownloadState prompts the user with an infobar as necessary. // TabDownloadState deletes itself (by invoking // DownloadRequestManager::Remove) as necessary. class TabDownloadState : public NotificationObserver { @@ -96,15 +95,24 @@ class DownloadRequestManager : DownloadRequestManager::Callback* callback); // Are we showing a prompt to the user? - bool is_showing_prompt() const { return (dialog_delegate_ != NULL); } + bool is_showing_prompt() const { return (infobar_ != NULL); } // NavigationController we're tracking. NavigationController* controller() const { return controller_; } // Invoked from DownloadRequestDialogDelegate. Notifies the delegates and - // changes the status appropriately. - void Cancel(); - void Accept(); + // changes the status appropriately. Virtual for testing. + virtual void Cancel(); + virtual void Accept(); + + protected: + // Used for testing. + TabDownloadState() + : host_(NULL), + controller_(NULL), + status_(DownloadRequestManager::ALLOW_ONE_DOWNLOAD), + infobar_(NULL) { + } private: // NotificationObserver method. @@ -134,8 +142,8 @@ class DownloadRequestManager : // Used to remove observers installed on NavigationController. NotificationRegistrar registrar_; - // Handles showing the dialog to the user, may be null. - DownloadRequestDialogDelegate* dialog_delegate_; + // Handles showing the infobar to the user, may be null. + DownloadRequestInfoBarDelegate* infobar_; DISALLOW_COPY_AND_ASSIGN(TabDownloadState); }; diff --git a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc b/chrome/browser/extensions/extension_disabled_infobar_delegate.cc index 14cc3e7..8e4de1a 100644 --- a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc +++ b/chrome/browser/extensions/extension_disabled_infobar_delegate.cc @@ -37,6 +37,9 @@ class ExtensionDisabledDialogDelegate NewRunnableMethod(this, &ExtensionDisabledDialogDelegate::Start)); } + virtual ~ExtensionDisabledDialogDelegate() { + } + // ExtensionInstallUI::Delegate virtual void ContinueInstall() { service_->EnableExtension(extension_->id()); @@ -89,8 +92,7 @@ class ExtensionDisabledInfobarDelegate registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED, Source<ExtensionsService>(service)); } - virtual void InfoBarClosed() { - delete this; + virtual ~ExtensionDisabledInfobarDelegate() { } virtual std::wstring GetMessageText() const { return l10n_util::GetStringF(IDS_EXTENSION_DISABLED_INFOBAR_LABEL, diff --git a/chrome/browser/gtk/download_request_dialog_delegate_gtk.cc b/chrome/browser/gtk/download_request_dialog_delegate_gtk.cc deleted file mode 100644 index 8903ee2..0000000 --- a/chrome/browser/gtk/download_request_dialog_delegate_gtk.cc +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (c) 2009 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/gtk/download_request_dialog_delegate_gtk.h" - -#include "app/l10n_util.h" -#include "chrome/browser/gtk/constrained_window_gtk.h" -#include "chrome/common/gtk_util.h" -#include "chrome/browser/tab_contents/tab_contents.h" -#include "grit/generated_resources.h" - -static const int kButtonSpacing = 3; - -// static -DownloadRequestDialogDelegate* DownloadRequestDialogDelegate::Create( - TabContents* tab, - DownloadRequestManager::TabDownloadState* host) { - return new DownloadRequestDialogDelegateGtk(tab, host); -} - -DownloadRequestDialogDelegateGtk::~DownloadRequestDialogDelegateGtk() { - root_.Destroy(); -} - -DownloadRequestDialogDelegateGtk::DownloadRequestDialogDelegateGtk( - TabContents* tab, - DownloadRequestManager::TabDownloadState* host) - : DownloadRequestDialogDelegate(host), - responded_(false) { - // Create dialog. - root_.Own(gtk_vbox_new(NULL, gtk_util::kContentAreaBorder)); - GtkWidget* label = gtk_label_new( - l10n_util::GetStringUTF8(IDS_MULTI_DOWNLOAD_WARNING).c_str()); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); - gtk_box_pack_start(GTK_BOX(root_.get()), label, FALSE, FALSE, 0); - - GtkWidget* hbox = gtk_hbutton_box_new(); - gtk_button_box_set_layout(GTK_BUTTON_BOX(hbox), GTK_BUTTONBOX_END); - gtk_box_set_spacing(GTK_BOX(hbox), kButtonSpacing); - gtk_box_pack_start(GTK_BOX(root_.get()), hbox, FALSE, FALSE, 0); - - GtkWidget* deny = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_MULTI_DOWNLOAD_WARNING_DENY).c_str()); - gtk_button_set_image( - GTK_BUTTON(deny), - gtk_image_new_from_stock(GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON)); - g_signal_connect(deny, "clicked", G_CALLBACK(OnDenyClickedThunk), this); - gtk_box_pack_end(GTK_BOX(hbox), deny, FALSE, FALSE, 0); - - GtkWidget* allow = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_MULTI_DOWNLOAD_WARNING_ALLOW).c_str()); - gtk_button_set_image( - GTK_BUTTON(allow), - gtk_image_new_from_stock(GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON)); - g_signal_connect(allow, "clicked", G_CALLBACK(OnAllowClickedThunk), this); - gtk_box_pack_end(GTK_BOX(hbox), allow, FALSE, FALSE, 0); - - // Attach to window. - window_ = tab->CreateConstrainedDialog(this); - - // Now that we have attached ourself to the window, we can make our deny - // button the default action and mess with the focus. - GTK_WIDGET_SET_FLAGS(deny, GTK_CAN_DEFAULT); - gtk_widget_grab_default(deny); -} - -void DownloadRequestDialogDelegateGtk::CloseWindow() { - window_->CloseConstrainedWindow(); -} - -GtkWidget* DownloadRequestDialogDelegateGtk::GetWidgetRoot() { - return root_.get(); -} - -void DownloadRequestDialogDelegateGtk::DeleteDelegate() { - if (!responded_) - DoCancel(); - DCHECK(!host_); - delete this; -} - -void DownloadRequestDialogDelegateGtk::OnAllowClicked() { - DoAccept(); - responded_ = true; - CloseWindow(); -} - -void DownloadRequestDialogDelegateGtk::OnDenyClicked() { - DoCancel(); - responded_ = true; - CloseWindow(); -} diff --git a/chrome/browser/gtk/download_request_dialog_delegate_gtk.h b/chrome/browser/gtk/download_request_dialog_delegate_gtk.h deleted file mode 100644 index 5f65f99..0000000 --- a/chrome/browser/gtk/download_request_dialog_delegate_gtk.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) 2009 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_GTK_DOWNLOAD_REQUEST_DIALOG_DELEGATE_GTK_H_ -#define CHROME_BROWSER_GTK_DOWNLOAD_REQUEST_DIALOG_DELEGATE_GTK_H_ - -#include <gtk/gtk.h> - -#include "chrome/browser/download/download_request_dialog_delegate.h" -#include "chrome/browser/gtk/constrained_window_gtk.h" - -class DownloadRequestDialogDelegateGtk : public DownloadRequestDialogDelegate, - public ConstrainedWindowGtkDelegate { - public: - DownloadRequestDialogDelegateGtk(TabContents* tab, - DownloadRequestManager::TabDownloadState* host); - - virtual ~DownloadRequestDialogDelegateGtk(); - - private: - // DownloadRequestDialogDelegate methods. - virtual void CloseWindow(); - - // ConstrainedWindowGtkDelegate methods. - virtual GtkWidget* GetWidgetRoot(); - virtual void DeleteDelegate(); - - // Other methods. - static void OnAllowClickedThunk(GtkButton* button, - DownloadRequestDialogDelegateGtk* delegate) { - delegate->OnAllowClicked(); - } - void OnAllowClicked(); - static void OnDenyClickedThunk(GtkButton* button, - DownloadRequestDialogDelegateGtk* delegate) { - delegate->OnDenyClicked(); - } - void OnDenyClicked(); - - // The ConstrainedWindow that is hosting our DownloadRequestDialog. - ConstrainedWindow* window_; - - // Our root widget. - OwnedWidgetGtk root_; - - // Tracks whether we have responded so we can send a cancel response - // when we are getting deleted. DRDDWin gets this for free from its - // views::DialogDelegate superclass. - bool responded_; - - DISALLOW_COPY_AND_ASSIGN(DownloadRequestDialogDelegateGtk); -}; - -#endif // CHROME_BROWSER_GTK_DOWNLOAD_REQUEST_DIALOG_DELEGATE_GTK_H_ |