Bug 841850 - Check the target of a link click and update the content type from TYPE_SUBDOCUMENT to TYPE_DOCUMENT if the target is a new document. r=bz
authorTanvi Vyas <tvyas@mozilla.com>
Wed, 27 Mar 2013 22:24:00 -0700
changeset 126528 f46bbb876415cf01aa646aa6a646205e96555e87
parent 126527 844ef68557d8339001a1dc7ea25a10737be07bb1
child 126529 95274843db65e4ae1d23a88738628448cc266e27
push id24485
push userryanvm@gmail.com
push dateThu, 28 Mar 2013 12:31:20 +0000
treeherdermozilla-central@293498096b28 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs841850
milestone22.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 841850 - Check the target of a link click and update the content type from TYPE_SUBDOCUMENT to TYPE_DOCUMENT if the target is a new document. r=bz
docshell/base/nsDocShell.cpp
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -8626,17 +8626,30 @@ nsDocShell::InternalLoad(nsIURI * aURI,
     nsCOMPtr<nsIDOMElement> requestingElement;
     // Use nsPIDOMWindow since we _want_ to cross the chrome boundary if needed
     nsCOMPtr<nsPIDOMWindow> privateWin(do_QueryInterface(mScriptGlobal));
     if (privateWin)
         requestingElement = privateWin->GetFrameElementInternal();
 
     int16_t shouldLoad = nsIContentPolicy::ACCEPT;
     uint32_t contentType;
-    if (IsFrame()) {
+    bool isNewDocShell = false;
+    nsCOMPtr<nsIDocShell> targetDocShell;
+    if (aWindowTarget && *aWindowTarget) {
+        // Locate the target DocShell.
+        nsCOMPtr<nsIDocShellTreeItem> targetItem;
+        FindItemWithName(aWindowTarget, nullptr, this,
+                         getter_AddRefs(targetItem));
+
+        targetDocShell = do_QueryInterface(targetItem);
+        // If the targetDocShell doesn't exist, then this is a new docShell
+        // and we should consider this a TYPE_DOCUMENT load
+        isNewDocShell = !targetDocShell;
+    }
+    if (IsFrame() && !isNewDocShell) {
         NS_ASSERTION(requestingElement, "A frame but no DOM element!?");
         contentType = nsIContentPolicy::TYPE_SUBDOCUMENT;
     } else {
         contentType = nsIContentPolicy::TYPE_DOCUMENT;
     }
 
     nsISupports* context = requestingElement;
     if (!context) {
@@ -8729,25 +8742,16 @@ nsDocShell::InternalLoad(nsIURI * aURI,
     // load to it...
     //
     if (aWindowTarget && *aWindowTarget) {
         // We've already done our owner-inheriting.  Mask out that bit, so we
         // don't try inheriting an owner from the target window if we came up
         // with a null owner above.
         aFlags = aFlags & ~INTERNAL_LOAD_FLAGS_INHERIT_OWNER;
         
-        // Locate the target DocShell.
-        // This may involve creating a new toplevel window - if necessary.
-        //
-        nsCOMPtr<nsIDocShellTreeItem> targetItem;
-        FindItemWithName(aWindowTarget, nullptr, this,
-                         getter_AddRefs(targetItem));
-
-        nsCOMPtr<nsIDocShell> targetDocShell = do_QueryInterface(targetItem);
-        
         bool isNewWindow = false;
         if (!targetDocShell) {
             // If the docshell's document is sandboxed and was trying to
             // navigate/load a frame it wasn't allowed to access, the
             // FindItemWithName above will have returned null for the target
             // item - we don't want to actually open a new window in this case
             // though. Check if we are sandboxed and bail out here if so.
             NS_ENSURE_TRUE(mContentViewer, NS_ERROR_FAILURE);