2 * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
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 "InjectedBundlePagePolicyClient.h"
39 #include "InjectedBundlePageResourceLoadClient.h"
40 #include "InjectedBundlePageUIClient.h"
41 #include "MessageSender.h"
43 #include "SandboxExtension.h"
44 #include "WebEditCommand.h"
45 #include <WebCore/DragData.h>
46 #include <WebCore/Editor.h>
47 #include <WebCore/FrameLoaderTypes.h>
48 #include <WebCore/IntRect.h>
49 #include <WebCore/WebCoreKeyboardUIMode.h>
50 #include <wtf/HashMap.h>
51 #include <wtf/OwnPtr.h>
52 #include <wtf/PassRefPtr.h>
53 #include <wtf/RefPtr.h>
54 #include <wtf/text/WTFString.h>
56 #if ENABLE(TOUCH_EVENTS)
57 #include <WebCore/PlatformTouchEvent.h>
61 #include "DictionaryPopupInfo.h"
62 #include <wtf/RetainPtr.h>
63 OBJC_CLASS AccessibilityWebPageObject;
67 class ArgumentDecoder;
73 class GraphicsContext;
78 class ResourceRequest;
85 class InjectedBundleBackForwardList;
90 class WebContextMenuItemData;
95 class WebKeyboardEvent;
97 class WebOpenPanelResultListener;
98 class WebPageGroupProxy;
102 struct WebPageCreationParameters;
103 struct WebPreferencesStore;
105 #if ENABLE(GESTURE_EVENTS)
106 class WebGestureEvent;
109 #if ENABLE(TOUCH_EVENTS)
113 class WebPage : public APIObject, public CoreIPC::MessageSender<WebPage> {
115 static const Type APIType = TypeBundlePage;
117 static PassRefPtr<WebPage> create(uint64_t pageID, const WebPageCreationParameters&);
120 // Used by MessageSender.
121 CoreIPC::Connection* connection() const;
122 uint64_t destinationID() const { return pageID(); }
126 WebCore::Page* corePage() const { return m_page.get(); }
127 uint64_t pageID() const { return m_pageID; }
129 void setSize(const WebCore::IntSize&);
130 const WebCore::IntSize& size() const { return m_viewSize; }
131 WebCore::IntRect bounds() const { return WebCore::IntRect(WebCore::IntPoint(), size()); }
133 InjectedBundleBackForwardList* backForwardList();
134 DrawingArea* drawingArea() const { return m_drawingArea.get(); }
136 WebPageGroupProxy* pageGroup() const { return m_pageGroup.get(); }
138 void scrollMainFrameIfNotAtMaxScrollPosition(const WebCore::IntSize& scrollOffset);
140 #if ENABLE(INSPECTOR)
141 WebInspector* inspector();
144 // -- Called by the DrawingArea.
145 // FIXME: We could genericize these into a DrawingArea client interface. Would that be beneficial?
146 void drawRect(WebCore::GraphicsContext&, const WebCore::IntRect&);
147 void drawPageOverlay(WebCore::GraphicsContext&, const WebCore::IntRect&);
148 void layoutIfNeeded();
150 // -- Called from WebCore clients.
152 bool handleEditingKeyboardEvent(WebCore::KeyboardEvent*);
155 String userAgent() const { return m_userAgent; }
156 WebCore::IntRect windowResizerRect() const;
157 WebCore::KeyboardUIMode keyboardUIMode();
159 WebEditCommand* webEditCommand(uint64_t);
160 void addWebEditCommand(uint64_t, WebEditCommand*);
161 void removeWebEditCommand(uint64_t);
162 bool isInRedo() const { return m_isInRedo; }
164 void setActivePopupMenu(WebPopupMenu*);
166 WebOpenPanelResultListener* activeOpenPanelResultListener() const { return m_activeOpenPanelResultListener.get(); }
167 void setActiveOpenPanelResultListener(PassRefPtr<WebOpenPanelResultListener>);
169 // -- Called from WebProcess.
170 void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
171 CoreIPC::SyncReplyMode didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, CoreIPC::ArgumentEncoder*);
173 // -- InjectedBundle methods
174 void initializeInjectedBundleContextMenuClient(WKBundlePageContextMenuClient*);
175 void initializeInjectedBundleEditorClient(WKBundlePageEditorClient*);
176 void initializeInjectedBundleFormClient(WKBundlePageFormClient*);
177 void initializeInjectedBundleLoaderClient(WKBundlePageLoaderClient*);
178 void initializeInjectedBundlePolicyClient(WKBundlePagePolicyClient*);
179 void initializeInjectedBundleResourceLoadClient(WKBundlePageResourceLoadClient*);
180 void initializeInjectedBundleUIClient(WKBundlePageUIClient*);
182 InjectedBundlePageContextMenuClient& injectedBundleContextMenuClient() { return m_contextMenuClient; }
183 InjectedBundlePageEditorClient& injectedBundleEditorClient() { return m_editorClient; }
184 InjectedBundlePageFormClient& injectedBundleFormClient() { return m_formClient; }
185 InjectedBundlePageLoaderClient& injectedBundleLoaderClient() { return m_loaderClient; }
186 InjectedBundlePagePolicyClient& injectedBundlePolicyClient() { return m_policyClient; }
187 InjectedBundlePageResourceLoadClient& injectedBundleResourceLoadClient() { return m_resourceLoadClient; }
188 InjectedBundlePageUIClient& injectedBundleUIClient() { return m_uiClient; }
190 bool findStringFromInjectedBundle(const String&, FindOptions);
192 WebFrame* mainFrame() const { return m_mainFrame.get(); }
193 PassRefPtr<Plugin> createPlugin(const Plugin::Parameters&);
195 String renderTreeExternalRepresentation() const;
196 void executeEditingCommand(const String& commandName, const String& argument);
197 bool isEditingCommandEnabled(const String& commandName);
198 void clearMainFrameName();
201 double textZoomFactor() const;
202 void setTextZoomFactor(double);
203 double pageZoomFactor() const;
204 void setPageZoomFactor(double);
205 void setPageAndTextZoomFactors(double pageZoomFactor, double textZoomFactor);
207 void scaleWebView(double scale, const WebCore::IntPoint& origin);
208 double viewScaleFactor() const;
210 void setUseFixedLayout(bool);
211 void setFixedLayoutSize(const WebCore::IntSize&);
213 bool drawsBackground() const { return m_drawsBackground; }
214 bool drawsTransparentBackground() const { return m_drawsTransparentBackground; }
217 void stopLoadingFrame(uint64_t frameID);
218 void setDefersLoading(bool deferLoading);
220 #if USE(ACCELERATED_COMPOSITING)
221 void enterAcceleratedCompositingMode(WebCore::GraphicsLayer*);
222 void exitAcceleratedCompositingMode();
226 void addPluginView(PluginView*);
227 void removePluginView(PluginView*);
229 bool windowIsVisible() const { return m_windowIsVisible; }
230 const WebCore::IntRect& windowFrameInScreenCoordinates() const { return m_windowFrameInScreenCoordinates; }
231 const WebCore::IntRect& viewFrameInWindowCoordinates() const { return m_viewFrameInWindowCoordinates; }
232 bool windowIsFocused() const;
233 bool interceptEditingKeyboardEvent(WebCore::KeyboardEvent*, bool);
235 HWND nativeWindow() const { return m_nativeWindow; }
238 void installPageOverlay(PassRefPtr<PageOverlay>);
239 void uninstallPageOverlay(PageOverlay*);
240 bool hasPageOverlay() const { return m_pageOverlay; }
242 PassRefPtr<WebImage> snapshotInViewCoordinates(const WebCore::IntRect&, ImageOptions);
243 PassRefPtr<WebImage> snapshotInDocumentCoordinates(const WebCore::IntRect&, ImageOptions);
244 PassRefPtr<WebImage> scaledSnapshotInDocumentCoordinates(const WebCore::IntRect&, double scaleFactor, ImageOptions);
246 static const WebEvent* currentEvent();
248 FindController& findController() { return m_findController; }
249 GeolocationPermissionRequestManager& geolocationPermissionRequestManager() { return m_geolocationPermissionRequestManager; }
251 void pageDidScroll();
252 #if ENABLE(TILED_BACKING_STORE)
253 void pageDidRequestScroll(const WebCore::IntSize& delta);
254 void setActualVisibleContentRect(const WebCore::IntRect&);
256 bool resizesToContentsEnabled() const { return !m_resizesToContentsLayoutSize.isEmpty(); }
257 WebCore::IntSize resizesToContentsLayoutSize() const { return m_resizesToContentsLayoutSize; }
258 void setResizesToContentsUsingLayoutSize(const WebCore::IntSize& targetLayoutSize);
259 void resizeToContentsIfNeeded();
262 WebContextMenu* contextMenu();
264 bool hasLocalDataForURL(const WebCore::KURL&);
265 String cachedResponseMIMETypeForURL(const WebCore::KURL&);
267 static bool canHandleRequest(const WebCore::ResourceRequest&);
269 class SandboxExtensionTracker {
271 ~SandboxExtensionTracker();
275 void beginLoad(WebFrame*, const SandboxExtension::Handle& handle);
276 void didStartProvisionalLoad(WebFrame*);
277 void didCommitProvisionalLoad(WebFrame*);
278 void didFailProvisionalLoad(WebFrame*);
280 RefPtr<SandboxExtension> m_pendingProvisionalSandboxExtension;
281 RefPtr<SandboxExtension> m_provisionalSandboxExtension;
282 RefPtr<SandboxExtension> m_committedSandboxExtension;
285 SandboxExtensionTracker& sandboxExtensionTracker() { return m_sandboxExtensionTracker; }
287 static void getLocationAndLengthFromRange(WebCore::Range*, uint64_t& location, uint64_t& length);
290 void registerUIProcessAccessibilityTokens(const CoreIPC::DataReference& elemenToken, const CoreIPC::DataReference& windowToken);
291 AccessibilityWebPageObject* accessibilityRemoteObject();
292 WebCore::IntPoint accessibilityPosition() const { return m_accessibilityPosition; }
294 void sendComplexTextInputToPlugin(uint64_t pluginComplexTextInputIdentifier, const String& textInput);
296 void getMarkedRange(uint64_t& location, uint64_t& length);
297 void characterIndexForPoint(const WebCore::IntPoint point, uint64_t& result);
298 void firstRectForCharacterRange(uint64_t location, uint64_t length, WebCore::IntRect& resultRect);
299 void writeSelectionToPasteboard(const WTF::String& pasteboardName, const WTF::Vector<WTF::String>& pasteboardTypes, bool& result);
301 void confirmComposition(const String& compositionString);
302 void setComposition(const WTF::String& compositionString, const WTF::Vector<WebCore::CompositionUnderline>& underlines, uint64_t cursorPosition);
303 void firstRectForCharacterInSelectedRange(const uint64_t characterPosition, WebCore::IntRect& resultRect);
304 void getSelectedText(WTF::String&);
307 // FIXME: This a dummy message, to avoid breaking the build for platforms that don't require
308 // any synchronous messages, and should be removed when <rdar://problem/8775115> is fixed.
312 void performDictionaryLookupForRange(DictionaryPopupInfo::Type, WebCore::Frame*, WebCore::Range*);
315 void speak(const String&);
318 bool isSmartInsertDeleteEnabled() const { return m_isSmartInsertDeleteEnabled; }
321 void replaceSelectionWithText(WebCore::Frame*, const String&);
323 void performDragControllerAction(uint64_t action, WebCore::IntPoint clientPosition, WebCore::IntPoint globalPosition, uint64_t draggingSourceOperationMask, const WebCore::DragDataMap&, uint32_t flags);
325 void performDragControllerAction(uint64_t action, WebCore::IntPoint clientPosition, WebCore::IntPoint globalPosition, uint64_t draggingSourceOperationMask, const WTF::String& dragStorageName, uint32_t flags);
327 void dragEnded(WebCore::IntPoint clientPosition, WebCore::IntPoint globalPosition, uint64_t operation);
329 void beginPrinting(uint64_t frameID, const PrintInfo&);
331 void computePagesForPrinting(uint64_t frameID, const PrintInfo&, uint64_t callbackID);
332 #if PLATFORM(MAC) || PLATFORM(WIN)
333 void drawRectToPDF(uint64_t frameID, const WebCore::IntRect&, uint64_t callbackID);
334 void drawPagesToPDF(uint64_t frameID, uint32_t first, uint32_t count, uint64_t callbackID);
337 bool mainFrameHasCustomRepresentation() const;
339 void didChangeScrollOffsetForMainFrame();
341 bool canRunBeforeUnloadConfirmPanel() const { return m_canRunBeforeUnloadConfirmPanel; }
342 void setCanRunBeforeUnloadConfirmPanel(bool canRunBeforeUnloadConfirmPanel) { m_canRunBeforeUnloadConfirmPanel = canRunBeforeUnloadConfirmPanel; }
344 bool canRunModal() const { return m_canRunModal; }
345 void setCanRunModal(bool canRunModal) { m_canRunModal = canRunModal; }
349 void setMemoryCacheMessagesEnabled(bool);
351 void forceRepaintWithoutCallback();
354 WebPage(uint64_t pageID, const WebPageCreationParameters&);
356 virtual Type type() const { return APIType; }
358 void platformInitialize();
360 void didReceiveWebPageMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
361 CoreIPC::SyncReplyMode didReceiveSyncWebPageMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, CoreIPC::ArgumentEncoder*);
363 static const char* interpretKeyEvent(const WebCore::KeyboardEvent*);
364 bool performDefaultBehaviorForKeyEvent(const WebKeyboardEvent&);
366 String sourceForFrame(WebFrame*);
368 void loadData(PassRefPtr<WebCore::SharedBuffer>, const String& MIMEType, const String& encodingName, const WebCore::KURL& baseURL, const WebCore::KURL& failingURL);
370 bool platformHasLocalDataForURL(const WebCore::KURL&);
374 void loadURL(const String&, const SandboxExtension::Handle&);
375 void loadURLRequest(const WebCore::ResourceRequest&, const SandboxExtension::Handle&);
376 void loadHTMLString(const String& htmlString, const String& baseURL);
377 void loadAlternateHTMLString(const String& htmlString, const String& baseURL, const String& unreachableURL);
378 void loadPlainTextString(const String&);
379 void reload(bool reloadFromOrigin);
380 void goForward(uint64_t, const SandboxExtension::Handle&);
381 void goBack(uint64_t, const SandboxExtension::Handle&);
382 void goToBackForwardItem(uint64_t, const SandboxExtension::Handle&);
383 void setActive(bool);
384 void setFocused(bool);
385 void setInitialFocus(bool);
386 void setWindowResizerSize(const WebCore::IntSize&);
387 void setIsInWindow(bool);
388 void validateCommand(const String&, uint64_t);
389 void executeEditCommand(const String&);
391 void mouseEvent(const WebMouseEvent&);
392 void wheelEvent(const WebWheelEvent&);
393 void keyEvent(const WebKeyboardEvent&);
394 #if ENABLE(GESTURE_EVENTS)
395 void gestureEvent(const WebGestureEvent&);
397 #if ENABLE(TOUCH_EVENTS)
398 void touchEvent(const WebTouchEvent&);
401 uint64_t restoreSession(const SessionState&);
402 void restoreSessionAndNavigateToCurrentItem(const SessionState&, const SandboxExtension::Handle&);
404 void didRemoveBackForwardItem(uint64_t);
406 void setDrawsBackground(bool);
407 void setDrawsTransparentBackground(bool);
409 void viewWillStartLiveResize();
410 void viewWillEndLiveResize();
412 void getContentsAsString(uint64_t callbackID);
413 void getMainResourceDataOfFrame(uint64_t frameID, uint64_t callbackID);
414 void getResourceDataFromFrame(uint64_t frameID, const String& resourceURL, uint64_t callbackID);
415 void getRenderTreeExternalRepresentation(uint64_t callbackID);
416 void getSelectionOrContentsAsString(uint64_t callbackID);
417 void getSourceForFrame(uint64_t frameID, uint64_t callbackID);
418 void getWebArchiveOfFrame(uint64_t frameID, uint64_t callbackID);
419 void runJavaScriptInMainFrame(const String&, uint64_t callbackID);
420 void forceRepaint(uint64_t callbackID);
422 void preferencesDidChange(const WebPreferencesStore&);
423 void platformPreferencesDidChange(const WebPreferencesStore&);
424 void updatePreferences(const WebPreferencesStore&);
426 void didReceivePolicyDecision(uint64_t frameID, uint64_t listenerID, uint32_t policyAction, uint64_t downloadID);
427 void setUserAgent(const String&);
428 void setCustomTextEncodingName(const String&);
431 void performDictionaryLookupAtLocation(const WebCore::FloatPoint&);
433 void setWindowIsVisible(bool windowIsVisible);
434 void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates, const WebCore::IntPoint& accessibilityViewCoordinates);
437 void unapplyEditCommand(uint64_t commandID);
438 void reapplyEditCommand(uint64_t commandID);
439 void didRemoveEditCommand(uint64_t commandID);
441 void findString(const String&, uint32_t findOptions, uint32_t maxMatchCount);
443 void countStringMatches(const String&, uint32_t findOptions, uint32_t maxMatchCount);
446 void findZoomableAreaForPoint(const WebCore::IntPoint&);
449 void didChangeSelectedIndexForActivePopupMenu(int32_t newIndex);
450 void setTextForActivePopupMenu(int32_t index);
452 void didChooseFilesForOpenPanel(const Vector<String>&);
453 void didCancelForOpenPanel();
454 #if ENABLE(WEB_PROCESS_SANDBOX)
455 void extendSandboxForFileFromOpenPanel(const SandboxExtension::Handle&);
458 void didReceiveGeolocationPermissionDecision(uint64_t geolocationID, bool allowed);
460 void advanceToNextMisspelling(bool startBeforeSelection);
461 void changeSpellingToWord(const String& word);
462 void unmarkAllMisspellings();
463 void unmarkAllBadGrammar();
465 void uppercaseWord();
466 void lowercaseWord();
467 void capitalizeWord();
469 void setSmartInsertDeleteEnabled(bool isSmartInsertDeleteEnabled) { m_isSmartInsertDeleteEnabled = isSmartInsertDeleteEnabled; }
472 #if ENABLE(CONTEXT_MENUS)
473 void didSelectItemFromActiveContextMenu(const WebContextMenuItemData&);
476 OwnPtr<WebCore::Page> m_page;
477 RefPtr<WebFrame> m_mainFrame;
478 RefPtr<InjectedBundleBackForwardList> m_backForwardList;
480 RefPtr<WebPageGroupProxy> m_pageGroup;
484 WebCore::IntSize m_viewSize;
485 OwnPtr<DrawingArea> m_drawingArea;
487 bool m_drawsBackground;
488 bool m_drawsTransparentBackground;
496 // Whether the containing window is visible or not.
497 bool m_windowIsVisible;
499 // Whether smart insert/delete is enabled or not.
500 bool m_isSmartInsertDeleteEnabled;
502 // The frame of the containing window in screen coordinates.
503 WebCore::IntRect m_windowFrameInScreenCoordinates;
505 // The frame of the view in window coordinates.
506 WebCore::IntRect m_viewFrameInWindowCoordinates;
508 // The accessibility position of the view.
509 WebCore::IntPoint m_accessibilityPosition;
511 // All plug-in views on this web page.
512 HashSet<PluginView*> m_pluginViews;
514 RetainPtr<AccessibilityWebPageObject> m_mockAccessibilityElement;
516 // Our view's window (in the UI process).
520 HashMap<uint64_t, RefPtr<WebEditCommand> > m_editCommandMap;
522 WebCore::IntSize m_windowResizerSize;
524 InjectedBundlePageContextMenuClient m_contextMenuClient;
525 InjectedBundlePageEditorClient m_editorClient;
526 InjectedBundlePageFormClient m_formClient;
527 InjectedBundlePageLoaderClient m_loaderClient;
528 InjectedBundlePagePolicyClient m_policyClient;
529 InjectedBundlePageResourceLoadClient m_resourceLoadClient;
530 InjectedBundlePageUIClient m_uiClient;
532 #if ENABLE(TILED_BACKING_STORE)
533 WebCore::IntSize m_resizesToContentsLayoutSize;
536 FindController m_findController;
537 RefPtr<PageOverlay> m_pageOverlay;
539 #if ENABLE(INSPECTOR)
540 RefPtr<WebInspector> m_inspector;
542 RefPtr<WebPopupMenu> m_activePopupMenu;
543 RefPtr<WebContextMenu> m_contextMenu;
544 RefPtr<WebOpenPanelResultListener> m_activeOpenPanelResultListener;
545 GeolocationPermissionRequestManager m_geolocationPermissionRequestManager;
547 OwnPtr<WebCore::PrintContext> m_printContext;
549 SandboxExtensionTracker m_sandboxExtensionTracker;
552 bool m_canRunBeforeUnloadConfirmPanel;
555 bool m_isRunningModal;
557 bool m_cachedMainFrameIsPinnedToLeftSide;
558 bool m_cachedMainFrameIsPinnedToRightSide;
561 } // namespace WebKit