This commit is contained in:
Olli.Pettay@helsinki.fi 2008-04-01 03:37:28 -07:00
Родитель 431d2effa5
Коммит f44539b486
6 изменённых файлов: 75 добавлений и 12 удалений

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

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

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

@ -76,8 +76,8 @@ class nsScriptObjectHolder;
class nsXBLPrototypeHandler; class nsXBLPrototypeHandler;
#define NS_PIDOMWINDOW_IID \ #define NS_PIDOMWINDOW_IID \
{ 0x909852b5, 0xb9e6, 0x4d94, \ { 0xc9c187f9, 0x2104, 0x4c2c, \
{ 0x8d, 0xe3, 0x05, 0x16, 0x34, 0x80, 0x0b, 0x73 } } { 0xb4, 0xd7, 0xc1, 0xb1, 0x9d, 0xa5, 0xc7, 0xd8 } }
class nsPIDOMWindow : public nsIDOMWindowInternal class nsPIDOMWindow : public nsIDOMWindowInternal
{ {
@ -269,6 +269,8 @@ public:
// Restore the window state from aState. // Restore the window state from aState.
virtual nsresult RestoreWindowState(nsISupports *aState) = 0; virtual nsresult RestoreWindowState(nsISupports *aState) = 0;
// Suspend timeouts in this and in child windows.
virtual void SuspendTimeouts() = 0;
// Resume suspended timeouts in this window and in child windows. // Resume suspended timeouts in this window and in child windows.
virtual nsresult ResumeTimeouts() = 0; virtual nsresult ResumeTimeouts() = 0;

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

@ -605,6 +605,7 @@ nsGlobalWindow::nsGlobalWindow(nsGlobalWindow *aOuterWindow)
mFireOfflineStatusChangeEventOnThaw(PR_FALSE), mFireOfflineStatusChangeEventOnThaw(PR_FALSE),
mCreatingInnerWindow(PR_FALSE), mCreatingInnerWindow(PR_FALSE),
mIsChrome(PR_FALSE), mIsChrome(PR_FALSE),
mTimersSuspended(PR_FALSE),
mTimeoutInsertionPoint(nsnull), mTimeoutInsertionPoint(nsnull),
mTimeoutPublicIdCounter(1), mTimeoutPublicIdCounter(1),
mTimeoutFiringDepth(0), mTimeoutFiringDepth(0),
@ -8382,6 +8383,11 @@ nsGlobalWindow::SuspendTimeouts()
{ {
FORWARD_TO_INNER_VOID(SuspendTimeouts, ()); FORWARD_TO_INNER_VOID(SuspendTimeouts, ());
if (mTimersSuspended) {
return;
}
mTimersSuspended = PR_TRUE;
PRTime now = PR_Now(); PRTime now = PR_Now();
for (nsTimeout *t = FirstTimeout(); IsTimeout(t); t = t->Next()) { for (nsTimeout *t = FirstTimeout(); IsTimeout(t); t = t->Next()) {
// Change mWhen to be the time remaining for this timer. // Change mWhen to be the time remaining for this timer.
@ -8437,6 +8443,11 @@ nsGlobalWindow::ResumeTimeouts()
{ {
FORWARD_TO_INNER(ResumeTimeouts, (), NS_ERROR_NOT_INITIALIZED); FORWARD_TO_INNER(ResumeTimeouts, (), NS_ERROR_NOT_INITIALIZED);
if (!mTimersSuspended) {
return NS_OK;
}
mTimersSuspended = PR_FALSE;
// Restore all of the timeouts, using the stored time remaining // Restore all of the timeouts, using the stored time remaining
// (stored in timeout->mWhen). // (stored in timeout->mWhen).

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

@ -300,6 +300,7 @@ public:
virtual NS_HIDDEN_(nsresult) SaveWindowState(nsISupports **aState); virtual NS_HIDDEN_(nsresult) SaveWindowState(nsISupports **aState);
virtual NS_HIDDEN_(nsresult) RestoreWindowState(nsISupports *aState); virtual NS_HIDDEN_(nsresult) RestoreWindowState(nsISupports *aState);
virtual NS_HIDDEN_(void) SuspendTimeouts();
virtual NS_HIDDEN_(nsresult) ResumeTimeouts(); virtual NS_HIDDEN_(nsresult) ResumeTimeouts();
virtual NS_HIDDEN_(nsresult) FireDelayedDOMEvents(); virtual NS_HIDDEN_(nsresult) FireDelayedDOMEvents();
virtual NS_HIDDEN_(PRBool) IsFrozen() const virtual NS_HIDDEN_(PRBool) IsFrozen() const
@ -599,8 +600,6 @@ protected:
already_AddRefed<nsIWidget> GetMainWidget(); already_AddRefed<nsIWidget> GetMainWidget();
void SuspendTimeouts();
void Freeze() void Freeze()
{ {
NS_ASSERTION(!IsFrozen(), "Double-freezing?"); NS_ASSERTION(!IsFrozen(), "Double-freezing?");
@ -674,6 +673,8 @@ protected:
// Fast way to tell if this is a chrome window (without having to QI). // Fast way to tell if this is a chrome window (without having to QI).
PRPackedBool mIsChrome : 1; PRPackedBool mIsChrome : 1;
PRPackedBool mTimersSuspended : 1;
nsCOMPtr<nsIScriptContext> mContext; nsCOMPtr<nsIScriptContext> mContext;
nsWeakPtr mOpener; nsWeakPtr mOpener;
nsCOMPtr<nsIControllers> mControllers; nsCOMPtr<nsIControllers> mControllers;

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

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

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

@ -213,6 +213,35 @@ static void DumpPrintObjectsTreeLayout(nsPrintObject * aPO,nsIDeviceContext * aD
#define DUMP_DOC_TREELAYOUT #define DUMP_DOC_TREELAYOUT
#endif #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 // Class IDs
static NS_DEFINE_CID(kViewManagerCID, NS_VIEW_MANAGER_CID); static NS_DEFINE_CID(kViewManagerCID, NS_VIEW_MANAGER_CID);
@ -557,11 +586,13 @@ nsPrintEngine::DoCommonPrint(PRBool aIsPrintPreview,
(do_CreateInstance("@mozilla.org/gfx/devicecontextspec;1", &rv)); (do_CreateInstance("@mozilla.org/gfx/devicecontextspec;1", &rv));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsScriptSuppressor scriptSuppressor(this);
if (!aIsPrintPreview) { if (!aIsPrintPreview) {
#ifdef NS_DEBUG #ifdef NS_DEBUG
mPrt->mDebugFilePtr = mDebugFile; mPrt->mDebugFilePtr = mDebugFile;
#endif #endif
scriptSuppressor.Suppress();
PRBool printSilently; PRBool printSilently;
mPrt->mPrintSettings->GetPrintSilent(&printSilently); mPrt->mPrintSettings->GetPrintSilent(&printSilently);
@ -713,6 +744,9 @@ nsPrintEngine::DoCommonPrint(PRBool aIsPrintPreview,
} }
} }
// We will enable scripting later after printing has finished.
scriptSuppressor.Disconnect();
return NS_OK; return NS_OK;
} }
@ -2712,6 +2746,7 @@ nsPrintEngine::DonePrintingPages(nsPrintObject* aPO, nsresult aResult)
FirePrintCompletionEvent(); FirePrintCompletionEvent();
} }
TurnScriptingOn(PR_TRUE);
SetIsPrinting(PR_FALSE); SetIsPrinting(PR_FALSE);
// Release reference to mPagePrintTimer; the timer object destroys itself // Release reference to mPagePrintTimer; the timer object destroys itself
@ -2993,6 +3028,13 @@ nsPrintEngine::FindSmallestSTF()
void void
nsPrintEngine::TurnScriptingOn(PRBool aDoTurnOn) 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; nsPrintData* prt = mPrt;
#ifdef NS_PRINT_PREVIEW #ifdef NS_PRINT_PREVIEW
if (!prt) { if (!prt) {
@ -3016,25 +3058,32 @@ nsPrintEngine::TurnScriptingOn(PRBool aDoTurnOn)
nsIScriptGlobalObject *scriptGlobalObj = doc->GetScriptGlobalObject(); nsIScriptGlobalObject *scriptGlobalObj = doc->GetScriptGlobalObject();
if (scriptGlobalObj) { if (scriptGlobalObj) {
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(scriptGlobalObj);
NS_ASSERTION(window, "Can't get nsPIDOMWindow");
nsIScriptContext *scx = scriptGlobalObj->GetContext(); nsIScriptContext *scx = scriptGlobalObj->GetContext();
NS_ASSERTION(scx, "Can't get nsIScriptContext"); NS_ASSERTION(scx, "Can't get nsIScriptContext");
nsresult propThere = NS_PROPTABLE_PROP_NOT_THERE;
doc->GetProperty(nsGkAtoms::scriptEnabledBeforePrintOrPreview,
&propThere);
if (aDoTurnOn) { if (aDoTurnOn) {
doc->DeleteProperty(nsGkAtoms::scriptEnabledBeforePrintPreview); if (propThere != NS_PROPTABLE_PROP_NOT_THERE) {
doc->DeleteProperty(nsGkAtoms::scriptEnabledBeforePrintOrPreview);
scx->SetScriptsEnabled(PR_TRUE, PR_FALSE);
window->ResumeTimeouts();
}
} else { } else {
// Have to be careful, because people call us over and over again with // 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 // 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. // 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) { if (propThere == NS_PROPTABLE_PROP_NOT_THERE) {
// Stash the current value of IsScriptEnabled on the document, so // Stash the current value of IsScriptEnabled on the document, so
// that layout code running in print preview doesn't get confused. // 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())); NS_INT32_TO_PTR(doc->IsScriptEnabled()));
scx->SetScriptsEnabled(PR_FALSE, PR_FALSE);
window->SuspendTimeouts();
} }
} }
scx->SetScriptsEnabled(aDoTurnOn, PR_TRUE);
} }
} }
} }