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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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,
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,
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698