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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
// Copyright (c) 2012 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/custom_handlers/register_protocol_handler_infobar_delegate.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
using content::OpenURLParams;
using content::Referrer;
using content::UserMetricsAction;
// static
void RegisterProtocolHandlerInfoBarDelegate::Create(
InfoBarService* infobar_service,
ProtocolHandlerRegistry* registry,
const ProtocolHandler& handler) {
content::RecordAction(
content::UserMetricsAction("RegisterProtocolHandler.InfoBar_Shown"));
scoped_ptr<InfoBarDelegate> infobar(
new RegisterProtocolHandlerInfoBarDelegate(infobar_service, registry,
handler));
for (size_t i = 0; i < infobar_service->infobar_count(); ++i) {
RegisterProtocolHandlerInfoBarDelegate* existing_delegate =
infobar_service->infobar_at(i)->
AsRegisterProtocolHandlerInfoBarDelegate();
if ((existing_delegate != NULL) &&
existing_delegate->handler_.IsEquivalent(handler)) {
infobar_service->ReplaceInfoBar(existing_delegate, infobar.Pass());
return;
}
}
infobar_service->AddInfoBar(infobar.Pass());
}
InfoBarDelegate::InfoBarAutomationType
RegisterProtocolHandlerInfoBarDelegate::GetInfoBarAutomationType() const {
return RPH_INFOBAR;
}
InfoBarDelegate::Type
RegisterProtocolHandlerInfoBarDelegate::GetInfoBarType() const {
return PAGE_ACTION_TYPE;
}
string16 RegisterProtocolHandlerInfoBarDelegate::GetMessageText() const {
ProtocolHandler old_handler = registry_->GetHandlerFor(handler_.protocol());
return !old_handler.IsEmpty() ?
l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE,
handler_.title(), UTF8ToUTF16(handler_.url().host()),
GetProtocolName(handler_), old_handler.title()) :
l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM,
handler_.title(), UTF8ToUTF16(handler_.url().host()),
GetProtocolName(handler_));
}
RegisterProtocolHandlerInfoBarDelegate::RegisterProtocolHandlerInfoBarDelegate(
InfoBarService* infobar_service,
ProtocolHandlerRegistry* registry,
const ProtocolHandler& handler)
: ConfirmInfoBarDelegate(infobar_service),
registry_(registry),
handler_(handler) {
}
string16 RegisterProtocolHandlerInfoBarDelegate::GetProtocolName(
const ProtocolHandler& handler) const {
if (handler.protocol() == "mailto")
return l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_MAILTO_NAME);
if (handler.protocol() == "webcal")
return l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_WEBCAL_NAME);
return UTF8ToUTF16(handler.protocol());
}
string16 RegisterProtocolHandlerInfoBarDelegate::GetButtonLabel(
InfoBarButton button) const {
return (button == BUTTON_OK) ?
l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_ACCEPT,
handler_.title()) :
l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_DENY);
}
bool RegisterProtocolHandlerInfoBarDelegate::NeedElevation(
InfoBarButton button) const {
return button == BUTTON_OK;
}
bool RegisterProtocolHandlerInfoBarDelegate::Accept() {
content::RecordAction(
UserMetricsAction("RegisterProtocolHandler.Infobar_Accept"));
registry_->OnAcceptRegisterProtocolHandler(handler_);
return true;
}
bool RegisterProtocolHandlerInfoBarDelegate::Cancel() {
content::RecordAction(
UserMetricsAction("RegisterProtocolHandler.InfoBar_Deny"));
registry_->OnIgnoreRegisterProtocolHandler(handler_);
return true;
}
string16 RegisterProtocolHandlerInfoBarDelegate::GetLinkText() const {
return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
}
bool RegisterProtocolHandlerInfoBarDelegate::LinkClicked(
WindowOpenDisposition disposition) {
content::RecordAction(
UserMetricsAction("RegisterProtocolHandler.InfoBar_LearnMore"));
OpenURLParams params(
GURL(chrome::kLearnMoreRegisterProtocolHandlerURL),
Referrer(),
(disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
content::PAGE_TRANSITION_LINK,
false);
web_contents()->OpenURL(params);
return false;
}
RegisterProtocolHandlerInfoBarDelegate*
RegisterProtocolHandlerInfoBarDelegate::
AsRegisterProtocolHandlerInfoBarDelegate() {
return this;
}
|