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