<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[168054] trunk/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/168054">168054</a></dd>
<dt>Author</dt> <dd>ap@apple.com</dd>
<dt>Date</dt> <dd>2014-04-30 15:52:30 -0700 (Wed, 30 Apr 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Move Blob.slice() implementation into BlobRegistryImpl
https://bugs.webkit.org/show_bug.cgi?id=132402

Reviewed by Anders Carlsson.


Source/WebCore: 
Part or centralizing the responsibility for file size tracking.

* fileapi/Blob.cpp:
(WebCore::Blob::Blob):
(WebCore::Blob::slice): Deleted.
* fileapi/Blob.h:
(WebCore::Blob::slice):
* fileapi/ThreadableBlobRegistry.cpp:
(WebCore::ThreadableBlobRegistry::registerBlobURL):
(WebCore::ThreadableBlobRegistry::registerBlobURLForSlice):
(WebCore::registerBlobURLTask): Deleted.
(WebCore::registerBlobURLFromTask): Deleted.
* fileapi/ThreadableBlobRegistry.h:
* platform/network/BlobRegistry.h:
* platform/network/BlobRegistryImpl.cpp:
(WebCore::BlobRegistryImpl::appendStorageItems):
(WebCore::BlobRegistryImpl::registerBlobURLForSlice):
(WebCore::BlobRegistryImpl::blobSize):
* platform/network/BlobRegistryImpl.h:

Source/WebKit2: 
* NetworkProcess/FileAPI/NetworkBlobRegistry.cpp:
(WebKit::NetworkBlobRegistry::registerBlobURLForSlice):
* NetworkProcess/FileAPI/NetworkBlobRegistry.h:
* NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::NetworkConnectionToWebProcess::registerBlobURLForSlice):
* NetworkProcess/NetworkConnectionToWebProcess.h:
* NetworkProcess/NetworkConnectionToWebProcess.messages.in:
* WebProcess/FileAPI/BlobRegistryProxy.cpp:
(WebKit::BlobRegistryProxy::registerBlobURLForSlice):
* WebProcess/FileAPI/BlobRegistryProxy.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorefileapiBlobcpp">trunk/Source/WebCore/fileapi/Blob.cpp</a></li>
<li><a href="#trunkSourceWebCorefileapiBlobh">trunk/Source/WebCore/fileapi/Blob.h</a></li>
<li><a href="#trunkSourceWebCorefileapiThreadableBlobRegistrycpp">trunk/Source/WebCore/fileapi/ThreadableBlobRegistry.cpp</a></li>
<li><a href="#trunkSourceWebCorefileapiThreadableBlobRegistryh">trunk/Source/WebCore/fileapi/ThreadableBlobRegistry.h</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkBlobRegistryh">trunk/Source/WebCore/platform/network/BlobRegistry.h</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkBlobRegistryImplcpp">trunk/Source/WebCore/platform/network/BlobRegistryImpl.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkBlobRegistryImplh">trunk/Source/WebCore/platform/network/BlobRegistryImpl.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcessFileAPINetworkBlobRegistrycpp">trunk/Source/WebKit2/NetworkProcess/FileAPI/NetworkBlobRegistry.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcessFileAPINetworkBlobRegistryh">trunk/Source/WebKit2/NetworkProcess/FileAPI/NetworkBlobRegistry.h</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcessNetworkConnectionToWebProcesscpp">trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcessNetworkConnectionToWebProcessh">trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.h</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcessNetworkConnectionToWebProcessmessagesin">trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.messages.in</a></li>
<li><a href="#trunkSourceWebKit2WebProcessFileAPIBlobRegistryProxycpp">trunk/Source/WebKit2/WebProcess/FileAPI/BlobRegistryProxy.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessFileAPIBlobRegistryProxyh">trunk/Source/WebKit2/WebProcess/FileAPI/BlobRegistryProxy.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (168053 => 168054)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-04-30 22:45:36 UTC (rev 168053)
+++ trunk/Source/WebCore/ChangeLog        2014-04-30 22:52:30 UTC (rev 168054)
</span><span class="lines">@@ -1,3 +1,30 @@
</span><ins>+2014-04-30  Alexey Proskuryakov  &lt;ap@apple.com&gt;
+
+        Move Blob.slice() implementation into BlobRegistryImpl
+        https://bugs.webkit.org/show_bug.cgi?id=132402
+
+        Reviewed by Anders Carlsson.
+
+        Part or centralizing the responsibility for file size tracking.
+
+        * fileapi/Blob.cpp:
+        (WebCore::Blob::Blob):
+        (WebCore::Blob::slice): Deleted.
+        * fileapi/Blob.h:
+        (WebCore::Blob::slice):
+        * fileapi/ThreadableBlobRegistry.cpp:
+        (WebCore::ThreadableBlobRegistry::registerBlobURL):
+        (WebCore::ThreadableBlobRegistry::registerBlobURLForSlice):
+        (WebCore::registerBlobURLTask): Deleted.
+        (WebCore::registerBlobURLFromTask): Deleted.
+        * fileapi/ThreadableBlobRegistry.h:
+        * platform/network/BlobRegistry.h:
+        * platform/network/BlobRegistryImpl.cpp:
+        (WebCore::BlobRegistryImpl::appendStorageItems):
+        (WebCore::BlobRegistryImpl::registerBlobURLForSlice):
+        (WebCore::BlobRegistryImpl::blobSize):
+        * platform/network/BlobRegistryImpl.h:
+
</ins><span class="cx"> 2014-04-30  Brent Fulgham  &lt;bfulgham@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed build fix after r168041.
</span></span></pre></div>
<a id="trunkSourceWebCorefileapiBlobcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/fileapi/Blob.cpp (168053 => 168054)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/fileapi/Blob.cpp        2014-04-30 22:45:36 UTC (rev 168053)
+++ trunk/Source/WebCore/fileapi/Blob.cpp        2014-04-30 22:52:30 UTC (rev 168054)
</span><span class="lines">@@ -97,6 +97,16 @@
</span><span class="cx">     ThreadableBlobRegistry::registerBlobURL(0, m_internalURL, srcURL);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if ENABLE(BLOB)
+Blob::Blob(const URL&amp; srcURL, long long start, long long end, const String&amp; type)
+    : m_type(Blob::normalizedContentType(type))
+{
+    // Create a new internal URL and register it with the same blob data as the source URL.
+    m_internalURL = BlobURL::createInternalURL();
+    m_size = ThreadableBlobRegistry::registerBlobURLForSlice(m_internalURL, srcURL, start, end);
+}
+#endif
+
</ins><span class="cx"> Blob::~Blob()
</span><span class="cx"> {
</span><span class="cx">     ThreadableBlobRegistry::unregisterBlobURL(m_internalURL);
</span><span class="lines">@@ -170,52 +180,6 @@
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#if ENABLE(BLOB)
-PassRefPtr&lt;Blob&gt; Blob::slice(long long start, long long end, const String&amp; contentType) const
-{
-    // When we slice a file for the first time, we obtain a snapshot of the file by capturing its current size and modification time.
-    // The modification time will be used to verify if the file has been changed or not, when the underlying data are accessed.
-    long long size;
-    double modificationTime;
-    if (isFile()) {
-        // FIXME: This involves synchronous file operation. We need to figure out how to make it asynchronous.
-        toFile(this)-&gt;captureSnapshot(size, modificationTime);
-    } else {
-        ASSERT(m_size != -1);
-        size = m_size;
-    }
-
-    // Convert the negative value that is used to select from the end.
-    if (start &lt; 0)
-        start = start + size;
-    if (end &lt; 0)
-        end = end + size;
-
-    // Clamp the range if it exceeds the size limit.
-    if (start &lt; 0)
-        start = 0;
-    if (end &lt; 0)
-        end = 0;
-    if (start &gt;= size) {
-        start = 0;
-        end = 0;
-    } else if (end &lt; start)
-        end = start;
-    else if (end &gt; size)
-        end = size;
-
-    long long length = end - start;
-    auto blobData = std::make_unique&lt;BlobData&gt;();
-    blobData-&gt;setContentType(Blob::normalizedContentType(contentType));
-    if (isFile())
-        blobData-&gt;appendFile(toFile(this)-&gt;path(), start, length, modificationTime);
-    else
-        blobData-&gt;appendBlob(m_internalURL, start, length);
-
-    return Blob::create(std::move(blobData), length);
-}
-#endif
-
</del><span class="cx"> URLRegistry&amp; Blob::registry() const
</span><span class="cx"> {
</span><span class="cx">     return BlobURLRegistry::registry();
</span></span></pre></div>
<a id="trunkSourceWebCorefileapiBlobh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/fileapi/Blob.h (168053 => 168054)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/fileapi/Blob.h        2014-04-30 22:45:36 UTC (rev 168053)
+++ trunk/Source/WebCore/fileapi/Blob.h        2014-04-30 22:52:30 UTC (rev 168054)
</span><span class="lines">@@ -82,7 +82,10 @@
</span><span class="cx">     virtual URLRegistry&amp; registry() const override;
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(BLOB)
</span><del>-    PassRefPtr&lt;Blob&gt; slice(long long start = 0, long long end = std::numeric_limits&lt;long long&gt;::max(), const String&amp; contentType = String()) const;
</del><ins>+    PassRefPtr&lt;Blob&gt; slice(long long start = 0, long long end = std::numeric_limits&lt;long long&gt;::max(), const String&amp; contentType = String()) const
+    {
+        return adoptRef(new Blob(m_internalURL, start, end, contentType));
+    }
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> protected:
</span><span class="lines">@@ -92,6 +95,11 @@
</span><span class="cx">     // For deserialization.
</span><span class="cx">     Blob(const URL&amp; srcURL, const String&amp; type, long long size);
</span><span class="cx"> 
</span><ins>+#if ENABLE(BLOB)
+    // For slicing.
+    Blob(const URL&amp; srcURL, long long start, long long end, const String&amp; contentType);
+#endif
+
</ins><span class="cx">     // This is an internal URL referring to the blob data associated with this object. It serves
</span><span class="cx">     // as an identifier for this blob. The internal URL is never used to source the blob's content
</span><span class="cx">     // into an HTML or for FileRead'ing, public blob URLs must be used for those purposes.
</span></span></pre></div>
<a id="trunkSourceWebCorefileapiThreadableBlobRegistrycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/fileapi/ThreadableBlobRegistry.cpp (168053 => 168054)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/fileapi/ThreadableBlobRegistry.cpp        2014-04-30 22:45:36 UTC (rev 168053)
+++ trunk/Source/WebCore/fileapi/ThreadableBlobRegistry.cpp        2014-04-30 22:52:30 UTC (rev 168054)
</span><span class="lines">@@ -41,6 +41,7 @@
</span><span class="cx"> #include &lt;wtf/RefPtr.h&gt;
</span><span class="cx"> #include &lt;wtf/ThreadSpecific.h&gt;
</span><span class="cx"> #include &lt;wtf/text/StringHash.h&gt;
</span><ins>+#include &lt;wtf/threads/BinarySemaphore.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> using WTF::ThreadSpecific;
</span><span class="cx"> 
</span><span class="lines">@@ -87,26 +88,20 @@
</span><span class="cx">     return *map;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void registerBlobURLTask(void* context)
-{
-    std::unique_ptr&lt;BlobRegistryContext&gt; blobRegistryContext(static_cast&lt;BlobRegistryContext*&gt;(context));
-    blobRegistry().registerBlobURL(blobRegistryContext-&gt;url, std::move(blobRegistryContext-&gt;blobData));
-}
-
</del><span class="cx"> void ThreadableBlobRegistry::registerBlobURL(const URL&amp; url, std::unique_ptr&lt;BlobData&gt; blobData)
</span><span class="cx"> {
</span><span class="cx">     if (isMainThread())
</span><span class="cx">         blobRegistry().registerBlobURL(url, std::move(blobData));
</span><del>-    else
-        callOnMainThread(&amp;registerBlobURLTask, new BlobRegistryContext(url, std::move(blobData)));
</del><ins>+    else {
+        // BlobRegistryContext performs an isolated copy of data.
+        BlobRegistryContext* context = new BlobRegistryContext(url, std::move(blobData));
+        callOnMainThread([context] {
+            std::unique_ptr&lt;BlobRegistryContext&gt; blobRegistryContext(context);
+            blobRegistry().registerBlobURL(blobRegistryContext-&gt;url, std::move(blobRegistryContext-&gt;blobData));
+        });
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void registerBlobURLFromTask(void* context)
-{
-    std::unique_ptr&lt;BlobRegistryContext&gt; blobRegistryContext(static_cast&lt;BlobRegistryContext*&gt;(context));
-    blobRegistry().registerBlobURL(blobRegistryContext-&gt;url, blobRegistryContext-&gt;srcURL);
-}
-
</del><span class="cx"> void ThreadableBlobRegistry::registerBlobURL(SecurityOrigin* origin, const URL&amp; url, const URL&amp; srcURL)
</span><span class="cx"> {
</span><span class="cx">     // If the blob URL contains null origin, as in the context with unique security origin or file URL, save the mapping between url and origin so that the origin can be retrived when doing security origin check.
</span><span class="lines">@@ -115,10 +110,35 @@
</span><span class="cx"> 
</span><span class="cx">     if (isMainThread())
</span><span class="cx">         blobRegistry().registerBlobURL(url, srcURL);
</span><del>-    else
-        callOnMainThread(&amp;registerBlobURLFromTask, new BlobRegistryContext(url, srcURL));
</del><ins>+    else {
+        // BlobRegistryContext performs an isolated copy of data.
+        BlobRegistryContext* context = new BlobRegistryContext(url, srcURL);
+        callOnMainThread([context] {
+            std::unique_ptr&lt;BlobRegistryContext&gt; blobRegistryContext(context);
+            blobRegistry().registerBlobURL(blobRegistryContext-&gt;url, blobRegistryContext-&gt;srcURL);
+        });
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+unsigned long long ThreadableBlobRegistry::registerBlobURLForSlice(const URL&amp; newURL, const URL&amp; srcURL, long long start, long long end)
+{
+    unsigned long long resultSize;
+    if (isMainThread())
+        resultSize = blobRegistry().registerBlobURLForSlice(newURL, srcURL, start, end);
+    else {
+        // BlobRegistryContext performs an isolated copy of data.
+        BlobRegistryContext* context = new BlobRegistryContext(newURL, srcURL);
+        BinarySemaphore semaphore;
+        callOnMainThread([context, start, end, &amp;semaphore, &amp;resultSize] {
+            std::unique_ptr&lt;BlobRegistryContext&gt; blobRegistryContext(context);
+            resultSize = blobRegistry().registerBlobURLForSlice(blobRegistryContext-&gt;url, blobRegistryContext-&gt;srcURL, start, end);
+            semaphore.signal();
+        });
+        semaphore.wait(std::numeric_limits&lt;double&gt;::max());
+    }
+    return resultSize;
+}
+
</ins><span class="cx"> static void unregisterBlobURLTask(void* context)
</span><span class="cx"> {
</span><span class="cx">     std::unique_ptr&lt;BlobRegistryContext&gt; blobRegistryContext(static_cast&lt;BlobRegistryContext*&gt;(context));
</span></span></pre></div>
<a id="trunkSourceWebCorefileapiThreadableBlobRegistryh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/fileapi/ThreadableBlobRegistry.h (168053 => 168054)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/fileapi/ThreadableBlobRegistry.h        2014-04-30 22:45:36 UTC (rev 168053)
+++ trunk/Source/WebCore/fileapi/ThreadableBlobRegistry.h        2014-04-30 22:52:30 UTC (rev 168054)
</span><span class="lines">@@ -45,6 +45,8 @@
</span><span class="cx">     static void registerBlobURL(SecurityOrigin*, const URL&amp;, const URL&amp; srcURL);
</span><span class="cx">     static void unregisterBlobURL(const URL&amp;);
</span><span class="cx"> 
</span><ins>+    static unsigned long long registerBlobURLForSlice(const URL&amp; newURL, const URL&amp; srcURL, long long start, long long end);
+
</ins><span class="cx">     // Returns the origin for the given blob URL. This is because we are not able to embed the unique security origin or the origin of file URL
</span><span class="cx">     // in the blob URL.
</span><span class="cx">     static PassRefPtr&lt;SecurityOrigin&gt; getCachedOrigin(const URL&amp;);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkBlobRegistryh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/BlobRegistry.h (168053 => 168054)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/BlobRegistry.h        2014-04-30 22:45:36 UTC (rev 168053)
+++ trunk/Source/WebCore/platform/network/BlobRegistry.h        2014-04-30 22:52:30 UTC (rev 168054)
</span><span class="lines">@@ -51,6 +51,9 @@
</span><span class="cx">     // Registers a new blob URL referring to the blob data identified by the specified srcURL.
</span><span class="cx">     virtual void registerBlobURL(const URL&amp;, const URL&amp; srcURL) = 0;
</span><span class="cx"> 
</span><ins>+    // Negative start and end values select from the end.
+    virtual unsigned long long registerBlobURLForSlice(const URL&amp;, const URL&amp; srcURL, long long start, long long end) = 0;
+
</ins><span class="cx">     virtual void unregisterBlobURL(const URL&amp;) = 0;
</span><span class="cx"> 
</span><span class="cx">     virtual bool isBlobRegistryImpl() const { return false; }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkBlobRegistryImplcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/BlobRegistryImpl.cpp (168053 => 168054)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/BlobRegistryImpl.cpp        2014-04-30 22:45:36 UTC (rev 168053)
+++ trunk/Source/WebCore/platform/network/BlobRegistryImpl.cpp        2014-04-30 22:52:30 UTC (rev 168054)
</span><span class="lines">@@ -36,6 +36,8 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;BlobResourceHandle.h&quot;
</span><span class="cx"> #include &quot;BlobStorageData.h&quot;
</span><ins>+#include &quot;FileMetadata.h&quot;
+#include &quot;FileSystem.h&quot;
</ins><span class="cx"> #include &quot;ResourceError.h&quot;
</span><span class="cx"> #include &quot;ResourceHandle.h&quot;
</span><span class="cx"> #include &quot;ResourceRequest.h&quot;
</span><span class="lines">@@ -99,6 +101,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     for (; iter != items.end() &amp;&amp; length &gt; 0; ++iter) {
</span><ins>+        ASSERT(iter-&gt;length != BlobDataItem::toEndOfFile);
</ins><span class="cx">         long long currentLength = iter-&gt;length - offset;
</span><span class="cx">         long long newLength = currentLength &gt; length ? length : currentLength;
</span><span class="cx">         if (iter-&gt;type == BlobDataItem::Data)
</span><span class="lines">@@ -156,6 +159,43 @@
</span><span class="cx">     m_blobs.set(url.string(), src);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+unsigned long long BlobRegistryImpl::registerBlobURLForSlice(const URL&amp; url, const URL&amp; srcURL, long long start, long long end)
+{
+    ASSERT(isMainThread());
+    BlobStorageData* originalStorageData = m_blobs.get(srcURL.string());
+    if (!originalStorageData)
+        return 0;
+
+    unsigned long long originalSize = blobSize(srcURL);
+
+    // Convert the negative value that is used to select from the end.
+    if (start &lt; 0)
+        start = start + originalSize;
+    if (end &lt; 0)
+        end = end + originalSize;
+
+    // Clamp the range if it exceeds the size limit.
+    if (start &lt; 0)
+        start = 0;
+    if (end &lt; 0)
+        end = 0;
+    if (static_cast&lt;unsigned long long&gt;(start) &gt;= originalSize) {
+        start = 0;
+        end = 0;
+    } else if (end &lt; start)
+        end = start;
+    else if (static_cast&lt;unsigned long long&gt;(end) &gt; originalSize)
+        end = originalSize;
+
+    unsigned long long newLength = end - start;
+    RefPtr&lt;BlobStorageData&gt; newStorageData = BlobStorageData::create(originalStorageData-&gt;contentType(), originalStorageData-&gt;contentDisposition());
+
+    appendStorageItems(newStorageData.get(), originalStorageData-&gt;items(), start, newLength);
+
+    m_blobs.set(url.string(), newStorageData.release());
+    return newLength;
+}
+
</ins><span class="cx"> void BlobRegistryImpl::unregisterBlobURL(const URL&amp; url)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(isMainThread());
</span><span class="lines">@@ -168,6 +208,29 @@
</span><span class="cx">     return m_blobs.get(url.string());
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+unsigned long long BlobRegistryImpl::blobSize(const URL&amp; url)
+{
+    ASSERT(isMainThread());
+    BlobStorageData* storageData = m_blobs.get(url.string());
+    if (!storageData)
+        return 0;
+
+    unsigned long long result = 0;
+    for (const BlobDataItem&amp; item : storageData-&gt;items()) {
+        if (item.length == BlobDataItem::toEndOfFile) {
+            FileMetadata metadata;
+            if (!getFileMetadata(item.path, metadata))
+                return 0;
+
+            // FIXME: Factor out size and modification tracking for a cleaner implementation.
+            const_cast&lt;BlobDataItem&amp;&gt;(item).length = metadata.length;
+            const_cast&lt;BlobDataItem&amp;&gt;(item).expectedModificationTime = metadata.modificationTime;
+        }
+        result += item.length;
+    }
+    return result;
+}
+
</ins><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkBlobRegistryImplh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/BlobRegistryImpl.h (168053 => 168054)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/BlobRegistryImpl.h        2014-04-30 22:45:36 UTC (rev 168053)
+++ trunk/Source/WebCore/platform/network/BlobRegistryImpl.h        2014-04-30 22:52:30 UTC (rev 168054)
</span><span class="lines">@@ -59,9 +59,12 @@
</span><span class="cx"> 
</span><span class="cx">     virtual void registerBlobURL(const URL&amp;, std::unique_ptr&lt;BlobData&gt;) override;
</span><span class="cx">     virtual void registerBlobURL(const URL&amp;, const URL&amp; srcURL) override;
</span><ins>+    virtual unsigned long long registerBlobURLForSlice(const URL&amp;, const URL&amp; srcURL, long long start, long long end) override;
</ins><span class="cx">     virtual void unregisterBlobURL(const URL&amp;) override;
</span><span class="cx">     virtual bool isBlobRegistryImpl() const override { return true; }
</span><span class="cx"> 
</span><ins>+    unsigned long long blobSize(const URL&amp;);
+
</ins><span class="cx">     HashMap&lt;String, RefPtr&lt;BlobStorageData&gt;&gt; m_blobs;
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (168053 => 168054)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-04-30 22:45:36 UTC (rev 168053)
+++ trunk/Source/WebKit2/ChangeLog        2014-04-30 22:52:30 UTC (rev 168054)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2014-04-30  Alexey Proskuryakov  &lt;ap@apple.com&gt;
+
+        Move Blob.slice() implementation into BlobRegistryImpl
+        https://bugs.webkit.org/show_bug.cgi?id=132402
+
+        Reviewed by Anders Carlsson.
+
+        * NetworkProcess/FileAPI/NetworkBlobRegistry.cpp:
+        (WebKit::NetworkBlobRegistry::registerBlobURLForSlice):
+        * NetworkProcess/FileAPI/NetworkBlobRegistry.h:
+        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
+        (WebKit::NetworkConnectionToWebProcess::registerBlobURLForSlice):
+        * NetworkProcess/NetworkConnectionToWebProcess.h:
+        * NetworkProcess/NetworkConnectionToWebProcess.messages.in:
+        * WebProcess/FileAPI/BlobRegistryProxy.cpp:
+        (WebKit::BlobRegistryProxy::registerBlobURLForSlice):
+        * WebProcess/FileAPI/BlobRegistryProxy.h:
+
</ins><span class="cx"> 2014-04-30  Beth Dakin  &lt;bdakin@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Phone number data detection UI is offset for iframes, pages with topContentInset
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessFileAPINetworkBlobRegistrycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/FileAPI/NetworkBlobRegistry.cpp (168053 => 168054)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/FileAPI/NetworkBlobRegistry.cpp        2014-04-30 22:45:36 UTC (rev 168053)
+++ trunk/Source/WebKit2/NetworkProcess/FileAPI/NetworkBlobRegistry.cpp        2014-04-30 22:52:30 UTC (rev 168054)
</span><span class="lines">@@ -84,6 +84,22 @@
</span><span class="cx">     m_blobsForConnection.find(connection)-&gt;value.add(url);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+uint64_t NetworkBlobRegistry::registerBlobURLForSlice(NetworkConnectionToWebProcess* connection, const WebCore::URL&amp; url, const WebCore::URL&amp; srcURL, int64_t start, int64_t end)
+{
+    uint64_t resultSize = blobRegistry().registerBlobURLForSlice(url, srcURL, start, end);
+
+    // FIXME: Only store extensions for files that the slice actually contains, not for all the files in original blob.
+    SandboxExtensionMap::iterator iter = m_sandboxExtensions.find(srcURL.string());
+    if (iter != m_sandboxExtensions.end())
+        m_sandboxExtensions.add(url.string(), iter-&gt;value);
+
+    ASSERT(m_blobsForConnection.contains(connection));
+    ASSERT(m_blobsForConnection.find(connection)-&gt;value.contains(srcURL));
+    m_blobsForConnection.find(connection)-&gt;value.add(url);
+
+    return resultSize;
+}
+
</ins><span class="cx"> void NetworkBlobRegistry::unregisterBlobURL(NetworkConnectionToWebProcess* connection, const WebCore::URL&amp; url)
</span><span class="cx"> {
</span><span class="cx">     blobRegistry().unregisterBlobURL(url);
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessFileAPINetworkBlobRegistryh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/FileAPI/NetworkBlobRegistry.h (168053 => 168054)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/FileAPI/NetworkBlobRegistry.h        2014-04-30 22:45:36 UTC (rev 168053)
+++ trunk/Source/WebKit2/NetworkProcess/FileAPI/NetworkBlobRegistry.h        2014-04-30 22:52:30 UTC (rev 168054)
</span><span class="lines">@@ -49,6 +49,7 @@
</span><span class="cx"> 
</span><span class="cx">     void registerBlobURL(NetworkConnectionToWebProcess*, const WebCore::URL&amp;, std::unique_ptr&lt;WebCore::BlobData&gt;, const Vector&lt;RefPtr&lt;SandboxExtension&gt;&gt;&amp;);
</span><span class="cx">     void registerBlobURL(NetworkConnectionToWebProcess*, const WebCore::URL&amp;, const WebCore::URL&amp; srcURL);
</span><ins>+    uint64_t registerBlobURLForSlice(NetworkConnectionToWebProcess*, const WebCore::URL&amp;, const WebCore::URL&amp; srcURL, int64_t start, int64_t end);
</ins><span class="cx">     void unregisterBlobURL(NetworkConnectionToWebProcess*, const WebCore::URL&amp;);
</span><span class="cx"> 
</span><span class="cx">     void connectionToWebProcessDidClose(NetworkConnectionToWebProcess*);
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessNetworkConnectionToWebProcesscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp (168053 => 168054)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp        2014-04-30 22:45:36 UTC (rev 168053)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp        2014-04-30 22:52:30 UTC (rev 168054)
</span><span class="lines">@@ -241,6 +241,11 @@
</span><span class="cx">     NetworkBlobRegistry::shared().registerBlobURL(this, url, srcURL);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void NetworkConnectionToWebProcess::registerBlobURLForSlice(const URL&amp; url, const URL&amp; srcURL, int64_t start, int64_t end, uint64_t&amp; resultSize)
+{
+    resultSize = NetworkBlobRegistry::shared().registerBlobURLForSlice(this, url, srcURL, start, end);
+}
+
</ins><span class="cx"> void NetworkConnectionToWebProcess::unregisterBlobURL(const URL&amp; url)
</span><span class="cx"> {
</span><span class="cx">     NetworkBlobRegistry::shared().unregisterBlobURL(this, url);
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessNetworkConnectionToWebProcessh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.h (168053 => 168054)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.h        2014-04-30 22:45:36 UTC (rev 168053)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.h        2014-04-30 22:52:30 UTC (rev 168054)
</span><span class="lines">@@ -90,6 +90,7 @@
</span><span class="cx"> #if ENABLE(BLOB)
</span><span class="cx">     void registerBlobURL(const WebCore::URL&amp;, const BlobRegistrationData&amp;);
</span><span class="cx">     void registerBlobURLFromURL(const WebCore::URL&amp;, const WebCore::URL&amp; srcURL);
</span><ins>+    void registerBlobURLForSlice(const WebCore::URL&amp;, const WebCore::URL&amp; srcURL, int64_t start, int64_t end, uint64_t&amp; resultSize);
</ins><span class="cx">     void unregisterBlobURL(const WebCore::URL&amp;);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessNetworkConnectionToWebProcessmessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.messages.in (168053 => 168054)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.messages.in        2014-04-30 22:45:36 UTC (rev 168053)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.messages.in        2014-04-30 22:52:30 UTC (rev 168054)
</span><span class="lines">@@ -46,6 +46,7 @@
</span><span class="cx"> #if ENABLE(BLOB)
</span><span class="cx">     RegisterBlobURL(WebCore::URL url, WebKit::BlobRegistrationData data)
</span><span class="cx">     RegisterBlobURLFromURL(WebCore::URL url, WebCore::URL srcURL)
</span><ins>+    RegisterBlobURLForSlice(WebCore::URL url, WebCore::URL srcURL, int64_t start, int64_t end) -&gt; (uint64_t resultSize)
</ins><span class="cx">     UnregisterBlobURL(WebCore::URL url)
</span><span class="cx"> #endif
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessFileAPIBlobRegistryProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/FileAPI/BlobRegistryProxy.cpp (168053 => 168054)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/FileAPI/BlobRegistryProxy.cpp        2014-04-30 22:45:36 UTC (rev 168053)
+++ trunk/Source/WebKit2/WebProcess/FileAPI/BlobRegistryProxy.cpp        2014-04-30 22:52:30 UTC (rev 168054)
</span><span class="lines">@@ -60,6 +60,16 @@
</span><span class="cx">     WebProcess::shared().networkConnection()-&gt;connection()-&gt;send(Messages::NetworkConnectionToWebProcess::UnregisterBlobURL(url), 0);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+unsigned long long BlobRegistryProxy::registerBlobURLForSlice(const URL&amp; url, const URL&amp; srcURL, long long start, long long end)
+{
+    ASSERT(WebProcess::shared().usesNetworkProcess());
+
+    uint64_t resultSize;
+    if (!WebProcess::shared().networkConnection()-&gt;connection()-&gt;sendSync(Messages::NetworkConnectionToWebProcess::RegisterBlobURLForSlice(url, srcURL, start, end), Messages::NetworkConnectionToWebProcess::RegisterBlobURLForSlice::Reply(resultSize), 0))
+        return 0;
+    return resultSize;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+}
+
</ins><span class="cx"> #endif // ENABLE(BLOB) &amp;&amp; ENABLE(NETWORK_PROCESS)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessFileAPIBlobRegistryProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/FileAPI/BlobRegistryProxy.h (168053 => 168054)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/FileAPI/BlobRegistryProxy.h        2014-04-30 22:45:36 UTC (rev 168053)
+++ trunk/Source/WebKit2/WebProcess/FileAPI/BlobRegistryProxy.h        2014-04-30 22:52:30 UTC (rev 168054)
</span><span class="lines">@@ -37,6 +37,7 @@
</span><span class="cx">     virtual void registerBlobURL(const WebCore::URL&amp;, std::unique_ptr&lt;WebCore::BlobData&gt;) override;
</span><span class="cx">     virtual void registerBlobURL(const WebCore::URL&amp;, const WebCore::URL&amp; srcURL) override;
</span><span class="cx">     virtual void unregisterBlobURL(const WebCore::URL&amp;) override;
</span><ins>+    virtual unsigned long long registerBlobURLForSlice(const WebCore::URL&amp;, const WebCore::URL&amp; srcURL, long long start, long long end) override;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>