chromium/third_party/blink/renderer/core/timing/third_party_script_detector.cc

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/core/timing/third_party_script_detector.h"

#include <cmath>

#include "third_party/blink/public/common/features.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"

namespace blink {

namespace {
// kThirdPartyTechnologiesSourceLocationRegexString has to strictly follow the
// rules below in order for the regex matching to be working as intended.
//
// 1. Each technology(eg. WordPress) contains exactly one capturing group in
// order to identify technologies when a pattern is matched. Non-capturing
// groups are free to use. (Ref:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Groups_and_backreferences#types)
// 2. Different technologies are separated by "|".
// 3. If a technology has more than one regex pattern to be matched, use "|" to
// concatenate them together within the same technology group.
// 4. The order must be consistent with Technology enum value defined in
// third_party_script_detector.h. That means i-th (0 based) group in regex
// should have (1<<i) Technology.
// 5. For better readability, please put each regex pattern on a new line
// beginning with a "|".
// 6. If adding a new technology which leverages an existing technology (eg.
// Elementor plugins always leverage WordPress), make sure the the smaller set
// goes first (ie. Elementor prior to WordPress) so it won't be masked. Feel
// free to swap their locations if needed and make sure their locations in
// GetTechnologyFromGroupIndex are also swapped.
constexpr char kThirdPartyTechnologiesSourceLocationRegexString[] =// Elementor
    "(/wp-content/plugins/elementor)"
    // Google Analytics
    "|(google-analytics\\.com/(?:ga|urchin|analytics)\\.js"
    "|googletagmanager\\.com/gtag/js)"
    // Google Font Api
    "|(googleapis\\.com/.+webfont)"
    // Google Tag Manager
    "|(googletagmanager\\.com/gtm\\.js)"
    // Google Maps
    "|((?:maps\\.google\\.com/"
    "maps\\?file=api(?:&v=(?:[\\d.]+))?|maps\\.google\\.com/maps/api/"
    "staticmap)\\;version:API v1"
    "|//maps\\.google(?:apis)?\\.com/maps/api/js)"
    // Meta Pixel
    "|(connect\\.facebook.\\w+/signals/config/"
    "\\d+\\?v=(?:[\\d\\.]+)\\;version:1"
    "|connect\\.facebook\\.\\w+/.+/fbevents\\.js)"
    // YouTube
    "|(youtube\\.com)"
    // Adobe Analytics
    "|(adoberesources\\.net/alloy/.+/alloy(?:\\.min)?\\.js"
    "|adobedtm\\.com/extensions/.+/AppMeasurement(?:\\.min)?\\.js)"
    // Tiktok Pixel
    "|(analytics\\.tiktok\\.com)"
    // Hotjar
    "|(static\\.hotjar\\.com)"
    // Google AdSense
    "|(googlesyndication\\.com/[^\"]+/"
    "(?:adsbygoogle|show_ads_impl|interstitial_ad_frame))"
    // Google Publisher Tag
    "|(doubleclick\\.net/[^\"]+/pubads_impl(?:_page_level_ads)?.js"
    "|googlesyndication\\.com/tag/js/gpt\\.js)"
    // Google Ads Libraries
    "|(googlesyndication\\.com/[^\"]+/(?:ufs_web_display|reactive_library_fy))"
    // Funding Choices
    "|(fundingchoicesmessages\\.google\\.com)"
    // WordPress
    "|(/wp-(?:content|includes)/"
    "|wp-embed\\.min\\.js)";

constexpr int kTechnologyCount =;

// The order of technologies in the vector should follow their order in the
// regex patterns in kThirdPartyTechnologiesSourceLocationRegexString.
ThirdPartyScriptDetector::Technology GetTechnologyFromGroupIndex(int index) {}
}  // namespace

// static
const char ThirdPartyScriptDetector::kSupplementName[] =;

// static
ThirdPartyScriptDetector& ThirdPartyScriptDetector::From(
    LocalDOMWindow& window) {}

ThirdPartyScriptDetector::ThirdPartyScriptDetector(LocalDOMWindow& window)
    :{}

void ThirdPartyScriptDetector::Trace(Visitor* visitor) const {}

ThirdPartyScriptDetector::Technology ThirdPartyScriptDetector::Detect(
    const WTF::String url) {}

}  // namespace blink