Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3673)

Unified Diff: chrome/browser/custom_handlers/register_protocol_handler_permission_request.cc

Issue 152143003: [ProtocolHandlers] Add a permission bubble client for RPH requests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move infobar/bubble call to browser.cc Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/custom_handlers/register_protocol_handler_permission_request.cc
diff --git a/chrome/browser/custom_handlers/register_protocol_handler_permission_request.cc b/chrome/browser/custom_handlers/register_protocol_handler_permission_request.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1930539880582865c56af7700c88d81eee7bdcf4
--- /dev/null
+++ b/chrome/browser/custom_handlers/register_protocol_handler_permission_request.cc
@@ -0,0 +1,91 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#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 "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());
+}
+
+} // namespace
+
+RegisterProtocolHandlerPermissionRequest
+::RegisterProtocolHandlerPermissionRequest(
+ ProtocolHandlerRegistry* registry,
+ const ProtocolHandler& handler)
+ : registry_(registry),
+ handler_(handler) {}
+
+RegisterProtocolHandlerPermissionRequest::
+~RegisterProtocolHandlerPermissionRequest() {}
+
+base::string16
+RegisterProtocolHandlerPermissionRequest::GetMessageText() const {
+ ProtocolHandler old_handler = registry_->GetHandlerFor(handler_.protocol());
+ return old_handler.IsEmpty() ?
+ l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM,
Lei Zhang 2014/02/13 21:48:30 Since both the if and else case take the same para
Greg Billock 2014/02/13 22:49:03 mostly the same, yes. the old title is different,
+ 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());
+}
+
+base::string16 RegisterProtocolHandlerPermissionRequest::
+GetAlternateAcceptButtonText() const {
+ return l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_ACCEPT,
+ handler_.title());
+}
+
+base::string16 RegisterProtocolHandlerPermissionRequest::
+GetAlternateDenyButtonText() const {
+ return l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_DENY,
+ handler_.title());
+}
+
+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;
+}

Powered by Google App Engine
This is Rietveld 408576698