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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/framework/inspector/page-agent.sky
diff --git a/sky/framework/inspector/page-agent.sky b/sky/framework/inspector/page-agent.sky
index 875d5719301ef3179c79eb802451230b75aa9904..2157b770bd0983519ffb9e6e3c6509e79131b15a 100644
--- a/sky/framework/inspector/page-agent.sky
+++ b/sky/framework/inspector/page-agent.sky
@@ -19,13 +19,13 @@ Page.prototype.canEmulate = function() {
};
};
-Page.prototype.getResourceContent = function(params, message_id) {
+Page.prototype.getResourceContent = function(params, messageId) {
var request = new XMLHttpRequest;
request.onload = function() {
var message = {
'content' : request.responseText,
};
- this.delegate_.sendResponse(message_id, message);
+ this.delegate_.sendResponse(messageId, message);
}.bind(this);
request.open("GET", params.url);
request.send();
@@ -33,6 +33,57 @@ Page.prototype.getResourceContent = function(params, message_id) {
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.
@@ -41,11 +92,11 @@ Page.prototype.getResourceTree = function() {
"frame": {
"id": "1",
"loaderId": "1",
- "url": document.URL,
+ "url": String(document.URL),
"mimeType": "text/html",
- "securityOrigin": document.URL,
+ "securityOrigin": String(document.URL),
},
- "resources": [], // FIXME
+ "resources": arrayFromIterator(resourcesMapForSubtree(document).values()),
}
};
};
« 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