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

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

Issue 955383003: ContentBrowserClient::RequestPermission replies with PermissionStatus instead of bool. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix android geolocation breakage Created 5 years, 9 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/content_settings/permission_context_base.h" 5 #include "chrome/browser/content_settings/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/permission_bubble_request_impl.h" 9 #include "chrome/browser/content_settings/permission_bubble_request_impl.h"
10 #include "chrome/browser/content_settings/permission_context_uma_util.h" 10 #include "chrome/browser/content_settings/permission_context_uma_util.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 const BrowserPermissionCallback& callback) { 92 const BrowserPermissionCallback& callback) {
93 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 93 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
94 94
95 if (!requesting_origin.is_valid() || !embedding_origin.is_valid()) { 95 if (!requesting_origin.is_valid() || !embedding_origin.is_valid()) {
96 DVLOG(1) 96 DVLOG(1)
97 << "Attempt to use " << content_settings::GetTypeName(permission_type_) 97 << "Attempt to use " << content_settings::GetTypeName(permission_type_)
98 << " from an invalid URL: " << requesting_origin 98 << " from an invalid URL: " << requesting_origin
99 << "," << embedding_origin 99 << "," << embedding_origin
100 << " (" << content_settings::GetTypeName(permission_type_) 100 << " (" << content_settings::GetTypeName(permission_type_)
101 << " is not supported in popups)"; 101 << " is not supported in popups)";
102 NotifyPermissionSet(id, requesting_origin, embedding_origin, 102 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
103 callback, false /* persist */, false /* granted */); 103 false /* persist */, CONTENT_SETTING_BLOCK);
104 return; 104 return;
105 } 105 }
106 106
107 ContentSetting content_setting = 107 ContentSetting content_setting =
108 profile_->GetHostContentSettingsMap() 108 profile_->GetHostContentSettingsMap()
109 ->GetContentSettingAndMaybeUpdateLastUsage( 109 ->GetContentSettingAndMaybeUpdateLastUsage(
110 requesting_origin, embedding_origin, permission_type_, 110 requesting_origin, embedding_origin, permission_type_,
111 std::string()); 111 std::string());
112 112
113 switch (content_setting) { 113 if (content_setting == CONTENT_SETTING_ALLOW ||
114 case CONTENT_SETTING_BLOCK: 114 content_setting == CONTENT_SETTING_BLOCK) {
115 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, 115 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
116 false /* persist */, false /* granted */); 116 false /* persist */, content_setting);
117 return; 117 return;
118 case CONTENT_SETTING_ALLOW:
119 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
120 false /* persist */, true /* granted */);
121 return;
122 default:
123 break;
124 } 118 }
125 119
126 PermissionContextUmaUtil::PermissionRequested( 120 PermissionContextUmaUtil::PermissionRequested(
127 permission_type_, requesting_origin); 121 permission_type_, requesting_origin);
128 122
129 if (PermissionBubbleManager::Enabled()) { 123 if (PermissionBubbleManager::Enabled()) {
130 if (pending_bubbles_.get(id.ToString()) != NULL) 124 if (pending_bubbles_.get(id.ToString()) != NULL)
131 return; 125 return;
132 PermissionBubbleManager* bubble_manager = 126 PermissionBubbleManager* bubble_manager =
133 PermissionBubbleManager::FromWebContents(web_contents); 127 PermissionBubbleManager::FromWebContents(web_contents);
(...skipping 27 matching lines...) Expand all
161 // permission 155 // permission
162 false)); 156 false));
163 } 157 }
164 158
165 void PermissionContextBase::PermissionDecided( 159 void PermissionContextBase::PermissionDecided(
166 const PermissionRequestID& id, 160 const PermissionRequestID& id,
167 const GURL& requesting_origin, 161 const GURL& requesting_origin,
168 const GURL& embedding_origin, 162 const GURL& embedding_origin,
169 const BrowserPermissionCallback& callback, 163 const BrowserPermissionCallback& callback,
170 bool persist, 164 bool persist,
171 bool allowed) { 165 ContentSetting content_setting) {
172 // Infobar persistance and its related UMA is tracked on the infobar 166 // Infobar persistance and its related UMA is tracked on the infobar
173 // controller directly. 167 // controller directly.
174 if (PermissionBubbleManager::Enabled()) { 168 if (PermissionBubbleManager::Enabled()) {
175 if (persist) { 169 if (persist) {
176 if (allowed) 170 DCHECK(content_setting == CONTENT_SETTING_ALLOW ||
171 content_setting == CONTENT_SETTING_BLOCK);
172 if (CONTENT_SETTING_ALLOW)
dgrogan 2015/05/14 03:48:28 strictly by code inspection, but won't this block
Miguel Garcia 2015/05/14 11:10:53 You are totally right I uploaded a fix in https://
177 PermissionContextUmaUtil::PermissionGranted(permission_type_, 173 PermissionContextUmaUtil::PermissionGranted(permission_type_,
178 requesting_origin); 174 requesting_origin);
179 else 175 else
180 PermissionContextUmaUtil::PermissionDenied(permission_type_, 176 PermissionContextUmaUtil::PermissionDenied(permission_type_,
181 requesting_origin); 177 requesting_origin);
182 } else { 178 } else {
179 DCHECK_EQ(content_setting, CONTENT_SETTING_DEFAULT);
183 PermissionContextUmaUtil::PermissionDismissed(permission_type_, 180 PermissionContextUmaUtil::PermissionDismissed(permission_type_,
184 requesting_origin); 181 requesting_origin);
185 } 182 }
186 } 183 }
187 184
188 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, 185 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
189 persist, allowed); 186 persist, content_setting);
190 } 187 }
191 188
192 PermissionQueueController* PermissionContextBase::GetQueueController() { 189 PermissionQueueController* PermissionContextBase::GetQueueController() {
193 return permission_queue_controller_.get(); 190 return permission_queue_controller_.get();
194 } 191 }
195 192
196 Profile* PermissionContextBase::profile() const { 193 Profile* PermissionContextBase::profile() const {
197 return profile_; 194 return profile_;
198 } 195 }
199 196
200 void PermissionContextBase::NotifyPermissionSet( 197 void PermissionContextBase::NotifyPermissionSet(
201 const PermissionRequestID& id, 198 const PermissionRequestID& id,
202 const GURL& requesting_origin, 199 const GURL& requesting_origin,
203 const GURL& embedding_origin, 200 const GURL& embedding_origin,
204 const BrowserPermissionCallback& callback, 201 const BrowserPermissionCallback& callback,
205 bool persist, 202 bool persist,
206 bool allowed) { 203 ContentSetting content_setting) {
207 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 204 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
205
208 if (persist) 206 if (persist)
209 UpdateContentSetting(requesting_origin, embedding_origin, allowed); 207 UpdateContentSetting(requesting_origin, embedding_origin, content_setting);
210 208
211 UpdateTabContext(id, requesting_origin, allowed); 209 UpdateTabContext(id, requesting_origin,
212 callback.Run(allowed); 210 content_setting == CONTENT_SETTING_ALLOW);
211
212 if (content_setting == CONTENT_SETTING_DEFAULT) {
213 content_setting =
214 profile_->GetHostContentSettingsMap()->GetDefaultContentSetting(
215 permission_type_, nullptr);
216 }
217
218 DCHECK_NE(content_setting, CONTENT_SETTING_DEFAULT);
219 callback.Run(content_setting);
213 } 220 }
214 221
215 void PermissionContextBase::CleanUpBubble(const PermissionRequestID& id) { 222 void PermissionContextBase::CleanUpBubble(const PermissionRequestID& id) {
216 size_t success = pending_bubbles_.erase(id.ToString()); 223 size_t success = pending_bubbles_.erase(id.ToString());
217 DCHECK(success == 1) << "Missing request " << id.ToString(); 224 DCHECK(success == 1) << "Missing request " << id.ToString();
218 } 225 }
219 226
220 void PermissionContextBase::UpdateContentSetting(const GURL& requesting_origin, 227 void PermissionContextBase::UpdateContentSetting(
221 const GURL& embedding_origin, 228 const GURL& requesting_origin,
222 bool allowed) { 229 const GURL& embedding_origin,
230 ContentSetting content_setting) {
223 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin()); 231 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin());
224 DCHECK_EQ(embedding_origin, embedding_origin.GetOrigin()); 232 DCHECK_EQ(embedding_origin, embedding_origin.GetOrigin());
225 ContentSetting content_setting = 233 DCHECK(content_setting == CONTENT_SETTING_ALLOW ||
226 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; 234 content_setting == CONTENT_SETTING_BLOCK);
235
227 profile_->GetHostContentSettingsMap()->SetContentSetting( 236 profile_->GetHostContentSettingsMap()->SetContentSetting(
228 ContentSettingsPattern::FromURLNoWildcard(requesting_origin), 237 ContentSettingsPattern::FromURLNoWildcard(requesting_origin),
229 ContentSettingsPattern::FromURLNoWildcard(embedding_origin), 238 ContentSettingsPattern::FromURLNoWildcard(embedding_origin),
230 permission_type_, std::string(), content_setting); 239 permission_type_, std::string(), content_setting);
231 } 240 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698