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