| OLD | NEW |
| (Empty) |
| 1 <import src="../xmlhttprequest.sky" as="XMLHttpRequest" /> | |
| 2 <script> | |
| 3 class Page { | |
| 4 constructor(delegate) { | |
| 5 this.delegate_ = delegate; | |
| 6 Object.preventExtensions(this); | |
| 7 } | |
| 8 | |
| 9 enable() { | |
| 10 } | |
| 11 | |
| 12 canScreencast() { | |
| 13 return { | |
| 14 result: false | |
| 15 }; | |
| 16 } | |
| 17 | |
| 18 canEmulate() { | |
| 19 return { | |
| 20 result: false | |
| 21 }; | |
| 22 } | |
| 23 | |
| 24 getResourceContent(params, messageId) { | |
| 25 var request = new XMLHttpRequest; | |
| 26 request.onload = function() { | |
| 27 var message = { | |
| 28 'content' : request.responseText, | |
| 29 }; | |
| 30 this.delegate_.sendResponse(messageId, message); | |
| 31 }.bind(this); | |
| 32 request.open("GET", params.url); | |
| 33 request.send(); | |
| 34 | |
| 35 return this.delegate_.ASYNC_RESPONSE; | |
| 36 } | |
| 37 | |
| 38 getResourceTree() { | |
| 39 // Unclear if this is all needed, but if we don't return something here | |
| 40 // the inspector hits an exception in WebInspector.ResourceTreeModel. | |
| 41 return { | |
| 42 "frameTree": { | |
| 43 "frame": { | |
| 44 "id": "1", | |
| 45 "loaderId": "1", | |
| 46 "url": String(document.URL), | |
| 47 "mimeType": "text/html", | |
| 48 "securityOrigin": String(document.URL), | |
| 49 }, | |
| 50 "resources": arrayFromIterator(resourcesMapForSubtree(document).values()
), | |
| 51 } | |
| 52 }; | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 // FIXME: ES6 has Array.from which theoretically does this. | |
| 57 function arrayFromIterator(iterator) { | |
| 58 var a = []; | |
| 59 for (var e of iterator) | |
| 60 a.push(e); | |
| 61 return a; | |
| 62 } | |
| 63 | |
| 64 // FIXME: NodeList will soon inherit from array. | |
| 65 function forEachInNodeList(array, callback, scope) { | |
| 66 for (var i = 0; i < array.length; i++) { | |
| 67 callback.call(scope, array[i]); | |
| 68 } | |
| 69 } | |
| 70 | |
| 71 function addResource(map, url, type, mimeType) { | |
| 72 // Be sure to string the url object since has(new Object) | |
| 73 // will always return false. | |
| 74 var absoluteURL = String(new URL(url, document.URL)); | |
| 75 if (map.has(absoluteURL)) | |
| 76 return; | |
| 77 map.set(absoluteURL, { | |
| 78 'url': String(absoluteURL), | |
| 79 'type': type, | |
| 80 'mimeType': mimeType, | |
| 81 }) | |
| 82 } | |
| 83 | |
| 84 function resourcesMapForSubtree(root_doc) { | |
| 85 var map = new Map; | |
| 86 var roots = [root_doc]; | |
| 87 while (roots.length) { | |
| 88 var root = roots.pop(); | |
| 89 var elements = root.querySelectorAll('*'); | |
| 90 forEachInNodeList(elements, function(element) { | |
| 91 if (element.tagName == "import") { | |
| 92 // FIXME: It's no longer possible to walk into an import. :( | |
| 93 // roots.push(element.import); | |
| 94 addResource(map, element.getAttribute('src'), 'Document', 'text/html'); | |
| 95 } else if (element.tagName == "img") { | |
| 96 // FIXME: Can't determine the type of an image from the DOM. | |
| 97 addResource(map, element.getAttribute('src'), 'Image', 'image/unknown'); | |
| 98 } | |
| 99 if (element.shadowRoot) { | |
| 100 roots.push(element.shadowRoot); | |
| 101 } | |
| 102 }); | |
| 103 } | |
| 104 return map; | |
| 105 } | |
| 106 | |
| 107 module.exports = Page; | |
| 108 </script> | |
| OLD | NEW |