1717#include " nsHistory.h"
1818#include " nsDOMNavigationTiming.h"
1919#include " nsIDOMStorageManager.h"
20+ #include " mozilla/dom/CallbackDebuggerNotification.h"
2021#include " mozilla/dom/ContentFrameMessageManager.h"
2122#include " mozilla/dom/CSPEvalChecker.h"
23+ #include " mozilla/dom/DebuggerNotification.h"
2224#include " mozilla/dom/DocumentInlines.h"
2325#include " mozilla/dom/DOMJSProxyHandler.h"
2426#include " mozilla/dom/EventTarget.h"
@@ -1370,6 +1372,8 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindowInner)
13701372 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCacheStorage )
13711373 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVRDisplays )
13721374
1375+ NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDebuggerNotificationManager )
1376+
13731377 // Traverse stuff from nsPIDOMWindow
13741378 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChromeEventHandler )
13751379 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParentTarget )
@@ -1468,6 +1472,8 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindowInner)
14681472 NS_IMPL_CYCLE_COLLECTION_UNLINK(mCacheStorage )
14691473 NS_IMPL_CYCLE_COLLECTION_UNLINK(mVRDisplays )
14701474
1475+ NS_IMPL_CYCLE_COLLECTION_UNLINK(mDebuggerNotificationManager )
1476+
14711477 // Unlink stuff from nsPIDOMWindow
14721478 NS_IMPL_CYCLE_COLLECTION_UNLINK(mChromeEventHandler )
14731479 NS_IMPL_CYCLE_COLLECTION_UNLINK(mParentTarget )
@@ -3289,6 +3295,9 @@ int32_t nsGlobalWindowInner::RequestAnimationFrame(
32893295 js::NotifyAnimationActivity (GetWrapperPreserveColor ());
32903296 }
32913297
3298+ DebuggerNotificationDispatch (this ,
3299+ DebuggerNotificationType::RequestAnimationFrame);
3300+
32923301 int32_t handle;
32933302 aError = mDoc ->ScheduleFrameRequestCallback (aCallback, &handle);
32943303 return handle;
@@ -3300,6 +3309,9 @@ void nsGlobalWindowInner::CancelAnimationFrame(int32_t aHandle,
33003309 return ;
33013310 }
33023311
3312+ DebuggerNotificationDispatch (this ,
3313+ DebuggerNotificationType::CancelAnimationFrame);
3314+
33033315 mDoc ->CancelFrameRequestCallback (aHandle);
33043316}
33053317
@@ -3730,12 +3742,16 @@ void nsGlobalWindowInner::MozScrollSnap() {
37303742}
37313743
37323744void nsGlobalWindowInner::ClearTimeout (int32_t aHandle) {
3745+ DebuggerNotificationDispatch (this , DebuggerNotificationType::ClearTimeout);
3746+
37333747 if (aHandle > 0 ) {
37343748 mTimeoutManager ->ClearTimeout (aHandle, Timeout::Reason::eTimeoutOrInterval);
37353749 }
37363750}
37373751
37383752void nsGlobalWindowInner::ClearInterval (int32_t aHandle) {
3753+ DebuggerNotificationDispatch (this , DebuggerNotificationType::ClearInterval);
3754+
37393755 if (aHandle > 0 ) {
37403756 mTimeoutManager ->ClearTimeout (aHandle, Timeout::Reason::eTimeoutOrInterval);
37413757 }
@@ -4003,6 +4019,20 @@ EventListenerManager* nsGlobalWindowInner::GetExistingListenerManager() const {
40034019 return mListenerManager ;
40044020}
40054021
4022+ mozilla::dom::DebuggerNotificationManager*
4023+ nsGlobalWindowInner::GetOrCreateDebuggerNotificationManager () {
4024+ if (!mDebuggerNotificationManager ) {
4025+ mDebuggerNotificationManager = new DebuggerNotificationManager (this );
4026+ }
4027+
4028+ return mDebuggerNotificationManager ;
4029+ }
4030+
4031+ mozilla::dom::DebuggerNotificationManager*
4032+ nsGlobalWindowInner::GetExistingDebuggerNotificationManager () {
4033+ return mDebuggerNotificationManager ;
4034+ }
4035+
40064036// *****************************************************************************
40074037// nsGlobalWindowInner::nsPIDOMWindow
40084038// *****************************************************************************
@@ -5758,10 +5788,15 @@ int32_t nsGlobalWindowInner::SetTimeoutOrInterval(
57585788 }
57595789
57605790 if (inner != this ) {
5761- return inner->SetTimeoutOrInterval (aCx, aFunction, aTimeout, aArguments,
5762- aIsInterval, aError);
5791+ RefPtr<nsGlobalWindowInner> innerRef (inner);
5792+ return innerRef->SetTimeoutOrInterval (aCx, aFunction, aTimeout, aArguments,
5793+ aIsInterval, aError);
57635794 }
57645795
5796+ DebuggerNotificationDispatch (
5797+ this , aIsInterval ? DebuggerNotificationType::SetInterval
5798+ : DebuggerNotificationType::SetTimeout);
5799+
57655800 if (!GetContextInternal () || !HasJSGlobal ()) {
57665801 // This window was already closed, or never properly initialized,
57675802 // don't let a timer be scheduled on such a window.
@@ -5796,10 +5831,15 @@ int32_t nsGlobalWindowInner::SetTimeoutOrInterval(JSContext* aCx,
57965831 }
57975832
57985833 if (inner != this ) {
5799- return inner->SetTimeoutOrInterval (aCx, aHandler, aTimeout, aIsInterval,
5800- aError);
5834+ RefPtr<nsGlobalWindowInner> innerRef (inner);
5835+ return innerRef->SetTimeoutOrInterval (aCx, aHandler, aTimeout, aIsInterval,
5836+ aError);
58015837 }
58025838
5839+ DebuggerNotificationDispatch (
5840+ this , aIsInterval ? DebuggerNotificationType::SetInterval
5841+ : DebuggerNotificationType::SetTimeout);
5842+
58035843 if (!GetContextInternal () || !HasJSGlobal ()) {
58045844 // This window was already closed, or never properly initialized,
58055845 // don't let a timer be scheduled on such a window.
@@ -5857,8 +5897,17 @@ bool nsGlobalWindowInner::RunTimeoutHandler(Timeout* aTimeout,
58575897 reason = " setTimeout handler" ;
58585898 }
58595899
5860- RefPtr<TimeoutHandler> handler (timeout->mScriptHandler );
5861- bool abortIntervalHandler = !handler->Call (reason);
5900+ bool abortIntervalHandler;
5901+ {
5902+ RefPtr<TimeoutHandler> handler (timeout->mScriptHandler );
5903+
5904+ CallbackDebuggerNotificationGuard guard (
5905+ this , timeout->mIsInterval
5906+ ? DebuggerNotificationType::SetIntervalCallback
5907+ : DebuggerNotificationType::SetTimeoutCallback);
5908+ abortIntervalHandler = !handler->Call (reason);
5909+ }
5910+
58625911 // If we received an uncatchable exception, do not schedule the timeout again.
58635912 // This allows the slow script dialog to break easy DoS attacks like
58645913 // setInterval(function() { while(1); }, 100);
0 commit comments