[Cocoa] Avoid some double-wrapping of strings and URLs
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Nov 2013 21:26:50 +0000 (21:26 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Nov 2013 21:26:50 +0000 (21:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=123632

Reviewed by Anders Carlsson.

* Shared/API/c/cf/WKStringCF.cpp: Removed.
* Shared/API/c/cf/WKStringCF.mm: Copied from Source/WebKit2/Shared/API/c/cf/WKStringCF.cpp.
(wkNSStringClass): Added this helper.
(WKStringCreateWithCFString): If the passed-in CFString is already wrapping a WebString,
then retain it and return it.
* Shared/API/c/cf/WKURLCF.cpp: Removed.
* Shared/API/c/cf/WKURLCF.mm: Copied from Source/WebKit2/Shared/API/c/cf/WKURLCF.cpp.
(wkNSURLClass): Added this helper.
(WKURLCreateWithCFURL): If the passed-in CFURL is already wrapping a WebURL, then retain it
and return it.
* WebKit2.xcodeproj/project.pbxproj: Updated for renames.

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

Source/WebKit2/ChangeLog
Source/WebKit2/Shared/API/c/cf/WKStringCF.mm [moved from Source/WebKit2/Shared/API/c/cf/WKStringCF.cpp with 76% similarity]
Source/WebKit2/Shared/API/c/cf/WKURLCF.mm [moved from Source/WebKit2/Shared/API/c/cf/WKURLCF.cpp with 77% similarity]
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

index cb0a1a5f7c785a0e0c9ed25dce3dea651cc96556..6bf29a6e14648b9c8a9268cfb895d5840923110c 100644 (file)
@@ -1,3 +1,22 @@
+2013-11-01  Dan Bernstein  <mitz@apple.com>
+
+        [Cocoa] Avoid some double-wrapping of strings and URLs
+        https://bugs.webkit.org/show_bug.cgi?id=123632
+
+        Reviewed by Anders Carlsson.
+
+        * Shared/API/c/cf/WKStringCF.cpp: Removed.
+        * Shared/API/c/cf/WKStringCF.mm: Copied from Source/WebKit2/Shared/API/c/cf/WKStringCF.cpp.
+        (wkNSStringClass): Added this helper.
+        (WKStringCreateWithCFString): If the passed-in CFString is already wrapping a WebString,
+        then retain it and return it.
+        * Shared/API/c/cf/WKURLCF.cpp: Removed.
+        * Shared/API/c/cf/WKURLCF.mm: Copied from Source/WebKit2/Shared/API/c/cf/WKURLCF.cpp.
+        (wkNSURLClass): Added this helper.
+        (WKURLCreateWithCFURL): If the passed-in CFURL is already wrapping a WebURL, then retain it
+        and return it.
+        * WebKit2.xcodeproj/project.pbxproj: Updated for renames.
+
 2013-11-01  Anders Carlsson  <andersca@apple.com>
 
         Begin work on encoding argument types
similarity index 76%
rename from Source/WebKit2/Shared/API/c/cf/WKStringCF.cpp
rename to Source/WebKit2/Shared/API/c/cf/WKStringCF.mm
index f5ab629081bb5f68ec7486395b7c83e6d3f10a69..a3bf723a274aac0d6bed69e492d421b5565e3a98 100644 (file)
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "config.h"
-#include "WKStringCF.h"
+#import "config.h"
+#import "WKStringCF.h"
 
-#include "WKAPICast.h"
-#include <wtf/text/WTFString.h>
+#import "WKAPICast.h"
+#import "WKNSString.h"
+#import <objc/runtime.h>
+#import <wtf/text/WTFString.h>
 
 using namespace WebCore;
 using namespace WebKit;
 
+#if WK_API_ENABLED
+static inline Class wkNSStringClass()
+{
+    static dispatch_once_t once;
+    static Class wkNSStringClass;
+    dispatch_once(&once, ^{
+        wkNSStringClass = [WKNSString class];
+    });
+    return wkNSStringClass;
+}
+#endif // WK_API_ENABLED
+
 WKStringRef WKStringCreateWithCFString(CFStringRef cfString)
 {
+#if WK_API_ENABLED
+    // Since WKNSString is an internal class with no subclasses, we can do a simple equality check.
+    if (object_getClass((NSString *)cfString) == wkNSStringClass()) {
+        return toAPI(static_cast<WebString*>(&[(WKNSString *)cfString retain]._apiObject));
+    }
+#endif
     String string(cfString);
     return toCopiedAPI(string);
 }
similarity index 77%
rename from Source/WebKit2/Shared/API/c/cf/WKURLCF.cpp
rename to Source/WebKit2/Shared/API/c/cf/WKURLCF.mm
index 47564ebbba7558a5c1a12ad90c680378de8e9406..882e4f1854b15b70450e6a59a61564b963eaf1b3 100644 (file)
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "config.h"
-#include "WKURLCF.h"
+#import "config.h"
+#import "WKURLCF.h"
 
-#include "WKAPICast.h"
-#include <WebCore/CFURLExtras.h>
-#include <wtf/PassRefPtr.h>
-#include <wtf/RefPtr.h>
-#include <wtf/text/CString.h>
-#include <wtf/text/WTFString.h>
+#import "WKAPICast.h"
+#import "WKNSURL.h"
+#import <WebCore/CFURLExtras.h>
+#import <objc/runtime.h>
+#import <wtf/PassRefPtr.h>
+#import <wtf/RefPtr.h>
+#import <wtf/text/CString.h>
+#import <wtf/text/WTFString.h>
 
 using namespace WebCore;
 using namespace WebKit;
 
+#if WK_API_ENABLED
+static inline Class wkNSURLClass()
+{
+    static dispatch_once_t once;
+    static Class wkNSURLClass;
+    dispatch_once(&once, ^{
+        wkNSURLClass = [WKNSURL class];
+    });
+    return wkNSURLClass;
+}
+#endif // WK_API_ENABLED
+
 WKURLRef WKURLCreateWithCFURL(CFURLRef cfURL)
 {
     if (!cfURL)
         return 0;
 
+#if WK_API_ENABLED
+    // Since WKNSURL is an internal class with no subclasses, we can do a simple equality check.
+    if (object_getClass((NSURL *)cfURL) == wkNSURLClass()) {
+        return toAPI(static_cast<WebURL*>(&[(WKNSURL *)cfURL retain]._apiObject));
+    }
+#endif
+
     CString urlBytes;
     getURLBytes(cfURL, urlBytes);
 
index 87572aaa89fb0752a6003001f1d18dfb6bb9d3e5..f7708188a4303f7ce2a18ba83e841e1ec214a77e 100644 (file)
                BC40760C124FF0270068F20A /* WKURLRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = BC4075F0124FF0270068F20A /* WKURLRequest.h */; settings = {ATTRIBUTES = (Private, ); }; };
                BC40760D124FF0270068F20A /* WKURLResponse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC4075F1124FF0270068F20A /* WKURLResponse.cpp */; };
                BC40760E124FF0270068F20A /* WKURLResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = BC4075F2124FF0270068F20A /* WKURLResponse.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               BC407619124FF0370068F20A /* WKStringCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC407611124FF0370068F20A /* WKStringCF.cpp */; };
