summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/external_protocol_dialog_delegate.cc
blob: b71327758c11b54b79645cdee5aec3ec8c5edbb8 (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
79
80
81
82
83
84
// 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,
    int render_process_host_id,
    int tab_contents_id)
    : ProtocolDialogDelegate(url),
      render_process_host_id_(render_process_host_id),
      tab_contents_id_(tab_contents_id) {
}

ExternalProtocolDialogDelegate::~ExternalProtocolDialogDelegate() {
}

base::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.
  base::string16 command =
    base::UTF8ToUTF16(ShellIntegration::GetApplicationForProtocol(url()));
  base::string16 elided_url_without_scheme;
  base::string16 elided_command;
  gfx::ElideString(base::ASCIIToUTF16(url().possibly_invalid_spec()),
                  kMaxUrlWithoutSchemeSize, &elided_url_without_scheme);
  gfx::ElideString(command, kMaxCommandSize, &elided_command);

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

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

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

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

base::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, render_process_host_id_, tab_contents_id_);
}

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