Bug 1655967 - Move serviceWorkersTestingEnabled to BrowsingContext. r=nika

Differential Revision: https://phabricator.services.mozilla.com/D103757
This commit is contained in:
Emilio Cobos Álvarez 2021-02-03 10:38:43 +00:00
Родитель 4b58806ec7
Коммит 635e3580e3
11 изменённых файлов: 38 добавлений и 98 удалений

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

@ -2082,12 +2082,10 @@ Toolbox.prototype = {
*/
_applyServiceWorkersTestingSettings: function() {
const pref = "devtools.serviceWorkers.testing.enabled";
const serviceWorkersTestingEnabled =
Services.prefs.getBoolPref(pref) || false;
const serviceWorkersTestingEnabled = Services.prefs.getBoolPref(pref);
this.target.reconfigure({
options: {
serviceWorkersTestingEnabled: serviceWorkersTestingEnabled,
serviceWorkersTestingEnabled
},
});
},

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

@ -1248,11 +1248,7 @@ const browsingContextTargetPrototype = {
) {
this._setPaintFlashingEnabled(options.paintFlashing);
}
if (
typeof options.serviceWorkersTestingEnabled !== "undefined" &&
options.serviceWorkersTestingEnabled !==
this._getServiceWorkersTestingEnabled()
) {
if (typeof options.serviceWorkersTestingEnabled !== "undefined") {
this._setServiceWorkersTestingEnabled(
options.serviceWorkersTestingEnabled
);
@ -1335,8 +1331,9 @@ const browsingContextTargetPrototype = {
* Disable or enable the service workers testing features.
*/
_setServiceWorkersTestingEnabled(enabled) {
const windowUtils = this.window.windowUtils;
windowUtils.serviceWorkersTestingEnabled = enabled;
if (this.browsingContext.serviceWorkersTestingEnabled != enabled) {
this.browsingContext.serviceWorkersTestingEnabled = enabled;
}
},
/**
@ -1372,19 +1369,6 @@ const browsingContextTargetPrototype = {
return this.window.windowUtils.paintFlashing;
},
/**
* Return service workers testing allowed status.
*/
_getServiceWorkersTestingEnabled() {
if (!this.docShell) {
// The browsing context is already closed.
return null;
}
const windowUtils = this.window.windowUtils;
return windowUtils.serviceWorkersTestingEnabled;
},
_changeTopLevelDocument(window) {
// Fake a will-navigate on the previous document
// to let a chance to unregister it

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

@ -188,6 +188,7 @@ enum class ExplicitActiveStatus : uint8_t {
* browsing contexts created as a descendant of this one. Valid only for \
* top BCs. */ \
FIELD(AuthorStyleDisabledDefault, bool) \
FIELD(ServiceWorkersTestingEnabled, bool) \
FIELD(DisplayMode, mozilla::dom::DisplayMode) \
/* True if the top level browsing context owns a main media controller */ \
FIELD(HasMainMediaController, bool) \
@ -435,7 +436,7 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
}
}
uint32_t SandboxFlags() { return GetSandboxFlags(); }
uint32_t SandboxFlags() const { return GetSandboxFlags(); }
Span<RefPtr<BrowsingContext>> Children() const;
void GetChildren(nsTArray<RefPtr<BrowsingContext>>& aChildren);
@ -789,6 +790,10 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
void IncrementHistoryEntryCountForBrowsingContext();
bool ServiceWorkersTestingEnabled() const {
return GetServiceWorkersTestingEnabled();
}
protected:
virtual ~BrowsingContext();
BrowsingContext(WindowContext* aParentWindow, BrowsingContextGroup* aGroup,
@ -877,6 +882,11 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
return true;
}
bool CanSet(FieldIndex<IDX_ServiceWorkersTestingEnabled>, bool,
ContentParent*) {
return IsTop();
}
bool CanSet(FieldIndex<IDX_SuspendMediaWhenInactive>, bool, ContentParent*) {
return IsTop();
}

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

@ -4065,26 +4065,6 @@ nsDOMWindowUtils::GetFramesReflowed(uint64_t* aResult) {
return NS_OK;
}
NS_IMETHODIMP
nsDOMWindowUtils::SetServiceWorkersTestingEnabled(bool aEnabled) {
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
NS_ENSURE_STATE(window);
window->SetServiceWorkersTestingEnabled(aEnabled);
return NS_OK;
}
NS_IMETHODIMP
nsDOMWindowUtils::GetServiceWorkersTestingEnabled(bool* aEnabled) {
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
NS_ENSURE_STATE(window);
*aEnabled = window->GetServiceWorkersTestingEnabled();
return NS_OK;
}
NS_IMETHODIMP
nsDOMWindowUtils::EnterChaosMode() {
ChaosMode::enterChaosMode();

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

@ -4916,7 +4916,8 @@ already_AddRefed<CacheStorage> nsGlobalWindowInner::GetCaches(
ErrorResult& aRv) {
if (!mCacheStorage) {
bool forceTrustedOrigin =
GetOuterWindow()->GetServiceWorkersTestingEnabled();
GetBrowsingContext() &&
GetBrowsingContext()->Top()->GetServiceWorkersTestingEnabled();
mCacheStorage = CacheStorage::CreateOnMainThread(
cache::DEFAULT_NAMESPACE, this, GetEffectiveStoragePrincipal(),
forceTrustedOrigin, aRv);

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

@ -3108,27 +3108,6 @@ void nsPIDOMWindowOuter::RefreshMediaElementsSuspend(SuspendTypes aSuspend) {
}
}
void nsPIDOMWindowOuter::SetServiceWorkersTestingEnabled(bool aEnabled) {
// Devtools should only be setting this on the top level window. Its
// ok if devtools clears the flag on clean up of nested windows, though.
// It will have no affect.
#ifdef DEBUG
nsCOMPtr<nsPIDOMWindowOuter> topWindow = GetInProcessScriptableTop();
MOZ_ASSERT_IF(aEnabled, this == topWindow);
#endif
mServiceWorkersTestingEnabled = aEnabled;
}
bool nsPIDOMWindowOuter::GetServiceWorkersTestingEnabled() {
// Automatically get this setting from the top level window so that nested
// iframes get the correct devtools setting.
nsCOMPtr<nsPIDOMWindowOuter> topWindow = GetInProcessScriptableTop();
if (!topWindow) {
return false;
}
return topWindow->mServiceWorkersTestingEnabled;
}
mozilla::dom::BrowsingContextGroup*
nsPIDOMWindowOuter::GetBrowsingContextGroup() const {
return mBrowsingContext ? mBrowsingContext->Group() : nullptr;
@ -7625,7 +7604,6 @@ nsPIDOMWindowOuter::nsPIDOMWindowOuter(uint64_t aWindowID)
mIsRootOuterWindow(false),
mInnerWindow(nullptr),
mWindowID(aWindowID),
mMarkedCCGeneration(0),
mServiceWorkersTestingEnabled(false) {}
mMarkedCCGeneration(0) {}
nsPIDOMWindowOuter::~nsPIDOMWindowOuter() = default;

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

@ -773,9 +773,6 @@ class nsPIDOMWindowOuter : public mozIDOMWindowProxy {
void RefreshMediaElementsVolume();
void SetServiceWorkersTestingEnabled(bool aEnabled);
bool GetServiceWorkersTestingEnabled();
float GetDevicePixelRatio(mozilla::dom::CallerType aCallerType);
bool HadOriginalOpener() const;
@ -1135,10 +1132,6 @@ class nsPIDOMWindowOuter : public mozIDOMWindowProxy {
uint64_t mWindowID;
uint32_t mMarkedCCGeneration;
// Let the service workers plumbing know that some feature are enabled while
// testing.
bool mServiceWorkersTestingEnabled;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsPIDOMWindowOuter, NS_PIDOMWINDOWOUTER_IID)

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

@ -145,6 +145,9 @@ interface BrowsingContext {
// debugging this browsing context.
[SetterThrows] attribute boolean watchedByDevTools;
// Enable some service workers testing features, for DevTools.
[SetterThrows] attribute boolean serviceWorkersTestingEnabled;
/**
* A unique identifier for the browser element that is hosting this
* BrowsingContext tree. Every BrowsingContext in the element's tree will

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

@ -1864,11 +1864,6 @@ interface nsIDOMWindowUtils : nsISupports {
in int32_t aBottom,
in int32_t aLeft);
/**
* Enable some service workers testing features.
*/
attribute boolean serviceWorkersTestingEnabled;
/**
* Returns a JSObject which contains a list of frame uniformities
* when the pref gfx.vsync.collect-scroll-data is enabled.

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

@ -73,9 +73,8 @@ bool IsInPrivateBrowsing(JSContext* const aCx) {
bool IsServiceWorkersTestingEnabledInWindow(JSObject* const aGlobal) {
if (const nsCOMPtr<nsPIDOMWindowInner> innerWindow =
Navigator::GetWindowFromGlobal(aGlobal)) {
if (const nsCOMPtr<nsPIDOMWindowOuter> outerWindow =
innerWindow->GetOuterWindow()) {
return outerWindow->GetServiceWorkersTestingEnabled();
if (auto* bc = innerWindow->GetBrowsingContext()) {
return bc->Top()->ServiceWorkersTestingEnabled();
}
}
return false;
@ -87,6 +86,8 @@ bool IsServiceWorkersTestingEnabledInWindow(JSObject* const aGlobal) {
bool ServiceWorkerContainer::IsEnabled(JSContext* aCx, JSObject* aGlobal) {
MOZ_ASSERT(NS_IsMainThread());
// FIXME: Why does this need to root? Shouldn't the caller root aGlobal for
// us?
JS::Rooted<JSObject*> global(aCx, aGlobal);
if (!StaticPrefs::dom_serviceWorkers_enabled()) {
@ -101,14 +102,8 @@ bool ServiceWorkerContainer::IsEnabled(JSContext* aCx, JSObject* aGlobal) {
return true;
}
const bool isTestingEnabledInWindow =
IsServiceWorkersTestingEnabledInWindow(global);
const bool isTestingEnabledByPref =
StaticPrefs::dom_serviceWorkers_testing_enabled();
const bool isTestingEnabled =
isTestingEnabledByPref || isTestingEnabledInWindow;
return isTestingEnabled;
return StaticPrefs::dom_serviceWorkers_testing_enabled() ||
IsServiceWorkersTestingEnabledInWindow(global);
}
// static

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

@ -2593,12 +2593,16 @@ nsresult WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindowInner* aWindow,
// access it.
if (nsPIDOMWindowOuter* outerWindow = globalWindow->GetOuterWindow()) {
loadInfo.mWindow = outerWindow->GetCurrentInnerWindow();
// TODO: fix this for SharedWorkers with multiple documents (bug
// 1177935)
loadInfo.mServiceWorkersTestingInWindow =
outerWindow->GetServiceWorkersTestingEnabled();
}
BrowsingContext* browsingContext = globalWindow->GetBrowsingContext();
// TODO: fix this for SharedWorkers with multiple documents (bug
// 1177935)
loadInfo.mServiceWorkersTestingInWindow =
browsingContext &&
browsingContext->Top()->ServiceWorkersTestingEnabled();
if (!loadInfo.mWindow ||
(globalWindow != loadInfo.mWindow &&
!nsContentUtils::CanCallerAccess(loadInfo.mWindow))) {
@ -2671,9 +2675,8 @@ nsresult WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindowInner* aWindow,
loadInfo.mXHRParamsAllowed = perm == nsIPermissionManager::ALLOW_ACTION;
BrowsingContext* browsingContext = globalWindow->GetBrowsingContext();
loadInfo.mWatchedByDevTools =
browsingContext ? browsingContext->WatchedByDevTools() : false;
browsingContext && browsingContext->WatchedByDevTools();
loadInfo.mReferrerInfo =
ReferrerInfo::CreateForFetch(loadInfo.mLoadingPrincipal, document);