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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/external_protocol_dialog_delegate.h"
9 #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"
13 #include "grit/chromium_strings.h"
14 #include "grit/generated_resources.h"
15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/gfx/text_elider.h"
18 ExternalProtocolDialogDelegate::ExternalProtocolDialogDelegate(
20 int render_process_host_id
,
22 : ProtocolDialogDelegate(url
),
23 render_process_host_id_(render_process_host_id
),
24 tab_contents_id_(tab_contents_id
) {
27 ExternalProtocolDialogDelegate::~ExternalProtocolDialogDelegate() {
30 base::string16
ExternalProtocolDialogDelegate::GetMessageText() const {
31 const int kMaxUrlWithoutSchemeSize
= 256;
32 const int kMaxCommandSize
= 256;
33 // TODO(calamity): Look up the command in ExternalProtocolHandler and pass it
34 // into the constructor. Will require simultaneous change of
35 // ExternalProtocolHandler::RunExternalProtocolDialog across all platforms.
36 base::string16 command
=
37 base::UTF8ToUTF16(ShellIntegration::GetApplicationForProtocol(url()));
38 base::string16 elided_url_without_scheme
;
39 base::string16 elided_command
;
40 gfx::ElideString(base::ASCIIToUTF16(url().possibly_invalid_spec()),
41 kMaxUrlWithoutSchemeSize
, &elided_url_without_scheme
);
42 gfx::ElideString(command
, kMaxCommandSize
, &elided_command
);
44 base::string16 message_text
= l10n_util::GetStringFUTF16(
45 IDS_EXTERNAL_PROTOCOL_INFORMATION
,
46 base::ASCIIToUTF16(url().scheme() + ":"),
47 elided_url_without_scheme
) + base::ASCIIToUTF16("\n\n");
49 message_text
+= l10n_util::GetStringFUTF16(
50 IDS_EXTERNAL_PROTOCOL_APPLICATION_TO_LAUNCH
,
51 elided_command
) + base::ASCIIToUTF16("\n\n");
53 message_text
+= l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_WARNING
);
57 base::string16
ExternalProtocolDialogDelegate::GetCheckboxText() const {
58 return l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_CHECKBOX_TEXT
);
61 base::string16
ExternalProtocolDialogDelegate::GetTitleText() const {
62 return l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_TITLE
);
65 void ExternalProtocolDialogDelegate::DoAccept(
67 bool dont_block
) const {
69 ExternalProtocolHandler::SetBlockState(
70 url
.scheme(), ExternalProtocolHandler::DONT_BLOCK
);
73 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(
74 url
, render_process_host_id_
, tab_contents_id_
);
77 void ExternalProtocolDialogDelegate::DoCancel(
79 bool dont_block
) const {
81 ExternalProtocolHandler::SetBlockState(
82 url
.scheme(), ExternalProtocolHandler::BLOCK
);