1 // Copyright 2014 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/custom_handlers/register_protocol_handler_permission_request.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
9 #include "content/public/browser/user_metrics.h"
10 #include "grit/generated_resources.h"
11 #include "grit/theme_resources.h"
12 #include "ui/base/l10n/l10n_util.h"
16 base::string16
GetProtocolName(
17 const ProtocolHandler
& handler
) {
18 if (handler
.protocol() == "mailto")
19 return l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_MAILTO_NAME
);
20 if (handler
.protocol() == "webcal")
21 return l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_WEBCAL_NAME
);
22 return base::UTF8ToUTF16(handler
.protocol());
27 RegisterProtocolHandlerPermissionRequest
28 ::RegisterProtocolHandlerPermissionRequest(
29 ProtocolHandlerRegistry
* registry
,
30 const ProtocolHandler
& handler
,
33 : registry_(registry
),
36 user_gesture_(user_gesture
) {}
38 RegisterProtocolHandlerPermissionRequest::
39 ~RegisterProtocolHandlerPermissionRequest() {}
41 int RegisterProtocolHandlerPermissionRequest::GetIconID() const {
42 return IDR_REGISTER_PROTOCOL_HANDLER
;
46 RegisterProtocolHandlerPermissionRequest::GetMessageText() const {
47 ProtocolHandler old_handler
= registry_
->GetHandlerFor(handler_
.protocol());
48 return old_handler
.IsEmpty() ?
49 l10n_util::GetStringFUTF16(
50 IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM
,
51 base::UTF8ToUTF16(handler_
.url().host()),
52 GetProtocolName(handler_
)) :
53 l10n_util::GetStringFUTF16(
54 IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE
,
55 base::UTF8ToUTF16(handler_
.url().host()),
56 GetProtocolName(handler_
),
57 base::UTF8ToUTF16(old_handler
.url().host()));
61 RegisterProtocolHandlerPermissionRequest::GetMessageTextFragment() const {
62 ProtocolHandler old_handler
= registry_
->GetHandlerFor(handler_
.protocol());
63 return old_handler
.IsEmpty() ?
64 l10n_util::GetStringFUTF16(
65 IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_FRAGMENT
,
66 GetProtocolName(handler_
)) :
67 l10n_util::GetStringFUTF16(
68 IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE_FRAGMENT
,
69 GetProtocolName(handler_
),
70 base::UTF8ToUTF16(old_handler
.url().host()));
73 bool RegisterProtocolHandlerPermissionRequest::HasUserGesture() const {
77 GURL
RegisterProtocolHandlerPermissionRequest::GetRequestingHostname() const {
81 void RegisterProtocolHandlerPermissionRequest::PermissionGranted() {
82 content::RecordAction(
83 base::UserMetricsAction("RegisterProtocolHandler.Infobar_Accept"));
84 registry_
->OnAcceptRegisterProtocolHandler(handler_
);
87 void RegisterProtocolHandlerPermissionRequest::PermissionDenied() {
88 content::RecordAction(
89 base::UserMetricsAction("RegisterProtocolHandler.InfoBar_Deny"));
90 registry_
->OnIgnoreRegisterProtocolHandler(handler_
);
93 void RegisterProtocolHandlerPermissionRequest::Cancelled() {
94 content::RecordAction(
95 base::UserMetricsAction("RegisterProtocolHandler.InfoBar_Deny"));
96 registry_
->OnIgnoreRegisterProtocolHandler(handler_
);
99 void RegisterProtocolHandlerPermissionRequest::RequestFinished() {