| <import src="/sky/framework/xmlhttprequest.sky" as="XMLHttpRequest" /> |
| <script> |
| function Page(delegate) { |
| this.delegate_ = delegate; |
| } |
| |
| Page.prototype.enable = function() { |
| }; |
| |
| Page.prototype.canScreencast = function() { |
| return { |
| result: false |
| }; |
| }; |
| |
| Page.prototype.canEmulate = function() { |
| return { |
| result: false |
| }; |
| }; |
| |
| Page.prototype.getResourceContent = function(params, messageId) { |
| var request = new XMLHttpRequest; |
| request.onload = function() { |
| var message = { |
| 'content' : request.responseText, |
| }; |
| this.delegate_.sendResponse(messageId, message); |
| }.bind(this); |
| request.open("GET", params.url); |
| request.send(); |
| |
| return this.delegate_.ASYNC_RESPONSE; |
| }; |
| |
| // FIXME: ES6 has Array.from which theoretically does this. |
| function arrayFromIterator(iterator) { |
| var a = []; |
| for (var e of iterator) |
| a.push(e); |
| return a; |
| } |
| |
| // FIXME: NodeList will soon inherit from array. |
| function forEachInNodeList(array, callback, scope) { |
| for (var i = 0; i < array.length; i++) { |
| callback.call(scope, array[i]); |
| } |
| }; |
| |
| function addResource(map, url, type, mimeType) { |
| // Be sure to string the url object since has(new Object) |
| // will always return false. |
| var absoluteURL = String(new URL(url, document.URL)); |
| if (map.has(absoluteURL)) |
| return; |
| map.set(absoluteURL, { |
| 'url': String(absoluteURL), |
| 'type': type, |
| 'mimeType': mimeType, |
| }) |
| } |
| |
| function resourcesMapForSubtree(root_doc) { |
| var map = new Map; |
| var roots = [root_doc]; |
| while (roots.length) { |
| var root = roots.pop(); |
| var elements = root.querySelectorAll('*'); |
| forEachInNodeList(elements, function(element) { |
| if (element.tagName == "import") { |
| // FIXME: It's no longer possible to walk into an import. :( |
| // roots.push(element.import); |
| addResource(map, element.getAttribute('src'), 'Document', 'text/html'); |
| } else if (element.tagName == "img") { |
| // FIXME: Can't determine the type of an image from the DOM. |
| addResource(map, element.getAttribute('src'), 'Image', 'image/unknown'); |
| } |
| if (element.shadowRoot) { |
| roots.push(element.shadowRoot); |
| } |
| }); |
| } |
| return map; |
| } |
| |
| Page.prototype.getResourceTree = function() { |
| // Unclear if this is all needed, but if we don't return something here |
| // the inspector hits an exception in WebInspector.ResourceTreeModel. |
| return { |
| "frameTree": { |
| "frame": { |
| "id": "1", |
| "loaderId": "1", |
| "url": String(document.URL), |
| "mimeType": "text/html", |
| "securityOrigin": String(document.URL), |
| }, |
| "resources": arrayFromIterator(resourcesMapForSubtree(document).values()), |
| } |
| }; |
| }; |
| |
| module.exports = Page; |
| </script> |