OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 "use strict"; | 18 "use strict"; |
19 | 19 |
20 let {PrivateBrowsingUtils} = Cu.import("resource://gre/modules/PrivateBrowsingUt
ils.jsm", {}); | 20 let {PrivateBrowsingUtils} = Cu.import("resource://gre/modules/PrivateBrowsingUt
ils.jsm", {}); |
21 | 21 |
| 22 let {Utils} = require("utils"); |
| 23 |
| 24 /** |
| 25 * Retrieves the effective location of a window. |
| 26 */ |
| 27 let getWindowLocation = exports.getWindowLocation = function(/**Window*/ window)
/**String*/ |
| 28 { |
| 29 let result = null; |
| 30 |
| 31 // Crazy Thunderbird stuff |
| 32 if ("name" in window && window.name == "messagepane") |
| 33 { |
| 34 try |
| 35 { |
| 36 let mailWnd = window.QueryInterface(Ci.nsIInterfaceRequestor) |
| 37 .getInterface(Ci.nsIWebNavigation) |
| 38 .QueryInterface(Ci.nsIDocShellTreeItem) |
| 39 .rootTreeItem |
| 40 .QueryInterface(Ci.nsIInterfaceRequestor) |
| 41 .getInterface(Ci.nsIDOMWindow); |
| 42 |
| 43 // Typically we get a wrapped mail window here, need to unwrap |
| 44 try |
| 45 { |
| 46 mailWnd = mailWnd.wrappedJSObject; |
| 47 } catch(e) {} |
| 48 |
| 49 if ("currentHeaderData" in mailWnd && "content-base" in mailWnd.currentHea
derData) |
| 50 { |
| 51 result = mailWnd.currentHeaderData["content-base"].headerValue; |
| 52 } |
| 53 else if ("currentHeaderData" in mailWnd && "from" in mailWnd.currentHeader
Data) |
| 54 { |
| 55 let emailAddress = Utils.headerParser.extractHeaderAddressMailboxes(mail
Wnd.currentHeaderData.from.headerValue); |
| 56 if (emailAddress) |
| 57 result = 'mailto:' + emailAddress.replace(/^[\s"]+/, "").replace(/[\s"
]+$/, "").replace(/\s/g, '%20'); |
| 58 } |
| 59 } catch(e) {} |
| 60 } |
| 61 |
| 62 // Sane branch |
| 63 if (!result) |
| 64 result = window.location.href; |
| 65 |
| 66 // Remove the anchor if any |
| 67 let index = result.indexOf("#"); |
| 68 if (index >= 0) |
| 69 result = result.substring(0, index); |
| 70 |
| 71 return result; |
| 72 } |
| 73 |
22 /** | 74 /** |
23 * Retrieves the frame hierarchy for a window. Returns an array containing | 75 * Retrieves the frame hierarchy for a window. Returns an array containing |
24 * the information for all frames, starting with the window itself up to its | 76 * the information for all frames, starting with the window itself up to its |
25 * top-level window. Each entry has a location and a sitekey entry. | 77 * top-level window. Each entry has a location and a sitekey entry. |
26 * @return {Array} | 78 * @return {Array} |
27 */ | 79 */ |
28 let getFrames = exports.getFrames = function(/**Window*/ window) | 80 let getFrames = exports.getFrames = function(/**Window*/ window) |
29 { | 81 { |
30 let frames = []; | 82 let frames = []; |
31 while (window) | 83 while (window) |
32 { | 84 { |
33 let frame = { | 85 let frame = { |
34 location: window.location.href, | 86 location: getWindowLocation(window), |
35 sitekey: null | 87 sitekey: null |
36 }; | 88 }; |
37 | 89 |
38 let documentElement = window.document && window.document.documentElement; | 90 let documentElement = window.document && window.document.documentElement; |
39 if (documentElement) | 91 if (documentElement) |
40 frame.sitekey = documentElement.getAttribute("data-adblockkey") | 92 frame.sitekey = documentElement.getAttribute("data-adblockkey") |
41 | 93 |
42 frames.push(frame); | 94 frames.push(frame); |
43 window = (window != window.parent ? window.parent : null); | 95 window = (window != window.parent ? window.parent : null); |
44 } | 96 } |
| 97 |
| 98 // URLs like about:blank inherit their security context from upper-level |
| 99 // frames, resolve their URLs accordingly. |
| 100 for (let i = frames.length - 2; i >= 0; i--) |
| 101 { |
| 102 let frame = frames[i]; |
| 103 if (frame.location == "about:blank" || frame.location == "moz-safe-about:bla
nk" || |
| 104 Utils.netUtils.URIChainHasFlags(Utils.makeURI(frame.location), Ci.nsIPro
tocolHandler.URI_INHERITS_SECURITY_CONTEXT)) |
| 105 { |
| 106 frame.location = frames[i + 1].location; |
| 107 } |
| 108 } |
| 109 |
45 return frames; | 110 return frames; |
46 }; | 111 }; |
47 | 112 |
48 /** | 113 /** |
49 * Checks whether Private Browsing mode is enabled for a content window. | 114 * Checks whether Private Browsing mode is enabled for a content window. |
50 * @return {Boolean} | 115 * @return {Boolean} |
51 */ | 116 */ |
52 let isPrivate = exports.isPrivate = function(/**Window*/ window) | 117 let isPrivate = exports.isPrivate = function(/**Window*/ window) |
53 { | 118 { |
54 return PrivateBrowsingUtils.isContentWindowPrivate(window); | 119 return PrivateBrowsingUtils.isContentWindowPrivate(window); |
55 }; | 120 }; |
OLD | NEW |