+               BC407619124FF0370068F20A /* WKStringCF.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC407611124FF0370068F20A /* WKStringCF.mm */; };
                BC40761A124FF0370068F20A /* WKStringCF.h in Headers */ = {isa = PBXBuildFile; fileRef = BC407612124FF0370068F20A /* WKStringCF.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               BC40761B124FF0370068F20A /* WKURLCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC407613124FF0370068F20A /* WKURLCF.cpp */; };
+               BC40761B124FF0370068F20A /* WKURLCF.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC407613124FF0370068F20A /* WKURLCF.mm */; };
                BC40761C124FF0370068F20A /* WKURLCF.h in Headers */ = {isa = PBXBuildFile; fileRef = BC407614124FF0370068F20A /* WKURLCF.h */; settings = {ATTRIBUTES = (Private, ); }; };
                BC407627124FF0400068F20A /* WKCertificateInfoMac.h in Headers */ = {isa = PBXBuildFile; fileRef = BC407621124FF0400068F20A /* WKCertificateInfoMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
                BC407628124FF0400068F20A /* WKCertificateInfoMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC407622124FF0400068F20A /* WKCertificateInfoMac.mm */; };
                BC4075F0124FF0270068F20A /* WKURLRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKURLRequest.h; sourceTree = "<group>"; };
                BC4075F1124FF0270068F20A /* WKURLResponse.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKURLResponse.cpp; sourceTree = "<group>"; };
                BC4075F2124FF0270068F20A /* WKURLResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKURLResponse.h; sourceTree = "<group>"; };
-               BC407611124FF0370068F20A /* WKStringCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKStringCF.cpp; sourceTree = "<group>"; };
+               BC407611124FF0370068F20A /* WKStringCF.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKStringCF.mm; sourceTree = "<group>"; };
                BC407612124FF0370068F20A /* WKStringCF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKStringCF.h; sourceTree = "<group>"; };
-               BC407613124FF0370068F20A /* WKURLCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKURLCF.cpp; sourceTree = "<group>"; };
+               BC407613124FF0370068F20A /* WKURLCF.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKURLCF.mm; sourceTree = "<group>"; };
                BC407614124FF0370068F20A /* WKURLCF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKURLCF.h; sourceTree = "<group>"; };
                BC407621124FF0400068F20A /* WKCertificateInfoMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKCertificateInfoMac.h; sourceTree = "<group>"; };
                BC407622124FF0400068F20A /* WKCertificateInfoMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKCertificateInfoMac.mm; sourceTree = "<group>"; };
                        children = (
                                BCFD5489132D82680055D816 /* WKErrorCF.cpp */,
                                BCFD548A132D82680055D816 /* WKErrorCF.h */,
