1/*
2 * Copyright 2006, 2007, 2008, 2009, 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. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef WebCoreSystemInterface_h
27#define WebCoreSystemInterface_h
28
29#include <objc/objc.h>
30
31#if PLATFORM(IOS)
32#include "WebCoreSystemInterfaceIOS.h"
33#endif
34
35typedef const struct __CFString * CFStringRef;
36typedef const struct __CFNumber * CFNumberRef;
37typedef const struct __CFDictionary * CFDictionaryRef;
38typedef struct CGPoint CGPoint;
39typedef struct CGSize CGSize;
40typedef struct CGRect CGRect;
41typedef struct CGAffineTransform CGAffineTransform;
42typedef struct CGContext *CGContextRef;
43typedef struct CGImage *CGImageRef;
44typedef struct CGColor *CGColorRef;
45typedef struct CGFont *CGFontRef;
46typedef struct CGColorSpace *CGColorSpaceRef;
47typedef struct CGPattern *CGPatternRef;
48typedef struct CGPath *CGMutablePathRef;
49typedef unsigned short CGGlyph;
50typedef struct __CFReadStream * CFReadStreamRef;
51typedef struct __CFRunLoop * CFRunLoopRef;
52typedef struct __CFHTTPMessage *CFHTTPMessageRef;
53typedef struct _CFURLResponse *CFURLResponseRef;
54typedef const struct _CFURLRequest *CFURLRequestRef;
55typedef const struct __CTFont * CTFontRef;
56typedef const struct __CTLine * CTLineRef;
57typedef const struct __CTRun * CTRunRef;
58typedef const struct __CTTypesetter * CTTypesetterRef;
59typedef const struct __AXUIElement *AXUIElementRef;
60#if !PLATFORM(IOS)
61typedef struct _NSRange NSRange;
62typedef double NSTimeInterval;
63
64typedef UInt32 FMFont;
65typedef FMFont ATSUFontID;
66typedef UInt16 ATSGlyphRef;
67#endif
68
69#if PLATFORM(COCOA) && USE(CA)
70#if !PLATFORM(IOS_SIMULATOR)
71typedef struct __IOSurface *IOSurfaceRef;
72#endif // !PLATFORM(IOS_SIMULATOR)
73#endif
74
75#if !PLATFORM(IOS)
76#ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
77typedef struct CGPoint NSPoint;
78typedef struct CGRect NSRect;
79#else
80typedef struct _NSPoint NSPoint;
81typedef struct _NSRect NSRect;
82#endif
83#endif // !PLATFORM(IOS)
84
85#if PLATFORM(IOS)
86#include <CoreGraphics/CoreGraphics.h>
87#endif
88
89#if USE(CFNETWORK)
90typedef struct OpaqueCFHTTPCookieStorage*  CFHTTPCookieStorageRef;
91typedef struct _CFURLProtectionSpace* CFURLProtectionSpaceRef;
92typedef struct _CFURLCredential* WKCFURLCredentialRef;
93typedef struct _CFURLRequest* CFMutableURLRequestRef;
94typedef const struct _CFURLRequest* CFURLRequestRef;
95#endif
96
97OBJC_CLASS AVAsset;
98OBJC_CLASS AVPlayer;
99OBJC_CLASS CALayer;
100OBJC_CLASS NSArray;
101OBJC_CLASS NSButtonCell;
102OBJC_CLASS NSCell;
103OBJC_CLASS NSControl;
104OBJC_CLASS NSCursor;
105OBJC_CLASS NSData;
106OBJC_CLASS NSDate;
107OBJC_CLASS NSEvent;
108OBJC_CLASS NSFont;
109OBJC_CLASS NSHTTPCookie;
110OBJC_CLASS NSImage;
111OBJC_CLASS NSLocale;
112OBJC_CLASS NSMenu;
113OBJC_CLASS NSMutableURLRequest;
114OBJC_CLASS NSString;
115OBJC_CLASS NSTextFieldCell;
116OBJC_CLASS NSURL;
117OBJC_CLASS NSURLConnection;
118OBJC_CLASS NSURLRequest;
119OBJC_CLASS NSURLResponse;
120OBJC_CLASS NSView;
121OBJC_CLASS NSWindow;
122OBJC_CLASS QTMovie;
123OBJC_CLASS QTMovieView;
124
125extern "C" {
126
127// In alphabetical order.
128
129extern void (*wkAdvanceDefaultButtonPulseAnimation)(NSButtonCell *);
130extern void (*wkCALayerEnumerateRectsBeingDrawnWithBlock)(CALayer *, CGContextRef, void (^block)(CGRect rect));
131
132extern BOOL (*wkCGContextGetShouldSmoothFonts)(CGContextRef);
133typedef enum {
134    wkPatternTilingNoDistortion,
135    wkPatternTilingConstantSpacingMinimalDistortion,
136    wkPatternTilingConstantSpacing
137} wkPatternTiling;
138extern void (*wkCGContextResetClip)(CGContextRef);
139#if !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
140extern bool (*wkCGContextDrawsWithCorrectShadowOffsets)(CGContextRef);
141#endif
142extern CGPatternRef (*wkCGPatternCreateWithImageAndTransform)(CGImageRef, CGAffineTransform, int);
143extern CFReadStreamRef (*wkCreateCustomCFReadStream)(void *(*formCreate)(CFReadStreamRef, void *),
144    void (*formFinalize)(CFReadStreamRef, void *),
145    Boolean (*formOpen)(CFReadStreamRef, CFStreamError *, Boolean *, void *),
146    CFIndex (*formRead)(CFReadStreamRef, UInt8 *, CFIndex, CFStreamError *, Boolean *, void *),
147    Boolean (*formCanRead)(CFReadStreamRef, void *),
148    void (*formClose)(CFReadStreamRef, void *),
149    void (*formSchedule)(CFReadStreamRef, CFRunLoopRef, CFStringRef, void *),
150    void (*formUnschedule)(CFReadStreamRef, CFRunLoopRef, CFStringRef, void *),
151    void *context);
152extern CFStringRef (*wkCopyCFLocalizationPreferredName)(CFStringRef);
153extern NSString* (*wkCopyNSURLResponseStatusLine)(NSURLResponse*);
154extern CFArrayRef (*wkCopyNSURLResponseCertificateChain)(NSURLResponse*);
155extern CFStringEncoding (*wkGetWebDefaultCFStringEncoding)(void);
156#if !PLATFORM(IOS)
157extern void (*wkDrawBezeledTextFieldCell)(NSRect, BOOL enabled);
158extern void (*wkDrawTextFieldCellFocusRing)(NSTextFieldCell*, NSRect);
159extern void (*wkDrawCapsLockIndicator)(CGContextRef, CGRect);
160extern void (*wkDrawBezeledTextArea)(NSRect, BOOL enabled);
161extern void (*wkDrawFocusRing)(CGContextRef, CGColorRef, int);
162extern bool (*wkDrawFocusRingAtTime)(CGContextRef, NSTimeInterval time);
163extern bool (*wkDrawCellFocusRingWithFrameAtTime)(NSCell *cell, NSRect cellFrame, NSView *controlView, NSTimeInterval time);
164
165extern NSFont* (*wkGetFontInLanguageForRange)(NSFont*, NSString*, NSRange);
166extern NSFont* (*wkGetFontInLanguageForCharacter)(NSFont*, UniChar);
167extern BOOL (*wkGetGlyphTransformedAdvances)(CGFontRef, NSFont*, CGAffineTransform*, ATSGlyphRef*, CGSize* advance);
168#endif
169#if !PLATFORM(IOS)
170extern void (*wkDrawMediaSliderTrack)(CGContextRef context, CGRect rect, float timeLoaded, float currentTime,
171    float duration, unsigned state);
172extern void (*wkDrawMediaUIPart)(int part, CGContextRef context, CGRect rect, unsigned state);
173extern CFStringRef (*wkSignedPublicKeyAndChallengeString)(unsigned keySize, CFStringRef challenge, CFStringRef keyDescription);
174extern NSString* (*wkGetPreferredExtensionForMIMEType)(NSString*);
175extern NSArray* (*wkGetExtensionsForMIMEType)(NSString*);
176#endif
177extern NSString* (*wkGetMIMETypeForExtension)(NSString*);
178#if !PLATFORM(IOS)
179extern ATSUFontID (*wkGetNSFontATSUFontId)(NSFont*);
180extern double (*wkGetNSURLResponseCalculatedExpiration)(NSURLResponse *response);
181#endif
182extern NSDate *(*wkGetNSURLResponseLastModifiedDate)(NSURLResponse *response);
183#if !PLATFORM(IOS)
184extern BOOL (*wkGetNSURLResponseMustRevalidate)(NSURLResponse *response);
185extern void (*wkGetWheelEventDeltas)(NSEvent*, float* deltaX, float* deltaY, BOOL* continuous);
186extern UInt8 (*wkGetNSEventKeyChar)(NSEvent *);
187extern BOOL (*wkHitTestMediaUIPart)(int part, CGRect bounds, CGPoint point);
188extern void (*wkMeasureMediaUIPart)(int part, CGRect *bounds, CGSize *naturalSize);
189extern NSView *(*wkCreateMediaUIBackgroundView)(void);
190
191typedef enum {
192    wkMediaUIControlTimeline,
193    wkMediaUIControlSlider,
194    wkMediaUIControlPlayPauseButton,
195    wkMediaUIControlExitFullscreenButton,
196    wkMediaUIControlRewindButton,
197    wkMediaUIControlFastForwardButton,
198    wkMediaUIControlVolumeUpButton,
199    wkMediaUIControlVolumeDownButton
200} wkMediaUIControlType;
201extern NSControl *(*wkCreateMediaUIControl)(int);
202
203extern void (*wkWindowSetAlpha)(NSWindow *, float);
204extern void (*wkWindowSetScaledFrame)(NSWindow *, NSRect, NSRect);
205
206#if defined(__OBJC__)
207extern void (*wkPopupMenu)(NSMenu*, NSPoint location, float width, NSView*, int selectedItem, NSFont*, NSControlSize controlSize, bool hideArrows);
208extern void (*wkPopupMenuWithSize)(NSMenu*, NSPoint location, float width, NSView*, int selectedItem, NSFont*, NSControlSize controlSize);
209#endif
210
211extern unsigned (*wkQTIncludeOnlyModernMediaFileTypes)(void);
212extern int (*wkQTMovieDataRate)(QTMovie*);
213extern void (*wkQTMovieDisableComponent)(uint32_t[5]);
214extern float (*wkQTMovieMaxTimeLoaded)(QTMovie*);
215extern NSString *(*wkQTMovieMaxTimeLoadedChangeNotification)(void);
216extern float (*wkQTMovieMaxTimeSeekable)(QTMovie*);
217extern int (*wkQTMovieGetType)(QTMovie*);
218extern BOOL (*wkQTMovieHasClosedCaptions)(QTMovie*);
219extern NSURL *(*wkQTMovieResolvedURL)(QTMovie*);
220extern void (*wkQTMovieSetShowClosedCaptions)(QTMovie*, BOOL);
221extern void (*wkQTMovieSelectPreferredAlternates)(QTMovie*);
222extern void (*wkQTMovieViewSetDrawSynchronously)(QTMovieView*, BOOL);
223extern NSArray *(*wkQTGetSitesInMediaDownloadCache)();
224extern void (*wkQTClearMediaDownloadCacheForSite)(NSString *site);
225extern void (*wkQTClearMediaDownloadCache)();
226extern void (*wkSetCGFontRenderingMode)(CGContextRef, NSFont*, BOOL);
227extern void (*wkSetCookieStoragePrivateBrowsingEnabled)(BOOL);
228extern void (*wkSetDragImage)(NSImage*, NSPoint offset);
229#endif
230extern void (*wkSetNSURLConnectionDefersCallbacks)(NSURLConnection *, BOOL);
231extern void (*wkSetNSURLRequestShouldContentSniff)(NSMutableURLRequest *, BOOL);
232extern void (*wkSetBaseCTM)(CGContextRef, CGAffineTransform);
233extern void (*wkSetPatternPhaseInUserSpace)(CGContextRef, CGPoint);
234extern CGAffineTransform (*wkGetUserToBaseCTM)(CGContextRef);
235extern bool (*wkCGContextIsPDFContext)(CGContextRef);
236extern void (*wkSetUpFontCache)();
237extern void (*wkSignalCFReadStreamEnd)(CFReadStreamRef stream);
238extern void (*wkSignalCFReadStreamError)(CFReadStreamRef stream, CFStreamError *error);
239extern void (*wkSignalCFReadStreamHasBytes)(CFReadStreamRef stream);
240extern unsigned (*wkInitializeMaximumHTTPConnectionCountPerHost)(unsigned preferredConnectionCount);
241extern int (*wkGetHTTPRequestPriority)(CFURLRequestRef);
242extern void (*wkSetHTTPRequestMaximumPriority)(int maximumPriority);
243extern void (*wkSetHTTPRequestPriority)(CFURLRequestRef, int priority);
244extern void (*wkSetHTTPRequestMinimumFastLanePriority)(int priority);
245extern void (*wkHTTPRequestEnablePipelining)(CFURLRequestRef);
246extern void (*wkSetCONNECTProxyForStream)(CFReadStreamRef, CFStringRef proxyHost, CFNumberRef proxyPort);
247extern void (*wkSetCONNECTProxyAuthorizationForStream)(CFReadStreamRef, CFStringRef proxyAuthorizationString);
248extern CFHTTPMessageRef (*wkCopyCONNECTProxyResponse)(CFReadStreamRef, CFURLRef responseURL, CFStringRef proxyHost, CFNumberRef proxyPort);
249
250extern void (*wkGetGlyphsForCharacters)(CGFontRef, const UniChar[], CGGlyph[], size_t);
251extern bool (*wkGetVerticalGlyphsForCharacters)(CTFontRef, const UniChar[], CGGlyph[], size_t);
252
253extern BOOL (*wkUseSharedMediaUI)();
254
255#if !PLATFORM(IOS)
256extern void* wkGetHyphenationLocationBeforeIndex;
257#endif
258
259extern CTLineRef (*wkCreateCTLineWithUniCharProvider)(const UniChar* (*provide)(CFIndex stringIndex, CFIndex* charCount, CFDictionaryRef* attributes, void*), void (*dispose)(const UniChar* chars, void*), void*);
260
261#if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
262enum {
263    wkCTFontTransformApplyShaping = (1 << 0),
264    wkCTFontTransformApplyPositioning = (1 << 1)
265};
266
267typedef int wkCTFontTransformOptions;
268
269extern bool (*wkCTFontTransformGlyphs)(CTFontRef font, CGGlyph glyphs[], CGSize advances[], CFIndex count, wkCTFontTransformOptions options);
270#endif
271
272extern CTTypesetterRef (*wkCreateCTTypesetterWithUniCharProviderAndOptions)(const UniChar* (*provide)(CFIndex stringIndex, CFIndex* charCount, CFDictionaryRef* attributes, void*), void (*dispose)(const UniChar* chars, void*), void*, CFDictionaryRef options);
273
274extern CGSize (*wkCTRunGetInitialAdvance)(CTRunRef);
275
276#if PLATFORM(COCOA) && USE(CA) && !PLATFORM(IOS_SIMULATOR)
277extern CGContextRef (*wkIOSurfaceContextCreate)(IOSurfaceRef surface, unsigned width, unsigned height, CGColorSpaceRef colorSpace);
278extern CGImageRef (*wkIOSurfaceContextCreateImage)(CGContextRef context);
279#endif
280
281#if PLATFORM(MAC) || PLATFORM(IOS_SIMULATOR)
282extern void (*wkSetCrashReportApplicationSpecificInformation)(CFStringRef);
283#endif
284
285#if !PLATFORM(IOS)
286extern int (*wkRecommendedScrollerStyle)(void);
287
288extern bool (*wkExecutableWasLinkedOnOrBeforeSnowLeopard)(void);
289
290extern CFStringRef (*wkCopyDefaultSearchProviderDisplayName)(void);
291
292extern NSCursor *(*wkCursor)(const char*);
293#endif // !PLATFORM(IOS)
294
295#if !PLATFORM(IOS)
296extern NSArray *(*wkSpeechSynthesisGetVoiceIdentifiers)(void);
297extern NSString *(*wkSpeechSynthesisGetDefaultVoiceIdentifierForLocale)(NSLocale *);
298
299extern void (*wkUnregisterUniqueIdForElement)(id element);
300extern void (*wkAccessibilityHandleFocusChanged)(void);
301extern CFTypeID (*wkGetAXTextMarkerTypeID)(void);
302extern CFTypeID (*wkGetAXTextMarkerRangeTypeID)(void);
303extern CFTypeRef (*wkCreateAXTextMarkerRange)(CFTypeRef start, CFTypeRef end);
304extern CFTypeRef (*wkCopyAXTextMarkerRangeStart)(CFTypeRef range);
305extern CFTypeRef (*wkCopyAXTextMarkerRangeEnd)(CFTypeRef range);
306extern CFTypeRef (*wkCreateAXTextMarker)(const void *bytes, size_t len);
307extern BOOL (*wkGetBytesFromAXTextMarker)(CFTypeRef textMarker, void *bytes, size_t length);
308extern AXUIElementRef (*wkCreateAXUIElementRef)(id element);
309#endif // !PLATFORM(IOS)
310
311#if PLATFORM(IOS)
312extern CGSize (*wkGetScreenSize)(void);
313extern CGSize (*wkGetAvailableScreenSize)(void);
314extern void (*wkSetLayerContentsScale)(CALayer *);
315extern float (*wkGetScreenScaleFactor)(void);
316#endif
317
318typedef const struct __CFURLStorageSession* CFURLStorageSessionRef;
319extern CFURLStorageSessionRef (*wkCreatePrivateStorageSession)(CFStringRef);
320extern NSURLRequest* (*wkCopyRequestWithStorageSession)(CFURLStorageSessionRef, NSURLRequest*);
321
322typedef struct OpaqueCFHTTPCookieStorage* CFHTTPCookieStorageRef;
323extern CFHTTPCookieStorageRef (*wkCopyHTTPCookieStorage)(CFURLStorageSessionRef);
324extern unsigned (*wkGetHTTPCookieAcceptPolicy)(CFHTTPCookieStorageRef);
325extern void (*wkSetHTTPCookieAcceptPolicy)(CFHTTPCookieStorageRef, unsigned);
326extern NSArray *(*wkHTTPCookies)(CFHTTPCookieStorageRef);
327extern NSArray *(*wkHTTPCookiesForURL)(CFHTTPCookieStorageRef, NSURL *, NSURL *);
328extern void (*wkSetHTTPCookiesForURL)(CFHTTPCookieStorageRef, NSArray *, NSURL *, NSURL *);
329extern void (*wkDeleteHTTPCookie)(CFHTTPCookieStorageRef, NSHTTPCookie *);
330extern void (*wkDeleteAllHTTPCookies)(CFHTTPCookieStorageRef);
331
332extern CFStringRef (*wkGetCFURLResponseMIMEType)(CFURLResponseRef);
333extern CFURLRef (*wkGetCFURLResponseURL)(CFURLResponseRef);
334extern CFHTTPMessageRef (*wkGetCFURLResponseHTTPResponse)(CFURLResponseRef);
335extern CFStringRef (*wkCopyCFURLResponseSuggestedFilename)(CFURLResponseRef);
336extern void (*wkSetCFURLResponseMIMEType)(CFURLResponseRef, CFStringRef mimeType);
337
338extern void(*wkDestroyRenderingResources)(void);
339
340#if USE(CFNETWORK)
341extern CFHTTPCookieStorageRef (*wkGetDefaultHTTPCookieStorage)();
342extern WKCFURLCredentialRef (*wkCopyCredentialFromCFPersistentStorage)(CFURLProtectionSpaceRef protectionSpace);
343extern void (*wkSetCFURLRequestShouldContentSniff)(CFMutableURLRequestRef, bool);
344extern void (*wkSetRequestStorageSession)(CFURLStorageSessionRef, CFMutableURLRequestRef);
345#endif
346#if !PLATFORM(IOS)
347extern void (*wkSetMetadataURL)(NSString *urlString, NSString *referrer, NSString *path);
348#endif
349
350#if !PLATFORM(IOS)
351#import <dispatch/dispatch.h>
352
353extern dispatch_source_t (*wkCreateVMPressureDispatchOnMainQueue)(void);
354#endif
355
356#if !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
357extern dispatch_source_t (*wkCreateMemoryStatusPressureCriticalDispatchOnMainQueue)(void);
358#endif
359
360#if !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
361extern bool (*wkExecutableWasLinkedOnOrBeforeLion)(void);
362#endif
363
364extern void (*wkCGPathAddRoundedRect)(CGMutablePathRef path, const CGAffineTransform* matrix, CGRect rect, CGFloat cornerWidth, CGFloat cornerHeight);
365
366extern void (*wkCFURLRequestAllowAllPostCaching)(CFURLRequestRef);
367
368#if !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
369extern CGFloat (*wkNSElasticDeltaForTimeDelta)(CGFloat initialPosition, CGFloat initialVelocity, CGFloat elapsedTime);
370extern CGFloat (*wkNSElasticDeltaForReboundDelta)(CGFloat delta);
371extern CGFloat (*wkNSReboundDeltaForElasticDelta)(CGFloat delta);
372#endif
373
374#if ENABLE(PUBLIC_SUFFIX_LIST)
375extern bool (*wkIsPublicSuffix)(NSString *host);
376#endif
377
378#if ENABLE(CACHE_PARTITIONING)
379extern CFStringRef (*wkCachePartitionKey)(void);
380#endif
381
382typedef enum {
383    wkExternalPlaybackTypeNone,
384    wkExternalPlaybackTypeAirPlay,
385    wkExternalPlaybackTypeTVOut,
386} wkExternalPlaybackType;
387extern int (*wkExernalDeviceTypeForPlayer)(AVPlayer *);
388extern NSString *(*wkExernalDeviceDisplayNameForPlayer)(AVPlayer *);
389
390extern bool (*wkQueryDecoderAvailability)(void);
391
392}
393
394#endif
395