summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/external_protocol_dialog_delegate.cc
blob: e0129c2815e9c1adac21b11af3e4d87dc0448f48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/external_protocol_dialog_delegate.h"

#include <string>

#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread.h"
#include "base/threading/thread_restrictions.h"
#include "chrome/browser/external_protocol/external_protocol_handler.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/text_elider.h"

ExternalProtocolDialogDelegate::ExternalProtocolDialogDelegate(const GURL& url)
    : ProtocolDialogDelegate(url) {
}

ExternalProtocolDialogDelegate::~ExternalProtocolDialogDelegate() {
}

string16 ExternalProtocolDialogDelegate::GetMessageText() const {
  const int kMaxUrlWithoutSchemeSize = 256;
  const int kMaxCommandSize = 256;
  // TODO(calamity): Look up the command in ExternalProtocolHandler and pass it
  // into the constructor. Will require simultaneous change of
  // ExternalProtocolHandler::RunExternalProtocolDialog across all platforms.
  string16 command =
    UTF8ToUTF16(ShellIntegration::GetApplicationForProtocol(url()));
  string16 elided_url_without_scheme;
  string16 elided_command;
  gfx::ElideString(ASCIIToUTF16(url().possibly_invalid_spec()),
                  kMaxUrlWithoutSchemeSize, &elided_url_without_scheme);
  gfx::ElideString(command, kMaxCommandSize, &elided_command);

  string16 message_text = l10n_util::GetStringFUTF16(
      IDS_EXTERNAL_PROTOCOL_INFORMATION,
      ASCIIToUTF16(url().scheme() + ":"),
      elided_url_without_scheme) + ASCIIToUTF16("\n\n");

  message_text += l10n_util::GetStringFUTF16(
      IDS_EXTERNAL_PROTOCOL_APPLICATION_TO_LAUNCH,
      elided_command) + ASCIIToUTF16("\n\n");

  message_text += l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_WARNING);
  return message_text;
}

string16 ExternalProtocolDialogDelegate::GetCheckboxText() const {
  return l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_CHECKBOX_TEXT);
}

string16 ExternalProtocolDialogDelegate::GetTitleText() const {
  return l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_TITLE);
}

void ExternalProtocolDialogDelegate::DoAccept(
    const GURL& url,
    bool dont_block) const {
  if (dont_block) {
      ExternalProtocolHandler::SetBlockState(
          url.scheme(), ExternalProtocolHandler::DONT_BLOCK);
  }

  ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url);
}

void ExternalProtocolDialogDelegate::DoCancel(
    const GURL& url,
    bool dont_block) const {
  if (dont_block) {
      ExternalProtocolHandler::SetBlockState(
          url.scheme(), ExternalProtocolHandler::BLOCK);
  }
}