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