blob: 0068e2d0cf53aa7ceefa01e2e1d22677cf6979dd [file] [log] [blame]
utatane.tea@gmail.com750fa062016-11-16 11:39:43 +00001/*
2 * Copyright (C) 2016 Apple, Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
utatane.tea@gmail.com750fa062016-11-16 11:39:43 +000028#include "LoadableScript.h"
29#include <wtf/TypeCasts.h>
30
31namespace WebCore {
32
utatane.tea@gmail.com5da4e1a2017-01-28 00:47:30 +000033class ScriptSourceCode;
utatane.tea@gmail.com6069db22017-10-12 13:12:48 +000034class ModuleFetchParameters;
utatane.tea@gmail.com5da4e1a2017-01-28 00:47:30 +000035
36class LoadableModuleScript final : public LoadableScript {
utatane.tea@gmail.com750fa062016-11-16 11:39:43 +000037public:
38 virtual ~LoadableModuleScript();
39
rniwa@webkit.orgb5617a92022-02-01 19:12:52 +000040 static Ref<LoadableModuleScript> create(const AtomString& nonce, const AtomString& integrity, ReferrerPolicy, const AtomString& crossOriginMode, const String& charset, const AtomString& initiatorName, bool isInUserAgentShadowTree);
utatane.tea@gmail.com750fa062016-11-16 11:39:43 +000041
42 bool isLoaded() const final;
darin@apple.coma4ddc782021-05-30 16:11:40 +000043 std::optional<Error> error() const final;
utatane.tea@gmail.com750fa062016-11-16 11:39:43 +000044 bool wasCanceled() const final;
45
utatane.tea@gmail.comd53760f2017-01-27 10:49:23 +000046 bool isClassicScript() const final { return false; }
utatane.tea@gmail.com750fa062016-11-16 11:39:43 +000047 bool isModuleScript() const final { return true; }
48
49 void execute(ScriptElement&) final;
50
51 void setError(Error&&);
52
jlewis3@apple.com91a058b2017-10-20 17:58:32 +000053 void notifyLoadCompleted(UniquedStringImpl&);
54 void notifyLoadFailed(LoadableScript::Error&&);
55 void notifyLoadWasCanceled();
utatane.tea@gmail.com5da4e1a2017-01-28 00:47:30 +000056
jlewis3@apple.com91a058b2017-10-20 17:58:32 +000057 UniquedStringImpl* moduleKey() const { return m_moduleKey.get(); }
utatane.tea@gmail.com11efb902017-10-20 07:19:02 +000058
ysuzuki@apple.com8c1c24c2021-02-20 20:28:27 +000059 ModuleFetchParameters& parameters() { return m_parameters.get(); }
60
utatane.tea@gmail.com750fa062016-11-16 11:39:43 +000061private:
rniwa@webkit.orgb5617a92022-02-01 19:12:52 +000062 LoadableModuleScript(const AtomString& nonce, const AtomString& integrity, ReferrerPolicy, const AtomString& crossOriginMode, const String& charset, const AtomString& initiatorName, bool isInUserAgentShadowTree);
utatane.tea@gmail.com750fa062016-11-16 11:39:43 +000063
utatane.tea@gmail.com6069db22017-10-12 13:12:48 +000064 Ref<ModuleFetchParameters> m_parameters;
utatane.tea@gmail.com5da4e1a2017-01-28 00:47:30 +000065 RefPtr<UniquedStringImpl> m_moduleKey;
darin@apple.coma4ddc782021-05-30 16:11:40 +000066 std::optional<LoadableScript::Error> m_error;
utatane.tea@gmail.com5da4e1a2017-01-28 00:47:30 +000067 bool m_wasCanceled { false };
68 bool m_isLoaded { false };
utatane.tea@gmail.com750fa062016-11-16 11:39:43 +000069};
70
71}
72
73SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::LoadableModuleScript)
74 static bool isType(const WebCore::LoadableScript& script) { return script.isModuleScript(); }
75SPECIALIZE_TYPE_TRAITS_END()