| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/custom_handlers/register_protocol_handler_permission_re
quest.h" | 5 #include "chrome/browser/custom_handlers/register_protocol_handler_permission_re
quest.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 8 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 9 #include "content/public/browser/user_metrics.h" | 9 #include "content/public/browser/user_metrics.h" |
| 10 #include "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
| 11 #include "grit/theme_resources.h" |
| 11 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 base::string16 GetProtocolName( | 16 base::string16 GetProtocolName( |
| 16 const ProtocolHandler& handler) { | 17 const ProtocolHandler& handler) { |
| 17 if (handler.protocol() == "mailto") | 18 if (handler.protocol() == "mailto") |
| 18 return l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_MAILTO_NAME); | 19 return l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_MAILTO_NAME); |
| 19 if (handler.protocol() == "webcal") | 20 if (handler.protocol() == "webcal") |
| 20 return l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_WEBCAL_NAME); | 21 return l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_WEBCAL_NAME); |
| 21 return base::UTF8ToUTF16(handler.protocol()); | 22 return base::UTF8ToUTF16(handler.protocol()); |
| 22 } | 23 } |
| 23 | 24 |
| 24 } // namespace | 25 } // namespace |
| 25 | 26 |
| 26 RegisterProtocolHandlerPermissionRequest | 27 RegisterProtocolHandlerPermissionRequest |
| 27 ::RegisterProtocolHandlerPermissionRequest( | 28 ::RegisterProtocolHandlerPermissionRequest( |
| 28 ProtocolHandlerRegistry* registry, | 29 ProtocolHandlerRegistry* registry, |
| 29 const ProtocolHandler& handler) | 30 const ProtocolHandler& handler, |
| 31 GURL url, |
| 32 bool user_gesture) |
| 30 : registry_(registry), | 33 : registry_(registry), |
| 31 handler_(handler) {} | 34 handler_(handler), |
| 35 url_(url), |
| 36 user_gesture_(user_gesture) {} |
| 32 | 37 |
| 33 RegisterProtocolHandlerPermissionRequest:: | 38 RegisterProtocolHandlerPermissionRequest:: |
| 34 ~RegisterProtocolHandlerPermissionRequest() {} | 39 ~RegisterProtocolHandlerPermissionRequest() {} |
| 35 | 40 |
| 41 int RegisterProtocolHandlerPermissionRequest::GetIconID() const { |
| 42 return IDR_REGISTER_PROTOCOL_HANDLER; |
| 43 } |
| 44 |
| 36 base::string16 | 45 base::string16 |
| 37 RegisterProtocolHandlerPermissionRequest::GetMessageText() const { | 46 RegisterProtocolHandlerPermissionRequest::GetMessageText() const { |
| 38 ProtocolHandler old_handler = registry_->GetHandlerFor(handler_.protocol()); | 47 ProtocolHandler old_handler = registry_->GetHandlerFor(handler_.protocol()); |
| 39 return old_handler.IsEmpty() ? | 48 return old_handler.IsEmpty() ? |
| 40 l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM, | 49 l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM, |
| 41 handler_.title(), base::UTF8ToUTF16(handler_.url().host()), | 50 handler_.title(), base::UTF8ToUTF16(handler_.url().host()), |
| 42 GetProtocolName(handler_)) : | 51 GetProtocolName(handler_)) : |
| 43 l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE, | 52 l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE, |
| 44 handler_.title(), base::UTF8ToUTF16(handler_.url().host()), | 53 handler_.title(), base::UTF8ToUTF16(handler_.url().host()), |
| 45 GetProtocolName(handler_), old_handler.title()); | 54 GetProtocolName(handler_), old_handler.title()); |
| 46 } | 55 } |
| 47 | 56 |
| 48 base::string16 | 57 base::string16 |
| 49 RegisterProtocolHandlerPermissionRequest::GetMessageTextFragment() const { | 58 RegisterProtocolHandlerPermissionRequest::GetMessageTextFragment() const { |
| 50 ProtocolHandler old_handler = registry_->GetHandlerFor(handler_.protocol()); | 59 ProtocolHandler old_handler = registry_->GetHandlerFor(handler_.protocol()); |
| 51 return old_handler.IsEmpty() ? | 60 return old_handler.IsEmpty() ? |
| 52 l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_FRAGMENT, | 61 l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_FRAGMENT, |
| 53 GetProtocolName(handler_)) : | 62 GetProtocolName(handler_)) : |
| 54 l10n_util::GetStringFUTF16( | 63 l10n_util::GetStringFUTF16( |
| 55 IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE_FRAGMENT, | 64 IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE_FRAGMENT, |
| 56 GetProtocolName(handler_), old_handler.title()); | 65 GetProtocolName(handler_), old_handler.title()); |
| 57 } | 66 } |
| 58 | 67 |
| 59 base::string16 RegisterProtocolHandlerPermissionRequest:: | 68 bool RegisterProtocolHandlerPermissionRequest::HasUserGesture() const { |
| 60 GetAlternateAcceptButtonText() const { | 69 return user_gesture_; |
| 61 return l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_ACCEPT, | |
| 62 handler_.title()); | |
| 63 } | 70 } |
| 64 | 71 |
| 65 base::string16 RegisterProtocolHandlerPermissionRequest:: | 72 GURL RegisterProtocolHandlerPermissionRequest::GetRequestingHostname() const { |
| 66 GetAlternateDenyButtonText() const { | 73 return url_; |
| 67 return l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_DENY, | |
| 68 handler_.title()); | |
| 69 } | 74 } |
| 70 | 75 |
| 71 void RegisterProtocolHandlerPermissionRequest::PermissionGranted() { | 76 void RegisterProtocolHandlerPermissionRequest::PermissionGranted() { |
| 72 content::RecordAction( | 77 content::RecordAction( |
| 73 base::UserMetricsAction("RegisterProtocolHandler.Infobar_Accept")); | 78 base::UserMetricsAction("RegisterProtocolHandler.Infobar_Accept")); |
| 74 registry_->OnAcceptRegisterProtocolHandler(handler_); | 79 registry_->OnAcceptRegisterProtocolHandler(handler_); |
| 75 } | 80 } |
| 76 | 81 |
| 77 void RegisterProtocolHandlerPermissionRequest::PermissionDenied() { | 82 void RegisterProtocolHandlerPermissionRequest::PermissionDenied() { |
| 78 content::RecordAction( | 83 content::RecordAction( |
| 79 base::UserMetricsAction("RegisterProtocolHandler.InfoBar_Deny")); | 84 base::UserMetricsAction("RegisterProtocolHandler.InfoBar_Deny")); |
| 80 registry_->OnIgnoreRegisterProtocolHandler(handler_); | 85 registry_->OnIgnoreRegisterProtocolHandler(handler_); |
| 81 } | 86 } |
| 82 | 87 |
| 83 void RegisterProtocolHandlerPermissionRequest::Cancelled() { | 88 void RegisterProtocolHandlerPermissionRequest::Cancelled() { |
| 84 content::RecordAction( | 89 content::RecordAction( |
| 85 base::UserMetricsAction("RegisterProtocolHandler.InfoBar_Deny")); | 90 base::UserMetricsAction("RegisterProtocolHandler.InfoBar_Deny")); |
| 86 registry_->OnIgnoreRegisterProtocolHandler(handler_); | 91 registry_->OnIgnoreRegisterProtocolHandler(handler_); |
| 87 } | 92 } |
| 88 | 93 |
| 89 void RegisterProtocolHandlerPermissionRequest::RequestFinished() { | 94 void RegisterProtocolHandlerPermissionRequest::RequestFinished() { |
| 90 delete this; | 95 delete this; |
| 91 } | 96 } |
| OLD | NEW |