[Cocoa] Make all API objects have Cocoa wrappers, and delegate refcounting to those...
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Oct 2013 22:49:20 +0000 (22:49 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Oct 2013 22:49:20 +0000 (22:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=123394

Reviewed by Darin Adler.

All wrappers conform to a new WKObject protocol and contain the wrapped object inline.
APIObject-derived classes override operator new to call newObject, which allocates the
wrapper and returns a pointer to the inline API object.

There are three kinds of wrapper classes: (a) classes that inherit directly from NSObject
and implement their API by calling the wrapped object (example: WKBackForwardList),
(b) internal classes that inherit from a class cluster, and implement the primitive methods
of the class cluster by calling the wrapped object (example: WKNSArray), and (c) internal
classes that inerit from the new WKObject class, and proxy to an object of some public type,
which is created from the wrapped object (example: WKNSURL).

* Shared/APIObject.h:
(WebKit::APIObject::wrapper): Added this getter.
(WebKit::TypedAPIObject::operator new): Added override that calls newObject.
* Shared/Cocoa/APIObject.mm: Added.
(WebKit::APIObject::ref): Retains the wrapper.
(WebKit::APIObject::deref): Releases the wrapper. When the wrapper is deallocated, it calls
the API object destructor.
(WebKit::APIObject::newObject): Allocates the wrapper and returns a pointer to the API
object inside the wrapper.

* Shared/Cocoa/WKNSArray.h:
(WebKit::wrapper): Added. Returns an ImmutableArray’s wrapper as an NSArray.
Replaced the RefPtr<ImmutableArray> ivar with space for an ImmutableArray to live inside
the wrapper.
(-[WKNSArray dealloc]): Calls the ImmutableArray destructor.
(-[WKNSArray count]): Updated for ivar change.
(-[WKNSArray objectAtIndex:]): Ditto.
(-[WKNSArray _apiObject]): Returns the wrapped ImmutableArray.

* Shared/Cocoa/WKNSObjectExtras.h: Removed.
* Shared/Cocoa/WKNSObjectExtras.mm: Removed.

* Shared/Cocoa/WKNSString.h: Added.
* Shared/Cocoa/WKNSString.mm: Added.
(-[WKNSString _web_createTarget]): Override this WKObject method to create an NSString from
the WebString.
(-[WKNSString copyWithZone:]): Retains self.

* Shared/Cocoa/WKNSURL.h: Added.
* Shared/Cocoa/WKNSURL.mm: Added.
(-[WKNSURL _web_createTarget]): Override this WKObject method to create an NSURL from
the WebURL.
(-[WKNSURL copyWithZone:]): Retains self.

* Shared/Cocoa/WKObject.h: Added.
* Shared/Cocoa/WKObject.mm: Added.
(-[WKObject dealloc]): Calls the destructor of the wrapped object and releases the target
object.
(initializeTargetIfNeeded): Helper function. Tries to create the target exactly once.
(-[WKObject isEqual:]): NSObject override that creates and compares to the target
object if necessary.
(-[WKObject hash]): NSObject override that creates and hashes the target object if
there is one.
(-[WKObject isKindOfClass:]): NSObject override that delegates to the target object.
(-[WKObject isMemberOfClass:]): Ditto.
(-[WKObject respondsToSelector:]): NSObject override that creates the target object if
necessary and returns whether it or self responds to the selector.
(-[WKObject conformsToProtocol:]): Similarly for protocols.
(-[WKObject forwardingTargetForSelector:]): NSObject override that creates the target object
if necessary and returns it as the target.
(-[WKObject description]): NSObject override that creates the target object if necessary and
forwards to it.
(-[WKObject _web_createTarget]): Added. The base implementation returns nil.
(-[WKObject _apiObject]): Returns the wrapped object.

* UIProcess/API/mac/WKBrowsingContextController.mm:
(-[WKBrowsingContextController backForwardList]): Changed to return the existing wrapper.
(didChangeBackForwardList): Changed to use existing wrappers.

Replaced the RefPtr<WebBackForwardList> ivar with space for a WebBackForwardList to live
inside the wrapper.
(-[WKBackForwardList dealloc]): Call the WebBackForwardList destructor.
(toWKBackForwardListItem): Changed to us the existing wrapper.
(-[WKBackForwardList currentItem]): Updated for ivar change.
(-[WKBackForwardList backItem]): Ditto.
(-[WKBackForwardList forwardItem]): Ditto.
(-[WKBackForwardList itemAtIndex:]): Ditto.
(-[WKBackForwardList backListCount]): Ditto.
(-[WKBackForwardList forwardListCount]): Ditto,
(-[WKBackForwardList backListWithLimit:]): Ditto, and also changed to use the
ImmutableArray’s existing wrapper.
(-[WKBackForwardList forwardListWithLimit:]): Ditto.
(-[WKBackForwardList _apiObject]): Returns the WebBackForwardListItem.
* UIProcess/Cocoa/WKBackForwardListInternal.h:
(WebKit::wrapper): Added. Returns a WebBackForwardList’s wrapper as a WKBackForwardList.

* UIProcess/Cocoa/WKBackForwardListItem.mm:
Replaced the RefPtr<WebBackForwardListItem> ivar with space for a WebBackForwardListItem to
live inside the wrapper.
(-[WKBackForwardListItem dealloc]): Call the WebBackForwardListItem destructor.
(-[WKBackForwardListItem URL]): Updated for ivar change, and changed to make an NSURL
directly instead of going through a wrapper.
(-[WKBackForwardListItem title]): Updated for ivar change, and changed to use
String’s operator NSString*.
(-[WKBackForwardListItem originalURL]): Updated for ivar change, and changed to make an
NSURL directly instead of going through a wrapper.
(-[WKBackForwardListItem _apiObject]): Returns the WebBackForwardListItem.
(-[WKBackForwardListItem _item]): Ditto.
* UIProcess/Cocoa/WKBackForwardListItemInternal.h:
(WebKit::wrapper): Added. Returns a WebBackForwardListItem’s wrapper as a
WKBackForwardListItem.

* UIProcess/WebColorPickerResultListenerProxy.h: Changed into a TypedAPIObject.

* UIProcess/WebFormSubmissionListenerProxy.h:
(WebKit::WebFormSubmissionListenerProxy::operator new): Override to call newObject.

* UIProcess/WebFramePolicyListenerProxy.h:
(WebKit::WebFramePolicyListenerProxy::operator new): Ditto.

* WebKit2.xcodeproj/project.pbxproj: Updated for file additions and removals.

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

20 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/APIObject.h
Source/WebKit2/Shared/Cocoa/APIObject.mm [new file with mode: 0644]
Source/WebKit2/Shared/Cocoa/WKNSArray.h
Source/WebKit2/Shared/Cocoa/WKNSArray.mm
Source/WebKit2/Shared/Cocoa/WKNSString.h [moved from Source/WebKit2/Shared/Cocoa/WKNSObjectExtras.h with 91% similarity]
Source/WebKit2/Shared/Cocoa/WKNSString.mm [moved from Source/WebKit2/Shared/Cocoa/WKNSObjectExtras.mm with 53% similarity]
Source/WebKit2/Shared/Cocoa/WKNSURL.h [new file with mode: 0644]
Source/WebKit2/Shared/Cocoa/WKNSURL.mm [new file with mode: 0644]
Source/WebKit2/Shared/Cocoa/WKObject.h [new file with mode: 0644]
Source/WebKit2/Shared/Cocoa/WKObject.mm [new file with mode: 0644]
Source/WebKit2/UIProcess/API/mac/WKBrowsingContextController.mm
Source/WebKit2/UIProcess/Cocoa/WKBackForwardList.mm
Source/WebKit2/UIProcess/Cocoa/WKBackForwardListInternal.h
Source/WebKit2/UIProcess/Cocoa/WKBackForwardListItem.mm
Source/WebKit2/UIProcess/Cocoa/WKBackForwardListItemInternal.h
Source/WebKit2/UIProcess/WebColorPickerResultListenerProxy.h
Source/WebKit2/UIProcess/WebFormSubmissionListenerProxy.h
Source/WebKit2/UIProcess/WebFramePolicyListenerProxy.h
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

index 0c700b4..5204682 100644 (file)
@@ -1,3 +1,123 @@
+2013-10-30  Dan Bernstein  <mitz@apple.com>
+
+        [Cocoa] Make all API objects have Cocoa wrappers, and delegate refcounting to those wrappers
+        https://bugs.webkit.org/show_bug.cgi?id=123394
+
+        Reviewed by Darin Adler.
+
+        All wrappers conform to a new WKObject protocol and contain the wrapped object inline.
+        APIObject-derived classes override operator new to call newObject, which allocates the
+        wrapper and returns a pointer to the inline API object.
+
+        There are three kinds of wrapper classes: (a) classes that inherit directly from NSObject
+        and implement their API by calling the wrapped object (example: WKBackForwardList),
+        (b) internal classes that inherit from a class cluster, and implement the primitive methods
+        of the class cluster by calling the wrapped object (example: WKNSArray), and (c) internal
+        classes that inerit from the new WKObject class, and proxy to an object of some public type,
+        which is created from the wrapped object (example: WKNSURL).
+
+        * Shared/APIObject.h:
+        (WebKit::APIObject::wrapper): Added this getter.
+        (WebKit::TypedAPIObject::operator new): Added override that calls newObject.
+        * Shared/Cocoa/APIObject.mm: Added.
+        (WebKit::APIObject::ref): Retains the wrapper.
+        (WebKit::APIObject::deref): Releases the wrapper. When the wrapper is deallocated, it calls
+        the API object destructor.
+        (WebKit::APIObject::newObject): Allocates the wrapper and returns a pointer to the API
+        object inside the wrapper.
+
+        * Shared/Cocoa/WKNSArray.h:
+        (WebKit::wrapper): Added. Returns an ImmutableArray’s wrapper as an NSArray.
+        Replaced the RefPtr<ImmutableArray> ivar with space for an ImmutableArray to live inside
+        the wrapper.
+        (-[WKNSArray dealloc]): Calls the ImmutableArray destructor.
+        (-[WKNSArray count]): Updated for ivar change.
+        (-[WKNSArray objectAtIndex:]): Ditto.
+        (-[WKNSArray _apiObject]): Returns the wrapped ImmutableArray.
+
+        * Shared/Cocoa/WKNSObjectExtras.h: Removed.
+        * Shared/Cocoa/WKNSObjectExtras.mm: Removed.
+
+        * Shared/Cocoa/WKNSString.h: Added.
+        * Shared/Cocoa/WKNSString.mm: Added.
+        (-[WKNSString _web_createTarget]): Override this WKObject method to create an NSString from
+        the WebString.
+        (-[WKNSString copyWithZone:]): Retains self.
+
+        * Shared/Cocoa/WKNSURL.h: Added.
+        * Shared/Cocoa/WKNSURL.mm: Added.
+        (-[WKNSURL _web_createTarget]): Override this WKObject method to create an NSURL from
+        the WebURL.
+        (-[WKNSURL copyWithZone:]): Retains self.
+
+        * Shared/Cocoa/WKObject.h: Added.
+        * Shared/Cocoa/WKObject.mm: Added.
+        (-[WKObject dealloc]): Calls the destructor of the wrapped object and releases the target
+        object.
+        (initializeTargetIfNeeded): Helper function. Tries to create the target exactly once.
+        (-[WKObject isEqual:]): NSObject override that creates and compares to the target
+        object if necessary.
+        (-[WKObject hash]): NSObject override that creates and hashes the target object if
+        there is one.
+        (-[WKObject isKindOfClass:]): NSObject override that delegates to the target object.
+        (-[WKObject isMemberOfClass:]): Ditto.
+        (-[WKObject respondsToSelector:]): NSObject override that creates the target object if
+        necessary and returns whether it or self responds to the selector.
+        (-[WKObject conformsToProtocol:]): Similarly for protocols.
+        (-[WKObject forwardingTargetForSelector:]): NSObject override that creates the target object
+        if necessary and returns it as the target.
+        (-[WKObject description]): NSObject override that creates the target object if necessary and
+        forwards to it.
+        (-[WKObject _web_createTarget]): Added. The base implementation returns nil.
+        (-[WKObject _apiObject]): Returns the wrapped object.
+
+        * UIProcess/API/mac/WKBrowsingContextController.mm:
+        (-[WKBrowsingContextController backForwardList]): Changed to return the existing wrapper.
+        (didChangeBackForwardList): Changed to use existing wrappers.
+
+        Replaced the RefPtr<WebBackForwardList> ivar with space for a WebBackForwardList to live
+        inside the wrapper.
+        (-[WKBackForwardList dealloc]): Call the WebBackForwardList destructor.
+        (toWKBackForwardListItem): Changed to us the existing wrapper.
+        (-[WKBackForwardList currentItem]): Updated for ivar change.
+        (-[WKBackForwardList backItem]): Ditto.
+        (-[WKBackForwardList forwardItem]): Ditto.
+        (-[WKBackForwardList itemAtIndex:]): Ditto.
+        (-[WKBackForwardList backListCount]): Ditto.
+        (-[WKBackForwardList forwardListCount]): Ditto,
+        (-[WKBackForwardList backListWithLimit:]): Ditto, and also changed to use the
+        ImmutableArray’s existing wrapper.
+        (-[WKBackForwardList forwardListWithLimit:]): Ditto.
+        (-[WKBackForwardList _apiObject]): Returns the WebBackForwardListItem.
+        * UIProcess/Cocoa/WKBackForwardListInternal.h:
+        (WebKit::wrapper): Added. Returns a WebBackForwardList’s wrapper as a WKBackForwardList.
+
+        * UIProcess/Cocoa/WKBackForwardListItem.mm:
+        Replaced the RefPtr<WebBackForwardListItem> ivar with space for a WebBackForwardListItem to
+        live inside the wrapper.
+        (-[WKBackForwardListItem dealloc]): Call the WebBackForwardListItem destructor.
+        (-[WKBackForwardListItem URL]): Updated for ivar change, and changed to make an NSURL
+        directly instead of going through a wrapper.
+        (-[WKBackForwardListItem title]): Updated for ivar change, and changed to use
+        String’s operator NSString*.
+        (-[WKBackForwardListItem originalURL]): Updated for ivar change, and changed to make an
+        NSURL directly instead of going through a wrapper.
+        (-[WKBackForwardListItem _apiObject]): Returns the WebBackForwardListItem.
+        (-[WKBackForwardListItem _item]): Ditto.
+        * UIProcess/Cocoa/WKBackForwardListItemInternal.h:
+        (WebKit::wrapper): Added. Returns a WebBackForwardListItem’s wrapper as a
+        WKBackForwardListItem.
+
+        * UIProcess/WebColorPickerResultListenerProxy.h: Changed into a TypedAPIObject.
+
+        * UIProcess/WebFormSubmissionListenerProxy.h:
+        (WebKit::WebFormSubmissionListenerProxy::operator new): Override to call newObject.
+
+        * UIProcess/WebFramePolicyListenerProxy.h:
+        (WebKit::WebFramePolicyListenerProxy::operator new): Ditto.
+
+        * WebKit2.xcodeproj/project.pbxproj: Updated for file additions and removals.
+
 2013-10-30  Anders Carlsson  <andersca@apple.com>
 
         Begin fleshing out an API test for WKRemoteObjectRegistry
index 70321b9..b250ae7 100644 (file)
 
 #include <wtf/RefCounted.h>
 
+#if PLATFORM(MAC)
+#include "WKFoundation.h"
+#endif
+
+#define DELEGATE_REF_COUNTING_TO_COCOA (PLATFORM(MAC) && WK_API_ENABLED)
+
+#if DELEGATE_REF_COUNTING_TO_COCOA
+OBJC_CLASS NSObject;
+#endif
+
 namespace WebKit {
 
-class APIObject : public ThreadSafeRefCounted<APIObject> {
+class APIObject
+#if !DELEGATE_REF_COUNTING_TO_COCOA
+    : public ThreadSafeRefCounted<APIObject>
+#endif
+{
 public:
     enum Type {
         // Base types
@@ -151,8 +165,25 @@ public:
 
     virtual Type type() const = 0;
 
+#if DELEGATE_REF_COUNTING_TO_COCOA
+    NSObject *wrapper() { return m_wrapper; }
+
+    void ref();
+    void deref();
+#endif // DELEGATE_REF_COUNTING_TO_COCOA
+
 protected:
     APIObject();
+
+#if DELEGATE_REF_COUNTING_TO_COCOA
+    static void* newObject(size_t, Type);
+
+private:
+    // Derived classes must override operator new and call newObject().
+    void* operator new(size_t) = delete;
+
+    NSObject *m_wrapper;
+#endif // DELEGATE_REF_COUNTING_TO_COCOA
 };
 
 template <APIObject::Type ArgumentType>
@@ -170,8 +201,14 @@ protected:
     }
 
     virtual Type type() const OVERRIDE { return APIType; }
+
+#if DELEGATE_REF_COUNTING_TO_COCOA
+    void* operator new(size_t size) { return newObject(size, APIType); }
+#endif
 };
 
 } // namespace WebKit
 
+#undef DELEGATE_REF_COUNTING_TO_COCOA
+
 #endif // APIObject_h
diff --git a/Source/WebKit2/Shared/Cocoa/APIObject.mm b/Source/WebKit2/Shared/Cocoa/APIObject.mm
new file mode 100644 (file)
index 0000000..652bd23
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+#import "config.h"
+#import "APIObject.h"
+
+#import "WKBackForwardListInternal.h"
+#import "WKBackForwardListItemInternal.h"
+#import "WKNSArray.h"
+#import "WKNSString.h"
+#import "WKNSURL.h"
+
+namespace WebKit {
+
+void APIObject::ref()
+{
+    [wrapper() retain];
+}
+
+void APIObject::deref()
+{
+    [wrapper() release];
+}
+
+void* APIObject::newObject(size_t size, Type type)
+{
+    NSObject <WKObject> *wrapper;
+
+    // Wrappers that inherit from WKObject store the APIObject in their extra bytes, so they are
+    // allocated using NSAllocatedObject. The other wrapper classes contain inline storage for the
+    // APIObject, so they are allocated using +alloc.
+
+    switch (type) {
+    case TypeArray:
+        wrapper = [WKNSArray alloc];
+        break;
+
+    case TypeBackForwardList:
+        wrapper = [WKBackForwardList alloc];
+        break;
+
+    case TypeBackForwardListItem:
+        wrapper = [WKBackForwardListItem alloc];
+        break;
+
+    case TypeString:
+        wrapper = NSAllocateObject([WKNSString class], size, nullptr);
+        break;
+
+    case TypeURL:
+        wrapper = NSAllocateObject([WKNSURL class], size, nullptr);
+        break;
+
+    default:
+        wrapper = NSAllocateObject([WKObject class], size, nullptr);
+        break;
+    }
+
+    APIObject* object = &wrapper._apiObject;
+    object->m_wrapper = wrapper;
+    return object;
+}
+
+} // namespace WebKit
index 836ddbd..4bca2ae 100644 (file)
 
 #if WK_API_ENABLED
 
+#import "ImmutableArray.h"
+#import "WKObject.h"
+
 namespace WebKit {
-class ImmutableArray;
+inline NSArray *wrapper(ImmutableArray& array) { ASSERT([array.wrapper() isKindOfClass:[NSArray class]]); return (NSArray *)array.wrapper(); }
 }
 
-@interface WKNSArray : NSArray
-
-+ (id)web_arrayWithImmutableArray:(WebKit::ImmutableArray&)array;
-
-- (id)web_initWithImmutableArray:(WebKit::ImmutableArray&)array NS_REPLACES_RECEIVER;
-
+@interface WKNSArray : NSArray <WKObject>
 @end
 
 #endif // WK_API_ENABLED
index 4fbb4c7..faa132a 100644 (file)
 
 #if WK_API_ENABLED
 
-#import "ImmutableArray.h"
-#import "WKNSObjectExtras.h"
-
 using namespace WebKit;
 
 @implementation WKNSArray {
-    RefPtr<ImmutableArray> _array;
+    std::aligned_storage<sizeof(ImmutableArray), std::alignment_of<ImmutableArray>::value>::type _array;
 }
 
-+ (id)web_arrayWithImmutableArray:(WebKit::ImmutableArray&)array
+- (void)dealloc
 {
-    return [[[[self class] alloc] web_initWithImmutableArray:array] autorelease];
-}
-
-- (id)web_initWithImmutableArray:(ImmutableArray&)array
-{
-    if (!(self = [super init]))
-        return nil;
-
-    _array = &array;
+    reinterpret_cast<ImmutableArray*>(&_array)->~ImmutableArray();
 
-    return self;
+    [super dealloc];
 }
 
+#pragma mark NSArray primitive methods
+
 - (NSUInteger)count
 {
-    return _array->size();
+    return reinterpret_cast<ImmutableArray*>(&_array)->size();
 }
 
 - (id)objectAtIndex:(NSUInteger)i
 {
-    return [NSObject _web_objectWithAPIObject:_array->at(i)];
+    return reinterpret_cast<ImmutableArray*>(&_array)->at(i)->wrapper();
 }
 
-#pragma mark NSCopying protocol implementation
+#pragma mark NSCopying protocol implementation
 
 - (id)copyWithZone:(NSZone *)zone
 {
     return [self retain];
 }
 
+#pragma mark WKObject protocol implementation
+
+- (APIObject&)_apiObject
+{
+    return *reinterpret_cast<APIObject*>(&_array);
+}
+
 @end
 
 #endif // WK_API_ENABLED
similarity index 91%
rename from Source/WebKit2/Shared/Cocoa/WKNSObjectExtras.h
rename to Source/WebKit2/Shared/Cocoa/WKNSString.h
index 53b0cea..a0d1e65 100644 (file)
 
 #if WK_API_ENABLED
 
-namespace WebKit {
-class APIObject;
-}
-
-@interface NSObject (WKExtras)
-
-+ (id)_web_objectWithAPIObject:(WebKit::APIObject*)object;
+#import "WKObject.h"
 
+@interface WKNSString : WKObject <NSCopying>
 @end
 
 #endif // WK_API_ENABLED
similarity index 53%
rename from Source/WebKit2/Shared/Cocoa/WKNSObjectExtras.mm
rename to Source/WebKit2/Shared/Cocoa/WKNSString.mm
index 0845739..416cf53 100644 (file)
  */
 
 #import "config.h"
-#import "WKNSObjectExtras.h"
+#import "WKNSString.h"
 
 #if WK_API_ENABLED
 
-#import "WKBackForwardListItemInternal.h"
-#import "WebBackForwardListItem.h"
-#import <wtf/RefPtr.h>
+#import "WebString.h"
+#import <wtf/RetainPtr.h>
 
 using namespace WebKit;
 
-@interface WKObject : NSObject
+@implementation WKNSString
 
-- (id)initWithAPIObject:(WebKit::APIObject&)object;
-
-@end
-
-@implementation WKObject {
-    RefPtr<APIObject> _object;
-}
-
-- (id)initWithAPIObject:(APIObject&)object
+- (NSObject *)_web_createTarget
 {
-    if (!(self = [super init]))
-        return nil;
-
-    _object = &object;
-
-    return self;
+    const String& string = static_cast<WebString*>(&self._apiObject)->string();
+    return (NSString *)CFMakeCollectable(string.createCFString().leakRef());
 }
 
-#pragma mark - NSObject protocol implementation
-
-- (BOOL)isEqual:(id)object
-{
-    if ([object class] != [self class])
-        return NO;
-
-    return _object == ((WKObject *)object)->_object;
-}
+#pragma mark NSCopying protocol implementation
 
-- (NSUInteger)hash
+- (id)copyWithZone:(NSZone *)zone
 {
-    return (NSUInteger)_object.get();
-}
-
-- (NSString *)description
-{
-    return [NSString stringWithFormat:@"<%@: %p; object = %p; type = %d>", NSStringFromClass([self class]), self, _object.get(), _object->type()];
-}
-
-@end
-
-#pragma mark -
-
-@implementation NSObject (WKExtras)
-
-+ (id)_web_objectWithAPIObject:(APIObject*)object
-{
-    if (!object)
-        return nil;
-
-    switch (object->type()) {
-    case APIObject::TypeBackForwardListItem:
-        return [[[WKBackForwardListItem alloc] _initWithItem:*static_cast<WebBackForwardListItem*>(object)] autorelease];
-
-    default:
-        return [[[WKObject alloc] initWithAPIObject:*object] autorelease];
-    }
+    return [self retain];
 }
 
 @end
diff --git a/Source/WebKit2/Shared/Cocoa/WKNSURL.h b/Source/WebKit2/Shared/Cocoa/WKNSURL.h
new file mode 100644 (file)
index 0000000..d612504
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+#import "WKFoundation.h"
+
+#if WK_API_ENABLED
+
+#import "WKObject.h"
+
+@interface WKNSURL : WKObject <NSCopying>
+@end
+
+#endif // WK_API_ENABLED
diff --git a/Source/WebKit2/Shared/Cocoa/WKNSURL.mm b/Source/WebKit2/Shared/Cocoa/WKNSURL.mm
new file mode 100644 (file)
index 0000000..0e88e97
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+#import "config.h"
+#import "WKNSURL.h"
+
+#if WK_API_ENABLED
+
+#import "WKAPICast.h"
+#import "WKURLCF.h"
+#import "WebURL.h"
+
+using namespace WebKit;
+
+@implementation WKNSURL
+
+- (NSObject *)_web_createTarget
+{
+    return (NSURL *)CFMakeCollectable(WKURLCopyCFURL(kCFAllocatorDefault, toAPI(reinterpret_cast<WebURL*>(&self._apiObject))));
+}
+
+#pragma mark NSCopying protocol implementation
+
+- (id)copyWithZone:(NSZone *)zone
+{
+    return [self retain];
+}
+
+@end
+
+#endif // WK_API_ENABLED
diff --git a/Source/WebKit2/Shared/Cocoa/WKObject.h b/Source/WebKit2/Shared/Cocoa/WKObject.h
new file mode 100644 (file)
index 0000000..90be11a
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+#import "WKFoundation.h"
+
+#if WK_API_ENABLED
+
+namespace WebKit {
+class APIObject;
+}
+
+@protocol WKObject <NSObject>
+
+@property (readonly) WebKit::APIObject& _apiObject;
+
+@end
+
+@interface WKObject : NSObject <WKObject>
+
+- (NSObject *)_web_createTarget NS_RETURNS_RETAINED;
+
+@end
+
+#endif // WK_API_ENABLED
diff --git a/Source/WebKit2/Shared/Cocoa/WKObject.mm b/Source/WebKit2/Shared/Cocoa/WKObject.mm
new file mode 100644 (file)
index 0000000..baa6cb9
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+#import "config.h"
+#import "WKObject.h"
+
+#if WK_API_ENABLED
+
+#import "APIObject.h"
+
+using namespace WebKit;
+
+@implementation WKObject {
+    dispatch_once_t _targetInitializationToken;
+    NSObject *_target;
+}
+
+- (void)dealloc
+{
+    static_cast<APIObject*>(object_getIndexedIvars(self))->~APIObject();
+    [_target release];
+
+    [super dealloc];
+}
+
+static inline void initializeTargetIfNeeded(WKObject *self)
+{
+    if (self->_target)
+        return;
+
+    dispatch_once(&self->_targetInitializationToken, ^{
+        self->_target = [self _web_createTarget];
+    });
+}
+
+- (BOOL)isEqual:(id)object
+{
+    if (object == self)
+        return YES;
+
+    if (!object)
+        return NO;
+
+    initializeTargetIfNeeded(self);
+
+    return [_target isEqual:object];
+}
+
+- (NSUInteger)hash
+{
+    initializeTargetIfNeeded(self);
+
+    return _target ? [_target hash] : [super hash];
+}
+
+- (BOOL)isKindOfClass:(Class)aClass
+{
+    initializeTargetIfNeeded(self);
+
+    return [_target isKindOfClass:aClass];
+}
+
+- (BOOL)isMemberOfClass:(Class)aClass
+{
+    initializeTargetIfNeeded(self);
+
+    return [_target isMemberOfClass:aClass];
+}
+
+- (BOOL)respondsToSelector:(SEL)selector
+{
+    initializeTargetIfNeeded(self);
+
+    return [_target respondsToSelector:selector] || [super respondsToSelector:selector];
+}
+
+- (BOOL)conformsToProtocol:(Protocol *)protocol
+{
+    initializeTargetIfNeeded(self);
+
+    return [_target conformsToProtocol:protocol] || [super conformsToProtocol:protocol];
+}
+
+- (id)forwardingTargetForSelector:(SEL)selector
+{
+    initializeTargetIfNeeded(self);
+
+    return _target;
+}
+
+- (NSString *)description
+{
+    initializeTargetIfNeeded(self);
+
+    return _target ? [_target description] : [super description];
+}
+
+- (NSObject *)_web_createTarget
+{
+    return nil;
+}
+
+#pragma mark WKObject protocol implementation
+
+- (APIObject&)_apiObject
+{
+    return *static_cast<APIObject*>(object_getIndexedIvars(self));
+}
+
+@end
+
+#endif // WK_API_ENABLED
index c38cef2..57d5afd 100644 (file)
@@ -267,7 +267,7 @@ static void releaseNSData(unsigned char*, const void* data)
     if (!list)
         return nil;
 
-    return [[[WKBackForwardList alloc] _initWithList:*list] autorelease];
+    return wrapper(*list);
 }
 #endif // WK_API_ENABLED
 
@@ -502,11 +502,9 @@ static void didChangeBackForwardList(WKPageRef page, WKBackForwardListItemRef ad
     if (![browsingContext.loadDelegate respondsToSelector:@selector(browsingContextControllerDidChangeBackForwardList:addedItem:removedItems:)])
         return;
 
-    WKBackForwardListItem *added = addedItem ? [[WKBackForwardListItem alloc] _initWithItem:*toImpl(addedItem)] : nil;
-    NSArray *removed = removedItems ? [[WKNSArray alloc] web_initWithImmutableArray:*toImpl(removedItems)] : nil;
+    WKBackForwardListItem *added = addedItem ? wrapper(*toImpl(addedItem)) : nil;
+    NSArray *removed = removedItems ? wrapper(*toImpl(removedItems)) : nil;
     [browsingContext.loadDelegate browsingContextControllerDidChangeBackForwardList:browsingContext addedItem:added removedItems:removed];
-    [added release];
-    [removed release];
 }
 #endif // WK_API_ENABLED
 
index 7d62a1a..43e7ed6 100644 (file)
 
 #import "WKBackForwardListItemInternal.h"
 #import "WKNSArray.h"
-#import "WebBackForwardList.h"
 
 using namespace WebKit;
 
 @implementation WKBackForwardList {
-    RefPtr<WebBackForwardList> _list;
+    std::aligned_storage<sizeof(WebBackForwardList), std::alignment_of<WebBackForwardList>::value>::type _list;
+}
+
+- (void)dealloc
+{
+    reinterpret_cast<WebBackForwardList*>(&_list)->~WebBackForwardList();
+
+    [super dealloc];
 }
 
 static WKBackForwardListItem *toWKBackForwardListItem(WebBackForwardListItem* item)
@@ -43,71 +49,62 @@ static WKBackForwardListItem *toWKBackForwardListItem(WebBackForwardListItem* it
     if (!item)
         return nil;
 
-    return [[[WKBackForwardListItem alloc] _initWithItem:*item] autorelease];
+    return wrapper(*item);
 }
 
 - (WKBackForwardListItem *)currentItem
 {
-    return toWKBackForwardListItem(_list->currentItem());
+    return toWKBackForwardListItem(reinterpret_cast<WebBackForwardList*>(&_list)->currentItem());
 }
 
 - (WKBackForwardListItem *)backItem
 {
-    return toWKBackForwardListItem(_list->backItem());
+    return toWKBackForwardListItem(reinterpret_cast<WebBackForwardList*>(&_list)->backItem());
 }
 
 - (WKBackForwardListItem *)forwardItem
 {
-    return toWKBackForwardListItem(_list->forwardItem());
+    return toWKBackForwardListItem(reinterpret_cast<WebBackForwardList*>(&_list)->forwardItem());
 }
 
 - (WKBackForwardListItem *)itemAtIndex:(NSInteger)index
 {
-    return toWKBackForwardListItem(_list->itemAtIndex(index));
+    return toWKBackForwardListItem(reinterpret_cast<WebBackForwardList*>(&_list)->itemAtIndex(index));
 }
 
 - (NSUInteger)backListCount
 {
-    return _list->backListCount();
+    return reinterpret_cast<WebBackForwardList*>(&_list)->backListCount();
 }
 
 - (NSUInteger)forwardListCount
 {
-    return _list->forwardListCount();
+    return reinterpret_cast<WebBackForwardList*>(&_list)->forwardListCount();
 }
 
 - (NSArray *)backListWithLimit:(NSUInteger)limit
 {
-    RefPtr<ImmutableArray> list = _list->backListAsImmutableArrayWithLimit(limit);
+    RefPtr<ImmutableArray> list = reinterpret_cast<WebBackForwardList*>(&_list)->backListAsImmutableArrayWithLimit(limit);
     if (!list)
         return nil;
 
-    return [WKNSArray web_arrayWithImmutableArray:*list];
+    return [wrapper(*list.release().leakRef()) autorelease];
 }
 
 - (NSArray *)forwardListWithLimit:(NSUInteger)limit
 {
-    RefPtr<ImmutableArray> list = _list->forwardListAsImmutableArrayWithLimit(limit);
+    RefPtr<ImmutableArray> list = reinterpret_cast<WebBackForwardList*>(&_list)->forwardListAsImmutableArrayWithLimit(limit);
     if (!list)
         return nil;
 
-    return [WKNSArray web_arrayWithImmutableArray:*list];
+    return [wrapper(*list.release().leakRef()) autorelease];
 }
 
-@end
-
-#pragma mark -
-
-@implementation WKBackForwardList (Internal)
+#pragma mark WKObject protocol implementation
 
-- (id)_initWithList:(WebBackForwardList&)list
+- (APIObject &)_apiObject
 {
-    if (!(self = [super init]))
-        return nil;
-
-    _list = &list;
-
-    return self;
+    return *reinterpret_cast<APIObject*>(&_list);
 }
 
 @end
index 0013585..4925a9b 100644 (file)
 
 #if WK_API_ENABLED
 
+#import "WKObject.h"
+#import "WebBackForwardList.h"
+
 namespace WebKit {
-class WebBackForwardList;
+inline WKBackForwardList *wrapper(WebBackForwardList& list) { ASSERT([list.wrapper() isKindOfClass:[WKBackForwardList class]]); return (WKBackForwardList *)list.wrapper(); }
 }
 
-@interface WKBackForwardList (Internal)
-
-- (id)_initWithList:(WebKit::WebBackForwardList&)list;
-
+@interface WKBackForwardList () <WKObject>
 @end
 
 #endif // WK_API_ENABLED
index 45ef377..f9a1d78 100644 (file)
 
 #if WK_API_ENABLED
 
-#import "WebBackForwardListItem.h"
-#import "WKRetainPtr.h"
-#import "WKSharedAPICast.h"
-#import "WKStringCF.h"
-#import "WKURLCF.h"
+#import "WebString.h"
 
 using namespace WebKit;
 
 @implementation WKBackForwardListItem {
-    RefPtr<WebBackForwardListItem> _item;
+    std::aligned_storage<sizeof(WebBackForwardListItem), std::alignment_of<WebBackForwardListItem>::value>::type _item;
+}
+
+- (void)dealloc
+{
+    reinterpret_cast<WebBackForwardListItem*>(&_item)->~WebBackForwardListItem();
+
+    [super dealloc];
 }
 
 - (NSURL *)URL
 {
-    if (!_item->url())
+    if (!reinterpret_cast<WebBackForwardListItem*>(&_item)->url())
         return nil;
 
-    return CFBridgingRelease(WKURLCopyCFURL(kCFAllocatorDefault, adoptWK(toCopiedURLAPI(_item->url())).get()));
+    return [NSURL URLWithString:reinterpret_cast<WebBackForwardListItem*>(&_item)->url()];
 }
 
 - (NSString *)title
 {
-    if (!_item->title())
+    if (!reinterpret_cast<WebBackForwardListItem*>(&_item)->title())
         return nil;
 
-    return CFBridgingRelease(WKStringCopyCFString(kCFAllocatorDefault, adoptWK(toCopiedAPI(_item->title())).get()));
+    return reinterpret_cast<WebBackForwardListItem*>(&_item)->title();
 }
 
 - (NSURL *)originalURL
 {
-    if (!_item->originalURL())
+    if (!reinterpret_cast<WebBackForwardListItem*>(&_item)->originalURL())
         return nil;
 
-    return CFBridgingRelease(WKURLCopyCFURL(kCFAllocatorDefault, adoptWK(toCopiedURLAPI(_item->originalURL())).get()));
+    return [NSURL URLWithString:reinterpret_cast<WebBackForwardListItem*>(&_item)->originalURL()];
 }
 
-#pragma mark - NSObject protocol implementation
-
-- (BOOL)isEqual:(id)object
-{
-    if ([object class] != [self class])
-        return NO;
-
-    return _item == ((WKBackForwardListItem *)object)->_item;
-}
+#pragma mark WKObject protocol implementation
 
-- (NSUInteger)hash
+- (APIObject&)_apiObject
 {
-    return (NSUInteger)_item.get();
+    return *reinterpret_cast<APIObject*>(&_item);
 }
 
 @end
 
-#pragma mark -
-
 @implementation WKBackForwardListItem (Internal)
 
-- (id)_initWithItem:(WebBackForwardListItem&)item
-{
-    if (!(self = [super init]))
-        return nil;
-
-    _item = &item;
-
-    return self;
-}
-
 - (WebKit::WebBackForwardListItem&)_item
 {
-    return *_item;
+    return *reinterpret_cast<WebBackForwardListItem*>(&_item);
 }
 
 @end
index 1b83342..85ff584 100644 (file)
 
 #if WK_API_ENABLED
 
+#import "WKObject.h"
+#import "WebBackForwardListItem.h"
+
 namespace WebKit {
-class WebBackForwardListItem;
+inline WKBackForwardListItem *wrapper(WebBackForwardListItem& item) { ASSERT([item.wrapper() isKindOfClass:[WKBackForwardListItem class]]); return (WKBackForwardListItem *)item.wrapper(); }
 }
 
-@interface WKBackForwardListItem (Internal)
+@interface WKBackForwardListItem () <WKObject>
+@end
 
-- (id)_initWithItem:(WebKit::WebBackForwardListItem&)item;
+@interface WKBackForwardListItem (Internal)
 
 @property (readonly) WebKit::WebBackForwardListItem& _item;
 
index d28eb8a..4fa5e94 100644 (file)
@@ -37,10 +37,8 @@ namespace WebKit {
 
 class WebPageProxy;
 
-class WebColorPickerResultListenerProxy : public APIObject {
+class WebColorPickerResultListenerProxy : public TypedAPIObject<APIObject::TypeColorPickerResultListener> {
 public:
-    static const Type APIType = TypeColorPickerResultListener;
-
     static PassRefPtr<WebColorPickerResultListenerProxy> create(WebPageProxy* page)
     {
         return adoptRef(new WebColorPickerResultListenerProxy(page));
@@ -54,8 +52,6 @@ public:
 private:
     explicit WebColorPickerResultListenerProxy(WebPageProxy*);
 
-    virtual Type type() const { return APIType; }
-
     RefPtr<WebPageProxy> m_page;
 };
 
index 53ba3b9..d84cca8 100644 (file)
 
 #include "WebFrameListenerProxy.h"
 
+#if PLATFORM(MAC)
+#include "WKFoundation.h"
+#endif
+
+#define DELEGATE_REF_COUNTING_TO_COCOA (PLATFORM(MAC) && WK_API_ENABLED)
+
 namespace WebKit {
 
 class WebFrameProxy;
@@ -47,8 +53,14 @@ private:
     WebFormSubmissionListenerProxy(WebFrameProxy*, uint64_t listenerID);
 
     virtual Type type() const { return APIType; }
+
+#if DELEGATE_REF_COUNTING_TO_COCOA
+    void* operator new(size_t size) { return newObject(size, APIType); }
+#endif
 };
 
 } // namespace WebKit
 
+#undef DELEGATE_REF_COUNTING_TO_COCOA
+
 #endif // WebFramePolicyListenerProxy_h
index 779d2a5..ae88984 100644 (file)
 
 #include "WebFrameListenerProxy.h"
 
+#if PLATFORM(MAC)
+#include "WKFoundation.h"
+#endif
+
+#define DELEGATE_REF_COUNTING_TO_COCOA (PLATFORM(MAC) && WK_API_ENABLED)
+
 namespace WebKit {
 
 class WebFramePolicyListenerProxy : public WebFrameListenerProxy {
@@ -47,8 +53,14 @@ private:
     WebFramePolicyListenerProxy(WebFrameProxy*, uint64_t listenerID);
 
     virtual Type type() const { return APIType; }
+
+#if DELEGATE_REF_COUNTING_TO_COCOA
+    void* operator new(size_t size) { return newObject(size, APIType); }
+#endif
 };
 
 } // namespace WebKit
 
+#undef DELEGATE_REF_COUNTING_TO_COCOA
+
 #endif // WebFramePolicyListenerProxy_h
index b24720b..81f2a97 100644 (file)
                33D3A3CA1339617900709BE4 /* WebMediaCacheManagerProxyMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33D3A3C61339617900709BE4 /* WebMediaCacheManagerProxyMessageReceiver.cpp */; };
                33D3A3CB1339617900709BE4 /* WebMediaCacheManagerProxyMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 33D3A3C71339617900709BE4 /* WebMediaCacheManagerProxyMessages.h */; };
                33F9D5B91312F1EE000D683F /* WebResourceCacheManagerCFNet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33F9D5B81312F1EE000D683F /* WebResourceCacheManagerCFNet.cpp */; };
