Commit f9556791 authored by Mugurell's avatar Mugurell
Browse files

For #20229 - Use the AC common implementation for ads/search telemetry

Everything should work exactly as before.
parent b2a5723b
Loading
Loading
Loading
Loading
+0 −11
Original line number Diff line number Diff line
@@ -741,14 +741,3 @@ ext.updateExtensionVersion = { task, extDir ->
        expand(values)
    }
}

tasks.register("updateAdsExtensionVersion", Copy) { task ->
    updateExtensionVersion(task, 'src/main/assets/extensions/ads')
}

tasks.register("updateCookiesExtensionVersion", Copy) { task ->
    updateExtensionVersion(task, 'src/main/assets/extensions/cookies')
}

preBuild.dependsOn "updateAdsExtensionVersion"
preBuild.dependsOn "updateCookiesExtensionVersion"
+6 −3
Original line number Diff line number Diff line
@@ -4235,11 +4235,12 @@ browser.search:
      - https://github.com/mozilla-mobile/fenix/pull/10112
      - https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068
      - https://github.com/mozilla-mobile/fenix/pull/19924#issuecomment-861423789
      - https://github.com/mozilla-mobile/focus-android/pull/4968#issuecomment-879256443
    data_sensitivity:
      - interaction
    notification_emails:
      - android-probes@mozilla.com
    expires: "2021-08-01"
    expires: "2022-07-01"
  ad_clicks:
    type: labeled_counter
    description: |
@@ -4253,11 +4254,12 @@ browser.search:
      - https://github.com/mozilla-mobile/fenix/pull/10112
      - https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068
      - https://github.com/mozilla-mobile/fenix/pull/19924#issuecomment-861423789
      - https://github.com/mozilla-mobile/focus-android/pull/4968#issuecomment-879256443
    data_sensitivity:
      - interaction
    notification_emails:
      - android-probes@mozilla.com
    expires: "2021-08-01"
    expires: "2022-07-01"
  in_content:
    type: labeled_counter
    description: |
@@ -4270,11 +4272,12 @@ browser.search:
      - https://github.com/mozilla-mobile/fenix/pull/10167
      - https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068
      - https://github.com/mozilla-mobile/fenix/pull/19924#issuecomment-861423789
      - https://github.com/mozilla-mobile/focus-android/pull/4968#issuecomment-879256443
    data_sensitivity:
      - interaction
    notification_emails:
      - android-probes@mozilla.com
    expires: "2021-08-01"
    expires: "2022-07-01"

addons:
  open_addons_in_settings:
+0 −61
Original line number Diff line number Diff line
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const ADLINK_CHECK_TIMEOUT_MS = 1000;

function collectLinks(urls) {
    let anchors = document.getElementsByTagName("a");
    for (let anchor of anchors) {
          if (!anchor.href) {
            continue;
          }
          urls.push(anchor.href);
    }
}

function sendLinks(cookies) {
    let urls = [];
    collectLinks(urls);

    let message = {
     'url': document.location.href,
     'urls': urls,
     'cookies': cookies
    };
    browser.runtime.sendNativeMessage("MozacBrowserAds", message);
}

function notify(message) {
   sendLinks(message.cookies);
}

browser.runtime.onMessage.addListener(notify);

const events = ["pageshow", "load", "unload"];
var timeout;

const eventLogger = event => {
  switch (event.type) {
    case "load":
        timeout = setTimeout(() => {
            browser.runtime.sendMessage({ "checkCookies": true });
        }, ADLINK_CHECK_TIMEOUT_MS)
        break;
    case "pageshow":
        if (event.persisted) {
          timeout = setTimeout(() => {
              browser.runtime.sendMessage({ "checkCookies": true });
          }, ADLINK_CHECK_TIMEOUT_MS)
        }
        break;
    case "unload":
        clearTimeout(timeout);
    default:
        console.log('Event:', event.type);
  }
};

events.forEach(eventName =>
  window.addEventListener(eventName, eventLogger)
);
+0 −28
Original line number Diff line number Diff line
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

browser.runtime.onMessage.addListener(notify);

function sendMessageToTabs(tabs, cookies) {
  for (let tab of tabs) {
    browser.tabs.sendMessage(
      tab.id,
      { cookies }
    );
  }
}

function notify(message) {
    if (message.checkCookies) {
        browser.cookies.getAll({})
            .then(cookies => {
                browser.tabs.query({
                    currentWindow: true,
                    active: true
                }).then(tabs => {
                    sendMessageToTabs(tabs, cookies);
                });
            });
    }
}
+0 −40
Original line number Diff line number Diff line
{
  "manifest_version": 2,
  "applications": {
    "gecko": {
      "id": "ads@mozac.org"
    }
  },
  "name": "Mozilla Android Components - Ads",
  "version": "${version}",
  "content_scripts": [
    {
      "matches": ["https://*/*"],
      "include_globs": [
        "https://www.google.*/search*",
        "https://www.bing.com/search*",
        "https://www.baidu.com/*",
        "https://m.baidu.com/*",
        "https://duckduckgo.com/*"
      ],
      "js": ["ads.js"],
      "run_at": "document_end"
    }
  ],
  "background": {
    "scripts": ["adsBackground.js"]
  },
  "permissions": [
    "geckoViewAddons",
    "nativeMessaging",
    "nativeMessagingFromContent",
    "geckoViewAddons",
    "nativeMessaging",
    "nativeMessagingFromContent",
    "webNavigation",
    "webRequest",
    "webRequestBlocking",
    "cookies",
    "*://*/*"
  ]
}
Loading