#include "third_party/blink/renderer/core/inspector/inspector_dom_agent.h"
#include <memory>
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/renderer/bindings/core/v8/binding_security.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_file.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_html_document.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_node.h"
#include "third_party/blink/renderer/core/css/css_computed_style_declaration.h"
#include "third_party/blink/renderer/core/css/css_container_rule.h"
#include "third_party/blink/renderer/core/css/css_property_name.h"
#include "third_party/blink/renderer/core/css/resolver/style_resolver.h"
#include "third_party/blink/renderer/core/dom/attr.h"
#include "third_party/blink/renderer/core/dom/character_data.h"
#include "third_party/blink/renderer/core/dom/container_node.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/document_fragment.h"
#include "third_party/blink/renderer/core/dom/document_type.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/dom/dom_node_ids.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/dom/flat_tree_traversal.h"
#include "third_party/blink/renderer/core/dom/focus_params.h"
#include "third_party/blink/renderer/core/dom/layout_tree_builder_traversal.h"
#include "third_party/blink/renderer/core/dom/node.h"
#include "third_party/blink/renderer/core/dom/node_computed_style.h"
#include "third_party/blink/renderer/core/dom/pseudo_element.h"
#include "third_party/blink/renderer/core/dom/shadow_root.h"
#include "third_party/blink/renderer/core/dom/static_node_list.h"
#include "third_party/blink/renderer/core/dom/text.h"
#include "third_party/blink/renderer/core/dom/xml_document.h"
#include "third_party/blink/renderer/core/editing/serializers/serialization.h"
#include "third_party/blink/renderer/core/fileapi/file.h"
#include "third_party/blink/renderer/core/frame/frame.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/location.h"
#include "third_party/blink/renderer/core/frame/remote_frame.h"
#include "third_party/blink/renderer/core/html/fenced_frame/document_fenced_frames.h"
#include "third_party/blink/renderer/core/html/fenced_frame/html_fenced_frame_element.h"
#include "third_party/blink/renderer/core/html/forms/html_input_element.h"
#include "third_party/blink/renderer/core/html/html_document.h"
#include "third_party/blink/renderer/core/html/html_frame_owner_element.h"
#include "third_party/blink/renderer/core/html/html_link_element.h"
#include "third_party/blink/renderer/core/html/html_slot_element.h"
#include "third_party/blink/renderer/core/html/html_template_element.h"
#include "third_party/blink/renderer/core/input_type_names.h"
#include "third_party/blink/renderer/core/inspector/dom_editor.h"
#include "third_party/blink/renderer/core/inspector/dom_patch_support.h"
#include "third_party/blink/renderer/core/inspector/identifiers_factory.h"
#include "third_party/blink/renderer/core/inspector/inspected_frames.h"
#include "third_party/blink/renderer/core/inspector/inspector_css_agent.h"
#include "third_party/blink/renderer/core/inspector/inspector_highlight.h"
#include "third_party/blink/renderer/core/inspector/inspector_history.h"
#include "third_party/blink/renderer/core/inspector/resolve_node.h"
#include "third_party/blink/renderer/core/inspector/v8_inspector_string.h"
#include "third_party/blink/renderer/core/layout/hit_test_location.h"
#include "third_party/blink/renderer/core/layout/hit_test_result.h"
#include "third_party/blink/renderer/core/layout/layout_inline.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/loader/document_loader.h"
#include "third_party/blink/renderer/core/page/frame_tree.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/scroll/scroll_alignment.h"
#include "third_party/blink/renderer/core/scroll/scroll_into_view_util.h"
#include "third_party/blink/renderer/core/style/computed_style_constants.h"
#include "third_party/blink/renderer/core/svg/svg_svg_element.h"
#include "third_party/blink/renderer/core/view_transition/view_transition_utils.h"
#include "third_party/blink/renderer/core/xml/document_xpath_evaluator.h"
#include "third_party/blink/renderer/core/xml/xpath_result.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/graphics/color.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink {
FormControlType;
Maybe;
namespace {
const size_t kMaxTextSize = …;
const UChar kEllipsisUChar[] = …;
template <typename Functor>
void ForEachSupportedPseudo(const Element* element, Functor& func) { … }
}
class InspectorRevalidateDOMTask final
: public GarbageCollected<InspectorRevalidateDOMTask> { … };
InspectorRevalidateDOMTask::InspectorRevalidateDOMTask(
InspectorDOMAgent* dom_agent)
: … { … }
void InspectorRevalidateDOMTask::ScheduleStyleAttrRevalidationFor(
Element* element) { … }
void InspectorRevalidateDOMTask::OnTimer(TimerBase*) { … }
void InspectorRevalidateDOMTask::Trace(Visitor* visitor) const { … }
protocol::Response InspectorDOMAgent::ToResponse(
ExceptionState& exception_state) { … }
protocol::DOM::PseudoType InspectorDOMAgent::ProtocolPseudoElementType(
PseudoId pseudo_id) { … }
InspectorDOMAgent::InspectorDOMAgent(
v8::Isolate* isolate,
InspectedFrames* inspected_frames,
v8_inspector::V8InspectorSession* v8_session)
: … { … }
InspectorDOMAgent::~InspectorDOMAgent() = default;
void InspectorDOMAgent::Restore() { … }
HeapVector<Member<Document>> InspectorDOMAgent::Documents() { … }
void InspectorDOMAgent::AddDOMListener(DOMListener* listener) { … }
void InspectorDOMAgent::RemoveDOMListener(DOMListener* listener) { … }
void InspectorDOMAgent::NotifyDidAddDocument(Document* document) { … }
void InspectorDOMAgent::NotifyWillRemoveDOMNode(Node* node) { … }
void InspectorDOMAgent::NotifyDidModifyDOMAttr(Element* element) { … }
void InspectorDOMAgent::SetDocument(Document* doc) { … }
bool InspectorDOMAgent::Enabled() const { … }
InspectorDOMAgent::IncludeWhitespaceEnum InspectorDOMAgent::IncludeWhitespace()
const { … }
void InspectorDOMAgent::ReleaseDanglingNodes() { … }
int InspectorDOMAgent::Bind(Node* node, NodeToIdMap* nodes_map) { … }
void InspectorDOMAgent::Unbind(Node* node) { … }
protocol::Response InspectorDOMAgent::AssertNode(int node_id, Node*& node) { … }
protocol::Response InspectorDOMAgent::AssertNode(
const protocol::Maybe<int>& node_id,
const protocol::Maybe<int>& backend_node_id,
const protocol::Maybe<String>& object_id,
Node*& node) { … }
protocol::Response InspectorDOMAgent::AssertElement(int node_id,
Element*& element) { … }
ShadowRoot* InspectorDOMAgent::UserAgentShadowRoot(Node* node) { … }
protocol::Response InspectorDOMAgent::AssertEditableNode(int node_id,
Node*& node) { … }
protocol::Response InspectorDOMAgent::AssertEditableChildNode(
Element* parent_element,
int node_id,
Node*& node) { … }
protocol::Response InspectorDOMAgent::AssertEditableElement(int node_id,
Element*& element) { … }
void InspectorDOMAgent::EnableAndReset() { … }
protocol::Response InspectorDOMAgent::enable(Maybe<String> includeWhitespace) { … }
protocol::Response InspectorDOMAgent::disable() { … }
protocol::Response InspectorDOMAgent::getDocument(
Maybe<int> depth,
Maybe<bool> pierce,
std::unique_ptr<protocol::DOM::Node>* root) { … }
namespace {
bool NodeHasMatchingStyles(
const HashMap<CSSPropertyID, HashSet<String>>* properties,
Node* node) { … }
}
protocol::Response InspectorDOMAgent::getNodesForSubtreeByStyle(
int node_id,
std::unique_ptr<protocol::Array<protocol::DOM::CSSComputedStyleProperty>>
computed_styles,
Maybe<bool> pierce,
std::unique_ptr<protocol::Array<int>>* node_ids) { … }
protocol::Response InspectorDOMAgent::getFlattenedDocument(
Maybe<int> depth,
Maybe<bool> pierce,
std::unique_ptr<protocol::Array<protocol::DOM::Node>>* nodes) { … }
void InspectorDOMAgent::PushChildNodesToFrontend(int node_id,
int depth,
bool pierce) { … }
void InspectorDOMAgent::DiscardFrontendBindings() { … }
Node* InspectorDOMAgent::NodeForId(int id) const { … }
protocol::Response InspectorDOMAgent::collectClassNamesFromSubtree(
int node_id,
std::unique_ptr<protocol::Array<String>>* class_names) { … }
protocol::Response InspectorDOMAgent::requestChildNodes(
int node_id,
Maybe<int> depth,
Maybe<bool> maybe_taverse_frames) { … }
protocol::Response InspectorDOMAgent::querySelector(int node_id,
const String& selectors,
int* element_id) { … }
protocol::Response InspectorDOMAgent::querySelectorAll(
int node_id,
const String& selectors,
std::unique_ptr<protocol::Array<int>>* result) { … }
protocol::Response InspectorDOMAgent::getTopLayerElements(
std::unique_ptr<protocol::Array<int>>* result) { … }
int InspectorDOMAgent::PushNodePathToFrontend(Node* node_to_push,
NodeToIdMap* node_map) { … }
int InspectorDOMAgent::PushNodePathToFrontend(Node* node_to_push) { … }
int InspectorDOMAgent::BoundNodeId(Node* node) const { … }
protocol::Response InspectorDOMAgent::setAttributeValue(int element_id,
const String& name,
const String& value) { … }
protocol::Response InspectorDOMAgent::setAttributesAsText(int element_id,
const String& text,
Maybe<String> name) { … }
protocol::Response InspectorDOMAgent::removeAttribute(int element_id,
const String& name) { … }
protocol::Response InspectorDOMAgent::removeNode(int node_id) { … }
protocol::Response InspectorDOMAgent::setNodeName(int node_id,
const String& tag_name,
int* new_id) { … }
protocol::Response InspectorDOMAgent::getOuterHTML(Maybe<int> node_id,
Maybe<int> backend_node_id,
Maybe<String> object_id,
WTF::String* outer_html) { … }
protocol::Response InspectorDOMAgent::setOuterHTML(int node_id,
const String& outer_html) { … }
protocol::Response InspectorDOMAgent::setNodeValue(int node_id,
const String& value) { … }
static Node* NextNodeWithShadowDOMInMind(const Node& current,
const Node* stay_within,
bool include_user_agent_shadow_dom) { … }
protocol::Response InspectorDOMAgent::performSearch(
const String& whitespace_trimmed_query,
Maybe<bool> optional_include_user_agent_shadow_dom,
String* search_id,
int* result_count) { … }
protocol::Response InspectorDOMAgent::getSearchResults(
const String& search_id,
int from_index,
int to_index,
std::unique_ptr<protocol::Array<int>>* node_ids) { … }
protocol::Response InspectorDOMAgent::discardSearchResults(
const String& search_id) { … }
protocol::Response InspectorDOMAgent::NodeForRemoteObjectId(
const String& object_id,
Node*& node) { … }
protocol::Response InspectorDOMAgent::copyTo(int node_id,
int target_element_id,
Maybe<int> anchor_node_id,
int* new_node_id) { … }
protocol::Response InspectorDOMAgent::moveTo(int node_id,
int target_element_id,
Maybe<int> anchor_node_id,
int* new_node_id) { … }
protocol::Response InspectorDOMAgent::undo() { … }
protocol::Response InspectorDOMAgent::redo() { … }
protocol::Response InspectorDOMAgent::markUndoableState() { … }
protocol::Response InspectorDOMAgent::focus(Maybe<int> node_id,
Maybe<int> backend_node_id,
Maybe<String> object_id) { … }
protocol::Response InspectorDOMAgent::setFileInputFiles(
std::unique_ptr<protocol::Array<String>> files,
Maybe<int> node_id,
Maybe<int> backend_node_id,
Maybe<String> object_id) { … }
protocol::Response InspectorDOMAgent::setNodeStackTracesEnabled(bool enable) { … }
protocol::Response InspectorDOMAgent::getNodeStackTraces(
int node_id,
protocol::Maybe<v8_inspector::protocol::Runtime::API::StackTrace>*
creation) { … }
protocol::Response InspectorDOMAgent::getBoxModel(
Maybe<int> node_id,
Maybe<int> backend_node_id,
Maybe<String> object_id,
std::unique_ptr<protocol::DOM::BoxModel>* model) { … }
protocol::Response InspectorDOMAgent::getContentQuads(
Maybe<int> node_id,
Maybe<int> backend_node_id,
Maybe<String> object_id,
std::unique_ptr<protocol::Array<protocol::Array<double>>>* quads) { … }
protocol::Response InspectorDOMAgent::getNodeForLocation(
int x,
int y,
Maybe<bool> optional_include_user_agent_shadow_dom,
Maybe<bool> optional_ignore_pointer_events_none,
int* backend_node_id,
String* frame_id,
Maybe<int>* node_id) { … }
protocol::Response InspectorDOMAgent::resolveNode(
protocol::Maybe<int> node_id,
protocol::Maybe<int> backend_node_id,
protocol::Maybe<String> object_group,
protocol::Maybe<int> execution_context_id,
std::unique_ptr<v8_inspector::protocol::Runtime::API::RemoteObject>*
result) { … }
protocol::Response InspectorDOMAgent::getAttributes(
int node_id,
std::unique_ptr<protocol::Array<String>>* result) { … }
protocol::Response InspectorDOMAgent::requestNode(const String& object_id,
int* node_id) { … }
protocol::Response InspectorDOMAgent::getContainerForNode(
int node_id,
protocol::Maybe<String> container_name,
protocol::Maybe<protocol::DOM::PhysicalAxes> physical_axes,
protocol::Maybe<protocol::DOM::LogicalAxes> logical_axes,
Maybe<int>* container_node_id) { … }
protocol::Response InspectorDOMAgent::getQueryingDescendantsForContainer(
int node_id,
std::unique_ptr<protocol::Array<int>>* node_ids) { … }
protocol::Response InspectorDOMAgent::getElementByRelation(
int node_id,
const String& relation,
int* related_element_id) { … }
protocol::Response InspectorDOMAgent::getAnchorElement(
int node_id,
protocol::Maybe<String> anchor_specifier,
int* anchor_element_id) { … }
const HeapVector<Member<Element>>
InspectorDOMAgent::GetContainerQueryingDescendants(Element* container) { … }
bool InspectorDOMAgent::ContainerQueriedByElement(Element* container,
Element* element) { … }
String InspectorDOMAgent::DocumentURLString(Document* document) { … }
String InspectorDOMAgent::DocumentBaseURLString(Document* document) { … }
protocol::DOM::ShadowRootType InspectorDOMAgent::GetShadowRootType(
ShadowRoot* shadow_root) { … }
protocol::DOM::CompatibilityMode
InspectorDOMAgent::GetDocumentCompatibilityMode(Document* document) { … }
std::unique_ptr<protocol::DOM::Node> InspectorDOMAgent::BuildObjectForNode(
Node* node,
int depth,
bool pierce,
NodeToIdMap* nodes_map,
protocol::Array<protocol::DOM::Node>* flatten_result) { … }
std::unique_ptr<protocol::Array<String>>
InspectorDOMAgent::BuildArrayForElementAttributes(Element* element) { … }
std::unique_ptr<protocol::Array<protocol::DOM::Node>>
InspectorDOMAgent::BuildArrayForContainerChildren(
Node* container,
int depth,
bool pierce,
NodeToIdMap* nodes_map,
protocol::Array<protocol::DOM::Node>* flatten_result) { … }
std::unique_ptr<protocol::Array<protocol::DOM::Node>>
InspectorDOMAgent::BuildArrayForPseudoElements(Element* element,
NodeToIdMap* nodes_map) { … }
std::unique_ptr<protocol::DOM::BackendNode> InspectorDOMAgent::BuildBackendNode(
Node* slot_element) { … }
std::unique_ptr<protocol::Array<protocol::DOM::BackendNode>>
InspectorDOMAgent::BuildDistributedNodesForSlot(HTMLSlotElement* slot_element) { … }
Node* InspectorDOMAgent::InnerFirstChild(
Node* node,
InspectorDOMAgent::IncludeWhitespaceEnum include_whitespace) { … }
Node* InspectorDOMAgent::InnerNextSibling(
Node* node,
InspectorDOMAgent::IncludeWhitespaceEnum include_whitespace) { … }
Node* InspectorDOMAgent::InnerPreviousSibling(
Node* node,
InspectorDOMAgent::IncludeWhitespaceEnum include_whitespace) { … }
unsigned InspectorDOMAgent::InnerChildNodeCount(
Node* node,
InspectorDOMAgent::IncludeWhitespaceEnum include_whitespace) { … }
Node* InspectorDOMAgent::InnerParentNode(Node* node) { … }
bool InspectorDOMAgent::ShouldSkipNode(
Node* node,
InspectorDOMAgent::IncludeWhitespaceEnum include_whitespace) { … }
void InspectorDOMAgent::CollectNodes(
Node* node,
int depth,
bool pierce,
InspectorDOMAgent::IncludeWhitespaceEnum include_whitespace,
base::RepeatingCallback<bool(Node*)> filter,
HeapVector<Member<Node>>* result) { … }
void InspectorDOMAgent::DomContentLoadedEventFired(LocalFrame* frame) { … }
void InspectorDOMAgent::InvalidateFrameOwnerElement(
HTMLFrameOwnerElement* frame_owner) { … }
void InspectorDOMAgent::DidCommitLoad(LocalFrame*, DocumentLoader* loader) { … }
void InspectorDOMAgent::DidRestoreFromBackForwardCache(LocalFrame* frame) { … }
void InspectorDOMAgent::DidInsertDOMNode(Node* node) { … }
void InspectorDOMAgent::WillRemoveDOMNode(Node* node) { … }
void InspectorDOMAgent::DOMNodeRemoved(Node* node) { … }
void InspectorDOMAgent::WillModifyDOMAttr(Element*,
const AtomicString& old_value,
const AtomicString& new_value) { … }
void InspectorDOMAgent::DidModifyDOMAttr(Element* element,
const QualifiedName& name,
const AtomicString& value) { … }
void InspectorDOMAgent::DidRemoveDOMAttr(Element* element,
const QualifiedName& name) { … }
void InspectorDOMAgent::StyleAttributeInvalidated(
const HeapVector<Member<Element>>& elements) { … }
void InspectorDOMAgent::CharacterDataModified(CharacterData* character_data) { … }
InspectorRevalidateDOMTask* InspectorDOMAgent::RevalidateTask() { … }
void InspectorDOMAgent::DidInvalidateStyleAttr(Node* node) { … }
void InspectorDOMAgent::DidPushShadowRoot(Element* host, ShadowRoot* root) { … }
void InspectorDOMAgent::WillPopShadowRoot(Element* host, ShadowRoot* root) { … }
void InspectorDOMAgent::DidPerformSlotDistribution(
HTMLSlotElement* slot_element) { … }
void InspectorDOMAgent::FrameDocumentUpdated(LocalFrame* frame) { … }
void InspectorDOMAgent::FrameOwnerContentUpdated(
LocalFrame* frame,
HTMLFrameOwnerElement* frame_owner) { … }
void InspectorDOMAgent::PseudoElementCreated(PseudoElement* pseudo_element) { … }
void InspectorDOMAgent::TopLayerElementsChanged() { … }
void InspectorDOMAgent::PseudoElementDestroyed(PseudoElement* pseudo_element) { … }
void InspectorDOMAgent::NodeCreated(Node* node) { … }
namespace {
ShadowRoot* ShadowRootForNode(Node* node, const String& type) { … }
Document* DocumentForFrameOwner(Node* node) { … }
}
Node* InspectorDOMAgent::NodeForPath(const String& path) { … }
protocol::Response InspectorDOMAgent::pushNodeByPathToFrontend(
const String& path,
int* node_id) { … }
protocol::Response InspectorDOMAgent::pushNodesByBackendIdsToFrontend(
std::unique_ptr<protocol::Array<int>> backend_node_ids,
std::unique_ptr<protocol::Array<int>>* result) { … }
class InspectableNode final
: public v8_inspector::V8InspectorSession::Inspectable { … };
protocol::Response InspectorDOMAgent::setInspectedNode(int node_id) { … }
protocol::Response InspectorDOMAgent::getRelayoutBoundary(
int node_id,
int* relayout_boundary_node_id) { … }
protocol::Response InspectorDOMAgent::describeNode(
protocol::Maybe<int> node_id,
protocol::Maybe<int> backend_node_id,
protocol::Maybe<String> object_id,
protocol::Maybe<int> depth,
protocol::Maybe<bool> pierce,
std::unique_ptr<protocol::DOM::Node>* result) { … }
protocol::Response InspectorDOMAgent::scrollIntoViewIfNeeded(
protocol::Maybe<int> node_id,
protocol::Maybe<int> backend_node_id,
protocol::Maybe<String> object_id,
protocol::Maybe<protocol::DOM::Rect> rect) { … }
protocol::Response InspectorDOMAgent::getFrameOwner(
const String& frame_id,
int* backend_node_id,
protocol::Maybe<int>* node_id) { … }
protocol::Response InspectorDOMAgent::getFileInfo(const String& object_id,
String* path) { … }
protocol::Response InspectorDOMAgent::getDetachedDomNodes(
std::unique_ptr<protocol::Array<protocol::DOM::DetachedElementInfo>>*
detached_nodes) { … }
void InspectorDOMAgent::Trace(Visitor* visitor) const { … }
}