-
Notifications
You must be signed in to change notification settings - Fork 868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make shields settings persist #558
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
811d060
Add ShieldSettingsPersistTest
simonhong 582f2a2
Makes shields configuration persist across sesstions
simonhong b5d769b
Add more test to check flash configuration isn't persisted
simonhong e652fc6
Add more DCHECKs to BraveEphemeralProvider
simonhong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 12 additions & 0 deletions
12
chromium_src/components/content_settings/core/browser/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,12 @@ | ||
/* 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_ephemeral_provider.h" | ||
#include "brave/components/content_settings/core/browser/brave_content_settings_pref_provider.h" | ||
|
||
#define EphemeralProvider BraveEphemeralProvider | ||
#define PrefProvider BravePrefProvider | ||
#include "../../../../../../components/content_settings/core/browser/host_content_settings_map.cc" | ||
#undef EphemeralProvider | ||
#undef PrefProvider |
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
51 changes: 51 additions & 0 deletions
51
components/content_settings/core/browser/brave_content_settings_ephemeral_provider.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,51 @@ | ||
/* 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_ephemeral_provider.h" | ||
|
||
#include "brave/components/brave_shields/common/brave_shield_constants.h" | ||
|
||
namespace { | ||
|
||
bool IsShieldsResourceID( | ||
const content_settings::ResourceIdentifier& resource_identifier) { | ||
if (resource_identifier == brave_shields::kAds || | ||
resource_identifier == brave_shields::kTrackers || | ||
resource_identifier == brave_shields::kHTTPUpgradableResources || | ||
resource_identifier == brave_shields::kJavaScript || | ||
resource_identifier == brave_shields::kFingerprinting || | ||
resource_identifier == brave_shields::kBraveShields || | ||
resource_identifier == brave_shields::kReferrers || | ||
resource_identifier == brave_shields::kCookies) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
} | ||
|
||
namespace content_settings { | ||
|
||
bool BraveEphemeralProvider::SetWebsiteSetting( | ||
const ContentSettingsPattern& primary_pattern, | ||
const ContentSettingsPattern& secondary_pattern, | ||
ContentSettingsType content_type, | ||
const ResourceIdentifier& resource_identifier, | ||
base::Value* in_value) { | ||
// Prevent this handle shields configuration. | ||
if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS && | ||
IsShieldsResourceID(resource_identifier)) { | ||
return false; | ||
} | ||
|
||
// Only flash plugin setting can be reached here. | ||
DCHECK(resource_identifier.empty()); | ||
|
||
return EphemeralProvider::SetWebsiteSetting( | ||
primary_pattern, secondary_pattern, | ||
content_type, resource_identifier, in_value); | ||
} | ||
|
||
} // namespace content_settings |
31 changes: 31 additions & 0 deletions
31
components/content_settings/core/browser/brave_content_settings_ephemeral_provider.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,31 @@ | ||
/* 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_CONTENT_SETTINGS_EPHEMERAL_PROVIDER_H_ | ||
#define BRAVE_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_EPHEMERAL_PROVIDER_H_ | ||
|
||
#include "components/content_settings/core/browser/content_settings_ephemeral_provider.h" | ||
|
||
namespace content_settings { | ||
|
||
// See the comments of BravePrefProvider. | ||
class BraveEphemeralProvider : public EphemeralProvider { | ||
public: | ||
using EphemeralProvider::EphemeralProvider; | ||
~BraveEphemeralProvider() override {} | ||
|
||
private: | ||
// EphemeralProvider overrides: | ||
bool SetWebsiteSetting(const ContentSettingsPattern& primary_pattern, | ||
const ContentSettingsPattern& secondary_pattern, | ||
ContentSettingsType content_type, | ||
const ResourceIdentifier& resource_identifier, | ||
base::Value* value) override; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(BraveEphemeralProvider); | ||
}; | ||
|
||
} // namespace content_settings | ||
|
||
#endif // BRAVE_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_EPHEMERAL_PROVIDER_H_ |
61 changes: 61 additions & 0 deletions
61
components/content_settings/core/browser/brave_content_settings_pref_provider.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,61 @@ | ||
/* 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_pref_provider.h" | ||
|
||
#include "base/bind.h" | ||
#include "components/content_settings/core/browser/content_settings_pref.h" | ||
#include "components/content_settings/core/browser/website_settings_registry.h" | ||
|
||
namespace content_settings { | ||
|
||
BravePrefProvider::BravePrefProvider(PrefService* prefs, | ||
bool incognito, | ||
bool store_last_modified) | ||
: PrefProvider(prefs, incognito, store_last_modified) { | ||
brave_pref_change_registrar_.Init(prefs_); | ||
|
||
WebsiteSettingsRegistry* website_settings = | ||
WebsiteSettingsRegistry::GetInstance(); | ||
// Makes BravePrefProvder handle plugin type. | ||
for (const WebsiteSettingsInfo* info : *website_settings) { | ||
if (info->type() == CONTENT_SETTINGS_TYPE_PLUGINS) { | ||
content_settings_prefs_.insert(std::make_pair( | ||
info->type(), | ||
std::make_unique<ContentSettingsPref>( | ||
info->type(), prefs_, &brave_pref_change_registrar_, | ||
info->pref_name(), | ||
is_incognito_, | ||
base::Bind(&PrefProvider::Notify, base::Unretained(this))))); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
void BravePrefProvider::ShutdownOnUIThread() { | ||
brave_pref_change_registrar_.RemoveAll(); | ||
PrefProvider::ShutdownOnUIThread(); | ||
} | ||
|
||
bool BravePrefProvider::SetWebsiteSetting( | ||
const ContentSettingsPattern& primary_pattern, | ||
const ContentSettingsPattern& secondary_pattern, | ||
ContentSettingsType content_type, | ||
const ResourceIdentifier& resource_identifier, | ||
base::Value* in_value) { | ||
// Flash's setting shouldn't be reached here. | ||
// Its content type is plugin and id is empty string. | ||
// One excpetion is default setting. It can be persisted. | ||
if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS && | ||
resource_identifier.empty()) { | ||
DCHECK(primary_pattern == ContentSettingsPattern::Wildcard() && | ||
secondary_pattern == ContentSettingsPattern::Wildcard()); | ||
} | ||
|
||
return PrefProvider::SetWebsiteSetting( | ||
primary_pattern, secondary_pattern, | ||
content_type, resource_identifier, in_value); | ||
} | ||
|
||
} // namespace content_settings |
44 changes: 44 additions & 0 deletions
44
components/content_settings/core/browser/brave_content_settings_pref_provider.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,44 @@ | ||
/* 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_PREF_PROVIDER_H_ | ||
#define BRAVE_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_BRAVE_CONTENT_SETTINGS_PREF_PROVIDER_H_ | ||
|
||
#include "components/content_settings/core/browser/content_settings_pref_provider.h" | ||
#include "components/prefs/pref_change_registrar.h" | ||
|
||
namespace content_settings { | ||
|
||
// With this subclass, shields configuration is persisted across sessions. | ||
// Its content type is |CONTENT_SETTINGS_TYPE_PLUGIN| and its storage option is | ||
// ephemeral because chromium want that flash configuration shouldn't be | ||
// persisted. (Maybe chromium assumes flash is the only one of this type). | ||
// Because of this reasion, shields configuration was also ephemeral. | ||
// However, we want shilelds configuration persisted. To do this, we make | ||
// EphemeralProvider ignore shields type and this class handles. | ||
class BravePrefProvider : public PrefProvider { | ||
public: | ||
BravePrefProvider( | ||
PrefService* prefs, bool incognito, bool store_last_modified); | ||
~BravePrefProvider() override {} | ||
|
||
private: | ||
// content_settings::PrefProvider overrides: | ||
void ShutdownOnUIThread() override; | ||
bool SetWebsiteSetting( | ||
const ContentSettingsPattern& primary_pattern, | ||
const ContentSettingsPattern& secondary_pattern, | ||
ContentSettingsType content_type, | ||
const ResourceIdentifier& resource_identifier, | ||
base::Value* value) override; | ||
|
||
// PrefProvider::pref_change_registrar_ alreay has plugin type. | ||
PrefChangeRegistrar brave_pref_change_registrar_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(BravePrefProvider); | ||
}; | ||
|
||
} // namespace content_settings | ||
|
||
#endif // BRAVE_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_BRAVE_CONTENT_SETTINGS_PREF_PROVIDER_H_ |
12 changes: 12 additions & 0 deletions
12
patches/components-content_settings-core-browser-content_settings_pref_provider.h.patch
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,12 @@ | ||
diff --git a/components/content_settings/core/browser/content_settings_pref_provider.h b/components/content_settings/core/browser/content_settings_pref_provider.h | ||
index 2dcdfbacda452ca8519f40d9db74d202b76dc425..915591404eb06bc04696d61522c087ea1a95c729 100644 | ||
--- a/components/content_settings/core/browser/content_settings_pref_provider.h | ||
+++ b/components/content_settings/core/browser/content_settings_pref_provider.h | ||
@@ -64,6 +64,7 @@ class PrefProvider : public UserModifiableProvider { | ||
void SetClockForTesting(base::Clock* clock); | ||
|
||
private: | ||
+ friend class BravePrefProvider; | ||
friend class DeadlockCheckerObserver; // For testing. | ||
|
||
void Notify(const ContentSettingsPattern& primary_pattern, |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have a DCHECK here to ensure resource_identifier is empty?
I think that will prevent a future bug when we add a new content setting type and forget to add it in the list of
IsShieldsResourceID
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.