mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 1752332: Remove the shouldSanitizeFunction member r=KrisWright
In the following patch we are going to change the signature of ShouldSanitizePreference to take a Pref object. Pref is only known to the Preferences compilation unit; so to keep this member (whose signature will change) we would need to expose the Pref class. However it will only be a forward declaration, one could not construct a Pref object in e.g. the gtest. It is simpler to just remove the member entirely and call ShouldSanitizePreference unconditionally - the member was only used for the gtest, and while the gtest will be less robust because of this change, it will still do some testing. Depends on D141419 Differential Revision: https://phabricator.services.mozilla.com/D141420
This commit is contained in:
parent
1b7e20d742
commit
735f58c46f
@ -2532,8 +2532,7 @@ bool ContentParent::BeginSubprocessLaunch(ProcessPriority aPriority) {
|
||||
|
||||
// Instantiate the pref serializer. It will be cleaned up in
|
||||
// `LaunchSubprocessReject`/`LaunchSubprocessResolve`.
|
||||
mPrefSerializer = MakeUnique<mozilla::ipc::SharedPreferenceSerializer>(
|
||||
ShouldSanitizePreference);
|
||||
mPrefSerializer = MakeUnique<mozilla::ipc::SharedPreferenceSerializer>();
|
||||
if (!mPrefSerializer->SerializeToSharedMemory(GeckoProcessType_Content,
|
||||
GetRemoteType())) {
|
||||
NS_WARNING("SharedPreferenceSerializer::SerializeToSharedMemory failed");
|
||||
|
@ -46,8 +46,7 @@ bool RDDProcessHost::Launch(StringVector aExtraOpts) {
|
||||
MOZ_ASSERT(mLaunchPhase == LaunchPhase::Unlaunched);
|
||||
MOZ_ASSERT(!mRDDChild);
|
||||
|
||||
mPrefSerializer =
|
||||
MakeUnique<ipc::SharedPreferenceSerializer>(ShouldSanitizePreference);
|
||||
mPrefSerializer = MakeUnique<ipc::SharedPreferenceSerializer>();
|
||||
if (!mPrefSerializer->SerializeToSharedMemory(GeckoProcessType_RDD,
|
||||
/* remoteType */ ""_ns)) {
|
||||
return false;
|
||||
|
@ -42,8 +42,7 @@ bool GPUProcessHost::Launch(StringVector aExtraOpts) {
|
||||
MOZ_ASSERT(!mGPUChild);
|
||||
MOZ_ASSERT(!gfxPlatform::IsHeadless());
|
||||
|
||||
mPrefSerializer =
|
||||
MakeUnique<ipc::SharedPreferenceSerializer>(ShouldSanitizePreference);
|
||||
mPrefSerializer = MakeUnique<ipc::SharedPreferenceSerializer>();
|
||||
if (!mPrefSerializer->SerializeToSharedMemory(GeckoProcessType_GPU,
|
||||
/* remoteType */ ""_ns)) {
|
||||
return false;
|
||||
|
@ -55,8 +55,7 @@ bool VRProcessParent::Launch() {
|
||||
std::vector<std::string> extraArgs;
|
||||
ProcessChild::AddPlatformBuildID(extraArgs);
|
||||
|
||||
mPrefSerializer =
|
||||
MakeUnique<ipc::SharedPreferenceSerializer>(ShouldSanitizePreference);
|
||||
mPrefSerializer = MakeUnique<ipc::SharedPreferenceSerializer>();
|
||||
if (!mPrefSerializer->SerializeToSharedMemory(GeckoProcessType_VR,
|
||||
/* remoteType */ ""_ns)) {
|
||||
return false;
|
||||
|
@ -27,8 +27,7 @@ void SetThisProcessName(const char* aName);
|
||||
|
||||
class SharedPreferenceSerializer final {
|
||||
public:
|
||||
explicit SharedPreferenceSerializer(
|
||||
std::function<bool(const char*, bool)>&& aShouldSanitizeFn);
|
||||
explicit SharedPreferenceSerializer();
|
||||
SharedPreferenceSerializer(SharedPreferenceSerializer&& aOther);
|
||||
~SharedPreferenceSerializer();
|
||||
|
||||
@ -51,7 +50,6 @@ class SharedPreferenceSerializer final {
|
||||
size_t mPrefsLength;
|
||||
UniqueFileHandle mPrefMapHandle;
|
||||
UniqueFileHandle mPrefsHandle;
|
||||
std::function<bool(const char*, bool)> mShouldSanitizeFn;
|
||||
};
|
||||
|
||||
class SharedPreferenceDeserializer final {
|
||||
|
@ -18,9 +18,8 @@
|
||||
namespace mozilla {
|
||||
namespace ipc {
|
||||
|
||||
SharedPreferenceSerializer::SharedPreferenceSerializer(
|
||||
std::function<bool(const char*, bool)>&& aShouldSanitizeFn)
|
||||
: mPrefMapSize(0), mPrefsLength(0), mShouldSanitizeFn(aShouldSanitizeFn) {
|
||||
SharedPreferenceSerializer::SharedPreferenceSerializer()
|
||||
: mPrefMapSize(0), mPrefsLength(0) {
|
||||
MOZ_COUNT_CTOR(SharedPreferenceSerializer);
|
||||
}
|
||||
|
||||
@ -50,7 +49,7 @@ bool SharedPreferenceSerializer::SerializeToSharedMemory(
|
||||
|
||||
// Serialize the early prefs.
|
||||
nsAutoCStringN<1024> prefs;
|
||||
Preferences::SerializePreferences(prefs, mShouldSanitizeFn, destIsWebContent);
|
||||
Preferences::SerializePreferences(prefs, destIsWebContent);
|
||||
mPrefsLength = prefs.Length();
|
||||
|
||||
base::SharedMemory shm;
|
||||
|
@ -60,8 +60,7 @@ bool UtilityProcessHost::Launch(StringVector aExtraOpts) {
|
||||
MOZ_ASSERT(mLaunchPhase == LaunchPhase::Unlaunched);
|
||||
MOZ_ASSERT(!mUtilityProcessParent);
|
||||
|
||||
mPrefSerializer =
|
||||
MakeUnique<ipc::SharedPreferenceSerializer>(ShouldSanitizePreference);
|
||||
mPrefSerializer = MakeUnique<ipc::SharedPreferenceSerializer>();
|
||||
if (!mPrefSerializer->SerializeToSharedMemory(GeckoProcessType_Utility,
|
||||
/* remoteType */ ""_ns)) {
|
||||
return false;
|
||||
|
@ -49,8 +49,7 @@ already_AddRefed<IPDLUnitTestParent> IPDLUnitTestParent::CreateCrossProcess() {
|
||||
|
||||
std::vector<std::string> extraArgs;
|
||||
|
||||
auto prefSerializer =
|
||||
MakeUnique<ipc::SharedPreferenceSerializer>(ShouldSanitizePreference);
|
||||
auto prefSerializer = MakeUnique<ipc::SharedPreferenceSerializer>();
|
||||
if (!prefSerializer->SerializeToSharedMemory(GeckoProcessType_IPDLUnitTest,
|
||||
/* remoteType */ ""_ns)) {
|
||||
ADD_FAILURE()
|
||||
|
@ -3611,10 +3611,8 @@ NS_IMPL_ISUPPORTS(Preferences, nsIPrefService, nsIObserver, nsIPrefBranch,
|
||||
nsISupportsWeakReference)
|
||||
|
||||
/* static */
|
||||
void Preferences::SerializePreferences(
|
||||
nsCString& aStr,
|
||||
const std::function<bool(const char*, bool)>& aShouldSanitizeFn,
|
||||
bool aIsDestinationContentProcess) {
|
||||
void Preferences::SerializePreferences(nsCString& aStr,
|
||||
bool aIsDestinationWebContentProcess) {
|
||||
MOZ_RELEASE_ASSERT(InitStaticMembers());
|
||||
|
||||
aStr.Truncate();
|
||||
@ -3623,7 +3621,8 @@ void Preferences::SerializePreferences(
|
||||
Pref* pref = iter.get().get();
|
||||
if (!pref->IsTypeNone() && pref->HasAdvisablySizedValues()) {
|
||||
pref->SerializeAndAppend(
|
||||
aStr, aShouldSanitizeFn(pref->Name(), aIsDestinationContentProcess));
|
||||
aStr,
|
||||
ShouldSanitizePreference(pref, aIsDestinationWebContentProcess));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -400,10 +400,8 @@ class Preferences final : public nsIPrefService,
|
||||
|
||||
// When a content process is created these methods are used to pass changed
|
||||
// prefs in bulk from the parent process, via shared memory.
|
||||
static void SerializePreferences(
|
||||
nsCString& aStr,
|
||||
const std::function<bool(const char*, bool)>& aShouldSanitizeFn,
|
||||
bool aIsDestinationContentProcess);
|
||||
static void SerializePreferences(nsCString& aStr,
|
||||
bool aIsDestinationWebContentProcess);
|
||||
static void DeserializePreferences(char* aStr, size_t aPrefsLen);
|
||||
|
||||
static mozilla::ipc::FileDescriptor EnsureSnapshot(size_t* aSize);
|
||||
|
@ -43,17 +43,13 @@ TEST(PrefsBasics, Serialize)
|
||||
true);
|
||||
|
||||
nsCString str;
|
||||
Preferences::SerializePreferences(
|
||||
str, [](const char* aPref, bool) -> bool { return true; }, true);
|
||||
// Assert everything was marked sanitized
|
||||
ASSERT_EQ(nullptr, strstr(str.Data(), "--:"));
|
||||
|
||||
Preferences::SerializePreferences(
|
||||
str,
|
||||
[](const char* aPref, bool) -> bool {
|
||||
return strncmp(aPref, "foo.bool", 8) == 0;
|
||||
},
|
||||
true);
|
||||
// Assert the sanitized serializtion was found
|
||||
ASSERT_NE(nullptr, strstr(str.Data(), "B-S:8/foo.bool:T:\n"));
|
||||
Preferences::SerializePreferences(str, true);
|
||||
fprintf(stderr, "%s\n", str.Data());
|
||||
// Assert that some prefs were not sanitized
|
||||
ASSERT_NE(nullptr, strstr(str.Data(), "B--:"));
|
||||
ASSERT_NE(nullptr, strstr(str.Data(), "I--:"));
|
||||
ASSERT_NE(nullptr, strstr(str.Data(), "S--:"));
|
||||
// Assert that something was sanitized
|
||||
ASSERT_NE(nullptr,
|
||||
strstr(str.Data(), "I-S:56/datareporting.policy.dataSubmissionPolicyAcceptedVersion"));
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ bool SocketProcessHost::Launch() {
|
||||
std::vector<std::string> extraArgs;
|
||||
ProcessChild::AddPlatformBuildID(extraArgs);
|
||||
|
||||
SharedPreferenceSerializer prefSerializer(ShouldSanitizePreference);
|
||||
SharedPreferenceSerializer prefSerializer;
|
||||
if (!prefSerializer.SerializeToSharedMemory(GeckoProcessType_VR,
|
||||
/* remoteType */ ""_ns)) {
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user