Bug 1551672 - add a site patch to fix PDK video player versions that are broken on Fennec; r=denschub,aswan
authorThomas Wisniewski <twisniewski@mozilla.com>
Tue, 21 May 2019 16:16:33 +0000
changeset 474771 ea3552a1c04093f444af1c64228727341e8cce05
parent 474770 a45257ffaf572e39c87ded7bd2ee065d310f3bda
child 474772 c9760dcf558384e068cfa490008c0148668fe6af
push id85983
push usertwisniewski@mozilla.com
push dateTue, 21 May 2019 16:22:25 +0000
treeherderautoland@ea3552a1c040 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdenschub, aswan
bugs1551672
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1551672 - add a site patch to fix PDK video player versions that are broken on Fennec; r=denschub,aswan add a site patch to fix PDK video player versions that are broken on Fennec Differential Revision: https://phabricator.services.mozilla.com/D31122
browser/extensions/webcompat/injections.js
browser/extensions/webcompat/manifest.json
mobile/android/extensions/webcompat/injections.js
mobile/android/extensions/webcompat/manifest.json
--- a/browser/extensions/webcompat/injections.js
+++ b/browser/extensions/webcompat/injections.js
@@ -89,16 +89,25 @@ for (const injection of [
     platform: "desktop",
     domain: "twitch.tv",
     bug: "1518781",
     contentScripts: {
       matches: ["*://*.twitch.tv/*"],
       css: [{file: "injections/css/bug1518781-twitch.tv-webkit-scrollbar.css"}],
     },
   }, {
+    id: "bug1551672",
+    platform: "android",
+    domain: "Sites using PDK 5 video",
+    bug: "1551672",
+    pdk5fix: {
+      urls: ["https://*/*/tpPdk.js", "https://*/*/pdk/js/*/*.js"],
+      types: ["script"],
+    },
+  }, {
     id: "bug1305028",
     platform: "desktop",
     domain: "gaming.youtube.com",
     bug: "1305028",
     contentScripts: {
       matches: ["*://gaming.youtube.com/*"],
       css: [{file: "injections/css/bug1305028-gaming.youtube.com-webkit-scrollbar.css"}],
     },
@@ -121,21 +130,52 @@ async function registerContentScripts() 
       await enableInjection(injection);
     }
   }
 
   InjectionsEnabled = true;
   portsToAboutCompatTabs.broadcast({interventionsChanged: filterOverrides(Injections)});
 }
 
+function replaceStringInRequest(requestId, inString, outString, inEncoding = "utf-8") {
+  const filter = browser.webRequest.filterResponseData(requestId);
+  const decoder = new TextDecoder(inEncoding);
+  const encoder = new TextEncoder();
+  const RE = new RegExp(inString, "g");
+  const carryoverLength = inString.length;
+  let carryover = "";
+  filter.ondata = event => {
+    const replaced = (carryover + decoder.decode(event.data, {stream: true})).replace(RE, outString);
+    filter.write(encoder.encode(replaced.slice(0, -carryoverLength)));
+    carryover = replaced.slice(-carryoverLength);
+  };
+  filter.onstop = event => {
+    if (carryover.length) {
+      filter.write(encoder.encode(carryover));
+    }
+    filter.close();
+  };
+}
+
 async function enableInjection(injection) {
   if (injection.active) {
     return;
   }
 
+  if ("pdk5fix" in injection) {
+    const {urls, types} = injection.pdk5fix;
+    const listener = injection.pdk5fix.listener = ({requestId}) => {
+      replaceStringInRequest(requestId, "VideoContextChromeAndroid", "VideoContextAndroid");
+      return {};
+    };
+    browser.webRequest.onBeforeRequest.addListener(listener, {urls, types}, ["blocking"]);
+    injection.active = true;
+    return;
+  }
+
   try {
     const handle = await browser.contentScripts.register(injection.contentScripts);
     ActiveInjections.set(injection, handle);
     injection.active = true;
   } catch (ex) {
     console.error("Registering WebCompat GoFaster content scripts failed: ", ex);
   }
 }
