Implement WebKit2 callback equivalent to - [WebUIDelegate webView:setStatusText:]
[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 (*WKPageSetStatusTextCallback)(WKPageRef page, WKStringRef text, const void *clientInfo);
144 typedef void (*WKPageContentsSizeChangedCallback)(WKPageRef page, int width, int height, WKFrameRef frame, const void *clientInfo);
145
146 struct WKPageUIClient {
147     int                                                                 version;
148     const void *                                                        clientInfo;
149     WKPageCreateNewPageCallback                                         createNewPage;
150     WKPageShowPageCallback                                              showPage;
151     WKPageCloseCallback                                                 close;
152     WKPageRunJavaScriptAlertCallback                                    runJavaScriptAlert;
153     WKPageRunJavaScriptConfirmCallback                                  runJavaScriptConfirm;
154     WKPageRunJavaScriptPromptCallback                                   runJavaScriptPrompt;
155     WKPageSetStatusTextCallback                                         setStatusText;
156     WKPageContentsSizeChangedCallback                                   contentsSizeChanged;
157 };
158 typedef struct WKPageUIClient WKPageUIClient;
159
160 WK_EXPORT WKTypeID WKPageGetTypeID();
161
162 WK_EXPORT WKPageNamespaceRef WKPageGetPageNamespace(WKPageRef page);
163
164 WK_EXPORT void WKPageLoadURL(WKPageRef page, WKURLRef url);
165 WK_EXPORT void WKPageLoadURLRequest(WKPageRef page, WKURLRequestRef urlRequest);
166
167 WK_EXPORT void WKPageStopLoading(WKPageRef page);
168 WK_EXPORT void WKPageReload(WKPageRef page);
169 WK_EXPORT void WKPageReloadFromOrigin(WKPageRef page);
170
171 WK_EXPORT bool WKPageTryClose(WKPageRef page);
172 WK_EXPORT void WKPageClose(WKPageRef page);
173 WK_EXPORT bool WKPageIsClosed(WKPageRef page);
174
175 WK_EXPORT void WKPageGoForward(WKPageRef page);
176 WK_EXPORT bool WKPageCanGoForward(WKPageRef page);
177 WK_EXPORT void WKPageGoBack(WKPageRef page);
178 WK_EXPORT bool WKPageCanGoBack(WKPageRef page);
179 WK_EXPORT void WKPageGoToBackForwardListItem(WKPageRef page, WKBackForwardListItemRef item);
180 WK_EXPORT WKBackForwardListRef WKPageGetBackForwardList(WKPageRef page);
181
182 WK_EXPORT WKStringRef WKPageCopyTitle(WKPageRef page);
183
184 WK_EXPORT WKFrameRef WKPageGetMainFrame(WKPageRef page);
185 WK_EXPORT double WKPageGetEstimatedProgress(WKPageRef page);
186
187 WK_EXPORT void WKPageSetCustomUserAgent(WKPageRef page, WKStringRef userAgent);
188
189 WK_EXPORT void WKPageTerminate(WKPageRef page);
190
191 WK_EXPORT WKDataRef WKPageCopySessionState(WKPageRef page);
192 WK_EXPORT void WKPageRestoreFromSessionState(WKPageRef page, WKDataRef sessionStateData);
193
194 WK_EXPORT double WKPageGetTextZoomFactor(WKPageRef page);
195 WK_EXPORT void WKPageSetTextZoomFactor(WKPageRef page, double zoomFactor);
196 WK_EXPORT double WKPageGetPageZoomFactor(WKPageRef page);
197 WK_EXPORT void WKPageSetPageZoomFactor(WKPageRef page, double zoomFactor);
198 WK_EXPORT void WKPageSetPageAndTextZoomFactors(WKPageRef page, double pageZoomFactor, double textZoomFactor);
199
200 WK_EXPORT void WKPageSetPageLoaderClient(WKPageRef page, const WKPageLoaderClient* client);
201 WK_EXPORT void WKPageSetPagePolicyClient(WKPageRef page, const WKPagePolicyClient* client);
202 WK_EXPORT void WKPageSetPageFormClient(WKPageRef page, const WKPageFormClient* client);
203 WK_EXPORT void WKPageSetPageUIClient(WKPageRef page, const WKPageUIClient* client);
204
205 typedef void (*WKPageRunJavaScriptFunction)(WKStringRef, WKErrorRef, void*);
206 WK_EXPORT void WKPageRunJavaScriptInMainFrame(WKPageRef page, WKStringRef script, void *context, WKPageRunJavaScriptFunction function);
207 #ifdef __BLOCKS__
208 typedef void (^WKPageRunJavaScriptBlock)(WKStringRef, WKErrorRef);
209 WK_EXPORT void WKPageRunJavaScriptInMainFrame_b(WKPageRef page, WKStringRef script, WKPageRunJavaScriptBlock block);
210 #endif
211
212 typedef void (*WKPageGetSourceForFrameFunction)(WKStringRef, WKErrorRef, void*);
213 WK_EXPORT void WKPageGetSourceForFrame(WKPageRef page, WKFrameRef frame, void *context, WKPageGetSourceForFrameFunction function);
214 #ifdef __BLOCKS__
215 typedef void (^WKPageGetSourceForFrameBlock)(WKStringRef, WKErrorRef);
216 WK_EXPORT void WKPageGetSourceForFrame_b(WKPageRef page, WKFrameRef frame, WKPageGetSourceForFrameBlock block);
217 #endif
218
219 #ifdef __cplusplus
220 }
221 #endif
222
223 #endif /* WKPage_h */