78ac012afedc4d9432b705fb90dd932c55f830e0
[WebKit.git] / WebKit2 / UIProcess / API / C / WKPage.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 WKPage_h
27 #define WKPage_h
28
29 #include <WebKit2/WKBase.h>
30
31 #ifndef __cplusplus
32 #include <stdbool.h>
33 #endif
34
35 #include <stdint.h>
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 enum {
42     kWKFrameNavigationTypeLinkClicked = 0,
43     kWKFrameNavigationTypeFormSubmitted = 1,
44     kWKFrameNavigationTypeBackForward = 2,
45     kWKFrameNavigationTypeReload = 3,
46     kWKFrameNavigationTypeFormResubmitted = 4,
47     kWKFrameNavigationTypeOther = 5
48 };
49 typedef uint32_t WKFrameNavigationType;
50
51 enum {
52     kWKEventModifiersShiftKey = 1 << 0,
53     kWKEventModifiersControlKey = 1 << 1,
54     kWKEventModifiersAltKey = 1 << 2,
55     kWKEventModifiersMetaKey = 1 << 3
56 };
57 typedef uint32_t WKEventModifiers;
58
59 // FrameLoad Client
60 typedef void (*WKPageDidStartProvisionalLoadForFrameCallback)(WKPageRef page, WKFrameRef frame, const void *clientInfo);
61 typedef void (*WKPageDidReceiveServerRedirectForProvisionalLoadForFrameCallback)(WKPageRef page, WKFrameRef frame, const void *clientInfo);
62 typedef void (*WKPageDidFailProvisionalLoadWithErrorForFrameCallback)(WKPageRef page, WKFrameRef frame, const void *clientInfo); // FIXME: Add WKErrorRef.
63 typedef void (*WKPageDidCommitLoadForFrameCallback)(WKPageRef page, WKFrameRef frame, const void *clientInfo);
64 typedef void (*WKPageDidFinishDocumentLoadForFrameCallback)(WKPageRef page, WKFrameRef frame, const void *clientInfo);
65 typedef void (*WKPageDidFinishLoadForFrameCallback)(WKPageRef page, WKFrameRef frame, const void *clientInfo);
66 typedef void (*WKPageDidFailLoadWithErrorForFrameCallback)(WKPageRef page, WKFrameRef frame, const void *clientInfo); // FIXME: Add WKErrorRef.
67 typedef void (*WKPageDidReceiveTitleForFrameCallback)(WKPageRef page, WKStringRef title, WKFrameRef frame, const void *clientInfo);
68 typedef void (*WKPageDidFirstLayoutForFrame)(WKPageRef page, WKFrameRef frame, const void *clientInfo);
69 typedef void (*WKPageDidFirstVisuallyNonEmptyLayoutForFrame)(WKPageRef page, WKFrameRef frame, const void *clientInfo);
70
71 // Progress Client
72 typedef void (*WKPageDidStartProgressCallback)(WKPageRef page, const void *clientInfo);
73 typedef void (*WKPageDidChangeProgressCallback)(WKPageRef page, const void *clientInfo);
74 typedef void (*WKPageDidFinishProgressCallback)(WKPageRef page, const void *clientInfo);
75
76 // WebPageNamespace Client
77 // FIXME: These three functions should not be part of this client.
78 typedef void (*WKPageDidBecomeUnresponsiveCallback)(WKPageRef page, const void *clientInfo);
79 typedef void (*WKPageDidBecomeResponsiveCallback)(WKPageRef page, const void *clientInfo);
80 typedef void (*WKPageProcessDidExitCallback)(WKPageRef page, const void *clientInfo);
81
82 typedef void (*WKPageDidChangeBackForwardListCallback)(WKPageRef page, const void *clientInfo);
83
84 struct WKPageLoaderClient {
85     int                                                                 version;
86     const void *                                                        clientInfo;
87     WKPageDidStartProvisionalLoadForFrameCallback                       didStartProvisionalLoadForFrame;
88     WKPageDidReceiveServerRedirectForProvisionalLoadForFrameCallback    didReceiveServerRedirectForProvisionalLoadForFrame;
89     WKPageDidFailProvisionalLoadWithErrorForFrameCallback               didFailProvisionalLoadWithErrorForFrame;
90     WKPageDidCommitLoadForFrameCallback                                 didCommitLoadForFrame;
91     WKPageDidFinishDocumentLoadForFrameCallback                         didFinishDocumentLoadForFrame;
92     WKPageDidFinishLoadForFrameCallback                                 didFinishLoadForFrame;
93     WKPageDidFailLoadWithErrorForFrameCallback                          didFailLoadWithErrorForFrame;
94     WKPageDidReceiveTitleForFrameCallback                               didReceiveTitleForFrame;
95     WKPageDidFirstLayoutForFrame                                        didFirstLayoutForFrame;
96     WKPageDidFirstVisuallyNonEmptyLayoutForFrame                        didFirstVisuallyNonEmptyLayoutForFrame;
97
98     // FIXME: Move to progress client.
99     WKPageDidStartProgressCallback                                      didStartProgress;
100     WKPageDidChangeProgressCallback                                     didChangeProgress;
101     WKPageDidFinishProgressCallback                                     didFinishProgress;
102
103     // FIXME: These three functions should not be part of this client.
104     WKPageDidBecomeUnresponsiveCallback                                 didBecomeUnresponsive;
105     WKPageDidBecomeResponsiveCallback                                   didBecomeResponsive;
106     WKPageProcessDidExitCallback                                        processDidExit;
107
108     WKPageDidChangeBackForwardListCallback                              didChangeBackForwardList;
109 };
110 typedef struct WKPageLoaderClient WKPageLoaderClient;
111
112 // Policy Client.
113 typedef void (*WKPageDecidePolicyForNavigationActionCallback)(WKPageRef page, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKURLRef url, WKFrameRef frame, WKFramePolicyListenerRef listener, const void *clientInfo);
114 typedef void (*WKPageDecidePolicyForNewWindowActionCallback)(WKPageRef page, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKURLRef url, WKFrameRef frame, WKFramePolicyListenerRef listener, const void *clientInfo);
115 typedef void (*WKPageDecidePolicyForMIMETypeCallback)(WKPageRef page, WKStringRef MIMEType, WKURLRef url, WKFrameRef frame, WKFramePolicyListenerRef listener, const void *clientInfo);
116
117 struct WKPagePolicyClient {
118     int                                                                 version;
119     const void *                                                        clientInfo;
120     WKPageDecidePolicyForNavigationActionCallback                       decidePolicyForNavigationAction;
121     WKPageDecidePolicyForNewWindowActionCallback                        decidePolicyForNewWindowAction;
122     WKPageDecidePolicyForMIMETypeCallback                               decidePolicyForMIMEType;
123 };
124 typedef struct WKPagePolicyClient WKPagePolicyClient;
125
126 // Form Client.
127 typedef void (*WKPageWillSubmitFormCallback)(WKPageRef page, WKFrameRef frame, WKFrameRef sourceFrame, WKDictionaryRef values, WKTypeRef userData, WKFormSubmissionListenerRef listener, const void* clientInfo);
128
129 struct WKPageFormClient {
130     int                                                                 version;
131     const void *                                                        clientInfo;
132     WKPageWillSubmitFormCallback                                        willSubmitForm;
133 };
134 typedef struct WKPageFormClient WKPageFormClient;
135
136 // UI Client
137 typedef WKPageRef (*WKPageCreateNewPageCallback)(WKPageRef page, const void *clientInfo);
138 typedef void (*WKPageShowPageCallback)(WKPageRef page, const void *clientInfo);
139 typedef void (*WKPageCloseCallback)(WKPageRef page, const void *clientInfo);
140 typedef void (*WKPageRunJavaScriptAlertCallback)(WKPageRef page, WKStringRef alertText, WKFrameRef frame, const void *clientInfo);
141 typedef bool (*WKPageRunJavaScriptConfirmCallback)(WKPageRef page, WKStringRef message, WKFrameRef frame, const void *clientInfo);
142 typedef WKStringRef (*WKPageRunJavaScriptPromptCallback)(WKPageRef page, WKStringRef message, WKStringRef defaultValue, WKFrameRef frame, const void *clientInfo);
143 typedef void (*WKPageContentsSizeChangedCallback)(WKPageRef page, int width, int height, WKFrameRef frame, const void *clientInfo);
144
145 struct WKPageUIClient {
146     int                                                                 version;
147     const void *                                                        clientInfo;
148     WKPageCreateNewPageCallback                                         createNewPage;
149     WKPageShowPageCallback                                              showPage;
150     WKPageCloseCallback                                                 close;
151     WKPageRunJavaScriptAlertCallback                                    runJavaScriptAlert;
152     WKPageRunJavaScriptConfirmCallback                                  runJavaScriptConfirm;
153     WKPageRunJavaScriptPromptCallback                                   runJavaScriptPrompt;
154     WKPageContentsSizeChangedCallback                                   contentsSizeChanged;
155 };
156 typedef struct WKPageUIClient WKPageUIClient;
157
158 WK_EXPORT WKTypeID WKPageGetTypeID();
159
160 WK_EXPORT WKPageNamespaceRef WKPageGetPageNamespace(WKPageRef page);
161
162 WK_EXPORT void WKPageLoadURL(WKPageRef page, WKURLRef url);
163 WK_EXPORT void WKPageLoadURLRequest(WKPageRef page, WKURLRequestRef urlRequest);
164
165 WK_EXPORT void WKPageStopLoading(WKPageRef page);
166 WK_EXPORT void WKPageReload(WKPageRef page);
167 WK_EXPORT void WKPageReloadFromOrigin(WKPageRef page);
168
169 WK_EXPORT bool WKPageTryClose(WKPageRef page);
170 WK_EXPORT void WKPageClose(WKPageRef page);
171 WK_EXPORT bool WKPageIsClosed(WKPageRef page);
172
173 WK_EXPORT void WKPageGoForward(WKPageRef page);
174 WK_EXPORT bool WKPageCanGoForward(WKPageRef page);
175 WK_EXPORT void WKPageGoBack(WKPageRef page);
176 WK_EXPORT bool WKPageCanGoBack(WKPageRef page);
177 WK_EXPORT void WKPageGoToBackForwardListItem(WKPageRef page, WKBackForwardListItemRef item);
178 WK_EXPORT WKBackForwardListRef WKPageGetBackForwardList(WKPageRef page);
179
180 WK_EXPORT WKStringRef WKPageCopyTitle(WKPageRef page);
181
182 WK_EXPORT WKFrameRef WKPageGetMainFrame(WKPageRef page);
183 WK_EXPORT double WKPageGetEstimatedProgress(WKPageRef page);
184
185 WK_EXPORT void WKPageSetCustomUserAgent(WKPageRef page, WKStringRef userAgent);
186
187 WK_EXPORT void WKPageTerminate(WKPageRef page);
188
189 WK_EXPORT WKDataRef WKPageCopySessionState(WKPageRef page);
190 WK_EXPORT void WKPageRestoreFromSessionState(WKPageRef page, WKDataRef sessionStateData);
191
192 WK_EXPORT double WKPageGetTextZoomFactor(WKPageRef page);
193 WK_EXPORT void WKPageSetTextZoomFactor(WKPageRef page, double zoomFactor);
194 WK_EXPORT double WKPageGetPageZoomFactor(WKPageRef page);
195 WK_EXPORT void WKPageSetPageZoomFactor(WKPageRef page, double zoomFactor);
196 WK_EXPORT void WKPageSetPageAndTextZoomFactors(WKPageRef page, double pageZoomFactor, double textZoomFactor);
197
198 WK_EXPORT void WKPageSetPageLoaderClient(WKPageRef page, const WKPageLoaderClient* client);
199 WK_EXPORT void WKPageSetPagePolicyClient(WKPageRef page, const WKPagePolicyClient* client);
200 WK_EXPORT void WKPageSetPageFormClient(WKPageRef page, const WKPageFormClient* client);
201 WK_EXPORT void WKPageSetPageUIClient(WKPageRef page, const WKPageUIClient* client);
202
203 typedef void (*WKPageRunJavaScriptFunction)(WKStringRef, WKErrorRef, void*);
204 WK_EXPORT void WKPageRunJavaScriptInMainFrame(WKPageRef page, WKStringRef script, void *context, WKPageRunJavaScriptFunction function);
205 #ifdef __BLOCKS__
206 typedef void (^WKPageRunJavaScriptBlock)(WKStringRef, WKErrorRef);
207 WK_EXPORT void WKPageRunJavaScriptInMainFrame_b(WKPageRef page, WKStringRef script, WKPageRunJavaScriptBlock block);
208 #endif
209
210 typedef void (*WKPageGetSourceForFrameFunction)(WKStringRef, WKErrorRef, void*);
211 WK_EXPORT void WKPageGetSourceForFrame(WKPageRef page, WKFrameRef frame, void *context, WKPageGetSourceForFrameFunction function);
212 #ifdef __BLOCKS__
213 typedef void (^WKPageGetSourceForFrameBlock)(WKStringRef, WKErrorRef);
214 WK_EXPORT void WKPageGetSourceForFrame_b(WKPageRef page, WKFrameRef frame, WKPageGetSourceForFrameBlock block);
215 #endif
216
217 #ifdef __cplusplus
218 }
219 #endif
220
221 #endif /* WKPage_h */