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

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

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

Powered by Google App Engine
This is Rietveld 408576698