Re-architecture DOM script loading.
This commit is contained in:
parent
4eebf89b27
commit
68fc602db6
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "ImportManager.h"
|
||||
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
#include "mozilla/EventListenerManager.h"
|
||||
#include "HTMLLinkElement.h"
|
||||
#include "nsContentPolicyUtils.h"
|
||||
|
@ -18,7 +19,6 @@
|
|||
#include "nsIDOMEvent.h"
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsIScriptObjectPrincipal.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -156,7 +156,7 @@ ImportLoader::Updater::UpdateMainReferrer(uint32_t aNewIdx)
|
|||
// Our nearest predecessor has changed. So let's add the ScriptLoader to the
|
||||
// new one if there is any. And remove it from the old one.
|
||||
RefPtr<ImportManager> manager = mLoader->Manager();
|
||||
nsScriptLoader* loader = mLoader->mDocument->ScriptLoader();
|
||||
ScriptLoader* loader = mLoader->mDocument->ScriptLoader();
|
||||
ImportLoader*& pred = mLoader->mBlockingPredecessor;
|
||||
ImportLoader* newPred = manager->GetNearestPredecessor(newMainReferrer);
|
||||
if (pred) {
|
||||
|
@ -339,7 +339,7 @@ ImportLoader::DispatchEventIfFinished(nsINode* aNode)
|
|||
}
|
||||
|
||||
void
|
||||
ImportLoader::AddBlockedScriptLoader(nsScriptLoader* aScriptLoader)
|
||||
ImportLoader::AddBlockedScriptLoader(ScriptLoader* aScriptLoader)
|
||||
{
|
||||
if (mBlockedScriptLoaders.Contains(aScriptLoader)) {
|
||||
return;
|
||||
|
@ -352,7 +352,7 @@ ImportLoader::AddBlockedScriptLoader(nsScriptLoader* aScriptLoader)
|
|||
}
|
||||
|
||||
bool
|
||||
ImportLoader::RemoveBlockedScriptLoader(nsScriptLoader* aScriptLoader)
|
||||
ImportLoader::RemoveBlockedScriptLoader(ScriptLoader* aScriptLoader)
|
||||
{
|
||||
aScriptLoader->RemoveParserBlockingScriptExecutionBlocker();
|
||||
return mBlockedScriptLoaders.RemoveElement(aScriptLoader);
|
||||
|
|
|
@ -45,8 +45,8 @@
|
|||
#include "nsIStreamListener.h"
|
||||
#include "nsIWeakReferenceUtils.h"
|
||||
#include "nsRefPtrHashtable.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "nsURIHashKey.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
|
||||
class nsIDocument;
|
||||
class nsIPrincipal;
|
||||
|
@ -184,8 +184,8 @@ public:
|
|||
// and wait for that to run its scripts. We keep track of all the
|
||||
// ScriptRunners that are waiting for this import. NOTE: updating
|
||||
// the main referrer might change this list.
|
||||
void AddBlockedScriptLoader(nsScriptLoader* aScriptLoader);
|
||||
bool RemoveBlockedScriptLoader(nsScriptLoader* aScriptLoader);
|
||||
void AddBlockedScriptLoader(ScriptLoader* aScriptLoader);
|
||||
bool RemoveBlockedScriptLoader(ScriptLoader* aScriptLoader);
|
||||
void SetBlockingPredecessor(ImportLoader* aLoader);
|
||||
|
||||
private:
|
||||
|
@ -230,7 +230,7 @@ private:
|
|||
|
||||
// List of pending ScriptLoaders that are waiting for this import
|
||||
// to finish.
|
||||
nsTArray<RefPtr<nsScriptLoader>> mBlockedScriptLoaders;
|
||||
nsTArray<RefPtr<ScriptLoader>> mBlockedScriptLoaders;
|
||||
|
||||
// There is always exactly one referrer link that is flagged as
|
||||
// the main referrer the primary link. This is the one that is
|
||||
|
|
|
@ -32,9 +32,9 @@
|
|||
#include "mozilla/Likely.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsNullPrincipal.h"
|
||||
#include "ScriptSettings.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "mozilla/dom/LocationBinding.h"
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
|
|
@ -26,7 +26,6 @@ XPIDL_SOURCES += [
|
|||
'nsIObjectLoadingContent.idl',
|
||||
'nsIRemoteWindowContext.idl',
|
||||
'nsIScriptChannel.idl',
|
||||
'nsIScriptLoaderObserver.idl',
|
||||
'nsISelection.idl',
|
||||
'nsISelectionController.idl',
|
||||
'nsISelectionDisplay.idl',
|
||||
|
@ -96,7 +95,6 @@ EXPORTS += [
|
|||
'nsINode.h',
|
||||
'nsINodeList.h',
|
||||
'nsIScriptContext.h',
|
||||
'nsIScriptElement.h',
|
||||
'nsIScriptGlobalObject.h',
|
||||
'nsIScriptNameSpaceManager.h',
|
||||
'nsIScriptObjectPrincipal.h',
|
||||
|
@ -117,7 +115,6 @@ EXPORTS += [
|
|||
'nsRange.h',
|
||||
'nsReferencedElement.h',
|
||||
'nsSandboxFlags.h',
|
||||
'nsScriptLoader.h',
|
||||
'nsStructuredCloneContainer.h',
|
||||
'nsStubAnimationObserver.h',
|
||||
'nsStubDocumentObserver.h',
|
||||
|
@ -208,7 +205,6 @@ EXPORTS.mozilla.dom += [
|
|||
'ResponsiveImageSelector.h',
|
||||
'SameProcessMessageQueue.h',
|
||||
'ScreenOrientation.h',
|
||||
'ScriptSettings.h',
|
||||
'ShadowRoot.h',
|
||||
'SimpleTreeIterator.h',
|
||||
'StructuredCloneHolder.h',
|
||||
|
@ -329,8 +325,6 @@ SOURCES += [
|
|||
'nsRange.cpp',
|
||||
'nsReferencedElement.cpp',
|
||||
'nsScreen.cpp',
|
||||
'nsScriptElement.cpp',
|
||||
'nsScriptLoader.cpp',
|
||||
'nsScriptNameSpaceManager.cpp',
|
||||
'nsStructuredCloneContainer.cpp',
|
||||
'nsStubAnimationObserver.cpp',
|
||||
|
@ -356,7 +350,6 @@ SOURCES += [
|
|||
'ResponsiveImageSelector.cpp',
|
||||
'SameProcessMessageQueue.cpp',
|
||||
'ScreenOrientation.cpp',
|
||||
'ScriptSettings.cpp',
|
||||
'ShadowRoot.cpp',
|
||||
'StructuredCloneHolder.cpp',
|
||||
'StyleScope.cpp',
|
||||
|
|
|
@ -29,9 +29,8 @@
|
|||
#include "nsIDocument.h"
|
||||
#include "nsIDOMEvent.h"
|
||||
#include "nsWeakPtr.h"
|
||||
#include "ScriptSettings.h"
|
||||
|
||||
using mozilla::Unused; // <snicker>
|
||||
using mozilla::Unused;
|
||||
using namespace mozilla::dom;
|
||||
using namespace mozilla;
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
*/
|
||||
|
||||
#include "nsContentSink.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "mozilla/css/Loader.h"
|
||||
|
@ -49,6 +48,7 @@
|
|||
#include "nsHTMLDNSPrefetch.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
#include "nsParserConstants.h"
|
||||
#include "nsSandboxFlags.h"
|
||||
|
||||
|
|
|
@ -36,13 +36,16 @@ class nsIAtom;
|
|||
class nsIChannel;
|
||||
class nsIContent;
|
||||
class nsNodeInfoManager;
|
||||
class nsScriptLoader;
|
||||
class nsIApplicationCache;
|
||||
|
||||
namespace mozilla {
|
||||
namespace css {
|
||||
class Loader;
|
||||
} // namespace css
|
||||
|
||||
namespace dom {
|
||||
class ScriptLoader;
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#ifdef DEBUG
|
||||
|
@ -273,7 +276,7 @@ protected:
|
|||
nsCOMPtr<nsIDocShell> mDocShell;
|
||||
RefPtr<mozilla::css::Loader> mCSSLoader;
|
||||
RefPtr<nsNodeInfoManager> mNodeInfoManager;
|
||||
RefPtr<nsScriptLoader> mScriptLoader;
|
||||
RefPtr<mozilla::dom::ScriptLoader> mScriptLoader;
|
||||
|
||||
// back off timer notification after count
|
||||
int32_t mBackoffCount;
|
||||
|
|
|
@ -1812,7 +1812,7 @@ nsDocument::Init()
|
|||
mScopeObject = do_GetWeakReference(global);
|
||||
MOZ_ASSERT(mScopeObject);
|
||||
|
||||
mScriptLoader = new nsScriptLoader(this);
|
||||
mScriptLoader = new dom::ScriptLoader(this);
|
||||
|
||||
mozilla::HoldJSObjects(this);
|
||||
|
||||
|
@ -4622,7 +4622,7 @@ nsDocument::GetWindowInternal() const
|
|||
return win;
|
||||
}
|
||||
|
||||
nsScriptLoader*
|
||||
ScriptLoader*
|
||||
nsDocument::ScriptLoader()
|
||||
{
|
||||
return mScriptLoader;
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#include "nsJSThingHashtable.h"
|
||||
#include "nsIScriptObjectPrincipal.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "nsIRadioGroupContainer.h"
|
||||
#include "nsILayoutHistoryState.h"
|
||||
#include "nsIRequest.h"
|
||||
|
@ -60,6 +59,7 @@
|
|||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/PendingAnimationTracker.h"
|
||||
#include "mozilla/dom/DOMImplementation.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
#include "mozilla/dom/StyleSheetList.h"
|
||||
#include "nsDataHashtable.h"
|
||||
#include "mozilla/TimeStamp.h"
|
||||
|
@ -636,7 +636,7 @@ public:
|
|||
/**
|
||||
* Get the script loader for this document
|
||||
*/
|
||||
virtual nsScriptLoader* ScriptLoader() override;
|
||||
virtual mozilla::dom::ScriptLoader* ScriptLoader() override;
|
||||
|
||||
/**
|
||||
* Add/Remove an element to the document's id and name hashes
|
||||
|
@ -1348,7 +1348,7 @@ protected:
|
|||
public:
|
||||
RefPtr<mozilla::EventListenerManager> mListenerManager;
|
||||
RefPtr<nsDOMStyleSheetSetList> mStyleSheetSetList;
|
||||
RefPtr<nsScriptLoader> mScriptLoader;
|
||||
RefPtr<mozilla::dom::ScriptLoader> mScriptLoader;
|
||||
nsDocHeaderData* mHeaderData;
|
||||
/* mIdentifierMap works as follows for IDs:
|
||||
* 1) Attribute changes affect the table immediately (removing and adding
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "nsJSUtils.h"
|
||||
#include "nsJSPrincipals.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "nsFrameLoader.h"
|
||||
#include "nsIXULRuntime.h"
|
||||
#include "nsIScriptError.h"
|
||||
|
@ -38,6 +37,7 @@
|
|||
#include "mozilla/dom/PermissionMessageUtils.h"
|
||||
#include "mozilla/dom/ProcessGlobal.h"
|
||||
#include "mozilla/dom/SameProcessMessageQueue.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
#include "mozilla/dom/ipc/BlobChild.h"
|
||||
#include "mozilla/dom/ipc/BlobParent.h"
|
||||
|
@ -1786,9 +1786,9 @@ nsMessageManagerScriptExecutor::TryCacheLoadAndCompileScript(
|
|||
if (NS_FAILED(NS_ReadInputStreamToString(input, buffer, avail))) {
|
||||
return;
|
||||
}
|
||||
nsScriptLoader::ConvertToUTF16(channel, (uint8_t*)buffer.get(), avail,
|
||||
EmptyString(), nullptr,
|
||||
dataStringBuf, dataStringLength);
|
||||
ScriptLoader::ConvertToUTF16(channel, (uint8_t*)buffer.get(), avail,
|
||||
EmptyString(), nullptr,
|
||||
dataStringBuf, dataStringLength);
|
||||
}
|
||||
|
||||
JS::SourceBufferHolder srcBuf(dataStringBuf, dataStringLength,
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
#include "nsReadableUtils.h"
|
||||
#include "nsDOMClassInfo.h"
|
||||
#include "nsJSEnvironment.h"
|
||||
#include "ScriptSettings.h"
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/Likely.h"
|
||||
#include "mozilla/Sprintf.h"
|
||||
|
|
|
@ -93,7 +93,6 @@ class nsIVariant;
|
|||
class nsViewManager;
|
||||
class nsPresContext;
|
||||
class nsRange;
|
||||
class nsScriptLoader;
|
||||
class nsSMILAnimationController;
|
||||
class nsTextNode;
|
||||
class nsWindowSizes;
|
||||
|
@ -153,6 +152,7 @@ enum class OrientationType : uint32_t;
|
|||
class ProcessingInstruction;
|
||||
class Promise;
|
||||
class Selection;
|
||||
class ScriptLoader;
|
||||
class StyleSheetList;
|
||||
class SVGDocument;
|
||||
class SVGSVGElement;
|
||||
|
@ -1283,7 +1283,7 @@ public:
|
|||
/**
|
||||
* Get the script loader for this document
|
||||
*/
|
||||
virtual nsScriptLoader* ScriptLoader() = 0;
|
||||
virtual mozilla::dom::ScriptLoader* ScriptLoader() = 0;
|
||||
|
||||
/**
|
||||
* Add/Remove an element to the document's id and name hashes
|
||||
|
|
|
@ -11,13 +11,13 @@
|
|||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "nsFrameLoader.h"
|
||||
#include "xpcpublic.h"
|
||||
#include "nsIMozBrowserFrame.h"
|
||||
#include "nsDOMClassInfoID.h"
|
||||
#include "mozilla/EventDispatcher.h"
|
||||
#include "mozilla/dom/SameProcessMessageQueue.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
#include "nsXPCOMCIDInternal.h"
|
||||
#include "nsIXULRuntime.h"
|
||||
#include "nsTextFormatter.h"
|
||||
#include "ScriptSettings.h"
|
||||
|
||||
#include "xpcpublic.h"
|
||||
|
||||
|
@ -55,6 +54,7 @@
|
|||
#include "mozilla/dom/DOMException.h"
|
||||
#include "mozilla/dom/DOMExceptionBinding.h"
|
||||
#include "mozilla/dom/ErrorEvent.h"
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
#include "nsAXPCNativeCallContext.h"
|
||||
#include "mozilla/CycleCollectedJSContext.h"
|
||||
#include "mozilla/Telemetry.h"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "mozilla/Attributes.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsIContentSerializer.h"
|
||||
#include "nsIDocumentEncoder.h"
|
||||
#include "nsILineBreaker.h"
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "mozilla/dom/File.h"
|
||||
#include "mozilla/dom/FunctionBinding.h"
|
||||
#include "mozilla/dom/Performance.h"
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
#include "mozilla/dom/StructuredCloneHolder.h"
|
||||
#include "mozilla/dom/ToJSValue.h"
|
||||
#include "mozilla/dom/WorkletGlobalScope.h"
|
||||
|
@ -22,7 +23,6 @@
|
|||
#include "nsGlobalWindow.h"
|
||||
#include "nsJSUtils.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "ScriptSettings.h"
|
||||
#include "WorkerPrivate.h"
|
||||
#include "WorkerRunnable.h"
|
||||
#include "WorkerScope.h"
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include "nsIDocument.h"
|
||||
#include "mozilla/Sprintf.h"
|
||||
#include "nsGlobalWindow.h"
|
||||
#include "ScriptSettings.h"
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
#include "mozilla/DOMEventTargetHelper.h"
|
||||
#include "mozilla/EventDispatcher.h"
|
||||
#include "mozilla/EventListenerManager.h"
|
||||
|
|
|
@ -37,7 +37,7 @@ HTMLScriptElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
|||
HTMLScriptElement::HTMLScriptElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
|
||||
FromParser aFromParser)
|
||||
: nsGenericHTMLElement(aNodeInfo)
|
||||
, nsScriptElement(aFromParser)
|
||||
, ScriptElement(aFromParser)
|
||||
{
|
||||
AddMutationObserver(this);
|
||||
}
|
||||
|
|
|
@ -8,16 +8,16 @@
|
|||
#define mozilla_dom_HTMLScriptElement_h
|
||||
|
||||
#include "nsIDOMHTMLScriptElement.h"
|
||||
#include "nsScriptElement.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/dom/ScriptElement.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class HTMLScriptElement final : public nsGenericHTMLElement,
|
||||
public nsIDOMHTMLScriptElement,
|
||||
public nsScriptElement
|
||||
public ScriptElement
|
||||
{
|
||||
public:
|
||||
using Element::GetText;
|
||||
|
@ -98,7 +98,8 @@ protected:
|
|||
virtual ~HTMLScriptElement();
|
||||
|
||||
virtual JSObject* WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override;
|
||||
// nsScriptElement
|
||||
|
||||
// ScriptElement
|
||||
virtual bool HasScriptContent() override;
|
||||
};
|
||||
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
#include "nsIDocShell.h"
|
||||
#include "nsNameSpaceManager.h"
|
||||
#include "nsError.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "nsRuleData.h"
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsContainerFrame.h"
|
||||
|
@ -92,6 +91,7 @@
|
|||
#include "mozilla/dom/FromParser.h"
|
||||
#include "mozilla/dom/Link.h"
|
||||
#include "mozilla/BloomFilter.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
|
||||
#include "nsVariant.h"
|
||||
#include "nsDOMTokenList.h"
|
||||
|
|
|
@ -20,10 +20,10 @@
|
|||
#include "nsIHTMLContentSink.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsIContentViewer.h"
|
||||
#include "mozilla/dom/NodeInfo.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
#include "nsToken.h"
|
||||
#include "nsIAppShell.h"
|
||||
#include "nsCRT.h"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "mozilla/dom/MessagePortBinding.h"
|
||||
#include "mozilla/dom/MessagePortChild.h"
|
||||
#include "mozilla/dom/PMessagePort.h"
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
#include "mozilla/dom/StructuredCloneTags.h"
|
||||
#include "mozilla/dom/WorkerPrivate.h"
|
||||
#include "mozilla/dom/WorkerScope.h"
|
||||
|
@ -28,7 +29,6 @@
|
|||
#include "nsContentUtils.h"
|
||||
#include "nsGlobalWindow.h"
|
||||
#include "nsPresContext.h"
|
||||
#include "ScriptSettings.h"
|
||||
#include "SharedMessagePortMessage.h"
|
||||
|
||||
#include "nsIBFCacheEntry.h"
|
||||
|
|
|
@ -100,6 +100,7 @@ DIRS += [
|
|||
'performance',
|
||||
'xhr',
|
||||
'worklet',
|
||||
'script',
|
||||
]
|
||||
|
||||
if CONFIG['OS_ARCH'] == 'WINNT':
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
/* -*- 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 "ModuleLoadRequest.h"
|
||||
#include "ModuleScript.h"
|
||||
#include "ScriptLoader.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ModuleLoadRequest)
|
||||
NS_INTERFACE_MAP_END_INHERITING(ScriptLoadRequest)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED(ModuleLoadRequest, ScriptLoadRequest,
|
||||
mBaseURL,
|
||||
mLoader,
|
||||
mParent,
|
||||
mModuleScript,
|
||||
mImports)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(ModuleLoadRequest, ScriptLoadRequest)
|
||||
NS_IMPL_RELEASE_INHERITED(ModuleLoadRequest, ScriptLoadRequest)
|
||||
|
||||
ModuleLoadRequest::ModuleLoadRequest(nsIScriptElement* aElement,
|
||||
uint32_t aVersion,
|
||||
CORSMode aCORSMode,
|
||||
const SRIMetadata &aIntegrity,
|
||||
ScriptLoader* aLoader)
|
||||
: ScriptLoadRequest(ScriptKind::Module,
|
||||
aElement,
|
||||
aVersion,
|
||||
aCORSMode,
|
||||
aIntegrity),
|
||||
mIsTopLevel(true),
|
||||
mLoader(aLoader)
|
||||
{}
|
||||
|
||||
void ModuleLoadRequest::Cancel()
|
||||
{
|
||||
ScriptLoadRequest::Cancel();
|
||||
mModuleScript = nullptr;
|
||||
mProgress = ScriptLoadRequest::Progress::Ready;
|
||||
for (size_t i = 0; i < mImports.Length(); i++) {
|
||||
mImports[i]->Cancel();
|
||||
}
|
||||
mReady.RejectIfExists(NS_ERROR_FAILURE, __func__);
|
||||
}
|
||||
|
||||
void
|
||||
ModuleLoadRequest::SetReady()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
for (size_t i = 0; i < mImports.Length(); i++) {
|
||||
MOZ_ASSERT(mImports[i]->IsReadyToRun());
|
||||
}
|
||||
#endif
|
||||
|
||||
ScriptLoadRequest::SetReady();
|
||||
mReady.ResolveIfExists(true, __func__);
|
||||
}
|
||||
|
||||
void
|
||||
ModuleLoadRequest::ModuleLoaded()
|
||||
{
|
||||
// A module that was found to be marked as fetching in the module map has now
|
||||
// been loaded.
|
||||
|
||||
mModuleScript = mLoader->GetFetchedModule(mURI);
|
||||
mLoader->StartFetchingModuleDependencies(this);
|
||||
}
|
||||
|
||||
void
|
||||
ModuleLoadRequest::DependenciesLoaded()
|
||||
{
|
||||
// The module and all of its dependencies have been successfully fetched and
|
||||
// compiled.
|
||||
|
||||
if (!mLoader->InstantiateModuleTree(this)) {
|
||||
LoadFailed();
|
||||
return;
|
||||
}
|
||||
|
||||
SetReady();
|
||||
mLoader->ProcessLoadedModuleTree(this);
|
||||
mLoader = nullptr;
|
||||
mParent = nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
ModuleLoadRequest::LoadFailed()
|
||||
{
|
||||
Cancel();
|
||||
mLoader->ProcessLoadedModuleTree(this);
|
||||
mLoader = nullptr;
|
||||
mParent = nullptr;
|
||||
}
|
||||
|
||||
} // dom namespace
|
||||
} // mozilla namespace
|
|
@ -0,0 +1,81 @@
|
|||
/* -*- 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_ModuleLoadRequest_h
|
||||
#define mozilla_dom_ModuleLoadRequest_h
|
||||
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
#include "mozilla/MozPromise.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class ModuleScript;
|
||||
class ScriptLoader;
|
||||
|
||||
// A load request for a module, created for every top level module script and
|
||||
// every module import. Load request can share a ModuleScript if there are
|
||||
// multiple imports of the same module.
|
||||
|
||||
class ModuleLoadRequest final : public ScriptLoadRequest
|
||||
{
|
||||
~ModuleLoadRequest() {}
|
||||
|
||||
ModuleLoadRequest(const ModuleLoadRequest& aOther) = delete;
|
||||
ModuleLoadRequest(ModuleLoadRequest&& aOther) = delete;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ModuleLoadRequest, ScriptLoadRequest)
|
||||
|
||||
ModuleLoadRequest(nsIScriptElement* aElement,
|
||||
uint32_t aVersion,
|
||||
CORSMode aCORSMode,
|
||||
const SRIMetadata& aIntegrity,
|
||||
ScriptLoader* aLoader);
|
||||
|
||||
bool IsTopLevel() const {
|
||||
return mIsTopLevel;
|
||||
}
|
||||
|
||||
void SetReady() override;
|
||||
void Cancel() override;
|
||||
|
||||
void ModuleLoaded();
|
||||
void DependenciesLoaded();
|
||||
void LoadFailed();
|
||||
|
||||
// Is this a request for a top level module script or an import?
|
||||
bool mIsTopLevel;
|
||||
|
||||
// The base URL used for resolving relative module imports.
|
||||
nsCOMPtr<nsIURI> mBaseURL;
|
||||
|
||||
// Pointer to the script loader, used to trigger actions when the module load
|
||||
// finishes.
|
||||
RefPtr<ScriptLoader> mLoader;
|
||||
|
||||
// The importing module, or nullptr for top level module scripts. Used to
|
||||
// implement the ancestor list checked when fetching module dependencies.
|
||||
RefPtr<ModuleLoadRequest> mParent;
|
||||
|
||||
// Set to a module script object after a successful load or nullptr on
|
||||
// failure.
|
||||
RefPtr<ModuleScript> mModuleScript;
|
||||
|
||||
// A promise that is completed on successful load of this module and all of
|
||||
// its dependencies, indicating that the module is ready for instantiation and
|
||||
// evaluation.
|
||||
MozPromiseHolder<GenericPromise> mReady;
|
||||
|
||||
// Array of imported modules.
|
||||
nsTArray<RefPtr<ModuleLoadRequest>> mImports;
|
||||
};
|
||||
|
||||
} // dom namespace
|
||||
} // mozilla namespace
|
||||
|
||||
#endif // mozilla_dom_ModuleLoadRequest_h
|
|
@ -0,0 +1,100 @@
|
|||
/* -*- 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/. */
|
||||
|
||||
/*
|
||||
* A class that handles loading and evaluation of <script> elements.
|
||||
*/
|
||||
|
||||
#include "ModuleScript.h"
|
||||
#include "mozilla/HoldDropJSObjects.h"
|
||||
#include "ScriptLoader.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
// A single module script. May be used to satisfy multiple load requests.
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ModuleScript)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(ModuleScript)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ModuleScript)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mLoader)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mBaseURL)
|
||||
tmp->UnlinkModuleRecord();
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(ModuleScript)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLoader)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(ModuleScript)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mModuleRecord)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mException)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(ModuleScript)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(ModuleScript)
|
||||
|
||||
ModuleScript::ModuleScript(ScriptLoader *aLoader, nsIURI* aBaseURL,
|
||||
JS::Handle<JSObject*> aModuleRecord)
|
||||
: mLoader(aLoader),
|
||||
mBaseURL(aBaseURL),
|
||||
mModuleRecord(aModuleRecord),
|
||||
mInstantiationState(Uninstantiated)
|
||||
{
|
||||
MOZ_ASSERT(mLoader);
|
||||
MOZ_ASSERT(mBaseURL);
|
||||
MOZ_ASSERT(mModuleRecord);
|
||||
MOZ_ASSERT(mException.isUndefined());
|
||||
|
||||
// Make module's host defined field point to this module script object.
|
||||
// This is cleared in the UnlinkModuleRecord().
|
||||
JS::SetModuleHostDefinedField(mModuleRecord, JS::PrivateValue(this));
|
||||
HoldJSObjects(this);
|
||||
}
|
||||
|
||||
void
|
||||
ModuleScript::UnlinkModuleRecord()
|
||||
{
|
||||
// Remove module's back reference to this object request if present.
|
||||
if (mModuleRecord) {
|
||||
MOZ_ASSERT(JS::GetModuleHostDefinedField(mModuleRecord).toPrivate() ==
|
||||
this);
|
||||
JS::SetModuleHostDefinedField(mModuleRecord, JS::UndefinedValue());
|
||||
}
|
||||
mModuleRecord = nullptr;
|
||||
mException.setUndefined();
|
||||
}
|
||||
|
||||
ModuleScript::~ModuleScript()
|
||||
{
|
||||
if (mModuleRecord) {
|
||||
// The object may be destroyed without being unlinked first.
|
||||
UnlinkModuleRecord();
|
||||
}
|
||||
DropJSObjects(this);
|
||||
}
|
||||
|
||||
void
|
||||
ModuleScript::SetInstantiationResult(JS::Handle<JS::Value> aMaybeException)
|
||||
{
|
||||
MOZ_ASSERT(mInstantiationState == Uninstantiated);
|
||||
MOZ_ASSERT(mModuleRecord);
|
||||
MOZ_ASSERT(mException.isUndefined());
|
||||
|
||||
if (aMaybeException.isUndefined()) {
|
||||
mInstantiationState = Instantiated;
|
||||
} else {
|
||||
mModuleRecord = nullptr;
|
||||
mException = aMaybeException;
|
||||
mInstantiationState = Errored;
|
||||
}
|
||||
}
|
||||
|
||||
} // dom namespace
|
||||
} // mozilla namespace
|
|
@ -0,0 +1,67 @@
|
|||
/* -*- 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_ModuleScript_h
|
||||
#define mozilla_dom_ModuleScript_h
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "jsapi.h"
|
||||
|
||||
class nsIURI;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class ScriptLoader;
|
||||
|
||||
class ModuleScript final : public nsISupports
|
||||
{
|
||||
enum InstantiationState {
|
||||
Uninstantiated,
|
||||
Instantiated,
|
||||
Errored
|
||||
};
|
||||
|
||||
RefPtr<ScriptLoader> mLoader;
|
||||
nsCOMPtr<nsIURI> mBaseURL;
|
||||
JS::Heap<JSObject*> mModuleRecord;
|
||||
JS::Heap<JS::Value> mException;
|
||||
InstantiationState mInstantiationState;
|
||||
|
||||
~ModuleScript();
|
||||
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ModuleScript)
|
||||
|
||||
ModuleScript(ScriptLoader* aLoader,
|
||||
nsIURI* aBaseURL,
|
||||
JS::Handle<JSObject*> aModuleRecord);
|
||||
|
||||
ScriptLoader* Loader() const { return mLoader; }
|
||||
JSObject* ModuleRecord() const { return mModuleRecord; }
|
||||
JS::Value Exception() const { return mException; }
|
||||
nsIURI* BaseURL() const { return mBaseURL; }
|
||||
|
||||
void SetInstantiationResult(JS::Handle<JS::Value> aMaybeException);
|
||||
bool IsUninstantiated() const {
|
||||
return mInstantiationState == Uninstantiated;
|
||||
}
|
||||
bool IsInstantiated() const {
|
||||
return mInstantiationState == Instantiated;
|
||||
}
|
||||
bool InstantiationFailed() const {
|
||||
return mInstantiationState == Errored;
|
||||
}
|
||||
|
||||
void UnlinkModuleRecord();
|
||||
};
|
||||
|
||||
} // dom namespace
|
||||
} // mozilla namespace
|
||||
|
||||
#endif // mozilla_dom_ModuleScript_h
|
|
@ -4,13 +4,13 @@
|
|||
* 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 "nsScriptElement.h"
|
||||
#include "ScriptElement.h"
|
||||
#include "ScriptLoader.h"
|
||||
#include "mozilla/BasicEvents.h"
|
||||
#include "mozilla/EventDispatcher.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsPresContext.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "nsIParser.h"
|
||||
#include "nsGkAtoms.h"
|
||||
#include "nsContentSink.h"
|
||||
|
@ -19,11 +19,11 @@ using namespace mozilla;
|
|||
using namespace mozilla::dom;
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScriptElement::ScriptAvailable(nsresult aResult,
|
||||
nsIScriptElement *aElement,
|
||||
bool aIsInline,
|
||||
nsIURI *aURI,
|
||||
int32_t aLineNo)
|
||||
ScriptElement::ScriptAvailable(nsresult aResult,
|
||||
nsIScriptElement *aElement,
|
||||
bool aIsInline,
|
||||
nsIURI *aURI,
|
||||
int32_t aLineNo)
|
||||
{
|
||||
if (!aIsInline && NS_FAILED(aResult)) {
|
||||
nsCOMPtr<nsIParser> parser = do_QueryReferent(mCreatorParser);
|
||||
|
@ -40,7 +40,7 @@ nsScriptElement::ScriptAvailable(nsresult aResult,
|
|||
}
|
||||
|
||||
/* virtual */ nsresult
|
||||
nsScriptElement::FireErrorEvent()
|
||||
ScriptElement::FireErrorEvent()
|
||||
{
|
||||
nsCOMPtr<nsIContent> cont =
|
||||
do_QueryInterface((nsIScriptElement*) this);
|
||||
|
@ -53,9 +53,9 @@ nsScriptElement::FireErrorEvent()
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScriptElement::ScriptEvaluated(nsresult aResult,
|
||||
nsIScriptElement *aElement,
|
||||
bool aIsInline)
|
||||
ScriptElement::ScriptEvaluated(nsresult aResult,
|
||||
nsIScriptElement *aElement,
|
||||
bool aIsInline)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (!aIsInline) {
|
||||
|
@ -78,44 +78,44 @@ nsScriptElement::ScriptEvaluated(nsresult aResult,
|
|||
}
|
||||
|
||||
void
|
||||
nsScriptElement::CharacterDataChanged(nsIDocument *aDocument,
|
||||
nsIContent* aContent,
|
||||
CharacterDataChangeInfo* aInfo)
|
||||
ScriptElement::CharacterDataChanged(nsIDocument *aDocument,
|
||||
nsIContent* aContent,
|
||||
CharacterDataChangeInfo* aInfo)
|
||||
{
|
||||
MaybeProcessScript();
|
||||
}
|
||||
|
||||
void
|
||||
nsScriptElement::AttributeChanged(nsIDocument* aDocument,
|
||||
Element* aElement,
|
||||
int32_t aNameSpaceID,
|
||||
nsIAtom* aAttribute,
|
||||
int32_t aModType,
|
||||
const nsAttrValue* aOldValue)
|
||||
ScriptElement::AttributeChanged(nsIDocument* aDocument,
|
||||
Element* aElement,
|
||||
int32_t aNameSpaceID,
|
||||
nsIAtom* aAttribute,
|
||||
int32_t aModType,
|
||||
const nsAttrValue* aOldValue)
|
||||
{
|
||||
MaybeProcessScript();
|
||||
}
|
||||
|
||||
void
|
||||
nsScriptElement::ContentAppended(nsIDocument* aDocument,
|
||||
nsIContent* aContainer,
|
||||
nsIContent* aFirstNewContent,
|
||||
int32_t aNewIndexInContainer)
|
||||
ScriptElement::ContentAppended(nsIDocument* aDocument,
|
||||
nsIContent* aContainer,
|
||||
nsIContent* aFirstNewContent,
|
||||
int32_t aNewIndexInContainer)
|
||||
{
|
||||
MaybeProcessScript();
|
||||
}
|
||||
|
||||
void
|
||||
nsScriptElement::ContentInserted(nsIDocument *aDocument,
|
||||
nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
int32_t aIndexInContainer)
|
||||
ScriptElement::ContentInserted(nsIDocument *aDocument,
|
||||
nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
int32_t aIndexInContainer)
|
||||
{
|
||||
MaybeProcessScript();
|
||||
}
|
||||
|
||||
bool
|
||||
nsScriptElement::MaybeProcessScript()
|
||||
ScriptElement::MaybeProcessScript()
|
||||
{
|
||||
nsCOMPtr<nsIContent> cont =
|
||||
do_QueryInterface((nsIScriptElement*) this);
|
||||
|
@ -145,6 +145,6 @@ nsScriptElement::MaybeProcessScript()
|
|||
}
|
||||
}
|
||||
|
||||
RefPtr<nsScriptLoader> loader = ownerDoc->ScriptLoader();
|
||||
RefPtr<ScriptLoader> loader = ownerDoc->ScriptLoader();
|
||||
return loader->ProcessScriptElement(this);
|
||||
}
|
|
@ -4,22 +4,25 @@
|
|||
* 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 nsScriptElement_h
|
||||
#define nsScriptElement_h
|
||||
#ifndef mozilla_dom_ScriptElement_h
|
||||
#define mozilla_dom_ScriptElement_h
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "nsIScriptLoaderObserver.h"
|
||||
#include "nsIScriptElement.h"
|
||||
#include "nsStubMutationObserver.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
/**
|
||||
* Baseclass useful for script elements (such as <xhtml:script> and
|
||||
* <svg:script>). Currently the class assumes that only the 'src'
|
||||
* attribute and the children of the class affect what script to execute.
|
||||
*/
|
||||
|
||||
class nsScriptElement : public nsIScriptElement,
|
||||
public nsStubMutationObserver
|
||||
class ScriptElement : public nsIScriptElement,
|
||||
public nsStubMutationObserver
|
||||
{
|
||||
public:
|
||||
// nsIScriptLoaderObserver
|
||||
|
@ -31,7 +34,7 @@ public:
|
|||
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
||||
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
||||
|
||||
explicit nsScriptElement(mozilla::dom::FromParser aFromParser)
|
||||
explicit ScriptElement(FromParser aFromParser)
|
||||
: nsIScriptElement(aFromParser)
|
||||
{
|
||||
}
|
||||
|
@ -49,4 +52,7 @@ protected:
|
|||
virtual bool MaybeProcessScript() override;
|
||||
};
|
||||
|
||||
#endif // nsScriptElement_h
|
||||
} // dom namespace
|
||||
} // mozilla namespace
|
||||
|
||||
#endif // mozilla_dom_ScriptElement_h
|
|
@ -0,0 +1,216 @@
|
|||
/* -*- 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/. */
|
||||
|
||||
/*
|
||||
* A class that handles loading and evaluation of <script> elements.
|
||||
*/
|
||||
|
||||
#include "ScriptLoadHandler.h"
|
||||
#include "ScriptLoader.h"
|
||||
#include "nsContentUtils.h"
|
||||
|
||||
#include "mozilla/dom/EncodingUtils.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
ScriptLoadHandler::ScriptLoadHandler(ScriptLoader *aScriptLoader,
|
||||
ScriptLoadRequest *aRequest,
|
||||
mozilla::dom::SRICheckDataVerifier *aSRIDataVerifier)
|
||||
: mScriptLoader(aScriptLoader),
|
||||
mRequest(aRequest),
|
||||
mSRIDataVerifier(aSRIDataVerifier),
|
||||
mSRIStatus(NS_OK),
|
||||
mDecoder(),
|
||||
mBuffer()
|
||||
{}
|
||||
|
||||
ScriptLoadHandler::~ScriptLoadHandler()
|
||||
{}
|
||||
|
||||
NS_IMPL_ISUPPORTS(ScriptLoadHandler, nsIIncrementalStreamLoaderObserver)
|
||||
|
||||
NS_IMETHODIMP
|
||||
ScriptLoadHandler::OnIncrementalData(nsIIncrementalStreamLoader* aLoader,
|
||||
nsISupports* aContext,
|
||||
uint32_t aDataLength,
|
||||
const uint8_t* aData,
|
||||
uint32_t *aConsumedLength)
|
||||
{
|
||||
if (mRequest->IsCanceled()) {
|
||||
// If request cancelled, ignore any incoming data.
|
||||
*aConsumedLength = aDataLength;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!EnsureDecoder(aLoader, aData, aDataLength,
|
||||
/* aEndOfStream = */ false)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Below we will/shall consume entire data chunk.
|
||||
*aConsumedLength = aDataLength;
|
||||
|
||||
// Decoder has already been initialized. -- trying to decode all loaded bytes.
|
||||
nsresult rv = TryDecodeRawData(aData, aDataLength,
|
||||
/* aEndOfStream = */ false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// If SRI is required for this load, appending new bytes to the hash.
|
||||
if (mSRIDataVerifier && NS_SUCCEEDED(mSRIStatus)) {
|
||||
mSRIStatus = mSRIDataVerifier->Update(aDataLength, aData);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
ScriptLoadHandler::TryDecodeRawData(const uint8_t* aData,
|
||||
uint32_t aDataLength,
|
||||
bool aEndOfStream)
|
||||
{
|
||||
int32_t srcLen = aDataLength;
|
||||
const char* src = reinterpret_cast<const char *>(aData);
|
||||
int32_t dstLen;
|
||||
nsresult rv =
|
||||
mDecoder->GetMaxLength(src, srcLen, &dstLen);
|
||||
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
uint32_t haveRead = mBuffer.length();
|
||||
|
||||
CheckedInt<uint32_t> capacity = haveRead;
|
||||
capacity += dstLen;
|
||||
|
||||
if (!capacity.isValid() || !mBuffer.reserve(capacity.value())) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
rv = mDecoder->Convert(src,
|
||||
&srcLen,
|
||||
mBuffer.begin() + haveRead,
|
||||
&dstLen);
|
||||
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
haveRead += dstLen;
|
||||
MOZ_ASSERT(haveRead <= capacity.value(), "mDecoder produced more data than expected");
|
||||
MOZ_ALWAYS_TRUE(mBuffer.resizeUninitialized(haveRead));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool
|
||||
ScriptLoadHandler::EnsureDecoder(nsIIncrementalStreamLoader *aLoader,
|
||||
const uint8_t* aData,
|
||||
uint32_t aDataLength,
|
||||
bool aEndOfStream)
|
||||
{
|
||||
// Check if decoder has already been created.
|
||||
if (mDecoder) {
|
||||
return true;
|
||||
}
|
||||
|
||||
nsAutoCString charset;
|
||||
|
||||
// JavaScript modules are always UTF-8.
|
||||
if (mRequest->IsModuleRequest()) {
|
||||
charset = "UTF-8";
|
||||
mDecoder = EncodingUtils::DecoderForEncoding(charset);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Determine if BOM check should be done. This occurs either
|
||||
// if end-of-stream has been reached, or at least 3 bytes have
|
||||
// been read from input.
|
||||
if (!aEndOfStream && (aDataLength < 3)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Do BOM detection.
|
||||
if (nsContentUtils::CheckForBOM(aData, aDataLength, charset)) {
|
||||
mDecoder = EncodingUtils::DecoderForEncoding(charset);
|
||||
return true;
|
||||
}
|
||||
|
||||
// BOM detection failed, check content stream for charset.
|
||||
nsCOMPtr<nsIRequest> req;
|
||||
nsresult rv = aLoader->GetRequest(getter_AddRefs(req));
|
||||
NS_ASSERTION(req, "StreamLoader's request went away prematurely");
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
|
||||
nsCOMPtr<nsIChannel> channel = do_QueryInterface(req);
|
||||
|
||||
if (channel &&
|
||||
NS_SUCCEEDED(channel->GetContentCharset(charset)) &&
|
||||
EncodingUtils::FindEncodingForLabel(charset, charset)) {
|
||||
mDecoder = EncodingUtils::DecoderForEncoding(charset);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check the hint charset from the script element or preload
|
||||
// request.
|
||||
nsAutoString hintCharset;
|
||||
if (!mRequest->IsPreload()) {
|
||||
mRequest->mElement->GetScriptCharset(hintCharset);
|
||||
} else {
|
||||
nsTArray<ScriptLoader::PreloadInfo>::index_type i =
|
||||
mScriptLoader->mPreloads.IndexOf(mRequest, 0,
|
||||
ScriptLoader::PreloadRequestComparator());
|
||||
|
||||
NS_ASSERTION(i != mScriptLoader->mPreloads.NoIndex,
|
||||
"Incorrect preload bookkeeping");
|
||||
hintCharset = mScriptLoader->mPreloads[i].mCharset;
|
||||
}
|
||||
|
||||
if (EncodingUtils::FindEncodingForLabel(hintCharset, charset)) {
|
||||
mDecoder = EncodingUtils::DecoderForEncoding(charset);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the charset from the charset of the document.
|
||||
if (mScriptLoader->mDocument) {
|
||||
charset = mScriptLoader->mDocument->GetDocumentCharacterSet();
|
||||
mDecoder = EncodingUtils::DecoderForEncoding(charset);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Curiously, there are various callers that don't pass aDocument. The
|
||||
// fallback in the old code was ISO-8859-1, which behaved like
|
||||
// windows-1252. Saying windows-1252 for clarity and for compliance
|
||||
// with the Encoding Standard.
|
||||
charset = "windows-1252";
|
||||
mDecoder = EncodingUtils::DecoderForEncoding(charset);
|
||||
return true;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ScriptLoadHandler::OnStreamComplete(nsIIncrementalStreamLoader* aLoader,
|
||||
nsISupports* aContext,
|
||||
nsresult aStatus,
|
||||
uint32_t aDataLength,
|
||||
const uint8_t* aData)
|
||||
{
|
||||
if (!mRequest->IsCanceled()) {
|
||||
DebugOnly<bool> encoderSet =
|
||||
EnsureDecoder(aLoader, aData, aDataLength, /* aEndOfStream = */ true);
|
||||
MOZ_ASSERT(encoderSet);
|
||||
DebugOnly<nsresult> rv = TryDecodeRawData(aData, aDataLength,
|
||||
/* aEndOfStream = */ true);
|
||||
|
||||
// If SRI is required for this load, appending new bytes to the hash.
|
||||
if (mSRIDataVerifier && NS_SUCCEEDED(mSRIStatus)) {
|
||||
mSRIStatus = mSRIDataVerifier->Update(aDataLength, aData);
|
||||
}
|
||||
}
|
||||
|
||||
// we have to mediate and use mRequest.
|
||||
return mScriptLoader->OnStreamComplete(aLoader, mRequest, aStatus, mSRIStatus,
|
||||
mBuffer, mSRIDataVerifier);
|
||||
}
|
||||
|
||||
} // dom namespace
|
||||
} // mozilla namespace
|
|
@ -0,0 +1,76 @@
|
|||
/* -*- 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/. */
|
||||
|
||||
/*
|
||||
* A class that handles loading and evaluation of <script> elements.
|
||||
*/
|
||||
|
||||
#ifndef mozilla_dom_ScriptLoadHandler_h
|
||||
#define mozilla_dom_ScriptLoadHandler_h
|
||||
|
||||
#include "nsIIncrementalStreamLoader.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "mozilla/Vector.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class ScriptLoadRequest;
|
||||
class ScriptLoader;
|
||||
class SRICheckDataVerifier;
|
||||
|
||||
class ScriptLoadHandler final : public nsIIncrementalStreamLoaderObserver
|
||||
{
|
||||
public:
|
||||
explicit ScriptLoadHandler(ScriptLoader* aScriptLoader,
|
||||
ScriptLoadRequest* aRequest,
|
||||
SRICheckDataVerifier* aSRIDataVerifier);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIINCREMENTALSTREAMLOADEROBSERVER
|
||||
|
||||
private:
|
||||
virtual ~ScriptLoadHandler();
|
||||
|
||||
/*
|
||||
* Try to decode some raw data.
|
||||
*/
|
||||
nsresult TryDecodeRawData(const uint8_t* aData, uint32_t aDataLength,
|
||||
bool aEndOfStream);
|
||||
|
||||
/*
|
||||
* Discover the charset by looking at the stream data, the script
|
||||
* tag, and other indicators. Returns true if charset has been
|
||||
* discovered.
|
||||
*/
|
||||
bool EnsureDecoder(nsIIncrementalStreamLoader *aLoader,
|
||||
const uint8_t* aData, uint32_t aDataLength,
|
||||
bool aEndOfStream);
|
||||
|
||||
// ScriptLoader which will handle the parsed script.
|
||||
RefPtr<ScriptLoader> mScriptLoader;
|
||||
|
||||
// The ScriptLoadRequest for this load.
|
||||
RefPtr<ScriptLoadRequest> mRequest;
|
||||
|
||||
// SRI data verifier.
|
||||
nsAutoPtr<SRICheckDataVerifier> mSRIDataVerifier;
|
||||
|
||||
// Status of SRI data operations.
|
||||
nsresult mSRIStatus;
|
||||
|
||||
// Unicode decoder for charset.
|
||||
nsCOMPtr<nsIUnicodeDecoder> mDecoder;
|
||||
|
||||
// Accumulated decoded char buffer.
|
||||
mozilla::Vector<char16_t> mBuffer;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif //mozilla_dom_ScriptLoader_h
|
File diff suppressed because it is too large
Load Diff
|
@ -4,12 +4,8 @@
|
|||
* 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/. */
|
||||
|
||||
/*
|
||||
* A class that handles loading and evaluation of <script> elements.
|
||||
*/
|
||||
|
||||
#ifndef __nsScriptLoader_h__
|
||||
#define __nsScriptLoader_h__
|
||||
#ifndef mozilla_dom_ScriptLoader_h
|
||||
#define mozilla_dom_ScriptLoader_h
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsRefPtrHashtable.h"
|
||||
|
@ -25,14 +21,10 @@
|
|||
#include "mozilla/CORSMode.h"
|
||||
#include "mozilla/dom/SRIMetadata.h"
|
||||
#include "mozilla/dom/SRICheck.h"
|
||||
#include "mozilla/LinkedList.h"
|
||||
#include "mozilla/MozPromise.h"
|
||||
#include "mozilla/net/ReferrerPolicy.h"
|
||||
#include "mozilla/Vector.h"
|
||||
|
||||
class nsModuleLoadRequest;
|
||||
class nsModuleScript;
|
||||
class nsScriptLoadRequestList;
|
||||
class nsIURI;
|
||||
|
||||
namespace JS {
|
||||
|
@ -41,37 +33,39 @@ namespace JS {
|
|||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class AutoJSAPI;
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
class ModuleLoadRequest;
|
||||
class ModuleScript;
|
||||
class ScriptLoadRequestList;
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// Per-request data structure
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
enum class nsScriptKind {
|
||||
enum class ScriptKind {
|
||||
Classic,
|
||||
Module
|
||||
};
|
||||
|
||||
class nsScriptLoadRequest : public nsISupports,
|
||||
private mozilla::LinkedListElement<nsScriptLoadRequest>
|
||||
class ScriptLoadRequest : public nsISupports,
|
||||
private mozilla::LinkedListElement<ScriptLoadRequest>
|
||||
{
|
||||
typedef LinkedListElement<nsScriptLoadRequest> super;
|
||||
typedef LinkedListElement<ScriptLoadRequest> super;
|
||||
|
||||
// Allow LinkedListElement<nsScriptLoadRequest> to cast us to itself as needed.
|
||||
friend class mozilla::LinkedListElement<nsScriptLoadRequest>;
|
||||
friend class nsScriptLoadRequestList;
|
||||
// Allow LinkedListElement<ScriptLoadRequest> to cast us to itself as needed.
|
||||
friend class mozilla::LinkedListElement<ScriptLoadRequest>;
|
||||
friend class ScriptLoadRequestList;
|
||||
|
||||
protected:
|
||||
virtual ~nsScriptLoadRequest();
|
||||
virtual ~ScriptLoadRequest();
|
||||
|
||||
public:
|
||||
nsScriptLoadRequest(nsScriptKind aKind,
|
||||
nsIScriptElement* aElement,
|
||||
uint32_t aVersion,
|
||||
mozilla::CORSMode aCORSMode,
|
||||
const mozilla::dom::SRIMetadata &aIntegrity)
|
||||
ScriptLoadRequest(ScriptKind aKind,
|
||||
nsIScriptElement* aElement,
|
||||
uint32_t aVersion,
|
||||
mozilla::CORSMode aCORSMode,
|
||||
const mozilla::dom::SRIMetadata &aIntegrity)
|
||||
: mKind(aKind),
|
||||
mElement(aElement),
|
||||
mProgress(Progress::Loading),
|
||||
|
@ -95,14 +89,14 @@ public:
|
|||
}
|
||||
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS(nsScriptLoadRequest)
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS(ScriptLoadRequest)
|
||||
|
||||
bool IsModuleRequest() const
|
||||
{
|
||||
return mKind == nsScriptKind::Module;
|
||||
return mKind == ScriptKind::Module;
|
||||
}
|
||||
|
||||
nsModuleLoadRequest* AsModuleRequest();
|
||||
ModuleLoadRequest* AsModuleRequest();
|
||||
|
||||
void FireScriptAvailable(nsresult aResult)
|
||||
{
|
||||
|
@ -154,7 +148,7 @@ public:
|
|||
using super::getNext;
|
||||
using super::isInList;
|
||||
|
||||
const nsScriptKind mKind;
|
||||
const ScriptKind mKind;
|
||||
nsCOMPtr<nsIScriptElement> mElement;
|
||||
Progress mProgress; // Are we still waiting for a load to complete?
|
||||
bool mIsInline; // Is the script inline or loaded?
|
||||
|
@ -179,23 +173,23 @@ public:
|
|||
mozilla::net::ReferrerPolicy mReferrerPolicy;
|
||||
};
|
||||
|
||||
class nsScriptLoadRequestList : private mozilla::LinkedList<nsScriptLoadRequest>
|
||||
class ScriptLoadRequestList : private mozilla::LinkedList<ScriptLoadRequest>
|
||||
{
|
||||
typedef mozilla::LinkedList<nsScriptLoadRequest> super;
|
||||
typedef mozilla::LinkedList<ScriptLoadRequest> super;
|
||||
|
||||
public:
|
||||
~nsScriptLoadRequestList();
|
||||
~ScriptLoadRequestList();
|
||||
|
||||
void Clear();
|
||||
|
||||
#ifdef DEBUG
|
||||
bool Contains(nsScriptLoadRequest* aElem) const;
|
||||
bool Contains(ScriptLoadRequest* aElem) const;
|
||||
#endif // DEBUG
|
||||
|
||||
using super::getFirst;
|
||||
using super::isEmpty;
|
||||
|
||||
void AppendElement(nsScriptLoadRequest* aElem)
|
||||
void AppendElement(ScriptLoadRequest* aElem)
|
||||
{
|
||||
MOZ_ASSERT(!aElem->isInList());
|
||||
NS_ADDREF(aElem);
|
||||
|
@ -203,36 +197,37 @@ public:
|
|||
}
|
||||
|
||||
MOZ_MUST_USE
|
||||
already_AddRefed<nsScriptLoadRequest> Steal(nsScriptLoadRequest* aElem)
|
||||
already_AddRefed<ScriptLoadRequest> Steal(ScriptLoadRequest* aElem)
|
||||
{
|
||||
aElem->removeFrom(*this);
|
||||
return dont_AddRef(aElem);
|
||||
}
|
||||
|
||||
MOZ_MUST_USE
|
||||
already_AddRefed<nsScriptLoadRequest> StealFirst()
|
||||
already_AddRefed<ScriptLoadRequest> StealFirst()
|
||||
{
|
||||
MOZ_ASSERT(!isEmpty());
|
||||
return Steal(getFirst());
|
||||
}
|
||||
|
||||
void Remove(nsScriptLoadRequest* aElem)
|
||||
void Remove(ScriptLoadRequest* aElem)
|
||||
{
|
||||
aElem->removeFrom(*this);
|
||||
NS_RELEASE(aElem);
|
||||
}
|
||||
};
|
||||
class ScriptLoadHandler;
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// Script loader implementation
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
class nsScriptLoader final : public nsISupports
|
||||
class ScriptLoader final : public nsISupports
|
||||
{
|
||||
class MOZ_STACK_CLASS AutoCurrentScriptUpdater
|
||||
{
|
||||
public:
|
||||
AutoCurrentScriptUpdater(nsScriptLoader* aScriptLoader,
|
||||
AutoCurrentScriptUpdater(ScriptLoader* aScriptLoader,
|
||||
nsIScriptElement* aCurrentScript)
|
||||
: mOldScript(aScriptLoader->mCurrentScript)
|
||||
, mScriptLoader(aScriptLoader)
|
||||
|
@ -245,19 +240,19 @@ class nsScriptLoader final : public nsISupports
|
|||
}
|
||||
private:
|
||||
nsCOMPtr<nsIScriptElement> mOldScript;
|
||||
nsScriptLoader* mScriptLoader;
|
||||
ScriptLoader* mScriptLoader;
|
||||
};
|
||||
|
||||
friend class nsModuleLoadRequest;
|
||||
friend class nsScriptRequestProcessor;
|
||||
friend class nsScriptLoadHandler;
|
||||
friend class ModuleLoadRequest;
|
||||
friend class ScriptRequestProcessor;
|
||||
friend class ScriptLoadHandler;
|
||||
friend class AutoCurrentScriptUpdater;
|
||||
|
||||
public:
|
||||
explicit nsScriptLoader(nsIDocument* aDocument);
|
||||
explicit ScriptLoader(nsIDocument* aDocument);
|
||||
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS(nsScriptLoader)
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS(ScriptLoader)
|
||||
|
||||
/**
|
||||
* The loader maintains a weak reference to the document with
|
||||
|
@ -395,7 +390,7 @@ public:
|
|||
|
||||
/**
|
||||
* Handle the completion of a stream. This is called by the
|
||||
* nsScriptLoadHandler object which observes the IncrementalStreamLoader
|
||||
* ScriptLoadHandler object which observes the IncrementalStreamLoader
|
||||
* loading the script.
|
||||
*/
|
||||
nsresult OnStreamComplete(nsIIncrementalStreamLoader* aLoader,
|
||||
|
@ -463,17 +458,17 @@ public:
|
|||
* Process a request that was deferred so that the script could be compiled
|
||||
* off thread.
|
||||
*/
|
||||
nsresult ProcessOffThreadRequest(nsScriptLoadRequest *aRequest);
|
||||
nsresult ProcessOffThreadRequest(ScriptLoadRequest *aRequest);
|
||||
|
||||
bool AddPendingChildLoader(nsScriptLoader* aChild) {
|
||||
bool AddPendingChildLoader(ScriptLoader* aChild) {
|
||||
return mPendingChildLoaders.AppendElement(aChild) != nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
virtual ~nsScriptLoader();
|
||||
virtual ~ScriptLoader();
|
||||
|
||||
nsScriptLoadRequest* CreateLoadRequest(
|
||||
nsScriptKind aKind,
|
||||
ScriptLoadRequest* CreateLoadRequest(
|
||||
ScriptKind aKind,
|
||||
nsIScriptElement* aElement,
|
||||
uint32_t aVersion,
|
||||
mozilla::CORSMode aCORSMode,
|
||||
|
@ -482,12 +477,12 @@ private:
|
|||
/**
|
||||
* Unblocks the creator parser of the parser-blocking scripts.
|
||||
*/
|
||||
void UnblockParser(nsScriptLoadRequest* aParserBlockingRequest);
|
||||
void UnblockParser(ScriptLoadRequest* aParserBlockingRequest);
|
||||
|
||||
/**
|
||||
* Asynchronously resumes the creator parser of the parser-blocking scripts.
|
||||
*/
|
||||
void ContinueParserAsync(nsScriptLoadRequest* aParserBlockingRequest);
|
||||
void ContinueParserAsync(ScriptLoadRequest* aParserBlockingRequest);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -502,7 +497,7 @@ private:
|
|||
/**
|
||||
* Start a load for aRequest's URI.
|
||||
*/
|
||||
nsresult StartLoad(nsScriptLoadRequest *aRequest, const nsAString &aType,
|
||||
nsresult StartLoad(ScriptLoadRequest *aRequest, const nsAString &aType,
|
||||
bool aScriptFromHead);
|
||||
|
||||
/**
|
||||
|
@ -539,83 +534,83 @@ private:
|
|||
return mEnabled && !mBlockerCount;
|
||||
}
|
||||
|
||||
nsresult AttemptAsyncScriptCompile(nsScriptLoadRequest* aRequest);
|
||||
nsresult ProcessRequest(nsScriptLoadRequest* aRequest);
|
||||
nsresult CompileOffThreadOrProcessRequest(nsScriptLoadRequest* aRequest);
|
||||
nsresult AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest);
|
||||
nsresult ProcessRequest(ScriptLoadRequest* aRequest);
|
||||
nsresult CompileOffThreadOrProcessRequest(ScriptLoadRequest* aRequest);
|
||||
void FireScriptAvailable(nsresult aResult,
|
||||
nsScriptLoadRequest* aRequest);
|
||||
ScriptLoadRequest* aRequest);
|
||||
void FireScriptEvaluated(nsresult aResult,
|
||||
nsScriptLoadRequest* aRequest);
|
||||
nsresult EvaluateScript(nsScriptLoadRequest* aRequest);
|
||||
ScriptLoadRequest* aRequest);
|
||||
nsresult EvaluateScript(ScriptLoadRequest* aRequest);
|
||||
|
||||
already_AddRefed<nsIScriptGlobalObject> GetScriptGlobalObject();
|
||||
nsresult FillCompileOptionsForRequest(const mozilla::dom::AutoJSAPI& jsapi,
|
||||
nsScriptLoadRequest* aRequest,
|
||||
ScriptLoadRequest* aRequest,
|
||||
JS::Handle<JSObject*> aScopeChain,
|
||||
JS::CompileOptions* aOptions);
|
||||
|
||||
uint32_t NumberOfProcessors();
|
||||
nsresult PrepareLoadedRequest(nsScriptLoadRequest* aRequest,
|
||||
nsresult PrepareLoadedRequest(ScriptLoadRequest* aRequest,
|
||||
nsIIncrementalStreamLoader* aLoader,
|
||||
nsresult aStatus,
|
||||
mozilla::Vector<char16_t> &aString);
|
||||
|
||||
void AddDeferRequest(nsScriptLoadRequest* aRequest);
|
||||
void AddDeferRequest(ScriptLoadRequest* aRequest);
|
||||
bool MaybeRemovedDeferRequests();
|
||||
|
||||
void MaybeMoveToLoadedList(nsScriptLoadRequest* aRequest);
|
||||
void MaybeMoveToLoadedList(ScriptLoadRequest* aRequest);
|
||||
|
||||
JS::SourceBufferHolder GetScriptSource(nsScriptLoadRequest* aRequest,
|
||||
JS::SourceBufferHolder GetScriptSource(ScriptLoadRequest* aRequest,
|
||||
nsAutoString& inlineData);
|
||||
|
||||
bool ModuleScriptsEnabled();
|
||||
|
||||
void SetModuleFetchStarted(nsModuleLoadRequest *aRequest);
|
||||
void SetModuleFetchFinishedAndResumeWaitingRequests(nsModuleLoadRequest *aRequest,
|
||||
void SetModuleFetchStarted(ModuleLoadRequest *aRequest);
|
||||
void SetModuleFetchFinishedAndResumeWaitingRequests(ModuleLoadRequest *aRequest,
|
||||
nsresult aResult);
|
||||
|
||||
bool IsFetchingModule(nsModuleLoadRequest *aRequest) const;
|
||||
bool IsFetchingModule(ModuleLoadRequest *aRequest) const;
|
||||
|
||||
bool ModuleMapContainsModule(nsModuleLoadRequest *aRequest) const;
|
||||
RefPtr<mozilla::GenericPromise> WaitForModuleFetch(nsModuleLoadRequest *aRequest);
|
||||
nsModuleScript* GetFetchedModule(nsIURI* aURL) const;
|
||||
bool ModuleMapContainsModule(ModuleLoadRequest *aRequest) const;
|
||||
RefPtr<mozilla::GenericPromise> WaitForModuleFetch(ModuleLoadRequest *aRequest);
|
||||
ModuleScript* GetFetchedModule(nsIURI* aURL) const;
|
||||
|
||||
friend bool
|
||||
HostResolveImportedModule(JSContext* aCx, unsigned argc, JS::Value* vp);
|
||||
|
||||
nsresult CreateModuleScript(nsModuleLoadRequest* aRequest);
|
||||
nsresult ProcessFetchedModuleSource(nsModuleLoadRequest* aRequest);
|
||||
void ProcessLoadedModuleTree(nsModuleLoadRequest* aRequest);
|
||||
bool InstantiateModuleTree(nsModuleLoadRequest* aRequest);
|
||||
void StartFetchingModuleDependencies(nsModuleLoadRequest* aRequest);
|
||||
nsresult CreateModuleScript(ModuleLoadRequest* aRequest);
|
||||
nsresult ProcessFetchedModuleSource(ModuleLoadRequest* aRequest);
|
||||
void ProcessLoadedModuleTree(ModuleLoadRequest* aRequest);
|
||||
bool InstantiateModuleTree(ModuleLoadRequest* aRequest);
|
||||
void StartFetchingModuleDependencies(ModuleLoadRequest* aRequest);
|
||||
|
||||
RefPtr<mozilla::GenericPromise>
|
||||
StartFetchingModuleAndDependencies(nsModuleLoadRequest* aRequest, nsIURI* aURI);
|
||||
StartFetchingModuleAndDependencies(ModuleLoadRequest* aRequest, nsIURI* aURI);
|
||||
|
||||
nsIDocument* mDocument; // [WEAK]
|
||||
nsCOMArray<nsIScriptLoaderObserver> mObservers;
|
||||
nsScriptLoadRequestList mNonAsyncExternalScriptInsertedRequests;
|
||||
ScriptLoadRequestList mNonAsyncExternalScriptInsertedRequests;
|
||||
// mLoadingAsyncRequests holds async requests while they're loading; when they
|
||||
// have been loaded they are moved to mLoadedAsyncRequests.
|
||||
nsScriptLoadRequestList mLoadingAsyncRequests;
|
||||
nsScriptLoadRequestList mLoadedAsyncRequests;
|
||||
nsScriptLoadRequestList mDeferRequests;
|
||||
nsScriptLoadRequestList mXSLTRequests;
|
||||
RefPtr<nsScriptLoadRequest> mParserBlockingRequest;
|
||||
ScriptLoadRequestList mLoadingAsyncRequests;
|
||||
ScriptLoadRequestList mLoadedAsyncRequests;
|
||||
ScriptLoadRequestList mDeferRequests;
|
||||
ScriptLoadRequestList mXSLTRequests;
|
||||
RefPtr<ScriptLoadRequest> mParserBlockingRequest;
|
||||
|
||||
// In mRequests, the additional information here is stored by the element.
|
||||
struct PreloadInfo {
|
||||
RefPtr<nsScriptLoadRequest> mRequest;
|
||||
RefPtr<ScriptLoadRequest> mRequest;
|
||||
nsString mCharset;
|
||||
};
|
||||
|
||||
friend void ImplCycleCollectionUnlink(nsScriptLoader::PreloadInfo& aField);
|
||||
friend void ImplCycleCollectionUnlink(ScriptLoader::PreloadInfo& aField);
|
||||
friend void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
|
||||
nsScriptLoader::PreloadInfo& aField,
|
||||
ScriptLoader::PreloadInfo& aField,
|
||||
const char* aName, uint32_t aFlags);
|
||||
|
||||
struct PreloadRequestComparator {
|
||||
bool Equals(const PreloadInfo &aPi, nsScriptLoadRequest * const &aRequest)
|
||||
bool Equals(const PreloadInfo &aPi, ScriptLoadRequest * const &aRequest)
|
||||
const
|
||||
{
|
||||
return aRequest == aPi.mRequest;
|
||||
|
@ -628,7 +623,7 @@ private:
|
|||
|
||||
nsCOMPtr<nsIScriptElement> mCurrentScript;
|
||||
nsCOMPtr<nsIScriptElement> mCurrentParserInsertedScript;
|
||||
nsTArray< RefPtr<nsScriptLoader> > mPendingChildLoaders;
|
||||
nsTArray< RefPtr<ScriptLoader> > mPendingChildLoaders;
|
||||
uint32_t mParserBlockingBlockerCount;
|
||||
uint32_t mBlockerCount;
|
||||
uint32_t mNumberOfProcessors;
|
||||
|
@ -639,58 +634,11 @@ private:
|
|||
|
||||
// Module map
|
||||
nsRefPtrHashtable<nsURIHashKey, mozilla::GenericPromise::Private> mFetchingModules;
|
||||
nsRefPtrHashtable<nsURIHashKey, nsModuleScript> mFetchedModules;
|
||||
nsRefPtrHashtable<nsURIHashKey, ModuleScript> mFetchedModules;
|
||||
|
||||
nsCOMPtr<nsIConsoleReportCollector> mReporter;
|
||||
};
|
||||
|
||||
class nsScriptLoadHandler final : public nsIIncrementalStreamLoaderObserver
|
||||
{
|
||||
public:
|
||||
explicit nsScriptLoadHandler(nsScriptLoader* aScriptLoader,
|
||||
nsScriptLoadRequest *aRequest,
|
||||
mozilla::dom::SRICheckDataVerifier *aSRIDataVerifier);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIINCREMENTALSTREAMLOADEROBSERVER
|
||||
|
||||
private:
|
||||
virtual ~nsScriptLoadHandler();
|
||||
|
||||
/*
|
||||
* Try to decode some raw data.
|
||||
*/
|
||||
nsresult TryDecodeRawData(const uint8_t* aData, uint32_t aDataLength,
|
||||
bool aEndOfStream);
|
||||
|
||||
/*
|
||||
* Discover the charset by looking at the stream data, the script
|
||||
* tag, and other indicators. Returns true if charset has been
|
||||
* discovered.
|
||||
*/
|
||||
bool EnsureDecoder(nsIIncrementalStreamLoader *aLoader,
|
||||
const uint8_t* aData, uint32_t aDataLength,
|
||||
bool aEndOfStream);
|
||||
|
||||
// ScriptLoader which will handle the parsed script.
|
||||
RefPtr<nsScriptLoader> mScriptLoader;
|
||||
|
||||
// The nsScriptLoadRequest for this load.
|
||||
RefPtr<nsScriptLoadRequest> mRequest;
|
||||
|
||||
// SRI data verifier.
|
||||
nsAutoPtr<mozilla::dom::SRICheckDataVerifier> mSRIDataVerifier;
|
||||
|
||||
// Status of SRI data operations.
|
||||
nsresult mSRIStatus;
|
||||
|
||||
// Unicode decoder for charset.
|
||||
nsCOMPtr<nsIUnicodeDecoder> mDecoder;
|
||||
|
||||
// Accumulated decoded char buffer.
|
||||
mozilla::Vector<char16_t> mBuffer;
|
||||
};
|
||||
|
||||
class nsAutoScriptLoaderDisabler
|
||||
{
|
||||
public:
|
||||
|
@ -711,7 +659,10 @@ public:
|
|||
}
|
||||
|
||||
bool mWasEnabled;
|
||||
RefPtr<nsScriptLoader> mLoader;
|
||||
RefPtr<ScriptLoader> mLoader;
|
||||
};
|
||||
|
||||
#endif //__nsScriptLoader_h__
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif //mozilla_dom_ScriptLoader_h
|
|
@ -0,0 +1,36 @@
|
|||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# 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/.
|
||||
|
||||
XPIDL_SOURCES += [
|
||||
'nsIScriptLoaderObserver.idl',
|
||||
]
|
||||
|
||||
XPIDL_MODULE = 'dom'
|
||||
|
||||
EXPORTS += ['nsIScriptElement.h']
|
||||
|
||||
EXPORTS.mozilla.dom += [
|
||||
'ScriptElement.h',
|
||||
'ScriptLoader.h',
|
||||
'ScriptSettings.h',
|
||||
]
|
||||
|
||||
SOURCES += [
|
||||
'ModuleLoadRequest.cpp',
|
||||
'ModuleScript.cpp',
|
||||
'ScriptElement.cpp',
|
||||
'ScriptLoader.cpp',
|
||||
'ScriptLoadHandler.cpp',
|
||||
'ScriptSettings.cpp',
|
||||
]
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
'/dom/base',
|
||||
'/dom/workers',
|
||||
]
|
||||
|
||||
include('/ipc/chromium/chromium-config.mozbuild')
|
||||
|
||||
FINAL_LIBRARY = 'xul'
|
|
@ -42,7 +42,7 @@ NS_IMPL_ISUPPORTS_INHERITED(SVGScriptElement, SVGScriptElementBase,
|
|||
SVGScriptElement::SVGScriptElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
|
||||
FromParser aFromParser)
|
||||
: SVGScriptElementBase(aNodeInfo)
|
||||
, nsScriptElement(aFromParser)
|
||||
, ScriptElement(aFromParser)
|
||||
{
|
||||
AddMutationObserver(this);
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ SVGScriptElement::FreezeUriAsyncDefer()
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// nsScriptElement methods
|
||||
// ScriptElement methods
|
||||
|
||||
bool
|
||||
SVGScriptElement::HasScriptContent()
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "nsSVGElement.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsSVGString.h"
|
||||
#include "nsScriptElement.h"
|
||||
#include "mozilla/dom/ScriptElement.h"
|
||||
|
||||
class nsIDocument;
|
||||
|
||||
|
@ -24,7 +24,7 @@ namespace dom {
|
|||
typedef nsSVGElement SVGScriptElementBase;
|
||||
|
||||
class SVGScriptElement final : public SVGScriptElementBase,
|
||||
public nsScriptElement
|
||||
public ScriptElement
|
||||
{
|
||||
protected:
|
||||
friend nsresult (::NS_NewSVGScriptElement(nsIContent **aResult,
|
||||
|
@ -47,7 +47,7 @@ public:
|
|||
virtual void FreezeUriAsyncDefer() override;
|
||||
virtual CORSMode GetCORSMode() const override;
|
||||
|
||||
// nsScriptElement
|
||||
// ScriptElement
|
||||
virtual bool HasScriptContent() override;
|
||||
|
||||
// nsIContent specializations:
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
#include "nsIPipe.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsPrintfCString.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "nsString.h"
|
||||
#include "nsStreamUtils.h"
|
||||
#include "nsTArray.h"
|
||||
|
@ -58,6 +57,7 @@
|
|||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/PromiseNativeHandler.h"
|
||||
#include "mozilla/dom/Response.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
#include "mozilla/dom/SRILogHelper.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
|
@ -1075,14 +1075,14 @@ private:
|
|||
// May be null.
|
||||
nsIDocument* parentDoc = mWorkerPrivate->GetDocument();
|
||||
|
||||
// Use the regular nsScriptLoader for this grunt work! Should be just fine
|
||||
// Use the regular ScriptLoader for this grunt work! Should be just fine
|
||||
// because we're running on the main thread.
|
||||
// Unlike <script> tags, Worker scripts are always decoded as UTF-8,
|
||||
// per spec. So we explicitly pass in the charset hint.
|
||||
rv = nsScriptLoader::ConvertToUTF16(aLoadInfo.mChannel, aString, aStringLen,
|
||||
NS_LITERAL_STRING("UTF-8"), parentDoc,
|
||||
aLoadInfo.mScriptTextBuf,
|
||||
aLoadInfo.mScriptTextLength);
|
||||
rv = ScriptLoader::ConvertToUTF16(aLoadInfo.mChannel, aString, aStringLen,
|
||||
NS_LITERAL_STRING("UTF-8"), parentDoc,
|
||||
aLoadInfo.mScriptTextBuf,
|
||||
aLoadInfo.mScriptTextLength);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
@ -1289,10 +1289,10 @@ private:
|
|||
MOZ_ASSERT(!loadInfo.mScriptTextBuf);
|
||||
|
||||
nsresult rv =
|
||||
nsScriptLoader::ConvertToUTF16(nullptr, aString, aStringLen,
|
||||
NS_LITERAL_STRING("UTF-8"), parentDoc,
|
||||
loadInfo.mScriptTextBuf,
|
||||
loadInfo.mScriptTextLength);
|
||||
ScriptLoader::ConvertToUTF16(nullptr, aString, aStringLen,
|
||||
NS_LITERAL_STRING("UTF-8"), parentDoc,
|
||||
loadInfo.mScriptTextBuf,
|
||||
loadInfo.mScriptTextLength);
|
||||
if (NS_SUCCEEDED(rv) && IsMainWorkerScript()) {
|
||||
nsCOMPtr<nsIURI> finalURI;
|
||||
rv = NS_NewURI(getter_AddRefs(finalURI), loadInfo.mFullURL, nullptr, nullptr);
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "nsITimer.h"
|
||||
#include "nsIUploadChannel2.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
|
@ -44,6 +43,7 @@
|
|||
#include "mozilla/dom/PromiseNativeHandler.h"
|
||||
#include "mozilla/dom/Request.h"
|
||||
#include "mozilla/dom/RootedDictionary.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
#include "mozilla/dom/TypedArray.h"
|
||||
#include "mozilla/ipc/BackgroundChild.h"
|
||||
#include "mozilla/ipc/PBackgroundChild.h"
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "mozilla/dom/cache/Cache.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/PromiseWorkerProxy.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
#include "mozilla/ipc/BackgroundUtils.h"
|
||||
#include "mozilla/ipc/PBackgroundSharedTypes.h"
|
||||
#include "nsICacheInfoChannel.h"
|
||||
|
@ -23,7 +24,6 @@
|
|||
#include "nsIScriptError.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "ServiceWorkerManager.h"
|
||||
#include "Workers.h"
|
||||
#include "nsStringStream.h"
|
||||
|
@ -801,9 +801,9 @@ CompareNetwork::OnStreamComplete(nsIStreamLoader* aLoader, nsISupports* aContext
|
|||
char16_t* buffer = nullptr;
|
||||
size_t len = 0;
|
||||
|
||||
rv = nsScriptLoader::ConvertToUTF16(httpChannel, aString, aLen,
|
||||
NS_LITERAL_STRING("UTF-8"), nullptr,
|
||||
buffer, len);
|
||||
rv = ScriptLoader::ConvertToUTF16(httpChannel, aString, aLen,
|
||||
NS_LITERAL_STRING("UTF-8"), nullptr,
|
||||
buffer, len);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
mManager->NetworkFinished(rv);
|
||||
return rv;
|
||||
|
@ -855,9 +855,9 @@ CompareCache::OnStreamComplete(nsIStreamLoader* aLoader, nsISupports* aContext,
|
|||
char16_t* buffer = nullptr;
|
||||
size_t len = 0;
|
||||
|
||||
nsresult rv = nsScriptLoader::ConvertToUTF16(nullptr, aString, aLen,
|
||||
NS_LITERAL_STRING("UTF-8"),
|
||||
nullptr, buffer, len);
|
||||
nsresult rv = ScriptLoader::ConvertToUTF16(nullptr, aString, aLen,
|
||||
NS_LITERAL_STRING("UTF-8"),
|
||||
nullptr, buffer, len);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
mManager->CacheFinished(rv, false);
|
||||
return rv;
|
||||
|
|
|
@ -12,11 +12,11 @@
|
|||
#include "mozilla/dom/PromiseNativeHandler.h"
|
||||
#include "mozilla/dom/RegisterWorkletBindings.h"
|
||||
#include "mozilla/dom/Response.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
#include "nsIInputStreamPump.h"
|
||||
#include "nsIThreadRetargetableRequest.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "xpcprivate.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -171,9 +171,9 @@ public:
|
|||
char16_t* scriptTextBuf;
|
||||
size_t scriptTextLength;
|
||||
nsresult rv =
|
||||
nsScriptLoader::ConvertToUTF16(nullptr, aString, aStringLen,
|
||||
NS_LITERAL_STRING("UTF-8"), nullptr,
|
||||
scriptTextBuf, scriptTextLength);
|
||||
ScriptLoader::ConvertToUTF16(nullptr, aString, aStringLen,
|
||||
NS_LITERAL_STRING("UTF-8"), nullptr,
|
||||
scriptTextBuf, scriptTextLength);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
RejectPromises(rv);
|
||||
return NS_OK;
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
#include "nsRect.h"
|
||||
#include "nsIWebNavigation.h"
|
||||
#include "nsIScriptElement.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "nsStyleLinkElement.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
|
@ -62,6 +61,7 @@
|
|||
#include "mozilla/dom/Element.h"
|
||||
#include "mozilla/dom/HTMLTemplateElement.h"
|
||||
#include "mozilla/dom/ProcessingInstruction.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
|
|
@ -24,10 +24,10 @@
|
|||
#include "nsTArray.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "mozilla/css/Loader.h"
|
||||
#include "mozilla/dom/DocumentFragment.h"
|
||||
#include "mozilla/dom/ProcessingInstruction.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
|
||||
using namespace mozilla::dom;
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMDocumentType.h"
|
||||
#include "nsIScriptElement.h"
|
||||
|
@ -31,6 +30,7 @@
|
|||
#include "mozilla/css/Loader.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "mozilla/dom/EncodingUtils.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "txXMLUtils.h"
|
||||
#include "nsContentSink.h"
|
||||
|
@ -230,7 +230,7 @@ txMozillaXMLOutput::endDocument(nsresult aResult)
|
|||
MOZ_ASSERT(mDocument->GetReadyStateEnum() ==
|
||||
nsIDocument::READYSTATE_LOADING, "Bad readyState");
|
||||
mDocument->SetReadyStateInternal(nsIDocument::READYSTATE_INTERACTIVE);
|
||||
nsScriptLoader* loader = mDocument->ScriptLoader();
|
||||
ScriptLoader* loader = mDocument->ScriptLoader();
|
||||
if (loader) {
|
||||
loader->ParsingComplete(false);
|
||||
}
|
||||
|
@ -416,7 +416,7 @@ txMozillaXMLOutput::startDocument()
|
|||
}
|
||||
|
||||
if (mCreatingNewDocument) {
|
||||
nsScriptLoader* loader = mDocument->ScriptLoader();
|
||||
ScriptLoader* loader = mDocument->ScriptLoader();
|
||||
if (loader) {
|
||||
loader->BeginDeferringScripts();
|
||||
}
|
||||
|
@ -857,7 +857,7 @@ txMozillaXMLOutput::createResultDocument(const nsSubstring& aName, int32_t aNsID
|
|||
}
|
||||
|
||||
// Set up script loader of the result document.
|
||||
nsScriptLoader *loader = mDocument->ScriptLoader();
|
||||
ScriptLoader *loader = mDocument->ScriptLoader();
|
||||
if (mNotifier) {
|
||||
loader->AddObserver(mNotifier);
|
||||
}
|
||||
|
|
|
@ -3336,10 +3336,10 @@ XULDocument::OnStreamComplete(nsIStreamLoader* aLoader,
|
|||
!mOffThreadCompileStringBuf),
|
||||
"XULDocument can't load multiple scripts at once");
|
||||
|
||||
rv = nsScriptLoader::ConvertToUTF16(channel, string, stringLen,
|
||||
EmptyString(), this,
|
||||
mOffThreadCompileStringBuf,
|
||||
mOffThreadCompileStringLength);
|
||||
rv = ScriptLoader::ConvertToUTF16(channel, string, stringLen,
|
||||
EmptyString(), this,
|
||||
mOffThreadCompileStringBuf,
|
||||
mOffThreadCompileStringLength);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// Attempt to give ownership of the buffer to the JS engine. If
|
||||
// we hit offthread compilation, however, we will have to take it
|
||||
|
|
|
@ -21,13 +21,13 @@
|
|||
#include "nsCOMArray.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsIXULDocument.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIStreamLoader.h"
|
||||
#include "nsICSSLoaderObserver.h"
|
||||
#include "nsIXULStore.h"
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
|
||||
#include "js/TracingAPI.h"
|
||||
#include "js/TypeDecls.h"
|
||||
|
|
|
@ -881,7 +881,7 @@ XULContentSinkImpl::OpenScript(const char16_t** aAttributes,
|
|||
isJavaScript = false;
|
||||
}
|
||||
} else if (key.EqualsLiteral("language")) {
|
||||
// Language is deprecated, and the impl in nsScriptLoader ignores the
|
||||
// Language is deprecated, and the impl in ScriptLoader ignores the
|
||||
// various version strings anyway. So we make no attempt to support
|
||||
// languages other than JS for language=
|
||||
nsAutoString lang(aAttributes[1]);
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include "nsNetCID.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIFileURL.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
|
@ -26,6 +25,7 @@
|
|||
#include "jswrapper.h"
|
||||
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
#include "mozilla/dom/ToJSValue.h"
|
||||
#include "mozilla/HoldDropJSObjects.h"
|
||||
#include "mozilla/scache/StartupCache.h"
|
||||
|
@ -139,8 +139,8 @@ PrepareScript(nsIURI* uri,
|
|||
size_t scriptLength = 0;
|
||||
|
||||
nsresult rv =
|
||||
nsScriptLoader::ConvertToUTF16(nullptr, reinterpret_cast<const uint8_t*>(buf), len,
|
||||
charset, nullptr, scriptBuf, scriptLength);
|
||||
ScriptLoader::ConvertToUTF16(nullptr, reinterpret_cast<const uint8_t*>(buf), len,
|
||||
charset, nullptr, scriptBuf, scriptLength);
|
||||
|
||||
JS::SourceBufferHolder srcBuf(scriptBuf, scriptLength,
|
||||
JS::SourceBufferHolder::GiveOwnership);
|
||||
|
@ -826,9 +826,9 @@ ScriptPrecompiler::OnStreamComplete(nsIIncrementalStreamLoader* aLoader,
|
|||
// Convert data to char16_t* and prepare to call CompileOffThread.
|
||||
nsAutoString hintCharset;
|
||||
nsresult rv =
|
||||
nsScriptLoader::ConvertToUTF16(mChannel, aString, aLength,
|
||||
hintCharset, nullptr,
|
||||
mScriptBuf, mScriptLength);
|
||||
ScriptLoader::ConvertToUTF16(mChannel, aString, aLength,
|
||||
hintCharset, nullptr,
|
||||
mScriptBuf, mScriptLength);
|
||||
|
||||
NS_ENSURE_SUCCESS(rv, NS_OK);
|
||||
|
||||
|
|
|
@ -35,13 +35,13 @@
|
|||
#include "nsCCUncollectableMarker.h"
|
||||
#include "nsCycleCollectionNoteRootCallback.h"
|
||||
#include "nsCycleCollector.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "jsapi.h"
|
||||
#include "jsprf.h"
|
||||
#include "js/MemoryMetrics.h"
|
||||
#include "mozilla/dom/GeneratedAtomList.h"
|
||||
#include "mozilla/dom/BindingUtils.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
#include "mozilla/dom/WindowBinding.h"
|
||||
#include "mozilla/jsipc/CrossProcessObjectWrappers.h"
|
||||
#include "mozilla/Atomics.h"
|
||||
|
@ -3035,8 +3035,8 @@ ReadSourceFromFilename(JSContext* cx, const char* filename, char16_t** src, size
|
|||
ptr += bytesRead;
|
||||
}
|
||||
|
||||
rv = nsScriptLoader::ConvertToUTF16(scriptChannel, buf.get(), rawLen, EmptyString(),
|
||||
nullptr, *src, *len);
|
||||
rv = ScriptLoader::ConvertToUTF16(scriptChannel, buf.get(), rawLen, EmptyString(),
|
||||
nullptr, *src, *len);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!*src)
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
|
||||
#include "nsIStyleSheetLinkingElement.h"
|
||||
#include "nsStyleLinkElement.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "nsIHTMLDocument.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED(nsHtml5DocumentBuilder, nsContentSink,
|
||||
mOwnedElements)
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
#include "nsHtml5OplessBuilder.h"
|
||||
|
||||
#include "nsScriptLoader.h"
|
||||
#include "mozilla/css/Loader.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIHTMLDocument.h"
|
||||
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
#include "mozilla/DebugOnly.h"
|
||||
#include "mozilla/Likely.h"
|
||||
#include "mozilla/dom/nsCSPService.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
|
||||
#include "nsError.h"
|
||||
#include "nsHtml5TreeOpExecutor.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "nsIContentViewer.h"
|
||||
#include "nsIContentSecurityPolicy.h"
|
||||
#include "nsIDocShellTreeItem.h"
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#include "nsXPCOM.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "nsEscape.h"
|
||||
#include "nsIParser.h"
|
||||
#include "nsIDTD.h"
|
||||
|
@ -36,6 +35,7 @@
|
|||
#include "nsTreeSanitizer.h"
|
||||
#include "nsHtml5Module.h"
|
||||
#include "mozilla/dom/DocumentFragment.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
#include "nsNullPrincipal.h"
|
||||
|
||||
#define XHTML_DIV_TAG "div xmlns=\"http://www.w3.org/1999/xhtml\""
|
||||
|
@ -148,7 +148,7 @@ nsParserUtils::ParseFragment(const nsAString& aFragment,
|
|||
nsAutoScriptBlockerSuppressNodeRemoved autoBlocker;
|
||||
|
||||
// stop scripts
|
||||
RefPtr<nsScriptLoader> loader;
|
||||
RefPtr<ScriptLoader> loader;
|
||||
bool scripts_enabled = false;
|
||||
if (document) {
|
||||
loader = document->ScriptLoader();
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include "nsIFragmentContentSink.h"
|
||||
#include "nsStreamUtils.h"
|
||||
#include "nsHTMLTokenizer.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "nsDataHashtable.h"
|
||||
#include "nsXPCOMCIDInternal.h"
|
||||
#include "nsMimeTypes.h"
|
||||
|
@ -41,6 +40,7 @@
|
|||
#include "nsIHTMLContentSink.h"
|
||||
|
||||
#include "mozilla/dom/EncodingUtils.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
#include "mozilla/BinarySearch.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
|
Loading…
Reference in New Issue