@@ -148,16 +188,24 @@ function unregisterContentScripts() {
   portsToAboutCompatTabs.broadcast({interventionsChanged: false});
 }
 
 async function disableInjection(injection) {
   if (!injection.active) {
     return;
   }
 
+  if (injection.pdk5fix) {
+    const {listener} = injection.pdk5fix;
+    browser.webRequest.onBeforeRequest.removeListener(listener);
+    injection.active = false;
+    delete injection.pdk5fix.listener;
+    return;
+  }
+
   const contentScript = ActiveInjections.get(injection);
   await contentScript.unregister();
   ActiveInjections.delete(injection);
   injection.active = false;
 }
 
 port.onMessage.addListener((message) => {
   switch (message.type) {
--- a/browser/extensions/webcompat/manifest.json
+++ b/browser/extensions/webcompat/manifest.json
@@ -1,13 +1,13 @@
 {
   "manifest_version": 2,
   "name": "Web Compat",
   "description": "Urgent post-release fixes for web compatibility.",
-  "version": "4.2.0",
+  "version": "4.3.0",
 
   "applications": {
     "gecko": {
       "id": "webcompat@mozilla.org",
       "strict_min_version": "59.0b5"
     }
   },
 
--- a/mobile/android/extensions/webcompat/injections.js
+++ b/mobile/android/extensions/webcompat/injections.js
@@ -89,16 +89,25 @@ for (const injection of [
     platform: "desktop",
     domain: "twitch.tv",
     bug: "1518781",
     contentScripts: {
       matches: ["*://*.twitch.tv/*"],
       css: [{file: "injections/css/bug1518781-twitch.tv-webkit-scrollbar.css"}],
     },
   }, {
+    id: "bug1551672",
+    platform: "android",
+    domain: "Sites using PDK 5 video",
+    bug: "1551672",
+    pdk5fix: {
+      urls: ["https://*/*/tpPdk.js", "https://*/*/pdk/js/*/*.js"],
+      types: ["script"],
+    },
+  }, {
     id: "bug1305028",
     platform: "desktop",
     domain: "gaming.youtube.com",
     bug: "1305028",
     contentScripts: {
       matches: ["*://gaming.youtube.com/*"],
       css: [{file: "injections/css/bug1305028-gaming.youtube.com-webkit-scrollbar.css"}],
     },
@@ -121,21 +130,52 @@ async function registerContentScripts() 
       await enableInjection(injection);
     }
   }
 
   InjectionsEnabled = true;
   portsToAboutCompatTabs.broadcast({interventionsChanged: filterOverrides(Injections)});
 }
 
+function replaceStringInRequest(requestId, inString, outString, inEncoding = "utf-8") {
+  const filter = browser.webRequest.filterResponseData(requestId);
+  const decoder = new TextDecoder(inEncoding);
+  const encoder = new TextEncoder();
+  const RE = new RegExp(inString, "g");
+  const carryoverLength = inString.length;
+  let carryover = "";
+  filter.ondata = event => {
+    const replaced = (carryover + decoder.decode(event.data, {stream: true})).replace(RE, outString);
+    filter.write(encoder.encode(replaced.slice(0, -carryoverLength)));
+    carryover = replaced.slice(-carryoverLength);
+  };
+  filter.onstop = event => {
+    if (carryover.length) {
+      filter.write(encoder.encode(carryover));
+    }
+    filter.close();
+  };
+}
+
 async function enableInjection(injection) {
   if (injection.active) {
     return;
   }
 
+  if ("pdk5fix" in injection) {
+    const {urls, types} = injection.pdk5fix;
+    const listener = injection.pdk5fix.listener = ({requestId}) => {
+      replaceStringInRequest(requestId, "VideoContextChromeAndroid", "VideoContextAndroid");
+      return {};
+    };
+    browser.webRequest.onBeforeRequest.addListener(listener, {urls, types}, ["blocking"]);
+    injection.active = true;
+    return;
+  }
+
   try {
     const handle = await browser.contentScripts.register(injection.contentScripts);
     ActiveInjections.set(injection, handle);
     injection.active = true;
   } catch (ex) {
     console.error("Registering WebCompat GoFaster content scripts failed: ", ex);
   }
 }
@@ -148,16 +188,24 @@ function unregisterContentScripts() {
   portsToAboutCompatTabs.broadcast({interventionsChanged: false});
 }
 
 async function disableInjection(injection) {
   if (!injection.active) {
     return;
   }
 
+  if (injection.pdk5fix) {
+    const {listener} = injection.pdk5fix;
+    browser.webRequest.onBeforeRequest.removeListener(listener);
+    injection.active = false;
+    delete injection.pdk5fix.listener;
+    return;
+  }
+
   const contentScript = ActiveInjections.get(injection);
   await contentScript.unregister();
   ActiveInjections.delete(injection);
   injection.active = false;
 }
 
 port.onMessage.addListener((message) => {
   switch (message.type) {
--- a/mobile/android/extensions/webcompat/manifest.json
+++ b/mobile/android/extensions/webcompat/manifest.json
@@ -1,13 +1,13 @@
 {
   "manifest_version": 2,
   "name": "Web Compat",
   "description": "Urgent post-release fixes for web compatibility.",
-  "version": "4.2.0",
+  "version": "4.3.0",
 
   "applications": {
     "gecko": {
       "id": "webcompat@mozilla.org",
       "strict_min_version": "59.0b5"
     }
   },