2010-10-20 Andrey Kosyakov <caseq@chromium.org>
authorcaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Oct 2010 14:18:57 +0000 (14:18 +0000)
committercaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Oct 2010 14:18:57 +0000 (14:18 +0000)
        Reviewed by Yury Semikhatsky.

        Inspector needs to use cached resources to display image resources.
        https://bugs.webkit.org/show_bug.cgi?id=16395

        * inspector/Inspector.idl: Add base64Encode parameter to getContent
        * inspector/InspectorResourceAgent.cpp:
        (WebCore::InspectorResourceAgent::resourceContent):
        * inspector/InspectorResourceAgent.h:
        * inspector/front-end/ExtensionServer.js:
        (WebInspector.ExtensionServer.prototype._onGetResourceContent):
        * inspector/front-end/ImageView.js:
        (WebInspector.ImageView.prototype.contentTabSelected.onResourceContent):
        (WebInspector.ImageView.prototype.contentTabSelected):
        * inspector/front-end/NetworkPanel.js:
        (WebInspector.NetworkDataGridNode.prototype._refreshNameCell.):
        (WebInspector.NetworkDataGridNode.prototype._refreshNameCell):
        * inspector/front-end/Resource.js:
        (WebInspector.Resource):
        (WebInspector.Resource.prototype.set finished):
        (WebInspector.Resource.prototype.getContent):
        (WebInspector.Resource.prototype.get contentURL):
        (WebInspector.Resource.prototype._requestContent.onResourceContent):
        (WebInspector.Resource.prototype._requestContent):
        * inspector/front-end/ResourcesPanel.js:
        (WebInspector.ResourceSidebarTreeElement.prototype.createIconElement.):
        (WebInspector.ResourceSidebarTreeElement.prototype.createIconElement):
        * inspector/front-end/Settings.js: Added useDataURLForResourceImageIcons
        * inspector/front-end/SourceView.js:
        (WebInspector.SourceView.prototype.setupSourceFrameIfNeeded):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@70519 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
WebCore/ChangeLog
WebCore/inspector/Inspector.idl
WebCore/inspector/InspectorResourceAgent.cpp
WebCore/inspector/InspectorResourceAgent.h
WebCore/inspector/front-end/ExtensionServer.js
WebCore/inspector/front-end/ImageView.js
WebCore/inspector/front-end/NetworkPanel.js
WebCore/inspector/front-end/Resource.js
WebCore/inspector/front-end/ResourceManager.js
WebCore/inspector/front-end/ResourcesPanel.js
WebCore/inspector/front-end/Settings.js
WebCore/inspector/front-end/SourceView.js

index cb4df10..2527c4b 100644 (file)
@@ -1,3 +1,36 @@
+2010-10-20  Andrey Kosyakov  <caseq@chromium.org>
+
+        Reviewed by Yury Semikhatsky.
+
+        Inspector needs to use cached resources to display image resources.
+        https://bugs.webkit.org/show_bug.cgi?id=16395
+
+        * inspector/Inspector.idl: Add base64Encode parameter to getContent
+        * inspector/InspectorResourceAgent.cpp:
+        (WebCore::InspectorResourceAgent::resourceContent):
+        * inspector/InspectorResourceAgent.h:
+        * inspector/front-end/ExtensionServer.js:
+        (WebInspector.ExtensionServer.prototype._onGetResourceContent):
+        * inspector/front-end/ImageView.js:
+        (WebInspector.ImageView.prototype.contentTabSelected.onResourceContent):
+        (WebInspector.ImageView.prototype.contentTabSelected):
+        * inspector/front-end/NetworkPanel.js:
+        (WebInspector.NetworkDataGridNode.prototype._refreshNameCell.):
+        (WebInspector.NetworkDataGridNode.prototype._refreshNameCell):
+        * inspector/front-end/Resource.js:
+        (WebInspector.Resource):
+        (WebInspector.Resource.prototype.set finished):
+        (WebInspector.Resource.prototype.getContent):
+        (WebInspector.Resource.prototype.get contentURL):
+        (WebInspector.Resource.prototype._requestContent.onResourceContent):
+        (WebInspector.Resource.prototype._requestContent):
+        * inspector/front-end/ResourcesPanel.js:
+        (WebInspector.ResourceSidebarTreeElement.prototype.createIconElement.):
+        (WebInspector.ResourceSidebarTreeElement.prototype.createIconElement):
+        * inspector/front-end/Settings.js: Added useDataURLForResourceImageIcons
+        * inspector/front-end/SourceView.js:
+        (WebInspector.SourceView.prototype.setupSourceFrameIfNeeded):
+
 2010-10-26  Pavel Feldman  <pfeldman@chromium.org>
 
         Reviewed by Timothy Hatcher.
