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

Side by Side Diff: chrome/browser/ui/tab_modal_dialog_delegate.cc

Issue 8851007: WIP / Do not commit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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_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 TabModalDialogDelegate::TabModalDialogDelegate(
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 TabModalDialogDelegate::~TabModalDialogDelegate() {
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 TabModalDialogDelegate::Cancel() {
34 if (closing_)
35 return;
36 OnCanceled();
37 CloseDialog();
38 }
39
40 void TabModalDialogDelegate::Accept() {
41 if (closing_)
42 return;
43 OnAccepted();
44 CloseDialog();
45 }
46
47 void TabModalDialogDelegate::CloseDialog() {
48 // Make sure we won't do anything when |Cancel()| is called again.
49 closing_ = true;
50 if (window_)
51 window_->CloseConstrainedWindow();
52 }
53
54 void TabModalDialogDelegate::Observe(
55 int type,
56 const content::NotificationSource& source,
57 const content::NotificationDetails& details) {
58 // Close the dialog if we load a page (because the action might not apply to
59 // the same page anymore) or if the tab is closed.
60 if (type == content::NOTIFICATION_LOAD_START ||
61 type == content::NOTIFICATION_TAB_CLOSING) {
62 Cancel();
63 } else {
64 NOTREACHED();
65 }
66 }
67
68 gfx::Image* TabModalDialogDelegate::GetIcon() {
69 return NULL;
70 }
71
72 string16 TabModalDialogDelegate::GetAcceptButtonTitle() {
73 return l10n_util::GetStringUTF16(IDS_OK);
74 }
75
76 string16 TabModalDialogDelegate::GetCancelButtonTitle() {
77 return l10n_util::GetStringUTF16(IDS_CANCEL);
78 }
79
80 const char* TabModalDialogDelegate::GetAcceptButtonIcon() {
81 return NULL;
82 }
83
84 const char* TabModalDialogDelegate::GetCancelButtonTitleIcon() {
85 return NULL;
86 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/tab_modal_dialog_delegate.h ('k') | chrome/browser/ui/views/browser_dialogs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698