2020-03-14 12:41:51 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-05-24 22:00:46 +02:00
|
|
|
#include <AK/Function.h>
|
2020-07-26 15:08:16 +02:00
|
|
|
#include <LibWeb/HTML/HTMLElement.h>
|
2020-03-14 12:41:51 +01:00
|
|
|
|
2020-07-28 18:20:36 +02:00
|
|
|
namespace Web::HTML {
|
2020-03-14 12:41:51 +01:00
|
|
|
|
2020-07-28 02:54:19 +01:00
|
|
|
class HTMLScriptElement final : public HTMLElement {
|
2020-03-14 12:41:51 +01:00
|
|
|
public:
|
2020-07-27 05:04:26 +01:00
|
|
|
using WrapperType = Bindings::HTMLScriptElementWrapper;
|
|
|
|
|
2021-02-07 11:20:15 +01:00
|
|
|
HTMLScriptElement(DOM::Document&, QualifiedName);
|
2020-03-14 12:41:51 +01:00
|
|
|
virtual ~HTMLScriptElement() override;
|
|
|
|
|
2020-05-24 22:00:46 +02:00
|
|
|
bool is_non_blocking() const { return m_non_blocking; }
|
2020-05-27 23:01:04 +02:00
|
|
|
bool is_ready_to_be_parser_executed() const { return m_ready_to_be_parser_executed; }
|
2020-06-15 18:37:48 +02:00
|
|
|
bool failed_to_load() const { return m_failed_to_load; }
|
2020-05-24 22:00:46 +02:00
|
|
|
|
2020-07-26 19:37:56 +02:00
|
|
|
void set_parser_document(Badge<HTMLDocumentParser>, DOM::Document&);
|
2020-05-24 22:00:46 +02:00
|
|
|
void set_non_blocking(Badge<HTMLDocumentParser>, bool);
|
2020-06-06 16:32:27 +02:00
|
|
|
void set_already_started(Badge<HTMLDocumentParser>, bool b) { m_already_started = b; }
|
2021-03-15 19:41:15 +01:00
|
|
|
void prepare_script(Badge<HTMLDocumentParser>) { prepare_script(); }
|
2020-05-27 23:01:04 +02:00
|
|
|
void execute_script();
|
2020-05-24 22:00:46 +02:00
|
|
|
|
2021-04-06 18:09:18 +01:00
|
|
|
bool is_parser_inserted() const { return !!m_parser_document; }
|
|
|
|
|
|
|
|
virtual void inserted() override;
|
2021-03-15 19:41:15 +01:00
|
|
|
|
2020-05-24 22:00:46 +02:00
|
|
|
private:
|
2021-03-15 19:41:15 +01:00
|
|
|
void prepare_script();
|
2020-05-24 22:00:46 +02:00
|
|
|
void script_became_ready();
|
|
|
|
void when_the_script_is_ready(Function<void()>);
|
|
|
|
|
2020-07-26 19:37:56 +02:00
|
|
|
WeakPtr<DOM::Document> m_parser_document;
|
|
|
|
WeakPtr<DOM::Document> m_preparation_time_document;
|
2020-05-24 22:00:46 +02:00
|
|
|
bool m_non_blocking { false };
|
|
|
|
bool m_already_started { false };
|
|
|
|
bool m_from_an_external_file { false };
|
|
|
|
bool m_script_ready { false };
|
|
|
|
bool m_ready_to_be_parser_executed { false };
|
2020-06-15 18:37:48 +02:00
|
|
|
bool m_failed_to_load { false };
|
2020-05-24 22:00:46 +02:00
|
|
|
|
2021-01-28 20:31:20 +00:00
|
|
|
enum class ScriptType {
|
|
|
|
Classic,
|
|
|
|
Module
|
|
|
|
};
|
|
|
|
|
|
|
|
ScriptType m_script_type { ScriptType::Classic };
|
|
|
|
|
2020-05-24 22:00:46 +02:00
|
|
|
Function<void()> m_script_ready_callback;
|
|
|
|
|
|
|
|
String m_script_source;
|
2021-02-27 19:35:45 +01:00
|
|
|
String m_script_filename;
|
2020-03-14 12:41:51 +01:00
|
|
|
};
|
|
|
|
|
2020-05-24 22:00:46 +02:00
|
|
|
}
|