InjectedBundlePage.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. #ifndef InjectedBundlePage_h
  26. #define InjectedBundlePage_h
  27. #include <WebKit2/WKBundlePage.h>
  28. #include <WebKit2/WKBundleScriptWorld.h>
  29. #include <WebKit2/WKRetainPtr.h>
  30. #include <wtf/text/WTFString.h>
  31. namespace WTR {
  32. class InjectedBundlePage {
  33. public:
  34. InjectedBundlePage(WKBundlePageRef);
  35. ~InjectedBundlePage();
  36. WKBundlePageRef page() const { return m_page; }
  37. void dump();
  38. void stopLoading();
  39. void prepare();
  40. void resetAfterTest();
  41. void dumpBackForwardList(WTF::StringBuilder&);
  42. private:
  43. // Loader Client
  44. static void didStartProvisionalLoadForFrame(WKBundlePageRef, WKBundleFrameRef, WKTypeRef*, const void*);
  45. static void didReceiveServerRedirectForProvisionalLoadForFrame(WKBundlePageRef, WKBundleFrameRef, WKTypeRef*, const void*);
  46. static void didFailProvisionalLoadWithErrorForFrame(WKBundlePageRef, WKBundleFrameRef, WKErrorRef, WKTypeRef*, const void*);
  47. static void didCommitLoadForFrame(WKBundlePageRef, WKBundleFrameRef, WKTypeRef*, const void*);
  48. static void didFinishLoadForFrame(WKBundlePageRef, WKBundleFrameRef, WKTypeRef*, const void*);
  49. static void didFinishProgress(WKBundlePageRef, const void*);
  50. static void didFinishDocumentLoadForFrame(WKBundlePageRef, WKBundleFrameRef, WKTypeRef*, const void*);
  51. static void didFailLoadWithErrorForFrame(WKBundlePageRef, WKBundleFrameRef, WKErrorRef, WKTypeRef*, const void*);
  52. static void didReceiveTitleForFrame(WKBundlePageRef, WKStringRef title, WKBundleFrameRef, WKTypeRef*, const void*);
  53. static void didClearWindowForFrame(WKBundlePageRef, WKBundleFrameRef, WKBundleScriptWorldRef, const void*);
  54. static void didCancelClientRedirectForFrame(WKBundlePageRef, WKBundleFrameRef, const void*);
  55. static void willPerformClientRedirectForFrame(WKBundlePageRef, WKBundleFrameRef, WKURLRef url, double delay, double date, const void*);
  56. static void didSameDocumentNavigationForFrame(WKBundlePageRef, WKBundleFrameRef, WKSameDocumentNavigationType, WKTypeRef*, const void*);
  57. static void didHandleOnloadEventsForFrame(WKBundlePageRef, WKBundleFrameRef, const void*);
  58. static void didDisplayInsecureContentForFrame(WKBundlePageRef, WKBundleFrameRef, WKTypeRef*, const void*);
  59. static void didRunInsecureContentForFrame(WKBundlePageRef, WKBundleFrameRef, WKTypeRef*, const void*);
  60. static void didDetectXSSForFrame(WKBundlePageRef, WKBundleFrameRef, WKTypeRef*, const void*);
  61. static void didInitiateLoadForResource(WKBundlePageRef, WKBundleFrameRef, uint64_t identifier, WKURLRequestRef, bool pageLoadIsProvisional, const void*);
  62. static WKURLRequestRef willSendRequestForFrame(WKBundlePageRef, WKBundleFrameRef, uint64_t identifier, WKURLRequestRef, WKURLResponseRef, const void*);
  63. static void didReceiveResponseForResource(WKBundlePageRef, WKBundleFrameRef, uint64_t identifier, WKURLResponseRef, const void*);
  64. static void didReceiveContentLengthForResource(WKBundlePageRef, WKBundleFrameRef, uint64_t identifier, uint64_t length, const void*);
  65. static void didFinishLoadForResource(WKBundlePageRef, WKBundleFrameRef, uint64_t identifier, const void*);
  66. static void didFailLoadForResource(WKBundlePageRef, WKBundleFrameRef, uint64_t identifier, WKErrorRef, const void*);
  67. static bool shouldCacheResponse(WKBundlePageRef, WKBundleFrameRef, uint64_t identifier, const void*);
  68. void didStartProvisionalLoadForFrame(WKBundleFrameRef);
  69. void didReceiveServerRedirectForProvisionalLoadForFrame(WKBundleFrameRef);
  70. void didFailProvisionalLoadWithErrorForFrame(WKBundleFrameRef, WKErrorRef);
  71. void didCommitLoadForFrame(WKBundleFrameRef);
  72. void didFinishLoadForFrame(WKBundleFrameRef);
  73. void didFinishProgress();
  74. void didFailLoadWithErrorForFrame(WKBundleFrameRef, WKErrorRef);
  75. void didReceiveTitleForFrame(WKStringRef title, WKBundleFrameRef);
  76. void didClearWindowForFrame(WKBundleFrameRef, WKBundleScriptWorldRef);
  77. void didCancelClientRedirectForFrame(WKBundleFrameRef);
  78. void willPerformClientRedirectForFrame(WKBundleFrameRef, WKURLRef url, double delay, double date);
  79. void didSameDocumentNavigationForFrame(WKBundleFrameRef, WKSameDocumentNavigationType);
  80. void didFinishDocumentLoadForFrame(WKBundleFrameRef);
  81. void didHandleOnloadEventsForFrame(WKBundleFrameRef);
  82. void didDisplayInsecureContentForFrame(WKBundleFrameRef);
  83. void didRunInsecureContentForFrame(WKBundleFrameRef);
  84. void didDetectXSSForFrame(WKBundleFrameRef);
  85. // Resource Load Client
  86. void didInitiateLoadForResource(WKBundlePageRef, WKBundleFrameRef, uint64_t identifier, WKURLRequestRef, bool pageLoadIsProvisional);
  87. WKURLRequestRef willSendRequestForFrame(WKBundlePageRef, WKBundleFrameRef, uint64_t identifier, WKURLRequestRef, WKURLResponseRef);
  88. void didReceiveResponseForResource(WKBundlePageRef, WKBundleFrameRef, uint64_t identifier, WKURLResponseRef);
  89. void didReceiveContentLengthForResource(WKBundlePageRef, WKBundleFrameRef, uint64_t identifier, uint64_t length);
  90. void didFinishLoadForResource(WKBundlePageRef, WKBundleFrameRef, uint64_t identifier);
  91. void didFailLoadForResource(WKBundlePageRef, WKBundleFrameRef, uint64_t identifier, WKErrorRef);
  92. bool shouldCacheResponse(WKBundlePageRef, WKBundleFrameRef, uint64_t identifier);
  93. // WKBundlePagePolicyClient
  94. static WKBundlePagePolicyAction decidePolicyForNavigationAction(WKBundlePageRef, WKBundleFrameRef, WKBundleNavigationActionRef, WKURLRequestRef, WKTypeRef*, const void*);
  95. static WKBundlePagePolicyAction decidePolicyForNewWindowAction(WKBundlePageRef, WKBundleFrameRef, WKBundleNavigationActionRef, WKURLRequestRef, WKStringRef frameName, WKTypeRef*, const void*);
  96. static WKBundlePagePolicyAction decidePolicyForResponse(WKBundlePageRef, WKBundleFrameRef, WKURLResponseRef, WKURLRequestRef, WKTypeRef*, const void*);
  97. static void unableToImplementPolicy(WKBundlePageRef, WKBundleFrameRef, WKErrorRef, WKTypeRef*, const void*);
  98. WKBundlePagePolicyAction decidePolicyForNavigationAction(WKBundlePageRef, WKBundleFrameRef, WKBundleNavigationActionRef, WKURLRequestRef, WKTypeRef*);
  99. WKBundlePagePolicyAction decidePolicyForNewWindowAction(WKBundlePageRef, WKBundleFrameRef, WKBundleNavigationActionRef, WKURLRequestRef, WKStringRef frameName, WKTypeRef*);
  100. WKBundlePagePolicyAction decidePolicyForResponse(WKBundlePageRef, WKBundleFrameRef, WKURLResponseRef, WKURLRequestRef, WKTypeRef*);
  101. void unableToImplementPolicy(WKBundlePageRef, WKBundleFrameRef, WKErrorRef, WKTypeRef*);
  102. // UI Client
  103. static void willAddMessageToConsole(WKBundlePageRef, WKStringRef message, uint32_t lineNumber, const void* clientInfo);
  104. static void willSetStatusbarText(WKBundlePageRef, WKStringRef statusbarText, const void* clientInfo);
  105. static void willRunJavaScriptAlert(WKBundlePageRef, WKStringRef message, WKBundleFrameRef frame, const void* clientInfo);
  106. static void willRunJavaScriptConfirm(WKBundlePageRef, WKStringRef message, WKBundleFrameRef frame, const void* clientInfo);
  107. static void willRunJavaScriptPrompt(WKBundlePageRef, WKStringRef message, WKStringRef defaultValue, WKBundleFrameRef frame, const void* clientInfo);
  108. static void didReachApplicationCacheOriginQuota(WKBundlePageRef, WKSecurityOriginRef, int64_t totalBytesNeeded, const void* clientInfo);
  109. static uint64_t didExceedDatabaseQuota(WKBundlePageRef, WKSecurityOriginRef, WKStringRef databaseName, WKStringRef databaseDisplayName, uint64_t currentQuotaBytes, uint64_t currentOriginUsageBytes, uint64_t currentDatabaseUsageBytes, uint64_t expectedUsageBytes, const void* clientInfo);
  110. void willAddMessageToConsole(WKStringRef message, uint32_t lineNumber);
  111. void willSetStatusbarText(WKStringRef statusbarText);
  112. void willRunJavaScriptAlert(WKStringRef message, WKBundleFrameRef);
  113. void willRunJavaScriptConfirm(WKStringRef message, WKBundleFrameRef);
  114. void willRunJavaScriptPrompt(WKStringRef message, WKStringRef defaultValue, WKBundleFrameRef);
  115. void didReachApplicationCacheOriginQuota(WKSecurityOriginRef, int64_t totalBytesNeeded);
  116. uint64_t didExceedDatabaseQuota(WKSecurityOriginRef, WKStringRef databaseName, WKStringRef databaseDisplayName, uint64_t currentQuotaBytes, uint64_t currentOriginUsageBytes, uint64_t currentDatabaseUsageBytes, uint64_t expectedUsageBytes);
  117. #if ENABLE(FULLSCREEN_API)
  118. // Full Screen client
  119. static bool supportsFullScreen(WKBundlePageRef, WKFullScreenKeyboardRequestType);
  120. static void setHasCustomFullScreenBehavior(WKBundlePageRef, bool value);
  121. static void enterFullScreenForElement(WKBundlePageRef, WKBundleNodeHandleRef element);
  122. static void exitFullScreenForElement(WKBundlePageRef, WKBundleNodeHandleRef element);
  123. static void beganEnterFullScreen(WKBundlePageRef, WKRect initialFrame, WKRect finalFrame);
  124. static void beganExitFullScreen(WKBundlePageRef, WKRect initialFrame, WKRect finalFrame);
  125. static void closeFullScreen(WKBundlePageRef);
  126. #endif
  127. // Editor client
  128. static bool shouldBeginEditing(WKBundlePageRef, WKBundleRangeHandleRef, const void* clientInfo);
  129. static bool shouldEndEditing(WKBundlePageRef, WKBundleRangeHandleRef, const void* clientInfo);
  130. static bool shouldInsertNode(WKBundlePageRef, WKBundleNodeHandleRef, WKBundleRangeHandleRef rangeToReplace, WKInsertActionType, const void* clientInfo);
  131. static bool shouldInsertText(WKBundlePageRef, WKStringRef, WKBundleRangeHandleRef rangeToReplace, WKInsertActionType, const void* clientInfo);
  132. static bool shouldDeleteRange(WKBundlePageRef, WKBundleRangeHandleRef, const void* clientInfo);
  133. static bool shouldChangeSelectedRange(WKBundlePageRef, WKBundleRangeHandleRef fromRange, WKBundleRangeHandleRef toRange, WKAffinityType, bool stillSelecting, const void* clientInfo);
  134. static bool shouldApplyStyle(WKBundlePageRef, WKBundleCSSStyleDeclarationRef style, WKBundleRangeHandleRef range, const void* clientInfo);
  135. static void didBeginEditing(WKBundlePageRef, WKStringRef notificationName, const void* clientInfo);
  136. static void didEndEditing(WKBundlePageRef, WKStringRef notificationName, const void* clientInfo);
  137. static void didChange(WKBundlePageRef, WKStringRef notificationName, const void* clientInfo);
  138. static void didChangeSelection(WKBundlePageRef, WKStringRef notificationName, const void* clientInfo);
  139. bool shouldBeginEditing(WKBundleRangeHandleRef);
  140. bool shouldEndEditing(WKBundleRangeHandleRef);
  141. bool shouldInsertNode(WKBundleNodeHandleRef, WKBundleRangeHandleRef rangeToReplace, WKInsertActionType);
  142. bool shouldInsertText(WKStringRef, WKBundleRangeHandleRef rangeToReplace, WKInsertActionType);
  143. bool shouldDeleteRange(WKBundleRangeHandleRef);
  144. bool shouldChangeSelectedRange(WKBundleRangeHandleRef fromRange, WKBundleRangeHandleRef toRange, WKAffinityType, bool stillSelecting);
  145. bool shouldApplyStyle(WKBundleCSSStyleDeclarationRef style, WKBundleRangeHandleRef range);
  146. void didBeginEditing(WKStringRef notificationName);
  147. void didEndEditing(WKStringRef notificationName);
  148. void didChange(WKStringRef notificationName);
  149. void didChangeSelection(WKStringRef notificationName);
  150. void dumpAllFramesText(WTF::StringBuilder&);
  151. void dumpAllFrameScrollPositions(WTF::StringBuilder&);
  152. void dumpDOMAsWebArchive(WKBundleFrameRef, WTF::StringBuilder&);
  153. void platformDidStartProvisionalLoadForFrame(WKBundleFrameRef);
  154. void frameDidChangeLocation(WKBundleFrameRef, bool shouldDump = false);
  155. WKBundlePageRef m_page;
  156. WKRetainPtr<WKBundleScriptWorldRef> m_world;
  157. WKRetainPtr<WKBundleBackForwardListItemRef> m_previousTestBackForwardListItem;
  158. };
  159. } // namespace WTR
  160. #endif // InjectedBundlePage_h