+               374436881820E7240049579F /* WKObject.mm in Sources */ = {isa = PBXBuildFile; fileRef = 374436871820E7240049579F /* WKObject.mm */; };
                3760881E150413E900FC82C7 /* WebRenderObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3760881C150413E900FC82C7 /* WebRenderObject.cpp */; };
                3760881F150413E900FC82C7 /* WebRenderObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 3760881D150413E900FC82C7 /* WebRenderObject.h */; };
                37608822150414F700FC82C7 /* WKRenderObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37608820150414F700FC82C7 /* WKRenderObject.cpp */; };
                377EAD4817E2C77B002D193D /* WKUserContentInjectedFrames.h in Headers */ = {isa = PBXBuildFile; fileRef = 377EAD4617E2C77B002D193D /* WKUserContentInjectedFrames.h */; settings = {ATTRIBUTES = (Public, ); }; };
                377EAD4917E2C77B002D193D /* WKUserScriptInjectionTime.h in Headers */ = {isa = PBXBuildFile; fileRef = 377EAD4717E2C77B002D193D /* WKUserScriptInjectionTime.h */; settings = {ATTRIBUTES = (Public, ); }; };
                3788A05C14743C90006319E5 /* WKBrowsingContextControllerPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 3788A05B14743C90006319E5 /* WKBrowsingContextControllerPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               378E1A3D181ED6FF0031007A /* APIObject.mm in Sources */ = {isa = PBXBuildFile; fileRef = 378E1A3B181ED6FF0031007A /* APIObject.mm */; };
