LoadableModuleScript.cpp [plain text]
#include "config.h"
#include "LoadableModuleScript.h"
#include "Document.h"
#include "Frame.h"
#include "ModuleFetchParameters.h"
#include "ScriptController.h"
#include "ScriptElement.h"
namespace WebCore {
Ref<LoadableModuleScript> LoadableModuleScript::create(const String& nonce, const String& integrity, const String& crossOriginMode, const String& charset, const AtomicString& initiatorName, bool isInUserAgentShadowTree)
{
return adoptRef(*new LoadableModuleScript(nonce, integrity, crossOriginMode, charset, initiatorName, isInUserAgentShadowTree));
}
LoadableModuleScript::LoadableModuleScript(const String& nonce, const String& integrity, const String& crossOriginMode, const String& charset, const AtomicString& initiatorName, bool isInUserAgentShadowTree)
: LoadableScript(nonce, crossOriginMode, charset, initiatorName, isInUserAgentShadowTree)
, m_parameters(ModuleFetchParameters::create(integrity))
{
}
LoadableModuleScript::~LoadableModuleScript() = default;
bool LoadableModuleScript::isLoaded() const
{
return m_isLoaded;
}
std::optional<LoadableScript::Error> LoadableModuleScript::error() const
{
return m_error;
}
bool LoadableModuleScript::wasCanceled() const
{
return m_wasCanceled;
}
void LoadableModuleScript::notifyLoadCompleted(UniquedStringImpl& moduleKey)
{
m_moduleKey = &moduleKey;
m_isLoaded = true;
notifyClientFinished();
}
void LoadableModuleScript::notifyLoadFailed(LoadableScript::Error&& error)
{
m_error = WTFMove(error);
m_isLoaded = true;
notifyClientFinished();
}
void LoadableModuleScript::notifyLoadWasCanceled()
{
m_wasCanceled = true;
m_isLoaded = true;
notifyClientFinished();
}
void LoadableModuleScript::execute(ScriptElement& scriptElement)
{
scriptElement.executeModuleScript(*this);
}
void LoadableModuleScript::load(Document& document, const URL& rootURL)
{
if (auto* frame = document.frame())
frame->script().loadModuleScript(*this, rootURL.string(), m_parameters.copyRef());
}
void LoadableModuleScript::load(Document& document, const ScriptSourceCode& sourceCode)
{
if (auto* frame = document.frame())
frame->script().loadModuleScript(*this, sourceCode);
}
}