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

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

Issue 2675483002: Replace PermissionType in chrome/ with ContentSettingsType (Closed)
Patch Set: ready Created 3 years, 10 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_manager.h" 5 #include "chrome/browser/permissions/permission_manager.h"
6 6
7 #include <stddef.h>
8
9 #include <memory> 7 #include <memory>
10 #include <utility> 8 #include <utility>
11 9
12 #include "base/callback.h" 10 #include "base/callback.h"
13 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
14 #include "build/build_config.h" 12 #include "build/build_config.h"
15 #include "chrome/browser/background_sync/background_sync_permission_context.h" 13 #include "chrome/browser/background_sync/background_sync_permission_context.h"
16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 14 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
17 #include "chrome/browser/media/midi_permission_context.h" 15 #include "chrome/browser/media/midi_permission_context.h"
18 #include "chrome/browser/media/webrtc/media_stream_device_permission_context.h" 16 #include "chrome/browser/media/webrtc/media_stream_device_permission_context.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 ContentSetting setting) { 77 ContentSetting setting) {
80 callback.Run(ContentSettingToPermissionStatus(setting)); 78 callback.Run(ContentSettingToPermissionStatus(setting));
81 } 79 }
82 80
83 // Helper method to convert PermissionType to ContentSettingType. 81 // Helper method to convert PermissionType to ContentSettingType.
84 ContentSettingsType PermissionTypeToContentSetting(PermissionType permission) { 82 ContentSettingsType PermissionTypeToContentSetting(PermissionType permission) {
85 switch (permission) { 83 switch (permission) {
86 case PermissionType::MIDI_SYSEX: 84 case PermissionType::MIDI_SYSEX:
87 return CONTENT_SETTINGS_TYPE_MIDI_SYSEX; 85 return CONTENT_SETTINGS_TYPE_MIDI_SYSEX;
88 case PermissionType::PUSH_MESSAGING: 86 case PermissionType::PUSH_MESSAGING:
87 return CONTENT_SETTINGS_TYPE_PUSH_MESSAGING;
89 case PermissionType::NOTIFICATIONS: 88 case PermissionType::NOTIFICATIONS:
90 return CONTENT_SETTINGS_TYPE_NOTIFICATIONS; 89 return CONTENT_SETTINGS_TYPE_NOTIFICATIONS;
91 case PermissionType::GEOLOCATION: 90 case PermissionType::GEOLOCATION:
92 return CONTENT_SETTINGS_TYPE_GEOLOCATION; 91 return CONTENT_SETTINGS_TYPE_GEOLOCATION;
93 case PermissionType::PROTECTED_MEDIA_IDENTIFIER: 92 case PermissionType::PROTECTED_MEDIA_IDENTIFIER:
94 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) 93 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
95 return CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER; 94 return CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER;
96 #else 95 #else
97 NOTIMPLEMENTED(); 96 NOTIMPLEMENTED();
98 break; 97 break;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 const std::vector<PermissionStatus>& vector) { 138 const std::vector<PermissionStatus>& vector) {
140 DCHECK_EQ(vector.size(), 1ul); 139 DCHECK_EQ(vector.size(), 1ul);
141 callback.Run(vector[0]); 140 callback.Run(vector[0]);
142 } 141 }
143 142
144 // Function used for handling permission types which do not change their 143 // Function used for handling permission types which do not change their
145 // value i.e. they are always approved or always denied etc. 144 // value i.e. they are always approved or always denied etc.
146 // CONTENT_SETTING_DEFAULT is returned if the permission needs further handling. 145 // CONTENT_SETTING_DEFAULT is returned if the permission needs further handling.
147 // This function should only be called when IsConstantPermission has returned 146 // This function should only be called when IsConstantPermission has returned
148 // true for the PermissionType. 147 // true for the PermissionType.
149 ContentSetting GetContentSettingForConstantPermission(PermissionType type) { 148 blink::mojom::PermissionStatus GetPermissionStatusForConstantPermission(
149 PermissionType type) {
150 DCHECK(IsConstantPermission(type)); 150 DCHECK(IsConstantPermission(type));
151 switch (type) { 151 switch (type) {
152 case PermissionType::MIDI: 152 case PermissionType::MIDI:
153 return CONTENT_SETTING_ALLOW; 153 return PermissionStatus::GRANTED;
154 default: 154 default:
155 return CONTENT_SETTING_DEFAULT; 155 return PermissionStatus::DENIED;
156 } 156 }
157 } 157 }
158 158
159 } // anonymous namespace 159 } // anonymous namespace
160 160
161 class PermissionManager::PendingRequest { 161 class PermissionManager::PendingRequest {
162 public: 162 public:
163 PendingRequest(content::RenderFrameHost* render_frame_host, 163 PendingRequest(content::RenderFrameHost* render_frame_host,
164 const std::vector<PermissionType> permissions, 164 const std::vector<PermissionType> permissions,
165 const base::Callback< 165 const base::Callback<
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 std::vector<PermissionType> permissions_; 205 std::vector<PermissionType> permissions_;
206 std::vector<PermissionStatus> results_; 206 std::vector<PermissionStatus> results_;
207 size_t remaining_results_; 207 size_t remaining_results_;
208 }; 208 };
209 209
210 struct PermissionManager::Subscription { 210 struct PermissionManager::Subscription {
211 PermissionType permission; 211 PermissionType permission;
212 GURL requesting_origin; 212 GURL requesting_origin;
213 GURL embedding_origin; 213 GURL embedding_origin;
214 base::Callback<void(PermissionStatus)> callback; 214 base::Callback<void(PermissionStatus)> callback;
215 ContentSetting current_value; 215 PermissionStatus current_value;
216 }; 216 };
217 217
218 // static 218 // static
219 PermissionManager* PermissionManager::Get(Profile* profile) { 219 PermissionManager* PermissionManager::Get(Profile* profile) {
220 return PermissionManagerFactory::GetForProfile(profile); 220 return PermissionManagerFactory::GetForProfile(profile);
221 } 221 }
222 222
223 PermissionManager::PermissionManager(Profile* profile) 223 PermissionManager::PermissionManager(Profile* profile)
224 : profile_(profile), 224 : profile_(profile),
225 weak_ptr_factory_(this) { 225 weak_ptr_factory_(this) {
226 permission_contexts_[PermissionType::MIDI_SYSEX] = 226 permission_contexts_[CONTENT_SETTINGS_TYPE_MIDI_SYSEX] =
227 base::MakeUnique<MidiPermissionContext>(profile); 227 base::MakeUnique<MidiPermissionContext>(profile);
228 permission_contexts_[PermissionType::PUSH_MESSAGING] = 228 permission_contexts_[CONTENT_SETTINGS_TYPE_PUSH_MESSAGING] =
229 base::MakeUnique<NotificationPermissionContext>( 229 base::MakeUnique<NotificationPermissionContext>(
230 profile, PermissionType::PUSH_MESSAGING); 230 profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING);
231 permission_contexts_[PermissionType::NOTIFICATIONS] = 231 permission_contexts_[CONTENT_SETTINGS_TYPE_NOTIFICATIONS] =
232 base::MakeUnique<NotificationPermissionContext>( 232 base::MakeUnique<NotificationPermissionContext>(
233 profile, PermissionType::NOTIFICATIONS); 233 profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
234 #if !defined(OS_ANDROID) 234 #if !defined(OS_ANDROID)
235 permission_contexts_[PermissionType::GEOLOCATION] = 235 permission_contexts_[CONTENT_SETTINGS_TYPE_GEOLOCATION] =
236 base::MakeUnique<GeolocationPermissionContext>(profile); 236 base::MakeUnique<GeolocationPermissionContext>(profile);
237 #else 237 #else
238 permission_contexts_[PermissionType::GEOLOCATION] = 238 permission_contexts_[CONTENT_SETTINGS_TYPE_GEOLOCATION] =
239 base::MakeUnique<GeolocationPermissionContextAndroid>(profile); 239 base::MakeUnique<GeolocationPermissionContextAndroid>(profile);
240 #endif 240 #endif
241 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) 241 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
242 permission_contexts_[PermissionType::PROTECTED_MEDIA_IDENTIFIER] = 242 permission_contexts_[CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER] =
243 base::MakeUnique<ProtectedMediaIdentifierPermissionContext>(profile); 243 base::MakeUnique<ProtectedMediaIdentifierPermissionContext>(profile);
244 #endif 244 #endif
245 permission_contexts_[PermissionType::DURABLE_STORAGE] = 245 permission_contexts_[CONTENT_SETTINGS_TYPE_DURABLE_STORAGE] =
246 base::MakeUnique<DurableStoragePermissionContext>(profile); 246 base::MakeUnique<DurableStoragePermissionContext>(profile);
247 permission_contexts_[PermissionType::AUDIO_CAPTURE] = 247 permission_contexts_[CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC] =
248 base::MakeUnique<MediaStreamDevicePermissionContext>( 248 base::MakeUnique<MediaStreamDevicePermissionContext>(
249 profile, content::PermissionType::AUDIO_CAPTURE, 249 profile, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
250 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); 250 permission_contexts_[CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA] =
251 permission_contexts_[PermissionType::VIDEO_CAPTURE] =
252 base::MakeUnique<MediaStreamDevicePermissionContext>( 251 base::MakeUnique<MediaStreamDevicePermissionContext>(
253 profile, content::PermissionType::VIDEO_CAPTURE, 252 profile, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
254 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); 253 permission_contexts_[CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC] =
255 permission_contexts_[PermissionType::BACKGROUND_SYNC] =
256 base::MakeUnique<BackgroundSyncPermissionContext>(profile); 254 base::MakeUnique<BackgroundSyncPermissionContext>(profile);
257 #if BUILDFLAG(ENABLE_PLUGINS) 255 #if BUILDFLAG(ENABLE_PLUGINS)
258 permission_contexts_[PermissionType::FLASH] = 256 permission_contexts_[CONTENT_SETTINGS_TYPE_PLUGINS] =
259 base::MakeUnique<FlashPermissionContext>(profile); 257 base::MakeUnique<FlashPermissionContext>(profile);
260 #endif 258 #endif
261 } 259 }
262 260
263 PermissionManager::~PermissionManager() { 261 PermissionManager::~PermissionManager() {
264 if (!subscriptions_.IsEmpty()) 262 if (!subscriptions_.IsEmpty())
265 HostContentSettingsMapFactory::GetForProfile(profile_) 263 HostContentSettingsMapFactory::GetForProfile(profile_)
266 ->RemoveObserver(this); 264 ->RemoveObserver(this);
267 } 265 }
268 266
269 int PermissionManager::RequestPermission( 267 int PermissionManager::RequestPermission(
268 ContentSettingsType content_settings_type,
269 content::RenderFrameHost* render_frame_host,
270 const GURL& requesting_origin,
271 bool user_gesture,
272 const base::Callback<void(PermissionStatus)>& callback) {
273 PermissionType permission_type;
274 bool success = PermissionUtil::GetPermissionType(content_settings_type,
275 &permission_type);
276 DCHECK(success);
277 return RequestPermissions(
raymes 2017/02/07 04:46:15 I think it would be better to have functions that
Timothy Loh 2017/02/08 04:01:06 I think we can't do this until we add MIDI as a Co
278 std::vector<PermissionType>(1, permission_type), render_frame_host,
279 requesting_origin, user_gesture,
280 base::Bind(&PermissionRequestResponseCallbackWrapper, callback));
281 }
282
283 int PermissionManager::RequestPermission(
270 PermissionType permission, 284 PermissionType permission,
271 content::RenderFrameHost* render_frame_host, 285 content::RenderFrameHost* render_frame_host,
272 const GURL& requesting_origin, 286 const GURL& requesting_origin,
273 bool user_gesture, 287 bool user_gesture,
274 const base::Callback<void(PermissionStatus)>& callback) { 288 const base::Callback<void(PermissionStatus)>& callback) {
275 return RequestPermissions( 289 return RequestPermissions(
276 std::vector<PermissionType>(1, permission), 290 std::vector<PermissionType>(1, permission),
277 render_frame_host, 291 render_frame_host,
278 requesting_origin, 292 requesting_origin,
279 user_gesture, 293 user_gesture,
(...skipping 19 matching lines...) Expand all
299 313
300 int request_id = pending_requests_.Add(base::MakeUnique<PendingRequest>( 314 int request_id = pending_requests_.Add(base::MakeUnique<PendingRequest>(
301 render_frame_host, permissions, callback)); 315 render_frame_host, permissions, callback));
302 316
303 const PermissionRequestID request(render_frame_host, request_id); 317 const PermissionRequestID request(render_frame_host, request_id);
304 318
305 for (size_t i = 0; i < permissions.size(); ++i) { 319 for (size_t i = 0; i < permissions.size(); ++i) {
306 const PermissionType permission = permissions[i]; 320 const PermissionType permission = permissions[i];
307 321
308 if (IsConstantPermission(permission) || 322 if (IsConstantPermission(permission) ||
309 !GetPermissionContext(permission)) { 323 !GetPermissionContext(PermissionTypeToContentSetting(permission))) {
310 // Track permission request usages even for constant permissions. 324 // Track permission request usages even for constant permissions.
311 PermissionUmaUtil::PermissionRequested(permission, requesting_origin, 325 PermissionUmaUtil::PermissionRequested(permission, requesting_origin,
312 embedding_origin, profile_); 326 embedding_origin, profile_);
313 OnPermissionsRequestResponseStatus(request_id, i, 327 OnPermissionsRequestResponseStatus(
314 GetPermissionStatus(permission, requesting_origin, embedding_origin)); 328 request_id, i, GetPermissionStatusForConstantPermission(permission));
315 continue; 329 continue;
316 } 330 }
317 331
318 PermissionContextBase* context = GetPermissionContext(permission); 332 PermissionContextBase* context =
333 GetPermissionContext(PermissionTypeToContentSetting(permission));
319 context->RequestPermission( 334 context->RequestPermission(
320 web_contents, request, requesting_origin, user_gesture, 335 web_contents, request, requesting_origin, user_gesture,
321 base::Bind(&ContentSettingToPermissionStatusCallbackWrapper, 336 base::Bind(&ContentSettingToPermissionStatusCallbackWrapper,
322 base::Bind(&PermissionManager::OnPermissionsRequestResponseStatus, 337 base::Bind(&PermissionManager::OnPermissionsRequestResponseStatus,
323 weak_ptr_factory_.GetWeakPtr(), request_id, i))); 338 weak_ptr_factory_.GetWeakPtr(), request_id, i)));
324 } 339 }
325 340
326 // The request might have been resolved already. 341 // The request might have been resolved already.
327 if (!pending_requests_.Lookup(request_id)) 342 if (!pending_requests_.Lookup(request_id))
328 return kNoPendingOperation; 343 return kNoPendingOperation;
329 344
330 return request_id; 345 return request_id;
331 } 346 }
332 347
333 PermissionContextBase* PermissionManager::GetPermissionContext( 348 PermissionContextBase* PermissionManager::GetPermissionContext(
334 PermissionType type) { 349 ContentSettingsType type) {
335 const auto& it = permission_contexts_.find(type); 350 const auto& it = permission_contexts_.find(type);
336 return it == permission_contexts_.end() ? nullptr : it->second.get(); 351 return it == permission_contexts_.end() ? nullptr : it->second.get();
337 } 352 }
338 353
339 void PermissionManager::OnPermissionsRequestResponseStatus( 354 void PermissionManager::OnPermissionsRequestResponseStatus(
340 int request_id, 355 int request_id,
341 int permission_id, 356 int permission_id,
342 PermissionStatus status) { 357 PermissionStatus status) {
343 PendingRequest* pending_request = pending_requests_.Lookup(request_id); 358 PendingRequest* pending_request = pending_requests_.Lookup(request_id);
344 pending_request->SetPermissionStatus(permission_id, status); 359 pending_request->SetPermissionStatus(permission_id, status);
(...skipping 12 matching lines...) Expand all
357 return; 372 return;
358 373
359 content::WebContents* web_contents = tab_util::GetWebContentsByFrameID( 374 content::WebContents* web_contents = tab_util::GetWebContentsByFrameID(
360 pending_request->render_process_id(), pending_request->render_frame_id()); 375 pending_request->render_process_id(), pending_request->render_frame_id());
361 DCHECK(web_contents); 376 DCHECK(web_contents);
362 377
363 const PermissionRequestID request(pending_request->render_process_id(), 378 const PermissionRequestID request(pending_request->render_process_id(),
364 pending_request->render_frame_id(), 379 pending_request->render_frame_id(),
365 request_id); 380 request_id);
366 for (PermissionType permission : pending_request->permissions()) { 381 for (PermissionType permission : pending_request->permissions()) {
367 PermissionContextBase* context = GetPermissionContext(permission); 382 PermissionContextBase* context =
383 GetPermissionContext(PermissionTypeToContentSetting(permission));
368 if (!context) 384 if (!context)
369 continue; 385 continue;
370 context->CancelPermissionRequest(web_contents, request); 386 context->CancelPermissionRequest(web_contents, request);
371 } 387 }
372 pending_requests_.Remove(request_id); 388 pending_requests_.Remove(request_id);
373 } 389 }
374 390
375 void PermissionManager::ResetPermission(PermissionType permission, 391 void PermissionManager::ResetPermission(PermissionType permission,
376 const GURL& requesting_origin, 392 const GURL& requesting_origin,
377 const GURL& embedding_origin) { 393 const GURL& embedding_origin) {
378 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 394 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
379 PermissionContextBase* context = GetPermissionContext(permission); 395 PermissionContextBase* context =
396 GetPermissionContext(PermissionTypeToContentSetting(permission));
380 if (!context) 397 if (!context)
381 return; 398 return;
382 399
383 context->ResetPermission(requesting_origin.GetOrigin(), 400 context->ResetPermission(requesting_origin.GetOrigin(),
384 embedding_origin.GetOrigin()); 401 embedding_origin.GetOrigin());
385 } 402 }
386 403
387 PermissionStatus PermissionManager::GetPermissionStatus( 404 PermissionStatus PermissionManager::GetPermissionStatus(
388 PermissionType permission, 405 PermissionType permission,
389 const GURL& requesting_origin, 406 const GURL& requesting_origin,
390 const GURL& embedding_origin) { 407 const GURL& embedding_origin) {
391 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 408 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
392 return ContentSettingToPermissionStatus(GetPermissionStatusInternal( 409 if (IsConstantPermission(permission))
393 permission, requesting_origin, embedding_origin)); 410 return GetPermissionStatusForConstantPermission(permission);
411 return GetPermissionStatus(PermissionTypeToContentSetting(permission),
412 requesting_origin, embedding_origin);
413 }
414
415 PermissionStatus PermissionManager::GetPermissionStatus(
416 ContentSettingsType permission,
417 const GURL& requesting_origin,
418 const GURL& embedding_origin) {
419 PermissionContextBase* context = GetPermissionContext(permission);
420 return ContentSettingToPermissionStatus(
421 context->GetPermissionStatus(requesting_origin.GetOrigin(),
422 embedding_origin.GetOrigin()));
raymes 2017/02/07 04:46:15 nit: function order should match the header
Timothy Loh 2017/02/08 04:01:06 Done.
394 } 423 }
395 424
396 void PermissionManager::RegisterPermissionUsage(PermissionType permission, 425 void PermissionManager::RegisterPermissionUsage(PermissionType permission,
397 const GURL& requesting_origin, 426 const GURL& requesting_origin,
398 const GURL& embedding_origin) { 427 const GURL& embedding_origin) {
399 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 428 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
400 // This is required because constant permissions don't have a 429 // This is required because constant permissions don't have a
401 // ContentSettingsType. 430 // ContentSettingsType.
402 if (IsConstantPermission(permission)) 431 if (IsConstantPermission(permission))
403 return; 432 return;
(...skipping 12 matching lines...) Expand all
416 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 445 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
417 if (subscriptions_.IsEmpty()) 446 if (subscriptions_.IsEmpty())
418 HostContentSettingsMapFactory::GetForProfile(profile_)->AddObserver(this); 447 HostContentSettingsMapFactory::GetForProfile(profile_)->AddObserver(this);
419 448
420 auto subscription = base::MakeUnique<Subscription>(); 449 auto subscription = base::MakeUnique<Subscription>();
421 subscription->permission = permission; 450 subscription->permission = permission;
422 subscription->requesting_origin = requesting_origin; 451 subscription->requesting_origin = requesting_origin;
423 subscription->embedding_origin = embedding_origin; 452 subscription->embedding_origin = embedding_origin;
424 subscription->callback = callback; 453 subscription->callback = callback;
425 454
426 subscription->current_value = GetPermissionStatusInternal( 455 subscription->current_value =
427 permission, requesting_origin, embedding_origin); 456 GetPermissionStatus(permission, requesting_origin, embedding_origin);
428 457
429 return subscriptions_.Add(std::move(subscription)); 458 return subscriptions_.Add(std::move(subscription));
430 } 459 }
431 460
432 void PermissionManager::UnsubscribePermissionStatusChange(int subscription_id) { 461 void PermissionManager::UnsubscribePermissionStatusChange(int subscription_id) {
433 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 462 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
434 // Whether |subscription_id| is known will be checked by the Remove() call. 463 // Whether |subscription_id| is known will be checked by the Remove() call.
435 subscriptions_.Remove(subscription_id); 464 subscriptions_.Remove(subscription_id);
436 465
437 if (subscriptions_.IsEmpty()) 466 if (subscriptions_.IsEmpty())
438 HostContentSettingsMapFactory::GetForProfile(profile_) 467 HostContentSettingsMapFactory::GetForProfile(profile_)
439 ->RemoveObserver(this); 468 ->RemoveObserver(this);
440 } 469 }
441 470
442 bool PermissionManager::IsPermissionKillSwitchOn( 471 bool PermissionManager::IsPermissionKillSwitchOn(
443 content::PermissionType permission) { 472 ContentSettingsType permission) {
444 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 473 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
445 return GetPermissionContext(permission)->IsPermissionKillSwitchOn(); 474 return GetPermissionContext(permission)->IsPermissionKillSwitchOn();
446 } 475 }
447 476
448 void PermissionManager::OnContentSettingChanged( 477 void PermissionManager::OnContentSettingChanged(
449 const ContentSettingsPattern& primary_pattern, 478 const ContentSettingsPattern& primary_pattern,
450 const ContentSettingsPattern& secondary_pattern, 479 const ContentSettingsPattern& secondary_pattern,
451 ContentSettingsType content_type, 480 ContentSettingsType content_type,
452 std::string resource_identifier) { 481 std::string resource_identifier) {
453 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 482 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
454 std::list<base::Closure> callbacks; 483 std::list<base::Closure> callbacks;
455 484
456 for (SubscriptionsMap::iterator iter(&subscriptions_); 485 for (SubscriptionsMap::iterator iter(&subscriptions_);
457 !iter.IsAtEnd(); iter.Advance()) { 486 !iter.IsAtEnd(); iter.Advance()) {
458 Subscription* subscription = iter.GetCurrentValue(); 487 Subscription* subscription = iter.GetCurrentValue();
459 if (IsConstantPermission(subscription->permission)) 488 if (IsConstantPermission(subscription->permission))
460 continue; 489 continue;
461 if (PermissionTypeToContentSetting(subscription->permission) != 490 if (PermissionTypeToContentSetting(subscription->permission) !=
462 content_type) { 491 content_type) {
463 continue; 492 continue;
464 } 493 }
465 494
466 if (primary_pattern.IsValid() && 495 if (primary_pattern.IsValid() &&
467 !primary_pattern.Matches(subscription->requesting_origin)) 496 !primary_pattern.Matches(subscription->requesting_origin))
468 continue; 497 continue;
469 if (secondary_pattern.IsValid() && 498 if (secondary_pattern.IsValid() &&
470 !secondary_pattern.Matches(subscription->embedding_origin)) 499 !secondary_pattern.Matches(subscription->embedding_origin))
471 continue; 500 continue;
472 501
473 ContentSetting new_value = GetPermissionStatusInternal( 502 PermissionStatus new_value = GetPermissionStatus(
474 subscription->permission, subscription->requesting_origin, 503 subscription->permission, subscription->requesting_origin,
475 subscription->embedding_origin); 504 subscription->embedding_origin);
476 if (subscription->current_value == new_value) 505 if (subscription->current_value == new_value)
477 continue; 506 continue;
478 507
479 subscription->current_value = new_value; 508 subscription->current_value = new_value;
480 509
481 // Add the callback to |callbacks| which will be run after the loop to 510 // Add the callback to |callbacks| which will be run after the loop to
482 // prevent re-entrance issues. 511 // prevent re-entrance issues.
483 callbacks.push_back( 512 callbacks.push_back(base::Bind(subscription->callback, new_value));
484 base::Bind(subscription->callback,
485 ContentSettingToPermissionStatus(new_value)));
486 } 513 }
487 514
488 for (const auto& callback : callbacks) 515 for (const auto& callback : callbacks)
489 callback.Run(); 516 callback.Run();
490 } 517 }
491
492 ContentSetting PermissionManager::GetPermissionStatusInternal(
493 PermissionType permission,
494 const GURL& requesting_origin,
495 const GURL& embedding_origin) {
496 if (IsConstantPermission(permission))
497 return GetContentSettingForConstantPermission(permission);
498
499 PermissionContextBase* context = GetPermissionContext(permission);
500 return context->GetPermissionStatus(requesting_origin.GetOrigin(),
501 embedding_origin.GetOrigin());
502 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698