initial import
[vuplus_webkit] / Source / WebKit2 / WebProcess / InjectedBundle / API / c / WKBundlePage.cpp
1 /*
2  * Copyright (C) 2010, 2011 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 "config.h"
27 #include "WKBundlePage.h"
28 #include "WKBundlePagePrivate.h"
29
30 #include "InjectedBundleBackForwardList.h"
31 #include "InjectedBundleNodeHandle.h"
32 #include "WKAPICast.h"
33 #include "WKBundleAPICast.h"
34 #include "WebFullScreenManager.h"
35 #include "WebImage.h"
36 #include "WebPage.h"
37 #include "WebURL.h"
38 #include "WebURLRequest.h"
39
40 #include <WebCore/KURL.h>
41
42 using namespace WebKit;
43
44 WKTypeID WKBundlePageGetTypeID()
45 {
46     return toAPI(WebPage::APIType);
47 }
48
49 void WKBundlePageSetContextMenuClient(WKBundlePageRef pageRef, WKBundlePageContextMenuClient* wkClient)
50 {
51     toImpl(pageRef)->initializeInjectedBundleContextMenuClient(wkClient);
52 }
53
54 void WKBundlePageSetEditorClient(WKBundlePageRef pageRef, WKBundlePageEditorClient* wkClient)
55 {
56     toImpl(pageRef)->initializeInjectedBundleEditorClient(wkClient);
57 }
58
59 void WKBundlePageSetFormClient(WKBundlePageRef pageRef, WKBundlePageFormClient* wkClient)
60 {
61     toImpl(pageRef)->initializeInjectedBundleFormClient(wkClient);
62 }
63
64 void WKBundlePageSetPageLoaderClient(WKBundlePageRef pageRef, WKBundlePageLoaderClient* wkClient)
65 {
66     toImpl(pageRef)->initializeInjectedBundleLoaderClient(wkClient);
67 }
68
69 void WKBundlePageSetResourceLoadClient(WKBundlePageRef pageRef, WKBundlePageResourceLoadClient* wkClient)
70 {
71     toImpl(pageRef)->initializeInjectedBundleResourceLoadClient(wkClient);
72 }
73
74 void WKBundlePageSetPolicyClient(WKBundlePageRef pageRef, WKBundlePagePolicyClient* wkClient)
75 {
76     toImpl(pageRef)->initializeInjectedBundlePolicyClient(wkClient);
77 }
78
79 void WKBundlePageSetUIClient(WKBundlePageRef pageRef, WKBundlePageUIClient* wkClient)
80 {
81     toImpl(pageRef)->initializeInjectedBundleUIClient(wkClient);
82 }
83
84 void WKBundlePageSetFullScreenClient(WKBundlePageRef pageRef, WKBundlePageFullScreenClient* wkClient)
85 {
86 #if defined(ENABLE_FULLSCREEN_API) && ENABLE_FULLSCREEN_API
87     toImpl(pageRef)->initializeInjectedBundleFullScreenClient(wkClient);
88 #endif
89 }
90
91 void WKBundlePageWillEnterFullScreen(WKBundlePageRef pageRef)
92 {
93 #if defined(ENABLE_FULLSCREEN_API) && ENABLE_FULLSCREEN_API
94     toImpl(pageRef)->fullScreenManager()->willEnterFullScreen();
95 #endif
96 }
97
98 void WKBundlePageDidEnterFullScreen(WKBundlePageRef pageRef)
99 {
100 #if defined(ENABLE_FULLSCREEN_API) && ENABLE_FULLSCREEN_API
101     toImpl(pageRef)->fullScreenManager()->didEnterFullScreen();
102 #endif
103 }
104
105 void WKBundlePageWillExitFullScreen(WKBundlePageRef pageRef)
106 {
107 #if defined(ENABLE_FULLSCREEN_API) && ENABLE_FULLSCREEN_API
108     toImpl(pageRef)->fullScreenManager()->willExitFullScreen();
109 #endif
110 }
111
112 void WKBundlePageDidExitFullScreen(WKBundlePageRef pageRef)
113 {
114 #if defined(ENABLE_FULLSCREEN_API) && ENABLE_FULLSCREEN_API
115     toImpl(pageRef)->fullScreenManager()->didExitFullScreen();
116 #endif
117 }
118
119 WKBundlePageGroupRef WKBundlePageGetPageGroup(WKBundlePageRef pageRef)
120 {
121     return toAPI(toImpl(pageRef)->pageGroup());
122 }
123
124 WKBundleFrameRef WKBundlePageGetMainFrame(WKBundlePageRef pageRef)
125 {
126     return toAPI(toImpl(pageRef)->mainFrame());
127 }
128
129 void WKBundlePageStopLoading(WKBundlePageRef pageRef)
130 {
131     toImpl(pageRef)->stopLoading();
132 }
133
134 void WKBundlePageSetDefersLoading(WKBundlePageRef pageRef, bool defersLoading)
135 {
136     toImpl(pageRef)->setDefersLoading(defersLoading);
137 }
138
139 WKStringRef WKBundlePageCopyRenderTreeExternalRepresentation(WKBundlePageRef pageRef)
140 {
141     return toCopiedAPI(toImpl(pageRef)->renderTreeExternalRepresentation());
142 }
143
144 void WKBundlePageExecuteEditingCommand(WKBundlePageRef pageRef, WKStringRef name, WKStringRef argument)
145 {
146     toImpl(pageRef)->executeEditingCommand(toImpl(name)->string(), toImpl(argument)->string());
147 }
148
149 bool WKBundlePageIsEditingCommandEnabled(WKBundlePageRef pageRef, WKStringRef name)
150 {
151     return toImpl(pageRef)->isEditingCommandEnabled(toImpl(name)->string());
152 }
153
154 void WKBundlePageClearMainFrameName(WKBundlePageRef pageRef)
155 {
156     toImpl(pageRef)->clearMainFrameName();
157 }
158
159 void WKBundlePageClose(WKBundlePageRef pageRef)
160 {
161     toImpl(pageRef)->sendClose();
162 }
163
164 double WKBundlePageGetTextZoomFactor(WKBundlePageRef pageRef)
165 {
166     return toImpl(pageRef)->textZoomFactor();
167 }
168
169 void WKBundlePageSetTextZoomFactor(WKBundlePageRef pageRef, double zoomFactor)
170 {
171     toImpl(pageRef)->setTextZoomFactor(zoomFactor);
172 }
173
174 double WKBundlePageGetPageZoomFactor(WKBundlePageRef pageRef)
175 {
176     return toImpl(pageRef)->pageZoomFactor();
177 }
178
179 void WKBundlePageSetPageZoomFactor(WKBundlePageRef pageRef, double zoomFactor)
180 {
181     toImpl(pageRef)->setPageZoomFactor(zoomFactor);
182 }
183
184 void WKBundlePageSetScaleAtOrigin(WKBundlePageRef pageRef, double scale, WKPoint origin)
185 {
186     toImpl(pageRef)->scalePage(scale, toIntPoint(origin));
187 }
188
189 WKBundleBackForwardListRef WKBundlePageGetBackForwardList(WKBundlePageRef pageRef)
190 {
191     return toAPI(toImpl(pageRef)->backForwardList());
192 }
193
194 void WKBundlePageSetUnderlayPage(WKBundlePageRef pageRef, WKBundlePageRef pageUnderlayRef)
195 {
196     toImpl(pageRef)->setUnderlayPage(toImpl(pageUnderlayRef));
197 }
198
199 void WKBundlePageInstallPageOverlay(WKBundlePageRef pageRef, WKBundlePageOverlayRef pageOverlayRef)
200 {
201     toImpl(pageRef)->installPageOverlay(toImpl(pageOverlayRef));
202 }
203
204 void WKBundlePageUninstallPageOverlay(WKBundlePageRef pageRef, WKBundlePageOverlayRef pageOverlayRef)
205 {
206     toImpl(pageRef)->uninstallPageOverlay(toImpl(pageOverlayRef), false);
207 }
208
209 bool WKBundlePageHasLocalDataForURL(WKBundlePageRef pageRef, WKURLRef urlRef)
210 {
211     return toImpl(pageRef)->hasLocalDataForURL(WebCore::KURL(WebCore::KURL(), toImpl(urlRef)->string()));
212 }
213
214 bool WKBundlePageCanHandleRequest(WKURLRequestRef requestRef)
215 {
216     return WebPage::canHandleRequest(toImpl(requestRef)->resourceRequest());
217 }
218
219 bool WKBundlePageFindString(WKBundlePageRef pageRef, WKStringRef target, WKFindOptions findOptions)
220 {
221     return toImpl(pageRef)->findStringFromInjectedBundle(toImpl(target)->string(), toFindOptions(findOptions));
222 }
223
224 WKImageRef WKBundlePageCreateSnapshotInViewCoordinates(WKBundlePageRef pageRef, WKRect rect, WKImageOptions options)
225 {
226     RefPtr<WebImage> webImage = toImpl(pageRef)->snapshotInViewCoordinates(toIntRect(rect), toImageOptions(options));
227     return toAPI(webImage.release().leakRef());
228 }
229
230 WKImageRef WKBundlePageCreateSnapshotInDocumentCoordinates(WKBundlePageRef pageRef, WKRect rect, WKImageOptions options)
231 {
232     RefPtr<WebImage> webImage = toImpl(pageRef)->snapshotInDocumentCoordinates(toIntRect(rect), toImageOptions(options));
233     return toAPI(webImage.release().leakRef());
234 }
235
236 WKImageRef WKBundlePageCreateScaledSnapshotInDocumentCoordinates(WKBundlePageRef pageRef, WKRect rect, double scaleFactor, WKImageOptions options)
237 {
238     RefPtr<WebImage> webImage = toImpl(pageRef)->scaledSnapshotInDocumentCoordinates(toIntRect(rect), scaleFactor, toImageOptions(options));
239     return toAPI(webImage.release().leakRef());
240 }
241
242 #if defined(ENABLE_INSPECTOR) && ENABLE_INSPECTOR
243 WKBundleInspectorRef WKBundlePageGetInspector(WKBundlePageRef pageRef)
244 {
245     return toAPI(toImpl(pageRef)->inspector());
246 }
247 #endif
248
249 void WKBundlePageForceRepaint(WKBundlePageRef page)
250 {
251     toImpl(page)->forceRepaintWithoutCallback();
252 }
253
254 void WKBundlePageSimulateMouseDown(WKBundlePageRef page, int button, WKPoint position, int clickCount, WKEventModifiers modifiers, double time)
255 {
256     toImpl(page)->simulateMouseDown(button, toIntPoint(position), clickCount, modifiers, time);
257 }
258
259 void WKBundlePageSimulateMouseUp(WKBundlePageRef page, int button, WKPoint position, int clickCount, WKEventModifiers modifiers, double time)
260 {
261     toImpl(page)->simulateMouseUp(button, toIntPoint(position), clickCount, modifiers, time);
262 }
263
264 void WKBundlePageSimulateMouseMotion(WKBundlePageRef page, WKPoint position, double time)
265 {
266     toImpl(page)->simulateMouseMotion(toIntPoint(position), time);
267 }
268
269 uint64_t WKBundlePageGetRenderTreeSize(WKBundlePageRef pageRef)
270 {
271     return toImpl(pageRef)->renderTreeSize();
272 }