| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_queue_controller.h" | 5 #include "chrome/browser/permissions/permission_queue_controller.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 9 #include "chrome/browser/geolocation/geolocation_infobar_delegate_android.h" | 9 #include "chrome/browser/geolocation/geolocation_infobar_delegate_android.h" |
| 10 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 pending_infobar_requests_.erase(i); | 202 pending_infobar_requests_.erase(i); |
| 203 return; | 203 return; |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 | 206 |
| 207 void PermissionQueueController::OnPermissionSet(const PermissionRequestID& id, | 207 void PermissionQueueController::OnPermissionSet(const PermissionRequestID& id, |
| 208 const GURL& requesting_frame, | 208 const GURL& requesting_frame, |
| 209 const GURL& embedder, | 209 const GURL& embedder, |
| 210 bool user_gesture, | 210 bool user_gesture, |
| 211 bool update_content_setting, | 211 bool update_content_setting, |
| 212 bool allowed) { | 212 PermissionAction decision) { |
| 213 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 213 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 214 | 214 |
| 215 // TODO(miguelg): move the permission persistence to | 215 // TODO(miguelg): move the permission persistence to |
| 216 // PermissionContextBase once all the types are moved there. | 216 // PermissionContextBase once all the types are moved there. |
| 217 PermissionRequestGestureType gesture_type = | 217 PermissionRequestGestureType gesture_type = |
| 218 user_gesture ? PermissionRequestGestureType::GESTURE | 218 user_gesture ? PermissionRequestGestureType::GESTURE |
| 219 : PermissionRequestGestureType::NO_GESTURE; | 219 : PermissionRequestGestureType::NO_GESTURE; |
| 220 if (update_content_setting) { | 220 switch (decision) { |
| 221 UpdateContentSetting(requesting_frame, embedder, allowed); | 221 case GRANTED: |
| 222 if (allowed) { | |
| 223 PermissionUmaUtil::PermissionGranted(permission_type_, gesture_type, | 222 PermissionUmaUtil::PermissionGranted(permission_type_, gesture_type, |
| 224 requesting_frame, profile_); | 223 requesting_frame, profile_); |
| 225 } else { | 224 break; |
| 225 case DENIED: |
| 226 PermissionUmaUtil::PermissionDenied(permission_type_, gesture_type, | 226 PermissionUmaUtil::PermissionDenied(permission_type_, gesture_type, |
| 227 requesting_frame, profile_); | 227 requesting_frame, profile_); |
| 228 } | 228 break; |
| 229 } else { | 229 case DISMISSED: |
| 230 PermissionUmaUtil::PermissionDismissed(permission_type_, gesture_type, | 230 PermissionUmaUtil::PermissionDismissed(permission_type_, gesture_type, |
| 231 requesting_frame, profile_); | 231 requesting_frame, profile_); |
| 232 break; |
| 233 default: |
| 234 NOTREACHED(); |
| 232 } | 235 } |
| 233 | 236 |
| 237 if (decision != DISMISSED && update_content_setting) |
| 238 UpdateContentSetting(requesting_frame, embedder, decision); |
| 239 |
| 234 // Cancel this request first, then notify listeners. TODO(pkasting): Why | 240 // Cancel this request first, then notify listeners. TODO(pkasting): Why |
| 235 // is this order important? | 241 // is this order important? |
| 236 PendingInfobarRequests requests_to_notify; | 242 PendingInfobarRequests requests_to_notify; |
| 237 PendingInfobarRequests infobars_to_remove; | 243 PendingInfobarRequests infobars_to_remove; |
| 238 std::vector<PendingInfobarRequests::iterator> pending_requests_to_remove; | 244 std::vector<PendingInfobarRequests::iterator> pending_requests_to_remove; |
| 239 for (PendingInfobarRequests::iterator i = pending_infobar_requests_.begin(); | 245 for (PendingInfobarRequests::iterator i = pending_infobar_requests_.begin(); |
| 240 i != pending_infobar_requests_.end(); ++i) { | 246 i != pending_infobar_requests_.end(); ++i) { |
| 241 if (!i->IsForPair(requesting_frame, embedder)) | 247 if (!i->IsForPair(requesting_frame, embedder)) |
| 242 continue; | 248 continue; |
| 243 requests_to_notify.push_back(*i); | 249 requests_to_notify.push_back(*i); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 260 infobars_to_remove.push_back(*i); | 266 infobars_to_remove.push_back(*i); |
| 261 } | 267 } |
| 262 | 268 |
| 263 // Remove all infobars for the same |requesting_frame| and |embedder|. | 269 // Remove all infobars for the same |requesting_frame| and |embedder|. |
| 264 for (PendingInfobarRequests::iterator i = infobars_to_remove.begin(); | 270 for (PendingInfobarRequests::iterator i = infobars_to_remove.begin(); |
| 265 i != infobars_to_remove.end(); ++i) | 271 i != infobars_to_remove.end(); ++i) |
| 266 GetInfoBarService(i->id())->RemoveInfoBar(i->infobar()); | 272 GetInfoBarService(i->id())->RemoveInfoBar(i->infobar()); |
| 267 | 273 |
| 268 // PermissionContextBase needs to know about the new ContentSetting value, | 274 // PermissionContextBase needs to know about the new ContentSetting value, |
| 269 // CONTENT_SETTING_DEFAULT being the value for nothing happened. The callers | 275 // CONTENT_SETTING_DEFAULT being the value for nothing happened. The callers |
| 270 // of ::OnPermissionSet passes { true, true } for allow, { true, false } for | 276 // of ::OnPermissionSet passes { bool, GRANTED } for allow, { bool, DENIED } |
| 271 // block and { false, * } for dismissed. The tuple being | 277 // for block and { false, DISMISSED } for dismissed. The tuple being |
| 272 // { update_content_setting, allowed }. | 278 // { update_content_setting, decision }. |
| 273 ContentSetting content_setting = CONTENT_SETTING_DEFAULT; | 279 ContentSetting content_setting = CONTENT_SETTING_DEFAULT; |
| 274 if (update_content_setting) { | 280 if (decision == GRANTED) |
| 275 content_setting = allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 281 content_setting = CONTENT_SETTING_ALLOW; |
| 276 } | 282 else if (decision == DENIED) |
| 283 content_setting = CONTENT_SETTING_BLOCK; |
| 277 | 284 |
| 278 // Send out the permission notifications. | 285 // Send out the permission notifications. |
| 279 for (PendingInfobarRequests::iterator i = requests_to_notify.begin(); | 286 for (PendingInfobarRequests::iterator i = requests_to_notify.begin(); |
| 280 i != requests_to_notify.end(); ++i) | 287 i != requests_to_notify.end(); ++i) |
| 281 i->RunCallback(content_setting); | 288 i->RunCallback(content_setting); |
| 282 | 289 |
| 283 // Remove the pending requests in reverse order. | 290 // Remove the pending requests in reverse order. |
| 284 for (int i = pending_requests_to_remove.size() - 1; i >= 0; --i) | 291 for (int i = pending_requests_to_remove.size() - 1; i >= 0; --i) |
| 285 pending_infobar_requests_.erase(pending_requests_to_remove[i]); | 292 pending_infobar_requests_.erase(pending_requests_to_remove[i]); |
| 286 } | 293 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 content::Source<InfoBarService>(infobar_service))) { | 392 content::Source<InfoBarService>(infobar_service))) { |
| 386 registrar_.Remove(this, | 393 registrar_.Remove(this, |
| 387 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 394 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
| 388 content::Source<InfoBarService>(infobar_service)); | 395 content::Source<InfoBarService>(infobar_service)); |
| 389 } | 396 } |
| 390 } | 397 } |
| 391 | 398 |
| 392 void PermissionQueueController::UpdateContentSetting( | 399 void PermissionQueueController::UpdateContentSetting( |
| 393 const GURL& requesting_frame, | 400 const GURL& requesting_frame, |
| 394 const GURL& embedder, | 401 const GURL& embedder, |
| 395 bool allowed) { | 402 PermissionAction decision) { |
| 396 if (requesting_frame.GetOrigin().SchemeIsFile()) { | 403 if (requesting_frame.GetOrigin().SchemeIsFile()) { |
| 397 // Chrome can be launched with --disable-web-security which allows | 404 // Chrome can be launched with --disable-web-security which allows |
| 398 // geolocation requests from file:// URLs. We don't want to store these | 405 // geolocation requests from file:// URLs. We don't want to store these |
| 399 // in the host content settings map. | 406 // in the host content settings map. |
| 400 return; | 407 return; |
| 401 } | 408 } |
| 402 | 409 |
| 403 ContentSetting content_setting = | 410 ContentSetting content_setting = |
| 404 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 411 (decision == GRANTED) ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 405 | 412 |
| 406 HostContentSettingsMapFactory::GetForProfile(profile_) | 413 HostContentSettingsMapFactory::GetForProfile(profile_) |
| 407 ->SetContentSettingDefaultScope( | 414 ->SetContentSettingDefaultScope( |
| 408 requesting_frame.GetOrigin(), embedder.GetOrigin(), | 415 requesting_frame.GetOrigin(), embedder.GetOrigin(), |
| 409 content_settings_type_, std::string(), content_setting); | 416 content_settings_type_, std::string(), content_setting); |
| 410 } | 417 } |
| OLD | NEW |