Backed out 17 changesets (bug 1896709) for causing build bustage and mochitest failures CLOSED TREE
Backed out changeset 046f0f522ce7 (bug 1896709) Backed out changeset 0271e50308e6 (bug 1896709) Backed out changeset 26fac760de19 (bug 1896709) Backed out changeset 6fa3424dfc40 (bug 1896709) Backed out changeset b7bcb9904435 (bug 1896709) Backed out changeset c6878c5fdde4 (bug 1896709) Backed out changeset 8ca8a4082e44 (bug 1896709) Backed out changeset 20ff83806cc6 (bug 1896709) Backed out changeset 6c9338852a19 (bug 1896709) Backed out changeset e8615b5d82ab (bug 1896709) Backed out changeset 842f2047a4bd (bug 1896709) Backed out changeset 54eea04a7342 (bug 1896709) Backed out changeset 220b544127cb (bug 1896709) Backed out changeset 52ce0ebfb29a (bug 1896709) Backed out changeset 34fc79dc1ad7 (bug 1896709) Backed out changeset 50b0f6a23e3c (bug 1896709) Backed out changeset 89c4c6bb465a (bug 1896709)
This commit is contained in:
@@ -32,7 +32,6 @@
|
||||
#include "mozilla/ScopeExit.h"
|
||||
#include "mozilla/ScrollingMetrics.h"
|
||||
#include "mozilla/SharedStyleSheetCache.h"
|
||||
#include "mozilla/dom/SharedScriptCache.h"
|
||||
#include "mozilla/SpinEventLoopUntil.h"
|
||||
#include "mozilla/TimeStamp.h"
|
||||
#include "mozilla/dom/ContentParent.h"
|
||||
@@ -1373,20 +1372,6 @@ void ChromeUtils::ClearStyleSheetCache(GlobalObject&) {
|
||||
SharedStyleSheetCache::Clear();
|
||||
}
|
||||
|
||||
void ChromeUtils::ClearScriptCacheByPrincipal(GlobalObject&,
|
||||
nsIPrincipal* aForPrincipal) {
|
||||
SharedScriptCache::Clear(aForPrincipal);
|
||||
}
|
||||
|
||||
void ChromeUtils::ClearScriptCacheByBaseDomain(GlobalObject&,
|
||||
const nsACString& aBaseDomain) {
|
||||
SharedScriptCache::Clear(nullptr, &aBaseDomain);
|
||||
}
|
||||
|
||||
void ChromeUtils::ClearScriptCache(GlobalObject&) {
|
||||
SharedScriptCache::Clear();
|
||||
}
|
||||
|
||||
#define PROCTYPE_TO_WEBIDL_CASE(_procType, _webidl) \
|
||||
case mozilla::ProcType::_procType: \
|
||||
return WebIDLProcType::_webidl
|
||||
|
||||
@@ -190,14 +190,6 @@ class ChromeUtils {
|
||||
|
||||
static void ClearStyleSheetCache(GlobalObject& aGlobal);
|
||||
|
||||
static void ClearScriptCacheByPrincipal(GlobalObject&,
|
||||
nsIPrincipal* aForPrincipal);
|
||||
|
||||
static void ClearScriptCacheByBaseDomain(GlobalObject& aGlobal,
|
||||
const nsACString& aBaseDomain);
|
||||
|
||||
static void ClearScriptCache(GlobalObject& aGlobal);
|
||||
|
||||
static void SetPerfStatsCollectionMask(GlobalObject& aGlobal, uint64_t aMask);
|
||||
|
||||
static already_AddRefed<Promise> CollectPerfStats(GlobalObject& aGlobal,
|
||||
|
||||
@@ -2794,11 +2794,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Document)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCSSLoader)
|
||||
}
|
||||
|
||||
if (tmp->mScriptLoader) {
|
||||
tmp->mScriptLoader->DropDocumentReference();
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mScriptLoader)
|
||||
}
|
||||
|
||||
// We own only the items in mDOMMediaQueryLists that have listeners;
|
||||
// this reference is managed by their AddListener and RemoveListener
|
||||
// methods.
|
||||
@@ -4364,7 +4359,6 @@ void Document::SetPrincipals(nsIPrincipal* aNewPrincipal,
|
||||
}
|
||||
}
|
||||
|
||||
mScriptLoader->DeregisterFromCache();
|
||||
mCSSLoader->DeregisterFromSheetCache();
|
||||
|
||||
mNodeInfoManager->SetDocumentPrincipal(aNewPrincipal);
|
||||
@@ -4373,7 +4367,6 @@ void Document::SetPrincipals(nsIPrincipal* aNewPrincipal,
|
||||
mCachedURLData = nullptr;
|
||||
|
||||
mCSSLoader->RegisterInSheetCache();
|
||||
mScriptLoader->RegisterToCache();
|
||||
|
||||
RecomputeResistFingerprinting();
|
||||
|
||||
|
||||
@@ -102,17 +102,7 @@ nsresult JSExecutionContext::JoinOffThread(ScriptLoadContext* aContext) {
|
||||
return mRv;
|
||||
}
|
||||
|
||||
if (mKeepStencil) {
|
||||
mStencil = JS::DuplicateStencil(mCx, stencil.get());
|
||||
if (!mStencil) {
|
||||
mSkip = true;
|
||||
mRv = EvaluationExceptionToNSResult(mCx);
|
||||
return mRv;
|
||||
}
|
||||
}
|
||||
|
||||
bool unused;
|
||||
return InstantiateStencil(std::move(stencil), unused, &storage);
|
||||
return InstantiateStencil(std::move(stencil), &storage);
|
||||
}
|
||||
|
||||
template <typename Unit>
|
||||
@@ -135,17 +125,7 @@ nsresult JSExecutionContext::InternalCompile(JS::SourceText<Unit>& aSrcBuf) {
|
||||
return mRv;
|
||||
}
|
||||
|
||||
if (mKeepStencil) {
|
||||
mStencil = JS::DuplicateStencil(mCx, stencil.get());
|
||||
if (!mStencil) {
|
||||
mSkip = true;
|
||||
mRv = EvaluationExceptionToNSResult(mCx);
|
||||
return mRv;
|
||||
}
|
||||
}
|
||||
|
||||
bool unused;
|
||||
return InstantiateStencil(std::move(stencil), unused);
|
||||
return InstantiateStencil(std::move(stencil));
|
||||
}
|
||||
|
||||
nsresult JSExecutionContext::Compile(JS::SourceText<char16_t>& aSrcBuf) {
|
||||
@@ -195,22 +175,11 @@ nsresult JSExecutionContext::Decode(const JS::TranscodeRange& aBytecodeBuf) {
|
||||
return mRv;
|
||||
}
|
||||
|
||||
if (mKeepStencil) {
|
||||
mStencil = JS::DuplicateStencil(mCx, stencil.get());
|
||||
if (!mStencil) {
|
||||
mSkip = true;
|
||||
mRv = EvaluationExceptionToNSResult(mCx);
|
||||
return mRv;
|
||||
}
|
||||
}
|
||||
|
||||
bool unused;
|
||||
return InstantiateStencil(std::move(stencil), unused);
|
||||
return InstantiateStencil(std::move(stencil));
|
||||
}
|
||||
|
||||
nsresult JSExecutionContext::InstantiateStencil(
|
||||
RefPtr<JS::Stencil>&& aStencil, bool& incrementalEncodingAlreadyStarted,
|
||||
JS::InstantiationStorage* aStorage) {
|
||||
RefPtr<JS::Stencil>&& aStencil, JS::InstantiationStorage* aStorage) {
|
||||
JS::InstantiateOptions instantiateOptions(mCompileOptions);
|
||||
JS::Rooted<JSScript*> script(
|
||||
mCx, JS::InstantiateGlobalStencil(mCx, instantiateOptions, aStencil,
|
||||
@@ -222,12 +191,14 @@ nsresult JSExecutionContext::InstantiateStencil(
|
||||
}
|
||||
|
||||
if (mEncodeBytecode) {
|
||||
bool alreadyStarted;
|
||||
if (!JS::StartIncrementalEncoding(mCx, std::move(aStencil),
|
||||
incrementalEncodingAlreadyStarted)) {
|
||||
alreadyStarted)) {
|
||||
mSkip = true;
|
||||
mRv = EvaluationExceptionToNSResult(mCx);
|
||||
return mRv;
|
||||
}
|
||||
MOZ_ASSERT(!alreadyStarted);
|
||||
}
|
||||
|
||||
MOZ_ASSERT(!mScript);
|
||||
|
||||
@@ -57,8 +57,6 @@ class MOZ_STACK_CLASS JSExecutionContext final {
|
||||
JS::Rooted<JS::Value> mDebuggerPrivateValue;
|
||||
JS::Rooted<JSScript*> mDebuggerIntroductionScript;
|
||||
|
||||
RefPtr<JS::Stencil> mStencil;
|
||||
|
||||
// returned value forwarded when we have to interupt the execution eagerly
|
||||
// with mSkip.
|
||||
nsresult mRv;
|
||||
@@ -73,8 +71,6 @@ class MOZ_STACK_CLASS JSExecutionContext final {
|
||||
// Encode the bytecode before it is being executed.
|
||||
bool mEncodeBytecode;
|
||||
|
||||
bool mKeepStencil = false;
|
||||
|
||||
#ifdef DEBUG
|
||||
// Should we set the return value.
|
||||
bool mWantsReturnValue;
|
||||
@@ -87,6 +83,11 @@ class MOZ_STACK_CLASS JSExecutionContext final {
|
||||
template <typename Unit>
|
||||
nsresult InternalCompile(JS::SourceText<Unit>& aSrcBuf);
|
||||
|
||||
// Instantiate (on main-thread) a JS::Stencil generated by off-thread or
|
||||
// main-thread parsing or decoding.
|
||||
nsresult InstantiateStencil(RefPtr<JS::Stencil>&& aStencil,
|
||||
JS::InstantiationStorage* aStorage = nullptr);
|
||||
|
||||
public:
|
||||
// Enter compartment in which the code would be executed. The JSContext
|
||||
// must come from an AutoEntryScript.
|
||||
@@ -111,9 +112,6 @@ class MOZ_STACK_CLASS JSExecutionContext final {
|
||||
MOZ_ASSERT_IF(mEncodeBytecode && mScript && mRv == NS_OK, mScriptUsed);
|
||||
}
|
||||
|
||||
void SetKeepStencil() { mKeepStencil = true; }
|
||||
already_AddRefed<JS::Stencil> StealStencil() { return mStencil.forget(); }
|
||||
|
||||
// The returned value would be converted to a string if the
|
||||
// |aCoerceToString| is flag set.
|
||||
JSExecutionContext& SetCoerceToString(bool aCoerceToString) {
|
||||
@@ -145,12 +143,6 @@ class MOZ_STACK_CLASS JSExecutionContext final {
|
||||
// Decode a script contained in a buffer.
|
||||
nsresult Decode(const JS::TranscodeRange& aBytecodeBuf);
|
||||
|
||||
// Instantiate (on main-thread) a JS::Stencil generated by off-thread or
|
||||
// main-thread parsing or decoding.
|
||||
nsresult InstantiateStencil(RefPtr<JS::Stencil>&& aStencil,
|
||||
bool& incrementalEncodingAlreadyStarted,
|
||||
JS::InstantiationStorage* aStorage = nullptr);
|
||||
|
||||
// Get a successfully compiled script.
|
||||
JSScript* GetScript();
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
#include "mozilla/ScrollContainerFrame.h"
|
||||
#include "mozilla/ServoStyleSet.h"
|
||||
#include "mozilla/SharedStyleSheetCache.h"
|
||||
#include "mozilla/dom/SharedScriptCache.h"
|
||||
#include "mozilla/StaticPrefs_test.h"
|
||||
#include "mozilla/InputTaskManager.h"
|
||||
#include "nsIObjectLoadingContent.h"
|
||||
@@ -1290,12 +1289,6 @@ nsDOMWindowUtils::ClearSharedStyleSheetCache() {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMWindowUtils::ClearSharedScriptCache() {
|
||||
SharedScriptCache::Clear();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMWindowUtils::GetParsedStyleSheets(uint32_t* aSheets) {
|
||||
RefPtr<Document> doc = GetDocument();
|
||||
|
||||
@@ -243,22 +243,6 @@ namespace ChromeUtils {
|
||||
*/
|
||||
undefined clearStyleSheetCache();
|
||||
|
||||
/**
|
||||
* Clears the JavaScript cache by baseDomain. This includes associated
|
||||
* state-partitioned cache.
|
||||
*/
|
||||
undefined clearScriptCacheByBaseDomain(UTF8String baseDomain);
|
||||
|
||||
/**
|
||||
* Clears the JavaScript cache by principal.
|
||||
*/
|
||||
undefined clearScriptCacheByPrincipal(Principal principal);
|
||||
|
||||
/**
|
||||
* Clears the entire JavaScript cache.
|
||||
*/
|
||||
undefined clearScriptCache();
|
||||
|
||||
/**
|
||||
* If the profiler is currently running and recording the current thread,
|
||||
* add a marker for the current thread. No-op otherwise.
|
||||
|
||||
@@ -841,11 +841,6 @@ interface nsIDOMWindowUtils : nsISupports {
|
||||
*/
|
||||
void clearSharedStyleSheetCache();
|
||||
|
||||
/**
|
||||
* Clears the SharedScriptCache.
|
||||
*/
|
||||
void clearSharedScriptCache();
|
||||
|
||||
/**
|
||||
* Returns the number of stylesheets that have been parsed on this document.
|
||||
* Useful to test caching.
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
#include "mozilla/SchedulerGroup.h"
|
||||
#include "mozilla/ScopeExit.h"
|
||||
#include "mozilla/SharedStyleSheetCache.h"
|
||||
#include "mozilla/dom/SharedScriptCache.h"
|
||||
#include "mozilla/SimpleEnumerator.h"
|
||||
#include "mozilla/SpinEventLoopUntil.h"
|
||||
#include "mozilla/StaticPrefs_browser.h"
|
||||
@@ -2131,16 +2130,6 @@ mozilla::ipc::IPCResult ContentChild::RecvClearStyleSheetCache(
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult ContentChild::RecvClearScriptCache(
|
||||
const Maybe<RefPtr<nsIPrincipal>>& aForPrincipal,
|
||||
const Maybe<nsCString>& aBaseDomain) {
|
||||
nsIPrincipal* principal =
|
||||
aForPrincipal ? aForPrincipal.value().get() : nullptr;
|
||||
const nsCString* baseDomain = aBaseDomain ? aBaseDomain.ptr() : nullptr;
|
||||
SharedScriptCache::Clear(principal, baseDomain);
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult ContentChild::RecvClearImageCacheFromPrincipal(
|
||||
nsIPrincipal* aPrincipal) {
|
||||
imgLoader* loader;
|
||||
|
||||
@@ -252,10 +252,6 @@ class ContentChild final : public PContentChild,
|
||||
const Maybe<RefPtr<nsIPrincipal>>& aForPrincipal,
|
||||
const Maybe<nsCString>& aBaseDomain);
|
||||
|
||||
mozilla::ipc::IPCResult RecvClearScriptCache(
|
||||
const Maybe<RefPtr<nsIPrincipal>>& aForPrincipal,
|
||||
const Maybe<nsCString>& aBaseDomain);
|
||||
|
||||
mozilla::ipc::IPCResult RecvClearImageCacheFromPrincipal(
|
||||
nsIPrincipal* aPrincipal);
|
||||
mozilla::ipc::IPCResult RecvClearImageCacheFromBaseDomain(
|
||||
|
||||
@@ -666,9 +666,6 @@ child:
|
||||
async ClearStyleSheetCache(nullable nsIPrincipal? aForPrincipal,
|
||||
nsCString? aBaseDomain);
|
||||
|
||||
async ClearScriptCache(nullable nsIPrincipal? aForPrincipal,
|
||||
nsCString? aBaseDomain);
|
||||
|
||||
async SetOffline(bool offline);
|
||||
async SetConnectivity(bool connectivity);
|
||||
async SetCaptivePortalState(int32_t aState);
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsIAsyncVerifyRedirectCallback.h"
|
||||
#include "nsICacheInfoChannel.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIHttpChannel.h"
|
||||
@@ -124,27 +123,10 @@ ScriptLoadHandler::ScriptLoadHandler(
|
||||
|
||||
ScriptLoadHandler::~ScriptLoadHandler() = default;
|
||||
|
||||
NS_IMPL_ISUPPORTS(ScriptLoadHandler, nsIIncrementalStreamLoaderObserver,
|
||||
nsIChannelEventSink, nsIInterfaceRequestor)
|
||||
|
||||
static uint32_t CalculateExpirationTime(nsIRequest* aRequest, nsIURI* aURI) {
|
||||
auto info = nsContentUtils::GetSubresourceCacheValidationInfo(aRequest, aURI);
|
||||
|
||||
// For now, we never cache entries that we have to revalidate, or whose
|
||||
// channel don't support caching.
|
||||
if (info.mMustRevalidate || !info.mExpirationTime) {
|
||||
return nsContentUtils::SecondsFromPRTime(PR_Now()) - 1;
|
||||
}
|
||||
return *info.mExpirationTime;
|
||||
}
|
||||
NS_IMPL_ISUPPORTS(ScriptLoadHandler, nsIIncrementalStreamLoaderObserver)
|
||||
|
||||
NS_IMETHODIMP
|
||||
ScriptLoadHandler::OnStartRequest(nsIRequest* aRequest) {
|
||||
mRequest->SetMinimumExpirationTime(
|
||||
CalculateExpirationTime(aRequest, mRequest->mURI));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
ScriptLoadHandler::OnStartRequest(nsIRequest* aRequest) { return NS_OK; }
|
||||
|
||||
NS_IMETHODIMP
|
||||
ScriptLoadHandler::OnIncrementalData(nsIIncrementalStreamLoader* aLoader,
|
||||
@@ -382,11 +364,6 @@ ScriptLoadHandler::OnStreamComplete(nsIIncrementalStreamLoader* aLoader,
|
||||
nsCOMPtr<nsIRequest> channelRequest;
|
||||
aLoader->GetRequest(getter_AddRefs(channelRequest));
|
||||
|
||||
{
|
||||
nsCOMPtr<nsIChannel> channel = do_QueryInterface(channelRequest);
|
||||
channel->SetNotificationCallbacks(nullptr);
|
||||
}
|
||||
|
||||
auto firstMessage = !mPreloadStartNotified;
|
||||
if (!mPreloadStartNotified) {
|
||||
mPreloadStartNotified = true;
|
||||
@@ -489,26 +466,6 @@ ScriptLoadHandler::OnStreamComplete(nsIIncrementalStreamLoader* aLoader,
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ScriptLoadHandler::GetInterface(const nsIID& aIID, void** aResult) {
|
||||
if (aIID.Equals(NS_GET_IID(nsIChannelEventSink))) {
|
||||
return QueryInterface(aIID, aResult);
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
nsresult ScriptLoadHandler::AsyncOnChannelRedirect(
|
||||
nsIChannel* aOld, nsIChannel* aNew, uint32_t aFlags,
|
||||
nsIAsyncVerifyRedirectCallback* aCallback) {
|
||||
mRequest->SetMinimumExpirationTime(
|
||||
CalculateExpirationTime(aOld, mRequest->mURI));
|
||||
|
||||
aCallback->OnRedirectVerifyCallback(NS_OK);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#undef LOG_ENABLED
|
||||
#undef LOG
|
||||
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
#define mozilla_dom_ScriptLoadHandler_h
|
||||
|
||||
#include "nsIIncrementalStreamLoader.h"
|
||||
#include "nsIChannelEventSink.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsISupports.h"
|
||||
#include "mozilla/Encoding.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
@@ -67,9 +65,7 @@ class ScriptDecoder {
|
||||
mozilla::UniquePtr<mozilla::Decoder> mDecoder;
|
||||
};
|
||||
|
||||
class ScriptLoadHandler final : public nsIIncrementalStreamLoaderObserver,
|
||||
public nsIChannelEventSink,
|
||||
public nsIInterfaceRequestor {
|
||||
class ScriptLoadHandler final : public nsIIncrementalStreamLoaderObserver {
|
||||
public:
|
||||
explicit ScriptLoadHandler(
|
||||
ScriptLoader* aScriptLoader, JS::loader::ScriptLoadRequest* aRequest,
|
||||
@@ -77,8 +73,6 @@ class ScriptLoadHandler final : public nsIIncrementalStreamLoaderObserver,
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIINCREMENTALSTREAMLOADEROBSERVER
|
||||
NS_DECL_NSICHANNELEVENTSINK
|
||||
NS_DECL_NSIINTERFACEREQUESTOR
|
||||
|
||||
private:
|
||||
virtual ~ScriptLoadHandler();
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "ScriptTrace.h"
|
||||
#include "ModuleLoader.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "SharedScriptCache.h"
|
||||
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/dom/FetchPriority.h"
|
||||
@@ -166,28 +165,13 @@ inline void ImplCycleCollectionTraverse(
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ScriptLoader)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(ScriptLoader)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ScriptLoader)
|
||||
if (tmp->mDocument) {
|
||||
tmp->DropDocumentReference();
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(
|
||||
mNonAsyncExternalScriptInsertedRequests, mLoadingAsyncRequests,
|
||||
mLoadedAsyncRequests, mOffThreadCompilingRequests, mDeferRequests,
|
||||
mXSLTRequests, mParserBlockingRequest, mBytecodeEncodingQueue, mPreloads,
|
||||
mPendingChildLoaders, mModuleLoader, mWebExtModuleLoaders,
|
||||
mShadowRealmModuleLoaders)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(ScriptLoader)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(
|
||||
mNonAsyncExternalScriptInsertedRequests, mLoadingAsyncRequests,
|
||||
mLoadedAsyncRequests, mOffThreadCompilingRequests, mDeferRequests,
|
||||
mXSLTRequests, mParserBlockingRequest, mBytecodeEncodingQueue, mPreloads,
|
||||
mPendingChildLoaders, mModuleLoader, mWebExtModuleLoaders,
|
||||
mShadowRealmModuleLoaders)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
NS_IMPL_CYCLE_COLLECTION(ScriptLoader, mNonAsyncExternalScriptInsertedRequests,
|
||||
mLoadingAsyncRequests, mLoadedAsyncRequests,
|
||||
mOffThreadCompilingRequests, mDeferRequests,
|
||||
mXSLTRequests, mParserBlockingRequest,
|
||||
mBytecodeEncodingQueue, mPreloads,
|
||||
mPendingChildLoaders, mModuleLoader,
|
||||
mWebExtModuleLoaders, mShadowRealmModuleLoaders)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(ScriptLoader)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(ScriptLoader)
|
||||
@@ -212,13 +196,6 @@ ScriptLoader::ScriptLoader(Document* aDocument)
|
||||
mSpeculativeOMTParsingEnabled = StaticPrefs::
|
||||
dom_script_loader_external_scripts_speculative_omt_parse_enabled();
|
||||
|
||||
#ifdef NIGHTLY_BUILD
|
||||
if (StaticPrefs::dom_script_loader_navigation_cache()) {
|
||||
mCache = SharedScriptCache::Get();
|
||||
RegisterToCache();
|
||||
}
|
||||
#endif
|
||||
|
||||
mShutdownObserver = new AsyncCompileShutdownObserver(this);
|
||||
nsContentUtils::RegisterShutdownObserver(mShutdownObserver);
|
||||
}
|
||||
@@ -296,44 +273,6 @@ void ScriptLoader::SetGlobalObject(nsIGlobalObject* aGlobalObject) {
|
||||
mModuleLoader);
|
||||
}
|
||||
|
||||
void ScriptLoader::DropDocumentReference() {
|
||||
if (mDocument && mCache) {
|
||||
DeregisterFromCache();
|
||||
}
|
||||
|
||||
mDocument = nullptr;
|
||||
}
|
||||
|
||||
void ScriptLoader::RegisterToCache() {
|
||||
if (mCache) {
|
||||
MOZ_ASSERT(mDocument);
|
||||
mCache->RegisterLoader(*this);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptLoader::DeregisterFromCache() {
|
||||
if (mCache) {
|
||||
MOZ_ASSERT(mDocument);
|
||||
mCache->CancelLoadsForLoader(*this);
|
||||
mCache->UnregisterLoader(*this);
|
||||
}
|
||||
}
|
||||
|
||||
nsIPrincipal* ScriptLoader::LoaderPrincipal() const {
|
||||
return mDocument->NodePrincipal();
|
||||
}
|
||||
|
||||
nsIPrincipal* ScriptLoader::PartitionedPrincipal() const {
|
||||
if (mDocument && StaticPrefs::privacy_partition_network_state()) {
|
||||
return mDocument->PartitionedPrincipal();
|
||||
}
|
||||
return LoaderPrincipal();
|
||||
}
|
||||
|
||||
bool ScriptLoader::ShouldBypassCache() const {
|
||||
return mDocument && nsContentUtils::ShouldBypassSubResourceCache(mDocument);
|
||||
}
|
||||
|
||||
void ScriptLoader::RegisterContentScriptModuleLoader(ModuleLoader* aLoader) {
|
||||
MOZ_ASSERT(aLoader);
|
||||
MOZ_ASSERT(aLoader->GetScriptLoader() == this);
|
||||
@@ -893,8 +832,7 @@ nsresult ScriptLoader::PrepareHttpRequestAndInitiatorType(
|
||||
}
|
||||
|
||||
nsresult ScriptLoader::PrepareIncrementalStreamLoader(
|
||||
nsIIncrementalStreamLoader** aOutLoader, nsIChannel* aChannel,
|
||||
ScriptLoadRequest* aRequest) {
|
||||
nsIIncrementalStreamLoader** aOutLoader, ScriptLoadRequest* aRequest) {
|
||||
UniquePtr<mozilla::dom::SRICheckDataVerifier> sriDataVerifier;
|
||||
if (!aRequest->mIntegrity.IsEmpty()) {
|
||||
nsAutoCString sourceUri;
|
||||
@@ -908,8 +846,6 @@ nsresult ScriptLoader::PrepareIncrementalStreamLoader(
|
||||
RefPtr<ScriptLoadHandler> handler =
|
||||
new ScriptLoadHandler(this, aRequest, std::move(sriDataVerifier));
|
||||
|
||||
aChannel->SetNotificationCallbacks(handler);
|
||||
|
||||
nsresult rv = NS_NewIncrementalStreamLoader(aOutLoader, handler);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return rv;
|
||||
@@ -959,8 +895,7 @@ nsresult ScriptLoader::StartLoadInternal(
|
||||
mDocument->NodePrincipal()->OriginAttributesRef());
|
||||
|
||||
nsCOMPtr<nsIIncrementalStreamLoader> loader;
|
||||
rv =
|
||||
PrepareIncrementalStreamLoader(getter_AddRefs(loader), channel, aRequest);
|
||||
rv = PrepareIncrementalStreamLoader(getter_AddRefs(loader), aRequest);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
auto key = PreloadHashKey::CreateAsScript(
|
||||
@@ -1035,7 +970,7 @@ already_AddRefed<ScriptLoadRequest> ScriptLoader::CreateLoadRequest(
|
||||
nsIPrincipal* aTriggeringPrincipal, CORSMode aCORSMode,
|
||||
const nsAString& aNonce, RequestPriority aRequestPriority,
|
||||
const SRIMetadata& aIntegrity, ReferrerPolicy aReferrerPolicy,
|
||||
ParserMetadata aParserMetadata, RequestType requestType) {
|
||||
ParserMetadata aParserMetadata) {
|
||||
nsIURI* referrer = mDocument->GetDocumentURIAsReferrer();
|
||||
RefPtr<ScriptFetchOptions> fetchOptions =
|
||||
new ScriptFetchOptions(aCORSMode, aNonce, aRequestPriority,
|
||||
@@ -1046,24 +981,6 @@ already_AddRefed<ScriptLoadRequest> ScriptLoader::CreateLoadRequest(
|
||||
RefPtr<ScriptLoadRequest> aRequest =
|
||||
new ScriptLoadRequest(aKind, aURI, aReferrerPolicy, fetchOptions,
|
||||
aIntegrity, referrer, context);
|
||||
if (requestType == RequestType::External && mCache) {
|
||||
ScriptHashKey key(this, aRequest);
|
||||
auto cacheResult = mCache->Lookup(*this, key,
|
||||
/* aSyncLoad = */ true);
|
||||
if (cacheResult.mState == CachedSubResourceState::Complete) {
|
||||
if (NS_FAILED(
|
||||
CheckContentPolicy(mDocument, aElement, aNonce, aRequest))) {
|
||||
aRequest->NoCacheEntryFound();
|
||||
return aRequest.forget();
|
||||
}
|
||||
|
||||
aRequest->CacheEntryFound(cacheResult.mCompleteValue);
|
||||
return aRequest.forget();
|
||||
}
|
||||
|
||||
aRequest->NoCacheEntryFound();
|
||||
return aRequest.forget();
|
||||
}
|
||||
|
||||
aRequest->NoCacheEntryFound();
|
||||
return aRequest.forget();
|
||||
@@ -1165,8 +1082,9 @@ bool ScriptLoader::ProcessExternalScript(nsIScriptElement* aElement,
|
||||
|
||||
RefPtr<ScriptLoadRequest> request =
|
||||
LookupPreloadRequest(aElement, aScriptKind, sriMetadata);
|
||||
if (request) {
|
||||
if (NS_FAILED(CheckContentPolicy(mDocument, aElement, nonce, request))) {
|
||||
|
||||
if (request &&
|
||||
NS_FAILED(CheckContentPolicy(mDocument, aElement, nonce, request))) {
|
||||
LOG(("ScriptLoader (%p): content policy check failed for preload", this));
|
||||
|
||||
// Probably plans have changed; even though the preload was allowed seems
|
||||
@@ -1176,6 +1094,7 @@ bool ScriptLoader::ProcessExternalScript(nsIScriptElement* aElement,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (request) {
|
||||
// Use the preload request.
|
||||
|
||||
LOG(("ScriptLoadRequest (%p): Using preload request", request.get()));
|
||||
@@ -1215,10 +1134,10 @@ bool ScriptLoader::ProcessExternalScript(nsIScriptElement* aElement,
|
||||
ReferrerPolicy referrerPolicy = GetReferrerPolicy(aElement);
|
||||
ParserMetadata parserMetadata = GetParserMetadata(aElement);
|
||||
|
||||
request = CreateLoadRequest(
|
||||
aScriptKind, scriptURI, aElement, principal, ourCORSMode, nonce,
|
||||
FetchPriorityToRequestPriority(fetchPriority), sriMetadata,
|
||||
referrerPolicy, parserMetadata, RequestType::External);
|
||||
request = CreateLoadRequest(aScriptKind, scriptURI, aElement, principal,
|
||||
ourCORSMode, nonce,
|
||||
FetchPriorityToRequestPriority(fetchPriority),
|
||||
sriMetadata, referrerPolicy, parserMetadata);
|
||||
request->GetScriptLoadContext()->mIsInline = false;
|
||||
request->GetScriptLoadContext()->SetScriptMode(
|
||||
aElement->GetScriptDeferred(), aElement->GetScriptAsync(), false);
|
||||
@@ -1229,7 +1148,6 @@ bool ScriptLoader::ProcessExternalScript(nsIScriptElement* aElement,
|
||||
LOG(("ScriptLoadRequest (%p): Created request for external script",
|
||||
request.get()));
|
||||
|
||||
if (!request->IsStencil()) {
|
||||
nsresult rv = StartLoad(request, Nothing());
|
||||
if (NS_FAILED(rv)) {
|
||||
ReportErrorToConsole(request, rv);
|
||||
@@ -1246,7 +1164,6 @@ bool ScriptLoader::ProcessExternalScript(nsIScriptElement* aElement,
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We should still be in loading stage of script unless we're loading a
|
||||
// module or speculatively off-main-thread parsing a script.
|
||||
@@ -1399,7 +1316,7 @@ bool ScriptLoader::ProcessInlineScript(nsIScriptElement* aElement,
|
||||
mDocument->NodePrincipal(), corsMode, nonce,
|
||||
FetchPriorityToRequestPriority(fetchPriority),
|
||||
SRIMetadata(), // SRI doesn't apply
|
||||
referrerPolicy, parserMetadata, RequestType::Inline);
|
||||
referrerPolicy, parserMetadata);
|
||||
request->GetScriptLoadContext()->mIsInline = true;
|
||||
request->GetScriptLoadContext()->mLineNo = aElement->GetScriptLineNumber();
|
||||
request->GetScriptLoadContext()->mColumnNo =
|
||||
@@ -1659,8 +1576,7 @@ nsresult ScriptLoader::CompileOffThreadOrProcessRequest(
|
||||
NS_ASSERTION(nsContentUtils::IsSafeToRunScript(),
|
||||
"Processing requests when running scripts is unsafe.");
|
||||
|
||||
if (!aRequest->IsStencil() &&
|
||||
!aRequest->GetScriptLoadContext()->mCompileOrDecodeTask &&
|
||||
if (!aRequest->GetScriptLoadContext()->mCompileOrDecodeTask &&
|
||||
!aRequest->GetScriptLoadContext()->CompileStarted()) {
|
||||
bool couldCompile = false;
|
||||
nsresult rv = AttemptOffThreadScriptCompile(aRequest, &couldCompile);
|
||||
@@ -2449,11 +2365,6 @@ void ScriptLoader::CalculateBytecodeCacheFlag(ScriptLoadRequest* aRequest) {
|
||||
using mozilla::TimeDuration;
|
||||
using mozilla::TimeStamp;
|
||||
|
||||
if (aRequest->IsStencil()) {
|
||||
aRequest->MarkPassedConditionForBytecodeEncoding();
|
||||
return;
|
||||
}
|
||||
|
||||
// We need the nsICacheInfoChannel to exist to be able to open the alternate
|
||||
// data output stream. This pointer would only be non-null if the bytecode was
|
||||
// activated at the time the channel got created in StartLoad.
|
||||
@@ -2638,7 +2549,7 @@ nsresult ScriptLoader::EvaluateScriptElement(ScriptLoadRequest* aRequest) {
|
||||
return EvaluateScript(globalObject, aRequest);
|
||||
}
|
||||
|
||||
nsresult ScriptLoader::InstantiateClassicScriptFromMaybeEncodedSource(
|
||||
nsresult ScriptLoader::CompileOrDecodeClassicScript(
|
||||
JSContext* aCx, JSExecutionContext& aExec, ScriptLoadRequest* aRequest) {
|
||||
nsAutoCString profilerLabelString;
|
||||
aRequest->GetScriptLoadContext()->GetProfilerLabel(profilerLabelString);
|
||||
@@ -2699,65 +2610,6 @@ nsresult ScriptLoader::InstantiateClassicScriptFromMaybeEncodedSource(
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult ScriptLoader::InstantiateClassicScriptFromCachedStencil(
|
||||
JSContext* aCx, JSExecutionContext& aExec, ScriptLoadRequest* aRequest,
|
||||
JS::Stencil* aStencil) {
|
||||
RefPtr<JS::Stencil> stencil = JS::DuplicateStencil(aCx, aStencil);
|
||||
if (!stencil) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
aExec.SetEncodeBytecode(true);
|
||||
|
||||
bool incrementalEncodingAlreadyStarted = false;
|
||||
nsresult rv = aExec.InstantiateStencil(std::move(stencil),
|
||||
incrementalEncodingAlreadyStarted);
|
||||
if (incrementalEncodingAlreadyStarted) {
|
||||
aRequest->MarkSkippedBytecodeEncoding();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult ScriptLoader::InstantiateClassicScriptFromAny(
|
||||
JSContext* aCx, JSExecutionContext& aExec, ScriptLoadRequest* aRequest) {
|
||||
if (aRequest->IsStencil()) {
|
||||
RefPtr<JS::Stencil> stencil = aRequest->GetStencil();
|
||||
return InstantiateClassicScriptFromCachedStencil(aCx, aExec, aRequest,
|
||||
stencil);
|
||||
}
|
||||
|
||||
bool createCache = false;
|
||||
if (mCache) {
|
||||
createCache = aRequest->IsCacheable();
|
||||
|
||||
ScriptHashKey key(this, aRequest);
|
||||
auto cacheResult = mCache->Lookup(*this, key,
|
||||
/* aSyncLoad = */ true);
|
||||
if (cacheResult.mState == CachedSubResourceState::Complete) {
|
||||
// NOTE: Avoid creating cache regardless of CSP.
|
||||
createCache = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (createCache) {
|
||||
aExec.SetKeepStencil();
|
||||
}
|
||||
|
||||
nsresult rv =
|
||||
InstantiateClassicScriptFromMaybeEncodedSource(aCx, aExec, aRequest);
|
||||
// NOTE: rv can be NS_SUCCESS_DOM_SCRIPT_EVALUATION_THREW.
|
||||
if (rv == NS_OK) {
|
||||
if (createCache) {
|
||||
MOZ_ASSERT(mCache);
|
||||
aRequest->SetStencil(aExec.StealStencil());
|
||||
auto loadData = MakeRefPtr<ScriptLoadData>(this, aRequest);
|
||||
mCache->Insert(*loadData);
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* static */
|
||||
nsCString& ScriptLoader::BytecodeMimeTypeFor(ScriptLoadRequest* aRequest) {
|
||||
if (aRequest->IsModuleRequest()) {
|
||||
@@ -2779,18 +2631,12 @@ nsresult ScriptLoader::MaybePrepareForBytecodeEncodingAfterExecute(
|
||||
ScriptLoadRequest* aRequest, nsresult aRv) {
|
||||
if (aRequest->IsMarkedForBytecodeEncoding()) {
|
||||
TRACE_FOR_TEST(aRequest, "scriptloader_encode");
|
||||
// Bytecode-encoding branch is used for 2 purposes right now:
|
||||
// * If the request is stencil, reflect delazifications to cached stencil
|
||||
// * otherwise, encode the initial stencil and delazifications
|
||||
//
|
||||
// For latter case, check that the TranscodeBuffer which is going to
|
||||
// receive the encoded bytecode only contains the SRI, and nothing more.
|
||||
// Check that the TranscodeBuffer which is going to receive the encoded
|
||||
// bytecode only contains the SRI, and nothing more.
|
||||
//
|
||||
// NOTE: This assertion will fail once we start encoding more data after the
|
||||
// first encode.
|
||||
MOZ_ASSERT_IF(
|
||||
!aRequest->IsStencil(),
|
||||
aRequest->GetSRILength() == aRequest->SRIAndBytecode().length());
|
||||
MOZ_ASSERT(aRequest->GetSRILength() == aRequest->SRIAndBytecode().length());
|
||||
RegisterForBytecodeEncoding(aRequest);
|
||||
MOZ_ASSERT(IsAlreadyHandledForBytecodeEncodingPreparation(aRequest));
|
||||
|
||||
@@ -2859,28 +2705,10 @@ nsresult ScriptLoader::EvaluateScript(nsIGlobalObject* aGlobalObject,
|
||||
|
||||
// Create a ClassicScript object and associate it with the JSScript.
|
||||
MOZ_ASSERT(aRequest->mLoadedScript->IsClassicScript());
|
||||
MOZ_ASSERT(aRequest->mLoadedScript->GetFetchOptions()->IsCompatible(
|
||||
aRequest->mFetchOptions));
|
||||
|
||||
#ifdef DEBUG
|
||||
{
|
||||
bool equals;
|
||||
(void)aRequest->mLoadedScript->GetURI()->Equals(aRequest->mURI, &equals);
|
||||
MOZ_ASSERT(equals);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (aRequest->IsStencil()) {
|
||||
#ifdef DEBUG
|
||||
bool equals;
|
||||
(void)aRequest->mLoadedScript->BaseURL()->Equals(aRequest->mBaseURL,
|
||||
&equals);
|
||||
MOZ_ASSERT(equals);
|
||||
#endif
|
||||
} else {
|
||||
MOZ_ASSERT(aRequest->mLoadedScript->GetFetchOptions() ==
|
||||
aRequest->mFetchOptions);
|
||||
MOZ_ASSERT(aRequest->mLoadedScript->GetURI() == aRequest->mURI);
|
||||
aRequest->mLoadedScript->SetBaseURL(aRequest->mBaseURL);
|
||||
}
|
||||
|
||||
RefPtr<ClassicScript> classicScript =
|
||||
aRequest->mLoadedScript->AsClassicScript();
|
||||
JS::Rooted<JS::Value> classicScriptValue(cx, JS::PrivateValue(classicScript));
|
||||
@@ -2916,7 +2744,7 @@ nsresult ScriptLoader::EvaluateScript(nsIGlobalObject* aGlobalObject,
|
||||
JSExecutionContext exec(cx, global, options, classicScriptValue,
|
||||
introductionScript);
|
||||
|
||||
rv = InstantiateClassicScriptFromAny(cx, exec, aRequest);
|
||||
rv = CompileOrDecodeClassicScript(cx, exec, aRequest);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
@@ -2963,7 +2791,7 @@ LoadedScript* ScriptLoader::GetActiveScript(JSContext* aCx) {
|
||||
}
|
||||
|
||||
void ScriptLoader::RegisterForBytecodeEncoding(ScriptLoadRequest* aRequest) {
|
||||
MOZ_ASSERT_IF(!aRequest->IsStencil(), aRequest->mCacheInfo);
|
||||
MOZ_ASSERT(aRequest->mCacheInfo);
|
||||
MOZ_ASSERT(aRequest->IsMarkedForBytecodeEncoding());
|
||||
MOZ_DIAGNOSTIC_ASSERT(!aRequest->isInList());
|
||||
mBytecodeEncodingQueue.AppendElement(aRequest);
|
||||
@@ -3073,29 +2901,20 @@ void ScriptLoader::EncodeRequestBytecode(JSContext* aCx,
|
||||
ScriptLoadRequest* aRequest) {
|
||||
using namespace mozilla::Telemetry;
|
||||
nsresult rv = NS_OK;
|
||||
MOZ_ASSERT_IF(!aRequest->IsStencil(), aRequest->mCacheInfo);
|
||||
MOZ_ASSERT(aRequest->mCacheInfo);
|
||||
auto bytecodeFailed = mozilla::MakeScopeExit(
|
||||
[&]() { TRACE_FOR_TEST_NONE(aRequest, "scriptloader_bytecode_failed"); });
|
||||
|
||||
bool result;
|
||||
if (aRequest->IsModuleRequest()) {
|
||||
aRequest->mScriptForBytecodeEncoding = nullptr;
|
||||
ModuleScript* moduleScript = aRequest->AsModuleRequest()->mModuleScript;
|
||||
JS::Rooted<JSObject*> module(aCx, moduleScript->ModuleRecord());
|
||||
result =
|
||||
JS::FinishIncrementalEncoding(aCx, module, aRequest->SRIAndBytecode());
|
||||
} else {
|
||||
RefPtr<JS::Stencil> stencil;
|
||||
JS::Rooted<JSScript*> script(aCx, aRequest->mScriptForBytecodeEncoding);
|
||||
aRequest->mScriptForBytecodeEncoding = nullptr;
|
||||
result =
|
||||
JS::FinishIncrementalEncoding(aCx, script, getter_AddRefs(stencil));
|
||||
if (result) {
|
||||
aRequest->SetStencil(stencil.forget());
|
||||
bytecodeFailed.release();
|
||||
return;
|
||||
}
|
||||
// TODO: Bytecode encoding for script, at different timing.
|
||||
JS::FinishIncrementalEncoding(aCx, script, aRequest->SRIAndBytecode());
|
||||
}
|
||||
if (!result) {
|
||||
// Encoding can be aborted for non-supported syntax (e.g. asm.js), or
|
||||
@@ -3195,7 +3014,6 @@ void ScriptLoader::GiveUpBytecodeEncoding() {
|
||||
} else {
|
||||
JS::Rooted<JSScript*> script(aes->cx(),
|
||||
request->mScriptForBytecodeEncoding);
|
||||
request->mScriptForBytecodeEncoding = nullptr;
|
||||
JS::AbortIncrementalEncoding(script);
|
||||
}
|
||||
}
|
||||
@@ -4085,8 +3903,7 @@ void ScriptLoader::PreloadURI(
|
||||
Element::StringToCORSMode(aCrossOrigin), aNonce,
|
||||
requestPriority, sriMetadata, aReferrerPolicy,
|
||||
aLinkPreload ? ParserMetadata::NotParserInserted
|
||||
: ParserMetadata::ParserInserted,
|
||||
RequestType::Preload);
|
||||
: ParserMetadata::ParserInserted);
|
||||
request->GetScriptLoadContext()->mIsInline = false;
|
||||
request->GetScriptLoadContext()->mScriptFromHead = aScriptFromHead;
|
||||
request->GetScriptLoadContext()->SetScriptMode(aDefer, aAsync, aLinkPreload);
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsRefPtrHashtable.h"
|
||||
#include "nsIScriptElement.h"
|
||||
#include "SharedScriptCache.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsTArray.h"
|
||||
@@ -152,35 +151,7 @@ class ScriptLoader final : public JS::loader::ScriptLoaderInterface {
|
||||
* which it is initialized. This call forces the reference to
|
||||
* be dropped.
|
||||
*/
|
||||
void DropDocumentReference();
|
||||
|
||||
/**
|
||||
* Register this loader to the shared script cache.
|
||||
*
|
||||
* When the principal for the document for the loader is modified,
|
||||
* DeregisterFromCache and RegisterToCache should be called to reflect the
|
||||
* modification (See Document::SetPrincipals).
|
||||
*/
|
||||
void RegisterToCache();
|
||||
|
||||
/**
|
||||
* Deregister this loader from the shared script cache and
|
||||
* clear the cache data associated with this loader.
|
||||
*/
|
||||
void DeregisterFromCache();
|
||||
|
||||
// Methods for SharedScriptCache.
|
||||
nsIPrincipal* LoaderPrincipal() const;
|
||||
nsIPrincipal* PartitionedPrincipal() const;
|
||||
|
||||
bool ShouldBypassCache() const;
|
||||
|
||||
template <typename T>
|
||||
bool HasLoaded(const T& aKey) {
|
||||
// NOTE: ScriptLoader doesn't cache pending/loading requests, and
|
||||
// this method is unsed.
|
||||
return false;
|
||||
}
|
||||
void DropDocumentReference() { mDocument = nullptr; }
|
||||
|
||||
/**
|
||||
* Add an observer for all scripts loaded through this loader.
|
||||
@@ -462,14 +433,12 @@ class ScriptLoader final : public JS::loader::ScriptLoaderInterface {
|
||||
private:
|
||||
~ScriptLoader();
|
||||
|
||||
enum class RequestType { Inline, External, Preload };
|
||||
|
||||
already_AddRefed<ScriptLoadRequest> CreateLoadRequest(
|
||||
ScriptKind aKind, nsIURI* aURI, nsIScriptElement* aElement,
|
||||
nsIPrincipal* aTriggeringPrincipal, mozilla::CORSMode aCORSMode,
|
||||
const nsAString& aNonce, RequestPriority aRequestPriority,
|
||||
const SRIMetadata& aIntegrity, ReferrerPolicy aReferrerPolicy,
|
||||
JS::loader::ParserMetadata aParserMetadata, RequestType requestType);
|
||||
JS::loader::ParserMetadata aParserMetadata);
|
||||
|
||||
/**
|
||||
* Unblocks the creator parser of the parser-blocking scripts.
|
||||
@@ -540,8 +509,7 @@ class ScriptLoader final : public JS::loader::ScriptLoaderInterface {
|
||||
const Maybe<nsAutoString>& aCharsetForPreload);
|
||||
|
||||
[[nodiscard]] nsresult PrepareIncrementalStreamLoader(
|
||||
nsIIncrementalStreamLoader** aOutLoader, nsIChannel* aChannel,
|
||||
ScriptLoadRequest* aRequest);
|
||||
nsIIncrementalStreamLoader** aOutLoader, ScriptLoadRequest* aRequest);
|
||||
|
||||
/**
|
||||
* Start a load for a script (module or classic) URI.
|
||||
@@ -626,26 +594,12 @@ class ScriptLoader final : public JS::loader::ScriptLoaderInterface {
|
||||
// Implements https://html.spec.whatwg.org/#execute-the-script-block
|
||||
nsresult EvaluateScriptElement(ScriptLoadRequest* aRequest);
|
||||
|
||||
// Instantiate classic script from one of the following data:
|
||||
// * text source
|
||||
// * encoded bytecode
|
||||
// * cached stencil
|
||||
nsresult InstantiateClassicScriptFromAny(JSContext* aCx,
|
||||
// Handles both bytecode and text source scripts; populates exec with a
|
||||
// compiled script
|
||||
nsresult CompileOrDecodeClassicScript(JSContext* aCx,
|
||||
JSExecutionContext& aExec,
|
||||
ScriptLoadRequest* aRequest);
|
||||
|
||||
// Instantiate classic script from one of the following data:
|
||||
// * text source
|
||||
// * encoded bytecode
|
||||
nsresult InstantiateClassicScriptFromMaybeEncodedSource(
|
||||
JSContext* aCx, JSExecutionContext& aExec, ScriptLoadRequest* aRequest);
|
||||
|
||||
// Instantiate classic script from the following data:
|
||||
// * cached stencil
|
||||
nsresult InstantiateClassicScriptFromCachedStencil(
|
||||
JSContext* aCx, JSExecutionContext& aExec, ScriptLoadRequest* aRequest,
|
||||
JS::Stencil* aStencil);
|
||||
|
||||
static nsCString& BytecodeMimeTypeFor(ScriptLoadRequest* aRequest);
|
||||
|
||||
// Decide whether to encode bytecode for given script load request,
|
||||
@@ -811,8 +765,6 @@ class ScriptLoader final : public JS::loader::ScriptLoaderInterface {
|
||||
nsTArray<RefPtr<ModuleLoader>> mWebExtModuleLoaders;
|
||||
nsTArray<RefPtr<ModuleLoader>> mShadowRealmModuleLoaders;
|
||||
|
||||
RefPtr<SharedScriptCache> mCache;
|
||||
|
||||
// Logging
|
||||
public:
|
||||
static LazyLogModule gCspPRLog;
|
||||
|
||||
@@ -1,158 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "SharedScriptCache.h"
|
||||
|
||||
#include "mozilla/Maybe.h" // Maybe, Some, Nothing
|
||||
#include "mozilla/Unused.h" // Unused
|
||||
#include "nsIPrefService.h" // NS_PREFSERVICE_CONTRACTID
|
||||
#include "nsIPrefBranch.h" // nsIPrefBranch, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID
|
||||
#include "nsISupportsImpl.h" // NS_IMPL_ISUPPORTS
|
||||
#include "nsIMemoryReporter.h" // nsIMemoryReporter, MOZ_DEFINE_MALLOC_SIZE_OF, RegisterWeakMemoryReporter, UnregisterWeakMemoryReporter, MOZ_COLLECT_REPORT, KIND_HEAP, UNITS_BYTES
|
||||
#include "mozilla/dom/ContentParent.h" // dom::ContentParent
|
||||
#include "nsIPrincipal.h" // nsIPrincipal
|
||||
#include "nsStringFwd.h" // nsACString
|
||||
#include "ScriptLoader.h" // ScriptLoader
|
||||
#include "ScriptLoadHandler.h" // ScriptLoadHandler
|
||||
|
||||
namespace mozilla::dom {
|
||||
|
||||
ScriptHashKey::ScriptHashKey(ScriptLoader* aLoader,
|
||||
const JS::loader::ScriptLoadRequest* aRequest)
|
||||
: mURI(aRequest->mURI),
|
||||
mPrincipal(aRequest->TriggeringPrincipal()),
|
||||
mLoaderPrincipal(aLoader->LoaderPrincipal()),
|
||||
mPartitionPrincipal(aLoader->PartitionedPrincipal()),
|
||||
mCORSMode(aRequest->CORSMode()),
|
||||
mSRIMetadata(aRequest->mIntegrity),
|
||||
mKind(aRequest->mKind),
|
||||
mNonce(aRequest->Nonce()),
|
||||
mIsLinkRelPreload(aRequest->GetScriptLoadContext()->IsPreload()) {
|
||||
if (mKind == JS::loader::ScriptKind::eClassic) {
|
||||
if (aRequest->GetScriptLoadContext()->HasScriptElement()) {
|
||||
aRequest->GetScriptLoadContext()->GetHintCharset(mHintCharset);
|
||||
}
|
||||
}
|
||||
|
||||
MOZ_COUNT_CTOR(ScriptHashKey);
|
||||
}
|
||||
|
||||
ScriptHashKey::ScriptHashKey(const ScriptLoadData& aLoadData)
|
||||
: ScriptHashKey(aLoadData.CacheKey()) {}
|
||||
|
||||
bool ScriptHashKey::KeyEquals(const ScriptHashKey& aKey) const {
|
||||
if (mKind != aKey.mKind) {
|
||||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
bool eq;
|
||||
if (NS_FAILED(mURI->Equals(aKey.mURI, &eq)) || !eq) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!mPrincipal->Equals(aKey.mPrincipal)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mCORSMode != aKey.mCORSMode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mNonce != aKey.mNonce) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// NOTE: module always use UTF-8.
|
||||
if (mKind == JS::loader::ScriptKind::eClassic) {
|
||||
if (mHintCharset != aKey.mHintCharset) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!mSRIMetadata.CanTrustBeDelegatedTo(aKey.mSRIMetadata) ||
|
||||
!aKey.mSRIMetadata.CanTrustBeDelegatedTo(mSRIMetadata)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(ScriptLoadData, nsISupports)
|
||||
|
||||
ScriptLoadData::ScriptLoadData(ScriptLoader* aLoader,
|
||||
JS::loader::ScriptLoadRequest* aRequest)
|
||||
: mExpirationTime(aRequest->ExpirationTime()),
|
||||
mLoader(aLoader),
|
||||
mKey(aLoader, aRequest),
|
||||
mLoadedScript(aRequest->getLoadedScript()) {}
|
||||
|
||||
NS_IMPL_ISUPPORTS(SharedScriptCache, nsIMemoryReporter, nsIObserver)
|
||||
|
||||
MOZ_DEFINE_MALLOC_SIZE_OF(SharedScriptCacheMallocSizeOf)
|
||||
|
||||
SharedScriptCache::SharedScriptCache() = default;
|
||||
|
||||
void SharedScriptCache::Init() {
|
||||
RegisterWeakMemoryReporter(this);
|
||||
|
||||
// URL classification (tracking protection etc) are handled inside
|
||||
// nsHttpChannel.
|
||||
// The cache reflects the policy for whether to block or not, and once
|
||||
// the policy is modified, we should discard the cache, to avoid running
|
||||
// a cached script which is supposed to be blocked.
|
||||
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (prefs) {
|
||||
prefs->AddObserver("urlclassifier", this, false);
|
||||
prefs->AddObserver("privacy.trackingprotection.enabled", this, false);
|
||||
}
|
||||
}
|
||||
|
||||
SharedScriptCache::~SharedScriptCache() { UnregisterWeakMemoryReporter(this); }
|
||||
|
||||
void SharedScriptCache::LoadCompleted(SharedScriptCache* aCache,
|
||||
ScriptLoadData& aData) {}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SharedScriptCache::CollectReports(nsIHandleReportCallback* aHandleReport,
|
||||
nsISupports* aData, bool aAnonymize) {
|
||||
MOZ_COLLECT_REPORT("explicit/js-non-window/cache", KIND_HEAP, UNITS_BYTES,
|
||||
SizeOfIncludingThis(SharedScriptCacheMallocSizeOf),
|
||||
"Memory used for SharedScriptCache to share script "
|
||||
"across documents");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SharedScriptCache::Observe(nsISupports* aSubject, const char* aTopic,
|
||||
const char16_t* aData) {
|
||||
if (strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) == 0) {
|
||||
this->Clear();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void SharedScriptCache::Clear(nsIPrincipal* aForPrincipal,
|
||||
const nsACString* aBaseDomain) {
|
||||
using ContentParent = dom::ContentParent;
|
||||
|
||||
if (XRE_IsParentProcess()) {
|
||||
auto forPrincipal = aForPrincipal ? Some(RefPtr(aForPrincipal)) : Nothing();
|
||||
auto baseDomain = aBaseDomain ? Some(nsCString(*aBaseDomain)) : Nothing();
|
||||
|
||||
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
|
||||
Unused << cp->SendClearScriptCache(forPrincipal, baseDomain);
|
||||
}
|
||||
}
|
||||
|
||||
if (sInstance) {
|
||||
sInstance->ClearInProcess(aForPrincipal, aBaseDomain);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mozilla::dom
|
||||
@@ -1,199 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_dom_SharedScriptCache_h
|
||||
#define mozilla_dom_SharedScriptCache_h
|
||||
|
||||
#include "PLDHashTable.h" // PLDHashEntryHdr
|
||||
#include "js/loader/LoadedScript.h" // JS::loader::LoadedScript
|
||||
#include "js/loader/ScriptKind.h" // JS::loader::ScriptKind
|
||||
#include "js/loader/ScriptLoadRequest.h" // JS::loader::ScriptLoadRequest
|
||||
#include "mozilla/WeakPtr.h" // SupportsWeakPtr
|
||||
#include "mozilla/CORSMode.h" // mozilla::CORSMode
|
||||
#include "mozilla/MemoryReporting.h" // MallocSizeOf
|
||||
#include "mozilla/SharedSubResourceCache.h" // SharedSubResourceCache, SharedSubResourceCacheLoadingValueBase
|
||||
#include "nsIMemoryReporter.h" // nsIMemoryReporter, NS_DECL_NSIMEMORYREPORTER
|
||||
#include "nsIObserver.h" // nsIObserver, NS_DECL_NSIOBSERVER
|
||||
#include "nsIPrincipal.h" // nsIPrincipal
|
||||
#include "nsISupports.h" // nsISupports, NS_DECL_ISUPPORTS
|
||||
#include "nsStringFwd.h" // nsACString
|
||||
#include "mozilla/dom/SRIMetadata.h" // mozilla::dom::SRIMetadata
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class ScriptLoader;
|
||||
class ScriptLoadData;
|
||||
|
||||
class ScriptHashKey : public PLDHashEntryHdr {
|
||||
public:
|
||||
using KeyType = const ScriptHashKey&;
|
||||
using KeyTypePointer = const ScriptHashKey*;
|
||||
|
||||
explicit ScriptHashKey(const ScriptHashKey& aKey)
|
||||
: mURI(aKey.mURI),
|
||||
mPrincipal(aKey.mPrincipal),
|
||||
mLoaderPrincipal(aKey.mLoaderPrincipal),
|
||||
mPartitionPrincipal(aKey.mPartitionPrincipal),
|
||||
mCORSMode(aKey.mCORSMode),
|
||||
mSRIMetadata(aKey.mSRIMetadata),
|
||||
mKind(aKey.mKind),
|
||||
mNonce(aKey.mNonce),
|
||||
mHintCharset(aKey.mHintCharset),
|
||||
mIsLinkRelPreload(aKey.mIsLinkRelPreload) {
|
||||
MOZ_COUNT_CTOR(ScriptHashKey);
|
||||
}
|
||||
|
||||
explicit ScriptHashKey(const ScriptHashKey* aKey) : ScriptHashKey(*aKey) {}
|
||||
|
||||
ScriptHashKey(ScriptHashKey&& aKey)
|
||||
: mURI(std::move(aKey.mURI)),
|
||||
mPrincipal(std::move(aKey.mPrincipal)),
|
||||
mLoaderPrincipal(std::move(aKey.mLoaderPrincipal)),
|
||||
mPartitionPrincipal(std::move(aKey.mPartitionPrincipal)),
|
||||
mCORSMode(std::move(aKey.mCORSMode)),
|
||||
mSRIMetadata(std::move(aKey.mSRIMetadata)),
|
||||
mKind(std::move(aKey.mKind)),
|
||||
mNonce(std::move(aKey.mNonce)),
|
||||
mHintCharset(std::move(aKey.mHintCharset)),
|
||||
mIsLinkRelPreload(std::move(aKey.mIsLinkRelPreload)) {
|
||||
MOZ_COUNT_CTOR(ScriptHashKey);
|
||||
}
|
||||
|
||||
ScriptHashKey(ScriptLoader* aLoader,
|
||||
const JS::loader::ScriptLoadRequest* aRequest);
|
||||
explicit ScriptHashKey(const ScriptLoadData& aLoadData);
|
||||
|
||||
MOZ_COUNTED_DTOR(ScriptHashKey)
|
||||
|
||||
const ScriptHashKey& GetKey() const { return *this; }
|
||||
const ScriptHashKey* GetKeyPointer() const { return this; }
|
||||
|
||||
bool KeyEquals(const ScriptHashKey* aKey) const { return KeyEquals(*aKey); }
|
||||
|
||||
bool KeyEquals(const ScriptHashKey&) const;
|
||||
|
||||
static const ScriptHashKey* KeyToPointer(const ScriptHashKey& aKey) {
|
||||
return &aKey;
|
||||
}
|
||||
static PLDHashNumber HashKey(const ScriptHashKey* aKey) {
|
||||
return nsURIHashKey::HashKey(aKey->mURI);
|
||||
}
|
||||
|
||||
nsIPrincipal* Principal() const { return mPrincipal; }
|
||||
nsIPrincipal* LoaderPrincipal() const { return mLoaderPrincipal; }
|
||||
nsIPrincipal* PartitionPrincipal() const { return mPartitionPrincipal; }
|
||||
|
||||
enum { ALLOW_MEMMOVE = true };
|
||||
|
||||
protected:
|
||||
const nsCOMPtr<nsIURI> mURI;
|
||||
const nsCOMPtr<nsIPrincipal> mPrincipal;
|
||||
const nsCOMPtr<nsIPrincipal> mLoaderPrincipal;
|
||||
const nsCOMPtr<nsIPrincipal> mPartitionPrincipal;
|
||||
const CORSMode mCORSMode;
|
||||
const SRIMetadata mSRIMetadata;
|
||||
const JS::loader::ScriptKind mKind;
|
||||
const nsString mNonce;
|
||||
|
||||
// charset attribute for classic script.
|
||||
// module always use UTF-8.
|
||||
nsString mHintCharset;
|
||||
|
||||
// TODO: Reflect URL classifier data source.
|
||||
// mozilla::dom::ContentType
|
||||
// maybe implicit
|
||||
// top-level document's host
|
||||
// maybe part of principal?
|
||||
// what if it's inside frame in different host?
|
||||
|
||||
const bool mIsLinkRelPreload;
|
||||
};
|
||||
|
||||
class ScriptLoadData final
|
||||
: public SupportsWeakPtr,
|
||||
public nsISupports,
|
||||
public SharedSubResourceCacheLoadingValueBase<ScriptLoadData> {
|
||||
protected:
|
||||
virtual ~ScriptLoadData() {}
|
||||
|
||||
public:
|
||||
ScriptLoadData(ScriptLoader* mLoader,
|
||||
JS::loader::ScriptLoadRequest* aRequest);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// Only completed loads are used for the cache.
|
||||
bool IsLoading() const override { return false; }
|
||||
bool IsCancelled() const override { return false; }
|
||||
bool IsSyncLoad() const override { return true; }
|
||||
|
||||
void StartLoading() override {}
|
||||
void SetLoadCompleted() override {}
|
||||
void Cancel() override {}
|
||||
|
||||
void DidCancelLoad() {}
|
||||
|
||||
bool ShouldDefer() const { return false; }
|
||||
|
||||
JS::loader::LoadedScript* ValueForCache() const {
|
||||
return mLoadedScript.get();
|
||||
}
|
||||
|
||||
uint32_t ExpirationTime() const { return mExpirationTime; }
|
||||
|
||||
ScriptLoader& Loader() { return *mLoader; }
|
||||
|
||||
const ScriptHashKey& CacheKey() const { return mKey; }
|
||||
|
||||
private:
|
||||
uint32_t mExpirationTime = 0;
|
||||
ScriptLoader* mLoader;
|
||||
ScriptHashKey mKey;
|
||||
RefPtr<JS::loader::LoadedScript> mLoadedScript;
|
||||
};
|
||||
|
||||
struct SharedScriptCacheTraits {
|
||||
using Loader = ScriptLoader;
|
||||
using Key = ScriptHashKey;
|
||||
using Value = JS::loader::LoadedScript;
|
||||
using LoadingValue = ScriptLoadData;
|
||||
|
||||
static ScriptHashKey KeyFromLoadingValue(const LoadingValue& aValue) {
|
||||
return ScriptHashKey(aValue);
|
||||
}
|
||||
};
|
||||
|
||||
class SharedScriptCache final
|
||||
: public SharedSubResourceCache<SharedScriptCacheTraits, SharedScriptCache>,
|
||||
public nsIMemoryReporter,
|
||||
public nsIObserver {
|
||||
public:
|
||||
using Base =
|
||||
SharedSubResourceCache<SharedScriptCacheTraits, SharedScriptCache>;
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIMEMORYREPORTER
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
SharedScriptCache();
|
||||
void Init();
|
||||
|
||||
// This has to be static because it's also called for loaders that don't have
|
||||
// a sheet cache (loaders that are not owned by a document).
|
||||
static void LoadCompleted(SharedScriptCache*, ScriptLoadData&);
|
||||
using Base::LoadCompleted;
|
||||
static void Clear(nsIPrincipal* aForPrincipal = nullptr,
|
||||
const nsACString* aBaseDomain = nullptr);
|
||||
|
||||
protected:
|
||||
~SharedScriptCache();
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_SharedScriptCache_h
|
||||
@@ -24,7 +24,6 @@ EXPORTS.mozilla.dom += [
|
||||
"ScriptSettings.h",
|
||||
"ScriptTrace.h",
|
||||
"ShadowRealmGlobalScope.h",
|
||||
"SharedScriptCache.h",
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
@@ -38,7 +37,6 @@ UNIFIED_SOURCES += [
|
||||
"ScriptLoadHandler.cpp",
|
||||
"ScriptSettings.cpp",
|
||||
"ShadowRealmGlobalScope.cpp",
|
||||
"SharedScriptCache.cpp",
|
||||
]
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
|
||||
@@ -141,18 +141,6 @@ support-files = ["test_mixed_content_image.html"]
|
||||
|
||||
["browser_pointerlock_warning.js"]
|
||||
|
||||
["browser_scriptCache_clear.js"]
|
||||
skip-if = ["!nightly_build"]
|
||||
support-files = [
|
||||
"counter_server.sjs",
|
||||
]
|
||||
|
||||
["browser_scriptCache_redirect.js"]
|
||||
skip-if = ["!nightly_build"]
|
||||
support-files = [
|
||||
"redirect_server.sjs",
|
||||
]
|
||||
|
||||
["browser_sessionStorage_navigation.js"]
|
||||
skip-if = ["os == 'linux' && bits == 64 && !debug"] # Bug 1712961
|
||||
support-files = [
|
||||
|
||||
@@ -1,163 +0,0 @@
|
||||
const TEST_URL = "https://example.com/browser/dom/tests/browser/dummy.html";
|
||||
const SCRIPT_NAME = "counter_server.sjs";
|
||||
const TEST_SCRIPT_URL =
|
||||
"https://example.com/browser/dom/tests/browser/" + SCRIPT_NAME;
|
||||
|
||||
function getCounter(tab) {
|
||||
const browser = tab.linkedBrowser;
|
||||
return SpecialPowers.spawn(browser, [SCRIPT_NAME], async scriptName => {
|
||||
const { promise, resolve } = Promise.withResolvers();
|
||||
|
||||
const script = content.document.createElement("script");
|
||||
script.src = scriptName;
|
||||
script.addEventListener("load", resolve);
|
||||
content.document.body.appendChild(script);
|
||||
|
||||
await promise;
|
||||
|
||||
return parseInt(content.document.body.getAttribute("counter"));
|
||||
});
|
||||
}
|
||||
|
||||
async function reloadAndGetCounter(tab) {
|
||||
await BrowserTestUtils.reloadTab(tab);
|
||||
|
||||
return getCounter(tab);
|
||||
}
|
||||
|
||||
function clearAllCache() {
|
||||
return new Promise(function (resolve) {
|
||||
Services.clearData.deleteData(
|
||||
Ci.nsIClearDataService.CLEAR_ALL_CACHES,
|
||||
resolve
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function clearJSCache() {
|
||||
return new Promise(function (resolve) {
|
||||
Services.clearData.deleteData(
|
||||
Ci.nsIClearDataService.CLEAR_JS_CACHE,
|
||||
resolve
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function clearNetworkCache() {
|
||||
return new Promise(function (resolve) {
|
||||
Services.clearData.deleteData(
|
||||
Ci.nsIClearDataService.CLEAR_NETWORK_CACHE,
|
||||
resolve
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
add_task(async function test_withoutNavigationCache() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["dom.script_loader.navigation_cache", false]],
|
||||
});
|
||||
registerCleanupFunction(() => SpecialPowers.popPrefEnv());
|
||||
|
||||
await clearAllCache();
|
||||
|
||||
const resetResponse = await fetch(TEST_SCRIPT_URL + "?reset");
|
||||
is(await resetResponse.text(), "reset", "Server state should be reset");
|
||||
|
||||
const tab = await BrowserTestUtils.openNewForegroundTab({
|
||||
gBrowser,
|
||||
url: TEST_URL,
|
||||
});
|
||||
|
||||
is(await getCounter(tab), 0, "counter should be 0 for the first load.");
|
||||
|
||||
is(
|
||||
await reloadAndGetCounter(tab),
|
||||
0,
|
||||
"cache should be used for subsequent load."
|
||||
);
|
||||
|
||||
await clearAllCache();
|
||||
is(
|
||||
await reloadAndGetCounter(tab),
|
||||
1,
|
||||
"request should reach the server after removing all cache."
|
||||
);
|
||||
is(
|
||||
await reloadAndGetCounter(tab),
|
||||
1,
|
||||
"cache should be used for subsequent load."
|
||||
);
|
||||
|
||||
await clearJSCache();
|
||||
is(await reloadAndGetCounter(tab), 1, "network cache should be used.");
|
||||
|
||||
await clearNetworkCache();
|
||||
is(
|
||||
await reloadAndGetCounter(tab),
|
||||
2,
|
||||
"request should reach the server after network cache is cleared."
|
||||
);
|
||||
|
||||
await clearJSCache();
|
||||
is(await reloadAndGetCounter(tab), 2, "network cache should be used.");
|
||||
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
||||
add_task(async function test_withNavigationCache() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["dom.script_loader.navigation_cache", true]],
|
||||
});
|
||||
registerCleanupFunction(() => SpecialPowers.popPrefEnv());
|
||||
|
||||
await clearAllCache();
|
||||
|
||||
const resetResponse = await fetch(TEST_SCRIPT_URL + "?reset");
|
||||
is(await resetResponse.text(), "reset", "Server state should be reset");
|
||||
|
||||
const tab = await BrowserTestUtils.openNewForegroundTab({
|
||||
gBrowser,
|
||||
url: TEST_URL,
|
||||
});
|
||||
|
||||
is(await getCounter(tab), 0, "counter should be 0 for the first load.");
|
||||
|
||||
is(
|
||||
await reloadAndGetCounter(tab),
|
||||
0,
|
||||
"cache should be used for subsequent load."
|
||||
);
|
||||
|
||||
await clearAllCache();
|
||||
is(
|
||||
await reloadAndGetCounter(tab),
|
||||
1,
|
||||
"request should reach the server after removing all cache."
|
||||
);
|
||||
is(
|
||||
await reloadAndGetCounter(tab),
|
||||
1,
|
||||
"cache should be used for subsequent load."
|
||||
);
|
||||
|
||||
await clearJSCache();
|
||||
is(await reloadAndGetCounter(tab), 1, "network cache should be used.");
|
||||
|
||||
// The above reload loads from the network cache, and the JS cache is
|
||||
// re-created.
|
||||
|
||||
await clearNetworkCache();
|
||||
is(await reloadAndGetCounter(tab), 1, "JS cache should be used.");
|
||||
|
||||
// The above reload loads from the JS cache.
|
||||
// Currently, network cache is not re-created from the JS cache.
|
||||
|
||||
await clearJSCache();
|
||||
is(
|
||||
await reloadAndGetCounter(tab),
|
||||
2,
|
||||
"request should reach the server after both cache is cleared."
|
||||
);
|
||||
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
@@ -1,111 +0,0 @@
|
||||
const TEST_URL = "https://example.com/browser/dom/tests/browser/dummy.html";
|
||||
const SCRIPT_NAME = "redirect_server.sjs";
|
||||
const TEST_SCRIPT_URL =
|
||||
"https://example.com/browser/dom/tests/browser/" + SCRIPT_NAME;
|
||||
|
||||
function getCounter(tab, query) {
|
||||
const browser = tab.linkedBrowser;
|
||||
const scriptPath = SCRIPT_NAME + query;
|
||||
return SpecialPowers.spawn(browser, [scriptPath], async scriptPath => {
|
||||
const { promise, resolve } = Promise.withResolvers();
|
||||
|
||||
const script = content.document.createElement("script");
|
||||
script.src = scriptPath;
|
||||
script.addEventListener("load", resolve);
|
||||
content.document.body.appendChild(script);
|
||||
|
||||
await promise;
|
||||
|
||||
return parseInt(content.document.body.getAttribute("counter"));
|
||||
});
|
||||
}
|
||||
|
||||
async function reloadAndGetCounter(tab, query) {
|
||||
await BrowserTestUtils.reloadTab(tab);
|
||||
|
||||
return getCounter(tab, query);
|
||||
}
|
||||
|
||||
function clearAllCache() {
|
||||
return new Promise(function (resolve) {
|
||||
Services.clearData.deleteData(
|
||||
Ci.nsIClearDataService.CLEAR_ALL_CACHES,
|
||||
resolve
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
add_task(async function test_redirectCache() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["dom.script_loader.navigation_cache", true]],
|
||||
});
|
||||
registerCleanupFunction(() => SpecialPowers.popPrefEnv());
|
||||
|
||||
const tests = [
|
||||
{
|
||||
query: "?redirect=cacheable&script=cacheable",
|
||||
cachedCounter: true,
|
||||
log: [",redirect=cacheable&script=cacheable", ",script=cacheable"].join(
|
||||
""
|
||||
),
|
||||
},
|
||||
{
|
||||
query: "?redirect=cacheable&script=not-cacheable",
|
||||
cachedCounter: false,
|
||||
log: [
|
||||
",redirect=cacheable&script=not-cacheable",
|
||||
",script=not-cacheable",
|
||||
",script=not-cacheable",
|
||||
].join(""),
|
||||
},
|
||||
{
|
||||
query: "?redirect=not-cacheable&script=cacheable",
|
||||
cachedCounter: true,
|
||||
log: [
|
||||
",redirect=not-cacheable&script=cacheable",
|
||||
",script=cacheable",
|
||||
",redirect=not-cacheable&script=cacheable",
|
||||
].join(""),
|
||||
},
|
||||
{
|
||||
query: "?redirect=not-cacheable&script=not-cacheable",
|
||||
cachedCounter: false,
|
||||
log: [
|
||||
",redirect=not-cacheable&script=not-cacheable",
|
||||
",script=not-cacheable",
|
||||
",redirect=not-cacheable&script=not-cacheable",
|
||||
",script=not-cacheable",
|
||||
].join(""),
|
||||
},
|
||||
];
|
||||
|
||||
for (const { query, cachedCounter, log } of tests) {
|
||||
await clearAllCache();
|
||||
|
||||
const resetResponse = await fetch(TEST_SCRIPT_URL + "?reset");
|
||||
is(await resetResponse.text(), "reset", "Server state should be reset");
|
||||
|
||||
const tab = await BrowserTestUtils.openNewForegroundTab({
|
||||
gBrowser,
|
||||
url: TEST_URL,
|
||||
});
|
||||
|
||||
is(
|
||||
await getCounter(tab, query),
|
||||
0,
|
||||
"counter should be 0 for the first load."
|
||||
);
|
||||
|
||||
const counter = await reloadAndGetCounter(tab, query);
|
||||
if (cachedCounter) {
|
||||
is(counter, 0, "cache should be used for " + query);
|
||||
} else {
|
||||
is(counter, 1, "cache should not be used for " + query);
|
||||
}
|
||||
|
||||
const logResponse = await fetch(TEST_SCRIPT_URL + "?log");
|
||||
is(await logResponse.text(), log, "Log should match");
|
||||
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
}
|
||||
});
|
||||
@@ -1,22 +0,0 @@
|
||||
function handleRequest(request, response) {
|
||||
if (request.queryString == "reset") {
|
||||
setState("counter", "0");
|
||||
|
||||
response.setStatusLine(request.httpVersion, 200, "OK");
|
||||
response.setHeader("Content-Type", "text/text", false);
|
||||
const body = "reset";
|
||||
response.bodyOutputStream.write(body, body.length);
|
||||
return;
|
||||
}
|
||||
|
||||
let counter = parseInt(getState("counter"));
|
||||
setState("counter", (counter + 1).toString());
|
||||
|
||||
response.setStatusLine(request.httpVersion, 200, "OK");
|
||||
response.setHeader("Cache-Control", "max-age=10000", false);
|
||||
response.setHeader("Content-Type", "text/javascript", false);
|
||||
const body = `
|
||||
document.body.setAttribute("counter", "${counter}");
|
||||
`;
|
||||
response.bodyOutputStream.write(body, body.length);
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
function handleRequest(request, response) {
|
||||
if (request.queryString == "reset") {
|
||||
setState("counter", "0");
|
||||
setState("log", "");
|
||||
|
||||
response.setStatusLine(request.httpVersion, 200, "OK");
|
||||
response.setHeader("Content-Type", "text/text", false);
|
||||
const body = "reset";
|
||||
response.bodyOutputStream.write(body, body.length);
|
||||
return;
|
||||
}
|
||||
|
||||
if (request.queryString == "log") {
|
||||
response.setStatusLine(request.httpVersion, 200, "OK");
|
||||
response.setHeader("Content-Type", "text/text", false);
|
||||
const body = getState("log");
|
||||
response.bodyOutputStream.write(body, body.length);
|
||||
return;
|
||||
}
|
||||
|
||||
setState("log", getState("log") + "," + request.queryString);
|
||||
|
||||
const query = {};
|
||||
for (const segment of request.queryString.split("&")) {
|
||||
const [name, value] = segment.split("=");
|
||||
query[name] = value;
|
||||
}
|
||||
|
||||
if ("redirect" in query) {
|
||||
response.setStatusLine(request.httpVersion, 302, "Found");
|
||||
if (query.redirect == "cacheable") {
|
||||
response.setHeader("Cache-Control", "max-age=10000", false);
|
||||
} else {
|
||||
response.setHeader("Cache-Control", "no-cache", false);
|
||||
}
|
||||
response.setHeader(
|
||||
"Location",
|
||||
`redirect_server.sjs?script=${query.script}`,
|
||||
false
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
let counter = parseInt(getState("counter"));
|
||||
setState("counter", (counter + 1).toString());
|
||||
|
||||
response.setStatusLine(request.httpVersion, 200, "OK");
|
||||
if (query.script == "cacheable") {
|
||||
response.setHeader("Cache-Control", "max-age=10000", false);
|
||||
} else {
|
||||
response.setHeader("Cache-Control", "no-cache", false);
|
||||
}
|
||||
response.setHeader("Content-Type", "text/javascript", false);
|
||||
const body = `
|
||||
document.body.setAttribute("counter", "${counter}");
|
||||
`;
|
||||
response.bodyOutputStream.write(body, body.length);
|
||||
}
|
||||
@@ -42,12 +42,6 @@ mozilla::dom::ScriptLoadContext* LoadContextBase::AsWindowContext() {
|
||||
return static_cast<mozilla::dom::ScriptLoadContext*>(this);
|
||||
}
|
||||
|
||||
const mozilla::dom::ScriptLoadContext* LoadContextBase::AsWindowContext()
|
||||
const {
|
||||
MOZ_ASSERT(IsWindowContext());
|
||||
return static_cast<const mozilla::dom::ScriptLoadContext*>(this);
|
||||
}
|
||||
|
||||
mozilla::loader::SyncLoadContext* LoadContextBase::AsSyncContext() {
|
||||
MOZ_ASSERT(IsSyncContext());
|
||||
return static_cast<mozilla::loader::SyncLoadContext*>(this);
|
||||
|
||||
@@ -58,7 +58,6 @@ class LoadContextBase : public nsISupports {
|
||||
// Casting to the different contexts
|
||||
bool IsWindowContext() const { return mKind == ContextKind::Window; }
|
||||
mozilla::dom::ScriptLoadContext* AsWindowContext();
|
||||
const mozilla::dom::ScriptLoadContext* AsWindowContext() const;
|
||||
|
||||
bool IsSyncContext() const { return mKind == ContextKind::Sync; }
|
||||
mozilla::loader::SyncLoadContext* AsSyncContext();
|
||||
|
||||
@@ -105,8 +105,6 @@ size_t LoadedScript::SizeOfIncludingThis(
|
||||
}
|
||||
|
||||
bytes += mScriptBytecode.sizeOfExcludingThis(aMallocSizeOf);
|
||||
|
||||
// NOTE: Stencil is reported by SpiderMonkey.
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,14 +8,11 @@
|
||||
#define js_loader_LoadedScript_h
|
||||
|
||||
#include "js/AllocPolicy.h"
|
||||
#include "js/experimental/JSStencil.h"
|
||||
#include "js/Transcoding.h"
|
||||
|
||||
#include "mozilla/AlreadyAddRefed.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/MaybeOneOf.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/Utf8.h" // mozilla::Utf8Unit
|
||||
#include "mozilla/Variant.h"
|
||||
#include "mozilla/Vector.h"
|
||||
@@ -115,9 +112,8 @@ class LoadedScript : public nsIMemoryReporter {
|
||||
template <typename... Ts>
|
||||
using VariantType = mozilla::VariantType<Ts...>;
|
||||
|
||||
// Type of data this instance holds, which is either provided by the nsChannel
|
||||
// or retrieved from the cache.
|
||||
enum class DataType : uint8_t { eUnknown, eTextSource, eBytecode, eStencil };
|
||||
// Type of data provided by the nsChannel.
|
||||
enum class DataType : uint8_t { eUnknown, eTextSource, eBytecode };
|
||||
|
||||
// Use a vector backed by the JS allocator for script text so that contents
|
||||
// can be transferred in constant time to the JS engine, not copied in linear
|
||||
@@ -132,7 +128,6 @@ class LoadedScript : public nsIMemoryReporter {
|
||||
bool IsTextSource() const { return mDataType == DataType::eTextSource; }
|
||||
bool IsSource() const { return IsTextSource(); }
|
||||
bool IsBytecode() const { return mDataType == DataType::eBytecode; }
|
||||
bool IsStencil() const { return mDataType == DataType::eStencil; }
|
||||
|
||||
void SetUnknownDataType() {
|
||||
mDataType = DataType::eUnknown;
|
||||
@@ -150,12 +145,6 @@ class LoadedScript : public nsIMemoryReporter {
|
||||
mDataType = DataType::eBytecode;
|
||||
}
|
||||
|
||||
void SetStencil(already_AddRefed<JS::Stencil> aStencil) {
|
||||
SetUnknownDataType();
|
||||
mDataType = DataType::eStencil;
|
||||
mStencil = aStencil;
|
||||
}
|
||||
|
||||
bool IsUTF16Text() const {
|
||||
return mScriptData->is<ScriptTextBuffer<char16_t>>();
|
||||
}
|
||||
@@ -203,15 +192,11 @@ class LoadedScript : public nsIMemoryReporter {
|
||||
mReceivedScriptTextLength = aLength;
|
||||
}
|
||||
|
||||
bool CanHaveBytecode() const {
|
||||
return IsBytecode() || IsSource() || IsStencil();
|
||||
}
|
||||
|
||||
JS::TranscodeBuffer& SRIAndBytecode() {
|
||||
// Note: SRIAndBytecode might be called even if the IsSource() returns true,
|
||||
// as we want to be able to save the bytecode content when we are loading
|
||||
// from source.
|
||||
MOZ_ASSERT(CanHaveBytecode());
|
||||
MOZ_ASSERT(IsBytecode() || IsSource());
|
||||
return mScriptBytecode;
|
||||
}
|
||||
JS::TranscodeRange Bytecode() const {
|
||||
@@ -223,27 +208,19 @@ class LoadedScript : public nsIMemoryReporter {
|
||||
}
|
||||
|
||||
size_t GetSRILength() const {
|
||||
MOZ_ASSERT(CanHaveBytecode());
|
||||
MOZ_ASSERT(IsBytecode() || IsSource());
|
||||
return mBytecodeOffset;
|
||||
}
|
||||
void SetSRILength(size_t sriLength) {
|
||||
MOZ_ASSERT(CanHaveBytecode());
|
||||
MOZ_ASSERT(IsBytecode() || IsSource());
|
||||
mBytecodeOffset = JS::AlignTranscodingBytecodeOffset(sriLength);
|
||||
}
|
||||
|
||||
void DropBytecode() {
|
||||
MOZ_ASSERT(CanHaveBytecode());
|
||||
MOZ_ASSERT(IsBytecode() || IsSource());
|
||||
mScriptBytecode.clearAndFree();
|
||||
}
|
||||
|
||||
JS::Stencil* GetStencil() const {
|
||||
MOZ_ASSERT(IsStencil());
|
||||
return mStencil;
|
||||
}
|
||||
|
||||
public:
|
||||
// Fields.
|
||||
|
||||
// Determine whether the mScriptData or mScriptBytecode is used.
|
||||
DataType mDataType;
|
||||
|
||||
@@ -261,8 +238,6 @@ class LoadedScript : public nsIMemoryReporter {
|
||||
// or, if compression is enabled, ScriptBytecodeCompressedDataLayout.
|
||||
JS::TranscodeBuffer mScriptBytecode;
|
||||
uint32_t mBytecodeOffset; // Offset of the bytecode in mScriptBytecode
|
||||
|
||||
RefPtr<JS::Stencil> mStencil;
|
||||
};
|
||||
|
||||
// Provide accessors for any classes `Derived` which is providing the
|
||||
@@ -295,7 +270,6 @@ class LoadedScriptDelegate {
|
||||
bool IsTextSource() const { return GetLoadedScript()->IsTextSource(); }
|
||||
bool IsSource() const { return GetLoadedScript()->IsSource(); }
|
||||
bool IsBytecode() const { return GetLoadedScript()->IsBytecode(); }
|
||||
bool IsStencil() const { return GetLoadedScript()->IsStencil(); }
|
||||
|
||||
void SetUnknownDataType() { GetLoadedScript()->SetUnknownDataType(); }
|
||||
|
||||
@@ -305,10 +279,6 @@ class LoadedScriptDelegate {
|
||||
|
||||
void SetBytecode() { GetLoadedScript()->SetBytecode(); }
|
||||
|
||||
void SetStencil(already_AddRefed<JS::Stencil> aStencil) {
|
||||
GetLoadedScript()->SetStencil(std::move(aStencil));
|
||||
}
|
||||
|
||||
bool IsUTF16Text() const { return GetLoadedScript()->IsUTF16Text(); }
|
||||
bool IsUTF8Text() const { return GetLoadedScript()->IsUTF8Text(); }
|
||||
|
||||
@@ -357,8 +327,6 @@ class LoadedScriptDelegate {
|
||||
}
|
||||
|
||||
void DropBytecode() { GetLoadedScript()->DropBytecode(); }
|
||||
|
||||
JS::Stencil* GetStencil() const { return GetLoadedScript()->GetStencil(); }
|
||||
};
|
||||
|
||||
class ClassicScript final : public LoadedScript {
|
||||
|
||||
@@ -86,21 +86,6 @@ class ScriptFetchOptions {
|
||||
* TODO: Move to ScriptLoadContext
|
||||
*/
|
||||
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
|
||||
|
||||
// Returns true if given fetch option is compatible with this fetch option
|
||||
// in term of sharing the server response.
|
||||
inline bool IsCompatible(ScriptFetchOptions* other) {
|
||||
bool equals;
|
||||
(void)mTriggeringPrincipal->Equals(other->mTriggeringPrincipal, &equals);
|
||||
|
||||
if (!equals) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// NOTE: mParserMetadata can be ignored.
|
||||
return mCORSMode == other->mCORSMode && mNonce == other->mNonce &&
|
||||
mFetchPriority == other->mFetchPriority;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace JS::loader
|
||||
|
||||
@@ -128,12 +128,6 @@ mozilla::dom::ScriptLoadContext* ScriptLoadRequest::GetScriptLoadContext() {
|
||||
return mLoadContext->AsWindowContext();
|
||||
}
|
||||
|
||||
const mozilla::dom::ScriptLoadContext* ScriptLoadRequest::GetScriptLoadContext()
|
||||
const {
|
||||
MOZ_ASSERT(mLoadContext);
|
||||
return mLoadContext->AsWindowContext();
|
||||
}
|
||||
|
||||
mozilla::loader::SyncLoadContext* ScriptLoadRequest::GetSyncLoadContext() {
|
||||
MOZ_ASSERT(mLoadContext);
|
||||
return mLoadContext->AsSyncContext();
|
||||
@@ -159,43 +153,6 @@ const ModuleLoadRequest* ScriptLoadRequest::AsModuleRequest() const {
|
||||
return static_cast<const ModuleLoadRequest*>(this);
|
||||
}
|
||||
|
||||
bool ScriptLoadRequest::IsCacheable() const {
|
||||
if (HasScriptLoadContext() && GetScriptLoadContext()->mIsInline) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mExpirationTime == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t now = nsContentUtils::SecondsFromPRTime(PR_Now());
|
||||
|
||||
return mExpirationTime > now;
|
||||
}
|
||||
|
||||
void ScriptLoadRequest::CacheEntryFound(LoadedScript* aLoadedScript) {
|
||||
MOZ_ASSERT(IsCheckingCache());
|
||||
MOZ_ASSERT(mURI);
|
||||
|
||||
mLoadedScript = aLoadedScript;
|
||||
|
||||
MOZ_ASSERT(mFetchOptions->IsCompatible(mLoadedScript->GetFetchOptions()));
|
||||
|
||||
switch (mKind) {
|
||||
case ScriptKind::eClassic:
|
||||
case ScriptKind::eImportMap:
|
||||
MOZ_ASSERT(mLoadedScript->IsClassicScript());
|
||||
break;
|
||||
case ScriptKind::eModule:
|
||||
MOZ_ASSERT(mLoadedScript->IsModuleScript());
|
||||
break;
|
||||
case ScriptKind::eEvent:
|
||||
MOZ_ASSERT_UNREACHABLE("EventScripts are not using ScriptLoadRequest");
|
||||
break;
|
||||
}
|
||||
mState = State::Ready;
|
||||
}
|
||||
|
||||
void ScriptLoadRequest::NoCacheEntryFound() {
|
||||
MOZ_ASSERT(IsCheckingCache());
|
||||
MOZ_ASSERT(mURI);
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#ifndef js_loader_ScriptLoadRequest_h
|
||||
#define js_loader_ScriptLoadRequest_h
|
||||
|
||||
#include "js/experimental/JSStencil.h"
|
||||
#include "js/RootingAPI.h"
|
||||
#include "js/SourceText.h"
|
||||
#include "js/TypeDecls.h"
|
||||
@@ -112,21 +111,6 @@ class ScriptLoadRequest : public nsISupports,
|
||||
ModuleLoadRequest* AsModuleRequest();
|
||||
const ModuleLoadRequest* AsModuleRequest() const;
|
||||
|
||||
bool IsCacheable() const;
|
||||
|
||||
uint32_t ExpirationTime() const { return mExpirationTime; }
|
||||
|
||||
void SetMinimumExpirationTime(uint32_t aExpirationTime) {
|
||||
// 0 means "doesn't expire".
|
||||
// Otherwise, calculate the minimum value.
|
||||
if (aExpirationTime == 0) {
|
||||
return;
|
||||
}
|
||||
if (mExpirationTime == 0 || aExpirationTime < mExpirationTime) {
|
||||
mExpirationTime = aExpirationTime;
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool IsTopLevel() const { return true; };
|
||||
|
||||
virtual void Cancel();
|
||||
@@ -190,10 +174,6 @@ class ScriptLoadRequest : public nsISupports,
|
||||
return mFetchOptions->mTriggeringPrincipal;
|
||||
}
|
||||
|
||||
// Convert a CheckingCache ScriptLoadRequest into a Ready one, by populating
|
||||
// the script data from cached script.
|
||||
void CacheEntryFound(LoadedScript* aLoadedScript);
|
||||
|
||||
// Convert a CheckingCache ScriptLoadRequest into a Fetching one, by creating
|
||||
// a new LoadedScript which is matching the ScriptKind provided when
|
||||
// constructing this ScriptLoadRequest.
|
||||
@@ -207,8 +187,7 @@ class ScriptLoadRequest : public nsISupports,
|
||||
}
|
||||
|
||||
void MarkSkippedBytecodeEncoding() {
|
||||
MOZ_ASSERT(mBytecodeEncodingPlan == BytecodeEncodingPlan::Uninitialized ||
|
||||
mBytecodeEncodingPlan == BytecodeEncodingPlan::PassedCondition);
|
||||
MOZ_ASSERT(mBytecodeEncodingPlan == BytecodeEncodingPlan::Uninitialized);
|
||||
mBytecodeEncodingPlan = BytecodeEncodingPlan::Skipped;
|
||||
}
|
||||
|
||||
@@ -239,7 +218,6 @@ class ScriptLoadRequest : public nsISupports,
|
||||
bool HasWorkerLoadContext() const;
|
||||
|
||||
mozilla::dom::ScriptLoadContext* GetScriptLoadContext();
|
||||
const mozilla::dom::ScriptLoadContext* GetScriptLoadContext() const;
|
||||
|
||||
mozilla::loader::SyncLoadContext* GetSyncLoadContext();
|
||||
|
||||
@@ -283,9 +261,6 @@ class ScriptLoadRequest : public nsISupports,
|
||||
// The referrer policy used for the initial fetch and for fetching any
|
||||
// imported modules
|
||||
enum mozilla::dom::ReferrerPolicy mReferrerPolicy;
|
||||
|
||||
uint32_t mExpirationTime = 0;
|
||||
|
||||
RefPtr<ScriptFetchOptions> mFetchOptions;
|
||||
const SRIMetadata mIntegrity;
|
||||
const nsCOMPtr<nsIURI> mReferrer;
|
||||
|
||||
@@ -3690,12 +3690,6 @@
|
||||
value: false
|
||||
mirror: always
|
||||
|
||||
# Cache stencil across navigation
|
||||
- name: dom.script_loader.navigation_cache
|
||||
type: bool
|
||||
value: false
|
||||
mirror: always
|
||||
|
||||
- name: dom.securecontext.allowlist_onions
|
||||
type: bool
|
||||
value: false
|
||||
|
||||
@@ -468,37 +468,6 @@ const CSSCacheCleaner = {
|
||||
},
|
||||
};
|
||||
|
||||
const JSCacheCleaner = {
|
||||
async deleteByHost(aHost, aOriginAttributes) {
|
||||
// Delete data from both HTTP and HTTPS sites.
|
||||
let httpURI = Services.io.newURI("http://" + aHost);
|
||||
let httpsURI = Services.io.newURI("https://" + aHost);
|
||||
let httpPrincipal = Services.scriptSecurityManager.createContentPrincipal(
|
||||
httpURI,
|
||||
aOriginAttributes
|
||||
);
|
||||
let httpsPrincipal = Services.scriptSecurityManager.createContentPrincipal(
|
||||
httpsURI,
|
||||
aOriginAttributes
|
||||
);
|
||||
|
||||
ChromeUtils.clearScriptCacheByPrincipal(httpPrincipal);
|
||||
ChromeUtils.clearScriptCacheByPrincipal(httpsPrincipal);
|
||||
},
|
||||
|
||||
async deleteByPrincipal(aPrincipal) {
|
||||
ChromeUtils.clearScriptCacheByPrincipal(aPrincipal);
|
||||
},
|
||||
|
||||
async deleteByBaseDomain(aBaseDomain) {
|
||||
ChromeUtils.clearScriptCacheByBaseDomain(aBaseDomain);
|
||||
},
|
||||
|
||||
async deleteAll() {
|
||||
ChromeUtils.clearScriptCache();
|
||||
},
|
||||
};
|
||||
|
||||
const ImageCacheCleaner = {
|
||||
async deleteByHost(aHost, aOriginAttributes) {
|
||||
let imageCache = Cc["@mozilla.org/image/tools;1"]
|
||||
@@ -1924,11 +1893,6 @@ const FLAGS_MAP = [
|
||||
cleaners: [CSSCacheCleaner],
|
||||
},
|
||||
|
||||
{
|
||||
flag: Ci.nsIClearDataService.CLEAR_JS_CACHE,
|
||||
cleaners: [JSCacheCleaner],
|
||||
},
|
||||
|
||||
{
|
||||
flag: Ci.nsIClearDataService.CLEAR_CLIENT_AUTH_REMEMBER_SERVICE,
|
||||
cleaners: [ClientAuthRememberCleaner],
|
||||
|
||||
@@ -177,11 +177,6 @@ interface nsIClearDataService : nsISupports
|
||||
*/
|
||||
const uint32_t CLEAR_IMAGE_CACHE = 1 << 2;
|
||||
|
||||
/**
|
||||
* In-memory JS cache.
|
||||
*/
|
||||
const uint32_t CLEAR_JS_CACHE = 1 << 3;
|
||||
|
||||
/**
|
||||
* Completed downloads.
|
||||
*/
|
||||
@@ -343,7 +338,7 @@ interface nsIClearDataService : nsISupports
|
||||
* Delete all the possible caches.
|
||||
*/
|
||||
const uint32_t CLEAR_ALL_CACHES = CLEAR_NETWORK_CACHE | CLEAR_IMAGE_CACHE |
|
||||
CLEAR_JS_CACHE | CLEAR_CSS_CACHE | CLEAR_PREFLIGHT_CACHE | CLEAR_HSTS;
|
||||
CLEAR_CSS_CACHE | CLEAR_PREFLIGHT_CACHE | CLEAR_HSTS;
|
||||
|
||||
/**
|
||||
* Delete all DOM storages
|
||||
|
||||
@@ -445,8 +445,7 @@ function clearCacheForExtensionPrincipal(principal, clearAll = false) {
|
||||
const clearDataFlags = clearAll
|
||||
? Ci.nsIClearDataService.CLEAR_ALL_CACHES
|
||||
: Ci.nsIClearDataService.CLEAR_IMAGE_CACHE |
|
||||
Ci.nsIClearDataService.CLEAR_CSS_CACHE |
|
||||
Ci.nsIClearDataService.CLEAR_JS_CACHE;
|
||||
Ci.nsIClearDataService.CLEAR_CSS_CACHE;
|
||||
|
||||
return new Promise(resolve =>
|
||||
Services.clearData.deleteDataFromPrincipal(
|
||||
|
||||
3
tools/@types/lib.gecko.dom.d.ts
vendored
3
tools/@types/lib.gecko.dom.d.ts
vendored
@@ -24056,9 +24056,6 @@ declare namespace ChromeUtils {
|
||||
function clearStyleSheetCache(): void;
|
||||
function clearStyleSheetCacheByBaseDomain(baseDomain: string): void;
|
||||
function clearStyleSheetCacheByPrincipal(principal: Principal): void;
|
||||
function clearScriptCache(): void;
|
||||
function clearScriptCacheByBaseDomain(baseDomain: UTF8String): void;
|
||||
function clearScriptCacheByPrincipal(principal: Principal): void;
|
||||
function collectPerfStats(): Promise<string>;
|
||||
function collectScrollingData(): Promise<InteractionData>;
|
||||
function compileScript(url: string, options?: CompileScriptOptionsDictionary): Promise<PrecompiledScript>;
|
||||
|
||||
1
tools/@types/lib.gecko.xpcom.d.ts
vendored
1
tools/@types/lib.gecko.xpcom.d.ts
vendored
@@ -2701,7 +2701,6 @@ interface nsIDOMWindowUtils extends nsISupports {
|
||||
sendNativeTouchpadDoubleTap(aScreenX: i32, aScreenY: i32, aModifierFlags: i32): void;
|
||||
sendNativeTouchpadPan(aEventPhase: u32, aScreenX: i32, aScreenY: i32, aDeltaX: double, aDeltaY: double, aModifierFlags: i32, aObserver?: nsIObserver): void;
|
||||
clearSharedStyleSheetCache(): void;
|
||||
clearSharedScriptCache(): void;
|
||||
readonly parsedStyleSheets: u32;
|
||||
activateNativeMenuItemAt(indexString: string): void;
|
||||
forceUpdateNativeMenuAt(indexString: string): void;
|
||||
|
||||
Reference in New Issue
Block a user