Extend EnrollmentHandler to handle consumer management.
[chromium-blink-merge.git] / chrome / browser / ui / tab_modal_confirm_dialog_delegate.cc
blob1892ce80dd96738a01b9508af944ba77cbb14ac7
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));
26 TabModalConfirmDialogDelegate::~TabModalConfirmDialogDelegate() {
27 // If we end up here, the window has been closed, so make sure we don't close
28 // it again.
29 close_delegate_ = NULL;
30 // Make sure everything is cleaned up.
31 Cancel();
34 void TabModalConfirmDialogDelegate::Cancel() {
35 if (closing_)
36 return;
37 // Make sure we won't do anything when another action occurs.
38 closing_ = true;
39 OnCanceled();
40 CloseDialog();
43 void TabModalConfirmDialogDelegate::Accept() {
44 if (closing_)
45 return;
46 // Make sure we won't do anything when another action occurs.
47 closing_ = true;
48 OnAccepted();
49 CloseDialog();
52 void TabModalConfirmDialogDelegate::Observe(
53 int type,
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);
60 Close();
63 void TabModalConfirmDialogDelegate::Close() {
64 if (closing_)
65 return;
66 // Make sure we won't do anything when another action occurs.
67 closing_ = true;
68 OnClosed();
69 CloseDialog();
72 void TabModalConfirmDialogDelegate::LinkClicked(
73 WindowOpenDisposition disposition) {
74 if (closing_)
75 return;
76 OnLinkClicked(disposition);
79 gfx::Image* TabModalConfirmDialogDelegate::GetIcon() {
80 return NULL;
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() {
96 return NULL;
99 const char* TabModalConfirmDialogDelegate::GetCancelButtonIcon() {
100 return NULL;
103 void TabModalConfirmDialogDelegate::OnAccepted() {
106 void TabModalConfirmDialogDelegate::OnCanceled() {
109 void TabModalConfirmDialogDelegate::OnLinkClicked(
110 WindowOpenDisposition disposition) {
113 void TabModalConfirmDialogDelegate::OnClosed() {
116 void TabModalConfirmDialogDelegate::CloseDialog() {
117 if (close_delegate_)
118 close_delegate_->CloseDialog();