OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/external_protocol_dialog_delegate.h" | 5 #include "chrome/browser/ui/external_protocol_dialog_delegate.h" |
6 | 6 |
7 #include <string> | |
8 | |
9 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
10 #include "base/threading/thread.h" | |
11 #include "base/threading/thread_restrictions.h" | |
12 #include "chrome/browser/external_protocol/external_protocol_handler.h" | 8 #include "chrome/browser/external_protocol/external_protocol_handler.h" |
13 #include "chrome/grit/chromium_strings.h" | 9 #include "chrome/grit/chromium_strings.h" |
14 #include "chrome/grit/generated_resources.h" | 10 #include "chrome/grit/generated_resources.h" |
| 11 #include "components/strings/grit/components_strings.h" |
15 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
16 #include "ui/gfx/text_elider.h" | 13 #include "ui/gfx/text_elider.h" |
17 | 14 |
| 15 namespace { |
| 16 |
| 17 const size_t kMaxCommandSize = 64: |
| 18 |
| 19 base::string16 ElideCommandName(const base::string16& command_name) { |
| 20 base::string16 elided_command; |
| 21 gfx::ElideString(command_name, kMaxCommandSize, &elided_command); |
| 22 return elided_command; |
| 23 } |
| 24 |
| 25 } // namespace |
| 26 |
18 ExternalProtocolDialogDelegate::ExternalProtocolDialogDelegate( | 27 ExternalProtocolDialogDelegate::ExternalProtocolDialogDelegate( |
19 const GURL& url, | 28 const GURL& url, |
20 int render_process_host_id, | 29 int render_process_host_id, |
21 int tab_contents_id) | 30 int tab_contents_id) |
22 : ProtocolDialogDelegate(url), | 31 : ProtocolDialogDelegate(url), |
23 render_process_host_id_(render_process_host_id), | 32 render_process_host_id_(render_process_host_id), |
24 tab_contents_id_(tab_contents_id), | 33 tab_contents_id_(tab_contents_id), |
25 program_name_(shell_integration::GetApplicationNameForProtocol(url)) {} | 34 program_name_(shell_integration::GetApplicationNameForProtocol(url)) {} |
26 | 35 |
27 ExternalProtocolDialogDelegate::~ExternalProtocolDialogDelegate() { | 36 ExternalProtocolDialogDelegate::~ExternalProtocolDialogDelegate() { |
28 } | 37 } |
29 | 38 |
| 39 base::string16 ExternalProtocolDialogDelegate::GetDialogButtonLabel( |
| 40 ui::DialogButton button) const { |
| 41 if (button == ui::DIALOG_BUTTON_OK) { |
| 42 return l10n_util::GetStringFUTF16(IDS_EXTERNAL_PROTOCOL_OK_BUTTON_TEXT, |
| 43 ElideCommandName(program_name_)); |
| 44 } |
| 45 return l10n_util::GetStringUTF16(IDS_CANCEL); |
| 46 } |
| 47 |
30 base::string16 ExternalProtocolDialogDelegate::GetMessageText() const { | 48 base::string16 ExternalProtocolDialogDelegate::GetMessageText() const { |
31 const size_t kMaxUrlWithoutSchemeSize = 256; | 49 return base::string16(); |
32 const size_t kMaxCommandSize = 256; | |
33 base::string16 elided_url_without_scheme; | |
34 base::string16 elided_command; | |
35 gfx::ElideString(base::ASCIIToUTF16(url().possibly_invalid_spec()), | |
36 kMaxUrlWithoutSchemeSize, &elided_url_without_scheme); | |
37 gfx::ElideString(program_name_, kMaxCommandSize, &elided_command); | |
38 | |
39 base::string16 message_text = l10n_util::GetStringFUTF16( | |
40 IDS_EXTERNAL_PROTOCOL_INFORMATION, | |
41 base::ASCIIToUTF16(url().scheme() + ":"), | |
42 elided_url_without_scheme) + base::ASCIIToUTF16("\n\n"); | |
43 | |
44 message_text += l10n_util::GetStringFUTF16( | |
45 IDS_EXTERNAL_PROTOCOL_APPLICATION_TO_LAUNCH, | |
46 elided_command) + base::ASCIIToUTF16("\n\n"); | |
47 | |
48 message_text += l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_WARNING); | |
49 return message_text; | |
50 } | 50 } |
51 | 51 |
52 base::string16 ExternalProtocolDialogDelegate::GetCheckboxText() const { | 52 base::string16 ExternalProtocolDialogDelegate::GetCheckboxText() const { |
53 return l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_CHECKBOX_TEXT); | 53 return l10n_util::GetStringFUTF16(IDS_EXTERNAL_PROTOCOL_CHECKBOX_TEXT, |
| 54 ElideCommandName(program_name_)); |
54 } | 55 } |
55 | 56 |
56 base::string16 ExternalProtocolDialogDelegate::GetTitleText() const { | 57 base::string16 ExternalProtocolDialogDelegate::GetTitleText() const { |
57 return l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_TITLE); | 58 return l10n_util::GetStringFUTF16(IDS_EXTERNAL_PROTOCOL_TITLE, |
| 59 ElideCommandName(program_name_)); |
58 } | 60 } |
59 | 61 |
60 void ExternalProtocolDialogDelegate::DoAccept( | 62 void ExternalProtocolDialogDelegate::DoAccept(const GURL& url, |
61 const GURL& url, | 63 bool dont_block) const { |
62 bool dont_block) const { | |
63 if (dont_block) { | 64 if (dont_block) { |
64 ExternalProtocolHandler::SetBlockState( | 65 ExternalProtocolHandler::SetBlockState(url.scheme(), |
65 url.scheme(), ExternalProtocolHandler::DONT_BLOCK); | 66 ExternalProtocolHandler::DONT_BLOCK); |
66 } | 67 } |
67 | 68 |
68 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck( | 69 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck( |
69 url, render_process_host_id_, tab_contents_id_); | 70 url, render_process_host_id_, tab_contents_id_); |
70 } | 71 } |
71 | 72 |
72 void ExternalProtocolDialogDelegate::DoCancel( | 73 void ExternalProtocolDialogDelegate::DoCancel(const GURL& url, |
73 const GURL& url, | 74 bool dont_block) const { |
74 bool dont_block) const { | |
75 if (dont_block) { | 75 if (dont_block) { |
76 ExternalProtocolHandler::SetBlockState( | 76 ExternalProtocolHandler::SetBlockState(url.scheme(), |
77 url.scheme(), ExternalProtocolHandler::BLOCK); | 77 ExternalProtocolHandler::BLOCK); |
78 } | 78 } |
79 } | 79 } |
OLD | NEW |