Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <import src="/sky/framework/xmlhttprequest.sky" as="XMLHttpRequest" /> | 1 <import src="/sky/framework/xmlhttprequest.sky" as="XMLHttpRequest" /> |
| 2 <script> | 2 <script> |
| 3 function Page(delegate) { | 3 function Page(delegate) { |
| 4 this.delegate_ = delegate; | 4 this.delegate_ = delegate; |
| 5 } | 5 } |
| 6 | 6 |
| 7 Page.prototype.enable = function() { | 7 Page.prototype.enable = function() { |
| 8 }; | 8 }; |
| 9 | 9 |
| 10 Page.prototype.canScreencast = function() { | 10 Page.prototype.canScreencast = function() { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 'content' : request.responseText, | 26 'content' : request.responseText, |
| 27 }; | 27 }; |
| 28 this.delegate_.sendResponse(message_id, message); | 28 this.delegate_.sendResponse(message_id, message); |
| 29 }.bind(this); | 29 }.bind(this); |
| 30 request.open("GET", params.url); | 30 request.open("GET", params.url); |
| 31 request.send(); | 31 request.send(); |
| 32 | 32 |
| 33 return this.delegate_.ASYNC_RESPONSE; | 33 return this.delegate_.ASYNC_RESPONSE; |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 Page.prototype._treeOrderWalk = function(root, visit) { | |
| 37 // HTML defines tree-order as a pre-order depth-first walk. | |
| 38 var node = root; | |
| 39 var parent_stack = []; | |
| 40 // WTF? Why is !![] == true in this forsaken language? | |
|
abarth-chromium
2014/11/18 23:08:42
Not sure we want this comment...
| |
| 41 while (parent_stack.length || node) { | |
| 42 if (node) { | |
| 43 visit(node); | |
| 44 if (node.nextSibling) | |
| 45 parent_stack.push(node.nextSibling); | |
| 46 node = node.firstChild; | |
| 47 } else | |
| 48 node = parent_stack.pop(); | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 Page.prototype._getElementsByTagName = function(root, tag_name) { | |
| 53 var elements = []; | |
| 54 this._treeOrderWalk(root, function(node) { | |
| 55 if (node.tagName == tag_name) | |
| 56 elements.push(node); | |
| 57 }); | |
| 58 return elements; | |
| 59 } | |
| 60 | |
| 61 // Javascript is possibly the worst language known to man. | |
| 62 // ES6 has Array.from which theoretically does this. | |
| 63 Page.prototype._arrayFromIterator = function(iterator) { | |
| 64 var a = []; | |
| 65 for (var e of iterator) | |
| 66 a.push(e); | |
| 67 return a; | |
| 68 } | |
| 69 | |
| 70 Page.prototype._resourcesMapForSubtree = function(root_doc) { | |
| 71 var resource_map = new Map; | |
| 72 function _addResource(url, type, mimeType) { | |
| 73 var absolute_url = new URL(url, document.URL); | |
| 74 if (resource_map.has(absolute_url)) | |
| 75 return; | |
| 76 resource_map.set(absolute_url, { | |
| 77 'url': String(absolute_url), | |
| 78 'type': type, | |
| 79 'mimeType': mimeType, | |
| 80 }) | |
| 81 } | |
| 82 | |
| 83 var pending_docs = [root_doc]; | |
| 84 while (pending_docs.length) { | |
| 85 var doc = pending_docs.pop(); | |
| 86 var imports = this._getElementsByTagName(doc, 'import'); | |
| 87 imports.forEach(function(imp) { | |
| 88 // FIXME: It's no longer possible to walk into an import. :( | |
| 89 // pending_docs.push(imp.import); | |
| 90 _addResource(imp.getAttribute('src'), 'Document', 'text/html'); | |
| 91 }); | |
| 92 var images = this._getElementsByTagName(doc, 'img'); | |
| 93 images.forEach(function(img) { | |
| 94 // FIXME: Can't determine the type of an image from the DOM. | |
| 95 _addResource(img.getAttribute('src'), 'Image', 'image/unknown'); | |
| 96 }); | |
| 97 } | |
| 98 return resource_map; | |
| 99 } | |
| 100 | |
| 36 Page.prototype.getResourceTree = function() { | 101 Page.prototype.getResourceTree = function() { |
| 37 // Unclear if this is all needed, but if we don't return something here | 102 // Unclear if this is all needed, but if we don't return something here |
| 38 // the inspector hits an exception in WebInspector.ResourceTreeModel. | 103 // the inspector hits an exception in WebInspector.ResourceTreeModel. |
| 104 var resources_iter = this._resourcesMapForSubtree(document).values(); | |
| 39 return { | 105 return { |
| 40 "frameTree": { | 106 "frameTree": { |
| 41 "frame": { | 107 "frame": { |
| 42 "id": "1", | 108 "id": "1", |
| 43 "loaderId": "1", | 109 "loaderId": "1", |
| 44 "url": document.URL, | 110 "url": String(document.URL), |
| 45 "mimeType": "text/html", | 111 "mimeType": "text/html", |
| 46 "securityOrigin": document.URL, | 112 "securityOrigin": String(document.URL), |
| 47 }, | 113 }, |
| 48 "resources": [], // FIXME | 114 "resources": this._arrayFromIterator(resources_iter), |
| 49 } | 115 } |
| 50 }; | 116 }; |
| 51 }; | 117 }; |
| 52 | 118 |
| 53 module.exports = Page; | 119 module.exports = Page; |
| 54 </script> | 120 </script> |
| OLD | NEW |