| 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 bool user_gesture) |
| 30 : registry_(registry), | 32 : registry_(registry), |
| 31 handler_(handler) {} | 33 handler_(handler), |
| 34 user_gesture_(user_gesture) {} |
| 32 | 35 |
| 33 RegisterProtocolHandlerPermissionRequest:: | 36 RegisterProtocolHandlerPermissionRequest:: |
| 34 ~RegisterProtocolHandlerPermissionRequest() {} | 37 ~RegisterProtocolHandlerPermissionRequest() {} |
| 35 | 38 |
| 39 int RegisterProtocolHandlerPermissionRequest::GetIconID() const { |
| 40 return IDR_REGISTER_PROTOCOL_HANDLER; |
| 41 } |
| 42 |
| 36 base::string16 | 43 base::string16 |
| 37 RegisterProtocolHandlerPermissionRequest::GetMessageText() const { | 44 RegisterProtocolHandlerPermissionRequest::GetMessageText() const { |
| 38 ProtocolHandler old_handler = registry_->GetHandlerFor(handler_.protocol()); | 45 ProtocolHandler old_handler = registry_->GetHandlerFor(handler_.protocol()); |
| 39 return old_handler.IsEmpty() ? | 46 return old_handler.IsEmpty() ? |
| 40 l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM, | 47 l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM, |
| 41 handler_.title(), base::UTF8ToUTF16(handler_.url().host()), | 48 handler_.title(), base::UTF8ToUTF16(handler_.url().host()), |
| 42 GetProtocolName(handler_)) : | 49 GetProtocolName(handler_)) : |
| 43 l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE, | 50 l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE, |
| 44 handler_.title(), base::UTF8ToUTF16(handler_.url().host()), | 51 handler_.title(), base::UTF8ToUTF16(handler_.url().host()), |
| 45 GetProtocolName(handler_), old_handler.title()); | 52 GetProtocolName(handler_), old_handler.title()); |
| 46 } | 53 } |
| 47 | 54 |
| 48 base::string16 | 55 base::string16 |
| 49 RegisterProtocolHandlerPermissionRequest::GetMessageTextFragment() const { | 56 RegisterProtocolHandlerPermissionRequest::GetMessageTextFragment() const { |
| 50 ProtocolHandler old_handler = registry_->GetHandlerFor(handler_.protocol()); | 57 ProtocolHandler old_handler = registry_->GetHandlerFor(handler_.protocol()); |
| 51 return old_handler.IsEmpty() ? | 58 return old_handler.IsEmpty() ? |
| 52 l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_FRAGMENT, | 59 l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_FRAGMENT, |
| 53 GetProtocolName(handler_)) : | 60 GetProtocolName(handler_)) : |
| 54 l10n_util::GetStringFUTF16( | 61 l10n_util::GetStringFUTF16( |
| 55 IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE_FRAGMENT, | 62 IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE_FRAGMENT, |
| 56 GetProtocolName(handler_), old_handler.title()); | 63 GetProtocolName(handler_), old_handler.title()); |
| 57 } | 64 } |
| 58 | 65 |
| 59 base::string16 RegisterProtocolHandlerPermissionRequest:: | 66 bool RegisterProtocolHandlerPermissionRequest::HasUserGesture() const { |
| 60 GetAlternateAcceptButtonText() const { | 67 return user_gesture_; |
| 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 } | 68 } |
| 70 | 69 |
| 71 void RegisterProtocolHandlerPermissionRequest::PermissionGranted() { | 70 void RegisterProtocolHandlerPermissionRequest::PermissionGranted() { |
| 72 content::RecordAction( | 71 content::RecordAction( |
| 73 base::UserMetricsAction("RegisterProtocolHandler.Infobar_Accept")); | 72 base::UserMetricsAction("RegisterProtocolHandler.Infobar_Accept")); |
| 74 registry_->OnAcceptRegisterProtocolHandler(handler_); | 73 registry_->OnAcceptRegisterProtocolHandler(handler_); |
| 75 } | 74 } |
| 76 | 75 |
| 77 void RegisterProtocolHandlerPermissionRequest::PermissionDenied() { | 76 void RegisterProtocolHandlerPermissionRequest::PermissionDenied() { |
| 78 content::RecordAction( | 77 content::RecordAction( |
| 79 base::UserMetricsAction("RegisterProtocolHandler.InfoBar_Deny")); | 78 base::UserMetricsAction("RegisterProtocolHandler.InfoBar_Deny")); |
| 80 registry_->OnIgnoreRegisterProtocolHandler(handler_); | 79 registry_->OnIgnoreRegisterProtocolHandler(handler_); |
| 81 } | 80 } |
| 82 | 81 |
| 83 void RegisterProtocolHandlerPermissionRequest::Cancelled() { | 82 void RegisterProtocolHandlerPermissionRequest::Cancelled() { |
| 84 content::RecordAction( | 83 content::RecordAction( |
| 85 base::UserMetricsAction("RegisterProtocolHandler.InfoBar_Deny")); | 84 base::UserMetricsAction("RegisterProtocolHandler.InfoBar_Deny")); |
| 86 registry_->OnIgnoreRegisterProtocolHandler(handler_); | 85 registry_->OnIgnoreRegisterProtocolHandler(handler_); |
| 87 } | 86 } |
| 88 | 87 |
| 89 void RegisterProtocolHandlerPermissionRequest::RequestFinished() { | 88 void RegisterProtocolHandlerPermissionRequest::RequestFinished() { |
| 90 delete this; | 89 delete this; |
| 91 } | 90 } |
| OLD | NEW |