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

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: 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;
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 } 117 }
125 118
126 PermissionContextUmaUtil::PermissionRequested( 119 PermissionContextUmaUtil::PermissionRequested(
127 permission_type_, requesting_origin); 120 permission_type_, requesting_origin);
128 121
129 if (PermissionBubbleManager::Enabled()) { 122 if (PermissionBubbleManager::Enabled()) {
130 if (pending_bubbles_.get(id.ToString()) != NULL) 123 if (pending_bubbles_.get(id.ToString()) != NULL)
131 return; 124 return;
132 PermissionBubbleManager* bubble_manager = 125 PermissionBubbleManager* bubble_manager =
133 PermissionBubbleManager::FromWebContents(web_contents); 126 PermissionBubbleManager::FromWebContents(web_contents);
(...skipping 27 matching lines...) Expand all
161 // permission 154 // permission
162 false)); 155 false));
163 } 156 }
164 157
165 void PermissionContextBase::PermissionDecided( 158 void PermissionContextBase::PermissionDecided(
166 const PermissionRequestID& id, 159 const PermissionRequestID& id,
167 const GURL& requesting_origin, 160 const GURL& requesting_origin,
168 const GURL& embedding_origin, 161 const GURL& embedding_origin,
169 const BrowserPermissionCallback& callback, 162 const BrowserPermissionCallback& callback,
170 bool persist, 163 bool persist,
171 bool allowed) { 164 ContentSetting content_setting) {
172 // Infobar persistance and its related UMA is tracked on the infobar 165 // Infobar persistance and its related UMA is tracked on the infobar
173 // controller directly. 166 // controller directly.
174 if (PermissionBubbleManager::Enabled()) { 167 if (PermissionBubbleManager::Enabled()) {
175 if (persist) { 168 if (persist) {
176 if (allowed) 169 DCHECK(content_setting == CONTENT_SETTING_ALLOW ||
170 content_setting == CONTENT_SETTING_BLOCK);
171 if (CONTENT_SETTING_ALLOW)
177 PermissionContextUmaUtil::PermissionGranted(permission_type_, 172 PermissionContextUmaUtil::PermissionGranted(permission_type_,
178 requesting_origin); 173 requesting_origin);
179 else 174 else
180 PermissionContextUmaUtil::PermissionDenied(permission_type_, 175 PermissionContextUmaUtil::PermissionDenied(permission_type_,
181 requesting_origin); 176 requesting_origin);
182 } else { 177 } else {
178 DCHECK_EQ(content_setting, CONTENT_SETTING_DEFAULT);
183 PermissionContextUmaUtil::PermissionDismissed(permission_type_, 179 PermissionContextUmaUtil::PermissionDismissed(permission_type_,
184 requesting_origin); 180 requesting_origin);
185 } 181 }
186 } 182 }
187 183
188 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, 184 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
189 persist, allowed); 185 persist, content_setting);
190 } 186 }
191 187
192 PermissionQueueController* PermissionContextBase::GetQueueController() { 188 PermissionQueueController* PermissionContextBase::GetQueueController() {
193 return permission_queue_controller_.get(); 189 return permission_queue_controller_.get();
194 } 190 }
195 191
196 Profile* PermissionContextBase::profile() const { 192 Profile* PermissionContextBase::profile() const {
197 return profile_; 193 return profile_;
198 } 194 }
199 195
200 void PermissionContextBase::NotifyPermissionSet( 196 void PermissionContextBase::NotifyPermissionSet(
201 const PermissionRequestID& id, 197 const PermissionRequestID& id,
202 const GURL& requesting_origin, 198 const GURL& requesting_origin,
203 const GURL& embedding_origin, 199 const GURL& embedding_origin,
204 const BrowserPermissionCallback& callback, 200 const BrowserPermissionCallback& callback,
205 bool persist, 201 bool persist,
206 bool allowed) { 202 ContentSetting content_setting) {
207 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 203 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
204
208 if (persist) 205 if (persist)
209 UpdateContentSetting(requesting_origin, embedding_origin, allowed); 206 UpdateContentSetting(requesting_origin, embedding_origin, content_setting);
210 207
211 UpdateTabContext(id, requesting_origin, allowed); 208 UpdateTabContext(id, requesting_origin,
212 callback.Run(allowed); 209 content_setting == CONTENT_SETTING_ALLOW);
210
211 if (content_setting == CONTENT_SETTING_DEFAULT) {
212 content_setting =
213 profile_->GetHostContentSettingsMap()->GetDefaultContentSetting(
214 permission_type_, nullptr);
215 }
216
217 DCHECK_NE(content_setting, CONTENT_SETTING_DEFAULT);
218 callback.Run(content_setting);
213 } 219 }
214 220
215 void PermissionContextBase::CleanUpBubble(const PermissionRequestID& id) { 221 void PermissionContextBase::CleanUpBubble(const PermissionRequestID& id) {
216 size_t success = pending_bubbles_.erase(id.ToString()); 222 size_t success = pending_bubbles_.erase(id.ToString());
217 DCHECK(success == 1) << "Missing request " << id.ToString(); 223 DCHECK(success == 1) << "Missing request " << id.ToString();
218 } 224 }
219 225
220 void PermissionContextBase::UpdateContentSetting(const GURL& requesting_origin, 226 void PermissionContextBase::UpdateContentSetting(
221 const GURL& embedding_origin, 227 const GURL& requesting_origin,
222 bool allowed) { 228 const GURL& embedding_origin,
229 ContentSetting content_setting) {
223 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin()); 230 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin());
224 DCHECK_EQ(embedding_origin, embedding_origin.GetOrigin()); 231 DCHECK_EQ(embedding_origin, embedding_origin.GetOrigin());
225 ContentSetting content_setting = 232 DCHECK(content_setting == CONTENT_SETTING_ALLOW ||
226 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; 233 content_setting == CONTENT_SETTING_BLOCK);
234
227 profile_->GetHostContentSettingsMap()->SetContentSetting( 235 profile_->GetHostContentSettingsMap()->SetContentSetting(
228 ContentSettingsPattern::FromURLNoWildcard(requesting_origin), 236 ContentSettingsPattern::FromURLNoWildcard(requesting_origin),
229 ContentSettingsPattern::FromURLNoWildcard(embedding_origin), 237 ContentSettingsPattern::FromURLNoWildcard(embedding_origin),
230 permission_type_, std::string(), content_setting); 238 permission_type_, std::string(), content_setting);
231 } 239 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698