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

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

Issue 2675483002: Replace PermissionType in chrome/ with ContentSettingsType (Closed)
Patch Set: rebase 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 // TODO(timloh): We should be operating on ContentSettingsType instead of
274 // converting these back to PermissionType.
275 PermissionType permission_type;
276 bool success = PermissionUtil::GetPermissionType(content_settings_type,
277 &permission_type);
278 DCHECK(success);
279 return RequestPermissions(
280 std::vector<PermissionType>(1, permission_type), render_frame_host,
281 requesting_origin, user_gesture,
282 base::Bind(&PermissionRequestResponseCallbackWrapper, callback));
283 }
284
285 PermissionStatus PermissionManager::GetPermissionStatus(
286 ContentSettingsType permission,
287 const GURL& requesting_origin,
288 const GURL& embedding_origin) {
289 PermissionContextBase* context = GetPermissionContext(permission);
290 return ContentSettingToPermissionStatus(
291 context->GetPermissionStatus(requesting_origin.GetOrigin(),
292 embedding_origin.GetOrigin()));
293 }
294
295 int PermissionManager::RequestPermission(
270 PermissionType permission, 296 PermissionType permission,
271 content::RenderFrameHost* render_frame_host, 297 content::RenderFrameHost* render_frame_host,
272 const GURL& requesting_origin, 298 const GURL& requesting_origin,
273 bool user_gesture, 299 bool user_gesture,
274 const base::Callback<void(PermissionStatus)>& callback) { 300 const base::Callback<void(PermissionStatus)>& callback) {
275 return RequestPermissions( 301 return RequestPermissions(
276 std::vector<PermissionType>(1, permission), 302 std::vector<PermissionType>(1, permission),
277 render_frame_host, 303 render_frame_host,
278 requesting_origin, 304 requesting_origin,
279 user_gesture, 305 user_gesture,
(...skipping 19 matching lines...) Expand all
299 325
300 int request_id = pending_requests_.Add(base::MakeUnique<PendingRequest>( 326 int request_id = pending_requests_.Add(base::MakeUnique<PendingRequest>(
301 render_frame_host, permissions, callback)); 327 render_frame_host, permissions, callback));
302 328
303 const PermissionRequestID request(render_frame_host, request_id); 329 const PermissionRequestID request(render_frame_host, request_id);
304 330
305 for (size_t i = 0; i < permissions.size(); ++i) { 331 for (size_t i = 0; i < permissions.size(); ++i) {
306 const PermissionType permission = permissions[i]; 332 const PermissionType permission = permissions[i];
307 333
308 if (IsConstantPermission(permission) || 334 if (IsConstantPermission(permission) ||
309 !GetPermissionContext(permission)) { 335 !GetPermissionContext(PermissionTypeToContentSetting(permission))) {
310 // Track permission request usages even for constant permissions. 336 // Track permission request usages even for constant permissions.
311 PermissionUmaUtil::PermissionRequested(permission, requesting_origin, 337 PermissionUmaUtil::PermissionRequested(permission, requesting_origin,
312 embedding_origin, profile_); 338 embedding_origin, profile_);
313 OnPermissionsRequestResponseStatus(request_id, i, 339 OnPermissionsRequestResponseStatus(
314 GetPermissionStatus(permission, requesting_origin, embedding_origin)); 340 request_id, i, GetPermissionStatusForConstantPermission(permission));
315 continue; 341 continue;
316 } 342 }
317 343
318 PermissionContextBase* context = GetPermissionContext(permission); 344 PermissionContextBase* context =
345 GetPermissionContext(PermissionTypeToContentSetting(permission));
319 context->RequestPermission( 346 context->RequestPermission(
320 web_contents, request, requesting_origin, user_gesture, 347 web_contents, request, requesting_origin, user_gesture,
321 base::Bind(&ContentSettingToPermissionStatusCallbackWrapper, 348 base::Bind(&ContentSettingToPermissionStatusCallbackWrapper,
322 base::Bind(&PermissionManager::OnPermissionsRequestResponseStatus, 349 base::Bind(&PermissionManager::OnPermissionsRequestResponseStatus,
323 weak_ptr_factory_.GetWeakPtr(), request_id, i))); 350 weak_ptr_factory_.GetWeakPtr(), request_id, i)));
324 } 351 }
325 352
326 // The request might have been resolved already. 353 // The request might have been resolved already.
327 if (!pending_requests_.Lookup(request_id)) 354 if (!pending_requests_.Lookup(request_id))
328 return kNoPendingOperation; 355 return kNoPendingOperation;
329 356
330 return request_id; 357 return request_id;
331 } 358 }
332 359
333 PermissionContextBase* PermissionManager::GetPermissionContext( 360 PermissionContextBase* PermissionManager::GetPermissionContext(
334 PermissionType type) { 361 ContentSettingsType type) {
335 const auto& it = permission_contexts_.find(type); 362 const auto& it = permission_contexts_.find(type);
336 return it == permission_contexts_.end() ? nullptr : it->second.get(); 363 return it == permission_contexts_.end() ? nullptr : it->second.get();
337 } 364 }
338 365
339 void PermissionManager::OnPermissionsRequestResponseStatus( 366 void PermissionManager::OnPermissionsRequestResponseStatus(
340 int request_id, 367 int request_id,
341 int permission_id, 368 int permission_id,
342 PermissionStatus status) { 369 PermissionStatus status) {
343 PendingRequest* pending_request = pending_requests_.Lookup(request_id); 370 PendingRequest* pending_request = pending_requests_.Lookup(request_id);
344 pending_request->SetPermissionStatus(permission_id, status); 371 pending_request->SetPermissionStatus(permission_id, status);
(...skipping 12 matching lines...) Expand all
357 return; 384 return;
358 385
359 content::WebContents* web_contents = tab_util::GetWebContentsByFrameID( 386 content::WebContents* web_contents = tab_util::GetWebContentsByFrameID(
360 pending_request->render_process_id(), pending_request->render_frame_id()); 387 pending_request->render_process_id(), pending_request->render_frame_id());
361 DCHECK(web_contents); 388 DCHECK(web_contents);
362 389
363 const PermissionRequestID request(pending_request->render_process_id(), 390 const PermissionRequestID request(pending_request->render_process_id(),
364 pending_request->render_frame_id(), 391 pending_request->render_frame_id(),
365 request_id); 392 request_id);
366 for (PermissionType permission : pending_request->permissions()) { 393 for (PermissionType permission : pending_request->permissions()) {
367 PermissionContextBase* context = GetPermissionContext(permission); 394 PermissionContextBase* context =
395 GetPermissionContext(PermissionTypeToContentSetting(permission));
368 if (!context) 396 if (!context)
369 continue; 397 continue;
370 context->CancelPermissionRequest(web_contents, request); 398 context->CancelPermissionRequest(web_contents, request);
371 } 399 }
372 pending_requests_.Remove(request_id); 400 pending_requests_.Remove(request_id);
373 } 401 }
374 402
375 void PermissionManager::ResetPermission(PermissionType permission, 403 void PermissionManager::ResetPermission(PermissionType permission,
376 const GURL& requesting_origin, 404 const GURL& requesting_origin,
377 const GURL& embedding_origin) { 405 const GURL& embedding_origin) {
378 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 406 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
379 PermissionContextBase* context = GetPermissionContext(permission); 407 PermissionContextBase* context =
408 GetPermissionContext(PermissionTypeToContentSetting(permission));
380 if (!context) 409 if (!context)
381 return; 410 return;
382 411
383 context->ResetPermission(requesting_origin.GetOrigin(), 412 context->ResetPermission(requesting_origin.GetOrigin(),
384 embedding_origin.GetOrigin()); 413 embedding_origin.GetOrigin());
385 } 414 }
386 415
387 PermissionStatus PermissionManager::GetPermissionStatus( 416 PermissionStatus PermissionManager::GetPermissionStatus(
388 PermissionType permission, 417 PermissionType permission,
389 const GURL& requesting_origin, 418 const GURL& requesting_origin,
390 const GURL& embedding_origin) { 419 const GURL& embedding_origin) {
391 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 420 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
392 return ContentSettingToPermissionStatus(GetPermissionStatusInternal( 421 if (IsConstantPermission(permission))
393 permission, requesting_origin, embedding_origin)); 422 return GetPermissionStatusForConstantPermission(permission);
423 return GetPermissionStatus(PermissionTypeToContentSetting(permission),
424 requesting_origin, embedding_origin);
394 } 425 }
395 426
396 void PermissionManager::RegisterPermissionUsage(PermissionType permission, 427 void PermissionManager::RegisterPermissionUsage(PermissionType permission,
397 const GURL& requesting_origin, 428 const GURL& requesting_origin,
398 const GURL& embedding_origin) { 429 const GURL& embedding_origin) {
399 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 430 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
400 // This is required because constant permissions don't have a 431 // This is required because constant permissions don't have a
401 // ContentSettingsType. 432 // ContentSettingsType.
402 if (IsConstantPermission(permission)) 433 if (IsConstantPermission(permission))
403 return; 434 return;
(...skipping 12 matching lines...) Expand all
416 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 447 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
417 if (subscriptions_.IsEmpty()) 448 if (subscriptions_.IsEmpty())
418 HostContentSettingsMapFactory::GetForProfile(profile_)->AddObserver(this); 449 HostContentSettingsMapFactory::GetForProfile(profile_)->AddObserver(this);
419 450
420 auto subscription = base::MakeUnique<Subscription>(); 451 auto subscription = base::MakeUnique<Subscription>();
421 subscription->permission = permission; 452 subscription->permission = permission;
422 subscription->requesting_origin = requesting_origin; 453 subscription->requesting_origin = requesting_origin;
423 subscription->embedding_origin = embedding_origin; 454 subscription->embedding_origin = embedding_origin;
424 subscription->callback = callback; 455 subscription->callback = callback;
425 456
426 subscription->current_value = GetPermissionStatusInternal( 457 subscription->current_value =
427 permission, requesting_origin, embedding_origin); 458 GetPermissionStatus(permission, requesting_origin, embedding_origin);
428 459
429 return subscriptions_.Add(std::move(subscription)); 460 return subscriptions_.Add(std::move(subscription));
430 } 461 }
431 462
432 void PermissionManager::UnsubscribePermissionStatusChange(int subscription_id) { 463 void PermissionManager::UnsubscribePermissionStatusChange(int subscription_id) {
433 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 464 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
434 // Whether |subscription_id| is known will be checked by the Remove() call. 465 // Whether |subscription_id| is known will be checked by the Remove() call.
435 subscriptions_.Remove(subscription_id); 466 subscriptions_.Remove(subscription_id);
436 467
437 if (subscriptions_.IsEmpty()) 468 if (subscriptions_.IsEmpty())
438 HostContentSettingsMapFactory::GetForProfile(profile_) 469 HostContentSettingsMapFactory::GetForProfile(profile_)
439 ->RemoveObserver(this); 470 ->RemoveObserver(this);
440 } 471 }
441 472
442 bool PermissionManager::IsPermissionKillSwitchOn( 473 bool PermissionManager::IsPermissionKillSwitchOn(
443 content::PermissionType permission) { 474 ContentSettingsType permission) {
444 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 475 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
445 return GetPermissionContext(permission)->IsPermissionKillSwitchOn(); 476 return GetPermissionContext(permission)->IsPermissionKillSwitchOn();
446 } 477 }
447 478
448 void PermissionManager::OnContentSettingChanged( 479 void PermissionManager::OnContentSettingChanged(
449 const ContentSettingsPattern& primary_pattern, 480 const ContentSettingsPattern& primary_pattern,
450 const ContentSettingsPattern& secondary_pattern, 481 const ContentSettingsPattern& secondary_pattern,
451 ContentSettingsType content_type, 482 ContentSettingsType content_type,
452 std::string resource_identifier) { 483 std::string resource_identifier) {
453 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 484 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
454 std::list<base::Closure> callbacks; 485 std::list<base::Closure> callbacks;
455 486
456 for (SubscriptionsMap::iterator iter(&subscriptions_); 487 for (SubscriptionsMap::iterator iter(&subscriptions_);
457 !iter.IsAtEnd(); iter.Advance()) { 488 !iter.IsAtEnd(); iter.Advance()) {
458 Subscription* subscription = iter.GetCurrentValue(); 489 Subscription* subscription = iter.GetCurrentValue();
459 if (IsConstantPermission(subscription->permission)) 490 if (IsConstantPermission(subscription->permission))
460 continue; 491 continue;
461 if (PermissionTypeToContentSetting(subscription->permission) != 492 if (PermissionTypeToContentSetting(subscription->permission) !=
462 content_type) { 493 content_type) {
463 continue; 494 continue;
464 } 495 }
465 496
466 if (primary_pattern.IsValid() && 497 if (primary_pattern.IsValid() &&
467 !primary_pattern.Matches(subscription->requesting_origin)) 498 !primary_pattern.Matches(subscription->requesting_origin))
468 continue; 499 continue;
469 if (secondary_pattern.IsValid() && 500 if (secondary_pattern.IsValid() &&
470 !secondary_pattern.Matches(subscription->embedding_origin)) 501 !secondary_pattern.Matches(subscription->embedding_origin))
471 continue; 502 continue;
472 503
473 ContentSetting new_value = GetPermissionStatusInternal( 504 PermissionStatus new_value = GetPermissionStatus(
474 subscription->permission, subscription->requesting_origin, 505 subscription->permission, subscription->requesting_origin,
475 subscription->embedding_origin); 506 subscription->embedding_origin);
476 if (subscription->current_value == new_value) 507 if (subscription->current_value == new_value)
477 continue; 508 continue;
478 509
479 subscription->current_value = new_value; 510 subscription->current_value = new_value;
480 511
481 // Add the callback to |callbacks| which will be run after the loop to 512 // Add the callback to |callbacks| which will be run after the loop to
482 // prevent re-entrance issues. 513 // prevent re-entrance issues.
483 callbacks.push_back( 514 callbacks.push_back(base::Bind(subscription->callback, new_value));
484 base::Bind(subscription->callback,
485 ContentSettingToPermissionStatus(new_value)));
486 } 515 }
487 516
488 for (const auto& callback : callbacks) 517 for (const auto& callback : callbacks)
489 callback.Run(); 518 callback.Run();
490 } 519 }
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