Skip to content

Commit 337bbaa

Browse files
authored
Merge pull request #776 from NativeScript/pete/devtools-elements
DevTools Elements tab
2 parents a8c7f11 + 0ac17fd commit 337bbaa

16 files changed

+7062
-442
lines changed
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
//
2+
// Created by pkanev on 5/10/2017.
3+
//
4+
5+
#include <sstream>
6+
#include <ArgConverter.h>
7+
#include <NativeScriptAssert.h>
8+
#include "DOMDomainCallbackHandlers.h"
9+
10+
using namespace tns;
11+
12+
void DOMDomainCallbackHandlers::DocumentUpdatedCallback(const v8::FunctionCallbackInfo<v8::Value> &args) {
13+
auto domAgentInstance = V8DOMAgentImpl::Instance;
14+
15+
if (!domAgentInstance) {
16+
return;
17+
}
18+
19+
domAgentInstance->m_frontend.documentUpdated();
20+
}
21+
22+
void DOMDomainCallbackHandlers::ChildNodeInsertedCallback(const v8::FunctionCallbackInfo<v8::Value> &args) {
23+
try {
24+
auto domAgentInstance = V8DOMAgentImpl::Instance;
25+
26+
if (!domAgentInstance) {
27+
return;
28+
}
29+
30+
auto isolate = args.GetIsolate();
31+
32+
v8::HandleScope scope(isolate);
33+
34+
if (args.Length() != 3 || !(args[0]->IsNumber() && args[1]->IsNumber() && args[2]->IsString())) {
35+
throw NativeScriptException("Calling ChildNodeInserted with invalid arguments. Required params: parentId: number, lastId: number, node: JSON String");
36+
}
37+
38+
auto parentId = args[0]->ToNumber(isolate);
39+
auto lastId = args[1]->ToNumber(isolate);
40+
auto node = args[2]->ToString(isolate);
41+
42+
auto nodeString = ArgConverter::ConvertToString(node);
43+
auto nodeCStr = nodeString.c_str();
44+
auto nodeJson = protocol::parseJSON(nodeCStr);
45+
46+
protocol::ErrorSupport errorSupport;
47+
auto domNode = protocol::DOM::Node::parse(nodeJson.get(), &errorSupport);
48+
49+
auto errorSupportString = errorSupport.errors().utf8();
50+
if (!errorSupportString.empty()) {
51+
auto errorMessage = "Error while parsing debug `DOM Node` object. ";
52+
DEBUG_WRITE_FORCE("%s Error: %s", errorMessage, errorSupportString.c_str());
53+
}
54+
55+
domAgentInstance->m_frontend.childNodeInserted(parentId->Int32Value(), lastId->Int32Value(), std::move(domNode));
56+
} catch (NativeScriptException& e) {
57+
e.ReThrowToV8();
58+
} catch (std::exception e) {
59+
std::stringstream ss;
60+
ss << "Error: c exception: " << e.what() << std::endl;
61+
NativeScriptException nsEx(ss.str());
62+
nsEx.ReThrowToV8();
63+
} catch (...) {
64+
NativeScriptException nsEx(std::string("Error: c exception!"));
65+
nsEx.ReThrowToV8();
66+
}
67+
}
68+
69+
void DOMDomainCallbackHandlers::ChildNodeRemovedCallback(const v8::FunctionCallbackInfo<v8::Value> &args) {
70+
try {
71+
auto domAgentInstance = V8DOMAgentImpl::Instance;
72+
73+
if (!domAgentInstance) {
74+
return;
75+
}
76+
77+
auto isolate = args.GetIsolate();
78+
79+
v8::HandleScope scope(isolate);
80+
81+
if (args.Length() != 2 || !(args[0]->IsNumber() && args[1]->IsNumber())) {
82+
throw NativeScriptException("Calling ChildNodeRemoved with invalid arguments. Required params: parentId: number, nodeId: number");
83+
}
84+
85+
auto parentId = args[0]->ToNumber(isolate);
86+
auto nodeId = args[1]->ToNumber(isolate);
87+
88+
domAgentInstance->m_frontend.childNodeRemoved(parentId->Int32Value(), nodeId->Int32Value());
89+
} catch (NativeScriptException& e) {
90+
e.ReThrowToV8();
91+
} catch (std::exception e) {
92+
std::stringstream ss;
93+
ss << "Error: c exception: " << e.what() << std::endl;
94+
NativeScriptException nsEx(ss.str());
95+
nsEx.ReThrowToV8();
96+
} catch (...) {
97+
NativeScriptException nsEx(std::string("Error: c exception!"));
98+
nsEx.ReThrowToV8();
99+
}
100+
}
101+
102+
void DOMDomainCallbackHandlers::AttributeModifiedCallback(const v8::FunctionCallbackInfo<v8::Value> &args) {
103+
try {
104+
auto domAgentInstance = V8DOMAgentImpl::Instance;
105+
106+
if (!domAgentInstance) {
107+
return;
108+
}
109+
110+
auto isolate = args.GetIsolate();
111+
112+
v8::HandleScope scope(isolate);
113+
114+
if (args.Length() != 3 || !(args[0]->IsNumber() && args[1]->IsString() && args[2]->IsString())) {
115+
throw NativeScriptException("Calling AttributeModified with invalid arguments. Required params: nodeId: number, name: string, value: string");
116+
}
117+
118+
auto nodeId = args[0]->ToNumber(isolate);
119+
auto attributeName = args[1]->ToString();
120+
auto attributeValue = args[2]->ToString();
121+
122+
domAgentInstance->m_frontend.attributeModified(nodeId->Int32Value(),
123+
ArgConverter::ConvertToString(attributeName).c_str(),
124+
ArgConverter::ConvertToString(attributeValue).c_str());
125+
} catch (NativeScriptException& e) {
126+
e.ReThrowToV8();
127+
} catch (std::exception e) {
128+
std::stringstream ss;
129+
ss << "Error: c exception: " << e.what() << std::endl;
130+
NativeScriptException nsEx(ss.str());
131+
nsEx.ReThrowToV8();
132+
} catch (...) {
133+
NativeScriptException nsEx(std::string("Error: c exception!"));
134+
nsEx.ReThrowToV8();
135+
}
136+
}
137+
138+
void DOMDomainCallbackHandlers::AttributeRemovedCallback(const v8::FunctionCallbackInfo<v8::Value> &args) {
139+
try {
140+
auto domAgentInstance = V8DOMAgentImpl::Instance;
141+
142+
if (!domAgentInstance) {
143+
return;
144+
}
145+
auto isolate = args.GetIsolate();
146+
147+
v8::HandleScope scope(isolate);
148+
149+
if (args.Length() != 2 || !(args[0]->IsNumber() && args[1]->IsString())) {
150+
throw NativeScriptException("Calling AttributeRemoved with invalid arguments. Required params: nodeId: number, name: string");
151+
}
152+
153+
auto nodeId = args[0]->ToNumber(isolate);
154+
auto attributeName = args[1]->ToString();
155+
156+
domAgentInstance->m_frontend.attributeRemoved(nodeId->Int32Value(),
157+
ArgConverter::ConvertToString(attributeName).c_str());
158+
} catch (NativeScriptException& e) {
159+
e.ReThrowToV8();
160+
} catch (std::exception e) {
161+
std::stringstream ss;
162+
ss << "Error: c exception: " << e.what() << std::endl;
163+
NativeScriptException nsEx(ss.str());
164+
nsEx.ReThrowToV8();
165+
} catch (...) {
166+
NativeScriptException nsEx(std::string("Error: c exception!"));
167+
nsEx.ReThrowToV8();
168+
}
169+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// Created by pkanev on 5/10/2017.
3+
//
4+
5+
#ifndef DOMDOMAINCALLBACKHANDLERS_H
6+
#define DOMDOMAINCALLBACKHANDLERS_H
7+
8+
#include <include/v8.h>
9+
#include <v8_inspector/src/inspector/v8-dom-agent-impl.h>
10+
#include "JsV8InspectorClient.h"
11+
#include "NativeScriptException.h"
12+
13+
namespace tns {
14+
class DOMDomainCallbackHandlers {
15+
16+
public:
17+
static void DocumentUpdatedCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
18+
static void ChildNodeInsertedCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
19+
static void ChildNodeRemovedCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
20+
static void AttributeModifiedCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
21+
static void AttributeRemovedCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
22+
};
23+
}
24+
25+
26+
#endif //DOMDOMAINCALLBACKHANDLERS_H

runtime/src/main/jni/JsV8InspectorClient.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "NativeScriptException.h"
77

88
#include "ArgConverter.h"
9+
#include "DOMDomainCallbackHandlers.h"
910
#include "NetworkDomainCallbackHandlers.h"
1011

1112
using namespace std;
@@ -279,6 +280,12 @@ void JsV8InspectorClient::attachInspectorCallbacks(Isolate* isolate,
279280
inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "loadingFinished"), FunctionTemplate::New(isolate, NetworkDomainCallbackHandlers::LoadingFinishedCallback));
280281
inspectorJSObject->SetAccessor(ArgConverter::ConvertToV8String(isolate, "isConnected"), JsV8InspectorClient::InspectorIsConnectedGetterCallback);
281282

283+
inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "documentUpdated"), FunctionTemplate::New(isolate, DOMDomainCallbackHandlers::DocumentUpdatedCallback));
284+
inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "childNodeInserted"), FunctionTemplate::New(isolate, DOMDomainCallbackHandlers::ChildNodeInsertedCallback));
285+
inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "childNodeRemoved"), FunctionTemplate::New(isolate, DOMDomainCallbackHandlers::ChildNodeRemovedCallback));
286+
inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "attributeModified"), FunctionTemplate::New(isolate, DOMDomainCallbackHandlers::AttributeModifiedCallback));
287+
inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "attributeRemoved"), FunctionTemplate::New(isolate, DOMDomainCallbackHandlers::AttributeRemovedCallback));
288+
282289
globalObjectTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__inspector"), inspectorJSObject);
283290
}
284291

0 commit comments

Comments
 (0)