Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
/**
* Send
* - current URL
* - cookies of this page
* - all links found in this page
* to the native application.
*/
function sendCurrentState() {
let message = {
'url': document.location.href,
'urls': getLinks(),
'cookies': getCookies()
'urls': getLinks()
};

webkit.messageHandlers.adsMessageHandler.postMessage(message);
Comment on lines -15 to 17
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the adsMessageHandler processing it, I only ever see iterating over the links:

let body = message.body as? [String: Any],
let urls = body["urls"] as? [String] else { return }

but no cookie info (from message body["cookies"]) is ever parsed.

It also appears the whole message payload is never stored raw, so that would hint at only parsing the explicit values, which is currently just the links.

Expand All @@ -38,56 +36,6 @@ function getLinks() {
return urls;
}

/**
* Get all cookies for the current document.
*
* @return {Array<{name: string, value: string}>} containing all cookies.
*/
function getCookies() {
let cookiesList = safeCookiesList();
let result = [];

cookiesList.forEach(cookie => {
var [name, ...value] = cookie.split('=');
// For that special cases where the value contains '='.
value = value.join("=")

result.push({
"name" : name,
"value" : value
});
});

return result;
}

// FXIOS-13891: WebKit process crashes on cross-origin cookie operation on about:blank tabs
// Helper method to verify via SecurityError earlier than touching the document crashes it
function safeCookiesList() {
let documentCookies = [];

const isNewTab = window.location.protocol == "about:";
const hasOpener = !!window.opener;
const hasParent = hasOpener && window.opener.parent != window.opener;

// Special-casing only different origins coming from different frames in new tabs
if (isNewTab && hasOpener && hasParent) {
const frameParent = window.opener.parent;
// Positively catch the SecurityError on the conditional as a way to not touch the cookie inside
try {
if (frameParent.location.origin == window.opener.location.origin) {
documentCookies = document.cookie.split("; ");
}
} catch {
documentCookies = [""];
}
} else {
documentCookies = document.cookie.split("; ");
}

return documentCookies;
}

// Whenever a page is first accessed or when loaded from cache
// send all needed data about the ads provider to the app.
const events = ["pageshow", "load"];
Expand Down
27 changes: 1 addition & 26 deletions focus-ios/Blockzilla/Ads.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
/**
* Send
* - current URL
* - cookies of this page
* - all links found in this page
* to the native application.
*/
function sendCurrentState() {
let message = {
'url': document.location.href,
'urls': getLinks(),
'cookies': getCookies()
'urls': getLinks()
};

webkit.messageHandlers.adsMessageHandler.postMessage(message);
Expand All @@ -41,29 +39,6 @@ function getLinks() {
return urls;
}

/**
* Get all cookies for the current document.
*
* @return {Array<{name: string, value: string}>} containing all cookies.
*/
function getCookies() {
let cookiesList = document.cookie.split("; ");
let result = [];

cookiesList.forEach(cookie => {
var [name, ...value] = cookie.split('=');
// For that special cases where the value contains '='.
value = value.join("=")

result.push({
"name" : name,
"value" : value
});
});

return result;
}

// Whenever a page is first accessed or when loaded from cache
// send all needed data about the ads provider to the app.
const events = ["pageshow", "load"];
Expand Down
Loading