bug 1171785 create nsContentUtils::RunInStableState helper r=bholley

This commit is contained in:
Karl Tomlinson 2015-06-05 16:19:37 +12:00
parent 78515a2a5a
commit 2e41c8c701
2 changed files with 40 additions and 0 deletions

View File

@ -92,6 +92,7 @@
#include "nsHostObjectProtocolHandler.h"
#include "nsHtml5Module.h"
#include "nsHtml5StringParser.h"
#include "nsIAppShell.h"
#include "nsIAsyncVerifyRedirectCallback.h"
#include "nsICategoryManager.h"
#include "nsIChannelEventSink.h"
@ -182,6 +183,7 @@
#include "nsUnicodeProperties.h"
#include "nsViewManager.h"
#include "nsViewportInfo.h"
#include "nsWidgetsCID.h"
#include "nsWrapperCacheInlines.h"
#include "nsXULPopupManager.h"
#include "xpcprivate.h" // nsXPConnect
@ -337,6 +339,7 @@ namespace {
static NS_DEFINE_CID(kParserServiceCID, NS_PARSERSERVICE_CID);
static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
static PLDHashTable* sEventListenerManagersHash;
@ -5148,6 +5151,22 @@ nsContentUtils::AddScriptRunner(nsIRunnable* aRunnable)
return true;
}
/* static */
void
nsContentUtils::RunInStableState(already_AddRefed<nsIRunnable> aRunnable,
DispatchFailureHandling aHandling)
{
nsCOMPtr<nsIRunnable> runnable = aRunnable;
nsCOMPtr<nsIAppShell> appShell(do_GetService(kAppShellCID));
if (!appShell) {
MOZ_ASSERT(aHandling == DispatchFailureHandling::IgnoreFailure);
return;
}
DebugOnly<nsresult> rv = appShell->RunInStableState(runnable);
MOZ_ASSERT(NS_SUCCEEDED(rv) ||
aHandling == DispatchFailureHandling::IgnoreFailure);
}
void
nsContentUtils::EnterMicroTask()
{

View File

@ -1576,6 +1576,27 @@ public:
*/
static void WarnScriptWasIgnored(nsIDocument* aDocument);
/**
* Whether to assert that RunInStableState() succeeds, or ignore failure,
* which may happen late in shutdown.
*/
enum class DispatchFailureHandling { AssertSuccess, IgnoreFailure };
/**
* Add a "synchronous section", in the form of an nsIRunnable run once the
* event loop has reached a "stable state". |aRunnable| must not cause any
* queued events to be processed (i.e. must not spin the event loop).
* We've reached a stable state when the currently executing task/event has
* finished, see
* http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#synchronous-section
* In practice this runs aRunnable once the currently executing event
* finishes. If called multiple times per task/event, all the runnables will
* be executed, in the order in which RunInStableState() was called.
*/
static void RunInStableState(already_AddRefed<nsIRunnable> aRunnable,
DispatchFailureHandling aHandling =
DispatchFailureHandling::AssertSuccess);
/**
* Retrieve information about the viewport as a data structure.
* This will return information in the viewport META data section