diff --git a/runtime/src/main/jni/DOMDomainCallbackHandlers.cpp b/runtime/src/main/jni/DOMDomainCallbackHandlers.cpp new file mode 100644 index 000000000..f06cee3e4 --- /dev/null +++ b/runtime/src/main/jni/DOMDomainCallbackHandlers.cpp @@ -0,0 +1,169 @@ +// +// Created by pkanev on 5/10/2017. +// + +#include +#include +#include +#include "DOMDomainCallbackHandlers.h" + +using namespace tns; + +void DOMDomainCallbackHandlers::DocumentUpdatedCallback(const v8::FunctionCallbackInfo &args) { + auto domAgentInstance = V8DOMAgentImpl::Instance; + + if (!domAgentInstance) { + return; + } + + domAgentInstance->m_frontend.documentUpdated(); +} + +void DOMDomainCallbackHandlers::ChildNodeInsertedCallback(const v8::FunctionCallbackInfo &args) { + try { + auto domAgentInstance = V8DOMAgentImpl::Instance; + + if (!domAgentInstance) { + return; + } + + auto isolate = args.GetIsolate(); + + v8::HandleScope scope(isolate); + + if (args.Length() != 3 || !(args[0]->IsNumber() && args[1]->IsNumber() && args[2]->IsString())) { + throw NativeScriptException("Calling ChildNodeInserted with invalid arguments. Required params: parentId: number, lastId: number, node: JSON String"); + } + + auto parentId = args[0]->ToNumber(isolate); + auto lastId = args[1]->ToNumber(isolate); + auto node = args[2]->ToString(isolate); + + auto nodeString = ArgConverter::ConvertToString(node); + auto nodeCStr = nodeString.c_str(); + auto nodeJson = protocol::parseJSON(nodeCStr); + + protocol::ErrorSupport errorSupport; + auto domNode = protocol::DOM::Node::parse(nodeJson.get(), &errorSupport); + + auto errorSupportString = errorSupport.errors().utf8(); + if (!errorSupportString.empty()) { + auto errorMessage = "Error while parsing debug `DOM Node` object. "; + DEBUG_WRITE_FORCE("%s Error: %s", errorMessage, errorSupportString.c_str()); + } + + domAgentInstance->m_frontend.childNodeInserted(parentId->Int32Value(), lastId->Int32Value(), std::move(domNode)); + } catch (NativeScriptException& e) { + e.ReThrowToV8(); + } catch (std::exception e) { + std::stringstream ss; + ss << "Error: c exception: " << e.what() << std::endl; + NativeScriptException nsEx(ss.str()); + nsEx.ReThrowToV8(); + } catch (...) { + NativeScriptException nsEx(std::string("Error: c exception!")); + nsEx.ReThrowToV8(); + } +} + +void DOMDomainCallbackHandlers::ChildNodeRemovedCallback(const v8::FunctionCallbackInfo &args) { + try { + auto domAgentInstance = V8DOMAgentImpl::Instance; + + if (!domAgentInstance) { + return; + } + + auto isolate = args.GetIsolate(); + + v8::HandleScope scope(isolate); + + if (args.Length() != 2 || !(args[0]->IsNumber() && args[1]->IsNumber())) { + throw NativeScriptException("Calling ChildNodeRemoved with invalid arguments. Required params: parentId: number, nodeId: number"); + } + + auto parentId = args[0]->ToNumber(isolate); + auto nodeId = args[1]->ToNumber(isolate); + + domAgentInstance->m_frontend.childNodeRemoved(parentId->Int32Value(), nodeId->Int32Value()); + } catch (NativeScriptException& e) { + e.ReThrowToV8(); + } catch (std::exception e) { + std::stringstream ss; + ss << "Error: c exception: " << e.what() << std::endl; + NativeScriptException nsEx(ss.str()); + nsEx.ReThrowToV8(); + } catch (...) { + NativeScriptException nsEx(std::string("Error: c exception!")); + nsEx.ReThrowToV8(); + } +} + +void DOMDomainCallbackHandlers::AttributeModifiedCallback(const v8::FunctionCallbackInfo &args) { + try { + auto domAgentInstance = V8DOMAgentImpl::Instance; + + if (!domAgentInstance) { + return; + } + + auto isolate = args.GetIsolate(); + + v8::HandleScope scope(isolate); + + if (args.Length() != 3 || !(args[0]->IsNumber() && args[1]->IsString() && args[2]->IsString())) { + throw NativeScriptException("Calling AttributeModified with invalid arguments. Required params: nodeId: number, name: string, value: string"); + } + + auto nodeId = args[0]->ToNumber(isolate); + auto attributeName = args[1]->ToString(); + auto attributeValue = args[2]->ToString(); + + domAgentInstance->m_frontend.attributeModified(nodeId->Int32Value(), + ArgConverter::ConvertToString(attributeName).c_str(), + ArgConverter::ConvertToString(attributeValue).c_str()); + } catch (NativeScriptException& e) { + e.ReThrowToV8(); + } catch (std::exception e) { + std::stringstream ss; + ss << "Error: c exception: " << e.what() << std::endl; + NativeScriptException nsEx(ss.str()); + nsEx.ReThrowToV8(); + } catch (...) { + NativeScriptException nsEx(std::string("Error: c exception!")); + nsEx.ReThrowToV8(); + } +} + +void DOMDomainCallbackHandlers::AttributeRemovedCallback(const v8::FunctionCallbackInfo &args) { + try { + auto domAgentInstance = V8DOMAgentImpl::Instance; + + if (!domAgentInstance) { + return; + } + auto isolate = args.GetIsolate(); + + v8::HandleScope scope(isolate); + + if (args.Length() != 2 || !(args[0]->IsNumber() && args[1]->IsString())) { + throw NativeScriptException("Calling AttributeRemoved with invalid arguments. Required params: nodeId: number, name: string"); + } + + auto nodeId = args[0]->ToNumber(isolate); + auto attributeName = args[1]->ToString(); + + domAgentInstance->m_frontend.attributeRemoved(nodeId->Int32Value(), + ArgConverter::ConvertToString(attributeName).c_str()); + } catch (NativeScriptException& e) { + e.ReThrowToV8(); + } catch (std::exception e) { + std::stringstream ss; + ss << "Error: c exception: " << e.what() << std::endl; + NativeScriptException nsEx(ss.str()); + nsEx.ReThrowToV8(); + } catch (...) { + NativeScriptException nsEx(std::string("Error: c exception!")); + nsEx.ReThrowToV8(); + } +} diff --git a/runtime/src/main/jni/DOMDomainCallbackHandlers.h b/runtime/src/main/jni/DOMDomainCallbackHandlers.h new file mode 100644 index 000000000..eeb52e106 --- /dev/null +++ b/runtime/src/main/jni/DOMDomainCallbackHandlers.h @@ -0,0 +1,26 @@ +// +// Created by pkanev on 5/10/2017. +// + +#ifndef DOMDOMAINCALLBACKHANDLERS_H +#define DOMDOMAINCALLBACKHANDLERS_H + +#include +#include +#include "JsV8InspectorClient.h" +#include "NativeScriptException.h" + +namespace tns { + class DOMDomainCallbackHandlers { + + public: + static void DocumentUpdatedCallback(const v8::FunctionCallbackInfo& args); + static void ChildNodeInsertedCallback(const v8::FunctionCallbackInfo& args); + static void ChildNodeRemovedCallback(const v8::FunctionCallbackInfo& args); + static void AttributeModifiedCallback(const v8::FunctionCallbackInfo& args); + static void AttributeRemovedCallback(const v8::FunctionCallbackInfo& args); + }; +} + + +#endif //DOMDOMAINCALLBACKHANDLERS_H diff --git a/runtime/src/main/jni/JsV8InspectorClient.cpp b/runtime/src/main/jni/JsV8InspectorClient.cpp index 2fbabb31d..394f1f68a 100644 --- a/runtime/src/main/jni/JsV8InspectorClient.cpp +++ b/runtime/src/main/jni/JsV8InspectorClient.cpp @@ -6,6 +6,7 @@ #include "NativeScriptException.h" #include "ArgConverter.h" +#include "DOMDomainCallbackHandlers.h" #include "NetworkDomainCallbackHandlers.h" using namespace std; @@ -272,6 +273,12 @@ void JsV8InspectorClient::attachInspectorCallbacks(Isolate* isolate, inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "loadingFinished"), FunctionTemplate::New(isolate, NetworkDomainCallbackHandlers::LoadingFinishedCallback)); inspectorJSObject->SetAccessor(ArgConverter::ConvertToV8String(isolate, "isConnected"), JsV8InspectorClient::InspectorIsConnectedGetterCallback); + inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "documentUpdated"), FunctionTemplate::New(isolate, DOMDomainCallbackHandlers::DocumentUpdatedCallback)); + inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "childNodeInserted"), FunctionTemplate::New(isolate, DOMDomainCallbackHandlers::ChildNodeInsertedCallback)); + inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "childNodeRemoved"), FunctionTemplate::New(isolate, DOMDomainCallbackHandlers::ChildNodeRemovedCallback)); + inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "attributeModified"), FunctionTemplate::New(isolate, DOMDomainCallbackHandlers::AttributeModifiedCallback)); + inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "attributeRemoved"), FunctionTemplate::New(isolate, DOMDomainCallbackHandlers::AttributeRemovedCallback)); + globalObjectTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__inspector"), inspectorJSObject); } diff --git a/runtime/src/main/jni/v8_inspector/src/inspector/js_protocol.json b/runtime/src/main/jni/v8_inspector/src/inspector/js_protocol.json index c2e0d7947..3e751ca94 100644 --- a/runtime/src/main/jni/v8_inspector/src/inspector/js_protocol.json +++ b/runtime/src/main/jni/v8_inspector/src/inspector/js_protocol.json @@ -2162,5 +2162,1037 @@ ] } ] - }] + }, + { + "domain": "DOM", + "description": "This domain exposes DOM read/write operations. Each DOM Node is represented with its mirror object that has an id. This id can be used to get additional information on the Node, resolve it into the JavaScript object wrapper, etc. It is important that client receives DOM events only for the nodes that are known to the client. Backend keeps track of the nodes that were sent to the client and never sends the same node twice. It is client's responsibility to collect information about the nodes that were sent to the client.", + "types": [ + { + "id": "NodeId", + "type": "integer", + "description": "Unique DOM node identifier." + }, + { + "id": "BackendNodeId", + "type": "integer", + "description": "Unique DOM node identifier used to reference a node that may not have been pushed to the front-end." + }, + { + "id": "PseudoType", + "type": "string", + "enum": [ + "before", + "after" + ], + "description": "Pseudo element type." + }, + { + "id": "ShadowRootType", + "type": "string", + "enum": [ + "user-agent", + "open", + "closed" + ], + "description": "Shadow root type." + }, + { + "id": "LiveRegionRelevant", + "type": "string", + "enum": [ + "additions", + "removals", + "text" + ], + "description": "Token values of @aria-relevant attribute." + }, + { + "id": "Node", + "type": "object", + "properties": [ + { + "name": "nodeId", + "$ref": "NodeId", + "description": "Node identifier that is passed into the rest of the DOM messages as the nodeId. Backend will only push node with given id once. It is aware of all requested nodes and will only fire DOM events for nodes known to the client." + }, + { + "name": "nodeType", + "type": "integer", + "description": "Node's nodeType." + }, + { + "name": "nodeName", + "type": "string", + "description": "Node's nodeName." + }, + { + "name": "localName", + "type": "string", + "description": "Node's localName." + }, + { + "name": "nodeValue", + "type": "string", + "description": "Node's nodeValue." + }, + { + "name": "childNodeCount", + "type": "integer", + "optional": true, + "description": "Child count for Container nodes." + }, + { + "name": "children", + "type": "array", + "optional": true, + "items": { + "$ref": "Node" + }, + "description": "Child nodes of this node when requested with children." + }, + { + "name": "attributes", + "type": "array", + "optional": true, + "items": { + "type": "string" + }, + "description": "Attributes of the Element node in the form of flat array [name1, value1, name2, value2]." + }, + { + "name": "documentURL", + "type": "string", + "optional": true, + "description": "Document URL that Document or FrameOwner node points to." + }, + { + "name": "baseURL", + "type": "string", + "optional": true, + "description": "Base URL that Document or FrameOwner node uses for URL completion." + }, + { + "name": "publicId", + "type": "string", + "optional": true, + "description": "DocumentType's publicId." + }, + { + "name": "systemId", + "type": "string", + "optional": true, + "description": "DocumentType's systemId." + }, + { + "name": "xmlVersion", + "type": "string", + "optional": true, + "description": "Document's XML version in case of XML documents." + }, + { + "name": "name", + "type": "string", + "optional": true, + "description": "Attr's name." + }, + { + "name": "value", + "type": "string", + "optional": true, + "description": "Attr's value." + }, + { + "name": "pseudoType", + "$ref": "PseudoType", + "optional": true, + "description": "Pseudo element type for this node." + }, + { + "name": "shadowRootType", + "$ref": "ShadowRootType", + "optional": true, + "description": "Shadow root type." + }, + { + "name": "frameId", + "$ref": "Network.FrameId", + "optional": true, + "description": "Frame ID for frame owner elements." + }, + { + "name": "contentDocument", + "$ref": "Node", + "optional": true, + "description": "Content document for frame owner elements." + }, + { + "name": "shadowRoots", + "type": "array", + "optional": true, + "items": { + "$ref": "Node" + }, + "description": "Shadow root list for given element host." + }, + { + "name": "templateContent", + "$ref": "Node", + "optional": true, + "description": "Content document fragment for template elements" + }, + { + "name": "pseudoElements", + "type": "array", + "items": { + "$ref": "Node" + }, + "optional": true, + "description": "Pseudo elements associated with this node." + }, + { + "name": "role", + "type": "string", + "optional": true, + "description": "Computed value for first recognized role token, default role per element, or overridden role." + }, + { + "name": "contentSecurityPolicyHash", + "type": "string", + "optional": true, + "description": "Computed SHA-256 Content Security Policy hash source for given element." + } + ], + "description": "DOM interaction is implemented in terms of mirror objects that represent the actual DOM nodes. DOMNode is a base node mirror type." + }, + { + "id": "RGBAColor", + "type": "object", + "properties": [ + { + "name": "r", + "type": "integer", + "description": "The red component, in the [0-255] range." + }, + { + "name": "g", + "type": "integer", + "description": "The green component, in the [0-255] range." + }, + { + "name": "b", + "type": "integer", + "description": "The blue component, in the [0-255] range." + }, + { + "name": "a", + "type": "number", + "optional": true, + "description": "The alpha component, in the [0-1] range (default: 1)." + } + ], + "description": "A structure holding an RGBA color." + }, + { + "id": "Quad", + "type": "array", + "items": { + "type": "number" + }, + "minItems": 8, + "maxItems": 8, + "description": "An array of quad vertices, x immediately followed by y for each point, points clock-wise." + }, + { + "id": "HighlightConfig", + "type": "object", + "properties": [ + { + "name": "showInfo", + "type": "boolean", + "optional": true, + "description": "Whether the node info tooltip should be shown (default: false)." + }, + { + "name": "contentColor", + "$ref": "RGBAColor", + "optional": true, + "description": "The content box highlight fill color (default: transparent)." + }, + { + "name": "paddingColor", + "$ref": "RGBAColor", + "optional": true, + "description": "The padding highlight fill color (default: transparent)." + }, + { + "name": "borderColor", + "$ref": "RGBAColor", + "optional": true, + "description": "The border highlight fill color (default: transparent)." + }, + { + "name": "marginColor", + "$ref": "RGBAColor", + "optional": true, + "description": "The margin highlight fill color (default: transparent)." + } + ], + "description": "Configuration data for the highlighting of page elements." + } + ], + "commands": [ + { + "name": "enable" + }, + { + "name": "disable" + }, + { + "name": "getDocument", + "returns": [ + { + "name": "root", + "$ref": "Node", + "description": "Resulting node." + } + ], + "description": "Returns the root DOM node to the caller." + }, + { + "name": "removeNode", + "parameters": [ + { + "name": "nodeId", + "$ref": "NodeId", + "description": "Id of the node to remove." + } + ], + "description": "Removes node with given id." + }, + { + "name": "setAttributeValue", + "parameters": [ + { + "name": "nodeId", + "$ref": "NodeId", + "description": "Id of the element to set attribute for." + }, + { + "name": "name", + "type": "string", + "description": "Attribute name." + }, + { + "name": "value", + "type": "string", + "description": "Attribute value." + } + ], + "description": "Sets attribute for an element with given id." + }, + { + "name": "setAttributesAsText", + "parameters": [ + { + "name": "nodeId", + "$ref": "NodeId", + "description": "Id of the element to set attributes for." + }, + { + "name": "text", + "type": "string", + "description": "Text with a number of attributes. Will parse this text using HTML parser." + }, + { + "name": "name", + "type": "string", + "optional": true, + "description": "Attribute name to replace with new attributes derived from text in case text parsed successfully." + } + ], + "description": "Sets attributes on element with given id. This method is useful when user edits some existing attribute value and types in several attribute name/value pairs." + }, + { + "name": "removeAttribute", + "parameters": [ + { + "name": "nodeId", + "$ref": "NodeId", + "description": "Id of the element to remove attribute from." + }, + { + "name": "name", + "type": "string", + "description": "Name of the attribute to remove." + } + ], + "description": "Removes attribute with given name from an element with given id." + }, + { + "name": "performSearch", + "parameters": [ + { + "name": "query", + "type": "string", + "description": "Plain text or query selector or XPath search query." + }, + { + "name": "nodeIds", + "type": "array", + "items": { + "$ref": "NodeId" + }, + "optional": true, + "description": "Ids of nodes to use as starting points for the search." + } + ], + "returns": [ + { + "name": "searchId", + "type": "string", + "description": "Unique search session identifier." + }, + { + "name": "resultCount", + "type": "integer", + "description": "Number of search results." + } + ], + "description": "Searches for a given string in the DOM tree. Use getSearchResults to access search results or cancelSearch to end this search session." + }, + { + "name": "getSearchResults", + "parameters": [ + { + "name": "searchId", + "type": "string", + "description": "Unique search session identifier." + }, + { + "name": "fromIndex", + "type": "integer", + "description": "Start index of the search result to be returned." + }, + { + "name": "toIndex", + "type": "integer", + "description": "End index of the search result to be returned." + } + ], + "returns": [ + { + "name": "nodeIds", + "type": "array", + "items": { + "$ref": "NodeId" + }, + "description": "Ids of the search result nodes." + } + ], + "description": "Returns search results from given fromIndex to given toIndex from the sarch with the given identifier." + }, + { + "name": "discardSearchResults", + "parameters": [ + { + "name": "searchId", + "type": "string", + "description": "Unique search session identifier." + } + ], + "description": "Discards search results from the session with the given id. getSearchResults should no longer be called for that search." + }, + { + "name": "highlightNode", + "parameters": [ + { + "name": "highlightConfig", + "$ref": "HighlightConfig", + "description": "A descriptor for the highlight appearance." + }, + { + "name": "nodeId", + "$ref": "NodeId", + "optional": true, + "description": "Identifier of the node to highlight." + }, + { + "name": "objectId", + "$ref": "Runtime.RemoteObjectId", + "optional": true, + "description": "JavaScript object id of the node to be highlighted." + } + ], + "description": "Highlights DOM node with given id or with the given JavaScript object wrapper. Either nodeId or objectId must be specified." + }, + { + "name": "hideHighlight", + "description": "Hides DOM node highlight." + }, + { + "name": "resolveNode", + "parameters": [ + { + "name": "nodeId", + "$ref": "NodeId", + "description": "Id of the node to resolve." + }, + { + "name": "objectGroup", + "type": "string", + "optional": true, + "description": "Symbolic group name that can be used to release multiple objects." + } + ], + "returns": [ + { + "name": "object", + "$ref": "Runtime.RemoteObject", + "description": "JavaScript object wrapper for given node." + } + ], + "description": "Resolves JavaScript node object for given node id." + } + ], + "events": [ + { + "name": "documentUpdated", + "description": "Fired when Document has been totally updated. Node ids are no longer valid." + }, + { + "name": "setChildNodes", + "parameters": [ + { + "name": "parentId", + "$ref": "NodeId", + "description": "Parent node id to populate with children." + }, + { + "name": "nodes", + "type": "array", + "items": { + "$ref": "Node" + }, + "description": "Child nodes array." + } + ], + "description": "Fired when backend wants to provide client with the missing DOM structure. This happens upon most of the calls requesting node ids." + }, + { + "name": "attributeModified", + "parameters": [ + { + "name": "nodeId", + "$ref": "NodeId", + "description": "Id of the node that has changed." + }, + { + "name": "name", + "type": "string", + "description": "Attribute name." + }, + { + "name": "value", + "type": "string", + "description": "Attribute value." + } + ], + "description": "Fired when Element's attribute is modified." + }, + { + "name": "attributeRemoved", + "parameters": [ + { + "name": "nodeId", + "$ref": "NodeId", + "description": "Id of the node that has changed." + }, + { + "name": "name", + "type": "string", + "description": "A ttribute name." + } + ], + "description": "Fired when Element's attribute is removed." + }, + { + "name": "inlineStyleInvalidated", + "parameters": [ + { + "name": "nodeIds", + "type": "array", + "items": { + "$ref": "NodeId" + }, + "description": "Ids of the nodes for which the inline styles have been invalidated." + } + ], + "description": "Fired when Element's inline style is modified via a CSS property modification." + }, + { + "name": "characterDataModified", + "parameters": [ + { + "name": "nodeId", + "$ref": "NodeId", + "description": "Id of the node that has changed." + }, + { + "name": "characterData", + "type": "string", + "description": "New text value." + } + ], + "description": "Mirrors DOMCharacterDataModified event." + }, + { + "name": "childNodeCountUpdated", + "parameters": [ + { + "name": "nodeId", + "$ref": "NodeId", + "description": "Id of the node that has changed." + }, + { + "name": "childNodeCount", + "type": "integer", + "description": "New node count." + } + ], + "description": "Fired when Container's child node count has changed." + }, + { + "name": "childNodeInserted", + "parameters": [ + { + "name": "parentNodeId", + "$ref": "NodeId", + "description": "Id of the node that has changed." + }, + { + "name": "previousNodeId", + "$ref": "NodeId", + "description": "If of the previous siblint." + }, + { + "name": "node", + "$ref": "Node", + "description": "Inserted node data." + } + ], + "description": "Mirrors DOMNodeInserted event." + }, + { + "name": "childNodeRemoved", + "parameters": [ + { + "name": "parentNodeId", + "$ref": "NodeId", + "description": "Parent id." + }, + { + "name": "nodeId", + "$ref": "NodeId", + "description": "Id of the node that has been removed." + } + ], + "description": "Mirrors DOMNodeRemoved event." + }, + { + "name": "shadowRootPushed", + "parameters": [ + { + "name": "hostId", + "$ref": "NodeId", + "description": "Host element id." + }, + { + "name": "root", + "$ref": "Node", + "description": "Shadow root." + } + ], + "description": "Called when shadow root is pushed into the element." + }, + { + "name": "shadowRootPopped", + "parameters": [ + { + "name": "hostId", + "$ref": "NodeId", + "description": "Host element id." + }, + { + "name": "rootId", + "$ref": "NodeId", + "description": "Shadow root id." + } + ], + "description": "Called when shadow root is popped from the element." + }, + { + "name": "pseudoElementAdded", + "parameters": [ + { + "name": "parentId", + "$ref": "NodeId", + "description": "Pseudo element's parent element id." + }, + { + "name": "pseudoElement", + "$ref": "Node", + "description": "The added pseudo element." + } + ], + "description": "Called when a pseudo element is added to an element." + }, + { + "name": "pseudoElementRemoved", + "parameters": [ + { + "name": "parentId", + "$ref": "NodeId", + "description": "Pseudo element's parent element id." + }, + { + "name": "pseudoElementId", + "$ref": "NodeId", + "description": "The removed pseudo element id." + } + ], + "description": "Called when a pseudo element is removed from an element." + } + ] + }, + { + "domain": "CSS", + "experimental": true, + "description": "This domain exposes CSS read/write operations. All CSS objects (stylesheets, rules, and styles) have an associated 'id' used in subsequent operations on the related object. Each object type has a specific 'id' structure, and those are not interchangeable between objects of different kinds. CSS objects can be loaded using the get*ForNode() calls (which accept a DOM node id). A client can also discover all the existing stylesheets with the getAllStyleSheets() method (or keeping track of the styleSheetAdded/styleSheetRemoved events) and subsequently load the required stylesheet contents using the getStyleSheet[Text]() methods.", + "types": [ + { + "id": "StyleSheetId", + "type": "string" + }, + { + "id": "StyleSheetOrigin", + "type": "string", + "enum": ["injected", "user-agent", "inspector", "regular"], + "description": "Stylesheet type: \"injected\" for stylesheets injected via extension, \"user-agent\" for user-agent stylesheets, \"inspector\" for stylesheets created by the inspector (i.e. those holding the \"via inspector\" rules), \"regular\" for regular stylesheets." + }, + { + "id": "PseudoElementMatches", + "type": "object", + "properties": [ + { "name": "pseudoType", "$ref": "DOM.PseudoType", "description": "Pseudo element type."}, + { "name": "matches", "type": "array", "items": { "$ref": "RuleMatch" }, "description": "Matches of CSS rules applicable to the pseudo style."} + ], + "description": "CSS rule collection for a single pseudo style." + }, + { + "id": "InheritedStyleEntry", + "type": "object", + "properties": [ + { "name": "inlineStyle", "$ref": "CSSStyle", "optional": true, "description": "The ancestor node's inline style, if any, in the style inheritance chain." }, + { "name": "matchedCSSRules", "type": "array", "items": { "$ref": "RuleMatch" }, "description": "Matches of CSS rules matching the ancestor node in the style inheritance chain." } + ], + "description": "Inherited CSS rule collection from ancestor node." + }, + { + "id": "RuleMatch", + "type": "object", + "properties": [ + { "name": "rule", "$ref": "CSSRule", "description": "CSS rule in the match." }, + { "name": "matchingSelectors", "type": "array", "items": { "type": "integer" }, "description": "Matching selector indices in the rule's selectorList selectors (0-based)." } + ], + "description": "Match data for a CSS rule." + }, + { + "id": "Value", + "type": "object", + "properties": [ + { "name": "text", "type": "string", "description": "Value text." }, + { "name": "range", "$ref": "SourceRange", "optional": true, "description": "Value range in the underlying resource (if available)." } + ], + "description": "Data for a simple selector (these are delimited by commas in a selector list)." + }, + { + "id": "SelectorList", + "type": "object", + "properties": [ + { "name": "selectors", "type": "array", "items": { "$ref": "Value" }, "description": "Selectors in the list." }, + { "name": "text", "type": "string", "description": "Rule selector text." } + ], + "description": "Selector list data." + }, + { + "id": "CSSStyleSheetHeader", + "type": "object", + "properties": [ + { "name": "styleSheetId", "$ref": "StyleSheetId", "description": "The stylesheet identifier."}, + { "name": "frameId", "type": "string", "description": "Owner frame identifier."}, + { "name": "sourceURL", "type": "string", "description": "Stylesheet resource URL."}, + { "name": "sourceMapURL", "type": "string", "optional": true, "description": "URL of source map associated with the stylesheet (if any)." }, + { "name": "origin", "$ref": "StyleSheetOrigin", "description": "Stylesheet origin."}, + { "name": "title", "type": "string", "description": "Stylesheet title."}, + { "name": "ownerNode", "$ref": "DOM.BackendNodeId", "optional": true, "description": "The backend id for the owner node of the stylesheet." }, + { "name": "disabled", "type": "boolean", "description": "Denotes whether the stylesheet is disabled."}, + { "name": "hasSourceURL", "type": "boolean", "optional": true, "description": "Whether the sourceURL field value comes from the sourceURL comment." }, + { "name": "isInline", "type": "boolean", "description": "Whether this stylesheet is created for STYLE tag by parser. This flag is not set for document.written STYLE tags." }, + { "name": "startLine", "type": "number", "description": "Line offset of the stylesheet within the resource (zero based)." }, + { "name": "startColumn", "type": "number", "description": "Column offset of the stylesheet within the resource (zero based)." } + ], + "description": "CSS stylesheet metainformation." + }, + { + "id": "CSSRule", + "type": "object", + "properties": [ + { "name": "styleSheetId", "$ref": "StyleSheetId", "optional": true, "description": "The css style sheet identifier (absent for user agent stylesheet and user-specified stylesheet rules) this rule came from." }, + { "name": "selectorList", "$ref": "SelectorList", "description": "Rule selector data." }, + { "name": "origin", "$ref": "StyleSheetOrigin", "description": "Parent stylesheet's origin."}, + { "name": "style", "$ref": "CSSStyle", "description": "Associated style declaration." }, + { "name": "media", "type": "array", "items": { "$ref": "CSSMedia" }, "optional": true, "description": "Media list array (for rules involving media queries). The array enumerates media queries starting with the innermost one, going outwards." } + ], + "description": "CSS rule representation." + }, + { + "id": "SourceRange", + "type": "object", + "properties": [ + { "name": "startLine", "type": "integer", "description": "Start line of range." }, + { "name": "startColumn", "type": "integer", "description": "Start column of range (inclusive)." }, + { "name": "endLine", "type": "integer", "description": "End line of range" }, + { "name": "endColumn", "type": "integer", "description": "End column of range (exclusive)." } + ], + "description": "Text range within a resource. All numbers are zero-based." + }, + { + "id": "ShorthandEntry", + "type": "object", + "properties": [ + { "name": "name", "type": "string", "description": "Shorthand name." }, + { "name": "value", "type": "string", "description": "Shorthand value." }, + { "name": "important", "type": "boolean", "optional": true, "description": "Whether the property has \"!important\" annotation (implies false if absent)." } + ] + }, + { + "id": "CSSComputedStyleProperty", + "type": "object", + "properties": [ + { "name": "name", "type": "string", "description": "Computed style property name." }, + { "name": "value", "type": "string", "description": "Computed style property value." } + ] + }, + { + "id": "CSSStyle", + "type": "object", + "properties": [ + { "name": "styleSheetId", "$ref": "StyleSheetId", "optional": true, "description": "The css style sheet identifier (absent for user agent stylesheet and user-specified stylesheet rules) this rule came from." }, + { "name": "cssProperties", "type": "array", "items": { "$ref": "CSSProperty" }, "description": "CSS properties in the style." }, + { "name": "shorthandEntries", "type": "array", "items": { "$ref": "ShorthandEntry" }, "description": "Computed values for all shorthands found in the style." }, + { "name": "cssText", "type": "string", "optional": true, "description": "Style declaration text (if available)." }, + { "name": "range", "$ref": "SourceRange", "optional": true, "description": "Style declaration range in the enclosing stylesheet (if available)." } + ], + "description": "CSS style representation." + }, + { + "id": "CSSProperty", + "type": "object", + "properties": [ + { "name": "name", "type": "string", "description": "The property name." }, + { "name": "value", "type": "string", "description": "The property value." }, + { "name": "important", "type": "boolean", "optional": true, "description": "Whether the property has \"!important\" annotation (implies false if absent)." }, + { "name": "implicit", "type": "boolean", "optional": true, "description": "Whether the property is implicit (implies false if absent)." }, + { "name": "text", "type": "string", "optional": true, "description": "The full property text as specified in the style." }, + { "name": "parsedOk", "type": "boolean", "optional": true, "description": "Whether the property is understood by the browser (implies true if absent)." }, + { "name": "disabled", "type": "boolean", "optional": true, "description": "Whether the property is disabled by the user (present for source-based properties only)." }, + { "name": "range", "$ref": "SourceRange", "optional": true, "description": "The entire property range in the enclosing style declaration (if available)." } + ], + "description": "CSS property declaration data." + }, + { + "id": "CSSMedia", + "type": "object", + "properties": [ + { "name": "text", "type": "string", "description": "Media query text." }, + { "name": "source", "type": "string", "enum": ["mediaRule", "importRule", "linkedSheet", "inlineSheet"], "description": "Source of the media query: \"mediaRule\" if specified by a @media rule, \"importRule\" if specified by an @import rule, \"linkedSheet\" if specified by a \"media\" attribute in a linked stylesheet's LINK tag, \"inlineSheet\" if specified by a \"media\" attribute in an inline stylesheet's STYLE tag." }, + { "name": "sourceURL", "type": "string", "optional": true, "description": "URL of the document containing the media query description." }, + { "name": "range", "$ref": "SourceRange", "optional": true, "description": "The associated rule (@media or @import) header range in the enclosing stylesheet (if available)." }, + { "name": "styleSheetId", "$ref": "StyleSheetId", "optional": true, "description": "Identifier of the stylesheet containing this object (if exists)." }, + { "name": "mediaList", "type": "array", "items": { "$ref": "MediaQuery" }, "optional": true, "experimental": true, "description": "Array of media queries." } + ], + "description": "CSS media rule descriptor." + }, + { + "id": "MediaQuery", + "type": "object", + "properties": [ + { "name": "expressions", "type": "array", "items": { "$ref": "MediaQueryExpression" }, "description": "Array of media query expressions." }, + { "name": "active", "type": "boolean", "description": "Whether the media query condition is satisfied." } + ], + "description": "Media query descriptor.", + "experimental": true + }, + { + "id": "MediaQueryExpression", + "type": "object", + "properties": [ + { "name": "value", "type": "number", "description": "Media query expression value."}, + { "name": "unit", "type": "string", "description": "Media query expression units."}, + { "name": "feature", "type": "string", "description": "Media query expression feature."}, + { "name": "valueRange", "$ref": "SourceRange", "optional": true, "description": "The associated range of the value text in the enclosing stylesheet (if available)." }, + { "name": "computedLength", "type": "number", "optional": true, "description": "Computed length of media query expression (if applicable)."} + ], + "description": "Media query expression descriptor.", + "experimental": true + }, + { + "id": "PlatformFontUsage", + "type": "object", + "properties": [ + { "name": "familyName", "type": "string", "description": "Font's family name reported by platform."}, + { "name": "isCustomFont", "type": "boolean", "description": "Indicates if the font was downloaded or resolved locally."}, + { "name": "glyphCount", "type": "number", "description": "Amount of glyphs that were rendered with this font."} + ], + "description": "Information about amount of glyphs that were rendered with given font.", + "experimental": true + }, + { + "id": "CSSKeyframesRule", + "type": "object", + "properties": [ + { "name": "animationName", "$ref": "Value", "description": "Animation name." }, + { "name": "keyframes", "type": "array", "items": { "$ref": "CSSKeyframeRule" }, "description": "List of keyframes." } + ], + "description": "CSS keyframes rule representation." + }, + { + "id": "CSSKeyframeRule", + "type": "object", + "properties": [ + { "name": "styleSheetId", "$ref": "StyleSheetId", "optional": true, "description": "The css style sheet identifier (absent for user agent stylesheet and user-specified stylesheet rules) this rule came from." }, + { "name": "origin", "$ref": "StyleSheetOrigin", "description": "Parent stylesheet's origin."}, + { "name": "keyText", "$ref": "Value", "description": "Associated key text." }, + { "name": "style", "$ref": "CSSStyle", "description": "Associated style declaration." } + ], + "description": "CSS keyframe rule representation." + }, + { + "id": "StyleDeclarationEdit", + "type": "object", + "properties": [ + { "name": "styleSheetId", "$ref": "StyleSheetId", "description": "The css style sheet identifier." }, + { "name": "range", "$ref": "SourceRange", "description": "The range of the style text in the enclosing stylesheet." }, + { "name": "text", "type": "string", "description": "New style text."} + ], + "description": "A descriptor of operation to mutate style declaration text." + } + ], + "commands": [ + { + "name": "enable", + "async": true, + "description": "Enables the CSS agent for the given page. Clients should not assume that the CSS agent has been enabled until the result of this command is received." + }, + { + "name": "disable", + "description": "Disables the CSS agent for the given page." + }, + { + "name": "getMatchedStylesForNode", + "parameters": [ + { "name": "nodeId", "$ref": "DOM.NodeId" } + ], + "returns": [ + { "name": "inlineStyle", "$ref": "CSSStyle", "optional": true, "description": "Inline style for the specified DOM node." }, + { "name": "attributesStyle", "$ref": "CSSStyle", "optional": true, "description": "Attribute-defined element style (e.g. resulting from \"width=20 height=100%\")."}, + { "name": "matchedCSSRules", "type": "array", "items": { "$ref": "RuleMatch" }, "optional": true, "description": "CSS rules matching this node, from all applicable stylesheets." }, + { "name": "pseudoElements", "type": "array", "items": { "$ref": "PseudoElementMatches" }, "optional": true, "description": "Pseudo style matches for this node." }, + { "name": "inherited", "type": "array", "items": { "$ref": "InheritedStyleEntry" }, "optional": true, "description": "A chain of inherited styles (from the immediate node parent up to the DOM tree root)." }, + { "name": "cssKeyframesRules", "type": "array", "items": { "$ref": "CSSKeyframesRule" }, "optional": true, "description": "A list of CSS keyframed animations matching this node." } + ], + "description": "Returns requested styles for a DOM node identified by nodeId." + }, + { + "name": "getInlineStylesForNode", + "parameters": [ + { "name": "nodeId", "$ref": "DOM.NodeId" } + ], + "returns": [ + { "name": "inlineStyle", "$ref": "CSSStyle", "optional": true, "description": "Inline style for the specified DOM node." }, + { "name": "attributesStyle", "$ref": "CSSStyle", "optional": true, "description": "Attribute-defined element style (e.g. resulting from \"width=20 height=100%\")."} + ], + "description": "Returns the styles defined inline (explicitly in the \"style\" attribute and implicitly, using DOM attributes) for a DOM node identified by nodeId." + }, + { + "name": "getComputedStyleForNode", + "parameters": [ + { "name": "nodeId", "$ref": "DOM.NodeId" } + ], + "returns": [ + { "name": "computedStyle", "type": "array", "items": { "$ref": "CSSComputedStyleProperty" }, "description": "Computed style for the specified DOM node." } + ], + "description": "Returns the computed style for a DOM node identified by nodeId." + }, + { + "name": "getPlatformFontsForNode", + "parameters": [ + { "name": "nodeId", "$ref": "DOM.NodeId" } + ], + "returns": [ + { "name": "fonts", "type": "array", "items": { "$ref": "PlatformFontUsage" }, "description": "Usage statistics for every employed platform font." } + ], + "description": "Requests information about platform fonts which we used to render child TextNodes in the given node.", + "experimental": true + }, + { + "name": "getStyleSheetText", + "parameters": [ + { "name": "styleSheetId", "$ref": "StyleSheetId" } + ], + "returns": [ + { "name": "text", "type": "string", "description": "The stylesheet text." } + ], + "description": "Returns the current textual content and the URL for a stylesheet." + } + ], + "events": [ + { + "name": "mediaQueryResultChanged", + "description": "Fires whenever a MediaQuery result changes (for example, after a browser window has been resized.) The current implementation considers only viewport-dependent media features." + }, + { + "name": "fontsUpdated", + "description": "Fires whenever a web font gets loaded." + }, + { + "name": "styleSheetChanged", + "parameters": [ + { "name": "styleSheetId", "$ref": "StyleSheetId" } + ], + "description": "Fired whenever a stylesheet is changed as a result of the client operation." + }, + { + "name": "styleSheetAdded", + "parameters": [ + { "name": "header", "$ref": "CSSStyleSheetHeader", "description": "Added stylesheet metainfo." } + ], + "description": "Fired whenever an active document stylesheet is added." + }, + { + "name": "styleSheetRemoved", + "parameters": [ + { "name": "styleSheetId", "$ref": "StyleSheetId", "description": "Identifier of the removed stylesheet." } + ], + "description": "Fired whenever an active document stylesheet is removed." + }, + { + "name": "layoutEditorChange", + "parameters": [ + { "name": "styleSheetId", "$ref": "StyleSheetId", "description": "Identifier of the stylesheet where the modification occurred." }, + { "name": "changeRange", "$ref": "SourceRange", "description": "Range where the modification occurred." } + ] + } + ] + }] } diff --git a/runtime/src/main/jni/v8_inspector/src/inspector/protocol/CSS.cpp b/runtime/src/main/jni/v8_inspector/src/inspector/protocol/CSS.cpp new file mode 100644 index 000000000..b5a63c84f --- /dev/null +++ b/runtime/src/main/jni/v8_inspector/src/inspector/protocol/CSS.cpp @@ -0,0 +1,1255 @@ +// This file is generated + +// Copyright (c) 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "src/inspector/protocol/CSS.h" + +#include "src/inspector/protocol/Protocol.h" + +namespace v8_inspector { +namespace protocol { +namespace CSS { + +// ------------- Enum values from types. + +const char Metainfo::domainName[] = "CSS"; +const char Metainfo::commandPrefix[] = "CSS."; +const char Metainfo::version[] = "1.2"; + +namespace StyleSheetOriginEnum { +const char* Injected = "injected"; +const char* UserAgent = "user-agent"; +const char* Inspector = "inspector"; +const char* Regular = "regular"; +} // namespace StyleSheetOriginEnum + +std::unique_ptr PseudoElementMatches::parse(protocol::Value* value, ErrorSupport* errors) +{ + if (!value || value->type() != protocol::Value::TypeObject) { + errors->addError("object expected"); + return nullptr; + } + + std::unique_ptr result(new PseudoElementMatches()); + protocol::DictionaryValue* object = DictionaryValue::cast(value); + errors->push(); + protocol::Value* pseudoTypeValue = object->get("pseudoType"); + errors->setName("pseudoType"); + result->m_pseudoType = ValueConversions::parse(pseudoTypeValue, errors); + protocol::Value* matchesValue = object->get("matches"); + errors->setName("matches"); + result->m_matches = ValueConversions>::parse(matchesValue, errors); + errors->pop(); + if (errors->hasErrors()) + return nullptr; + return result; +} + +std::unique_ptr PseudoElementMatches::serialize() const +{ + std::unique_ptr result = DictionaryValue::create(); + result->setValue("pseudoType", ValueConversions::serialize(m_pseudoType)); + result->setValue("matches", ValueConversions>::serialize(m_matches.get())); + return result; +} + +std::unique_ptr PseudoElementMatches::clone() const +{ + ErrorSupport errors; + return parse(serialize().get(), &errors); +} + +std::unique_ptr InheritedStyleEntry::parse(protocol::Value* value, ErrorSupport* errors) +{ + if (!value || value->type() != protocol::Value::TypeObject) { + errors->addError("object expected"); + return nullptr; + } + + std::unique_ptr result(new InheritedStyleEntry()); + protocol::DictionaryValue* object = DictionaryValue::cast(value); + errors->push(); + protocol::Value* inlineStyleValue = object->get("inlineStyle"); + if (inlineStyleValue) { + errors->setName("inlineStyle"); + result->m_inlineStyle = ValueConversions::parse(inlineStyleValue, errors); + } + protocol::Value* matchedCSSRulesValue = object->get("matchedCSSRules"); + errors->setName("matchedCSSRules"); + result->m_matchedCSSRules = ValueConversions>::parse(matchedCSSRulesValue, errors); + errors->pop(); + if (errors->hasErrors()) + return nullptr; + return result; +} + +std::unique_ptr InheritedStyleEntry::serialize() const +{ + std::unique_ptr result = DictionaryValue::create(); + if (m_inlineStyle.isJust()) + result->setValue("inlineStyle", ValueConversions::serialize(m_inlineStyle.fromJust())); + result->setValue("matchedCSSRules", ValueConversions>::serialize(m_matchedCSSRules.get())); + return result; +} + +std::unique_ptr InheritedStyleEntry::clone() const +{ + ErrorSupport errors; + return parse(serialize().get(), &errors); +} + +std::unique_ptr RuleMatch::parse(protocol::Value* value, ErrorSupport* errors) +{ + if (!value || value->type() != protocol::Value::TypeObject) { + errors->addError("object expected"); + return nullptr; + } + + std::unique_ptr result(new RuleMatch()); + protocol::DictionaryValue* object = DictionaryValue::cast(value); + errors->push(); + protocol::Value* ruleValue = object->get("rule"); + errors->setName("rule"); + result->m_rule = ValueConversions::parse(ruleValue, errors); + protocol::Value* matchingSelectorsValue = object->get("matchingSelectors"); + errors->setName("matchingSelectors"); + result->m_matchingSelectors = ValueConversions>::parse(matchingSelectorsValue, errors); + errors->pop(); + if (errors->hasErrors()) + return nullptr; + return result; +} + +std::unique_ptr RuleMatch::serialize() const +{ + std::unique_ptr result = DictionaryValue::create(); + result->setValue("rule", ValueConversions::serialize(m_rule.get())); + result->setValue("matchingSelectors", ValueConversions>::serialize(m_matchingSelectors.get())); + return result; +} + +std::unique_ptr RuleMatch::clone() const +{ + ErrorSupport errors; + return parse(serialize().get(), &errors); +} + +std::unique_ptr Value::parse(protocol::Value* value, ErrorSupport* errors) +{ + if (!value || value->type() != protocol::Value::TypeObject) { + errors->addError("object expected"); + return nullptr; + } + + std::unique_ptr result(new Value()); + protocol::DictionaryValue* object = DictionaryValue::cast(value); + errors->push(); + protocol::Value* textValue = object->get("text"); + errors->setName("text"); + result->m_text = ValueConversions::parse(textValue, errors); + protocol::Value* rangeValue = object->get("range"); + if (rangeValue) { + errors->setName("range"); + result->m_range = ValueConversions::parse(rangeValue, errors); + } + errors->pop(); + if (errors->hasErrors()) + return nullptr; + return result; +} + +std::unique_ptr Value::serialize() const +{ + std::unique_ptr result = DictionaryValue::create(); + result->setValue("text", ValueConversions::serialize(m_text)); + if (m_range.isJust()) + result->setValue("range", ValueConversions::serialize(m_range.fromJust())); + return result; +} + +std::unique_ptr Value::clone() const +{ + ErrorSupport errors; + return parse(serialize().get(), &errors); +} + +std::unique_ptr SelectorList::parse(protocol::Value* value, ErrorSupport* errors) +{ + if (!value || value->type() != protocol::Value::TypeObject) { + errors->addError("object expected"); + return nullptr; + } + + std::unique_ptr result(new SelectorList()); + protocol::DictionaryValue* object = DictionaryValue::cast(value); + errors->push(); + protocol::Value* selectorsValue = object->get("selectors"); + errors->setName("selectors"); + result->m_selectors = ValueConversions>::parse(selectorsValue, errors); + protocol::Value* textValue = object->get("text"); + errors->setName("text"); + result->m_text = ValueConversions::parse(textValue, errors); + errors->pop(); + if (errors->hasErrors()) + return nullptr; + return result; +} + +std::unique_ptr SelectorList::serialize() const +{ + std::unique_ptr result = DictionaryValue::create(); + result->setValue("selectors", ValueConversions>::serialize(m_selectors.get())); + result->setValue("text", ValueConversions::serialize(m_text)); + return result; +} + +std::unique_ptr SelectorList::clone() const +{ + ErrorSupport errors; + return parse(serialize().get(), &errors); +} + +std::unique_ptr CSSStyleSheetHeader::parse(protocol::Value* value, ErrorSupport* errors) +{ + if (!value || value->type() != protocol::Value::TypeObject) { + errors->addError("object expected"); + return nullptr; + } + + std::unique_ptr result(new CSSStyleSheetHeader()); + protocol::DictionaryValue* object = DictionaryValue::cast(value); + errors->push(); + protocol::Value* styleSheetIdValue = object->get("styleSheetId"); + errors->setName("styleSheetId"); + result->m_styleSheetId = ValueConversions::parse(styleSheetIdValue, errors); + protocol::Value* frameIdValue = object->get("frameId"); + errors->setName("frameId"); + result->m_frameId = ValueConversions::parse(frameIdValue, errors); + protocol::Value* sourceURLValue = object->get("sourceURL"); + errors->setName("sourceURL"); + result->m_sourceURL = ValueConversions::parse(sourceURLValue, errors); + protocol::Value* sourceMapURLValue = object->get("sourceMapURL"); + if (sourceMapURLValue) { + errors->setName("sourceMapURL"); + result->m_sourceMapURL = ValueConversions::parse(sourceMapURLValue, errors); + } + protocol::Value* originValue = object->get("origin"); + errors->setName("origin"); + result->m_origin = ValueConversions::parse(originValue, errors); + protocol::Value* titleValue = object->get("title"); + errors->setName("title"); + result->m_title = ValueConversions::parse(titleValue, errors); + protocol::Value* ownerNodeValue = object->get("ownerNode"); + if (ownerNodeValue) { + errors->setName("ownerNode"); + result->m_ownerNode = ValueConversions::parse(ownerNodeValue, errors); + } + protocol::Value* disabledValue = object->get("disabled"); + errors->setName("disabled"); + result->m_disabled = ValueConversions::parse(disabledValue, errors); + protocol::Value* hasSourceURLValue = object->get("hasSourceURL"); + if (hasSourceURLValue) { + errors->setName("hasSourceURL"); + result->m_hasSourceURL = ValueConversions::parse(hasSourceURLValue, errors); + } + protocol::Value* isInlineValue = object->get("isInline"); + errors->setName("isInline"); + result->m_isInline = ValueConversions::parse(isInlineValue, errors); + protocol::Value* startLineValue = object->get("startLine"); + errors->setName("startLine"); + result->m_startLine = ValueConversions::parse(startLineValue, errors); + protocol::Value* startColumnValue = object->get("startColumn"); + errors->setName("startColumn"); + result->m_startColumn = ValueConversions::parse(startColumnValue, errors); + errors->pop(); + if (errors->hasErrors()) + return nullptr; + return result; +} + +std::unique_ptr CSSStyleSheetHeader::serialize() const +{ + std::unique_ptr result = DictionaryValue::create(); + result->setValue("styleSheetId", ValueConversions::serialize(m_styleSheetId)); + result->setValue("frameId", ValueConversions::serialize(m_frameId)); + result->setValue("sourceURL", ValueConversions::serialize(m_sourceURL)); + if (m_sourceMapURL.isJust()) + result->setValue("sourceMapURL", ValueConversions::serialize(m_sourceMapURL.fromJust())); + result->setValue("origin", ValueConversions::serialize(m_origin)); + result->setValue("title", ValueConversions::serialize(m_title)); + if (m_ownerNode.isJust()) + result->setValue("ownerNode", ValueConversions::serialize(m_ownerNode.fromJust())); + result->setValue("disabled", ValueConversions::serialize(m_disabled)); + if (m_hasSourceURL.isJust()) + result->setValue("hasSourceURL", ValueConversions::serialize(m_hasSourceURL.fromJust())); + result->setValue("isInline", ValueConversions::serialize(m_isInline)); + result->setValue("startLine", ValueConversions::serialize(m_startLine)); + result->setValue("startColumn", ValueConversions::serialize(m_startColumn)); + return result; +} + +std::unique_ptr CSSStyleSheetHeader::clone() const +{ + ErrorSupport errors; + return parse(serialize().get(), &errors); +} + +std::unique_ptr CSSRule::parse(protocol::Value* value, ErrorSupport* errors) +{ + if (!value || value->type() != protocol::Value::TypeObject) { + errors->addError("object expected"); + return nullptr; + } + + std::unique_ptr result(new CSSRule()); + protocol::DictionaryValue* object = DictionaryValue::cast(value); + errors->push(); + protocol::Value* styleSheetIdValue = object->get("styleSheetId"); + if (styleSheetIdValue) { + errors->setName("styleSheetId"); + result->m_styleSheetId = ValueConversions::parse(styleSheetIdValue, errors); + } + protocol::Value* selectorListValue = object->get("selectorList"); + errors->setName("selectorList"); + result->m_selectorList = ValueConversions::parse(selectorListValue, errors); + protocol::Value* originValue = object->get("origin"); + errors->setName("origin"); + result->m_origin = ValueConversions::parse(originValue, errors); + protocol::Value* styleValue = object->get("style"); + errors->setName("style"); + result->m_style = ValueConversions::parse(styleValue, errors); + protocol::Value* mediaValue = object->get("media"); + if (mediaValue) { + errors->setName("media"); + result->m_media = ValueConversions>::parse(mediaValue, errors); + } + errors->pop(); + if (errors->hasErrors()) + return nullptr; + return result; +} + +std::unique_ptr CSSRule::serialize() const +{ + std::unique_ptr result = DictionaryValue::create(); + if (m_styleSheetId.isJust()) + result->setValue("styleSheetId", ValueConversions::serialize(m_styleSheetId.fromJust())); + result->setValue("selectorList", ValueConversions::serialize(m_selectorList.get())); + result->setValue("origin", ValueConversions::serialize(m_origin)); + result->setValue("style", ValueConversions::serialize(m_style.get())); + if (m_media.isJust()) + result->setValue("media", ValueConversions>::serialize(m_media.fromJust())); + return result; +} + +std::unique_ptr CSSRule::clone() const +{ + ErrorSupport errors; + return parse(serialize().get(), &errors); +} + +std::unique_ptr SourceRange::parse(protocol::Value* value, ErrorSupport* errors) +{ + if (!value || value->type() != protocol::Value::TypeObject) { + errors->addError("object expected"); + return nullptr; + } + + std::unique_ptr result(new SourceRange()); + protocol::DictionaryValue* object = DictionaryValue::cast(value); + errors->push(); + protocol::Value* startLineValue = object->get("startLine"); + errors->setName("startLine"); + result->m_startLine = ValueConversions::parse(startLineValue, errors); + protocol::Value* startColumnValue = object->get("startColumn"); + errors->setName("startColumn"); + result->m_startColumn = ValueConversions::parse(startColumnValue, errors); + protocol::Value* endLineValue = object->get("endLine"); + errors->setName("endLine"); + result->m_endLine = ValueConversions::parse(endLineValue, errors); + protocol::Value* endColumnValue = object->get("endColumn"); + errors->setName("endColumn"); + result->m_endColumn = ValueConversions::parse(endColumnValue, errors); + errors->pop(); + if (errors->hasErrors()) + return nullptr; + return result; +} + +std::unique_ptr SourceRange::serialize() const +{ + std::unique_ptr result = DictionaryValue::create(); + result->setValue("startLine", ValueConversions::serialize(m_startLine)); + result->setValue("startColumn", ValueConversions::serialize(m_startColumn)); + result->setValue("endLine", ValueConversions::serialize(m_endLine)); + result->setValue("endColumn", ValueConversions::serialize(m_endColumn)); + return result; +} + +std::unique_ptr SourceRange::clone() const +{ + ErrorSupport errors; + return parse(serialize().get(), &errors); +} + +std::unique_ptr ShorthandEntry::parse(protocol::Value* value, ErrorSupport* errors) +{ + if (!value || value->type() != protocol::Value::TypeObject) { + errors->addError("object expected"); + return nullptr; + } + + std::unique_ptr result(new ShorthandEntry()); + protocol::DictionaryValue* object = DictionaryValue::cast(value); + errors->push(); + protocol::Value* nameValue = object->get("name"); + errors->setName("name"); + result->m_name = ValueConversions::parse(nameValue, errors); + protocol::Value* valueValue = object->get("value"); + errors->setName("value"); + result->m_value = ValueConversions::parse(valueValue, errors); + protocol::Value* importantValue = object->get("important"); + if (importantValue) { + errors->setName("important"); + result->m_important = ValueConversions::parse(importantValue, errors); + } + errors->pop(); + if (errors->hasErrors()) + return nullptr; + return result; +} + +std::unique_ptr ShorthandEntry::serialize() const +{ + std::unique_ptr result = DictionaryValue::create(); + result->setValue("name", ValueConversions::serialize(m_name)); + result->setValue("value", ValueConversions::serialize(m_value)); + if (m_important.isJust()) + result->setValue("important", ValueConversions::serialize(m_important.fromJust())); + return result; +} + +std::unique_ptr ShorthandEntry::clone() const +{ + ErrorSupport errors; + return parse(serialize().get(), &errors); +} + +std::unique_ptr CSSComputedStyleProperty::parse(protocol::Value* value, ErrorSupport* errors) +{ + if (!value || value->type() != protocol::Value::TypeObject) { + errors->addError("object expected"); + return nullptr; + } + + std::unique_ptr result(new CSSComputedStyleProperty()); + protocol::DictionaryValue* object = DictionaryValue::cast(value); + errors->push(); + protocol::Value* nameValue = object->get("name"); + errors->setName("name"); + result->m_name = ValueConversions::parse(nameValue, errors); + protocol::Value* valueValue = object->get("value"); + errors->setName("value"); + result->m_value = ValueConversions::parse(valueValue, errors); + errors->pop(); + if (errors->hasErrors()) + return nullptr; + return result; +} + +std::unique_ptr CSSComputedStyleProperty::serialize() const +{ + std::unique_ptr result = DictionaryValue::create(); + result->setValue("name", ValueConversions::serialize(m_name)); + result->setValue("value", ValueConversions::serialize(m_value)); + return result; +} + +std::unique_ptr CSSComputedStyleProperty::clone() const +{ + ErrorSupport errors; + return parse(serialize().get(), &errors); +} + +std::unique_ptr CSSStyle::parse(protocol::Value* value, ErrorSupport* errors) +{ + if (!value || value->type() != protocol::Value::TypeObject) { + errors->addError("object expected"); + return nullptr; + } + + std::unique_ptr result(new CSSStyle()); + protocol::DictionaryValue* object = DictionaryValue::cast(value); + errors->push(); + protocol::Value* styleSheetIdValue = object->get("styleSheetId"); + if (styleSheetIdValue) { + errors->setName("styleSheetId"); + result->m_styleSheetId = ValueConversions::parse(styleSheetIdValue, errors); + } + protocol::Value* cssPropertiesValue = object->get("cssProperties"); + errors->setName("cssProperties"); + result->m_cssProperties = ValueConversions>::parse(cssPropertiesValue, errors); + protocol::Value* shorthandEntriesValue = object->get("shorthandEntries"); + errors->setName("shorthandEntries"); + result->m_shorthandEntries = ValueConversions>::parse(shorthandEntriesValue, errors); + protocol::Value* cssTextValue = object->get("cssText"); + if (cssTextValue) { + errors->setName("cssText"); + result->m_cssText = ValueConversions::parse(cssTextValue, errors); + } + protocol::Value* rangeValue = object->get("range"); + if (rangeValue) { + errors->setName("range"); + result->m_range = ValueConversions::parse(rangeValue, errors); + } + errors->pop(); + if (errors->hasErrors()) + return nullptr; + return result; +} + +std::unique_ptr CSSStyle::serialize() const +{ + std::unique_ptr result = DictionaryValue::create(); + if (m_styleSheetId.isJust()) + result->setValue("styleSheetId", ValueConversions::serialize(m_styleSheetId.fromJust())); + result->setValue("cssProperties", ValueConversions>::serialize(m_cssProperties.get())); + result->setValue("shorthandEntries", ValueConversions>::serialize(m_shorthandEntries.get())); + if (m_cssText.isJust()) + result->setValue("cssText", ValueConversions::serialize(m_cssText.fromJust())); + if (m_range.isJust()) + result->setValue("range", ValueConversions::serialize(m_range.fromJust())); + return result; +} + +std::unique_ptr CSSStyle::clone() const +{ + ErrorSupport errors; + return parse(serialize().get(), &errors); +} + +std::unique_ptr CSSProperty::parse(protocol::Value* value, ErrorSupport* errors) +{ + if (!value || value->type() != protocol::Value::TypeObject) { + errors->addError("object expected"); + return nullptr; + } + + std::unique_ptr result(new CSSProperty()); + protocol::DictionaryValue* object = DictionaryValue::cast(value); + errors->push(); + protocol::Value* nameValue = object->get("name"); + errors->setName("name"); + result->m_name = ValueConversions::parse(nameValue, errors); + protocol::Value* valueValue = object->get("value"); + errors->setName("value"); + result->m_value = ValueConversions::parse(valueValue, errors); + protocol::Value* importantValue = object->get("important"); + if (importantValue) { + errors->setName("important"); + result->m_important = ValueConversions::parse(importantValue, errors); + } + protocol::Value* implicitValue = object->get("implicit"); + if (implicitValue) { + errors->setName("implicit"); + result->m_implicit = ValueConversions::parse(implicitValue, errors); + } + protocol::Value* textValue = object->get("text"); + if (textValue) { + errors->setName("text"); + result->m_text = ValueConversions::parse(textValue, errors); + } + protocol::Value* parsedOkValue = object->get("parsedOk"); + if (parsedOkValue) { + errors->setName("parsedOk"); + result->m_parsedOk = ValueConversions::parse(parsedOkValue, errors); + } + protocol::Value* disabledValue = object->get("disabled"); + if (disabledValue) { + errors->setName("disabled"); + result->m_disabled = ValueConversions::parse(disabledValue, errors); + } + protocol::Value* rangeValue = object->get("range"); + if (rangeValue) { + errors->setName("range"); + result->m_range = ValueConversions::parse(rangeValue, errors); + } + errors->pop(); + if (errors->hasErrors()) + return nullptr; + return result; +} + +std::unique_ptr CSSProperty::serialize() const +{ + std::unique_ptr result = DictionaryValue::create(); + result->setValue("name", ValueConversions::serialize(m_name)); + result->setValue("value", ValueConversions::serialize(m_value)); + if (m_important.isJust()) + result->setValue("important", ValueConversions::serialize(m_important.fromJust())); + if (m_implicit.isJust()) + result->setValue("implicit", ValueConversions::serialize(m_implicit.fromJust())); + if (m_text.isJust()) + result->setValue("text", ValueConversions::serialize(m_text.fromJust())); + if (m_parsedOk.isJust()) + result->setValue("parsedOk", ValueConversions::serialize(m_parsedOk.fromJust())); + if (m_disabled.isJust()) + result->setValue("disabled", ValueConversions::serialize(m_disabled.fromJust())); + if (m_range.isJust()) + result->setValue("range", ValueConversions::serialize(m_range.fromJust())); + return result; +} + +std::unique_ptr CSSProperty::clone() const +{ + ErrorSupport errors; + return parse(serialize().get(), &errors); +} + +const char* CSSMedia::SourceEnum::MediaRule = "mediaRule"; +const char* CSSMedia::SourceEnum::ImportRule = "importRule"; +const char* CSSMedia::SourceEnum::LinkedSheet = "linkedSheet"; +const char* CSSMedia::SourceEnum::InlineSheet = "inlineSheet"; + +std::unique_ptr CSSMedia::parse(protocol::Value* value, ErrorSupport* errors) +{ + if (!value || value->type() != protocol::Value::TypeObject) { + errors->addError("object expected"); + return nullptr; + } + + std::unique_ptr result(new CSSMedia()); + protocol::DictionaryValue* object = DictionaryValue::cast(value); + errors->push(); + protocol::Value* textValue = object->get("text"); + errors->setName("text"); + result->m_text = ValueConversions::parse(textValue, errors); + protocol::Value* sourceValue = object->get("source"); + errors->setName("source"); + result->m_source = ValueConversions::parse(sourceValue, errors); + protocol::Value* sourceURLValue = object->get("sourceURL"); + if (sourceURLValue) { + errors->setName("sourceURL"); + result->m_sourceURL = ValueConversions::parse(sourceURLValue, errors); + } + protocol::Value* rangeValue = object->get("range"); + if (rangeValue) { + errors->setName("range"); + result->m_range = ValueConversions::parse(rangeValue, errors); + } + protocol::Value* styleSheetIdValue = object->get("styleSheetId"); + if (styleSheetIdValue) { + errors->setName("styleSheetId"); + result->m_styleSheetId = ValueConversions::parse(styleSheetIdValue, errors); + } + protocol::Value* mediaListValue = object->get("mediaList"); + if (mediaListValue) { + errors->setName("mediaList"); + result->m_mediaList = ValueConversions>::parse(mediaListValue, errors); + } + errors->pop(); + if (errors->hasErrors()) + return nullptr; + return result; +} + +std::unique_ptr CSSMedia::serialize() const +{ + std::unique_ptr result = DictionaryValue::create(); + result->setValue("text", ValueConversions::serialize(m_text)); + result->setValue("source", ValueConversions::serialize(m_source)); + if (m_sourceURL.isJust()) + result->setValue("sourceURL", ValueConversions::serialize(m_sourceURL.fromJust())); + if (m_range.isJust()) + result->setValue("range", ValueConversions::serialize(m_range.fromJust())); + if (m_styleSheetId.isJust()) + result->setValue("styleSheetId", ValueConversions::serialize(m_styleSheetId.fromJust())); + if (m_mediaList.isJust()) + result->setValue("mediaList", ValueConversions>::serialize(m_mediaList.fromJust())); + return result; +} + +std::unique_ptr CSSMedia::clone() const +{ + ErrorSupport errors; + return parse(serialize().get(), &errors); +} + +std::unique_ptr MediaQuery::parse(protocol::Value* value, ErrorSupport* errors) +{ + if (!value || value->type() != protocol::Value::TypeObject) { + errors->addError("object expected"); + return nullptr; + } + + std::unique_ptr result(new MediaQuery()); + protocol::DictionaryValue* object = DictionaryValue::cast(value); + errors->push(); + protocol::Value* expressionsValue = object->get("expressions"); + errors->setName("expressions"); + result->m_expressions = ValueConversions>::parse(expressionsValue, errors); + protocol::Value* activeValue = object->get("active"); + errors->setName("active"); + result->m_active = ValueConversions::parse(activeValue, errors); + errors->pop(); + if (errors->hasErrors()) + return nullptr; + return result; +} + +std::unique_ptr MediaQuery::serialize() const +{ + std::unique_ptr result = DictionaryValue::create(); + result->setValue("expressions", ValueConversions>::serialize(m_expressions.get())); + result->setValue("active", ValueConversions::serialize(m_active)); + return result; +} + +std::unique_ptr MediaQuery::clone() const +{ + ErrorSupport errors; + return parse(serialize().get(), &errors); +} + +std::unique_ptr MediaQueryExpression::parse(protocol::Value* value, ErrorSupport* errors) +{ + if (!value || value->type() != protocol::Value::TypeObject) { + errors->addError("object expected"); + return nullptr; + } + + std::unique_ptr result(new MediaQueryExpression()); + protocol::DictionaryValue* object = DictionaryValue::cast(value); + errors->push(); + protocol::Value* valueValue = object->get("value"); + errors->setName("value"); + result->m_value = ValueConversions::parse(valueValue, errors); + protocol::Value* unitValue = object->get("unit"); + errors->setName("unit"); + result->m_unit = ValueConversions::parse(unitValue, errors); + protocol::Value* featureValue = object->get("feature"); + errors->setName("feature"); + result->m_feature = ValueConversions::parse(featureValue, errors); + protocol::Value* valueRangeValue = object->get("valueRange"); + if (valueRangeValue) { + errors->setName("valueRange"); + result->m_valueRange = ValueConversions::parse(valueRangeValue, errors); + } + protocol::Value* computedLengthValue = object->get("computedLength"); + if (computedLengthValue) { + errors->setName("computedLength"); + result->m_computedLength = ValueConversions::parse(computedLengthValue, errors); + } + errors->pop(); + if (errors->hasErrors()) + return nullptr; + return result; +} + +std::unique_ptr MediaQueryExpression::serialize() const +{ + std::unique_ptr result = DictionaryValue::create(); + result->setValue("value", ValueConversions::serialize(m_value)); + result->setValue("unit", ValueConversions::serialize(m_unit)); + result->setValue("feature", ValueConversions::serialize(m_feature)); + if (m_valueRange.isJust()) + result->setValue("valueRange", ValueConversions::serialize(m_valueRange.fromJust())); + if (m_computedLength.isJust()) + result->setValue("computedLength", ValueConversions::serialize(m_computedLength.fromJust())); + return result; +} + +std::unique_ptr MediaQueryExpression::clone() const +{ + ErrorSupport errors; + return parse(serialize().get(), &errors); +} + +std::unique_ptr PlatformFontUsage::parse(protocol::Value* value, ErrorSupport* errors) +{ + if (!value || value->type() != protocol::Value::TypeObject) { + errors->addError("object expected"); + return nullptr; + } + + std::unique_ptr result(new PlatformFontUsage()); + protocol::DictionaryValue* object = DictionaryValue::cast(value); + errors->push(); + protocol::Value* familyNameValue = object->get("familyName"); + errors->setName("familyName"); + result->m_familyName = ValueConversions::parse(familyNameValue, errors); + protocol::Value* isCustomFontValue = object->get("isCustomFont"); + errors->setName("isCustomFont"); + result->m_isCustomFont = ValueConversions::parse(isCustomFontValue, errors); + protocol::Value* glyphCountValue = object->get("glyphCount"); + errors->setName("glyphCount"); + result->m_glyphCount = ValueConversions::parse(glyphCountValue, errors); + errors->pop(); + if (errors->hasErrors()) + return nullptr; + return result; +} + +std::unique_ptr PlatformFontUsage::serialize() const +{ + std::unique_ptr result = DictionaryValue::create(); + result->setValue("familyName", ValueConversions::serialize(m_familyName)); + result->setValue("isCustomFont", ValueConversions::serialize(m_isCustomFont)); + result->setValue("glyphCount", ValueConversions::serialize(m_glyphCount)); + return result; +} + +std::unique_ptr PlatformFontUsage::clone() const +{ + ErrorSupport errors; + return parse(serialize().get(), &errors); +} + +std::unique_ptr CSSKeyframesRule::parse(protocol::Value* value, ErrorSupport* errors) +{ + if (!value || value->type() != protocol::Value::TypeObject) { + errors->addError("object expected"); + return nullptr; + } + + std::unique_ptr result(new CSSKeyframesRule()); + protocol::DictionaryValue* object = DictionaryValue::cast(value); + errors->push(); + protocol::Value* animationNameValue = object->get("animationName"); + errors->setName("animationName"); + result->m_animationName = ValueConversions::parse(animationNameValue, errors); + protocol::Value* keyframesValue = object->get("keyframes"); + errors->setName("keyframes"); + result->m_keyframes = ValueConversions>::parse(keyframesValue, errors); + errors->pop(); + if (errors->hasErrors()) + return nullptr; + return result; +} + +std::unique_ptr CSSKeyframesRule::serialize() const +{ + std::unique_ptr result = DictionaryValue::create(); + result->setValue("animationName", ValueConversions::serialize(m_animationName.get())); + result->setValue("keyframes", ValueConversions>::serialize(m_keyframes.get())); + return result; +} + +std::unique_ptr CSSKeyframesRule::clone() const +{ + ErrorSupport errors; + return parse(serialize().get(), &errors); +} + +std::unique_ptr CSSKeyframeRule::parse(protocol::Value* value, ErrorSupport* errors) +{ + if (!value || value->type() != protocol::Value::TypeObject) { + errors->addError("object expected"); + return nullptr; + } + + std::unique_ptr result(new CSSKeyframeRule()); + protocol::DictionaryValue* object = DictionaryValue::cast(value); + errors->push(); + protocol::Value* styleSheetIdValue = object->get("styleSheetId"); + if (styleSheetIdValue) { + errors->setName("styleSheetId"); + result->m_styleSheetId = ValueConversions::parse(styleSheetIdValue, errors); + } + protocol::Value* originValue = object->get("origin"); + errors->setName("origin"); + result->m_origin = ValueConversions::parse(originValue, errors); + protocol::Value* keyTextValue = object->get("keyText"); + errors->setName("keyText"); + result->m_keyText = ValueConversions::parse(keyTextValue, errors); + protocol::Value* styleValue = object->get("style"); + errors->setName("style"); + result->m_style = ValueConversions::parse(styleValue, errors); + errors->pop(); + if (errors->hasErrors()) + return nullptr; + return result; +} + +std::unique_ptr CSSKeyframeRule::serialize() const +{ + std::unique_ptr result = DictionaryValue::create(); + if (m_styleSheetId.isJust()) + result->setValue("styleSheetId", ValueConversions::serialize(m_styleSheetId.fromJust())); + result->setValue("origin", ValueConversions::serialize(m_origin)); + result->setValue("keyText", ValueConversions::serialize(m_keyText.get())); + result->setValue("style", ValueConversions::serialize(m_style.get())); + return result; +} + +std::unique_ptr CSSKeyframeRule::clone() const +{ + ErrorSupport errors; + return parse(serialize().get(), &errors); +} + +std::unique_ptr StyleDeclarationEdit::parse(protocol::Value* value, ErrorSupport* errors) +{ + if (!value || value->type() != protocol::Value::TypeObject) { + errors->addError("object expected"); + return nullptr; + } + + std::unique_ptr result(new StyleDeclarationEdit()); + protocol::DictionaryValue* object = DictionaryValue::cast(value); + errors->push(); + protocol::Value* styleSheetIdValue = object->get("styleSheetId"); + errors->setName("styleSheetId"); + result->m_styleSheetId = ValueConversions::parse(styleSheetIdValue, errors); + protocol::Value* rangeValue = object->get("range"); + errors->setName("range"); + result->m_range = ValueConversions::parse(rangeValue, errors); + protocol::Value* textValue = object->get("text"); + errors->setName("text"); + result->m_text = ValueConversions::parse(textValue, errors); + errors->pop(); + if (errors->hasErrors()) + return nullptr; + return result; +} + +std::unique_ptr StyleDeclarationEdit::serialize() const +{ + std::unique_ptr result = DictionaryValue::create(); + result->setValue("styleSheetId", ValueConversions::serialize(m_styleSheetId)); + result->setValue("range", ValueConversions::serialize(m_range.get())); + result->setValue("text", ValueConversions::serialize(m_text)); + return result; +} + +std::unique_ptr StyleDeclarationEdit::clone() const +{ + ErrorSupport errors; + return parse(serialize().get(), &errors); +} + +// ------------- Enum values from params. + + +// ------------- Frontend notifications. + +void Frontend::mediaQueryResultChanged() +{ + std::unique_ptr jsonMessage = DictionaryValue::create(); + jsonMessage->setString("method", "CSS.mediaQueryResultChanged"); + std::unique_ptr paramsObject = DictionaryValue::create(); + jsonMessage->setObject("params", std::move(paramsObject)); + if (m_frontendChannel) + m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString()); +} + +void Frontend::fontsUpdated() +{ + std::unique_ptr jsonMessage = DictionaryValue::create(); + jsonMessage->setString("method", "CSS.fontsUpdated"); + std::unique_ptr paramsObject = DictionaryValue::create(); + jsonMessage->setObject("params", std::move(paramsObject)); + if (m_frontendChannel) + m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString()); +} + +void Frontend::styleSheetChanged(const String& styleSheetId) +{ + std::unique_ptr jsonMessage = DictionaryValue::create(); + jsonMessage->setString("method", "CSS.styleSheetChanged"); + std::unique_ptr paramsObject = DictionaryValue::create(); + paramsObject->setValue("styleSheetId", ValueConversions::serialize(styleSheetId)); + jsonMessage->setObject("params", std::move(paramsObject)); + if (m_frontendChannel) + m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString()); +} + +void Frontend::styleSheetAdded(std::unique_ptr header) +{ + std::unique_ptr jsonMessage = DictionaryValue::create(); + jsonMessage->setString("method", "CSS.styleSheetAdded"); + std::unique_ptr paramsObject = DictionaryValue::create(); + paramsObject->setValue("header", ValueConversions::serialize(header.get())); + jsonMessage->setObject("params", std::move(paramsObject)); + if (m_frontendChannel) + m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString()); +} + +void Frontend::styleSheetRemoved(const String& styleSheetId) +{ + std::unique_ptr jsonMessage = DictionaryValue::create(); + jsonMessage->setString("method", "CSS.styleSheetRemoved"); + std::unique_ptr paramsObject = DictionaryValue::create(); + paramsObject->setValue("styleSheetId", ValueConversions::serialize(styleSheetId)); + jsonMessage->setObject("params", std::move(paramsObject)); + if (m_frontendChannel) + m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString()); +} + +void Frontend::layoutEditorChange(const String& styleSheetId, std::unique_ptr changeRange) +{ + std::unique_ptr jsonMessage = DictionaryValue::create(); + jsonMessage->setString("method", "CSS.layoutEditorChange"); + std::unique_ptr paramsObject = DictionaryValue::create(); + paramsObject->setValue("styleSheetId", ValueConversions::serialize(styleSheetId)); + paramsObject->setValue("changeRange", ValueConversions::serialize(changeRange.get())); + jsonMessage->setObject("params", std::move(paramsObject)); + if (m_frontendChannel) + m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString()); +} + +void Frontend::flush() +{ + m_frontendChannel->flushProtocolNotifications(); +} + +// --------------------- Dispatcher. + +class DispatcherImpl : public protocol::DispatcherBase { +public: + DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend) + : DispatcherBase(frontendChannel) + , m_backend(backend) { + m_dispatchMap["CSS.enable"] = &DispatcherImpl::enable; + m_dispatchMap["CSS.disable"] = &DispatcherImpl::disable; + m_dispatchMap["CSS.getMatchedStylesForNode"] = &DispatcherImpl::getMatchedStylesForNode; + m_dispatchMap["CSS.getInlineStylesForNode"] = &DispatcherImpl::getInlineStylesForNode; + m_dispatchMap["CSS.getComputedStyleForNode"] = &DispatcherImpl::getComputedStyleForNode; + m_dispatchMap["CSS.getPlatformFontsForNode"] = &DispatcherImpl::getPlatformFontsForNode; + m_dispatchMap["CSS.getStyleSheetText"] = &DispatcherImpl::getStyleSheetText; + } + ~DispatcherImpl() override { } + void dispatch(int callId, const String& method, std::unique_ptr messageObject) override; + +protected: + using CallHandler = void (DispatcherImpl::*)(int callId, std::unique_ptr messageObject, ErrorSupport* errors); + using DispatchMap = protocol::HashMap; + DispatchMap m_dispatchMap; + + void enable(int callId, std::unique_ptr requestMessageObject, ErrorSupport*); + void disable(int callId, std::unique_ptr requestMessageObject, ErrorSupport*); + void getMatchedStylesForNode(int callId, std::unique_ptr requestMessageObject, ErrorSupport*); + void getInlineStylesForNode(int callId, std::unique_ptr requestMessageObject, ErrorSupport*); + void getComputedStyleForNode(int callId, std::unique_ptr requestMessageObject, ErrorSupport*); + void getPlatformFontsForNode(int callId, std::unique_ptr requestMessageObject, ErrorSupport*); + void getStyleSheetText(int callId, std::unique_ptr requestMessageObject, ErrorSupport*); + + Backend* m_backend; +}; + +void DispatcherImpl::dispatch(int callId, const String& method, std::unique_ptr messageObject) +{ + protocol::HashMap::iterator it = m_dispatchMap.find(method); + if (it == m_dispatchMap.end()) { + reportProtocolError(callId, MethodNotFound, "'" + method + "' wasn't found", nullptr); + return; + } + + protocol::ErrorSupport errors; + (this->*(it->second))(callId, std::move(messageObject), &errors); +} + + +class EnableCallbackImpl : public Backend::EnableCallback, public DispatcherBase::Callback { +public: + EnableCallbackImpl(std::unique_ptr backendImpl, int callId) + : DispatcherBase::Callback(std::move(backendImpl), callId) { } + + void sendSuccess() override + { + std::unique_ptr resultObject = DictionaryValue::create(); + sendIfActive(std::move(resultObject), ErrorString()); + } + + void sendFailure(const ErrorString& error) override + { + DCHECK(error.length()); + sendIfActive(nullptr, error); + } + +}; + +void DispatcherImpl::enable(int callId, std::unique_ptr requestMessageObject, ErrorSupport* errors) +{ + std::unique_ptr callback(new EnableCallbackImpl(weakPtr(), callId)); + + std::unique_ptr weak = weakPtr(); + m_backend->enable(std::move(callback)); +} + +void DispatcherImpl::disable(int callId, std::unique_ptr requestMessageObject, ErrorSupport* errors) +{ + + std::unique_ptr weak = weakPtr(); + ErrorString error; + m_backend->disable(&error); + if (weak->get()) + weak->get()->sendResponse(callId, error); +} + +void DispatcherImpl::getMatchedStylesForNode(int callId, std::unique_ptr requestMessageObject, ErrorSupport* errors) +{ + // Prepare input parameters. + protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params")); + errors->push(); + protocol::Value* nodeIdValue = object ? object->get("nodeId") : nullptr; + errors->setName("nodeId"); + int in_nodeId = ValueConversions::parse(nodeIdValue, errors); + errors->pop(); + if (errors->hasErrors()) { + reportProtocolError(callId, InvalidParams, kInvalidRequest, errors); + return; + } + // Declare output parameters. + std::unique_ptr result = DictionaryValue::create(); + Maybe out_inlineStyle; + Maybe out_attributesStyle; + Maybe> out_matchedCSSRules; + Maybe> out_pseudoElements; + Maybe> out_inherited; + Maybe> out_cssKeyframesRules; + + std::unique_ptr weak = weakPtr(); + ErrorString error; + m_backend->getMatchedStylesForNode(&error, in_nodeId, &out_inlineStyle, &out_attributesStyle, &out_matchedCSSRules, &out_pseudoElements, &out_inherited, &out_cssKeyframesRules); + if (!error.length()) { + if (out_inlineStyle.isJust()) + result->setValue("inlineStyle", ValueConversions::serialize(out_inlineStyle.fromJust())); + if (out_attributesStyle.isJust()) + result->setValue("attributesStyle", ValueConversions::serialize(out_attributesStyle.fromJust())); + if (out_matchedCSSRules.isJust()) + result->setValue("matchedCSSRules", ValueConversions>::serialize(out_matchedCSSRules.fromJust())); + if (out_pseudoElements.isJust()) + result->setValue("pseudoElements", ValueConversions>::serialize(out_pseudoElements.fromJust())); + if (out_inherited.isJust()) + result->setValue("inherited", ValueConversions>::serialize(out_inherited.fromJust())); + if (out_cssKeyframesRules.isJust()) + result->setValue("cssKeyframesRules", ValueConversions>::serialize(out_cssKeyframesRules.fromJust())); + } + if (weak->get()) + weak->get()->sendResponse(callId, error, std::move(result)); +} + +void DispatcherImpl::getInlineStylesForNode(int callId, std::unique_ptr requestMessageObject, ErrorSupport* errors) +{ + // Prepare input parameters. + protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params")); + errors->push(); + protocol::Value* nodeIdValue = object ? object->get("nodeId") : nullptr; + errors->setName("nodeId"); + int in_nodeId = ValueConversions::parse(nodeIdValue, errors); + errors->pop(); + if (errors->hasErrors()) { + reportProtocolError(callId, InvalidParams, kInvalidRequest, errors); + return; + } + // Declare output parameters. + std::unique_ptr result = DictionaryValue::create(); + Maybe out_inlineStyle; + Maybe out_attributesStyle; + + std::unique_ptr weak = weakPtr(); + ErrorString error; + m_backend->getInlineStylesForNode(&error, in_nodeId, &out_inlineStyle, &out_attributesStyle); + if (!error.length()) { + if (out_inlineStyle.isJust()) + result->setValue("inlineStyle", ValueConversions::serialize(out_inlineStyle.fromJust())); + if (out_attributesStyle.isJust()) + result->setValue("attributesStyle", ValueConversions::serialize(out_attributesStyle.fromJust())); + } + if (weak->get()) + weak->get()->sendResponse(callId, error, std::move(result)); +} + +void DispatcherImpl::getComputedStyleForNode(int callId, std::unique_ptr requestMessageObject, ErrorSupport* errors) +{ + // Prepare input parameters. + protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params")); + errors->push(); + protocol::Value* nodeIdValue = object ? object->get("nodeId") : nullptr; + errors->setName("nodeId"); + int in_nodeId = ValueConversions::parse(nodeIdValue, errors); + errors->pop(); + if (errors->hasErrors()) { + reportProtocolError(callId, InvalidParams, kInvalidRequest, errors); + return; + } + // Declare output parameters. + std::unique_ptr result = DictionaryValue::create(); + std::unique_ptr> out_computedStyle; + + std::unique_ptr weak = weakPtr(); + ErrorString error; + m_backend->getComputedStyleForNode(&error, in_nodeId, &out_computedStyle); + if (!error.length()) { + result->setValue("computedStyle", ValueConversions>::serialize(out_computedStyle.get())); + } + if (weak->get()) + weak->get()->sendResponse(callId, error, std::move(result)); +} + +void DispatcherImpl::getPlatformFontsForNode(int callId, std::unique_ptr requestMessageObject, ErrorSupport* errors) +{ + // Prepare input parameters. + protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params")); + errors->push(); + protocol::Value* nodeIdValue = object ? object->get("nodeId") : nullptr; + errors->setName("nodeId"); + int in_nodeId = ValueConversions::parse(nodeIdValue, errors); + errors->pop(); + if (errors->hasErrors()) { + reportProtocolError(callId, InvalidParams, kInvalidRequest, errors); + return; + } + // Declare output parameters. + std::unique_ptr result = DictionaryValue::create(); + std::unique_ptr> out_fonts; + + std::unique_ptr weak = weakPtr(); + ErrorString error; + m_backend->getPlatformFontsForNode(&error, in_nodeId, &out_fonts); + if (!error.length()) { + result->setValue("fonts", ValueConversions>::serialize(out_fonts.get())); + } + if (weak->get()) + weak->get()->sendResponse(callId, error, std::move(result)); +} + +void DispatcherImpl::getStyleSheetText(int callId, std::unique_ptr requestMessageObject, ErrorSupport* errors) +{ + // Prepare input parameters. + protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params")); + errors->push(); + protocol::Value* styleSheetIdValue = object ? object->get("styleSheetId") : nullptr; + errors->setName("styleSheetId"); + String in_styleSheetId = ValueConversions::parse(styleSheetIdValue, errors); + errors->pop(); + if (errors->hasErrors()) { + reportProtocolError(callId, InvalidParams, kInvalidRequest, errors); + return; + } + // Declare output parameters. + std::unique_ptr result = DictionaryValue::create(); + String out_text; + + std::unique_ptr weak = weakPtr(); + ErrorString error; + m_backend->getStyleSheetText(&error, in_styleSheetId, &out_text); + if (!error.length()) { + result->setValue("text", ValueConversions::serialize(out_text)); + } + if (weak->get()) + weak->get()->sendResponse(callId, error, std::move(result)); +} + +// static +void Dispatcher::wire(UberDispatcher* dispatcher, Backend* backend) +{ + dispatcher->registerBackend("CSS", wrapUnique(new DispatcherImpl(dispatcher->channel(), backend))); +} + +} // CSS +} // namespace v8_inspector +} // namespace protocol diff --git a/runtime/src/main/jni/v8_inspector/src/inspector/protocol/CSS.h b/runtime/src/main/jni/v8_inspector/src/inspector/protocol/CSS.h new file mode 100644 index 000000000..6e1a43714 --- /dev/null +++ b/runtime/src/main/jni/v8_inspector/src/inspector/protocol/CSS.h @@ -0,0 +1,1967 @@ +// This file is generated + +// Copyright (c) 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef v8_inspector_protocol_CSS_h +#define v8_inspector_protocol_CSS_h + +#include "src/inspector/protocol/Protocol.h" +// For each imported domain we generate a ValueConversions struct instead of a full domain definition +// and include Domain::API version from there. + +namespace v8_inspector { +namespace protocol { +namespace CSS { + +// ------------- Forward and enum declarations. +// +using StyleSheetId = String; +// Stylesheet type: "injected" for stylesheets injected via extension, "user-agent" for user-agent stylesheets, "inspector" for stylesheets created by the inspector (i.e. those holding the "via inspector" rules), "regular" for regular stylesheets. +using StyleSheetOrigin = String; +// CSS rule collection for a single pseudo style. +class PseudoElementMatches; +// Inherited CSS rule collection from ancestor node. +class InheritedStyleEntry; +// Match data for a CSS rule. +class RuleMatch; +// Data for a simple selector (these are delimited by commas in a selector list). +class Value; +// Selector list data. +class SelectorList; +// CSS stylesheet metainformation. +class CSSStyleSheetHeader; +// CSS rule representation. +class CSSRule; +// Text range within a resource. All numbers are zero-based. +class SourceRange; +// +class ShorthandEntry; +// +class CSSComputedStyleProperty; +// CSS style representation. +class CSSStyle; +// CSS property declaration data. +class CSSProperty; +// CSS media rule descriptor. +class CSSMedia; +// Media query descriptor. +class MediaQuery; +// Media query expression descriptor. +class MediaQueryExpression; +// Information about amount of glyphs that were rendered with given font. +class PlatformFontUsage; +// CSS keyframes rule representation. +class CSSKeyframesRule; +// CSS keyframe rule representation. +class CSSKeyframeRule; +// A descriptor of operation to mutate style declaration text. +class StyleDeclarationEdit; + +namespace StyleSheetOriginEnum { + extern const char* Injected; + extern const char* UserAgent; + extern const char* Inspector; + extern const char* Regular; +} // namespace StyleSheetOriginEnum + +// ------------- Type and builder declarations. + +// CSS rule collection for a single pseudo style. +class PseudoElementMatches { + PROTOCOL_DISALLOW_COPY(PseudoElementMatches); +public: + static std::unique_ptr parse(protocol::Value* value, ErrorSupport* errors); + + ~PseudoElementMatches() { } + + String getPseudoType() { return m_pseudoType; } + void setPseudoType(const String& value) { m_pseudoType = value; } + + protocol::Array* getMatches() { return m_matches.get(); } + void setMatches(std::unique_ptr> value) { m_matches = std::move(value); } + + std::unique_ptr serialize() const; + std::unique_ptr clone() const; + + template + class PseudoElementMatchesBuilder { + public: + enum { + NoFieldsSet = 0, + PseudoTypeSet = 1 << 1, + MatchesSet = 1 << 2, + AllFieldsSet = (PseudoTypeSet | MatchesSet | 0)}; + + + PseudoElementMatchesBuilder& setPseudoType(const String& value) + { + static_assert(!(STATE & PseudoTypeSet), "property pseudoType should not be set yet"); + m_result->setPseudoType(value); + return castState(); + } + + PseudoElementMatchesBuilder& setMatches(std::unique_ptr> value) + { + static_assert(!(STATE & MatchesSet), "property matches should not be set yet"); + m_result->setMatches(std::move(value)); + return castState(); + } + + std::unique_ptr build() + { + static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet"); + return std::move(m_result); + } + + private: + friend class PseudoElementMatches; + PseudoElementMatchesBuilder() : m_result(new PseudoElementMatches()) { } + + template PseudoElementMatchesBuilder& castState() + { + return *reinterpret_cast*>(this); + } + + std::unique_ptr m_result; + }; + + static PseudoElementMatchesBuilder<0> create() + { + return PseudoElementMatchesBuilder<0>(); + } + +private: + PseudoElementMatches() + { + } + + String m_pseudoType; + std::unique_ptr> m_matches; +}; + + +// Inherited CSS rule collection from ancestor node. +class InheritedStyleEntry { + PROTOCOL_DISALLOW_COPY(InheritedStyleEntry); +public: + static std::unique_ptr parse(protocol::Value* value, ErrorSupport* errors); + + ~InheritedStyleEntry() { } + + bool hasInlineStyle() { return m_inlineStyle.isJust(); } + protocol::CSS::CSSStyle* getInlineStyle(protocol::CSS::CSSStyle* defaultValue) { return m_inlineStyle.isJust() ? m_inlineStyle.fromJust() : defaultValue; } + void setInlineStyle(std::unique_ptr value) { m_inlineStyle = std::move(value); } + + protocol::Array* getMatchedCSSRules() { return m_matchedCSSRules.get(); } + void setMatchedCSSRules(std::unique_ptr> value) { m_matchedCSSRules = std::move(value); } + + std::unique_ptr serialize() const; + std::unique_ptr clone() const; + + template + class InheritedStyleEntryBuilder { + public: + enum { + NoFieldsSet = 0, + MatchedCSSRulesSet = 1 << 1, + AllFieldsSet = (MatchedCSSRulesSet | 0)}; + + + InheritedStyleEntryBuilder& setInlineStyle(std::unique_ptr value) + { + m_result->setInlineStyle(std::move(value)); + return *this; + } + + InheritedStyleEntryBuilder& setMatchedCSSRules(std::unique_ptr> value) + { + static_assert(!(STATE & MatchedCSSRulesSet), "property matchedCSSRules should not be set yet"); + m_result->setMatchedCSSRules(std::move(value)); + return castState(); + } + + std::unique_ptr build() + { + static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet"); + return std::move(m_result); + } + + private: + friend class InheritedStyleEntry; + InheritedStyleEntryBuilder() : m_result(new InheritedStyleEntry()) { } + + template InheritedStyleEntryBuilder& castState() + { + return *reinterpret_cast*>(this); + } + + std::unique_ptr m_result; + }; + + static InheritedStyleEntryBuilder<0> create() + { + return InheritedStyleEntryBuilder<0>(); + } + +private: + InheritedStyleEntry() + { + } + + Maybe m_inlineStyle; + std::unique_ptr> m_matchedCSSRules; +}; + + +// Match data for a CSS rule. +class RuleMatch { + PROTOCOL_DISALLOW_COPY(RuleMatch); +public: + static std::unique_ptr parse(protocol::Value* value, ErrorSupport* errors); + + ~RuleMatch() { } + + protocol::CSS::CSSRule* getRule() { return m_rule.get(); } + void setRule(std::unique_ptr value) { m_rule = std::move(value); } + + protocol::Array* getMatchingSelectors() { return m_matchingSelectors.get(); } + void setMatchingSelectors(std::unique_ptr> value) { m_matchingSelectors = std::move(value); } + + std::unique_ptr serialize() const; + std::unique_ptr clone() const; + + template + class RuleMatchBuilder { + public: + enum { + NoFieldsSet = 0, + RuleSet = 1 << 1, + MatchingSelectorsSet = 1 << 2, + AllFieldsSet = (RuleSet | MatchingSelectorsSet | 0)}; + + + RuleMatchBuilder& setRule(std::unique_ptr value) + { + static_assert(!(STATE & RuleSet), "property rule should not be set yet"); + m_result->setRule(std::move(value)); + return castState(); + } + + RuleMatchBuilder& setMatchingSelectors(std::unique_ptr> value) + { + static_assert(!(STATE & MatchingSelectorsSet), "property matchingSelectors should not be set yet"); + m_result->setMatchingSelectors(std::move(value)); + return castState(); + } + + std::unique_ptr build() + { + static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet"); + return std::move(m_result); + } + + private: + friend class RuleMatch; + RuleMatchBuilder() : m_result(new RuleMatch()) { } + + template RuleMatchBuilder& castState() + { + return *reinterpret_cast*>(this); + } + + std::unique_ptr m_result; + }; + + static RuleMatchBuilder<0> create() + { + return RuleMatchBuilder<0>(); + } + +private: + RuleMatch() + { + } + + std::unique_ptr m_rule; + std::unique_ptr> m_matchingSelectors; +}; + + +// Data for a simple selector (these are delimited by commas in a selector list). +class Value { + PROTOCOL_DISALLOW_COPY(Value); +public: + static std::unique_ptr parse(protocol::Value* value, ErrorSupport* errors); + + ~Value() { } + + String getText() { return m_text; } + void setText(const String& value) { m_text = value; } + + bool hasRange() { return m_range.isJust(); } + protocol::CSS::SourceRange* getRange(protocol::CSS::SourceRange* defaultValue) { return m_range.isJust() ? m_range.fromJust() : defaultValue; } + void setRange(std::unique_ptr value) { m_range = std::move(value); } + + std::unique_ptr serialize() const; + std::unique_ptr clone() const; + + template + class ValueBuilder { + public: + enum { + NoFieldsSet = 0, + TextSet = 1 << 1, + AllFieldsSet = (TextSet | 0)}; + + + ValueBuilder& setText(const String& value) + { + static_assert(!(STATE & TextSet), "property text should not be set yet"); + m_result->setText(value); + return castState(); + } + + ValueBuilder& setRange(std::unique_ptr value) + { + m_result->setRange(std::move(value)); + return *this; + } + + std::unique_ptr build() + { + static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet"); + return std::move(m_result); + } + + private: + friend class Value; + ValueBuilder() : m_result(new Value()) { } + + template ValueBuilder& castState() + { + return *reinterpret_cast*>(this); + } + + std::unique_ptr m_result; + }; + + static ValueBuilder<0> create() + { + return ValueBuilder<0>(); + } + +private: + Value() + { + } + + String m_text; + Maybe m_range; +}; + + +// Selector list data. +class SelectorList { + PROTOCOL_DISALLOW_COPY(SelectorList); +public: + static std::unique_ptr parse(protocol::Value* value, ErrorSupport* errors); + + ~SelectorList() { } + + protocol::Array* getSelectors() { return m_selectors.get(); } + void setSelectors(std::unique_ptr> value) { m_selectors = std::move(value); } + + String getText() { return m_text; } + void setText(const String& value) { m_text = value; } + + std::unique_ptr serialize() const; + std::unique_ptr clone() const; + + template + class SelectorListBuilder { + public: + enum { + NoFieldsSet = 0, + SelectorsSet = 1 << 1, + TextSet = 1 << 2, + AllFieldsSet = (SelectorsSet | TextSet | 0)}; + + + SelectorListBuilder& setSelectors(std::unique_ptr> value) + { + static_assert(!(STATE & SelectorsSet), "property selectors should not be set yet"); + m_result->setSelectors(std::move(value)); + return castState(); + } + + SelectorListBuilder& setText(const String& value) + { + static_assert(!(STATE & TextSet), "property text should not be set yet"); + m_result->setText(value); + return castState(); + } + + std::unique_ptr build() + { + static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet"); + return std::move(m_result); + } + + private: + friend class SelectorList; + SelectorListBuilder() : m_result(new SelectorList()) { } + + template SelectorListBuilder& castState() + { + return *reinterpret_cast*>(this); + } + + std::unique_ptr m_result; + }; + + static SelectorListBuilder<0> create() + { + return SelectorListBuilder<0>(); + } + +private: + SelectorList() + { + } + + std::unique_ptr> m_selectors; + String m_text; +}; + + +// CSS stylesheet metainformation. +class CSSStyleSheetHeader { + PROTOCOL_DISALLOW_COPY(CSSStyleSheetHeader); +public: + static std::unique_ptr parse(protocol::Value* value, ErrorSupport* errors); + + ~CSSStyleSheetHeader() { } + + String getStyleSheetId() { return m_styleSheetId; } + void setStyleSheetId(const String& value) { m_styleSheetId = value; } + + String getFrameId() { return m_frameId; } + void setFrameId(const String& value) { m_frameId = value; } + + String getSourceURL() { return m_sourceURL; } + void setSourceURL(const String& value) { m_sourceURL = value; } + + bool hasSourceMapURL() { return m_sourceMapURL.isJust(); } + String getSourceMapURL(const String& defaultValue) { return m_sourceMapURL.isJust() ? m_sourceMapURL.fromJust() : defaultValue; } + void setSourceMapURL(const String& value) { m_sourceMapURL = value; } + + String getOrigin() { return m_origin; } + void setOrigin(const String& value) { m_origin = value; } + + String getTitle() { return m_title; } + void setTitle(const String& value) { m_title = value; } + + bool hasOwnerNode() { return m_ownerNode.isJust(); } + int getOwnerNode(int defaultValue) { return m_ownerNode.isJust() ? m_ownerNode.fromJust() : defaultValue; } + void setOwnerNode(int value) { m_ownerNode = value; } + + bool getDisabled() { return m_disabled; } + void setDisabled(bool value) { m_disabled = value; } + + bool hasHasSourceURL() { return m_hasSourceURL.isJust(); } + bool getHasSourceURL(bool defaultValue) { return m_hasSourceURL.isJust() ? m_hasSourceURL.fromJust() : defaultValue; } + void setHasSourceURL(bool value) { m_hasSourceURL = value; } + + bool getIsInline() { return m_isInline; } + void setIsInline(bool value) { m_isInline = value; } + + double getStartLine() { return m_startLine; } + void setStartLine(double value) { m_startLine = value; } + + double getStartColumn() { return m_startColumn; } + void setStartColumn(double value) { m_startColumn = value; } + + std::unique_ptr serialize() const; + std::unique_ptr clone() const; + + template + class CSSStyleSheetHeaderBuilder { + public: + enum { + NoFieldsSet = 0, + StyleSheetIdSet = 1 << 1, + FrameIdSet = 1 << 2, + SourceURLSet = 1 << 3, + OriginSet = 1 << 4, + TitleSet = 1 << 5, + DisabledSet = 1 << 6, + IsInlineSet = 1 << 7, + StartLineSet = 1 << 8, + StartColumnSet = 1 << 9, + AllFieldsSet = (StyleSheetIdSet | FrameIdSet | SourceURLSet | OriginSet | TitleSet | DisabledSet | IsInlineSet | StartLineSet | StartColumnSet | 0)}; + + + CSSStyleSheetHeaderBuilder& setStyleSheetId(const String& value) + { + static_assert(!(STATE & StyleSheetIdSet), "property styleSheetId should not be set yet"); + m_result->setStyleSheetId(value); + return castState(); + } + + CSSStyleSheetHeaderBuilder& setFrameId(const String& value) + { + static_assert(!(STATE & FrameIdSet), "property frameId should not be set yet"); + m_result->setFrameId(value); + return castState(); + } + + CSSStyleSheetHeaderBuilder& setSourceURL(const String& value) + { + static_assert(!(STATE & SourceURLSet), "property sourceURL should not be set yet"); + m_result->setSourceURL(value); + return castState(); + } + + CSSStyleSheetHeaderBuilder& setSourceMapURL(const String& value) + { + m_result->setSourceMapURL(value); + return *this; + } + + CSSStyleSheetHeaderBuilder& setOrigin(const String& value) + { + static_assert(!(STATE & OriginSet), "property origin should not be set yet"); + m_result->setOrigin(value); + return castState(); + } + + CSSStyleSheetHeaderBuilder& setTitle(const String& value) + { + static_assert(!(STATE & TitleSet), "property title should not be set yet"); + m_result->setTitle(value); + return castState(); + } + + CSSStyleSheetHeaderBuilder& setOwnerNode(int value) + { + m_result->setOwnerNode(value); + return *this; + } + + CSSStyleSheetHeaderBuilder& setDisabled(bool value) + { + static_assert(!(STATE & DisabledSet), "property disabled should not be set yet"); + m_result->setDisabled(value); + return castState(); + } + + CSSStyleSheetHeaderBuilder& setHasSourceURL(bool value) + { + m_result->setHasSourceURL(value); + return *this; + } + + CSSStyleSheetHeaderBuilder& setIsInline(bool value) + { + static_assert(!(STATE & IsInlineSet), "property isInline should not be set yet"); + m_result->setIsInline(value); + return castState(); + } + + CSSStyleSheetHeaderBuilder& setStartLine(double value) + { + static_assert(!(STATE & StartLineSet), "property startLine should not be set yet"); + m_result->setStartLine(value); + return castState(); + } + + CSSStyleSheetHeaderBuilder& setStartColumn(double value) + { + static_assert(!(STATE & StartColumnSet), "property startColumn should not be set yet"); + m_result->setStartColumn(value); + return castState(); + } + + std::unique_ptr build() + { + static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet"); + return std::move(m_result); + } + + private: + friend class CSSStyleSheetHeader; + CSSStyleSheetHeaderBuilder() : m_result(new CSSStyleSheetHeader()) { } + + template CSSStyleSheetHeaderBuilder& castState() + { + return *reinterpret_cast*>(this); + } + + std::unique_ptr m_result; + }; + + static CSSStyleSheetHeaderBuilder<0> create() + { + return CSSStyleSheetHeaderBuilder<0>(); + } + +private: + CSSStyleSheetHeader() + { + m_disabled = false; + m_isInline = false; + m_startLine = 0; + m_startColumn = 0; + } + + String m_styleSheetId; + String m_frameId; + String m_sourceURL; + Maybe m_sourceMapURL; + String m_origin; + String m_title; + Maybe m_ownerNode; + bool m_disabled; + Maybe m_hasSourceURL; + bool m_isInline; + double m_startLine; + double m_startColumn; +}; + + +// CSS rule representation. +class CSSRule { + PROTOCOL_DISALLOW_COPY(CSSRule); +public: + static std::unique_ptr parse(protocol::Value* value, ErrorSupport* errors); + + ~CSSRule() { } + + bool hasStyleSheetId() { return m_styleSheetId.isJust(); } + String getStyleSheetId(const String& defaultValue) { return m_styleSheetId.isJust() ? m_styleSheetId.fromJust() : defaultValue; } + void setStyleSheetId(const String& value) { m_styleSheetId = value; } + + protocol::CSS::SelectorList* getSelectorList() { return m_selectorList.get(); } + void setSelectorList(std::unique_ptr value) { m_selectorList = std::move(value); } + + String getOrigin() { return m_origin; } + void setOrigin(const String& value) { m_origin = value; } + + protocol::CSS::CSSStyle* getStyle() { return m_style.get(); } + void setStyle(std::unique_ptr value) { m_style = std::move(value); } + + bool hasMedia() { return m_media.isJust(); } + protocol::Array* getMedia(protocol::Array* defaultValue) { return m_media.isJust() ? m_media.fromJust() : defaultValue; } + void setMedia(std::unique_ptr> value) { m_media = std::move(value); } + + std::unique_ptr serialize() const; + std::unique_ptr clone() const; + + template + class CSSRuleBuilder { + public: + enum { + NoFieldsSet = 0, + SelectorListSet = 1 << 1, + OriginSet = 1 << 2, + StyleSet = 1 << 3, + AllFieldsSet = (SelectorListSet | OriginSet | StyleSet | 0)}; + + + CSSRuleBuilder& setStyleSheetId(const String& value) + { + m_result->setStyleSheetId(value); + return *this; + } + + CSSRuleBuilder& setSelectorList(std::unique_ptr value) + { + static_assert(!(STATE & SelectorListSet), "property selectorList should not be set yet"); + m_result->setSelectorList(std::move(value)); + return castState(); + } + + CSSRuleBuilder& setOrigin(const String& value) + { + static_assert(!(STATE & OriginSet), "property origin should not be set yet"); + m_result->setOrigin(value); + return castState(); + } + + CSSRuleBuilder& setStyle(std::unique_ptr value) + { + static_assert(!(STATE & StyleSet), "property style should not be set yet"); + m_result->setStyle(std::move(value)); + return castState(); + } + + CSSRuleBuilder& setMedia(std::unique_ptr> value) + { + m_result->setMedia(std::move(value)); + return *this; + } + + std::unique_ptr build() + { + static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet"); + return std::move(m_result); + } + + private: + friend class CSSRule; + CSSRuleBuilder() : m_result(new CSSRule()) { } + + template CSSRuleBuilder& castState() + { + return *reinterpret_cast*>(this); + } + + std::unique_ptr m_result; + }; + + static CSSRuleBuilder<0> create() + { + return CSSRuleBuilder<0>(); + } + +private: + CSSRule() + { + } + + Maybe m_styleSheetId; + std::unique_ptr m_selectorList; + String m_origin; + std::unique_ptr m_style; + Maybe> m_media; +}; + + +// Text range within a resource. All numbers are zero-based. +class SourceRange { + PROTOCOL_DISALLOW_COPY(SourceRange); +public: + static std::unique_ptr parse(protocol::Value* value, ErrorSupport* errors); + + ~SourceRange() { } + + int getStartLine() { return m_startLine; } + void setStartLine(int value) { m_startLine = value; } + + int getStartColumn() { return m_startColumn; } + void setStartColumn(int value) { m_startColumn = value; } + + int getEndLine() { return m_endLine; } + void setEndLine(int value) { m_endLine = value; } + + int getEndColumn() { return m_endColumn; } + void setEndColumn(int value) { m_endColumn = value; } + + std::unique_ptr serialize() const; + std::unique_ptr clone() const; + + template + class SourceRangeBuilder { + public: + enum { + NoFieldsSet = 0, + StartLineSet = 1 << 1, + StartColumnSet = 1 << 2, + EndLineSet = 1 << 3, + EndColumnSet = 1 << 4, + AllFieldsSet = (StartLineSet | StartColumnSet | EndLineSet | EndColumnSet | 0)}; + + + SourceRangeBuilder& setStartLine(int value) + { + static_assert(!(STATE & StartLineSet), "property startLine should not be set yet"); + m_result->setStartLine(value); + return castState(); + } + + SourceRangeBuilder& setStartColumn(int value) + { + static_assert(!(STATE & StartColumnSet), "property startColumn should not be set yet"); + m_result->setStartColumn(value); + return castState(); + } + + SourceRangeBuilder& setEndLine(int value) + { + static_assert(!(STATE & EndLineSet), "property endLine should not be set yet"); + m_result->setEndLine(value); + return castState(); + } + + SourceRangeBuilder& setEndColumn(int value) + { + static_assert(!(STATE & EndColumnSet), "property endColumn should not be set yet"); + m_result->setEndColumn(value); + return castState(); + } + + std::unique_ptr build() + { + static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet"); + return std::move(m_result); + } + + private: + friend class SourceRange; + SourceRangeBuilder() : m_result(new SourceRange()) { } + + template SourceRangeBuilder& castState() + { + return *reinterpret_cast*>(this); + } + + std::unique_ptr m_result; + }; + + static SourceRangeBuilder<0> create() + { + return SourceRangeBuilder<0>(); + } + +private: + SourceRange() + { + m_startLine = 0; + m_startColumn = 0; + m_endLine = 0; + m_endColumn = 0; + } + + int m_startLine; + int m_startColumn; + int m_endLine; + int m_endColumn; +}; + + +// +class ShorthandEntry { + PROTOCOL_DISALLOW_COPY(ShorthandEntry); +public: + static std::unique_ptr parse(protocol::Value* value, ErrorSupport* errors); + + ~ShorthandEntry() { } + + String getName() { return m_name; } + void setName(const String& value) { m_name = value; } + + String getValue() { return m_value; } + void setValue(const String& value) { m_value = value; } + + bool hasImportant() { return m_important.isJust(); } + bool getImportant(bool defaultValue) { return m_important.isJust() ? m_important.fromJust() : defaultValue; } + void setImportant(bool value) { m_important = value; } + + std::unique_ptr serialize() const; + std::unique_ptr clone() const; + + template + class ShorthandEntryBuilder { + public: + enum { + NoFieldsSet = 0, + NameSet = 1 << 1, + ValueSet = 1 << 2, + AllFieldsSet = (NameSet | ValueSet | 0)}; + + + ShorthandEntryBuilder& setName(const String& value) + { + static_assert(!(STATE & NameSet), "property name should not be set yet"); + m_result->setName(value); + return castState(); + } + + ShorthandEntryBuilder& setValue(const String& value) + { + static_assert(!(STATE & ValueSet), "property value should not be set yet"); + m_result->setValue(value); + return castState(); + } + + ShorthandEntryBuilder& setImportant(bool value) + { + m_result->setImportant(value); + return *this; + } + + std::unique_ptr build() + { + static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet"); + return std::move(m_result); + } + + private: + friend class ShorthandEntry; + ShorthandEntryBuilder() : m_result(new ShorthandEntry()) { } + + template ShorthandEntryBuilder& castState() + { + return *reinterpret_cast*>(this); + } + + std::unique_ptr m_result; + }; + + static ShorthandEntryBuilder<0> create() + { + return ShorthandEntryBuilder<0>(); + } + +private: + ShorthandEntry() + { + } + + String m_name; + String m_value; + Maybe m_important; +}; + + +// +class CSSComputedStyleProperty { + PROTOCOL_DISALLOW_COPY(CSSComputedStyleProperty); +public: + static std::unique_ptr parse(protocol::Value* value, ErrorSupport* errors); + + ~CSSComputedStyleProperty() { } + + String getName() { return m_name; } + void setName(const String& value) { m_name = value; } + + String getValue() { return m_value; } + void setValue(const String& value) { m_value = value; } + + std::unique_ptr serialize() const; + std::unique_ptr clone() const; + + template + class CSSComputedStylePropertyBuilder { + public: + enum { + NoFieldsSet = 0, + NameSet = 1 << 1, + ValueSet = 1 << 2, + AllFieldsSet = (NameSet | ValueSet | 0)}; + + + CSSComputedStylePropertyBuilder& setName(const String& value) + { + static_assert(!(STATE & NameSet), "property name should not be set yet"); + m_result->setName(value); + return castState(); + } + + CSSComputedStylePropertyBuilder& setValue(const String& value) + { + static_assert(!(STATE & ValueSet), "property value should not be set yet"); + m_result->setValue(value); + return castState(); + } + + std::unique_ptr build() + { + static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet"); + return std::move(m_result); + } + + private: + friend class CSSComputedStyleProperty; + CSSComputedStylePropertyBuilder() : m_result(new CSSComputedStyleProperty()) { } + + template CSSComputedStylePropertyBuilder& castState() + { + return *reinterpret_cast*>(this); + } + + std::unique_ptr m_result; + }; + + static CSSComputedStylePropertyBuilder<0> create() + { + return CSSComputedStylePropertyBuilder<0>(); + } + +private: + CSSComputedStyleProperty() + { + } + + String m_name; + String m_value; +}; + + +// CSS style representation. +class CSSStyle { + PROTOCOL_DISALLOW_COPY(CSSStyle); +public: + static std::unique_ptr parse(protocol::Value* value, ErrorSupport* errors); + + ~CSSStyle() { } + + bool hasStyleSheetId() { return m_styleSheetId.isJust(); } + String getStyleSheetId(const String& defaultValue) { return m_styleSheetId.isJust() ? m_styleSheetId.fromJust() : defaultValue; } + void setStyleSheetId(const String& value) { m_styleSheetId = value; } + + protocol::Array* getCssProperties() { return m_cssProperties.get(); } + void setCssProperties(std::unique_ptr> value) { m_cssProperties = std::move(value); } + + protocol::Array* getShorthandEntries() { return m_shorthandEntries.get(); } + void setShorthandEntries(std::unique_ptr> value) { m_shorthandEntries = std::move(value); } + + bool hasCssText() { return m_cssText.isJust(); } + String getCssText(const String& defaultValue) { return m_cssText.isJust() ? m_cssText.fromJust() : defaultValue; } + void setCssText(const String& value) { m_cssText = value; } + + bool hasRange() { return m_range.isJust(); } + protocol::CSS::SourceRange* getRange(protocol::CSS::SourceRange* defaultValue) { return m_range.isJust() ? m_range.fromJust() : defaultValue; } + void setRange(std::unique_ptr value) { m_range = std::move(value); } + + std::unique_ptr serialize() const; + std::unique_ptr clone() const; + + template + class CSSStyleBuilder { + public: + enum { + NoFieldsSet = 0, + CssPropertiesSet = 1 << 1, + ShorthandEntriesSet = 1 << 2, + AllFieldsSet = (CssPropertiesSet | ShorthandEntriesSet | 0)}; + + + CSSStyleBuilder& setStyleSheetId(const String& value) + { + m_result->setStyleSheetId(value); + return *this; + } + + CSSStyleBuilder& setCssProperties(std::unique_ptr> value) + { + static_assert(!(STATE & CssPropertiesSet), "property cssProperties should not be set yet"); + m_result->setCssProperties(std::move(value)); + return castState(); + } + + CSSStyleBuilder& setShorthandEntries(std::unique_ptr> value) + { + static_assert(!(STATE & ShorthandEntriesSet), "property shorthandEntries should not be set yet"); + m_result->setShorthandEntries(std::move(value)); + return castState(); + } + + CSSStyleBuilder& setCssText(const String& value) + { + m_result->setCssText(value); + return *this; + } + + CSSStyleBuilder& setRange(std::unique_ptr value) + { + m_result->setRange(std::move(value)); + return *this; + } + + std::unique_ptr build() + { + static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet"); + return std::move(m_result); + } + + private: + friend class CSSStyle; + CSSStyleBuilder() : m_result(new CSSStyle()) { } + + template CSSStyleBuilder& castState() + { + return *reinterpret_cast*>(this); + } + + std::unique_ptr m_result; + }; + + static CSSStyleBuilder<0> create() + { + return CSSStyleBuilder<0>(); + } + +private: + CSSStyle() + { + } + + Maybe m_styleSheetId; + std::unique_ptr> m_cssProperties; + std::unique_ptr> m_shorthandEntries; + Maybe m_cssText; + Maybe m_range; +}; + + +// CSS property declaration data. +class CSSProperty { + PROTOCOL_DISALLOW_COPY(CSSProperty); +public: + static std::unique_ptr parse(protocol::Value* value, ErrorSupport* errors); + + ~CSSProperty() { } + + String getName() { return m_name; } + void setName(const String& value) { m_name = value; } + + String getValue() { return m_value; } + void setValue(const String& value) { m_value = value; } + + bool hasImportant() { return m_important.isJust(); } + bool getImportant(bool defaultValue) { return m_important.isJust() ? m_important.fromJust() : defaultValue; } + void setImportant(bool value) { m_important = value; } + + bool hasImplicit() { return m_implicit.isJust(); } + bool getImplicit(bool defaultValue) { return m_implicit.isJust() ? m_implicit.fromJust() : defaultValue; } + void setImplicit(bool value) { m_implicit = value; } + + bool hasText() { return m_text.isJust(); } + String getText(const String& defaultValue) { return m_text.isJust() ? m_text.fromJust() : defaultValue; } + void setText(const String& value) { m_text = value; } + + bool hasParsedOk() { return m_parsedOk.isJust(); } + bool getParsedOk(bool defaultValue) { return m_parsedOk.isJust() ? m_parsedOk.fromJust() : defaultValue; } + void setParsedOk(bool value) { m_parsedOk = value; } + + bool hasDisabled() { return m_disabled.isJust(); } + bool getDisabled(bool defaultValue) { return m_disabled.isJust() ? m_disabled.fromJust() : defaultValue; } + void setDisabled(bool value) { m_disabled = value; } + + bool hasRange() { return m_range.isJust(); } + protocol::CSS::SourceRange* getRange(protocol::CSS::SourceRange* defaultValue) { return m_range.isJust() ? m_range.fromJust() : defaultValue; } + void setRange(std::unique_ptr value) { m_range = std::move(value); } + + std::unique_ptr serialize() const; + std::unique_ptr clone() const; + + template + class CSSPropertyBuilder { + public: + enum { + NoFieldsSet = 0, + NameSet = 1 << 1, + ValueSet = 1 << 2, + AllFieldsSet = (NameSet | ValueSet | 0)}; + + + CSSPropertyBuilder& setName(const String& value) + { + static_assert(!(STATE & NameSet), "property name should not be set yet"); + m_result->setName(value); + return castState(); + } + + CSSPropertyBuilder& setValue(const String& value) + { + static_assert(!(STATE & ValueSet), "property value should not be set yet"); + m_result->setValue(value); + return castState(); + } + + CSSPropertyBuilder& setImportant(bool value) + { + m_result->setImportant(value); + return *this; + } + + CSSPropertyBuilder& setImplicit(bool value) + { + m_result->setImplicit(value); + return *this; + } + + CSSPropertyBuilder& setText(const String& value) + { + m_result->setText(value); + return *this; + } + + CSSPropertyBuilder& setParsedOk(bool value) + { + m_result->setParsedOk(value); + return *this; + } + + CSSPropertyBuilder& setDisabled(bool value) + { + m_result->setDisabled(value); + return *this; + } + + CSSPropertyBuilder& setRange(std::unique_ptr value) + { + m_result->setRange(std::move(value)); + return *this; + } + + std::unique_ptr build() + { + static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet"); + return std::move(m_result); + } + + private: + friend class CSSProperty; + CSSPropertyBuilder() : m_result(new CSSProperty()) { } + + template CSSPropertyBuilder& castState() + { + return *reinterpret_cast*>(this); + } + + std::unique_ptr m_result; + }; + + static CSSPropertyBuilder<0> create() + { + return CSSPropertyBuilder<0>(); + } + +private: + CSSProperty() + { + } + + String m_name; + String m_value; + Maybe m_important; + Maybe m_implicit; + Maybe m_text; + Maybe m_parsedOk; + Maybe m_disabled; + Maybe m_range; +}; + + +// CSS media rule descriptor. +class CSSMedia { + PROTOCOL_DISALLOW_COPY(CSSMedia); +public: + static std::unique_ptr parse(protocol::Value* value, ErrorSupport* errors); + + ~CSSMedia() { } + + String getText() { return m_text; } + void setText(const String& value) { m_text = value; } + + struct SourceEnum { + static const char* MediaRule; + static const char* ImportRule; + static const char* LinkedSheet; + static const char* InlineSheet; + }; // SourceEnum + + String getSource() { return m_source; } + void setSource(const String& value) { m_source = value; } + + bool hasSourceURL() { return m_sourceURL.isJust(); } + String getSourceURL(const String& defaultValue) { return m_sourceURL.isJust() ? m_sourceURL.fromJust() : defaultValue; } + void setSourceURL(const String& value) { m_sourceURL = value; } + + bool hasRange() { return m_range.isJust(); } + protocol::CSS::SourceRange* getRange(protocol::CSS::SourceRange* defaultValue) { return m_range.isJust() ? m_range.fromJust() : defaultValue; } + void setRange(std::unique_ptr value) { m_range = std::move(value); } + + bool hasStyleSheetId() { return m_styleSheetId.isJust(); } + String getStyleSheetId(const String& defaultValue) { return m_styleSheetId.isJust() ? m_styleSheetId.fromJust() : defaultValue; } + void setStyleSheetId(const String& value) { m_styleSheetId = value; } + + bool hasMediaList() { return m_mediaList.isJust(); } + protocol::Array* getMediaList(protocol::Array* defaultValue) { return m_mediaList.isJust() ? m_mediaList.fromJust() : defaultValue; } + void setMediaList(std::unique_ptr> value) { m_mediaList = std::move(value); } + + std::unique_ptr serialize() const; + std::unique_ptr clone() const; + + template + class CSSMediaBuilder { + public: + enum { + NoFieldsSet = 0, + TextSet = 1 << 1, + SourceSet = 1 << 2, + AllFieldsSet = (TextSet | SourceSet | 0)}; + + + CSSMediaBuilder& setText(const String& value) + { + static_assert(!(STATE & TextSet), "property text should not be set yet"); + m_result->setText(value); + return castState(); + } + + CSSMediaBuilder& setSource(const String& value) + { + static_assert(!(STATE & SourceSet), "property source should not be set yet"); + m_result->setSource(value); + return castState(); + } + + CSSMediaBuilder& setSourceURL(const String& value) + { + m_result->setSourceURL(value); + return *this; + } + + CSSMediaBuilder& setRange(std::unique_ptr value) + { + m_result->setRange(std::move(value)); + return *this; + } + + CSSMediaBuilder& setStyleSheetId(const String& value) + { + m_result->setStyleSheetId(value); + return *this; + } + + CSSMediaBuilder& setMediaList(std::unique_ptr> value) + { + m_result->setMediaList(std::move(value)); + return *this; + } + + std::unique_ptr build() + { + static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet"); + return std::move(m_result); + } + + private: + friend class CSSMedia; + CSSMediaBuilder() : m_result(new CSSMedia()) { } + + template CSSMediaBuilder& castState() + { + return *reinterpret_cast*>(this); + } + + std::unique_ptr m_result; + }; + + static CSSMediaBuilder<0> create() + { + return CSSMediaBuilder<0>(); + } + +private: + CSSMedia() + { + } + + String m_text; + String m_source; + Maybe m_sourceURL; + Maybe m_range; + Maybe m_styleSheetId; + Maybe> m_mediaList; +}; + + +// Media query descriptor. +class MediaQuery { + PROTOCOL_DISALLOW_COPY(MediaQuery); +public: + static std::unique_ptr parse(protocol::Value* value, ErrorSupport* errors); + + ~MediaQuery() { } + + protocol::Array* getExpressions() { return m_expressions.get(); } + void setExpressions(std::unique_ptr> value) { m_expressions = std::move(value); } + + bool getActive() { return m_active; } + void setActive(bool value) { m_active = value; } + + std::unique_ptr serialize() const; + std::unique_ptr clone() const; + + template + class MediaQueryBuilder { + public: + enum { + NoFieldsSet = 0, + ExpressionsSet = 1 << 1, + ActiveSet = 1 << 2, + AllFieldsSet = (ExpressionsSet | ActiveSet | 0)}; + + + MediaQueryBuilder& setExpressions(std::unique_ptr> value) + { + static_assert(!(STATE & ExpressionsSet), "property expressions should not be set yet"); + m_result->setExpressions(std::move(value)); + return castState(); + } + + MediaQueryBuilder& setActive(bool value) + { + static_assert(!(STATE & ActiveSet), "property active should not be set yet"); + m_result->setActive(value); + return castState(); + } + + std::unique_ptr build() + { + static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet"); + return std::move(m_result); + } + + private: + friend class MediaQuery; + MediaQueryBuilder() : m_result(new MediaQuery()) { } + + template MediaQueryBuilder& castState() + { + return *reinterpret_cast*>(this); + } + + std::unique_ptr m_result; + }; + + static MediaQueryBuilder<0> create() + { + return MediaQueryBuilder<0>(); + } + +private: + MediaQuery() + { + m_active = false; + } + + std::unique_ptr> m_expressions; + bool m_active; +}; + + +// Media query expression descriptor. +class MediaQueryExpression { + PROTOCOL_DISALLOW_COPY(MediaQueryExpression); +public: + static std::unique_ptr parse(protocol::Value* value, ErrorSupport* errors); + + ~MediaQueryExpression() { } + + double getValue() { return m_value; } + void setValue(double value) { m_value = value; } + + String getUnit() { return m_unit; } + void setUnit(const String& value) { m_unit = value; } + + String getFeature() { return m_feature; } + void setFeature(const String& value) { m_feature = value; } + + bool hasValueRange() { return m_valueRange.isJust(); } + protocol::CSS::SourceRange* getValueRange(protocol::CSS::SourceRange* defaultValue) { return m_valueRange.isJust() ? m_valueRange.fromJust() : defaultValue; } + void setValueRange(std::unique_ptr value) { m_valueRange = std::move(value); } + + bool hasComputedLength() { return m_computedLength.isJust(); } + double getComputedLength(double defaultValue) { return m_computedLength.isJust() ? m_computedLength.fromJust() : defaultValue; } + void setComputedLength(double value) { m_computedLength = value; } + + std::unique_ptr serialize() const; + std::unique_ptr clone() const; + + template + class MediaQueryExpressionBuilder { + public: + enum { + NoFieldsSet = 0, + ValueSet = 1 << 1, + UnitSet = 1 << 2, + FeatureSet = 1 << 3, + AllFieldsSet = (ValueSet | UnitSet | FeatureSet | 0)}; + + + MediaQueryExpressionBuilder& setValue(double value) + { + static_assert(!(STATE & ValueSet), "property value should not be set yet"); + m_result->setValue(value); + return castState(); + } + + MediaQueryExpressionBuilder& setUnit(const String& value) + { + static_assert(!(STATE & UnitSet), "property unit should not be set yet"); + m_result->setUnit(value); + return castState(); + } + + MediaQueryExpressionBuilder& setFeature(const String& value) + { + static_assert(!(STATE & FeatureSet), "property feature should not be set yet"); + m_result->setFeature(value); + return castState(); + } + + MediaQueryExpressionBuilder& setValueRange(std::unique_ptr value) + { + m_result->setValueRange(std::move(value)); + return *this; + } + + MediaQueryExpressionBuilder& setComputedLength(double value) + { + m_result->setComputedLength(value); + return *this; + } + + std::unique_ptr build() + { + static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet"); + return std::move(m_result); + } + + private: + friend class MediaQueryExpression; + MediaQueryExpressionBuilder() : m_result(new MediaQueryExpression()) { } + + template MediaQueryExpressionBuilder& castState() + { + return *reinterpret_cast*>(this); + } + + std::unique_ptr m_result; + }; + + static MediaQueryExpressionBuilder<0> create() + { + return MediaQueryExpressionBuilder<0>(); + } + +private: + MediaQueryExpression() + { + m_value = 0; + } + + double m_value; + String m_unit; + String m_feature; + Maybe m_valueRange; + Maybe m_computedLength; +}; + + +// Information about amount of glyphs that were rendered with given font. +class PlatformFontUsage { + PROTOCOL_DISALLOW_COPY(PlatformFontUsage); +public: + static std::unique_ptr parse(protocol::Value* value, ErrorSupport* errors); + + ~PlatformFontUsage() { } + + String getFamilyName() { return m_familyName; } + void setFamilyName(const String& value) { m_familyName = value; } + + bool getIsCustomFont() { return m_isCustomFont; } + void setIsCustomFont(bool value) { m_isCustomFont = value; } + + double getGlyphCount() { return m_glyphCount; } + void setGlyphCount(double value) { m_glyphCount = value; } + + std::unique_ptr serialize() const; + std::unique_ptr clone() const; + + template + class PlatformFontUsageBuilder { + public: + enum { + NoFieldsSet = 0, + FamilyNameSet = 1 << 1, + IsCustomFontSet = 1 << 2, + GlyphCountSet = 1 << 3, + AllFieldsSet = (FamilyNameSet | IsCustomFontSet | GlyphCountSet | 0)}; + + + PlatformFontUsageBuilder& setFamilyName(const String& value) + { + static_assert(!(STATE & FamilyNameSet), "property familyName should not be set yet"); + m_result->setFamilyName(value); + return castState(); + } + + PlatformFontUsageBuilder& setIsCustomFont(bool value) + { + static_assert(!(STATE & IsCustomFontSet), "property isCustomFont should not be set yet"); + m_result->setIsCustomFont(value); + return castState(); + } + + PlatformFontUsageBuilder& setGlyphCount(double value) + { + static_assert(!(STATE & GlyphCountSet), "property glyphCount should not be set yet"); + m_result->setGlyphCount(value); + return castState(); + } + + std::unique_ptr build() + { + static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet"); + return std::move(m_result); + } + + private: + friend class PlatformFontUsage; + PlatformFontUsageBuilder() : m_result(new PlatformFontUsage()) { } + + template PlatformFontUsageBuilder& castState() + { + return *reinterpret_cast*>(this); + } + + std::unique_ptr m_result; + }; + + static PlatformFontUsageBuilder<0> create() + { + return PlatformFontUsageBuilder<0>(); + } + +private: + PlatformFontUsage() + { + m_isCustomFont = false; + m_glyphCount = 0; + } + + String m_familyName; + bool m_isCustomFont; + double m_glyphCount; +}; + + +// CSS keyframes rule representation. +class CSSKeyframesRule { + PROTOCOL_DISALLOW_COPY(CSSKeyframesRule); +public: + static std::unique_ptr parse(protocol::Value* value, ErrorSupport* errors); + + ~CSSKeyframesRule() { } + + protocol::CSS::Value* getAnimationName() { return m_animationName.get(); } + void setAnimationName(std::unique_ptr value) { m_animationName = std::move(value); } + + protocol::Array* getKeyframes() { return m_keyframes.get(); } + void setKeyframes(std::unique_ptr> value) { m_keyframes = std::move(value); } + + std::unique_ptr serialize() const; + std::unique_ptr clone() const; + + template + class CSSKeyframesRuleBuilder { + public: + enum { + NoFieldsSet = 0, + AnimationNameSet = 1 << 1, + KeyframesSet = 1 << 2, + AllFieldsSet = (AnimationNameSet | KeyframesSet | 0)}; + + + CSSKeyframesRuleBuilder& setAnimationName(std::unique_ptr value) + { + static_assert(!(STATE & AnimationNameSet), "property animationName should not be set yet"); + m_result->setAnimationName(std::move(value)); + return castState(); + } + + CSSKeyframesRuleBuilder& setKeyframes(std::unique_ptr> value) + { + static_assert(!(STATE & KeyframesSet), "property keyframes should not be set yet"); + m_result->setKeyframes(std::move(value)); + return castState(); + } + + std::unique_ptr build() + { + static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet"); + return std::move(m_result); + } + + private: + friend class CSSKeyframesRule; + CSSKeyframesRuleBuilder() : m_result(new CSSKeyframesRule()) { } + + template CSSKeyframesRuleBuilder& castState() + { + return *reinterpret_cast*>(this); + } + + std::unique_ptr m_result; + }; + + static CSSKeyframesRuleBuilder<0> create() + { + return CSSKeyframesRuleBuilder<0>(); + } + +private: + CSSKeyframesRule() + { + } + + std::unique_ptr m_animationName; + std::unique_ptr> m_keyframes; +}; + + +// CSS keyframe rule representation. +class CSSKeyframeRule { + PROTOCOL_DISALLOW_COPY(CSSKeyframeRule); +public: + static std::unique_ptr parse(protocol::Value* value, ErrorSupport* errors); + + ~CSSKeyframeRule() { } + + bool hasStyleSheetId() { return m_styleSheetId.isJust(); } + String getStyleSheetId(const String& defaultValue) { return m_styleSheetId.isJust() ? m_styleSheetId.fromJust() : defaultValue; } + void setStyleSheetId(const String& value) { m_styleSheetId = value; } + + String getOrigin() { return m_origin; } + void setOrigin(const String& value) { m_origin = value; } + + protocol::CSS::Value* getKeyText() { return m_keyText.get(); } + void setKeyText(std::unique_ptr value) { m_keyText = std::move(value); } + + protocol::CSS::CSSStyle* getStyle() { return m_style.get(); } + void setStyle(std::unique_ptr value) { m_style = std::move(value); } + + std::unique_ptr serialize() const; + std::unique_ptr clone() const; + + template + class CSSKeyframeRuleBuilder { + public: + enum { + NoFieldsSet = 0, + OriginSet = 1 << 1, + KeyTextSet = 1 << 2, + StyleSet = 1 << 3, + AllFieldsSet = (OriginSet | KeyTextSet | StyleSet | 0)}; + + + CSSKeyframeRuleBuilder& setStyleSheetId(const String& value) + { + m_result->setStyleSheetId(value); + return *this; + } + + CSSKeyframeRuleBuilder& setOrigin(const String& value) + { + static_assert(!(STATE & OriginSet), "property origin should not be set yet"); + m_result->setOrigin(value); + return castState(); + } + + CSSKeyframeRuleBuilder& setKeyText(std::unique_ptr value) + { + static_assert(!(STATE & KeyTextSet), "property keyText should not be set yet"); + m_result->setKeyText(std::move(value)); + return castState(); + } + + CSSKeyframeRuleBuilder& setStyle(std::unique_ptr value) + { + static_assert(!(STATE & StyleSet), "property style should not be set yet"); + m_result->setStyle(std::move(value)); + return castState(); + } + + std::unique_ptr build() + { + static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet"); + return std::move(m_result); + } + + private: + friend class CSSKeyframeRule; + CSSKeyframeRuleBuilder() : m_result(new CSSKeyframeRule()) { } + + template CSSKeyframeRuleBuilder& castState() + { + return *reinterpret_cast*>(this); + } + + std::unique_ptr m_result; + }; + + static CSSKeyframeRuleBuilder<0> create() + { + return CSSKeyframeRuleBuilder<0>(); + } + +private: + CSSKeyframeRule() + { + } + + Maybe m_styleSheetId; + String m_origin; + std::unique_ptr m_keyText; + std::unique_ptr m_style; +}; + + +// A descriptor of operation to mutate style declaration text. +class StyleDeclarationEdit { + PROTOCOL_DISALLOW_COPY(StyleDeclarationEdit); +public: + static std::unique_ptr parse(protocol::Value* value, ErrorSupport* errors); + + ~StyleDeclarationEdit() { } + + String getStyleSheetId() { return m_styleSheetId; } + void setStyleSheetId(const String& value) { m_styleSheetId = value; } + + protocol::CSS::SourceRange* getRange() { return m_range.get(); } + void setRange(std::unique_ptr value) { m_range = std::move(value); } + + String getText() { return m_text; } + void setText(const String& value) { m_text = value; } + + std::unique_ptr serialize() const; + std::unique_ptr clone() const; + + template + class StyleDeclarationEditBuilder { + public: + enum { + NoFieldsSet = 0, + StyleSheetIdSet = 1 << 1, + RangeSet = 1 << 2, + TextSet = 1 << 3, + AllFieldsSet = (StyleSheetIdSet | RangeSet | TextSet | 0)}; + + + StyleDeclarationEditBuilder& setStyleSheetId(const String& value) + { + static_assert(!(STATE & StyleSheetIdSet), "property styleSheetId should not be set yet"); + m_result->setStyleSheetId(value); + return castState(); + } + + StyleDeclarationEditBuilder& setRange(std::unique_ptr value) + { + static_assert(!(STATE & RangeSet), "property range should not be set yet"); + m_result->setRange(std::move(value)); + return castState(); + } + + StyleDeclarationEditBuilder& setText(const String& value) + { + static_assert(!(STATE & TextSet), "property text should not be set yet"); + m_result->setText(value); + return castState(); + } + + std::unique_ptr build() + { + static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet"); + return std::move(m_result); + } + + private: + friend class StyleDeclarationEdit; + StyleDeclarationEditBuilder() : m_result(new StyleDeclarationEdit()) { } + + template StyleDeclarationEditBuilder& castState() + { + return *reinterpret_cast*>(this); + } + + std::unique_ptr m_result; + }; + + static StyleDeclarationEditBuilder<0> create() + { + return StyleDeclarationEditBuilder<0>(); + } + +private: + StyleDeclarationEdit() + { + } + + String m_styleSheetId; + std::unique_ptr m_range; + String m_text; +}; + + +// ------------- Backend interface. + +class Backend { +public: + virtual ~Backend() { } + + class EnableCallback : public BackendCallback { + public: + virtual void sendSuccess() = 0; + }; + virtual void enable(std::unique_ptr callback) = 0; + virtual void disable(ErrorString*) = 0; + virtual void getMatchedStylesForNode(ErrorString*, int in_nodeId, Maybe* out_inlineStyle, Maybe* out_attributesStyle, Maybe>* out_matchedCSSRules, Maybe>* out_pseudoElements, Maybe>* out_inherited, Maybe>* out_cssKeyframesRules) = 0; + virtual void getInlineStylesForNode(ErrorString*, int in_nodeId, Maybe* out_inlineStyle, Maybe* out_attributesStyle) = 0; + virtual void getComputedStyleForNode(ErrorString*, int in_nodeId, std::unique_ptr>* out_computedStyle) = 0; + virtual void getPlatformFontsForNode(ErrorString*, int in_nodeId, std::unique_ptr>* out_fonts) = 0; + virtual void getStyleSheetText(ErrorString*, const String& in_styleSheetId, String* out_text) = 0; + +}; + +// ------------- Frontend interface. + +class Frontend { +public: + Frontend(FrontendChannel* frontendChannel) : m_frontendChannel(frontendChannel) { } + void mediaQueryResultChanged(); + void fontsUpdated(); + void styleSheetChanged(const String& styleSheetId); + void styleSheetAdded(std::unique_ptr header); + void styleSheetRemoved(const String& styleSheetId); + void layoutEditorChange(const String& styleSheetId, std::unique_ptr changeRange); + + void flush(); +private: + FrontendChannel* m_frontendChannel; +}; + +// ------------- Dispatcher. + +class Dispatcher { +public: + static void wire(UberDispatcher*, Backend*); + +private: + Dispatcher() { } +}; + +// ------------- Metainfo. + +class Metainfo { +public: + using BackendClass = Backend; + using FrontendClass = Frontend; + using DispatcherClass = Dispatcher; + static const char domainName[]; + static const char commandPrefix[]; + static const char version[]; +}; + +} // namespace CSS +} // namespace v8_inspector +} // namespace protocol + +#endif // !defined(v8_inspector_protocol_CSS_h) diff --git a/runtime/src/main/jni/v8_inspector/src/inspector/protocol/DOM.cpp b/runtime/src/main/jni/v8_inspector/src/inspector/protocol/DOM.cpp new file mode 100644 index 000000000..15b957eac --- /dev/null +++ b/runtime/src/main/jni/v8_inspector/src/inspector/protocol/DOM.cpp @@ -0,0 +1,864 @@ +// This file is generated + +// Copyright (c) 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "src/inspector/protocol/DOM.h" + +#include "src/inspector/protocol/Protocol.h" + +namespace v8_inspector { +namespace protocol { +namespace DOM { + +// ------------- Enum values from types. + +const char Metainfo::domainName[] = "DOM"; +const char Metainfo::commandPrefix[] = "DOM."; +const char Metainfo::version[] = "1.2"; + +namespace PseudoTypeEnum { +const char* Before = "before"; +const char* After = "after"; +} // namespace PseudoTypeEnum + +namespace ShadowRootTypeEnum { +const char* UserAgent = "user-agent"; +const char* Open = "open"; +const char* Closed = "closed"; +} // namespace ShadowRootTypeEnum + +namespace LiveRegionRelevantEnum { +const char* Additions = "additions"; +const char* Removals = "removals"; +const char* Text = "text"; +} // namespace LiveRegionRelevantEnum + +std::unique_ptr Node::parse(protocol::Value* value, ErrorSupport* errors) +{ + if (!value || value->type() != protocol::Value::TypeObject) { + errors->addError("object expected"); + return nullptr; + } + + std::unique_ptr result(new Node()); + protocol::DictionaryValue* object = DictionaryValue::cast(value); + errors->push(); + protocol::Value* nodeIdValue = object->get("nodeId"); + errors->setName("nodeId"); + result->m_nodeId = ValueConversions::parse(nodeIdValue, errors); + protocol::Value* nodeTypeValue = object->get("nodeType"); + errors->setName("nodeType"); + result->m_nodeType = ValueConversions::parse(nodeTypeValue, errors); + protocol::Value* nodeNameValue = object->get("nodeName"); + errors->setName("nodeName"); + result->m_nodeName = ValueConversions::parse(nodeNameValue, errors); + protocol::Value* localNameValue = object->get("localName"); + errors->setName("localName"); + result->m_localName = ValueConversions::parse(localNameValue, errors); + protocol::Value* nodeValueValue = object->get("nodeValue"); + errors->setName("nodeValue"); + result->m_nodeValue = ValueConversions::parse(nodeValueValue, errors); + protocol::Value* childNodeCountValue = object->get("childNodeCount"); + if (childNodeCountValue) { + errors->setName("childNodeCount"); + result->m_childNodeCount = ValueConversions::parse(childNodeCountValue, errors); + } + protocol::Value* childrenValue = object->get("children"); + if (childrenValue) { + errors->setName("children"); + result->m_children = ValueConversions>::parse(childrenValue, errors); + } + protocol::Value* attributesValue = object->get("attributes"); + if (attributesValue) { + errors->setName("attributes"); + result->m_attributes = ValueConversions>::parse(attributesValue, errors); + } + protocol::Value* documentURLValue = object->get("documentURL"); + if (documentURLValue) { + errors->setName("documentURL"); + result->m_documentURL = ValueConversions::parse(documentURLValue, errors); + } + protocol::Value* baseURLValue = object->get("baseURL"); + if (baseURLValue) { + errors->setName("baseURL"); + result->m_baseURL = ValueConversions::parse(baseURLValue, errors); + } + protocol::Value* publicIdValue = object->get("publicId"); + if (publicIdValue) { + errors->setName("publicId"); + result->m_publicId = ValueConversions::parse(publicIdValue, errors); + } + protocol::Value* systemIdValue = object->get("systemId"); + if (systemIdValue) { + errors->setName("systemId"); + result->m_systemId = ValueConversions::parse(systemIdValue, errors); + } + protocol::Value* xmlVersionValue = object->get("xmlVersion"); + if (xmlVersionValue) { + errors->setName("xmlVersion"); + result->m_xmlVersion = ValueConversions::parse(xmlVersionValue, errors); + } + protocol::Value* nameValue = object->get("name"); + if (nameValue) { + errors->setName("name"); + result->m_name = ValueConversions::parse(nameValue, errors); + } + protocol::Value* valueValue = object->get("value"); + if (valueValue) { + errors->setName("value"); + result->m_value = ValueConversions::parse(valueValue, errors); + } + protocol::Value* pseudoTypeValue = object->get("pseudoType"); + if (pseudoTypeValue) { + errors->setName("pseudoType"); + result->m_pseudoType = ValueConversions::parse(pseudoTypeValue, errors); + } + protocol::Value* shadowRootTypeValue = object->get("shadowRootType"); + if (shadowRootTypeValue) { + errors->setName("shadowRootType"); + result->m_shadowRootType = ValueConversions::parse(shadowRootTypeValue, errors); + } + protocol::Value* frameIdValue = object->get("frameId"); + if (frameIdValue) { + errors->setName("frameId"); + result->m_frameId = ValueConversions::parse(frameIdValue, errors); + } + protocol::Value* contentDocumentValue = object->get("contentDocument"); + if (contentDocumentValue) { + errors->setName("contentDocument"); + result->m_contentDocument = ValueConversions::parse(contentDocumentValue, errors); + } + protocol::Value* shadowRootsValue = object->get("shadowRoots"); + if (shadowRootsValue) { + errors->setName("shadowRoots"); + result->m_shadowRoots = ValueConversions>::parse(shadowRootsValue, errors); + } + protocol::Value* templateContentValue = object->get("templateContent"); + if (templateContentValue) { + errors->setName("templateContent"); + result->m_templateContent = ValueConversions::parse(templateContentValue, errors); + } + protocol::Value* pseudoElementsValue = object->get("pseudoElements"); + if (pseudoElementsValue) { + errors->setName("pseudoElements"); + result->m_pseudoElements = ValueConversions>::parse(pseudoElementsValue, errors); + } + protocol::Value* roleValue = object->get("role"); + if (roleValue) { + errors->setName("role"); + result->m_role = ValueConversions::parse(roleValue, errors); + } + protocol::Value* contentSecurityPolicyHashValue = object->get("contentSecurityPolicyHash"); + if (contentSecurityPolicyHashValue) { + errors->setName("contentSecurityPolicyHash"); + result->m_contentSecurityPolicyHash = ValueConversions::parse(contentSecurityPolicyHashValue, errors); + } + errors->pop(); + if (errors->hasErrors()) + return nullptr; + return result; +} + +std::unique_ptr Node::serialize() const +{ + std::unique_ptr result = DictionaryValue::create(); + result->setValue("nodeId", ValueConversions::serialize(m_nodeId)); + result->setValue("nodeType", ValueConversions::serialize(m_nodeType)); + result->setValue("nodeName", ValueConversions::serialize(m_nodeName)); + result->setValue("localName", ValueConversions::serialize(m_localName)); + result->setValue("nodeValue", ValueConversions::serialize(m_nodeValue)); + if (m_childNodeCount.isJust()) + result->setValue("childNodeCount", ValueConversions::serialize(m_childNodeCount.fromJust())); + if (m_children.isJust()) + result->setValue("children", ValueConversions>::serialize(m_children.fromJust())); + if (m_attributes.isJust()) + result->setValue("attributes", ValueConversions>::serialize(m_attributes.fromJust())); + if (m_documentURL.isJust()) + result->setValue("documentURL", ValueConversions::serialize(m_documentURL.fromJust())); + if (m_baseURL.isJust()) + result->setValue("baseURL", ValueConversions::serialize(m_baseURL.fromJust())); + if (m_publicId.isJust()) + result->setValue("publicId", ValueConversions::serialize(m_publicId.fromJust())); + if (m_systemId.isJust()) + result->setValue("systemId", ValueConversions::serialize(m_systemId.fromJust())); + if (m_xmlVersion.isJust()) + result->setValue("xmlVersion", ValueConversions::serialize(m_xmlVersion.fromJust())); + if (m_name.isJust()) + result->setValue("name", ValueConversions::serialize(m_name.fromJust())); + if (m_value.isJust()) + result->setValue("value", ValueConversions::serialize(m_value.fromJust())); + if (m_pseudoType.isJust()) + result->setValue("pseudoType", ValueConversions::serialize(m_pseudoType.fromJust())); + if (m_shadowRootType.isJust()) + result->setValue("shadowRootType", ValueConversions::serialize(m_shadowRootType.fromJust())); + if (m_frameId.isJust()) + result->setValue("frameId", ValueConversions::serialize(m_frameId.fromJust())); + if (m_contentDocument.isJust()) + result->setValue("contentDocument", ValueConversions::serialize(m_contentDocument.fromJust())); + if (m_shadowRoots.isJust()) + result->setValue("shadowRoots", ValueConversions>::serialize(m_shadowRoots.fromJust())); + if (m_templateContent.isJust()) + result->setValue("templateContent", ValueConversions::serialize(m_templateContent.fromJust())); + if (m_pseudoElements.isJust()) + result->setValue("pseudoElements", ValueConversions>::serialize(m_pseudoElements.fromJust())); + if (m_role.isJust()) + result->setValue("role", ValueConversions::serialize(m_role.fromJust())); + if (m_contentSecurityPolicyHash.isJust()) + result->setValue("contentSecurityPolicyHash", ValueConversions::serialize(m_contentSecurityPolicyHash.fromJust())); + return result; +} + +std::unique_ptr Node::clone() const +{ + ErrorSupport errors; + return parse(serialize().get(), &errors); +} + +std::unique_ptr RGBAColor::parse(protocol::Value* value, ErrorSupport* errors) +{ + if (!value || value->type() != protocol::Value::TypeObject) { + errors->addError("object expected"); + return nullptr; + } + + std::unique_ptr result(new RGBAColor()); + protocol::DictionaryValue* object = DictionaryValue::cast(value); + errors->push(); + protocol::Value* rValue = object->get("r"); + errors->setName("r"); + result->m_r = ValueConversions::parse(rValue, errors); + protocol::Value* gValue = object->get("g"); + errors->setName("g"); + result->m_g = ValueConversions::parse(gValue, errors); + protocol::Value* bValue = object->get("b"); + errors->setName("b"); + result->m_b = ValueConversions::parse(bValue, errors); + protocol::Value* aValue = object->get("a"); + if (aValue) { + errors->setName("a"); + result->m_a = ValueConversions::parse(aValue, errors); + } + errors->pop(); + if (errors->hasErrors()) + return nullptr; + return result; +} + +std::unique_ptr RGBAColor::serialize() const +{ + std::unique_ptr result = DictionaryValue::create(); + result->setValue("r", ValueConversions::serialize(m_r)); + result->setValue("g", ValueConversions::serialize(m_g)); + result->setValue("b", ValueConversions::serialize(m_b)); + if (m_a.isJust()) + result->setValue("a", ValueConversions::serialize(m_a.fromJust())); + return result; +} + +std::unique_ptr RGBAColor::clone() const +{ + ErrorSupport errors; + return parse(serialize().get(), &errors); +} + +std::unique_ptr HighlightConfig::parse(protocol::Value* value, ErrorSupport* errors) +{ + if (!value || value->type() != protocol::Value::TypeObject) { + errors->addError("object expected"); + return nullptr; + } + + std::unique_ptr result(new HighlightConfig()); + protocol::DictionaryValue* object = DictionaryValue::cast(value); + errors->push(); + protocol::Value* showInfoValue = object->get("showInfo"); + if (showInfoValue) { + errors->setName("showInfo"); + result->m_showInfo = ValueConversions::parse(showInfoValue, errors); + } + protocol::Value* contentColorValue = object->get("contentColor"); + if (contentColorValue) { + errors->setName("contentColor"); + result->m_contentColor = ValueConversions::parse(contentColorValue, errors); + } + protocol::Value* paddingColorValue = object->get("paddingColor"); + if (paddingColorValue) { + errors->setName("paddingColor"); + result->m_paddingColor = ValueConversions::parse(paddingColorValue, errors); + } + protocol::Value* borderColorValue = object->get("borderColor"); + if (borderColorValue) { + errors->setName("borderColor"); + result->m_borderColor = ValueConversions::parse(borderColorValue, errors); + } + protocol::Value* marginColorValue = object->get("marginColor"); + if (marginColorValue) { + errors->setName("marginColor"); + result->m_marginColor = ValueConversions::parse(marginColorValue, errors); + } + errors->pop(); + if (errors->hasErrors()) + return nullptr; + return result; +} + +std::unique_ptr HighlightConfig::serialize() const +{ + std::unique_ptr result = DictionaryValue::create(); + if (m_showInfo.isJust()) + result->setValue("showInfo", ValueConversions::serialize(m_showInfo.fromJust())); + if (m_contentColor.isJust()) + result->setValue("contentColor", ValueConversions::serialize(m_contentColor.fromJust())); + if (m_paddingColor.isJust()) + result->setValue("paddingColor", ValueConversions::serialize(m_paddingColor.fromJust())); + if (m_borderColor.isJust()) + result->setValue("borderColor", ValueConversions::serialize(m_borderColor.fromJust())); + if (m_marginColor.isJust()) + result->setValue("marginColor", ValueConversions::serialize(m_marginColor.fromJust())); + return result; +} + +std::unique_ptr HighlightConfig::clone() const +{ + ErrorSupport errors; + return parse(serialize().get(), &errors); +} + +// ------------- Enum values from params. + + +// ------------- Frontend notifications. + +void Frontend::documentUpdated() +{ + std::unique_ptr jsonMessage = DictionaryValue::create(); + jsonMessage->setString("method", "DOM.documentUpdated"); + std::unique_ptr paramsObject = DictionaryValue::create(); + jsonMessage->setObject("params", std::move(paramsObject)); + if (m_frontendChannel) + m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString()); +} + +void Frontend::setChildNodes(int parentId, std::unique_ptr> nodes) +{ + std::unique_ptr jsonMessage = DictionaryValue::create(); + jsonMessage->setString("method", "DOM.setChildNodes"); + std::unique_ptr paramsObject = DictionaryValue::create(); + paramsObject->setValue("parentId", ValueConversions::serialize(parentId)); + paramsObject->setValue("nodes", ValueConversions>::serialize(nodes.get())); + jsonMessage->setObject("params", std::move(paramsObject)); + if (m_frontendChannel) + m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString()); +} + +void Frontend::attributeModified(int nodeId, const String& name, const String& value) +{ + std::unique_ptr jsonMessage = DictionaryValue::create(); + jsonMessage->setString("method", "DOM.attributeModified"); + std::unique_ptr paramsObject = DictionaryValue::create(); + paramsObject->setValue("nodeId", ValueConversions::serialize(nodeId)); + paramsObject->setValue("name", ValueConversions::serialize(name)); + paramsObject->setValue("value", ValueConversions::serialize(value)); + jsonMessage->setObject("params", std::move(paramsObject)); + if (m_frontendChannel) + m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString()); +} + +void Frontend::attributeRemoved(int nodeId, const String& name) +{ + std::unique_ptr jsonMessage = DictionaryValue::create(); + jsonMessage->setString("method", "DOM.attributeRemoved"); + std::unique_ptr paramsObject = DictionaryValue::create(); + paramsObject->setValue("nodeId", ValueConversions::serialize(nodeId)); + paramsObject->setValue("name", ValueConversions::serialize(name)); + jsonMessage->setObject("params", std::move(paramsObject)); + if (m_frontendChannel) + m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString()); +} + +void Frontend::inlineStyleInvalidated(std::unique_ptr> nodeIds) +{ + std::unique_ptr jsonMessage = DictionaryValue::create(); + jsonMessage->setString("method", "DOM.inlineStyleInvalidated"); + std::unique_ptr paramsObject = DictionaryValue::create(); + paramsObject->setValue("nodeIds", ValueConversions>::serialize(nodeIds.get())); + jsonMessage->setObject("params", std::move(paramsObject)); + if (m_frontendChannel) + m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString()); +} + +void Frontend::characterDataModified(int nodeId, const String& characterData) +{ + std::unique_ptr jsonMessage = DictionaryValue::create(); + jsonMessage->setString("method", "DOM.characterDataModified"); + std::unique_ptr paramsObject = DictionaryValue::create(); + paramsObject->setValue("nodeId", ValueConversions::serialize(nodeId)); + paramsObject->setValue("characterData", ValueConversions::serialize(characterData)); + jsonMessage->setObject("params", std::move(paramsObject)); + if (m_frontendChannel) + m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString()); +} + +void Frontend::childNodeCountUpdated(int nodeId, int childNodeCount) +{ + std::unique_ptr jsonMessage = DictionaryValue::create(); + jsonMessage->setString("method", "DOM.childNodeCountUpdated"); + std::unique_ptr paramsObject = DictionaryValue::create(); + paramsObject->setValue("nodeId", ValueConversions::serialize(nodeId)); + paramsObject->setValue("childNodeCount", ValueConversions::serialize(childNodeCount)); + jsonMessage->setObject("params", std::move(paramsObject)); + if (m_frontendChannel) + m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString()); +} + +void Frontend::childNodeInserted(int parentNodeId, int previousNodeId, std::unique_ptr node) +{ + std::unique_ptr jsonMessage = DictionaryValue::create(); + jsonMessage->setString("method", "DOM.childNodeInserted"); + std::unique_ptr paramsObject = DictionaryValue::create(); + paramsObject->setValue("parentNodeId", ValueConversions::serialize(parentNodeId)); + paramsObject->setValue("previousNodeId", ValueConversions::serialize(previousNodeId)); + paramsObject->setValue("node", ValueConversions::serialize(node.get())); + jsonMessage->setObject("params", std::move(paramsObject)); + if (m_frontendChannel) + m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString()); +} + +void Frontend::childNodeRemoved(int parentNodeId, int nodeId) +{ + std::unique_ptr jsonMessage = DictionaryValue::create(); + jsonMessage->setString("method", "DOM.childNodeRemoved"); + std::unique_ptr paramsObject = DictionaryValue::create(); + paramsObject->setValue("parentNodeId", ValueConversions::serialize(parentNodeId)); + paramsObject->setValue("nodeId", ValueConversions::serialize(nodeId)); + jsonMessage->setObject("params", std::move(paramsObject)); + if (m_frontendChannel) + m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString()); +} + +void Frontend::shadowRootPushed(int hostId, std::unique_ptr root) +{ + std::unique_ptr jsonMessage = DictionaryValue::create(); + jsonMessage->setString("method", "DOM.shadowRootPushed"); + std::unique_ptr paramsObject = DictionaryValue::create(); + paramsObject->setValue("hostId", ValueConversions::serialize(hostId)); + paramsObject->setValue("root", ValueConversions::serialize(root.get())); + jsonMessage->setObject("params", std::move(paramsObject)); + if (m_frontendChannel) + m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString()); +} + +void Frontend::shadowRootPopped(int hostId, int rootId) +{ + std::unique_ptr jsonMessage = DictionaryValue::create(); + jsonMessage->setString("method", "DOM.shadowRootPopped"); + std::unique_ptr paramsObject = DictionaryValue::create(); + paramsObject->setValue("hostId", ValueConversions::serialize(hostId)); + paramsObject->setValue("rootId", ValueConversions::serialize(rootId)); + jsonMessage->setObject("params", std::move(paramsObject)); + if (m_frontendChannel) + m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString()); +} + +void Frontend::pseudoElementAdded(int parentId, std::unique_ptr pseudoElement) +{ + std::unique_ptr jsonMessage = DictionaryValue::create(); + jsonMessage->setString("method", "DOM.pseudoElementAdded"); + std::unique_ptr paramsObject = DictionaryValue::create(); + paramsObject->setValue("parentId", ValueConversions::serialize(parentId)); + paramsObject->setValue("pseudoElement", ValueConversions::serialize(pseudoElement.get())); + jsonMessage->setObject("params", std::move(paramsObject)); + if (m_frontendChannel) + m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString()); +} + +void Frontend::pseudoElementRemoved(int parentId, int pseudoElementId) +{ + std::unique_ptr jsonMessage = DictionaryValue::create(); + jsonMessage->setString("method", "DOM.pseudoElementRemoved"); + std::unique_ptr paramsObject = DictionaryValue::create(); + paramsObject->setValue("parentId", ValueConversions::serialize(parentId)); + paramsObject->setValue("pseudoElementId", ValueConversions::serialize(pseudoElementId)); + jsonMessage->setObject("params", std::move(paramsObject)); + if (m_frontendChannel) + m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString()); +} + +void Frontend::flush() +{ + m_frontendChannel->flushProtocolNotifications(); +} + +// --------------------- Dispatcher. + +class DispatcherImpl : public protocol::DispatcherBase { +public: + DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend) + : DispatcherBase(frontendChannel) + , m_backend(backend) { + m_dispatchMap["DOM.enable"] = &DispatcherImpl::enable; + m_dispatchMap["DOM.disable"] = &DispatcherImpl::disable; + m_dispatchMap["DOM.getDocument"] = &DispatcherImpl::getDocument; + m_dispatchMap["DOM.removeNode"] = &DispatcherImpl::removeNode; + m_dispatchMap["DOM.setAttributeValue"] = &DispatcherImpl::setAttributeValue; + m_dispatchMap["DOM.setAttributesAsText"] = &DispatcherImpl::setAttributesAsText; + m_dispatchMap["DOM.removeAttribute"] = &DispatcherImpl::removeAttribute; + m_dispatchMap["DOM.performSearch"] = &DispatcherImpl::performSearch; + m_dispatchMap["DOM.getSearchResults"] = &DispatcherImpl::getSearchResults; + m_dispatchMap["DOM.discardSearchResults"] = &DispatcherImpl::discardSearchResults; + m_dispatchMap["DOM.highlightNode"] = &DispatcherImpl::highlightNode; + m_dispatchMap["DOM.hideHighlight"] = &DispatcherImpl::hideHighlight; + m_dispatchMap["DOM.resolveNode"] = &DispatcherImpl::resolveNode; + } + ~DispatcherImpl() override { } + void dispatch(int callId, const String& method, std::unique_ptr messageObject) override; + +protected: + using CallHandler = void (DispatcherImpl::*)(int callId, std::unique_ptr messageObject, ErrorSupport* errors); + using DispatchMap = protocol::HashMap; + DispatchMap m_dispatchMap; + + void enable(int callId, std::unique_ptr requestMessageObject, ErrorSupport*); + void disable(int callId, std::unique_ptr requestMessageObject, ErrorSupport*); + void getDocument(int callId, std::unique_ptr requestMessageObject, ErrorSupport*); + void removeNode(int callId, std::unique_ptr requestMessageObject, ErrorSupport*); + void setAttributeValue(int callId, std::unique_ptr requestMessageObject, ErrorSupport*); + void setAttributesAsText(int callId, std::unique_ptr requestMessageObject, ErrorSupport*); + void removeAttribute(int callId, std::unique_ptr requestMessageObject, ErrorSupport*); + void performSearch(int callId, std::unique_ptr requestMessageObject, ErrorSupport*); + void getSearchResults(int callId, std::unique_ptr requestMessageObject, ErrorSupport*); + void discardSearchResults(int callId, std::unique_ptr requestMessageObject, ErrorSupport*); + void highlightNode(int callId, std::unique_ptr requestMessageObject, ErrorSupport*); + void hideHighlight(int callId, std::unique_ptr requestMessageObject, ErrorSupport*); + void resolveNode(int callId, std::unique_ptr requestMessageObject, ErrorSupport*); + + Backend* m_backend; +}; + +void DispatcherImpl::dispatch(int callId, const String& method, std::unique_ptr messageObject) +{ + protocol::HashMap::iterator it = m_dispatchMap.find(method); + if (it == m_dispatchMap.end()) { + reportProtocolError(callId, MethodNotFound, "'" + method + "' wasn't found", nullptr); + return; + } + + protocol::ErrorSupport errors; + (this->*(it->second))(callId, std::move(messageObject), &errors); +} + + +void DispatcherImpl::enable(int callId, std::unique_ptr requestMessageObject, ErrorSupport* errors) +{ + + std::unique_ptr weak = weakPtr(); + ErrorString error; + m_backend->enable(&error); + if (weak->get()) + weak->get()->sendResponse(callId, error); +} + +void DispatcherImpl::disable(int callId, std::unique_ptr requestMessageObject, ErrorSupport* errors) +{ + + std::unique_ptr weak = weakPtr(); + ErrorString error; + m_backend->disable(&error); + if (weak->get()) + weak->get()->sendResponse(callId, error); +} + +void DispatcherImpl::getDocument(int callId, std::unique_ptr requestMessageObject, ErrorSupport* errors) +{ + // Declare output parameters. + std::unique_ptr result = DictionaryValue::create(); + std::unique_ptr out_root; + + std::unique_ptr weak = weakPtr(); + ErrorString error; + m_backend->getDocument(&error, &out_root); + if (!error.length()) { + result->setValue("root", ValueConversions::serialize(out_root.get())); + } + if (weak->get()) + weak->get()->sendResponse(callId, error, std::move(result)); +} + +void DispatcherImpl::removeNode(int callId, std::unique_ptr requestMessageObject, ErrorSupport* errors) +{ + // Prepare input parameters. + protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params")); + errors->push(); + protocol::Value* nodeIdValue = object ? object->get("nodeId") : nullptr; + errors->setName("nodeId"); + int in_nodeId = ValueConversions::parse(nodeIdValue, errors); + errors->pop(); + if (errors->hasErrors()) { + reportProtocolError(callId, InvalidParams, kInvalidRequest, errors); + return; + } + + std::unique_ptr weak = weakPtr(); + ErrorString error; + m_backend->removeNode(&error, in_nodeId); + if (weak->get()) + weak->get()->sendResponse(callId, error); +} + +void DispatcherImpl::setAttributeValue(int callId, std::unique_ptr requestMessageObject, ErrorSupport* errors) +{ + // Prepare input parameters. + protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params")); + errors->push(); + protocol::Value* nodeIdValue = object ? object->get("nodeId") : nullptr; + errors->setName("nodeId"); + int in_nodeId = ValueConversions::parse(nodeIdValue, errors); + protocol::Value* nameValue = object ? object->get("name") : nullptr; + errors->setName("name"); + String in_name = ValueConversions::parse(nameValue, errors); + protocol::Value* valueValue = object ? object->get("value") : nullptr; + errors->setName("value"); + String in_value = ValueConversions::parse(valueValue, errors); + errors->pop(); + if (errors->hasErrors()) { + reportProtocolError(callId, InvalidParams, kInvalidRequest, errors); + return; + } + + std::unique_ptr weak = weakPtr(); + ErrorString error; + m_backend->setAttributeValue(&error, in_nodeId, in_name, in_value); + if (weak->get()) + weak->get()->sendResponse(callId, error); +} + +void DispatcherImpl::setAttributesAsText(int callId, std::unique_ptr requestMessageObject, ErrorSupport* errors) +{ + // Prepare input parameters. + protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params")); + errors->push(); + protocol::Value* nodeIdValue = object ? object->get("nodeId") : nullptr; + errors->setName("nodeId"); + int in_nodeId = ValueConversions::parse(nodeIdValue, errors); + protocol::Value* textValue = object ? object->get("text") : nullptr; + errors->setName("text"); + String in_text = ValueConversions::parse(textValue, errors); + protocol::Value* nameValue = object ? object->get("name") : nullptr; + Maybe in_name; + if (nameValue) { + errors->setName("name"); + in_name = ValueConversions::parse(nameValue, errors); + } + errors->pop(); + if (errors->hasErrors()) { + reportProtocolError(callId, InvalidParams, kInvalidRequest, errors); + return; + } + + std::unique_ptr weak = weakPtr(); + ErrorString error; + m_backend->setAttributesAsText(&error, in_nodeId, in_text, in_name); + if (weak->get()) + weak->get()->sendResponse(callId, error); +} + +void DispatcherImpl::removeAttribute(int callId, std::unique_ptr requestMessageObject, ErrorSupport* errors) +{ + // Prepare input parameters. + protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params")); + errors->push(); + protocol::Value* nodeIdValue = object ? object->get("nodeId") : nullptr; + errors->setName("nodeId"); + int in_nodeId = ValueConversions::parse(nodeIdValue, errors); + protocol::Value* nameValue = object ? object->get("name") : nullptr; + errors->setName("name"); + String in_name = ValueConversions::parse(nameValue, errors); + errors->pop(); + if (errors->hasErrors()) { + reportProtocolError(callId, InvalidParams, kInvalidRequest, errors); + return; + } + + std::unique_ptr weak = weakPtr(); + ErrorString error; + m_backend->removeAttribute(&error, in_nodeId, in_name); + if (weak->get()) + weak->get()->sendResponse(callId, error); +} + +void DispatcherImpl::performSearch(int callId, std::unique_ptr requestMessageObject, ErrorSupport* errors) +{ + // Prepare input parameters. + protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params")); + errors->push(); + protocol::Value* queryValue = object ? object->get("query") : nullptr; + errors->setName("query"); + String in_query = ValueConversions::parse(queryValue, errors); + protocol::Value* nodeIdsValue = object ? object->get("nodeIds") : nullptr; + Maybe> in_nodeIds; + if (nodeIdsValue) { + errors->setName("nodeIds"); + in_nodeIds = ValueConversions>::parse(nodeIdsValue, errors); + } + errors->pop(); + if (errors->hasErrors()) { + reportProtocolError(callId, InvalidParams, kInvalidRequest, errors); + return; + } + // Declare output parameters. + std::unique_ptr result = DictionaryValue::create(); + String out_searchId; + int out_resultCount; + + std::unique_ptr weak = weakPtr(); + ErrorString error; + m_backend->performSearch(&error, in_query, in_nodeIds, &out_searchId, &out_resultCount); + if (!error.length()) { + result->setValue("searchId", ValueConversions::serialize(out_searchId)); + result->setValue("resultCount", ValueConversions::serialize(out_resultCount)); + } + if (weak->get()) + weak->get()->sendResponse(callId, error, std::move(result)); +} + +void DispatcherImpl::getSearchResults(int callId, std::unique_ptr requestMessageObject, ErrorSupport* errors) +{ + // Prepare input parameters. + protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params")); + errors->push(); + protocol::Value* searchIdValue = object ? object->get("searchId") : nullptr; + errors->setName("searchId"); + String in_searchId = ValueConversions::parse(searchIdValue, errors); + protocol::Value* fromIndexValue = object ? object->get("fromIndex") : nullptr; + errors->setName("fromIndex"); + int in_fromIndex = ValueConversions::parse(fromIndexValue, errors); + protocol::Value* toIndexValue = object ? object->get("toIndex") : nullptr; + errors->setName("toIndex"); + int in_toIndex = ValueConversions::parse(toIndexValue, errors); + errors->pop(); + if (errors->hasErrors()) { + reportProtocolError(callId, InvalidParams, kInvalidRequest, errors); + return; + } + // Declare output parameters. + std::unique_ptr result = DictionaryValue::create(); + std::unique_ptr> out_nodeIds; + + std::unique_ptr weak = weakPtr(); + ErrorString error; + m_backend->getSearchResults(&error, in_searchId, in_fromIndex, in_toIndex, &out_nodeIds); + if (!error.length()) { + result->setValue("nodeIds", ValueConversions>::serialize(out_nodeIds.get())); + } + if (weak->get()) + weak->get()->sendResponse(callId, error, std::move(result)); +} + +void DispatcherImpl::discardSearchResults(int callId, std::unique_ptr requestMessageObject, ErrorSupport* errors) +{ + // Prepare input parameters. + protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params")); + errors->push(); + protocol::Value* searchIdValue = object ? object->get("searchId") : nullptr; + errors->setName("searchId"); + String in_searchId = ValueConversions::parse(searchIdValue, errors); + errors->pop(); + if (errors->hasErrors()) { + reportProtocolError(callId, InvalidParams, kInvalidRequest, errors); + return; + } + + std::unique_ptr weak = weakPtr(); + ErrorString error; + m_backend->discardSearchResults(&error, in_searchId); + if (weak->get()) + weak->get()->sendResponse(callId, error); +} + +void DispatcherImpl::highlightNode(int callId, std::unique_ptr requestMessageObject, ErrorSupport* errors) +{ + // Prepare input parameters. + protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params")); + errors->push(); + protocol::Value* highlightConfigValue = object ? object->get("highlightConfig") : nullptr; + errors->setName("highlightConfig"); + std::unique_ptr in_highlightConfig = ValueConversions::parse(highlightConfigValue, errors); + protocol::Value* nodeIdValue = object ? object->get("nodeId") : nullptr; + Maybe in_nodeId; + if (nodeIdValue) { + errors->setName("nodeId"); + in_nodeId = ValueConversions::parse(nodeIdValue, errors); + } + protocol::Value* objectIdValue = object ? object->get("objectId") : nullptr; + Maybe in_objectId; + if (objectIdValue) { + errors->setName("objectId"); + in_objectId = ValueConversions::parse(objectIdValue, errors); + } + errors->pop(); + if (errors->hasErrors()) { + reportProtocolError(callId, InvalidParams, kInvalidRequest, errors); + return; + } + + std::unique_ptr weak = weakPtr(); + ErrorString error; + m_backend->highlightNode(&error, std::move(in_highlightConfig), in_nodeId, in_objectId); + if (weak->get()) + weak->get()->sendResponse(callId, error); +} + +void DispatcherImpl::hideHighlight(int callId, std::unique_ptr requestMessageObject, ErrorSupport* errors) +{ + + std::unique_ptr weak = weakPtr(); + ErrorString error; + m_backend->hideHighlight(&error); + if (weak->get()) + weak->get()->sendResponse(callId, error); +} + +void DispatcherImpl::resolveNode(int callId, std::unique_ptr requestMessageObject, ErrorSupport* errors) +{ + // Prepare input parameters. + protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params")); + errors->push(); + protocol::Value* nodeIdValue = object ? object->get("nodeId") : nullptr; + errors->setName("nodeId"); + int in_nodeId = ValueConversions::parse(nodeIdValue, errors); + protocol::Value* objectGroupValue = object ? object->get("objectGroup") : nullptr; + Maybe in_objectGroup; + if (objectGroupValue) { + errors->setName("objectGroup"); + in_objectGroup = ValueConversions::parse(objectGroupValue, errors); + } + errors->pop(); + if (errors->hasErrors()) { + reportProtocolError(callId, InvalidParams, kInvalidRequest, errors); + return; + } + // Declare output parameters. + std::unique_ptr result = DictionaryValue::create(); + std::unique_ptr out_object; + + std::unique_ptr weak = weakPtr(); + ErrorString error; + m_backend->resolveNode(&error, in_nodeId, in_objectGroup, &out_object); + if (!error.length()) { + result->setValue("object", ValueConversions::serialize(out_object.get())); + } + if (weak->get()) + weak->get()->sendResponse(callId, error, std::move(result)); +} + +// static +void Dispatcher::wire(UberDispatcher* dispatcher, Backend* backend) +{ + dispatcher->registerBackend("DOM", wrapUnique(new DispatcherImpl(dispatcher->channel(), backend))); +} + +} // DOM +} // namespace v8_inspector +} // namespace protocol diff --git a/runtime/src/main/jni/v8_inspector/src/inspector/protocol/DOM.h b/runtime/src/main/jni/v8_inspector/src/inspector/protocol/DOM.h new file mode 100644 index 000000000..278be0096 --- /dev/null +++ b/runtime/src/main/jni/v8_inspector/src/inspector/protocol/DOM.h @@ -0,0 +1,654 @@ +// This file is generated + +// Copyright (c) 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef v8_inspector_protocol_DOM_h +#define v8_inspector_protocol_DOM_h + +#include "src/inspector/protocol/Protocol.h" +#include "Runtime.h" +// For each imported domain we generate a ValueConversions struct instead of a full domain definition +// and include Domain::API version from there. + +namespace v8_inspector { +namespace protocol { +namespace DOM { + +// ------------- Forward and enum declarations. +// Unique DOM node identifier. +using NodeId = int; +// Unique DOM node identifier used to reference a node that may not have been pushed to the front-end. +using BackendNodeId = int; +// Pseudo element type. +using PseudoType = String; +// Shadow root type. +using ShadowRootType = String; +// Token values of @aria-relevant attribute. +using LiveRegionRelevant = String; +// DOM interaction is implemented in terms of mirror objects that represent the actual DOM nodes. DOMNode is a base node mirror type. +class Node; +// A structure holding an RGBA color. +class RGBAColor; +// Configuration data for the highlighting of page elements. +class HighlightConfig; + +namespace PseudoTypeEnum { + extern const char* Before; + extern const char* After; +} // namespace PseudoTypeEnum + +namespace ShadowRootTypeEnum { + extern const char* UserAgent; + extern const char* Open; + extern const char* Closed; +} // namespace ShadowRootTypeEnum + +namespace LiveRegionRelevantEnum { + extern const char* Additions; + extern const char* Removals; + extern const char* Text; +} // namespace LiveRegionRelevantEnum + +// ------------- Type and builder declarations. + +// DOM interaction is implemented in terms of mirror objects that represent the actual DOM nodes. DOMNode is a base node mirror type. +class Node { + PROTOCOL_DISALLOW_COPY(Node); +public: + static std::unique_ptr parse(protocol::Value* value, ErrorSupport* errors); + + ~Node() { } + + int getNodeId() { return m_nodeId; } + void setNodeId(int value) { m_nodeId = value; } + + int getNodeType() { return m_nodeType; } + void setNodeType(int value) { m_nodeType = value; } + + String getNodeName() { return m_nodeName; } + void setNodeName(const String& value) { m_nodeName = value; } + + String getLocalName() { return m_localName; } + void setLocalName(const String& value) { m_localName = value; } + + String getNodeValue() { return m_nodeValue; } + void setNodeValue(const String& value) { m_nodeValue = value; } + + bool hasChildNodeCount() { return m_childNodeCount.isJust(); } + int getChildNodeCount(int defaultValue) { return m_childNodeCount.isJust() ? m_childNodeCount.fromJust() : defaultValue; } + void setChildNodeCount(int value) { m_childNodeCount = value; } + + bool hasChildren() { return m_children.isJust(); } + protocol::Array* getChildren(protocol::Array* defaultValue) { return m_children.isJust() ? m_children.fromJust() : defaultValue; } + void setChildren(std::unique_ptr> value) { m_children = std::move(value); } + + bool hasAttributes() { return m_attributes.isJust(); } + protocol::Array* getAttributes(protocol::Array* defaultValue) { return m_attributes.isJust() ? m_attributes.fromJust() : defaultValue; } + void setAttributes(std::unique_ptr> value) { m_attributes = std::move(value); } + + bool hasDocumentURL() { return m_documentURL.isJust(); } + String getDocumentURL(const String& defaultValue) { return m_documentURL.isJust() ? m_documentURL.fromJust() : defaultValue; } + void setDocumentURL(const String& value) { m_documentURL = value; } + + bool hasBaseURL() { return m_baseURL.isJust(); } + String getBaseURL(const String& defaultValue) { return m_baseURL.isJust() ? m_baseURL.fromJust() : defaultValue; } + void setBaseURL(const String& value) { m_baseURL = value; } + + bool hasPublicId() { return m_publicId.isJust(); } + String getPublicId(const String& defaultValue) { return m_publicId.isJust() ? m_publicId.fromJust() : defaultValue; } + void setPublicId(const String& value) { m_publicId = value; } + + bool hasSystemId() { return m_systemId.isJust(); } + String getSystemId(const String& defaultValue) { return m_systemId.isJust() ? m_systemId.fromJust() : defaultValue; } + void setSystemId(const String& value) { m_systemId = value; } + + bool hasXmlVersion() { return m_xmlVersion.isJust(); } + String getXmlVersion(const String& defaultValue) { return m_xmlVersion.isJust() ? m_xmlVersion.fromJust() : defaultValue; } + void setXmlVersion(const String& value) { m_xmlVersion = value; } + + bool hasName() { return m_name.isJust(); } + String getName(const String& defaultValue) { return m_name.isJust() ? m_name.fromJust() : defaultValue; } + void setName(const String& value) { m_name = value; } + + bool hasValue() { return m_value.isJust(); } + String getValue(const String& defaultValue) { return m_value.isJust() ? m_value.fromJust() : defaultValue; } + void setValue(const String& value) { m_value = value; } + + bool hasPseudoType() { return m_pseudoType.isJust(); } + String getPseudoType(const String& defaultValue) { return m_pseudoType.isJust() ? m_pseudoType.fromJust() : defaultValue; } + void setPseudoType(const String& value) { m_pseudoType = value; } + + bool hasShadowRootType() { return m_shadowRootType.isJust(); } + String getShadowRootType(const String& defaultValue) { return m_shadowRootType.isJust() ? m_shadowRootType.fromJust() : defaultValue; } + void setShadowRootType(const String& value) { m_shadowRootType = value; } + + bool hasFrameId() { return m_frameId.isJust(); } + String getFrameId(const String& defaultValue) { return m_frameId.isJust() ? m_frameId.fromJust() : defaultValue; } + void setFrameId(const String& value) { m_frameId = value; } + + bool hasContentDocument() { return m_contentDocument.isJust(); } + protocol::DOM::Node* getContentDocument(protocol::DOM::Node* defaultValue) { return m_contentDocument.isJust() ? m_contentDocument.fromJust() : defaultValue; } + void setContentDocument(std::unique_ptr value) { m_contentDocument = std::move(value); } + + bool hasShadowRoots() { return m_shadowRoots.isJust(); } + protocol::Array* getShadowRoots(protocol::Array* defaultValue) { return m_shadowRoots.isJust() ? m_shadowRoots.fromJust() : defaultValue; } + void setShadowRoots(std::unique_ptr> value) { m_shadowRoots = std::move(value); } + + bool hasTemplateContent() { return m_templateContent.isJust(); } + protocol::DOM::Node* getTemplateContent(protocol::DOM::Node* defaultValue) { return m_templateContent.isJust() ? m_templateContent.fromJust() : defaultValue; } + void setTemplateContent(std::unique_ptr value) { m_templateContent = std::move(value); } + + bool hasPseudoElements() { return m_pseudoElements.isJust(); } + protocol::Array* getPseudoElements(protocol::Array* defaultValue) { return m_pseudoElements.isJust() ? m_pseudoElements.fromJust() : defaultValue; } + void setPseudoElements(std::unique_ptr> value) { m_pseudoElements = std::move(value); } + + bool hasRole() { return m_role.isJust(); } + String getRole(const String& defaultValue) { return m_role.isJust() ? m_role.fromJust() : defaultValue; } + void setRole(const String& value) { m_role = value; } + + bool hasContentSecurityPolicyHash() { return m_contentSecurityPolicyHash.isJust(); } + String getContentSecurityPolicyHash(const String& defaultValue) { return m_contentSecurityPolicyHash.isJust() ? m_contentSecurityPolicyHash.fromJust() : defaultValue; } + void setContentSecurityPolicyHash(const String& value) { m_contentSecurityPolicyHash = value; } + + std::unique_ptr serialize() const; + std::unique_ptr clone() const; + + template + class NodeBuilder { + public: + enum { + NoFieldsSet = 0, + NodeIdSet = 1 << 1, + NodeTypeSet = 1 << 2, + NodeNameSet = 1 << 3, + LocalNameSet = 1 << 4, + NodeValueSet = 1 << 5, + AllFieldsSet = (NodeIdSet | NodeTypeSet | NodeNameSet | LocalNameSet | NodeValueSet | 0)}; + + + NodeBuilder& setNodeId(int value) + { + static_assert(!(STATE & NodeIdSet), "property nodeId should not be set yet"); + m_result->setNodeId(value); + return castState(); + } + + NodeBuilder& setNodeType(int value) + { + static_assert(!(STATE & NodeTypeSet), "property nodeType should not be set yet"); + m_result->setNodeType(value); + return castState(); + } + + NodeBuilder& setNodeName(const String& value) + { + static_assert(!(STATE & NodeNameSet), "property nodeName should not be set yet"); + m_result->setNodeName(value); + return castState(); + } + + NodeBuilder& setLocalName(const String& value) + { + static_assert(!(STATE & LocalNameSet), "property localName should not be set yet"); + m_result->setLocalName(value); + return castState(); + } + + NodeBuilder& setNodeValue(const String& value) + { + static_assert(!(STATE & NodeValueSet), "property nodeValue should not be set yet"); + m_result->setNodeValue(value); + return castState(); + } + + NodeBuilder& setChildNodeCount(int value) + { + m_result->setChildNodeCount(value); + return *this; + } + + NodeBuilder& setChildren(std::unique_ptr> value) + { + m_result->setChildren(std::move(value)); + return *this; + } + + NodeBuilder& setAttributes(std::unique_ptr> value) + { + m_result->setAttributes(std::move(value)); + return *this; + } + + NodeBuilder& setDocumentURL(const String& value) + { + m_result->setDocumentURL(value); + return *this; + } + + NodeBuilder& setBaseURL(const String& value) + { + m_result->setBaseURL(value); + return *this; + } + + NodeBuilder& setPublicId(const String& value) + { + m_result->setPublicId(value); + return *this; + } + + NodeBuilder& setSystemId(const String& value) + { + m_result->setSystemId(value); + return *this; + } + + NodeBuilder& setXmlVersion(const String& value) + { + m_result->setXmlVersion(value); + return *this; + } + + NodeBuilder& setName(const String& value) + { + m_result->setName(value); + return *this; + } + + NodeBuilder& setValue(const String& value) + { + m_result->setValue(value); + return *this; + } + + NodeBuilder& setPseudoType(const String& value) + { + m_result->setPseudoType(value); + return *this; + } + + NodeBuilder& setShadowRootType(const String& value) + { + m_result->setShadowRootType(value); + return *this; + } + + NodeBuilder& setFrameId(const String& value) + { + m_result->setFrameId(value); + return *this; + } + + NodeBuilder& setContentDocument(std::unique_ptr value) + { + m_result->setContentDocument(std::move(value)); + return *this; + } + + NodeBuilder& setShadowRoots(std::unique_ptr> value) + { + m_result->setShadowRoots(std::move(value)); + return *this; + } + + NodeBuilder& setTemplateContent(std::unique_ptr value) + { + m_result->setTemplateContent(std::move(value)); + return *this; + } + + NodeBuilder& setPseudoElements(std::unique_ptr> value) + { + m_result->setPseudoElements(std::move(value)); + return *this; + } + + NodeBuilder& setRole(const String& value) + { + m_result->setRole(value); + return *this; + } + + NodeBuilder& setContentSecurityPolicyHash(const String& value) + { + m_result->setContentSecurityPolicyHash(value); + return *this; + } + + std::unique_ptr build() + { + static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet"); + return std::move(m_result); + } + + private: + friend class Node; + NodeBuilder() : m_result(new Node()) { } + + template NodeBuilder& castState() + { + return *reinterpret_cast*>(this); + } + + std::unique_ptr m_result; + }; + + static NodeBuilder<0> create() + { + return NodeBuilder<0>(); + } + +private: + Node() + { + m_nodeId = 0; + m_nodeType = 0; + } + + int m_nodeId; + int m_nodeType; + String m_nodeName; + String m_localName; + String m_nodeValue; + Maybe m_childNodeCount; + Maybe> m_children; + Maybe> m_attributes; + Maybe m_documentURL; + Maybe m_baseURL; + Maybe m_publicId; + Maybe m_systemId; + Maybe m_xmlVersion; + Maybe m_name; + Maybe m_value; + Maybe m_pseudoType; + Maybe m_shadowRootType; + Maybe m_frameId; + Maybe m_contentDocument; + Maybe> m_shadowRoots; + Maybe m_templateContent; + Maybe> m_pseudoElements; + Maybe m_role; + Maybe m_contentSecurityPolicyHash; +}; + + +// A structure holding an RGBA color. +class RGBAColor { + PROTOCOL_DISALLOW_COPY(RGBAColor); +public: + static std::unique_ptr parse(protocol::Value* value, ErrorSupport* errors); + + ~RGBAColor() { } + + int getR() { return m_r; } + void setR(int value) { m_r = value; } + + int getG() { return m_g; } + void setG(int value) { m_g = value; } + + int getB() { return m_b; } + void setB(int value) { m_b = value; } + + bool hasA() { return m_a.isJust(); } + double getA(double defaultValue) { return m_a.isJust() ? m_a.fromJust() : defaultValue; } + void setA(double value) { m_a = value; } + + std::unique_ptr serialize() const; + std::unique_ptr clone() const; + + template + class RGBAColorBuilder { + public: + enum { + NoFieldsSet = 0, + RSet = 1 << 1, + GSet = 1 << 2, + BSet = 1 << 3, + AllFieldsSet = (RSet | GSet | BSet | 0)}; + + + RGBAColorBuilder& setR(int value) + { + static_assert(!(STATE & RSet), "property r should not be set yet"); + m_result->setR(value); + return castState(); + } + + RGBAColorBuilder& setG(int value) + { + static_assert(!(STATE & GSet), "property g should not be set yet"); + m_result->setG(value); + return castState(); + } + + RGBAColorBuilder& setB(int value) + { + static_assert(!(STATE & BSet), "property b should not be set yet"); + m_result->setB(value); + return castState(); + } + + RGBAColorBuilder& setA(double value) + { + m_result->setA(value); + return *this; + } + + std::unique_ptr build() + { + static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet"); + return std::move(m_result); + } + + private: + friend class RGBAColor; + RGBAColorBuilder() : m_result(new RGBAColor()) { } + + template RGBAColorBuilder& castState() + { + return *reinterpret_cast*>(this); + } + + std::unique_ptr m_result; + }; + + static RGBAColorBuilder<0> create() + { + return RGBAColorBuilder<0>(); + } + +private: + RGBAColor() + { + m_r = 0; + m_g = 0; + m_b = 0; + } + + int m_r; + int m_g; + int m_b; + Maybe m_a; +}; + + +// Configuration data for the highlighting of page elements. +class HighlightConfig { + PROTOCOL_DISALLOW_COPY(HighlightConfig); +public: + static std::unique_ptr parse(protocol::Value* value, ErrorSupport* errors); + + ~HighlightConfig() { } + + bool hasShowInfo() { return m_showInfo.isJust(); } + bool getShowInfo(bool defaultValue) { return m_showInfo.isJust() ? m_showInfo.fromJust() : defaultValue; } + void setShowInfo(bool value) { m_showInfo = value; } + + bool hasContentColor() { return m_contentColor.isJust(); } + protocol::DOM::RGBAColor* getContentColor(protocol::DOM::RGBAColor* defaultValue) { return m_contentColor.isJust() ? m_contentColor.fromJust() : defaultValue; } + void setContentColor(std::unique_ptr value) { m_contentColor = std::move(value); } + + bool hasPaddingColor() { return m_paddingColor.isJust(); } + protocol::DOM::RGBAColor* getPaddingColor(protocol::DOM::RGBAColor* defaultValue) { return m_paddingColor.isJust() ? m_paddingColor.fromJust() : defaultValue; } + void setPaddingColor(std::unique_ptr value) { m_paddingColor = std::move(value); } + + bool hasBorderColor() { return m_borderColor.isJust(); } + protocol::DOM::RGBAColor* getBorderColor(protocol::DOM::RGBAColor* defaultValue) { return m_borderColor.isJust() ? m_borderColor.fromJust() : defaultValue; } + void setBorderColor(std::unique_ptr value) { m_borderColor = std::move(value); } + + bool hasMarginColor() { return m_marginColor.isJust(); } + protocol::DOM::RGBAColor* getMarginColor(protocol::DOM::RGBAColor* defaultValue) { return m_marginColor.isJust() ? m_marginColor.fromJust() : defaultValue; } + void setMarginColor(std::unique_ptr value) { m_marginColor = std::move(value); } + + std::unique_ptr serialize() const; + std::unique_ptr clone() const; + + template + class HighlightConfigBuilder { + public: + enum { + NoFieldsSet = 0, + AllFieldsSet = (0)}; + + + HighlightConfigBuilder& setShowInfo(bool value) + { + m_result->setShowInfo(value); + return *this; + } + + HighlightConfigBuilder& setContentColor(std::unique_ptr value) + { + m_result->setContentColor(std::move(value)); + return *this; + } + + HighlightConfigBuilder& setPaddingColor(std::unique_ptr value) + { + m_result->setPaddingColor(std::move(value)); + return *this; + } + + HighlightConfigBuilder& setBorderColor(std::unique_ptr value) + { + m_result->setBorderColor(std::move(value)); + return *this; + } + + HighlightConfigBuilder& setMarginColor(std::unique_ptr value) + { + m_result->setMarginColor(std::move(value)); + return *this; + } + + std::unique_ptr build() + { + static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet"); + return std::move(m_result); + } + + private: + friend class HighlightConfig; + HighlightConfigBuilder() : m_result(new HighlightConfig()) { } + + template HighlightConfigBuilder& castState() + { + return *reinterpret_cast*>(this); + } + + std::unique_ptr m_result; + }; + + static HighlightConfigBuilder<0> create() + { + return HighlightConfigBuilder<0>(); + } + +private: + HighlightConfig() + { + } + + Maybe m_showInfo; + Maybe m_contentColor; + Maybe m_paddingColor; + Maybe m_borderColor; + Maybe m_marginColor; +}; + + +// ------------- Backend interface. + +class Backend { +public: + virtual ~Backend() { } + + virtual void enable(ErrorString*) = 0; + virtual void disable(ErrorString*) = 0; + virtual void getDocument(ErrorString*, std::unique_ptr* out_root) = 0; + virtual void removeNode(ErrorString*, int in_nodeId) = 0; + virtual void setAttributeValue(ErrorString*, int in_nodeId, const String& in_name, const String& in_value) = 0; + virtual void setAttributesAsText(ErrorString*, int in_nodeId, const String& in_text, const Maybe& in_name) = 0; + virtual void removeAttribute(ErrorString*, int in_nodeId, const String& in_name) = 0; + virtual void performSearch(ErrorString*, const String& in_query, const Maybe>& in_nodeIds, String* out_searchId, int* out_resultCount) = 0; + virtual void getSearchResults(ErrorString*, const String& in_searchId, int in_fromIndex, int in_toIndex, std::unique_ptr>* out_nodeIds) = 0; + virtual void discardSearchResults(ErrorString*, const String& in_searchId) = 0; + virtual void highlightNode(ErrorString*, std::unique_ptr in_highlightConfig, const Maybe& in_nodeId, const Maybe& in_objectId) = 0; + virtual void hideHighlight(ErrorString*) = 0; + virtual void resolveNode(ErrorString*, int in_nodeId, const Maybe& in_objectGroup, std::unique_ptr* out_object) = 0; + +}; + +// ------------- Frontend interface. + +class Frontend { +public: + Frontend(FrontendChannel* frontendChannel) : m_frontendChannel(frontendChannel) { } + void documentUpdated(); + void setChildNodes(int parentId, std::unique_ptr> nodes); + void attributeModified(int nodeId, const String& name, const String& value); + void attributeRemoved(int nodeId, const String& name); + void inlineStyleInvalidated(std::unique_ptr> nodeIds); + void characterDataModified(int nodeId, const String& characterData); + void childNodeCountUpdated(int nodeId, int childNodeCount); + void childNodeInserted(int parentNodeId, int previousNodeId, std::unique_ptr node); + void childNodeRemoved(int parentNodeId, int nodeId); + void shadowRootPushed(int hostId, std::unique_ptr root); + void shadowRootPopped(int hostId, int rootId); + void pseudoElementAdded(int parentId, std::unique_ptr pseudoElement); + void pseudoElementRemoved(int parentId, int pseudoElementId); + + void flush(); +private: + FrontendChannel* m_frontendChannel; +}; + +// ------------- Dispatcher. + +class Dispatcher { +public: + static void wire(UberDispatcher*, Backend*); + +private: + Dispatcher() { } +}; + +// ------------- Metainfo. + +class Metainfo { +public: + using BackendClass = Backend; + using FrontendClass = Frontend; + using DispatcherClass = Dispatcher; + static const char domainName[]; + static const char commandPrefix[]; + static const char version[]; +}; + +} // namespace DOM +} // namespace v8_inspector +} // namespace protocol + +#endif // !defined(v8_inspector_protocol_DOM_h) diff --git a/runtime/src/main/jni/v8_inspector/src/inspector/utils/v8-inspector-common.cpp b/runtime/src/main/jni/v8_inspector/src/inspector/utils/v8-inspector-common.cpp new file mode 100644 index 000000000..7219f0ead --- /dev/null +++ b/runtime/src/main/jni/v8_inspector/src/inspector/utils/v8-inspector-common.cpp @@ -0,0 +1,38 @@ +// +// Created by pkanev on 6/5/2017. +// + +#include +#include +#include + +using tns::ArgConverter; + +namespace v8_inspector { + namespace utils { + v8::Local Common::getGlobalInspectorObject(v8::Isolate *isolate) { + auto context = isolate->GetCurrentContext(); + auto global = context->Global(); + + auto inspectorObjectString = "__inspector"; + + v8::Local outInspector; + + auto maybeInspectorObj = global->Get(context, ArgConverter::ConvertToV8String(isolate, inspectorObjectString)); + + if (maybeInspectorObj.ToLocal(&outInspector)) { + return outInspector->ToObject(); + } + + return v8::Local(); + } + + std::string Common::getJSCallErrorMessage(const std::string &functionName, v8::Local tcMessage) { + auto errorMessage = "Error thrown while calling " + functionName + ": " + ArgConverter::ConvertToString(tcMessage); + + DEBUG_WRITE_FORCE("JS Error: %s", errorMessage.c_str()); + + return errorMessage; + } + } +} diff --git a/runtime/src/main/jni/v8_inspector/src/inspector/utils/v8-inspector-common.h b/runtime/src/main/jni/v8_inspector/src/inspector/utils/v8-inspector-common.h new file mode 100644 index 000000000..b1a56151c --- /dev/null +++ b/runtime/src/main/jni/v8_inspector/src/inspector/utils/v8-inspector-common.h @@ -0,0 +1,20 @@ +// +// Created by pkanev on 6/5/2017. +// + +#ifndef V8_INSPECTOR_COMMON_H +#define V8_INSPECTOR_COMMON_H + +#include + +namespace v8_inspector { + namespace utils { + class Common { + public: + static v8::Local getGlobalInspectorObject(v8::Isolate *isolate); + static std::string getJSCallErrorMessage(const std::string& functionName, v8::Local tcMessage); + }; + } + } + +#endif //V8_INSPECTOR_COMMON_H diff --git a/runtime/src/main/jni/v8_inspector/src/inspector/v8-css-agent-impl.cpp b/runtime/src/main/jni/v8_inspector/src/inspector/v8-css-agent-impl.cpp new file mode 100644 index 000000000..9e3bbba0a --- /dev/null +++ b/runtime/src/main/jni/v8_inspector/src/inspector/v8-css-agent-impl.cpp @@ -0,0 +1,219 @@ +// +// Created by pkanev on 5/11/2017. +// + +#include +#include +#include +#include "v8-css-agent-impl.h" + +namespace v8_inspector { + + using tns::ArgConverter; + + namespace CSSAgentState { + static const char cssEnabled[] = "cssEnabled"; + } + + V8CSSAgentImpl::V8CSSAgentImpl(V8InspectorSessionImpl *session, + protocol::FrontendChannel *frontendChannel, + protocol::DictionaryValue *state) + : m_session(session), + m_frontend(frontendChannel), + m_state(state), + m_enabled(false) { + Instance = this; + } + + V8CSSAgentImpl::~V8CSSAgentImpl() { } + + void V8CSSAgentImpl::enable(std::unique_ptr callback) { + if (m_enabled) { + callback->sendFailure("CSS Agent already enabled!"); + return; + } + + m_state->setBoolean(CSSAgentState::cssEnabled, true); + m_enabled = true; + callback->sendSuccess(); + } + + void V8CSSAgentImpl::disable(ErrorString *) { + if (!m_enabled) { + return; + } + + m_state->setBoolean(CSSAgentState::cssEnabled, false); + + m_enabled = false; + } + + // Not supported + void V8CSSAgentImpl::getMatchedStylesForNode(ErrorString *errorString, int in_nodeId, + Maybe *out_inlineStyle, + Maybe *out_attributesStyle, + Maybe> *out_matchedCSSRules, + Maybe> *out_pseudoElements, + Maybe> *out_inherited, + Maybe> *out_cssKeyframesRules) { + + //// out_inlineStyle + auto cssPropsArr = protocol::Array::create(); + auto shorthandPropArr = protocol::Array::create(); + auto inlineStyle = protocol::CSS::CSSStyle::create() + .setCssProperties(std::move(cssPropsArr)) + .setShorthandEntries(std::move(shorthandPropArr)) + .build(); + + //// out_attributesStyle + auto attrArr = protocol::Array::create(); + auto attributeStyle = protocol::CSS::CSSStyle::create() + .setCssProperties(std::move(attrArr)) + .setShorthandEntries(std::move(protocol::Array::create())) + .build(); + + //// out_matchedCSSRules + auto cssSelectorsArr = protocol::Array::create(); + auto cssSelectorList = protocol::CSS::SelectorList::create() + .setSelectors(std::move(cssSelectorsArr)) + .setText("") + .build(); + + auto cssRule = protocol::CSS::CSSRule::create() + .setSelectorList(std::move(cssSelectorList)) + .setOrigin(protocol::CSS::StyleSheetOriginEnum::Regular) + .setStyle(std::move(protocol::CSS::CSSStyle::create() + .setCssProperties(std::move(protocol::Array::create())) + .setShorthandEntries(std::move(protocol::Array::create())) + .build())) + .build(); + + auto rulesMatchedArr = protocol::Array::create(); + + //// out_pseudoElements + auto pseudoElementsArr = protocol::Array::create(); + + //// out_inherited + auto inheritedElementsArr = protocol::Array::create(); + auto inheritedelem = protocol::CSS::InheritedStyleEntry::create() + .setInlineStyle(std::move(protocol::CSS::CSSStyle::create() + .setCssProperties(std::move(protocol::Array::create())) + .setShorthandEntries(std::move(protocol::Array::create())) + .build())) + .setMatchedCSSRules(std::move(protocol::Array::create())) + .build(); + inheritedElementsArr->addItem(std::move(inheritedelem)); + + //// out_cssKeyframesRules + auto cssKeyFramesRulesArr = protocol::Array::create(); + + *out_inlineStyle = Maybe(std::move(inlineStyle)); + *out_attributesStyle = Maybe(std::move(attributeStyle)); + *out_matchedCSSRules = Maybe>(std::move(rulesMatchedArr)); + *out_cssKeyframesRules = Maybe>(std::move(cssKeyFramesRulesArr)); + *out_inherited = Maybe>(std::move(inheritedElementsArr)); + *out_pseudoElements = Maybe>(std::move(pseudoElementsArr)); + } + + // Not supported + void V8CSSAgentImpl::getInlineStylesForNode(ErrorString *, int in_nodeId, + Maybe *out_inlineStyle, + Maybe *out_attributesStyle) { + + //// out_inlineStyle + auto cssPropsArr = protocol::Array::create(); + auto shorthandPropArr = protocol::Array::create(); + + auto inlineStyle = protocol::CSS::CSSStyle::create() + .setCssProperties(std::move(cssPropsArr)) + .setShorthandEntries(std::move(shorthandPropArr)) + .build(); + + //// out_attributesStyle + auto attrArr = protocol::Array::create(); + auto attributeStyle = protocol::CSS::CSSStyle::create() + .setCssProperties(std::move(attrArr)) + .setShorthandEntries(std::move(protocol::Array::create())) + .build(); + + *out_inlineStyle = Maybe(std::move(inlineStyle)); + *out_attributesStyle = Maybe(std::move(attributeStyle)); + } + + void V8CSSAgentImpl::getComputedStyleForNode(ErrorString *errorString, int in_nodeId, + std::unique_ptr> *out_computedStyle) { + auto computedStylePropertyArr = protocol::Array::create(); + + std::string getComputedStylesForNodeString = "getComputedStylesForNode"; + // TODO: Pete: Find a better way to get a hold of the isolate + auto isolate = v8::Isolate::GetCurrent(); + auto context = isolate->GetCurrentContext(); + auto global = context->Global(); + + auto globalInspectorObject = utils::Common::getGlobalInspectorObject(isolate); + + if (!globalInspectorObject.IsEmpty()) { + auto getComputedStylesForNode = globalInspectorObject->Get(ArgConverter::ConvertToV8String(isolate, getComputedStylesForNodeString)); + + if (!getComputedStylesForNode.IsEmpty() && getComputedStylesForNode->IsFunction()) { + auto getComputedStylesForNodeFunc = getComputedStylesForNode.As(); + v8::Local args[] = { v8::Number::New(isolate, in_nodeId) }; + v8::TryCatch tc; + + auto maybeResult = getComputedStylesForNodeFunc->Call(context, global, 1, args); + + if (tc.HasCaught()) { + *errorString = utils::Common::getJSCallErrorMessage(getComputedStylesForNodeString, tc.Message()->Get()).c_str(); + + *out_computedStyle = std::move(computedStylePropertyArr); + return; + } + + v8::Local outResult; + + if (maybeResult.ToLocal(&outResult)) { + auto resultString = ArgConverter::ConvertToString(outResult->ToString()); + auto resultCStr = resultString.c_str(); + auto resultJson = protocol::parseJSON(resultCStr); + + protocol::ErrorSupport errorSupport; + auto computedStyles = protocol::Array::parse( + resultJson.get(), &errorSupport); + + auto errorSupportString = errorSupport.errors().utf8(); + if (!errorSupportString.empty()) { + auto errorMessage = "Error while parsing CSSComputedStyleProperty object. "; + DEBUG_WRITE_FORCE("%s Error: %s", errorMessage, errorSupportString.c_str()); + } else { + *out_computedStyle = std::move(computedStyles); + + return; + } + } + } + } + + *out_computedStyle = std::move(computedStylePropertyArr); + } + + void V8CSSAgentImpl::getPlatformFontsForNode(ErrorString *, int in_nodeId, + std::unique_ptr> *out_fonts) { + auto fontsArr = protocol::Array::create(); + auto defaultFont = "System Font"; + fontsArr->addItem(std::move(protocol::CSS::PlatformFontUsage::create() + .setFamilyName(defaultFont) + .setGlyphCount(1) + .setIsCustomFont(false) + .build())); + *out_fonts = std::move(fontsArr); + } + + // Not supported + void V8CSSAgentImpl::getStyleSheetText(ErrorString *, const String &in_styleSheetId, + String *out_text) { + *out_text = ""; + } + + + V8CSSAgentImpl* V8CSSAgentImpl::Instance = 0; +} \ No newline at end of file diff --git a/runtime/src/main/jni/v8_inspector/src/inspector/v8-css-agent-impl.h b/runtime/src/main/jni/v8_inspector/src/inspector/v8-css-agent-impl.h new file mode 100644 index 000000000..e21596e3e --- /dev/null +++ b/runtime/src/main/jni/v8_inspector/src/inspector/v8-css-agent-impl.h @@ -0,0 +1,47 @@ +// +// Created by pkanev on 5/11/2017. +// + +#ifndef V8_CSS_AGENT_IMPL_H +#define V8_CSS_AGENT_IMPL_H + +#include + +namespace v8_inspector { + + class V8InspectorSessionImpl; + + using protocol::ErrorString; + using v8_inspector::protocol::Maybe; + using String = v8_inspector::String16; + + + class V8CSSAgentImpl : public protocol::CSS::Backend { + public: + V8CSSAgentImpl(V8InspectorSessionImpl *, protocol::FrontendChannel *, + protocol::DictionaryValue *state); + + ~V8CSSAgentImpl() override; + + void enable(std::unique_ptr callback) override; + void disable(ErrorString*) override; + void getMatchedStylesForNode(ErrorString*, int in_nodeId, Maybe* out_inlineStyle, Maybe* out_attributesStyle, Maybe>* out_matchedCSSRules, Maybe>* out_pseudoElements, Maybe>* out_inherited, Maybe>* out_cssKeyframesRules) override; + void getInlineStylesForNode(ErrorString*, int in_nodeId, Maybe* out_inlineStyle, Maybe* out_attributesStyle) override; + void getComputedStyleForNode(ErrorString*, int in_nodeId, std::unique_ptr>* out_computedStyle) override; + void getPlatformFontsForNode(ErrorString*, int in_nodeId, std::unique_ptr>* out_fonts) override; + void getStyleSheetText(ErrorString*, const String& in_styleSheetId, String* out_text) override; + + static V8CSSAgentImpl* Instance; + protocol::CSS::Frontend m_frontend; + + private: + V8InspectorSessionImpl* m_session; + protocol::DictionaryValue* m_state; + bool m_enabled; + + DISALLOW_COPY_AND_ASSIGN(V8CSSAgentImpl); + }; +} + + +#endif //V8_CSS_AGENT_IMPL_H diff --git a/runtime/src/main/jni/v8_inspector/src/inspector/v8-dom-agent-impl.cpp b/runtime/src/main/jni/v8_inspector/src/inspector/v8-dom-agent-impl.cpp new file mode 100644 index 000000000..6e6c6b822 --- /dev/null +++ b/runtime/src/main/jni/v8_inspector/src/inspector/v8-dom-agent-impl.cpp @@ -0,0 +1,227 @@ +// +// Created by pkanev on 4/24/2017. +// + +#include +#include "v8-dom-agent-impl.h" +#include +#include +#include + +namespace v8_inspector { + + using tns::Runtime; + using tns::ArgConverter; + + namespace DOMAgentState { + static const char domEnabled[] = "domEnabled"; + } + + V8DOMAgentImpl::V8DOMAgentImpl(V8InspectorSessionImpl *session, + protocol::FrontendChannel *frontendChannel, + protocol::DictionaryValue *state) + : m_session(session), + m_frontend(frontendChannel), + m_state(state), + m_enabled(false) { + Instance = this; + } + + V8DOMAgentImpl::~V8DOMAgentImpl() { } + + void V8DOMAgentImpl::enable(ErrorString*) { + if (m_enabled) { + return; + } + + m_state->setBoolean(DOMAgentState::domEnabled, true); + + m_enabled = true; + } + + void V8DOMAgentImpl::disable(ErrorString*) { + if (!m_enabled) { + return; + } + + m_state->setBoolean(DOMAgentState::domEnabled, false); + + m_enabled = false; + } + + void V8DOMAgentImpl::getDocument(ErrorString *errorString, std::unique_ptr* out_root) { + std::unique_ptr defaultNode = protocol::DOM::Node::create() + .setNodeId(0) + .setNodeType(9) + .setNodeName("Frame") + .setLocalName("Frame") + .setNodeValue("") + .build(); + + std::string getDocumentFunctionString = "getDocument"; + // TODO: Pete: Find a better way to get a hold of the isolate + auto isolate = v8::Isolate::GetCurrent(); + auto context = isolate->GetCurrentContext(); + auto global = context->Global(); + + auto globalInspectorObject = utils::Common::getGlobalInspectorObject(isolate); + + if (!globalInspectorObject.IsEmpty()) { + auto getDocument = globalInspectorObject->Get(ArgConverter::ConvertToV8String(isolate, getDocumentFunctionString)); + + if (!getDocument.IsEmpty() && getDocument->IsFunction()) { + auto getDocumentFunc = getDocument.As(); + v8::Local args[] = { }; + v8::TryCatch tc; + + auto maybeResult = getDocumentFunc->Call(context, global, 0, args); + + if (tc.HasCaught()) { + *errorString = utils::Common::getJSCallErrorMessage(getDocumentFunctionString, tc.Message()->Get()).c_str(); + + *out_root = std::move(defaultNode); + return; + } + + v8::Local outResult; + + if (maybeResult.ToLocal(&outResult)) { + auto resultString = ArgConverter::ConvertToString(outResult->ToString()); + auto resultCStr = resultString.c_str(); + auto resultJson = protocol::parseJSON(resultCStr); + + protocol::ErrorSupport errorSupport; + auto domNode = protocol::DOM::Node::parse(resultJson.get(), &errorSupport); + + auto errorSupportString = errorSupport.errors().utf8(); + *errorString = errorSupportString.c_str(); + if (!errorSupportString.empty()) { + auto errorMessage = "Error while parsing debug `DOM Node` object. "; + DEBUG_WRITE_FORCE("JS Error: %s", errorMessage, errorSupportString.c_str()); + } else { + *out_root = std::move(domNode); + + return; + } + } else { + *errorString = "Didn't get a proper result from __getDocument call. Returning empty visual tree."; + } + } + } + + *out_root = std::move(defaultNode); + } + + void V8DOMAgentImpl::removeNode(ErrorString *errorString, int in_nodeId) { + std::string removeNodeFunctionString = "removeNode"; + + // TODO: Pete: Find a better way to get a hold of the isolate + auto isolate = v8::Isolate::GetCurrent(); + auto context = isolate->GetCurrentContext(); + auto global = context->Global(); + + auto globalInspectorObject = utils::Common::getGlobalInspectorObject(isolate); + + if (!globalInspectorObject.IsEmpty()) { + auto removeNode = globalInspectorObject->Get(ArgConverter::ConvertToV8String(isolate, removeNodeFunctionString)); + + if (!removeNode.IsEmpty() && removeNode->IsFunction()) { + auto removeNodeFunc = removeNode.As(); + v8::Local args[] = { v8::Number::New(isolate, in_nodeId) }; + v8::TryCatch tc; + + removeNodeFunc->Call(context, global, 1, args); + + if (tc.HasCaught()) { + *errorString = utils::Common::getJSCallErrorMessage(removeNodeFunctionString, tc.Message()->Get()).c_str(); + } + + return; + } + } + + *errorString = "Couldn't remove the selected DOMNode from the visual tree."; + } + + // Pete: return empty resolved object - prevents crashes when opening the 'properties', 'event listeners' tabs + // Not supported + void V8DOMAgentImpl::resolveNode(ErrorString*, int in_nodeId, const Maybe& in_objectGroup, std::unique_ptr* out_object) { + auto resolvedNode = protocol::Runtime::RemoteObject::create() + .setType("View") + .build(); + + *out_object = std::move(resolvedNode); + } + + void V8DOMAgentImpl::setAttributeValue(ErrorString *errorString, int in_nodeId, const String &in_name, + const String &in_value) { + // Irrelevant + } + + void V8DOMAgentImpl::setAttributesAsText(ErrorString *errorString, int in_nodeId, const String &in_text, + const Maybe &in_name) { + // call modules' View class methods to modify view's attribute + // TODO: Pete: Find a better way to get a hold of the isolate + std::string setAttributeAsTextFunctionString = "setAttributeAsText"; + auto isolate = v8::Isolate::GetCurrent(); + auto context = isolate->GetCurrentContext(); + auto global = context->Global(); + + auto globalInspectorObject = utils::Common::getGlobalInspectorObject(isolate); + + if (!globalInspectorObject.IsEmpty()) { + auto setAttributeAsText = globalInspectorObject->Get(ArgConverter::ConvertToV8String(isolate, setAttributeAsTextFunctionString)); + + if (!setAttributeAsText.IsEmpty() && setAttributeAsText->IsFunction()) { + auto setAttributeAsTextFunc = setAttributeAsText.As(); + v8::Local args[] = { v8::Number::New(isolate, in_nodeId), ArgConverter::ConvertToV8String(isolate, in_text.utf8()), ArgConverter::ConvertToV8String(isolate, in_name.fromJust().utf8()) }; + v8::TryCatch tc; + + setAttributeAsTextFunc->Call(context, global, 3, args); + + if (tc.HasCaught()) { + *errorString = utils::Common::getJSCallErrorMessage(setAttributeAsTextFunctionString, tc.Message()->Get()).c_str(); + } + + return; + } + } + } + + void V8DOMAgentImpl::removeAttribute(ErrorString *errorString, int in_nodeId, const String &in_name) { + // Irrelevant + } + + // Not supported + void V8DOMAgentImpl::performSearch(ErrorString *, const String &in_query, + const Maybe> &in_nodeIds, + String *out_searchId, int *out_resultCount) { + + } + + // Not supported + void V8DOMAgentImpl::getSearchResults(ErrorString *, const String &in_searchId, int in_fromIndex, + int in_toIndex, + std::unique_ptr> *out_nodeIds) { + + } + + // Not supported + void V8DOMAgentImpl::discardSearchResults(ErrorString *, const String &in_searchId) { + + } + + // Not supported + void V8DOMAgentImpl::highlightNode(ErrorString *, + std::unique_ptr in_highlightConfig, + const Maybe &in_nodeId, + const Maybe &in_objectId) { + + } + + void V8DOMAgentImpl::hideHighlight(ErrorString *) { + + } + + V8DOMAgentImpl* V8DOMAgentImpl::Instance = 0; +} diff --git a/runtime/src/main/jni/v8_inspector/src/inspector/v8-dom-agent-impl.h b/runtime/src/main/jni/v8_inspector/src/inspector/v8-dom-agent-impl.h new file mode 100644 index 000000000..e829eb00c --- /dev/null +++ b/runtime/src/main/jni/v8_inspector/src/inspector/v8-dom-agent-impl.h @@ -0,0 +1,57 @@ +// +// Created by pkanev on 4/24/2017. +// + +#ifndef V8_DOM_AGENT_IMPL_H +#define V8_DOM_AGENT_IMPL_H + +#include + +namespace v8_inspector { + + class V8InspectorSessionImpl; + + using protocol::ErrorString; + using v8_inspector::protocol::Maybe; + using String = v8_inspector::String16; + + class V8DOMAgentImpl : public protocol::DOM::Backend { + public: + V8DOMAgentImpl(V8InspectorSessionImpl *, protocol::FrontendChannel *, + protocol::DictionaryValue *state); + + ~V8DOMAgentImpl() override; + + void enable(ErrorString*) override; + void disable(ErrorString*) override; + + void getDocument(ErrorString*, std::unique_ptr* out_root) override; + void removeNode(ErrorString*, int in_nodeId)override; + void setAttributeValue(ErrorString*, int in_nodeId, const String& in_name, const String& in_value) override; + void setAttributesAsText(ErrorString*, int in_nodeId, const String& in_text, const Maybe& in_name) override; + void removeAttribute(ErrorString*, int in_nodeId, const String& in_name) override; + void performSearch(ErrorString*, const String& in_query, const Maybe>& in_nodeIds, String* out_searchId, int* out_resultCount) override; + void getSearchResults(ErrorString*, const String& in_searchId, int in_fromIndex, int in_toIndex, std::unique_ptr>* out_nodeIds) override; + void discardSearchResults(ErrorString*, const String& in_searchId) override; + void highlightNode(ErrorString*, std::unique_ptr in_highlightConfig, const Maybe& in_nodeId, const Maybe& in_objectId) override; + void hideHighlight(ErrorString*) override; + void resolveNode(ErrorString*, int in_nodeId, const Maybe& in_objectGroup, std::unique_ptr* out_object) override; + + const bool enabled() { + return m_enabled; + }; + + static V8DOMAgentImpl* Instance; + protocol::DOM::Frontend m_frontend; + + private: + V8InspectorSessionImpl* m_session; + protocol::DictionaryValue* m_state; + + bool m_enabled; + + DISALLOW_COPY_AND_ASSIGN(V8DOMAgentImpl); + }; +} + +#endif //V8_DOM_AGENT_IMPL_H \ No newline at end of file diff --git a/runtime/src/main/jni/v8_inspector/src/inspector/v8-inspector-session-impl.cc b/runtime/src/main/jni/v8_inspector/src/inspector/v8-inspector-session-impl.cc index cd48636bb..3acf22469 100644 --- a/runtime/src/main/jni/v8_inspector/src/inspector/v8-inspector-session-impl.cc +++ b/runtime/src/main/jni/v8_inspector/src/inspector/v8-inspector-session-impl.cc @@ -20,427 +20,453 @@ #include "src/inspector/v8-schema-agent-impl.h" #include "src/inspector/v8-page-agent-impl.h" #include "src/inspector/v8-network-agent-impl.h" +#include "src/inspector/v8-dom-agent-impl.h" +#include "src/inspector/v8-css-agent-impl.h" namespace v8_inspector { // static -bool V8InspectorSession::canDispatchMethod(const StringView& method) { - return stringViewStartsWith(method, - protocol::Runtime::Metainfo::commandPrefix) || - stringViewStartsWith(method, - protocol::Debugger::Metainfo::commandPrefix) || - stringViewStartsWith(method, - protocol::Profiler::Metainfo::commandPrefix) || - stringViewStartsWith( - method, protocol::HeapProfiler::Metainfo::commandPrefix) || - stringViewStartsWith(method, - protocol::Console::Metainfo::commandPrefix) || - stringViewStartsWith(method, - protocol::Schema::Metainfo::commandPrefix) || - stringViewStartsWith(method, - protocol::Page::Metainfo::commandPrefix) || - stringViewStartsWith(method, - protocol::Network::Metainfo::commandPrefix); -} - -std::unique_ptr V8InspectorSessionImpl::create( - V8InspectorImpl* inspector, int contextGroupId, - V8Inspector::Channel* channel, const StringView& state) { - return wrapUnique( - new V8InspectorSessionImpl(inspector, contextGroupId, channel, state)); -} - -V8InspectorSessionImpl::V8InspectorSessionImpl(V8InspectorImpl* inspector, - int contextGroupId, - V8Inspector::Channel* channel, - const StringView& savedState) - : m_contextGroupId(contextGroupId), - m_inspector(inspector), - m_channel(channel), - m_customObjectFormatterEnabled(false), - m_dispatcher(this), - m_state(nullptr), - m_runtimeAgent(nullptr), - m_debuggerAgent(nullptr), - m_heapProfilerAgent(nullptr), - m_profilerAgent(nullptr), - m_consoleAgent(nullptr), - m_schemaAgent(nullptr), - m_pageAgent(nullptr), - m_networkAgent(nullptr) { - if (savedState.length()) { - std::unique_ptr state = - protocol::parseJSON(toString16(savedState)); - if (state) m_state = protocol::DictionaryValue::cast(std::move(state)); - if (!m_state) m_state = protocol::DictionaryValue::create(); - } else { - m_state = protocol::DictionaryValue::create(); - } - - m_runtimeAgent = wrapUnique(new V8RuntimeAgentImpl( - this, this, agentState(protocol::Runtime::Metainfo::domainName))); - protocol::Runtime::Dispatcher::wire(&m_dispatcher, m_runtimeAgent.get()); - - m_debuggerAgent = wrapUnique(new V8DebuggerAgentImpl( - this, this, agentState(protocol::Debugger::Metainfo::domainName))); - protocol::Debugger::Dispatcher::wire(&m_dispatcher, m_debuggerAgent.get()); - - m_profilerAgent = wrapUnique(new V8ProfilerAgentImpl( - this, this, agentState(protocol::Profiler::Metainfo::domainName))); - protocol::Profiler::Dispatcher::wire(&m_dispatcher, m_profilerAgent.get()); - - m_heapProfilerAgent = wrapUnique(new V8HeapProfilerAgentImpl( - this, this, agentState(protocol::HeapProfiler::Metainfo::domainName))); - protocol::HeapProfiler::Dispatcher::wire(&m_dispatcher, - m_heapProfilerAgent.get()); - - m_consoleAgent = wrapUnique(new V8ConsoleAgentImpl( - this, this, agentState(protocol::Console::Metainfo::domainName))); - protocol::Console::Dispatcher::wire(&m_dispatcher, m_consoleAgent.get()); - - m_schemaAgent = wrapUnique(new V8SchemaAgentImpl( - this, this, agentState(protocol::Schema::Metainfo::domainName))); - protocol::Schema::Dispatcher::wire(&m_dispatcher, m_schemaAgent.get()); - - m_pageAgent = wrapUnique(new V8PageAgentImpl( - this, this, agentState(protocol::Page::Metainfo::domainName))); - protocol::Page::Dispatcher::wire(&m_dispatcher, m_pageAgent.get()); - - m_networkAgent = wrapUnique(new V8NetworkAgentImpl( - this, this, agentState(protocol::Network::Metainfo::domainName))); - protocol::Network::Dispatcher::wire(&m_dispatcher, m_networkAgent.get()); - - if (savedState.length()) { - m_runtimeAgent->restore(); - m_debuggerAgent->restore(); - m_heapProfilerAgent->restore(); - m_profilerAgent->restore(); - m_consoleAgent->restore(); - m_pageAgent->restore(); - } -} - -V8InspectorSessionImpl::~V8InspectorSessionImpl() { - ErrorString errorString; - m_consoleAgent->disable(&errorString); - m_profilerAgent->disable(&errorString); - m_heapProfilerAgent->disable(&errorString); - m_debuggerAgent->disable(&errorString); - m_runtimeAgent->disable(&errorString); - m_pageAgent->disable(&errorString); - m_networkAgent->disable(&errorString); - - discardInjectedScripts(); - m_inspector->disconnect(this); -} - -protocol::DictionaryValue* V8InspectorSessionImpl::agentState( - const String16& name) { - protocol::DictionaryValue* state = m_state->getObject(name); - if (!state) { - std::unique_ptr newState = - protocol::DictionaryValue::create(); - state = newState.get(); - m_state->setObject(name, std::move(newState)); - } - return state; -} - -void V8InspectorSessionImpl::sendProtocolResponse(int callId, - const String16& message) { - m_channel->sendProtocolResponse(callId, toStringView(message)); -} - -void V8InspectorSessionImpl::sendProtocolNotification(const String16& message) { - m_channel->sendProtocolNotification(toStringView(message)); -} - -void V8InspectorSessionImpl::flushProtocolNotifications() { - m_channel->flushProtocolNotifications(); -} - -void V8InspectorSessionImpl::reset() { - m_debuggerAgent->reset(); - m_runtimeAgent->reset(); - discardInjectedScripts(); -} - -void V8InspectorSessionImpl::discardInjectedScripts() { - m_inspectedObjects.clear(); - const V8InspectorImpl::ContextByIdMap* contexts = - m_inspector->contextGroup(m_contextGroupId); - if (!contexts) return; - - std::vector keys; - keys.reserve(contexts->size()); - for (auto& idContext : *contexts) keys.push_back(idContext.first); - for (auto& key : keys) { - contexts = m_inspector->contextGroup(m_contextGroupId); - if (!contexts) continue; - auto contextIt = contexts->find(key); - if (contextIt != contexts->end()) - contextIt->second - ->discardInjectedScript(); // This may destroy some contexts. - } -} - -InjectedScript* V8InspectorSessionImpl::findInjectedScript( - ErrorString* errorString, int contextId) { + bool V8InspectorSession::canDispatchMethod(const StringView& method) { + return stringViewStartsWith(method, + protocol::Runtime::Metainfo::commandPrefix) || + stringViewStartsWith(method, + protocol::Debugger::Metainfo::commandPrefix) || + stringViewStartsWith(method, + protocol::Profiler::Metainfo::commandPrefix) || + stringViewStartsWith( + method, protocol::HeapProfiler::Metainfo::commandPrefix) || + stringViewStartsWith(method, + protocol::Console::Metainfo::commandPrefix) || + stringViewStartsWith(method, + protocol::Schema::Metainfo::commandPrefix) || + stringViewStartsWith(method, + protocol::Page::Metainfo::commandPrefix) || + stringViewStartsWith(method, + protocol::Network::Metainfo::commandPrefix) || + stringViewStartsWith(method, + protocol::DOM::Metainfo::commandPrefix) || + stringViewStartsWith(method, + protocol::CSS::Metainfo::commandPrefix); + } + + std::unique_ptr V8InspectorSessionImpl::create( + V8InspectorImpl* inspector, int contextGroupId, + V8Inspector::Channel* channel, const StringView& state) { + return wrapUnique( + new V8InspectorSessionImpl(inspector, contextGroupId, channel, state)); + } + + V8InspectorSessionImpl::V8InspectorSessionImpl(V8InspectorImpl* inspector, + int contextGroupId, + V8Inspector::Channel* channel, + const StringView& savedState) + : m_contextGroupId(contextGroupId), + m_inspector(inspector), + m_channel(channel), + m_customObjectFormatterEnabled(false), + m_dispatcher(this), + m_state(nullptr), + m_runtimeAgent(nullptr), + m_debuggerAgent(nullptr), + m_heapProfilerAgent(nullptr), + m_profilerAgent(nullptr), + m_consoleAgent(nullptr), + m_schemaAgent(nullptr), + m_pageAgent(nullptr), + m_networkAgent(nullptr), + m_domAgent(nullptr), + m_cssAgent(nullptr) { + if (savedState.length()) { + std::unique_ptr state = + protocol::parseJSON(toString16(savedState)); + if (state) m_state = protocol::DictionaryValue::cast(std::move(state)); + if (!m_state) m_state = protocol::DictionaryValue::create(); + } else { + m_state = protocol::DictionaryValue::create(); + } + + m_runtimeAgent = wrapUnique(new V8RuntimeAgentImpl( + this, this, agentState(protocol::Runtime::Metainfo::domainName))); + protocol::Runtime::Dispatcher::wire(&m_dispatcher, m_runtimeAgent.get()); + + m_debuggerAgent = wrapUnique(new V8DebuggerAgentImpl( + this, this, agentState(protocol::Debugger::Metainfo::domainName))); + protocol::Debugger::Dispatcher::wire(&m_dispatcher, m_debuggerAgent.get()); + + m_profilerAgent = wrapUnique(new V8ProfilerAgentImpl( + this, this, agentState(protocol::Profiler::Metainfo::domainName))); + protocol::Profiler::Dispatcher::wire(&m_dispatcher, m_profilerAgent.get()); + + m_heapProfilerAgent = wrapUnique(new V8HeapProfilerAgentImpl( + this, this, agentState(protocol::HeapProfiler::Metainfo::domainName))); + protocol::HeapProfiler::Dispatcher::wire(&m_dispatcher, + m_heapProfilerAgent.get()); + + m_consoleAgent = wrapUnique(new V8ConsoleAgentImpl( + this, this, agentState(protocol::Console::Metainfo::domainName))); + protocol::Console::Dispatcher::wire(&m_dispatcher, m_consoleAgent.get()); + + m_schemaAgent = wrapUnique(new V8SchemaAgentImpl( + this, this, agentState(protocol::Schema::Metainfo::domainName))); + protocol::Schema::Dispatcher::wire(&m_dispatcher, m_schemaAgent.get()); + + m_pageAgent = wrapUnique(new V8PageAgentImpl( + this, this, agentState(protocol::Page::Metainfo::domainName))); + protocol::Page::Dispatcher::wire(&m_dispatcher, m_pageAgent.get()); + + m_networkAgent = wrapUnique(new V8NetworkAgentImpl( + this, this, agentState(protocol::Network::Metainfo::domainName))); + protocol::Network::Dispatcher::wire(&m_dispatcher, m_networkAgent.get()); + + m_domAgent = wrapUnique(new V8DOMAgentImpl( + this, this, agentState(protocol::DOM::Metainfo::domainName))); + protocol::DOM::Dispatcher::wire(&m_dispatcher, m_domAgent.get()); + + m_cssAgent = wrapUnique(new V8CSSAgentImpl( + this, this, agentState(protocol::CSS::Metainfo::domainName))); + protocol::CSS::Dispatcher::wire(&m_dispatcher, m_cssAgent.get()); + + if (savedState.length()) { + m_runtimeAgent->restore(); + m_debuggerAgent->restore(); + m_heapProfilerAgent->restore(); + m_profilerAgent->restore(); + m_consoleAgent->restore(); + m_pageAgent->restore(); + } + } + + V8InspectorSessionImpl::~V8InspectorSessionImpl() { + ErrorString errorString; + m_consoleAgent->disable(&errorString); + m_profilerAgent->disable(&errorString); + m_heapProfilerAgent->disable(&errorString); + m_debuggerAgent->disable(&errorString); + m_runtimeAgent->disable(&errorString); + m_pageAgent->disable(&errorString); + m_networkAgent->disable(&errorString); + m_domAgent->disable(&errorString); + m_cssAgent->disable(&errorString); + + discardInjectedScripts(); + m_inspector->disconnect(this); + } + + protocol::DictionaryValue* V8InspectorSessionImpl::agentState( + const String16& name) { + protocol::DictionaryValue* state = m_state->getObject(name); + if (!state) { + std::unique_ptr newState = + protocol::DictionaryValue::create(); + state = newState.get(); + m_state->setObject(name, std::move(newState)); + } + return state; + } + + void V8InspectorSessionImpl::sendProtocolResponse(int callId, + const String16& message) { + m_channel->sendProtocolResponse(callId, toStringView(message)); + } + + void V8InspectorSessionImpl::sendProtocolNotification(const String16& message) { + m_channel->sendProtocolNotification(toStringView(message)); + } + + void V8InspectorSessionImpl::flushProtocolNotifications() { + m_channel->flushProtocolNotifications(); + } + + void V8InspectorSessionImpl::reset() { + m_debuggerAgent->reset(); + m_runtimeAgent->reset(); + discardInjectedScripts(); + } + + void V8InspectorSessionImpl::discardInjectedScripts() { + m_inspectedObjects.clear(); + const V8InspectorImpl::ContextByIdMap* contexts = + m_inspector->contextGroup(m_contextGroupId); + if (!contexts) return; + + std::vector keys; + keys.reserve(contexts->size()); + for (auto& idContext : *contexts) keys.push_back(idContext.first); + for (auto& key : keys) { + contexts = m_inspector->contextGroup(m_contextGroupId); + if (!contexts) continue; + auto contextIt = contexts->find(key); + if (contextIt != contexts->end()) + contextIt->second + ->discardInjectedScript(); // This may destroy some contexts. + } + } + + InjectedScript* V8InspectorSessionImpl::findInjectedScript( + ErrorString* errorString, int contextId) { // if (!contextId) { // *errorString = "Cannot find context with specified id"; // return nullptr; // } - const V8InspectorImpl::ContextByIdMap* contexts = - m_inspector->contextGroup(m_contextGroupId); - if (!contexts) { - *errorString = "Cannot find context with specified id"; - return nullptr; - } - - auto contextsIt = contexts->find(contextId); - if (contextsIt == contexts->end()) { - *errorString = "Cannot find context with specified id"; - return nullptr; - } - - const std::unique_ptr& context = contextsIt->second; - if (!context->getInjectedScript()) { - context->createInjectedScript(); - if (!context->getInjectedScript()) { - *errorString = "Cannot access specified execution context"; - return nullptr; - } - if (m_customObjectFormatterEnabled) - context->getInjectedScript()->setCustomObjectFormatterEnabled(true); - } - return context->getInjectedScript(); -} - -InjectedScript* V8InspectorSessionImpl::findInjectedScript( - ErrorString* errorString, RemoteObjectIdBase* objectId) { - return objectId ? findInjectedScript(errorString, objectId->contextId()) - : nullptr; -} - -void V8InspectorSessionImpl::releaseObjectGroup(const StringView& objectGroup) { - releaseObjectGroup(toString16(objectGroup)); -} - -void V8InspectorSessionImpl::releaseObjectGroup(const String16& objectGroup) { - const V8InspectorImpl::ContextByIdMap* contexts = - m_inspector->contextGroup(m_contextGroupId); - if (!contexts) return; - - std::vector keys; - for (auto& idContext : *contexts) keys.push_back(idContext.first); - for (auto& key : keys) { - contexts = m_inspector->contextGroup(m_contextGroupId); - if (!contexts) continue; - auto contextsIt = contexts->find(key); - if (contextsIt == contexts->end()) continue; - InjectedScript* injectedScript = contextsIt->second->getInjectedScript(); - if (injectedScript) - injectedScript->releaseObjectGroup( - objectGroup); // This may destroy some contexts. - } -} - -bool V8InspectorSessionImpl::unwrapObject( - std::unique_ptr* error, const StringView& objectId, - v8::Local* object, v8::Local* context, - std::unique_ptr* objectGroup) { - ErrorString errorString; - String16 objectGroupString; - bool result = - unwrapObject(&errorString, toString16(objectId), object, context, - objectGroup ? &objectGroupString : nullptr); - if (error) *error = StringBufferImpl::adopt(errorString); - if (objectGroup) *objectGroup = StringBufferImpl::adopt(objectGroupString); - return result; -} - -bool V8InspectorSessionImpl::unwrapObject(ErrorString* errorString, - const String16& objectId, - v8::Local* object, - v8::Local* context, - String16* objectGroup) { - std::unique_ptr remoteId = - RemoteObjectId::parse(errorString, objectId); - if (!remoteId) return false; - InjectedScript* injectedScript = - findInjectedScript(errorString, remoteId.get()); - if (!injectedScript) return false; - if (!injectedScript->findObject(errorString, *remoteId, object)) return false; - *context = injectedScript->context()->context(); - if (objectGroup) *objectGroup = injectedScript->objectGroupName(*remoteId); - return true; -} - -std::unique_ptr -V8InspectorSessionImpl::wrapObject(v8::Local context, - v8::Local value, - const StringView& groupName) { - return wrapObject(context, value, toString16(groupName), false); -} - -std::unique_ptr -V8InspectorSessionImpl::wrapObject(v8::Local context, - v8::Local value, - const String16& groupName, - bool generatePreview) { - ErrorString errorString; - InjectedScript* injectedScript = - findInjectedScript(&errorString, V8Debugger::contextId(context)); - if (!injectedScript) return nullptr; - return injectedScript->wrapObject(&errorString, value, groupName, false, - generatePreview); -} - -std::unique_ptr -V8InspectorSessionImpl::wrapTable(v8::Local context, - v8::Local table, - v8::Local columns) { - ErrorString errorString; - InjectedScript* injectedScript = - findInjectedScript(&errorString, V8Debugger::contextId(context)); - if (!injectedScript) return nullptr; - return injectedScript->wrapTable(table, columns); -} - -void V8InspectorSessionImpl::setCustomObjectFormatterEnabled(bool enabled) { - m_customObjectFormatterEnabled = enabled; - const V8InspectorImpl::ContextByIdMap* contexts = - m_inspector->contextGroup(m_contextGroupId); - if (!contexts) return; - for (auto& idContext : *contexts) { - InjectedScript* injectedScript = idContext.second->getInjectedScript(); - if (injectedScript) - injectedScript->setCustomObjectFormatterEnabled(enabled); - } -} - -void V8InspectorSessionImpl::reportAllContexts(V8RuntimeAgentImpl* agent) { - const V8InspectorImpl::ContextByIdMap* contexts = - m_inspector->contextGroup(m_contextGroupId); - if (!contexts) return; - for (auto& idContext : *contexts) - agent->reportExecutionContextCreated(idContext.second.get()); -} - -void V8InspectorSessionImpl::dispatchProtocolMessage( - const StringView& message) { - m_dispatcher.dispatch(protocol::parseJSON(message)); -} - -std::unique_ptr V8InspectorSessionImpl::stateJSON() { - String16 json = m_state->toJSONString(); - return StringBufferImpl::adopt(json); -} - -std::vector> -V8InspectorSessionImpl::supportedDomains() { - std::vector> domains = - supportedDomainsImpl(); - std::vector> result; - for (size_t i = 0; i < domains.size(); ++i) - result.push_back(std::move(domains[i])); - return result; -} - -std::vector> -V8InspectorSessionImpl::supportedDomainsImpl() { - std::vector> result; - result.push_back(protocol::Schema::Domain::create() - .setName(protocol::Runtime::Metainfo::domainName) - .setVersion(protocol::Runtime::Metainfo::version) - .build()); - result.push_back(protocol::Schema::Domain::create() - .setName(protocol::Debugger::Metainfo::domainName) - .setVersion(protocol::Debugger::Metainfo::version) - .build()); - result.push_back(protocol::Schema::Domain::create() - .setName(protocol::Profiler::Metainfo::domainName) - .setVersion(protocol::Profiler::Metainfo::version) - .build()); - result.push_back(protocol::Schema::Domain::create() - .setName(protocol::HeapProfiler::Metainfo::domainName) - .setVersion(protocol::HeapProfiler::Metainfo::version) - .build()); - result.push_back(protocol::Schema::Domain::create() - .setName(protocol::Schema::Metainfo::domainName) - .setVersion(protocol::Schema::Metainfo::version) - .build()); - result.push_back(protocol::Schema::Domain::create() - .setName(protocol::Page::Metainfo::domainName) - .setVersion(protocol::Page::Metainfo::version) - .build()); - result.push_back(protocol::Schema::Domain::create() - .setName(protocol::Network::Metainfo::domainName) - .setVersion(protocol::Network::Metainfo::version) - .build()); - return result; -} - -void V8InspectorSessionImpl::addInspectedObject( - std::unique_ptr inspectable) { - m_inspectedObjects.insert(m_inspectedObjects.begin(), std::move(inspectable)); - if (m_inspectedObjects.size() > kInspectedObjectBufferSize) - m_inspectedObjects.resize(kInspectedObjectBufferSize); -} - -V8InspectorSession::Inspectable* V8InspectorSessionImpl::inspectedObject( - unsigned num) { - if (num >= m_inspectedObjects.size()) return nullptr; - return m_inspectedObjects[num].get(); -} - -void V8InspectorSessionImpl::schedulePauseOnNextStatement( - const StringView& breakReason, const StringView& breakDetails) { - m_debuggerAgent->schedulePauseOnNextStatement( - toString16(breakReason), - protocol::DictionaryValue::cast(protocol::parseJSON(breakDetails))); -} - -void V8InspectorSessionImpl::cancelPauseOnNextStatement() { - m_debuggerAgent->cancelPauseOnNextStatement(); -} - -void V8InspectorSessionImpl::breakProgram(const StringView& breakReason, - const StringView& breakDetails) { - m_debuggerAgent->breakProgram( - toString16(breakReason), - protocol::DictionaryValue::cast(protocol::parseJSON(breakDetails))); -} - -void V8InspectorSessionImpl::setSkipAllPauses(bool skip) { - ErrorString errorString; - m_debuggerAgent->setSkipAllPauses(&errorString, skip); -} - -void V8InspectorSessionImpl::resume() { - ErrorString errorString; - m_debuggerAgent->resume(&errorString); -} - -void V8InspectorSessionImpl::stepOver() { - ErrorString errorString; - m_debuggerAgent->stepOver(&errorString); -} - -std::vector> -V8InspectorSessionImpl::searchInTextByLines(const StringView& text, - const StringView& query, - bool caseSensitive, bool isRegex) { - // TODO(dgozman): search may operate on StringView and avoid copying |text|. - std::vector> matches = - searchInTextByLinesImpl(this, toString16(text), toString16(query), - caseSensitive, isRegex); - std::vector> result; - for (size_t i = 0; i < matches.size(); ++i) - result.push_back(std::move(matches[i])); - return result; -} + const V8InspectorImpl::ContextByIdMap* contexts = + m_inspector->contextGroup(m_contextGroupId); + if (!contexts) { + *errorString = "Cannot find context with specified id"; + return nullptr; + } + + auto contextsIt = contexts->find(contextId); + if (contextsIt == contexts->end()) { + *errorString = "Cannot find context with specified id"; + return nullptr; + } + + const std::unique_ptr& context = contextsIt->second; + if (!context->getInjectedScript()) { + context->createInjectedScript(); + if (!context->getInjectedScript()) { + *errorString = "Cannot access specified execution context"; + return nullptr; + } + if (m_customObjectFormatterEnabled) + context->getInjectedScript()->setCustomObjectFormatterEnabled(true); + } + return context->getInjectedScript(); + } + + InjectedScript* V8InspectorSessionImpl::findInjectedScript( + ErrorString* errorString, RemoteObjectIdBase* objectId) { + return objectId ? findInjectedScript(errorString, objectId->contextId()) + : nullptr; + } + + void V8InspectorSessionImpl::releaseObjectGroup(const StringView& objectGroup) { + releaseObjectGroup(toString16(objectGroup)); + } + + void V8InspectorSessionImpl::releaseObjectGroup(const String16& objectGroup) { + const V8InspectorImpl::ContextByIdMap* contexts = + m_inspector->contextGroup(m_contextGroupId); + if (!contexts) return; + + std::vector keys; + for (auto& idContext : *contexts) keys.push_back(idContext.first); + for (auto& key : keys) { + contexts = m_inspector->contextGroup(m_contextGroupId); + if (!contexts) continue; + auto contextsIt = contexts->find(key); + if (contextsIt == contexts->end()) continue; + InjectedScript* injectedScript = contextsIt->second->getInjectedScript(); + if (injectedScript) + injectedScript->releaseObjectGroup( + objectGroup); // This may destroy some contexts. + } + } + + bool V8InspectorSessionImpl::unwrapObject( + std::unique_ptr* error, const StringView& objectId, + v8::Local* object, v8::Local* context, + std::unique_ptr* objectGroup) { + ErrorString errorString; + String16 objectGroupString; + bool result = + unwrapObject(&errorString, toString16(objectId), object, context, + objectGroup ? &objectGroupString : nullptr); + if (error) *error = StringBufferImpl::adopt(errorString); + if (objectGroup) *objectGroup = StringBufferImpl::adopt(objectGroupString); + return result; + } + + bool V8InspectorSessionImpl::unwrapObject(ErrorString* errorString, + const String16& objectId, + v8::Local* object, + v8::Local* context, + String16* objectGroup) { + std::unique_ptr remoteId = + RemoteObjectId::parse(errorString, objectId); + if (!remoteId) return false; + InjectedScript* injectedScript = + findInjectedScript(errorString, remoteId.get()); + if (!injectedScript) return false; + if (!injectedScript->findObject(errorString, *remoteId, object)) return false; + *context = injectedScript->context()->context(); + if (objectGroup) *objectGroup = injectedScript->objectGroupName(*remoteId); + return true; + } + + std::unique_ptr + V8InspectorSessionImpl::wrapObject(v8::Local context, + v8::Local value, + const StringView& groupName) { + return wrapObject(context, value, toString16(groupName), false); + } + + std::unique_ptr + V8InspectorSessionImpl::wrapObject(v8::Local context, + v8::Local value, + const String16& groupName, + bool generatePreview) { + ErrorString errorString; + InjectedScript* injectedScript = + findInjectedScript(&errorString, V8Debugger::contextId(context)); + if (!injectedScript) return nullptr; + return injectedScript->wrapObject(&errorString, value, groupName, false, + generatePreview); + } + + std::unique_ptr + V8InspectorSessionImpl::wrapTable(v8::Local context, + v8::Local table, + v8::Local columns) { + ErrorString errorString; + InjectedScript* injectedScript = + findInjectedScript(&errorString, V8Debugger::contextId(context)); + if (!injectedScript) return nullptr; + return injectedScript->wrapTable(table, columns); + } + + void V8InspectorSessionImpl::setCustomObjectFormatterEnabled(bool enabled) { + m_customObjectFormatterEnabled = enabled; + const V8InspectorImpl::ContextByIdMap* contexts = + m_inspector->contextGroup(m_contextGroupId); + if (!contexts) return; + for (auto& idContext : *contexts) { + InjectedScript* injectedScript = idContext.second->getInjectedScript(); + if (injectedScript) + injectedScript->setCustomObjectFormatterEnabled(enabled); + } + } + + void V8InspectorSessionImpl::reportAllContexts(V8RuntimeAgentImpl* agent) { + const V8InspectorImpl::ContextByIdMap* contexts = + m_inspector->contextGroup(m_contextGroupId); + if (!contexts) return; + for (auto& idContext : *contexts) + agent->reportExecutionContextCreated(idContext.second.get()); + } + + void V8InspectorSessionImpl::dispatchProtocolMessage( + const StringView& message) { + m_dispatcher.dispatch(protocol::parseJSON(message)); + } + + std::unique_ptr V8InspectorSessionImpl::stateJSON() { + String16 json = m_state->toJSONString(); + return StringBufferImpl::adopt(json); + } + + std::vector> + V8InspectorSessionImpl::supportedDomains() { + std::vector> domains = + supportedDomainsImpl(); + std::vector> result; + for (size_t i = 0; i < domains.size(); ++i) + result.push_back(std::move(domains[i])); + return result; + } + + std::vector> + V8InspectorSessionImpl::supportedDomainsImpl() { + std::vector> result; + result.push_back(protocol::Schema::Domain::create() + .setName(protocol::Runtime::Metainfo::domainName) + .setVersion(protocol::Runtime::Metainfo::version) + .build()); + result.push_back(protocol::Schema::Domain::create() + .setName(protocol::Debugger::Metainfo::domainName) + .setVersion(protocol::Debugger::Metainfo::version) + .build()); + result.push_back(protocol::Schema::Domain::create() + .setName(protocol::Profiler::Metainfo::domainName) + .setVersion(protocol::Profiler::Metainfo::version) + .build()); + result.push_back(protocol::Schema::Domain::create() + .setName(protocol::HeapProfiler::Metainfo::domainName) + .setVersion(protocol::HeapProfiler::Metainfo::version) + .build()); + result.push_back(protocol::Schema::Domain::create() + .setName(protocol::Schema::Metainfo::domainName) + .setVersion(protocol::Schema::Metainfo::version) + .build()); + result.push_back(protocol::Schema::Domain::create() + .setName(protocol::Page::Metainfo::domainName) + .setVersion(protocol::Page::Metainfo::version) + .build()); + result.push_back(protocol::Schema::Domain::create() + .setName(protocol::Network::Metainfo::domainName) + .setVersion(protocol::Network::Metainfo::version) + .build()); + result.push_back(protocol::Schema::Domain::create() + .setName(protocol::DOM::Metainfo::domainName) + .setVersion(protocol::DOM::Metainfo::version) + .build()); + result.push_back(protocol::Schema::Domain::create() + .setName(protocol::CSS::Metainfo::domainName) + .setVersion(protocol::CSS::Metainfo::version) + .build()); + return result; + } + + void V8InspectorSessionImpl::addInspectedObject( + std::unique_ptr inspectable) { + m_inspectedObjects.insert(m_inspectedObjects.begin(), std::move(inspectable)); + if (m_inspectedObjects.size() > kInspectedObjectBufferSize) + m_inspectedObjects.resize(kInspectedObjectBufferSize); + } + + V8InspectorSession::Inspectable* V8InspectorSessionImpl::inspectedObject( + unsigned num) { + if (num >= m_inspectedObjects.size()) return nullptr; + return m_inspectedObjects[num].get(); + } + + void V8InspectorSessionImpl::schedulePauseOnNextStatement( + const StringView& breakReason, const StringView& breakDetails) { + m_debuggerAgent->schedulePauseOnNextStatement( + toString16(breakReason), + protocol::DictionaryValue::cast(protocol::parseJSON(breakDetails))); + } + + void V8InspectorSessionImpl::cancelPauseOnNextStatement() { + m_debuggerAgent->cancelPauseOnNextStatement(); + } + + void V8InspectorSessionImpl::breakProgram(const StringView& breakReason, + const StringView& breakDetails) { + m_debuggerAgent->breakProgram( + toString16(breakReason), + protocol::DictionaryValue::cast(protocol::parseJSON(breakDetails))); + } + + void V8InspectorSessionImpl::setSkipAllPauses(bool skip) { + ErrorString errorString; + m_debuggerAgent->setSkipAllPauses(&errorString, skip); + } + + void V8InspectorSessionImpl::resume() { + ErrorString errorString; + m_debuggerAgent->resume(&errorString); + } + + void V8InspectorSessionImpl::stepOver() { + ErrorString errorString; + m_debuggerAgent->stepOver(&errorString); + } + + std::vector> + V8InspectorSessionImpl::searchInTextByLines(const StringView& text, + const StringView& query, + bool caseSensitive, bool isRegex) { + // TODO(dgozman): search may operate on StringView and avoid copying |text|. + std::vector> matches = + searchInTextByLinesImpl(this, toString16(text), toString16(query), + caseSensitive, isRegex); + std::vector> result; + for (size_t i = 0; i < matches.size(); ++i) + result.push_back(std::move(matches[i])); + return result; + } } // namespace v8_inspector diff --git a/runtime/src/main/jni/v8_inspector/src/inspector/v8-inspector-session-impl.h b/runtime/src/main/jni/v8_inspector/src/inspector/v8-inspector-session-impl.h index f5ed8eb35..492e9a998 100644 --- a/runtime/src/main/jni/v8_inspector/src/inspector/v8-inspector-session-impl.h +++ b/runtime/src/main/jni/v8_inspector/src/inspector/v8-inspector-session-impl.h @@ -13,31 +13,35 @@ #include "src/inspector/protocol/Schema.h" #include "src/inspector/protocol/Page.h" #include "src/inspector/protocol/Network.h" +#include "src/inspector/protocol/DOM.h" +#include "src/inspector/protocol/CSS.h" #include "include/v8-inspector.h" namespace v8_inspector { -class InjectedScript; -class RemoteObjectIdBase; -class V8ConsoleAgentImpl; -class V8DebuggerAgentImpl; -class V8InspectorImpl; -class V8HeapProfilerAgentImpl; -class V8ProfilerAgentImpl; -class V8RuntimeAgentImpl; -class V8SchemaAgentImpl; -class V8PageAgentImpl; -class V8NetworkAgentImpl; - -using protocol::ErrorString; - -class V8InspectorSessionImpl : public V8InspectorSession, - public protocol::FrontendChannel { + class InjectedScript; + class RemoteObjectIdBase; + class V8ConsoleAgentImpl; + class V8DebuggerAgentImpl; + class V8InspectorImpl; + class V8HeapProfilerAgentImpl; + class V8ProfilerAgentImpl; + class V8RuntimeAgentImpl; + class V8SchemaAgentImpl; + class V8PageAgentImpl; + class V8NetworkAgentImpl; + class V8DOMAgentImpl; + class V8CSSAgentImpl; + + using protocol::ErrorString; + + class V8InspectorSessionImpl : public V8InspectorSession, + public protocol::FrontendChannel { public: static std::unique_ptr create( - V8InspectorImpl*, int contextGroupId, V8Inspector::Channel*, - const StringView& state); + V8InspectorImpl*, int contextGroupId, V8Inspector::Channel*, + const StringView& state); ~V8InspectorSessionImpl(); V8InspectorImpl* inspector() const { @@ -64,6 +68,12 @@ class V8InspectorSessionImpl : public V8InspectorSession, V8NetworkAgentImpl* networkAgent() { return m_networkAgent.get(); } + V8DOMAgentImpl* domAgent() { + return m_domAgent.get(); + } + V8CSSAgentImpl* cssAgent() { + return m_cssAgent.get(); + } int contextGroupId() const { return m_contextGroupId; } @@ -75,11 +85,11 @@ class V8InspectorSessionImpl : public V8InspectorSession, void reportAllContexts(V8RuntimeAgentImpl*); void setCustomObjectFormatterEnabled(bool); std::unique_ptr wrapObject( - v8::Local, v8::Local, const String16& groupName, - bool generatePreview); + v8::Local, v8::Local, const String16& groupName, + bool generatePreview); std::unique_ptr wrapTable( - v8::Local, v8::Local table, - v8::Local columns); + v8::Local, v8::Local table, + v8::Local columns); std::vector> supportedDomainsImpl(); bool unwrapObject(ErrorString*, const String16& objectId, v8::Local*, v8::Local*, @@ -90,9 +100,9 @@ class V8InspectorSessionImpl : public V8InspectorSession, void dispatchProtocolMessage(const StringView& message) override; std::unique_ptr stateJSON() override; std::vector> supportedDomains() - override; + override; void addInspectedObject( - std::unique_ptr) override; + std::unique_ptr) override; void schedulePauseOnNextStatement(const StringView& breakReason, const StringView& breakDetails) override; void cancelPauseOnNextStatement() override; @@ -102,15 +112,15 @@ class V8InspectorSessionImpl : public V8InspectorSession, void resume() override; void stepOver() override; std::vector> - searchInTextByLines(const StringView& text, const StringView& query, - bool caseSensitive, bool isRegex) override; + searchInTextByLines(const StringView& text, const StringView& query, + bool caseSensitive, bool isRegex) override; void releaseObjectGroup(const StringView& objectGroup) override; bool unwrapObject(std::unique_ptr*, const StringView& objectId, v8::Local*, v8::Local*, std::unique_ptr* objectGroup) override; std::unique_ptr wrapObject( - v8::Local, v8::Local, - const StringView& groupName) override; + v8::Local, v8::Local, + const StringView& groupName) override; V8InspectorSession::Inspectable* inspectedObject(unsigned num); static const unsigned kInspectedObjectBufferSize = 5; @@ -141,12 +151,14 @@ class V8InspectorSessionImpl : public V8InspectorSession, std::unique_ptr m_schemaAgent; std::unique_ptr m_pageAgent; std::unique_ptr m_networkAgent; + std::unique_ptr m_domAgent; + std::unique_ptr m_cssAgent; std::vector> m_inspectedObjects; DISALLOW_COPY_AND_ASSIGN(V8InspectorSessionImpl); -}; + }; } // namespace v8_inspector