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 "config.h" 27#include "WKPage.h" 28#include "WKPagePrivate.h" 29 30#include "PrintInfo.h" 31#include "WKAPICast.h" 32#include "WKPluginInformation.h" 33#include "WebBackForwardList.h" 34#include "WebData.h" 35#include "WebPageProxy.h" 36#include "WebProcessProxy.h" 37#include <WebCore/Page.h> 38 39#ifdef __BLOCKS__ 40#include <Block.h> 41#endif 42 43#if ENABLE(CONTEXT_MENUS) 44#include "WebContextMenuItem.h" 45#endif 46 47using namespace WebCore; 48using namespace WebKit; 49 50WKTypeID WKPageGetTypeID() 51{ 52 return toAPI(WebPageProxy::APIType); 53} 54 55WKContextRef WKPageGetContext(WKPageRef pageRef) 56{ 57 return toAPI(toImpl(pageRef)->process()->context()); 58} 59 60WKPageGroupRef WKPageGetPageGroup(WKPageRef pageRef) 61{ 62 return toAPI(toImpl(pageRef)->pageGroup()); 63} 64 65void WKPageLoadURL(WKPageRef pageRef, WKURLRef URLRef) 66{ 67 toImpl(pageRef)->loadURL(toWTFString(URLRef)); 68} 69 70void WKPageLoadURLWithUserData(WKPageRef pageRef, WKURLRef URLRef, WKTypeRef userDataRef) 71{ 72 toImpl(pageRef)->loadURL(toWTFString(URLRef), toImpl(userDataRef)); 73} 74 75void WKPageLoadURLRequest(WKPageRef pageRef, WKURLRequestRef urlRequestRef) 76{ 77 toImpl(pageRef)->loadURLRequest(toImpl(urlRequestRef)); 78} 79 80void WKPageLoadURLRequestWithUserData(WKPageRef pageRef, WKURLRequestRef urlRequestRef, WKTypeRef userDataRef) 81{ 82 toImpl(pageRef)->loadURLRequest(toImpl(urlRequestRef), toImpl(userDataRef)); 83} 84 85void WKPageLoadFile(WKPageRef pageRef, WKURLRef fileURL, WKURLRef resourceDirectoryURL) 86{ 87 toImpl(pageRef)->loadFile(toWTFString(fileURL), toWTFString(resourceDirectoryURL)); 88} 89 90void WKPageLoadFileWithUserData(WKPageRef pageRef, WKURLRef fileURL, WKURLRef resourceDirectoryURL, WKTypeRef userDataRef) 91{ 92 toImpl(pageRef)->loadFile(toWTFString(fileURL), toWTFString(resourceDirectoryURL), toImpl(userDataRef)); 93} 94 95void WKPageLoadData(WKPageRef pageRef, WKDataRef dataRef, WKStringRef MIMETypeRef, WKStringRef encodingRef, WKURLRef baseURLRef) 96{ 97 toImpl(pageRef)->loadData(toImpl(dataRef), toWTFString(MIMETypeRef), toWTFString(encodingRef), toWTFString(baseURLRef)); 98} 99 100void WKPageLoadDataWithUserData(WKPageRef pageRef, WKDataRef dataRef, WKStringRef MIMETypeRef, WKStringRef encodingRef, WKURLRef baseURLRef, WKTypeRef userDataRef) 101{ 102 toImpl(pageRef)->loadData(toImpl(dataRef), toWTFString(MIMETypeRef), toWTFString(encodingRef), toWTFString(baseURLRef), toImpl(userDataRef)); 103} 104 105void WKPageLoadHTMLString(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef) 106{ 107 toImpl(pageRef)->loadHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef)); 108} 109 110void WKPageLoadHTMLStringWithUserData(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef, WKTypeRef userDataRef) 111{ 112 toImpl(pageRef)->loadHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef), toImpl(userDataRef)); 113} 114 115void WKPageLoadAlternateHTMLString(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef, WKURLRef unreachableURLRef) 116{ 117 toImpl(pageRef)->loadAlternateHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef), toWTFString(unreachableURLRef)); 118} 119 120void WKPageLoadAlternateHTMLStringWithUserData(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef, WKURLRef unreachableURLRef, WKTypeRef userDataRef) 121{ 122 toImpl(pageRef)->loadAlternateHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef), toWTFString(unreachableURLRef), toImpl(userDataRef)); 123} 124 125void WKPageLoadPlainTextString(WKPageRef pageRef, WKStringRef plainTextStringRef) 126{ 127 toImpl(pageRef)->loadPlainTextString(toWTFString(plainTextStringRef)); 128} 129 130void WKPageLoadPlainTextStringWithUserData(WKPageRef pageRef, WKStringRef plainTextStringRef, WKTypeRef userDataRef) 131{ 132 toImpl(pageRef)->loadPlainTextString(toWTFString(plainTextStringRef), toImpl(userDataRef)); 133} 134 135void WKPageLoadWebArchiveData(WKPageRef pageRef, WKDataRef webArchiveDataRef) 136{ 137 toImpl(pageRef)->loadWebArchiveData(toImpl(webArchiveDataRef)); 138} 139 140void WKPageLoadWebArchiveDataWithUserData(WKPageRef pageRef, WKDataRef webArchiveDataRef, WKTypeRef userDataRef) 141{ 142 toImpl(pageRef)->loadWebArchiveData(toImpl(webArchiveDataRef), toImpl(userDataRef)); 143} 144 145void WKPageStopLoading(WKPageRef pageRef) 146{ 147 toImpl(pageRef)->stopLoading(); 148} 149 150void WKPageReload(WKPageRef pageRef) 151{ 152 toImpl(pageRef)->reload(false); 153} 154 155void WKPageReloadFromOrigin(WKPageRef pageRef) 156{ 157 toImpl(pageRef)->reload(true); 158} 159 160bool WKPageTryClose(WKPageRef pageRef) 161{ 162 return toImpl(pageRef)->tryClose(); 163} 164 165void WKPageClose(WKPageRef pageRef) 166{ 167 toImpl(pageRef)->close(); 168} 169 170bool WKPageIsClosed(WKPageRef pageRef) 171{ 172 return toImpl(pageRef)->isClosed(); 173} 174 175void WKPageGoForward(WKPageRef pageRef) 176{ 177 toImpl(pageRef)->goForward(); 178} 179 180bool WKPageCanGoForward(WKPageRef pageRef) 181{ 182 return toImpl(pageRef)->canGoForward(); 183} 184 185void WKPageGoBack(WKPageRef pageRef) 186{ 187 toImpl(pageRef)->goBack(); 188} 189 190bool WKPageCanGoBack(WKPageRef pageRef) 191{ 192 return toImpl(pageRef)->canGoBack(); 193} 194 195void WKPageGoToBackForwardListItem(WKPageRef pageRef, WKBackForwardListItemRef itemRef) 196{ 197 toImpl(pageRef)->goToBackForwardItem(toImpl(itemRef)); 198} 199 200void WKPageTryRestoreScrollPosition(WKPageRef pageRef) 201{ 202 toImpl(pageRef)->tryRestoreScrollPosition(); 203} 204 205WKBackForwardListRef WKPageGetBackForwardList(WKPageRef pageRef) 206{ 207 return toAPI(toImpl(pageRef)->backForwardList()); 208} 209 210bool WKPageWillHandleHorizontalScrollEvents(WKPageRef pageRef) 211{ 212 return toImpl(pageRef)->willHandleHorizontalScrollEvents(); 213} 214 215WKStringRef WKPageCopyTitle(WKPageRef pageRef) 216{ 217 return toCopiedAPI(toImpl(pageRef)->pageTitle()); 218} 219 220WKFrameRef WKPageGetMainFrame(WKPageRef pageRef) 221{ 222 return toAPI(toImpl(pageRef)->mainFrame()); 223} 224 225WKFrameRef WKPageGetFocusedFrame(WKPageRef pageRef) 226{ 227 return toAPI(toImpl(pageRef)->focusedFrame()); 228} 229 230WKFrameRef WKPageGetFrameSetLargestFrame(WKPageRef pageRef) 231{ 232 return toAPI(toImpl(pageRef)->frameSetLargestFrame()); 233} 234 235uint64_t WKPageGetRenderTreeSize(WKPageRef page) 236{ 237 return toImpl(page)->renderTreeSize(); 238} 239 240WKInspectorRef WKPageGetInspector(WKPageRef pageRef) 241{ 242#if defined(ENABLE_INSPECTOR) && ENABLE_INSPECTOR 243 return toAPI(toImpl(pageRef)->inspector()); 244#else 245 UNUSED_PARAM(pageRef); 246 return 0; 247#endif 248} 249 250WKVibrationRef WKPageGetVibration(WKPageRef page) 251{ 252#if ENABLE(VIBRATION) 253 return toAPI(toImpl(page)->vibration()); 254#else 255 UNUSED_PARAM(page); 256 return 0; 257#endif 258} 259 260double WKPageGetEstimatedProgress(WKPageRef pageRef) 261{ 262 return toImpl(pageRef)->estimatedProgress(); 263} 264 265void WKPageSetMemoryCacheClientCallsEnabled(WKPageRef pageRef, bool memoryCacheClientCallsEnabled) 266{ 267 toImpl(pageRef)->setMemoryCacheClientCallsEnabled(memoryCacheClientCallsEnabled); 268} 269 270WKStringRef WKPageCopyUserAgent(WKPageRef pageRef) 271{ 272 return toCopiedAPI(toImpl(pageRef)->userAgent()); 273} 274 275WKStringRef WKPageCopyApplicationNameForUserAgent(WKPageRef pageRef) 276{ 277 return toCopiedAPI(toImpl(pageRef)->applicationNameForUserAgent()); 278} 279 280void WKPageSetApplicationNameForUserAgent(WKPageRef pageRef, WKStringRef applicationNameRef) 281{ 282 toImpl(pageRef)->setApplicationNameForUserAgent(toWTFString(applicationNameRef)); 283} 284 285WKStringRef WKPageCopyCustomUserAgent(WKPageRef pageRef) 286{ 287 return toCopiedAPI(toImpl(pageRef)->customUserAgent()); 288} 289 290void WKPageSetCustomUserAgent(WKPageRef pageRef, WKStringRef userAgentRef) 291{ 292 toImpl(pageRef)->setCustomUserAgent(toWTFString(userAgentRef)); 293} 294 295bool WKPageSupportsTextEncoding(WKPageRef pageRef) 296{ 297 return toImpl(pageRef)->supportsTextEncoding(); 298} 299 300WKStringRef WKPageCopyCustomTextEncodingName(WKPageRef pageRef) 301{ 302 return toCopiedAPI(toImpl(pageRef)->customTextEncodingName()); 303} 304 305void WKPageSetCustomTextEncodingName(WKPageRef pageRef, WKStringRef encodingNameRef) 306{ 307 toImpl(pageRef)->setCustomTextEncodingName(toWTFString(encodingNameRef)); 308} 309 310void WKPageTerminate(WKPageRef pageRef) 311{ 312 toImpl(pageRef)->terminateProcess(); 313} 314 315WKStringRef WKPageGetSessionHistoryURLValueType() 316{ 317 static WebString* sessionHistoryURLValueType = WebString::create("SessionHistoryURL").leakRef(); 318 return toAPI(sessionHistoryURLValueType); 319} 320 321WKStringRef WKPageGetSessionBackForwardListItemValueType() 322{ 323 static WebString* sessionBackForwardListValueType = WebString::create("SessionBackForwardListItem").leakRef(); 324 return toAPI(sessionBackForwardListValueType); 325} 326 327WKDataRef WKPageCopySessionState(WKPageRef pageRef, void *context, WKPageSessionStateFilterCallback filter) 328{ 329 return toAPI(toImpl(pageRef)->sessionStateData(filter, context).leakRef()); 330} 331 332void WKPageRestoreFromSessionState(WKPageRef pageRef, WKDataRef sessionStateData) 333{ 334 toImpl(pageRef)->restoreFromSessionStateData(toImpl(sessionStateData)); 335} 336 337double WKPageGetTextZoomFactor(WKPageRef pageRef) 338{ 339 return toImpl(pageRef)->textZoomFactor(); 340} 341 342double WKPageGetBackingScaleFactor(WKPageRef pageRef) 343{ 344 return toImpl(pageRef)->deviceScaleFactor(); 345} 346 347void WKPageSetCustomBackingScaleFactor(WKPageRef pageRef, double customScaleFactor) 348{ 349 toImpl(pageRef)->setCustomDeviceScaleFactor(customScaleFactor); 350} 351 352bool WKPageSupportsTextZoom(WKPageRef pageRef) 353{ 354 return toImpl(pageRef)->supportsTextZoom(); 355} 356 357void WKPageSetTextZoomFactor(WKPageRef pageRef, double zoomFactor) 358{ 359 toImpl(pageRef)->setTextZoomFactor(zoomFactor); 360} 361 362double WKPageGetPageZoomFactor(WKPageRef pageRef) 363{ 364 return toImpl(pageRef)->pageZoomFactor(); 365} 366 367void WKPageSetPageZoomFactor(WKPageRef pageRef, double zoomFactor) 368{ 369 toImpl(pageRef)->setPageZoomFactor(zoomFactor); 370} 371 372void WKPageSetPageAndTextZoomFactors(WKPageRef pageRef, double pageZoomFactor, double textZoomFactor) 373{ 374 toImpl(pageRef)->setPageAndTextZoomFactors(pageZoomFactor, textZoomFactor); 375} 376 377void WKPageSetScaleFactor(WKPageRef pageRef, double scale, WKPoint origin) 378{ 379 toImpl(pageRef)->scalePage(scale, toIntPoint(origin)); 380} 381 382double WKPageGetScaleFactor(WKPageRef pageRef) 383{ 384 return toImpl(pageRef)->pageScaleFactor(); 385} 386 387void WKPageSetUseFixedLayout(WKPageRef pageRef, bool fixed) 388{ 389 toImpl(pageRef)->setUseFixedLayout(fixed); 390} 391 392void WKPageSetFixedLayoutSize(WKPageRef pageRef, WKSize size) 393{ 394 toImpl(pageRef)->setFixedLayoutSize(toIntSize(size)); 395} 396 397bool WKPageUseFixedLayout(WKPageRef pageRef) 398{ 399 return toImpl(pageRef)->useFixedLayout(); 400} 401 402WKSize WKPageFixedLayoutSize(WKPageRef pageRef) 403{ 404 return toAPI(toImpl(pageRef)->fixedLayoutSize()); 405} 406 407void WKPageListenForLayoutMilestones(WKPageRef pageRef, WKLayoutMilestones milestones) 408{ 409 toImpl(pageRef)->listenForLayoutMilestones(toLayoutMilestones(milestones)); 410} 411 412void WKPageSetVisibilityState(WKPageRef pageRef, WKPageVisibilityState state, bool isInitialState) 413{ 414 toImpl(pageRef)->setVisibilityState(toPageVisibilityState(state), isInitialState); 415} 416 417bool WKPageHasHorizontalScrollbar(WKPageRef pageRef) 418{ 419 return toImpl(pageRef)->hasHorizontalScrollbar(); 420} 421 422bool WKPageHasVerticalScrollbar(WKPageRef pageRef) 423{ 424 return toImpl(pageRef)->hasVerticalScrollbar(); 425} 426 427void WKPageSetSuppressScrollbarAnimations(WKPageRef pageRef, bool suppressAnimations) 428{ 429 toImpl(pageRef)->setSuppressScrollbarAnimations(suppressAnimations); 430} 431 432bool WKPageAreScrollbarAnimationsSuppressed(WKPageRef pageRef) 433{ 434 return toImpl(pageRef)->areScrollbarAnimationsSuppressed(); 435} 436 437bool WKPageIsPinnedToLeftSide(WKPageRef pageRef) 438{ 439 return toImpl(pageRef)->isPinnedToLeftSide(); 440} 441 442bool WKPageIsPinnedToRightSide(WKPageRef pageRef) 443{ 444 return toImpl(pageRef)->isPinnedToRightSide(); 445} 446 447bool WKPageIsPinnedToTopSide(WKPageRef pageRef) 448{ 449 return toImpl(pageRef)->isPinnedToTopSide(); 450} 451 452bool WKPageIsPinnedToBottomSide(WKPageRef pageRef) 453{ 454 return toImpl(pageRef)->isPinnedToBottomSide(); 455} 456 457 458bool WKPageRubberBandsAtBottom(WKPageRef pageRef) 459{ 460 return toImpl(pageRef)->rubberBandsAtBottom(); 461} 462 463void WKPageSetRubberBandsAtBottom(WKPageRef pageRef, bool rubberBandsAtBottom) 464{ 465 toImpl(pageRef)->setRubberBandsAtBottom(rubberBandsAtBottom); 466} 467 468bool WKPageRubberBandsAtTop(WKPageRef pageRef) 469{ 470 return toImpl(pageRef)->rubberBandsAtTop(); 471} 472 473void WKPageSetRubberBandsAtTop(WKPageRef pageRef, bool rubberBandsAtTop) 474{ 475 toImpl(pageRef)->setRubberBandsAtTop(rubberBandsAtTop); 476} 477 478void WKPageSetPaginationMode(WKPageRef pageRef, WKPaginationMode paginationMode) 479{ 480 Pagination::Mode mode; 481 switch (paginationMode) { 482 case kWKPaginationModeUnpaginated: 483 mode = Pagination::Unpaginated; 484 break; 485 case kWKPaginationModeLeftToRight: 486 mode = Pagination::LeftToRightPaginated; 487 break; 488 case kWKPaginationModeRightToLeft: 489 mode = Pagination::RightToLeftPaginated; 490 break; 491 case kWKPaginationModeTopToBottom: 492 mode = Pagination::TopToBottomPaginated; 493 break; 494 case kWKPaginationModeBottomToTop: 495 mode = Pagination::BottomToTopPaginated; 496 break; 497 default: 498 return; 499 } 500 toImpl(pageRef)->setPaginationMode(mode); 501} 502 503WKPaginationMode WKPageGetPaginationMode(WKPageRef pageRef) 504{ 505 switch (toImpl(pageRef)->paginationMode()) { 506 case Pagination::Unpaginated: 507 return kWKPaginationModeUnpaginated; 508 case Pagination::LeftToRightPaginated: 509 return kWKPaginationModeLeftToRight; 510 case Pagination::RightToLeftPaginated: 511 return kWKPaginationModeRightToLeft; 512 case Pagination::TopToBottomPaginated: 513 return kWKPaginationModeTopToBottom; 514 case Pagination::BottomToTopPaginated: 515 return kWKPaginationModeBottomToTop; 516 } 517 518 ASSERT_NOT_REACHED(); 519 return kWKPaginationModeUnpaginated; 520} 521 522void WKPageSetPaginationBehavesLikeColumns(WKPageRef pageRef, bool behavesLikeColumns) 523{ 524 toImpl(pageRef)->setPaginationBehavesLikeColumns(behavesLikeColumns); 525} 526 527bool WKPageGetPaginationBehavesLikeColumns(WKPageRef pageRef) 528{ 529 return toImpl(pageRef)->paginationBehavesLikeColumns(); 530} 531 532void WKPageSetPageLength(WKPageRef pageRef, double pageLength) 533{ 534 toImpl(pageRef)->setPageLength(pageLength); 535} 536 537double WKPageGetPageLength(WKPageRef pageRef) 538{ 539 return toImpl(pageRef)->pageLength(); 540} 541 542void WKPageSetGapBetweenPages(WKPageRef pageRef, double gap) 543{ 544 toImpl(pageRef)->setGapBetweenPages(gap); 545} 546 547double WKPageGetGapBetweenPages(WKPageRef pageRef) 548{ 549 return toImpl(pageRef)->gapBetweenPages(); 550} 551 552unsigned WKPageGetPageCount(WKPageRef pageRef) 553{ 554 return toImpl(pageRef)->pageCount(); 555} 556 557bool WKPageCanDelete(WKPageRef pageRef) 558{ 559 return toImpl(pageRef)->canDelete(); 560} 561 562bool WKPageHasSelectedRange(WKPageRef pageRef) 563{ 564 return toImpl(pageRef)->hasSelectedRange(); 565} 566 567bool WKPageIsContentEditable(WKPageRef pageRef) 568{ 569 return toImpl(pageRef)->isContentEditable(); 570} 571 572void WKPageSetMaintainsInactiveSelection(WKPageRef pageRef, bool newValue) 573{ 574 return toImpl(pageRef)->setMaintainsInactiveSelection(newValue); 575} 576 577void WKPageCenterSelectionInVisibleArea(WKPageRef pageRef) 578{ 579 return toImpl(pageRef)->centerSelectionInVisibleArea(); 580} 581 582void WKPageFindStringMatches(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount) 583{ 584 toImpl(pageRef)->findStringMatches(toImpl(string)->string(), toFindOptions(options), maxMatchCount); 585} 586 587void WKPageGetImageForFindMatch(WKPageRef pageRef, int32_t matchIndex) 588{ 589 toImpl(pageRef)->getImageForFindMatch(matchIndex); 590} 591 592void WKPageSelectFindMatch(WKPageRef pageRef, int32_t matchIndex) 593{ 594 toImpl(pageRef)->selectFindMatch(matchIndex); 595} 596 597void WKPageFindString(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount) 598{ 599 toImpl(pageRef)->findString(toImpl(string)->string(), toFindOptions(options), maxMatchCount); 600} 601 602void WKPageHideFindUI(WKPageRef pageRef) 603{ 604 toImpl(pageRef)->hideFindUI(); 605} 606 607void WKPageCountStringMatches(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount) 608{ 609 toImpl(pageRef)->countStringMatches(toImpl(string)->string(), toFindOptions(options), maxMatchCount); 610} 611 612void WKPageSetPageContextMenuClient(WKPageRef pageRef, const WKPageContextMenuClient* wkClient) 613{ 614#if ENABLE(CONTEXT_MENUS) 615 toImpl(pageRef)->initializeContextMenuClient(wkClient); 616#endif 617} 618 619void WKPageSetPageFindClient(WKPageRef pageRef, const WKPageFindClient* wkClient) 620{ 621 toImpl(pageRef)->initializeFindClient(wkClient); 622} 623 624void WKPageSetPageFindMatchesClient(WKPageRef pageRef, const WKPageFindMatchesClient* wkClient) 625{ 626 toImpl(pageRef)->initializeFindMatchesClient(wkClient); 627} 628 629void WKPageSetPageFormClient(WKPageRef pageRef, const WKPageFormClient* wkClient) 630{ 631 toImpl(pageRef)->initializeFormClient(wkClient); 632} 633 634void WKPageSetPageLoaderClient(WKPageRef pageRef, const WKPageLoaderClient* wkClient) 635{ 636 toImpl(pageRef)->initializeLoaderClient(wkClient); 637} 638 639void WKPageSetPagePolicyClient(WKPageRef pageRef, const WKPagePolicyClient* wkClient) 640{ 641 toImpl(pageRef)->initializePolicyClient(wkClient); 642} 643 644void WKPageSetPageUIClient(WKPageRef pageRef, const WKPageUIClient* wkClient) 645{ 646 toImpl(pageRef)->initializeUIClient(wkClient); 647} 648 649void WKPageRunJavaScriptInMainFrame(WKPageRef pageRef, WKStringRef scriptRef, void* context, WKPageRunJavaScriptFunction callback) 650{ 651 toImpl(pageRef)->runJavaScriptInMainFrame(toImpl(scriptRef)->string(), ScriptValueCallback::create(context, callback)); 652} 653 654#ifdef __BLOCKS__ 655static void callRunJavaScriptBlockAndRelease(WKSerializedScriptValueRef resultValue, WKErrorRef error, void* context) 656{ 657 WKPageRunJavaScriptBlock block = (WKPageRunJavaScriptBlock)context; 658 block(resultValue, error); 659 Block_release(block); 660} 661 662void WKPageRunJavaScriptInMainFrame_b(WKPageRef pageRef, WKStringRef scriptRef, WKPageRunJavaScriptBlock block) 663{ 664 WKPageRunJavaScriptInMainFrame(pageRef, scriptRef, Block_copy(block), callRunJavaScriptBlockAndRelease); 665} 666#endif 667 668void WKPageRenderTreeExternalRepresentation(WKPageRef pageRef, void* context, WKPageRenderTreeExternalRepresentationFunction callback) 669{ 670 toImpl(pageRef)->getRenderTreeExternalRepresentation(StringCallback::create(context, callback)); 671} 672 673#ifdef __BLOCKS__ 674static void callRenderTreeExternalRepresentationBlockAndDispose(WKStringRef resultValue, WKErrorRef error, void* context) 675{ 676 WKPageRenderTreeExternalRepresentationBlock block = (WKPageRenderTreeExternalRepresentationBlock)context; 677 block(resultValue, error); 678 Block_release(block); 679} 680 681void WKPageRenderTreeExternalRepresentation_b(WKPageRef pageRef, WKPageRenderTreeExternalRepresentationBlock block) 682{ 683 WKPageRenderTreeExternalRepresentation(pageRef, Block_copy(block), callRenderTreeExternalRepresentationBlockAndDispose); 684} 685#endif 686 687void WKPageGetSourceForFrame(WKPageRef pageRef, WKFrameRef frameRef, void* context, WKPageGetSourceForFrameFunction callback) 688{ 689 toImpl(pageRef)->getSourceForFrame(toImpl(frameRef), StringCallback::create(context, callback)); 690} 691 692#ifdef __BLOCKS__ 693static void callGetSourceForFrameBlockBlockAndDispose(WKStringRef resultValue, WKErrorRef error, void* context) 694{ 695 WKPageGetSourceForFrameBlock block = (WKPageGetSourceForFrameBlock)context; 696 block(resultValue, error); 697 Block_release(block); 698} 699 700void WKPageGetSourceForFrame_b(WKPageRef pageRef, WKFrameRef frameRef, WKPageGetSourceForFrameBlock block) 701{ 702 WKPageGetSourceForFrame(pageRef, frameRef, Block_copy(block), callGetSourceForFrameBlockBlockAndDispose); 703} 704#endif 705 706void WKPageGetContentsAsString(WKPageRef pageRef, void* context, WKPageGetContentsAsStringFunction callback) 707{ 708 toImpl(pageRef)->getContentsAsString(StringCallback::create(context, callback)); 709} 710 711#ifdef __BLOCKS__ 712static void callContentsAsStringBlockBlockAndDispose(WKStringRef resultValue, WKErrorRef error, void* context) 713{ 714 WKPageGetContentsAsStringBlock block = (WKPageGetContentsAsStringBlock)context; 715 block(resultValue, error); 716 Block_release(block); 717} 718 719void WKPageGetContentsAsString_b(WKPageRef pageRef, WKPageGetSourceForFrameBlock block) 720{ 721 WKPageGetContentsAsString(pageRef, Block_copy(block), callContentsAsStringBlockBlockAndDispose); 722} 723#endif 724 725void WKPageGetSelectionAsWebArchiveData(WKPageRef pageRef, void* context, WKPageGetSelectionAsWebArchiveDataFunction callback) 726{ 727 toImpl(pageRef)->getSelectionAsWebArchiveData(DataCallback::create(context, callback)); 728} 729 730void WKPageGetContentsAsMHTMLData(WKPageRef pageRef, bool useBinaryEncoding, void* context, WKPageGetContentsAsMHTMLDataFunction callback) 731{ 732#if ENABLE(MHTML) 733 toImpl(pageRef)->getContentsAsMHTMLData(DataCallback::create(context, callback), useBinaryEncoding); 734#else 735 UNUSED_PARAM(pageRef); 736 UNUSED_PARAM(useBinaryEncoding); 737 UNUSED_PARAM(context); 738 UNUSED_PARAM(callback); 739#endif 740} 741 742void WKPageForceRepaint(WKPageRef pageRef, void* context, WKPageForceRepaintFunction callback) 743{ 744 toImpl(pageRef)->forceRepaint(VoidCallback::create(context, callback)); 745} 746 747WK_EXPORT WKURLRef WKPageCopyPendingAPIRequestURL(WKPageRef pageRef) 748{ 749 if (toImpl(pageRef)->pendingAPIRequestURL().isNull()) 750 return 0; 751 return toCopiedURLAPI(toImpl(pageRef)->pendingAPIRequestURL()); 752} 753 754WKURLRef WKPageCopyActiveURL(WKPageRef pageRef) 755{ 756 return toCopiedURLAPI(toImpl(pageRef)->activeURL()); 757} 758 759WKURLRef WKPageCopyProvisionalURL(WKPageRef pageRef) 760{ 761 return toCopiedURLAPI(toImpl(pageRef)->provisionalURL()); 762} 763 764WKURLRef WKPageCopyCommittedURL(WKPageRef pageRef) 765{ 766 return toCopiedURLAPI(toImpl(pageRef)->committedURL()); 767} 768 769void WKPageSetDebugPaintFlags(WKPageDebugPaintFlags flags) 770{ 771 WebPageProxy::setDebugPaintFlags(flags); 772} 773 774WKPageDebugPaintFlags WKPageGetDebugPaintFlags() 775{ 776 return WebPageProxy::debugPaintFlags(); 777} 778 779WKStringRef WKPageCopyStandardUserAgentWithApplicationName(WKStringRef applicationName) 780{ 781 return toCopiedAPI(WebPageProxy::standardUserAgent(toImpl(applicationName)->string())); 782} 783 784void WKPageValidateCommand(WKPageRef pageRef, WKStringRef command, void* context, WKPageValidateCommandCallback callback) 785{ 786 toImpl(pageRef)->validateCommand(toImpl(command)->string(), ValidateCommandCallback::create(context, callback)); 787} 788 789void WKPageExecuteCommand(WKPageRef pageRef, WKStringRef command) 790{ 791 toImpl(pageRef)->executeEditCommand(toImpl(command)->string()); 792} 793 794#if PLATFORM(MAC) 795struct ComputedPagesContext { 796 ComputedPagesContext(WKPageComputePagesForPrintingFunction callback, void* context) 797 : callback(callback) 798 , context(context) 799 { 800 } 801 WKPageComputePagesForPrintingFunction callback; 802 void* context; 803}; 804 805static void computedPagesCallback(const Vector<WebCore::IntRect>& rects, double scaleFactor, WKErrorRef error, void* untypedContext) 806{ 807 OwnPtr<ComputedPagesContext> context = adoptPtr(static_cast<ComputedPagesContext*>(untypedContext)); 808 Vector<WKRect> wkRects(rects.size()); 809 for (size_t i = 0; i < rects.size(); ++i) 810 wkRects[i] = toAPI(rects[i]); 811 context->callback(wkRects.data(), wkRects.size(), scaleFactor, error, context->context); 812} 813 814static PrintInfo printInfoFromWKPrintInfo(const WKPrintInfo& printInfo) 815{ 816 PrintInfo result; 817 result.pageSetupScaleFactor = printInfo.pageSetupScaleFactor; 818 result.availablePaperWidth = printInfo.availablePaperWidth; 819 result.availablePaperHeight = printInfo.availablePaperHeight; 820 return result; 821} 822 823void WKPageComputePagesForPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo, WKPageComputePagesForPrintingFunction callback, void* context) 824{ 825 toImpl(page)->computePagesForPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo), ComputedPagesCallback::create(new ComputedPagesContext(callback, context), computedPagesCallback)); 826} 827 828void WKPageBeginPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo) 829{ 830 toImpl(page)->beginPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo)); 831} 832 833void WKPageDrawPagesToPDF(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo, uint32_t first, uint32_t count, WKPageDrawToPDFFunction callback, void* context) 834{ 835 toImpl(page)->drawPagesToPDF(toImpl(frame), printInfoFromWKPrintInfo(printInfo), first, count, DataCallback::create(context, callback)); 836} 837 838void WKPageEndPrinting(WKPageRef page) 839{ 840 toImpl(page)->endPrinting(); 841} 842#endif 843 844WKImageRef WKPageCreateSnapshotOfVisibleContent(WKPageRef) 845{ 846 return 0; 847} 848 849void WKPageSetShouldSendEventsSynchronously(WKPageRef page, bool sync) 850{ 851 toImpl(page)->setShouldSendEventsSynchronously(sync); 852} 853 854void WKPageSetMediaVolume(WKPageRef page, float volume) 855{ 856 toImpl(page)->setMediaVolume(volume); 857} 858 859void WKPagePostMessageToInjectedBundle(WKPageRef pageRef, WKStringRef messageNameRef, WKTypeRef messageBodyRef) 860{ 861 toImpl(pageRef)->postMessageToInjectedBundle(toImpl(messageNameRef)->string(), toImpl(messageBodyRef)); 862} 863 864WKArrayRef WKPageCopyRelatedPages(WKPageRef pageRef) 865{ 866 return toAPI(toImpl(pageRef)->relatedPages().leakRef()); 867} 868 869void WKPageSetMayStartMediaWhenInWindow(WKPageRef pageRef, bool mayStartMedia) 870{ 871 toImpl(pageRef)->setMayStartMediaWhenInWindow(mayStartMedia); 872} 873 874 875void WKPageSelectContextMenuItem(WKPageRef page, WKContextMenuItemRef item) 876{ 877#if ENABLE(CONTEXT_MENUS) 878 toImpl(page)->contextMenuItemSelected(*(toImpl(item)->data())); 879#endif 880} 881 882WKScrollPinningBehavior WKPageGetScrollPinningBehavior(WKPageRef page) 883{ 884 ScrollPinningBehavior pinning = toImpl(page)->scrollPinningBehavior(); 885 886 switch (pinning) { 887 case WebCore::ScrollPinningBehavior::DoNotPin: 888 return kWKScrollPinningBehaviorDoNotPin; 889 case WebCore::ScrollPinningBehavior::PinToTop: 890 return kWKScrollPinningBehaviorPinToTop; 891 case WebCore::ScrollPinningBehavior::PinToBottom: 892 return kWKScrollPinningBehaviorPinToBottom; 893 } 894 895 ASSERT_NOT_REACHED(); 896 return kWKScrollPinningBehaviorDoNotPin; 897} 898 899void WKPageSetScrollPinningBehavior(WKPageRef page, WKScrollPinningBehavior pinning) 900{ 901 ScrollPinningBehavior corePinning = ScrollPinningBehavior::DoNotPin; 902 903 switch (pinning) { 904 case kWKScrollPinningBehaviorDoNotPin: 905 corePinning = ScrollPinningBehavior::DoNotPin; 906 break; 907 case kWKScrollPinningBehaviorPinToTop: 908 corePinning = ScrollPinningBehavior::PinToTop; 909 break; 910 case kWKScrollPinningBehaviorPinToBottom: 911 corePinning = ScrollPinningBehavior::PinToBottom; 912 break; 913 default: 914 ASSERT_NOT_REACHED(); 915 } 916 917 toImpl(page)->setScrollPinningBehavior(corePinning); 918} 919 920 921 922// -- DEPRECATED -- 923 924void WKPageSetInvalidMessageFunction(WKPageInvalidMessageFunction) 925{ 926 // FIXME: Remove this function when doing so won't break WebKit nightlies. 927} 928 929WKStringRef WKPageGetPluginInformationBundleIdentifierKey() 930{ 931 return WKPluginInformationBundleIdentifierKey(); 932} 933 934WKStringRef WKPageGetPluginInformationBundleVersionKey() 935{ 936 return WKPluginInformationBundleVersionKey(); 937} 938 939WKStringRef WKPageGetPluginInformationDisplayNameKey() 940{ 941 return WKPluginInformationDisplayNameKey(); 942} 943 944WKStringRef WKPageGetPluginInformationFrameURLKey() 945{ 946 return WKPluginInformationFrameURLKey(); 947} 948 949WKStringRef WKPageGetPluginInformationMIMETypeKey() 950{ 951 return WKPluginInformationMIMETypeKey(); 952} 953 954WKStringRef WKPageGetPluginInformationPageURLKey() 955{ 956 return WKPluginInformationPageURLKey(); 957} 958 959WKStringRef WKPageGetPluginInformationPluginspageAttributeURLKey() 960{ 961 return WKPluginInformationPluginspageAttributeURLKey(); 962} 963 964WKStringRef WKPageGetPluginInformationPluginURLKey() 965{ 966 return WKPluginInformationPluginURLKey(); 967} 968 969// -- DEPRECATED -- 970 971