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 "chrome/grit/generated_resources.h"
9 #include "content/public/browser/navigation_controller.h"
10 #include "content/public/browser/notification_source.h"
11 #include "content/public/browser/web_contents.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
));
26 TabModalConfirmDialogDelegate::~TabModalConfirmDialogDelegate() {
27 // If we end up here, the window has been closed, so make sure we don't close
29 close_delegate_
= NULL
;
30 // Make sure everything is cleaned up.
34 void TabModalConfirmDialogDelegate::Cancel() {
37 // Make sure we won't do anything when another action occurs.
43 void TabModalConfirmDialogDelegate::Accept() {
46 // Make sure we won't do anything when another action occurs.
52 void TabModalConfirmDialogDelegate::Observe(
54 const content::NotificationSource
& source
,
55 const content::NotificationDetails
& details
) {
56 // Close the dialog if we load a page (because the action might not apply to
57 // the same page anymore).
58 DCHECK_EQ(content::NOTIFICATION_LOAD_START
, type
);
63 void TabModalConfirmDialogDelegate::Close() {
66 // Make sure we won't do anything when another action occurs.
72 void TabModalConfirmDialogDelegate::LinkClicked(
73 WindowOpenDisposition disposition
) {
76 OnLinkClicked(disposition
);
79 gfx::Image
* TabModalConfirmDialogDelegate::GetIcon() {
83 base::string16
TabModalConfirmDialogDelegate::GetAcceptButtonTitle() {
84 return l10n_util::GetStringUTF16(IDS_OK
);
87 base::string16
TabModalConfirmDialogDelegate::GetCancelButtonTitle() {
88 return l10n_util::GetStringUTF16(IDS_CANCEL
);
91 base::string16
TabModalConfirmDialogDelegate::GetLinkText() const {
92 return base::string16();
95 const char* TabModalConfirmDialogDelegate::GetAcceptButtonIcon() {
99 const char* TabModalConfirmDialogDelegate::GetCancelButtonIcon() {
103 void TabModalConfirmDialogDelegate::OnAccepted() {
106 void TabModalConfirmDialogDelegate::OnCanceled() {
109 void TabModalConfirmDialogDelegate::OnLinkClicked(
110 WindowOpenDisposition disposition
) {
113 void TabModalConfirmDialogDelegate::OnClosed() {
116 void TabModalConfirmDialogDelegate::CloseDialog() {
118 close_delegate_
->CloseDialog();