| Index: lib/child/utils.js | 
| =================================================================== | 
| new file mode 100644 | 
| --- /dev/null | 
| +++ b/lib/child/utils.js | 
| @@ -0,0 +1,124 @@ | 
| +/* | 
| + * This file is part of Adblock Plus <https://adblockplus.org/>, | 
| + * Copyright (C) 2006-2015 Eyeo GmbH | 
| + * | 
| + * Adblock Plus is free software: you can redistribute it and/or modify | 
| + * it under the terms of the GNU General Public License version 3 as | 
| + * published by the Free Software Foundation. | 
| + * | 
| + * Adblock Plus is distributed in the hope that it will be useful, | 
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
| + * GNU General Public License for more details. | 
| + * | 
| + * You should have received a copy of the GNU General Public License | 
| + * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 
| + */ | 
| + | 
| +let {PrivateBrowsingUtils} = Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm", {}); | 
| + | 
| +let {Utils} = require("utils"); | 
| + | 
| +/** | 
| + * Retrieves the frame hierarchie for a window. Returns an array containing | 
| + * the information for all frames, starting with the window itself up to its | 
| + * top-level window. Each entry has a location and a sitekey entry. | 
| + * @return {Array} | 
| + */ | 
| +let getFrames = exports.getFrames = function(/**Window*/ window) | 
| +{ | 
| + let frames = []; | 
| + while (window) | 
| + { | 
| + let frame = { | 
| + location: getWindowLocation(window), | 
| + sitekey: null | 
| + }; | 
| + | 
| + let documentElement = window.document && window.document.documentElement; | 
| + if (documentElement) | 
| + frame.sitekey = documentElement.getAttribute("data-adblockkey") | 
| + | 
| + frames.push(frame); | 
| + window = (window != window.parent ? window.parent : null); | 
| + } | 
| + | 
| + // URLs like about:blank inherit their security context from upper-level | 
| + // frames, resolve their URLs accordingly. | 
| + for (let i = frames.length - 2; i >= 0; i--) | 
| + { | 
| + let frame = frames[i]; | 
| + if (frame.location == "about:blank" || frame.location != "moz-safe-about:blank" || | 
| + !Utils.netUtils.URIChainHasFlags(Utils.makeURI(frame.location), Ci.nsIProtocolHandler.URI_INHERITS_SECURITY_CONTEXT)) | 
| + { | 
| + frames[i].location = frames[i + 1].location; | 
| + } | 
| + } | 
| 
 
Wladimir Palant
2015/10/22 21:51:13
The block above is something we have been doing in
 
 | 
| + | 
| + return frames; | 
| +} | 
| + | 
| +let isPrivate = exports.isPrivate = function(/**Window*/ window) | 
| +{ | 
| + return PrivateBrowsingUtils.isWindowPrivate(window); | 
| +}; | 
| + | 
| +/** | 
| + * Retrieves the window for a document node. | 
| + * @return {Window} will be null if the node isn't associated with a window | 
| + */ | 
| +let getWindow = exports.getWindow = function(/**Node*/ node) | 
| +{ | 
| + if (!node) | 
| + return null; | 
| + | 
| + if ("ownerDocument" in node && node.ownerDocument) | 
| + node = node.ownerDocument; | 
| + | 
| + if ("defaultView" in node) | 
| + return node.defaultView; | 
| + | 
| + return null; | 
| +} | 
| + | 
| +/** | 
| + * Retrieves the location of a window. | 
| + * @return {String} window location or null on failure | 
| + */ | 
| +function getWindowLocation(/**Window*/ wnd) | 
| +{ | 
| + if ("name" in wnd && wnd.name == "messagepane") | 
| + { | 
| + // Thunderbird branch | 
| + try | 
| + { | 
| + let mailWnd = wnd.QueryInterface(Ci.nsIInterfaceRequestor) | 
| + .getInterface(Ci.nsIWebNavigation) | 
| + .QueryInterface(Ci.nsIDocShellTreeItem) | 
| + .rootTreeItem | 
| + .QueryInterface(Ci.nsIInterfaceRequestor) | 
| + .getInterface(Ci.nsIDOMWindow); | 
| + | 
| + // Typically we get a wrapped mail window here, need to unwrap | 
| + try | 
| + { | 
| + mailWnd = mailWnd.wrappedJSObject; | 
| + } catch(e) {} | 
| + | 
| + if ("currentHeaderData" in mailWnd && "content-base" in mailWnd.currentHeaderData) | 
| + { | 
| + return mailWnd.currentHeaderData["content-base"].headerValue; | 
| + } | 
| + else if ("currentHeaderData" in mailWnd && "from" in mailWnd.currentHeaderData) | 
| + { | 
| + let emailAddress = Utils.headerParser.extractHeaderAddressMailboxes(mailWnd.currentHeaderData.from.headerValue); | 
| + if (emailAddress) | 
| + return 'mailto:' + emailAddress.replace(/^[\s"]+/, "").replace(/[\s"]+$/, "").replace(/\s/g, '%20'); | 
| + } | 
| + } catch(e) {} | 
| + } | 
| + | 
| + // Firefox branch | 
| + return wnd.location.href; | 
| +} | 
| + |