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