+               378E1A40181EDA010031007A /* WKObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 378E1A3F181EDA010031007A /* WKObject.h */; };
+               378E1A4918208CD60031007A /* WKNSString.mm in Sources */ = {isa = PBXBuildFile; fileRef = 378E1A4718208CD60031007A /* WKNSString.mm */; };
+               378E1A4A18208CD60031007A /* WKNSString.h in Headers */ = {isa = PBXBuildFile; fileRef = 378E1A4818208CD60031007A /* WKNSString.h */; };
+               378E1A4D18208D700031007A /* WKNSURL.mm in Sources */ = {isa = PBXBuildFile; fileRef = 378E1A4B18208D700031007A /* WKNSURL.mm */; };
+               378E1A4E18208D700031007A /* WKNSURL.h in Headers */ = {isa = PBXBuildFile; fileRef = 378E1A4C18208D700031007A /* WKNSURL.h */; };
                37948403150C350600E52CE9 /* WebRenderLayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37948401150C350600E52CE9 /* WebRenderLayer.cpp */; };
                37948404150C350600E52CE9 /* WebRenderLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 37948402150C350600E52CE9 /* WebRenderLayer.h */; };
                37948408150C4B9700E52CE9 /* WKRenderLayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37948406150C4B9600E52CE9 /* WKRenderLayer.cpp */; };
                37C4C0931814B3AF003688B9 /* WKNSArray.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37C4C0911814B3AF003688B9 /* WKNSArray.mm */; };
                37C4C0941814B3AF003688B9 /* WKNSArray.h in Headers */ = {isa = PBXBuildFile; fileRef = 37C4C0921814B3AF003688B9 /* WKNSArray.h */; };
                37C4C0951814B9E6003688B9 /* WKBackForwardListInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 37C4C08E1814AF3A003688B9 /* WKBackForwardListInternal.h */; };
