Skip to content

Commit

Permalink
Bug 1804654 - Deduplicate cookie banner rules collection for GetRules…
Browse files Browse the repository at this point in the history
…. r=timhuang

Differential Revision: https://phabricator.services.mozilla.com/D165173
  • Loading branch information
Trikolon committed Jan 12, 2023
1 parent ef14e4a commit d847698
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion toolkit/components/cookiebanners/nsCookieBannerService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,22 @@ nsCookieBannerService::GetRules(nsTArray<RefPtr<nsICookieBannerRule>>& aRules) {
return NS_ERROR_NOT_AVAILABLE;
}

// Append global rules if enabled. We don't have to deduplicate here because
// global rules are stored by ID and every ID maps to exactly one rule.
if (StaticPrefs::cookiebanners_service_enableGlobalRules()) {
AppendToArray(aRules, mGlobalRules.Values());
}
AppendToArray(aRules, mRules.Values());

// Append domain-keyed rules.
// Since multiple domains can map to the same rule in mRules we need to
// deduplicate using a set before returning a rules array.
nsTHashSet<nsRefPtrHashKey<nsICookieBannerRule>> rulesSet;

for (const nsCOMPtr<nsICookieBannerRule>& rule : mRules.Values()) {
rulesSet.Insert(rule);
}

AppendToArray(aRules, rulesSet);

return NS_OK;
}
Expand Down

0 comments on commit d847698

Please sign in to comment.