index 107f156..10965da 100644 (file)
@@ -113,7 +113,7 @@ module core {
         [handler=Controller] void stopTimelineProfiler();
 
         [handler=Resource] void cachedResources(out Object resources);
-        [handler=Resource] void resourceContent(in unsigned long frameId, in String url, out String content);
+        [handler=Resource] void resourceContent(in unsigned long frameId, in String url, in boolean base64Encode, out String content);
         [notify] void identifierForInitialRequest(out long identifier, out String url, out Object loader, out boolean isMainResource);
         [notify] void willSendRequest(out long identifier, out double time, out Object request, out Object redirectResponse);
         [notify] void markResourceAsCached(out long identifier);
index ee7457b..c711974 100644 (file)
@@ -432,13 +432,15 @@ void InspectorResourceAgent::cachedResources(RefPtr<InspectorObject>* object)
     *object = buildObjectForFrameTree(m_page->mainFrame(), true);
 }
 
-void InspectorResourceAgent::resourceContent(unsigned long frameId, const String& url, String* content)
+void InspectorResourceAgent::resourceContent(unsigned long frameId, const String& url, bool base64Encode, String* content)
 {
-    RefPtr<InspectorArray> frameResources = InspectorArray::create();
     for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->traverseNext(m_page->mainFrame())) {
         if (reinterpret_cast<uintptr_t>(frame) != frameId)
             continue;
-        InspectorResourceAgent::resourceContent(frame, KURL(ParsedURLString, url), content);
+        if (base64Encode)
+            InspectorResourceAgent::resourceContentBase64(frame, KURL(ParsedURLString, url), content);
+        else
+            InspectorResourceAgent::resourceContent(frame, KURL(ParsedURLString, url), content);
         break;
     }
 }
index fe52a3a..8a54c89 100644 (file)
@@ -98,7 +98,7 @@ public:
 
     // Called from frontend 
     void cachedResources(RefPtr<InspectorObject>*);
-    void resourceContent(unsigned long frameID, const String& url, String* content);
+    void resourceContent(unsigned long frameID, const String& url, bool base64Encode, String* content);
 
 private:
     InspectorResourceAgent(Page* page, InspectorFrontend* frontend);
