In bug 1112134 we introduced `nsGlobalWindowInner::CachesEnabled` to do a proper SecureContext check, but we did not remove the [IsTrusted](https://searchfox.org/mozilla-central/rev/3067ba33c2202459aae52b7a0f7218a71fe5f7c3/dom/cache/CacheStorage.cpp#73) method which is [called by the CreateOn* methods](https://searchfox.org/mozilla-central/query/default?q=calls-to%3A%27mozilla%3A%3Adom%3A%3Acache%3A%3AIsTrusted%27+depth%3A2) and served as an approximation of the secure context check. We should be able to remove IsTrusted now. The one behavior that the IsTrusted control flow path handles that CachesEnabled does not, is checking the [BrowsingContext ServiceWorkersTestingEnabled flag](https://searchfox.org/mozilla-central/rev/3067ba33c2202459aae52b7a0f7218a71fe5f7c3/docshell/base/BrowsingContext.h#226) that devtools sets to allow a page to use ServiceWorkers despite being http. That check is [done in nsGlobalWindowInner::GetCaches and passed into CacheStorage::CreateOnMainThread](https://searchfox.org/mozilla-central/rev/3067ba33c2202459aae52b7a0f7218a71fe5f7c3/dom/base/nsGlobalWindowInner.cpp#5184-5186), which is of course too late since CachesEnabled already would have returned false. It's possible we haven't seen a bug report for this because [as we can see in the call graph for the getter flag](https://searchfox.org/mozilla-central/query/default?q=calls-to%3A%27mozilla%3A%3Adom%3A%3ABrowsingContext%3A%3AGetServiceWorkersTestingEnabled%27%20depth%3A4) the enabling check for ServiceWorkers [ServiceWorkersEnabled](https://searchfox.org/mozilla-central/rev/3067ba33c2202459aae52b7a0f7218a71fe5f7c3/dom/serviceworkers/ServiceWorkerUtils.cpp#45) calls [IsServiceWorkersTestingEnabledInWindow](https://searchfox.org/mozilla-central/rev/3067ba33c2202459aae52b7a0f7218a71fe5f7c3/dom/serviceworkers/ServiceWorkerUtils.cpp#26) which does check the browsing context. However, while this would make it look like ServiceWorkers are working in that case, and there is an effort to propagate the flag onto the WorkerLoadInfoData ([see diagram of field use](calls-to:'mozilla::dom::WorkerLoadInfoData::mServiceWorkersTestingInWindow' depth:3)), the same CachesEnabled enabling function is used on workers, so any non-trivial ServiceWorker would likely fail to install. The tl;dr for this is that CachesEnabled should be doing the same check ServiceWorkersEnabled is doing, and it's reasonable to do this as part of removing `IsTrusted`.
Bug 1817893 Comment 0 Edit History
Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.
In bug 1112134 we introduced `nsGlobalWindowInner::CachesEnabled` to do a proper SecureContext check, but we did not remove the [IsTrusted](https://searchfox.org/mozilla-central/rev/3067ba33c2202459aae52b7a0f7218a71fe5f7c3/dom/cache/CacheStorage.cpp#73) method which is [called by the CreateOn* methods](https://searchfox.org/mozilla-central/query/default?q=calls-to%3A%27mozilla%3A%3Adom%3A%3Acache%3A%3AIsTrusted%27+depth%3A2) and served as an approximation of the secure context check. We should be able to remove IsTrusted now. The one behavior that the IsTrusted control flow path handles that CachesEnabled does not, is checking the [BrowsingContext ServiceWorkersTestingEnabled flag](https://searchfox.org/mozilla-central/rev/3067ba33c2202459aae52b7a0f7218a71fe5f7c3/docshell/base/BrowsingContext.h#226) that devtools sets to allow a page to use ServiceWorkers despite being http. That check is [done in nsGlobalWindowInner::GetCaches and passed into CacheStorage::CreateOnMainThread](https://searchfox.org/mozilla-central/rev/3067ba33c2202459aae52b7a0f7218a71fe5f7c3/dom/base/nsGlobalWindowInner.cpp#5184-5186), which is of course too late since CachesEnabled already would have returned false. It's possible we haven't seen a bug report for this because [as we can see in the call graph for the getter flag](https://searchfox.org/mozilla-central/query/default?q=calls-to%3A%27mozilla%3A%3Adom%3A%3ABrowsingContext%3A%3AGetServiceWorkersTestingEnabled%27%20depth%3A4) the enabling check for ServiceWorkers [ServiceWorkersEnabled](https://searchfox.org/mozilla-central/rev/3067ba33c2202459aae52b7a0f7218a71fe5f7c3/dom/serviceworkers/ServiceWorkerUtils.cpp#45) calls [IsServiceWorkersTestingEnabledInWindow](https://searchfox.org/mozilla-central/rev/3067ba33c2202459aae52b7a0f7218a71fe5f7c3/dom/serviceworkers/ServiceWorkerUtils.cpp#26) which does check the browsing context. However, while this would make it look like ServiceWorkers are working in that case, and there is an effort to propagate the flag onto the WorkerLoadInfoData ([see diagram of field use](https://searchfox.org/mozilla-central/query/default?q=calls-to%3A%27mozilla%3A%3Adom%3A%3AWorkerLoadInfoData%3A%3AmServiceWorkersTestingInWindow%27+depth%3A3)), the same CachesEnabled enabling function is used on workers, so any non-trivial ServiceWorker would likely fail to install. The tl;dr for this is that CachesEnabled should be doing the same check ServiceWorkersEnabled is doing, and it's reasonable to do this as part of removing `IsTrusted`.