This source file includes following definitions.
- GetProtocolName
- user_gesture_
- RegisterProtocolHandlerPermissionRequest
- GetIconID
- GetMessageText
- GetMessageTextFragment
- HasUserGesture
- GetRequestingHostname
- PermissionGranted
- PermissionDenied
- Cancelled
- RequestFinished
#include "chrome/browser/custom_handlers/register_protocol_handler_permission_request.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
#include "content/public/browser/user_metrics.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util.h"
namespace {
base::string16 GetProtocolName(
const ProtocolHandler& handler) {
if (handler.protocol() == "mailto")
return l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_MAILTO_NAME);
if (handler.protocol() == "webcal")
return l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_WEBCAL_NAME);
return base::UTF8ToUTF16(handler.protocol());
}
}
RegisterProtocolHandlerPermissionRequest
::RegisterProtocolHandlerPermissionRequest(
ProtocolHandlerRegistry* registry,
const ProtocolHandler& handler,
GURL url,
bool user_gesture)
: registry_(registry),
handler_(handler),
url_(url),
user_gesture_(user_gesture) {}
RegisterProtocolHandlerPermissionRequest::
~RegisterProtocolHandlerPermissionRequest() {}
int RegisterProtocolHandlerPermissionRequest::GetIconID() const {
return IDR_REGISTER_PROTOCOL_HANDLER;
}
base::string16
RegisterProtocolHandlerPermissionRequest::GetMessageText() const {
ProtocolHandler old_handler = registry_->GetHandlerFor(handler_.protocol());
return old_handler.IsEmpty() ?
l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM,
handler_.title(), base::UTF8ToUTF16(handler_.url().host()),
GetProtocolName(handler_)) :
l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE,
handler_.title(), base::UTF8ToUTF16(handler_.url().host()),
GetProtocolName(handler_), old_handler.title());
}
base::string16
RegisterProtocolHandlerPermissionRequest::GetMessageTextFragment() const {
ProtocolHandler old_handler = registry_->GetHandlerFor(handler_.protocol());
return old_handler.IsEmpty() ?
l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_FRAGMENT,
GetProtocolName(handler_)) :
l10n_util::GetStringFUTF16(
IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE_FRAGMENT,
GetProtocolName(handler_), old_handler.title());
}
bool RegisterProtocolHandlerPermissionRequest::HasUserGesture() const {
return user_gesture_;
}
GURL RegisterProtocolHandlerPermissionRequest::GetRequestingHostname() const {
return url_;
}
void RegisterProtocolHandlerPermissionRequest::PermissionGranted() {
content::RecordAction(
base::UserMetricsAction("RegisterProtocolHandler.Infobar_Accept"));
registry_->OnAcceptRegisterProtocolHandler(handler_);
}
void RegisterProtocolHandlerPermissionRequest::PermissionDenied() {
content::RecordAction(
base::UserMetricsAction("RegisterProtocolHandler.InfoBar_Deny"));
registry_->OnIgnoreRegisterProtocolHandler(handler_);
}
void RegisterProtocolHandlerPermissionRequest::Cancelled() {
content::RecordAction(
base::UserMetricsAction("RegisterProtocolHandler.InfoBar_Deny"));
registry_->OnIgnoreRegisterProtocolHandler(handler_);
}
void RegisterProtocolHandlerPermissionRequest::RequestFinished() {
delete this;
}