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 UIClient_h 27#define UIClient_h 28 29#import "WKFoundation.h" 30 31#if WK_API_ENABLED 32 33#import "APIUIClient.h" 34#import "WeakObjCPtr.h" 35#import <wtf/RetainPtr.h> 36 37@class _WKActivatedElementInfo; 38@class WKWebView; 39@protocol WKUIDelegate; 40 41namespace WebKit { 42 43class UIDelegate { 44public: 45 explicit UIDelegate(WKWebView *); 46 ~UIDelegate(); 47 48 std::unique_ptr<API::UIClient> createUIClient(); 49 50 RetainPtr<id <WKUIDelegate> > delegate(); 51 void setDelegate(id <WKUIDelegate>); 52 53private: 54 class UIClient : public API::UIClient { 55 public: 56 explicit UIClient(UIDelegate&); 57 ~UIClient(); 58 59 private: 60 // API::UIClient 61 virtual PassRefPtr<WebKit::WebPageProxy> createNewPage(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, const WebCore::ResourceRequest&, const WebCore::WindowFeatures&, const WebKit::NavigationActionData&) override; 62 virtual void runJavaScriptAlert(WebKit::WebPageProxy*, const WTF::String&, WebKit::WebFrameProxy*, std::function<void ()> completionHandler) override; 63 virtual void runJavaScriptConfirm(WebKit::WebPageProxy*, const WTF::String&, WebKit::WebFrameProxy*, std::function<void (bool)> completionHandler) override; 64 virtual void runJavaScriptPrompt(WebKit::WebPageProxy*, const WTF::String&, const WTF::String&, WebKit::WebFrameProxy*, std::function<void (const WTF::String&)> completionHandler) override; 65 virtual void exceededDatabaseQuota(WebPageProxy*, WebFrameProxy*, WebSecurityOrigin*, const WTF::String& databaseName, const WTF::String& displayName, unsigned long long currentQuota, unsigned long long currentOriginUsage, unsigned long long currentUsage, unsigned long long expectedUsage, std::function<void (unsigned long long)>) override; 66 virtual void reachedApplicationCacheOriginQuota(WebPageProxy*, const WebCore::SecurityOrigin&, uint64_t currentQuota, uint64_t totalBytesNeeded, std::function<void (unsigned long long)> completionHandler) override; 67 virtual void printFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy*) override; 68 #if PLATFORM(IOS) 69 virtual RetainPtr<NSArray> actionsForElement(_WKActivatedElementInfo *, RetainPtr<NSArray> defaultActions) override; 70 virtual void didNotHandleTapAsClick(const WebCore::IntPoint&) override; 71 #endif 72 73 UIDelegate& m_uiDelegate; 74 }; 75 76 WKWebView *m_webView; 77 WeakObjCPtr<id <WKUIDelegate> > m_delegate; 78 79 struct { 80 bool webViewCreateWebViewWithConfigurationForNavigationActionWindowFeatures : 1; 81 bool webViewRunJavaScriptAlertPanelWithMessageInitiatedByFrameCompletionHandler : 1; 82 bool webViewRunJavaScriptConfirmPanelWithMessageInitiatedByFrameCompletionHandler : 1; 83 bool webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler : 1; 84 bool webViewDecideDatabaseQuotaForSecurityOriginCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler : 1; 85 bool webViewDecideWebApplicationCacheQuotaForSecurityOriginCurrentQuotaTotalBytesNeeded : 1; 86 bool webViewPrintFrame : 1; 87#if PLATFORM(IOS) 88 bool webViewActionsForElementDefaultActions : 1; 89 bool webViewDidNotHandleTapAsClickAtPoint : 1; 90#endif 91 } m_delegateMethods; 92}; 93 94} // namespace WebKit 95 96#endif // WK_API_ENABLED 97 98#endif // UIClient_h 99