HTMLScriptElement.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Function.h>
  8. #include <LibWeb/HTML/HTMLElement.h>
  9. #include <LibWeb/HTML/Scripting/Script.h>
  10. namespace Web::HTML {
  11. class HTMLScriptElement final : public HTMLElement {
  12. public:
  13. using WrapperType = Bindings::HTMLScriptElementWrapper;
  14. HTMLScriptElement(DOM::Document&, QualifiedName);
  15. virtual ~HTMLScriptElement() override;
  16. bool is_non_blocking() const { return m_non_blocking; }
  17. bool is_ready_to_be_parser_executed() const { return m_ready_to_be_parser_executed; }
  18. bool failed_to_load() const { return m_failed_to_load; }
  19. void set_parser_document(Badge<HTMLParser>, DOM::Document&);
  20. void set_non_blocking(Badge<HTMLParser>, bool);
  21. void set_already_started(Badge<HTMLParser>, bool b) { m_already_started = b; }
  22. void prepare_script(Badge<HTMLParser>) { prepare_script(); }
  23. void execute_script();
  24. bool is_parser_inserted() const { return !!m_parser_document; }
  25. virtual void inserted() override;
  26. // https://html.spec.whatwg.org/multipage/scripting.html#dom-script-supports
  27. static bool supports(String const& type)
  28. {
  29. return type.is_one_of("classic", "module");
  30. }
  31. private:
  32. void prepare_script();
  33. void script_became_ready();
  34. void when_the_script_is_ready(Function<void()>);
  35. WeakPtr<DOM::Document> m_parser_document;
  36. WeakPtr<DOM::Document> m_preparation_time_document;
  37. bool m_non_blocking { false };
  38. bool m_already_started { false };
  39. bool m_from_an_external_file { false };
  40. bool m_script_ready { false };
  41. bool m_ready_to_be_parser_executed { false };
  42. bool m_failed_to_load { false };
  43. enum class ScriptType {
  44. Classic,
  45. Module
  46. };
  47. ScriptType m_script_type { ScriptType::Classic };
  48. Function<void()> m_script_ready_callback;
  49. String m_script_filename;
  50. RefPtr<Script> m_script;
  51. };
  52. }