Move URL from WebCore to WTF
[WebKit-https.git] / Source / WebCore / workers / WorkerScriptLoader.h
index 2eec2ad..04a41c2 100644 (file)
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
- *
  */
 
-#ifndef WorkerScriptLoader_h
-#define WorkerScriptLoader_h
+#pragma once
 
-#include "URL.h"
+#include "ContentSecurityPolicyResponseHeaders.h"
+#include "FetchOptions.h"
+#include "ResourceError.h"
 #include "ResourceRequest.h"
 #include "ThreadableLoader.h"
 #include "ThreadableLoaderClient.h"
 #include <memory>
 #include <wtf/FastMalloc.h>
-#include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+#include <wtf/URL.h>
 #include <wtf/text/StringBuilder.h>
 
 namespace WebCore {
 
-    class ResourceRequest;
-    class ResourceResponse;
-    class ScriptExecutionContext;
-    class TextResourceDecoder;
-    class WorkerScriptLoaderClient;
+class ResourceResponse;
+class ScriptExecutionContext;
+class TextResourceDecoder;
+class WorkerScriptLoaderClient;
 
-    class WorkerScriptLoader : public RefCounted<WorkerScriptLoader>, public ThreadableLoaderClient {
-        WTF_MAKE_FAST_ALLOCATED;
-    public:
-        static Ref<WorkerScriptLoader> create()
-        {
-            return adoptRef(*new WorkerScriptLoader);
-        }
+class WorkerScriptLoader : public RefCounted<WorkerScriptLoader>, public ThreadableLoaderClient {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    static Ref<WorkerScriptLoader> create()
+    {
+        return adoptRef(*new WorkerScriptLoader);
+    }
 
-        void loadSynchronously(ScriptExecutionContext*, const URL&, FetchOptions::Mode, ContentSecurityPolicyEnforcement);
-        void loadAsynchronously(ScriptExecutionContext*, const URL&, FetchOptions::Mode, ContentSecurityPolicyEnforcement, WorkerScriptLoaderClient*);
+    std::optional<Exception> loadSynchronously(ScriptExecutionContext*, const URL&, FetchOptions::Mode, FetchOptions::Cache, ContentSecurityPolicyEnforcement, const String& initiatorIdentifier);
+    void loadAsynchronously(ScriptExecutionContext&, ResourceRequest&&, FetchOptions&&, ContentSecurityPolicyEnforcement, ServiceWorkersMode, WorkerScriptLoaderClient&);
 
-        void notifyError();
+    void notifyError();
 
-        String script();
-        const URL& url() const { return m_url; }
-        const URL& responseURL() const;
-        bool failed() const { return m_failed; }
-        unsigned long identifier() const { return m_identifier; }
+    String script();
+    const ContentSecurityPolicyResponseHeaders& contentSecurityPolicy() const { return m_contentSecurityPolicy; }
+    const URL& url() const { return m_url; }
+    const URL& responseURL() const;
+    const String& responseMIMEType() const { return m_responseMIMEType; }
+    bool failed() const { return m_failed; }
+    unsigned long identifier() const { return m_identifier; }
+    const ResourceError& error() const { return m_error; }
 
-        void didReceiveResponse(unsigned long /*identifier*/, const ResourceResponse&) override;
-        void didReceiveData(const char* data, int dataLength) override;
-        void didFinishLoading(unsigned long identifier, double) override;
-        void didFail(const ResourceError&) override;
+    void didReceiveResponse(unsigned long identifier, const ResourceResponse&) override;
+    void didReceiveData(const char* data, int dataLength) override;
+    void didFinishLoading(unsigned long identifier) override;
+    void didFail(const ResourceError&) override;
 
-    private:
-        friend class WTF::RefCounted<WorkerScriptLoader>;
+    void cancel();
 
-        WorkerScriptLoader();
-        ~WorkerScriptLoader();
+private:
+    friend class WTF::RefCounted<WorkerScriptLoader>;
 
-        std::unique_ptr<ResourceRequest> createResourceRequest();
-        void notifyFinished();
+    WorkerScriptLoader();
+    ~WorkerScriptLoader();
 
-        WorkerScriptLoaderClient* m_client;
-        RefPtr<ThreadableLoader> m_threadableLoader;
-        String m_responseEncoding;        
-        RefPtr<TextResourceDecoder> m_decoder;
-        StringBuilder m_script;
-        URL m_url;
-        URL m_responseURL;
-        bool m_failed;
-        unsigned long m_identifier;
-        bool m_finishing;
-    };
+    std::unique_ptr<ResourceRequest> createResourceRequest(const String& initiatorIdentifier);
+    void notifyFinished();
 
-} // namespace WebCore
+    WorkerScriptLoaderClient* m_client { nullptr };
+    RefPtr<ThreadableLoader> m_threadableLoader;
+    String m_responseEncoding;
+    RefPtr<TextResourceDecoder> m_decoder;
+    StringBuilder m_script;
+    URL m_url;
+    URL m_responseURL;
+    String m_responseMIMEType;
+    FetchOptions::Destination m_destination;
+    ContentSecurityPolicyResponseHeaders m_contentSecurityPolicy;
+    unsigned long m_identifier { 0 };
+    bool m_failed { false };
+    bool m_finishing { false };
+    ResourceError m_error;
+};
 
-#endif // WorkerScriptLoader_h
+} // namespace WebCore