Commit 5625ce9a authored by Pavel Feldman's avatar Pavel Feldman Committed by Commit Bot

DevTools: introduce DOMSnapshot.captureSnapshot that dedupes strings and is overall more compact.

Change-Id: I916652f378d2d43cb89c1aa546108d4bc38d8746
Reviewed-on: https://chromium-review.googlesource.com/1121420
Commit-Queue: Pavel Feldman <pfeldman@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#572300}
parent 50abe8b7
......@@ -292,9 +292,8 @@ def CreateTypeDefinitions(json_api):
type_definitions[domain['domain'] + '.' + type['id']] = (
CreateObjectTypeDefinition())
elif type['type'] == 'array':
items_type = type['items']['type']
type_definitions[domain['domain'] + '.' + type['id']] = (
WrapArrayDefinition(type_definitions[items_type]))
ResolveType(type))
elif 'enum' in type:
type_definitions[domain['domain'] + '.' + type['id']] = (
CreateEnumTypeDefinition(domain['domain'], type))
......
......@@ -2092,6 +2092,124 @@ experimental domain DOMSnapshot
# Attribute/property value.
string value
# Index of the string in the strings table.
type StringIndex extends integer
# Index of the string in the strings table.
type ArrayOfStrings extends array of StringIndex
# Data that is only present on rare nodes.
type RareStringData extends object
properties
array of integer index
array of StringIndex value
type RareBooleanData extends object
properties
array of integer index
type RareIntegerData extends object
properties
array of integer index
array of integer value
type Rectangle extends array of number
# DOM tree snapshot.
type DOMTreeSnapshot extends object
properties
# Parent node index.
optional array of integer parentIndex
# `Node`'s nodeType.
optional array of integer nodeType
# `Node`'s nodeName.
optional array of StringIndex nodeName
# `Node`'s nodeValue.
optional array of StringIndex nodeValue
# `Node`'s id, corresponds to DOM.Node.backendNodeId.
optional array of DOM.BackendNodeId backendNodeId
# Attributes of an `Element` node. Flatten name, value pairs.
optional array of ArrayOfStrings attributes
# The index of the node's related layout tree node in the `layoutTreeNodes` array returned by
# `captureSnapshot`, if any.
optional array of integer layoutNodeIndex
# Only set for textarea elements, contains the text value.
optional RareStringData textValue
# Only set for input elements, contains the input's associated text value.
optional RareStringData inputValue
# Only set for radio and checkbox input elements, indicates if the element has been checked
optional RareBooleanData inputChecked
# Only set for option elements, indicates if the element has been selected
optional RareBooleanData optionSelected
# Document URL that `Document` or `FrameOwner` node points to.
optional RareStringData documentURL
# Base URL that `Document` or `FrameOwner` node uses for URL completion.
optional RareStringData baseURL
# Only set for documents, contains the document's content language.
optional RareStringData contentLanguage
# Only set for documents, contains the document's character set encoding.
optional RareStringData documentEncoding
# `DocumentType` node's publicId.
optional RareStringData publicId
# `DocumentType` node's systemId.
optional RareStringData systemId
# Frame ID for frame owner elements and also for the document node.
optional RareStringData frameId
# The index of a frame owner element's content document in the `domNodes` array returned by
# `captureSnapshot`, if any.
optional RareIntegerData contentDocumentIndex
# Index of the imported document's node of a link element in the `domNodes` array returned by
# `captureSnapshot`, if any.
optional RareIntegerData importedDocumentIndex
# Index of the content node of a template element in the `domNodes` array returned by
# `captureSnapshot`.
optional RareIntegerData templateContentIndex
# Type of a pseudo element node.
optional RareStringData pseudoType
# Whether this DOM node responds to mouse clicks. This includes nodes that have had click
# event listeners attached via JavaScript as well as anchor tags that naturally navigate when
# clicked.
optional RareBooleanData isClickable
# The selected url for nodes with a srcset attribute.
optional RareStringData currentSourceURL
# The url of the script (if any) that generates this node.
optional RareStringData originURL
# Details of post layout rendered text positions. The exact layout should not be regarded as
# stable and may change between versions.
type TextBoxSnapshot extends object
properties
# Intex of th elayout tree node that owns this box collection.
array of integer layoutIndex
# The absolute position bounding box.
array of Rectangle bounds
# The starting index in characters, for this post layout textbox substring. Characters that
# would be represented as a surrogate pair in UTF-16 have length 2.
array of integer start
# The number of characters in this post layout textbox substring. Characters that would be
# represented as a surrogate pair in UTF-16 have length 2.
array of integer length
# Details of an element in the DOM tree with a LayoutObject.
type LayoutTreeSnapshot extends object
properties
# The index of the related DOM node in the `domNodes` array returned by `getSnapshot`.
array of integer nodeIndex
# Index into the `computedStyles` array returned by `captureSnapshot`.
array of ArrayOfStrings styles
# The absolute position bounding box.
array of Rectangle bounds
# Contents of the LayoutText, if any.
array of StringIndex text
# The post-layout inline text nodes
TextBoxSnapshot textBoxes
# Computed style snapshot.
type StylesSnapshot extends object
properties
# Whitelisted ComputedStyle property values referenced by styleIndex.
array of ArrayOfStrings values
# Disables DOM snapshot agent for the given page.
command disable
......@@ -2102,7 +2220,7 @@ experimental domain DOMSnapshot
# template contents, and imported documents) in a flattened array, as well as layout and
# white-listed computed style information for the nodes. Shadow DOM in the returned DOM tree is
# flattened.
command getSnapshot
deprecated command getSnapshot
parameters
# Whitelist of computed styles to return.
array of string computedStyleWhitelist
......@@ -2120,6 +2238,22 @@ experimental domain DOMSnapshot
# Whitelisted ComputedStyle properties for each node in the layout tree.
array of ComputedStyle computedStyles
# Returns a document snapshot, including the full DOM tree of the root node (including iframes,
# template contents, and imported documents) in a flattened array, as well as layout and
# white-listed computed style information for the nodes. Shadow DOM in the returned DOM tree is
# flattened.
command captureSnapshot
parameters
# Whitelist of computed styles to return.
array of string computedStyles
returns
# The nodes in the DOM tree. The DOMNode at index 0 corresponds to the root document.
DOMTreeSnapshot nodes
# The nodes in the layout tree.
LayoutTreeSnapshot layout
# Shared string table that all string properties refer to with indexes.
array of string strings
# Query and modify DOM storage.
experimental domain DOMStorage
......
......@@ -49,6 +49,11 @@ class CORE_EXPORT InspectorDOMSnapshotAgent final
layout_tree_nodes,
std::unique_ptr<protocol::Array<protocol::DOMSnapshot::ComputedStyle>>*
computed_styles) override;
protocol::Response captureSnapshot(
std::unique_ptr<protocol::Array<String>> computed_styles,
std::unique_ptr<protocol::DOMSnapshot::DOMTreeSnapshot>* nodes,
std::unique_ptr<protocol::DOMSnapshot::LayoutTreeSnapshot>* layout,
std::unique_ptr<protocol::Array<String>>* strings) override;
bool Enabled() const;
......@@ -60,11 +65,20 @@ class CORE_EXPORT InspectorDOMSnapshotAgent final
InspectorDOMSnapshotAgent(InspectedFrames*, InspectorDOMDebuggerAgent*);
void InnerEnable();
// Adds a DOMNode for the given Node to |dom_nodes_| and returns its index.
int VisitNode(Node*,
bool include_event_listeners,
bool include_user_agent_shadow_tree);
int AddString(const String& string);
void SetRare(protocol::DOMSnapshot::RareIntegerData* data,
int index,
int value);
void SetRare(protocol::DOMSnapshot::RareStringData* data,
int index,
const String& value);
void SetRare(protocol::DOMSnapshot::RareBooleanData* data, int index);
int VisitNode2(Node*, int parent_index);
// Helpers for VisitContainerChildren.
static Node* FirstChild(const Node& node,
bool include_user_agent_shadow_tree);
......@@ -77,23 +91,28 @@ class CORE_EXPORT InspectorDOMSnapshotAgent final
Node* container,
bool include_event_listeners,
bool include_user_agent_shadow_tree);
void VisitContainerChildren2(Node* container, int parent_index);
std::unique_ptr<protocol::Array<int>> VisitPseudoElements(
Element* parent,
bool include_event_listeners,
bool include_user_agent_shadow_tree);
void VisitPseudoElements2(Element* parent, int parent_index);
std::unique_ptr<protocol::Array<protocol::DOMSnapshot::NameValue>>
BuildArrayForElementAttributes(Element*);
std::unique_ptr<protocol::Array<int>> BuildArrayForElementAttributes2(Node*);
// Adds a LayoutTreeNode for the LayoutObject of the given Node to
// |layout_tree_nodes_| and returns its index. Returns -1 if the Node has no
// associated LayoutObject.
int VisitLayoutTreeNode(Node*, int node_index);
int BuildLayoutTreeNode(Node*, int node_index);
// Returns the index of the ComputedStyle in |computed_styles_| for the given
// Node. Adds a new ComputedStyle if necessary, but ensures no duplicates are
// added to |computed_styles_|. Returns -1 if the node has no values for
// styles in |style_whitelist_|.
int GetStyleIndexForNode(Node*);
std::unique_ptr<protocol::Array<int>> BuildStylesForNode(Node*);
// Traverses the PaintLayer tree in paint order to fill |paint_order_map_|.
void TraversePaintLayerTree(Document*);
......@@ -116,6 +135,14 @@ class CORE_EXPORT InspectorDOMSnapshotAgent final
layout_tree_nodes_;
std::unique_ptr<protocol::Array<protocol::DOMSnapshot::ComputedStyle>>
computed_styles_;
std::unique_ptr<protocol::Array<String>> strings_;
WTF::HashMap<String, int> string_table_;
std::unique_ptr<protocol::DOMSnapshot::DOMTreeSnapshot> dom_tree_snapshot_;
std::unique_ptr<protocol::DOMSnapshot::LayoutTreeSnapshot>
layout_tree_snapshot_;
// Maps a style string vector to an index in |computed_styles_|. Used to avoid
// duplicate entries in |computed_styles_|.
std::unique_ptr<ComputedStylesMap> computed_styles_map_;
......
......@@ -2,7 +2,7 @@ Name: inspector protocol
Short Name: inspector_protocol
URL: https://chromium.googlesource.com/deps/inspector_protocol/
Version: 0
Revision: 7efd53047e3df9993c0c1653bb674f2de9b93053
Revision: 5e219fd8e92b250684f978bf0ee237e83d77c682
License: BSD
License File: LICENSE
Security Critical: no
......
......@@ -453,8 +453,7 @@ class Protocol(object):
elif type["type"] == "object":
self.type_definitions[type_name] = create_user_type_definition(domain["domain"], type)
elif type["type"] == "array":
items_type = type["items"]["type"]
self.type_definitions[type_name] = wrap_array_definition(self.type_definitions[items_type])
self.type_definitions[type_name] = self.resolve_type(type)
elif type["type"] == domain["domain"] + ".string":
self.type_definitions[type_name] = create_string_type_definition()
else:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment