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
),
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
31 close_delegate_
= NULL
;
32 // Make sure everything is cleaned up.
36 void TabModalConfirmDialogDelegate::Cancel() {
39 // Make sure we won't do anything when another action occurs.
45 void TabModalConfirmDialogDelegate::Accept() {
48 // Make sure we won't do anything when another action occurs.
54 void TabModalConfirmDialogDelegate::LinkClicked(
55 WindowOpenDisposition disposition
) {
58 // Make sure we won't do anything when another action occurs.
60 OnLinkClicked(disposition
);
64 void TabModalConfirmDialogDelegate::Observe(
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
) {
78 void TabModalConfirmDialogDelegate::Close() {
81 // Make sure we won't do anything when another action occurs.
87 gfx::Image
* TabModalConfirmDialogDelegate::GetIcon() {
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 {
103 const char* TabModalConfirmDialogDelegate::GetAcceptButtonIcon() {
107 const char* TabModalConfirmDialogDelegate::GetCancelButtonIcon() {
111 void TabModalConfirmDialogDelegate::OnAccepted() {
114 void TabModalConfirmDialogDelegate::OnCanceled() {
117 void TabModalConfirmDialogDelegate::OnLinkClicked(
118 WindowOpenDisposition disposition
) {
121 void TabModalConfirmDialogDelegate::OnClosed() {
124 void TabModalConfirmDialogDelegate::CloseDialog() {
126 close_delegate_
->CloseDialog();