- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / external_protocol_dialog_delegate.cc
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.
4
5 #include "chrome/browser/ui/external_protocol_dialog_delegate.h"
6
7 #include <string>
8
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"
17
18 ExternalProtocolDialogDelegate::ExternalProtocolDialogDelegate(const GURL& url)
19     : ProtocolDialogDelegate(url) {
20 }
21
22 ExternalProtocolDialogDelegate::~ExternalProtocolDialogDelegate() {
23 }
24
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   gfx::ElideString(ASCIIToUTF16(url().possibly_invalid_spec()),
36                   kMaxUrlWithoutSchemeSize, &elided_url_without_scheme);
37   gfx::ElideString(command, kMaxCommandSize, &elided_command);
38
39   string16 message_text = l10n_util::GetStringFUTF16(
40       IDS_EXTERNAL_PROTOCOL_INFORMATION,
41       ASCIIToUTF16(url().scheme() + ":"),
42       elided_url_without_scheme) + ASCIIToUTF16("\n\n");
43
44   message_text += l10n_util::GetStringFUTF16(
45       IDS_EXTERNAL_PROTOCOL_APPLICATION_TO_LAUNCH,
46       elided_command) + ASCIIToUTF16("\n\n");
47
48   message_text += l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_WARNING);
49   return message_text;
50 }
51
52 string16 ExternalProtocolDialogDelegate::GetCheckboxText() const {
53   return l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_CHECKBOX_TEXT);
54 }
55
56 string16 ExternalProtocolDialogDelegate::GetTitleText() const {
57   return l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_TITLE);
58 }
59
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);
66   }
67
68   ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url);
69 }
70
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);
77   }
78 }