diff options
Diffstat (limited to 'Source/WebCore/dom/PendingScript.h')
-rw-r--r-- | Source/WebCore/dom/PendingScript.h | 101 |
1 files changed, 39 insertions, 62 deletions
diff --git a/Source/WebCore/dom/PendingScript.h b/Source/WebCore/dom/PendingScript.h index f7831ce6f..fc758d07d 100644 --- a/Source/WebCore/dom/PendingScript.h +++ b/Source/WebCore/dom/PendingScript.h @@ -23,86 +23,63 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef PendingScript_h -#define PendingScript_h +#pragma once -#include "CachedResourceClient.h" -#include "CachedResourceHandle.h" +#include "LoadableScript.h" +#include "LoadableScriptClient.h" +#include <wtf/Ref.h> +#include <wtf/RefCounted.h> #include <wtf/text/TextPosition.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefPtr.h> namespace WebCore { class CachedScript; -class Element; - -// A container for an external script which may be loaded and executed. -// -// A CachedResourceHandle alone does not prevent the underlying CachedResource -// from purging its data buffer. This class holds a dummy client open for its -// lifetime in order to guarantee that the data buffer will not be purged. -class PendingScript : public CachedResourceClient { +class PendingScriptClient; +class ScriptElement; + +// A container for scripts which may be loaded and executed. +// This can hold LoadableScript and non external inline script. +class PendingScript final : public RefCounted<PendingScript>, public LoadableScriptClient { public: - PendingScript() - : m_watchingForLoad(false) - , m_startingPosition(TextPosition::belowRangePosition()) - { - } - - PendingScript(Element* element, CachedScript* cachedScript) - : m_watchingForLoad(false) - , m_element(element) - { - setCachedScript(cachedScript); - } - - PendingScript(const PendingScript& other) - : CachedResourceClient(other) - , m_watchingForLoad(other.m_watchingForLoad) - , m_element(other.m_element) - , m_startingPosition(other.m_startingPosition) - { - setCachedScript(other.cachedScript()); - } - - ~PendingScript(); - - PendingScript& operator=(const PendingScript& other) - { - if (this == &other) - return *this; - - m_watchingForLoad = other.m_watchingForLoad; - m_element = other.m_element; - m_startingPosition = other.m_startingPosition; - setCachedScript(other.cachedScript()); - - return *this; - } + static Ref<PendingScript> create(ScriptElement&, LoadableScript&); + static Ref<PendingScript> create(ScriptElement&, TextPosition scriptStartPosition); + + virtual ~PendingScript(); TextPosition startingPosition() const { return m_startingPosition; } void setStartingPosition(const TextPosition& position) { m_startingPosition = position; } - bool watchingForLoad() const { return m_watchingForLoad; } - void setWatchingForLoad(bool b) { m_watchingForLoad = b; } + bool watchingForLoad() const { return needsLoading() && m_client; } + + ScriptElement& element() { return m_element.get(); } + const ScriptElement& element() const { return m_element.get(); } + + LoadableScript* loadableScript() const; + bool needsLoading() const { return loadableScript(); } - Element* element() const { return m_element.get(); } - void setElement(Element* element) { m_element = element; } - PassRefPtr<Element> releaseElementAndClear(); + bool isLoaded() const; + bool error() const; - CachedScript* cachedScript() const; - void setCachedScript(CachedScript*); + void notifyFinished(LoadableScript&) override; - virtual void notifyFinished(CachedResource*) override; + void setClient(PendingScriptClient&); + void clearClient(); private: - bool m_watchingForLoad; - RefPtr<Element> m_element; + PendingScript(ScriptElement&, LoadableScript&); + PendingScript(ScriptElement&, TextPosition startingPosition); + + void notifyClientFinished(); + + Ref<ScriptElement> m_element; TextPosition m_startingPosition; // Only used for inline script tags. - CachedResourceHandle<CachedScript> m_cachedScript; + RefPtr<LoadableScript> m_loadableScript; + PendingScriptClient* m_client { nullptr }; }; +inline LoadableScript* PendingScript::loadableScript() const +{ + return m_loadableScript.get(); } -#endif +} |