Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 6fea65e

Browse files
committed
cleaned up some of the code
1 parent 66bcf49 commit 6fea65e

1 file changed

Lines changed: 18 additions & 80 deletions

File tree

IEWebkitImpl/Browser.ts

Lines changed: 18 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module F12.Proxy {
1616
constructor() {
1717
this._mapUidToNode = new Map<number, Node>();
1818
this._mapNodeToUid = new WeakMap<Node, number>();
19-
this._nextAvailableUid = 44; // 43 is reserved for root to copy chrome, maybe change this to 2 later
19+
this._nextAvailableUid = 2; // 1 is reserved for the root
2020
this.windowExternal = (<any>external);
2121
this.windowExternal.addEventListener("message", (e: any) => this.messageHandler(e));
2222
}
@@ -142,8 +142,7 @@ module F12.Proxy {
142142
private _mapNodeToUid: WeakMap<Node, number>;
143143
private _nextAvailableUid: number;
144144

145-
private nodeToINode(node: Node): INode {
146-
145+
private createChromeNodeFromIENode(node: Node): INode {
147146
var inode: INode = {
148147
nodeId: +this.getOrAssignUid(node),
149148
nodeType: node.nodeType,
@@ -159,28 +158,14 @@ module F12.Proxy {
159158
if (node.attributes) {
160159
inode.attributes = [];
161160
for (var i = 0; i < node.attributes.length; i++) {
162-
inode.attributes.push(node.attributes[i].name); //todo: ensure this returns the same array as chrome
161+
inode.attributes.push(node.attributes[i].name);
163162
inode.attributes.push(node.attributes[i].value);
164163
}
165164
}
166165

167166
return inode;
168167
}
169168

170-
private popKidsRecursive(inode: INode, node: Node, childNum: number, depth: number): INode { //fixme childNum is not needed
171-
var newchild: INode = this.nodeToINode(node);
172-
if (!inode.children) {
173-
inode.children = [];
174-
}
175-
inode.children.push(newchild);
176-
if (depth > 0) {
177-
for (var i = 0; i < newchild.childNodeCount; i++) {
178-
this.popKidsRecursive(newchild, node.childNodes[i], i, depth - 1);
179-
}
180-
}
181-
return inode;
182-
}
183-
184169
public getOrAssignUid(node: Node): number {
185170
if (!node) {
186171
return;
@@ -190,13 +175,6 @@ module F12.Proxy {
190175
return 1;
191176
}
192177
var uid: number;
193-
//var uid = (<HTMLElement>node).uniqueID;
194-
//if (uid) {
195-
// if (this.getNode(uid)) { // <-- should ALWAYS succeed.
196-
// return uid;
197-
// }
198-
// needs mapping then continue with this id.
199-
//}
200178

201179
if (this._mapNodeToUid.has(node)) {
202180
return this._mapNodeToUid.get(node);
@@ -208,61 +186,32 @@ module F12.Proxy {
208186
this._mapNodeToUid.set(node, uid);
209187
return uid;
210188
}
211-
/*
212-
public getNode(uid: string): Node {
213-
if (uid === "#root") {
214-
return browser.document;
215-
}
216-
217-
var node: Node = this._dom.getElementByUniqueId(uid);
218-
if (node) {
219-
if (!this.isNodeAccessible(node)) {
220-
// Should never happen.
221-
return null;
222-
}
223-
224-
return node;
225-
}
226-
227-
node = this._mapUidToNode.get(uid);
228-
if (!node) {
229-
return null;
230-
}
231189

232-
if (!this.isNodeAccessible(node)) {
233-
this._mapUidToNode.delete(uid);
234-
return null;
235-
}
236-
237-
return node;
238-
}*/
239-
240-
private popKidsRecursiveTry2(iEnode: Node): INode {
241-
var chromeNode: INode = this.nodeToINode(iEnode);
190+
// same as createChromeNodeFromIENode but also recursively converts child nodes. //todo: add depth limitation
191+
private createChromeNodeFromIENodeRecursive(iEnode: Node): INode {
192+
var chromeNode: INode = this.createChromeNodeFromIENode(iEnode);
242193
if (!chromeNode.children && chromeNode.childNodeCount > 0) {
243194
chromeNode.children = [];
244195
}
245196
//todo: add an assert iEnode.childNodes.length == chromeNode.childNodeCount
246197
for (var i = 0; i < iEnode.childNodes.length; i++) {
247198
if (iEnode.childNodes[i].nodeType == NodeType.ELEMENT_NODE) {
248-
chromeNode.children.push(this.popKidsRecursiveTry2(iEnode.childNodes[i]));
199+
chromeNode.children.push(this.createChromeNodeFromIENodeRecursive(iEnode.childNodes[i]));
249200
}
250201
}
251-
252202
return chromeNode;
253203
}
254204

255205
private setChildNodes(id: number): void {
256206
var iEnode: Node = this._mapUidToNode.get(id);
257-
var chromeNode = this.nodeToINode(iEnode);
207+
var chromeNode = this.createChromeNodeFromIENode(iEnode);
258208
var nodeArray: INode[] = []
259209
for (var i = 0; i < iEnode.childNodes.length; i++) {
260-
nodeArray.push(this.popKidsRecursiveTry2(iEnode.childNodes[i]));
210+
nodeArray.push(this.createChromeNodeFromIENodeRecursive(iEnode.childNodes[i]));
261211
}
262212

263-
264213
// Send the response back over the websocket
265-
var response: any = {}; // todo type this. it has no ide so its not an Iwebkitresponce
214+
var response: any = {}; // todo type this. it has no id so its not an Iwebkitresponce
266215
response.method = "DOM.setChildNodes";
267216
response.params = {};
268217
response.params.parentId = id;
@@ -277,26 +226,30 @@ module F12.Proxy {
277226
switch (method) {
278227
//todo pull out into files/funcions
279228
case "getDocument":
280-
//var id:string =.toString();
281229
var x: INode = {
282-
nodeId: 43, //+browser.document.uniqueID, // unary + to convert string to number fixme
230+
nodeId: 1,
283231
nodeType: browser.document.nodeType,
284232
nodeName: browser.document.nodeName,
285233
localName: browser.document.localName || "",
286234
nodeValue: browser.document.nodeValue || "",
287235
documentURL: browser.document.URL,
288-
baseURL: browser.document.URL, // fixme: this line or the above line is probaly not right
236+
baseURL: browser.document.URL, // fixme: this line or the above line is probably not right
289237
xmlVersion: browser.document.xmlVersion,
290238

291239
};
240+
241+
if (!this._mapUidToNode.has(1)) {
242+
this._mapUidToNode.set(1, browser.document);
243+
this._mapNodeToUid.set(browser.document, 1);
244+
}
292245
if (browser.document.childNodes.length > 0) {
293246
x.childNodeCount = browser.document.childNodes.length;
294247
x.children = [];
295248
}
296249

297250
for (var i = 0; i < browser.document.childNodes.length; i++){
298251
if (browser.document.childNodes[i].nodeType == NodeType.ELEMENT_NODE) {
299-
x.children.push(this.popKidsRecursiveTry2(browser.document.childNodes[i]));
252+
x.children.push(this.createChromeNodeFromIENodeRecursive(browser.document.childNodes[i]));
300253
}
301254
}
302255

@@ -321,20 +274,6 @@ module F12.Proxy {
321274
padding: "rgba(247, 163, 135, 0.50)",
322275
content: "rgba(168, 221, 246, 0.50)"
323276
};
324-
/*
325-
var basicHighlightColor = {
326-
margin: "rgba(250, 212, 107, 0.75)",
327-
border: "rgba(120, 181, 51, 0.75)",
328-
padding: "rgba(247, 163, 135, 0.75)",
329-
content: "rgba(168, 221, 246, 0.75)"
330-
};
331-
332-
var hoverElementColor = {
333-
margin: "rgba(250, 212, 107, 0.50)",
334-
border: "rgba(120, 181, 51, 0.50)",
335-
padding: "rgba(247, 163, 135, 0.50)",
336-
content: "rgba(168, 221, 246, 0.50)"
337-
};*/
338277

339278
var element_to_highlight: Node = this._mapUidToNode.get(request.params.nodeId);
340279
while (element_to_highlight && element_to_highlight.nodeType != NodeType.ELEMENT_NODE) {
@@ -361,7 +300,6 @@ module F12.Proxy {
361300
this.setChildNodes(request.params.nodeId);
362301
}
363302

364-
365303
processedResult = {};
366304
break;
367305

0 commit comments

Comments
 (0)