Bug 455736: Getting an app cache should not EnsureContentViewer(). r+sr=bz
authorDave Camp <dcamp@mozilla.com>
Sun, 28 Sep 2008 16:42:18 -0700
changeset 19860 ad3074e580096ffd6a8cb29b1e91effeee176fd6
parent 19859 62b670248ab799fd8816bc2fb39a45a881f65e66
child 19861 1a971f9406f8036a7255b92950a5d36811a07891
push idunknown
push userunknown
push dateunknown
bugs455736
milestone1.9.1b1pre
Bug 455736: Getting an app cache should not EnsureContentViewer(). r+sr=bz
docshell/base/nsDocShell.cpp
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -455,26 +455,35 @@ NS_IMETHODIMP nsDocShell::GetInterface(c
              NS_SUCCEEDED(EnsureScriptEnvironment())) {
         return mScriptGlobal->QueryInterface(aIID, aSink);
     }
     else if (aIID.Equals(NS_GET_IID(nsIDOMDocument)) &&
              NS_SUCCEEDED(EnsureContentViewer())) {
         mContentViewer->GetDOMDocument((nsIDOMDocument **) aSink);
         return *aSink ? NS_OK : NS_NOINTERFACE;
     }
-    else if (aIID.Equals(NS_GET_IID(nsIApplicationCacheContainer)) &&
-             NS_SUCCEEDED(EnsureContentViewer())) {
+    else if (aIID.Equals(NS_GET_IID(nsIApplicationCacheContainer))) {
         *aSink = nsnull;
 
         // Return the toplevel document as an
         // nsIApplicationCacheContainer.
 
         nsCOMPtr<nsIDocShellTreeItem> rootItem;
         GetSameTypeRootTreeItem(getter_AddRefs(rootItem));
-        nsCOMPtr<nsIDOMDocument> domDoc = do_GetInterface(rootItem);
+        nsCOMPtr<nsIDocShell> rootDocShell = do_QueryInterface(rootItem);
+        if (!rootDocShell)
+            return NS_ERROR_NO_INTERFACE;
+
+        nsCOMPtr<nsIContentViewer> contentViewer;
+        rootDocShell->GetContentViewer(getter_AddRefs(contentViewer));
+        if (!contentViewer)
+            return NS_ERROR_NO_INTERFACE;
+
+        nsCOMPtr<nsIDOMDocument> domDoc;
+        contentViewer->GetDOMDocument(getter_AddRefs(domDoc));
         NS_ASSERTION(domDoc, "Should have a document.");
         if (!domDoc)
             return NS_ERROR_NO_INTERFACE;
 
         return domDoc->QueryInterface(aIID, aSink);
     }
     else if (aIID.Equals(NS_GET_IID(nsIPrompt)) &&
              NS_SUCCEEDED(EnsureScriptEnvironment())) {