Skip to content

Commit

Permalink
[CRX] Drop code supporting ancient Chrome versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob--W committed Jul 2, 2023
1 parent 2c74323 commit 70db938
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 76 deletions.
6 changes: 1 addition & 5 deletions extensions/chromium/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ function getViewerURL(pdf_url) {
return VIEWER_URL + "?file=" + encodeURIComponent(pdf_url);
}

if (CSS.supports("animation", "0s")) {
document.addEventListener("animationstart", onAnimationStart, true);
} else {
document.addEventListener("webkitAnimationStart", onAnimationStart, true);
}
document.addEventListener("animationstart", onAnimationStart, true);

function onAnimationStart(event) {
if (event.animationName === "pdfjs-detected-object-or-embed") {
Expand Down
8 changes: 0 additions & 8 deletions extensions/chromium/contentstyle.css
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
/**
* Detect creation of <embed> and <object> tags.
*/
@-webkit-keyframes pdfjs-detected-object-or-embed {
from {
/* empty */
}
}
@keyframes pdfjs-detected-object-or-embed {
from {
/* empty */
}
}
object,
embed {
-webkit-animation-delay: 0s !important;
-webkit-animation-name: pdfjs-detected-object-or-embed !important;
-webkit-animation-play-state: running !important;
animation-delay: 0s !important;
animation-name: pdfjs-detected-object-or-embed !important;
animation-play-state: running !important;
Expand Down
21 changes: 1 addition & 20 deletions extensions/chromium/pdfHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,7 @@ chrome.webRequest.onBeforeRequest.addListener(
return { redirectUrl: viewerUrl };
},
{
urls: [
"file://*/*.pdf",
"file://*/*.PDF",
...// Duck-typing: MediaError.prototype.message was added in Chrome 59.
(MediaError.prototype.hasOwnProperty("message")
? []
: [
// Note: Chrome 59 has disabled ftp resource loading by default:
// https://www.chromestatus.com/feature/5709390967472128
"ftp://*/*.pdf",
"ftp://*/*.PDF",
]),
],
urls: ["file://*/*.pdf", "file://*/*.PDF"],
types: ["main_frame", "sub_frame"],
},
["blocking"]
Expand Down Expand Up @@ -252,10 +240,3 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
}
return undefined;
});

// Remove keys from storage that were once part of the deleted feature-detect.js
chrome.storage.local.remove([
"featureDetectLastUA",
"webRequestRedirectUrl",
"extensionSupportsFTP",
]);
28 changes: 8 additions & 20 deletions extensions/chromium/preserve-referer.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,18 @@ var g_requestHeaders = {};
// g_referrers[tabId][frameId] = referrer of PDF frame.
var g_referrers = {};

var extraInfoSpecWithHeaders; // = ['requestHeaders', 'extraHeaders']

(function () {
var requestFilter = {
urls: ["*://*/*"],
types: ["main_frame", "sub_frame"],
};
function registerListener(extraInfoSpec) {
extraInfoSpecWithHeaders = extraInfoSpec;
// May throw if the given extraInfoSpec is unsupported.
chrome.webRequest.onSendHeaders.addListener(
function (details) {
g_requestHeaders[details.requestId] = details.requestHeaders;
},
requestFilter,
extraInfoSpec
);
}
try {
registerListener(["requestHeaders", "extraHeaders"]);
} catch {
// "extraHeaders" is not supported in Chrome 71 and earlier.
registerListener(["requestHeaders"]);
}
chrome.webRequest.onSendHeaders.addListener(
function (details) {
g_requestHeaders[details.requestId] = details.requestHeaders;
},
requestFilter,
["requestHeaders", "extraHeaders"]
);
chrome.webRequest.onBeforeRedirect.addListener(forgetHeaders, requestFilter);
chrome.webRequest.onCompleted.addListener(forgetHeaders, requestFilter);
chrome.webRequest.onErrorOccurred.addListener(forgetHeaders, requestFilter);
Expand Down Expand Up @@ -126,7 +114,7 @@ chrome.runtime.onConnect.addListener(function onReceivePort(port) {
types: ["xmlhttprequest"],
tabId,
},
["blocking", ...extraInfoSpecWithHeaders]
["blocking", "requestHeaders", "extraHeaders"]
);
}
// Acknowledge the message, and include the latest referer for this frame.
Expand Down
37 changes: 14 additions & 23 deletions extensions/chromium/telemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,29 +70,20 @@ limitations under the License.

var deduplication_id = getDeduplicationId(wasUpdated);
var extension_version = chrome.runtime.getManifest().version;
if (window.Request && "mode" in Request.prototype) {
// fetch is supported in extensions since Chrome 42 (though the above
// feature-detection method detects Chrome 43+).
// Unlike XMLHttpRequest, fetch omits credentials such as cookies in the
// requests, which guarantees that the server cannot track the client
// via HTTP cookies.
fetch(LOG_URL, {
method: "POST",
headers: new Headers({
"Deduplication-Id": deduplication_id,
"Extension-Version": extension_version,
}),
// Set mode=cors so that the above custom headers are included in the
// request.
mode: "cors",
});
return;
}
var x = new XMLHttpRequest();
x.open("POST", LOG_URL);
x.setRequestHeader("Deduplication-Id", deduplication_id);
x.setRequestHeader("Extension-Version", extension_version);
x.send();
fetch(LOG_URL, {
method: "POST",
headers: new Headers({
"Deduplication-Id": deduplication_id,
"Extension-Version": extension_version,
}),
// Set mode=cors so that the above custom headers are included in the
// request.
mode: "cors",
// Omits credentials such as cookies in the requests, which guarantees
// that the server cannot track the client via HTTP cookies.
credentials: "omit",
cache: "no-store",
});
});
}

Expand Down

0 comments on commit 70db938

Please sign in to comment.