Add URLRequest API for WebKit2
[WebKit-https.git] / WebKit2 / WebProcess / WebPage / WebPage.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 WebPage_h
27 #define WebPage_h
28
29 #include "APIObject.h"
30 #include "DrawingArea.h"
31 #include "InjectedBundlePageEditorClient.h"
32 #include "InjectedBundlePageFormClient.h"
33 #include "InjectedBundlePageLoaderClient.h"
34 #include "InjectedBundlePageUIClient.h"
35 #include <WebCore/FrameLoaderTypes.h>
36 #include <WebCore/IntRect.h>
37 #include <WebCore/ZoomMode.h>
38 #include <wtf/HashMap.h>
39 #include <wtf/OwnPtr.h>
40 #include <wtf/PassRefPtr.h>
41 #include <wtf/RefPtr.h>
42 #include <wtf/text/WTFString.h>
43
44 #if ENABLE(TOUCH_EVENTS)
45 #include <WebCore/PlatformTouchEvent.h>
46 #endif
47
48 namespace CoreIPC {
49     class ArgumentDecoder;
50     class Connection;
51     class MessageID;
52 }
53
54 namespace WebCore {
55     class GraphicsContext;
56     class KeyboardEvent;
57     class Page;
58     class ResourceRequest;
59 }
60
61 namespace WebKit {
62
63 class DrawingArea;
64 class WebEvent;
65 class WebFrame;
66 class WebKeyboardEvent;
67 class WebMouseEvent;
68 class WebWheelEvent;
69 #if ENABLE(TOUCH_EVENTS)
70 class WebTouchEvent;
71 #endif
72 struct WebPreferencesStore;
73
74 class WebPage : public APIObject {
75 public:
76     static const Type APIType = TypeBundlePage;
77
78     static PassRefPtr<WebPage> create(uint64_t pageID, const WebCore::IntSize& viewSize, const WebPreferencesStore&, const DrawingAreaBase::DrawingAreaInfo&);
79     ~WebPage();
80
81     void close();
82
83     WebCore::Page* corePage() const { return m_page.get(); }
84     uint64_t pageID() const { return m_pageID; }
85
86     void setSize(const WebCore::IntSize&);
87     const WebCore::IntSize& size() const { return m_viewSize; }
88
89     DrawingArea* drawingArea() const { return m_drawingArea.get(); }
90
91     // -- Called by the DrawingArea.
92     // FIXME: We could genericize these into a DrawingArea client interface. Would that be beneficial?
93     void drawRect(WebCore::GraphicsContext&, const WebCore::IntRect&);
94     void layoutIfNeeded();
95
96     // -- Called from WebCore clients.
97     bool handleEditingKeyboardEvent(WebCore::KeyboardEvent*);
98     void show();
99     String userAgent() const;
100
101     // -- Called from WebProcess.
102     void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
103
104     // -- InjectedBundle methods
105     void initializeInjectedBundleEditorClient(WKBundlePageEditorClient*);
106     void initializeInjectedBundleFormClient(WKBundlePageFormClient*);
107     void initializeInjectedBundleLoaderClient(WKBundlePageLoaderClient*);
108     void initializeInjectedBundleUIClient(WKBundlePageUIClient*);
109
110     InjectedBundlePageEditorClient& injectedBundleEditorClient() { return m_editorClient; }
111     InjectedBundlePageFormClient& injectedBundleFormClient() { return m_formClient; }
112     InjectedBundlePageLoaderClient& injectedBundleLoaderClient() { return m_loaderClient; }
113     InjectedBundlePageUIClient& injectedBundleUIClient() { return m_uiClient; }
114
115     WebFrame* mainFrame() const { return m_mainFrame.get(); }
116
117     String renderTreeExternalRepresentation() const;
118     void executeEditingCommand(const WTF::String& commandName, const WTF::String& argument);
119     bool isEditingCommandEnabled(const WTF::String& commandName);
120     void clearMainFrameName();
121     void sendClose();
122
123     float zoomFactor() const;
124     void setZoomFactor(float);
125     void setZoomMode(WebCore::ZoomMode);
126
127     void stopLoading();
128
129 #if USE(ACCELERATED_COMPOSITING)
130     void changeAcceleratedCompositingMode(WebCore::GraphicsLayer*);
131     void enterAcceleratedCompositingMode(WebCore::GraphicsLayer*);
132     void exitAcceleratedCompositingMode();
133 #endif
134
135     static const WebEvent* currentEvent();
136
137 private:
138     WebPage(uint64_t pageID, const WebCore::IntSize& viewSize, const WebPreferencesStore&, const DrawingAreaBase::DrawingAreaInfo&);
139
140     virtual Type type() const { return APIType; }
141
142     void platformInitialize();
143     static const char* interpretKeyEvent(const WebCore::KeyboardEvent*);
144     bool performDefaultBehaviorForKeyEvent(const WebKeyboardEvent&);
145
146     // Actions
147     void tryClose();
148     void loadURL(const String&);
149     void loadURLRequest(const WebCore::ResourceRequest&);
150     void reload(bool reloadFromOrigin);
151     void goForward(uint64_t);
152     void goBack(uint64_t);
153     void goToBackForwardItem(uint64_t);
154     void setActive(bool);
155     void setFocused(bool);
156     void setIsInWindow(bool);
157     void mouseEvent(const WebMouseEvent&);
158     void wheelEvent(const WebWheelEvent&);
159     void keyEvent(const WebKeyboardEvent&);
160 #if ENABLE(TOUCH_EVENTS)
161     void touchEvent(const WebTouchEvent&);
162 #endif
163     void runJavaScriptInMainFrame(const WTF::String&, uint64_t callbackID);
164     void getRenderTreeExternalRepresentation(uint64_t callbackID);
165     void preferencesDidChange(const WebPreferencesStore&);
166     void platformPreferencesDidChange(const WebPreferencesStore&);
167     void didReceivePolicyDecision(WebFrame*, uint64_t listenerID, WebCore::PolicyAction policyAction);
168     void setCustomUserAgent(const WTF::String&);
169
170     OwnPtr<WebCore::Page> m_page;
171     RefPtr<WebFrame> m_mainFrame;
172
173     String m_customUserAgent;
174
175     WebCore::IntSize m_viewSize;
176     RefPtr<DrawingArea> m_drawingArea;
177
178     InjectedBundlePageEditorClient m_editorClient;
179     InjectedBundlePageFormClient m_formClient;
180     InjectedBundlePageLoaderClient m_loaderClient;
181     InjectedBundlePageUIClient m_uiClient;
182
183     uint64_t m_pageID;
184 };
185
186 } // namespace WebKit
187
188 #endif // WebPage_h