[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / views / tab_modal_confirm_dialog_views.cc
blob28e9b3b95be54370b7eca0f74212859132b932ea
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/views/tab_modal_confirm_dialog_views.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/ui/browser_dialogs.h"
9 #include "chrome/browser/ui/browser_list.h"
10 #include "chrome/browser/ui/browser_window.h"
11 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "components/web_modal/web_contents_modal_dialog_host.h"
14 #include "components/web_modal/web_contents_modal_dialog_manager.h"
15 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h"
16 #include "content/public/browser/web_contents.h"
17 #include "grit/generated_resources.h"
18 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/window_open_disposition.h"
20 #include "ui/views/controls/message_box_view.h"
21 #include "ui/views/layout/layout_constants.h"
22 #include "ui/views/widget/widget.h"
23 #include "ui/views/window/dialog_client_view.h"
25 using web_modal::WebContentsModalDialogManager;
26 using web_modal::WebContentsModalDialogManagerDelegate;
28 // static
29 TabModalConfirmDialog* TabModalConfirmDialog::Create(
30 TabModalConfirmDialogDelegate* delegate,
31 content::WebContents* web_contents) {
32 return new TabModalConfirmDialogViews(
33 delegate, web_contents);
36 //////////////////////////////////////////////////////////////////////////////
37 // TabModalConfirmDialogViews, constructor & destructor:
39 TabModalConfirmDialogViews::TabModalConfirmDialogViews(
40 TabModalConfirmDialogDelegate* delegate,
41 content::WebContents* web_contents)
42 : delegate_(delegate),
43 dialog_(NULL) {
44 views::MessageBoxView::InitParams init_params(delegate->GetDialogMessage());
45 init_params.inter_row_vertical_spacing =
46 views::kUnrelatedControlVerticalSpacing;
47 message_box_view_ = new views::MessageBoxView(init_params);
49 base::string16 link_text(delegate->GetLinkText());
50 if (!link_text.empty())
51 message_box_view_->SetLink(link_text, this);
53 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
54 WebContentsModalDialogManager::FromWebContents(web_contents);
55 WebContentsModalDialogManagerDelegate* modal_delegate =
56 web_contents_modal_dialog_manager->delegate();
57 DCHECK(modal_delegate);
58 dialog_ = views::Widget::CreateWindowAsFramelessChild(
59 this, modal_delegate->GetWebContentsModalDialogHost()->GetHostView());
60 web_contents_modal_dialog_manager->ShowModalDialog(
61 dialog_->GetNativeView());
62 delegate_->set_close_delegate(this);
65 TabModalConfirmDialogViews::~TabModalConfirmDialogViews() {
68 void TabModalConfirmDialogViews::AcceptTabModalDialog() {
69 GetDialogClientView()->AcceptWindow();
72 void TabModalConfirmDialogViews::CancelTabModalDialog() {
73 GetDialogClientView()->CancelWindow();
76 void TabModalConfirmDialogViews::CloseDialog() {
77 dialog_->Close();
80 //////////////////////////////////////////////////////////////////////////////
81 // TabModalConfirmDialogViews, views::LinkListener implementation:
83 void TabModalConfirmDialogViews::LinkClicked(views::Link* source,
84 int event_flags) {
85 delegate_->LinkClicked(ui::DispositionFromEventFlags(event_flags));
88 //////////////////////////////////////////////////////////////////////////////
89 // TabModalConfirmDialogViews, views::DialogDelegate implementation:
91 base::string16 TabModalConfirmDialogViews::GetWindowTitle() const {
92 return delegate_->GetTitle();
95 base::string16 TabModalConfirmDialogViews::GetDialogButtonLabel(
96 ui::DialogButton button) const {
97 if (button == ui::DIALOG_BUTTON_OK)
98 return delegate_->GetAcceptButtonTitle();
99 if (button == ui::DIALOG_BUTTON_CANCEL)
100 return delegate_->GetCancelButtonTitle();
101 return base::string16();
104 bool TabModalConfirmDialogViews::Cancel() {
105 delegate_->Cancel();
106 return true;
109 bool TabModalConfirmDialogViews::Accept() {
110 delegate_->Accept();
111 return true;
114 bool TabModalConfirmDialogViews::Close() {
115 delegate_->Close();
116 return true;
119 ///////////////////////////////////////////////////////////////////////////////
120 // TabModalConfirmDialogViews, views::WidgetDelegate implementation:
122 views::View* TabModalConfirmDialogViews::GetContentsView() {
123 return message_box_view_;
126 views::Widget* TabModalConfirmDialogViews::GetWidget() {
127 return message_box_view_->GetWidget();
130 const views::Widget* TabModalConfirmDialogViews::GetWidget() const {
131 return message_box_view_->GetWidget();
134 void TabModalConfirmDialogViews::DeleteDelegate() {
135 delete this;
138 ui::ModalType TabModalConfirmDialogViews::GetModalType() const {
139 #if defined(USE_ASH)
140 return ui::MODAL_TYPE_CHILD;
141 #else
142 return views::WidgetDelegate::GetModalType();
143 #endif