| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/external_protocol_dialog.h" | 5 #include "chrome/browser/chromeos/external_protocol_dialog.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/sparse_histogram.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/chromeos/arc/arc_external_protocol_dialog.h" | 10 #include "chrome/browser/chromeos/arc/arc_external_protocol_dialog.h" |
| 11 #include "chrome/browser/external_protocol/external_protocol_handler.h" | 11 #include "chrome/browser/external_protocol/external_protocol_handler.h" |
| 12 #include "chrome/browser/tab_contents/tab_util.h" | 12 #include "chrome/browser/tab_contents/tab_util.h" |
| 13 #include "chrome/grit/chromium_strings.h" | 13 #include "chrome/grit/chromium_strings.h" |
| 14 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "ui/gfx/text_elider.h" | 17 #include "ui/gfx/text_elider.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 base::string16 ExternalProtocolDialog::GetWindowTitle() const { | 69 base::string16 ExternalProtocolDialog::GetWindowTitle() const { |
| 70 return l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_TITLE); | 70 return l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_TITLE); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void ExternalProtocolDialog::DeleteDelegate() { | 73 void ExternalProtocolDialog::DeleteDelegate() { |
| 74 delete this; | 74 delete this; |
| 75 } | 75 } |
| 76 | 76 |
| 77 bool ExternalProtocolDialog::Accept() { | 77 bool ExternalProtocolDialog::Accept() { |
| 78 if (message_box_view_->IsCheckBoxSelected()) { | 78 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 79 ExternalProtocolHandler::SetBlockState( | 79 ExternalProtocolHandler::kRememberCheckedHistogram, |
| 80 scheme_, ExternalProtocolHandler::DONT_BLOCK); | 80 message_box_view_->IsCheckBoxSelected()); |
| 81 } | 81 |
| 82 // Returning true closes the dialog. | 82 // Returning true closes the dialog. |
| 83 return true; | 83 return true; |
| 84 } | 84 } |
| 85 | 85 |
| 86 views::View* ExternalProtocolDialog::GetContentsView() { | 86 views::View* ExternalProtocolDialog::GetContentsView() { |
| 87 return message_box_view_; | 87 return message_box_view_; |
| 88 } | 88 } |
| 89 | 89 |
| 90 const views::Widget* ExternalProtocolDialog::GetWidget() const { | 90 const views::Widget* ExternalProtocolDialog::GetWidget() const { |
| 91 return message_box_view_->GetWidget(); | 91 return message_box_view_->GetWidget(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 views::Widget* ExternalProtocolDialog::GetWidget() { | 94 views::Widget* ExternalProtocolDialog::GetWidget() { |
| 95 return message_box_view_->GetWidget(); | 95 return message_box_view_->GetWidget(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 /////////////////////////////////////////////////////////////////////////////// | 98 /////////////////////////////////////////////////////////////////////////////// |
| 99 // ExternalProtocolDialog, private: | 99 // ExternalProtocolDialog, private: |
| 100 | 100 |
| 101 ExternalProtocolDialog::ExternalProtocolDialog(WebContents* web_contents, | 101 ExternalProtocolDialog::ExternalProtocolDialog(WebContents* web_contents, |
| 102 const GURL& url) | 102 const GURL& url) |
| 103 : creation_time_(base::TimeTicks::Now()), | 103 : creation_time_(base::TimeTicks::Now()), |
| 104 scheme_(url.scheme()) { | 104 scheme_(url.scheme()) { |
| 105 const size_t kMaxUrlWithoutSchemeSize = 256; | 105 views::MessageBoxView::InitParams params(base::ASCIIToUTF16("")); |
| 106 base::string16 elided_url_without_scheme; | |
| 107 gfx::ElideString(base::ASCIIToUTF16(url.possibly_invalid_spec()), | |
| 108 kMaxUrlWithoutSchemeSize, &elided_url_without_scheme); | |
| 109 | |
| 110 views::MessageBoxView::InitParams params( | |
| 111 l10n_util::GetStringFUTF16(IDS_EXTERNAL_PROTOCOL_INFORMATION, | |
| 112 base::ASCIIToUTF16(url.scheme() + ":"), | |
| 113 elided_url_without_scheme) + base::ASCIIToUTF16("\n\n")); | |
| 114 params.message_width = kMessageWidth; | 106 params.message_width = kMessageWidth; |
| 115 message_box_view_ = new views::MessageBoxView(params); | 107 message_box_view_ = new views::MessageBoxView(params); |
| 116 message_box_view_->SetCheckBoxLabel( | |
| 117 l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_CHECKBOX_TEXT)); | |
| 118 | 108 |
| 119 gfx::NativeWindow parent_window; | 109 gfx::NativeWindow parent_window; |
| 120 if (web_contents) { | 110 if (web_contents) { |
| 121 parent_window = web_contents->GetTopLevelNativeWindow(); | 111 parent_window = web_contents->GetTopLevelNativeWindow(); |
| 122 } else { | 112 } else { |
| 123 // Dialog is top level if we don't have a web_contents associated with us. | 113 // Dialog is top level if we don't have a web_contents associated with us. |
| 124 parent_window = NULL; | 114 parent_window = NULL; |
| 125 } | 115 } |
| 126 views::DialogDelegate::CreateDialogWidget(this, NULL, parent_window)->Show(); | 116 views::DialogDelegate::CreateDialogWidget(this, NULL, parent_window)->Show(); |
| 127 } | 117 } |
| OLD | NEW |