Rename Source/WebKit2 to Source/WebKit.
[WebKit-https.git] / Source / WebKit / WebProcess / WebCoreSupport / WebChromeClient.h
1 /*
2  * Copyright (C) 2010-2017 Apple Inc. All rights reserved.
3  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24  * THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #pragma once
28
29 #include <WebCore/ChromeClient.h>
30
31 namespace WebKit {
32
33 class WebFrame;
34 class WebPage;
35
36 class WebChromeClient final : public WebCore::ChromeClient {
37 public:
38     WebChromeClient(WebPage&);
39
40     WebPage& page() const { return m_page; }
41
42 private:
43     ~WebChromeClient();
44
45     void chromeDestroyed() final;
46     
47     void setWindowRect(const WebCore::FloatRect&) final;
48     WebCore::FloatRect windowRect() final;
49     
50     WebCore::FloatRect pageRect() final;
51     
52     void focus() final;
53     void unfocus() final;
54     
55     bool canTakeFocus(WebCore::FocusDirection) final;
56     void takeFocus(WebCore::FocusDirection) final;
57
58     void focusedElementChanged(WebCore::Element*) final;
59     void focusedFrameChanged(WebCore::Frame*) final;
60
61     // The Frame pointer provides the ChromeClient with context about which
62     // Frame wants to create the new Page.  Also, the newly created window
63     // should not be shown to the user until the ChromeClient of the newly
64     // created Page has its show method called.
65     WebCore::Page* createWindow(WebCore::Frame&, const WebCore::FrameLoadRequest&, const WebCore::WindowFeatures&, const WebCore::NavigationAction&) final;
66     void show() final;
67     
68     bool canRunModal() final;
69     void runModal() final;
70
71     void reportProcessCPUTime(Seconds, WebCore::ActivityStateForCPUSampling) final;
72     
73     void setToolbarsVisible(bool) final;
74     bool toolbarsVisible() final;
75     
76     void setStatusbarVisible(bool) final;
77     bool statusbarVisible() final;
78     
79     void setScrollbarsVisible(bool) final;
80     bool scrollbarsVisible() final;
81     
82     void setMenubarVisible(bool) final;
83     bool menubarVisible() final;
84     
85     void setResizable(bool) final;
86     
87     void addMessageToConsole(JSC::MessageSource, JSC::MessageLevel, const String& message, unsigned lineNumber, unsigned columnNumber, const String& sourceID) final;
88     
89     bool canRunBeforeUnloadConfirmPanel() final;
90     bool runBeforeUnloadConfirmPanel(const String& message, WebCore::Frame&) final;
91     
92     void closeWindowSoon() final;
93     
94     void runJavaScriptAlert(WebCore::Frame&, const String&) final;
95     bool runJavaScriptConfirm(WebCore::Frame&, const String&) final;
96     bool runJavaScriptPrompt(WebCore::Frame&, const String& message, const String& defaultValue, String& result) final;
97     void setStatusbarText(const String&) final;
98
99     WebCore::KeyboardUIMode keyboardUIMode() final;
100
101     // HostWindow member function finals.
102     void invalidateRootView(const WebCore::IntRect&) final;
103     void invalidateContentsAndRootView(const WebCore::IntRect&) final;
104     void invalidateContentsForSlowScroll(const WebCore::IntRect&) final;
105     void scroll(const WebCore::IntSize& scrollDelta, const WebCore::IntRect& scrollRect, const WebCore::IntRect& clipRect) final;
106
107 #if USE(COORDINATED_GRAPHICS)
108     void delegatedScrollRequested(const WebCore::IntPoint& scrollOffset) final;
109     void resetUpdateAtlasForTesting() final;
110 #endif
111
112     WebCore::IntPoint screenToRootView(const WebCore::IntPoint&) const final;
113     WebCore::IntRect rootViewToScreen(const WebCore::IntRect&) const final;
114
115 #if PLATFORM(IOS)
116     WebCore::IntPoint accessibilityScreenToRootView(const WebCore::IntPoint&) const final;
117     WebCore::IntRect rootViewToAccessibilityScreen(const WebCore::IntRect&) const final;
118 #endif
119
120     PlatformPageClient platformPageClient() const final;
121     void contentsSizeChanged(WebCore::Frame&, const WebCore::IntSize&) const final;
122     void scrollRectIntoView(const WebCore::IntRect&) const final; // Currently only Mac has a non empty implementation.
123
124     bool shouldUnavailablePluginMessageBeButton(WebCore::RenderEmbeddedObject::PluginUnavailabilityReason) const final;
125     void unavailablePluginButtonClicked(WebCore::Element&, WebCore::RenderEmbeddedObject::PluginUnavailabilityReason) const final;
126
127     void scrollbarsModeDidChange() const final;
128     void mouseDidMoveOverElement(const WebCore::HitTestResult&, unsigned modifierFlags) final;
129
130     void setToolTip(const String&, WebCore::TextDirection) final;
131     
132     void print(WebCore::Frame&) final;
133
134     void exceededDatabaseQuota(WebCore::Frame&, const String& databaseName, WebCore::DatabaseDetails) final;
135
136     void reachedMaxAppCacheSize(int64_t spaceNeeded) final;
137     void reachedApplicationCacheOriginQuota(WebCore::SecurityOrigin&, int64_t spaceNeeded) final;
138
139 #if ENABLE(DASHBOARD_SUPPORT)
140     void annotatedRegionsChanged() final;
141 #endif
142
143     bool shouldReplaceWithGeneratedFileForUpload(const String& path, String& generatedFilename) final;
144     String generateReplacementFile(const String& path) final;
145     
146 #if ENABLE(INPUT_TYPE_COLOR)
147     std::unique_ptr<WebCore::ColorChooser> createColorChooser(WebCore::ColorChooserClient&, const WebCore::Color&) final;
148 #endif
149
150 #if ENABLE(IOS_TOUCH_EVENTS)
151     void didPreventDefaultForEvent() final;
152 #endif
153
154 #if PLATFORM(IOS)
155     void didReceiveMobileDocType(bool) final;
156     void setNeedsScrollNotifications(WebCore::Frame&, bool) final;
157     void observedContentChange(WebCore::Frame&) final;
158     void clearContentChangeObservers(WebCore::Frame&) final;
159     void notifyRevealedSelectionByScrollingFrame(WebCore::Frame&) final;
160     bool isStopping() final;
161
162     void didLayout(LayoutType = NormalLayout) final;
163     void didStartOverflowScroll() final;
164     void didEndOverflowScroll() final;
165     bool hasStablePageScaleFactor() const final;
166
167     // FIXME: See <rdar://problem/5975559>
168     void suppressFormNotifications() final;
169     void restoreFormNotifications() final;
170
171     void addOrUpdateScrollingLayer(WebCore::Node*, PlatformLayer* scrollingLayer, PlatformLayer* contentsLayer, const WebCore::IntSize& scrollSize, bool allowHorizontalScrollbar, bool allowVerticalScrollbar) final;
172     void removeScrollingLayer(WebCore::Node*, PlatformLayer* scrollingLayer, PlatformLayer* contentsLayer) final;
173
174     void webAppOrientationsUpdated() final;
175     void showPlaybackTargetPicker(bool hasVideo) final;
176
177     Seconds eventThrottlingDelay() final;
178 #endif
179
180 #if ENABLE(ORIENTATION_EVENTS)
181     int deviceOrientation() const final;
182 #endif
183
184     void runOpenPanel(WebCore::Frame&, WebCore::FileChooser&) final;
185     void loadIconForFiles(const Vector<String>&, WebCore::FileIconLoader&) final;
186
187 #if !PLATFORM(IOS)
188     void setCursor(const WebCore::Cursor&) final;
189     void setCursorHiddenUntilMouseMoves(bool) final;
190 #endif
191
192 #if ENABLE(POINTER_LOCK)
193     bool requestPointerLock() final;
194     void requestPointerUnlock() final;
195 #endif
196
197     void didAssociateFormControls(const Vector<RefPtr<WebCore::Element>>&) final;
198     bool shouldNotifyOnFormChanges() final;
199
200     bool selectItemWritingDirectionIsNatural() final;
201     bool selectItemAlignmentFollowsMenuWritingDirection() final;
202     bool hasOpenedPopup() const final;
203     RefPtr<WebCore::PopupMenu> createPopupMenu(WebCore::PopupMenuClient&) const final;
204     RefPtr<WebCore::SearchPopupMenu> createSearchPopupMenu(WebCore::PopupMenuClient&) const final;
205
206     WebCore::GraphicsLayerFactory* graphicsLayerFactory() const final;
207     void attachRootGraphicsLayer(WebCore::Frame&, WebCore::GraphicsLayer*) final;
208     void attachViewOverlayGraphicsLayer(WebCore::Frame&, WebCore::GraphicsLayer*) final;
209     void setNeedsOneShotDrawingSynchronization() final;
210     void scheduleCompositingLayerFlush() final;
211     bool adjustLayerFlushThrottling(WebCore::LayerFlushThrottleState::Flags) final;
212
213 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
214     RefPtr<WebCore::DisplayRefreshMonitor> createDisplayRefreshMonitor(WebCore::PlatformDisplayID) const final;
215 #endif
216
217     CompositingTriggerFlags allowedCompositingTriggers() const final
218     {
219         return static_cast<CompositingTriggerFlags>(
220             ThreeDTransformTrigger |
221             VideoTrigger |
222             PluginTrigger|
223             CanvasTrigger |
224 #if PLATFORM(MAC) || PLATFORM(IOS)
225             ScrollableNonMainFrameTrigger |
226 #endif
227 #if PLATFORM(IOS)
228             AnimatedOpacityTrigger | // Allow opacity animations to trigger compositing mode for iPhone: <rdar://problem/7830677>
229 #endif
230             AnimationTrigger);
231     }
232
233     bool layerTreeStateIsFrozen() const final;
234
235 #if ENABLE(ASYNC_SCROLLING)
236     RefPtr<WebCore::ScrollingCoordinator> createScrollingCoordinator(WebCore::Page&) const final;
237 #endif
238
239 #if PLATFORM(IOS)
240     void elementDidRefocus(WebCore::Element&) final;
241 #endif
242
243 #if (PLATFORM(IOS) && HAVE(AVKIT)) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE))
244     bool supportsVideoFullscreen(WebCore::HTMLMediaElementEnums::VideoFullscreenMode) final;
245     void setUpPlaybackControlsManager(WebCore::HTMLMediaElement&) final;
246     void clearPlaybackControlsManager() final;
247     void enterVideoFullscreenForVideoElement(WebCore::HTMLVideoElement&, WebCore::HTMLMediaElementEnums::VideoFullscreenMode) final;
248     void exitVideoFullscreenForVideoElement(WebCore::HTMLVideoElement&) final;
249 #endif
250
251 #if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)
252     void exitVideoFullscreenToModeWithoutAnimation(WebCore::HTMLVideoElement&, WebCore::HTMLMediaElementEnums::VideoFullscreenMode) final;
253 #endif
254
255 #if ENABLE(FULLSCREEN_API)
256     bool supportsFullScreenForElement(const WebCore::Element&, bool withKeyboard) final;
257     void enterFullScreenForElement(WebCore::Element&) final;
258     void exitFullScreenForElement(WebCore::Element*) final;
259 #endif
260
261 #if PLATFORM(COCOA)
262     void elementDidFocus(WebCore::Element&) final;
263     void elementDidBlur(WebCore::Element&) final;
264
265     void makeFirstResponder() final;
266 #endif
267
268     void enableSuddenTermination() final;
269     void disableSuddenTermination() final;
270
271 #if PLATFORM(IOS)
272     WebCore::FloatSize screenSize() const final;
273     WebCore::FloatSize availableScreenSize() const final;
274 #endif
275
276     void dispatchViewportPropertiesDidChange(const WebCore::ViewportArguments&) const final;
277
278     void notifyScrollerThumbIsVisibleInRect(const WebCore::IntRect&) final;
279     void recommendedScrollbarStyleDidChange(WebCore::ScrollbarStyle newStyle) final;
280
281     std::optional<WebCore::ScrollbarOverlayStyle> preferredScrollbarOverlayStyle() final;
282
283     WebCore::Color underlayColor() const final;
284
285     void pageExtendedBackgroundColorDidChange(WebCore::Color) const final;
286     
287     void wheelEventHandlersChanged(bool) final;
288
289     String plugInStartLabelTitle(const String& mimeType) const final;
290     String plugInStartLabelSubtitle(const String& mimeType) const final;
291     String plugInExtraStyleSheet() const final;
292     String plugInExtraScript() const final;
293
294     void didAddHeaderLayer(WebCore::GraphicsLayer&) final;
295     void didAddFooterLayer(WebCore::GraphicsLayer&) final;
296
297     bool shouldUseTiledBackingForFrameView(const WebCore::FrameView&) const final;
298
299     void isPlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags, uint64_t) final;
300     void handleAutoplayEvent(WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final;
301
302 #if ENABLE(MEDIA_SESSION)
303     void hasMediaSessionWithActiveMediaElementsDidChange(bool) final;
304     void mediaSessionMetadataDidChange(const WebCore::MediaSessionMetadata&) final;
305     void focusedContentMediaElementDidChange(uint64_t) final;
306 #endif
307
308 #if ENABLE(SUBTLE_CRYPTO)
309     bool wrapCryptoKey(const Vector<uint8_t>&, Vector<uint8_t>&) const final;
310     bool unwrapCryptoKey(const Vector<uint8_t>&, Vector<uint8_t>&) const final;
311 #endif
312
313 #if ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC)
314     void handleTelephoneNumberClick(const String& number, const WebCore::IntPoint&) final;
315 #endif
316
317 #if ENABLE(SERVICE_CONTROLS)
318     void handleSelectionServiceClick(WebCore::FrameSelection&, const Vector<String>& telephoneNumbers, const WebCore::IntPoint&) final;
319     bool hasRelevantSelectionServices(bool isTextOnly) const final;
320 #endif
321
322     bool shouldDispatchFakeMouseMoveEvents() const final;
323
324     void handleAutoFillButtonClick(WebCore::HTMLInputElement&) final;
325
326 #if ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS)
327     void addPlaybackTargetPickerClient(uint64_t /*contextId*/) final;
328     void removePlaybackTargetPickerClient(uint64_t /*contextId*/) final;
329     void showPlaybackTargetPicker(uint64_t contextId, const WebCore::IntPoint&, bool) final;
330     void playbackTargetPickerClientStateDidChange(uint64_t, WebCore::MediaProducer::MediaStateFlags) final;
331     void setMockMediaPlaybackTargetPickerEnabled(bool) final;
332     void setMockMediaPlaybackTargetPickerState(const String&, WebCore::MediaPlaybackTargetContext::State) final;
333 #endif
334
335     void imageOrMediaDocumentSizeChanged(const WebCore::IntSize&) final;
336
337     RefPtr<WebCore::Icon> createIconForFiles(const Vector<String>& filenames) final;
338
339 #if ENABLE(VIDEO) && USE(GSTREAMER)
340     void requestInstallMissingMediaPlugins(const String& /*details*/, const String& /*description*/, WebCore::MediaPlayerRequestInstallMissingPluginsCallback&) final;
341 #endif
342
343     void didInvalidateDocumentMarkerRects() final;
344
345     String m_cachedToolTip;
346     mutable RefPtr<WebFrame> m_cachedFrameSetLargestFrame;
347     mutable bool m_cachedMainFrameHasHorizontalScrollbar { false };
348     mutable bool m_cachedMainFrameHasVerticalScrollbar { false };
349
350     WebPage& m_page;
351 };
352
353 } // namespace WebKit