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

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

Issue 1803973002: Content Settings: Add RevocationObserver to measure when permissions are revoked (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 4 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 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> 7 #include <stddef.h>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 11 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
12 #include "chrome/browser/permissions/permission_context.h" 12 #include "chrome/browser/permissions/permission_context.h"
13 #include "chrome/browser/permissions/permission_context_base.h" 13 #include "chrome/browser/permissions/permission_context_base.h"
14 #include "chrome/browser/permissions/permission_request_id.h" 14 #include "chrome/browser/permissions/permission_request_id.h"
15 #include "chrome/browser/permissions/permission_uma_util.h"
16 #include "chrome/browser/permissions/permission_util.h"
15 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/tab_contents/tab_util.h" 18 #include "chrome/browser/tab_contents/tab_util.h"
17 #include "components/content_settings/core/browser/host_content_settings_map.h" 19 #include "components/content_settings/core/browser/host_content_settings_map.h"
18 #include "content/public/browser/permission_type.h" 20 #include "content/public/browser/permission_type.h"
19 #include "content/public/browser/render_frame_host.h" 21 #include "content/public/browser/render_frame_host.h"
20 #include "content/public/browser/render_process_host.h" 22 #include "content/public/browser/render_process_host.h"
21 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
22 24
23 #if !defined(OS_ANDROID) 25 #if !defined(OS_ANDROID)
24 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" 26 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 PermissionType permission; 193 PermissionType permission;
192 GURL requesting_origin; 194 GURL requesting_origin;
193 GURL embedding_origin; 195 GURL embedding_origin;
194 base::Callback<void(PermissionStatus)> callback; 196 base::Callback<void(PermissionStatus)> callback;
195 ContentSetting current_value; 197 ContentSetting current_value;
196 }; 198 };
197 199
198 PermissionManager::PermissionManager(Profile* profile) 200 PermissionManager::PermissionManager(Profile* profile)
199 : profile_(profile), 201 : profile_(profile),
200 weak_ptr_factory_(this) { 202 weak_ptr_factory_(this) {
203 HostContentSettingsMapFactory::GetForProfile(profile_)->AddObserver(this);
201 } 204 }
202 205
203 PermissionManager::~PermissionManager() { 206 PermissionManager::~PermissionManager() {
204 if (!subscriptions_.IsEmpty()) 207 HostContentSettingsMapFactory::GetForProfile(profile_)->RemoveObserver(this);
205 HostContentSettingsMapFactory::GetForProfile(profile_)
206 ->RemoveObserver(this);
207 } 208 }
208 209
209 int PermissionManager::RequestPermission( 210 int PermissionManager::RequestPermission(
210 PermissionType permission, 211 PermissionType permission,
211 content::RenderFrameHost* render_frame_host, 212 content::RenderFrameHost* render_frame_host,
212 const GURL& requesting_origin, 213 const GURL& requesting_origin,
213 const base::Callback<void(PermissionStatus)>& callback) { 214 const base::Callback<void(PermissionStatus)>& callback) {
214 return RequestPermissions( 215 return RequestPermissions(
215 std::vector<PermissionType>(1, permission), 216 std::vector<PermissionType>(1, permission),
216 render_frame_host, 217 render_frame_host,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 requesting_origin, 345 requesting_origin,
345 embedding_origin, 346 embedding_origin,
346 PermissionTypeToContentSetting(permission)); 347 PermissionTypeToContentSetting(permission));
347 } 348 }
348 349
349 int PermissionManager::SubscribePermissionStatusChange( 350 int PermissionManager::SubscribePermissionStatusChange(
350 PermissionType permission, 351 PermissionType permission,
351 const GURL& requesting_origin, 352 const GURL& requesting_origin,
352 const GURL& embedding_origin, 353 const GURL& embedding_origin,
353 const base::Callback<void(PermissionStatus)>& callback) { 354 const base::Callback<void(PermissionStatus)>& callback) {
354 if (subscriptions_.IsEmpty())
355 HostContentSettingsMapFactory::GetForProfile(profile_)->AddObserver(this);
356 355
357 Subscription* subscription = new Subscription(); 356 Subscription* subscription = new Subscription();
358 subscription->permission = permission; 357 subscription->permission = permission;
359 subscription->requesting_origin = requesting_origin; 358 subscription->requesting_origin = requesting_origin;
360 subscription->embedding_origin = embedding_origin; 359 subscription->embedding_origin = embedding_origin;
361 subscription->callback = callback; 360 subscription->callback = callback;
362 361
363 if (IsConstantPermission(permission)) { 362 if (IsConstantPermission(permission)) {
364 subscription->current_value = GetContentSettingForConstantPermission( 363 subscription->current_value = GetContentSettingForConstantPermission(
365 permission); 364 permission);
366 } else { 365 } else {
367 subscription->current_value = PermissionContext::Get(profile_, permission) 366 subscription->current_value = PermissionContext::Get(profile_, permission)
368 ->GetPermissionStatus(subscription->requesting_origin, 367 ->GetPermissionStatus(subscription->requesting_origin,
369 subscription->embedding_origin); 368 subscription->embedding_origin);
370 } 369 }
371 370
372 return subscriptions_.Add(subscription); 371 return subscriptions_.Add(subscription);
373 } 372 }
374 373
375 void PermissionManager::UnsubscribePermissionStatusChange(int subscription_id) { 374 void PermissionManager::UnsubscribePermissionStatusChange(int subscription_id) {
376 // Whether |subscription_id| is known will be checked by the Remove() call. 375 // Whether |subscription_id| is known will be checked by the Remove() call.
377 subscriptions_.Remove(subscription_id); 376 subscriptions_.Remove(subscription_id);
378
379 if (subscriptions_.IsEmpty())
380 HostContentSettingsMapFactory::GetForProfile(profile_)
381 ->RemoveObserver(this);
382 } 377 }
383 378
384 bool PermissionManager::IsPermissionBubbleManagerMissing( 379 bool PermissionManager::IsPermissionBubbleManagerMissing(
385 content::WebContents* web_contents) { 380 content::WebContents* web_contents) {
386 // TODO(felt): Remove this method entirely. Leaving it to make a minimal 381 // TODO(felt): Remove this method entirely. Leaving it to make a minimal
387 // last-minute merge to 46. See crbug.com/457091 and crbug.com/534631. 382 // last-minute merge to 46. See crbug.com/457091 and crbug.com/534631.
388 return false; 383 return false;
389 } 384 }
390 385
391 void PermissionManager::OnContentSettingChanged( 386 void PermissionManager::OnContentSettingChanged(
(...skipping 30 matching lines...) Expand all
422 // Add the callback to |callbacks| which will be run after the loop to 417 // Add the callback to |callbacks| which will be run after the loop to
423 // prevent re-entrance issues. 418 // prevent re-entrance issues.
424 callbacks.push_back( 419 callbacks.push_back(
425 base::Bind(subscription->callback, 420 base::Bind(subscription->callback,
426 ContentSettingToPermissionStatus(new_value))); 421 ContentSettingToPermissionStatus(new_value)));
427 } 422 }
428 423
429 for (const auto& callback : callbacks) 424 for (const auto& callback : callbacks)
430 callback.Run(); 425 callback.Run();
431 } 426 }
427
428 void PermissionManager::OnContentSettingRevoked(
429 const GURL& primary_url,
430 const GURL& secondary_url,
431 ContentSettingsType content_type,
432 std::string resource_identifier) {
433 PermissionType permission_type;
434 if (PermissionUtil::GetPermissionType(content_type, &permission_type))
435 PermissionUmaUtil::PermissionRevoked(permission_type, primary_url);
436 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698