|
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 #include "WKPage.h" |
|
27 #include "WKPagePrivate.h" |
|
28 |
|
29 #include "WKAPICast.h" |
|
30 #include "WebBackForwardList.h" |
|
31 #include "WebPageProxy.h" |
|
32 |
|
33 #ifdef __BLOCKS__ |
|
34 #include <Block.h> |
|
35 #endif |
|
36 |
|
37 using namespace WebKit; |
|
38 |
|
39 WKPageNamespaceRef WKPageGetPageNamespace(WKPageRef pageRef) |
|
40 { |
|
41 return toRef(toWK(pageRef)->pageNamespace()); |
|
42 } |
|
43 |
|
44 void WKPageLoadURL(WKPageRef pageRef, WKURLRef URLRef) |
|
45 { |
|
46 toWK(pageRef)->loadURL(toWK(URLRef)); |
|
47 } |
|
48 |
|
49 void WKPageStopLoading(WKPageRef pageRef) |
|
50 { |
|
51 toWK(pageRef)->stopLoading(); |
|
52 } |
|
53 |
|
54 void WKPageReload(WKPageRef pageRef) |
|
55 { |
|
56 toWK(pageRef)->reload(false); |
|
57 } |
|
58 |
|
59 void WKPageReloadFromOrigin(WKPageRef pageRef) |
|
60 { |
|
61 toWK(pageRef)->reload(true); |
|
62 } |
|
63 |
|
64 bool WKPageTryClose(WKPageRef pageRef) |
|
65 { |
|
66 return toWK(pageRef)->tryClose(); |
|
67 } |
|
68 |
|
69 void WKPageClose(WKPageRef pageRef) |
|
70 { |
|
71 toWK(pageRef)->close(); |
|
72 } |
|
73 |
|
74 bool WKPageIsClosed(WKPageRef pageRef) |
|
75 { |
|
76 return toWK(pageRef)->isClosed(); |
|
77 } |
|
78 |
|
79 void WKPageGoForward(WKPageRef pageRef) |
|
80 { |
|
81 toWK(pageRef)->goForward(); |
|
82 } |
|
83 |
|
84 bool WKPageCanGoForward(WKPageRef pageRef) |
|
85 { |
|
86 return toWK(pageRef)->canGoForward(); |
|
87 } |
|
88 |
|
89 void WKPageGoBack(WKPageRef pageRef) |
|
90 { |
|
91 toWK(pageRef)->goBack(); |
|
92 } |
|
93 |
|
94 bool WKPageCanGoBack(WKPageRef pageRef) |
|
95 { |
|
96 return toWK(pageRef)->canGoBack(); |
|
97 } |
|
98 |
|
99 void WKPageGoToBackForwardListItem(WKPageRef pageRef, WKBackForwardListItemRef itemRef) |
|
100 { |
|
101 toWK(pageRef)->goToBackForwardItem(toWK(itemRef)); |
|
102 } |
|
103 |
|
104 WKBackForwardListRef WKPageGetBackForwardList(WKPageRef pageRef) |
|
105 { |
|
106 return toRef(toWK(pageRef)->backForwardList()); |
|
107 } |
|
108 |
|
109 WKStringRef WKPageGetTitle(WKPageRef pageRef) |
|
110 { |
|
111 return toRef(toWK(pageRef)->pageTitle().impl()); |
|
112 } |
|
113 |
|
114 WKFrameRef WKPageGetMainFrame(WKPageRef pageRef) |
|
115 { |
|
116 return toRef(toWK(pageRef)->mainFrame()); |
|
117 } |
|
118 |
|
119 double WKPageGetEstimatedProgress(WKPageRef pageRef) |
|
120 { |
|
121 return toWK(pageRef)->estimatedProgress(); |
|
122 } |
|
123 |
|
124 void WKPageTerminate(WKPageRef pageRef) |
|
125 { |
|
126 toWK(pageRef)->terminateProcess(); |
|
127 } |
|
128 |
|
129 void WKPageSetPageLoaderClient(WKPageRef pageRef, WKPageLoaderClient* wkClient) |
|
130 { |
|
131 if (wkClient && !wkClient->version) |
|
132 toWK(pageRef)->initializeLoaderClient(wkClient); |
|
133 } |
|
134 |
|
135 void WKPageSetPagePolicyClient(WKPageRef pageRef, WKPagePolicyClient * wkClient) |
|
136 { |
|
137 if (wkClient && !wkClient->version) |
|
138 toWK(pageRef)->initializePolicyClient(wkClient); |
|
139 } |
|
140 |
|
141 void WKPageSetPageUIClient(WKPageRef pageRef, WKPageUIClient * wkClient) |
|
142 { |
|
143 if (wkClient && !wkClient->version) |
|
144 toWK(pageRef)->initializeUIClient(wkClient); |
|
145 } |
|
146 |
|
147 void WKPageSetPageHistoryClient(WKPageRef pageRef, WKPageHistoryClient * wkClient) |
|
148 { |
|
149 if (wkClient && !wkClient->version) |
|
150 toWK(pageRef)->initializeHistoryClient(wkClient); |
|
151 } |
|
152 |
|
153 void WKPageRunJavaScriptInMainFrame(WKPageRef pageRef, WKStringRef scriptRef, void* context, WKPageRunJavaScriptFunction callback, WKPageRunJavaScriptDisposeFunction disposeFunction) |
|
154 { |
|
155 toWK(pageRef)->runJavaScriptInMainFrame(toWK(scriptRef), ScriptReturnValueCallback::create(context, callback, disposeFunction)); |
|
156 } |
|
157 |
|
158 #ifdef __BLOCKS__ |
|
159 static void callRunJavaScriptBlockAndRelease(WKStringRef resultValue, void* context) |
|
160 { |
|
161 WKPageRunJavaScriptBlock block = (WKPageRunJavaScriptBlock)context; |
|
162 block(resultValue); |
|
163 Block_release(block); |
|
164 } |
|
165 |
|
166 static void disposeRunJavaScriptBlock(void* context) |
|
167 { |
|
168 WKPageRunJavaScriptBlock block = (WKPageRunJavaScriptBlock)context; |
|
169 Block_release(block); |
|
170 } |
|
171 |
|
172 void WKPageRunJavaScriptInMainFrame_b(WKPageRef pageRef, WKStringRef scriptRef, WKPageRunJavaScriptBlock block) |
|
173 { |
|
174 WKPageRunJavaScriptInMainFrame(pageRef, scriptRef, Block_copy(block), callRunJavaScriptBlockAndRelease, disposeRunJavaScriptBlock); |
|
175 } |
|
176 #endif |
|
177 |
|
178 void WKPageRenderTreeExternalRepresentation(WKPageRef pageRef, void *context, WKPageRenderTreeExternalRepresentationFunction callback, WKPageRenderTreeExternalRepresentationDisposeFunction disposeFunction) |
|
179 { |
|
180 toWK(pageRef)->getRenderTreeExternalRepresentation(RenderTreeExternalRepresentationCallback::create(context, callback, disposeFunction)); |
|
181 } |
|
182 |
|
183 #ifdef __BLOCKS__ |
|
184 static void callRenderTreeExternalRepresentationBlockAndDispose(WKStringRef resultValue, void* context) |
|
185 { |
|
186 WKPageRenderTreeExternalRepresentationBlock block = (WKPageRenderTreeExternalRepresentationBlock)context; |
|
187 block(resultValue); |
|
188 Block_release(block); |
|
189 } |
|
190 |
|
191 static void disposeRenderTreeExternalRepresentationBlock(void* context) |
|
192 { |
|
193 WKPageRenderTreeExternalRepresentationBlock block = (WKPageRenderTreeExternalRepresentationBlock)context; |
|
194 Block_release(block); |
|
195 } |
|
196 |
|
197 void WKPageRenderTreeExternalRepresentation_b(WKPageRef pageRef, WKPageRenderTreeExternalRepresentationBlock block) |
|
198 { |
|
199 WKPageRenderTreeExternalRepresentation(pageRef, Block_copy(block), callRenderTreeExternalRepresentationBlockAndDispose, disposeRenderTreeExternalRepresentationBlock); |
|
200 } |
|
201 #endif |
|
202 |
|
203 WKPageRef WKPageRetain(WKPageRef pageRef) |
|
204 { |
|
205 toWK(pageRef)->ref(); |
|
206 return pageRef; |
|
207 } |
|
208 |
|
209 void WKPageRelease(WKPageRef pageRef) |
|
210 { |
|
211 toWK(pageRef)->deref(); |
|
212 } |