Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / external_protocol_dialog_delegate.cc
blob6ac91e01417d5a8b0fb258f27f50b6e8739c1db6
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 "chrome/grit/chromium_strings.h"
14 #include "chrome/grit/generated_resources.h"
15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/gfx/text_elider.h"
18 ExternalProtocolDialogDelegate::ExternalProtocolDialogDelegate(
19 const GURL& url,
20 int render_process_host_id,
21 int tab_contents_id)
22 : ProtocolDialogDelegate(url),
23 render_process_host_id_(render_process_host_id),
24 tab_contents_id_(tab_contents_id),
25 program_name_(ShellIntegration::GetApplicationNameForProtocol(url)) {
28 ExternalProtocolDialogDelegate::~ExternalProtocolDialogDelegate() {
31 base::string16 ExternalProtocolDialogDelegate::GetMessageText() const {
32 const int kMaxUrlWithoutSchemeSize = 256;
33 const int kMaxCommandSize = 256;
34 base::string16 elided_url_without_scheme;
35 base::string16 elided_command;
36 gfx::ElideString(base::ASCIIToUTF16(url().possibly_invalid_spec()),
37 kMaxUrlWithoutSchemeSize, &elided_url_without_scheme);
38 gfx::ElideString(program_name_, kMaxCommandSize, &elided_command);
40 base::string16 message_text = l10n_util::GetStringFUTF16(
41 IDS_EXTERNAL_PROTOCOL_INFORMATION,
42 base::ASCIIToUTF16(url().scheme() + ":"),
43 elided_url_without_scheme) + base::ASCIIToUTF16("\n\n");
45 message_text += l10n_util::GetStringFUTF16(
46 IDS_EXTERNAL_PROTOCOL_APPLICATION_TO_LAUNCH,
47 elided_command) + base::ASCIIToUTF16("\n\n");
49 message_text += l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_WARNING);
50 return message_text;
53 base::string16 ExternalProtocolDialogDelegate::GetCheckboxText() const {
54 return l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_CHECKBOX_TEXT);
57 base::string16 ExternalProtocolDialogDelegate::GetTitleText() const {
58 return l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_TITLE);
61 void ExternalProtocolDialogDelegate::DoAccept(
62 const GURL& url,
63 bool dont_block) const {
64 if (dont_block) {
65 ExternalProtocolHandler::SetBlockState(
66 url.scheme(), ExternalProtocolHandler::DONT_BLOCK);
69 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(
70 url, render_process_host_id_, tab_contents_id_);
73 void ExternalProtocolDialogDelegate::DoCancel(
74 const GURL& url,
75 bool dont_block) const {
76 if (dont_block) {
77 ExternalProtocolHandler::SetBlockState(
78 url.scheme(), ExternalProtocolHandler::BLOCK);