OLD | NEW |
(Empty) | |
| 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_re
quest.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 "ui/base/l10n/l10n_util.h" |
| 12 |
| 13 namespace { |
| 14 |
| 15 base::string16 GetProtocolName( |
| 16 const ProtocolHandler& handler) { |
| 17 if (handler.protocol() == "mailto") |
| 18 return l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_MAILTO_NAME); |
| 19 if (handler.protocol() == "webcal") |
| 20 return l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_WEBCAL_NAME); |
| 21 return base::UTF8ToUTF16(handler.protocol()); |
| 22 } |
| 23 |
| 24 } // namespace |
| 25 |
| 26 RegisterProtocolHandlerPermissionRequest |
| 27 ::RegisterProtocolHandlerPermissionRequest( |
| 28 ProtocolHandlerRegistry* registry, |
| 29 const ProtocolHandler& handler) |
| 30 : registry_(registry), |
| 31 handler_(handler) {} |
| 32 |
| 33 RegisterProtocolHandlerPermissionRequest:: |
| 34 ~RegisterProtocolHandlerPermissionRequest() {} |
| 35 |
| 36 base::string16 |
| 37 RegisterProtocolHandlerPermissionRequest::GetMessageText() const { |
| 38 ProtocolHandler old_handler = registry_->GetHandlerFor(handler_.protocol()); |
| 39 return old_handler.IsEmpty() ? |
| 40 l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM, |
| 41 handler_.title(), base::UTF8ToUTF16(handler_.url().host()), |
| 42 GetProtocolName(handler_)) : |
| 43 l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE, |
| 44 handler_.title(), base::UTF8ToUTF16(handler_.url().host()), |
| 45 GetProtocolName(handler_), old_handler.title()); |
| 46 } |
| 47 |
| 48 base::string16 |
| 49 RegisterProtocolHandlerPermissionRequest::GetMessageTextFragment() const { |
| 50 ProtocolHandler old_handler = registry_->GetHandlerFor(handler_.protocol()); |
| 51 return old_handler.IsEmpty() ? |
| 52 l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_FRAGMENT, |
| 53 GetProtocolName(handler_)) : |
| 54 l10n_util::GetStringFUTF16( |
| 55 IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE_FRAGMENT, |
| 56 GetProtocolName(handler_), old_handler.title()); |
| 57 } |
| 58 |
| 59 base::string16 RegisterProtocolHandlerPermissionRequest:: |
| 60 GetAlternateAcceptButtonText() const { |
| 61 return l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_ACCEPT, |
| 62 handler_.title()); |
| 63 } |
| 64 |
| 65 base::string16 RegisterProtocolHandlerPermissionRequest:: |
| 66 GetAlternateDenyButtonText() const { |
| 67 return l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_DENY, |
| 68 handler_.title()); |
| 69 } |
| 70 |
| 71 void RegisterProtocolHandlerPermissionRequest::PermissionGranted() { |
| 72 content::RecordAction( |
| 73 base::UserMetricsAction("RegisterProtocolHandler.Infobar_Accept")); |
| 74 registry_->OnAcceptRegisterProtocolHandler(handler_); |
| 75 } |
| 76 |
| 77 void RegisterProtocolHandlerPermissionRequest::PermissionDenied() { |
| 78 content::RecordAction( |
| 79 base::UserMetricsAction("RegisterProtocolHandler.InfoBar_Deny")); |
| 80 registry_->OnIgnoreRegisterProtocolHandler(handler_); |
| 81 } |
| 82 |
| 83 void RegisterProtocolHandlerPermissionRequest::Cancelled() { |
| 84 content::RecordAction( |
| 85 base::UserMetricsAction("RegisterProtocolHandler.InfoBar_Deny")); |
| 86 registry_->OnIgnoreRegisterProtocolHandler(handler_); |
| 87 } |
| 88 |
| 89 void RegisterProtocolHandlerPermissionRequest::RequestFinished() { |
| 90 delete this; |
| 91 } |
OLD | NEW |