Bug 487667 - Clone documents for printing, r=roc+jst+joe+dbaron

This commit is contained in:
Olli Pettay
2009-12-10 20:02:13 -08:00
parent be28d4906a
commit 2e3d0c93fe
73 changed files with 1422 additions and 495 deletions

View File

@@ -87,6 +87,8 @@
#include "nsINameSpaceManager.h"
#include "nsThreadUtils.h"
#include "nsICSSStyleSheet.h"
#include "nsIContentViewer.h"
class nsAsyncDocShellDestroyer : public nsRunnable
{
@@ -138,9 +140,11 @@ nsFrameLoader*
nsFrameLoader::Create(nsIContent* aOwner)
{
NS_ENSURE_TRUE(aOwner, nsnull);
nsIDocument* doc = aOwner->GetCurrentDoc();
nsIDocument* doc = aOwner->GetOwnerDoc();
NS_ENSURE_TRUE(doc && !doc->GetDisplayDocument() &&
!doc->IsLoadedAsData(), nsnull);
((!doc->IsLoadedAsData() && aOwner->GetCurrentDoc()) ||
doc->IsStaticDocument()),
nsnull);
return new nsFrameLoader(aOwner);
}
@@ -160,7 +164,7 @@ nsFrameLoader::LoadFrame()
}
nsIDocument* doc = mOwnerContent->GetOwnerDoc();
if (!doc) {
if (!doc || doc->IsStaticDocument()) {
return NS_OK;
}
@@ -910,8 +914,8 @@ nsFrameLoader::EnsureDocShell()
// Get our parent docshell off the document of mOwnerContent
// XXXbz this is such a total hack.... We really need to have a
// better setup for doing this.
nsIDocument* doc = mOwnerContent->GetDocument();
if (!doc) {
nsIDocument* doc = mOwnerContent->GetOwnerDoc();
if (!doc || !(doc->IsStaticDocument() || mOwnerContent->IsInDoc())) {
return NS_ERROR_UNEXPECTED;
}
@@ -920,8 +924,9 @@ nsFrameLoader::EnsureDocShell()
return NS_ERROR_NOT_AVAILABLE;
}
nsCOMPtr<nsIWebNavigation> parentAsWebNav =
do_GetInterface(doc->GetScriptGlobalObject());
nsCOMPtr<nsISupports> container =
doc->GetContainer();
nsCOMPtr<nsIWebNavigation> parentAsWebNav = do_QueryInterface(container);
// Create the docshell...
mDocShell = do_CreateInstance("@mozilla.org/docshell;1");
@@ -1123,3 +1128,28 @@ nsFrameLoader::CheckForRecursiveLoad(nsIURI* aURI)
return NS_OK;
}
nsresult
nsFrameLoader::CreateStaticClone(nsIFrameLoader* aDest)
{
nsFrameLoader* dest = static_cast<nsFrameLoader*>(aDest);
dest->EnsureDocShell();
NS_ENSURE_STATE(dest->mDocShell);
nsCOMPtr<nsIDOMDocument> dummy = do_GetInterface(dest->mDocShell);
nsCOMPtr<nsIContentViewer> viewer;
dest->mDocShell->GetContentViewer(getter_AddRefs(viewer));
NS_ENSURE_STATE(viewer);
nsCOMPtr<nsIDocShell> origDocShell;
GetDocShell(getter_AddRefs(origDocShell));
nsCOMPtr<nsIDOMDocument> domDoc = do_GetInterface(origDocShell);
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
NS_ENSURE_STATE(doc);
nsCOMPtr<nsIDocument> clonedDoc = doc->CreateStaticClone(dest->mDocShell);
nsCOMPtr<nsIDOMDocument> clonedDOMDoc = do_QueryInterface(clonedDoc);
viewer->SetDOMDocument(clonedDOMDoc);
return NS_OK;
}