2011-06-09 Jay Civelli <jcivelli@chromium.org>
authorjcivelli@chromium.org <jcivelli@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Jun 2011 21:45:18 +0000 (21:45 +0000)
committerjcivelli@chromium.org <jcivelli@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Jun 2011 21:45:18 +0000 (21:45 +0000)
        Reviewed by Darin Fisher.

        Page serializer APIs now use WebData instead of fetching the entire
        resource contents.
        https://bugs.webkit.org/show_bug.cgi?id=61908

        * public/WebData.h:
        * public/WebPageSerializer.h:
        * src/WebData.cpp:
        (WebKit::WebData::getSomeData):
        * src/WebPageSerializer.cpp:
        (WebKit::WebPageSerializer::serialize):
        (WebKit::WebPageSerializer::serializeToMHTML):

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

Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/public/WebData.h
Source/WebKit/chromium/public/WebPageSerializer.h
Source/WebKit/chromium/src/WebData.cpp
Source/WebKit/chromium/src/WebPageSerializer.cpp

index 7106fddb9e0d769a02ab0308eb5c58ba4cb6f329..747c5dc51df6bae537eb4abc02d8e68bd2aa21d2 100755 (executable)
@@ -1,3 +1,19 @@
+2011-06-09  Jay Civelli  <jcivelli@chromium.org>
+
+        Reviewed by Darin Fisher.
+
+        Page serializer APIs now use WebData instead of fetching the entire
+        resource contents.
+        https://bugs.webkit.org/show_bug.cgi?id=61908
+
+        * public/WebData.h:
+        * public/WebPageSerializer.h:
+        * src/WebData.cpp:
+        (WebKit::WebData::getSomeData):
+        * src/WebPageSerializer.cpp:
+        (WebKit::WebPageSerializer::serialize):
+        (WebKit::WebPageSerializer::serializeToMHTML):
+
 2011-06-09  Bill Budge  <bbudge@chromium.org>
 
         Reviewed by Adam Barth.
index 5874bed31682395760822957245783c38c75e668..dd72901f3b8034a70a8a8f744e8de8be2b78b6e8 100644 (file)
@@ -76,6 +76,22 @@ public:
     WEBKIT_API void assign(const char* data, size_t size);
 
     WEBKIT_API size_t size() const;
+
+    // Sets |data| to point to the content of the WebData at index |position|
+    // and returns the number of bytes available to be read in |data|.
+    // Return 0 when no more data is left.
+    // Usage:
+    //      const char* segment;
+    //      size_t position = 0;
+    //      while (size_t length = webData.getSomeData(segment, position)) {
+    //          // Use the data. for example: decoder->decode(segment, length);
+    //          position += length;
+    //      }
+    WEBKIT_API size_t getSomeData(const char*& data, size_t position) const;
+
+    // Returns all the data from the SharedBuffer.
+    // Consider using getSomeData() as data() could require flattening the internal buffer
+    // which might be expensive.
     WEBKIT_API const char* data() const;
 
     bool isEmpty() const { return !size(); }
index e2db07be418057b0e86d2a5c8068787dd0bcfe79..c9dc9db577551c05aca50feb82ef794895662881 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "WebCString.h"
 #include "WebCommon.h"
+#include "WebData.h"
 #include "WebURL.h"
 
 namespace WebKit {
@@ -49,7 +50,7 @@ public:
     struct Resource {
         WebURL url;
         WebCString mimeType;
-        WebCString data;
+        WebData data;
     };
 
     // Serializes all the frames from the WebView, retrieves the page's
@@ -59,7 +60,7 @@ public:
     WEBKIT_API static void serialize(WebView*, WebVector<Resource>*);
 
     // Serializes the WebView contents to a MHTML representation.
-    WEBKIT_API static WebCString serializeToMHTML(WebView*);
+    WEBKIT_API static WebData serializeToMHTML(WebView*);
 
     // IMPORTANT:
     // The API below is an older implementation of a pageserialization that
index 6aafe796dd3bee9fcab2a79cce4eded8a080fc97..7ef0228b16a8eedfe4e854e5abc2d8bee7c5c4a9 100644 (file)
@@ -69,6 +69,11 @@ size_t WebData::size() const
     return const_cast<WebDataPrivate*>(m_private)->size();
 }
 
+size_t WebData::getSomeData(const char*& data, size_t position) const
+{
+    return m_private->getSomeData(data, position);
+}
+
 const char* WebData::data() const
 {
     if (!m_private)
index 6df84bb6b96a8dd34c2686e2066128d7e0ff5bbd..cd0aec7e439fb018d055a3b1a972f6524c6c702e 100644 (file)
@@ -193,19 +193,15 @@ void WebPageSerializer::serialize(WebView* view, WebVector<WebPageSerializer::Re
         Resource resource;
         resource.url = iter->url;
         resource.mimeType = iter->mimeType.ascii();
-        // FIXME: we are copying all the resource data here. Idealy we would have a WebSharedData().
-        resource.data = WebCString(iter->data->data(), iter->data->size());
+        resource.data = iter->data;
         result.append(resource);
     }
-
     *resourcesParam = result;         
 }
 
-WebCString WebPageSerializer::serializeToMHTML(WebView* view)
+WebData WebPageSerializer::serializeToMHTML(WebView* view)
 {
-    RefPtr<SharedBuffer> mhtml = MHTMLArchive::generateMHTMLData(static_cast<WebViewImpl*>(view)->page());
-    // FIXME: we are copying all the data here. Idealy we would have a WebSharedData().
-    return WebCString(mhtml->data(), mhtml->size());
+    return MHTMLArchive::generateMHTMLData(static_cast<WebViewImpl*>(view)->page());
 }
 
 bool WebPageSerializer::serialize(WebFrame* frame,