HTMLScriptElement.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) 2018-2020, 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. namespace Web::HTML {
  10. class HTMLScriptElement final : public HTMLElement {
  11. public:
  12. using WrapperType = Bindings::HTMLScriptElementWrapper;
  13. HTMLScriptElement(DOM::Document&, QualifiedName);
  14. virtual ~HTMLScriptElement() override;
  15. bool is_non_blocking() const { return m_non_blocking; }
  16. bool is_ready_to_be_parser_executed() const { return m_ready_to_be_parser_executed; }
  17. bool failed_to_load() const { return m_failed_to_load; }
  18. void set_parser_document(Badge<HTMLDocumentParser>, DOM::Document&);
  19. void set_non_blocking(Badge<HTMLDocumentParser>, bool);
  20. void set_already_started(Badge<HTMLDocumentParser>, bool b) { m_already_started = b; }
  21. void prepare_script(Badge<HTMLDocumentParser>) { prepare_script(); }
  22. void execute_script();
  23. bool is_parser_inserted() const { return !!m_parser_document; }
  24. virtual void inserted() override;
  25. private:
  26. void prepare_script();
  27. void script_became_ready();
  28. void when_the_script_is_ready(Function<void()>);
  29. WeakPtr<DOM::Document> m_parser_document;
  30. WeakPtr<DOM::Document> m_preparation_time_document;
  31. bool m_non_blocking { false };
  32. bool m_already_started { false };
  33. bool m_from_an_external_file { false };
  34. bool m_script_ready { false };
  35. bool m_ready_to_be_parser_executed { false };
  36. bool m_failed_to_load { false };
  37. enum class ScriptType {
  38. Classic,
  39. Module
  40. };
  41. ScriptType m_script_type { ScriptType::Classic };
  42. Function<void()> m_script_ready_callback;
  43. String m_script_source;
  44. String m_script_filename;
  45. };
  46. }