-               37C4C0981814BF9C003688B9 /* WKNSObjectExtras.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37C4C0961814BF9C003688B9 /* WKNSObjectExtras.mm */; };
-               37C4C0991814BF9C003688B9 /* WKNSObjectExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = 37C4C0971814BF9C003688B9 /* WKNSObjectExtras.h */; };
                37C4E9F6131C6E7E0029BD5A /* config.h in Headers */ = {isa = PBXBuildFile; fileRef = B396EA5512E0ED2D00F4FEB7 /* config.h */; };
                37DFA7001810BB92001F4A9F /* WKFoundation.h in Headers */ = {isa = PBXBuildFile; fileRef = 37DFA6FF1810BB92001F4A9F /* WKFoundation.h */; settings = {ATTRIBUTES = (Public, ); }; };
                37F623B812A57B6200E3FDF6 /* WKFindOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 37F623B712A57B6200E3FDF6 /* WKFindOptions.h */; settings = {ATTRIBUTES = (Private, ); }; };
                33D3A3C71339617900709BE4 /* WebMediaCacheManagerProxyMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebMediaCacheManagerProxyMessages.h; sourceTree = "<group>"; };
                33F9D5B81312F1EE000D683F /* WebResourceCacheManagerCFNet.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; name = WebResourceCacheManagerCFNet.cpp; path = ResourceCache/cf/WebResourceCacheManagerCFNet.cpp; sourceTree = "<group>"; };
                3574B37F1665932C00859BB7 /* PDFAnnotationTextWidgetDetails.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = PDFAnnotationTextWidgetDetails.h; path = PDF/PDFAnnotationTextWidgetDetails.h; sourceTree = "<group>"; };
+               374436871820E7240049579F /* WKObject.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKObject.mm; sourceTree = "<group>"; };
                3760881C150413E900FC82C7 /* WebRenderObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebRenderObject.cpp; sourceTree = "<group>"; };
                3760881D150413E900FC82C7 /* WebRenderObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebRenderObject.h; sourceTree = "<group>"; };
                37608820150414F700FC82C7 /* WKRenderObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKRenderObject.cpp; sourceTree = "<group>"; };
                377EAD4617E2C77B002D193D /* WKUserContentInjectedFrames.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKUserContentInjectedFrames.h; sourceTree = "<group>"; };
                377EAD4717E2C77B002D193D /* WKUserScriptInjectionTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKUserScriptInjectionTime.h; sourceTree = "<group>"; };
                3788A05B14743C90006319E5 /* WKBrowsingContextControllerPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKBrowsingContextControllerPrivate.h; sourceTree = "<group>"; };
+               378E1A3B181ED6FF0031007A /* APIObject.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = APIObject.mm; sourceTree = "<group>"; };
+               378E1A3F181EDA010031007A /* WKObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKObject.h; sourceTree = "<group>"; };
+               378E1A4718208CD60031007A /* WKNSString.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKNSString.mm; sourceTree = "<group>"; };
+               378E1A4818208CD60031007A /* WKNSString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKNSString.h; sourceTree = "<group>"; };
+               378E1A4B18208D700031007A /* WKNSURL.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKNSURL.mm; sourceTree = "<group>"; };
+               378E1A4C18208D700031007A /* WKNSURL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKNSURL.h; sourceTree = "<group>"; };
                37948401150C350600E52CE9 /* WebRenderLayer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebRenderLayer.cpp; sourceTree = "<group>"; };
                37948402150C350600E52CE9 /* WebRenderLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebRenderLayer.h; sourceTree = "<group>"; };
                37948406150C4B9600E52CE9 /* WKRenderLayer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKRenderLayer.cpp; sourceTree = "<group>"; };
                37C4C08E1814AF3A003688B9 /* WKBackForwardListInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKBackForwardListInternal.h; sourceTree = "<group>"; };
                37C4C0911814B3AF003688B9 /* WKNSArray.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKNSArray.mm; sourceTree = "<group>"; };
                37C4C0921814B3AF003688B9 /* WKNSArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKNSArray.h; sourceTree = "<group>"; };
-               37C4C0961814BF9C003688B9 /* WKNSObjectExtras.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKNSObjectExtras.mm; sourceTree = "<group>"; };
-               37C4C0971814BF9C003688B9 /* WKNSObjectExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKNSObjectExtras.h; sourceTree = "<group>"; };
                37DFA6FF1810BB92001F4A9F /* WKFoundation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKFoundation.h; sourceTree = "<group>"; };
                37F623B712A57B6200E3FDF6 /* WKFindOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKFindOptions.h; sourceTree = "<group>"; };
                3F87B9BA15893F630090FF62 /* WebColorChooser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebColorChooser.cpp; sourceTree = "<group>"; };
                37C4C0901814B37B003688B9 /* Cocoa */ = {
                        isa = PBXGroup;
                        children = (
+                               378E1A3B181ED6FF0031007A /* APIObject.mm */,
                                37C4C0921814B3AF003688B9 /* WKNSArray.h */,
                                37C4C0911814B3AF003688B9 /* WKNSArray.mm */,
-                               37C4C0971814BF9C003688B9 /* WKNSObjectExtras.h */,
-                               37C4C0961814BF9C003688B9 /* WKNSObjectExtras.mm */,
+                               378E1A4818208CD60031007A /* WKNSString.h */,
+                               378E1A4718208CD60031007A /* WKNSString.mm */,
+                               378E1A4C18208D700031007A /* WKNSURL.h */,
+                               378E1A4B18208D700031007A /* WKNSURL.mm */,
+                               378E1A3F181EDA010031007A /* WKObject.h */,
+                               374436871820E7240049579F /* WKObject.mm */,
                        );
                        path = Cocoa;
                        sourceTree = "<group>";
                                1AB7D61A1288B9D900CFD08C /* DownloadProxyMessages.h in Headers */,
                                C517388112DF8F4F00EE3F47 /* DragControllerAction.h in Headers */,
                                BC8452A81162C80900CAB9B5 /* DrawingArea.h in Headers */,
+                               378E1A4A18208CD60031007A /* WKNSString.h in Headers */,
                                2D8949F1182044F600E898AA /* PlatformCALayerRemoteTiledBacking.h in Headers */,
                                0FB659231208B4DB0044816C /* DrawingAreaInfo.h in Headers */,
                                1A64229A12DD029200CAAE2C /* DrawingAreaMessages.h in Headers */,
                                84477853176FCC0800CDC7BB /* InjectedBundleHitTestResultMediaType.h in Headers */,
                                BC8147D512F66D31007B2C32 /* InjectedBundleNavigationAction.h in Headers */,
                                BC4BEEAB120A0A5F00FBA0C7 /* InjectedBundleNodeHandle.h in Headers */,
+                               378E1A4E18208D700031007A /* WKNSURL.h in Headers */,
                                512935E41288D97800A4B695 /* InjectedBundlePageContextMenuClient.h in Headers */,
                                E1EE53E311F8CFC000CCBEE4 /* InjectedBundlePageEditorClient.h in Headers */,
                                BC14E10A120B905E00826C0C /* InjectedBundlePageFormClient.h in Headers */,
                                1AE4987811FF7FAA0048B464 /* JSNPObject.h in Headers */,
                                1A588B33174AAE0B00ACF472 /* KeyedCodingValue.h in Headers */,
                                1A588B37174AB77000ACF472 /* KeyedCodingValueCF.h in Headers */,
-                               37C4C0991814BF9C003688B9 /* WKNSObjectExtras.h in Headers */,
                                1A588B31174AAC7100ACF472 /* KeyedEncoder.h in Headers */,
                                BCE0937814FB128C001138D9 /* LayerHostingContext.h in Headers */,
                                1A92DC1112F8BA460017AF65 /* LayerTreeContext.h in Headers */,
                                1AD09F2C1743F8E600A95E50 /* WKNPAPIPlugInContainer.h in Headers */,
                                BC407602124FF0270068F20A /* WKNumber.h in Headers */,
                                7CD5EBB91746A15B000C1C45 /* WKObjCTypeWrapperRef.h in Headers */,
+                               378E1A40181EDA010031007A /* WKObject.h in Headers */,
                                BC857FE612B843D800EDEB2E /* WKOpenPanelParameters.h in Headers */,
                                BC1DFE8F12B31CA8005DF730 /* WKOpenPanelResultListener.h in Headers */,
                                BCD597D7112B56DC00EC8C23 /* WKPage.h in Headers */,
                                1A30EAC6115D7DA30053E937 /* ConnectionMac.cpp in Sources */,
                                5136183D163126DA00A99DDE /* ConnectionStack.cpp in Sources */,
                                2DA049B7180CCD0A00AAFA9E /* GraphicsLayerCARemote.cpp in Sources */,
+                               378E1A4D18208D700031007A /* WKNSURL.mm in Sources */,
                                2DA049B3180CCCD300AAFA9E /* PlatformCALayerRemote.cpp in Sources */,
                                CDC3831017212440008A2FC3 /* CookieStorageShim.cpp in Sources */,
                                B878B616133428DC006888E9 /* CorrectionPanel.mm in Sources */,
                                1A910072126675C4001842F5 /* FindIndicator.cpp in Sources */,
                                1A91010B1268C8CA001842F5 /* FindIndicatorWindow.mm in Sources */,
                                BCE81D8C1319F7EF00241910 /* FontInfo.cpp in Sources */,
+                               378E1A4918208CD60031007A /* WKNSString.mm in Sources */,
                                BC06F43012DBB9B6002D78DE /* GeolocationPermissionRequestManager.cpp in Sources */,
                                BC06F44B12DBD1F5002D78DE /* GeolocationPermissionRequestManagerProxy.cpp in Sources */,
                                BC06F43B12DBCCFB002D78DE /* GeolocationPermissionRequestProxy.cpp in Sources */,
                                1AAF263814687C39004A1E8A /* TiledCoreAnimationDrawingArea.mm in Sources */,
                                1AF05D8614688348008B1E81 /* TiledCoreAnimationDrawingAreaProxy.mm in Sources */,
                                1A64245F12DE29A100CAAE2C /* UpdateInfo.cpp in Sources */,
+                               374436881820E7240049579F /* WKObject.mm in Sources */,
                                1A0F29E3120B44420053D1B9 /* VisitedLinkProvider.cpp in Sources */,
                                1A0F29CB120B37160053D1B9 /* VisitedLinkTable.cpp in Sources */,
                                CEDA12E2152CD1AE00D9E08D /* WebAlternativeTextClient.cpp in Sources */,
                                C574A37712E6099D002DFE98 /* WebDragClientMac.mm in Sources */,
                                BCA0EFA012332642007D3CFB /* WebEditCommandProxy.cpp in Sources */,
                                BC111A5E112F4FBB00337BAB /* WebEditorClient.cpp in Sources */,
-                               37C4C0981814BF9C003688B9 /* WKNSObjectExtras.mm in Sources */,
                                C5237F6012441CA300780472 /* WebEditorClientMac.mm in Sources */,
                                BC575613126E0138006F0F12 /* WebError.cpp in Sources */,
                                BC111AE0112F5BC200337BAB /* WebErrorsMac.mm in Sources */,
                                33367657130C9ECA006C9DE2 /* WebResourceCacheManagerProxyMessageReceiver.cpp in Sources */,
                                510AFFB916542048001BA05E /* WebResourceLoader.cpp in Sources */,
                                51F060E11654318500F3281B /* WebResourceLoaderMessageReceiver.cpp in Sources */,
+                               378E1A3D181ED6FF0031007A /* APIObject.mm in Sources */,
                                51FB08FF1639DE1A00EC324A /* WebResourceLoadScheduler.cpp in Sources */,
                                D3B9484811FF4B6500032B39 /* WebSearchPopupMenu.cpp in Sources */,
                                BCC5715C115ADAEF001CCAF9 /* WebSystemInterface.mm in Sources */,