OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/views/external_protocol_dialog.h" | 5 #include "chrome/browser/ui/views/external_protocol_dialog.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/message_box_flags.h" | |
9 #include "app/text_elider.h" | |
10 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
11 #include "base/string_util.h" | 9 #include "base/string_util.h" |
12 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
13 #include "base/threading/thread_restrictions.h" | 11 #include "base/threading/thread_restrictions.h" |
14 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
15 #include "base/win/registry.h" | 13 #include "base/win/registry.h" |
16 #include "chrome/browser/external_protocol_handler.h" | 14 #include "chrome/browser/external_protocol_handler.h" |
17 #include "chrome/browser/tab_contents/tab_contents.h" | 15 #include "chrome/browser/tab_contents/tab_contents.h" |
18 #include "chrome/browser/tab_contents/tab_util.h" | 16 #include "chrome/browser/tab_contents/tab_util.h" |
19 #include "grit/chromium_strings.h" | 17 #include "grit/chromium_strings.h" |
20 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 19 #include "ui/base/message_box_flags.h" |
| 20 #include "ui/base/text/text_elider.h" |
21 #include "views/controls/message_box_view.h" | 21 #include "views/controls/message_box_view.h" |
22 #include "views/window/window.h" | 22 #include "views/window/window.h" |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 const int kMessageWidth = 400; | 26 const int kMessageWidth = 400; |
27 | 27 |
28 } // namespace | 28 } // namespace |
29 | 29 |
30 /////////////////////////////////////////////////////////////////////////////// | 30 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 18 matching lines...) Expand all Loading... |
49 /////////////////////////////////////////////////////////////////////////////// | 49 /////////////////////////////////////////////////////////////////////////////// |
50 // ExternalProtocolDialog | 50 // ExternalProtocolDialog |
51 | 51 |
52 ExternalProtocolDialog::~ExternalProtocolDialog() { | 52 ExternalProtocolDialog::~ExternalProtocolDialog() { |
53 } | 53 } |
54 | 54 |
55 ////////////////////////////////////////////////////////////////////////////// | 55 ////////////////////////////////////////////////////////////////////////////// |
56 // ExternalProtocolDialog, views::DialogDelegate implementation: | 56 // ExternalProtocolDialog, views::DialogDelegate implementation: |
57 | 57 |
58 int ExternalProtocolDialog::GetDefaultDialogButton() const { | 58 int ExternalProtocolDialog::GetDefaultDialogButton() const { |
59 return MessageBoxFlags::DIALOGBUTTON_CANCEL; | 59 return ui::MessageBoxFlags::DIALOGBUTTON_CANCEL; |
60 } | 60 } |
61 | 61 |
62 std::wstring ExternalProtocolDialog::GetDialogButtonLabel( | 62 std::wstring ExternalProtocolDialog::GetDialogButtonLabel( |
63 MessageBoxFlags::DialogButton button) const { | 63 ui::MessageBoxFlags::DialogButton button) const { |
64 if (button == MessageBoxFlags::DIALOGBUTTON_OK) | 64 if (button == ui::MessageBoxFlags::DIALOGBUTTON_OK) |
65 return UTF16ToWide( | 65 return UTF16ToWide( |
66 l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_OK_BUTTON_TEXT)); | 66 l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_OK_BUTTON_TEXT)); |
67 else | 67 else |
68 return UTF16ToWide( | 68 return UTF16ToWide( |
69 l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_CANCEL_BUTTON_TEXT)); | 69 l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_CANCEL_BUTTON_TEXT)); |
70 } | 70 } |
71 | 71 |
72 std::wstring ExternalProtocolDialog::GetWindowTitle() const { | 72 std::wstring ExternalProtocolDialog::GetWindowTitle() const { |
73 return UTF16ToWide(l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_TITLE)); | 73 return UTF16ToWide(l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_TITLE)); |
74 } | 74 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 ExternalProtocolDialog::ExternalProtocolDialog(TabContents* tab_contents, | 118 ExternalProtocolDialog::ExternalProtocolDialog(TabContents* tab_contents, |
119 const GURL& url, | 119 const GURL& url, |
120 const std::wstring& command) | 120 const std::wstring& command) |
121 : tab_contents_(tab_contents), | 121 : tab_contents_(tab_contents), |
122 url_(url), | 122 url_(url), |
123 creation_time_(base::TimeTicks::Now()) { | 123 creation_time_(base::TimeTicks::Now()) { |
124 const int kMaxUrlWithoutSchemeSize = 256; | 124 const int kMaxUrlWithoutSchemeSize = 256; |
125 const int kMaxCommandSize = 256; | 125 const int kMaxCommandSize = 256; |
126 std::wstring elided_url_without_scheme; | 126 std::wstring elided_url_without_scheme; |
127 std::wstring elided_command; | 127 std::wstring elided_command; |
128 gfx::ElideString(ASCIIToWide(url.possibly_invalid_spec()), | 128 ui::ElideString(ASCIIToWide(url.possibly_invalid_spec()), |
129 kMaxUrlWithoutSchemeSize, &elided_url_without_scheme); | 129 kMaxUrlWithoutSchemeSize, &elided_url_without_scheme); |
130 gfx::ElideString(command, kMaxCommandSize, &elided_command); | 130 ui::ElideString(command, kMaxCommandSize, &elided_command); |
131 | 131 |
132 std::wstring message_text = UTF16ToWide(l10n_util::GetStringFUTF16( | 132 std::wstring message_text = UTF16ToWide(l10n_util::GetStringFUTF16( |
133 IDS_EXTERNAL_PROTOCOL_INFORMATION, | 133 IDS_EXTERNAL_PROTOCOL_INFORMATION, |
134 ASCIIToUTF16(url.scheme() + ":"), | 134 ASCIIToUTF16(url.scheme() + ":"), |
135 elided_url_without_scheme) + ASCIIToUTF16("\n\n")); | 135 elided_url_without_scheme) + ASCIIToUTF16("\n\n")); |
136 | 136 |
137 message_text += UTF16ToWide(l10n_util::GetStringFUTF16( | 137 message_text += UTF16ToWide(l10n_util::GetStringFUTF16( |
138 IDS_EXTERNAL_PROTOCOL_APPLICATION_TO_LAUNCH, | 138 IDS_EXTERNAL_PROTOCOL_APPLICATION_TO_LAUNCH, |
139 elided_command) + ASCIIToUTF16("\n\n")); | 139 elided_command) + ASCIIToUTF16("\n\n")); |
140 | 140 |
141 message_text += | 141 message_text += |
142 UTF16ToWide(l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_WARNING)); | 142 UTF16ToWide(l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_WARNING)); |
143 | 143 |
144 message_box_view_ = new MessageBoxView(MessageBoxFlags::kIsConfirmMessageBox, | 144 message_box_view_ = new MessageBoxView( |
145 message_text, | 145 ui::MessageBoxFlags::kIsConfirmMessageBox, |
146 std::wstring(), | 146 message_text, |
147 kMessageWidth); | 147 std::wstring(), |
| 148 kMessageWidth); |
148 message_box_view_->SetCheckBoxLabel(UTF16ToWide( | 149 message_box_view_->SetCheckBoxLabel(UTF16ToWide( |
149 l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_CHECKBOX_TEXT))); | 150 l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_CHECKBOX_TEXT))); |
150 | 151 |
151 HWND root_hwnd; | 152 HWND root_hwnd; |
152 if (tab_contents_) { | 153 if (tab_contents_) { |
153 root_hwnd = GetAncestor(tab_contents_->GetContentNativeView(), GA_ROOT); | 154 root_hwnd = GetAncestor(tab_contents_->GetContentNativeView(), GA_ROOT); |
154 } else { | 155 } else { |
155 // Dialog is top level if we don't have a tab_contents associated with us. | 156 // Dialog is top level if we don't have a tab_contents associated with us. |
156 root_hwnd = NULL; | 157 root_hwnd = NULL; |
157 } | 158 } |
(...skipping 18 matching lines...) Expand all Loading... |
176 std::wstring parameters = url_spec.substr(split_offset + 1, | 177 std::wstring parameters = url_spec.substr(split_offset + 1, |
177 url_spec.length() - 1); | 178 url_spec.length() - 1); |
178 std::wstring application_to_launch; | 179 std::wstring application_to_launch; |
179 if (cmd_key.ReadValue(NULL, &application_to_launch) == ERROR_SUCCESS) { | 180 if (cmd_key.ReadValue(NULL, &application_to_launch) == ERROR_SUCCESS) { |
180 ReplaceSubstringsAfterOffset(&application_to_launch, 0, L"%1", parameters); | 181 ReplaceSubstringsAfterOffset(&application_to_launch, 0, L"%1", parameters); |
181 return application_to_launch; | 182 return application_to_launch; |
182 } else { | 183 } else { |
183 return std::wstring(); | 184 return std::wstring(); |
184 } | 185 } |
185 } | 186 } |
OLD | NEW |