ChromeClient.h revision ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddb
1/*
2 * Copyright (C) 2006, 2007, 2008, 2009 Apple, Inc. All rights reserved.
3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB.  If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#ifndef ChromeClient_h
22#define ChromeClient_h
23
24#include "AXObjectCache.h"
25#include "Console.h"
26#include "Cursor.h"
27#include "FocusDirection.h"
28#include "GraphicsContext.h"
29#include "HTMLParserQuirks.h"
30#include "HostWindow.h"
31#include "PopupMenu.h"
32#include "PopupMenuClient.h"
33#include "ScrollTypes.h"
34#include "SearchPopupMenu.h"
35#include <wtf/Forward.h>
36#include <wtf/PassOwnPtr.h>
37#include <wtf/Vector.h>
38
39#if PLATFORM(MAC)
40#include "WebCoreKeyboardUIMode.h"
41#endif
42
43#ifndef __OBJC__
44class NSMenu;
45class NSResponder;
46#endif
47
48namespace WebCore {
49
50    class AccessibilityObject;
51    class Element;
52    class FileChooser;
53    class FloatRect;
54    class Frame;
55    class Geolocation;
56    class HTMLParserQuirks;
57    class HitTestResult;
58    class IntRect;
59    class NavigationAction;
60    class Node;
61    class Page;
62    class PopupMenuClient;
63    class SecurityOrigin;
64    class SharedGraphicsContext3D;
65    class Widget;
66
67    struct FrameLoadRequest;
68    struct ViewportArguments;
69    struct WindowFeatures;
70
71#if USE(ACCELERATED_COMPOSITING)
72    class GraphicsLayer;
73#endif
74
75#if ENABLE(NOTIFICATIONS)
76    class NotificationPresenter;
77#endif
78
79    class ChromeClient {
80    public:
81        virtual void chromeDestroyed() = 0;
82
83        virtual void setWindowRect(const FloatRect&) = 0;
84        virtual FloatRect windowRect() = 0;
85
86        virtual FloatRect pageRect() = 0;
87
88        virtual float scaleFactor() = 0;
89
90        virtual void focus() = 0;
91        virtual void unfocus() = 0;
92
93        virtual bool canTakeFocus(FocusDirection) = 0;
94        virtual void takeFocus(FocusDirection) = 0;
95
96        virtual void focusedNodeChanged(Node*) = 0;
97        virtual void focusedFrameChanged(Frame*) = 0;
98
99        // The Frame pointer provides the ChromeClient with context about which
100        // Frame wants to create the new Page.  Also, the newly created window
101        // should not be shown to the user until the ChromeClient of the newly
102        // created Page has its show method called.
103        // The FrameLoadRequest parameter is only for ChromeClient to check if the
104        // request could be fulfilled.  The ChromeClient should not load the request.
105        virtual Page* createWindow(Frame*, const FrameLoadRequest&, const WindowFeatures&, const NavigationAction&) = 0;
106        virtual void show() = 0;
107
108        virtual bool canRunModal() = 0;
109        virtual void runModal() = 0;
110
111        virtual void setToolbarsVisible(bool) = 0;
112        virtual bool toolbarsVisible() = 0;
113
114        virtual void setStatusbarVisible(bool) = 0;
115        virtual bool statusbarVisible() = 0;
116
117        virtual void setScrollbarsVisible(bool) = 0;
118        virtual bool scrollbarsVisible() = 0;
119
120        virtual void setMenubarVisible(bool) = 0;
121        virtual bool menubarVisible() = 0;
122
123        virtual void setResizable(bool) = 0;
124
125        virtual void addMessageToConsole(MessageSource, MessageType, MessageLevel, const String& message, unsigned int lineNumber, const String& sourceID) = 0;
126
127        virtual bool canRunBeforeUnloadConfirmPanel() = 0;
128        virtual bool runBeforeUnloadConfirmPanel(const String& message, Frame* frame) = 0;
129
130        virtual void closeWindowSoon() = 0;
131
132        virtual void runJavaScriptAlert(Frame*, const String&) = 0;
133        virtual bool runJavaScriptConfirm(Frame*, const String&) = 0;
134        virtual bool runJavaScriptPrompt(Frame*, const String& message, const String& defaultValue, String& result) = 0;
135        virtual void setStatusbarText(const String&) = 0;
136        virtual bool shouldInterruptJavaScript() = 0;
137        virtual bool tabsToLinks() const = 0;
138
139        virtual IntRect windowResizerRect() const = 0;
140
141        // Methods used by HostWindow.
142        virtual void invalidateWindow(const IntRect&, bool) = 0;
143        virtual void invalidateContentsAndWindow(const IntRect&, bool) = 0;
144        virtual void invalidateContentsForSlowScroll(const IntRect&, bool) = 0;
145        virtual void scroll(const IntSize&, const IntRect&, const IntRect&) = 0;
146#if ENABLE(TILED_BACKING_STORE)
147        virtual void delegatedScrollRequested(const IntSize&) = 0;
148#endif
149        virtual IntPoint screenToWindow(const IntPoint&) const = 0;
150        virtual IntRect windowToScreen(const IntRect&) const = 0;
151        virtual PlatformPageClient platformPageClient() const = 0;
152        virtual void scrollbarsModeDidChange() const = 0;
153        virtual void setCursor(const Cursor&) = 0;
154#if ENABLE(REQUEST_ANIMATION_FRAME)
155        virtual void scheduleAnimation() = 0;
156#endif
157        // End methods used by HostWindow.
158
159        virtual void dispatchViewportDataDidChange(const ViewportArguments&) const { }
160
161        virtual void contentsSizeChanged(Frame*, const IntSize&) const = 0;
162        virtual void scrollRectIntoView(const IntRect&, const ScrollView*) const = 0; // Currently only Mac has a non empty implementation.
163
164        virtual bool shouldMissingPluginMessageBeButton() const { return false; }
165        virtual void missingPluginButtonClicked(Element*) const { }
166        virtual void mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags) = 0;
167
168        virtual void setToolTip(const String&, TextDirection) = 0;
169
170        virtual void print(Frame*) = 0;
171
172#if ENABLE(DATABASE)
173        virtual void exceededDatabaseQuota(Frame*, const String& databaseName) = 0;
174#endif
175
176#if ENABLE(OFFLINE_WEB_APPLICATIONS)
177        // Callback invoked when the application cache fails to save a cache object
178        // because storing it would grow the database file past its defined maximum
179        // size or past the amount of free space on the device.
180        // The chrome client would need to take some action such as evicting some
181        // old caches.
182        virtual void reachedMaxAppCacheSize(int64_t spaceNeeded) = 0;
183
184        // Callback invoked when the application cache origin quota is reached. This
185        // means that the resources attempting to be cached via the manifest are
186        // more than allowed on this origin. This callback allows the chrome client
187        // to take action, such as prompting the user to ask to increase the quota
188        // for this origin.
189        virtual void reachedApplicationCacheOriginQuota(SecurityOrigin* origin) = 0;
190#endif
191
192#if ENABLE(DASHBOARD_SUPPORT)
193        virtual void dashboardRegionsChanged();
194#endif
195
196#if ENABLE(NOTIFICATIONS)
197        virtual NotificationPresenter* notificationPresenter() const = 0;
198#endif
199
200        virtual void populateVisitedLinks();
201
202        virtual FloatRect customHighlightRect(Node*, const AtomicString& type, const FloatRect& lineRect);
203        virtual void paintCustomHighlight(Node*, const AtomicString& type, const FloatRect& boxRect, const FloatRect& lineRect,
204            bool behindText, bool entireLine);
205
206        virtual bool shouldReplaceWithGeneratedFileForUpload(const String& path, String& generatedFilename);
207        virtual String generateReplacementFile(const String& path);
208
209        virtual bool paintCustomScrollbar(GraphicsContext*, const FloatRect&, ScrollbarControlSize,
210                                          ScrollbarControlState, ScrollbarPart pressedPart, bool vertical,
211                                          float value, float proportion, ScrollbarControlPartMask);
212        virtual bool paintCustomScrollCorner(GraphicsContext*, const FloatRect&);
213
214        // FIXME: Remove once all ports are using client-based geolocation. https://bugs.webkit.org/show_bug.cgi?id=40373
215        // For client-based geolocation, these two methods have moved to GeolocationClient. https://bugs.webkit.org/show_bug.cgi?id=50061
216        // This can be either a synchronous or asynchronous call. The ChromeClient can display UI asking the user for permission
217        // to use Geolocation.
218        virtual void requestGeolocationPermissionForFrame(Frame*, Geolocation*) = 0;
219        virtual void cancelGeolocationPermissionRequestForFrame(Frame*, Geolocation*) = 0;
220
221        virtual void runOpenPanel(Frame*, PassRefPtr<FileChooser>) = 0;
222        // Asynchronous request to load an icon for specified filenames.
223        virtual void chooseIconForFiles(const Vector<String>&, FileChooser*) = 0;
224
225        // Notification that the given form element has changed. This function
226        // will be called frequently, so handling should be very fast.
227        virtual void formStateDidChange(const Node*) = 0;
228
229        virtual void formDidFocus(const Node*) { };
230        virtual void formDidBlur(const Node*) { };
231
232        virtual PassOwnPtr<HTMLParserQuirks> createHTMLParserQuirks() = 0;
233
234#if USE(ACCELERATED_COMPOSITING)
235        // Pass 0 as the GraphicsLayer to detatch the root layer.
236        virtual void attachRootGraphicsLayer(Frame*, GraphicsLayer*) = 0;
237        // Sets a flag to specify that the next time content is drawn to the window,
238        // the changes appear on the screen in synchrony with updates to GraphicsLayers.
239        virtual void setNeedsOneShotDrawingSynchronization() = 0;
240        // Sets a flag to specify that the view needs to be updated, so we need
241        // to do an eager layout before the drawing.
242        virtual void scheduleCompositingLayerSync() = 0;
243        // Returns whether or not the client can render the composited layer,
244        // regardless of the settings.
245        virtual bool allowsAcceleratedCompositing() const { return true; }
246
247        enum CompositingTrigger {
248            ThreeDTransformTrigger = 1 << 0,
249            VideoTrigger = 1 << 1,
250            PluginTrigger = 1 << 2,
251            CanvasTrigger = 1 << 3,
252            AnimationTrigger = 1 << 4,
253            AllTriggers = 0xFFFFFFFF
254        };
255        typedef unsigned CompositingTriggerFlags;
256
257        // Returns a bitfield indicating conditions that can trigger the compositor.
258        virtual CompositingTriggerFlags allowedCompositingTriggers() const { return static_cast<CompositingTriggerFlags>(AllTriggers); }
259#endif
260
261        virtual bool supportsFullscreenForNode(const Node*) { return false; }
262        virtual void enterFullscreenForNode(Node*) { }
263        virtual void exitFullscreenForNode(Node*) { }
264        virtual bool requiresFullscreenForVideoPlayback() { return false; }
265
266#if ENABLE(FULLSCREEN_API)
267        virtual bool supportsFullScreenForElement(const Element*) { return false; }
268        virtual void enterFullScreenForElement(Element*) { }
269        virtual void exitFullScreenForElement(Element*) { }
270        virtual void fullScreenRendererChanged(RenderBox*) { }
271#endif
272
273#if ENABLE(TILED_BACKING_STORE)
274        virtual IntRect visibleRectForTiledBackingStore() const { return IntRect(); }
275#endif
276
277#if PLATFORM(MAC)
278        virtual KeyboardUIMode keyboardUIMode() { return KeyboardAccessDefault; }
279
280        virtual NSResponder *firstResponder() { return 0; }
281        virtual void makeFirstResponder(NSResponder *) { }
282
283        virtual void willPopUpMenu(NSMenu *) { }
284#endif
285
286#if PLATFORM(WIN)
287        virtual void setLastSetCursorToCurrentCursor() = 0;
288#endif
289
290#if ENABLE(TOUCH_EVENTS)
291        virtual void needTouchEvents(bool) = 0;
292#endif
293
294        virtual bool selectItemWritingDirectionIsNatural() = 0;
295        virtual PassRefPtr<PopupMenu> createPopupMenu(PopupMenuClient*) const = 0;
296        virtual PassRefPtr<SearchPopupMenu> createSearchPopupMenu(PopupMenuClient*) const = 0;
297
298#if ENABLE(CONTEXT_MENUS)
299        virtual void showContextMenu() = 0;
300#endif
301
302        virtual void postAccessibilityNotification(AccessibilityObject*, AXObjectCache::AXNotification) { }
303
304#if ENABLE(ANDROID_INSTALLABLE_WEB_APPS)
305        virtual void webAppCanBeInstalled() = 0;
306#endif
307
308    protected:
309        virtual ~ChromeClient() { }
310    };
311
312}
313
314#endif // ChromeClient_h
315