Fix infinite recursion on hiding panel when created during fullscreen mode.
[chromium-blink-merge.git] / chrome / browser / custom_handlers / register_protocol_handler_permission_request.cc
blob11c206ffccbcbeb5b815698e75b14bc9f8bb7881
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"
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(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM,
50 handler_.title(), base::UTF8ToUTF16(handler_.url().host()),
51 GetProtocolName(handler_)) :
52 l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE,
53 handler_.title(), base::UTF8ToUTF16(handler_.url().host()),
54 GetProtocolName(handler_), old_handler.title());
57 base::string16
58 RegisterProtocolHandlerPermissionRequest::GetMessageTextFragment() const {
59 ProtocolHandler old_handler = registry_->GetHandlerFor(handler_.protocol());
60 return old_handler.IsEmpty() ?
61 l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_FRAGMENT,
62 GetProtocolName(handler_)) :
63 l10n_util::GetStringFUTF16(
64 IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE_FRAGMENT,
65 GetProtocolName(handler_), old_handler.title());
68 bool RegisterProtocolHandlerPermissionRequest::HasUserGesture() const {
69 return user_gesture_;
72 GURL RegisterProtocolHandlerPermissionRequest::GetRequestingHostname() const {
73 return url_;
76 void RegisterProtocolHandlerPermissionRequest::PermissionGranted() {
77 content::RecordAction(
78 base::UserMetricsAction("RegisterProtocolHandler.Infobar_Accept"));
79 registry_->OnAcceptRegisterProtocolHandler(handler_);
82 void RegisterProtocolHandlerPermissionRequest::PermissionDenied() {
83 content::RecordAction(
84 base::UserMetricsAction("RegisterProtocolHandler.InfoBar_Deny"));
85 registry_->OnIgnoreRegisterProtocolHandler(handler_);
88 void RegisterProtocolHandlerPermissionRequest::Cancelled() {
89 content::RecordAction(
90 base::UserMetricsAction("RegisterProtocolHandler.InfoBar_Deny"));
91 registry_->OnIgnoreRegisterProtocolHandler(handler_);
94 void RegisterProtocolHandlerPermissionRequest::RequestFinished() {
95 delete this;