Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / custom_handlers / register_protocol_handler_permission_request.cc
blob6b06d6c1adc2e5f2145482961ae9319d619c3f76
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 "chrome/grit/generated_resources.h"
10 #include "content/public/browser/user_metrics.h"
11 #include "grit/theme_resources.h"
12 #include "ui/base/l10n/l10n_util.h"
14 namespace {
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());
25 } // namespace
27 RegisterProtocolHandlerPermissionRequest
28 ::RegisterProtocolHandlerPermissionRequest(
29 ProtocolHandlerRegistry* registry,
30 const ProtocolHandler& handler,
31 GURL url,
32 bool user_gesture)
33 : registry_(registry),
34 handler_(handler),
35 url_(url),
36 user_gesture_(user_gesture) {}
38 RegisterProtocolHandlerPermissionRequest::
39 ~RegisterProtocolHandlerPermissionRequest() {}
41 int RegisterProtocolHandlerPermissionRequest::GetIconID() const {
42 return IDR_REGISTER_PROTOCOL_HANDLER;
45 base::string16
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()));
60 base::string16
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 {
74 return user_gesture_;
77 GURL RegisterProtocolHandlerPermissionRequest::GetRequestingHostname() const {
78 return url_;
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() {
100 delete this;