Bug 902350 - Set the appropriate content type when navigating a frame with a target that changes the top level document. r=smaug, a=bajaj
authorTanvi Vyas <tvyas@mozilla.com>
Sun, 18 Aug 2013 12:32:17 -0700
changeset 148381 8959a853c1f0
parent 148380 2d0439c5138f
child 148382 209b28130fd1
push id2772
push userryanvm@gmail.com
push date2013-08-19 16:05 +0000
treeherdermozilla-beta@209b28130fd1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, bajaj
bugs902350
milestone24.0
Bug 902350 - Set the appropriate content type when navigating a frame with a target that changes the top level document. r=smaug, a=bajaj
docshell/base/nsDocShell.cpp
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -8607,29 +8607,45 @@ nsDocShell::InternalLoad(nsIURI * aURI,
     if (mScriptGlobal)
         requestingElement = mScriptGlobal->GetFrameElementInternal();
 
     nsRefPtr<nsGlobalWindow> MMADeathGrip = mScriptGlobal;
 
     int16_t shouldLoad = nsIContentPolicy::ACCEPT;
     uint32_t contentType;
     bool isNewDocShell = false;
+    bool isTargetTopLevelDocShell = 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) {
+
+        // If the targetDocShell and the rootDocShell are the same, then the
+        // targetDocShell is the top level document and hence we should
+        // consider this TYPE_DOCUMENT
+        if (targetDocShell) {
+          nsCOMPtr<nsIDocShellTreeItem> sameTypeRoot;
+          targetDocShell->GetSameTypeRootTreeItem(getter_AddRefs(sameTypeRoot));
+          NS_ASSERTION(sameTypeRoot, "No document shell root tree item from targetDocShell!");
+          nsCOMPtr<nsIDocShell> rootShell = do_QueryInterface(sameTypeRoot);
+          NS_ASSERTION(rootShell, "No root docshell from document shell root tree item.");
+
+          if (targetDocShell == rootShell) {
+            isTargetTopLevelDocShell = true;
+          }
+        }
+    }
+    if (IsFrame() && !isNewDocShell && !isTargetTopLevelDocShell) {
         NS_ASSERTION(requestingElement, "A frame but no DOM element!?");
         contentType = nsIContentPolicy::TYPE_SUBDOCUMENT;
     } else {
         contentType = nsIContentPolicy::TYPE_DOCUMENT;
     }
 
     nsISupports* context = requestingElement;
     if (!context) {