Skip to content

Commit a85a399

Browse files
committed
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.
1 parent b2d46a5 commit a85a399

20 files changed

+381
-27
lines changed

browser/BUILD.gn

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ source_set("browser_process") {
5656
"brave_tab_helpers.h",
5757
"browser_context_keyed_service_factories.cc",
5858
"browser_context_keyed_service_factories.h",
59-
"browsing_data/brave_clear_browsing_data.cc",
60-
"browsing_data/brave_clear_browsing_data.h",
6159
"component_updater/brave_component_installer.cc",
6260
"component_updater/brave_component_installer.h",
6361
"component_updater/brave_component_updater_configurator.cc",
@@ -165,6 +163,7 @@ source_set("browser_process") {
165163
"//content/public/common",
166164
"//extensions/buildflags",
167165
"//brave/chromium_src:browser",
166+
"browsing_data",
168167
"themes",
169168
"ntp_sponsored_images",
170169
"//services/network/public/cpp",

browser/browsing_data/BUILD.gn

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
source_set("browsing_data") {
2+
sources = [
3+
"brave_clear_browsing_data.cc",
4+
"brave_clear_browsing_data.h",
5+
"counters/brave_site_settings_counter.cc",
6+
"counters/brave_site_settings_counter.h",
7+
]
8+
9+
deps = [
10+
"//base",
11+
"//chrome/common",
12+
"//content/public/browser",
13+
"//components/browsing_data/core",
14+
"//components/content_settings/core/browser",
15+
"//components/content_settings/core/common",
16+
"//components/prefs",
17+
]
18+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
#include "brave/browser/browsing_data/counters/brave_site_settings_counter.h"
7+
8+
#include <set>
9+
#include <string>
10+
11+
#include "brave/components/content_settings/core/browser/brave_content_settings_utils.h"
12+
#include "components/browsing_data/core/pref_names.h"
13+
#include "components/content_settings/core/browser/content_settings_registry.h"
14+
#include "components/content_settings/core/common/content_settings_pattern.h"
15+
16+
BraveSiteSettingsCounter::BraveSiteSettingsCounter(
17+
HostContentSettingsMap* map,
18+
content::HostZoomMap* zoom_map,
19+
ProtocolHandlerRegistry* handler_registry,
20+
PrefService* pref_service)
21+
: SiteSettingsCounter(map, zoom_map, handler_registry, pref_service) {
22+
map_ = static_cast<BraveHostContentSettingsMap*>(map);
23+
}
24+
25+
BraveSiteSettingsCounter::~BraveSiteSettingsCounter() = default;
26+
27+
int BraveSiteSettingsCounter::CountShieldsSettings() {
28+
std::set<std::string> hosts;
29+
int empty_host_pattern = 0;
30+
base::Time period_start = GetPeriodStart();
31+
base::Time period_end = GetPeriodEnd();
32+
33+
auto iterate_content_settings_list =
34+
[&](ContentSettingsType content_type,
35+
const ContentSettingsForOneType& content_settings_list,
36+
const std::string& resource_identifier) {
37+
for (const auto& content_setting : content_settings_list) {
38+
// We don't care other source except preference because all shields
39+
// settings are stored in pref storage.
40+
if (content_setting.source != "preference")
41+
continue;
42+
43+
base::Time last_modified;
44+
DCHECK_EQ(ContentSettingsType::PLUGINS, content_type);
45+
// Fetching last time for specific resource ids.
46+
last_modified = map_->GetShieldsSettingLastModifiedDate(
47+
content_setting.primary_pattern,
48+
content_setting.secondary_pattern,
49+
resource_identifier);
50+
if (last_modified >= period_start && last_modified < period_end) {
51+
if (content_setting.primary_pattern.GetHost().empty())
52+
empty_host_pattern++;
53+
else
54+
hosts.insert(content_setting.primary_pattern.GetHost());
55+
}
56+
}
57+
};
58+
59+
auto* registry = content_settings::ContentSettingsRegistry::GetInstance();
60+
for (const content_settings::ContentSettingsInfo* info : *registry) {
61+
ContentSettingsType type = info->website_settings_info()->type();
62+
ContentSettingsForOneType content_settings_list;
63+
if (type == ContentSettingsType::PLUGINS) {
64+
for (const auto& id : content_settings::GetShieldsResourceIDs()) {
65+
map_->GetSettingsForOneType(type, id, &content_settings_list);
66+
iterate_content_settings_list(type, content_settings_list, id);
67+
}
68+
continue;
69+
}
70+
}
71+
72+
return hosts.size() + empty_host_pattern;
73+
}
74+
75+
void BraveSiteSettingsCounter::ReportResult(ResultInt value) {
76+
SiteSettingsCounter::ReportResult(value + CountShieldsSettings());
77+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
#ifndef BRAVE_BROWSER_BROWSING_DATA_COUNTERS_BRAVE_SITE_SETTINGS_COUNTER_H_
7+
#define BRAVE_BROWSER_BROWSING_DATA_COUNTERS_BRAVE_SITE_SETTINGS_COUNTER_H_
8+
9+
#include "brave/components/content_settings/core/browser/brave_host_content_settings_map.h"
10+
#include "chrome/browser/browsing_data/counters/site_settings_counter.h"
11+
12+
// This class adds shieldss settings count
13+
class BraveSiteSettingsCounter : public SiteSettingsCounter {
14+
public:
15+
BraveSiteSettingsCounter(HostContentSettingsMap* map,
16+
content::HostZoomMap* zoom_map,
17+
ProtocolHandlerRegistry* handler_registry,
18+
PrefService* pref_service);
19+
~BraveSiteSettingsCounter() override;
20+
BraveSiteSettingsCounter(const BraveSiteSettingsCounter&) = delete;
21+
BraveSiteSettingsCounter& operator=(const BraveSiteSettingsCounter&) = delete;
22+
23+
private:
24+
// SiteSettingsCounter overrides:
25+
void ReportResult(ResultInt value) override;
26+
27+
int CountShieldsSettings();
28+
29+
scoped_refptr<BraveHostContentSettingsMap> map_;
30+
};
31+
32+
#endif // BRAVE_BROWSER_BROWSING_DATA_COUNTERS_BRAVE_SITE_SETTINGS_COUNTER_H_
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
#include "brave/components/content_settings/core/browser/brave_host_content_settings_map.h"
7+
#include "components/content_settings/core/browser/content_settings_info.h"
8+
#include "components/content_settings/core/browser/website_settings_info.h"
9+
10+
#define CLEAR_SHIELDS_SETTINGS \
11+
static_cast<BraveHostContentSettingsMap*>(host_content_settings_map_)-> \
12+
ClearSettingsForPluginsType(delete_begin_, delete_end_);
13+
#include "../../../../../chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc"
14+
#undef CLEAR_SHIELDS_SETTINGS
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
#include "brave/browser/browsing_data/counters/brave_site_settings_counter.h"
7+
8+
#define SiteSettingsCounter BraveSiteSettingsCounter
9+
#include "../../../../../../chrome/browser/browsing_data/counters/browsing_data_counter_factory.cc" // NOLINT
10+
#undef SiteSettingsCounter

chromium_src/chrome/browser/content_settings/host_content_settings_map_factory.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* You can obtain one at http://mozilla.org/MPL/2.0/. */
55

66
#include "brave/browser/profiles/profile_util.h"
7+
#include "brave/components/content_settings/core/browser/brave_host_content_settings_map.h"
78

89
#define BRAVE_BUILD_SERVICE_INSTANCE_FOR brave::IsSessionProfile(profile) ||
9-
#include "../../../../../chrome/browser/content_settings/host_content_settings_map_factory.cc"
10+
#include "../../../../../chrome/browser/content_settings/host_content_settings_map_factory.cc" // NOLINT
11+
#undef BRAVE_BUILD_SERVICE_INSTANCE_FOR
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_BROWSING_DATA_CORE_COUNTERS_BROWSING_DATA_COUNTER_H_
7+
#define BRAVE_CHROMIUM_SRC_COMPONENTS_BROWSING_DATA_CORE_COUNTERS_BROWSING_DATA_COUNTER_H_
8+
9+
#define ReportResult virtual ReportResult
10+
#include "../../../../../../components/browsing_data/core/counters/browsing_data_counter.h"
11+
#undef ReportResult
12+
13+
#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_BROWSING_DATA_CORE_COUNTERS_BROWSING_DATA_COUNTER_H_
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_HOST_CONTENT_SETTINGS_MAP_H_
7+
#define BRAVE_CHROMIUM_SRC_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_HOST_CONTENT_SETTINGS_MAP_H_
8+
9+
#define BRAVE_HOST_CONTENT_SETTINGS_MAP_H \
10+
private: \
11+
friend class BraveHostContentSettingsMap;
12+
13+
#include "../../../../../../components/content_settings/core/browser/host_content_settings_map.h"
14+
15+
#undef BRAVE_HOST_CONTENT_SETTINGS_MAP_H
16+
17+
#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_HOST_CONTENT_SETTINGS_MAP_H_

components/content_settings/core/browser/BUILD.gn

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ source_set("browser") {
55
"brave_content_settings_ephemeral_provider.h",
66
"brave_content_settings_pref_provider.cc",
77
"brave_content_settings_pref_provider.h",
8+
"brave_content_settings_utils.cc",
9+
"brave_content_settings_utils.h",
10+
"brave_host_content_settings_map.cc",
11+
"brave_host_content_settings_map.h",
812
]
913

1014
deps = [

components/content_settings/core/browser/brave_content_settings_ephemeral_provider.cc

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,7 @@
88
#include <memory>
99
#include <utility>
1010

11-
#include "brave/components/brave_shields/common/brave_shield_constants.h"
12-
13-
namespace {
14-
15-
bool IsShieldsResourceID(
16-
const content_settings::ResourceIdentifier& resource_identifier) {
17-
if (resource_identifier == brave_shields::kAds ||
18-
resource_identifier == brave_shields::kTrackers ||
19-
resource_identifier == brave_shields::kHTTPUpgradableResources ||
20-
resource_identifier == brave_shields::kJavaScript ||
21-
resource_identifier == brave_shields::kFingerprinting ||
22-
resource_identifier == brave_shields::kBraveShields ||
23-
resource_identifier == brave_shields::kReferrers ||
24-
resource_identifier == brave_shields::kCookies) {
25-
return true;
26-
} else {
27-
return false;
28-
}
29-
}
30-
31-
} // namespace
11+
#include "brave/components/content_settings/core/browser/brave_content_settings_utils.h"
3212

3313
namespace content_settings {
3414

components/content_settings/core/browser/brave_content_settings_pref_provider.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ std::unique_ptr<RuleIterator> BravePrefProvider::GetRuleIterator(
192192
cookie_rules_.at(incognito).end());
193193
}
194194

195+
// Earyl return. We don't store flash plugin setting in preference.
196+
if (content_type == ContentSettingsType::PLUGINS &&
197+
resource_identifier == "")
198+
return nullptr;
199+
195200
return PrefProvider::GetRuleIterator(content_type,
196201
resource_identifier,
197202
incognito);
@@ -359,4 +364,9 @@ void BravePrefProvider::OnContentSettingChanged(
359364
}
360365
}
361366

367+
void BravePrefProvider::ClearAllShieldsContentSettings() {
368+
DCHECK(CalledOnValidThread());
369+
GetPref(ContentSettingsType::PLUGINS)->ClearAllContentSettingsRules();
370+
}
371+
362372
} // namespace content_settings

components/content_settings/core/browser/brave_content_settings_pref_provider.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class BravePrefProvider : public PrefProvider,
4646
const ResourceIdentifier& resource_identifier,
4747
bool incognito) const override;
4848

49+
void ClearAllShieldsContentSettings();
50+
4951
private:
5052
void UpdateCookieRules(ContentSettingsType content_type, bool incognito);
5153
void OnCookieSettingsChanged(ContentSettingsType content_type);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
#include "brave/components/content_settings/core/browser/brave_content_settings_utils.h"
7+
8+
#include <algorithm>
9+
10+
#include "brave/components/brave_shields/common/brave_shield_constants.h"
11+
12+
namespace {
13+
14+
const std::vector<std::string> kShieldsResourceIDs {
15+
brave_shields::kAds,
16+
brave_shields::kTrackers,
17+
brave_shields::kHTTPUpgradableResources,
18+
brave_shields::kJavaScript,
19+
brave_shields::kFingerprinting,
20+
brave_shields::kBraveShields,
21+
brave_shields::kReferrers,
22+
brave_shields::kCookies };
23+
24+
} // namespace
25+
26+
namespace content_settings {
27+
28+
const std::vector<std::string>& GetShieldsResourceIDs() {
29+
return kShieldsResourceIDs;
30+
}
31+
32+
bool IsShieldsResourceID(
33+
const content_settings::ResourceIdentifier& resource_identifier) {
34+
return std::find(kShieldsResourceIDs.begin(),
35+
kShieldsResourceIDs.end(),
36+
resource_identifier) != kShieldsResourceIDs.end();
37+
}
38+
39+
} // namespace content_settings
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
#ifndef BRAVE_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_BRAVE_CONTENT_SETTINGS_UTILS_H_
7+
#define BRAVE_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_BRAVE_CONTENT_SETTINGS_UTILS_H_
8+
9+
#include <string>
10+
#include <vector>
11+
12+
#include "components/content_settings/core/common/content_settings.h"
13+
14+
namespace content_settings {
15+
16+
const std::vector<std::string>& GetShieldsResourceIDs();
17+
18+
bool IsShieldsResourceID(const ResourceIdentifier& resource_identifier);
19+
20+
} // namespace content_settings
21+
22+
#endif // BRAVE_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_BRAVE_CONTENT_SETTINGS_UTILS_H_
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
#include "brave/components/content_settings/core/browser/brave_host_content_settings_map.h"
7+
#include "brave/components/content_settings/core/browser/brave_content_settings_pref_provider.h"
8+
#include "brave/components/content_settings/core/browser/brave_content_settings_utils.h"
9+
10+
base::Time BraveHostContentSettingsMap::GetShieldsSettingLastModifiedDate(
11+
const ContentSettingsPattern& primary_pattern,
12+
const ContentSettingsPattern& secondary_pattern,
13+
const std::string& resource_identifier) const {
14+
return GetPrefProvider()->GetWebsiteSettingLastModified(
15+
primary_pattern, secondary_pattern,
16+
ContentSettingsType::PLUGINS, resource_identifier);
17+
}
18+
19+
void BraveHostContentSettingsMap::ClearSettingsForPluginsType() {
20+
static_cast<content_settings::BravePrefProvider*>(GetPrefProvider())->
21+
ClearAllShieldsContentSettings();
22+
FlushLossyWebsiteSettings();
23+
}
24+
25+
void BraveHostContentSettingsMap::ClearSettingsForPluginsType(
26+
base::Time begin_time,
27+
base::Time end_time) {
28+
if (begin_time.is_null() && (end_time.is_null() || end_time.is_max())) {
29+
ClearSettingsForPluginsType();
30+
return;
31+
}
32+
33+
auto* provider = GetPrefProvider();
34+
for (const auto& resource_id : content_settings::GetShieldsResourceIDs()) {
35+
ContentSettingsForOneType settings;
36+
ContentSettingsType content_type = ContentSettingsType::PLUGINS;
37+
GetSettingsForOneType(content_type, resource_id, &settings);
38+
for (const ContentSettingPatternSource& setting : settings) {
39+
base::Time last_modified = provider->GetWebsiteSettingLastModified(
40+
setting.primary_pattern, setting.secondary_pattern, content_type,
41+
resource_id);
42+
if (last_modified >= begin_time &&
43+
(last_modified < end_time || end_time.is_null())) {
44+
provider->SetWebsiteSetting(setting.primary_pattern,
45+
setting.secondary_pattern, content_type,
46+
resource_id, nullptr);
47+
}
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)