Bug 526394. Part 34: Create nsContentUtils::AddScriptBlockerAndPreventAddingRunners. r=sicking

This commit is contained in:
Robert O'Callahan 2010-01-12 10:45:20 +13:00
parent b5f5b11c36
commit 4eda29f7e1
2 changed files with 26 additions and 1 deletions

View File

@ -1366,6 +1366,13 @@ public:
*/
static void AddScriptBlocker();
/**
* Increases the count of blockers preventing scripts from running.
* Also, while this script blocker is active, script runners must not be
* added --- we'll assert if one is, and ignore it.
*/
static void AddScriptBlockerAndPreventAddingRunners();
/**
* Decreases the count of blockers preventing scripts from running.
* NOTE: You might want to use nsAutoScriptBlocker rather than calling
@ -1590,6 +1597,7 @@ private:
static PRUint32 sRemovableScriptBlockerCount;
static nsCOMArray<nsIRunnable>* sBlockedScriptRunners;
static PRUint32 sRunnersCountAtFirstBlocker;
static PRUint32 sScriptBlockerCountWhereRunnersPrevented;
static nsIInterfaceRequestor* sSameOriginChecker;
};

View File

@ -223,6 +223,7 @@ PRUint32 nsContentUtils::sScriptBlockerCount = 0;
PRUint32 nsContentUtils::sRemovableScriptBlockerCount = 0;
nsCOMArray<nsIRunnable>* nsContentUtils::sBlockedScriptRunners = nsnull;
PRUint32 nsContentUtils::sRunnersCountAtFirstBlocker = 0;
PRUint32 nsContentUtils::sScriptBlockerCountWhereRunnersPrevented = 0;
nsIInterfaceRequestor* nsContentUtils::sSameOriginChecker = nsnull;
nsIJSRuntimeService *nsAutoGCRoot::sJSRuntimeService;
@ -4493,12 +4494,25 @@ nsContentUtils::AddScriptBlocker()
++sScriptBlockerCount;
}
/* static */
void
nsContentUtils::AddScriptBlockerAndPreventAddingRunners()
{
AddScriptBlocker();
if (sScriptBlockerCountWhereRunnersPrevented == 0) {
sScriptBlockerCountWhereRunnersPrevented = sScriptBlockerCount;
}
}
/* static */
void
nsContentUtils::RemoveScriptBlocker()
{
NS_ASSERTION(sScriptBlockerCount != 0, "Negative script blockers");
--sScriptBlockerCount;
if (sScriptBlockerCount < sScriptBlockerCountWhereRunnersPrevented) {
sScriptBlockerCountWhereRunnersPrevented = 0;
}
if (sScriptBlockerCount) {
return;
}
@ -4522,7 +4536,6 @@ nsContentUtils::RemoveScriptBlocker()
}
}
/* static */
PRBool
nsContentUtils::AddScriptRunner(nsIRunnable* aRunnable)
@ -4532,6 +4545,10 @@ nsContentUtils::AddScriptRunner(nsIRunnable* aRunnable)
}
if (sScriptBlockerCount) {
if (sScriptBlockerCountWhereRunnersPrevented > 0) {
NS_ERROR("Adding a script runner when that is prevented!");
return PR_FALSE;
}
return sBlockedScriptRunners->AppendObject(aRunnable);
}