index 75361a2..ea73c39 100644 (file)
@@ -277,7 +277,7 @@ WebInspector.ExtensionServer.prototype = {
         var ids;
         var response = [];
 
-        function onContentAvailable(id, encoded, content)
+        function onContentAvailable(id, content, encoded)
         {
             var resourceContent = {
                 id: id,
@@ -301,10 +301,8 @@ WebInspector.ExtensionServer.prototype = {
             var resource = WebInspector.networkResources[id];
             if (!resource)
                 response.push(this._status.E_NOTFOUND(id));
-            else {
-                var encode = !WebInspector.Resource.Type.isTextType(resource.type);
-                WebInspector.getEncodedResourceContent(id, encode, onContentAvailable.bind(this, id, encode));
-            }
+            else
+                resource.getContent(onContentAvailable.bind(this, id));
         }
         if (response.length === ids.length)
             this._dispatchCallback(message.requestId, port, response);
@@ -451,8 +449,3 @@ WebInspector.addExtensions = function(extensions)
 }
 
 WebInspector.extensionServer = new WebInspector.ExtensionServer();
-
-WebInspector.getEncodedResourceContent = function(identifier, encode, callback)
-{
-    InspectorBackend.getResourceContent(identifier, encode, callback);
-}
index 06ca4a4..7cff056 100644 (file)
@@ -49,10 +49,14 @@ WebInspector.ImageView.prototype = {
 
         this.imagePreviewElement = document.createElement("img");
         this.imagePreviewElement.addStyleClass("resource-image-view");
-        this.imagePreviewElement.setAttribute("src", this.resource.url);
-
         this._container.appendChild(this.imagePreviewElement);
 
+        function onResourceContent(element, content)
+        {
+            this.imagePreviewElement.setAttribute("src", this.resource.contentURL);
+        }
+        this.resource.getContent(onResourceContent.bind(this));
+
         this._container = document.createElement("div");
         this._container.className = "info";
         this.contentElement.appendChild(this._container);
index e31ff0d..bec6056 100644 (file)
@@ -1462,7 +1462,15 @@ WebInspector.NetworkDataGridNode.prototype = {
         if (this._resource.category === WebInspector.resourceCategories.images) {
             var previewImage = document.createElement("img");
             previewImage.className = "image-network-icon-preview";
-            previewImage.src = this._resource.url;
+
+            function onResourceContent()
+            {
+                previewImage.src = this._resource.contentURL;
+            }
+            if (Preferences.useDataURLForResourceImageIcons)
+                this._resource.getContent(onResourceContent.bind(this));
+            else
+                previewImage.src = this._resource.url;
 
             var iconElement = document.createElement("div");
             iconElement.className = "icon";
index 817af0e..c1385a7 100644 (file)
@@ -34,6 +34,7 @@ WebInspector.Resource = function(identifier, url)
     this._endTime = -1;
     this._requestMethod = "";
     this._category = WebInspector.resourceCategories.other;
+    this._pendingContentCallbacks = [];
 }
 
 // Keep these in sync with WebCore::InspectorResource::Type
@@ -254,6 +255,8 @@ WebInspector.Resource.prototype = {
         if (x) {
             this._checkWarnings();
             this.dispatchEventToListeners("finished");
+            if (this._pendingContentCallbacks.length)
+                this._requestContent();
         }
     },
 
@@ -597,9 +600,43 @@ WebInspector.Resource.prototype = {
             WebInspector.console.addMessage(msg);
     },
 
-    getContents: function(callback)
+    getContent: function(callback)
     {
-        WebInspector.ResourceManager.getContents(this, callback);
+        if (this._content) {
+            callback(this._content, this._contentEncoded);
+            return;
+        }
+        this._pendingContentCallbacks.push(callback);
+        if (this.finished)
+            this._requestContent();
+    },
+
+    get contentURL()
+    {
+        const maxDataUrlSize = 1024 * 1024;
+        // If resource content is not available or won't fit a data URL, fall back to using original URL.
+        if (!this._content || this._content.length > maxDataUrlSize)
+            return this.url;
+
+        return "data:" + this.mimeType + (this._contentEncoded ? ";base64," : ",") + this._content;
+    },
+
+    _requestContent: function()
+    {
+        if (this._contentRequested)
+            return;
+        this._contentRequested = true;
+        this._contentEncoded = !WebInspector.Resource.Type.isTextType(this.type);
+
+        function onResourceContent(data)
+        {
+            this._content = data;
+            var callbacks = this._pendingContentCallbacks.slice();
+            for (var i = 0; i < callbacks.length; ++i)
+                callbacks[i](this._content, this._contentEncoded);
+            this._pendingContentCallbacks.length = 0;
+        }
+        WebInspector.ResourceManager.getContent(this, this._contentEncoded, onResourceContent.bind(this));
     }
 }
 
index 8eb7f04..0533ec5 100644 (file)
@@ -407,7 +407,7 @@ WebInspector.ResourceManager.existingResourceViewForResource = function(resource
     return resource._resourcesView;
 }
 
-WebInspector.ResourceManager.getContents = function(resource, callback)
+WebInspector.ResourceManager.getContent = function(resource, base64Encode, callback)
 {
     if ("overridenContent" in resource) {
         callback(resource.overridenContent);
@@ -416,9 +416,9 @@ WebInspector.ResourceManager.getContents = function(resource, callback)
 
     // FIXME: eventually, cached resources will have no identifiers.
     if (resource.loader)
-        InspectorBackend.resourceContent(resource.loader.frameId, resource.url, callback);
+        InspectorBackend.resourceContent(resource.loader.frameId, resource.url, base64Encode, callback);
     else
-        InspectorBackend.getResourceContent(resource.identifier, false, callback);
+        InspectorBackend.getResourceContent(resource.identifier, base64Encode, callback);
 }
 
 WebInspector.ResourceTreeModel = function()
index cba0cae..48c49dd 100644 (file)
@@ -1666,7 +1666,15 @@ WebInspector.ResourceSidebarTreeElement.prototype = {
         if (this.resource.category === WebInspector.resourceCategories.images) {
             var previewImage = document.createElement("img");
             previewImage.className = "image-resource-icon-preview";
-            previewImage.src = this.resource.url;
+
+            function onResourceContent()
+            {
+                previewImage.src = this.resource.contentURL;
+            }
+            if (Preferences.useDataURLForResourceImageIcons)
+                this.resource.getContent(onResourceContent.bind(this));
+            else
+                previewImage.src = this.resource.url;
 
             this.iconElement = document.createElement("div");
             this.iconElement.className = "icon";
index c6da14d..c22cf71 100644 (file)
@@ -45,7 +45,8 @@ var Preferences = {
     onlineDetectionEnabled: true,
     nativeInstrumentationEnabled: false,
     resourceExportEnabled: false,
-    networkPanelEnabled: false
+    networkPanelEnabled: false,
+    useDataURLForResourceImageIcons: true
 }
 
 WebInspector.Settings = function(sessionScope)
index 8092505..8f024bc 100644 (file)
@@ -83,7 +83,7 @@ WebInspector.SourceView.prototype = {
         this.attach();
 
         delete this._frameNeedsSetup;
-        this.resource.getContents(this._contentLoaded.bind(this));
+        this.resource.getContent(this._contentLoaded.bind(this));
     },
 
     hasContentTab: function()