-
Notifications
You must be signed in to change notification settings - Fork 868
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #558 from brave/make_plugin_contents_type_persist
Make shields settings persist
- Loading branch information
Showing
8 changed files
with
268 additions
and
0 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
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, |