Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/child/utils.js

Issue 29329336: Issue 3208 - Inject content policy implementation into all processes (Closed)
Patch Set: Created Oct. 22, 2015, 9:03 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
18 let {PrivateBrowsingUtils} = Cu.import("resource://gre/modules/PrivateBrowsingUt ils.jsm", {});
19
20 let {Utils} = require("utils");
21
22 /**
23 * Retrieves the frame hierarchie for a window. Returns an array containing
24 * 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.
26 * @return {Array}
27 */
28 let getFrames = exports.getFrames = function(/**Window*/ window)
29 {
30 let frames = [];
31 while (window)
32 {
33 let frame = {
34 location: getWindowLocation(window),
35 sitekey: null
36 };
37
38 let documentElement = window.document && window.document.documentElement;
39 if (documentElement)
40 frame.sitekey = documentElement.getAttribute("data-adblockkey")
41
42 frames.push(frame);
43 window = (window != window.parent ? window.parent : null);
44 }
45
46 // URLs like about:blank inherit their security context from upper-level
47 // frames, resolve their URLs accordingly.
48 for (let i = frames.length - 2; i >= 0; i--)
49 {
50 let frame = frames[i];
51 if (frame.location == "about:blank" || frame.location != "moz-safe-about:bla nk" ||
52 !Utils.netUtils.URIChainHasFlags(Utils.makeURI(frame.location), Ci.nsIPr otocolHandler.URI_INHERITS_SECURITY_CONTEXT))
53 {
54 frames[i].location = frames[i + 1].location;
55 }
56 }
Wladimir Palant 2015/10/22 21:51:13 The block above is something we have been doing in
57
58 return frames;
59 }
60
61 let isPrivate = exports.isPrivate = function(/**Window*/ window)
62 {
63 return PrivateBrowsingUtils.isWindowPrivate(window);
64 };
65
66 /**
67 * Retrieves the window for a document node.
68 * @return {Window} will be null if the node isn't associated with a window
69 */
70 let getWindow = exports.getWindow = function(/**Node*/ node)
71 {
72 if (!node)
73 return null;
74
75 if ("ownerDocument" in node && node.ownerDocument)
76 node = node.ownerDocument;
77
78 if ("defaultView" in node)
79 return node.defaultView;
80
81 return null;
82 }
83
84 /**
85 * Retrieves the location of a window.
86 * @return {String} window location or null on failure
87 */
88 function getWindowLocation(/**Window*/ wnd)
89 {
90 if ("name" in wnd && wnd.name == "messagepane")
91 {
92 // Thunderbird branch
93 try
94 {
95 let mailWnd = wnd.QueryInterface(Ci.nsIInterfaceRequestor)
96 .getInterface(Ci.nsIWebNavigation)
97 .QueryInterface(Ci.nsIDocShellTreeItem)
98 .rootTreeItem
99 .QueryInterface(Ci.nsIInterfaceRequestor)
100 .getInterface(Ci.nsIDOMWindow);
101
102 // Typically we get a wrapped mail window here, need to unwrap
103 try
104 {
105 mailWnd = mailWnd.wrappedJSObject;
106 } catch(e) {}
107
108 if ("currentHeaderData" in mailWnd && "content-base" in mailWnd.currentHea derData)
109 {
110 return mailWnd.currentHeaderData["content-base"].headerValue;
111 }
112 else if ("currentHeaderData" in mailWnd && "from" in mailWnd.currentHeader Data)
113 {
114 let emailAddress = Utils.headerParser.extractHeaderAddressMailboxes(mail Wnd.currentHeaderData.from.headerValue);
115 if (emailAddress)
116 return 'mailto:' + emailAddress.replace(/^[\s"]+/, "").replace(/[\s"]+ $/, "").replace(/\s/g, '%20');
117 }
118 } catch(e) {}
119 }
120
121 // Firefox branch
122 return wnd.location.href;
123 }
124
OLDNEW

Powered by Google App Engine
This is Rietveld