-                               BC407611124FF0370068F20A /* WKStringCF.cpp */,
+                               BC407611124FF0370068F20A /* WKStringCF.mm */,
                                BC407612124FF0370068F20A /* WKStringCF.h */,
-                               BC407613124FF0370068F20A /* WKURLCF.cpp */,
+                               BC407613124FF0370068F20A /* WKURLCF.mm */,
                                BC407614124FF0370068F20A /* WKURLCF.h */,
                        );
                        path = cf;
                                F634445C12A885E9000612D8 /* WKSecurityOrigin.cpp in Sources */,
                                BC407603124FF0270068F20A /* WKSerializedScriptValue.cpp in Sources */,
                                BC407605124FF0270068F20A /* WKString.cpp in Sources */,
-                               BC407619124FF0370068F20A /* WKStringCF.cpp in Sources */,
+                               BC407619124FF0370068F20A /* WKStringCF.mm in Sources */,
                                1A4A9AA912B7E796008FE984 /* WKTextInputWindowController.mm in Sources */,
                                BC407607124FF0270068F20A /* WKType.cpp in Sources */,
                                7CD5EBBE1746B04C000C1C45 /* WKTypeRefWrapper.mm in Sources */,
                                BC407609124FF0270068F20A /* WKURL.cpp in Sources */,
-                               BC40761B124FF0370068F20A /* WKURLCF.cpp in Sources */,
+                               BC40761B124FF0370068F20A /* WKURLCF.mm in Sources */,
                                BC40760B124FF0270068F20A /* WKURLRequest.cpp in Sources */,
                                BC40762A124FF0400068F20A /* WKURLRequestNS.mm in Sources */,
                                512A9760180E031D0039A149 /* DatabaseProcessMessageReceiver.cpp in Sources */,