mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 20:59:16 +00:00
LibWeb+LibWebView+WebContent: Remove the built-in Inspector
This commit is contained in:
parent
1c696e7893
commit
810d04b3f4
Notes:
github-actions[bot]
2025-03-15 18:10:57 +00:00
Author: https://github.com/trflynn89
Commit: 810d04b3f4
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3956
34 changed files with 24 additions and 3082 deletions
|
@ -8,7 +8,6 @@ set(SOURCES
|
|||
CookieJar.cpp
|
||||
Database.cpp
|
||||
HelperProcess.cpp
|
||||
InspectorClient.cpp
|
||||
Mutation.cpp
|
||||
Plugins/FontPlugin.cpp
|
||||
Plugins/ImageCodecPlugin.cpp
|
||||
|
|
|
@ -13,7 +13,6 @@ namespace WebView {
|
|||
class Application;
|
||||
class CookieJar;
|
||||
class Database;
|
||||
class InspectorClient;
|
||||
class OutOfProcessWebView;
|
||||
class ProcessManager;
|
||||
class ViewImplementation;
|
||||
|
|
|
@ -85,7 +85,6 @@ static ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_proc
|
|||
Optional<IPC::File> request_server_socket,
|
||||
ClientArguments&&... client_arguments)
|
||||
{
|
||||
auto const& chrome_options = WebView::Application::chrome_options();
|
||||
auto const& web_content_options = WebView::Application::web_content_options();
|
||||
|
||||
Vector<ByteString> arguments {
|
||||
|
@ -95,8 +94,6 @@ static ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_proc
|
|||
web_content_options.executable_path.to_byte_string(),
|
||||
};
|
||||
|
||||
if (chrome_options.devtools_port.has_value())
|
||||
arguments.append("--devtools"sv);
|
||||
if (web_content_options.config_path.has_value()) {
|
||||
arguments.append("--config-path"sv);
|
||||
arguments.append(web_content_options.config_path.value());
|
||||
|
|
|
@ -1,809 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2024, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Base64.h>
|
||||
#include <AK/Enumerate.h>
|
||||
#include <AK/JsonArray.h>
|
||||
#include <AK/JsonObject.h>
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <AK/SourceGenerator.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibCore/Directory.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/Resource.h>
|
||||
#include <LibJS/MarkupGenerator.h>
|
||||
#include <LibURL/Parser.h>
|
||||
#include <LibWeb/Infra/Strings.h>
|
||||
#include <LibWeb/Namespace.h>
|
||||
#include <LibWebView/Application.h>
|
||||
#include <LibWebView/CookieJar.h>
|
||||
#include <LibWebView/InspectorClient.h>
|
||||
#include <LibWebView/SourceHighlighter.h>
|
||||
|
||||
namespace WebView {
|
||||
|
||||
static constexpr auto INSPECTOR_HTML = "resource://ladybird/inspector.html"sv;
|
||||
static constexpr auto INSPECTOR_CSS = "resource://ladybird/inspector.css"sv;
|
||||
static constexpr auto INSPECTOR_JS = "resource://ladybird/inspector.js"sv;
|
||||
|
||||
static String style_sheet_identifier_to_json(Web::CSS::StyleSheetIdentifier const& identifier)
|
||||
{
|
||||
return MUST(String::formatted("{{ type: '{}', domNodeId: {}, url: '{}' }}"sv,
|
||||
Web::CSS::style_sheet_identifier_type_to_string(identifier.type),
|
||||
identifier.dom_element_unique_id.map([](auto& it) { return String::number(it.value()); }).value_or("undefined"_string),
|
||||
identifier.url.value_or("undefined"_string)));
|
||||
}
|
||||
|
||||
InspectorClient::InspectorClient(ViewImplementation& content_web_view, ViewImplementation& inspector_web_view)
|
||||
: m_content_web_view(content_web_view)
|
||||
, m_inspector_web_view(inspector_web_view)
|
||||
{
|
||||
m_content_web_view.on_received_dom_tree = [this](auto const& dom_tree) {
|
||||
auto dom_tree_html = generate_dom_tree(dom_tree);
|
||||
auto dom_tree_base64 = MUST(encode_base64(dom_tree_html.bytes()));
|
||||
|
||||
auto script = MUST(String::formatted("inspector.loadDOMTree(\"{}\");", dom_tree_base64));
|
||||
m_inspector_web_view.run_javascript(script);
|
||||
|
||||
m_dom_tree_loaded = true;
|
||||
|
||||
if (m_pending_selection.has_value())
|
||||
select_node(m_pending_selection.release_value());
|
||||
else
|
||||
select_default_node();
|
||||
};
|
||||
|
||||
m_content_web_view.on_received_dom_node_properties = [this](auto const& properties) {
|
||||
StringBuilder builder;
|
||||
|
||||
// FIXME: Support box model metrics and ARIA properties.
|
||||
builder.append("inspector.createPropertyTables(\""sv);
|
||||
builder.append_escaped_for_json(properties.computed_style.serialized());
|
||||
builder.append("\", \""sv);
|
||||
builder.append_escaped_for_json(properties.resolved_style.serialized());
|
||||
builder.append("\", \""sv);
|
||||
builder.append_escaped_for_json(properties.custom_properties.serialized());
|
||||
builder.append("\");"sv);
|
||||
|
||||
builder.append("inspector.createFontList(\""sv);
|
||||
builder.append_escaped_for_json(properties.fonts.serialized());
|
||||
builder.append("\");"sv);
|
||||
|
||||
m_inspector_web_view.run_javascript(MUST(builder.to_string()));
|
||||
};
|
||||
|
||||
m_content_web_view.on_received_accessibility_tree = [this](auto const& accessibility_tree) {
|
||||
auto accessibility_tree_html = generate_accessibility_tree(accessibility_tree);
|
||||
auto accessibility_tree_base64 = MUST(encode_base64(accessibility_tree_html.bytes()));
|
||||
|
||||
auto script = MUST(String::formatted("inspector.loadAccessibilityTree(\"{}\");", accessibility_tree_base64));
|
||||
m_inspector_web_view.run_javascript(script);
|
||||
};
|
||||
|
||||
m_content_web_view.on_received_hovered_node_id = [this](auto node_id) {
|
||||
select_node(node_id);
|
||||
};
|
||||
|
||||
m_content_web_view.on_received_style_sheet_list = [this](auto const& style_sheets) {
|
||||
StringBuilder builder;
|
||||
builder.append("inspector.setStyleSheets(["sv);
|
||||
for (auto& style_sheet : style_sheets) {
|
||||
builder.appendff("{}, "sv, style_sheet_identifier_to_json(style_sheet));
|
||||
}
|
||||
builder.append("]);"sv);
|
||||
|
||||
m_inspector_web_view.run_javascript(MUST(builder.to_string()));
|
||||
};
|
||||
|
||||
m_content_web_view.on_received_style_sheet_source = [this](Web::CSS::StyleSheetIdentifier const& identifier, URL::URL const& base_url, String const& source) {
|
||||
auto html = highlight_source(URL::Parser::basic_parse(identifier.url.value_or({})), base_url, source, Syntax::Language::CSS, HighlightOutputMode::SourceOnly);
|
||||
auto script = MUST(String::formatted("inspector.setStyleSheetSource({}, \"{}\");",
|
||||
style_sheet_identifier_to_json(identifier),
|
||||
MUST(encode_base64(html.bytes()))));
|
||||
m_inspector_web_view.run_javascript(script);
|
||||
};
|
||||
|
||||
m_content_web_view.on_finshed_editing_dom_node = [this](auto const& node_id) {
|
||||
m_pending_selection = node_id;
|
||||
m_dom_tree_loaded = false;
|
||||
m_dom_node_attributes.clear();
|
||||
|
||||
inspect();
|
||||
};
|
||||
|
||||
m_content_web_view.on_received_dom_node_html = [this](auto const& html) {
|
||||
if (m_content_web_view.on_insert_clipboard_entry)
|
||||
m_content_web_view.on_insert_clipboard_entry(html, "unspecified"_string, "text/plain"_string);
|
||||
};
|
||||
|
||||
m_content_web_view.on_console_message_available = [this](auto message_index) {
|
||||
console_message_available(message_index);
|
||||
};
|
||||
|
||||
m_content_web_view.on_received_styled_console_messages = [this](auto start_index, auto const& message_types, auto const& messages) {
|
||||
console_messages_received(start_index, message_types, messages);
|
||||
};
|
||||
|
||||
m_inspector_web_view.enable_inspector_prototype();
|
||||
m_inspector_web_view.use_native_user_style_sheet();
|
||||
|
||||
m_inspector_web_view.on_inspector_loaded = [this]() {
|
||||
m_inspector_loaded = true;
|
||||
inspect();
|
||||
|
||||
m_content_web_view.js_console_request_messages(0);
|
||||
};
|
||||
|
||||
m_inspector_web_view.on_inspector_requested_dom_tree_context_menu = [this](auto node_id, auto position, auto const& type, auto const& tag, auto const& attribute_index) {
|
||||
Optional<Attribute> attribute;
|
||||
if (attribute_index.has_value())
|
||||
attribute = m_dom_node_attributes.get(node_id)->at(*attribute_index);
|
||||
|
||||
m_context_menu_data = ContextMenuData { node_id, tag, attribute };
|
||||
|
||||
if (type.is_one_of("text"sv, "comment"sv)) {
|
||||
if (on_requested_dom_node_text_context_menu)
|
||||
on_requested_dom_node_text_context_menu(position);
|
||||
} else if (type == "tag"sv) {
|
||||
VERIFY(tag.has_value());
|
||||
|
||||
if (on_requested_dom_node_tag_context_menu)
|
||||
on_requested_dom_node_tag_context_menu(position, *tag);
|
||||
} else if (type == "attribute"sv) {
|
||||
VERIFY(tag.has_value());
|
||||
VERIFY(attribute.has_value());
|
||||
|
||||
if (on_requested_dom_node_attribute_context_menu)
|
||||
on_requested_dom_node_attribute_context_menu(position, *tag, *attribute);
|
||||
}
|
||||
};
|
||||
|
||||
m_inspector_web_view.on_inspector_selected_dom_node = [this](auto node_id, auto const& pseudo_element) {
|
||||
m_content_web_view.highlight_dom_node(node_id, pseudo_element);
|
||||
m_content_web_view.inspect_dom_node(node_id, pseudo_element);
|
||||
};
|
||||
|
||||
m_inspector_web_view.on_inspector_set_dom_node_text = [this](auto node_id, auto const& text) {
|
||||
m_content_web_view.set_dom_node_text(node_id, text);
|
||||
};
|
||||
|
||||
m_inspector_web_view.on_inspector_set_dom_node_tag = [this](auto node_id, auto const& tag) {
|
||||
m_content_web_view.set_dom_node_tag(node_id, tag);
|
||||
};
|
||||
|
||||
m_inspector_web_view.on_inspector_added_dom_node_attributes = [this](auto node_id, auto const& attributes) {
|
||||
m_content_web_view.add_dom_node_attributes(node_id, attributes);
|
||||
};
|
||||
|
||||
m_inspector_web_view.on_inspector_replaced_dom_node_attribute = [this](auto node_id, u32 attribute_index, auto const& replacement_attributes) {
|
||||
auto const& attribute = m_dom_node_attributes.get(node_id)->at(attribute_index);
|
||||
m_content_web_view.replace_dom_node_attribute(node_id, attribute.name, replacement_attributes);
|
||||
};
|
||||
|
||||
m_inspector_web_view.on_inspector_requested_cookie_context_menu = [this](auto cookie_index, auto position) {
|
||||
if (cookie_index >= m_cookies.size())
|
||||
return;
|
||||
|
||||
m_cookie_context_menu_index = cookie_index;
|
||||
|
||||
if (on_requested_cookie_context_menu)
|
||||
on_requested_cookie_context_menu(position, m_cookies[cookie_index]);
|
||||
};
|
||||
|
||||
m_inspector_web_view.on_inspector_requested_style_sheet_source = [this](auto const& identifier) {
|
||||
m_content_web_view.request_style_sheet_source(identifier);
|
||||
};
|
||||
|
||||
m_inspector_web_view.on_inspector_executed_console_script = [this](auto const& script) {
|
||||
append_console_source(script);
|
||||
|
||||
m_content_web_view.js_console_input(script);
|
||||
};
|
||||
|
||||
m_inspector_web_view.on_inspector_exported_inspector_html = [this](String const& html) {
|
||||
auto maybe_inspector_path = Application::the().path_for_downloaded_file("inspector"sv);
|
||||
|
||||
if (maybe_inspector_path.is_error()) {
|
||||
append_console_warning(MUST(String::formatted("Unable to select a download location: {}", maybe_inspector_path.error())));
|
||||
return;
|
||||
}
|
||||
|
||||
auto inspector_path = maybe_inspector_path.release_value();
|
||||
|
||||
if (auto result = Core::Directory::create(inspector_path.string(), Core::Directory::CreateDirectories::Yes); result.is_error()) {
|
||||
append_console_warning(MUST(String::formatted("Unable to create {}: {}", inspector_path, result.error())));
|
||||
return;
|
||||
}
|
||||
|
||||
auto export_file = [&](auto name, auto const& contents) {
|
||||
auto path = inspector_path.append(name);
|
||||
|
||||
auto file = Core::File::open(path.string(), Core::File::OpenMode::Write);
|
||||
if (file.is_error()) {
|
||||
append_console_warning(MUST(String::formatted("Unable to open {}: {}", path, file.error())));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (auto result = file.value()->write_until_depleted(contents); result.is_error()) {
|
||||
append_console_warning(MUST(String::formatted("Unable to save {}: {}", path, result.error())));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
auto inspector_css = MUST(Core::Resource::load_from_uri(INSPECTOR_CSS));
|
||||
auto inspector_js = MUST(Core::Resource::load_from_uri(INSPECTOR_JS));
|
||||
|
||||
auto inspector_html = MUST(html.replace(INSPECTOR_CSS, "inspector.css"sv, ReplaceMode::All));
|
||||
inspector_html = MUST(inspector_html.replace(INSPECTOR_JS, "inspector.js"sv, ReplaceMode::All));
|
||||
|
||||
if (!export_file("inspector.html"sv, inspector_html))
|
||||
return;
|
||||
if (!export_file("inspector.css"sv, inspector_css->data()))
|
||||
return;
|
||||
if (!export_file("inspector.js"sv, inspector_js->data()))
|
||||
return;
|
||||
|
||||
append_console_message(MUST(String::formatted("Exported Inspector files to {}", inspector_path)));
|
||||
};
|
||||
|
||||
load_inspector();
|
||||
}
|
||||
|
||||
InspectorClient::~InspectorClient()
|
||||
{
|
||||
m_content_web_view.on_finshed_editing_dom_node = nullptr;
|
||||
m_content_web_view.on_received_accessibility_tree = nullptr;
|
||||
m_content_web_view.on_console_message_available = nullptr;
|
||||
m_content_web_view.on_received_styled_console_messages = nullptr;
|
||||
m_content_web_view.on_received_dom_node_html = nullptr;
|
||||
m_content_web_view.on_received_dom_node_properties = nullptr;
|
||||
m_content_web_view.on_received_dom_tree = nullptr;
|
||||
m_content_web_view.on_received_hovered_node_id = nullptr;
|
||||
m_content_web_view.on_received_style_sheet_list = nullptr;
|
||||
m_content_web_view.on_inspector_requested_style_sheet_source = nullptr;
|
||||
}
|
||||
|
||||
void InspectorClient::inspect()
|
||||
{
|
||||
if (!m_inspector_loaded)
|
||||
return;
|
||||
|
||||
m_content_web_view.inspect_dom_tree();
|
||||
m_content_web_view.inspect_accessibility_tree();
|
||||
m_content_web_view.list_style_sheets();
|
||||
load_cookies();
|
||||
}
|
||||
|
||||
void InspectorClient::reset()
|
||||
{
|
||||
static auto script = "inspector.reset();"_string;
|
||||
m_inspector_web_view.run_javascript(script);
|
||||
|
||||
m_body_or_frameset_node_id.clear();
|
||||
m_pending_selection.clear();
|
||||
m_dom_tree_loaded = false;
|
||||
|
||||
m_dom_node_attributes.clear();
|
||||
|
||||
m_highest_notified_message_index = -1;
|
||||
m_highest_received_message_index = -1;
|
||||
m_waiting_for_messages = false;
|
||||
}
|
||||
|
||||
void InspectorClient::select_hovered_node()
|
||||
{
|
||||
m_content_web_view.get_hovered_node_id();
|
||||
}
|
||||
|
||||
void InspectorClient::select_default_node()
|
||||
{
|
||||
if (m_body_or_frameset_node_id.has_value())
|
||||
select_node(*m_body_or_frameset_node_id);
|
||||
}
|
||||
|
||||
void InspectorClient::clear_selection()
|
||||
{
|
||||
m_content_web_view.clear_highlighted_dom_node();
|
||||
m_content_web_view.clear_inspected_dom_node();
|
||||
|
||||
static auto script = "inspector.clearInspectedDOMNode();"_string;
|
||||
m_inspector_web_view.run_javascript(script);
|
||||
}
|
||||
|
||||
void InspectorClient::select_node(Web::UniqueNodeID node_id)
|
||||
{
|
||||
if (!m_dom_tree_loaded) {
|
||||
m_pending_selection = node_id;
|
||||
return;
|
||||
}
|
||||
|
||||
auto script = MUST(String::formatted("inspector.inspectDOMNodeID({});", node_id.value()));
|
||||
m_inspector_web_view.run_javascript(script);
|
||||
}
|
||||
|
||||
void InspectorClient::load_cookies()
|
||||
{
|
||||
m_cookies = Application::cookie_jar().get_all_cookies(m_content_web_view.url());
|
||||
JsonArray json_cookies;
|
||||
|
||||
for (auto const& [index, cookie] : enumerate(m_cookies)) {
|
||||
JsonObject json_cookie;
|
||||
|
||||
json_cookie.set("index"sv, JsonValue { index });
|
||||
json_cookie.set("name"sv, JsonValue { cookie.name });
|
||||
json_cookie.set("value"sv, JsonValue { cookie.value });
|
||||
json_cookie.set("domain"sv, JsonValue { cookie.domain });
|
||||
json_cookie.set("path"sv, JsonValue { cookie.path });
|
||||
json_cookie.set("creationTime"sv, JsonValue { cookie.creation_time.milliseconds_since_epoch() });
|
||||
json_cookie.set("lastAccessTime"sv, JsonValue { cookie.last_access_time.milliseconds_since_epoch() });
|
||||
json_cookie.set("expiryTime"sv, JsonValue { cookie.expiry_time.milliseconds_since_epoch() });
|
||||
|
||||
MUST(json_cookies.append(move(json_cookie)));
|
||||
}
|
||||
|
||||
StringBuilder builder;
|
||||
builder.append("inspector.setCookies("sv);
|
||||
json_cookies.serialize(builder);
|
||||
builder.append(");"sv);
|
||||
|
||||
m_inspector_web_view.run_javascript(MUST(builder.to_string()));
|
||||
}
|
||||
|
||||
void InspectorClient::context_menu_edit_dom_node()
|
||||
{
|
||||
VERIFY(m_context_menu_data.has_value());
|
||||
|
||||
auto script = MUST(String::formatted("inspector.editDOMNodeID({});", m_context_menu_data->dom_node_id));
|
||||
m_inspector_web_view.run_javascript(script);
|
||||
|
||||
m_context_menu_data.clear();
|
||||
}
|
||||
|
||||
void InspectorClient::context_menu_copy_dom_node()
|
||||
{
|
||||
VERIFY(m_context_menu_data.has_value());
|
||||
|
||||
m_content_web_view.get_dom_node_outer_html(m_context_menu_data->dom_node_id);
|
||||
m_context_menu_data.clear();
|
||||
}
|
||||
|
||||
void InspectorClient::context_menu_screenshot_dom_node()
|
||||
{
|
||||
VERIFY(m_context_menu_data.has_value());
|
||||
|
||||
m_content_web_view.take_dom_node_screenshot(m_context_menu_data->dom_node_id)
|
||||
->when_resolved([this](auto const& path) {
|
||||
append_console_message(MUST(String::formatted("Screenshot saved to: {}", path)));
|
||||
})
|
||||
.when_rejected([this](auto const& error) {
|
||||
append_console_warning(MUST(String::formatted("Warning: {}", error)));
|
||||
});
|
||||
|
||||
m_context_menu_data.clear();
|
||||
}
|
||||
|
||||
void InspectorClient::context_menu_create_child_element()
|
||||
{
|
||||
VERIFY(m_context_menu_data.has_value());
|
||||
|
||||
m_content_web_view.create_child_element(m_context_menu_data->dom_node_id);
|
||||
m_context_menu_data.clear();
|
||||
}
|
||||
|
||||
void InspectorClient::context_menu_create_child_text_node()
|
||||
{
|
||||
VERIFY(m_context_menu_data.has_value());
|
||||
|
||||
m_content_web_view.create_child_text_node(m_context_menu_data->dom_node_id);
|
||||
m_context_menu_data.clear();
|
||||
}
|
||||
|
||||
void InspectorClient::context_menu_clone_dom_node()
|
||||
{
|
||||
VERIFY(m_context_menu_data.has_value());
|
||||
|
||||
m_content_web_view.clone_dom_node(m_context_menu_data->dom_node_id);
|
||||
m_context_menu_data.clear();
|
||||
}
|
||||
|
||||
void InspectorClient::context_menu_remove_dom_node()
|
||||
{
|
||||
VERIFY(m_context_menu_data.has_value());
|
||||
|
||||
m_content_web_view.remove_dom_node(m_context_menu_data->dom_node_id);
|
||||
m_context_menu_data.clear();
|
||||
}
|
||||
|
||||
void InspectorClient::context_menu_add_dom_node_attribute()
|
||||
{
|
||||
VERIFY(m_context_menu_data.has_value());
|
||||
|
||||
auto script = MUST(String::formatted("inspector.addAttributeToDOMNodeID({});", m_context_menu_data->dom_node_id));
|
||||
m_inspector_web_view.run_javascript(script);
|
||||
|
||||
m_context_menu_data.clear();
|
||||
}
|
||||
|
||||
void InspectorClient::context_menu_remove_dom_node_attribute()
|
||||
{
|
||||
VERIFY(m_context_menu_data.has_value());
|
||||
VERIFY(m_context_menu_data->attribute.has_value());
|
||||
|
||||
m_content_web_view.replace_dom_node_attribute(m_context_menu_data->dom_node_id, m_context_menu_data->attribute->name, {});
|
||||
m_context_menu_data.clear();
|
||||
}
|
||||
|
||||
void InspectorClient::context_menu_copy_dom_node_attribute_value()
|
||||
{
|
||||
VERIFY(m_context_menu_data.has_value());
|
||||
VERIFY(m_context_menu_data->attribute.has_value());
|
||||
|
||||
if (m_content_web_view.on_insert_clipboard_entry)
|
||||
m_content_web_view.on_insert_clipboard_entry(m_context_menu_data->attribute->value, "unspecified"_string, "text/plain"_string);
|
||||
|
||||
m_context_menu_data.clear();
|
||||
}
|
||||
|
||||
void InspectorClient::context_menu_delete_cookie()
|
||||
{
|
||||
VERIFY(m_cookie_context_menu_index.has_value());
|
||||
VERIFY(*m_cookie_context_menu_index < m_cookies.size());
|
||||
|
||||
auto& cookie = m_cookies[*m_cookie_context_menu_index];
|
||||
cookie.expiry_time = UnixDateTime::earliest();
|
||||
|
||||
Application::cookie_jar().update_cookie(move(cookie));
|
||||
load_cookies();
|
||||
|
||||
m_cookie_context_menu_index.clear();
|
||||
}
|
||||
|
||||
void InspectorClient::context_menu_delete_all_cookies()
|
||||
{
|
||||
for (auto& cookie : m_cookies) {
|
||||
cookie.expiry_time = UnixDateTime::earliest();
|
||||
|
||||
Application::cookie_jar().update_cookie(move(cookie));
|
||||
}
|
||||
|
||||
load_cookies();
|
||||
|
||||
m_cookie_context_menu_index.clear();
|
||||
}
|
||||
|
||||
void InspectorClient::load_inspector()
|
||||
{
|
||||
auto inspector_html = MUST(Core::Resource::load_from_uri(INSPECTOR_HTML));
|
||||
|
||||
auto generate_property_table = [&](auto name) {
|
||||
return MUST(String::formatted(R"~~~(
|
||||
<div id="{0}" class="tab-content">
|
||||
<input class="property-filter" id="{0}-filter" placeholder="Filter properties" />
|
||||
<table class="property-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Value</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="{0}-table">
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)~~~",
|
||||
name));
|
||||
};
|
||||
|
||||
StringBuilder builder;
|
||||
|
||||
SourceGenerator generator { builder };
|
||||
generator.set("INSPECTOR_CSS"sv, INSPECTOR_CSS);
|
||||
generator.set("INSPECTOR_JS"sv, INSPECTOR_JS);
|
||||
generator.set("INSPECTOR_STYLE"sv, HTML_HIGHLIGHTER_STYLE);
|
||||
generator.set("COMPUTED_STYLE"sv, generate_property_table("computed-style"sv));
|
||||
generator.set("RESOVLED_STYLE"sv, generate_property_table("resolved-style"sv));
|
||||
generator.set("CUSTOM_PROPERTIES"sv, generate_property_table("custom-properties"sv));
|
||||
generator.append(inspector_html->data());
|
||||
|
||||
m_inspector_web_view.load_html(generator.as_string_view());
|
||||
}
|
||||
|
||||
template<typename Generator>
|
||||
static void generate_tree(StringBuilder& builder, JsonObject const& node, Generator&& generator)
|
||||
{
|
||||
if (auto children = node.get_array("children"sv); children.has_value() && !children->is_empty()) {
|
||||
auto name = node.get_string("name"sv).value_or({});
|
||||
builder.append("<details>"sv);
|
||||
|
||||
builder.append("<summary>"sv);
|
||||
generator(node);
|
||||
builder.append("</summary>"sv);
|
||||
|
||||
children->for_each([&](auto const& child) {
|
||||
builder.append("<div>"sv);
|
||||
generate_tree(builder, child.as_object(), generator);
|
||||
builder.append("</div>"sv);
|
||||
});
|
||||
|
||||
builder.append("</details>"sv);
|
||||
} else {
|
||||
generator(node);
|
||||
}
|
||||
}
|
||||
|
||||
String InspectorClient::generate_dom_tree(JsonObject const& dom_tree)
|
||||
{
|
||||
StringBuilder builder;
|
||||
|
||||
generate_tree(builder, dom_tree, [&](JsonObject const& node) {
|
||||
auto type = node.get_string("type"sv).value_or("unknown"_string);
|
||||
auto name = node.get_string("name"sv).value_or({});
|
||||
|
||||
StringBuilder data_attributes;
|
||||
auto append_data_attribute = [&](auto name, auto value) {
|
||||
if (!data_attributes.is_empty())
|
||||
data_attributes.append(' ');
|
||||
data_attributes.appendff("data-{}=\"{}\"", name, value);
|
||||
};
|
||||
|
||||
i32 node_id = 0;
|
||||
|
||||
if (auto pseudo_element = node.get_integer<i32>("pseudo-element"sv); pseudo_element.has_value()) {
|
||||
node_id = node.get_integer<i32>("parent-id"sv).value();
|
||||
append_data_attribute("pseudo-element"sv, *pseudo_element);
|
||||
} else {
|
||||
node_id = node.get_integer<i32>("id"sv).value();
|
||||
}
|
||||
|
||||
append_data_attribute("id"sv, node_id);
|
||||
|
||||
if (type == "text"sv) {
|
||||
auto deprecated_text = escape_html_entities(*node.get_string("text"sv));
|
||||
auto text = MUST(Web::Infra::strip_and_collapse_whitespace(deprecated_text));
|
||||
|
||||
builder.appendff("<span data-node-type=\"text\" class=\"hoverable editable\" {}>", data_attributes.string_view());
|
||||
|
||||
if (text.is_empty())
|
||||
builder.appendff("<span class=\"internal\">{}</span>", name);
|
||||
else
|
||||
builder.append(text);
|
||||
|
||||
builder.append("</span>"sv);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == "comment"sv) {
|
||||
auto comment = escape_html_entities(*node.get_string("data"sv));
|
||||
|
||||
builder.appendff("<span class=\"hoverable comment\" {}>", data_attributes.string_view());
|
||||
builder.append("<span><!--</span>"sv);
|
||||
builder.appendff("<span data-node-type=\"comment\" class=\"editable\">{}</span>", comment);
|
||||
builder.append("<span>--></span>"sv);
|
||||
builder.append("</span>"sv);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == "shadow-root"sv) {
|
||||
auto mode = node.get_string("mode"sv).release_value();
|
||||
|
||||
builder.appendff("<span class=\"hoverable internal\" {}>", data_attributes.string_view());
|
||||
builder.appendff("{} ({})", name, mode);
|
||||
builder.append("</span>"sv);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type != "element"sv) {
|
||||
builder.appendff("<span class=\"hoverable internal\" {}>", data_attributes.string_view());
|
||||
builder.appendff(name);
|
||||
} else {
|
||||
if (name.equals_ignoring_ascii_case("BODY"sv) || name.equals_ignoring_ascii_case("FRAMESET"sv))
|
||||
m_body_or_frameset_node_id = node_id;
|
||||
|
||||
auto tag = name;
|
||||
if (node.get_string("namespace"sv) == Web::Namespace::HTML.bytes_as_string_view())
|
||||
tag = MUST(tag.to_lowercase());
|
||||
|
||||
builder.appendff("<span class=\"hoverable\" {}>", data_attributes.string_view());
|
||||
builder.append("<span><</span>"sv);
|
||||
builder.appendff("<span data-node-type=\"tag\" data-tag=\"{0}\" class=\"editable tag\">{0}</span>", tag);
|
||||
|
||||
if (auto attributes = node.get_object("attributes"sv); attributes.has_value()) {
|
||||
attributes->for_each_member([&](auto const& name, auto const& value) {
|
||||
auto& dom_node_attributes = m_dom_node_attributes.ensure(node_id);
|
||||
auto value_string = value.as_string();
|
||||
|
||||
builder.append(" "sv);
|
||||
builder.appendff("<span data-node-type=\"attribute\" data-tag=\"{}\" data-attribute-index={} class=\"editable\">", tag, dom_node_attributes.size());
|
||||
builder.appendff("<span class=\"attribute-name\">{}</span>", escape_html_entities(name));
|
||||
builder.append('=');
|
||||
builder.appendff("<span class=\"attribute-value\">\"{}\"</span>", escape_html_entities(value_string));
|
||||
builder.append("</span>"sv);
|
||||
|
||||
dom_node_attributes.empend(name, value_string);
|
||||
});
|
||||
}
|
||||
|
||||
builder.append("<span>></span>"sv);
|
||||
}
|
||||
|
||||
// display miscellaneous extra bits of info about the element
|
||||
Vector<String> extra;
|
||||
if (node.get_bool("scrollable"sv).value_or(false)) {
|
||||
extra.append("scrollable"_string);
|
||||
}
|
||||
if (node.get_bool("invisible"sv).value_or(false)) {
|
||||
extra.append("invisible"_string);
|
||||
}
|
||||
if (node.get_bool("stackingContext"sv).value_or(false)) {
|
||||
extra.append("isolated"_string);
|
||||
}
|
||||
if (!extra.is_empty()) {
|
||||
builder.append(" <span>("sv);
|
||||
builder.append(extra[0]);
|
||||
for (size_t i = 1; i < extra.size(); i++) {
|
||||
builder.appendff(", {}", extra[i]);
|
||||
}
|
||||
builder.append(")</span>"sv);
|
||||
}
|
||||
|
||||
builder.append("</span>"sv);
|
||||
});
|
||||
|
||||
return MUST(builder.to_string());
|
||||
}
|
||||
|
||||
String InspectorClient::generate_accessibility_tree(JsonObject const& accessibility_tree)
|
||||
{
|
||||
StringBuilder builder;
|
||||
|
||||
generate_tree(builder, accessibility_tree, [&](JsonObject const& node) {
|
||||
auto type = node.get_string("type"sv).value_or("unknown"_string);
|
||||
auto role = node.get_string("role"sv).value_or({});
|
||||
|
||||
if (type == "text"sv) {
|
||||
auto text = escape_html_entities(*node.get_string("text"sv));
|
||||
|
||||
builder.appendff("<span class=\"hoverable\">");
|
||||
builder.append(MUST(Web::Infra::strip_and_collapse_whitespace(text)));
|
||||
builder.append("</span>"sv);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type != "element"sv) {
|
||||
builder.appendff("<span class=\"hoverable internal\">");
|
||||
builder.appendff(MUST(role.to_lowercase()));
|
||||
builder.append("</span>"sv);
|
||||
return;
|
||||
}
|
||||
|
||||
auto name = node.get_string("name"sv).value_or({});
|
||||
auto description = node.get_string("description"sv).value_or({});
|
||||
|
||||
builder.appendff("<span class=\"hoverable\">");
|
||||
builder.append(MUST(role.to_lowercase()));
|
||||
builder.appendff(" name: \"{}\", description: \"{}\"", name, description);
|
||||
builder.append("</span>"sv);
|
||||
});
|
||||
|
||||
return MUST(builder.to_string());
|
||||
}
|
||||
|
||||
void InspectorClient::request_console_messages()
|
||||
{
|
||||
VERIFY(!m_waiting_for_messages);
|
||||
|
||||
m_content_web_view.js_console_request_messages(m_highest_received_message_index + 1);
|
||||
m_waiting_for_messages = true;
|
||||
}
|
||||
|
||||
void InspectorClient::console_message_available(i32 message_index)
|
||||
{
|
||||
if (message_index <= m_highest_received_message_index) {
|
||||
dbgln("Notified about console message we already have");
|
||||
return;
|
||||
}
|
||||
if (message_index <= m_highest_notified_message_index) {
|
||||
dbgln("Notified about console message we're already aware of");
|
||||
return;
|
||||
}
|
||||
|
||||
m_highest_notified_message_index = message_index;
|
||||
|
||||
if (!m_waiting_for_messages)
|
||||
request_console_messages();
|
||||
}
|
||||
|
||||
void InspectorClient::console_messages_received(i32 start_index, ReadonlySpan<String> message_types, ReadonlySpan<String> messages)
|
||||
{
|
||||
auto end_index = start_index + static_cast<i32>(message_types.size()) - 1;
|
||||
if (end_index <= m_highest_received_message_index) {
|
||||
dbgln("Received old console messages");
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < message_types.size(); ++i) {
|
||||
auto const& type = message_types[i];
|
||||
auto const& message = messages[i];
|
||||
|
||||
if (type == "html"sv)
|
||||
append_console_output(message);
|
||||
else if (type == "clear"sv)
|
||||
clear_console_output();
|
||||
else if (type == "group"sv)
|
||||
begin_console_group(message, true);
|
||||
else if (type == "groupCollapsed"sv)
|
||||
begin_console_group(message, false);
|
||||
else if (type == "groupEnd"sv)
|
||||
end_console_group();
|
||||
else
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
m_highest_received_message_index = end_index;
|
||||
m_waiting_for_messages = false;
|
||||
|
||||
if (m_highest_received_message_index < m_highest_notified_message_index)
|
||||
request_console_messages();
|
||||
}
|
||||
|
||||
void InspectorClient::append_console_source(StringView source)
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.append("<span class=\"console-prompt\">> </span>"sv);
|
||||
builder.append(MUST(JS::MarkupGenerator::html_from_source(source)));
|
||||
|
||||
append_console_output(builder.string_view());
|
||||
}
|
||||
|
||||
void InspectorClient::append_console_message(StringView message)
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.append("<span class=\"console-prompt\"># </span>"sv);
|
||||
builder.appendff("<span class=\"console-message\">{}</span>", message);
|
||||
|
||||
append_console_output(builder.string_view());
|
||||
}
|
||||
|
||||
void InspectorClient::append_console_warning(StringView warning)
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.append("<span class=\"console-prompt\"># </span>"sv);
|
||||
builder.appendff("<span class=\"console-warning\">{}</span>", warning);
|
||||
|
||||
append_console_output(builder.string_view());
|
||||
}
|
||||
|
||||
void InspectorClient::append_console_output(StringView html)
|
||||
{
|
||||
auto html_base64 = MUST(encode_base64(html.bytes()));
|
||||
|
||||
auto script = MUST(String::formatted("inspector.appendConsoleOutput(\"{}\");", html_base64));
|
||||
m_inspector_web_view.run_javascript(script);
|
||||
}
|
||||
|
||||
void InspectorClient::clear_console_output()
|
||||
{
|
||||
static auto script = "inspector.clearConsoleOutput();"_string;
|
||||
m_inspector_web_view.run_javascript(script);
|
||||
}
|
||||
|
||||
void InspectorClient::begin_console_group(StringView label, bool start_expanded)
|
||||
{
|
||||
auto label_base64 = MUST(encode_base64(label.bytes()));
|
||||
|
||||
auto script = MUST(String::formatted("inspector.beginConsoleGroup(\"{}\", {});", label_base64, start_expanded));
|
||||
m_inspector_web_view.run_javascript(script);
|
||||
}
|
||||
|
||||
void InspectorClient::end_console_group()
|
||||
{
|
||||
static auto script = "inspector.endConsoleGroup();"_string;
|
||||
m_inspector_web_view.run_javascript(script);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Function.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/JsonValue.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibGfx/Point.h>
|
||||
#include <LibWebView/Attribute.h>
|
||||
#include <LibWebView/ViewImplementation.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace WebView {
|
||||
|
||||
class InspectorClient {
|
||||
public:
|
||||
InspectorClient(ViewImplementation& content_web_view, ViewImplementation& inspector_web_view);
|
||||
~InspectorClient();
|
||||
|
||||
void inspect();
|
||||
void reset();
|
||||
|
||||
void select_hovered_node();
|
||||
void select_default_node();
|
||||
void clear_selection();
|
||||
|
||||
void context_menu_edit_dom_node();
|
||||
void context_menu_copy_dom_node();
|
||||
void context_menu_screenshot_dom_node();
|
||||
void context_menu_create_child_element();
|
||||
void context_menu_create_child_text_node();
|
||||
void context_menu_clone_dom_node();
|
||||
void context_menu_remove_dom_node();
|
||||
void context_menu_add_dom_node_attribute();
|
||||
void context_menu_remove_dom_node_attribute();
|
||||
void context_menu_copy_dom_node_attribute_value();
|
||||
void context_menu_delete_cookie();
|
||||
void context_menu_delete_all_cookies();
|
||||
|
||||
Function<void(Gfx::IntPoint)> on_requested_dom_node_text_context_menu;
|
||||
Function<void(Gfx::IntPoint, String const&)> on_requested_dom_node_tag_context_menu;
|
||||
Function<void(Gfx::IntPoint, String const&, Attribute const&)> on_requested_dom_node_attribute_context_menu;
|
||||
Function<void(Gfx::IntPoint, Web::Cookie::Cookie const&)> on_requested_cookie_context_menu;
|
||||
|
||||
private:
|
||||
void load_inspector();
|
||||
|
||||
String generate_dom_tree(JsonObject const&);
|
||||
String generate_accessibility_tree(JsonObject const&);
|
||||
void select_node(Web::UniqueNodeID);
|
||||
|
||||
void load_cookies();
|
||||
|
||||
void request_console_messages();
|
||||
void console_message_available(i32 message_index);
|
||||
void console_messages_received(i32 start_index, ReadonlySpan<String> message_types, ReadonlySpan<String> messages);
|
||||
|
||||
void append_console_source(StringView);
|
||||
void append_console_message(StringView);
|
||||
void append_console_warning(StringView);
|
||||
void append_console_output(StringView);
|
||||
void clear_console_output();
|
||||
|
||||
void begin_console_group(StringView label, bool start_expanded);
|
||||
void end_console_group();
|
||||
|
||||
ViewImplementation& m_content_web_view;
|
||||
ViewImplementation& m_inspector_web_view;
|
||||
|
||||
Optional<Web::UniqueNodeID> m_body_or_frameset_node_id;
|
||||
Optional<Web::UniqueNodeID> m_pending_selection;
|
||||
|
||||
bool m_inspector_loaded { false };
|
||||
bool m_dom_tree_loaded { false };
|
||||
|
||||
struct ContextMenuData {
|
||||
Web::UniqueNodeID dom_node_id;
|
||||
Optional<String> tag;
|
||||
Optional<Attribute> attribute;
|
||||
};
|
||||
Optional<ContextMenuData> m_context_menu_data;
|
||||
|
||||
HashMap<Web::UniqueNodeID, Vector<Attribute>> m_dom_node_attributes;
|
||||
|
||||
Vector<Web::Cookie::Cookie> m_cookies;
|
||||
Optional<size_t> m_cookie_context_menu_index;
|
||||
|
||||
i32 m_highest_notified_message_index { -1 };
|
||||
i32 m_highest_received_message_index { -1 };
|
||||
bool m_waiting_for_messages { false };
|
||||
};
|
||||
|
||||
}
|
|
@ -779,9 +779,4 @@ void ViewImplementation::use_native_user_style_sheet()
|
|||
set_user_style_sheet(native_stylesheet_source);
|
||||
}
|
||||
|
||||
void ViewImplementation::enable_inspector_prototype()
|
||||
{
|
||||
client().async_enable_inspector_prototype(page_id());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -180,8 +180,6 @@ public:
|
|||
// native GUI widgets as possible.
|
||||
void use_native_user_style_sheet();
|
||||
|
||||
void enable_inspector_prototype();
|
||||
|
||||
Function<void()> on_ready_to_paint;
|
||||
Function<String(Web::HTML::ActivateTab, Web::HTML::WebViewHints, Optional<u64>)> on_new_web_view;
|
||||
Function<void()> on_activate_tab;
|
||||
|
@ -215,13 +213,12 @@ public:
|
|||
Function<void(JsonObject)> on_received_dom_tree;
|
||||
Function<void(DOMNodeProperties)> on_received_dom_node_properties;
|
||||
Function<void(JsonObject)> on_received_accessibility_tree;
|
||||
Function<void(Vector<Web::CSS::StyleSheetIdentifier>)> on_received_style_sheet_list;
|
||||
Function<void(Web::CSS::StyleSheetIdentifier const&)> on_inspector_requested_style_sheet_source;
|
||||
Function<void(Web::CSS::StyleSheetIdentifier const&, URL::URL const&, String const&)> on_received_style_sheet_source;
|
||||
Function<void(Web::UniqueNodeID)> on_received_hovered_node_id;
|
||||
Function<void(Mutation)> on_dom_mutation_received;
|
||||
Function<void(Optional<Web::UniqueNodeID> const& node_id)> on_finshed_editing_dom_node;
|
||||
Function<void(String)> on_received_dom_node_html;
|
||||
Function<void(Vector<Web::CSS::StyleSheetIdentifier>)> on_received_style_sheet_list;
|
||||
Function<void(Web::CSS::StyleSheetIdentifier const&, URL::URL const&, String const&)> on_received_style_sheet_source;
|
||||
Function<void(JsonValue)> on_received_js_console_result;
|
||||
Function<void(i32 message_id)> on_console_message_available;
|
||||
Function<void(i32 start_index, Vector<String> const& message_types, Vector<String> const& messages)> on_received_styled_console_messages;
|
||||
|
@ -246,16 +243,6 @@ public:
|
|||
Function<void(String const&, String const&, String const&)> on_insert_clipboard_entry;
|
||||
Function<void(Web::HTML::AudioPlayState)> on_audio_play_state_changed;
|
||||
Function<void(bool, bool)> on_navigation_buttons_state_changed;
|
||||
Function<void()> on_inspector_loaded;
|
||||
Function<void(Web::UniqueNodeID, Optional<Web::CSS::Selector::PseudoElement::Type> const&)> on_inspector_selected_dom_node;
|
||||
Function<void(Web::UniqueNodeID, String const&)> on_inspector_set_dom_node_text;
|
||||
Function<void(Web::UniqueNodeID, String const&)> on_inspector_set_dom_node_tag;
|
||||
Function<void(Web::UniqueNodeID, Vector<Attribute> const&)> on_inspector_added_dom_node_attributes;
|
||||
Function<void(Web::UniqueNodeID, size_t, Vector<Attribute> const&)> on_inspector_replaced_dom_node_attribute;
|
||||
Function<void(Web::UniqueNodeID, Gfx::IntPoint, String const&, Optional<String> const&, Optional<size_t> const&)> on_inspector_requested_dom_tree_context_menu;
|
||||
Function<void(size_t, Gfx::IntPoint)> on_inspector_requested_cookie_context_menu;
|
||||
Function<void(String const&)> on_inspector_executed_console_script;
|
||||
Function<void(String const&)> on_inspector_exported_inspector_html;
|
||||
Function<void()> on_web_content_crashed;
|
||||
|
||||
virtual Web::DevicePixelSize viewport_size() const = 0;
|
||||
|
|
|
@ -375,6 +375,22 @@ void WebContentClient::did_get_dom_node_html(u64 page_id, String html)
|
|||
}
|
||||
}
|
||||
|
||||
void WebContentClient::did_list_style_sheets(u64 page_id, Vector<Web::CSS::StyleSheetIdentifier> stylesheets)
|
||||
{
|
||||
if (auto view = view_for_page_id(page_id); view.has_value()) {
|
||||
if (view->on_received_style_sheet_list)
|
||||
view->on_received_style_sheet_list(stylesheets);
|
||||
}
|
||||
}
|
||||
|
||||
void WebContentClient::did_get_style_sheet_source(u64 page_id, Web::CSS::StyleSheetIdentifier identifier, URL::URL base_url, String source)
|
||||
{
|
||||
if (auto view = view_for_page_id(page_id); view.has_value()) {
|
||||
if (view->on_received_style_sheet_source)
|
||||
view->on_received_style_sheet_source(identifier, base_url, source);
|
||||
}
|
||||
}
|
||||
|
||||
void WebContentClient::did_take_screenshot(u64 page_id, Gfx::ShareableBitmap screenshot)
|
||||
{
|
||||
if (auto view = view_for_page_id(page_id); view.has_value())
|
||||
|
@ -664,86 +680,6 @@ void WebContentClient::did_allocate_backing_stores(u64 page_id, i32 front_bitmap
|
|||
view->did_allocate_backing_stores({}, front_bitmap_id, front_bitmap, back_bitmap_id, back_bitmap);
|
||||
}
|
||||
|
||||
void WebContentClient::inspector_did_load(u64 page_id)
|
||||
{
|
||||
if (auto view = view_for_page_id(page_id); view.has_value()) {
|
||||
if (view->on_inspector_loaded)
|
||||
view->on_inspector_loaded();
|
||||
}
|
||||
}
|
||||
|
||||
void WebContentClient::inspector_did_select_dom_node(u64 page_id, Web::UniqueNodeID node_id, Optional<Web::CSS::Selector::PseudoElement::Type> pseudo_element)
|
||||
{
|
||||
if (auto view = view_for_page_id(page_id); view.has_value()) {
|
||||
if (view->on_inspector_selected_dom_node)
|
||||
view->on_inspector_selected_dom_node(node_id, pseudo_element);
|
||||
}
|
||||
}
|
||||
|
||||
void WebContentClient::inspector_did_set_dom_node_text(u64 page_id, Web::UniqueNodeID node_id, String text)
|
||||
{
|
||||
if (auto view = view_for_page_id(page_id); view.has_value()) {
|
||||
if (view->on_inspector_set_dom_node_text)
|
||||
view->on_inspector_set_dom_node_text(node_id, text);
|
||||
}
|
||||
}
|
||||
|
||||
void WebContentClient::inspector_did_set_dom_node_tag(u64 page_id, Web::UniqueNodeID node_id, String tag)
|
||||
{
|
||||
if (auto view = view_for_page_id(page_id); view.has_value()) {
|
||||
if (view->on_inspector_set_dom_node_tag)
|
||||
view->on_inspector_set_dom_node_tag(node_id, tag);
|
||||
}
|
||||
}
|
||||
|
||||
void WebContentClient::inspector_did_add_dom_node_attributes(u64 page_id, Web::UniqueNodeID node_id, Vector<Attribute> attributes)
|
||||
{
|
||||
if (auto view = view_for_page_id(page_id); view.has_value()) {
|
||||
if (view->on_inspector_added_dom_node_attributes)
|
||||
view->on_inspector_added_dom_node_attributes(node_id, attributes);
|
||||
}
|
||||
}
|
||||
|
||||
void WebContentClient::inspector_did_replace_dom_node_attribute(u64 page_id, Web::UniqueNodeID node_id, size_t attribute_index, Vector<Attribute> replacement_attributes)
|
||||
{
|
||||
if (auto view = view_for_page_id(page_id); view.has_value()) {
|
||||
if (view->on_inspector_replaced_dom_node_attribute)
|
||||
view->on_inspector_replaced_dom_node_attribute(node_id, attribute_index, replacement_attributes);
|
||||
}
|
||||
}
|
||||
|
||||
void WebContentClient::inspector_did_request_dom_tree_context_menu(u64 page_id, Web::UniqueNodeID node_id, Gfx::IntPoint position, String type, Optional<String> tag, Optional<size_t> attribute_index)
|
||||
{
|
||||
if (auto view = view_for_page_id(page_id); view.has_value()) {
|
||||
if (view->on_inspector_requested_dom_tree_context_menu)
|
||||
view->on_inspector_requested_dom_tree_context_menu(node_id, view->to_widget_position(position), type, tag, attribute_index);
|
||||
}
|
||||
}
|
||||
|
||||
void WebContentClient::inspector_did_request_cookie_context_menu(u64 page_id, size_t cookie_index, Gfx::IntPoint position)
|
||||
{
|
||||
if (auto view = view_for_page_id(page_id); view.has_value()) {
|
||||
if (view->on_inspector_requested_cookie_context_menu)
|
||||
view->on_inspector_requested_cookie_context_menu(cookie_index, view->to_widget_position(position));
|
||||
}
|
||||
}
|
||||
|
||||
void WebContentClient::inspector_did_execute_console_script(u64 page_id, String script)
|
||||
{
|
||||
if (auto view = view_for_page_id(page_id); view.has_value()) {
|
||||
if (view->on_inspector_executed_console_script)
|
||||
view->on_inspector_executed_console_script(script);
|
||||
}
|
||||
}
|
||||
|
||||
void WebContentClient::inspector_did_export_inspector_html(u64 page_id, String html)
|
||||
{
|
||||
if (auto view = view_for_page_id(page_id); view.has_value()) {
|
||||
if (view->on_inspector_exported_inspector_html)
|
||||
view->on_inspector_exported_inspector_html(html);
|
||||
}
|
||||
}
|
||||
|
||||
Messages::WebContentClient::RequestWorkerAgentResponse WebContentClient::request_worker_agent(u64 page_id)
|
||||
{
|
||||
if (auto view = view_for_page_id(page_id); view.has_value()) {
|
||||
|
@ -754,30 +690,6 @@ Messages::WebContentClient::RequestWorkerAgentResponse WebContentClient::request
|
|||
return IPC::File {};
|
||||
}
|
||||
|
||||
void WebContentClient::inspector_did_list_style_sheets(u64 page_id, Vector<Web::CSS::StyleSheetIdentifier> stylesheets)
|
||||
{
|
||||
if (auto view = view_for_page_id(page_id); view.has_value()) {
|
||||
if (view->on_received_style_sheet_list)
|
||||
view->on_received_style_sheet_list(stylesheets);
|
||||
}
|
||||
}
|
||||
|
||||
void WebContentClient::inspector_did_request_style_sheet_source(u64 page_id, Web::CSS::StyleSheetIdentifier identifier)
|
||||
{
|
||||
if (auto view = view_for_page_id(page_id); view.has_value()) {
|
||||
if (view->on_inspector_requested_style_sheet_source)
|
||||
view->on_inspector_requested_style_sheet_source(identifier);
|
||||
}
|
||||
}
|
||||
|
||||
void WebContentClient::did_get_style_sheet_source(u64 page_id, Web::CSS::StyleSheetIdentifier identifier, URL::URL base_url, String source)
|
||||
{
|
||||
if (auto view = view_for_page_id(page_id); view.has_value()) {
|
||||
if (view->on_received_style_sheet_source)
|
||||
view->on_received_style_sheet_source(identifier, base_url, source);
|
||||
}
|
||||
}
|
||||
|
||||
Optional<ViewImplementation&> WebContentClient::view_for_page_id(u64 page_id, SourceLocation location)
|
||||
{
|
||||
// Don't bother logging anything for the spare WebContent process. It will only receive a load notification for about:blank.
|
||||
|
|
|
@ -83,6 +83,8 @@ private:
|
|||
virtual void did_finish_editing_dom_node(u64 page_id, Optional<Web::UniqueNodeID> node_id) override;
|
||||
virtual void did_mutate_dom(u64 page_id, Mutation) override;
|
||||
virtual void did_get_dom_node_html(u64 page_id, String html) override;
|
||||
virtual void did_list_style_sheets(u64 page_id, Vector<Web::CSS::StyleSheetIdentifier> stylesheets) override;
|
||||
virtual void did_get_style_sheet_source(u64 page_id, Web::CSS::StyleSheetIdentifier identifier, URL::URL, String source) override;
|
||||
virtual void did_take_screenshot(u64 page_id, Gfx::ShareableBitmap screenshot) override;
|
||||
virtual void did_get_internal_page_info(u64 page_id, PageInfoType, String) override;
|
||||
virtual void did_execute_js_console_input(u64 page_id, JsonValue) override;
|
||||
|
@ -126,20 +128,7 @@ private:
|
|||
virtual void did_change_audio_play_state(u64 page_id, Web::HTML::AudioPlayState) override;
|
||||
virtual void did_update_navigation_buttons_state(u64 page_id, bool back_enabled, bool forward_enabled) override;
|
||||
virtual void did_allocate_backing_stores(u64 page_id, i32 front_bitmap_id, Gfx::ShareableBitmap, i32 back_bitmap_id, Gfx::ShareableBitmap) override;
|
||||
virtual void inspector_did_load(u64 page_id) override;
|
||||
virtual void inspector_did_select_dom_node(u64 page_id, Web::UniqueNodeID node_id, Optional<Web::CSS::Selector::PseudoElement::Type> pseudo_element) override;
|
||||
virtual void inspector_did_set_dom_node_text(u64 page_id, Web::UniqueNodeID node_id, String text) override;
|
||||
virtual void inspector_did_set_dom_node_tag(u64 page_id, Web::UniqueNodeID node_id, String tag) override;
|
||||
virtual void inspector_did_add_dom_node_attributes(u64 page_id, Web::UniqueNodeID node_id, Vector<Attribute> attributes) override;
|
||||
virtual void inspector_did_replace_dom_node_attribute(u64 page_id, Web::UniqueNodeID node_id, size_t attribute_index, Vector<Attribute> replacement_attributes) override;
|
||||
virtual void inspector_did_request_dom_tree_context_menu(u64 page_id, Web::UniqueNodeID node_id, Gfx::IntPoint position, String type, Optional<String> tag, Optional<size_t> attribute_index) override;
|
||||
virtual void inspector_did_request_cookie_context_menu(u64 page_id, size_t cookie_index, Gfx::IntPoint position) override;
|
||||
virtual void inspector_did_execute_console_script(u64 page_id, String script) override;
|
||||
virtual void inspector_did_export_inspector_html(u64 page_id, String html) override;
|
||||
virtual Messages::WebContentClient::RequestWorkerAgentResponse request_worker_agent(u64 page_id) override;
|
||||
virtual void inspector_did_list_style_sheets(u64 page_id, Vector<Web::CSS::StyleSheetIdentifier> stylesheets) override;
|
||||
virtual void inspector_did_request_style_sheet_source(u64 page_id, Web::CSS::StyleSheetIdentifier identifier) override;
|
||||
virtual void did_get_style_sheet_source(u64 page_id, Web::CSS::StyleSheetIdentifier identifier, URL::URL, String source) override;
|
||||
|
||||
Optional<ViewImplementation&> view_for_page_id(u64, SourceLocation = SourceLocation::current());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue