Bug 1546736 Part 1 - Keep track of whether docshells and workers are being watched by the devtools, r=bzbarsky.

--HG--
extra : rebase_source : 837fc73223c0e275fce716bbe1108a14d0e9afa4
This commit is contained in:
Brian Hackett 2019-05-08 09:27:32 -10:00
Родитель b1eb76223f
Коммит 0c7f13ec4c
8 изменённых файлов: 38 добавлений и 5 удалений

Просмотреть файл

@ -386,7 +386,8 @@ nsDocShell::nsDocShell(BrowsingContext* aBrowsingContext)
mBlankTiming(false),
mTitleValidForCurrentURI(false),
mIsFrame(false),
mSkipBrowsingContextDetachOnDestroy(false) {
mSkipBrowsingContextDetachOnDestroy(false),
mWatchedByDevtools(false) {
mHistoryID.m0 = 0;
mHistoryID.m1 = 0;
mHistoryID.m2 = 0;
@ -13548,3 +13549,16 @@ 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;
return NS_OK;
}

Просмотреть файл

@ -1245,6 +1245,9 @@ class nsDocShell final : public nsDocLoader,
// docshell is destroyed, the browsing context will not be detached. This is
// for cases where we want to preserve the BC for future use.
bool mSkipBrowsingContextDetachOnDestroy : 1;
// Set when activity in this docshell is being watched by the developer tools.
bool mWatchedByDevtools : 1;
};
#endif /* nsDocShell_h__ */

Просмотреть файл

@ -1167,4 +1167,9 @@ interface nsIDocShell : nsIDocShellTreeItem
* sense that's relevant to document.open.
*/
[notxpcom, nostdcall] readonly attribute boolean isAttemptingToNavigate;
/**
* Whether developer tools are watching activity in this docshell.
*/
[infallible] attribute boolean watchedByDevtools;
};

Просмотреть файл

@ -49,10 +49,9 @@ class SerializedStackHolder {
// monitor later on. This may be called on either the main or a worker thread.
//
// This always creates a stack, even if the net monitor isn't active for the
// associated window. Ideally we would only create the stack if the net monitor
// was active, but there doesn't seem to be an easy way to determine this.
// The operations this is used with should be rare enough and/or have enough
// other associated costs that the perf impact is low. See bug 1546736.
// 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.
UniquePtr<SerializedStackHolder> GetCurrentStackForNetMonitor(JSContext* aCx);
// If aStackHolder is non-null, this notifies the net monitor that aStackHolder

Просмотреть файл

@ -87,6 +87,7 @@ WorkerLoadInfoData::WorkerLoadInfoData()
mReportCSPViolations(false),
mXHRParamsAllowed(false),
mPrincipalIsSystem(false),
mWatchedByDevtools(false),
mStorageAccess(nsContentUtils::StorageAccess::eDeny),
mFirstPartyStorageAccessGranted(false),
mServiceWorkersTestingInWindow(false),

Просмотреть файл

@ -118,6 +118,7 @@ struct WorkerLoadInfoData {
bool mReportCSPViolations;
bool mXHRParamsAllowed;
bool mPrincipalIsSystem;
bool mWatchedByDevtools;
nsContentUtils::StorageAccess mStorageAccess;
bool mFirstPartyStorageAccessGranted;
bool mServiceWorkersTestingInWindow;

Просмотреть файл

@ -2366,6 +2366,7 @@ nsresult WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindowInner* aWindow,
loadInfo.mServiceWorkersTestingInWindow =
aParent->ServiceWorkersTestingInWindow();
loadInfo.mParentController = aParent->GetController();
loadInfo.mWatchedByDevtools = aParent->IsWatchedByDevtools();
} else {
AssertIsOnMainThread();
@ -2486,6 +2487,11 @@ nsresult WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindowInner* aWindow,
loadInfo.mXHRParamsAllowed = perm == nsIPermissionManager::ALLOW_ACTION;
nsIDocShell* docShell = globalWindow->GetDocShell();
if (docShell) {
loadInfo.mWatchedByDevtools = docShell->GetWatchedByDevtools();
}
loadInfo.mFromWindow = true;
loadInfo.mWindowID = globalWindow->WindowID();
loadInfo.mStorageAccess =

Просмотреть файл

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