Permalink
Browse files

Update src/content/whitelistedDOMAPI.jsm

Use documentURIObject for originFromWindow, and adjust allContentWindows iterator to use the window's root docShell for enumeration (rather than enumerating all browsers separately).
  • Loading branch information...
1 parent 93d9c99 commit 647cfd119a4af2716b6814321003bf8789b8f829 @gavinsharp committed Nov 22, 2012
Showing with 12 additions and 18 deletions.
  1. +12 −18 src/content/whitelistedDOMAPI.jsm
@@ -95,34 +95,28 @@ function originFromWindow(win) {
let doc = win.document;
if (!doc)
return null;
- let uriSpec = doc.documentURI;
try {
- let uri = Cc["@mozilla.org/network/io-service;1"].
- getService(Ci.nsIIOService).
- newURI(uriSpec, null, null);
- return uri.scheme + "://" + uri.hostPort;
+ return doc.documentURIObject.prePath;
}
catch (err) {
- log.debug("originFromWindow failed, uri=" + (uriSpec || "(none)"), err);
+ log.debug("originFromWindow failed, uri=" + (doc.documentURI || "(none)"), err);
}
return null;
}
function allContentWindows() {
- let browsers = Cc["@mozilla.org/appshell/window-mediator;1"].
+ let browserWindows = Cc["@mozilla.org/appshell/window-mediator;1"].
getService(Ci.nsIWindowMediator).
getEnumerator("navigator:browser");
- while (browsers.hasMoreElements()) {
- let browserBrowsers = browsers.getNext().gBrowser.browsers;
- for (let i = 0; i < browserBrowsers.length; i++) {
- let contentWins =
- browserBrowsers[i].docShell.
- getDocShellEnumerator(Ci.nsIDocShellTreeItem.typeContent,
- Ci.nsIDocShell.ENUMERATE_FORWARDS);
- while (contentWins.hasMoreElements())
- yield contentWins.getNext().
- QueryInterface(Ci.nsIInterfaceRequestor).
- getInterface(Ci.nsIDOMWindow);
+ while (browserWindows.hasMoreElements()) {
+ let windowDocShell = browserWindows.getNext().getInterface(Ci.nsIDocShell);
@gavinsharp
gavinsharp Nov 22, 2012 owner

Hrm, this should actually be:
browserWindows.getNext().QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDocShell);

to be on the safe side and not rely on xpconnect interface flattening.

+ let contentWins =
+ windowDocShell.getDocShellEnumerator(Ci.nsIDocShellTreeItem.typeContent,
+ Ci.nsIDocShell.ENUMERATE_FORWARDS);
+ while (contentWins.hasMoreElements()) {
+ yield contentWins.getNext().
+ QueryInterface(Ci.nsIInterfaceRequestor).
+ getInterface(Ci.nsIDOMWindow);
}
}
}

0 comments on commit 647cfd1

Please sign in to comment.