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

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

Issue 1337903002: permissions: remove PermissionQueueController and introduce PermissionInfoBarManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@callbacks-delegates
Patch Set: Just a rebase Created 5 years, 2 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 "base/logging.h" 7 #include "base/logging.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
10 #include "chrome/browser/permissions/permission_bubble_request_impl.h" 10 #include "chrome/browser/permissions/permission_bubble_request_impl.h"
11 #include "chrome/browser/permissions/permission_context_uma_util.h" 11 #include "chrome/browser/permissions/permission_context_uma_util.h"
12 #include "chrome/browser/permissions/permission_queue_controller.h" 12 #include "chrome/browser/permissions/permission_infobar_manager.h"
13 #include "chrome/browser/permissions/permission_request_id.h" 13 #include "chrome/browser/permissions/permission_request_id.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" 15 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
16 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
17 #include "components/content_settings/core/browser/host_content_settings_map.h" 17 #include "components/content_settings/core/browser/host_content_settings_map.h"
18 #include "components/content_settings/core/browser/website_settings_registry.h" 18 #include "components/content_settings/core/browser/website_settings_registry.h"
19 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
21 #include "content/public/common/origin_util.h" 21 #include "content/public/common/origin_util.h"
22 22
23 PermissionContextBase::PermissionContextBase( 23 PermissionContextBase::PermissionContextBase(
24 Profile* profile, 24 Profile* profile,
25 const ContentSettingsType permission_type) 25 const ContentSettingsType permission_type)
26 : profile_(profile), 26 : profile_(profile),
27 permission_type_(permission_type), 27 permission_type_(permission_type),
28 weak_factory_(this) { 28 weak_factory_(this) {
29 permission_queue_controller_.reset(
30 new PermissionQueueController(profile_, permission_type_));
31 } 29 }
32 30
33 PermissionContextBase::~PermissionContextBase() { 31 PermissionContextBase::~PermissionContextBase() {
34 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 32 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
35 } 33 }
36 34
37 void PermissionContextBase::RequestPermission( 35 void PermissionContextBase::RequestPermission(
38 content::WebContents* web_contents, 36 content::WebContents* web_contents,
39 const PermissionRequestID& id, 37 const PermissionRequestID& id,
40 const GURL& requesting_frame, 38 const GURL& requesting_frame,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 ContentSettingsPattern::FromURLNoWildcard(requesting_origin), 70 ContentSettingsPattern::FromURLNoWildcard(requesting_origin),
73 ContentSettingsPattern::FromURLNoWildcard(embedding_origin), 71 ContentSettingsPattern::FromURLNoWildcard(embedding_origin),
74 permission_type_, std::string(), CONTENT_SETTING_DEFAULT); 72 permission_type_, std::string(), CONTENT_SETTING_DEFAULT);
75 } 73 }
76 74
77 void PermissionContextBase::CancelPermissionRequest( 75 void PermissionContextBase::CancelPermissionRequest(
78 content::WebContents* web_contents, 76 content::WebContents* web_contents,
79 const PermissionRequestID& id) { 77 const PermissionRequestID& id) {
80 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 78 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
81 79
80 if (!web_contents)
81 return;
82
82 if (PermissionBubbleManager::Enabled()) { 83 if (PermissionBubbleManager::Enabled()) {
83 PermissionBubbleRequest* cancelling = 84 PermissionBubbleRequest* cancelling =
84 pending_bubbles_.get(id.ToString()); 85 pending_bubbles_.get(id.ToString());
85 if (cancelling != NULL && web_contents != NULL && 86 if (cancelling != NULL &&
86 PermissionBubbleManager::FromWebContents(web_contents) != NULL) { 87 PermissionBubbleManager::FromWebContents(web_contents) != NULL) {
87 PermissionBubbleManager::FromWebContents(web_contents)-> 88 PermissionBubbleManager::FromWebContents(web_contents)->
88 CancelRequest(cancelling); 89 CancelRequest(cancelling);
89 } 90 }
90 return; 91 return;
91 } 92 }
92 93
93 GetQueueController()->CancelInfoBarRequest(id); 94 if (PermissionInfoBarManager::FromWebContents(web_contents) != NULL) {
mlamouri (slow - plz ping) 2015/09/28 13:30:14 Remove |!= NULL| and do !PermissionInfoBarManager:
Lalit Maganti 2015/09/28 15:32:38 Done.
95 PermissionInfoBarManager::FromWebContents(web_contents)->
96 CancelInfoBarRequest(id);
97 }
mlamouri (slow - plz ping) 2015/09/28 13:30:14 What about removing the |return;| from the |Permis
Lalit Maganti 2015/09/28 15:32:38 Done.
94 } 98 }
95 99
96 void PermissionContextBase::DecidePermission( 100 void PermissionContextBase::DecidePermission(
97 content::WebContents* web_contents, 101 content::WebContents* web_contents,
98 const PermissionRequestID& id, 102 const PermissionRequestID& id,
99 const GURL& requesting_origin, 103 const GURL& requesting_origin,
100 const GURL& embedding_origin, 104 const GURL& embedding_origin,
101 bool user_gesture, 105 bool user_gesture,
102 const BrowserPermissionCallback& callback) { 106 const BrowserPermissionCallback& callback) {
103 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 107 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 weak_factory_.GetWeakPtr(), id))); 159 weak_factory_.GetWeakPtr(), id)));
156 PermissionBubbleRequest* request = request_ptr.get(); 160 PermissionBubbleRequest* request = request_ptr.get();
157 161
158 bool inserted = pending_bubbles_.add( 162 bool inserted = pending_bubbles_.add(
159 id.ToString(), request_ptr.Pass()).second; 163 id.ToString(), request_ptr.Pass()).second;
160 DCHECK(inserted) << "Duplicate id " << id.ToString(); 164 DCHECK(inserted) << "Duplicate id " << id.ToString();
161 bubble_manager->AddRequest(request); 165 bubble_manager->AddRequest(request);
162 return; 166 return;
163 } 167 }
164 168
165 // TODO(gbillock): Delete this and the infobar delegate when 169 PermissionInfoBarManager* infobar_manager =
166 // we're using only bubbles. crbug.com/337458 170 PermissionInfoBarManager::FromWebContents(web_contents);
167 GetQueueController()->CreateInfoBarRequest( 171 DCHECK(infobar_manager);
mlamouri (slow - plz ping) 2015/09/28 13:30:14 What if we are not in a Tab context? Couldn't the
Lalit Maganti 2015/09/28 15:32:38 You're right this is an issue. Best course of acti
168 id, requesting_origin, embedding_origin, 172 infobar_manager->CreateInfoBarRequest(
173 permission_type_, id,
174 requesting_origin, embedding_origin,
169 base::Bind(&PermissionContextBase::PermissionDecided, 175 base::Bind(&PermissionContextBase::PermissionDecided,
170 weak_factory_.GetWeakPtr(), id, requesting_origin, 176 weak_factory_.GetWeakPtr(), id, requesting_origin,
171 embedding_origin, callback, 177 embedding_origin, callback),
172 // the queue controller takes care of persisting the 178 base::Bind(&PermissionContextBase::NotifyPermissionSet,
mlamouri (slow - plz ping) 2015/09/28 13:30:14 It would be great to unify that with what Bubble d
Lalit Maganti 2015/09/28 15:32:38 Changed as discussed.
173 // permission 179 weak_factory_.GetWeakPtr(), id, requesting_origin,
174 false)); 180 embedding_origin, callback));
175 } 181 }
176 182
177 void PermissionContextBase::PermissionDecided( 183 void PermissionContextBase::PermissionDecided(
178 const PermissionRequestID& id, 184 const PermissionRequestID& id,
179 const GURL& requesting_origin, 185 const GURL& requesting_origin,
180 const GURL& embedding_origin, 186 const GURL& embedding_origin,
181 const BrowserPermissionCallback& callback, 187 const BrowserPermissionCallback& callback,
182 bool persist, 188 bool persist,
183 ContentSetting content_setting) { 189 ContentSetting content_setting) {
184 // Infobar persistance and its related UMA is tracked on the infobar 190 if (persist) {
185 // controller directly. 191 DCHECK(content_setting == CONTENT_SETTING_ALLOW ||
186 if (PermissionBubbleManager::Enabled()) { 192 content_setting == CONTENT_SETTING_BLOCK);
187 if (persist) { 193 if (content_setting == CONTENT_SETTING_ALLOW)
188 DCHECK(content_setting == CONTENT_SETTING_ALLOW || 194 PermissionContextUmaUtil::PermissionGranted(permission_type_,
189 content_setting == CONTENT_SETTING_BLOCK); 195 requesting_origin);
190 if (content_setting == CONTENT_SETTING_ALLOW) 196 else
191 PermissionContextUmaUtil::PermissionGranted(permission_type_, 197 PermissionContextUmaUtil::PermissionDenied(permission_type_,
192 requesting_origin); 198 requesting_origin);
193 else 199 } else {
194 PermissionContextUmaUtil::PermissionDenied(permission_type_, 200 DCHECK_EQ(content_setting, CONTENT_SETTING_DEFAULT);
195 requesting_origin); 201 PermissionContextUmaUtil::PermissionDismissed(permission_type_,
196 } else { 202 requesting_origin);
197 DCHECK_EQ(content_setting, CONTENT_SETTING_DEFAULT);
198 PermissionContextUmaUtil::PermissionDismissed(permission_type_,
199 requesting_origin);
200 }
201 } 203 }
202 204
203 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, 205 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
204 persist, content_setting); 206 persist, content_setting);
205 } 207 }
206 208
207 PermissionQueueController* PermissionContextBase::GetQueueController() {
208 return permission_queue_controller_.get();
209 }
210
211 Profile* PermissionContextBase::profile() const { 209 Profile* PermissionContextBase::profile() const {
212 return profile_; 210 return profile_;
213 } 211 }
214 212
215 void PermissionContextBase::NotifyPermissionSet( 213 void PermissionContextBase::NotifyPermissionSet(
216 const PermissionRequestID& id, 214 const PermissionRequestID& id,
217 const GURL& requesting_origin, 215 const GURL& requesting_origin,
218 const GURL& embedding_origin, 216 const GURL& embedding_origin,
219 const BrowserPermissionCallback& callback, 217 const BrowserPermissionCallback& callback,
220 bool persist, 218 bool persist,
(...skipping 28 matching lines...) Expand all
249 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin()); 247 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin());
250 DCHECK_EQ(embedding_origin, embedding_origin.GetOrigin()); 248 DCHECK_EQ(embedding_origin, embedding_origin.GetOrigin());
251 DCHECK(content_setting == CONTENT_SETTING_ALLOW || 249 DCHECK(content_setting == CONTENT_SETTING_ALLOW ||
252 content_setting == CONTENT_SETTING_BLOCK); 250 content_setting == CONTENT_SETTING_BLOCK);
253 251
254 HostContentSettingsMapFactory::GetForProfile(profile_)->SetContentSetting( 252 HostContentSettingsMapFactory::GetForProfile(profile_)->SetContentSetting(
255 ContentSettingsPattern::FromURLNoWildcard(requesting_origin), 253 ContentSettingsPattern::FromURLNoWildcard(requesting_origin),
256 ContentSettingsPattern::FromURLNoWildcard(embedding_origin), 254 ContentSettingsPattern::FromURLNoWildcard(embedding_origin),
257 permission_type_, std::string(), content_setting); 255 permission_type_, std::string(), content_setting);
258 } 256 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698