Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(651)

Side by Side Diff: sky/framework/inspector/page-agent.sky

Issue 837933003: Convert the inspector framework to use ES6 classes. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Remove empty ctors Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 }
7
8 enable() {
9 }
10
11 canScreencast() {
12 return {
13 result: false
14 };
15 }
16
17 canEmulate() {
18 return {
19 result: false
20 };
21 }
22
23 getResourceContent(params, messageId) {
24 var request = new XMLHttpRequest;
25 request.onload = function() {
26 var message = {
27 'content' : request.responseText,
28 };
29 this.delegate_.sendResponse(messageId, message);
30 }.bind(this);
31 request.open("GET", params.url);
32 request.send();
33
34 return this.delegate_.ASYNC_RESPONSE;
35 }
36
37 getResourceTree() {
38 // Unclear if this is all needed, but if we don't return something here
39 // the inspector hits an exception in WebInspector.ResourceTreeModel.
40 return {
41 "frameTree": {
42 "frame": {
43 "id": "1",
44 "loaderId": "1",
45 "url": String(document.URL),
46 "mimeType": "text/html",
47 "securityOrigin": String(document.URL),
48 },
49 "resources": arrayFromIterator(resourcesMapForSubtree(document).values() ),
50 }
51 };
52 }
5 } 53 }
6 54
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. 55 // FIXME: ES6 has Array.from which theoretically does this.
37 function arrayFromIterator(iterator) { 56 function arrayFromIterator(iterator) {
38 var a = []; 57 var a = [];
39 for (var e of iterator) 58 for (var e of iterator)
40 a.push(e); 59 a.push(e);
41 return a; 60 return a;
42 } 61 }
43 62
44 // FIXME: NodeList will soon inherit from array. 63 // FIXME: NodeList will soon inherit from array.
45 function forEachInNodeList(array, callback, scope) { 64 function forEachInNodeList(array, callback, scope) {
46 for (var i = 0; i < array.length; i++) { 65 for (var i = 0; i < array.length; i++) {
47 callback.call(scope, array[i]); 66 callback.call(scope, array[i]);
48 } 67 }
49 }; 68 }
50 69
51 function addResource(map, url, type, mimeType) { 70 function addResource(map, url, type, mimeType) {
52 // Be sure to string the url object since has(new Object) 71 // Be sure to string the url object since has(new Object)
53 // will always return false. 72 // will always return false.
54 var absoluteURL = String(new URL(url, document.URL)); 73 var absoluteURL = String(new URL(url, document.URL));
55 if (map.has(absoluteURL)) 74 if (map.has(absoluteURL))
56 return; 75 return;
57 map.set(absoluteURL, { 76 map.set(absoluteURL, {
58 'url': String(absoluteURL), 77 'url': String(absoluteURL),
59 'type': type, 78 'type': type,
(...skipping 17 matching lines...) Expand all
77 addResource(map, element.getAttribute('src'), 'Image', 'image/unknown'); 96 addResource(map, element.getAttribute('src'), 'Image', 'image/unknown');
78 } 97 }
79 if (element.shadowRoot) { 98 if (element.shadowRoot) {
80 roots.push(element.shadowRoot); 99 roots.push(element.shadowRoot);
81 } 100 }
82 }); 101 });
83 } 102 }
84 return map; 103 return map;
85 } 104 }
86 105
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; 106 module.exports = Page;
105 </script> 107 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698