deff014fd6e7a5a768477749af6da68e0622b2a8
[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 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 // FrameLoad Client
40 typedef void (*WKPageDidStartProvisionalLoadForFrameCallback)(WKPageRef page, WKFrameRef frame, const void *clientInfo);
41 typedef void (*WKPageDidReceiveServerRedirectForProvisionalLoadForFrameCallback)(WKPageRef page, WKFrameRef frame, const void *clientInfo);
42 typedef void (*WKPageDidFailProvisionalLoadWithErrorForFrameCallback)(WKPageRef page, WKFrameRef frame, const void *clientInfo); // FIXME: Add WKErrorRef.
43 typedef void (*WKPageDidCommitLoadForFrameCallback)(WKPageRef page, WKFrameRef frame, const void *clientInfo);
44 typedef void (*WKPageDidFinishLoadForFrameCallback)(WKPageRef page, WKFrameRef frame, const void *clientInfo);
45 typedef void (*WKPageDidFailLoadWithErrorForFrameCallback)(WKPageRef page, WKFrameRef frame, const void *clientInfo); // FIXME: Add WKErrorRef.
46 typedef void (*WKPageDidReceiveTitleForFrameCallback)(WKPageRef page, WKStringRef title, WKFrameRef frame, const void *clientInfo);
47 typedef void (*WKPageDidFirstLayoutForFrame)(WKPageRef page, WKFrameRef frame, const void *clientInfo);
48 typedef void (*WKPageDidFirstVisuallyNonEmptyLayoutForFrame)(WKPageRef page, WKFrameRef frame, const void *clientInfo);
49
50 // Progress Client
51 typedef void (*WKPageDidStartProgressCallback)(WKPageRef page, const void *clientInfo);
52 typedef void (*WKPageDidChangeProgressCallback)(WKPageRef page, const void *clientInfo);
53 typedef void (*WKPageDidFinishProgressCallback)(WKPageRef page, const void *clientInfo);
54
55 // WebPageNamespace Client
56 // FIXME: These two methods should not be part of this client.
57 typedef void (*WKPageDidBecomeUnresponsiveCallback)(WKPageRef page, const void *clientInfo);
58 typedef void (*WKPageDidBecomeResponsiveCallback)(WKPageRef page, const void *clientInfo);
59
60 struct WKPageLoaderClient {
61     int                                                                 version;
62     const void *                                                        clientInfo;
63     WKPageDidStartProvisionalLoadForFrameCallback                       didStartProvisionalLoadForFrame;
64     WKPageDidReceiveServerRedirectForProvisionalLoadForFrameCallback    didReceiveServerRedirectForProvisionalLoadForFrame;
65     WKPageDidFailProvisionalLoadWithErrorForFrameCallback               didFailProvisionalLoadWithErrorForFrame;
66     WKPageDidCommitLoadForFrameCallback                                 didCommitLoadForFrame;
67     WKPageDidFinishLoadForFrameCallback                                 didFinishLoadForFrame;
68     WKPageDidFailLoadWithErrorForFrameCallback                          didFailLoadWithErrorForFrame;
69     WKPageDidReceiveTitleForFrameCallback                               didReceiveTitleForFrame;
70     WKPageDidFirstLayoutForFrame                                        didFirstLayoutForFrame;
71     WKPageDidFirstVisuallyNonEmptyLayoutForFrame                        didFirstVisuallyNonEmptyLayoutForFrame;
72
73     // FIXME: Move to progress client.
74     WKPageDidStartProgressCallback                                      didStartProgress;
75     WKPageDidChangeProgressCallback                                     didChangeProgress;
76     WKPageDidFinishProgressCallback                                     didFinishProgress;
77
78     // FIXME: These two methods should not be part of this client.
79     WKPageDidBecomeUnresponsiveCallback                                 didBecomeUnresponsive;
80     WKPageDidBecomeResponsiveCallback                                   didBecomeResponsive;
81 };
82 typedef struct WKPageLoaderClient WKPageLoaderClient;
83
84 // Policy Client.
85 typedef void (*WKPageDecidePolicyForNavigationActionCallback)(WKPageRef page, uint32_t navigationType, WKURLRef url, WKFrameRef frame, WKFramePolicyListenerRef listener, const void *clientInfo);
86 typedef void (*WKPageDecidePolicyForNewWindowActionCallback)(WKPageRef page, uint32_t navigationType, WKURLRef url, WKFrameRef frame, WKFramePolicyListenerRef listener, const void *clientInfo);
87 typedef void (*WKPageDecidePolicyForMIMETypeCallback)(WKPageRef page, WKStringRef MIMEType, WKURLRef url, WKFrameRef frame, WKFramePolicyListenerRef listener, const void *clientInfo);
88
89 struct WKPagePolicyClient {
90     int                                                                 version;
91     const void *                                                        clientInfo;
92     WKPageDecidePolicyForNavigationActionCallback                       decidePolicyForNavigationAction;
93     WKPageDecidePolicyForNewWindowActionCallback                        decidePolicyForNewWindowAction;
94     WKPageDecidePolicyForMIMETypeCallback                               decidePolicyForMIMEType;
95 };
96 typedef struct WKPagePolicyClient WKPagePolicyClient;
97
98 // UI Client
99 typedef WKPageRef (*WKPageCreateNewPageCallback)(WKPageRef page, const void *clientInfo);
100 typedef void (*WKPageShowPageCallback)(WKPageRef page, const void *clientInfo);
101 typedef void (*WKPageCloseCallback)(WKPageRef page, const void *clientInfo);
102 typedef void (*WKPageRunJavaScriptAlertCallback)(WKPageRef page, WKStringRef alertText, WKFrameRef frame, const void *clientInfo);
103
104 struct WKPageUIClient {
105     int                                                                 version;
106     const void *                                                        clientInfo;
107     WKPageCreateNewPageCallback                                         createNewPage;
108     WKPageShowPageCallback                                              showPage;
109     WKPageCloseCallback                                                 close;
110     WKPageRunJavaScriptAlertCallback                                    runJavaScriptAlert;
111 };
112 typedef struct WKPageUIClient WKPageUIClient;
113
114 // History Client
115 typedef void (*WKPageDidNavigateWithNavigationDataCallback)(WKPageRef page, WKNavigationDataRef navigationData, WKFrameRef frame, const void *clientInfo);
116 typedef void (*WKPageDidPerformClientRedirectCallback)(WKPageRef page, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef frame, const void *clientInfo);
117 typedef void (*WKPageDidPerformServerRedirectCallback)(WKPageRef page, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef frame, const void *clientInfo);
118 typedef void (*WKPageDidUpdateHistoryTitleCallback)(WKPageRef page, WKStringRef title, WKURLRef URL, WKFrameRef frame, const void *clientInfo);
119
120 struct WKPageHistoryClient {
121     int                                                                 version;
122     const void *                                                        clientInfo;
123     WKPageDidNavigateWithNavigationDataCallback                         didNavigateWithNavigationData;
124     WKPageDidPerformClientRedirectCallback                              didPerformClientRedirect;
125     WKPageDidPerformServerRedirectCallback                              didPerformServerRedirect;
126     WKPageDidUpdateHistoryTitleCallback                                 didUpdateHistoryTitle;
127 };
128 typedef struct WKPageHistoryClient WKPageHistoryClient;
129
130
131 WK_EXPORT WKPageNamespaceRef WKPageGetPageNamespace(WKPageRef page);
132
133 WK_EXPORT void WKPageLoadURL(WKPageRef page, WKURLRef url);
134 WK_EXPORT void WKPageStopLoading(WKPageRef page);
135 WK_EXPORT void WKPageReload(WKPageRef page);
136 WK_EXPORT void WKPageReloadFromOrigin(WKPageRef page);
137
138 WK_EXPORT bool WKPageTryClose(WKPageRef page);
139 WK_EXPORT void WKPageClose(WKPageRef page);
140 WK_EXPORT bool WKPageIsClosed(WKPageRef page);
141
142 WK_EXPORT void WKPageGoForward(WKPageRef page);
143 WK_EXPORT bool WKPageCanGoForward(WKPageRef page);
144 WK_EXPORT void WKPageGoBack(WKPageRef page);
145 WK_EXPORT bool WKPageCanGoBack(WKPageRef page);
146 WK_EXPORT WKBackForwardListRef WKPageGetBackForwardList(WKPageRef page);
147
148 WK_EXPORT WKStringRef WKPageGetTitle(WKPageRef page);
149
150 WK_EXPORT WKFrameRef WKPageGetMainFrame(WKPageRef page);
151 WK_EXPORT double WKPageGetEstimatedProgress(WKPageRef page);
152     
153 WK_EXPORT void WKPageTerminate(WKPageRef page);
154
155 WK_EXPORT void WKPageSetPageLoaderClient(WKPageRef page, WKPageLoaderClient * client);
156 WK_EXPORT void WKPageSetPagePolicyClient(WKPageRef page, WKPagePolicyClient * client);
157 WK_EXPORT void WKPageSetPageUIClient(WKPageRef page, WKPageUIClient * client);
158 WK_EXPORT void WKPageSetPageHistoryClient(WKPageRef page, WKPageHistoryClient * client);
159
160 typedef void (*WKPageRunJavaScriptFunction)(WKStringRef, void*);
161 typedef void (*WKPageRunJavaScriptDisposeFunction)(void*);
162 WK_EXPORT void WKPageRunJavaScriptInMainFrame(WKPageRef page, WKStringRef script, void *context, WKPageRunJavaScriptFunction function, WKPageRunJavaScriptDisposeFunction disposeFunction);
163 #ifdef __BLOCKS__
164 typedef void (^WKPageRunJavaScriptBlock)(WKStringRef);
165 WK_EXPORT void WKPageRunJavaScriptInMainFrame_b(WKPageRef page, WKStringRef script, WKPageRunJavaScriptBlock block);
166 #endif
167
168
169 WK_EXPORT WKPageRef WKPageRetain(WKPageRef page);
170 WK_EXPORT void WKPageRelease(WKPageRef page);
171
172 #ifdef __cplusplus
173 }
174 #endif
175
176 WK_DECLARE_RETAIN_RELEASE_OVERLOADS(WKPage)
177
178 #endif /* WKPage_h */