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