e9462dfae31f8c4ad225e823d871e6b97272a7fa
[WebKit.git] / Tools / WebKitTestRunner / InjectedBundle / InjectedBundlePage.h
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
33 namespace WTR {
34
35 class InjectedBundlePage {
36 public:
37     InjectedBundlePage(WKBundlePageRef);
38     ~InjectedBundlePage();
39
40     WKBundlePageRef page() const { return m_page; }
41     void dump();
42
43     void stopLoading();
44     bool isLoading() { return m_isLoading; }
45
46     void reset();
47
48     void dumpBackForwardList();
49
50 private:
51     // Loader Client
52     static void didStartProvisionalLoadForFrame(WKBundlePageRef, WKBundleFrameRef, WKTypeRef*, const void*);
53     static void didReceiveServerRedirectForProvisionalLoadForFrame(WKBundlePageRef, WKBundleFrameRef, WKTypeRef*, const void*);
54     static void didFailProvisionalLoadWithErrorForFrame(WKBundlePageRef, WKBundleFrameRef, WKErrorRef, WKTypeRef*, const void*);
55     static void didCommitLoadForFrame(WKBundlePageRef, WKBundleFrameRef, WKTypeRef*, const void*);
56     static void didFinishLoadForFrame(WKBundlePageRef, WKBundleFrameRef, WKTypeRef*, const void*);
57     static void didFinishDocumentLoadForFrame(WKBundlePageRef, WKBundleFrameRef,  WKTypeRef*, const void*);
58     static void didFailLoadWithErrorForFrame(WKBundlePageRef, WKBundleFrameRef, WKErrorRef, WKTypeRef*, const void*);
59     static void didReceiveTitleForFrame(WKBundlePageRef, WKStringRef title, WKBundleFrameRef, WKTypeRef*, const void*);
60     static void didClearWindowForFrame(WKBundlePageRef, WKBundleFrameRef, WKBundleScriptWorldRef, const void*);
61     static void didCancelClientRedirectForFrame(WKBundlePageRef, WKBundleFrameRef, const void*);
62     static void willPerformClientRedirectForFrame(WKBundlePageRef, WKBundleFrameRef, WKURLRef url, double delay, double date, const void*);
63     static void didSameDocumentNavigationForFrame(WKBundlePageRef, WKBundleFrameRef, WKSameDocumentNavigationType, WKTypeRef*, const void*);
64     static void didHandleOnloadEventsForFrame(WKBundlePageRef, WKBundleFrameRef, const void*);
65     static void didDisplayInsecureContentForFrame(WKBundlePageRef, WKBundleFrameRef, WKTypeRef*, const void*);
66     static void didRunInsecureContentForFrame(WKBundlePageRef, WKBundleFrameRef, WKTypeRef*, const void*);
67     static bool shouldLoadResourceForFrame(WKBundlePageRef, WKBundleFrameRef, WKStringRef, 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 didFailLoadWithErrorForFrame(WKBundleFrameRef, WKErrorRef);
74     void didReceiveTitleForFrame(WKStringRef title, WKBundleFrameRef);
75     void didClearWindowForFrame(WKBundleFrameRef, WKBundleScriptWorldRef);
76     void didCancelClientRedirectForFrame(WKBundleFrameRef);
77     void willPerformClientRedirectForFrame(WKBundleFrameRef, WKURLRef url, double delay, double date);
78     void didSameDocumentNavigationForFrame(WKBundleFrameRef, WKSameDocumentNavigationType);
79     void didFinishDocumentLoadForFrame(WKBundleFrameRef);
80     void didHandleOnloadEventsForFrame(WKBundleFrameRef);
81     void didDisplayInsecureContentForFrame(WKBundleFrameRef);
82     void didRunInsecureContentForFrame(WKBundleFrameRef);
83     bool shouldLoadResourceForFrame(WKBundleFrameRef);
84
85     // UI Client
86     static void willAddMessageToConsole(WKBundlePageRef, WKStringRef message, uint32_t lineNumber, const void* clientInfo);
87     static void willSetStatusbarText(WKBundlePageRef, WKStringRef statusbarText, const void* clientInfo);
88     static void willRunJavaScriptAlert(WKBundlePageRef, WKStringRef message, WKBundleFrameRef frame, const void* clientInfo);
89     static void willRunJavaScriptConfirm(WKBundlePageRef, WKStringRef message, WKBundleFrameRef frame, const void* clientInfo);
90     static void willRunJavaScriptPrompt(WKBundlePageRef, WKStringRef message, WKStringRef defaultValue, WKBundleFrameRef frame, const void* clientInfo);
91     void willAddMessageToConsole(WKStringRef message, uint32_t lineNumber);
92     void willSetStatusbarText(WKStringRef statusbarText);
93     void willRunJavaScriptAlert(WKStringRef message, WKBundleFrameRef);
94     void willRunJavaScriptConfirm(WKStringRef message, WKBundleFrameRef);
95     void willRunJavaScriptPrompt(WKStringRef message, WKStringRef defaultValue, WKBundleFrameRef);
96
97     // Editor client
98     static bool shouldBeginEditing(WKBundlePageRef, WKBundleRangeHandleRef, const void* clientInfo);
99     static bool shouldEndEditing(WKBundlePageRef, WKBundleRangeHandleRef, const void* clientInfo);
100     static bool shouldInsertNode(WKBundlePageRef, WKBundleNodeHandleRef, WKBundleRangeHandleRef rangeToReplace, WKInsertActionType, const void* clientInfo);
101     static bool shouldInsertText(WKBundlePageRef, WKStringRef, WKBundleRangeHandleRef rangeToReplace, WKInsertActionType, const void* clientInfo);
102     static bool shouldDeleteRange(WKBundlePageRef, WKBundleRangeHandleRef, const void* clientInfo);
103     static bool shouldChangeSelectedRange(WKBundlePageRef, WKBundleRangeHandleRef fromRange, WKBundleRangeHandleRef toRange, WKAffinityType, bool stillSelecting, const void* clientInfo);
104     static bool shouldApplyStyle(WKBundlePageRef, WKBundleCSSStyleDeclarationRef style, WKBundleRangeHandleRef range, const void* clientInfo);
105     static void didBeginEditing(WKBundlePageRef, WKStringRef notificationName, const void* clientInfo);
106     static void didEndEditing(WKBundlePageRef, WKStringRef notificationName, const void* clientInfo);
107     static void didChange(WKBundlePageRef, WKStringRef notificationName, const void* clientInfo);
108     static void didChangeSelection(WKBundlePageRef, WKStringRef notificationName, const void* clientInfo);
109     bool shouldBeginEditing(WKBundleRangeHandleRef);
110     bool shouldEndEditing(WKBundleRangeHandleRef);
111     bool shouldInsertNode(WKBundleNodeHandleRef, WKBundleRangeHandleRef rangeToReplace, WKInsertActionType);
112     bool shouldInsertText(WKStringRef, WKBundleRangeHandleRef rangeToReplace, WKInsertActionType);
113     bool shouldDeleteRange(WKBundleRangeHandleRef);
114     bool shouldChangeSelectedRange(WKBundleRangeHandleRef fromRange, WKBundleRangeHandleRef toRange, WKAffinityType, bool stillSelecting);
115     bool shouldApplyStyle(WKBundleCSSStyleDeclarationRef style, WKBundleRangeHandleRef range);
116     void didBeginEditing(WKStringRef notificationName);
117     void didEndEditing(WKStringRef notificationName);
118     void didChange(WKStringRef notificationName);
119     void didChangeSelection(WKStringRef notificationName);
120
121     void dumpAllFramesText();
122     void dumpAllFrameScrollPositions();
123
124     WKBundlePageRef m_page;
125     WKRetainPtr<WKBundleScriptWorldRef> m_world;
126     WKRetainPtr<WKBundleBackForwardListItemRef> m_previousTestBackForwardListItem;
127     bool m_isLoading;
128 };
129
130 } // namespace WTR
131
132 #endif // InjectedBundlePage_h