Add a minor text member to ui::MenuModel.
[chromium-blink-merge.git] / chrome / browser / ui / external_protocol_dialog_delegate.cc
blobaa368081c1f83e23fcbc2f304406cfe261eb66a0
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"
7 #include <string>
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/base/text/text_elider.h"
18 ExternalProtocolDialogDelegate::ExternalProtocolDialogDelegate(const GURL& url)
19 : ProtocolDialogDelegate(url) {
22 ExternalProtocolDialogDelegate::~ExternalProtocolDialogDelegate() {
25 string16 ExternalProtocolDialogDelegate::GetMessageText() const {
26 const int kMaxUrlWithoutSchemeSize = 256;
27 const int kMaxCommandSize = 256;
28 // TODO(calamity): Look up the command in ExternalProtocolHandler and pass it
29 // into the constructor. Will require simultaneous change of
30 // ExternalProtocolHandler::RunExternalProtocolDialog across all platforms.
31 string16 command =
32 UTF8ToUTF16(ShellIntegration::GetApplicationForProtocol(url()));
33 string16 elided_url_without_scheme;
34 string16 elided_command;
35 ui::ElideString(ASCIIToUTF16(url().possibly_invalid_spec()),
36 kMaxUrlWithoutSchemeSize, &elided_url_without_scheme);
37 ui::ElideString(command, kMaxCommandSize, &elided_command);
39 string16 message_text = l10n_util::GetStringFUTF16(
40 IDS_EXTERNAL_PROTOCOL_INFORMATION,
41 ASCIIToUTF16(url().scheme() + ":"),
42 elided_url_without_scheme) + ASCIIToUTF16("\n\n");
44 message_text += l10n_util::GetStringFUTF16(
45 IDS_EXTERNAL_PROTOCOL_APPLICATION_TO_LAUNCH,
46 elided_command) + ASCIIToUTF16("\n\n");
48 message_text += l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_WARNING);
49 return message_text;
52 string16 ExternalProtocolDialogDelegate::GetCheckboxText() const {
53 return l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_CHECKBOX_TEXT);
56 string16 ExternalProtocolDialogDelegate::GetTitleText() const {
57 return l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_TITLE);
60 void ExternalProtocolDialogDelegate::DoAccept(
61 const GURL& url,
62 bool dont_block) const {
63 if (dont_block) {
64 ExternalProtocolHandler::SetBlockState(
65 url.scheme(), ExternalProtocolHandler::DONT_BLOCK);
68 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url);
71 void ExternalProtocolDialogDelegate::DoCancel(
72 const GURL& url,
73 bool dont_block) const {
74 if (dont_block) {
75 ExternalProtocolHandler::SetBlockState(
76 url.scheme(), ExternalProtocolHandler::BLOCK);