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.
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.
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.
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.
22 #ifndef ChromeClient_h
23 #define ChromeClient_h
25 #include "AXObjectCache.h"
27 #include "DatabaseDetails.h"
28 #include "DisplayRefreshMonitor.h"
29 #include "FocusDirection.h"
30 #include "FrameLoader.h"
31 #include "GraphicsContext.h"
32 #include "HTMLMediaElementEnums.h"
33 #include "HostWindow.h"
34 #include "LayerFlushThrottleState.h"
35 #include "MediaProducer.h"
36 #include "PageThrottler.h"
37 #include "PopupMenu.h"
38 #include "PopupMenuClient.h"
39 #include "RenderEmbeddedObject.h"
40 #include "ScrollTypes.h"
41 #include "ScrollingCoordinator.h"
42 #include "SearchPopupMenu.h"
43 #include "WebCoreKeyboardUIMode.h"
44 #include <runtime/ConsoleTypes.h>
45 #include <wtf/Forward.h>
46 #include <wtf/Vector.h>
48 #if ENABLE(MEDIA_SESSION)
50 struct MediaSessionMetadata;
55 #include "PlatformLayer.h"
56 #define NSResponder WAKResponder
64 OBJC_CLASS NSResponder;
68 class AccessibilityObject;
70 class ColorChooserClient;
71 class DateTimeChooser;
72 class DateTimeChooserClient;
79 class GraphicsContext3D;
81 class GraphicsLayerFactory;
82 class HTMLInputElement;
83 class HTMLVideoElement;
86 class NavigationAction;
89 class PopupMenuClient;
91 class ViewportConstraints;
94 #if ENABLE(VIDEO) && USE(GSTREAMER)
95 class MediaPlayerRequestInstallMissingPluginsCallback;
98 struct DateTimeChooserParameters;
99 struct FrameLoadRequest;
100 struct GraphicsDeviceAdapter;
101 struct ViewportArguments;
102 struct WindowFeatures;
104 class WEBCORE_EXPORT ChromeClient {
106 virtual void chromeDestroyed() = 0;
108 virtual void setWindowRect(const FloatRect&) = 0;
109 virtual FloatRect windowRect() = 0;
111 virtual FloatRect pageRect() = 0;
113 virtual void focus() = 0;
114 virtual void unfocus() = 0;
116 virtual bool canTakeFocus(FocusDirection) = 0;
117 virtual void takeFocus(FocusDirection) = 0;
119 virtual void focusedElementChanged(Element*) = 0;
120 virtual void focusedFrameChanged(Frame*) = 0;
122 // The Frame pointer provides the ChromeClient with context about which
123 // Frame wants to create the new Page. Also, the newly created window
124 // should not be shown to the user until the ChromeClient of the newly
125 // created Page has its show method called.
126 // The FrameLoadRequest parameter is only for ChromeClient to check if the
127 // request could be fulfilled. The ChromeClient should not load the request.
128 virtual Page* createWindow(Frame*, const FrameLoadRequest&, const WindowFeatures&, const NavigationAction&) = 0;
129 virtual void show() = 0;
131 virtual bool canRunModal() = 0;
132 virtual void runModal() = 0;
134 virtual void setToolbarsVisible(bool) = 0;
135 virtual bool toolbarsVisible() = 0;
137 virtual void setStatusbarVisible(bool) = 0;
138 virtual bool statusbarVisible() = 0;
140 virtual void setScrollbarsVisible(bool) = 0;
141 virtual bool scrollbarsVisible() = 0;
143 virtual void setMenubarVisible(bool) = 0;
144 virtual bool menubarVisible() = 0;
146 virtual void setResizable(bool) = 0;
148 virtual void addMessageToConsole(MessageSource, MessageLevel, const String& message, unsigned lineNumber, unsigned columnNumber, const String& sourceID) = 0;
150 virtual bool canRunBeforeUnloadConfirmPanel() = 0;
151 virtual bool runBeforeUnloadConfirmPanel(const String& message, Frame*) = 0;
153 virtual void closeWindowSoon() = 0;
155 virtual void runJavaScriptAlert(Frame*, const String&) = 0;
156 virtual bool runJavaScriptConfirm(Frame*, const String&) = 0;
157 virtual bool runJavaScriptPrompt(Frame*, const String& message, const String& defaultValue, String& result) = 0;
158 virtual void setStatusbarText(const String&) = 0;
159 virtual KeyboardUIMode keyboardUIMode() = 0;
161 // Methods used by HostWindow.
162 virtual bool supportsImmediateInvalidation() { return false; }
163 virtual void invalidateRootView(const IntRect&) = 0;
164 virtual void invalidateContentsAndRootView(const IntRect&) = 0;
165 virtual void invalidateContentsForSlowScroll(const IntRect&) = 0;
166 virtual void scroll(const IntSize&, const IntRect&, const IntRect&) = 0;
167 #if USE(COORDINATED_GRAPHICS)
168 virtual void delegatedScrollRequested(const IntPoint&) = 0;
170 virtual IntPoint screenToRootView(const IntPoint&) const = 0;
171 virtual IntRect rootViewToScreen(const IntRect&) const = 0;
173 virtual IntPoint accessibilityScreenToRootView(const IntPoint&) const = 0;
174 virtual IntRect rootViewToAccessibilityScreen(const IntRect&) const = 0;
176 virtual PlatformPageClient platformPageClient() const = 0;
177 virtual void scrollbarsModeDidChange() const = 0;
178 #if ENABLE(CURSOR_SUPPORT)
179 virtual void setCursor(const Cursor&) = 0;
180 virtual void setCursorHiddenUntilMouseMoves(bool) = 0;
182 #if ENABLE(REQUEST_ANIMATION_FRAME) && !USE(REQUEST_ANIMATION_FRAME_TIMER)
183 virtual void scheduleAnimation() = 0;
185 // End methods used by HostWindow.
187 virtual FloatSize screenSize() const { return const_cast<ChromeClient*>(this)->windowRect().size(); }
188 virtual FloatSize availableScreenSize() const { return const_cast<ChromeClient*>(this)->windowRect().size(); }
190 virtual void dispatchViewportPropertiesDidChange(const ViewportArguments&) const { }
192 virtual void contentsSizeChanged(Frame*, const IntSize&) const = 0;
193 virtual void scrollRectIntoView(const IntRect&) const { }; // Currently only Mac has a non empty implementation.
195 virtual bool shouldUnavailablePluginMessageBeButton(RenderEmbeddedObject::PluginUnavailabilityReason) const { return false; }
196 virtual void unavailablePluginButtonClicked(Element*, RenderEmbeddedObject::PluginUnavailabilityReason) const { }
197 virtual void mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags) = 0;
199 virtual void setToolTip(const String&, TextDirection) = 0;
201 virtual void print(Frame*) = 0;
203 virtual Color underlayColor() const { return Color(); }
205 virtual void pageExtendedBackgroundColorDidChange(Color) const { }
207 virtual void exceededDatabaseQuota(Frame*, const String& databaseName, DatabaseDetails) = 0;
209 // Callback invoked when the application cache fails to save a cache object
210 // because storing it would grow the database file past its defined maximum
211 // size or past the amount of free space on the device.
212 // The chrome client would need to take some action such as evicting some
214 virtual void reachedMaxAppCacheSize(int64_t spaceNeeded) = 0;
216 // Callback invoked when the application cache origin quota is reached. This
217 // means that the resources attempting to be cached via the manifest are
218 // more than allowed on this origin. This callback allows the chrome client
219 // to take action, such as prompting the user to ask to increase the quota
220 // for this origin. The totalSpaceNeeded parameter is the total amount of
221 // storage, in bytes, needed to store the new cache along with all of the
222 // other existing caches for the origin that would not be replaced by
224 virtual void reachedApplicationCacheOriginQuota(SecurityOrigin*, int64_t totalSpaceNeeded) = 0;
226 #if ENABLE(DASHBOARD_SUPPORT)
227 virtual void annotatedRegionsChanged();
230 virtual bool shouldReplaceWithGeneratedFileForUpload(const String& path, String& generatedFilename);
231 virtual String generateReplacementFile(const String& path);
233 #if ENABLE(IOS_TOUCH_EVENTS)
234 virtual void didPreventDefaultForEvent() = 0;
237 virtual std::chrono::milliseconds eventThrottlingDelay() { return std::chrono::milliseconds::zero(); };
240 virtual void didReceiveMobileDocType(bool) = 0;
241 virtual void setNeedsScrollNotifications(Frame*, bool) = 0;
242 virtual void observedContentChange(Frame*) = 0;
243 virtual void clearContentChangeObservers(Frame*) = 0;
244 virtual void notifyRevealedSelectionByScrollingFrame(Frame*) = 0;
246 enum LayoutType { NormalLayout, Scroll };
247 virtual void didLayout(LayoutType = NormalLayout) = 0;
248 virtual void didStartOverflowScroll() = 0;
249 virtual void didEndOverflowScroll() = 0;
251 // FIXME: Remove this functionality. This functionality was added to workaround an issue (<rdar://problem/5973875>)
252 // where the unconfirmed text in a text area would be removed when a person clicks in the text area before a
253 // suggestion is shown. We should fix this issue in <rdar://problem/5975559>.
254 virtual void suppressFormNotifications() = 0;
255 virtual void restoreFormNotifications() = 0;
257 virtual void didFlushCompositingLayers() { }
259 virtual bool fetchCustomFixedPositionLayoutRect(IntRect&) { return false; }
261 virtual void updateViewportConstrainedLayers(HashMap<PlatformLayer*, std::unique_ptr<ViewportConstraints>>&, HashMap<PlatformLayer*, PlatformLayer*>&) { }
263 virtual void addOrUpdateScrollingLayer(Node*, PlatformLayer* scrollingLayer, PlatformLayer* contentsLayer, const IntSize& scrollSize, bool allowHorizontalScrollbar, bool allowVerticalScrollbar) = 0;
264 virtual void removeScrollingLayer(Node*, PlatformLayer* scrollingLayer, PlatformLayer* contentsLayer) = 0;
266 virtual void webAppOrientationsUpdated() = 0;
267 virtual void showPlaybackTargetPicker(bool hasVideo) = 0;
270 #if ENABLE(ORIENTATION_EVENTS)
271 virtual int deviceOrientation() const = 0;
274 #if ENABLE(INPUT_TYPE_COLOR)
275 virtual std::unique_ptr<ColorChooser> createColorChooser(ColorChooserClient*, const Color&) = 0;
278 virtual void runOpenPanel(Frame*, PassRefPtr<FileChooser>) = 0;
279 // Asynchronous request to load an icon for specified filenames.
280 virtual void loadIconForFiles(const Vector<String>&, FileIconLoader*) = 0;
282 virtual void elementDidFocus(const Node*) { };
283 virtual void elementDidBlur(const Node*) { };
285 virtual bool shouldPaintEntireContents() const { return false; }
286 virtual bool hasStablePageScaleFactor() const { return true; }
288 // Allows ports to customize the type of graphics layers created by this page.
289 virtual GraphicsLayerFactory* graphicsLayerFactory() const { return nullptr; }
291 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
292 virtual RefPtr<DisplayRefreshMonitor> createDisplayRefreshMonitor(PlatformDisplayID) const { return nullptr; }
295 // Pass 0 as the GraphicsLayer to detatch the root layer.
296 virtual void attachRootGraphicsLayer(Frame*, GraphicsLayer*) = 0;
297 virtual void attachViewOverlayGraphicsLayer(Frame*, GraphicsLayer*) = 0;
298 // Sets a flag to specify that the next time content is drawn to the window,
299 // the changes appear on the screen in synchrony with updates to GraphicsLayers.
300 virtual void setNeedsOneShotDrawingSynchronization() = 0;
301 // Sets a flag to specify that the view needs to be updated, so we need
302 // to do an eager layout before the drawing.
303 virtual void scheduleCompositingLayerFlush() = 0;
304 // Returns whether or not the client can render the composited layer,
305 // regardless of the settings.
306 virtual bool allowsAcceleratedCompositing() const { return true; }
308 enum CompositingTrigger {
309 ThreeDTransformTrigger = 1 << 0,
310 VideoTrigger = 1 << 1,
311 PluginTrigger = 1 << 2,
312 CanvasTrigger = 1 << 3,
313 AnimationTrigger = 1 << 4,
314 FilterTrigger = 1 << 5,
315 ScrollableInnerFrameTrigger = 1 << 6,
316 AnimatedOpacityTrigger = 1 << 7,
317 AllTriggers = 0xFFFFFFFF
319 typedef unsigned CompositingTriggerFlags;
321 // Returns a bitfield indicating conditions that can trigger the compositor.
322 virtual CompositingTriggerFlags allowedCompositingTriggers() const { return static_cast<CompositingTriggerFlags>(AllTriggers); }
324 // Returns true if layer tree updates are disabled.
325 virtual bool layerTreeStateIsFrozen() const { return false; }
327 virtual bool adjustLayerFlushThrottling(LayerFlushThrottleState::Flags) { return false; }
329 virtual PassRefPtr<ScrollingCoordinator> createScrollingCoordinator(Page*) const { return nullptr; }
331 #if PLATFORM(WIN) && USE(AVFOUNDATION)
332 virtual GraphicsDeviceAdapter* graphicsDeviceAdapter() const { return 0; }
335 virtual bool supportsVideoFullscreen() { return false; }
337 virtual void enterVideoFullscreenForVideoElement(HTMLVideoElement&, HTMLMediaElementEnums::VideoFullscreenMode) { }
339 virtual void exitVideoFullscreenForVideoElement(WebCore::HTMLVideoElement&) { }
340 virtual bool requiresFullscreenForVideoPlayback() { return false; }
342 #if ENABLE(FULLSCREEN_API)
343 virtual bool supportsFullScreenForElement(const Element*, bool) { return false; }
344 virtual void enterFullScreenForElement(Element*) { }
345 virtual void exitFullScreenForElement(Element*) { }
346 virtual void setRootFullScreenLayer(GraphicsLayer*) { }
349 #if USE(COORDINATED_GRAPHICS)
350 virtual IntRect visibleRectForTiledBackingStore() const { return IntRect(); }
354 virtual NSResponder *firstResponder() { return 0; }
355 virtual void makeFirstResponder(NSResponder *) { }
356 // Focuses on the containing view associated with this page.
357 virtual void makeFirstResponder() { }
361 // FIXME: Come up with a more descriptive name for this function and make it platform independent (if possible).
362 virtual bool isStopping() = 0;
365 virtual void enableSuddenTermination() { }
366 virtual void disableSuddenTermination() { }
369 virtual void setLastSetCursorToCurrentCursor() = 0;
370 virtual void AXStartFrameLoad() = 0;
371 virtual void AXFinishFrameLoad() = 0;
374 #if ENABLE(TOUCH_EVENTS)
375 virtual void needTouchEvents(bool) = 0;
378 virtual bool selectItemWritingDirectionIsNatural() = 0;
379 virtual bool selectItemAlignmentFollowsMenuWritingDirection() = 0;
380 // Checks if there is an opened popup, called by RenderMenuList::showPopup().
381 virtual bool hasOpenedPopup() const = 0;
382 virtual RefPtr<PopupMenu> createPopupMenu(PopupMenuClient*) const = 0;
383 virtual RefPtr<SearchPopupMenu> createSearchPopupMenu(PopupMenuClient*) const = 0;
385 virtual void postAccessibilityNotification(AccessibilityObject*, AXObjectCache::AXNotification) { }
387 virtual void notifyScrollerThumbIsVisibleInRect(const IntRect&) { }
388 virtual void recommendedScrollbarStyleDidChange(ScrollbarStyle) { }
390 virtual WTF::Optional<ScrollbarOverlayStyle> preferredScrollbarOverlayStyle() { return ScrollbarOverlayStyleDefault; }
392 virtual void wheelEventHandlersChanged(bool hasHandlers) = 0;
394 virtual bool isSVGImageChromeClient() const { return false; }
396 #if ENABLE(POINTER_LOCK)
397 virtual bool requestPointerLock() { return false; }
398 virtual void requestPointerUnlock() { }
399 virtual bool isPointerLocked() { return false; }
402 virtual void didBeginTrackingPotentialLongMousePress(const IntPoint& mouseDownPosition, const HitTestResult&) { UNUSED_PARAM(mouseDownPosition); }
403 virtual void didRecognizeLongMousePress() { }
404 virtual void didCancelTrackingPotentialLongMousePress() { }
406 virtual FloatSize minimumWindowSize() const { return FloatSize(100, 100); };
408 virtual bool isEmptyChromeClient() const { return false; }
410 virtual String plugInStartLabelTitle(const String& mimeType) const { UNUSED_PARAM(mimeType); return String(); }
411 virtual String plugInStartLabelSubtitle(const String& mimeType) const { UNUSED_PARAM(mimeType); return String(); }
412 virtual String plugInExtraStyleSheet() const { return String(); }
413 virtual String plugInExtraScript() const { return String(); }
415 virtual void didAssociateFormControls(const Vector<RefPtr<Element>>&) { };
416 virtual bool shouldNotifyOnFormChanges() { return false; };
418 virtual void didAddHeaderLayer(GraphicsLayer*) { }
419 virtual void didAddFooterLayer(GraphicsLayer*) { }
421 virtual bool shouldUseTiledBackingForFrameView(const FrameView*) const { return false; }
423 virtual void isPlayingMediaDidChange(MediaProducer::MediaStateFlags, uint64_t) { }
425 #if ENABLE(MEDIA_SESSION)
426 virtual void hasMediaSessionWithActiveMediaElementsDidChange(bool) { }
427 virtual void mediaSessionMetadataDidChange(const WebCore::MediaSessionMetadata&) { }
428 virtual void focusedContentMediaElementDidChange(uint64_t) { }
431 virtual void setPageActivityState(PageActivityState::Flags) { }
433 #if ENABLE(SUBTLE_CRYPTO)
434 virtual bool wrapCryptoKey(const Vector<uint8_t>&, Vector<uint8_t>&) const { return false; }
435 virtual bool unwrapCryptoKey(const Vector<uint8_t>&, Vector<uint8_t>&) const { return false; }
438 #if ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC)
439 virtual void handleTelephoneNumberClick(const String&, const WebCore::IntPoint&) { }
441 #if ENABLE(SERVICE_CONTROLS)
442 virtual void handleSelectionServiceClick(WebCore::FrameSelection&, const Vector<String>&, const WebCore::IntPoint&) { }
443 virtual bool hasRelevantSelectionServices(bool /* isTextOnly */) const { return false; }
446 virtual bool shouldDispatchFakeMouseMoveEvents() const { return true; }
448 virtual void handleAutoFillButtonClick(HTMLInputElement&) { }
450 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
451 virtual void addPlaybackTargetPickerClient(uint64_t /*contextId*/) { }
452 virtual void removePlaybackTargetPickerClient(uint64_t /*contextId*/) { }
453 virtual void showPlaybackTargetPicker(uint64_t /*contextId*/, const WebCore::IntPoint&, bool /* isVideo */) { }
454 virtual void playbackTargetPickerClientStateDidChange(uint64_t /*contextId*/, MediaProducer::MediaStateFlags) { }
458 virtual void mediaDocumentNaturalSizeChanged(const WebCore::IntSize&) { }
460 virtual void requestInstallMissingMediaPlugins(const String& /*details*/, const String& /*description*/, MediaPlayerRequestInstallMissingPluginsCallback&) { };
465 virtual ~ChromeClient() { }
469 #endif // ChromeClient_h