1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
/*
* This file is part of Adblock Plus <https://adblockplus.org/>,
* Copyright (C) 2006-2017 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/>.
*/
"use strict";
let {PrivateBrowsingUtils} = Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm", {});
let {Utils} = require("utils");
/**
* Retrieves the effective location of a window.
*/
let getWindowLocation = exports.getWindowLocation = function(/**Window*/ window) /**String*/
{
let result = null;
// Crazy Thunderbird stuff
if ("name" in window && window.name == "messagepane")
{
try
{
let mailWnd = window.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)
{
result = 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)
result = 'mailto:' + emailAddress.replace(/^[\s"]+/, "").replace(/[\s"]+$/, "").replace(/\s/g, '%20');
}
} catch(e) {}
}
// Sane branch
if (!result)
result = window.location.href;
// Remove the anchor if any
let index = result.indexOf("#");
if (index >= 0)
result = result.substring(0, index);
return result;
}
/**
* Retrieves the frame hierarchy 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" ||
frame.location == "about:srcdoc" ||
Utils.netUtils.URIChainHasFlags(Utils.makeURI(frame.location), Ci.nsIProtocolHandler.URI_INHERITS_SECURITY_CONTEXT))
{
frame.location = frames[i + 1].location;
}
}
return frames;
};
/**
* Checks whether Private Browsing mode is enabled for a content window.
* @return {Boolean}
*/
let isPrivate = exports.isPrivate = function(/**Window*/ window)
{
return PrivateBrowsingUtils.isContentWindowPrivate(window);
};
/**
* Gets the DOM window associated with a particular request (if any).
*/
let getRequestWindow = exports.getRequestWindow = function(/**nsIChannel*/ channel) /**nsIDOMWindow*/
{
try
{
if (channel.notificationCallbacks)
return channel.notificationCallbacks.getInterface(Ci.nsILoadContext).associatedWindow;
} catch(e) {}
try
{
if (channel.loadGroup && channel.loadGroup.notificationCallbacks)
return channel.loadGroup.notificationCallbacks.getInterface(Ci.nsILoadContext).associatedWindow;
} catch(e) {}
return null;
};
|