BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / chromeos / external_protocol_dialog.cc
bloba3cd36001c553878b7ddbe7ce9f31e16f89ac203
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/chromeos/external_protocol_dialog.h"
7 #include "base/metrics/histogram.h"
8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/external_protocol/external_protocol_handler.h"
11 #include "chrome/browser/tab_contents/tab_util.h"
12 #include "chrome/grit/chromium_strings.h"
13 #include "chrome/grit/generated_resources.h"
14 #include "content/public/browser/web_contents.h"
15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/gfx/text_elider.h"
17 #include "ui/views/controls/message_box_view.h"
18 #include "ui/views/widget/widget.h"
19 #include "url/gurl.h"
21 using content::WebContents;
23 namespace {
25 const int kMessageWidth = 400;
27 } // namespace
29 ///////////////////////////////////////////////////////////////////////////////
30 // ExternalProtocolHandler
32 // static
33 void ExternalProtocolHandler::RunExternalProtocolDialog(
34 const GURL& url,
35 int render_process_host_id,
36 int routing_id,
37 ui::PageTransition page_transition,
38 bool has_user_gesture) {
39 WebContents* web_contents = tab_util::GetWebContentsByID(
40 render_process_host_id, routing_id);
41 new ExternalProtocolDialog(web_contents, url);
44 ///////////////////////////////////////////////////////////////////////////////
45 // ExternalProtocolDialog
47 ExternalProtocolDialog::~ExternalProtocolDialog() {
50 //////////////////////////////////////////////////////////////////////////////
51 // ExternalProtocolDialog, views::DialogDelegate implementation:
53 int ExternalProtocolDialog::GetDialogButtons() const {
54 return ui::DIALOG_BUTTON_OK;
57 base::string16 ExternalProtocolDialog::GetDialogButtonLabel(
58 ui::DialogButton button) const {
59 return l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_OK_BUTTON_TEXT);
62 base::string16 ExternalProtocolDialog::GetWindowTitle() const {
63 return l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_TITLE);
66 void ExternalProtocolDialog::DeleteDelegate() {
67 delete this;
70 bool ExternalProtocolDialog::Accept() {
71 if (message_box_view_->IsCheckBoxSelected()) {
72 ExternalProtocolHandler::SetBlockState(
73 scheme_, ExternalProtocolHandler::DONT_BLOCK);
75 // Returning true closes the dialog.
76 return true;
79 views::View* ExternalProtocolDialog::GetContentsView() {
80 return message_box_view_;
83 const views::Widget* ExternalProtocolDialog::GetWidget() const {
84 return message_box_view_->GetWidget();
87 views::Widget* ExternalProtocolDialog::GetWidget() {
88 return message_box_view_->GetWidget();
91 ///////////////////////////////////////////////////////////////////////////////
92 // ExternalProtocolDialog, private:
94 ExternalProtocolDialog::ExternalProtocolDialog(WebContents* web_contents,
95 const GURL& url)
96 : creation_time_(base::TimeTicks::Now()),
97 scheme_(url.scheme()) {
98 const int kMaxUrlWithoutSchemeSize = 256;
99 base::string16 elided_url_without_scheme;
100 gfx::ElideString(base::ASCIIToUTF16(url.possibly_invalid_spec()),
101 kMaxUrlWithoutSchemeSize, &elided_url_without_scheme);
103 views::MessageBoxView::InitParams params(
104 l10n_util::GetStringFUTF16(IDS_EXTERNAL_PROTOCOL_INFORMATION,
105 base::ASCIIToUTF16(url.scheme() + ":"),
106 elided_url_without_scheme) + base::ASCIIToUTF16("\n\n"));
107 params.message_width = kMessageWidth;
108 message_box_view_ = new views::MessageBoxView(params);
109 message_box_view_->SetCheckBoxLabel(
110 l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_CHECKBOX_TEXT));
112 gfx::NativeWindow parent_window;
113 if (web_contents) {
114 parent_window = web_contents->GetTopLevelNativeWindow();
115 } else {
116 // Dialog is top level if we don't have a web_contents associated with us.
117 parent_window = NULL;
119 views::DialogDelegate::CreateDialogWidget(this, NULL, parent_window)->Show();