WebPageProxy.h 9.05 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*
 * Copyright (C) 2010 Apple Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef WebPageProxy_h
#define WebPageProxy_h

#include "DrawingAreaProxy.h"
30 31
#include "GenericCallback.h"
#include "WKBase.h"
32 33
#include "WebEvent.h"
#include "WebFrameProxy.h"
34
#include "WebHistoryClient.h"
35 36 37 38
#include "WebLoaderClient.h"
#include "WebPolicyClient.h"
#include "WebUIClient.h"
#include <WebCore/FrameLoaderTypes.h>
39
#include <WebCore/PlatformString.h>
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#include <wtf/HashMap.h>
#include <wtf/OwnPtr.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>

namespace CoreIPC {
    class ArgumentDecoder;
    class Connection;
    class MessageID;
}

namespace WebCore {
    class IntSize;
55
    class Cursor;
56 57
}

58 59
struct WKContextStatistics;

60 61 62 63
namespace WebKit {

class DrawingAreaProxy;
class PageClient;
64
class WebBackForwardList;
65
class WebBackForwardListItem;
66 67 68 69 70
class WebKeyboardEvent;
class WebMouseEvent;
class WebPageNamespace;
class WebProcessProxy;
class WebWheelEvent;
71
struct WebNavigationDataStore;
72

73 74 75
typedef GenericCallback<WKStringRef> RenderTreeExternalRepresentationCallback;
typedef GenericCallback<WKStringRef> ScriptReturnValueCallback;

76 77 78 79 80 81 82 83 84 85 86
class WebPageProxy : public RefCounted<WebPageProxy> {
public:
    static PassRefPtr<WebPageProxy> create(WebPageNamespace*, uint64_t pageID);
    ~WebPageProxy();

    uint64_t pageID() const { return m_pageID; }

    WebFrameProxy* webFrame(uint64_t) const;
    WebFrameProxy* mainFrame() const { return m_mainFrame.get(); }

    DrawingAreaProxy* drawingArea() { return m_drawingArea.get(); }
87
    void setDrawingArea(PassOwnPtr<DrawingAreaProxy>);
88

89
    WebBackForwardList* backForwardList() { return m_backForwardList.get(); }
90

91 92 93 94
    void setPageClient(PageClient*);
    void initializeLoaderClient(WKPageLoaderClient*);
    void initializePolicyClient(WKPagePolicyClient*);
    void initializeUIClient(WKPageUIClient*);
95
    void initializeHistoryClient(WKPageHistoryClient*);
96 97 98 99 100 101 102 103 104 105

    void revive();

    void initializeWebPage(const WebCore::IntSize&, PassOwnPtr<DrawingAreaProxy>);
    void reinitializeWebPage(const WebCore::IntSize&);

    void close();
    bool tryClose();
    bool isClosed() const { return m_closed; }

106
    void loadURL(const WebCore::String&);
107
    void stopLoading();
108
    void reload(bool reloadFromOrigin);
109 110

    void goForward();
111
    bool canGoForward() const;
112
    void goBack();
113 114 115
    bool canGoBack() const;

    void goToBackForwardItem(WebBackForwardListItem*);
116
    void didChangeBackForwardList();
117 118 119

    void setFocused(bool isFocused);
    void setActive(bool active);
120
    void setIsInWindow(bool isInWindow);
121 122 123 124 125

    void mouseEvent(const WebMouseEvent&);
    void wheelEvent(const WebWheelEvent&);
    void keyEvent(const WebKeyboardEvent&);

126
    const WebCore::String& pageTitle() const { return m_pageTitle; }
127 128
    const WebCore::String& toolTip() const { return m_toolTip; }

129 130
    double estimatedProgress() const { return m_estimatedProgress; }

131 132 133
    void terminateProcess();

    void runJavaScriptInMainFrame(const WebCore::String&, PassRefPtr<ScriptReturnValueCallback>);
134
    void getRenderTreeExternalRepresentation(PassRefPtr<RenderTreeExternalRepresentationCallback>);
135 136 137 138 139 140 141 142 143 144 145

    void receivedPolicyDecision(WebCore::PolicyAction, WebFrameProxy*, uint64_t listenerID);

    void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder&);
    void didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder&, CoreIPC::ArgumentEncoder&);

    void processDidBecomeUnresponsive();
    void processDidBecomeResponsive();
    void processDidExit();
    void processDidRevive();

146 147 148 149 150
#if USE(ACCELERATED_COMPOSITING)
    void didEnterAcceleratedCompositing();
    void didLeaveAcceleratedCompositing();
#endif

151 152 153 154 155 156
    WebProcessProxy* process() const;
    WebPageNamespace* pageNamespace() const { return m_pageNamespace.get(); }

    bool isValid();

    // REMOVE: For demo purposes only.
157
    const WebCore::String& urlAtProcessExit() const { return m_urlAtProcessExit; }
158 159 160

    void preferencesDidChange();

161 162
    void getStatistics(WKContextStatistics*);

