2011-02-09 Andrey Kosyakov <caseq@chromium.org>
authorcaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Feb 2011 12:36:37 +0000 (12:36 +0000)
committercaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Feb 2011 12:36:37 +0000 (12:36 +0000)
        Reviewed by Pavel Feldman.

        Web Inspector: Network & Resource panels make multiple requests for images with no content
        https://bugs.webkit.org/show_bug.cgi?id=54085

        - Added success parameter to resourceContent
        - NetworkManager.requestContent() now returns empty for zero-length resources, null for errors

        * inspector/Inspector.idl:
        * inspector/InspectorResourceAgent.cpp:
        (WebCore::InspectorResourceAgent::resourceData):
        (WebCore::InspectorResourceAgent::resourceContent):
        * inspector/InspectorResourceAgent.h:
        * inspector/front-end/NetworkManager.js:
        (WebInspector.NetworkManager.prototype.requestContent):
        * inspector/front-end/Resource.js:
        (WebInspector.Resource.prototype.requestContent):
        (WebInspector.Resource.prototype._contentURL):

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

Source/WebCore/ChangeLog
Source/WebCore/inspector/Inspector.idl
Source/WebCore/inspector/InspectorResourceAgent.cpp
Source/WebCore/inspector/InspectorResourceAgent.h
Source/WebCore/inspector/front-end/NetworkManager.js
Source/WebCore/inspector/front-end/Resource.js

index 3f7a2cc..fe31940 100644 (file)
@@ -1,3 +1,24 @@
+2011-02-09  Andrey Kosyakov  <caseq@chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        Web Inspector: Network & Resource panels make multiple requests for images with no content
+        https://bugs.webkit.org/show_bug.cgi?id=54085
+
+        - Added success parameter to resourceContent
+        - NetworkManager.requestContent() now returns empty for zero-length resources, null for errors
+
+        * inspector/Inspector.idl:
+        * inspector/InspectorResourceAgent.cpp:
+        (WebCore::InspectorResourceAgent::resourceData):
+        (WebCore::InspectorResourceAgent::resourceContent):
+        * inspector/InspectorResourceAgent.h:
+        * inspector/front-end/NetworkManager.js:
+        (WebInspector.NetworkManager.prototype.requestContent):
+        * inspector/front-end/Resource.js:
+        (WebInspector.Resource.prototype.requestContent):
+        (WebInspector.Resource.prototype._contentURL):
+
 2011-02-10  Renata Hodovan  <reni@webkit.org>
 
         Reviewed by Dirk Schulze.
index ea0f480..8a08715 100644 (file)
@@ -100,7 +100,7 @@ module core {
         ///////////////////////////////////////////////////////////////////////
 
         [domain=Network] void cachedResources(out Object resources);
-        [domain=Network] void resourceContent(in unsigned long frameId, in String url, in boolean base64Encode, out String content);
+        [domain=Network] void resourceContent(in unsigned long frameId, in String url, in boolean base64Encode, out boolean success, out String content);
         [domain=Network] void setExtraHeaders(in Object headers);
 
         [notify, domain=Network] void frameDetachedFromParent(out unsigned long frameId);
index 3a69eef..38d9e32 100644 (file)
@@ -124,6 +124,10 @@ PassRefPtr<SharedBuffer> InspectorResourceAgent::resourceData(Frame* frame, cons
     if (!cachedResource)
         return 0;
 
+    // Zero-sized resources don't have data at all -- so fake the empty buffer, insted of indicating error by returning 0.
+    if (!cachedResource->encodedSize())
+        return SharedBuffer::create();
+
     if (cachedResource->isPurgeable()) {
         // If the resource is purgeable then make it unpurgeable to get
         // get its data. This might fail, in which case we return an
@@ -499,17 +503,17 @@ void InspectorResourceAgent::cachedResources(RefPtr<InspectorObject>* object)
     *object = buildObjectForFrameTree(m_page->mainFrame(), true);
 }
 
-void InspectorResourceAgent::resourceContent(unsigned long id, const String& url, bool base64Encode, String* content)
+void InspectorResourceAgent::resourceContent(unsigned long frameId, const String& url, bool base64Encode, bool* success, String* content)
 {
-    for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->traverseNext(m_page->mainFrame())) {
-        if (frameId(frame) != id)
-            continue;
-        if (base64Encode)
-            InspectorResourceAgent::resourceContentBase64(frame, KURL(ParsedURLString, url), content);
-        else
-            InspectorResourceAgent::resourceContent(frame, KURL(ParsedURLString, url), content);
-        break;
+    Frame* frame = frameForId(frameId);
+    if (!frame) {
+        *success = false;
+        return;
     }
+    if (base64Encode)
+        *success = InspectorResourceAgent::resourceContentBase64(frame, KURL(ParsedURLString, url), content);
+    else
+        *success = InspectorResourceAgent::resourceContent(frame, KURL(ParsedURLString, url), content);
 }
 
 InspectorResourceAgent::InspectorResourceAgent(Page* page, InspectorState* state, InspectorFrontend* frontend)
index 23dbeee..fb24b70 100644 (file)
@@ -103,7 +103,7 @@ public:
 
     // Called from frontend 
     void cachedResources(RefPtr<InspectorObject>*);
-    void resourceContent(unsigned long frameID, const String& url, bool base64Encode, String* content);
+    void resourceContent(unsigned long frameId, const String& url, bool base64Encode, bool* resourceFound, String* content);
     void setExtraHeaders(PassRefPtr<InspectorObject>);
 
 private:
index d2452df..da043fe 100644 (file)
@@ -53,7 +53,11 @@ WebInspector.NetworkManager.prototype = {
 
     requestContent: function(resource, base64Encode, callback)
     {
-        InspectorBackend.resourceContent(resource.loader.frameId, resource.url, base64Encode, callback);
+        function callbackWrapper(success, content)
+        {
+            callback(success ? content : null);
+        }
+        InspectorBackend.resourceContent(resource.loader.frameId, resource.url, base64Encode, callbackWrapper);
     },
 
     _processCachedResources: function(mainFramePayload)
index 9108d2d..6cf5b9c 100644 (file)
@@ -693,8 +693,8 @@ WebInspector.Resource.prototype = {
             callback(null, null);
             return;
         }
-        if (this._content) {
-            callback(this._content, this._contentEncoded);
+        if (typeof this._content !== "undefined") {
+            callback(this.content, this._contentEncoded);
             return;
         }
         this._pendingContentCallbacks.push(callback);
@@ -719,7 +719,7 @@ WebInspector.Resource.prototype = {
     {
         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)
+        if (this._content == null || this._content.length > maxDataUrlSize)
             return this.url;
 
         return "data:" + this.mimeType + (this._contentEncoded ? ";base64," : ",") + this._content;