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

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

Issue 732413004: Add support for Page.getResourceTree (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Add FIXME Created 6 years, 1 month 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 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() {
11 return { 11 return {
12 result: false 12 result: false
13 }; 13 };
14 }; 14 };
15 15
16 Page.prototype.canEmulate = function() { 16 Page.prototype.canEmulate = function() {
17 return { 17 return {
18 result: false 18 result: false
19 }; 19 };
20 }; 20 };
21 21
22 Page.prototype.getResourceContent = function(params, message_id) { 22 Page.prototype.getResourceContent = function(params, messageId) {
23 var request = new XMLHttpRequest; 23 var request = new XMLHttpRequest;
24 request.onload = function() { 24 request.onload = function() {
25 var message = { 25 var message = {
26 'content' : request.responseText, 26 'content' : request.responseText,
27 }; 27 };
28 this.delegate_.sendResponse(message_id, message); 28 this.delegate_.sendResponse(messageId, 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 // FIXME: ES6 has Array.from which theoretically does this.
37 function arrayFromIterator(iterator) {
38 var a = [];
39 for (var e of iterator)
40 a.push(e);
41 return a;
42 }
43
44 // FIXME: NodeList will soon inherit from array.
45 function forEachInNodeList(array, callback, scope) {
46 for (var i = 0; i < array.length; i++) {
47 callback.call(scope, array[i]);
48 }
49 };
50
51 function addResource(map, url, type, mimeType) {
52 // Be sure to string the url object since has(new Object)
53 // will always return false.
54 var absoluteURL = String(new URL(url, document.URL));
55 if (map.has(absoluteURL))
56 return;
57 map.set(absoluteURL, {
58 'url': String(absoluteURL),
59 'type': type,
60 'mimeType': mimeType,
61 })
62 }
63
64 function resourcesMapForSubtree(root_doc) {
65 var map = new Map;
66 var roots = [root_doc];
67 while (roots.length) {
68 var root = roots.pop();
69 var elements = root.querySelectorAll('*');
70 forEachInNodeList(elements, function(element) {
71 if (element.tagName == "import") {
72 // FIXME: It's no longer possible to walk into an import. :(
73 // roots.push(element.import);
74 addResource(map, element.getAttribute('src'), 'Document', 'text/html');
75 } else if (element.tagName == "img") {
76 // FIXME: Can't determine the type of an image from the DOM.
77 addResource(map, element.getAttribute('src'), 'Image', 'image/unknown');
78 }
79 if (element.shadowRoot) {
80 roots.push(element.shadowRoot);
81 }
82 });
83 }
84 return map;
85 }
86
36 Page.prototype.getResourceTree = function() { 87 Page.prototype.getResourceTree = function() {
37 // Unclear if this is all needed, but if we don't return something here 88 // Unclear if this is all needed, but if we don't return something here
38 // the inspector hits an exception in WebInspector.ResourceTreeModel. 89 // the inspector hits an exception in WebInspector.ResourceTreeModel.
39 return { 90 return {
40 "frameTree": { 91 "frameTree": {
41 "frame": { 92 "frame": {
42 "id": "1", 93 "id": "1",
43 "loaderId": "1", 94 "loaderId": "1",
44 "url": document.URL, 95 "url": String(document.URL),
45 "mimeType": "text/html", 96 "mimeType": "text/html",
46 "securityOrigin": document.URL, 97 "securityOrigin": String(document.URL),
47 }, 98 },
48 "resources": [], // FIXME 99 "resources": arrayFromIterator(resourcesMapForSubtree(document).values()),
49 } 100 }
50 }; 101 };
51 }; 102 };
52 103
53 module.exports = Page; 104 module.exports = Page;
54 </script> 105 </script>
OLDNEW
« no previous file with comments | « sky/engine/web/ChromeClientImpl.cpp ('k') | sky/tests/inspector/page-agent-get-resource-tree.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698