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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h"
6
7 #include "chrome/browser/ui/constrained_window.h"
8 #include "content/browser/tab_contents/tab_contents.h"
9 #include "content/public/browser/notification_source.h"
10 #include "content/public/browser/notification_types.h"
11 #include "grit/generated_resources.h"
12 #include "ui/base/l10n/l10n_util.h"
13
14 TabModalConfirmDialogDelegate::TabModalConfirmDialogDelegate(
15 TabContents* tab_contents)
16 : window_(NULL),
17 closing_(false) {
18 NavigationController* controller = &tab_contents->controller();
19 registrar_.Add(this, content::NOTIFICATION_LOAD_START,
20 content::Source<NavigationController>(controller));
21 registrar_.Add(this, content::NOTIFICATION_TAB_CLOSING,
22 content::Source<NavigationController>(controller));
23 }
24
25 TabModalConfirmDialogDelegate::~TabModalConfirmDialogDelegate() {
26 // If we end up here, the constrained window has been closed, so make sure we
27 // don't close it again.
28 window_ = NULL;
29 // Make sure everything is cleaned up.
30 Cancel();
31 }
32
33 void TabModalConfirmDialogDelegate::Cancel() {
34 if (closing_)
35 return;
36 OnCanceled();
37 CloseDialog();
38 }
39
40 void TabModalConfirmDialogDelegate::Accept() {
41 if (closing_)
42 return;
43 OnAccepted();
44 CloseDialog();
45 }
46
47
48 void TabModalConfirmDialogDelegate::Observe(
49 int type,
50 const content::NotificationSource& source,
51 const content::NotificationDetails& details) {
52 // Close the dialog if we load a page (because the action might not apply to
53 // the same page anymore) or if the tab is closed.
54 if (type == content::NOTIFICATION_LOAD_START ||
55 type == content::NOTIFICATION_TAB_CLOSING) {
56 Cancel();
57 } else {
58 NOTREACHED();
59 }
60 }
61
62 gfx::Image* TabModalConfirmDialogDelegate::GetIcon() {
63 return NULL;
64 }
65
66 string16 TabModalConfirmDialogDelegate::GetAcceptButtonTitle() {
67 return l10n_util::GetStringUTF16(IDS_OK);
68 }
69
70 string16 TabModalConfirmDialogDelegate::GetCancelButtonTitle() {
71 return l10n_util::GetStringUTF16(IDS_CANCEL);
72 }
73
74 const char* TabModalConfirmDialogDelegate::GetAcceptButtonIcon() {
75 return NULL;
76 }
77
78 const char* TabModalConfirmDialogDelegate::GetCancelButtonIcon() {
79 return NULL;
80 }
81
82 void TabModalConfirmDialogDelegate::OnAccepted() {
83 }
84
85 void TabModalConfirmDialogDelegate::OnCanceled() {
86 }
87
88 void TabModalConfirmDialogDelegate::CloseDialog() {
89 // Make sure we won't do anything when |Cancel()| is called again.
90 closing_ = true;
91 if (window_)
92 window_->CloseConstrainedWindow();
93 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698