Bug 1504729 - Make sure the STATE_LOADED_TRACKING_CONTENT state is stored outside of the content blocking log r=baku

Differential Revision: https://phabricator.services.mozilla.com/D10944

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ehsan Akhgari 2018-11-06 07:38:02 +00:00
Родитель 2cde9dfed2
Коммит 8915579fb6
2 изменённых файлов: 53 добавлений и 53 удалений

Просмотреть файл

@ -30,7 +30,8 @@ class ContentBlockingLog final
// Each element is a tuple of (type, blocked, repeatCount). The type values
// come from the blocking types defined in nsIWebProgressListener.
typedef nsTArray<LogEntry> OriginLog;
typedef nsClassHashtable<nsStringHashKey, OriginLog> OriginLogHashTable;
typedef Pair<bool, OriginLog> OriginData;
typedef nsClassHashtable<nsStringHashKey, OriginData> OriginDataHashTable;
struct StringWriteFunc : public JSONWriteFunc
{
@ -56,9 +57,14 @@ public:
}
auto entry = mLog.LookupForAdd(aOrigin);
if (entry) {
auto& log = entry.Data();
if (!log->IsEmpty()) {
auto& last = log->LastElement();
auto& data = entry.Data();
if (aType == nsIWebProgressListener::STATE_LOADED_TRACKING_CONTENT) {
data->first() = aBlocked;
return;
}
auto& log = data->second();
if (!log.IsEmpty()) {
auto& last = log.LastElement();
if (last.mType == aType &&
last.mBlocked == aBlocked) {
++last.mRepeatCount;
@ -66,17 +72,21 @@ public:
return;
}
}
if (log->Length() ==
if (log.Length() ==
std::max(1u, StaticPrefs::browser_contentblocking_originlog_length())) {
// Cap the size at the maximum length adjustable by the pref
log->RemoveElementAt(0);
log.RemoveElementAt(0);
}
log->AppendElement(LogEntry{aType, 1u, aBlocked});
log.AppendElement(LogEntry{aType, 1u, aBlocked});
} else {
entry.OrInsert([=] {
auto log(MakeUnique<OriginLog>());
log->AppendElement(LogEntry{aType, 1u, aBlocked});
return log.release();
nsAutoPtr<OriginData> data(new OriginData(false, OriginLog()));
if (aType == nsIWebProgressListener::STATE_LOADED_TRACKING_CONTENT) {
data->first() = true;
} else {
data->second().AppendElement(LogEntry{aType, 1u, aBlocked});
}
return data.forget();
});
}
}
@ -96,7 +106,17 @@ public:
}
w.StartArrayProperty(NS_ConvertUTF16toUTF8(iter.Key()).get(), w.SingleLineStyle);
for (auto& item: *iter.UserData()) {
auto& data = *iter.UserData();
if (data.first()) {
w.StartArrayElement(w.SingleLineStyle);
{
w.IntElement(nsIWebProgressListener::STATE_LOADED_TRACKING_CONTENT);
w.BoolElement(true); // blocked
w.IntElement(1); // repeat count
}
w.EndArray();
}
for (auto& item: data.second()) {
w.StartArrayElement(w.SingleLineStyle);
{
w.IntElement(item.mType);
@ -120,10 +140,16 @@ public:
continue;
}
for (auto& item: *iter.UserData()) {
if ((item.mType & aType) != 0) {
if (aType == nsIWebProgressListener::STATE_LOADED_TRACKING_CONTENT) {
if (iter.UserData()->first()) {
return true;
}
} else {
for (auto& item: iter.UserData()->second()) {
if ((item.mType & aType) != 0) {
return true;
}
}
}
}
return false;
@ -136,17 +162,17 @@ public:
// Now add the sizes of each origin log queue.
// The const_cast is needed because the nsTHashtable::Iterator interface is
// not const-safe. :-(
for (auto iter = const_cast<OriginLogHashTable&>(mLog).Iter();
for (auto iter = const_cast<OriginDataHashTable&>(mLog).Iter();
!iter.Done(); iter.Next()) {
if (iter.UserData()) {
aSizes.mDOMOtherSize +=
iter.UserData()->ShallowSizeOfIncludingThis(aSizes.mState.mMallocSizeOf);
iter.UserData()->second().ShallowSizeOfIncludingThis(aSizes.mState.mMallocSizeOf);
}
}
}
private:
OriginLogHashTable mLog;
OriginDataHashTable mLog;
};
} // namespace dom

Просмотреть файл

@ -156,55 +156,29 @@ add_task(async function() {
is(text, 1, "One cookie received received for scripts.");
});
let expectTrackerFound = item => {
is(item[0], Ci.nsIWebProgressListener.STATE_LOADED_TRACKING_CONTENT,
"Correct blocking type reported");
is(item[1], true,
"Correct blocking status reported");
ok(item[2] >= 1,
"Correct repeat count reported");
};
let log = JSON.parse(await browser.getContentBlockingLog());
for (let trackerOrigin in log) {
is(trackerOrigin, TEST_3RD_PARTY_DOMAIN, "Correct tracker origin must be reported");
let originLog = log[trackerOrigin];
is(originLog.length, 10, "We should have 10 entries in the compressed log");
expectTrackerFound(originLog[0]);
is(originLog.length, 3, "We should have 3 entries in the compressed log");
is(originLog[0][0], Ci.nsIWebProgressListener.STATE_LOADED_TRACKING_CONTENT,
"Correct blocking type reported");
is(originLog[0][1], true,
"Correct blocking status reported");
ok(originLog[0][2] >= 1,
"Correct repeat count reported");
is(originLog[1][0], Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER,
"Correct blocking type reported");
is(originLog[1][1], true,
"Correct blocking status reported");
is(originLog[1][2], 1,
is(originLog[1][2], 6,
"Correct repeat count reported");
expectTrackerFound(originLog[2]);
is(originLog[3][0], Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER,
is(originLog[2][0], Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER,
"Correct blocking type reported");
is(originLog[3][1], true,
is(originLog[2][1], false,
"Correct blocking status reported");
is(originLog[3][2], 1,
ok(originLog[2][2] >= 1,
"Correct repeat count reported");
expectTrackerFound(originLog[4]);
is(originLog[5][0], Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER,
"Correct blocking type reported");
is(originLog[5][1], true,
"Correct blocking status reported");
is(originLog[5][2], 1,
"Correct repeat count reported");
expectTrackerFound(originLog[6]);
is(originLog[7][0], Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER,
"Correct blocking type reported");
is(originLog[7][1], true,
"Correct blocking status reported");
is(originLog[7][2], 3,
"Correct repeat count reported");
is(originLog[8][0], Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER,
"Correct blocking type reported");
is(originLog[8][1], false,
"Correct blocking status reported");
is(originLog[8][2], 1,
"Correct repeat count reported");
expectTrackerFound(originLog[9]);
}
info("Removing the tab");