diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-07-16 11:45:35 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-07-17 08:59:23 +0000 |
commit | 552906b0f222c5d5dd11b9fd73829d510980461a (patch) | |
tree | 3a11e6ed0538a81dd83b20cf3a4783e297f26d91 /chromium/third_party/blink/renderer/core/inspector/inspector_dom_agent.cc | |
parent | 1b05827804eaf047779b597718c03e7d38344261 (diff) | |
download | qtwebengine-chromium-552906b0f222c5d5dd11b9fd73829d510980461a.tar.gz |
BASELINE: Update Chromium to 83.0.4103.122
Change-Id: Ie3a82f5bb0076eec2a7c6a6162326b4301ee291e
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/third_party/blink/renderer/core/inspector/inspector_dom_agent.cc')
-rw-r--r-- | chromium/third_party/blink/renderer/core/inspector/inspector_dom_agent.cc | 448 |
1 files changed, 246 insertions, 202 deletions
diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_dom_agent.cc b/chromium/third_party/blink/renderer/core/inspector/inspector_dom_agent.cc index 793c27538ba..ce49bb82a00 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_dom_agent.cc +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_dom_agent.cc @@ -52,11 +52,13 @@ #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/v0_insertion_point.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/frame/frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/remote_frame.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" @@ -108,7 +110,7 @@ class InspectorRevalidateDOMTask final void ScheduleStyleAttrRevalidationFor(Element*); void Reset() { timer_.Stop(); } void OnTimer(TimerBase*); - void Trace(blink::Visitor*); + void Trace(Visitor*); private: Member<InspectorDOMAgent> dom_agent_; @@ -141,7 +143,7 @@ void InspectorRevalidateDOMTask::OnTimer(TimerBase*) { style_attr_invalidated_elements_.clear(); } -void InspectorRevalidateDOMTask::Trace(blink::Visitor* visitor) { +void InspectorRevalidateDOMTask::Trace(Visitor* visitor) { visitor->Trace(dom_agent_); visitor->Trace(style_attr_invalidated_elements_); } @@ -153,61 +155,51 @@ Response InspectorDOMAgent::ToResponse(ExceptionState& exception_state) { exception_state.CodeAs<DOMExceptionCode>()) + " " : g_empty_string; - return Response::Error(name_prefix + exception_state.Message()); + String msg = name_prefix + exception_state.Message(); + return Response::ServerError(msg.Utf8()); } - return Response::OK(); + return Response::Success(); } -bool InspectorDOMAgent::GetPseudoElementType(PseudoId pseudo_id, - protocol::DOM::PseudoType* type) { +protocol::DOM::PseudoType InspectorDOMAgent::ProtocolPseudoElementType( + PseudoId pseudo_id) { switch (pseudo_id) { case kPseudoIdFirstLine: - *type = protocol::DOM::PseudoTypeEnum::FirstLine; - return true; + return protocol::DOM::PseudoTypeEnum::FirstLine; case kPseudoIdFirstLetter: - *type = protocol::DOM::PseudoTypeEnum::FirstLetter; - return true; + return protocol::DOM::PseudoTypeEnum::FirstLetter; case kPseudoIdBefore: - *type = protocol::DOM::PseudoTypeEnum::Before; - return true; + return protocol::DOM::PseudoTypeEnum::Before; case kPseudoIdAfter: - *type = protocol::DOM::PseudoTypeEnum::After; - return true; + return protocol::DOM::PseudoTypeEnum::After; + case kPseudoIdMarker: + return protocol::DOM::PseudoTypeEnum::Marker; case kPseudoIdBackdrop: - *type = protocol::DOM::PseudoTypeEnum::Backdrop; - return true; + return protocol::DOM::PseudoTypeEnum::Backdrop; case kPseudoIdSelection: - *type = protocol::DOM::PseudoTypeEnum::Selection; - return true; + return protocol::DOM::PseudoTypeEnum::Selection; case kPseudoIdFirstLineInherited: - *type = protocol::DOM::PseudoTypeEnum::FirstLineInherited; - return true; + return protocol::DOM::PseudoTypeEnum::FirstLineInherited; case kPseudoIdScrollbar: - *type = protocol::DOM::PseudoTypeEnum::Scrollbar; - return true; + return protocol::DOM::PseudoTypeEnum::Scrollbar; case kPseudoIdScrollbarThumb: - *type = protocol::DOM::PseudoTypeEnum::ScrollbarThumb; - return true; + return protocol::DOM::PseudoTypeEnum::ScrollbarThumb; case kPseudoIdScrollbarButton: - *type = protocol::DOM::PseudoTypeEnum::ScrollbarButton; - return true; + return protocol::DOM::PseudoTypeEnum::ScrollbarButton; case kPseudoIdScrollbarTrack: - *type = protocol::DOM::PseudoTypeEnum::ScrollbarTrack; - return true; + return protocol::DOM::PseudoTypeEnum::ScrollbarTrack; case kPseudoIdScrollbarTrackPiece: - *type = protocol::DOM::PseudoTypeEnum::ScrollbarTrackPiece; - return true; + return protocol::DOM::PseudoTypeEnum::ScrollbarTrackPiece; case kPseudoIdScrollbarCorner: - *type = protocol::DOM::PseudoTypeEnum::ScrollbarCorner; - return true; + return protocol::DOM::PseudoTypeEnum::ScrollbarCorner; case kPseudoIdResizer: - *type = protocol::DOM::PseudoTypeEnum::Resizer; - return true; + return protocol::DOM::PseudoTypeEnum::Resizer; case kPseudoIdInputListButton: - *type = protocol::DOM::PseudoTypeEnum::InputListButton; - return true; - default: - return false; + return protocol::DOM::PseudoTypeEnum::InputListButton; + case kAfterLastInternalPseudoId: + case kPseudoIdNone: + CHECK(false); + return ""; } } @@ -330,6 +322,8 @@ void InspectorDOMAgent::Unbind(Node* node, NodeToIdMap* nodes_map) { Unbind(element->GetPseudoElement(kPseudoIdBefore), nodes_map); if (element->GetPseudoElement(kPseudoIdAfter)) Unbind(element->GetPseudoElement(kPseudoIdAfter), nodes_map); + if (element->GetPseudoElement(kPseudoIdMarker)) + Unbind(element->GetPseudoElement(kPseudoIdMarker), nodes_map); if (auto* link_element = DynamicTo<HTMLLinkElement>(*element)) { if (link_element->IsImport() && link_element->import()) @@ -358,8 +352,8 @@ void InspectorDOMAgent::Unbind(Node* node, NodeToIdMap* nodes_map) { Response InspectorDOMAgent::AssertNode(int node_id, Node*& node) { node = NodeForId(node_id); if (!node) - return Response::Error("Could not find node with given id"); - return Response::OK(); + return Response::ServerError("Could not find node with given id"); + return Response::Success(); } Response InspectorDOMAgent::AssertNode( @@ -372,27 +366,27 @@ Response InspectorDOMAgent::AssertNode( if (backend_node_id.isJust()) { node = DOMNodeIds::NodeForId(backend_node_id.fromJust()); - return !node ? Response::Error("No node found for given backend id") - : Response::OK(); + return !node ? Response::ServerError("No node found for given backend id") + : Response::Success(); } if (object_id.isJust()) return NodeForRemoteObjectId(object_id.fromJust(), node); - return Response::Error( + return Response::ServerError( "Either nodeId, backendNodeId or objectId must be specified"); } Response InspectorDOMAgent::AssertElement(int node_id, Element*& element) { Node* node = nullptr; Response response = AssertNode(node_id, node); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; element = DynamicTo<Element>(node); if (!element) - return Response::Error("Node is not an Element"); - return Response::OK(); + return Response::ServerError("Node is not an Element"); + return Response::Success(); } // static @@ -411,45 +405,49 @@ ShadowRoot* InspectorDOMAgent::UserAgentShadowRoot(Node* node) { Response InspectorDOMAgent::AssertEditableNode(int node_id, Node*& node) { Response response = AssertNode(node_id, node); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; if (node->IsInShadowTree()) { if (IsA<ShadowRoot>(node)) - return Response::Error("Cannot edit shadow roots"); - if (UserAgentShadowRoot(node)) - return Response::Error("Cannot edit nodes from user-agent shadow trees"); + return Response::ServerError("Cannot edit shadow roots"); + if (UserAgentShadowRoot(node)) { + return Response::ServerError( + "Cannot edit nodes from user-agent shadow trees"); + } } if (node->IsPseudoElement()) - return Response::Error("Cannot edit pseudo elements"); - return Response::OK(); + return Response::ServerError("Cannot edit pseudo elements"); + return Response::Success(); } Response InspectorDOMAgent::AssertEditableChildNode(Element* parent_element, int node_id, Node*& node) { Response response = AssertEditableNode(node_id, node); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; - if (node->parentNode() != parent_element) - return Response::Error("Anchor node must be child of the target element"); - return Response::OK(); + if (node->parentNode() != parent_element) { + return Response::ServerError( + "Anchor node must be child of the target element"); + } + return Response::Success(); } Response InspectorDOMAgent::AssertEditableElement(int node_id, Element*& element) { Response response = AssertElement(node_id, element); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; - - if (element->IsInShadowTree() && UserAgentShadowRoot(element)) - return Response::Error("Cannot edit elements from user-agent shadow trees"); - + if (element->IsInShadowTree() && UserAgentShadowRoot(element)) { + return Response::ServerError( + "Cannot edit elements from user-agent shadow trees"); + } if (element->IsPseudoElement()) - return Response::Error("Cannot edit pseudo elements"); + return Response::ServerError("Cannot edit pseudo elements"); - return Response::OK(); + return Response::Success(); } void InspectorDOMAgent::EnableAndReset() { @@ -463,18 +461,18 @@ void InspectorDOMAgent::EnableAndReset() { Response InspectorDOMAgent::enable() { if (!enabled_.Get()) EnableAndReset(); - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::disable() { if (!enabled_.Get()) - return Response::Error("DOM agent hasn't been enabled"); + return Response::ServerError("DOM agent hasn't been enabled"); enabled_.Clear(); instrumenting_agents_->RemoveInspectorDOMAgent(this); history_.Clear(); dom_editor_.Clear(); SetDocument(nullptr); - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::getDocument( @@ -485,7 +483,7 @@ Response InspectorDOMAgent::getDocument( enable(); if (!document_) - return Response::Error("Document is not available"); + return Response::ServerError("Document is not available"); DiscardFrontendBindings(); @@ -496,7 +494,7 @@ Response InspectorDOMAgent::getDocument( *root = BuildObjectForNode(document_.Get(), sanitized_depth, pierce.fromMaybe(false), document_node_to_id_map_.Get()); - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::getFlattenedDocument( @@ -504,10 +502,10 @@ Response InspectorDOMAgent::getFlattenedDocument( Maybe<bool> pierce, std::unique_ptr<protocol::Array<protocol::DOM::Node>>* nodes) { if (!enabled_.Get()) - return Response::Error("DOM agent hasn't been enabled"); + return Response::ServerError("DOM agent hasn't been enabled"); if (!document_) - return Response::Error("Document is not available"); + return Response::ServerError("Document is not available"); DiscardFrontendBindings(); @@ -519,7 +517,7 @@ Response InspectorDOMAgent::getFlattenedDocument( (*nodes)->emplace_back(BuildObjectForNode( document_.Get(), sanitized_depth, pierce.fromMaybe(false), document_node_to_id_map_.Get(), nodes->get())); - return Response::OK(); + return Response::Success(); } void InspectorDOMAgent::PushChildNodesToFrontend(int node_id, @@ -585,7 +583,7 @@ Response InspectorDOMAgent::collectClassNamesFromSubtree( auto* parent_element = DynamicTo<Element>(parent_node); if (!parent_element && !parent_node->IsDocumentNode() && !parent_node->IsDocumentFragment()) - return Response::Error("No suitable node with given id found"); + return Response::ServerError("No suitable node with given id found"); for (Node* node = parent_node; node; node = FlatTreeTraversal::Next(*node, parent_node)) { @@ -599,7 +597,7 @@ Response InspectorDOMAgent::collectClassNamesFromSubtree( } for (const String& class_name : unique_names) (*class_names)->emplace_back(class_name); - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::requestChildNodes( @@ -608,7 +606,7 @@ Response InspectorDOMAgent::requestChildNodes( Maybe<bool> maybe_taverse_frames) { int sanitized_depth = depth.fromMaybe(1); if (sanitized_depth == 0 || sanitized_depth < -1) { - return Response::Error( + return Response::ServerError( "Please provide a positive integer as a depth or -1 for entire " "subtree"); } @@ -617,7 +615,7 @@ Response InspectorDOMAgent::requestChildNodes( PushChildNodesToFrontend(node_id, sanitized_depth, maybe_taverse_frames.fromMaybe(false)); - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::querySelector(int node_id, @@ -626,21 +624,21 @@ Response InspectorDOMAgent::querySelector(int node_id, *element_id = 0; Node* node = nullptr; Response response = AssertNode(node_id, node); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; auto* container_node = DynamicTo<ContainerNode>(node); if (!container_node) - return Response::Error("Not a container node"); + return Response::ServerError("Not a container node"); DummyExceptionStateForTesting exception_state; Element* element = container_node->QuerySelector(AtomicString(selectors), exception_state); if (exception_state.HadException()) - return Response::Error("DOM Error while querying"); + return Response::ServerError("DOM Error while querying"); if (element) *element_id = PushNodePathToFrontend(element); - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::querySelectorAll( @@ -649,23 +647,23 @@ Response InspectorDOMAgent::querySelectorAll( std::unique_ptr<protocol::Array<int>>* result) { Node* node = nullptr; Response response = AssertNode(node_id, node); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; auto* container_node = DynamicTo<ContainerNode>(node); if (!container_node) - return Response::Error("Not a container node"); + return Response::ServerError("Not a container node"); DummyExceptionStateForTesting exception_state; StaticElementList* elements = container_node->QuerySelectorAll( AtomicString(selectors), exception_state); if (exception_state.HadException()) - return Response::Error("DOM Error while querying"); + return Response::ServerError("DOM Error while querying"); *result = std::make_unique<protocol::Array<int>>(); for (unsigned i = 0; i < elements->length(); ++i) (*result)->emplace_back(PushNodePathToFrontend(elements->item(i))); - return Response::OK(); + return Response::Success(); } int InspectorDOMAgent::PushNodePathToFrontend(Node* node_to_push, @@ -736,7 +734,7 @@ Response InspectorDOMAgent::setAttributeValue(int element_id, const String& value) { Element* element = nullptr; Response response = AssertEditableElement(element_id, element); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; return dom_editor_->SetAttribute(element, name, value); } @@ -746,14 +744,14 @@ Response InspectorDOMAgent::setAttributesAsText(int element_id, Maybe<String> name) { Element* element = nullptr; Response response = AssertEditableElement(element_id, element); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; String markup = "<span " + text + "></span>"; DocumentFragment* fragment = element->GetDocument().createDocumentFragment(); bool should_ignore_case = - element->GetDocument().IsHTMLDocument() && element->IsHTMLElement(); + IsA<HTMLDocument>(element->GetDocument()) && element->IsHTMLElement(); // Not all elements can represent the context (i.e. IFRAME), hence using // document.body. if (should_ignore_case && element->GetDocument().body()) { @@ -768,7 +766,7 @@ Response InspectorDOMAgent::setAttributesAsText(int element_id, Element* parsed_element = DynamicTo<Element>(fragment->firstChild()); if (!parsed_element) - return Response::Error("Could not parse value as attributes"); + return Response::ServerError("Could not parse value as attributes"); String case_adjusted_name = should_ignore_case ? name.fromMaybe("").DeprecatedLower() @@ -788,7 +786,7 @@ Response InspectorDOMAgent::setAttributesAsText(int element_id, name.isJust() && attribute_name == case_adjusted_name; Response response = dom_editor_->SetAttribute(element, attribute_name, attribute.Value()); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; } @@ -796,14 +794,14 @@ Response InspectorDOMAgent::setAttributesAsText(int element_id, !name.fromJust().StripWhiteSpace().IsEmpty()) { return dom_editor_->RemoveAttribute(element, case_adjusted_name); } - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::removeAttribute(int element_id, const String& name) { Element* element = nullptr; Response response = AssertEditableElement(element_id, element); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; return dom_editor_->RemoveAttribute(element, name); @@ -812,12 +810,12 @@ Response InspectorDOMAgent::removeAttribute(int element_id, Response InspectorDOMAgent::removeNode(int node_id) { Node* node = nullptr; Response response = AssertEditableNode(node_id, node); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; ContainerNode* parent_node = node->parentNode(); if (!parent_node) - return Response::Error("Cannot remove detached node"); + return Response::ServerError("Cannot remove detached node"); return dom_editor_->RemoveChild(parent_node, node); } @@ -829,7 +827,7 @@ Response InspectorDOMAgent::setNodeName(int node_id, Element* old_element = nullptr; Response response = AssertElement(node_id, old_element); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; DummyExceptionStateForTesting exception_state; @@ -845,7 +843,7 @@ Response InspectorDOMAgent::setNodeName(int node_id, for (Node* child = old_element->firstChild(); child; child = old_element->firstChild()) { response = dom_editor_->InsertBefore(new_elem, child, nullptr); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; } @@ -853,16 +851,16 @@ Response InspectorDOMAgent::setNodeName(int node_id, ContainerNode* parent = old_element->parentNode(); response = dom_editor_->InsertBefore(parent, new_elem, old_element->nextSibling()); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; response = dom_editor_->RemoveChild(parent, old_element); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; *new_id = PushNodePathToFrontend(new_elem); if (children_requested_.Contains(node_id)) PushChildNodesToFrontend(*new_id); - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::getOuterHTML(Maybe<int> node_id, @@ -871,11 +869,11 @@ Response InspectorDOMAgent::getOuterHTML(Maybe<int> node_id, WTF::String* outer_html) { Node* node = nullptr; Response response = AssertNode(node_id, backend_node_id, object_id, node); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; *outer_html = CreateMarkup(node); - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::setOuterHTML(int node_id, @@ -884,27 +882,28 @@ Response InspectorDOMAgent::setOuterHTML(int node_id, DCHECK(document_); DOMPatchSupport dom_patch_support(dom_editor_.Get(), *document_.Get()); dom_patch_support.PatchDocument(outer_html); - return Response::OK(); + return Response::Success(); } Node* node = nullptr; Response response = AssertEditableNode(node_id, node); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; Document* document = IsA<Document>(node) ? To<Document>(node) : node->ownerDocument(); - if (!document || (!document->IsHTMLDocument() && !document->IsXMLDocument())) - return Response::Error("Not an HTML/XML document"); + if (!document || + (!IsA<HTMLDocument>(document) && !IsA<XMLDocument>(document))) + return Response::ServerError("Not an HTML/XML document"); Node* new_node = nullptr; response = dom_editor_->SetOuterHTML(node, outer_html, &new_node); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; if (!new_node) { // The only child node has been deleted. - return Response::OK(); + return Response::Success(); } int new_id = PushNodePathToFrontend(new_node); @@ -912,17 +911,17 @@ Response InspectorDOMAgent::setOuterHTML(int node_id, bool children_requested = children_requested_.Contains(node_id); if (children_requested) PushChildNodesToFrontend(new_id); - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::setNodeValue(int node_id, const String& value) { Node* node = nullptr; Response response = AssertEditableNode(node_id, node); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; if (node->getNodeType() != Node::kTextNode) - return Response::Error("Can only set value of text nodes"); + return Response::ServerError("Can only set value of text nodes"); return dom_editor_->ReplaceWholeText(To<Text>(node), value); } @@ -964,7 +963,7 @@ Response InspectorDOMAgent::performSearch( String* search_id, int* result_count) { if (!enabled_.Get()) - return Response::Error("DOM agent is not enabled"); + return Response::ServerError("DOM agent is not enabled"); // FIXME: Few things are missing here: // 1) Search works with node granularity - number of matches within node is @@ -1106,7 +1105,7 @@ Response InspectorDOMAgent::performSearch( results_it->push_back(result); *result_count = results_it->size(); - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::getSearchResults( @@ -1116,21 +1115,21 @@ Response InspectorDOMAgent::getSearchResults( std::unique_ptr<protocol::Array<int>>* node_ids) { SearchResults::iterator it = search_results_.find(search_id); if (it == search_results_.end()) - return Response::Error("No search session with given id found"); + return Response::ServerError("No search session with given id found"); int size = it->value.size(); if (from_index < 0 || to_index > size || from_index >= to_index) - return Response::Error("Invalid search result range"); + return Response::ServerError("Invalid search result range"); *node_ids = std::make_unique<protocol::Array<int>>(); for (int i = from_index; i < to_index; ++i) (*node_ids)->emplace_back(PushNodePathToFrontend((it->value)[i].Get())); - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::discardSearchResults(const String& search_id) { search_results_.erase(search_id); - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::NodeForRemoteObjectId(const String& object_id, @@ -1141,15 +1140,15 @@ Response InspectorDOMAgent::NodeForRemoteObjectId(const String& object_id, std::unique_ptr<v8_inspector::StringBuffer> error; if (!v8_session_->unwrapObject(&error, ToV8InspectorStringView(object_id), &value, &context, nullptr)) - return Response::Error(ToCoreString(std::move(error))); + return Response::ServerError(ToCoreString(std::move(error)).Utf8()); if (!V8Node::HasInstance(value, isolate_)) - return Response::Error("Object id doesn't reference a Node"); + return Response::ServerError("Object id doesn't reference a Node"); node = V8Node::ToImpl(v8::Local<v8::Object>::Cast(value)); if (!node) { - return Response::Error( + return Response::ServerError( "Couldn't convert object with given objectId to Node"); } - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::copyTo(int node_id, @@ -1158,33 +1157,33 @@ Response InspectorDOMAgent::copyTo(int node_id, int* new_node_id) { Node* node = nullptr; Response response = AssertEditableNode(node_id, node); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; Element* target_element = nullptr; response = AssertEditableElement(target_element_id, target_element); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; Node* anchor_node = nullptr; if (anchor_node_id.isJust() && anchor_node_id.fromJust()) { response = AssertEditableChildNode(target_element, anchor_node_id.fromJust(), anchor_node); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; } // The clone is deep by default. Node* cloned_node = node->cloneNode(true); if (!cloned_node) - return Response::Error("Failed to clone node"); + return Response::ServerError("Failed to clone node"); response = dom_editor_->InsertBefore(target_element, cloned_node, anchor_node); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; *new_node_id = PushNodePathToFrontend(cloned_node); - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::moveTo(int node_id, @@ -1193,18 +1192,20 @@ Response InspectorDOMAgent::moveTo(int node_id, int* new_node_id) { Node* node = nullptr; Response response = AssertEditableNode(node_id, node); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; Element* target_element = nullptr; response = AssertEditableElement(target_element_id, target_element); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; Node* current = target_element; while (current) { - if (current == node) - return Response::Error("Unable to move node into self or descendant"); + if (current == node) { + return Response::ServerError( + "Unable to move node into self or descendant"); + } current = current->parentNode(); } @@ -1212,21 +1213,21 @@ Response InspectorDOMAgent::moveTo(int node_id, if (anchor_node_id.isJust() && anchor_node_id.fromJust()) { response = AssertEditableChildNode(target_element, anchor_node_id.fromJust(), anchor_node); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; } response = dom_editor_->InsertBefore(target_element, node, anchor_node); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; *new_node_id = PushNodePathToFrontend(node); - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::undo() { if (!enabled_.Get()) - return Response::Error("DOM agent is not enabled"); + return Response::ServerError("DOM agent is not enabled"); DummyExceptionStateForTesting exception_state; history_->Undo(exception_state); return InspectorDOMAgent::ToResponse(exception_state); @@ -1234,7 +1235,7 @@ Response InspectorDOMAgent::undo() { Response InspectorDOMAgent::redo() { if (!enabled_.Get()) - return Response::Error("DOM agent is not enabled"); + return Response::ServerError("DOM agent is not enabled"); DummyExceptionStateForTesting exception_state; history_->Redo(exception_state); return InspectorDOMAgent::ToResponse(exception_state); @@ -1242,7 +1243,7 @@ Response InspectorDOMAgent::redo() { Response InspectorDOMAgent::markUndoableState() { history_->MarkUndoableState(); - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::focus(Maybe<int> node_id, @@ -1250,16 +1251,16 @@ Response InspectorDOMAgent::focus(Maybe<int> node_id, Maybe<String> object_id) { Node* node = nullptr; Response response = AssertNode(node_id, backend_node_id, object_id, node); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; auto* element = DynamicTo<Element>(node); if (!element) - return Response::Error("Node is not an Element"); - element->GetDocument().UpdateStyleAndLayout(); + return Response::ServerError("Node is not an Element"); + element->GetDocument().UpdateStyleAndLayout(DocumentUpdateReason::kInspector); if (!element->IsFocusable()) - return Response::Error("Element is not focusable"); + return Response::ServerError("Element is not focusable"); element->focus(); - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::setFileInputFiles( @@ -1269,24 +1270,24 @@ Response InspectorDOMAgent::setFileInputFiles( Maybe<String> object_id) { Node* node = nullptr; Response response = AssertNode(node_id, backend_node_id, object_id, node); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; auto* html_input_element = DynamicTo<HTMLInputElement>(node); if (!html_input_element || html_input_element->type() != input_type_names::kFile) - return Response::Error("Node is not a file input element"); + return Response::ServerError("Node is not a file input element"); Vector<String> paths; for (const String& file : *files) paths.push_back(file); To<HTMLInputElement>(node)->SetFilesFromPaths(paths); - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::setNodeStackTracesEnabled(bool enable) { capture_node_stack_traces_.Set(enable); - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::getNodeStackTraces( @@ -1295,7 +1296,7 @@ Response InspectorDOMAgent::getNodeStackTraces( creation) { Node* node = nullptr; Response response = AssertNode(node_id, node); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; InspectorSourceLocation* creation_inspector_source_location = @@ -1305,7 +1306,7 @@ Response InspectorDOMAgent::getNodeStackTraces( creation_inspector_source_location->GetSourceLocation(); *creation = source_location.BuildInspectorObject(); } - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::getBoxModel( @@ -1315,13 +1316,13 @@ Response InspectorDOMAgent::getBoxModel( std::unique_ptr<protocol::DOM::BoxModel>* model) { Node* node = nullptr; Response response = AssertNode(node_id, backend_node_id, object_id, node); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; bool result = InspectorHighlight::GetBoxModel(node, model, true); if (!result) - return Response::Error("Could not compute box model."); - return Response::OK(); + return Response::ServerError("Could not compute box model."); + return Response::Success(); } Response InspectorDOMAgent::getContentQuads( @@ -1331,12 +1332,12 @@ Response InspectorDOMAgent::getContentQuads( std::unique_ptr<protocol::Array<protocol::Array<double>>>* quads) { Node* node = nullptr; Response response = AssertNode(node_id, backend_node_id, object_id, node); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; bool result = InspectorHighlight::GetContentQuads(node, quads); if (!result) - return Response::Error("Could not compute content quads."); - return Response::OK(); + return Response::ServerError("Could not compute content quads."); + return Response::Success(); } Response InspectorDOMAgent::getNodeForLocation( @@ -1368,7 +1369,7 @@ Response InspectorDOMAgent::getNodeForLocation( while (node && node->getNodeType() == Node::kTextNode) node = node->parentNode(); if (!node) - return Response::Error("No node found at given location"); + return Response::ServerError("No node found at given location"); *backend_node_id = IdentifiersFactory::IntIdForNode(node); LocalFrame* frame = node->GetDocument().GetFrame(); *frame_id = IdentifiersFactory::FrameId(frame); @@ -1376,7 +1377,7 @@ Response InspectorDOMAgent::getNodeForLocation( document_node_to_id_map_->Contains(document_)) { *node_id = PushNodePathToFrontend(node); } - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::resolveNode( @@ -1389,8 +1390,10 @@ Response InspectorDOMAgent::resolveNode( String object_group_name = object_group.fromMaybe(""); Node* node = nullptr; - if (node_id.isJust() == backend_node_id.isJust()) - return Response::Error("Either nodeId or backendNodeId must be specified."); + if (node_id.isJust() == backend_node_id.isJust()) { + return Response::ServerError( + "Either nodeId or backendNodeId must be specified."); + } if (node_id.isJust()) node = NodeForId(node_id.fromJust()); @@ -1398,14 +1401,14 @@ Response InspectorDOMAgent::resolveNode( node = DOMNodeIds::NodeForId(backend_node_id.fromJust()); if (!node) - return Response::Error("No node with given id found"); + return Response::ServerError("No node with given id found"); *result = ResolveNode(v8_session_, node, object_group_name, std::move(execution_context_id)); if (!*result) { - return Response::Error( + return Response::ServerError( "Node with given id does not belong to the document"); } - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::getAttributes( @@ -1413,20 +1416,20 @@ Response InspectorDOMAgent::getAttributes( std::unique_ptr<protocol::Array<String>>* result) { Element* element = nullptr; Response response = AssertElement(node_id, element); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; *result = BuildArrayForElementAttributes(element); - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::requestNode(const String& object_id, int* node_id) { Node* node = nullptr; Response response = NodeForRemoteObjectId(object_id, node); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; *node_id = PushNodePathToFrontend(node); - return Response::OK(); + return Response::Success(); } // static @@ -1544,20 +1547,17 @@ std::unique_ptr<protocol::DOM::Node> InspectorDOMAgent::BuildObjectForNode( } if (element->GetPseudoId()) { - protocol::DOM::PseudoType pseudo_type; - if (InspectorDOMAgent::GetPseudoElementType(element->GetPseudoId(), - &pseudo_type)) - value->setPseudoType(pseudo_type); + value->setPseudoType(ProtocolPseudoElementType(element->GetPseudoId())); } else { - std::unique_ptr<protocol::Array<protocol::DOM::Node>> pseudo_elements = - BuildArrayForPseudoElements(element, nodes_map); - if (pseudo_elements) { - value->setPseudoElements(std::move(pseudo_elements)); - force_push_children = true; - } if (!element->ownerDocument()->xmlVersion().IsEmpty()) value->setXmlVersion(element->ownerDocument()->xmlVersion()); } + std::unique_ptr<protocol::Array<protocol::DOM::Node>> pseudo_elements = + BuildArrayForPseudoElements(element, nodes_map); + if (pseudo_elements) { + value->setPseudoElements(std::move(pseudo_elements)); + force_push_children = true; + } if (auto* insertion_point = DynamicTo<V0InsertionPoint>(element)) { value->setDistributedNodes( @@ -1668,21 +1668,24 @@ InspectorDOMAgent::BuildArrayForContainerChildren( std::unique_ptr<protocol::Array<protocol::DOM::Node>> InspectorDOMAgent::BuildArrayForPseudoElements(Element* element, NodeToIdMap* nodes_map) { - if (!element->GetPseudoElement(kPseudoIdBefore) && - !element->GetPseudoElement(kPseudoIdAfter)) - return nullptr; - - auto pseudo_elements = - std::make_unique<protocol::Array<protocol::DOM::Node>>(); + protocol::Array<protocol::DOM::Node> pseudo_elements; if (element->GetPseudoElement(kPseudoIdBefore)) { - pseudo_elements->emplace_back(BuildObjectForNode( + pseudo_elements.emplace_back(BuildObjectForNode( element->GetPseudoElement(kPseudoIdBefore), 0, false, nodes_map)); } if (element->GetPseudoElement(kPseudoIdAfter)) { - pseudo_elements->emplace_back(BuildObjectForNode( + pseudo_elements.emplace_back(BuildObjectForNode( element->GetPseudoElement(kPseudoIdAfter), 0, false, nodes_map)); } - return pseudo_elements; + if (element->GetPseudoElement(kPseudoIdMarker) && + RuntimeEnabledFeatures::CSSMarkerPseudoElementEnabled()) { + pseudo_elements.emplace_back(BuildObjectForNode( + element->GetPseudoElement(kPseudoIdMarker), 0, false, nodes_map)); + } + if (pseudo_elements.empty()) + return nullptr; + return std::make_unique<protocol::Array<protocol::DOM::Node>>( + std::move(pseudo_elements)); } std::unique_ptr<protocol::Array<protocol::DOM::BackendNode>> @@ -2089,6 +2092,10 @@ void InspectorDOMAgent::FrameOwnerContentUpdated( } void InspectorDOMAgent::PseudoElementCreated(PseudoElement* pseudo_element) { + if (pseudo_element->IsMarkerPseudoElement() && + !RuntimeEnabledFeatures::CSSMarkerPseudoElementEnabled()) { + return; + } Element* parent = pseudo_element->ParentOrShadowHostElement(); if (!parent) return; @@ -2187,19 +2194,19 @@ Node* InspectorDOMAgent::NodeForPath(const String& path) { Response InspectorDOMAgent::pushNodeByPathToFrontend(const String& path, int* node_id) { if (!enabled_.Get()) - return Response::Error("DOM agent is not enabled"); + return Response::ServerError("DOM agent is not enabled"); if (Node* node = NodeForPath(path)) *node_id = PushNodePathToFrontend(node); else - return Response::Error("No node with given path found"); - return Response::OK(); + return Response::ServerError("No node with given path found"); + return Response::Success(); } Response InspectorDOMAgent::pushNodesByBackendIdsToFrontend( std::unique_ptr<protocol::Array<int>> backend_node_ids, std::unique_ptr<protocol::Array<int>>* result) { if (!document_ || !document_node_to_id_map_->Contains(document_)) - return Response::Error("Document needs to be requested first"); + return Response::ServerError("Document needs to be requested first"); *result = std::make_unique<protocol::Array<int>>(); for (int id : *backend_node_ids) { @@ -2210,7 +2217,7 @@ Response InspectorDOMAgent::pushNodesByBackendIdsToFrontend( else (*result)->emplace_back(0); } - return Response::OK(); + return Response::Success(); } class InspectableNode final @@ -2230,10 +2237,10 @@ class InspectableNode final Response InspectorDOMAgent::setInspectedNode(int node_id) { Node* node = nullptr; Response response = AssertNode(node_id, node); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; v8_session_->addInspectedObject(std::make_unique<InspectableNode>(node)); - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::getRelayoutBoundary( @@ -2241,11 +2248,11 @@ Response InspectorDOMAgent::getRelayoutBoundary( int* relayout_boundary_node_id) { Node* node = nullptr; Response response = AssertNode(node_id, node); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; LayoutObject* layout_object = node->GetLayoutObject(); if (!layout_object) { - return Response::Error( + return Response::ServerError( "No layout object for node, perhaps orphan or hidden node"); } while (layout_object && !layout_object->IsDocumentElement() && @@ -2254,7 +2261,7 @@ Response InspectorDOMAgent::getRelayoutBoundary( Node* result_node = layout_object ? layout_object->GeneratingNode() : node->ownerDocument(); *relayout_boundary_node_id = PushNodePathToFrontend(result_node); - return Response::OK(); + return Response::Success(); } protocol::Response InspectorDOMAgent::describeNode( @@ -2266,13 +2273,50 @@ protocol::Response InspectorDOMAgent::describeNode( std::unique_ptr<protocol::DOM::Node>* result) { Node* node = nullptr; Response response = AssertNode(node_id, backend_node_id, object_id, node); - if (!response.isSuccess()) + if (!response.IsSuccess()) return response; if (!node) - return Response::Error("Node not found"); + return Response::ServerError("Node not found"); *result = BuildObjectForNode(node, depth.fromMaybe(0), pierce.fromMaybe(false), nullptr, nullptr); - return Response::OK(); + return Response::Success(); +} + +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) { + Node* node = nullptr; + Response response = AssertNode(node_id, backend_node_id, object_id, node); + if (!response.IsSuccess()) + return response; + node->GetDocument().EnsurePaintLocationDataValidForNode( + node, DocumentUpdateReason::kInspector); + if (!node->isConnected()) + return Response::ServerError("Node is detached from document"); + LayoutObject* layout_object = node->GetLayoutObject(); + if (!layout_object) + return Response::ServerError("Node does not have a layout object"); + PhysicalRect rect_to_scroll = PhysicalRect::EnclosingRect( + layout_object->AbsoluteBoundingBoxFloatRect()); + if (rect.isJust()) { + rect_to_scroll.SetX(rect_to_scroll.X() + + LayoutUnit(rect.fromJust()->getX())); + rect_to_scroll.SetY(rect_to_scroll.Y() + + LayoutUnit(rect.fromJust()->getY())); + rect_to_scroll.SetWidth(LayoutUnit(rect.fromJust()->getWidth())); + rect_to_scroll.SetHeight(LayoutUnit(rect.fromJust()->getHeight())); + } + layout_object->ScrollRectToVisible( + rect_to_scroll, + ScrollAlignment::CreateScrollIntoViewParams( + ScrollAlignment::CenterIfNeeded(), ScrollAlignment::CenterIfNeeded(), + mojom::blink::ScrollType::kProgrammatic, + true /* make_visible_in_visual_viewport */, + mojom::blink::ScrollBehavior::kInstant, + true /* is_for_scroll_sequence */, false /* zoom_into_rect */)); + return Response::Success(); } protocol::Response InspectorDOMAgent::getFrameOwner( @@ -2294,10 +2338,10 @@ protocol::Response InspectorDOMAgent::getFrameOwner( } } if (!frame) - return Response::Error("Frame with the given id was not found."); + return Response::ServerError("Frame with the given id was not found."); auto* frame_owner = DynamicTo<HTMLFrameOwnerElement>(frame->Owner()); if (!frame_owner) { - return Response::Error( + return Response::ServerError( "Frame with the given id does not belong to the target."); } @@ -2307,7 +2351,7 @@ protocol::Response InspectorDOMAgent::getFrameOwner( document_node_to_id_map_->Contains(document_)) { *node_id = PushNodePathToFrontend(frame_owner); } - return Response::OK(); + return Response::Success(); } Response InspectorDOMAgent::getFileInfo(const String& object_id, String* path) { @@ -2317,21 +2361,21 @@ Response InspectorDOMAgent::getFileInfo(const String& object_id, String* path) { std::unique_ptr<v8_inspector::StringBuffer> error; if (!v8_session_->unwrapObject(&error, ToV8InspectorStringView(object_id), &value, &context, nullptr)) - return Response::Error(ToCoreString(std::move(error))); + return Response::ServerError(ToCoreString(std::move(error)).Utf8()); if (!V8File::HasInstance(value, isolate_)) - return Response::Error("Object id doesn't reference a File"); + return Response::ServerError("Object id doesn't reference a File"); File* file = V8File::ToImpl(v8::Local<v8::Object>::Cast(value)); if (!file) { - return Response::Error( + return Response::ServerError( "Couldn't convert object with given objectId to File"); } *path = file->GetPath(); - return Response::OK(); + return Response::Success(); } -void InspectorDOMAgent::Trace(blink::Visitor* visitor) { +void InspectorDOMAgent::Trace(Visitor* visitor) { visitor->Trace(dom_listener_); visitor->Trace(inspected_frames_); visitor->Trace(document_node_to_id_map_); |