diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/dom/ScriptElement.h | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/dom/ScriptElement.h')
-rw-r--r-- | Source/WebCore/dom/ScriptElement.h | 79 |
1 files changed, 48 insertions, 31 deletions
diff --git a/Source/WebCore/dom/ScriptElement.h b/Source/WebCore/dom/ScriptElement.h index e1b5fda88..e5e95fd7a 100644 --- a/Source/WebCore/dom/ScriptElement.h +++ b/Source/WebCore/dom/ScriptElement.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2009-2017 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -18,70 +19,85 @@ * */ -#ifndef ScriptElement_h -#define ScriptElement_h +#pragma once #include "CachedResourceClient.h" #include "CachedResourceHandle.h" +#include "ContainerNode.h" +#include "LoadableScript.h" +#include "LoadableScriptClient.h" +#include "Timer.h" #include <wtf/text/TextPosition.h> -#include <wtf/text/WTFString.h> namespace WebCore { class CachedScript; class ContainerNode; class Element; -class ScriptElement; +class LoadableModuleScript; +class PendingScript; class ScriptSourceCode; +class URL; -class ScriptElement : private CachedResourceClient { - WTF_MAKE_FAST_ALLOCATED; +class ScriptElement { public: - ScriptElement(Element*, bool createdByParser, bool isEvaluated); - virtual ~ScriptElement(); + virtual ~ScriptElement() { } - Element* element() const { return m_element; } + Element& element() { return m_element; } + const Element& element() const { return m_element; } enum LegacyTypeSupport { DisallowLegacyTypeInTypeAttribute, AllowLegacyTypeInTypeAttribute }; - bool prepareScript(const TextPosition& scriptStartPosition = TextPosition::minimumPosition(), LegacyTypeSupport = DisallowLegacyTypeInTypeAttribute); + bool prepareScript(const TextPosition& scriptStartPosition = TextPosition(), LegacyTypeSupport = DisallowLegacyTypeInTypeAttribute); String scriptCharset() const { return m_characterEncoding; } - String scriptContent() const; - void executeScript(const ScriptSourceCode&); - void execute(CachedScript*); + WEBCORE_EXPORT String scriptContent() const; + void executeClassicScript(const ScriptSourceCode&); + void executeModuleScript(LoadableModuleScript&); + + void executePendingScript(PendingScript&); // XML parser calls these virtual void dispatchLoadEvent() = 0; void dispatchErrorEvent(); - bool isScriptTypeSupported(LegacyTypeSupport) const; bool haveFiredLoadEvent() const { return m_haveFiredLoad; } bool willBeParserExecuted() const { return m_willBeParserExecuted; } bool readyToBeParserExecuted() const { return m_readyToBeParserExecuted; } bool willExecuteWhenDocumentFinishedParsing() const { return m_willExecuteWhenDocumentFinishedParsing; } - CachedResourceHandle<CachedScript> cachedScript() { return m_cachedScript; } + bool willExecuteInOrder() const { return m_willExecuteInOrder; } + LoadableScript* loadableScript() { return m_loadableScript.get(); } + + // https://html.spec.whatwg.org/multipage/scripting.html#concept-script-type + enum class ScriptType { Classic, Module }; + ScriptType scriptType() const { return m_isModuleScript ? ScriptType::Module : ScriptType::Classic; } + + void ref(); + void deref(); protected: + ScriptElement(Element&, bool createdByParser, bool isEvaluated); + void setHaveFiredLoadEvent(bool haveFiredLoad) { m_haveFiredLoad = haveFiredLoad; } bool isParserInserted() const { return m_parserInserted; } bool alreadyStarted() const { return m_alreadyStarted; } bool forceAsync() const { return m_forceAsync; } // Helper functions used by our parent classes. - bool shouldNotifySubtreeInsertions(ContainerNode&); - void didNotifySubtreeInsertions(ContainerNode*); - void childrenChanged(); - void handleSourceAttribute(const String& sourceUrl); + bool shouldCallFinishedInsertingSubtree(ContainerNode&); + void finishedInsertingSubtree(); + void childrenChanged(const ContainerNode::ChildChange&); + void handleSourceAttribute(const String& sourceURL); void handleAsyncAttribute(); private: + void executeScriptAndDispatchEvent(LoadableScript&); + + std::optional<ScriptType> determineScriptType(LegacyTypeSupport) const; bool ignoresLoadRequest() const; bool isScriptForEventSupported() const; - bool requestScript(const String& sourceUrl); - void stopLoadRequest(); - - virtual void notifyFinished(CachedResource*) override; + bool requestClassicScript(const String& sourceURL); + bool requestModuleScript(const TextPosition& scriptStartPosition); virtual String sourceAttributeValue() const = 0; virtual String charsetAttributeValue() const = 0; @@ -89,12 +105,12 @@ private: virtual String languageAttributeValue() const = 0; virtual String forAttributeValue() const = 0; virtual String eventAttributeValue() const = 0; - virtual bool asyncAttributeValue() const = 0; - virtual bool deferAttributeValue() const = 0; + virtual bool hasAsyncAttribute() const = 0; + virtual bool hasDeferAttribute() const = 0; virtual bool hasSourceAttribute() const = 0; + virtual bool hasNoModuleAttribute() const = 0; - Element* m_element; - CachedResourceHandle<CachedScript> m_cachedScript; + Element& m_element; WTF::OrdinalNumber m_startLineNumber; bool m_parserInserted : 1; bool m_isExternalScript : 1; @@ -105,13 +121,14 @@ private: bool m_willExecuteWhenDocumentFinishedParsing : 1; bool m_forceAsync : 1; bool m_willExecuteInOrder : 1; - bool m_requestUsesAccessControl : 1; + bool m_isModuleScript : 1; String m_characterEncoding; String m_fallbackCharacterEncoding; + RefPtr<LoadableScript> m_loadableScript; }; -ScriptElement* toScriptElementIfPossible(Element*); +// FIXME: replace with is/downcast<ScriptElement>. +bool isScriptElement(Element&); +ScriptElement& downcastScriptElement(Element&); } - -#endif |