Add a minor text member to ui::MenuModel.
[chromium-blink-merge.git] / chrome / browser / ui / tab_modal_confirm_dialog_delegate.cc
blob9e49df0d9902af42519eb53bab25b59cef60813e
1 // Copyright (c) 2012 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.
5 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h"
7 #include "chrome/browser/chrome_notification_types.h"
8 #include "content/public/browser/navigation_controller.h"
9 #include "content/public/browser/notification_source.h"
10 #include "content/public/browser/web_contents.h"
11 #include "grit/generated_resources.h"
12 #include "ui/base/l10n/l10n_util.h"
14 using content::NavigationController;
15 using content::WebContents;
17 TabModalConfirmDialogDelegate::TabModalConfirmDialogDelegate(
18 WebContents* web_contents)
19 : close_delegate_(NULL),
20 closing_(false) {
21 NavigationController* controller = &web_contents->GetController();
22 registrar_.Add(this, content::NOTIFICATION_LOAD_START,
23 content::Source<NavigationController>(controller));
24 registrar_.Add(this, chrome::NOTIFICATION_TAB_CLOSING,
25 content::Source<NavigationController>(controller));
28 TabModalConfirmDialogDelegate::~TabModalConfirmDialogDelegate() {
29 // If we end up here, the window has been closed, so make sure we don't close
30 // it again.
31 close_delegate_ = NULL;
32 // Make sure everything is cleaned up.
33 Cancel();
36 void TabModalConfirmDialogDelegate::Cancel() {
37 if (closing_)
38 return;
39 // Make sure we won't do anything when another action occurs.
40 closing_ = true;
41 OnCanceled();
42 CloseDialog();
45 void TabModalConfirmDialogDelegate::Accept() {
46 if (closing_)
47 return;
48 // Make sure we won't do anything when another action occurs.
49 closing_ = true;
50 OnAccepted();
51 CloseDialog();
54 void TabModalConfirmDialogDelegate::LinkClicked(
55 WindowOpenDisposition disposition) {
56 if (closing_)
57 return;
58 // Make sure we won't do anything when another action occurs.
59 closing_ = true;
60 OnLinkClicked(disposition);
61 CloseDialog();
64 void TabModalConfirmDialogDelegate::Observe(
65 int type,
66 const content::NotificationSource& source,
67 const content::NotificationDetails& details) {
68 // Close the dialog if we load a page (because the action might not apply to
69 // the same page anymore) or if the tab is closed.
70 if (type == content::NOTIFICATION_LOAD_START ||
71 type == chrome::NOTIFICATION_TAB_CLOSING) {
72 Close();
73 } else {
74 NOTREACHED();
78 void TabModalConfirmDialogDelegate::Close() {
79 if (closing_)
80 return;
81 // Make sure we won't do anything when another action occurs.
82 closing_ = true;
83 OnClosed();
84 CloseDialog();
87 gfx::Image* TabModalConfirmDialogDelegate::GetIcon() {
88 return NULL;
91 string16 TabModalConfirmDialogDelegate::GetAcceptButtonTitle() {
92 return l10n_util::GetStringUTF16(IDS_OK);
95 string16 TabModalConfirmDialogDelegate::GetCancelButtonTitle() {
96 return l10n_util::GetStringUTF16(IDS_CANCEL);
99 string16 TabModalConfirmDialogDelegate::GetLinkText() const {
100 return string16();
103 const char* TabModalConfirmDialogDelegate::GetAcceptButtonIcon() {
104 return NULL;
107 const char* TabModalConfirmDialogDelegate::GetCancelButtonIcon() {
108 return NULL;
111 void TabModalConfirmDialogDelegate::OnAccepted() {
114 void TabModalConfirmDialogDelegate::OnCanceled() {
117 void TabModalConfirmDialogDelegate::OnLinkClicked(
118 WindowOpenDisposition disposition) {
121 void TabModalConfirmDialogDelegate::OnClosed() {
124 void TabModalConfirmDialogDelegate::CloseDialog() {
125 if (close_delegate_)
126 close_delegate_->CloseDialog();