Inspector.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/Runtime/Realm.h>
  7. #include <LibJS/Runtime/VM.h>
  8. #include <LibWeb/Bindings/InspectorPrototype.h>
  9. #include <LibWeb/Bindings/Intrinsics.h>
  10. #include <LibWeb/CSS/Selector.h>
  11. #include <LibWeb/HTML/BrowsingContext.h>
  12. #include <LibWeb/HTML/Window.h>
  13. #include <LibWeb/Internals/Inspector.h>
  14. #include <LibWeb/Page/Page.h>
  15. namespace Web::Internals {
  16. JS_DEFINE_ALLOCATOR(Inspector);
  17. Inspector::Inspector(JS::Realm& realm)
  18. : Bindings::PlatformObject(realm)
  19. {
  20. }
  21. Inspector::~Inspector() = default;
  22. void Inspector::initialize(JS::Realm& realm)
  23. {
  24. Base::initialize(realm);
  25. Object::set_prototype(&Bindings::ensure_web_prototype<Bindings::InspectorPrototype>(realm, "Inspector"_fly_string));
  26. }
  27. void Inspector::inspector_loaded()
  28. {
  29. if (auto* page = global_object().browsing_context()->page())
  30. page->client().inspector_did_load();
  31. }
  32. void Inspector::inspect_dom_node(i32 node_id, Optional<i32> const& pseudo_element)
  33. {
  34. if (auto* page = global_object().browsing_context()->page()) {
  35. page->client().inspector_did_select_dom_node(node_id, pseudo_element.map([](auto value) {
  36. VERIFY(value < to_underlying(Web::CSS::Selector::PseudoElement::PseudoElementCount));
  37. return static_cast<Web::CSS::Selector::PseudoElement>(value);
  38. }));
  39. }
  40. }
  41. void Inspector::execute_console_script(String const& script)
  42. {
  43. if (auto* page = global_object().browsing_context()->page())
  44. page->client().inspector_did_execute_console_script(script);
  45. }
  46. }