163 164 165 166 167 168
private:
    WebPageProxy(WebPageNamespace*, uint64_t pageID);

    void didCreateMainFrame(uint64_t frameID);
    void didCreateSubFrame(uint64_t frameID);

169
    void didStartProvisionalLoadForFrame(WebFrameProxy*, const WebCore::String&);
170 171 172 173 174 175 176 177 178 179 180 181
    void didReceiveServerRedirectForProvisionalLoadForFrame(WebFrameProxy*);
    void didFailProvisionalLoadForFrame(WebFrameProxy*);
    void didCommitLoadForFrame(WebFrameProxy*);
    void didFinishLoadForFrame(WebFrameProxy*);
    void didFailLoadForFrame(WebFrameProxy*);
    void didReceiveTitleForFrame(WebFrameProxy*, const WebCore::String&);
    void didFirstLayoutForFrame(WebFrameProxy*);
    void didFirstVisuallyNonEmptyLayoutForFrame(WebFrameProxy*);
    void didStartProgress();
    void didChangeProgress(double);
    void didFinishProgress();
    
182 183
    void decidePolicyForNavigationAction(WebFrameProxy*, WebCore::NavigationType navigationType, const WebCore::String& url, uint64_t listenerID);
    void decidePolicyForNewWindowAction(WebFrameProxy*, WebCore::NavigationType navigationType, const WebCore::String& url, uint64_t listenerID);
184
    void decidePolicyForMIMEType(WebFrameProxy*, const WebCore::String& MIMEType, const WebCore::String& url, uint64_t listenerID);
185 186 187 188 189

    WebPageProxy* createNewPage();
    void showPage();
    void closePage();
    void runJavaScriptAlert(WebFrameProxy*, const WebCore::String&);
190 191
    bool runJavaScriptConfirm(WebFrameProxy* frame, const WebCore::String&);
    WebCore::String runJavaScriptPrompt(WebFrameProxy* frame, const WebCore::String&, const WebCore::String&);
192

193 194 195 196 197
    void didNavigateWithNavigationData(WebFrameProxy*, const WebNavigationDataStore&); 
    void didPerformClientRedirect(WebFrameProxy*, const WebCore::String& sourceURLString, const WebCore::String& destinationURLString);
    void didPerformServerRedirect(WebFrameProxy*, const WebCore::String& sourceURLString, const WebCore::String& destinationURLString);
    void didUpdateHistoryTitle(WebFrameProxy*, const WebCore::String& title, const WebCore::String& url);

198 199
    void addItemToBackForwardList(WebBackForwardListItem*);
    void goToItemInBackForwardList(WebBackForwardListItem*);
200

201 202
    void takeFocus(bool direction);
    void setToolTip(const WebCore::String&);
203
    void setCursor(const WebCore::Cursor&);
204 205 206

    void didReceiveEvent(WebEvent::Type);
    void didRunJavaScriptInMainFrame(const WebCore::String&, uint64_t);
207
    void didGetRenderTreeExternalRepresentation(const WebCore::String&, uint64_t);
208

209 210 211
#if USE(ACCELERATED_COMPOSITING)
    void didChangeAcceleratedCompositing(bool compositing);
#endif    
212

213 214 215 216 217
#if PLATFORM(WIN)
    PageClient* m_pageClient;
#else
    // FIXME: This should not be an OwnPtr to the PageClient.  We need to find a better way to clean up m_pageClient on mac.
    // http://bugs.webkit.org/show_bug.cgi?id=40185
218
    OwnPtr<PageClient> m_pageClient;
219
#endif
220 221 222
    WebLoaderClient m_loaderClient;
    WebPolicyClient m_policyClient;
    WebUIClient m_uiClient;
223
    WebHistoryClient m_historyClient;
224 225 226 227 228

    OwnPtr<DrawingAreaProxy> m_drawingArea;
    RefPtr<WebPageNamespace> m_pageNamespace;
    RefPtr<WebFrameProxy> m_mainFrame;
    HashMap<uint64_t, RefPtr<WebFrameProxy> > m_frameMap;
229
    WebCore::String m_pageTitle;
230 231

    HashMap<uint64_t, RefPtr<ScriptReturnValueCallback> > m_scriptReturnValueCallbacks;
232 233
    HashMap<uint64_t, RefPtr<RenderTreeExternalRepresentationCallback> > m_renderTreeExternalRepresentationCallbacks;

234
    double m_estimatedProgress;
235

236 237 238
    // Whether the web page is contained in a top-level window.
    bool m_isInWindow;

239 240
    bool m_canGoBack;
    bool m_canGoForward;
241
    RefPtr<WebBackForwardList> m_backForwardList;
242 243 244 245

    WebCore::String m_toolTip;

    // REMOVE: For demo purposes only.
246
    WebCore::String m_urlAtProcessExit;
247 248 249 250 251 252 253 254 255 256
    
    bool m_valid;
    bool m_closed;

    uint64_t m_pageID;
};

} // namespace WebKit

#endif // WebPageProxy_h