Changeset 158324 in webkit


Ignore:
Timestamp:
Oct 30, 2013, 3:49:20 PM (12 years ago)
Author:
mitz@apple.com
Message:

[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.
Location:
trunk/Source/WebKit2
Files:
7 added
2 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r158316 r158324  
     12013-10-30  Dan Bernstein  <mitz@apple.com>
     2
     3        [Cocoa] Make all API objects have Cocoa wrappers, and delegate refcounting to those wrappers
     4        https://bugs.webkit.org/show_bug.cgi?id=123394
     5
     6        Reviewed by Darin Adler.
     7
     8        All wrappers conform to a new WKObject protocol and contain the wrapped object inline.
     9        APIObject-derived classes override operator new to call newObject, which allocates the
     10        wrapper and returns a pointer to the inline API object.
     11
     12        There are three kinds of wrapper classes: (a) classes that inherit directly from NSObject
     13        and implement their API by calling the wrapped object (example: WKBackForwardList),
     14        (b) internal classes that inherit from a class cluster, and implement the primitive methods
     15        of the class cluster by calling the wrapped object (example: WKNSArray), and (c) internal
     16        classes that inerit from the new WKObject class, and proxy to an object of some public type,
     17        which is created from the wrapped object (example: WKNSURL).
     18
     19        * Shared/APIObject.h:
     20        (WebKit::APIObject::wrapper): Added this getter.
     21        (WebKit::TypedAPIObject::operator new): Added override that calls newObject.
     22        * Shared/Cocoa/APIObject.mm: Added.
     23        (WebKit::APIObject::ref): Retains the wrapper.
     24        (WebKit::APIObject::deref): Releases the wrapper. When the wrapper is deallocated, it calls
     25        the API object destructor.
     26        (WebKit::APIObject::newObject): Allocates the wrapper and returns a pointer to the API
     27        object inside the wrapper.
     28
     29        * Shared/Cocoa/WKNSArray.h:
     30        (WebKit::wrapper): Added. Returns an ImmutableArray’s wrapper as an NSArray.
     31        Replaced the RefPtr<ImmutableArray> ivar with space for an ImmutableArray to live inside
     32        the wrapper.
     33        (-[WKNSArray dealloc]): Calls the ImmutableArray destructor.
     34        (-[WKNSArray count]): Updated for ivar change.
     35        (-[WKNSArray objectAtIndex:]): Ditto.
     36        (-[WKNSArray _apiObject]): Returns the wrapped ImmutableArray.
     37
     38        * Shared/Cocoa/WKNSObjectExtras.h: Removed.
     39        * Shared/Cocoa/WKNSObjectExtras.mm: Removed.
     40
     41        * Shared/Cocoa/WKNSString.h: Added.
     42        * Shared/Cocoa/WKNSString.mm: Added.
     43        (-[WKNSString _web_createTarget]): Override this WKObject method to create an NSString from
     44        the WebString.
     45        (-[WKNSString copyWithZone:]): Retains self.
     46
     47        * Shared/Cocoa/WKNSURL.h: Added.
     48        * Shared/Cocoa/WKNSURL.mm: Added.
     49        (-[WKNSURL _web_createTarget]): Override this WKObject method to create an NSURL from
     50        the WebURL.
     51        (-[WKNSURL copyWithZone:]): Retains self.
     52
     53        * Shared/Cocoa/WKObject.h: Added.
     54        * Shared/Cocoa/WKObject.mm: Added.
     55        (-[WKObject dealloc]): Calls the destructor of the wrapped object and releases the target
     56        object.
     57        (initializeTargetIfNeeded): Helper function. Tries to create the target exactly once.
     58        (-[WKObject isEqual:]): NSObject override that creates and compares to the target
     59        object if necessary.
     60        (-[WKObject hash]): NSObject override that creates and hashes the target object if
     61        there is one.
     62        (-[WKObject isKindOfClass:]): NSObject override that delegates to the target object.
     63        (-[WKObject isMemberOfClass:]): Ditto.
     64        (-[WKObject respondsToSelector:]): NSObject override that creates the target object if
     65        necessary and returns whether it or self responds to the selector.
     66        (-[WKObject conformsToProtocol:]): Similarly for protocols.
     67        (-[WKObject forwardingTargetForSelector:]): NSObject override that creates the target object
     68        if necessary and returns it as the target.
     69        (-[WKObject description]): NSObject override that creates the target object if necessary and
     70        forwards to it.
     71        (-[WKObject _web_createTarget]): Added. The base implementation returns nil.
     72        (-[WKObject _apiObject]): Returns the wrapped object.
     73
     74        * UIProcess/API/mac/WKBrowsingContextController.mm:
     75        (-[WKBrowsingContextController backForwardList]): Changed to return the existing wrapper.
     76        (didChangeBackForwardList): Changed to use existing wrappers.
     77
     78        Replaced the RefPtr<WebBackForwardList> ivar with space for a WebBackForwardList to live
     79        inside the wrapper.
     80        (-[WKBackForwardList dealloc]): Call the WebBackForwardList destructor.
     81        (toWKBackForwardListItem): Changed to us the existing wrapper.
     82        (-[WKBackForwardList currentItem]): Updated for ivar change.
     83        (-[WKBackForwardList backItem]): Ditto.
     84        (-[WKBackForwardList forwardItem]): Ditto.
     85        (-[WKBackForwardList itemAtIndex:]): Ditto.
     86        (-[WKBackForwardList backListCount]): Ditto.
     87        (-[WKBackForwardList forwardListCount]): Ditto,
     88        (-[WKBackForwardList backListWithLimit:]): Ditto, and also changed to use the
     89        ImmutableArray’s existing wrapper.
     90        (-[WKBackForwardList forwardListWithLimit:]): Ditto.
     91        (-[WKBackForwardList _apiObject]): Returns the WebBackForwardListItem.
     92        * UIProcess/Cocoa/WKBackForwardListInternal.h:
     93        (WebKit::wrapper): Added. Returns a WebBackForwardList’s wrapper as a WKBackForwardList.
     94
     95        * UIProcess/Cocoa/WKBackForwardListItem.mm:
     96        Replaced the RefPtr<WebBackForwardListItem> ivar with space for a WebBackForwardListItem to
     97        live inside the wrapper.
     98        (-[WKBackForwardListItem dealloc]): Call the WebBackForwardListItem destructor.
     99        (-[WKBackForwardListItem URL]): Updated for ivar change, and changed to make an NSURL
     100        directly instead of going through a wrapper.
     101        (-[WKBackForwardListItem title]): Updated for ivar change, and changed to use
     102        String’s operator NSString*.
     103        (-[WKBackForwardListItem originalURL]): Updated for ivar change, and changed to make an
     104        NSURL directly instead of going through a wrapper.
     105        (-[WKBackForwardListItem _apiObject]): Returns the WebBackForwardListItem.
     106        (-[WKBackForwardListItem _item]): Ditto.
     107        * UIProcess/Cocoa/WKBackForwardListItemInternal.h:
     108        (WebKit::wrapper): Added. Returns a WebBackForwardListItem’s wrapper as a
     109        WKBackForwardListItem.
     110
     111        * UIProcess/WebColorPickerResultListenerProxy.h: Changed into a TypedAPIObject.
     112
     113        * UIProcess/WebFormSubmissionListenerProxy.h:
     114        (WebKit::WebFormSubmissionListenerProxy::operator new): Override to call newObject.
     115
     116        * UIProcess/WebFramePolicyListenerProxy.h:
     117        (WebKit::WebFramePolicyListenerProxy::operator new): Ditto.
     118
     119        * WebKit2.xcodeproj/project.pbxproj: Updated for file additions and removals.
     120
    11212013-10-30  Anders Carlsson  <andersca@apple.com>
    2122
  • trunk/Source/WebKit2/Shared/APIObject.h

    r157595 r158324  
    2929#include <wtf/RefCounted.h>
    3030
     31#if PLATFORM(MAC)
     32#include "WKFoundation.h"
     33#endif
     34
     35#define DELEGATE_REF_COUNTING_TO_COCOA (PLATFORM(MAC) && WK_API_ENABLED)
     36
     37#if DELEGATE_REF_COUNTING_TO_COCOA
     38OBJC_CLASS NSObject;
     39#endif
     40
    3141namespace WebKit {
    3242
    33 class APIObject : public ThreadSafeRefCounted<APIObject> {
     43class APIObject
     44#if !DELEGATE_REF_COUNTING_TO_COCOA
     45    : public ThreadSafeRefCounted<APIObject>
     46#endif
     47{
    3448public:
    3549    enum Type {
     
    152166    virtual Type type() const = 0;
    153167
     168#if DELEGATE_REF_COUNTING_TO_COCOA
     169    NSObject *wrapper() { return m_wrapper; }
     170
     171    void ref();
     172    void deref();
     173#endif // DELEGATE_REF_COUNTING_TO_COCOA
     174
    154175protected:
    155176    APIObject();
     177
     178#if DELEGATE_REF_COUNTING_TO_COCOA
     179    static void* newObject(size_t, Type);
     180
     181private:
     182    // Derived classes must override operator new and call newObject().
     183    void* operator new(size_t) = delete;
     184
     185    NSObject *m_wrapper;
     186#endif // DELEGATE_REF_COUNTING_TO_COCOA
    156187};
    157188
     
    171202
    172203    virtual Type type() const OVERRIDE { return APIType; }
     204
     205#if DELEGATE_REF_COUNTING_TO_COCOA
     206    void* operator new(size_t size) { return newObject(size, APIType); }
     207#endif
    173208};
    174209
    175210} // namespace WebKit
    176211
     212#undef DELEGATE_REF_COUNTING_TO_COCOA
     213
    177214#endif // APIObject_h
  • trunk/Source/WebKit2/Shared/Cocoa/WKNSArray.h

    r158082 r158324  
    2828#if WK_API_ENABLED
    2929
     30#import "ImmutableArray.h"
     31#import "WKObject.h"
     32
    3033namespace WebKit {
    31 class ImmutableArray;
     34inline NSArray *wrapper(ImmutableArray& array) { ASSERT([array.wrapper() isKindOfClass:[NSArray class]]); return (NSArray *)array.wrapper(); }
    3235}
    3336
    34 @interface WKNSArray : NSArray
    35 
    36 + (id)web_arrayWithImmutableArray:(WebKit::ImmutableArray&)array;
    37 
    38 - (id)web_initWithImmutableArray:(WebKit::ImmutableArray&)array NS_REPLACES_RECEIVER;
    39 
     37@interface WKNSArray : NSArray <WKObject>
    4038@end
    4139
  • trunk/Source/WebKit2/Shared/Cocoa/WKNSArray.mm

    r157748 r158324  
    2929#if WK_API_ENABLED
    3030
    31 #import "ImmutableArray.h"
    32 #import "WKNSObjectExtras.h"
    33 
    3431using namespace WebKit;
    3532
    3633@implementation WKNSArray {
    37     RefPtr<ImmutableArray> _array;
     34    std::aligned_storage<sizeof(ImmutableArray), std::alignment_of<ImmutableArray>::value>::type _array;
    3835}
    3936
    40 + (id)web_arrayWithImmutableArray:(WebKit::ImmutableArray&)array
     37- (void)dealloc
    4138{
    42     return [[[[self class] alloc] web_initWithImmutableArray:array] autorelease];
     39    reinterpret_cast<ImmutableArray*>(&_array)->~ImmutableArray();
     40
     41    [super dealloc];
    4342}
    4443
    45 - (id)web_initWithImmutableArray:(ImmutableArray&)array
    46 {
    47     if (!(self = [super init]))
    48         return nil;
    49 
    50     _array = &array;
    51 
    52     return self;
    53 }
     44#pragma mark NSArray primitive methods
    5445
    5546- (NSUInteger)count
    5647{
    57     return _array->size();
     48    return reinterpret_cast<ImmutableArray*>(&_array)->size();
    5849}
    5950
    6051- (id)objectAtIndex:(NSUInteger)i
    6152{
    62     return [NSObject _web_objectWithAPIObject:_array->at(i)];
     53    return reinterpret_cast<ImmutableArray*>(&_array)->at(i)->wrapper();
    6354}
    6455
    65 #pragma mark - NSCopying protocol implementation
     56#pragma mark NSCopying protocol implementation
    6657
    6758- (id)copyWithZone:(NSZone *)zone
     
    7061}
    7162
     63#pragma mark WKObject protocol implementation
     64
     65- (APIObject&)_apiObject
     66{
     67    return *reinterpret_cast<APIObject*>(&_array);
     68}
     69
    7270@end
    7371
  • trunk/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextController.mm

    r157951 r158324  
    268268        return nil;
    269269
    270     return [[[WKBackForwardList alloc] _initWithList:*list] autorelease];
     270    return wrapper(*list);
    271271}
    272272#endif // WK_API_ENABLED
     
    503503        return;
    504504
    505     WKBackForwardListItem *added = addedItem ? [[WKBackForwardListItem alloc] _initWithItem:*toImpl(addedItem)] : nil;
    506     NSArray *removed = removedItems ? [[WKNSArray alloc] web_initWithImmutableArray:*toImpl(removedItems)] : nil;
     505    WKBackForwardListItem *added = addedItem ? wrapper(*toImpl(addedItem)) : nil;
     506    NSArray *removed = removedItems ? wrapper(*toImpl(removedItems)) : nil;
    507507    [browsingContext.loadDelegate browsingContextControllerDidChangeBackForwardList:browsingContext addedItem:added removedItems:removed];
    508     [added release];
    509     [removed release];
    510508}
    511509#endif // WK_API_ENABLED
  • trunk/Source/WebKit2/UIProcess/Cocoa/WKBackForwardList.mm

    r158091 r158324  
    3131#import "WKBackForwardListItemInternal.h"
    3232#import "WKNSArray.h"
    33 #import "WebBackForwardList.h"
    3433
    3534using namespace WebKit;
    3635
    3736@implementation WKBackForwardList {
    38     RefPtr<WebBackForwardList> _list;
     37    std::aligned_storage<sizeof(WebBackForwardList), std::alignment_of<WebBackForwardList>::value>::type _list;
     38}
     39
     40- (void)dealloc
     41{
     42    reinterpret_cast<WebBackForwardList*>(&_list)->~WebBackForwardList();
     43
     44    [super dealloc];
    3945}
    4046
     
    4450        return nil;
    4551
    46     return [[[WKBackForwardListItem alloc] _initWithItem:*item] autorelease];
     52    return wrapper(*item);
    4753}
    4854
    4955- (WKBackForwardListItem *)currentItem
    5056{
    51     return toWKBackForwardListItem(_list->currentItem());
     57    return toWKBackForwardListItem(reinterpret_cast<WebBackForwardList*>(&_list)->currentItem());
    5258}
    5359
    5460- (WKBackForwardListItem *)backItem
    5561{
    56     return toWKBackForwardListItem(_list->backItem());
     62    return toWKBackForwardListItem(reinterpret_cast<WebBackForwardList*>(&_list)->backItem());
    5763}
    5864
    5965- (WKBackForwardListItem *)forwardItem
    6066{
    61     return toWKBackForwardListItem(_list->forwardItem());
     67    return toWKBackForwardListItem(reinterpret_cast<WebBackForwardList*>(&_list)->forwardItem());
    6268}
    6369
    6470- (WKBackForwardListItem *)itemAtIndex:(NSInteger)index
    6571{
    66     return toWKBackForwardListItem(_list->itemAtIndex(index));
     72    return toWKBackForwardListItem(reinterpret_cast<WebBackForwardList*>(&_list)->itemAtIndex(index));
    6773}
    6874
    6975- (NSUInteger)backListCount
    7076{
    71     return _list->backListCount();
     77    return reinterpret_cast<WebBackForwardList*>(&_list)->backListCount();
    7278}
    7379
    7480- (NSUInteger)forwardListCount
    7581{
    76     return _list->forwardListCount();
     82    return reinterpret_cast<WebBackForwardList*>(&_list)->forwardListCount();
    7783}
    7884
    7985- (NSArray *)backListWithLimit:(NSUInteger)limit
    8086{
    81     RefPtr<ImmutableArray> list = _list->backListAsImmutableArrayWithLimit(limit);
     87    RefPtr<ImmutableArray> list = reinterpret_cast<WebBackForwardList*>(&_list)->backListAsImmutableArrayWithLimit(limit);
    8288    if (!list)
    8389        return nil;
    8490
    85     return [WKNSArray web_arrayWithImmutableArray:*list];
     91    return [wrapper(*list.release().leakRef()) autorelease];
    8692}
    8793
    8894- (NSArray *)forwardListWithLimit:(NSUInteger)limit
    8995{
    90     RefPtr<ImmutableArray> list = _list->forwardListAsImmutableArrayWithLimit(limit);
     96    RefPtr<ImmutableArray> list = reinterpret_cast<WebBackForwardList*>(&_list)->forwardListAsImmutableArrayWithLimit(limit);
    9197    if (!list)
    9298        return nil;
    9399
    94     return [WKNSArray web_arrayWithImmutableArray:*list];
     100    return [wrapper(*list.release().leakRef()) autorelease];
    95101}
    96102
    97 @end
     103#pragma mark WKObject protocol implementation
    98104
    99 #pragma mark -
    100 
    101 @implementation WKBackForwardList (Internal)
    102 
    103 - (id)_initWithList:(WebBackForwardList&)list
     105- (APIObject &)_apiObject
    104106{
    105     if (!(self = [super init]))
    106         return nil;
    107 
    108     _list = &list;
    109 
    110     return self;
     107    return *reinterpret_cast<APIObject*>(&_list);
    111108}
    112109
  • trunk/Source/WebKit2/UIProcess/Cocoa/WKBackForwardListInternal.h

    r157748 r158324  
    2828#if WK_API_ENABLED
    2929
     30#import "WKObject.h"
     31#import "WebBackForwardList.h"
     32
    3033namespace WebKit {
    31 class WebBackForwardList;
     34inline WKBackForwardList *wrapper(WebBackForwardList& list) { ASSERT([list.wrapper() isKindOfClass:[WKBackForwardList class]]); return (WKBackForwardList *)list.wrapper(); }
    3235}
    3336
    34 @interface WKBackForwardList (Internal)
    35 
    36 - (id)_initWithList:(WebKit::WebBackForwardList&)list;
    37 
     37@interface WKBackForwardList () <WKObject>
    3838@end
    3939
  • trunk/Source/WebKit2/UIProcess/Cocoa/WKBackForwardListItem.mm

    r157951 r158324  
    2929#if WK_API_ENABLED
    3030
    31 #import "WebBackForwardListItem.h"
    32 #import "WKRetainPtr.h"
    33 #import "WKSharedAPICast.h"
    34 #import "WKStringCF.h"
    35 #import "WKURLCF.h"
     31#import "WebString.h"
    3632
    3733using namespace WebKit;
    3834
    3935@implementation WKBackForwardListItem {
    40     RefPtr<WebBackForwardListItem> _item;
     36    std::aligned_storage<sizeof(WebBackForwardListItem), std::alignment_of<WebBackForwardListItem>::value>::type _item;
     37}
     38
     39- (void)dealloc
     40{
     41    reinterpret_cast<WebBackForwardListItem*>(&_item)->~WebBackForwardListItem();
     42
     43    [super dealloc];
    4144}
    4245
    4346- (NSURL *)URL
    4447{
    45     if (!_item->url())
     48    if (!reinterpret_cast<WebBackForwardListItem*>(&_item)->url())
    4649        return nil;
    4750
    48     return CFBridgingRelease(WKURLCopyCFURL(kCFAllocatorDefault, adoptWK(toCopiedURLAPI(_item->url())).get()));
     51    return [NSURL URLWithString:reinterpret_cast<WebBackForwardListItem*>(&_item)->url()];
    4952}
    5053
    5154- (NSString *)title
    5255{
    53     if (!_item->title())
     56    if (!reinterpret_cast<WebBackForwardListItem*>(&_item)->title())
    5457        return nil;
    5558
    56     return CFBridgingRelease(WKStringCopyCFString(kCFAllocatorDefault, adoptWK(toCopiedAPI(_item->title())).get()));
     59    return reinterpret_cast<WebBackForwardListItem*>(&_item)->title();
    5760}
    5861
    5962- (NSURL *)originalURL
    6063{
    61     if (!_item->originalURL())
     64    if (!reinterpret_cast<WebBackForwardListItem*>(&_item)->originalURL())
    6265        return nil;
    6366
    64     return CFBridgingRelease(WKURLCopyCFURL(kCFAllocatorDefault, adoptWK(toCopiedURLAPI(_item->originalURL())).get()));
     67    return [NSURL URLWithString:reinterpret_cast<WebBackForwardListItem*>(&_item)->originalURL()];
    6568}
    6669
    67 #pragma mark - NSObject protocol implementation
     70#pragma mark WKObject protocol implementation
    6871
    69 - (BOOL)isEqual:(id)object
     72- (APIObject&)_apiObject
    7073{
    71     if ([object class] != [self class])
    72         return NO;
    73 
    74     return _item == ((WKBackForwardListItem *)object)->_item;
    75 }
    76 
    77 - (NSUInteger)hash
    78 {
    79     return (NSUInteger)_item.get();
     74    return *reinterpret_cast<APIObject*>(&_item);
    8075}
    8176
    8277@end
    8378
    84 #pragma mark -
    85 
    8679@implementation WKBackForwardListItem (Internal)
    87 
    88 - (id)_initWithItem:(WebBackForwardListItem&)item
    89 {
    90     if (!(self = [super init]))
    91         return nil;
    92 
    93     _item = &item;
    94 
    95     return self;
    96 }
    9780
    9881- (WebKit::WebBackForwardListItem&)_item
    9982{
    100     return *_item;
     83    return *reinterpret_cast<WebBackForwardListItem*>(&_item);
    10184}
    10285
  • trunk/Source/WebKit2/UIProcess/Cocoa/WKBackForwardListItemInternal.h

    r157951 r158324  
    2828#if WK_API_ENABLED
    2929
     30#import "WKObject.h"
     31#import "WebBackForwardListItem.h"
     32
    3033namespace WebKit {
    31 class WebBackForwardListItem;
     34inline WKBackForwardListItem *wrapper(WebBackForwardListItem& item) { ASSERT([item.wrapper() isKindOfClass:[WKBackForwardListItem class]]); return (WKBackForwardListItem *)item.wrapper(); }
    3235}
    3336
     37@interface WKBackForwardListItem () <WKObject>
     38@end
     39
    3440@interface WKBackForwardListItem (Internal)
    35 
    36 - (id)_initWithItem:(WebKit::WebBackForwardListItem&)item;
    3741
    3842@property (readonly) WebKit::WebBackForwardListItem& _item;
  • trunk/Source/WebKit2/UIProcess/WebColorPickerResultListenerProxy.h

    r128553 r158324  
    3838class WebPageProxy;
    3939
    40 class WebColorPickerResultListenerProxy : public APIObject {
     40class WebColorPickerResultListenerProxy : public TypedAPIObject<APIObject::TypeColorPickerResultListener> {
    4141public:
    42     static const Type APIType = TypeColorPickerResultListener;
    43 
    4442    static PassRefPtr<WebColorPickerResultListenerProxy> create(WebPageProxy* page)
    4543    {
     
    5553    explicit WebColorPickerResultListenerProxy(WebPageProxy*);
    5654
    57     virtual Type type() const { return APIType; }
    58 
    5955    RefPtr<WebPageProxy> m_page;
    6056};
  • trunk/Source/WebKit2/UIProcess/WebFormSubmissionListenerProxy.h

    r95901 r158324  
    2929#include "WebFrameListenerProxy.h"
    3030
     31#if PLATFORM(MAC)
     32#include "WKFoundation.h"
     33#endif
     34
     35#define DELEGATE_REF_COUNTING_TO_COCOA (PLATFORM(MAC) && WK_API_ENABLED)
     36
    3137namespace WebKit {
    3238
     
    4854
    4955    virtual Type type() const { return APIType; }
     56
     57#if DELEGATE_REF_COUNTING_TO_COCOA
     58    void* operator new(size_t size) { return newObject(size, APIType); }
     59#endif
    5060};
    5161
    5262} // namespace WebKit
    5363
     64#undef DELEGATE_REF_COUNTING_TO_COCOA
     65
    5466#endif // WebFramePolicyListenerProxy_h
  • trunk/Source/WebKit2/UIProcess/WebFramePolicyListenerProxy.h

    r95901 r158324  
    2929#include "WebFrameListenerProxy.h"
    3030
     31#if PLATFORM(MAC)
     32#include "WKFoundation.h"
     33#endif
     34
     35#define DELEGATE_REF_COUNTING_TO_COCOA (PLATFORM(MAC) && WK_API_ENABLED)
     36
    3137namespace WebKit {
    3238
     
    4854
    4955    virtual Type type() const { return APIType; }
     56
     57#if DELEGATE_REF_COUNTING_TO_COCOA
     58    void* operator new(size_t size) { return newObject(size, APIType); }
     59#endif
    5060};
    5161
    5262} // namespace WebKit
    5363
     64#undef DELEGATE_REF_COUNTING_TO_COCOA
     65
    5466#endif // WebFramePolicyListenerProxy_h
  • trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

    r158316 r158324  
    394394                33D3A3CB1339617900709BE4 /* WebMediaCacheManagerProxyMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 33D3A3C71339617900709BE4 /* WebMediaCacheManagerProxyMessages.h */; };
    395395                33F9D5B91312F1EE000D683F /* WebResourceCacheManagerCFNet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33F9D5B81312F1EE000D683F /* WebResourceCacheManagerCFNet.cpp */; };
     396                374436881820E7240049579F /* WKObject.mm in Sources */ = {isa = PBXBuildFile; fileRef = 374436871820E7240049579F /* WKObject.mm */; };
    396397                3760881E150413E900FC82C7 /* WebRenderObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3760881C150413E900FC82C7 /* WebRenderObject.cpp */; };
    397398                3760881F150413E900FC82C7 /* WebRenderObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 3760881D150413E900FC82C7 /* WebRenderObject.h */; };
     
    402403                377EAD4917E2C77B002D193D /* WKUserScriptInjectionTime.h in Headers */ = {isa = PBXBuildFile; fileRef = 377EAD4717E2C77B002D193D /* WKUserScriptInjectionTime.h */; settings = {ATTRIBUTES = (Public, ); }; };
    403404                3788A05C14743C90006319E5 /* WKBrowsingContextControllerPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 3788A05B14743C90006319E5 /* WKBrowsingContextControllerPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
     405                378E1A3D181ED6FF0031007A /* APIObject.mm in Sources */ = {isa = PBXBuildFile; fileRef = 378E1A3B181ED6FF0031007A /* APIObject.mm */; };
     406                378E1A40181EDA010031007A /* WKObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 378E1A3F181EDA010031007A /* WKObject.h */; };
     407                378E1A4918208CD60031007A /* WKNSString.mm in Sources */ = {isa = PBXBuildFile; fileRef = 378E1A4718208CD60031007A /* WKNSString.mm */; };
     408                378E1A4A18208CD60031007A /* WKNSString.h in Headers */ = {isa = PBXBuildFile; fileRef = 378E1A4818208CD60031007A /* WKNSString.h */; };
     409                378E1A4D18208D700031007A /* WKNSURL.mm in Sources */ = {isa = PBXBuildFile; fileRef = 378E1A4B18208D700031007A /* WKNSURL.mm */; };
     410                378E1A4E18208D700031007A /* WKNSURL.h in Headers */ = {isa = PBXBuildFile; fileRef = 378E1A4C18208D700031007A /* WKNSURL.h */; };
    404411                37948403150C350600E52CE9 /* WebRenderLayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37948401150C350600E52CE9 /* WebRenderLayer.cpp */; };
    405412                37948404150C350600E52CE9 /* WebRenderLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 37948402150C350600E52CE9 /* WebRenderLayer.h */; };
     
    414421                37C4C0941814B3AF003688B9 /* WKNSArray.h in Headers */ = {isa = PBXBuildFile; fileRef = 37C4C0921814B3AF003688B9 /* WKNSArray.h */; };
    415422                37C4C0951814B9E6003688B9 /* WKBackForwardListInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 37C4C08E1814AF3A003688B9 /* WKBackForwardListInternal.h */; };
    416                 37C4C0981814BF9C003688B9 /* WKNSObjectExtras.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37C4C0961814BF9C003688B9 /* WKNSObjectExtras.mm */; };
    417                 37C4C0991814BF9C003688B9 /* WKNSObjectExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = 37C4C0971814BF9C003688B9 /* WKNSObjectExtras.h */; };
    418423                37C4E9F6131C6E7E0029BD5A /* config.h in Headers */ = {isa = PBXBuildFile; fileRef = B396EA5512E0ED2D00F4FEB7 /* config.h */; };
    419424                37DFA7001810BB92001F4A9F /* WKFoundation.h in Headers */ = {isa = PBXBuildFile; fileRef = 37DFA6FF1810BB92001F4A9F /* WKFoundation.h */; settings = {ATTRIBUTES = (Public, ); }; };
     
    18771882                33F9D5B81312F1EE000D683F /* WebResourceCacheManagerCFNet.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; name = WebResourceCacheManagerCFNet.cpp; path = ResourceCache/cf/WebResourceCacheManagerCFNet.cpp; sourceTree = "<group>"; };
    18781883                3574B37F1665932C00859BB7 /* PDFAnnotationTextWidgetDetails.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = PDFAnnotationTextWidgetDetails.h; path = PDF/PDFAnnotationTextWidgetDetails.h; sourceTree = "<group>"; };
     1884                374436871820E7240049579F /* WKObject.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKObject.mm; sourceTree = "<group>"; };
    18791885                3760881C150413E900FC82C7 /* WebRenderObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebRenderObject.cpp; sourceTree = "<group>"; };
    18801886                3760881D150413E900FC82C7 /* WebRenderObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebRenderObject.h; sourceTree = "<group>"; };
     
    18851891                377EAD4717E2C77B002D193D /* WKUserScriptInjectionTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKUserScriptInjectionTime.h; sourceTree = "<group>"; };
    18861892                3788A05B14743C90006319E5 /* WKBrowsingContextControllerPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKBrowsingContextControllerPrivate.h; sourceTree = "<group>"; };
     1893                378E1A3B181ED6FF0031007A /* APIObject.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = APIObject.mm; sourceTree = "<group>"; };
     1894                378E1A3F181EDA010031007A /* WKObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKObject.h; sourceTree = "<group>"; };
     1895                378E1A4718208CD60031007A /* WKNSString.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKNSString.mm; sourceTree = "<group>"; };
     1896                378E1A4818208CD60031007A /* WKNSString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKNSString.h; sourceTree = "<group>"; };
     1897                378E1A4B18208D700031007A /* WKNSURL.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKNSURL.mm; sourceTree = "<group>"; };
     1898                378E1A4C18208D700031007A /* WKNSURL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKNSURL.h; sourceTree = "<group>"; };
    18871899                37948401150C350600E52CE9 /* WebRenderLayer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebRenderLayer.cpp; sourceTree = "<group>"; };
    18881900                37948402150C350600E52CE9 /* WebRenderLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebRenderLayer.h; sourceTree = "<group>"; };
     
    18971909                37C4C0911814B3AF003688B9 /* WKNSArray.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKNSArray.mm; sourceTree = "<group>"; };
    18981910                37C4C0921814B3AF003688B9 /* WKNSArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKNSArray.h; sourceTree = "<group>"; };
    1899                 37C4C0961814BF9C003688B9 /* WKNSObjectExtras.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKNSObjectExtras.mm; sourceTree = "<group>"; };
    1900                 37C4C0971814BF9C003688B9 /* WKNSObjectExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKNSObjectExtras.h; sourceTree = "<group>"; };
    19011911                37DFA6FF1810BB92001F4A9F /* WKFoundation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKFoundation.h; sourceTree = "<group>"; };
    19021912                37F623B712A57B6200E3FDF6 /* WKFindOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKFindOptions.h; sourceTree = "<group>"; };
     
    36653675                        isa = PBXGroup;
    36663676                        children = (
     3677                                378E1A3B181ED6FF0031007A /* APIObject.mm */,
    36673678                                37C4C0921814B3AF003688B9 /* WKNSArray.h */,
    36683679                                37C4C0911814B3AF003688B9 /* WKNSArray.mm */,
    3669                                 37C4C0971814BF9C003688B9 /* WKNSObjectExtras.h */,
    3670                                 37C4C0961814BF9C003688B9 /* WKNSObjectExtras.mm */,
     3680                                378E1A4818208CD60031007A /* WKNSString.h */,
     3681                                378E1A4718208CD60031007A /* WKNSString.mm */,
     3682                                378E1A4C18208D700031007A /* WKNSURL.h */,
     3683                                378E1A4B18208D700031007A /* WKNSURL.mm */,
     3684                                378E1A3F181EDA010031007A /* WKObject.h */,
     3685                                374436871820E7240049579F /* WKObject.mm */,
    36713686                        );
    36723687                        path = Cocoa;
     
    54375452                                C517388112DF8F4F00EE3F47 /* DragControllerAction.h in Headers */,
    54385453                                BC8452A81162C80900CAB9B5 /* DrawingArea.h in Headers */,
     5454                                378E1A4A18208CD60031007A /* WKNSString.h in Headers */,
    54395455                                2D8949F1182044F600E898AA /* PlatformCALayerRemoteTiledBacking.h in Headers */,
    54405456                                0FB659231208B4DB0044816C /* DrawingAreaInfo.h in Headers */,
     
    54715487                                BC8147D512F66D31007B2C32 /* InjectedBundleNavigationAction.h in Headers */,
    54725488                                BC4BEEAB120A0A5F00FBA0C7 /* InjectedBundleNodeHandle.h in Headers */,
     5489                                378E1A4E18208D700031007A /* WKNSURL.h in Headers */,
    54735490                                512935E41288D97800A4B695 /* InjectedBundlePageContextMenuClient.h in Headers */,
    54745491                                E1EE53E311F8CFC000CCBEE4 /* InjectedBundlePageEditorClient.h in Headers */,
     
    54865503                                1A588B33174AAE0B00ACF472 /* KeyedCodingValue.h in Headers */,
    54875504                                1A588B37174AB77000ACF472 /* KeyedCodingValueCF.h in Headers */,
    5488                                 37C4C0991814BF9C003688B9 /* WKNSObjectExtras.h in Headers */,
    54895505                                1A588B31174AAC7100ACF472 /* KeyedEncoder.h in Headers */,
    54905506                                BCE0937814FB128C001138D9 /* LayerHostingContext.h in Headers */,
     
    58975913                                BC407602124FF0270068F20A /* WKNumber.h in Headers */,
    58985914                                7CD5EBB91746A15B000C1C45 /* WKObjCTypeWrapperRef.h in Headers */,
     5915                                378E1A40181EDA010031007A /* WKObject.h in Headers */,
    58995916                                BC857FE612B843D800EDEB2E /* WKOpenPanelParameters.h in Headers */,
    59005917                                BC1DFE8F12B31CA8005DF730 /* WKOpenPanelResultListener.h in Headers */,
     
    67026719                                5136183D163126DA00A99DDE /* ConnectionStack.cpp in Sources */,
    67036720                                2DA049B7180CCD0A00AAFA9E /* GraphicsLayerCARemote.cpp in Sources */,
     6721                                378E1A4D18208D700031007A /* WKNSURL.mm in Sources */,
    67046722                                2DA049B3180CCCD300AAFA9E /* PlatformCALayerRemote.cpp in Sources */,
    67056723                                CDC3831017212440008A2FC3 /* CookieStorageShim.cpp in Sources */,
     
    67386756                                1A91010B1268C8CA001842F5 /* FindIndicatorWindow.mm in Sources */,
    67396757                                BCE81D8C1319F7EF00241910 /* FontInfo.cpp in Sources */,
     6758                                378E1A4918208CD60031007A /* WKNSString.mm in Sources */,
    67406759                                BC06F43012DBB9B6002D78DE /* GeolocationPermissionRequestManager.cpp in Sources */,
    67416760                                BC06F44B12DBD1F5002D78DE /* GeolocationPermissionRequestManagerProxy.cpp in Sources */,
     
    69256944                                1AF05D8614688348008B1E81 /* TiledCoreAnimationDrawingAreaProxy.mm in Sources */,
    69266945                                1A64245F12DE29A100CAAE2C /* UpdateInfo.cpp in Sources */,
     6946                                374436881820E7240049579F /* WKObject.mm in Sources */,
    69276947                                1A0F29E3120B44420053D1B9 /* VisitedLinkProvider.cpp in Sources */,
    69286948                                1A0F29CB120B37160053D1B9 /* VisitedLinkTable.cpp in Sources */,
     
    69877007                                BCA0EFA012332642007D3CFB /* WebEditCommandProxy.cpp in Sources */,
    69887008                                BC111A5E112F4FBB00337BAB /* WebEditorClient.cpp in Sources */,
    6989                                 37C4C0981814BF9C003688B9 /* WKNSObjectExtras.mm in Sources */,
    69907009                                C5237F6012441CA300780472 /* WebEditorClientMac.mm in Sources */,
    69917010                                BC575613126E0138006F0F12 /* WebError.cpp in Sources */,
     
    71027121                                510AFFB916542048001BA05E /* WebResourceLoader.cpp in Sources */,
    71037122                                51F060E11654318500F3281B /* WebResourceLoaderMessageReceiver.cpp in Sources */,
     7123                                378E1A3D181ED6FF0031007A /* APIObject.mm in Sources */,
    71047124                                51FB08FF1639DE1A00EC324A /* WebResourceLoadScheduler.cpp in Sources */,
    71057125                                D3B9484811FF4B6500032B39 /* WebSearchPopupMenu.cpp in Sources */,
Note: See TracChangeset for help on using the changeset viewer.