1/*
2 * Copyright (C) 2010, 2011 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 WKPage_h
27#define WKPage_h
28
29#include <WebKit/WKBase.h>
30#include <WebKit/WKDeprecated.h>
31#include <WebKit/WKErrorRef.h>
32#include <WebKit/WKEvent.h>
33#include <WebKit/WKFindOptions.h>
34#include <WebKit/WKGeometry.h>
35#include <WebKit/WKNativeEvent.h>
36#include <WebKit/WKPageContextMenuClient.h>
37#include <WebKit/WKPageDiagnosticLoggingClient.h>
38#include <WebKit/WKPageFindClient.h>
39#include <WebKit/WKPageFindMatchesClient.h>
40#include <WebKit/WKPageFormClient.h>
41#include <WebKit/WKPageInjectedBundleClient.h>
42#include <WebKit/WKPageLoadTypes.h>
43#include <WebKit/WKPageLoaderClient.h>
44#include <WebKit/WKPageNavigationClient.h>
45#include <WebKit/WKPagePolicyClient.h>
46#include <WebKit/WKPageUIClient.h>
47#include <WebKit/WKPageVisibilityTypes.h>
48
49#ifndef __cplusplus
50#include <stdbool.h>
51#endif
52
53#ifdef __cplusplus
54extern "C" {
55#endif
56
57WK_EXPORT WKTypeID WKPageGetTypeID();
58
59WK_EXPORT WKContextRef WKPageGetContext(WKPageRef page);
60WK_EXPORT WKPageGroupRef WKPageGetPageGroup(WKPageRef page);
61
62WK_EXPORT WKPageConfigurationRef WKPageCopyPageConfiguration(WKPageRef page);
63
64// URL Requests
65WK_EXPORT void WKPageLoadURL(WKPageRef page, WKURLRef url);
66WK_EXPORT void WKPageLoadURLWithUserData(WKPageRef page, WKURLRef url, WKTypeRef userData);
67WK_EXPORT void WKPageLoadURLRequest(WKPageRef page, WKURLRequestRef urlRequest);
68WK_EXPORT void WKPageLoadURLRequestWithUserData(WKPageRef page, WKURLRequestRef urlRequest, WKTypeRef userData);
69WK_EXPORT void WKPageLoadFile(WKPageRef page, WKURLRef fileURL, WKURLRef resourceDirectoryURL);
70WK_EXPORT void WKPageLoadFileWithUserData(WKPageRef page, WKURLRef fileURL, WKURLRef resourceDirectoryURL, WKTypeRef userData);
71
72// Data Requests
73WK_EXPORT void WKPageLoadData(WKPageRef page, WKDataRef data, WKStringRef MIMEType, WKStringRef encoding, WKURLRef baseURL);
74WK_EXPORT void WKPageLoadDataWithUserData(WKPageRef page, WKDataRef data, WKStringRef MIMEType, WKStringRef encoding, WKURLRef baseURL, WKTypeRef userData);
75WK_EXPORT void WKPageLoadHTMLString(WKPageRef page, WKStringRef htmlString, WKURLRef baseURL);
76WK_EXPORT void WKPageLoadHTMLStringWithUserData(WKPageRef page, WKStringRef htmlString, WKURLRef baseURL, WKTypeRef userData);
77WK_EXPORT void WKPageLoadAlternateHTMLString(WKPageRef page, WKStringRef htmlString, WKURLRef baseURL, WKURLRef unreachableURL);
78WK_EXPORT void WKPageLoadAlternateHTMLStringWithUserData(WKPageRef page, WKStringRef htmlString, WKURLRef baseURL, WKURLRef unreachableURL, WKTypeRef userData);
79WK_EXPORT void WKPageLoadPlainTextString(WKPageRef page, WKStringRef plainTextString);
80WK_EXPORT void WKPageLoadPlainTextStringWithUserData(WKPageRef page, WKStringRef plainTextString, WKTypeRef userData);
81WK_EXPORT void WKPageLoadWebArchiveData(WKPageRef page, WKDataRef webArchiveData);
82WK_EXPORT void WKPageLoadWebArchiveDataWithUserData(WKPageRef page, WKDataRef webArchiveData, WKTypeRef userData);
83
84WK_EXPORT void WKPageStopLoading(WKPageRef page);
85WK_EXPORT void WKPageReload(WKPageRef page);
86WK_EXPORT void WKPageReloadWithoutContentBlockers(WKPageRef page);
87WK_EXPORT void WKPageReloadFromOrigin(WKPageRef page);
88WK_EXPORT void WKPageReloadExpiredOnly(WKPageRef page);
89
90WK_EXPORT bool WKPageTryClose(WKPageRef page);
91WK_EXPORT void WKPageClose(WKPageRef page);
92WK_EXPORT bool WKPageIsClosed(WKPageRef page);
93
94WK_EXPORT void WKPageGoForward(WKPageRef page);
95WK_EXPORT bool WKPageCanGoForward(WKPageRef page);
96WK_EXPORT void WKPageGoBack(WKPageRef page);
97WK_EXPORT bool WKPageCanGoBack(WKPageRef page);
98WK_EXPORT void WKPageGoToBackForwardListItem(WKPageRef page, WKBackForwardListItemRef item);
99WK_EXPORT void WKPageTryRestoreScrollPosition(WKPageRef page);
100WK_EXPORT WKBackForwardListRef WKPageGetBackForwardList(WKPageRef page);
101WK_EXPORT bool WKPageWillHandleHorizontalScrollEvents(WKPageRef page);
102
103WK_EXPORT void WKPageUpdateWebsitePolicies(WKPageRef, WKWebsitePoliciesRef);
104
105WK_EXPORT WKStringRef WKPageCopyTitle(WKPageRef page);
106
107WK_EXPORT WKURLRef WKPageCopyPendingAPIRequestURL(WKPageRef page);
108
109WK_EXPORT WKURLRef WKPageCopyActiveURL(WKPageRef page);
110WK_EXPORT WKURLRef WKPageCopyProvisionalURL(WKPageRef page);
111WK_EXPORT WKURLRef WKPageCopyCommittedURL(WKPageRef page);
112
113WK_EXPORT WKFrameRef WKPageGetMainFrame(WKPageRef page);
114WK_EXPORT WKFrameRef WKPageGetFocusedFrame(WKPageRef page); // The focused frame may be inactive.
115WK_EXPORT WKFrameRef WKPageGetFrameSetLargestFrame(WKPageRef page);
116WK_EXPORT double WKPageGetEstimatedProgress(WKPageRef page);
117
118WK_EXPORT uint64_t WKPageGetRenderTreeSize(WKPageRef page);
119
120WK_EXPORT WKInspectorRef WKPageGetInspector(WKPageRef page);
121
122WK_EXPORT WKStringRef WKPageCopyUserAgent(WKPageRef page);
123
124WK_EXPORT WKStringRef WKPageCopyApplicationNameForUserAgent(WKPageRef page);
125WK_EXPORT void WKPageSetApplicationNameForUserAgent(WKPageRef page, WKStringRef applicationName);
126
127WK_EXPORT WKStringRef WKPageCopyCustomUserAgent(WKPageRef page);
128WK_EXPORT void WKPageSetCustomUserAgent(WKPageRef page, WKStringRef userAgent);
129
130WK_EXPORT void WKPageSetUserContentExtensionsEnabled(WKPageRef, bool);
131
132WK_EXPORT bool WKPageSupportsTextEncoding(WKPageRef page);
133WK_EXPORT WKStringRef WKPageCopyCustomTextEncodingName(WKPageRef page);
134WK_EXPORT void WKPageSetCustomTextEncodingName(WKPageRef page, WKStringRef encodingName);
135
136WK_EXPORT void WKPageTerminate(WKPageRef page);
137
138WK_EXPORT WKStringRef WKPageGetSessionHistoryURLValueType(void);
139WK_EXPORT WKStringRef WKPageGetSessionBackForwardListItemValueType(void);
140
141typedef bool (*WKPageSessionStateFilterCallback)(WKPageRef page, WKStringRef valueType, WKTypeRef value, void* context);
142
143// FIXME: This should return a WKSessionStateRef object, not a WKTypeRef.
144// It currently returns a WKTypeRef for backwards compatibility with Safari.
145WK_EXPORT WKTypeRef WKPageCopySessionState(WKPageRef page, void* context, WKPageSessionStateFilterCallback urlAllowedCallback);
146
147// FIXME: This should take a WKSessionStateRef object, not a WKTypeRef.
148// It currently takes a WKTypeRef for backwards compatibility with Safari.
149WK_EXPORT void WKPageRestoreFromSessionState(WKPageRef page, WKTypeRef sessionState);
150
151WK_EXPORT double WKPageGetBackingScaleFactor(WKPageRef page);
152WK_EXPORT void WKPageSetCustomBackingScaleFactor(WKPageRef page, double customScaleFactor);
153WK_EXPORT void WKPageClearWheelEventTestTrigger(WKPageRef page);
154
155WK_EXPORT bool WKPageSupportsTextZoom(WKPageRef page);
156WK_EXPORT double WKPageGetTextZoomFactor(WKPageRef page);
157WK_EXPORT void WKPageSetTextZoomFactor(WKPageRef page, double zoomFactor);
158WK_EXPORT double WKPageGetPageZoomFactor(WKPageRef page);
159WK_EXPORT void WKPageSetPageZoomFactor(WKPageRef page, double zoomFactor);
160WK_EXPORT void WKPageSetPageAndTextZoomFactors(WKPageRef page, double pageZoomFactor, double textZoomFactor);
161
162WK_EXPORT void WKPageSetScaleFactor(WKPageRef page, double scale, WKPoint origin);
163WK_EXPORT double WKPageGetScaleFactor(WKPageRef page);
164
165WK_EXPORT void WKPageSetUseFixedLayout(WKPageRef page, bool fixed);
166WK_EXPORT void WKPageSetFixedLayoutSize(WKPageRef page, WKSize size);
167WK_EXPORT bool WKPageUseFixedLayout(WKPageRef page);
168WK_EXPORT WKSize WKPageFixedLayoutSize(WKPageRef page);
169
170WK_EXPORT void WKPageListenForLayoutMilestones(WKPageRef page, WKLayoutMilestones milestones);
171
172WK_EXPORT bool WKPageHasHorizontalScrollbar(WKPageRef page);
173WK_EXPORT bool WKPageHasVerticalScrollbar(WKPageRef page);
174
175WK_EXPORT void WKPageSetSuppressScrollbarAnimations(WKPageRef page, bool suppressAnimations);
176WK_EXPORT bool WKPageAreScrollbarAnimationsSuppressed(WKPageRef page);
177
178WK_EXPORT bool WKPageIsPinnedToLeftSide(WKPageRef page);
179WK_EXPORT bool WKPageIsPinnedToRightSide(WKPageRef page);
180WK_EXPORT bool WKPageIsPinnedToTopSide(WKPageRef page);
181WK_EXPORT bool WKPageIsPinnedToBottomSide(WKPageRef page);
182
183// This API is poorly named. Even when these values are set to false, rubber-banding will
184// still be allowed to occur at the end of a momentum scroll. These values are used along
185// with pin state to determine if wheel events should be handled in the web process or if
186// they should be passed up to the client.
187WK_EXPORT bool WKPageRubberBandsAtLeft(WKPageRef);
188WK_EXPORT void WKPageSetRubberBandsAtLeft(WKPageRef, bool rubberBandsAtLeft);
189WK_EXPORT bool WKPageRubberBandsAtRight(WKPageRef);
190WK_EXPORT void WKPageSetRubberBandsAtRight(WKPageRef, bool rubberBandsAtRight);
191WK_EXPORT bool WKPageRubberBandsAtTop(WKPageRef);
192WK_EXPORT void WKPageSetRubberBandsAtTop(WKPageRef, bool rubberBandsAtTop);
193WK_EXPORT bool WKPageRubberBandsAtBottom(WKPageRef);
194WK_EXPORT void WKPageSetRubberBandsAtBottom(WKPageRef, bool rubberBandsAtBottom);
195
196// Rubber-banding is enabled by default.
197WK_EXPORT bool WKPageVerticalRubberBandingIsEnabled(WKPageRef);
198WK_EXPORT void WKPageSetEnableVerticalRubberBanding(WKPageRef, bool enableVerticalRubberBanding);
199WK_EXPORT bool WKPageHorizontalRubberBandingIsEnabled(WKPageRef);
200WK_EXPORT void WKPageSetEnableHorizontalRubberBanding(WKPageRef, bool enableHorizontalRubberBanding);
201
202WK_EXPORT void WKPageSetBackgroundExtendsBeyondPage(WKPageRef, bool backgroundExtendsBeyondPage);
203WK_EXPORT bool WKPageBackgroundExtendsBeyondPage(WKPageRef);
204
205WK_EXPORT bool WKPageCanDelete(WKPageRef page);
206WK_EXPORT bool WKPageHasSelectedRange(WKPageRef page);
207WK_EXPORT bool WKPageIsContentEditable(WKPageRef page);
208
209WK_EXPORT void WKPageSetMaintainsInactiveSelection(WKPageRef page, bool maintainsInactiveSelection);
210WK_EXPORT void WKPageCenterSelectionInVisibleArea(WKPageRef page);
211
212WK_EXPORT void WKPageFindString(WKPageRef page, WKStringRef string, WKFindOptions findOptions, unsigned maxMatchCount);
213WK_EXPORT void WKPageHideFindUI(WKPageRef page);
214WK_EXPORT void WKPageCountStringMatches(WKPageRef page, WKStringRef string, WKFindOptions findOptions, unsigned maxMatchCount);
215WK_EXPORT void WKPageFindStringMatches(WKPageRef page, WKStringRef string, WKFindOptions findOptions, unsigned maxMatchCount);
216WK_EXPORT void WKPageGetImageForFindMatch(WKPageRef page, int32_t matchIndex);
217WK_EXPORT void WKPageSelectFindMatch(WKPageRef page, int32_t matchIndex);
218
219WK_EXPORT void WKPageSetPageContextMenuClient(WKPageRef page, const WKPageContextMenuClientBase* client);
220WK_EXPORT void WKPageSetPageDiagnosticLoggingClient(WKPageRef page, const WKPageDiagnosticLoggingClientBase* client);
221WK_EXPORT void WKPageSetPageFindClient(WKPageRef page, const WKPageFindClientBase* client);
222WK_EXPORT void WKPageSetPageFindMatchesClient(WKPageRef page, const WKPageFindMatchesClientBase* client);
223WK_EXPORT void WKPageSetPageFormClient(WKPageRef page, const WKPageFormClientBase* client);
224WK_EXPORT void WKPageSetPageUIClient(WKPageRef page, const WKPageUIClientBase* client);
225WK_EXPORT void WKPageSetPageInjectedBundleClient(WKPageRef page, const WKPageInjectedBundleClientBase* client);
226
227// A client can implement either a navigation client or loader and policy clients, but never both.
228WK_EXPORT void WKPageSetPageLoaderClient(WKPageRef page, const WKPageLoaderClientBase* client) WK_C_API_DEPRECATED_WITH_REPLACEMENT(WKPageSetPageNavigationClient, macos(10.14.4));
229WK_EXPORT void WKPageSetPagePolicyClient(WKPageRef page, const WKPagePolicyClientBase* client) WK_C_API_DEPRECATED_WITH_REPLACEMENT(WKPageSetPageNavigationClient, macos(10.14.4));
230WK_EXPORT void WKPageSetPageNavigationClient(WKPageRef page, const WKPageNavigationClientBase* client);
231
232typedef void (*WKPageRunJavaScriptFunction)(WKSerializedScriptValueRef, WKErrorRef, void*);
233WK_EXPORT void WKPageRunJavaScriptInMainFrame(WKPageRef page, WKStringRef script, void* context, WKPageRunJavaScriptFunction function);
234#ifdef __BLOCKS__
235typedef void (^WKPageRunJavaScriptBlock)(WKSerializedScriptValueRef, WKErrorRef);
236WK_EXPORT void WKPageRunJavaScriptInMainFrame_b(WKPageRef page, WKStringRef script, WKPageRunJavaScriptBlock block);
237#endif
238
239typedef void (*WKPageGetSourceForFrameFunction)(WKStringRef, WKErrorRef, void*);
240WK_EXPORT void WKPageGetSourceForFrame(WKPageRef page, WKFrameRef frame, void* context, WKPageGetSourceForFrameFunction function);
241
242typedef void (*WKPageGetContentsAsStringFunction)(WKStringRef, WKErrorRef, void*);
243WK_EXPORT void WKPageGetContentsAsString(WKPageRef page, void* context, WKPageGetContentsAsStringFunction function);
244
245typedef void (*WKPageGetContentsAsMHTMLDataFunction)(WKDataRef, WKErrorRef, void*);
246WK_EXPORT void WKPageGetContentsAsMHTMLData(WKPageRef page, void* context, WKPageGetContentsAsMHTMLDataFunction function);
247
248typedef void (*WKPageGetSelectionAsWebArchiveDataFunction)(WKDataRef, WKErrorRef, void*);
249WK_EXPORT void WKPageGetSelectionAsWebArchiveData(WKPageRef page, void* context, WKPageGetSelectionAsWebArchiveDataFunction function);
250
251typedef void (*WKPageForceRepaintFunction)(WKErrorRef, void*);
252WK_EXPORT void WKPageForceRepaint(WKPageRef page, void* context, WKPageForceRepaintFunction function);
253
254/*
255 Some of the more common command name strings include the following, although any WebCore EditorCommand string is supported:
256
257 "Cut"
258 "Copy"
259 "Paste"
260 "SelectAll"
261 "Undo"
262 "Redo"
263*/
264
265// state represents the state of the command in a menu (on is 1, off is 0, and mixed is -1), typically used to add a checkmark next to the menu item.
266typedef void (*WKPageValidateCommandCallback)(WKStringRef command, bool isEnabled, int32_t state, WKErrorRef, void* context);
267WK_EXPORT void WKPageValidateCommand(WKPageRef page, WKStringRef command, void* context, WKPageValidateCommandCallback callback);
268WK_EXPORT void WKPageExecuteCommand(WKPageRef page, WKStringRef command);
269
270WK_EXPORT void WKPagePostMessageToInjectedBundle(WKPageRef page, WKStringRef messageName, WKTypeRef messageBody);
271
272WK_EXPORT void WKPageSelectContextMenuItem(WKPageRef page, WKContextMenuItemRef item);
273
274#ifdef __cplusplus
275}
276#endif
277
278#endif /* WKPage_h */
279