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