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

Side by Side Diff: chrome/browser/permissions/permission_bubble_request_impl.cc

Issue 2123653006: Rename PermissionBubbleRequest to PermissionRequest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permission_manager_rename
Patch Set: PermissionBubbleType -> PermissionRequestType Created 4 years, 5 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
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/permissions/permission_bubble_request_impl.h"
6
7 #include "build/build_config.h"
8 #include "chrome/browser/permissions/permission_context_base.h"
9 #include "chrome/browser/permissions/permission_uma_util.h"
10 #include "chrome/grit/generated_resources.h"
11 #include "components/url_formatter/elide_url.h"
12 #include "grit/theme_resources.h"
13 #include "net/base/escape.h"
14 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/gfx/vector_icons_public.h"
16
17 PermissionBubbleRequestImpl::PermissionBubbleRequestImpl(
18 const GURL& request_origin,
19 content::PermissionType permission_type,
20 const PermissionDecidedCallback& permission_decided_callback,
21 const base::Closure delete_callback)
22 : request_origin_(request_origin),
23 permission_type_(permission_type),
24 permission_decided_callback_(permission_decided_callback),
25 delete_callback_(delete_callback),
26 is_finished_(false),
27 action_taken_(false) {}
28
29 PermissionBubbleRequestImpl::~PermissionBubbleRequestImpl() {
30 DCHECK(is_finished_);
31 if (!action_taken_)
32 PermissionUmaUtil::PermissionIgnored(permission_type_, request_origin_);
33 }
34
35 gfx::VectorIconId PermissionBubbleRequestImpl::GetVectorIconId() const {
36 #if !defined(OS_MACOSX)
37 switch (permission_type_) {
38 case content::PermissionType::GEOLOCATION:
39 return gfx::VectorIconId::LOCATION_ON;
40 #if defined(ENABLE_NOTIFICATIONS)
41 case content::PermissionType::NOTIFICATIONS:
42 return gfx::VectorIconId::NOTIFICATIONS;
43 #endif
44 #if defined(OS_CHROMEOS)
45 // TODO(xhwang): fix this icon, see crrev.com/863263007
46 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER:
47 return gfx::VectorIconId::CHROME_PRODUCT;
48 #endif
49 case content::PermissionType::MIDI_SYSEX:
50 return gfx::VectorIconId::MIDI;
51 default:
52 NOTREACHED();
53 return gfx::VectorIconId::VECTOR_ICON_NONE;
54 }
55 #else // !defined(OS_MACOSX)
56 return gfx::VectorIconId::VECTOR_ICON_NONE;
57 #endif
58 }
59
60 int PermissionBubbleRequestImpl::GetIconId() const {
61 int icon_id = IDR_INFOBAR_WARNING;
62 #if defined(OS_MACOSX)
63 switch (permission_type_) {
64 case content::PermissionType::GEOLOCATION:
65 icon_id = IDR_INFOBAR_GEOLOCATION;
66 break;
67 #if defined(ENABLE_NOTIFICATIONS)
68 case content::PermissionType::NOTIFICATIONS:
69 icon_id = IDR_INFOBAR_DESKTOP_NOTIFICATIONS;
70 break;
71 #endif
72 case content::PermissionType::MIDI_SYSEX:
73 icon_id = IDR_ALLOWED_MIDI_SYSEX;
74 break;
75 default:
76 NOTREACHED();
77 }
78 #endif
79 return icon_id;
80 }
81
82 base::string16 PermissionBubbleRequestImpl::GetMessageTextFragment() const {
83 int message_id;
84 switch (permission_type_) {
85 case content::PermissionType::GEOLOCATION:
86 message_id = IDS_GEOLOCATION_INFOBAR_PERMISSION_FRAGMENT;
87 break;
88 #if defined(ENABLE_NOTIFICATIONS)
89 case content::PermissionType::NOTIFICATIONS:
90 message_id = IDS_NOTIFICATION_PERMISSIONS_FRAGMENT;
91 break;
92 #endif
93 case content::PermissionType::MIDI_SYSEX:
94 message_id = IDS_MIDI_SYSEX_PERMISSION_FRAGMENT;
95 break;
96 case content::PermissionType::PUSH_MESSAGING:
97 message_id = IDS_PUSH_MESSAGES_BUBBLE_FRAGMENT;
98 break;
99 #if defined(OS_CHROMEOS)
100 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER:
101 message_id = IDS_PROTECTED_MEDIA_IDENTIFIER_PERMISSION_FRAGMENT;
102 break;
103 #endif
104 default:
105 NOTREACHED();
106 return base::string16();
107 }
108 return l10n_util::GetStringUTF16(message_id);
109 }
110
111 GURL PermissionBubbleRequestImpl::GetOrigin() const {
112 return request_origin_;
113 }
114
115 void PermissionBubbleRequestImpl::PermissionGranted() {
116 RegisterActionTaken();
117 permission_decided_callback_.Run(true, CONTENT_SETTING_ALLOW);
118 }
119
120 void PermissionBubbleRequestImpl::PermissionDenied() {
121 RegisterActionTaken();
122 permission_decided_callback_.Run(true, CONTENT_SETTING_BLOCK);
123 }
124
125 void PermissionBubbleRequestImpl::Cancelled() {
126 RegisterActionTaken();
127 permission_decided_callback_.Run(false, CONTENT_SETTING_DEFAULT);
128 }
129
130 void PermissionBubbleRequestImpl::RequestFinished() {
131 is_finished_ = true;
132 delete_callback_.Run();
133 }
134
135 PermissionBubbleType PermissionBubbleRequestImpl::GetPermissionBubbleType()
136 const {
137 switch (permission_type_) {
138 case content::PermissionType::GEOLOCATION:
139 return PermissionBubbleType::PERMISSION_GEOLOCATION;
140 #if defined(ENABLE_NOTIFICATIONS)
141 case content::PermissionType::NOTIFICATIONS:
142 return PermissionBubbleType::PERMISSION_NOTIFICATIONS;
143 #endif
144 case content::PermissionType::MIDI_SYSEX:
145 return PermissionBubbleType::PERMISSION_MIDI_SYSEX;
146 case content::PermissionType::PUSH_MESSAGING:
147 return PermissionBubbleType::PERMISSION_PUSH_MESSAGING;
148 #if defined(OS_CHROMEOS)
149 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER:
150 return PermissionBubbleType::PERMISSION_PROTECTED_MEDIA_IDENTIFIER;
151 #endif
152 default:
153 NOTREACHED();
154 return PermissionBubbleType::UNKNOWN;
155 }
156 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698