<!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>[170108] 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/170108">170108</a></dd>
<dt>Author</dt> <dd>andersca@apple.com</dd>
<dt>Date</dt> <dd>2014-06-18 11:03:16 -0700 (Wed, 18 Jun 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add CF type cast function templates and use them in KeyedDecoder in WebKit2
https://bugs.webkit.org/show_bug.cgi?id=134033

Reviewed by Sam Weinig.

Source/WebKit2:
* Shared/cf/KeyedDecoder.cpp:
(WebKit::KeyedDecoder::KeyedDecoder):
(WebKit::KeyedDecoder::decodeBytes):
(WebKit::KeyedDecoder::decodeBool):
(WebKit::KeyedDecoder::decodeInt32):
(WebKit::KeyedDecoder::decodeInt64):
(WebKit::KeyedDecoder::decodeFloat):
(WebKit::KeyedDecoder::decodeDouble):
(WebKit::KeyedDecoder::decodeString):
(WebKit::KeyedDecoder::beginObject):
(WebKit::KeyedDecoder::beginArray):
(WebKit::KeyedDecoder::beginArrayElement):

Source/WTF:
* WTF.xcodeproj/project.pbxproj:
* wtf/cf/TypeCasts.h: Added.
(WTF::dynamic_cf_cast):
Returns null if the given CFTypeRef object doesn't have the right type.

(WTF::checked_cf_cast):
ASSERTs (with security implication) if the given CFTypeRef object is null or doesn't have the right type.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFWTFxcodeprojprojectpbxproj">trunk/Source/WTF/WTF.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2SharedcfKeyedDecodercpp">trunk/Source/WebKit2/Shared/cf/KeyedDecoder.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWTFwtfcfTypeCastsh">trunk/Source/WTF/wtf/cf/TypeCasts.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (170107 => 170108)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2014-06-18 17:58:28 UTC (rev 170107)
+++ trunk/Source/WTF/ChangeLog        2014-06-18 18:03:16 UTC (rev 170108)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2014-06-18  Anders Carlsson  &lt;andersca@apple.com&gt;
+
+        Add CF type cast function templates and use them in KeyedDecoder in WebKit2
+        https://bugs.webkit.org/show_bug.cgi?id=134033
+
+        Reviewed by Sam Weinig.
+
+        * WTF.xcodeproj/project.pbxproj:
+        * wtf/cf/TypeCasts.h: Added.
+        (WTF::dynamic_cf_cast):
+        Returns null if the given CFTypeRef object doesn't have the right type.
+
+        (WTF::checked_cf_cast):
+        ASSERTs (with security implication) if the given CFTypeRef object is null or doesn't have the right type.
+
</ins><span class="cx"> 2014-06-17  Tamas Gergely  &lt;tgergely.u-szeged@partner.samsung.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Misused PLATFORM(MIDDLE_ENDIAN) and PLATFORM(BIG_ENDIAN).
</span></span></pre></div>
<a id="trunkSourceWTFWTFxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/WTF.xcodeproj/project.pbxproj (170107 => 170108)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/WTF.xcodeproj/project.pbxproj        2014-06-18 17:58:28 UTC (rev 170107)
+++ trunk/Source/WTF/WTF.xcodeproj/project.pbxproj        2014-06-18 18:03:16 UTC (rev 170108)
</span><span class="lines">@@ -62,6 +62,7 @@
</span><span class="cx">                 1A6BB769162F300500DD16DB /* StreamBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A6BB768162F300500DD16DB /* StreamBuffer.h */; };
</span><span class="cx">                 1A6EB1E0187D0BD30030126F /* StringView.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A6EB1DF187D0BD30030126F /* StringView.h */; };
</span><span class="cx">                 1ACADD841884480100D8B71D /* DeprecatedSymbolsUsedBySafari.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1ACADD821884480100D8B71D /* DeprecatedSymbolsUsedBySafari.mm */; };
</span><ins>+                1AFDE648195201C300C48FFA /* TypeCasts.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AFDE647195201C300C48FFA /* TypeCasts.h */; };
</ins><span class="cx">                 1FA47C8A152502DA00568D1B /* WebCoreThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1FA47C88152502DA00568D1B /* WebCoreThread.cpp */; };
</span><span class="cx">                 1FA47C8B152502DA00568D1B /* WebCoreThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FA47C89152502DA00568D1B /* WebCoreThread.h */; };
</span><span class="cx">                 26147B0A15DDCCDC00DDB907 /* IntegerToStringConversion.h in Headers */ = {isa = PBXBuildFile; fileRef = 26147B0815DDCCDC00DDB907 /* IntegerToStringConversion.h */; };
</span><span class="lines">@@ -319,7 +320,7 @@
</span><span class="cx">                 0FDDBFA51666DFA300C55FEF /* StringPrintStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringPrintStream.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 0FDDBFA61666DFA300C55FEF /* StringPrintStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringPrintStream.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 0FEC3EE4171B834700FDAC8D /* ByteSpinLock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ByteSpinLock.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><del>-                14022F4018F5C3FC007FF0EB /* libbmalloc.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libbmalloc.a; path = libbmalloc.a; sourceTree = BUILT_PRODUCTS_DIR; };
</del><ins>+                14022F4018F5C3FC007FF0EB /* libbmalloc.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libbmalloc.a; sourceTree = BUILT_PRODUCTS_DIR; };
</ins><span class="cx">                 143F611D1565F0F900DB514A /* RAMSize.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RAMSize.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 143F611E1565F0F900DB514A /* RAMSize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RAMSize.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1447AEBE18FCE56900B3D7FF /* libmbmalloc.dylib */ = {isa = PBXFileReference; explicitFileType = &quot;compiled.mach-o.dylib&quot;; includeInIndex = 0; path = libmbmalloc.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
</span><span class="lines">@@ -343,13 +344,14 @@
</span><span class="cx">                 1A6BB768162F300500DD16DB /* StreamBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamBuffer.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1A6EB1DF187D0BD30030126F /* StringView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringView.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1ACADD821884480100D8B71D /* DeprecatedSymbolsUsedBySafari.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DeprecatedSymbolsUsedBySafari.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                1AFDE647195201C300C48FFA /* TypeCasts.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TypeCasts.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 1FA47C88152502DA00568D1B /* WebCoreThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebCoreThread.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1FA47C89152502DA00568D1B /* WebCoreThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreThread.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 26147B0815DDCCDC00DDB907 /* IntegerToStringConversion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntegerToStringConversion.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 26299B6D17A9E5B800ADEBE5 /* Ref.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Ref.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2C05385315BC819000F21B96 /* GregorianDateTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GregorianDateTime.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2CCD892915C0390200285083 /* GregorianDateTime.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GregorianDateTime.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><del>-                2CDED0EE18115C38004DBA70 /* RunLoopCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RunLoopCF.cpp; path = cf/RunLoopCF.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</del><ins>+                2CDED0EE18115C38004DBA70 /* RunLoopCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RunLoopCF.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 2CDED0F118115C85004DBA70 /* RunLoop.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RunLoop.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2CDED0F218115C85004DBA70 /* RunLoop.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RunLoop.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 44DEE74A152274BB00C6EC37 /* iOS.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = iOS.xcconfig; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -613,8 +615,9 @@
</span><span class="cx">                         isa = PBXGroup;
</span><span class="cx">                         children = (
</span><span class="cx">                                 2CDED0EE18115C38004DBA70 /* RunLoopCF.cpp */,
</span><ins>+                                1AFDE647195201C300C48FFA /* TypeCasts.h */,
</ins><span class="cx">                         );
</span><del>-                        name = cf;
</del><ins>+                        path = cf;
</ins><span class="cx">                         sourceTree = &quot;&lt;group&gt;&quot;;
</span><span class="cx">                 };
</span><span class="cx">                 5D247B5714689B8600E78B76 = {
</span><span class="lines">@@ -1131,6 +1134,7 @@
</span><span class="cx">                                 A8A4741F151A825B004123FF /* SegmentedVector.h in Headers */,
</span><span class="cx">                                 A8A47420151A825B004123FF /* SentinelLinkedList.h in Headers */,
</span><span class="cx">                                 A8A47422151A825B004123FF /* SHA1.h in Headers */,
</span><ins>+                                1AFDE648195201C300C48FFA /* TypeCasts.h in Headers */,
</ins><span class="cx">                                 A8A47423151A825B004123FF /* SimpleStats.h in Headers */,
</span><span class="cx">                                 A8A47424151A825B004123FF /* SinglyLinkedList.h in Headers */,
</span><span class="cx">                                 A748745317A0BDAE00FA04CB /* SixCharacterHash.h in Headers */,
</span></span></pre></div>
<a id="trunkSourceWTFwtfcfTypeCastsh"></a>
<div class="addfile"><h4>Added: trunk/Source/WTF/wtf/cf/TypeCasts.h (0 => 170108)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/cf/TypeCasts.h                                (rev 0)
+++ trunk/Source/WTF/wtf/cf/TypeCasts.h        2014-06-18 18:03:16 UTC (rev 170108)
</span><span class="lines">@@ -0,0 +1,75 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple 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:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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.
+ */
+
+#ifndef TypeCasts_h
+#define TypeCasts_h
+
+#include &lt;CoreFoundation/CoreFoundation.h&gt;
+#include &lt;wtf/Assertions.h&gt;
+
+namespace WTF {
+
+template &lt;typename&gt; struct CFTypeTrait;
+
+#define DECLARE_CF_TYPE_TRAIT(ClassName) \
+template &lt;&gt; \
+struct CFTypeTrait&lt;ClassName##Ref&gt; { \
+    static inline CFTypeID typeID() { return ClassName##GetTypeID(); } \
+};
+
+DECLARE_CF_TYPE_TRAIT(CFArray);
+DECLARE_CF_TYPE_TRAIT(CFBoolean);
+DECLARE_CF_TYPE_TRAIT(CFData);
+DECLARE_CF_TYPE_TRAIT(CFDictionary);
+DECLARE_CF_TYPE_TRAIT(CFNumber);
+DECLARE_CF_TYPE_TRAIT(CFString);
+
+#undef DECLARE_CF_TYPE_TRAIT
+
+template&lt;typename T&gt; T dynamic_cf_cast(CFTypeRef object)
+{
+    if (!object)
+        return nullptr;
+
+    if (CFGetTypeID(object) != CFTypeTrait&lt;T&gt;::typeID())
+        return nullptr;
+
+    return static_cast&lt;T&gt;(object);
+}
+
+template&lt;typename T&gt; T checked_cf_cast(CFTypeRef object)
+{
+    auto result = dynamic_cf_cast&lt;T&gt;(object);
+    ASSERT_WITH_SECURITY_IMPLICATION(result);
+
+    return result;
+}
+
+} // namespace WTF
+
+using WTF::checked_cf_cast;
+using WTF::dynamic_cf_cast;
+
+#endif // TypeCasts_h
</ins></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (170107 => 170108)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-06-18 17:58:28 UTC (rev 170107)
+++ trunk/Source/WebKit2/ChangeLog        2014-06-18 18:03:16 UTC (rev 170108)
</span><span class="lines">@@ -1,3 +1,23 @@
</span><ins>+2014-06-18  Anders Carlsson  &lt;andersca@apple.com&gt;
+
+        Add CF type cast function templates and use them in KeyedDecoder in WebKit2
+        https://bugs.webkit.org/show_bug.cgi?id=134033
+
+        Reviewed by Sam Weinig.
+
+        * Shared/cf/KeyedDecoder.cpp:
+        (WebKit::KeyedDecoder::KeyedDecoder):
+        (WebKit::KeyedDecoder::decodeBytes):
+        (WebKit::KeyedDecoder::decodeBool):
+        (WebKit::KeyedDecoder::decodeInt32):
+        (WebKit::KeyedDecoder::decodeInt64):
+        (WebKit::KeyedDecoder::decodeFloat):
+        (WebKit::KeyedDecoder::decodeDouble):
+        (WebKit::KeyedDecoder::decodeString):
+        (WebKit::KeyedDecoder::beginObject):
+        (WebKit::KeyedDecoder::beginArray):
+        (WebKit::KeyedDecoder::beginArrayElement):
+
</ins><span class="cx"> 2014-06-18  Dan Bernstein  &lt;mitz@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Remove the unused _WKBackForwardListDidChangeNotification.
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedcfKeyedDecodercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/cf/KeyedDecoder.cpp (170107 => 170108)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/cf/KeyedDecoder.cpp        2014-06-18 17:58:28 UTC (rev 170107)
+++ trunk/Source/WebKit2/Shared/cf/KeyedDecoder.cpp        2014-06-18 18:03:16 UTC (rev 170108)
</span><span class="lines">@@ -26,6 +26,7 @@
</span><span class="cx"> #include &quot;config.h&quot;
</span><span class="cx"> #include &quot;KeyedDecoder.h&quot;
</span><span class="cx"> 
</span><ins>+#include &lt;wtf/cf/TypeCasts.h&gt;
</ins><span class="cx"> #include &lt;wtf/text/WTFString.h&gt;
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="lines">@@ -33,10 +34,9 @@
</span><span class="cx"> KeyedDecoder::KeyedDecoder(const uint8_t* data, size_t size)
</span><span class="cx"> {
</span><span class="cx">     auto cfData = adoptCF(CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, data, size, kCFAllocatorNull));
</span><del>-    auto rootDictionary = adoptCF(CFPropertyListCreateWithData(kCFAllocatorDefault, cfData.get(), kCFPropertyListImmutable, nullptr, nullptr));
</del><span class="cx"> 
</span><del>-    if (rootDictionary &amp;&amp; CFGetTypeID(rootDictionary.get()) == CFDictionaryGetTypeID())
-        m_rootDictionary = adoptCF(static_cast&lt;CFDictionaryRef&gt;(rootDictionary.leakRef()));
</del><ins>+    if (auto rootDictionary = adoptCF(dynamic_cf_cast&lt;CFDictionaryRef&gt;(CFPropertyListCreateWithData(kCFAllocatorDefault, cfData.get(), kCFPropertyListImmutable, nullptr, nullptr))))
+        m_rootDictionary = std::move(rootDictionary);
</ins><span class="cx">     else
</span><span class="cx">         m_rootDictionary = adoptCF(CFDictionaryCreate(kCFAllocatorDefault, nullptr, nullptr, 0, &amp;kCFTypeDictionaryKeyCallBacks, &amp;kCFTypeDictionaryValueCallBacks));
</span><span class="cx">     m_dictionaryStack.append(m_rootDictionary.get());
</span><span class="lines">@@ -52,8 +52,8 @@
</span><span class="cx"> 
</span><span class="cx"> bool KeyedDecoder::decodeBytes(const String&amp; key, const uint8_t*&amp; bytes, size_t&amp; size)
</span><span class="cx"> {
</span><del>-    CFDataRef data = static_cast&lt;CFDataRef&gt;(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
-    if (!data || CFGetTypeID(data) != CFDataGetTypeID())
</del><ins>+    auto data = dynamic_cf_cast&lt;CFDataRef&gt;(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
+    if (!data)
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="cx">     bytes = CFDataGetBytePtr(data);
</span><span class="lines">@@ -63,8 +63,8 @@
</span><span class="cx"> 
</span><span class="cx"> bool KeyedDecoder::decodeBool(const String&amp; key, bool&amp; result)
</span><span class="cx"> {
</span><del>-    CFBooleanRef boolean = static_cast&lt;CFBooleanRef&gt;(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
-    if (!boolean || CFGetTypeID(boolean) != CFBooleanGetTypeID())
</del><ins>+    auto boolean = dynamic_cf_cast&lt;CFBooleanRef&gt;(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
+    if (!boolean)
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="cx">     result = CFBooleanGetValue(boolean);
</span><span class="lines">@@ -78,8 +78,8 @@
</span><span class="cx"> 
</span><span class="cx"> bool KeyedDecoder::decodeInt32(const String&amp; key, int32_t&amp; result)
</span><span class="cx"> {
</span><del>-    CFNumberRef number = static_cast&lt;CFNumberRef&gt;(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
-    if (!number || CFGetTypeID(number) != CFNumberGetTypeID())
</del><ins>+    auto number = dynamic_cf_cast&lt;CFNumberRef&gt;(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
+    if (!number)
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="cx">     return CFNumberGetValue(number, kCFNumberSInt32Type, &amp;result);
</span><span class="lines">@@ -87,8 +87,8 @@
</span><span class="cx"> 
</span><span class="cx"> bool KeyedDecoder::decodeInt64(const String&amp; key, int64_t&amp; result)
</span><span class="cx"> {
</span><del>-    CFNumberRef number = static_cast&lt;CFNumberRef&gt;(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
-    if (!number || CFGetTypeID(number) != CFNumberGetTypeID())
</del><ins>+    auto number = dynamic_cf_cast&lt;CFNumberRef&gt;(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
+    if (!number)
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="cx">     return CFNumberGetValue(number, kCFNumberSInt64Type, &amp;result);
</span><span class="lines">@@ -96,8 +96,8 @@
</span><span class="cx"> 
</span><span class="cx"> bool KeyedDecoder::decodeFloat(const String&amp; key, float&amp; result)
</span><span class="cx"> {
</span><del>-    CFNumberRef number = static_cast&lt;CFNumberRef&gt;(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
-    if (!number || CFGetTypeID(number) != CFNumberGetTypeID())
</del><ins>+    auto number = dynamic_cf_cast&lt;CFNumberRef&gt;(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
+    if (!number)
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="cx">     return CFNumberGetValue(number, kCFNumberFloatType, &amp;result);
</span><span class="lines">@@ -105,8 +105,8 @@
</span><span class="cx"> 
</span><span class="cx"> bool KeyedDecoder::decodeDouble(const String&amp; key, double&amp; result)
</span><span class="cx"> {
</span><del>-    CFNumberRef number = static_cast&lt;CFNumberRef&gt;(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
-    if (!number || CFGetTypeID(number) != CFNumberGetTypeID())
</del><ins>+    auto number = dynamic_cf_cast&lt;CFNumberRef&gt;(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
+    if (!number)
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="cx">     return CFNumberGetValue(number, kCFNumberDoubleType, &amp;result);
</span><span class="lines">@@ -114,8 +114,8 @@
</span><span class="cx"> 
</span><span class="cx"> bool KeyedDecoder::decodeString(const String&amp; key, String&amp; result)
</span><span class="cx"> {
</span><del>-    CFStringRef string = static_cast&lt;CFStringRef&gt;(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
-    if (!string || CFGetTypeID(string) != CFStringGetTypeID())
</del><ins>+    auto string = dynamic_cf_cast&lt;CFStringRef&gt;(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
+    if (!string)
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="cx">     result = string;
</span><span class="lines">@@ -124,8 +124,8 @@
</span><span class="cx"> 
</span><span class="cx"> bool KeyedDecoder::beginObject(const String&amp; key)
</span><span class="cx"> {
</span><del>-    CFDictionaryRef dictionary = static_cast&lt;CFDictionaryRef&gt;(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
-    if (!dictionary || CFGetTypeID(dictionary) != CFDictionaryGetTypeID())
</del><ins>+    auto dictionary = dynamic_cf_cast&lt;CFDictionaryRef&gt;(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
+    if (!dictionary)
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="cx">     m_dictionaryStack.append(dictionary);
</span><span class="lines">@@ -139,8 +139,8 @@
</span><span class="cx"> 
</span><span class="cx"> bool KeyedDecoder::beginArray(const String&amp; key)
</span><span class="cx"> {
</span><del>-    CFArrayRef array = static_cast&lt;CFArrayRef&gt;(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
-    if (!array || CFGetTypeID(array) != CFArrayGetTypeID())
</del><ins>+    auto array = dynamic_cf_cast&lt;CFArrayRef&gt;(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
+    if (!array)
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="cx">     for (CFIndex i = 0; i &lt; CFArrayGetCount(array); ++i) {
</span><span class="lines">@@ -159,7 +159,7 @@
</span><span class="cx">     if (m_arrayIndexStack.last() &gt;= CFArrayGetCount(m_arrayStack.last()))
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><del>-    CFDictionaryRef dictionary = static_cast&lt;CFDictionaryRef&gt;(CFArrayGetValueAtIndex(m_arrayStack.last(), m_arrayIndexStack.last()++));
</del><ins>+    auto dictionary = checked_cf_cast&lt;CFDictionaryRef&gt;(CFArrayGetValueAtIndex(m_arrayStack.last(), m_arrayIndexStack.last()++));
</ins><span class="cx">     m_dictionaryStack.append(dictionary);
</span><span class="cx">     return true;
</span><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>