register_protocol_handler_permission_request.cc revision cedac228d2dd51db4b79ea1e72c7f249408ee061
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. 4 5#include "chrome/browser/custom_handlers/register_protocol_handler_permission_request.h" 6 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" 13 14namespace { 15 16base::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()); 23} 24 25} // namespace 26 27RegisterProtocolHandlerPermissionRequest 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) {} 37 38RegisterProtocolHandlerPermissionRequest:: 39~RegisterProtocolHandlerPermissionRequest() {} 40 41int RegisterProtocolHandlerPermissionRequest::GetIconID() const { 42 return IDR_REGISTER_PROTOCOL_HANDLER; 43} 44 45base::string16 46RegisterProtocolHandlerPermissionRequest::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())); 58} 59 60base::string16 61RegisterProtocolHandlerPermissionRequest::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())); 71} 72 73bool RegisterProtocolHandlerPermissionRequest::HasUserGesture() const { 74 return user_gesture_; 75} 76 77GURL RegisterProtocolHandlerPermissionRequest::GetRequestingHostname() const { 78 return url_; 79} 80 81void RegisterProtocolHandlerPermissionRequest::PermissionGranted() { 82 content::RecordAction( 83 base::UserMetricsAction("RegisterProtocolHandler.Infobar_Accept")); 84 registry_->OnAcceptRegisterProtocolHandler(handler_); 85} 86 87void RegisterProtocolHandlerPermissionRequest::PermissionDenied() { 88 content::RecordAction( 89 base::UserMetricsAction("RegisterProtocolHandler.InfoBar_Deny")); 90 registry_->OnIgnoreRegisterProtocolHandler(handler_); 91} 92 93void RegisterProtocolHandlerPermissionRequest::Cancelled() { 94 content::RecordAction( 95 base::UserMetricsAction("RegisterProtocolHandler.InfoBar_Deny")); 96 registry_->OnIgnoreRegisterProtocolHandler(handler_); 97} 98 99void RegisterProtocolHandlerPermissionRequest::RequestFinished() { 100 delete this; 101} 102