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