Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3203)

Unified Diff: chrome/browser/ui/tab_modal_confirm_dialog_delegate.cc

Issue 8986005: Reland r114898: Add TabModalConfirmDialogDelegate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix and cleanup Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/tab_modal_confirm_dialog_delegate.cc
diff --git a/chrome/browser/ui/tab_modal_confirm_dialog_delegate.cc b/chrome/browser/ui/tab_modal_confirm_dialog_delegate.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f2b35909bfa872d74c0b827f120aa260b6c5b883
--- /dev/null
+++ b/chrome/browser/ui/tab_modal_confirm_dialog_delegate.cc
@@ -0,0 +1,93 @@
+// 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/tab_modal_confirm_dialog_delegate.h"
+
+#include "chrome/browser/ui/constrained_window.h"
+#include "content/browser/tab_contents/tab_contents.h"
+#include "content/public/browser/notification_source.h"
+#include "content/public/browser/notification_types.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+
+TabModalConfirmDialogDelegate::TabModalConfirmDialogDelegate(
+ TabContents* tab_contents)
+ : window_(NULL),
+ closing_(false) {
+ NavigationController* controller = &tab_contents->controller();
+ registrar_.Add(this, content::NOTIFICATION_LOAD_START,
+ content::Source<NavigationController>(controller));
+ registrar_.Add(this, content::NOTIFICATION_TAB_CLOSING,
+ content::Source<NavigationController>(controller));
+}
+
+TabModalConfirmDialogDelegate::~TabModalConfirmDialogDelegate() {
+ // If we end up here, the constrained window has been closed, so make sure we
+ // don't close it again.
+ window_ = NULL;
+ // Make sure everything is cleaned up.
+ Cancel();
+}
+
+void TabModalConfirmDialogDelegate::Cancel() {
+ if (closing_)
+ return;
+ OnCanceled();
+ CloseDialog();
+}
+
+void TabModalConfirmDialogDelegate::Accept() {
+ if (closing_)
+ return;
+ OnAccepted();
+ CloseDialog();
+}
+
+
+void TabModalConfirmDialogDelegate::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ // Close the dialog if we load a page (because the action might not apply to
+ // the same page anymore) or if the tab is closed.
+ if (type == content::NOTIFICATION_LOAD_START ||
+ type == content::NOTIFICATION_TAB_CLOSING) {
+ Cancel();
+ } else {
+ NOTREACHED();
+ }
+}
+
+gfx::Image* TabModalConfirmDialogDelegate::GetIcon() {
+ return NULL;
+}
+
+string16 TabModalConfirmDialogDelegate::GetAcceptButtonTitle() {
+ return l10n_util::GetStringUTF16(IDS_OK);
+}
+
+string16 TabModalConfirmDialogDelegate::GetCancelButtonTitle() {
+ return l10n_util::GetStringUTF16(IDS_CANCEL);
+}
+
+const char* TabModalConfirmDialogDelegate::GetAcceptButtonIcon() {
+ return NULL;
+}
+
+const char* TabModalConfirmDialogDelegate::GetCancelButtonIcon() {
+ return NULL;
+}
+
+void TabModalConfirmDialogDelegate::OnAccepted() {
+}
+
+void TabModalConfirmDialogDelegate::OnCanceled() {
+}
+
+void TabModalConfirmDialogDelegate::CloseDialog() {
+ // Make sure we won't do anything when |Cancel()| is called again.
+ closing_ = true;
+ if (window_)
+ window_->CloseConstrainedWindow();
+}

Powered by Google App Engine
This is Rietveld 408576698