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
31namespace WebCore {
32class RegistrableDomain;
33enum class StorageAccessPromptWasShown : bool;
34enum class StorageAccessWasGranted : bool;
35}
36
37namespace WebKit {
38
39class WebFrame;
40class WebPage;
41
42class WebChromeClient final : public WebCore::ChromeClient {
43public:
44 WebChromeClient(WebPage&);
45
46 WebPage& page() const { return m_page; }
47
48private:
49 ~WebChromeClient();
50
51 void didInsertMenuElement(WebCore::HTMLMenuElement&);
52 void didRemoveMenuElement(WebCore::HTMLMenuElement&);
53 void didInsertMenuItemElement(WebCore::HTMLMenuItemElement&);
54 void didRemoveMenuItemElement(WebCore::HTMLMenuItemElement&);
55
56 void chromeDestroyed() final;
57
58 void setWindowRect(const WebCore::FloatRect&) final;
59 WebCore::FloatRect windowRect() final;
60
61 WebCore::FloatRect pageRect() final;
62
63 void focus() final;
64 void unfocus() final;
65
66 bool canTakeFocus(WebCore::FocusDirection) final;
67 void takeFocus(WebCore::FocusDirection) final;
68
69 void focusedElementChanged(WebCore::Element*) final;
70 void focusedFrameChanged(WebCore::Frame*) final;
71
72 // The Frame pointer provides the ChromeClient with context about which
73 // Frame wants to create the new Page. Also, the newly created window
74 // should not be shown to the user until the ChromeClient of the newly
75 // created Page has its show method called.
76 WebCore::Page* createWindow(WebCore::Frame&, const WebCore::FrameLoadRequest&, const WebCore::WindowFeatures&, const WebCore::NavigationAction&) final;
77 void show() final;
78
79 bool canRunModal() final;
80 void runModal() final;
81
82 void reportProcessCPUTime(Seconds, WebCore::ActivityStateForCPUSampling) final;
83
84 void setToolbarsVisible(bool) final;
85 bool toolbarsVisible() final;
86
87 void setStatusbarVisible(bool) final;
88 bool statusbarVisible() final;
89
90 void setScrollbarsVisible(bool) final;
91 bool scrollbarsVisible() final;
92
93 void setMenubarVisible(bool) final;
94 bool menubarVisible() final;
95
96 void setResizable(bool) final;
97
98 void addMessageToConsole(JSC::MessageSource, JSC::MessageLevel, const String& message, unsigned lineNumber, unsigned columnNumber, const String& sourceID) final;
99
100 bool canRunBeforeUnloadConfirmPanel() final;
101 bool runBeforeUnloadConfirmPanel(const String& message, WebCore::Frame&) final;
102
103 void closeWindowSoon() final;
104
105 void runJavaScriptAlert(WebCore::Frame&, const String&) final;
106 bool runJavaScriptConfirm(WebCore::Frame&, const String&) final;
107 bool runJavaScriptPrompt(WebCore::Frame&, const String& message, const String& defaultValue, String& result) final;
108 void setStatusbarText(const String&) final;
109
110 WebCore::KeyboardUIMode keyboardUIMode() final;
111
112 // HostWindow member function finals.
113 void invalidateRootView(const WebCore::IntRect&) final;
114 void invalidateContentsAndRootView(const WebCore::IntRect&) final;
115 void invalidateContentsForSlowScroll(const WebCore::IntRect&) final;
116 void scroll(const WebCore::IntSize& scrollDelta, const WebCore::IntRect& scrollRect, const WebCore::IntRect& clipRect) final;
117
118 WebCore::IntPoint screenToRootView(const WebCore::IntPoint&) const final;
119 WebCore::IntRect rootViewToScreen(const WebCore::IntRect&) const final;
120
121 WebCore::IntPoint accessibilityScreenToRootView(const WebCore::IntPoint&) const final;
122 WebCore::IntRect rootViewToAccessibilityScreen(const WebCore::IntRect&) const final;
123
124 PlatformPageClient platformPageClient() const final;
125 void contentsSizeChanged(WebCore::Frame&, const WebCore::IntSize&) const final;
126 void intrinsicContentsSizeChanged(const WebCore::IntSize&) const final;
127 void scrollRectIntoView(const WebCore::IntRect&) const final; // Currently only Mac has a non empty implementation.
128
129 bool shouldUnavailablePluginMessageBeButton(WebCore::RenderEmbeddedObject::PluginUnavailabilityReason) const final;
130 void unavailablePluginButtonClicked(WebCore::Element&, WebCore::RenderEmbeddedObject::PluginUnavailabilityReason) const final;
131
132 void mouseDidMoveOverElement(const WebCore::HitTestResult&, unsigned modifierFlags) final;
133
134 void setToolTip(const String&, WebCore::TextDirection) final;
135
136 void print(WebCore::Frame&) final;
137
138 void exceededDatabaseQuota(WebCore::Frame&, const String& databaseName, WebCore::DatabaseDetails) final;
139
140 void reachedMaxAppCacheSize(int64_t spaceNeeded) final;
141 void reachedApplicationCacheOriginQuota(WebCore::SecurityOrigin&, int64_t spaceNeeded) final;
142
143#if ENABLE(DASHBOARD_SUPPORT)
144 void annotatedRegionsChanged() final;
145#endif
146
147 bool shouldReplaceWithGeneratedFileForUpload(const String& path, String& generatedFilename) final;
148 String generateReplacementFile(const String& path) final;
149
150#if ENABLE(INPUT_TYPE_COLOR)
151 std::unique_ptr<WebCore::ColorChooser> createColorChooser(WebCore::ColorChooserClient&, const WebCore::Color&) final;
152#endif
153
154#if ENABLE(DATALIST_ELEMENT)
155 std::unique_ptr<WebCore::DataListSuggestionPicker> createDataListSuggestionPicker(WebCore::DataListSuggestionsClient&) final;
156#endif
157
158#if ENABLE(IOS_TOUCH_EVENTS)
159 void didPreventDefaultForEvent() final;
160#endif
161
162#if PLATFORM(IOS_FAMILY)
163 void didReceiveMobileDocType(bool) final;
164 void setNeedsScrollNotifications(WebCore::Frame&, bool) final;
165 void observedContentChange(WebCore::Frame&) final;
166 void notifyRevealedSelectionByScrollingFrame(WebCore::Frame&) final;
167 bool isStopping() final;
168
169 void didLayout(LayoutType = NormalLayout) final;
170 void didStartOverflowScroll() final;
171 void didEndOverflowScroll() final;
172 bool hasStablePageScaleFactor() const final;
173
174 // FIXME: See <rdar://problem/5975559>
175 void suppressFormNotifications() final;
176 void restoreFormNotifications() final;
177
178 void addOrUpdateScrollingLayer(WebCore::Node*, PlatformLayer* scrollingLayer, PlatformLayer* contentsLayer, const WebCore::IntSize& scrollSize, bool allowHorizontalScrollbar, bool allowVerticalScrollbar) final;
179 void removeScrollingLayer(WebCore::Node*, PlatformLayer* scrollingLayer, PlatformLayer* contentsLayer) final;
180
181 void webAppOrientationsUpdated() final;
182 void showPlaybackTargetPicker(bool hasVideo, WebCore::RouteSharingPolicy, const String&) final;
183
184 Seconds eventThrottlingDelay() final;
185
186 void associateEditableImageWithAttachment(WebCore::GraphicsLayer::EmbeddedViewID, const String& attachmentID) final;
187 void didCreateEditableImage(WebCore::GraphicsLayer::EmbeddedViewID) final;
188 void didDestroyEditableImage(WebCore::GraphicsLayer::EmbeddedViewID) final;
189#endif
190
191#if ENABLE(ORIENTATION_EVENTS)
192 int deviceOrientation() const final;
193#endif
194
195 void runOpenPanel(WebCore::Frame&, WebCore::FileChooser&) final;
196 void showShareSheet(WebCore::ShareDataWithParsedURL&, WTF::CompletionHandler<void(bool)>&&) final;
197 void loadIconForFiles(const Vector<String>&, WebCore::FileIconLoader&) final;
198
199#if !PLATFORM(IOS_FAMILY)
200 void setCursor(const WebCore::Cursor&) final;
201 void setCursorHiddenUntilMouseMoves(bool) final;
202#endif
203
204#if ENABLE(POINTER_LOCK)
205 bool requestPointerLock() final;
206 void requestPointerUnlock() final;
207#endif
208
209 void didAssociateFormControls(const Vector<RefPtr<WebCore::Element>>&, WebCore::Frame&) final;
210 bool shouldNotifyOnFormChanges() final;
211
212 bool selectItemWritingDirectionIsNatural() final;
213 bool selectItemAlignmentFollowsMenuWritingDirection() final;
214 RefPtr<WebCore::PopupMenu> createPopupMenu(WebCore::PopupMenuClient&) const final;
215 RefPtr<WebCore::SearchPopupMenu> createSearchPopupMenu(WebCore::PopupMenuClient&) const final;
216
217 WebCore::GraphicsLayerFactory* graphicsLayerFactory() const final;
218 void attachRootGraphicsLayer(WebCore::Frame&, WebCore::GraphicsLayer*) final;
219 void attachViewOverlayGraphicsLayer(WebCore::GraphicsLayer*) final;
220 void setNeedsOneShotDrawingSynchronization() final;
221 void scheduleCompositingLayerFlush() final;
222 bool adjustLayerFlushThrottling(WebCore::LayerFlushThrottleState::Flags) final;
223
224 void contentRuleListNotification(const URL&, const WebCore::ContentRuleListResults&) final;
225
226#if PLATFORM(WIN)
227 void setLastSetCursorToCurrentCursor() final { }
228 void AXStartFrameLoad() final { }
229 void AXFinishFrameLoad() final { }
230#endif
231
232#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
233 RefPtr<WebCore::DisplayRefreshMonitor> createDisplayRefreshMonitor(WebCore::PlatformDisplayID) const final;
234#endif
235
236 CompositingTriggerFlags allowedCompositingTriggers() const final
237 {
238 return static_cast<CompositingTriggerFlags>(
239 ThreeDTransformTrigger |
240 VideoTrigger |
241 PluginTrigger|
242 CanvasTrigger |
243#if PLATFORM(MAC) || PLATFORM(IOS_FAMILY)
244 ScrollableNonMainFrameTrigger |
245#endif
246#if PLATFORM(IOS_FAMILY)
247 AnimatedOpacityTrigger | // Allow opacity animations to trigger compositing mode for iPhone: <rdar://problem/7830677>
248#endif
249 AnimationTrigger);
250 }
251
252 bool layerTreeStateIsFrozen() const final;
253 bool layerFlushThrottlingIsActive() const final;
254
255#if ENABLE(ASYNC_SCROLLING)
256 RefPtr<WebCore::ScrollingCoordinator> createScrollingCoordinator(WebCore::Page&) const final;
257#endif
258
259#if (PLATFORM(IOS_FAMILY) && HAVE(AVKIT)) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE))
260 bool supportsVideoFullscreen(WebCore::HTMLMediaElementEnums::VideoFullscreenMode) final;
261 bool supportsVideoFullscreenStandby() final;
262 void setUpPlaybackControlsManager(WebCore::HTMLMediaElement&) final;
263 void clearPlaybackControlsManager() final;
264 void enterVideoFullscreenForVideoElement(WebCore::HTMLVideoElement&, WebCore::HTMLMediaElementEnums::VideoFullscreenMode, bool standby) final;
265 void exitVideoFullscreenForVideoElement(WebCore::HTMLVideoElement&) final;
266#endif
267
268#if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)
269 void exitVideoFullscreenToModeWithoutAnimation(WebCore::HTMLVideoElement&, WebCore::HTMLMediaElementEnums::VideoFullscreenMode) final;
270#endif
271
272#if ENABLE(FULLSCREEN_API)
273 bool supportsFullScreenForElement(const WebCore::Element&, bool withKeyboard) final;
274 void enterFullScreenForElement(WebCore::Element&) final;
275 void exitFullScreenForElement(WebCore::Element*) final;
276#endif
277
278#if PLATFORM(COCOA)
279 void elementDidFocus(WebCore::Element&) final;
280 void elementDidBlur(WebCore::Element&) final;
281 void elementDidRefocus(WebCore::Element&) final;
282 void focusedElementDidChangeInputMode(WebCore::Element&, WebCore::InputMode) final;
283
284 void makeFirstResponder() final;
285 void assistiveTechnologyMakeFirstResponder() final;
286#endif
287
288 void enableSuddenTermination() final;
289 void disableSuddenTermination() final;
290
291#if PLATFORM(IOS_FAMILY)
292 WebCore::FloatSize screenSize() const final;
293 WebCore::FloatSize availableScreenSize() const final;
294 WebCore::FloatSize overrideScreenSize() const final;
295#endif
296
297 void dispatchDisabledAdaptationsDidChange(const OptionSet<WebCore::DisabledAdaptations>&) const final;
298 void dispatchViewportPropertiesDidChange(const WebCore::ViewportArguments&) const final;
299
300 void notifyScrollerThumbIsVisibleInRect(const WebCore::IntRect&) final;
301 void recommendedScrollbarStyleDidChange(WebCore::ScrollbarStyle newStyle) final;
302
303 Optional<WebCore::ScrollbarOverlayStyle> preferredScrollbarOverlayStyle() final;
304
305 WebCore::Color underlayColor() const final;
306
307 void pageExtendedBackgroundColorDidChange(WebCore::Color) const final;
308
309 void wheelEventHandlersChanged(bool) final;
310
311 String plugInStartLabelTitle(const String& mimeType) const final;
312 String plugInStartLabelSubtitle(const String& mimeType) const final;
313 String plugInExtraStyleSheet() const final;
314 String plugInExtraScript() const final;
315
316 void didAddHeaderLayer(WebCore::GraphicsLayer&) final;
317 void didAddFooterLayer(WebCore::GraphicsLayer&) final;
318
319 bool shouldUseTiledBackingForFrameView(const WebCore::FrameView&) const final;
320
321 void isPlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags, uint64_t) final;
322 void handleAutoplayEvent(WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final;
323
324#if ENABLE(MEDIA_SESSION)
325 void hasMediaSessionWithActiveMediaElementsDidChange(bool) final;
326 void mediaSessionMetadataDidChange(const WebCore::MediaSessionMetadata&) final;
327 void focusedContentMediaElementDidChange(uint64_t) final;
328#endif
329
330#if ENABLE(WEB_CRYPTO)
331 bool wrapCryptoKey(const Vector<uint8_t>&, Vector<uint8_t>&) const final;
332 bool unwrapCryptoKey(const Vector<uint8_t>&, Vector<uint8_t>&) const final;
333#endif
334
335 String signedPublicKeyAndChallengeString(unsigned keySizeIndex, const String& challengeString, const URL&) const final;
336
337#if ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC)
338 void handleTelephoneNumberClick(const String& number, const WebCore::IntPoint&) final;
339#endif
340
341#if ENABLE(SERVICE_CONTROLS)
342 void handleSelectionServiceClick(WebCore::FrameSelection&, const Vector<String>& telephoneNumbers, const WebCore::IntPoint&) final;
343 bool hasRelevantSelectionServices(bool isTextOnly) const final;
344#endif
345
346 bool shouldDispatchFakeMouseMoveEvents() const final;
347
348 void handleAutoFillButtonClick(WebCore::HTMLInputElement&) final;
349
350 void inputElementDidResignStrongPasswordAppearance(WebCore::HTMLInputElement&) final;
351
352#if ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS_FAMILY)
353 void addPlaybackTargetPickerClient(uint64_t /*contextId*/) final;
354 void removePlaybackTargetPickerClient(uint64_t /*contextId*/) final;
355 void showPlaybackTargetPicker(uint64_t contextId, const WebCore::IntPoint&, bool) final;
356 void playbackTargetPickerClientStateDidChange(uint64_t, WebCore::MediaProducer::MediaStateFlags) final;
357 void setMockMediaPlaybackTargetPickerEnabled(bool) final;
358 void setMockMediaPlaybackTargetPickerState(const String&, WebCore::MediaPlaybackTargetContext::State) final;
359#endif
360
361 void imageOrMediaDocumentSizeChanged(const WebCore::IntSize&) final;
362
363 RefPtr<WebCore::Icon> createIconForFiles(const Vector<String>& filenames) final;
364
365#if ENABLE(VIDEO) && USE(GSTREAMER)
366 void requestInstallMissingMediaPlugins(const String& /*details*/, const String& /*description*/, WebCore::MediaPlayerRequestInstallMissingPluginsCallback&) final;
367#endif
368
369 void didInvalidateDocumentMarkerRects() final;
370
371#if ENABLE(RESOURCE_LOAD_STATISTICS)
372 void hasStorageAccess(WebCore::RegistrableDomain&& subFrameDomain, WebCore::RegistrableDomain&& topFrameDomain, uint64_t frameID, uint64_t pageID, WTF::CompletionHandler<void(bool)>&&) final;
373 void requestStorageAccess(WebCore::RegistrableDomain&& subFrameDomain, WebCore::RegistrableDomain&& topFrameDomain, uint64_t frameID, uint64_t pageID, WTF::CompletionHandler<void(WebCore::StorageAccessWasGranted, WebCore::StorageAccessPromptWasShown)>&&) final;
374#endif
375
376#if ENABLE(DEVICE_ORIENTATION)
377 void shouldAllowDeviceOrientationAndMotionAccess(WebCore::Frame&, bool mayPrompt, CompletionHandler<void(WebCore::DeviceOrientationOrMotionPermissionState)>&&) final;
378#endif
379
380 void configureLoggingChannel(const String&, WTFLogChannelState, WTFLogLevel) final;
381
382 bool userIsInteracting() const final;
383 void setUserIsInteracting(bool) final;
384
385 String m_cachedToolTip;
386 mutable RefPtr<WebFrame> m_cachedFrameSetLargestFrame;
387 mutable bool m_cachedMainFrameHasHorizontalScrollbar { false };
388 mutable bool m_cachedMainFrameHasVerticalScrollbar { false };
389
390 WebPage& m_page;
391};
392
393} // namespace WebKit
394