1/* 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple, Inc. All rights reserved. 3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 4 * Copyright (C) 2012 Samsung Electronics. All rights reserved. 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Library General Public License for more details. 15 * 16 * You should have received a copy of the GNU Library General Public License 17 * along with this library; see the file COPYING.LIB. If not, write to 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA. 20 */ 21 22#ifndef ChromeClient_h 23#define ChromeClient_h 24 25#include "AXObjectCache.h" 26#include "ConsoleAPITypes.h" 27#include "ConsoleTypes.h" 28#include "Cursor.h" 29#include "FocusDirection.h" 30#include "FrameLoader.h" 31#include "GraphicsContext.h" 32#include "HostWindow.h" 33#include "PopupMenu.h" 34#include "PopupMenuClient.h" 35#include "RenderEmbeddedObject.h" 36#include "ScrollTypes.h" 37#include "SearchPopupMenu.h" 38#include "WebCoreKeyboardUIMode.h" 39#include <wtf/Forward.h> 40#include <wtf/PassOwnPtr.h> 41#include <wtf/Vector.h> 42 43#if ENABLE(SQL_DATABASE) 44#include "DatabaseDetails.h" 45#endif 46 47OBJC_CLASS NSResponder; 48 49namespace WebCore { 50 51class AccessibilityObject; 52class ColorChooser; 53class ColorChooserClient; 54class DateTimeChooser; 55class DateTimeChooserClient; 56class Element; 57class FileChooser; 58class FileIconLoader; 59class FloatRect; 60class Frame; 61class Geolocation; 62class GraphicsContext3D; 63class GraphicsLayer; 64class GraphicsLayerFactory; 65class HitTestResult; 66class HTMLInputElement; 67class IntRect; 68class NavigationAction; 69class Node; 70class Page; 71class PopupMenuClient; 72class SecurityOrigin; 73class Widget; 74 75struct DateTimeChooserParameters; 76struct FrameLoadRequest; 77struct GraphicsDeviceAdapter; 78struct ViewportArguments; 79struct WindowFeatures; 80 81class ChromeClient { 82public: 83 virtual void chromeDestroyed() = 0; 84 85 virtual void setWindowRect(const FloatRect&) = 0; 86 virtual FloatRect windowRect() = 0; 87 88 virtual FloatRect pageRect() = 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, MessageLevel, const String& message, unsigned lineNumber, unsigned columnNumber, const String& sourceID) = 0; 126 // FIXME: Remove this MessageType variant once all the clients are updated. 127 virtual void addMessageToConsole(MessageSource source, MessageType, MessageLevel level, const String& message, unsigned lineNumber, unsigned columnNumber, const String& sourceID) 128 { 129 addMessageToConsole(source, level, message, lineNumber, columnNumber, sourceID); 130 } 131 132 virtual bool canRunBeforeUnloadConfirmPanel() = 0; 133 virtual bool runBeforeUnloadConfirmPanel(const String& message, Frame*) = 0; 134 135 virtual void closeWindowSoon() = 0; 136 137 virtual void runJavaScriptAlert(Frame*, const String&) = 0; 138 virtual bool runJavaScriptConfirm(Frame*, const String&) = 0; 139 virtual bool runJavaScriptPrompt(Frame*, const String& message, const String& defaultValue, String& result) = 0; 140 virtual void setStatusbarText(const String&) = 0; 141 virtual bool shouldInterruptJavaScript() = 0; 142 virtual KeyboardUIMode keyboardUIMode() = 0; 143 144 virtual IntRect windowResizerRect() const = 0; 145 146 // Methods used by HostWindow. 147 virtual bool supportsImmediateInvalidation() { return false; } 148 virtual void invalidateRootView(const IntRect&, bool immediate) = 0; 149 virtual void invalidateContentsAndRootView(const IntRect&, bool immediate) = 0; 150 virtual void invalidateContentsForSlowScroll(const IntRect&, bool immediate) = 0; 151 virtual void scroll(const IntSize&, const IntRect&, const IntRect&) = 0; 152#if USE(TILED_BACKING_STORE) 153 virtual void delegatedScrollRequested(const IntPoint&) = 0; 154#endif 155 virtual IntPoint screenToRootView(const IntPoint&) const = 0; 156 virtual IntRect rootViewToScreen(const IntRect&) const = 0; 157 virtual PlatformPageClient platformPageClient() const = 0; 158 virtual void scrollbarsModeDidChange() const = 0; 159 virtual void setCursor(const Cursor&) = 0; 160 virtual void setCursorHiddenUntilMouseMoves(bool) = 0; 161#if ENABLE(REQUEST_ANIMATION_FRAME) && !USE(REQUEST_ANIMATION_FRAME_TIMER) 162 virtual void scheduleAnimation() = 0; 163#endif 164 // End methods used by HostWindow. 165 166 virtual void dispatchViewportPropertiesDidChange(const ViewportArguments&) const { } 167 168 virtual void contentsSizeChanged(Frame*, const IntSize&) const = 0; 169 virtual void layoutUpdated(Frame*) const { } 170 virtual void scrollRectIntoView(const IntRect&) const { }; // Currently only Mac has a non empty implementation. 171 172 virtual bool shouldUnavailablePluginMessageBeButton(RenderEmbeddedObject::PluginUnavailabilityReason) const { return false; } 173 virtual void unavailablePluginButtonClicked(Element*, RenderEmbeddedObject::PluginUnavailabilityReason) const { } 174 virtual void mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags) = 0; 175 176 virtual void setToolTip(const String&, TextDirection) = 0; 177 178 virtual void print(Frame*) = 0; 179 virtual bool shouldRubberBandInDirection(ScrollDirection) const = 0; 180 181 virtual Color underlayColor() const { return Color(); } 182 183#if ENABLE(SQL_DATABASE) 184 virtual void exceededDatabaseQuota(Frame*, const String& databaseName, DatabaseDetails) = 0; 185#endif 186 187 // Callback invoked when the application cache fails to save a cache object 188 // because storing it would grow the database file past its defined maximum 189 // size or past the amount of free space on the device. 190 // The chrome client would need to take some action such as evicting some 191 // old caches. 192 virtual void reachedMaxAppCacheSize(int64_t spaceNeeded) = 0; 193 194 // Callback invoked when the application cache origin quota is reached. This 195 // means that the resources attempting to be cached via the manifest are 196 // more than allowed on this origin. This callback allows the chrome client 197 // to take action, such as prompting the user to ask to increase the quota 198 // for this origin. The totalSpaceNeeded parameter is the total amount of 199 // storage, in bytes, needed to store the new cache along with all of the 200 // other existing caches for the origin that would not be replaced by 201 // the new cache. 202 virtual void reachedApplicationCacheOriginQuota(SecurityOrigin*, int64_t totalSpaceNeeded) = 0; 203 204#if ENABLE(DASHBOARD_SUPPORT) || ENABLE(DRAGGABLE_REGION) 205 virtual void annotatedRegionsChanged(); 206#endif 207 208 virtual void populateVisitedLinks(); 209 210 virtual FloatRect customHighlightRect(Node*, const AtomicString& type, const FloatRect& lineRect); 211 virtual void paintCustomHighlight(Node*, const AtomicString& type, const FloatRect& boxRect, const FloatRect& lineRect, bool behindText, bool entireLine); 212 213 virtual bool shouldReplaceWithGeneratedFileForUpload(const String& path, String& generatedFilename); 214 virtual String generateReplacementFile(const String& path); 215 216 virtual bool paintCustomOverhangArea(GraphicsContext*, const IntRect&, const IntRect&, const IntRect&); 217 218#if ENABLE(INPUT_TYPE_COLOR) 219 virtual PassOwnPtr<ColorChooser> createColorChooser(ColorChooserClient*, const Color&) = 0; 220#endif 221 222#if ENABLE(DATE_AND_TIME_INPUT_TYPES) 223 virtual PassRefPtr<DateTimeChooser> openDateTimeChooser(DateTimeChooserClient*, const DateTimeChooserParameters&) = 0; 224#endif 225 226 virtual void runOpenPanel(Frame*, PassRefPtr<FileChooser>) = 0; 227 // Asynchronous request to load an icon for specified filenames. 228 virtual void loadIconForFiles(const Vector<String>&, FileIconLoader*) = 0; 229 230#if ENABLE(DIRECTORY_UPLOAD) 231 // Asychronous request to enumerate all files in a directory chosen by the user. 232 virtual void enumerateChosenDirectory(FileChooser*) = 0; 233#endif 234 235 // Notification that the given form element has changed. This function 236 // will be called frequently, so handling should be very fast. 237 virtual void formStateDidChange(const Node*) = 0; 238 239 virtual void elementDidFocus(const Node*) { }; 240 virtual void elementDidBlur(const Node*) { }; 241 242 virtual bool shouldPaintEntireContents() const { return false; } 243 244#if USE(ACCELERATED_COMPOSITING) 245 // Allows ports to customize the type of graphics layers created by this page. 246 virtual GraphicsLayerFactory* graphicsLayerFactory() const { return 0; } 247 248 // Pass 0 as the GraphicsLayer to detatch the root layer. 249 virtual void attachRootGraphicsLayer(Frame*, GraphicsLayer*) = 0; 250 // Sets a flag to specify that the next time content is drawn to the window, 251 // the changes appear on the screen in synchrony with updates to GraphicsLayers. 252 virtual void setNeedsOneShotDrawingSynchronization() = 0; 253 // Sets a flag to specify that the view needs to be updated, so we need 254 // to do an eager layout before the drawing. 255 virtual void scheduleCompositingLayerFlush() = 0; 256 // Returns whether or not the client can render the composited layer, 257 // regardless of the settings. 258 virtual bool allowsAcceleratedCompositing() const { return true; } 259 260 enum CompositingTrigger { 261 ThreeDTransformTrigger = 1 << 0, 262 VideoTrigger = 1 << 1, 263 PluginTrigger = 1 << 2, 264 CanvasTrigger = 1 << 3, 265 AnimationTrigger = 1 << 4, 266 FilterTrigger = 1 << 5, 267 ScrollableInnerFrameTrigger = 1 << 6, 268 AnimatedOpacityTrigger = 1 << 7, 269 AllTriggers = 0xFFFFFFFF 270 }; 271 typedef unsigned CompositingTriggerFlags; 272 273 // Returns a bitfield indicating conditions that can trigger the compositor. 274 virtual CompositingTriggerFlags allowedCompositingTriggers() const { return static_cast<CompositingTriggerFlags>(AllTriggers); } 275 276 // Returns true if layer tree updates are disabled. 277 virtual bool layerTreeStateIsFrozen() const { return false; } 278#endif 279 280#if PLATFORM(WIN) && USE(AVFOUNDATION) 281 virtual GraphicsDeviceAdapter* graphicsDeviceAdapter() const { return 0; } 282#endif 283 284 virtual bool supportsFullscreenForNode(const Node*) { return false; } 285 virtual void enterFullscreenForNode(Node*) { } 286 virtual void exitFullscreenForNode(Node*) { } 287 virtual bool requiresFullscreenForVideoPlayback() { return false; } 288 289#if ENABLE(FULLSCREEN_API) 290 virtual bool supportsFullScreenForElement(const Element*, bool) { return false; } 291 virtual void enterFullScreenForElement(Element*) { } 292 virtual void exitFullScreenForElement(Element*) { } 293 virtual void fullScreenRendererChanged(RenderBox*) { } 294 virtual void setRootFullScreenLayer(GraphicsLayer*) { } 295#endif 296 297#if USE(TILED_BACKING_STORE) 298 virtual IntRect visibleRectForTiledBackingStore() const { return IntRect(); } 299#endif 300 301#if PLATFORM(MAC) 302 virtual NSResponder *firstResponder() { return 0; } 303 virtual void makeFirstResponder(NSResponder *) { } 304 // Focuses on the containing view associated with this page. 305 virtual void makeFirstResponder() { } 306#endif 307 308 virtual void enableSuddenTermination() { } 309 virtual void disableSuddenTermination() { } 310 311#if PLATFORM(WIN) 312 virtual void setLastSetCursorToCurrentCursor() = 0; 313 virtual void AXStartFrameLoad() = 0; 314 virtual void AXFinishFrameLoad() = 0; 315#endif 316 317#if ENABLE(TOUCH_EVENTS) 318 virtual void needTouchEvents(bool) = 0; 319#endif 320 321 virtual bool selectItemWritingDirectionIsNatural() = 0; 322 virtual bool selectItemAlignmentFollowsMenuWritingDirection() = 0; 323 // Checks if there is an opened popup, called by RenderMenuList::showPopup(). 324 virtual bool hasOpenedPopup() const = 0; 325 virtual PassRefPtr<PopupMenu> createPopupMenu(PopupMenuClient*) const = 0; 326 virtual PassRefPtr<SearchPopupMenu> createSearchPopupMenu(PopupMenuClient*) const = 0; 327 328 virtual void postAccessibilityNotification(AccessibilityObject*, AXObjectCache::AXNotification) { } 329 330 virtual void notifyScrollerThumbIsVisibleInRect(const IntRect&) { } 331 virtual void recommendedScrollbarStyleDidChange(int /*newStyle*/) { } 332 333 enum DialogType { 334 AlertDialog = 0, 335 ConfirmDialog = 1, 336 PromptDialog = 2, 337 HTMLDialog = 3 338 }; 339 virtual bool shouldRunModalDialogDuringPageDismissal(const DialogType&, const String& dialogMessage, FrameLoader::PageDismissalType) const { UNUSED_PARAM(dialogMessage); return true; } 340 341 virtual void numWheelEventHandlersChanged(unsigned) = 0; 342 343 virtual bool isSVGImageChromeClient() const { return false; } 344 345#if ENABLE(POINTER_LOCK) 346 virtual bool requestPointerLock() { return false; } 347 virtual void requestPointerUnlock() { } 348 virtual bool isPointerLocked() { return false; } 349#endif 350 351 virtual void logDiagnosticMessage(const String& message, const String& description, const String& status) { UNUSED_PARAM(message); UNUSED_PARAM(description); UNUSED_PARAM(status); } 352 353 virtual FloatSize minimumWindowSize() const { return FloatSize(100, 100); }; 354 355 virtual bool isEmptyChromeClient() const { return false; } 356 357 virtual String plugInStartLabelTitle(const String& mimeType) const { UNUSED_PARAM(mimeType); return String(); } 358 virtual String plugInStartLabelSubtitle(const String& mimeType) const { UNUSED_PARAM(mimeType); return String(); } 359 virtual String plugInExtraStyleSheet() const { return String(); } 360 virtual String plugInExtraScript() const { return String(); } 361 362 // FIXME: Port should return true using heuristic based on scrollable(RenderBox). 363 virtual bool shouldAutoscrollForDragAndDrop(RenderBox*) const { return false; } 364 365 virtual void didAssociateFormControls(const Vector<RefPtr<Element> >&) { }; 366 virtual bool shouldNotifyOnFormChanges() { return false; }; 367 368 virtual void didAddHeaderLayer(GraphicsLayer*) { } 369 virtual void didAddFooterLayer(GraphicsLayer*) { } 370 371 // These methods are used to report pages that are performing 372 // some task that we consider to be "active", and so the user 373 // would likely want the page to remain running uninterrupted. 374 virtual void incrementActivePageCount() { } 375 virtual void decrementActivePageCount() { } 376 377protected: 378 virtual ~ChromeClient() { } 379}; 380 381} 382#endif // ChromeClient_h 383