diff --git a/mozilla/layout/base/nsLayoutAtomList.h b/mozilla/layout/base/nsLayoutAtomList.h index 484dd9fc934..8b572ce0f31 100644 --- a/mozilla/layout/base/nsLayoutAtomList.h +++ b/mozilla/layout/base/nsLayoutAtomList.h @@ -254,6 +254,7 @@ LAYOUT_ATOM(embeddingLevel, "EmbeddingLevel") // PRUint8 LAYOUT_ATOM(endsInDiacritic, "EndsInDiacritic") // PRUint32 LAYOUT_ATOM(nextBidi, "NextBidi") // nsIFrame* LAYOUT_ATOM(charType, "charType") // PRUint8 +LAYOUT_ATOM(scriptEnabledBeforePrintPreview, "scriptEnabledBeforePrintPreview") // PRBool #ifdef MOZ_SVG // Alphabetical list of SVG frame types diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index 666375c6a3e..a926e501b20 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -2381,7 +2381,12 @@ PresShell::SetPrefNoScriptRule() { nsresult rv = NS_OK; - if (mDocument->IsScriptEnabled()) { + PRBool scriptEnabled = mDocument->IsScriptEnabled() || + (mPresContext->Type() == nsPresContext::eContext_PrintPreview && + NS_PTR_TO_INT32(mDocument->GetProperty( + nsLayoutAtoms::scriptEnabledBeforePrintPreview))); + + if (scriptEnabled) { if (!mPrefStyleSheet) { rv = CreatePreferenceStyleSheet(); NS_ENSURE_SUCCESS(rv, rv); diff --git a/mozilla/layout/printing/nsPrintEngine.cpp b/mozilla/layout/printing/nsPrintEngine.cpp index 282f61f6583..f559cb7c610 100644 --- a/mozilla/layout/printing/nsPrintEngine.cpp +++ b/mozilla/layout/printing/nsPrintEngine.cpp @@ -4388,12 +4388,23 @@ nsPrintEngine::TurnScriptingOn(PRBool aDoTurnOn) for (PRInt32 i=0;imPrintDocList->Count();i++) { nsPrintObject* po = (nsPrintObject*)prt->mPrintDocList->ElementAt(i); NS_ASSERTION(po, "nsPrintObject can't be null!"); + + nsIDocument* doc = po->mDocument; // get the script global object - nsIScriptGlobalObject *scriptGlobalObj = po->mDocument->GetScriptGlobalObject(); + nsIScriptGlobalObject *scriptGlobalObj = doc->GetScriptGlobalObject(); if (scriptGlobalObj) { nsIScriptContext *scx = scriptGlobalObj->GetContext(); NS_ASSERTION(scx, "Can't get nsIScriptContext"); + if (aDoTurnOn) { + doc->DeleteProperty(nsLayoutAtoms::scriptEnabledBeforePrintPreview); + } else { + // Stash the current value of IsScriptEnabled on the document, + // so that layout code running in print preview doesn't get + // confused. + doc->SetProperty(nsLayoutAtoms::scriptEnabledBeforePrintPreview, + NS_INT32_TO_PTR(doc->IsScriptEnabled())); + } scx->SetScriptsEnabled(aDoTurnOn, PR_TRUE); } }