bug 1171785 use nsContentUtils::RunInStableState() r=bholley

This commit is contained in:
Karl Tomlinson 2015-06-11 14:36:12 +12:00
parent 171d831ed9
commit dfec676114
8 changed files with 28 additions and 60 deletions

View File

@ -3441,16 +3441,14 @@ nsDOMWindowUtils::DispatchEventToChromeOnly(nsIDOMEventTarget* aTarget,
}
NS_IMETHODIMP
nsDOMWindowUtils::RunInStableState(nsIRunnable *runnable)
nsDOMWindowUtils::RunInStableState(nsIRunnable *aRunnable)
{
MOZ_RELEASE_ASSERT(nsContentUtils::IsCallerChrome());
nsCOMPtr<nsIAppShell> appShell(do_GetService(kAppShellCID));
if (!appShell) {
return NS_ERROR_NOT_AVAILABLE;
}
nsCOMPtr<nsIRunnable> runnable = aRunnable;
nsContentUtils::RunInStableState(runnable.forget());
return appShell->RunInStableState(runnable);
return NS_OK;
}
NS_IMETHODIMP

View File

@ -17,8 +17,6 @@
#include "nsIURL.h"
#include "nsIIOService.h"
#include "nsIServiceManager.h"
#include "nsIAppShell.h"
#include "nsWidgetsCID.h"
#include "nsNetUtil.h"
#include "nsContentUtils.h"
#include "nsContainerFrame.h"
@ -53,8 +51,6 @@
#include "mozilla/Preferences.h"
static const char *kPrefSrcsetEnabled = "dom.image.srcset.enabled";
static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
NS_IMPL_NS_NEW_HTML_ELEMENT(Image)
#ifdef DEBUG
@ -882,15 +878,11 @@ HTMLImageElement::QueueImageLoadTask()
return;
}
// The task checks this to determine if it was the last queued event, so this
// implicitly cancels earlier tasks
mPendingImageLoadTask = new ImageLoadTask(this);
nsCOMPtr<nsIAppShell> appShell = do_GetService(kAppShellCID);
if (appShell) {
appShell->RunInStableState(mPendingImageLoadTask);
} else {
MOZ_ASSERT(false, "expect appshell for HTMLImageElement");
}
nsCOMPtr<nsIRunnable> task = new ImageLoadTask(this);
// The task checks this to determine if it was the last
// queued event, and so earlier tasks are implicitly canceled.
mPendingImageLoadTask = task;
nsContentUtils::RunInStableState(task.forget());
}
bool

View File

@ -61,8 +61,6 @@
#include "Layers.h"
#include <limits>
#include "nsIAsyncVerifyRedirectCallback.h"
#include "nsIAppShell.h"
#include "nsWidgetsCID.h"
#include "nsMediaFragmentURIParser.h"
#include "nsURIHashKey.h"
#include "nsJSUtils.h"
@ -758,13 +756,10 @@ public:
}
};
static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
void HTMLMediaElement::RunInStableState(nsIRunnable* aRunnable)
{
nsCOMPtr<nsIRunnable> event = new nsSyncSection(this, aRunnable);
nsCOMPtr<nsIAppShell> appShell = do_GetService(kAppShellCID);
appShell->RunInStableState(event);
nsContentUtils::RunInStableState(event.forget());
}
void HTMLMediaElement::QueueLoadFromSourceTask()

View File

@ -1704,9 +1704,11 @@ interface nsIDOMWindowUtils : nsISupports {
attribute boolean paintFlashing;
/**
* Allows running of a "synchronous section", in the form of an nsIRunnable
* once the event loop has reached a "stable state". We've reached a stable
* state when the currently executing task/event has finished, see:
* Add a "synchronous section", in the form of an nsIRunnable run once the
* event loop has reached a "stable state". |runnable| 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

View File

@ -10,8 +10,7 @@
#include "nsThreadUtils.h"
#include "TaskDispatcher.h"
#include "nsIAppShell.h"
#include "nsWidgetsCID.h"
#include "nsContentUtils.h"
#include "nsServiceManagerUtils.h"
#include "mozilla/ClearOnShutdown.h"
@ -24,8 +23,6 @@ namespace mozilla {
StaticRefPtr<AbstractThread> sMainThread;
ThreadLocal<AbstractThread*> AbstractThread::sCurrentThreadTLS;
static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
class XPCOMThreadWrapper : public AbstractThread
{
public:
@ -87,8 +84,7 @@ public:
mTailDispatcher.emplace(/* aIsTailDispatcher = */ true);
nsCOMPtr<nsIRunnable> event = NS_NewRunnableMethod(this, &XPCOMThreadWrapper::FireTailDispatcher);
nsCOMPtr<nsIAppShell> appShell = do_GetService(kAppShellCID);
appShell->RunInStableState(event);
nsContentUtils::RunInStableState(event.forget());
}
return mTailDispatcher.ref();

