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

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

Issue 1913413002: [WIP][POC] Base URL: https://chromium.googlesource.com/chromium/src.git@permission-request-rename
Patch Set: rebase Created 4 years, 8 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/permissions/permission_context_base.h" 5 #include "chrome/browser/permissions/permission_context_base.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 13 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
14 #include "chrome/browser/permissions/permission_request_id.h" 14 #include "chrome/browser/permissions/permission_request_id.h"
15 #include "chrome/browser/permissions/permission_request_impl.h"
16 #include "chrome/browser/permissions/permission_request_manager.h"
15 #include "chrome/browser/permissions/permission_uma_util.h" 17 #include "chrome/browser/permissions/permission_uma_util.h"
16 #include "chrome/browser/permissions/permission_util.h" 18 #include "chrome/browser/permissions/permission_util.h"
17 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
19 #include "components/content_settings/core/browser/host_content_settings_map.h" 21 #include "components/content_settings/core/browser/host_content_settings_map.h"
20 #include "components/content_settings/core/browser/website_settings_registry.h" 22 #include "components/content_settings/core/browser/website_settings_registry.h"
21 #include "components/prefs/pref_service.h" 23 #include "components/prefs/pref_service.h"
22 #include "components/variations/variations_associated_data.h" 24 #include "components/variations/variations_associated_data.h"
23 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
24 #include "content/public/browser/render_frame_host.h" 26 #include "content/public/browser/render_frame_host.h"
25 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
26 #include "content/public/common/origin_util.h" 28 #include "content/public/common/origin_util.h"
27 29
28 #if defined(OS_ANDROID) 30 #if defined(OS_ANDROID)
29 #include "chrome/browser/permissions/permission_queue_controller.h" 31 #include "chrome/browser/permissions/permission_queue_controller.h"
30 #else
31 #include "chrome/browser/permissions/permission_request_impl.h"
32 #include "chrome/browser/permissions/permission_request_manager.h"
33 #endif 32 #endif
34 33
35 // static 34 // static
36 const char PermissionContextBase::kPermissionsKillSwitchFieldStudy[] = 35 const char PermissionContextBase::kPermissionsKillSwitchFieldStudy[] =
37 "PermissionsKillSwitch"; 36 "PermissionsKillSwitch";
38 // static 37 // static
39 const char PermissionContextBase::kPermissionsKillSwitchBlockedValue[] = 38 const char PermissionContextBase::kPermissionsKillSwitchBlockedValue[] =
40 "blocked"; 39 "blocked";
41 40
42 PermissionContextBase::PermissionContextBase( 41 PermissionContextBase::PermissionContextBase(
43 Profile* profile, 42 Profile* profile,
44 const content::PermissionType permission_type, 43 const content::PermissionType permission_type,
45 const ContentSettingsType content_settings_type) 44 const ContentSettingsType content_settings_type)
46 : profile_(profile), 45 : profile_(profile),
47 permission_type_(permission_type), 46 permission_type_(permission_type),
48 content_settings_type_(content_settings_type), 47 content_settings_type_(content_settings_type),
49 weak_factory_(this) { 48 weak_factory_(this) {
50 #if defined(OS_ANDROID) 49 // #if defined(OS_ANDROID)
51 permission_queue_controller_.reset(new PermissionQueueController( 50 // TODO: add runtime flag.
52 profile_, permission_type_, content_settings_type_)); 51 // permission_queue_controller_.reset(new PermissionQueueController(
53 #endif 52 // profile_, permission_type_, content_settings_type_));
53 // #endif
54 } 54 }
55 55
56 PermissionContextBase::~PermissionContextBase() { 56 PermissionContextBase::~PermissionContextBase() {
57 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 57 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
58 } 58 }
59 59
60 void PermissionContextBase::RequestPermission( 60 void PermissionContextBase::RequestPermission(
61 content::WebContents* web_contents, 61 content::WebContents* web_contents,
62 const PermissionRequestID& id, 62 const PermissionRequestID& id,
63 const GURL& requesting_frame, 63 const GURL& requesting_frame,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 ->SetContentSettingDefaultScope(requesting_origin, embedding_origin, 140 ->SetContentSettingDefaultScope(requesting_origin, embedding_origin,
141 content_settings_type_, std::string(), 141 content_settings_type_, std::string(),
142 CONTENT_SETTING_DEFAULT); 142 CONTENT_SETTING_DEFAULT);
143 } 143 }
144 144
145 void PermissionContextBase::CancelPermissionRequest( 145 void PermissionContextBase::CancelPermissionRequest(
146 content::WebContents* web_contents, 146 content::WebContents* web_contents,
147 const PermissionRequestID& id) { 147 const PermissionRequestID& id) {
148 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 148 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
149 149
150 #if defined(OS_ANDROID) 150 // #if defined(OS_ANDROID)
151 GetQueueController()->CancelInfoBarRequest(id); 151 // GetQueueController()->CancelInfoBarRequest(id);
152 #else 152 // #else
153 PermissionRequest* cancelling = pending_requests_.get(id.ToString()); 153 PermissionRequest* cancelling = pending_requests_.get(id.ToString());
154 if (cancelling != NULL && web_contents != NULL && 154 if (cancelling != NULL && web_contents != NULL &&
155 PermissionRequestManager::FromWebContents(web_contents) != NULL) { 155 PermissionRequestManager::FromWebContents(web_contents) != NULL) {
156 PermissionRequestManager::FromWebContents(web_contents) 156 PermissionRequestManager::FromWebContents(web_contents)
157 ->CancelRequest(cancelling); 157 ->CancelRequest(cancelling);
158 } 158 }
159 #endif 159 // #endif
160 } 160 }
161 161
162 void PermissionContextBase::DecidePermission( 162 void PermissionContextBase::DecidePermission(
163 content::WebContents* web_contents, 163 content::WebContents* web_contents,
164 const PermissionRequestID& id, 164 const PermissionRequestID& id,
165 const GURL& requesting_origin, 165 const GURL& requesting_origin,
166 const GURL& embedding_origin, 166 const GURL& embedding_origin,
167 const BrowserPermissionCallback& callback) { 167 const BrowserPermissionCallback& callback) {
168 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 168 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
169 169
170 #if !defined(OS_ANDROID) 170 // #if !defined(OS_ANDROID)
171
172 LOG(INFO) << "REQUESTING PERMISSION";
171 PermissionRequestManager* permission_request_manager = 173 PermissionRequestManager* permission_request_manager =
172 PermissionRequestManager::FromWebContents(web_contents); 174 PermissionRequestManager::FromWebContents(web_contents);
173 // TODO(felt): sometimes |permission_request_manager| is null. This check is 175 // TODO(felt): sometimes |permission_request_manager| is null. This check is
174 // meant to prevent crashes. See crbug.com/457091. 176 // meant to prevent crashes. See crbug.com/457091.
175 if (!permission_request_manager) 177 if (!permission_request_manager)
176 return; 178 return;
177 std::unique_ptr<PermissionRequest> request_ptr(new PermissionRequestImpl( 179 std::unique_ptr<PermissionRequest> request_ptr(new PermissionRequestImpl(
178 requesting_origin, permission_type_, 180 requesting_origin, permission_type_,
179 base::Bind(&PermissionContextBase::PermissionDecided, 181 base::Bind(&PermissionContextBase::PermissionDecided,
180 weak_factory_.GetWeakPtr(), id, requesting_origin, 182 weak_factory_.GetWeakPtr(), id, requesting_origin,
181 embedding_origin, callback), 183 embedding_origin, callback),
182 base::Bind(&PermissionContextBase::CleanUpRequest, 184 base::Bind(&PermissionContextBase::CleanUpRequest,
183 weak_factory_.GetWeakPtr(), id))); 185 weak_factory_.GetWeakPtr(), id)));
184 PermissionRequest* request = request_ptr.get(); 186 PermissionRequest* request = request_ptr.get();
185 187
186 bool inserted = 188 bool inserted =
187 pending_requests_.add(id.ToString(), std::move(request_ptr)).second; 189 pending_requests_.add(id.ToString(), std::move(request_ptr)).second;
188 DCHECK(inserted) << "Duplicate id " << id.ToString(); 190 DCHECK(inserted) << "Duplicate id " << id.ToString();
189 permission_request_manager->AddRequest(request); 191 permission_request_manager->AddRequest(request);
190 #else 192 // #else
191 GetQueueController()->CreateInfoBarRequest( 193 // GetQueueController()->CreateInfoBarRequest(
192 id, requesting_origin, embedding_origin, 194 // id, requesting_origin, embedding_origin,
193 base::Bind(&PermissionContextBase::PermissionDecided, 195 // base::Bind(&PermissionContextBase::PermissionDecided,
194 weak_factory_.GetWeakPtr(), id, requesting_origin, 196 // weak_factory_.GetWeakPtr(), id, requesting_origin,
195 embedding_origin, callback, 197 // embedding_origin, callback,
196 // the queue controller takes care of persisting the 198 // // the queue controller takes care of persisting the
197 // permission 199 // // permission
198 false)); 200 // false));
199 #endif 201 // #endif
200 } 202 }
201 203
202 void PermissionContextBase::PermissionDecided( 204 void PermissionContextBase::PermissionDecided(
203 const PermissionRequestID& id, 205 const PermissionRequestID& id,
204 const GURL& requesting_origin, 206 const GURL& requesting_origin,
205 const GURL& embedding_origin, 207 const GURL& embedding_origin,
206 const BrowserPermissionCallback& callback, 208 const BrowserPermissionCallback& callback,
207 bool persist, 209 bool persist,
208 ContentSetting content_setting) { 210 ContentSetting content_setting) {
209 #if !defined(OS_ANDROID) 211 #if !defined(OS_ANDROID)
210 // Infobar persistence and its related UMA is tracked on the infobar 212 // Infobar persistence and its related UMA is tracked on the infobar
211 // controller directly. 213 // controller directly.
212 if (persist) { 214 if (persist) {
213 DCHECK(content_setting == CONTENT_SETTING_ALLOW || 215 DCHECK(content_setting == CONTENT_SETTING_ALLOW ||
214 content_setting == CONTENT_SETTING_BLOCK); 216 content_setting == CONTENT_SETTING_BLOCK);
215 if (content_setting == CONTENT_SETTING_ALLOW) 217 if (content_setting == CONTENT_SETTING_ALLOW)
216 PermissionUmaUtil::PermissionGranted(permission_type_, requesting_origin); 218 PermissionUmaUtil::PermissionGranted(permission_type_, requesting_origin);
217 else 219 else
218 PermissionUmaUtil::PermissionDenied(permission_type_, requesting_origin); 220 PermissionUmaUtil::PermissionDenied(permission_type_, requesting_origin);
219 } else { 221 } else {
220 DCHECK_EQ(content_setting, CONTENT_SETTING_DEFAULT); 222 DCHECK_EQ(content_setting, CONTENT_SETTING_DEFAULT);
221 PermissionUmaUtil::PermissionDismissed(permission_type_, requesting_origin); 223 PermissionUmaUtil::PermissionDismissed(permission_type_, requesting_origin);
222 } 224 }
223 #endif 225 #endif
224 226
225 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, 227 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
226 persist, content_setting); 228 persist, content_setting);
227 } 229 }
228 230
229 #if defined(OS_ANDROID) 231 // #if defined(OS_ANDROID)
230 PermissionQueueController* PermissionContextBase::GetQueueController() { 232 // PermissionQueueController* PermissionContextBase::GetQueueController() {
231 return permission_queue_controller_.get(); 233 // return permission_queue_controller_.get();
232 } 234 // }
233 #endif 235 // #endif
234 236
235 Profile* PermissionContextBase::profile() const { 237 Profile* PermissionContextBase::profile() const {
236 return profile_; 238 return profile_;
237 } 239 }
238 240
239 void PermissionContextBase::NotifyPermissionSet( 241 void PermissionContextBase::NotifyPermissionSet(
240 const PermissionRequestID& id, 242 const PermissionRequestID& id,
241 const GURL& requesting_origin, 243 const GURL& requesting_origin,
242 const GURL& embedding_origin, 244 const GURL& embedding_origin,
243 const BrowserPermissionCallback& callback, 245 const BrowserPermissionCallback& callback,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 content_setting); 283 content_setting);
282 } 284 }
283 285
284 bool PermissionContextBase::IsPermissionKillSwitchOn() const { 286 bool PermissionContextBase::IsPermissionKillSwitchOn() const {
285 const std::string param = variations::GetVariationParamValue( 287 const std::string param = variations::GetVariationParamValue(
286 kPermissionsKillSwitchFieldStudy, 288 kPermissionsKillSwitchFieldStudy,
287 PermissionUtil::GetPermissionString(permission_type_)); 289 PermissionUtil::GetPermissionString(permission_type_));
288 290
289 return param == kPermissionsKillSwitchBlockedValue; 291 return param == kPermissionsKillSwitchBlockedValue;
290 } 292 }
OLDNEW
« no previous file with comments | « chrome/browser/permissions/permission_context_base.h ('k') | chrome/browser/permissions/permission_infobar_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698