1/*
2 * Copyright (C) 2014 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#ifndef APIUIClient_h
27#define APIUIClient_h
28
29#include "WKPage.h"
30#include "WebEvent.h"
31#include "WebHitTestResult.h"
32#include "WebPageProxy.h"
33#include <WebCore/FloatRect.h>
34#include <functional>
35#include <wtf/PassRefPtr.h>
36
37#if PLATFORM(IOS)
38OBJC_CLASS NSArray;
39OBJC_CLASS _WKActivatedElementInfo;
40#endif
41
42namespace WebCore {
43class ResourceRequest;
44struct WindowFeatures;
45}
46
47namespace WebKit {
48class GeolocationPermissionRequestProxy;
49class ImmutableDictionary;
50class NativeWebKeyboardEvent;
51class NativeWebWheelEvent;
52class NotificationPermissionRequest;
53class WebColorPickerResultListenerProxy;
54class WebFrameProxy;
55class WebOpenPanelParameters;
56class WebOpenPanelResultListenerProxy;
57class WebPageProxy;
58class WebSecurityOrigin;
59struct NavigationActionData;
60}
61
62namespace API {
63
64class Data;
65class Object;
66
67class UIClient {
68public:
69    virtual ~UIClient() { }
70
71    virtual PassRefPtr<WebKit::WebPageProxy> createNewPage(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, const WebCore::ResourceRequest&, const WebCore::WindowFeatures&, const WebKit::NavigationActionData&) { return nullptr; }
72    virtual void showPage(WebKit::WebPageProxy*) { }
73    virtual void close(WebKit::WebPageProxy*) { }
74
75    virtual void takeFocus(WebKit::WebPageProxy*, WKFocusDirection) { }
76    virtual void focus(WebKit::WebPageProxy*) { }
77    virtual void unfocus(WebKit::WebPageProxy*) { }
78
79    virtual void runJavaScriptAlert(WebKit::WebPageProxy*, const WTF::String&, WebKit::WebFrameProxy*, std::function<void ()> completionHandler) { completionHandler(); }
80    virtual void runJavaScriptConfirm(WebKit::WebPageProxy*, const WTF::String&, WebKit::WebFrameProxy*, std::function<void (bool)> completionHandler) { completionHandler(false); }
81    virtual void runJavaScriptPrompt(WebKit::WebPageProxy*, const WTF::String&, const WTF::String&, WebKit::WebFrameProxy*, std::function<void (const WTF::String&)> completionHandler) { completionHandler(WTF::String()); }
82
83    virtual void setStatusText(WebKit::WebPageProxy*, const WTF::String&) { }
84    virtual void mouseDidMoveOverElement(WebKit::WebPageProxy*, const WebKit::WebHitTestResult::Data&, WebKit::WebEvent::Modifiers, API::Object*) { }
85#if ENABLE(NETSCAPE_PLUGIN_API)
86    virtual void unavailablePluginButtonClicked(WebKit::WebPageProxy*, WKPluginUnavailabilityReason, WebKit::ImmutableDictionary*) { }
87#endif // ENABLE(NETSCAPE_PLUGIN_API)
88
89    virtual bool implementsDidNotHandleKeyEvent() const { return false; }
90    virtual void didNotHandleKeyEvent(WebKit::WebPageProxy*, const WebKit::NativeWebKeyboardEvent&) { }
91
92    virtual bool implementsDidNotHandleWheelEvent() const { return false; }
93    virtual void didNotHandleWheelEvent(WebKit::WebPageProxy*, const WebKit::NativeWebWheelEvent&) { }
94
95    virtual bool toolbarsAreVisible(WebKit::WebPageProxy*) { return true; }
96    virtual void setToolbarsAreVisible(WebKit::WebPageProxy*, bool) { }
97    virtual bool menuBarIsVisible(WebKit::WebPageProxy*) { return true; }
98    virtual void setMenuBarIsVisible(WebKit::WebPageProxy*, bool) { }
99    virtual bool statusBarIsVisible(WebKit::WebPageProxy*) { return true; }
100    virtual void setStatusBarIsVisible(WebKit::WebPageProxy*, bool) { }
101    virtual bool isResizable(WebKit::WebPageProxy*) { return true; }
102    virtual void setIsResizable(WebKit::WebPageProxy*, bool) { }
103
104    virtual void setWindowFrame(WebKit::WebPageProxy*, const WebCore::FloatRect&) { }
105    virtual WebCore::FloatRect windowFrame(WebKit::WebPageProxy*) { return WebCore::FloatRect(); }
106
107    virtual bool canRunBeforeUnloadConfirmPanel() const { return false; }
108    virtual bool runBeforeUnloadConfirmPanel(WebKit::WebPageProxy*, const WTF::String&, WebKit::WebFrameProxy*) { return true; }
109
110    virtual void didDraw(WebKit::WebPageProxy*) { }
111    virtual void pageDidScroll(WebKit::WebPageProxy*) { }
112
113    virtual void exceededDatabaseQuota(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, WebKit::WebSecurityOrigin*, const WTF::String&, const WTF::String&, unsigned long long currentQuota, unsigned long long, unsigned long long, unsigned long long, std::function<void (unsigned long long)> completionHandler)
114    {
115        completionHandler(currentQuota);
116    }
117
118    virtual void reachedApplicationCacheOriginQuota(WebKit::WebPageProxy*, const WebCore::SecurityOrigin&, uint64_t currentQuota, uint64_t, std::function<void (unsigned long long)> completionHandler)
119    {
120        completionHandler(currentQuota);
121    }
122
123    virtual bool runOpenPanel(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, WebKit::WebOpenPanelParameters*, WebKit::WebOpenPanelResultListenerProxy*) { return false; }
124    virtual bool decidePolicyForGeolocationPermissionRequest(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, WebKit::WebSecurityOrigin*, WebKit::GeolocationPermissionRequestProxy*) { return false; }
125    virtual bool decidePolicyForNotificationPermissionRequest(WebKit::WebPageProxy*, WebKit::WebSecurityOrigin*, WebKit::NotificationPermissionRequest*) { return false; }
126
127    // Printing.
128    virtual float headerHeight(WebKit::WebPageProxy*, WebKit::WebFrameProxy*) { return 0; }
129    virtual float footerHeight(WebKit::WebPageProxy*, WebKit::WebFrameProxy*) { return 0; }
130    virtual void drawHeader(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, const WebCore::FloatRect&) { }
131    virtual void drawFooter(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, const WebCore::FloatRect&) { }
132    virtual void printFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy*) { }
133
134    virtual bool canRunModal() const { return false; }
135    virtual void runModal(WebKit::WebPageProxy*) { }
136
137    virtual void saveDataToFileInDownloadsFolder(WebKit::WebPageProxy*, const WTF::String&, const WTF::String&, const WTF::String&, API::Data*) { }
138
139    virtual bool shouldInterruptJavaScript(WebKit::WebPageProxy*) { return false; }
140
141    virtual void pinnedStateDidChange(WebKit::WebPageProxy&) { }
142
143#if PLATFORM(IOS)
144    virtual RetainPtr<NSArray> actionsForElement(_WKActivatedElementInfo *, RetainPtr<NSArray> defaultActions) { return WTF::move(defaultActions); }
145    virtual void didNotHandleTapAsClick(const WebCore::IntPoint&) { }
146#endif
147};
148
149} // namespace API
150
151#endif // APIUIClient_h
152