Track the NPN protocol version negotiated with the server
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 19 Feb 2012 06:25:41 +0000 (06:25 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 19 Feb 2012 06:25:41 +0000 (06:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=77349

Source/WebCore:

Patch by raman Tenneti <rtenneti@chromium.org> on 2012-02-18
Reviewed by Darin Fisher..

[chromium] Added ExtraData to WebURLResponse.

No intended functionality change.

* platform/network/chromium/ResourceResponse.h:
(ExtraData):
(WebCore::ResourceResponse::ExtraData::~ExtraData):
(ResourceResponse):
(WebCore::ResourceResponse::extraData):
(WebCore::ResourceResponse::setExtraData):

Source/WebKit/chromium:

Patch by raman Tenneti <rtenneti@chromium.org> on 2012-02-18
Reviewed by Darin Fisher.

[chromium] Added ExtraData to WebURLResponse.

* WebKit.gypi:
* public/platform/WebURLResponse.h:
(ExtraData):
(WebKit::WebURLResponse::ExtraData::~ExtraData):
(WebURLResponse):
* src/WebURLResponse.cpp:
(WebKit::WebURLResponse::extraData):
(WebKit):
(WebKit::WebURLResponse::setExtraData):
* tests/WebURLResponseTest.cpp: Added.
(WebKit):
(TestExtraData):
(WebKit::TestExtraData::TestExtraData):
(WebKit::TestExtraData::~TestExtraData):
(WebKit::TEST):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/network/chromium/ResourceResponse.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/WebKit.gypi
Source/WebKit/chromium/public/platform/WebURLResponse.h
Source/WebKit/chromium/src/WebURLResponse.cpp
Source/WebKit/chromium/tests/WebURLResponseTest.cpp [new file with mode: 0644]

index 4e4cced..f497a88 100644 (file)
@@ -1,3 +1,21 @@
+2012-02-18  raman Tenneti  <rtenneti@chromium.org>
+
+        Track the NPN protocol version negotiated with the server
+        https://bugs.webkit.org/show_bug.cgi?id=77349
+
+        Reviewed by Darin Fisher..
+
+        [chromium] Added ExtraData to WebURLResponse.
+        
+        No intended functionality change.
+
+        * platform/network/chromium/ResourceResponse.h:
+        (ExtraData):
+        (WebCore::ResourceResponse::ExtraData::~ExtraData):
+        (ResourceResponse):
+        (WebCore::ResourceResponse::extraData):
+        (WebCore::ResourceResponse::setExtraData):
+
 2012-02-18  Abhishek Arya  <inferno@chromium.org>
 
         Unreviewed, rolling out r107965.
index a2a8c5d..997cd71 100644 (file)
@@ -36,6 +36,11 @@ namespace WebCore {
 
     class ResourceResponse : public ResourceResponseBase {
     public:
+        class ExtraData : public RefCounted<ExtraData> {
+        public:
+            virtual ~ExtraData() { }
+        };
+
         ResourceResponse()
             : m_appCacheID(0)
             , m_isMultipartPayload(false)
@@ -103,6 +108,10 @@ namespace WebCore {
         const File* downloadedFile() const { return m_downloadedFile.get(); }
         void setDownloadedFile(PassRefPtr<File> downloadedFile) { m_downloadedFile = downloadedFile; }
 
+        // Extra data associated with this response.
+        ExtraData* extraData() const { return m_extraData.get(); }
+        void setExtraData(PassRefPtr<ExtraData> extraData) { m_extraData = extraData; }
+
     private:
         friend class ResourceResponseBase;
 
@@ -155,6 +164,9 @@ namespace WebCore {
 
         // The downloaded file if the load streamed to a file.
         RefPtr<File> m_downloadedFile;
+
+        // ExtraData associated with the response.
+        RefPtr<ExtraData> m_extraData;
     };
 
     struct CrossThreadResourceResponseData : public CrossThreadResourceResponseDataBase {
index dc132f3..cccbfce 100644 (file)
@@ -1,3 +1,28 @@
+2012-02-18  raman Tenneti  <rtenneti@chromium.org>
+
+        Track the NPN protocol version negotiated with the server
+        https://bugs.webkit.org/show_bug.cgi?id=77349
+
+        Reviewed by Darin Fisher.
+
+        [chromium] Added ExtraData to WebURLResponse.
+
+        * WebKit.gypi:
+        * public/platform/WebURLResponse.h:
+        (ExtraData):
+        (WebKit::WebURLResponse::ExtraData::~ExtraData):
+        (WebURLResponse):
+        * src/WebURLResponse.cpp:
+        (WebKit::WebURLResponse::extraData):
+        (WebKit):
+        (WebKit::WebURLResponse::setExtraData):
+        * tests/WebURLResponseTest.cpp: Added.
+        (WebKit):
+        (TestExtraData):
+        (WebKit::TestExtraData::TestExtraData):
+        (WebKit::TestExtraData::~TestExtraData):
+        (WebKit::TEST):
+
 2012-02-17  Joshua Bell  <jsbell@chromium.org>
 
         IndexedDB: Support overloaded methods that take IDBKey or IDBKeyRange
index 35f2b19..fcd09c4 100644 (file)
             'tests/WebPageSerializerTest.cpp',
             'tests/WebSocketExtensionDispatcherTest.cpp',
             'tests/WebURLRequestTest.cpp',
+            'tests/WebURLResponseTest.cpp',
             'tests/WebViewTest.cpp',
         ],
 
index 8629b84..8d53eac 100644 (file)
@@ -50,6 +50,11 @@ class WebURLResponsePrivate;
 
 class WebURLResponse {
 public:
+    class ExtraData {
+    public:
+        virtual ~ExtraData() { }
+    };
+
     ~WebURLResponse() { reset(); }
 
     WebURLResponse() : m_private(0) { }
@@ -174,6 +179,15 @@ public:
     WEBKIT_EXPORT unsigned short remotePort() const;
     WEBKIT_EXPORT void setRemotePort(unsigned short);
 
+    // Extra data associated with the underlying resource response. Resource
+    // responses can be copied. If non-null, each copy of a resource response
+    // holds a pointer to the extra data, and the extra data pointer will be
+    // deleted when the last resource response is destroyed. Setting the extra
+    // data pointer will cause the underlying resource response to be
+    // dissociated from any existing non-null extra data pointer.
+    WEBKIT_EXPORT ExtraData* extraData() const;
+    WEBKIT_EXPORT void setExtraData(ExtraData*);
+
 protected:
     void assign(WebURLResponsePrivate*);
 
index 2eacda5..ec212e5 100644 (file)
@@ -47,6 +47,27 @@ using namespace WebCore;
 
 namespace WebKit {
 
+namespace {
+
+class ExtraDataContainer : public ResourceResponse::ExtraData {
+public:
+    static PassRefPtr<ExtraDataContainer> create(WebURLResponse::ExtraData* extraData) { return adoptRef(new ExtraDataContainer(extraData)); }
+
+    virtual ~ExtraDataContainer() { }
+
+    WebURLResponse::ExtraData* extraData() const { return m_extraData.get(); }
+
+private:
+    explicit ExtraDataContainer(WebURLResponse::ExtraData* extraData)
+        : m_extraData(adoptPtr(extraData))
+    {
+    }
+
+    OwnPtr<WebURLResponse::ExtraData> m_extraData;
+};
+
+} // namespace
+
 // The standard implementation of WebURLResponsePrivate, which maintains
 // ownership of a ResourceResponse instance.
 class WebURLResponsePrivateImpl : public WebURLResponsePrivate {
@@ -399,6 +420,19 @@ void WebURLResponse::setRemotePort(unsigned short remotePort)
     m_private->m_resourceResponse->setRemotePort(remotePort);
 }
 
+WebURLResponse::ExtraData* WebURLResponse::extraData() const
+{
+    RefPtr<ResourceResponse::ExtraData> data = m_private->m_resourceResponse->extraData();
+    if (!data)
+        return 0;
+    return static_cast<ExtraDataContainer*>(data.get())->extraData();
+}
+
+void WebURLResponse::setExtraData(WebURLResponse::ExtraData* extraData)
+{
+    m_private->m_resourceResponse->setExtraData(ExtraDataContainer::create(extraData));
+}
+
 void WebURLResponse::assign(WebURLResponsePrivate* p)
 {
     // Subclasses may call this directly so a self-assignment check is needed
diff --git a/Source/WebKit/chromium/tests/WebURLResponseTest.cpp b/Source/WebKit/chromium/tests/WebURLResponseTest.cpp
new file mode 100644 (file)
index 0000000..112ed86
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "platform/WebURLResponse.h"
+
+#include <gtest/gtest.h>
+
+using namespace WebKit;
+
+namespace {
+
+class TestExtraData : public WebURLResponse::ExtraData {
+public:
+    explicit TestExtraData(bool* alive)
+        : m_alive(alive)
+    {
+        *alive = true;
+    }
+
+    virtual ~TestExtraData() { *m_alive = false; }
+
+private:
+    bool* m_alive;
+};
+
+TEST(WebURLResponseTest, ExtraData)
+{
+    bool alive = false;
+    {
+        WebURLResponse urlResponse;
+        TestExtraData* extraData = new TestExtraData(&alive);
+        EXPECT_TRUE(alive);
+
+        urlResponse.initialize();
+        urlResponse.setExtraData(extraData);
+        EXPECT_EQ(extraData, urlResponse.extraData());
+        {
+            WebURLResponse otherUrlResponse = urlResponse;
+            EXPECT_TRUE(alive);
+            EXPECT_EQ(extraData, otherUrlResponse.extraData());
+            EXPECT_EQ(extraData, urlResponse.extraData());
+        }
+        EXPECT_TRUE(alive);
+        EXPECT_EQ(extraData, urlResponse.extraData());
+    }
+    EXPECT_FALSE(alive);
+}
+
+} // namespace