This commit is contained in:
Olli Pettay 2009-03-10 21:30:50 +02:00
Родитель ecc15423c1
Коммит ba008990ed
3 изменённых файлов: 66 добавлений и 10 удалений

Просмотреть файл

@ -798,7 +798,7 @@ GK_ATOM(screen, "screen")
GK_ATOM(screenX, "screenX")
GK_ATOM(screenY, "screenY")
GK_ATOM(script, "script")
GK_ATOM(scriptEnabledBeforePrintPreview, "scriptEnabledBeforePrintPreview")
GK_ATOM(scriptEnabledBeforePrintOrPreview, "scriptEnabledBeforePrintOrPreview")
GK_ATOM(scrollbar, "scrollbar")
GK_ATOM(scrollbarbutton, "scrollbarbutton")
GK_ATOM(scrollbox, "scrollbox")

Просмотреть файл

@ -2057,7 +2057,7 @@ PresShell::SetPrefNoScriptRule()
((mPresContext->Type() == nsPresContext::eContext_PrintPreview ||
mPresContext->Type() == nsPresContext::eContext_Print) &&
NS_PTR_TO_INT32(mDocument->GetProperty(
nsGkAtoms::scriptEnabledBeforePrintPreview)));
nsGkAtoms::scriptEnabledBeforePrintOrPreview)));
if (scriptEnabled) {
if (!mPrefStyleSheet) {

Просмотреть файл

@ -214,6 +214,35 @@ static void DumpPrintObjectsTreeLayout(nsPrintObject * aPO,nsIDeviceContext * aD
#define DUMP_DOC_TREELAYOUT
#endif
class nsScriptSuppressor
{
public:
nsScriptSuppressor(nsPrintEngine* aPrintEngine)
: mPrintEngine(aPrintEngine), mSuppressed(PR_FALSE) {}
~nsScriptSuppressor() { Unsuppress(); }
void Suppress()
{
if (mPrintEngine) {
mSuppressed = PR_TRUE;
mPrintEngine->TurnScriptingOn(PR_FALSE);
}
}
void Unsuppress()
{
if (mPrintEngine && mSuppressed) {
mPrintEngine->TurnScriptingOn(PR_TRUE);
}
mSuppressed = PR_FALSE;
}
void Disconnect() { mPrintEngine = nsnull; }
protected:
nsRefPtr<nsPrintEngine> mPrintEngine;
PRBool mSuppressed;
};
// Class IDs
static NS_DEFINE_CID(kViewManagerCID, NS_VIEW_MANAGER_CID);
@ -554,11 +583,13 @@ nsPrintEngine::DoCommonPrint(PRBool aIsPrintPreview,
(do_CreateInstance("@mozilla.org/gfx/devicecontextspec;1", &rv));
NS_ENSURE_SUCCESS(rv, rv);
nsScriptSuppressor scriptSuppressor(this);
if (!aIsPrintPreview) {
#ifdef NS_DEBUG
mPrt->mDebugFilePtr = mDebugFile;
#endif
scriptSuppressor.Suppress();
PRBool printSilently;
mPrt->mPrintSettings->GetPrintSilent(&printSilently);
@ -710,6 +741,9 @@ nsPrintEngine::DoCommonPrint(PRBool aIsPrintPreview,
}
}
// We will enable scripting later after printing has finished.
scriptSuppressor.Disconnect();
return NS_OK;
}
@ -2742,6 +2776,7 @@ nsPrintEngine::DonePrintingPages(nsPrintObject* aPO, nsresult aResult)
FirePrintCompletionEvent();
}
TurnScriptingOn(PR_TRUE);
SetIsPrinting(PR_FALSE);
// Release reference to mPagePrintTimer; the timer object destroys itself
@ -3022,6 +3057,13 @@ nsPrintEngine::FindSmallestSTF()
void
nsPrintEngine::TurnScriptingOn(PRBool aDoTurnOn)
{
if (mIsDoingPrinting && aDoTurnOn && mDocViewerPrint &&
mDocViewerPrint->GetIsPrintPreview()) {
// We don't want to turn scripting on if print preview is shown still after
// printing.
return;
}
nsPrintData* prt = mPrt;
#ifdef NS_PRINT_PREVIEW
if (!prt) {
@ -3040,30 +3082,44 @@ nsPrintEngine::TurnScriptingOn(PRBool aDoTurnOn)
NS_ASSERTION(po, "nsPrintObject can't be null!");
nsIDocument* doc = po->mDocument;
if (!doc) {
continue;
}
// get the script global object
nsIScriptGlobalObject *scriptGlobalObj = doc->GetScriptGlobalObject();
if (scriptGlobalObj) {
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(scriptGlobalObj);
NS_ASSERTION(window, "Can't get nsPIDOMWindow");
nsIScriptContext *scx = scriptGlobalObj->GetContext();
NS_ASSERTION(scx, "Can't get nsIScriptContext");
NS_WARN_IF_FALSE(scx, "Can't get nsIScriptContext");
nsresult propThere = NS_PROPTABLE_PROP_NOT_THERE;
doc->GetProperty(nsGkAtoms::scriptEnabledBeforePrintOrPreview,
&propThere);
if (aDoTurnOn) {
doc->DeleteProperty(nsGkAtoms::scriptEnabledBeforePrintPreview);
if (propThere != NS_PROPTABLE_PROP_NOT_THERE) {
doc->DeleteProperty(nsGkAtoms::scriptEnabledBeforePrintOrPreview);
if (scx) {
scx->SetScriptsEnabled(PR_TRUE, PR_FALSE);
}
window->ResumeTimeouts(PR_FALSE);
}
} else {
// Have to be careful, because people call us over and over again with
// aDoTurnOn == PR_FALSE. So don't set the property if it's already
// set, since in that case we'd set it to the wrong value.
nsresult propThere;
doc->GetProperty(nsGkAtoms::scriptEnabledBeforePrintPreview,
&propThere);
if (propThere == NS_PROPTABLE_PROP_NOT_THERE) {
// Stash the current value of IsScriptEnabled on the document, so
// that layout code running in print preview doesn't get confused.
doc->SetProperty(nsGkAtoms::scriptEnabledBeforePrintPreview,
doc->SetProperty(nsGkAtoms::scriptEnabledBeforePrintOrPreview,
NS_INT32_TO_PTR(doc->IsScriptEnabled()));
if (scx) {
scx->SetScriptsEnabled(PR_FALSE, PR_FALSE);
}
window->SuspendTimeouts(1, PR_FALSE);
}
}
scx->SetScriptsEnabled(aDoTurnOn, PR_TRUE);
}
}
}