Implement DownloadMonitor to prevent long-running slow downloads from background...
[WebKit-https.git] / Source / WebKit / UIProcess / ios / PageClientImplIOS.h
1 /*
2  * Copyright (C) 2012-2016 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #pragma once
27
28 #if PLATFORM(IOS_FAMILY)
29
30 #import "PageClientImplCocoa.h"
31 #import "WebFullScreenManagerProxy.h"
32 #import <wtf/RetainPtr.h>
33
34 OBJC_CLASS WKContentView;
35 OBJC_CLASS WKEditorUndoTarget;
36
37 namespace WebCore {
38 enum class DOMPasteAccessResponse : uint8_t;
39 struct PromisedAttachmentInfo;
40 }
41
42 namespace WebKit {
43
44 enum class UndoOrRedo : bool;
45
46 class PageClientImpl : public PageClientImplCocoa
47 #if ENABLE(FULLSCREEN_API)
48     , public WebFullScreenManagerProxyClient
49 #endif
50     {
51 public:
52     PageClientImpl(WKContentView *, WKWebView *);
53     virtual ~PageClientImpl();
54     
55 private:
56     // PageClient
57     std::unique_ptr<DrawingAreaProxy> createDrawingAreaProxy(WebProcessProxy&) override;
58     void setViewNeedsDisplay(const WebCore::Region&) override;
59     void requestScroll(const WebCore::FloatPoint& scrollPosition, const WebCore::IntPoint& scrollOrigin, bool isProgrammaticScroll) override;
60     WebCore::FloatPoint viewScrollPosition() override;
61     WebCore::IntSize viewSize() override;
62     bool isViewWindowActive() override;
63     bool isViewFocused() override;
64     bool isViewVisible() override;
65     bool isViewInWindow() override;
66     bool isViewVisibleOrOccluded() override;
67     bool isVisuallyIdle() override;
68     void processDidExit() override;
69     void processWillSwap() override;
70     void didRelaunchProcess() override;
71     void pageClosed() override;
72     void preferencesDidChange() override;
73     void toolTipChanged(const String&, const String&) override;
74     void decidePolicyForGeolocationPermissionRequest(WebFrameProxy&, API::SecurityOrigin&, Function<void(bool)>&) override;
75     void didStartProvisionalLoadForMainFrame() override;
76     void didFailProvisionalLoadForMainFrame() override;
77     void didCommitLoadForMainFrame(const String& mimeType, bool useCustomContentProvider) override;
78     void handleDownloadRequest(DownloadProxy&) override;
79     void didChangeContentSize(const WebCore::IntSize&) override;
80     void setCursor(const WebCore::Cursor&) override;
81     void setCursorHiddenUntilMouseMoves(bool) override;
82     void didChangeViewportProperties(const WebCore::ViewportAttributes&) override;
83     void registerEditCommand(Ref<WebEditCommandProxy>&&, UndoOrRedo) override;
84     void clearAllEditCommands() override;
85     bool canUndoRedo(UndoOrRedo) override;
86     void executeUndoRedo(UndoOrRedo) override;
87     void accessibilityWebProcessTokenReceived(const IPC::DataReference&) override;
88     bool executeSavedCommandBySelector(const String& selector) override;
89     void updateSecureInputState() override;
90     void resetSecureInputState() override;
91     void notifyInputContextAboutDiscardedComposition() override;
92     void makeFirstResponder() override;
93     void assistiveTechnologyMakeFirstResponder() override;
94     WebCore::FloatRect convertToDeviceSpace(const WebCore::FloatRect&) override;
95     WebCore::FloatRect convertToUserSpace(const WebCore::FloatRect&) override;
96     WebCore::IntPoint screenToRootView(const WebCore::IntPoint&) override;
97     WebCore::IntRect rootViewToScreen(const WebCore::IntRect&) override;
98     WebCore::IntPoint accessibilityScreenToRootView(const WebCore::IntPoint&) override;
99     WebCore::IntRect rootViewToAccessibilityScreen(const WebCore::IntRect&) override;
100     void doneWithKeyEvent(const NativeWebKeyboardEvent&, bool wasEventHandled) override;
101 #if ENABLE(TOUCH_EVENTS)
102     void doneWithTouchEvent(const NativeWebTouchEvent&, bool wasEventHandled) override;
103 #endif
104     RefPtr<WebPopupMenuProxy> createPopupMenuProxy(WebPageProxy&) override;
105     Ref<WebCore::ValidationBubble> createValidationBubble(const String& message, const WebCore::ValidationBubble::Settings&) final;
106
107 #if ENABLE(INPUT_TYPE_COLOR)
108     RefPtr<WebColorPicker> createColorPicker(WebPageProxy*, const WebCore::Color& initialColor, const WebCore::IntRect&, Vector<WebCore::Color>&&) final;
109 #endif
110
111 #if ENABLE(DATALIST_ELEMENT)
112     RefPtr<WebDataListSuggestionsDropdown> createDataListSuggestionsDropdown(WebPageProxy&) final;
113 #endif
114
115     void setTextIndicator(Ref<WebCore::TextIndicator>, WebCore::TextIndicatorWindowLifetime) override;
116     void clearTextIndicator(WebCore::TextIndicatorWindowDismissalAnimation) override;
117     void setTextIndicatorAnimationProgress(float) override;
118
119     void showSafeBrowsingWarning(const SafeBrowsingWarning&, CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, URL>&&)>&&) override;
120     void clearSafeBrowsingWarning() override;
121     void clearSafeBrowsingWarningIfForMainFrameNavigation() override;
122
123     void enterAcceleratedCompositingMode(const LayerTreeContext&) override;
124     void exitAcceleratedCompositingMode() override;
125     void updateAcceleratedCompositingMode(const LayerTreeContext&) override;
126     void setRemoteLayerTreeRootNode(RemoteLayerTreeNode*) override;
127     CALayer* acceleratedCompositingRootLayer() const override;
128     LayerHostingMode viewLayerHostingMode() override { return LayerHostingMode::OutOfProcess; }
129
130     RefPtr<ViewSnapshot> takeViewSnapshot() override;
131     void wheelEventWasNotHandledByWebCore(const NativeWebWheelEvent&) override;
132
133     void commitPotentialTapFailed() override;
134     void didGetTapHighlightGeometries(uint64_t requestID, const WebCore::Color&, const Vector<WebCore::FloatQuad>& highlightedQuads, const WebCore::IntSize& topLeftRadius, const WebCore::IntSize& topRightRadius, const WebCore::IntSize& bottomLeftRadius, const WebCore::IntSize& bottomRightRadius, bool nodeHasBuiltInClickHandling) override;
135
136     void didCommitLayerTree(const RemoteLayerTreeTransaction&) override;
137     void layerTreeCommitComplete() override;
138         
139     void didPerformDictionaryLookup(const WebCore::DictionaryPopupInfo&) override;
140
141 #if USE(APPLE_INTERNAL_SDK)
142 #include <WebKitAdditions/PageClientImplIOSAdditions.h>
143 #endif
144
145     void couldNotRestorePageState() override;
146     void restorePageState(Optional<WebCore::FloatPoint>, const WebCore::FloatPoint&, const WebCore::FloatBoxExtent&, double) override;
147     void restorePageCenterAndScale(Optional<WebCore::FloatPoint>, double) override;
148
149     void elementDidFocus(const FocusedElementInformation&, bool userIsInteracting, bool blurPreviousNode, bool changingActivityState, API::Object* userData) override;
150     void elementDidBlur() override;
151     void focusedElementDidChangeInputMode(WebCore::InputMode) override;
152     void didReceiveEditorStateUpdateAfterFocus() override;
153     bool isFocusingElement() override;
154     void selectionDidChange() override;
155     bool interpretKeyEvent(const NativeWebKeyboardEvent&, bool isCharEvent) override;
156     void positionInformationDidChange(const InteractionInformationAtPosition&) override;
157     void saveImageToLibrary(Ref<WebCore::SharedBuffer>&&) override;
158     void showPlaybackTargetPicker(bool hasVideo, const WebCore::IntRect& elementRect, WebCore::RouteSharingPolicy, const String&) override;
159
160     bool handleRunOpenPanel(WebPageProxy*, WebFrameProxy*, API::OpenPanelParameters*, WebOpenPanelResultListenerProxy*) override;
161     bool showShareSheet(const WebCore::ShareDataWithParsedURL&, WTF::CompletionHandler<void(bool)>&&) override;
162     
163     void disableDoubleTapGesturesDuringTapIfNecessary(uint64_t requestID) override;
164     void handleSmartMagnificationInformationForPotentialTap(uint64_t requestID, const WebCore::FloatRect& renderRect, bool fitEntireRect, double viewportMinimumScale, double viewportMaximumScale) override;
165
166     double minimumZoomScale() const override;
167     WebCore::FloatRect documentRect() const override;
168
169     void showInspectorHighlight(const WebCore::Highlight&) override;
170     void hideInspectorHighlight() override;
171
172     void showInspectorIndication() override;
173     void hideInspectorIndication() override;
174
175     void enableInspectorNodeSearch() override;
176     void disableInspectorNodeSearch() override;
177
178     void scrollingNodeScrollViewWillStartPanGesture() override;
179     void scrollingNodeScrollViewDidScroll() override;
180     void scrollingNodeScrollWillStartScroll() override;
181     void scrollingNodeScrollDidEndScroll() override;
182
183     // Auxiliary Client Creation
184 #if ENABLE(FULLSCREEN_API)
185     WebFullScreenManagerProxyClient& fullScreenManagerProxyClient() override;
186 #endif
187
188 #if ENABLE(FULLSCREEN_API)
189     // WebFullScreenManagerProxyClient
190     void closeFullScreenManager() override;
191     bool isFullScreen() override;
192     void enterFullScreen() override;
193     void exitFullScreen() override;
194     void beganEnterFullScreen(const WebCore::IntRect& initialFrame, const WebCore::IntRect& finalFrame) override;
195     void beganExitFullScreen(const WebCore::IntRect& initialFrame, const WebCore::IntRect& finalFrame) override;
196 #endif
197
198     void didFinishLoadingDataForCustomContentProvider(const String& suggestedFilename, const IPC::DataReference&) override;
199
200     Vector<String> mimeTypesWithCustomContentProviders() override;
201
202     void navigationGestureDidBegin() override;
203     void navigationGestureWillEnd(bool willNavigate, WebBackForwardListItem&) override;
204     void navigationGestureDidEnd(bool willNavigate, WebBackForwardListItem&) override;
205     void navigationGestureDidEnd() override;
206     void willRecordNavigationSnapshot(WebBackForwardListItem&) override;
207     void didRemoveNavigationGestureSnapshot() override;
208
209     void didFirstVisuallyNonEmptyLayoutForMainFrame() override;
210     void didFinishLoadForMainFrame() override;
211     void didFailLoadForMainFrame() override;
212     void didSameDocumentNavigationForMainFrame(SameDocumentNavigationType) override;
213     void didNotHandleTapAsClick(const WebCore::IntPoint&) override;
214     void didCompleteSyntheticClick() override;
215
216     void didChangeBackgroundColor() override;
217     void videoControlsManagerDidChange() override;
218
219     void refView() override;
220     void derefView() override;
221
222     void didRestoreScrollPosition() override;
223
224     WebCore::UserInterfaceLayoutDirection userInterfaceLayoutDirection() override;
225
226 #if USE(QUICK_LOOK)
227     void requestPasswordForQuickLookDocument(const String& fileName, WTF::Function<void(const String&)>&&) override;
228 #endif
229
230     void requestDOMPasteAccess(const WebCore::IntRect& elementRect, const String&, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&) final;
231
232 #if ENABLE(DATA_INTERACTION)
233     void didPerformDragOperation(bool handled) override;
234     void didHandleDragStartRequest(bool started) override;
235     void didHandleAdditionalDragItemsRequest(bool added) override;
236     void startDrag(const WebCore::DragItem&, const ShareableBitmap::Handle& image) override;
237     void didConcludeEditDrag(Optional<WebCore::TextIndicatorData>) override;
238     void didChangeDragCaretRect(const WebCore::IntRect& previousCaretRect, const WebCore::IntRect& caretRect) override;
239 #endif
240
241     void handleAutocorrectionContext(const WebAutocorrectionContext&) final;
242
243     void didFinishProcessingAllPendingMouseEvents() final { }
244
245 #if HAVE(PENCILKIT)
246     RetainPtr<WKDrawingView> createDrawingView(WebCore::GraphicsLayer::EmbeddedViewID) override;
247 #endif
248
249 #if ENABLE(POINTER_EVENTS)
250     void cancelPointersForGestureRecognizer(UIGestureRecognizer*) override;
251 #endif
252
253     WKContentView *m_contentView;
254     RetainPtr<WKEditorUndoTarget> m_undoTarget;
255 };
256 } // namespace WebKit
257
258 #endif // PLATFORM(IOS_FAMILY)