[Cocoa] Make all API objects have Cocoa wrappers, and delegate refcounting to those...
[WebKit-https.git] / Source / WebKit2 / Shared / APIObject.h
1 /*
2  * Copyright (C) 2010 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #ifndef APIObject_h
27 #define APIObject_h
28
29 #include <wtf/RefCounted.h>
30
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
38 OBJC_CLASS NSObject;
39 #endif
40
41 namespace WebKit {
42
43 class APIObject
44 #if !DELEGATE_REF_COUNTING_TO_COCOA
45     : public ThreadSafeRefCounted<APIObject>
46 #endif
47 {
48 public:
49     enum Type {
50         // Base types
51         TypeNull = 0,
52         TypeArray,
53         TypeAuthenticationChallenge,
54         TypeAuthenticationDecisionListener,
55         TypeCertificateInfo,
56         TypeConnection,
57         TypeContextMenuItem,
58         TypeCredential,
59         TypeData,
60         TypeDictionary,
61         TypeError,
62         TypeGraphicsContext,
63         TypeImage,
64         TypeProtectionSpace,
65         TypeRenderLayer,
66         TypeRenderObject,
67         TypeSecurityOrigin,
68         TypeSerializedScriptValue,
69         TypeString,
70         TypeURL,
71         TypeURLRequest,
72         TypeURLResponse,
73         TypeUserContentURLPattern,
74         TypeWebArchive,
75         TypeWebArchiveResource,
76
77         // Base numeric types
78         TypeBoolean,
79         TypeDouble,
80         TypeUInt64,
81         
82         // Geometry types
83         TypePoint,
84         TypeSize,
85         TypeRect,
86         
87         // UIProcess types
88         TypeApplicationCacheManager,
89         TypeBackForwardList,
90         TypeBackForwardListItem,
91         TypeBatteryManager,
92         TypeBatteryStatus,
93         TypeCacheManager,
94         TypeColorPickerResultListener,
95         TypeContext,
96         TypeCookieManager,
97         TypeDatabaseManager,
98         TypeDownload,
99         TypeFormSubmissionListener,
100         TypeFrame,
101         TypeFramePolicyListener,
102         TypeFullScreenManager,
103         TypeGeolocationManager,
104         TypeGeolocationPermissionRequest,
105         TypeHitTestResult,
106         TypeGeolocationPosition,
107         TypeGrammarDetail,
108         TypeIconDatabase,
109         TypeInspector,
110         TypeKeyValueStorageManager,
111         TypeMediaCacheManager,
112         TypeNavigationData,
113         TypeNetworkInfo,
114         TypeNetworkInfoManager,
115         TypeNotification,
116         TypeNotificationManager,
117         TypeNotificationPermissionRequest,
118         TypeOpenPanelParameters,
119         TypeOpenPanelResultListener,
120         TypeOriginDataManager,
121         TypePage,
122         TypePageGroup,
123         TypePluginSiteDataManager,
124         TypePreferences,
125         TypeTextChecker,
126         TypeVibration,
127         TypeViewportAttributes,
128
129         // Bundle types
130         TypeBundle,
131         TypeBundleBackForwardList,
132         TypeBundleBackForwardListItem,
133         TypeBundleDOMWindowExtension,
134         TypeBundleFrame,
135         TypeBundleHitTestResult,
136         TypeBundleInspector,
137         TypeBundleNavigationAction,
138         TypeBundleNodeHandle,
139         TypeBundlePage,
140         TypeBundlePageBanner,
141         TypeBundlePageGroup,
142         TypeBundlePageOverlay,
143         TypeBundleRangeHandle,
144         TypeBundleScriptWorld,
145
146         // Platform specific
147         TypeEditCommandProxy,
148         TypeObjCObjectGraph,
149         TypeView,
150 #if USE(SOUP)
151         TypeSoupRequestManager,
152 #endif
153 #if PLATFORM(EFL)
154         TypePopupMenuItem,
155 #if ENABLE(TOUCH_EVENTS)
156         TypeTouchPoint,
157         TypeTouchEvent,
158 #endif
159 #endif
160     };
161
162     virtual ~APIObject()
163     {
164     }
165
166     virtual Type type() const = 0;
167
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
175 protected:
176     APIObject();
177
178 #if DELEGATE_REF_COUNTING_TO_COCOA
179     static void* newObject(size_t, Type);
180
181 private:
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
187 };
188
189 template <APIObject::Type ArgumentType>
190 class TypedAPIObject : public APIObject {
191 public:
192     static const Type APIType = ArgumentType;
193
194     virtual ~TypedAPIObject()
195     {
196     }
197
198 protected:
199     TypedAPIObject()
200     {
201     }
202
203     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
208 };
209
210 } // namespace WebKit
211
212 #undef DELEGATE_REF_COUNTING_TO_COCOA
213
214 #endif // APIObject_h