21ca44268728dc936c6c2dfb70ee97d446490cdb
[WebKit-https.git] / Source / WebKit2 / WebProcess / WebPage / WebPage.h
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 WebPage_h
27 #define WebPage_h
28
29 #include "APIObject.h"
30 #include "DrawingArea.h"
31 #include "FindController.h"
32 #include "GeolocationPermissionRequestManager.h"
33 #include "ImageOptions.h"
34 #include "InjectedBundlePageContextMenuClient.h"
35 #include "InjectedBundlePageEditorClient.h"
36 #include "InjectedBundlePageFormClient.h"
37 #include "InjectedBundlePageLoaderClient.h"
38 #include "InjectedBundlePageUIClient.h"
39 #include "MessageSender.h"
40 #include "Plugin.h"
41 #include "SandboxExtension.h"
42 #include "WebEditCommand.h"
43 #include <WebCore/Editor.h>
44 #include <WebCore/FrameLoaderTypes.h>
45 #include <WebCore/IntRect.h>
46 #include <wtf/HashMap.h>
47 #include <wtf/OwnPtr.h>
48 #include <wtf/PassRefPtr.h>
49 #include <wtf/RefPtr.h>
50 #include <wtf/text/WTFString.h>
51
52 #if ENABLE(TOUCH_EVENTS)
53 #include <WebCore/PlatformTouchEvent.h>
54 #endif
55
56 #if PLATFORM(MAC)
57 #include <wtf/RetainPtr.h>
58 #ifdef __OBJC__
59 @class AccessibilityWebPageObject;
60 #else
61 class AccessibilityWebPageObject;
62 #endif
63 #endif
64
65 namespace CoreIPC {
66     class ArgumentDecoder;
67     class Connection;
68     class MessageID;
69 }
70
71 namespace WebCore {
72     class GraphicsContext;
73     class KeyboardEvent;
74     class Page;
75     class ResourceRequest;
76     class SharedBuffer;
77 }
78
79 namespace WebKit {
80
81 class DrawingArea;
82 class InjectedBundleBackForwardList;
83 class PageOverlay;
84 class PluginView;
85 class SessionState;
86 class WebContextMenu;
87 class WebContextMenuItemData;
88 class WebEvent;
89 class WebFrame;
90 class WebImage;
91 class WebInspector;
92 class WebKeyboardEvent;
93 class WebMouseEvent;
94 class WebOpenPanelResultListener;
95 class WebPageGroupProxy;
96 class WebPopupMenu;
97 class WebWheelEvent;
98
99 struct WebPageCreationParameters;
100 struct WebPreferencesStore;
101
102 #if ENABLE(TOUCH_EVENTS)
103 class WebTouchEvent;
104 #endif
105
106 class WebPage : public APIObject, public CoreIPC::MessageSender<WebPage> {
107 public:
108     static const Type APIType = TypeBundlePage;
109
110     static PassRefPtr<WebPage> create(uint64_t pageID, const WebPageCreationParameters&);
111     virtual ~WebPage();
112
113     // Used by MessageSender.
114     CoreIPC::Connection* connection() const;
115     uint64_t destinationID() const { return pageID(); }
116
117     void close();
118
119     WebCore::Page* corePage() const { return m_page.get(); }
120     uint64_t pageID() const { return m_pageID; }
121
122     void setSize(const WebCore::IntSize&);
123     const WebCore::IntSize& size() const { return m_viewSize; }
124
125     InjectedBundleBackForwardList* backForwardList();
126     DrawingArea* drawingArea() const { return m_drawingArea.get(); }
127
128     WebPageGroupProxy* pageGroup() const { return m_pageGroup.get(); }
129
130 #if ENABLE(INSPECTOR)
131     WebInspector* inspector();
132 #endif
133
134     // -- Called by the DrawingArea.
135     // FIXME: We could genericize these into a DrawingArea client interface. Would that be beneficial?
136     void drawRect(WebCore::GraphicsContext&, const WebCore::IntRect&);
137     void layoutIfNeeded();
138
139     // -- Called from WebCore clients.
140 #if !PLATFORM(MAC)
141     bool handleEditingKeyboardEvent(WebCore::KeyboardEvent*);
142 #endif
143     void show();
144     String userAgent() const { return m_userAgent; }
145     WebCore::IntRect windowResizerRect() const;
146     bool tabsToLinks() const { return m_tabToLinks; }
147
148     WebEditCommand* webEditCommand(uint64_t);
149     void addWebEditCommand(uint64_t, WebEditCommand*);
150     void removeWebEditCommand(uint64_t);
151     bool isInRedo() const { return m_isInRedo; }
152
153     void setActivePopupMenu(WebPopupMenu*);
154     
155     WebOpenPanelResultListener* activeOpenPanelResultListener() const { return m_activeOpenPanelResultListener.get(); }
156     void setActiveOpenPanelResultListener(PassRefPtr<WebOpenPanelResultListener>);
157
158     // -- Called from WebProcess.
159     void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
160     CoreIPC::SyncReplyMode didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, CoreIPC::ArgumentEncoder*);
161
162     // -- InjectedBundle methods
163     void initializeInjectedBundleContextMenuClient(WKBundlePageContextMenuClient*);
164     void initializeInjectedBundleEditorClient(WKBundlePageEditorClient*);
165     void initializeInjectedBundleFormClient(WKBundlePageFormClient*);
166     void initializeInjectedBundleLoaderClient(WKBundlePageLoaderClient*);
167     void initializeInjectedBundleUIClient(WKBundlePageUIClient*);
168
169     InjectedBundlePageContextMenuClient& injectedBundleContextMenuClient() { return m_contextMenuClient; }
170     InjectedBundlePageEditorClient& injectedBundleEditorClient() { return m_editorClient; }
171     InjectedBundlePageFormClient& injectedBundleFormClient() { return m_formClient; }
172     InjectedBundlePageLoaderClient& injectedBundleLoaderClient() { return m_loaderClient; }
173     InjectedBundlePageUIClient& injectedBundleUIClient() { return m_uiClient; }
174
175     bool findStringFromInjectedBundle(const String&, FindOptions);
176
177     WebFrame* mainFrame() const { return m_mainFrame.get(); }
178     PassRefPtr<Plugin> createPlugin(const Plugin::Parameters&);
179
180     String renderTreeExternalRepresentation() const;
181     void executeEditingCommand(const String& commandName, const String& argument);
182     bool isEditingCommandEnabled(const String& commandName);
183     void clearMainFrameName();
184     void sendClose();
185
186     double textZoomFactor() const;
187     void setTextZoomFactor(double);
188     double pageZoomFactor() const;
189     void setPageZoomFactor(double);
190     void setPageAndTextZoomFactors(double pageZoomFactor, double textZoomFactor);
191
192     void scaleWebView(double scale, const WebCore::IntPoint& origin);
193     double viewScaleFactor() const;
194
195     void setUseFixedLayout(bool);
196     void setFixedLayoutSize(const WebCore::IntSize&);
197
198     bool drawsBackground() const { return m_drawsBackground; }
199     bool drawsTransparentBackground() const { return m_drawsTransparentBackground; }
200
201     void stopLoading();
202     void setDefersLoading(bool deferLoading);
203
204 #if USE(ACCELERATED_COMPOSITING)
205     void changeAcceleratedCompositingMode(WebCore::GraphicsLayer*);
206     void enterAcceleratedCompositingMode(WebCore::GraphicsLayer*);
207     void exitAcceleratedCompositingMode();
208 #endif
209
210 #if PLATFORM(MAC)
211     void addPluginView(PluginView*);
212     void removePluginView(PluginView*);
213
214     bool windowIsVisible() const { return m_windowIsVisible; }
215     const WebCore::IntRect& windowFrameInScreenCoordinates() const { return m_windowFrameInScreenCoordinates; }
216     const WebCore::IntRect& viewFrameInWindowCoordinates() const { return m_viewFrameInWindowCoordinates; }
217     bool windowIsFocused() const;
218     bool interceptEditingKeyboardEvent(WebCore::KeyboardEvent*, bool);
219 #elif PLATFORM(WIN)
220     HWND nativeWindow() const { return m_nativeWindow; }
221 #endif
222
223     void installPageOverlay(PassRefPtr<PageOverlay>);
224     void uninstallPageOverlay(PageOverlay*);
225
226     PassRefPtr<WebImage> snapshotInViewCoordinates(const WebCore::IntRect&, ImageOptions);
227     PassRefPtr<WebImage> snapshotInDocumentCoordinates(const WebCore::IntRect&, ImageOptions);
228
229     static const WebEvent* currentEvent();
230
231     FindController& findController() { return m_findController; }
232     GeolocationPermissionRequestManager& geolocationPermissionRequestManager() { return m_geolocationPermissionRequestManager; }
233
234     void pageDidScroll();
235 #if ENABLE(TILED_BACKING_STORE)
236     void pageDidRequestScroll(const WebCore::IntSize& delta);
237     void setActualVisibleContentRect(const WebCore::IntRect&);
238
239     bool resizesToContentsEnabled() const { return !m_resizesToContentsLayoutSize.isEmpty(); }
240     WebCore::IntSize resizesToContentsLayoutSize() const { return m_resizesToContentsLayoutSize; }
241     void setResizesToContentsUsingLayoutSize(const WebCore::IntSize& targetLayoutSize);
242     void resizeToContentsIfNeeded();
243 #endif
244
245     WebContextMenu* contextMenu();
246     
247     bool hasLocalDataForURL(const WebCore::KURL&);
248     
249     static bool canHandleRequest(const WebCore::ResourceRequest&);
250
251     class SandboxExtensionTracker {
252     public:
253         ~SandboxExtensionTracker();
254
255         void invalidate();
256
257         void beginLoad(WebFrame*, const SandboxExtension::Handle& handle);
258         void didStartProvisionalLoad(WebFrame*);
259         void didCommitProvisionalLoad(WebFrame*);
260         void didFailProvisionalLoad(WebFrame*);
261     private:
262         RefPtr<SandboxExtension> m_pendingProvisionalSandboxExtension;
263         RefPtr<SandboxExtension> m_provisionalSandboxExtension;
264         RefPtr<SandboxExtension> m_committedSandboxExtension;
265     };
266
267     SandboxExtensionTracker& sandboxExtensionTracker() { return m_sandboxExtensionTracker; }
268
269     static void getLocationAndLengthFromRange(WebCore::Range*, uint64_t& location, uint64_t& length);
270
271 #if PLATFORM(MAC)
272     void sendAccessibilityPresenterToken(const CoreIPC::DataReference&);
273     AccessibilityWebPageObject* accessibilityRemoteObject();
274     WebCore::IntPoint accessibilityPosition() const { return m_accessibilityPosition; }    
275     
276     void sendComplexTextInputToPlugin(uint64_t pluginComplexTextInputIdentifier, const String& textInput);
277
278     void getMarkedRange(uint64_t& location, uint64_t& length);
279     void characterIndexForPoint(const WebCore::IntPoint point, uint64_t& result);
280     void firstRectForCharacterRange(uint64_t location, uint64_t length, WebCore::IntRect& resultRect);
281 #elif PLATFORM(WIN)
282     void confirmComposition(const String& compositionString);
283     void setComposition(const WTF::String& compositionString, const WTF::Vector<WebCore::CompositionUnderline>& underlines, uint64_t cursorPosition);
284     void firstRectForCharacterInSelectedRange(const uint64_t characterPosition, WebCore::IntRect& resultRect);
285     void getSelectedText(WTF::String&);
286 #endif
287
288     // FIXME: This a dummy message, to avoid breaking the build for platforms that don't require
289     // any synchronous messages, and should be removed when <rdar://problem/8775115> is fixed.
290     void dummy(bool&);
291
292 #if PLATFORM(MAC)
293     bool isSpeaking();
294     void speak(const String&);
295     void stopSpeaking();
296
297     bool isSmartInsertDeleteEnabled() const { return m_isSmartInsertDeleteEnabled; }
298 #endif
299
300     void replaceSelectionWithText(WebCore::Frame*, const String&);
301     void performDragControllerAction(uint64_t action, WebCore::IntPoint clientPosition, WebCore::IntPoint globalPosition, uint64_t draggingSourceOperationMask, const WTF::String& dragStorageName, uint32_t flags);
302
303     bool mainFrameHasCustomRepresentation() const;
304
305 private:
306     WebPage(uint64_t pageID, const WebPageCreationParameters&);
307
308     virtual Type type() const { return APIType; }
309
310     void platformInitialize();
311
312     void didReceiveWebPageMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
313     CoreIPC::SyncReplyMode didReceiveSyncWebPageMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, CoreIPC::ArgumentEncoder*);
314
315     static const char* interpretKeyEvent(const WebCore::KeyboardEvent*);
316     bool performDefaultBehaviorForKeyEvent(const WebKeyboardEvent&);
317
318     String sourceForFrame(WebFrame*);
319
320     void loadData(PassRefPtr<WebCore::SharedBuffer>, const String& MIMEType, const String& encodingName, const WebCore::KURL& baseURL, const WebCore::KURL& failingURL);
321
322     bool platformHasLocalDataForURL(const WebCore::KURL&);
323
324     // Actions
325     void tryClose();
326     void loadURL(const String&, const SandboxExtension::Handle& sandboxExtensionHandle);
327     void loadURLRequest(const WebCore::ResourceRequest&, const SandboxExtension::Handle& sandboxExtensionHandle);
328     void loadHTMLString(const String& htmlString, const String& baseURL);
329     void loadAlternateHTMLString(const String& htmlString, const String& baseURL, const String& unreachableURL);
330     void loadPlainTextString(const String&);
331     void reload(bool reloadFromOrigin);
332     void goForward(uint64_t);
333     void goBack(uint64_t);
334     void goToBackForwardItem(uint64_t);
335     void setActive(bool);
336     void setFocused(bool);
337     void setInitialFocus(bool);
338     void setWindowResizerSize(const WebCore::IntSize&);
339     void setIsInWindow(bool);
340     void mouseEvent(const WebMouseEvent&);
341     void wheelEvent(const WebWheelEvent&);
342     void keyEvent(const WebKeyboardEvent&);
343     void validateMenuItem(const String&);
344     void executeEditCommand(const String&);
345 #if ENABLE(TOUCH_EVENTS)
346     void touchEvent(const WebTouchEvent&);
347 #endif
348
349     uint64_t restoreSession(const SessionState&);
350     void restoreSessionAndNavigateToCurrentItem(const SessionState&);
351
352     void didRemoveBackForwardItem(uint64_t);
353
354     void setDrawsBackground(bool);
355     void setDrawsTransparentBackground(bool);
356
357     void getContentsAsString(uint64_t callbackID);
358     void getMainResourceDataOfFrame(uint64_t frameID, uint64_t callbackID);
359     void getRenderTreeExternalRepresentation(uint64_t callbackID);
360     void getSelectionOrContentsAsString(uint64_t callbackID);
361     void getSourceForFrame(uint64_t frameID, uint64_t callbackID);
362     void getWebArchiveOfFrame(uint64_t frameID, uint64_t callbackID);
363     void runJavaScriptInMainFrame(const String&, uint64_t callbackID);
364
365     void preferencesDidChange(const WebPreferencesStore&);
366     void platformPreferencesDidChange(const WebPreferencesStore&);
367     void updatePreferences(const WebPreferencesStore&);
368
369     void didReceivePolicyDecision(uint64_t frameID, uint64_t listenerID, uint32_t policyAction, uint64_t downloadID);
370     void setUserAgent(const String&);
371     void setCustomTextEncodingName(const String&);
372
373 #if PLATFORM(MAC)
374     void setWindowIsVisible(bool windowIsVisible);
375     void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates, const WebCore::IntPoint& accessibilityViewCoordinates);
376 #endif
377
378     void unapplyEditCommand(uint64_t commandID);
379     void reapplyEditCommand(uint64_t commandID);
380     void didRemoveEditCommand(uint64_t commandID);
381
382     void findString(const String&, uint32_t findOptions, uint32_t maxMatchCount);
383     void hideFindUI();
384     void countStringMatches(const String&, uint32_t findOptions, uint32_t maxMatchCount);
385
386 #if PLATFORM(QT)
387     void findZoomableAreaForPoint(const WebCore::IntPoint&);
388 #endif
389
390     void didChangeSelectedIndexForActivePopupMenu(int32_t newIndex);
391     void setTextForActivePopupMenu(int32_t index);
392
393     void didChooseFilesForOpenPanel(const Vector<String>&);
394     void didCancelForOpenPanel();
395
396     void didReceiveGeolocationPermissionDecision(uint64_t geolocationID, bool allowed);
397
398     void advanceToNextMisspelling(bool startBeforeSelection);
399     void changeSpellingToWord(const String& word);
400     void unmarkAllMisspellings();
401     void unmarkAllBadGrammar();
402 #if PLATFORM(MAC)
403     void uppercaseWord();
404     void lowercaseWord();
405     void capitalizeWord();
406
407     void setSmartInsertDeleteEnabled(bool isSmartInsertDeleteEnabled) { m_isSmartInsertDeleteEnabled = isSmartInsertDeleteEnabled; }
408 #endif
409
410 #if ENABLE(CONTEXT_MENUS)
411     void didSelectItemFromActiveContextMenu(const WebContextMenuItemData&);
412 #endif
413
414     OwnPtr<WebCore::Page> m_page;
415     RefPtr<WebFrame> m_mainFrame;
416     RefPtr<InjectedBundleBackForwardList> m_backForwardList;
417
418     RefPtr<WebPageGroupProxy> m_pageGroup;
419
420     String m_userAgent;
421
422     WebCore::IntSize m_viewSize;
423     RefPtr<DrawingArea> m_drawingArea;
424
425     bool m_drawsBackground;
426     bool m_drawsTransparentBackground;
427
428     bool m_isInRedo;
429     bool m_isClosed;
430
431     bool m_tabToLinks;
432
433 #if PLATFORM(MAC)
434     // Whether the containing window is visible or not.
435     bool m_windowIsVisible;
436
437     // Whether smart insert/delete is enabled or not.
438     bool m_isSmartInsertDeleteEnabled;
439
440     // The frame of the containing window in screen coordinates.
441     WebCore::IntRect m_windowFrameInScreenCoordinates;
442
443     // The frame of the view in window coordinates.
444     WebCore::IntRect m_viewFrameInWindowCoordinates;
445
446     // The accessibility position of the view.
447     WebCore::IntPoint m_accessibilityPosition;
448     
449     // All plug-in views on this web page.
450     HashSet<PluginView*> m_pluginViews;
451     
452     RetainPtr<AccessibilityWebPageObject> m_mockAccessibilityElement;
453 #elif PLATFORM(WIN)
454     // Our view's window (in the UI process).
455     HWND m_nativeWindow;
456 #endif
457     
458     HashMap<uint64_t, RefPtr<WebEditCommand> > m_editCommandMap;
459
460     WebCore::IntSize m_windowResizerSize;
461
462     InjectedBundlePageContextMenuClient m_contextMenuClient;
463     InjectedBundlePageEditorClient m_editorClient;
464     InjectedBundlePageFormClient m_formClient;
465     InjectedBundlePageLoaderClient m_loaderClient;
466     InjectedBundlePageUIClient m_uiClient;
467
468 #if ENABLE(TILED_BACKING_STORE)
469     WebCore::IntSize m_resizesToContentsLayoutSize;
470 #endif
471
472     FindController m_findController;
473     RefPtr<PageOverlay> m_pageOverlay;
474
475 #if ENABLE(INSPECTOR)
476     OwnPtr<WebInspector> m_inspector;
477 #endif
478     RefPtr<WebPopupMenu> m_activePopupMenu;
479     RefPtr<WebContextMenu> m_contextMenu;
480     RefPtr<WebOpenPanelResultListener> m_activeOpenPanelResultListener;
481     GeolocationPermissionRequestManager m_geolocationPermissionRequestManager;
482
483     SandboxExtensionTracker m_sandboxExtensionTracker;
484     uint64_t m_pageID;
485 };
486
487 } // namespace WebKit
488
489 #endif // WebPage_h