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

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

Issue 2790473004: Permissions: Clear embargo if user changes an embargoed permission's setting. (Closed)
Patch Set: Hook up for permissions on Android. Created 3 years, 8 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_decision_auto_blocker.h" 5 #include "chrome/browser/permissions/permission_decision_auto_blocker.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/feature_list.h" 9 #include "base/feature_list.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 14 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
15 #include "chrome/browser/permissions/permission_blacklist_client.h" 15 #include "chrome/browser/permissions/permission_blacklist_client.h"
16 #include "chrome/browser/permissions/permission_manager.h"
16 #include "chrome/browser/permissions/permission_util.h" 17 #include "chrome/browser/permissions/permission_util.h"
17 #include "chrome/browser/profiles/incognito_helpers.h" 18 #include "chrome/browser/profiles/incognito_helpers.h"
18 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 20 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
20 #include "chrome/common/chrome_features.h" 21 #include "chrome/common/chrome_features.h"
21 #include "components/content_settings/core/browser/host_content_settings_map.h" 22 #include "components/content_settings/core/browser/host_content_settings_map.h"
22 #include "components/keyed_service/content/browser_context_dependency_manager.h" 23 #include "components/keyed_service/content/browser_context_dependency_manager.h"
23 #include "components/safe_browsing_db/database_manager.h" 24 #include "components/safe_browsing_db/database_manager.h"
24 #include "components/variations/variations_associated_data.h" 25 #include "components/variations/variations_associated_data.h"
25 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 return false; 298 return false;
298 } 299 }
299 300
300 int PermissionDecisionAutoBlocker::RecordIgnore( 301 int PermissionDecisionAutoBlocker::RecordIgnore(
301 const GURL& url, 302 const GURL& url,
302 ContentSettingsType permission) { 303 ContentSettingsType permission) {
303 return RecordActionInWebsiteSettings(url, permission, kPromptIgnoreCountKey, 304 return RecordActionInWebsiteSettings(url, permission, kPromptIgnoreCountKey,
304 profile_); 305 profile_);
305 } 306 }
306 307
308 void PermissionDecisionAutoBlocker::RemoveEmbargoByUrl(
309 const GURL& origin_url,
310 const GURL& embedder_url,
311 ContentSettingsType permission) {
312 if (!PermissionUtil::IsPermission(permission))
313 return;
314
315 // Don't proceed if |permission| was not under embargo for |origin_url|.
316 PermissionResult permission_result =
317 PermissionManager::Get(profile_)->GetPermissionStatus(
dominickn 2017/04/05 08:50:19 Instead of calling PermissionManager (and thus req
Patti Lor 2017/04/06 02:14:02 Done, thanks Dom :)
318 permission, origin_url, embedder_url);
319 switch (permission_result.source) {
dominickn 2017/04/05 08:50:19 I think it's clearer to just do if (result.source
Patti Lor 2017/04/06 02:14:02 Done.
320 case PermissionStatusSource::MULTIPLE_DISMISSALS:
321 case PermissionStatusSource::SAFE_BROWSING_BLACKLIST:
322 break;
323 default:
324 return;
325 }
326
327 HostContentSettingsMap* map =
328 HostContentSettingsMapFactory::GetForProfile(profile_);
329 std::unique_ptr<base::DictionaryValue> dict = GetOriginDict(map, origin_url);
330 base::DictionaryValue* permission_dict = GetOrCreatePermissionDict(
331 dict.get(), PermissionUtil::GetPermissionString(permission));
332
333 // Deleting non-existent entries will return a false value. Since it should be
334 // impossible for a permission to have been embargoed for two different
335 // reasons at the same time, check that exactly one deletion was successful.
336 const bool dismissal_key_deleted =
337 permission_dict->RemoveWithoutPathExpansion(
338 kPermissionDismissalEmbargoKey, nullptr);
339 const bool blacklist_key_deleted =
340 permission_dict->RemoveWithoutPathExpansion(
341 kPermissionBlacklistEmbargoKey, nullptr);
342 DCHECK(dismissal_key_deleted != blacklist_key_deleted);
343
344 map->SetWebsiteSettingDefaultScope(
345 origin_url, GURL(), CONTENT_SETTINGS_TYPE_PERMISSION_AUTOBLOCKER_DATA,
346 std::string(), std::move(dict));
347 }
348
307 void PermissionDecisionAutoBlocker::RemoveCountsByUrl( 349 void PermissionDecisionAutoBlocker::RemoveCountsByUrl(
308 base::Callback<bool(const GURL& url)> filter) { 350 base::Callback<bool(const GURL& url)> filter) {
309 HostContentSettingsMap* map = 351 HostContentSettingsMap* map =
310 HostContentSettingsMapFactory::GetForProfile(profile_); 352 HostContentSettingsMapFactory::GetForProfile(profile_);
311 353
312 std::unique_ptr<ContentSettingsForOneType> settings( 354 std::unique_ptr<ContentSettingsForOneType> settings(
313 new ContentSettingsForOneType); 355 new ContentSettingsForOneType);
314 map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_PERMISSION_AUTOBLOCKER_DATA, 356 map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_PERMISSION_AUTOBLOCKER_DATA,
315 std::string(), settings.get()); 357 std::string(), settings.get());
316 358
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, 415 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager,
374 int timeout) { 416 int timeout) {
375 db_manager_ = db_manager; 417 db_manager_ = db_manager;
376 safe_browsing_timeout_ = timeout; 418 safe_browsing_timeout_ = timeout;
377 } 419 }
378 420
379 void PermissionDecisionAutoBlocker::SetClockForTesting( 421 void PermissionDecisionAutoBlocker::SetClockForTesting(
380 std::unique_ptr<base::Clock> clock) { 422 std::unique_ptr<base::Clock> clock) {
381 clock_ = std::move(clock); 423 clock_ = std::move(clock);
382 } 424 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698