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

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: Fix missed file 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 // TODO(stefanocs): Pass in a non null profile.
33 PermissionUmaUtil::PermissionIgnored(permission_type_, request_origin_,
34 nullptr);
35 }
36
37 gfx::VectorIconId PermissionBubbleRequestImpl::GetVectorIconId() const {
38 #if !defined(OS_MACOSX)
39 switch (permission_type_) {
40 case content::PermissionType::GEOLOCATION:
41 return gfx::VectorIconId::LOCATION_ON;
42 #if defined(ENABLE_NOTIFICATIONS)
43 case content::PermissionType::NOTIFICATIONS:
44 return gfx::VectorIconId::NOTIFICATIONS;
45 #endif
46 #if defined(OS_CHROMEOS)
47 // TODO(xhwang): fix this icon, see crrev.com/863263007
48 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER:
49 return gfx::VectorIconId::CHROME_PRODUCT;
50 #endif
51 case content::PermissionType::MIDI_SYSEX:
52 return gfx::VectorIconId::MIDI;
53 default:
54 NOTREACHED();
55 return gfx::VectorIconId::VECTOR_ICON_NONE;
56 }
57 #else // !defined(OS_MACOSX)
58 return gfx::VectorIconId::VECTOR_ICON_NONE;
59 #endif
60 }
61
62 int PermissionBubbleRequestImpl::GetIconId() const {
63 int icon_id = IDR_INFOBAR_WARNING;
64 #if defined(OS_MACOSX)
65 switch (permission_type_) {
66 case content::PermissionType::GEOLOCATION:
67 icon_id = IDR_INFOBAR_GEOLOCATION;
68 break;
69 #if defined(ENABLE_NOTIFICATIONS)
70 case content::PermissionType::NOTIFICATIONS:
71 icon_id = IDR_INFOBAR_DESKTOP_NOTIFICATIONS;
72 break;
73 #endif
74 case content::PermissionType::MIDI_SYSEX:
75 icon_id = IDR_ALLOWED_MIDI_SYSEX;
76 break;
77 default:
78 NOTREACHED();
79 }
80 #endif
81 return icon_id;
82 }
83
84 base::string16 PermissionBubbleRequestImpl::GetMessageTextFragment() const {
85 int message_id;
86 switch (permission_type_) {
87 case content::PermissionType::GEOLOCATION:
88 message_id = IDS_GEOLOCATION_INFOBAR_PERMISSION_FRAGMENT;
89 break;
90 #if defined(ENABLE_NOTIFICATIONS)
91 case content::PermissionType::NOTIFICATIONS:
92 message_id = IDS_NOTIFICATION_PERMISSIONS_FRAGMENT;
93 break;
94 #endif
95 case content::PermissionType::MIDI_SYSEX:
96 message_id = IDS_MIDI_SYSEX_PERMISSION_FRAGMENT;
97 break;
98 case content::PermissionType::PUSH_MESSAGING:
99 message_id = IDS_PUSH_MESSAGES_BUBBLE_FRAGMENT;
100 break;
101 #if defined(OS_CHROMEOS)
102 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER:
103 message_id = IDS_PROTECTED_MEDIA_IDENTIFIER_PERMISSION_FRAGMENT;
104 break;
105 #endif
106 default:
107 NOTREACHED();
108 return base::string16();
109 }
110 return l10n_util::GetStringUTF16(message_id);
111 }
112
113 GURL PermissionBubbleRequestImpl::GetOrigin() const {
114 return request_origin_;
115 }
116
117 void PermissionBubbleRequestImpl::PermissionGranted() {
118 RegisterActionTaken();
119 permission_decided_callback_.Run(true, CONTENT_SETTING_ALLOW);
120 }
121
122 void PermissionBubbleRequestImpl::PermissionDenied() {
123 RegisterActionTaken();
124 permission_decided_callback_.Run(true, CONTENT_SETTING_BLOCK);
125 }
126
127 void PermissionBubbleRequestImpl::Cancelled() {
128 RegisterActionTaken();
129 permission_decided_callback_.Run(false, CONTENT_SETTING_DEFAULT);
130 }
131
132 void PermissionBubbleRequestImpl::RequestFinished() {
133 is_finished_ = true;
134 delete_callback_.Run();
135 }
136
137 PermissionBubbleType PermissionBubbleRequestImpl::GetPermissionBubbleType()
138 const {
139 switch (permission_type_) {
140 case content::PermissionType::GEOLOCATION:
141 return PermissionBubbleType::PERMISSION_GEOLOCATION;
142 #if defined(ENABLE_NOTIFICATIONS)
143 case content::PermissionType::NOTIFICATIONS:
144 return PermissionBubbleType::PERMISSION_NOTIFICATIONS;
145 #endif
146 case content::PermissionType::MIDI_SYSEX:
147 return PermissionBubbleType::PERMISSION_MIDI_SYSEX;
148 case content::PermissionType::PUSH_MESSAGING:
149 return PermissionBubbleType::PERMISSION_PUSH_MESSAGING;
150 #if defined(OS_CHROMEOS)
151 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER:
152 return PermissionBubbleType::PERMISSION_PROTECTED_MEDIA_IDENTIFIER;
153 #endif
154 default:
155 NOTREACHED();
156 return PermissionBubbleType::UNKNOWN;
157 }
158 }
OLDNEW
« no previous file with comments | « chrome/browser/permissions/permission_bubble_request_impl.h ('k') | chrome/browser/permissions/permission_context_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698