Bug 1620966 - Move DocShell.watchedByDevtools to BrowsingContext and rename it to watchedByDevTools. r=nika,jdescottes

Differential Revision: https://phabricator.services.mozilla.com/D66037
This commit is contained in:
Alexandre Poirot 2020-05-12 09:18:26 +00:00
parent 18a6ab6770
commit 718bf89e62
19 changed files with 58 additions and 78 deletions

View File

@ -790,12 +790,8 @@ const browsingContextTargetPrototype = {
// In child processes, we have new root docshells,
// let's watch them and all their child docshells.
if (this._isRootDocShell(docShell)) {
if (this.watchNewDocShells) {
this._progressListener.watch(docShell);
}
} else if (this._progressListener.isParentWatched(docShell)) {
docShell.watchedByDevtools = true;
if (this._isRootDocShell(docShell) && this.watchNewDocShells) {
this._progressListener.watch(docShell);
}
this._notifyDocShellsUpdate([docShell]);
});
@ -1616,12 +1612,10 @@ DebuggerProgressListener.prototype = {
this._knownWindowIDs.set(getWindowID(win), win);
}
// The watchedByDevtools flag is set on each docshell this target is
// associated with. This enables Gecko behavior tied to this flag, such as
// reporting the contents of HTML loaded in the docshells, or capturing
// stacks for the network monitor.
docShell.watchedByDevtools = true;
getChildDocShells(docShell).forEach(d => (d.watchedByDevtools = true));
// The `watchedByDevTools` enables gecko behavior tied to this flag, such as:
// - reporting the contents of HTML loaded in the docshells,
// - or capturing stacks for the network monitor.
docShell.browsingContext.watchedByDevTools = true;
},
unwatch(docShell) {
@ -1654,19 +1648,7 @@ DebuggerProgressListener.prototype = {
this._knownWindowIDs.delete(getWindowID(win));
}
docShell.watchedByDevtools = false;
getChildDocShells(docShell).forEach(d => (d.watchedByDevtools = false));
},
isParentWatched(docShell) {
let parent = docShell.parent;
while (parent) {
if (this._watchedDocShells.has(parent.domWindow)) {
return true;
}
parent = parent.parent;
}
return false;
docShell.browsingContext.watchedByDevTools = false;
},
_getWindowsInDocShell(docShell) {

View File

@ -239,7 +239,6 @@ already_AddRefed<BrowsingContext> BrowsingContext::CreateDetached(
context->mFields.SetWithoutSyncing<IDX_OpenerPolicy>(
nsILoadInfo::OPENER_POLICY_UNSAFE_NONE);
context->mFields.SetWithoutSyncing<IDX_WatchedByDevtools>(false);
if (aOpener && aOpener->SameOriginWithTop()) {
// We inherit the opener policy if there is a creator and if the creator's
@ -1915,10 +1914,27 @@ bool BrowsingContext::CanSet(FieldIndex<IDX_AllowPlugins>,
return CheckOnlyOwningProcessCanSet(aSource);
}
bool BrowsingContext::CanSet(FieldIndex<IDX_WatchedByDevtools>,
const bool& aWatchedByDevtools,
// We map `watchedByDevTools` WebIDL attribute to `watchedByDevToolsInternal`
// BC field. And we map it to the top level BrowsingContext.
bool BrowsingContext::WatchedByDevTools() {
return Top()->GetWatchedByDevToolsInternal();
}
// Enforce that the watchedByDevTools BC field can only be set on the top level
// Browsing Context.
bool BrowsingContext::CanSet(FieldIndex<IDX_WatchedByDevToolsInternal>,
const bool& aWatchedByDevTools,
ContentParent* aSource) {
return CheckOnlyOwningProcessCanSet(aSource);
return IsTop();
}
void BrowsingContext::SetWatchedByDevTools(bool aWatchedByDevTools,
ErrorResult& aRv) {
if (!IsTop()) {
aRv.ThrowInvalidModificationError(
"watchedByDevTools can only be set on top BrowsingContext");
return;
}
SetWatchedByDevToolsInternal(aWatchedByDevTools);
}
bool BrowsingContext::CanSet(FieldIndex<IDX_DefaultLoadFlags>,

View File

@ -129,7 +129,7 @@ class WindowProxyHolder;
FIELD(MessageManagerGroup, nsString) \
FIELD(MaxTouchPointsOverride, uint8_t) \
FIELD(FullZoom, float) \
FIELD(WatchedByDevtools, bool) \
FIELD(WatchedByDevToolsInternal, bool) \
FIELD(TextZoom, float) \
/* See nsIRequest for possible flags. */ \
FIELD(DefaultLoadFlags, uint32_t)
@ -378,6 +378,9 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
bool InRDMPane() const { return GetInRDMPane(); }
bool WatchedByDevTools();
void SetWatchedByDevTools(bool aWatchedByDevTools, ErrorResult& aRv);
float FullZoom() const { return GetFullZoom(); }
float TextZoom() const { return GetTextZoom(); }
@ -724,8 +727,8 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
ContentParent* aSource);
bool CanSet(FieldIndex<IDX_AllowPlugins>, const bool& aAllowPlugins,
ContentParent* aSource);
bool CanSet(FieldIndex<IDX_WatchedByDevtools>, const bool& aWatchedByDevtools,
ContentParent* aSource);
bool CanSet(FieldIndex<IDX_WatchedByDevToolsInternal>,
const bool& aWatchedByDevToolsInternal, ContentParent* aSource);
bool CanSet(FieldIndex<IDX_DefaultLoadFlags>,
const uint32_t& aDefaultLoadFlags, ContentParent* aSource);

View File

@ -565,7 +565,7 @@ bool CanonicalBrowsingContext::AttemptLoadURIInParent(
// process notifications, which happens after the load is initiated in this
// case. Devtools clears all prior requests when it detects a new navigation,
// so it drops the main document load that happened here.
if (GetWatchedByDevtools()) {
if (WatchedByDevTools()) {
return false;
}

View File

@ -397,7 +397,6 @@ nsDocShell::nsDocShell(BrowsingContext* aBrowsingContext,
mBlankTiming(false),
mTitleValidForCurrentURI(false),
mWillChangeProcess(false),
mWatchedByDevtools(false),
mIsNavigating(false),
mSuspendMediaWhenInactive(false) {
// If no outer window ID was provided, generate a new one.
@ -12660,19 +12659,3 @@ bool nsDocShell::GetIsAttemptingToNavigate() {
return false;
}
NS_IMETHODIMP
nsDocShell::GetWatchedByDevtools(bool* aWatched) {
NS_ENSURE_ARG(aWatched);
*aWatched = mWatchedByDevtools;
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::SetWatchedByDevtools(bool aWatched) {
mWatchedByDevtools = aWatched;
if (!mWillChangeProcess) {
mBrowsingContext->SetWatchedByDevtools(aWatched);
}
return NS_OK;
}

View File

@ -1309,9 +1309,6 @@ class nsDocShell final : public nsDocLoader,
// we prepare the browsing context to change process.
bool mWillChangeProcess : 1;
// Set when activity in this docshell is being watched by the developer tools.
bool mWatchedByDevtools : 1;
// This flag indicates whether or not the DocShell is currently executing an
// nsIWebNavigation navigation method.
bool mIsNavigating : 1;

View File

@ -1038,11 +1038,6 @@ interface nsIDocShell : nsIDocShellTreeItem
*/
[notxpcom, nostdcall] readonly attribute boolean isAttemptingToNavigate;
/**
* Whether developer tools are watching activity in this docshell.
*/
[infallible] attribute boolean watchedByDevtools;
/*
* Whether or not this docshell is executing a nsIWebNavigation navigation
* method.

View File

@ -89,7 +89,7 @@ JSObject* SerializedStackHolder::ReadStack(JSContext* aCx) {
UniquePtr<SerializedStackHolder> GetCurrentStackForNetMonitor(JSContext* aCx) {
MOZ_ASSERT_IF(!NS_IsMainThread(),
GetCurrentThreadWorkerPrivate()->IsWatchedByDevtools());
GetCurrentThreadWorkerPrivate()->IsWatchedByDevTools());
UniquePtr<SerializedStackHolder> stack = MakeUnique<SerializedStackHolder>();
stack->SerializeCurrentStack(aCx);

View File

@ -51,8 +51,8 @@ class SerializedStackHolder {
//
// This always creates a stack, even if the net monitor isn't active for the
// associated window. The net monitor will only be active if the associated
// docshell or worker's WatchedByDevtools flag is set, so this should be checked
// before creating the stack.
// Browsing Context or worker's WatchedByDevTools flag is set, so this should
// be checked before creating the stack.
UniquePtr<SerializedStackHolder> GetCurrentStackForNetMonitor(JSContext* aCx);
// If aStackHolder is non-null, this notifies the net monitor that aStackHolder

View File

@ -100,6 +100,10 @@ interface BrowsingContext {
// Extension to give chrome JS the ability to set a maxTouchPoints override
// while in RDM.
void setRDMPaneMaxTouchPoints(octet maxTouchPoints);
// The watchedByDevTools flag indicates whether or not DevTools are currently
// debugging this browsing context.
[SetterThrows] attribute boolean watchedByDevTools;
};
BrowsingContext includes LoadContextMixin;

View File

@ -543,7 +543,7 @@ already_AddRefed<Promise> FetchRequest(nsIGlobalObject* aGlobal,
}
UniquePtr<SerializedStackHolder> stack;
if (worker->IsWatchedByDevtools()) {
if (worker->IsWatchedByDevTools()) {
stack = GetCurrentStackForNetMonitor(cx);
}

View File

@ -1358,8 +1358,8 @@ already_AddRefed<WebSocket> WebSocket::ConstructorCommon(
nsPIDOMWindowOuter* outerWindow = ownerWindow->GetOuterWindow();
UniquePtr<SerializedStackHolder> stack;
nsIDocShell* docShell = outerWindow->GetDocShell();
if (docShell && docShell->GetWatchedByDevtools()) {
BrowsingContext* browsingContext = ownerWindow->GetBrowsingContext();
if (browsingContext && browsingContext->WatchedByDevTools()) {
stack = GetCurrentStackForNetMonitor(aGlobal.Context());
}
@ -1383,7 +1383,7 @@ already_AddRefed<WebSocket> WebSocket::ConstructorCommon(
UniquePtr<SerializedStackHolder> stack;
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
if (workerPrivate->IsWatchedByDevtools()) {
if (workerPrivate->IsWatchedByDevTools()) {
stack = GetCurrentStackForNetMonitor(aGlobal.Context());
}

View File

@ -91,7 +91,7 @@ WorkerLoadInfoData::WorkerLoadInfoData()
mXHRParamsAllowed(false),
mPrincipalIsSystem(false),
mPrincipalIsAddonOrExpandedAddon(false),
mWatchedByDevtools(false),
mWatchedByDevTools(false),
mStorageAccess(StorageAccess::eDeny),
mFirstPartyStorageAccessGranted(false),
mServiceWorkersTestingInWindow(false),

View File

@ -127,7 +127,7 @@ struct WorkerLoadInfoData {
bool mXHRParamsAllowed;
bool mPrincipalIsSystem;
bool mPrincipalIsAddonOrExpandedAddon;
bool mWatchedByDevtools;
bool mWatchedByDevTools;
StorageAccess mStorageAccess;
bool mFirstPartyStorageAccessGranted;
bool mServiceWorkersTestingInWindow;

View File

@ -2425,7 +2425,7 @@ already_AddRefed<WorkerPrivate> WorkerPrivate::Constructor(
MOZ_DIAGNOSTIC_ASSERT(worker->PrincipalIsValid());
UniquePtr<SerializedStackHolder> stack;
if (worker->IsWatchedByDevtools()) {
if (worker->IsWatchedByDevTools()) {
stack = GetCurrentStackForNetMonitor(aCx);
}
@ -2535,7 +2535,7 @@ nsresult WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindowInner* aWindow,
loadInfo.mServiceWorkersTestingInWindow =
aParent->ServiceWorkersTestingInWindow();
loadInfo.mParentController = aParent->GlobalScope()->GetController();
loadInfo.mWatchedByDevtools = aParent->IsWatchedByDevtools();
loadInfo.mWatchedByDevTools = aParent->IsWatchedByDevTools();
} else {
AssertIsOnMainThread();
@ -2656,10 +2656,9 @@ nsresult WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindowInner* aWindow,
loadInfo.mXHRParamsAllowed = perm == nsIPermissionManager::ALLOW_ACTION;
nsIDocShell* docShell = globalWindow->GetDocShell();
if (docShell) {
loadInfo.mWatchedByDevtools = docShell->GetWatchedByDevtools();
}
BrowsingContext* browsingContext = globalWindow->GetBrowsingContext();
loadInfo.mWatchedByDevTools =
browsingContext ? browsingContext->WatchedByDevTools() : false;
loadInfo.mReferrerInfo =
ReferrerInfo::CreateForFetch(loadInfo.mLoadingPrincipal, document);

View File

@ -790,7 +790,7 @@ class WorkerPrivate : public RelativeTimeline {
return mLoadInfo.mServiceWorkersTestingInWindow;
}
bool IsWatchedByDevtools() const { return mLoadInfo.mWatchedByDevtools; }
bool IsWatchedByDevTools() const { return mLoadInfo.mWatchedByDevTools; }
// Determine if the worker is currently loading its top level script.
bool IsLoadingWorkerScript() const { return mLoadingWorkerScript; }

View File

@ -343,7 +343,7 @@ void WorkerGlobalScope::ImportScripts(JSContext* aCx,
mWorkerPrivate->AssertIsOnWorkerThread();
UniquePtr<SerializedStackHolder> stack;
if (mWorkerPrivate->IsWatchedByDevtools()) {
if (mWorkerPrivate->IsWatchedByDevTools()) {
stack = GetCurrentStackForNetMonitor(aCx);
}

View File

@ -1724,7 +1724,7 @@ void XMLHttpRequestWorker::Open(const nsACString& aMethod,
mProxy->mOuterEventStreamId++;
UniquePtr<SerializedStackHolder> stack;
if (mWorkerPrivate->IsWatchedByDevtools()) {
if (mWorkerPrivate->IsWatchedByDevTools()) {
if (JSContext* cx = nsContentUtils::GetCurrentJSContext()) {
stack = GetCurrentStackForNetMonitor(cx);
}

View File

@ -310,8 +310,9 @@ void nsHtml5StreamParser::FeedDetector(Span<const uint8_t> aBuffer,
void nsHtml5StreamParser::SetViewSourceTitle(nsIURI* aURL) {
MOZ_ASSERT(NS_IsMainThread());
nsIDocShell* docshell = mExecutor->GetDocument()->GetDocShell();
if (docshell && docshell->GetWatchedByDevtools()) {
BrowsingContext* browsingContext =
mExecutor->GetDocument()->GetBrowsingContext();
if (browsingContext && browsingContext->WatchedByDevTools()) {
mURIToSendToDevtools = aURL;
nsID uuid;