View File

@ -11,10 +11,7 @@
#include "mozilla/Mutex.h"
#include "mozilla/dom/CanvasCaptureMediaStreamBinding.h"
#include "mozilla/dom/HTMLCanvasElement.h"
#include "nsIAppShell.h"
#include "nsWidgetsCID.h"
static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
#include "nsContentUtils.h"
using namespace mozilla::layers;
using namespace mozilla::gfx;
@ -113,8 +110,7 @@ OutputStreamDriver::Start()
// Run StartInternal() in stable state to allow it to directly capture a frame
nsCOMPtr<nsIRunnable> runnable =
NS_NewRunnableMethod(this, &OutputStreamDriver::StartInternal);
nsCOMPtr<nsIAppShell> appShell = do_GetService(kAppShellCID);
appShell->RunInStableState(runnable);
nsContentUtils::RunInStableState(runnable.forget());
mStarted = true;
return NS_OK;

View File

@ -10,11 +10,9 @@
#include "AudioSegment.h"
#include "VideoSegment.h"
#include "nsContentUtils.h"
#include "nsIAppShell.h"
#include "nsIObserver.h"
#include "nsPrintfCString.h"
#include "nsServiceManagerUtils.h"
#include "nsWidgetsCID.h"
#include "prerror.h"
#include "mozilla/Logging.h"
#include "mozilla/Attributes.h"
@ -1839,8 +1837,6 @@ MediaStreamGraphImpl::RunInStableState(bool aSourceIsMSG)
}
static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
void
MediaStreamGraphImpl::EnsureRunInStableState()
{
@ -1850,12 +1846,7 @@ MediaStreamGraphImpl::EnsureRunInStableState()
return;
mPostedRunInStableState = true;
nsCOMPtr<nsIRunnable> event = new MediaStreamGraphStableStateRunnable(this, false);
nsCOMPtr<nsIAppShell> appShell = do_GetService(kAppShellCID);
if (appShell) {
appShell->RunInStableState(event);
} else {
NS_ERROR("Appshell already destroyed?");
}
nsContentUtils::RunInStableState(event.forget());
}
void

View File

@ -16,13 +16,12 @@
#include "AudioNodeStream.h"
#include "MediaStreamGraph.h"
#include "OfflineAudioCompletionEvent.h"
#include "nsContentUtils.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIDocShell.h"
#include "nsIPermissionManager.h"
#include "nsIScriptObjectPrincipal.h"
#include "nsServiceManagerUtils.h"
#include "nsIAppShell.h"
#include "nsWidgetsCID.h"
#include "mozilla/dom/Promise.h"
namespace mozilla {
@ -684,17 +683,16 @@ AudioDestinationNode::NotifyStableState()
mExtraCurrentTimeUpdatedSinceLastStableState = false;
}
static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
void
AudioDestinationNode::ScheduleStableStateNotification()
{
nsCOMPtr<nsIAppShell> appShell = do_GetService(kAppShellCID);
if (appShell) {
nsCOMPtr<nsIRunnable> event =
NS_NewRunnableMethod(this, &AudioDestinationNode::NotifyStableState);
appShell->RunInStableState(event);
}
nsCOMPtr<nsIRunnable> event =
NS_NewRunnableMethod(this, &AudioDestinationNode::NotifyStableState);
// Dispatch will fail if this is called on AudioNode destruction during
// shutdown, in which case failure can be ignored.
nsContentUtils::RunInStableState(event.forget(),
nsContentUtils::
DispatchFailureHandling::IgnoreFailure);
}
double