Commit 0330f2ce authored by Josh Karlin's avatar Josh Karlin Committed by Commit Bot

[AdTagging] Don't track ad scripts that we could detect by context

Ad scripts loaded in ad contexts can be detected by the context
alone. Reserve tracking individual scripts to non-ad contexts.

Bug: 894080

Change-Id: I90ec62e7e816fc83540f0daa232b105d03eb1553
Reviewed-on: https://chromium-review.googlesource.com/c/1276785
Commit-Queue: Josh Karlin <jkarlin@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600549}
parent 5bda1693
......@@ -114,8 +114,12 @@ void AdTracker::WillSendRequest(ExecutionContext* execution_context,
if (!request.IsAdResource() && IsAdScriptInStack())
request.SetIsAdResource();
// If it is a script marked as an ad, append it to the known ad scripts set.
if (resource_type == ResourceType::kScript && request.IsAdResource()) {
// If it is a script marked as an ad and it's not in an ad context, append it
// to the known ad script set. We don't need to keep track of ad scripts in ad
// contexts, because any script executed inside an ad context is considered an
// ad script by IsKnownAdScript.
if (resource_type == ResourceType::kScript && request.IsAdResource() &&
!IsKnownAdExecutionContext(execution_context)) {
AppendToKnownAdScripts(*execution_context, request.Url().GetString());
}
}
......@@ -151,9 +155,6 @@ bool AdTracker::IsKnownAdScript(ExecutionContext* execution_context,
if (!execution_context)
return false;
// TODO(jkarlin): Minor memory optimization, stop tracking known ad scripts in
// ad contexts. This will reduce the size of known_ad_scripts_. Note that
// this is a minor win, as the strings are already ref-counted.
if (IsKnownAdExecutionContext(execution_context))
return true;
......
......@@ -85,6 +85,7 @@ class CORE_EXPORT AdTracker : public GarbageCollectedFinalized<AdTracker> {
// an ad script. Each time the script or function finishes, it pops the stack.
Vector<bool> stack_frame_is_ad_;
// The set of ad scripts detected outside of ad-frame contexts.
HeapHashMap<WeakMember<ExecutionContext>, HashSet<String>> known_ad_scripts_;
DISALLOW_COPY_AND_ASSIGN(AdTracker);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment