1 /*
2  * Copyright (C) 2010, 2011 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 WebPageProxy_h
27 #define WebPageProxy_h
28 
29 #include "APIObject.h"
30 #include "Connection.h"
31 #include "ContextMenuState.h"
32 #include "DragControllerAction.h"
33 #include "DrawingAreaProxy.h"
34 #include "EditorState.h"
35 #include "GeolocationPermissionRequestManagerProxy.h"
36 #include "SandboxExtension.h"
37 #include "SharedMemory.h"
38 #include "WKBase.h"
39 #include "WKPagePrivate.h"
40 #include "WebContextMenuItemData.h"
41 #include "WebFindClient.h"
42 #include "WebFormClient.h"
43 #include "WebFrameProxy.h"
44 #include "WebHistoryClient.h"
45 #include "WebLoaderClient.h"
46 #include "WebPageContextMenuClient.h"
47 #include "WebPolicyClient.h"
48 #include "WebPopupMenuProxy.h"
49 #include "WebResourceLoadClient.h"
50 #include "WebUIClient.h"
51 #include <WebCore/ScrollTypes.h>
52 #include <wtf/HashMap.h>
53 #include <wtf/HashSet.h>
54 #include <wtf/OwnPtr.h>
55 #include <wtf/PassOwnPtr.h>
56 #include <wtf/PassRefPtr.h>
57 #include <wtf/RefPtr.h>
58 #include <wtf/text/WTFString.h>
59 
60 namespace CoreIPC {
61     class ArgumentDecoder;
62     class Connection;
63     class MessageID;
64 }
65 
66 namespace WebCore {
67     class AuthenticationChallenge;
68     class Cursor;
69     class DragData;
70     class FloatRect;
71     class IntSize;
72     class ProtectionSpace;
73     struct TextCheckingResult;
74     struct ViewportArguments;
75     struct WindowFeatures;
76 }
77 
78 #if PLATFORM(MAC)
79 #ifdef __OBJC__
80 @class WKView;
81 #else
82 class WKView;
83 #endif
84 #endif
85 
86 namespace WebKit {
87 
88 class NativeWebKeyboardEvent;
89 class NativeWebMouseEvent;
90 class NativeWebWheelEvent;
91 class PageClient;
92 class PlatformCertificateInfo;
93 class StringPairVector;
94 class WebBackForwardList;
95 class WebBackForwardListItem;
96 class WebContextMenuProxy;
97 class WebData;
98 class WebEditCommandProxy;
99 class WebFullScreenManagerProxy;
100 class WebKeyboardEvent;
101 class WebMouseEvent;
102 class WebOpenPanelResultListenerProxy;
103 class WebPageGroup;
104 class WebProcessProxy;
105 class WebURLRequest;
106 class WebWheelEvent;
107 struct AttributedString;
108 struct DictionaryPopupInfo;
109 struct EditorState;
110 struct PlatformPopupMenuData;
111 struct PrintInfo;
112 struct WebPageCreationParameters;
113 struct WebPopupItem;
114 
115 #if ENABLE(GESTURE_EVENTS)
116 class WebGestureEvent;
117 #endif
118 
119 typedef GenericCallback<WKStringRef, StringImpl*> StringCallback;
120 typedef GenericCallback<WKSerializedScriptValueRef, WebSerializedScriptValue*> ScriptValueCallback;
121 
122 // FIXME: Make a version of CallbackBase with three arguments, and define ValidateCommandCallback as a specialization.
123 class ValidateCommandCallback : public CallbackBase {
124 public:
125     typedef void (*CallbackFunction)(WKStringRef, bool, int32_t, WKErrorRef, void*);
126 
create(void * context,CallbackFunction callback)127     static PassRefPtr<ValidateCommandCallback> create(void* context, CallbackFunction callback)
128     {
129         return adoptRef(new ValidateCommandCallback(context, callback));
130     }
131 
~ValidateCommandCallback()132     virtual ~ValidateCommandCallback()
133     {
134         ASSERT(!m_callback);
135     }
136 
performCallbackWithReturnValue(StringImpl * returnValue1,bool returnValue2,int returnValue3)137     void performCallbackWithReturnValue(StringImpl* returnValue1, bool returnValue2, int returnValue3)
138     {
139         ASSERT(m_callback);
140 
141         m_callback(toAPI(returnValue1), returnValue2, returnValue3, 0, context());
142 
143         m_callback = 0;
144     }
145 
invalidate()146     void invalidate()
147     {
148         ASSERT(m_callback);
149 
150         RefPtr<WebError> error = WebError::create();
151         m_callback(0, 0, 0, toAPI(error.get()), context());
152 
153         m_callback = 0;
154     }
155 
156 private:
157 
ValidateCommandCallback(void * context,CallbackFunction callback)158     ValidateCommandCallback(void* context, CallbackFunction callback)
159         : CallbackBase(context)
160         , m_callback(callback)
161     {
162     }
163 
164     CallbackFunction m_callback;
165 };
166 
167 class WebPageProxy : public APIObject, public WebPopupMenuProxy::Client {
168 public:
169     static const Type APIType = TypePage;
170 
171     static PassRefPtr<WebPageProxy> create(PageClient*, PassRefPtr<WebProcessProxy>, WebPageGroup*, uint64_t pageID);
172     virtual ~WebPageProxy();
173 
pageID()174     uint64_t pageID() const { return m_pageID; }
175 
mainFrame()176     WebFrameProxy* mainFrame() const { return m_mainFrame.get(); }
focusedFrame()177     WebFrameProxy* focusedFrame() const { return m_focusedFrame.get(); }
frameSetLargestFrame()178     WebFrameProxy* frameSetLargestFrame() const { return m_frameSetLargestFrame.get(); }
179 
drawingArea()180     DrawingAreaProxy* drawingArea() const { return m_drawingArea.get(); }
181 
backForwardList()182     WebBackForwardList* backForwardList() const { return m_backForwardList.get(); }
183 
184 #if ENABLE(INSPECTOR)
185     WebInspectorProxy* inspector();
186 #endif
187 
188 #if ENABLE(FULLSCREEN_API)
189     WebFullScreenManagerProxy* fullScreenManager();
190 #endif
191 
192     void initializeContextMenuClient(const WKPageContextMenuClient*);
193     void initializeFindClient(const WKPageFindClient*);
194     void initializeFormClient(const WKPageFormClient*);
195     void initializeLoaderClient(const WKPageLoaderClient*);
196     void initializePolicyClient(const WKPagePolicyClient*);
197     void initializeResourceLoadClient(const WKPageResourceLoadClient*);
198     void initializeUIClient(const WKPageUIClient*);
199 
200     void initializeWebPage();
201 
202     void close();
203     bool tryClose();
isClosed()204     bool isClosed() const { return m_isClosed; }
205 
206     void loadURL(const String&);
207     void loadURLRequest(WebURLRequest*);
208     void loadHTMLString(const String& htmlString, const String& baseURL);
209     void loadAlternateHTMLString(const String& htmlString, const String& baseURL, const String& unreachableURL);
210     void loadPlainTextString(const String& string);
211 
212     void stopLoading();
213     void reload(bool reloadFromOrigin);
214 
215     void goForward();
216     bool canGoForward() const;
217     void goBack();
218     bool canGoBack() const;
219 
220     void goToBackForwardItem(WebBackForwardListItem*);
221     void didChangeBackForwardList(WebBackForwardListItem* addedItem, Vector<RefPtr<APIObject> >* removedItems);
222     void shouldGoToBackForwardListItem(uint64_t itemID, bool& shouldGoToBackForwardListItem);
223 
224     bool canShowMIMEType(const String& mimeType) const;
225 
drawsBackground()226     bool drawsBackground() const { return m_drawsBackground; }
227     void setDrawsBackground(bool);
228 
drawsTransparentBackground()229     bool drawsTransparentBackground() const { return m_drawsTransparentBackground; }
230     void setDrawsTransparentBackground(bool);
231 
232     void viewWillStartLiveResize();
233     void viewWillEndLiveResize();
234 
235     void setInitialFocus(bool);
236     void setWindowResizerSize(const WebCore::IntSize&);
237 
238     void clearSelection();
239 
240     void setViewNeedsDisplay(const WebCore::IntRect&);
241     void displayView();
242     void scrollView(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset);
243 
244     enum {
245         ViewWindowIsActive = 1 << 0,
246         ViewIsFocused = 1 << 1,
247         ViewIsVisible = 1 << 2,
248         ViewIsInWindow = 1 << 3
249     };
250     typedef unsigned ViewStateFlags;
251     void viewStateDidChange(ViewStateFlags flags);
252 
253     WebCore::IntSize viewSize() const;
isViewVisible()254     bool isViewVisible() const { return m_isVisible; }
255     bool isViewWindowActive() const;
256 
257     void executeEditCommand(const String& commandName);
258     void validateCommand(const String& commandName, PassRefPtr<ValidateCommandCallback>);
259 
editorState()260     const EditorState& editorState() const { return m_editorState; }
canDelete()261     bool canDelete() const { return hasSelectedRange() && isContentEditable(); }
hasSelectedRange()262     bool hasSelectedRange() const { return m_editorState.selectionIsRange; }
isContentEditable()263     bool isContentEditable() const { return m_editorState.isContentEditable; }
264 
maintainsInactiveSelection()265     bool maintainsInactiveSelection() const { return m_maintainsInactiveSelection; }
266     void setMaintainsInactiveSelection(bool);
267 
268 #if PLATFORM(MAC)
269     void updateWindowIsVisible(bool windowIsVisible);
270     void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates, const WebCore::IntPoint& accessibilityViewCoordinates);
271 
272     void setComposition(const String& text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeEnd);
273     void confirmComposition();
274     void confirmCompositionWithoutDisturbingSelection();
275     bool insertText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd);
276     void getMarkedRange(uint64_t& location, uint64_t& length);
277     void getSelectedRange(uint64_t& location, uint64_t& length);
278     void getAttributedSubstringFromRange(uint64_t location, uint64_t length, AttributedString&);
279     uint64_t characterIndexForPoint(const WebCore::IntPoint);
280     WebCore::IntRect firstRectForCharacterRange(uint64_t, uint64_t);
281     bool executeKeypressCommands(const Vector<WebCore::KeypressCommand>&);
282 
283     void sendComplexTextInputToPlugin(uint64_t pluginComplexTextInputIdentifier, const String& textInput);
284     CGContextRef containingWindowGraphicsContext();
285     bool shouldDelayWindowOrderingForEvent(const WebMouseEvent&);
286     bool acceptsFirstMouse(int eventNumber, const WebMouseEvent&);
287 
288     WKView* wkView() const;
289 #endif
290 #if PLATFORM(WIN)
291     void didChangeCompositionSelection(bool);
292     void confirmComposition(const String&);
293     void setComposition(const String&, Vector<WebCore::CompositionUnderline>&, int);
294     WebCore::IntRect firstRectForCharacterInSelectedRange(int);
295     String getSelectedText();
296 
297     bool gestureWillBegin(const WebCore::IntPoint&);
298     void gestureDidScroll(const WebCore::IntSize&);
299     void gestureDidEnd();
300 
301     void setGestureReachedScrollingLimit(bool);
302 
303     HWND nativeWindow() const;
304 #endif
305 #if ENABLE(TILED_BACKING_STORE)
306     void setActualVisibleContentRect(const WebCore::IntRect& rect);
307 #endif
308 
309     void handleMouseEvent(const NativeWebMouseEvent&);
310     void handleWheelEvent(const NativeWebWheelEvent&);
311     void handleKeyboardEvent(const NativeWebKeyboardEvent&);
312 #if ENABLE(GESTURE_EVENTS)
313     void handleGestureEvent(const WebGestureEvent&);
314 #endif
315 #if ENABLE(TOUCH_EVENTS)
316     void handleTouchEvent(const WebTouchEvent&);
317 #endif
318 
319     void scrollBy(WebCore::ScrollDirection, WebCore::ScrollGranularity);
320 
321     String pageTitle() const;
toolTip()322     const String& toolTip() const { return m_toolTip; }
323 
324     void setUserAgent(const String&);
userAgent()325     const String& userAgent() const { return m_userAgent; }
326     void setApplicationNameForUserAgent(const String&);
applicationNameForUserAgent()327     const String& applicationNameForUserAgent() const { return m_applicationNameForUserAgent; }
328     void setCustomUserAgent(const String&);
customUserAgent()329     const String& customUserAgent() const { return m_customUserAgent; }
330 
331     bool supportsTextEncoding() const;
332     void setCustomTextEncodingName(const String&);
customTextEncodingName()333     String customTextEncodingName() const { return m_customTextEncodingName; }
334 
335     double estimatedProgress() const;
336 
337     void terminateProcess();
338 
339     typedef bool (*WebPageProxySessionStateFilterCallback)(WKPageRef, WKStringRef type, WKTypeRef object, void* context);
340     PassRefPtr<WebData> sessionStateData(WebPageProxySessionStateFilterCallback, void* context) const;
341     void restoreFromSessionStateData(WebData*);
342 
343     bool supportsTextZoom() const;
textZoomFactor()344     double textZoomFactor() const { return m_mainFrameHasCustomRepresentation ? 1 : m_textZoomFactor; }
345     void setTextZoomFactor(double);
346     double pageZoomFactor() const;
347     void setPageZoomFactor(double);
348     void setPageAndTextZoomFactors(double pageZoomFactor, double textZoomFactor);
349 
350     void scaleWebView(double scale, const WebCore::IntPoint& origin);
viewScaleFactor()351     double viewScaleFactor() const { return m_viewScaleFactor; }
352 
353     void setUseFixedLayout(bool);
354     void setFixedLayoutSize(const WebCore::IntSize&);
useFixedLayout()355     bool useFixedLayout() const { return m_useFixedLayout; };
fixedLayoutSize()356     const WebCore::IntSize& fixedLayoutSize() const { return m_fixedLayoutSize; };
357 
hasHorizontalScrollbar()358     bool hasHorizontalScrollbar() const { return m_mainFrameHasHorizontalScrollbar; }
hasVerticalScrollbar()359     bool hasVerticalScrollbar() const { return m_mainFrameHasVerticalScrollbar; }
360 
isPinnedToLeftSide()361     bool isPinnedToLeftSide() const { return m_mainFrameIsPinnedToLeftSide; }
isPinnedToRightSide()362     bool isPinnedToRightSide() const { return m_mainFrameIsPinnedToRightSide; }
363 
364 #if PLATFORM(MAC)
365     // Called by the web process through a message.
366     void registerWebProcessAccessibilityToken(const CoreIPC::DataReference&);
367     // Called by the UI process when it is ready to send its tokens to the web process.
368     void registerUIProcessAccessibilityTokens(const CoreIPC::DataReference& elemenToken, const CoreIPC::DataReference& windowToken);
369     bool writeSelectionToPasteboard(const String& pasteboardName, const Vector<String>& pasteboardTypes);
370     bool readSelectionFromPasteboard(const String& pasteboardName);
371 #endif
372 
373     void viewScaleFactorDidChange(double);
374 
375     void setMemoryCacheClientCallsEnabled(bool);
376 
377     // Find.
378     void findString(const String&, FindOptions, unsigned maxMatchCount);
379     void hideFindUI();
380     void countStringMatches(const String&, FindOptions, unsigned maxMatchCount);
381     void didCountStringMatches(const String&, uint32_t matchCount);
382     void setFindIndicator(const WebCore::FloatRect& selectionRectInWindowCoordinates, const Vector<WebCore::FloatRect>& textRectsInSelectionRectCoordinates, const ShareableBitmap::Handle& contentImageHandle, bool fadeOut);
383     void didFindString(const String&, uint32_t matchCount);
384     void didFailToFindString(const String&);
385 
386     void getContentsAsString(PassRefPtr<StringCallback>);
387     void getMainResourceDataOfFrame(WebFrameProxy*, PassRefPtr<DataCallback>);
388     void getResourceDataFromFrame(WebFrameProxy*, WebURL*, PassRefPtr<DataCallback>);
389     void getRenderTreeExternalRepresentation(PassRefPtr<StringCallback>);
390     void getSelectionOrContentsAsString(PassRefPtr<StringCallback>);
391     void getSourceForFrame(WebFrameProxy*, PassRefPtr<StringCallback>);
392     void getWebArchiveOfFrame(WebFrameProxy*, PassRefPtr<DataCallback>);
393     void runJavaScriptInMainFrame(const String&, PassRefPtr<ScriptValueCallback>);
394     void forceRepaint(PassRefPtr<VoidCallback>);
395 
396     float headerHeight(WebFrameProxy*);
397     float footerHeight(WebFrameProxy*);
398     void drawHeader(WebFrameProxy*, const WebCore::FloatRect&);
399     void drawFooter(WebFrameProxy*, const WebCore::FloatRect&);
400 
401 #if PLATFORM(MAC)
402     // Dictionary.
403     void performDictionaryLookupAtLocation(const WebCore::FloatPoint&);
404 #endif
405 
406     void receivedPolicyDecision(WebCore::PolicyAction, WebFrameProxy*, uint64_t listenerID);
407 
408     void backForwardRemovedItem(uint64_t itemID);
409 
410     // Drag and drop support.
411     void dragEntered(WebCore::DragData*, const String& dragStorageName = String());
412     void dragUpdated(WebCore::DragData*, const String& dragStorageName = String());
413     void dragExited(WebCore::DragData*, const String& dragStorageName = String());
414     void performDrag(WebCore::DragData*, const String& dragStorageName, const SandboxExtension::Handle&);
415 
416     void didPerformDragControllerAction(uint64_t resultOperation);
417     void dragEnded(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition, uint64_t operation);
418 #if PLATFORM(MAC)
419     void setDragImage(const WebCore::IntPoint& clientPosition, const ShareableBitmap::Handle& dragImageHandle, bool isLinkDrag);
420 #endif
421 #if PLATFORM(WIN)
422     void startDragDrop(const WebCore::IntPoint& imagePoint, const WebCore::IntPoint& dragPoint, uint64_t okEffect, const HashMap<UINT, Vector<String> >& dataMap, const WebCore::IntSize& dragImageSize, const SharedMemory::Handle& dragImageHandle, bool isLinkDrag);
423 #endif
424     void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
425     void didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, CoreIPC::ArgumentEncoder*);
426 
427     void processDidBecomeUnresponsive();
428     void processDidBecomeResponsive();
429     void processDidCrash();
430 
431 #if USE(ACCELERATED_COMPOSITING)
432     virtual void enterAcceleratedCompositingMode(const LayerTreeContext&);
433     virtual void exitAcceleratedCompositingMode();
434 #endif
435 
436     void didDraw();
437 
438     enum UndoOrRedo { Undo, Redo };
439     void addEditCommand(WebEditCommandProxy*);
440     void removeEditCommand(WebEditCommandProxy*);
441     bool isValidEditCommand(WebEditCommandProxy*);
442     void registerEditCommand(PassRefPtr<WebEditCommandProxy>, UndoOrRedo);
443 
444     WebProcessProxy* process() const;
445 
pageGroup()446     WebPageGroup* pageGroup() const { return m_pageGroup.get(); }
447 
448     bool isValid();
449 
dragOperation()450     WebCore::DragOperation dragOperation() { return m_currentDragOperation; }
resetDragOperation()451     void resetDragOperation() { m_currentDragOperation = WebCore::DragOperationNone; }
452 
453     void preferencesDidChange();
454 
455 #if ENABLE(TILED_BACKING_STORE)
456     void setResizesToContentsUsingLayoutSize(const WebCore::IntSize&);
457 #endif
458 
459     // Called by the WebContextMenuProxy.
460     void contextMenuItemSelected(const WebContextMenuItemData&);
461 
462     // Called by the WebOpenPanelResultListenerProxy.
463     void didChooseFilesForOpenPanel(const Vector<String>&);
464     void didCancelForOpenPanel();
465 
466     WebPageCreationParameters creationParameters() const;
467 
468 #if PLATFORM(QT)
469     void findZoomableAreaForPoint(const WebCore::IntPoint&);
470 #endif
471 
472     void advanceToNextMisspelling(bool startBeforeSelection) const;
473     void changeSpellingToWord(const String& word) const;
474 #if PLATFORM(MAC)
475     void uppercaseWord();
476     void lowercaseWord();
477     void capitalizeWord();
478 
isSmartInsertDeleteEnabled()479     bool isSmartInsertDeleteEnabled() const { return m_isSmartInsertDeleteEnabled; }
480     void setSmartInsertDeleteEnabled(bool);
481 #endif
482 
483     void beginPrinting(WebFrameProxy*, const PrintInfo&);
484     void endPrinting();
485     void computePagesForPrinting(WebFrameProxy*, const PrintInfo&, PassRefPtr<ComputedPagesCallback>);
486 #if PLATFORM(MAC) || PLATFORM(WIN)
487     void drawRectToPDF(WebFrameProxy*, const WebCore::IntRect&, PassRefPtr<DataCallback>);
488     void drawPagesToPDF(WebFrameProxy*, uint32_t first, uint32_t count, PassRefPtr<DataCallback>);
489 #endif
490 
pendingAPIRequestURL()491     const String& pendingAPIRequestURL() const { return m_pendingAPIRequestURL; }
492 
493     void flashBackingStoreUpdates(const Vector<WebCore::IntRect>& updateRects);
494 
495 #if PLATFORM(MAC)
496     void handleCorrectionPanelResult(const String& result);
497 #endif
498 
setDebugPaintFlags(WKPageDebugPaintFlags flags)499     static void setDebugPaintFlags(WKPageDebugPaintFlags flags) { s_debugPaintFlags = flags; }
debugPaintFlags()500     static WKPageDebugPaintFlags debugPaintFlags() { return s_debugPaintFlags; }
501 
502     // Color to be used with kWKDebugFlashViewUpdates.
503     static WebCore::Color viewUpdatesFlashColor();
504 
505     // Color to be used with kWKDebugFlashBackingStoreUpdates.
506     static WebCore::Color backingStoreUpdatesFlashColor();
507 
508     void saveDataToFileInDownloadsFolder(const String& suggestedFilename, const String& mimeType, const String& originatingURLString, WebData*);
509 
510     void linkClicked(const String&, const WebMouseEvent&);
511 
visibleScrollerThumbRect()512     WebCore::IntRect visibleScrollerThumbRect() const { return m_visibleScrollerThumbRect; }
513 
514     // FIXME: This is in violation of the no synchronous messages to the Web Process policy and
515     // should be removed as soon as possible.
516     PassRefPtr<WebImage> createSnapshotOfVisibleContent();
517 
518 private:
519     WebPageProxy(PageClient*, PassRefPtr<WebProcessProxy>, WebPageGroup*, uint64_t pageID);
520 
type()521     virtual Type type() const { return APIType; }
522 
523     // WebPopupMenuProxy::Client
524     virtual void valueChangedForPopupMenu(WebPopupMenuProxy*, int32_t newSelectedIndex);
525     virtual void setTextFromItemForPopupMenu(WebPopupMenuProxy*, int32_t index);
526     virtual NativeWebMouseEvent* currentlyProcessedMouseDownEvent();
527 
528     // Implemented in generated WebPageProxyMessageReceiver.cpp
529     void didReceiveWebPageProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
530     CoreIPC::SyncReplyMode didReceiveSyncWebPageProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, CoreIPC::ArgumentEncoder*);
531 
532     void didCreateMainFrame(uint64_t frameID);
533     void didCreateSubframe(uint64_t frameID, uint64_t parentFrameID);
534     void didSaveFrameToPageCache(uint64_t frameID);
535     void didRestoreFrameFromPageCache(uint64_t frameID, uint64_t parentFrameID);
536 
537     void didStartProvisionalLoadForFrame(uint64_t frameID, const String& url, const String& unreachableURL, CoreIPC::ArgumentDecoder*);
538     void didReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, const String&, CoreIPC::ArgumentDecoder*);
539     void didFailProvisionalLoadForFrame(uint64_t frameID, const WebCore::ResourceError&, CoreIPC::ArgumentDecoder*);
540     void didCommitLoadForFrame(uint64_t frameID, const String& mimeType, bool frameHasCustomRepresentation, const PlatformCertificateInfo&, CoreIPC::ArgumentDecoder*);
541     void didFinishDocumentLoadForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder*);
542     void didFinishLoadForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder*);
543     void didFailLoadForFrame(uint64_t frameID, const WebCore::ResourceError&, CoreIPC::ArgumentDecoder*);
544     void didSameDocumentNavigationForFrame(uint64_t frameID, uint32_t sameDocumentNavigationType, const String&, CoreIPC::ArgumentDecoder*);
545     void didReceiveTitleForFrame(uint64_t frameID, const String&, CoreIPC::ArgumentDecoder*);
546     void didFirstLayoutForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder*);
547     void didFirstVisuallyNonEmptyLayoutForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder*);
548     void didRemoveFrameFromHierarchy(uint64_t frameID, CoreIPC::ArgumentDecoder*);
549     void didDisplayInsecureContentForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder*);
550     void didRunInsecureContentForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder*);
551     void frameDidBecomeFrameSet(uint64_t frameID, bool);
552     void didStartProgress();
553     void didChangeProgress(double);
554     void didFinishProgress();
555 
556     void decidePolicyForNavigationAction(uint64_t frameID, uint32_t navigationType, uint32_t modifiers, int32_t mouseButton, const WebCore::ResourceRequest&, uint64_t listenerID, CoreIPC::ArgumentDecoder*, bool& receivedPolicyAction, uint64_t& policyAction, uint64_t& downloadID);
557     void decidePolicyForNewWindowAction(uint64_t frameID, uint32_t navigationType, uint32_t modifiers, int32_t mouseButton, const WebCore::ResourceRequest&, const String& frameName, uint64_t listenerID, CoreIPC::ArgumentDecoder*);
558     void decidePolicyForResponse(uint64_t frameID, const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, uint64_t listenerID, CoreIPC::ArgumentDecoder* arguments, bool& receivedPolicyAction, uint64_t& policyAction, uint64_t& downloadID);
559     void unableToImplementPolicy(uint64_t frameID, const WebCore::ResourceError&, CoreIPC::ArgumentDecoder* arguments);
560 
561     void willSubmitForm(uint64_t frameID, uint64_t sourceFrameID, const StringPairVector& textFieldValues, uint64_t listenerID, CoreIPC::ArgumentDecoder*);
562 
563     // Resource load client
564     void didInitiateLoadForResource(uint64_t frameID, uint64_t resourceIdentifier, const WebCore::ResourceRequest&, bool pageIsProvisionallyLoading);
565     void didSendRequestForResource(uint64_t frameID, uint64_t resourceIdentifier, const WebCore::ResourceRequest&, const WebCore::ResourceResponse& redirectResponse);
566     void didReceiveResponseForResource(uint64_t frameID, uint64_t resourceIdentifier, const WebCore::ResourceResponse&);
567     void didReceiveContentLengthForResource(uint64_t frameID, uint64_t resourceIdentifier, uint64_t contentLength);
568     void didFinishLoadForResource(uint64_t frameID, uint64_t resourceIdentifier);
569     void didFailLoadForResource(uint64_t frameID, uint64_t resourceIdentifier, const WebCore::ResourceError&);
570 
571     // UI client
572     void createNewPage(const WebCore::WindowFeatures&, uint32_t modifiers, int32_t mouseButton, uint64_t& newPageID, WebPageCreationParameters&);
573     void showPage();
574     void closePage();
575     void runJavaScriptAlert(uint64_t frameID, const String&);
576     void runJavaScriptConfirm(uint64_t frameID, const String&, bool& result);
577     void runJavaScriptPrompt(uint64_t frameID, const String&, const String&, String& result);
578     void shouldInterruptJavaScript(bool& result);
579     void setStatusText(const String&);
580     void mouseDidMoveOverElement(uint32_t modifiers, CoreIPC::ArgumentDecoder*);
581     void missingPluginButtonClicked(const String& mimeType, const String& url, const String& pluginsPageURL);
582     void setToolbarsAreVisible(bool toolbarsAreVisible);
583     void getToolbarsAreVisible(bool& toolbarsAreVisible);
584     void setMenuBarIsVisible(bool menuBarIsVisible);
585     void getMenuBarIsVisible(bool& menuBarIsVisible);
586     void setStatusBarIsVisible(bool statusBarIsVisible);
587     void getStatusBarIsVisible(bool& statusBarIsVisible);
588     void setIsResizable(bool isResizable);
589     void getIsResizable(bool& isResizable);
590     void setWindowFrame(const WebCore::FloatRect&);
591     void getWindowFrame(WebCore::FloatRect&);
592     void windowToScreen(const WebCore::IntRect& viewRect, WebCore::IntRect& result);
593     void runBeforeUnloadConfirmPanel(const String& message, uint64_t frameID, bool& shouldClose);
594     void didChangeViewportData(const WebCore::ViewportArguments&);
595     void pageDidScroll();
596     void runOpenPanel(uint64_t frameID, const WebOpenPanelParameters::Data&);
597     void printFrame(uint64_t frameID);
598     void exceededDatabaseQuota(uint64_t frameID, const String& originIdentifier, const String& databaseName, const String& displayName, uint64_t currentQuota, uint64_t currentUsage, uint64_t expectedUsage, uint64_t& newQuota);
599     void requestGeolocationPermissionForFrame(uint64_t geolocationID, uint64_t frameID, String originIdentifier);
runModal()600     void runModal() { m_uiClient.runModal(this); }
601     void didCompleteRubberBandForMainFrame(const WebCore::IntSize&);
602     void notifyScrollerThumbIsVisibleInRect(const WebCore::IntRect&);
603     void didChangeScrollbarsForMainFrame(bool hasHorizontalScrollbar, bool hasVerticalScrollbar);
604     void didChangeScrollOffsetPinningForMainFrame(bool pinnedToLeftSide, bool pinnedToRightSide);
605     void didFailToInitializePlugin(const String& mimeType);
606 
607     void reattachToWebProcess();
608     void reattachToWebProcessWithItem(WebBackForwardListItem*);
609 
610 #if ENABLE(TILED_BACKING_STORE)
611     void pageDidRequestScroll(const WebCore::IntPoint&);
612 #endif
613 
614 #if PLATFORM(QT)
615     void didChangeContentsSize(const WebCore::IntSize&);
616     void didFindZoomableArea(const WebCore::IntRect&);
617 #endif
618 
619     void editorStateChanged(const EditorState&);
620 
621     // Back/Forward list management
622     void backForwardAddItem(uint64_t itemID);
623     void backForwardGoToItem(uint64_t itemID);
624     void backForwardItemAtIndex(int32_t index, uint64_t& itemID);
625     void backForwardBackListCount(int32_t& count);
626     void backForwardForwardListCount(int32_t& count);
627     void backForwardClear();
628 
629     // Undo management
630     void registerEditCommandForUndo(uint64_t commandID, uint32_t editAction);
631     void clearAllEditCommands();
632     void canUndoRedo(uint32_t action, bool& result);
633     void executeUndoRedo(uint32_t action, bool& result);
634 
635     // Keyboard handling
636 #if PLATFORM(MAC)
637     void interpretQueuedKeyEvent(const EditorState&, bool& handled, Vector<WebCore::KeypressCommand>&);
638     void executeSavedCommandBySelector(const String& selector, bool& handled);
639 #endif
640 
641 #if PLATFORM(GTK)
642     void getEditorCommandsForKeyEvent(Vector<String>&);
643 #endif
644 
645     // Popup Menu.
646     void showPopupMenu(const WebCore::IntRect& rect, uint64_t textDirection, const Vector<WebPopupItem>& items, int32_t selectedIndex, const PlatformPopupMenuData&);
647     void hidePopupMenu();
648 #if PLATFORM(WIN)
649     void setPopupMenuSelectedIndex(int32_t);
650 #endif
651 
652     // Context Menu.
653     void showContextMenu(const WebCore::IntPoint& menuLocation, const ContextMenuState&, const Vector<WebContextMenuItemData>&, CoreIPC::ArgumentDecoder*);
654     void internalShowContextMenu(const WebCore::IntPoint& menuLocation, const ContextMenuState&, const Vector<WebContextMenuItemData>&, CoreIPC::ArgumentDecoder*);
655 
656     // Search popup results
657     void saveRecentSearches(const String&, const Vector<String>&);
658     void loadRecentSearches(const String&, Vector<String>&);
659 
660 #if PLATFORM(MAC)
661     // Speech.
662     void getIsSpeaking(bool&);
663     void speak(const String&);
664     void stopSpeaking();
665 
666     // Spotlight.
667     void searchWithSpotlight(const String&);
668 
669     // Dictionary.
670     void didPerformDictionaryLookup(const String&, const DictionaryPopupInfo&);
671 #endif
672 
673     // Spelling and grammar.
674     int64_t spellDocumentTag();
675 #if USE(UNIFIED_TEXT_CHECKING)
676     void checkTextOfParagraph(const String& text, uint64_t checkingTypes, Vector<WebCore::TextCheckingResult>& results);
677 #endif
678     void checkSpellingOfString(const String& text, int32_t& misspellingLocation, int32_t& misspellingLength);
679     void checkGrammarOfString(const String& text, Vector<WebCore::GrammarDetail>&, int32_t& badGrammarLocation, int32_t& badGrammarLength);
680     void spellingUIIsShowing(bool&);
681     void updateSpellingUIWithMisspelledWord(const String& misspelledWord);
682     void updateSpellingUIWithGrammarString(const String& badGrammarPhrase, const WebCore::GrammarDetail&);
683     void getGuessesForWord(const String& word, const String& context, Vector<String>& guesses);
684     void learnWord(const String& word);
685     void ignoreWord(const String& word);
686 
687     void setFocus(bool focused);
688     void takeFocus(uint32_t direction);
689     void setToolTip(const String&);
690     void setCursor(const WebCore::Cursor&);
691 
692     void didReceiveEvent(uint32_t opaqueType, bool handled);
693     void stopResponsivenessTimer();
694 
695 #if PLATFORM(WIN)
696     void wheelEventNotHandled(NativeWebWheelEvent&) const;
697 #endif
698 
699     void voidCallback(uint64_t);
700     void dataCallback(const CoreIPC::DataReference&, uint64_t);
701     void stringCallback(const String&, uint64_t);
702     void scriptValueCallback(const CoreIPC::DataReference&, uint64_t);
703     void computedPagesCallback(const Vector<WebCore::IntRect>&, double totalScaleFactorForPrinting, uint64_t);
704     void validateCommandCallback(const String&, bool, int, uint64_t);
705 
706     void focusedFrameChanged(uint64_t frameID);
707     void frameSetLargestFrameChanged(uint64_t frameID);
708 
709     void canAuthenticateAgainstProtectionSpaceInFrame(uint64_t frameID, const WebCore::ProtectionSpace&, bool& canAuthenticate);
710     void didReceiveAuthenticationChallenge(uint64_t frameID, const WebCore::AuthenticationChallenge&, uint64_t challengeID);
711 
712     void didFinishLoadingDataForCustomRepresentation(const String& suggestedFilename, const CoreIPC::DataReference&);
713 
714 #if PLATFORM(MAC)
715     void setComplexTextInputEnabled(uint64_t pluginComplexTextInputIdentifier, bool complexTextInputEnabled);
716 #endif
717 
718     static String standardUserAgent(const String& applicationName = String());
719 
clearPendingAPIRequestURL()720     void clearPendingAPIRequestURL() { m_pendingAPIRequestURL = String(); }
setPendingAPIRequestURL(const String & pendingAPIRequestURL)721     void setPendingAPIRequestURL(const String& pendingAPIRequestURL) { m_pendingAPIRequestURL = pendingAPIRequestURL; }
722 
723     void initializeSandboxExtensionHandle(const WebCore::KURL&, SandboxExtension::Handle&);
724 
725 #if PLATFORM(MAC)
726     void substitutionsPanelIsShowing(bool&);
727 #if !defined(BUILDING_ON_SNOW_LEOPARD)
728     void showCorrectionPanel(int32_t panelType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings);
729     void dismissCorrectionPanel(int32_t reason);
730     void dismissCorrectionPanelSoon(int32_t reason, String& result);
731     void recordAutocorrectionResponse(int32_t responseType, const String& replacedString, const String& replacementString);
732 #endif // !defined(BUILDING_ON_SNOW_LEOPARD)
733 #endif // PLATFORM(MAC)
734 
735     void clearLoadDependentCallbacks();
736 
737     void performDragControllerAction(DragControllerAction, WebCore::DragData*, const String& dragStorageName, const SandboxExtension::Handle&);
738 
739     void updateBackingStoreDiscardableState();
740 
741 #if PLATFORM(WIN)
742     void scheduleChildWindowGeometryUpdate(uint64_t window, const WebCore::IntRect& rectInParentClientCoordinates, const WebCore::IntRect& clipRectInChildClientCoordinates);
743 #endif
744 
745     PageClient* m_pageClient;
746     WebLoaderClient m_loaderClient;
747     WebPolicyClient m_policyClient;
748     WebFormClient m_formClient;
749     WebResourceLoadClient m_resourceLoadClient;
750     WebUIClient m_uiClient;
751     WebFindClient m_findClient;
752     WebPageContextMenuClient m_contextMenuClient;
753 
754     OwnPtr<DrawingAreaProxy> m_drawingArea;
755     RefPtr<WebProcessProxy> m_process;
756     RefPtr<WebPageGroup> m_pageGroup;
757     RefPtr<WebFrameProxy> m_mainFrame;
758     RefPtr<WebFrameProxy> m_focusedFrame;
759     RefPtr<WebFrameProxy> m_frameSetLargestFrame;
760 
761     String m_userAgent;
762     String m_applicationNameForUserAgent;
763     String m_customUserAgent;
764     String m_customTextEncodingName;
765 
766 #if ENABLE(INSPECTOR)
767     RefPtr<WebInspectorProxy> m_inspector;
768 #endif
769 
770 #if ENABLE(FULLSCREEN_API)
771     RefPtr<WebFullScreenManagerProxy> m_fullScreenManager;
772 #endif
773 
774     HashMap<uint64_t, RefPtr<VoidCallback> > m_voidCallbacks;
775     HashMap<uint64_t, RefPtr<DataCallback> > m_dataCallbacks;
776     HashMap<uint64_t, RefPtr<StringCallback> > m_stringCallbacks;
777     HashSet<uint64_t> m_loadDependentStringCallbackIDs;
778     HashMap<uint64_t, RefPtr<ScriptValueCallback> > m_scriptValueCallbacks;
779     HashMap<uint64_t, RefPtr<ComputedPagesCallback> > m_computedPagesCallbacks;
780     HashMap<uint64_t, RefPtr<ValidateCommandCallback> > m_validateCommandCallbacks;
781 
782     HashSet<WebEditCommandProxy*> m_editCommandSet;
783 
784     RefPtr<WebPopupMenuProxy> m_activePopupMenu;
785     RefPtr<WebContextMenuProxy> m_activeContextMenu;
786     ContextMenuState m_activeContextMenuState;
787     RefPtr<WebOpenPanelResultListenerProxy> m_openPanelResultListener;
788     GeolocationPermissionRequestManagerProxy m_geolocationPermissionRequestManager;
789 
790     double m_estimatedProgress;
791 
792     // Whether the web page is contained in a top-level window.
793     bool m_isInWindow;
794 
795     // Whether the page is visible; if the backing view is visible and inserted into a window.
796     bool m_isVisible;
797 
798     bool m_canGoBack;
799     bool m_canGoForward;
800     RefPtr<WebBackForwardList> m_backForwardList;
801 
802     bool m_maintainsInactiveSelection;
803 
804     String m_toolTip;
805 
806     EditorState m_editorState;
807 
808     double m_textZoomFactor;
809     double m_pageZoomFactor;
810     double m_viewScaleFactor;
811 
812     bool m_drawsBackground;
813     bool m_drawsTransparentBackground;
814 
815     bool m_areMemoryCacheClientCallsEnabled;
816 
817     bool m_useFixedLayout;
818     WebCore::IntSize m_fixedLayoutSize;
819 
820     // If the process backing the web page is alive and kicking.
821     bool m_isValid;
822 
823     // Whether WebPageProxy::close() has been called on this page.
824     bool m_isClosed;
825 
826     bool m_isInPrintingMode;
827     bool m_isPerformingDOMPrintOperation;
828 
829     bool m_inDecidePolicyForMIMEType;
830     bool m_syncMimeTypePolicyActionIsValid;
831     WebCore::PolicyAction m_syncMimeTypePolicyAction;
832     uint64_t m_syncMimeTypePolicyDownloadID;
833 
834     bool m_inDecidePolicyForNavigationAction;
835     bool m_syncNavigationActionPolicyActionIsValid;
836     WebCore::PolicyAction m_syncNavigationActionPolicyAction;
837     uint64_t m_syncNavigationActionPolicyDownloadID;
838 
839     Deque<NativeWebKeyboardEvent> m_keyEventQueue;
840     bool m_processingWheelEvent;
841     OwnPtr<NativeWebWheelEvent> m_currentlyProcessedWheelEvent;
842     OwnPtr<NativeWebWheelEvent> m_nextWheelEvent;
843 
844     bool m_processingMouseMoveEvent;
845     OwnPtr<NativeWebMouseEvent> m_nextMouseMoveEvent;
846     OwnPtr<NativeWebMouseEvent> m_currentlyProcessedMouseDownEvent;
847 
848     uint64_t m_pageID;
849 
850 #if PLATFORM(MAC)
851     bool m_isSmartInsertDeleteEnabled;
852 #endif
853 
854     int64_t m_spellDocumentTag;
855     bool m_hasSpellDocumentTag;
856     unsigned m_pendingLearnOrIgnoreWordMessageCount;
857 
858     bool m_mainFrameHasCustomRepresentation;
859     WebCore::DragOperation m_currentDragOperation;
860 
861     String m_pendingAPIRequestURL;
862 
863     bool m_mainFrameHasHorizontalScrollbar;
864     bool m_mainFrameHasVerticalScrollbar;
865 
866     bool m_mainFrameIsPinnedToLeftSide;
867     bool m_mainFrameIsPinnedToRightSide;
868 
869     WebCore::IntRect m_visibleScrollerThumbRect;
870 
871     static WKPageDebugPaintFlags s_debugPaintFlags;
872 };
873 
874 } // namespace WebKit
875 
876 #endif // WebPageProxy_h
877