summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa
diff options
context:
space:
mode:
authorbauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-09 11:59:02 +0000
committerbauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-09 11:59:02 +0000
commit965bb0937dc924fbabe69a350c427aa3d84f76ab (patch)
treece6e1ebfa7f64a97467e2b1555cfd26462676d86 /chrome/browser/cocoa
parente14c72d324f6eddfc0f1b1d462ea7e897da5fc1c (diff)
downloadchromium_src-965bb0937dc924fbabe69a350c427aa3d84f76ab.zip
chromium_src-965bb0937dc924fbabe69a350c427aa3d84f76ab.tar.gz
chromium_src-965bb0937dc924fbabe69a350c427aa3d84f76ab.tar.bz2
Refactor common, platform-independent code for the repost form warning dialog on all platforms into a delegate.
The platform-dependent ConstrainedWindow{Gtk,Mac,Win} classes each have their own platform-dependent |ConstrainedWindowDelegate| to inherit from, so instead of a common superclass they now have a RepostFormWarningDelegate. Also, change the RELOADING notification to REPOST_WARNING_SHOWN to avoid trying to close the dialog while it's already in the process of being closed. BUG=none TEST=RepostFormWarningTest.* Review URL: http://codereview.chromium.org/1520023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44074 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r--chrome/browser/cocoa/browser_window_cocoa.mm5
-rw-r--r--chrome/browser/cocoa/repost_form_warning_mac.h48
-rw-r--r--chrome/browser/cocoa/repost_form_warning_mac.mm88
3 files changed, 41 insertions, 100 deletions
diff --git a/chrome/browser/cocoa/browser_window_cocoa.mm b/chrome/browser/cocoa/browser_window_cocoa.mm
index a425f79..186ec86 100644
--- a/chrome/browser/cocoa/browser_window_cocoa.mm
+++ b/chrome/browser/cocoa/browser_window_cocoa.mm
@@ -321,9 +321,8 @@ void BrowserWindowCocoa::ShowNewProfileDialog() {
NOTIMPLEMENTED();
}
-void BrowserWindowCocoa::ShowRepostFormWarningDialog(
- TabContents* tab_contents) {
- new RepostFormWarningMac(GetNativeHandle(), tab_contents);
+void BrowserWindowCocoa::ShowRepostFormWarningDialog(TabContents* tab_contents) {
+ RepostFormWarningMac::Create(GetNativeHandle(), tab_contents);
}
void BrowserWindowCocoa::ShowContentSettingsWindow(
diff --git a/chrome/browser/cocoa/repost_form_warning_mac.h b/chrome/browser/cocoa/repost_form_warning_mac.h
index a9c480a..7139be6 100644
--- a/chrome/browser/cocoa/repost_form_warning_mac.h
+++ b/chrome/browser/cocoa/repost_form_warning_mac.h
@@ -8,49 +8,31 @@
#import <Cocoa/Cocoa.h>
#include "base/scoped_nsobject.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/cocoa/constrained_window_mac.h"
-#include "chrome/common/notification_registrar.h"
-
-class NavigationController;
-@class RepostDelegate;
-class RepostFormWarningMac;
-
-// Displays a dialog that warns the user that they are about to resubmit a form.
-// To display the dialog, allocate this object on the heap. It will open the
-// dialog from its constructor and then delete itself when the user dismisses
-// the dialog.
-class RepostFormWarningMac : public NotificationObserver,
- public ConstrainedWindowMacDelegateSystemSheet {
+
+class RepostFormWarningController;
+
+// Displays a dialog that warns the user that they are about to resubmit
+// a form. To show the dialog, call the |Create| method. It will open the
+// dialog and then delete itself when the user dismisses the dialog.
+class RepostFormWarningMac : public ConstrainedDialogDelegate {
public:
+ // Convenience method that creates a new |RepostFormWarningController| and
+ // then a new |RepostFormWarningMac| from that.
+ static RepostFormWarningMac* Create(NSWindow* parent,
+ TabContents* tab_contents);
+
RepostFormWarningMac(NSWindow* parent,
- TabContents* tab_contents);
- virtual ~RepostFormWarningMac();
+ RepostFormWarningController* controller);
+ // ConstrainedWindowDelegateMacSystemSheet methods:
virtual void DeleteDelegate();
- void Confirm();
- void Cancel();
-
private:
- // NotificationObserver implementation.
- // Watch for a new load or a closed tab and dismiss the dialog if they occur.
- virtual void Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details);
+ virtual ~RepostFormWarningMac();
// Close the sheet.
void Dismiss();
- // Clean up. This will only be done once, even if Destroy is called
- // multiple times (eg, from both Confirm and Observe.)
- void Destroy();
-
- NotificationRegistrar registrar_;
-
- // Navigation controller, used to continue the reload.
- NavigationController* navigation_controller_;
-
- ConstrainedWindow* window_;
DISALLOW_COPY_AND_ASSIGN(RepostFormWarningMac);
};
diff --git a/chrome/browser/cocoa/repost_form_warning_mac.mm b/chrome/browser/cocoa/repost_form_warning_mac.mm
index 31292c0..adfe54e8 100644
--- a/chrome/browser/cocoa/repost_form_warning_mac.mm
+++ b/chrome/browser/cocoa/repost_form_warning_mac.mm
@@ -5,24 +5,22 @@
#include "chrome/browser/cocoa/repost_form_warning_mac.h"
#include "app/l10n_util_mac.h"
-#include "base/message_loop.h"
-#include "chrome/browser/tab_contents/navigation_controller.h"
-#include "chrome/common/notification_service.h"
+#include "chrome/browser/repost_form_warning_controller.h"
#include "grit/generated_resources.h"
// The delegate of the NSAlert used to display the dialog. Forwards the alert's
-// completion event to the C++ class |RepostFormWarningMac|.
+// completion event to the C++ class |RepostFormWarningController|.
@interface RepostDelegate : NSObject {
- RepostFormWarningMac* warning_; // weak, owns us.
+ RepostFormWarningController* warning_; // weak
}
-- (id)initWithWarning:(RepostFormWarningMac*)warning;
+- (id)initWithWarning:(RepostFormWarningController*)warning;
- (void)alertDidEnd:(NSAlert*)alert
returnCode:(int)returnCode
contextInfo:(void*)contextInfo;
@end
@implementation RepostDelegate
-- (id)initWithWarning:(RepostFormWarningMac*)warning {
+- (id)initWithWarning:(RepostFormWarningController*)warning {
if ((self = [super init])) {
warning_ = warning;
}
@@ -32,20 +30,28 @@
- (void)alertDidEnd:(NSAlert*)alert
returnCode:(int)returnCode
contextInfo:(void*)contextInfo {
- if (returnCode == NSAlertFirstButtonReturn)
- warning_->Confirm();
- else
+ if (returnCode == NSAlertFirstButtonReturn) {
+ warning_->Continue();
+ } else {
warning_->Cancel();
+ }
}
@end
+RepostFormWarningMac* RepostFormWarningMac::Create(NSWindow* parent,
+ TabContents* tab_contents) {
+ return new RepostFormWarningMac(
+ parent,
+ new RepostFormWarningController(tab_contents));
+}
+
RepostFormWarningMac::RepostFormWarningMac(
NSWindow* parent,
- TabContents* tab_contents)
+ RepostFormWarningController* controller)
: ConstrainedWindowMacDelegateSystemSheet(
- [[[RepostDelegate alloc] initWithWarning:this] autorelease],
- @selector(alertDidEnd:returnCode:contextInfo:)),
- navigation_controller_(&tab_contents->controller()) {
+ [[[RepostDelegate alloc] initWithWarning:controller]
+ autorelease],
+ @selector(alertDidEnd:returnCode:contextInfo:)) {
scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]);
[alert setMessageText:
l10n_util::GetNSStringWithFixup(IDS_HTTP_POST_WARNING_TITLE)];
@@ -58,67 +64,21 @@ RepostFormWarningMac::RepostFormWarningMac(
set_sheet(alert);
- registrar_.Add(this, NotificationType::LOAD_START,
- Source<NavigationController>(navigation_controller_));
- registrar_.Add(this, NotificationType::TAB_CLOSING,
- Source<NavigationController>(navigation_controller_));
- registrar_.Add(this, NotificationType::RELOADING,
- Source<NavigationController>(navigation_controller_));
- window_ = tab_contents->CreateConstrainedDialog(this);
+ controller->Show(this);
}
RepostFormWarningMac::~RepostFormWarningMac() {
}
void RepostFormWarningMac::DeleteDelegate() {
- window_ = NULL;
Dismiss();
delete this;
}
-void RepostFormWarningMac::Confirm() {
- if (navigation_controller_) {
- navigation_controller_->ContinuePendingReload();
- }
- Destroy();
-}
-
-void RepostFormWarningMac::Cancel() {
- if (navigation_controller_) {
- navigation_controller_->CancelPendingReload();
- }
- Destroy();
-}
-
void RepostFormWarningMac::Dismiss() {
- if (sheet() && is_sheet_open()) {
- // This will call |Cancel()|.
- [NSApp endSheet:[(NSAlert*)sheet() window]
+ NSWindow* window = [(NSAlert*)sheet() window];
+ if (window && is_sheet_open()) {
+ [NSApp endSheet:window
returnCode:NSAlertSecondButtonReturn];
}
}
-
-void RepostFormWarningMac::Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- // Close the dialog if we load a page (because reloading might not apply to
- // the same page anymore) or if the tab is closed, because then we won't have
- // a navigation controller anymore.
- if ((type == NotificationType::LOAD_START ||
- type == NotificationType::TAB_CLOSING ||
- type == NotificationType::RELOADING)) {
- DCHECK_EQ(Source<NavigationController>(source).ptr(),
- navigation_controller_);
- Dismiss();
- }
-}
-
-void RepostFormWarningMac::Destroy() {
- navigation_controller_ = NULL;
- if (sheet()) {
- set_sheet(nil);
- }
- if (window_) {
- window_->CloseConstrainedWindow();
- }
-}