Bug 766871 - Part 1: window.open in <iframe> in in-process <iframe mozbrowser> should work. r=bz
authorJustin Lebar <justin.lebar@gmail.com>
Sat, 23 Jun 2012 11:05:12 -0400
changeset 106399 6222b149e94e14997ab0d65afe338e22ee614883
parent 106398 96aacfacb5ed5360791024231dc3bf2a3890f50c
child 106400 80fe492a0d5fbc745fbad96bd76c22eca89581b0
push id23447
push userdanderson@mozilla.com
push dateTue, 11 Sep 2012 17:34:27 +0000
treeherdermozilla-central@fdfaef738a00 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs766871
milestone16.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 766871 - Part 1: window.open in <iframe> in in-process <iframe mozbrowser> should work. r=bz
content/base/src/nsINode.cpp
dom/browser-element/BrowserElementParent.cpp
--- a/dom/browser-element/BrowserElementParent.cpp
+++ b/dom/browser-element/BrowserElementParent.cpp
@@ -165,22 +165,33 @@ BrowserElementParent::OpenWindowOOP(mozi
 BrowserElementParent::OpenWindowInProcess(nsIDOMWindow* aOpenerWindow,
                                           nsIURI* aURI,
                                           const nsAString& aName,
                                           const nsACString& aFeatures,
                                           nsIDOMWindow** aReturnWindow)
 {
   *aReturnWindow = NULL;
 
+  // If we call window.open from an <iframe> inside an <iframe mozbrowser>,
+  // it's as though the top-level document inside the <iframe mozbrowser>
+  // called window.open.  (Indeed, in the OOP case, the inner <iframe> lives
+  // out-of-process, so we couldn't touch it if we tried.)
+  //
+  // GetScriptableTop gets us the <iframe mozbrowser>'s window; we'll use its
+  // frame element, rather than aOpenerWindow's frame element, as our "opener
+  // frame element" below.
+  nsCOMPtr<nsIDOMWindow> topWindow;
+  aOpenerWindow->GetScriptableTop(getter_AddRefs(topWindow));
+
   nsCOMPtr<nsIDOMElement> openerFrameDOMElement;
-  aOpenerWindow->GetFrameElement(getter_AddRefs(openerFrameDOMElement));
+  topWindow->GetFrameElement(getter_AddRefs(openerFrameDOMElement));
   NS_ENSURE_TRUE(openerFrameDOMElement, false);
 
-  nsCOMPtr<nsINode> openerFrameNode = do_QueryInterface(openerFrameDOMElement);
-  nsRefPtr<Element> openerFrameElement = openerFrameNode->AsElement();
+  nsCOMPtr<Element> openerFrameElement =
+    do_QueryInterface(openerFrameDOMElement);
 
   nsRefPtr<nsHTMLIFrameElement> popupFrameElement =
     CreateIframe(openerFrameElement);
   NS_ENSURE_TRUE(popupFrameElement, false);
 
   nsCAutoString spec;
   aURI->GetSpec(spec);
   bool dispatchSucceeded =