-
Notifications
You must be signed in to change notification settings - Fork 889
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clear shields settings via clear browsing data dialog
So far, shields settings are also cleard with "All time" time range. With "All time" range option, browser nuke whole plugins type data. With non "All time" range option, browser only clears plugins type for empty resource ids which is flash type. This commit makes browser clear shields data also with non "All time" range.
- Loading branch information
Showing
20 changed files
with
381 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
source_set("browsing_data") { | ||
sources = [ | ||
"brave_clear_browsing_data.cc", | ||
"brave_clear_browsing_data.h", | ||
"counters/brave_site_settings_counter.cc", | ||
"counters/brave_site_settings_counter.h", | ||
] | ||
|
||
deps = [ | ||
"//base", | ||
"//chrome/common", | ||
"//content/public/browser", | ||
"//components/browsing_data/core", | ||
"//components/content_settings/core/browser", | ||
"//components/content_settings/core/common", | ||
"//components/prefs", | ||
] | ||
} |
77 changes: 77 additions & 0 deletions
77
browser/browsing_data/counters/brave_site_settings_counter.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/browsing_data/counters/brave_site_settings_counter.h" | ||
|
||
#include <set> | ||
#include <string> | ||
|
||
#include "brave/components/content_settings/core/browser/brave_content_settings_utils.h" | ||
#include "components/browsing_data/core/pref_names.h" | ||
#include "components/content_settings/core/browser/content_settings_registry.h" | ||
#include "components/content_settings/core/common/content_settings_pattern.h" | ||
|
||
BraveSiteSettingsCounter::BraveSiteSettingsCounter( | ||
HostContentSettingsMap* map, | ||
content::HostZoomMap* zoom_map, | ||
ProtocolHandlerRegistry* handler_registry, | ||
PrefService* pref_service) | ||
: SiteSettingsCounter(map, zoom_map, handler_registry, pref_service) { | ||
map_ = static_cast<BraveHostContentSettingsMap*>(map); | ||
} | ||
|
||
BraveSiteSettingsCounter::~BraveSiteSettingsCounter() = default; | ||
|
||
int BraveSiteSettingsCounter::CountShieldsSettings() { | ||
std::set<std::string> hosts; | ||
int empty_host_pattern = 0; | ||
base::Time period_start = GetPeriodStart(); | ||
base::Time period_end = GetPeriodEnd(); | ||
|
||
auto iterate_content_settings_list = | ||
[&](ContentSettingsType content_type, | ||
const ContentSettingsForOneType& content_settings_list, | ||
const std::string& resource_identifier) { | ||
for (const auto& content_setting : content_settings_list) { | ||
// We don't care other source except preference because all shields | ||
// settings are stored in pref storage. | ||
if (content_setting.source != "preference") | ||
continue; | ||
|
||
base::Time last_modified; | ||
DCHECK_EQ(ContentSettingsType::PLUGINS, content_type); | ||
// Fetching last time for specific resource ids. | ||
last_modified = map_->GetShieldsSettingLastModifiedDate( | ||
content_setting.primary_pattern, | ||
content_setting.secondary_pattern, | ||
resource_identifier); | ||
if (last_modified >= period_start && last_modified < period_end) { | ||
if (content_setting.primary_pattern.GetHost().empty()) | ||
empty_host_pattern++; | ||
else | ||
hosts.insert(content_setting.primary_pattern.GetHost()); | ||
} | ||
} | ||
}; | ||
|
||
auto* registry = content_settings::ContentSettingsRegistry::GetInstance(); | ||
for (const content_settings::ContentSettingsInfo* info : *registry) { | ||
ContentSettingsType type = info->website_settings_info()->type(); | ||
ContentSettingsForOneType content_settings_list; | ||
if (type == ContentSettingsType::PLUGINS) { | ||
for (const auto& id : content_settings::GetShieldsResourceIDs()) { | ||
map_->GetSettingsForOneType(type, id, &content_settings_list); | ||
iterate_content_settings_list(type, content_settings_list, id); | ||
} | ||
continue; | ||
} | ||
} | ||
|
||
return hosts.size() + empty_host_pattern; | ||
} | ||
|
||
void BraveSiteSettingsCounter::ReportResult(ResultInt value) { | ||
SiteSettingsCounter::ReportResult(value + CountShieldsSettings()); | ||
} |
32 changes: 32 additions & 0 deletions
32
browser/browsing_data/counters/brave_site_settings_counter.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_BROWSER_BROWSING_DATA_COUNTERS_BRAVE_SITE_SETTINGS_COUNTER_H_ | ||
#define BRAVE_BROWSER_BROWSING_DATA_COUNTERS_BRAVE_SITE_SETTINGS_COUNTER_H_ | ||
|
||
#include "brave/components/content_settings/core/browser/brave_host_content_settings_map.h" | ||
#include "chrome/browser/browsing_data/counters/site_settings_counter.h" | ||
|
||
// This class adds shieldss settings count | ||
class BraveSiteSettingsCounter : public SiteSettingsCounter { | ||
public: | ||
BraveSiteSettingsCounter(HostContentSettingsMap* map, | ||
content::HostZoomMap* zoom_map, | ||
ProtocolHandlerRegistry* handler_registry, | ||
PrefService* pref_service); | ||
~BraveSiteSettingsCounter() override; | ||
BraveSiteSettingsCounter(const BraveSiteSettingsCounter&) = delete; | ||
BraveSiteSettingsCounter& operator=(const BraveSiteSettingsCounter&) = delete; | ||
|
||
private: | ||
// SiteSettingsCounter overrides: | ||
void ReportResult(ResultInt value) override; | ||
|
||
int CountShieldsSettings(); | ||
|
||
scoped_refptr<BraveHostContentSettingsMap> map_; | ||
}; | ||
|
||
#endif // BRAVE_BROWSER_BROWSING_DATA_COUNTERS_BRAVE_SITE_SETTINGS_COUNTER_H_ |
14 changes: 14 additions & 0 deletions
14
chromium_src/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/components/content_settings/core/browser/brave_host_content_settings_map.h" | ||
#include "components/content_settings/core/browser/content_settings_info.h" | ||
#include "components/content_settings/core/browser/website_settings_info.h" | ||
|
||
#define CLEAR_SHIELDS_SETTINGS \ | ||
static_cast<BraveHostContentSettingsMap*>(host_content_settings_map_)-> \ | ||
ClearSettingsForPluginsType(delete_begin_, delete_end_); | ||
#include "../../../../../chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc" | ||
#undef CLEAR_SHIELDS_SETTINGS |
10 changes: 10 additions & 0 deletions
10
chromium_src/chrome/browser/browsing_data/counters/browsing_data_counter_factory.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/browsing_data/counters/brave_site_settings_counter.h" | ||
|
||
#define SiteSettingsCounter BraveSiteSettingsCounter | ||
#include "../../../../../../chrome/browser/browsing_data/counters/browsing_data_counter_factory.cc" // NOLINT | ||
#undef SiteSettingsCounter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
chromium_src/components/browsing_data/core/counters/browsing_data_counter.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_BROWSING_DATA_CORE_COUNTERS_BROWSING_DATA_COUNTER_H_ | ||
#define BRAVE_CHROMIUM_SRC_COMPONENTS_BROWSING_DATA_CORE_COUNTERS_BROWSING_DATA_COUNTER_H_ | ||
|
||
#define ReportResult virtual ReportResult | ||
#include "../../../../../../components/browsing_data/core/counters/browsing_data_counter.h" | ||
#undef ReportResult | ||
|
||
#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_BROWSING_DATA_CORE_COUNTERS_BROWSING_DATA_COUNTER_H_ |
17 changes: 17 additions & 0 deletions
17
chromium_src/components/content_settings/core/browser/host_content_settings_map.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_HOST_CONTENT_SETTINGS_MAP_H_ | ||
#define BRAVE_CHROMIUM_SRC_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_HOST_CONTENT_SETTINGS_MAP_H_ | ||
|
||
#define BRAVE_HOST_CONTENT_SETTINGS_MAP_H \ | ||
private: \ | ||
friend class BraveHostContentSettingsMap; | ||
|
||
#include "../../../../../../components/content_settings/core/browser/host_content_settings_map.h" | ||
|
||
#undef BRAVE_HOST_CONTENT_SETTINGS_MAP_H | ||
|
||
#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_HOST_CONTENT_SETTINGS_MAP_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
components/content_settings/core/browser/brave_content_settings_utils.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/components/content_settings/core/browser/brave_content_settings_utils.h" | ||
|
||
#include <algorithm> | ||
|
||
#include "brave/components/brave_shields/common/brave_shield_constants.h" | ||
|
||
namespace { | ||
|
||
const std::vector<std::string> kShieldsResourceIDs { | ||
brave_shields::kAds, | ||
brave_shields::kTrackers, | ||
brave_shields::kHTTPUpgradableResources, | ||
brave_shields::kJavaScript, | ||
brave_shields::kFingerprinting, | ||
brave_shields::kBraveShields, | ||
brave_shields::kReferrers, | ||
brave_shields::kCookies }; | ||
|
||
} // namespace | ||
|
||
namespace content_settings { | ||
|
||
const std::vector<std::string>& GetShieldsResourceIDs() { | ||
return kShieldsResourceIDs; | ||
} | ||
|
||
bool IsShieldsResourceID( | ||
const content_settings::ResourceIdentifier& resource_identifier) { | ||
return std::find(kShieldsResourceIDs.begin(), | ||
kShieldsResourceIDs.end(), | ||
resource_identifier) != kShieldsResourceIDs.end(); | ||
} | ||
|
||
} // namespace content_settings |
22 changes: 22 additions & 0 deletions
22
components/content_settings/core/browser/brave_content_settings_utils.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_BRAVE_CONTENT_SETTINGS_UTILS_H_ | ||
#define BRAVE_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_BRAVE_CONTENT_SETTINGS_UTILS_H_ | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "components/content_settings/core/common/content_settings.h" | ||
|
||
namespace content_settings { | ||
|
||
const std::vector<std::string>& GetShieldsResourceIDs(); | ||
|
||
bool IsShieldsResourceID(const ResourceIdentifier& resource_identifier); | ||
|
||
} // namespace content_settings | ||
|
||
#endif // BRAVE_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_BRAVE_CONTENT_SETTINGS_UTILS_H_ |
50 changes: 50 additions & 0 deletions
50
components/content_settings/core/browser/brave_host_content_settings_map.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/components/content_settings/core/browser/brave_host_content_settings_map.h" | ||
#include "brave/components/content_settings/core/browser/brave_content_settings_pref_provider.h" | ||
#include "brave/components/content_settings/core/browser/brave_content_settings_utils.h" | ||
|
||
base::Time BraveHostContentSettingsMap::GetShieldsSettingLastModifiedDate( | ||
const ContentSettingsPattern& primary_pattern, | ||
const ContentSettingsPattern& secondary_pattern, | ||
const std::string& resource_identifier) const { | ||
return GetPrefProvider()->GetWebsiteSettingLastModified( | ||
primary_pattern, secondary_pattern, | ||
ContentSettingsType::PLUGINS, resource_identifier); | ||
} | ||
|
||
void BraveHostContentSettingsMap::ClearSettingsForPluginsType() { | ||
static_cast<content_settings::BravePrefProvider*>(GetPrefProvider())-> | ||
ClearAllShieldsContentSettings(); | ||
FlushLossyWebsiteSettings(); | ||
} | ||
|
||
void BraveHostContentSettingsMap::ClearSettingsForPluginsType( | ||
base::Time begin_time, | ||
base::Time end_time) { | ||
if (begin_time.is_null() && (end_time.is_null() || end_time.is_max())) { | ||
ClearSettingsForPluginsType(); | ||
return; | ||
} | ||
|
||
auto* provider = GetPrefProvider(); | ||
for (const auto& resource_id : content_settings::GetShieldsResourceIDs()) { | ||
ContentSettingsForOneType settings; | ||
ContentSettingsType content_type = ContentSettingsType::PLUGINS; | ||
GetSettingsForOneType(content_type, resource_id, &settings); | ||
for (const ContentSettingPatternSource& setting : settings) { | ||
base::Time last_modified = provider->GetWebsiteSettingLastModified( | ||
setting.primary_pattern, setting.secondary_pattern, content_type, | ||
resource_id); | ||
if (last_modified >= begin_time && | ||
(last_modified < end_time || end_time.is_null())) { | ||
provider->SetWebsiteSetting(setting.primary_pattern, | ||
setting.secondary_pattern, content_type, | ||
resource_id, nullptr); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.