mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-08 06:04:12 +01:00
Add util.iterFrames.
This commit is contained in:
@@ -363,17 +363,13 @@ var Buffer = Module("Buffer", {
|
|||||||
/**
|
/**
|
||||||
* Returns a list of all frames in the given window or current buffer.
|
* Returns a list of all frames in the given window or current buffer.
|
||||||
*/
|
*/
|
||||||
allFrames: function allFrames(win, focusedFirst) {
|
allFrames: function allFrames(win=this.win, focusedFirst) {
|
||||||
let frames = [];
|
let frames = iter(util.iterFrames(win)).toArray();
|
||||||
(function rec(frame) {
|
|
||||||
if (true || frame.document.body instanceof Ci.nsIDOMHTMLBodyElement)
|
|
||||||
frames.push(frame);
|
|
||||||
Array.forEach(frame.frames, rec);
|
|
||||||
})(win || this.win);
|
|
||||||
|
|
||||||
if (focusedFirst)
|
if (focusedFirst)
|
||||||
return frames.filter(f => f === this.focusedFrame).concat(
|
return frames.filter(f => f === this.focusedFrame).concat(
|
||||||
frames.filter(f => f !== this.focusedFrame));
|
frames.filter(f => f !== this.focusedFrame));
|
||||||
|
|
||||||
return frames;
|
return frames;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -2337,7 +2333,7 @@ var Buffer = Module("Buffer", {
|
|||||||
if (count >= 1 || !elem || !events.isContentNode(elem)) {
|
if (count >= 1 || !elem || !events.isContentNode(elem)) {
|
||||||
let xpath = ["frame", "iframe", "input", "xul:textbox", "textarea[not(@disabled) and not(@readonly)]"];
|
let xpath = ["frame", "iframe", "input", "xul:textbox", "textarea[not(@disabled) and not(@readonly)]"];
|
||||||
|
|
||||||
let frames = buffer.allFrames(null, true);
|
let frames = buffer.allFrames(undefined, true);
|
||||||
|
|
||||||
let elements = Ary.flatten(frames.map(win => [m for (m of DOM.XPath(xpath, win.document))]))
|
let elements = Ary.flatten(frames.map(win => [m for (m of DOM.XPath(xpath, win.document))]))
|
||||||
.filter(function (elem) {
|
.filter(function (elem) {
|
||||||
|
|||||||
@@ -1704,6 +1704,19 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterates, depth-first, over the given window and all of its descendant
|
||||||
|
* frames.
|
||||||
|
*
|
||||||
|
* @param {nsIDOMWindow} win The root window.
|
||||||
|
* @returns {Generator(nsIDOMWindow)}
|
||||||
|
*/
|
||||||
|
iterFrames: function* iterFrames(win) {
|
||||||
|
yield win;
|
||||||
|
for (let i = 0; i < win.frames.length; i++)
|
||||||
|
yield* iterFrames(win.frames[i]);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of all domains and subdomains of documents in the
|
* Returns a list of all domains and subdomains of documents in the
|
||||||
* given window and all of its descendant frames.
|
* given window and all of its descendant frames.
|
||||||
@@ -1712,16 +1725,14 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
|||||||
* @returns {[string]} The visible domains.
|
* @returns {[string]} The visible domains.
|
||||||
*/
|
*/
|
||||||
visibleHosts: function visibleHosts(win) {
|
visibleHosts: function visibleHosts(win) {
|
||||||
let res = [],
|
let res = [], seen = new RealSet;
|
||||||
seen = new RealSet;
|
for (let frame of this.iterFrames(win)) {
|
||||||
(function rec(frame) {
|
|
||||||
try {
|
try {
|
||||||
if (frame.location.hostname)
|
if (frame.location.hostname)
|
||||||
res = res.concat(util.subdomains(frame.location.hostname));
|
res = res.concat(util.subdomains(frame.location.hostname));
|
||||||
}
|
}
|
||||||
catch (e) {}
|
catch (e) {}
|
||||||
Array.forEach(frame.frames, rec);
|
}
|
||||||
})(win);
|
|
||||||
return res.filter(h => !seen.add(h));
|
return res.filter(h => !seen.add(h));
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -1733,15 +1744,13 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
|||||||
* @returns {[nsIURI]} The visible URIs.
|
* @returns {[nsIURI]} The visible URIs.
|
||||||
*/
|
*/
|
||||||
visibleURIs: function visibleURIs(win) {
|
visibleURIs: function visibleURIs(win) {
|
||||||
let res = [],
|
let res = [], seen = new RealSet;
|
||||||
seen = new RealSet;
|
for (let frame of this.iterFrames(win)) {
|
||||||
(function rec(frame) {
|
|
||||||
try {
|
try {
|
||||||
res = res.concat(util.newURI(frame.location.href));
|
res.push(util.newURI(frame.location.href));
|
||||||
}
|
}
|
||||||
catch (e) {}
|
catch (e) {}
|
||||||
Array.forEach(frame.frames, rec);
|
}
|
||||||
})(win);
|
|
||||||
return res.filter(h => !seen.add(h.spec));
|
return res.filter(h => !seen.add(h.spec));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user