<!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>[163318] trunk/Source/WebCore</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/163318">163318</a></dd>
<dt>Author</dt> <dd>ddkilzer@apple.com</dd>
<dt>Date</dt> <dd>2014-02-03 11:34:30 -0800 (Mon, 03 Feb 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Remove CachedImageManual class
&lt;http://webkit.org/b/128043&gt;

Reviewed by Darin Adler.

Get rid of the CachedImageManual class by inlining its
functionality into CachedImage.  This makes it possible to
de-virtual-ize isManual() (renamed to isManuallyCached()) and to
make CachedImage final.  The size of CachedImage does not
increase because we turn an existing bool into a bitfield to add
an m_isManuallyCached bit, and create a static CachedImageClient
in MemoryCache.cpp as the &quot;fake&quot; client to keep the manually
cached image alive in the cache.

* loader/cache/CachedImage.cpp:
(WebCore::CachedImage::CachedImage): Set m_isManuallyCached
bitfield.  For one overloaded constructor, move the
CachedImageManual code into the CachedImage constructor.
(WebCore::CachedImageManual::CachedImageManual): Remove.
(WebCore::CachedImage::mustRevalidateDueToCacheHeaders): Move
method from CachedImageManual to CachedImage, and put
ManuallyCached behavior behind a check.
* loader/cache/CachedImage.h: Update includes.  Make CachedImage
final.  Add CachedImage::CacheBehaviorType enum when manually
cached images are created.  Move CachedImageManual methods into
CachedImage, remove addFakeClient() and removeFakeClient()
methods (MemoryCache methods use addClient() and removeClient()
with a static CachedImageClient), and remove the
CachedImageManual class definition.  Change
m_shouldPaintBrokenImage to a bitfield and add
m_isManuallyCached bitfield.

* loader/cache/MemoryCache.cpp:
(WebCore::MemoryCache::addImageToCache): Use std::unique_ptr and
remove useless NULL check after calling CachedImage constructor.
(WebCore::MemoryCache::removeImageFromCache):
- Update to use CachedImage class instead of CachedImageManual.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreloadercacheCachedImagecpp">trunk/Source/WebCore/loader/cache/CachedImage.cpp</a></li>
<li><a href="#trunkSourceWebCoreloadercacheCachedImageh">trunk/Source/WebCore/loader/cache/CachedImage.h</a></li>
<li><a href="#trunkSourceWebCoreloadercacheMemoryCachecpp">trunk/Source/WebCore/loader/cache/MemoryCache.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (163317 => 163318)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-02-03 19:07:29 UTC (rev 163317)
+++ trunk/Source/WebCore/ChangeLog        2014-02-03 19:34:30 UTC (rev 163318)
</span><span class="lines">@@ -1,3 +1,43 @@
</span><ins>+2014-02-03  David Kilzer  &lt;ddkilzer@apple.com&gt;
+
+        Remove CachedImageManual class
+        &lt;http://webkit.org/b/128043&gt;
+
+        Reviewed by Darin Adler.
+
+        Get rid of the CachedImageManual class by inlining its
+        functionality into CachedImage.  This makes it possible to
+        de-virtual-ize isManual() (renamed to isManuallyCached()) and to
+        make CachedImage final.  The size of CachedImage does not
+        increase because we turn an existing bool into a bitfield to add
+        an m_isManuallyCached bit, and create a static CachedImageClient
+        in MemoryCache.cpp as the &quot;fake&quot; client to keep the manually
+        cached image alive in the cache.
+
+        * loader/cache/CachedImage.cpp:
+        (WebCore::CachedImage::CachedImage): Set m_isManuallyCached
+        bitfield.  For one overloaded constructor, move the
+        CachedImageManual code into the CachedImage constructor.
+        (WebCore::CachedImageManual::CachedImageManual): Remove.
+        (WebCore::CachedImage::mustRevalidateDueToCacheHeaders): Move
+        method from CachedImageManual to CachedImage, and put
+        ManuallyCached behavior behind a check.
+        * loader/cache/CachedImage.h: Update includes.  Make CachedImage
+        final.  Add CachedImage::CacheBehaviorType enum when manually
+        cached images are created.  Move CachedImageManual methods into
+        CachedImage, remove addFakeClient() and removeFakeClient()
+        methods (MemoryCache methods use addClient() and removeClient()
+        with a static CachedImageClient), and remove the
+        CachedImageManual class definition.  Change
+        m_shouldPaintBrokenImage to a bitfield and add
+        m_isManuallyCached bitfield.
+
+        * loader/cache/MemoryCache.cpp:
+        (WebCore::MemoryCache::addImageToCache): Use std::unique_ptr and
+        remove useless NULL check after calling CachedImage constructor.
+        (WebCore::MemoryCache::removeImageFromCache):
+        - Update to use CachedImage class instead of CachedImageManual.
+
</ins><span class="cx"> 2014-02-03  Zan Dobersek  &lt;zdobersek@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Move the webdatabase module source code to std::unique_ptr
</span></span></pre></div>
<a id="trunkSourceWebCoreloadercacheCachedImagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/cache/CachedImage.cpp (163317 => 163318)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/cache/CachedImage.cpp        2014-02-03 19:07:29 UTC (rev 163317)
+++ trunk/Source/WebCore/loader/cache/CachedImage.cpp        2014-02-03 19:34:30 UTC (rev 163318)
</span><span class="lines">@@ -66,6 +66,7 @@
</span><span class="cx"> CachedImage::CachedImage(const ResourceRequest&amp; resourceRequest)
</span><span class="cx">     : CachedResource(resourceRequest, ImageResource)
</span><span class="cx">     , m_image(0)
</span><ins>+    , m_isManuallyCached(false)
</ins><span class="cx">     , m_shouldPaintBrokenImage(true)
</span><span class="cx"> {
</span><span class="cx">     setStatus(Unknown);
</span><span class="lines">@@ -74,19 +75,27 @@
</span><span class="cx"> CachedImage::CachedImage(Image* image)
</span><span class="cx">     : CachedResource(ResourceRequest(), ImageResource)
</span><span class="cx">     , m_image(image)
</span><ins>+    , m_isManuallyCached(false)
</ins><span class="cx">     , m_shouldPaintBrokenImage(true)
</span><span class="cx"> {
</span><span class="cx">     setStatus(Cached);
</span><span class="cx">     setLoading(false);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-CachedImage::CachedImage(const URL&amp; url, Image* image)
</del><ins>+CachedImage::CachedImage(const URL&amp; url, Image* image, CachedImage::CacheBehaviorType type)
</ins><span class="cx">     : CachedResource(ResourceRequest(url), ImageResource)
</span><span class="cx">     , m_image(image)
</span><ins>+    , m_isManuallyCached(type == CachedImage::ManuallyCached)
</ins><span class="cx">     , m_shouldPaintBrokenImage(true)
</span><span class="cx"> {
</span><span class="cx">     setStatus(Cached);
</span><span class="cx">     setLoading(false);
</span><ins>+    if (UNLIKELY(isManuallyCached())) {
+        // Use the incoming URL in the response field. This ensures that code
+        // using the response directly, such as origin checks for security,
+        // actually see something.
+        m_response.setURL(url);
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> CachedImage::~CachedImage()
</span><span class="lines">@@ -612,29 +621,17 @@
</span><span class="cx">     return !securityOrigin-&gt;taintsCanvas(response().url());
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#if USE(CF)
-// FIXME: We should look to incorporate the functionality of CachedImageManual
-// into CachedImage or find a better place for this class.
-// FIXME: Remove the USE(CF) once we make MemoryCache::addImageToCache() platform-independent.
-CachedImageManual::CachedImageManual(const URL&amp; url, Image* image)
-    : CachedImage(url, image)
-    , m_fakeClient(std::make_unique&lt;CachedImageClient&gt;())
</del><ins>+bool CachedImage::mustRevalidateDueToCacheHeaders(CachePolicy policy) const
</ins><span class="cx"> {
</span><del>-    // Use the incoming URL in the response field. This ensures that code
-    // using the response directly, such as origin checks for security,
-    // actually see something.
-    m_response.setURL(url);
</del><ins>+    if (UNLIKELY(isManuallyCached())) {
+        // Do not revalidate manually cached images. This mechanism is used as a
+        // way to efficiently share an image from the client to content and
+        // the URL for that image may not represent a resource that can be
+        // retrieved by standard means. If the manual caching SPI is used, it is
+        // incumbent on the client to only use valid resources.
+        return false;
+    }
+    return CachedResource::mustRevalidateDueToCacheHeaders(policy);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool CachedImageManual::mustRevalidateDueToCacheHeaders(CachePolicy) const
-{
-    // Do not revalidate manually cached images. This mechanism is used as a
-    // way to efficiently share an image from the client to content and
-    // the URL for that image may not represent a resource that can be
-    // retrieved by standard means. If the manual caching SPI is used, it is
-    // incumbent on the client to only use valid resources.
-    return false;
-}
-#endif
-
</del><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreloadercacheCachedImageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/cache/CachedImage.h (163317 => 163318)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/cache/CachedImage.h        2014-02-03 19:07:29 UTC (rev 163317)
+++ trunk/Source/WebCore/loader/cache/CachedImage.h        2014-02-03 19:34:30 UTC (rev 163318)
</span><span class="lines">@@ -44,13 +44,15 @@
</span><span class="cx"> 
</span><span class="cx"> struct Length;
</span><span class="cx"> 
</span><del>-class CachedImage : public CachedResource, public ImageObserver {
</del><ins>+class CachedImage final : public CachedResource, public ImageObserver {
</ins><span class="cx">     friend class MemoryCache;
</span><span class="cx"> 
</span><span class="cx"> public:
</span><ins>+    enum CacheBehaviorType { AutomaticallyCached, ManuallyCached };
+
</ins><span class="cx">     CachedImage(const ResourceRequest&amp;);
</span><span class="cx">     CachedImage(Image*);
</span><del>-    CachedImage(const URL&amp;, Image*);
</del><ins>+    CachedImage(const URL&amp;, Image*, CacheBehaviorType = AutomaticallyCached);
</ins><span class="cx">     virtual ~CachedImage();
</span><span class="cx"> 
</span><span class="cx">     Image* image(); // Returns the nullImage() if the image is not available yet.
</span><span class="lines">@@ -79,10 +81,8 @@
</span><span class="cx">     LayoutSize imageSizeForRenderer(const RenderObject*, float multiplier, SizeType = UsedSize); // returns the size of the complete image.
</span><span class="cx">     void computeIntrinsicDimensions(Length&amp; intrinsicWidth, Length&amp; intrinsicHeight, FloatSize&amp; intrinsicRatio);
</span><span class="cx"> 
</span><del>-#if USE(CF)
-    // FIXME: Remove the USE(CF) once we make MemoryCache::addImageToCache() platform-independent.
-    virtual bool isManual() const { return false; }
-#endif
</del><ins>+    bool isManuallyCached() const { return m_isManuallyCached; }
+    virtual bool mustRevalidateDueToCacheHeaders(CachePolicy) const;
</ins><span class="cx"> 
</span><span class="cx">     static void resumeAnimatingImagesForLoader(CachedResourceLoader*);
</span><span class="cx"> 
</span><span class="lines">@@ -142,29 +142,11 @@
</span><span class="cx"> #if ENABLE(SVG)
</span><span class="cx">     std::unique_ptr&lt;SVGImageCache&gt; m_svgImageCache;
</span><span class="cx"> #endif
</span><del>-    bool m_shouldPaintBrokenImage;
</del><ins>+    unsigned char m_isManuallyCached : 1;
+    unsigned char m_shouldPaintBrokenImage : 1;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><del>-#if USE(CF)
-// FIXME: We should look to incorporate the functionality of CachedImageManual
-// into CachedImage or find a better place for this class.
-// FIXME: Remove the USE(CF) once we make MemoryCache::addImageToCache() platform-independent.
-class CachedImageManual final : public CachedImage {
-public:
-    CachedImageManual(const URL&amp;, Image*);
-    void addFakeClient() { addClient(m_fakeClient.get()); }
-    void removeFakeClient() { removeClient(m_fakeClient.get()); }
-    virtual bool isManual() const override { return true; }
-    virtual bool mustRevalidateDueToCacheHeaders(CachePolicy) const;
-private:
-    std::unique_ptr&lt;CachedResourceClient&gt; m_fakeClient;
-};
-#endif
-
</del><span class="cx"> CACHED_RESOURCE_TYPE_CASTS(CachedImage, CachedResource, CachedResource::ImageResource)
</span><del>-#if USE(CF)
-TYPE_CASTS_BASE(CachedImageManual, CachedImage, resource, resource-&gt;isManual(), resource.isManual())
-#endif
</del><span class="cx"> 
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreloadercacheMemoryCachecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/cache/MemoryCache.cpp (163317 => 163318)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/cache/MemoryCache.cpp        2014-02-03 19:07:29 UTC (rev 163317)
+++ trunk/Source/WebCore/loader/cache/MemoryCache.cpp        2014-02-03 19:34:30 UTC (rev 163318)
</span><span class="lines">@@ -25,6 +25,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;BitmapImage.h&quot;
</span><span class="cx"> #include &quot;CachedImage.h&quot;
</span><ins>+#include &quot;CachedImageClient.h&quot;
</ins><span class="cx"> #include &quot;CachedResource.h&quot;
</span><span class="cx"> #include &quot;CachedResourceHandle.h&quot;
</span><span class="cx"> #include &quot;CrossThreadTask.h&quot;
</span><span class="lines">@@ -215,6 +216,12 @@
</span><span class="cx"> #if USE(CG)
</span><span class="cx"> // FIXME: Remove the USE(CG) once we either make NativeImagePtr a smart pointer on all platforms or
</span><span class="cx"> // remove the usage of CFRetain() in MemoryCache::addImageToCache() so as to make the code platform-independent.
</span><ins>+static CachedImageClient&amp; dummyCachedImageClient()
+{
+    DEFINE_STATIC_LOCAL(CachedImageClient, client, ());
+    return client;
+}
+
</ins><span class="cx"> bool MemoryCache::addImageToCache(NativeImagePtr image, const URL&amp; url, const String&amp; cachePartition)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(image);
</span><span class="lines">@@ -224,18 +231,16 @@
</span><span class="cx">     if (!bitmapImage)
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><del>-    CachedImageManual* cachedImage = new CachedImageManual(url, bitmapImage.get());
-    if (!cachedImage)
-        return false;
</del><ins>+    std::unique_ptr&lt;CachedImage&gt; cachedImage = std::make_unique&lt;CachedImage&gt;(url, bitmapImage.get(), CachedImage::ManuallyCached);
</ins><span class="cx"> 
</span><span class="cx">     // Actual release of the CGImageRef is done in BitmapImage.
</span><span class="cx">     CFRetain(image);
</span><del>-    cachedImage-&gt;addFakeClient();
</del><ins>+    cachedImage-&gt;addClient(&amp;dummyCachedImageClient());
</ins><span class="cx">     cachedImage-&gt;setDecodedSize(bitmapImage-&gt;decodedSize());
</span><span class="cx"> #if ENABLE(CACHE_PARTITIONING)
</span><span class="cx">     cachedImage-&gt;resourceRequest().setCachePartition(cachePartition);
</span><span class="cx"> #endif
</span><del>-    add(cachedImage);
</del><ins>+    add(cachedImage.release());
</ins><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -255,7 +260,7 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     // A resource exists and is not a manually cached image, so just remove it.
</span><del>-    if (!resource-&gt;isImage() || !toCachedImage(resource)-&gt;isManual()) {
</del><ins>+    if (!resource-&gt;isImage() || !toCachedImage(resource)-&gt;isManuallyCached()) {
</ins><span class="cx">         evict(resource);
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="lines">@@ -265,7 +270,7 @@
</span><span class="cx">     // dead resources are pruned. That might be immediately since
</span><span class="cx">     // removing the last client triggers a MemoryCache::prune, so the
</span><span class="cx">     // resource may be deleted after this call.
</span><del>-    toCachedImageManual(toCachedImage(resource))-&gt;removeFakeClient();
</del><ins>+    toCachedImage(resource)-&gt;removeClient(&amp;dummyCachedImageClient());
</ins><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>