diff options
| author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2016-05-24 08:28:08 +0000 |
|---|---|---|
| committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2016-05-24 08:28:08 +0000 |
| commit | a4e969f4965059196ca948db781e52f7cfebf19e (patch) | |
| tree | 6ca352808c8fdc52006a0f33f6ae3c593b23867d /Source/WebKit2/UIProcess | |
| parent | 41386e9cb918eed93b3f13648cbef387e371e451 (diff) | |
| download | WebKitGtk-tarball-a4e969f4965059196ca948db781e52f7cfebf19e.tar.gz | |
webkitgtk-2.12.3webkitgtk-2.12.3
Diffstat (limited to 'Source/WebKit2/UIProcess')
605 files changed, 37446 insertions, 14284 deletions
diff --git a/Source/WebKit2/UIProcess/API/APIAutomationClient.h b/Source/WebKit2/UIProcess/API/APIAutomationClient.h new file mode 100644 index 000000000..299581095 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIAutomationClient.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef APIAutomationClient_h +#define APIAutomationClient_h + +#include <wtf/Forward.h> + +namespace WebKit { +class WebProcessPool; +} + +namespace API { + +class AutomationClient { +public: + virtual ~AutomationClient() { } + + virtual bool allowsRemoteAutomation(WebKit::WebProcessPool*) { return false; } + virtual void didRequestAutomationSession(WebKit::WebProcessPool*, const WTF::String&) { } +}; + +} // namespace API + +#endif // APIAutomationClient_h diff --git a/Source/WebKit2/UIProcess/API/APIAutomationSessionClient.h b/Source/WebKit2/UIProcess/API/APIAutomationSessionClient.h new file mode 100644 index 000000000..18edacb56 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIAutomationSessionClient.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef APIAutomationSessionClient_h +#define APIAutomationSessionClient_h + +#include <wtf/text/WTFString.h> + +namespace WebKit { +class WebAutomationSession; +class WebProcessPool; +} + +namespace API { + +class AutomationSessionClient { +public: + virtual ~AutomationSessionClient() { } + + virtual String sessionIdentifier() const { return String(); } + virtual void didRequestNewWindow(WebKit::WebProcessPool*, WebKit::WebAutomationSession*) { } +}; + +} // namespace API + +#endif // APIAutomationSessionClient_h diff --git a/Source/WebKit2/UIProcess/API/APIContextMenuClient.h b/Source/WebKit2/UIProcess/API/APIContextMenuClient.h new file mode 100644 index 000000000..f8f2023c1 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIContextMenuClient.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2014 Igalia S.L. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef APIContextMenuClient_h +#define APIContextMenuClient_h + +#if ENABLE(CONTEXT_MENUS) + +#include "WebHitTestResultData.h" +#include <wtf/RefPtr.h> +#include <wtf/Vector.h> + +OBJC_CLASS NSMenu; + +namespace WebCore { +class IntPoint; +} + +namespace WebKit { +class WebContextMenuItem; +class WebContextMenuItemData; +class WebPageProxy; +} + +namespace API { + +class ContextMenuClient { +public: + virtual ~ContextMenuClient() { } + + virtual bool getContextMenuFromProposedMenu(WebKit::WebPageProxy&, const Vector<RefPtr<WebKit::WebContextMenuItem>>& /* proposedMenu */, Vector<RefPtr<WebKit::WebContextMenuItem>>& /* customMenu */, const WebKit::WebHitTestResultData&, API::Object* /* userData */) { return false; } + virtual void customContextMenuItemSelected(WebKit::WebPageProxy&, const WebKit::WebContextMenuItemData&) { } + virtual bool showContextMenu(WebKit::WebPageProxy&, const WebCore::IntPoint&, const Vector<RefPtr<WebKit::WebContextMenuItem>>&) { return false; } + virtual bool hideContextMenu(WebKit::WebPageProxy&) { return false; } + +#if PLATFORM(MAC) + virtual RetainPtr<NSMenu> menuFromProposedMenu(WebKit::WebPageProxy&, NSMenu *menu, const WebKit::WebHitTestResultData&, API::Object*) { return menu; } +#endif +}; + +} // namespace API + +#endif // ENABLE(CONTEXT_MENUS) +#endif // APIContextMenuClient_h diff --git a/Source/WebKit2/UIProcess/WebColorPickerResultListenerProxy.h b/Source/WebKit2/UIProcess/API/APIDiagnosticLoggingClient.h index 58268c6cc..f54a0b1ad 100644 --- a/Source/WebKit2/UIProcess/WebColorPickerResultListenerProxy.h +++ b/Source/WebKit2/UIProcess/API/APIDiagnosticLoggingClient.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Samsung Electronics. All rights reserved. + * Copyright (C) 2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -10,7 +10,7 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS AS IS'' + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS @@ -23,40 +23,28 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef WebColorPickerResultListenerProxy_h -#define WebColorPickerResultListenerProxy_h +#ifndef APIDiagnosticLoggingClient_h +#define APIDiagnosticLoggingClient_h -#if ENABLE(INPUT_TYPE_COLOR) - -#include "APIObject.h" -#include <wtf/PassRefPtr.h> -#include <wtf/RefPtr.h> +#include <WebCore/DiagnosticLoggingResultType.h> #include <wtf/text/WTFString.h> namespace WebKit { - class WebPageProxy; +} -class WebColorPickerResultListenerProxy : public API::ObjectImpl<API::Object::Type::ColorPickerResultListener> { -public: - static PassRefPtr<WebColorPickerResultListenerProxy> create(WebPageProxy* page) - { - return adoptRef(new WebColorPickerResultListenerProxy(page)); - } - - virtual ~WebColorPickerResultListenerProxy(); - - void invalidate(); - void setColor(const String&); +namespace API { -private: - explicit WebColorPickerResultListenerProxy(WebPageProxy*); +class DiagnosticLoggingClient { +public: + virtual ~DiagnosticLoggingClient() { } - RefPtr<WebPageProxy> m_page; + virtual void logDiagnosticMessage(WebKit::WebPageProxy*, const WTF::String& message, const WTF::String& description) { UNUSED_PARAM(message); UNUSED_PARAM(description); } + virtual void logDiagnosticMessageWithResult(WebKit::WebPageProxy*, const WTF::String& message, const WTF::String& description, WebCore::DiagnosticLoggingResultType) { UNUSED_PARAM(message); UNUSED_PARAM(description); } + virtual void logDiagnosticMessageWithValue(WebKit::WebPageProxy*, const WTF::String& message, const WTF::String& description, const WTF::String& value) { UNUSED_PARAM(message); UNUSED_PARAM(description); UNUSED_PARAM(value); } }; -} // namespace WebKit +} // namespace API -#endif // ENABLE(INPUT_TYPE_COLOR) +#endif // APIDiagnosticLoggingClient_h -#endif // WebColorPickerResultListenerProxy_h diff --git a/Source/WebKit2/UIProcess/API/APIDownloadClient.h b/Source/WebKit2/UIProcess/API/APIDownloadClient.h new file mode 100644 index 000000000..2a7e3a6ba --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIDownloadClient.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef APIDownloadClient_h +#define APIDownloadClient_h + +#include <functional> +#include <wtf/text/WTFString.h> + +namespace WebCore { +class ResourceError; +class ResourceRequest; +class ResourceResponse; +} + +namespace WebKit { +class AuthenticationChallengeProxy; +class DownloadProxy; +class WebProcessPool; +class WebProtectionSpace; +} + +namespace API { + +class DownloadClient { +public: + virtual ~DownloadClient() { } + + virtual void didStart(WebKit::WebProcessPool*, WebKit::DownloadProxy*) { } + virtual void didReceiveAuthenticationChallenge(WebKit::WebProcessPool*, WebKit::DownloadProxy*, WebKit::AuthenticationChallengeProxy*) { } + virtual void didReceiveResponse(WebKit::WebProcessPool*, WebKit::DownloadProxy*, const WebCore::ResourceResponse&) { } + virtual void didReceiveData(WebKit::WebProcessPool*, WebKit::DownloadProxy*, uint64_t) { } + virtual bool shouldDecodeSourceDataOfMIMEType(WebKit::WebProcessPool*, WebKit::DownloadProxy*, const WTF::String&) { return true; } + virtual WTF::String decideDestinationWithSuggestedFilename(WebKit::WebProcessPool*, WebKit::DownloadProxy*, const WTF::String&, bool&) { return { }; } + virtual void didCreateDestination(WebKit::WebProcessPool*, WebKit::DownloadProxy*, const WTF::String&) { } + virtual void didFinish(WebKit::WebProcessPool*, WebKit::DownloadProxy*) { } + virtual void didFail(WebKit::WebProcessPool*, WebKit::DownloadProxy*, const WebCore::ResourceError&) { } + virtual void didCancel(WebKit::WebProcessPool*, WebKit::DownloadProxy*) { } + virtual void processDidCrash(WebKit::WebProcessPool*, WebKit::DownloadProxy*) { } + virtual bool canAuthenticateAgainstProtectionSpace(WebKit::WebProtectionSpace*) { return true; } + virtual void willSendRequest(const WebCore::ResourceRequest& request, const WebCore::ResourceResponse&, std::function<void(const WebCore::ResourceRequest&)> callback) { callback(request); } +}; + +} // namespace API + +#endif // APIDownloadClient_h diff --git a/Source/WebKit2/UIProcess/API/APIFindClient.h b/Source/WebKit2/UIProcess/API/APIFindClient.h new file mode 100644 index 000000000..0abf8f673 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIFindClient.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef APIFindClient_h +#define APIFindClient_h + +#include <wtf/text/WTFString.h> + +namespace WebCore { +class IntRect; +} + +namespace WebKit { +class WebPageProxy; +} + +namespace API { + +class FindClient { +public: + virtual ~FindClient() { } + + virtual void didCountStringMatches(WebKit::WebPageProxy*, const WTF::String&, uint32_t) { } + virtual void didFindString(WebKit::WebPageProxy*, const WTF::String&, const Vector<WebCore::IntRect>& matchRects, uint32_t, int32_t) { } + virtual void didFailToFindString(WebKit::WebPageProxy*, const WTF::String&) { } +}; + +} // namespace API + +#endif // APIFindClient_h diff --git a/Source/WebKit2/UIProcess/API/APIFindMatchesClient.h b/Source/WebKit2/UIProcess/API/APIFindMatchesClient.h new file mode 100644 index 000000000..c6f457342 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIFindMatchesClient.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef APIFindMatchesClient_h +#define APIFindMatchesClient_h + +#include <WebCore/IntRect.h> +#include <wtf/Vector.h> +#include <wtf/text/WTFString.h> + +namespace WebKit { +class WebImage; +class WebPageProxy; +} + +namespace API { + +class FindMatchesClient { +public: + virtual ~FindMatchesClient() { } + + virtual void didFindStringMatches(WebKit::WebPageProxy*, const WTF::String&, const WTF::Vector<WTF::Vector<WebCore::IntRect>>&, int32_t) { } + virtual void didGetImageForMatchResult(WebKit::WebPageProxy*, WebKit::WebImage*, int32_t) { } +}; + +} // namespace API + +#endif // APIFindMatchesClient_h diff --git a/Source/WebKit2/UIProcess/WebOriginDataManagerProxyChangeClient.h b/Source/WebKit2/UIProcess/API/APIFormClient.h index 2fea808ac..44c005ba6 100644 --- a/Source/WebKit2/UIProcess/WebOriginDataManagerProxyChangeClient.h +++ b/Source/WebKit2/UIProcess/API/APIFormClient.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Apple Inc. All rights reserved. + * Copyright (C) 2014 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -23,28 +23,31 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef WebOriginDataManagerProxyChangeClient_h -#define WebOriginDataManagerProxyChangeClient_h +#ifndef APIFormClient_h +#define APIFormClient_h -#include "APIClient.h" -#include "WKOriginDataManager.h" +#include "WebFormSubmissionListenerProxy.h" #include <wtf/Forward.h> - -namespace API { -template<> struct ClientTraits<WKOriginDataManagerChangeClientBase> { - typedef std::tuple<WKOriginDataManagerChangeClientV0> Versions; -}; -} +#include <wtf/Vector.h> namespace WebKit { +class WebFrameProxy; +class WebPageProxy; +} -class WebOriginDataManagerProxy; +namespace API { +class Object; -class WebOriginDataManagerProxyChangeClient : public API::Client<WKOriginDataManagerChangeClientBase> { +class FormClient { public: - void didChange(WebOriginDataManagerProxy*); + virtual ~FormClient() { } + + virtual void willSubmitForm(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, WebKit::WebFrameProxy&, const Vector<std::pair<WTF::String, WTF::String>>&, API::Object*, Ref<WebKit::WebFormSubmissionListenerProxy>&& listener) + { + listener->continueSubmission(); + } }; -} // namespace WebKit +} // namespace API -#endif // WebOriginDataManagerProxyChangeClient_h +#endif // APIFormClient_h diff --git a/Source/WebKit2/UIProcess/API/APIFrameInfo.cpp b/Source/WebKit2/UIProcess/API/APIFrameInfo.cpp new file mode 100644 index 000000000..91dc42957 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIFrameInfo.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "APIFrameInfo.h" + +#include "APIFrameHandle.h" +#include "WebFrameProxy.h" + +namespace API { + +// FIXME: This should use the full request of the frame, not just the URL. +FrameInfo::FrameInfo(const WebKit::WebFrameProxy& frame, const WebCore::SecurityOrigin& securityOrigin) + : m_isMainFrame(frame.isMainFrame()) + , m_request(WebCore::ResourceRequest(frame.url())) + , m_securityOrigin(adoptRef(*SecurityOrigin::create(securityOrigin).leakRef())) + , m_handle(API::FrameHandle::create(frame.frameID())) +{ +} + +FrameInfo::~FrameInfo() +{ +} + +} // namespace API diff --git a/Source/WebKit2/UIProcess/WebKeyValueStorageManager.h b/Source/WebKit2/UIProcess/API/APIFrameInfo.h index 3e15f9b4c..7a4796374 100644 --- a/Source/WebKit2/UIProcess/WebKeyValueStorageManager.h +++ b/Source/WebKit2/UIProcess/API/APIFrameInfo.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011, 2013 Apple Inc. All rights reserved. + * Copyright (C) 2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -23,43 +23,47 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef WebKeyValueStorageManager_h -#define WebKeyValueStorageManager_h +#ifndef APIFrameInfo_h +#define APIFrameInfo_h #include "APIObject.h" -#include "GenericCallback.h" -#include "MessageReceiver.h" -#include "WebContextSupplement.h" -#include <wtf/PassRefPtr.h> -#include <wtf/RefPtr.h> -#include <wtf/Vector.h> +#include <WebCore/ResourceRequest.h> + +namespace WebCore { +class SecurityOrigin; +} namespace WebKit { +class WebFrameProxy; +} -typedef GenericCallback<WKArrayRef> ArrayCallback; +namespace API { -class WebKeyValueStorageManager : public API::ObjectImpl<API::Object::Type::KeyValueStorageManager>, public WebContextSupplement { -public: - static const char* supplementName(); +class FrameHandle; +class SecurityOrigin; - static PassRefPtr<WebKeyValueStorageManager> create(WebContext*); - virtual ~WebKeyValueStorageManager(); +class FrameInfo final : public ObjectImpl<Object::Type::FrameInfo> { +public: + static Ref<FrameInfo> create(const WebKit::WebFrameProxy& frame, const WebCore::SecurityOrigin& securityOrigin) + { + return adoptRef(*new FrameInfo(frame, securityOrigin)); + } + virtual ~FrameInfo(); - void getKeyValueStorageOrigins(PassRefPtr<ArrayCallback>); - void deleteEntriesForOrigin(WebSecurityOrigin*); - void deleteAllEntries(); + FrameInfo(const WebKit::WebFrameProxy&, const WebCore::SecurityOrigin&); - using API::Object::ref; - using API::Object::deref; + bool isMainFrame() const { return m_isMainFrame; } + const WebCore::ResourceRequest& request() const { return m_request; } + SecurityOrigin& securityOrigin() { return m_securityOrigin.get(); } + API::FrameHandle& handle() { return m_handle.get(); } private: - explicit WebKeyValueStorageManager(WebContext*); - - // WebContextSupplement - virtual void refWebContextSupplement() override; - virtual void derefWebContextSupplement() override; + bool m_isMainFrame; + WebCore::ResourceRequest m_request; + Ref<SecurityOrigin> m_securityOrigin; + Ref<FrameHandle> m_handle; }; -} // namespace WebKit +} // namespace API -#endif // WebKeyValueStorageManager_h +#endif // APIFrameInfo_h diff --git a/Source/WebKit2/UIProcess/API/APIHistoryClient.h b/Source/WebKit2/UIProcess/API/APIHistoryClient.h new file mode 100644 index 000000000..77fca2656 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIHistoryClient.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2014, 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef APIHistoryClient_h +#define APIHistoryClient_h + +#include <wtf/Forward.h> + +namespace WebKit { +class WebPageProxy; +struct WebNavigationDataStore; +} + +namespace API { + +class HistoryClient { +public: + virtual ~HistoryClient() { } + + virtual void didNavigateWithNavigationData(WebKit::WebPageProxy&, const WebKit::WebNavigationDataStore&) { } + virtual void didPerformClientRedirect(WebKit::WebPageProxy&, const WTF::String&, const WTF::String&) { } + virtual void didPerformServerRedirect(WebKit::WebPageProxy&, const WTF::String&, const WTF::String&) { } + virtual void didUpdateHistoryTitle(WebKit::WebPageProxy&, const WTF::String&, const WTF::String&) { } +}; + +} // namespace API + +#endif // APIHistoryClient_h diff --git a/Source/WebKit2/UIProcess/API/APIHitTestResult.cpp b/Source/WebKit2/UIProcess/API/APIHitTestResult.cpp new file mode 100644 index 000000000..4d4e06234 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIHitTestResult.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "APIHitTestResult.h" + +using namespace WebCore; + +namespace API { + +PassRefPtr<HitTestResult> HitTestResult::create(const WebKit::WebHitTestResultData& hitTestResultData) +{ + return adoptRef(new HitTestResult(hitTestResultData)); +} + +} // namespace API diff --git a/Source/WebKit2/UIProcess/API/APIHitTestResult.h b/Source/WebKit2/UIProcess/API/APIHitTestResult.h new file mode 100644 index 000000000..709579a6b --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIHitTestResult.h @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef APIHitTestResult_h +#define APIHitTestResult_h + +#include "APIObject.h" +#include "SharedMemory.h" +#include "WebHitTestResultData.h" +#include <WebCore/DictionaryPopupInfo.h> +#include <WebCore/FloatPoint.h> +#include <WebCore/IntRect.h> +#include <WebCore/PageOverlay.h> +#include <wtf/Forward.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefPtr.h> +#include <wtf/text/WTFString.h> + +OBJC_CLASS DDActionContext; + +namespace IPC { +class ArgumentDecoder; +class ArgumentEncoder; +} + +namespace WebCore { +class HitTestResult; +} + +namespace API { + +class WebFrame; + +class HitTestResult : public API::ObjectImpl<API::Object::Type::HitTestResult> { +public: + static PassRefPtr<HitTestResult> create(const WebKit::WebHitTestResultData&); + + WTF::String absoluteImageURL() const { return m_data.absoluteImageURL; } + WTF::String absolutePDFURL() const { return m_data.absolutePDFURL; } + WTF::String absoluteLinkURL() const { return m_data.absoluteLinkURL; } + WTF::String absoluteMediaURL() const { return m_data.absoluteMediaURL; } + + WTF::String linkLabel() const { return m_data.linkLabel; } + WTF::String linkTitle() const { return m_data.linkTitle; } + WTF::String lookupText() const { return m_data.lookupText; } + + bool isContentEditable() const { return m_data.isContentEditable; } + + WebCore::IntRect elementBoundingBox() const { return m_data.elementBoundingBox; } + + bool isScrollbar() const { return m_data.isScrollbar; } + + bool isSelected() const { return m_data.isSelected; } + + bool isTextNode() const { return m_data.isTextNode; } + + bool isOverTextInsideFormControlElement() const { return m_data.isOverTextInsideFormControlElement; } + + bool allowsCopy() const { return m_data.allowsCopy; } + + bool isDownloadableMedia() const { return m_data.isDownloadableMedia; } + +private: + explicit HitTestResult(const WebKit::WebHitTestResultData& hitTestResultData) + : m_data(hitTestResultData) + { + } + + WebKit::WebHitTestResultData m_data; +}; + +} // namespace API + +#endif // APIHitTestResult_h diff --git a/Source/WebKit2/UIProcess/WebHistoryClient.h b/Source/WebKit2/UIProcess/API/APILegacyContextHistoryClient.h index c748d77cf..cbb9e0a97 100644 --- a/Source/WebKit2/UIProcess/WebHistoryClient.h +++ b/Source/WebKit2/UIProcess/API/APILegacyContextHistoryClient.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2014 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -23,37 +23,32 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef WebHistoryClient_h -#define WebHistoryClient_h +#ifndef APILegacyContextHistoryClient_h +#define APILegacyContextHistoryClient_h -#include "APIClient.h" -#include "WKContext.h" #include <wtf/Forward.h> -namespace API { -template<> struct ClientTraits<WKContextHistoryClientBase> { - typedef std::tuple<WKContextHistoryClientV0> Versions; -}; -} - namespace WebKit { - -class WebContext; class WebFrameProxy; class WebPageProxy; +class WebProcessPool; struct WebNavigationDataStore; +} -class WebHistoryClient : public API::Client<WKContextHistoryClientBase> { -public: - void didNavigateWithNavigationData(WebContext*, WebPageProxy*, const WebNavigationDataStore&, WebFrameProxy*); - void didPerformClientRedirect(WebContext*, WebPageProxy*, const String& sourceURL, const String& destinationURL, WebFrameProxy*); - void didPerformServerRedirect(WebContext*, WebPageProxy*, const String& sourceURL, const String& destinationURL, WebFrameProxy*); - void didUpdateHistoryTitle(WebContext*, WebPageProxy*, const String& title, const String& url, WebFrameProxy*); - void populateVisitedLinks(WebContext*); +namespace API { - bool shouldTrackVisitedLinks() const { return m_client.populateVisitedLinks; } +class LegacyContextHistoryClient { +public: + virtual ~LegacyContextHistoryClient() { } + + virtual void didNavigateWithNavigationData(WebKit::WebProcessPool&, WebKit::WebPageProxy&, const WebKit::WebNavigationDataStore&, WebKit::WebFrameProxy&) { } + virtual void didPerformClientRedirect(WebKit::WebProcessPool&, WebKit::WebPageProxy&, const WTF::String&, const WTF::String&, WebKit::WebFrameProxy&) { } + virtual void didPerformServerRedirect(WebKit::WebProcessPool&, WebKit::WebPageProxy&, const WTF::String&, const WTF::String&, WebKit::WebFrameProxy&) { } + virtual void didUpdateHistoryTitle(WebKit::WebProcessPool&, WebKit::WebPageProxy&, const WTF::String&, const WTF::String&, WebKit::WebFrameProxy&) { } + virtual void populateVisitedLinks(WebKit::WebProcessPool&) { } + virtual bool addsVisitedLinks() const { return false; } }; -} // namespace WebKit +} // namespace API -#endif // WebHistoryClient_h +#endif // APILegacyContextHistoryClient_h diff --git a/Source/WebKit2/UIProcess/API/APILoaderClient.h b/Source/WebKit2/UIProcess/API/APILoaderClient.h index f7d68b1fb..eff556ae8 100644 --- a/Source/WebKit2/UIProcess/API/APILoaderClient.h +++ b/Source/WebKit2/UIProcess/API/APILoaderClient.h @@ -26,6 +26,7 @@ #ifndef APILoaderClient_h #define APILoaderClient_h +#include "APIData.h" #include "PluginModuleInfo.h" #include "SameDocumentNavigationType.h" #include <WebCore/FrameLoaderTypes.h> @@ -38,67 +39,86 @@ class ResourceError; namespace WebKit { class AuthenticationChallengeProxy; -class ImmutableDictionary; +class QuickLookDocumentData; class WebBackForwardListItem; class WebFrameProxy; class WebPageProxy; class WebProtectionSpace; +struct WebNavigationDataStore; } namespace API { +class Dictionary; +class Navigation; class Object; class LoaderClient { public: virtual ~LoaderClient() { } - virtual void didStartProvisionalLoadForFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, API::Object*) { } - virtual void didReceiveServerRedirectForProvisionalLoadForFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, API::Object*) { } - virtual void didFailProvisionalLoadWithErrorForFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, const WebCore::ResourceError&, API::Object*) { } - virtual void didCommitLoadForFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, API::Object*) { } - virtual void didFinishDocumentLoadForFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, API::Object*) { } - virtual void didFinishLoadForFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, API::Object*) { } - virtual void didFailLoadWithErrorForFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, const WebCore::ResourceError&, API::Object*) { } - virtual void didSameDocumentNavigationForFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, WebKit::SameDocumentNavigationType, API::Object*) { } - virtual void didReceiveTitleForFrame(WebKit::WebPageProxy*, const WTF::String&, WebKit::WebFrameProxy*, API::Object*) { } - virtual void didFirstLayoutForFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, API::Object*) { } + virtual void didStartProvisionalLoadForFrame(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, API::Navigation*, API::Object*) { } + virtual void didReceiveServerRedirectForProvisionalLoadForFrame(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, API::Navigation*, API::Object*) { } + virtual void didFailProvisionalLoadWithErrorForFrame(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, API::Navigation*, const WebCore::ResourceError&, API::Object*) { } + virtual void didCommitLoadForFrame(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, API::Navigation*, API::Object*) { } + virtual void didFinishDocumentLoadForFrame(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, API::Navigation*, API::Object*) { } + virtual void didFinishLoadForFrame(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, API::Navigation*, API::Object*) { } + virtual void didFailLoadWithErrorForFrame(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, API::Navigation*, const WebCore::ResourceError&, API::Object*) { } + virtual void didSameDocumentNavigationForFrame(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, API::Navigation*, WebKit::SameDocumentNavigationType, API::Object*) { } + virtual void didReceiveTitleForFrame(WebKit::WebPageProxy&, const WTF::String&, WebKit::WebFrameProxy&, API::Object*) { } + virtual void didFirstLayoutForFrame(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, API::Object*) { } // FIXME: We should consider removing didFirstVisuallyNonEmptyLayoutForFrame since it is replaced by didLayout. - virtual void didFirstVisuallyNonEmptyLayoutForFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, API::Object*) { } + virtual void didFirstVisuallyNonEmptyLayoutForFrame(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, API::Object*) { } - virtual void didRemoveFrameFromHierarchy(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, API::Object*) { } - virtual void didDisplayInsecureContentForFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, API::Object*) { } - virtual void didRunInsecureContentForFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, API::Object*) { } - virtual void didDetectXSSForFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, API::Object*) { } + virtual void didDisplayInsecureContentForFrame(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, API::Object*) { } + virtual void didRunInsecureContentForFrame(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, API::Object*) { } + virtual void didDetectXSSForFrame(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, API::Object*) { } - virtual void didLayout(WebKit::WebPageProxy*, WebCore::LayoutMilestones, API::Object*) { } + virtual void didLayout(WebKit::WebPageProxy&, WebCore::LayoutMilestones) { } - virtual bool canAuthenticateAgainstProtectionSpaceInFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, WebKit::WebProtectionSpace*) { return false; } - virtual void didReceiveAuthenticationChallengeInFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, WebKit::AuthenticationChallengeProxy*) { } + virtual bool canAuthenticateAgainstProtectionSpaceInFrame(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, WebKit::WebProtectionSpace*) { return false; } + virtual void didReceiveAuthenticationChallengeInFrame(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, WebKit::AuthenticationChallengeProxy*) { } - virtual void didStartProgress(WebKit::WebPageProxy*) { } - virtual void didChangeProgress(WebKit::WebPageProxy*) { } - virtual void didFinishProgress(WebKit::WebPageProxy*) { } + virtual void didStartProgress(WebKit::WebPageProxy&) { } + virtual void didChangeProgress(WebKit::WebPageProxy&) { } + virtual void didFinishProgress(WebKit::WebPageProxy&) { } - // FIXME: These three functions should not be part of this client. - virtual void processDidBecomeUnresponsive(WebKit::WebPageProxy*) { } - virtual void interactionOccurredWhileProcessUnresponsive(WebKit::WebPageProxy*) { } - virtual void processDidBecomeResponsive(WebKit::WebPageProxy*) { } - virtual void processDidCrash(WebKit::WebPageProxy*) { } + // FIXME: These functions should not be part of this client. + virtual void processDidBecomeUnresponsive(WebKit::WebPageProxy&) { } + virtual void processDidBecomeResponsive(WebKit::WebPageProxy&) { } + virtual void processDidCrash(WebKit::WebPageProxy&) { } - virtual void didChangeBackForwardList(WebKit::WebPageProxy*, WebKit::WebBackForwardListItem* addedItem, Vector<RefPtr<API::Object>>* removedItems) { } - virtual void willGoToBackForwardListItem(WebKit::WebPageProxy*, WebKit::WebBackForwardListItem*, API::Object*) { } + virtual void didChangeBackForwardList(WebKit::WebPageProxy&, WebKit::WebBackForwardListItem*, Vector<RefPtr<WebKit::WebBackForwardListItem>>) { } + virtual bool shouldKeepCurrentBackForwardListItemInList(WebKit::WebPageProxy&, WebKit::WebBackForwardListItem*) { return true; } + virtual void willGoToBackForwardListItem(WebKit::WebPageProxy&, WebKit::WebBackForwardListItem*, API::Object*) { } + + virtual RefPtr<Data> webCryptoMasterKey(WebKit::WebPageProxy&) { return nullptr; } + + virtual void didNavigateWithNavigationData(WebKit::WebPageProxy&, const WebKit::WebNavigationDataStore&, WebKit::WebFrameProxy&) { } + virtual void didPerformClientRedirect(WebKit::WebPageProxy&, const WTF::String&, const WTF::String&, WebKit::WebFrameProxy&) { } + virtual void didPerformServerRedirect(WebKit::WebPageProxy&, const WTF::String&, const WTF::String&, WebKit::WebFrameProxy&) { } + virtual void didUpdateHistoryTitle(WebKit::WebPageProxy&, const WTF::String&, const WTF::String&, WebKit::WebFrameProxy&) { } + + virtual void navigationGestureDidBegin(WebKit::WebPageProxy&) { } + virtual void navigationGestureWillEnd(WebKit::WebPageProxy&, bool willNavigate, WebKit::WebBackForwardListItem&) { } + virtual void navigationGestureDidEnd(WebKit::WebPageProxy&, bool willNavigate, WebKit::WebBackForwardListItem&) { } #if ENABLE(NETSCAPE_PLUGIN_API) - virtual WebKit::PluginModuleLoadPolicy pluginLoadPolicy(WebKit::WebPageProxy*, WebKit::PluginModuleLoadPolicy currentPluginLoadPolicy, WebKit::ImmutableDictionary*, WTF::String& unavailabilityDescription) { return currentPluginLoadPolicy; } - virtual void didFailToInitializePlugin(WebKit::WebPageProxy*, WebKit::ImmutableDictionary*) { } - virtual void didBlockInsecurePluginVersion(WebKit::WebPageProxy*, WebKit::ImmutableDictionary*) { } + virtual WebKit::PluginModuleLoadPolicy pluginLoadPolicy(WebKit::WebPageProxy&, WebKit::PluginModuleLoadPolicy currentPluginLoadPolicy, API::Dictionary*, WTF::String& /* unavailabilityDescription */) { return currentPluginLoadPolicy; } + virtual void didFailToInitializePlugin(WebKit::WebPageProxy&, API::Dictionary*) { } + virtual void didBlockInsecurePluginVersion(WebKit::WebPageProxy&, API::Dictionary*) { } #endif // ENABLE(NETSCAPE_PLUGIN_API) #if ENABLE(WEBGL) - virtual WebCore::WebGLLoadPolicy webGLLoadPolicy(WebKit::WebPageProxy*, const WTF::String&) const { return WebCore::WebGLLoadPolicy::WebGLAllow; } + virtual WebCore::WebGLLoadPolicy webGLLoadPolicy(WebKit::WebPageProxy&, const WTF::String&) const { return WebCore::WebGLLoadPolicy::WebGLAllowCreation; } + virtual WebCore::WebGLLoadPolicy resolveWebGLLoadPolicy(WebKit::WebPageProxy&, const WTF::String&) const { return WebCore::WebGLLoadPolicy::WebGLAllowCreation; } #endif // ENABLE(WEBGL) + +#if USE(QUICK_LOOK) + virtual void didStartLoadForQuickLookDocumentInMainFrame(const WTF::String& fileName, const WTF::String& uti) { } + virtual void didFinishLoadForQuickLookDocumentInMainFrame(const WebKit::QuickLookDocumentData&) { } +#endif }; } // namespace API diff --git a/Source/WebKit2/UIProcess/gtk/WebProcessProxyGtk.cpp b/Source/WebKit2/UIProcess/API/APINavigation.cpp index 5907d5657..1a80b04ce 100644 --- a/Source/WebKit2/UIProcess/gtk/WebProcessProxyGtk.cpp +++ b/Source/WebKit2/UIProcess/API/APINavigation.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Apple Inc. All rights reserved. + * Copyright (C) 2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -24,20 +24,25 @@ */ #include "config.h" -#include "WebProcessProxy.h" -#include <glib.h> +#include "APINavigation.h" -namespace WebKit { +#include "WebNavigationState.h" -void WebProcessProxy::platformGetLaunchOptions(ProcessLauncher::LaunchOptions& launchOptions) +namespace API { + +Navigation::Navigation(WebKit::WebNavigationState& state) + : m_navigationID(state.generateNavigationID()) +{ +} + +Navigation::Navigation(WebKit::WebNavigationState& state, const WebCore::ResourceRequest& request) + : m_navigationID(state.generateNavigationID()) + , m_request(request) +{ +} + +Navigation::~Navigation() { -#ifndef NDEBUG - const char* webProcessCmdPrefix = g_getenv("WEB_PROCESS_CMD_PREFIX"); - if (webProcessCmdPrefix && *webProcessCmdPrefix) - launchOptions.processCmdPrefix = String::fromUTF8(webProcessCmdPrefix); -#else - UNUSED_PARAM(launchOptions); -#endif } } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/API/APINavigation.h b/Source/WebKit2/UIProcess/API/APINavigation.h new file mode 100644 index 000000000..a014898c1 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APINavigation.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef APINavigation_h +#define APINavigation_h + +#include "APIObject.h" +#include <WebCore/ResourceRequest.h> +#include <wtf/Ref.h> + +namespace WebKit { +class WebNavigationState; +} + +namespace API { + +class Navigation : public ObjectImpl<Object::Type::Navigation> { +public: + static Ref<Navigation> create(WebKit::WebNavigationState& state) + { + return adoptRef(*new Navigation(state)); + } + + static Ref<Navigation> create(WebKit::WebNavigationState& state, const WebCore::ResourceRequest& request) + { + return adoptRef(*new Navigation(state, request)); + } + + virtual ~Navigation(); + + uint64_t navigationID() const { return m_navigationID; } + + const WebCore::ResourceRequest& request() const { return m_request; } + +private: + explicit Navigation(WebKit::WebNavigationState&); + explicit Navigation(WebKit::WebNavigationState&, const WebCore::ResourceRequest&); + + uint64_t m_navigationID; + WebCore::ResourceRequest m_request; +}; + +} // namespace API + + +#endif // APINavigation_h diff --git a/Source/WebKit2/UIProcess/API/APINavigationAction.h b/Source/WebKit2/UIProcess/API/APINavigationAction.h new file mode 100644 index 000000000..5ab91b274 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APINavigationAction.h @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef APINavigationAction_h +#define APINavigationAction_h + +#include "APIFrameInfo.h" +#include "APIObject.h" +#include "NavigationActionData.h" +#include <WebCore/ResourceRequest.h> +#include <WebCore/URL.h> + +namespace API { + +class FrameInfo; + +class NavigationAction final : public ObjectImpl<Object::Type::NavigationAction> { +public: + static Ref<NavigationAction> create(const WebKit::NavigationActionData& navigationActionData, API::FrameInfo* sourceFrame, API::FrameInfo* targetFrame, const WebCore::ResourceRequest& request, const WebCore::URL& originalURL, bool shouldOpenAppLinks) + { + return adoptRef(*new NavigationAction(navigationActionData, sourceFrame, targetFrame, request, originalURL, shouldOpenAppLinks)); + } + + NavigationAction(const WebKit::NavigationActionData& navigationActionData, API::FrameInfo* sourceFrame, API::FrameInfo* targetFrame, const WebCore::ResourceRequest& request, const WebCore::URL& originalURL, bool shouldOpenAppLinks) + : m_sourceFrame(sourceFrame) + , m_targetFrame(targetFrame) + , m_request(request) + , m_originalURL(originalURL) + , m_shouldOpenAppLinks(shouldOpenAppLinks) + , m_navigationActionData(navigationActionData) + { + } + + FrameInfo* sourceFrame() const { return m_sourceFrame.get(); } + FrameInfo* targetFrame() const { return m_targetFrame.get(); } + + const WebCore::ResourceRequest& request() const { return m_request; } + const WebCore::URL& originalURL() const { return m_originalURL; } + + WebCore::NavigationType navigationType() const { return m_navigationActionData.navigationType; } + WebKit::WebEvent::Modifiers modifiers() const { return m_navigationActionData.modifiers; } + WebKit::WebMouseEvent::Button mouseButton() const { return m_navigationActionData.mouseButton; } + bool isProcessingUserGesture() const { return m_navigationActionData.isProcessingUserGesture; } + bool canHandleRequest() const { return m_navigationActionData.canHandleRequest; } + bool shouldOpenExternalSchemes() const { return m_navigationActionData.shouldOpenExternalURLsPolicy == WebCore::ShouldOpenExternalURLsPolicy::ShouldAllow || m_navigationActionData.shouldOpenExternalURLsPolicy == WebCore::ShouldOpenExternalURLsPolicy::ShouldAllowExternalSchemes; } + bool shouldOpenAppLinks() const { return m_shouldOpenAppLinks && m_navigationActionData.shouldOpenExternalURLsPolicy == WebCore::ShouldOpenExternalURLsPolicy::ShouldAllow; } + +private: + RefPtr<FrameInfo> m_sourceFrame; + RefPtr<FrameInfo> m_targetFrame; + + WebCore::ResourceRequest m_request; + WebCore::URL m_originalURL; + + bool m_shouldOpenAppLinks; + + WebKit::NavigationActionData m_navigationActionData; +}; + +} // namespace API + +#endif // APINavigationAction_h diff --git a/Source/WebKit2/UIProcess/API/APINavigationClient.h b/Source/WebKit2/UIProcess/API/APINavigationClient.h new file mode 100644 index 000000000..fb5a26785 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APINavigationClient.h @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2014, 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef APINavigationClient_h +#define APINavigationClient_h + +#include "APIData.h" +#include "PluginModuleInfo.h" +#include "SameDocumentNavigationType.h" +#include "WebEvent.h" +#include "WebFramePolicyListenerProxy.h" +#include <WebCore/FrameLoaderTypes.h> +#include <WebCore/LayoutMilestones.h> +#include <wtf/Forward.h> + +namespace WebCore { +class ResourceError; +class ResourceRequest; +class ResourceResponse; +struct SecurityOriginData; +} + +namespace WebKit { +class AuthenticationChallengeProxy; +class QuickLookDocumentData; +class WebBackForwardListItem; +class WebFramePolicyListenerProxy; +class WebFrameProxy; +class WebPageProxy; +class WebProtectionSpace; +struct NavigationActionData; +struct WebNavigationDataStore; +} + +namespace API { + +class Dictionary; +class Navigation; +class NavigationAction; +class NavigationResponse; +class Object; + +class NavigationClient { +public: + virtual ~NavigationClient() { } + + virtual void didStartProvisionalNavigation(WebKit::WebPageProxy&, API::Navigation*, API::Object*) { } + virtual void didReceiveServerRedirectForProvisionalNavigation(WebKit::WebPageProxy&, API::Navigation*, API::Object*) { } + virtual void didFailProvisionalNavigationWithError(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, API::Navigation*, const WebCore::ResourceError&, API::Object*) { } + virtual void didFailProvisionalLoadInSubframeWithError(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, const WebCore::SecurityOriginData&, API::Navigation*, const WebCore::ResourceError&, API::Object*) { } + virtual void didCommitNavigation(WebKit::WebPageProxy&, API::Navigation*, API::Object*) { } + virtual void didFinishDocumentLoad(WebKit::WebPageProxy&, API::Navigation*, API::Object*) { } + virtual void didFinishNavigation(WebKit::WebPageProxy&, API::Navigation*, API::Object*) { } + virtual void didFailNavigationWithError(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, API::Navigation*, const WebCore::ResourceError&, API::Object*) { } + virtual void didSameDocumentNavigation(WebKit::WebPageProxy&, API::Navigation*, WebKit::SameDocumentNavigationType, API::Object*) { } + + virtual void renderingProgressDidChange(WebKit::WebPageProxy&, WebCore::LayoutMilestones) { } + + virtual bool canAuthenticateAgainstProtectionSpace(WebKit::WebPageProxy&, WebKit::WebProtectionSpace*) { return false; } + virtual void didReceiveAuthenticationChallenge(WebKit::WebPageProxy&, WebKit::AuthenticationChallengeProxy*) { } + + // FIXME: These function should not be part of this client. + virtual void processDidCrash(WebKit::WebPageProxy&) { } + virtual void processDidBecomeResponsive(WebKit::WebPageProxy&) { } + virtual void processDidBecomeUnresponsive(WebKit::WebPageProxy&) { } + + virtual RefPtr<Data> webCryptoMasterKey(WebKit::WebPageProxy&) { return nullptr; } + +#if USE(QUICK_LOOK) + virtual void didStartLoadForQuickLookDocumentInMainFrame(const WTF::String& fileName, const WTF::String& uti) { } + virtual void didFinishLoadForQuickLookDocumentInMainFrame(const WebKit::QuickLookDocumentData&) { } +#endif + + virtual void decidePolicyForNavigationAction(WebKit::WebPageProxy&, API::NavigationAction&, Ref<WebKit::WebFramePolicyListenerProxy>&& listener, API::Object*) + { + listener->use(); + } + + virtual void decidePolicyForNavigationResponse(WebKit::WebPageProxy&, API::NavigationResponse&, Ref<WebKit::WebFramePolicyListenerProxy>&& listener, API::Object*) + { + listener->use(); + } + +#if ENABLE(NETSCAPE_PLUGIN_API) + virtual WebKit::PluginModuleLoadPolicy decidePolicyForPluginLoad(WebKit::WebPageProxy&, WebKit::PluginModuleLoadPolicy currentPluginLoadPolicy, API::Dictionary*, WTF::String&) + { + return currentPluginLoadPolicy; + } +#endif + + virtual void didBeginNavigationGesture(WebKit::WebPageProxy&) { } + virtual void willEndNavigationGesture(WebKit::WebPageProxy&, bool willNavigate, WebKit::WebBackForwardListItem&) { } + virtual void didEndNavigationGesture(WebKit::WebPageProxy&, bool willNavigate, WebKit::WebBackForwardListItem&) { } + virtual void didRemoveNavigationGestureSnapshot(WebKit::WebPageProxy&) { } +}; + +} // namespace API + +#endif // APINavigationClient_h diff --git a/Source/WebKit2/UIProcess/APINavigationData.cpp b/Source/WebKit2/UIProcess/API/APINavigationData.cpp index 7415e5358..7415e5358 100644 --- a/Source/WebKit2/UIProcess/APINavigationData.cpp +++ b/Source/WebKit2/UIProcess/API/APINavigationData.cpp diff --git a/Source/WebKit2/UIProcess/APINavigationData.h b/Source/WebKit2/UIProcess/API/APINavigationData.h index 22e4183df..01c4c8b8d 100644 --- a/Source/WebKit2/UIProcess/APINavigationData.h +++ b/Source/WebKit2/UIProcess/API/APINavigationData.h @@ -34,9 +34,9 @@ namespace API { class NavigationData : public ObjectImpl<Object::Type::NavigationData> { public: - static PassRefPtr<NavigationData> create(const WebKit::WebNavigationDataStore& store) + static Ref<NavigationData> create(const WebKit::WebNavigationDataStore& store) { - return adoptRef(new NavigationData(store)); + return adoptRef(*new NavigationData(store)); } virtual ~NavigationData(); diff --git a/Source/WebKit2/UIProcess/API/APINavigationResponse.h b/Source/WebKit2/UIProcess/API/APINavigationResponse.h new file mode 100644 index 000000000..75c456f53 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APINavigationResponse.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef APINavigationResponse_h +#define APINavigationResponse_h + +#include "APIFrameInfo.h" +#include "APIObject.h" +#include <WebCore/ResourceRequest.h> +#include <WebCore/ResourceResponse.h> + +namespace API { + +class FrameInfo; + +class NavigationResponse final : public ObjectImpl<Object::Type::NavigationResponse> { +public: + static Ref<NavigationResponse> create(API::FrameInfo& frame, const WebCore::ResourceRequest& request, const WebCore::ResourceResponse& response, bool canShowMIMEType) + { + return adoptRef(*new NavigationResponse(frame, request, response, canShowMIMEType)); + } + + NavigationResponse(API::FrameInfo& frame, const WebCore::ResourceRequest& request, const WebCore::ResourceResponse& response, bool canShowMIMEType) + : m_frame(frame) + , m_request(request) + , m_response(response) + , m_canShowMIMEType(canShowMIMEType) + { + } + + FrameInfo& frame() { return m_frame.get(); } + + const WebCore::ResourceRequest& request() const { return m_request; } + const WebCore::ResourceResponse& response() const { return m_response; } + + bool canShowMIMEType() const { return m_canShowMIMEType; } + +private: + Ref<FrameInfo> m_frame; + + WebCore::ResourceRequest m_request; + WebCore::ResourceResponse m_response; + bool m_canShowMIMEType; +}; + +} // namespace API + +#endif // APINavigationResponse_h diff --git a/Source/WebKit2/UIProcess/API/APIPageConfiguration.cpp b/Source/WebKit2/UIProcess/API/APIPageConfiguration.cpp new file mode 100644 index 000000000..f2fc3b801 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIPageConfiguration.cpp @@ -0,0 +1,161 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "APIPageConfiguration.h" + +#include "APIProcessPoolConfiguration.h" +#include "WebPageGroup.h" +#include "WebPageProxy.h" +#include "WebPreferences.h" +#include "WebProcessPool.h" +#include "WebUserContentControllerProxy.h" + +using namespace WebKit; + +namespace API { + +Ref<PageConfiguration> PageConfiguration::create() +{ + return adoptRef(*new PageConfiguration); +} + +PageConfiguration::PageConfiguration() +{ +} + +PageConfiguration::~PageConfiguration() +{ +} + +Ref<PageConfiguration> PageConfiguration::copy() const +{ + auto copy = create(); + + copy->m_processPool = this->m_processPool; + copy->m_userContentController = this->m_userContentController; + copy->m_pageGroup = this->m_pageGroup; + copy->m_preferences = this->m_preferences; + copy->m_preferenceValues = this->m_preferenceValues; + copy->m_relatedPage = this->m_relatedPage; + copy->m_visitedLinkStore = this->m_visitedLinkStore; + copy->m_websiteDataStore = this->m_websiteDataStore; + copy->m_sessionID = this->m_sessionID; + copy->m_treatsSHA1SignedCertificatesAsInsecure = this->m_treatsSHA1SignedCertificatesAsInsecure; +#if PLATFORM(IOS) + copy->m_alwaysRunsAtForegroundPriority = this->m_alwaysRunsAtForegroundPriority; +#endif + + return copy; +} + + +WebProcessPool* PageConfiguration::processPool() +{ + return m_processPool.get(); +} + +void PageConfiguration::setProcessPool(WebProcessPool* processPool) +{ + m_processPool = processPool; +} + +WebUserContentControllerProxy* PageConfiguration::userContentController() +{ + return m_userContentController.get(); +} + +void PageConfiguration::setUserContentController(WebUserContentControllerProxy* userContentController) +{ + m_userContentController = userContentController; +} + +WebPageGroup* PageConfiguration::pageGroup() +{ + return m_pageGroup.get(); +} + +void PageConfiguration::setPageGroup(WebPageGroup* pageGroup) +{ + m_pageGroup = pageGroup; +} + +WebPreferences* PageConfiguration::preferences() +{ + return m_preferences.get(); +} + +void PageConfiguration::setPreferences(WebPreferences* preferences) +{ + m_preferences = preferences; +} + +WebPageProxy* PageConfiguration::relatedPage() +{ + return m_relatedPage.get(); +} + +void PageConfiguration::setRelatedPage(WebPageProxy* relatedPage) +{ + m_relatedPage = relatedPage; +} + + +VisitedLinkStore* PageConfiguration::visitedLinkStore() +{ + return m_visitedLinkStore.get(); +} + +void PageConfiguration::setVisitedLinkStore(VisitedLinkStore* visitedLinkStore) +{ + m_visitedLinkStore = visitedLinkStore; +} + +API::WebsiteDataStore* PageConfiguration::websiteDataStore() +{ + return m_websiteDataStore.get(); +} + +void PageConfiguration::setWebsiteDataStore(API::WebsiteDataStore* websiteDataStore) +{ + m_websiteDataStore = websiteDataStore; + + if (m_websiteDataStore) + m_sessionID = m_websiteDataStore->websiteDataStore().sessionID(); + else + m_sessionID = WebCore::SessionID(); +} + +WebCore::SessionID PageConfiguration::sessionID() +{ + return m_sessionID; +} + +void PageConfiguration::setSessionID(WebCore::SessionID sessionID) +{ + m_sessionID = sessionID; +} + +} // namespace API diff --git a/Source/WebKit2/UIProcess/API/APIPageConfiguration.h b/Source/WebKit2/UIProcess/API/APIPageConfiguration.h new file mode 100644 index 000000000..5c62532a8 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIPageConfiguration.h @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef APIPageConfiguration_h +#define APIPageConfiguration_h + +#include "APIObject.h" +#include "WebPreferencesStore.h" +#include <WebCore/SessionID.h> +#include <wtf/GetPtr.h> + +namespace WebKit { +class VisitedLinkStore; +class WebPageGroup; +class WebPageProxy; +class WebPreferences; +class WebProcessPool; +class WebUserContentControllerProxy; +} + +namespace API { + +class WebsiteDataStore; + +class PageConfiguration : public ObjectImpl<Object::Type::PageConfiguration> { +public: + static Ref<PageConfiguration> create(); + + explicit PageConfiguration(); + virtual ~PageConfiguration(); + + Ref<PageConfiguration> copy() const; + + // FIXME: The configuration properties should return their default values + // rather than nullptr. + + WebKit::WebProcessPool* processPool(); + void setProcessPool(WebKit::WebProcessPool*); + + WebKit::WebUserContentControllerProxy* userContentController(); + void setUserContentController(WebKit::WebUserContentControllerProxy*); + + WebKit::WebPageGroup* pageGroup(); + void setPageGroup(WebKit::WebPageGroup*); + + WebKit::WebPreferences* preferences(); + void setPreferences(WebKit::WebPreferences*); + + WebKit::WebPreferencesStore::ValueMap& preferenceValues() { return m_preferenceValues; } + + WebKit::WebPageProxy* relatedPage(); + void setRelatedPage(WebKit::WebPageProxy*); + + WebKit::VisitedLinkStore* visitedLinkStore(); + void setVisitedLinkStore(WebKit::VisitedLinkStore*); + + WebsiteDataStore* websiteDataStore(); + void setWebsiteDataStore(WebsiteDataStore*); + + WebCore::SessionID sessionID(); + void setSessionID(WebCore::SessionID); + + bool treatsSHA1SignedCertificatesAsInsecure() { return m_treatsSHA1SignedCertificatesAsInsecure; } + void setTreatsSHA1SignedCertificatesAsInsecure(bool treatsSHA1SignedCertificatesAsInsecure) { m_treatsSHA1SignedCertificatesAsInsecure = treatsSHA1SignedCertificatesAsInsecure; } + +#if PLATFORM(IOS) + bool alwaysRunsAtForegroundPriority() { return m_alwaysRunsAtForegroundPriority; } + void setAlwaysRunsAtForegroundPriority(bool alwaysRunsAtForegroundPriority) { m_alwaysRunsAtForegroundPriority = alwaysRunsAtForegroundPriority; } +#endif + +private: + + RefPtr<WebKit::WebProcessPool> m_processPool; + RefPtr<WebKit::WebUserContentControllerProxy> m_userContentController; + RefPtr<WebKit::WebPageGroup> m_pageGroup; + RefPtr<WebKit::WebPreferences> m_preferences; + WebKit::WebPreferencesStore::ValueMap m_preferenceValues; + RefPtr<WebKit::WebPageProxy> m_relatedPage; + RefPtr<WebKit::VisitedLinkStore> m_visitedLinkStore; + + RefPtr<WebsiteDataStore> m_websiteDataStore; + // FIXME: We currently have to pass the session ID separately here to support the legacy private browsing session. + // Once we get rid of it we should get rid of this configuration parameter as well. + WebCore::SessionID m_sessionID; + + bool m_treatsSHA1SignedCertificatesAsInsecure = false; +#if PLATFORM(IOS) + bool m_alwaysRunsAtForegroundPriority = false; +#endif +}; + +} // namespace API + + +#endif // APIPageConfiguration_h diff --git a/Source/WebKit2/UIProcess/API/APIPolicyClient.h b/Source/WebKit2/UIProcess/API/APIPolicyClient.h index b0215a48a..8edfaa1a9 100644 --- a/Source/WebKit2/UIProcess/API/APIPolicyClient.h +++ b/Source/WebKit2/UIProcess/API/APIPolicyClient.h @@ -51,10 +51,19 @@ class PolicyClient { public: virtual ~PolicyClient() { } - virtual void decidePolicyForNavigationAction(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, const WebKit::NavigationActionData&, WebKit::WebFrameProxy* originatingFrame, const WebCore::ResourceRequest& originalRequest, const WebCore::ResourceRequest&, WebKit::WebFramePolicyListenerProxy* listener, API::Object* userData) { listener->use(); } - virtual void decidePolicyForNewWindowAction(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, WebCore::NavigationType, WebKit::WebEvent::Modifiers, WebKit::WebMouseEvent::Button, const WebCore::ResourceRequest&, const WTF::String& frameName, WebKit::WebFramePolicyListenerProxy* listener, API::Object* userData) { listener->use(); } - virtual void decidePolicyForResponse(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, bool canShowMIMEType, WebKit::WebFramePolicyListenerProxy* listener, API::Object* userData) { listener->use(); } - virtual void unableToImplementPolicy(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, const WebCore::ResourceError&, API::Object* userData) { } + virtual void decidePolicyForNavigationAction(WebKit::WebPageProxy&, WebKit::WebFrameProxy*, const WebKit::NavigationActionData&, WebKit::WebFrameProxy*, const WebCore::ResourceRequest&, const WebCore::ResourceRequest&, Ref<WebKit::WebFramePolicyListenerProxy>&& listener, API::Object*) + { + listener->use(); + } + virtual void decidePolicyForNewWindowAction(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, const WebKit::NavigationActionData&, const WebCore::ResourceRequest&, const WTF::String&, Ref<WebKit::WebFramePolicyListenerProxy>&& listener, API::Object*) + { + listener->use(); + } + virtual void decidePolicyForResponse(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, bool, Ref<WebKit::WebFramePolicyListenerProxy>&& listener, API::Object*) + { + listener->use(); + } + virtual void unableToImplementPolicy(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, const WebCore::ResourceError&, API::Object*) { } }; } // namespace API diff --git a/Source/WebKit2/UIProcess/API/APIProcessPoolConfiguration.cpp b/Source/WebKit2/UIProcess/API/APIProcessPoolConfiguration.cpp new file mode 100644 index 000000000..7895e137b --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIProcessPoolConfiguration.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "APIProcessPoolConfiguration.h" + +#include "APIWebsiteDataStore.h" +#include "WebProcessPool.h" + +namespace API { + +Ref<ProcessPoolConfiguration> ProcessPoolConfiguration::create() +{ + return adoptRef(*new ProcessPoolConfiguration); +} + +Ref<ProcessPoolConfiguration> ProcessPoolConfiguration::createWithLegacyOptions() +{ + auto configuration = ProcessPoolConfiguration::create(); + + configuration->m_shouldHaveLegacyDataStore = true; + configuration->m_maximumProcessCount = 1; + configuration->m_cacheModel = WebKit::CacheModelDocumentViewer; + + configuration->m_applicationCacheDirectory = WebKit::WebProcessPool::legacyPlatformDefaultApplicationCacheDirectory(); + configuration->m_diskCacheDirectory = WebKit::WebProcessPool::legacyPlatformDefaultNetworkCacheDirectory(); + configuration->m_indexedDBDatabaseDirectory = WebKit::WebProcessPool::legacyPlatformDefaultIndexedDBDatabaseDirectory(); + configuration->m_localStorageDirectory = WebKit::WebProcessPool::legacyPlatformDefaultLocalStorageDirectory(); + configuration->m_mediaKeysStorageDirectory = WebKit::WebProcessPool::legacyPlatformDefaultMediaKeysStorageDirectory(); + configuration->m_webSQLDatabaseDirectory = WebKit::WebProcessPool::legacyPlatformDefaultWebSQLDatabaseDirectory(); + + return configuration; +} + +ProcessPoolConfiguration::ProcessPoolConfiguration() + : m_applicationCacheDirectory(WebsiteDataStore::defaultApplicationCacheDirectory()) + , m_diskCacheDirectory(WebsiteDataStore::defaultNetworkCacheDirectory()) + , m_indexedDBDatabaseDirectory(WebsiteDataStore::defaultIndexedDBDatabaseDirectory()) + , m_localStorageDirectory(WebsiteDataStore::defaultLocalStorageDirectory()) + , m_webSQLDatabaseDirectory(WebsiteDataStore::defaultWebSQLDatabaseDirectory()) + , m_mediaKeysStorageDirectory(WebsiteDataStore::defaultMediaKeysStorageDirectory()) +{ +} + +ProcessPoolConfiguration::~ProcessPoolConfiguration() +{ +} + +Ref<ProcessPoolConfiguration> ProcessPoolConfiguration::copy() +{ + auto copy = this->create(); + + copy->m_shouldHaveLegacyDataStore = this->m_shouldHaveLegacyDataStore; + copy->m_maximumProcessCount = this->m_maximumProcessCount; + copy->m_cacheModel = this->m_cacheModel; + copy->m_diskCacheSizeOverride = this->m_diskCacheSizeOverride; + copy->m_applicationCacheDirectory = this->m_applicationCacheDirectory; + copy->m_diskCacheDirectory = this->m_diskCacheDirectory; + copy->m_indexedDBDatabaseDirectory = this->m_indexedDBDatabaseDirectory; + copy->m_injectedBundlePath = this->m_injectedBundlePath; + copy->m_localStorageDirectory = this->m_localStorageDirectory; + copy->m_mediaKeysStorageDirectory = this->m_mediaKeysStorageDirectory; + copy->m_webSQLDatabaseDirectory = this->m_webSQLDatabaseDirectory; + copy->m_cachePartitionedURLSchemes = this->m_cachePartitionedURLSchemes; + copy->m_alwaysRevalidatedURLSchemes = this->m_alwaysRevalidatedURLSchemes; + copy->m_fullySynchronousModeIsAllowedForTesting = this->m_fullySynchronousModeIsAllowedForTesting; + copy->m_overrideLanguages = this->m_overrideLanguages; + + return copy; +} + +} // namespace API diff --git a/Source/WebKit2/UIProcess/API/APIProcessPoolConfiguration.h b/Source/WebKit2/UIProcess/API/APIProcessPoolConfiguration.h new file mode 100644 index 000000000..a5d813ff0 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIProcessPoolConfiguration.h @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef APIContextConfiguration_h +#define APIContextConfiguration_h + +#include "APIObject.h" +#include "CacheModel.h" +#include <wtf/Ref.h> +#include <wtf/Vector.h> +#include <wtf/text/WTFString.h> + +namespace API { + +class ProcessPoolConfiguration final : public ObjectImpl<Object::Type::ProcessPoolConfiguration> { +public: + static Ref<ProcessPoolConfiguration> create(); + static Ref<ProcessPoolConfiguration> createWithLegacyOptions(); + + explicit ProcessPoolConfiguration(); + virtual ~ProcessPoolConfiguration(); + + Ref<ProcessPoolConfiguration> copy(); + + bool shouldHaveLegacyDataStore() const { return m_shouldHaveLegacyDataStore; } + void setShouldHaveLegacyDataStore(bool shouldHaveLegacyDataStore) { m_shouldHaveLegacyDataStore = shouldHaveLegacyDataStore; } + + unsigned maximumProcessCount() const { return m_maximumProcessCount; } + void setMaximumProcessCount(unsigned maximumProcessCount) { m_maximumProcessCount = maximumProcessCount; } + + WebKit::CacheModel cacheModel() const { return m_cacheModel; } + void setCacheModel(WebKit::CacheModel cacheModel) { m_cacheModel = cacheModel; } + + int64_t diskCacheSizeOverride() const { return m_diskCacheSizeOverride; } + void setDiskCacheSizeOverride(int64_t size) { m_diskCacheSizeOverride = size; } + + const WTF::String& applicationCacheDirectory() const { return m_applicationCacheDirectory; } + void setApplicationCacheDirectory(const WTF::String& applicationCacheDirectory) { m_applicationCacheDirectory = applicationCacheDirectory; } + + const WTF::String& diskCacheDirectory() const { return m_diskCacheDirectory; } + void setDiskCacheDirectory(const WTF::String& diskCacheDirectory) { m_diskCacheDirectory = diskCacheDirectory; } + + const WTF::String& indexedDBDatabaseDirectory() const { return m_indexedDBDatabaseDirectory; } + void setIndexedDBDatabaseDirectory(const WTF::String& indexedDBDatabaseDirectory) { m_indexedDBDatabaseDirectory = indexedDBDatabaseDirectory; } + + const WTF::String& injectedBundlePath() const { return m_injectedBundlePath; } + void setInjectedBundlePath(const WTF::String& injectedBundlePath) { m_injectedBundlePath = injectedBundlePath; } + + const WTF::String& localStorageDirectory() const { return m_localStorageDirectory; } + void setLocalStorageDirectory(const WTF::String& localStorageDirectory) { m_localStorageDirectory = localStorageDirectory; } + + const WTF::String& webSQLDatabaseDirectory() const { return m_webSQLDatabaseDirectory; } + void setWebSQLDatabaseDirectory(const WTF::String& webSQLDatabaseDirectory) { m_webSQLDatabaseDirectory = webSQLDatabaseDirectory; } + + const WTF::String& mediaKeysStorageDirectory() const { return m_mediaKeysStorageDirectory; } + void setMediaKeysStorageDirectory(const WTF::String& mediaKeysStorageDirectory) { m_mediaKeysStorageDirectory = mediaKeysStorageDirectory; } + + const Vector<WTF::String>& cachePartitionedURLSchemes() { return m_cachePartitionedURLSchemes; } + void setCachePartitionedURLSchemes(Vector<WTF::String>&& cachePartitionedURLSchemes) { m_cachePartitionedURLSchemes = WTFMove(cachePartitionedURLSchemes); } + + const Vector<WTF::String>& alwaysRevalidatedURLSchemes() { return m_alwaysRevalidatedURLSchemes; } + void setAlwaysRevalidatedURLSchemes(Vector<WTF::String>&& alwaysRevalidatedURLSchemes) { m_alwaysRevalidatedURLSchemes = WTFMove(alwaysRevalidatedURLSchemes); } + + bool fullySynchronousModeIsAllowedForTesting() const { return m_fullySynchronousModeIsAllowedForTesting; } + void setFullySynchronousModeIsAllowedForTesting(bool allowed) { m_fullySynchronousModeIsAllowedForTesting = allowed; } + + const Vector<WTF::String>& overrideLanguages() const { return m_overrideLanguages; } + void setOverrideLanguages(Vector<WTF::String>&& languages) { m_overrideLanguages = WTFMove(languages); } + +private: + bool m_shouldHaveLegacyDataStore { false }; + + unsigned m_maximumProcessCount { 0 }; + WebKit::CacheModel m_cacheModel { WebKit::CacheModelPrimaryWebBrowser }; + int64_t m_diskCacheSizeOverride { -1 }; + + WTF::String m_applicationCacheDirectory; + WTF::String m_diskCacheDirectory; + WTF::String m_indexedDBDatabaseDirectory; + WTF::String m_injectedBundlePath; + WTF::String m_localStorageDirectory; + WTF::String m_webSQLDatabaseDirectory; + WTF::String m_mediaKeysStorageDirectory; + Vector<WTF::String> m_cachePartitionedURLSchemes; + Vector<WTF::String> m_alwaysRevalidatedURLSchemes; + bool m_fullySynchronousModeIsAllowedForTesting { false }; + Vector<WTF::String> m_overrideLanguages; +}; + +} // namespace API + +#endif // APIContextConfiguration_h diff --git a/Source/WebKit2/UIProcess/APISession.cpp b/Source/WebKit2/UIProcess/API/APISession.cpp index c2a2615ff..61553b195 100644 --- a/Source/WebKit2/UIProcess/APISession.cpp +++ b/Source/WebKit2/UIProcess/API/APISession.cpp @@ -26,65 +26,61 @@ #include "config.h" #include "APISession.h" -#include <wtf/MainThread.h> +#include "NetworkProcessMessages.h" +#include "WebProcessPool.h" +#include <wtf/RunLoop.h> namespace API { -static uint64_t generateID(bool isEphemeral) +static uint64_t generateID() { - ASSERT(isMainThread()); + ASSERT(RunLoop::isMain()); + + static uint64_t uniqueSessionID = WebCore::SessionID::legacyPrivateSessionID().sessionID(); - static uint64_t uniqueSessionID = WebKit::SessionTracker::legacyPrivateSessionID; - ASSERT(isEphemeral); return ++uniqueSessionID; } Session& Session::defaultSession() { - ASSERT(isMainThread()); + ASSERT(RunLoop::isMain()); - static Session* defaultSession = new Session(false, WebKit::SessionTracker::defaultSessionID); + static Session* defaultSession = new Session(WebCore::SessionID::defaultSessionID()); return *defaultSession; } -Session& Session::legacyPrivateSession() -{ - ASSERT(isMainThread()); - - static Session* legacyPrivateSession = new Session(true, WebKit::SessionTracker::legacyPrivateSessionID); - return *legacyPrivateSession; -} - -Session::Session(bool isEphemeral) - : m_isEphemeral(isEphemeral) - , m_sessionID(generateID(isEphemeral)) +Session::Session() + : m_sessionID(generateID()) { } -Session::Session(bool isEphemeral, uint64_t sessionID) - : m_isEphemeral(isEphemeral) - , m_sessionID(sessionID) +Session::Session(WebCore::SessionID sessionID) + : m_sessionID(sessionID) { } -PassRefPtr<Session> Session::create(bool isEphemeral) +Ref<Session> Session::createEphemeral() { // FIXME: support creation of non-default, non-ephemeral sessions - return adoptRef(new Session(isEphemeral)); + return adoptRef(*new Session()); } bool Session::isEphemeral() const { - return m_isEphemeral; + return m_sessionID.isEphemeral(); } -uint64_t Session::getID() const +WebCore::SessionID Session::getID() const { return m_sessionID; } Session::~Session() { + if (m_sessionID.isEphemeral()) { + for (auto& processPool : WebKit::WebProcessPool::allProcessPools()) + processPool->sendToNetworkingProcess(Messages::NetworkProcess::DestroyPrivateBrowsingSession(m_sessionID)); + } } } // namespace API diff --git a/Source/WebKit2/UIProcess/APISession.h b/Source/WebKit2/UIProcess/API/APISession.h index bd604b2d5..d2091dd3a 100644 --- a/Source/WebKit2/UIProcess/APISession.h +++ b/Source/WebKit2/UIProcess/API/APISession.h @@ -27,26 +27,25 @@ #define APISession_h #include "APIObject.h" -#include "SessionTracker.h" +#include <WebCore/SessionID.h> #include <wtf/PassRefPtr.h> namespace API { class Session : public API::ObjectImpl<API::Object::Type::Session> { public: - // FIXME: We can create sessions on demand, because we hardcode the fact that all sessions but the default one are ephemeral. We'll need to create them explicitly once sessions have more configuration options. - static PassRefPtr<Session> create(bool isEphemeral); + static Ref<Session> createEphemeral(); + virtual ~Session(); + static Session& defaultSession(); - static Session& legacyPrivateSession(); bool isEphemeral() const; - uint64_t getID() const; - virtual ~Session(); + WebCore::SessionID getID() const; private: - explicit Session(bool isEphemeral); - Session(bool isEphemeral, uint64_t sessionID); - bool m_isEphemeral; - uint64_t m_sessionID; + Session(); + explicit Session(WebCore::SessionID); + + WebCore::SessionID m_sessionID; }; } // namespace API diff --git a/Source/WebKit2/UIProcess/API/APISessionState.cpp b/Source/WebKit2/UIProcess/API/APISessionState.cpp new file mode 100644 index 000000000..473e5c750 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APISessionState.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "APISessionState.h" + +namespace API { + +Ref<SessionState> SessionState::create(WebKit::SessionState sessionState) +{ + return adoptRef(*new SessionState(WTFMove(sessionState))); +} + +SessionState::SessionState(WebKit::SessionState sessionState) + : m_sessionState(WTFMove(sessionState)) +{ +} + +SessionState::~SessionState() +{ +} + +} // namespace API diff --git a/Source/WebKit2/UIProcess/API/APISessionState.h b/Source/WebKit2/UIProcess/API/APISessionState.h new file mode 100644 index 000000000..e4d32f7fc --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APISessionState.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef APISessionState_h +#define APISessionState_h + +#include "APIObject.h" +#include "SessionState.h" + +namespace API { + +class SessionState final : public ObjectImpl<Object::Type::SessionState> { +public: + static Ref<SessionState> create(WebKit::SessionState); + virtual ~SessionState(); + + const WebKit::SessionState& sessionState() const { return m_sessionState; } + +private: + explicit SessionState(WebKit::SessionState); + + const WebKit::SessionState m_sessionState; +}; + +} // namespace API + +#endif // APISessionState_h diff --git a/Source/WebKit2/UIProcess/API/APIUIClient.h b/Source/WebKit2/UIProcess/API/APIUIClient.h new file mode 100644 index 000000000..0e5927f9b --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIUIClient.h @@ -0,0 +1,175 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef APIUIClient_h +#define APIUIClient_h + +#include "WKPage.h" +#include "WebEvent.h" +#include "WebHitTestResultData.h" +#include "WebPageProxy.h" +#include <WebCore/FloatRect.h> +#include <functional> +#include <wtf/PassRefPtr.h> + +#if PLATFORM(IOS) +OBJC_CLASS NSArray; +OBJC_CLASS _WKActivatedElementInfo; +OBJC_CLASS UIViewController; +#endif + +namespace WebCore { +class ResourceRequest; +struct SecurityOriginData; +struct WindowFeatures; +} + +namespace WebKit { +class GeolocationPermissionRequestProxy; +class NativeWebKeyboardEvent; +class NativeWebWheelEvent; +class NotificationPermissionRequest; +class UserMediaPermissionCheckProxy; +class UserMediaPermissionRequestProxy; +class WebColorPickerResultListenerProxy; +class WebFrameProxy; +class WebOpenPanelParameters; +class WebOpenPanelResultListenerProxy; +class WebPageProxy; +struct NavigationActionData; + +#if ENABLE(MEDIA_SESSION) +class WebMediaSessionMetadata; +#endif +} + +namespace API { + +class Data; +class Dictionary; +class Object; +class SecurityOrigin; + +class UIClient { +public: + virtual ~UIClient() { } + + virtual PassRefPtr<WebKit::WebPageProxy> createNewPage(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, const WebCore::SecurityOriginData&, const WebCore::ResourceRequest&, const WebCore::WindowFeatures&, const WebKit::NavigationActionData&) { return nullptr; } + virtual void showPage(WebKit::WebPageProxy*) { } + virtual void fullscreenMayReturnToInline(WebKit::WebPageProxy*) { } + virtual void didEnterFullscreen(WebKit::WebPageProxy*) { } + virtual void didExitFullscreen(WebKit::WebPageProxy*) { } + virtual void close(WebKit::WebPageProxy*) { } + + virtual void takeFocus(WebKit::WebPageProxy*, WKFocusDirection) { } + virtual void focus(WebKit::WebPageProxy*) { } + virtual void unfocus(WebKit::WebPageProxy*) { } + + virtual void runJavaScriptAlert(WebKit::WebPageProxy*, const WTF::String&, WebKit::WebFrameProxy*, const WebCore::SecurityOriginData&, std::function<void ()> completionHandler) { completionHandler(); } + virtual void runJavaScriptConfirm(WebKit::WebPageProxy*, const WTF::String&, WebKit::WebFrameProxy*, const WebCore::SecurityOriginData&, std::function<void (bool)> completionHandler) { completionHandler(false); } + virtual void runJavaScriptPrompt(WebKit::WebPageProxy*, const WTF::String&, const WTF::String&, WebKit::WebFrameProxy*, const WebCore::SecurityOriginData&, std::function<void (const WTF::String&)> completionHandler) { completionHandler(WTF::String()); } + + virtual void setStatusText(WebKit::WebPageProxy*, const WTF::String&) { } + virtual void mouseDidMoveOverElement(WebKit::WebPageProxy*, const WebKit::WebHitTestResultData&, WebKit::WebEvent::Modifiers, API::Object*) { } +#if ENABLE(NETSCAPE_PLUGIN_API) + virtual void unavailablePluginButtonClicked(WebKit::WebPageProxy*, WKPluginUnavailabilityReason, API::Dictionary*) { } +#endif // ENABLE(NETSCAPE_PLUGIN_API) + + virtual bool implementsDidNotHandleKeyEvent() const { return false; } + virtual void didNotHandleKeyEvent(WebKit::WebPageProxy*, const WebKit::NativeWebKeyboardEvent&) { } + + virtual bool implementsDidNotHandleWheelEvent() const { return false; } + virtual void didNotHandleWheelEvent(WebKit::WebPageProxy*, const WebKit::NativeWebWheelEvent&) { } + + virtual bool toolbarsAreVisible(WebKit::WebPageProxy*) { return true; } + virtual void setToolbarsAreVisible(WebKit::WebPageProxy*, bool) { } + virtual bool menuBarIsVisible(WebKit::WebPageProxy*) { return true; } + virtual void setMenuBarIsVisible(WebKit::WebPageProxy*, bool) { } + virtual bool statusBarIsVisible(WebKit::WebPageProxy*) { return true; } + virtual void setStatusBarIsVisible(WebKit::WebPageProxy*, bool) { } + virtual bool isResizable(WebKit::WebPageProxy*) { return true; } + virtual void setIsResizable(WebKit::WebPageProxy*, bool) { } + + virtual void setWindowFrame(WebKit::WebPageProxy*, const WebCore::FloatRect&) { } + virtual WebCore::FloatRect windowFrame(WebKit::WebPageProxy*) { return WebCore::FloatRect(); } + + virtual bool canRunBeforeUnloadConfirmPanel() const { return false; } + virtual void runBeforeUnloadConfirmPanel(WebKit::WebPageProxy*, const WTF::String&, WebKit::WebFrameProxy*, std::function<void (bool)> completionHandler) { completionHandler(true); } + + virtual void pageDidScroll(WebKit::WebPageProxy*) { } + + virtual void exceededDatabaseQuota(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, SecurityOrigin*, 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) + { + completionHandler(currentQuota); + } + + virtual void reachedApplicationCacheOriginQuota(WebKit::WebPageProxy*, const WebCore::SecurityOrigin&, uint64_t currentQuota, uint64_t, std::function<void (unsigned long long)> completionHandler) + { + completionHandler(currentQuota); + } + + virtual bool runOpenPanel(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, WebKit::WebOpenPanelParameters*, WebKit::WebOpenPanelResultListenerProxy*) { return false; } + virtual bool decidePolicyForGeolocationPermissionRequest(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, SecurityOrigin*, WebKit::GeolocationPermissionRequestProxy*) { return false; } + virtual bool decidePolicyForUserMediaPermissionRequest(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, SecurityOrigin&, WebKit::UserMediaPermissionRequestProxy&) { return false; } + virtual bool checkUserMediaPermissionForOrigin(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, SecurityOrigin&, WebKit::UserMediaPermissionCheckProxy&) { return false; } + virtual bool decidePolicyForNotificationPermissionRequest(WebKit::WebPageProxy*, SecurityOrigin*, WebKit::NotificationPermissionRequest*) { return false; } + + // Printing. + virtual float headerHeight(WebKit::WebPageProxy*, WebKit::WebFrameProxy*) { return 0; } + virtual float footerHeight(WebKit::WebPageProxy*, WebKit::WebFrameProxy*) { return 0; } + virtual void drawHeader(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, const WebCore::FloatRect&) { } + virtual void drawFooter(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, const WebCore::FloatRect&) { } + virtual void printFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy*) { } + + virtual bool canRunModal() const { return false; } + virtual void runModal(WebKit::WebPageProxy*) { } + + virtual void saveDataToFileInDownloadsFolder(WebKit::WebPageProxy*, const WTF::String&, const WTF::String&, const WTF::String&, API::Data*) { } + + virtual void pinnedStateDidChange(WebKit::WebPageProxy&) { } + + virtual void isPlayingAudioDidChange(WebKit::WebPageProxy&) { } + +#if ENABLE(MEDIA_SESSION) + virtual void mediaSessionMetadataDidChange(WebKit::WebPageProxy&, WebKit::WebMediaSessionMetadata*) { } +#endif + +#if PLATFORM(IOS) +#if HAVE(APP_LINKS) + virtual bool shouldIncludeAppLinkActionsForElement(_WKActivatedElementInfo *) { return true; } +#endif + virtual RetainPtr<NSArray> actionsForElement(_WKActivatedElementInfo *, RetainPtr<NSArray> defaultActions) { return defaultActions; } + virtual void didNotHandleTapAsClick(const WebCore::IntPoint&) { } + virtual UIViewController *presentingViewController() { return nullptr; } +#endif + + virtual void didClickAutoFillButton(WebKit::WebPageProxy&, API::Object*) { } + + virtual void imageOrMediaDocumentSizeChanged(const WebCore::IntSize&) { } +}; + +} // namespace API + +#endif // APIUIClient_h diff --git a/Source/WebKit2/UIProcess/API/APIUserContentExtension.cpp b/Source/WebKit2/UIProcess/API/APIUserContentExtension.cpp new file mode 100644 index 000000000..b06d9d43b --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIUserContentExtension.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "APIUserContentExtension.h" + +#if ENABLE(CONTENT_EXTENSIONS) + +#include "WebCompiledContentExtension.h" + +namespace API { + +UserContentExtension::UserContentExtension(const WTF::String& name, Ref<WebKit::WebCompiledContentExtension>&& contentExtension) + : m_name(name) + , m_compiledExtension(WTFMove(contentExtension)) +{ +} + +UserContentExtension::~UserContentExtension() +{ +} + +} // namespace API + +#endif // ENABLE(CONTENT_EXTENSIONS) diff --git a/Source/WebKit2/UIProcess/API/APIUserContentExtension.h b/Source/WebKit2/UIProcess/API/APIUserContentExtension.h new file mode 100644 index 000000000..c60661870 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIUserContentExtension.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef APIUserContentExtension_h +#define APIUserContentExtension_h + +#include "APIObject.h" +#include <wtf/text/WTFString.h> + +namespace WebKit { +class WebCompiledContentExtension; +} + +namespace API { + +class UserContentExtension final : public ObjectImpl<Object::Type::UserContentExtension> { +public: +#if ENABLE(CONTENT_EXTENSIONS) + static Ref<UserContentExtension> create(const WTF::String& name, Ref<WebKit::WebCompiledContentExtension>&& contentExtension) + { + return adoptRef(*new UserContentExtension(name, WTFMove(contentExtension))); + } + + UserContentExtension(const WTF::String& name, Ref<WebKit::WebCompiledContentExtension>&&); + virtual ~UserContentExtension(); + + const WTF::String& name() const { return m_name; } + const WebKit::WebCompiledContentExtension& compiledExtension() const { return m_compiledExtension.get(); } + +private: + WTF::String m_name; + Ref<WebKit::WebCompiledContentExtension> m_compiledExtension; +#endif // ENABLE(CONTENT_EXTENSIONS) +}; + +} // namespace API + +#endif // APIUserContentExtension_h diff --git a/Source/WebKit2/UIProcess/API/APIUserContentExtensionStore.cpp b/Source/WebKit2/UIProcess/API/APIUserContentExtensionStore.cpp new file mode 100644 index 000000000..ae08a2ad5 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIUserContentExtensionStore.cpp @@ -0,0 +1,425 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "APIUserContentExtensionStore.h" + +#if ENABLE(CONTENT_EXTENSIONS) + +#include "APIUserContentExtension.h" +#include "NetworkCacheData.h" +#include "NetworkCacheDecoder.h" +#include "NetworkCacheEncoder.h" +#include "NetworkCacheFileSystem.h" +#include "SharedMemory.h" +#include "WebCompiledContentExtension.h" +#include <WebCore/ContentExtensionCompiler.h> +#include <WebCore/ContentExtensionError.h> +#include <string> +#include <wtf/NeverDestroyed.h> +#include <wtf/RunLoop.h> +#include <wtf/WorkQueue.h> + +using namespace WebKit::NetworkCache; + +namespace API { + +UserContentExtensionStore& UserContentExtensionStore::defaultStore() +{ + static UserContentExtensionStore* defaultStore = adoptRef(new UserContentExtensionStore).leakRef(); + return *defaultStore; +} + +Ref<UserContentExtensionStore> UserContentExtensionStore::storeWithPath(const WTF::String& storePath) +{ + return adoptRef(*new UserContentExtensionStore(storePath)); +} + +UserContentExtensionStore::UserContentExtensionStore() + : UserContentExtensionStore(defaultStorePath()) +{ +} + +UserContentExtensionStore::UserContentExtensionStore(const WTF::String& storePath) + : m_storePath(storePath) + , m_compileQueue(WorkQueue::create("UserContentExtensionStore Compile Queue", WorkQueue::Type::Concurrent)) + , m_readQueue(WorkQueue::create("UserContentExtensionStore Read Queue")) + , m_removeQueue(WorkQueue::create("UserContentExtensionStore Remove Queue")) +{ +} + +UserContentExtensionStore::~UserContentExtensionStore() +{ +} + +static String constructedPath(const String& base, const String& identifier) +{ + return WebCore::pathByAppendingComponent(base, "ContentExtension-" + WebCore::encodeForFileName(identifier)); +} + +const size_t ContentExtensionFileHeaderSize = sizeof(uint32_t) + 4 * sizeof(uint64_t); +struct ContentExtensionMetaData { + uint32_t version { UserContentExtensionStore::CurrentContentExtensionFileVersion }; + uint64_t actionsSize { 0 }; + uint64_t filtersWithoutDomainsBytecodeSize { 0 }; + uint64_t filtersWithDomainBytecodeSize { 0 }; + uint64_t domainFiltersBytecodeSize { 0 }; + + size_t fileSize() const + { + return ContentExtensionFileHeaderSize + + actionsSize + + filtersWithoutDomainsBytecodeSize + + filtersWithDomainBytecodeSize + + domainFiltersBytecodeSize; + } +}; + +static Data encodeContentExtensionMetaData(const ContentExtensionMetaData& metaData) +{ + WebKit::NetworkCache::Encoder encoder; + + encoder << metaData.version; + encoder << metaData.actionsSize; + encoder << metaData.filtersWithoutDomainsBytecodeSize; + encoder << metaData.filtersWithDomainBytecodeSize; + encoder << metaData.domainFiltersBytecodeSize; + + ASSERT(encoder.bufferSize() == ContentExtensionFileHeaderSize); + return Data(encoder.buffer(), encoder.bufferSize()); +} + +static bool decodeContentExtensionMetaData(ContentExtensionMetaData& metaData, const Data& fileData) +{ + bool success = false; + fileData.apply([&metaData, &success, &fileData](const uint8_t* data, size_t size) { + // The file data should be mapped into one continuous memory segment so the size + // passed to the applier should always equal the data size. + if (size != fileData.size()) + return false; + + WebKit::NetworkCache::Decoder decoder(data, size); + if (!decoder.decode(metaData.version)) + return false; + if (!decoder.decode(metaData.actionsSize)) + return false; + if (!decoder.decode(metaData.filtersWithoutDomainsBytecodeSize)) + return false; + if (!decoder.decode(metaData.filtersWithDomainBytecodeSize)) + return false; + if (!decoder.decode(metaData.domainFiltersBytecodeSize)) + return false; + success = true; + return false; + }); + return success; +} + +static bool openAndMapContentExtension(const String& path, ContentExtensionMetaData& metaData, Data& fileData) +{ + fileData = mapFile(WebCore::fileSystemRepresentation(path).data()); + if (fileData.isNull()) + return false; + + if (!decodeContentExtensionMetaData(metaData, fileData)) + return false; + + return true; +} + +static bool writeDataToFile(const Data& fileData, WebCore::PlatformFileHandle fd) +{ + bool success = true; + fileData.apply([fd, &success](const uint8_t* data, size_t size) { + if (WebCore::writeToFile(fd, (const char*)data, size) == -1) { + success = false; + return false; + } + return true; + }); + + return success; +} + +static std::error_code compiledToFile(String&& json, const String& finalFilePath, ContentExtensionMetaData& metaData, Data& mappedData) +{ + using namespace WebCore::ContentExtensions; + + class CompilationClient final : public ContentExtensionCompilationClient { + public: + CompilationClient(WebCore::PlatformFileHandle fileHandle, ContentExtensionMetaData& metaData) + : m_fileHandle(fileHandle) + , m_metaData(metaData) + { + ASSERT(!metaData.actionsSize); + ASSERT(!metaData.filtersWithoutDomainsBytecodeSize); + ASSERT(!metaData.filtersWithDomainBytecodeSize); + ASSERT(!metaData.domainFiltersBytecodeSize); + } + + virtual void writeFiltersWithoutDomainsBytecode(Vector<DFABytecode>&& bytecode) override + { + ASSERT(!m_filtersWithDomainBytecodeWritten); + ASSERT(!m_domainFiltersBytecodeWritten); + m_filtersWithoutDomainsBytecodeWritten += bytecode.size(); + writeToFile(Data(bytecode.data(), bytecode.size())); + } + + virtual void writeFiltersWithDomainsBytecode(Vector<DFABytecode>&& bytecode) override + { + ASSERT(!m_domainFiltersBytecodeWritten); + m_filtersWithDomainBytecodeWritten += bytecode.size(); + writeToFile(Data(bytecode.data(), bytecode.size())); + } + + virtual void writeDomainFiltersBytecode(Vector<DFABytecode>&& bytecode) override + { + m_domainFiltersBytecodeWritten += bytecode.size(); + writeToFile(Data(bytecode.data(), bytecode.size())); + } + + virtual void writeActions(Vector<SerializedActionByte>&& actions) override + { + ASSERT(!m_filtersWithoutDomainsBytecodeWritten); + ASSERT(!m_filtersWithDomainBytecodeWritten); + ASSERT(!m_domainFiltersBytecodeWritten); + ASSERT(!m_actionsWritten); + m_actionsWritten += actions.size(); + writeToFile(Data(actions.data(), actions.size())); + } + + virtual void finalize() override + { + m_metaData.actionsSize = m_actionsWritten; + m_metaData.filtersWithoutDomainsBytecodeSize = m_filtersWithoutDomainsBytecodeWritten; + m_metaData.filtersWithDomainBytecodeSize = m_filtersWithDomainBytecodeWritten; + m_metaData.domainFiltersBytecodeSize = m_domainFiltersBytecodeWritten; + + Data header = encodeContentExtensionMetaData(m_metaData); + if (!m_fileError && WebCore::seekFile(m_fileHandle, 0ll, WebCore::FileSeekOrigin::SeekFromBeginning) == -1) { + WebCore::closeFile(m_fileHandle); + m_fileError = true; + } + writeToFile(header); + } + + bool hadErrorWhileWritingToFile() { return m_fileError; } + + private: + void writeToFile(const Data& data) + { + if (!m_fileError && !writeDataToFile(data, m_fileHandle)) { + WebCore::closeFile(m_fileHandle); + m_fileError = true; + } + } + + WebCore::PlatformFileHandle m_fileHandle; + ContentExtensionMetaData& m_metaData; + size_t m_filtersWithoutDomainsBytecodeWritten { 0 }; + size_t m_filtersWithDomainBytecodeWritten { 0 }; + size_t m_domainFiltersBytecodeWritten { 0 }; + size_t m_actionsWritten { 0 }; + bool m_fileError { false }; + }; + + auto temporaryFileHandle = WebCore::invalidPlatformFileHandle; + String temporaryFilePath = WebCore::openTemporaryFile("ContentExtension", temporaryFileHandle); + if (temporaryFileHandle == WebCore::invalidPlatformFileHandle) + return UserContentExtensionStore::Error::CompileFailed; + + char invalidHeader[ContentExtensionFileHeaderSize]; + memset(invalidHeader, 0xFF, sizeof(invalidHeader)); + // This header will be rewritten in CompilationClient::finalize. + if (WebCore::writeToFile(temporaryFileHandle, invalidHeader, sizeof(invalidHeader)) == -1) { + WebCore::closeFile(temporaryFileHandle); + return UserContentExtensionStore::Error::CompileFailed; + } + + CompilationClient compilationClient(temporaryFileHandle, metaData); + + if (auto compilerError = compileRuleList(compilationClient, WTFMove(json))) { + WebCore::closeFile(temporaryFileHandle); + return compilerError; + } + if (compilationClient.hadErrorWhileWritingToFile()) { + WebCore::closeFile(temporaryFileHandle); + return UserContentExtensionStore::Error::CompileFailed; + } + + mappedData = adoptAndMapFile(temporaryFileHandle, 0, metaData.fileSize()); + if (mappedData.isNull()) + return UserContentExtensionStore::Error::CompileFailed; + + if (!WebCore::moveFile(temporaryFilePath, finalFilePath)) + return UserContentExtensionStore::Error::CompileFailed; + + return { }; +} + +static RefPtr<API::UserContentExtension> createExtension(const String& identifier, const ContentExtensionMetaData& metaData, const Data& fileData) +{ + auto sharedMemory = WebKit::SharedMemory::create(const_cast<uint8_t*>(fileData.data()), fileData.size(), WebKit::SharedMemory::Protection::ReadOnly); + auto compiledContentExtensionData = WebKit::WebCompiledContentExtensionData( + WTFMove(sharedMemory), + fileData, + ContentExtensionFileHeaderSize, + metaData.actionsSize, + ContentExtensionFileHeaderSize + + metaData.actionsSize, + metaData.filtersWithoutDomainsBytecodeSize, + ContentExtensionFileHeaderSize + + metaData.actionsSize + + metaData.filtersWithoutDomainsBytecodeSize, + metaData.filtersWithDomainBytecodeSize, + ContentExtensionFileHeaderSize + + metaData.actionsSize + + metaData.filtersWithoutDomainsBytecodeSize + + metaData.filtersWithDomainBytecodeSize, + metaData.domainFiltersBytecodeSize + ); + auto compiledContentExtension = WebKit::WebCompiledContentExtension::create(WTFMove(compiledContentExtensionData)); + return API::UserContentExtension::create(identifier, WTFMove(compiledContentExtension)); +} + +void UserContentExtensionStore::lookupContentExtension(const WTF::String& identifier, std::function<void(RefPtr<API::UserContentExtension>, std::error_code)> completionHandler) +{ + RefPtr<UserContentExtensionStore> self(this); + StringCapture identifierCapture(identifier); + StringCapture pathCapture(m_storePath); + + m_readQueue->dispatch([self, identifierCapture, pathCapture, completionHandler] { + auto path = constructedPath(pathCapture.string(), identifierCapture.string()); + + ContentExtensionMetaData metaData; + Data fileData; + if (!openAndMapContentExtension(path, metaData, fileData)) { + RunLoop::main().dispatch([self, completionHandler] { + completionHandler(nullptr, Error::LookupFailed); + }); + return; + } + + if (metaData.version != UserContentExtensionStore::CurrentContentExtensionFileVersion) { + RunLoop::main().dispatch([self, completionHandler] { + completionHandler(nullptr, Error::VersionMismatch); + }); + return; + } + + RunLoop::main().dispatch([self, identifierCapture, fileData, metaData, completionHandler] { + RefPtr<API::UserContentExtension> userContentExtension = createExtension(identifierCapture.string(), metaData, fileData); + completionHandler(userContentExtension, { }); + }); + }); +} + +void UserContentExtensionStore::compileContentExtension(const WTF::String& identifier, WTF::String&& json, std::function<void(RefPtr<API::UserContentExtension>, std::error_code)> completionHandler) +{ + RefPtr<UserContentExtensionStore> self(this); + StringCapture identifierCapture(identifier); + StringCapture jsonCapture(WTFMove(json)); + StringCapture pathCapture(m_storePath); + + m_compileQueue->dispatch([self, identifierCapture, jsonCapture, pathCapture, completionHandler] () mutable { + auto path = constructedPath(pathCapture.string(), identifierCapture.string()); + + ContentExtensionMetaData metaData; + Data fileData; + auto error = compiledToFile(jsonCapture.releaseString(), path, metaData, fileData); + if (error) { + RunLoop::main().dispatch([self, error, completionHandler] { + completionHandler(nullptr, error); + }); + return; + } + + RunLoop::main().dispatch([self, identifierCapture, fileData, metaData, completionHandler] { + RefPtr<API::UserContentExtension> userContentExtension = createExtension(identifierCapture.string(), metaData, fileData); + completionHandler(userContentExtension, { }); + }); + }); +} + +void UserContentExtensionStore::removeContentExtension(const WTF::String& identifier, std::function<void(std::error_code)> completionHandler) +{ + RefPtr<UserContentExtensionStore> self(this); + StringCapture identifierCapture(identifier); + StringCapture pathCapture(m_storePath); + + m_removeQueue->dispatch([self, identifierCapture, pathCapture, completionHandler] { + auto path = constructedPath(pathCapture.string(), identifierCapture.string()); + + if (!WebCore::deleteFile(path)) { + RunLoop::main().dispatch([self, completionHandler] { + completionHandler(Error::RemoveFailed); + }); + return; + } + + RunLoop::main().dispatch([self, completionHandler] { + completionHandler({ }); + }); + }); +} + +void UserContentExtensionStore::synchronousRemoveAllContentExtensions() +{ + for (const auto& path : WebCore::listDirectory(m_storePath, "*")) + WebCore::deleteFile(path); +} + +const std::error_category& userContentExtensionStoreErrorCategory() +{ + class UserContentExtensionStoreErrorCategory : public std::error_category { + const char* name() const noexcept override + { + return "user content extension store"; + } + + virtual std::string message(int errorCode) const override + { + switch (static_cast<UserContentExtensionStore::Error>(errorCode)) { + case UserContentExtensionStore::Error::LookupFailed: + return "Unspecified error during lookup."; + case UserContentExtensionStore::Error::VersionMismatch: + return "Version of file does not match version of interpreter."; + case UserContentExtensionStore::Error::CompileFailed: + return "Unspecified error during compile."; + case UserContentExtensionStore::Error::RemoveFailed: + return "Unspecified error during remove."; + } + + return std::string(); + } + }; + + static NeverDestroyed<UserContentExtensionStoreErrorCategory> contentExtensionErrorCategory; + return contentExtensionErrorCategory; +} + +} // namespace API + +#endif // ENABLE(CONTENT_EXTENSIONS) diff --git a/Source/WebKit2/UIProcess/API/APIUserContentExtensionStore.h b/Source/WebKit2/UIProcess/API/APIUserContentExtensionStore.h new file mode 100644 index 000000000..28309fbb6 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIUserContentExtensionStore.h @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef APIUserContentExtensionStore_h +#define APIUserContentExtensionStore_h + +#if ENABLE(CONTENT_EXTENSIONS) + +#include "APIObject.h" +#include <system_error> +#include <wtf/text/WTFString.h> + +namespace WTF { +class WorkQueue; +} + +namespace API { + +class UserContentExtension; + +class UserContentExtensionStore final : public ObjectImpl<Object::Type::UserContentExtensionStore> { +public: + enum class Error { + LookupFailed = 1, + VersionMismatch, + CompileFailed, + RemoveFailed + }; + + // This should be incremented every time a functional change is made to the bytecode, file format, etc. + // to prevent crashing while loading old data. + const static uint32_t CurrentContentExtensionFileVersion = 7; + + static UserContentExtensionStore& defaultStore(); + static Ref<UserContentExtensionStore> storeWithPath(const WTF::String& storePath); + + explicit UserContentExtensionStore(); + explicit UserContentExtensionStore(const WTF::String& storePath); + virtual ~UserContentExtensionStore(); + + void compileContentExtension(const WTF::String& identifier, WTF::String&& json, std::function<void(RefPtr<API::UserContentExtension>, std::error_code)>); + void lookupContentExtension(const WTF::String& identifier, std::function<void(RefPtr<API::UserContentExtension>, std::error_code)>); + void removeContentExtension(const WTF::String& identifier, std::function<void(std::error_code)>); + + // For testing only. + void synchronousRemoveAllContentExtensions(); + +private: + WTF::String defaultStorePath(); + + const WTF::String m_storePath; + Ref<WTF::WorkQueue> m_compileQueue; + Ref<WTF::WorkQueue> m_readQueue; + Ref<WTF::WorkQueue> m_removeQueue; +}; + +const std::error_category& userContentExtensionStoreErrorCategory(); + +inline std::error_code make_error_code(UserContentExtensionStore::Error error) +{ + return { static_cast<int>(error), userContentExtensionStoreErrorCategory() }; +} + +} // namespace API + +namespace std { + template<> struct is_error_code_enum<API::UserContentExtensionStore::Error> : public true_type { }; +} + +#endif // ENABLE(CONTENT_EXTENSIONS) +#endif // APIUserContentExtensionStore_h diff --git a/Source/WebKit2/UIProcess/API/APIUserScript.cpp b/Source/WebKit2/UIProcess/API/APIUserScript.cpp new file mode 100644 index 000000000..84ea6a1c8 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIUserScript.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "APIUserScript.h" + +#include <wtf/text/StringBuilder.h> + +namespace API { + +static uint64_t generateIdentifier() +{ + static uint64_t identifier; + + return ++identifier; +} + +WebCore::URL UserScript::generateUniqueURL() +{ + StringBuilder urlStringBuilder; + urlStringBuilder.appendLiteral("user-script:"); + urlStringBuilder.appendNumber(generateIdentifier()); + return { { }, urlStringBuilder.toString() }; +} + + +} // namespace API diff --git a/Source/WebKit2/UIProcess/API/APIUserScript.h b/Source/WebKit2/UIProcess/API/APIUserScript.h new file mode 100644 index 000000000..03e2f62cd --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIUserScript.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef APIUserScript_h +#define APIUserScript_h + +#include "APIObject.h" +#include <WebCore/UserScript.h> + +namespace API { + +class UserScript final : public ObjectImpl<Object::Type::UserScript> { +public: + static WebCore::URL generateUniqueURL(); + + static Ref<UserScript> create(WebCore::UserScript userScript) + { + return adoptRef(*new UserScript(WTFMove(userScript))); + } + + UserScript(WebCore::UserScript userScript) + : m_userScript(userScript) + { + } + + const WebCore::UserScript& userScript() const { return m_userScript; } + +private: + WebCore::UserScript m_userScript; +}; + +} // namespace API + +#endif // APIUserScript_h diff --git a/Source/WebKit2/UIProcess/API/APIUserStyleSheet.cpp b/Source/WebKit2/UIProcess/API/APIUserStyleSheet.cpp new file mode 100644 index 000000000..0c1b2ac22 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIUserStyleSheet.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "APIUserStyleSheet.h" + +#include <wtf/text/StringBuilder.h> + +namespace API { + +static uint64_t generateIdentifier() +{ + static uint64_t identifier; + + return ++identifier; +} + +WebCore::URL UserStyleSheet::generateUniqueURL() +{ + StringBuilder urlStringBuilder; + urlStringBuilder.appendLiteral("user-style-sheet:"); + urlStringBuilder.appendNumber(generateIdentifier()); + return { { }, urlStringBuilder.toString() }; +} + + +} // namespace API diff --git a/Source/WebKit2/UIProcess/API/APIUserStyleSheet.h b/Source/WebKit2/UIProcess/API/APIUserStyleSheet.h new file mode 100644 index 000000000..ac5754cac --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIUserStyleSheet.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef APIUserStyleSheet_h +#define APIUserStyleSheet_h + +#include "APIObject.h" +#include <WebCore/UserStyleSheet.h> + +namespace API { + +class UserStyleSheet final : public ObjectImpl<Object::Type::UserStyleSheet> { +public: + static WebCore::URL generateUniqueURL(); + + UserStyleSheet(WebCore::UserStyleSheet userStyleSheet) + : m_userStyleSheet(userStyleSheet) + { + } + + const WebCore::UserStyleSheet& userStyleSheet() const { return m_userStyleSheet; } + +private: + WebCore::UserStyleSheet m_userStyleSheet; +}; + +} // namespace API + +#endif // APIUserStyleSheet_h diff --git a/Source/WebKit2/UIProcess/API/APIWebsiteDataRecord.cpp b/Source/WebKit2/UIProcess/API/APIWebsiteDataRecord.cpp new file mode 100644 index 000000000..d4885904c --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIWebsiteDataRecord.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "APIWebsiteDataRecord.h" + +namespace API { + +Ref<WebsiteDataRecord> WebsiteDataRecord::create(WebKit::WebsiteDataRecord&& websiteDataRecord) +{ + return adoptRef(*new WebsiteDataRecord(WTFMove(websiteDataRecord))); +} + +WebsiteDataRecord::WebsiteDataRecord(WebKit::WebsiteDataRecord&& websiteDataRecord) + : m_websiteDataRecord(WTFMove(websiteDataRecord)) +{ +} + +WebsiteDataRecord::~WebsiteDataRecord() +{ +} + +} diff --git a/Source/WebKit2/UIProcess/API/APIWebsiteDataRecord.h b/Source/WebKit2/UIProcess/API/APIWebsiteDataRecord.h new file mode 100644 index 000000000..0ccdb2190 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIWebsiteDataRecord.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef APIWebsiteDataRecord_h +#define APIWebsiteDataRecord_h + +#include "APIObject.h" +#include "WebsiteDataRecord.h" + +namespace API { + +class WebsiteDataRecord final : public ObjectImpl<Object::Type::WebsiteDataRecord> { +public: + static Ref<WebsiteDataRecord> create(WebKit::WebsiteDataRecord&&); + virtual ~WebsiteDataRecord(); + + const WebKit::WebsiteDataRecord& websiteDataRecord() const { return m_websiteDataRecord; } + +private: + explicit WebsiteDataRecord(WebKit::WebsiteDataRecord&&); + + const WebKit::WebsiteDataRecord m_websiteDataRecord; +}; + +} + +#endif // APIWebsiteDataRecord_h diff --git a/Source/WebKit2/UIProcess/API/APIWebsiteDataStore.cpp b/Source/WebKit2/UIProcess/API/APIWebsiteDataStore.cpp new file mode 100644 index 000000000..1d0873890 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIWebsiteDataStore.cpp @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "APIWebsiteDataStore.h" + +#include "WebsiteDataStore.h" + +namespace API { + +RefPtr<WebsiteDataStore> WebsiteDataStore::defaultDataStore() +{ + static WebsiteDataStore* defaultDataStore = adoptRef(new WebsiteDataStore(defaultDataStoreConfiguration())).leakRef(); + + return defaultDataStore; +} + +Ref<WebsiteDataStore> WebsiteDataStore::createNonPersistentDataStore() +{ + return adoptRef(*new WebsiteDataStore); +} + +Ref<WebsiteDataStore> WebsiteDataStore::create(WebKit::WebsiteDataStore::Configuration configuration) +{ + return adoptRef(*new WebsiteDataStore(WTFMove(configuration))); +} + +WebsiteDataStore::WebsiteDataStore() + : m_websiteDataStore(WebKit::WebsiteDataStore::createNonPersistent()) +{ +} + +WebsiteDataStore::WebsiteDataStore(WebKit::WebsiteDataStore::Configuration configuration) + : m_websiteDataStore(WebKit::WebsiteDataStore::create(WTFMove(configuration))) +{ +} + +WebsiteDataStore::~WebsiteDataStore() +{ +} + +bool WebsiteDataStore::isPersistent() +{ + return m_websiteDataStore->isPersistent(); +} + +#if !PLATFORM(COCOA) && !PLATFORM(EFL) && !PLATFORM(GTK) +WebKit::WebsiteDataStore::Configuration WebsiteDataStore::defaultDataStoreConfiguration() +{ + // FIXME: Fill everything in. + WebKit::WebsiteDataStore::Configuration configuration; + + return configuration; +} + +String WebsiteDataStore::websiteDataDirectoryFileSystemRepresentation(const String&) +{ + // FIXME: Implement. + return String(); +} + +String WebsiteDataStore::defaultLocalStorageDirectory() +{ + // FIXME: Implement. + return String(); +} + +String WebsiteDataStore::defaultWebSQLDatabaseDirectory() +{ + // FIXME: Implement. + return String(); +} + +String WebsiteDataStore::defaultNetworkCacheDirectory() +{ + // FIXME: Implement. + return String(); +} + +String WebsiteDataStore::defaultApplicationCacheDirectory() +{ + // FIXME: Implement. + return String(); +} + +String WebsiteDataStore::defaultMediaKeysStorageDirectory() +{ + // FIXME: Implement. + return String(); +} + +String WebsiteDataStore::defaultIndexedDBDatabaseDirectory() +{ + // FIXME: Implement. + return String(); +} + +#endif + +} diff --git a/Source/WebKit2/UIProcess/API/APIWebsiteDataStore.h b/Source/WebKit2/UIProcess/API/APIWebsiteDataStore.h new file mode 100644 index 000000000..559b4a99b --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIWebsiteDataStore.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef APIWebsiteDataStore_h +#define APIWebsiteDataStore_h + +#include "APIObject.h" +#include "WebsiteDataStore.h" +#include <WebCore/SessionID.h> +#include <wtf/text/WTFString.h> + +namespace API { + +class WebsiteDataStore final : public ObjectImpl<Object::Type::WebsiteDataStore> { +public: + static RefPtr<WebsiteDataStore> defaultDataStore(); + static Ref<WebsiteDataStore> createNonPersistentDataStore(); + static Ref<WebsiteDataStore> create(WebKit::WebsiteDataStore::Configuration); + virtual ~WebsiteDataStore(); + + bool isPersistent(); + + WebKit::WebsiteDataStore& websiteDataStore() { return *m_websiteDataStore; } + + static String defaultApplicationCacheDirectory(); + static String defaultNetworkCacheDirectory(); + + static String defaultIndexedDBDatabaseDirectory(); + static String defaultLocalStorageDirectory(); + static String defaultMediaKeysStorageDirectory(); + static String defaultWebSQLDatabaseDirectory(); + +private: + WebsiteDataStore(WebKit::WebsiteDataStore::Configuration); + WebsiteDataStore(); + + static String cacheDirectoryFileSystemRepresentation(const String& directoryName); + static String websiteDataDirectoryFileSystemRepresentation(const String& directoryName); + + static WebKit::WebsiteDataStore::Configuration defaultDataStoreConfiguration(); + + RefPtr<WebKit::WebsiteDataStore> m_websiteDataStore; +}; + +} + +#endif // APIWebsiteDataStore_h diff --git a/Source/WebKit2/UIProcess/API/APIWindowFeatures.cpp b/Source/WebKit2/UIProcess/API/APIWindowFeatures.cpp new file mode 100644 index 000000000..f6fa0dc31 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIWindowFeatures.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "APIWindowFeatures.h" + +namespace API { + +Ref<WindowFeatures> WindowFeatures::create(const WebCore::WindowFeatures& windowFeatures) +{ + return adoptRef(*new WindowFeatures(windowFeatures)); +} + +WindowFeatures::WindowFeatures(const WebCore::WindowFeatures& windowFeatures) + : m_windowFeatures(windowFeatures) +{ +} + +WindowFeatures::~WindowFeatures() +{ +} + +} diff --git a/Source/WebKit2/UIProcess/API/APIWindowFeatures.h b/Source/WebKit2/UIProcess/API/APIWindowFeatures.h new file mode 100644 index 000000000..ccedf79fd --- /dev/null +++ b/Source/WebKit2/UIProcess/API/APIWindowFeatures.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef APIWindowFeatures_h +#define APIWindowFeatures_h + +#include "APIObject.h" +#include <WebCore/WindowFeatures.h> + +namespace API { + +class WindowFeatures final : public ObjectImpl<Object::Type::WindowFeatures> { +public: + static Ref<WindowFeatures> create(const WebCore::WindowFeatures&); + virtual ~WindowFeatures(); + + const WebCore::WindowFeatures& windowFeatures() const { return m_windowFeatures; } + +private: + explicit WindowFeatures(const WebCore::WindowFeatures&); + + const WebCore::WindowFeatures m_windowFeatures; +}; + +} + +#endif // APIWindowFeatures_h diff --git a/Source/WebKit2/UIProcess/API/C/CoordinatedGraphics/WKView.cpp b/Source/WebKit2/UIProcess/API/C/CoordinatedGraphics/WKView.cpp new file mode 100644 index 000000000..b14b99503 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/CoordinatedGraphics/WKView.cpp @@ -0,0 +1,205 @@ +/* + * Copyright (C) 2012 Samsung Electronics + * Copyright (C) 2013 Intel Corporation. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this program; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#if USE(COORDINATED_GRAPHICS) + +#include "WKView.h" + +#include "APIPageConfiguration.h" +#include "WKAPICast.h" +#include "WebView.h" + +using namespace WebCore; +using namespace WebKit; + +WKViewRef WKViewCreate(WKContextRef context, WKPageConfigurationRef pageConfiguration) +{ + RefPtr<WebView> webView = WebView::create(toImpl(context), *toImpl(pageConfiguration)); + return toAPI(webView.release().leakRef()); +} + +WKSize WKViewGetSize(WKViewRef viewRef) +{ + return toAPI(toImpl(viewRef)->size()); +} + +void WKViewSetSize(WKViewRef viewRef, WKSize size) +{ + toImpl(viewRef)->setSize(toIntSize(size)); +} + +void WKViewSetViewClient(WKViewRef viewRef, const WKViewClientBase* client) +{ + toImpl(viewRef)->initializeClient(client); +} + +bool WKViewIsActive(WKViewRef viewRef) +{ + return toImpl(viewRef)->isActive(); +} + +void WKViewSetIsActive(WKViewRef viewRef, bool isActive) +{ + toImpl(viewRef)->setActive(isActive); +} + +bool WKViewIsFocused(WKViewRef viewRef) +{ + return toImpl(viewRef)->isFocused(); +} + +void WKViewSetIsFocused(WKViewRef viewRef, bool isFocused) +{ + toImpl(viewRef)->setFocused(isFocused); +} + +bool WKViewIsVisible(WKViewRef viewRef) +{ + return toImpl(viewRef)->isVisible(); +} + +void WKViewSetIsVisible(WKViewRef viewRef, bool isVisible) +{ + toImpl(viewRef)->setVisible(isVisible); +} + +float WKViewGetContentScaleFactor(WKViewRef viewRef) +{ + return toImpl(viewRef)->contentScaleFactor(); +} + +void WKViewSetContentScaleFactor(WKViewRef viewRef, float scale) +{ + toImpl(viewRef)->setContentScaleFactor(scale); +} + +WKPoint WKViewGetContentPosition(WKViewRef viewRef) +{ + const WebCore::FloatPoint& result = toImpl(viewRef)->contentPosition(); + return WKPointMake(result.x(), result.y()); +} + +void WKViewSetContentPosition(WKViewRef viewRef, WKPoint position) +{ + toImpl(viewRef)->setContentPosition(WebCore::FloatPoint(position.x, position.y)); +} + +void WKViewSetUserViewportTranslation(WKViewRef viewRef, double tx, double ty) +{ + toImpl(viewRef)->setUserViewportTranslation(tx, ty); +} + +WKPoint WKViewUserViewportToContents(WKViewRef viewRef, WKPoint point) +{ + const WebCore::IntPoint& result = toImpl(viewRef)->userViewportToContents(toIntPoint(point)); + return WKPointMake(result.x(), result.y()); +} + +WKPoint WKViewUserViewportToScene(WKViewRef viewRef, WKPoint point) +{ + WebCore::IntPoint result = toImpl(viewRef)->userViewportToScene(toIntPoint(point)); + return WKPointMake(result.x(), result.y()); +} + +WKPoint WKViewContentsToUserViewport(WKViewRef viewRef, WKPoint point) +{ + WebCore::IntPoint result = toImpl(viewRef)->contentsToUserViewport(toIntPoint(point)); + return WKPointMake(result.x(), result.y()); +} + +void WKViewPaintToCurrentGLContext(WKViewRef viewRef) +{ + toImpl(viewRef)->paintToCurrentGLContext(); +} + +WKPageRef WKViewGetPage(WKViewRef viewRef) +{ + return toImpl(viewRef)->pageRef(); +} + +void WKViewSetDrawsBackground(WKViewRef viewRef, bool flag) +{ + toImpl(viewRef)->setDrawsBackground(flag); +} + +bool WKViewGetDrawsBackground(WKViewRef viewRef) +{ + return toImpl(viewRef)->drawsBackground(); +} + +void WKViewSetDrawsTransparentBackground(WKViewRef viewRef, bool flag) +{ + toImpl(viewRef)->setDrawsTransparentBackground(flag); +} + +bool WKViewGetDrawsTransparentBackground(WKViewRef viewRef) +{ + return toImpl(viewRef)->drawsTransparentBackground(); +} + +void WKViewSuspendActiveDOMObjectsAndAnimations(WKViewRef viewRef) +{ + toImpl(viewRef)->suspendActiveDOMObjectsAndAnimations(); +} + +void WKViewResumeActiveDOMObjectsAndAnimations(WKViewRef viewRef) +{ + toImpl(viewRef)->resumeActiveDOMObjectsAndAnimations(); +} + +bool WKViewExitFullScreen(WKViewRef viewRef) +{ +#if ENABLE(FULLSCREEN_API) + return toImpl(viewRef)->requestExitFullScreen(); +#else + UNUSED_PARAM(viewRef); + return false; +#endif +} + +void WKViewSetOpacity(WKViewRef view, double opacity) +{ + toImpl(view)->setOpacity(opacity); +} + +double WKViewOpacity(WKViewRef view) +{ + return toImpl(view)->opacity(); +} + +void WKViewFindZoomableAreaForRect(WKViewRef viewRef, WKRect wkRect) +{ +#if USE(COORDINATED_GRAPHICS_MULTIPROCESS) + IntRect rect = toIntRect(wkRect); + toImpl(viewRef)->findZoomableAreaForPoint(rect.center(), rect.size()); +#else + UNUSED_PARAM(viewRef); + UNUSED_PARAM(wkRect); +#endif +} + +WKSize WKViewGetContentsSize(WKViewRef viewRef) +{ + const WebCore::IntSize& size = toImpl(viewRef)->contentsSize(); + return WKSizeMake(size.width(), size.height()); +} + +#endif // USE(COORDINATED_GRAPHICS) diff --git a/Source/WebKit2/UIProcess/API/C/CoordinatedGraphics/WKView.h b/Source/WebKit2/UIProcess/API/C/CoordinatedGraphics/WKView.h new file mode 100644 index 000000000..60f4239e0 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/CoordinatedGraphics/WKView.h @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2012 Samsung Electronics + * Copyright (C) 2013 Intel Corporation. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this program; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef WKView_h +#define WKView_h + +#include <WebKit/WKBase.h> +#include <WebKit/WKGeometry.h> + +#ifndef __cplusplus +#include <stdbool.h> +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*WKViewCallback)(WKViewRef view, const void* clientInfo); +typedef void (*WKViewViewNeedsDisplayCallback)(WKViewRef view, WKRect area, const void* clientInfo); +typedef void (*WKViewPageDidChangeContentsSizeCallback)(WKViewRef view, WKSize size, const void* clientInfo); +typedef void (*WKViewWebProcessCrashedCallback)(WKViewRef view, WKURLRef url, const void* clientInfo); +typedef void (*WKViewPageDidChangeContentsPositionCallback)(WKViewRef view, WKPoint position, const void* clientInfo); +typedef void (*WKViewPageDidRenderFrameCallback)(WKViewRef view, WKSize contentsSize, WKRect coveredRect, const void* clientInfo); +typedef void (*WKViewPageDidChangeViewportAttributesCallback)(WKViewRef view, WKViewportAttributesRef, const void* clientInfo); +typedef void (*WKViewPageDidChangeTooltipCallback)(WKViewRef view, WKStringRef newTooltip, const void* clientInfo); +typedef void (*WKViewDidFindZoomableAreaCallback)(WKViewRef view, WKPoint point, WKRect area, const void* clientInfo); +typedef void (*WKViewDoneWithTouchEventCallback)(WKViewRef view, WKTouchEventRef touchEvent, bool wasEventHandled, const void* clientInfo); + +typedef struct WKViewClientBase { + int version; + const void* clientInfo; +} WKViewClientBase; + +typedef struct WKViewClientV0 { + WKViewClientBase base; + // Version 0 + WKViewViewNeedsDisplayCallback viewNeedsDisplay; + WKViewPageDidChangeContentsSizeCallback didChangeContentsSize; + WKViewWebProcessCrashedCallback webProcessCrashed; + WKViewCallback webProcessDidRelaunch; + WKViewPageDidChangeContentsPositionCallback didChangeContentsPosition; + WKViewPageDidRenderFrameCallback didRenderFrame; + WKViewCallback didCompletePageTransition; + WKViewPageDidChangeViewportAttributesCallback didChangeViewportAttributes; + WKViewPageDidChangeTooltipCallback didChangeTooltip; + WKViewDidFindZoomableAreaCallback didFindZoomableArea; + WKViewDoneWithTouchEventCallback doneWithTouchEvent; +} WKViewClientV0; + +WK_EXPORT WKViewRef WKViewCreate(WKContextRef context, WKPageConfigurationRef pageConfiguration); + +WK_EXPORT WKSize WKViewGetSize(WKViewRef); +WK_EXPORT void WKViewSetSize(WKViewRef, WKSize size); + +WK_EXPORT void WKViewSetViewClient(WKViewRef, const WKViewClientBase*); + +WK_EXPORT bool WKViewIsActive(WKViewRef); +WK_EXPORT void WKViewSetIsActive(WKViewRef, bool); + +WK_EXPORT bool WKViewIsFocused(WKViewRef); +WK_EXPORT void WKViewSetIsFocused(WKViewRef, bool); + +WK_EXPORT bool WKViewIsVisible(WKViewRef); +WK_EXPORT void WKViewSetIsVisible(WKViewRef, bool); + +WK_EXPORT float WKViewGetContentScaleFactor(WKViewRef); +WK_EXPORT void WKViewSetContentScaleFactor(WKViewRef, float); + +WK_EXPORT WKPoint WKViewGetContentPosition(WKViewRef); +WK_EXPORT void WKViewSetContentPosition(WKViewRef, WKPoint); + +WK_EXPORT void WKViewSetUserViewportTranslation(WKViewRef, double tx, double ty); +WK_EXPORT WKPoint WKViewUserViewportToContents(WKViewRef, WKPoint); +WK_EXPORT WKPoint WKViewUserViewportToScene(WKViewRef, WKPoint); +WK_EXPORT WKPoint WKViewContentsToUserViewport(WKViewRef, WKPoint); + +WK_EXPORT void WKViewPaintToCurrentGLContext(WKViewRef); + +WK_EXPORT WKPageRef WKViewGetPage(WKViewRef); + +WK_EXPORT void WKViewSetDrawsBackground(WKViewRef, bool); +WK_EXPORT bool WKViewGetDrawsBackground(WKViewRef); + +WK_EXPORT void WKViewSetDrawsTransparentBackground(WKViewRef, bool); +WK_EXPORT bool WKViewGetDrawsTransparentBackground(WKViewRef); + +WK_EXPORT void WKViewSuspendActiveDOMObjectsAndAnimations(WKViewRef); +WK_EXPORT void WKViewResumeActiveDOMObjectsAndAnimations(WKViewRef); + +WK_EXPORT bool WKViewExitFullScreen(WKViewRef); + +WK_EXPORT void WKViewSetOpacity(WKViewRef view, double opacity); +WK_EXPORT double WKViewOpacity(WKViewRef view); + +WK_EXPORT void WKViewFindZoomableAreaForRect(WKViewRef, WKRect); + +WK_EXPORT WKSize WKViewGetContentsSize(WKViewRef); + +#ifdef __cplusplus +} +#endif + +#endif /* WKView_h */ diff --git a/Source/WebKit2/UIProcess/API/C/WKAPICast.h b/Source/WebKit2/UIProcess/API/C/WKAPICast.h index 71569bbb5..ee7f2dfc5 100644 --- a/Source/WebKit2/UIProcess/API/C/WKAPICast.h +++ b/Source/WebKit2/UIProcess/API/C/WKAPICast.h @@ -32,26 +32,39 @@ #include "HTTPCookieAcceptPolicy.h" #include "InjectedBundleHitTestResultMediaType.h" #include "PluginModuleInfo.h" -#include "ProcessModel.h" #include "ResourceCachesToClear.h" #include "WKBundleHitTestResult.h" #include "WKContext.h" #include "WKCookieManager.h" #include "WKCredentialTypes.h" #include "WKPage.h" -#include "WKPreferencesPrivate.h" #include "WKPreferencesRef.h" +#include "WKPreferencesRefPrivate.h" #include "WKProtectionSpaceTypes.h" #include "WKResourceCacheManager.h" #include "WKSharedAPICast.h" #include "WebGrammarDetail.h" #include <WebCore/Credential.h> #include <WebCore/FrameLoaderTypes.h> +#include <WebCore/PluginData.h> #include <WebCore/ProtectionSpace.h> #include <WebCore/Settings.h> namespace API { +class FrameInfo; +class HitTestResult; +class Navigation; +class NavigationAction; class NavigationData; +class NavigationResponse; +class PageConfiguration; +class ProcessPoolConfiguration; +class SessionState; +class UserContentExtension; +class UserContentExtensionStore; +class UserScript; +class WebsiteDataStore; +class WindowFeatures; } namespace WebKit { @@ -61,48 +74,42 @@ class AuthenticationDecisionListener; class DownloadProxy; class GeolocationPermissionRequestProxy; class NotificationPermissionRequest; -class WebApplicationCacheManagerProxy; +class UserMediaPermissionCheckProxy; +class UserMediaPermissionRequestProxy; class WebBackForwardList; class WebBackForwardListItem; class WebBatteryManagerProxy; class WebBatteryStatus; -class WebResourceCacheManagerProxy; class WebColorPickerResultListenerProxy; -class WebContext; class WebCookieManagerProxy; class WebCredential; -class WebDatabaseManagerProxy; class WebFormSubmissionListenerProxy; class WebFramePolicyListenerProxy; class WebFrameProxy; class WebGeolocationManagerProxy; class WebGeolocationPosition; class WebGrammarDetail; -class WebHitTestResult; class WebIconDatabase; class WebInspectorProxy; -class WebKeyValueStorageManager; -class WebMediaCacheManagerProxy; -class WebNetworkInfoManagerProxy; -class WebNetworkInfo; +class WebMediaSessionFocusManager; +class WebMediaSessionMetadata; class WebNotification; -class WebNotificationProvider; class WebNotificationManagerProxy; +class WebNotificationProvider; class WebOpenPanelParameters; class WebOpenPanelResultListenerProxy; -class WebOriginDataManagerProxy; class WebPageGroup; class WebPageProxy; -class WebPluginSiteDataManager; class WebPreferences; +class WebProcessPool; class WebProtectionSpace; class WebRenderLayer; class WebRenderObject; class WebTextChecker; +class WebUserContentControllerProxy; class WebVibrationProxy; class WebViewportAttributes; -WK_ADD_API_MAPPING(WKApplicationCacheManagerRef, WebApplicationCacheManagerProxy) WK_ADD_API_MAPPING(WKAuthenticationChallengeRef, AuthenticationChallengeProxy) WK_ADD_API_MAPPING(WKAuthenticationDecisionListenerRef, AuthenticationDecisionListener) WK_ADD_API_MAPPING(WKBackForwardListItemRef, WebBackForwardListItem) @@ -110,45 +117,54 @@ WK_ADD_API_MAPPING(WKBackForwardListRef, WebBackForwardList) WK_ADD_API_MAPPING(WKBatteryManagerRef, WebBatteryManagerProxy) WK_ADD_API_MAPPING(WKBatteryStatusRef, WebBatteryStatus) WK_ADD_API_MAPPING(WKBundleHitTestResultMediaType, BundleHitTestResultMediaType) -WK_ADD_API_MAPPING(WKResourceCacheManagerRef, WebResourceCacheManagerProxy) WK_ADD_API_MAPPING(WKColorPickerResultListenerRef, WebColorPickerResultListenerProxy) -WK_ADD_API_MAPPING(WKContextRef, WebContext) +WK_ADD_API_MAPPING(WKContextRef, WebProcessPool) +WK_ADD_API_MAPPING(WKContextConfigurationRef, API::ProcessPoolConfiguration) WK_ADD_API_MAPPING(WKCookieManagerRef, WebCookieManagerProxy) WK_ADD_API_MAPPING(WKCredentialRef, WebCredential) -WK_ADD_API_MAPPING(WKDatabaseManagerRef, WebDatabaseManagerProxy) WK_ADD_API_MAPPING(WKDownloadRef, DownloadProxy) WK_ADD_API_MAPPING(WKFormSubmissionListenerRef, WebFormSubmissionListenerProxy) WK_ADD_API_MAPPING(WKFramePolicyListenerRef, WebFramePolicyListenerProxy) +WK_ADD_API_MAPPING(WKFrameInfoRef, API::FrameInfo) WK_ADD_API_MAPPING(WKFrameRef, WebFrameProxy) WK_ADD_API_MAPPING(WKGeolocationManagerRef, WebGeolocationManagerProxy) WK_ADD_API_MAPPING(WKGeolocationPermissionRequestRef, GeolocationPermissionRequestProxy) WK_ADD_API_MAPPING(WKGeolocationPositionRef, WebGeolocationPosition) WK_ADD_API_MAPPING(WKGrammarDetailRef, WebGrammarDetail) -WK_ADD_API_MAPPING(WKHitTestResultRef, WebHitTestResult) +WK_ADD_API_MAPPING(WKHitTestResultRef, API::HitTestResult) WK_ADD_API_MAPPING(WKIconDatabaseRef, WebIconDatabase) -WK_ADD_API_MAPPING(WKKeyValueStorageManagerRef, WebKeyValueStorageManager) -WK_ADD_API_MAPPING(WKMediaCacheManagerRef, WebMediaCacheManagerProxy) +WK_ADD_API_MAPPING(WKInspectorRef, WebInspectorProxy) +WK_ADD_API_MAPPING(WKMediaSessionFocusManagerRef, WebMediaSessionFocusManager) +WK_ADD_API_MAPPING(WKMediaSessionMetadataRef, WebMediaSessionMetadata) +WK_ADD_API_MAPPING(WKNavigationActionRef, API::NavigationAction) WK_ADD_API_MAPPING(WKNavigationDataRef, API::NavigationData) -WK_ADD_API_MAPPING(WKNetworkInfoManagerRef, WebNetworkInfoManagerProxy) -WK_ADD_API_MAPPING(WKNetworkInfoRef, WebNetworkInfo) +WK_ADD_API_MAPPING(WKNavigationRef, API::Navigation) +WK_ADD_API_MAPPING(WKNavigationResponseRef, API::NavigationResponse) WK_ADD_API_MAPPING(WKNotificationManagerRef, WebNotificationManagerProxy) WK_ADD_API_MAPPING(WKNotificationPermissionRequestRef, NotificationPermissionRequest) WK_ADD_API_MAPPING(WKNotificationProviderRef, WebNotificationProvider) WK_ADD_API_MAPPING(WKNotificationRef, WebNotification) WK_ADD_API_MAPPING(WKOpenPanelParametersRef, WebOpenPanelParameters) WK_ADD_API_MAPPING(WKOpenPanelResultListenerRef, WebOpenPanelResultListenerProxy) -WK_ADD_API_MAPPING(WKOriginDataManagerRef, WebOriginDataManagerProxy) WK_ADD_API_MAPPING(WKPageGroupRef, WebPageGroup) +WK_ADD_API_MAPPING(WKPageConfigurationRef, API::PageConfiguration) WK_ADD_API_MAPPING(WKPageRef, WebPageProxy) -WK_ADD_API_MAPPING(WKPluginSiteDataManagerRef, WebPluginSiteDataManager) WK_ADD_API_MAPPING(WKPreferencesRef, WebPreferences) WK_ADD_API_MAPPING(WKProtectionSpaceRef, WebProtectionSpace) WK_ADD_API_MAPPING(WKRenderLayerRef, WebRenderLayer) WK_ADD_API_MAPPING(WKRenderObjectRef, WebRenderObject) +WK_ADD_API_MAPPING(WKSessionStateRef, API::SessionState) WK_ADD_API_MAPPING(WKTextCheckerRef, WebTextChecker) +WK_ADD_API_MAPPING(WKUserContentControllerRef, WebUserContentControllerProxy) +WK_ADD_API_MAPPING(WKUserContentExtensionStoreRef, API::UserContentExtensionStore) +WK_ADD_API_MAPPING(WKUserContentFilterRef, API::UserContentExtension) +WK_ADD_API_MAPPING(WKUserMediaPermissionCheckRef, UserMediaPermissionCheckProxy) +WK_ADD_API_MAPPING(WKUserMediaPermissionRequestRef, UserMediaPermissionRequestProxy) +WK_ADD_API_MAPPING(WKUserScriptRef, API::UserScript) WK_ADD_API_MAPPING(WKVibrationRef, WebVibrationProxy) WK_ADD_API_MAPPING(WKViewportAttributesRef, WebViewportAttributes) -WK_ADD_API_MAPPING(WKInspectorRef, WebInspectorProxy) +WK_ADD_API_MAPPING(WKWebsiteDataStoreRef, API::WebsiteDataStore) +WK_ADD_API_MAPPING(WKWindowFeaturesRef, API::WindowFeatures) /* Enum conversions */ @@ -211,31 +227,6 @@ inline WKCacheModel toAPI(CacheModel cacheModel) return kWKCacheModelDocumentViewer; } -inline ProcessModel toProcessModel(WKProcessModel wkProcessModel) -{ - switch (wkProcessModel) { - case kWKProcessModelSharedSecondaryProcess: - return ProcessModelSharedSecondaryProcess; - case kWKProcessModelMultipleSecondaryProcesses: - return ProcessModelMultipleSecondaryProcesses; - } - - ASSERT_NOT_REACHED(); - return ProcessModelSharedSecondaryProcess; -} - -inline WKProcessModel toAPI(ProcessModel processModel) -{ - switch (processModel) { - case ProcessModelSharedSecondaryProcess: - return kWKProcessModelSharedSecondaryProcess; - case ProcessModelMultipleSecondaryProcesses: - return kWKProcessModelMultipleSecondaryProcesses; - } - - return kWKProcessModelSharedSecondaryProcess; -} - inline FontSmoothingLevel toFontSmoothingLevel(WKFontSmoothingLevel wkLevel) { switch (wkLevel) { @@ -454,40 +445,99 @@ inline WKPluginLoadPolicy toWKPluginLoadPolicy(PluginModuleLoadPolicy pluginModu return kWKPluginLoadPolicyLoadNormally; case PluginModuleLoadUnsandboxed: return kWKPluginLoadPolicyLoadUnsandboxed; - case PluginModuleBlocked: + case PluginModuleBlockedForSecurity: return kWKPluginLoadPolicyBlocked; + case PluginModuleBlockedForCompatibility: + return kWKPluginLoadPolicyBlockedForCompatibility; } ASSERT_NOT_REACHED(); return kWKPluginLoadPolicyBlocked; } +inline WKPluginLoadClientPolicy toWKPluginLoadClientPolicy(WebCore::PluginLoadClientPolicy PluginLoadClientPolicy) +{ + switch (PluginLoadClientPolicy) { + case WebCore::PluginLoadClientPolicyUndefined: + return kWKPluginLoadClientPolicyUndefined; + case WebCore::PluginLoadClientPolicyBlock: + return kWKPluginLoadClientPolicyBlock; + case WebCore::PluginLoadClientPolicyAsk: + return kWKPluginLoadClientPolicyAsk; + case WebCore::PluginLoadClientPolicyAllow: + return kWKPluginLoadClientPolicyAllow; + case WebCore::PluginLoadClientPolicyAllowAlways: + return kWKPluginLoadClientPolicyAllowAlways; + } + + ASSERT_NOT_REACHED(); + return kWKPluginLoadClientPolicyBlock; +} + inline PluginModuleLoadPolicy toPluginModuleLoadPolicy(WKPluginLoadPolicy pluginLoadPolicy) { switch (pluginLoadPolicy) { case kWKPluginLoadPolicyLoadNormally: return PluginModuleLoadNormally; case kWKPluginLoadPolicyBlocked: - return PluginModuleBlocked; + return PluginModuleBlockedForSecurity; + case kWKPluginLoadPolicyBlockedForCompatibility: + return PluginModuleBlockedForCompatibility; case kWKPluginLoadPolicyLoadUnsandboxed: return PluginModuleLoadUnsandboxed; } ASSERT_NOT_REACHED(); - return PluginModuleBlocked; + return PluginModuleBlockedForSecurity; +} + +inline WebCore::PluginLoadClientPolicy toPluginLoadClientPolicy(WKPluginLoadClientPolicy pluginLoadClientPolicy) +{ + switch (pluginLoadClientPolicy) { + case kWKPluginLoadClientPolicyUndefined: + return WebCore::PluginLoadClientPolicyUndefined; + case kWKPluginLoadClientPolicyBlock: + return WebCore::PluginLoadClientPolicyBlock; + case kWKPluginLoadClientPolicyAsk: + return WebCore::PluginLoadClientPolicyAsk; + case kWKPluginLoadClientPolicyAllow: + return WebCore::PluginLoadClientPolicyAllow; + case kWKPluginLoadClientPolicyAllowAlways: + return WebCore::PluginLoadClientPolicyAllowAlways; + } + + ASSERT_NOT_REACHED(); + return WebCore::PluginLoadClientPolicyBlock; } inline WebCore::WebGLLoadPolicy toWebGLLoadPolicy(WKWebGLLoadPolicy webGLLoadPolicy) { switch (webGLLoadPolicy) { case kWKWebGLLoadPolicyLoadNormally: - return WebCore::WebGLAllow; + return WebCore::WebGLAllowCreation; case kWKWebGLLoadPolicyBlocked: - return WebCore::WebGLBlock; + return WebCore::WebGLBlockCreation; + case kWKWebGLLoadPolicyPending: + return WebCore::WebGLPendingCreation; } ASSERT_NOT_REACHED(); - return WebCore::WebGLAllow; + return WebCore::WebGLAllowCreation; +} + +inline WKWebGLLoadPolicy toAPI(WebCore::WebGLLoadPolicy webGLLoadPolicy) +{ + switch (webGLLoadPolicy) { + case WebCore::WebGLAllowCreation: + return kWKWebGLLoadPolicyLoadNormally; + case WebCore::WebGLBlockCreation: + return kWKWebGLLoadPolicyBlocked; + case WebCore::WebGLPendingCreation: + return kWKWebGLLoadPolicyPending; + } + + ASSERT_NOT_REACHED(); + return kWKWebGLLoadPolicyLoadNormally; } inline ProxyingRefPtr<WebGrammarDetail> toAPI(const WebCore::GrammarDetail& grammarDetail) diff --git a/Source/WebKit2/UIProcess/API/C/WKApplicationCacheManager.cpp b/Source/WebKit2/UIProcess/API/C/WKApplicationCacheManager.cpp index 2d95c6721..72b3fa5c8 100644 --- a/Source/WebKit2/UIProcess/API/C/WKApplicationCacheManager.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKApplicationCacheManager.cpp @@ -26,27 +26,43 @@ #include "config.h" #include "WKApplicationCacheManager.h" +#include "APIWebsiteDataStore.h" #include "WKAPICast.h" -#include "WebApplicationCacheManagerProxy.h" +#include "WebsiteDataRecord.h" using namespace WebKit; WKTypeID WKApplicationCacheManagerGetTypeID() { - return toAPI(WebApplicationCacheManagerProxy::APIType); + return toAPI(API::WebsiteDataStore::APIType); } -void WKApplicationCacheManagerGetApplicationCacheOrigins(WKApplicationCacheManagerRef applicationCacheManagerRef, void* context, WKApplicationCacheManagerGetApplicationCacheOriginsFunction callback) +void WKApplicationCacheManagerGetApplicationCacheOrigins(WKApplicationCacheManagerRef applicationCacheManager, void* context, WKApplicationCacheManagerGetApplicationCacheOriginsFunction callback) { - toImpl(applicationCacheManagerRef)->getApplicationCacheOrigins(ArrayCallback::create(context, callback)); + auto& websiteDataStore = toImpl(reinterpret_cast<WKWebsiteDataStoreRef>(applicationCacheManager))->websiteDataStore(); + websiteDataStore.fetchData(WebsiteDataTypes::WebsiteDataTypeOfflineWebApplicationCache, [context, callback](Vector<WebsiteDataRecord> dataRecords) { + Vector<RefPtr<API::Object>> securityOrigins; + for (const auto& dataRecord : dataRecords) { + for (const auto& origin : dataRecord.origins) + securityOrigins.append(API::SecurityOrigin::create(*origin)); + } + + callback(toAPI(API::Array::create(WTFMove(securityOrigins)).ptr()), nullptr, context); + }); } -void WKApplicationCacheManagerDeleteEntriesForOrigin(WKApplicationCacheManagerRef applicationCacheManagerRef, WKSecurityOriginRef originRef) +void WKApplicationCacheManagerDeleteEntriesForOrigin(WKApplicationCacheManagerRef applicationCacheManager, WKSecurityOriginRef origin) { - toImpl(applicationCacheManagerRef)->deleteEntriesForOrigin(toImpl(originRef)); + auto& websiteDataStore = toImpl(reinterpret_cast<WKWebsiteDataStoreRef>(applicationCacheManager))->websiteDataStore(); + + WebsiteDataRecord dataRecord; + dataRecord.add(WebsiteDataTypes::WebsiteDataTypeOfflineWebApplicationCache, &toImpl(origin)->securityOrigin()); + + websiteDataStore.removeData(WebsiteDataTypes::WebsiteDataTypeOfflineWebApplicationCache, { dataRecord }, [] { }); } -void WKApplicationCacheManagerDeleteAllEntries(WKApplicationCacheManagerRef applicationCacheManagerRef) +void WKApplicationCacheManagerDeleteAllEntries(WKApplicationCacheManagerRef applicationCacheManager) { - toImpl(applicationCacheManagerRef)->deleteAllEntries(); + auto& websiteDataStore = toImpl(reinterpret_cast<WKWebsiteDataStoreRef>(applicationCacheManager))->websiteDataStore(); + websiteDataStore.removeData(WebsiteDataTypes::WebsiteDataTypeOfflineWebApplicationCache, std::chrono::system_clock::time_point::min(), [] { }); } diff --git a/Source/WebKit2/UIProcess/API/C/WKApplicationCacheManager.h b/Source/WebKit2/UIProcess/API/C/WKApplicationCacheManager.h index c40039e37..065a462d4 100644 --- a/Source/WebKit2/UIProcess/API/C/WKApplicationCacheManager.h +++ b/Source/WebKit2/UIProcess/API/C/WKApplicationCacheManager.h @@ -26,7 +26,7 @@ #ifndef WKApplicationCacheManager_h #define WKApplicationCacheManager_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/WKAuthenticationChallenge.cpp b/Source/WebKit2/UIProcess/API/C/WKAuthenticationChallenge.cpp index c42b85732..17067cc32 100644 --- a/Source/WebKit2/UIProcess/API/C/WKAuthenticationChallenge.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKAuthenticationChallenge.cpp @@ -27,10 +27,11 @@ #include "WKAuthenticationChallenge.h" #include "AuthenticationChallengeProxy.h" +#include "AuthenticationDecisionListener.h" +#include "WKAPICast.h" #include "WebCertificateInfo.h" #include "WebCredential.h" #include "WebProtectionSpace.h" -#include "WKAPICast.h" using namespace WebKit; diff --git a/Source/WebKit2/UIProcess/API/C/WKAuthenticationChallenge.h b/Source/WebKit2/UIProcess/API/C/WKAuthenticationChallenge.h index 3802f417f..bc2cf2e7e 100644 --- a/Source/WebKit2/UIProcess/API/C/WKAuthenticationChallenge.h +++ b/Source/WebKit2/UIProcess/API/C/WKAuthenticationChallenge.h @@ -26,7 +26,7 @@ #ifndef WKAuthenticationChallenge_h #define WKAuthenticationChallenge_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/WKAuthenticationDecisionListener.cpp b/Source/WebKit2/UIProcess/API/C/WKAuthenticationDecisionListener.cpp index bcb175dfd..06ca308b5 100644 --- a/Source/WebKit2/UIProcess/API/C/WKAuthenticationDecisionListener.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKAuthenticationDecisionListener.cpp @@ -28,6 +28,7 @@ #include "AuthenticationDecisionListener.h" #include "WKAPICast.h" +#include "WebCredential.h" using namespace WebKit; diff --git a/Source/WebKit2/UIProcess/API/C/WKAuthenticationDecisionListener.h b/Source/WebKit2/UIProcess/API/C/WKAuthenticationDecisionListener.h index f0724610b..2134de091 100644 --- a/Source/WebKit2/UIProcess/API/C/WKAuthenticationDecisionListener.h +++ b/Source/WebKit2/UIProcess/API/C/WKAuthenticationDecisionListener.h @@ -26,7 +26,7 @@ #ifndef WKAuthenticationDecisionListener_h #define WKAuthenticationDecisionListener_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/WKBackForwardListItemRef.h b/Source/WebKit2/UIProcess/API/C/WKBackForwardListItemRef.h index 7008e9a90..f63ba5f45 100644 --- a/Source/WebKit2/UIProcess/API/C/WKBackForwardListItemRef.h +++ b/Source/WebKit2/UIProcess/API/C/WKBackForwardListItemRef.h @@ -26,7 +26,7 @@ #ifndef WKBackForwardListItemRef_h #define WKBackForwardListItemRef_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/WKBackForwardListRef.cpp b/Source/WebKit2/UIProcess/API/C/WKBackForwardListRef.cpp index b3a1d0882..4be7fc369 100644 --- a/Source/WebKit2/UIProcess/API/C/WKBackForwardListRef.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKBackForwardListRef.cpp @@ -74,10 +74,10 @@ unsigned WKBackForwardListGetForwardListCount(WKBackForwardListRef listRef) WKArrayRef WKBackForwardListCopyBackListWithLimit(WKBackForwardListRef listRef, unsigned limit) { - return toAPI(toImpl(listRef)->backListAsAPIArrayWithLimit(limit).leakRef()); + return toAPI(&toImpl(listRef)->backListAsAPIArrayWithLimit(limit).leakRef()); } WKArrayRef WKBackForwardListCopyForwardListWithLimit(WKBackForwardListRef listRef, unsigned limit) { - return toAPI(toImpl(listRef)->forwardListAsAPIArrayWithLimit(limit).leakRef()); + return toAPI(&toImpl(listRef)->forwardListAsAPIArrayWithLimit(limit).leakRef()); } diff --git a/Source/WebKit2/UIProcess/API/C/WKBackForwardListRef.h b/Source/WebKit2/UIProcess/API/C/WKBackForwardListRef.h index 1c7643986..97b2209d2 100644 --- a/Source/WebKit2/UIProcess/API/C/WKBackForwardListRef.h +++ b/Source/WebKit2/UIProcess/API/C/WKBackForwardListRef.h @@ -26,7 +26,7 @@ #ifndef WKBackForwardListRef_h #define WKBackForwardListRef_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/WKBatteryManager.cpp b/Source/WebKit2/UIProcess/API/C/WKBatteryManager.cpp index a9acfa0a4..7a87d5d85 100644 --- a/Source/WebKit2/UIProcess/API/C/WKBatteryManager.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKBatteryManager.cpp @@ -31,6 +31,7 @@ #if ENABLE(BATTERY_STATUS) #include "WebBatteryManagerProxy.h" +#include "WebBatteryStatus.h" #endif using namespace WebKit; diff --git a/Source/WebKit2/UIProcess/API/C/WKBatteryManager.h b/Source/WebKit2/UIProcess/API/C/WKBatteryManager.h index 75b3eafec..5c2ce7585 100644 --- a/Source/WebKit2/UIProcess/API/C/WKBatteryManager.h +++ b/Source/WebKit2/UIProcess/API/C/WKBatteryManager.h @@ -26,7 +26,7 @@ #ifndef WKBatteryManager_h #define WKBatteryManager_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/WKBatteryStatus.h b/Source/WebKit2/UIProcess/API/C/WKBatteryStatus.h index afa1dd931..b32b99fd7 100644 --- a/Source/WebKit2/UIProcess/API/C/WKBatteryStatus.h +++ b/Source/WebKit2/UIProcess/API/C/WKBatteryStatus.h @@ -26,7 +26,7 @@ #ifndef WKBatteryStatus_h #define WKBatteryStatus_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/WKContext.cpp b/Source/WebKit2/UIProcess/API/C/WKContext.cpp index f5a9cb635..98555a2d6 100644 --- a/Source/WebKit2/UIProcess/API/C/WKContext.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKContext.cpp @@ -24,52 +24,68 @@ */ #include "config.h" -#include "WKContext.h" #include "WKContextPrivate.h" +#include "APIClient.h" +#include "APIDownloadClient.h" +#include "APILegacyContextHistoryClient.h" +#include "APINavigationData.h" +#include "APIProcessPoolConfiguration.h" #include "APIURLRequest.h" +#include "AuthenticationChallengeProxy.h" +#include "DownloadProxy.h" #include "WKAPICast.h" -#include "WebContext.h" +#include "WKContextConfigurationRef.h" +#include "WKRetainPtr.h" +#include "WebCertificateInfo.h" +#include "WebIconDatabase.h" +#include "WebProcessPool.h" #include <wtf/PassRefPtr.h> #include <wtf/RefPtr.h> #include <wtf/text/WTFString.h> // Supplements -#include "WebApplicationCacheManagerProxy.h" #include "WebCookieManagerProxy.h" #include "WebGeolocationManagerProxy.h" -#include "WebKeyValueStorageManager.h" -#include "WebMediaCacheManagerProxy.h" #include "WebNotificationManagerProxy.h" -#include "WebOriginDataManagerProxy.h" -#include "WebResourceCacheManagerProxy.h" -#if ENABLE(SQL_DATABASE) -#include "WebDatabaseManagerProxy.h" -#endif #if ENABLE(BATTERY_STATUS) #include "WebBatteryManagerProxy.h" #endif -#if ENABLE(NETWORK_INFO) -#include "WebNetworkInfoManagerProxy.h" -#endif +namespace API { +template<> struct ClientTraits<WKContextDownloadClientBase> { + typedef std::tuple<WKContextDownloadClientV0> Versions; +}; +template<> struct ClientTraits<WKContextHistoryClientBase> { + typedef std::tuple<WKContextHistoryClientV0> Versions; +}; +} + +using namespace WebCore; using namespace WebKit; WKTypeID WKContextGetTypeID() { - return toAPI(WebContext::APIType); + return toAPI(WebProcessPool::APIType); } WKContextRef WKContextCreate() { - RefPtr<WebContext> context = WebContext::create(String()); - return toAPI(context.release().leakRef()); + auto configuration = API::ProcessPoolConfiguration::createWithLegacyOptions(); + return toAPI(&WebProcessPool::create(configuration).leakRef()); } WKContextRef WKContextCreateWithInjectedBundlePath(WKStringRef pathRef) { - RefPtr<WebContext> context = WebContext::create(toImpl(pathRef)->string()); - return toAPI(context.release().leakRef()); + auto configuration = API::ProcessPoolConfiguration::createWithLegacyOptions(); + configuration->setInjectedBundlePath(toWTFString(pathRef)); + + return toAPI(&WebProcessPool::create(configuration).leakRef()); +} + +WKContextRef WKContextCreateWithConfiguration(WKContextConfigurationRef configuration) +{ + return toAPI(&WebProcessPool::create(*toImpl(configuration)).leakRef()); } void WKContextSetClient(WKContextRef contextRef, const WKContextClientBase* wkClient) @@ -84,12 +100,173 @@ void WKContextSetInjectedBundleClient(WKContextRef contextRef, const WKContextIn void WKContextSetHistoryClient(WKContextRef contextRef, const WKContextHistoryClientBase* wkClient) { - toImpl(contextRef)->initializeHistoryClient(wkClient); + class HistoryClient final : public API::Client<WKContextHistoryClientBase>, public API::LegacyContextHistoryClient { + public: + explicit HistoryClient(const WKContextHistoryClientBase* client) + { + initialize(client); + } + + private: + virtual void didNavigateWithNavigationData(WebProcessPool& processPool, WebPageProxy& page, const WebNavigationDataStore& navigationDataStore, WebFrameProxy& frame) override + { + if (!m_client.didNavigateWithNavigationData) + return; + + RefPtr<API::NavigationData> navigationData = API::NavigationData::create(navigationDataStore); + m_client.didNavigateWithNavigationData(toAPI(&processPool), toAPI(&page), toAPI(navigationData.get()), toAPI(&frame), m_client.base.clientInfo); + } + + virtual void didPerformClientRedirect(WebProcessPool& processPool, WebPageProxy& page, const String& sourceURL, const String& destinationURL, WebFrameProxy& frame) override + { + if (!m_client.didPerformClientRedirect) + return; + + m_client.didPerformClientRedirect(toAPI(&processPool), toAPI(&page), toURLRef(sourceURL.impl()), toURLRef(destinationURL.impl()), toAPI(&frame), m_client.base.clientInfo); + } + + virtual void didPerformServerRedirect(WebProcessPool& processPool, WebPageProxy& page, const String& sourceURL, const String& destinationURL, WebFrameProxy& frame) override + { + if (!m_client.didPerformServerRedirect) + return; + + m_client.didPerformServerRedirect(toAPI(&processPool), toAPI(&page), toURLRef(sourceURL.impl()), toURLRef(destinationURL.impl()), toAPI(&frame), m_client.base.clientInfo); + } + + virtual void didUpdateHistoryTitle(WebProcessPool& processPool, WebPageProxy& page, const String& title, const String& url, WebFrameProxy& frame) override + { + if (!m_client.didUpdateHistoryTitle) + return; + + m_client.didUpdateHistoryTitle(toAPI(&processPool), toAPI(&page), toAPI(title.impl()), toURLRef(url.impl()), toAPI(&frame), m_client.base.clientInfo); + } + + virtual void populateVisitedLinks(WebProcessPool& processPool) override + { + if (!m_client.populateVisitedLinks) + return; + + m_client.populateVisitedLinks(toAPI(&processPool), m_client.base.clientInfo); + } + + virtual bool addsVisitedLinks() const override + { + return m_client.populateVisitedLinks; + } + }; + + WebProcessPool& processPool = *toImpl(contextRef); + processPool.setHistoryClient(std::make_unique<HistoryClient>(wkClient)); + + bool addsVisitedLinks = processPool.historyClient().addsVisitedLinks(); + + for (auto& process : processPool.processes()) { + for (auto& page : process->pages()) + page->setAddsVisitedLinks(addsVisitedLinks); + } } void WKContextSetDownloadClient(WKContextRef contextRef, const WKContextDownloadClientBase* wkClient) { - toImpl(contextRef)->initializeDownloadClient(wkClient); + class DownloadClient final : public API::Client<WKContextDownloadClientBase>, public API::DownloadClient { + public: + explicit DownloadClient(const WKContextDownloadClientBase* client) + { + initialize(client); + } + private: + virtual void didStart(WebProcessPool* processPool, DownloadProxy* downloadProxy) override + { + if (!m_client.didStart) + return; + + m_client.didStart(toAPI(processPool), toAPI(downloadProxy), m_client.base.clientInfo); + } + + virtual void didReceiveAuthenticationChallenge(WebProcessPool* processPool, DownloadProxy* downloadProxy, AuthenticationChallengeProxy* authenticationChallengeProxy) override + { + if (!m_client.didReceiveAuthenticationChallenge) + return; + + m_client.didReceiveAuthenticationChallenge(toAPI(processPool), toAPI(downloadProxy), toAPI(authenticationChallengeProxy), m_client.base.clientInfo); + } + + virtual void didReceiveResponse(WebProcessPool* processPool, DownloadProxy* downloadProxy, const ResourceResponse& response) override + { + if (!m_client.didReceiveResponse) + return; + + m_client.didReceiveResponse(toAPI(processPool), toAPI(downloadProxy), toAPI(API::URLResponse::create(response).ptr()), m_client.base.clientInfo); + } + + virtual void didReceiveData(WebProcessPool* processPool, DownloadProxy* downloadProxy, uint64_t length) override + { + if (!m_client.didReceiveData) + return; + + m_client.didReceiveData(toAPI(processPool), toAPI(downloadProxy), length, m_client.base.clientInfo); + } + + virtual bool shouldDecodeSourceDataOfMIMEType(WebProcessPool* processPool, DownloadProxy* downloadProxy, const String& mimeType) override + { + if (!m_client.shouldDecodeSourceDataOfMIMEType) + return true; + + return m_client.shouldDecodeSourceDataOfMIMEType(toAPI(processPool), toAPI(downloadProxy), toAPI(mimeType.impl()), m_client.base.clientInfo); + } + + virtual String decideDestinationWithSuggestedFilename(WebProcessPool* processPool, DownloadProxy* downloadProxy, const String& filename, bool& allowOverwrite) override + { + if (!m_client.decideDestinationWithSuggestedFilename) + return String(); + + WKRetainPtr<WKStringRef> destination(AdoptWK, m_client.decideDestinationWithSuggestedFilename(toAPI(processPool), toAPI(downloadProxy), toAPI(filename.impl()), &allowOverwrite, m_client.base.clientInfo)); + return toWTFString(destination.get()); + } + + virtual void didCreateDestination(WebProcessPool* processPool, DownloadProxy* downloadProxy, const String& path) override + { + if (!m_client.didCreateDestination) + return; + + m_client.didCreateDestination(toAPI(processPool), toAPI(downloadProxy), toAPI(path.impl()), m_client.base.clientInfo); + } + + virtual void didFinish(WebProcessPool* processPool, DownloadProxy* downloadProxy) override + { + if (!m_client.didFinish) + return; + + m_client.didFinish(toAPI(processPool), toAPI(downloadProxy), m_client.base.clientInfo); + } + + virtual void didFail(WebProcessPool* processPool, DownloadProxy* downloadProxy, const ResourceError& error) override + { + if (!m_client.didFail) + return; + + m_client.didFail(toAPI(processPool), toAPI(downloadProxy), toAPI(error), m_client.base.clientInfo); + } + + virtual void didCancel(WebProcessPool* processPool, DownloadProxy* downloadProxy) override + { + if (!m_client.didCancel) + return; + + m_client.didCancel(toAPI(processPool), toAPI(downloadProxy), m_client.base.clientInfo); + } + + virtual void processDidCrash(WebProcessPool* processPool, DownloadProxy* downloadProxy) override + { + if (!m_client.processDidCrash) + return; + + m_client.processDidCrash(toAPI(processPool), toAPI(downloadProxy), m_client.base.clientInfo); + } + + }; + + toImpl(contextRef)->setDownloadClient(std::make_unique<DownloadClient>(wkClient)); } void WKContextSetConnectionClient(WKContextRef contextRef, const WKContextConnectionClientBase* wkClient) @@ -97,11 +274,16 @@ void WKContextSetConnectionClient(WKContextRef contextRef, const WKContextConnec toImpl(contextRef)->initializeConnectionClient(wkClient); } -WKDownloadRef WKContextDownloadURLRequest(WKContextRef contextRef, const WKURLRequestRef requestRef) +WKDownloadRef WKContextDownloadURLRequest(WKContextRef contextRef, WKURLRequestRef requestRef) { return toAPI(toImpl(contextRef)->download(0, toImpl(requestRef)->resourceRequest())); } +WKDownloadRef WKContextResumeDownload(WKContextRef contextRef, WKDataRef resumeData, WKStringRef path) +{ + return toAPI(toImpl(contextRef)->resumeDownload(toImpl(resumeData), toWTFString(path))); +} + void WKContextSetInitializationUserDataForInjectedBundle(WKContextRef contextRef, WKTypeRef userDataRef) { toImpl(contextRef)->setInjectedBundleInitializationUserData(toImpl(userDataRef)); @@ -114,7 +296,7 @@ void WKContextPostMessageToInjectedBundle(WKContextRef contextRef, WKStringRef m void WKContextGetGlobalStatistics(WKContextStatistics* statistics) { - const WebContext::Statistics& webContextStatistics = WebContext::statistics(); + const WebProcessPool::Statistics& webContextStatistics = WebProcessPool::statistics(); statistics->wkViewCount = webContextStatistics.wkViewCount; statistics->wkPageCount = webContextStatistics.wkPageCount; @@ -123,27 +305,26 @@ void WKContextGetGlobalStatistics(WKContextStatistics* statistics) void WKContextAddVisitedLink(WKContextRef contextRef, WKStringRef visitedURL) { - toImpl(contextRef)->addVisitedLink(toImpl(visitedURL)->string()); -} + String visitedURLString = toImpl(visitedURL)->string(); + if (visitedURLString.isEmpty()) + return; -void WKContextSetCacheModel(WKContextRef contextRef, WKCacheModel cacheModel) -{ - toImpl(contextRef)->setCacheModel(toCacheModel(cacheModel)); + toImpl(contextRef)->visitedLinkStore().addVisitedLinkHash(visitedLinkHash(visitedURLString)); } -WKCacheModel WKContextGetCacheModel(WKContextRef contextRef) +void WKContextClearVisitedLinks(WKContextRef contextRef) { - return toAPI(toImpl(contextRef)->cacheModel()); + toImpl(contextRef)->visitedLinkStore().removeAll(); } -void WKContextSetProcessModel(WKContextRef contextRef, WKProcessModel processModel) +void WKContextSetCacheModel(WKContextRef contextRef, WKCacheModel cacheModel) { - toImpl(contextRef)->setProcessModel(toProcessModel(processModel)); + toImpl(contextRef)->setCacheModel(toCacheModel(cacheModel)); } -WKProcessModel WKContextGetProcessModel(WKContextRef contextRef) +WKCacheModel WKContextGetCacheModel(WKContextRef contextRef) { - return toAPI(toImpl(contextRef)->processModel()); + return toAPI(toImpl(contextRef)->cacheModel()); } void WKContextSetMaximumNumberOfProcesses(WKContextRef contextRef, unsigned numberOfProcesses) @@ -186,35 +367,50 @@ void WKContextRegisterURLSchemeAsSecure(WKContextRef contextRef, WKStringRef url toImpl(contextRef)->registerURLSchemeAsSecure(toImpl(urlScheme)->string()); } +void WKContextRegisterURLSchemeAsBypassingContentSecurityPolicy(WKContextRef contextRef, WKStringRef urlScheme) +{ + toImpl(contextRef)->registerURLSchemeAsBypassingContentSecurityPolicy(toImpl(urlScheme)->string()); +} + +void WKContextRegisterURLSchemeAsCachePartitioned(WKContextRef contextRef, WKStringRef urlScheme) +{ +#if ENABLE(CACHE_PARTITIONING) + toImpl(contextRef)->registerURLSchemeAsCachePartitioned(toImpl(urlScheme)->string()); +#else + UNUSED_PARAM(contextRef); + UNUSED_PARAM(urlScheme); +#endif +} + void WKContextSetDomainRelaxationForbiddenForURLScheme(WKContextRef contextRef, WKStringRef urlScheme) { toImpl(contextRef)->setDomainRelaxationForbiddenForURLScheme(toImpl(urlScheme)->string()); } +void WKContextSetCanHandleHTTPSServerTrustEvaluation(WKContextRef contextRef, bool value) +{ + toImpl(contextRef)->setCanHandleHTTPSServerTrustEvaluation(value); +} + WKCookieManagerRef WKContextGetCookieManager(WKContextRef contextRef) { return toAPI(toImpl(contextRef)->supplement<WebCookieManagerProxy>()); } -WKApplicationCacheManagerRef WKContextGetApplicationCacheManager(WKContextRef contextRef) +WKWebsiteDataStoreRef WKContextGetWebsiteDataStore(WKContextRef context) { - return toAPI(toImpl(contextRef)->supplement<WebApplicationCacheManagerProxy>()); + return toAPI(toImpl(context)->websiteDataStore()); } -WKBatteryManagerRef WKContextGetBatteryManager(WKContextRef contextRef) +WKApplicationCacheManagerRef WKContextGetApplicationCacheManager(WKContextRef context) { -#if ENABLE(BATTERY_STATUS) - return toAPI(toImpl(contextRef)->supplement<WebBatteryManagerProxy>()); -#else - UNUSED_PARAM(contextRef); - return 0; -#endif + return reinterpret_cast<WKApplicationCacheManagerRef>(WKContextGetWebsiteDataStore(context)); } -WKDatabaseManagerRef WKContextGetDatabaseManager(WKContextRef contextRef) +WKBatteryManagerRef WKContextGetBatteryManager(WKContextRef contextRef) { -#if ENABLE(SQL_DATABASE) - return toAPI(toImpl(contextRef)->supplement<WebDatabaseManagerProxy>()); +#if ENABLE(BATTERY_STATUS) + return toAPI(toImpl(contextRef)->supplement<WebBatteryManagerProxy>()); #else UNUSED_PARAM(contextRef); return 0; @@ -226,29 +422,24 @@ WKGeolocationManagerRef WKContextGetGeolocationManager(WKContextRef contextRef) return toAPI(toImpl(contextRef)->supplement<WebGeolocationManagerProxy>()); } -WKNetworkInfoManagerRef WKContextGetNetworkInfoManager(WKContextRef contextRef) -{ -#if ENABLE(NETWORK_INFO) - return toAPI(toImpl(contextRef)->supplement<WebNetworkInfoManagerProxy>()); -#else - UNUSED_PARAM(contextRef); - return 0; -#endif -} - WKIconDatabaseRef WKContextGetIconDatabase(WKContextRef contextRef) { return toAPI(toImpl(contextRef)->iconDatabase()); } -WKKeyValueStorageManagerRef WKContextGetKeyValueStorageManager(WKContextRef contextRef) +WKKeyValueStorageManagerRef WKContextGetKeyValueStorageManager(WKContextRef context) { - return toAPI(toImpl(contextRef)->supplement<WebKeyValueStorageManager>()); + return reinterpret_cast<WKKeyValueStorageManagerRef>(WKContextGetWebsiteDataStore(context)); } -WKMediaCacheManagerRef WKContextGetMediaCacheManager(WKContextRef contextRef) +WKMediaSessionFocusManagerRef WKContextGetMediaSessionFocusManager(WKContextRef context) { - return toAPI(toImpl(contextRef)->supplement<WebMediaCacheManagerProxy>()); +#if ENABLE(MEDIA_SESSION) + return toAPI(toImpl(context)->supplement<WebMediaSessionFocusManager>()); +#else + UNUSED_PARAM(context); + return nullptr; +#endif } WKNotificationManagerRef WKContextGetNotificationManager(WKContextRef contextRef) @@ -256,24 +447,19 @@ WKNotificationManagerRef WKContextGetNotificationManager(WKContextRef contextRef return toAPI(toImpl(contextRef)->supplement<WebNotificationManagerProxy>()); } -WKPluginSiteDataManagerRef WKContextGetPluginSiteDataManager(WKContextRef contextRef) +WKPluginSiteDataManagerRef WKContextGetPluginSiteDataManager(WKContextRef context) { #if ENABLE(NETSCAPE_PLUGIN_API) - return toAPI(toImpl(contextRef)->pluginSiteDataManager()); + return reinterpret_cast<WKPluginSiteDataManagerRef>(WKContextGetWebsiteDataStore(context)); #else - UNUSED_PARAM(contextRef); - return 0; + UNUSED_PARAM(context); + return nullptr; #endif } -WKResourceCacheManagerRef WKContextGetResourceCacheManager(WKContextRef contextRef) +WKResourceCacheManagerRef WKContextGetResourceCacheManager(WKContextRef context) { - return toAPI(toImpl(contextRef)->supplement<WebResourceCacheManagerProxy>()); -} - -WKOriginDataManagerRef WKContextGetOriginDataManager(WKContextRef contextRef) -{ - return toAPI(toImpl(contextRef)->supplement<WebOriginDataManagerProxy>()); + return reinterpret_cast<WKResourceCacheManagerRef>(WKContextGetWebsiteDataStore(context)); } void WKContextStartMemorySampler(WKContextRef contextRef, WKDoubleRef interval) @@ -296,26 +482,6 @@ void WKContextAllowSpecificHTTPSCertificateForHost(WKContextRef contextRef, WKCe toImpl(contextRef)->allowSpecificHTTPSCertificateForHost(toImpl(certificateRef), toImpl(hostRef)->string()); } -WK_EXPORT void WKContextSetApplicationCacheDirectory(WKContextRef contextRef, WKStringRef applicationCacheDirectory) -{ - toImpl(contextRef)->setApplicationCacheDirectory(toImpl(applicationCacheDirectory)->string()); -} - -void WKContextSetDatabaseDirectory(WKContextRef contextRef, WKStringRef databaseDirectory) -{ - toImpl(contextRef)->setDatabaseDirectory(toImpl(databaseDirectory)->string()); -} - -void WKContextSetLocalStorageDirectory(WKContextRef contextRef, WKStringRef localStorageDirectory) -{ - toImpl(contextRef)->setLocalStorageDirectory(toImpl(localStorageDirectory)->string()); -} - -WK_EXPORT void WKContextSetDiskCacheDirectory(WKContextRef contextRef, WKStringRef diskCacheDirectory) -{ - toImpl(contextRef)->setDiskCacheDirectory(toImpl(diskCacheDirectory)->string()); -} - WK_EXPORT void WKContextSetCookieStorageDirectory(WKContextRef contextRef, WKStringRef cookieStorageDirectory) { toImpl(contextRef)->setCookieStorageDirectory(toImpl(cookieStorageDirectory)->string()); @@ -343,12 +509,12 @@ void WKContextWarmInitialProcess(WKContextRef contextRef) void WKContextGetStatistics(WKContextRef contextRef, void* context, WKContextGetStatisticsFunction callback) { - toImpl(contextRef)->getStatistics(0xFFFFFFFF, DictionaryCallback::create(context, callback)); + toImpl(contextRef)->getStatistics(0xFFFFFFFF, toGenericCallbackFunction(context, callback)); } void WKContextGetStatisticsWithOptions(WKContextRef contextRef, WKStatisticsOptions optionsMask, void* context, WKContextGetStatisticsFunction callback) { - toImpl(contextRef)->getStatistics(optionsMask, DictionaryCallback::create(context, callback)); + toImpl(contextRef)->getStatistics(optionsMask, toGenericCallbackFunction(context, callback)); } void WKContextGarbageCollectJavaScriptObjects(WKContextRef contextRef) @@ -361,14 +527,14 @@ void WKContextSetJavaScriptGarbageCollectorTimerEnabled(WKContextRef contextRef, toImpl(contextRef)->setJavaScriptGarbageCollectorTimerEnabled(enable); } -void WKContextSetUsesNetworkProcess(WKContextRef contextRef, bool usesNetworkProcess) +void WKContextUseTestingNetworkSession(WKContextRef context) { - toImpl(contextRef)->setUsesNetworkProcess(usesNetworkProcess); + toImpl(context)->useTestingNetworkSession(); } -void WKContextUseTestingNetworkSession(WKContextRef context) +void WKContextClearCachedCredentials(WKContextRef context) { - toImpl(context)->useTestingNetworkSession(); + toImpl(context)->clearCachedCredentials(); } WKDictionaryRef WKContextCopyPlugInAutoStartOriginHashes(WKContextRef contextRef) @@ -399,10 +565,15 @@ void WKContextSetPlugInAutoStartOrigins(WKContextRef contextRef, WKArrayRef arra void WKContextSetInvalidMessageFunction(WKContextInvalidMessageFunction invalidMessageFunction) { - WebContext::setInvalidMessageCallback(invalidMessageFunction); + WebProcessPool::setInvalidMessageCallback(invalidMessageFunction); } void WKContextSetMemoryCacheDisabled(WKContextRef contextRef, bool disabled) { toImpl(contextRef)->setMemoryCacheDisabled(disabled); } + +void WKContextSetFontWhitelist(WKContextRef contextRef, WKArrayRef arrayRef) +{ + toImpl(contextRef)->setFontWhitelist(toImpl(arrayRef)); +} diff --git a/Source/WebKit2/UIProcess/API/C/WKContext.h b/Source/WebKit2/UIProcess/API/C/WKContext.h index 82237a5b4..279096991 100644 --- a/Source/WebKit2/UIProcess/API/C/WKContext.h +++ b/Source/WebKit2/UIProcess/API/C/WKContext.h @@ -26,11 +26,11 @@ #ifndef WKContext_h #define WKContext_h -#include <WebKit2/WKBase.h> -#include <WebKit2/WKContextConnectionClient.h> -#include <WebKit2/WKContextDownloadClient.h> -#include <WebKit2/WKContextHistoryClient.h> -#include <WebKit2/WKContextInjectedBundleClient.h> +#include <WebKit/WKBase.h> +#include <WebKit/WKContextConnectionClient.h> +#include <WebKit/WKContextDownloadClient.h> +#include <WebKit/WKContextHistoryClient.h> +#include <WebKit/WKContextInjectedBundleClient.h> #ifdef __cplusplus extern "C" { @@ -47,6 +47,7 @@ typedef uint32_t WKCacheModel; typedef void (*WKContextPlugInAutoStartOriginHashesChangedCallback)(WKContextRef context, const void *clientInfo); typedef void (*WKContextNetworkProcessDidCrashCallback)(WKContextRef context, const void *clientInfo); typedef void (*WKContextPlugInInformationBecameAvailableCallback)(WKContextRef context, WKArrayRef plugIn, const void *clientInfo); +typedef WKDataRef (*WKContextCopyWebCryptoMasterKeyCallback)(WKContextRef context, const void *clientInfo); typedef struct WKContextClientBase { int version; @@ -62,17 +63,19 @@ typedef struct WKContextClientV0 { WKContextPlugInInformationBecameAvailableCallback plugInInformationBecameAvailable; } WKContextClientV0; -enum { kWKContextClientCurrentVersion WK_ENUM_DEPRECATED("Use an explicit version number instead") = 0 }; -typedef struct WKContextClient { - int version; - const void * clientInfo; +typedef struct WKContextClientV1 { + WKContextClientBase base; // Version 0. WKContextPlugInAutoStartOriginHashesChangedCallback plugInAutoStartOriginHashesChanged; WKContextNetworkProcessDidCrashCallback networkProcessDidCrash; WKContextPlugInInformationBecameAvailableCallback plugInInformationBecameAvailable; -} WKContextClient WK_DEPRECATED("Use an explicit versioned struct instead"); + // Version 1. + WKContextCopyWebCryptoMasterKeyCallback copyWebCryptoMasterKey; +} WKContextClientV1; + +// FIXME: Remove these once support for Mavericks has been dropped. enum { kWKProcessModelSharedSecondaryProcess = 0, kWKProcessModelMultipleSecondaryProcesses = 1 @@ -89,6 +92,7 @@ WK_EXPORT WKTypeID WKContextGetTypeID(); WK_EXPORT WKContextRef WKContextCreate(); WK_EXPORT WKContextRef WKContextCreateWithInjectedBundlePath(WKStringRef path); +WK_EXPORT WKContextRef WKContextCreateWithConfiguration(WKContextConfigurationRef configuration); WK_EXPORT void WKContextSetClient(WKContextRef context, const WKContextClientBase* client); WK_EXPORT void WKContextSetInjectedBundleClient(WKContextRef context, const WKContextInjectedBundleClientBase* client); @@ -96,18 +100,21 @@ WK_EXPORT void WKContextSetHistoryClient(WKContextRef context, const WKContextHi WK_EXPORT void WKContextSetDownloadClient(WKContextRef context, const WKContextDownloadClientBase* client); WK_EXPORT void WKContextSetConnectionClient(WKContextRef context, const WKContextConnectionClientBase* client); -WK_EXPORT WKDownloadRef WKContextDownloadURLRequest(WKContextRef context, const WKURLRequestRef request); +WK_EXPORT WKDownloadRef WKContextDownloadURLRequest(WKContextRef context, WKURLRequestRef request); +WK_EXPORT WKDownloadRef WKContextResumeDownload(WKContextRef context, WKDataRef resumeData, WKStringRef path); WK_EXPORT void WKContextSetInitializationUserDataForInjectedBundle(WKContextRef context, WKTypeRef userData); WK_EXPORT void WKContextPostMessageToInjectedBundle(WKContextRef context, WKStringRef messageName, WKTypeRef messageBody); WK_EXPORT void WKContextAddVisitedLink(WKContextRef context, WKStringRef visitedURL); +WK_EXPORT void WKContextClearVisitedLinks(WKContextRef contextRef); WK_EXPORT void WKContextSetCacheModel(WKContextRef context, WKCacheModel cacheModel); WK_EXPORT WKCacheModel WKContextGetCacheModel(WKContextRef context); -WK_EXPORT void WKContextSetProcessModel(WKContextRef context, WKProcessModel processModel); -WK_EXPORT WKProcessModel WKContextGetProcessModel(WKContextRef context); +// FIXME: Move these to WKDeprecatedFunctions.cpp once support for Mavericks has been dropped. +WK_EXPORT void WKContextSetProcessModel(WKContextRef, WKProcessModel); +WK_EXPORT WKProcessModel WKContextGetProcessModel(WKContextRef); WK_EXPORT void WKContextSetMaximumNumberOfProcesses(WKContextRef context, unsigned numberOfProcesses); WK_EXPORT unsigned WKContextGetMaximumNumberOfProcesses(WKContextRef context); @@ -115,19 +122,18 @@ WK_EXPORT unsigned WKContextGetMaximumNumberOfProcesses(WKContextRef context); WK_EXPORT void WKContextStartMemorySampler(WKContextRef context, WKDoubleRef interval); WK_EXPORT void WKContextStopMemorySampler(WKContextRef context); +WK_EXPORT WKWebsiteDataStoreRef WKContextGetWebsiteDataStore(WKContextRef context); + WK_EXPORT WKApplicationCacheManagerRef WKContextGetApplicationCacheManager(WKContextRef context); WK_EXPORT WKBatteryManagerRef WKContextGetBatteryManager(WKContextRef context); WK_EXPORT WKCookieManagerRef WKContextGetCookieManager(WKContextRef context); -WK_EXPORT WKDatabaseManagerRef WKContextGetDatabaseManager(WKContextRef context); WK_EXPORT WKGeolocationManagerRef WKContextGetGeolocationManager(WKContextRef context); WK_EXPORT WKIconDatabaseRef WKContextGetIconDatabase(WKContextRef context); WK_EXPORT WKKeyValueStorageManagerRef WKContextGetKeyValueStorageManager(WKContextRef context); -WK_EXPORT WKMediaCacheManagerRef WKContextGetMediaCacheManager(WKContextRef context); -WK_EXPORT WKNetworkInfoManagerRef WKContextGetNetworkInfoManager(WKContextRef context); +WK_EXPORT WKMediaSessionFocusManagerRef WKContextGetMediaSessionFocusManager(WKContextRef context); WK_EXPORT WKNotificationManagerRef WKContextGetNotificationManager(WKContextRef context); WK_EXPORT WKPluginSiteDataManagerRef WKContextGetPluginSiteDataManager(WKContextRef context); WK_EXPORT WKResourceCacheManagerRef WKContextGetResourceCacheManager(WKContextRef context); -WK_EXPORT WKOriginDataManagerRef WKContextGetOriginDataManager(WKContextRef context); typedef void (*WKContextGetStatisticsFunction)(WKDictionaryRef statistics, WKErrorRef error, void* functionContext); WK_EXPORT void WKContextGetStatistics(WKContextRef context, void* functionContext, WKContextGetStatisticsFunction function); diff --git a/Source/WebKit2/UIProcess/API/C/WKContextConfigurationRef.cpp b/Source/WebKit2/UIProcess/API/C/WKContextConfigurationRef.cpp new file mode 100644 index 000000000..fe4f9139a --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKContextConfigurationRef.cpp @@ -0,0 +1,133 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKContextConfigurationRef.h" + +#include "APIProcessPoolConfiguration.h" +#include "WKAPICast.h" + +using namespace WebKit; + +WKContextConfigurationRef WKContextConfigurationCreate() +{ + auto configuration = API::ProcessPoolConfiguration::create(); + + // FIXME: A context created like this shouldn't have a data store, + // instead there should be a WKPageConfigurationRef object that specifies the data store. + configuration->setShouldHaveLegacyDataStore(true); + + return toAPI(&configuration.leakRef()); +} + +WKStringRef WKContextConfigurationCopyDiskCacheDirectory(WKContextConfigurationRef configuration) +{ + return toCopiedAPI(toImpl(configuration)->diskCacheDirectory()); +} + +void WKContextConfigurationSetDiskCacheDirectory(WKContextConfigurationRef configuration, WKStringRef diskCacheDirectory) +{ + toImpl(configuration)->setDiskCacheDirectory(toImpl(diskCacheDirectory)->string()); +} + +WKStringRef WKContextConfigurationCopyApplicationCacheDirectory(WKContextConfigurationRef configuration) +{ + return toCopiedAPI(toImpl(configuration)->applicationCacheDirectory()); +} + +void WKContextConfigurationSetApplicationCacheDirectory(WKContextConfigurationRef configuration, WKStringRef applicationCacheDirectory) +{ + toImpl(configuration)->setApplicationCacheDirectory(toImpl(applicationCacheDirectory)->string()); +} + +WKStringRef WKContextConfigurationCopyIndexedDBDatabaseDirectory(WKContextConfigurationRef configuration) +{ + return toCopiedAPI(toImpl(configuration)->indexedDBDatabaseDirectory()); +} + +void WKContextConfigurationSetIndexedDBDatabaseDirectory(WKContextConfigurationRef configuration, WKStringRef indexedDBDatabaseDirectory) +{ + toImpl(configuration)->setIndexedDBDatabaseDirectory(toImpl(indexedDBDatabaseDirectory)->string()); +} + +WKStringRef WKContextConfigurationCopyInjectedBundlePath(WKContextConfigurationRef configuration) +{ + return toCopiedAPI(toImpl(configuration)->injectedBundlePath()); +} + +void WKContextConfigurationSetInjectedBundlePath(WKContextConfigurationRef configuration, WKStringRef injectedBundlePath) +{ + toImpl(configuration)->setInjectedBundlePath(toImpl(injectedBundlePath)->string()); +} + +WKStringRef WKContextConfigurationCopyLocalStorageDirectory(WKContextConfigurationRef configuration) +{ + return toCopiedAPI(toImpl(configuration)->localStorageDirectory()); +} + +void WKContextConfigurationSetLocalStorageDirectory(WKContextConfigurationRef configuration, WKStringRef localStorageDirectory) +{ + toImpl(configuration)->setLocalStorageDirectory(toImpl(localStorageDirectory)->string()); +} + +WKStringRef WKContextConfigurationCopyWebSQLDatabaseDirectory(WKContextConfigurationRef configuration) +{ + return toCopiedAPI(toImpl(configuration)->webSQLDatabaseDirectory()); +} + +void WKContextConfigurationSetWebSQLDatabaseDirectory(WKContextConfigurationRef configuration, WKStringRef webSQLDatabaseDirectory) +{ + toImpl(configuration)->setWebSQLDatabaseDirectory(toImpl(webSQLDatabaseDirectory)->string()); +} + +WKStringRef WKContextConfigurationCopyMediaKeysStorageDirectory(WKContextConfigurationRef configuration) +{ + return toCopiedAPI(toImpl(configuration)->mediaKeysStorageDirectory()); +} + +void WKContextConfigurationSetMediaKeysStorageDirectory(WKContextConfigurationRef configuration, WKStringRef mediaKeysStorageDirectory) +{ + toImpl(configuration)->setMediaKeysStorageDirectory(toImpl(mediaKeysStorageDirectory)->string()); +} + +bool WKContextConfigurationFullySynchronousModeIsAllowedForTesting(WKContextConfigurationRef configuration) +{ + return toImpl(configuration)->fullySynchronousModeIsAllowedForTesting(); +} + +void WKContextConfigurationSetFullySynchronousModeIsAllowedForTesting(WKContextConfigurationRef configuration, bool allowed) +{ + toImpl(configuration)->setFullySynchronousModeIsAllowedForTesting(allowed); +} + +WKArrayRef WKContextConfigurationCopyOverrideLanguages(WKContextConfigurationRef configuration) +{ + return toAPI(&API::Array::createStringArray(toImpl(configuration)->overrideLanguages()).leakRef()); +} + +void WKContextConfigurationSetOverrideLanguages(WKContextConfigurationRef configuration, WKArrayRef overrideLanguages) +{ + toImpl(configuration)->setOverrideLanguages(toImpl(overrideLanguages)->toStringVector()); +} diff --git a/Source/WebKit2/UIProcess/API/C/WKContextConfigurationRef.h b/Source/WebKit2/UIProcess/API/C/WKContextConfigurationRef.h new file mode 100644 index 000000000..1ee343a47 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKContextConfigurationRef.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKContextConfigurationRef_h +#define WKContextConfigurationRef_h + +#include <WebKit/WKBase.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKContextConfigurationRef WKContextConfigurationCreate(); + +WK_EXPORT WKStringRef WKContextConfigurationCopyApplicationCacheDirectory(WKContextConfigurationRef configuration); +WK_EXPORT void WKContextConfigurationSetApplicationCacheDirectory(WKContextConfigurationRef configuration, WKStringRef applicationCacheDirectory); + +WK_EXPORT WKStringRef WKContextConfigurationCopyDiskCacheDirectory(WKContextConfigurationRef configuration); +WK_EXPORT void WKContextConfigurationSetDiskCacheDirectory(WKContextConfigurationRef configuration, WKStringRef diskCacheDirectory); + +WK_EXPORT WKStringRef WKContextConfigurationCopyIndexedDBDatabaseDirectory(WKContextConfigurationRef configuration); +WK_EXPORT void WKContextConfigurationSetIndexedDBDatabaseDirectory(WKContextConfigurationRef configuration, WKStringRef indexedDBDatabaseDirectory); + +WK_EXPORT WKStringRef WKContextConfigurationCopyInjectedBundlePath(WKContextConfigurationRef configuration); +WK_EXPORT void WKContextConfigurationSetInjectedBundlePath(WKContextConfigurationRef configuration, WKStringRef injectedBundlePath); + +WK_EXPORT WKStringRef WKContextConfigurationCopyLocalStorageDirectory(WKContextConfigurationRef configuration); +WK_EXPORT void WKContextConfigurationSetLocalStorageDirectory(WKContextConfigurationRef configuration, WKStringRef localStorageDirectory); + +WK_EXPORT WKStringRef WKContextConfigurationCopyWebSQLDatabaseDirectory(WKContextConfigurationRef configuration); +WK_EXPORT void WKContextConfigurationSetWebSQLDatabaseDirectory(WKContextConfigurationRef configuration, WKStringRef webSQLDatabaseDirectory); + +WK_EXPORT WKStringRef WKContextConfigurationCopyMediaKeysStorageDirectory(WKContextConfigurationRef configuration); +WK_EXPORT void WKContextConfigurationSetMediaKeysStorageDirectory(WKContextConfigurationRef configuration, WKStringRef mediaKeysStorageDirectory); + +WK_EXPORT bool WKContextConfigurationFullySynchronousModeIsAllowedForTesting(WKContextConfigurationRef configuration); +WK_EXPORT void WKContextConfigurationSetFullySynchronousModeIsAllowedForTesting(WKContextConfigurationRef configuration, bool allowed); + +WK_EXPORT WKArrayRef WKContextConfigurationCopyOverrideLanguages(WKContextConfigurationRef configuration); +WK_EXPORT void WKContextConfigurationSetOverrideLanguages(WKContextConfigurationRef configuration, WKArrayRef overrideLanguages); + +#ifdef __cplusplus +} +#endif + + +#endif // WKContextConfigurationRef_h diff --git a/Source/WebKit2/UIProcess/API/C/WKContextConnectionClient.h b/Source/WebKit2/UIProcess/API/C/WKContextConnectionClient.h index 82f79d63e..e7c576310 100644 --- a/Source/WebKit2/UIProcess/API/C/WKContextConnectionClient.h +++ b/Source/WebKit2/UIProcess/API/C/WKContextConnectionClient.h @@ -26,7 +26,7 @@ #ifndef WKContextConnectionClient_h #define WKContextConnectionClient_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> typedef void (*WKContextDidCreateConnection)(WKContextRef context, WKConnectionRef connection, const void* clientInfo); @@ -42,13 +42,4 @@ typedef struct WKContextConnectionClientV0 { WKContextDidCreateConnection didCreateConnection; } WKContextConnectionClientV0; -enum { kWKContextConnectionClientCurrentVersion WK_ENUM_DEPRECATED("Use an explicit version number instead") = 0 }; -typedef struct WKContextConnectionClient { - int version; - const void * clientInfo; - - // Version 0. - WKContextDidCreateConnection didCreateConnection; -} WKContextConnectionClient WK_DEPRECATED("Use an explicit versioned struct instead"); - #endif // WKContextConnectionClient_h diff --git a/Source/WebKit2/UIProcess/API/C/WKContextDownloadClient.h b/Source/WebKit2/UIProcess/API/C/WKContextDownloadClient.h index 0aede7fb6..5bb8d83a8 100644 --- a/Source/WebKit2/UIProcess/API/C/WKContextDownloadClient.h +++ b/Source/WebKit2/UIProcess/API/C/WKContextDownloadClient.h @@ -26,7 +26,7 @@ #ifndef WKContextDownloadClient_h #define WKContextDownloadClient_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> typedef void (*WKContextDownloadDidStartCallback)(WKContextRef context, WKDownloadRef download, const void *clientInfo); typedef void (*WKContextDownloadDidReceiveAuthenticationChallengeCallback)(WKContextRef context, WKDownloadRef download, WKAuthenticationChallengeRef authenticationChallenge, const void *clientInfo); @@ -62,23 +62,4 @@ typedef struct WKContextDownloadClientV0 { WKContextDownloadProcessDidCrashCallback processDidCrash; } WKContextDownloadClientV0; -enum { kWKContextDownloadClientCurrentVersion WK_ENUM_DEPRECATED("Use an explicit version number instead") = 0 }; -typedef struct WKContextDownloadClient { - int version; - const void * clientInfo; - - // Version 0. - WKContextDownloadDidStartCallback didStart; - WKContextDownloadDidReceiveAuthenticationChallengeCallback didReceiveAuthenticationChallenge; - WKContextDownloadDidReceiveResponseCallback didReceiveResponse; - WKContextDownloadDidReceiveDataCallback didReceiveData; - WKContextDownloadShouldDecodeSourceDataOfMIMETypeCallback shouldDecodeSourceDataOfMIMEType; - WKContextDownloadDecideDestinationWithSuggestedFilenameCallback decideDestinationWithSuggestedFilename; - WKContextDownloadDidCreateDestinationCallback didCreateDestination; - WKContextDownloadDidFinishCallback didFinish; - WKContextDownloadDidFailCallback didFail; - WKContextDownloadDidCancel didCancel; - WKContextDownloadProcessDidCrashCallback processDidCrash; -} WKContextDownloadClient WK_DEPRECATED("Use an explicit versioned struct instead"); - #endif // WKContextDownloadClient_h diff --git a/Source/WebKit2/UIProcess/API/C/WKContextHistoryClient.h b/Source/WebKit2/UIProcess/API/C/WKContextHistoryClient.h index 821b0ab42..0558efdba 100644 --- a/Source/WebKit2/UIProcess/API/C/WKContextHistoryClient.h +++ b/Source/WebKit2/UIProcess/API/C/WKContextHistoryClient.h @@ -26,7 +26,7 @@ #ifndef WKContextHistoryClient_h #define WKContextHistoryClient_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> typedef void (*WKContextDidNavigateWithNavigationDataCallback)(WKContextRef context, WKPageRef page, WKNavigationDataRef navigationData, WKFrameRef frame, const void *clientInfo); typedef void (*WKContextDidPerformClientRedirectCallback)(WKContextRef context, WKPageRef page, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef frame, const void *clientInfo); @@ -50,17 +50,4 @@ typedef struct WKContextHistoryClientV0 { WKContextPopulateVisitedLinksCallback populateVisitedLinks; } WKContextHistoryClientV0; -enum { kWKContextHistoryClientCurrentVersion WK_ENUM_DEPRECATED("Use an explicit version number instead") = 0 }; -typedef struct WKContextHistoryClient { - int version; - const void * clientInfo; - - // Version 0. - WKContextDidNavigateWithNavigationDataCallback didNavigateWithNavigationData; - WKContextDidPerformClientRedirectCallback didPerformClientRedirect; - WKContextDidPerformServerRedirectCallback didPerformServerRedirect; - WKContextDidUpdateHistoryTitleCallback didUpdateHistoryTitle; - WKContextPopulateVisitedLinksCallback populateVisitedLinks; -} WKContextHistoryClient WK_DEPRECATED("Use an explicit versioned struct instead"); - #endif // WKContextHistoryClient_h diff --git a/Source/WebKit2/UIProcess/API/C/WKContextInjectedBundleClient.h b/Source/WebKit2/UIProcess/API/C/WKContextInjectedBundleClient.h index d48f8e7bc..d3456aa68 100644 --- a/Source/WebKit2/UIProcess/API/C/WKContextInjectedBundleClient.h +++ b/Source/WebKit2/UIProcess/API/C/WKContextInjectedBundleClient.h @@ -26,7 +26,7 @@ #ifndef WKContextInjectedBundleClient_h #define WKContextInjectedBundleClient_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> // Injected Bundle Client typedef void (*WKContextDidReceiveMessageFromInjectedBundleCallback)(WKContextRef page, WKStringRef messageName, WKTypeRef messageBody, const void *clientInfo); @@ -57,17 +57,4 @@ typedef struct WKContextInjectedBundleClientV1 { WKContextGetInjectedBundleInitializationUserDataCallback getInjectedBundleInitializationUserData; } WKContextInjectedBundleClientV1; -enum { kWKContextInjectedBundleClientCurrentVersion WK_ENUM_DEPRECATED("Use an explicit version number instead") = 1 }; -typedef struct WKContextInjectedBundleClient { - int version; - const void * clientInfo; - - // Version 0. - WKContextDidReceiveMessageFromInjectedBundleCallback didReceiveMessageFromInjectedBundle; - WKContextDidReceiveSynchronousMessageFromInjectedBundleCallback didReceiveSynchronousMessageFromInjectedBundle; - - // Version 1. - WKContextGetInjectedBundleInitializationUserDataCallback getInjectedBundleInitializationUserData; -} WKContextInjectedBundleClient WK_DEPRECATED("Use an explicit versioned struct instead"); - #endif // WKContextInjectedBundleClient_h diff --git a/Source/WebKit2/UIProcess/API/C/WKContextPrivate.h b/Source/WebKit2/UIProcess/API/C/WKContextPrivate.h index 9189163fd..05d27fd10 100644 --- a/Source/WebKit2/UIProcess/API/C/WKContextPrivate.h +++ b/Source/WebKit2/UIProcess/API/C/WKContextPrivate.h @@ -26,8 +26,8 @@ #ifndef WKContextPrivate_h #define WKContextPrivate_h -#include <WebKit2/WKBase.h> -#include <WebKit2/WKContext.h> +#include <WebKit/WKBase.h> +#include <WebKit/WKContext.h> #ifdef __cplusplus extern "C" { @@ -52,18 +52,18 @@ WK_EXPORT void WKContextSetShouldUseFontSmoothing(WKContextRef context, bool use WK_EXPORT void WKContextRegisterURLSchemeAsSecure(WKContextRef context, WKStringRef urlScheme); +WK_EXPORT void WKContextRegisterURLSchemeAsBypassingContentSecurityPolicy(WKContextRef context, WKStringRef urlScheme); + +WK_EXPORT void WKContextRegisterURLSchemeAsCachePartitioned(WKContextRef context, WKStringRef urlScheme); + WK_EXPORT void WKContextSetDomainRelaxationForbiddenForURLScheme(WKContextRef context, WKStringRef urlScheme); +WK_EXPORT void WKContextSetCanHandleHTTPSServerTrustEvaluation(WKContextRef context, bool value); + WK_EXPORT void WKContextSetIconDatabasePath(WKContextRef context, WKStringRef iconDatabasePath); WK_EXPORT void WKContextAllowSpecificHTTPSCertificateForHost(WKContextRef context, WKCertificateInfoRef certificate, WKStringRef host); -// FIXME: These functions are only effective if called before the Web process is launched. But -// we should really change these settings to be on WebPreferences and changeable at runtime. -WK_EXPORT void WKContextSetApplicationCacheDirectory(WKContextRef context, WKStringRef applicationCacheDirectory); -WK_EXPORT void WKContextSetDatabaseDirectory(WKContextRef context, WKStringRef databaseDirectory); -WK_EXPORT void WKContextSetLocalStorageDirectory(WKContextRef context, WKStringRef localStorageDirectory); -WK_EXPORT void WKContextSetDiskCacheDirectory(WKContextRef context, WKStringRef diskCacheDirectory); WK_EXPORT void WKContextSetCookieStorageDirectory(WKContextRef context, WKStringRef cookieStorageDirectory); // FIXME: This is a workaround for testing purposes only and should be removed once a better @@ -77,16 +77,21 @@ WK_EXPORT void WKContextWarmInitialProcess(WKContextRef context); // FIXME: This function is temporary and useful during the development of the NetworkProcess feature. // At some point it should be removed. -WK_EXPORT void WKContextSetUsesNetworkProcess(WKContextRef context, bool usesNetworkProcess); +WK_EXPORT void WKContextSetUsesNetworkProcess(WKContextRef, bool); // Test only. Should be called before any secondary processes are started. WK_EXPORT void WKContextUseTestingNetworkSession(WKContextRef context); +// Test only. Should be called before running a test. +WK_EXPORT void WKContextClearCachedCredentials(WKContextRef context); + typedef void (*WKContextInvalidMessageFunction)(WKStringRef messageName); WK_EXPORT void WKContextSetInvalidMessageFunction(WKContextInvalidMessageFunction invalidMessageFunction); WK_EXPORT void WKContextSetMemoryCacheDisabled(WKContextRef, bool disabled); +WK_EXPORT void WKContextSetFontWhitelist(WKContextRef, WKArrayRef); + #ifdef __cplusplus } #endif diff --git a/Source/WebKit2/UIProcess/API/C/WKCookieManager.cpp b/Source/WebKit2/UIProcess/API/C/WKCookieManager.cpp index ed2770f5d..e4a30611a 100644 --- a/Source/WebKit2/UIProcess/API/C/WKCookieManager.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKCookieManager.cpp @@ -43,7 +43,7 @@ void WKCookieManagerSetClient(WKCookieManagerRef cookieManagerRef, const WKCooki void WKCookieManagerGetHostnamesWithCookies(WKCookieManagerRef cookieManagerRef, void* context, WKCookieManagerGetCookieHostnamesFunction callback) { - toImpl(cookieManagerRef)->getHostnamesWithCookies(ArrayCallback::create(context, callback)); + toImpl(cookieManagerRef)->getHostnamesWithCookies(toGenericCallbackFunction(context, callback)); } void WKCookieManagerDeleteCookiesForHostname(WKCookieManagerRef cookieManagerRef, WKStringRef hostname) @@ -56,6 +56,14 @@ void WKCookieManagerDeleteAllCookies(WKCookieManagerRef cookieManagerRef) toImpl(cookieManagerRef)->deleteAllCookies(); } +void WKCookieManagerDeleteAllCookiesModifiedAfterDate(WKCookieManagerRef cookieManagerRef, double date) +{ + using namespace std::chrono; + + auto time = system_clock::time_point(duration_cast<system_clock::duration>(duration<double>(date))); + toImpl(cookieManagerRef)->deleteAllCookiesModifiedSince(time); +} + void WKCookieManagerSetHTTPCookieAcceptPolicy(WKCookieManagerRef cookieManager, WKHTTPCookieAcceptPolicy policy) { toImpl(cookieManager)->setHTTPCookieAcceptPolicy(toHTTPCookieAcceptPolicy(policy)); @@ -63,7 +71,7 @@ void WKCookieManagerSetHTTPCookieAcceptPolicy(WKCookieManagerRef cookieManager, void WKCookieManagerGetHTTPCookieAcceptPolicy(WKCookieManagerRef cookieManager, void* context, WKCookieManagerGetHTTPCookieAcceptPolicyFunction callback) { - toImpl(cookieManager)->getHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicyCallback::create(context, callback)); + toImpl(cookieManager)->getHTTPCookieAcceptPolicy(toGenericCallbackFunction<WKHTTPCookieAcceptPolicy, HTTPCookieAcceptPolicy>(context, callback)); } void WKCookieManagerStartObservingCookieChanges(WKCookieManagerRef cookieManager) diff --git a/Source/WebKit2/UIProcess/API/C/WKCookieManager.h b/Source/WebKit2/UIProcess/API/C/WKCookieManager.h index 6f302a2ce..8f4111c3f 100644 --- a/Source/WebKit2/UIProcess/API/C/WKCookieManager.h +++ b/Source/WebKit2/UIProcess/API/C/WKCookieManager.h @@ -26,7 +26,7 @@ #ifndef WKCookieManager_h #define WKCookieManager_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { @@ -55,15 +55,6 @@ typedef struct WKCookieManagerClientV0 { WKCookieManagerCookiesDidChangeCallback cookiesDidChange; } WKCookieManagerClientV0; -enum { kWKCookieManagerClientCurrentVersion WK_ENUM_DEPRECATED("Use an explicit version number instead") = 0 }; -typedef struct WKCookieManagerClient { - int version; - const void * clientInfo; - - // Version 0. - WKCookieManagerCookiesDidChangeCallback cookiesDidChange; -} WKCookieManagerClient WK_DEPRECATED("Use an explicit versioned struct instead"); - WK_EXPORT WKTypeID WKCookieManagerGetTypeID(); WK_EXPORT void WKCookieManagerSetClient(WKCookieManagerRef cookieManager, const WKCookieManagerClientBase* client); @@ -74,6 +65,9 @@ WK_EXPORT void WKCookieManagerGetHostnamesWithCookies(WKCookieManagerRef cookieM WK_EXPORT void WKCookieManagerDeleteCookiesForHostname(WKCookieManagerRef cookieManager, WKStringRef hostname); WK_EXPORT void WKCookieManagerDeleteAllCookies(WKCookieManagerRef cookieManager); +// The time here is relative to the Unix epoch. +WK_EXPORT void WKCookieManagerDeleteAllCookiesModifiedAfterDate(WKCookieManagerRef cookieManager, double); + WK_EXPORT void WKCookieManagerSetHTTPCookieAcceptPolicy(WKCookieManagerRef cookieManager, WKHTTPCookieAcceptPolicy policy); typedef void (*WKCookieManagerGetHTTPCookieAcceptPolicyFunction)(WKHTTPCookieAcceptPolicy, WKErrorRef, void*); WK_EXPORT void WKCookieManagerGetHTTPCookieAcceptPolicy(WKCookieManagerRef cookieManager, void* context, WKCookieManagerGetHTTPCookieAcceptPolicyFunction callback); diff --git a/Source/WebKit2/UIProcess/API/C/WKCredential.cpp b/Source/WebKit2/UIProcess/API/C/WKCredential.cpp index 6a956003b..35ecb203b 100644 --- a/Source/WebKit2/UIProcess/API/C/WKCredential.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKCredential.cpp @@ -40,18 +40,16 @@ WKTypeID WKCredentialGetTypeID() WKCredentialRef WKCredentialCreate(WKStringRef username, WKStringRef password, WKCredentialPersistence persistence) { - RefPtr<WebCredential> credential = WebCredential::create(toImpl(username), toImpl(password), toCredentialPersistence(persistence)); - return toAPI(credential.release().leakRef()); + return toAPI(&WebCredential::create(WebCore::Credential(toImpl(username)->string(), toImpl(password)->string(), toCredentialPersistence(persistence))).leakRef()); } WKCredentialRef WKCredentialCreateWithCertificateInfo(WKCertificateInfoRef certificateInfo) { - RefPtr<WebCredential> credential = WebCredential::create(toImpl(certificateInfo)); - return toAPI(credential.release().leakRef()); + return toAPI(&WebCredential::create(toImpl(certificateInfo)).leakRef()); } WKStringRef WKCredentialCopyUser(WKCredentialRef credentialRef) { - return toCopiedAPI(toImpl(credentialRef)->user()); + return toCopiedAPI(toImpl(credentialRef)->credential().user()); } diff --git a/Source/WebKit2/UIProcess/API/C/WKCredential.h b/Source/WebKit2/UIProcess/API/C/WKCredential.h index 560fc419a..57842fbda 100644 --- a/Source/WebKit2/UIProcess/API/C/WKCredential.h +++ b/Source/WebKit2/UIProcess/API/C/WKCredential.h @@ -26,8 +26,8 @@ #ifndef WKCredential_h #define WKCredential_h -#include <WebKit2/WKBase.h> -#include <WebKit2/WKCredentialTypes.h> +#include <WebKit/WKBase.h> +#include <WebKit/WKCredentialTypes.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/WKDatabaseManager.cpp b/Source/WebKit2/UIProcess/API/C/WKDatabaseManager.cpp deleted file mode 100644 index 5aa9dcf6b..000000000 --- a/Source/WebKit2/UIProcess/API/C/WKDatabaseManager.cpp +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright (C) 2010 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "WKDatabaseManager.h" - -#include "WebDatabaseManagerProxy.h" -#include "WKAPICast.h" - -using namespace WebKit; - -WKTypeID WKDatabaseManagerGetTypeID() -{ -#if ENABLE(SQL_DATABASE) - return toAPI(WebDatabaseManagerProxy::APIType); -#else - return 0; -#endif -} - -WKStringRef WKDatabaseManagerGetOriginKey() -{ -#if ENABLE(SQL_DATABASE) - static API::String* key = API::String::create(WebDatabaseManagerProxy::originKey()).leakRef(); - return toAPI(key); -#else - return 0; -#endif -} - -WKStringRef WKDatabaseManagerGetOriginQuotaKey() -{ -#if ENABLE(SQL_DATABASE) - static API::String* key = API::String::create(WebDatabaseManagerProxy::originQuotaKey()).leakRef(); - return toAPI(key); -#else - return 0; -#endif -} - -WKStringRef WKDatabaseManagerGetOriginUsageKey() -{ -#if ENABLE(SQL_DATABASE) - static API::String* key = API::String::create(WebDatabaseManagerProxy::originUsageKey()).leakRef(); - return toAPI(key); -#else - return 0; -#endif -} - -WKStringRef WKDatabaseManagerGetDatabaseDetailsKey() -{ -#if ENABLE(SQL_DATABASE) - static API::String* key = API::String::create(WebDatabaseManagerProxy::databaseDetailsKey()).leakRef(); - return toAPI(key); -#else - return 0; -#endif -} - -WKStringRef WKDatabaseManagerGetDatabaseDetailsNameKey() -{ -#if ENABLE(SQL_DATABASE) - static API::String* key = API::String::create(WebDatabaseManagerProxy::databaseDetailsNameKey()).leakRef(); - return toAPI(key); -#else - return 0; -#endif -} - -WKStringRef WKDatabaseManagerGetDatabaseDetailsDisplayNameKey() -{ -#if ENABLE(SQL_DATABASE) - static API::String* key = API::String::create(WebDatabaseManagerProxy::databaseDetailsDisplayNameKey()).leakRef(); - return toAPI(key); -#else - return 0; -#endif -} - -WKStringRef WKDatabaseManagerGetDatabaseDetailsExpectedUsageKey() -{ -#if ENABLE(SQL_DATABASE) - static API::String* key = API::String::create(WebDatabaseManagerProxy::databaseDetailsExpectedUsageKey()).leakRef(); - return toAPI(key); -#else - return 0; -#endif -} - -WKStringRef WKDatabaseManagerGetDatabaseDetailsCurrentUsageKey() -{ -#if ENABLE(SQL_DATABASE) - static API::String* key = API::String::create(WebDatabaseManagerProxy::databaseDetailsCurrentUsageKey()).leakRef(); - return toAPI(key); -#else - return 0; -#endif -} - -WKStringRef WKDatabaseManagerGetDatabaseDetailsCreationTimeKey() -{ -#if ENABLE(SQL_DATABASE) - static API::String* key = API::String::create(WebDatabaseManagerProxy::databaseDetailsCreationTimeKey()).leakRef(); - return toAPI(key); -#else - return 0; -#endif -} - -WKStringRef WKDatabaseManagerGetDatabaseDetailsModificationTimeKey() -{ -#if ENABLE(SQL_DATABASE) - static API::String* key = API::String::create(WebDatabaseManagerProxy::databaseDetailsModificationTimeKey()).leakRef(); - return toAPI(key); -#else - return 0; -#endif -} - -void WKDatabaseManagerSetClient(WKDatabaseManagerRef databaseManagerRef, const WKDatabaseManagerClientBase* wkClient) -{ -#if ENABLE(SQL_DATABASE) - if (wkClient && wkClient->version) - return; - toImpl(databaseManagerRef)->initializeClient(wkClient); -#else - UNUSED_PARAM(databaseManagerRef); - UNUSED_PARAM(wkClient); -#endif -} - -void WKDatabaseManagerGetDatabasesByOrigin(WKDatabaseManagerRef databaseManagerRef, void* context, WKDatabaseManagerGetDatabasesByOriginFunction callback) -{ -#if ENABLE(SQL_DATABASE) - toImpl(databaseManagerRef)->getDatabasesByOrigin(ArrayCallback::create(context, callback)); -#else - UNUSED_PARAM(databaseManagerRef); - UNUSED_PARAM(context); - UNUSED_PARAM(callback); -#endif -} - -void WKDatabaseManagerGetDatabaseOrigins(WKDatabaseManagerRef databaseManagerRef, void* context, WKDatabaseManagerGetDatabaseOriginsFunction callback) -{ -#if ENABLE(SQL_DATABASE) - toImpl(databaseManagerRef)->getDatabaseOrigins(ArrayCallback::create(context, callback)); -#else - UNUSED_PARAM(databaseManagerRef); - UNUSED_PARAM(context); - UNUSED_PARAM(callback); -#endif -} - -void WKDatabaseManagerDeleteDatabasesWithNameForOrigin(WKDatabaseManagerRef databaseManagerRef, WKStringRef databaseNameRef, WKSecurityOriginRef originRef) -{ -#if ENABLE(SQL_DATABASE) - toImpl(databaseManagerRef)->deleteDatabaseWithNameForOrigin(toWTFString(databaseNameRef), toImpl(originRef)); -#else - UNUSED_PARAM(databaseManagerRef); - UNUSED_PARAM(databaseNameRef); - UNUSED_PARAM(originRef); -#endif -} - -void WKDatabaseManagerDeleteDatabasesForOrigin(WKDatabaseManagerRef databaseManagerRef, WKSecurityOriginRef originRef) -{ -#if ENABLE(SQL_DATABASE) - toImpl(databaseManagerRef)->deleteDatabasesForOrigin(toImpl(originRef)); -#else - UNUSED_PARAM(databaseManagerRef); - UNUSED_PARAM(originRef); -#endif -} - -void WKDatabaseManagerDeleteAllDatabases(WKDatabaseManagerRef databaseManagerRef) -{ -#if ENABLE(SQL_DATABASE) - toImpl(databaseManagerRef)->deleteAllDatabases(); -#else - UNUSED_PARAM(databaseManagerRef); -#endif -} - -void WKDatabaseManagerSetQuotaForOrigin(WKDatabaseManagerRef databaseManagerRef, WKSecurityOriginRef originRef, uint64_t quota) -{ -#if ENABLE(SQL_DATABASE) - toImpl(databaseManagerRef)->setQuotaForOrigin(toImpl(originRef), quota); -#else - UNUSED_PARAM(databaseManagerRef); - UNUSED_PARAM(originRef); - UNUSED_PARAM(quota); -#endif -} diff --git a/Source/WebKit2/UIProcess/API/C/WKDatabaseManager.h b/Source/WebKit2/UIProcess/API/C/WKDatabaseManager.h deleted file mode 100644 index 12f2dbc83..000000000 --- a/Source/WebKit2/UIProcess/API/C/WKDatabaseManager.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) 2010 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef WKDatabaseManager_h -#define WKDatabaseManager_h - -#include <WebKit2/WKBase.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/* Value type: WKSecurityOriginRef */ -WK_EXPORT WKStringRef WKDatabaseManagerGetOriginKey(); - -/* Value type: WKUInt64Ref */ -WK_EXPORT WKStringRef WKDatabaseManagerGetOriginQuotaKey(); - -/* Value type: WKUInt64Ref */ -WK_EXPORT WKStringRef WKDatabaseManagerGetOriginUsageKey(); - -/* Value type: WKArrayRef (array of WKDictionaryRef's with keys that include: - - WKDatabaseManagerGetDatabaseNameKey() - - WKDatabaseManagerGetDatabaseDisplayNameKey() - - WKDatabaseManagerGetDatabaseExpectedUsageKey() - - WKDatabaseManagerGetDatabaseCurrentUsageKey() - */ -WK_EXPORT WKStringRef WKDatabaseManagerGetDatabaseDetailsKey(); - -/* Value type: WKStringRef */ -WK_EXPORT WKStringRef WKDatabaseManagerGetDatabaseDetailsNameKey(); - -/* Value type: WKStringRef */ -WK_EXPORT WKStringRef WKDatabaseManagerGetDatabaseDetailsDisplayNameKey(); - -/* Value type: WKUInt64Ref */ -WK_EXPORT WKStringRef WKDatabaseManagerGetDatabaseDetailsExpectedUsageKey(); - -/* Value type: WKUInt64Ref */ -WK_EXPORT WKStringRef WKDatabaseManagerGetDatabaseDetailsCurrentUsageKey(); - -/* Value type: WKDoubleRef, seconds since January 1st, 1970 UTC */ -WK_EXPORT WKStringRef WKDatabaseManagerGetDatabaseDetailsCreationTimeKey(); - -/* Value type: WKDoubleRef, seconds since January 1st, 1970 UTC */ -WK_EXPORT WKStringRef WKDatabaseManagerGetDatabaseDetailsModificationTimeKey(); - - -// Database Manager Client -typedef void (*WKDatabaseManagerDidModifyOriginCallback)(WKDatabaseManagerRef databaseManager, WKSecurityOriginRef origin, const void *clientInfo); -typedef void (*WKDatabaseManagerDidModifyDatabaseCallback)(WKDatabaseManagerRef databaseManager, WKSecurityOriginRef origin, WKStringRef databaseIdentifier, const void *clientInfo); - -typedef struct WKDatabaseManagerClientBase { - int version; - const void * clientInfo; -} WKDatabaseManagerClientBase; - -typedef struct WKDatabaseManagerClientV0 { - WKDatabaseManagerClientBase base; - - // Version 0. - WKDatabaseManagerDidModifyOriginCallback didModifyOrigin; - WKDatabaseManagerDidModifyDatabaseCallback didModifyDatabase; -} WKDatabaseManagerClientV0; - -enum { kWKDatabaseManagerClientCurrentVersion WK_ENUM_DEPRECATED("Use an explicit version number instead") = 0 }; -typedef struct WKDatabaseManagerClient { - int version; - const void * clientInfo; - - // Version 0. - WKDatabaseManagerDidModifyOriginCallback didModifyOrigin; - WKDatabaseManagerDidModifyDatabaseCallback didModifyDatabase; -} WKDatabaseManagerClient WK_DEPRECATED("Use an explicit versioned struct instead"); - -WK_EXPORT WKTypeID WKDatabaseManagerGetTypeID(); - -WK_EXPORT void WKDatabaseManagerSetClient(WKDatabaseManagerRef databaseManager, const WKDatabaseManagerClientBase* client); - -typedef void (*WKDatabaseManagerGetDatabasesByOriginFunction)(WKArrayRef, WKErrorRef, void*); -WK_EXPORT void WKDatabaseManagerGetDatabasesByOrigin(WKDatabaseManagerRef databaseManager, void* context, WKDatabaseManagerGetDatabasesByOriginFunction function); - -typedef void (*WKDatabaseManagerGetDatabaseOriginsFunction)(WKArrayRef, WKErrorRef, void*); -WK_EXPORT void WKDatabaseManagerGetDatabaseOrigins(WKDatabaseManagerRef contextRef, void* context, WKDatabaseManagerGetDatabaseOriginsFunction function); - -WK_EXPORT void WKDatabaseManagerDeleteDatabasesWithNameForOrigin(WKDatabaseManagerRef databaseManager, WKStringRef databaseName, WKSecurityOriginRef origin); -WK_EXPORT void WKDatabaseManagerDeleteDatabasesForOrigin(WKDatabaseManagerRef databaseManager, WKSecurityOriginRef origin); -WK_EXPORT void WKDatabaseManagerDeleteAllDatabases(WKDatabaseManagerRef databaseManager); - -WK_EXPORT void WKDatabaseManagerSetQuotaForOrigin(WKDatabaseManagerRef databaseManager, WKSecurityOriginRef origin, uint64_t quota); - -#ifdef __cplusplus -} -#endif - -#endif // WKDatabaseManager_h diff --git a/Source/WebKit2/UIProcess/API/C/WKDownload.cpp b/Source/WebKit2/UIProcess/API/C/WKDownload.cpp index 84e9103c4..abf93f12f 100644 --- a/Source/WebKit2/UIProcess/API/C/WKDownload.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKDownload.cpp @@ -26,6 +26,7 @@ #include "config.h" #include "WKDownload.h" +#include "APIData.h" #include "APIURLRequest.h" #include "DownloadProxy.h" #include "WKAPICast.h" @@ -39,12 +40,12 @@ WKTypeID WKDownloadGetTypeID() uint64_t WKDownloadGetID(WKDownloadRef download) { - return toImpl(download)->downloadID(); + return toImpl(download)->downloadID().downloadID(); } WKURLRequestRef WKDownloadCopyRequest(WKDownloadRef download) { - return toAPI(API::URLRequest::create(toImpl(download)->request()).leakRef()); + return toAPI(&API::URLRequest::create(toImpl(download)->request()).leakRef()); } WKDataRef WKDownloadGetResumeData(WKDownloadRef download) diff --git a/Source/WebKit2/UIProcess/API/C/WKDownload.h b/Source/WebKit2/UIProcess/API/C/WKDownload.h index 8acc9106d..5dbea7e44 100644 --- a/Source/WebKit2/UIProcess/API/C/WKDownload.h +++ b/Source/WebKit2/UIProcess/API/C/WKDownload.h @@ -26,7 +26,7 @@ #ifndef WKDownload_h #define WKDownload_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifndef __cplusplus #include <stdbool.h> diff --git a/Source/WebKit2/UIProcess/API/C/WKFormSubmissionListener.h b/Source/WebKit2/UIProcess/API/C/WKFormSubmissionListener.h index 4b9b79acb..c320b68d4 100644 --- a/Source/WebKit2/UIProcess/API/C/WKFormSubmissionListener.h +++ b/Source/WebKit2/UIProcess/API/C/WKFormSubmissionListener.h @@ -26,7 +26,7 @@ #ifndef WKFormSubmissionListener_h #define WKFormSubmissionListener_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/WKFrame.cpp b/Source/WebKit2/UIProcess/API/C/WKFrame.cpp index 2f74c6df7..f54e70d8a 100644 --- a/Source/WebKit2/UIProcess/API/C/WKFrame.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKFrame.cpp @@ -26,8 +26,12 @@ #include "config.h" #include "WKFrame.h" +#include "APIData.h" +#include "APIFrameInfo.h" #include "WKAPICast.h" +#include "WebCertificateInfo.h" #include "WebFrameProxy.h" +#include "WebPageProxy.h" using namespace WebKit; @@ -44,7 +48,7 @@ bool WKFrameIsMainFrame(WKFrameRef frameRef) WKFrameLoadState WKFrameGetFrameLoadState(WKFrameRef frameRef) { WebFrameProxy* frame = toImpl(frameRef); - switch (frame->frameLoadState().m_state) { + switch (frame->frameLoadState().state()) { case FrameLoadState::State::Provisional: return kWKFrameLoadStateProvisional; case FrameLoadState::State::Committed: @@ -122,29 +126,22 @@ bool WKFrameIsFrameSet(WKFrameRef frameRef) return toImpl(frameRef)->isFrameSet(); } -void WKFrameGetMainResourceData(WKFrameRef frameRef, WKFrameGetResourceDataFunction callback, void* context) -{ - toImpl(frameRef)->getMainResourceData(DataCallback::create(context, callback)); -} - -void WKFrameGetResourceData(WKFrameRef frameRef, WKURLRef resourceURL, WKFrameGetResourceDataFunction callback, void* context) +WKFrameInfoRef WKFrameCreateFrameInfo(WKFrameRef frameRef) { - toImpl(frameRef)->getResourceData(toImpl(resourceURL), DataCallback::create(context, callback)); + return toAPI(&API::FrameInfo::create(*toImpl(frameRef), WebCore::SecurityOrigin::createFromString(toImpl(frameRef)->url())).leakRef()); } -void WKFrameGetWebArchive(WKFrameRef frameRef, WKFrameGetWebArchiveFunction callback, void* context) +void WKFrameGetMainResourceData(WKFrameRef frameRef, WKFrameGetResourceDataFunction callback, void* context) { - toImpl(frameRef)->getWebArchive(DataCallback::create(context, callback)); + toImpl(frameRef)->getMainResourceData(toGenericCallbackFunction(context, callback)); } -// NOTE: These are deprecated and should be removed. They currently do nothing. - -WKArrayRef WKFrameCopyChildFrames(WKFrameRef) +void WKFrameGetResourceData(WKFrameRef frameRef, WKURLRef resourceURL, WKFrameGetResourceDataFunction callback, void* context) { - return 0; + toImpl(frameRef)->getResourceData(toImpl(resourceURL), toGenericCallbackFunction(context, callback)); } -WKFrameRef WKFrameGetParentFrame(WKFrameRef) +void WKFrameGetWebArchive(WKFrameRef frameRef, WKFrameGetWebArchiveFunction callback, void* context) { - return 0; + toImpl(frameRef)->getWebArchive(toGenericCallbackFunction(context, callback)); } diff --git a/Source/WebKit2/UIProcess/API/C/WKFrame.h b/Source/WebKit2/UIProcess/API/C/WKFrame.h index 5f169e48e..4fd29a608 100644 --- a/Source/WebKit2/UIProcess/API/C/WKFrame.h +++ b/Source/WebKit2/UIProcess/API/C/WKFrame.h @@ -26,7 +26,7 @@ #ifndef WKFrame_h #define WKFrame_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifndef __cplusplus #include <stdbool.h> @@ -68,6 +68,8 @@ WK_EXPORT bool WKFrameIsDisplayingMarkupDocument(WKFrameRef frame); WK_EXPORT bool WKFrameIsFrameSet(WKFrameRef frame); +WK_EXPORT WKFrameInfoRef WKFrameCreateFrameInfo(WKFrameRef frame); + typedef void (*WKFrameGetResourceDataFunction)(WKDataRef data, WKErrorRef error, void* functionContext); WK_EXPORT void WKFrameGetMainResourceData(WKFrameRef frame, WKFrameGetResourceDataFunction function, void* functionContext); WK_EXPORT void WKFrameGetResourceData(WKFrameRef frame, WKURLRef resourceURL, WKFrameGetResourceDataFunction function, void* functionContext); @@ -75,11 +77,6 @@ WK_EXPORT void WKFrameGetResourceData(WKFrameRef frame, WKURLRef resourceURL, WK typedef void (*WKFrameGetWebArchiveFunction)(WKDataRef archiveData, WKErrorRef error, void* functionContext); WK_EXPORT void WKFrameGetWebArchive(WKFrameRef frame, WKFrameGetWebArchiveFunction function, void* functionContext); -// NOTE: These are deprecated and should be removed. They currently do nothing. - -WK_EXPORT WKArrayRef WKFrameCopyChildFrames(WKFrameRef frame); -WK_EXPORT WKFrameRef WKFrameGetParentFrame(WKFrameRef frame); - #ifdef __cplusplus } #endif diff --git a/Source/WebKit2/UIProcess/WebOriginDataManagerProxyChangeClient.cpp b/Source/WebKit2/UIProcess/API/C/WKFrameInfoRef.cpp index f1ee820e8..dbdd10113 100644 --- a/Source/WebKit2/UIProcess/WebOriginDataManagerProxyChangeClient.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKFrameInfoRef.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Apple Inc. All rights reserved. + * Copyright (C) 2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -24,18 +24,14 @@ */ #include "config.h" -#include "WebOriginDataManagerProxyChangeClient.h" +#include "WKFrameInfoRef.h" +#include "APIFrameInfo.h" #include "WKAPICast.h" -namespace WebKit { +using namespace WebKit; -void WebOriginDataManagerProxyChangeClient::didChange(WebOriginDataManagerProxy* originDataManager) +WKTypeID WKFrameInfoGetTypeID() { - if (!m_client.didChange) - return; - - m_client.didChange(toAPI(originDataManager), m_client.base.clientInfo); + return toAPI(API::FrameInfo::APIType); } - -} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/ProcessModel.h b/Source/WebKit2/UIProcess/API/C/WKFrameInfoRef.h index 6c18da0a2..f7ddadd92 100644 --- a/Source/WebKit2/UIProcess/ProcessModel.h +++ b/Source/WebKit2/UIProcess/API/C/WKFrameInfoRef.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -23,16 +23,19 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ProcessModel_h -#define ProcessModel_h +#ifndef WKFrameInfoRef_h +#define WKFrameInfoRef_h -namespace WebKit { +#include <WebKit/WKBase.h> -enum ProcessModel { - ProcessModelSharedSecondaryProcess, - ProcessModelMultipleSecondaryProcesses -}; +#ifdef __cplusplus +extern "C" { +#endif -} // namespace WebKit +WK_EXPORT WKTypeID WKFrameInfoGetTypeID(); -#endif // ProcessModel_h +#ifdef __cplusplus +} +#endif + +#endif // WKFrameInfoRef_h diff --git a/Source/WebKit2/UIProcess/API/C/WKFramePolicyListener.h b/Source/WebKit2/UIProcess/API/C/WKFramePolicyListener.h index 99b013d54..046c68131 100644 --- a/Source/WebKit2/UIProcess/API/C/WKFramePolicyListener.h +++ b/Source/WebKit2/UIProcess/API/C/WKFramePolicyListener.h @@ -26,7 +26,7 @@ #ifndef WKFramePolicyListener_h #define WKFramePolicyListener_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/WKGeolocationManager.cpp b/Source/WebKit2/UIProcess/API/C/WKGeolocationManager.cpp index 968bd920a..18b1a09bc 100644 --- a/Source/WebKit2/UIProcess/API/C/WKGeolocationManager.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKGeolocationManager.cpp @@ -28,6 +28,7 @@ #include "WKAPICast.h" #include "WebGeolocationManagerProxy.h" +#include "WebGeolocationPosition.h" using namespace WebKit; diff --git a/Source/WebKit2/UIProcess/API/C/WKGeolocationManager.h b/Source/WebKit2/UIProcess/API/C/WKGeolocationManager.h index f8c191790..581ae0472 100644 --- a/Source/WebKit2/UIProcess/API/C/WKGeolocationManager.h +++ b/Source/WebKit2/UIProcess/API/C/WKGeolocationManager.h @@ -26,7 +26,7 @@ #ifndef WKGeolocationManager_h #define WKGeolocationManager_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { @@ -61,17 +61,6 @@ typedef struct WKGeolocationProviderV1 { WKGeolocationProviderSetEnableHighAccuracyCallback setEnableHighAccuracy; } WKGeolocationProviderV1; -enum { kWKGeolocationProviderCurrentVersion WK_ENUM_DEPRECATED("Use an explicit version number instead") = 1 }; -typedef struct WKGeolocationProvider { - int version; - const void * clientInfo; - WKGeolocationProviderStartUpdatingCallback startUpdating; - WKGeolocationProviderStopUpdatingCallback stopUpdating; - - // Version 1. - WKGeolocationProviderSetEnableHighAccuracyCallback setEnableHighAccuracy; -} WKGeolocationProvider WK_DEPRECATED("Use an explicit versioned struct instead"); - WK_EXPORT WKTypeID WKGeolocationManagerGetTypeID(); diff --git a/Source/WebKit2/UIProcess/API/C/WKGeolocationPermissionRequest.h b/Source/WebKit2/UIProcess/API/C/WKGeolocationPermissionRequest.h index ee27b66ec..b1391813a 100644 --- a/Source/WebKit2/UIProcess/API/C/WKGeolocationPermissionRequest.h +++ b/Source/WebKit2/UIProcess/API/C/WKGeolocationPermissionRequest.h @@ -26,7 +26,7 @@ #ifndef WKGeolocationPermissionRequest_h #define WKGeolocationPermissionRequest_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/WKGeolocationPosition.h b/Source/WebKit2/UIProcess/API/C/WKGeolocationPosition.h index 4727e9763..6d67f1d1e 100644 --- a/Source/WebKit2/UIProcess/API/C/WKGeolocationPosition.h +++ b/Source/WebKit2/UIProcess/API/C/WKGeolocationPosition.h @@ -26,7 +26,7 @@ #ifndef WKGeolocationPosition_h #define WKGeolocationPosition_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/WKGrammarDetail.cpp b/Source/WebKit2/UIProcess/API/C/WKGrammarDetail.cpp index 193af2eb7..065f99ba7 100644 --- a/Source/WebKit2/UIProcess/API/C/WKGrammarDetail.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKGrammarDetail.cpp @@ -56,7 +56,7 @@ int WKGrammarDetailGetLength(WKGrammarDetailRef grammarDetailRef) WKArrayRef WKGrammarDetailCopyGuesses(WKGrammarDetailRef grammarDetailRef) { - return toAPI(toImpl(grammarDetailRef)->guesses().leakRef()); + return toAPI(&toImpl(grammarDetailRef)->guesses().leakRef()); } WKStringRef WKGrammarDetailCopyUserDescription(WKGrammarDetailRef grammarDetailRef) diff --git a/Source/WebKit2/UIProcess/API/C/WKGrammarDetail.h b/Source/WebKit2/UIProcess/API/C/WKGrammarDetail.h index c187ce6ad..2493c44d4 100644 --- a/Source/WebKit2/UIProcess/API/C/WKGrammarDetail.h +++ b/Source/WebKit2/UIProcess/API/C/WKGrammarDetail.h @@ -26,7 +26,7 @@ #ifndef WKGrammarDetail_h #define WKGrammarDetail_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/WKHitTestResult.cpp b/Source/WebKit2/UIProcess/API/C/WKHitTestResult.cpp index 5949091bb..4082002b0 100644 --- a/Source/WebKit2/UIProcess/API/C/WKHitTestResult.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKHitTestResult.cpp @@ -27,14 +27,14 @@ #include "config.h" #include "WKHitTestResult.h" +#include "APIHitTestResult.h" #include "WKAPICast.h" -#include "WebHitTestResult.h" using namespace WebKit; WKTypeID WKHitTestResultGetTypeID() { - return toAPI(WebHitTestResult::APIType); + return toAPI(API::HitTestResult::APIType); } WKURLRef WKHitTestResultCopyAbsoluteImageURL(WKHitTestResultRef hitTestResultRef) @@ -67,7 +67,17 @@ WKStringRef WKHitTestResultCopyLinkTitle(WKHitTestResultRef hitTestResultRef) return toCopiedAPI(toImpl(hitTestResultRef)->linkTitle()); } +WKStringRef WKHitTestResultCopyLookupText(WKHitTestResultRef hitTestResult) +{ + return toCopiedAPI(toImpl(hitTestResult)->lookupText()); +} + bool WKHitTestResultIsContentEditable(WKHitTestResultRef hitTestResultRef) { return toImpl(hitTestResultRef)->isContentEditable(); } + +WKRect WKHitTestResultGetElementBoundingBox(WKHitTestResultRef hitTestResultRef) +{ + return toAPI(toImpl(hitTestResultRef)->elementBoundingBox()); +} diff --git a/Source/WebKit2/UIProcess/API/C/WKHitTestResult.h b/Source/WebKit2/UIProcess/API/C/WKHitTestResult.h index 55fd13768..3c7081362 100644 --- a/Source/WebKit2/UIProcess/API/C/WKHitTestResult.h +++ b/Source/WebKit2/UIProcess/API/C/WKHitTestResult.h @@ -27,7 +27,8 @@ #ifndef WKHitTestResult_h #define WKHitTestResult_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> +#include <WebKit/WKGeometry.h> #ifdef __cplusplus extern "C" { @@ -42,9 +43,12 @@ WK_EXPORT WKURLRef WKHitTestResultCopyAbsoluteMediaURL(WKHitTestResultRef hitTes WK_EXPORT WKStringRef WKHitTestResultCopyLinkLabel(WKHitTestResultRef hitTestResult); WK_EXPORT WKStringRef WKHitTestResultCopyLinkTitle(WKHitTestResultRef hitTestResult); +WK_EXPORT WKStringRef WKHitTestResultCopyLookupText(WKHitTestResultRef hitTestResult); WK_EXPORT bool WKHitTestResultIsContentEditable(WKHitTestResultRef hitTestResult); +WK_EXPORT WKRect WKHitTestResultGetElementBoundingBox(WKHitTestResultRef hitTestResultRef); + #ifdef __cplusplus } #endif diff --git a/Source/WebKit2/UIProcess/API/C/WKIconDatabase.cpp b/Source/WebKit2/UIProcess/API/C/WKIconDatabase.cpp index a47290073..39006631f 100644 --- a/Source/WebKit2/UIProcess/API/C/WKIconDatabase.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKIconDatabase.cpp @@ -57,6 +57,23 @@ void WKIconDatabaseSetIconDataForIconURL(WKIconDatabaseRef iconDatabaseRef, WKDa toImpl(iconDatabaseRef)->setIconDataForIconURL(toImpl(iconDataRef)->dataReference(), toWTFString(iconURLRef)); } +void WKIconDatabaseSetIconURLForPageURL(WKIconDatabaseRef iconDatabaseRef, WKURLRef iconURLRef, WKURLRef pageURLRef) +{ + toImpl(iconDatabaseRef)->setIconURLForPageURL(toWTFString(iconURLRef), toWTFString(pageURLRef)); +} + +WKURLRef WKIconDatabaseCopyIconURLForPageURL(WKIconDatabaseRef iconDatabaseRef, WKURLRef pageURLRef) +{ + String iconURLString; + toImpl(iconDatabaseRef)->synchronousIconURLForPageURL(toWTFString(pageURLRef), iconURLString); + return toCopiedURLAPI(iconURLString); +} + +WKDataRef WKIconDatabaseCopyIconDataForPageURL(WKIconDatabaseRef iconDatabaseRef, WKURLRef pageURL) +{ + return toAPI(toImpl(iconDatabaseRef)->iconDataForPageURL(toWTFString(pageURL)).leakRef()); +} + void WKIconDatabaseEnableDatabaseCleanup(WKIconDatabaseRef iconDatabaseRef) { toImpl(iconDatabaseRef)->enableDatabaseCleanup(); diff --git a/Source/WebKit2/UIProcess/API/C/WKIconDatabase.h b/Source/WebKit2/UIProcess/API/C/WKIconDatabase.h index 0a10f6596..847414179 100644 --- a/Source/WebKit2/UIProcess/API/C/WKIconDatabase.h +++ b/Source/WebKit2/UIProcess/API/C/WKIconDatabase.h @@ -26,7 +26,7 @@ #ifndef WKIconDatabase_h #define WKIconDatabase_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { @@ -61,19 +61,6 @@ typedef struct WKIconDatabaseClientV1 { WKIconDatabaseIconDataReadyForPageURLCallback iconDataReadyForPageURL; } WKIconDatabaseClientV1; -enum { kWKIconDatabaseClientCurrentVersion WK_ENUM_DEPRECATED("Use an explicit version number instead") = 1 }; -typedef struct WKIconDatabaseClient { - int version; - const void * clientInfo; - - // Version 0. - WKIconDatabaseDidChangeIconForPageURLCallback didChangeIconForPageURL; - WKIconDatabaseDidRemoveAllIconsCallback didRemoveAllIcons; - - // Version 1. - WKIconDatabaseIconDataReadyForPageURLCallback iconDataReadyForPageURL; -} WKIconDatabaseClient WK_DEPRECATED("Use an explicit versioned struct instead"); - WK_EXPORT WKTypeID WKIconDatabaseGetTypeID(); WK_EXPORT void WKIconDatabaseSetIconDatabaseClient(WKIconDatabaseRef iconDatabase, const WKIconDatabaseClientBase* client); @@ -81,6 +68,10 @@ WK_EXPORT void WKIconDatabaseSetIconDatabaseClient(WKIconDatabaseRef iconDatabas WK_EXPORT void WKIconDatabaseRetainIconForURL(WKIconDatabaseRef iconDatabase, WKURLRef pageURL); WK_EXPORT void WKIconDatabaseReleaseIconForURL(WKIconDatabaseRef iconDatabase, WKURLRef pageURL); WK_EXPORT void WKIconDatabaseSetIconDataForIconURL(WKIconDatabaseRef iconDatabase, WKDataRef iconData, WKURLRef iconURL); +WK_EXPORT void WKIconDatabaseSetIconURLForPageURL(WKIconDatabaseRef iconDatabase, WKURLRef iconURL, WKURLRef pageURL); +WK_EXPORT WKURLRef WKIconDatabaseCopyIconURLForPageURL(WKIconDatabaseRef iconDatabase, WKURLRef pageURL); +WK_EXPORT WKDataRef WKIconDatabaseCopyIconDataForPageURL(WKIconDatabaseRef iconDatabase, WKURLRef pageURL); + WK_EXPORT void WKIconDatabaseEnableDatabaseCleanup(WKIconDatabaseRef iconDatabase); WK_EXPORT void WKIconDatabaseRemoveAllIcons(WKIconDatabaseRef iconDatabase); diff --git a/Source/WebKit2/UIProcess/API/C/WKInspector.cpp b/Source/WebKit2/UIProcess/API/C/WKInspector.cpp index e638609bb..92c641dbb 100644 --- a/Source/WebKit2/UIProcess/API/C/WKInspector.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKInspector.cpp @@ -26,205 +26,98 @@ #include "config.h" #include "WKInspector.h" +#if !PLATFORM(IOS) + #include "WKAPICast.h" #include "WebInspectorProxy.h" +#include "WebPageProxy.h" using namespace WebKit; WKTypeID WKInspectorGetTypeID() { -#if ENABLE(INSPECTOR) return toAPI(WebInspectorProxy::APIType); -#else - return 0; -#endif } WKPageRef WKInspectorGetPage(WKInspectorRef inspectorRef) { -#if ENABLE(INSPECTOR) - return toAPI(toImpl(inspectorRef)->page()); -#else - UNUSED_PARAM(inspectorRef); - return 0; -#endif + return toAPI(toImpl(inspectorRef)->inspectedPage()); } bool WKInspectorIsConnected(WKInspectorRef inspectorRef) { -#if ENABLE(INSPECTOR) return toImpl(inspectorRef)->isConnected(); -#else - UNUSED_PARAM(inspectorRef); - return false; -#endif } bool WKInspectorIsVisible(WKInspectorRef inspectorRef) { -#if ENABLE(INSPECTOR) return toImpl(inspectorRef)->isVisible(); -#else - UNUSED_PARAM(inspectorRef); - return false; -#endif } bool WKInspectorIsFront(WKInspectorRef inspectorRef) { -#if ENABLE(INSPECTOR) return toImpl(inspectorRef)->isFront(); -#else - UNUSED_PARAM(inspectorRef); - return false; -#endif } void WKInspectorConnect(WKInspectorRef inspectorRef) { -#if ENABLE(INSPECTOR) toImpl(inspectorRef)->connect(); -#else - UNUSED_PARAM(inspectorRef); -#endif } void WKInspectorShow(WKInspectorRef inspectorRef) { -#if ENABLE(INSPECTOR) toImpl(inspectorRef)->show(); -#else - UNUSED_PARAM(inspectorRef); -#endif } void WKInspectorHide(WKInspectorRef inspectorRef) { -#if ENABLE(INSPECTOR) toImpl(inspectorRef)->hide(); -#else - UNUSED_PARAM(inspectorRef); -#endif } void WKInspectorClose(WKInspectorRef inspectorRef) { -#if ENABLE(INSPECTOR) toImpl(inspectorRef)->close(); -#else - UNUSED_PARAM(inspectorRef); -#endif } void WKInspectorShowConsole(WKInspectorRef inspectorRef) { -#if ENABLE(INSPECTOR) toImpl(inspectorRef)->showConsole(); -#else - UNUSED_PARAM(inspectorRef); -#endif } void WKInspectorShowResources(WKInspectorRef inspectorRef) { -#if ENABLE(INSPECTOR) toImpl(inspectorRef)->showResources(); -#else - UNUSED_PARAM(inspectorRef); -#endif } void WKInspectorShowMainResourceForFrame(WKInspectorRef inspectorRef, WKFrameRef frameRef) { -#if ENABLE(INSPECTOR) toImpl(inspectorRef)->showMainResourceForFrame(toImpl(frameRef)); -#else - UNUSED_PARAM(inspectorRef); - UNUSED_PARAM(frameRef); -#endif } bool WKInspectorIsAttached(WKInspectorRef inspectorRef) { -#if ENABLE(INSPECTOR) return toImpl(inspectorRef)->isAttached(); -#else - UNUSED_PARAM(inspectorRef); - return false; -#endif } void WKInspectorAttach(WKInspectorRef inspectorRef) { -#if ENABLE(INSPECTOR) - toImpl(inspectorRef)->attach(); -#else - UNUSED_PARAM(inspectorRef); -#endif + auto inspector = toImpl(inspectorRef); + inspector->attach(inspector->attachmentSide()); } void WKInspectorDetach(WKInspectorRef inspectorRef) { -#if ENABLE(INSPECTOR) toImpl(inspectorRef)->detach(); -#else - UNUSED_PARAM(inspectorRef); -#endif -} - -bool WKInspectorIsDebuggingJavaScript(WKInspectorRef inspectorRef) -{ -#if ENABLE(INSPECTOR) - return toImpl(inspectorRef)->isDebuggingJavaScript(); -#else - UNUSED_PARAM(inspectorRef); - return false; -#endif -} - -void WKInspectorToggleJavaScriptDebugging(WKInspectorRef inspectorRef) -{ -#if ENABLE(INSPECTOR) - toImpl(inspectorRef)->toggleJavaScriptDebugging(); -#else - UNUSED_PARAM(inspectorRef); -#endif -} - -bool WKInspectorIsProfilingJavaScript(WKInspectorRef inspectorRef) -{ -#if ENABLE(INSPECTOR) - return toImpl(inspectorRef)->isProfilingJavaScript(); -#else - UNUSED_PARAM(inspectorRef); - return false; -#endif -} - -void WKInspectorToggleJavaScriptProfiling(WKInspectorRef inspectorRef) -{ -#if ENABLE(INSPECTOR) - toImpl(inspectorRef)->toggleJavaScriptProfiling(); -#else - UNUSED_PARAM(inspectorRef); -#endif } bool WKInspectorIsProfilingPage(WKInspectorRef inspectorRef) { -#if ENABLE(INSPECTOR) return toImpl(inspectorRef)->isProfilingPage(); -#else - UNUSED_PARAM(inspectorRef); - return false; -#endif } void WKInspectorTogglePageProfiling(WKInspectorRef inspectorRef) { -#if ENABLE(INSPECTOR) toImpl(inspectorRef)->togglePageProfiling(); -#else - UNUSED_PARAM(inspectorRef); -#endif } + +#endif // !PLATFORM(IOS) diff --git a/Source/WebKit2/UIProcess/API/C/WKInspector.h b/Source/WebKit2/UIProcess/API/C/WKInspector.h index 203e1b3cf..14654fcd4 100644 --- a/Source/WebKit2/UIProcess/API/C/WKInspector.h +++ b/Source/WebKit2/UIProcess/API/C/WKInspector.h @@ -26,7 +26,7 @@ #ifndef WKInspector_h #define WKInspector_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifndef __cplusplus #include <stdbool.h> @@ -58,12 +58,6 @@ WK_EXPORT bool WKInspectorIsAttached(WKInspectorRef inspector); WK_EXPORT void WKInspectorAttach(WKInspectorRef inspector); WK_EXPORT void WKInspectorDetach(WKInspectorRef inspector); -WK_EXPORT bool WKInspectorIsDebuggingJavaScript(WKInspectorRef inspector); -WK_EXPORT void WKInspectorToggleJavaScriptDebugging(WKInspectorRef inspector); - -WK_EXPORT bool WKInspectorIsProfilingJavaScript(WKInspectorRef inspector); -WK_EXPORT void WKInspectorToggleJavaScriptProfiling(WKInspectorRef inspector); - WK_EXPORT bool WKInspectorIsProfilingPage(WKInspectorRef inspector); WK_EXPORT void WKInspectorTogglePageProfiling(WKInspectorRef inspector); diff --git a/Source/WebKit2/UIProcess/API/C/WKKeyValueStorageManager.cpp b/Source/WebKit2/UIProcess/API/C/WKKeyValueStorageManager.cpp index d33c056bf..e412511f6 100644 --- a/Source/WebKit2/UIProcess/API/C/WKKeyValueStorageManager.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKKeyValueStorageManager.cpp @@ -26,27 +26,106 @@ #include "config.h" #include "WKKeyValueStorageManager.h" +#include "APIDictionary.h" +#include "APIWebsiteDataStore.h" +#include "StorageManager.h" #include "WKAPICast.h" -#include "WebKeyValueStorageManager.h" +#include "WebsiteDataStore.h" +#include <wtf/RunLoop.h> using namespace WebKit; WKTypeID WKKeyValueStorageManagerGetTypeID() { - return toAPI(WebKeyValueStorageManager::APIType); + return toAPI(API::WebsiteDataStore::APIType); } -void WKKeyValueStorageManagerGetKeyValueStorageOrigins(WKKeyValueStorageManagerRef keyValueStorageManagerRef, void* context, WKKeyValueStorageManagerGetKeyValueStorageOriginsFunction callback) +WKStringRef WKKeyValueStorageManagerGetOriginKey() { - toImpl(keyValueStorageManagerRef)->getKeyValueStorageOrigins(ArrayCallback::create(context, callback)); + static API::String& key = API::String::create("WebKeyValueStorageManagerStorageDetailsOriginKey").leakRef(); + return toAPI(&key); } -void WKKeyValueStorageManagerDeleteEntriesForOrigin(WKKeyValueStorageManagerRef keyValueStorageManagerRef, WKSecurityOriginRef originRef) +WKStringRef WKKeyValueStorageManagerGetCreationTimeKey() { - toImpl(keyValueStorageManagerRef)->deleteEntriesForOrigin(toImpl(originRef)); + static API::String& key = API::String::create("WebKeyValueStorageManagerStorageDetailsCreationTimeKey").leakRef(); + return toAPI(&key); } -void WKKeyValueStorageManagerDeleteAllEntries(WKKeyValueStorageManagerRef keyValueStorageManagerRef) +WKStringRef WKKeyValueStorageManagerGetModificationTimeKey() { - toImpl(keyValueStorageManagerRef)->deleteAllEntries(); + static API::String& key = API::String::create("WebKeyValueStorageManagerStorageDetailsModificationTimeKey").leakRef(); + return toAPI(&key); +} + +void WKKeyValueStorageManagerGetKeyValueStorageOrigins(WKKeyValueStorageManagerRef keyValueStorageManager, void* context, WKKeyValueStorageManagerGetKeyValueStorageOriginsFunction callback) + +{ + StorageManager* storageManager = toImpl(reinterpret_cast<WKWebsiteDataStoreRef>(keyValueStorageManager))->websiteDataStore().storageManager(); + if (!storageManager) { + RunLoop::main().dispatch([context, callback] { + callback(toAPI(API::Array::create().ptr()), nullptr, context); + }); + return; + } + + storageManager->getLocalStorageOrigins([context, callback](HashSet<RefPtr<WebCore::SecurityOrigin>>&& securityOrigins) { + Vector<RefPtr<API::Object>> webSecurityOrigins; + webSecurityOrigins.reserveInitialCapacity(securityOrigins.size()); + for (auto& origin : securityOrigins) + webSecurityOrigins.uncheckedAppend(API::SecurityOrigin::create(*origin)); + + callback(toAPI(API::Array::create(WTFMove(webSecurityOrigins)).ptr()), nullptr, context); + }); +} + +void WKKeyValueStorageManagerGetStorageDetailsByOrigin(WKKeyValueStorageManagerRef keyValueStorageManager, void* context, WKKeyValueStorageManagerGetStorageDetailsByOriginFunction callback) +{ + StorageManager* storageManager = toImpl(reinterpret_cast<WKWebsiteDataStoreRef>(keyValueStorageManager))->websiteDataStore().storageManager(); + if (!storageManager) { + RunLoop::main().dispatch([context, callback] { + callback(toAPI(API::Array::create().ptr()), nullptr, context); + }); + return; + } + + storageManager->getLocalStorageOriginDetails([context, callback](Vector<LocalStorageDatabaseTracker::OriginDetails> storageDetails) { + HashMap<String, RefPtr<API::Object>> detailsMap; + Vector<RefPtr<API::Object>> result; + result.reserveInitialCapacity(storageDetails.size()); + + for (const auto& originDetails : storageDetails) { + HashMap<String, RefPtr<API::Object>> detailsMap; + + RefPtr<API::Object> origin = API::SecurityOrigin::create(WebCore::SecurityOrigin::createFromDatabaseIdentifier(originDetails.originIdentifier)); + + detailsMap.set(toImpl(WKKeyValueStorageManagerGetOriginKey())->string(), origin); + if (originDetails.creationTime) + detailsMap.set(toImpl(WKKeyValueStorageManagerGetCreationTimeKey())->string(), API::Double::create(originDetails.creationTime.valueOr(0))); + if (originDetails.modificationTime) + detailsMap.set(toImpl(WKKeyValueStorageManagerGetModificationTimeKey())->string(), API::Double::create(originDetails.modificationTime.valueOr(0))); + + result.uncheckedAppend(API::Dictionary::create(WTFMove(detailsMap))); + } + + callback(toAPI(API::Array::create(WTFMove(result)).ptr()), nullptr, context); + }); +} + +void WKKeyValueStorageManagerDeleteEntriesForOrigin(WKKeyValueStorageManagerRef keyValueStorageManager, WKSecurityOriginRef origin) +{ + StorageManager* storageManager = toImpl(reinterpret_cast<WKWebsiteDataStoreRef>(keyValueStorageManager))->websiteDataStore().storageManager(); + if (!storageManager) + return; + + storageManager->deleteLocalStorageEntriesForOrigin(toImpl(origin)->securityOrigin()); +} + +void WKKeyValueStorageManagerDeleteAllEntries(WKKeyValueStorageManagerRef keyValueStorageManager) +{ + StorageManager* storageManager = toImpl(reinterpret_cast<WKWebsiteDataStoreRef>(keyValueStorageManager))->websiteDataStore().storageManager(); + if (!storageManager) + return; + + storageManager->deleteLocalStorageOriginsModifiedSince(std::chrono::system_clock::time_point::min(), [] { }); } diff --git a/Source/WebKit2/UIProcess/API/C/WKKeyValueStorageManager.h b/Source/WebKit2/UIProcess/API/C/WKKeyValueStorageManager.h index a0ee27825..d92adadad 100644 --- a/Source/WebKit2/UIProcess/API/C/WKKeyValueStorageManager.h +++ b/Source/WebKit2/UIProcess/API/C/WKKeyValueStorageManager.h @@ -26,7 +26,7 @@ #ifndef WKKeyValueStorageManager_h #define WKKeyValueStorageManager_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { @@ -34,9 +34,21 @@ extern "C" { WK_EXPORT WKTypeID WKKeyValueStorageManagerGetTypeID(); +/* Value type: WKSecurityOriginRef */ +WK_EXPORT WKStringRef WKKeyValueStorageManagerGetOriginKey(); + +/* Value type: WKDoubleRef, seconds since January 1st, 1970 UTC */ +WK_EXPORT WKStringRef WKKeyValueStorageManagerGetCreationTimeKey(); + +/* Value type: WKDoubleRef, seconds since January 1st, 1970 UTC */ +WK_EXPORT WKStringRef WKKeyValueStorageManagerGetModificationTimeKey(); + typedef void (*WKKeyValueStorageManagerGetKeyValueStorageOriginsFunction)(WKArrayRef, WKErrorRef, void*); WK_EXPORT void WKKeyValueStorageManagerGetKeyValueStorageOrigins(WKKeyValueStorageManagerRef keyValueStorageManager, void* context, WKKeyValueStorageManagerGetKeyValueStorageOriginsFunction function); +typedef void (*WKKeyValueStorageManagerGetStorageDetailsByOriginFunction)(WKArrayRef, WKErrorRef, void*); +WK_EXPORT void WKKeyValueStorageManagerGetStorageDetailsByOrigin(WKKeyValueStorageManagerRef keyValueStorageManager, void* context, WKKeyValueStorageManagerGetStorageDetailsByOriginFunction function); + WK_EXPORT void WKKeyValueStorageManagerDeleteEntriesForOrigin(WKKeyValueStorageManagerRef keyValueStorageManager, WKSecurityOriginRef origin); WK_EXPORT void WKKeyValueStorageManagerDeleteAllEntries(WKKeyValueStorageManagerRef keyValueStorageManager); diff --git a/Source/WebKit2/UIProcess/API/C/WKLayoutMode.h b/Source/WebKit2/UIProcess/API/C/WKLayoutMode.h new file mode 100644 index 000000000..bb75f17f9 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKLayoutMode.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKLayoutMode_h +#define WKLayoutMode_h + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +enum { + kWKLayoutModeViewSize = 0, + kWKLayoutModeFixedSize = 1, + kWKLayoutModeDynamicSizeComputedFromViewScale = 2, + kWKLayoutModeDynamicSizeComputedFromMinimumDocumentSize = 4 +}; +typedef uint32_t WKLayoutMode; + +#ifdef __cplusplus +} +#endif + +#endif /* WKLayoutMode_h */ diff --git a/Source/WebKit2/UIProcess/API/C/WKNetworkInfoManager.cpp b/Source/WebKit2/UIProcess/API/C/WKMediaSessionFocusManager.cpp index 6c278a8d9..9603bf072 100644 --- a/Source/WebKit2/UIProcess/API/C/WKNetworkInfoManager.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKMediaSessionFocusManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Intel Corporation. All rights reserved. + * Copyright (C) 2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -24,39 +24,49 @@ */ #include "config.h" -#include "WKNetworkInfoManager.h" +#include "WKMediaSessionFocusManager.h" #include "WKAPICast.h" -#include "WebNetworkInfoManagerProxy.h" +#include "WebMediaSessionFocusManager.h" using namespace WebKit; -WKTypeID WKNetworkInfoManagerGetTypeID() +WKTypeID WKMediaSessionFocusManagerGetTypeID() { -#if ENABLE(NETWORK_INFO) - return toAPI(WebNetworkInfoManagerProxy::APIType); +#if ENABLE(MEDIA_SESSION) + return toAPI(WebMediaSessionFocusManager::APIType); #else - return 0; + return toAPI(API::Object::Type::Null); #endif } -void WKNetworkInfoManagerSetProvider(WKNetworkInfoManagerRef networkInfoManager, const WKNetworkInfoProviderBase* provider) +void WKMediaSessionFocusManagerSetClient(WKMediaSessionFocusManagerRef manager, const WKMediaSessionFocusManagerClientBase* client) { -#if ENABLE(NETWORK_INFO) - toImpl(networkInfoManager)->initializeProvider(provider); +#if ENABLE(MEDIA_SESSION) + toImpl(manager)->initializeClient(client); #else - UNUSED_PARAM(networkInfoManager); - UNUSED_PARAM(provider); + UNUSED_PARAM(manager); + UNUSED_PARAM(client); #endif } -void WKNetworkInfoManagerProviderDidChangeNetworkInformation(WKNetworkInfoManagerRef networkInfoManager, WKStringRef eventType, WKNetworkInfoRef networkInfo) +bool WKMediaSessionFocusManagerValueForPlaybackAttribute(WKMediaSessionFocusManagerRef manager, WKMediaSessionFocusManagerPlaybackAttribute attribute) { -#if ENABLE(NETWORK_INFO) - toImpl(networkInfoManager)->providerDidChangeNetworkInformation(AtomicString(toImpl(eventType)->string()), toImpl(networkInfo)); +#if ENABLE(MEDIA_SESSION) + return toImpl(manager)->valueForPlaybackAttribute(attribute); #else - UNUSED_PARAM(networkInfoManager); - UNUSED_PARAM(eventType); - UNUSED_PARAM(networkInfo); + UNUSED_PARAM(manager); + UNUSED_PARAM(attribute); + return false; +#endif +} + +void WKMediaSessionFocusManagerSetVolumeOfFocusedMediaElement(WKMediaSessionFocusManagerRef manager, double volume) +{ +#if ENABLE(MEDIA_SESSION) + toImpl(manager)->setVolumeOfFocusedMediaElement(volume); +#else + UNUSED_PARAM(manager); + UNUSED_PARAM(volume); #endif } diff --git a/Source/WebKit2/UIProcess/API/C/WKMediaSessionFocusManager.h b/Source/WebKit2/UIProcess/API/C/WKMediaSessionFocusManager.h new file mode 100644 index 000000000..ed39e705a --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKMediaSessionFocusManager.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKMediaSessionFocusManager_h +#define WKMediaSessionFocusManager_h + +#include <WebKit/WKBase.h> + +#ifndef __cplusplus +#include <stdbool.h> +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +enum WKMediaSessionFocusManagerPlaybackAttribute { + IsPlaying = 1 << 0, + IsPreviousTrackControlEnabled = 1 << 1, + IsNextTrackControlEnabled = 1 << 2, +}; +typedef uint32_t WKMediaSessionFocusManagerPlaybackAttributes; + +// Media Session Focus Manager Client +typedef void (*WKMediaSessionFocusManagerDidChangePlaybackAttribute)(WKMediaSessionFocusManagerRef manager, WKMediaSessionFocusManagerPlaybackAttribute playbackAttribute, bool value, const void *clientInfo); + +typedef struct WKMediaSessionFocusManagerClientBase { + int version; + const void * clientInfo; +} WKMediaSessionFocusManagerClientBase; + +typedef struct WKMediaSessionFocusManagerClientV0 { + WKMediaSessionFocusManagerClientBase base; + + // Version 0. + WKMediaSessionFocusManagerDidChangePlaybackAttribute didChangePlaybackAttribute; +} WKMediaSessionFocusManagerClientV0; + +WK_EXPORT WKTypeID WKMediaSessionFocusManagerGetTypeID(); + +WK_EXPORT void WKMediaSessionFocusManagerSetClient(WKMediaSessionFocusManagerRef manager, const WKMediaSessionFocusManagerClientBase* client); + +WK_EXPORT bool WKMediaSessionFocusManagerValueForPlaybackAttribute(WKMediaSessionFocusManagerRef, WKMediaSessionFocusManagerPlaybackAttribute); +WK_EXPORT void WKMediaSessionFocusManagerSetVolumeOfFocusedMediaElement(WKMediaSessionFocusManagerRef, double); + +#ifdef __cplusplus +} +#endif + +#endif /* WKMediaSessionFocusManager_h */ diff --git a/Source/WebKit2/UIProcess/API/C/WKMediaSessionMetadata.cpp b/Source/WebKit2/UIProcess/API/C/WKMediaSessionMetadata.cpp new file mode 100644 index 000000000..330ca53aa --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKMediaSessionMetadata.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKMediaSessionMetadata.h" + +#include "WKAPICast.h" +#include "WebMediaSessionMetadata.h" + +using namespace WebKit; + +WKTypeID WKMediaSessionMetadataGetTypeID() +{ +#if ENABLE(MEDIA_SESSION) + return toAPI(WebMediaSessionMetadata::APIType); +#else + return toAPI(API::Object::Type::Null); +#endif +} + +WKStringRef WKMediaSessionMetadataCopyTitle(WKMediaSessionMetadataRef metadata) +{ +#if ENABLE(MEDIA_SESSION) + return toCopiedAPI(toImpl(metadata)->title()); +#else + UNUSED_PARAM(metadata); + return nullptr; +#endif +} + +WKStringRef WKMediaSessionMetadataCopyArtist(WKMediaSessionMetadataRef metadata) +{ +#if ENABLE(MEDIA_SESSION) + return toCopiedAPI(toImpl(metadata)->artist()); +#else + UNUSED_PARAM(metadata); + return nullptr; +#endif +} + +WKStringRef WKMediaSessionMetadataCopyAlbum(WKMediaSessionMetadataRef metadata) +{ +#if ENABLE(MEDIA_SESSION) + return toCopiedAPI(toImpl(metadata)->album()); +#else + UNUSED_PARAM(metadata); + return nullptr; +#endif +} + +WKURLRef WKMediaSessionMetadataCopyArtworkURL(WKMediaSessionMetadataRef metadata) +{ +#if ENABLE(MEDIA_SESSION) + return toCopiedURLAPI(toImpl(metadata)->artworkURL()); +#else + UNUSED_PARAM(metadata); + return nullptr; +#endif +} diff --git a/Source/WebKit2/UIProcess/API/C/WKMediaCacheManager.h b/Source/WebKit2/UIProcess/API/C/WKMediaSessionMetadata.h index eee1b9291..b9430f7e4 100644 --- a/Source/WebKit2/UIProcess/API/C/WKMediaCacheManager.h +++ b/Source/WebKit2/UIProcess/API/C/WKMediaSessionMetadata.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 Apple Inc. All rights reserved. + * Copyright (C) 2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -23,25 +23,28 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef WKMediaCacheManager_h -#define WKMediaCacheManager_h +#ifndef WKMediaSessionMetadata_h +#define WKMediaSessionMetadata_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> + +#ifndef __cplusplus +#include <stdbool.h> +#endif #ifdef __cplusplus extern "C" { #endif -WK_EXPORT WKTypeID WKMediaCacheManagerGetTypeID(); - -typedef void (*WKMediaCacheManagerGetHostnamesWithMediaCacheFunction)(WKArrayRef, WKErrorRef, void*); -WK_EXPORT void WKMediaCacheManagerGetHostnamesWithMediaCache(WKMediaCacheManagerRef mediaCacheManager, void* context, WKMediaCacheManagerGetHostnamesWithMediaCacheFunction function); +WK_EXPORT WKTypeID WKMediaSessionMetadataGetTypeID(); -WK_EXPORT void WKMediaCacheManagerClearCacheForHostname(WKMediaCacheManagerRef mediaCacheManager, WKStringRef hostname); -WK_EXPORT void WKMediaCacheManagerClearCacheForAllHostnames(WKMediaCacheManagerRef mediaCacheManager); +WK_EXPORT WKStringRef WKMediaSessionMetadataCopyTitle(WKMediaSessionMetadataRef metadata); +WK_EXPORT WKStringRef WKMediaSessionMetadataCopyArtist(WKMediaSessionMetadataRef metadata); +WK_EXPORT WKStringRef WKMediaSessionMetadataCopyAlbum(WKMediaSessionMetadataRef metadata); +WK_EXPORT WKURLRef WKMediaSessionMetadataCopyArtworkURL(WKMediaSessionMetadataRef metadata); #ifdef __cplusplus } #endif -#endif // WKMediaCacheManager_h +#endif /* WKMediaSessionMetadata_h */ diff --git a/Source/WebKit2/UIProcess/API/C/WKNativeEvent.h b/Source/WebKit2/UIProcess/API/C/WKNativeEvent.h index 349582628..7d8b6b9dc 100644 --- a/Source/WebKit2/UIProcess/API/C/WKNativeEvent.h +++ b/Source/WebKit2/UIProcess/API/C/WKNativeEvent.h @@ -34,7 +34,7 @@ extern "C" { #endif -#if defined(__APPLE__) && !TARGET_OS_IPHONE +#if defined(__APPLE__) && !TARGET_OS_IPHONE && !defined(BUILDING_GTK__) #ifdef __OBJC__ @class NSEvent; #elif __cplusplus diff --git a/Source/WebKit2/UIProcess/API/C/WKNavigationActionRef.cpp b/Source/WebKit2/UIProcess/API/C/WKNavigationActionRef.cpp new file mode 100644 index 000000000..14a235157 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKNavigationActionRef.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKNavigationActionRef.h" + +#include "APINavigationAction.h" +#include "WKAPICast.h" + +using namespace WebKit; + +WKTypeID WKNavigationActionGetTypeID() +{ + return toAPI(API::NavigationAction::APIType); +} diff --git a/Source/WebKit2/UIProcess/API/C/WKNetworkInfo.h b/Source/WebKit2/UIProcess/API/C/WKNavigationActionRef.h index cff864a75..5691eabcd 100644 --- a/Source/WebKit2/UIProcess/API/C/WKNetworkInfo.h +++ b/Source/WebKit2/UIProcess/API/C/WKNavigationActionRef.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Intel Corporation. All rights reserved. + * Copyright (C) 2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -23,21 +23,19 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef WKNetworkInfo_h -#define WKNetworkInfo_h +#ifndef WKNavigationActionRef_h +#define WKNavigationActionRef_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { #endif -WK_EXPORT WKTypeID WKNetworkInfoGetTypeID(); - -WK_EXPORT WKNetworkInfoRef WKNetworkInfoCreate(double bandwidth, bool isMetered); +WK_EXPORT WKTypeID WKNavigationActionGetTypeID(); #ifdef __cplusplus } #endif -#endif // WKNetworkInfo_h +#endif // WKNavigationActionRef_h diff --git a/Source/WebKit2/UIProcess/API/C/WKNavigationDataRef.cpp b/Source/WebKit2/UIProcess/API/C/WKNavigationDataRef.cpp index 86840e33e..0a815bb82 100644 --- a/Source/WebKit2/UIProcess/API/C/WKNavigationDataRef.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKNavigationDataRef.cpp @@ -55,5 +55,5 @@ WKURLRef WKNavigationDataCopyNavigationDestinationURL(WKNavigationDataRef naviga WKURLRequestRef WKNavigationDataCopyOriginalRequest(WKNavigationDataRef navigationData) { - return toAPI(API::URLRequest::create(toImpl(navigationData)->originalRequest()).leakRef()); + return toAPI(&API::URLRequest::create(toImpl(navigationData)->originalRequest()).leakRef()); } diff --git a/Source/WebKit2/UIProcess/API/C/WKNavigationDataRef.h b/Source/WebKit2/UIProcess/API/C/WKNavigationDataRef.h index 8d70b76fa..b2c5f5b2b 100644 --- a/Source/WebKit2/UIProcess/API/C/WKNavigationDataRef.h +++ b/Source/WebKit2/UIProcess/API/C/WKNavigationDataRef.h @@ -26,7 +26,7 @@ #ifndef WKNavigationDataRef_h #define WKNavigationDataRef_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/WKNavigationRef.cpp b/Source/WebKit2/UIProcess/API/C/WKNavigationRef.cpp new file mode 100644 index 000000000..591c14660 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKNavigationRef.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKNavigationRef.h" + +#include "APINavigation.h" +#include "WKAPICast.h" + +using namespace WebKit; + +WKTypeID WKNavigationGetTypeID() +{ + return toAPI(API::Navigation::APIType); +} diff --git a/Source/WebKit2/UIProcess/API/C/WKNavigationRef.h b/Source/WebKit2/UIProcess/API/C/WKNavigationRef.h new file mode 100644 index 000000000..ae9a19074 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKNavigationRef.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKNavigationRef_h +#define WKNavigationRef_h + +#include <WebKit/WKBase.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKTypeID WKNavigationGetTypeID(); + +#ifdef __cplusplus +} +#endif + +#endif // WKNavigationRef_h diff --git a/Source/WebKit2/UIProcess/API/C/WKNavigationResponseRef.cpp b/Source/WebKit2/UIProcess/API/C/WKNavigationResponseRef.cpp new file mode 100644 index 000000000..ed6f21b0f --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKNavigationResponseRef.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKNavigationResponseRef.h" + +#include "APINavigationResponse.h" +#include "WKAPICast.h" + +using namespace WebKit; + +WKTypeID WKNavigationResponseGetTypeID() +{ + return toAPI(API::NavigationResponse::APIType); +} + +bool WKNavigationResponseCanShowMIMEType(WKNavigationResponseRef response) +{ + return toImpl(response)->canShowMIMEType(); +} diff --git a/Source/WebKit2/UIProcess/API/C/WKNavigationResponseRef.h b/Source/WebKit2/UIProcess/API/C/WKNavigationResponseRef.h new file mode 100644 index 000000000..c82b14dc3 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKNavigationResponseRef.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKNavigationResponseRef_h +#define WKNavigationResponseRef_h + +#include <WebKit/WKBase.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKTypeID WKNavigationResponseGetTypeID(); + +WK_EXPORT bool WKNavigationResponseCanShowMIMEType(WKNavigationResponseRef); + +#ifdef __cplusplus +} +#endif + +#endif // WKNavigationResponseRef_h diff --git a/Source/WebKit2/UIProcess/API/C/WKNetworkInfoManager.h b/Source/WebKit2/UIProcess/API/C/WKNetworkInfoManager.h deleted file mode 100644 index e3bdca671..000000000 --- a/Source/WebKit2/UIProcess/API/C/WKNetworkInfoManager.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2012 Intel Corporation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef WKNetworkInfoManager_h -#define WKNetworkInfoManager_h - -#include <WebKit2/WKBase.h> - -#ifdef __cplusplus -extern "C" { -#endif - -// Provider. -typedef void (*WKNetworkInfoProviderStartUpdatingCallback)(WKNetworkInfoManagerRef networkInfoManager, const void* clientInfo); -typedef void (*WKNetworkInfoProviderStopUpdatingCallback)(WKNetworkInfoManagerRef networkInfoManager, const void* clientInfo); -typedef double (*WKNetworkInfoProviderGetBandwidthCallback)(WKNetworkInfoManagerRef networkInfoManager, const void* clientInfo); -typedef bool (*WKNetworkInfoProviderIsMeteredCallback)(WKNetworkInfoManagerRef networkInfoManager, const void* clientInfo); - -typedef struct WKNetworkInfoProviderBase { - int version; - const void * clientInfo; -} WKNetworkInfoProviderBase; - -typedef struct WKNetworkInfoProvider { - WKNetworkInfoProviderBase base; - - WKNetworkInfoProviderStartUpdatingCallback startUpdating; - WKNetworkInfoProviderStopUpdatingCallback stopUpdating; - WKNetworkInfoProviderGetBandwidthCallback bandwidth; - WKNetworkInfoProviderIsMeteredCallback isMetered; -} WKNetworkInfoProviderV0; - -WK_EXPORT WKTypeID WKNetworkInfoManagerGetTypeID(); - -WK_EXPORT void WKNetworkInfoManagerSetProvider(WKNetworkInfoManagerRef networkInfoManager, const WKNetworkInfoProviderBase* provider); - -WK_EXPORT void WKNetworkInfoManagerProviderDidChangeNetworkInformation(WKNetworkInfoManagerRef networkInfoManager, WKStringRef eventType, WKNetworkInfoRef networkInfo); - -#ifdef __cplusplus -} -#endif - -#endif // WKNetworkInfoManager_h diff --git a/Source/WebKit2/UIProcess/API/C/WKNotification.cpp b/Source/WebKit2/UIProcess/API/C/WKNotification.cpp index 78b09e09e..3d1805730 100644 --- a/Source/WebKit2/UIProcess/API/C/WKNotification.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKNotification.cpp @@ -26,9 +26,9 @@ #include "config.h" #include "WKNotification.h" +#include "APISecurityOrigin.h" #include "WKAPICast.h" #include "WebNotification.h" -#include "WebSecurityOrigin.h" using namespace WebKit; diff --git a/Source/WebKit2/UIProcess/API/C/WKNotification.h b/Source/WebKit2/UIProcess/API/C/WKNotification.h index 7035ef3f8..d3ae98bf7 100644 --- a/Source/WebKit2/UIProcess/API/C/WKNotification.h +++ b/Source/WebKit2/UIProcess/API/C/WKNotification.h @@ -26,7 +26,7 @@ #ifndef WKNotification_h #define WKNotification_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/WKNotificationManager.h b/Source/WebKit2/UIProcess/API/C/WKNotificationManager.h index 50f50d747..cb88036bc 100644 --- a/Source/WebKit2/UIProcess/API/C/WKNotificationManager.h +++ b/Source/WebKit2/UIProcess/API/C/WKNotificationManager.h @@ -27,7 +27,7 @@ #define WKNotificationManager_h #include "WKNotificationProvider.h" -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/WKNotificationPermissionRequest.h b/Source/WebKit2/UIProcess/API/C/WKNotificationPermissionRequest.h index 1947a06aa..02be0e63c 100644 --- a/Source/WebKit2/UIProcess/API/C/WKNotificationPermissionRequest.h +++ b/Source/WebKit2/UIProcess/API/C/WKNotificationPermissionRequest.h @@ -26,7 +26,7 @@ #ifndef WKNotificationPermissionRequest_h #define WKNotificationPermissionRequest_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/WKNotificationProvider.h b/Source/WebKit2/UIProcess/API/C/WKNotificationProvider.h index 920e297b3..8a416c57c 100644 --- a/Source/WebKit2/UIProcess/API/C/WKNotificationProvider.h +++ b/Source/WebKit2/UIProcess/API/C/WKNotificationProvider.h @@ -26,7 +26,7 @@ #ifndef WKNotificationProvider_h #define WKNotificationProvider_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { @@ -58,21 +58,6 @@ typedef struct WKNotificationProviderV0 { WKNotificationProviderClearNotificationsCallback clearNotifications; } WKNotificationProviderV0; -enum { kWKNotificationProviderCurrentVersion WK_ENUM_DEPRECATED("Use an explicit version number instead") = 0, }; -typedef struct WKNotificationProvider { - int version; - const void* clientInfo; - - // Version 0. - WKNotificationProviderShowCallback show; - WKNotificationProviderCancelCallback cancel; - WKNotificationProviderDidDestroyNotificationCallback didDestroyNotification; - WKNotificationProviderAddNotificationManagerCallback addNotificationManager; - WKNotificationProviderRemoveNotificationManagerCallback removeNotificationManager; - WKNotificationProviderNotificationPermissionsCallback notificationPermissions; - WKNotificationProviderClearNotificationsCallback clearNotifications; -} WKNotificationProvider WK_DEPRECATED("Use an explicit versioned struct instead"); - #ifdef __cplusplus } #endif diff --git a/Source/WebKit2/UIProcess/API/C/WKOpenPanelParameters.cpp b/Source/WebKit2/UIProcess/API/C/WKOpenPanelParameters.cpp index aa3e0b58a..8370a6ffd 100644 --- a/Source/WebKit2/UIProcess/API/C/WKOpenPanelParameters.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKOpenPanelParameters.cpp @@ -45,20 +45,26 @@ bool WKOpenPanelParametersGetAllowsMultipleFiles(WKOpenPanelParametersRef parame WKArrayRef WKOpenPanelParametersCopyAcceptedMIMETypes(WKOpenPanelParametersRef parametersRef) { - return toAPI(toImpl(parametersRef)->acceptMIMETypes().leakRef()); + return toAPI(&toImpl(parametersRef)->acceptMIMETypes().leakRef()); } -WKStringRef WKOpenPanelParametersCopyCapture(WKOpenPanelParametersRef parametersRef) +// Deprecated. +WKStringRef WKOpenPanelParametersCopyCapture(WKOpenPanelParametersRef) +{ + return 0; +} + +bool WKOpenPanelParametersGetCaptureEnabled(WKOpenPanelParametersRef parametersRef) { #if ENABLE(MEDIA_CAPTURE) - return toCopiedAPI(toImpl(parametersRef)->capture()); + return toImpl(parametersRef)->capture(); #else UNUSED_PARAM(parametersRef); - return 0; + return false; #endif } WKArrayRef WKOpenPanelParametersCopySelectedFileNames(WKOpenPanelParametersRef parametersRef) { - return toAPI(toImpl(parametersRef)->selectedFileNames().leakRef()); + return toAPI(&toImpl(parametersRef)->selectedFileNames().leakRef()); } diff --git a/Source/WebKit2/UIProcess/API/C/WKOpenPanelParameters.h b/Source/WebKit2/UIProcess/API/C/WKOpenPanelParameters.h index 3801c2f7b..803bff8b4 100644 --- a/Source/WebKit2/UIProcess/API/C/WKOpenPanelParameters.h +++ b/Source/WebKit2/UIProcess/API/C/WKOpenPanelParameters.h @@ -27,7 +27,7 @@ #ifndef WKOpenPanelParameters_h #define WKOpenPanelParameters_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifndef __cplusplus #include <stdbool.h> @@ -43,8 +43,11 @@ WK_EXPORT bool WKOpenPanelParametersGetAllowsMultipleFiles(WKOpenPanelParameters WK_EXPORT WKArrayRef WKOpenPanelParametersCopyAcceptedMIMETypes(WKOpenPanelParametersRef parameters); +/* DEPRECATED - Please use WKOpenPanelParametersGetCaptureEnabled() instead. */ WK_EXPORT WKStringRef WKOpenPanelParametersCopyCapture(WKOpenPanelParametersRef parameters); +WK_EXPORT bool WKOpenPanelParametersGetCaptureEnabled(WKOpenPanelParametersRef parametersRef); + WK_EXPORT WKArrayRef WKOpenPanelParametersCopySelectedFileNames(WKOpenPanelParametersRef parametersRef); #ifdef __cplusplus diff --git a/Source/WebKit2/UIProcess/API/C/WKOpenPanelResultListener.h b/Source/WebKit2/UIProcess/API/C/WKOpenPanelResultListener.h index d581738a5..21c92ee24 100644 --- a/Source/WebKit2/UIProcess/API/C/WKOpenPanelResultListener.h +++ b/Source/WebKit2/UIProcess/API/C/WKOpenPanelResultListener.h @@ -26,7 +26,7 @@ #ifndef WKOpenPanelResultListener_h #define WKOpenPanelResultListener_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/WKOriginDataManager.cpp b/Source/WebKit2/UIProcess/API/C/WKOriginDataManager.cpp deleted file mode 100644 index 8ab0f37d7..000000000 --- a/Source/WebKit2/UIProcess/API/C/WKOriginDataManager.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2013 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "WKOriginDataManager.h" - -#include "WKAPICast.h" -#include "WebOriginDataManagerProxy.h" - -using namespace WebKit; - -WKTypeID WKOriginDataManagerGetTypeID() -{ - return toAPI(WebOriginDataManagerProxy::APIType); -} - -void WKOriginDataManagerGetOrigins(WKOriginDataManagerRef originDataManagerRef, WKOriginDataTypes types, void* context, WKOriginDataManagerGetOriginsFunction callback) -{ - toImpl(originDataManagerRef)->getOrigins(types, ArrayCallback::create(context, callback)); -} - -void WKOriginDataManagerDeleteEntriesForOrigin(WKOriginDataManagerRef originDataManagerRef, WKOriginDataTypes types, WKSecurityOriginRef originRef) -{ - toImpl(originDataManagerRef)->deleteEntriesForOrigin(types, toImpl(originRef)); -} - -void WKOriginDataManagerDeleteAllEntries(WKOriginDataManagerRef originDataManagerRef, WKOriginDataTypes types) -{ - toImpl(originDataManagerRef)->deleteAllEntries(types); -} - -void WKOriginDataManagerStartObservingChanges(WKOriginDataManagerRef originDataManagerRef, WKOriginDataTypes types) -{ - toImpl(originDataManagerRef)->startObservingChanges(types); -} - -void WKOriginDataManagerStopObservingChanges(WKOriginDataManagerRef originDataManagerRef, WKOriginDataTypes types) -{ - toImpl(originDataManagerRef)->stopObservingChanges(types); -} - -void WKOriginDataManagerSetChangeClient(WKOriginDataManagerRef originDataManagerRef, const WKOriginDataManagerChangeClientBase *client) -{ - toImpl(originDataManagerRef)->setChangeClient(client); -} diff --git a/Source/WebKit2/UIProcess/API/C/WKOriginDataManager.h b/Source/WebKit2/UIProcess/API/C/WKOriginDataManager.h deleted file mode 100644 index f6300593b..000000000 --- a/Source/WebKit2/UIProcess/API/C/WKOriginDataManager.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) 2013 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef WKOriginDataManager_h -#define WKOriginDataManager_h - -#include <WebKit2/WKBase.h> - -#ifdef __cplusplus -extern "C" { -#endif - -enum { - kWKApplicationCacheOriginData = 1 << 0, - kWKCookieOriginData = 1 << 1, - kWKDatabaseOriginData = 1 << 2, - kWKKeyValueStorageOriginData = 1 << 3, - kWKMediaCacheOriginData = 1 << 4, - kWKPluginDataOriginData = 1 << 5, - kWKResourceCacheOriginData = 1 << 6, - - kWKAllOriginData = (1 << 7) - 1 -}; -typedef uint32_t WKOriginDataTypes; - -WK_EXPORT WKTypeID WKOriginDataManagerGetTypeID(); - -typedef void (*WKOriginDataManagerGetOriginsFunction)(WKArrayRef, WKErrorRef, void*); -WK_EXPORT void WKOriginDataManagerGetOrigins(WKOriginDataManagerRef originDataManager, WKOriginDataTypes types, void* context, WKOriginDataManagerGetOriginsFunction function); - -WK_EXPORT void WKOriginDataManagerDeleteEntriesForOrigin(WKOriginDataManagerRef originDataManager, WKOriginDataTypes types, WKSecurityOriginRef origin); -WK_EXPORT void WKOriginDataManagerDeleteAllEntries(WKOriginDataManagerRef originDataManager, WKOriginDataTypes types); - -// OriginDataManager Client -typedef void (*WKOriginDataManagerChangeCallback)(WKOriginDataManagerRef originDataManager, const void *clientInfo); - -typedef struct WKOriginDataManagerChangeClientBase { - const void * clientInfo; - int version; -} WKOriginDataManagerChangeClientBase; - -typedef struct WKOriginDataManagerChangeClientV0 { - WKOriginDataManagerChangeClientBase base; - - // Version 0. - WKOriginDataManagerChangeCallback didChange; -} WKOriginDataManagerChangeClientV0; - -enum { kWKOriginDataManagerChangeClientVersion = 0 }; -typedef struct WKOriginDataManagerChangeClient { - int version; - const void * clientInfo; - - // Version 0. - WKOriginDataManagerChangeCallback didChange; -} WKOriginDataManagerChangeClient WK_DEPRECATED("Use an explicit versioned struct instead"); - -WK_EXPORT void WKOriginDataManagerStartObservingChanges(WKOriginDataManagerRef originDataManager, WKOriginDataTypes types); -WK_EXPORT void WKOriginDataManagerStopObservingChanges(WKOriginDataManagerRef originDataManager, WKOriginDataTypes types); -WK_EXPORT void WKOriginDataManagerSetChangeClient(WKOriginDataManagerRef originDataManger, const WKOriginDataManagerChangeClientBase* client); -#ifdef __cplusplus -} -#endif - -#endif // WKOriginDataManager_h diff --git a/Source/WebKit2/UIProcess/API/C/WKPage.cpp b/Source/WebKit2/UIProcess/API/C/WKPage.cpp index c398b7060..701a4c83b 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPage.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKPage.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2010, 2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,21 +28,50 @@ #include "WKPagePrivate.h" #include "APIArray.h" +#include "APIContextMenuClient.h" #include "APIData.h" +#include "APIDictionary.h" +#include "APIFindClient.h" +#include "APIFindMatchesClient.h" +#include "APIFrameInfo.h" +#include "APIGeometry.h" +#include "APIHitTestResult.h" #include "APILoaderClient.h" +#include "APINavigationAction.h" +#include "APINavigationClient.h" +#include "APINavigationResponse.h" +#include "APIPageConfiguration.h" #include "APIPolicyClient.h" -#include "ImmutableDictionary.h" +#include "APISessionState.h" +#include "APIUIClient.h" +#include "APIWindowFeatures.h" +#include "AuthenticationChallengeProxy.h" +#include "LegacySessionStateCoding.h" +#include "Logging.h" +#include "NativeWebKeyboardEvent.h" +#include "NativeWebWheelEvent.h" #include "NavigationActionData.h" #include "PluginInformation.h" #include "PrintInfo.h" #include "WKAPICast.h" #include "WKPagePolicyClientInternal.h" +#include "WKPageRenderingProgressEventsInternal.h" #include "WKPluginInformation.h" #include "WebBackForwardList.h" +#include "WebFormClient.h" +#include "WebImage.h" +#include "WebInspectorProxy.h" +#include "WebOpenPanelParameters.h" +#include "WebOpenPanelResultListenerProxy.h" +#include "WebPageGroup.h" #include "WebPageMessages.h" #include "WebPageProxy.h" +#include "WebProcessPool.h" #include "WebProcessProxy.h" +#include "WebProtectionSpace.h" #include <WebCore/Page.h> +#include <WebCore/SecurityOriginData.h> +#include <WebCore/WindowFeatures.h> #ifdef __BLOCKS__ #include <Block.h> @@ -52,17 +81,49 @@ #include "WebContextMenuItem.h" #endif +#if ENABLE(VIBRATION) +#include "WebVibrationProxy.h" +#endif + +#if ENABLE(MEDIA_SESSION) +#include "WebMediaSessionMetadata.h" +#include <WebCore/MediaSessionEvents.h> +#endif + using namespace WebCore; using namespace WebKit; namespace API { template<> struct ClientTraits<WKPageLoaderClientBase> { - typedef std::tuple<WKPageLoaderClientV0, WKPageLoaderClientV1, WKPageLoaderClientV2, WKPageLoaderClientV3, WKPageLoaderClientV4> Versions; + typedef std::tuple<WKPageLoaderClientV0, WKPageLoaderClientV1, WKPageLoaderClientV2, WKPageLoaderClientV3, WKPageLoaderClientV4, WKPageLoaderClientV5, WKPageLoaderClientV6> Versions; +}; + +template<> struct ClientTraits<WKPageNavigationClientBase> { + typedef std::tuple<WKPageNavigationClientV0> Versions; }; template<> struct ClientTraits<WKPagePolicyClientBase> { typedef std::tuple<WKPagePolicyClientV0, WKPagePolicyClientV1, WKPagePolicyClientInternal> Versions; }; + +template<> struct ClientTraits<WKPageUIClientBase> { + typedef std::tuple<WKPageUIClientV0, WKPageUIClientV1, WKPageUIClientV2, WKPageUIClientV3, WKPageUIClientV4, WKPageUIClientV5, WKPageUIClientV6, WKPageUIClientV7> Versions; +}; + +#if ENABLE(CONTEXT_MENUS) +template<> struct ClientTraits<WKPageContextMenuClientBase> { + typedef std::tuple<WKPageContextMenuClientV0, WKPageContextMenuClientV1, WKPageContextMenuClientV2, WKPageContextMenuClientV3> Versions; +}; +#endif + +template<> struct ClientTraits<WKPageFindClientBase> { + typedef std::tuple<WKPageFindClientV0> Versions; +}; + +template<> struct ClientTraits<WKPageFindMatchesClientBase> { + typedef std::tuple<WKPageFindMatchesClientV0> Versions; +}; + } WKTypeID WKPageGetTypeID() @@ -72,7 +133,7 @@ WKTypeID WKPageGetTypeID() WKContextRef WKPageGetContext(WKPageRef pageRef) { - return toAPI(&toImpl(pageRef)->process().context()); + return toAPI(&toImpl(pageRef)->process().processPool()); } WKPageGroupRef WKPageGetPageGroup(WKPageRef pageRef) @@ -80,14 +141,25 @@ WKPageGroupRef WKPageGetPageGroup(WKPageRef pageRef) return toAPI(&toImpl(pageRef)->pageGroup()); } +WKPageConfigurationRef WKPageCopyPageConfiguration(WKPageRef pageRef) +{ + return toAPI(&toImpl(pageRef)->configuration().copy().leakRef()); +} + void WKPageLoadURL(WKPageRef pageRef, WKURLRef URLRef) { - toImpl(pageRef)->loadRequest(toWTFString(URLRef)); + toImpl(pageRef)->loadRequest(URL(URL(), toWTFString(URLRef))); +} + +void WKPageLoadURLWithShouldOpenExternalURLsPolicy(WKPageRef pageRef, WKURLRef URLRef, bool shouldOpenExternalURLs) +{ + ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy = shouldOpenExternalURLs ? ShouldOpenExternalURLsPolicy::ShouldAllow : ShouldOpenExternalURLsPolicy::ShouldNotAllow; + toImpl(pageRef)->loadRequest(URL(URL(), toWTFString(URLRef)), shouldOpenExternalURLsPolicy); } void WKPageLoadURLWithUserData(WKPageRef pageRef, WKURLRef URLRef, WKTypeRef userDataRef) { - toImpl(pageRef)->loadRequest(URL(URL(), toWTFString(URLRef)), toImpl(userDataRef)); + toImpl(pageRef)->loadRequest(URL(URL(), toWTFString(URLRef)), ShouldOpenExternalURLsPolicy::ShouldNotAllow, toImpl(userDataRef)); } void WKPageLoadURLRequest(WKPageRef pageRef, WKURLRequestRef urlRequestRef) @@ -97,7 +169,7 @@ void WKPageLoadURLRequest(WKPageRef pageRef, WKURLRequestRef urlRequestRef) void WKPageLoadURLRequestWithUserData(WKPageRef pageRef, WKURLRequestRef urlRequestRef, WKTypeRef userDataRef) { - toImpl(pageRef)->loadRequest(toImpl(urlRequestRef)->resourceRequest(), toImpl(userDataRef)); + toImpl(pageRef)->loadRequest(toImpl(urlRequestRef)->resourceRequest(), ShouldOpenExternalURLsPolicy::ShouldNotAllow, toImpl(userDataRef)); } void WKPageLoadFile(WKPageRef pageRef, WKURLRef fileURL, WKURLRef resourceDirectoryURL) @@ -167,12 +239,23 @@ void WKPageStopLoading(WKPageRef pageRef) void WKPageReload(WKPageRef pageRef) { - toImpl(pageRef)->reload(false); + const bool reloadFromOrigin = false; + const bool contentBlockersEnabled = true; + toImpl(pageRef)->reload(reloadFromOrigin, contentBlockersEnabled); +} + +void WKPageReloadWithoutContentBlockers(WKPageRef pageRef) +{ + const bool reloadFromOrigin = false; + const bool contentBlockersEnabled = false; + toImpl(pageRef)->reload(reloadFromOrigin, contentBlockersEnabled); } void WKPageReloadFromOrigin(WKPageRef pageRef) { - toImpl(pageRef)->reload(true); + const bool reloadFromOrigin = true; + const bool contentBlockersEnabled = true; + toImpl(pageRef)->reload(reloadFromOrigin, contentBlockersEnabled); } bool WKPageTryClose(WKPageRef pageRef) @@ -257,12 +340,7 @@ uint64_t WKPageGetRenderTreeSize(WKPageRef page) WKInspectorRef WKPageGetInspector(WKPageRef pageRef) { -#if defined(ENABLE_INSPECTOR) && ENABLE_INSPECTOR return toAPI(toImpl(pageRef)->inspector()); -#else - UNUSED_PARAM(pageRef); - return 0; -#endif } WKVibrationRef WKPageGetVibration(WKPageRef page) @@ -280,11 +358,6 @@ double WKPageGetEstimatedProgress(WKPageRef pageRef) return toImpl(pageRef)->estimatedProgress(); } -void WKPageSetMemoryCacheClientCallsEnabled(WKPageRef pageRef, bool memoryCacheClientCallsEnabled) -{ - toImpl(pageRef)->setMemoryCacheClientCallsEnabled(memoryCacheClientCallsEnabled); -} - WKStringRef WKPageCopyUserAgent(WKPageRef pageRef) { return toCopiedAPI(toImpl(pageRef)->userAgent()); @@ -310,6 +383,11 @@ void WKPageSetCustomUserAgent(WKPageRef pageRef, WKStringRef userAgentRef) toImpl(pageRef)->setCustomUserAgent(toWTFString(userAgentRef)); } +void WKPageSetUserContentExtensionsEnabled(WKPageRef pageRef, bool enabled) +{ + // FIXME: Remove this function once it is no longer used. +} + bool WKPageSupportsTextEncoding(WKPageRef pageRef) { return toImpl(pageRef)->supportsTextEncoding(); @@ -332,24 +410,55 @@ void WKPageTerminate(WKPageRef pageRef) WKStringRef WKPageGetSessionHistoryURLValueType() { - static API::String* sessionHistoryURLValueType = API::String::create("SessionHistoryURL").leakRef(); - return toAPI(sessionHistoryURLValueType); + static API::String& sessionHistoryURLValueType = API::String::create("SessionHistoryURL").leakRef(); + return toAPI(&sessionHistoryURLValueType); } WKStringRef WKPageGetSessionBackForwardListItemValueType() { - static API::String* sessionBackForwardListValueType = API::String::create("SessionBackForwardListItem").leakRef(); - return toAPI(sessionBackForwardListValueType); + static API::String& sessionBackForwardListValueType = API::String::create("SessionBackForwardListItem").leakRef(); + return toAPI(&sessionBackForwardListValueType); } -WKDataRef WKPageCopySessionState(WKPageRef pageRef, void *context, WKPageSessionStateFilterCallback filter) +WKTypeRef WKPageCopySessionState(WKPageRef pageRef, void* context, WKPageSessionStateFilterCallback filter) { - return toAPI(toImpl(pageRef)->sessionStateData(filter, context).leakRef()); + // FIXME: This is a hack to make sure we return a WKDataRef to maintain compatibility with older versions of Safari. + bool shouldReturnData = !(reinterpret_cast<uintptr_t>(context) & 1); + context = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(context) & ~1); + + auto sessionState = toImpl(pageRef)->sessionState([pageRef, context, filter](WebBackForwardListItem& item) { + if (filter) { + if (!filter(pageRef, WKPageGetSessionBackForwardListItemValueType(), toAPI(&item), context)) + return false; + + if (!filter(pageRef, WKPageGetSessionHistoryURLValueType(), toURLRef(item.originalURL().impl()), context)) + return false; + } + + return true; + }); + + if (shouldReturnData) + return toAPI(encodeLegacySessionState(sessionState).release().leakRef()); + + return toAPI(&API::SessionState::create(WTFMove(sessionState)).leakRef()); } -void WKPageRestoreFromSessionState(WKPageRef pageRef, WKDataRef sessionStateData) +void WKPageRestoreFromSessionState(WKPageRef pageRef, WKTypeRef sessionStateRef) { - toImpl(pageRef)->restoreFromSessionStateData(toImpl(sessionStateData)); + SessionState sessionState; + + // FIXME: This is for backwards compatibility with Safari. Remove it once Safari no longer depends on it. + if (toImpl(sessionStateRef)->type() == API::Object::Type::Data) { + if (!decodeLegacySessionState(toImpl(static_cast<WKDataRef>(sessionStateRef))->bytes(), toImpl(static_cast<WKDataRef>(sessionStateRef))->size(), sessionState)) + return; + } else { + ASSERT(toImpl(sessionStateRef)->type() == API::Object::Type::SessionState); + + sessionState = toImpl(static_cast<WKSessionStateRef>(sessionStateRef))->sessionState(); + } + + toImpl(pageRef)->restoreFromSessionState(WTFMove(sessionState), true); } double WKPageGetTextZoomFactor(WKPageRef pageRef) @@ -427,12 +536,6 @@ void WKPageListenForLayoutMilestones(WKPageRef pageRef, WKLayoutMilestones miles toImpl(pageRef)->listenForLayoutMilestones(toLayoutMilestones(milestones)); } -void WKPageSetVisibilityState(WKPageRef pageRef, WKPageVisibilityState state, bool) -{ - if (state == kWKPageVisibilityStatePrerender) - toImpl(pageRef)->setVisibilityStatePrerender(); -} - bool WKPageHasHorizontalScrollbar(WKPageRef pageRef) { return toImpl(pageRef)->hasHorizontalScrollbar(); @@ -513,6 +616,26 @@ void WKPageSetRubberBandsAtBottom(WKPageRef pageRef, bool rubberBandsAtBottom) toImpl(pageRef)->setRubberBandsAtBottom(rubberBandsAtBottom); } +bool WKPageVerticalRubberBandingIsEnabled(WKPageRef pageRef) +{ + return toImpl(pageRef)->verticalRubberBandingIsEnabled(); +} + +void WKPageSetEnableVerticalRubberBanding(WKPageRef pageRef, bool enableVerticalRubberBanding) +{ + toImpl(pageRef)->setEnableVerticalRubberBanding(enableVerticalRubberBanding); +} + +bool WKPageHorizontalRubberBandingIsEnabled(WKPageRef pageRef) +{ + return toImpl(pageRef)->horizontalRubberBandingIsEnabled(); +} + +void WKPageSetEnableHorizontalRubberBanding(WKPageRef pageRef, bool enableHorizontalRubberBanding) +{ + toImpl(pageRef)->setEnableHorizontalRubberBanding(enableHorizontalRubberBanding); +} + void WKPageSetBackgroundExtendsBeyondPage(WKPageRef pageRef, bool backgroundExtendsBeyondPage) { toImpl(pageRef)->setBackgroundExtendsBeyondPage(backgroundExtendsBeyondPage); @@ -597,6 +720,16 @@ double WKPageGetGapBetweenPages(WKPageRef pageRef) return toImpl(pageRef)->gapBetweenPages(); } +void WKPageSetPaginationLineGridEnabled(WKPageRef pageRef, bool lineGridEnabled) +{ + toImpl(pageRef)->setPaginationLineGridEnabled(lineGridEnabled); +} + +bool WKPageGetPaginationLineGridEnabled(WKPageRef pageRef) +{ + return toImpl(pageRef)->paginationLineGridEnabled(); +} + unsigned WKPageGetPageCount(WKPageRef pageRef) { return toImpl(pageRef)->pageCount(); @@ -660,26 +793,189 @@ void WKPageCountStringMatches(WKPageRef pageRef, WKStringRef string, WKFindOptio void WKPageSetPageContextMenuClient(WKPageRef pageRef, const WKPageContextMenuClientBase* wkClient) { #if ENABLE(CONTEXT_MENUS) - toImpl(pageRef)->initializeContextMenuClient(wkClient); + class ContextMenuClient final : public API::Client<WKPageContextMenuClientBase>, public API::ContextMenuClient { + public: + explicit ContextMenuClient(const WKPageContextMenuClientBase* client) + { + initialize(client); + } + + private: + virtual bool getContextMenuFromProposedMenu(WebPageProxy& page, const Vector<RefPtr<WebKit::WebContextMenuItem>>& proposedMenuVector, Vector<RefPtr<WebKit::WebContextMenuItem>>& customMenu, const WebHitTestResultData& hitTestResultData, API::Object* userData) override + { + if (!m_client.getContextMenuFromProposedMenu && !m_client.getContextMenuFromProposedMenu_deprecatedForUseWithV0) + return false; + + if (m_client.base.version >= 2 && !m_client.getContextMenuFromProposedMenu) + return false; + + Vector<RefPtr<API::Object>> proposedMenuItems; + proposedMenuItems.reserveInitialCapacity(proposedMenuVector.size()); + + for (const auto& menuItem : proposedMenuVector) + proposedMenuItems.uncheckedAppend(menuItem); + + WKArrayRef newMenu = nullptr; + if (m_client.base.version >= 2) { + RefPtr<API::HitTestResult> webHitTestResult = API::HitTestResult::create(hitTestResultData); + m_client.getContextMenuFromProposedMenu(toAPI(&page), toAPI(API::Array::create(WTFMove(proposedMenuItems)).ptr()), &newMenu, toAPI(webHitTestResult.get()), toAPI(userData), m_client.base.clientInfo); + } else + m_client.getContextMenuFromProposedMenu_deprecatedForUseWithV0(toAPI(&page), toAPI(API::Array::create(WTFMove(proposedMenuItems)).ptr()), &newMenu, toAPI(userData), m_client.base.clientInfo); + + RefPtr<API::Array> array = adoptRef(toImpl(newMenu)); + + customMenu.clear(); + + size_t newSize = array ? array->size() : 0; + for (size_t i = 0; i < newSize; ++i) { + WebContextMenuItem* item = array->at<WebContextMenuItem>(i); + if (!item) { + LOG(ContextMenu, "New menu entry at index %i is not a WebContextMenuItem", (int)i); + continue; + } + + customMenu.append(item); + } + + return true; + } + + virtual void customContextMenuItemSelected(WebPageProxy& page, const WebContextMenuItemData& itemData) override + { + if (!m_client.customContextMenuItemSelected) + return; + + m_client.customContextMenuItemSelected(toAPI(&page), toAPI(WebContextMenuItem::create(itemData).ptr()), m_client.base.clientInfo); + } + + virtual bool showContextMenu(WebPageProxy& page, const WebCore::IntPoint& menuLocation, const Vector<RefPtr<WebContextMenuItem>>& menuItemsVector) override + { + if (!m_client.showContextMenu) + return false; + + Vector<RefPtr<API::Object>> menuItems; + menuItems.reserveInitialCapacity(menuItemsVector.size()); + + for (const auto& menuItem : menuItemsVector) + menuItems.uncheckedAppend(menuItem); + + m_client.showContextMenu(toAPI(&page), toAPI(menuLocation), toAPI(API::Array::create(WTFMove(menuItems)).ptr()), m_client.base.clientInfo); + + return true; + } + + virtual bool hideContextMenu(WebPageProxy& page) override + { + if (!m_client.hideContextMenu) + return false; + + m_client.hideContextMenu(toAPI(&page), m_client.base.clientInfo); + + return true; + } + }; + + toImpl(pageRef)->setContextMenuClient(std::make_unique<ContextMenuClient>(wkClient)); #else UNUSED_PARAM(pageRef); UNUSED_PARAM(wkClient); #endif } +void WKPageSetPageDiagnosticLoggingClient(WKPageRef pageRef, const WKPageDiagnosticLoggingClientBase* wkClient) +{ + toImpl(pageRef)->setDiagnosticLoggingClient(std::make_unique<WebPageDiagnosticLoggingClient>(wkClient)); +} + void WKPageSetPageFindClient(WKPageRef pageRef, const WKPageFindClientBase* wkClient) { - toImpl(pageRef)->initializeFindClient(wkClient); + class FindClient : public API::Client<WKPageFindClientBase>, public API::FindClient { + public: + explicit FindClient(const WKPageFindClientBase* client) + { + initialize(client); + } + + private: + virtual void didFindString(WebPageProxy* page, const String& string, const Vector<WebCore::IntRect>&, uint32_t matchCount, int32_t) override + { + if (!m_client.didFindString) + return; + + m_client.didFindString(toAPI(page), toAPI(string.impl()), matchCount, m_client.base.clientInfo); + } + + virtual void didFailToFindString(WebPageProxy* page, const String& string) override + { + if (!m_client.didFailToFindString) + return; + + m_client.didFailToFindString(toAPI(page), toAPI(string.impl()), m_client.base.clientInfo); + } + + virtual void didCountStringMatches(WebPageProxy* page, const String& string, uint32_t matchCount) override + { + if (!m_client.didCountStringMatches) + return; + + m_client.didCountStringMatches(toAPI(page), toAPI(string.impl()), matchCount, m_client.base.clientInfo); + } + }; + + toImpl(pageRef)->setFindClient(std::make_unique<FindClient>(wkClient)); } void WKPageSetPageFindMatchesClient(WKPageRef pageRef, const WKPageFindMatchesClientBase* wkClient) { - toImpl(pageRef)->initializeFindMatchesClient(wkClient); + class FindMatchesClient : public API::Client<WKPageFindMatchesClientBase>, public API::FindMatchesClient { + public: + explicit FindMatchesClient(const WKPageFindMatchesClientBase* client) + { + initialize(client); + } + + private: + virtual void didFindStringMatches(WebPageProxy* page, const String& string, const Vector<Vector<WebCore::IntRect>>& matchRects, int32_t index) override + { + if (!m_client.didFindStringMatches) + return; + + Vector<RefPtr<API::Object>> matches; + matches.reserveInitialCapacity(matchRects.size()); + + for (const auto& rects : matchRects) { + Vector<RefPtr<API::Object>> apiRects; + apiRects.reserveInitialCapacity(rects.size()); + + for (const auto& rect : rects) + apiRects.uncheckedAppend(API::Rect::create(toAPI(rect))); + + matches.uncheckedAppend(API::Array::create(WTFMove(apiRects))); + } + + m_client.didFindStringMatches(toAPI(page), toAPI(string.impl()), toAPI(API::Array::create(WTFMove(matches)).ptr()), index, m_client.base.clientInfo); + } + + virtual void didGetImageForMatchResult(WebPageProxy* page, WebImage* image, int32_t index) override + { + if (!m_client.didGetImageForMatchResult) + return; + + m_client.didGetImageForMatchResult(toAPI(page), toAPI(image), index, m_client.base.clientInfo); + } + }; + + toImpl(pageRef)->setFindMatchesClient(std::make_unique<FindMatchesClient>(wkClient)); +} + +void WKPageSetPageInjectedBundleClient(WKPageRef pageRef, const WKPageInjectedBundleClientBase* wkClient) +{ + toImpl(pageRef)->setInjectedBundleClient(wkClient); } void WKPageSetPageFormClient(WKPageRef pageRef, const WKPageFormClientBase* wkClient) { - toImpl(pageRef)->initializeFormClient(wkClient); + toImpl(pageRef)->setFormClient(std::make_unique<WebFormClient>(wkClient)); } void WKPageSetPageLoaderClient(WKPageRef pageRef, const WKPageLoaderClientBase* wkClient) @@ -692,255 +988,276 @@ void WKPageSetPageLoaderClient(WKPageRef pageRef, const WKPageLoaderClientBase* } private: - virtual void didStartProvisionalLoadForFrame(WebPageProxy* page, WebFrameProxy* frame, API::Object* userData) override + virtual void didStartProvisionalLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override { if (!m_client.didStartProvisionalLoadForFrame) return; - m_client.didStartProvisionalLoadForFrame(toAPI(page), toAPI(frame), toAPI(userData), m_client.base.clientInfo); + m_client.didStartProvisionalLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo); } - virtual void didReceiveServerRedirectForProvisionalLoadForFrame(WebPageProxy* page, WebFrameProxy* frame, API::Object* userData) override + virtual void didReceiveServerRedirectForProvisionalLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override { if (!m_client.didReceiveServerRedirectForProvisionalLoadForFrame) return; - m_client.didReceiveServerRedirectForProvisionalLoadForFrame(toAPI(page), toAPI(frame), toAPI(userData), m_client.base.clientInfo); + m_client.didReceiveServerRedirectForProvisionalLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo); } - virtual void didFailProvisionalLoadWithErrorForFrame(WebPageProxy* page, WebFrameProxy* frame, const ResourceError& error, API::Object* userData) override + virtual void didFailProvisionalLoadWithErrorForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, const ResourceError& error, API::Object* userData) override { if (!m_client.didFailProvisionalLoadWithErrorForFrame) return; - m_client.didFailProvisionalLoadWithErrorForFrame(toAPI(page), toAPI(frame), toAPI(error), toAPI(userData), m_client.base.clientInfo); + m_client.didFailProvisionalLoadWithErrorForFrame(toAPI(&page), toAPI(&frame), toAPI(error), toAPI(userData), m_client.base.clientInfo); } - virtual void didCommitLoadForFrame(WebPageProxy* page, WebFrameProxy* frame, API::Object* userData) override + virtual void didCommitLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override { if (!m_client.didCommitLoadForFrame) return; - m_client.didCommitLoadForFrame(toAPI(page), toAPI(frame), toAPI(userData), m_client.base.clientInfo); + m_client.didCommitLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo); } - virtual void didFinishDocumentLoadForFrame(WebPageProxy* page, WebFrameProxy* frame, API::Object* userData) override + virtual void didFinishDocumentLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override { if (!m_client.didFinishDocumentLoadForFrame) return; - m_client.didFinishDocumentLoadForFrame(toAPI(page), toAPI(frame), toAPI(userData), m_client.base.clientInfo); + m_client.didFinishDocumentLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo); } - virtual void didFinishLoadForFrame(WebPageProxy* page, WebFrameProxy* frame, API::Object* userData) override + virtual void didFinishLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override { if (!m_client.didFinishLoadForFrame) return; - m_client.didFinishLoadForFrame(toAPI(page), toAPI(frame), toAPI(userData), m_client.base.clientInfo); + m_client.didFinishLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo); } - virtual void didFailLoadWithErrorForFrame(WebPageProxy* page, WebFrameProxy* frame, const ResourceError& error, API::Object* userData) override + virtual void didFailLoadWithErrorForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, const ResourceError& error, API::Object* userData) override { if (!m_client.didFailLoadWithErrorForFrame) return; - m_client.didFailLoadWithErrorForFrame(toAPI(page), toAPI(frame), toAPI(error), toAPI(userData), m_client.base.clientInfo); + m_client.didFailLoadWithErrorForFrame(toAPI(&page), toAPI(&frame), toAPI(error), toAPI(userData), m_client.base.clientInfo); } - virtual void didSameDocumentNavigationForFrame(WebPageProxy* page, WebFrameProxy* frame, SameDocumentNavigationType type, API::Object* userData) override + virtual void didSameDocumentNavigationForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, SameDocumentNavigationType type, API::Object* userData) override { if (!m_client.didSameDocumentNavigationForFrame) return; - m_client.didSameDocumentNavigationForFrame(toAPI(page), toAPI(frame), toAPI(type), toAPI(userData), m_client.base.clientInfo); + m_client.didSameDocumentNavigationForFrame(toAPI(&page), toAPI(&frame), toAPI(type), toAPI(userData), m_client.base.clientInfo); } - virtual void didReceiveTitleForFrame(WebPageProxy* page, const String& title, WebFrameProxy* frame, API::Object* userData) override + virtual void didReceiveTitleForFrame(WebPageProxy& page, const String& title, WebFrameProxy& frame, API::Object* userData) override { if (!m_client.didReceiveTitleForFrame) return; - m_client.didReceiveTitleForFrame(toAPI(page), toAPI(title.impl()), toAPI(frame), toAPI(userData), m_client.base.clientInfo); + m_client.didReceiveTitleForFrame(toAPI(&page), toAPI(title.impl()), toAPI(&frame), toAPI(userData), m_client.base.clientInfo); } - virtual void didFirstLayoutForFrame(WebPageProxy* page, WebFrameProxy* frame, API::Object* userData) override + virtual void didFirstLayoutForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override { if (!m_client.didFirstLayoutForFrame) return; - m_client.didFirstLayoutForFrame(toAPI(page), toAPI(frame), toAPI(userData), m_client.base.clientInfo); + m_client.didFirstLayoutForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo); } - virtual void didFirstVisuallyNonEmptyLayoutForFrame(WebPageProxy* page, WebFrameProxy* frame, API::Object* userData) override + virtual void didFirstVisuallyNonEmptyLayoutForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override { if (!m_client.didFirstVisuallyNonEmptyLayoutForFrame) return; - m_client.didFirstVisuallyNonEmptyLayoutForFrame(toAPI(page), toAPI(frame), toAPI(userData), m_client.base.clientInfo); + m_client.didFirstVisuallyNonEmptyLayoutForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo); } - virtual void didLayout(WebPageProxy* page, LayoutMilestones milestones, API::Object* userData) override + virtual void didLayout(WebPageProxy& page, LayoutMilestones milestones) override { if (!m_client.didLayout) return; - m_client.didLayout(toAPI(page), toWKLayoutMilestones(milestones), toAPI(userData), m_client.base.clientInfo); + m_client.didLayout(toAPI(&page), toWKLayoutMilestones(milestones), nullptr, m_client.base.clientInfo); } - virtual void didRemoveFrameFromHierarchy(WebPageProxy* page, WebFrameProxy* frame, API::Object* userData) override - { - if (!m_client.didRemoveFrameFromHierarchy) - return; - - m_client.didRemoveFrameFromHierarchy(toAPI(page), toAPI(frame), toAPI(userData), m_client.base.clientInfo); - } - - virtual void didDisplayInsecureContentForFrame(WebPageProxy* page, WebFrameProxy* frame, API::Object* userData) override + virtual void didDisplayInsecureContentForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override { if (!m_client.didDisplayInsecureContentForFrame) return; - m_client.didDisplayInsecureContentForFrame(toAPI(page), toAPI(frame), toAPI(userData), m_client.base.clientInfo); + m_client.didDisplayInsecureContentForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo); } - virtual void didRunInsecureContentForFrame(WebPageProxy* page, WebFrameProxy* frame, API::Object* userData) override + virtual void didRunInsecureContentForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override { if (!m_client.didRunInsecureContentForFrame) return; - m_client.didRunInsecureContentForFrame(toAPI(page), toAPI(frame), toAPI(userData), m_client.base.clientInfo); + m_client.didRunInsecureContentForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo); } - virtual void didDetectXSSForFrame(WebPageProxy* page, WebFrameProxy* frame, API::Object* userData) override + virtual void didDetectXSSForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override { if (!m_client.didDetectXSSForFrame) return; - m_client.didDetectXSSForFrame(toAPI(page), toAPI(frame), toAPI(userData), m_client.base.clientInfo); + m_client.didDetectXSSForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo); } - virtual bool canAuthenticateAgainstProtectionSpaceInFrame(WebPageProxy* page, WebFrameProxy* frame, WebProtectionSpace* protectionSpace) override + virtual bool canAuthenticateAgainstProtectionSpaceInFrame(WebPageProxy& page, WebFrameProxy& frame, WebProtectionSpace* protectionSpace) override { if (!m_client.canAuthenticateAgainstProtectionSpaceInFrame) return false; - return m_client.canAuthenticateAgainstProtectionSpaceInFrame(toAPI(page), toAPI(frame), toAPI(protectionSpace), m_client.base.clientInfo); + return m_client.canAuthenticateAgainstProtectionSpaceInFrame(toAPI(&page), toAPI(&frame), toAPI(protectionSpace), m_client.base.clientInfo); } - virtual void didReceiveAuthenticationChallengeInFrame(WebPageProxy* page, WebFrameProxy* frame, AuthenticationChallengeProxy* authenticationChallenge) override + virtual void didReceiveAuthenticationChallengeInFrame(WebPageProxy& page, WebFrameProxy& frame, AuthenticationChallengeProxy* authenticationChallenge) override { if (!m_client.didReceiveAuthenticationChallengeInFrame) return; - m_client.didReceiveAuthenticationChallengeInFrame(toAPI(page), toAPI(frame), toAPI(authenticationChallenge), m_client.base.clientInfo); + m_client.didReceiveAuthenticationChallengeInFrame(toAPI(&page), toAPI(&frame), toAPI(authenticationChallenge), m_client.base.clientInfo); } - virtual void didStartProgress(WebPageProxy* page) override + virtual void didStartProgress(WebPageProxy& page) override { if (!m_client.didStartProgress) return; - m_client.didStartProgress(toAPI(page), m_client.base.clientInfo); + m_client.didStartProgress(toAPI(&page), m_client.base.clientInfo); } - virtual void didChangeProgress(WebPageProxy* page) override + virtual void didChangeProgress(WebPageProxy& page) override { if (!m_client.didChangeProgress) return; - m_client.didChangeProgress(toAPI(page), m_client.base.clientInfo); + m_client.didChangeProgress(toAPI(&page), m_client.base.clientInfo); } - virtual void didFinishProgress(WebPageProxy* page) override + virtual void didFinishProgress(WebPageProxy& page) override { if (!m_client.didFinishProgress) return; - m_client.didFinishProgress(toAPI(page), m_client.base.clientInfo); + m_client.didFinishProgress(toAPI(&page), m_client.base.clientInfo); } - virtual void processDidBecomeUnresponsive(WebPageProxy* page) override + virtual void processDidBecomeUnresponsive(WebPageProxy& page) override { if (!m_client.processDidBecomeUnresponsive) return; - m_client.processDidBecomeUnresponsive(toAPI(page), m_client.base.clientInfo); - } - - virtual void interactionOccurredWhileProcessUnresponsive(WebPageProxy* page) override - { - if (!m_client.interactionOccurredWhileProcessUnresponsive) - return; - - m_client.interactionOccurredWhileProcessUnresponsive(toAPI(page), m_client.base.clientInfo); + m_client.processDidBecomeUnresponsive(toAPI(&page), m_client.base.clientInfo); } - virtual void processDidBecomeResponsive(WebPageProxy* page) override + virtual void processDidBecomeResponsive(WebPageProxy& page) override { if (!m_client.processDidBecomeResponsive) return; - m_client.processDidBecomeResponsive(toAPI(page), m_client.base.clientInfo); + m_client.processDidBecomeResponsive(toAPI(&page), m_client.base.clientInfo); } - virtual void processDidCrash(WebPageProxy* page) override + virtual void processDidCrash(WebPageProxy& page) override { if (!m_client.processDidCrash) return; - m_client.processDidCrash(toAPI(page), m_client.base.clientInfo); + m_client.processDidCrash(toAPI(&page), m_client.base.clientInfo); } - virtual void didChangeBackForwardList(WebPageProxy* page, WebBackForwardListItem* addedItem, Vector<RefPtr<API::Object>>* removedItems) override + virtual void didChangeBackForwardList(WebPageProxy& page, WebBackForwardListItem* addedItem, Vector<RefPtr<WebBackForwardListItem>> removedItems) override { if (!m_client.didChangeBackForwardList) return; RefPtr<API::Array> removedItemsArray; - if (removedItems && !removedItems->isEmpty()) - removedItemsArray = API::Array::create(std::move(*removedItems)); + if (!removedItems.isEmpty()) { + Vector<RefPtr<API::Object>> removedItemsVector; + removedItemsVector.reserveInitialCapacity(removedItems.size()); + for (auto& removedItem : removedItems) + removedItemsVector.append(WTFMove(removedItem)); - m_client.didChangeBackForwardList(toAPI(page), toAPI(addedItem), toAPI(removedItemsArray.get()), m_client.base.clientInfo); + removedItemsArray = API::Array::create(WTFMove(removedItemsVector)); + } + + m_client.didChangeBackForwardList(toAPI(&page), toAPI(addedItem), toAPI(removedItemsArray.get()), m_client.base.clientInfo); } - virtual void willGoToBackForwardListItem(WebPageProxy* page, WebBackForwardListItem* item, API::Object* userData) override + virtual bool shouldKeepCurrentBackForwardListItemInList(WebKit::WebPageProxy& page, WebKit::WebBackForwardListItem* item) override + { + if (!m_client.shouldKeepCurrentBackForwardListItemInList) + return true; + + return m_client.shouldKeepCurrentBackForwardListItemInList(toAPI(&page), toAPI(item), m_client.base.clientInfo); + } + + virtual void willGoToBackForwardListItem(WebPageProxy& page, WebBackForwardListItem* item, API::Object* userData) override { if (m_client.willGoToBackForwardListItem) - m_client.willGoToBackForwardListItem(toAPI(page), toAPI(item), toAPI(userData), m_client.base.clientInfo); + m_client.willGoToBackForwardListItem(toAPI(&page), toAPI(item), toAPI(userData), m_client.base.clientInfo); + } + + virtual RefPtr<API::Data> webCryptoMasterKey(WebPageProxy& page) override + { + return page.process().processPool().client().copyWebCryptoMasterKey(&page.process().processPool()); + } + + virtual void navigationGestureDidBegin(WebPageProxy& page) override + { + if (m_client.navigationGestureDidBegin) + m_client.navigationGestureDidBegin(toAPI(&page), m_client.base.clientInfo); + } + + virtual void navigationGestureWillEnd(WebPageProxy& page, bool willNavigate, WebBackForwardListItem& item) override + { + if (m_client.navigationGestureWillEnd) + m_client.navigationGestureWillEnd(toAPI(&page), willNavigate, toAPI(&item), m_client.base.clientInfo); + } + + virtual void navigationGestureDidEnd(WebPageProxy& page, bool willNavigate, WebBackForwardListItem& item) override + { + if (m_client.navigationGestureDidEnd) + m_client.navigationGestureDidEnd(toAPI(&page), willNavigate, toAPI(&item), m_client.base.clientInfo); } #if ENABLE(NETSCAPE_PLUGIN_API) - virtual void didFailToInitializePlugin(WebPageProxy* page, ImmutableDictionary* pluginInformation) override + virtual void didFailToInitializePlugin(WebPageProxy& page, API::Dictionary* pluginInformation) override { if (m_client.didFailToInitializePlugin_deprecatedForUseWithV0) - m_client.didFailToInitializePlugin_deprecatedForUseWithV0(toAPI(page), toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), m_client.base.clientInfo); + m_client.didFailToInitializePlugin_deprecatedForUseWithV0(toAPI(&page), toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), m_client.base.clientInfo); if (m_client.pluginDidFail_deprecatedForUseWithV1) - m_client.pluginDidFail_deprecatedForUseWithV1(toAPI(page), kWKErrorCodeCannotLoadPlugIn, toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), 0, 0, m_client.base.clientInfo); + m_client.pluginDidFail_deprecatedForUseWithV1(toAPI(&page), kWKErrorCodeCannotLoadPlugIn, toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), 0, 0, m_client.base.clientInfo); if (m_client.pluginDidFail) - m_client.pluginDidFail(toAPI(page), kWKErrorCodeCannotLoadPlugIn, toAPI(pluginInformation), m_client.base.clientInfo); + m_client.pluginDidFail(toAPI(&page), kWKErrorCodeCannotLoadPlugIn, toAPI(pluginInformation), m_client.base.clientInfo); } - virtual void didBlockInsecurePluginVersion(WebPageProxy* page, ImmutableDictionary* pluginInformation) override + virtual void didBlockInsecurePluginVersion(WebPageProxy& page, API::Dictionary* pluginInformation) override { if (m_client.pluginDidFail_deprecatedForUseWithV1) - m_client.pluginDidFail_deprecatedForUseWithV1(toAPI(page), kWKErrorCodeInsecurePlugInVersion, toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), toAPI(pluginInformation->get<API::String>(pluginInformationBundleIdentifierKey())), toAPI(pluginInformation->get<API::String>(pluginInformationBundleVersionKey())), m_client.base.clientInfo); + m_client.pluginDidFail_deprecatedForUseWithV1(toAPI(&page), kWKErrorCodeInsecurePlugInVersion, toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), toAPI(pluginInformation->get<API::String>(pluginInformationBundleIdentifierKey())), toAPI(pluginInformation->get<API::String>(pluginInformationBundleVersionKey())), m_client.base.clientInfo); if (m_client.pluginDidFail) - m_client.pluginDidFail(toAPI(page), kWKErrorCodeInsecurePlugInVersion, toAPI(pluginInformation), m_client.base.clientInfo); + m_client.pluginDidFail(toAPI(&page), kWKErrorCodeInsecurePlugInVersion, toAPI(pluginInformation), m_client.base.clientInfo); } - virtual PluginModuleLoadPolicy pluginLoadPolicy(WebPageProxy* page, PluginModuleLoadPolicy currentPluginLoadPolicy, ImmutableDictionary* pluginInformation, String& unavailabilityDescription) override + virtual PluginModuleLoadPolicy pluginLoadPolicy(WebPageProxy& page, PluginModuleLoadPolicy currentPluginLoadPolicy, API::Dictionary* pluginInformation, String& unavailabilityDescription) override { WKStringRef unavailabilityDescriptionOut = 0; PluginModuleLoadPolicy loadPolicy = currentPluginLoadPolicy; if (m_client.pluginLoadPolicy_deprecatedForUseWithV2) - loadPolicy = toPluginModuleLoadPolicy(m_client.pluginLoadPolicy_deprecatedForUseWithV2(toAPI(page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), m_client.base.clientInfo)); + loadPolicy = toPluginModuleLoadPolicy(m_client.pluginLoadPolicy_deprecatedForUseWithV2(toAPI(&page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), m_client.base.clientInfo)); else if (m_client.pluginLoadPolicy) - loadPolicy = toPluginModuleLoadPolicy(m_client.pluginLoadPolicy(toAPI(page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), &unavailabilityDescriptionOut, m_client.base.clientInfo)); + loadPolicy = toPluginModuleLoadPolicy(m_client.pluginLoadPolicy(toAPI(&page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), &unavailabilityDescriptionOut, m_client.base.clientInfo)); if (unavailabilityDescriptionOut) { RefPtr<API::String> webUnavailabilityDescription = adoptRef(toImpl(unavailabilityDescriptionOut)); @@ -952,15 +1269,26 @@ void WKPageSetPageLoaderClient(WKPageRef pageRef, const WKPageLoaderClientBase* #endif // ENABLE(NETSCAPE_PLUGIN_API) #if ENABLE(WEBGL) - virtual WebCore::WebGLLoadPolicy webGLLoadPolicy(WebPageProxy* page, const String& url) const override + virtual WebCore::WebGLLoadPolicy webGLLoadPolicy(WebPageProxy& page, const String& url) const override { - WebCore::WebGLLoadPolicy loadPolicy = WebGLAllow; + WebCore::WebGLLoadPolicy loadPolicy = WebGLAllowCreation; if (m_client.webGLLoadPolicy) - loadPolicy = toWebGLLoadPolicy(m_client.webGLLoadPolicy(toAPI(page), toAPI(url.impl()), m_client.base.clientInfo)); + loadPolicy = toWebGLLoadPolicy(m_client.webGLLoadPolicy(toAPI(&page), toAPI(url.impl()), m_client.base.clientInfo)); return loadPolicy; } + + virtual WebCore::WebGLLoadPolicy resolveWebGLLoadPolicy(WebPageProxy& page, const String& url) const override + { + WebCore::WebGLLoadPolicy loadPolicy = WebGLAllowCreation; + + if (m_client.resolveWebGLLoadPolicy) + loadPolicy = toWebGLLoadPolicy(m_client.resolveWebGLLoadPolicy(toAPI(&page), toAPI(url.impl()), m_client.base.clientInfo)); + + return loadPolicy; + } + #endif // ENABLE(WEBGL) }; @@ -980,7 +1308,7 @@ void WKPageSetPageLoaderClient(WKPageRef pageRef, const WKPageLoaderClientBase* if (milestones) webPageProxy->process().send(Messages::WebPage::ListenForLayoutMilestones(milestones), webPageProxy->pageID()); - webPageProxy->setLoaderClient(std::move(loaderClient)); + webPageProxy->setLoaderClient(WTFMove(loaderClient)); } void WKPageSetPagePolicyClient(WKPageRef pageRef, const WKPagePolicyClientBase* wkClient) @@ -993,77 +1321,1060 @@ void WKPageSetPagePolicyClient(WKPageRef pageRef, const WKPagePolicyClientBase* } private: - virtual void decidePolicyForNavigationAction(WebPageProxy* page, WebFrameProxy* frame, const NavigationActionData& navigationActionData, WebFrameProxy* originatingFrame, const WebCore::ResourceRequest& originalResourceRequest, const WebCore::ResourceRequest& resourceRequest, WebFramePolicyListenerProxy* listener, API::Object* userData) override + virtual void decidePolicyForNavigationAction(WebPageProxy& page, WebFrameProxy* frame, const NavigationActionData& navigationActionData, WebFrameProxy* originatingFrame, const WebCore::ResourceRequest& originalResourceRequest, const WebCore::ResourceRequest& resourceRequest, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* userData) override { if (!m_client.decidePolicyForNavigationAction_deprecatedForUseWithV0 && !m_client.decidePolicyForNavigationAction_deprecatedForUseWithV1 && !m_client.decidePolicyForNavigationAction) { listener->use(); return; } - RefPtr<API::URLRequest> originalRequest = API::URLRequest::create(originalResourceRequest); - RefPtr<API::URLRequest> request = API::URLRequest::create(resourceRequest); + Ref<API::URLRequest> originalRequest = API::URLRequest::create(originalResourceRequest); + Ref<API::URLRequest> request = API::URLRequest::create(resourceRequest); if (m_client.decidePolicyForNavigationAction_deprecatedForUseWithV0) - m_client.decidePolicyForNavigationAction_deprecatedForUseWithV0(toAPI(page), toAPI(frame), toAPI(navigationActionData.navigationType), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), toAPI(request.get()), toAPI(listener), toAPI(userData), m_client.base.clientInfo); + m_client.decidePolicyForNavigationAction_deprecatedForUseWithV0(toAPI(&page), toAPI(frame), toAPI(navigationActionData.navigationType), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), toAPI(request.ptr()), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo); else if (m_client.decidePolicyForNavigationAction_deprecatedForUseWithV1) - m_client.decidePolicyForNavigationAction_deprecatedForUseWithV1(toAPI(page), toAPI(frame), toAPI(navigationActionData.navigationType), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), toAPI(originatingFrame), toAPI(request.get()), toAPI(listener), toAPI(userData), m_client.base.clientInfo); + m_client.decidePolicyForNavigationAction_deprecatedForUseWithV1(toAPI(&page), toAPI(frame), toAPI(navigationActionData.navigationType), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), toAPI(originatingFrame), toAPI(request.ptr()), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo); else - m_client.decidePolicyForNavigationAction(toAPI(page), toAPI(frame), toAPI(navigationActionData.navigationType), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), toAPI(originatingFrame), toAPI(originalRequest.get()), toAPI(request.get()), toAPI(listener), toAPI(userData), m_client.base.clientInfo); + m_client.decidePolicyForNavigationAction(toAPI(&page), toAPI(frame), toAPI(navigationActionData.navigationType), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), toAPI(originatingFrame), toAPI(originalRequest.ptr()), toAPI(request.ptr()), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo); } - virtual void decidePolicyForNewWindowAction(WebPageProxy* page, WebFrameProxy* frame, NavigationType type, WebEvent::Modifiers modifiers, WebMouseEvent::Button mouseButton, const ResourceRequest& resourceRequest, const String& frameName, WebFramePolicyListenerProxy* listener, API::Object* userData) override + virtual void decidePolicyForNewWindowAction(WebPageProxy& page, WebFrameProxy& frame, const NavigationActionData& navigationActionData, const ResourceRequest& resourceRequest, const String& frameName, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* userData) override { if (!m_client.decidePolicyForNewWindowAction) { listener->use(); return; } - RefPtr<API::URLRequest> request = API::URLRequest::create(resourceRequest); + Ref<API::URLRequest> request = API::URLRequest::create(resourceRequest); - m_client.decidePolicyForNewWindowAction(toAPI(page), toAPI(frame), toAPI(type), toAPI(modifiers), toAPI(mouseButton), toAPI(request.get()), toAPI(frameName.impl()), toAPI(listener), toAPI(userData), m_client.base.clientInfo); + m_client.decidePolicyForNewWindowAction(toAPI(&page), toAPI(&frame), toAPI(navigationActionData.navigationType), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), toAPI(request.ptr()), toAPI(frameName.impl()), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo); } - virtual void decidePolicyForResponse(WebPageProxy* page, WebFrameProxy* frame, const ResourceResponse& resourceResponse, const ResourceRequest& resourceRequest, bool canShowMIMEType, WebFramePolicyListenerProxy* listener, API::Object* userData) override + virtual void decidePolicyForResponse(WebPageProxy& page, WebFrameProxy& frame, const ResourceResponse& resourceResponse, const ResourceRequest& resourceRequest, bool canShowMIMEType, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* userData) override { if (!m_client.decidePolicyForResponse_deprecatedForUseWithV0 && !m_client.decidePolicyForResponse) { listener->use(); return; } - RefPtr<API::URLResponse> response = API::URLResponse::create(resourceResponse); - RefPtr<API::URLRequest> request = API::URLRequest::create(resourceRequest); + Ref<API::URLResponse> response = API::URLResponse::create(resourceResponse); + Ref<API::URLRequest> request = API::URLRequest::create(resourceRequest); if (m_client.decidePolicyForResponse_deprecatedForUseWithV0) - m_client.decidePolicyForResponse_deprecatedForUseWithV0(toAPI(page), toAPI(frame), toAPI(response.get()), toAPI(request.get()), toAPI(listener), toAPI(userData), m_client.base.clientInfo); + m_client.decidePolicyForResponse_deprecatedForUseWithV0(toAPI(&page), toAPI(&frame), toAPI(response.ptr()), toAPI(request.ptr()), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo); else - m_client.decidePolicyForResponse(toAPI(page), toAPI(frame), toAPI(response.get()), toAPI(request.get()), canShowMIMEType, toAPI(listener), toAPI(userData), m_client.base.clientInfo); + m_client.decidePolicyForResponse(toAPI(&page), toAPI(&frame), toAPI(response.ptr()), toAPI(request.ptr()), canShowMIMEType, toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo); } - virtual void unableToImplementPolicy(WebPageProxy* page, WebFrameProxy* frame, const ResourceError& error, API::Object* userData) override + virtual void unableToImplementPolicy(WebPageProxy& page, WebFrameProxy& frame, const ResourceError& error, API::Object* userData) override { if (!m_client.unableToImplementPolicy) return; - m_client.unableToImplementPolicy(toAPI(page), toAPI(frame), toAPI(error), toAPI(userData), m_client.base.clientInfo); + m_client.unableToImplementPolicy(toAPI(&page), toAPI(&frame), toAPI(error), toAPI(userData), m_client.base.clientInfo); } }; toImpl(pageRef)->setPolicyClient(std::make_unique<PolicyClient>(wkClient)); } +#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED <= 101000 +static void fixUpBotchedPageUIClient(WKPageRef pageRef, const WKPageUIClientBase& wkClient) +{ + struct BotchedWKPageUIClientV4 { + WKPageUIClientBase base; + + // Version 0. + WKPageCreateNewPageCallback_deprecatedForUseWithV0 createNewPage_deprecatedForUseWithV0; + WKPageUIClientCallback showPage; + WKPageUIClientCallback close; + WKPageTakeFocusCallback takeFocus; + WKPageFocusCallback focus; + WKPageUnfocusCallback unfocus; + WKPageRunJavaScriptAlertCallback_deprecatedForUseWithV0 runJavaScriptAlert_deprecatedForUseWithV0; + WKPageRunJavaScriptConfirmCallback_deprecatedForUseWithV0 runJavaScriptConfirm_deprecatedForUseWithV0; + WKPageRunJavaScriptPromptCallback_deprecatedForUseWithV0 runJavaScriptPrompt_deprecatedForUseWithV0; + WKPageSetStatusTextCallback setStatusText; + WKPageMouseDidMoveOverElementCallback_deprecatedForUseWithV0 mouseDidMoveOverElement_deprecatedForUseWithV0; + WKPageMissingPluginButtonClickedCallback_deprecatedForUseWithV0 missingPluginButtonClicked_deprecatedForUseWithV0; + WKPageDidNotHandleKeyEventCallback didNotHandleKeyEvent; + WKPageDidNotHandleWheelEventCallback didNotHandleWheelEvent; + WKPageGetToolbarsAreVisibleCallback toolbarsAreVisible; + WKPageSetToolbarsAreVisibleCallback setToolbarsAreVisible; + WKPageGetMenuBarIsVisibleCallback menuBarIsVisible; + WKPageSetMenuBarIsVisibleCallback setMenuBarIsVisible; + WKPageGetStatusBarIsVisibleCallback statusBarIsVisible; + WKPageSetStatusBarIsVisibleCallback setStatusBarIsVisible; + WKPageGetIsResizableCallback isResizable; + WKPageSetIsResizableCallback setIsResizable; + WKPageGetWindowFrameCallback getWindowFrame; + WKPageSetWindowFrameCallback setWindowFrame; + WKPageRunBeforeUnloadConfirmPanelCallback_deprecatedForUseWithV6 runBeforeUnloadConfirmPanel; + WKPageUIClientCallback didDraw; + WKPageUIClientCallback pageDidScroll; + WKPageExceededDatabaseQuotaCallback exceededDatabaseQuota; + WKPageRunOpenPanelCallback runOpenPanel; + WKPageDecidePolicyForGeolocationPermissionRequestCallback decidePolicyForGeolocationPermissionRequest; + WKPageHeaderHeightCallback headerHeight; + WKPageFooterHeightCallback footerHeight; + WKPageDrawHeaderCallback drawHeader; + WKPageDrawFooterCallback drawFooter; + WKPagePrintFrameCallback printFrame; + WKPageUIClientCallback runModal; + void* unused1; // Used to be didCompleteRubberBandForMainFrame + WKPageSaveDataToFileInDownloadsFolderCallback saveDataToFileInDownloadsFolder; + void* shouldInterruptJavaScript_unavailable; + + // Version 1. + WKPageCreateNewPageCallback_deprecatedForUseWithV1 createNewPage; + WKPageMouseDidMoveOverElementCallback mouseDidMoveOverElement; + WKPageDecidePolicyForNotificationPermissionRequestCallback decidePolicyForNotificationPermissionRequest; + WKPageUnavailablePluginButtonClickedCallback_deprecatedForUseWithV1 unavailablePluginButtonClicked_deprecatedForUseWithV1; + + // Version 2. + WKPageShowColorPickerCallback showColorPicker; + WKPageHideColorPickerCallback hideColorPicker; + WKPageUnavailablePluginButtonClickedCallback unavailablePluginButtonClicked; + + // Version 3. + WKPagePinnedStateDidChangeCallback pinnedStateDidChange; + + // Version 4. + WKPageRunJavaScriptAlertCallback_deprecatedForUseWithV5 runJavaScriptAlert; + WKPageRunJavaScriptConfirmCallback_deprecatedForUseWithV5 runJavaScriptConfirm; + WKPageRunJavaScriptPromptCallback_deprecatedForUseWithV5 runJavaScriptPrompt; + }; + + const auto& botchedPageUIClient = reinterpret_cast<const BotchedWKPageUIClientV4&>(wkClient); + + WKPageUIClientV5 fixedPageUIClient = { + { 5, botchedPageUIClient.base.clientInfo }, + botchedPageUIClient.createNewPage_deprecatedForUseWithV0, + botchedPageUIClient.showPage, + botchedPageUIClient.close, + botchedPageUIClient.takeFocus, + botchedPageUIClient.focus, + botchedPageUIClient.unfocus, + botchedPageUIClient.runJavaScriptAlert_deprecatedForUseWithV0, + botchedPageUIClient.runJavaScriptConfirm_deprecatedForUseWithV0, + botchedPageUIClient.runJavaScriptPrompt_deprecatedForUseWithV0, + botchedPageUIClient.setStatusText, + botchedPageUIClient.mouseDidMoveOverElement_deprecatedForUseWithV0, + botchedPageUIClient.missingPluginButtonClicked_deprecatedForUseWithV0, + botchedPageUIClient.didNotHandleKeyEvent, + botchedPageUIClient.didNotHandleWheelEvent, + botchedPageUIClient.toolbarsAreVisible, + botchedPageUIClient.setToolbarsAreVisible, + botchedPageUIClient.menuBarIsVisible, + botchedPageUIClient.setMenuBarIsVisible, + botchedPageUIClient.statusBarIsVisible, + botchedPageUIClient.setStatusBarIsVisible, + botchedPageUIClient.isResizable, + botchedPageUIClient.setIsResizable, + botchedPageUIClient.getWindowFrame, + botchedPageUIClient.setWindowFrame, + botchedPageUIClient.runBeforeUnloadConfirmPanel, + botchedPageUIClient.didDraw, + botchedPageUIClient.pageDidScroll, + botchedPageUIClient.exceededDatabaseQuota, + botchedPageUIClient.runOpenPanel, + botchedPageUIClient.decidePolicyForGeolocationPermissionRequest, + botchedPageUIClient.headerHeight, + botchedPageUIClient.footerHeight, + botchedPageUIClient.drawHeader, + botchedPageUIClient.drawFooter, + botchedPageUIClient.printFrame, + botchedPageUIClient.runModal, + botchedPageUIClient.unused1, + botchedPageUIClient.saveDataToFileInDownloadsFolder, + botchedPageUIClient.shouldInterruptJavaScript_unavailable, + botchedPageUIClient.createNewPage, + botchedPageUIClient.mouseDidMoveOverElement, + botchedPageUIClient.decidePolicyForNotificationPermissionRequest, + botchedPageUIClient.unavailablePluginButtonClicked_deprecatedForUseWithV1, + botchedPageUIClient.showColorPicker, + botchedPageUIClient.hideColorPicker, + botchedPageUIClient.unavailablePluginButtonClicked, + botchedPageUIClient.pinnedStateDidChange, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + botchedPageUIClient.runJavaScriptAlert, + botchedPageUIClient.runJavaScriptConfirm, + botchedPageUIClient.runJavaScriptPrompt, + nullptr, + }; + + WKPageSetPageUIClient(pageRef, &fixedPageUIClient.base); +} +#endif + +namespace WebKit { + +class RunBeforeUnloadConfirmPanelResultListener : public API::ObjectImpl<API::Object::Type::RunBeforeUnloadConfirmPanelResultListener> { +public: + static PassRefPtr<RunBeforeUnloadConfirmPanelResultListener> create(std::function<void (bool)>&& completionHandler) + { + return adoptRef(new RunBeforeUnloadConfirmPanelResultListener(WTFMove(completionHandler))); + } + + virtual ~RunBeforeUnloadConfirmPanelResultListener() + { + } + + void call(bool result) + { + m_completionHandler(result); + } + +private: + explicit RunBeforeUnloadConfirmPanelResultListener(std::function<void (bool)>&& completionHandler) + : m_completionHandler(WTFMove(completionHandler)) + { + } + + std::function<void (bool)> m_completionHandler; +}; + +class RunJavaScriptAlertResultListener : public API::ObjectImpl<API::Object::Type::RunJavaScriptAlertResultListener> { +public: + static PassRefPtr<RunJavaScriptAlertResultListener> create(std::function<void ()>&& completionHandler) + { + return adoptRef(new RunJavaScriptAlertResultListener(WTFMove(completionHandler))); + } + + virtual ~RunJavaScriptAlertResultListener() + { + } + + void call() + { + m_completionHandler(); + } + +private: + explicit RunJavaScriptAlertResultListener(std::function<void ()>&& completionHandler) + : m_completionHandler(WTFMove(completionHandler)) + { + } + + std::function<void ()> m_completionHandler; +}; + +class RunJavaScriptConfirmResultListener : public API::ObjectImpl<API::Object::Type::RunJavaScriptConfirmResultListener> { +public: + static PassRefPtr<RunJavaScriptConfirmResultListener> create(std::function<void (bool)>&& completionHandler) + { + return adoptRef(new RunJavaScriptConfirmResultListener(WTFMove(completionHandler))); + } + + virtual ~RunJavaScriptConfirmResultListener() + { + } + + void call(bool result) + { + m_completionHandler(result); + } + +private: + explicit RunJavaScriptConfirmResultListener(std::function<void (bool)>&& completionHandler) + : m_completionHandler(WTFMove(completionHandler)) + { + } + + std::function<void (bool)> m_completionHandler; +}; + +class RunJavaScriptPromptResultListener : public API::ObjectImpl<API::Object::Type::RunJavaScriptPromptResultListener> { +public: + static PassRefPtr<RunJavaScriptPromptResultListener> create(std::function<void (const String&)>&& completionHandler) + { + return adoptRef(new RunJavaScriptPromptResultListener(WTFMove(completionHandler))); + } + + virtual ~RunJavaScriptPromptResultListener() + { + } + + void call(const String& result) + { + m_completionHandler(result); + } + +private: + explicit RunJavaScriptPromptResultListener(std::function<void (const String&)>&& completionHandler) + : m_completionHandler(WTFMove(completionHandler)) + { + } + + std::function<void (const String&)> m_completionHandler; +}; + +WK_ADD_API_MAPPING(WKPageRunBeforeUnloadConfirmPanelResultListenerRef, RunBeforeUnloadConfirmPanelResultListener) +WK_ADD_API_MAPPING(WKPageRunJavaScriptAlertResultListenerRef, RunJavaScriptAlertResultListener) +WK_ADD_API_MAPPING(WKPageRunJavaScriptConfirmResultListenerRef, RunJavaScriptConfirmResultListener) +WK_ADD_API_MAPPING(WKPageRunJavaScriptPromptResultListenerRef, RunJavaScriptPromptResultListener) + +} + +WKTypeID WKPageRunBeforeUnloadConfirmPanelResultListenerGetTypeID() +{ + return toAPI(RunBeforeUnloadConfirmPanelResultListener::APIType); +} + +void WKPageRunBeforeUnloadConfirmPanelResultListenerCall(WKPageRunBeforeUnloadConfirmPanelResultListenerRef listener, bool result) +{ + toImpl(listener)->call(result); +} + +WKTypeID WKPageRunJavaScriptAlertResultListenerGetTypeID() +{ + return toAPI(RunJavaScriptAlertResultListener::APIType); +} + +void WKPageRunJavaScriptAlertResultListenerCall(WKPageRunJavaScriptAlertResultListenerRef listener) +{ + toImpl(listener)->call(); +} + +WKTypeID WKPageRunJavaScriptConfirmResultListenerGetTypeID() +{ + return toAPI(RunJavaScriptConfirmResultListener::APIType); +} + +void WKPageRunJavaScriptConfirmResultListenerCall(WKPageRunJavaScriptConfirmResultListenerRef listener, bool result) +{ + toImpl(listener)->call(result); +} + +WKTypeID WKPageRunJavaScriptPromptResultListenerGetTypeID() +{ + return toAPI(RunJavaScriptPromptResultListener::APIType); +} + +void WKPageRunJavaScriptPromptResultListenerCall(WKPageRunJavaScriptPromptResultListenerRef listener, WKStringRef result) +{ + toImpl(listener)->call(toWTFString(result)); +} + void WKPageSetPageUIClient(WKPageRef pageRef, const WKPageUIClientBase* wkClient) { - toImpl(pageRef)->initializeUIClient(wkClient); +#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED <= 101000 + if (wkClient && wkClient->version == 4) { + fixUpBotchedPageUIClient(pageRef, *wkClient); + return; + } +#endif + + class UIClient : public API::Client<WKPageUIClientBase>, public API::UIClient { + public: + explicit UIClient(const WKPageUIClientBase* client) + { + initialize(client); + } + + private: + virtual PassRefPtr<WebPageProxy> createNewPage(WebPageProxy* page, WebFrameProxy* initiatingFrame, const SecurityOriginData& securityOriginData, const ResourceRequest& resourceRequest, const WindowFeatures& windowFeatures, const NavigationActionData& navigationActionData) override + { + if (m_client.createNewPage) { + auto configuration = page->configuration().copy(); + configuration->setRelatedPage(page); + + auto sourceFrameInfo = API::FrameInfo::create(*initiatingFrame, securityOriginData.securityOrigin()); + + bool shouldOpenAppLinks = !hostsAreEqual(WebCore::URL(WebCore::ParsedURLString, initiatingFrame->url()), resourceRequest.url()); + auto apiNavigationAction = API::NavigationAction::create(navigationActionData, sourceFrameInfo.ptr(), nullptr, resourceRequest, WebCore::URL(), shouldOpenAppLinks); + + auto apiWindowFeatures = API::WindowFeatures::create(windowFeatures); + + return adoptRef(toImpl(m_client.createNewPage(toAPI(page), toAPI(configuration.ptr()), toAPI(apiNavigationAction.ptr()), toAPI(apiWindowFeatures.ptr()), m_client.base.clientInfo))); + } + + if (m_client.createNewPage_deprecatedForUseWithV1 || m_client.createNewPage_deprecatedForUseWithV0) { + API::Dictionary::MapType map; + if (windowFeatures.x) + map.set("x", API::Double::create(*windowFeatures.x)); + if (windowFeatures.y) + map.set("y", API::Double::create(*windowFeatures.y)); + if (windowFeatures.width) + map.set("width", API::Double::create(*windowFeatures.width)); + if (windowFeatures.height) + map.set("height", API::Double::create(*windowFeatures.height)); + map.set("menuBarVisible", API::Boolean::create(windowFeatures.menuBarVisible)); + map.set("statusBarVisible", API::Boolean::create(windowFeatures.statusBarVisible)); + map.set("toolBarVisible", API::Boolean::create(windowFeatures.toolBarVisible)); + map.set("locationBarVisible", API::Boolean::create(windowFeatures.locationBarVisible)); + map.set("scrollbarsVisible", API::Boolean::create(windowFeatures.scrollbarsVisible)); + map.set("resizable", API::Boolean::create(windowFeatures.resizable)); + map.set("fullscreen", API::Boolean::create(windowFeatures.fullscreen)); + map.set("dialog", API::Boolean::create(windowFeatures.dialog)); + Ref<API::Dictionary> featuresMap = API::Dictionary::create(WTFMove(map)); + + if (m_client.createNewPage_deprecatedForUseWithV1) { + Ref<API::URLRequest> request = API::URLRequest::create(resourceRequest); + return adoptRef(toImpl(m_client.createNewPage_deprecatedForUseWithV1(toAPI(page), toAPI(request.ptr()), toAPI(featuresMap.ptr()), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), m_client.base.clientInfo))); + } + + ASSERT(m_client.createNewPage_deprecatedForUseWithV0); + return adoptRef(toImpl(m_client.createNewPage_deprecatedForUseWithV0(toAPI(page), toAPI(featuresMap.ptr()), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), m_client.base.clientInfo))); + } + + return nullptr; + } + + virtual void showPage(WebPageProxy* page) override + { + if (!m_client.showPage) + return; + + m_client.showPage(toAPI(page), m_client.base.clientInfo); + } + + virtual void close(WebPageProxy* page) override + { + if (!m_client.close) + return; + + m_client.close(toAPI(page), m_client.base.clientInfo); + } + + virtual void takeFocus(WebPageProxy* page, WKFocusDirection direction) override + { + if (!m_client.takeFocus) + return; + + m_client.takeFocus(toAPI(page), direction, m_client.base.clientInfo); + } + + virtual void focus(WebPageProxy* page) override + { + if (!m_client.focus) + return; + + m_client.focus(toAPI(page), m_client.base.clientInfo); + } + + virtual void unfocus(WebPageProxy* page) override + { + if (!m_client.unfocus) + return; + + m_client.unfocus(toAPI(page), m_client.base.clientInfo); + } + + virtual void runJavaScriptAlert(WebPageProxy* page, const String& message, WebFrameProxy* frame, const SecurityOriginData& securityOriginData, std::function<void ()> completionHandler) override + { + if (m_client.runJavaScriptAlert) { + RefPtr<RunJavaScriptAlertResultListener> listener = RunJavaScriptAlertResultListener::create(WTFMove(completionHandler)); + RefPtr<API::SecurityOrigin> securityOrigin = API::SecurityOrigin::create(securityOriginData.protocol, securityOriginData.host, securityOriginData.port); + m_client.runJavaScriptAlert(toAPI(page), toAPI(message.impl()), toAPI(frame), toAPI(securityOrigin.get()), toAPI(listener.get()), m_client.base.clientInfo); + return; + } + + if (m_client.runJavaScriptAlert_deprecatedForUseWithV5) { + RefPtr<API::SecurityOrigin> securityOrigin = API::SecurityOrigin::create(securityOriginData.protocol, securityOriginData.host, securityOriginData.port); + m_client.runJavaScriptAlert_deprecatedForUseWithV5(toAPI(page), toAPI(message.impl()), toAPI(frame), toAPI(securityOrigin.get()), m_client.base.clientInfo); + completionHandler(); + return; + } + + if (m_client.runJavaScriptAlert_deprecatedForUseWithV0) { + m_client.runJavaScriptAlert_deprecatedForUseWithV0(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo); + completionHandler(); + return; + } + + + completionHandler(); + } + + virtual void runJavaScriptConfirm(WebPageProxy* page, const String& message, WebFrameProxy* frame, const SecurityOriginData& securityOriginData, std::function<void (bool)> completionHandler) override + { + if (m_client.runJavaScriptConfirm) { + RefPtr<RunJavaScriptConfirmResultListener> listener = RunJavaScriptConfirmResultListener::create(WTFMove(completionHandler)); + RefPtr<API::SecurityOrigin> securityOrigin = API::SecurityOrigin::create(securityOriginData.protocol, securityOriginData.host, securityOriginData.port); + m_client.runJavaScriptConfirm(toAPI(page), toAPI(message.impl()), toAPI(frame), toAPI(securityOrigin.get()), toAPI(listener.get()), m_client.base.clientInfo); + return; + } + + if (m_client.runJavaScriptConfirm_deprecatedForUseWithV5) { + RefPtr<API::SecurityOrigin> securityOrigin = API::SecurityOrigin::create(securityOriginData.protocol, securityOriginData.host, securityOriginData.port); + bool result = m_client.runJavaScriptConfirm_deprecatedForUseWithV5(toAPI(page), toAPI(message.impl()), toAPI(frame), toAPI(securityOrigin.get()), m_client.base.clientInfo); + + completionHandler(result); + return; + } + + if (m_client.runJavaScriptConfirm_deprecatedForUseWithV0) { + bool result = m_client.runJavaScriptConfirm_deprecatedForUseWithV0(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo); + + completionHandler(result); + return; + } + + completionHandler(false); + } + + virtual void runJavaScriptPrompt(WebPageProxy* page, const String& message, const String& defaultValue, WebFrameProxy* frame, const SecurityOriginData& securityOriginData, std::function<void (const String&)> completionHandler) override + { + if (m_client.runJavaScriptPrompt) { + RefPtr<RunJavaScriptPromptResultListener> listener = RunJavaScriptPromptResultListener::create(WTFMove(completionHandler)); + RefPtr<API::SecurityOrigin> securityOrigin = API::SecurityOrigin::create(securityOriginData.protocol, securityOriginData.host, securityOriginData.port); + m_client.runJavaScriptPrompt(toAPI(page), toAPI(message.impl()), toAPI(defaultValue.impl()), toAPI(frame), toAPI(securityOrigin.get()), toAPI(listener.get()), m_client.base.clientInfo); + return; + } + + if (m_client.runJavaScriptPrompt_deprecatedForUseWithV5) { + RefPtr<API::SecurityOrigin> securityOrigin = API::SecurityOrigin::create(securityOriginData.protocol, securityOriginData.host, securityOriginData.port); + RefPtr<API::String> string = adoptRef(toImpl(m_client.runJavaScriptPrompt_deprecatedForUseWithV5(toAPI(page), toAPI(message.impl()), toAPI(defaultValue.impl()), toAPI(frame), toAPI(securityOrigin.get()), m_client.base.clientInfo))); + + if (string) + completionHandler(string->string()); + else + completionHandler(String()); + return; + } + + if (m_client.runJavaScriptPrompt_deprecatedForUseWithV0) { + RefPtr<API::String> string = adoptRef(toImpl(m_client.runJavaScriptPrompt_deprecatedForUseWithV0(toAPI(page), toAPI(message.impl()), toAPI(defaultValue.impl()), toAPI(frame), m_client.base.clientInfo))); + + if (string) + completionHandler(string->string()); + else + completionHandler(String()); + return; + } + + completionHandler(String()); + } + + virtual void setStatusText(WebPageProxy* page, const String& text) override + { + if (!m_client.setStatusText) + return; + + m_client.setStatusText(toAPI(page), toAPI(text.impl()), m_client.base.clientInfo); + } + + virtual void mouseDidMoveOverElement(WebPageProxy* page, const WebHitTestResultData& data, WebEvent::Modifiers modifiers, API::Object* userData) override + { + if (!m_client.mouseDidMoveOverElement && !m_client.mouseDidMoveOverElement_deprecatedForUseWithV0) + return; + + if (m_client.base.version > 0 && !m_client.mouseDidMoveOverElement) + return; + + if (!m_client.base.version) { + m_client.mouseDidMoveOverElement_deprecatedForUseWithV0(toAPI(page), toAPI(modifiers), toAPI(userData), m_client.base.clientInfo); + return; + } + + RefPtr<API::HitTestResult> webHitTestResult = API::HitTestResult::create(data); + m_client.mouseDidMoveOverElement(toAPI(page), toAPI(webHitTestResult.get()), toAPI(modifiers), toAPI(userData), m_client.base.clientInfo); + } + +#if ENABLE(NETSCAPE_PLUGIN_API) + virtual void unavailablePluginButtonClicked(WebPageProxy* page, WKPluginUnavailabilityReason pluginUnavailabilityReason, API::Dictionary* pluginInformation) override + { + if (pluginUnavailabilityReason == kWKPluginUnavailabilityReasonPluginMissing) { + if (m_client.missingPluginButtonClicked_deprecatedForUseWithV0) + m_client.missingPluginButtonClicked_deprecatedForUseWithV0( + toAPI(page), + toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), + toAPI(pluginInformation->get<API::String>(pluginInformationPluginURLKey())), + toAPI(pluginInformation->get<API::String>(pluginInformationPluginspageAttributeURLKey())), + m_client.base.clientInfo); + } + + if (m_client.unavailablePluginButtonClicked_deprecatedForUseWithV1) + m_client.unavailablePluginButtonClicked_deprecatedForUseWithV1( + toAPI(page), + pluginUnavailabilityReason, + toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), + toAPI(pluginInformation->get<API::String>(pluginInformationPluginURLKey())), + toAPI(pluginInformation->get<API::String>(pluginInformationPluginspageAttributeURLKey())), + m_client.base.clientInfo); + + if (m_client.unavailablePluginButtonClicked) + m_client.unavailablePluginButtonClicked( + toAPI(page), + pluginUnavailabilityReason, + toAPI(pluginInformation), + m_client.base.clientInfo); + } +#endif // ENABLE(NETSCAPE_PLUGIN_API) + + virtual bool implementsDidNotHandleKeyEvent() const override + { + return m_client.didNotHandleKeyEvent; + } + + virtual void didNotHandleKeyEvent(WebPageProxy* page, const NativeWebKeyboardEvent& event) override + { + if (!m_client.didNotHandleKeyEvent) + return; + m_client.didNotHandleKeyEvent(toAPI(page), event.nativeEvent(), m_client.base.clientInfo); + } + + virtual bool implementsDidNotHandleWheelEvent() const override + { + return m_client.didNotHandleWheelEvent; + } + + virtual void didNotHandleWheelEvent(WebPageProxy* page, const NativeWebWheelEvent& event) override + { + if (!m_client.didNotHandleWheelEvent) + return; + m_client.didNotHandleWheelEvent(toAPI(page), event.nativeEvent(), m_client.base.clientInfo); + } + + virtual bool toolbarsAreVisible(WebPageProxy* page) override + { + if (!m_client.toolbarsAreVisible) + return true; + return m_client.toolbarsAreVisible(toAPI(page), m_client.base.clientInfo); + } + + virtual void setToolbarsAreVisible(WebPageProxy* page, bool visible) override + { + if (!m_client.setToolbarsAreVisible) + return; + m_client.setToolbarsAreVisible(toAPI(page), visible, m_client.base.clientInfo); + } + + virtual bool menuBarIsVisible(WebPageProxy* page) override + { + if (!m_client.menuBarIsVisible) + return true; + return m_client.menuBarIsVisible(toAPI(page), m_client.base.clientInfo); + } + + virtual void setMenuBarIsVisible(WebPageProxy* page, bool visible) override + { + if (!m_client.setMenuBarIsVisible) + return; + m_client.setMenuBarIsVisible(toAPI(page), visible, m_client.base.clientInfo); + } + + virtual bool statusBarIsVisible(WebPageProxy* page) override + { + if (!m_client.statusBarIsVisible) + return true; + return m_client.statusBarIsVisible(toAPI(page), m_client.base.clientInfo); + } + + virtual void setStatusBarIsVisible(WebPageProxy* page, bool visible) override + { + if (!m_client.setStatusBarIsVisible) + return; + m_client.setStatusBarIsVisible(toAPI(page), visible, m_client.base.clientInfo); + } + + virtual bool isResizable(WebPageProxy* page) override + { + if (!m_client.isResizable) + return true; + return m_client.isResizable(toAPI(page), m_client.base.clientInfo); + } + + virtual void setIsResizable(WebPageProxy* page, bool resizable) override + { + if (!m_client.setIsResizable) + return; + m_client.setIsResizable(toAPI(page), resizable, m_client.base.clientInfo); + } + + virtual void setWindowFrame(WebPageProxy* page, const FloatRect& frame) override + { + if (!m_client.setWindowFrame) + return; + + m_client.setWindowFrame(toAPI(page), toAPI(frame), m_client.base.clientInfo); + } + + virtual FloatRect windowFrame(WebPageProxy* page) override + { + if (!m_client.getWindowFrame) + return FloatRect(); + + return toFloatRect(m_client.getWindowFrame(toAPI(page), m_client.base.clientInfo)); + } + + virtual bool canRunBeforeUnloadConfirmPanel() const override + { + return m_client.runBeforeUnloadConfirmPanel_deprecatedForUseWithV6 || m_client.runBeforeUnloadConfirmPanel; + } + + virtual void runBeforeUnloadConfirmPanel(WebKit::WebPageProxy* page, const WTF::String& message, WebKit::WebFrameProxy* frame, std::function<void (bool)> completionHandler) override + { + if (m_client.runBeforeUnloadConfirmPanel) { + RefPtr<RunBeforeUnloadConfirmPanelResultListener> listener = RunBeforeUnloadConfirmPanelResultListener::create(WTFMove(completionHandler)); + m_client.runBeforeUnloadConfirmPanel(toAPI(page), toAPI(message.impl()), toAPI(frame), toAPI(listener.get()), m_client.base.clientInfo); + return; + } + + if (m_client.runBeforeUnloadConfirmPanel_deprecatedForUseWithV6) { + bool result = m_client.runBeforeUnloadConfirmPanel_deprecatedForUseWithV6(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo); + completionHandler(result); + return; + } + + completionHandler(true); + } + + virtual void pageDidScroll(WebPageProxy* page) override + { + if (!m_client.pageDidScroll) + return; + + m_client.pageDidScroll(toAPI(page), m_client.base.clientInfo); + } + + virtual void exceededDatabaseQuota(WebPageProxy* page, WebFrameProxy* frame, API::SecurityOrigin* origin, const String& databaseName, const String& databaseDisplayName, unsigned long long currentQuota, unsigned long long currentOriginUsage, unsigned long long currentDatabaseUsage, unsigned long long expectedUsage, std::function<void (unsigned long long)> completionHandler) override + { + if (!m_client.exceededDatabaseQuota) { + completionHandler(currentQuota); + return; + } + + completionHandler(m_client.exceededDatabaseQuota(toAPI(page), toAPI(frame), toAPI(origin), toAPI(databaseName.impl()), toAPI(databaseDisplayName.impl()), currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage, m_client.base.clientInfo)); + } + + virtual bool runOpenPanel(WebPageProxy* page, WebFrameProxy* frame, WebOpenPanelParameters* parameters, WebOpenPanelResultListenerProxy* listener) override + { + if (!m_client.runOpenPanel) + return false; + + m_client.runOpenPanel(toAPI(page), toAPI(frame), toAPI(parameters), toAPI(listener), m_client.base.clientInfo); + return true; + } + + virtual bool decidePolicyForGeolocationPermissionRequest(WebPageProxy* page, WebFrameProxy* frame, API::SecurityOrigin* origin, GeolocationPermissionRequestProxy* permissionRequest) override + { + if (!m_client.decidePolicyForGeolocationPermissionRequest) + return false; + + m_client.decidePolicyForGeolocationPermissionRequest(toAPI(page), toAPI(frame), toAPI(origin), toAPI(permissionRequest), m_client.base.clientInfo); + return true; + } + + virtual bool decidePolicyForUserMediaPermissionRequest(WebPageProxy& page, WebFrameProxy& frame, API::SecurityOrigin& origin, UserMediaPermissionRequestProxy& permissionRequest) override + { + if (!m_client.decidePolicyForUserMediaPermissionRequest) + return false; + + m_client.decidePolicyForUserMediaPermissionRequest(toAPI(&page), toAPI(&frame), toAPI(&origin), toAPI(&permissionRequest), m_client.base.clientInfo); + return true; + } + + virtual bool checkUserMediaPermissionForOrigin(WebPageProxy& page, WebFrameProxy& frame, API::SecurityOrigin& origin, UserMediaPermissionCheckProxy& request) override + { + if (!m_client.checkUserMediaPermissionForOrigin) + return false; + + m_client.checkUserMediaPermissionForOrigin(toAPI(&page), toAPI(&frame), toAPI(&origin), toAPI(&request), m_client.base.clientInfo); + return true; + } + + virtual bool decidePolicyForNotificationPermissionRequest(WebPageProxy* page, API::SecurityOrigin* origin, NotificationPermissionRequest* permissionRequest) override + { + if (!m_client.decidePolicyForNotificationPermissionRequest) + return false; + + m_client.decidePolicyForNotificationPermissionRequest(toAPI(page), toAPI(origin), toAPI(permissionRequest), m_client.base.clientInfo); + return true; + } + + // Printing. + virtual float headerHeight(WebPageProxy* page, WebFrameProxy* frame) override + { + if (!m_client.headerHeight) + return 0; + + return m_client.headerHeight(toAPI(page), toAPI(frame), m_client.base.clientInfo); + } + + virtual float footerHeight(WebPageProxy* page, WebFrameProxy* frame) override + { + if (!m_client.footerHeight) + return 0; + + return m_client.footerHeight(toAPI(page), toAPI(frame), m_client.base.clientInfo); + } + + virtual void drawHeader(WebPageProxy* page, WebFrameProxy* frame, const WebCore::FloatRect& rect) override + { + if (!m_client.drawHeader) + return; + + m_client.drawHeader(toAPI(page), toAPI(frame), toAPI(rect), m_client.base.clientInfo); + } + + virtual void drawFooter(WebPageProxy* page, WebFrameProxy* frame, const WebCore::FloatRect& rect) override + { + if (!m_client.drawFooter) + return; + + m_client.drawFooter(toAPI(page), toAPI(frame), toAPI(rect), m_client.base.clientInfo); + } + + virtual void printFrame(WebPageProxy* page, WebFrameProxy* frame) override + { + if (!m_client.printFrame) + return; + + m_client.printFrame(toAPI(page), toAPI(frame), m_client.base.clientInfo); + } + + virtual bool canRunModal() const override + { + return m_client.runModal; + } + + virtual void runModal(WebPageProxy* page) override + { + if (!m_client.runModal) + return; + + m_client.runModal(toAPI(page), m_client.base.clientInfo); + } + + virtual void saveDataToFileInDownloadsFolder(WebPageProxy* page, const String& suggestedFilename, const String& mimeType, const String& originatingURLString, API::Data* data) override + { + if (!m_client.saveDataToFileInDownloadsFolder) + return; + + m_client.saveDataToFileInDownloadsFolder(toAPI(page), toAPI(suggestedFilename.impl()), toAPI(mimeType.impl()), toURLRef(originatingURLString.impl()), toAPI(data), m_client.base.clientInfo); + } + + virtual void pinnedStateDidChange(WebPageProxy& page) override + { + if (!m_client.pinnedStateDidChange) + return; + + m_client.pinnedStateDidChange(toAPI(&page), m_client.base.clientInfo); + } + + virtual void isPlayingAudioDidChange(WebPageProxy& page) override + { + if (!m_client.isPlayingAudioDidChange) + return; + + m_client.isPlayingAudioDidChange(toAPI(&page), m_client.base.clientInfo); + } + + virtual void didClickAutoFillButton(WebPageProxy& page, API::Object* userInfo) override + { + if (!m_client.didClickAutoFillButton) + return; + + m_client.didClickAutoFillButton(toAPI(&page), toAPI(userInfo), m_client.base.clientInfo); + } + +#if ENABLE(MEDIA_SESSION) + virtual void mediaSessionMetadataDidChange(WebPageProxy& page, WebMediaSessionMetadata* metadata) override + { + if (!m_client.mediaSessionMetadataDidChange) + return; + + m_client.mediaSessionMetadataDidChange(toAPI(&page), toAPI(metadata), m_client.base.clientInfo); + } +#endif + }; + + toImpl(pageRef)->setUIClient(std::make_unique<UIClient>(wkClient)); +} + +void WKPageSetPageNavigationClient(WKPageRef pageRef, const WKPageNavigationClientBase* wkClient) +{ + class NavigationClient : public API::Client<WKPageNavigationClientBase>, public API::NavigationClient { + public: + explicit NavigationClient(const WKPageNavigationClientBase* client) + { + initialize(client); + } + + private: + virtual void decidePolicyForNavigationAction(WebPageProxy& page, API::NavigationAction& navigationAction, Ref<WebKit::WebFramePolicyListenerProxy>&& listener, API::Object* userData) override + { + if (!m_client.decidePolicyForNavigationAction) + return; + m_client.decidePolicyForNavigationAction(toAPI(&page), toAPI(&navigationAction), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo); + } + + virtual void decidePolicyForNavigationResponse(WebPageProxy& page, API::NavigationResponse& navigationResponse, Ref<WebKit::WebFramePolicyListenerProxy>&& listener, API::Object* userData) override + { + if (!m_client.decidePolicyForNavigationResponse) + return; + m_client.decidePolicyForNavigationResponse(toAPI(&page), toAPI(&navigationResponse), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo); + } + + virtual void didStartProvisionalNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override + { + if (!m_client.didStartProvisionalNavigation) + return; + m_client.didStartProvisionalNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo); + } + + virtual void didReceiveServerRedirectForProvisionalNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override + { + if (!m_client.didReceiveServerRedirectForProvisionalNavigation) + return; + m_client.didReceiveServerRedirectForProvisionalNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo); + } + + virtual void didFailProvisionalNavigationWithError(WebPageProxy& page, WebFrameProxy&, API::Navigation* navigation, const WebCore::ResourceError& error, API::Object* userData) override + { + if (!m_client.didFailProvisionalNavigation) + return; + m_client.didFailProvisionalNavigation(toAPI(&page), toAPI(navigation), toAPI(error), toAPI(userData), m_client.base.clientInfo); + } + + virtual void didCommitNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override + { + if (!m_client.didCommitNavigation) + return; + m_client.didCommitNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo); + } + + virtual void didFinishNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override + { + if (!m_client.didFinishNavigation) + return; + m_client.didFinishNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo); + } + + virtual void didFailNavigationWithError(WebPageProxy& page, WebFrameProxy&, API::Navigation* navigation, const WebCore::ResourceError& error, API::Object* userData) override + { + if (!m_client.didFailNavigation) + return; + m_client.didFailNavigation(toAPI(&page), toAPI(navigation), toAPI(error), toAPI(userData), m_client.base.clientInfo); + } + + virtual void didFailProvisionalLoadInSubframeWithError(WebPageProxy& page, WebFrameProxy& subframe, const WebCore::SecurityOriginData& securityOriginData, API::Navigation* navigation, const WebCore::ResourceError& error, API::Object* userData) override + { + if (!m_client.didFailProvisionalLoadInSubframe) + return; + m_client.didFailProvisionalLoadInSubframe(toAPI(&page), toAPI(navigation), toAPI(API::FrameInfo::create(subframe, securityOriginData.securityOrigin()).ptr()), toAPI(error), toAPI(userData), m_client.base.clientInfo); + } + + virtual void didFinishDocumentLoad(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override + { + if (!m_client.didFinishDocumentLoad) + return; + m_client.didFinishDocumentLoad(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo); + } + + virtual void didSameDocumentNavigation(WebPageProxy& page, API::Navigation* navigation, WebKit::SameDocumentNavigationType navigationType, API::Object* userData) override + { + if (!m_client.didSameDocumentNavigation) + return; + m_client.didSameDocumentNavigation(toAPI(&page), toAPI(navigation), toAPI(navigationType), toAPI(userData), m_client.base.clientInfo); + } + + virtual void renderingProgressDidChange(WebPageProxy& page, WebCore::LayoutMilestones milestones) override + { + if (!m_client.renderingProgressDidChange) + return; + m_client.renderingProgressDidChange(toAPI(&page), pageRenderingProgressEvents(milestones), nullptr, m_client.base.clientInfo); + } + + virtual bool canAuthenticateAgainstProtectionSpace(WebPageProxy& page, WebProtectionSpace* protectionSpace) override + { + if (!m_client.canAuthenticateAgainstProtectionSpace) + return false; + return m_client.canAuthenticateAgainstProtectionSpace(toAPI(&page), toAPI(protectionSpace), m_client.base.clientInfo); + } + + virtual void didReceiveAuthenticationChallenge(WebPageProxy& page, AuthenticationChallengeProxy* authenticationChallenge) override + { + if (!m_client.didReceiveAuthenticationChallenge) + return; + m_client.didReceiveAuthenticationChallenge(toAPI(&page), toAPI(authenticationChallenge), m_client.base.clientInfo); + } + + virtual void processDidCrash(WebPageProxy& page) override + { + if (!m_client.webProcessDidCrash) + return; + m_client.webProcessDidCrash(toAPI(&page), m_client.base.clientInfo); + } + + virtual RefPtr<API::Data> webCryptoMasterKey(WebPageProxy& page) override + { + if (!m_client.copyWebCryptoMasterKey) + return nullptr; + return adoptRef(toImpl(m_client.copyWebCryptoMasterKey(toAPI(&page), m_client.base.clientInfo))); + } + + virtual void didBeginNavigationGesture(WebPageProxy& page) override + { + if (!m_client.didBeginNavigationGesture) + return; + m_client.didBeginNavigationGesture(toAPI(&page), m_client.base.clientInfo); + } + + virtual void didEndNavigationGesture(WebPageProxy& page, bool willNavigate, WebKit::WebBackForwardListItem& item) override + { + if (!m_client.didEndNavigationGesture) + return; + m_client.didEndNavigationGesture(toAPI(&page), willNavigate ? toAPI(&item) : nullptr, m_client.base.clientInfo); + } + + virtual void willEndNavigationGesture(WebPageProxy& page, bool willNavigate, WebKit::WebBackForwardListItem& item) override + { + if (!m_client.willEndNavigationGesture) + return; + m_client.willEndNavigationGesture(toAPI(&page), willNavigate ? toAPI(&item) : nullptr, m_client.base.clientInfo); + } + + virtual void didRemoveNavigationGestureSnapshot(WebPageProxy& page) override + { + if (!m_client.didRemoveNavigationGestureSnapshot) + return; + m_client.didRemoveNavigationGestureSnapshot(toAPI(&page), m_client.base.clientInfo); + } + +#if ENABLE(NETSCAPE_PLUGIN_API) + virtual PluginModuleLoadPolicy decidePolicyForPluginLoad(WebPageProxy& page, PluginModuleLoadPolicy currentPluginLoadPolicy, API::Dictionary* pluginInformation, String& unavailabilityDescription) override + { + WKStringRef unavailabilityDescriptionOut = 0; + PluginModuleLoadPolicy loadPolicy = currentPluginLoadPolicy; + + if (m_client.decidePolicyForPluginLoad) + loadPolicy = toPluginModuleLoadPolicy(m_client.decidePolicyForPluginLoad(toAPI(&page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), &unavailabilityDescriptionOut, m_client.base.clientInfo)); + + if (unavailabilityDescriptionOut) { + RefPtr<API::String> webUnavailabilityDescription = adoptRef(toImpl(unavailabilityDescriptionOut)); + unavailabilityDescription = webUnavailabilityDescription->string(); + } + + return loadPolicy; + } +#endif + }; + + WebPageProxy* webPageProxy = toImpl(pageRef); + + auto navigationClient = std::make_unique<NavigationClient>(wkClient); + webPageProxy->setNavigationClient(WTFMove(navigationClient)); } void WKPageSetSession(WKPageRef pageRef, WKSessionRef session) { - toImpl(pageRef)->setSession(*toImpl(session)); + toImpl(pageRef)->setSessionID(toImpl(session)->getID()); } void WKPageRunJavaScriptInMainFrame(WKPageRef pageRef, WKStringRef scriptRef, void* context, WKPageRunJavaScriptFunction callback) { - toImpl(pageRef)->runJavaScriptInMainFrame(toImpl(scriptRef)->string(), ScriptValueCallback::create(context, callback)); + toImpl(pageRef)->runJavaScriptInMainFrame(toImpl(scriptRef)->string(), [context, callback](API::SerializedScriptValue* returnValue, bool, const WebCore::ExceptionDetails&, CallbackBase::Error error) { + callback(toAPI(returnValue), (error != CallbackBase::Error::None) ? toAPI(API::Error::create().ptr()) : 0, context); + }); } #ifdef __BLOCKS__ @@ -1080,33 +2391,51 @@ void WKPageRunJavaScriptInMainFrame_b(WKPageRef pageRef, WKStringRef scriptRef, } #endif +static std::function<void (const String&, WebKit::CallbackBase::Error)> toGenericCallbackFunction(void* context, void (*callback)(WKStringRef, WKErrorRef, void*)) +{ + return [context, callback](const String& returnValue, WebKit::CallbackBase::Error error) { + callback(toAPI(API::String::create(returnValue).ptr()), error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context); + }; +} + void WKPageRenderTreeExternalRepresentation(WKPageRef pageRef, void* context, WKPageRenderTreeExternalRepresentationFunction callback) { - toImpl(pageRef)->getRenderTreeExternalRepresentation(StringCallback::create(context, callback)); + toImpl(pageRef)->getRenderTreeExternalRepresentation(toGenericCallbackFunction(context, callback)); } void WKPageGetSourceForFrame(WKPageRef pageRef, WKFrameRef frameRef, void* context, WKPageGetSourceForFrameFunction callback) { - toImpl(pageRef)->getSourceForFrame(toImpl(frameRef), StringCallback::create(context, callback)); + toImpl(pageRef)->getSourceForFrame(toImpl(frameRef), toGenericCallbackFunction(context, callback)); } void WKPageGetContentsAsString(WKPageRef pageRef, void* context, WKPageGetContentsAsStringFunction callback) { - toImpl(pageRef)->getContentsAsString(StringCallback::create(context, callback)); + toImpl(pageRef)->getContentsAsString(toGenericCallbackFunction(context, callback)); +} + +void WKPageGetBytecodeProfile(WKPageRef pageRef, void* context, WKPageGetBytecodeProfileFunction callback) +{ + toImpl(pageRef)->getBytecodeProfile(toGenericCallbackFunction(context, callback)); +} + +void WKPageIsWebProcessResponsive(WKPageRef pageRef, void* context, WKPageIsWebProcessResponsiveFunction callback) +{ + toImpl(pageRef)->isWebProcessResponsive([context, callback](bool isWebProcessResponsive) { + callback(isWebProcessResponsive, context); + }); } void WKPageGetSelectionAsWebArchiveData(WKPageRef pageRef, void* context, WKPageGetSelectionAsWebArchiveDataFunction callback) { - toImpl(pageRef)->getSelectionAsWebArchiveData(DataCallback::create(context, callback)); + toImpl(pageRef)->getSelectionAsWebArchiveData(toGenericCallbackFunction(context, callback)); } -void WKPageGetContentsAsMHTMLData(WKPageRef pageRef, bool useBinaryEncoding, void* context, WKPageGetContentsAsMHTMLDataFunction callback) +void WKPageGetContentsAsMHTMLData(WKPageRef pageRef, void* context, WKPageGetContentsAsMHTMLDataFunction callback) { #if ENABLE(MHTML) - toImpl(pageRef)->getContentsAsMHTMLData(DataCallback::create(context, callback), useBinaryEncoding); + toImpl(pageRef)->getContentsAsMHTMLData(toGenericCallbackFunction(context, callback)); #else UNUSED_PARAM(pageRef); - UNUSED_PARAM(useBinaryEncoding); UNUSED_PARAM(context); UNUSED_PARAM(callback); #endif @@ -1114,7 +2443,9 @@ void WKPageGetContentsAsMHTMLData(WKPageRef pageRef, bool useBinaryEncoding, voi void WKPageForceRepaint(WKPageRef pageRef, void* context, WKPageForceRepaintFunction callback) { - toImpl(pageRef)->forceRepaint(VoidCallback::create(context, callback)); + toImpl(pageRef)->forceRepaint(VoidCallback::create([context, callback](WebKit::CallbackBase::Error error) { + callback(error == WebKit::CallbackBase::Error::None ? nullptr : toAPI(API::Error::create().ptr()), context); + })); } WK_EXPORT WKURLRef WKPageCopyPendingAPIRequestURL(WKPageRef pageRef) @@ -1149,7 +2480,9 @@ WKStringRef WKPageCopyStandardUserAgentWithApplicationName(WKStringRef applicati void WKPageValidateCommand(WKPageRef pageRef, WKStringRef command, void* context, WKPageValidateCommandCallback callback) { - toImpl(pageRef)->validateCommand(toImpl(command)->string(), ValidateCommandCallback::create(context, callback)); + toImpl(pageRef)->validateCommand(toImpl(command)->string(), [context, callback](const String& commandName, bool isEnabled, int32_t state, WebKit::CallbackBase::Error error) { + callback(toAPI(API::String::create(commandName).ptr()), isEnabled, state, error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context); + }); } void WKPageExecuteCommand(WKPageRef pageRef, WKStringRef command) @@ -1157,26 +2490,7 @@ void WKPageExecuteCommand(WKPageRef pageRef, WKStringRef command) toImpl(pageRef)->executeEditCommand(toImpl(command)->string()); } -#if PLATFORM(MAC) -struct ComputedPagesContext { - ComputedPagesContext(WKPageComputePagesForPrintingFunction callback, void* context) - : callback(callback) - , context(context) - { - } - WKPageComputePagesForPrintingFunction callback; - void* context; -}; - -static void computedPagesCallback(const Vector<WebCore::IntRect>& rects, double scaleFactor, WKErrorRef error, void* untypedContext) -{ - OwnPtr<ComputedPagesContext> context = adoptPtr(static_cast<ComputedPagesContext*>(untypedContext)); - Vector<WKRect> wkRects(rects.size()); - for (size_t i = 0; i < rects.size(); ++i) - wkRects[i] = toAPI(rects[i]); - context->callback(wkRects.data(), wkRects.size(), scaleFactor, error, context->context); -} - +#if PLATFORM(COCOA) static PrintInfo printInfoFromWKPrintInfo(const WKPrintInfo& printInfo) { PrintInfo result; @@ -1188,7 +2502,12 @@ static PrintInfo printInfoFromWKPrintInfo(const WKPrintInfo& printInfo) void WKPageComputePagesForPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo, WKPageComputePagesForPrintingFunction callback, void* context) { - toImpl(page)->computePagesForPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo), ComputedPagesCallback::create(new ComputedPagesContext(callback, context), computedPagesCallback)); + toImpl(page)->computePagesForPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo), ComputedPagesCallback::create([context, callback](const Vector<WebCore::IntRect>& rects, double scaleFactor, WebKit::CallbackBase::Error error) { + Vector<WKRect> wkRects(rects.size()); + for (size_t i = 0; i < rects.size(); ++i) + wkRects[i] = toAPI(rects[i]); + callback(wkRects.data(), wkRects.size(), scaleFactor, error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context); + })); } void WKPageBeginPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo) @@ -1198,7 +2517,7 @@ void WKPageBeginPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo void WKPageDrawPagesToPDF(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo, uint32_t first, uint32_t count, WKPageDrawToPDFFunction callback, void* context) { - toImpl(page)->drawPagesToPDF(toImpl(frame), printInfoFromWKPrintInfo(printInfo), first, count, DataCallback::create(context, callback)); + toImpl(page)->drawPagesToPDF(toImpl(frame), printInfoFromWKPrintInfo(printInfo), first, count, DataCallback::create(toGenericCallbackFunction(context, callback))); } void WKPageEndPrinting(WKPageRef page) @@ -1207,14 +2526,24 @@ void WKPageEndPrinting(WKPageRef page) } #endif -WKImageRef WKPageCreateSnapshotOfVisibleContent(WKPageRef) +bool WKPageGetAllowsRemoteInspection(WKPageRef page) { - return 0; +#if ENABLE(REMOTE_INSPECTOR) + return toImpl(page)->allowsRemoteInspection(); +#else + UNUSED_PARAM(page); + return false; +#endif } -void WKPageSetShouldSendEventsSynchronously(WKPageRef page, bool sync) +void WKPageSetAllowsRemoteInspection(WKPageRef page, bool allow) { - toImpl(page)->setShouldSendEventsSynchronously(sync); +#if ENABLE(REMOTE_INSPECTOR) + toImpl(page)->setAllowsRemoteInspection(allow); +#else + UNUSED_PARAM(page); + UNUSED_PARAM(allow); +#endif } void WKPageSetMediaVolume(WKPageRef page, float volume) @@ -1222,6 +2551,48 @@ void WKPageSetMediaVolume(WKPageRef page, float volume) toImpl(page)->setMediaVolume(volume); } +void WKPageSetMuted(WKPageRef page, bool muted) +{ + toImpl(page)->setMuted(muted); +} + +bool WKPageHasMediaSessionWithActiveMediaElements(WKPageRef page) +{ +#if ENABLE(MEDIA_SESSION) + return toImpl(page)->hasMediaSessionWithActiveMediaElements(); +#else + UNUSED_PARAM(page); + return false; +#endif +} + +void WKPageHandleMediaEvent(WKPageRef page, WKMediaEventType wkEventType) +{ +#if ENABLE(MEDIA_SESSION) + MediaEventType eventType; + + switch (wkEventType) { + case kWKMediaEventTypePlayPause: + eventType = MediaEventType::PlayPause; + break; + case kWKMediaEventTypeTrackNext: + eventType = MediaEventType::TrackNext; + break; + case kWKMediaEventTypeTrackPrevious: + eventType = MediaEventType::TrackPrevious; + break; + default: + ASSERT_NOT_REACHED(); + return; + } + + toImpl(page)->handleMediaEvent(eventType); +#else + UNUSED_PARAM(page); + UNUSED_PARAM(wkEventType); +#endif +} + void WKPagePostMessageToInjectedBundle(WKPageRef pageRef, WKStringRef messageNameRef, WKTypeRef messageBodyRef) { toImpl(pageRef)->postMessageToInjectedBundle(toImpl(messageNameRef)->string(), toImpl(messageBodyRef)); @@ -1229,7 +2600,14 @@ void WKPagePostMessageToInjectedBundle(WKPageRef pageRef, WKStringRef messageNam WKArrayRef WKPageCopyRelatedPages(WKPageRef pageRef) { - return toAPI(toImpl(pageRef)->relatedPages().leakRef()); + Vector<RefPtr<API::Object>> relatedPages; + + for (auto& page : toImpl(pageRef)->process().pages()) { + if (page != toImpl(pageRef)) + relatedPages.append(page); + } + + return toAPI(&API::Array::create(WTFMove(relatedPages)).leakRef()); } void WKPageSetMayStartMediaWhenInWindow(WKPageRef pageRef, bool mayStartMedia) @@ -1241,7 +2619,7 @@ void WKPageSetMayStartMediaWhenInWindow(WKPageRef pageRef, bool mayStartMedia) void WKPageSelectContextMenuItem(WKPageRef page, WKContextMenuItemRef item) { #if ENABLE(CONTEXT_MENUS) - toImpl(page)->contextMenuItemSelected(*(toImpl(item)->data())); + toImpl(page)->contextMenuItemSelected((toImpl(item)->data())); #else UNUSED_PARAM(page); UNUSED_PARAM(item); @@ -1286,9 +2664,31 @@ void WKPageSetScrollPinningBehavior(WKPageRef page, WKScrollPinningBehavior pinn toImpl(page)->setScrollPinningBehavior(corePinning); } -void WKPageSetInvalidMessageFunction(WKPageInvalidMessageFunction) +bool WKPageGetAddsVisitedLinks(WKPageRef page) +{ + return toImpl(page)->addsVisitedLinks(); +} + +void WKPageSetAddsVisitedLinks(WKPageRef page, bool addsVisitedLinks) +{ + toImpl(page)->setAddsVisitedLinks(addsVisitedLinks); +} + +bool WKPageIsPlayingAudio(WKPageRef page) +{ + return toImpl(page)->isPlayingAudio(); +} + +void WKPageClearWheelEventTestTrigger(WKPageRef pageRef) +{ + toImpl(pageRef)->clearWheelEventTestTrigger(); +} + +void WKPageCallAfterNextPresentationUpdate(WKPageRef pageRef, void* context, WKPagePostPresentationUpdateFunction callback) { - // FIXME: Remove this function when doing so won't break WebKit nightlies. + toImpl(pageRef)->callAfterNextPresentationUpdate([context, callback](WebKit::CallbackBase::Error error) { + callback(error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context); + }); } #if ENABLE(NETSCAPE_PLUGIN_API) diff --git a/Source/WebKit2/UIProcess/API/C/WKPage.h b/Source/WebKit2/UIProcess/API/C/WKPage.h index 216a8ff45..59709495d 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPage.h +++ b/Source/WebKit2/UIProcess/API/C/WKPage.h @@ -26,22 +26,25 @@ #ifndef WKPage_h #define WKPage_h -#include <WebKit2/WKBase.h> -#include <WebKit2/WKError.h> -#include <WebKit2/WKEvent.h> -#include <WebKit2/WKFindOptions.h> -#include <WebKit2/WKGeometry.h> -#include <WebKit2/WKNativeEvent.h> -#include <WebKit2/WKPageContextMenuClient.h> -#include <WebKit2/WKPageFindClient.h> -#include <WebKit2/WKPageFindMatchesClient.h> -#include <WebKit2/WKPageFormClient.h> -#include <WebKit2/WKPageLoadTypes.h> -#include <WebKit2/WKPageLoaderClient.h> -#include <WebKit2/WKPagePolicyClient.h> -#include <WebKit2/WKPageUIClient.h> -#include <WebKit2/WKPageVisibilityTypes.h> -#include <WebKit2/WKSessionRef.h> +#include <WebKit/WKBase.h> +#include <WebKit/WKErrorRef.h> +#include <WebKit/WKEvent.h> +#include <WebKit/WKFindOptions.h> +#include <WebKit/WKGeometry.h> +#include <WebKit/WKNativeEvent.h> +#include <WebKit/WKPageContextMenuClient.h> +#include <WebKit/WKPageDiagnosticLoggingClient.h> +#include <WebKit/WKPageFindClient.h> +#include <WebKit/WKPageFindMatchesClient.h> +#include <WebKit/WKPageFormClient.h> +#include <WebKit/WKPageInjectedBundleClient.h> +#include <WebKit/WKPageLoadTypes.h> +#include <WebKit/WKPageLoaderClient.h> +#include <WebKit/WKPageNavigationClient.h> +#include <WebKit/WKPagePolicyClient.h> +#include <WebKit/WKPageUIClient.h> +#include <WebKit/WKPageVisibilityTypes.h> +#include <WebKit/WKSessionRef.h> #ifndef __cplusplus #include <stdbool.h> @@ -56,6 +59,8 @@ WK_EXPORT WKTypeID WKPageGetTypeID(); WK_EXPORT WKContextRef WKPageGetContext(WKPageRef page); WK_EXPORT WKPageGroupRef WKPageGetPageGroup(WKPageRef page); +WK_EXPORT WKPageConfigurationRef WKPageCopyPageConfiguration(WKPageRef page); + // URL Requests WK_EXPORT void WKPageLoadURL(WKPageRef page, WKURLRef url); WK_EXPORT void WKPageLoadURLWithUserData(WKPageRef page, WKURLRef url, WKTypeRef userData); @@ -78,6 +83,7 @@ WK_EXPORT void WKPageLoadWebArchiveDataWithUserData(WKPageRef page, WKDataRef we WK_EXPORT void WKPageStopLoading(WKPageRef page); WK_EXPORT void WKPageReload(WKPageRef page); +WK_EXPORT void WKPageReloadWithoutContentBlockers(WKPageRef page); WK_EXPORT void WKPageReloadFromOrigin(WKPageRef page); WK_EXPORT bool WKPageTryClose(WKPageRef page); @@ -108,8 +114,6 @@ WK_EXPORT double WKPageGetEstimatedProgress(WKPageRef page); WK_EXPORT uint64_t WKPageGetRenderTreeSize(WKPageRef page); -WK_EXPORT void WKPageSetMemoryCacheClientCallsEnabled(WKPageRef page, bool memoryCacheClientCallsEnabled); - WK_EXPORT WKInspectorRef WKPageGetInspector(WKPageRef page); WK_EXPORT WKVibrationRef WKPageGetVibration(WKPageRef page); @@ -122,6 +126,8 @@ WK_EXPORT void WKPageSetApplicationNameForUserAgent(WKPageRef page, WKStringRef WK_EXPORT WKStringRef WKPageCopyCustomUserAgent(WKPageRef page); WK_EXPORT void WKPageSetCustomUserAgent(WKPageRef page, WKStringRef userAgent); +WK_EXPORT void WKPageSetUserContentExtensionsEnabled(WKPageRef, bool); + WK_EXPORT bool WKPageSupportsTextEncoding(WKPageRef page); WK_EXPORT WKStringRef WKPageCopyCustomTextEncodingName(WKPageRef page); WK_EXPORT void WKPageSetCustomTextEncodingName(WKPageRef page, WKStringRef encodingName); @@ -132,11 +138,18 @@ WK_EXPORT WKStringRef WKPageGetSessionHistoryURLValueType(void); WK_EXPORT WKStringRef WKPageGetSessionBackForwardListItemValueType(void); typedef bool (*WKPageSessionStateFilterCallback)(WKPageRef page, WKStringRef valueType, WKTypeRef value, void* context); -WK_EXPORT WKDataRef WKPageCopySessionState(WKPageRef page, void* context, WKPageSessionStateFilterCallback urlAllowedCallback); -WK_EXPORT void WKPageRestoreFromSessionState(WKPageRef page, WKDataRef sessionStateData); + +// FIXME: This should return a WKSessionStateRef object, not a WKTypeRef. +// It currently returns a WKTypeRef for backwards compatibility with Safari. +WK_EXPORT WKTypeRef WKPageCopySessionState(WKPageRef page, void* context, WKPageSessionStateFilterCallback urlAllowedCallback); + +// FIXME: This should take a WKSessionStateRef object, not a WKTypeRef. +// It currently takes a WKTypeRef for backwards compatibility with Safari. +WK_EXPORT void WKPageRestoreFromSessionState(WKPageRef page, WKTypeRef sessionState); WK_EXPORT double WKPageGetBackingScaleFactor(WKPageRef page); WK_EXPORT void WKPageSetCustomBackingScaleFactor(WKPageRef page, double customScaleFactor); +WK_EXPORT void WKPageClearWheelEventTestTrigger(WKPageRef page); WK_EXPORT bool WKPageSupportsTextZoom(WKPageRef page); WK_EXPORT double WKPageGetTextZoomFactor(WKPageRef page); @@ -155,8 +168,6 @@ WK_EXPORT WKSize WKPageFixedLayoutSize(WKPageRef page); WK_EXPORT void WKPageListenForLayoutMilestones(WKPageRef page, WKLayoutMilestones milestones); -WK_EXPORT void WKPageSetVisibilityState(WKPageRef page, WKPageVisibilityState state, bool isInitialState); - WK_EXPORT bool WKPageHasHorizontalScrollbar(WKPageRef page); WK_EXPORT bool WKPageHasVerticalScrollbar(WKPageRef page); @@ -167,7 +178,11 @@ WK_EXPORT bool WKPageIsPinnedToLeftSide(WKPageRef page); WK_EXPORT bool WKPageIsPinnedToRightSide(WKPageRef page); WK_EXPORT bool WKPageIsPinnedToTopSide(WKPageRef page); WK_EXPORT bool WKPageIsPinnedToBottomSide(WKPageRef page); - + +// This API is poorly named. Even when these values are set to false, rubber-banding will +// still be allowed to occur at the end of a momentum scroll. These values are used along +// with pin state to determine if wheel events should be handled in the web process or if +// they should be passed up to the client. WK_EXPORT bool WKPageRubberBandsAtLeft(WKPageRef); WK_EXPORT void WKPageSetRubberBandsAtLeft(WKPageRef, bool rubberBandsAtLeft); WK_EXPORT bool WKPageRubberBandsAtRight(WKPageRef); @@ -176,7 +191,13 @@ WK_EXPORT bool WKPageRubberBandsAtTop(WKPageRef); WK_EXPORT void WKPageSetRubberBandsAtTop(WKPageRef, bool rubberBandsAtTop); WK_EXPORT bool WKPageRubberBandsAtBottom(WKPageRef); WK_EXPORT void WKPageSetRubberBandsAtBottom(WKPageRef, bool rubberBandsAtBottom); - + +// Rubber-banding is enabled by default. +WK_EXPORT bool WKPageVerticalRubberBandingIsEnabled(WKPageRef); +WK_EXPORT void WKPageSetEnableVerticalRubberBanding(WKPageRef, bool enableVerticalRubberBanding); +WK_EXPORT bool WKPageHorizontalRubberBandingIsEnabled(WKPageRef); +WK_EXPORT void WKPageSetEnableHorizontalRubberBanding(WKPageRef, bool enableHorizontalRubberBanding); + WK_EXPORT void WKPageSetBackgroundExtendsBeyondPage(WKPageRef, bool backgroundExtendsBeyondPage); WK_EXPORT bool WKPageBackgroundExtendsBeyondPage(WKPageRef); @@ -195,12 +216,17 @@ WK_EXPORT void WKPageGetImageForFindMatch(WKPageRef page, int32_t matchIndex); WK_EXPORT void WKPageSelectFindMatch(WKPageRef page, int32_t matchIndex); WK_EXPORT void WKPageSetPageContextMenuClient(WKPageRef page, const WKPageContextMenuClientBase* client); +WK_EXPORT void WKPageSetPageDiagnosticLoggingClient(WKPageRef page, const WKPageDiagnosticLoggingClientBase* client); WK_EXPORT void WKPageSetPageFindClient(WKPageRef page, const WKPageFindClientBase* client); WK_EXPORT void WKPageSetPageFindMatchesClient(WKPageRef page, const WKPageFindMatchesClientBase* client); WK_EXPORT void WKPageSetPageFormClient(WKPageRef page, const WKPageFormClientBase* client); +WK_EXPORT void WKPageSetPageUIClient(WKPageRef page, const WKPageUIClientBase* client); +WK_EXPORT void WKPageSetPageInjectedBundleClient(WKPageRef page, const WKPageInjectedBundleClientBase* client); + +// A client can implement either a navigation client or loader and policy clients, but never both. WK_EXPORT void WKPageSetPageLoaderClient(WKPageRef page, const WKPageLoaderClientBase* client); WK_EXPORT void WKPageSetPagePolicyClient(WKPageRef page, const WKPagePolicyClientBase* client); -WK_EXPORT void WKPageSetPageUIClient(WKPageRef page, const WKPageUIClientBase* client); +WK_EXPORT void WKPageSetPageNavigationClient(WKPageRef page, const WKPageNavigationClientBase* client); WK_EXPORT void WKPageSetSession(WKPageRef page, WKSessionRef session); @@ -218,7 +244,7 @@ typedef void (*WKPageGetContentsAsStringFunction)(WKStringRef, WKErrorRef, void* WK_EXPORT void WKPageGetContentsAsString(WKPageRef page, void* context, WKPageGetContentsAsStringFunction function); typedef void (*WKPageGetContentsAsMHTMLDataFunction)(WKDataRef, WKErrorRef, void*); -WK_EXPORT void WKPageGetContentsAsMHTMLData(WKPageRef page, bool useBinaryEncoding, void* context, WKPageGetContentsAsMHTMLDataFunction function); +WK_EXPORT void WKPageGetContentsAsMHTMLData(WKPageRef page, void* context, WKPageGetContentsAsMHTMLDataFunction function); typedef void (*WKPageGetSelectionAsWebArchiveDataFunction)(WKDataRef, WKErrorRef, void*); WK_EXPORT void WKPageGetSelectionAsWebArchiveData(WKPageRef page, void* context, WKPageGetSelectionAsWebArchiveDataFunction function); diff --git a/Source/WebKit2/UIProcess/API/C/WKPageConfigurationRef.cpp b/Source/WebKit2/UIProcess/API/C/WKPageConfigurationRef.cpp new file mode 100644 index 000000000..ccdd66dca --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKPageConfigurationRef.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKPageConfigurationRef.h" + +#include "APIPageConfiguration.h" +#include "WKAPICast.h" +#include "WebPageGroup.h" +#include "WebProcessPool.h" +#include "WebUserContentControllerProxy.h" + +using namespace WebKit; + +WKTypeID WKPageConfigurationGetTypeID() +{ + return toAPI(API::PageConfiguration::APIType); +} + +WKPageConfigurationRef WKPageConfigurationCreate() +{ + return toAPI(&API::PageConfiguration::create().leakRef()); +} + +WKContextRef WKPageConfigurationGetContext(WKPageConfigurationRef configuration) +{ + return toAPI(toImpl(configuration)->processPool()); +} + +void WKPageConfigurationSetContext(WKPageConfigurationRef configuration, WKContextRef context) +{ + toImpl(configuration)->setProcessPool(toImpl(context)); +} + +WKPageGroupRef WKPageConfigurationGetPageGroup(WKPageConfigurationRef configuration) +{ + return toAPI(toImpl(configuration)->pageGroup()); +} + +void WKPageConfigurationSetPageGroup(WKPageConfigurationRef configuration, WKPageGroupRef pageGroup) +{ + toImpl(configuration)->setPageGroup(toImpl(pageGroup)); +} + +WKUserContentControllerRef WKPageConfigurationGetUserContentController(WKPageConfigurationRef configuration) +{ + return toAPI(toImpl(configuration)->userContentController()); +} + +void WKPageConfigurationSetUserContentController(WKPageConfigurationRef configuration, WKUserContentControllerRef userContentController) +{ + toImpl(configuration)->setUserContentController(toImpl(userContentController)); +} + +WKPreferencesRef WKPageConfigurationGetPreferences(WKPageConfigurationRef configuration) +{ + return toAPI(toImpl(configuration)->preferences()); +} + +void WKPageConfigurationSetPreferences(WKPageConfigurationRef configuration, WKPreferencesRef preferences) +{ + toImpl(configuration)->setPreferences(toImpl(preferences)); +} + +WKPageRef WKPageConfigurationGetRelatedPage(WKPageConfigurationRef configuration) +{ + return toAPI(toImpl(configuration)->relatedPage()); +} + +void WKPageConfigurationSetRelatedPage(WKPageConfigurationRef configuration, WKPageRef relatedPage) +{ + toImpl(configuration)->setRelatedPage(toImpl(relatedPage)); +} + +WKWebsiteDataStoreRef WKPageConfigurationGetWebsiteDataStore(WKPageConfigurationRef configuration) +{ + return toAPI(toImpl(configuration)->websiteDataStore()); +} + +void WKPageConfigurationSetWebsiteDataStore(WKPageConfigurationRef configuration, WKWebsiteDataStoreRef websiteDataStore) +{ + toImpl(configuration)->setWebsiteDataStore(toImpl(websiteDataStore)); +} diff --git a/Source/WebKit2/UIProcess/API/C/WKPageConfigurationRef.h b/Source/WebKit2/UIProcess/API/C/WKPageConfigurationRef.h new file mode 100644 index 000000000..e61c70fbc --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKPageConfigurationRef.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKPageConfigurationRef_h +#define WKPageConfigurationRef_h + +#include <WebKit/WKBase.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKTypeID WKPageConfigurationGetTypeID(); + +WK_EXPORT WKPageConfigurationRef WKPageConfigurationCreate(); + +WK_EXPORT WKContextRef WKPageConfigurationGetContext(WKPageConfigurationRef configuration); +WK_EXPORT void WKPageConfigurationSetContext(WKPageConfigurationRef configuration, WKContextRef context); + +WK_EXPORT WKPageGroupRef WKPageConfigurationGetPageGroup(WKPageConfigurationRef configuration); +WK_EXPORT void WKPageConfigurationSetPageGroup(WKPageConfigurationRef configuration, WKPageGroupRef pageGroup); + +WK_EXPORT WKUserContentControllerRef WKPageConfigurationGetUserContentController(WKPageConfigurationRef configuration); +WK_EXPORT void WKPageConfigurationSetUserContentController(WKPageConfigurationRef configuration, WKUserContentControllerRef userContentController); + +WK_EXPORT WKPreferencesRef WKPageConfigurationGetPreferences(WKPageConfigurationRef configuration); +WK_EXPORT void WKPageConfigurationSetPreferences(WKPageConfigurationRef configuration, WKPreferencesRef preferences); + +WK_EXPORT WKPageRef WKPageConfigurationGetRelatedPage(WKPageConfigurationRef configuration); +WK_EXPORT void WKPageConfigurationSetRelatedPage(WKPageConfigurationRef configuration, WKPageRef relatedPage); + +WK_EXPORT WKWebsiteDataStoreRef WKPageConfigurationGetWebsiteDataStore(WKPageConfigurationRef configuration); +WK_EXPORT void WKPageConfigurationSetWebsiteDataStore(WKPageConfigurationRef configuration, WKWebsiteDataStoreRef websiteDataStore); + +#ifdef __cplusplus +} +#endif + +#endif // WKPageConfigurationRef_h diff --git a/Source/WebKit2/UIProcess/API/C/WKPageContextMenuClient.h b/Source/WebKit2/UIProcess/API/C/WKPageContextMenuClient.h index e892c3d59..ce2e4b07f 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPageContextMenuClient.h +++ b/Source/WebKit2/UIProcess/API/C/WKPageContextMenuClient.h @@ -26,8 +26,8 @@ #ifndef WKPageContextMenuClient_h #define WKPageContextMenuClient_h -#include <WebKit2/WKBase.h> -#include <WebKit2/WKGeometry.h> +#include <WebKit/WKBase.h> +#include <WebKit/WKGeometry.h> #ifdef __cplusplus extern "C" { @@ -98,26 +98,6 @@ typedef struct WKPageContextMenuClientV3 { WKPageHideContextMenuCallback hideContextMenu; } WKPageContextMenuClientV3; -enum { kWKPageContextMenuClientCurrentVersion WK_ENUM_DEPRECATED("Use an explicit version number instead") = 3 }; -typedef struct WKPageContextMenuClient { - int version; - const void * clientInfo; - - // Version 0. - WKPageGetContextMenuFromProposedContextMenuCallback_deprecatedForUseWithV0 getContextMenuFromProposedMenu_deprecatedForUseWithV0; - WKPageCustomContextMenuItemSelectedCallback customContextMenuItemSelected; - - // Version 1. - WKPageContextMenuDismissedCallback contextMenuDismissed; - - // Version 2. - WKPageGetContextMenuFromProposedContextMenuCallback getContextMenuFromProposedMenu; - - // Version 3. - WKPageShowContextMenuCallback showContextMenu; - WKPageHideContextMenuCallback hideContextMenu; -} WKPageContextMenuClient WK_DEPRECATED("Use an explicit versioned struct instead"); - #ifdef __cplusplus } #endif diff --git a/Source/WebKit2/UIProcess/API/C/WKPageDiagnosticLoggingClient.h b/Source/WebKit2/UIProcess/API/C/WKPageDiagnosticLoggingClient.h new file mode 100644 index 000000000..9bb0b36e9 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKPageDiagnosticLoggingClient.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKPageDiagnosticLoggingClient_h +#define WKPageDiagnosticLoggingClient_h + +#include <WebKit/WKBase.h> +#include <WebKit/WKDiagnosticLoggingResultType.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*WKPageLogDiagnosticMessageCallback)(WKPageRef page, WKStringRef message, WKStringRef description, const void* clientInfo); +typedef void (*WKPageLogDiagnosticMessageWithResultCallback)(WKPageRef page, WKStringRef message, WKStringRef description, WKDiagnosticLoggingResultType result, const void* clientInfo); +typedef void (*WKPageLogDiagnosticMessageWithValueCallback)(WKPageRef page, WKStringRef message, WKStringRef description, WKStringRef value, const void* clientInfo); + +typedef struct WKPageDiagnosticLoggingClientBase { + int version; + const void * clientInfo; +} WKPageDiagnosticLoggingClientBase; + +typedef struct WKPageDiagnosticLoggingClientV0 { + WKPageDiagnosticLoggingClientBase base; + + // Version 0. + WKPageLogDiagnosticMessageCallback logDiagnosticMessage; + WKPageLogDiagnosticMessageWithResultCallback logDiagnosticMessageWithResult; + WKPageLogDiagnosticMessageWithValueCallback logDiagnosticMessageWithValue; +} WKPageDiagnosticLoggingClientV0; + +#ifdef __cplusplus +} +#endif + +#endif // WKPageDiagnosticLoggingClient_h diff --git a/Source/WebKit2/UIProcess/API/C/WKPageFindClient.h b/Source/WebKit2/UIProcess/API/C/WKPageFindClient.h index 4d67d69db..6c7b1f22c 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPageFindClient.h +++ b/Source/WebKit2/UIProcess/API/C/WKPageFindClient.h @@ -26,7 +26,7 @@ #ifndef WKPageFindClient_h #define WKPageFindClient_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { @@ -50,17 +50,6 @@ typedef struct WKPageFindClientV0 { WKPageDidCountStringMatchesCallback didCountStringMatches; } WKPageFindClientV0; -enum { kWKPageFindClientCurrentVersion WK_ENUM_DEPRECATED("Use an explicit version number instead") = 0 }; -typedef struct WKPageFindClient { - int version; - const void * clientInfo; - - // Version 0. - WKPageDidFindStringCallback didFindString; - WKPageDidFailToFindStringCallback didFailToFindString; - WKPageDidCountStringMatchesCallback didCountStringMatches; -} WKPageFindClient WK_DEPRECATED("Use an explicit versioned struct instead"); - #ifdef __cplusplus } #endif diff --git a/Source/WebKit2/UIProcess/API/C/WKPageFindMatchesClient.h b/Source/WebKit2/UIProcess/API/C/WKPageFindMatchesClient.h index 15701aac6..395588c7e 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPageFindMatchesClient.h +++ b/Source/WebKit2/UIProcess/API/C/WKPageFindMatchesClient.h @@ -26,7 +26,7 @@ #ifndef WKPageFindMatchesClient_h #define WKPageFindMatchesClient_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { @@ -53,14 +53,6 @@ typedef struct WKPageFindMatchesClientV0 { WKPageDidGetImageForMatchResultCallback didGetImageForMatchResult; } WKPageFindMatchesClientV0; -enum { kWKPageFindMatchesClientCurrentVersion WK_ENUM_DEPRECATED("Use an explicit version number instead") = 0 }; -typedef struct WKPageFindMatchesClient { - int version; - const void * clientInfo; - WKPageDidFindStringMatchesCallback didFindStringMatches; - WKPageDidGetImageForMatchResultCallback didGetImageForMatchResult; -} WKPageFindMatchesClient WK_DEPRECATED("Use an explicit versioned struct instead"); - #ifdef __cplusplus } #endif diff --git a/Source/WebKit2/UIProcess/API/C/WKPageFormClient.h b/Source/WebKit2/UIProcess/API/C/WKPageFormClient.h index 98b2c6abe..2e6b7aeb1 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPageFormClient.h +++ b/Source/WebKit2/UIProcess/API/C/WKPageFormClient.h @@ -26,7 +26,7 @@ #ifndef WKPageFormClient_h #define WKPageFormClient_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { @@ -47,15 +47,6 @@ typedef struct WKPageFormClientV0 { WKPageWillSubmitFormCallback willSubmitForm; } WKPageFormClientV0; -enum { kWKPageFormClientCurrentVersion WK_ENUM_DEPRECATED("Use an explicit version number instead") = 0 }; -typedef struct WKPageFormClient { - int version; - const void * clientInfo; - - // Version 0. - WKPageWillSubmitFormCallback willSubmitForm; -} WKPageFormClient WK_DEPRECATED("Use an explicit versioned struct instead"); - #ifdef __cplusplus } #endif diff --git a/Source/WebKit2/UIProcess/API/C/WKPageGroup.cpp b/Source/WebKit2/UIProcess/API/C/WKPageGroup.cpp index 51298cd14..f1641dbbe 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPageGroup.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKPageGroup.cpp @@ -26,6 +26,7 @@ #include "config.h" #include "WKPageGroup.h" +#include "APIUserContentExtension.h" #include "WKAPICast.h" #include "WebPageGroup.h" #include "WebPreferences.h" @@ -55,7 +56,7 @@ void WKPageGroupSetPreferences(WKPageGroupRef pageGroupRef, WKPreferencesRef pre WKPreferencesRef WKPageGroupGetPreferences(WKPageGroupRef pageGroupRef) { - return toAPI(toImpl(pageGroupRef)->preferences()); + return toAPI(&toImpl(pageGroupRef)->preferences()); } void WKPageGroupAddUserStyleSheet(WKPageGroupRef pageGroupRef, WKStringRef sourceRef, WKURLRef baseURL, WKArrayRef whitelistedURLPatterns, WKArrayRef blacklistedURLPatterns, WKUserContentInjectedFrames injectedFrames) @@ -68,7 +69,7 @@ void WKPageGroupRemoveAllUserStyleSheets(WKPageGroupRef pageGroupRef) toImpl(pageGroupRef)->removeAllUserStyleSheets(); } -void WKPageGroupAddUserScript(WKPageGroupRef pageGroupRef, WKStringRef sourceRef, WKURLRef baseURL, WKArrayRef whitelistedURLPatterns, WKArrayRef blacklistedURLPatterns, WKUserContentInjectedFrames injectedFrames, WKUserScriptInjectionTime injectionTime) +void WKPageGroupAddUserScript(WKPageGroupRef pageGroupRef, WKStringRef sourceRef, WKURLRef baseURL, WKArrayRef whitelistedURLPatterns, WKArrayRef blacklistedURLPatterns, WKUserContentInjectedFrames injectedFrames, _WKUserScriptInjectionTime injectionTime) { toImpl(pageGroupRef)->addUserScript(toWTFString(sourceRef), toWTFString(baseURL), toImpl(whitelistedURLPatterns), toImpl(blacklistedURLPatterns), toUserContentInjectedFrames(injectedFrames), toUserScriptInjectionTime(injectionTime)); } @@ -77,3 +78,33 @@ void WKPageGroupRemoveAllUserScripts(WKPageGroupRef pageGroupRef) { toImpl(pageGroupRef)->removeAllUserScripts(); } + +void WKPageGroupAddUserContentFilter(WKPageGroupRef pageGroupRef, WKUserContentFilterRef userContentFilterRef) +{ +#if ENABLE(CONTENT_EXTENSIONS) + toImpl(pageGroupRef)->addUserContentExtension(*toImpl(userContentFilterRef)); +#else + UNUSED_PARAM(pageGroupRef); + UNUSED_PARAM(userContentFilterRef); +#endif +} + +void WKPageGroupRemoveUserContentFilter(WKPageGroupRef pageGroupRef, WKStringRef userContentFilterNameRef) +{ +#if ENABLE(CONTENT_EXTENSIONS) + toImpl(pageGroupRef)->removeUserContentExtension(toWTFString(userContentFilterNameRef)); +#else + UNUSED_PARAM(pageGroupRef); + UNUSED_PARAM(userContentFilterNameRef); +#endif +} + + +void WKPageGroupRemoveAllUserContentFilters(WKPageGroupRef pageGroupRef) +{ +#if ENABLE(CONTENT_EXTENSIONS) + toImpl(pageGroupRef)->removeAllUserContentExtensions(); +#else + UNUSED_PARAM(pageGroupRef); +#endif +} diff --git a/Source/WebKit2/UIProcess/API/C/WKPageGroup.h b/Source/WebKit2/UIProcess/API/C/WKPageGroup.h index 530674220..b21455c10 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPageGroup.h +++ b/Source/WebKit2/UIProcess/API/C/WKPageGroup.h @@ -26,9 +26,9 @@ #ifndef WKPageGroup_h #define WKPageGroup_h -#include <WebKit2/WKBase.h> -#include <WebKit2/WKUserContentInjectedFrames.h> -#include <WebKit2/WKUserScriptInjectionTime.h> +#include <WebKit/WKBase.h> +#include <WebKit/WKUserContentInjectedFrames.h> +#include <WebKit/WKUserScriptInjectionTime.h> #ifdef __cplusplus extern "C" { @@ -46,9 +46,13 @@ WK_EXPORT WKPreferencesRef WKPageGroupGetPreferences(WKPageGroupRef pageGroup); WK_EXPORT void WKPageGroupAddUserStyleSheet(WKPageGroupRef pageGroup, WKStringRef source, WKURLRef baseURL, WKArrayRef whitelistedURLPatterns, WKArrayRef blacklistedURLPatterns, WKUserContentInjectedFrames); WK_EXPORT void WKPageGroupRemoveAllUserStyleSheets(WKPageGroupRef pageGroup); -WK_EXPORT void WKPageGroupAddUserScript(WKPageGroupRef pageGroup, WKStringRef source, WKURLRef baseURL, WKArrayRef whitelistedURLPatterns, WKArrayRef blacklistedURLPatterns, WKUserContentInjectedFrames, WKUserScriptInjectionTime); +WK_EXPORT void WKPageGroupAddUserScript(WKPageGroupRef pageGroup, WKStringRef source, WKURLRef baseURL, WKArrayRef whitelistedURLPatterns, WKArrayRef blacklistedURLPatterns, WKUserContentInjectedFrames, _WKUserScriptInjectionTime); WK_EXPORT void WKPageGroupRemoveAllUserScripts(WKPageGroupRef pageGroup); +WK_EXPORT void WKPageGroupAddUserContentFilter(WKPageGroupRef pageGroup, WKUserContentFilterRef userContentFilter); +WK_EXPORT void WKPageGroupRemoveUserContentFilter(WKPageGroupRef pageGroup, WKStringRef userContentFilterName); +WK_EXPORT void WKPageGroupRemoveAllUserContentFilters(WKPageGroupRef pageGroup); + #ifdef __cplusplus } #endif diff --git a/Source/WebKit2/UIProcess/API/C/WKPageInjectedBundleClient.h b/Source/WebKit2/UIProcess/API/C/WKPageInjectedBundleClient.h new file mode 100644 index 000000000..b22c3eb86 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKPageInjectedBundleClient.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKPageInjectedBundleClient_h +#define WKPageInjectedBundleClient_h + +#include <WebKit/WKBase.h> + +typedef void (*WKPageDidReceiveMessageFromInjectedBundleCallback)(WKPageRef page, WKStringRef messageName, WKTypeRef messageBody, const void *clientInfo); +typedef void (*WKPageDidReceiveSynchronousMessageFromInjectedBundleCallback)(WKPageRef page, WKStringRef messageName, WKTypeRef messageBody, WKTypeRef* returnData, const void *clientInfo); +typedef WKTypeRef (*WKPageGetInjectedBundleInitializationUserDataCallback)(WKPageRef page, const void *clientInfo); + +typedef struct WKPageInjectedBundleClientBase { + int version; + const void * clientInfo; +} WKPageInjectedBundleClientBase; + +typedef struct WKPageInjectedBundleClientV0 { + WKPageInjectedBundleClientBase base; + + // Version 0. + WKPageDidReceiveMessageFromInjectedBundleCallback didReceiveMessageFromInjectedBundle; + WKPageDidReceiveSynchronousMessageFromInjectedBundleCallback didReceiveSynchronousMessageFromInjectedBundle; +} WKPageInjectedBundleClientV0; + +#endif // WKPageInjectedBundleClient_h diff --git a/Source/WebKit2/UIProcess/API/C/WKPageLoaderClient.h b/Source/WebKit2/UIProcess/API/C/WKPageLoaderClient.h index 579d8c2cb..c7c1cb011 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPageLoaderClient.h +++ b/Source/WebKit2/UIProcess/API/C/WKPageLoaderClient.h @@ -26,25 +26,19 @@ #ifndef WKPageLoaderClient_h #define WKPageLoaderClient_h -#include <WebKit2/WKBase.h> -#include <WebKit2/WKError.h> -#include <WebKit2/WKPageLoadTypes.h> +#include <WebKit/WKBase.h> +#include <WebKit/WKErrorRef.h> +#include <WebKit/WKPageLoadTypes.h> +#include <WebKit/WKPluginLoadPolicy.h> #ifdef __cplusplus extern "C" { #endif enum { - kWKPluginLoadPolicyLoadNormally = 0, - kWKPluginLoadPolicyBlocked, - kWKPluginLoadPolicyInactive, - kWKPluginLoadPolicyLoadUnsandboxed, -}; -typedef uint32_t WKPluginLoadPolicy; - -enum { kWKWebGLLoadPolicyBlocked = 0, kWKWebGLLoadPolicyLoadNormally, + kWKWebGLLoadPolicyPending }; typedef uint32_t WKWebGLLoadPolicy; @@ -68,15 +62,19 @@ typedef bool (*WKPageCanAuthenticateAgainstProtectionSpaceInFrameCallback)(WKPag typedef void (*WKPageDidReceiveAuthenticationChallengeInFrameCallback)(WKPageRef page, WKFrameRef frame, WKAuthenticationChallengeRef authenticationChallenge, const void *clientInfo); typedef void (*WKPageDidChangeBackForwardListCallback)(WKPageRef page, WKBackForwardListItemRef addedItem, WKArrayRef removedItems, const void *clientInfo); typedef bool (*WKPageShouldGoToBackForwardListItemCallback)(WKPageRef page, WKBackForwardListItemRef item, const void *clientInfo); +typedef bool (*WKPageShouldKeepCurrentBackForwardListItemInListCallback)(WKPageRef page, WKBackForwardListItemRef item, const void *clientInfo); typedef void (*WKPageWillGoToBackForwardListItemCallback)(WKPageRef page, WKBackForwardListItemRef item, WKTypeRef userData, const void *clientInfo); typedef void (*WKPageDidLayoutCallback)(WKPageRef page, WKLayoutMilestones milestones, WKTypeRef userData, const void *clientInfo); typedef WKPluginLoadPolicy (*WKPagePluginLoadPolicyCallback)(WKPageRef page, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInfoDictionary, WKStringRef* unavailabilityDescription, const void* clientInfo); -typedef void (*WKPagePluginDidFailCallback)(WKPageRef page, WKErrorCode errorCode, WKDictionaryRef pluginInfoDictionary, const void* clientInfo); +typedef void (*WKPagePluginDidFailCallback)(WKPageRef page, uint32_t errorCode, WKDictionaryRef pluginInfoDictionary, const void* clientInfo); typedef WKWebGLLoadPolicy (*WKPageWebGLLoadPolicyCallback)(WKPageRef page, WKStringRef url, const void* clientInfo); +typedef void (*WKPageNavigationGestureDidBeginCallback)(WKPageRef page, const void* clientInfo); +typedef void (*WKPageNavigationGestureWillEndCallback)(WKPageRef page, bool willNavigate, WKBackForwardListItemRef item, const void* clientInfo); +typedef void (*WKPageNavigationGestureDidEndCallback)(WKPageRef page, bool willNavigate, WKBackForwardListItemRef item, const void* clientInfo); // Deprecated typedef void (*WKPageDidFailToInitializePluginCallback_deprecatedForUseWithV0)(WKPageRef page, WKStringRef mimeType, const void* clientInfo); -typedef void (*WKPagePluginDidFailCallback_deprecatedForUseWithV1)(WKPageRef page, WKErrorCode errorCode, WKStringRef mimeType, WKStringRef pluginIdentifier, WKStringRef pluginVersion, const void* clientInfo); +typedef void (*WKPagePluginDidFailCallback_deprecatedForUseWithV1)(WKPageRef page, uint32_t errorCode, WKStringRef mimeType, WKStringRef pluginIdentifier, WKStringRef pluginVersion, const void* clientInfo); typedef WKPluginLoadPolicy (*WKPagePluginLoadPolicyCallback_deprecatedForUseWithV2)(WKPageRef page, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInfoDictionary, const void* clientInfo); typedef struct WKPageLoaderClientBase { @@ -330,13 +328,74 @@ typedef struct WKPageLoaderClientV4 { // Version 4 WKPageWebGLLoadPolicyCallback webGLLoadPolicy; + WKPageWebGLLoadPolicyCallback resolveWebGLLoadPolicy; } WKPageLoaderClientV4; -// FIXME: These should be deprecated. -enum { kWKPageLoaderClientCurrentVersion WK_ENUM_DEPRECATED("Use an explicit version number instead") = 3 }; -typedef struct WKPageLoaderClient { - int version; - const void * clientInfo; +typedef struct WKPageLoaderClientV5 { + WKPageLoaderClientBase base; + + // Version 0. + WKPageDidStartProvisionalLoadForFrameCallback didStartProvisionalLoadForFrame; + WKPageDidReceiveServerRedirectForProvisionalLoadForFrameCallback didReceiveServerRedirectForProvisionalLoadForFrame; + WKPageDidFailProvisionalLoadWithErrorForFrameCallback didFailProvisionalLoadWithErrorForFrame; + WKPageDidCommitLoadForFrameCallback didCommitLoadForFrame; + WKPageDidFinishDocumentLoadForFrameCallback didFinishDocumentLoadForFrame; + WKPageDidFinishLoadForFrameCallback didFinishLoadForFrame; + WKPageDidFailLoadWithErrorForFrameCallback didFailLoadWithErrorForFrame; + WKPageDidSameDocumentNavigationForFrameCallback didSameDocumentNavigationForFrame; + WKPageDidReceiveTitleForFrameCallback didReceiveTitleForFrame; + WKPageDidFirstLayoutForFrameCallback didFirstLayoutForFrame; + WKPageDidFirstVisuallyNonEmptyLayoutForFrameCallback didFirstVisuallyNonEmptyLayoutForFrame; + WKPageDidRemoveFrameFromHierarchyCallback didRemoveFrameFromHierarchy; + WKPageDidDisplayInsecureContentForFrameCallback didDisplayInsecureContentForFrame; + WKPageDidRunInsecureContentForFrameCallback didRunInsecureContentForFrame; + WKPageCanAuthenticateAgainstProtectionSpaceInFrameCallback canAuthenticateAgainstProtectionSpaceInFrame; + WKPageDidReceiveAuthenticationChallengeInFrameCallback didReceiveAuthenticationChallengeInFrame; + + // FIXME: Move to progress client. + WKPageLoaderClientCallback didStartProgress; + WKPageLoaderClientCallback didChangeProgress; + WKPageLoaderClientCallback didFinishProgress; + + // FIXME: These three functions should not be part of this client. + WKPageLoaderClientCallback processDidBecomeUnresponsive; + WKPageLoaderClientCallback processDidBecomeResponsive; + WKPageLoaderClientCallback processDidCrash; + WKPageDidChangeBackForwardListCallback didChangeBackForwardList; + WKPageShouldGoToBackForwardListItemCallback shouldGoToBackForwardListItem; + WKPageDidFailToInitializePluginCallback_deprecatedForUseWithV0 didFailToInitializePlugin_deprecatedForUseWithV0; + + // Version 1. + WKPageDidDetectXSSForFrameCallback didDetectXSSForFrame; + + void* didNewFirstVisuallyNonEmptyLayout_unavailable; + + WKPageWillGoToBackForwardListItemCallback willGoToBackForwardListItem; + + WKPageLoaderClientCallback interactionOccurredWhileProcessUnresponsive; + WKPagePluginDidFailCallback_deprecatedForUseWithV1 pluginDidFail_deprecatedForUseWithV1; + + // Version 2. + void (*didReceiveIntentForFrame_unavailable)(void); + void (*registerIntentServiceForFrame_unavailable)(void); + + WKPageDidLayoutCallback didLayout; + WKPagePluginLoadPolicyCallback_deprecatedForUseWithV2 pluginLoadPolicy_deprecatedForUseWithV2; + WKPagePluginDidFailCallback pluginDidFail; + + // Version 3. + WKPagePluginLoadPolicyCallback pluginLoadPolicy; + + // Version 4. + WKPageWebGLLoadPolicyCallback webGLLoadPolicy; + WKPageWebGLLoadPolicyCallback resolveWebGLLoadPolicy; + + // Version 5. + WKPageShouldKeepCurrentBackForwardListItemInListCallback shouldKeepCurrentBackForwardListItemInList; +} WKPageLoaderClientV5; + +typedef struct WKPageLoaderClientV6 { + WKPageLoaderClientBase base; // Version 0. WKPageDidStartProvisionalLoadForFrameCallback didStartProvisionalLoadForFrame; @@ -389,7 +448,19 @@ typedef struct WKPageLoaderClient { // Version 3. WKPagePluginLoadPolicyCallback pluginLoadPolicy; -} WKPageLoaderClient; + + // Version 4. + WKPageWebGLLoadPolicyCallback webGLLoadPolicy; + WKPageWebGLLoadPolicyCallback resolveWebGLLoadPolicy; + + // Version 5. + WKPageShouldKeepCurrentBackForwardListItemInListCallback shouldKeepCurrentBackForwardListItemInList; + + // Version 6. + WKPageNavigationGestureDidBeginCallback navigationGestureDidBegin; + WKPageNavigationGestureWillEndCallback navigationGestureWillEnd; + WKPageNavigationGestureDidEndCallback navigationGestureDidEnd; +} WKPageLoaderClientV6; #ifdef __cplusplus } diff --git a/Source/WebKit2/UIProcess/API/C/WKPageNavigationClient.h b/Source/WebKit2/UIProcess/API/C/WKPageNavigationClient.h new file mode 100644 index 000000000..e19cf9741 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKPageNavigationClient.h @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKPageNavigationClient_h +#define WKPageNavigationClient_h + +#include <WebKit/WKBase.h> +#include <WebKit/WKPageLoadTypes.h> +#include <WebKit/WKPageRenderingProgressEvents.h> +#include <WebKit/WKPluginLoadPolicy.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*WKPageNavigationDecidePolicyForNavigationActionCallback)(WKPageRef page, WKNavigationActionRef navigationAction, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo); + +typedef void (*WKPageNavigationDecidePolicyForNavigationResponseCallback)(WKPageRef page, WKNavigationResponseRef navigationResponse, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo); + +typedef void (*WKPageNavigationDidStartProvisionalNavigationCallback)(WKPageRef page, WKNavigationRef navigation, WKTypeRef userData, const void* clientInfo); + +typedef void (*WKPageNavigationDidReceiveServerRedirectForProvisionalNavigationCallback)(WKPageRef page, WKNavigationRef navigation, WKTypeRef userData, const void* clientInfo); + +typedef void (*WKPageNavigationDidFailProvisionalNavigationCallback)(WKPageRef page, WKNavigationRef navigation, WKErrorRef error, WKTypeRef userData, const void* clientInfo); + +typedef void (*WKPageNavigationDidCommitNavigationCallback)(WKPageRef page, WKNavigationRef navigation, WKTypeRef userData, const void* clientInfo); + +typedef void (*WKPageNavigationDidFinishNavigationCallback)(WKPageRef page, WKNavigationRef navigation, WKTypeRef userData, const void* clientInfo); + +typedef void (*WKPageNavigationDidFailNavigationCallback)(WKPageRef page, WKNavigationRef navigation, WKErrorRef error, WKTypeRef userData, const void* clientInfo); + +typedef void (*WKPageNavigationDidFailProvisionalLoadInSubframeCallback)(WKPageRef page, WKNavigationRef navigation, WKFrameInfoRef subframe, WKErrorRef error, WKTypeRef userData, const void* clientInfo); + +typedef void (*WKPageNavigationDidFinishDocumentLoadCallback)(WKPageRef page, WKNavigationRef navigation, WKTypeRef userData, const void* clientInfo); + +typedef void (*WKPageNavigationDidSameDocumentNavigationCallback)(WKPageRef page, WKNavigationRef navigation, WKSameDocumentNavigationType navigationType, WKTypeRef userData, const void* clientInfo); + +typedef void (*WKPageNavigationRenderingProgressDidChangeCallback)(WKPageRef page, WKPageRenderingProgressEvents progressEvents, WKTypeRef userData, const void* clientInfo); + +typedef bool (*WKPageNavigationCanAuthenticateAgainstProtectionSpaceCallback)(WKPageRef page, WKProtectionSpaceRef protectionSpace, const void* clientInfo); + +typedef void (*WKPageNavigationDidReceiveAuthenticationChallengeCallback)(WKPageRef page, WKAuthenticationChallengeRef challenge, const void* clientInfo); + +typedef void (*WKPageNavigationWebProcessDidCrashCallback)(WKPageRef page, const void* clientInfo); + +typedef WKDataRef (*WKPageNavigationCopyWebCryptoMasterKeyCallback)(WKPageRef page, const void* clientInfo); + +typedef WKPluginLoadPolicy (*WKPageNavigationDecidePolicyForPluginLoadCallback)(WKPageRef page, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInfoDictionary, WKStringRef* unavailabilityDescription, const void* clientInfo); + +typedef void (*WKPageNavigationDidBeginNavigationGesture)(WKPageRef page, const void* clientInfo); + +typedef void (*WKPageNavigationWillEndNavigationGesture)(WKPageRef page, WKBackForwardListItemRef backForwardListItem, const void* clientInfo); + +typedef void (*WKPageNavigationDidEndNavigationGesture)(WKPageRef page, WKBackForwardListItemRef backForwardListItem, const void* clientInfo); + +typedef void (*WKPageNavigationDidRemoveNavigationGestureSnapshot)(WKPageRef page, const void* clientInfo); + + +typedef struct WKPageNavigationClientBase { + int version; + const void* clientInfo; +} WKPageNavigationClientBase; + +typedef struct WKPageNavigationClientV0 { + WKPageNavigationClientBase base; + + // Version 0. + WKPageNavigationDecidePolicyForNavigationActionCallback decidePolicyForNavigationAction; + WKPageNavigationDecidePolicyForNavigationResponseCallback decidePolicyForNavigationResponse; + WKPageNavigationDecidePolicyForPluginLoadCallback decidePolicyForPluginLoad; + WKPageNavigationDidStartProvisionalNavigationCallback didStartProvisionalNavigation; + WKPageNavigationDidReceiveServerRedirectForProvisionalNavigationCallback didReceiveServerRedirectForProvisionalNavigation; + WKPageNavigationDidFailProvisionalNavigationCallback didFailProvisionalNavigation; + WKPageNavigationDidCommitNavigationCallback didCommitNavigation; + WKPageNavigationDidFinishNavigationCallback didFinishNavigation; + WKPageNavigationDidFailNavigationCallback didFailNavigation; + WKPageNavigationDidFailProvisionalLoadInSubframeCallback didFailProvisionalLoadInSubframe; + WKPageNavigationDidFinishDocumentLoadCallback didFinishDocumentLoad; + WKPageNavigationDidSameDocumentNavigationCallback didSameDocumentNavigation; + WKPageNavigationRenderingProgressDidChangeCallback renderingProgressDidChange; + WKPageNavigationCanAuthenticateAgainstProtectionSpaceCallback canAuthenticateAgainstProtectionSpace; + WKPageNavigationDidReceiveAuthenticationChallengeCallback didReceiveAuthenticationChallenge; + WKPageNavigationWebProcessDidCrashCallback webProcessDidCrash; + WKPageNavigationCopyWebCryptoMasterKeyCallback copyWebCryptoMasterKey; + + WKPageNavigationDidBeginNavigationGesture didBeginNavigationGesture; + WKPageNavigationWillEndNavigationGesture willEndNavigationGesture; + WKPageNavigationDidEndNavigationGesture didEndNavigationGesture; + WKPageNavigationDidRemoveNavigationGestureSnapshot didRemoveNavigationGestureSnapshot; +} WKPageNavigationClientV0; + +#ifdef __cplusplus +} +#endif + +#endif // WKPageNavigationClient_h diff --git a/Source/WebKit2/UIProcess/API/C/WKPagePolicyClient.h b/Source/WebKit2/UIProcess/API/C/WKPagePolicyClient.h index 15f834835..121c1018a 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPagePolicyClient.h +++ b/Source/WebKit2/UIProcess/API/C/WKPagePolicyClient.h @@ -26,9 +26,9 @@ #ifndef WKPagePolicyClient_h #define WKPagePolicyClient_h -#include <WebKit2/WKBase.h> -#include <WebKit2/WKEvent.h> -#include <WebKit2/WKPageLoadTypes.h> +#include <WebKit/WKBase.h> +#include <WebKit/WKEvent.h> +#include <WebKit/WKPageLoadTypes.h> #ifdef __cplusplus extern "C" { @@ -71,23 +71,6 @@ typedef struct WKPagePolicyClientV1 { WKPageDecidePolicyForResponseCallback decidePolicyForResponse; } WKPagePolicyClientV1; -// FIXME: These should be deprecated. -enum { kWKPagePolicyClientCurrentVersion WK_ENUM_DEPRECATED("Use an explicit version number instead") = 1 }; -typedef struct WKPagePolicyClient { - int version; - const void * clientInfo; - - // Version 0. - WKPageDecidePolicyForNavigationActionCallback_deprecatedForUseWithV0 decidePolicyForNavigationAction_deprecatedForUseWithV0; - WKPageDecidePolicyForNewWindowActionCallback decidePolicyForNewWindowAction; - WKPageDecidePolicyForResponseCallback_deprecatedForUseWithV0 decidePolicyForResponse_deprecatedForUseWithV0; - WKPageUnableToImplementPolicyCallback unableToImplementPolicy; - - // Version 1. - WKPageDecidePolicyForNavigationActionCallback decidePolicyForNavigationAction; - WKPageDecidePolicyForResponseCallback decidePolicyForResponse; -} WKPagePolicyClient; - #ifdef __cplusplus } #endif diff --git a/Source/WebKit2/UIProcess/API/C/WKPagePrivate.h b/Source/WebKit2/UIProcess/API/C/WKPagePrivate.h index 5d6f66082..3c361182e 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPagePrivate.h +++ b/Source/WebKit2/UIProcess/API/C/WKPagePrivate.h @@ -26,8 +26,8 @@ #ifndef WKPagePrivate_h #define WKPagePrivate_h -#include <WebKit2/WKBase.h> -#include <WebKit2/WKPage.h> +#include <WebKit/WKBase.h> +#include <WebKit/WKPage.h> #ifdef __cplusplus extern "C" { @@ -64,6 +64,8 @@ WK_EXPORT void WKPageSetPageLength(WKPageRef page, double pageLength); WK_EXPORT double WKPageGetPageLength(WKPageRef page); WK_EXPORT void WKPageSetGapBetweenPages(WKPageRef page, double gap); WK_EXPORT double WKPageGetGapBetweenPages(WKPageRef page); +WK_EXPORT void WKPageSetPaginationLineGridEnabled(WKPageRef page, bool lineGridEnabled); +WK_EXPORT bool WKPageGetPaginationLineGridEnabled(WKPageRef page); WK_EXPORT unsigned WKPageGetPageCount(WKPageRef page); @@ -82,18 +84,19 @@ WK_EXPORT void WKPageBeginPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo WK_EXPORT void WKPageDrawPagesToPDF(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo, uint32_t first, uint32_t count, WKPageDrawToPDFFunction callback, void* context); WK_EXPORT void WKPageEndPrinting(WKPageRef page); -// FIXME https://bugs.webkit.org/show_bug.cgi?id=66979: Remove this sync call. -WK_EXPORT WKImageRef WKPageCreateSnapshotOfVisibleContent(WKPageRef page); - -WK_EXPORT void WKPageSetShouldSendEventsSynchronously(WKPageRef page, bool sync); +WK_EXPORT bool WKPageGetAllowsRemoteInspection(WKPageRef page); +WK_EXPORT void WKPageSetAllowsRemoteInspection(WKPageRef page, bool allow); WK_EXPORT void WKPageSetMediaVolume(WKPageRef page, float volume); WK_EXPORT void WKPageSetMayStartMediaWhenInWindow(WKPageRef page, bool mayStartMedia); -WK_EXPORT WKArrayRef WKPageCopyRelatedPages(WKPageRef page); +typedef void (*WKPageGetBytecodeProfileFunction)(WKStringRef, WKErrorRef, void*); +WK_EXPORT void WKPageGetBytecodeProfile(WKPageRef page, void* context, WKPageGetBytecodeProfileFunction function); -typedef void (*WKPageInvalidMessageFunction)(uint32_t messageID); -WK_EXPORT void WKPageSetInvalidMessageFunction(WKPageInvalidMessageFunction function); +typedef void (*WKPageIsWebProcessResponsiveFunction)(bool isWebProcessResponsive, void* context); +WK_EXPORT void WKPageIsWebProcessResponsive(WKPageRef page, void* context, WKPageIsWebProcessResponsiveFunction function); + +WK_EXPORT WKArrayRef WKPageCopyRelatedPages(WKPageRef page); enum { kWKScrollPinningBehaviorDoNotPin, @@ -105,6 +108,27 @@ typedef uint32_t WKScrollPinningBehavior; WK_EXPORT WKScrollPinningBehavior WKPageGetScrollPinningBehavior(WKPageRef page); WK_EXPORT void WKPageSetScrollPinningBehavior(WKPageRef page, WKScrollPinningBehavior pinning); +WK_EXPORT bool WKPageGetAddsVisitedLinks(WKPageRef page); +WK_EXPORT void WKPageSetAddsVisitedLinks(WKPageRef page, bool visitedLinks); + +WK_EXPORT bool WKPageIsPlayingAudio(WKPageRef page); +WK_EXPORT void WKPageSetMuted(WKPageRef page, bool muted); + +enum { + kWKMediaEventTypePlayPause, + kWKMediaEventTypeTrackNext, + kWKMediaEventTypeTrackPrevious +}; +typedef uint32_t WKMediaEventType; + +WK_EXPORT bool WKPageHasMediaSessionWithActiveMediaElements(WKPageRef page); +WK_EXPORT void WKPageHandleMediaEvent(WKPageRef page, WKMediaEventType event); + +WK_EXPORT void WKPageLoadURLWithShouldOpenExternalURLsPolicy(WKPageRef page, WKURLRef url, bool shouldOpenExternalURLs); + +typedef void (*WKPagePostPresentationUpdateFunction)(WKErrorRef, void*); +WK_EXPORT void WKPageCallAfterNextPresentationUpdate(WKPageRef page, void* context, WKPagePostPresentationUpdateFunction function); + #ifdef __cplusplus } #endif diff --git a/Source/WebKit2/UIProcess/API/C/WKPageRenderingProgressEvents.h b/Source/WebKit2/UIProcess/API/C/WKPageRenderingProgressEvents.h new file mode 100644 index 000000000..6d258ed15 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKPageRenderingProgressEvents.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKPageRenderingProgressEvents_h +#define WKPageRenderingProgressEvents_h + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +enum { + WKPageRenderingProgressEventFirstLayout = 1 << 0, + WKPageRenderingProgressEventFirstVisuallyNonEmptyLayout = 1 << 1, + WKPageRenderingProgressEventFirstPaintWithSignificantArea = 1 << 2, + WKPageRenderingProgressEventReachedSessionRestorationRenderTreeSizeThreshold = 1 << 3 +}; +typedef uint32_t WKPageRenderingProgressEvents; + +#ifdef __cplusplus +} +#endif + +#endif /* WKPageRenderingProgressEvents_h */ diff --git a/Source/WebKit2/UIProcess/API/C/WKPageRenderingProgressEventsInternal.h b/Source/WebKit2/UIProcess/API/C/WKPageRenderingProgressEventsInternal.h new file mode 100644 index 000000000..ab9274534 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKPageRenderingProgressEventsInternal.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "WKPageRenderingProgressEvents.h" + +#include <WebCore/LayoutMilestones.h> + +static inline WKPageRenderingProgressEvents pageRenderingProgressEvents(WebCore::LayoutMilestones milestones) +{ + WKPageRenderingProgressEvents events = 0; + + if (milestones & WebCore::DidFirstLayout) + events |= WKPageRenderingProgressEventFirstLayout; + + if (milestones & WebCore::DidFirstVisuallyNonEmptyLayout) + events |= WKPageRenderingProgressEventFirstVisuallyNonEmptyLayout; + + if (milestones & WebCore::DidHitRelevantRepaintedObjectsAreaThreshold) + events |= WKPageRenderingProgressEventFirstPaintWithSignificantArea; + + if (milestones & WebCore::ReachedSessionRestorationRenderTreeSizeThreshold) + events |= WKPageRenderingProgressEventReachedSessionRestorationRenderTreeSizeThreshold; + + return events; +} diff --git a/Source/WebKit2/UIProcess/API/C/WKPageUIClient.h b/Source/WebKit2/UIProcess/API/C/WKPageUIClient.h index 1d8417000..2ab3595bd 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPageUIClient.h +++ b/Source/WebKit2/UIProcess/API/C/WKPageUIClient.h @@ -26,10 +26,10 @@ #ifndef WKPageUIClient_h #define WKPageUIClient_h -#include <WebKit2/WKBase.h> -#include <WebKit2/WKEvent.h> -#include <WebKit2/WKGeometry.h> -#include <WebKit2/WKNativeEvent.h> +#include <WebKit/WKBase.h> +#include <WebKit/WKEvent.h> +#include <WebKit/WKGeometry.h> +#include <WebKit/WKNativeEvent.h> #ifdef __cplusplus extern "C" { @@ -48,11 +48,24 @@ enum { }; typedef uint32_t WKPluginUnavailabilityReason; +WK_EXPORT WKTypeID WKPageRunBeforeUnloadConfirmPanelResultListenerGetTypeID(); +WK_EXPORT void WKPageRunBeforeUnloadConfirmPanelResultListenerCall(WKPageRunBeforeUnloadConfirmPanelResultListenerRef listener, bool result); + +WK_EXPORT WKTypeID WKPageRunJavaScriptAlertResultListenerGetTypeID(); +WK_EXPORT void WKPageRunJavaScriptAlertResultListenerCall(WKPageRunJavaScriptAlertResultListenerRef listener); + +WK_EXPORT WKTypeID WKPageRunJavaScriptConfirmResultListenerGetTypeID(); +WK_EXPORT void WKPageRunJavaScriptConfirmResultListenerCall(WKPageRunJavaScriptConfirmResultListenerRef listener, bool result); + +WK_EXPORT WKTypeID WKPageRunJavaScriptPromptResultListenerGetTypeID(); +WK_EXPORT void WKPageRunJavaScriptPromptResultListenerCall(WKPageRunJavaScriptPromptResultListenerRef listener, WKStringRef result); + typedef void (*WKPageUIClientCallback)(WKPageRef page, const void* clientInfo); -typedef WKPageRef (*WKPageCreateNewPageCallback)(WKPageRef page, WKURLRequestRef urlRequest, WKDictionaryRef features, WKEventModifiers modifiers, WKEventMouseButton mouseButton, const void *clientInfo); -typedef void (*WKPageRunJavaScriptAlertCallback)(WKPageRef page, WKStringRef alertText, WKFrameRef frame, const void *clientInfo); -typedef bool (*WKPageRunJavaScriptConfirmCallback)(WKPageRef page, WKStringRef message, WKFrameRef frame, const void *clientInfo); -typedef WKStringRef (*WKPageRunJavaScriptPromptCallback)(WKPageRef page, WKStringRef message, WKStringRef defaultValue, WKFrameRef frame, const void *clientInfo); +typedef WKPageRef (*WKPageCreateNewPageCallback)(WKPageRef page, WKPageConfigurationRef configuration, WKNavigationActionRef navigationAction, WKWindowFeaturesRef windowFeatures, const void *clientInfo); +typedef void (*WKPageRunBeforeUnloadConfirmPanelCallback)(WKPageRef page, WKStringRef message, WKFrameRef frame, WKPageRunBeforeUnloadConfirmPanelResultListenerRef listener, const void *clientInfo); +typedef void (*WKPageRunJavaScriptAlertCallback)(WKPageRef page, WKStringRef alertText, WKFrameRef frame, WKSecurityOriginRef securityOrigin, WKPageRunJavaScriptAlertResultListenerRef listener, const void *clientInfo); +typedef void (*WKPageRunJavaScriptConfirmCallback)(WKPageRef page, WKStringRef message, WKFrameRef frame, WKSecurityOriginRef securityOrigin, WKPageRunJavaScriptConfirmResultListenerRef listener, const void *clientInfo); +typedef void (*WKPageRunJavaScriptPromptCallback)(WKPageRef page, WKStringRef message, WKStringRef defaultValue, WKFrameRef frame, WKSecurityOriginRef securityOrigin, WKPageRunJavaScriptPromptResultListenerRef listener, const void *clientInfo); typedef void (*WKPageTakeFocusCallback)(WKPageRef page, WKFocusDirection direction, const void *clientInfo); typedef void (*WKPageFocusCallback)(WKPageRef page, const void *clientInfo); typedef void (*WKPageUnfocusCallback)(WKPageRef page, const void *clientInfo); @@ -70,7 +83,6 @@ typedef bool (*WKPageGetIsResizableCallback)(WKPageRef page, const void *clientI typedef void (*WKPageSetIsResizableCallback)(WKPageRef page, bool resizable, const void *clientInfo); typedef WKRect (*WKPageGetWindowFrameCallback)(WKPageRef page, const void *clientInfo); typedef void (*WKPageSetWindowFrameCallback)(WKPageRef page, WKRect frame, const void *clientInfo); -typedef bool (*WKPageRunBeforeUnloadConfirmPanelCallback)(WKPageRef page, WKStringRef message, WKFrameRef frame, const void *clientInfo); typedef unsigned long long (*WKPageExceededDatabaseQuotaCallback)(WKPageRef page, WKFrameRef frame, WKSecurityOriginRef origin, WKStringRef databaseName, WKStringRef displayName, unsigned long long currentQuota, unsigned long long currentOriginUsage, unsigned long long currentDatabaseUsage, unsigned long long expectedUsage, const void *clientInfo); typedef void (*WKPageRunOpenPanelCallback)(WKPageRef page, WKFrameRef frame, WKOpenPanelParametersRef parameters, WKOpenPanelResultListenerRef listener, const void *clientInfo); typedef void (*WKPageDecidePolicyForGeolocationPermissionRequestCallback)(WKPageRef page, WKFrameRef frame, WKSecurityOriginRef origin, WKGeolocationPermissionRequestRef permissionRequest, const void* clientInfo); @@ -80,17 +92,30 @@ typedef void (*WKPageDrawHeaderCallback)(WKPageRef page, WKFrameRef frame, WKRec typedef void (*WKPageDrawFooterCallback)(WKPageRef page, WKFrameRef frame, WKRect rect, const void* clientInfo); typedef void (*WKPagePrintFrameCallback)(WKPageRef page, WKFrameRef frame, const void* clientInfo); typedef void (*WKPageSaveDataToFileInDownloadsFolderCallback)(WKPageRef page, WKStringRef suggestedFilename, WKStringRef mimeType, WKURLRef originatingURL, WKDataRef data, const void* clientInfo); -typedef bool (*WKPageShouldInterruptJavaScriptCallback)(WKPageRef page, const void *clientInfo); typedef void (*WKPageDecidePolicyForNotificationPermissionRequestCallback)(WKPageRef page, WKSecurityOriginRef origin, WKNotificationPermissionRequestRef permissionRequest, const void *clientInfo); typedef void (*WKPageShowColorPickerCallback)(WKPageRef page, WKStringRef initialColor, WKColorPickerResultListenerRef listener, const void* clientInfo); typedef void (*WKPageHideColorPickerCallback)(WKPageRef page, const void* clientInfo); typedef void (*WKPageUnavailablePluginButtonClickedCallback)(WKPageRef page, WKPluginUnavailabilityReason pluginUnavailabilityReason, WKDictionaryRef pluginInfoDictionary, const void* clientInfo); +typedef void (*WKPagePinnedStateDidChangeCallback)(WKPageRef page, const void* clientInfo); +typedef void (*WKPageIsPlayingAudioDidChangeCallback)(WKPageRef page, const void* clientInfo); +typedef void (*WKPageDecidePolicyForUserMediaPermissionRequestCallback)(WKPageRef page, WKFrameRef frame, WKSecurityOriginRef origin, WKUserMediaPermissionRequestRef permissionRequest, const void* clientInfo); +typedef void (*WKCheckUserMediaPermissionCallback)(WKPageRef page, WKFrameRef frame, WKSecurityOriginRef origin, WKUserMediaPermissionCheckRef devicesRequest, const void *clientInfo); +typedef void (*WKPageDidClickAutoFillButtonCallback)(WKPageRef page, WKTypeRef userData, const void *clientInfo); +typedef void (*WKPageMediaSessionMetadataDidChangeCallback)(WKPageRef page, WKMediaSessionMetadataRef metadata, const void* clientInfo); -// Deprecated +// Deprecated typedef WKPageRef (*WKPageCreateNewPageCallback_deprecatedForUseWithV0)(WKPageRef page, WKDictionaryRef features, WKEventModifiers modifiers, WKEventMouseButton mouseButton, const void *clientInfo); typedef void (*WKPageMouseDidMoveOverElementCallback_deprecatedForUseWithV0)(WKPageRef page, WKEventModifiers modifiers, WKTypeRef userData, const void *clientInfo); typedef void (*WKPageMissingPluginButtonClickedCallback_deprecatedForUseWithV0)(WKPageRef page, WKStringRef mimeType, WKStringRef url, WKStringRef pluginsPageURL, const void* clientInfo); typedef void (*WKPageUnavailablePluginButtonClickedCallback_deprecatedForUseWithV1)(WKPageRef page, WKPluginUnavailabilityReason pluginUnavailabilityReason, WKStringRef mimeType, WKStringRef url, WKStringRef pluginsPageURL, const void* clientInfo); +typedef void (*WKPageRunJavaScriptAlertCallback_deprecatedForUseWithV0)(WKPageRef page, WKStringRef alertText, WKFrameRef frame, const void *clientInfo); +typedef bool (*WKPageRunJavaScriptConfirmCallback_deprecatedForUseWithV0)(WKPageRef page, WKStringRef message, WKFrameRef frame, const void *clientInfo); +typedef WKStringRef (*WKPageRunJavaScriptPromptCallback_deprecatedForUseWithV0)(WKPageRef page, WKStringRef message, WKStringRef defaultValue, WKFrameRef frame, const void *clientInfo); +typedef WKPageRef (*WKPageCreateNewPageCallback_deprecatedForUseWithV1)(WKPageRef page, WKURLRequestRef urlRequest, WKDictionaryRef features, WKEventModifiers modifiers, WKEventMouseButton mouseButton, const void *clientInfo); +typedef void (*WKPageRunJavaScriptAlertCallback_deprecatedForUseWithV5)(WKPageRef page, WKStringRef alertText, WKFrameRef frame, WKSecurityOriginRef securityOrigin, const void *clientInfo); +typedef bool (*WKPageRunJavaScriptConfirmCallback_deprecatedForUseWithV5)(WKPageRef page, WKStringRef message, WKFrameRef frame, WKSecurityOriginRef securityOrigin, const void *clientInfo); +typedef WKStringRef (*WKPageRunJavaScriptPromptCallback_deprecatedForUseWithV5)(WKPageRef page, WKStringRef message, WKStringRef defaultValue, WKFrameRef frame, WKSecurityOriginRef securityOrigin, const void *clientInfo); +typedef bool (*WKPageRunBeforeUnloadConfirmPanelCallback_deprecatedForUseWithV6)(WKPageRef page, WKStringRef message, WKFrameRef frame, const void *clientInfo); typedef struct WKPageUIClientBase { int version; @@ -107,9 +132,9 @@ typedef struct WKPageUIClientV0 { WKPageTakeFocusCallback takeFocus; WKPageFocusCallback focus; WKPageUnfocusCallback unfocus; - WKPageRunJavaScriptAlertCallback runJavaScriptAlert; - WKPageRunJavaScriptConfirmCallback runJavaScriptConfirm; - WKPageRunJavaScriptPromptCallback runJavaScriptPrompt; + WKPageRunJavaScriptAlertCallback_deprecatedForUseWithV0 runJavaScriptAlert; + WKPageRunJavaScriptConfirmCallback_deprecatedForUseWithV0 runJavaScriptConfirm; + WKPageRunJavaScriptPromptCallback_deprecatedForUseWithV0 runJavaScriptPrompt; WKPageSetStatusTextCallback setStatusText; WKPageMouseDidMoveOverElementCallback_deprecatedForUseWithV0 mouseDidMoveOverElement_deprecatedForUseWithV0; WKPageMissingPluginButtonClickedCallback_deprecatedForUseWithV0 missingPluginButtonClicked_deprecatedForUseWithV0; @@ -125,7 +150,7 @@ typedef struct WKPageUIClientV0 { WKPageSetIsResizableCallback setIsResizable; WKPageGetWindowFrameCallback getWindowFrame; WKPageSetWindowFrameCallback setWindowFrame; - WKPageRunBeforeUnloadConfirmPanelCallback runBeforeUnloadConfirmPanel; + WKPageRunBeforeUnloadConfirmPanelCallback_deprecatedForUseWithV6 runBeforeUnloadConfirmPanel; WKPageUIClientCallback didDraw; WKPageUIClientCallback pageDidScroll; WKPageExceededDatabaseQuotaCallback exceededDatabaseQuota; @@ -139,7 +164,7 @@ typedef struct WKPageUIClientV0 { WKPageUIClientCallback runModal; void* unused1; // Used to be didCompleteRubberBandForMainFrame WKPageSaveDataToFileInDownloadsFolderCallback saveDataToFileInDownloadsFolder; - WKPageShouldInterruptJavaScriptCallback shouldInterruptJavaScript; + void* shouldInterruptJavaScript_unavailable; } WKPageUIClientV0; typedef struct WKPageUIClientV1 { @@ -152,9 +177,9 @@ typedef struct WKPageUIClientV1 { WKPageTakeFocusCallback takeFocus; WKPageFocusCallback focus; WKPageUnfocusCallback unfocus; - WKPageRunJavaScriptAlertCallback runJavaScriptAlert; - WKPageRunJavaScriptConfirmCallback runJavaScriptConfirm; - WKPageRunJavaScriptPromptCallback runJavaScriptPrompt; + WKPageRunJavaScriptAlertCallback_deprecatedForUseWithV0 runJavaScriptAlert; + WKPageRunJavaScriptConfirmCallback_deprecatedForUseWithV0 runJavaScriptConfirm; + WKPageRunJavaScriptPromptCallback_deprecatedForUseWithV0 runJavaScriptPrompt; WKPageSetStatusTextCallback setStatusText; WKPageMouseDidMoveOverElementCallback_deprecatedForUseWithV0 mouseDidMoveOverElement_deprecatedForUseWithV0; WKPageMissingPluginButtonClickedCallback_deprecatedForUseWithV0 missingPluginButtonClicked_deprecatedForUseWithV0; @@ -170,7 +195,7 @@ typedef struct WKPageUIClientV1 { WKPageSetIsResizableCallback setIsResizable; WKPageGetWindowFrameCallback getWindowFrame; WKPageSetWindowFrameCallback setWindowFrame; - WKPageRunBeforeUnloadConfirmPanelCallback runBeforeUnloadConfirmPanel; + WKPageRunBeforeUnloadConfirmPanelCallback_deprecatedForUseWithV6 runBeforeUnloadConfirmPanel; WKPageUIClientCallback didDraw; WKPageUIClientCallback pageDidScroll; WKPageExceededDatabaseQuotaCallback exceededDatabaseQuota; @@ -184,10 +209,10 @@ typedef struct WKPageUIClientV1 { WKPageUIClientCallback runModal; void* unused1; // Used to be didCompleteRubberBandForMainFrame WKPageSaveDataToFileInDownloadsFolderCallback saveDataToFileInDownloadsFolder; - WKPageShouldInterruptJavaScriptCallback shouldInterruptJavaScript; + void* shouldInterruptJavaScript_unavailable; // Version 1. - WKPageCreateNewPageCallback createNewPage; + WKPageCreateNewPageCallback_deprecatedForUseWithV1 createNewPage; WKPageMouseDidMoveOverElementCallback mouseDidMoveOverElement; WKPageDecidePolicyForNotificationPermissionRequestCallback decidePolicyForNotificationPermissionRequest; WKPageUnavailablePluginButtonClickedCallback_deprecatedForUseWithV1 unavailablePluginButtonClicked_deprecatedForUseWithV1; @@ -203,9 +228,9 @@ typedef struct WKPageUIClientV2 { WKPageTakeFocusCallback takeFocus; WKPageFocusCallback focus; WKPageUnfocusCallback unfocus; - WKPageRunJavaScriptAlertCallback runJavaScriptAlert; - WKPageRunJavaScriptConfirmCallback runJavaScriptConfirm; - WKPageRunJavaScriptPromptCallback runJavaScriptPrompt; + WKPageRunJavaScriptAlertCallback_deprecatedForUseWithV0 runJavaScriptAlert; + WKPageRunJavaScriptConfirmCallback_deprecatedForUseWithV0 runJavaScriptConfirm; + WKPageRunJavaScriptPromptCallback_deprecatedForUseWithV0 runJavaScriptPrompt; WKPageSetStatusTextCallback setStatusText; WKPageMouseDidMoveOverElementCallback_deprecatedForUseWithV0 mouseDidMoveOverElement_deprecatedForUseWithV0; WKPageMissingPluginButtonClickedCallback_deprecatedForUseWithV0 missingPluginButtonClicked_deprecatedForUseWithV0; @@ -221,7 +246,7 @@ typedef struct WKPageUIClientV2 { WKPageSetIsResizableCallback setIsResizable; WKPageGetWindowFrameCallback getWindowFrame; WKPageSetWindowFrameCallback setWindowFrame; - WKPageRunBeforeUnloadConfirmPanelCallback runBeforeUnloadConfirmPanel; + WKPageRunBeforeUnloadConfirmPanelCallback_deprecatedForUseWithV6 runBeforeUnloadConfirmPanel; WKPageUIClientCallback didDraw; WKPageUIClientCallback pageDidScroll; WKPageExceededDatabaseQuotaCallback exceededDatabaseQuota; @@ -235,10 +260,10 @@ typedef struct WKPageUIClientV2 { WKPageUIClientCallback runModal; void* unused1; // Used to be didCompleteRubberBandForMainFrame WKPageSaveDataToFileInDownloadsFolderCallback saveDataToFileInDownloadsFolder; - WKPageShouldInterruptJavaScriptCallback shouldInterruptJavaScript; + void* shouldInterruptJavaScript_unavailable; // Version 1. - WKPageCreateNewPageCallback createNewPage; + WKPageCreateNewPageCallback_deprecatedForUseWithV1 createNewPage; WKPageMouseDidMoveOverElementCallback mouseDidMoveOverElement; WKPageDecidePolicyForNotificationPermissionRequestCallback decidePolicyForNotificationPermissionRequest; WKPageUnavailablePluginButtonClickedCallback_deprecatedForUseWithV1 unavailablePluginButtonClicked_deprecatedForUseWithV1; @@ -249,10 +274,8 @@ typedef struct WKPageUIClientV2 { WKPageUnavailablePluginButtonClickedCallback unavailablePluginButtonClicked; } WKPageUIClientV2; -enum { kWKPageUIClientCurrentVersion WK_ENUM_DEPRECATED("Use an explicit version number instead") = 2 }; -typedef struct WKPageUIClient { - int version; - const void * clientInfo; +typedef struct WKPageUIClientV3 { + WKPageUIClientBase base; // Version 0. WKPageCreateNewPageCallback_deprecatedForUseWithV0 createNewPage_deprecatedForUseWithV0; @@ -261,9 +284,286 @@ typedef struct WKPageUIClient { WKPageTakeFocusCallback takeFocus; WKPageFocusCallback focus; WKPageUnfocusCallback unfocus; + WKPageRunJavaScriptAlertCallback_deprecatedForUseWithV0 runJavaScriptAlert; + WKPageRunJavaScriptConfirmCallback_deprecatedForUseWithV0 runJavaScriptConfirm; + WKPageRunJavaScriptPromptCallback_deprecatedForUseWithV0 runJavaScriptPrompt; + WKPageSetStatusTextCallback setStatusText; + WKPageMouseDidMoveOverElementCallback_deprecatedForUseWithV0 mouseDidMoveOverElement_deprecatedForUseWithV0; + WKPageMissingPluginButtonClickedCallback_deprecatedForUseWithV0 missingPluginButtonClicked_deprecatedForUseWithV0; + WKPageDidNotHandleKeyEventCallback didNotHandleKeyEvent; + WKPageDidNotHandleWheelEventCallback didNotHandleWheelEvent; + WKPageGetToolbarsAreVisibleCallback toolbarsAreVisible; + WKPageSetToolbarsAreVisibleCallback setToolbarsAreVisible; + WKPageGetMenuBarIsVisibleCallback menuBarIsVisible; + WKPageSetMenuBarIsVisibleCallback setMenuBarIsVisible; + WKPageGetStatusBarIsVisibleCallback statusBarIsVisible; + WKPageSetStatusBarIsVisibleCallback setStatusBarIsVisible; + WKPageGetIsResizableCallback isResizable; + WKPageSetIsResizableCallback setIsResizable; + WKPageGetWindowFrameCallback getWindowFrame; + WKPageSetWindowFrameCallback setWindowFrame; + WKPageRunBeforeUnloadConfirmPanelCallback_deprecatedForUseWithV6 runBeforeUnloadConfirmPanel; + WKPageUIClientCallback didDraw; + WKPageUIClientCallback pageDidScroll; + WKPageExceededDatabaseQuotaCallback exceededDatabaseQuota; + WKPageRunOpenPanelCallback runOpenPanel; + WKPageDecidePolicyForGeolocationPermissionRequestCallback decidePolicyForGeolocationPermissionRequest; + WKPageHeaderHeightCallback headerHeight; + WKPageFooterHeightCallback footerHeight; + WKPageDrawHeaderCallback drawHeader; + WKPageDrawFooterCallback drawFooter; + WKPagePrintFrameCallback printFrame; + WKPageUIClientCallback runModal; + void* unused1; // Used to be didCompleteRubberBandForMainFrame + WKPageSaveDataToFileInDownloadsFolderCallback saveDataToFileInDownloadsFolder; + void* shouldInterruptJavaScript_unavailable; + + // Version 1. + WKPageCreateNewPageCallback_deprecatedForUseWithV1 createNewPage; + WKPageMouseDidMoveOverElementCallback mouseDidMoveOverElement; + WKPageDecidePolicyForNotificationPermissionRequestCallback decidePolicyForNotificationPermissionRequest; + WKPageUnavailablePluginButtonClickedCallback_deprecatedForUseWithV1 unavailablePluginButtonClicked_deprecatedForUseWithV1; + + // Version 2. + WKPageShowColorPickerCallback showColorPicker; + WKPageHideColorPickerCallback hideColorPicker; + WKPageUnavailablePluginButtonClickedCallback unavailablePluginButtonClicked; + + // Version 3. + WKPagePinnedStateDidChangeCallback pinnedStateDidChange; +} WKPageUIClientV3; + +typedef struct WKPageUIClientV4 { + WKPageUIClientBase base; + + // Version 0. + WKPageCreateNewPageCallback_deprecatedForUseWithV0 createNewPage_deprecatedForUseWithV0; + WKPageUIClientCallback showPage; + WKPageUIClientCallback close; + WKPageTakeFocusCallback takeFocus; + WKPageFocusCallback focus; + WKPageUnfocusCallback unfocus; + WKPageRunJavaScriptAlertCallback_deprecatedForUseWithV0 runJavaScriptAlert; + WKPageRunJavaScriptConfirmCallback_deprecatedForUseWithV0 runJavaScriptConfirm; + WKPageRunJavaScriptPromptCallback_deprecatedForUseWithV0 runJavaScriptPrompt; + WKPageSetStatusTextCallback setStatusText; + WKPageMouseDidMoveOverElementCallback_deprecatedForUseWithV0 mouseDidMoveOverElement_deprecatedForUseWithV0; + WKPageMissingPluginButtonClickedCallback_deprecatedForUseWithV0 missingPluginButtonClicked_deprecatedForUseWithV0; + WKPageDidNotHandleKeyEventCallback didNotHandleKeyEvent; + WKPageDidNotHandleWheelEventCallback didNotHandleWheelEvent; + WKPageGetToolbarsAreVisibleCallback toolbarsAreVisible; + WKPageSetToolbarsAreVisibleCallback setToolbarsAreVisible; + WKPageGetMenuBarIsVisibleCallback menuBarIsVisible; + WKPageSetMenuBarIsVisibleCallback setMenuBarIsVisible; + WKPageGetStatusBarIsVisibleCallback statusBarIsVisible; + WKPageSetStatusBarIsVisibleCallback setStatusBarIsVisible; + WKPageGetIsResizableCallback isResizable; + WKPageSetIsResizableCallback setIsResizable; + WKPageGetWindowFrameCallback getWindowFrame; + WKPageSetWindowFrameCallback setWindowFrame; + WKPageRunBeforeUnloadConfirmPanelCallback_deprecatedForUseWithV6 runBeforeUnloadConfirmPanel; + WKPageUIClientCallback didDraw; + WKPageUIClientCallback pageDidScroll; + WKPageExceededDatabaseQuotaCallback exceededDatabaseQuota; + WKPageRunOpenPanelCallback runOpenPanel; + WKPageDecidePolicyForGeolocationPermissionRequestCallback decidePolicyForGeolocationPermissionRequest; + WKPageHeaderHeightCallback headerHeight; + WKPageFooterHeightCallback footerHeight; + WKPageDrawHeaderCallback drawHeader; + WKPageDrawFooterCallback drawFooter; + WKPagePrintFrameCallback printFrame; + WKPageUIClientCallback runModal; + void* unused1; // Used to be didCompleteRubberBandForMainFrame. + WKPageSaveDataToFileInDownloadsFolderCallback saveDataToFileInDownloadsFolder; + void* shouldInterruptJavaScript_unavailable; + + // Version 1. + WKPageCreateNewPageCallback_deprecatedForUseWithV1 createNewPage; + WKPageMouseDidMoveOverElementCallback mouseDidMoveOverElement; + WKPageDecidePolicyForNotificationPermissionRequestCallback decidePolicyForNotificationPermissionRequest; + WKPageUnavailablePluginButtonClickedCallback_deprecatedForUseWithV1 unavailablePluginButtonClicked_deprecatedForUseWithV1; + + // Version 2. + WKPageShowColorPickerCallback showColorPicker; + WKPageHideColorPickerCallback hideColorPicker; + WKPageUnavailablePluginButtonClickedCallback unavailablePluginButtonClicked; + + // Version 3. + WKPagePinnedStateDidChangeCallback pinnedStateDidChange; + + // Version 4. + void* unused2; // Used to be didBeginTrackingPotentialLongMousePress. + void* unused3; // Used to be didRecognizeLongMousePress. + void* unused4; // Used to be didCancelTrackingPotentialLongMousePress. + WKPageIsPlayingAudioDidChangeCallback isPlayingAudioDidChange; +} WKPageUIClientV4; + +typedef struct WKPageUIClientV5 { + WKPageUIClientBase base; + + // Version 0. + WKPageCreateNewPageCallback_deprecatedForUseWithV0 createNewPage_deprecatedForUseWithV0; + WKPageUIClientCallback showPage; + WKPageUIClientCallback close; + WKPageTakeFocusCallback takeFocus; + WKPageFocusCallback focus; + WKPageUnfocusCallback unfocus; + WKPageRunJavaScriptAlertCallback_deprecatedForUseWithV0 runJavaScriptAlert_deprecatedForUseWithV0; + WKPageRunJavaScriptConfirmCallback_deprecatedForUseWithV0 runJavaScriptConfirm_deprecatedForUseWithV0; + WKPageRunJavaScriptPromptCallback_deprecatedForUseWithV0 runJavaScriptPrompt_deprecatedForUseWithV0; + WKPageSetStatusTextCallback setStatusText; + WKPageMouseDidMoveOverElementCallback_deprecatedForUseWithV0 mouseDidMoveOverElement_deprecatedForUseWithV0; + WKPageMissingPluginButtonClickedCallback_deprecatedForUseWithV0 missingPluginButtonClicked_deprecatedForUseWithV0; + WKPageDidNotHandleKeyEventCallback didNotHandleKeyEvent; + WKPageDidNotHandleWheelEventCallback didNotHandleWheelEvent; + WKPageGetToolbarsAreVisibleCallback toolbarsAreVisible; + WKPageSetToolbarsAreVisibleCallback setToolbarsAreVisible; + WKPageGetMenuBarIsVisibleCallback menuBarIsVisible; + WKPageSetMenuBarIsVisibleCallback setMenuBarIsVisible; + WKPageGetStatusBarIsVisibleCallback statusBarIsVisible; + WKPageSetStatusBarIsVisibleCallback setStatusBarIsVisible; + WKPageGetIsResizableCallback isResizable; + WKPageSetIsResizableCallback setIsResizable; + WKPageGetWindowFrameCallback getWindowFrame; + WKPageSetWindowFrameCallback setWindowFrame; + WKPageRunBeforeUnloadConfirmPanelCallback_deprecatedForUseWithV6 runBeforeUnloadConfirmPanel; + WKPageUIClientCallback didDraw; + WKPageUIClientCallback pageDidScroll; + WKPageExceededDatabaseQuotaCallback exceededDatabaseQuota; + WKPageRunOpenPanelCallback runOpenPanel; + WKPageDecidePolicyForGeolocationPermissionRequestCallback decidePolicyForGeolocationPermissionRequest; + WKPageHeaderHeightCallback headerHeight; + WKPageFooterHeightCallback footerHeight; + WKPageDrawHeaderCallback drawHeader; + WKPageDrawFooterCallback drawFooter; + WKPagePrintFrameCallback printFrame; + WKPageUIClientCallback runModal; + void* unused1; // Used to be didCompleteRubberBandForMainFrame + WKPageSaveDataToFileInDownloadsFolderCallback saveDataToFileInDownloadsFolder; + void* shouldInterruptJavaScript_unavailable; + + // Version 1. + WKPageCreateNewPageCallback_deprecatedForUseWithV1 createNewPage; + WKPageMouseDidMoveOverElementCallback mouseDidMoveOverElement; + WKPageDecidePolicyForNotificationPermissionRequestCallback decidePolicyForNotificationPermissionRequest; + WKPageUnavailablePluginButtonClickedCallback_deprecatedForUseWithV1 unavailablePluginButtonClicked_deprecatedForUseWithV1; + + // Version 2. + WKPageShowColorPickerCallback showColorPicker; + WKPageHideColorPickerCallback hideColorPicker; + WKPageUnavailablePluginButtonClickedCallback unavailablePluginButtonClicked; + + // Version 3. + WKPagePinnedStateDidChangeCallback pinnedStateDidChange; + + // Version 4. + void* unused2; // Used to be didBeginTrackingPotentialLongMousePress. + void* unused3; // Used to be didRecognizeLongMousePress. + void* unused4; // Used to be didCancelTrackingPotentialLongMousePress. + WKPageIsPlayingAudioDidChangeCallback isPlayingAudioDidChange; + + // Version 5. + WKPageDecidePolicyForUserMediaPermissionRequestCallback decidePolicyForUserMediaPermissionRequest; + WKPageDidClickAutoFillButtonCallback didClickAutoFillButton; + WKPageRunJavaScriptAlertCallback_deprecatedForUseWithV5 runJavaScriptAlert; + WKPageRunJavaScriptConfirmCallback_deprecatedForUseWithV5 runJavaScriptConfirm; + WKPageRunJavaScriptPromptCallback_deprecatedForUseWithV5 runJavaScriptPrompt; + WKPageMediaSessionMetadataDidChangeCallback mediaSessionMetadataDidChange; +} WKPageUIClientV5; + +typedef struct WKPageUIClientV6 { + WKPageUIClientBase base; + + // Version 0. + WKPageCreateNewPageCallback_deprecatedForUseWithV0 createNewPage_deprecatedForUseWithV0; + WKPageUIClientCallback showPage; + WKPageUIClientCallback close; + WKPageTakeFocusCallback takeFocus; + WKPageFocusCallback focus; + WKPageUnfocusCallback unfocus; + WKPageRunJavaScriptAlertCallback_deprecatedForUseWithV0 runJavaScriptAlert_deprecatedForUseWithV0; + WKPageRunJavaScriptConfirmCallback_deprecatedForUseWithV0 runJavaScriptConfirm_deprecatedForUseWithV0; + WKPageRunJavaScriptPromptCallback_deprecatedForUseWithV0 runJavaScriptPrompt_deprecatedForUseWithV0; + WKPageSetStatusTextCallback setStatusText; + WKPageMouseDidMoveOverElementCallback_deprecatedForUseWithV0 mouseDidMoveOverElement_deprecatedForUseWithV0; + WKPageMissingPluginButtonClickedCallback_deprecatedForUseWithV0 missingPluginButtonClicked_deprecatedForUseWithV0; + WKPageDidNotHandleKeyEventCallback didNotHandleKeyEvent; + WKPageDidNotHandleWheelEventCallback didNotHandleWheelEvent; + WKPageGetToolbarsAreVisibleCallback toolbarsAreVisible; + WKPageSetToolbarsAreVisibleCallback setToolbarsAreVisible; + WKPageGetMenuBarIsVisibleCallback menuBarIsVisible; + WKPageSetMenuBarIsVisibleCallback setMenuBarIsVisible; + WKPageGetStatusBarIsVisibleCallback statusBarIsVisible; + WKPageSetStatusBarIsVisibleCallback setStatusBarIsVisible; + WKPageGetIsResizableCallback isResizable; + WKPageSetIsResizableCallback setIsResizable; + WKPageGetWindowFrameCallback getWindowFrame; + WKPageSetWindowFrameCallback setWindowFrame; + WKPageRunBeforeUnloadConfirmPanelCallback_deprecatedForUseWithV6 runBeforeUnloadConfirmPanel; + WKPageUIClientCallback didDraw; + WKPageUIClientCallback pageDidScroll; + WKPageExceededDatabaseQuotaCallback exceededDatabaseQuota; + WKPageRunOpenPanelCallback runOpenPanel; + WKPageDecidePolicyForGeolocationPermissionRequestCallback decidePolicyForGeolocationPermissionRequest; + WKPageHeaderHeightCallback headerHeight; + WKPageFooterHeightCallback footerHeight; + WKPageDrawHeaderCallback drawHeader; + WKPageDrawFooterCallback drawFooter; + WKPagePrintFrameCallback printFrame; + WKPageUIClientCallback runModal; + void* unused1; // Used to be didCompleteRubberBandForMainFrame + WKPageSaveDataToFileInDownloadsFolderCallback saveDataToFileInDownloadsFolder; + void* shouldInterruptJavaScript_unavailable; + + // Version 1. + WKPageCreateNewPageCallback_deprecatedForUseWithV1 createNewPage_deprecatedForUseWithV1; + WKPageMouseDidMoveOverElementCallback mouseDidMoveOverElement; + WKPageDecidePolicyForNotificationPermissionRequestCallback decidePolicyForNotificationPermissionRequest; + WKPageUnavailablePluginButtonClickedCallback_deprecatedForUseWithV1 unavailablePluginButtonClicked_deprecatedForUseWithV1; + + // Version 2. + WKPageShowColorPickerCallback showColorPicker; + WKPageHideColorPickerCallback hideColorPicker; + WKPageUnavailablePluginButtonClickedCallback unavailablePluginButtonClicked; + + // Version 3. + WKPagePinnedStateDidChangeCallback pinnedStateDidChange; + + // Version 4. + void* unused2; // Used to be didBeginTrackingPotentialLongMousePress. + void* unused3; // Used to be didRecognizeLongMousePress. + void* unused4; // Used to be didCancelTrackingPotentialLongMousePress. + WKPageIsPlayingAudioDidChangeCallback isPlayingAudioDidChange; + + // Version 5. + WKPageDecidePolicyForUserMediaPermissionRequestCallback decidePolicyForUserMediaPermissionRequest; + WKPageDidClickAutoFillButtonCallback didClickAutoFillButton; + WKPageRunJavaScriptAlertCallback_deprecatedForUseWithV5 runJavaScriptAlert_deprecatedForUseWithV5; + WKPageRunJavaScriptConfirmCallback_deprecatedForUseWithV5 runJavaScriptConfirm_deprecatedForUseWithV5; + WKPageRunJavaScriptPromptCallback_deprecatedForUseWithV5 runJavaScriptPrompt_deprecatedForUseWithV5; + WKPageMediaSessionMetadataDidChangeCallback mediaSessionMetadataDidChange; + + // Version 6. + WKPageCreateNewPageCallback createNewPage; WKPageRunJavaScriptAlertCallback runJavaScriptAlert; WKPageRunJavaScriptConfirmCallback runJavaScriptConfirm; WKPageRunJavaScriptPromptCallback runJavaScriptPrompt; + WKCheckUserMediaPermissionCallback checkUserMediaPermissionForOrigin; +} WKPageUIClientV6; + +typedef struct WKPageUIClientV7 { + WKPageUIClientBase base; + + // Version 0. + WKPageCreateNewPageCallback_deprecatedForUseWithV0 createNewPage_deprecatedForUseWithV0; + WKPageUIClientCallback showPage; + WKPageUIClientCallback close; + WKPageTakeFocusCallback takeFocus; + WKPageFocusCallback focus; + WKPageUnfocusCallback unfocus; + WKPageRunJavaScriptAlertCallback_deprecatedForUseWithV0 runJavaScriptAlert_deprecatedForUseWithV0; + WKPageRunJavaScriptConfirmCallback_deprecatedForUseWithV0 runJavaScriptConfirm_deprecatedForUseWithV0; + WKPageRunJavaScriptPromptCallback_deprecatedForUseWithV0 runJavaScriptPrompt_deprecatedForUseWithV0; WKPageSetStatusTextCallback setStatusText; WKPageMouseDidMoveOverElementCallback_deprecatedForUseWithV0 mouseDidMoveOverElement_deprecatedForUseWithV0; WKPageMissingPluginButtonClickedCallback_deprecatedForUseWithV0 missingPluginButtonClicked_deprecatedForUseWithV0; @@ -279,7 +579,7 @@ typedef struct WKPageUIClient { WKPageSetIsResizableCallback setIsResizable; WKPageGetWindowFrameCallback getWindowFrame; WKPageSetWindowFrameCallback setWindowFrame; - WKPageRunBeforeUnloadConfirmPanelCallback runBeforeUnloadConfirmPanel; + WKPageRunBeforeUnloadConfirmPanelCallback_deprecatedForUseWithV6 runBeforeUnloadConfirmPanel_deprecatedForUseWithV6; WKPageUIClientCallback didDraw; WKPageUIClientCallback pageDidScroll; WKPageExceededDatabaseQuotaCallback exceededDatabaseQuota; @@ -293,10 +593,10 @@ typedef struct WKPageUIClient { WKPageUIClientCallback runModal; void* unused1; // Used to be didCompleteRubberBandForMainFrame WKPageSaveDataToFileInDownloadsFolderCallback saveDataToFileInDownloadsFolder; - WKPageShouldInterruptJavaScriptCallback shouldInterruptJavaScript; + void* shouldInterruptJavaScript_unavailable; // Version 1. - WKPageCreateNewPageCallback createNewPage; + WKPageCreateNewPageCallback_deprecatedForUseWithV1 createNewPage_deprecatedForUseWithV1; WKPageMouseDidMoveOverElementCallback mouseDidMoveOverElement; WKPageDecidePolicyForNotificationPermissionRequestCallback decidePolicyForNotificationPermissionRequest; WKPageUnavailablePluginButtonClickedCallback_deprecatedForUseWithV1 unavailablePluginButtonClicked_deprecatedForUseWithV1; @@ -305,7 +605,34 @@ typedef struct WKPageUIClient { WKPageShowColorPickerCallback showColorPicker; WKPageHideColorPickerCallback hideColorPicker; WKPageUnavailablePluginButtonClickedCallback unavailablePluginButtonClicked; -} WKPageUIClient WK_DEPRECATED("Use an explicit versioned struct instead"); + + // Version 3. + WKPagePinnedStateDidChangeCallback pinnedStateDidChange; + + // Version 4. + void* unused2; // Used to be didBeginTrackingPotentialLongMousePress. + void* unused3; // Used to be didRecognizeLongMousePress. + void* unused4; // Used to be didCancelTrackingPotentialLongMousePress. + WKPageIsPlayingAudioDidChangeCallback isPlayingAudioDidChange; + + // Version 5. + WKPageDecidePolicyForUserMediaPermissionRequestCallback decidePolicyForUserMediaPermissionRequest; + WKPageDidClickAutoFillButtonCallback didClickAutoFillButton; + WKPageRunJavaScriptAlertCallback_deprecatedForUseWithV5 runJavaScriptAlert_deprecatedForUseWithV5; + WKPageRunJavaScriptConfirmCallback_deprecatedForUseWithV5 runJavaScriptConfirm_deprecatedForUseWithV5; + WKPageRunJavaScriptPromptCallback_deprecatedForUseWithV5 runJavaScriptPrompt_deprecatedForUseWithV5; + WKPageMediaSessionMetadataDidChangeCallback mediaSessionMetadataDidChange; + + // Version 6. + WKPageCreateNewPageCallback createNewPage; + WKPageRunJavaScriptAlertCallback runJavaScriptAlert; + WKPageRunJavaScriptConfirmCallback runJavaScriptConfirm; + WKPageRunJavaScriptPromptCallback runJavaScriptPrompt; + WKCheckUserMediaPermissionCallback checkUserMediaPermissionForOrigin; + + // Version 7. + WKPageRunBeforeUnloadConfirmPanelCallback runBeforeUnloadConfirmPanel; +} WKPageUIClientV7; #ifdef __cplusplus } diff --git a/Source/WebKit2/UIProcess/API/C/WKPluginLoadPolicy.h b/Source/WebKit2/UIProcess/API/C/WKPluginLoadPolicy.h new file mode 100644 index 000000000..7aaef37ee --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKPluginLoadPolicy.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKPluginLoadPolicy_h +#define WKPluginLoadPolicy_h + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +enum { + kWKPluginLoadPolicyLoadNormally = 0, + kWKPluginLoadPolicyBlocked, + kWKPluginLoadPolicyInactive, + kWKPluginLoadPolicyLoadUnsandboxed, + kWKPluginLoadPolicyBlockedForCompatibility, +}; +typedef uint32_t WKPluginLoadPolicy; + +enum { + kWKPluginLoadClientPolicyUndefined = 0, + kWKPluginLoadClientPolicyBlock, + kWKPluginLoadClientPolicyAsk, + kWKPluginLoadClientPolicyAllow, + kWKPluginLoadClientPolicyAllowAlways, +}; +typedef uint32_t WKPluginLoadClientPolicy; + +#ifdef __cplusplus +} +#endif + +#endif /* WKPluginLoadPolicy_h */ diff --git a/Source/WebKit2/UIProcess/API/C/WKPluginSiteDataManager.cpp b/Source/WebKit2/UIProcess/API/C/WKPluginSiteDataManager.cpp index 5ae8abf9d..1015fc4f2 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPluginSiteDataManager.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKPluginSiteDataManager.cpp @@ -28,68 +28,71 @@ #include "APIObject.h" #include "WKAPICast.h" -#include "WebPluginSiteDataManager.h" - -#if ENABLE(NETSCAPE_PLUGIN_API) -#include <WebCore/npapi.h> -#endif +#include "WebProcessPool.h" +#include "WebsiteDataRecord.h" using namespace WebKit; WKTypeID WKPluginSiteDataManagerGetTypeID() { -#if ENABLE(NETSCAPE_PLUGIN_API) - return toAPI(WebPluginSiteDataManager::APIType); -#else - return toAPI(API::Object::Type::Null); -#endif + return toAPI(API::WebsiteDataStore::APIType); } -void WKPluginSiteDataManagerGetSitesWithData(WKPluginSiteDataManagerRef managerRef, void* context, WKPluginSiteDataManagerGetSitesWithDataFunction callback) +void WKPluginSiteDataManagerGetSitesWithData(WKPluginSiteDataManagerRef manager, void* context, WKPluginSiteDataManagerGetSitesWithDataFunction callback) { #if ENABLE(NETSCAPE_PLUGIN_API) - toImpl(managerRef)->getSitesWithData(ArrayCallback::create(context, callback)); + auto& websiteDataStore = toImpl(reinterpret_cast<WKWebsiteDataStoreRef>(manager))->websiteDataStore(); + websiteDataStore.fetchData(WebsiteDataTypes::WebsiteDataTypePlugInData, [context, callback](Vector<WebsiteDataRecord> dataRecords) { + Vector<String> hostNames; + for (const auto& dataRecord : dataRecords) { + for (const auto& hostName : dataRecord.pluginDataHostNames) + hostNames.append(hostName); + } + + callback(toAPI(API::Array::createStringArray(hostNames).ptr()), nullptr, context); + }); #else - UNUSED_PARAM(managerRef); + UNUSED_PARAM(manager); UNUSED_PARAM(context); UNUSED_PARAM(callback); #endif } -#if ENABLE(NETSCAPE_PLUGIN_API) -static uint64_t toNPClearSiteDataFlags(WKClearSiteDataFlags flags) +void WKPluginSiteDataManagerClearSiteData(WKPluginSiteDataManagerRef manager, WKArrayRef sites, WKClearSiteDataFlags flags, uint64_t maxAgeInSeconds, void* context, WKPluginSiteDataManagerClearSiteDataFunction callback) { - if (flags == kWKClearSiteDataFlagsClearAll) - return NP_CLEAR_ALL; + // These are the only parameters supported. + ASSERT_UNUSED(flags, flags == kWKClearSiteDataFlagsClearAll); + ASSERT_UNUSED(maxAgeInSeconds, maxAgeInSeconds == std::numeric_limits<uint64_t>::max()); - uint64_t result = 0; - if (flags & kWKClearSiteDataFlagsClearCache) - result |= NP_CLEAR_CACHE; - return result; -} -#endif - -void WKPluginSiteDataManagerClearSiteData(WKPluginSiteDataManagerRef managerRef, WKArrayRef sitesRef, WKClearSiteDataFlags flags, uint64_t maxAgeInSeconds, void* context, WKPluginSiteDataManagerClearSiteDataFunction function) -{ #if ENABLE(NETSCAPE_PLUGIN_API) - toImpl(managerRef)->clearSiteData(toImpl(sitesRef), toNPClearSiteDataFlags(flags), maxAgeInSeconds, VoidCallback::create(context, function)); + WebsiteDataRecord dataRecord; + for (const auto& string : toImpl(sites)->elementsOfType<API::String>()) + dataRecord.pluginDataHostNames.add(string->string()); + + auto& websiteDataStore = toImpl(reinterpret_cast<WKWebsiteDataStoreRef>(manager))->websiteDataStore(); + websiteDataStore.removeData(WebsiteDataTypes::WebsiteDataTypePlugInData, { dataRecord }, [context, callback] { + callback(nullptr, context); + }); #else - UNUSED_PARAM(managerRef); - UNUSED_PARAM(sitesRef); + UNUSED_PARAM(manager); + UNUSED_PARAM(sites); UNUSED_PARAM(flags); UNUSED_PARAM(maxAgeInSeconds); UNUSED_PARAM(context); - UNUSED_PARAM(function); + UNUSED_PARAM(callback); #endif } -void WKPluginSiteDataManagerClearAllSiteData(WKPluginSiteDataManagerRef managerRef, void* context, WKPluginSiteDataManagerClearSiteDataFunction function) +void WKPluginSiteDataManagerClearAllSiteData(WKPluginSiteDataManagerRef manager, void* context, WKPluginSiteDataManagerClearSiteDataFunction callback) { #if ENABLE(NETSCAPE_PLUGIN_API) - toImpl(managerRef)->clearSiteData(0, NP_CLEAR_ALL, std::numeric_limits<uint64_t>::max(), VoidCallback::create(context, function)); + auto& websiteDataStore = toImpl(reinterpret_cast<WKWebsiteDataStoreRef>(manager))->websiteDataStore(); + websiteDataStore.removeData(WebsiteDataTypes::WebsiteDataTypePlugInData, std::chrono::system_clock::time_point::min(), [context, callback] { + callback(nullptr, context); + }); #else - UNUSED_PARAM(managerRef); + UNUSED_PARAM(manager); UNUSED_PARAM(context); - UNUSED_PARAM(function); + UNUSED_PARAM(callback); #endif } diff --git a/Source/WebKit2/UIProcess/API/C/WKPluginSiteDataManager.h b/Source/WebKit2/UIProcess/API/C/WKPluginSiteDataManager.h index 66e76fbcd..9a772b2b5 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPluginSiteDataManager.h +++ b/Source/WebKit2/UIProcess/API/C/WKPluginSiteDataManager.h @@ -26,7 +26,7 @@ #ifndef WKPluginSiteDataManager_h #define WKPluginSiteDataManager_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/WKPreferences.cpp b/Source/WebKit2/UIProcess/API/C/WKPreferences.cpp index d81dd2ba5..7699c5392 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPreferences.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKPreferences.cpp @@ -24,11 +24,10 @@ */ #include "config.h" -#include "WKPreferencesPrivate.h" -#include "WKPreferencesRef.h" +#include "WKPreferencesRef.h" +#include "WKPreferencesRefPrivate.h" #include "WKAPICast.h" -#include "WebContext.h" #include "WebPreferences.h" #include <WebCore/Settings.h> #include <wtf/PassRefPtr.h> @@ -43,19 +42,19 @@ WKTypeID WKPreferencesGetTypeID() WKPreferencesRef WKPreferencesCreate() { - RefPtr<WebPreferences> preferences = WebPreferences::create(); + RefPtr<WebPreferences> preferences = WebPreferences::createWithLegacyDefaults(String(), "WebKit2.", "WebKit2."); return toAPI(preferences.release().leakRef()); } WKPreferencesRef WKPreferencesCreateWithIdentifier(WKStringRef identifierRef) { - RefPtr<WebPreferences> preferences = WebPreferences::create(toWTFString(identifierRef)); + RefPtr<WebPreferences> preferences = WebPreferences::createWithLegacyDefaults(toWTFString(identifierRef), "WebKit2.", "WebKit2."); return toAPI(preferences.release().leakRef()); } WKPreferencesRef WKPreferencesCreateCopy(WKPreferencesRef preferencesRef) { - RefPtr<WebPreferences> preferences = WebPreferences::create(*toImpl(preferencesRef)); + RefPtr<WebPreferences> preferences = toImpl(preferencesRef)->copy(); return toAPI(preferences.release().leakRef()); } @@ -299,15 +298,6 @@ uint32_t WKPreferencesGetMinimumFontSize(WKPreferencesRef preferencesRef) return toImpl(preferencesRef)->minimumFontSize(); } -void WKPreferencesSetScreenFontSubstitutionEnabled(WKPreferencesRef preferencesRef, bool enabled) -{ - toImpl(preferencesRef)->setScreenFontSubstitutionEnabled(enabled); -} - -bool WKPreferencesGetScreenFontSubstitutionEnabled(WKPreferencesRef preferencesRef) -{ - return toImpl(preferencesRef)->screenFontSubstitutionEnabled(); -} void WKPreferencesSetCookieEnabled(WKPreferencesRef preferencesRef, bool enabled) { @@ -359,14 +349,14 @@ bool WKPreferencesGetDeveloperExtrasEnabled(WKPreferencesRef preferencesRef) return toImpl(preferencesRef)->developerExtrasEnabled(); } -void WKPreferencesSetJavaScriptExperimentsEnabled(WKPreferencesRef preferencesRef, bool enabled) +void WKPreferencesSetJavaScriptRuntimeFlags(WKPreferencesRef preferencesRef, WKJavaScriptRuntimeFlagSet javaScriptRuntimeFlagSet) { - toImpl(preferencesRef)->setJavaScriptExperimentsEnabled(enabled); + toImpl(preferencesRef)->setJavaScriptRuntimeFlags(javaScriptRuntimeFlagSet); } -bool WKPreferencesGetJavaScriptExperimentsEnabled(WKPreferencesRef preferencesRef) +WKJavaScriptRuntimeFlagSet WKPreferencesGetJavaScriptRuntimeFlags(WKPreferencesRef preferencesRef) { - return toImpl(preferencesRef)->javaScriptExperimentsEnabled(); + return toImpl(preferencesRef)->javaScriptRuntimeFlags(); } void WKPreferencesSetTextAreasAreResizable(WKPreferencesRef preferencesRef, bool resizable) @@ -469,16 +459,6 @@ bool WKPreferencesGetWebGLEnabled(WKPreferencesRef preferencesRef) return toImpl(preferencesRef)->webGLEnabled(); } -void WKPreferencesSetMultithreadedWebGLEnabled(WKPreferencesRef preferencesRef, bool flag) -{ - toImpl(preferencesRef)->setMultithreadedWebGLEnabled(flag); -} - -bool WKPreferencesGetMultithreadedWebGLEnabled(WKPreferencesRef preferencesRef) -{ - return toImpl(preferencesRef)->multithreadedWebGLEnabled(); -} - void WKPreferencesSetForceSoftwareWebGLRendering(WKPreferencesRef preferencesRef, bool flag) { toImpl(preferencesRef)->setForceSoftwareWebGLRendering(flag); @@ -499,34 +479,34 @@ bool WKPreferencesGetAccelerated2DCanvasEnabled(WKPreferencesRef preferencesRef) return toImpl(preferencesRef)->accelerated2dCanvasEnabled(); } -void WKPreferencesSetCSSRegionsEnabled(WKPreferencesRef preferencesRef, bool flag) +void WKPreferencesSetCSSAnimationTriggersEnabled(WKPreferencesRef preferencesRef, bool flag) { - toImpl(preferencesRef)->setCSSRegionsEnabled(flag); + toImpl(preferencesRef)->setCSSAnimationTriggersEnabled(flag); } -bool WKPreferencesGetCSSRegionsEnabled(WKPreferencesRef preferencesRef) +bool WKPreferencesGetCSSAnimationTriggersEnabled(WKPreferencesRef preferencesRef) { - return toImpl(preferencesRef)->cssRegionsEnabled(); + return toImpl(preferencesRef)->cssAnimationTriggersEnabled(); } -void WKPreferencesSetCSSGridLayoutEnabled(WKPreferencesRef preferencesRef, bool flag) +void WKPreferencesSetWebAnimationsEnabled(WKPreferencesRef preferencesRef, bool flag) { - toImpl(preferencesRef)->setCSSGridLayoutEnabled(flag); + toImpl(preferencesRef)->setWebAnimationsEnabled(flag); } -bool WKPreferencesGetCSSGridLayoutEnabled(WKPreferencesRef preferencesRef) +bool WKPreferencesGetWebAnimationsEnabled(WKPreferencesRef preferencesRef) { - return toImpl(preferencesRef)->cssGridLayoutEnabled(); + return toImpl(preferencesRef)->webAnimationsEnabled(); } -void WKPreferencesSetRegionBasedColumnsEnabled(WKPreferencesRef preferencesRef, bool flag) +void WKPreferencesSetCSSRegionsEnabled(WKPreferencesRef preferencesRef, bool flag) { - toImpl(preferencesRef)->setRegionBasedColumnsEnabled(flag); + toImpl(preferencesRef)->setCSSRegionsEnabled(flag); } -bool WKPreferencesGetRegionBasedColumnsEnabled(WKPreferencesRef preferencesRef) +bool WKPreferencesGetCSSRegionsEnabled(WKPreferencesRef preferencesRef) { - return toImpl(preferencesRef)->regionBasedColumnsEnabled(); + return toImpl(preferencesRef)->cssRegionsEnabled(); } void WKPreferencesSetNeedsSiteSpecificQuirks(WKPreferencesRef preferencesRef, bool flag) @@ -609,6 +589,16 @@ bool WKPreferencesGetShouldPrintBackgrounds(WKPreferencesRef preferencesRef) return toImpl(preferencesRef)->shouldPrintBackgrounds(); } +void WKPreferencesSetDOMTimersThrottlingEnabled(WKPreferencesRef preferencesRef, bool enabled) +{ + toImpl(preferencesRef)->setDOMTimersThrottlingEnabled(enabled); +} + +bool WKPreferencesGetDOMTimersThrottlingEnabled(WKPreferencesRef preferencesRef) +{ + return toImpl(preferencesRef)->domTimersThrottlingEnabled(); +} + void WKPreferencesSetWebArchiveDebugModeEnabled(WKPreferencesRef preferencesRef, bool enabled) { toImpl(preferencesRef)->setWebArchiveDebugModeEnabled(enabled); @@ -709,6 +699,16 @@ bool WKPreferencesGetAVFoundationEnabled(WKPreferencesRef preferencesRef) return toImpl(preferencesRef)->isAVFoundationEnabled(); } +void WKPreferencesSetAVFoundationNSURLSessionEnabled(WKPreferencesRef preferencesRef, bool enabled) +{ + toImpl(preferencesRef)->setAVFoundationNSURLSessionEnabled(enabled); +} + +bool WKPreferencesGetAVFoundationNSURLSessionEnabled(WKPreferencesRef preferencesRef) +{ + return toImpl(preferencesRef)->isAVFoundationNSURLSessionEnabled(); +} + void WKPreferencesSetWebSecurityEnabled(WKPreferencesRef preferencesRef, bool enabled) { toImpl(preferencesRef)->setWebSecurityEnabled(enabled); @@ -750,22 +750,52 @@ bool WKPreferencesGetHixie76WebSocketProtocolEnabled(WKPreferencesRef) void WKPreferencesSetMediaPlaybackRequiresUserGesture(WKPreferencesRef preferencesRef, bool flag) { - toImpl(preferencesRef)->setMediaPlaybackRequiresUserGesture(flag); + toImpl(preferencesRef)->setRequiresUserGestureForMediaPlayback(flag); } bool WKPreferencesGetMediaPlaybackRequiresUserGesture(WKPreferencesRef preferencesRef) { - return toImpl(preferencesRef)->mediaPlaybackRequiresUserGesture(); + return toImpl(preferencesRef)->requiresUserGestureForMediaPlayback(); +} + +void WKPreferencesSetAudioPlaybackRequiresUserGesture(WKPreferencesRef preferencesRef, bool flag) +{ + toImpl(preferencesRef)->setRequiresUserGestureForAudioPlayback(flag); +} + +bool WKPreferencesGetAudioPlaybackRequiresUserGesture(WKPreferencesRef preferencesRef) +{ + return toImpl(preferencesRef)->requiresUserGestureForAudioPlayback(); } void WKPreferencesSetMediaPlaybackAllowsInline(WKPreferencesRef preferencesRef, bool flag) { - toImpl(preferencesRef)->setMediaPlaybackAllowsInline(flag); + toImpl(preferencesRef)->setAllowsInlineMediaPlayback(flag); } bool WKPreferencesGetMediaPlaybackAllowsInline(WKPreferencesRef preferencesRef) { - return toImpl(preferencesRef)->mediaPlaybackAllowsInline(); + return toImpl(preferencesRef)->allowsInlineMediaPlayback(); +} + +void WKPreferencesSetInlineMediaPlaybackRequiresPlaysInlineAttribute(WKPreferencesRef preferencesRef, bool flag) +{ + toImpl(preferencesRef)->setInlineMediaPlaybackRequiresPlaysInlineAttribute(flag); +} + +bool WKPreferencesGetInlineMediaPlaybackRequiresPlaysInlineAttribute(WKPreferencesRef preferencesRef) +{ + return toImpl(preferencesRef)->inlineMediaPlaybackRequiresPlaysInlineAttribute(); +} + +void WKPreferencesSetMediaControlsScaleWithPageZoom(WKPreferencesRef preferencesRef, bool flag) +{ + toImpl(preferencesRef)->setMediaControlsScaleWithPageZoom(flag); +} + +bool WKPreferencesGetMediaControlsScaleWithPageZoom(WKPreferencesRef preferencesRef) +{ + return toImpl(preferencesRef)->mediaControlsScaleWithPageZoom(); } void WKPreferencesSetShowsToolTipOverTruncatedText(WKPreferencesRef preferencesRef, bool flag) @@ -798,14 +828,15 @@ bool WKPreferencesGetWebAudioEnabled(WKPreferencesRef preferencesRef) return toImpl(preferencesRef)->webAudioEnabled(); } -void WKPreferencesSetApplicationChromeModeEnabled(WKPreferencesRef preferencesRef, bool enabled) +void WKPreferencesSetApplicationChromeModeEnabled(WKPreferencesRef, bool) { - toImpl(preferencesRef)->setApplicationChromeModeEnabled(enabled); + // FIXME: Remove once WebKit nightlies don't need to support Safari 8. } -bool WKPreferencesGetApplicationChromeModeEnabled(WKPreferencesRef preferencesRef) +bool WKPreferencesGetApplicationChromeModeEnabled(WKPreferencesRef) { - return toImpl(preferencesRef)->applicationChromeMode(); + // FIXME: Remove once WebKit nightlies don't need to support Safari 8. + return false; } void WKPreferencesSetInspectorUsesWebKitUserInterface(WKPreferencesRef, bool) @@ -1196,24 +1227,44 @@ bool WKPreferencesGetSimpleLineLayoutDebugBordersEnabled(WKPreferencesRef prefer return toImpl(preferencesRef)->simpleLineLayoutDebugBordersEnabled(); } -void WKPreferencesSetMediaStreamEnabled(WKPreferencesRef preferencesRef, bool enabled) +void WKPreferencesSetNewBlockInsideInlineModelEnabled(WKPreferencesRef preferencesRef, bool flag) { - toImpl(preferencesRef)->setMediaStreamEnabled(enabled); + toImpl(preferencesRef)->setNewBlockInsideInlineModelEnabled(flag); } -bool WKPreferencesGetMediaStreamEnabled(WKPreferencesRef preferencesRef) +bool WKPreferencesGetNewBlockInsideInlineModelEnabled(WKPreferencesRef preferencesRef) { - return toImpl(preferencesRef)->mediaStreamEnabled(); + return toImpl(preferencesRef)->newBlockInsideInlineModelEnabled(); +} + +void WKPreferencesSetSubpixelCSSOMElementMetricsEnabled(WKPreferencesRef preferencesRef, bool flag) +{ + toImpl(preferencesRef)->setSubpixelCSSOMElementMetricsEnabled(flag); +} + +bool WKPreferencesGetSubpixelCSSOMElementMetricsEnabled(WKPreferencesRef preferencesRef) +{ + return toImpl(preferencesRef)->subpixelCSSOMElementMetricsEnabled(); +} + +void WKPreferencesSetUseGiantTiles(WKPreferencesRef preferencesRef, bool flag) +{ + toImpl(preferencesRef)->setUseGiantTiles(flag); } -void WKPreferencesSetVideoPluginProxyEnabled(WKPreferencesRef preferencesRef, bool enabled) +bool WKPreferencesGetUseGiantTiles(WKPreferencesRef preferencesRef) { - toImpl(preferencesRef)->setVideoPluginProxyEnabled(enabled); + return toImpl(preferencesRef)->useGiantTiles(); } -bool WKPreferencesGetVideoPluginProxyEnabled(WKPreferencesRef preferencesRef) +void WKPreferencesSetMediaStreamEnabled(WKPreferencesRef preferencesRef, bool enabled) { - return toImpl(preferencesRef)->isVideoPluginProxyEnabled(); + toImpl(preferencesRef)->setMediaStreamEnabled(enabled); +} + +bool WKPreferencesGetMediaStreamEnabled(WKPreferencesRef preferencesRef) +{ + return toImpl(preferencesRef)->mediaStreamEnabled(); } void WKPreferencesSetSpatialNavigationEnabled(WKPreferencesRef preferencesRef, bool enabled) @@ -1245,3 +1296,163 @@ bool WKPreferencesGetViewGestureDebuggingEnabled(WKPreferencesRef preferencesRef { return toImpl(preferencesRef)->viewGestureDebuggingEnabled(); } + +void WKPreferencesSetShouldConvertPositionStyleOnCopy(WKPreferencesRef preferencesRef, bool convert) +{ + toImpl(preferencesRef)->setShouldConvertPositionStyleOnCopy(convert); +} + +bool WKPreferencesGetShouldConvertPositionStyleOnCopy(WKPreferencesRef preferencesRef) +{ + return toImpl(preferencesRef)->shouldConvertPositionStyleOnCopy(); +} + +void WKPreferencesSetTelephoneNumberParsingEnabled(WKPreferencesRef preferencesRef, bool enabled) +{ + toImpl(preferencesRef)->setTelephoneNumberParsingEnabled(enabled); +} + +bool WKPreferencesGetTelephoneNumberParsingEnabled(WKPreferencesRef preferencesRef) +{ + return toImpl(preferencesRef)->telephoneNumberParsingEnabled(); +} + +void WKPreferencesSetEnableInheritURIQueryComponent(WKPreferencesRef preferencesRef, bool enabled) +{ + toImpl(preferencesRef)->setEnableInheritURIQueryComponent(enabled); +} + +bool WKPreferencesGetEnableInheritURIQueryComponent(WKPreferencesRef preferencesRef) +{ + return toImpl(preferencesRef)->enableInheritURIQueryComponent(); +} + +void WKPreferencesSetServiceControlsEnabled(WKPreferencesRef preferencesRef, bool enabled) +{ + toImpl(preferencesRef)->setServiceControlsEnabled(enabled); +} + +bool WKPreferencesGetServiceControlsEnabled(WKPreferencesRef preferencesRef) +{ + return toImpl(preferencesRef)->serviceControlsEnabled(); +} + +void WKPreferencesSetImageControlsEnabled(WKPreferencesRef preferencesRef, bool enabled) +{ + toImpl(preferencesRef)->setImageControlsEnabled(enabled); +} + +bool WKPreferencesGetImageControlsEnabled(WKPreferencesRef preferencesRef) +{ + return toImpl(preferencesRef)->imageControlsEnabled(); +} + +void WKPreferencesSetGamepadsEnabled(WKPreferencesRef preferencesRef, bool enabled) +{ + toImpl(preferencesRef)->setGamepadsEnabled(enabled); +} + +bool WKPreferencesGetGamepadsEnabled(WKPreferencesRef preferencesRef) +{ + return toImpl(preferencesRef)->gamepadsEnabled(); +} + +// FIXME: Remove these when possible. +void WKPreferencesSetLongMousePressEnabled(WKPreferencesRef preferencesRef, bool enabled) +{ +} + +bool WKPreferencesGetLongMousePressEnabled(WKPreferencesRef preferencesRef) +{ + return false; +} + +void WKPreferencesSetMinimumZoomFontSize(WKPreferencesRef preferencesRef, double size) +{ + toImpl(preferencesRef)->setMinimumZoomFontSize(size); +} + +double WKPreferencesGetMinimumZoomFontSize(WKPreferencesRef preferencesRef) +{ + return toImpl(preferencesRef)->minimumZoomFontSize(); +} + +void WKPreferencesSetAntialiasedFontDilationEnabled(WKPreferencesRef preferencesRef, bool enabled) +{ + toImpl(preferencesRef)->setAntialiasedFontDilationEnabled(enabled); +} + +bool WKPreferencesGetAntialiasedFontDilationEnabled(WKPreferencesRef preferencesRef) +{ + return toImpl(preferencesRef)->antialiasedFontDilationEnabled(); +} + +void WKPreferencesSetVisibleDebugOverlayRegions(WKPreferencesRef preferencesRef, WKDebugOverlayRegions visibleRegions) +{ + toImpl(preferencesRef)->setVisibleDebugOverlayRegions(visibleRegions); +} + +WKDebugOverlayRegions WKPreferencesGetVisibleDebugOverlayRegions(WKPreferencesRef preferencesRef) +{ + return toImpl(preferencesRef)->visibleDebugOverlayRegions(); +} + +void WKPreferencesSetIgnoreViewportScalingConstraints(WKPreferencesRef preferencesRef, bool enabled) +{ + toImpl(preferencesRef)->setIgnoreViewportScalingConstraints(enabled); +} + +bool WKPreferencesGetIgnoreViewportScalingConstraints(WKPreferencesRef preferencesRef) +{ + return toImpl(preferencesRef)->ignoreViewportScalingConstraints(); +} + +void WKPreferencesSetMetaRefreshEnabled(WKPreferencesRef preferencesRef, bool enabled) +{ + toImpl(preferencesRef)->setHTTPEquivEnabled(enabled); +} + +bool WKPreferencesGetMetaRefreshEnabled(WKPreferencesRef preferencesRef) +{ + return toImpl(preferencesRef)->httpEquivEnabled(); +} + +void WKPreferencesSetHTTPEquivEnabled(WKPreferencesRef preferencesRef, bool enabled) +{ + toImpl(preferencesRef)->setHTTPEquivEnabled(enabled); +} + +bool WKPreferencesGetHTTPEquivEnabled(WKPreferencesRef preferencesRef) +{ + return toImpl(preferencesRef)->httpEquivEnabled(); +} + +void WKPreferencesSetAllowsAirPlayForMediaPlayback(WKPreferencesRef preferencesRef, bool enabled) +{ + toImpl(preferencesRef)->setAllowsAirPlayForMediaPlayback(enabled); +} + +bool WKPreferencesGetAllowsAirPlayForMediaPlayback(WKPreferencesRef preferencesRef) +{ + return toImpl(preferencesRef)->allowsAirPlayForMediaPlayback(); +} + +void WKPreferencesSetResourceUsageOverlayVisible(WKPreferencesRef preferencesRef, bool enabled) +{ + toImpl(preferencesRef)->setResourceUsageOverlayVisible(enabled); +} + +bool WKPreferencesGetResourceUsageOverlayVisible(WKPreferencesRef preferencesRef) +{ + return toImpl(preferencesRef)->resourceUsageOverlayVisible(); +} + +void WKPreferencesSetMockCaptureDevicesEnabled(WKPreferencesRef preferencesRef, bool enabled) +{ + toImpl(preferencesRef)->setMockCaptureDevicesEnabled(enabled); +} + +bool WKPreferencesGetMockCaptureDevicesEnabled(WKPreferencesRef preferencesRef) +{ + return toImpl(preferencesRef)->mockCaptureDevicesEnabled(); +} diff --git a/Source/WebKit2/UIProcess/API/C/WKPreferencesRef.h b/Source/WebKit2/UIProcess/API/C/WKPreferencesRef.h index a4a7c9b1a..c352038bf 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPreferencesRef.h +++ b/Source/WebKit2/UIProcess/API/C/WKPreferencesRef.h @@ -26,7 +26,7 @@ #ifndef WKPreferencesRef_h #define WKPreferencesRef_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifndef __cplusplus #include <stdbool.h> @@ -43,6 +43,12 @@ enum WKStorageBlockingPolicy { }; typedef enum WKStorageBlockingPolicy WKStorageBlockingPolicy; +enum WKDebugOverlayRegionFlags { + kWKNonFastScrollableRegion = 1 << 0, + kWKWheelEventHandlerRegion = 1 << 1 +}; +typedef unsigned WKDebugOverlayRegions; + WK_EXPORT WKTypeID WKPreferencesGetTypeID(); WK_EXPORT WKPreferencesRef WKPreferencesCreate(); @@ -144,10 +150,6 @@ WK_EXPORT bool WKPreferencesGetPrivateBrowsingEnabled(WKPreferencesRef preferenc WK_EXPORT void WKPreferencesSetDeveloperExtrasEnabled(WKPreferencesRef preferencesRef, bool enabled); WK_EXPORT bool WKPreferencesGetDeveloperExtrasEnabled(WKPreferencesRef preferencesRef); -// Defaults to false. -WK_EXPORT void WKPreferencesSetJavaScriptExperimentsEnabled(WKPreferencesRef preferencesRef, bool enabled); -WK_EXPORT bool WKPreferencesGetJavaScriptExperimentsEnabled(WKPreferencesRef preferencesRef); - // Defaults to true. WK_EXPORT void WKPreferencesSetTextAreasAreResizable(WKPreferencesRef preferencesRef, bool resizable); WK_EXPORT bool WKPreferencesGetTextAreasAreResizable(WKPreferencesRef preferencesRef); @@ -180,6 +182,10 @@ WK_EXPORT bool WKPreferencesGetFullScreenEnabled(WKPreferencesRef preferencesRef WK_EXPORT void WKPreferencesSetAVFoundationEnabled(WKPreferencesRef preferencesRef, bool enabled); WK_EXPORT bool WKPreferencesGetAVFoundationEnabled(WKPreferencesRef preferencesRef); +// Defaults to false. +WK_EXPORT void WKPreferencesSetAVFoundationNSURLSessionEnabled(WKPreferencesRef preferencesRef, bool enabled); +WK_EXPORT bool WKPreferencesGetAVFoundationNSURLSessionEnabled(WKPreferencesRef preferencesRef); + // Defaults to false WK_EXPORT void WKPreferencesSetWebAudioEnabled(WKPreferencesRef preferencesRef, bool enabled); WK_EXPORT bool WKPreferencesGetWebAudioEnabled(WKPreferencesRef preferencesRef); @@ -216,7 +222,7 @@ WK_EXPORT bool WKPreferencesGetNotificationsEnabled(WKPreferencesRef preferences WK_EXPORT void WKPreferencesSetShouldRespectImageOrientation(WKPreferencesRef preferencesRef, bool enabled); WK_EXPORT bool WKPreferencesGetShouldRespectImageOrientation(WKPreferencesRef preferencesRef); -// Defaults to false +// Defaults to kWKAllowAllStorage WK_EXPORT void WKPreferencesSetStorageBlockingPolicy(WKPreferencesRef preferencesRef, WKStorageBlockingPolicy policy); WK_EXPORT WKStorageBlockingPolicy WKPreferencesGetStorageBlockingPolicy(WKPreferencesRef preferencesRef); @@ -244,14 +250,22 @@ WK_EXPORT bool WKPreferencesGetAsynchronousSpellCheckingEnabled(WKPreferencesRef WK_EXPORT void WKPreferencesSetMediaStreamEnabled(WKPreferencesRef preferencesRef, bool enabled); WK_EXPORT bool WKPreferencesGetMediaStreamEnabled(WKPreferencesRef preferencesRef); -// Defaults to true. -WK_EXPORT void WKPreferencesSetVideoPluginProxyEnabled(WKPreferencesRef preferencesRef, bool enabled); -WK_EXPORT bool WKPreferencesGetVideoPluginProxyEnabled(WKPreferencesRef preferencesRef); - // Defaults to false. WK_EXPORT void WKPreferencesSetSpatialNavigationEnabled(WKPreferencesRef preferencesRef, bool enabled); WK_EXPORT bool WKPreferencesGetSpatialNavigationEnabled(WKPreferencesRef preferencesRef); +// Defaults to 0. +WK_EXPORT void WKPreferencesSetVisibleDebugOverlayRegions(WKPreferencesRef preferencesRef, WKDebugOverlayRegions enabled); +WK_EXPORT WKDebugOverlayRegions WKPreferencesGetVisibleDebugOverlayRegions(WKPreferencesRef preferencesRef); + +// Defaults to false. +WK_EXPORT void WKPreferencesSetIgnoreViewportScalingConstraints(WKPreferencesRef preferencesRef, bool enabled); +WK_EXPORT bool WKPreferencesGetIgnoreViewportScalingConstraints(WKPreferencesRef preferencesRef); + +// Defaults to true. +WK_EXPORT void WKPreferencesSetAllowsAirPlayForMediaPlayback(WKPreferencesRef preferencesRef, bool enabled); +WK_EXPORT bool WKPreferencesGetAllowsAirPlayForMediaPlayback(WKPreferencesRef preferencesRef); + #ifdef __cplusplus } #endif diff --git a/Source/WebKit2/UIProcess/API/C/WKPreferencesPrivate.h b/Source/WebKit2/UIProcess/API/C/WKPreferencesRefPrivate.h index 0d80f0499..1b079209a 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPreferencesPrivate.h +++ b/Source/WebKit2/UIProcess/API/C/WKPreferencesRefPrivate.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2010, 2014 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,7 +26,7 @@ #ifndef WKPreferencesPrivate_h #define WKPreferencesPrivate_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { @@ -49,6 +49,11 @@ enum WKEditableLinkBehavior { }; typedef enum WKEditableLinkBehavior WKEditableLinkBehavior; +enum WKJavaScriptRuntimeFlags { + kWKJavaScriptRuntimeFlagsAllEnabled = 0 +}; +typedef unsigned WKJavaScriptRuntimeFlagSet; + // Creates a copy with no identifier. WK_EXPORT WKPreferencesRef WKPreferencesCreateCopy(WKPreferencesRef); @@ -93,10 +98,6 @@ WK_EXPORT void WKPreferencesSetWebGLEnabled(WKPreferencesRef, bool); WK_EXPORT bool WKPreferencesGetWebGLEnabled(WKPreferencesRef); // Defaults to false. -WK_EXPORT void WKPreferencesSetMultithreadedWebGLEnabled(WKPreferencesRef, bool); -WK_EXPORT bool WKPreferencesGetMultithreadedWebGLEnabled(WKPreferencesRef); - -// Defaults to false. WK_EXPORT void WKPreferencesSetForceSoftwareWebGLRendering(WKPreferencesRef, bool); WK_EXPORT bool WKPreferencesGetForceSoftwareWebGLRendering(WKPreferencesRef); @@ -105,16 +106,16 @@ WK_EXPORT void WKPreferencesSetAccelerated2DCanvasEnabled(WKPreferencesRef, bool WK_EXPORT bool WKPreferencesGetAccelerated2DCanvasEnabled(WKPreferencesRef); // Defaults to true -WK_EXPORT void WKPreferencesSetCSSRegionsEnabled(WKPreferencesRef, bool flag); -WK_EXPORT bool WKPreferencesGetCSSRegionsEnabled(WKPreferencesRef); +WK_EXPORT void WKPreferencesSetCSSAnimationTriggersEnabled(WKPreferencesRef, bool flag); +WK_EXPORT bool WKPreferencesGetCSSAnimationTriggersEnabled(WKPreferencesRef); // Defaults to false -WK_EXPORT void WKPreferencesSetCSSGridLayoutEnabled(WKPreferencesRef, bool flag); -WK_EXPORT bool WKPreferencesGetCSSGridLayoutEnabled(WKPreferencesRef); +WK_EXPORT void WKPreferencesSetWebAnimationsEnabled(WKPreferencesRef, bool flag); +WK_EXPORT bool WKPreferencesGetWebAnimationsEnabled(WKPreferencesRef); -// Defaults to false -WK_EXPORT void WKPreferencesSetRegionBasedColumnsEnabled(WKPreferencesRef, bool flag); -WK_EXPORT bool WKPreferencesGetRegionBasedColumnsEnabled(WKPreferencesRef); +// Defaults to true +WK_EXPORT void WKPreferencesSetCSSRegionsEnabled(WKPreferencesRef, bool flag); +WK_EXPORT bool WKPreferencesGetCSSRegionsEnabled(WKPreferencesRef); // Defaults to false. WK_EXPORT void WKPreferencesSetNeedsSiteSpecificQuirks(WKPreferencesRef, bool); @@ -128,6 +129,10 @@ WK_EXPORT bool WKPreferencesGetForceFTPDirectoryListings(WKPreferencesRef prefer WK_EXPORT void WKPreferencesSetFTPDirectoryTemplatePath(WKPreferencesRef preferences, WKStringRef path); WK_EXPORT WKStringRef WKPreferencesCopyFTPDirectoryTemplatePath(WKPreferencesRef preferences); +// Defaults to true. +WK_EXPORT void WKPreferencesSetDOMTimersThrottlingEnabled(WKPreferencesRef preferences, bool enabled); +WK_EXPORT bool WKPreferencesGetDOMTimersThrottlingEnabled(WKPreferencesRef preferences); + // Defaults to false. WK_EXPORT void WKPreferencesSetWebArchiveDebugModeEnabled(WKPreferencesRef preferences, bool enabled); WK_EXPORT bool WKPreferencesGetWebArchiveDebugModeEnabled(WKPreferencesRef preferences); @@ -172,19 +177,31 @@ WK_EXPORT bool WKPreferencesGetHixie76WebSocketProtocolEnabled(WKPreferencesRef WK_EXPORT void WKPreferencesSetMediaPlaybackRequiresUserGesture(WKPreferencesRef preferencesRef, bool flag); WK_EXPORT bool WKPreferencesGetMediaPlaybackRequiresUserGesture(WKPreferencesRef preferencesRef); +// Defaults to false. +WK_EXPORT void WKPreferencesSetAudioPlaybackRequiresUserGesture(WKPreferencesRef preferencesRef, bool flag); +WK_EXPORT bool WKPreferencesGetAudioPlaybackRequiresUserGesture(WKPreferencesRef preferencesRef); + // Defaults to true. WK_EXPORT void WKPreferencesSetMediaPlaybackAllowsInline(WKPreferencesRef preferencesRef, bool flag); WK_EXPORT bool WKPreferencesGetMediaPlaybackAllowsInline(WKPreferencesRef preferencesRef); // Defaults to false. +WK_EXPORT void WKPreferencesSetInlineMediaPlaybackRequiresPlaysInlineAttribute(WKPreferencesRef preferencesRef, bool flag); +WK_EXPORT bool WKPreferencesGetInlineMediaPlaybackRequiresPlaysInlineAttribute(WKPreferencesRef preferencesRef); + +// Defaults to false on iOS, true elsewhere. +WK_EXPORT void WKPreferencesSetMediaControlsScaleWithPageZoom(WKPreferencesRef preferencesRef, bool flag); +WK_EXPORT bool WKPreferencesGetMediaControlsScaleWithPageZoom(WKPreferencesRef preferencesRef); + +// Defaults to false. WK_EXPORT void WKPreferencesSetShowsToolTipOverTruncatedText(WKPreferencesRef preferencesRef, bool flag); WK_EXPORT bool WKPreferencesGetShowsToolTipOverTruncatedText(WKPreferencesRef preferencesRef); // Defaults to false. WK_EXPORT void WKPreferencesSetMockScrollbarsEnabled(WKPreferencesRef preferencesRef, bool flag); WK_EXPORT bool WKPreferencesGetMockScrollbarsEnabled(WKPreferencesRef preferencesRef); - -// Defaults to false. + +// Deprecated. Always returns false. WK_EXPORT void WKPreferencesSetApplicationChromeModeEnabled(WKPreferencesRef preferencesRef, bool enabled); WK_EXPORT bool WKPreferencesGetApplicationChromeModeEnabled(WKPreferencesRef preferencesRef); @@ -229,10 +246,6 @@ WK_EXPORT void WKPreferencesSetScrollingPerformanceLoggingEnabled(WKPreferencesR WK_EXPORT bool WKPreferencesGetScrollingPerformanceLoggingEnabled(WKPreferencesRef preferencesRef); // Defaults to true -WK_EXPORT void WKPreferencesSetScreenFontSubstitutionEnabled(WKPreferencesRef preferences, bool enabled); -WK_EXPORT bool WKPreferencesGetScreenFontSubstitutionEnabled(WKPreferencesRef preferences); - -// Defaults to true WK_EXPORT void WKPreferencesSetCookieEnabled(WKPreferencesRef preferences, bool enabled); WK_EXPORT bool WKPreferencesGetCookieEnabled(WKPreferencesRef preferences); @@ -248,7 +261,7 @@ WK_EXPORT bool WKPreferencesGetAggressiveTileRetentionEnabled(WKPreferencesRef p WK_EXPORT void WKPreferencesSetLogsPageMessagesToSystemConsoleEnabled(WKPreferencesRef preferences, bool enabled); WK_EXPORT bool WKPreferencesGetLogsPageMessagesToSystemConsoleEnabled(WKPreferencesRef preferences); -// Defaults to false +// Defaults to true WK_EXPORT void WKPreferencesSetPageVisibilityBasedProcessSuppressionEnabled(WKPreferencesRef preferences, bool enabled); WK_EXPORT bool WKPreferencesGetPageVisibilityBasedProcessSuppressionEnabled(WKPreferencesRef); @@ -300,13 +313,25 @@ WK_EXPORT bool WKPreferencesGetSimpleLineLayoutEnabled(WKPreferencesRef); WK_EXPORT void WKPreferencesSetSimpleLineLayoutDebugBordersEnabled(WKPreferencesRef, bool); WK_EXPORT bool WKPreferencesGetSimpleLineLayoutDebugBordersEnabled(WKPreferencesRef); +// Defaults to false. +WK_EXPORT void WKPreferencesSetNewBlockInsideInlineModelEnabled(WKPreferencesRef, bool); +WK_EXPORT bool WKPreferencesGetNewBlockInsideInlineModelEnabled(WKPreferencesRef); + +// Defaults to false. +WK_EXPORT void WKPreferencesSetSubpixelCSSOMElementMetricsEnabled(WKPreferencesRef, bool); +WK_EXPORT bool WKPreferencesGetSubpixelCSSOMElementMetricsEnabled(WKPreferencesRef); + +// Defaults to false. +WK_EXPORT void WKPreferencesSetUseGiantTiles(WKPreferencesRef, bool); +WK_EXPORT bool WKPreferencesGetUseGiantTiles(WKPreferencesRef); + WK_EXPORT void WKPreferencesResetTestRunnerOverrides(WKPreferencesRef preferencesRef); // Defaults to false. WK_EXPORT void WKPreferencesSetUseLegacyTextAlignPositionedElementBehavior(WKPreferencesRef preferencesRef, bool enabled); WK_EXPORT bool WKPreferencesUseLegacyTextAlignPositionedElementBehavior(WKPreferencesRef preferencesRef); -// Defaults to false. +// Defaults to true. WK_EXPORT void WKPreferencesSetMediaSourceEnabled(WKPreferencesRef preferencesRef, bool enabled); WK_EXPORT bool WKPreferencesGetMediaSourceEnabled(WKPreferencesRef preferencesRef); @@ -314,6 +339,66 @@ WK_EXPORT bool WKPreferencesGetMediaSourceEnabled(WKPreferencesRef preferencesRe WK_EXPORT void WKPreferencesSetViewGestureDebuggingEnabled(WKPreferencesRef preferencesRef, bool enabled); WK_EXPORT bool WKPreferencesGetViewGestureDebuggingEnabled(WKPreferencesRef preferencesRef); +// Default to false. +WK_EXPORT void WKPreferencesSetShouldConvertPositionStyleOnCopy(WKPreferencesRef preferencesRef, bool convert); +WK_EXPORT bool WKPreferencesGetShouldConvertPositionStyleOnCopy(WKPreferencesRef preferencesRef); + +// Default to false. +WK_EXPORT void WKPreferencesSetTelephoneNumberParsingEnabled(WKPreferencesRef preferencesRef, bool enabled); +WK_EXPORT bool WKPreferencesGetTelephoneNumberParsingEnabled(WKPreferencesRef preferencesRef); + +// Default to false. +WK_EXPORT void WKPreferencesSetEnableInheritURIQueryComponent(WKPreferencesRef preferencesRef, bool enabled); +WK_EXPORT bool WKPreferencesGetEnableInheritURIQueryComponent(WKPreferencesRef preferencesRef); + +// Default to false. +WK_EXPORT void WKPreferencesSetServiceControlsEnabled(WKPreferencesRef preferencesRef, bool enabled); +WK_EXPORT bool WKPreferencesGetServiceControlsEnabled(WKPreferencesRef preferencesRef); + +// Default to false. +WK_EXPORT void WKPreferencesSetImageControlsEnabled(WKPreferencesRef preferencesRef, bool enabled); +WK_EXPORT bool WKPreferencesGetImageControlsEnabled(WKPreferencesRef preferencesRef); + +// Default to false. +WK_EXPORT void WKPreferencesSetGamepadsEnabled(WKPreferencesRef preferencesRef, bool enabled); +WK_EXPORT bool WKPreferencesGetGamepadsEnabled(WKPreferencesRef preferencesRef); + +// Not implemented, should be deleted once there are no callers. +WK_EXPORT void WKPreferencesSetLongMousePressEnabled(WKPreferencesRef preferencesRef, bool enabled); +WK_EXPORT bool WKPreferencesGetLongMousePressEnabled(WKPreferencesRef preferencesRef); + +// Defaults to 0. Setting this to 0 disables font autosizing on iOS. +WK_EXPORT void WKPreferencesSetMinimumZoomFontSize(WKPreferencesRef preferencesRef, double); +WK_EXPORT double WKPreferencesGetMinimumZoomFontSize(WKPreferencesRef preferencesRef); + +// Not implemented, should be deleted once Safari no longer uses this function. +WK_EXPORT void WKPreferencesSetScreenFontSubstitutionEnabled(WKPreferencesRef preferences, bool enabled); +WK_EXPORT bool WKPreferencesGetScreenFontSubstitutionEnabled(WKPreferencesRef preferences); + +// Defaults to false. +WK_EXPORT void WKPreferencesSetAntialiasedFontDilationEnabled(WKPreferencesRef preferences, bool enabled); +WK_EXPORT bool WKPreferencesGetAntialiasedFontDilationEnabled(WKPreferencesRef preferences); + +// Defaults to 0. +WK_EXPORT void WKPreferencesSetJavaScriptRuntimeFlags(WKPreferencesRef preferences, WKJavaScriptRuntimeFlagSet javascriptRuntimeFlagSet); +WK_EXPORT WKJavaScriptRuntimeFlagSet WKPreferencesGetJavaScriptRuntimeFlags(WKPreferencesRef preferences); + +// Defaults to true. +WK_EXPORT void WKPreferencesSetMetaRefreshEnabled(WKPreferencesRef preferences, bool enabled); +WK_EXPORT bool WKPreferencesGetMetaRefreshEnabled(WKPreferencesRef preferences); + +// Defaults to true. +WK_EXPORT void WKPreferencesSetHTTPEquivEnabled(WKPreferencesRef preferences, bool enabled); +WK_EXPORT bool WKPreferencesGetHTTPEquivEnabled(WKPreferencesRef preferences); + +// Defaults to false. +WK_EXPORT void WKPreferencesSetResourceUsageOverlayVisible(WKPreferencesRef, bool); +WK_EXPORT bool WKPreferencesGetResourceUsageOverlayVisible(WKPreferencesRef); + +// Defaults to false. +WK_EXPORT void WKPreferencesSetMockCaptureDevicesEnabled(WKPreferencesRef, bool); +WK_EXPORT bool WKPreferencesGetMockCaptureDevicesEnabled(WKPreferencesRef); + #ifdef __cplusplus } #endif diff --git a/Source/WebKit2/UIProcess/API/C/WKProtectionSpace.h b/Source/WebKit2/UIProcess/API/C/WKProtectionSpace.h index c77d93ba0..ff7ca8742 100644 --- a/Source/WebKit2/UIProcess/API/C/WKProtectionSpace.h +++ b/Source/WebKit2/UIProcess/API/C/WKProtectionSpace.h @@ -26,8 +26,8 @@ #ifndef WKProtectionSpace_h #define WKProtectionSpace_h -#include <WebKit2/WKBase.h> -#include <WebKit2/WKProtectionSpaceTypes.h> +#include <WebKit/WKBase.h> +#include <WebKit/WKProtectionSpaceTypes.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/WKProtectionSpaceTypes.h b/Source/WebKit2/UIProcess/API/C/WKProtectionSpaceTypes.h index fd1bd09d2..474146049 100644 --- a/Source/WebKit2/UIProcess/API/C/WKProtectionSpaceTypes.h +++ b/Source/WebKit2/UIProcess/API/C/WKProtectionSpaceTypes.h @@ -26,7 +26,7 @@ #ifndef WKProtectionSpaceTypes_h #define WKProtectionSpaceTypes_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/WKResourceCacheManager.cpp b/Source/WebKit2/UIProcess/API/C/WKResourceCacheManager.cpp index a5711e014..0e3c7a2d6 100644 --- a/Source/WebKit2/UIProcess/API/C/WKResourceCacheManager.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKResourceCacheManager.cpp @@ -26,27 +26,68 @@ #include "config.h" #include "WKResourceCacheManager.h" -#include "WebResourceCacheManagerProxy.h" +#include "APIWebsiteDataStore.h" #include "WKAPICast.h" +#include "WebsiteDataRecord.h" using namespace WebKit; WKTypeID WKResourceCacheManagerGetTypeID() { - return toAPI(WebResourceCacheManagerProxy::APIType); + return toAPI(API::WebsiteDataStore::APIType); } -void WKResourceCacheManagerGetCacheOrigins(WKResourceCacheManagerRef cacheManagerRef, void* context, WKResourceCacheManagerGetCacheOriginsFunction callback) +static WebsiteDataTypes toWebsiteDataTypes(WKResourceCachesToClear cachesToClear) { - toImpl(cacheManagerRef)->getCacheOrigins(ArrayCallback::create(context, callback)); + using WebsiteDataTypes = WebKit::WebsiteDataTypes; + + int websiteDataTypes = WebsiteDataTypeMemoryCache; + + if (cachesToClear == WKResourceCachesToClearAll) + websiteDataTypes |= WebsiteDataTypeDiskCache; + + return static_cast<WebsiteDataTypes>(websiteDataTypes); +} + +void WKResourceCacheManagerGetCacheOrigins(WKResourceCacheManagerRef cacheManager, void* context, WKResourceCacheManagerGetCacheOriginsFunction callback) +{ + auto& websiteDataStore = toImpl(reinterpret_cast<WKWebsiteDataStoreRef>(cacheManager))->websiteDataStore(); + websiteDataStore.fetchData(toWebsiteDataTypes(WKResourceCachesToClearAll), [context, callback](Vector<WebsiteDataRecord> dataRecords) { + Vector<RefPtr<API::Object>> securityOrigins; + for (const auto& dataRecord : dataRecords) { + for (const auto& origin : dataRecord.origins) + securityOrigins.append(API::SecurityOrigin::create(*origin)); + } + + callback(toAPI(API::Array::create(WTFMove(securityOrigins)).ptr()), nullptr, context); + }); } -void WKResourceCacheManagerClearCacheForOrigin(WKResourceCacheManagerRef cacheManagerRef, WKSecurityOriginRef originRef, WKResourceCachesToClear cachesToClear) +void WKResourceCacheManagerClearCacheForOrigin(WKResourceCacheManagerRef cacheManager, WKSecurityOriginRef origin, WKResourceCachesToClear cachesToClear) { - toImpl(cacheManagerRef)->clearCacheForOrigin(toImpl(originRef), toResourceCachesToClear(cachesToClear)); + auto& websiteDataStore = toImpl(reinterpret_cast<WKWebsiteDataStoreRef>(cacheManager))->websiteDataStore(); + + Vector<WebsiteDataRecord> dataRecords; + + { + WebsiteDataRecord dataRecord; + dataRecord.add(WebsiteDataTypes::WebsiteDataTypeMemoryCache, &toImpl(origin)->securityOrigin()); + + dataRecords.append(dataRecord); + } + + if (cachesToClear == WKResourceCachesToClearAll) { + WebsiteDataRecord dataRecord; + dataRecord.add(WebsiteDataTypes::WebsiteDataTypeDiskCache, &toImpl(origin)->securityOrigin()); + + dataRecords.append(dataRecord); + } + + websiteDataStore.removeData(toWebsiteDataTypes(cachesToClear), dataRecords, [] { }); } -void WKResourceCacheManagerClearCacheForAllOrigins(WKResourceCacheManagerRef cacheManagerRef, WKResourceCachesToClear cachesToClear) +void WKResourceCacheManagerClearCacheForAllOrigins(WKResourceCacheManagerRef cacheManager, WKResourceCachesToClear cachesToClear) { - toImpl(cacheManagerRef)->clearCacheForAllOrigins(toResourceCachesToClear(cachesToClear)); + auto& websiteDataStore = toImpl(reinterpret_cast<WKWebsiteDataStoreRef>(cacheManager))->websiteDataStore(); + websiteDataStore.removeData(toWebsiteDataTypes(cachesToClear), std::chrono::system_clock::time_point::min(), [] { }); } diff --git a/Source/WebKit2/UIProcess/API/C/WKResourceCacheManager.h b/Source/WebKit2/UIProcess/API/C/WKResourceCacheManager.h index 80c4531ff..7f4bb6c51 100644 --- a/Source/WebKit2/UIProcess/API/C/WKResourceCacheManager.h +++ b/Source/WebKit2/UIProcess/API/C/WKResourceCacheManager.h @@ -26,7 +26,7 @@ #ifndef WKResourceCacheManager_h #define WKResourceCacheManager_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/WKSessionRef.cpp b/Source/WebKit2/UIProcess/API/C/WKSessionRef.cpp index 4af2f7bb5..a93579087 100644 --- a/Source/WebKit2/UIProcess/API/C/WKSessionRef.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKSessionRef.cpp @@ -33,7 +33,11 @@ using namespace WebKit; WKSessionRef WKSessionCreate(bool isEphemeral) { - RefPtr<API::Session> session = API::Session::create(isEphemeral); + // The implementation doesn't support non-ephemeral + if (!isEphemeral) + return nullptr; + + RefPtr<API::Session> session = API::Session::createEphemeral(); return toAPI(session.release().leakRef()); } diff --git a/Source/WebKit2/UIProcess/API/C/WKSessionRef.h b/Source/WebKit2/UIProcess/API/C/WKSessionRef.h index 63fa54277..693902677 100644 --- a/Source/WebKit2/UIProcess/API/C/WKSessionRef.h +++ b/Source/WebKit2/UIProcess/API/C/WKSessionRef.h @@ -26,7 +26,7 @@ #ifndef WKSessionRef_h #define WKSessionRef_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/WKColorPickerResultListener.cpp b/Source/WebKit2/UIProcess/API/C/WKSessionStateRef.cpp index 07bfe3c9e..98e717519 100644 --- a/Source/WebKit2/UIProcess/API/C/WKColorPickerResultListener.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKSessionStateRef.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Samsung Electronics. All rights reserved. + * Copyright (C) 2014 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -10,7 +10,7 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS AS IS'' + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS @@ -24,28 +24,29 @@ */ #include "config.h" -#include "WKColorPickerResultListener.h" +#include "WKSessionStateRef.h" +#include "APIData.h" +#include "APISessionState.h" +#include "LegacySessionStateCoding.h" +#include "SessionState.h" #include "WKAPICast.h" -#include "WebColorPickerResultListenerProxy.h" -using namespace WebKit; +WKTypeID WKSessionStateGetTypeID() +{ + return WebKit::toAPI(API::SessionState::APIType); +} -WKTypeID WKColorPickerResultListenerGetTypeID() +WKSessionStateRef WKSessionStateCreateFromData(WKDataRef data) { -#if ENABLE(INPUT_TYPE_COLOR) - return toAPI(WebColorPickerResultListenerProxy::APIType); -#else - return 0; -#endif + WebKit::SessionState sessionState; + if (!WebKit::decodeLegacySessionState(WebKit::toImpl(data)->bytes(), WebKit::toImpl(data)->size(), sessionState)) + return nullptr; + + return WebKit::toAPI(&API::SessionState::create(WTFMove(sessionState)).leakRef()); } -void WKColorPickerResultListenerSetColor(WKColorPickerResultListenerRef listenerRef, const WKStringRef color) +WKDataRef WKSessionStateCopyData(WKSessionStateRef sessionState) { -#if ENABLE(INPUT_TYPE_COLOR) - toImpl(listenerRef)->setColor(toWTFString(color)); -#else - UNUSED_PARAM(listenerRef); - UNUSED_PARAM(color); -#endif + return WebKit::toAPI(WebKit::encodeLegacySessionState(WebKit::toImpl(sessionState)->sessionState()).release().leakRef()); } diff --git a/Source/WebKit2/UIProcess/API/C/WKColorPickerResultListener.h b/Source/WebKit2/UIProcess/API/C/WKSessionStateRef.h index bfd4732c9..e46b66414 100644 --- a/Source/WebKit2/UIProcess/API/C/WKColorPickerResultListener.h +++ b/Source/WebKit2/UIProcess/API/C/WKSessionStateRef.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Samsung Electronics. All rights reserved. + * Copyright (C) 2014 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -10,7 +10,7 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS AS IS'' + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS @@ -23,21 +23,23 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef WKColorPickerResultListener_h -#define WKColorPickerResultListener_h +#ifndef WKSessionStateRef_h +#define WKSessionStateRef_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { #endif -WK_EXPORT WKTypeID WKColorPickerResultListenerGetTypeID(); +WK_EXPORT WKTypeID WKSessionStateGetTypeID(); -WK_EXPORT void WKColorPickerResultListenerSetColor(WKColorPickerResultListenerRef listenerRef, const WKStringRef color); +WK_EXPORT WKSessionStateRef WKSessionStateCreateFromData(WKDataRef data); + +WK_EXPORT WKDataRef WKSessionStateCopyData(WKSessionStateRef sessionState); #ifdef __cplusplus } #endif -#endif /* WKColorPickerResultListener_h */ +#endif // WKSessionStateRef_h diff --git a/Source/WebKit2/UIProcess/API/C/WKTextChecker.cpp b/Source/WebKit2/UIProcess/API/C/WKTextChecker.cpp index 2da94dfc2..3279dd7a9 100644 --- a/Source/WebKit2/UIProcess/API/C/WKTextChecker.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKTextChecker.cpp @@ -36,25 +36,25 @@ void WKTextCheckerSetClient(const WKTextCheckerClientBase* wkClient) { if (wkClient && wkClient->version) return; - WebTextChecker::shared()->setClient(wkClient); + WebTextChecker::singleton()->setClient(wkClient); } void WKTextCheckerContinuousSpellCheckingEnabledStateChanged(bool enabled) { - WebTextChecker::shared()->continuousSpellCheckingEnabledStateChanged(enabled); + WebTextChecker::singleton()->continuousSpellCheckingEnabledStateChanged(enabled); } void WKTextCheckerGrammarCheckingEnabledStateChanged(bool enabled) { - WebTextChecker::shared()->grammarCheckingEnabledStateChanged(enabled); + WebTextChecker::singleton()->grammarCheckingEnabledStateChanged(enabled); } void WKTextCheckerCheckSpelling(WKPageRef page, bool startBeforeSelection) { - WebTextChecker::shared()->checkSpelling(toImpl(page), startBeforeSelection); + WebTextChecker::singleton()->checkSpelling(toImpl(page), startBeforeSelection); } void WKTextCheckerChangeSpellingToWord(WKPageRef page, WKStringRef word) { - WebTextChecker::shared()->changeSpellingToWord(toImpl(page), toWTFString(word)); + WebTextChecker::singleton()->changeSpellingToWord(toImpl(page), toWTFString(word)); } diff --git a/Source/WebKit2/UIProcess/API/C/WKTextChecker.h b/Source/WebKit2/UIProcess/API/C/WKTextChecker.h index af72c75b7..a32469461 100644 --- a/Source/WebKit2/UIProcess/API/C/WKTextChecker.h +++ b/Source/WebKit2/UIProcess/API/C/WKTextChecker.h @@ -26,7 +26,7 @@ #ifndef WKTextChecker_h #define WKTextChecker_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/WKUserContentControllerRef.cpp b/Source/WebKit2/UIProcess/API/C/WKUserContentControllerRef.cpp new file mode 100644 index 000000000..bb73853ba --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKUserContentControllerRef.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKUserContentControllerRef.h" + +#include "APIUserContentExtension.h" +#include "APIUserScript.h" +#include "WKAPICast.h" +#include "WebUserContentControllerProxy.h" + +using namespace WebKit; + +WKTypeID WKUserContentControllerGetTypeID() +{ + return toAPI(WebUserContentControllerProxy::APIType); +} + +WKUserContentControllerRef WKUserContentControllerCreate() +{ + return toAPI(&WebUserContentControllerProxy::create().leakRef()); +} + +WKArrayRef WKUserContentControllerCopyUserScripts(WKUserContentControllerRef userContentControllerRef) +{ + Ref<API::Array> userScripts = toImpl(userContentControllerRef)->userScripts().copy(); + return toAPI(&userScripts.leakRef()); +} + +void WKUserContentControllerAddUserScript(WKUserContentControllerRef userContentControllerRef, WKUserScriptRef userScriptRef) +{ + toImpl(userContentControllerRef)->addUserScript(*toImpl(userScriptRef)); +} + +void WKUserContentControllerRemoveAllUserScripts(WKUserContentControllerRef userContentControllerRef) +{ + toImpl(userContentControllerRef)->removeAllUserScripts(); +} + +void WKUserContentControllerAddUserContentFilter(WKUserContentControllerRef userContentControllerRef, WKUserContentFilterRef userContentFilterRef) +{ +#if ENABLE(CONTENT_EXTENSIONS) + toImpl(userContentControllerRef)->addUserContentExtension(*toImpl(userContentFilterRef)); +#endif +} + +void WKUserContentControllerRemoveAllUserContentFilters(WKUserContentControllerRef userContentControllerRef) +{ +#if ENABLE(CONTENT_EXTENSIONS) + toImpl(userContentControllerRef)->removeAllUserContentExtensions(); +#endif +} diff --git a/Source/WebKit2/UIProcess/API/C/WKUserContentControllerRef.h b/Source/WebKit2/UIProcess/API/C/WKUserContentControllerRef.h new file mode 100644 index 000000000..d462e99b1 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKUserContentControllerRef.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKUserContentControllerRef_h +#define WKUserContentControllerRef_h + +#include <WebKit/WKBase.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKTypeID WKUserContentControllerGetTypeID(); + +WK_EXPORT WKUserContentControllerRef WKUserContentControllerCreate(); + +WK_EXPORT WKArrayRef WKUserContentControllerCopyUserScripts(WKUserContentControllerRef userContentController); +WK_EXPORT void WKUserContentControllerAddUserScript(WKUserContentControllerRef userContentController, WKUserScriptRef userScript); +WK_EXPORT void WKUserContentControllerRemoveAllUserScripts(WKUserContentControllerRef userContentController); + +WK_EXPORT void WKUserContentControllerAddUserContentFilter(WKUserContentControllerRef userContentController, WKUserContentFilterRef userContentFilter); +WK_EXPORT void WKUserContentControllerRemoveAllUserContentFilters(WKUserContentControllerRef userContentController); + +#ifdef __cplusplus +} +#endif + +#endif /* WKUserContentControllerRef_h */ diff --git a/Source/WebKit2/UIProcess/API/C/WKUserContentExtensionStoreRef.cpp b/Source/WebKit2/UIProcess/API/C/WKUserContentExtensionStoreRef.cpp new file mode 100644 index 000000000..6fe872e62 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKUserContentExtensionStoreRef.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKUserContentExtensionStoreRef.h" + +#include "APIUserContentExtensionStore.h" +#include "WKAPICast.h" + +using namespace WebKit; + +WKTypeID WKUserContentExtensionStoreGetTypeID() +{ +#if ENABLE(CONTENT_EXTENSIONS) + return toAPI(API::UserContentExtensionStore::APIType); +#else + return 0; +#endif +} diff --git a/Source/WebKit2/UIProcess/API/C/WKUserContentExtensionStoreRef.h b/Source/WebKit2/UIProcess/API/C/WKUserContentExtensionStoreRef.h new file mode 100644 index 000000000..53598ec80 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKUserContentExtensionStoreRef.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKUserContentExtensionStoreRef_h +#define WKUserContentExtensionStoreRef_h + +#include <WebKit/WKBase.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKTypeID WKUserContentExtensionStoreGetTypeID(); + +#ifdef __cplusplus +} +#endif + +#endif /* WKUserContentExtensionStoreRef_h */ diff --git a/Source/WebKit2/UIProcess/API/C/WKUserMediaPermissionCheck.cpp b/Source/WebKit2/UIProcess/API/C/WKUserMediaPermissionCheck.cpp new file mode 100644 index 000000000..371c813c3 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKUserMediaPermissionCheck.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "config.h" +#include "WKUserMediaPermissionCheck.h" + +#include "UserMediaPermissionCheckProxy.h" +#include "WKAPICast.h" +#include "WKArray.h" +#include "WKMutableArray.h" +#include "WKString.h" + +using namespace WebKit; + +WKTypeID WKUserMediaPermissionCheckGetTypeID() +{ + return toAPI(UserMediaPermissionCheckProxy::APIType); +} + +void WKUserMediaPermissionCheckSetHasPersistentPermission(WKUserMediaPermissionCheckRef userMediaPermissionRequestRef, bool allowed) +{ + toImpl(userMediaPermissionRequestRef)->setHasPersistentPermission(allowed); +} + diff --git a/Source/WebKit2/UIProcess/API/C/WKUserMediaPermissionCheck.h b/Source/WebKit2/UIProcess/API/C/WKUserMediaPermissionCheck.h new file mode 100644 index 000000000..e0cb0a339 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKUserMediaPermissionCheck.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef WKUserMediaPermissionCheck_h +#define WKUserMediaPermissionCheck_h + +#include <WebKit/WKBase.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKTypeID WKUserMediaPermissionCheckGetTypeID(); + +WK_EXPORT void WKUserMediaPermissionCheckSetHasPersistentPermission(WKUserMediaPermissionCheckRef, bool); + +#ifdef __cplusplus +} +#endif + +#endif /* WKMediaDevicesRequest_h */ diff --git a/Source/WebKit2/UIProcess/API/C/WKUserMediaPermissionRequest.cpp b/Source/WebKit2/UIProcess/API/C/WKUserMediaPermissionRequest.cpp new file mode 100644 index 000000000..c86f86771 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKUserMediaPermissionRequest.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2014 Igalia S.L + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "WKUserMediaPermissionRequest.h" + +#include "UserMediaPermissionRequestProxy.h" +#include "WKAPICast.h" +#include "WKArray.h" +#include "WKMutableArray.h" +#include "WKString.h" + +using namespace WebKit; + +WKTypeID WKUserMediaPermissionRequestGetTypeID() +{ + return toAPI(UserMediaPermissionRequestProxy::APIType); +} + + +void WKUserMediaPermissionRequestAllow(WKUserMediaPermissionRequestRef userMediaPermissionRequestRef, WKStringRef audioDeviceUID, WKStringRef videoDeviceUID) +{ + toImpl(userMediaPermissionRequestRef)->allow(toWTFString(audioDeviceUID), toWTFString(videoDeviceUID)); +} + +void WKUserMediaPermissionRequestDeny(WKUserMediaPermissionRequestRef userMediaPermissionRequestRef) +{ + toImpl(userMediaPermissionRequestRef)->deny(); +} + +WKArrayRef WKUserMediaPermissionRequestVideoDeviceUIDs(WKUserMediaPermissionRequestRef userMediaPermissionRef) +{ + WKMutableArrayRef array = WKMutableArrayCreate(); +#if ENABLE(MEDIA_STREAM) + for (auto& deviceUID : toImpl(userMediaPermissionRef)->videoDeviceUIDs()) + WKArrayAppendItem(array, toAPI(API::String::create(deviceUID).ptr())); +#endif + return array; +} + +WKArrayRef WKUserMediaPermissionRequestAudioDeviceUIDs(WKUserMediaPermissionRequestRef userMediaPermissionRef) +{ + WKMutableArrayRef array = WKMutableArrayCreate(); +#if ENABLE(MEDIA_STREAM) + for (auto& deviceUID : toImpl(userMediaPermissionRef)->audioDeviceUIDs()) + WKArrayAppendItem(array, toAPI(API::String::create(deviceUID).ptr())); +#endif + return array; +} diff --git a/Source/WebKit2/UIProcess/API/C/WKUserMediaPermissionRequest.h b/Source/WebKit2/UIProcess/API/C/WKUserMediaPermissionRequest.h new file mode 100644 index 000000000..764489a25 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKUserMediaPermissionRequest.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2014 Igalia S.L + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef WKUserMediaPermissionRequest_h +#define WKUserMediaPermissionRequest_h + +#include <WebKit/WKBase.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKTypeID WKUserMediaPermissionRequestGetTypeID(); + +WK_EXPORT void WKUserMediaPermissionRequestAllow(WKUserMediaPermissionRequestRef, WKStringRef audioDeviceUID, WKStringRef videoDeviceUID); +WK_EXPORT void WKUserMediaPermissionRequestDeny(WKUserMediaPermissionRequestRef); + +WK_EXPORT WKArrayRef WKUserMediaPermissionRequestVideoDeviceUIDs(WKUserMediaPermissionRequestRef); +WK_EXPORT WKArrayRef WKUserMediaPermissionRequestAudioDeviceUIDs(WKUserMediaPermissionRequestRef); + +#ifdef __cplusplus +} +#endif + +#endif /* WKUserMediaPermissionRequest_h */ diff --git a/Source/WebKit2/UIProcess/API/C/WKMediaCacheManager.cpp b/Source/WebKit2/UIProcess/API/C/WKUserScriptRef.cpp index 6e2ecce06..ad71b017c 100644 --- a/Source/WebKit2/UIProcess/API/C/WKMediaCacheManager.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKUserScriptRef.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 Apple Inc. All rights reserved. + * Copyright (C) 2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -24,29 +24,34 @@ */ #include "config.h" -#include "WKMediaCacheManager.h" +#include "WKUserScriptRef.h" +#include "APIUserScript.h" #include "WKAPICast.h" -#include "WebMediaCacheManagerProxy.h" using namespace WebKit; -WKTypeID WKMediaCacheManagerGetTypeID() +WKTypeID WKUserScriptGetTypeID() { - return toAPI(WebMediaCacheManagerProxy::APIType); + return toAPI(API::UserScript::APIType); } -void WKMediaCacheManagerGetHostnamesWithMediaCache(WKMediaCacheManagerRef mediaCacheManagerRef, void* context, WKMediaCacheManagerGetHostnamesWithMediaCacheFunction callback) +WKUserScriptRef WKUserScriptCreateWithSource(WKStringRef sourceRef, _WKUserScriptInjectionTime injectionTime, bool forMainFrameOnly) { - toImpl(mediaCacheManagerRef)->getHostnamesWithMediaCache(ArrayCallback::create(context, callback)); + return toAPI(&API::UserScript::create(WebCore::UserScript { toWTFString(sourceRef), API::UserScript::generateUniqueURL(), { }, { }, toUserScriptInjectionTime(injectionTime), forMainFrameOnly ? WebCore::InjectInTopFrameOnly : WebCore::InjectInAllFrames }).leakRef()); } -void WKMediaCacheManagerClearCacheForHostname(WKMediaCacheManagerRef mediaCacheManagerRef, WKStringRef hostname) +WKStringRef WKUserScriptCopySource(WKUserScriptRef userScriptRef) { - toImpl(mediaCacheManagerRef)->clearCacheForHostname(toWTFString(hostname)); + return toCopiedAPI(toImpl(userScriptRef)->userScript().source()); } -void WKMediaCacheManagerClearCacheForAllHostnames(WKMediaCacheManagerRef mediaCacheManagerRef) +_WKUserScriptInjectionTime WKUserScriptGetInjectionTime(WKUserScriptRef userScriptRef) { - toImpl(mediaCacheManagerRef)->clearCacheForAllHostnames(); + return toWKUserScriptInjectionTime(toImpl(userScriptRef)->userScript().injectionTime()); +} + +bool WKUserScriptGetMainFrameOnly(WKUserScriptRef userScriptRef) +{ + return toImpl(userScriptRef)->userScript().injectedFrames() == WebCore::InjectInTopFrameOnly; } diff --git a/Source/WebKit2/UIProcess/API/C/WKUserScriptRef.h b/Source/WebKit2/UIProcess/API/C/WKUserScriptRef.h new file mode 100644 index 000000000..610f9fb58 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKUserScriptRef.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKUserScriptRef_h +#define WKUserScriptRef_h + +#include <WebKit/WKBase.h> +#include <WebKit/WKUserScriptInjectionTime.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKTypeID WKUserScriptGetTypeID(); + +WK_EXPORT WKUserScriptRef WKUserScriptCreateWithSource(WKStringRef source, _WKUserScriptInjectionTime injectionTime, bool forMainFrameOnly); + +WK_EXPORT WKStringRef WKUserScriptCopySource(WKUserScriptRef userScript); +WK_EXPORT _WKUserScriptInjectionTime WKUserScriptGetInjectionTime(WKUserScriptRef userScript); +WK_EXPORT bool WKUserScriptGetMainFrameOnly(WKUserScriptRef userScript); + +#ifdef __cplusplus +} +#endif + +#endif /* WKUserScriptRef_h */ diff --git a/Source/WebKit2/UIProcess/API/C/WKVibration.h b/Source/WebKit2/UIProcess/API/C/WKVibration.h index c18000bf1..965749c86 100644 --- a/Source/WebKit2/UIProcess/API/C/WKVibration.h +++ b/Source/WebKit2/UIProcess/API/C/WKVibration.h @@ -26,7 +26,7 @@ #ifndef WKVibration_h #define WKVibration_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/WKViewportAttributes.cpp b/Source/WebKit2/UIProcess/API/C/WKViewportAttributes.cpp new file mode 100644 index 000000000..e30af5666 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKViewportAttributes.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2013 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the followlayoutSizeing disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list Viewof conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKViewportAttributes.h" + +#include "WKAPICast.h" +#include "WebViewportAttributes.h" + +using namespace WebKit; + +WKTypeID WKViewportAttributesGetTypeID() +{ + return toAPI(WebViewportAttributes::APIType); +} diff --git a/Source/WebKit2/UIProcess/API/C/WKViewportAttributes.h b/Source/WebKit2/UIProcess/API/C/WKViewportAttributes.h new file mode 100644 index 000000000..8ab84edac --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKViewportAttributes.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2013 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list Viewof conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKViewportAttributes_h +#define WKViewportAttributes_h + +#include <WebKit/WKBase.h> +#include <WebKit/WKGeometry.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKTypeID WKViewportAttributesGetTypeID(); + +#ifdef __cplusplus +} +#endif + +#endif /* WKViewportAttributes_h */ diff --git a/Source/WebKit2/UIProcess/Network/soup/NetworkProcessProxySoup.cpp b/Source/WebKit2/UIProcess/API/C/WKWebsiteDataStoreRef.cpp index 1bdf0ed7c..e9e907b63 100644 --- a/Source/WebKit2/UIProcess/Network/soup/NetworkProcessProxySoup.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKWebsiteDataStoreRef.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Apple Inc. All rights reserved. + * Copyright (C) 2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -24,24 +24,22 @@ */ #include "config.h" -#if ENABLE(NETWORK_PROCESS) +#include "WKWebsiteDataStoreRef.h" -#include "NetworkProcessProxy.h" -#include <glib.h> +#include "APIWebsiteDataStore.h" +#include "WKAPICast.h" -namespace WebKit { - -void NetworkProcessProxy::platformGetLaunchOptions(ProcessLauncher::LaunchOptions& launchOptions) +WKTypeID WKWebsiteDataStoreGetTypeID() { -#ifndef NDEBUG - const char* networkProcessCmdPrefix = g_getenv("NETWORK_PROCESS_CMD_PREFIX"); - if (networkProcessCmdPrefix && *networkProcessCmdPrefix) - launchOptions.processCmdPrefix = String::fromUTF8(networkProcessCmdPrefix); -#else - UNUSED_PARAM(launchOptions); -#endif + return WebKit::toAPI(API::WebsiteDataStore::APIType); } +WKWebsiteDataStoreRef WKWebsiteDataStoreGetDefaultDataStore() +{ + return WebKit::toAPI(API::WebsiteDataStore::defaultDataStore().get()); } -#endif // ENABLE(NETWORK_PROCESS) +WKWebsiteDataStoreRef WKWebsiteDataStoreCreateNonPersistentDataStore() +{ + return WebKit::toAPI(&API::WebsiteDataStore::createNonPersistentDataStore().leakRef()); +} diff --git a/Source/WebKit2/UIProcess/API/C/WKWebsiteDataStoreRef.h b/Source/WebKit2/UIProcess/API/C/WKWebsiteDataStoreRef.h new file mode 100644 index 000000000..36990e3d4 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKWebsiteDataStoreRef.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKWebsiteDataStoreRef_h +#define WKWebsiteDataStoreRef_h + +#include <WebKit/WKBase.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKTypeID WKWebsiteDataStoreGetTypeID(); + +WK_EXPORT WKWebsiteDataStoreRef WKWebsiteDataStoreGetDefaultDataStore(); +WK_EXPORT WKWebsiteDataStoreRef WKWebsiteDataStoreCreateNonPersistentDataStore(); + +#ifdef __cplusplus +} +#endif + +#endif /* WKWebsiteDataStoreRef_h */ diff --git a/Source/WebKit2/UIProcess/API/C/WKWindowFeaturesRef.cpp b/Source/WebKit2/UIProcess/API/C/WKWindowFeaturesRef.cpp new file mode 100644 index 000000000..e9338a662 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKWindowFeaturesRef.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKWindowFeaturesRef.h" + +#include "APIWindowFeatures.h" +#include "WKAPICast.h" + +WKTypeID WKWindowFeaturesGetTypeID() +{ + return WebKit::toAPI(API::WindowFeatures::APIType); +} diff --git a/Source/WebKit2/UIProcess/API/C/WKWindowFeaturesRef.h b/Source/WebKit2/UIProcess/API/C/WKWindowFeaturesRef.h new file mode 100644 index 000000000..5dc940477 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKWindowFeaturesRef.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKWindowFeaturesRef_h +#define WKWindowFeaturesRef_h + +#include <WebKit/WKBase.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKTypeID WKWindowFeaturesGetTypeID(); + +#ifdef __cplusplus +} +#endif + +#endif // WKWindowFeaturesRef_h diff --git a/Source/WebKit2/UIProcess/API/C/WebKit2_C.h b/Source/WebKit2/UIProcess/API/C/WebKit2_C.h index 21c9eeaab..2e7aa3b68 100644 --- a/Source/WebKit2/UIProcess/API/C/WebKit2_C.h +++ b/Source/WebKit2/UIProcess/API/C/WebKit2_C.h @@ -26,42 +26,46 @@ #ifndef WebKit2_C_h #define WebKit2_C_h -#include <WebKit2/WKBase.h> -#include <WebKit2/WKType.h> +#include <WebKit/WKBase.h> +#include <WebKit/WKType.h> -#include <WebKit2/WKArray.h> -#include <WebKit2/WKBackForwardListRef.h> -#include <WebKit2/WKBackForwardListItemRef.h> -#include <WebKit2/WKConnectionRef.h> -#include <WebKit2/WKContext.h> -#include <WebKit2/WKData.h> -#include <WebKit2/WKDictionary.h> -#include <WebKit2/WKError.h> -#include <WebKit2/WKFormSubmissionListener.h> -#include <WebKit2/WKFrame.h> -#include <WebKit2/WKFramePolicyListener.h> -#include <WebKit2/WKGeolocationManager.h> -#include <WebKit2/WKGeolocationPermissionRequest.h> -#include <WebKit2/WKGeolocationPosition.h> -#include <WebKit2/WKHitTestResult.h> -#include <WebKit2/WKMutableArray.h> -#include <WebKit2/WKMutableDictionary.h> -#include <WebKit2/WKNavigationDataRef.h> -#include <WebKit2/WKNumber.h> -#include <WebKit2/WKOpenPanelParameters.h> -#include <WebKit2/WKOpenPanelResultListener.h> -#include <WebKit2/WKPage.h> -#include <WebKit2/WKPageGroup.h> -#include <WebKit2/WKPreferencesRef.h> -#include <WebKit2/WKString.h> -#include <WebKit2/WKURL.h> -#include <WebKit2/WKURLRequest.h> -#include <WebKit2/WKURLResponse.h> +#include <WebKit/WKArray.h> +#include <WebKit/WKBackForwardListRef.h> +#include <WebKit/WKBackForwardListItemRef.h> +#include <WebKit/WKConnectionRef.h> +#include <WebKit/WKContext.h> +#include <WebKit/WKData.h> +#include <WebKit/WKDictionary.h> +#include <WebKit/WKErrorRef.h> +#include <WebKit/WKFormSubmissionListener.h> +#include <WebKit/WKFrame.h> +#include <WebKit/WKFramePolicyListener.h> +#include <WebKit/WKGeolocationManager.h> +#include <WebKit/WKGeolocationPermissionRequest.h> +#include <WebKit/WKGeolocationPosition.h> +#include <WebKit/WKHitTestResult.h> +#include <WebKit/WKMutableArray.h> +#include <WebKit/WKMutableDictionary.h> +#include <WebKit/WKNavigationDataRef.h> +#include <WebKit/WKNumber.h> +#include <WebKit/WKOpenPanelParameters.h> +#include <WebKit/WKOpenPanelResultListener.h> +#include <WebKit/WKPage.h> +#include <WebKit/WKPageConfigurationRef.h> +#include <WebKit/WKPageGroup.h> +#include <WebKit/WKPreferencesRef.h> +#include <WebKit/WKString.h> +#include <WebKit/WKURL.h> +#include <WebKit/WKURLRequest.h> +#include <WebKit/WKURLResponse.h> +#include <WebKit/WKUserContentControllerRef.h> +#include <WebKit/WKUserMediaPermissionRequest.h> +#include <WebKit/WKUserScriptRef.h> #if defined(__OBJC__) && __OBJC__ -#import <WebKit2/WKView.h> +#import <WebKit/WKView.h> #elif !(defined(__APPLE__) && __APPLE__) -#include <WebKit2/WKView.h> +#include <WebKit/WKView.h> #endif #endif /* WebKit2_C_h */ diff --git a/Source/WebKit2/UIProcess/API/C/cairo/WKIconDatabaseCairo.cpp b/Source/WebKit2/UIProcess/API/C/cairo/WKIconDatabaseCairo.cpp new file mode 100644 index 000000000..118c4d8cb --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/cairo/WKIconDatabaseCairo.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2013 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKIconDatabaseCairo.h" + +#include "WKAPICast.h" +#include "WebIconDatabase.h" + +using namespace WebCore; +using namespace WebKit; + +cairo_surface_t* WKIconDatabaseTryGetCairoSurfaceForURL(WKIconDatabaseRef iconDatabase, WKURLRef url) +{ + return toImpl(iconDatabase)->nativeImageForPageURL(toWTFString(url)).get(); +} diff --git a/Source/WebKit2/UIProcess/API/C/cairo/WKIconDatabaseCairo.h b/Source/WebKit2/UIProcess/API/C/cairo/WKIconDatabaseCairo.h new file mode 100644 index 000000000..5830177df --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/cairo/WKIconDatabaseCairo.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2013 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <WebKit/WKBase.h> + +typedef struct _cairo_surface cairo_surface_t; + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT cairo_surface_t* WKIconDatabaseTryGetCairoSurfaceForURL(WKIconDatabaseRef iconDatabase, WKURLRef url); + +#ifdef __cplusplus +} +#endif diff --git a/Source/WebKit2/UIProcess/API/C/gtk/WKAPICastGtk.h b/Source/WebKit2/UIProcess/API/C/gtk/WKAPICastGtk.h index 9eb0c78ad..a06292b2e 100644 --- a/Source/WebKit2/UIProcess/API/C/gtk/WKAPICastGtk.h +++ b/Source/WebKit2/UIProcess/API/C/gtk/WKAPICastGtk.h @@ -37,6 +37,18 @@ namespace WebKit { WK_ADD_API_MAPPING(WKViewRef, WebKitWebViewBase) +template<> +inline WKViewRef toAPI<>(WebKitWebViewBase* view) +{ + return reinterpret_cast<WKViewRef>(static_cast<void*>(view)); +} + +template<> +inline WebKitWebViewBase* toImpl<>(WKViewRef view) +{ + return static_cast<WebKitWebViewBase*>(static_cast<void*>(const_cast<typename std::remove_const<typename std::remove_pointer<WKViewRef>::type>::type*>(view))); +} + } #endif // WKAPICastGtk_h diff --git a/Source/WebKit2/UIProcess/API/C/gtk/WKFullScreenClientGtk.h b/Source/WebKit2/UIProcess/API/C/gtk/WKFullScreenClientGtk.h index a292dda11..cece1057b 100644 --- a/Source/WebKit2/UIProcess/API/C/gtk/WKFullScreenClientGtk.h +++ b/Source/WebKit2/UIProcess/API/C/gtk/WKFullScreenClientGtk.h @@ -26,7 +26,7 @@ #ifndef WKFullScreenClientGtk_h #define WKFullScreenClientGtk_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/gtk/WKInspectorClientGtk.h b/Source/WebKit2/UIProcess/API/C/gtk/WKInspectorClientGtk.h index 28242da09..2e60bc793 100644 --- a/Source/WebKit2/UIProcess/API/C/gtk/WKInspectorClientGtk.h +++ b/Source/WebKit2/UIProcess/API/C/gtk/WKInspectorClientGtk.h @@ -26,7 +26,7 @@ #ifndef WKInspectorClientGtk_h #define WKInspectorClientGtk_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { @@ -37,6 +37,7 @@ typedef void (*WKInspectorClientGtkInspectorDidCloseCallback)(WKInspectorRef ins typedef void (*WKInspectorClientGtkInspectedURLChangedCallback)(WKInspectorRef inspector, WKStringRef url, const void* clientInfo); typedef void (*WKInspectorClientGtkDidChangeAttachedHeightCallback)(WKInspectorRef inspector, unsigned height, const void* clientInfo); typedef void (*WKInspectorClientGtkDidChangeAttachedWidthCallback)(WKInspectorRef inspector, unsigned width, const void* clientInfo); +typedef void (*WKInspectorClientGtkDidChangeAttachAvailabilityCallback)(WKInspectorRef inspector, bool available, const void* clientInfo); typedef struct WKInspectorClientGtkBase { int version; @@ -54,6 +55,7 @@ typedef struct WKInspectorClientGtkV0 { WKInspectorClientGtkInspectorCallback detach; WKInspectorClientGtkDidChangeAttachedHeightCallback didChangeAttachedHeight; WKInspectorClientGtkDidChangeAttachedWidthCallback didChangeAttachedWidth; + WKInspectorClientGtkDidChangeAttachAvailabilityCallback didChangeAttachAvailability; } WKInspectorClientGtkV0; WK_EXPORT void WKInspectorSetInspectorClientGtk(WKInspectorRef inspectorRef, const WKInspectorClientGtkBase* client); diff --git a/Source/WebKit2/UIProcess/API/C/gtk/WKTextCheckerGtk.cpp b/Source/WebKit2/UIProcess/API/C/gtk/WKTextCheckerGtk.cpp new file mode 100644 index 000000000..2924ba6db --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/gtk/WKTextCheckerGtk.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2015 Igalia S.L. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKTextCheckerGtk.h" + +#include "TextChecker.h" + +void WKTextCheckerSetSpellCheckingLanguages(const char* const* languages) +{ +#if ENABLE(SPELLCHECK) + Vector<String> spellCheckingLanguages; + for (size_t i = 0; languages[i]; ++i) + spellCheckingLanguages.append(String::fromUTF8(languages[i])); + WebKit::TextChecker::setSpellCheckingLanguages(spellCheckingLanguages); +#endif +} diff --git a/Source/WebKit2/UIProcess/API/C/gtk/WKTextCheckerGtk.h b/Source/WebKit2/UIProcess/API/C/gtk/WKTextCheckerGtk.h new file mode 100644 index 000000000..1f6e55a66 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/gtk/WKTextCheckerGtk.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2015 Igalia S.L. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKTextCheckerGtk_h +#define WKTextCheckerGtk_h + +#include <WebKit/WKBase.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT void WKTextCheckerSetSpellCheckingLanguages(const char* const* languages); + +#ifdef __cplusplus +} +#endif + +#endif /* WKTextCheckerGtk_h */ diff --git a/Source/WebKit2/UIProcess/API/C/gtk/WKView.cpp b/Source/WebKit2/UIProcess/API/C/gtk/WKView.cpp index 6f0c04bf2..48c41ac77 100644 --- a/Source/WebKit2/UIProcess/API/C/gtk/WKView.cpp +++ b/Source/WebKit2/UIProcess/API/C/gtk/WKView.cpp @@ -33,11 +33,10 @@ #include "WebKitWebViewBasePrivate.h" using namespace WebKit; -using namespace WebCore; -WKViewRef WKViewCreate(WKContextRef contextRef, WKPageGroupRef pageGroupRef) +WKViewRef WKViewCreate(WKPageConfigurationRef configuration) { - return toAPI(webkitWebViewBaseCreate(toImpl(contextRef), toImpl(pageGroupRef), nullptr)); + return toAPI(webkitWebViewBaseCreate(*toImpl(configuration))); } WKPageRef WKViewGetPage(WKViewRef viewRef) diff --git a/Source/WebKit2/UIProcess/API/C/gtk/WKView.h b/Source/WebKit2/UIProcess/API/C/gtk/WKView.h index 291dfe1b6..989ab66a2 100644 --- a/Source/WebKit2/UIProcess/API/C/gtk/WKView.h +++ b/Source/WebKit2/UIProcess/API/C/gtk/WKView.h @@ -28,13 +28,13 @@ #ifndef WKView_h #define WKView_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { #endif -WK_EXPORT WKViewRef WKViewCreate(WKContextRef context, WKPageGroupRef pageGroup); +WK_EXPORT WKViewRef WKViewCreate(WKPageConfigurationRef configuration); WK_EXPORT WKPageRef WKViewGetPage(WKViewRef view); diff --git a/Source/WebKit2/UIProcess/API/C/gtk/WKViewPrivate.h b/Source/WebKit2/UIProcess/API/C/gtk/WKViewPrivate.h index 2c1b2d1f0..acabfd3af 100644 --- a/Source/WebKit2/UIProcess/API/C/gtk/WKViewPrivate.h +++ b/Source/WebKit2/UIProcess/API/C/gtk/WKViewPrivate.h @@ -26,7 +26,7 @@ #ifndef WKViewPrivate_h #define WKViewPrivate_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/soup/WKAPICastSoup.h b/Source/WebKit2/UIProcess/API/C/soup/WKAPICastSoup.h index 0333335ba..d77267dbd 100644 --- a/Source/WebKit2/UIProcess/API/C/soup/WKAPICastSoup.h +++ b/Source/WebKit2/UIProcess/API/C/soup/WKAPICastSoup.h @@ -35,11 +35,7 @@ namespace WebKit { class WebSoupCustomProtocolRequestManager; class WebSoupRequestManagerProxy; -#if ENABLE(CUSTOM_PROTOCOLS) WK_ADD_API_MAPPING(WKSoupCustomProtocolRequestManagerRef, WebSoupCustomProtocolRequestManager) -#else -WK_ADD_API_MAPPING(WKSoupRequestManagerRef, WebSoupRequestManagerProxy) -#endif } diff --git a/Source/WebKit2/UIProcess/API/C/soup/WKContextSoup.h b/Source/WebKit2/UIProcess/API/C/soup/WKContextSoup.h new file mode 100644 index 000000000..cd42f3979 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/soup/WKContextSoup.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2012 Igalia S.L. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKContextSoup_h +#define WKContextSoup_h + +#include <WebKit/WKBase.h> +#include <WebKit/WKSoupRequestManager.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKSoupRequestManagerRef WKContextGetSoupRequestManager(WKContextRef context); + +#ifdef __cplusplus +} +#endif + +#endif /* WKContextSoup_h */ diff --git a/Source/WebKit2/UIProcess/API/C/WKNetworkInfo.cpp b/Source/WebKit2/UIProcess/API/C/soup/WKCookieManagerSoup.cpp index 73fd05e53..86b31aa47 100644 --- a/Source/WebKit2/UIProcess/API/C/WKNetworkInfo.cpp +++ b/Source/WebKit2/UIProcess/API/C/soup/WKCookieManagerSoup.cpp @@ -24,32 +24,28 @@ */ #include "config.h" -#include "WKNetworkInfo.h" +#include "WKCookieManagerSoup.h" -#if ENABLE(NETWORK_INFO) +#include "SoupCookiePersistentStorageType.h" #include "WKAPICast.h" -#include "WebNetworkInfo.h" +#include "WebCookieManagerProxy.h" using namespace WebKit; -#endif -WKTypeID WKNetworkInfoGetTypeID() +inline SoupCookiePersistentStorageType toSoupCookiePersistentStorageType(WKCookieStorageType wkCookieStorageType) { -#if ENABLE(NETWORK_INFO) - return toAPI(WebNetworkInfo::APIType); -#else - return 0; -#endif + switch (wkCookieStorageType) { + case kWKCookieStorageTypeText: + return SoupCookiePersistentStorageText; + case kWKCookieStorageTypeSQLite: + return SoupCookiePersistentStorageSQLite; + } + + ASSERT_NOT_REACHED(); + return SoupCookiePersistentStorageText; } -WKNetworkInfoRef WKNetworkInfoCreate(double bandwidth, bool isMetered) +void WKCookieManagerSetCookiePersistentStorage(WKCookieManagerRef cookieManager, WKStringRef storagePath, WKCookieStorageType storageType) { -#if ENABLE(NETWORK_INFO) - RefPtr<WebNetworkInfo> networkInfo = WebNetworkInfo::create(bandwidth, isMetered); - return toAPI(networkInfo.release().leakRef()); -#else - UNUSED_PARAM(bandwidth); - UNUSED_PARAM(isMetered); - return 0; -#endif + toImpl(cookieManager)->setCookiePersistentStorage(toWTFString(storagePath), storageType); } diff --git a/Source/WebKit2/UIProcess/API/C/soup/WKCookieManagerSoup.h b/Source/WebKit2/UIProcess/API/C/soup/WKCookieManagerSoup.h new file mode 100644 index 000000000..90cafca21 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/soup/WKCookieManagerSoup.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2012 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKCookieManagerSoup_h +#define WKCookieManagerSoup_h + +#include <WebKit/WKBase.h> + +#ifdef __cplusplus +extern "C" { +#endif + +enum { + kWKCookieStorageTypeText = 0, + kWKCookieStorageTypeSQLite = 1 +}; +typedef uint32_t WKCookieStorageType; + +WK_EXPORT void WKCookieManagerSetCookiePersistentStorage(WKCookieManagerRef cookieManager, WKStringRef storagePath, WKCookieStorageType storageType); + +#ifdef __cplusplus +} +#endif + +#endif // WKCookieManagerSoup_h diff --git a/Source/WebKit2/UIProcess/API/C/soup/WKSoupCustomProtocolRequestManager.cpp b/Source/WebKit2/UIProcess/API/C/soup/WKSoupCustomProtocolRequestManager.cpp index 95b1f8124..d5d36f6a7 100644 --- a/Source/WebKit2/UIProcess/API/C/soup/WKSoupCustomProtocolRequestManager.cpp +++ b/Source/WebKit2/UIProcess/API/C/soup/WKSoupCustomProtocolRequestManager.cpp @@ -33,19 +33,10 @@ using namespace WebKit; WKTypeID WKSoupCustomProtocolRequestManagerGetTypeID() { -#if ENABLE(CUSTOM_PROTOCOLS) return toAPI(WebSoupCustomProtocolRequestManager::APIType); -#else - return 0; -#endif } void WKSoupCustomProtocolRequestManagerSetClient(WKSoupCustomProtocolRequestManagerRef soupRequestManagerRef, const WKSoupCustomProtocolRequestManagerClientBase* wkClient) { -#if ENABLE(CUSTOM_PROTOCOLS) toImpl(soupRequestManagerRef)->initializeClient(wkClient); -#else - UNUSED_PARAM(soupRequestManagerRef); - UNUSED_PARAM(wkClient); -#endif } diff --git a/Source/WebKit2/UIProcess/API/C/soup/WKSoupCustomProtocolRequestManager.h b/Source/WebKit2/UIProcess/API/C/soup/WKSoupCustomProtocolRequestManager.h index cb0edc72f..822a762f7 100644 --- a/Source/WebKit2/UIProcess/API/C/soup/WKSoupCustomProtocolRequestManager.h +++ b/Source/WebKit2/UIProcess/API/C/soup/WKSoupCustomProtocolRequestManager.h @@ -26,7 +26,7 @@ #ifndef WKSoupCustomProtocolRequestManager_h #define WKSoupCustomProtocolRequestManager_h -#include <WebKit2/WKBase.h> +#include <WebKit/WKBase.h> #ifdef __cplusplus extern "C" { diff --git a/Source/WebKit2/UIProcess/API/C/soup/WKSoupRequestManager.h b/Source/WebKit2/UIProcess/API/C/soup/WKSoupRequestManager.h new file mode 100644 index 000000000..f667ede06 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/soup/WKSoupRequestManager.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2012 Igalia S.L. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKSoupRequestManager_h +#define WKSoupRequestManager_h + +#include <WebKit/WKBase.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*WKSoupRequestManagerDidReceiveURIRequestCallback)(WKSoupRequestManagerRef soupRequestManagerRef, WKURLRef urlRef, WKPageRef pageRef, uint64_t requestID, const void* clientInfo); +typedef void (*WKSoupRequestManagerDidFailToLoadURIRequestCallback)(WKSoupRequestManagerRef soupRequestManagerRef, uint64_t requestID, const void* clientInfo); + +typedef struct WKSoupRequestManagerClientBase { + int version; + const void* clientInfo; +} WKSoupRequestManagerClientBase; + +typedef struct WKSoupRequestManagerClientV0 { + WKSoupRequestManagerClientBase base; + + WKSoupRequestManagerDidReceiveURIRequestCallback didReceiveURIRequest; + WKSoupRequestManagerDidFailToLoadURIRequestCallback didFailToLoadURIRequest; +} WKSoupRequestManagerClientV0; + +WK_EXPORT WKTypeID WKSoupRequestManagerGetTypeID(); + +WK_EXPORT void WKSoupRequestManagerSetClient(WKSoupRequestManagerRef, const WKSoupRequestManagerClientBase* client); +WK_EXPORT void WKSoupRequestManagerRegisterURIScheme(WKSoupRequestManagerRef, WKStringRef schemeRef); +WK_EXPORT void WKSoupRequestManagerDidHandleURIRequest(WKSoupRequestManagerRef, WKDataRef, uint64_t contentLength, WKStringRef mimeTypeRef, uint64_t requestID); +WK_EXPORT void WKSoupRequestManagerDidReceiveURIRequestData(WKSoupRequestManagerRef, WKDataRef, uint64_t requestID); + +#ifdef __cplusplus +} +#endif + +#endif /* WKSoupRequestManager_h */ diff --git a/Source/WebKit2/UIProcess/API/CoordinatedGraphics/WKCoordinatedScene.cpp b/Source/WebKit2/UIProcess/API/CoordinatedGraphics/WKCoordinatedScene.cpp new file mode 100644 index 000000000..a855116f3 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/CoordinatedGraphics/WKCoordinatedScene.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies) + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if USE(COORDINATED_GRAPHICS) +#include "WKCoordinatedScene.h" + +#include "CoordinatedGraphicsScene.h" +#include "WKCoordinatedSceneAPICast.h" +#include <WebCore/TextureMapperLayer.h> + +using namespace WebKit; + +WK_EXPORT WKCoordinatedSceneLayer WKCoordinatedSceneFindScrollableContentsLayerAt(WKCoordinatedScene scene, WKPoint point) +{ + return toAPI(toImpl(scene)->findScrollableContentsLayerAt(WebCore::FloatPoint(point.x, point.y))); +} + +WK_EXPORT uint32_t WKCoordinatedSceneGetLayerID(WKCoordinatedSceneLayer layer) +{ + return toImpl(layer)->id(); +} + +WK_EXPORT void WKCoordinatedSceneScrollBy(WKCoordinatedSceneLayer layer, WKSize offset) +{ + toImpl(layer)->scrollBy(WebCore::FloatSize(offset.width, offset.height)); +} +#endif diff --git a/Source/WebKit2/UIProcess/API/CoordinatedGraphics/WKCoordinatedScene.h b/Source/WebKit2/UIProcess/API/CoordinatedGraphics/WKCoordinatedScene.h new file mode 100644 index 000000000..061212865 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/CoordinatedGraphics/WKCoordinatedScene.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies) + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKCoordinatedScene_h +#define WKCoordinatedScene_h + +#include <WebKit/WKGeometry.h> + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +typedef struct OpaqueCGScene* WKCoordinatedScene; +typedef struct OpaqueCGLayer* WKCoordinatedSceneLayer; + +WK_EXPORT WKCoordinatedSceneLayer WKCoordinatedSceneFindScrollableContentsLayerAt(WKCoordinatedScene, WKPoint); +WK_EXPORT uint32_t WKCoordinatedSceneGetLayerID(WKCoordinatedSceneLayer); +WK_EXPORT void WKCoordinatedSceneScrollBy(WKCoordinatedSceneLayer, WKSize); + +#ifdef __cplusplus +} +#endif // __cplusplus + +#endif // WKCoordinatedScene_h diff --git a/Source/WebKit2/UIProcess/API/cpp/WKRetainPtr.h b/Source/WebKit2/UIProcess/API/cpp/WKRetainPtr.h index 6915dd334..24a45afd4 100644 --- a/Source/WebKit2/UIProcess/API/cpp/WKRetainPtr.h +++ b/Source/WebKit2/UIProcess/API/cpp/WKRetainPtr.h @@ -26,8 +26,12 @@ #ifndef WKRetainPtr_h #define WKRetainPtr_h -#include <WebKit2/WKType.h> +#include <WebKit/WKType.h> #include <algorithm> +#include <wtf/GetPtr.h> +#include <wtf/HashFunctions.h> +#include <wtf/HashTraits.h> +#include <wtf/RefPtr.h> namespace WebKit { @@ -84,6 +88,15 @@ public: WKRelease(ptr); } + // Hash table deleted values, which are only constructed and never copied or destroyed. + WKRetainPtr(WTF::HashTableDeletedValueType) + : m_ptr(hashTableDeletedValue()) + { + } + + bool isHashTableDeletedValue() const { return m_ptr == hashTableDeletedValue(); } + constexpr static T hashTableDeletedValue() { return reinterpret_cast<T>(-1); } + PtrType get() const { return m_ptr; } void clear() @@ -229,17 +242,8 @@ template<typename T, typename U> inline bool operator!=(T* a, const WKRetainPtr< return a != b.get(); } -#if defined(__GNUC__) && !(defined(__CC_ARM) || defined(__ARMCC__)) -#define WK_WARN_UNUSED_RETURN __attribute__((warn_unused_result)) -#else -#define WK_WARN_UNUSED_RETURN -#endif - -template<typename T> inline WKRetainPtr<T> adoptWK(T) WK_WARN_UNUSED_RETURN; - -#undef WK_WARN_UNUSED_RETURN - -template<typename T> inline WKRetainPtr<T> adoptWK(T o) +template<typename T> inline WKRetainPtr<T> adoptWK(T) __attribute__((warn_unused_result)); +template<typename T> inline WKRetainPtr<T> adoptWK(T o) { return WKRetainPtr<T>(AdoptWK, o); } @@ -250,4 +254,24 @@ using WebKit::WKRetainPtr; using WebKit::AdoptWK; using WebKit::adoptWK; +namespace WTF { + +template <typename T> struct IsSmartPtr<WKRetainPtr<T>> { + static const bool value = true; +}; + +template<typename P> struct DefaultHash<WKRetainPtr<P>> { + typedef PtrHash<WKRetainPtr<P>> Hash; +}; + +template<typename P> struct HashTraits<WKRetainPtr<P>> : SimpleClassHashTraits<WKRetainPtr<P>> { + static P emptyValue() { return nullptr; } + + typedef P PeekType; + static PeekType peek(const WKRetainPtr<P>& value) { return value.get(); } + static PeekType peek(P value) { return value; } +}; + +} // namespace WTF + #endif // WKRetainPtr_h diff --git a/Source/WebKit2/UIProcess/API/gtk/APIWebsiteDataStoreGtk.cpp b/Source/WebKit2/UIProcess/API/gtk/APIWebsiteDataStoreGtk.cpp new file mode 100644 index 000000000..c6b0787c1 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/APIWebsiteDataStoreGtk.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2015 Igalia S.L. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "APIWebsiteDataStore.h" + +#include <WebCore/FileSystem.h> + +namespace API { + +String WebsiteDataStore::defaultApplicationCacheDirectory() +{ + return cacheDirectoryFileSystemRepresentation("webkitgtk" G_DIR_SEPARATOR_S "applications"); +} + +String WebsiteDataStore::defaultNetworkCacheDirectory() +{ +#if ENABLE(NETWORK_CACHE) + static const char networkCacheSubdirectory[] = "WebKitCache"; +#else + static const char networkCacheSubdirectory[] = "webkit"; +#endif + return cacheDirectoryFileSystemRepresentation(WebCore::pathByAppendingComponent(WebCore::filenameToString(g_get_prgname()), networkCacheSubdirectory)); +} + +String WebsiteDataStore::defaultIndexedDBDatabaseDirectory() +{ + return websiteDataDirectoryFileSystemRepresentation("webkitgtk" G_DIR_SEPARATOR_S "databases" G_DIR_SEPARATOR_S "indexeddb"); +} + +String WebsiteDataStore::defaultLocalStorageDirectory() +{ + return websiteDataDirectoryFileSystemRepresentation("webkitgtk" G_DIR_SEPARATOR_S "localstorage"); +} + +String WebsiteDataStore::defaultMediaKeysStorageDirectory() +{ + return websiteDataDirectoryFileSystemRepresentation("webkitgtk" G_DIR_SEPARATOR_S "mediakeys"); +} + +String WebsiteDataStore::defaultWebSQLDatabaseDirectory() +{ + return websiteDataDirectoryFileSystemRepresentation("webkitgtk" G_DIR_SEPARATOR_S "databases"); +} + +String WebsiteDataStore::cacheDirectoryFileSystemRepresentation(const String& directoryName) +{ + return WebCore::pathByAppendingComponent(WebCore::filenameToString(g_get_user_cache_dir()), directoryName); +} + +String WebsiteDataStore::websiteDataDirectoryFileSystemRepresentation(const String& directoryName) +{ + return WebCore::pathByAppendingComponent(WebCore::filenameToString(g_get_user_data_dir()), directoryName); +} + +WebKit::WebsiteDataStore::Configuration WebsiteDataStore::defaultDataStoreConfiguration() +{ + WebKit::WebsiteDataStore::Configuration configuration; + + configuration.applicationCacheDirectory = defaultApplicationCacheDirectory(); + configuration.networkCacheDirectory = defaultNetworkCacheDirectory(); + + configuration.webSQLDatabaseDirectory = defaultWebSQLDatabaseDirectory(); + configuration.localStorageDirectory = defaultLocalStorageDirectory(); + configuration.mediaKeysStorageDirectory = defaultMediaKeysStorageDirectory(); + + return configuration; +} + +} // namespace API diff --git a/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.cpp b/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.cpp index 872a274c9..0a8675d35 100644 --- a/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.cpp @@ -32,12 +32,15 @@ #include "NativeWebKeyboardEvent.h" #include "NativeWebMouseEvent.h" #include "NotImplemented.h" -#include "WebContext.h" +#include "WebColorPickerGtk.h" #include "WebContextMenuProxyGtk.h" #include "WebEventFactory.h" +#include "WebKitColorChooser.h" #include "WebKitWebViewBasePrivate.h" +#include "WebKitWebViewPrivate.h" #include "WebPageProxy.h" #include "WebPopupMenuProxyGtk.h" +#include "WebProcessPool.h" #include <WebCore/Cursor.h> #include <WebCore/EventNames.h> #include <WebCore/GtkUtilities.h> @@ -53,23 +56,10 @@ PageClientImpl::PageClientImpl(GtkWidget* viewWidget) { } -PageClientImpl::~PageClientImpl() -{ -} - -void PageClientImpl::getEditorCommandsForKeyEvent(const NativeWebKeyboardEvent& event, const AtomicString& eventType, Vector<WTF::String>& commandList) -{ - ASSERT(eventType == eventNames().keydownEvent || eventType == eventNames().keypressEvent); - - KeyBindingTranslator::EventType type = eventType == eventNames().keydownEvent ? - KeyBindingTranslator::KeyDown : KeyBindingTranslator::KeyPress; - m_keyBindingTranslator.getEditorCommandsForKeyEvent(const_cast<GdkEventKey*>(&event.nativeEvent()->key), type, commandList); -} - // PageClient's pure virtual functions std::unique_ptr<DrawingAreaProxy> PageClientImpl::createDrawingAreaProxy() { - return std::make_unique<DrawingAreaProxyImpl>(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(m_viewWidget))); + return std::make_unique<DrawingAreaProxyImpl>(*webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(m_viewWidget))); } void PageClientImpl::setViewNeedsDisplay(const WebCore::IntRect& rect) @@ -82,18 +72,20 @@ void PageClientImpl::displayView() notImplemented(); } -void PageClientImpl::scrollView(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset) +void PageClientImpl::scrollView(const WebCore::IntRect& scrollRect, const WebCore::IntSize& /* scrollOffset */) { setViewNeedsDisplay(scrollRect); } +void PageClientImpl::requestScroll(const WebCore::FloatPoint&, const WebCore::IntPoint&, bool) +{ + notImplemented(); +} + WebCore::IntSize PageClientImpl::viewSize() { - if (!gtk_widget_get_realized(m_viewWidget)) - return IntSize(); - GtkAllocation allocation; - gtk_widget_get_allocation(m_viewWidget, &allocation); - return IntSize(allocation.width, allocation.height); + auto* drawingArea = static_cast<DrawingAreaProxyImpl*>(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(m_viewWidget))->drawingArea()); + return drawingArea ? drawingArea->size() : IntSize(); } bool PageClientImpl::isViewWindowActive() @@ -116,14 +108,14 @@ bool PageClientImpl::isViewInWindow() return webkitWebViewBaseIsInWindow(WEBKIT_WEB_VIEW_BASE(m_viewWidget)); } -void PageClientImpl::PageClientImpl::processDidCrash() +void PageClientImpl::PageClientImpl::processDidExit() { notImplemented(); } void PageClientImpl::didRelaunchProcess() { - notImplemented(); + webkitWebViewBaseDidRelaunchWebProcess(WEBKIT_WEB_VIEW_BASE(m_viewWidget)); } void PageClientImpl::toolTipChanged(const String&, const String& newToolTip) @@ -131,7 +123,7 @@ void PageClientImpl::toolTipChanged(const String&, const String& newToolTip) webkitWebViewBaseSetTooltipText(WEBKIT_WEB_VIEW_BASE(m_viewWidget), newToolTip.utf8().data()); } -void PageClientImpl::setCursor(const Cursor& cursor) +void PageClientImpl::setCursor(const WebCore::Cursor& cursor) { if (!gtk_widget_get_realized(m_viewWidget)) return; @@ -147,7 +139,7 @@ void PageClientImpl::setCursor(const Cursor& cursor) gdk_window_set_cursor(window, newCursor); } -void PageClientImpl::setCursorHiddenUntilMouseMoves(bool hiddenUntilMouseMoves) +void PageClientImpl::setCursorHiddenUntilMouseMoves(bool /* hiddenUntilMouseMoves */) { notImplemented(); } @@ -189,7 +181,7 @@ FloatRect PageClientImpl::convertToUserSpace(const FloatRect& viewRect) return viewRect; } -IntPoint PageClientImpl::screenToWindow(const IntPoint& point) +IntPoint PageClientImpl::screenToRootView(const IntPoint& point) { IntPoint widgetPositionOnScreen = convertWidgetPointToScreenPoint(m_viewWidget, IntPoint()); IntPoint result(point); @@ -197,7 +189,7 @@ IntPoint PageClientImpl::screenToWindow(const IntPoint& point) return result; } -IntRect PageClientImpl::windowToScreen(const IntRect& rect) +IntRect PageClientImpl::rootViewToScreen(const IntRect& rect) { return IntRect(convertWidgetPointToScreenPoint(m_viewWidget, rect.location()), rect.size()); } @@ -214,45 +206,42 @@ void PageClientImpl::doneWithKeyEvent(const NativeWebKeyboardEvent& event, bool gtk_main_do_event(event.nativeEvent()); } -PassRefPtr<WebPopupMenuProxy> PageClientImpl::createPopupMenuProxy(WebPageProxy* page) +RefPtr<WebPopupMenuProxy> PageClientImpl::createPopupMenuProxy(WebPageProxy& page) { return WebPopupMenuProxyGtk::create(m_viewWidget, page); } -PassRefPtr<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy* page) +std::unique_ptr<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy& page, const ContextMenuContextData& context, const UserData& userData) { - return WebContextMenuProxyGtk::create(m_viewWidget, page); + return std::make_unique<WebContextMenuProxyGtk>(m_viewWidget, page, context, userData); } -#if ENABLE(INPUT_TYPE_COLOR) -PassRefPtr<WebColorPicker> PageClientImpl::createColorPicker(WebPageProxy*, const WebCore::Color&, const WebCore::IntRect&) +RefPtr<WebColorPicker> PageClientImpl::createColorPicker(WebPageProxy* page, const WebCore::Color& color, const WebCore::IntRect& rect) { - notImplemented(); - return 0; + if (WEBKIT_IS_WEB_VIEW(m_viewWidget)) + return WebKitColorChooser::create(*page, color, rect); + return WebColorPickerGtk::create(*page, color, rect); } -#endif -void PageClientImpl::setFindIndicator(PassRefPtr<FindIndicator>, bool fadeOut, bool animate) +void PageClientImpl::enterAcceleratedCompositingMode(const LayerTreeContext&) { - notImplemented(); + webkitWebViewBaseEnterAcceleratedCompositingMode(WEBKIT_WEB_VIEW_BASE(m_viewWidget)); } -#if USE(ACCELERATED_COMPOSITING) -void PageClientImpl::enterAcceleratedCompositingMode(const LayerTreeContext&) +void PageClientImpl::exitAcceleratedCompositingMode() { - notImplemented(); + webkitWebViewBaseExitAcceleratedCompositingMode(WEBKIT_WEB_VIEW_BASE(m_viewWidget)); } -void PageClientImpl::exitAcceleratedCompositingMode() +void PageClientImpl::willEnterAcceleratedCompositingMode() { - notImplemented(); + webkitWebViewBaseWillEnterAcceleratedCompositingMode(WEBKIT_WEB_VIEW_BASE(m_viewWidget)); } void PageClientImpl::updateAcceleratedCompositingMode(const LayerTreeContext&) { notImplemented(); } -#endif // USE(ACCELERATED_COMPOSITING) void PageClientImpl::pageClosed() { @@ -264,15 +253,22 @@ void PageClientImpl::preferencesDidChange() notImplemented(); } -void PageClientImpl::updateTextInputState() +void PageClientImpl::selectionDidChange() { webkitWebViewBaseUpdateTextInputState(WEBKIT_WEB_VIEW_BASE(m_viewWidget)); + if (WEBKIT_IS_WEB_VIEW(m_viewWidget)) + webkitWebViewSelectionDidChange(WEBKIT_WEB_VIEW(m_viewWidget)); } #if ENABLE(DRAG_SUPPORT) void PageClientImpl::startDrag(const WebCore::DragData& dragData, PassRefPtr<ShareableBitmap> dragImage) { - webkitWebViewBaseStartDrag(WEBKIT_WEB_VIEW_BASE(m_viewWidget), dragData, dragImage); + WebKitWebViewBase* webView = WEBKIT_WEB_VIEW_BASE(m_viewWidget); + webkitWebViewBaseDragAndDropHandler(webView).startDrag(dragData, dragImage); + + // A drag starting should prevent a double-click from happening. This might + // happen if a drag is followed very quickly by another click (like in the WTR). + webkitWebViewBaseResetClickCounter(webView); } #endif @@ -281,7 +277,7 @@ void PageClientImpl::handleDownloadRequest(DownloadProxy* download) webkitWebViewBaseHandleDownloadRequest(WEBKIT_WEB_VIEW_BASE(m_viewWidget), download); } -void PageClientImpl::didCommitLoadForMainFrame() +void PageClientImpl::didCommitLoadForMainFrame(const String& /* mimeType */, bool /* useCustomContentProvider */ ) { webkitWebViewBaseResetClickCounter(WEBKIT_WEB_VIEW_BASE(m_viewWidget)); } @@ -319,23 +315,30 @@ void PageClientImpl::exitFullScreen() webkitWebViewBaseExitFullScreen(WEBKIT_WEB_VIEW_BASE(m_viewWidget)); } -void PageClientImpl::beganEnterFullScreen(const IntRect& initialFrame, const IntRect& finalFrame) +void PageClientImpl::beganEnterFullScreen(const IntRect& /* initialFrame */, const IntRect& /* finalFrame */) { notImplemented(); } -void PageClientImpl::beganExitFullScreen(const IntRect& initialFrame, const IntRect& finalFrame) +void PageClientImpl::beganExitFullScreen(const IntRect& /* initialFrame */, const IntRect& /* finalFrame */) { notImplemented(); } #endif // ENABLE(FULLSCREEN_API) +#if ENABLE(TOUCH_EVENTS) void PageClientImpl::doneWithTouchEvent(const NativeWebTouchEvent& event, bool wasEventHandled) { if (wasEventHandled) return; +#if HAVE(GTK_GESTURES) + GestureController& gestureController = webkitWebViewBaseGestureController(WEBKIT_WEB_VIEW_BASE(m_viewWidget)); + if (gestureController.handleEvent(event.nativeEvent())) + return; +#endif + // Emulate pointer events if unhandled. const GdkEvent* touchEvent = event.nativeEvent(); @@ -380,5 +383,71 @@ void PageClientImpl::doneWithTouchEvent(const NativeWebTouchEvent& event, bool w gtk_widget_event(m_viewWidget, pointerEvent.get()); } +#endif // ENABLE(TOUCH_EVENTS) + +void PageClientImpl::didFinishLoadingDataForCustomContentProvider(const String&, const IPC::DataReference&) +{ +} + +void PageClientImpl::navigationGestureDidBegin() +{ +} + +void PageClientImpl::navigationGestureWillEnd(bool, WebBackForwardListItem&) +{ +} + +void PageClientImpl::navigationGestureDidEnd(bool, WebBackForwardListItem&) +{ +} + +void PageClientImpl::navigationGestureDidEnd() +{ +} + +void PageClientImpl::willRecordNavigationSnapshot(WebBackForwardListItem&) +{ +} + +void PageClientImpl::didRemoveNavigationGestureSnapshot() +{ +} + +void PageClientImpl::didFirstVisuallyNonEmptyLayoutForMainFrame() +{ +} + +void PageClientImpl::didFinishLoadForMainFrame() +{ +} + +void PageClientImpl::didSameDocumentNavigationForMainFrame(SameDocumentNavigationType) +{ +} + +void PageClientImpl::didChangeBackgroundColor() +{ +} + +void PageClientImpl::refView() +{ + g_object_ref(m_viewWidget); +} + +void PageClientImpl::derefView() +{ + g_object_unref(m_viewWidget); +} + +#if ENABLE(VIDEO) && USE(GSTREAMER) +bool PageClientImpl::decidePolicyForInstallMissingMediaPluginsPermissionRequest(InstallMissingMediaPluginsPermissionRequest& request) +{ + if (!WEBKIT_IS_WEB_VIEW(m_viewWidget)) + return false; + + webkitWebViewRequestInstallMissingMediaPlugins(WEBKIT_WEB_VIEW(m_viewWidget), request); + return true; +} +#endif } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.h b/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.h index c420beec7..7af2b9b6c 100644 --- a/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.h +++ b/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.h @@ -1,3 +1,4 @@ + /* * Copyright (C) 2010 Apple Inc. All rights reserved. * Portions Copyright (c) 2010 Motorola Mobility, Inc. All rights reserved. @@ -29,13 +30,12 @@ #define PageClientImpl_h #include "DefaultUndoController.h" -#include "KeyBindingTranslator.h" #include "PageClient.h" #include "WebFullScreenManagerProxy.h" #include "WebPageProxy.h" -#include "WindowsKeyboardCodes.h" #include <WebCore/IntSize.h> #include <gtk/gtk.h> +#include <memory> namespace WebKit { @@ -48,29 +48,24 @@ class PageClientImpl : public PageClient #endif { public: - ~PageClientImpl(); - static PassOwnPtr<PageClientImpl> create(GtkWidget* viewWidget) - { - return adoptPtr(new PageClientImpl(viewWidget)); - } + explicit PageClientImpl(GtkWidget*); GtkWidget* viewWidget() { return m_viewWidget; } private: - explicit PageClientImpl(GtkWidget*); - // PageClient virtual std::unique_ptr<DrawingAreaProxy> createDrawingAreaProxy() override; virtual void setViewNeedsDisplay(const WebCore::IntRect&) override; virtual void displayView() override; virtual bool canScrollView() override { return false; } virtual void scrollView(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset) override; + virtual void requestScroll(const WebCore::FloatPoint& scrollPosition, const WebCore::IntPoint& scrollOrigin, bool isProgrammaticScroll) override; virtual WebCore::IntSize viewSize() override; virtual bool isViewWindowActive() override; virtual bool isViewFocused() override; virtual bool isViewVisible() override; virtual bool isViewInWindow() override; - virtual void processDidCrash() override; + virtual void processDidExit() override; virtual void didRelaunchProcess() override; virtual void pageClosed() override; virtual void preferencesDidChange() override; @@ -84,29 +79,28 @@ private: virtual void executeUndoRedo(WebPageProxy::UndoOrRedo) override; virtual WebCore::FloatRect convertToDeviceSpace(const WebCore::FloatRect&) override; virtual WebCore::FloatRect convertToUserSpace(const WebCore::FloatRect&) override; - virtual WebCore::IntPoint screenToWindow(const WebCore::IntPoint&) override; - virtual WebCore::IntRect windowToScreen(const WebCore::IntRect&) override; + virtual WebCore::IntPoint screenToRootView(const WebCore::IntPoint&) override; + virtual WebCore::IntRect rootViewToScreen(const WebCore::IntRect&) override; virtual void doneWithKeyEvent(const NativeWebKeyboardEvent&, bool wasEventHandled) override; - virtual PassRefPtr<WebPopupMenuProxy> createPopupMenuProxy(WebPageProxy*) override; - virtual PassRefPtr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy*) override; + virtual RefPtr<WebPopupMenuProxy> createPopupMenuProxy(WebPageProxy&) override; + virtual std::unique_ptr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy&, const ContextMenuContextData&, const UserData&) override; #if ENABLE(INPUT_TYPE_COLOR) - virtual PassRefPtr<WebColorPicker> createColorPicker(WebPageProxy*, const WebCore::Color& intialColor, const WebCore::IntRect&) override; + virtual RefPtr<WebColorPicker> createColorPicker(WebPageProxy*, const WebCore::Color& intialColor, const WebCore::IntRect&) override; #endif - virtual void setFindIndicator(PassRefPtr<FindIndicator>, bool fadeOut, bool animate) override; - virtual void getEditorCommandsForKeyEvent(const NativeWebKeyboardEvent&, const AtomicString&, Vector<WTF::String>&) override; - virtual void updateTextInputState() override; + virtual void selectionDidChange() override; #if ENABLE(DRAG_SUPPORT) virtual void startDrag(const WebCore::DragData&, PassRefPtr<ShareableBitmap> dragImage) override; #endif -#if USE(ACCELERATED_COMPOSITING) virtual void enterAcceleratedCompositingMode(const LayerTreeContext&) override; virtual void exitAcceleratedCompositingMode() override; virtual void updateAcceleratedCompositingMode(const LayerTreeContext&) override; -#endif + void willEnterAcceleratedCompositingMode() override; virtual void handleDownloadRequest(DownloadProxy*) override; - virtual void didCommitLoadForMainFrame() override; + virtual void didChangeContentSize(const WebCore::IntSize&) override { } + virtual void didCommitLoadForMainFrame(const String& mimeType, bool useCustomContentProvider) override; + virtual void didFailLoadForMainFrame() override { } // Auxiliary Client Creation #if ENABLE(FULLSCREEN_API) @@ -123,12 +117,37 @@ private: virtual void beganExitFullScreen(const WebCore::IntRect& initialFrame, const WebCore::IntRect& finalFrame) override; #endif + virtual void didFinishLoadingDataForCustomContentProvider(const String& suggestedFilename, const IPC::DataReference&) override; + + virtual void navigationGestureDidBegin() override; + virtual void navigationGestureWillEnd(bool, WebBackForwardListItem&) override; + virtual void navigationGestureDidEnd(bool, WebBackForwardListItem&) override; + virtual void navigationGestureDidEnd() override; + virtual void willRecordNavigationSnapshot(WebBackForwardListItem&) override; + virtual void didRemoveNavigationGestureSnapshot() override; + + virtual void didFirstVisuallyNonEmptyLayoutForMainFrame() override; + virtual void didFinishLoadForMainFrame() override; + virtual void didSameDocumentNavigationForMainFrame(SameDocumentNavigationType) override; + +#if ENABLE(TOUCH_EVENTS) virtual void doneWithTouchEvent(const NativeWebTouchEvent&, bool wasEventHandled) override; +#endif + + virtual void didChangeBackgroundColor() override; + + virtual void refView() override; + virtual void derefView() override; + + virtual void didRestoreScrollPosition() override { } + +#if ENABLE(VIDEO) && USE(GSTREAMER) + virtual bool decidePolicyForInstallMissingMediaPluginsPermissionRequest(InstallMissingMediaPluginsPermissionRequest&) override; +#endif // Members of PageClientImpl class GtkWidget* m_viewWidget; DefaultUndoController m_undoController; - WebCore::KeyBindingTranslator m_keyBindingTranslator; }; } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitAuthenticationDialog.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitAuthenticationDialog.cpp index 43cd83ac0..fc856f698 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitAuthenticationDialog.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitAuthenticationDialog.cpp @@ -25,12 +25,17 @@ #include "WebKitCredentialPrivate.h" #include "WebKitPrivate.h" #include "WebKitWebView.h" +#include <glib/gi18n-lib.h> +#include <wtf/text/CString.h> using namespace WebKit; struct _WebKitAuthenticationDialogPrivate { GRefPtr<WebKitAuthenticationRequest> request; - GtkWidget* authWidget; + CredentialStorageMode credentialStorageMode; + GtkWidget* loginEntry; + GtkWidget* passwordEntry; + GtkWidget* rememberCheckButton; GtkWidget* defaultButton; unsigned long authenticationCancelledID; GRefPtr<GtkStyleContext> styleContext; @@ -41,7 +46,15 @@ WEBKIT_DEFINE_TYPE(WebKitAuthenticationDialog, webkit_authentication_dialog, GTK static void okButtonClicked(GtkButton*, WebKitAuthenticationDialog* authDialog) { WebKitAuthenticationDialogPrivate* priv = authDialog->priv; - WebKitCredential* credential = webkitCredentialCreate(webkitAuthenticationWidgetCreateCredential(WEBKIT_AUTHENTICATION_WIDGET(priv->authWidget))); + const char* username = gtk_entry_get_text(GTK_ENTRY(priv->loginEntry)); + const char* password = gtk_entry_get_text(GTK_ENTRY(priv->passwordEntry)); + bool rememberPassword = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->rememberCheckButton)); + + WebCore::CredentialPersistence persistence = rememberPassword && priv->credentialStorageMode == AllowPersistentStorage ? + WebCore::CredentialPersistencePermanent : WebCore::CredentialPersistenceForSession; + + // FIXME: Use a stack allocated WebKitCredential. + WebKitCredential* credential = webkitCredentialCreate(WebCore::Credential(String::fromUTF8(username), String::fromUTF8(password), persistence)); webkit_authentication_request_authenticate(priv->request.get(), credential); webkit_credential_free(credential); gtk_widget_destroy(GTK_WIDGET(authDialog)); @@ -49,7 +62,7 @@ static void okButtonClicked(GtkButton*, WebKitAuthenticationDialog* authDialog) static void cancelButtonClicked(GtkButton*, WebKitAuthenticationDialog* authDialog) { - webkit_authentication_request_authenticate(authDialog->priv->request.get(), 0); + webkit_authentication_request_authenticate(authDialog->priv->request.get(), nullptr); gtk_widget_destroy(GTK_WIDGET(authDialog)); } @@ -58,34 +71,122 @@ static void authenticationCancelled(WebKitAuthenticationRequest*, WebKitAuthenti gtk_widget_destroy(GTK_WIDGET(authDialog)); } -static void webkitAuthenticationDialogInitialize(WebKitAuthenticationDialog* authDialog, CredentialStorageMode credentialStorageMode) +static GtkWidget* createLabelWithLineWrap(const char* text) +{ + GtkWidget* label = gtk_label_new(text); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + gtk_label_set_max_width_chars(GTK_LABEL(label), 40); + return label; +} + +static void webkitAuthenticationDialogInitialize(WebKitAuthenticationDialog* authDialog) { GtkWidget* frame = gtk_frame_new(0); gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); GtkWidget* vBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6); - gtk_container_set_border_width(GTK_CONTAINER(vBox), 5); + gtk_container_set_border_width(GTK_CONTAINER(vBox), 12); + + GtkWidget* label = gtk_label_new(nullptr); + // Title of the HTTP authentication dialog. + GUniquePtr<char> title(g_strdup_printf("<b>%s</b>", _("Authentication Required"))); + gtk_label_set_markup(GTK_LABEL(label), title.get()); + gtk_widget_set_halign(label, GTK_ALIGN_CENTER); + gtk_widget_show(label); + gtk_box_pack_start(GTK_BOX(vBox), label, FALSE, FALSE, 0); GtkWidget* buttonBox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL); gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonBox), GTK_BUTTONBOX_END); gtk_container_set_border_width(GTK_CONTAINER(buttonBox), 5); gtk_box_set_spacing(GTK_BOX(buttonBox), 6); - GtkWidget* button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); + GtkWidget* button = gtk_button_new_with_mnemonic(_("_Cancel")); g_signal_connect(button, "clicked", G_CALLBACK(cancelButtonClicked), authDialog); gtk_box_pack_end(GTK_BOX(buttonBox), button, FALSE, TRUE, 0); gtk_widget_show(button); - button = gtk_button_new_from_stock(GTK_STOCK_OK); - authDialog->priv->defaultButton = button; + WebKitAuthenticationDialogPrivate* priv = authDialog->priv; + button = gtk_button_new_with_mnemonic(_("_Authenticate")); + priv->defaultButton = button; g_signal_connect(button, "clicked", G_CALLBACK(okButtonClicked), authDialog); gtk_widget_set_can_default(button, TRUE); gtk_box_pack_end(GTK_BOX(buttonBox), button, FALSE, TRUE, 0); gtk_widget_show(button); - authDialog->priv->authWidget = webkitAuthenticationWidgetNew(webkitAuthenticationRequestGetAuthenticationChallenge(authDialog->priv->request.get())->core(), credentialStorageMode); - gtk_box_pack_start(GTK_BOX(vBox), authDialog->priv->authWidget, TRUE, TRUE, 0); - gtk_widget_show(authDialog->priv->authWidget); + GtkWidget* authBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 12); + gtk_container_set_border_width(GTK_CONTAINER(authBox), 5); + + const WebCore::AuthenticationChallenge& challenge = webkitAuthenticationRequestGetAuthenticationChallenge(priv->request.get())->core(); + // Prompt on the HTTP authentication dialog. + GUniquePtr<char> prompt(g_strdup_printf(_("Authentication required by %s:%i"), + challenge.protectionSpace().host().utf8().data(), challenge.protectionSpace().port())); + label = createLabelWithLineWrap(prompt.get()); + gtk_widget_show(label); + gtk_box_pack_start(GTK_BOX(authBox), label, FALSE, FALSE, 0); + + String realm = challenge.protectionSpace().realm(); + if (!realm.isEmpty()) { + // Label on the HTTP authentication dialog. %s is a (probably English) message from the website. + GUniquePtr<char> message(g_strdup_printf(_("The site says: “%s”"), realm.utf8().data())); + label = createLabelWithLineWrap(message.get()); + gtk_widget_show(label); + gtk_box_pack_start(GTK_BOX(authBox), label, FALSE, FALSE, 0); + } + + // Check button on the HTTP authentication dialog. + priv->rememberCheckButton = gtk_check_button_new_with_mnemonic(_("_Remember password")); + gtk_label_set_line_wrap(GTK_LABEL(gtk_bin_get_child(GTK_BIN(priv->rememberCheckButton))), TRUE); + + priv->loginEntry = gtk_entry_new(); + gtk_widget_set_hexpand(priv->loginEntry, TRUE); + gtk_entry_set_activates_default(GTK_ENTRY(priv->loginEntry), TRUE); + gtk_widget_show(priv->loginEntry); + + // Entry on the HTTP authentication dialog. + GtkWidget* loginLabel = gtk_label_new_with_mnemonic(_("_Username")); + gtk_label_set_mnemonic_widget(GTK_LABEL(loginLabel), priv->loginEntry); + gtk_widget_set_halign(loginLabel, GTK_ALIGN_END); + gtk_style_context_add_class(gtk_widget_get_style_context(loginLabel), GTK_STYLE_CLASS_DIM_LABEL); + gtk_widget_show(loginLabel); + + priv->passwordEntry = gtk_entry_new(); + gtk_widget_set_hexpand(priv->passwordEntry, TRUE); + gtk_entry_set_activates_default(GTK_ENTRY(priv->passwordEntry), TRUE); + gtk_widget_show(priv->passwordEntry); + + // Entry on the HTTP authentication dialog. + GtkWidget* passwordLabel = gtk_label_new_with_mnemonic(_("_Password")); + gtk_label_set_mnemonic_widget(GTK_LABEL(passwordLabel), priv->passwordEntry); + gtk_widget_set_halign(passwordLabel, GTK_ALIGN_END); + gtk_style_context_add_class(gtk_widget_get_style_context(passwordLabel), GTK_STYLE_CLASS_DIM_LABEL); + gtk_widget_show(passwordLabel); + + GtkWidget* grid = gtk_grid_new(); + gtk_grid_set_column_spacing(GTK_GRID(grid), 6); + gtk_grid_set_row_spacing(GTK_GRID(grid), 6); + gtk_grid_attach(GTK_GRID(grid), loginLabel, 0, 0, 1, 1); + gtk_grid_attach(GTK_GRID(grid), priv->loginEntry, 1, 0, 1, 1); + gtk_grid_attach(GTK_GRID(grid), passwordLabel, 0, 1, 1, 1); + gtk_grid_attach(GTK_GRID(grid), priv->passwordEntry, 1, 1, 1, 1); + gtk_grid_attach(GTK_GRID(grid), priv->rememberCheckButton, 1, 2, 1, 1); + gtk_widget_show(grid); + gtk_box_pack_start(GTK_BOX(authBox), grid, FALSE, FALSE, 0); + + gtk_entry_set_visibility(GTK_ENTRY(priv->passwordEntry), FALSE); + gtk_widget_set_visible(priv->rememberCheckButton, priv->credentialStorageMode != DisallowPersistentStorage && !realm.isEmpty()); + + const WebCore::Credential& credentialFromPersistentStorage = challenge.proposedCredential(); + if (!credentialFromPersistentStorage.isEmpty()) { + gtk_entry_set_text(GTK_ENTRY(priv->loginEntry), credentialFromPersistentStorage.user().utf8().data()); + gtk_entry_set_text(GTK_ENTRY(priv->passwordEntry), credentialFromPersistentStorage.password().utf8().data()); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->rememberCheckButton), TRUE); + } + + gtk_widget_grab_focus(priv->loginEntry); + + gtk_box_pack_start(GTK_BOX(vBox), authBox, TRUE, TRUE, 0); + gtk_widget_show(authBox); gtk_box_pack_end(GTK_BOX(vBox), buttonBox, FALSE, TRUE, 0); gtk_widget_show(buttonBox); @@ -159,6 +260,7 @@ GtkWidget* webkitAuthenticationDialogNew(WebKitAuthenticationRequest* request, C { WebKitAuthenticationDialog* authDialog = WEBKIT_AUTHENTICATION_DIALOG(g_object_new(WEBKIT_TYPE_AUTHENTICATION_DIALOG, NULL)); authDialog->priv->request = request; - webkitAuthenticationDialogInitialize(authDialog, mode); + authDialog->priv->credentialStorageMode = mode; + webkitAuthenticationDialogInitialize(authDialog); return GTK_WIDGET(authDialog); } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitAuthenticationDialog.h b/Source/WebKit2/UIProcess/API/gtk/WebKitAuthenticationDialog.h index e5e62a7bd..0e5071f53 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitAuthenticationDialog.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitAuthenticationDialog.h @@ -21,10 +21,13 @@ #define WebKitAuthenticationDialog_h #include "WebKitAuthenticationRequest.h" -#include "WebKitAuthenticationWidget.h" -#include "WebKitWebView.h" #include <gtk/gtk.h> +enum CredentialStorageMode { + AllowPersistentStorage, // The user is asked whether to store credential information. + DisallowPersistentStorage // Credential information is only kept in the session. +}; + G_BEGIN_DECLS #define WEBKIT_TYPE_AUTHENTICATION_DIALOG (webkit_authentication_dialog_get_type()) diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitAuthenticationRequest.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitAuthenticationRequest.cpp index 6f0c3707e..f79d03a4b 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitAuthenticationRequest.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitAuthenticationRequest.cpp @@ -67,18 +67,35 @@ struct _WebKitAuthenticationRequestPrivate { static guint signals[LAST_SIGNAL] = { 0, }; -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_AUTHENTICATION_SCHEME_DEFAULT, ProtectionSpaceAuthenticationSchemeDefault); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_AUTHENTICATION_SCHEME_HTTP_BASIC, ProtectionSpaceAuthenticationSchemeHTTPBasic); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_AUTHENTICATION_SCHEME_HTTP_DIGEST, ProtectionSpaceAuthenticationSchemeHTTPDigest); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_AUTHENTICATION_SCHEME_HTML_FORM, ProtectionSpaceAuthenticationSchemeHTMLForm); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_AUTHENTICATION_SCHEME_NTLM, ProtectionSpaceAuthenticationSchemeNTLM); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_AUTHENTICATION_SCHEME_NEGOTIATE, ProtectionSpaceAuthenticationSchemeNegotiate); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_AUTHENTICATION_SCHEME_CLIENT_CERTIFICATE_REQUESTED, ProtectionSpaceAuthenticationSchemeClientCertificateRequested); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_AUTHENTICATION_SCHEME_SERVER_TRUST_EVALUATION_REQUESTED, ProtectionSpaceAuthenticationSchemeServerTrustEvaluationRequested); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_AUTHENTICATION_SCHEME_UNKNOWN, ProtectionSpaceAuthenticationSchemeUnknown); - WEBKIT_DEFINE_TYPE(WebKitAuthenticationRequest, webkit_authentication_request, G_TYPE_OBJECT) +static inline WebKitAuthenticationScheme toWebKitAuthenticationScheme(WebCore::ProtectionSpaceAuthenticationScheme coreScheme) +{ + switch (coreScheme) { + case WebCore::ProtectionSpaceAuthenticationSchemeDefault: + return WEBKIT_AUTHENTICATION_SCHEME_DEFAULT; + case WebCore::ProtectionSpaceAuthenticationSchemeHTTPBasic: + return WEBKIT_AUTHENTICATION_SCHEME_HTTP_BASIC; + case WebCore::ProtectionSpaceAuthenticationSchemeHTTPDigest: + return WEBKIT_AUTHENTICATION_SCHEME_HTTP_DIGEST; + case WebCore::ProtectionSpaceAuthenticationSchemeHTMLForm: + return WEBKIT_AUTHENTICATION_SCHEME_HTML_FORM; + case WebCore::ProtectionSpaceAuthenticationSchemeNTLM: + return WEBKIT_AUTHENTICATION_SCHEME_NTLM; + case WebCore::ProtectionSpaceAuthenticationSchemeNegotiate: + return WEBKIT_AUTHENTICATION_SCHEME_NEGOTIATE; + case WebCore::ProtectionSpaceAuthenticationSchemeClientCertificateRequested: + return WEBKIT_AUTHENTICATION_SCHEME_CLIENT_CERTIFICATE_REQUESTED; + case WebCore::ProtectionSpaceAuthenticationSchemeServerTrustEvaluationRequested: + return WEBKIT_AUTHENTICATION_SCHEME_SERVER_TRUST_EVALUATION_REQUESTED; + case WebCore::ProtectionSpaceAuthenticationSchemeUnknown: + return WEBKIT_AUTHENTICATION_SCHEME_UNKNOWN; + default: + ASSERT_NOT_REACHED(); + return WEBKIT_AUTHENTICATION_SCHEME_DEFAULT; + } +} + static void webkitAuthenticationRequestDispose(GObject* object) { WebKitAuthenticationRequest* request = WEBKIT_AUTHENTICATION_REQUEST(object); @@ -168,7 +185,7 @@ WebKitCredential* webkit_authentication_request_get_proposed_credential(WebKitAu { g_return_val_if_fail(WEBKIT_IS_AUTHENTICATION_REQUEST(request), 0); - const WebCore::Credential& credential = request->priv->authenticationChallenge->proposedCredential()->core(); + const WebCore::Credential& credential = request->priv->authenticationChallenge->proposedCredential()->credential(); if (credential.isEmpty()) return 0; @@ -244,7 +261,7 @@ WebKitAuthenticationScheme webkit_authentication_request_get_scheme(WebKitAuthen { g_return_val_if_fail(WEBKIT_IS_AUTHENTICATION_REQUEST(request), WEBKIT_AUTHENTICATION_SCHEME_UNKNOWN); - return static_cast<WebKitAuthenticationScheme>(request->priv->authenticationChallenge->protectionSpace()->authenticationScheme()); + return toWebKitAuthenticationScheme(request->priv->authenticationChallenge->protectionSpace()->authenticationScheme()); } /** @@ -295,8 +312,11 @@ void webkit_authentication_request_authenticate(WebKitAuthenticationRequest* req { g_return_if_fail(WEBKIT_IS_AUTHENTICATION_REQUEST(request)); - RefPtr<WebCredential> webCredential = credential ? WebCredential::create(webkitCredentialGetCredential(credential)) : 0; - request->priv->authenticationChallenge->listener()->useCredential(webCredential.get()); + if (credential) + request->priv->authenticationChallenge->listener()->useCredential(WebCredential::create(webkitCredentialGetCredential(credential)).ptr()); + else + request->priv->authenticationChallenge->listener()->useCredential(nullptr); + request->priv->handledRequest = true; } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitAutocleanups.h b/Source/WebKit2/UIProcess/API/gtk/WebKitAutocleanups.h new file mode 100644 index 000000000..f872f3068 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitAutocleanups.h @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2015 Igalia S.L. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) +#error "Only <webkit2/webkit2.h> can be included directly." +#endif + +#ifndef WebKitAutocleanups_h +#define WebKitAutocleanups_h + +#ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC +#ifndef __GI_SCANNER__ + +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitAuthenticationRequest, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitBackForwardList, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitBackForwardListItem, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitColorChooserRequest, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitContextMenu, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitContextMenuItem, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitCookieManager, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitDownload, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitEditorState, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitFaviconDatabase, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitFileChooserRequest, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitFindController, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitFormSubmissionRequest, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitGeolocationPermissionRequest, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitHitTestResult, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitInstallMissingMediaPluginsPermissionRequest, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitNavigationPolicyDecision, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitNotification, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitNotificationPermissionRequest, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitPermissionRequest, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitPlugin, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitPolicyDecision, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitPrintOperation, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitResponsePolicyDecision, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitSecurityManager, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitSettings, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitURIRequest, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitURIResponse, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitURISchemeRequest, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitUserContentManager, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitUserMediaPermissionRequest, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitWebContext, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitWebInspector, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitWebResource, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitWebView, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitWebsiteDataManager, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitWindowProperties, g_object_unref) + +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitCredential, webkit_credential_free) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitJavascriptResult, webkit_javascript_result_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitMimeInfo, webkit_mime_info_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitNavigationAction, webkit_navigation_action_free) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitUserScript, webkit_user_script_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitUserStyleSheet, webkit_user_style_sheet_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitWebViewSessionState, webkit_web_view_session_state_unref) + +#endif // __GI_SCANNER__ +#endif // G_DEFINE_AUTOPTR_CLEANUP_FUNC + +#endif // WebKitAutocleanups_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardList.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardList.cpp index 6cbddc8aa..0762d0280 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardList.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardList.cpp @@ -23,7 +23,7 @@ #include "WebKitBackForwardListPrivate.h" #include "WebKitMarshal.h" #include "WebKitPrivate.h" -#include <wtf/gobject/GRefPtr.h> +#include <wtf/glib/GRefPtr.h> /** * SECTION: WebKitBackForwardList @@ -128,20 +128,25 @@ WebKitBackForwardList* webkitBackForwardListCreate(WebBackForwardList* backForwa return list; } -void webkitBackForwardListChanged(WebKitBackForwardList* backForwardList, WebBackForwardListItem* webAddedItem, API::Array* webRemovedItems) +void webkitBackForwardListChanged(WebKitBackForwardList* backForwardList, WebBackForwardListItem* webAddedItem, const Vector<RefPtr<WebBackForwardListItem>>& webRemovedItems) { WebKitBackForwardListItem* addedItem = webkitBackForwardListGetOrCreateItem(backForwardList, webAddedItem); - GList* removedItems = 0; + GList* removedItems = nullptr; - size_t removedItemsSize = webRemovedItems ? webRemovedItems->size() : 0; WebKitBackForwardListPrivate* priv = backForwardList->priv; - for (size_t i = 0; i < removedItemsSize; ++i) { - WebBackForwardListItem* webItem = static_cast<WebBackForwardListItem*>(webRemovedItems->at(i)); - removedItems = g_list_prepend(removedItems, g_object_ref(G_OBJECT(priv->itemsMap.get(webItem).get()))); - priv->itemsMap.remove(webItem); + for (auto& webItem : webRemovedItems) { + // After a session restore, we still don't have wrappers for the newly added items, so it would be possible that + // the removed items are not in the map. In that case we create a wrapper now to pass it the changed signal, but + // without adding it to the item map. See https://bugs.webkit.org/show_bug.cgi?id=153233. + GRefPtr<WebKitBackForwardListItem> removedItem = priv->itemsMap.get(webItem.get()); + if (removedItem) { + removedItems = g_list_prepend(removedItems, g_object_ref(removedItem.get())); + priv->itemsMap.remove(webItem.get()); + } else + removedItems = g_list_prepend(removedItems, webkitBackForwardListItemGetOrCreate(webItem.get())); } - g_signal_emit(backForwardList, signals[CHANGED], 0, addedItem, removedItems, NULL); + g_signal_emit(backForwardList, signals[CHANGED], 0, addedItem, removedItems, nullptr); g_list_free_full(removedItems, static_cast<GDestroyNotify>(g_object_unref)); } @@ -252,8 +257,8 @@ GList* webkit_back_forward_list_get_back_list_with_limit(WebKitBackForwardList* g_return_val_if_fail(WEBKIT_IS_BACK_FORWARD_LIST(backForwardList), 0); WebKitBackForwardListPrivate* priv = backForwardList->priv; - RefPtr<API::Array> apiArray = priv->backForwardItems->backListAsAPIArrayWithLimit(limit); - return webkitBackForwardListCreateList(backForwardList, apiArray.get()); + Ref<API::Array> apiArray = priv->backForwardItems->backListAsAPIArrayWithLimit(limit); + return webkitBackForwardListCreateList(backForwardList, apiArray.ptr()); } /** @@ -283,6 +288,6 @@ GList* webkit_back_forward_list_get_forward_list_with_limit(WebKitBackForwardLis g_return_val_if_fail(WEBKIT_IS_BACK_FORWARD_LIST(backForwardList), 0); WebKitBackForwardListPrivate* priv = backForwardList->priv; - RefPtr<API::Array> apiArray = priv->backForwardItems->forwardListAsAPIArrayWithLimit(limit); - return webkitBackForwardListCreateList(backForwardList, apiArray.get()); + Ref<API::Array> apiArray = priv->backForwardItems->forwardListAsAPIArrayWithLimit(limit); + return webkitBackForwardListCreateList(backForwardList, apiArray.ptr()); } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardListItem.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardListItem.cpp index ae18b05ec..b295c9904 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardListItem.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardListItem.cpp @@ -23,7 +23,8 @@ #include "WebKitBackForwardListPrivate.h" #include "WebKitPrivate.h" #include <wtf/HashMap.h> -#include <wtf/gobject/GRefPtr.h> +#include <wtf/NeverDestroyed.h> +#include <wtf/glib/GRefPtr.h> #include <wtf/text/CString.h> using namespace WebKit; @@ -48,7 +49,7 @@ struct _WebKitBackForwardListItemPrivate { WEBKIT_DEFINE_TYPE(WebKitBackForwardListItem, webkit_back_forward_list_item, G_TYPE_INITIALLY_UNOWNED) -static void webkit_back_forward_list_item_class_init(WebKitBackForwardListItemClass* listItemClass) +static void webkit_back_forward_list_item_class_init(WebKitBackForwardListItemClass*) { } @@ -56,13 +57,13 @@ typedef HashMap<WebBackForwardListItem*, WebKitBackForwardListItem*> HistoryItem static HistoryItemsMap& historyItemsMap() { - DEFINE_STATIC_LOCAL(HistoryItemsMap, itemsMap, ()); + static NeverDestroyed<HistoryItemsMap> itemsMap; return itemsMap; } static void webkitBackForwardListItemFinalized(gpointer webListItem, GObject* finalizedListItem) { - ASSERT(G_OBJECT(historyItemsMap().get(static_cast<WebBackForwardListItem*>(webListItem))) == finalizedListItem); + ASSERT_UNUSED(finalizedListItem, G_OBJECT(historyItemsMap().get(static_cast<WebBackForwardListItem*>(webListItem))) == finalizedListItem); historyItemsMap().remove(static_cast<WebBackForwardListItem*>(webListItem)); } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardListPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardListPrivate.h index ef9052dc9..88ec1d01c 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardListPrivate.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardListPrivate.h @@ -32,6 +32,6 @@ WebKitBackForwardList* webkitBackForwardListCreate(WebKit::WebBackForwardList*); WebKitBackForwardListItem* webkitBackForwardListItemGetOrCreate(WebKit::WebBackForwardListItem*); WebKit::WebBackForwardListItem* webkitBackForwardListItemGetItem(WebKitBackForwardListItem*); -void webkitBackForwardListChanged(WebKitBackForwardList*, WebKit::WebBackForwardListItem* webAddedItem, API::Array* webRemovedItems); +void webkitBackForwardListChanged(WebKitBackForwardList*, WebKit::WebBackForwardListItem* webAddedItem, const Vector<RefPtr<WebKit::WebBackForwardListItem>>&); #endif // WebKitBackForwardListPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitBatteryProvider.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitBatteryProvider.cpp index 3c1e4c6a8..6b9b4cbef 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitBatteryProvider.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitBatteryProvider.cpp @@ -43,9 +43,9 @@ static void stopUpdatingCallback(WKBatteryManagerRef batteryManager, const void* toBatteryProvider(clientInfo)->stopUpdating(); } -PassRefPtr<WebKitBatteryProvider> WebKitBatteryProvider::create(WebBatteryManagerProxy* batteryManager) +Ref<WebKitBatteryProvider> WebKitBatteryProvider::create(WebBatteryManagerProxy* batteryManager) { - return adoptRef(new WebKitBatteryProvider(batteryManager)); + return adoptRef(*new WebKitBatteryProvider(batteryManager)); } WebKitBatteryProvider::WebKitBatteryProvider(WebBatteryManagerProxy* batteryManager) diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitBatteryProvider.h b/Source/WebKit2/UIProcess/API/gtk/WebKitBatteryProvider.h index 7f05db6c7..e2e94bf04 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitBatteryProvider.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitBatteryProvider.h @@ -32,7 +32,7 @@ namespace WebKit { class WebKitBatteryProvider : public RefCounted<WebKitBatteryProvider>, public WebCore::BatteryProviderUPowerClient { public: - static PassRefPtr<WebKitBatteryProvider> create(WebBatteryManagerProxy*); + static Ref<WebKitBatteryProvider> create(WebBatteryManagerProxy*); virtual ~WebKitBatteryProvider(); void startUpdating(); diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitCertificateInfo.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitCertificateInfo.cpp deleted file mode 100644 index 12df1aaca..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitCertificateInfo.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2013 Samsung Electronics Inc. All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" -#include "WebKitCertificateInfo.h" - -#include "WebKitCertificateInfoPrivate.h" -#include <wtf/text/CString.h> - -using namespace WebKit; -using namespace WebCore; - -/** - * SECTION: WebKitCertificateInfo - * @Short_description: Boxed type to encapsulate TLS certificate information - * @Title: WebKitCertificateInfo - * @See_also: #WebKitWebView, #WebKitWebContext - * - * When a client loads a page over HTTPS where there is an underlying TLS error - * WebKit will fire a #WebKitWebView::load-failed-with-tls-errors signal with a - * #WebKitCertificateInfo and the host of the failing URI. - * - * To handle this signal asynchronously you should make a copy of the - * #WebKitCertificateInfo with webkit_certificate_info_copy(). - */ - -G_DEFINE_BOXED_TYPE(WebKitCertificateInfo, webkit_certificate_info, webkit_certificate_info_copy, webkit_certificate_info_free) - -const CertificateInfo& webkitCertificateInfoGetCertificateInfo(WebKitCertificateInfo* info) -{ - ASSERT(info); - return info->certificateInfo; -} - -/** - * webkit_certificate_info_copy: - * @info: a #WebKitCertificateInfo - * - * Make a copy of the #WebKitCertificateInfo. - * - * Returns: (transfer full): A copy of passed in #WebKitCertificateInfo. - * - * Since: 2.4 - */ -WebKitCertificateInfo* webkit_certificate_info_copy(WebKitCertificateInfo* info) -{ - g_return_val_if_fail(info, 0); - - WebKitCertificateInfo* copy = g_slice_new0(WebKitCertificateInfo); - new (copy) WebKitCertificateInfo(info); - return copy; -} - -/** - * webkit_certificate_info_free: - * @info: a #WebKitCertificateInfo - * - * Free the #WebKitCertificateInfo. - * - * Since: 2.4 - */ -void webkit_certificate_info_free(WebKitCertificateInfo* info) -{ - g_return_if_fail(info); - - info->~WebKitCertificateInfo(); - g_slice_free(WebKitCertificateInfo, info); -} - -/** - * webkit_certificate_info_get_tls_certificate: - * @info: a #WebKitCertificateInfo - * - * Get the #GTlsCertificate associated with this - * #WebKitCertificateInfo. - * - * Returns: (transfer none): The certificate of @info. - * - * Since: 2.4 - */ -GTlsCertificate* webkit_certificate_info_get_tls_certificate(WebKitCertificateInfo *info) -{ - g_return_val_if_fail(info, 0); - - return info->certificateInfo.certificate(); -} - -/** - * webkit_certificate_info_get_tls_errors: - * @info: a #WebKitCertificateInfo - * - * Get the #GTlsCertificateFlags verification status associated with this - * #WebKitCertificateInfo. - * - * Returns: The verification status of @info. - * - * Since: 2.4 - */ -GTlsCertificateFlags webkit_certificate_info_get_tls_errors(WebKitCertificateInfo *info) -{ - g_return_val_if_fail(info, static_cast<GTlsCertificateFlags>(0)); - - return info->certificateInfo.tlsErrors(); -} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitColorChooser.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitColorChooser.cpp new file mode 100644 index 000000000..71919d8f6 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitColorChooser.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2015 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "WebKitColorChooser.h" + +#include "WebKitColorChooserRequestPrivate.h" +#include "WebKitWebViewPrivate.h" +#include <WebCore/Color.h> +#include <WebCore/IntRect.h> + +using namespace WebCore; + +namespace WebKit { + +Ref<WebKitColorChooser> WebKitColorChooser::create(WebPageProxy& page, const WebCore::Color& initialColor, const WebCore::IntRect& rect) +{ + return adoptRef(*new WebKitColorChooser(page, initialColor, rect)); +} + +WebKitColorChooser::WebKitColorChooser(WebPageProxy& page, const Color& initialColor, const IntRect& rect) + : WebColorPickerGtk(page, initialColor, rect) + , m_elementRect(rect) +{ +} + +WebKitColorChooser::~WebKitColorChooser() +{ + endPicker(); +} + +void WebKitColorChooser::endPicker() +{ + if (!m_request) { + WebColorPickerGtk::endPicker(); + return; + } + + webkit_color_chooser_request_finish(m_request.get()); +} + +void WebKitColorChooser::colorChooserRequestFinished(WebKitColorChooserRequest*, WebKitColorChooser* colorChooser) +{ + colorChooser->m_request = nullptr; +} + +void WebKitColorChooser::colorChooserRequestRGBAChanged(WebKitColorChooserRequest* request, GParamSpec*, WebKitColorChooser* colorChooser) +{ + GdkRGBA rgba; + webkit_color_chooser_request_get_rgba(request, &rgba); + colorChooser->didChooseColor(rgba); +} + +void WebKitColorChooser::showColorPicker(const Color& color) +{ + m_initialColor = color; + GRefPtr<WebKitColorChooserRequest> request = adoptGRef(webkitColorChooserRequestCreate(this)); + g_signal_connect(request.get(), "notify::rgba", G_CALLBACK(WebKitColorChooser::colorChooserRequestRGBAChanged), this); + g_signal_connect(request.get(), "finished", G_CALLBACK(WebKitColorChooser::colorChooserRequestFinished), this); + + if (webkitWebViewEmitRunColorChooser(WEBKIT_WEB_VIEW(m_webView), request.get())) + m_request = request; + else + WebColorPickerGtk::showColorPicker(color); +} + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitColorChooser.h b/Source/WebKit2/UIProcess/API/gtk/WebKitColorChooser.h new file mode 100644 index 000000000..f2bf35edf --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitColorChooser.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2015 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef WebKitColorChooser_h +#define WebKitColorChooser_h + +#include "WebColorPickerGtk.h" +#include "WebKitPrivate.h" +#include <wtf/glib/GRefPtr.h> + +typedef struct _WebKitColorChooserRequest WebKitColorChooserRequest; + +namespace WebCore { +class Color; +class IntRect; +} + +namespace WebKit { + +class WebKitColorChooser final : public WebColorPickerGtk { +public: + static Ref<WebKitColorChooser> create(WebPageProxy&, const WebCore::Color&, const WebCore::IntRect&); + virtual ~WebKitColorChooser(); + + const WebCore::IntRect& elementRect() const { return m_elementRect; } + +private: + WebKitColorChooser(WebPageProxy&, const WebCore::Color&, const WebCore::IntRect&); + + virtual void endPicker() override; + virtual void showColorPicker(const WebCore::Color&) override; + + static void colorChooserRequestFinished(WebKitColorChooserRequest*, WebKitColorChooser*); + static void colorChooserRequestRGBAChanged(WebKitColorChooserRequest*, GParamSpec*, WebKitColorChooser*); + + GRefPtr<WebKitColorChooserRequest> m_request; + WebCore::IntRect m_elementRect; +}; + +} // namespace WebKit + +#endif // WebKitColorChooser_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitColorChooserRequest.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitColorChooserRequest.cpp new file mode 100644 index 000000000..98dad2514 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitColorChooserRequest.cpp @@ -0,0 +1,264 @@ +/* + * Copyright (C) 2015 Igalia S.L. + * Copyright (c) 2012, Samsung Electronics + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebKitColorChooserRequest.h" + +#include "WebKitColorChooserRequestPrivate.h" +#include <glib/gi18n-lib.h> + +using namespace WebKit; +using namespace WebCore; + +/** + * SECTION: WebKitColorChooserRequest + * @Short_description: A request to open a color chooser + * @Title: WebKitColorChooserRequest + * @See_also: #WebKitWebView + * + * Whenever the user interacts with an <input type='color' /> + * HTML element, WebKit will need to show a dialog to choose a color. For that + * to happen in a general way, instead of just opening a #GtkColorChooser + * (which might be not desirable in some cases, which could prefer to use their + * own color chooser dialog), WebKit will fire the + * #WebKitWebView::run-color-chooser signal with a #WebKitColorChooserRequest + * object, which will allow the client application to specify the color to be + * selected, to inspect the details of the request (e.g. to get initial color) + * and to cancel the request, in case nothing was selected. + * + * In case the client application does not wish to handle this signal, + * WebKit will provide a default handler which will asynchronously run + * a regular #GtkColorChooserDialog for the user to interact with. + */ + +enum { + PROP_0, + + PROP_RGBA +}; + +enum { + FINISHED, + + LAST_SIGNAL +}; + +struct _WebKitColorChooserRequestPrivate { + WebKitColorChooser* colorChooser; + GdkRGBA rgba; + bool handled; +}; + +static guint signals[LAST_SIGNAL] = { 0, }; + +WEBKIT_DEFINE_TYPE(WebKitColorChooserRequest, webkit_color_chooser_request, G_TYPE_OBJECT) + +static void webkitColorChooserRequestDispose(GObject* object) +{ + WebKitColorChooserRequest* request = WEBKIT_COLOR_CHOOSER_REQUEST(object); + if (!request->priv->handled) + webkit_color_chooser_request_finish(request); + + G_OBJECT_CLASS(webkit_color_chooser_request_parent_class)->dispose(object); +} + +static void webkitColorChooserRequestGetProperty(GObject* object, guint propertyID, GValue* value, GParamSpec* paramSpec) +{ + WebKitColorChooserRequest* request = WEBKIT_COLOR_CHOOSER_REQUEST(object); + + switch (propertyID) { + case PROP_RGBA: + g_value_set_boxed(value, &request->priv->rgba); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyID, paramSpec); + } +} + +static void webkitColorChooserRequestSetProperty(GObject* object, guint propertyID, const GValue* value, GParamSpec* paramSpec) +{ + WebKitColorChooserRequest* request = WEBKIT_COLOR_CHOOSER_REQUEST(object); + + switch (propertyID) { + case PROP_RGBA: + webkit_color_chooser_request_set_rgba(request, static_cast<GdkRGBA*>(g_value_get_boxed(value))); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyID, paramSpec); + } +} + +static void webkit_color_chooser_request_class_init(WebKitColorChooserRequestClass* requestClass) +{ + GObjectClass* objectClass = G_OBJECT_CLASS(requestClass); + objectClass->dispose = webkitColorChooserRequestDispose; + objectClass->get_property = webkitColorChooserRequestGetProperty; + objectClass->set_property = webkitColorChooserRequestSetProperty; + + /** + * WebKitWebView:rgba: + * + * The #GdkRGBA color of the request + * + * Since: 2.8 + */ + g_object_class_install_property(objectClass, + PROP_RGBA, + g_param_spec_boxed("rgba", + _("Current RGBA color"), + _("The current RGBA color for the request"), + GDK_TYPE_RGBA, + static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT))); + + /** + * WebKitColorChooserRequest::finished: + * @request: the #WebKitColorChooserRequest on which the signal is emitted + * + * Emitted when the @request finishes. This signal can be emitted because the + * user completed the @request calling webkit_color_chooser_request_finish(), + * or cancelled it with webkit_color_chooser_request_cancel() or because the + * color input element is removed from the DOM. + * + * Since: 2.8 + */ + signals[FINISHED] = + g_signal_new( + "finished", + G_TYPE_FROM_CLASS(requestClass), + G_SIGNAL_RUN_LAST, + 0, 0, + nullptr, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); +} + +/** + * webkit_color_chooser_request_set_rgba: + * @request: a #WebKitFileChooserRequest + * @rgba: a pointer #GdkRGBA + * + * Sets the current #GdkRGBA color of @request + * + * Since: 2.8 + */ +void webkit_color_chooser_request_set_rgba(WebKitColorChooserRequest* request, const GdkRGBA* rgba) +{ + g_return_if_fail(WEBKIT_IS_COLOR_CHOOSER_REQUEST(request)); + g_return_if_fail(rgba); + + if (gdk_rgba_equal(&request->priv->rgba, rgba)) + return; + + request->priv->rgba = *rgba; + g_object_notify(G_OBJECT(request), "rgba"); +} + +/** + * webkit_color_chooser_request_get_rgba: + * @request: a #WebKitColorChooserRequest + * @rgba: (out): a #GdkRGBA to fill in with the current color. + * + * Gets the current #GdkRGBA color of @request + * + * Since: 2.8 + */ +void webkit_color_chooser_request_get_rgba(WebKitColorChooserRequest* request, GdkRGBA* rgba) +{ + g_return_if_fail(WEBKIT_IS_COLOR_CHOOSER_REQUEST(request)); + g_return_if_fail(rgba); + + *rgba = request->priv->rgba; +} + +/** + * webkit_color_chooser_request_get_element_rectangle: + * @request: a #WebKitColorChooserRequest + * @rect: (out): a #GdkRectangle to fill in with the element area + * + * Gets the bounding box of the color input element. + * + * Since: 2.8 + */ +void webkit_color_chooser_request_get_element_rectangle(WebKitColorChooserRequest* request, GdkRectangle* rect) +{ + g_return_if_fail(WEBKIT_IS_COLOR_CHOOSER_REQUEST(request)); + g_return_if_fail(rect); + + *rect = request->priv->colorChooser->elementRect(); +} + +/** + * webkit_color_chooser_request_finish: + * @request: a #WebKitColorChooserRequest + * + * Finishes @request and the input element keeps the current value of + * #WebKitColorChooserRequest:rgba. + * The signal #WebKitColorChooserRequest::finished + * is emitted to notify that the request has finished. + * + * Since: 2.8 + */ +void webkit_color_chooser_request_finish(WebKitColorChooserRequest* request) +{ + g_return_if_fail(WEBKIT_IS_COLOR_CHOOSER_REQUEST(request)); + + if (request->priv->handled) + return; + + request->priv->handled = true; + g_signal_emit(request, signals[FINISHED], 0); +} + +/** + * webkit_color_chooser_request_cancel: + * @request: a #WebKitColorChooserRequest + * + * Cancels @request and the input element changes to use the initial color + * it has before the request started. + * The signal #WebKitColorChooserRequest::finished + * is emitted to notify that the request has finished. + * + * Since: 2.8 + */ +void webkit_color_chooser_request_cancel(WebKitColorChooserRequest* request) +{ + g_return_if_fail(WEBKIT_IS_COLOR_CHOOSER_REQUEST(request)); + + if (request->priv->handled) + return; + + request->priv->handled = true; + request->priv->colorChooser->cancel(); + g_signal_emit(request, signals[FINISHED], 0); +} + +WebKitColorChooserRequest* webkitColorChooserRequestCreate(WebKitColorChooser* colorChooser) +{ + WebKitColorChooserRequest* request = WEBKIT_COLOR_CHOOSER_REQUEST( + g_object_new(WEBKIT_TYPE_COLOR_CHOOSER_REQUEST, "rgba", colorChooser->initialColor(), nullptr)); + request->priv->colorChooser = colorChooser; + return request; +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitColorChooserRequest.h b/Source/WebKit2/UIProcess/API/gtk/WebKitColorChooserRequest.h new file mode 100644 index 000000000..33a4ebb35 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitColorChooserRequest.h @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2015 Igalia S.L. + * Copyright (c) 2012, Samsung Electronics + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) +#error "Only <webkit2/webkit2.h> can be included directly." +#endif + +#ifndef WebKitColorChooserRequest_h +#define WebKitColorChooserRequest_h + +#include <gtk/gtk.h> +#include <webkit2/WebKitDefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_COLOR_CHOOSER_REQUEST (webkit_color_chooser_request_get_type()) +#define WEBKIT_COLOR_CHOOSER_REQUEST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_COLOR_CHOOSER_REQUEST, WebKitColorChooserRequest)) +#define WEBKIT_IS_COLOR_CHOOSER_REQUEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_COLOR_CHOOSER_REQUEST)) +#define WEBKIT_COLOR_CHOOSER_REQUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_COLOR_CHOOSER_REQUEST, WebKitColorChooserRequestClass)) +#define WEBKIT_IS_COLOR_CHOOSER_REQUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_COLOR_CHOOSER_REQUEST)) +#define WEBKIT_COLOR_CHOOSER_REQUEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_COLOR_CHOOSER_REQUEST, WebKitColorChooserRequestClass)) + +typedef struct _WebKitColorChooserRequest WebKitColorChooserRequest; +typedef struct _WebKitColorChooserRequestClass WebKitColorChooserRequestClass; +typedef struct _WebKitColorChooserRequestPrivate WebKitColorChooserRequestPrivate; + +struct _WebKitColorChooserRequest { + GObject parent; + + /*< private >*/ + WebKitColorChooserRequestPrivate *priv; +}; + +struct _WebKitColorChooserRequestClass { + GObjectClass parent_class; +}; + +WEBKIT_API GType +webkit_color_chooser_request_get_type (void); + +WEBKIT_API void +webkit_color_chooser_request_get_rgba (WebKitColorChooserRequest *request, + GdkRGBA *rgba); + +WEBKIT_API void +webkit_color_chooser_request_set_rgba (WebKitColorChooserRequest *request, + const GdkRGBA *rgba); + +WEBKIT_API void +webkit_color_chooser_request_get_element_rectangle (WebKitColorChooserRequest *request, + GdkRectangle *rect); + +WEBKIT_API void +webkit_color_chooser_request_finish (WebKitColorChooserRequest *request); + +WEBKIT_API void +webkit_color_chooser_request_cancel (WebKitColorChooserRequest *request); + +G_END_DECLS + +#endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitColorChooserRequestPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitColorChooserRequestPrivate.h new file mode 100644 index 000000000..3acfe2821 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitColorChooserRequestPrivate.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2015 Igalia S.L. + * Copyright (c) 2012, Samsung Electronics + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebKitColorChooserRequestPrivate_h +#define WebKitColorChooserRequestPrivate_h + +#include "WebKitColorChooser.h" +#include "WebKitColorChooserRequest.h" + +WebKitColorChooserRequest* webkitColorChooserRequestCreate(WebKit::WebKitColorChooser*); + +#endif // WebKitColorChooserRequestPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenu.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenu.cpp index bbbed0ddc..95c1dd471 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenu.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenu.cpp @@ -24,6 +24,7 @@ #include "WebContextMenuItem.h" #include "WebKitContextMenuItemPrivate.h" #include "WebKitContextMenuPrivate.h" +#include <wtf/glib/GRefPtr.h> using namespace WebKit; using namespace WebCore; @@ -50,6 +51,7 @@ using namespace WebCore; struct _WebKitContextMenuPrivate { GList* items; WebKitContextMenuItem* parentItem; + GRefPtr<GVariant> userData; }; WEBKIT_DEFINE_TYPE(WebKitContextMenu, webkit_context_menu, G_TYPE_OBJECT) @@ -66,21 +68,27 @@ static void webkit_context_menu_class_init(WebKitContextMenuClass* listClass) gObjectClass->dispose = webkitContextMenuDispose; } -void webkitContextMenuPopulate(WebKitContextMenu* menu, Vector<ContextMenuItem>& contextMenuItems) +void webkitContextMenuPopulate(WebKitContextMenu* menu, Vector<WebContextMenuItemData>& contextMenuItems) { for (GList* item = menu->priv->items; item; item = g_list_next(item)) { WebKitContextMenuItem* menuItem = WEBKIT_CONTEXT_MENU_ITEM(item->data); - contextMenuItems.append(ContextMenuItem(webkitContextMenuItemRelease(menuItem))); + contextMenuItems.append(webkitContextMenuItemToWebContextMenuItemData(menuItem)); } } -WebKitContextMenu* webkitContextMenuCreate(API::Array* items) +void webkitContextMenuPopulate(WebKitContextMenu* menu, Vector<WebContextMenuItemGtk>& contextMenuItems) +{ + for (GList* item = menu->priv->items; item; item = g_list_next(item)) { + WebKitContextMenuItem* menuItem = WEBKIT_CONTEXT_MENU_ITEM(item->data); + contextMenuItems.append(webkitContextMenuItemToWebContextMenuItemGtk(menuItem)); + } +} + +WebKitContextMenu* webkitContextMenuCreate(const Vector<WebContextMenuItemData>& items) { WebKitContextMenu* menu = webkit_context_menu_new(); - for (size_t i = 0; i < items->size(); ++i) { - WebContextMenuItem* item = static_cast<WebContextMenuItem*>(items->at(i)); + for (const auto& item : items) webkit_context_menu_prepend(menu, webkitContextMenuItemCreate(item)); - } menu->priv->items = g_list_reverse(menu->priv->items); return menu; @@ -316,3 +324,41 @@ void webkit_context_menu_remove_all(WebKitContextMenu* menu) g_list_free_full(menu->priv->items, reinterpret_cast<GDestroyNotify>(g_object_unref)); menu->priv->items = 0; } + +/** + * webkit_context_menu_set_user_data: + * @menu: a #WebKitContextMenu + * @user_data: a #GVariant + * + * Sets user data to @menu. + * This function can be used from a Web Process extension to set user data + * that can be retrieved from the UI Process using webkit_context_menu_get_user_data(). + * + * Since: 2.8 + */ +void webkit_context_menu_set_user_data(WebKitContextMenu* menu, GVariant* userData) +{ + g_return_if_fail(WEBKIT_IS_CONTEXT_MENU(menu)); + g_return_if_fail(userData); + + menu->priv->userData = userData; +} + +/** + * webkit_context_menu_get_user_data: + * @menu: a #WebKitContextMenu + * + * Gets the user data of @menu. + * This function can be used from the UI Process to get user data previously set + * from the Web Process with webkit_context_menu_set_user_data(). + * + * Returns: (transfer none): the user data of @menu, or %NULL if @menu doesn't have user data + * + * Since: 2.8 + */ +GVariant* webkit_context_menu_get_user_data(WebKitContextMenu* menu) +{ + g_return_val_if_fail(WEBKIT_IS_CONTEXT_MENU(menu), nullptr); + + return menu->priv->userData.get(); +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenu.h b/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenu.h index 22f4bef29..9b50c6470 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenu.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenu.h @@ -17,7 +17,7 @@ * Boston, MA 02110-1301, USA. */ -#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) +#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) && !defined(__WEBKIT_WEB_EXTENSION_H_INSIDE__) #error "Only <webkit2/webkit2.h> can be included directly." #endif @@ -105,6 +105,13 @@ webkit_context_menu_remove (WebKitContextMenu *menu, WEBKIT_API void webkit_context_menu_remove_all (WebKitContextMenu *menu); +WEBKIT_API void +webkit_context_menu_set_user_data (WebKitContextMenu *menu, + GVariant *user_data); + +WEBKIT_API GVariant * +webkit_context_menu_get_user_data (WebKitContextMenu *menu); + G_END_DECLS #endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuActions.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuActions.cpp index e8cdffd04..cf1ddf955 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuActions.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuActions.cpp @@ -135,9 +135,9 @@ ContextMenuAction webkitContextMenuActionGetActionTag(WebKitContextMenuAction ac return ContextMenuItemBaseApplicationTag; } -WebKitContextMenuAction webkitContextMenuActionGetForContextMenuItem(ContextMenuItem* menuItem) +WebKitContextMenuAction webkitContextMenuActionGetForContextMenuItem(const WebKit::WebContextMenuItemGtk& menuItem) { - switch (menuItem->action()) { + switch (menuItem.action()) { case ContextMenuItemTagNoAction: return WEBKIT_CONTEXT_MENU_ACTION_NO_ACTION; case ContextMenuItemTagOpenLink: @@ -182,6 +182,8 @@ WebKitContextMenuAction webkitContextMenuActionGetForContextMenuItem(ContextMenu return WEBKIT_CONTEXT_MENU_ACTION_UNICODE; case ContextMenuItemTagSpellingGuess: return WEBKIT_CONTEXT_MENU_ACTION_SPELLING_GUESS; + case ContextMenuItemTagNoGuessesFound: + return WEBKIT_CONTEXT_MENU_ACTION_NO_GUESSES_FOUND; case ContextMenuItemTagIgnoreSpelling: return WEBKIT_CONTEXT_MENU_ACTION_IGNORE_SPELLING; case ContextMenuItemTagLearnSpelling: @@ -201,10 +203,10 @@ WebKitContextMenuAction webkitContextMenuActionGetForContextMenuItem(ContextMenu case ContextMenuItemTagInspectElement: return WEBKIT_CONTEXT_MENU_ACTION_INSPECT_ELEMENT; case ContextMenuItemTagOpenMediaInNewWindow: - return menuItem->title() == contextMenuItemTagOpenVideoInNewWindow() ? + return menuItem.title() == contextMenuItemTagOpenVideoInNewWindow() ? WEBKIT_CONTEXT_MENU_ACTION_OPEN_VIDEO_IN_NEW_WINDOW : WEBKIT_CONTEXT_MENU_ACTION_OPEN_AUDIO_IN_NEW_WINDOW; case ContextMenuItemTagCopyMediaLinkToClipboard: - return menuItem->title() == contextMenuItemTagCopyVideoLinkToClipboard() ? + return menuItem.title() == contextMenuItemTagCopyVideoLinkToClipboard() ? WEBKIT_CONTEXT_MENU_ACTION_COPY_VIDEO_LINK_TO_CLIPBOARD : WEBKIT_CONTEXT_MENU_ACTION_COPY_AUDIO_LINK_TO_CLIPBOARD; case ContextMenuItemTagToggleMediaControls: return WEBKIT_CONTEXT_MENU_ACTION_TOGGLE_MEDIA_CONTROLS; @@ -213,12 +215,12 @@ WebKitContextMenuAction webkitContextMenuActionGetForContextMenuItem(ContextMenu case ContextMenuItemTagEnterVideoFullscreen: return WEBKIT_CONTEXT_MENU_ACTION_ENTER_VIDEO_FULLSCREEN; case ContextMenuItemTagMediaPlayPause: - return menuItem->title() == contextMenuItemTagMediaPlay() ? + return menuItem.title() == contextMenuItemTagMediaPlay() ? WEBKIT_CONTEXT_MENU_ACTION_MEDIA_PLAY : WEBKIT_CONTEXT_MENU_ACTION_MEDIA_PAUSE; case ContextMenuItemTagMediaMute: return WEBKIT_CONTEXT_MENU_ACTION_MEDIA_MUTE; case ContextMenuItemTagDownloadMediaToDisk: - return menuItem->title() == contextMenuItemTagDownloadVideoToDisk() ? + return menuItem.title() == contextMenuItemTagDownloadVideoToDisk() ? WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_VIDEO_TO_DISK : WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_AUDIO_TO_DISK; case ContextMenuItemBaseApplicationTag: return WEBKIT_CONTEXT_MENU_ACTION_CUSTOM; diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuActions.h b/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuActions.h index c8c9a0dad..cf155e13a 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuActions.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuActions.h @@ -17,7 +17,7 @@ * Boston, MA 02110-1301, USA. */ -#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) +#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) && !defined(__WEBKIT_WEB_EXTENSION_H_INSIDE__) #error "Only <webkit2/webkit2.h> can be included directly." #endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuActionsPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuActionsPrivate.h index f753bb97c..e00b8e2df 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuActionsPrivate.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuActionsPrivate.h @@ -20,12 +20,12 @@ #ifndef WebKitContextMenuActionsPrivate_h #define WebKitContextMenuActionsPrivate_h +#include "WebContextMenuItemGtk.h" #include "WebKitContextMenuActions.h" -#include <WebCore/ContextMenuItem.h> bool webkitContextMenuActionIsCheckable(WebKitContextMenuAction); WebCore::ContextMenuAction webkitContextMenuActionGetActionTag(WebKitContextMenuAction); -WebKitContextMenuAction webkitContextMenuActionGetForContextMenuItem(WebCore::ContextMenuItem*); +WebKitContextMenuAction webkitContextMenuActionGetForContextMenuItem(const WebKit::WebContextMenuItemGtk&); String webkitContextMenuActionGetLabel(WebKitContextMenuAction); #endif // WebKitPrintOperationPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuClient.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuClient.cpp index ea5e42757..6671dc93a 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuClient.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuClient.cpp @@ -20,32 +20,44 @@ #include "config.h" #include "WebKitContextMenuClient.h" -#include "WebKitPrivate.h" +#include "APIContextMenuClient.h" +#include "WebContextMenuItem.h" #include "WebKitWebViewBasePrivate.h" #include "WebKitWebViewPrivate.h" using namespace WebKit; -static void getContextMenuFromProposedMenu(WKPageRef, WKArrayRef proposedMenu, WKArrayRef*, WKHitTestResultRef hitTestResult, WKTypeRef userData, const void* clientInfo) -{ - webkitWebViewPopulateContextMenu(WEBKIT_WEB_VIEW(clientInfo), toImpl(proposedMenu), toImpl(hitTestResult)); -} +class ContextMenuClient final: public API::ContextMenuClient { +public: + explicit ContextMenuClient(WebKitWebView* webView) + : m_webView(webView) + { + } + +private: + bool getContextMenuFromProposedMenu(WebPageProxy&, const Vector<RefPtr<WebContextMenuItem>>& proposedMenu, Vector<RefPtr<WebContextMenuItem>>&, const WebHitTestResultData& hitTestResultData, API::Object* userData) override + { + GRefPtr<GVariant> variant; + if (userData) { + ASSERT(userData->type() == API::Object::Type::String); + CString userDataString = static_cast<API::String*>(userData)->string().utf8(); + variant = adoptGRef(g_variant_parse(nullptr, userDataString.data(), userDataString.data() + userDataString.length(), nullptr, nullptr)); + } + + Vector<WebContextMenuItemData> menuItems; + menuItems.reserveInitialCapacity(proposedMenu.size()); + for (auto& item : proposedMenu) + menuItems.uncheckedAppend(item->data()); + webkitWebViewPopulateContextMenu(m_webView, menuItems, hitTestResultData, variant.get()); + return true; + } + + WebKitWebView* m_webView; +}; void attachContextMenuClientToView(WebKitWebView* webView) { - WKPageContextMenuClientV3 wkContextMenuClient = { - { - 3, // version - webView, // clientInfo - }, - 0, // getContextMenuFromProposedMenu_deprecatedForUseWithV0 - 0, // customContextMenuItemSelected - 0, // contextMenuDismissed - getContextMenuFromProposedMenu, - 0, // showContextMenu - 0, // hideContextMenu - }; - WKPageRef wkPage = toAPI(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView))); - WKPageSetPageContextMenuClient(wkPage, &wkContextMenuClient.base); + WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView)); + page->setContextMenuClient(std::make_unique<ContextMenuClient>(webView)); } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItem.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItem.cpp index c5e4553aa..5a3a47273 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItem.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItem.cpp @@ -22,17 +22,16 @@ #include "APIArray.h" #include "WebContextMenuItem.h" -#include "WebContextMenuItemData.h" +#include "WebContextMenuItemGtk.h" #include "WebKitContextMenuActionsPrivate.h" #include "WebKitContextMenuItemPrivate.h" #include "WebKitContextMenuPrivate.h" #include <WebCore/ContextMenu.h> #include <WebCore/ContextMenuItem.h> #include <gtk/gtk.h> -#include <wtf/OwnPtr.h> -#include <wtf/PassOwnPtr.h> -#include <wtf/gobject/GRefPtr.h> -#include <wtf/gobject/GUniquePtr.h> +#include <memory> +#include <wtf/glib/GRefPtr.h> +#include <wtf/glib/GUniquePtr.h> using namespace WebKit; using namespace WebCore; @@ -57,13 +56,13 @@ struct _WebKitContextMenuItemPrivate { webkitContextMenuSetParentItem(subMenu.get(), 0); } - OwnPtr<ContextMenuItem> menuItem; + std::unique_ptr<WebContextMenuItemGtk> menuItem; GRefPtr<WebKitContextMenu> subMenu; }; WEBKIT_DEFINE_TYPE(WebKitContextMenuItem, webkit_context_menu_item, G_TYPE_INITIALLY_UNOWNED) -static void webkit_context_menu_item_class_init(WebKitContextMenuItemClass* itemClass) +static void webkit_context_menu_item_class_init(WebKitContextMenuItemClass*) { } @@ -85,71 +84,44 @@ static void webkitContextMenuItemSetSubMenu(WebKitContextMenuItem* item, GRefPtr return; if (item->priv->subMenu) - webkitContextMenuSetParentItem(item->priv->subMenu.get(), 0); + webkitContextMenuSetParentItem(item->priv->subMenu.get(), nullptr); item->priv->subMenu = subMenu; if (subMenu) webkitContextMenuSetParentItem(subMenu.get(), item); } -WebKitContextMenuItem* webkitContextMenuItemCreate(WebContextMenuItem* webItem) +WebKitContextMenuItem* webkitContextMenuItemCreate(const WebContextMenuItemData& itemData) { WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, NULL)); - WebContextMenuItemData* itemData = webItem->data(); - item->priv->menuItem = WTF::adoptPtr(new ContextMenuItem(itemData->type(), itemData->action(), itemData->title(), itemData->enabled(), itemData->checked())); - const Vector<WebContextMenuItemData>& subMenu = itemData->submenu(); - if (!subMenu.size()) - return item; - - Vector<RefPtr<API::Object>> subMenuItems; - subMenuItems.reserveInitialCapacity(subMenu.size()); - for (size_t i = 0; i < subMenu.size(); ++i) - subMenuItems.uncheckedAppend(WebContextMenuItem::create(subMenu[i]).get()); - webkitContextMenuItemSetSubMenu(item, adoptGRef(webkitContextMenuCreate(API::Array::create(std::move(subMenuItems)).get()))); - return item; -} - -static WebKitContextMenuItem* webkitContextMenuItemCreateForGtkItem(GtkMenuItem* menuItem) -{ - WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, NULL)); - item->priv->menuItem = WTF::adoptPtr(new ContextMenuItem(menuItem)); - webkitContextMenuItemSetSubMenuFromGtkMenu(item, GTK_MENU(gtk_menu_item_get_submenu(menuItem))); + item->priv->menuItem = std::make_unique<WebContextMenuItemGtk>(itemData); + const Vector<WebContextMenuItemData>& subMenu = itemData.submenu(); + if (!subMenu.isEmpty()) + webkitContextMenuItemSetSubMenu(item, adoptGRef(webkitContextMenuCreate(subMenu))); return item; } -void webkitContextMenuItemSetSubMenuFromGtkMenu(WebKitContextMenuItem* item, GtkMenu* subMenu) +WebContextMenuItemGtk webkitContextMenuItemToWebContextMenuItemGtk(WebKitContextMenuItem* item) { - if (!subMenu) - return; - - GUniquePtr<GList> children(gtk_container_get_children(GTK_CONTAINER(subMenu))); - if (!g_list_length(children.get())) - return; - - webkitContextMenuItemSetSubMenu(item, adoptGRef(webkit_context_menu_new())); - for (GList* listItem = children.get(); listItem; listItem = g_list_next(listItem)) { - GRefPtr<GtkWidget> widget = GTK_WIDGET(listItem->data); - if (!GTK_IS_MENU_ITEM(widget.get())) - continue; - - gtk_container_remove(GTK_CONTAINER(subMenu), widget.get()); - GtkMenuItem* menuItem = GTK_MENU_ITEM(widget.leakRef()); - g_object_force_floating(G_OBJECT(menuItem)); - webkit_context_menu_append(item->priv->subMenu.get(), webkitContextMenuItemCreateForGtkItem(menuItem)); + if (item->priv->subMenu) { + Vector<WebContextMenuItemGtk> subMenuItems; + webkitContextMenuPopulate(item->priv->subMenu.get(), subMenuItems); + return WebContextMenuItemGtk(*item->priv->menuItem, WTFMove(subMenuItems)); } + + return *item->priv->menuItem; } -GtkMenuItem* webkitContextMenuItemRelease(WebKitContextMenuItem* item) +WebContextMenuItemData webkitContextMenuItemToWebContextMenuItemData(WebKitContextMenuItem* item) { if (item->priv->subMenu) { - Vector<ContextMenuItem> subMenuItems; + Vector<WebContextMenuItemData> subMenuItems; webkitContextMenuPopulate(item->priv->subMenu.get(), subMenuItems); - ContextMenu subMenu(platformMenuDescription(subMenuItems)); - item->priv->menuItem->setSubMenu(&subMenu); + return WebContextMenuItemData(item->priv->menuItem->action(), item->priv->menuItem->title(), item->priv->menuItem->enabled(), subMenuItems); } - return item->priv->menuItem->releasePlatformDescription(); + return WebContextMenuItemData(item->priv->menuItem->type(), item->priv->menuItem->action(), item->priv->menuItem->title(), item->priv->menuItem->enabled(), item->priv->menuItem->checked()); } /** @@ -162,11 +134,10 @@ GtkMenuItem* webkitContextMenuItemRelease(WebKitContextMenuItem* item) */ WebKitContextMenuItem* webkit_context_menu_item_new(GtkAction* action) { - g_return_val_if_fail(GTK_IS_ACTION(action), 0); + g_return_val_if_fail(GTK_IS_ACTION(action), nullptr); - WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, NULL)); - item->priv->menuItem = WTF::adoptPtr(new ContextMenuItem(GTK_MENU_ITEM(gtk_action_create_menu_item(action)))); - item->priv->menuItem->setAction(ContextMenuItemBaseApplicationTag); + WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, nullptr)); + item->priv->menuItem = std::make_unique<WebContextMenuItemGtk>(action); return item; } @@ -189,11 +160,11 @@ WebKitContextMenuItem* webkit_context_menu_item_new(GtkAction* action) */ WebKitContextMenuItem* webkit_context_menu_item_new_from_stock_action(WebKitContextMenuAction action) { - g_return_val_if_fail(action > WEBKIT_CONTEXT_MENU_ACTION_NO_ACTION && action < WEBKIT_CONTEXT_MENU_ACTION_CUSTOM, 0); + g_return_val_if_fail(action > WEBKIT_CONTEXT_MENU_ACTION_NO_ACTION && action < WEBKIT_CONTEXT_MENU_ACTION_CUSTOM, nullptr); - WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, NULL)); + WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, nullptr)); ContextMenuItemType type = webkitContextMenuActionIsCheckable(action) ? CheckableActionType : ActionType; - item->priv->menuItem = WTF::adoptPtr(new ContextMenuItem(type, webkitContextMenuActionGetActionTag(action), webkitContextMenuActionGetLabel(action))); + item->priv->menuItem = std::make_unique<WebContextMenuItemGtk>(type, webkitContextMenuActionGetActionTag(action), webkitContextMenuActionGetLabel(action)); return item; } @@ -211,11 +182,11 @@ WebKitContextMenuItem* webkit_context_menu_item_new_from_stock_action(WebKitCont */ WebKitContextMenuItem* webkit_context_menu_item_new_from_stock_action_with_label(WebKitContextMenuAction action, const gchar* label) { - g_return_val_if_fail(action > WEBKIT_CONTEXT_MENU_ACTION_NO_ACTION && action < WEBKIT_CONTEXT_MENU_ACTION_CUSTOM, 0); + g_return_val_if_fail(action > WEBKIT_CONTEXT_MENU_ACTION_NO_ACTION && action < WEBKIT_CONTEXT_MENU_ACTION_CUSTOM, nullptr); - WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, NULL)); + WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, nullptr)); ContextMenuItemType type = webkitContextMenuActionIsCheckable(action) ? CheckableActionType : ActionType; - item->priv->menuItem = WTF::adoptPtr(new ContextMenuItem(type, webkitContextMenuActionGetActionTag(action), String::fromUTF8(label))); + item->priv->menuItem = std::make_unique<WebContextMenuItemGtk>(type, webkitContextMenuActionGetActionTag(action), String::fromUTF8(label)); return item; } @@ -231,14 +202,14 @@ WebKitContextMenuItem* webkit_context_menu_item_new_from_stock_action_with_label */ WebKitContextMenuItem* webkit_context_menu_item_new_with_submenu(const gchar* label, WebKitContextMenu* submenu) { - g_return_val_if_fail(label, 0); - g_return_val_if_fail(WEBKIT_IS_CONTEXT_MENU(submenu), 0); + g_return_val_if_fail(label, nullptr); + g_return_val_if_fail(WEBKIT_IS_CONTEXT_MENU(submenu), nullptr); if (checkAndWarnIfMenuHasParentItem(submenu)) - return 0; + return nullptr; - WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, NULL)); - item->priv->menuItem = WTF::adoptPtr(new ContextMenuItem(SubmenuType, ContextMenuItemBaseApplicationTag, String::fromUTF8(label))); + WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, nullptr)); + item->priv->menuItem = std::make_unique<WebContextMenuItemGtk>(ActionType, ContextMenuItemBaseApplicationTag, String::fromUTF8(label)); item->priv->subMenu = submenu; webkitContextMenuSetParentItem(submenu, item); @@ -254,8 +225,8 @@ WebKitContextMenuItem* webkit_context_menu_item_new_with_submenu(const gchar* la */ WebKitContextMenuItem* webkit_context_menu_item_new_separator(void) { - WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, NULL)); - item->priv->menuItem = WTF::adoptPtr(new ContextMenuItem(SeparatorType, ContextMenuItemTagNoAction, String())); + WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, nullptr)); + item->priv->menuItem = std::make_unique<WebContextMenuItemGtk>(SeparatorType, ContextMenuItemTagNoAction, String()); return item; } @@ -271,7 +242,7 @@ WebKitContextMenuItem* webkit_context_menu_item_new_separator(void) */ GtkAction* webkit_context_menu_item_get_action(WebKitContextMenuItem* item) { - g_return_val_if_fail(WEBKIT_IS_CONTEXT_MENU_ITEM(item), 0); + g_return_val_if_fail(WEBKIT_IS_CONTEXT_MENU_ITEM(item), nullptr); return item->priv->menuItem->gtkAction(); } @@ -291,7 +262,7 @@ WebKitContextMenuAction webkit_context_menu_item_get_stock_action(WebKitContextM { g_return_val_if_fail(WEBKIT_IS_CONTEXT_MENU_ITEM(item), WEBKIT_CONTEXT_MENU_ACTION_NO_ACTION); - return webkitContextMenuActionGetForContextMenuItem(item->priv->menuItem.get()); + return webkitContextMenuActionGetForContextMenuItem(*item->priv->menuItem); } /** diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItem.h b/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItem.h index 75d60d7d6..33e31241a 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItem.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItem.h @@ -17,7 +17,7 @@ * Boston, MA 02110-1301, USA. */ -#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) +#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) && !defined(__WEBKIT_WEB_EXTENSION_H_INSIDE__) #error "Only <webkit2/webkit2.h> can be included directly." #endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItemPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItemPrivate.h index 18f8c1a87..be452fd9e 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItemPrivate.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItemPrivate.h @@ -20,11 +20,12 @@ #ifndef WebKitContextMenuItemPrivate_h #define WebKitContextMenuItemPrivate_h +#include "WebContextMenuItemGtk.h" #include "WebKitContextMenuItem.h" #include "WebKitPrivate.h" -WebKitContextMenuItem* webkitContextMenuItemCreate(WebKit::WebContextMenuItem*); -GtkMenuItem* webkitContextMenuItemRelease(WebKitContextMenuItem*); -void webkitContextMenuItemSetSubMenuFromGtkMenu(WebKitContextMenuItem*, GtkMenu*); +WebKitContextMenuItem* webkitContextMenuItemCreate(const WebKit::WebContextMenuItemData&); +WebKit::WebContextMenuItemGtk webkitContextMenuItemToWebContextMenuItemGtk(WebKitContextMenuItem*); +WebKit::WebContextMenuItemData webkitContextMenuItemToWebContextMenuItemData(WebKitContextMenuItem*); #endif // WebKitContextMenuItemPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuPrivate.h index dcfd16b21..3e4cae7b3 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuPrivate.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuPrivate.h @@ -20,11 +20,13 @@ #ifndef WebKitContextMenuPrivate_h #define WebKitContextMenuPrivate_h +#include "WebContextMenuItemGtk.h" #include "WebKitContextMenu.h" #include "WebKitPrivate.h" -WebKitContextMenu* webkitContextMenuCreate(API::Array* items); -void webkitContextMenuPopulate(WebKitContextMenu*, Vector<WebCore::ContextMenuItem>&); +WebKitContextMenu* webkitContextMenuCreate(const Vector<WebKit::WebContextMenuItemData>&); +void webkitContextMenuPopulate(WebKitContextMenu*, Vector<WebKit::WebContextMenuItemGtk>&); +void webkitContextMenuPopulate(WebKitContextMenu*, Vector<WebKit::WebContextMenuItemData>&); void webkitContextMenuSetParentItem(WebKitContextMenu*, WebKitContextMenuItem*); WebKitContextMenuItem* webkitContextMenuGetParentItem(WebKitContextMenu*); diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitCookieManager.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitCookieManager.cpp index 2c1ef4568..6f47f60e7 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitCookieManager.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitCookieManager.cpp @@ -25,7 +25,7 @@ #include "WebCookieManagerProxy.h" #include "WebKitCookieManagerPrivate.h" #include "WebKitEnumTypes.h" -#include <wtf/gobject/GRefPtr.h> +#include <wtf/glib/GRefPtr.h> #include <wtf/text/CString.h> using namespace WebKit; @@ -65,12 +65,48 @@ static guint signals[LAST_SIGNAL] = { 0, }; WEBKIT_DEFINE_TYPE(WebKitCookieManager, webkit_cookie_manager, G_TYPE_OBJECT) -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT, SoupCookiePersistentStorageText); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_COOKIE_PERSISTENT_STORAGE_SQLITE, SoupCookiePersistentStorageSQLite); +static inline SoupCookiePersistentStorageType toSoupCookiePersistentStorageType(WebKitCookiePersistentStorage kitStorage) +{ + switch (kitStorage) { + case WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT: + return SoupCookiePersistentStorageText; + case WEBKIT_COOKIE_PERSISTENT_STORAGE_SQLITE: + return SoupCookiePersistentStorageSQLite; + default: + ASSERT_NOT_REACHED(); + return SoupCookiePersistentStorageText; + } +} + +static inline WebKitCookieAcceptPolicy toWebKitCookieAcceptPolicy(HTTPCookieAcceptPolicy httpPolicy) +{ + switch (httpPolicy) { + case HTTPCookieAcceptPolicyAlways: + return WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS; + case HTTPCookieAcceptPolicyNever: + return WEBKIT_COOKIE_POLICY_ACCEPT_NEVER; + case HTTPCookieAcceptPolicyOnlyFromMainDocumentDomain: + return WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY; + default: + ASSERT_NOT_REACHED(); + return WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS; + } +} -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS, HTTPCookieAcceptPolicyAlways); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_COOKIE_POLICY_ACCEPT_NEVER, HTTPCookieAcceptPolicyNever); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY, HTTPCookieAcceptPolicyOnlyFromMainDocumentDomain); +static inline HTTPCookieAcceptPolicy toHTTPCookieAcceptPolicy(WebKitCookieAcceptPolicy kitPolicy) +{ + switch (kitPolicy) { + case WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS: + return HTTPCookieAcceptPolicyAlways; + case WEBKIT_COOKIE_POLICY_ACCEPT_NEVER: + return HTTPCookieAcceptPolicyNever; + case WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY: + return HTTPCookieAcceptPolicyOnlyFromMainDocumentDomain; + default: + ASSERT_NOT_REACHED(); + return HTTPCookieAcceptPolicyAlways; + } +} static void webkit_cookie_manager_class_init(WebKitCookieManagerClass* findClass) { @@ -134,7 +170,7 @@ void webkit_cookie_manager_set_persistent_storage(WebKitCookieManager* manager, g_return_if_fail(filename); manager->priv->webCookieManager->stopObservingCookieChanges(); - manager->priv->webCookieManager->setCookiePersistentStorage(String::fromUTF8(filename), storage); + manager->priv->webCookieManager->setCookiePersistentStorage(String::fromUTF8(filename), toSoupCookiePersistentStorageType(storage)); manager->priv->webCookieManager->startObservingCookieChanges(); } @@ -149,13 +185,13 @@ void webkit_cookie_manager_set_accept_policy(WebKitCookieManager* manager, WebKi { g_return_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager)); - manager->priv->webCookieManager->setHTTPCookieAcceptPolicy(policy); + manager->priv->webCookieManager->setHTTPCookieAcceptPolicy(toHTTPCookieAcceptPolicy(policy)); } static void webkitCookieManagerGetAcceptPolicyCallback(WKHTTPCookieAcceptPolicy policy, WKErrorRef, void* context) { GRefPtr<GTask> task = adoptGRef(G_TASK(context)); - g_task_return_int(task.get(), policy); + g_task_return_int(task.get(), toWebKitCookieAcceptPolicy(toHTTPCookieAcceptPolicy(policy))); } /** @@ -175,7 +211,7 @@ void webkit_cookie_manager_get_accept_policy(WebKitCookieManager* manager, GCanc g_return_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager)); GTask* task = g_task_new(manager, cancellable, callback, userData); - manager->priv->webCookieManager->getHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicyCallback::create(task, webkitCookieManagerGetAcceptPolicyCallback)); + manager->priv->webCookieManager->getHTTPCookieAcceptPolicy(toGenericCallbackFunction<WKHTTPCookieAcceptPolicy, HTTPCookieAcceptPolicy>(task, webkitCookieManagerGetAcceptPolicyCallback)); } /** @@ -233,7 +269,7 @@ void webkit_cookie_manager_get_domains_with_cookies(WebKitCookieManager* manager g_return_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager)); GTask* task = g_task_new(manager, cancellable, callback, userData); - manager->priv->webCookieManager->getHostnamesWithCookies(ArrayCallback::create(task, webkitCookieManagerGetDomainsWithCookiesCallback)); + manager->priv->webCookieManager->getHostnamesWithCookies(toGenericCallbackFunction(task, webkitCookieManagerGetDomainsWithCookiesCallback)); } /** diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitCredential.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitCredential.cpp index 5755fd5c7..a23e7e84b 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitCredential.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitCredential.cpp @@ -37,15 +37,41 @@ struct _WebKitCredential { CString password; }; -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_CREDENTIAL_PERSISTENCE_NONE, WebCore::CredentialPersistenceNone); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_CREDENTIAL_PERSISTENCE_FOR_SESSION, WebCore::CredentialPersistenceForSession); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_CREDENTIAL_PERSISTENCE_PERMANENT, WebCore::CredentialPersistencePermanent); - G_DEFINE_BOXED_TYPE(WebKitCredential, webkit_credential, webkit_credential_copy, webkit_credential_free) +static inline WebKitCredentialPersistence toWebKitCredentialPersistence(WebCore::CredentialPersistence corePersistence) +{ + switch (corePersistence) { + case WebCore::CredentialPersistenceNone: + return WEBKIT_CREDENTIAL_PERSISTENCE_NONE; + case WebCore::CredentialPersistenceForSession: + return WEBKIT_CREDENTIAL_PERSISTENCE_FOR_SESSION; + case WebCore::CredentialPersistencePermanent: + return WEBKIT_CREDENTIAL_PERSISTENCE_PERMANENT; + default: + ASSERT_NOT_REACHED(); + return WEBKIT_CREDENTIAL_PERSISTENCE_NONE; + } +} + +static inline WebCore::CredentialPersistence toWebCoreCredentialPersistence(WebKitCredentialPersistence kitPersistence) +{ + switch (kitPersistence) { + case WEBKIT_CREDENTIAL_PERSISTENCE_NONE: + return WebCore::CredentialPersistenceNone; + case WEBKIT_CREDENTIAL_PERSISTENCE_FOR_SESSION: + return WebCore::CredentialPersistenceForSession; + case WEBKIT_CREDENTIAL_PERSISTENCE_PERMANENT: + return WebCore::CredentialPersistencePermanent; + default: + ASSERT_NOT_REACHED(); + return WebCore::CredentialPersistenceNone; + } +} + WebKitCredential* webkitCredentialCreate(const WebCore::Credential& coreCredential) { - WebKitCredential* credential = g_slice_new(WebKitCredential); + WebKitCredential* credential = static_cast<WebKitCredential*>(fastMalloc(sizeof(WebKitCredential))); new (credential) WebKitCredential(coreCredential); return credential; } @@ -73,7 +99,7 @@ WebKitCredential* webkit_credential_new(const gchar* username, const gchar* pass g_return_val_if_fail(username, 0); g_return_val_if_fail(password, 0); - return webkitCredentialCreate(WebCore::Credential(String::fromUTF8(username), String::fromUTF8(password), static_cast<WebCore::CredentialPersistence>(persistence))); + return webkitCredentialCreate(WebCore::Credential(String::fromUTF8(username), String::fromUTF8(password), toWebCoreCredentialPersistence(persistence))); } /** @@ -106,7 +132,7 @@ void webkit_credential_free(WebKitCredential* credential) g_return_if_fail(credential); credential->~WebKitCredential(); - g_slice_free(WebKitCredential, credential); + fastFree(credential); } /** @@ -178,5 +204,5 @@ WebKitCredentialPersistence webkit_credential_get_persistence(WebKitCredential* { g_return_val_if_fail(credential, WEBKIT_CREDENTIAL_PERSISTENCE_NONE); - return static_cast<WebKitCredentialPersistence>(credential->credential.persistence()); + return toWebKitCredentialPersistence(credential->credential.persistence()); } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitDefines.h b/Source/WebKit2/UIProcess/API/gtk/WebKitDefines.h index 8b637652b..520e9957c 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitDefines.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitDefines.h @@ -38,10 +38,11 @@ # else # define WEBKIT_API __declspec(dllimport) # endif -# define WEBKIT_OBSOLETE_API WEBKIT_API #else # define WEBKIT_API __attribute__((visibility("default"))) -# define WEBKIT_OBSOLETE_API WEBKIT_API __attribute__((deprecated)) #endif +#define WEBKIT_DEPRECATED WEBKIT_API G_DEPRECATED +#define WEBKIT_DEPRECATED_FOR(f) WEBKIT_API G_DEPRECATED_FOR(f) + #endif // WebKitDefines_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp index e95e4c065..86c05b2f2 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Igalia S.L. + * Copyright (C) 2012, 2014 Igalia S.L. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -23,13 +23,14 @@ #include "DownloadProxy.h" #include "WebKitDownloadPrivate.h" #include "WebKitMarshal.h" +#include "WebKitPrivate.h" #include "WebKitURIRequestPrivate.h" #include "WebKitURIResponsePrivate.h" #include <WebCore/ErrorsGtk.h> #include <WebCore/ResourceResponse.h> #include <glib/gi18n-lib.h> -#include <wtf/gobject/GRefPtr.h> -#include <wtf/gobject/GUniquePtr.h> +#include <wtf/glib/GRefPtr.h> +#include <wtf/glib/GUniquePtr.h> using namespace WebKit; using namespace WebCore; @@ -62,7 +63,8 @@ enum { PROP_DESTINATION, PROP_RESPONSE, - PROP_ESTIMATED_PROGRESS + PROP_ESTIMATED_PROGRESS, + PROP_ALLOW_OVERWRITE }; struct _WebKitDownloadPrivate { @@ -83,12 +85,26 @@ struct _WebKitDownloadPrivate { GUniquePtr<GTimer> timer; gdouble lastProgress; gdouble lastElapsed; + bool allowOverwrite; }; static guint signals[LAST_SIGNAL] = { 0, }; WEBKIT_DEFINE_TYPE(WebKitDownload, webkit_download, G_TYPE_OBJECT) +static void webkitDownloadSetProperty(GObject* object, guint propId, const GValue* value, GParamSpec* paramSpec) +{ + WebKitDownload* download = WEBKIT_DOWNLOAD(object); + + switch (propId) { + case PROP_ALLOW_OVERWRITE: + webkit_download_set_allow_overwrite(download, g_value_get_boolean(value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); + } +} + static void webkitDownloadGetProperty(GObject* object, guint propId, GValue* value, GParamSpec* paramSpec) { WebKitDownload* download = WEBKIT_DOWNLOAD(object); @@ -103,6 +119,9 @@ static void webkitDownloadGetProperty(GObject* object, guint propId, GValue* val case PROP_ESTIMATED_PROGRESS: g_value_set_double(value, webkit_download_get_estimated_progress(download)); break; + case PROP_ALLOW_OVERWRITE: + g_value_set_boolean(value, webkit_download_get_allow_overwrite(download)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); } @@ -129,6 +148,7 @@ static gboolean webkitDownloadDecideDestination(WebKitDownload* download, const static void webkit_download_class_init(WebKitDownloadClass* downloadClass) { GObjectClass* objectClass = G_OBJECT_CLASS(downloadClass); + objectClass->set_property = webkitDownloadSetProperty; objectClass->get_property = webkitDownloadGetProperty; downloadClass->decide_destination = webkitDownloadDecideDestination; @@ -178,6 +198,25 @@ static void webkit_download_class_init(WebKitDownloadClass* downloadClass) WEBKIT_PARAM_READABLE)); /** + * WebKitDownload:allow-overwrite: + * + * Whether or not the download is allowed to overwrite an existing file on + * disk. If this property is %FALSE and the destination already exists, + * the download will fail. + * + * Since: 2.6 + */ + g_object_class_install_property( + objectClass, + PROP_ALLOW_OVERWRITE, + g_param_spec_boolean( + "allow-overwrite", + _("Allow Overwrite"), + _("Whether the destination may be overwritten"), + FALSE, + WEBKIT_PARAM_READWRITE)); + + /** * WebKitDownload::received-data: * @download: the #WebKitDownload * @data_length: the length of data received in bytes @@ -223,13 +262,14 @@ static void webkit_download_class_init(WebKitDownloadClass* downloadClass) * after an error and #WebKitDownload::finished signal is emitted after this one. */ signals[FAILED] = - g_signal_new("failed", - G_TYPE_FROM_CLASS(objectClass), - G_SIGNAL_RUN_LAST, - 0, 0, 0, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, - G_TYPE_POINTER); + g_signal_new( + "failed", + G_TYPE_FROM_CLASS(objectClass), + G_SIGNAL_RUN_LAST, + 0, 0, 0, + g_cclosure_marshal_VOID__BOXED, + G_TYPE_NONE, 1, + G_TYPE_ERROR | G_SIGNAL_TYPE_STATIC_SCOPE); /** * WebKitDownload::decide-destination: @@ -340,7 +380,7 @@ void webkitDownloadNotifyProgress(WebKitDownload* download, guint64 bytesReceive void webkitDownloadFailed(WebKitDownload* download, const ResourceError& resourceError) { GUniquePtr<GError> webError(g_error_new_literal(g_quark_from_string(resourceError.domain().utf8().data()), - resourceError.errorCode(), resourceError.localizedDescription().utf8().data())); + toWebKitError(resourceError.errorCode()), resourceError.localizedDescription().utf8().data())); if (download->priv->timer) g_timer_stop(download->priv->timer.get()); @@ -369,12 +409,13 @@ void webkitDownloadFinished(WebKitDownload* download) g_signal_emit(download, signals[FINISHED], 0, NULL); } -CString webkitDownloadDecideDestinationWithSuggestedFilename(WebKitDownload* download, const CString& suggestedFilename) +CString webkitDownloadDecideDestinationWithSuggestedFilename(WebKitDownload* download, const CString& suggestedFilename, bool& allowOverwrite) { if (download->priv->isCancelled) return ""; gboolean returnValue; g_signal_emit(download, signals[DECIDE_DESTINATION], 0, suggestedFilename.data(), &returnValue); + allowOverwrite = download->priv->allowOverwrite; return download->priv->destinationURI; } @@ -567,3 +608,44 @@ WebKitWebView* webkit_download_get_web_view(WebKitDownload* download) return download->priv->webView; } + +/** + * webkit_download_get_allow_overwrite: + * @download: a #WebKitDownload + * + * Returns the current value of the #WebKitDownload:allow-overwrite property, + * which determines whether the download will overwrite an existing file on + * disk, or if it will fail if the destination already exists. + * + * Returns: the current value of the #WebKitDownload:allow-overwrite property + * + * Since: 2.6 + */ +gboolean webkit_download_get_allow_overwrite(WebKitDownload* download) +{ + g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), FALSE); + + return download->priv->allowOverwrite; +} + +/** + * webkit_download_set_allow_overwrite: + * @download: a #WebKitDownload + * @allowed: the new value for the #WebKitDownload:allow-overwrite property + * + * Sets the #WebKitDownload:allow-overwrite property, which determines whether + * the download may overwrite an existing file on disk, or if it will fail if + * the destination already exists. + * + * Since: 2.6 + */ +void webkit_download_set_allow_overwrite(WebKitDownload* download, gboolean allowed) +{ + g_return_if_fail(WEBKIT_IS_DOWNLOAD(download)); + + if (allowed == download->priv->allowOverwrite) + return; + + download->priv->allowOverwrite = allowed; + g_object_notify(G_OBJECT(download), "allow-overwrite"); +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.h b/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.h index 493bfea40..7e6bfeb46 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.h @@ -92,6 +92,13 @@ webkit_download_get_received_data_length (WebKitDownload *download); WEBKIT_API WebKitWebView * webkit_download_get_web_view (WebKitDownload *download); +WEBKIT_API gboolean +webkit_download_get_allow_overwrite (WebKitDownload *download); + +WEBKIT_API void +webkit_download_set_allow_overwrite (WebKitDownload *download, + gboolean allowed); + G_END_DECLS #endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadClient.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadClient.cpp index 198cc68f9..02abf6642 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadClient.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadClient.cpp @@ -21,12 +21,12 @@ #include "WebKitDownloadClient.h" #include "APIURLResponse.h" -#include "WebContext.h" #include "WebKitDownloadPrivate.h" #include "WebKitURIResponsePrivate.h" #include "WebKitWebContextPrivate.h" -#include <WebKit2/WKString.h> -#include <wtf/gobject/GRefPtr.h> +#include "WebProcessPool.h" +#include <WebKit/WKString.h> +#include <wtf/glib/GRefPtr.h> #include <wtf/text/CString.h> using namespace WebCore; @@ -38,7 +38,7 @@ static void didStart(WKContextRef, WKDownloadRef wkDownload, const void* clientI webkitWebContextDownloadStarted(WEBKIT_WEB_CONTEXT(clientInfo), download.get()); } -static void didReceiveResponse(WKContextRef, WKDownloadRef wkDownload, WKURLResponseRef wkResponse, const void* clientInfo) +static void didReceiveResponse(WKContextRef, WKDownloadRef wkDownload, WKURLResponseRef wkResponse, const void* /* clientInfo */) { GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(toImpl(wkDownload)); if (webkitDownloadIsCancelled(download.get())) @@ -48,27 +48,26 @@ static void didReceiveResponse(WKContextRef, WKDownloadRef wkDownload, WKURLResp webkitDownloadSetResponse(download.get(), response.get()); } -static void didReceiveData(WKContextRef, WKDownloadRef wkDownload, uint64_t length, const void* clientInfo) +static void didReceiveData(WKContextRef, WKDownloadRef wkDownload, uint64_t length, const void* /* clientInfo */) { GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(toImpl(wkDownload)); webkitDownloadNotifyProgress(download.get(), length); } -static WKStringRef decideDestinationWithSuggestedFilename(WKContextRef, WKDownloadRef wkDownload, WKStringRef filename, bool* allowOverwrite, const void* clientInfo) +static WKStringRef decideDestinationWithSuggestedFilename(WKContextRef, WKDownloadRef wkDownload, WKStringRef filename, bool* allowOverwrite, const void* /* clientInfo */) { GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(toImpl(wkDownload)); - CString destinationURI = webkitDownloadDecideDestinationWithSuggestedFilename(download.get(), - toImpl(filename)->string().utf8()); + CString destinationURI = webkitDownloadDecideDestinationWithSuggestedFilename(download.get(), toImpl(filename)->string().utf8(), *allowOverwrite); return WKStringCreateWithUTF8CString(destinationURI.data()); } -static void didCreateDestination(WKContextRef, WKDownloadRef wkDownload, WKStringRef path, const void* clientInfo) +static void didCreateDestination(WKContextRef, WKDownloadRef wkDownload, WKStringRef path, const void* /* clientInfo */) { GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(toImpl(wkDownload)); webkitDownloadDestinationCreated(download.get(), toImpl(path)->string().utf8()); } -static void didFail(WKContextRef, WKDownloadRef wkDownload, WKErrorRef error, const void *clientInfo) +static void didFail(WKContextRef, WKDownloadRef wkDownload, WKErrorRef error, const void* /* clientInfo */) { GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(toImpl(wkDownload)); if (webkitDownloadIsCancelled(download.get())) { @@ -79,14 +78,14 @@ static void didFail(WKContextRef, WKDownloadRef wkDownload, WKErrorRef error, co webkitWebContextRemoveDownload(toImpl(wkDownload)); } -static void didCancel(WKContextRef, WKDownloadRef wkDownload, const void *clientInfo) +static void didCancel(WKContextRef, WKDownloadRef wkDownload, const void* /* clientInfo */) { GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(toImpl(wkDownload)); webkitDownloadCancelled(download.get()); webkitWebContextRemoveDownload(toImpl(wkDownload)); } -static void didFinish(WKContextRef wkContext, WKDownloadRef wkDownload, const void *clientInfo) +static void didFinish(WKContextRef, WKDownloadRef wkDownload, const void* /* clientInfo */) { GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(toImpl(wkDownload)); webkitDownloadFinished(download.get()); @@ -112,6 +111,6 @@ void attachDownloadClientToContext(WebKitWebContext* webContext) didCancel, 0, // processDidCrash }; - WKContextSetDownloadClient(toAPI(webkitWebContextGetContext(webContext)), &wkDownloadClient.base); + WKContextSetDownloadClient(toAPI(webkitWebContextGetProcessPool(webContext)), &wkDownloadClient.base); } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadPrivate.h index 980ad732b..b986ca231 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadPrivate.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadPrivate.h @@ -35,7 +35,7 @@ void webkitDownloadNotifyProgress(WebKitDownload*, guint64 bytesReceived); void webkitDownloadFailed(WebKitDownload*, const WebCore::ResourceError&); void webkitDownloadCancelled(WebKitDownload*); void webkitDownloadFinished(WebKitDownload*); -CString webkitDownloadDecideDestinationWithSuggestedFilename(WebKitDownload*, const CString& suggestedFilename); +CString webkitDownloadDecideDestinationWithSuggestedFilename(WebKitDownload*, const CString& suggestedFilename, bool& allowOverwrite); void webkitDownloadDestinationCreated(WebKitDownload*, const CString& destinationURI); #endif // WebKitDownloadPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitEditingCommands.h b/Source/WebKit2/UIProcess/API/gtk/WebKitEditingCommands.h index 437395710..a3bd0fab6 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitEditingCommands.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitEditingCommands.h @@ -94,6 +94,31 @@ G_BEGIN_DECLS */ #define WEBKIT_EDITING_COMMAND_REDO "Redo" +/** + * WEBKIT_EDITING_COMMAND_INSERT_IMAGE: + * + * The insert image command. Creates an image element that is inserted at + * the current cursor position. It receives an URI as argument, + * that is used as the image source. This command should be executed with + * webkit_web_view_execute_editing_command_with_argument(). + * + * Since: 2.10 + */ +#define WEBKIT_EDITING_COMMAND_INSERT_IMAGE "InsertImage" + +/** + * WEBKIT_EDITING_COMMAND_CREATE_LINK: + * + * The create link command. Creates a link elment thst is inserted at + * the current cursor position. If there's a selection, the selected text + * will be used as the link text, otherwise the URL itself will be used. + * It receives the link URL as argument. This command should be executed + * with webkit_web_view_execute_editing_command_with_argument() + * + * Since: 2.10 + */ +#define WEBKIT_EDITING_COMMAND_CREATE_LINK "CreateLink" + G_END_DECLS #endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitEditorState.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitEditorState.cpp new file mode 100644 index 000000000..97d1f8a17 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitEditorState.cpp @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2015 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "WebKitEditorState.h" + +#include "EditorState.h" +#include "WebKitEditorStatePrivate.h" +#include <glib/gi18n-lib.h> + +using namespace WebKit; + +/** + * SECTION: WebKitEditorState + * @Short_description: Web editor state + * @Title: WebKitEditorState + * @See_also: #WebKitWebView + * + * WebKitEditorState represents the state of a #WebKitWebView editor. + * Use webkit_web_view_get_editor_state() to get WebKitEditorState of + * a #WebKitWebView. + * + * Since: 2.10 + */ + +enum { + PROP_0, + + PROP_TYPING_ATTRIBUTES +}; + +struct _WebKitEditorStatePrivate { + unsigned typingAttributes; +}; + +WEBKIT_DEFINE_TYPE(WebKitEditorState, webkit_editor_state, G_TYPE_OBJECT) + +static void webkitEditorStateGetProperty(GObject* object, guint propId, GValue* value, GParamSpec* paramSpec) +{ + WebKitEditorState* editorState = WEBKIT_EDITOR_STATE(object); + + switch (propId) { + case PROP_TYPING_ATTRIBUTES: + g_value_set_uint(value, webkit_editor_state_get_typing_attributes(editorState)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); + } +} + +static void webkit_editor_state_class_init(WebKitEditorStateClass* editorStateClass) +{ + GObjectClass* objectClass = G_OBJECT_CLASS(editorStateClass); + objectClass->get_property = webkitEditorStateGetProperty; + + /** + * WebKitEditorState:typing-attributes: + * + * Bitmask of #WebKitEditorTypingAttributes flags. + * See webkit_editor_state_get_typing_attributes() for more information. + * + * Since: 2.10 + */ + g_object_class_install_property( + objectClass, + PROP_TYPING_ATTRIBUTES, + g_param_spec_uint( + "typing-attributes", + _("Typing Attributes"), + _("Flags with the typing attributes"), + 0, G_MAXUINT, 0, + WEBKIT_PARAM_READABLE)); +} + +static void webkitEditorStateSetTypingAttributes(WebKitEditorState* editorState, unsigned typingAttributes) +{ + if (typingAttributes == editorState->priv->typingAttributes) + return; + + editorState->priv->typingAttributes = typingAttributes; + g_object_notify(G_OBJECT(editorState), "typing-attributes"); +} + +WebKitEditorState* webkitEditorStateCreate(const EditorState& state) +{ + WebKitEditorState* editorState = WEBKIT_EDITOR_STATE(g_object_new(WEBKIT_TYPE_EDITOR_STATE, nullptr)); + webkitEditorStateChanged(editorState, state); + return editorState; +} + +void webkitEditorStateChanged(WebKitEditorState* editorState, const EditorState& newState) +{ + if (newState.isMissingPostLayoutData) + return; + + unsigned typingAttributes = WEBKIT_EDITOR_TYPING_ATTRIBUTE_NONE; + const auto& postLayoutData = newState.postLayoutData(); + if (postLayoutData.typingAttributes & AttributeBold) + typingAttributes |= WEBKIT_EDITOR_TYPING_ATTRIBUTE_BOLD; + if (postLayoutData.typingAttributes & AttributeItalics) + typingAttributes |= WEBKIT_EDITOR_TYPING_ATTRIBUTE_ITALIC; + if (postLayoutData.typingAttributes & AttributeUnderline) + typingAttributes |= WEBKIT_EDITOR_TYPING_ATTRIBUTE_UNDERLINE; + if (postLayoutData.typingAttributes & AttributeStrikeThrough) + typingAttributes |= WEBKIT_EDITOR_TYPING_ATTRIBUTE_STRIKETHROUGH; + webkitEditorStateSetTypingAttributes(editorState, typingAttributes); +} + +/** + * webkit_editor_state_get_typing_attributes: + * @editor_state: a #WebKitEditorState + * + * Gets the typing attributes at the current cursor position. + * If there is a selection, this returns the typing attributes + * of the the selected text. Note that in case of a selection, + * typing attributes are considered active only when they are + * present throughout the selection. + * + * Returns: a bitmask of #WebKitEditorTypingAttributes flags + * + * Since: 2.10 + */ +guint webkit_editor_state_get_typing_attributes(WebKitEditorState* editorState) +{ + g_return_val_if_fail(WEBKIT_IS_EDITOR_STATE(editorState), WEBKIT_EDITOR_TYPING_ATTRIBUTE_NONE); + + return editorState->priv->typingAttributes; +} + diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitEditorState.h b/Source/WebKit2/UIProcess/API/gtk/WebKitEditorState.h new file mode 100644 index 000000000..d0d8351ff --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitEditorState.h @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2015 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) && !defined(__WEBKIT_WEB_EXTENSION_H_INSIDE__) +#error "Only <webkit2/webkit2.h> can be included directly." +#endif + +#ifndef WebKitEditorState_h +#define WebKitEditorState_h + +#include <glib-object.h> +#include <webkit2/WebKitDefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_EDITOR_STATE (webkit_editor_state_get_type()) +#define WEBKIT_EDITOR_STATE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_EDITOR_STATE, WebKitEditorState)) +#define WEBKIT_IS_EDITOR_STATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_EDITOR_STATE)) +#define WEBKIT_EDITOR_STATE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_EDITOR_STATE, WebKitEditorStateClass)) +#define WEBKIT_IS_EDITOR_STATE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_EDITOR_STATE)) +#define WEBKIT_EDITOR_STATE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_EDITOR_STATE, WebKitEditorStateClass)) + +typedef struct _WebKitEditorState WebKitEditorState; +typedef struct _WebKitEditorStateClass WebKitEditorStateClass; +typedef struct _WebKitEditorStatePrivate WebKitEditorStatePrivate; + +/** + * WebKitEditorTypingAttributes: + * @WEBKIT_EDITOR_TYPING_ATTRIBUTE_NONE: No typing attrubutes. + * @WEBKIT_EDITOR_TYPING_ATTRIBUTE_BOLD: Bold typing attribute. + * @WEBKIT_EDITOR_TYPING_ATTRIBUTE_ITALIC: Italic typing attribute. + * @WEBKIT_EDITOR_TYPING_ATTRIBUTE_UNDERLINE: Underline typing attribute. + * @WEBKIT_EDITOR_TYPING_ATTRIBUTE_STRIKETHROUGH: Strikethrough typing attribute. + * + * Enum values with flags representing typing attributes. + * + * Since: 2.10 + */ +typedef enum +{ + WEBKIT_EDITOR_TYPING_ATTRIBUTE_NONE = 1 << 1, + WEBKIT_EDITOR_TYPING_ATTRIBUTE_BOLD = 1 << 2, + WEBKIT_EDITOR_TYPING_ATTRIBUTE_ITALIC = 1 << 3, + WEBKIT_EDITOR_TYPING_ATTRIBUTE_UNDERLINE = 1 << 4, + WEBKIT_EDITOR_TYPING_ATTRIBUTE_STRIKETHROUGH = 1 << 5 +} WebKitEditorTypingAttributes; + +struct _WebKitEditorState { + GObject parent; + + WebKitEditorStatePrivate *priv; +}; + +struct _WebKitEditorStateClass { + GObjectClass parent_class; + + void (*_webkit_reserved0) (void); + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); +}; + +WEBKIT_API GType +webkit_editor_state_get_type (void); + +WEBKIT_API guint +webkit_editor_state_get_typing_attributes (WebKitEditorState *editor_state); + +G_END_DECLS + +#endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitCertificateInfoPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitEditorStatePrivate.h index ab3f1ef39..fdf9a35f5 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitCertificateInfoPrivate.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitEditorStatePrivate.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Samsung Electronics Inc. All rights reserved. + * Copyright (C) 2015 Igalia S.L. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -17,27 +17,13 @@ * Boston, MA 02110-1301, USA. */ -#ifndef WebKitCertificateInfoPrivate_h -#define WebKitCertificateInfoPrivate_h +#ifndef WebKitEditorStatePrivate_h +#define WebKitEditorStatePrivate_h -#include "WebKitCertificateInfo.h" +#include "WebKitEditorState.h" #include "WebKitPrivate.h" -#include <WebCore/CertificateInfo.h> -struct _WebKitCertificateInfo { - _WebKitCertificateInfo(GTlsCertificate* certificate, GTlsCertificateFlags tlsErrors) - : certificateInfo(certificate, tlsErrors) - { - } +WebKitEditorState* webkitEditorStateCreate(const WebKit::EditorState&); +void webkitEditorStateChanged(WebKitEditorState*, const WebKit::EditorState&); - _WebKitCertificateInfo(WebKitCertificateInfo* info) - : certificateInfo(info->certificateInfo) - { - } - - WebCore::CertificateInfo certificateInfo; -}; - -const WebCore::CertificateInfo& webkitCertificateInfoGetCertificateInfo(WebKitCertificateInfo*); - -#endif // WebKitCertificateInfoPrivate_h +#endif // WebKitEditorStatePrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitError.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitError.cpp index c06dc61a5..7419ee721 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitError.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitError.cpp @@ -40,53 +40,26 @@ GQuark webkit_network_error_quark() return g_quark_from_static_string(WebCore::errorDomainNetwork); } -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_NETWORK_ERROR_FAILED, NetworkErrorFailed); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_NETWORK_ERROR_TRANSPORT, NetworkErrorTransport); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_NETWORK_ERROR_UNKNOWN_PROTOCOL, NetworkErrorUnknownProtocol); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_NETWORK_ERROR_CANCELLED, NetworkErrorCancelled); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_NETWORK_ERROR_FILE_DOES_NOT_EXIST, NetworkErrorFileDoesNotExist); - GQuark webkit_policy_error_quark() { return g_quark_from_static_string(WebCore::errorDomainPolicy); } -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_POLICY_ERROR_FAILED, PolicyErrorFailed); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_POLICY_ERROR_CANNOT_SHOW_MIME_TYPE, PolicyErrorCannotShowMimeType); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_POLICY_ERROR_CANNOT_SHOW_URI, PolicyErrorCannotShowURL); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_POLICY_ERROR_FRAME_LOAD_INTERRUPTED_BY_POLICY_CHANGE, PolicyErrorFrameLoadInterruptedByPolicyChange); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_POLICY_ERROR_CANNOT_USE_RESTRICTED_PORT, PolicyErrorCannotUseRestrictedPort); - GQuark webkit_plugin_error_quark() { return g_quark_from_static_string(WebCore::errorDomainPlugin); } -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_PLUGIN_ERROR_FAILED, PluginErrorFailed); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_PLUGIN_ERROR_CANNOT_FIND_PLUGIN, PluginErrorCannotFindPlugin); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_PLUGIN_ERROR_CANNOT_LOAD_PLUGIN, PluginErrorCannotLoadPlugin); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_PLUGIN_ERROR_JAVA_UNAVAILABLE, PluginErrorJavaUnavailable); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_PLUGIN_ERROR_CONNECTION_CANCELLED, PluginErrorConnectionCancelled); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_PLUGIN_ERROR_WILL_HANDLE_LOAD, PluginErrorWillHandleLoad); - GQuark webkit_download_error_quark() { return g_quark_from_static_string(WebCore::errorDomainDownload); } -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_DOWNLOAD_ERROR_NETWORK, DownloadErrorNetwork); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_DOWNLOAD_ERROR_CANCELLED_BY_USER, DownloadErrorCancelledByUser); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_DOWNLOAD_ERROR_DESTINATION, DownloadErrorDestination); - GQuark webkit_print_error_quark() { return g_quark_from_static_string(WebCore::errorDomainPrint); } -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_PRINT_ERROR_GENERAL, PrintErrorGeneral); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_PRINT_ERROR_PRINTER_NOT_FOUND, PrintErrorPrinterNotFound); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_PRINT_ERROR_INVALID_PAGE_RANGE, PrintErrorInvalidPageRange); - GQuark webkit_javascript_error_quark() { return g_quark_from_static_string("WebKitJavascriptError"); diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitFaviconDatabase.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitFaviconDatabase.cpp index 0eda2729e..80ac15a72 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitFaviconDatabase.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitFaviconDatabase.cpp @@ -29,8 +29,8 @@ #include <WebCore/RefPtrCairo.h> #include <glib/gi18n-lib.h> #include <wtf/RunLoop.h> -#include <wtf/gobject/GRefPtr.h> -#include <wtf/gobject/GUniquePtr.h> +#include <wtf/glib/GRefPtr.h> +#include <wtf/glib/GUniquePtr.h> #include <wtf/text/CString.h> using namespace WebKit; @@ -181,7 +181,7 @@ static void processPendingIconsForPageURL(WebKitFaviconDatabase* database, const deletePendingIconRequests(database, pendingIconRequests, pageURL); } -static void didChangeIconForPageURLCallback(WKIconDatabaseRef wkIconDatabase, WKURLRef wkPageURL, const void* clientInfo) +static void didChangeIconForPageURLCallback(WKIconDatabaseRef, WKURLRef wkPageURL, const void* clientInfo) { WebKitFaviconDatabase* database = WEBKIT_FAVICON_DATABASE(clientInfo); if (!database->priv->iconDatabase->isUrlImportCompleted()) @@ -203,7 +203,7 @@ static void didChangeIconForPageURLCallback(WKIconDatabaseRef wkIconDatabase, WK g_signal_emit(database, signals[FAVICON_CHANGED], 0, pageURL.utf8().data(), currentIconURL.utf8().data()); } -static void iconDataReadyForPageURLCallback(WKIconDatabaseRef wkIconDatabase, WKURLRef wkPageURL, const void* clientInfo) +static void iconDataReadyForPageURLCallback(WKIconDatabaseRef, WKURLRef wkPageURL, const void* clientInfo) { ASSERT(RunLoop::isMain()); processPendingIconsForPageURL(WEBKIT_FAVICON_DATABASE(clientInfo), toImpl(wkPageURL)->string()); diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitFileChooserRequest.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitFileChooserRequest.cpp index 0855deea3..1d1f2a1e0 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitFileChooserRequest.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitFileChooserRequest.cpp @@ -27,8 +27,8 @@ #include "WebOpenPanelResultListenerProxy.h" #include <WebCore/FileSystem.h> #include <glib/gi18n-lib.h> -#include <wtf/gobject/GRefPtr.h> -#include <wtf/gobject/GUniquePtr.h> +#include <wtf/glib/GRefPtr.h> +#include <wtf/glib/GUniquePtr.h> #include <wtf/text/CString.h> using namespace WebKit; @@ -206,7 +206,7 @@ const gchar* const* webkit_file_chooser_request_get_mime_types(WebKitFileChooser if (request->priv->mimeTypes) return reinterpret_cast<gchar**>(request->priv->mimeTypes->pdata); - RefPtr<API::Array> mimeTypes = request->priv->parameters->acceptMIMETypes(); + Ref<API::Array> mimeTypes = request->priv->parameters->acceptMIMETypes(); size_t numOfMimeTypes = mimeTypes->size(); if (!numOfMimeTypes) return 0; @@ -247,7 +247,7 @@ GtkFileFilter* webkit_file_chooser_request_get_mime_types_filter(WebKitFileChoos if (request->priv->filter) return request->priv->filter.get(); - RefPtr<API::Array> mimeTypes = request->priv->parameters->acceptMIMETypes(); + Ref<API::Array> mimeTypes = request->priv->parameters->acceptMIMETypes(); size_t numOfMimeTypes = mimeTypes->size(); if (!numOfMimeTypes) return 0; @@ -299,7 +299,7 @@ void webkit_file_chooser_request_select_files(WebKitFileChooserRequest* request, g_return_if_fail(files); GRefPtr<GPtrArray> selectedFiles = adoptGRef(g_ptr_array_new_with_free_func(g_free)); - Vector<RefPtr<API::Object> > choosenFiles; + Vector<RefPtr<API::Object> > chosenFiles; for (int i = 0; files[i]; i++) { GRefPtr<GFile> filename = adoptGRef(g_file_new_for_path(files[i])); @@ -307,7 +307,7 @@ void webkit_file_chooser_request_select_files(WebKitFileChooserRequest* request, // string, with the 'file://' prefix) to WebCore otherwise the // FileChooser won't actually choose it. GUniquePtr<char> uri(g_file_get_uri(filename.get())); - choosenFiles.append(API::URL::create(String::fromUTF8(uri.get()))); + chosenFiles.append(API::URL::create(String::fromUTF8(uri.get()))); // Do not use the URI here because this won't reach WebCore. g_ptr_array_add(selectedFiles.get(), g_strdup(files[i])); @@ -315,7 +315,7 @@ void webkit_file_chooser_request_select_files(WebKitFileChooserRequest* request, g_ptr_array_add(selectedFiles.get(), 0); // Select the files in WebCore and update local private attributes. - request->priv->listener->chooseFiles(API::Array::create(std::move(choosenFiles)).get()); + request->priv->listener->chooseFiles(API::Array::create(WTFMove(chosenFiles)).ptr()); request->priv->selectedFiles = selectedFiles; request->priv->handledRequest = true; } @@ -354,7 +354,7 @@ const gchar* const* webkit_file_chooser_request_get_selected_files(WebKitFileCho request->priv->selectedFiles = adoptGRef(g_ptr_array_new_with_free_func(g_free)); for (size_t i = 0; i < numOfFiles; ++i) { API::String* webFileName = static_cast<API::String*>(selectedFileNames->at(i)); - if (webFileName->isEmpty()) + if (webFileName->stringView().isEmpty()) continue; CString filename = fileSystemRepresentation(webFileName->string()); g_ptr_array_add(request->priv->selectedFiles.get(), g_strdup(filename.data())); diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitFindController.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitFindController.cpp index 8759306e2..0830bccaf 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitFindController.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitFindController.cpp @@ -25,7 +25,7 @@ #include "WebKitWebView.h" #include "WebKitWebViewBasePrivate.h" #include <glib/gi18n-lib.h> -#include <wtf/gobject/GRefPtr.h> +#include <wtf/glib/GRefPtr.h> #include <wtf/text/CString.h> using namespace WebKit; @@ -73,6 +73,7 @@ typedef enum { struct _WebKitFindControllerPrivate { CString searchText; + // Interpreted as WebKit::FindOptions. uint32_t findOptions; unsigned maxMatchCount; WebKitWebView* webView; @@ -82,23 +83,35 @@ static guint signals[LAST_SIGNAL] = { 0, }; WEBKIT_DEFINE_TYPE(WebKitFindController, webkit_find_controller, G_TYPE_OBJECT) -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE, FindOptionsCaseInsensitive); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_FIND_OPTIONS_AT_WORD_STARTS, FindOptionsAtWordStarts); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_FIND_OPTIONS_TREAT_MEDIAL_CAPITAL_AS_WORD_START, FindOptionsTreatMedialCapitalAsWordStart); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_FIND_OPTIONS_BACKWARDS, FindOptionsBackwards); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_FIND_OPTIONS_WRAP_AROUND, FindOptionsWrapAround); +static inline WebKit::FindOptions toWebFindOptions(uint32_t findOptions) +{ + return static_cast<WebKit::FindOptions>((findOptions & WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE ? FindOptionsCaseInsensitive : 0) + | (findOptions & WEBKIT_FIND_OPTIONS_AT_WORD_STARTS ? FindOptionsAtWordStarts : 0) + | (findOptions & WEBKIT_FIND_OPTIONS_TREAT_MEDIAL_CAPITAL_AS_WORD_START ? FindOptionsTreatMedialCapitalAsWordStart : 0) + | (findOptions & WEBKIT_FIND_OPTIONS_BACKWARDS ? FindOptionsBackwards : 0) + | (findOptions & WEBKIT_FIND_OPTIONS_WRAP_AROUND ? FindOptionsWrapAround : 0)); +} + +static inline WebKitFindOptions toWebKitFindOptions(uint32_t findOptions) +{ + return static_cast<WebKitFindOptions>((findOptions & FindOptionsCaseInsensitive ? WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE : 0) + | (findOptions & FindOptionsAtWordStarts ? WEBKIT_FIND_OPTIONS_AT_WORD_STARTS : 0) + | (findOptions & FindOptionsTreatMedialCapitalAsWordStart ? WEBKIT_FIND_OPTIONS_TREAT_MEDIAL_CAPITAL_AS_WORD_START : 0) + | (findOptions & FindOptionsBackwards ? WEBKIT_FIND_OPTIONS_BACKWARDS : 0) + | (findOptions & FindOptionsWrapAround ? WEBKIT_FIND_OPTIONS_WRAP_AROUND : 0)); +} -static void didFindString(WKPageRef page, WKStringRef string, unsigned matchCount, const void* clientInfo) +static void didFindString(WKPageRef, WKStringRef, unsigned matchCount, const void* clientInfo) { g_signal_emit(WEBKIT_FIND_CONTROLLER(clientInfo), signals[FOUND_TEXT], 0, matchCount); } -static void didFailToFindString(WKPageRef page, WKStringRef string, const void* clientInfo) +static void didFailToFindString(WKPageRef, WKStringRef, const void* clientInfo) { g_signal_emit(WEBKIT_FIND_CONTROLLER(clientInfo), signals[FAILED_TO_FIND_TEXT], 0); } -static void didCountStringMatches(WKPageRef page, WKStringRef string, unsigned matchCount, const void* clientInfo) +static void didCountStringMatches(WKPageRef, WKStringRef, unsigned matchCount, const void* clientInfo) { g_signal_emit(WEBKIT_FIND_CONTROLLER(clientInfo), signals[COUNTED_MATCHES], 0, matchCount); } @@ -306,7 +319,7 @@ guint32 webkit_find_controller_get_options(WebKitFindController* findController) { g_return_val_if_fail(WEBKIT_IS_FIND_CONTROLLER(findController), WEBKIT_FIND_OPTIONS_NONE); - return findController->priv->findOptions; + return toWebKitFindOptions(findController->priv->findOptions); } /** @@ -349,7 +362,7 @@ static void webKitFindControllerPerform(WebKitFindController* findController, We WebKitFindControllerPrivate* priv = findController->priv; if (operation == CountOperation) { getPage(findController)->countStringMatches(String::fromUTF8(priv->searchText.data()), - static_cast<WebKit::FindOptions>(priv->findOptions), priv->maxMatchCount); + static_cast<WebKit::FindOptions>(priv->findOptions), priv->maxMatchCount); return; } @@ -406,8 +419,7 @@ void webkit_find_controller_search(WebKitFindController* findController, const g { g_return_if_fail(WEBKIT_IS_FIND_CONTROLLER(findController)); g_return_if_fail(searchText); - - webKitFindControllerSetSearchData(findController, searchText, findOptions, maxMatchCount); + webKitFindControllerSetSearchData(findController, searchText, toWebFindOptions(findOptions), maxMatchCount); webKitFindControllerPerform(findController, FindOperation); } @@ -424,7 +436,7 @@ void webkit_find_controller_search_next(WebKitFindController* findController) { g_return_if_fail(WEBKIT_IS_FIND_CONTROLLER(findController)); - findController->priv->findOptions &= ~WEBKIT_FIND_OPTIONS_BACKWARDS; + findController->priv->findOptions &= ~FindOptionsBackwards; findController->priv->findOptions &= ~FindOptionsShowHighlight; webKitFindControllerPerform(findController, FindNextPrevOperation); } @@ -442,7 +454,7 @@ void webkit_find_controller_search_previous(WebKitFindController* findController { g_return_if_fail(WEBKIT_IS_FIND_CONTROLLER(findController)); - findController->priv->findOptions |= WEBKIT_FIND_OPTIONS_BACKWARDS; + findController->priv->findOptions |= FindOptionsBackwards; findController->priv->findOptions &= ~FindOptionsShowHighlight; webKitFindControllerPerform(findController, FindNextPrevOperation); } @@ -464,7 +476,7 @@ void webkit_find_controller_count_matches(WebKitFindController* findController, g_return_if_fail(WEBKIT_IS_FIND_CONTROLLER(findController)); g_return_if_fail(searchText); - webKitFindControllerSetSearchData(findController, searchText, findOptions, maxMatchCount); + webKitFindControllerSetSearchData(findController, searchText, toWebFindOptions(findOptions), maxMatchCount); webKitFindControllerPerform(findController, CountOperation); } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitFindController.h b/Source/WebKit2/UIProcess/API/gtk/WebKitFindController.h index 7bad1d051..8f3e438ff 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitFindController.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitFindController.h @@ -62,7 +62,7 @@ typedef enum { WEBKIT_FIND_OPTIONS_AT_WORD_STARTS = 1 << 1, WEBKIT_FIND_OPTIONS_TREAT_MEDIAL_CAPITAL_AS_WORD_START = 1 << 2, WEBKIT_FIND_OPTIONS_BACKWARDS = 1 << 3, - WEBKIT_FIND_OPTIONS_WRAP_AROUND = 1 << 4, + WEBKIT_FIND_OPTIONS_WRAP_AROUND = 1 << 4 } WebKitFindOptions; struct _WebKitFindController { diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitFormClient.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitFormClient.cpp index a07f04948..12ec927a8 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitFormClient.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitFormClient.cpp @@ -20,15 +20,17 @@ #include "config.h" #include "WebKitFormClient.h" +#include "APIDictionary.h" +#include "WebFormSubmissionListenerProxy.h" #include "WebKitFormSubmissionRequestPrivate.h" #include "WebKitPrivate.h" #include "WebKitWebViewBasePrivate.h" #include "WebKitWebViewPrivate.h" -#include <wtf/gobject/GRefPtr.h> +#include <wtf/glib/GRefPtr.h> using namespace WebKit; -static void willSubmitForm(WKPageRef page, WKFrameRef frame, WKFrameRef sourceFrame, WKDictionaryRef values, WKTypeRef userData, WKFormSubmissionListenerRef listener, const void* clientInfo) +static void willSubmitForm(WKPageRef, WKFrameRef, WKFrameRef, WKDictionaryRef values, WKTypeRef /* userData */, WKFormSubmissionListenerRef listener, const void* clientInfo) { GRefPtr<WebKitFormSubmissionRequest> request = adoptGRef(webkitFormSubmissionRequestCreate(toImpl(values), toImpl(listener))); webkitWebViewSubmitFormRequest(WEBKIT_WEB_VIEW(clientInfo), request.get()); diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitFormSubmissionRequest.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitFormSubmissionRequest.cpp index 8519a2cb6..7af2aee10 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitFormSubmissionRequest.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitFormSubmissionRequest.cpp @@ -20,11 +20,11 @@ #include "config.h" #include "WebKitFormSubmissionRequest.h" +#include "APIDictionary.h" #include "APIString.h" -#include "ImmutableDictionary.h" #include "WebFormSubmissionListenerProxy.h" #include "WebKitFormSubmissionRequestPrivate.h" -#include <wtf/gobject/GRefPtr.h> +#include <wtf/glib/GRefPtr.h> #include <wtf/text/CString.h> using namespace WebKit; @@ -45,7 +45,7 @@ using namespace WebKit; */ struct _WebKitFormSubmissionRequestPrivate { - RefPtr<ImmutableDictionary> webValues; + RefPtr<API::Dictionary> webValues; RefPtr<WebFormSubmissionListenerProxy> listener; GRefPtr<GHashTable> values; bool handledRequest; @@ -70,7 +70,7 @@ static void webkit_form_submission_request_class_init(WebKitFormSubmissionReques objectClass->dispose = webkitFormSubmissionRequestDispose; } -WebKitFormSubmissionRequest* webkitFormSubmissionRequestCreate(ImmutableDictionary* values, WebFormSubmissionListenerProxy* listener) +WebKitFormSubmissionRequest* webkitFormSubmissionRequestCreate(API::Dictionary* values, WebFormSubmissionListenerProxy* listener) { WebKitFormSubmissionRequest* request = WEBKIT_FORM_SUBMISSION_REQUEST(g_object_new(WEBKIT_TYPE_FORM_SUBMISSION_REQUEST, NULL)); request->priv->webValues = values; @@ -96,18 +96,18 @@ GHashTable* webkit_form_submission_request_get_text_fields(WebKitFormSubmissionR return request->priv->values.get(); if (!request->priv->webValues->size()) - return 0; + return nullptr; request->priv->values = adoptGRef(g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free)); - const ImmutableDictionary::MapType& map = request->priv->webValues->map(); - ImmutableDictionary::MapType::const_iterator end = map.end(); - for (ImmutableDictionary::MapType::const_iterator it = map.begin(); it != end; ++it) { + const API::Dictionary::MapType& map = request->priv->webValues->map(); + API::Dictionary::MapType::const_iterator end = map.end(); + for (API::Dictionary::MapType::const_iterator it = map.begin(); it != end; ++it) { API::String* value = static_cast<API::String*>(it->value.get()); g_hash_table_insert(request->priv->values.get(), g_strdup(it->key.utf8().data()), g_strdup(value->string().utf8().data())); } - request->priv->webValues = 0; + request->priv->webValues = nullptr; return request->priv->values.get(); } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitFormSubmissionRequestPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitFormSubmissionRequestPrivate.h index 9fe4751d2..1d2b499f6 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitFormSubmissionRequestPrivate.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitFormSubmissionRequestPrivate.h @@ -23,6 +23,6 @@ #include "WebKitFormSubmissionRequest.h" #include "WebKitPrivate.h" -WebKitFormSubmissionRequest* webkitFormSubmissionRequestCreate(WebKit::ImmutableDictionary* values, WebKit::WebFormSubmissionListenerProxy*); +WebKitFormSubmissionRequest* webkitFormSubmissionRequestCreate(API::Dictionary* values, WebKit::WebFormSubmissionListenerProxy*); #endif // WebKitFormSubmissionRequestPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitForwardDeclarations.h b/Source/WebKit2/UIProcess/API/gtk/WebKitForwardDeclarations.h index a9898de48..543f4b136 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitForwardDeclarations.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitForwardDeclarations.h @@ -23,7 +23,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) +#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) && !defined(__WEBKIT_WEB_EXTENSION_H_INSIDE__) #error "Only <webkit2/webkit2.h> can be included directly." #endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationPermissionRequest.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationPermissionRequest.cpp index f780dafb2..871c3cf3e 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationPermissionRequest.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationPermissionRequest.cpp @@ -35,6 +35,9 @@ using namespace WebKit; * WebKitGeolocationPermissionRequest represents a request for * permission to decide whether WebKit should provide the user's * location to a website when requested throught the Geolocation API. + * + * When a WebKitGeolocationPermissionRequest is not handled by the user, + * it is denied by default. */ static void webkit_permission_request_interface_init(WebKitPermissionRequestIface*); diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationProvider.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationProvider.cpp index 261abf81a..6ac0fbc98 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationProvider.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationProvider.cpp @@ -38,12 +38,12 @@ static inline WebKitGeolocationProvider* toGeolocationProvider(const void* clien return static_cast<WebKitGeolocationProvider*>(const_cast<void*>(clientInfo)); } -static void startUpdatingCallback(WKGeolocationManagerRef geolocationManager, const void* clientInfo) +static void startUpdatingCallback(WKGeolocationManagerRef, const void* clientInfo) { toGeolocationProvider(clientInfo)->startUpdating(); } -static void stopUpdatingCallback(WKGeolocationManagerRef geolocationManager, const void* clientInfo) +static void stopUpdatingCallback(WKGeolocationManagerRef, const void* clientInfo) { toGeolocationProvider(clientInfo)->stopUpdating(); } @@ -51,11 +51,12 @@ static void stopUpdatingCallback(WKGeolocationManagerRef geolocationManager, con WebKitGeolocationProvider::~WebKitGeolocationProvider() { m_provider.stopUpdating(); + WKGeolocationManagerSetProvider(toAPI(m_geolocationManager.get()), nullptr); } -PassRefPtr<WebKitGeolocationProvider> WebKitGeolocationProvider::create(WebGeolocationManagerProxy* geolocationManager) +Ref<WebKitGeolocationProvider> WebKitGeolocationProvider::create(WebGeolocationManagerProxy* geolocationManager) { - return adoptRef(new WebKitGeolocationProvider(geolocationManager)); + return adoptRef(*new WebKitGeolocationProvider(geolocationManager)); } WebKitGeolocationProvider::WebKitGeolocationProvider(WebGeolocationManagerProxy* geolocationManager) @@ -92,7 +93,7 @@ void WebKitGeolocationProvider::notifyPositionChanged(int timestamp, double lati m_geolocationManager->providerDidChangePosition(position.get()); } -void WebKitGeolocationProvider::notifyErrorOccurred(const char* message) +void WebKitGeolocationProvider::notifyErrorOccurred(const char* /* message */) { m_geolocationManager->providerDidFailToDeterminePosition(); } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationProvider.h b/Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationProvider.h index e6be3eac2..92586ce05 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationProvider.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationProvider.h @@ -33,7 +33,7 @@ namespace WebKit { class WebKitGeolocationProvider : public RefCounted<WebKitGeolocationProvider>, public WebCore::GeolocationProviderGeoclueClient { public: virtual ~WebKitGeolocationProvider(); - static PassRefPtr<WebKitGeolocationProvider> create(WebGeolocationManagerProxy*); + static Ref<WebKitGeolocationProvider> create(WebGeolocationManagerProxy*); void startUpdating(); void stopUpdating(); diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitHitTestResult.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitHitTestResult.cpp index 918d316c0..60b5fb853 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitHitTestResult.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitHitTestResult.cpp @@ -20,7 +20,7 @@ #include "config.h" #include "WebKitHitTestResult.h" -#include "WebHitTestResult.h" +#include "WebHitTestResultData.h" #include "WebKitHitTestResultPrivate.h" #include <glib/gi18n-lib.h> #include <wtf/text/CString.h> @@ -221,39 +221,36 @@ static void webkit_hit_test_result_class_init(WebKitHitTestResultClass* hitTestR paramFlags)); } -WebKitHitTestResult* webkitHitTestResultCreate(WebHitTestResult* hitTestResult) +WebKitHitTestResult* webkitHitTestResultCreate(const WebHitTestResultData& hitTestResult) { unsigned context = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT; - const String& linkURL = hitTestResult->absoluteLinkURL(); - if (!linkURL.isEmpty()) + if (!hitTestResult.absoluteLinkURL.isEmpty()) context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK; - const String& imageURL = hitTestResult->absoluteImageURL(); - if (!imageURL.isEmpty()) + if (!hitTestResult.absoluteImageURL.isEmpty()) context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE; - const String& mediaURL = hitTestResult->absoluteMediaURL(); - if (!mediaURL.isEmpty()) + if (!hitTestResult.absoluteMediaURL.isEmpty()) context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA; - if (hitTestResult->isContentEditable()) + if (hitTestResult.isContentEditable) context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE; - if (hitTestResult->isScrollbar()) + if (hitTestResult.isScrollbar) context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_SCROLLBAR; - const String& linkTitle = hitTestResult->linkTitle(); - const String& linkLabel = hitTestResult->linkLabel(); + if (hitTestResult.isSelected) + context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION; return WEBKIT_HIT_TEST_RESULT(g_object_new(WEBKIT_TYPE_HIT_TEST_RESULT, - "context", context, - "link-uri", !linkURL.isEmpty() ? linkURL.utf8().data() : 0, - "image-uri", !imageURL.isEmpty() ? imageURL.utf8().data() : 0, - "media-uri", !mediaURL.isEmpty() ? mediaURL.utf8().data() : 0, - "link-title", !linkTitle.isEmpty() ? linkTitle.utf8().data() : 0, - "link-label", !linkLabel.isEmpty() ? linkLabel.utf8().data() : 0, - NULL)); + "context", context, + "link-uri", context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK ? hitTestResult.absoluteLinkURL.utf8().data() : nullptr, + "image-uri", context & WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE ? hitTestResult.absoluteImageURL.utf8().data() : nullptr, + "media-uri", context & WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA ? hitTestResult.absoluteMediaURL.utf8().data() : nullptr, + "link-title", !hitTestResult.linkTitle.isEmpty() ? hitTestResult.linkTitle.utf8().data() : nullptr, + "link-label", !hitTestResult.linkLabel.isEmpty() ? hitTestResult.linkLabel.utf8().data() : nullptr, + nullptr)); } static bool stringIsEqualToCString(const String& string, const CString& cString) @@ -261,16 +258,17 @@ static bool stringIsEqualToCString(const String& string, const CString& cString) return ((string.isEmpty() && cString.isNull()) || (string.utf8() == cString)); } -bool webkitHitTestResultCompare(WebKitHitTestResult* hitTestResult, WebHitTestResult* webHitTestResult) +bool webkitHitTestResultCompare(WebKitHitTestResult* hitTestResult, const WebHitTestResultData& webHitTestResult) { WebKitHitTestResultPrivate* priv = hitTestResult->priv; - return webHitTestResult->isContentEditable() == webkit_hit_test_result_context_is_editable(hitTestResult) - && webHitTestResult->isScrollbar() == webkit_hit_test_result_context_is_scrollbar(hitTestResult) - && stringIsEqualToCString(webHitTestResult->absoluteLinkURL(), priv->linkURI) - && stringIsEqualToCString(webHitTestResult->linkTitle(), priv->linkTitle) - && stringIsEqualToCString(webHitTestResult->linkLabel(), priv->linkLabel) - && stringIsEqualToCString(webHitTestResult->absoluteImageURL(), priv->imageURI) - && stringIsEqualToCString(webHitTestResult->absoluteMediaURL(), priv->mediaURI); + return webHitTestResult.isContentEditable == webkit_hit_test_result_context_is_editable(hitTestResult) + && webHitTestResult.isScrollbar == webkit_hit_test_result_context_is_scrollbar(hitTestResult) + && webHitTestResult.isSelected == webkit_hit_test_result_context_is_selection(hitTestResult) + && stringIsEqualToCString(webHitTestResult.absoluteLinkURL, priv->linkURI) + && stringIsEqualToCString(webHitTestResult.linkTitle, priv->linkTitle) + && stringIsEqualToCString(webHitTestResult.linkLabel, priv->linkLabel) + && stringIsEqualToCString(webHitTestResult.absoluteImageURL, priv->imageURI) + && stringIsEqualToCString(webHitTestResult.absoluteMediaURL, priv->mediaURI); } /** @@ -357,6 +355,25 @@ gboolean webkit_hit_test_result_context_is_editable(WebKitHitTestResult* hitTest } /** + * webkit_hit_test_result_context_is_selection: + * @hit_test_result: a #WebKitHitTestResult + * + * Gets whether %WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION flag is present in + * #WebKitHitTestResult:context. + * + * Returns: %TRUE if there's a selected element at the coordinates of the @hit_test_result, + * or %FALSE otherwise + * + * Since: 2.8 + */ +gboolean webkit_hit_test_result_context_is_selection(WebKitHitTestResult* hitTestResult) +{ + g_return_val_if_fail(WEBKIT_IS_HIT_TEST_RESULT(hitTestResult), FALSE); + + return hitTestResult->priv->context & WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION; +} + +/** * webkit_hit_test_result_get_link_uri: * @hit_test_result: a #WebKitHitTestResult * diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitHitTestResult.h b/Source/WebKit2/UIProcess/API/gtk/WebKitHitTestResult.h index 54611ba92..718573b90 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitHitTestResult.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitHitTestResult.h @@ -17,7 +17,7 @@ * Boston, MA 02110-1301, USA. */ -#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) +#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) && !defined(__WEBKIT_WEB_EXTENSION_H_INSIDE__) #error "Only <webkit2/webkit2.h> can be included directly." #endif @@ -48,6 +48,7 @@ typedef struct _WebKitHitTestResultPrivate WebKitHitTestResultPrivate; * @WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA: a video or audio element. * @WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE: an editable element * @WEBKIT_HIT_TEST_RESULT_CONTEXT_SCROLLBAR: a scrollbar element. + * @WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION: a selected element. Since 2.8 * * Enum values with flags representing the context of a #WebKitHitTestResult. */ @@ -58,7 +59,8 @@ typedef enum WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE = 1 << 3, WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA = 1 << 4, WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE = 1 << 5, - WEBKIT_HIT_TEST_RESULT_CONTEXT_SCROLLBAR = 1 << 6 + WEBKIT_HIT_TEST_RESULT_CONTEXT_SCROLLBAR = 1 << 6, + WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION = 1 << 7 } WebKitHitTestResultContext; struct _WebKitHitTestResult { @@ -94,6 +96,9 @@ webkit_hit_test_result_context_is_media (WebKitHitTestResult *hit_test_resul WEBKIT_API gboolean webkit_hit_test_result_context_is_editable (WebKitHitTestResult *hit_test_result); +WEBKIT_API gboolean +webkit_hit_test_result_context_is_selection (WebKitHitTestResult *hit_test_result); + WEBKIT_API const gchar * webkit_hit_test_result_get_link_uri (WebKitHitTestResult *hit_test_result); diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitHitTestResultPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitHitTestResultPrivate.h index 7ba2c3871..4fdb46deb 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitHitTestResultPrivate.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitHitTestResultPrivate.h @@ -23,7 +23,7 @@ #include "WebKitHitTestResult.h" #include "WebKitPrivate.h" -WebKitHitTestResult* webkitHitTestResultCreate(WebKit::WebHitTestResult*); -bool webkitHitTestResultCompare(WebKitHitTestResult*, WebKit::WebHitTestResult*); +WebKitHitTestResult* webkitHitTestResultCreate(const WebKit::WebHitTestResultData&); +bool webkitHitTestResultCompare(WebKitHitTestResult*, const WebKit::WebHitTestResultData&); #endif // WebKitHitTestResultPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitInjectedBundleClient.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitInjectedBundleClient.cpp index 1b77b6ea7..f304d2f8a 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitInjectedBundleClient.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitInjectedBundleClient.cpp @@ -21,17 +21,18 @@ #include "WebKitInjectedBundleClient.h" #include "WebImage.h" +#include "WebKitPrivate.h" #include "WebKitURIRequestPrivate.h" #include "WebKitURIResponsePrivate.h" #include "WebKitWebContextPrivate.h" #include "WebKitWebResourcePrivate.h" #include "WebKitWebViewPrivate.h" -#include <wtf/gobject/GUniquePtr.h> +#include <wtf/glib/GUniquePtr.h> using namespace WebKit; using namespace WebCore; -static void didReceiveWebViewMessageFromInjectedBundle(WebKitWebView* webView, const char* messageName, ImmutableDictionary& message) +static void didReceiveWebViewMessageFromInjectedBundle(WebKitWebView* webView, const char* messageName, API::Dictionary& message) { if (g_str_equal(messageName, "DidInitiateLoadForResource")) { WebFrameProxy* frame = static_cast<WebFrameProxy*>(message.get(String::fromUTF8("Frame"))); @@ -87,9 +88,12 @@ static void didReceiveWebViewMessageFromInjectedBundle(WebKitWebView* webView, c API::Error* webError = static_cast<API::Error*>(message.get(String::fromUTF8("Error"))); const ResourceError& platformError = webError->platformError(); GUniquePtr<GError> resourceError(g_error_new_literal(g_quark_from_string(platformError.domain().utf8().data()), - platformError.errorCode(), platformError.localizedDescription().utf8().data())); + toWebKitError(platformError.errorCode()), platformError.localizedDescription().utf8().data())); + if (platformError.tlsErrors()) + webkitWebResourceFailedWithTLSErrors(resource.get(), static_cast<GTlsCertificateFlags>(platformError.tlsErrors()), platformError.certificate()); + else + webkitWebResourceFailed(resource.get(), resourceError.get()); - webkitWebResourceFailed(resource.get(), resourceError.get()); webkitWebViewRemoveLoadingWebResource(webView, resourceIdentifier->value()); } else if (g_str_equal(messageName, "DidGetSnapshot")) { API::UInt64* callbackID = static_cast<API::UInt64*>(message.get("CallbackID")); @@ -102,7 +106,7 @@ static void didReceiveWebViewMessageFromInjectedBundle(WebKitWebView* webView, c static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, const void* clientInfo) { ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); - ImmutableDictionary& message = *toImpl(static_cast<WKDictionaryRef>(messageBody)); + API::Dictionary& message = *toImpl(static_cast<WKDictionaryRef>(messageBody)); CString messageNameCString = toImpl(messageName)->string().utf8(); const char* messageNameUTF8 = messageNameCString.data(); @@ -136,5 +140,5 @@ void attachInjectedBundleClientToContext(WebKitWebContext* webContext) 0, // didReceiveSynchronousMessageFromInjectedBundle getInjectedBundleInitializationUserData }; - WKContextSetInjectedBundleClient(toAPI(webkitWebContextGetContext(webContext)), &wkInjectedBundleClient.base); + WKContextSetInjectedBundleClient(toAPI(webkitWebContextGetProcessPool(webContext)), &wkInjectedBundleClient.base); } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitInstallMissingMediaPluginsPermissionRequest.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitInstallMissingMediaPluginsPermissionRequest.cpp new file mode 100644 index 000000000..d516b61ad --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitInstallMissingMediaPluginsPermissionRequest.cpp @@ -0,0 +1,166 @@ +/* + * Copyright (C) 2015 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "WebKitInstallMissingMediaPluginsPermissionRequest.h" + +#include "WebKitInstallMissingMediaPluginsPermissionRequestPrivate.h" +#include "WebKitPermissionRequest.h" +#include "WebPageProxy.h" + +#if ENABLE(VIDEO) +#include <WebCore/PlatformDisplay.h> +#include <gtk/gtk.h> +#if PLATFORM(X11) +#include <gdk/gdkx.h> +#endif +#endif + +using namespace WebKit; +using namespace WebCore; + +/** + * SECTION: WebKitInstallMissingMediaPluginsPermissionRequest + * @Short_description: A permission request for installing missing media plugins + * @Title: WebKitInstallMissingMediaPluginsPermissionRequest + * @See_also: #WebKitPermissionRequest, #WebKitWebView + * + * WebKitInstallMissingMediaPluginsPermissionRequest represents a request for + * permission to decide whether WebKit should try to start a helper application to + * install missing media plugins when the media backend couldn't play a media because + * the required plugins were not available. + * + * When a WebKitInstallMissingMediaPluginsPermissionRequest is not handled by the user, + * it is allowed by default. + * + * Since: 2.10 + */ + +static void webkit_permission_request_interface_init(WebKitPermissionRequestIface*); + +struct _WebKitInstallMissingMediaPluginsPermissionRequestPrivate { +#if ENABLE(VIDEO) + RefPtr<InstallMissingMediaPluginsPermissionRequest> request; +#endif + CString description; + bool madeDecision; +}; + +WEBKIT_DEFINE_TYPE_WITH_CODE( + WebKitInstallMissingMediaPluginsPermissionRequest, webkit_install_missing_media_plugins_permission_request, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE(WEBKIT_TYPE_PERMISSION_REQUEST, webkit_permission_request_interface_init)) + +#if ENABLE(VIDEO) +static GUniquePtr<GstInstallPluginsContext> createGstInstallPluginsContext(GtkWidget* widget) +{ +#if PLATFORM(X11) + if (PlatformDisplay::sharedDisplay().type() == PlatformDisplay::Type::X11) { + GUniquePtr<GstInstallPluginsContext> context(gst_install_plugins_context_new()); + gst_install_plugins_context_set_xid(context.get(), GDK_WINDOW_XID(gtk_widget_get_window(widget))); + return context; + } +#endif + + return nullptr; +} +#endif + +static void webkitInstallMissingMediaPluginsPermissionRequestAllow(WebKitPermissionRequest* request) +{ + ASSERT(WEBKIT_IS_INSTALL_MISSING_MEDIA_PLUGINS_PERMISSION_REQUEST(request)); + + WebKitInstallMissingMediaPluginsPermissionRequestPrivate* priv = WEBKIT_INSTALL_MISSING_MEDIA_PLUGINS_PERMISSION_REQUEST(request)->priv; + + // Only one decision at a time. + if (priv->madeDecision) + return; +#if ENABLE(VIDEO) + priv->request->allow(createGstInstallPluginsContext(priv->request->page().viewWidget())); +#endif + priv->madeDecision = true; +} + +static void webkitInstallMissingMediaPluginsPermissionRequestDeny(WebKitPermissionRequest* request) +{ + ASSERT(WEBKIT_IS_INSTALL_MISSING_MEDIA_PLUGINS_PERMISSION_REQUEST(request)); + + WebKitInstallMissingMediaPluginsPermissionRequestPrivate* priv = WEBKIT_INSTALL_MISSING_MEDIA_PLUGINS_PERMISSION_REQUEST(request)->priv; + + // Only one decision at a time. + if (priv->madeDecision) + return; + +#if ENABLE(VIDEO) + priv->request->deny(); +#endif + priv->madeDecision = true; +} + +static void webkit_permission_request_interface_init(WebKitPermissionRequestIface* iface) +{ + iface->allow = webkitInstallMissingMediaPluginsPermissionRequestAllow; + iface->deny = webkitInstallMissingMediaPluginsPermissionRequestDeny; +} + +static void webkitInstallMissingMediaPluginsPermissionRequestDispose(GObject* object) +{ + // Default behaviour when no decision has been made is allowing the request for backwards compatibility. + webkitInstallMissingMediaPluginsPermissionRequestDeny(WEBKIT_PERMISSION_REQUEST(object)); + G_OBJECT_CLASS(webkit_install_missing_media_plugins_permission_request_parent_class)->dispose(object); +} + +static void webkit_install_missing_media_plugins_permission_request_class_init(WebKitInstallMissingMediaPluginsPermissionRequestClass* klass) +{ + GObjectClass* objectClass = G_OBJECT_CLASS(klass); + objectClass->dispose = webkitInstallMissingMediaPluginsPermissionRequestDispose; +} + +#if ENABLE(VIDEO) +WebKitInstallMissingMediaPluginsPermissionRequest* webkitInstallMissingMediaPluginsPermissionRequestCreate(InstallMissingMediaPluginsPermissionRequest& request) +{ + WebKitInstallMissingMediaPluginsPermissionRequest* permissionRequest = WEBKIT_INSTALL_MISSING_MEDIA_PLUGINS_PERMISSION_REQUEST(g_object_new(WEBKIT_TYPE_INSTALL_MISSING_MEDIA_PLUGINS_PERMISSION_REQUEST, nullptr)); + permissionRequest->priv->request = &request; + return permissionRequest; +} +#endif + +/** + * webkit_install_missing_media_plugins_permission_request_get_description: + * @request: a #WebKitInstallMissingMediaPluginsPermissionRequest + * + * Gets the description about the missing plugins provided by the media backend when a media couldn't be played. + * + * Returns: a string with the description provided by the media backend. + * + * Since: 2.10 + */ +const char* webkit_install_missing_media_plugins_permission_request_get_description(WebKitInstallMissingMediaPluginsPermissionRequest* request) +{ + g_return_val_if_fail(WEBKIT_IS_INSTALL_MISSING_MEDIA_PLUGINS_PERMISSION_REQUEST(request), nullptr); + +#if ENABLE(VIDEO) + if (!request->priv->description.isNull()) + return request->priv->description.data(); + + const auto& description = request->priv->request->description(); + ASSERT(!description.isEmpty()); + request->priv->description = description.utf8(); +#endif + return request->priv->description.data(); +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitInstallMissingMediaPluginsPermissionRequest.h b/Source/WebKit2/UIProcess/API/gtk/WebKitInstallMissingMediaPluginsPermissionRequest.h new file mode 100644 index 000000000..e0632afa5 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitInstallMissingMediaPluginsPermissionRequest.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2015 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) +#error "Only <webkit2/webkit2.h> can be included directly." +#endif + +#ifndef WebKitInstallMissingMediaPluginsPermissionRequest_h +#define WebKitInstallMissingMediaPluginsPermissionRequest_h + +#include <glib-object.h> +#include <webkit2/WebKitDefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_INSTALL_MISSING_MEDIA_PLUGINS_PERMISSION_REQUEST (webkit_install_missing_media_plugins_permission_request_get_type()) +#define WEBKIT_INSTALL_MISSING_MEDIA_PLUGINS_PERMISSION_REQUEST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_INSTALL_MISSING_MEDIA_PLUGINS_PERMISSION_REQUEST, WebKitInstallMissingMediaPluginsPermissionRequest)) +#define WEBKIT_IS_INSTALL_MISSING_MEDIA_PLUGINS_PERMISSION_REQUEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_INSTALL_MISSING_MEDIA_PLUGINS_PERMISSION_REQUEST)) +#define WEBKIT_INSTALL_MISSING_MEDIA_PLUGINS_PERMISSION_REQUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_INSTALL_MISSING_MEDIA_PLUGINS_PERMISSION_REQUEST, WebKitInstallMissingMediaPluginsPermissionRequestClass)) +#define WEBKIT_IS_INSTALL_MISSING_MEDIA_PLUGINS_PERMISSION_REQUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_INSTALL_MISSING_MEDIA_PLUGINS_PERMISSION_REQUEST)) +#define WEBKIT_INSTALL_MISSING_MEDIA_PLUGINS_PERMISSION_REQUEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_INSTALL_MISSING_MEDIA_PLUGINS_PERMISSION_REQUEST, WebKitInstallMissingMediaPluginsPermissionRequestClass)) + +typedef struct _WebKitInstallMissingMediaPluginsPermissionRequest WebKitInstallMissingMediaPluginsPermissionRequest; +typedef struct _WebKitInstallMissingMediaPluginsPermissionRequestClass WebKitInstallMissingMediaPluginsPermissionRequestClass; +typedef struct _WebKitInstallMissingMediaPluginsPermissionRequestPrivate WebKitInstallMissingMediaPluginsPermissionRequestPrivate; + +struct _WebKitInstallMissingMediaPluginsPermissionRequest { + GObject parent; + + WebKitInstallMissingMediaPluginsPermissionRequestPrivate *priv; +}; + +struct _WebKitInstallMissingMediaPluginsPermissionRequestClass { + GObjectClass parent_class; + + void (*_webkit_reserved0) (void); + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); +}; + +WEBKIT_API GType +webkit_install_missing_media_plugins_permission_request_get_type (void); + +WEBKIT_API const gchar * +webkit_install_missing_media_plugins_permission_request_get_description (WebKitInstallMissingMediaPluginsPermissionRequest *request); + +G_END_DECLS + +#endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitInstallMissingMediaPluginsPermissionRequestPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitInstallMissingMediaPluginsPermissionRequestPrivate.h new file mode 100644 index 000000000..2c7e3bc0d --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitInstallMissingMediaPluginsPermissionRequestPrivate.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2012 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef WebKitInstallMissingMediaPluginsPermissionRequestPrivate_h +#define WebKitInstallMissingMediaPluginsPermissionRequestPrivate_h + +#include "InstallMissingMediaPluginsPermissionRequest.h" +#include "WebKitInstallMissingMediaPluginsPermissionRequest.h" +#include "WebKitPrivate.h" + +#if ENABLE(VIDEO) +WebKitInstallMissingMediaPluginsPermissionRequest* webkitInstallMissingMediaPluginsPermissionRequestCreate(WebKit::InstallMissingMediaPluginsPermissionRequest&); +#endif + +#endif // WebKitInstallMissingMediaPluginsPermissionRequestPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitJavascriptResult.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitJavascriptResult.cpp index 9bbd3f4ed..79ec69b70 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitJavascriptResult.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitJavascriptResult.cpp @@ -20,18 +20,18 @@ #include "config.h" #include "WebKitJavascriptResult.h" +#include "APISerializedScriptValue.h" #include "WebKitJavascriptResultPrivate.h" -#include "WebSerializedScriptValue.h" -#include <wtf/gobject/GRefPtr.h> +#include <wtf/glib/GRefPtr.h> using namespace WebKit; struct _WebKitJavascriptResult { - _WebKitJavascriptResult(WebKitWebView* view, WebSerializedScriptValue* serializedScriptValue) + _WebKitJavascriptResult(WebKitWebView* view, WebCore::SerializedScriptValue& serializedScriptValue) : webView(view) , referenceCount(1) { - value = serializedScriptValue->deserialize(webkit_web_view_get_javascript_global_context(view), 0); + value = serializedScriptValue.deserialize(webkit_web_view_get_javascript_global_context(view), nullptr); } GRefPtr<WebKitWebView> webView; @@ -42,9 +42,9 @@ struct _WebKitJavascriptResult { G_DEFINE_BOXED_TYPE(WebKitJavascriptResult, webkit_javascript_result, webkit_javascript_result_ref, webkit_javascript_result_unref) -WebKitJavascriptResult* webkitJavascriptResultCreate(WebKitWebView* webView, WebSerializedScriptValue* serializedScriptValue) +WebKitJavascriptResult* webkitJavascriptResultCreate(WebKitWebView* webView, WebCore::SerializedScriptValue& serializedScriptValue) { - WebKitJavascriptResult* result = g_slice_new(WebKitJavascriptResult); + WebKitJavascriptResult* result = static_cast<WebKitJavascriptResult*>(fastMalloc(sizeof(WebKitJavascriptResult))); new (result) WebKitJavascriptResult(webView, serializedScriptValue); return result; } @@ -77,7 +77,7 @@ void webkit_javascript_result_unref(WebKitJavascriptResult* javascriptResult) { if (g_atomic_int_dec_and_test(&javascriptResult->referenceCount)) { javascriptResult->~WebKitJavascriptResult(); - g_slice_free(WebKitJavascriptResult, javascriptResult); + fastFree(javascriptResult); } } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitJavascriptResultPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitJavascriptResultPrivate.h index e47e94c1b..23e2e7926 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitJavascriptResultPrivate.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitJavascriptResultPrivate.h @@ -20,10 +20,11 @@ #ifndef WebKitJavascriptResultPrivate_h #define WebKitJavascriptResultPrivate_h +#include <WebCore/SerializedScriptValue.h> #include "WebKitJavascriptResult.h" #include "WebKitPrivate.h" #include "WebKitWebView.h" -WebKitJavascriptResult* webkitJavascriptResultCreate(WebKitWebView*, WebKit::WebSerializedScriptValue*); +WebKitJavascriptResult* webkitJavascriptResultCreate(WebKitWebView*, WebCore::SerializedScriptValue&); #endif // WebKitJavascriptResultPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitLoaderClient.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitLoaderClient.cpp index 4b2e59c25..f52c8c78e 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitLoaderClient.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitLoaderClient.cpp @@ -21,166 +21,107 @@ #include "config.h" #include "WebKitLoaderClient.h" +#include "APILoaderClient.h" #include "WebKitBackForwardListPrivate.h" +#include "WebKitPrivate.h" #include "WebKitURIResponsePrivate.h" #include "WebKitWebViewBasePrivate.h" #include "WebKitWebViewPrivate.h" -#include <wtf/gobject/GUniquePtr.h> +#include <wtf/glib/GUniquePtr.h> #include <wtf/text/CString.h> using namespace WebKit; using namespace WebCore; -static void didStartProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) -{ - if (!WKFrameIsMainFrame(frame)) - return; - - webkitWebViewLoadChanged(WEBKIT_WEB_VIEW(clientInfo), WEBKIT_LOAD_STARTED); -} - -static void didReceiveServerRedirectForProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) -{ - if (!WKFrameIsMainFrame(frame)) - return; - - webkitWebViewLoadChanged(WEBKIT_WEB_VIEW(clientInfo), WEBKIT_LOAD_REDIRECTED); -} - -static void didFailProvisionalLoadWithErrorForFrame(WKPageRef page, WKFrameRef frame, WKErrorRef error, WKTypeRef userData, const void* clientInfo) -{ - if (!WKFrameIsMainFrame(frame)) - return; - - const ResourceError& resourceError = toImpl(error)->platformError(); - GUniquePtr<GError> webError(g_error_new_literal(g_quark_from_string(resourceError.domain().utf8().data()), - resourceError.errorCode(), resourceError.localizedDescription().utf8().data())); - if (resourceError.tlsErrors()) { - webkitWebViewLoadFailedWithTLSErrors(WEBKIT_WEB_VIEW(clientInfo), resourceError.failingURL().utf8().data(), webError.get(), - static_cast<GTlsCertificateFlags>(resourceError.tlsErrors()), resourceError.certificate()); - } else - webkitWebViewLoadFailed(WEBKIT_WEB_VIEW(clientInfo), WEBKIT_LOAD_STARTED, resourceError.failingURL().utf8().data(), webError.get()); -} - -static void didCommitLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) -{ - if (!WKFrameIsMainFrame(frame)) - return; - - webkitWebViewLoadChanged(WEBKIT_WEB_VIEW(clientInfo), WEBKIT_LOAD_COMMITTED); -} - -static void didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) -{ - if (!WKFrameIsMainFrame(frame)) - return; - - webkitWebViewLoadChanged(WEBKIT_WEB_VIEW(clientInfo), WEBKIT_LOAD_FINISHED); -} - -static void didFailLoadWithErrorForFrame(WKPageRef page, WKFrameRef frame, WKErrorRef error, WKTypeRef, const void* clientInfo) -{ - if (!WKFrameIsMainFrame(frame)) - return; - - const ResourceError& resourceError = toImpl(error)->platformError(); - GUniquePtr<GError> webError(g_error_new_literal(g_quark_from_string(resourceError.domain().utf8().data()), - resourceError.errorCode(), resourceError.localizedDescription().utf8().data())); - webkitWebViewLoadFailed(WEBKIT_WEB_VIEW(clientInfo), WEBKIT_LOAD_COMMITTED, - resourceError.failingURL().utf8().data(), webError.get()); -} - -static void didSameDocumentNavigationForFrame(WKPageRef page, WKFrameRef frame, WKSameDocumentNavigationType, WKTypeRef, const void* clientInfo) -{ - if (!WKFrameIsMainFrame(frame)) - return; - - webkitWebViewUpdateURI(WEBKIT_WEB_VIEW(clientInfo)); -} - -static void didReceiveTitleForFrame(WKPageRef page, WKStringRef titleRef, WKFrameRef frameRef, WKTypeRef, const void* clientInfo) -{ - if (!WKFrameIsMainFrame(frameRef)) - return; - - webkitWebViewSetTitle(WEBKIT_WEB_VIEW(clientInfo), toImpl(titleRef)->string().utf8()); -} - -static void didDisplayInsecureContentForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo) -{ - webkitWebViewInsecureContentDetected(WEBKIT_WEB_VIEW(clientInfo), WEBKIT_INSECURE_CONTENT_DISPLAYED); -} - -static void didRunInsecureContentForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo) -{ - webkitWebViewInsecureContentDetected(WEBKIT_WEB_VIEW(clientInfo), WEBKIT_INSECURE_CONTENT_RUN); -} - -static void didChangeProgress(WKPageRef page, const void* clientInfo) -{ - webkitWebViewSetEstimatedLoadProgress(WEBKIT_WEB_VIEW(clientInfo), WKPageGetEstimatedProgress(page)); -} - -static void didChangeBackForwardList(WKPageRef page, WKBackForwardListItemRef addedItem, WKArrayRef removedItems, const void* clientInfo) -{ - webkitBackForwardListChanged(webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(clientInfo)), toImpl(addedItem), toImpl(removedItems)); -} - -static void didReceiveAuthenticationChallengeInFrame(WKPageRef page, WKFrameRef frame, WKAuthenticationChallengeRef authenticationChallenge, const void *clientInfo) -{ - webkitWebViewHandleAuthenticationChallenge(WEBKIT_WEB_VIEW(clientInfo), toImpl(authenticationChallenge)); -} - -static void processDidCrash(WKPageRef page, const void* clientInfo) -{ - webkitWebViewWebProcessCrashed(WEBKIT_WEB_VIEW(clientInfo)); -} +class LoaderClient : public API::LoaderClient { +public: + explicit LoaderClient(WebKitWebView* webView) + : m_webView(webView) + { + } + +private: + void didStartProvisionalLoadForFrame(WebPageProxy&, WebFrameProxy& frame, API::Navigation*, API::Object* /* userData */) override + { + if (!frame.isMainFrame()) + return; + webkitWebViewLoadChanged(m_webView, WEBKIT_LOAD_STARTED); + } + + void didReceiveServerRedirectForProvisionalLoadForFrame(WebPageProxy&, WebFrameProxy& frame, API::Navigation*, API::Object* /* userData */) override + { + if (!frame.isMainFrame()) + return; + webkitWebViewLoadChanged(m_webView, WEBKIT_LOAD_REDIRECTED); + } + + void didFailProvisionalLoadWithErrorForFrame(WebPageProxy&, WebFrameProxy& frame, API::Navigation*, const ResourceError& resourceError, API::Object* /* userData */) override + { + if (!frame.isMainFrame()) + return; + GUniquePtr<GError> error(g_error_new_literal(g_quark_from_string(resourceError.domain().utf8().data()), + toWebKitError(resourceError.errorCode()), resourceError.localizedDescription().utf8().data())); + if (resourceError.tlsErrors()) { + webkitWebViewLoadFailedWithTLSErrors(m_webView, resourceError.failingURL().string().utf8().data(), error.get(), + static_cast<GTlsCertificateFlags>(resourceError.tlsErrors()), resourceError.certificate()); + } else + webkitWebViewLoadFailed(m_webView, WEBKIT_LOAD_STARTED, resourceError.failingURL().string().utf8().data(), error.get()); + } + + void didCommitLoadForFrame(WebPageProxy&, WebFrameProxy& frame, API::Navigation*, API::Object* /* userData */) override + { + if (!frame.isMainFrame()) + return; + webkitWebViewLoadChanged(m_webView, WEBKIT_LOAD_COMMITTED); + } + + void didFinishLoadForFrame(WebPageProxy&, WebFrameProxy& frame, API::Navigation*, API::Object* /* userData */) override + { + if (!frame.isMainFrame()) + return; + webkitWebViewLoadChanged(m_webView, WEBKIT_LOAD_FINISHED); + } + + void didFailLoadWithErrorForFrame(WebPageProxy&, WebFrameProxy& frame, API::Navigation*, const ResourceError& resourceError, API::Object* /* userData */) override + { + if (!frame.isMainFrame()) + return; + GUniquePtr<GError> error(g_error_new_literal(g_quark_from_string(resourceError.domain().utf8().data()), + toWebKitError(resourceError.errorCode()), resourceError.localizedDescription().utf8().data())); + webkitWebViewLoadFailed(m_webView, WEBKIT_LOAD_COMMITTED, resourceError.failingURL().string().utf8().data(), error.get()); + } + + void didDisplayInsecureContentForFrame(WebPageProxy&, WebFrameProxy&, API::Object* /* userData */) override + { + webkitWebViewInsecureContentDetected(m_webView, WEBKIT_INSECURE_CONTENT_DISPLAYED); + } + + void didRunInsecureContentForFrame(WebPageProxy&, WebFrameProxy&, API::Object* /* userData */) override + { + webkitWebViewInsecureContentDetected(m_webView, WEBKIT_INSECURE_CONTENT_RUN); + } + + void didChangeBackForwardList(WebPageProxy&, WebBackForwardListItem* addedItem, Vector<RefPtr<WebBackForwardListItem>> removedItems) override + { + webkitBackForwardListChanged(webkit_web_view_get_back_forward_list(m_webView), addedItem, removedItems); + } + + void didReceiveAuthenticationChallengeInFrame(WebPageProxy&, WebFrameProxy&, AuthenticationChallengeProxy* authenticationChallenge) override + { + webkitWebViewHandleAuthenticationChallenge(m_webView, authenticationChallenge); + } + + void processDidCrash(WebPageProxy&) override + { + webkitWebViewWebProcessCrashed(m_webView); + } + + WebKitWebView* m_webView; +}; void attachLoaderClientToView(WebKitWebView* webView) { - WKPageLoaderClientV3 wkLoaderClient = { - { - 3, // version - webView, // clientInfo - }, - didStartProvisionalLoadForFrame, - didReceiveServerRedirectForProvisionalLoadForFrame, - didFailProvisionalLoadWithErrorForFrame, - didCommitLoadForFrame, - 0, // didFinishDocumentLoadForFrame - didFinishLoadForFrame, - didFailLoadWithErrorForFrame, - didSameDocumentNavigationForFrame, - didReceiveTitleForFrame, - 0, // didFirstLayoutForFrame - 0, // didFirstVisuallyNonEmptyLayoutForFrame - 0, // didRemoveFrameFromHierarchy - didDisplayInsecureContentForFrame, - didRunInsecureContentForFrame, - 0, // canAuthenticateAgainstProtectionSpaceInFrame - didReceiveAuthenticationChallengeInFrame, - didChangeProgress, // didStartProgress - didChangeProgress, - didChangeProgress, // didFinishProgress - 0, // didBecomeUnresponsive - 0, // didBecomeResponsive - processDidCrash, - didChangeBackForwardList, - 0, // shouldGoToBackForwardListItem - 0, // didFailToInitializePlugin - 0, // didDetectXSSForFrame - 0, // didFirstVisuallyNonEmptyLayoutForFrame - 0, // willGoToBackForwardListItem - 0, // interactionOccurredWhileProcessUnresponsive - 0, // pluginDidFail_deprecatedForUseWithV1 - 0, // didReceiveIntentForFrame - 0, // registerIntentServiceForFrame - 0, // didLayout - 0, // pluginLoadPolicy_deprecatedForUseWithV2 - 0, // pluginDidFail - 0, // pluginLoadPolicy - }; - WKPageRef wkPage = toAPI(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView))); - WKPageSetPageLoaderClient(wkPage, &wkLoaderClient.base); + WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView)); + page->setLoaderClient(std::make_unique<LoaderClient>(webView)); } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitMimeInfo.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitMimeInfo.cpp index 2282ede37..af61dc69a 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitMimeInfo.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitMimeInfo.cpp @@ -21,7 +21,7 @@ #include "WebKitMimeInfo.h" #include "WebKitMimeInfoPrivate.h" -#include <wtf/gobject/GRefPtr.h> +#include <wtf/glib/GRefPtr.h> #include <wtf/text/CString.h> struct _WebKitMimeInfo { @@ -42,7 +42,7 @@ G_DEFINE_BOXED_TYPE(WebKitMimeInfo, webkit_mime_info, webkit_mime_info_ref, webk WebKitMimeInfo* webkitMimeInfoCreate(const WebCore::MimeClassInfo& mimeInfo) { - WebKitMimeInfo* info = g_slice_new(WebKitMimeInfo); + WebKitMimeInfo* info = static_cast<WebKitMimeInfo*>(fastMalloc(sizeof(WebKitMimeInfo))); new (info) WebKitMimeInfo(mimeInfo); return info; } @@ -75,7 +75,7 @@ void webkit_mime_info_unref(WebKitMimeInfo* info) { if (g_atomic_int_dec_and_test(&info->referenceCount)) { info->~WebKitMimeInfo(); - g_slice_free(WebKitMimeInfo, info); + fastFree(info); } } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationAction.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationAction.cpp new file mode 100644 index 000000000..bcce8ba42 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationAction.cpp @@ -0,0 +1,153 @@ +/* + * Copyright (C) 2014 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "WebKitNavigationAction.h" + +#include "WebKitNavigationActionPrivate.h" +#include <gdk/gdk.h> +#include <wtf/glib/GRefPtr.h> + +using namespace WebKit; + +G_DEFINE_BOXED_TYPE(WebKitNavigationAction, webkit_navigation_action, webkit_navigation_action_copy, webkit_navigation_action_free) + +WebKitNavigationAction* webkitNavigationActionCreate(WebKitURIRequest* request, const NavigationActionData& navigationActionData) +{ + WebKitNavigationAction* navigation = static_cast<WebKitNavigationAction*>(fastZeroedMalloc(sizeof(WebKitNavigationAction))); + new (navigation) WebKitNavigationAction(request, navigationActionData); + return navigation; +} + +/** + * webkit_navigation_action_copy: + * @navigation: a #WebKitNavigationAction + * + * Make a copy of @navigation. + * + * Returns: (transfer full): A copy of passed in #WebKitNavigationAction + * + * Since: 2.6 + */ +WebKitNavigationAction* webkit_navigation_action_copy(WebKitNavigationAction* navigation) +{ + g_return_val_if_fail(navigation, nullptr); + + WebKitNavigationAction* copy = static_cast<WebKitNavigationAction*>(fastZeroedMalloc(sizeof(WebKitNavigationAction))); + new (copy) WebKitNavigationAction(navigation); + return copy; +} + +/** + * webkit_navigation_action_free: + * @navigation: a #WebKitNavigationAction + * + * Free the #WebKitNavigationAction + * + * Since: 2.6 + */ +void webkit_navigation_action_free(WebKitNavigationAction* navigation) +{ + g_return_if_fail(navigation); + + navigation->~WebKitNavigationAction(); + fastFree(navigation); +} + +/** + * webkit_navigation_action_get_navigation_type: + * @navigation: a #WebKitNavigationAction + * + * Return the type of action that triggered the navigation. + * + * Returns: a #WebKitNavigationType + * + * Since: 2.6 + */ +WebKitNavigationType webkit_navigation_action_get_navigation_type(WebKitNavigationAction* navigation) +{ + g_return_val_if_fail(navigation, WEBKIT_NAVIGATION_TYPE_OTHER); + return navigation->type; +} + +/** + * webkit_navigation_action_get_mouse_button: + * @navigation: a #WebKitNavigationAction + * + * Return the number of the mouse button that triggered the navigation, or 0 if + * the navigation was not started by a mouse event. + * + * Returns: the mouse button number or 0 + * + * Since: 2.6 + */ +unsigned webkit_navigation_action_get_mouse_button(WebKitNavigationAction* navigation) +{ + g_return_val_if_fail(navigation, 0); + return navigation->mouseButton; +} + +/** + * webkit_navigation_action_get_modifiers: + * @navigation: a #WebKitNavigationAction + * + * Return a bitmask of #GdkModifierType values describing the modifier keys that were in effect + * when the navigation was requested + * + * Returns: the modifier keys + * + * Since: 2.6 + */ +unsigned webkit_navigation_action_get_modifiers(WebKitNavigationAction* navigation) +{ + g_return_val_if_fail(navigation, 0); + return navigation->modifiers; +} + +/** + * webkit_navigation_action_get_request: + * @navigation: a #WebKitNavigationAction + * + * Return the navigation #WebKitURIRequest + * + * Returns: (transfer none): a #WebKitURIRequest + * + * Since: 2.6 + */ +WebKitURIRequest* webkit_navigation_action_get_request(WebKitNavigationAction* navigation) +{ + g_return_val_if_fail(navigation, nullptr); + return navigation->request.get(); +} + +/** + * webkit_navigation_action_is_user_gesture: + * @navigation: a #WebKitNavigationAction + * + * Return whether the navigation was triggered by a user gesture like a mouse click. + * + * Returns: whether navigation action is a user gesture + * + * Since: 2.6 + */ +gboolean webkit_navigation_action_is_user_gesture(WebKitNavigationAction* navigation) +{ + g_return_val_if_fail(navigation, FALSE); + return navigation->isUserGesture; +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationAction.h b/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationAction.h new file mode 100644 index 000000000..ae95586bc --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationAction.h @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2014 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) +#error "Only <webkit2/webkit2.h> can be included directly." +#endif + +#ifndef WebKitNavigationAction_h +#define WebKitNavigationAction_h + +#include <glib-object.h> +#include <webkit2/WebKitDefines.h> +#include <webkit2/WebKitURIRequest.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_NAVIGATION_ACTION (webkit_navigation_action_get_type()) + +/** + * WebKitNavigationType: + * @WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: The navigation was triggered by clicking a link. + * @WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: The navigation was triggered by submitting a form. + * @WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: The navigation was triggered by navigating forward or backward. + * @WEBKIT_NAVIGATION_TYPE_RELOAD: The navigation was triggered by reloading. + * @WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED: The navigation was triggered by resubmitting a form. + * @WEBKIT_NAVIGATION_TYPE_OTHER: The navigation was triggered by some other action. + * + * Enum values used to denote the various navigation types. + */ +typedef enum { + WEBKIT_NAVIGATION_TYPE_LINK_CLICKED, + WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED, + WEBKIT_NAVIGATION_TYPE_BACK_FORWARD, + WEBKIT_NAVIGATION_TYPE_RELOAD, + WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED, + WEBKIT_NAVIGATION_TYPE_OTHER +} WebKitNavigationType; + +typedef struct _WebKitNavigationAction WebKitNavigationAction; + + +WEBKIT_API GType +webkit_navigation_action_get_type (void); + +WEBKIT_API WebKitNavigationAction * +webkit_navigation_action_copy (WebKitNavigationAction *navigation); + +WEBKIT_API void +webkit_navigation_action_free (WebKitNavigationAction *navigation); + +WEBKIT_API WebKitNavigationType +webkit_navigation_action_get_navigation_type (WebKitNavigationAction *navigation); + +WEBKIT_API guint +webkit_navigation_action_get_mouse_button (WebKitNavigationAction *navigation); + +WEBKIT_API guint +webkit_navigation_action_get_modifiers (WebKitNavigationAction *navigation); + +WEBKIT_API WebKitURIRequest * +webkit_navigation_action_get_request (WebKitNavigationAction *navigation); + +WEBKIT_API gboolean +webkit_navigation_action_is_user_gesture (WebKitNavigationAction *navigation); + +G_END_DECLS + +#endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationActionPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationActionPrivate.h new file mode 100644 index 000000000..97fc8b36e --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationActionPrivate.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2014 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef WebKitNavigationActionPrivate_h +#define WebKitNavigationActionPrivate_h + +#include "NavigationActionData.h" +#include "WebKitNavigationAction.h" +#include "WebKitPrivate.h" + +struct _WebKitNavigationAction { + _WebKitNavigationAction(WebKitURIRequest* uriRequest, const WebKit::NavigationActionData& navigationActionData) + : type(toWebKitNavigationType(navigationActionData.navigationType)) + , mouseButton(toWebKitMouseButton(navigationActionData.mouseButton)) + , modifiers(toGdkModifiers(navigationActionData.modifiers)) + , isUserGesture(navigationActionData.isProcessingUserGesture) + , request(uriRequest) + { + } + + _WebKitNavigationAction(WebKitNavigationAction* navigation) + : type(navigation->type) + , mouseButton(navigation->mouseButton) + , modifiers(navigation->modifiers) + , isUserGesture(navigation->isUserGesture) + , request(navigation->request) + { + } + + WebKitNavigationType type; + unsigned mouseButton; + unsigned modifiers; + bool isUserGesture : 1; + GRefPtr<WebKitURIRequest> request; +}; + +WebKitNavigationAction* webkitNavigationActionCreate(WebKitURIRequest*, const WebKit::NavigationActionData&); + +#endif // WebKitNavigationActionPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationPolicyDecision.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationPolicyDecision.cpp index f03446bab..e5769723c 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationPolicyDecision.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationPolicyDecision.cpp @@ -20,13 +20,13 @@ #include "config.h" #include "WebKitNavigationPolicyDecision.h" -#include "APIURLRequest.h" -#include "WebEvent.h" #include "WebKitEnumTypes.h" +#include "WebKitNavigationActionPrivate.h" +#include "WebKitNavigationPolicyDecisionPrivate.h" #include "WebKitPolicyDecisionPrivate.h" #include "WebKitURIRequestPrivate.h" #include <glib/gi18n-lib.h> -#include <wtf/gobject/GRefPtr.h> +#include <wtf/glib/GRefPtr.h> #include <wtf/text/CString.h> using namespace WebKit; @@ -44,10 +44,12 @@ using namespace WebCore; */ struct _WebKitNavigationPolicyDecisionPrivate { - WebKitNavigationType navigationType; - unsigned modifiers; - unsigned mouseButton; - GRefPtr<WebKitURIRequest> request; + ~_WebKitNavigationPolicyDecisionPrivate() + { + webkit_navigation_action_free(navigationAction); + } + + WebKitNavigationAction* navigationAction; CString frameName; }; @@ -55,6 +57,7 @@ WEBKIT_DEFINE_TYPE(WebKitNavigationPolicyDecision, webkit_navigation_policy_deci enum { PROP_0, + PROP_NAVIGATION_ACTION, PROP_NAVIGATION_TYPE, PROP_MOUSE_BUTTON, PROP_MODIFIERS, @@ -66,17 +69,20 @@ static void webkitNavigationPolicyDecisionGetProperty(GObject* object, guint pro { WebKitNavigationPolicyDecision* decision = WEBKIT_NAVIGATION_POLICY_DECISION(object); switch (propId) { + case PROP_NAVIGATION_ACTION: + g_value_set_boxed(value, webkit_navigation_policy_decision_get_navigation_action(decision)); + break; case PROP_NAVIGATION_TYPE: - g_value_set_enum(value, webkit_navigation_policy_decision_get_navigation_type(decision)); + g_value_set_enum(value, webkit_navigation_action_get_navigation_type(decision->priv->navigationAction)); break; case PROP_MOUSE_BUTTON: - g_value_set_enum(value, webkit_navigation_policy_decision_get_mouse_button(decision)); + g_value_set_enum(value, webkit_navigation_action_get_mouse_button(decision->priv->navigationAction)); break; case PROP_MODIFIERS: - g_value_set_uint(value, webkit_navigation_policy_decision_get_modifiers(decision)); + g_value_set_uint(value, webkit_navigation_action_get_modifiers(decision->priv->navigationAction)); break; case PROP_REQUEST: - g_value_set_object(value, webkit_navigation_policy_decision_get_request(decision)); + g_value_set_object(value, webkit_navigation_action_get_request(decision->priv->navigationAction)); break; case PROP_FRAME_NAME: g_value_set_string(value, webkit_navigation_policy_decision_get_frame_name(decision)); @@ -93,11 +99,30 @@ static void webkit_navigation_policy_decision_class_init(WebKitNavigationPolicyD objectClass->get_property = webkitNavigationPolicyDecisionGetProperty; /** + * WebKitNavigationPolicyDecision:navigation-action: + * + * The #WebKitNavigationAction that triggered this policy decision. + * + * Since: 2.6 + */ + g_object_class_install_property( + objectClass, + PROP_NAVIGATION_ACTION, + g_param_spec_boxed( + "navigation-action", + _("Navigation action"), + _("The WebKitNavigationAction triggering this decision"), + WEBKIT_TYPE_NAVIGATION_ACTION, + WEBKIT_PARAM_READABLE)); + + /** * WebKitNavigationPolicyDecision:navigation-type: * * The type of navigation that triggered this policy decision. This is * useful for enacting different policies depending on what type of user * action caused the navigation. + * + * Deprecated: 2.6: Use #WebKitNavigationPolicyDecision:navigation-action instead */ g_object_class_install_property(objectClass, PROP_NAVIGATION_TYPE, @@ -116,6 +141,8 @@ static void webkit_navigation_policy_decision_class_init(WebKitNavigationPolicyD * of the button triggering that event. The button numbers match those from GDK. * If the navigation was not triggered by a mouse event, the value of this * property will be 0. + * + * Deprecated: 2.6: Use #WebKitNavigationPolicyDecision:navigation-action instead */ g_object_class_install_property(objectClass, PROP_MOUSE_BUTTON, @@ -133,6 +160,8 @@ static void webkit_navigation_policy_decision_class_init(WebKitNavigationPolicyD * #GdkModifierType values describing the modifiers used for that click. * If the navigation was not triggered by a mouse event or no modifiers * were active, the value of this property will be zero. + * + * Deprecated: 2.6: Use #WebKitNavigationPolicyDecision:navigation-action instead */ g_object_class_install_property(objectClass, PROP_MODIFIERS, @@ -147,6 +176,8 @@ static void webkit_navigation_policy_decision_class_init(WebKitNavigationPolicyD * * This property contains the #WebKitURIRequest associated with this * navigation. + * + * Deprecated: 2.6: Use #WebKitNavigationPolicyDecision:navigation-action instead */ g_object_class_install_property(objectClass, PROP_REQUEST, @@ -174,17 +205,35 @@ static void webkit_navigation_policy_decision_class_init(WebKitNavigationPolicyD } /** + * webkit_navigation_policy_decision_get_navigation_action: + * @decision: a #WebKitNavigationPolicyDecision + * + * Gets the value of the #WebKitNavigationPolicyDecision:navigation-action property. + * + * Returns: (transfer none): The #WebKitNavigationAction triggering this policy decision. + * + * Since: 2.6 + */ +WebKitNavigationAction* webkit_navigation_policy_decision_get_navigation_action(WebKitNavigationPolicyDecision* decision) +{ + g_return_val_if_fail(WEBKIT_IS_NAVIGATION_POLICY_DECISION(decision), nullptr); + return decision->priv->navigationAction; +} + +/** * webkit_navigation_policy_decision_get_navigation_type: * @decision: a #WebKitNavigationPolicyDecision * * Gets the value of the #WebKitNavigationPolicyDecision:navigation-type property. * * Returns: The type of navigation triggering this policy decision. + * + * Deprecated: 2.6: Use webkit_navigation_policy_decision_get_navigation_action() instead. */ WebKitNavigationType webkit_navigation_policy_decision_get_navigation_type(WebKitNavigationPolicyDecision* decision) { g_return_val_if_fail(WEBKIT_IS_NAVIGATION_POLICY_DECISION(decision), WEBKIT_NAVIGATION_TYPE_OTHER); - return decision->priv->navigationType; + return webkit_navigation_action_get_navigation_type(decision->priv->navigationAction); } /** @@ -194,11 +243,13 @@ WebKitNavigationType webkit_navigation_policy_decision_get_navigation_type(WebKi * Gets the value of the #WebKitNavigationPolicyDecision:mouse-button property. * * Returns: The mouse button used if this decision was triggered by a mouse event or 0 otherwise + * + * Deprecated: 2.6: Use webkit_navigation_policy_decision_get_navigation_action() instead. */ guint webkit_navigation_policy_decision_get_mouse_button(WebKitNavigationPolicyDecision* decision) { g_return_val_if_fail(WEBKIT_IS_NAVIGATION_POLICY_DECISION(decision), 0); - return decision->priv->mouseButton; + return webkit_navigation_action_get_mouse_button(decision->priv->navigationAction); } /** @@ -208,11 +259,13 @@ guint webkit_navigation_policy_decision_get_mouse_button(WebKitNavigationPolicyD * Gets the value of the #WebKitNavigationPolicyDecision:modifiers property. * * Returns: The modifiers active if this decision was triggered by a mouse event + * + * Deprecated: 2.6: Use webkit_navigation_policy_decision_get_navigation_action() instead. */ unsigned webkit_navigation_policy_decision_get_modifiers(WebKitNavigationPolicyDecision* decision) { g_return_val_if_fail(WEBKIT_IS_NAVIGATION_POLICY_DECISION(decision), 0); - return decision->priv->modifiers; + return webkit_navigation_action_get_modifiers(decision->priv->navigationAction); } /** @@ -222,11 +275,13 @@ unsigned webkit_navigation_policy_decision_get_modifiers(WebKitNavigationPolicyD * Gets the value of the #WebKitNavigationPolicyDecision:request property. * * Returns: (transfer none): The URI request that is associated with this navigation + * + * Deprecated: 2.6: Use webkit_navigation_policy_decision_get_navigation_action() instead. */ WebKitURIRequest* webkit_navigation_policy_decision_get_request(WebKitNavigationPolicyDecision* decision) { - g_return_val_if_fail(WEBKIT_IS_NAVIGATION_POLICY_DECISION(decision), 0); - return decision->priv->request.get(); + g_return_val_if_fail(WEBKIT_IS_NAVIGATION_POLICY_DECISION(decision), nullptr); + return webkit_navigation_action_get_request(decision->priv->navigationAction); } /** @@ -243,21 +298,19 @@ const char* webkit_navigation_policy_decision_get_frame_name(WebKitNavigationPol return decision->priv->frameName.data(); } -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_NAVIGATION_TYPE_LINK_CLICKED, NavigationTypeLinkClicked); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED, NavigationTypeFormSubmitted); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_NAVIGATION_TYPE_BACK_FORWARD, NavigationTypeBackForward); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_NAVIGATION_TYPE_RELOAD, NavigationTypeReload); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED, NavigationTypeFormResubmitted); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_NAVIGATION_TYPE_OTHER, NavigationTypeOther); +WebKitPolicyDecision* webkitNavigationPolicyDecisionCreate(const NavigationActionData& navigationActionData, const ResourceRequest& request, WebFramePolicyListenerProxy* listener) +{ + WebKitNavigationPolicyDecision* navigationDecision = WEBKIT_NAVIGATION_POLICY_DECISION(g_object_new(WEBKIT_TYPE_NAVIGATION_POLICY_DECISION, nullptr)); + GRefPtr<WebKitURIRequest> uriRequest = adoptGRef(webkitURIRequestCreateForResourceRequest(request)); + navigationDecision->priv->navigationAction = webkitNavigationActionCreate(uriRequest.get(), navigationActionData); + WebKitPolicyDecision* decision = WEBKIT_POLICY_DECISION(navigationDecision); + webkitPolicyDecisionSetListener(decision, listener); + return decision; +} -WebKitNavigationPolicyDecision* webkitNavigationPolicyDecisionCreate(WebKitNavigationType navigationType, unsigned mouseButton, unsigned modifiers, API::URLRequest* request, const char* frameName, WebFramePolicyListenerProxy* listener) +WebKitPolicyDecision* webkitNewWindowPolicyDecisionCreate(const NavigationActionData& navigationActionData, const ResourceRequest& request, const String& frameName, WebFramePolicyListenerProxy* listener) { - WebKitNavigationPolicyDecision* decision = WEBKIT_NAVIGATION_POLICY_DECISION(g_object_new(WEBKIT_TYPE_NAVIGATION_POLICY_DECISION, NULL)); - decision->priv->navigationType = navigationType; - decision->priv->mouseButton = mouseButton; - decision->priv->modifiers = modifiers; - decision->priv->request = adoptGRef(webkitURIRequestCreateForResourceRequest(request->resourceRequest())); - decision->priv->frameName = frameName; - webkitPolicyDecisionSetListener(WEBKIT_POLICY_DECISION(decision), listener); + WebKitPolicyDecision* decision = webkitNavigationPolicyDecisionCreate(navigationActionData, request, listener); + WEBKIT_NAVIGATION_POLICY_DECISION(decision)->priv->frameName = frameName.utf8().data(); return decision; } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationPolicyDecision.h b/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationPolicyDecision.h index 751397731..0d9fb261a 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationPolicyDecision.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationPolicyDecision.h @@ -26,31 +26,12 @@ #include <glib-object.h> #include <webkit2/WebKitDefines.h> +#include <webkit2/WebKitNavigationAction.h> #include <webkit2/WebKitPolicyDecision.h> #include <webkit2/WebKitURIRequest.h> G_BEGIN_DECLS -/** - * WebKitNavigationType: - * @WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: The navigation was triggered by clicking a link. - * @WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: The navigation was triggered by submitting a form. - * @WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: The navigation was triggered by navigating forward or backward. - * @WEBKIT_NAVIGATION_TYPE_RELOAD: The navigation was triggered by reloading. - * @WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED: The navigation was triggered by resubmitting a form. - * @WEBKIT_NAVIGATION_TYPE_OTHER: The navigation was triggered by some other action. - * - * Enum values used to denote the various navigation types. - */ -typedef enum { - WEBKIT_NAVIGATION_TYPE_LINK_CLICKED, - WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED, - WEBKIT_NAVIGATION_TYPE_BACK_FORWARD, - WEBKIT_NAVIGATION_TYPE_RELOAD, - WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED, - WEBKIT_NAVIGATION_TYPE_OTHER, -} WebKitNavigationType; - #define WEBKIT_TYPE_NAVIGATION_POLICY_DECISION (webkit_navigation_policy_decision_get_type()) #define WEBKIT_NAVIGATION_POLICY_DECISION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_NAVIGATION_POLICY_DECISION, WebKitNavigationPolicyDecision)) #define WEBKIT_NAVIGATION_POLICY_DECISION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_NAVIGATION_POLICY_DECISION, WebKitNavigationPolicyDecisionClass)) @@ -81,16 +62,24 @@ struct _WebKitNavigationPolicyDecisionClass { WEBKIT_API GType webkit_navigation_policy_decision_get_type (void); -WEBKIT_API WebKitNavigationType -webkit_navigation_policy_decision_get_navigation_type (WebKitNavigationPolicyDecision *decision); -WEBKIT_API guint -webkit_navigation_policy_decision_get_mouse_button (WebKitNavigationPolicyDecision *decision); -WEBKIT_API guint -webkit_navigation_policy_decision_get_modifiers (WebKitNavigationPolicyDecision *decision); -WEBKIT_API WebKitURIRequest * -webkit_navigation_policy_decision_get_request (WebKitNavigationPolicyDecision *decision); +WEBKIT_API WebKitNavigationAction * +webkit_navigation_policy_decision_get_navigation_action (WebKitNavigationPolicyDecision *decision); + +WEBKIT_DEPRECATED_FOR(webkit_navigation_policy_decision_get_navigation_action) WebKitNavigationType +webkit_navigation_policy_decision_get_navigation_type (WebKitNavigationPolicyDecision *decision); + +WEBKIT_DEPRECATED_FOR(webkit_navigation_policy_decision_get_navigation_action) guint +webkit_navigation_policy_decision_get_mouse_button (WebKitNavigationPolicyDecision *decision); + +WEBKIT_DEPRECATED_FOR(webkit_navigation_policy_decision_get_navigation_action) guint +webkit_navigation_policy_decision_get_modifiers (WebKitNavigationPolicyDecision *decision); + +WEBKIT_DEPRECATED_FOR(webkit_navigation_policy_decision_get_navigation_action) WebKitURIRequest * +webkit_navigation_policy_decision_get_request (WebKitNavigationPolicyDecision *decision); + WEBKIT_API const gchar * -webkit_navigation_policy_decision_get_frame_name (WebKitNavigationPolicyDecision *decision); +webkit_navigation_policy_decision_get_frame_name (WebKitNavigationPolicyDecision *decision); + G_END_DECLS #endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationPolicyDecisionPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationPolicyDecisionPrivate.h index 84ee827cd..9d94ee00e 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationPolicyDecisionPrivate.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationPolicyDecisionPrivate.h @@ -20,9 +20,11 @@ #ifndef WebKitNavigationPolicyDecisionPrivate_h #define WebKitNavigationPolicyDecisionPrivate_h +#include "NavigationActionData.h" #include "WebKitNavigationPolicyDecision.h" #include "WebKitPrivate.h" -WebKitNavigationPolicyDecision* webkitNavigationPolicyDecisionCreate(WebKitNavigationType, unsigned mouseButton, unsigned modifiers, API::URLRequest*, const char* frameName, WebKit::WebFramePolicyListenerProxy*); +WebKitPolicyDecision* webkitNavigationPolicyDecisionCreate(const WebKit::NavigationActionData&, const WebCore::ResourceRequest&, WebKit::WebFramePolicyListenerProxy*); +WebKitPolicyDecision* webkitNewWindowPolicyDecisionCreate(const WebKit::NavigationActionData&, const WebCore::ResourceRequest&, const String& frameName, WebKit::WebFramePolicyListenerProxy*); #endif // WebKitNavigationPolicyDecisionPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.cpp new file mode 100644 index 000000000..b17f2e192 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.cpp @@ -0,0 +1,268 @@ +/* + * Copyright (C) 2014 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "WebKitNotification.h" + +#include "WebKitNotificationPrivate.h" +#include "WebKitPrivate.h" +#include "WebNotification.h" +#include <glib/gi18n-lib.h> +#include <wtf/text/CString.h> + +/** + * SECTION: WebKitNotification + * @Short_description: Object used to hold information about a notification that should be shown to the user. + * @Title: WebKitNotification + * + * Since: 2.8 + */ + +enum { + PROP_0, + + PROP_ID, + PROP_TITLE, + PROP_BODY +}; + +enum { + CLOSED, + CLICKED, + + LAST_SIGNAL +}; + +struct _WebKitNotificationPrivate { + CString title; + CString body; + guint64 id; + + WebKitWebView* webView; +}; + +static guint signals[LAST_SIGNAL] = { 0, }; + +WEBKIT_DEFINE_TYPE(WebKitNotification, webkit_notification, G_TYPE_OBJECT) + +static void webkitNotificationGetProperty(GObject* object, guint propId, GValue* value, GParamSpec* paramSpec) +{ + WebKitNotification* notification = WEBKIT_NOTIFICATION(object); + + switch (propId) { + case PROP_ID: + g_value_set_uint64(value, webkit_notification_get_id(notification)); + break; + case PROP_TITLE: + g_value_set_string(value, webkit_notification_get_title(notification)); + break; + case PROP_BODY: + g_value_set_string(value, webkit_notification_get_body(notification)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); + } +} + +static void webkit_notification_class_init(WebKitNotificationClass* notificationClass) +{ + GObjectClass* objectClass = G_OBJECT_CLASS(notificationClass); + objectClass->get_property = webkitNotificationGetProperty; + + /** + * WebKitNotification:id: + * + * The unique id for the notification. + * + * Since: 2.8 + */ + g_object_class_install_property(objectClass, + PROP_ID, + g_param_spec_uint64("id", + _("ID"), + _("The unique id for the notification"), + 0, G_MAXUINT64, 0, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitNotification:title: + * + * The title for the notification. + * + * Since: 2.8 + */ + g_object_class_install_property(objectClass, + PROP_TITLE, + g_param_spec_string("title", + _("Title"), + _("The title for the notification"), + nullptr, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitNotification:body: + * + * The body for the notification. + * + * Since: 2.8 + */ + g_object_class_install_property(objectClass, + PROP_BODY, + g_param_spec_string("body", + _("Body"), + _("The body for the notification"), + nullptr, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitNotification::closed: + * @notification: the #WebKitNotification on which the signal is emitted + * + * Emitted when a notification has been withdrawn. + * + * The default handler will close the notification using libnotify, if built with + * support for it. + * + * Since: 2.8 + */ + signals[CLOSED] = + g_signal_new( + "closed", + G_TYPE_FROM_CLASS(notificationClass), + G_SIGNAL_RUN_LAST, + 0, 0, + nullptr, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + /** + * WebKitNotification::clicked: + * @notification: the #WebKitNotification on which the signal is emitted + * + * Emitted when a notification has been clicked. See webkit_notification_clicked(). + * + * Since: 2.12 + */ + signals[CLICKED] = + g_signal_new( + "clicked", + G_TYPE_FROM_CLASS(notificationClass), + G_SIGNAL_RUN_LAST, + 0, 0, + nullptr, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); +} + +WebKitNotification* webkitNotificationCreate(WebKitWebView* webView, const WebKit::WebNotification& webNotification) +{ + WebKitNotification* notification = WEBKIT_NOTIFICATION(g_object_new(WEBKIT_TYPE_NOTIFICATION, nullptr)); + notification->priv->id = webNotification.notificationID(); + notification->priv->title = webNotification.title().utf8(); + notification->priv->body = webNotification.body().utf8(); + notification->priv->webView = webView; + return notification; +} + +WebKitWebView* webkitNotificationGetWebView(WebKitNotification* notification) +{ + return notification->priv->webView; +} + +/** + * webkit_notification_get_id: + * @notification: a #WebKitNotification + * + * Obtains the unique id for the notification. + * + * Returns: the unique id for the notification + * + * Since: 2.8 + */ +guint64 webkit_notification_get_id(WebKitNotification* notification) +{ + g_return_val_if_fail(WEBKIT_IS_NOTIFICATION(notification), 0); + + return notification->priv->id; +} + +/** + * webkit_notification_get_title: + * @notification: a #WebKitNotification + * + * Obtains the title for the notification. + * + * Returns: the title for the notification + * + * Since: 2.8 + */ +const gchar* webkit_notification_get_title(WebKitNotification* notification) +{ + g_return_val_if_fail(WEBKIT_IS_NOTIFICATION(notification), nullptr); + + return notification->priv->title.data(); +} + +/** + * webkit_notification_get_body: + * @notification: a #WebKitNotification + * + * Obtains the body for the notification. + * + * Returns: the body for the notification + * + * Since: 2.8 + */ +const gchar* webkit_notification_get_body(WebKitNotification* notification) +{ + g_return_val_if_fail(WEBKIT_IS_NOTIFICATION(notification), nullptr); + + return notification->priv->body.data(); +} + +/** + * webkit_notification_close: + * @notification: a #WebKitNotification + * + * Closes the notification. + * + * Since: 2.8 + */ +void webkit_notification_close(WebKitNotification* notification) +{ + g_return_if_fail(WEBKIT_IS_NOTIFICATION(notification)); + + g_signal_emit(notification, signals[CLOSED], 0); +} + +/** + * webkit_notification_clicked: + * @notification: a #WebKitNotification + * + * Tells WebKit the notification has been clicked. This will emit the + * #WebKitNotification::clicked signal. + * + * Since: 2.12 + */ +void webkit_notification_clicked(WebKitNotification* notification) +{ + g_return_if_fail(WEBKIT_IS_NOTIFICATION(notification)); + + g_signal_emit(notification, signals[CLICKED], 0); +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.h b/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.h new file mode 100644 index 000000000..f99dd984a --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2014 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) +#error "Only <webkit2/webkit2.h> can be included directly." +#endif + +#ifndef WebKitNotification_h +#define WebKitNotification_h + +#include <glib-object.h> +#include <webkit2/WebKitDefines.h> +#include <webkit2/WebKitForwardDeclarations.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_NOTIFICATION (webkit_notification_get_type()) +#define WEBKIT_NOTIFICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_NOTIFICATION, WebKitNotification)) +#define WEBKIT_IS_NOTIFICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_NOTIFICATION)) +#define WEBKIT_NOTIFICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_NOTIFICATION, WebKitNotificationClass)) +#define WEBKIT_IS_NOTIFICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_NOTIFICATION)) +#define WEBKIT_NOTIFICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_NOTIFICATION, WebKitNotificationClass)) + +typedef struct _WebKitNotification WebKitNotification; +typedef struct _WebKitNotificationClass WebKitNotificationClass; +typedef struct _WebKitNotificationPrivate WebKitNotificationPrivate; + +struct _WebKitNotification { + GObject parent; + + WebKitNotificationPrivate *priv; +}; + +struct _WebKitNotificationClass { + GObjectClass parent_class; + + void (*_webkit_reserved0) (void); + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); + void (*_webkit_reserved4) (void); + void (*_webkit_reserved5) (void); +}; + +WEBKIT_API GType +webkit_notification_get_type (void); + +WEBKIT_API guint64 +webkit_notification_get_id (WebKitNotification *notification); + +WEBKIT_API const gchar * +webkit_notification_get_title (WebKitNotification *notification); + +WEBKIT_API const gchar * +webkit_notification_get_body (WebKitNotification *notification); + +WEBKIT_API void +webkit_notification_close (WebKitNotification *notification); + +WEBKIT_API void +webkit_notification_clicked (WebKitNotification *notification); + +G_END_DECLS + +#endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationPermissionRequest.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationPermissionRequest.cpp new file mode 100644 index 000000000..2df447455 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationPermissionRequest.cpp @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2013 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "WebKitNotificationPermissionRequest.h" + +#include "NotificationPermissionRequest.h" +#include "WebKitNotificationPermissionRequestPrivate.h" +#include "WebKitPermissionRequest.h" + +using namespace WebKit; + +/** + * SECTION: WebKitNotificationPermissionRequest + * @Short_description: A permission request for displaying web notifications + * @Title: WebKitNotificationPermissionRequest + * @See_also: #WebKitPermissionRequest, #WebKitWebView + * + * WebKitNotificationPermissionRequest represents a request for + * permission to decide whether WebKit should provide the user with + * notifications through the Web Notification API. + * + * When a WebKitNotificationPermissionRequest is not handled by the user, + * it is denied by default. + * + * Since: 2.8 + */ + +static void webkit_permission_request_interface_init(WebKitPermissionRequestIface*); + +struct _WebKitNotificationPermissionRequestPrivate { + RefPtr<NotificationPermissionRequest> request; + bool madeDecision; +}; + +WEBKIT_DEFINE_TYPE_WITH_CODE( + WebKitNotificationPermissionRequest, webkit_notification_permission_request, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE(WEBKIT_TYPE_PERMISSION_REQUEST, webkit_permission_request_interface_init)) + +static void webkitNotificationPermissionRequestAllow(WebKitPermissionRequest* request) +{ + ASSERT(WEBKIT_IS_NOTIFICATION_PERMISSION_REQUEST(request)); + + WebKitNotificationPermissionRequestPrivate* priv = WEBKIT_NOTIFICATION_PERMISSION_REQUEST(request)->priv; + + // Only one decision at a time. + if (priv->madeDecision) + return; + + priv->request->allow(); + priv->madeDecision = true; +} + +static void webkitNotificationPermissionRequestDeny(WebKitPermissionRequest* request) +{ + ASSERT(WEBKIT_IS_NOTIFICATION_PERMISSION_REQUEST(request)); + + WebKitNotificationPermissionRequestPrivate* priv = WEBKIT_NOTIFICATION_PERMISSION_REQUEST(request)->priv; + + // Only one decision at a time. + if (priv->madeDecision) + return; + + priv->request->deny(); + priv->madeDecision = true; +} + +static void webkit_permission_request_interface_init(WebKitPermissionRequestIface* iface) +{ + iface->allow = webkitNotificationPermissionRequestAllow; + iface->deny = webkitNotificationPermissionRequestDeny; +} + +static void webkitNotificationPermissionRequestDispose(GObject* object) +{ + // Default behaviour when no decision has been made is denying the request. + webkitNotificationPermissionRequestDeny(WEBKIT_PERMISSION_REQUEST(object)); + G_OBJECT_CLASS(webkit_notification_permission_request_parent_class)->dispose(object); +} + +static void webkit_notification_permission_request_class_init(WebKitNotificationPermissionRequestClass* klass) +{ + GObjectClass* objectClass = G_OBJECT_CLASS(klass); + objectClass->dispose = webkitNotificationPermissionRequestDispose; +} + +WebKitNotificationPermissionRequest* webkitNotificationPermissionRequestCreate(NotificationPermissionRequest* request) +{ + WebKitNotificationPermissionRequest* notificationPermissionRequest = WEBKIT_NOTIFICATION_PERMISSION_REQUEST(g_object_new(WEBKIT_TYPE_NOTIFICATION_PERMISSION_REQUEST, nullptr)); + notificationPermissionRequest->priv->request = request; + return notificationPermissionRequest; +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationPermissionRequest.h b/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationPermissionRequest.h new file mode 100644 index 000000000..d2fb41104 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationPermissionRequest.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2013 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) +#error "Only <webkit2/webkit2.h> can be included directly." +#endif + +#ifndef WebKitNotificationPermissionRequest_h +#define WebKitNotificationPermissionRequest_h + +#include <glib-object.h> +#include <webkit2/WebKitDefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_NOTIFICATION_PERMISSION_REQUEST (webkit_notification_permission_request_get_type()) +#define WEBKIT_NOTIFICATION_PERMISSION_REQUEST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_NOTIFICATION_PERMISSION_REQUEST, WebKitNotificationPermissionRequest)) +#define WEBKIT_NOTIFICATION_PERMISSION_REQUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_NOTIFICATION_PERMISSION_REQUEST, WebKitNotificationPermissionRequestClass)) +#define WEBKIT_IS_NOTIFICATION_PERMISSION_REQUEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_NOTIFICATION_PERMISSION_REQUEST)) +#define WEBKIT_IS_NOTIFICATION_PERMISSION_REQUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_NOTIFICATION_PERMISSION_REQUEST)) +#define WEBKIT_NOTIFICATION_PERMISSION_REQUEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_NOTIFICATION_PERMISSION_REQUEST, WebKitNotificationPermissionRequestClass)) + +typedef struct _WebKitNotificationPermissionRequest WebKitNotificationPermissionRequest; +typedef struct _WebKitNotificationPermissionRequestClass WebKitNotificationPermissionRequestClass; +typedef struct _WebKitNotificationPermissionRequestPrivate WebKitNotificationPermissionRequestPrivate; + +struct _WebKitNotificationPermissionRequest { + GObject parent; + + /*< private >*/ + WebKitNotificationPermissionRequestPrivate *priv; +}; + +struct _WebKitNotificationPermissionRequestClass { + GObjectClass parent_class; +}; + +WEBKIT_API GType +webkit_notification_permission_request_get_type (void); + +G_END_DECLS + +#endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewGroupPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationPermissionRequestPrivate.h index 5fd865610..c23707e76 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewGroupPrivate.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationPermissionRequestPrivate.h @@ -17,13 +17,12 @@ * Boston, MA 02110-1301, USA. */ -#ifndef WebKitWebViewGroupPrivate_h -#define WebKitWebViewGroupPrivate_h +#ifndef WebKitNotificationPermissionRequestPrivate_h +#define WebKitNotificationPermissionRequestPrivate_h -#include "WebKitWebViewGroup.h" -#include "WebPageGroup.h" +#include "WebKitNotificationPermissionRequest.h" +#include "WebKitPrivate.h" -WebKitWebViewGroup* webkitWebViewGroupCreate(WebKit::WebPageGroup*); -WebKit::WebPageGroup* webkitWebViewGroupGetPageGroup(WebKitWebViewGroup*); +WebKitNotificationPermissionRequest* webkitNotificationPermissionRequestCreate(WebKit::NotificationPermissionRequest*); -#endif // WebKitWebViewGroupPrivate_h +#endif // WebKitNotificationPermissionRequestPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationPrivate.h new file mode 100644 index 000000000..49e9a6087 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationPrivate.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2014 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef WebKitNotificationPrivate_h +#define WebKitNotificationPrivate_h + +#include "WebKitNotification.h" +#include "WebKitPrivate.h" +#include "WebNotification.h" +#include <wtf/text/CString.h> + +WebKitNotification* webkitNotificationCreate(WebKitWebView*, const WebKit::WebNotification&); +WebKitWebView* webkitNotificationGetWebView(WebKitNotification*); + +#endif // WebKitNotificationPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.cpp new file mode 100644 index 000000000..620750a44 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.cpp @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2013 Igalia S.L. + * Copyright (C) 2014 Collabora Ltd. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebKitNotificationProvider.h" + +#include "APIArray.h" +#include "WKNotificationManager.h" +#include "WebKitNotificationPrivate.h" +#include "WebKitWebViewPrivate.h" +#include "WebNotificationManagerProxy.h" +#include "WebPageProxy.h" +#include <wtf/text/CString.h> + +using namespace WebKit; + +static inline WebKitNotificationProvider* toNotificationProvider(const void* clientInfo) +{ + return static_cast<WebKitNotificationProvider*>(const_cast<void*>(clientInfo)); +} + +static void showCallback(WKPageRef page, WKNotificationRef notification, const void* clientInfo) +{ + toNotificationProvider(clientInfo)->show(toImpl(page), *toImpl(notification)); +} + +static void cancelCallback(WKNotificationRef notification, const void* clientInfo) +{ + toNotificationProvider(clientInfo)->cancel(*toImpl(notification)); +} + +static void clearNotificationsCallback(WKArrayRef notificationIDs, const void* clientInfo) +{ + toNotificationProvider(clientInfo)->clearNotifications(toImpl(notificationIDs)); +} + +WebKitNotificationProvider::~WebKitNotificationProvider() +{ +} + +Ref<WebKitNotificationProvider> WebKitNotificationProvider::create(WebNotificationManagerProxy* notificationManager) +{ + return adoptRef(*new WebKitNotificationProvider(notificationManager)); +} + +WebKitNotificationProvider::WebKitNotificationProvider(WebNotificationManagerProxy* notificationManager) + : m_notificationManager(notificationManager) +{ + ASSERT(notificationManager); + + WKNotificationProviderV0 wkNotificationProvider = { + { + 0, // version + this, // clientInfo + }, + showCallback, + cancelCallback, + 0, // didDestroyNotificationCallback, + 0, // addNotificationManagerCallback, + 0, // removeNotificationManagerCallback, + 0, // notificationPermissionsCallback, + clearNotificationsCallback, + }; + + WKNotificationManagerSetProvider(toAPI(notificationManager), reinterpret_cast<WKNotificationProviderBase*>(&wkNotificationProvider)); +} + +void WebKitNotificationProvider::notificationCloseCallback(WebKitNotification* notification, WebKitNotificationProvider* provider) +{ + uint64_t notificationID = webkit_notification_get_id(notification); + Vector<RefPtr<API::Object>> arrayIDs; + arrayIDs.append(API::UInt64::create(notificationID)); + provider->m_notificationManager->providerDidCloseNotifications(API::Array::create(WTFMove(arrayIDs)).ptr()); + provider->m_notifications.remove(notificationID); +} + +void WebKitNotificationProvider::notificationClickedCallback(WebKitNotification* notification, WebKitNotificationProvider* provider) +{ + provider->m_notificationManager->providerDidClickNotification(webkit_notification_get_id(notification)); +} + +void WebKitNotificationProvider::show(WebPageProxy* page, const WebNotification& webNotification) +{ + GRefPtr<WebKitNotification> notification = m_notifications.get(webNotification.notificationID()); + + if (!notification) { + notification = adoptGRef(webkitNotificationCreate(WEBKIT_WEB_VIEW(page->viewWidget()), webNotification)); + g_signal_connect(notification.get(), "closed", G_CALLBACK(notificationCloseCallback), this); + g_signal_connect(notification.get(), "clicked", G_CALLBACK(notificationClickedCallback), this); + m_notifications.set(webNotification.notificationID(), notification); + } + + if (webkitWebViewEmitShowNotification(WEBKIT_WEB_VIEW(page->viewWidget()), notification.get())) + m_notificationManager->providerDidShowNotification(webNotification.notificationID()); +} + +void WebKitNotificationProvider::cancelNotificationByID(uint64_t notificationID) +{ + if (GRefPtr<WebKitNotification> notification = m_notifications.get(notificationID)) + webkit_notification_close(notification.get()); +} + +void WebKitNotificationProvider::cancel(const WebNotification& webNotification) +{ + cancelNotificationByID(webNotification.notificationID()); +} + +void WebKitNotificationProvider::clearNotifications(const API::Array* notificationIDs) +{ + for (const auto& item : notificationIDs->elementsOfType<API::UInt64>()) + cancelNotificationByID(item->value()); +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.h b/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.h new file mode 100644 index 000000000..6f1da4604 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2013 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef WebKitNotificationProvider_h +#define WebKitNotificationProvider_h + +#include "WebKitPrivate.h" +#include "WebKitNotification.h" +#include <wtf/HashMap.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> + +namespace API { +class Array; +} + +namespace WebKit { + +class WebKitNotificationProvider : public RefCounted<WebKitNotificationProvider> { +public: + virtual ~WebKitNotificationProvider(); + static Ref<WebKitNotificationProvider> create(WebNotificationManagerProxy*); + + void show(WebPageProxy*, const WebNotification&); + void cancel(const WebNotification&); + void clearNotifications(const API::Array*); + +private: + WebKitNotificationProvider(WebNotificationManagerProxy*); + + void cancelNotificationByID(uint64_t); + static void notificationCloseCallback(WebKitNotification*, WebKitNotificationProvider*); + static void notificationClickedCallback(WebKitNotification*, WebKitNotificationProvider*); + + RefPtr<WebNotificationManagerProxy> m_notificationManager; + HashMap<uint64_t, GRefPtr<WebKitNotification>> m_notifications; +}; + +} // namespace WebKit + +#endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitPlugin.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitPlugin.cpp index 2bcb89c50..b6dec1d3a 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitPlugin.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitPlugin.cpp @@ -55,7 +55,7 @@ struct _WebKitPluginPrivate { WEBKIT_DEFINE_TYPE(WebKitPlugin, webkit_plugin, G_TYPE_OBJECT) -static void webkit_plugin_class_init(WebKitPluginClass* pluginClass) +static void webkit_plugin_class_init(WebKitPluginClass*) { } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitPolicyClient.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitPolicyClient.cpp index 1eb6b1ec6..2d4eac5b3 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitPolicyClient.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitPolicyClient.cpp @@ -20,65 +20,47 @@ #include "config.h" #include "WebKitPolicyClient.h" +#include "APIPolicyClient.h" #include "WebKitNavigationPolicyDecisionPrivate.h" #include "WebKitResponsePolicyDecisionPrivate.h" #include "WebKitWebViewBasePrivate.h" #include "WebKitWebViewPrivate.h" -#include <wtf/gobject/GRefPtr.h> +#include <wtf/glib/GRefPtr.h> #include <wtf/text/CString.h> using namespace WebKit; -static void decidePolicyForNavigationAction(WKPageRef page, WKFrameRef frame, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKFrameRef originatingFrame, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo) -{ - GRefPtr<WebKitNavigationPolicyDecision> decision = - adoptGRef(webkitNavigationPolicyDecisionCreate(static_cast<WebKitNavigationType>(navigationType), - wkEventMouseButtonToWebKitMouseButton(mouseButton), - wkEventModifiersToGdkModifiers(modifiers), - toImpl(request), - 0, /* frame name */ - toImpl(listener))); - webkitWebViewMakePolicyDecision(WEBKIT_WEB_VIEW(clientInfo), - WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION, - WEBKIT_POLICY_DECISION(decision.get())); -} +class PolicyClient: public API::PolicyClient { +public: + explicit PolicyClient(WebKitWebView* webView) + : m_webView(webView) + { + } -static void decidePolicyForNewWindowAction(WKPageRef page, WKFrameRef frame, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRequestRef request, WKStringRef frameName, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo) -{ - GRefPtr<WebKitNavigationPolicyDecision> decision = - adoptGRef(webkitNavigationPolicyDecisionCreate(static_cast<WebKitNavigationType>(navigationType), - wkEventMouseButtonToWebKitMouseButton(mouseButton), - wkEventModifiersToGdkModifiers(modifiers), - toImpl(request), - toImpl(frameName)->string().utf8().data(), - toImpl(listener))); - webkitWebViewMakePolicyDecision(WEBKIT_WEB_VIEW(clientInfo), - WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION, - WEBKIT_POLICY_DECISION(decision.get())); -} +private: + virtual void decidePolicyForNavigationAction(WebPageProxy&, WebFrameProxy*, const NavigationActionData& navigationActionData, WebFrameProxy* /*originatingFrame*/, const WebCore::ResourceRequest& /*originalRequest*/, const WebCore::ResourceRequest& request, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* /*userData*/) override + { + GRefPtr<WebKitPolicyDecision> decision = adoptGRef(webkitNavigationPolicyDecisionCreate(navigationActionData, request, listener.ptr())); + webkitWebViewMakePolicyDecision(m_webView, WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION, decision.get()); + } -static void decidePolicyForResponse(WKPageRef page, WKFrameRef frame, WKURLResponseRef response, WKURLRequestRef request, bool canShowMIMEType, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo) -{ - GRefPtr<WebKitResponsePolicyDecision> decision = - adoptGRef(webkitResponsePolicyDecisionCreate(toImpl(request), toImpl(response), canShowMIMEType, toImpl(listener))); - webkitWebViewMakePolicyDecision(WEBKIT_WEB_VIEW(clientInfo), - WEBKIT_POLICY_DECISION_TYPE_RESPONSE, - WEBKIT_POLICY_DECISION(decision.get())); -} + virtual void decidePolicyForNewWindowAction(WebPageProxy&, WebFrameProxy&, const NavigationActionData& navigationActionData, const WebCore::ResourceRequest& request, const String& frameName, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* /*userData*/) override + { + GRefPtr<WebKitPolicyDecision> decision = adoptGRef(webkitNewWindowPolicyDecisionCreate(navigationActionData, request, frameName, listener.ptr())); + webkitWebViewMakePolicyDecision(m_webView, WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION, decision.get()); + } + + virtual void decidePolicyForResponse(WebPageProxy&, WebFrameProxy&, const WebCore::ResourceResponse& response, const WebCore::ResourceRequest& request, bool canShowMIMEType, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* /*userData*/) override + { + GRefPtr<WebKitPolicyDecision> decision = adoptGRef(webkitResponsePolicyDecisionCreate(request, response, canShowMIMEType, listener.ptr())); + webkitWebViewMakePolicyDecision(m_webView, WEBKIT_POLICY_DECISION_TYPE_RESPONSE, decision.get()); + } + + WebKitWebView* m_webView; +}; void attachPolicyClientToView(WebKitWebView* webView) { - WKPagePolicyClientV1 policyClient = { - { - 1, // version - webView, // clientInfo - }, - 0, // decidePolicyForNavigationAction_deprecatedForUseWithV0 - decidePolicyForNewWindowAction, - 0, // decidePolicyForResponse_deprecatedForUseWithV0 - 0, // unableToImplementPolicy - decidePolicyForNavigationAction, - decidePolicyForResponse - }; - WKPageSetPagePolicyClient(toAPI(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView))), &policyClient.base); + WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView)); + page->setPolicyClient(std::make_unique<PolicyClient>(webView)); } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp index 75b435baf..5289cd70e 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp @@ -27,11 +27,11 @@ #include <WebCore/GtkUtilities.h> #include <WebCore/NotImplemented.h> #include <glib/gi18n-lib.h> -#include <wtf/gobject/GRefPtr.h> -#include <wtf/gobject/GUniquePtr.h> +#include <wtf/glib/GRefPtr.h> +#include <wtf/glib/GUniquePtr.h> #include <wtf/text/CString.h> -#ifdef HAVE_GTK_UNIX_PRINTING +#if HAVE(GTK_UNIX_PRINTING) #include <gtk/gtkunixprint.h> #endif @@ -198,16 +198,17 @@ static void webkit_print_operation_class_init(WebKitPrintOperationClass* printOp * The #WebKitPrintOperation::finished signal is emitted after this one. */ signals[FAILED] = - g_signal_new("failed", - G_TYPE_FROM_CLASS(gObjectClass), - G_SIGNAL_RUN_LAST, - 0, 0, 0, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, - G_TYPE_POINTER); + g_signal_new( + "failed", + G_TYPE_FROM_CLASS(gObjectClass), + G_SIGNAL_RUN_LAST, + 0, 0, 0, + g_cclosure_marshal_VOID__BOXED, + G_TYPE_NONE, 1, + G_TYPE_ERROR | G_SIGNAL_TYPE_STATIC_SCOPE); } -#ifdef HAVE_GTK_UNIX_PRINTING +#if HAVE(GTK_UNIX_PRINTING) static WebKitPrintOperationResponse webkitPrintOperationRunDialog(WebKitPrintOperation* printOperation, GtkWindow* parent) { GtkPrintUnixDialog* printDialog = GTK_PRINT_UNIX_DIALOG(gtk_print_unix_dialog_new(0, parent)); @@ -252,30 +253,31 @@ static WebKitPrintOperationResponse webkitPrintOperationRunDialog(WebKitPrintOpe } #endif -static void drawPagesForPrintingCompleted(WKErrorRef wkPrintError, WKErrorRef, void* context) +static void drawPagesForPrintingCompleted(API::Error* wkPrintError, WebKitPrintOperation* printOperation) { - GRefPtr<WebKitPrintOperation> printOperation = adoptGRef(WEBKIT_PRINT_OPERATION(context)); - // When running synchronously WebPageProxy::printFrame() calls endPrinting(). if (printOperation->priv->printMode == PrintInfo::PrintModeAsync && printOperation->priv->webView) { WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(printOperation->priv->webView)); page->endPrinting(); } - const WebCore::ResourceError& resourceError = wkPrintError ? toImpl(wkPrintError)->platformError() : WebCore::ResourceError(); + const WebCore::ResourceError& resourceError = wkPrintError ? wkPrintError->platformError() : WebCore::ResourceError(); if (!resourceError.isNull()) { GUniquePtr<GError> printError(g_error_new_literal(g_quark_from_string(resourceError.domain().utf8().data()), - resourceError.errorCode(), resourceError.localizedDescription().utf8().data())); - g_signal_emit(printOperation.get(), signals[FAILED], 0, printError.get()); + toWebKitError(resourceError.errorCode()), resourceError.localizedDescription().utf8().data())); + g_signal_emit(printOperation, signals[FAILED], 0, printError.get()); } - g_signal_emit(printOperation.get(), signals[FINISHED], 0, NULL); + g_signal_emit(printOperation, signals[FINISHED], 0, NULL); } static void webkitPrintOperationPrintPagesForFrame(WebKitPrintOperation* printOperation, WebFrameProxy* webFrame, GtkPrintSettings* printSettings, GtkPageSetup* pageSetup) { PrintInfo printInfo(printSettings, pageSetup, printOperation->priv->printMode); WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(printOperation->priv->webView)); - page->drawPagesForPrinting(webFrame, printInfo, PrintFinishedCallback::create(g_object_ref(printOperation), &drawPagesForPrintingCompleted)); + g_object_ref(printOperation); + page->drawPagesForPrinting(webFrame, printInfo, PrintFinishedCallback::create([printOperation](API::Error* printError, CallbackBase::Error) { + drawPagesForPrintingCompleted(printError, adoptGRef(printOperation).get()); + })); } WebKitPrintOperationResponse webkitPrintOperationRunDialogForFrame(WebKitPrintOperation* printOperation, GtkWindow* parent, WebFrameProxy* webFrame) diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.cpp index d34b9c471..2b1e12497 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.cpp @@ -20,6 +20,9 @@ #include "config.h" #include "WebKitPrivate.h" +#include "ErrorsGtk.h" +#include "WebEvent.h" +#include "WebKitError.h" #include <gdk/gdk.h> unsigned wkEventModifiersToGdkModifiers(WKEventModifiers wkModifiers) @@ -36,6 +39,57 @@ unsigned wkEventModifiersToGdkModifiers(WKEventModifiers wkModifiers) return modifiers; } +unsigned toGdkModifiers(WebKit::WebEvent::Modifiers wkModifiers) +{ + unsigned modifiers = 0; + if (wkModifiers & WebKit::WebEvent::Modifiers::ShiftKey) + modifiers |= GDK_SHIFT_MASK; + if (wkModifiers & WebKit::WebEvent::Modifiers::ControlKey) + modifiers |= GDK_CONTROL_MASK; + if (wkModifiers & WebKit::WebEvent::Modifiers::AltKey) + modifiers |= GDK_MOD1_MASK; + if (wkModifiers & WebKit::WebEvent::Modifiers::MetaKey) + modifiers |= GDK_META_MASK; + return modifiers; +} + +WebKitNavigationType toWebKitNavigationType(WebCore::NavigationType type) +{ + switch (type) { + case WebCore::NavigationType::LinkClicked: + return WEBKIT_NAVIGATION_TYPE_LINK_CLICKED; + case WebCore::NavigationType::FormSubmitted: + return WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED; + case WebCore::NavigationType::BackForward: + return WEBKIT_NAVIGATION_TYPE_BACK_FORWARD; + case WebCore::NavigationType::Reload: + return WEBKIT_NAVIGATION_TYPE_RELOAD; + case WebCore::NavigationType::FormResubmitted: + return WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED; + case WebCore::NavigationType::Other: + return WEBKIT_NAVIGATION_TYPE_OTHER; + default: + ASSERT_NOT_REACHED(); + return WEBKIT_NAVIGATION_TYPE_OTHER; + } +} + +unsigned toWebKitMouseButton(WebKit::WebMouseEvent::Button button) +{ + switch (button) { + case WebKit::WebMouseEvent::Button::NoButton: + return 0; + case WebKit::WebMouseEvent::Button::LeftButton: + return 1; + case WebKit::WebMouseEvent::Button::MiddleButton: + return 2; + case WebKit::WebMouseEvent::Button::RightButton: + return 3; + } + ASSERT_NOT_REACHED(); + return 0; +} + unsigned wkEventMouseButtonToWebKitMouseButton(WKEventMouseButton wkButton) { switch (wkButton) { @@ -51,3 +105,109 @@ unsigned wkEventMouseButtonToWebKitMouseButton(WKEventMouseButton wkButton) ASSERT_NOT_REACHED(); return 0; } + +unsigned toWebKitError(unsigned webCoreError) +{ + switch (webCoreError) { + case WebCore::NetworkErrorFailed: + return WEBKIT_NETWORK_ERROR_FAILED; + case WebCore::NetworkErrorTransport: + return WEBKIT_NETWORK_ERROR_TRANSPORT; + case WebCore::NetworkErrorUnknownProtocol: + return WEBKIT_NETWORK_ERROR_UNKNOWN_PROTOCOL; + case WebCore::NetworkErrorCancelled: + return WEBKIT_NETWORK_ERROR_CANCELLED; + case WebCore::NetworkErrorFileDoesNotExist: + return WEBKIT_NETWORK_ERROR_FILE_DOES_NOT_EXIST; + case WebCore::PolicyErrorFailed: + return WEBKIT_POLICY_ERROR_FAILED; + case WebCore::PolicyErrorCannotShowMimeType: + return WEBKIT_POLICY_ERROR_CANNOT_SHOW_MIME_TYPE; + case WebCore::PolicyErrorCannotShowURL: + return WEBKIT_POLICY_ERROR_CANNOT_SHOW_URI; + case WebCore::PolicyErrorFrameLoadInterruptedByPolicyChange: + return WEBKIT_POLICY_ERROR_FRAME_LOAD_INTERRUPTED_BY_POLICY_CHANGE; + case WebCore::PolicyErrorCannotUseRestrictedPort: + return WEBKIT_POLICY_ERROR_CANNOT_USE_RESTRICTED_PORT; + case WebCore::PluginErrorFailed: + return WEBKIT_PLUGIN_ERROR_FAILED; + case WebCore::PluginErrorCannotFindPlugin: + return WEBKIT_PLUGIN_ERROR_CANNOT_FIND_PLUGIN; + case WebCore::PluginErrorCannotLoadPlugin: + return WEBKIT_PLUGIN_ERROR_CANNOT_LOAD_PLUGIN; + case WebCore::PluginErrorJavaUnavailable: + return WEBKIT_PLUGIN_ERROR_JAVA_UNAVAILABLE; + case WebCore::PluginErrorConnectionCancelled: + return WEBKIT_PLUGIN_ERROR_CONNECTION_CANCELLED; + case WebCore::PluginErrorWillHandleLoad: + return WEBKIT_PLUGIN_ERROR_WILL_HANDLE_LOAD; + case WebCore::DownloadErrorNetwork: + return WEBKIT_DOWNLOAD_ERROR_NETWORK; + case WebCore::DownloadErrorCancelledByUser: + return WEBKIT_DOWNLOAD_ERROR_CANCELLED_BY_USER; + case WebCore::DownloadErrorDestination: + return WEBKIT_DOWNLOAD_ERROR_DESTINATION; + case WebCore::PrintErrorGeneral: + return WEBKIT_PRINT_ERROR_GENERAL; + case WebCore::PrintErrorPrinterNotFound: + return WEBKIT_PRINT_ERROR_PRINTER_NOT_FOUND; + case WebCore::PrintErrorInvalidPageRange: + return WEBKIT_PRINT_ERROR_INVALID_PAGE_RANGE; + default: + // This may be a user app defined error, which needs to be passed as-is. + return webCoreError; + } +} + +unsigned toWebCoreError(unsigned webKitError) +{ + switch (webKitError) { + case WEBKIT_NETWORK_ERROR_FAILED: + return WebCore::NetworkErrorFailed; + case WEBKIT_NETWORK_ERROR_TRANSPORT: + return WebCore::NetworkErrorTransport; + case WEBKIT_NETWORK_ERROR_UNKNOWN_PROTOCOL: + return WebCore::NetworkErrorUnknownProtocol; + case WEBKIT_NETWORK_ERROR_CANCELLED: + return WebCore::NetworkErrorCancelled; + case WEBKIT_NETWORK_ERROR_FILE_DOES_NOT_EXIST: + return WebCore::NetworkErrorFileDoesNotExist; + case WEBKIT_POLICY_ERROR_FAILED: + return WebCore::PolicyErrorFailed; + case WEBKIT_POLICY_ERROR_CANNOT_SHOW_MIME_TYPE: + return WebCore::PolicyErrorCannotShowMimeType; + case WEBKIT_POLICY_ERROR_CANNOT_SHOW_URI: + return WebCore::PolicyErrorCannotShowURL; + case WEBKIT_POLICY_ERROR_FRAME_LOAD_INTERRUPTED_BY_POLICY_CHANGE: + return WebCore::PolicyErrorFrameLoadInterruptedByPolicyChange; + case WEBKIT_POLICY_ERROR_CANNOT_USE_RESTRICTED_PORT: + return WebCore::PolicyErrorCannotUseRestrictedPort; + case WEBKIT_PLUGIN_ERROR_FAILED: + return WebCore::PluginErrorFailed; + case WEBKIT_PLUGIN_ERROR_CANNOT_FIND_PLUGIN: + return WebCore::PluginErrorCannotFindPlugin; + case WEBKIT_PLUGIN_ERROR_CANNOT_LOAD_PLUGIN: + return WebCore::PluginErrorCannotLoadPlugin; + case WEBKIT_PLUGIN_ERROR_JAVA_UNAVAILABLE: + return WebCore::PluginErrorJavaUnavailable; + case WEBKIT_PLUGIN_ERROR_CONNECTION_CANCELLED: + return WebCore::PluginErrorConnectionCancelled; + case WEBKIT_PLUGIN_ERROR_WILL_HANDLE_LOAD: + return WebCore::PluginErrorWillHandleLoad; + case WEBKIT_DOWNLOAD_ERROR_NETWORK: + return WebCore::DownloadErrorNetwork; + case WEBKIT_DOWNLOAD_ERROR_CANCELLED_BY_USER: + return WebCore::DownloadErrorCancelledByUser; + case WEBKIT_DOWNLOAD_ERROR_DESTINATION: + return WebCore::DownloadErrorDestination; + case WEBKIT_PRINT_ERROR_GENERAL: + return WebCore::PrintErrorGeneral; + case WEBKIT_PRINT_ERROR_PRINTER_NOT_FOUND: + return WebCore::PrintErrorPrinterNotFound; + case WEBKIT_PRINT_ERROR_INVALID_PAGE_RANGE: + return WebCore::PrintErrorInvalidPageRange; + default: + // This may be a user app defined error, which needs to be passed as-is. + return webKitError; + } +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h index bd060ed32..c995cd5c0 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h @@ -26,22 +26,23 @@ #ifndef WebKitPrivate_h #define WebKitPrivate_h -#include <WebKit2/WKAPICast.h> -#include <WebKit2/WKDownload.h> -#include <WebKit2/WKFindOptions.h> -#include <WebKit2/WKFullScreenClientGtk.h> -#include <WebKit2/WKGeolocationManager.h> -#include <WebKit2/WKGeolocationPermissionRequest.h> -#include <WebKit2/WKGeolocationPosition.h> -#include <WebKit2/WKIconDatabase.h> -#include <WebKit2/WKInspector.h> -#include <WebKit2/WKInspectorClientGtk.h> -#include <WebKit2/WKRetainPtr.h> -#include <WebKit2/WKSerializedScriptValue.h> -#include <WebKit2/WKSoupCustomProtocolRequestManager.h> -#include <WebKit2/WKString.h> -#include <WebKit2/WKTextChecker.h> -#include <WebKit2/WebKit2_C.h> +#include "WebKitNavigationAction.h" +#include <WebKit/WKAPICast.h> +#include <WebKit/WKDownload.h> +#include <WebKit/WKFindOptions.h> +#include <WebKit/WKFullScreenClientGtk.h> +#include <WebKit/WKGeolocationManager.h> +#include <WebKit/WKGeolocationPermissionRequest.h> +#include <WebKit/WKGeolocationPosition.h> +#include <WebKit/WKIconDatabase.h> +#include <WebKit/WKInspector.h> +#include <WebKit/WKInspectorClientGtk.h> +#include <WebKit/WKRetainPtr.h> +#include <WebKit/WKSerializedScriptValue.h> +#include <WebKit/WKSoupCustomProtocolRequestManager.h> +#include <WebKit/WKString.h> +#include <WebKit/WKUserMediaPermissionRequest.h> +#include <WebKit/WebKit2_C.h> #include <glib.h> #include <wtf/Assertions.h> @@ -49,20 +50,17 @@ #define WEBKIT_PARAM_WRITABLE (static_cast<GParamFlags>(G_PARAM_WRITABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)) #define WEBKIT_PARAM_READWRITE (static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)) -#define COMPILE_ASSERT_MATCHING_ENUM(webkitName, webcoreName) \ - COMPILE_ASSERT(int(webkitName) == int(webcoreName), mismatchingEnums) - #define WEBKIT_DEFINE_ASYNC_DATA_STRUCT(structName) \ static structName* create##structName() \ { \ - structName* data = g_slice_new0(structName); \ + structName* data = static_cast<structName*>(fastZeroedMalloc(sizeof(structName))); \ new (data) structName(); \ return data; \ } \ static void destroy##structName(structName* data) \ { \ data->~structName(); \ - g_slice_free(structName, data); \ + fastFree(data); \ } #define WEBKIT_DEFINE_TYPE(TypeName, type_name, TYPE_PARENT) _WEBKIT_DEFINE_TYPE_EXTENDED(TypeName, type_name, TYPE_PARENT, 0, { }) @@ -118,10 +116,21 @@ GType type_name##_get_type(void) \ unsigned wkEventModifiersToGdkModifiers(WKEventModifiers); unsigned wkEventMouseButtonToWebKitMouseButton(WKEventMouseButton); +unsigned toGdkModifiers(WebKit::WebEvent::Modifiers); +WebKitNavigationType toWebKitNavigationType(WebCore::NavigationType); +unsigned toWebKitMouseButton(WebKit::WebMouseEvent::Button); +unsigned toWebKitError(unsigned webCoreError); +unsigned toWebCoreError(unsigned webKitError); enum SnapshotRegion { SnapshotRegionVisible, SnapshotRegionFullDocument }; +#if ENABLE(NETWORK_CACHE) +static const char networkCacheSubdirectory[] = "WebKitCache"; +#else +static const char networkCacheSubdirectory[] = "webkit"; +#endif + #endif // WebKitPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitRequestManagerClient.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitRequestManagerClient.cpp index 72f91ec2e..f9189c916 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitRequestManagerClient.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitRequestManagerClient.cpp @@ -24,7 +24,7 @@ using namespace WebKit; -static void startLoading(WKSoupCustomProtocolRequestManagerRef soupRequestManagerRef, uint64_t customProtocolID, WKURLRequestRef requestRef, const void* clientInfo) +static void startLoading(WKSoupCustomProtocolRequestManagerRef, uint64_t customProtocolID, WKURLRequestRef requestRef, const void* clientInfo) { webkitWebContextStartLoadingCustomProtocol(WEBKIT_WEB_CONTEXT(clientInfo), customProtocolID, toImpl(requestRef)); } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitResponsePolicyDecision.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitResponsePolicyDecision.cpp index b6054b814..69b241f85 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitResponsePolicyDecision.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitResponsePolicyDecision.cpp @@ -20,17 +20,16 @@ #include "config.h" #include "WebKitResponsePolicyDecision.h" -#include "APIURLRequest.h" -#include "APIURLResponse.h" #include "WebKitPolicyDecisionPrivate.h" #include "WebKitPrivate.h" #include "WebKitURIRequestPrivate.h" #include "WebKitURIResponsePrivate.h" #include <glib/gi18n-lib.h> -#include <wtf/gobject/GRefPtr.h> +#include <wtf/glib/GRefPtr.h> #include <wtf/text/CString.h> using namespace WebKit; +using namespace WebCore; /** * SECTION: WebKitResponsePolicyDecision @@ -155,12 +154,13 @@ gboolean webkit_response_policy_decision_is_mime_type_supported(WebKitResponsePo return decision->priv->canShowMIMEType; } -WebKitResponsePolicyDecision* webkitResponsePolicyDecisionCreate(API::URLRequest* request, API::URLResponse* response, bool canShowMIMEType, WebFramePolicyListenerProxy* listener) +WebKitPolicyDecision* webkitResponsePolicyDecisionCreate(const ResourceRequest& request, const ResourceResponse& response, bool canShowMIMEType, WebFramePolicyListenerProxy* listener) { - WebKitResponsePolicyDecision* decision = WEBKIT_RESPONSE_POLICY_DECISION(g_object_new(WEBKIT_TYPE_RESPONSE_POLICY_DECISION, NULL)); - decision->priv->request = adoptGRef(webkitURIRequestCreateForResourceRequest(request->resourceRequest())); - decision->priv->response = adoptGRef(webkitURIResponseCreateForResourceResponse(response->resourceResponse())); - decision->priv->canShowMIMEType = canShowMIMEType; - webkitPolicyDecisionSetListener(WEBKIT_POLICY_DECISION(decision), listener); + WebKitResponsePolicyDecision* responseDecision = WEBKIT_RESPONSE_POLICY_DECISION(g_object_new(WEBKIT_TYPE_RESPONSE_POLICY_DECISION, nullptr)); + responseDecision->priv->request = adoptGRef(webkitURIRequestCreateForResourceRequest(request)); + responseDecision->priv->response = adoptGRef(webkitURIResponseCreateForResourceResponse(response)); + responseDecision->priv->canShowMIMEType = canShowMIMEType; + WebKitPolicyDecision* decision = WEBKIT_POLICY_DECISION(responseDecision); + webkitPolicyDecisionSetListener(decision, listener); return decision; } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitResponsePolicyDecisionPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitResponsePolicyDecisionPrivate.h index ff83a7df3..2ff91085b 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitResponsePolicyDecisionPrivate.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitResponsePolicyDecisionPrivate.h @@ -23,6 +23,6 @@ #include "WebKitPrivate.h" #include "WebKitResponsePolicyDecision.h" -WebKitResponsePolicyDecision* webkitResponsePolicyDecisionCreate(API::URLRequest*, API::URLResponse*, bool canShowMIMEType, WebKit::WebFramePolicyListenerProxy*); +WebKitPolicyDecision* webkitResponsePolicyDecisionCreate(const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, bool canShowMIMEType, WebKit::WebFramePolicyListenerProxy*); #endif // WebKitResponsePolicyDecisionPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitScriptDialog.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitScriptDialog.cpp index 863665d71..5f9772407 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitScriptDialog.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitScriptDialog.cpp @@ -24,7 +24,7 @@ static WebKitScriptDialog* webkitScriptDialogCopy(WebKitScriptDialog* dialog) { - WebKitScriptDialog* copy = g_slice_new0(WebKitScriptDialog); + WebKitScriptDialog* copy = static_cast<WebKitScriptDialog*>(fastZeroedMalloc(sizeof(WebKitScriptDialog))); new (copy) WebKitScriptDialog(dialog); return copy; } @@ -32,7 +32,7 @@ static WebKitScriptDialog* webkitScriptDialogCopy(WebKitScriptDialog* dialog) static void webkitScriptDialogFree(WebKitScriptDialog* dialog) { dialog->~WebKitScriptDialog(); - g_slice_free(WebKitScriptDialog, dialog); + fastFree(dialog); } G_DEFINE_BOXED_TYPE(WebKitScriptDialog, webkit_script_dialog, webkitScriptDialogCopy, webkitScriptDialogFree) @@ -72,17 +72,17 @@ const char* webkit_script_dialog_get_message(WebKitScriptDialog* dialog) * @dialog: a #WebKitScriptDialog * @confirmed: whether user confirmed the dialog * - * This method is used for %WEBKIT_SCRIPT_DIALOG_CONFIRM dialogs when + * This method is used for %WEBKIT_SCRIPT_DIALOG_CONFIRM and %WEBKIT_SCRIPT_DIALOG_BEFORE_UNLOAD_CONFIRM dialogs when * #WebKitWebView::script-dialog signal is emitted to set whether the user * confirmed the dialog or not. The default implementation of #WebKitWebView::script-dialog - * signal sets %TRUE when the OK button is clicked and %FALSE otherwise. + * signal sets %TRUE when the OK or Stay buttons are clicked and %FALSE otherwise. * It's an error to use this method with a #WebKitScriptDialog that is not of type - * %WEBKIT_SCRIPT_DIALOG_CONFIRM. + * %WEBKIT_SCRIPT_DIALOG_CONFIRM or %WEBKIT_SCRIPT_DIALOG_BEFORE_UNLOAD_CONFIRM */ void webkit_script_dialog_confirm_set_confirmed(WebKitScriptDialog* dialog, gboolean confirmed) { g_return_if_fail(dialog); - g_return_if_fail(dialog->type == WEBKIT_SCRIPT_DIALOG_CONFIRM); + g_return_if_fail(dialog->type == WEBKIT_SCRIPT_DIALOG_CONFIRM || dialog->type == WEBKIT_SCRIPT_DIALOG_BEFORE_UNLOAD_CONFIRM); dialog->confirmed = confirmed; } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitScriptDialog.h b/Source/WebKit2/UIProcess/API/gtk/WebKitScriptDialog.h index cf88535ad..71095beed 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitScriptDialog.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitScriptDialog.h @@ -41,13 +41,16 @@ typedef struct _WebKitScriptDialog WebKitScriptDialog; * confirmation to the user. * @WEBKIT_SCRIPT_DIALOG_PROMPT: Prompt script dialog, used to ask * information to the user. + * @WEBKIT_SCRIPT_DIALOG_BEFORE_UNLOAD_CONFIRM: Before unload confirm dialog, + * used to ask confirmation to leave the current page to the user. Since 2.12 * * Enum values used for determining the type of #WebKitScriptDialog */ typedef enum { WEBKIT_SCRIPT_DIALOG_ALERT, WEBKIT_SCRIPT_DIALOG_CONFIRM, - WEBKIT_SCRIPT_DIALOG_PROMPT + WEBKIT_SCRIPT_DIALOG_PROMPT, + WEBKIT_SCRIPT_DIALOG_BEFORE_UNLOAD_CONFIRM } WebKitScriptDialogType; WEBKIT_API GType diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitSecurityManager.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitSecurityManager.cpp index 9b849a825..ee3626fbe 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitSecurityManager.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitSecurityManager.cpp @@ -20,9 +20,9 @@ #include "config.h" #include "WebKitSecurityManager.h" -#include "WebContext.h" #include "WebKitSecurityManagerPrivate.h" #include "WebKitWebContextPrivate.h" +#include "WebProcessPool.h" #include <WebCore/SchemeRegistry.h> using namespace WebKit; @@ -55,7 +55,7 @@ struct _WebKitSecurityManagerPrivate { WEBKIT_DEFINE_TYPE(WebKitSecurityManager, webkit_security_manager, G_TYPE_OBJECT) -static void webkit_security_manager_class_init(WebKitSecurityManagerClass* klass) +static void webkit_security_manager_class_init(WebKitSecurityManagerClass*) { } @@ -69,7 +69,7 @@ WebKitSecurityManager* webkitSecurityManagerCreate(WebKitWebContext* webContext) static void registerSecurityPolicyForURIScheme(WebKitSecurityManager* manager, const char* scheme, SecurityPolicy policy) { String urlScheme = String::fromUTF8(scheme); - WebContext* webContext = webkitWebContextGetContext(manager->priv->webContext); + WebProcessPool* processPool = webkitWebContextGetProcessPool(manager->priv->webContext); // We keep the WebCore::SchemeRegistry of the UI process in sync with the // web process one, so that we can return the SecurityPolicy for @@ -77,27 +77,27 @@ static void registerSecurityPolicyForURIScheme(WebKitSecurityManager* manager, c switch (policy) { case SecurityPolicyLocal: WebCore::SchemeRegistry::registerURLSchemeAsLocal(urlScheme); - webContext->registerURLSchemeAsLocal(urlScheme); + processPool->registerURLSchemeAsLocal(urlScheme); break; case SecurityPolicyNoAccess: WebCore::SchemeRegistry::registerURLSchemeAsNoAccess(urlScheme); - webContext->registerURLSchemeAsNoAccess(urlScheme); + processPool->registerURLSchemeAsNoAccess(urlScheme); break; case SecurityPolicyDisplayIsolated: WebCore::SchemeRegistry::registerURLSchemeAsDisplayIsolated(urlScheme); - webContext->registerURLSchemeAsDisplayIsolated(urlScheme); + processPool->registerURLSchemeAsDisplayIsolated(urlScheme); break; case SecurityPolicySecure: WebCore::SchemeRegistry::registerURLSchemeAsSecure(urlScheme); - webContext->registerURLSchemeAsSecure(urlScheme); + processPool->registerURLSchemeAsSecure(urlScheme); break; case SecurityPolicyCORSEnabled: WebCore::SchemeRegistry::registerURLSchemeAsCORSEnabled(urlScheme); - webContext->registerURLSchemeAsCORSEnabled(urlScheme); + processPool->registerURLSchemeAsCORSEnabled(urlScheme); break; case SecurityPolicyEmptyDocument: WebCore::SchemeRegistry::registerURLSchemeAsEmptyDocument(urlScheme); - webContext->registerURLSchemeAsEmptyDocument(urlScheme); + processPool->registerURLSchemeAsEmptyDocument(urlScheme); break; } } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp index 7c49ccd82..409abcdeb 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp @@ -34,15 +34,21 @@ #include "ExperimentalFeatures.h" #include "WebKitPrivate.h" #include "WebKitSettingsPrivate.h" +#include "WebPageProxy.h" +#include "WebPreferences.h" #include <WebCore/UserAgentGtk.h> #include <glib/gi18n-lib.h> #include <wtf/text/CString.h> +#if PLATFORM(WAYLAND) +#include <WebCore/PlatformDisplay.h> +#endif + using namespace WebKit; struct _WebKitSettingsPrivate { _WebKitSettingsPrivate() - : preferences(WebPreferences::create()) + : preferences(WebPreferences::create(String(), "WebKit2.", "WebKit2.")) { defaultFontFamily = preferences->standardFontFamily().utf8(); monospaceFontFamily = preferences->fixedFontFamily().utf8(); @@ -70,13 +76,12 @@ struct _WebKitSettingsPrivate { /** * SECTION:WebKitSettings - * @short_description: Control the behaviour of #WebKitWebView<!-- -->s - * @see_also: #WebKitWebViewGroup, #WebKitWebView + * @short_description: Control the behaviour of a #WebKitWebView * - * #WebKitSettings can be applied to a #WebKitWebViewGroup to control text charset, + * #WebKitSettings can be applied to a #WebKitWebView to control text charset, * color, font sizes, printing mode, script support, loading of images and various - * other things on the #WebKitWebView<!-- -->s of the group. - * After creation, a #WebKitSettings object contains default settings. + * other things on a #WebKitWebView. After creation, a #WebKitSettings object + * contains default settings. * * <informalexample><programlisting> * /<!-- -->* Disable JavaScript. *<!-- -->/ @@ -138,7 +143,8 @@ enum { PROP_ENABLE_WRITE_CONSOLE_MESSAGES_TO_STDOUT, PROP_ENABLE_MEDIA_STREAM, PROP_ENABLE_SPATIAL_NAVIGATION, - PROP_ENABLE_MEDIASOURCE + PROP_ENABLE_MEDIASOURCE, + PROP_ALLOW_FILE_ACCESS_FROM_FILE_URLS }; static void webKitSettingsConstructed(GObject* object) @@ -146,14 +152,6 @@ static void webKitSettingsConstructed(GObject* object) G_OBJECT_CLASS(webkit_settings_parent_class)->constructed(object); WebPreferences* prefs = WEBKIT_SETTINGS(object)->priv->preferences.get(); - ExperimentalFeatures features; - bool cssGridLayoutEnabled = features.isEnabled(ExperimentalFeatures::CSSGridLayout); - if (prefs->cssGridLayoutEnabled() != cssGridLayoutEnabled) - prefs->setCSSGridLayoutEnabled(cssGridLayoutEnabled); - bool regionBasedColumnsEnabled = features.isEnabled(ExperimentalFeatures::RegionBasedColumns); - if (prefs->regionBasedColumnsEnabled() != regionBasedColumnsEnabled) - prefs->setRegionBasedColumnsEnabled(regionBasedColumnsEnabled); - prefs->setShouldRespectImageOrientation(true); } @@ -312,6 +310,9 @@ static void webKitSettingsSetProperty(GObject* object, guint propId, const GValu case PROP_ENABLE_MEDIASOURCE: webkit_settings_set_enable_mediasource(settings, g_value_get_boolean(value)); break; + case PROP_ALLOW_FILE_ACCESS_FROM_FILE_URLS: + webkit_settings_set_allow_file_access_from_file_urls(settings, g_value_get_boolean(value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); break; @@ -467,7 +468,9 @@ static void webKitSettingsGetProperty(GObject* object, guint propId, GValue* val case PROP_ENABLE_MEDIASOURCE: g_value_set_boolean(value, webkit_settings_get_enable_mediasource(settings)); break; - + case PROP_ALLOW_FILE_ACCESS_FROM_FILE_URLS: + g_value_set_boolean(value, webkit_settings_get_allow_file_access_from_file_urls(settings)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); break; @@ -1220,6 +1223,25 @@ static void webkit_settings_class_init(WebKitSettingsClass* klass) _("Whether MediaSource should be enabled."), FALSE, readWriteConstructParamFlags)); + + /** + * WebKitSettings:allow-file-access-from-file-urls: + * + * Whether file access is allowed from file URLs. By default, when + * something is loaded in a #WebKitWebView using a file URI, cross + * origin requests to other file resources are not allowed. This + * setting allows you to change that behaviour, so that it would be + * possible to do a XMLHttpRequest of a local file, for example. + * + * Since: 2.10 + */ + g_object_class_install_property(gObjectClass, + PROP_ALLOW_FILE_ACCESS_FROM_FILE_URLS, + g_param_spec_boolean("allow-file-access-from-file-urls", + _("Allow file access from file URLs"), + _("Whether file access is allowed from file URLs."), + FALSE, + readWriteConstructParamFlags)); } WebPreferences* webkitSettingsGetPreferences(WebKitSettings* settings) @@ -1231,7 +1253,7 @@ WebPreferences* webkitSettingsGetPreferences(WebKitSettings* settings) * webkit_settings_new: * * Creates a new #WebKitSettings instance with default values. It must - * be manually attached to a #WebKitWebViewGroup. + * be manually attached to a #WebKitWebView. * See also webkit_settings_new_with_settings(). * * Returns: a new #WebKitSettings instance. @@ -1248,7 +1270,7 @@ WebKitSettings* webkit_settings_new() * %NULL-terminated * * Creates a new #WebKitSettings instance with the given settings. It must - * be manually attached to a #WebKitWebViewGroup. + * be manually attached to a #WebKitWebView. * * Returns: a new #WebKitSettings instance. */ @@ -2551,7 +2573,7 @@ gboolean webkit_settings_get_media_playback_requires_user_gesture(WebKitSettings { g_return_val_if_fail(WEBKIT_IS_SETTINGS(settings), FALSE); - return settings->priv->preferences->mediaPlaybackRequiresUserGesture(); + return settings->priv->preferences->requiresUserGestureForMediaPlayback(); } /** @@ -2566,11 +2588,11 @@ void webkit_settings_set_media_playback_requires_user_gesture(WebKitSettings* se g_return_if_fail(WEBKIT_IS_SETTINGS(settings)); WebKitSettingsPrivate* priv = settings->priv; - bool currentValue = priv->preferences->mediaPlaybackRequiresUserGesture(); + bool currentValue = priv->preferences->requiresUserGestureForMediaPlayback(); if (currentValue == enabled) return; - priv->preferences->setMediaPlaybackRequiresUserGesture(enabled); + priv->preferences->setRequiresUserGestureForMediaPlayback(enabled); g_object_notify(G_OBJECT(settings), "media-playback-requires-user-gesture"); } @@ -2587,7 +2609,7 @@ gboolean webkit_settings_get_media_playback_allows_inline(WebKitSettings* settin { g_return_val_if_fail(WEBKIT_IS_SETTINGS(settings), TRUE); - return settings->priv->preferences->mediaPlaybackAllowsInline(); + return settings->priv->preferences->allowsInlineMediaPlayback(); } /** @@ -2602,11 +2624,11 @@ void webkit_settings_set_media_playback_allows_inline(WebKitSettings* settings, g_return_if_fail(WEBKIT_IS_SETTINGS(settings)); WebKitSettingsPrivate* priv = settings->priv; - bool currentValue = priv->preferences->mediaPlaybackAllowsInline(); + bool currentValue = priv->preferences->allowsInlineMediaPlayback(); if (currentValue == enabled) return; - priv->preferences->setMediaPlaybackAllowsInline(enabled); + priv->preferences->setAllowsInlineMediaPlayback(enabled); g_object_notify(G_OBJECT(settings), "media-playback-allows-inline"); } @@ -3002,3 +3024,41 @@ void webkit_settings_set_enable_mediasource(WebKitSettings* settings, gboolean e priv->preferences->setMediaSourceEnabled(enabled); g_object_notify(G_OBJECT(settings), "enable-mediasource"); } + +/** + * webkit_settings_get_allow_file_access_from_file_urls: + * @settings: a #WebKitSettings + * + * Get the #WebKitSettings:allow-file-access-from-file-urls property. + * + * Returns: %TRUE If file access from file URLs is allowed or %FALSE otherwise. + * + * Since: 2.10 + */ +gboolean webkit_settings_get_allow_file_access_from_file_urls(WebKitSettings* settings) +{ + g_return_val_if_fail(WEBKIT_IS_SETTINGS(settings), FALSE); + + return settings->priv->preferences->allowFileAccessFromFileURLs(); +} + +/** + * webkit_settings_set_allow_file_access_from_file_urls: + * @settings: a #WebKitSettings + * @allowed: Value to be set + * + * Set the #WebKitSettings:allow-file-access-from-file-urls property. + * + * Since: 2.10 + */ +void webkit_settings_set_allow_file_access_from_file_urls(WebKitSettings* settings, gboolean allowed) +{ + g_return_if_fail(WEBKIT_IS_SETTINGS(settings)); + + WebKitSettingsPrivate* priv = settings->priv; + if (priv->preferences->allowFileAccessFromFileURLs() == allowed) + return; + + priv->preferences->setAllowFileAccessFromFileURLs(allowed); + g_object_notify(G_OBJECT(settings), "allow-file-access-from-file-urls"); +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.h b/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.h index 66e687f3d..d9ec48034 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.h @@ -414,6 +414,13 @@ WEBKIT_API void webkit_settings_set_enable_mediasource (WebKitSettings *settings, gboolean enabled); +WEBKIT_API gboolean +webkit_settings_get_allow_file_access_from_file_urls (WebKitSettings *settings); + +WEBKIT_API void +webkit_settings_set_allow_file_access_from_file_urls (WebKitSettings *settings, + gboolean allowed); + G_END_DECLS #endif /* WebKitSettings_h */ diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitTextChecker.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitTextChecker.cpp deleted file mode 100644 index 69b4b091b..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitTextChecker.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (C) 2012 Igalia S.L. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "WebKitTextChecker.h" - -#if ENABLE(SPELLCHECK) - -#include "WebKitPrivate.h" - -using namespace WebKit; - -static inline WebKitTextChecker* toTextChecker(const void* clientInfo) -{ - return static_cast<WebKitTextChecker*>(const_cast<void*>(clientInfo)); -} - -static bool continuousSpellCheckingEnabledCallback(const void* clientInfo) -{ - return toTextChecker(clientInfo)->isSpellCheckingEnabled(); -} - -static void setContinuousSpellCheckingEnabledCallback(bool enabled, const void* clientInfo) -{ - toTextChecker(clientInfo)->setSpellCheckingEnabled(enabled); -} - -static void checkSpellingOfStringCallback(uint64_t tag, WKStringRef text, int32_t* misspellingLocation, int32_t* misspellingLength, const void* clientInfo) -{ - toTextChecker(clientInfo)->checkSpellingOfString(toImpl(text)->string(), *misspellingLocation, *misspellingLength); -} - -static WKArrayRef guessesForWordCallback(uint64_t tag, WKStringRef word, const void* clientInfo) -{ - Vector<String> guesses = toTextChecker(clientInfo)->getGuessesForWord(toImpl(word)->string()); - if (guesses.isEmpty()) - return 0; - - WKMutableArrayRef wkSuggestions = WKMutableArrayCreate(); - for (Vector<String>::const_iterator iter = guesses.begin(); iter != guesses.end(); ++iter) { - WKRetainPtr<WKStringRef> wkSuggestion(AdoptWK, WKStringCreateWithUTF8CString(iter->utf8().data())); - WKArrayAppendItem(wkSuggestions, wkSuggestion.get()); - } - - return wkSuggestions; -} - -static void learnWordCallback(uint64_t tag, WKStringRef word, const void* clientInfo) -{ - toTextChecker(clientInfo)->learnWord(toImpl(word)->string()); -} - -static void ignoreWordCallback(uint64_t tag, WKStringRef word, const void* clientInfo) -{ - toTextChecker(clientInfo)->ignoreWord(toImpl(word)->string()); -} - -WebKitTextChecker::~WebKitTextChecker() -{ -} - -WebKitTextChecker::WebKitTextChecker() - : m_textChecker(WebCore::TextCheckerEnchant::create()) - , m_spellCheckingEnabled(false) -{ - WKTextCheckerClientV0 wkTextCheckerClient = { - { - 0, // version - this, // clientInfo - }, - 0, // continuousSpellCheckingAllowed - continuousSpellCheckingEnabledCallback, - setContinuousSpellCheckingEnabledCallback, - 0, // grammarCheckingEnabled - 0, // setGrammarCheckingEnabled - 0, // uniqueSpellDocumentTag - 0, // closeSpellDocumentWithTag - checkSpellingOfStringCallback, - 0, // checkGrammarOfString - 0, // spellingUIIsShowing - 0, // toggleSpellingUIIsShowing - 0, // updateSpellingUIWithMisspelledWord - 0, // updateSpellingUIWithGrammarString - guessesForWordCallback, - learnWordCallback, - ignoreWordCallback, - }; - WKTextCheckerSetClient(&wkTextCheckerClient.base); -} - -void WebKitTextChecker::checkSpellingOfString(const String& string, int& misspellingLocation, int& misspellingLength) -{ - m_textChecker->checkSpellingOfString(string, misspellingLocation, misspellingLength); -} - -Vector<String> WebKitTextChecker::getGuessesForWord(const String& word) -{ - return m_textChecker->getGuessesForWord(word); -} - -void WebKitTextChecker::learnWord(const String& word) -{ - m_textChecker->learnWord(word); -} - -void WebKitTextChecker::ignoreWord(const String& word) -{ - m_textChecker->ignoreWord(word); -} - -void WebKitTextChecker::setSpellCheckingEnabled(bool enabled) -{ - if (m_spellCheckingEnabled == enabled) - return; - m_spellCheckingEnabled = enabled; - - // We need to notify the Web process that this has changed. - WKTextCheckerContinuousSpellCheckingEnabledStateChanged(enabled); -} - -const char* const* WebKitTextChecker::getSpellCheckingLanguages() -{ - Vector<String> spellCheckingLanguages = m_textChecker->loadedSpellCheckingLanguages(); - if (spellCheckingLanguages.isEmpty()) - return 0; - - m_spellCheckingLanguages = adoptGRef(g_ptr_array_new_with_free_func(g_free)); - for (size_t i = 0; i < spellCheckingLanguages.size(); ++i) - g_ptr_array_add(m_spellCheckingLanguages.get(), g_strdup(spellCheckingLanguages[i].utf8().data())); - g_ptr_array_add(m_spellCheckingLanguages.get(), 0); - - return reinterpret_cast<char**>(m_spellCheckingLanguages->pdata); -} - -void WebKitTextChecker::setSpellCheckingLanguages(const char* const* languages) -{ - Vector<String> spellCheckingLanguages; - for (size_t i = 0; languages[i]; ++i) - spellCheckingLanguages.append(String::fromUTF8(languages[i])); - m_textChecker->updateSpellCheckingLanguages(spellCheckingLanguages); -} -#endif // ENABLE(SPELLCHECK) diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitTextChecker.h b/Source/WebKit2/UIProcess/API/gtk/WebKitTextChecker.h deleted file mode 100644 index 45424c584..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitTextChecker.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2012 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef WebKitTextChecker_h -#define WebKitTextChecker_h - -#if ENABLE(SPELLCHECK) - -#include <WebCore/TextCheckerEnchant.h> -#include <wtf/FastMalloc.h> -#include <wtf/PassOwnPtr.h> -#include <wtf/Vector.h> -#include <wtf/gobject/GRefPtr.h> -#include <wtf/text/CString.h> - -class WebKitTextChecker { - WTF_MAKE_FAST_ALLOCATED; - -public: - static PassOwnPtr<WebKitTextChecker> create() { return adoptPtr(new WebKitTextChecker()); } - virtual ~WebKitTextChecker(); - - // For implementing TextCheckerClient. - bool isSpellCheckingEnabled() { return m_spellCheckingEnabled; } - void setSpellCheckingEnabled(bool enabled); - void checkSpellingOfString(const String& string, int& misspellingLocation, int& misspellingLength); - Vector<String> getGuessesForWord(const String& word); - void learnWord(const String& word); - void ignoreWord(const String& word); - - // To be called from WebKitWebContext only. - const char* const* getSpellCheckingLanguages(); - void setSpellCheckingLanguages(const char* const* spellCheckingLanguages); - -private: - WebKitTextChecker(); - - OwnPtr<WebCore::TextCheckerEnchant> m_textChecker; - GRefPtr<GPtrArray> m_spellCheckingLanguages; - bool m_spellCheckingEnabled; -}; - -#endif // ENABLE(SPELLCHECK) - -#endif // WebKitTextChecker_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitUIClient.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitUIClient.cpp index 483b82786..5b0835b18 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitUIClient.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitUIClient.cpp @@ -20,199 +20,197 @@ #include "config.h" #include "WebKitUIClient.h" +#include "APIUIClient.h" #include "WebKitFileChooserRequestPrivate.h" #include "WebKitGeolocationPermissionRequestPrivate.h" +#include "WebKitNavigationActionPrivate.h" +#include "WebKitNotificationPermissionRequestPrivate.h" #include "WebKitPrivate.h" +#include "WebKitURIRequestPrivate.h" +#include "WebKitUserMediaPermissionRequestPrivate.h" #include "WebKitWebViewBasePrivate.h" #include "WebKitWebViewPrivate.h" #include "WebKitWindowPropertiesPrivate.h" #include "WebPageProxy.h" #include <WebCore/GtkUtilities.h> -#include <wtf/gobject/GRefPtr.h> +#include <wtf/glib/GRefPtr.h> using namespace WebKit; -static WKPageRef createNewPage(WKPageRef page, WKURLRequestRef, WKDictionaryRef wkWindowFeatures, WKEventModifiers, WKEventMouseButton, const void* clientInfo) -{ - return static_cast<WKPageRef>(toAPI(webkitWebViewCreateNewPage(WEBKIT_WEB_VIEW(clientInfo), toImpl(wkWindowFeatures)))); -} +class UIClient : public API::UIClient { +public: + explicit UIClient(WebKitWebView* webView) + : m_webView(webView) + { + } -static void showPage(WKPageRef page, const void* clientInfo) -{ - webkitWebViewReadyToShowPage(WEBKIT_WEB_VIEW(clientInfo)); -} +private: + virtual PassRefPtr<WebPageProxy> createNewPage(WebPageProxy*, WebFrameProxy*, const WebCore::SecurityOriginData&, const WebCore::ResourceRequest& resourceRequest, const WebCore::WindowFeatures& windowFeatures, const NavigationActionData& navigationActionData) override + { + GRefPtr<WebKitURIRequest> request = adoptGRef(webkitURIRequestCreateForResourceRequest(resourceRequest)); + WebKitNavigationAction navigationAction(request.get(), navigationActionData); + return webkitWebViewCreateNewPage(m_webView, windowFeatures, &navigationAction); + } -static void closePage(WKPageRef page, const void* clientInfo) -{ - webkitWebViewClosePage(WEBKIT_WEB_VIEW(clientInfo)); -} + virtual void showPage(WebPageProxy*) override + { + webkitWebViewReadyToShowPage(m_webView); + } -static void runJavaScriptAlert(WKPageRef page, WKStringRef message, WKFrameRef, const void* clientInfo) -{ - webkitWebViewRunJavaScriptAlert(WEBKIT_WEB_VIEW(clientInfo), toImpl(message)->string().utf8()); -} + virtual void close(WebPageProxy*) override + { + webkitWebViewClosePage(m_webView); + } -static bool runJavaScriptConfirm(WKPageRef page, WKStringRef message, WKFrameRef, const void* clientInfo) -{ - return webkitWebViewRunJavaScriptConfirm(WEBKIT_WEB_VIEW(clientInfo), toImpl(message)->string().utf8()); -} + virtual void runJavaScriptAlert(WebPageProxy*, const String& message, WebFrameProxy*, const WebCore::SecurityOriginData&, std::function<void ()> completionHandler) override + { + webkitWebViewRunJavaScriptAlert(m_webView, message.utf8()); + completionHandler(); + } -static WKStringRef runJavaScriptPrompt(WKPageRef page, WKStringRef message, WKStringRef defaultValue, WKFrameRef, const void* clientInfo) -{ - CString result = webkitWebViewRunJavaScriptPrompt(WEBKIT_WEB_VIEW(clientInfo), toImpl(message)->string().utf8(), - toImpl(defaultValue)->string().utf8()); - return WKStringCreateWithUTF8CString(result.data()); -} + virtual void runJavaScriptConfirm(WebPageProxy*, const String& message, WebFrameProxy*, const WebCore::SecurityOriginData&, std::function<void (bool)> completionHandler) override + { + completionHandler(webkitWebViewRunJavaScriptConfirm(m_webView, message.utf8())); + } -static bool toolbarsAreVisible(WKPageRef page, const void* clientInfo) -{ - WebKitWindowProperties* windowProperties = webkit_web_view_get_window_properties(WEBKIT_WEB_VIEW(clientInfo)); - return webkit_window_properties_get_toolbar_visible(windowProperties); -} + virtual void runJavaScriptPrompt(WebPageProxy*, const String& message, const String& defaultValue, WebFrameProxy*, const WebCore::SecurityOriginData&, std::function<void (const String&)> completionHandler) override + { + CString result = webkitWebViewRunJavaScriptPrompt(m_webView, message.utf8(), defaultValue.utf8()); + if (result.isNull()) { + completionHandler(String()); + return; + } -static void setToolbarsAreVisible(WKPageRef page, bool toolbarsVisible, const void* clientInfo) -{ - WebKitWindowProperties* windowProperties = webkit_web_view_get_window_properties(WEBKIT_WEB_VIEW(clientInfo)); - webkitWindowPropertiesSetToolbarVisible(windowProperties, toolbarsVisible); -} + completionHandler(String::fromUTF8(result.data())); + } -static bool menuBarIsVisible(WKPageRef page, const void* clientInfo) -{ - WebKitWindowProperties* windowProperties = webkit_web_view_get_window_properties(WEBKIT_WEB_VIEW(clientInfo)); - return webkit_window_properties_get_menubar_visible(windowProperties); -} + virtual bool canRunBeforeUnloadConfirmPanel() const override { return true; } -static void setMenuBarIsVisible(WKPageRef page, bool menuBarVisible, const void* clientInfo) -{ - WebKitWindowProperties* windowProperties = webkit_web_view_get_window_properties(WEBKIT_WEB_VIEW(clientInfo)); - webkitWindowPropertiesSetMenubarVisible(windowProperties, menuBarVisible); -} + virtual void runBeforeUnloadConfirmPanel(WebPageProxy*, const String& message, WebFrameProxy*, std::function<void (bool)> completionHandler) override + { + completionHandler(webkitWebViewRunJavaScriptBeforeUnloadConfirm(m_webView, message.utf8())); + } -static bool statusBarIsVisible(WKPageRef page, const void* clientInfo) -{ - WebKitWindowProperties* windowProperties = webkit_web_view_get_window_properties(WEBKIT_WEB_VIEW(clientInfo)); - return webkit_window_properties_get_statusbar_visible(windowProperties); -} + virtual void mouseDidMoveOverElement(WebPageProxy*, const WebHitTestResultData& data, WebEvent::Modifiers modifiers, API::Object*) override + { + webkitWebViewMouseTargetChanged(m_webView, data, toGdkModifiers(modifiers)); + } -static void setStatusBarIsVisible(WKPageRef page, bool statusBarVisible, const void* clientInfo) -{ - WebKitWindowProperties* windowProperties = webkit_web_view_get_window_properties(WEBKIT_WEB_VIEW(clientInfo)); - webkitWindowPropertiesSetStatusbarVisible(windowProperties, statusBarVisible); -} + virtual bool toolbarsAreVisible(WebPageProxy*) override + { + return webkit_window_properties_get_toolbar_visible(webkit_web_view_get_window_properties(m_webView)); + } -static bool isResizable(WKPageRef page, const void* clientInfo) -{ - WebKitWindowProperties* windowProperties = webkit_web_view_get_window_properties(WEBKIT_WEB_VIEW(clientInfo)); - return webkit_window_properties_get_resizable(windowProperties); -} + virtual void setToolbarsAreVisible(WebPageProxy*, bool visible) override + { + webkitWindowPropertiesSetToolbarVisible(webkit_web_view_get_window_properties(m_webView), visible); + } -static void setIsResizable(WKPageRef page, bool resizable, const void* clientInfo) -{ - WebKitWindowProperties* windowProperties = webkit_web_view_get_window_properties(WEBKIT_WEB_VIEW(clientInfo)); - webkitWindowPropertiesSetResizable(windowProperties, resizable); -} + virtual bool menuBarIsVisible(WebPageProxy*) override + { + return webkit_window_properties_get_menubar_visible(webkit_web_view_get_window_properties(m_webView)); + } -static WKRect getWindowFrame(WKPageRef page, const void* clientInfo) -{ - GdkRectangle geometry = { 0, 0, 0, 0 }; - GtkWidget* window = gtk_widget_get_toplevel(GTK_WIDGET(clientInfo)); - if (WebCore::widgetIsOnscreenToplevelWindow(window) && gtk_widget_get_visible(window)) { - gtk_window_get_position(GTK_WINDOW(window), &geometry.x, &geometry.y); - gtk_window_get_size(GTK_WINDOW(window), &geometry.width, &geometry.height); + virtual void setMenuBarIsVisible(WebPageProxy*, bool visible) override + { + webkitWindowPropertiesSetToolbarVisible(webkit_web_view_get_window_properties(m_webView), visible); } - return WKRectMake(geometry.x, geometry.y, geometry.width, geometry.height); -} -static void setWindowFrame(WKPageRef page, WKRect frame, const void* clientInfo) -{ - WebKitWindowProperties* windowProperties = webkit_web_view_get_window_properties(WEBKIT_WEB_VIEW(clientInfo)); - GdkRectangle geometry = { static_cast<int>(frame.origin.x), static_cast<int>(frame.origin.y), - static_cast<int>(frame.size.width), static_cast<int>(frame.size.height) }; - webkitWindowPropertiesSetGeometry(windowProperties, &geometry); -} + virtual bool statusBarIsVisible(WebPageProxy*) override + { + return webkit_window_properties_get_statusbar_visible(webkit_web_view_get_window_properties(m_webView)); + } -static void mouseDidMoveOverElement(WKPageRef page, WKHitTestResultRef hitTestResult, WKEventModifiers modifiers, WKTypeRef userData, const void* clientInfo) -{ - webkitWebViewMouseTargetChanged(WEBKIT_WEB_VIEW(clientInfo), toImpl(hitTestResult), wkEventModifiersToGdkModifiers(modifiers)); -} + virtual void setStatusBarIsVisible(WebPageProxy*, bool visible) override + { + webkitWindowPropertiesSetStatusbarVisible(webkit_web_view_get_window_properties(m_webView), visible); + } -static void printFrame(WKPageRef page, WKFrameRef frame, const void*) -{ - webkitWebViewPrintFrame(WEBKIT_WEB_VIEW(toImpl(page)->viewWidget()), toImpl(frame)); -} + virtual bool isResizable(WebPageProxy*) override + { + return webkit_window_properties_get_resizable(webkit_web_view_get_window_properties(m_webView)); + } -static void runOpenPanel(WKPageRef page, WKFrameRef frame, WKOpenPanelParametersRef parameters, WKOpenPanelResultListenerRef listener, const void *clientInfo) -{ - GRefPtr<WebKitFileChooserRequest> request = adoptGRef(webkitFileChooserRequestCreate(toImpl(parameters), toImpl(listener))); - webkitWebViewRunFileChooserRequest(WEBKIT_WEB_VIEW(clientInfo), request.get()); -} + virtual void setIsResizable(WebPageProxy*, bool resizable) override + { + webkitWindowPropertiesSetResizable(webkit_web_view_get_window_properties(m_webView), resizable); + } -static void decidePolicyForGeolocationPermissionRequest(WKPageRef, WKFrameRef, WKSecurityOriginRef, WKGeolocationPermissionRequestRef request, const void* clientInfo) -{ - GRefPtr<WebKitGeolocationPermissionRequest> geolocationPermissionRequest = adoptGRef(webkitGeolocationPermissionRequestCreate(toImpl(request))); - webkitWebViewMakePermissionRequest(WEBKIT_WEB_VIEW(clientInfo), WEBKIT_PERMISSION_REQUEST(geolocationPermissionRequest.get())); -} + virtual void setWindowFrame(WebPageProxy*, const WebCore::FloatRect& frame) override + { + GdkRectangle geometry = WebCore::IntRect(frame); + webkitWindowPropertiesSetGeometry(webkit_web_view_get_window_properties(m_webView), &geometry); + } -static void runModal(WKPageRef page, const void* clientInfo) -{ - webkitWebViewRunAsModal(WEBKIT_WEB_VIEW(clientInfo)); -} + virtual WebCore::FloatRect windowFrame(WebPageProxy*) override + { + GdkRectangle geometry = { 0, 0, 0, 0 }; + GtkWidget* window = gtk_widget_get_toplevel(GTK_WIDGET(m_webView)); + if (WebCore::widgetIsOnscreenToplevelWindow(window) && gtk_widget_get_visible(window)) { + gtk_window_get_position(GTK_WINDOW(window), &geometry.x, &geometry.y); + gtk_window_get_size(GTK_WINDOW(window), &geometry.width, &geometry.height); + } + return WebCore::FloatRect(geometry); + } + + virtual void exceededDatabaseQuota(WebPageProxy*, WebFrameProxy*, API::SecurityOrigin*, const String&, const String&, unsigned long long /*currentQuota*/, unsigned long long /*currentOriginUsage*/, unsigned long long /*currentDatabaseUsage*/, unsigned long long /*expectedUsage*/, std::function<void (unsigned long long)> completionHandler) override + { + static const unsigned long long defaultQuota = 5 * 1024 * 1204; // 5 MB + // FIXME: Provide API for this. + completionHandler(defaultQuota); + } + + virtual bool runOpenPanel(WebPageProxy*, WebFrameProxy*, WebOpenPanelParameters* parameters, WebOpenPanelResultListenerProxy* listener) override + { + GRefPtr<WebKitFileChooserRequest> request = adoptGRef(webkitFileChooserRequestCreate(parameters, listener)); + webkitWebViewRunFileChooserRequest(m_webView, request.get()); + return true; + } + + virtual bool decidePolicyForGeolocationPermissionRequest(WebPageProxy*, WebFrameProxy*, API::SecurityOrigin*, GeolocationPermissionRequestProxy* permissionRequest) override + { + GRefPtr<WebKitGeolocationPermissionRequest> geolocationPermissionRequest = adoptGRef(webkitGeolocationPermissionRequestCreate(permissionRequest)); + webkitWebViewMakePermissionRequest(m_webView, WEBKIT_PERMISSION_REQUEST(geolocationPermissionRequest.get())); + return true; + } + + virtual bool decidePolicyForUserMediaPermissionRequest(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin& securityOrigin, UserMediaPermissionRequestProxy& permissionRequest) override + { + GRefPtr<WebKitUserMediaPermissionRequest> userMediaPermissionRequest = adoptGRef(webkitUserMediaPermissionRequestCreate(permissionRequest, securityOrigin)); + webkitWebViewMakePermissionRequest(m_webView, WEBKIT_PERMISSION_REQUEST(userMediaPermissionRequest.get())); + return true; + } + + virtual bool decidePolicyForNotificationPermissionRequest(WebPageProxy*, API::SecurityOrigin*, NotificationPermissionRequest* permissionRequest) override + { + GRefPtr<WebKitNotificationPermissionRequest> notificationPermissionRequest = adoptGRef(webkitNotificationPermissionRequestCreate(permissionRequest)); + webkitWebViewMakePermissionRequest(m_webView, WEBKIT_PERMISSION_REQUEST(notificationPermissionRequest.get())); + return true; + } + + virtual void printFrame(WebPageProxy*, WebFrameProxy* frame) override + { + webkitWebViewPrintFrame(m_webView, frame); + } + + virtual bool canRunModal() const override { return true; } + + virtual void runModal(WebPageProxy*) override + { + webkitWebViewRunAsModal(m_webView); + } + + virtual void isPlayingAudioDidChange(WebPageProxy&) override + { + webkitWebViewIsPlayingAudioChanged(m_webView); + } + + WebKitWebView* m_webView; +}; void attachUIClientToView(WebKitWebView* webView) { - WKPageUIClientV2 wkUIClient = { - { - 2, // version - webView, // clientInfo - }, - 0, // createNewPage_deprecatedForUseWithV0 - showPage, - closePage, - 0, // takeFocus - 0, // focus - 0, // unfocus - runJavaScriptAlert, - runJavaScriptConfirm, - runJavaScriptPrompt, - 0, // setStatusText - 0, // mouseDidMoveOverElement_deprecatedForUseWithV0 - 0, // missingPluginButtonClicked - 0, // didNotHandleKeyEvent - 0, // didNotHandleWheelEvent - toolbarsAreVisible, - setToolbarsAreVisible, - menuBarIsVisible, - setMenuBarIsVisible, - statusBarIsVisible, - setStatusBarIsVisible, - isResizable, - setIsResizable, - getWindowFrame, - setWindowFrame, - 0, // runBeforeUnloadConfirmPanel - 0, // didDraw - 0, // pageDidScroll - 0, // exceededDatabaseQuota - runOpenPanel, - decidePolicyForGeolocationPermissionRequest, - 0, // headerHeight - 0, // footerHeight - 0, // drawHeader - 0, // drawFooter - printFrame, - runModal, - 0, // didCompleteRubberBandForMainFrame - 0, // saveDataToFileInDownloadsFolder - 0, // shouldInterruptJavaScript - createNewPage, - mouseDidMoveOverElement, - 0, // decidePolicyForNotificationPermissionRequest - 0, // unavailablePluginButtonClicked - 0, // showColorPicker - 0, // hideColorPicker - 0, // pluginLoadPolicy - }; - WKPageRef wkPage = toAPI(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView))); - WKPageSetPageUIClient(wkPage, &wkUIClient.base); + WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView)); + page->setUIClient(std::make_unique<UIClient>(webView)); } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitURIRequest.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitURIRequest.cpp index 2c59cd868..e2ff04d19 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitURIRequest.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitURIRequest.cpp @@ -48,6 +48,7 @@ using namespace WebCore; struct _WebKitURIRequestPrivate { WebCore::ResourceRequest resourceRequest; CString uri; + const char* httpMethod; GUniquePtr<SoupMessageHeaders> httpHeaders; }; @@ -171,6 +172,32 @@ SoupMessageHeaders* webkit_uri_request_get_http_headers(WebKitURIRequest* reques return request->priv->httpHeaders.get(); } +/** + * webkit_uri_request_get_http_method: + * @request: a #WebKitURIRequest + * + * Get the HTTP method of the #WebKitURIRequest. + * + * Returns: the HTTP method of the #WebKitURIRequest or %NULL if @request is not + * an HTTP request. + * + * Since: 2.12 + */ +const gchar* webkit_uri_request_get_http_method(WebKitURIRequest* request) +{ + g_return_val_if_fail(WEBKIT_IS_URI_REQUEST(request), nullptr); + + if (!request->priv->resourceRequest.url().protocolIsInHTTPFamily()) + return nullptr; + + if (request->priv->resourceRequest.httpMethod().isEmpty()) + return nullptr; + + if (!request->priv->httpMethod) + request->priv->httpMethod = g_intern_string(request->priv->resourceRequest.httpMethod().utf8().data()); + return request->priv->httpMethod; +} + WebKitURIRequest* webkitURIRequestCreateForResourceRequest(const ResourceRequest& resourceRequest) { WebKitURIRequest* uriRequest = WEBKIT_URI_REQUEST(g_object_new(WEBKIT_TYPE_URI_REQUEST, NULL)); diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitURIRequest.h b/Source/WebKit2/UIProcess/API/gtk/WebKitURIRequest.h index cac3b332b..10cf63489 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitURIRequest.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitURIRequest.h @@ -70,6 +70,9 @@ WEBKIT_API void webkit_uri_request_set_uri (WebKitURIRequest *request, const gchar *uri); +WEBKIT_API const gchar * +webkit_uri_request_get_http_method (WebKitURIRequest *request); + WEBKIT_API SoupMessageHeaders * webkit_uri_request_get_http_headers (WebKitURIRequest *request); diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp index 20ab248a5..b85fc4300 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp @@ -22,6 +22,7 @@ #include "WebKitPrivate.h" #include "WebKitURIResponsePrivate.h" +#include <WebCore/GUniquePtrSoup.h> #include <glib/gi18n-lib.h> #include <wtf/text/CString.h> @@ -46,7 +47,8 @@ enum { PROP_STATUS_CODE, PROP_CONTENT_LENGTH, PROP_MIME_TYPE, - PROP_SUGGESTED_FILENAME + PROP_SUGGESTED_FILENAME, + PROP_HTTP_HEADERS }; struct _WebKitURIResponsePrivate { @@ -54,6 +56,7 @@ struct _WebKitURIResponsePrivate { CString uri; CString mimeType; CString suggestedFilename; + GUniquePtr<SoupMessageHeaders> httpHeaders; }; WEBKIT_DEFINE_TYPE(WebKitURIResponse, webkit_uri_response, G_TYPE_OBJECT) @@ -78,6 +81,9 @@ static void webkitURIResponseGetProperty(GObject* object, guint propId, GValue* case PROP_SUGGESTED_FILENAME: g_value_set_string(value, webkit_uri_response_get_suggested_filename(response)); break; + case PROP_HTTP_HEADERS: + g_value_set_boxed(value, webkit_uri_response_get_http_headers(response)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); } @@ -151,6 +157,23 @@ static void webkit_uri_response_class_init(WebKitURIResponseClass* responseClass _("The suggested filename for the URI response"), 0, WEBKIT_PARAM_READABLE)); + + /** + * WebKitURIResponse:http-headers: + * + * The HTTP headers of the response, or %NULL if the response is not an HTTP response. + * + * Since: 2.6 + */ + g_object_class_install_property( + objectClass, + PROP_HTTP_HEADERS, + g_param_spec_boxed( + "http-headers", + _("HTTP Headers"), + _("The The HTTP headers of the response"), + SOUP_TYPE_MESSAGE_HEADERS, + WEBKIT_PARAM_READABLE)); } /** @@ -237,6 +260,31 @@ const gchar* webkit_uri_response_get_suggested_filename(WebKitURIResponse* respo return response->priv->suggestedFilename.data(); } +/** + * webkit_uri_response_get_http_headers: + * @response: a #WebKitURIResponse + * + * Get the HTTP headers of a #WebKitURIResponse as a #SoupMessageHeaders. + * + * Returns: (transfer none): a #SoupMessageHeaders with the HTTP headers of @response + * or %NULL if @response is not an HTTP response. + * Since: 2.6 + */ +SoupMessageHeaders* webkit_uri_response_get_http_headers(WebKitURIResponse* response) +{ + g_return_val_if_fail(WEBKIT_IS_URI_RESPONSE(response), nullptr); + + if (response->priv->httpHeaders) + return response->priv->httpHeaders.get(); + + if (!response->priv->resourceResponse.url().protocolIsInHTTPFamily()) + return nullptr; + + response->priv->httpHeaders.reset(soup_message_headers_new(SOUP_MESSAGE_HEADERS_RESPONSE)); + response->priv->resourceResponse.updateSoupMessageHeaders(response->priv->httpHeaders.get()); + return response->priv->httpHeaders.get(); +} + WebKitURIResponse* webkitURIResponseCreateForResourceResponse(const WebCore::ResourceResponse& resourceResponse) { WebKitURIResponse* uriResponse = WEBKIT_URI_RESPONSE(g_object_new(WEBKIT_TYPE_URI_RESPONSE, NULL)); diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h b/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h index d43eca13f..67316165f 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h @@ -25,6 +25,7 @@ #define WebKitURIResponse_h #include <gio/gio.h> +#include <libsoup/soup.h> #include <webkit2/WebKitDefines.h> G_BEGIN_DECLS @@ -74,6 +75,9 @@ webkit_uri_response_get_mime_type (WebKitURIResponse *response); WEBKIT_API const gchar * webkit_uri_response_get_suggested_filename (WebKitURIResponse *response); +WEBKIT_API SoupMessageHeaders * +webkit_uri_response_get_http_headers (WebKitURIResponse *response); + G_END_DECLS #endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitURISchemeRequest.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitURISchemeRequest.cpp index 6d8c68418..872a56461 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitURISchemeRequest.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitURISchemeRequest.cpp @@ -21,6 +21,7 @@ #include "WebKitURISchemeRequest.h" #include "APIData.h" +#include "WebKitPrivate.h" #include "WebKitURISchemeRequestPrivate.h" #include "WebKitWebContextPrivate.h" #include "WebKitWebView.h" @@ -28,7 +29,7 @@ #include <WebCore/GUniquePtrSoup.h> #include <WebCore/ResourceError.h> #include <libsoup/soup.h> -#include <wtf/gobject/GRefPtr.h> +#include <wtf/glib/GRefPtr.h> #include <wtf/text/CString.h> using namespace WebKit; @@ -69,7 +70,7 @@ struct _WebKitURISchemeRequestPrivate { WEBKIT_DEFINE_TYPE(WebKitURISchemeRequest, webkit_uri_scheme_request, G_TYPE_OBJECT) -static void webkit_uri_scheme_request_class_init(WebKitURISchemeRequestClass* requestClass) +static void webkit_uri_scheme_request_class_init(WebKitURISchemeRequestClass*) { } @@ -165,17 +166,22 @@ static void webkitURISchemeRequestReadCallback(GInputStream* inputStream, GAsync return; } + // Need to check the stream before proceeding as it can be cancelled if finish_error + // was previously call, which won't be detected by g_input_stream_read_finish(). + if (!request->priv->stream) + return; + WebKitURISchemeRequestPrivate* priv = request->priv; - RefPtr<API::Data> webData = API::Data::create(reinterpret_cast<const unsigned char*>(priv->readBuffer), bytesRead); + Ref<API::Data> webData = API::Data::create(reinterpret_cast<const unsigned char*>(priv->readBuffer), bytesRead); if (!priv->bytesRead) { // First chunk read. In case of empty reply an empty API::Data is sent to the networking process. WebCore::ResourceResponse response(WebCore::URL(WebCore::URL(), String::fromUTF8(priv->uri)), String::fromUTF8(priv->mimeType.data()), - priv->streamLength, emptyString(), emptyString()); + priv->streamLength, emptyString()); priv->webRequestManager->didReceiveResponse(priv->requestID, response); - priv->webRequestManager->didLoadData(priv->requestID, webData.get()); + priv->webRequestManager->didLoadData(priv->requestID, webData.ptr()); } else if (bytesRead || (!bytesRead && !priv->streamLength)) { // Subsequent chunk read. We only send an empty API::Data to the networking process when stream length is unknown. - priv->webRequestManager->didLoadData(priv->requestID, webData.get()); + priv->webRequestManager->didLoadData(priv->requestID, webData.ptr()); } if (!bytesRead) { @@ -229,8 +235,11 @@ void webkit_uri_scheme_request_finish_error(WebKitURISchemeRequest* request, GEr g_return_if_fail(error); WebKitURISchemeRequestPrivate* priv = request->priv; + if (!webkitWebContextIsLoadingCustomProtocol(priv->webContext, priv->requestID)) + return; - WebCore::ResourceError resourceError(g_quark_to_string(error->domain), error->code, priv->uri.data(), String::fromUTF8(error->message)); + priv->stream = nullptr; + WebCore::ResourceError resourceError(g_quark_to_string(error->domain), toWebCoreError(error->code), WebCore::URL(priv->soupURI.get()), String::fromUTF8(error->message)); priv->webRequestManager->didFailWithError(priv->requestID, resourceError); webkitWebContextDidFinishLoadingCustomProtocol(priv->webContext, priv->requestID); } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitUserContent.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContent.cpp new file mode 100644 index 000000000..7834c2152 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContent.cpp @@ -0,0 +1,260 @@ +/* + * Copyright (C) 2014 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "WebKitUserContent.h" + +#include "WebKitPrivate.h" +#include "WebKitUserContentPrivate.h" +#include <wtf/text/CString.h> +#include <wtf/text/StringBuilder.h> + +using namespace WebCore; + +/** + * SECTION:WebKitUserContent + * @short_description: Defines user content types which affect web pages. + * @title: User content + * + * See also: #WebKitUserContentManager + * + * Since: 2.6 + */ + +static inline UserContentInjectedFrames toUserContentInjectedFrames(WebKitUserContentInjectedFrames injectedFrames) +{ + switch (injectedFrames) { + case WEBKIT_USER_CONTENT_INJECT_TOP_FRAME: + return InjectInTopFrameOnly; + case WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES: + return InjectInAllFrames; + default: + ASSERT_NOT_REACHED(); + return InjectInAllFrames; + } +} + +static inline UserStyleLevel toUserStyleLevel(WebKitUserStyleLevel styleLevel) +{ + switch (styleLevel) { + case WEBKIT_USER_STYLE_LEVEL_USER: + return UserStyleUserLevel; + case WEBKIT_USER_STYLE_LEVEL_AUTHOR: + return UserStyleAuthorLevel; + default: + ASSERT_NOT_REACHED(); + return UserStyleAuthorLevel; + } +} + +static inline UserScriptInjectionTime toUserScriptInjectionTime(WebKitUserScriptInjectionTime injectionTime) +{ + switch (injectionTime) { + case WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_START: + return InjectAtDocumentStart; + case WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_END: + return InjectAtDocumentEnd; + default: + ASSERT_NOT_REACHED(); + return InjectAtDocumentStart; + } +} + +static inline Vector<String> toStringVector(const char* const* strv) +{ + if (!strv) + return Vector<String>(); + + Vector<String> result; + for (auto str = strv; *str; ++str) + result.append(String::fromUTF8(*str)); + return result; +} + +struct _WebKitUserStyleSheet { + _WebKitUserStyleSheet(const gchar* source, WebKitUserContentInjectedFrames injectedFrames, WebKitUserStyleLevel level, const char* const* whitelist, const char* const* blacklist) + : userStyleSheet(adoptRef(new API::UserStyleSheet(UserStyleSheet { + String::fromUTF8(source), URL { }, + toStringVector(whitelist), toStringVector(blacklist), + toUserContentInjectedFrames(injectedFrames), + toUserStyleLevel(level) }))) + , referenceCount(1) + { + } + + RefPtr<API::UserStyleSheet> userStyleSheet; + int referenceCount; +}; + +G_DEFINE_BOXED_TYPE(WebKitUserStyleSheet, webkit_user_style_sheet, webkit_user_style_sheet_ref, webkit_user_style_sheet_unref) + +/** + * webkit_user_style_sheet_ref: + * @user_style_sheet: a #WebKitUserStyleSheet + * + * Atomically increments the reference count of @user_style_sheet by one. + * This function is MT-safe and may be called from any thread. + * + * Returns: The passed #WebKitUserStyleSheet + * + * Since: 2.6 + */ +WebKitUserStyleSheet* webkit_user_style_sheet_ref(WebKitUserStyleSheet* userStyleSheet) +{ + g_atomic_int_inc(&userStyleSheet->referenceCount); + return userStyleSheet; +} + +/** + * webkit_user_style_sheet_unref: + * @user_style_sheet: a #WebKitUserStyleSheet + * + * Atomically decrements the reference count of @user_style_sheet by one. + * If the reference count drops to 0, all memory allocated by + * #WebKitUserStyleSheet is released. This function is MT-safe and may be + * called from any thread. + * + * Since: 2.6 + */ +void webkit_user_style_sheet_unref(WebKitUserStyleSheet* userStyleSheet) +{ + if (g_atomic_int_dec_and_test(&userStyleSheet->referenceCount)) { + userStyleSheet->~WebKitUserStyleSheet(); + fastFree(userStyleSheet); + } +} + +/** + * webkit_user_style_sheet_new: + * @source: Source code of the user style sheet. + * @injected_frames: A #WebKitUserContentInjectedFrames value + * @level: A #WebKitUserStyleLevel + * @whitelist: (array zero-terminated=1) (allow-none): A whitelist of URI patterns or %NULL + * @blacklist: (array zero-terminated=1) (allow-none): A blacklist of URI patterns or %NULL + * + * Creates a new user style sheet. Style sheets can be applied to some URIs + * only by passing non-null values for @whitelist or @blacklist. Passing a + * %NULL whitelist implies that all URIs are on the whitelist. The style + * sheet is applied if an URI matches the whitelist and not the blacklist. + * URI patterns must be of the form `[protocol]://[host]/[path]`, where the + * *host* and *path* components can contain the wildcard character (`*`) to + * represent zero or more other characters. + * + * Returns: A new #WebKitUserStyleSheet + * + * Since: 2.6 + */ +WebKitUserStyleSheet* webkit_user_style_sheet_new(const gchar* source, WebKitUserContentInjectedFrames injectedFrames, WebKitUserStyleLevel level, const char* const* whitelist, const char* const* blacklist) +{ + g_return_val_if_fail(source, nullptr); + WebKitUserStyleSheet* userStyleSheet = static_cast<WebKitUserStyleSheet*>(fastMalloc(sizeof(WebKitUserStyleSheet))); + new (userStyleSheet) WebKitUserStyleSheet(source, injectedFrames, level, whitelist, blacklist); + return userStyleSheet; +} + +API::UserStyleSheet& webkitUserStyleSheetGetUserStyleSheet(WebKitUserStyleSheet* userStyleSheet) +{ + return *userStyleSheet->userStyleSheet; +} + +struct _WebKitUserScript { + _WebKitUserScript(const gchar* source, WebKitUserContentInjectedFrames injectedFrames, WebKitUserScriptInjectionTime injectionTime, const gchar* const* whitelist, const gchar* const* blacklist) + : userScript(adoptRef(new API::UserScript(UserScript { + String::fromUTF8(source), URL { }, + toStringVector(whitelist), toStringVector(blacklist), + toUserScriptInjectionTime(injectionTime), + toUserContentInjectedFrames(injectedFrames) }))) + , referenceCount(1) + { + } + + RefPtr<API::UserScript> userScript; + int referenceCount; +}; + +G_DEFINE_BOXED_TYPE(WebKitUserScript, webkit_user_script, webkit_user_script_ref, webkit_user_script_unref) + +/** + * webkit_user_script_ref: + * @user_script: a #WebKitUserScript + * + * Atomically increments the reference count of @user_script by one. + * This function is MT-safe and may be called from any thread. + * + * Returns: The passed #WebKitUserScript + * + * Since: 2.6 + */ +WebKitUserScript* webkit_user_script_ref(WebKitUserScript* userScript) +{ + g_atomic_int_inc(&userScript->referenceCount); + return userScript; +} + +/** + * webkit_user_script_unref: + * @user_script: a #WebKitUserScript + * + * Atomically decrements the reference count of @user_script by one. + * If the reference count drops to 0, all memory allocated by + * #WebKitUserScript is released. This function is MT-safe and may be called + * from any thread. + * + * Since: 2.6 + */ +void webkit_user_script_unref(WebKitUserScript* userScript) +{ + if (g_atomic_int_dec_and_test(&userScript->referenceCount)) { + userScript->~WebKitUserScript(); + fastFree(userScript); + } +} + +/** + * webkit_user_script_new: + * @source: Source code of the user script. + * @injected_frames: A #WebKitUserContentInjectedFrames value + * @injection_time: A #WebKitUserScriptInjectionTime value + * @whitelist: (array zero-terminated=1) (allow-none): A whitelist of URI patterns or %NULL + * @blacklist: (array zero-terminated=1) (allow-none): A blacklist of URI patterns or %NULL + * + * Creates a new user script. Scripts can be applied to some URIs + * only by passing non-null values for @whitelist or @blacklist. Passing a + * %NULL whitelist implies that all URIs are on the whitelist. The script + * is applied if an URI matches the whitelist and not the blacklist. + * URI patterns must be of the form `[protocol]://[host]/[path]`, where the + * *host* and *path* components can contain the wildcard character (`*`) to + * represent zero or more other characters. + * + * Returns: A new #WebKitUserScript + * + * Since: 2.6 + */ +WebKitUserScript* webkit_user_script_new(const gchar* source, WebKitUserContentInjectedFrames injectedFrames, WebKitUserScriptInjectionTime injectionTime, const gchar* const* whitelist, const gchar* const* blacklist) +{ + g_return_val_if_fail(source, nullptr); + WebKitUserScript* userScript = static_cast<WebKitUserScript*>(fastMalloc(sizeof(WebKitUserScript))); + new (userScript) WebKitUserScript(source, injectedFrames, injectionTime, whitelist, blacklist); + return userScript; +} + +API::UserScript& webkitUserScriptGetUserScript(WebKitUserScript* userScript) +{ + return *userScript->userScript; +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitUserContent.h b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContent.h new file mode 100644 index 000000000..c3f1ed569 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContent.h @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2014 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) +#error "Only <webkit2/webkit2.h> can be included directly." +#endif + +#ifndef WebKitUserContent_h +#define WebKitUserContent_h + +#include <glib-object.h> +#include <webkit2/WebKitDefines.h> + +G_BEGIN_DECLS + +/** + * WebKitUserContentInjectedFrames: + * @WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES: Insert the user style + * sheet in all the frames loaded by the web view, including + * nested frames. This is the default. + * @WEBKIT_USER_CONTENT_INJECT_TOP_FRAME: Insert the user style + * sheet *only* in the top-level frame loaded by the web view, + * and *not* in the nested frames. + * + * Specifies in which frames user style sheets are to be inserted in. + * + * Since: 2.6 + */ +typedef enum { + WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES, + WEBKIT_USER_CONTENT_INJECT_TOP_FRAME, +} WebKitUserContentInjectedFrames; + +/** + * WebKitUserStyleLevel: + * @WEBKIT_USER_STYLE_LEVEL_USER: The style sheet is an user style sheet, + * its contents always override other style sheets. This is the default. + * @WEBKIT_USER_STYLE_LEVEL_AUTHOR: The style sheet will be treated as if + * it was provided by the loaded documents. That means other user style + * sheets may still override it. + * + * Specifies how to treat an user style sheet. + * + * Since: 2.6 + */ +typedef enum { + WEBKIT_USER_STYLE_LEVEL_USER, + WEBKIT_USER_STYLE_LEVEL_AUTHOR, +} WebKitUserStyleLevel; + +#define WEBKIT_TYPE_USER_STYLE_SHEET (webkit_user_style_sheet_get_type()) + +typedef struct _WebKitUserStyleSheet WebKitUserStyleSheet; + +WEBKIT_API GType +webkit_user_style_sheet_get_type (void); + +WEBKIT_API WebKitUserStyleSheet * +webkit_user_style_sheet_ref (WebKitUserStyleSheet *user_style_sheet); + +WEBKIT_API void +webkit_user_style_sheet_unref (WebKitUserStyleSheet *user_style_sheet); + +WEBKIT_API WebKitUserStyleSheet * +webkit_user_style_sheet_new (const gchar *source, + WebKitUserContentInjectedFrames injected_frames, + WebKitUserStyleLevel level, + const gchar* const *whitelist, + const gchar* const *blacklist); + +/** + * WebKitUserScriptInjectionTime: + * @WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_START: Insert the code of the user + * script at the beginning of loaded documents. This is the default. + * @WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_END: Insert the code of the user + * script at the end of the loaded documents. + * + * Specifies at which place of documents an user script will be inserted. + * + * Since: 2.6 + */ +typedef enum { + WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_START, + WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_END, +} WebKitUserScriptInjectionTime; + +#define WEBKIT_TYPE_USER_SCRIPT (webkit_user_script_get_type()) + +typedef struct _WebKitUserScript WebKitUserScript; + +WEBKIT_API GType +webkit_user_script_get_type (void); + +WEBKIT_API WebKitUserScript * +webkit_user_script_ref (WebKitUserScript *user_script); + +WEBKIT_API void +webkit_user_script_unref (WebKitUserScript *user_script); + +WEBKIT_API WebKitUserScript * +webkit_user_script_new (const gchar *source, + WebKitUserContentInjectedFrames injected_frames, + WebKitUserScriptInjectionTime injection_time, + const gchar* const *whitelist, + const gchar* const *blacklist); + +G_END_DECLS + +#endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentManager.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentManager.cpp new file mode 100644 index 000000000..79d8f64e9 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentManager.cpp @@ -0,0 +1,266 @@ +/* + * Copyright (C) 2014 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "WebKitUserContentManager.h" + +#include "APISerializedScriptValue.h" +#include "WebKitJavascriptResultPrivate.h" +#include "WebKitPrivate.h" +#include "WebKitUserContentManagerPrivate.h" +#include "WebKitUserContentPrivate.h" +#include "WebKitWebContextPrivate.h" +#include "WebScriptMessageHandler.h" +#include <wtf/glib/GRefPtr.h> + +using namespace WebCore; +using namespace WebKit; + +struct _WebKitUserContentManagerPrivate { + _WebKitUserContentManagerPrivate() + : userContentController(adoptRef(new WebUserContentControllerProxy)) + { + } + + RefPtr<WebUserContentControllerProxy> userContentController; +}; + +/** + * SECTION:WebKitUserContentManager + * @short_description: Manages user-defined content which affects web pages. + * @title: WebKitUserContentManager + * + * Using a #WebKitUserContentManager user CSS style sheets can be set to + * be injected in the web pages loaded by a #WebKitWebView, by + * webkit_user_content_manager_add_style_sheet(). + * + * To use a #WebKitUserContentManager, it must be created using + * webkit_user_content_manager_new(), and then passed to + * webkit_web_view_new_with_user_content_manager(). User style + * sheets can be created with webkit_user_style_sheet_new(). + * + * User style sheets can be added and removed at any time, but + * they will affect the web pages loaded afterwards. + * + * Since: 2.6 + */ + +WEBKIT_DEFINE_TYPE(WebKitUserContentManager, webkit_user_content_manager, G_TYPE_OBJECT) + +enum { + SCRIPT_MESSAGE_RECEIVED, + + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0, }; + +static void webkit_user_content_manager_class_init(WebKitUserContentManagerClass* klass) +{ + GObjectClass* gObjectClass = G_OBJECT_CLASS(klass); + + /** + * WebKitUserContentManager::script-message-received: + * @manager: the #WebKitUserContentManager + * @js_result: the #WebKitJavascriptResult holding the value received from the JavaScript world. + * + * This signal is emitted when JavaScript in a web view calls + * <code>window.webkit.messageHandlers.<name>.postMessage()</code>, after registering + * <code><name></code> using + * webkit_user_content_manager_register_script_message_handler() + * + * Since: 2.8 + */ + signals[SCRIPT_MESSAGE_RECEIVED] = + g_signal_new( + "script-message-received", + G_TYPE_FROM_CLASS(gObjectClass), + static_cast<GSignalFlags>(G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED), + 0, nullptr, nullptr, + g_cclosure_marshal_VOID__BOXED, + G_TYPE_NONE, 1, + WEBKIT_TYPE_JAVASCRIPT_RESULT); +} + +/** + * webkit_user_content_manager_new: + * + * Creates a new user content manager. + * + * Returns: A #WebKitUserContentManager + * + * Since: 2.6 + */ +WebKitUserContentManager* webkit_user_content_manager_new() +{ + return WEBKIT_USER_CONTENT_MANAGER(g_object_new(WEBKIT_TYPE_USER_CONTENT_MANAGER, nullptr)); +} + +/** + * webkit_user_content_manager_add_style_sheet: + * @manager: A #WebKitUserContentManager + * @stylesheet: A #WebKitUserStyleSheet + * + * Adds a #WebKitUserStyleSheet to the given #WebKitUserContentManager. + * The same #WebKitUserStyleSheet can be reused with multiple + * #WebKitUserContentManager instances. + * + * Since: 2.6 + */ +void webkit_user_content_manager_add_style_sheet(WebKitUserContentManager* manager, WebKitUserStyleSheet* styleSheet) +{ + g_return_if_fail(WEBKIT_IS_USER_CONTENT_MANAGER(manager)); + g_return_if_fail(styleSheet); + manager->priv->userContentController->addUserStyleSheet(webkitUserStyleSheetGetUserStyleSheet(styleSheet)); +} + +/** + * webkit_user_content_manager_remove_all_style_sheets: + * @manager: A #WebKitUserContentManager + * + * Removes all user style sheets from the given #WebKitUserContentManager. + * + * Since: 2.6 + */ +void webkit_user_content_manager_remove_all_style_sheets(WebKitUserContentManager* manager) +{ + g_return_if_fail(WEBKIT_IS_USER_CONTENT_MANAGER(manager)); + manager->priv->userContentController->removeAllUserStyleSheets(); +} + +/** + * webkit_user_content_manager_add_script: + * @manager: A #WebKitUserContentManager + * @script: A #WebKitUserScript + * + * Adds a #WebKitUserScript to the given #WebKitUserContentManager. + * The same #WebKitUserScript can be reused with multiple + * #WebKitUserContentManager instances. + * + * Since: 2.6 + */ +void webkit_user_content_manager_add_script(WebKitUserContentManager* manager, WebKitUserScript* script) +{ + g_return_if_fail(WEBKIT_IS_USER_CONTENT_MANAGER(manager)); + g_return_if_fail(script); + manager->priv->userContentController->addUserScript(webkitUserScriptGetUserScript(script)); +} + +/** + * webkit_user_content_manager_remove_all_scripts: + * @manager: A #WebKitUserContentManager + * + * Removes all user scripts from the given #WebKitUserContentManager + * + * Since: 2.6 + */ +void webkit_user_content_manager_remove_all_scripts(WebKitUserContentManager* manager) +{ + g_return_if_fail(WEBKIT_IS_USER_CONTENT_MANAGER(manager)); + manager->priv->userContentController->removeAllUserScripts(); +} + +class ScriptMessageClientGtk final : public WebScriptMessageHandler::Client { +public: + ScriptMessageClientGtk(WebKitUserContentManager* manager, const char* handlerName) + : m_handlerName(g_quark_from_string(handlerName)) + , m_manager(manager) + { + } + + virtual void didPostMessage(WebPageProxy& page, WebFrameProxy&, const SecurityOriginData&, WebCore::SerializedScriptValue& serializedScriptValue) + { + WebKitJavascriptResult* jsResult = webkitJavascriptResultCreate(WEBKIT_WEB_VIEW(page.viewWidget()), serializedScriptValue); + g_signal_emit(m_manager, signals[SCRIPT_MESSAGE_RECEIVED], m_handlerName, jsResult); + webkit_javascript_result_unref(jsResult); + } + + virtual ~ScriptMessageClientGtk() { } + +private: + GQuark m_handlerName; + WebKitUserContentManager* m_manager; +}; + +/** + * webkit_user_content_manager_register_script_message_handler: + * @manager: A #WebKitUserContentManager + * @name: Name of the script message channel + * + * Registers a new user script message handler. After it is registered, + * scripts can use `window.webkit.messageHandlers.<name>.postMessage(value)` + * to send messages. Those messages are received by connecting handlers + * to the #WebKitUserContentManager::script-message-received signal. The + * handler name is used as the detail of the signal. To avoid race + * conditions between registering the handler name, and starting to + * receive the signals, it is recommended to connect to the signal + * *before* registering the handler name: + * + * <informalexample><programlisting> + * WebKitWebView *view = webkit_web_view_new (); + * WebKitUserContentManager *manager = webkit_web_view_get_user_content_manager (); + * g_signal_connect (manager, "script-message-received::foobar", + * G_CALLBACK (handle_script_message), NULL); + * webkit_user_content_manager_register_script_message_handler (manager, "foobar"); + * </programlisting></informalexample> + * + * Registering a script message handler will fail if the requested + * name has been already registered before. + * + * Returns: %TRUE if message handler was registered successfully, or %FALSE otherwise. + * + * Since: 2.8 + */ +gboolean webkit_user_content_manager_register_script_message_handler(WebKitUserContentManager* manager, const char* name) +{ + g_return_val_if_fail(WEBKIT_IS_USER_CONTENT_MANAGER(manager), FALSE); + g_return_val_if_fail(name, FALSE); + + RefPtr<WebScriptMessageHandler> handler = + WebScriptMessageHandler::create(std::make_unique<ScriptMessageClientGtk>(manager, name), String::fromUTF8(name)); + return manager->priv->userContentController->addUserScriptMessageHandler(handler.get()); +} + +/** + * webkit_user_content_manager_unregister_script_message_handler: + * @manager: A #WebKitUserContentManager + * @name: Name of the script message channel + * + * Unregisters a previously registered message handler. + * + * Note that this does *not* disconnect handlers for the + * #WebKitUserContentManager::script-message-received signal, + * they will be kept connected, but the signal will not be emitted + * unless the handler name is registered again. + * + * See also webkit_user_content_manager_register_script_message_handler() + * + * Since: 2.8 + */ +void webkit_user_content_manager_unregister_script_message_handler(WebKitUserContentManager* manager, const char* name) +{ + g_return_if_fail(WEBKIT_IS_USER_CONTENT_MANAGER(manager)); + g_return_if_fail(name); + manager->priv->userContentController->removeUserMessageHandlerForName(String::fromUTF8(name)); +} + +WebUserContentControllerProxy* webkitUserContentManagerGetUserContentControllerProxy(WebKitUserContentManager* manager) +{ + return manager->priv->userContentController.get(); +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentManager.h b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentManager.h new file mode 100644 index 000000000..86d24a113 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentManager.h @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2014 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) +#error "Only <webkit2/webkit2.h> can be included directly." +#endif + +#ifndef WebKitUserContentManager_h +#define WebKitUserContentManager_h + +#include <glib-object.h> +#include <webkit2/WebKitDefines.h> +#include <webkit2/WebKitUserContent.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_USER_CONTENT_MANAGER (webkit_user_content_manager_get_type()) +#define WEBKIT_USER_CONTENT_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_USER_CONTENT_MANAGER, WebKitUserContentManager)) +#define WEBKIT_IS_USER_CONTENT_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_USER_CONTENT_MANAGER)) +#define WEBKIT_USER_CONTENT_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_USER_CONTENT_MANAGER, WebKitUserContentManagerClass)) +#define WEBKIT_IS_USER_CONTENT_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_USER_CONTENT_MANAGER)) +#define WEBKIT_USER_CONTENT_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_USER_CONTENT_MANAGER, WebKitUserContentManagerClass)) + +typedef struct _WebKitUserContentManager WebKitUserContentManager; +typedef struct _WebKitUserContentManagerClass WebKitUserContentManagerClass; +typedef struct _WebKitUserContentManagerPrivate WebKitUserContentManagerPrivate; + + +struct _WebKitUserContentManager { + GObject parent; + + /*< private >*/ + WebKitUserContentManagerPrivate *priv; +}; + +struct _WebKitUserContentManagerClass { + GObjectClass parent_class; + + void (*_webkit_reserved0) (void); + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); +}; + + +WEBKIT_API GType +webkit_user_content_manager_get_type (void); + +WEBKIT_API WebKitUserContentManager * +webkit_user_content_manager_new (void); + +WEBKIT_API void +webkit_user_content_manager_add_style_sheet (WebKitUserContentManager *manager, + WebKitUserStyleSheet *stylesheet); +WEBKIT_API void +webkit_user_content_manager_remove_all_style_sheets (WebKitUserContentManager *manager); + +WEBKIT_API gboolean +webkit_user_content_manager_register_script_message_handler (WebKitUserContentManager *manager, + const gchar *name); +WEBKIT_API void +webkit_user_content_manager_unregister_script_message_handler (WebKitUserContentManager *manager, + const gchar *name); + +WEBKIT_API void +webkit_user_content_manager_add_script (WebKitUserContentManager *manager, + WebKitUserScript *script); + +WEBKIT_API void +webkit_user_content_manager_remove_all_scripts (WebKitUserContentManager *manager); + +G_END_DECLS + +#endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentManagerPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentManagerPrivate.h new file mode 100644 index 000000000..f791a5357 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentManagerPrivate.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2014 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef WebKitUserContentManagerPrivate_h +#define WebKitUserContentManagerPrivate_h + +#include "WebKitUserContentManager.h" +#include "WebUserContentControllerProxy.h" + +WebKit::WebUserContentControllerProxy* webkitUserContentManagerGetUserContentControllerProxy(WebKitUserContentManager*); + +#endif // WebKitUserContentManagerPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentPrivate.h new file mode 100644 index 000000000..444e2caaa --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentPrivate.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2014 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef WebKitUserContentPrivate_h +#define WebKitUserContentPrivate_h + +#include "APIUserScript.h" +#include "APIUserStyleSheet.h" +#include "WebKitUserContent.h" +#include <WebCore/UserScript.h> +#include <WebCore/UserStyleSheet.h> + +API::UserScript& webkitUserScriptGetUserScript(WebKitUserScript*); +API::UserStyleSheet& webkitUserStyleSheetGetUserStyleSheet(WebKitUserStyleSheet*); + +#endif // WebKitUserContentPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitUserMediaPermissionRequest.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitUserMediaPermissionRequest.cpp new file mode 100644 index 000000000..63957f2e1 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitUserMediaPermissionRequest.cpp @@ -0,0 +1,196 @@ +/* + * Copyright (C) 2014 Igalia S.L + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "WebKitUserMediaPermissionRequest.h" + +#include "UserMediaPermissionRequestProxy.h" +#include "WebKitPermissionRequest.h" +#include "WebKitUserMediaPermissionRequestPrivate.h" +#include <glib/gi18n-lib.h> + +using namespace WebKit; + +/** + * SECTION: WebKitUserMediaPermissionRequest + * @Short_description: A permission request for accessing user's audio/video devices. + * @Title: WebKitUserMediaPermissionRequest + * @See_also: #WebKitPermissionRequest, #WebKitWebView + * + * WebKitUserMediaPermissionRequest represents a request for + * permission to decide whether WebKit should be allowed to access the user's + * audio and video source devices when requested throught the getUserMedia API. + * + * When a WebKitUserMediaPermissionRequest is not handled by the user, + * it is denied by default. + * + * Since: 2.8 + */ + +enum { + PROP_0, + PROP_IS_FOR_AUDIO_DEVICE, + PROP_IS_FOR_VIDEO_DEVICE +}; + +static void webkit_permission_request_interface_init(WebKitPermissionRequestIface*); + +struct _WebKitUserMediaPermissionRequestPrivate { + RefPtr<UserMediaPermissionRequestProxy> request; + bool madeDecision; +}; + +WEBKIT_DEFINE_TYPE_WITH_CODE( + WebKitUserMediaPermissionRequest, webkit_user_media_permission_request, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE(WEBKIT_TYPE_PERMISSION_REQUEST, webkit_permission_request_interface_init)) + +static void webkitUserMediaPermissionRequestAllow(WebKitPermissionRequest* request) +{ + ASSERT(WEBKIT_IS_USER_MEDIA_PERMISSION_REQUEST(request)); + + WebKitUserMediaPermissionRequestPrivate* priv = WEBKIT_USER_MEDIA_PERMISSION_REQUEST(request)->priv; + + // Only one decision at a time. + if (priv->madeDecision) + return; + + priv->madeDecision = true; + + auto videoDeviceUIDs = priv->request->videoDeviceUIDs(); + auto audioDeviceUIDs = priv->request->audioDeviceUIDs(); + + auto videoDevice = !videoDeviceUIDs.isEmpty() ? videoDeviceUIDs[0] : emptyString(); + auto audioDevice = !audioDeviceUIDs.isEmpty() ? audioDeviceUIDs[0] : emptyString(); + + priv->request->allow(audioDevice, videoDevice); +} + +static void webkitUserMediaPermissionRequestDeny(WebKitPermissionRequest* request) +{ + ASSERT(WEBKIT_IS_USER_MEDIA_PERMISSION_REQUEST(request)); + + WebKitUserMediaPermissionRequestPrivate* priv = WEBKIT_USER_MEDIA_PERMISSION_REQUEST(request)->priv; + + // Only one decision at a time. + if (priv->madeDecision) + return; + + priv->madeDecision = true; + priv->request->deny(); +} + +static void webkit_permission_request_interface_init(WebKitPermissionRequestIface* iface) +{ + iface->allow = webkitUserMediaPermissionRequestAllow; + iface->deny = webkitUserMediaPermissionRequestDeny; +} + +static void webkitUserMediaPermissionRequestDispose(GObject* object) +{ + // Default behaviour when no decision has been made is denying the request. + webkitUserMediaPermissionRequestDeny(WEBKIT_PERMISSION_REQUEST(object)); + G_OBJECT_CLASS(webkit_user_media_permission_request_parent_class)->dispose(object); +} + +/** + * webkit_user_media_permission_is_for_audio_device: + * @request: a #WebKitUserMediaPermissionRequest + * + * Returns: %TRUE if access to an audio device was requested. + * + * Since: 2.8 + */ +gboolean webkit_user_media_permission_is_for_audio_device(WebKitUserMediaPermissionRequest* request) +{ + g_return_val_if_fail(request->priv->request, FALSE); + return request->priv->request->requiresAudio(); +} + +/** + * webkit_user_media_permission_is_for_video_device: + * @request: a #WebKitUserMediaPermissionRequest + * + * Returns: %TRUE if access to a video device was requested. + * + * Since: 2.8 + */ +gboolean webkit_user_media_permission_is_for_video_device(WebKitUserMediaPermissionRequest* request) +{ + g_return_val_if_fail(request->priv->request, FALSE); + return request->priv->request->requiresVideo(); +} + +static void webkitUserMediaPermissionRequestGetProperty(GObject* object, guint propId, GValue* value, GParamSpec* paramSpec) +{ + WebKitUserMediaPermissionRequest* request = WEBKIT_USER_MEDIA_PERMISSION_REQUEST(object); + + switch (propId) { + case PROP_IS_FOR_AUDIO_DEVICE: + g_value_set_boolean(value, webkit_user_media_permission_is_for_audio_device(request)); + break; + case PROP_IS_FOR_VIDEO_DEVICE: + g_value_set_boolean(value, webkit_user_media_permission_is_for_video_device(request)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); + } +} + +static void webkit_user_media_permission_request_class_init(WebKitUserMediaPermissionRequestClass* klass) +{ + GObjectClass* objectClass = G_OBJECT_CLASS(klass); + objectClass->dispose = webkitUserMediaPermissionRequestDispose; + objectClass->get_property = webkitUserMediaPermissionRequestGetProperty; + + /** + * WebKitUserPermissionRequest:is-for-audio-device: + * + * Whether the media device to which the permission was requested has a microphone or not. + * + * Since: 2.8 + */ + g_object_class_install_property(objectClass, PROP_IS_FOR_AUDIO_DEVICE, + g_param_spec_boolean("is-for-audio-device", _("Is for audio device"), + _("Whether the media device to which the permission was requested has a microphone or not."), + FALSE, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitUserPermissionRequest:is-for-video-device: + * + * Whether the media device to which the permission was requested has a video capture capability or not. + * + * Since: 2.8 + */ + g_object_class_install_property(objectClass, PROP_IS_FOR_VIDEO_DEVICE, + g_param_spec_boolean("is-for-video-device", _("Is for video device"), + _("Whether the media device to which the permission was requested has a video capture capability or not."), + FALSE, + WEBKIT_PARAM_READABLE)); +} + +WebKitUserMediaPermissionRequest* webkitUserMediaPermissionRequestCreate(UserMediaPermissionRequestProxy& request, API::SecurityOrigin& securityOrigin) +{ + WebKitUserMediaPermissionRequest* usermediaPermissionRequest = WEBKIT_USER_MEDIA_PERMISSION_REQUEST(g_object_new(WEBKIT_TYPE_USER_MEDIA_PERMISSION_REQUEST, nullptr)); + + // FIXME: store SecurityOrigin + UNUSED_PARAM(securityOrigin); + + usermediaPermissionRequest->priv->request = &request; + return usermediaPermissionRequest; +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitUserMediaPermissionRequest.h b/Source/WebKit2/UIProcess/API/gtk/WebKitUserMediaPermissionRequest.h new file mode 100644 index 000000000..ad382b1ba --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitUserMediaPermissionRequest.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2014 Igalia S.L + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) +#error "Only <webkit2/webkit2.h> can be included directly." +#endif + +#ifndef WebKitUserMediaPermissionRequest_h +#define WebKitUserMediaPermissionRequest_h + +#include <glib-object.h> +#include <webkit2/WebKitDefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_USER_MEDIA_PERMISSION_REQUEST (webkit_user_media_permission_request_get_type()) +#define WEBKIT_USER_MEDIA_PERMISSION_REQUEST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_USER_MEDIA_PERMISSION_REQUEST, WebKitUserMediaPermissionRequest)) +#define WEBKIT_USER_MEDIA_PERMISSION_REQUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_USER_MEDIA_PERMISSION_REQUEST, WebKitUserMediaPermissionRequestClass)) +#define WEBKIT_IS_USER_MEDIA_PERMISSION_REQUEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_USER_MEDIA_PERMISSION_REQUEST)) +#define WEBKIT_IS_USER_MEDIA_PERMISSION_REQUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_USER_MEDIA_PERMISSION_REQUEST)) +#define WEBKIT_USER_MEDIA_PERMISSION_REQUEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_USER_MEDIA_PERMISSION_REQUEST, WebKitUserMediaPermissionRequestClass)) + +typedef struct _WebKitUserMediaPermissionRequest WebKitUserMediaPermissionRequest; +typedef struct _WebKitUserMediaPermissionRequestClass WebKitUserMediaPermissionRequestClass; +typedef struct _WebKitUserMediaPermissionRequestPrivate WebKitUserMediaPermissionRequestPrivate; + +struct _WebKitUserMediaPermissionRequest { + GObject parent; + + /*< private >*/ + WebKitUserMediaPermissionRequestPrivate *priv; +}; + +struct _WebKitUserMediaPermissionRequestClass { + GObjectClass parent_class; + + void (*_webkit_reserved0) (void); + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); +}; + +WEBKIT_API GType +webkit_user_media_permission_request_get_type (void); + +WEBKIT_API gboolean +webkit_user_media_permission_is_for_audio_device (WebKitUserMediaPermissionRequest *request); + +WEBKIT_API gboolean +webkit_user_media_permission_is_for_video_device (WebKitUserMediaPermissionRequest *request); + +G_END_DECLS + +#endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitUserMediaPermissionRequestPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitUserMediaPermissionRequestPrivate.h new file mode 100644 index 000000000..a729d9112 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitUserMediaPermissionRequestPrivate.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2014 Igalia S.L + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef WebKitUserMediaPermissionRequestPrivate_h +#define WebKitUserMediaPermissionRequestPrivate_h + +#include "WebKitPrivate.h" +#include "WebKitUserMediaPermissionRequest.h" + +class SecurityOrigin; + +WebKitUserMediaPermissionRequest* webkitUserMediaPermissionRequestCreate(WebKit::UserMediaPermissionRequestProxy&, API::SecurityOrigin&); + +#endif // WebKitUserMediaPermissionRequestPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitVersion.h.in b/Source/WebKit2/UIProcess/API/gtk/WebKitVersion.h.in index b1c5af45d..1364bf602 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitVersion.h.in +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitVersion.h.in @@ -35,7 +35,7 @@ G_BEGIN_DECLS * application compile time, rather than from the library linked * against at application run time. */ -#define WEBKIT_MAJOR_VERSION (@WEBKIT_MAJOR_VERSION@) +#define WEBKIT_MAJOR_VERSION (@PROJECT_VERSION_MAJOR@) /** * WEBKIT_MINOR_VERSION: @@ -44,7 +44,7 @@ G_BEGIN_DECLS * application compile time, rather than from the library linked * against at application run time. */ -#define WEBKIT_MINOR_VERSION (@WEBKIT_MINOR_VERSION@) +#define WEBKIT_MINOR_VERSION (@PROJECT_VERSION_MINOR@) /** * WEBKIT_MICRO_VERSION: @@ -53,7 +53,7 @@ G_BEGIN_DECLS * application compile time, rather than from the library linked * against at application run time. */ -#define WEBKIT_MICRO_VERSION (@WEBKIT_MICRO_VERSION@) +#define WEBKIT_MICRO_VERSION (@PROJECT_VERSION_MICRO@) /** * WEBKIT_CHECK_VERSION: diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp index 1528324ba..365a1d7ba 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp @@ -20,39 +20,48 @@ #include "config.h" #include "WebKitWebContext.h" +#include "APIDownloadClient.h" +#include "APIPageConfiguration.h" +#include "APIProcessPoolConfiguration.h" #include "APIString.h" +#include "TextChecker.h" +#include "TextCheckerState.h" #include "WebBatteryManagerProxy.h" #include "WebCertificateInfo.h" #include "WebCookieManagerProxy.h" #include "WebGeolocationManagerProxy.h" #include "WebKitBatteryProvider.h" -#include "WebKitCertificateInfoPrivate.h" #include "WebKitCookieManagerPrivate.h" #include "WebKitDownloadClient.h" #include "WebKitDownloadPrivate.h" #include "WebKitFaviconDatabasePrivate.h" #include "WebKitGeolocationProvider.h" #include "WebKitInjectedBundleClient.h" +#include "WebKitNotificationProvider.h" #include "WebKitPluginPrivate.h" #include "WebKitPrivate.h" #include "WebKitRequestManagerClient.h" #include "WebKitSecurityManagerPrivate.h" -#include "WebKitTextChecker.h" +#include "WebKitSettingsPrivate.h" #include "WebKitURISchemeRequestPrivate.h" +#include "WebKitUserContentManagerPrivate.h" #include "WebKitWebContextPrivate.h" #include "WebKitWebViewBasePrivate.h" -#include "WebKitWebViewGroupPrivate.h" -#include "WebResourceCacheManagerProxy.h" +#include "WebKitWebViewPrivate.h" +#include "WebKitWebsiteDataManagerPrivate.h" +#include "WebNotificationManagerProxy.h" #include <WebCore/FileSystem.h> #include <WebCore/IconDatabase.h> #include <WebCore/Language.h> +#include <glib/gi18n-lib.h> #include <libintl.h> +#include <memory> #include <wtf/HashMap.h> -#include <wtf/OwnPtr.h> +#include <wtf/NeverDestroyed.h> #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> -#include <wtf/gobject/GRefPtr.h> -#include <wtf/gobject/GUniquePtr.h> +#include <wtf/glib/GRefPtr.h> +#include <wtf/glib/GUniquePtr.h> #include <wtf/text/CString.h> using namespace WebKit; @@ -82,9 +91,23 @@ using namespace WebKit; * You can use webkit_web_context_register_uri_scheme() to register * custom URI schemes, and manage several other settings. * + * TLS certificate validation failure is now treated as a transport + * error by default. To handle TLS failures differently, you can + * connect to #WebKitWebView::load-failed-with-tls-errors. + * Alternatively, you can use webkit_web_context_set_tls_errors_policy() + * to set the policy %WEBKIT_TLS_ERRORS_POLICY_IGNORE; however, this is + * not appropriate for Internet applications. + * */ enum { + PROP_0, + + PROP_LOCAL_STORAGE_DIRECTORY, + PROP_WEBSITE_DATA_MANAGER +}; + +enum { DOWNLOAD_STARTED, INITIALIZE_WEB_EXTENSIONS, @@ -134,7 +157,8 @@ typedef HashMap<String, RefPtr<WebKitURISchemeHandler> > URISchemeHandlerMap; typedef HashMap<uint64_t, GRefPtr<WebKitURISchemeRequest> > URISchemeRequestMap; struct _WebKitWebContextPrivate { - RefPtr<WebContext> context; + RefPtr<WebProcessPool> processPool; + bool clientsDetached; GRefPtr<WebKitCookieManager> cookieManager; GRefPtr<WebKitFaviconDatabase> faviconDatabase; @@ -148,27 +172,192 @@ struct _WebKitWebContextPrivate { #if ENABLE(BATTERY_STATUS) RefPtr<WebKitBatteryProvider> batteryProvider; #endif -#if ENABLE(SPELLCHECK) - OwnPtr<WebKitTextChecker> textChecker; +#if ENABLE(NOTIFICATIONS) + RefPtr<WebKitNotificationProvider> notificationProvider; #endif + GRefPtr<WebKitWebsiteDataManager> websiteDataManager; + CString faviconDatabaseDirectory; WebKitTLSErrorsPolicy tlsErrorsPolicy; + WebKitProcessModel processModel; + unsigned processCountLimit; HashMap<uint64_t, WebKitWebView*> webViews; - GRefPtr<WebKitWebViewGroup> defaultWebViewGroup; CString webExtensionsDirectory; GRefPtr<GVariant> webExtensionsInitializationUserData; + + CString localStorageDirectory; }; static guint signals[LAST_SIGNAL] = { 0, }; WEBKIT_DEFINE_TYPE(WebKitWebContext, webkit_web_context, G_TYPE_OBJECT) +static const char* injectedBundleDirectory() +{ +#if ENABLE(DEVELOPER_MODE) + const char* bundleDirectory = g_getenv("WEBKIT_INJECTED_BUNDLE_PATH"); + if (bundleDirectory && g_file_test(bundleDirectory, G_FILE_TEST_IS_DIR)) + return bundleDirectory; +#endif + + static const char* injectedBundlePath = LIBDIR G_DIR_SEPARATOR_S "webkit2gtk-" WEBKITGTK_API_VERSION_STRING + G_DIR_SEPARATOR_S "injected-bundle" G_DIR_SEPARATOR_S; + return injectedBundlePath; +} + +static void webkitWebContextGetProperty(GObject* object, guint propID, GValue* value, GParamSpec* paramSpec) +{ + WebKitWebContext* context = WEBKIT_WEB_CONTEXT(object); + + switch (propID) { + case PROP_LOCAL_STORAGE_DIRECTORY: + g_value_set_string(value, context->priv->localStorageDirectory.data()); + break; + case PROP_WEBSITE_DATA_MANAGER: + g_value_set_object(value, webkit_web_context_get_website_data_manager(context)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propID, paramSpec); + } +} + +static void webkitWebContextSetProperty(GObject* object, guint propID, const GValue* value, GParamSpec* paramSpec) +{ + WebKitWebContext* context = WEBKIT_WEB_CONTEXT(object); + + switch (propID) { + case PROP_LOCAL_STORAGE_DIRECTORY: + context->priv->localStorageDirectory = g_value_get_string(value); + break; + case PROP_WEBSITE_DATA_MANAGER: { + gpointer manager = g_value_get_object(value); + context->priv->websiteDataManager = manager ? WEBKIT_WEBSITE_DATA_MANAGER(manager) : nullptr; + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propID, paramSpec); + } +} + +static inline WebsiteDataStore::Configuration websiteDataStoreConfigurationForWebProcessPoolConfiguration(const API::ProcessPoolConfiguration& processPoolconfigurarion) +{ + WebsiteDataStore::Configuration configuration; + configuration.applicationCacheDirectory = processPoolconfigurarion.applicationCacheDirectory(); + configuration.networkCacheDirectory = processPoolconfigurarion.diskCacheDirectory(); + configuration.webSQLDatabaseDirectory = processPoolconfigurarion.webSQLDatabaseDirectory(); + configuration.localStorageDirectory = processPoolconfigurarion.localStorageDirectory(); + configuration.mediaKeysStorageDirectory = processPoolconfigurarion.mediaKeysStorageDirectory(); + return configuration; +} + +static void webkitWebContextConstructed(GObject* object) +{ + G_OBJECT_CLASS(webkit_web_context_parent_class)->constructed(object); + + GUniquePtr<char> bundleFilename(g_build_filename(injectedBundleDirectory(), "libwebkit2gtkinjectedbundle.so", nullptr)); + + API::ProcessPoolConfiguration configuration; + configuration.setInjectedBundlePath(WebCore::filenameToString(bundleFilename.get())); + configuration.setMaximumProcessCount(1); + + WebKitWebContext* webContext = WEBKIT_WEB_CONTEXT(object); + WebKitWebContextPrivate* priv = webContext->priv; + if (priv->websiteDataManager) { + configuration.setLocalStorageDirectory(WebCore::filenameToString(webkit_website_data_manager_get_local_storage_directory(priv->websiteDataManager.get()))); + configuration.setDiskCacheDirectory(WebCore::pathByAppendingComponent(WebCore::filenameToString(webkit_website_data_manager_get_disk_cache_directory(priv->websiteDataManager.get())), networkCacheSubdirectory)); + configuration.setApplicationCacheDirectory(WebCore::filenameToString(webkit_website_data_manager_get_offline_application_cache_directory(priv->websiteDataManager.get()))); + configuration.setIndexedDBDatabaseDirectory(WebCore::filenameToString(webkit_website_data_manager_get_indexeddb_directory(priv->websiteDataManager.get()))); + configuration.setWebSQLDatabaseDirectory(WebCore::filenameToString(webkit_website_data_manager_get_websql_directory(priv->websiteDataManager.get()))); + } else if (!priv->localStorageDirectory.isNull()) + configuration.setLocalStorageDirectory(WebCore::filenameToString(priv->localStorageDirectory.data())); + + priv->processPool = WebProcessPool::create(configuration); + + if (!priv->websiteDataManager) + priv->websiteDataManager = webkitWebsiteDataManagerCreate(websiteDataStoreConfigurationForWebProcessPoolConfiguration(configuration)); + + priv->requestManager = priv->processPool->supplement<WebSoupCustomProtocolRequestManager>(); + + priv->tlsErrorsPolicy = WEBKIT_TLS_ERRORS_POLICY_FAIL; + priv->processPool->setIgnoreTLSErrors(false); + + attachInjectedBundleClientToContext(webContext); + attachDownloadClientToContext(webContext); + attachRequestManagerClientToContext(webContext); + +#if ENABLE(GEOLOCATION) + priv->geolocationProvider = WebKitGeolocationProvider::create(priv->processPool->supplement<WebGeolocationManagerProxy>()); +#endif +#if ENABLE(BATTERY_STATUS) + priv->batteryProvider = WebKitBatteryProvider::create(priv->processPool->supplement<WebBatteryManagerProxy>()); +#endif +#if ENABLE(NOTIFICATIONS) + priv->notificationProvider = WebKitNotificationProvider::create(priv->processPool->supplement<WebNotificationManagerProxy>()); +#endif +} + +static void webkitWebContextDispose(GObject* object) +{ + WebKitWebContextPrivate* priv = WEBKIT_WEB_CONTEXT(object)->priv; + if (!priv->clientsDetached) { + priv->clientsDetached = true; + priv->processPool->initializeInjectedBundleClient(nullptr); + priv->processPool->setDownloadClient(nullptr); + } + + G_OBJECT_CLASS(webkit_web_context_parent_class)->dispose(object); +} + static void webkit_web_context_class_init(WebKitWebContextClass* webContextClass) { GObjectClass* gObjectClass = G_OBJECT_CLASS(webContextClass); + bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); + bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); + + gObjectClass->get_property = webkitWebContextGetProperty; + gObjectClass->set_property = webkitWebContextSetProperty; + gObjectClass->constructed = webkitWebContextConstructed; + gObjectClass->dispose = webkitWebContextDispose; + + /** + * WebKitWebContext:local-storage-directory: + * + * The directory where local storage data will be saved. + * + * Since: 2.8 + * + * Deprecated: 2.10. Use #WebKitWebsiteDataManager:local-storage-directory instead. + */ + g_object_class_install_property( + gObjectClass, + PROP_LOCAL_STORAGE_DIRECTORY, + g_param_spec_string( + "local-storage-directory", + _("Local Storage Directory"), + _("The directory where local storage data will be saved"), + nullptr, + static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); + + /** + * WebKitWebContext:website-data-manager: + * + * The #WebKitWebsiteDataManager associated with this context. + * + * Since: 2.10 + */ + g_object_class_install_property( + gObjectClass, + PROP_WEBSITE_DATA_MANAGER, + g_param_spec_object( + "website-data-manager", + _("Website Data Manager"), + _("The WebKitWebsiteDataManager associated with this context"), + WEBKIT_TYPE_WEBSITE_DATA_MANAGER, + static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); + /** * WebKitWebContext::download-started: * @context: the #WebKitWebContext @@ -178,12 +367,13 @@ static void webkit_web_context_class_init(WebKitWebContextClass* webContextClass */ signals[DOWNLOAD_STARTED] = g_signal_new("download-started", - G_TYPE_FROM_CLASS(gObjectClass), - G_SIGNAL_RUN_LAST, - 0, 0, 0, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, - WEBKIT_TYPE_DOWNLOAD); + G_TYPE_FROM_CLASS(gObjectClass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(WebKitWebContextClass, download_started), + nullptr, nullptr, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + WEBKIT_TYPE_DOWNLOAD); /** * WebKitWebContext::initialize-web-extensions: @@ -200,54 +390,15 @@ static void webkit_web_context_class_init(WebKitWebContextClass* webContextClass g_signal_new("initialize-web-extensions", G_TYPE_FROM_CLASS(gObjectClass), G_SIGNAL_RUN_LAST, - 0, nullptr, nullptr, + G_STRUCT_OFFSET(WebKitWebContextClass, initialize_web_extensions), + nullptr, nullptr, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); } -static CString injectedBundleDirectory() -{ - const char* bundleDirectory = g_getenv("WEBKIT_INJECTED_BUNDLE_PATH"); - if (bundleDirectory && g_file_test(bundleDirectory, G_FILE_TEST_IS_DIR)) - return bundleDirectory; - - static const char* injectedBundlePath = LIBDIR G_DIR_SEPARATOR_S "webkit2gtk-" WEBKITGTK_API_VERSION_STRING - G_DIR_SEPARATOR_S "injected-bundle" G_DIR_SEPARATOR_S; - return injectedBundlePath; -} - -static CString injectedBundleFilename() -{ - GUniquePtr<char> bundleFilename(g_build_filename(injectedBundleDirectory().data(), "libwebkit2gtkinjectedbundle.so", NULL)); - return bundleFilename.get(); -} - static gpointer createDefaultWebContext(gpointer) { - bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); - bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); - - static GRefPtr<WebKitWebContext> webContext = adoptGRef(WEBKIT_WEB_CONTEXT(g_object_new(WEBKIT_TYPE_WEB_CONTEXT, NULL))); - WebKitWebContextPrivate* priv = webContext->priv; - - priv->context = WebContext::create(WebCore::filenameToString(injectedBundleFilename().data())); - priv->requestManager = webContext->priv->context->supplement<WebSoupCustomProtocolRequestManager>(); - priv->context->setCacheModel(CacheModelPrimaryWebBrowser); - priv->tlsErrorsPolicy = WEBKIT_TLS_ERRORS_POLICY_IGNORE; - - attachInjectedBundleClientToContext(webContext.get()); - attachDownloadClientToContext(webContext.get()); - attachRequestManagerClientToContext(webContext.get()); - -#if ENABLE(GEOLOCATION) - priv->geolocationProvider = WebKitGeolocationProvider::create(priv->context->supplement<WebGeolocationManagerProxy>()); -#endif -#if ENABLE(BATTERY_STATUS) - priv->batteryProvider = WebKitBatteryProvider::create(priv->context->supplement<WebBatteryManagerProxy>()); -#endif -#if ENABLE(SPELLCHECK) - priv->textChecker = WebKitTextChecker::create(); -#endif + static GRefPtr<WebKitWebContext> webContext = adoptGRef(WEBKIT_WEB_CONTEXT(g_object_new(WEBKIT_TYPE_WEB_CONTEXT, nullptr))); return webContext.get(); } @@ -265,6 +416,54 @@ WebKitWebContext* webkit_web_context_get_default(void) } /** + * webkit_web_context_new: + * + * Create a new #WebKitWebContext + * + * Returns: (transfer full): a newly created #WebKitWebContext + * + * Since: 2.8 + */ +WebKitWebContext* webkit_web_context_new(void) +{ + return WEBKIT_WEB_CONTEXT(g_object_new(WEBKIT_TYPE_WEB_CONTEXT, nullptr)); +} + +/** + * webkit_web_context_new_with_website_data_manager: + * @manager: a #WebKitWebsiteDataManager + * + * Create a new #WebKitWebContext with a #WebKitWebsiteDataManager. + * + * Returns: (transfer full): a newly created #WebKitWebContext + * + * Since: 2.10 + */ +WebKitWebContext* webkit_web_context_new_with_website_data_manager(WebKitWebsiteDataManager* manager) +{ + g_return_val_if_fail(WEBKIT_IS_WEBSITE_DATA_MANAGER(manager), nullptr); + + return WEBKIT_WEB_CONTEXT(g_object_new(WEBKIT_TYPE_WEB_CONTEXT, "website-data-manager", manager, nullptr)); +} + +/** + * webkit_web_context_get_website_data_manager: + * @context: the #WebKitWebContext + * + * Get the #WebKitWebsiteDataManager of @context. + * + * Returns: (transfer none): a #WebKitWebsiteDataManager + * + * Since: 2.10 + */ +WebKitWebsiteDataManager* webkit_web_context_get_website_data_manager(WebKitWebContext* context) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), nullptr); + + return context->priv->websiteDataManager.get(); +} + +/** * webkit_web_context_set_cache_model: * @context: the #WebKitWebContext * @cache_model: a #WebKitCacheModel @@ -308,8 +507,8 @@ void webkit_web_context_set_cache_model(WebKitWebContext* context, WebKitCacheMo g_assert_not_reached(); } - if (cacheModel != context->priv->context->cacheModel()) - context->priv->context->setCacheModel(cacheModel); + if (cacheModel != context->priv->processPool->cacheModel()) + context->priv->processPool->setCacheModel(cacheModel); } /** @@ -326,7 +525,7 @@ WebKitCacheModel webkit_web_context_get_cache_model(WebKitWebContext* context) { g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), WEBKIT_CACHE_MODEL_WEB_BROWSER); - switch (context->priv->context->cacheModel()) { + switch (context->priv->processPool->cacheModel()) { case CacheModelDocumentViewer: return WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER; case CacheModelPrimaryWebBrowser: @@ -351,14 +550,16 @@ void webkit_web_context_clear_cache(WebKitWebContext* context) { g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context)); - context->priv->context->supplement<WebResourceCacheManagerProxy>()->clearCacheForAllOrigins(AllResourceCaches); + auto& websiteDataStore = webkitWebsiteDataManagerGetDataStore(context->priv->websiteDataManager.get()).websiteDataStore(); + websiteDataStore.removeData(static_cast<WebsiteDataTypes>(WebsiteDataTypes::WebsiteDataTypeMemoryCache | WebsiteDataTypes::WebsiteDataTypeDiskCache), + std::chrono::system_clock::time_point::min(), [] { }); } typedef HashMap<DownloadProxy*, GRefPtr<WebKitDownload> > DownloadsMap; static DownloadsMap& downloadsMap() { - DEFINE_STATIC_LOCAL(DownloadsMap, downloads, ()); + static NeverDestroyed<DownloadsMap> downloads; return downloads; } @@ -397,7 +598,7 @@ WebKitCookieManager* webkit_web_context_get_cookie_manager(WebKitWebContext* con WebKitWebContextPrivate* priv = context->priv; if (!priv->cookieManager) - priv->cookieManager = adoptGRef(webkitCookieManagerCreate(priv->context->supplement<WebCookieManagerProxy>())); + priv->cookieManager = adoptGRef(webkitCookieManagerCreate(priv->processPool->supplement<WebCookieManagerProxy>())); return priv->cookieManager.get(); } @@ -408,7 +609,7 @@ static void ensureFaviconDatabase(WebKitWebContext* context) if (priv->faviconDatabase) return; - priv->faviconDatabase = adoptGRef(webkitFaviconDatabaseCreate(priv->context->iconDatabase())); + priv->faviconDatabase = adoptGRef(webkitFaviconDatabaseCreate(priv->processPool->iconDatabase())); } /** @@ -431,7 +632,7 @@ void webkit_web_context_set_favicon_database_directory(WebKitWebContext* context g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context)); WebKitWebContextPrivate* priv = context->priv; - WebIconDatabase* iconDatabase = priv->context->iconDatabase(); + WebIconDatabase* iconDatabase = priv->processPool->iconDatabase(); if (iconDatabase->isOpen()) return; @@ -440,7 +641,7 @@ void webkit_web_context_set_favicon_database_directory(WebKitWebContext* context // Use default if 0 is passed as parameter. String directoryPath = WebCore::filenameToString(path); priv->faviconDatabaseDirectory = directoryPath.isEmpty() - ? priv->context->iconDatabasePath().utf8() + ? priv->processPool->iconDatabasePath().utf8() : directoryPath.utf8(); // Build the full path to the icon database file on disk. @@ -448,7 +649,7 @@ void webkit_web_context_set_favicon_database_directory(WebKitWebContext* context WebCore::IconDatabase::defaultDatabaseFilename().utf8().data(), nullptr)); // Setting the path will cause the icon database to be opened. - priv->context->setIconDatabasePath(WebCore::filenameToString(faviconDatabasePath.get())); + priv->processPool->setIconDatabasePath(WebCore::filenameToString(faviconDatabasePath.get())); } /** @@ -528,7 +729,9 @@ void webkit_web_context_set_additional_plugins_directory(WebKitWebContext* conte g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context)); g_return_if_fail(directory); - context->priv->context->setAdditionalPluginsDirectory(WebCore::filenameToString(directory)); +#if ENABLE(NETSCAPE_PLUGIN_API) + context->priv->processPool->setAdditionalPluginsDirectory(WebCore::filenameToString(directory)); +#endif } static void destroyPluginList(GList* plugins) @@ -536,12 +739,14 @@ static void destroyPluginList(GList* plugins) g_list_free_full(plugins, g_object_unref); } -static void webkitWebContextGetPluginThread(GTask* task, gpointer object, gpointer taskData, GCancellable*) +static void webkitWebContextGetPluginThread(GTask* task, gpointer object, gpointer /* taskData */, GCancellable*) { - Vector<PluginModuleInfo> plugins = WEBKIT_WEB_CONTEXT(object)->priv->context->pluginInfoStore().plugins(); GList* returnValue = 0; +#if ENABLE(NETSCAPE_PLUGIN_API) + Vector<PluginModuleInfo> plugins = WEBKIT_WEB_CONTEXT(object)->priv->processPool->pluginInfoStore().plugins(); for (size_t i = 0; i < plugins.size(); ++i) returnValue = g_list_prepend(returnValue, webkitPluginCreate(plugins[i])); +#endif g_task_return_pointer(task, returnValue, reinterpret_cast<GDestroyNotify>(destroyPluginList)); } @@ -659,7 +864,7 @@ gboolean webkit_web_context_get_spell_checking_enabled(WebKitWebContext* context g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), FALSE); #if ENABLE(SPELLCHECK) - return context->priv->textChecker->isSpellCheckingEnabled(); + return TextChecker::state().isContinuousSpellCheckingEnabled; #else return false; #endif @@ -677,7 +882,7 @@ void webkit_web_context_set_spell_checking_enabled(WebKitWebContext* context, gb g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context)); #if ENABLE(SPELLCHECK) - context->priv->textChecker->setSpellCheckingEnabled(enabled); + TextChecker::setContinuousSpellCheckingEnabled(enabled); #endif } @@ -696,10 +901,20 @@ void webkit_web_context_set_spell_checking_enabled(WebKitWebContext* context, gb */ const gchar* const* webkit_web_context_get_spell_checking_languages(WebKitWebContext* context) { - g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), 0); + g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), nullptr); #if ENABLE(SPELLCHECK) - return context->priv->textChecker->getSpellCheckingLanguages(); + Vector<String> spellCheckingLanguages = TextChecker::loadedSpellCheckingLanguages(); + if (spellCheckingLanguages.isEmpty()) + return nullptr; + + static GRefPtr<GPtrArray> languagesToReturn; + languagesToReturn = adoptGRef(g_ptr_array_new_with_free_func(g_free)); + for (const auto& language : spellCheckingLanguages) + g_ptr_array_add(languagesToReturn.get(), g_strdup(language.utf8().data())); + g_ptr_array_add(languagesToReturn.get(), nullptr); + + return reinterpret_cast<char**>(languagesToReturn->pdata); #else return 0; #endif @@ -728,7 +943,10 @@ void webkit_web_context_set_spell_checking_languages(WebKitWebContext* context, g_return_if_fail(languages); #if ENABLE(SPELLCHECK) - context->priv->textChecker->setSpellCheckingLanguages(languages); + Vector<String> spellCheckingLanguages; + for (size_t i = 0; languages[i]; ++i) + spellCheckingLanguages.append(String::fromUTF8(languages[i])); + TextChecker::setSpellCheckingLanguages(spellCheckingLanguages); #endif } @@ -751,7 +969,7 @@ void webkit_web_context_set_preferred_languages(WebKitWebContext* context, const Vector<String> languages; for (size_t i = 0; languageList[i]; ++i) - languages.append(String::fromUTF8(languageList[i]).lower().replace("_", "-")); + languages.append(String::fromUTF8(languageList[i]).convertToASCIILowercase().replace("_", "-")); WebCore::overrideUserPreferredLanguages(languages); WebCore::languageDidChange(); @@ -773,8 +991,8 @@ void webkit_web_context_set_tls_errors_policy(WebKitWebContext* context, WebKitT context->priv->tlsErrorsPolicy = policy; bool ignoreTLSErrors = policy == WEBKIT_TLS_ERRORS_POLICY_IGNORE; - if (context->priv->context->ignoreTLSErrors() != ignoreTLSErrors) - context->priv->context->setIgnoreTLSErrors(ignoreTLSErrors); + if (context->priv->processPool->ignoreTLSErrors() != ignoreTLSErrors) + context->priv->processPool->setIgnoreTLSErrors(ignoreTLSErrors); } /** @@ -842,13 +1060,19 @@ void webkit_web_context_set_web_extensions_initialization_user_data(WebKitWebCon * Set the directory where disk cache files will be stored * This method must be called before loading anything in this context, otherwise * it will not have any effect. + * + * Note that this method overrides the directory set in the #WebKitWebsiteDataManager, + * but it doesn't change the value returned by webkit_website_data_manager_get_disk_cache_directory() + * since the #WebKitWebsiteDataManager is immutable. + * + * Deprecated: 2.10. Use webkit_web_context_new_with_website_data_manager() instead. */ void webkit_web_context_set_disk_cache_directory(WebKitWebContext* context, const char* directory) { g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context)); g_return_if_fail(directory); - context->priv->context->setDiskCacheDirectory(WebCore::filenameToString(directory)); + context->priv->processPool->configuration().setDiskCacheDirectory(WebCore::pathByAppendingComponent(WebCore::filenameToString(directory), networkCacheSubdirectory)); } /** @@ -864,29 +1088,29 @@ void webkit_web_context_prefetch_dns(WebKitWebContext* context, const char* host g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context)); g_return_if_fail(hostname); - ImmutableDictionary::MapType message; + API::Dictionary::MapType message; message.set(String::fromUTF8("Hostname"), API::String::create(String::fromUTF8(hostname))); - context->priv->context->postMessageToInjectedBundle(String::fromUTF8("PrefetchDNS"), ImmutableDictionary::create(std::move(message)).get()); + context->priv->processPool->postMessageToInjectedBundle(String::fromUTF8("PrefetchDNS"), API::Dictionary::create(WTFMove(message)).ptr()); } /** * webkit_web_context_allow_tls_certificate_for_host: * @context: a #WebKitWebContext - * @info: a #WebKitCertificateInfo + * @certificate: a #GTlsCertificate * @host: the host for which a certificate is to be allowed * * Ignore further TLS errors on the @host for the certificate present in @info. * - * Since: 2.4 + * Since: 2.6 */ -void webkit_web_context_allow_tls_certificate_for_host(WebKitWebContext* context, WebKitCertificateInfo* info, const gchar* host) +void webkit_web_context_allow_tls_certificate_for_host(WebKitWebContext* context, GTlsCertificate* certificate, const gchar* host) { g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context)); - g_return_if_fail(info); + g_return_if_fail(G_IS_TLS_CERTIFICATE(certificate)); g_return_if_fail(host); - RefPtr<WebCertificateInfo> webCertificateInfo = WebCertificateInfo::create(webkitCertificateInfoGetCertificateInfo(info)); - context->priv->context->allowSpecificHTTPSCertificateForHost(webCertificateInfo.get(), String::fromUTF8(host)); + RefPtr<WebCertificateInfo> webCertificateInfo = WebCertificateInfo::create(WebCore::CertificateInfo(certificate, static_cast<GTlsCertificateFlags>(0))); + context->priv->processPool->allowSpecificHTTPSCertificateForHost(webCertificateInfo.get(), String::fromUTF8(host)); } /** @@ -910,7 +1134,7 @@ void webkit_web_context_allow_tls_certificate_for_host(WebKitWebContext* context * the rest of the WebViews in the application will still function * normally. * - * This method **must be called before any other functions**, + * This method **must be called before any web process has been created**, * as early as possible in your application. Calling it later will make * your application crash. * @@ -920,24 +1144,18 @@ void webkit_web_context_set_process_model(WebKitWebContext* context, WebKitProce { g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context)); - ProcessModel newProcessModel; + if (processModel == context->priv->processModel) + return; - switch (processModel) { + context->priv->processModel = processModel; + switch (context->priv->processModel) { case WEBKIT_PROCESS_MODEL_SHARED_SECONDARY_PROCESS: - newProcessModel = ProcessModelSharedSecondaryProcess; + context->priv->processPool->setMaximumNumberOfProcesses(1); break; case WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES: - newProcessModel = ProcessModelMultipleSecondaryProcesses; + context->priv->processPool->setMaximumNumberOfProcesses(context->priv->processCountLimit); break; - default: - g_assert_not_reached(); } - - if (newProcessModel == context->priv->context->processModel()) - return; - - context->priv->context->setUsesNetworkProcess(newProcessModel == ProcessModelMultipleSecondaryProcesses); - context->priv->context->setProcessModel(newProcessModel); } /** @@ -955,14 +1173,50 @@ WebKitProcessModel webkit_web_context_get_process_model(WebKitWebContext* contex { g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), WEBKIT_PROCESS_MODEL_SHARED_SECONDARY_PROCESS); - switch (context->priv->context->processModel()) { - case ProcessModelSharedSecondaryProcess: - return WEBKIT_PROCESS_MODEL_SHARED_SECONDARY_PROCESS; - case ProcessModelMultipleSecondaryProcesses: - return WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES; - default: - g_assert_not_reached(); - } + return context->priv->processModel; +} + +/** + * webkit_web_context_set_web_process_count_limit: + * @context: the #WebKitWebContext + * @limit: the maximum number of web processes + * + * Sets the maximum number of web processes that can be created at the same time for the @context. + * The default value is 0 and means no limit. + * + * This method **must be called before any web process has been created**, + * as early as possible in your application. Calling it later will make + * your application crash. + * + * Since: 2.10 + */ +void webkit_web_context_set_web_process_count_limit(WebKitWebContext* context, guint limit) +{ + g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context)); + + if (context->priv->processCountLimit == limit) + return; + + context->priv->processCountLimit = limit; + if (context->priv->processModel != WEBKIT_PROCESS_MODEL_SHARED_SECONDARY_PROCESS) + context->priv->processPool->setMaximumNumberOfProcesses(limit); +} + +/** + * webkit_web_context_get_web_process_count_limit: + * @context: the #WebKitWebContext + * + * Gets the maximum number of web processes that can be created at the same time for the @context. + * + * Returns: the maximum limit of web processes, or 0 if there isn't a limit. + * + * Since: 2.10 + */ +guint webkit_web_context_get_web_process_count_limit(WebKitWebContext* context) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), 0); + + return context->priv->processCountLimit; } WebKitDownload* webkitWebContextGetOrCreateDownload(DownloadProxy* downloadProxy) @@ -979,7 +1233,7 @@ WebKitDownload* webkitWebContextGetOrCreateDownload(DownloadProxy* downloadProxy WebKitDownload* webkitWebContextStartDownload(WebKitWebContext* context, const char* uri, WebPageProxy* initiatingPage) { WebCore::ResourceRequest request(String::fromUTF8(uri)); - DownloadProxy* downloadProxy = context->priv->context->download(initiatingPage, request); + DownloadProxy* downloadProxy = context->priv->processPool->download(initiatingPage, request); WebKitDownload* download = webkitDownloadCreateForRequest(downloadProxy, request); downloadsMap().set(downloadProxy, download); return download; @@ -1003,11 +1257,11 @@ GVariant* webkitWebContextInitializeWebExtensions(WebKitWebContext* context) context->priv->webExtensionsInitializationUserData.get()); } -WebContext* webkitWebContextGetContext(WebKitWebContext* context) +WebProcessPool* webkitWebContextGetProcessPool(WebKitWebContext* context) { g_assert(WEBKIT_IS_WEB_CONTEXT(context)); - return context->priv->context.get(); + return context->priv->processPool.get(); } WebSoupCustomProtocolRequestManager* webkitWebContextGetRequestManager(WebKitWebContext* context) @@ -1041,18 +1295,26 @@ void webkitWebContextDidFinishLoadingCustomProtocol(WebKitWebContext* context, u context->priv->uriSchemeRequests.remove(customProtocolID); } -void webkitWebContextCreatePageForWebView(WebKitWebContext* context, WebKitWebView* webView, WebKitWebViewGroup* webViewGroup, WebKitWebView* relatedView) +bool webkitWebContextIsLoadingCustomProtocol(WebKitWebContext* context, uint64_t customProtocolID) +{ + return context->priv->uriSchemeRequests.get(customProtocolID); +} + +void webkitWebContextCreatePageForWebView(WebKitWebContext* context, WebKitWebView* webView, WebKitUserContentManager* userContentManager, WebKitWebView* relatedView) { WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(webView); - WebPageGroup* pageGroup = webViewGroup ? webkitWebViewGroupGetPageGroup(webViewGroup) : 0; - WebPageProxy* relatedPage = relatedView ? webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(relatedView)) : nullptr; - webkitWebViewBaseCreateWebPage(webViewBase, context->priv->context.get(), pageGroup, relatedPage); + + auto pageConfiguration = API::PageConfiguration::create(); + pageConfiguration->setProcessPool(context->priv->processPool.get()); + pageConfiguration->setPreferences(webkitSettingsGetPreferences(webkit_web_view_get_settings(webView))); + pageConfiguration->setRelatedPage(relatedView ? webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(relatedView)) : nullptr); + pageConfiguration->setUserContentController(userContentManager ? webkitUserContentManagerGetUserContentControllerProxy(userContentManager) : nullptr); + pageConfiguration->setWebsiteDataStore(&webkitWebsiteDataManagerGetDataStore(context->priv->websiteDataManager.get())); + pageConfiguration->setSessionID(pageConfiguration->websiteDataStore()->websiteDataStore().sessionID()); + webkitWebViewBaseCreateWebPage(webViewBase, WTFMove(pageConfiguration)); WebPageProxy* page = webkitWebViewBaseGetPage(webViewBase); context->priv->webViews.set(page->pageID(), webView); - - if (!pageGroup && !context->priv->defaultWebViewGroup) - context->priv->defaultWebViewGroup = adoptGRef(webkitWebViewGroupCreate(&page->pageGroup())); } void webkitWebContextWebViewDestroyed(WebKitWebContext* context, WebKitWebView* webView) @@ -1065,8 +1327,3 @@ WebKitWebView* webkitWebContextGetWebViewForPage(WebKitWebContext* context, WebP { return page ? context->priv->webViews.get(page->pageID()) : 0; } - -WebKitWebViewGroup* webkitWebContextGetDefaultWebViewGroup(WebKitWebContext* context) -{ - return context->priv->defaultWebViewGroup.get(); -} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h index 3ce281b9b..cd55486f4 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h @@ -25,13 +25,13 @@ #define WebKitWebContext_h #include <glib-object.h> -#include <webkit2/WebKitCertificateInfo.h> #include <webkit2/WebKitCookieManager.h> #include <webkit2/WebKitDefines.h> #include <webkit2/WebKitDownload.h> #include <webkit2/WebKitFaviconDatabase.h> #include <webkit2/WebKitSecurityManager.h> #include <webkit2/WebKitURISchemeRequest.h> +#include <webkit2/WebKitWebsiteDataManager.h> G_BEGIN_DECLS @@ -128,14 +128,16 @@ struct _WebKitWebContext { struct _WebKitWebContextClass { GObjectClass parent; + void (* download_started) (WebKitWebContext *context, + WebKitDownload *download); + void (* initialize_web_extensions) (WebKitWebContext *context); + void (*_webkit_reserved0) (void); void (*_webkit_reserved1) (void); void (*_webkit_reserved2) (void); void (*_webkit_reserved3) (void); void (*_webkit_reserved4) (void); void (*_webkit_reserved5) (void); - void (*_webkit_reserved6) (void); - void (*_webkit_reserved7) (void); }; WEBKIT_API GType @@ -144,6 +146,15 @@ webkit_web_context_get_type (void); WEBKIT_API WebKitWebContext * webkit_web_context_get_default (void); +WEBKIT_API WebKitWebContext * +webkit_web_context_new (void); + +WEBKIT_API WebKitWebContext * +webkit_web_context_new_with_website_data_manager (WebKitWebsiteDataManager *manager); + +WEBKIT_API WebKitWebsiteDataManager * +webkit_web_context_get_website_data_manager (WebKitWebContext *context); + WEBKIT_API void webkit_web_context_set_cache_model (WebKitWebContext *context, WebKitCacheModel cache_model); @@ -151,6 +162,13 @@ WEBKIT_API WebKitCacheModel webkit_web_context_get_cache_model (WebKitWebContext *context); WEBKIT_API void +webkit_web_context_set_web_process_count_limit (WebKitWebContext *context, + guint limit); + +WEBKIT_API guint +webkit_web_context_get_web_process_count_limit (WebKitWebContext *context); + +WEBKIT_API void webkit_web_context_clear_cache (WebKitWebContext *context); WEBKIT_API WebKitDownload * @@ -230,13 +248,13 @@ WEBKIT_API void webkit_web_context_prefetch_dns (WebKitWebContext *context, const gchar *hostname); -WEBKIT_API void +WEBKIT_DEPRECATED_FOR(webkit_web_context_new_with_website_data_manager) void webkit_web_context_set_disk_cache_directory (WebKitWebContext *context, const gchar *directory); WEBKIT_API void webkit_web_context_allow_tls_certificate_for_host (WebKitWebContext *context, - WebKitCertificateInfo *info, + GTlsCertificate *certificate, const gchar *host); WEBKIT_API void diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContextPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContextPrivate.h index 06474a1ef..7ee96b199 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContextPrivate.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContextPrivate.h @@ -27,13 +27,13 @@ #define WebKitWebContextPrivate_h #include "DownloadProxy.h" -#include "WebContext.h" #include "WebKitPrivate.h" +#include "WebKitUserContentManager.h" #include "WebKitWebContext.h" -#include "WebKitWebViewGroup.h" +#include "WebProcessPool.h" #include "WebSoupCustomProtocolRequestManager.h" -WebKit::WebContext* webkitWebContextGetContext(WebKitWebContext*); +WebKit::WebProcessPool* webkitWebContextGetProcessPool(WebKitWebContext*); WebKitDownload* webkitWebContextGetOrCreateDownload(WebKit::DownloadProxy*); WebKitDownload* webkitWebContextStartDownload(WebKitWebContext*, const char* uri, WebKit::WebPageProxy*); void webkitWebContextRemoveDownload(WebKit::DownloadProxy*); @@ -42,10 +42,10 @@ WebKit::WebSoupCustomProtocolRequestManager* webkitWebContextGetRequestManager(W void webkitWebContextStartLoadingCustomProtocol(WebKitWebContext*, uint64_t customProtocolID, API::URLRequest*); void webkitWebContextStopLoadingCustomProtocol(WebKitWebContext*, uint64_t customProtocolID); void webkitWebContextDidFinishLoadingCustomProtocol(WebKitWebContext*, uint64_t customProtocolID); -void webkitWebContextCreatePageForWebView(WebKitWebContext*, WebKitWebView*, WebKitWebViewGroup*, WebKitWebView*); +bool webkitWebContextIsLoadingCustomProtocol(WebKitWebContext*, uint64_t customProtocolID); +void webkitWebContextCreatePageForWebView(WebKitWebContext*, WebKitWebView*, WebKitUserContentManager*, WebKitWebView*); void webkitWebContextWebViewDestroyed(WebKitWebContext*, WebKitWebView*); WebKitWebView* webkitWebContextGetWebViewForPage(WebKitWebContext*, WebKit::WebPageProxy*); -WebKitWebViewGroup* webkitWebContextGetDefaultWebViewGroup(WebKitWebContext*); GVariant* webkitWebContextInitializeWebExtensions(WebKitWebContext*); #endif // WebKitWebContextPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebInspector.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebInspector.cpp index 083d27c84..7b46d527f 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebInspector.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebInspector.cpp @@ -24,7 +24,7 @@ #include "WebKitMarshal.h" #include "WebKitWebInspectorPrivate.h" #include <glib/gi18n-lib.h> -#include <wtf/gobject/GRefPtr.h> +#include <wtf/glib/GRefPtr.h> #include <wtf/text/CString.h> using namespace WebKit; @@ -72,7 +72,8 @@ enum { PROP_0, PROP_INSPECTED_URI, - PROP_ATTACHED_HEIGHT + PROP_ATTACHED_HEIGHT, + PROP_CAN_ATTACH }; struct _WebKitWebInspectorPrivate { @@ -84,6 +85,7 @@ struct _WebKitWebInspectorPrivate { RefPtr<WebInspectorProxy> webInspector; CString inspectedURI; unsigned attachedHeight; + bool canAttach; }; WEBKIT_DEFINE_TYPE(WebKitWebInspector, webkit_web_inspector, G_TYPE_OBJECT) @@ -101,6 +103,9 @@ static void webkitWebInspectorGetProperty(GObject* object, guint propId, GValue* case PROP_ATTACHED_HEIGHT: g_value_set_uint(value, webkit_web_inspector_get_attached_height(inspector)); break; + case PROP_CAN_ATTACH: + g_value_set_boolean(value, webkit_web_inspector_get_can_attach(inspector)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); } @@ -137,6 +142,24 @@ static void webkit_web_inspector_class_init(WebKitWebInspectorClass* findClass) WEBKIT_PARAM_READABLE)); /** + * WebKitWebInspector:can-attach: + * + * Whether the @inspector can be attached to the same window that contains + * the inspected view. + * + * Since: 2.8 + */ + g_object_class_install_property( + gObjectClass, + PROP_CAN_ATTACH, + g_param_spec_boolean( + "can-attach", + _("Can Attach"), + _("Whether the inspector can be attached to the same window that contains the inspected view"), + FALSE, + WEBKIT_PARAM_READABLE)); + + /** * WebKitWebInspector::open-window: * @inspector: the #WebKitWebInspector on which the signal is emitted * @@ -295,7 +318,7 @@ static bool attach(WKInspectorRef, const void* clientInfo) return returnValue; } -static bool detach(WKInspectorRef inspector, const void* clientInfo) +static bool detach(WKInspectorRef, const void* clientInfo) { gboolean returnValue; g_signal_emit(WEBKIT_WEB_INSPECTOR(clientInfo), signals[DETACH], 0, &returnValue); @@ -311,6 +334,15 @@ static void didChangeAttachedHeight(WKInspectorRef, unsigned height, const void* g_object_notify(G_OBJECT(inspector), "attached-height"); } +static void didChangeAttachAvailability(WKInspectorRef, bool available, const void* clientInfo) +{ + WebKitWebInspector* inspector = WEBKIT_WEB_INSPECTOR(clientInfo); + if (inspector->priv->canAttach == available) + return; + inspector->priv->canAttach = available; + g_object_notify(G_OBJECT(clientInfo), "can-attach"); +} + WebKitWebInspector* webkitWebInspectorCreate(WebInspectorProxy* webInspector) { WebKitWebInspector* inspector = WEBKIT_WEB_INSPECTOR(g_object_new(WEBKIT_TYPE_WEB_INSPECTOR, NULL)); @@ -328,7 +360,8 @@ WebKitWebInspector* webkitWebInspectorCreate(WebInspectorProxy* webInspector) attach, detach, didChangeAttachedHeight, - nullptr // didChangeAttachedWidth + nullptr, // didChangeAttachedWidth + didChangeAttachAvailability }; WKInspectorSetInspectorClientGtk(toAPI(webInspector), &wkInspectorClientGtk.base); @@ -371,6 +404,25 @@ const char* webkit_web_inspector_get_inspected_uri(WebKitWebInspector* inspector } /** + * webkit_web_inspector_get_can_attach: + * @inspector: a #WebKitWebInspector + * + * Whether the @inspector can be attached to the same window that contains + * the inspected view. + * + * Returns: %TRUE if there is enough room for the inspector view inside the + * window that contains the inspected view, or %FALSE otherwise. + * + * Since: 2.8 + */ +gboolean webkit_web_inspector_get_can_attach(WebKitWebInspector* inspector) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_INSPECTOR(inspector), FALSE); + + return inspector->priv->canAttach; +} + +/** * webkit_web_inspector_is_attached: * @inspector: a #WebKitWebInspector * diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebInspector.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebInspector.h index 67f0f4957..686f949ac 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebInspector.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebInspector.h @@ -83,6 +83,9 @@ webkit_web_inspector_close (WebKitWebInspector *inspector); WEBKIT_API guint webkit_web_inspector_get_attached_height (WebKitWebInspector *inspector); +WEBKIT_API gboolean +webkit_web_inspector_get_can_attach (WebKitWebInspector* inspector); + G_END_DECLS #endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebResource.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebResource.cpp index b4e11e90c..7dbd804ad 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebResource.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebResource.cpp @@ -26,7 +26,7 @@ #include "WebKitURIRequest.h" #include "WebKitWebResourcePrivate.h" #include <glib/gi18n-lib.h> -#include <wtf/gobject/GRefPtr.h> +#include <wtf/glib/GRefPtr.h> #include <wtf/text/CString.h> using namespace WebKit; @@ -53,6 +53,7 @@ enum { RECEIVED_DATA, FINISHED, FAILED, + FAILED_WITH_TLS_ERRORS, LAST_SIGNAL }; @@ -190,13 +191,34 @@ static void webkit_web_resource_class_init(WebKitWebResourceClass* resourceClass * load operation. */ signals[FAILED] = - g_signal_new("failed", - G_TYPE_FROM_CLASS(objectClass), - G_SIGNAL_RUN_LAST, - 0, 0, 0, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, - G_TYPE_POINTER); + g_signal_new( + "failed", + G_TYPE_FROM_CLASS(objectClass), + G_SIGNAL_RUN_LAST, + 0, 0, 0, + g_cclosure_marshal_VOID__BOXED, + G_TYPE_NONE, 1, + G_TYPE_ERROR | G_SIGNAL_TYPE_STATIC_SCOPE); + + /** + * WebKitWebResource::failed-with-tls-errors: + * @resource: the #WebKitWebResource + * @certificate: a #GTlsCertificate + * @errors: a #GTlsCertificateFlags with the verification status of @certificate + * + * This signal is emitted when a TLS error occurs during the resource load operation. + * + * Since: 2.8 + */ + signals[FAILED_WITH_TLS_ERRORS] = + g_signal_new("failed-with-tls-errors", + G_TYPE_FROM_CLASS(objectClass), + G_SIGNAL_RUN_LAST, + 0, nullptr, nullptr, + g_cclosure_marshal_generic, + G_TYPE_NONE, 2, + G_TYPE_TLS_CERTIFICATE, + G_TYPE_TLS_CERTIFICATE_FLAGS); } static void webkitWebResourceUpdateURI(WebKitWebResource* resource, const CString& requestURI) @@ -246,6 +268,12 @@ void webkitWebResourceFailed(WebKitWebResource* resource, GError* error) g_signal_emit(resource, signals[FINISHED], 0, NULL); } +void webkitWebResourceFailedWithTLSErrors(WebKitWebResource* resource, GTlsCertificateFlags tlsErrors, GTlsCertificate* certificate) +{ + g_signal_emit(resource, signals[FAILED_WITH_TLS_ERRORS], 0, certificate, tlsErrors); + g_signal_emit(resource, signals[FINISHED], 0, nullptr); +} + WebFrameProxy* webkitWebResourceGetFrame(WebKitWebResource* resource) { return resource->priv->frame.get(); @@ -314,12 +342,11 @@ struct ResourceGetDataAsyncData { }; WEBKIT_DEFINE_ASYNC_DATA_STRUCT(ResourceGetDataAsyncData) -static void resourceDataCallback(WKDataRef wkData, WKErrorRef, void* context) +static void resourceDataCallback(API::Data* wkData, GTask* task) { - GRefPtr<GTask> task = adoptGRef(G_TASK(context)); - ResourceGetDataAsyncData* data = static_cast<ResourceGetDataAsyncData*>(g_task_get_task_data(task.get())); - data->webData = toImpl(wkData); - g_task_return_boolean(task.get(), TRUE); + ResourceGetDataAsyncData* data = static_cast<ResourceGetDataAsyncData*>(g_task_get_task_data(task)); + data->webData = wkData; + g_task_return_boolean(task, TRUE); } /** @@ -341,10 +368,14 @@ void webkit_web_resource_get_data(WebKitWebResource* resource, GCancellable* can GTask* task = g_task_new(resource, cancellable, callback, userData); g_task_set_task_data(task, createResourceGetDataAsyncData(), reinterpret_cast<GDestroyNotify>(destroyResourceGetDataAsyncData)); if (resource->priv->isMainResource) - resource->priv->frame->getMainResourceData(DataCallback::create(task, resourceDataCallback)); + resource->priv->frame->getMainResourceData([task](API::Data* data, CallbackBase::Error) { + resourceDataCallback(data, adoptGRef(task).get()); + }); else { String url = String::fromUTF8(resource->priv->uri.data()); - resource->priv->frame->getResourceData(API::URL::create(url).get(), DataCallback::create(task, resourceDataCallback)); + resource->priv->frame->getResourceData(API::URL::create(url).ptr(), [task](API::Data* data, CallbackBase::Error) { + resourceDataCallback(data, adoptGRef(task).get()); + }); } } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebResourcePrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebResourcePrivate.h index 82e2d8f5a..de9e36b5f 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebResourcePrivate.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebResourcePrivate.h @@ -29,6 +29,7 @@ void webkitWebResourceSetResponse(WebKitWebResource*, WebKitURIResponse*); void webkitWebResourceNotifyProgress(WebKitWebResource*, guint64 bytesReceived); void webkitWebResourceFinished(WebKitWebResource*); void webkitWebResourceFailed(WebKitWebResource*, GError*); +void webkitWebResourceFailedWithTLSErrors(WebKitWebResource*, GTlsCertificateFlags, GTlsCertificate*); WebKit::WebFrameProxy* webkitWebResourceGetFrame(WebKitWebResource*); diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp index 0abb35e12..0aa1b38a2 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp @@ -1,6 +1,7 @@ /* * Copyright (C) 2011 Igalia S.L. * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. + * Copyright (C) 2014 Collabora Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -22,6 +23,7 @@ #include "WebKitWebView.h" #include "APIData.h" +#include "APISerializedScriptValue.h" #include "ImageOptions.h" #include "WebCertificateInfo.h" #include "WebContextMenuItem.h" @@ -29,25 +31,28 @@ #include "WebKitAuthenticationDialog.h" #include "WebKitAuthenticationRequestPrivate.h" #include "WebKitBackForwardListPrivate.h" -#include "WebKitCertificateInfoPrivate.h" #include "WebKitContextMenuClient.h" #include "WebKitContextMenuItemPrivate.h" #include "WebKitContextMenuPrivate.h" #include "WebKitDownloadPrivate.h" +#include "WebKitEditorStatePrivate.h" #include "WebKitEnumTypes.h" #include "WebKitError.h" #include "WebKitFaviconDatabasePrivate.h" #include "WebKitFormClient.h" #include "WebKitFullscreenClient.h" #include "WebKitHitTestResultPrivate.h" +#include "WebKitInstallMissingMediaPluginsPermissionRequestPrivate.h" #include "WebKitJavascriptResultPrivate.h" #include "WebKitLoaderClient.h" #include "WebKitMarshal.h" +#include "WebKitNotificationPrivate.h" #include "WebKitPolicyClient.h" #include "WebKitPrintOperationPrivate.h" #include "WebKitPrivate.h" #include "WebKitResponsePolicyDecision.h" #include "WebKitScriptDialogPrivate.h" +#include "WebKitSettingsPrivate.h" #include "WebKitUIClient.h" #include "WebKitURIRequestPrivate.h" #include "WebKitURIResponsePrivate.h" @@ -55,20 +60,23 @@ #include "WebKitWebInspectorPrivate.h" #include "WebKitWebResourcePrivate.h" #include "WebKitWebViewBasePrivate.h" -#include "WebKitWebViewGroupPrivate.h" #include "WebKitWebViewPrivate.h" +#include "WebKitWebViewSessionStatePrivate.h" #include "WebKitWindowPropertiesPrivate.h" #include <JavaScriptCore/APICast.h> #include <WebCore/CertificateInfo.h> -#include <WebCore/DragIcon.h> #include <WebCore/GUniquePtrGtk.h> #include <WebCore/GUniquePtrSoup.h> #include <WebCore/GtkUtilities.h> #include <WebCore/RefPtrCairo.h> #include <glib/gi18n-lib.h> -#include <wtf/gobject/GRefPtr.h> +#include <wtf/glib/GRefPtr.h> #include <wtf/text/CString.h> +#if USE(LIBNOTIFY) +#include <libnotify/notify.h> +#endif + using namespace WebKit; using namespace WebCore; @@ -124,6 +132,10 @@ enum { AUTHENTICATE, + SHOW_NOTIFICATION, + + RUN_COLOR_CHOOSER, + LAST_SIGNAL }; @@ -132,19 +144,23 @@ enum { PROP_WEB_CONTEXT, PROP_RELATED_VIEW, - PROP_GROUP, + PROP_SETTINGS, + PROP_USER_CONTENT_MANAGER, PROP_TITLE, PROP_ESTIMATED_LOAD_PROGRESS, PROP_FAVICON, PROP_URI, PROP_ZOOM_LEVEL, PROP_IS_LOADING, - PROP_VIEW_MODE + PROP_IS_PLAYING_AUDIO, + PROP_EDITABLE }; typedef HashMap<uint64_t, GRefPtr<WebKitWebResource> > LoadingResourcesMap; typedef HashMap<uint64_t, GRefPtr<GTask> > SnapshotResultsMap; +class PageLoadStateObserver; + struct _WebKitWebViewPrivate { ~_WebKitWebViewPrivate() { @@ -156,24 +172,20 @@ struct _WebKitWebViewPrivate { g_main_loop_quit(modalLoop.get()); } - WebKitWebContext* context; WebKitWebView* relatedView; CString title; CString customTextEncoding; - double estimatedLoadProgress; CString activeURI; bool isLoading; - WebKitViewMode viewMode; - bool waitingForMainResource; - unsigned long mainResourceResponseHandlerID; - WebKitLoadEvent lastDelayedEvent; + std::unique_ptr<PageLoadStateObserver> loadObserver; GRefPtr<WebKitBackForwardList> backForwardList; GRefPtr<WebKitSettings> settings; - unsigned long settingsChangedHandlerID; - GRefPtr<WebKitWebViewGroup> group; + GRefPtr<WebKitUserContentManager> userContentManager; + GRefPtr<WebKitWebContext> context; GRefPtr<WebKitWindowProperties> windowProperties; + GRefPtr<WebKitEditorState> editorState; GRefPtr<GMainLoop> modalLoop; @@ -195,6 +207,7 @@ struct _WebKitWebViewPrivate { SnapshotResultsMap snapshotResultsMap; GRefPtr<WebKitAuthenticationRequest> authenticationRequest; + }; static guint signals[LAST_SIGNAL] = { 0, }; @@ -206,6 +219,87 @@ static inline WebPageProxy* getPage(WebKitWebView* webView) return webkitWebViewBaseGetPage(reinterpret_cast<WebKitWebViewBase*>(webView)); } +static void webkitWebViewSetIsLoading(WebKitWebView* webView, bool isLoading) +{ + if (webView->priv->isLoading == isLoading) + return; + + webView->priv->isLoading = isLoading; + g_object_notify(G_OBJECT(webView), "is-loading"); +} + +void webkitWebViewIsPlayingAudioChanged(WebKitWebView* webView) +{ + g_object_notify(G_OBJECT(webView), "is-playing-audio"); +} + +class PageLoadStateObserver final : public PageLoadState::Observer { +public: + PageLoadStateObserver(WebKitWebView* webView) + : m_webView(webView) + { + } + +private: + virtual void willChangeIsLoading() override + { + g_object_freeze_notify(G_OBJECT(m_webView)); + } + virtual void didChangeIsLoading() override + { + webkitWebViewSetIsLoading(m_webView, getPage(m_webView)->pageLoadState().isLoading()); + g_object_thaw_notify(G_OBJECT(m_webView)); + } + + virtual void willChangeTitle() override + { + g_object_freeze_notify(G_OBJECT(m_webView)); + } + virtual void didChangeTitle() override + { + m_webView->priv->title = getPage(m_webView)->pageLoadState().title().utf8(); + g_object_notify(G_OBJECT(m_webView), "title"); + g_object_thaw_notify(G_OBJECT(m_webView)); + } + + virtual void willChangeActiveURL() override + { + g_object_freeze_notify(G_OBJECT(m_webView)); + } + virtual void didChangeActiveURL() override + { + m_webView->priv->activeURI = getPage(m_webView)->pageLoadState().activeURL().utf8(); + g_object_notify(G_OBJECT(m_webView), "uri"); + g_object_thaw_notify(G_OBJECT(m_webView)); + } + + virtual void willChangeHasOnlySecureContent() override { } + virtual void didChangeHasOnlySecureContent() override { } + + virtual void willChangeEstimatedProgress() override + { + g_object_freeze_notify(G_OBJECT(m_webView)); + } + virtual void didChangeEstimatedProgress() override + { + g_object_notify(G_OBJECT(m_webView), "estimated-load-progress"); + g_object_thaw_notify(G_OBJECT(m_webView)); + } + + virtual void willChangeCanGoBack() override { } + virtual void didChangeCanGoBack() override { } + virtual void willChangeCanGoForward() override { } + virtual void didChangeCanGoForward() override { } + virtual void willChangeNetworkRequestsInProgress() override { } + virtual void didChangeNetworkRequestsInProgress() override { } + virtual void willChangeCertificateInfo() override { } + virtual void didChangeCertificateInfo() override { } + virtual void willChangeWebProcessIsResponsive() override { } + virtual void didChangeWebProcessIsResponsive() override { } + + WebKitWebView* m_webView; +}; + static gboolean webkitWebViewLoadFail(WebKitWebView* webView, WebKitLoadEvent, const char* failingURI, GError* error) { if (g_error_matches(error, WEBKIT_NETWORK_ERROR, WEBKIT_NETWORK_ERROR_CANCELLED) @@ -219,19 +313,22 @@ static gboolean webkitWebViewLoadFail(WebKitWebView* webView, WebKitLoadEvent, c return TRUE; } -static GtkWidget* webkitWebViewCreate(WebKitWebView*) +static GtkWidget* webkitWebViewCreate(WebKitWebView*, WebKitNavigationAction*) { - return 0; + return nullptr; } -static GtkWidget* webkitWebViewCreateJavaScriptDialog(WebKitWebView* webView, GtkMessageType type, GtkButtonsType buttons, int defaultResponse, const char* message) +static GtkWidget* webkitWebViewCreateJavaScriptDialog(WebKitWebView* webView, GtkMessageType type, GtkButtonsType buttons, int defaultResponse, const char* primaryText, const char* secondaryText = nullptr) { GtkWidget* parent = gtk_widget_get_toplevel(GTK_WIDGET(webView)); - GtkWidget* dialog = gtk_message_dialog_new(widgetIsOnscreenToplevelWindow(parent) ? GTK_WINDOW(parent) : 0, - GTK_DIALOG_DESTROY_WITH_PARENT, type, buttons, "%s", message); + GtkWidget* dialog = gtk_message_dialog_new(widgetIsOnscreenToplevelWindow(parent) ? GTK_WINDOW(parent) : nullptr, + GTK_DIALOG_DESTROY_WITH_PARENT, type, buttons, "%s", primaryText); + if (secondaryText) + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), "%s", secondaryText); GUniquePtr<char> title(g_strdup_printf("JavaScript - %s", webkit_web_view_get_uri(webView))); gtk_window_set_title(GTK_WINDOW(dialog), title.get()); - gtk_dialog_set_default_response(GTK_DIALOG(dialog), defaultResponse); + if (buttons != GTK_BUTTONS_NONE) + gtk_dialog_set_default_response(GTK_DIALOG(dialog), defaultResponse); return dialog; } @@ -249,7 +346,7 @@ static gboolean webkitWebViewScriptDialog(WebKitWebView* webView, WebKitScriptDi dialog = webkitWebViewCreateJavaScriptDialog(webView, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, GTK_RESPONSE_OK, scriptDialog->message.data()); scriptDialog->confirmed = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK; break; - case WEBKIT_SCRIPT_DIALOG_PROMPT: + case WEBKIT_SCRIPT_DIALOG_PROMPT: { dialog = webkitWebViewCreateJavaScriptDialog(webView, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, GTK_RESPONSE_OK, scriptDialog->message.data()); GtkWidget* entry = gtk_entry_new(); gtk_entry_set_text(GTK_ENTRY(entry), scriptDialog->defaultText.data()); @@ -260,13 +357,21 @@ static gboolean webkitWebViewScriptDialog(WebKitWebView* webView, WebKitScriptDi scriptDialog->text = gtk_entry_get_text(GTK_ENTRY(entry)); break; } + case WEBKIT_SCRIPT_DIALOG_BEFORE_UNLOAD_CONFIRM: + dialog = webkitWebViewCreateJavaScriptDialog(webView, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, GTK_RESPONSE_OK, + _("Are you sure you want to leave this page?"), scriptDialog->message.data()); + gtk_dialog_add_buttons(GTK_DIALOG(dialog), _("Stay on Page"), GTK_RESPONSE_CLOSE, _("Leave Page"), GTK_RESPONSE_OK, nullptr); + gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); + scriptDialog->confirmed = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK; + break; + } gtk_widget_destroy(dialog); return TRUE; } -static gboolean webkitWebViewDecidePolicy(WebKitWebView* webView, WebKitPolicyDecision* decision, WebKitPolicyDecisionType decisionType) +static gboolean webkitWebViewDecidePolicy(WebKitWebView*, WebKitPolicyDecision* decision, WebKitPolicyDecisionType decisionType) { if (decisionType != WEBKIT_POLICY_DECISION_TYPE_RESPONSE) { webkit_policy_decision_use(decision); @@ -353,7 +458,7 @@ static void webkitWebViewRequestFavicon(WebKitWebView* webView) WebKitWebViewPrivate* priv = webView->priv; priv->faviconCancellable = adoptGRef(g_cancellable_new()); - WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(priv->context); + WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(priv->context.get()); webkit_favicon_database_get_favicon(database, priv->activeURI.data(), priv->faviconCancellable.get(), gotFaviconCallback, webView); } @@ -366,7 +471,7 @@ static void webkitWebViewUpdateFaviconURI(WebKitWebView* webView, const char* fa webkitWebViewRequestFavicon(webView); } -static void faviconChangedCallback(WebKitFaviconDatabase* database, const char* pageURI, const char* faviconURI, WebKitWebView* webView) +static void faviconChangedCallback(WebKitFaviconDatabase*, const char* pageURI, const char* faviconURI, WebKitWebView* webView) { if (webView->priv->activeURI != pageURI) return; @@ -376,16 +481,18 @@ static void faviconChangedCallback(WebKitFaviconDatabase* database, const char* static void webkitWebViewUpdateSettings(WebKitWebView* webView) { - // We keep a ref of the current settings to disconnect the signals when settings change in the group. - webView->priv->settings = webkit_web_view_get_settings(webView); + // The "settings" property is set on construction, and in that + // case webkit_web_view_set_settings() will be called *before* the + // WebPageProxy has been created so we should do an early return. + WebPageProxy* page = getPage(webView); + if (!page) + return; WebKitSettings* settings = webView->priv->settings.get(); - WebPageProxy* page = getPage(webView); + page->setPreferences(*webkitSettingsGetPreferences(settings)); page->setCanRunModal(webkit_settings_get_allow_modal_dialogs(settings)); page->setCustomUserAgent(String::fromUTF8(webkit_settings_get_user_agent(settings))); - webkitWebViewBaseUpdatePreferences(WEBKIT_WEB_VIEW_BASE(webView)); - g_signal_connect(settings, "notify::allow-modal-dialogs", G_CALLBACK(allowModalDialogsChanged), webView); g_signal_connect(settings, "notify::zoom-text-only", G_CALLBACK(zoomTextOnlyChanged), webView); g_signal_connect(settings, "notify::user-agent", G_CALLBACK(userAgentChanged), webView); @@ -399,35 +506,13 @@ static void webkitWebViewDisconnectSettingsSignalHandlers(WebKitWebView* webView g_signal_handlers_disconnect_by_func(settings, reinterpret_cast<gpointer>(userAgentChanged), webView); } -static void webkitWebViewSettingsChanged(WebKitWebViewGroup* group, GParamSpec*, WebKitWebView* webView) -{ - webkitWebViewDisconnectSettingsSignalHandlers(webView); - webkitWebViewUpdateSettings(webView); -} - -static void webkitWebViewDisconnectSettingsChangedSignalHandler(WebKitWebView* webView) -{ - WebKitWebViewPrivate* priv = webView->priv; - if (priv->settingsChangedHandlerID) - g_signal_handler_disconnect(webkit_web_view_get_group(webView), priv->settingsChangedHandlerID); - priv->settingsChangedHandlerID = 0; -} - -static void webkitWebViewDisconnectMainResourceResponseChangedSignalHandler(WebKitWebView* webView) -{ - WebKitWebViewPrivate* priv = webView->priv; - if (priv->mainResourceResponseHandlerID) - g_signal_handler_disconnect(priv->mainResource.get(), priv->mainResourceResponseHandlerID); - priv->mainResourceResponseHandlerID = 0; -} - static void webkitWebViewWatchForChangesInFavicon(WebKitWebView* webView) { WebKitWebViewPrivate* priv = webView->priv; if (priv->faviconChangedHandlerID) return; - WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(priv->context); + WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(priv->context.get()); priv->faviconChangedHandlerID = g_signal_connect(database, "favicon-changed", G_CALLBACK(faviconChangedCallback), webView); } @@ -435,7 +520,7 @@ static void webkitWebViewDisconnectFaviconDatabaseSignalHandlers(WebKitWebView* { WebKitWebViewPrivate* priv = webView->priv; if (priv->faviconChangedHandlerID) - g_signal_handler_disconnect(webkit_web_context_get_favicon_database(priv->context), priv->faviconChangedHandlerID); + g_signal_handler_disconnect(webkit_web_context_get_favicon_database(priv->context.get()), priv->faviconChangedHandlerID); priv->faviconChangedHandlerID = 0; } @@ -496,14 +581,78 @@ static void webkitWebViewHandleDownloadRequest(WebKitWebViewBase* webViewBase, D webkitDownloadSetWebView(download.get(), WEBKIT_WEB_VIEW(webViewBase)); } +#if USE(LIBNOTIFY) +static const char* gNotifyNotificationID = "wk-notify-notification"; + +static void notifyNotificationClosed(NotifyNotification*, WebKitNotification* webNotification) +{ + g_object_set_data(G_OBJECT(webNotification), gNotifyNotificationID, nullptr); + webkit_notification_close(webNotification); +} + +static void notifyNotificationClicked(NotifyNotification*, char*, WebKitNotification* webNotification) +{ + webkit_notification_clicked(webNotification); +} + +static void webNotificationClosed(WebKitNotification* webNotification) +{ + NotifyNotification* notification = NOTIFY_NOTIFICATION(g_object_get_data(G_OBJECT(webNotification), gNotifyNotificationID)); + if (!notification) + return; + + notify_notification_close(notification, nullptr); + g_object_set_data(G_OBJECT(webNotification), gNotifyNotificationID, nullptr); +} +#endif // USE(LIBNOTIFY) + +static gboolean webkitWebViewShowNotification(WebKitWebView*, WebKitNotification* webNotification) +{ +#if USE(LIBNOTIFY) + if (!notify_is_initted()) + notify_init(g_get_prgname()); + + NotifyNotification* notification = NOTIFY_NOTIFICATION(g_object_get_data(G_OBJECT(webNotification), gNotifyNotificationID)); + if (!notification) { + notification = notify_notification_new(webkit_notification_get_title(webNotification), + webkit_notification_get_body(webNotification), nullptr); + + notify_notification_add_action(notification, "default", _("Acknowledge"), NOTIFY_ACTION_CALLBACK(notifyNotificationClicked), webNotification, nullptr); + + g_signal_connect_object(notification, "closed", G_CALLBACK(notifyNotificationClosed), webNotification, static_cast<GConnectFlags>(0)); + g_signal_connect(webNotification, "closed", G_CALLBACK(webNotificationClosed), nullptr); + g_object_set_data_full(G_OBJECT(webNotification), gNotifyNotificationID, notification, static_cast<GDestroyNotify>(g_object_unref)); + } else { + notify_notification_update(notification, webkit_notification_get_title(webNotification), + webkit_notification_get_body(webNotification), nullptr); + } + + notify_notification_show(notification, nullptr); + return TRUE; +#else + UNUSED_PARAM(webNotification); + return FALSE; +#endif +} + static void webkitWebViewConstructed(GObject* object) { - if (G_OBJECT_CLASS(webkit_web_view_parent_class)->constructed) - G_OBJECT_CLASS(webkit_web_view_parent_class)->constructed(object); + G_OBJECT_CLASS(webkit_web_view_parent_class)->constructed(object); WebKitWebView* webView = WEBKIT_WEB_VIEW(object); WebKitWebViewPrivate* priv = webView->priv; - webkitWebContextCreatePageForWebView(priv->context, webView, priv->group.get(), priv->relatedView); + if (priv->relatedView) + priv->context = webkit_web_view_get_context(priv->relatedView); + else if (!priv->context) + priv->context = webkit_web_context_get_default(); + if (!priv->settings) + priv->settings = adoptGRef(webkit_settings_new()); + + webkitWebContextCreatePageForWebView(priv->context.get(), webView, priv->userContentManager.get(), priv->relatedView); + + priv->loadObserver = std::make_unique<PageLoadStateObserver>(webView); + getPage(webView)->pageLoadState().addObserver(*priv->loadObserver); + // The related view is only valid during the construction. priv->relatedView = nullptr; @@ -516,12 +665,12 @@ static void webkitWebViewConstructed(GObject* object) attachContextMenuClientToView(webView); attachFormClientToView(webView); + // This needs to be after attachUIClientToView() because WebPageProxy::setUIClient() calls setCanRunModal() with true. + // See https://bugs.webkit.org/show_bug.cgi?id=135412. + webkitWebViewUpdateSettings(webView); + priv->backForwardList = adoptGRef(webkitBackForwardListCreate(&getPage(webView)->backForwardList())); priv->windowProperties = adoptGRef(webkitWindowPropertiesCreate()); - - webkitWebViewUpdateSettings(webView); - priv->settingsChangedHandlerID = - g_signal_connect(webkit_web_view_get_group(webView), "notify::settings", G_CALLBACK(webkitWebViewSettingsChanged), webView); } static void webkitWebViewSetProperty(GObject* object, guint propId, const GValue* value, GParamSpec* paramSpec) @@ -531,7 +680,7 @@ static void webkitWebViewSetProperty(GObject* object, guint propId, const GValue switch (propId) { case PROP_WEB_CONTEXT: { gpointer webContext = g_value_get_object(value); - webView->priv->context = webContext ? WEBKIT_WEB_CONTEXT(webContext) : webkit_web_context_get_default(); + webView->priv->context = webContext ? WEBKIT_WEB_CONTEXT(webContext) : nullptr; break; } case PROP_RELATED_VIEW: { @@ -539,16 +688,21 @@ static void webkitWebViewSetProperty(GObject* object, guint propId, const GValue webView->priv->relatedView = relatedView ? WEBKIT_WEB_VIEW(relatedView) : nullptr; break; } - case PROP_GROUP: { - gpointer group = g_value_get_object(value); - webView->priv->group = group ? WEBKIT_WEB_VIEW_GROUP(group) : 0; + case PROP_SETTINGS: { + if (gpointer settings = g_value_get_object(value)) + webkit_web_view_set_settings(webView, WEBKIT_SETTINGS(settings)); + break; + } + case PROP_USER_CONTENT_MANAGER: { + gpointer userContentManager = g_value_get_object(value); + webView->priv->userContentManager = userContentManager ? WEBKIT_USER_CONTENT_MANAGER(userContentManager) : nullptr; break; } case PROP_ZOOM_LEVEL: webkit_web_view_set_zoom_level(webView, g_value_get_double(value)); break; - case PROP_VIEW_MODE: - webkit_web_view_set_view_mode(webView, static_cast<WebKitViewMode>(g_value_get_enum(value))); + case PROP_EDITABLE: + webkit_web_view_set_editable(webView, g_value_get_boolean(value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); @@ -561,10 +715,13 @@ static void webkitWebViewGetProperty(GObject* object, guint propId, GValue* valu switch (propId) { case PROP_WEB_CONTEXT: - g_value_set_object(value, webView->priv->context); + g_value_set_object(value, webView->priv->context.get()); break; - case PROP_GROUP: - g_value_set_object(value, webkit_web_view_get_group(webView)); + case PROP_SETTINGS: + g_value_set_object(value, webkit_web_view_get_settings(webView)); + break; + case PROP_USER_CONTENT_MANAGER: + g_value_set_object(value, webkit_web_view_get_user_content_manager(webView)); break; case PROP_TITLE: g_value_set_string(value, webView->priv->title.data()); @@ -584,8 +741,11 @@ static void webkitWebViewGetProperty(GObject* object, guint propId, GValue* valu case PROP_IS_LOADING: g_value_set_boolean(value, webkit_web_view_is_loading(webView)); break; - case PROP_VIEW_MODE: - g_value_set_enum(value, webkit_web_view_get_view_mode(webView)); + case PROP_IS_PLAYING_AUDIO: + g_value_set_boolean(value, webkit_web_view_is_playing_audio(webView)); + break; + case PROP_EDITABLE: + g_value_set_boolean(value, webkit_web_view_is_editable(webView)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); @@ -596,12 +756,15 @@ static void webkitWebViewDispose(GObject* object) { WebKitWebView* webView = WEBKIT_WEB_VIEW(object); webkitWebViewCancelFaviconRequest(webView); - webkitWebViewDisconnectMainResourceResponseChangedSignalHandler(webView); - webkitWebViewDisconnectSettingsChangedSignalHandler(webView); webkitWebViewDisconnectSettingsSignalHandlers(webView); webkitWebViewDisconnectFaviconDatabaseSignalHandlers(webView); - webkitWebContextWebViewDestroyed(webView->priv->context, webView); + if (webView->priv->loadObserver) { + getPage(webView)->pageLoadState().removeObserver(*webView->priv->loadObserver); + webView->priv->loadObserver.reset(); + } + + webkitWebContextWebViewDestroyed(webView->priv->context.get(), webView); G_OBJECT_CLASS(webkit_web_view_parent_class)->dispose(object); } @@ -631,6 +794,7 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) webViewClass->permission_request = webkitWebViewPermissionRequest; webViewClass->run_file_chooser = webkitWebViewRunFileChooser; webViewClass->authenticate = webkitWebViewAuthenticate; + webViewClass->show_notification = webkitWebViewShowNotification; /** * WebKitWebView:web-context: @@ -664,18 +828,37 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) static_cast<GParamFlags>(WEBKIT_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY))); /** - * WebKitWebView:group: + * WebKitWebView:settings: + * + * The #WebKitSettings of the view. + * + * Since: 2.6 + */ + g_object_class_install_property( + gObjectClass, + PROP_SETTINGS, + g_param_spec_object( + "settings", + _("WebView settings"), + _("The WebKitSettings of the view"), + WEBKIT_TYPE_SETTINGS, + static_cast<GParamFlags>(WEBKIT_PARAM_WRITABLE | G_PARAM_CONSTRUCT))); + + /** + * WebKitWebView:user-content-manager: * - * The #WebKitWebViewGroup of the view. + * The #WebKitUserContentManager of the view. + * + * Since: 2.6 */ g_object_class_install_property( gObjectClass, - PROP_GROUP, + PROP_USER_CONTENT_MANAGER, g_param_spec_object( - "group", - _("WebView Group"), - _("The WebKitWebViewGroup of the view"), - WEBKIT_TYPE_WEB_VIEW_GROUP, + "user-content-manager", + _("WebView user content manager"), + _("The WebKitUserContentManager of the view"), + WEBKIT_TYPE_USER_CONTENT_MANAGER, static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); /** @@ -742,13 +925,15 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) * The zoom level of the #WebKitWebView content. * See webkit_web_view_set_zoom_level() for more details. */ - g_object_class_install_property(gObjectClass, - PROP_ZOOM_LEVEL, - g_param_spec_double("zoom-level", - "Zoom level", - _("The zoom level of the view content"), - 0, G_MAXDOUBLE, 1, - WEBKIT_PARAM_READWRITE)); + g_object_class_install_property( + gObjectClass, + PROP_ZOOM_LEVEL, + g_param_spec_double( + "zoom-level", + _("Zoom level"), + _("The zoom level of the view content"), + 0, G_MAXDOUBLE, 1, + WEBKIT_PARAM_READWRITE)); /** * WebKitWebView:is-loading: @@ -760,28 +945,53 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) * When the load operation finishes the property is set to %FALSE before * #WebKitWebView::load-changed is emitted with %WEBKIT_LOAD_FINISHED. */ - g_object_class_install_property(gObjectClass, - PROP_IS_LOADING, - g_param_spec_boolean("is-loading", - "Is Loading", - _("Whether the view is loading a page"), - FALSE, - WEBKIT_PARAM_READABLE)); + g_object_class_install_property( + gObjectClass, + PROP_IS_LOADING, + g_param_spec_boolean( + "is-loading", + _("Is Loading"), + _("Whether the view is loading a page"), + FALSE, + WEBKIT_PARAM_READABLE)); /** - * WebKitWebView:view-mode: + * WebKitWebView:is-playing-audio: + * + * Whether the #WebKitWebView is currently playing audio from a page. + * This property becomes %TRUE as soon as web content starts playing any + * kind of audio. When a page is no longer playing any kind of sound, + * the property is set back to %FALSE. * - * The #WebKitViewMode that is used to display the contents of a #WebKitWebView. - * See also webkit_web_view_set_view_mode(). + * Since: 2.8 */ - g_object_class_install_property(gObjectClass, - PROP_VIEW_MODE, - g_param_spec_enum("view-mode", - "View Mode", - _("The view mode to display the web view contents"), - WEBKIT_TYPE_VIEW_MODE, - WEBKIT_VIEW_MODE_WEB, - WEBKIT_PARAM_READWRITE)); + g_object_class_install_property( + gObjectClass, + PROP_IS_PLAYING_AUDIO, + g_param_spec_boolean( + "is-playing-audio", + "Is Playing Audio", + _("Whether the view is playing audio"), + FALSE, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitWebView:editable: + * + * Whether the pages loaded inside #WebKitWebView are editable. For more + * information see webkit_web_view_set_editable(). + * + * Since: 2.8 + */ + g_object_class_install_property( + gObjectClass, + PROP_EDITABLE, + g_param_spec_boolean( + "editable", + _("Editable"), + _("Whether the content can be modified by the user."), + FALSE, + WEBKIT_PARAM_READWRITE)); /** * WebKitWebView::load-changed: @@ -865,30 +1075,31 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) * %FALSE to propagate the event further. */ signals[LOAD_FAILED] = - g_signal_new("load-failed", - G_TYPE_FROM_CLASS(webViewClass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(WebKitWebViewClass, load_failed), - g_signal_accumulator_true_handled, 0, - webkit_marshal_BOOLEAN__ENUM_STRING_POINTER, - G_TYPE_BOOLEAN, 3, - WEBKIT_TYPE_LOAD_EVENT, - G_TYPE_STRING, - G_TYPE_POINTER); + g_signal_new( + "load-failed", + G_TYPE_FROM_CLASS(webViewClass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(WebKitWebViewClass, load_failed), + g_signal_accumulator_true_handled, 0, + g_cclosure_marshal_generic, + G_TYPE_BOOLEAN, 3, + WEBKIT_TYPE_LOAD_EVENT, + G_TYPE_STRING, + G_TYPE_ERROR | G_SIGNAL_TYPE_STATIC_SCOPE); /** * WebKitWebView::load-failed-with-tls-errors: * @web_view: the #WebKitWebView on which the signal is emitted - * @info: a #WebKitCertificateInfo - * @host: the host on which the error occurred + * @failing_uri: the URI that failed to load + * @certificate: a #GTlsCertificate + * @errors: a #GTlsCertificateFlags with the verification status of @certificate * - * Emitted when a TLS error occurs during a load operation. The @info - * object contains information about the error such as the #GTlsCertificate - * and the #GTlsCertificateFlags. To allow an exception for this certificate - * and this host use webkit_web_context_allow_tls_certificate_for_host(). + * Emitted when a TLS error occurs during a load operation. + * To allow an exception for this @certificate + * and the host of @failing_uri use webkit_web_context_allow_tls_certificate_for_host(). * - * To handle this signal asynchronously you should copy the #WebKitCertificateInfo - * with webkit_certificate_info_copy() and return %TRUE. + * To handle this signal asynchronously you should call g_object_ref() on @certificate + * and return %TRUE. * * If %FALSE is returned, #WebKitWebView::load-failed will be emitted. The load * will finish regardless of the returned value. @@ -896,7 +1107,7 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) * Returns: %TRUE to stop other handlers from being invoked for the event. * %FALSE to propagate the event further. * - * Since: 2.4 + * Since: 2.6 */ signals[LOAD_FAILED_WITH_TLS_ERRORS] = g_signal_new("load-failed-with-tls-errors", @@ -904,22 +1115,27 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET(WebKitWebViewClass, load_failed_with_tls_errors), g_signal_accumulator_true_handled, 0 /* accumulator data */, - webkit_marshal_BOOLEAN__BOXED_STRING, - G_TYPE_BOOLEAN, 2, /* number of parameters */ - WEBKIT_TYPE_CERTIFICATE_INFO | G_SIGNAL_TYPE_STATIC_SCOPE, - G_TYPE_STRING); + g_cclosure_marshal_generic, + G_TYPE_BOOLEAN, 3, + G_TYPE_STRING, + G_TYPE_TLS_CERTIFICATE, + G_TYPE_TLS_CERTIFICATE_FLAGS); /** * WebKitWebView::create: * @web_view: the #WebKitWebView on which the signal is emitted + * @navigation_action: a #WebKitNavigationAction * * Emitted when the creation of a new #WebKitWebView is requested. * If this signal is handled the signal handler should return the * newly created #WebKitWebView. * + * The #WebKitNavigationAction parameter contains information about the + * navigation action that triggered this signal. + * * When using %WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES * process model, the new #WebKitWebView should be related to - * @web_view to share the same web process, see webkit_web_view_new_with_related_view + * @web_view to share the same web process, see webkit_web_view_new_with_related_view() * for more details. * * The new #WebKitWebView should not be displayed to the user @@ -928,14 +1144,15 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) * Returns: (transfer full): a newly allocated #WebKitWebView widget * or %NULL to propagate the event further. */ - signals[CREATE] = - g_signal_new("create", - G_TYPE_FROM_CLASS(webViewClass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(WebKitWebViewClass, create), - webkitWebViewAccumulatorObjectHandled, 0, - webkit_marshal_OBJECT__VOID, - GTK_TYPE_WIDGET, 0); + signals[CREATE] = g_signal_new( + "create", + G_TYPE_FROM_CLASS(webViewClass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(WebKitWebViewClass, create), + webkitWebViewAccumulatorObjectHandled, 0, + g_cclosure_marshal_generic, + GTK_TYPE_WIDGET, 1, + WEBKIT_TYPE_NAVIGATION_ACTION | G_SIGNAL_TYPE_STATIC_SCOPE); /** * WebKitWebView::ready-to-show: @@ -980,10 +1197,11 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) /** * WebKitWebView::close: - * @webView: the #WebKitWebView on which the signal is emitted + * @web_view: the #WebKitWebView on which the signal is emitted * * Emitted when closing a #WebKitWebView is requested. This occurs when a - * call is made from JavaScript's <function>window.close</function> function. + * call is made from JavaScript's <function>window.close</function> function or + * after trying to close the @web_view with webkit_web_view_try_close(). * It is the owner's responsibility to handle this signal to hide or * destroy the #WebKitWebView, if necessary. */ @@ -1002,7 +1220,8 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) * @dialog: the #WebKitScriptDialog to show * * Emitted when JavaScript code calls <function>window.alert</function>, - * <function>window.confirm</function> or <function>window.prompt</function>. + * <function>window.confirm</function> or <function>window.prompt</function>, + * or when <function>onbeforeunload</function> event is fired. * The @dialog parameter should be used to build the dialog. * If the signal is not handled a different dialog will be built and shown depending * on the dialog type: @@ -1017,6 +1236,9 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) * %WEBKIT_SCRIPT_DIALOG_PROMPT: message dialog with OK and Cancel buttons and * a text entry with the default text. * </para></listitem> + * <listitem><para> + * %WEBKIT_SCRIPT_DIALOG_BEFORE_UNLOAD_CONFIRM: message dialog with Stay and Leave buttons. + * </para></listitem> * </itemizedlist> * * Returns: %TRUE to stop other handlers from being invoked for the event. @@ -1140,9 +1362,10 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) * request has not been handled, webkit_permission_request_deny() * will be the default action. * - * By default, if the signal is not handled, - * webkit_permission_request_deny() will be called over the - * #WebKitPermissionRequest. + * If the signal is not handled, the @request will be completed automatically + * by the specific #WebKitPermissionRequest that could allow or deny it. Check the + * documentation of classes implementing #WebKitPermissionRequest interface to know + * their default action. * * Returns: %TRUE to stop other handlers from being invoked for the event. * %FALSE to propagate the event further. @@ -1482,21 +1705,66 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) webkit_marshal_BOOLEAN__OBJECT, G_TYPE_BOOLEAN, 1, /* number of parameters */ WEBKIT_TYPE_AUTHENTICATION_REQUEST); -} -static void webkitWebViewSetIsLoading(WebKitWebView* webView, bool isLoading) -{ - if (webView->priv->isLoading == isLoading) - return; - - webView->priv->isLoading = isLoading; - g_object_freeze_notify(G_OBJECT(webView)); - g_object_notify(G_OBJECT(webView), "is-loading"); + /** + * WebKitWebView::show-notification: + * @web_view: the #WebKitWebView + * @notification: a #WebKitNotification + * + * This signal is emitted when a notification should be presented to the + * user. The @notification is kept alive until either: 1) the web page cancels it + * or 2) a navigation happens. + * + * The default handler will emit a notification using libnotify, if built with + * support for it. + * + * Returns: %TRUE to stop other handlers from being invoked. %FALSE otherwise. + * + * Since: 2.8 + */ + signals[SHOW_NOTIFICATION] = + g_signal_new("show-notification", + G_TYPE_FROM_CLASS(gObjectClass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(WebKitWebViewClass, show_notification), + g_signal_accumulator_true_handled, nullptr /* accumulator data */, + webkit_marshal_BOOLEAN__OBJECT, + G_TYPE_BOOLEAN, 1, + WEBKIT_TYPE_NOTIFICATION); - // Update the URI if a new load has started. - if (webView->priv->isLoading) - webkitWebViewUpdateURI(webView); - g_object_thaw_notify(G_OBJECT(webView)); + /** + * WebKitWebView::run-color-chooser: + * @web_view: the #WebKitWebView on which the signal is emitted + * @request: a #WebKitColorChooserRequest + * + * This signal is emitted when the user interacts with a <input + * type='color' /> HTML element, requesting from WebKit to show + * a dialog to select a color. To let the application know the details of + * the color chooser, as well as to allow the client application to either + * cancel the request or perform an actual color selection, the signal will + * pass an instance of the #WebKitColorChooserRequest in the @request + * argument. + * + * It is possible to handle this request asynchronously by increasing the + * reference count of the request. + * + * The default signal handler will asynchronously run a regular + * #GtkColorChooser for the user to interact with. + * + * Returns: %TRUE to stop other handlers from being invoked for the event. + * %FALSE to propagate the event further. + * + * Since: 2.8 + */ + signals[RUN_COLOR_CHOOSER] = + g_signal_new("run-color-chooser", + G_TYPE_FROM_CLASS(webViewClass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(WebKitWebViewClass, run_color_chooser), + g_signal_accumulator_true_handled, nullptr, + webkit_marshal_BOOLEAN__OBJECT, + G_TYPE_BOOLEAN, 1, + WEBKIT_TYPE_COLOR_CHOOSER_REQUEST); } static void webkitWebViewCancelAuthenticationRequest(WebKitWebView* webView) @@ -1508,68 +1776,35 @@ static void webkitWebViewCancelAuthenticationRequest(WebKitWebView* webView) webView->priv->authenticationRequest.clear(); } -static void webkitWebViewEmitLoadChanged(WebKitWebView* webView, WebKitLoadEvent loadEvent) -{ - if (loadEvent == WEBKIT_LOAD_STARTED) { - webkitWebViewSetIsLoading(webView, true); - webkitWebViewWatchForChangesInFavicon(webView); - webkitWebViewCancelAuthenticationRequest(webView); - } else if (loadEvent == WEBKIT_LOAD_FINISHED) { - webkitWebViewSetIsLoading(webView, false); - webkitWebViewCancelAuthenticationRequest(webView); - webkitWebViewDisconnectMainResourceResponseChangedSignalHandler(webView); - } else - webkitWebViewUpdateURI(webView); - g_signal_emit(webView, signals[LOAD_CHANGED], 0, loadEvent); -} - -static void webkitWebViewEmitDelayedLoadEvents(WebKitWebView* webView) -{ - WebKitWebViewPrivate* priv = webView->priv; - if (!priv->waitingForMainResource) - return; - ASSERT(priv->lastDelayedEvent == WEBKIT_LOAD_COMMITTED || priv->lastDelayedEvent == WEBKIT_LOAD_FINISHED); - - if (priv->lastDelayedEvent == WEBKIT_LOAD_FINISHED) - webkitWebViewEmitLoadChanged(webView, WEBKIT_LOAD_COMMITTED); - webkitWebViewEmitLoadChanged(webView, priv->lastDelayedEvent); - priv->waitingForMainResource = false; -} - void webkitWebViewLoadChanged(WebKitWebView* webView, WebKitLoadEvent loadEvent) { WebKitWebViewPrivate* priv = webView->priv; - if (loadEvent == WEBKIT_LOAD_STARTED) { - // Finish a possible previous load waiting for main resource. - webkitWebViewEmitDelayedLoadEvents(webView); - + switch (loadEvent) { + case WEBKIT_LOAD_STARTED: webkitWebViewCancelFaviconRequest(webView); + webkitWebViewWatchForChangesInFavicon(webView); + webkitWebViewCancelAuthenticationRequest(webView); priv->loadingResourcesMap.clear(); - priv->mainResource = 0; - priv->waitingForMainResource = false; - } else if (loadEvent == WEBKIT_LOAD_COMMITTED) { - WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(priv->context); + priv->mainResource = nullptr; + break; + case WEBKIT_LOAD_COMMITTED: { + WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(priv->context.get()); GUniquePtr<char> faviconURI(webkit_favicon_database_get_favicon_uri(database, priv->activeURI.data())); webkitWebViewUpdateFaviconURI(webView, faviconURI.get()); - - if (!priv->mainResource) { - // When a page is loaded from the history cache, the main resource load callbacks - // are called when the main frame load is finished. We want to make sure there's a - // main resource available when load has been committed, so we delay the emission of - // load-changed signal until main resource object has been created. - priv->waitingForMainResource = true; - } + break; + } + case WEBKIT_LOAD_FINISHED: + webkitWebViewCancelAuthenticationRequest(webView); + break; + default: + break; } - if (priv->waitingForMainResource) - priv->lastDelayedEvent = loadEvent; - else - webkitWebViewEmitLoadChanged(webView, loadEvent); + g_signal_emit(webView, signals[LOAD_CHANGED], 0, loadEvent); } void webkitWebViewLoadFailed(WebKitWebView* webView, WebKitLoadEvent loadEvent, const char* failingURI, GError *error) { - webkitWebViewSetIsLoading(webView, false); webkitWebViewCancelAuthenticationRequest(webView); gboolean returnValue; @@ -1579,15 +1814,12 @@ void webkitWebViewLoadFailed(WebKitWebView* webView, WebKitLoadEvent loadEvent, void webkitWebViewLoadFailedWithTLSErrors(WebKitWebView* webView, const char* failingURI, GError* error, GTlsCertificateFlags tlsErrors, GTlsCertificate* certificate) { - webkitWebViewSetIsLoading(webView, false); webkitWebViewCancelAuthenticationRequest(webView); - WebKitTLSErrorsPolicy tlsErrorsPolicy = webkit_web_context_get_tls_errors_policy(webView->priv->context); + WebKitTLSErrorsPolicy tlsErrorsPolicy = webkit_web_context_get_tls_errors_policy(webView->priv->context.get()); if (tlsErrorsPolicy == WEBKIT_TLS_ERRORS_POLICY_FAIL) { - GUniquePtr<SoupURI> soupURI(soup_uri_new(failingURI)); - WebKitCertificateInfo info(certificate, tlsErrors); gboolean returnValue; - g_signal_emit(webView, signals[LOAD_FAILED_WITH_TLS_ERRORS], 0, &info, soupURI->host, &returnValue); + g_signal_emit(webView, signals[LOAD_FAILED_WITH_TLS_ERRORS], 0, failingURI, certificate, tlsErrors, &returnValue); if (!returnValue) g_signal_emit(webView, signals[LOAD_FAILED], 0, WEBKIT_LOAD_STARTED, failingURI, error, &returnValue); } @@ -1595,39 +1827,10 @@ void webkitWebViewLoadFailedWithTLSErrors(WebKitWebView* webView, const char* fa g_signal_emit(webView, signals[LOAD_CHANGED], 0, WEBKIT_LOAD_FINISHED); } -void webkitWebViewSetTitle(WebKitWebView* webView, const CString& title) -{ - WebKitWebViewPrivate* priv = webView->priv; - if (priv->title == title) - return; - - priv->title = title; - g_object_notify(G_OBJECT(webView), "title"); -} - -void webkitWebViewSetEstimatedLoadProgress(WebKitWebView* webView, double estimatedLoadProgress) -{ - if (webView->priv->estimatedLoadProgress == estimatedLoadProgress) - return; - - webView->priv->estimatedLoadProgress = estimatedLoadProgress; - g_object_notify(G_OBJECT(webView), "estimated-load-progress"); -} - -void webkitWebViewUpdateURI(WebKitWebView* webView) -{ - CString activeURI = getPage(webView)->pageLoadState().activeURL().utf8(); - if (webView->priv->activeURI == activeURI) - return; - - webView->priv->activeURI = activeURI; - g_object_notify(G_OBJECT(webView), "uri"); -} - -WebPageProxy* webkitWebViewCreateNewPage(WebKitWebView* webView, ImmutableDictionary* windowFeatures) +WebPageProxy* webkitWebViewCreateNewPage(WebKitWebView* webView, const WindowFeatures& windowFeatures, WebKitNavigationAction* navigationAction) { WebKitWebView* newWebView; - g_signal_emit(webView, signals[CREATE], 0, &newWebView); + g_signal_emit(webView, signals[CREATE], 0, navigationAction, &newWebView); if (!newWebView) return 0; @@ -1647,9 +1850,14 @@ void webkitWebViewRunAsModal(WebKitWebView* webView) g_signal_emit(webView, signals[RUN_AS_MODAL], 0, NULL); webView->priv->modalLoop = adoptGRef(g_main_loop_new(0, FALSE)); + +// This is to suppress warnings about gdk_threads_leave and gdk_threads_enter. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" gdk_threads_leave(); g_main_loop_run(webView->priv->modalLoop.get()); gdk_threads_enter(); +#pragma GCC diagnostic pop } void webkitWebViewClosePage(WebKitWebView* webView) @@ -1680,6 +1888,14 @@ CString webkitWebViewRunJavaScriptPrompt(WebKitWebView* webView, const CString& return dialog.text; } +bool webkitWebViewRunJavaScriptBeforeUnloadConfirm(WebKitWebView* webView, const CString& message) +{ + WebKitScriptDialog dialog(WEBKIT_SCRIPT_DIALOG_BEFORE_UNLOAD_CONFIRM, message); + gboolean returnValue; + g_signal_emit(webView, signals[SCRIPT_DIALOG], 0, &dialog, &returnValue); + return dialog.confirmed; +} + void webkitWebViewMakePolicyDecision(WebKitWebView* webView, WebKitPolicyDecisionType type, WebKitPolicyDecision* decision) { gboolean returnValue; @@ -1692,9 +1908,9 @@ void webkitWebViewMakePermissionRequest(WebKitWebView* webView, WebKitPermission g_signal_emit(webView, signals[PERMISSION_REQUEST], 0, request, &returnValue); } -void webkitWebViewMouseTargetChanged(WebKitWebView* webView, WebHitTestResult* hitTestResult, unsigned modifiers) +void webkitWebViewMouseTargetChanged(WebKitWebView* webView, const WebHitTestResultData& hitTestResult, unsigned modifiers) { - webkitWebViewBaseSetTooltipArea(WEBKIT_WEB_VIEW_BASE(webView), hitTestResult->elementBoundingBox()); + webkitWebViewBaseSetTooltipArea(WEBKIT_WEB_VIEW_BASE(webView), hitTestResult.elementBoundingBox); WebKitWebViewPrivate* priv = webView->priv; if (priv->mouseTargetHitTestResult @@ -1722,32 +1938,13 @@ void webkitWebViewPrintFrame(WebKitWebView* webView, WebFrameProxy* frame) g_signal_connect(printOperation.leakRef(), "finished", G_CALLBACK(g_object_unref), 0); } -static void mainResourceResponseChangedCallback(WebKitWebResource*, GParamSpec*, WebKitWebView* webView) -{ - webkitWebViewDisconnectMainResourceResponseChangedSignalHandler(webView); - webkitWebViewEmitDelayedLoadEvents(webView); -} - -static void waitForMainResourceResponseIfWaitingForResource(WebKitWebView* webView) -{ - WebKitWebViewPrivate* priv = webView->priv; - if (!priv->waitingForMainResource) - return; - - webkitWebViewDisconnectMainResourceResponseChangedSignalHandler(webView); - priv->mainResourceResponseHandlerID = - g_signal_connect(priv->mainResource.get(), "notify::response", G_CALLBACK(mainResourceResponseChangedCallback), webView); -} - void webkitWebViewResourceLoadStarted(WebKitWebView* webView, WebFrameProxy* frame, uint64_t resourceIdentifier, WebKitURIRequest* request) { WebKitWebViewPrivate* priv = webView->priv; bool isMainResource = frame->isMainFrame() && !priv->mainResource; WebKitWebResource* resource = webkitWebResourceCreate(frame, request, isMainResource); - if (isMainResource) { + if (isMainResource) priv->mainResource = resource; - waitForMainResourceResponseIfWaitingForResource(webView); - } priv->loadingResourcesMap.set(resourceIdentifier, adoptGRef(resource)); g_signal_emit(webView, signals[RESOURCE_LOAD_STARTED], 0, resource, request); } @@ -1785,76 +1982,29 @@ void webkitWebViewRunFileChooserRequest(WebKitWebView* webView, WebKitFileChoose g_signal_emit(webView, signals[RUN_FILE_CHOOSER], 0, request, &returnValue); } -static bool webkitWebViewShouldShowInputMethodsMenu(WebKitWebView* webView) -{ - GtkSettings* settings = gtk_widget_get_settings(GTK_WIDGET(webView)); - if (!settings) - return true; - - gboolean showInputMethodMenu; - g_object_get(settings, "gtk-show-input-method-menu", &showInputMethodMenu, NULL); - return showInputMethodMenu; -} - -static int getUnicodeMenuItemPosition(WebKitContextMenu* contextMenu) -{ - GList* items = webkit_context_menu_get_items(contextMenu); - GList* iter; - int i = 0; - for (iter = items, i = 0; iter; iter = g_list_next(iter), ++i) { - WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(iter->data); - - if (webkit_context_menu_item_is_separator(item)) - continue; - if (webkit_context_menu_item_get_stock_action(item) == WEBKIT_CONTEXT_MENU_ACTION_UNICODE) - return i; - } - return -1; -} - -static void webkitWebViewCreateAndAppendInputMethodsMenuItem(WebKitWebView* webView, WebKitContextMenu* contextMenu) -{ - if (!webkitWebViewShouldShowInputMethodsMenu(webView)) - return; - - // Place the im context menu item right before the unicode menu item - // if it's present. - int unicodeMenuItemPosition = getUnicodeMenuItemPosition(contextMenu); - if (unicodeMenuItemPosition == -1) - webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_separator()); - - GtkIMContext* imContext = webkitWebViewBaseGetIMContext(WEBKIT_WEB_VIEW_BASE(webView)); - GtkMenu* imContextMenu = GTK_MENU(gtk_menu_new()); - gtk_im_multicontext_append_menuitems(GTK_IM_MULTICONTEXT(imContext), GTK_MENU_SHELL(imContextMenu)); - WebKitContextMenuItem* menuItem = webkit_context_menu_item_new_from_stock_action(WEBKIT_CONTEXT_MENU_ACTION_INPUT_METHODS); - webkitContextMenuItemSetSubMenuFromGtkMenu(menuItem, imContextMenu); - webkit_context_menu_insert(contextMenu, menuItem, unicodeMenuItemPosition); -} - static void contextMenuDismissed(GtkMenuShell*, WebKitWebView* webView) { g_signal_emit(webView, signals[CONTEXT_MENU_DISMISSED], 0, NULL); } -void webkitWebViewPopulateContextMenu(WebKitWebView* webView, API::Array* proposedMenu, WebHitTestResult* webHitTestResult) +void webkitWebViewPopulateContextMenu(WebKitWebView* webView, const Vector<WebContextMenuItemData>& proposedMenu, const WebHitTestResultData& hitTestResultData, GVariant* userData) { WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(webView); WebContextMenuProxyGtk* contextMenuProxy = webkitWebViewBaseGetActiveContextMenuProxy(webViewBase); ASSERT(contextMenuProxy); GRefPtr<WebKitContextMenu> contextMenu = adoptGRef(webkitContextMenuCreate(proposedMenu)); - if (webHitTestResult->isContentEditable()) - webkitWebViewCreateAndAppendInputMethodsMenuItem(webView, contextMenu.get()); + if (userData) + webkit_context_menu_set_user_data(WEBKIT_CONTEXT_MENU(contextMenu.get()), userData); - GRefPtr<WebKitHitTestResult> hitTestResult = adoptGRef(webkitHitTestResultCreate(webHitTestResult)); + GRefPtr<WebKitHitTestResult> hitTestResult = adoptGRef(webkitHitTestResultCreate(hitTestResultData)); GUniquePtr<GdkEvent> contextMenuEvent(webkitWebViewBaseTakeContextMenuEvent(webViewBase)); - gboolean returnValue; g_signal_emit(webView, signals[CONTEXT_MENU], 0, contextMenu.get(), contextMenuEvent.get(), hitTestResult.get(), &returnValue); if (returnValue) return; - Vector<ContextMenuItem> contextMenuItems; + Vector<WebContextMenuItemGtk> contextMenuItems; webkitContextMenuPopulate(contextMenu.get(), contextMenuItems); contextMenuProxy->populate(contextMenuItems); @@ -1871,7 +2021,7 @@ void webkitWebViewSubmitFormRequest(WebKitWebView* webView, WebKitFormSubmission void webkitWebViewHandleAuthenticationChallenge(WebKitWebView* webView, AuthenticationChallengeProxy* authenticationChallenge) { - gboolean privateBrowsingEnabled = webkit_settings_get_enable_private_browsing(webkit_web_view_get_settings(webView)); + gboolean privateBrowsingEnabled = webkit_settings_get_enable_private_browsing(webView->priv->settings.get()); webView->priv->authenticationRequest = adoptGRef(webkitAuthenticationRequestCreate(authenticationChallenge, privateBrowsingEnabled)); gboolean returnValue; g_signal_emit(webView, signals[AUTHENTICATE], 0, webView->priv->authenticationRequest.get(), &returnValue); @@ -1882,12 +2032,46 @@ void webkitWebViewInsecureContentDetected(WebKitWebView* webView, WebKitInsecure g_signal_emit(webView, signals[INSECURE_CONTENT_DETECTED], 0, type); } +bool webkitWebViewEmitShowNotification(WebKitWebView* webView, WebKitNotification* webNotification) +{ + gboolean handled; + g_signal_emit(webView, signals[SHOW_NOTIFICATION], 0, webNotification, &handled); + return handled; +} + +bool webkitWebViewEmitRunColorChooser(WebKitWebView* webView, WebKitColorChooserRequest* request) +{ + gboolean handled; + g_signal_emit(webView, signals[RUN_COLOR_CHOOSER], 0, request, &handled); + return handled; +} + +void webkitWebViewSelectionDidChange(WebKitWebView* webView) +{ + if (!webView->priv->editorState) + return; + + webkitEditorStateChanged(webView->priv->editorState.get(), getPage(webView)->editorState()); +} + +void webkitWebViewRequestInstallMissingMediaPlugins(WebKitWebView* webView, InstallMissingMediaPluginsPermissionRequest& request) +{ +#if ENABLE(VIDEO) + GRefPtr<WebKitInstallMissingMediaPluginsPermissionRequest> installMediaPluginsPermissionRequest = adoptGRef(webkitInstallMissingMediaPluginsPermissionRequestCreate(request)); + webkitWebViewMakePermissionRequest(webView, WEBKIT_PERMISSION_REQUEST(installMediaPluginsPermissionRequest.get())); +#else + ASSERT_NOT_REACHED(); +#endif +} + /** * webkit_web_view_new: * - * Creates a new #WebKitWebView with the default #WebKitWebContext and the - * default #WebKitWebViewGroup. - * See also webkit_web_view_new_with_context() and webkit_web_view_new_with_group(). + * Creates a new #WebKitWebView with the default #WebKitWebContext and + * no #WebKitUserContentManager associated with it. + * See also webkit_web_view_new_with_context(), + * webkit_web_view_new_with_user_content_manager(), and + * webkit_web_view_new_with_settings(). * * Returns: The newly created #WebKitWebView widget */ @@ -1900,9 +2084,10 @@ GtkWidget* webkit_web_view_new() * webkit_web_view_new_with_context: * @context: the #WebKitWebContext to be used by the #WebKitWebView * - * Creates a new #WebKitWebView with the given #WebKitWebContext and the - * default #WebKitWebViewGroup. - * See also webkit_web_view_new_with_group(). + * Creates a new #WebKitWebView with the given #WebKitWebContext and + * no #WebKitUserContentManager associated with it. + * See also webkit_web_view_new_with_user_content_manager() and + * webkit_web_view_new_with_settings(). * * Returns: The newly created #WebKitWebView widget */ @@ -1925,6 +2110,9 @@ GtkWidget* webkit_web_view_new_with_context(WebKitWebContext* context) * You can also use this method to implement other process models based on %WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES, * like for example, sharing the same web process for all the views in the same security domain. * + * The newly created #WebKitWebView will also have the same #WebKitUserContentManager + * and #WebKitSettings as @web_view. + * * Returns: (transfer full): The newly created #WebKitWebView widget * * Since: 2.4 @@ -1933,24 +2121,48 @@ GtkWidget* webkit_web_view_new_with_related_view(WebKitWebView* webView) { g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), nullptr); - return GTK_WIDGET(g_object_new(WEBKIT_TYPE_WEB_VIEW, "related-view", webView, nullptr)); + return GTK_WIDGET(g_object_new(WEBKIT_TYPE_WEB_VIEW, + "user-content-manager", webView->priv->userContentManager.get(), + "settings", webView->priv->settings.get(), + "related-view", webView, + nullptr)); } /** - * webkit_web_view_new_with_group: - * @group: a #WebKitWebViewGroup + * webkit_web_view_new_with_settings: + * @settings: a #WebKitSettings * - * Creates a new #WebKitWebView with the given #WebKitWebViewGroup. - * The view will be part of @group and it will be affected by the - * group properties like the settings. + * Creates a new #WebKitWebView with the given #WebKitSettings. + * See also webkit_web_view_new_with_context(), and + * webkit_web_view_new_with_user_content_manager(). * * Returns: The newly created #WebKitWebView widget + * + * Since: 2.6 + */ +GtkWidget* webkit_web_view_new_with_settings(WebKitSettings* settings) +{ + g_return_val_if_fail(WEBKIT_IS_SETTINGS(settings), nullptr); + return GTK_WIDGET(g_object_new(WEBKIT_TYPE_WEB_VIEW, "settings", settings, nullptr)); +} + +/** + * webkit_web_view_new_with_user_content_manager: + * @user_content_manager: a #WebKitUserContentManager. + * + * Creates a new #WebKitWebView with the given #WebKitUserContentManager. + * The content loaded in the view may be affected by the content injected + * in the view by the user content manager. + * + * Returns: The newly created #WebKitWebView widget + * + * Since: 2.6 */ -GtkWidget* webkit_web_view_new_with_group(WebKitWebViewGroup* group) +GtkWidget* webkit_web_view_new_with_user_content_manager(WebKitUserContentManager* userContentManager) { - g_return_val_if_fail(WEBKIT_IS_WEB_VIEW_GROUP(group), 0); + g_return_val_if_fail(WEBKIT_IS_USER_CONTENT_MANAGER(userContentManager), nullptr); - return GTK_WIDGET(g_object_new(WEBKIT_TYPE_WEB_VIEW, "group", group, NULL)); + return GTK_WIDGET(g_object_new(WEBKIT_TYPE_WEB_VIEW, "user-content-manager", userContentManager, nullptr)); } /** @@ -1965,25 +2177,43 @@ WebKitWebContext* webkit_web_view_get_context(WebKitWebView *webView) { g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); - return webView->priv->context; + return webView->priv->context.get(); } /** - * webkit_web_view_get_group: + * webkit_web_view_get_user_content_manager: * @web_view: a #WebKitWebView * - * Gets the group @web_view belongs to. + * Gets the user content manager associated to @web_view, or %NULL if the + * view does not have an user content manager. + * + * Returns: (transfer none): the #WebKitUserContentManager associated with the view * - * Returns: (transfer none): the #WebKitWebViewGroup to which the view belongs + * Since: 2.6 */ -WebKitWebViewGroup* webkit_web_view_get_group(WebKitWebView* webView) +WebKitUserContentManager* webkit_web_view_get_user_content_manager(WebKitWebView* webView) { - g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), nullptr); - if (webView->priv->group) - return webView->priv->group.get(); + return webView->priv->userContentManager.get(); +} - return webkitWebContextGetDefaultWebViewGroup(webView->priv->context); +/** + * webkit_web_view_try_close: + * @web_view: a #WebKitWebView + * + * Tries to close the @web_view. This will fire the onbeforeunload event + * to ask the user for confirmation to close the page. If there isn't an + * onbeforeunload event handler or the user confirms to close the page, + * the #WebKitWebView::close signal is emitted, otherwise nothing happens. + * + * Since: 2.12 + */ +void webkit_web_view_try_close(WebKitWebView *webView) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + if (getPage(webView)->tryClose()) + webkitWebViewClosePage(webView); } /** @@ -2067,6 +2297,45 @@ void webkit_web_view_load_plain_text(WebKitWebView* webView, const gchar* plainT getPage(webView)->loadPlainTextString(String::fromUTF8(plainText)); } +static void releaseGBytes(unsigned char*, const void* bytes) +{ + // Balanced by g_bytes_ref in webkit_web_view_load_bytes(). + g_bytes_unref(static_cast<GBytes*>(const_cast<void*>(bytes))); +} + +/** + * webkit_web_view_load_bytes: + * @web_view: a #WebKitWebView + * @bytes: input data to load + * @mime_type: (allow-none): the MIME type of @bytes, or %NULL + * @encoding: (allow-none): the character encoding of @bytes, or %NULL + * @base_uri: (allow-none): the base URI for relative locations or %NULL + * + * Load the specified @bytes into @web_view using the given @mime_type and @encoding. + * When @mime_type is %NULL, it defaults to "text/html". + * When @encoding is %NULL, it defaults to "UTF-8". + * When @base_uri is %NULL, it defaults to "about:blank". + * You can monitor the load operation by connecting to #WebKitWebView::load-changed signal. + * + * Since: 2.6 + */ +void webkit_web_view_load_bytes(WebKitWebView* webView, GBytes* bytes, const char* mimeType, const char* encoding, const char* baseURI) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + g_return_if_fail(bytes); + + gsize bytesDataSize; + gconstpointer bytesData = g_bytes_get_data(bytes, &bytesDataSize); + g_return_if_fail(bytesDataSize); + + // Balanced by g_bytes_unref in releaseGBytes. + g_bytes_ref(bytes); + + Ref<API::Data> data = API::Data::createWithoutCopying(static_cast<const unsigned char*>(bytesData), bytesDataSize, releaseGBytes, bytes); + getPage(webView)->loadData(data.ptr(), mimeType ? String::fromUTF8(mimeType) : String::fromUTF8("text/html"), + encoding ? String::fromUTF8(encoding) : String::fromUTF8("UTF-8"), String::fromUTF8(baseURI)); +} + /** * webkit_web_view_load_request: * @web_view: a #WebKitWebView @@ -2130,7 +2399,9 @@ void webkit_web_view_reload(WebKitWebView* webView) { g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); - getPage(webView)->reload(false); + const bool reloadFromOrigin = false; + const bool contentBlockersEnabled = true; + getPage(webView)->reload(reloadFromOrigin, contentBlockersEnabled); } /** @@ -2144,7 +2415,9 @@ void webkit_web_view_reload_bypass_cache(WebKitWebView* webView) { g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); - getPage(webView)->reload(true); + const bool reloadFromOrigin = true; + const bool contentBlockersEnabled = true; + getPage(webView)->reload(reloadFromOrigin, contentBlockersEnabled); } /** @@ -2185,6 +2458,27 @@ gboolean webkit_web_view_is_loading(WebKitWebView* webView) } /** + * webkit_web_view_is_playing_audio: + * @web_view: a #WebKitWebView + * + * Gets the value of the #WebKitWebView:is-playing-audio property. + * You can monitor when a page in a #WebKitWebView is playing audio by + * connecting to the notify::is-playing-audio signal of @web_view. This + * is useful when the application wants to provide visual feedback when a + * page is producing sound. + * + * Returns: %TRUE if a page in @web_view is playing audio or %FALSE otherwise. + * + * Since: 2.8 + */ +gboolean webkit_web_view_is_playing_audio(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE); + + return getPage(webView)->isPlayingAudio(); +} + +/** * webkit_web_view_go_back: * @web_view: a #WebKitWebView * @@ -2382,7 +2676,7 @@ void webkit_web_view_set_custom_charset(WebKitWebView* webView, const gchar* cha gdouble webkit_web_view_get_estimated_load_progress(WebKitWebView* webView) { g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); - return webView->priv->estimatedLoadProgress; + return getPage(webView)->pageLoadState().estimatedProgress(); } /** @@ -2423,16 +2717,30 @@ void webkit_web_view_go_to_back_forward_list_item(WebKitWebView* webView, WebKit * @web_view: a #WebKitWebView * @settings: a #WebKitSettings * - * Sets the #WebKitSettings to be applied to @web_view. - * This is a convenient method to set new settings to the - * #WebKitWebViewGroup @web_view belongs to. - * New settings are applied immediately on all #WebKitWebView<!-- -->s - * in the @web_view group. - * See also webkit_web_view_group_set_settings(). + * Sets the #WebKitSettings to be applied to @web_view. The + * existing #WebKitSettings of @web_view will be replaced by + * @settings. New settings are applied immediately on @web_view. + * The same #WebKitSettings object can be shared + * by multiple #WebKitWebView<!-- -->s. */ void webkit_web_view_set_settings(WebKitWebView* webView, WebKitSettings* settings) { - webkit_web_view_group_set_settings(webkit_web_view_get_group(webView), settings); + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + g_return_if_fail(WEBKIT_IS_SETTINGS(settings)); + + if (webView->priv->settings == settings) + return; + + // The "settings" property is set on construction, and in that + // case webkit_web_view_set_settings() will be called *before* + // any settings have been assigned. In that case there are no + // signal handlers to disconnect. + if (webView->priv->settings) + webkitWebViewDisconnectSettingsSignalHandlers(webView); + + webView->priv->settings = settings; + webkitWebViewUpdateSettings(webView); + g_object_notify(G_OBJECT(webView), "settings"); } /** @@ -2440,19 +2748,25 @@ void webkit_web_view_set_settings(WebKitWebView* webView, WebKitSettings* settin * @web_view: a #WebKitWebView * * Gets the #WebKitSettings currently applied to @web_view. - * This is a convenient method to get the settings of the - * #WebKitWebViewGroup @web_view belongs to. - * #WebKitSettings objects are shared by all the #WebKitWebView<!-- -->s - * in the same #WebKitWebViewGroup, so modifying + * If no other #WebKitSettings have been explicitly applied to + * @web_view with webkit_web_view_set_settings(), the default + * #WebKitSettings will be returned. This method always returns + * a valid #WebKitSettings object. + * To modify any of the @web_view settings, you can either create + * a new #WebKitSettings object with webkit_settings_new(), setting + * the desired preferences, and then replace the existing @web_view + * settings with webkit_web_view_set_settings() or get the existing + * @web_view settings and update it directly. #WebKitSettings objects + * can be shared by multiple #WebKitWebView<!-- -->s, so modifying * the settings of a #WebKitWebView would affect other - * #WebKitWebView<!-- -->s of the same group. - * See also webkit_web_view_group_get_settings(). + * #WebKitWebView<!-- -->s using the same #WebKitSettings. * * Returns: (transfer none): the #WebKitSettings attached to @web_view */ WebKitSettings* webkit_web_view_get_settings(WebKitWebView* webView) { - return webkit_web_view_group_get_settings(webkit_web_view_get_group(webView)); + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), nullptr); + return webView->priv->settings.get(); } /** @@ -2487,7 +2801,7 @@ void webkit_web_view_set_zoom_level(WebKitWebView* webView, gdouble zoomLevel) return; WebPageProxy* page = getPage(webView); - if (webkit_settings_get_zoom_text_only(webkit_web_view_get_settings(webView))) + if (webkit_settings_get_zoom_text_only(webView->priv->settings.get())) page->setTextZoomFactor(zoomLevel); else page->setPageZoomFactor(zoomLevel); @@ -2508,16 +2822,10 @@ gdouble webkit_web_view_get_zoom_level(WebKitWebView* webView) g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 1); WebPageProxy* page = getPage(webView); - gboolean zoomTextOnly = webkit_settings_get_zoom_text_only(webkit_web_view_get_settings(webView)); + gboolean zoomTextOnly = webkit_settings_get_zoom_text_only(webView->priv->settings.get()); return zoomTextOnly ? page->textZoomFactor() : page->pageZoomFactor(); } -static void didValidateCommand(WKStringRef command, bool isEnabled, int32_t state, WKErrorRef, void* context) -{ - GRefPtr<GTask> task = adoptGRef(G_TASK(context)); - g_task_return_boolean(task.get(), isEnabled); -} - /** * webkit_web_view_can_execute_editing_command: * @web_view: a #WebKitWebView @@ -2537,7 +2845,9 @@ void webkit_web_view_can_execute_editing_command(WebKitWebView* webView, const c g_return_if_fail(command); GTask* task = g_task_new(webView, cancellable, callback, userData); - getPage(webView)->validateCommand(String::fromUTF8(command), ValidateCommandCallback::create(task, didValidateCommand)); + getPage(webView)->validateCommand(String::fromUTF8(command), [task](const String&, bool isEnabled, int32_t, WebKit::CallbackBase::Error) { + g_task_return_boolean(adoptGRef(task).get(), isEnabled); + }); } /** @@ -2576,6 +2886,27 @@ void webkit_web_view_execute_editing_command(WebKitWebView* webView, const char* } /** + * webkit_web_view_execute_editing_command_with_argument: + * @web_view: a #WebKitWebView + * @command: the command to execute + * @argument: the command argument + * + * Request to execute the given @command with @argument for @web_view. You can use + * webkit_web_view_can_execute_editing_command() to check whether + * it's possible to execute the command. + * + * Since: 2.10 + */ +void webkit_web_view_execute_editing_command_with_argument(WebKitWebView* webView, const char* command, const char* argument) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + g_return_if_fail(command); + g_return_if_fail(argument); + + getPage(webView)->executeEditCommand(String::fromUTF8(command), String::fromUTF8(argument)); +} + +/** * webkit_web_view_get_find_controller: * @web_view: the #WebKitWebView * @@ -2614,20 +2945,20 @@ JSGlobalContextRef webkit_web_view_get_javascript_global_context(WebKitWebView* return webView->priv->javascriptGlobalContext; } -static void webkitWebViewRunJavaScriptCallback(WKSerializedScriptValueRef wkSerializedScriptValue, WKErrorRef, void* context) +static void webkitWebViewRunJavaScriptCallback(API::SerializedScriptValue* wkSerializedScriptValue, GTask* task) { - GRefPtr<GTask> task = adoptGRef(G_TASK(context)); - if (g_task_return_error_if_cancelled(task.get())) + if (g_task_return_error_if_cancelled(task)) return; if (!wkSerializedScriptValue) { - g_task_return_new_error(task.get(), WEBKIT_JAVASCRIPT_ERROR, WEBKIT_JAVASCRIPT_ERROR_SCRIPT_FAILED, + g_task_return_new_error(task, WEBKIT_JAVASCRIPT_ERROR, WEBKIT_JAVASCRIPT_ERROR_SCRIPT_FAILED, _("An exception was raised in JavaScript")); return; } - WebKitWebView* webView = WEBKIT_WEB_VIEW(g_task_get_source_object(task.get())); - g_task_return_pointer(task.get(), webkitJavascriptResultCreate(webView, toImpl(wkSerializedScriptValue)), + WebKitWebView* webView = WEBKIT_WEB_VIEW(g_task_get_source_object(task)); + g_task_return_pointer(task, webkitJavascriptResultCreate(webView, + *wkSerializedScriptValue->internalRepresentation()), reinterpret_cast<GDestroyNotify>(webkit_javascript_result_unref)); } @@ -2651,7 +2982,9 @@ void webkit_web_view_run_javascript(WebKitWebView* webView, const gchar* script, g_return_if_fail(script); GTask* task = g_task_new(webView, cancellable, callback, userData); - getPage(webView)->runJavaScriptInMainFrame(String::fromUTF8(script), ScriptValueCallback::create(task, webkitWebViewRunJavaScriptCallback)); + getPage(webView)->runJavaScriptInMainFrame(String::fromUTF8(script), [task](API::SerializedScriptValue* serializedScriptValue, bool, const WebCore::ExceptionDetails&, WebKit::CallbackBase::Error) { + webkitWebViewRunJavaScriptCallback(serializedScriptValue, adoptGRef(task).get()); + }); } /** @@ -2740,7 +3073,9 @@ static void resourcesStreamReadCallback(GObject* object, GAsyncResult* result, g WebKitWebView* webView = WEBKIT_WEB_VIEW(g_task_get_source_object(task.get())); gpointer outputStreamData = g_memory_output_stream_get_data(G_MEMORY_OUTPUT_STREAM(object)); getPage(webView)->runJavaScriptInMainFrame(String::fromUTF8(reinterpret_cast<const gchar*>(outputStreamData)), - ScriptValueCallback::create(task.leakRef(), webkitWebViewRunJavaScriptCallback)); + [task](API::SerializedScriptValue* serializedScriptValue, bool, const WebCore::ExceptionDetails&, WebKit::CallbackBase::Error) { + webkitWebViewRunJavaScriptCallback(serializedScriptValue, task.get()); + }); } /** @@ -2867,16 +3202,16 @@ static void fileReplaceContentsCallback(GObject* object, GAsyncResult* result, g g_task_return_boolean(task.get(), TRUE); } -static void getContentsAsMHTMLDataCallback(WKDataRef wkData, WKErrorRef, void* context) +static void getContentsAsMHTMLDataCallback(API::Data* wkData, GTask* taskPtr) { - GRefPtr<GTask> task = adoptGRef(G_TASK(context)); + GRefPtr<GTask> task = adoptGRef(taskPtr); if (g_task_return_error_if_cancelled(task.get())) return; ViewSaveAsyncData* data = static_cast<ViewSaveAsyncData*>(g_task_get_task_data(task.get())); // We need to retain the data until the asyncronous process // initiated by the user has finished completely. - data->webData = toImpl(wkData); + data->webData = wkData; // If we are saving to a file we need to write the data on disk before finishing. if (g_task_get_source_tag(task.get()) == webkit_web_view_save_to_file) { @@ -2916,7 +3251,9 @@ void webkit_web_view_save(WebKitWebView* webView, WebKitSaveMode saveMode, GCanc GTask* task = g_task_new(webView, cancellable, callback, userData); g_task_set_source_tag(task, reinterpret_cast<gpointer>(webkit_web_view_save)); g_task_set_task_data(task, createViewSaveAsyncData(), reinterpret_cast<GDestroyNotify>(destroyViewSaveAsyncData)); - getPage(webView)->getContentsAsMHTMLData(DataCallback::create(task, getContentsAsMHTMLDataCallback), false); + getPage(webView)->getContentsAsMHTMLData([task](API::Data* data, WebKit::CallbackBase::Error) { + getContentsAsMHTMLDataCallback(data, task); + }); } /** @@ -2979,7 +3316,9 @@ void webkit_web_view_save_to_file(WebKitWebView* webView, GFile* file, WebKitSav data->file = file; g_task_set_task_data(task, data, reinterpret_cast<GDestroyNotify>(destroyViewSaveAsyncData)); - getPage(webView)->getContentsAsMHTMLData(DataCallback::create(task, getContentsAsMHTMLDataCallback), false); + getPage(webView)->getContentsAsMHTMLData([task](API::Data* data, WebKit::CallbackBase::Error) { + getContentsAsMHTMLDataCallback(data, task); + }); } /** @@ -3015,50 +3354,13 @@ WebKitDownload* webkit_web_view_download_uri(WebKitWebView* webView, const char* g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); g_return_val_if_fail(uri, 0); - WebKitDownload* download = webkitWebContextStartDownload(webView->priv->context, uri, getPage(webView)); + WebKitDownload* download = webkitWebContextStartDownload(webView->priv->context.get(), uri, getPage(webView)); webkitDownloadSetWebView(download, webView); return download; } /** - * webkit_web_view_set_view_mode: - * @web_view: a #WebKitWebView - * @view_mode: a #WebKitViewMode - * - * Set the view mode of @web_view to @view_mode. This method should be called - * before loading new contents on @web_view so that the new #WebKitViewMode will - * be applied to the new contents. - */ -void webkit_web_view_set_view_mode(WebKitWebView* webView, WebKitViewMode viewMode) -{ - g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); - - if (webView->priv->viewMode == viewMode) - return; - - getPage(webView)->setMainFrameInViewSourceMode(viewMode == WEBKIT_VIEW_MODE_SOURCE); - - webView->priv->viewMode = viewMode; - g_object_notify(G_OBJECT(webView), "view-mode"); -} - -/** - * webkit_web_view_get_view_mode: - * @web_view: a #WebKitWebView - * - * Get the view mode of @web_view. - * - * Returns: the #WebKitViewMode of @web_view. - */ -WebKitViewMode webkit_web_view_get_view_mode(WebKitWebView* webView) -{ - g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), WEBKIT_VIEW_MODE_WEB); - - return webView->priv->viewMode; -} - -/** * webkit_web_view_get_tls_info: * @web_view: a #WebKitWebView * @certificate: (out) (transfer none): return location for a #GTlsCertificate @@ -3073,10 +3375,10 @@ WebKitViewMode webkit_web_view_get_view_mode(WebKitWebView* webView) * when it's emitted with %WEBKIT_LOAD_COMMITTED event. * * Note that this function provides no information about the security of the web - * page if the current #WebKitTLSErrorsPolicy is %WEBKIT_TLS_ERRORS_POLICY_IGNORE, + * page if the current #WebKitTLSErrorsPolicy is @WEBKIT_TLS_ERRORS_POLICY_IGNORE, * as subresources of the page may be controlled by an attacker. This function * may safely be used to determine the security status of the current page only - * if the current #WebKitTLSErrorsPolicy is %WEBKIT_TLS_ERRORS_POLICY_FAIL, in + * if the current #WebKitTLSErrorsPolicy is @WEBKIT_TLS_ERRORS_POLICY_FAIL, in * which case subresources that fail certificate verification will be blocked. * * Returns: %TRUE if the @web_view connection uses HTTPS and a response has been received @@ -3090,7 +3392,10 @@ gboolean webkit_web_view_get_tls_info(WebKitWebView* webView, GTlsCertificate** if (!mainFrame) return FALSE; - const WebCore::CertificateInfo& certificateInfo = mainFrame->certificateInfo()->certificateInfo(); + auto* wkCertificateInfo = mainFrame->certificateInfo(); + g_return_val_if_fail(wkCertificateInfo, FALSE); + + const auto& certificateInfo = wkCertificateInfo->certificateInfo(); if (certificate) *certificate = certificateInfo.certificate(); if (errors) @@ -3117,9 +3422,6 @@ void webKitWebViewDidReceiveSnapshot(WebKitWebView* webView, uint64_t callbackID g_task_return_pointer(task.get(), 0, 0); } -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_SNAPSHOT_REGION_VISIBLE, SnapshotRegionVisible); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT, SnapshotRegionFullDocument); - static inline unsigned webKitSnapshotOptionsToSnapshotOptions(WebKitSnapshotOptions options) { SnapshotOptions snapshotOptions = 0; @@ -3130,6 +3432,19 @@ static inline unsigned webKitSnapshotOptionsToSnapshotOptions(WebKitSnapshotOpti return snapshotOptions; } +static inline SnapshotRegion toSnapshotRegion(WebKitSnapshotRegion region) +{ + switch (region) { + case WEBKIT_SNAPSHOT_REGION_VISIBLE: + return SnapshotRegionVisible; + case WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT: + return SnapshotRegionFullDocument; + default: + ASSERT_NOT_REACHED(); + return SnapshotRegionVisible; + } +} + static inline uint64_t generateSnapshotCallbackID() { static uint64_t uniqueCallbackID = 1; @@ -3139,8 +3454,8 @@ static inline uint64_t generateSnapshotCallbackID() /** * webkit_web_view_get_snapshot: * @web_view: a #WebKitWebView - * @options: #WebKitSnapshotOptions for the snapshot * @region: the #WebKitSnapshotRegion for this snapshot + * @options: #WebKitSnapshotOptions for the snapshot * @cancellable: (allow-none): a #GCancellable * @callback: (scope async): a #GAsyncReadyCallback * @user_data: (closure): user data @@ -3156,14 +3471,15 @@ void webkit_web_view_get_snapshot(WebKitWebView* webView, WebKitSnapshotRegion r { g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); - ImmutableDictionary::MapType message; + API::Dictionary::MapType message; uint64_t callbackID = generateSnapshotCallbackID(); message.set(String::fromUTF8("SnapshotOptions"), API::UInt64::create(static_cast<uint64_t>(webKitSnapshotOptionsToSnapshotOptions(options)))); - message.set(String::fromUTF8("SnapshotRegion"), API::UInt64::create(static_cast<uint64_t>(region))); + message.set(String::fromUTF8("SnapshotRegion"), API::UInt64::create(static_cast<uint64_t>(toSnapshotRegion(region)))); message.set(String::fromUTF8("CallbackID"), API::UInt64::create(callbackID)); + message.set(String::fromUTF8("TransparentBackground"), API::Boolean::create(options & WEBKIT_SNAPSHOT_OPTIONS_TRANSPARENT_BACKGROUND)); webView->priv->snapshotResultsMap.set(callbackID, adoptGRef(g_task_new(webView, cancellable, callback, userData))); - getPage(webView)->postMessageToInjectedBundle(String::fromUTF8("GetSnapshot"), ImmutableDictionary::create(std::move(message)).get()); + getPage(webView)->postMessageToInjectedBundle(String::fromUTF8("GetSnapshot"), API::Dictionary::create(WTFMove(message)).ptr()); } /** @@ -3190,3 +3506,176 @@ void webkitWebViewWebProcessCrashed(WebKitWebView* webView) g_signal_emit(webView, signals[WEB_PROCESS_CRASHED], 0, &returnValue); } +/** + * webkit_web_view_set_background_color: + * @web_view: a #WebKitWebView + * @rgba: a #GdkRGBA + * + * Sets the color that will be used to draw the @web_view background before + * the actual contents are rendered. Note that if the web page loaded in @web_view + * specifies a background color, it will take precedence over the @rgba color. + * By default the @web_view background color is opaque white. + * If the @rgba color is not fully opaque, the parent window must have a RGBA visual and + * #GtkWidget:app-paintable property set to %TRUE, for the transparencies to work. + * + * <informalexample><programlisting> + * static void browser_window_set_background_color (BrowserWindow *window, + * const GdkRGBA *rgba) + * { + * WebKitWebView *web_view; + * + * if (rgba->alpha < 1) { + * GdkScreen *screen = gtk_window_get_screen (GTK_WINDOW (window)); + * GdkVisual *rgba_visual = gdk_screen_get_rgba_visual (screen); + * + * if (!rgba_visual) + * return; + * + * gtk_widget_set_visual (GTK_WIDGET (window), rgba_visual); + * gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE); + * } + * + * web_view = browser_window_get_web_view (window); + * webkit_web_view_set_background_color (web_view, rgba); + * } + * </programlisting></informalexample> + * + * Since: 2.8 + */ +void webkit_web_view_set_background_color(WebKitWebView* webView, const GdkRGBA* rgba) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + g_return_if_fail(rgba); + + Color color(*rgba); + WebPageProxy* page = getPage(webView); + if (page->backgroundColor() == color) + return; + + page->setBackgroundColor(color); + page->setDrawsBackground(color == Color::white); +} + +/** + * webkit_web_view_get_background_color: + * @web_view: a #WebKitWebView + * @rgba: (out): a #GdkRGBA to fill in with the background color + * + * Gets the color that is used to draw the @web_view background before + * the actual contents are rendered. + * For more information see also webkit_web_view_set_background_color() + * + * Since: 2.8 + */ +void webkit_web_view_get_background_color(WebKitWebView* webView, GdkRGBA* rgba) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + g_return_if_fail(rgba); + + *rgba = getPage(webView)->backgroundColor(); +} + +/* + * webkit_web_view_is_editable: + * @web_view: a #WebKitWebView + * + * Gets whether the user is allowed to edit the HTML document. When @web_view + * is not editable an element in the HTML document can only be edited if the + * CONTENTEDITABLE attribute has been set on the element or one of its parent + * elements. By default a #WebKitWebView is not editable. + * + * Returns: %TRUE if the user is allowed to edit the HTML document, or %FALSE otherwise. + * + * Since: 2.8 + */ +gboolean webkit_web_view_is_editable(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE); + + return getPage(webView)->isEditable(); +} + +/** + * webkit_web_view_set_editable: + * @web_view: a #WebKitWebView + * @editable: a #gboolean indicating the editable state + * + * Sets whether the user is allowed to edit the HTML document. + * + * If @editable is %TRUE, @web_view allows the user to edit the HTML document. If + * @editable is %FALSE, an element in @web_view's document can only be edited if the + * CONTENTEDITABLE attribute has been set on the element or one of its parent + * elements. By default a #WebKitWebView is not editable. + * + * Normally, a HTML document is not editable unless the elements within the + * document are editable. This function provides a way to make the contents + * of a #WebKitWebView editable without altering the document or DOM structure. + * + * Since: 2.8 + */ +void webkit_web_view_set_editable(WebKitWebView* webView, gboolean editable) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + if (editable == getPage(webView)->isEditable()) + return; + + getPage(webView)->setEditable(editable); + + g_object_notify(G_OBJECT(webView), "editable"); +} + +/** + * webkit_web_view_get_editor_state: + * @web_view: a #WebKitWebView + * + * Gets the web editor state of @web_view. + * + * Returns: (transfer none): the #WebKitEditorState of the view + * + * Since: 2.10 + */ +WebKitEditorState* webkit_web_view_get_editor_state(WebKitWebView *webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), nullptr); + + if (!webView->priv->editorState) + webView->priv->editorState = adoptGRef(webkitEditorStateCreate(getPage(webView)->editorState())); + + return webView->priv->editorState.get(); +} + +/** + * webkit_web_view_get_session_state: + * @web_view: a #WebKitWebView + * + * Gets the current session state of @web_view + * + * Returns: (transfer full): a #WebKitWebViewSessionState + * + * Since: 2.12 + */ +WebKitWebViewSessionState* webkit_web_view_get_session_state(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), nullptr); + + SessionState sessionState = getPage(webView)->sessionState(nullptr); + return webkitWebViewSessionStateCreate(WTFMove(sessionState)); +} + +/** + * webkit_web_view_restore_session_state: + * @web_view: a #WebKitWebView + * @state: a #WebKitWebViewSessionState + * + * Restore the @web_view session state from @state + * + * Since: 2.12 + */ +void webkit_web_view_restore_session_state(WebKitWebView* webView, WebKitWebViewSessionState* state) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + g_return_if_fail(state); + + getPage(webView)->restoreFromSessionState(webkitWebViewSessionStateGetSessionState(state), false); +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h index 493c68d18..700968fc4 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h @@ -32,22 +32,27 @@ #include <webkit2/WebKitAuthenticationRequest.h> #include <webkit2/WebKitBackForwardList.h> #include <webkit2/WebKitDefines.h> +#include <webkit2/WebKitColorChooserRequest.h> +#include <webkit2/WebKitEditorState.h> #include <webkit2/WebKitFileChooserRequest.h> #include <webkit2/WebKitFindController.h> #include <webkit2/WebKitFormSubmissionRequest.h> #include <webkit2/WebKitForwardDeclarations.h> #include <webkit2/WebKitHitTestResult.h> #include <webkit2/WebKitJavascriptResult.h> +#include <webkit2/WebKitNavigationAction.h> +#include <webkit2/WebKitNotification.h> #include <webkit2/WebKitPermissionRequest.h> #include <webkit2/WebKitPolicyDecision.h> #include <webkit2/WebKitScriptDialog.h> #include <webkit2/WebKitSettings.h> #include <webkit2/WebKitURIRequest.h> +#include <webkit2/WebKitUserContentManager.h> #include <webkit2/WebKitWebContext.h> #include <webkit2/WebKitWebInspector.h> #include <webkit2/WebKitWebResource.h> #include <webkit2/WebKitWebViewBase.h> -#include <webkit2/WebKitWebViewGroup.h> +#include <webkit2/WebKitWebViewSessionState.h> #include <webkit2/WebKitWindowProperties.h> G_BEGIN_DECLS @@ -150,23 +155,12 @@ typedef enum { } WebKitInsecureContentEvent; /** - * WebKitViewMode: - * @WEBKIT_VIEW_MODE_WEB: The normal view mode to display web contents. - * @WEBKIT_VIEW_MODE_SOURCE: The source mode to display web source code. - * - * Enum values to specify the different ways in which a #WebKitWebView - * can display a web page. - */ -typedef enum { - WEBKIT_VIEW_MODE_WEB, - WEBKIT_VIEW_MODE_SOURCE -} WebKitViewMode; - -/** * WebKitSnapshotOptions: * @WEBKIT_SNAPSHOT_OPTIONS_NONE: Do not include any special options. * @WEBKIT_SNAPSHOT_OPTIONS_INCLUDE_SELECTION_HIGHLIGHTING: Whether to include in the * snapshot the highlight of the selected content. + * @WEBKIT_SNAPSHOT_OPTIONS_TRANSPARENT_BACKGROUND: Do not fill the background with white before + * rendering the snapshot. Since 2.8 * * Enum values used to specify options when taking a snapshot * from a #WebKitWebView. @@ -174,6 +168,7 @@ typedef enum { typedef enum { WEBKIT_SNAPSHOT_OPTIONS_NONE = 0, WEBKIT_SNAPSHOT_OPTIONS_INCLUDE_SELECTION_HIGHLIGHTING = 1 << 0, + WEBKIT_SNAPSHOT_OPTIONS_TRANSPARENT_BACKGROUND = 1 << 1, } WebKitSnapshotOptions; /** @@ -207,7 +202,8 @@ struct _WebKitWebViewClass { const gchar *failing_uri, GError *error); - GtkWidget *(* create) (WebKitWebView *web_view); + GtkWidget *(* create) (WebKitWebView *web_view, + WebKitNavigationAction *navigation_action); void (* ready_to_show) (WebKitWebView *web_view); void (* run_as_modal) (WebKitWebView *web_view); void (* close) (WebKitWebView *web_view); @@ -246,14 +242,18 @@ struct _WebKitWebViewClass { gboolean (* authenticate) (WebKitWebView *web_view, WebKitAuthenticationRequest *request); gboolean (* load_failed_with_tls_errors) (WebKitWebView *web_view, - WebKitCertificateInfo *info, - const gchar *host); + const gchar *failing_uri, + GTlsCertificate *certificate, + GTlsCertificateFlags errors); + gboolean (* show_notification) (WebKitWebView *web_view, + WebKitNotification *notification); + gboolean (* run_color_chooser) (WebKitWebView *web_view, + WebKitColorChooserRequest *request); + void (*_webkit_reserved0) (void); void (*_webkit_reserved1) (void); void (*_webkit_reserved2) (void); void (*_webkit_reserved3) (void); - void (*_webkit_reserved4) (void); - void (*_webkit_reserved5) (void); }; WEBKIT_API GType @@ -266,16 +266,19 @@ WEBKIT_API GtkWidget * webkit_web_view_new_with_context (WebKitWebContext *context); WEBKIT_API GtkWidget * +webkit_web_view_new_with_settings (WebKitSettings *settings); + +WEBKIT_API GtkWidget * webkit_web_view_new_with_related_view (WebKitWebView *web_view); WEBKIT_API GtkWidget * -webkit_web_view_new_with_group (WebKitWebViewGroup *group); +webkit_web_view_new_with_user_content_manager (WebKitUserContentManager *user_content_manager); WEBKIT_API WebKitWebContext * webkit_web_view_get_context (WebKitWebView *web_view); -WEBKIT_API WebKitWebViewGroup * -webkit_web_view_get_group (WebKitWebView *web_view); +WEBKIT_API void +webkit_web_view_try_close (WebKitWebView *web_view); WEBKIT_API void webkit_web_view_load_uri (WebKitWebView *web_view, @@ -295,6 +298,13 @@ webkit_web_view_load_plain_text (WebKitWebView const gchar *plain_text); WEBKIT_API void +webkit_web_view_load_bytes (WebKitWebView *web_view, + GBytes *bytes, + const gchar *mime_type, + const gchar *encoding, + const gchar *base_uri); + +WEBKIT_API void webkit_web_view_load_request (WebKitWebView *web_view, WebKitURIRequest *request); @@ -304,6 +314,9 @@ webkit_web_view_stop_loading (WebKitWebView WEBKIT_API gboolean webkit_web_view_is_loading (WebKitWebView *web_view); +WEBKIT_API gboolean +webkit_web_view_is_playing_audio (WebKitWebView *web_view); + WEBKIT_API guint64 webkit_web_view_get_page_id (WebKitWebView *web_view); @@ -382,6 +395,11 @@ WEBKIT_API void webkit_web_view_execute_editing_command (WebKitWebView *web_view, const gchar *command); +WEBKIT_API void +webkit_web_view_execute_editing_command_with_argument(WebKitWebView *web_view, + const char *command, + const char *argument); + WEBKIT_API WebKitFindController * webkit_web_view_get_find_controller (WebKitWebView *web_view); @@ -450,13 +468,6 @@ WEBKIT_API WebKitDownload * webkit_web_view_download_uri (WebKitWebView *web_view, const char *uri); -WEBKIT_API void -webkit_web_view_set_view_mode (WebKitWebView *web_view, - WebKitViewMode view_mode); - -WEBKIT_API WebKitViewMode -webkit_web_view_get_view_mode (WebKitWebView *web_view); - WEBKIT_API gboolean webkit_web_view_get_tls_info (WebKitWebView *web_view, GTlsCertificate **certificate, @@ -473,6 +484,35 @@ WEBKIT_API cairo_surface_t * webkit_web_view_get_snapshot_finish (WebKitWebView *web_view, GAsyncResult *result, GError **error); + +WEBKIT_API WebKitUserContentManager * +webkit_web_view_get_user_content_manager (WebKitWebView *web_view); + +WEBKIT_API void +webkit_web_view_set_background_color (WebKitWebView *web_view, + const GdkRGBA *rgba); + +WEBKIT_API void +webkit_web_view_get_background_color (WebKitWebView *web_view, + GdkRGBA *rgba); + +WEBKIT_API gboolean +webkit_web_view_is_editable (WebKitWebView *web_view); + +WEBKIT_API void +webkit_web_view_set_editable (WebKitWebView *web_view, + gboolean editable); + +WEBKIT_API WebKitEditorState * +webkit_web_view_get_editor_state (WebKitWebView *web_view); + +WEBKIT_API WebKitWebViewSessionState * +webkit_web_view_get_session_state (WebKitWebView *web_view); + +WEBKIT_API void +webkit_web_view_restore_session_state (WebKitWebView *web_view, + WebKitWebViewSessionState *state); + G_END_DECLS #endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp index b22c71fa1..1de51537d 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp @@ -29,15 +29,20 @@ #include "config.h" #include "WebKitWebViewBase.h" +#include "APIPageConfiguration.h" #include "DrawingAreaProxyImpl.h" +#include "InputMethodFilter.h" +#include "KeyBindingTranslator.h" +#include "NativeWebKeyboardEvent.h" #include "NativeWebMouseEvent.h" #include "NativeWebWheelEvent.h" #include "PageClientImpl.h" +#include "RedirectedXCompositeWindow.h" #include "ViewState.h" -#include "WebContext.h" #include "WebEventFactory.h" #include "WebFullScreenClientGtk.h" #include "WebInspectorProxy.h" +#include "WebKit2Initialize.h" #include "WebKitAuthenticationDialog.h" #include "WebKitPrivate.h" #include "WebKitWebViewBaseAccessible.h" @@ -45,37 +50,35 @@ #include "WebPageGroup.h" #include "WebPageProxy.h" #include "WebPreferences.h" -#include "WebViewBaseInputMethodFilter.h" +#include "WebProcessPool.h" +#include "WebUserContentControllerProxy.h" #include <WebCore/CairoUtilities.h> -#include <WebCore/ClipboardUtilitiesGtk.h> -#include <WebCore/DataObjectGtk.h> -#include <WebCore/DragData.h> -#include <WebCore/DragIcon.h> #include <WebCore/GUniquePtrGtk.h> -#include <WebCore/GtkClickCounter.h> -#include <WebCore/GtkDragAndDropHelper.h> -#include <WebCore/GtkTouchContextHelper.h> #include <WebCore/GtkUtilities.h> #include <WebCore/GtkVersioning.h> #include <WebCore/NotImplemented.h> #include <WebCore/PasteboardHelper.h> +#include <WebCore/PlatformDisplay.h> #include <WebCore/RefPtrCairo.h> #include <WebCore/Region.h> #include <gdk/gdk.h> #include <gdk/gdkkeysyms.h> -#ifdef GDK_WINDOWING_X11 -#include <gdk/gdkx.h> -#endif +#include <glib/gi18n-lib.h> +#include <memory> #include <wtf/HashMap.h> -#include <wtf/gobject/GRefPtr.h> +#include <wtf/glib/GRefPtr.h> #include <wtf/text/CString.h> #if ENABLE(FULLSCREEN_API) #include "WebFullScreenManagerProxy.h" #endif -#if USE(TEXTURE_MAPPER_GL) && defined(GDK_WINDOWING_X11) -#include <WebCore/RedirectedXCompositeWindow.h> +#if PLATFORM(X11) +#include <gdk/gdkx.h> +#endif + +#if PLATFORM(WAYLAND) +#include <gdk/gdkwayland.h> #endif // gtk_widget_get_scale_factor() appeared in GTK 3.10, but we also need @@ -85,130 +88,212 @@ using namespace WebKit; using namespace WebCore; +struct ClickCounter { +public: + void reset() + { + currentClickCount = 0; + previousClickPoint = IntPoint(); + previousClickTime = 0; + previousClickButton = 0; + } + + int currentClickCountForGdkButtonEvent(GdkEventButton* buttonEvent) + { + GdkEvent* event = reinterpret_cast<GdkEvent*>(buttonEvent); + int doubleClickDistance = 250; + int doubleClickTime = 5; + g_object_get(gtk_settings_get_for_screen(gdk_event_get_screen(event)), + "gtk-double-click-distance", &doubleClickDistance, "gtk-double-click-time", &doubleClickTime, nullptr); + + // GTK+ only counts up to triple clicks, but WebCore wants to know about + // quadruple clicks, quintuple clicks, ad infinitum. Here, we replicate the + // GDK logic for counting clicks. + guint32 eventTime = gdk_event_get_time(event); + if (!eventTime) { + // Real events always have a non-zero time, but events synthesized + // by the WTR do not and we must calculate a time manually. This time + // is not calculated in the WTR, because GTK+ does not work well with + // anything other than GDK_CURRENT_TIME on synthesized events. + GTimeVal timeValue; + g_get_current_time(&timeValue); + eventTime = (timeValue.tv_sec * 1000) + (timeValue.tv_usec / 1000); + } + + if ((event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS) + || ((std::abs(buttonEvent->x - previousClickPoint.x()) < doubleClickDistance) + && (std::abs(buttonEvent->y - previousClickPoint.y()) < doubleClickDistance) + && (eventTime - previousClickTime < static_cast<unsigned>(doubleClickTime)) + && (buttonEvent->button == previousClickButton))) + currentClickCount++; + else + currentClickCount = 1; + + double x, y; + gdk_event_get_coords(event, &x, &y); + previousClickPoint = IntPoint(x, y); + previousClickButton = buttonEvent->button; + previousClickTime = eventTime; + + return currentClickCount; + } + +private: + int currentClickCount; + IntPoint previousClickPoint; + unsigned previousClickButton; + int previousClickTime; +}; + typedef HashMap<GtkWidget*, IntRect> WebKitWebViewChildrenMap; +typedef HashMap<uint32_t, GUniquePtr<GdkEvent>> TouchEventsMap; -#if USE(TEXTURE_MAPPER_GL) -void redirectedWindowDamagedCallback(void* data); +struct _WebKitWebViewBasePrivate { + _WebKitWebViewBasePrivate() + : updateViewStateTimer(RunLoop::main(), this, &_WebKitWebViewBasePrivate::updateViewStateTimerFired) +#if USE(REDIRECTED_XCOMPOSITE_WINDOW) + , clearRedirectedWindowSoonTimer(RunLoop::main(), this, &_WebKitWebViewBasePrivate::clearRedirectedWindowSoonTimerFired) +#endif + { + } + + void updateViewStateTimerFired() + { + if (!pageProxy) + return; + pageProxy->viewStateDidChange(viewStateFlagsToUpdate); + viewStateFlagsToUpdate = ViewState::NoFlags; + } + +#if USE(REDIRECTED_XCOMPOSITE_WINDOW) + void clearRedirectedWindowSoonTimerFired() + { + if (redirectedWindow) + redirectedWindow->resize(IntSize()); + } #endif -struct _WebKitWebViewBasePrivate { WebKitWebViewChildrenMap children; - OwnPtr<PageClientImpl> pageClient; + std::unique_ptr<PageClientImpl> pageClient; RefPtr<WebPageProxy> pageProxy; bool shouldForwardNextKeyEvent; - GtkClickCounter clickCounter; + ClickCounter clickCounter; CString tooltipText; IntRect tooltipArea; -#if ENABLE(DRAG_SUPPORT) - GtkDragAndDropHelper dragAndDropHelper; -#endif - DragIcon dragIcon; -#if !GTK_CHECK_VERSION(3, 13, 4) - IntSize resizerSize; -#endif GRefPtr<AtkObject> accessible; - bool needsResizeOnMap; GtkWidget* authenticationDialog; GtkWidget* inspectorView; AttachmentSide inspectorAttachmentSide; unsigned inspectorViewSize; GUniquePtr<GdkEvent> contextMenuEvent; WebContextMenuProxyGtk* activeContextMenuProxy; - WebViewBaseInputMethodFilter inputMethodFilter; - GtkTouchContextHelper touchContext; + InputMethodFilter inputMethodFilter; + KeyBindingTranslator keyBindingTranslator; + TouchEventsMap touchEvents; GtkWindow* toplevelOnScreenWindow; -#if !GTK_CHECK_VERSION(3, 13, 4) - unsigned long toplevelResizeGripVisibilityID; -#endif unsigned long toplevelFocusInEventID; unsigned long toplevelFocusOutEventID; - unsigned long toplevelVisibilityEventID; + unsigned long toplevelWindowStateEventID; + unsigned long toplevelWindowRealizedID; // View State. - bool isInWindowActive : 1; - bool isFocused : 1; - bool isVisible : 1; - bool isWindowVisible : 1; + ViewState::Flags viewState; + ViewState::Flags viewStateFlagsToUpdate; + RunLoop::Timer<WebKitWebViewBasePrivate> updateViewStateTimer; WebKitWebViewBaseDownloadRequestHandler downloadHandler; #if ENABLE(FULLSCREEN_API) bool fullScreenModeActive; WebFullScreenClientGtk fullScreenClient; + GRefPtr<GDBusProxy> screenSaverProxy; + GRefPtr<GCancellable> screenSaverInhibitCancellable; + unsigned screenSaverCookie; #endif -#if USE(TEXTURE_MAPPER_GL) - OwnPtr<RedirectedXCompositeWindow> redirectedWindow; +#if USE(REDIRECTED_XCOMPOSITE_WINDOW) + std::unique_ptr<RedirectedXCompositeWindow> redirectedWindow; + RunLoop::Timer<WebKitWebViewBasePrivate> clearRedirectedWindowSoonTimer; +#endif + +#if ENABLE(DRAG_SUPPORT) + std::unique_ptr<DragAndDropHandler> dragAndDropHandler; +#endif + +#if HAVE(GTK_GESTURES) + std::unique_ptr<GestureController> gestureController; #endif }; WEBKIT_DEFINE_TYPE(WebKitWebViewBase, webkit_web_view_base, GTK_TYPE_CONTAINER) -#if !GTK_CHECK_VERSION(3, 13, 4) -static void webkitWebViewBaseNotifyResizerSize(WebKitWebViewBase* webViewBase) +static void webkitWebViewBaseScheduleUpdateViewState(WebKitWebViewBase* webViewBase, ViewState::Flags flagsToUpdate) { WebKitWebViewBasePrivate* priv = webViewBase->priv; - if (!priv->toplevelOnScreenWindow) + priv->viewStateFlagsToUpdate |= flagsToUpdate; + if (priv->updateViewStateTimer.isActive()) return; - gboolean resizerVisible; - g_object_get(G_OBJECT(priv->toplevelOnScreenWindow), "resize-grip-visible", &resizerVisible, NULL); - - IntSize resizerSize; - if (resizerVisible) { - GdkRectangle resizerRect; - gtk_window_get_resize_grip_area(priv->toplevelOnScreenWindow, &resizerRect); - GdkRectangle allocation; - gtk_widget_get_allocation(GTK_WIDGET(webViewBase), &allocation); - if (gdk_rectangle_intersect(&resizerRect, &allocation, 0)) - resizerSize = IntSize(resizerRect.width, resizerRect.height); - } - - if (resizerSize != priv->resizerSize) { - priv->resizerSize = resizerSize; - priv->pageProxy->setWindowResizerSize(resizerSize); - } + priv->updateViewStateTimer.startOneShot(0); } -static void toplevelWindowResizeGripVisibilityChanged(GObject*, GParamSpec*, WebKitWebViewBase* webViewBase) +static gboolean toplevelWindowFocusInEvent(GtkWidget* widget, GdkEventFocus*, WebKitWebViewBase* webViewBase) { - webkitWebViewBaseNotifyResizerSize(webViewBase); + // Spurious focus in events can occur when the window is hidden. + if (!gtk_widget_get_visible(widget)) + return FALSE; + + WebKitWebViewBasePrivate* priv = webViewBase->priv; + if (priv->viewState & ViewState::WindowIsActive) + return FALSE; + + priv->viewState |= ViewState::WindowIsActive; + webkitWebViewBaseScheduleUpdateViewState(webViewBase, ViewState::WindowIsActive); + + return FALSE; } -#endif -static gboolean toplevelWindowFocusInEvent(GtkWidget* widget, GdkEventFocus*, WebKitWebViewBase* webViewBase) +static gboolean toplevelWindowFocusOutEvent(GtkWidget*, GdkEventFocus*, WebKitWebViewBase* webViewBase) { WebKitWebViewBasePrivate* priv = webViewBase->priv; - if (!priv->isInWindowActive) { - priv->isInWindowActive = true; - priv->pageProxy->viewStateDidChange(ViewState::WindowIsActive); - } + if (!(priv->viewState & ViewState::WindowIsActive)) + return FALSE; + + priv->viewState &= ~ViewState::WindowIsActive; + webkitWebViewBaseScheduleUpdateViewState(webViewBase, ViewState::WindowIsActive); return FALSE; } -static gboolean toplevelWindowFocusOutEvent(GtkWidget* widget, GdkEventFocus*, WebKitWebViewBase* webViewBase) +static gboolean toplevelWindowStateEvent(GtkWidget*, GdkEventWindowState* event, WebKitWebViewBase* webViewBase) { WebKitWebViewBasePrivate* priv = webViewBase->priv; - if (priv->isInWindowActive) { - priv->isInWindowActive = false; - priv->pageProxy->viewStateDidChange(ViewState::WindowIsActive); - } + if (!(event->changed_mask & GDK_WINDOW_STATE_ICONIFIED)) + return FALSE; + + bool visible = !(event->new_window_state & GDK_WINDOW_STATE_ICONIFIED); + if ((visible && priv->viewState & ViewState::IsVisible) || (!visible && !(priv->viewState & ViewState::IsVisible))) + return FALSE; + + if (visible) + priv->viewState |= ViewState::IsVisible; + else + priv->viewState &= ~ViewState::IsVisible; + webkitWebViewBaseScheduleUpdateViewState(webViewBase, ViewState::IsVisible); return FALSE; } -static gboolean toplevelWindowVisibilityEvent(GtkWidget*, GdkEventVisibility* visibilityEvent, WebKitWebViewBase* webViewBase) +static void toplevelWindowRealized(WebKitWebViewBase* webViewBase) { + gtk_widget_realize(GTK_WIDGET(webViewBase)); + WebKitWebViewBasePrivate* priv = webViewBase->priv; - bool isWindowVisible = visibilityEvent->state != GDK_VISIBILITY_FULLY_OBSCURED; - if (priv->isWindowVisible != isWindowVisible) { - priv->isWindowVisible = isWindowVisible; - priv->pageProxy->viewStateDidChange(ViewState::IsVisible); + if (priv->toplevelWindowRealizedID) { + g_signal_handler_disconnect(priv->toplevelOnScreenWindow, priv->toplevelWindowRealizedID); + priv->toplevelWindowRealizedID = 0; } - - return FALSE; } static void webkitWebViewBaseSetToplevelOnScreenWindow(WebKitWebViewBase* webViewBase, GtkWindow* window) @@ -217,12 +302,6 @@ static void webkitWebViewBaseSetToplevelOnScreenWindow(WebKitWebViewBase* webVie if (priv->toplevelOnScreenWindow == window) return; -#if !GTK_CHECK_VERSION(3, 13, 4) - if (priv->toplevelResizeGripVisibilityID) { - g_signal_handler_disconnect(priv->toplevelOnScreenWindow, priv->toplevelResizeGripVisibilityID); - priv->toplevelResizeGripVisibilityID = 0; - } -#endif if (priv->toplevelFocusInEventID) { g_signal_handler_disconnect(priv->toplevelOnScreenWindow, priv->toplevelFocusInEventID); priv->toplevelFocusInEventID = 0; @@ -231,36 +310,70 @@ static void webkitWebViewBaseSetToplevelOnScreenWindow(WebKitWebViewBase* webVie g_signal_handler_disconnect(priv->toplevelOnScreenWindow, priv->toplevelFocusOutEventID); priv->toplevelFocusOutEventID = 0; } - if (priv->toplevelVisibilityEventID) { - g_signal_handler_disconnect(priv->toplevelOnScreenWindow, priv->toplevelVisibilityEventID); - priv->toplevelVisibilityEventID = 0; + if (priv->toplevelWindowStateEventID) { + g_signal_handler_disconnect(priv->toplevelOnScreenWindow, priv->toplevelWindowStateEventID); + priv->toplevelWindowStateEventID = 0; + } + if (priv->toplevelWindowRealizedID) { + g_signal_handler_disconnect(priv->toplevelOnScreenWindow, priv->toplevelWindowRealizedID); + priv->toplevelWindowRealizedID = 0; } priv->toplevelOnScreenWindow = window; - priv->pageProxy->viewStateDidChange(ViewState::IsInWindow); - if (!priv->toplevelOnScreenWindow) - return; -#if !GTK_CHECK_VERSION(3, 13, 4) - webkitWebViewBaseNotifyResizerSize(webViewBase); + if (!priv->toplevelOnScreenWindow) { + ViewState::Flags flagsToUpdate = 0; + if (priv->viewState & ViewState::IsInWindow) { + priv->viewState &= ~ViewState::IsInWindow; + flagsToUpdate |= ViewState::IsInWindow; + } + if (priv->viewState & ViewState::WindowIsActive) { + priv->viewState &= ~ViewState::WindowIsActive; + flagsToUpdate |= ViewState::IsInWindow; + } + if (flagsToUpdate) + webkitWebViewBaseScheduleUpdateViewState(webViewBase, flagsToUpdate); + + return; + } - priv->toplevelResizeGripVisibilityID = - g_signal_connect(priv->toplevelOnScreenWindow, "notify::resize-grip-visible", - G_CALLBACK(toplevelWindowResizeGripVisibilityChanged), webViewBase); -#endif priv->toplevelFocusInEventID = g_signal_connect(priv->toplevelOnScreenWindow, "focus-in-event", G_CALLBACK(toplevelWindowFocusInEvent), webViewBase); priv->toplevelFocusOutEventID = g_signal_connect(priv->toplevelOnScreenWindow, "focus-out-event", G_CALLBACK(toplevelWindowFocusOutEvent), webViewBase); - priv->toplevelVisibilityEventID = - g_signal_connect(priv->toplevelOnScreenWindow, "visibility-notify-event", - G_CALLBACK(toplevelWindowVisibilityEvent), webViewBase); + priv->toplevelWindowStateEventID = + g_signal_connect(priv->toplevelOnScreenWindow, "window-state-event", G_CALLBACK(toplevelWindowStateEvent), webViewBase); + + if (gtk_widget_get_realized(GTK_WIDGET(window))) + gtk_widget_realize(GTK_WIDGET(webViewBase)); + else + priv->toplevelWindowRealizedID = g_signal_connect_swapped(window, "realize", G_CALLBACK(toplevelWindowRealized), webViewBase); } static void webkitWebViewBaseRealize(GtkWidget* widget) { + WebKitWebViewBase* webView = WEBKIT_WEB_VIEW_BASE(widget); + WebKitWebViewBasePrivate* priv = webView->priv; + +#if USE(REDIRECTED_XCOMPOSITE_WINDOW) + if (PlatformDisplay::sharedDisplay().type() == PlatformDisplay::Type::X11) { + ASSERT(!priv->redirectedWindow); + priv->redirectedWindow = RedirectedXCompositeWindow::create( + gtk_widget_get_parent_window(widget), + [webView] { + DrawingAreaProxyImpl* drawingArea = static_cast<DrawingAreaProxyImpl*>(webView->priv->pageProxy->drawingArea()); + if (drawingArea && drawingArea->isInAcceleratedCompositingMode()) + gtk_widget_queue_draw(GTK_WIDGET(webView)); + }); + if (priv->redirectedWindow) { + if (DrawingAreaProxyImpl* drawingArea = static_cast<DrawingAreaProxyImpl*>(priv->pageProxy->drawingArea())) + drawingArea->setNativeSurfaceHandleForCompositing(priv->redirectedWindow->windowID()); + } + } +#endif + gtk_widget_set_realized(widget, TRUE); GtkAllocation allocation; @@ -281,6 +394,8 @@ static void webkitWebViewBaseRealize(GtkWidget* widget) | GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK | GDK_POINTER_MOTION_MASK + | GDK_ENTER_NOTIFY_MASK + | GDK_LEAVE_NOTIFY_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_BUTTON_MOTION_MASK @@ -295,12 +410,29 @@ static void webkitWebViewBaseRealize(GtkWidget* widget) gtk_widget_set_window(widget, window); gdk_window_set_user_data(window, widget); +#if USE(TEXTURE_MAPPER) && PLATFORM(X11) && !USE(REDIRECTED_XCOMPOSITE_WINDOW) + if (DrawingAreaProxyImpl* drawingArea = static_cast<DrawingAreaProxyImpl*>(priv->pageProxy->drawingArea())) + drawingArea->setNativeSurfaceHandleForCompositing(GDK_WINDOW_XID(window)); +#endif + gtk_style_context_set_background(gtk_widget_get_style_context(widget), window); + gtk_im_context_set_client_window(priv->inputMethodFilter.context(), window); +} + +static void webkitWebViewBaseUnrealize(GtkWidget* widget) +{ WebKitWebViewBase* webView = WEBKIT_WEB_VIEW_BASE(widget); - GtkWidget* toplevel = gtk_widget_get_toplevel(widget); - if (widgetIsOnscreenToplevelWindow(toplevel)) - webkitWebViewBaseSetToplevelOnScreenWindow(webView, GTK_WINDOW(toplevel)); +#if USE(TEXTURE_MAPPER) && PLATFORM(X11) + if (DrawingAreaProxyImpl* drawingArea = static_cast<DrawingAreaProxyImpl*>(webView->priv->pageProxy->drawingArea())) + drawingArea->destroyNativeSurfaceHandleForCompositing(); +#endif +#if USE(REDIRECTED_XCOMPOSITE_WINDOW) + webView->priv->redirectedWindow = nullptr; +#endif + gtk_im_context_set_client_window(webView->priv->inputMethodFilter.context(), nullptr); + + GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->unrealize(widget); } static bool webkitWebViewChildIsInternalWidget(WebKitWebViewBase* webViewBase, GtkWidget* widget) @@ -406,6 +538,7 @@ void webkitWebViewBaseChildMoveResize(WebKitWebViewBase* webView, GtkWidget* chi static void webkitWebViewBaseDispose(GObject* gobject) { WebKitWebViewBase* webView = WEBKIT_WEB_VIEW_BASE(gobject); + g_cancellable_cancel(webView->priv->screenSaverInhibitCancellable.get()); webkitWebViewBaseSetToplevelOnScreenWindow(webView, nullptr); webView->priv->pageProxy->close(); G_OBJECT_CLASS(webkit_web_view_base_parent_class)->dispose(gobject); @@ -417,31 +550,20 @@ static void webkitWebViewBaseConstructed(GObject* object) GtkWidget* viewWidget = GTK_WIDGET(object); gtk_widget_set_can_focus(viewWidget, TRUE); - gtk_drag_dest_set(viewWidget, static_cast<GtkDestDefaults>(0), 0, 0, - static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_PRIVATE)); - gtk_drag_dest_set_target_list(viewWidget, PasteboardHelper::defaultPasteboardHelper()->targetList()); + gtk_drag_dest_set(viewWidget, static_cast<GtkDestDefaults>(0), nullptr, 0, + static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_PRIVATE)); + gtk_drag_dest_set_target_list(viewWidget, PasteboardHelper::singleton().targetList()); WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(object)->priv; - priv->pageClient = PageClientImpl::create(viewWidget); -#if ENABLE(DRAG_SUPPORT) - priv->dragAndDropHelper.setWidget(viewWidget); -#endif - -#if USE(TEXTURE_MAPPER_GL) && defined(GDK_WINDOWING_X11) - GdkDisplay* display = gdk_display_manager_get_default_display(gdk_display_manager_get()); - if (GDK_IS_X11_DISPLAY(display)) { - priv->redirectedWindow = RedirectedXCompositeWindow::create(IntSize(1, 1), RedirectedXCompositeWindow::DoNotCreateGLContext); - if (priv->redirectedWindow) - priv->redirectedWindow->setDamageNotifyCallback(redirectedWindowDamagedCallback, object); - } -#endif - + priv->pageClient = std::make_unique<PageClientImpl>(viewWidget); priv->authenticationDialog = 0; } -#if USE(TEXTURE_MAPPER_GL) static bool webkitWebViewRenderAcceleratedCompositingResults(WebKitWebViewBase* webViewBase, DrawingAreaProxyImpl* drawingArea, cairo_t* cr, GdkRectangle* clipRect) { +#if USE(TEXTURE_MAPPER) && USE(REDIRECTED_XCOMPOSITE_WINDOW) + ASSERT(drawingArea); + if (!drawingArea->isInAcceleratedCompositingMode()) return false; @@ -451,13 +573,26 @@ static bool webkitWebViewRenderAcceleratedCompositingResults(WebKitWebViewBase* if (!priv->redirectedWindow) return false; - cairo_rectangle(cr, clipRect->x, clipRect->y, clipRect->width, clipRect->height); - cairo_surface_t* surface = priv->redirectedWindow->cairoSurfaceForWidget(GTK_WIDGET(webViewBase)); - cairo_set_source_surface(cr, surface, 0, 0); - cairo_fill(cr); + priv->redirectedWindow->setDeviceScaleFactor(webViewBase->priv->pageProxy->deviceScaleFactor()); + priv->redirectedWindow->resize(drawingArea->size()); + + if (cairo_surface_t* surface = priv->redirectedWindow->surface()) { + cairo_save(cr); + cairo_rectangle(cr, clipRect->x, clipRect->y, clipRect->width, clipRect->height); + cairo_set_source_surface(cr, surface, 0, 0); + cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); + cairo_fill(cr); + cairo_restore(cr); + } + return true; -} +#else + UNUSED_PARAM(webViewBase); + UNUSED_PARAM(cr); + UNUSED_PARAM(clipRect); + return false; #endif +} static gboolean webkitWebViewBaseDraw(GtkWidget* widget, cairo_t* cr) { @@ -470,13 +605,10 @@ static gboolean webkitWebViewBaseDraw(GtkWidget* widget, cairo_t* cr) if (!gdk_cairo_get_clip_rectangle(cr, &clipRect)) return FALSE; -#if USE(TEXTURE_MAPPER_GL) - if (webkitWebViewRenderAcceleratedCompositingResults(webViewBase, drawingArea, cr, &clipRect)) - return GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->draw(widget, cr); -#endif - - WebCore::Region unpaintedRegion; // This is simply unused. - drawingArea->paint(cr, clipRect, unpaintedRegion); + if (!webkitWebViewRenderAcceleratedCompositingResults(webViewBase, drawingArea, cr, &clipRect)) { + WebCore::Region unpaintedRegion; // This is simply unused. + drawingArea->paint(cr, clipRect, unpaintedRegion); + } if (webViewBase->priv->authenticationDialog) { cairo_set_operator(cr, CAIRO_OPERATOR_OVER); @@ -505,8 +637,11 @@ static void webkitWebViewBaseChildAllocate(GtkWidget* child, gpointer userData) priv->children.set(child, IntRect()); } -static void resizeWebKitWebViewBaseFromAllocation(WebKitWebViewBase* webViewBase, GtkAllocation* allocation, bool sizeChanged) +static void webkitWebViewBaseSizeAllocate(GtkWidget* widget, GtkAllocation* allocation) { + GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->size_allocate(widget, allocation); + + WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget); gtk_container_foreach(GTK_CONTAINER(webViewBase), webkitWebViewBaseChildAllocate, webViewBase); IntRect viewRect(allocation->x, allocation->y, allocation->width, allocation->height); @@ -514,7 +649,7 @@ static void resizeWebKitWebViewBaseFromAllocation(WebKitWebViewBase* webViewBase if (priv->inspectorView) { GtkAllocation childAllocation = viewRect; - if (priv->inspectorAttachmentSide == AttachmentSideBottom) { + if (priv->inspectorAttachmentSide == AttachmentSide::Bottom) { int inspectorViewHeight = std::min(static_cast<int>(priv->inspectorViewSize), allocation->height); childAllocation.x = 0; childAllocation.y = allocation->height - inspectorViewHeight; @@ -547,33 +682,17 @@ static void resizeWebKitWebViewBaseFromAllocation(WebKitWebViewBase* webViewBase gtk_widget_size_allocate(priv->authenticationDialog, &childAllocation); } -#if USE(TEXTURE_MAPPER_GL) - if (sizeChanged && webViewBase->priv->redirectedWindow) - webViewBase->priv->redirectedWindow->resize(viewRect.size()); -#endif + DrawingAreaProxyImpl* drawingArea = static_cast<DrawingAreaProxyImpl*>(priv->pageProxy->drawingArea()); + if (!drawingArea) + return; - if (priv->pageProxy->drawingArea()) - priv->pageProxy->drawingArea()->setSize(viewRect.size(), IntSize(), IntSize()); -#if !GTK_CHECK_VERSION(3, 13, 4) - webkitWebViewBaseNotifyResizerSize(webViewBase); +#if USE(REDIRECTED_XCOMPOSITE_WINDOW) + if (priv->redirectedWindow && drawingArea->isInAcceleratedCompositingMode()) + priv->redirectedWindow->resize(viewRect.size()); #endif -} - -static void webkitWebViewBaseSizeAllocate(GtkWidget* widget, GtkAllocation* allocation) -{ - bool sizeChanged = gtk_widget_get_allocated_width(widget) != allocation->width - || gtk_widget_get_allocated_height(widget) != allocation->height; - - GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->size_allocate(widget, allocation); - - WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget); - if (sizeChanged && !gtk_widget_get_mapped(widget)) { - webViewBase->priv->needsResizeOnMap = true; - return; - } - resizeWebKitWebViewBaseFromAllocation(webViewBase, allocation, sizeChanged); + drawingArea->setSize(viewRect.size(), IntSize(), IntSize()); } static void webkitWebViewBaseMap(GtkWidget* widget) @@ -582,29 +701,33 @@ static void webkitWebViewBaseMap(GtkWidget* widget) WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget); WebKitWebViewBasePrivate* priv = webViewBase->priv; - if (!priv->isVisible) { - priv->isVisible = true; - priv->pageProxy->viewStateDidChange(ViewState::IsVisible); + ViewState::Flags flagsToUpdate = 0; + if (!(priv->viewState & ViewState::IsVisible)) + flagsToUpdate |= ViewState::IsVisible; + if (priv->toplevelOnScreenWindow) { + if (!(priv->viewState & ViewState::IsInWindow)) + flagsToUpdate |= ViewState::IsInWindow; + if (gtk_window_is_active(GTK_WINDOW(priv->toplevelOnScreenWindow)) && !(priv->viewState & ViewState::WindowIsActive)) + flagsToUpdate |= ViewState::WindowIsActive; } - - if (!priv->needsResizeOnMap) + if (!flagsToUpdate) return; - GtkAllocation allocation; - gtk_widget_get_allocation(widget, &allocation); - resizeWebKitWebViewBaseFromAllocation(webViewBase, &allocation, true /* sizeChanged */); - priv->needsResizeOnMap = false; + priv->viewState |= flagsToUpdate; + webkitWebViewBaseScheduleUpdateViewState(webViewBase, flagsToUpdate); } static void webkitWebViewBaseUnmap(GtkWidget* widget) { GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->unmap(widget); - WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv; - if (priv->isVisible) { - priv->isVisible = false; - priv->pageProxy->viewStateDidChange(ViewState::IsVisible); - } + WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget); + WebKitWebViewBasePrivate* priv = webViewBase->priv; + if (!(priv->viewState & ViewState::IsVisible)) + return; + + priv->viewState &= ~ViewState::IsVisible; + webkitWebViewBaseScheduleUpdateViewState(webViewBase, ViewState::IsVisible); } static gboolean webkitWebViewBaseFocusInEvent(GtkWidget* widget, GdkEventFocus* event) @@ -655,7 +778,12 @@ static gboolean webkitWebViewBaseKeyPressEvent(GtkWidget* widget, GdkEventKey* e priv->shouldForwardNextKeyEvent = FALSE; return GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->key_press_event(widget, event); } - priv->inputMethodFilter.filterKeyEvent(event); + + priv->inputMethodFilter.filterKeyEvent(event, [priv, event](const WebCore::CompositionResults& compositionResults, InputMethodFilter::EventFakedForComposition faked) { + priv->pageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(reinterpret_cast<GdkEvent*>(event), compositionResults, faked, + !compositionResults.compositionUpdated() ? priv->keyBindingTranslator.commandsForKeyEvent(event) : Vector<String>())); + }); + return TRUE; } @@ -668,7 +796,11 @@ static gboolean webkitWebViewBaseKeyReleaseEvent(GtkWidget* widget, GdkEventKey* priv->shouldForwardNextKeyEvent = FALSE; return GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->key_release_event(widget, event); } - priv->inputMethodFilter.filterKeyEvent(event); + + priv->inputMethodFilter.filterKeyEvent(event, [priv, event](const WebCore::CompositionResults& compositionResults, InputMethodFilter::EventFakedForComposition faked) { + priv->pageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(reinterpret_cast<GdkEvent*>(event), compositionResults, faked, { })); + }); + return TRUE; } @@ -684,14 +816,21 @@ static gboolean webkitWebViewBaseButtonPressEvent(GtkWidget* widget, GdkEventBut priv->inputMethodFilter.notifyMouseButtonPress(); - if (!priv->clickCounter.shouldProcessButtonEvent(buttonEvent)) + // For double and triple clicks GDK sends both a normal button press event + // and a specific type (like GDK_2BUTTON_PRESS). If we detect a special press + // coming up, ignore this event as it certainly generated the double or triple + // click. The consequence of not eating this event is two DOM button press events + // are generated. + GUniquePtr<GdkEvent> nextEvent(gdk_event_peek()); + if (nextEvent && (nextEvent->any.type == GDK_2BUTTON_PRESS || nextEvent->any.type == GDK_3BUTTON_PRESS)) return TRUE; // If it's a right click event save it as a possible context menu event. if (buttonEvent->button == 3) priv->contextMenuEvent.reset(gdk_event_copy(reinterpret_cast<GdkEvent*>(buttonEvent))); + priv->pageProxy->handleMouseEvent(NativeWebMouseEvent(reinterpret_cast<GdkEvent*>(buttonEvent), - priv->clickCounter.clickCountForGdkButtonEvent(widget, buttonEvent))); + priv->clickCounter.currentClickCountForGdkButtonEvent(buttonEvent))); return TRUE; } @@ -728,27 +867,162 @@ static gboolean webkitWebViewBaseMotionNotifyEvent(GtkWidget* widget, GdkEventMo WebKitWebViewBasePrivate* priv = webViewBase->priv; if (priv->authenticationDialog) - return TRUE; + return GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->motion_notify_event(widget, event); priv->pageProxy->handleMouseEvent(NativeWebMouseEvent(reinterpret_cast<GdkEvent*>(event), 0 /* currentClickCount */)); - return TRUE; + return FALSE; +} + +static gboolean webkitWebViewBaseCrossingNotifyEvent(GtkWidget* widget, GdkEventCrossing* crosssingEvent) +{ + WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget); + WebKitWebViewBasePrivate* priv = webViewBase->priv; + + if (priv->authenticationDialog) + return FALSE; + + // In the case of crossing events, it's very important the actual coordinates the WebProcess receives, because once the mouse leaves + // the web view, the WebProcess won't receive more events until the mouse enters again in the web view. So, if the coordinates of the leave + // event are not accurate, the WebProcess might not know the mouse left the view. This can happen because of double to integer conversion, + // if the coordinates of the leave event are for example (25.2, -0.9), the WebProcess will receive (25, 0) and any hit test will succeed + // because those coordinates are inside the web view. + GtkAllocation allocation; + gtk_widget_get_allocation(widget, &allocation); + double width = allocation.width; + double height = allocation.height; + double x = crosssingEvent->x; + double y = crosssingEvent->y; + if (x < 0 && x > -1) + x = -1; + else if (x >= width && x < width + 1) + x = width + 1; + if (y < 0 && y > -1) + y = -1; + else if (y >= height && y < height + 1) + y = height + 1; + + GdkEvent* event = reinterpret_cast<GdkEvent*>(crosssingEvent); + GUniquePtr<GdkEvent> copiedEvent; + if (x != crosssingEvent->x || y != crosssingEvent->y) { + copiedEvent.reset(gdk_event_copy(event)); + copiedEvent->crossing.x = x; + copiedEvent->crossing.y = y; + } + + priv->pageProxy->handleMouseEvent(NativeWebMouseEvent(copiedEvent ? copiedEvent.get() : event, 0 /* currentClickCount */)); + + return FALSE; +} + +#if ENABLE(TOUCH_EVENTS) +static void appendTouchEvent(Vector<WebPlatformTouchPoint>& touchPoints, const GdkEvent* event, WebPlatformTouchPoint::TouchPointState state) +{ + gdouble x, y; + gdk_event_get_coords(event, &x, &y); + + gdouble xRoot, yRoot; + gdk_event_get_root_coords(event, &xRoot, &yRoot); + + uint32_t identifier = GPOINTER_TO_UINT(gdk_event_get_event_sequence(event)); + touchPoints.uncheckedAppend(WebPlatformTouchPoint(identifier, state, IntPoint(xRoot, yRoot), IntPoint(x, y))); +} + +static inline WebPlatformTouchPoint::TouchPointState touchPointStateForEvents(const GdkEvent* current, const GdkEvent* event) +{ + if (gdk_event_get_event_sequence(current) != gdk_event_get_event_sequence(event)) + return WebPlatformTouchPoint::TouchStationary; + + switch (current->type) { + case GDK_TOUCH_UPDATE: + return WebPlatformTouchPoint::TouchMoved; + case GDK_TOUCH_BEGIN: + return WebPlatformTouchPoint::TouchPressed; + case GDK_TOUCH_END: + return WebPlatformTouchPoint::TouchReleased; + default: + return WebPlatformTouchPoint::TouchStationary; + } +} + +static void webkitWebViewBaseGetTouchPointsForEvent(WebKitWebViewBase* webViewBase, GdkEvent* event, Vector<WebPlatformTouchPoint>& touchPoints) +{ + WebKitWebViewBasePrivate* priv = webViewBase->priv; + touchPoints.reserveInitialCapacity(event->type == GDK_TOUCH_END ? priv->touchEvents.size() + 1 : priv->touchEvents.size()); + + for (const auto& it : priv->touchEvents) + appendTouchEvent(touchPoints, it.value.get(), touchPointStateForEvents(it.value.get(), event)); + + // Touch was already removed from the TouchEventsMap, add it here. + if (event->type == GDK_TOUCH_END) + appendTouchEvent(touchPoints, event, WebPlatformTouchPoint::TouchReleased); } static gboolean webkitWebViewBaseTouchEvent(GtkWidget* widget, GdkEventTouch* event) { - WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv; + WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget); + WebKitWebViewBasePrivate* priv = webViewBase->priv; if (priv->authenticationDialog) return TRUE; - priv->touchContext.handleEvent(reinterpret_cast<GdkEvent*>(event)); - priv->pageProxy->handleTouchEvent(NativeWebTouchEvent(reinterpret_cast<GdkEvent*>(event), priv->touchContext)); + GdkEvent* touchEvent = reinterpret_cast<GdkEvent*>(event); + uint32_t sequence = GPOINTER_TO_UINT(gdk_event_get_event_sequence(touchEvent)); + +#if HAVE(GTK_GESTURES) + GestureController& gestureController = webkitWebViewBaseGestureController(webViewBase); + if (gestureController.isProcessingGestures()) { + // If we are already processing gestures is because the WebProcess didn't handle the + // BEGIN touch event, so pass subsequent events to the GestureController. + gestureController.handleEvent(touchEvent); + // Remove the gesture event sequence from the handled touch events + // list to avoid the gesure sequence and a touch sequence of same + // ID to conflict. + priv->touchEvents.remove(sequence); + return TRUE; + } +#endif + + switch (touchEvent->type) { + case GDK_TOUCH_BEGIN: { + ASSERT(!priv->touchEvents.contains(sequence)); + GUniquePtr<GdkEvent> event(gdk_event_copy(touchEvent)); + priv->touchEvents.add(sequence, WTFMove(event)); + break; + } + case GDK_TOUCH_UPDATE: { + auto it = priv->touchEvents.find(sequence); + ASSERT(it != priv->touchEvents.end()); + it->value.reset(gdk_event_copy(touchEvent)); + break; + } + case GDK_TOUCH_END: + ASSERT(priv->touchEvents.contains(sequence)); + priv->touchEvents.remove(sequence); + break; + default: + break; + } + + Vector<WebPlatformTouchPoint> touchPoints; + webkitWebViewBaseGetTouchPointsForEvent(webViewBase, touchEvent, touchPoints); + priv->pageProxy->handleTouchEvent(NativeWebTouchEvent(reinterpret_cast<GdkEvent*>(event), WTFMove(touchPoints))); return TRUE; } +#endif // ENABLE(TOUCH_EVENTS) + +#if HAVE(GTK_GESTURES) +GestureController& webkitWebViewBaseGestureController(WebKitWebViewBase* webViewBase) +{ + WebKitWebViewBasePrivate* priv = webViewBase->priv; + if (!priv->gestureController) + priv->gestureController = std::make_unique<GestureController>(*priv->pageProxy); + return *priv->gestureController; +} +#endif -static gboolean webkitWebViewBaseQueryTooltip(GtkWidget* widget, gint x, gint y, gboolean keyboardMode, GtkTooltip* tooltip) +static gboolean webkitWebViewBaseQueryTooltip(GtkWidget* widget, gint /* x */, gint /* y */, gboolean keyboardMode, GtkTooltip* tooltip) { WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv; @@ -772,39 +1046,23 @@ static gboolean webkitWebViewBaseQueryTooltip(GtkWidget* widget, gint x, gint y, } #if ENABLE(DRAG_SUPPORT) -static void webkitWebViewBaseDragDataGet(GtkWidget* widget, GdkDragContext* context, GtkSelectionData* selectionData, guint info, guint time) +static void webkitWebViewBaseDragDataGet(GtkWidget* widget, GdkDragContext* context, GtkSelectionData* selectionData, guint info, guint /* time */) { - WEBKIT_WEB_VIEW_BASE(widget)->priv->dragAndDropHelper.handleGetDragData(context, selectionData, info); + WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv; + ASSERT(priv->dragAndDropHandler); + priv->dragAndDropHandler->fillDragData(context, selectionData, info); } static void webkitWebViewBaseDragEnd(GtkWidget* widget, GdkDragContext* context) { - WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget); - if (!webViewBase->priv->dragAndDropHelper.handleDragEnd(context)) - return; - - GdkDevice* device = gdk_drag_context_get_device(context); - int x = 0, y = 0; - gdk_device_get_window_at_position(device, &x, &y); - int xRoot = 0, yRoot = 0; - gdk_device_get_position(device, 0, &xRoot, &yRoot); - webViewBase->priv->pageProxy->dragEnded(IntPoint(x, y), IntPoint(xRoot, yRoot), - gdkDragActionToDragOperation(gdk_drag_context_get_selected_action(context))); + WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv; + ASSERT(priv->dragAndDropHandler); + priv->dragAndDropHandler->finishDrag(context); } -static void webkitWebViewBaseDragDataReceived(GtkWidget* widget, GdkDragContext* context, gint x, gint y, GtkSelectionData* selectionData, guint info, guint time) +static void webkitWebViewBaseDragDataReceived(GtkWidget* widget, GdkDragContext* context, gint /* x */, gint /* y */, GtkSelectionData* selectionData, guint info, guint time) { - WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget); - IntPoint position; - DataObjectGtk* dataObject = webViewBase->priv->dragAndDropHelper.handleDragDataReceived(context, selectionData, info, position); - if (!dataObject) - return; - - DragData dragData(dataObject, position, convertWidgetPointToScreenPoint(widget, position), gdkDragActionToDragOperation(gdk_drag_context_get_actions(context))); - webViewBase->priv->pageProxy->resetDragOperation(); - webViewBase->priv->pageProxy->dragEntered(dragData); - DragOperation operation = webViewBase->priv->pageProxy->dragSession().operation; - gdk_drag_status(context, dragOperationToSingleGdkDragAction(operation), time); + webkitWebViewBaseDragAndDropHandler(WEBKIT_WEB_VIEW_BASE(widget)).dragEntered(context, selectionData, info, time); } #endif // ENABLE(DRAG_SUPPORT) @@ -839,57 +1097,38 @@ static AtkObject* webkitWebViewBaseGetAccessible(GtkWidget* widget) #if ENABLE(DRAG_SUPPORT) static gboolean webkitWebViewBaseDragMotion(GtkWidget* widget, GdkDragContext* context, gint x, gint y, guint time) { - WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget); - IntPoint position(x, y); - DataObjectGtk* dataObject = webViewBase->priv->dragAndDropHelper.handleDragMotion(context, position, time); - if (!dataObject) - return TRUE; - - DragData dragData(dataObject, position, convertWidgetPointToScreenPoint(widget, position), gdkDragActionToDragOperation(gdk_drag_context_get_actions(context))); - webViewBase->priv->pageProxy->dragUpdated(dragData); - DragOperation operation = webViewBase->priv->pageProxy->dragSession().operation; - gdk_drag_status(context, dragOperationToSingleGdkDragAction(operation), time); + webkitWebViewBaseDragAndDropHandler(WEBKIT_WEB_VIEW_BASE(widget)).dragMotion(context, IntPoint(x, y), time); return TRUE; } -static void dragExitedCallback(GtkWidget* widget, DragData& dragData, bool dropHappened) +static void webkitWebViewBaseDragLeave(GtkWidget* widget, GdkDragContext* context, guint /* time */) { - // Don't call dragExited if we have just received a drag-drop signal. This - // happens in the case of a successful drop onto the view. - if (dropHappened) - return; - - WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget); - webViewBase->priv->pageProxy->dragExited(dragData); - webViewBase->priv->pageProxy->resetDragOperation(); -} - -static void webkitWebViewBaseDragLeave(GtkWidget* widget, GdkDragContext* context, guint time) -{ - WEBKIT_WEB_VIEW_BASE(widget)->priv->dragAndDropHelper.handleDragLeave(context, dragExitedCallback); + WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv; + ASSERT(priv->dragAndDropHandler); + priv->dragAndDropHandler->dragLeave(context); } static gboolean webkitWebViewBaseDragDrop(GtkWidget* widget, GdkDragContext* context, gint x, gint y, guint time) { - WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget); - DataObjectGtk* dataObject = webViewBase->priv->dragAndDropHelper.handleDragDrop(context); - if (!dataObject) - return FALSE; - - IntPoint position(x, y); - DragData dragData(dataObject, position, convertWidgetPointToScreenPoint(widget, position), gdkDragActionToDragOperation(gdk_drag_context_get_actions(context))); - SandboxExtension::Handle handle; - SandboxExtension::HandleArray sandboxExtensionForUpload; - webViewBase->priv->pageProxy->performDrag(dragData, String(), handle, sandboxExtensionForUpload); - gtk_drag_finish(context, TRUE, FALSE, time); - return TRUE; + WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv; + ASSERT(priv->dragAndDropHandler); + return priv->dragAndDropHandler->drop(context, IntPoint(x, y), time); } #endif // ENABLE(DRAG_SUPPORT) -static void webkitWebViewBaseParentSet(GtkWidget* widget, GtkWidget* oldParent) +static void webkitWebViewBaseHierarchyChanged(GtkWidget* widget, GtkWidget* oldToplevel) { - if (!gtk_widget_get_parent(widget)) - webkitWebViewBaseSetToplevelOnScreenWindow(WEBKIT_WEB_VIEW_BASE(widget), 0); + WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv; + if (widgetIsOnscreenToplevelWindow(oldToplevel) && GTK_WINDOW(oldToplevel) == priv->toplevelOnScreenWindow) { + webkitWebViewBaseSetToplevelOnScreenWindow(WEBKIT_WEB_VIEW_BASE(widget), nullptr); + return; + } + + if (!oldToplevel) { + GtkWidget* toplevel = gtk_widget_get_toplevel(widget); + if (widgetIsOnscreenToplevelWindow(toplevel)) + webkitWebViewBaseSetToplevelOnScreenWindow(WEBKIT_WEB_VIEW_BASE(widget), GTK_WINDOW(toplevel)); + } } static gboolean webkitWebViewBaseFocus(GtkWidget* widget, GtkDirectionType direction) @@ -919,6 +1158,7 @@ static void webkit_web_view_base_class_init(WebKitWebViewBaseClass* webkitWebVie { GtkWidgetClass* widgetClass = GTK_WIDGET_CLASS(webkitWebViewBaseClass); widgetClass->realize = webkitWebViewBaseRealize; + widgetClass->unrealize = webkitWebViewBaseUnrealize; widgetClass->draw = webkitWebViewBaseDraw; widgetClass->size_allocate = webkitWebViewBaseSizeAllocate; widgetClass->map = webkitWebViewBaseMap; @@ -932,7 +1172,11 @@ static void webkit_web_view_base_class_init(WebKitWebViewBaseClass* webkitWebVie widgetClass->button_release_event = webkitWebViewBaseButtonReleaseEvent; widgetClass->scroll_event = webkitWebViewBaseScrollEvent; widgetClass->motion_notify_event = webkitWebViewBaseMotionNotifyEvent; + widgetClass->enter_notify_event = webkitWebViewBaseCrossingNotifyEvent; + widgetClass->leave_notify_event = webkitWebViewBaseCrossingNotifyEvent; +#if ENABLE(TOUCH_EVENTS) widgetClass->touch_event = webkitWebViewBaseTouchEvent; +#endif widgetClass->query_tooltip = webkitWebViewBaseQueryTooltip; #if ENABLE(DRAG_SUPPORT) widgetClass->drag_end = webkitWebViewBaseDragEnd; @@ -943,7 +1187,7 @@ static void webkit_web_view_base_class_init(WebKitWebViewBaseClass* webkitWebVie widgetClass->drag_data_received = webkitWebViewBaseDragDataReceived; #endif // ENABLE(DRAG_SUPPORT) widgetClass->get_accessible = webkitWebViewBaseGetAccessible; - widgetClass->parent_set = webkitWebViewBaseParentSet; + widgetClass->hierarchy_changed = webkitWebViewBaseHierarchyChanged; widgetClass->destroy = webkitWebViewBaseDestroy; GObjectClass* gobjectClass = G_OBJECT_CLASS(webkitWebViewBaseClass); @@ -954,12 +1198,17 @@ static void webkit_web_view_base_class_init(WebKitWebViewBaseClass* webkitWebVie containerClass->add = webkitWebViewBaseContainerAdd; containerClass->remove = webkitWebViewBaseContainerRemove; containerClass->forall = webkitWebViewBaseContainerForall; + + // Before creating a WebKitWebViewBasePriv we need to be sure that WebKit is started. + // Usually starting a context triggers InitializeWebKit2, but in case + // we create a view without asking before for a default_context we get a crash. + WebKit::InitializeWebKit2(); } -WebKitWebViewBase* webkitWebViewBaseCreate(WebContext* context, WebPageGroup* pageGroup, WebPageProxy* relatedPage) +WebKitWebViewBase* webkitWebViewBaseCreate(const API::PageConfiguration& configuration) { - WebKitWebViewBase* webkitWebViewBase = WEBKIT_WEB_VIEW_BASE(g_object_new(WEBKIT_TYPE_WEB_VIEW_BASE, NULL)); - webkitWebViewBaseCreateWebPage(webkitWebViewBase, context, pageGroup, relatedPage); + WebKitWebViewBase* webkitWebViewBase = WEBKIT_WEB_VIEW_BASE(g_object_new(WEBKIT_TYPE_WEB_VIEW_BASE, nullptr)); + webkitWebViewBaseCreateWebPage(webkitWebViewBase, configuration.copy()); return webkitWebViewBase; } @@ -973,51 +1222,31 @@ WebPageProxy* webkitWebViewBaseGetPage(WebKitWebViewBase* webkitWebViewBase) return webkitWebViewBase->priv->pageProxy.get(); } -void webkitWebViewBaseUpdatePreferences(WebKitWebViewBase* webkitWebViewBase) -{ - WebKitWebViewBasePrivate* priv = webkitWebViewBase->priv; - -#if USE(TEXTURE_MAPPER_GL) - if (priv->redirectedWindow) - return; -#endif - - priv->pageProxy->pageGroup().preferences()->setAcceleratedCompositingEnabled(false); -} - #if HAVE(GTK_SCALE_FACTOR) static void deviceScaleFactorChanged(WebKitWebViewBase* webkitWebViewBase) { +#if USE(REDIRECTED_XCOMPOSITE_WINDOW) + if (webkitWebViewBase->priv->redirectedWindow) + webkitWebViewBase->priv->redirectedWindow->setDeviceScaleFactor(webkitWebViewBase->priv->pageProxy->deviceScaleFactor()); +#endif webkitWebViewBase->priv->pageProxy->setIntrinsicDeviceScaleFactor(gtk_widget_get_scale_factor(GTK_WIDGET(webkitWebViewBase))); } #endif // HAVE(GTK_SCALE_FACTOR) -void webkitWebViewBaseCreateWebPage(WebKitWebViewBase* webkitWebViewBase, WebContext* context, WebPageGroup* pageGroup, WebPageProxy* relatedPage) +void webkitWebViewBaseCreateWebPage(WebKitWebViewBase* webkitWebViewBase, Ref<API::PageConfiguration>&& configuration) { WebKitWebViewBasePrivate* priv = webkitWebViewBase->priv; - - WebPageConfiguration webPageConfiguration; - webPageConfiguration.pageGroup = pageGroup; - webPageConfiguration.relatedPage = relatedPage; - priv->pageProxy = context->createWebPage(*priv->pageClient, std::move(webPageConfiguration)); + WebProcessPool* context = configuration->processPool(); + priv->pageProxy = context->createWebPage(*priv->pageClient, WTFMove(configuration)); priv->pageProxy->initializeWebPage(); -#if USE(TEXTURE_MAPPER_GL) - if (priv->redirectedWindow) - priv->pageProxy->setAcceleratedCompositingWindowId(priv->redirectedWindow->windowId()); -#endif + priv->inputMethodFilter.setPage(priv->pageProxy.get()); #if HAVE(GTK_SCALE_FACTOR) // We attach this here, because changes in scale factor are passed directly to the page proxy. priv->pageProxy->setIntrinsicDeviceScaleFactor(gtk_widget_get_scale_factor(GTK_WIDGET(webkitWebViewBase))); g_signal_connect(webkitWebViewBase, "notify::scale-factor", G_CALLBACK(deviceScaleFactorChanged), nullptr); #endif - - webkitWebViewBaseUpdatePreferences(webkitWebViewBase); - - // This must happen here instead of the instance initializer, because the input method - // filter must have access to the page. - priv->inputMethodFilter.setWebView(webkitWebViewBase); } void webkitWebViewBaseSetTooltipText(WebKitWebViewBase* webViewBase, const char* tooltip) @@ -1040,31 +1269,12 @@ void webkitWebViewBaseSetTooltipArea(WebKitWebViewBase* webViewBase, const IntRe } #if ENABLE(DRAG_SUPPORT) -void webkitWebViewBaseStartDrag(WebKitWebViewBase* webViewBase, const DragData& dragData, PassRefPtr<ShareableBitmap> dragImage) +DragAndDropHandler& webkitWebViewBaseDragAndDropHandler(WebKitWebViewBase* webViewBase) { WebKitWebViewBasePrivate* priv = webViewBase->priv; - - RefPtr<DataObjectGtk> dataObject = adoptRef(dragData.platformData()); - GRefPtr<GtkTargetList> targetList = adoptGRef(PasteboardHelper::defaultPasteboardHelper()->targetListForDataObject(dataObject.get())); - GUniquePtr<GdkEvent> currentEvent(gtk_get_current_event()); - GdkDragContext* context = gtk_drag_begin(GTK_WIDGET(webViewBase), - targetList.get(), - dragOperationToGdkDragActions(dragData.draggingSourceOperationMask()), - 1, /* button */ - currentEvent.get()); - priv->dragAndDropHelper.startedDrag(context, dataObject.get()); - - - // A drag starting should prevent a double-click from happening. This might - // happen if a drag is followed very quickly by another click (like in the DRT). - priv->clickCounter.reset(); - - if (dragImage) { - RefPtr<cairo_surface_t> image(dragImage->createCairoSurface()); - priv->dragIcon.setImage(image.get()); - priv->dragIcon.useForDrag(context); - } else - gtk_drag_set_icon_default(context); + if (!priv->dragAndDropHandler) + priv->dragAndDropHandler = std::make_unique<DragAndDropHandler>(*priv->pageProxy); + return *priv->dragAndDropHandler; } #endif // ENABLE(DRAG_SUPPORT) @@ -1073,6 +1283,75 @@ void webkitWebViewBaseForwardNextKeyEvent(WebKitWebViewBase* webkitWebViewBase) webkitWebViewBase->priv->shouldForwardNextKeyEvent = TRUE; } +#if ENABLE(FULLSCREEN_API) +static void screenSaverInhibitedCallback(GDBusProxy* screenSaverProxy, GAsyncResult* result, WebKitWebViewBase* webViewBase) +{ + GRefPtr<GVariant> returnValue = adoptGRef(g_dbus_proxy_call_finish(screenSaverProxy, result, nullptr)); + if (returnValue) + g_variant_get(returnValue.get(), "(u)", &webViewBase->priv->screenSaverCookie); + webViewBase->priv->screenSaverInhibitCancellable = nullptr; +} + +static void webkitWebViewBaseSendInhibitMessageToScreenSaver(WebKitWebViewBase* webViewBase) +{ + WebKitWebViewBasePrivate* priv = webViewBase->priv; + ASSERT(priv->screenSaverProxy); + priv->screenSaverCookie = 0; + if (!priv->screenSaverInhibitCancellable) + priv->screenSaverInhibitCancellable = adoptGRef(g_cancellable_new()); + g_dbus_proxy_call(priv->screenSaverProxy.get(), "Inhibit", g_variant_new("(ss)", g_get_prgname(), _("Website running in fullscreen mode")), + G_DBUS_CALL_FLAGS_NONE, -1, priv->screenSaverInhibitCancellable.get(), reinterpret_cast<GAsyncReadyCallback>(screenSaverInhibitedCallback), webViewBase); +} + +static void screenSaverProxyCreatedCallback(GObject*, GAsyncResult* result, WebKitWebViewBase* webViewBase) +{ + // WebKitWebViewBase cancels the proxy creation on dispose, which means this could be called + // after the web view has been destroyed and g_dbus_proxy_new_for_bus_finish will return nullptr. + // So, make sure we don't use the web view unless we have a valid proxy. + // See https://bugs.webkit.org/show_bug.cgi?id=151653. + GRefPtr<GDBusProxy> proxy = adoptGRef(g_dbus_proxy_new_for_bus_finish(result, nullptr)); + if (!proxy) + return; + + webViewBase->priv->screenSaverProxy = proxy; + webkitWebViewBaseSendInhibitMessageToScreenSaver(webViewBase); +} + +static void webkitWebViewBaseInhibitScreenSaver(WebKitWebViewBase* webViewBase) +{ + WebKitWebViewBasePrivate* priv = webViewBase->priv; + if (priv->screenSaverCookie) { + // Already inhibited. + return; + } + + if (priv->screenSaverProxy) { + webkitWebViewBaseSendInhibitMessageToScreenSaver(webViewBase); + return; + } + + priv->screenSaverInhibitCancellable = adoptGRef(g_cancellable_new()); + g_dbus_proxy_new_for_bus(G_BUS_TYPE_SESSION, static_cast<GDBusProxyFlags>(G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS), + nullptr, "org.freedesktop.ScreenSaver", "/ScreenSaver", "org.freedesktop.ScreenSaver", priv->screenSaverInhibitCancellable.get(), + reinterpret_cast<GAsyncReadyCallback>(screenSaverProxyCreatedCallback), webViewBase); +} + +static void webkitWebViewBaseUninhibitScreenSaver(WebKitWebViewBase* webViewBase) +{ + WebKitWebViewBasePrivate* priv = webViewBase->priv; + if (!priv->screenSaverCookie) { + // Not inhibited or it's being inhibited. + g_cancellable_cancel(priv->screenSaverInhibitCancellable.get()); + return; + } + + // If we have a cookie we should have a proxy. + ASSERT(priv->screenSaverProxy); + g_dbus_proxy_call(priv->screenSaverProxy.get(), "UnInhibit", g_variant_new("(u)", priv->screenSaverCookie), G_DBUS_CALL_FLAGS_NONE, -1, nullptr, nullptr, nullptr); + priv->screenSaverCookie = 0; +} +#endif + void webkitWebViewBaseEnterFullScreen(WebKitWebViewBase* webkitWebViewBase) { #if ENABLE(FULLSCREEN_API) @@ -1091,6 +1370,7 @@ void webkitWebViewBaseEnterFullScreen(WebKitWebViewBase* webkitWebViewBase) gtk_window_fullscreen(GTK_WINDOW(topLevelWindow)); fullScreenManagerProxy->didEnterFullScreen(); priv->fullScreenModeActive = true; + webkitWebViewBaseInhibitScreenSaver(webkitWebViewBase); #endif } @@ -1112,6 +1392,7 @@ void webkitWebViewBaseExitFullScreen(WebKitWebViewBase* webkitWebViewBase) gtk_window_unfullscreen(GTK_WINDOW(topLevelWindow)); fullScreenManagerProxy->didExitFullScreen(); priv->fullScreenModeActive = false; + webkitWebViewBaseUninhibitScreenSaver(webkitWebViewBase); #endif } @@ -1129,9 +1410,16 @@ void webkitWebViewBaseSetInspectorViewSize(WebKitWebViewBase* webkitWebViewBase, gtk_widget_queue_resize_no_redraw(GTK_WIDGET(webkitWebViewBase)); } +static void activeContextMenuUnmapped(GtkMenu* menu, WebKitWebViewBase* webViewBase) +{ + if (webViewBase->priv->activeContextMenuProxy && webViewBase->priv->activeContextMenuProxy->gtkMenu() == menu) + webViewBase->priv->activeContextMenuProxy = nullptr; +} + void webkitWebViewBaseSetActiveContextMenuProxy(WebKitWebViewBase* webkitWebViewBase, WebContextMenuProxyGtk* contextMenuProxy) { webkitWebViewBase->priv->activeContextMenuProxy = contextMenuProxy; + g_signal_connect_object(contextMenuProxy->gtkMenu(), "unmap", G_CALLBACK(activeContextMenuUnmapped), webkitWebViewBase, static_cast<GConnectFlags>(0)); } WebContextMenuProxyGtk* webkitWebViewBaseGetActiveContextMenuProxy(WebKitWebViewBase* webkitWebViewBase) @@ -1144,57 +1432,49 @@ GdkEvent* webkitWebViewBaseTakeContextMenuEvent(WebKitWebViewBase* webkitWebView return webkitWebViewBase->priv->contextMenuEvent.release(); } -#if USE(TEXTURE_MAPPER_GL) -void redirectedWindowDamagedCallback(void* data) -{ - gtk_widget_queue_draw(GTK_WIDGET(data)); -} -#endif - void webkitWebViewBaseSetFocus(WebKitWebViewBase* webViewBase, bool focused) { WebKitWebViewBasePrivate* priv = webViewBase->priv; - if (priv->isFocused == focused) + if ((focused && priv->viewState & ViewState::IsFocused) || (!focused && !(priv->viewState & ViewState::IsFocused))) return; - unsigned viewStateFlags = ViewState::IsFocused; - priv->isFocused = focused; - - // If the view has received the focus and the window is not active - // mark the current window as active now. This can happen if the - // toplevel window is a GTK_WINDOW_POPUP and the focus has been - // set programatically like WebKitTestRunner does, because POPUP - // can't be focused. - if (priv->isFocused && !priv->isInWindowActive) { - priv->isInWindowActive = true; - viewStateFlags |= ViewState::WindowIsActive; - } - priv->pageProxy->viewStateDidChange(viewStateFlags); + ViewState::Flags flagsToUpdate = ViewState::IsFocused; + if (focused) { + priv->viewState |= ViewState::IsFocused; + + // If the view has received the focus and the window is not active + // mark the current window as active now. This can happen if the + // toplevel window is a GTK_WINDOW_POPUP and the focus has been + // set programatically like WebKitTestRunner does, because POPUP + // can't be focused. + if (!(priv->viewState & ViewState::WindowIsActive)) { + priv->viewState |= ViewState::WindowIsActive; + flagsToUpdate |= ViewState::WindowIsActive; + } + } else + priv->viewState &= ~ViewState::IsFocused; + + webkitWebViewBaseScheduleUpdateViewState(webViewBase, flagsToUpdate); } bool webkitWebViewBaseIsInWindowActive(WebKitWebViewBase* webViewBase) { - return webViewBase->priv->isInWindowActive; + return webViewBase->priv->viewState & ViewState::WindowIsActive; } bool webkitWebViewBaseIsFocused(WebKitWebViewBase* webViewBase) { - return webViewBase->priv->isFocused; + return webViewBase->priv->viewState & ViewState::IsFocused; } bool webkitWebViewBaseIsVisible(WebKitWebViewBase* webViewBase) { - return webViewBase->priv->isVisible; + return webViewBase->priv->viewState & ViewState::IsVisible; } bool webkitWebViewBaseIsInWindow(WebKitWebViewBase* webViewBase) { - return webViewBase->priv->toplevelOnScreenWindow; -} - -bool webkitWebViewBaseIsWindowVisible(WebKitWebViewBase* webViewBase) -{ - return webViewBase->priv->isWindowVisible; + return webViewBase->priv->viewState & ViewState::IsInWindow; } void webkitWebViewBaseSetDownloadRequestHandler(WebKitWebViewBase* webViewBase, WebKitWebViewBaseDownloadRequestHandler downloadHandler) @@ -1215,10 +1495,88 @@ void webkitWebViewBaseSetInputMethodState(WebKitWebViewBase* webkitWebViewBase, void webkitWebViewBaseUpdateTextInputState(WebKitWebViewBase* webkitWebViewBase) { - webkitWebViewBase->priv->inputMethodFilter.setCursorRect(webkitWebViewBase->priv->pageProxy->editorState().cursorRect); + const auto& editorState = webkitWebViewBase->priv->pageProxy->editorState(); + if (!editorState.isMissingPostLayoutData) + webkitWebViewBase->priv->inputMethodFilter.setCursorRect(editorState.postLayoutData().caretRectAtStart); } void webkitWebViewBaseResetClickCounter(WebKitWebViewBase* webkitWebViewBase) { webkitWebViewBase->priv->clickCounter.reset(); } + +#if USE(REDIRECTED_XCOMPOSITE_WINDOW) +static void webkitWebViewBaseClearRedirectedWindowSoon(WebKitWebViewBase* webkitWebViewBase) +{ + static const double clearRedirectedWindowSoonDelay = 2; + webkitWebViewBase->priv->clearRedirectedWindowSoonTimer.startOneShot(clearRedirectedWindowSoonDelay); +} +#endif + +void webkitWebViewBaseWillEnterAcceleratedCompositingMode(WebKitWebViewBase* webkitWebViewBase) +{ +#if USE(REDIRECTED_XCOMPOSITE_WINDOW) + WebKitWebViewBasePrivate* priv = webkitWebViewBase->priv; + if (!priv->redirectedWindow) + return; + DrawingAreaProxyImpl* drawingArea = static_cast<DrawingAreaProxyImpl*>(priv->pageProxy->drawingArea()); + if (!drawingArea) + return; + + priv->redirectedWindow->setDeviceScaleFactor(webkitWebViewBase->priv->pageProxy->deviceScaleFactor()); + priv->redirectedWindow->resize(drawingArea->size()); + + // Clear the redirected window if we don't enter AC mode in the end. + webkitWebViewBaseClearRedirectedWindowSoon(webkitWebViewBase); +#else + UNUSED_PARAM(webkitWebViewBase); +#endif +} + +void webkitWebViewBaseEnterAcceleratedCompositingMode(WebKitWebViewBase* webkitWebViewBase) +{ +#if USE(REDIRECTED_XCOMPOSITE_WINDOW) + webkitWebViewBase->priv->clearRedirectedWindowSoonTimer.stop(); +#else + UNUSED_PARAM(webkitWebViewBase); +#endif +} + +void webkitWebViewBaseExitAcceleratedCompositingMode(WebKitWebViewBase* webkitWebViewBase) +{ +#if USE(REDIRECTED_XCOMPOSITE_WINDOW) + // Resize the window later to ensure we have already rendered the + // non composited contents and avoid flickering. We can also avoid the + // window resize entirely if we switch back to AC mode quickly. + webkitWebViewBaseClearRedirectedWindowSoon(webkitWebViewBase); +#else + UNUSED_PARAM(webkitWebViewBase); +#endif +} + +void webkitWebViewBaseDidRelaunchWebProcess(WebKitWebViewBase* webkitWebViewBase) +{ + // Queue a resize to ensure the new DrawingAreaProxy is resized. + gtk_widget_queue_resize_no_redraw(GTK_WIDGET(webkitWebViewBase)); + +#if PLATFORM(X11) && USE(TEXTURE_MAPPER) + if (PlatformDisplay::sharedDisplay().type() != PlatformDisplay::Type::X11) + return; + + WebKitWebViewBasePrivate* priv = webkitWebViewBase->priv; + DrawingAreaProxyImpl* drawingArea = static_cast<DrawingAreaProxyImpl*>(priv->pageProxy->drawingArea()); + ASSERT(drawingArea); +#if USE(REDIRECTED_XCOMPOSITE_WINDOW) + if (!priv->redirectedWindow) + return; + uint64_t windowID = priv->redirectedWindow->windowID(); +#else + if (!gtk_widget_get_realized(GTK_WIDGET(webkitWebViewBase))) + return; + uint64_t windowID = GDK_WINDOW_XID(gtk_widget_get_window(GTK_WIDGET(webkitWebViewBase))); +#endif + drawingArea->setNativeSurfaceHandleForCompositing(windowID); +#else + UNUSED_PARAM(webkitWebViewBase); +#endif +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBaseAccessible.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBaseAccessible.cpp index 7b069dd94..fc2d053a7 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBaseAccessible.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBaseAccessible.cpp @@ -29,7 +29,7 @@ struct _WebKitWebViewBaseAccessiblePrivate { WEBKIT_DEFINE_TYPE(WebKitWebViewBaseAccessible, webkit_web_view_base_accessible, ATK_TYPE_SOCKET) -static void webkitWebViewBaseAccessibleWidgetDestroyed(GtkWidget* widget, WebKitWebViewBaseAccessible* accessible) +static void webkitWebViewBaseAccessibleWidgetDestroyed(GtkWidget*, WebKitWebViewBaseAccessible* accessible) { accessible->priv->widget = 0; atk_object_notify_state_change(ATK_OBJECT(accessible), ATK_STATE_DEFUNCT, TRUE); diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBasePrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBasePrivate.h index b9c38c265..2a3d955e9 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBasePrivate.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBasePrivate.h @@ -28,20 +28,22 @@ #ifndef WebKitWebViewBasePrivate_h #define WebKitWebViewBasePrivate_h +#include "APIPageConfiguration.h" +#include "DragAndDropHandler.h" +#include "GestureController.h" #include "WebContextMenuProxyGtk.h" #include "WebInspectorProxy.h" #include "WebKitPrivate.h" #include "WebKitWebViewBase.h" #include "WebPageProxy.h" -WebKitWebViewBase* webkitWebViewBaseCreate(WebKit::WebContext*, WebKit::WebPageGroup*, WebKit::WebPageProxy*); +WebKitWebViewBase* webkitWebViewBaseCreate(const API::PageConfiguration&); GtkIMContext* webkitWebViewBaseGetIMContext(WebKitWebViewBase*); WebKit::WebPageProxy* webkitWebViewBaseGetPage(WebKitWebViewBase*); -void webkitWebViewBaseCreateWebPage(WebKitWebViewBase*, WebKit::WebContext*, WebKit::WebPageGroup*, WebKit::WebPageProxy*); +void webkitWebViewBaseCreateWebPage(WebKitWebViewBase*, Ref<API::PageConfiguration>&&); void webkitWebViewBaseSetTooltipText(WebKitWebViewBase*, const char*); void webkitWebViewBaseSetTooltipArea(WebKitWebViewBase*, const WebCore::IntRect&); void webkitWebViewBaseForwardNextKeyEvent(WebKitWebViewBase*); -void webkitWebViewBaseStartDrag(WebKitWebViewBase*, const WebCore::DragData&, PassRefPtr<WebKit::ShareableBitmap> dragImage); void webkitWebViewBaseChildMoveResize(WebKitWebViewBase*, GtkWidget*, const WebCore::IntRect&); void webkitWebViewBaseEnterFullScreen(WebKitWebViewBase*); void webkitWebViewBaseExitFullScreen(WebKitWebViewBase*); @@ -52,18 +54,12 @@ WebKit::WebContextMenuProxyGtk* webkitWebViewBaseGetActiveContextMenuProxy(WebKi GdkEvent* webkitWebViewBaseTakeContextMenuEvent(WebKitWebViewBase*); void webkitWebViewBaseSetInputMethodState(WebKitWebViewBase*, bool enabled); void webkitWebViewBaseUpdateTextInputState(WebKitWebViewBase*); -void webkitWebViewBaseUpdatePreferences(WebKitWebViewBase*); - -#if USE(TEXTURE_MAPPER_GL) -void webkitWebViewBaseQueueDrawOfAcceleratedCompositingResults(WebKitWebViewBase*); -#endif void webkitWebViewBaseSetFocus(WebKitWebViewBase*, bool focused); bool webkitWebViewBaseIsInWindowActive(WebKitWebViewBase*); bool webkitWebViewBaseIsFocused(WebKitWebViewBase*); bool webkitWebViewBaseIsVisible(WebKitWebViewBase*); bool webkitWebViewBaseIsInWindow(WebKitWebViewBase*); -bool webkitWebViewBaseIsWindowVisible(WebKitWebViewBase*); typedef void (*WebKitWebViewBaseDownloadRequestHandler) (WebKitWebViewBase*, WebKit::DownloadProxy*); void webkitWebViewBaseSetDownloadRequestHandler(WebKitWebViewBase*, WebKitWebViewBaseDownloadRequestHandler); @@ -73,5 +69,17 @@ void webkitWebViewBaseAddAuthenticationDialog(WebKitWebViewBase*, GtkWidget* aut void webkitWebViewBaseCancelAuthenticationDialog(WebKitWebViewBase*); void webkitWebViewBaseAddWebInspector(WebKitWebViewBase*, GtkWidget* inspector, WebKit::AttachmentSide); void webkitWebViewBaseResetClickCounter(WebKitWebViewBase*); +void webkitWebViewBaseWillEnterAcceleratedCompositingMode(WebKitWebViewBase*); +void webkitWebViewBaseEnterAcceleratedCompositingMode(WebKitWebViewBase*); +void webkitWebViewBaseExitAcceleratedCompositingMode(WebKitWebViewBase*); +void webkitWebViewBaseDidRelaunchWebProcess(WebKitWebViewBase*); + +#if ENABLE(DRAG_SUPPORT) +WebKit::DragAndDropHandler& webkitWebViewBaseDragAndDropHandler(WebKitWebViewBase*); +#endif + +#if HAVE(GTK_GESTURES) +WebKit::GestureController& webkitWebViewBaseGestureController(WebKitWebViewBase*); +#endif #endif // WebKitWebViewBasePrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewGroup.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewGroup.cpp deleted file mode 100644 index 289ecdf03..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewGroup.cpp +++ /dev/null @@ -1,288 +0,0 @@ -/* - * Copyright (C) 2013 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" -#include "WebKitWebViewGroup.h" - -#include "APIArray.h" -#include "APIString.h" -#include "WebKitPrivate.h" -#include "WebKitSettingsPrivate.h" -#include "WebKitWebViewGroupPrivate.h" -#include <glib/gi18n-lib.h> -#include <wtf/gobject/GRefPtr.h> -#include <wtf/text/CString.h> - -using namespace WebKit; - -/** - * SECTION: WebKitWebViewGroup - * @Short_description: Group of web views - * @Title: WebKitWebViewGroup - * @See_also: #WebKitWebView, #WebKitSettings - * - * A WebKitWebViewGroup represents a group of #WebKitWebView<!-- -->s that - * share things like settings. There's a default WebKitWebViewGroup where - * all #WebKitWebView<!-- -->s of the same #WebKitWebContext are added by default. - * To create a #WebKitWebView in a different WebKitWebViewGroup you can use - * webkit_web_view_new_with_group(). - * - * WebKitWebViewGroups are identified by a unique name given when the group is - * created with webkit_web_view_group_new(). - * WebKitWebViewGroups have a #WebKitSettings to control the settings of all - * #WebKitWebView<!-- -->s of the group. You can get the settings with - * webkit_web_view_group_get_settings() to handle the settings, or you can set - * your own #WebKitSettings with webkit_web_view_group_set_settings(). When - * the #WebKitSettings of a WebKitWebViewGroup changes, the signal notify::settings - * is emitted on the group. - */ - -enum { - PROP_0, - - PROP_SETTINGS -}; - -struct _WebKitWebViewGroupPrivate { - RefPtr<WebPageGroup> pageGroup; - CString name; - GRefPtr<WebKitSettings> settings; -}; - -WEBKIT_DEFINE_TYPE(WebKitWebViewGroup, webkit_web_view_group, G_TYPE_OBJECT) - -static void webkitWebViewGroupSetProperty(GObject* object, guint propId, const GValue* value, GParamSpec* paramSpec) -{ - WebKitWebViewGroup* group = WEBKIT_WEB_VIEW_GROUP(object); - - switch (propId) { - case PROP_SETTINGS: - webkit_web_view_group_set_settings(group, WEBKIT_SETTINGS(g_value_get_object(value))); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); - } -} - -static void webkitWebViewGroupGetProperty(GObject* object, guint propId, GValue* value, GParamSpec* paramSpec) -{ - WebKitWebViewGroup* group = WEBKIT_WEB_VIEW_GROUP(object); - - switch (propId) { - case PROP_SETTINGS: - g_value_set_object(value, webkit_web_view_group_get_settings(group)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); - } -} - -static void webkitWebViewGroupConstructed(GObject* object) -{ - G_OBJECT_CLASS(webkit_web_view_group_parent_class)->constructed(object); - - WebKitWebViewGroupPrivate* priv = WEBKIT_WEB_VIEW_GROUP(object)->priv; - priv->settings = adoptGRef(webkit_settings_new()); -} - -static void webkit_web_view_group_class_init(WebKitWebViewGroupClass* hitTestResultClass) -{ - GObjectClass* objectClass = G_OBJECT_CLASS(hitTestResultClass); - objectClass->set_property = webkitWebViewGroupSetProperty; - objectClass->get_property = webkitWebViewGroupGetProperty; - objectClass->constructed = webkitWebViewGroupConstructed; - - /** - * WebKitWebViewGroup:settings: - * - * The #WebKitSettings of the web view group. - */ - g_object_class_install_property( - objectClass, - PROP_SETTINGS, - g_param_spec_object( - "settings", - _("Settings"), - _("The settings of the web view group"), - WEBKIT_TYPE_SETTINGS, - WEBKIT_PARAM_READWRITE)); -} - -static void webkitWebViewGroupAttachSettingsToPageGroup(WebKitWebViewGroup* group) -{ - group->priv->pageGroup->setPreferences(webkitSettingsGetPreferences(group->priv->settings.get())); -} - -WebKitWebViewGroup* webkitWebViewGroupCreate(WebPageGroup* pageGroup) -{ - WebKitWebViewGroup* group = WEBKIT_WEB_VIEW_GROUP(g_object_new(WEBKIT_TYPE_WEB_VIEW_GROUP, NULL)); - group->priv->pageGroup = pageGroup; - webkitWebViewGroupAttachSettingsToPageGroup(group); - return group; -} - -WebPageGroup* webkitWebViewGroupGetPageGroup(WebKitWebViewGroup* group) -{ - return group->priv->pageGroup.get(); -} - -/** - * webkit_web_view_group_new: - * @name: (allow-none): the name of the group - * - * Creates a new #WebKitWebViewGroup with the given @name. - * If @name is %NULL a unique identifier name will be created - * automatically. - * The newly created #WebKitWebViewGroup doesn't contain any - * #WebKitWebView, web views are added to the new group when created - * with webkit_web_view_new_with_group() passing the group. - * - * Returns: (transfer full): a new #WebKitWebViewGroup - */ -WebKitWebViewGroup* webkit_web_view_group_new(const char* name) -{ - WebKitWebViewGroup* group = WEBKIT_WEB_VIEW_GROUP(g_object_new(WEBKIT_TYPE_WEB_VIEW_GROUP, NULL)); - group->priv->pageGroup = WebPageGroup::create(name ? String::fromUTF8(name) : String()); - webkitWebViewGroupAttachSettingsToPageGroup(group); - return group; -} - -/** - * webkit_web_view_group_get_name: - * @group: a #WebKitWebViewGroup - * - * Gets the name that uniquely identifies the #WebKitWebViewGroup. - * - * Returns: the name of @group - */ -const char* webkit_web_view_group_get_name(WebKitWebViewGroup* group) -{ - g_return_val_if_fail(WEBKIT_IS_WEB_VIEW_GROUP(group), 0); - - WebKitWebViewGroupPrivate* priv = group->priv; - if (priv->name.isNull()) - priv->name = priv->pageGroup->identifier().utf8(); - - return priv->name.data(); -} - -/** - * webkit_web_view_group_get_settings: - * @group: a #WebKitWebViewGroup - * - * Gets the #WebKitSettings of the #WebKitWebViewGroup. - * - * Returns: (transfer none): the settings of @group - */ -WebKitSettings* webkit_web_view_group_get_settings(WebKitWebViewGroup* group) -{ - g_return_val_if_fail(WEBKIT_IS_WEB_VIEW_GROUP(group), 0); - - return group->priv->settings.get(); -} - -/** - * webkit_web_view_group_set_settings: - * @group: a #WebKitWebViewGroup - * @settings: a #WebKitSettings - * - * Sets a new #WebKitSettings for the #WebKitWebViewGroup. The settings will - * affect to all the #WebKitWebView<!-- -->s of the group. - * #WebKitWebViewGroup<!-- -->s always have a #WebKitSettings so if you just want to - * modify a setting you can use webkit_web_view_group_get_settings() and modify the - * returned #WebKitSettings instead. - * Setting the same #WebKitSettings multiple times doesn't have any effect. - * You can monitor the settings of a #WebKitWebViewGroup by connecting to the - * notify::settings signal of @group. - */ -void webkit_web_view_group_set_settings(WebKitWebViewGroup* group, WebKitSettings* settings) -{ - g_return_if_fail(WEBKIT_IS_WEB_VIEW_GROUP(group)); - g_return_if_fail(WEBKIT_IS_SETTINGS(settings)); - - if (group->priv->settings == settings) - return; - - group->priv->settings = settings; - webkitWebViewGroupAttachSettingsToPageGroup(group); - g_object_notify(G_OBJECT(group), "settings"); -} - -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_INJECTED_CONTENT_FRAMES_ALL, WebCore::InjectInAllFrames); -COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_INJECTED_CONTENT_FRAMES_TOP_ONLY, WebCore::InjectInTopFrameOnly); - -static PassRefPtr<API::Array> toAPIArray(const char* const* list) -{ - if (!list) - return 0; - - Vector<RefPtr<API::Object> > entries; - while (*list) { - entries.append(API::String::createFromUTF8String(*list)); - list++; - } - return API::Array::create(std::move(entries)); -} - -/** - * webkit_web_view_group_add_user_style_sheet: - * @group: a #WebKitWebViewGroup - * @source: the source of the style_sheet to inject - * @base_uri: (allow-none): the base URI to use when processing the style_sheet contents or %NULL for about:blank - * @whitelist: (array zero-terminated=1) (allow-none): a whitelist of URI patterns or %NULL - * @blacklist: (array zero-terminated=1) (allow-none): a blacklist of URI patterns or %NULL - * @injected_frames: a #WebKitInjectedContentFrames describing to which frames the style_sheet should apply - * - * Inject an external style sheet into pages. It is possible to only apply the style sheet - * to some URIs by passing non-null values for @whitelist or @blacklist. Passing a %NULL - * whitelist implies that all URIs are on the whitelist. The style sheet is applied if a URI matches - * the whitelist and not the blacklist. URI patterns must be of the form [protocol]://[host]/[path] - * where the host and path components can contain the wildcard character ('*') to represent zero - * or more other characters. - */ -void webkit_web_view_group_add_user_style_sheet(WebKitWebViewGroup* group, const char* source, const char* baseURI, const char* const* whitelist, const char* const* blacklist, WebKitInjectedContentFrames injectedFrames) -{ - g_return_if_fail(WEBKIT_IS_WEB_VIEW_GROUP(group)); - g_return_if_fail(source); - - RefPtr<API::Array> webWhitelist = toAPIArray(whitelist); - RefPtr<API::Array> webBlacklist = toAPIArray(blacklist); - - // We always use UserStyleUserLevel to match the behavior of WKPageGroupAddUserStyleSheet. - group->priv->pageGroup->addUserStyleSheet( - String::fromUTF8(source), - String::fromUTF8(baseURI), - webWhitelist.get(), - webBlacklist.get(), - static_cast<WebCore::UserContentInjectedFrames>(injectedFrames), - WebCore::UserStyleUserLevel); -} - -/** - * webkit_web_view_group_remove_all_user_style_sheets: - * @group: a #WebKitWebViewGroup - * - * Remove all style sheets previously injected into this #WebKitWebViewGroup - * via webkit_web_view_group_add_user_style_sheet(). - */ -void webkit_web_view_group_remove_all_user_style_sheets(WebKitWebViewGroup* group) -{ - g_return_if_fail(WEBKIT_IS_WEB_VIEW_GROUP(group)); - group->priv->pageGroup->removeAllUserStyleSheets(); -} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewGroup.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewGroup.h deleted file mode 100644 index 685f19904..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewGroup.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2013 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) -#error "Only <webkit2/webkit2.h> can be included directly." -#endif - -#ifndef WebKitWebViewGroup_h -#define WebKitWebViewGroup_h - -#include <glib-object.h> -#include <webkit2/WebKitDefines.h> -#include <webkit2/WebKitSettings.h> - -G_BEGIN_DECLS - -#define WEBKIT_TYPE_WEB_VIEW_GROUP (webkit_web_view_group_get_type()) -#define WEBKIT_WEB_VIEW_GROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_VIEW_GROUP, WebKitWebViewGroup)) -#define WEBKIT_IS_WEB_VIEW_GROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEB_VIEW_GROUP)) -#define WEBKIT_WEB_VIEW_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_WEB_VIEW_GROUP, WebKitWebViewGroupClass)) -#define WEBKIT_IS_WEB_VIEW_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_WEB_VIEW_GROUP)) -#define WEBKIT_WEB_VIEW_GROUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_WEB_VIEW_GROUP, WebKitWebViewGroupClass)) - -typedef struct _WebKitWebViewGroup WebKitWebViewGroup; -typedef struct _WebKitWebViewGroupClass WebKitWebViewGroupClass; -typedef struct _WebKitWebViewGroupPrivate WebKitWebViewGroupPrivate; - -struct _WebKitWebViewGroup { - GObject parent; - - WebKitWebViewGroupPrivate *priv; -}; - -struct _WebKitWebViewGroupClass { - GObjectClass parent_class; - - void (*_webkit_reserved0) (void); - void (*_webkit_reserved1) (void); - void (*_webkit_reserved2) (void); - void (*_webkit_reserved3) (void); -}; - -/** - * WebKitInjectedContentFrames: - * @WEBKIT_INJECTED_CONTENT_FRAMES_ALL: Content will be injected into all frames. - * @WEBKIT_INJECTED_CONTENT_FRAMES_TOP_ONLY: Content will only be injected into the main frame. - * - * Enum values used for determining into which frames content is injected. - */ -typedef enum { - WEBKIT_INJECTED_CONTENT_FRAMES_ALL, - WEBKIT_INJECTED_CONTENT_FRAMES_TOP_ONLY, -} WebKitInjectedContentFrames; - -WEBKIT_API GType -webkit_web_view_group_get_type (void); - -WEBKIT_API WebKitWebViewGroup * -webkit_web_view_group_new (const gchar *name); - -WEBKIT_API const gchar * -webkit_web_view_group_get_name (WebKitWebViewGroup *group); - -WEBKIT_API WebKitSettings * -webkit_web_view_group_get_settings (WebKitWebViewGroup *group); - -WEBKIT_API void -webkit_web_view_group_set_settings (WebKitWebViewGroup *group, - WebKitSettings *settings); - -WEBKIT_API void -webkit_web_view_group_add_user_style_sheet (WebKitWebViewGroup *group, - const gchar *source, - const gchar *base_uri, - const gchar * const *whitelist, - const gchar * const *blacklist, - WebKitInjectedContentFrames injected_frames); - -WEBKIT_API void -webkit_web_view_group_remove_all_user_style_sheets (WebKitWebViewGroup *group); - -G_END_DECLS - -#endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h index 11591ff18..61e0a5524 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h @@ -27,6 +27,9 @@ #ifndef WebKitWebViewPrivate_h #define WebKitWebViewPrivate_h +#include "InstallMissingMediaPluginsPermissionRequest.h" +#include "WebContextMenuItemData.h" +#include "WebHitTestResultData.h" #include "WebImage.h" #include "WebKitWebView.h" #include <wtf/text/CString.h> @@ -34,19 +37,17 @@ void webkitWebViewLoadChanged(WebKitWebView*, WebKitLoadEvent); void webkitWebViewLoadFailed(WebKitWebView*, WebKitLoadEvent, const char* failingURI, GError*); void webkitWebViewLoadFailedWithTLSErrors(WebKitWebView*, const char* failingURI, GError*, GTlsCertificateFlags, GTlsCertificate*); -void webkitWebViewSetEstimatedLoadProgress(WebKitWebView*, double estimatedLoadProgress); -void webkitWebViewSetTitle(WebKitWebView*, const CString&); -void webkitWebViewUpdateURI(WebKitWebView*); -WebKit::WebPageProxy* webkitWebViewCreateNewPage(WebKitWebView*, WebKit::ImmutableDictionary* windowFeatures); +WebKit::WebPageProxy* webkitWebViewCreateNewPage(WebKitWebView*, const WebCore::WindowFeatures&, WebKitNavigationAction*); void webkitWebViewReadyToShowPage(WebKitWebView*); void webkitWebViewRunAsModal(WebKitWebView*); void webkitWebViewClosePage(WebKitWebView*); void webkitWebViewRunJavaScriptAlert(WebKitWebView*, const CString& message); bool webkitWebViewRunJavaScriptConfirm(WebKitWebView*, const CString& message); CString webkitWebViewRunJavaScriptPrompt(WebKitWebView*, const CString& message, const CString& defaultText); +bool webkitWebViewRunJavaScriptBeforeUnloadConfirm(WebKitWebView*, const CString& message); void webkitWebViewMakePermissionRequest(WebKitWebView*, WebKitPermissionRequest*); void webkitWebViewMakePolicyDecision(WebKitWebView*, WebKitPolicyDecisionType, WebKitPolicyDecision*); -void webkitWebViewMouseTargetChanged(WebKitWebView*, WebKit::WebHitTestResult*, unsigned modifiers); +void webkitWebViewMouseTargetChanged(WebKitWebView*, const WebKit::WebHitTestResultData&, unsigned modifiers); void webkitWebViewPrintFrame(WebKitWebView*, WebKit::WebFrameProxy*); void webkitWebViewResourceLoadStarted(WebKitWebView*, WebKit::WebFrameProxy*, uint64_t resourceIdentifier, WebKitURIRequest*); void webkitWebViewRunFileChooserRequest(WebKitWebView*, WebKitFileChooserRequest*); @@ -55,10 +56,15 @@ void webKitWebViewDidReceiveSnapshot(WebKitWebView*, uint64_t callbackID, WebKit void webkitWebViewRemoveLoadingWebResource(WebKitWebView*, uint64_t resourceIdentifier); bool webkitWebViewEnterFullScreen(WebKitWebView*); bool webkitWebViewLeaveFullScreen(WebKitWebView*); -void webkitWebViewPopulateContextMenu(WebKitWebView*, API::Array* proposedMenu, WebKit::WebHitTestResult*); +void webkitWebViewPopulateContextMenu(WebKitWebView*, const Vector<WebKit::WebContextMenuItemData>& proposedMenu, const WebKit::WebHitTestResultData&, GVariant*); void webkitWebViewSubmitFormRequest(WebKitWebView*, WebKitFormSubmissionRequest*); void webkitWebViewHandleAuthenticationChallenge(WebKitWebView*, WebKit::AuthenticationChallengeProxy*); void webkitWebViewInsecureContentDetected(WebKitWebView*, WebKitInsecureContentEvent); +bool webkitWebViewEmitShowNotification(WebKitWebView*, WebKitNotification*); +bool webkitWebViewEmitRunColorChooser(WebKitWebView*, WebKitColorChooserRequest*); void webkitWebViewWebProcessCrashed(WebKitWebView*); +void webkitWebViewIsPlayingAudioChanged(WebKitWebView*); +void webkitWebViewSelectionDidChange(WebKitWebView*); +void webkitWebViewRequestInstallMissingMediaPlugins(WebKitWebView*, WebKit::InstallMissingMediaPluginsPermissionRequest&); #endif // WebKitWebViewPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewSessionState.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewSessionState.cpp new file mode 100644 index 000000000..85bc62cbd --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewSessionState.cpp @@ -0,0 +1,458 @@ +/* + * Copyright (C) 2016 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "WebKitWebViewSessionState.h" + +#include "WebKitWebViewSessionStatePrivate.h" +#include <wtf/glib/GRefPtr.h> +#include <wtf/glib/GUniquePtr.h> + +using namespace WebKit; + +struct _WebKitWebViewSessionState { + _WebKitWebViewSessionState(SessionState&& state) + : sessionState(WTFMove(state)) + , referenceCount(1) + { + } + + SessionState sessionState; + int referenceCount; +}; + +G_DEFINE_BOXED_TYPE(WebKitWebViewSessionState, webkit_web_view_session_state, webkit_web_view_session_state_ref, webkit_web_view_session_state_unref) + +static const guint16 g_sessionStateVersion = 1; +#define HTTP_BODY_ELEMENT_TYPE_STRING_V1 "(uaysxmxmds)" +#define HTTP_BODY_ELEMENT_FORMAT_STRING_V1 "(uay&sxmxmd&s)" +#define HTTP_BODY_TYPE_STRING_V1 "m(sa" HTTP_BODY_ELEMENT_TYPE_STRING_V1 ")" +#define HTTP_BODY_FORMAT_STRING_V1 "m(&sa" HTTP_BODY_ELEMENT_TYPE_STRING_V1 ")" +#define FRAME_STATE_TYPE_STRING_V1 "(ssssasmayxx(ii)d" HTTP_BODY_TYPE_STRING_V1 "av)" +#define FRAME_STATE_FORMAT_STRING_V1 "(&s&s&s&sasmayxx(ii)d@" HTTP_BODY_TYPE_STRING_V1 "av)" +#define BACK_FORWARD_LIST_ITEM_TYPE_STRING_V1 "(ts" FRAME_STATE_TYPE_STRING_V1 "u)" +#define BACK_FORWARD_LIST_ITEM_FORMAT_STRING_V1 "(t&s@" FRAME_STATE_TYPE_STRING_V1 "u)" +#define SESSION_STATE_TYPE_STRING_V1 "(qa" BACK_FORWARD_LIST_ITEM_TYPE_STRING_V1 "mu)" + +// Use our own enum types to ensure the serialized format even if the core enums change. +enum ExternalURLsPolicy { + Allow, + AllowExternalSchemes, + NotAllow +}; + +static inline unsigned toExternalURLsPolicy(WebCore::ShouldOpenExternalURLsPolicy policy) +{ + switch (policy) { + case WebCore::ShouldOpenExternalURLsPolicy::ShouldAllow: + return ExternalURLsPolicy::Allow; + case WebCore::ShouldOpenExternalURLsPolicy::ShouldAllowExternalSchemes: + return ExternalURLsPolicy::AllowExternalSchemes; + case WebCore::ShouldOpenExternalURLsPolicy::ShouldNotAllow: + return ExternalURLsPolicy::NotAllow; + } + + return ExternalURLsPolicy::NotAllow; +} + +static inline WebCore::ShouldOpenExternalURLsPolicy toWebCoreExternalURLsPolicy(unsigned policy) +{ + switch (policy) { + case ExternalURLsPolicy::Allow: + return WebCore::ShouldOpenExternalURLsPolicy::ShouldAllow; + case ExternalURLsPolicy::AllowExternalSchemes: + return WebCore::ShouldOpenExternalURLsPolicy::ShouldAllowExternalSchemes; + case ExternalURLsPolicy::NotAllow: + return WebCore::ShouldOpenExternalURLsPolicy::ShouldNotAllow; + } + + return WebCore::ShouldOpenExternalURLsPolicy::ShouldNotAllow; +} + +enum HTMLBodyElementType { + Data, + File, + Blob +}; + +static inline unsigned toHTMLBodyElementType(HTTPBody::Element::Type type) +{ + switch (type) { + case HTTPBody::Element::Type::Data: + return HTMLBodyElementType::Data; + case HTTPBody::Element::Type::File: + return HTMLBodyElementType::File; + case HTTPBody::Element::Type::Blob: + return HTMLBodyElementType::Blob; + } + + return HTMLBodyElementType::Data; +} + +static inline HTTPBody::Element::Type toHTTPBodyElementType(unsigned type) +{ + switch (type) { + case HTMLBodyElementType::Data: + return HTTPBody::Element::Type::Data; + case HTMLBodyElementType::File: + return HTTPBody::Element::Type::File; + case HTMLBodyElementType::Blob: + return HTTPBody::Element::Type::Blob; + } + + return HTTPBody::Element::Type::Data; +} + +static inline void encodeHTTPBody(GVariantBuilder* sessionBuilder, const HTTPBody& httpBody) +{ + g_variant_builder_open(sessionBuilder, G_VARIANT_TYPE("(sa" HTTP_BODY_ELEMENT_TYPE_STRING_V1 ")")); + g_variant_builder_add(sessionBuilder, "s", httpBody.contentType.utf8().data()); + g_variant_builder_open(sessionBuilder, G_VARIANT_TYPE("a" HTTP_BODY_ELEMENT_TYPE_STRING_V1)); + g_variant_builder_open(sessionBuilder, G_VARIANT_TYPE(HTTP_BODY_ELEMENT_TYPE_STRING_V1)); + for (const auto& element : httpBody.elements) { + g_variant_builder_add(sessionBuilder, "u", toHTMLBodyElementType(element.type)); + g_variant_builder_open(sessionBuilder, G_VARIANT_TYPE("ay")); + for (auto item : element.data) + g_variant_builder_add(sessionBuilder, "y", item); + g_variant_builder_close(sessionBuilder); + g_variant_builder_add(sessionBuilder, "s", element.filePath.utf8().data()); + g_variant_builder_add(sessionBuilder, "x", element.fileStart); + if (element.fileLength) + g_variant_builder_add(sessionBuilder, "mx", TRUE, element.fileLength.value()); + else + g_variant_builder_add(sessionBuilder, "mx", FALSE); + if (element.expectedFileModificationTime) + g_variant_builder_add(sessionBuilder, "md", TRUE, element.expectedFileModificationTime.value()); + else + g_variant_builder_add(sessionBuilder, "md", FALSE); + g_variant_builder_add(sessionBuilder, "s", element.blobURLString.utf8().data()); + } + g_variant_builder_close(sessionBuilder); + g_variant_builder_close(sessionBuilder); + g_variant_builder_close(sessionBuilder); +} + +static inline void encodeFrameState(GVariantBuilder* sessionBuilder, const FrameState& frameState) +{ + g_variant_builder_add(sessionBuilder, "s", frameState.urlString.utf8().data()); + g_variant_builder_add(sessionBuilder, "s", frameState.originalURLString.utf8().data()); + g_variant_builder_add(sessionBuilder, "s", frameState.referrer.utf8().data()); + g_variant_builder_add(sessionBuilder, "s", frameState.target.utf8().data()); + g_variant_builder_open(sessionBuilder, G_VARIANT_TYPE("as")); + for (const auto& state : frameState.documentState) + g_variant_builder_add(sessionBuilder, "s", state.utf8().data()); + g_variant_builder_close(sessionBuilder); + if (!frameState.stateObjectData) + g_variant_builder_add(sessionBuilder, "may", FALSE); + else { + g_variant_builder_open(sessionBuilder, G_VARIANT_TYPE("may")); + g_variant_builder_open(sessionBuilder, G_VARIANT_TYPE("ay")); + for (auto item : frameState.stateObjectData.value()) + g_variant_builder_add(sessionBuilder, "y", item); + g_variant_builder_close(sessionBuilder); + g_variant_builder_close(sessionBuilder); + } + g_variant_builder_add(sessionBuilder, "x", frameState.documentSequenceNumber); + g_variant_builder_add(sessionBuilder, "x", frameState.itemSequenceNumber); + g_variant_builder_add(sessionBuilder, "(ii)", frameState.scrollPosition.x(), frameState.scrollPosition.y()); + g_variant_builder_add(sessionBuilder, "d", frameState.pageScaleFactor); + if (!frameState.httpBody) + g_variant_builder_add(sessionBuilder, HTTP_BODY_TYPE_STRING_V1, FALSE); + else { + g_variant_builder_open(sessionBuilder, G_VARIANT_TYPE(HTTP_BODY_TYPE_STRING_V1)); + encodeHTTPBody(sessionBuilder, frameState.httpBody.value()); + g_variant_builder_close(sessionBuilder); + } + g_variant_builder_open(sessionBuilder, G_VARIANT_TYPE("av")); + for (const auto& child : frameState.children) { + GVariantBuilder frameStateBuilder; + g_variant_builder_init(&frameStateBuilder, G_VARIANT_TYPE(FRAME_STATE_TYPE_STRING_V1)); + encodeFrameState(&frameStateBuilder, child); + g_variant_builder_add(sessionBuilder, "v", g_variant_builder_end(&frameStateBuilder)); + } + g_variant_builder_close(sessionBuilder); +} + +static inline void encodePageState(GVariantBuilder* sessionBuilder, const PageState& pageState) +{ + g_variant_builder_add(sessionBuilder, "s", pageState.title.utf8().data()); + g_variant_builder_open(sessionBuilder, G_VARIANT_TYPE(FRAME_STATE_TYPE_STRING_V1)); + encodeFrameState(sessionBuilder, pageState.mainFrameState); + g_variant_builder_close(sessionBuilder); + g_variant_builder_add(sessionBuilder, "u", toExternalURLsPolicy(pageState.shouldOpenExternalURLsPolicy)); +} + +static inline void encodeBackForwardListItemState(GVariantBuilder* sessionBuilder, const BackForwardListItemState& item) +{ + g_variant_builder_open(sessionBuilder, G_VARIANT_TYPE(BACK_FORWARD_LIST_ITEM_TYPE_STRING_V1)); + g_variant_builder_add(sessionBuilder, "t", item.identifier); + encodePageState(sessionBuilder, item.pageState); + g_variant_builder_close(sessionBuilder); +} + +static inline void encodeBackForwardListState(GVariantBuilder* sessionBuilder, const BackForwardListState& backForwardListState) +{ + g_variant_builder_open(sessionBuilder, G_VARIANT_TYPE("a" BACK_FORWARD_LIST_ITEM_TYPE_STRING_V1)); + for (const auto& item : backForwardListState.items) + encodeBackForwardListItemState(sessionBuilder, item); + g_variant_builder_close(sessionBuilder); + + if (backForwardListState.currentIndex) + g_variant_builder_add(sessionBuilder, "mu", TRUE, backForwardListState.currentIndex.value()); + else + g_variant_builder_add(sessionBuilder, "mu", FALSE); +} + +static GBytes* encodeSessionState(const SessionState& sessionState) +{ + GVariantBuilder sessionBuilder; + g_variant_builder_init(&sessionBuilder, G_VARIANT_TYPE(SESSION_STATE_TYPE_STRING_V1)); + g_variant_builder_add(&sessionBuilder, "q", g_sessionStateVersion); + encodeBackForwardListState(&sessionBuilder, sessionState.backForwardListState); + GRefPtr<GVariant> variant = g_variant_builder_end(&sessionBuilder); + return g_variant_get_data_as_bytes(variant.get()); +} + +static inline bool decodeHTTPBody(GVariant* httpBodyVariant, HTTPBody& httpBody) +{ + gboolean hasHTTPBody; + const char* contentType; + GUniqueOutPtr<GVariantIter> elementsIter; + g_variant_get(httpBodyVariant, HTTP_BODY_FORMAT_STRING_V1, &hasHTTPBody, &contentType, &elementsIter.outPtr()); + if (!hasHTTPBody) + return false; + httpBody.contentType = String::fromUTF8(contentType); + gsize elementsLength = g_variant_iter_n_children(elementsIter.get()); + if (!elementsLength) + return true; + httpBody.elements.reserveInitialCapacity(elementsLength); + unsigned type; + GVariantIter* dataIter; + const char* filePath; + gint64 fileStart; + gboolean hasFileLength; + gint64 fileLength; + gboolean hasFileModificationTime; + gdouble fileModificationTime; + const char* blobURLString; + while (g_variant_iter_loop(elementsIter.get(), HTTP_BODY_ELEMENT_FORMAT_STRING_V1, &type, &dataIter, &filePath, &fileStart, &hasFileLength, &fileLength, &hasFileModificationTime, &fileModificationTime, &blobURLString)) { + HTTPBody::Element element; + element.type = toHTTPBodyElementType(type); + if (gsize dataLength = g_variant_iter_n_children(dataIter)) { + element.data.reserveInitialCapacity(dataLength); + guchar dataValue; + while (g_variant_iter_next(dataIter, "y", &dataValue)) + element.data.uncheckedAppend(dataValue); + } + element.filePath = String::fromUTF8(filePath); + element.fileStart = fileStart; + if (hasFileLength) + element.fileLength = fileLength; + if (hasFileModificationTime) + element.expectedFileModificationTime = fileModificationTime; + element.blobURLString = String::fromUTF8(blobURLString); + + httpBody.elements.uncheckedAppend(WTFMove(element)); + } + + return true; +} + +static inline void decodeFrameState(GVariant* frameStateVariant, FrameState& frameState) +{ + const char* urlString; + const char* originalURLString; + const char* referrer; + const char* target; + GUniqueOutPtr<GVariantIter> documentStateIter; + GUniqueOutPtr<GVariantIter> stateObjectDataIter; + gint64 documentSequenceNumber; + gint64 itemSequenceNumber; + gint32 scrollPositionX, scrollPositionY; + gdouble pageScaleFactor; + GVariant* httpBodyVariant; + GUniqueOutPtr<GVariantIter> childrenIter; + g_variant_get(frameStateVariant, FRAME_STATE_FORMAT_STRING_V1, &urlString, &originalURLString, &referrer, &target, + &documentStateIter.outPtr(), &stateObjectDataIter.outPtr(), &documentSequenceNumber, &itemSequenceNumber, + &scrollPositionX, &scrollPositionY, &pageScaleFactor, &httpBodyVariant, &childrenIter.outPtr()); + frameState.urlString = String::fromUTF8(urlString); + frameState.originalURLString = String::fromUTF8(originalURLString); + frameState.referrer = String::fromUTF8(referrer); + frameState.target = String::fromUTF8(target); + if (gsize documentStateLength = g_variant_iter_n_children(documentStateIter.get())) { + frameState.documentState.reserveInitialCapacity(documentStateLength); + const char* documentStateString; + while (g_variant_iter_next(documentStateIter.get(), "&s", &documentStateString)) + frameState.documentState.uncheckedAppend(String::fromUTF8(documentStateString)); + } + if (stateObjectDataIter) { + Vector<uint8_t> stateObjectVector; + if (gsize stateObjectDataLength = g_variant_iter_n_children(stateObjectDataIter.get())) { + stateObjectVector.reserveInitialCapacity(stateObjectDataLength); + guchar stateObjectDataValue; + while (g_variant_iter_next(stateObjectDataIter.get(), "y", &stateObjectDataValue)) + stateObjectVector.uncheckedAppend(stateObjectDataValue); + } + frameState.stateObjectData = WTFMove(stateObjectVector); + } + frameState.documentSequenceNumber = documentSequenceNumber; + frameState.itemSequenceNumber = itemSequenceNumber; + frameState.scrollPosition.setX(scrollPositionX); + frameState.scrollPosition.setY(scrollPositionY); + frameState.pageScaleFactor = pageScaleFactor; + HTTPBody httpBody; + if (decodeHTTPBody(httpBodyVariant, httpBody)) + frameState.httpBody = WTFMove(httpBody); + g_variant_unref(httpBodyVariant); + while (GRefPtr<GVariant> child = adoptGRef(g_variant_iter_next_value(childrenIter.get()))) { + FrameState childFrameState; + GRefPtr<GVariant> childVariant = adoptGRef(g_variant_get_variant(child.get())); + decodeFrameState(childVariant.get(), childFrameState); + frameState.children.append(WTFMove(childFrameState)); + } +} + +static inline void decodeBackForwardListItemState(GVariantIter* backForwardListStateIter, BackForwardListState& backForwardListState) +{ + gsize backForwardListStateLength = g_variant_iter_n_children(backForwardListStateIter); + if (!backForwardListStateLength) + return; + + backForwardListState.items.reserveInitialCapacity(backForwardListStateLength); + guint64 identifier; + const char* title; + GVariant* frameStateVariant; + unsigned shouldOpenExternalURLsPolicy; + while (g_variant_iter_loop(backForwardListStateIter, BACK_FORWARD_LIST_ITEM_FORMAT_STRING_V1, &identifier, &title, &frameStateVariant, &shouldOpenExternalURLsPolicy)) { + BackForwardListItemState state; + state.identifier = identifier; + state.pageState.title = String::fromUTF8(title); + decodeFrameState(frameStateVariant, state.pageState.mainFrameState); + state.pageState.shouldOpenExternalURLsPolicy = toWebCoreExternalURLsPolicy(shouldOpenExternalURLsPolicy); + backForwardListState.items.uncheckedAppend(WTFMove(state)); + } +} + +static bool decodeSessionState(GBytes* data, SessionState& sessionState) +{ + GRefPtr<GVariant> variant = g_variant_new_from_bytes(G_VARIANT_TYPE(SESSION_STATE_TYPE_STRING_V1), data, FALSE); + if (!g_variant_is_normal_form(variant.get())) + return false; + + guint16 version; + GUniqueOutPtr<GVariantIter> backForwardListStateIter; + gboolean hasCurrentIndex; + guint32 currentIndex; + g_variant_get(variant.get(), SESSION_STATE_TYPE_STRING_V1, &version, &backForwardListStateIter.outPtr(), &hasCurrentIndex, ¤tIndex); + if (!version || version > g_sessionStateVersion) + return false; + + decodeBackForwardListItemState(backForwardListStateIter.get(), sessionState.backForwardListState); + + if (hasCurrentIndex) + sessionState.backForwardListState.currentIndex = currentIndex; + return true; +} + +WebKitWebViewSessionState* webkitWebViewSessionStateCreate(SessionState&& sessionState) +{ + WebKitWebViewSessionState* state = static_cast<WebKitWebViewSessionState*>(fastMalloc(sizeof(WebKitWebViewSessionState))); + new (state) WebKitWebViewSessionState(WTFMove(sessionState)); + return state; +} + +const SessionState& webkitWebViewSessionStateGetSessionState(WebKitWebViewSessionState* state) +{ + return state->sessionState; +} + +/** + * webkit_web_view_session_state_new: + * @data: a #GBytes + * + * Creates a new #WebKitWebViewSessionState from serialized data. + * + * Returns: (transfer full): a new #WebKitWebViewSessionState, or %NULL if @data doesn't contain a + * valid serialized #WebKitWebViewSessionState. + * + * Since: 2.12 + */ +WebKitWebViewSessionState* webkit_web_view_session_state_new(GBytes* data) +{ + g_return_val_if_fail(data, nullptr); + + SessionState sessionState; + if (!decodeSessionState(data, sessionState)) + return nullptr; + return webkitWebViewSessionStateCreate(WTFMove(sessionState)); +} + +/** + * webkit_web_view_session_state_ref: + * @state: a #WebKitWebViewSessionState + * + * Atomically increments the reference count of @state by one. This + * function is MT-safe and may be called from any thread. + * + * Returns: The passed in #WebKitWebViewSessionState + * + * Since: 2.12 + */ +WebKitWebViewSessionState* webkit_web_view_session_state_ref(WebKitWebViewSessionState* state) +{ + g_return_val_if_fail(state, nullptr); + g_atomic_int_inc(&state->referenceCount); + return state; +} + +/** + * webkit_web_view_session_state_unref: + * @state: a #WebKitWebViewSessionState + * + * Atomically decrements the reference count of @state by one. If the + * reference count drops to 0, all memory allocated by the #WebKitWebViewSessionState is + * released. This function is MT-safe and may be called from any thread. + * + * Since: 2.12 + */ +void webkit_web_view_session_state_unref(WebKitWebViewSessionState* state) +{ + g_return_if_fail(state); + if (g_atomic_int_dec_and_test(&state->referenceCount)) { + state->~WebKitWebViewSessionState(); + fastFree(state); + } +} + +/** + * webkit_web_view_session_state_serialize: + * @state: a #WebKitWebViewSessionState + * + * Serializes a #WebKitWebViewSessionState. + * + * Returns: (transfer full): a #GBytes containing the @state serialized. + * + * Since: 2.12 + */ +GBytes* webkit_web_view_session_state_serialize(WebKitWebViewSessionState* state) +{ + g_return_val_if_fail(state, nullptr); + + return encodeSessionState(state->sessionState); +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitCertificateInfo.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewSessionState.h index eef16405e..73f4a4a69 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitCertificateInfo.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewSessionState.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Samsung Electronics Inc. All rights reserved. + * Copyright (C) 2016 Igalia S.L. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -21,33 +21,32 @@ #error "Only <webkit2/webkit2.h> can be included directly." #endif -#ifndef WebKitCertificateInfo_h -#define WebKitCertificateInfo_h +#ifndef WebKitWebViewSessionState_h +#define WebKitWebViewSessionState_h -#include <gio/gio.h> #include <glib-object.h> #include <webkit2/WebKitDefines.h> G_BEGIN_DECLS -#define WEBKIT_TYPE_CERTIFICATE_INFO (webkit_certificate_info_get_type()) +#define WEBKIT_TYPE_WEB_VIEW_SESSION_STATE (webkit_web_view_session_state_get_type()) -typedef struct _WebKitCertificateInfo WebKitCertificateInfo; +typedef struct _WebKitWebViewSessionState WebKitWebViewSessionState; WEBKIT_API GType -webkit_certificate_info_get_type (void); +webkit_web_view_session_state_get_type (void); -WEBKIT_API WebKitCertificateInfo * -webkit_certificate_info_copy (WebKitCertificateInfo *info); +WEBKIT_API WebKitWebViewSessionState * +webkit_web_view_session_state_new (GBytes *data); -WEBKIT_API void -webkit_certificate_info_free (WebKitCertificateInfo *info); +WEBKIT_API WebKitWebViewSessionState * +webkit_web_view_session_state_ref (WebKitWebViewSessionState *state); -WEBKIT_API GTlsCertificate * -webkit_certificate_info_get_tls_certificate (WebKitCertificateInfo *info); +WEBKIT_API void +webkit_web_view_session_state_unref (WebKitWebViewSessionState *state); -WEBKIT_API GTlsCertificateFlags -webkit_certificate_info_get_tls_errors (WebKitCertificateInfo *info); +WEBKIT_API GBytes * +webkit_web_view_session_state_serialize (WebKitWebViewSessionState *state); G_END_DECLS diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewSessionStatePrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewSessionStatePrivate.h new file mode 100644 index 000000000..4c7f4e15a --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewSessionStatePrivate.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2015 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "SessionState.h" +#include "WebKitWebViewSessionState.h" + +#ifndef WebKitWebViewSessionStatePrivate_h +#define WebKitWebViewSessionStatePrivate_h + +WebKitWebViewSessionState* webkitWebViewSessionStateCreate(WebKit::SessionState&&); +const WebKit::SessionState& webkitWebViewSessionStateGetSessionState(WebKitWebViewSessionState*); + +#endif // WebKitWebViewSessionStatePrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebsiteDataManager.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebsiteDataManager.cpp new file mode 100644 index 000000000..77d56effe --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebsiteDataManager.cpp @@ -0,0 +1,485 @@ +/* + * Copyright (C) 2015 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2,1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "WebKitWebsiteDataManager.h" + +#include "APIWebsiteDataStore.h" +#include "WebKitWebsiteDataManagerPrivate.h" +#include <WebCore/FileSystem.h> +#include <glib/gi18n-lib.h> +#include <wtf/glib/GUniquePtr.h> + +using namespace WebKit; + +/** + * SECTION: WebKitWebsiteDataManager + * @Short_description: Website data manager + * @Title: WebKitWebsiteDataManager + * @See_also: #WebKitWebContext + * + * WebKitWebsiteDataManager allows you to manage the data that websites + * can store in the client file system like databases or caches. + * You can use WebKitWebsiteDataManager to configure the local directories + * where the Website data will be stored, by creating a new manager with + * webkit_website_data_manager_new() passing the values you want to set. + * You can set all the possible configuration values or only some of them, + * a default value will be used automatically for the configuration options + * not provided. #WebKitWebsiteDataManager:base-data-directory and + * #WebKitWebsiteDataManager:base-cache-directory are two special properties + * that can be used to set a common base directory for all Website data and + * caches. It's possible to provide both, a base directory and a specific value, + * but in that case, the specific value takes precedence over the base directory. + * The newly created WebKitWebsiteDataManager must be passed as a construct property + * to a #WebKitWebContext, you can use webkit_web_context_new_with_website_data_manager() + * to create a new #WebKitWebContext with a WebKitWebsiteDataManager. + * In case you don't want to set any specific configuration, you don't need to create + * a WebKitWebsiteDataManager, the #WebKitWebContext will create a WebKitWebsiteDataManager + * with the default configuration. To get the WebKitWebsiteDataManager of a #WebKitWebContext + * you can use webkit_web_context_get_website_data_manager(). + * + * Since: 2.10 + */ + +enum { + PROP_0, + + PROP_BASE_DATA_DIRECTORY, + PROP_BASE_CACHE_DIRECTORY, + PROP_LOCAL_STORAGE_DIRECTORY, + PROP_DISK_CACHE_DIRECTORY, + PROP_APPLICATION_CACHE_DIRECTORY, + PROP_INDEXEDDB_DIRECTORY, + PROP_WEBSQL_DIRECTORY +}; + +struct _WebKitWebsiteDataManagerPrivate { + RefPtr<API::WebsiteDataStore> websiteDataStore; + GUniquePtr<char> baseDataDirectory; + GUniquePtr<char> baseCacheDirectory; + GUniquePtr<char> localStorageDirectory; + GUniquePtr<char> diskCacheDirectory; + GUniquePtr<char> applicationCacheDirectory; + GUniquePtr<char> indexedDBDirectory; + GUniquePtr<char> webSQLDirectory; +}; + +WEBKIT_DEFINE_TYPE(WebKitWebsiteDataManager, webkit_website_data_manager, G_TYPE_OBJECT) + +static void webkitWebsiteDataManagerGetProperty(GObject* object, guint propID, GValue* value, GParamSpec* paramSpec) +{ + WebKitWebsiteDataManager* manager = WEBKIT_WEBSITE_DATA_MANAGER(object); + + switch (propID) { + case PROP_BASE_DATA_DIRECTORY: + g_value_set_string(value, webkit_website_data_manager_get_base_data_directory(manager)); + break; + case PROP_BASE_CACHE_DIRECTORY: + g_value_set_string(value, webkit_website_data_manager_get_base_cache_directory(manager)); + break; + case PROP_LOCAL_STORAGE_DIRECTORY: + g_value_set_string(value, webkit_website_data_manager_get_local_storage_directory(manager)); + break; + case PROP_DISK_CACHE_DIRECTORY: + g_value_set_string(value, webkit_website_data_manager_get_disk_cache_directory(manager)); + break; + case PROP_APPLICATION_CACHE_DIRECTORY: + g_value_set_string(value, webkit_website_data_manager_get_offline_application_cache_directory(manager)); + break; + case PROP_INDEXEDDB_DIRECTORY: + g_value_set_string(value, webkit_website_data_manager_get_indexeddb_directory(manager)); + break; + case PROP_WEBSQL_DIRECTORY: + g_value_set_string(value, webkit_website_data_manager_get_websql_directory(manager)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propID, paramSpec); + } +} + +static void webkitWebsiteDataManagerSetProperty(GObject* object, guint propID, const GValue* value, GParamSpec* paramSpec) +{ + WebKitWebsiteDataManager* manager = WEBKIT_WEBSITE_DATA_MANAGER(object); + + switch (propID) { + case PROP_BASE_DATA_DIRECTORY: + manager->priv->baseDataDirectory.reset(g_value_dup_string(value)); + break; + case PROP_BASE_CACHE_DIRECTORY: + manager->priv->baseCacheDirectory.reset(g_value_dup_string(value)); + break; + case PROP_LOCAL_STORAGE_DIRECTORY: + manager->priv->localStorageDirectory.reset(g_value_dup_string(value)); + break; + case PROP_DISK_CACHE_DIRECTORY: + manager->priv->diskCacheDirectory.reset(g_value_dup_string(value)); + break; + case PROP_APPLICATION_CACHE_DIRECTORY: + manager->priv->applicationCacheDirectory.reset(g_value_dup_string(value)); + break; + case PROP_INDEXEDDB_DIRECTORY: + manager->priv->indexedDBDirectory.reset(g_value_dup_string(value)); + break; + case PROP_WEBSQL_DIRECTORY: + manager->priv->webSQLDirectory.reset(g_value_dup_string(value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propID, paramSpec); + } +} + +static void webkitWebsiteDataManagerConstructed(GObject* object) +{ + G_OBJECT_CLASS(webkit_website_data_manager_parent_class)->constructed(object); + + WebKitWebsiteDataManagerPrivate* priv = WEBKIT_WEBSITE_DATA_MANAGER(object)->priv; + if (priv->baseDataDirectory) { + if (!priv->localStorageDirectory) + priv->localStorageDirectory.reset(g_build_filename(priv->baseDataDirectory.get(), "localstorage", nullptr)); + if (!priv->indexedDBDirectory) + priv->indexedDBDirectory.reset(g_build_filename(priv->baseDataDirectory.get(), "databases", "indexeddb", nullptr)); + if (!priv->webSQLDirectory) + priv->webSQLDirectory.reset(g_build_filename(priv->baseDataDirectory.get(), "databases", nullptr)); + } + + if (priv->baseCacheDirectory) { + if (!priv->diskCacheDirectory) + priv->diskCacheDirectory.reset(g_strdup(priv->baseCacheDirectory.get())); + if (!priv->applicationCacheDirectory) + priv->applicationCacheDirectory.reset(g_build_filename(priv->baseCacheDirectory.get(), "applications", nullptr)); + } +} + +static void webkit_website_data_manager_class_init(WebKitWebsiteDataManagerClass* findClass) +{ + GObjectClass* gObjectClass = G_OBJECT_CLASS(findClass); + + gObjectClass->get_property = webkitWebsiteDataManagerGetProperty; + gObjectClass->set_property = webkitWebsiteDataManagerSetProperty; + gObjectClass->constructed = webkitWebsiteDataManagerConstructed; + + /** + * WebKitWebsiteDataManager:base-data-directory: + * + * The base directory for Website data. This is used as a base directory + * for any Website data when no specific data directory has been provided. + * + * Since: 2.10 + */ + g_object_class_install_property( + gObjectClass, + PROP_BASE_DATA_DIRECTORY, + g_param_spec_string( + "base-data-directory", + _("Base Data Directory"), + _("The base directory for Website data"), + nullptr, + static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); + + /** + * WebKitWebsiteDataManager:base-cache-directory: + * + * The base directory for Website cache. This is used as a base directory + * for any Website cache when no specific cache directory has been provided. + * + * Since: 2.10 + */ + g_object_class_install_property( + gObjectClass, + PROP_BASE_CACHE_DIRECTORY, + g_param_spec_string( + "base-cache-directory", + _("Base Cache Directory"), + _("The base directory for Website cache"), + nullptr, + static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); + + /** + * WebKitWebsiteDataManager:local-storage-directory: + * + * The directory where local storage data will be stored. + * + * Since: 2.10 + */ + g_object_class_install_property( + gObjectClass, + PROP_LOCAL_STORAGE_DIRECTORY, + g_param_spec_string( + "local-storage-directory", + _("Local Storage Directory"), + _("The directory where local storage data will be stored"), + nullptr, + static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); + + /** + * WebKitWebsiteDataManager:disk-cache-directory: + * + * The directory where HTTP disk cache will be stored. + * + * Since: 2.10 + */ + g_object_class_install_property( + gObjectClass, + PROP_DISK_CACHE_DIRECTORY, + g_param_spec_string( + "disk-cache-directory", + _("Disk Cache Directory"), + _("The directory where HTTP disk cache will be stored"), + nullptr, + static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); + + /** + * WebKitWebsiteDataManager:offline-application-cache-directory: + * + * The directory where offline web application cache will be stored. + * + * Since: 2.10 + */ + g_object_class_install_property( + gObjectClass, + PROP_APPLICATION_CACHE_DIRECTORY, + g_param_spec_string( + "offline-application-cache-directory", + _("Offline Web Application Cache Directory"), + _("The directory where offline web application cache will be stored"), + nullptr, + static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); + + /** + * WebKitWebsiteDataManager:indexeddb-directory: + * + * The directory where IndexedDB databases will be stored. + * + * Since: 2.10 + */ + g_object_class_install_property( + gObjectClass, + PROP_INDEXEDDB_DIRECTORY, + g_param_spec_string( + "indexeddb-directory", + _("IndexedDB Directory"), + _("The directory where IndexedDB databases will be stored"), + nullptr, + static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); + + /** + * WebKitWebsiteDataManager:websql-directory: + * + * The directory where WebSQL databases will be stored. + * + * Since: 2.10 + */ + g_object_class_install_property( + gObjectClass, + PROP_WEBSQL_DIRECTORY, + g_param_spec_string( + "websql-directory", + _("WebSQL Directory"), + _("The directory where WebSQL databases will be stored"), + nullptr, + static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); +} + +WebKitWebsiteDataManager* webkitWebsiteDataManagerCreate(WebsiteDataStore::Configuration&& configuration) +{ + WebKitWebsiteDataManager* manager = WEBKIT_WEBSITE_DATA_MANAGER(g_object_new(WEBKIT_TYPE_WEBSITE_DATA_MANAGER, nullptr)); + manager->priv->websiteDataStore = API::WebsiteDataStore::create(WTFMove(configuration)); + + return manager; +} + +API::WebsiteDataStore& webkitWebsiteDataManagerGetDataStore(WebKitWebsiteDataManager* manager) +{ + WebKitWebsiteDataManagerPrivate* priv = manager->priv; + if (!priv->websiteDataStore) { + WebsiteDataStore::Configuration configuration; + configuration.localStorageDirectory = !priv->localStorageDirectory ? + API::WebsiteDataStore::defaultLocalStorageDirectory() : WebCore::filenameToString(priv->localStorageDirectory.get()); + configuration.networkCacheDirectory = !priv->diskCacheDirectory ? + API::WebsiteDataStore::defaultNetworkCacheDirectory() : WebCore::pathByAppendingComponent(WebCore::filenameToString(priv->diskCacheDirectory.get()), networkCacheSubdirectory); + configuration.applicationCacheDirectory = !priv->applicationCacheDirectory ? + API::WebsiteDataStore::defaultApplicationCacheDirectory() : WebCore::filenameToString(priv->applicationCacheDirectory.get()); + configuration.webSQLDatabaseDirectory = !priv->webSQLDirectory ? + API::WebsiteDataStore::defaultWebSQLDatabaseDirectory() : WebCore::filenameToString(priv->webSQLDirectory.get()); + configuration.mediaKeysStorageDirectory = API::WebsiteDataStore::defaultMediaKeysStorageDirectory(); + priv->websiteDataStore = API::WebsiteDataStore::create(WTFMove(configuration)); + } + + return *priv->websiteDataStore; +} + +/** + * webkit_website_data_manager_new: + * @first_option_name: name of the first option to set + * @...: value of first option, followed by more options, %NULL-terminated + * + * Creates a new #WebKitWebsiteDataManager with the given options. It must + * be passed as construction parameter of a #WebKitWebContext. + * + * Returns: (transfer full): the newly created #WebKitWebsiteDataManager + * + * Since: 2.10 + */ +WebKitWebsiteDataManager* webkit_website_data_manager_new(const gchar* firstOptionName, ...) +{ + va_list args; + va_start(args, firstOptionName); + WebKitWebsiteDataManager* manager = WEBKIT_WEBSITE_DATA_MANAGER(g_object_new_valist(WEBKIT_TYPE_WEBSITE_DATA_MANAGER, firstOptionName, args)); + va_end(args); + + return manager; +} + +/** + * webkit_website_data_manager_get_base_data_directory: + * @manager: a #WebKitWebsiteDataManager + * + * Get the #WebKitWebsiteDataManager:base-data-directory property. + * + * Returns: the base directory for Website data, or %NULL if + * #WebKitWebsiteDataManager:base-data-directory was not provided. + * + * Since: 2.10 + */ +const gchar* webkit_website_data_manager_get_base_data_directory(WebKitWebsiteDataManager* manager) +{ + g_return_val_if_fail(WEBKIT_IS_WEBSITE_DATA_MANAGER(manager), nullptr); + + return manager->priv->baseDataDirectory.get(); +} + +/** + * webkit_website_data_manager_get_base_cache_directory: + * @manager: a #WebKitWebsiteDataManager + * + * Get the #WebKitWebsiteDataManager:base-cache-directory property. + * + * Returns: the base directory for Website cache, or %NULL if + * #WebKitWebsiteDataManager:base-cache-directory was not provided. + * + * Since: 2.10 + */ +const gchar* webkit_website_data_manager_get_base_cache_directory(WebKitWebsiteDataManager* manager) +{ + g_return_val_if_fail(WEBKIT_IS_WEBSITE_DATA_MANAGER(manager), nullptr); + + return manager->priv->baseCacheDirectory.get(); +} + +/** + * webkit_website_data_manager_get_local_storage_directory: + * @manager: a #WebKitWebsiteDataManager + * + * Get the #WebKitWebsiteDataManager:local-storage-directory property. + * + * Returns: the directory where local storage data is stored. + * + * Since: 2.10 + */ +const gchar* webkit_website_data_manager_get_local_storage_directory(WebKitWebsiteDataManager* manager) +{ + g_return_val_if_fail(WEBKIT_IS_WEBSITE_DATA_MANAGER(manager), nullptr); + + WebKitWebsiteDataManagerPrivate* priv = manager->priv; + if (!priv->localStorageDirectory) + priv->localStorageDirectory.reset(g_strdup(API::WebsiteDataStore::defaultLocalStorageDirectory().utf8().data())); + return priv->localStorageDirectory.get(); +} + +/** + * webkit_website_data_manager_get_disk_cache_directory: + * @manager: a #WebKitWebsiteDataManager + * + * Get the #WebKitWebsiteDataManager:disk-cache-directory property. + * + * Returns: the directory where HTTP disk cache is stored. + * + * Since: 2.10 + */ +const gchar* webkit_website_data_manager_get_disk_cache_directory(WebKitWebsiteDataManager* manager) +{ + g_return_val_if_fail(WEBKIT_IS_WEBSITE_DATA_MANAGER(manager), nullptr); + + WebKitWebsiteDataManagerPrivate* priv = manager->priv; + if (!priv->diskCacheDirectory) { + // The default directory already has the subdirectory. + priv->diskCacheDirectory.reset(g_strdup(WebCore::directoryName(API::WebsiteDataStore::defaultNetworkCacheDirectory()).utf8().data())); + } + return priv->diskCacheDirectory.get(); +} + +/** + * webkit_website_data_manager_get_offline_application_cache_directory: + * @manager: a #WebKitWebsiteDataManager + * + * Get the #WebKitWebsiteDataManager:offline-application-cache-directory property. + * + * Returns: the directory where offline web application cache is stored. + * + * Since: 2.10 + */ +const gchar* webkit_website_data_manager_get_offline_application_cache_directory(WebKitWebsiteDataManager* manager) +{ + g_return_val_if_fail(WEBKIT_IS_WEBSITE_DATA_MANAGER(manager), nullptr); + + WebKitWebsiteDataManagerPrivate* priv = manager->priv; + if (!priv->applicationCacheDirectory) + priv->applicationCacheDirectory.reset(g_strdup(API::WebsiteDataStore::defaultApplicationCacheDirectory().utf8().data())); + return priv->applicationCacheDirectory.get(); +} + +/** + * webkit_website_data_manager_get_indexeddb_directory: + * @manager: a #WebKitWebsiteDataManager + * + * Get the #WebKitWebsiteDataManager:indexeddb-directory property. + * + * Returns: the directory where IndexedDB databases are stored. + * + * Since: 2.10 + */ +const gchar* webkit_website_data_manager_get_indexeddb_directory(WebKitWebsiteDataManager* manager) +{ + g_return_val_if_fail(WEBKIT_IS_WEBSITE_DATA_MANAGER(manager), nullptr); + + WebKitWebsiteDataManagerPrivate* priv = manager->priv; + if (!priv->indexedDBDirectory) + priv->indexedDBDirectory.reset(g_strdup(API::WebsiteDataStore::defaultIndexedDBDatabaseDirectory().utf8().data())); + return priv->indexedDBDirectory.get(); +} + +/** + * webkit_website_data_manager_get_websql_directory: + * @manager: a #WebKitWebsiteDataManager + * + * Get the #WebKitWebsiteDataManager:websql-directory property. + * + * Returns: the directory where WebSQL databases are stored. + * + * Since: 2.10 + */ +const gchar* webkit_website_data_manager_get_websql_directory(WebKitWebsiteDataManager* manager) +{ + g_return_val_if_fail(WEBKIT_IS_WEBSITE_DATA_MANAGER(manager), nullptr); + + WebKitWebsiteDataManagerPrivate* priv = manager->priv; + if (!priv->webSQLDirectory) + priv->webSQLDirectory.reset(g_strdup(API::WebsiteDataStore::defaultWebSQLDatabaseDirectory().utf8().data())); + return priv->webSQLDirectory.get(); +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebsiteDataManager.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebsiteDataManager.h new file mode 100644 index 000000000..e9d85918c --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebsiteDataManager.h @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2015 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2,1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) +#error "Only <webkit2/webkit2.h> can be included directly." +#endif + +#ifndef WebKitWebsiteDataManager_h +#define WebKitWebsiteDataManager_h + +#include <glib-object.h> +#include <webkit2/WebKitDefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_WEBSITE_DATA_MANAGER (webkit_website_data_manager_get_type()) +#define WEBKIT_WEBSITE_DATA_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEBSITE_DATA_MANAGER, WebKitWebsiteDataManager)) +#define WEBKIT_IS_WEBSITE_DATA_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEBSITE_DATA_MANAGER)) +#define WEBKIT_WEBSITE_DATA_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_WEBSITE_DATA_MANAGER, WebKitWebsiteDataManagerClass)) +#define WEBKIT_IS_WEBSITE_DATA_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_WEBSITE_DATA_MANAGER)) +#define WEBKIT_WEBSITE_DATA_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_WEBSITE_DATA_MANAGER, WebKitWebsiteDataManagerClass)) + +typedef struct _WebKitWebsiteDataManager WebKitWebsiteDataManager; +typedef struct _WebKitWebsiteDataManagerClass WebKitWebsiteDataManagerClass; +typedef struct _WebKitWebsiteDataManagerPrivate WebKitWebsiteDataManagerPrivate; + +struct _WebKitWebsiteDataManager { + GObject parent; + + WebKitWebsiteDataManagerPrivate *priv; +}; + +struct _WebKitWebsiteDataManagerClass { + GObjectClass parent_class; + + void (*_webkit_reserved0) (void); + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); +}; + +WEBKIT_API GType +webkit_website_data_manager_get_type (void); + +WEBKIT_API WebKitWebsiteDataManager * +webkit_website_data_manager_new (const gchar *first_option_name, + ...); +WEBKIT_API const gchar * +webkit_website_data_manager_get_base_data_directory (WebKitWebsiteDataManager *manager); + +WEBKIT_API const gchar * +webkit_website_data_manager_get_base_cache_directory (WebKitWebsiteDataManager *manager); + +WEBKIT_API const gchar * +webkit_website_data_manager_get_local_storage_directory (WebKitWebsiteDataManager *manager); + +WEBKIT_API const gchar * +webkit_website_data_manager_get_disk_cache_directory (WebKitWebsiteDataManager *manager); + +WEBKIT_API const gchar * +webkit_website_data_manager_get_offline_application_cache_directory (WebKitWebsiteDataManager *manager); + +WEBKIT_API const gchar * +webkit_website_data_manager_get_indexeddb_directory (WebKitWebsiteDataManager *manager); + +WEBKIT_API const gchar * +webkit_website_data_manager_get_websql_directory (WebKitWebsiteDataManager *manager); + +G_END_DECLS + +#endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebsiteDataManagerPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebsiteDataManagerPrivate.h new file mode 100644 index 000000000..a00b06075 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebsiteDataManagerPrivate.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2015 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef WebKitWebsiteDataManagerPrivate_h +#define WebKitWebsiteDataManagerPrivate_h + +#include "APIWebsiteDataStore.h" +#include "WebKitPrivate.h" +#include "WebsiteDataStore.h" + +WebKitWebsiteDataManager* webkitWebsiteDataManagerCreate(WebKit::WebsiteDataStore::Configuration&&); +API::WebsiteDataStore& webkitWebsiteDataManagerGetDataStore(WebKitWebsiteDataManager*); + +#endif // WebKitWebsiteDataManagerPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWindowProperties.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWindowProperties.cpp index a40e6db4d..5e225db78 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWindowProperties.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWindowProperties.cpp @@ -20,12 +20,13 @@ #include "config.h" #include "WebKitWindowProperties.h" +#include "APIDictionary.h" #include "APINumber.h" #include "APIURLRequest.h" -#include "ImmutableDictionary.h" #include "WebKitPrivate.h" #include "WebKitWindowPropertiesPrivate.h" #include <WebCore/IntRect.h> +#include <WebCore/WindowFeatures.h> #include <glib/gi18n-lib.h> using namespace WebKit; @@ -374,54 +375,26 @@ void webkitWindowPropertiesSetFullscreen(WebKitWindowProperties* windowPropertie g_object_notify(G_OBJECT(windowProperties), "fullscreen"); } -void webkitWindowPropertiesUpdateFromWebWindowFeatures(WebKitWindowProperties* windowProperties, ImmutableDictionary* features) +void webkitWindowPropertiesUpdateFromWebWindowFeatures(WebKitWindowProperties* windowProperties, const WindowFeatures& windowFeatures) { GdkRectangle geometry = windowProperties->priv->geometry; - - API::Double* doubleValue = static_cast<API::Double*>(features->get("x")); - if (doubleValue) - geometry.x = doubleValue->value(); - - doubleValue = static_cast<API::Double*>(features->get("y")); - if (doubleValue) - geometry.y = doubleValue->value(); - - doubleValue = static_cast<API::Double*>(features->get("width")); - if (doubleValue) - geometry.width = doubleValue->value(); - - doubleValue = static_cast<API::Double*>(features->get("height")); - if (doubleValue) - geometry.height = doubleValue->value(); + if (windowFeatures.x) + geometry.x = *windowFeatures.x; + if (windowFeatures.y) + geometry.y = *windowFeatures.y; + if (windowFeatures.width) + geometry.width = *windowFeatures.width; + if (windowFeatures.height) + geometry.height = *windowFeatures.height; webkitWindowPropertiesSetGeometry(windowProperties, &geometry); - API::Boolean* booleanValue = static_cast<API::Boolean*>(features->get("menuBarVisible")); - if (booleanValue) - webkitWindowPropertiesSetMenubarVisible(windowProperties, booleanValue->value()); - - booleanValue = static_cast<API::Boolean*>(features->get("statusBarVisible")); - if (booleanValue) - webkitWindowPropertiesSetStatusbarVisible(windowProperties, booleanValue->value()); - - booleanValue = static_cast<API::Boolean*>(features->get("toolBarVisible")); - if (booleanValue) - webkitWindowPropertiesSetToolbarVisible(windowProperties, booleanValue->value()); - - booleanValue = static_cast<API::Boolean*>(features->get("locationBarVisible")); - if (booleanValue) - webkitWindowPropertiesSetLocationbarVisible(windowProperties, booleanValue->value()); - - booleanValue = static_cast<API::Boolean*>(features->get("scrollbarsVisible")); - if (booleanValue) - webkitWindowPropertiesSetScrollbarsVisible(windowProperties, booleanValue->value()); - - booleanValue = static_cast<API::Boolean*>(features->get("resizable")); - if (booleanValue) - webkitWindowPropertiesSetResizable(windowProperties, booleanValue->value()); - - booleanValue = static_cast<API::Boolean*>(features->get("fullscreen")); - if (booleanValue) - webkitWindowPropertiesSetFullscreen(windowProperties, booleanValue->value()); + webkitWindowPropertiesSetMenubarVisible(windowProperties, windowFeatures.menuBarVisible); + webkitWindowPropertiesSetStatusbarVisible(windowProperties, windowFeatures.statusBarVisible); + webkitWindowPropertiesSetToolbarVisible(windowProperties, windowFeatures.toolBarVisible); + webkitWindowPropertiesSetLocationbarVisible(windowProperties, windowFeatures.locationBarVisible); + webkitWindowPropertiesSetScrollbarsVisible(windowProperties, windowFeatures.scrollbarsVisible); + webkitWindowPropertiesSetResizable(windowProperties, windowFeatures.resizable); + webkitWindowPropertiesSetFullscreen(windowProperties, windowFeatures.fullscreen); } /** diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWindowPropertiesPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWindowPropertiesPrivate.h index 8ec17b4ea..05e4b9be0 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWindowPropertiesPrivate.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWindowPropertiesPrivate.h @@ -31,7 +31,7 @@ #include "WebKitWindowProperties.h" WebKitWindowProperties* webkitWindowPropertiesCreate(); -void webkitWindowPropertiesUpdateFromWebWindowFeatures(WebKitWindowProperties*, WebKit::ImmutableDictionary* features); +void webkitWindowPropertiesUpdateFromWebWindowFeatures(WebKitWindowProperties*, const WebCore::WindowFeatures&); void webkitWindowPropertiesSetGeometry(WebKitWindowProperties*, GdkRectangle*); void webkitWindowPropertiesSetToolbarVisible(WebKitWindowProperties*, bool toolbarsVisible); void webkitWindowPropertiesSetMenubarVisible(WebKitWindowProperties*, bool menuBarVisible); diff --git a/Source/WebKit2/UIProcess/API/gtk/WebViewBaseInputMethodFilter.cpp b/Source/WebKit2/UIProcess/API/gtk/WebViewBaseInputMethodFilter.cpp deleted file mode 100644 index 8b87c1522..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/WebViewBaseInputMethodFilter.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2012 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" -#include "WebViewBaseInputMethodFilter.h" - -#include "NativeWebKeyboardEvent.h" -#include "WebKitWebViewBasePrivate.h" -#include "WebPageProxy.h" -#include <WebCore/Color.h> -#include <WebCore/CompositionResults.h> -#include <WebCore/Editor.h> - -using namespace WebCore; - -namespace WebKit { - -void WebViewBaseInputMethodFilter::setWebView(WebKitWebViewBase* webView) -{ - GtkInputMethodFilter::setWidget(GTK_WIDGET(webView)); - - m_webPageProxy = webkitWebViewBaseGetPage(webView); - ASSERT(m_webPageProxy); -} - -bool WebViewBaseInputMethodFilter::canEdit() -{ - return true; -} - -bool WebViewBaseInputMethodFilter::sendSimpleKeyEvent(GdkEventKey* event, WTF::String simpleString, EventFakedForComposition faked) -{ - ASSERT(m_webPageProxy); - m_webPageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(reinterpret_cast<GdkEvent*>(event), - CompositionResults(simpleString), faked)); - return true; -} - -bool WebViewBaseInputMethodFilter::sendKeyEventWithCompositionResults(GdkEventKey* event, ResultsToSend resultsToSend, EventFakedForComposition faked) -{ - ASSERT(m_webPageProxy); - m_webPageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(reinterpret_cast<GdkEvent*>(event), - CompositionResults(CompositionResults::WillSendCompositionResultsSoon), - faked)); - - if (resultsToSend & Composition && !m_confirmedComposition.isNull()) - confirmCompositionText(m_confirmedComposition); - if (resultsToSend & Preedit && !m_preedit.isNull()) - setPreedit(m_preedit, m_cursorOffset); - return true; -} - -void WebViewBaseInputMethodFilter::confirmCompositionText(String text) -{ - ASSERT(m_webPageProxy); - m_webPageProxy->confirmComposition(text, -1, 0); -} - -void WebViewBaseInputMethodFilter::confirmCurrentComposition() -{ - ASSERT(m_webPageProxy); - m_webPageProxy->confirmComposition(String(), -1, 0); -} - -void WebViewBaseInputMethodFilter::cancelCurrentComposition() -{ - ASSERT(m_webPageProxy); - m_webPageProxy->cancelComposition(); -} - -void WebViewBaseInputMethodFilter::setPreedit(String newPreedit, int cursorOffset) -{ - // TODO: We should parse the PangoAttrList that we get from the IM context here. - Vector<CompositionUnderline> underlines; - underlines.append(CompositionUnderline(0, newPreedit.length(), Color(1, 1, 1), false)); - - ASSERT(m_webPageProxy); - m_webPageProxy->setComposition(newPreedit, underlines, - m_cursorOffset, m_cursorOffset, - 0 /* replacement start */, - 0 /* replacement end */); -} - -} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt index a098a00d8..245eb543e 100644 --- a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt +++ b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt @@ -16,7 +16,8 @@ WEBKIT_WEB_VIEW_BASE_GET_CLASS webkit_web_view_base_get_type WebKitWebViewBasePrivate WEBKIT_API -WEBKIT_OBSOLETE_API +WEBKIT_DEPRECATED +WEBKIT_DEPRECATED_FOR </SECTION> <SECTION> @@ -27,8 +28,13 @@ WebKitCacheModel WebKitProcessModel WebKitTLSErrorsPolicy webkit_web_context_get_default +webkit_web_context_new +webkit_web_context_new_with_website_data_manager +webkit_web_context_get_website_data_manager webkit_web_context_get_cache_model webkit_web_context_set_cache_model +webkit_web_context_get_web_process_count_limit +webkit_web_context_set_web_process_count_limit webkit_web_context_clear_cache webkit_web_context_download_uri webkit_web_context_get_cookie_manager @@ -73,13 +79,62 @@ webkit_web_context_get_type </SECTION> <SECTION> +<FILE>WebKitUserContent</FILE> +<TITLE>WebKitUserContent</TITLE> +WebKitUserStyleSheet +WebKitUserScript +WebKitUserContentInjectedFrames +WebKitUserStyleLevel +WebKitUserScriptInjectionTime +webkit_user_style_sheet_ref +webkit_user_style_sheet_unref +webkit_user_style_sheet_new +webkit_user_script_ref +webkit_user_script_unref +webkit_user_script_new + +<SUBSECTION Standard> +WEBKIT_TYPE_USER_STYLE_SHEET +WEBKIT_TYPE_USER_SCRIPT + +<SUBSECTION Private> +webkit_user_style_sheet_get_type +webkit_user_script_get_type +</SECTION> + +<SECTION> +<FILE>WebKitUserContentManager</FILE> +<TITLE>WebKitUserContentManager</TITLE> +WebKitUserContentManager +webkit_user_content_manager_new +webkit_user_content_manager_add_style_sheet +webkit_user_content_manager_remove_all_style_sheets +webkit_user_content_manager_add_script +webkit_user_content_manager_remove_all_scripts +webkit_user_content_manager_register_script_message_handler +webkit_user_content_manager_unregister_script_message_handler + +<SUBSECTION Standard> +WEBKIT_IS_USER_CONTENT_MANAGER +WEBKIT_IS_USER_CONTENT_MANAGER_CLASS +WEBKIT_TYPE_USER_CONTENT_MANAGER +WEBKIT_USER_CONTENT_MANAGER +WEBKIT_USER_CONTENT_MANAGER_CLASS +WEBKIT_USER_CONTENT_MANAGER_GET_CLASS +WebKitUserContentManagerClass + +<SUBSECTION Private> +WebKitUserContentManagerPrivate +webkit_user_content_manager_get_type +</SECTION> + +<SECTION> <FILE>WebKitWebView</FILE> <TITLE>WebKitWebView</TITLE> WebKitWebView WebKitLoadEvent WebKitPolicyDecisionType WebKitSaveMode -WebKitViewMode WebKitInsecureContentEvent WebKitSnapshotOptions WebKitSnapshotRegion @@ -91,18 +146,23 @@ WEBKIT_EDITING_COMMAND_PASTE WEBKIT_EDITING_COMMAND_SELECT_ALL WEBKIT_EDITING_COMMAND_UNDO WEBKIT_EDITING_COMMAND_REDO +WEBKIT_EDITING_COMMAND_INSERT_IMAGE +WEBKIT_EDITING_COMMAND_CREATE_LINK <SUBSECTION> webkit_web_view_new webkit_web_view_new_with_context webkit_web_view_new_with_related_view -webkit_web_view_new_with_group +webkit_web_view_new_with_settings +webkit_web_view_new_with_user_content_manager webkit_web_view_get_context -webkit_web_view_get_group +webkit_web_view_get_user_content_manager +webkit_web_view_try_close webkit_web_view_load_uri webkit_web_view_load_html webkit_web_view_load_alternate_html webkit_web_view_load_plain_text +webkit_web_view_load_bytes webkit_web_view_load_request webkit_web_view_can_go_back webkit_web_view_go_back @@ -114,6 +174,7 @@ webkit_web_view_reload webkit_web_view_reload_bypass_cache webkit_web_view_stop_loading webkit_web_view_is_loading +webkit_web_view_is_playing_audio webkit_web_view_get_estimated_load_progress webkit_web_view_get_custom_charset webkit_web_view_set_custom_charset @@ -129,6 +190,7 @@ webkit_web_view_get_zoom_level webkit_web_view_can_execute_editing_command webkit_web_view_can_execute_editing_command_finish webkit_web_view_execute_editing_command +webkit_web_view_execute_editing_command_with_argument webkit_web_view_get_find_controller webkit_web_view_get_inspector webkit_web_view_get_javascript_global_context @@ -142,11 +204,16 @@ webkit_web_view_save_finish webkit_web_view_save_to_file webkit_web_view_save_to_file_finish webkit_web_view_download_uri -webkit_web_view_set_view_mode -webkit_web_view_get_view_mode webkit_web_view_get_tls_info webkit_web_view_get_snapshot webkit_web_view_get_snapshot_finish +webkit_web_view_set_background_color +webkit_web_view_get_background_color +webkit_web_view_set_editable +webkit_web_view_is_editable +webkit_web_view_get_editor_state +webkit_web_view_get_session_state +webkit_web_view_restore_session_state <SUBSECTION WebKitJavascriptResult> WebKitJavascriptResult @@ -165,6 +232,13 @@ webkit_script_dialog_prompt_get_default_text webkit_script_dialog_prompt_set_text webkit_web_view_get_main_resource +<SUBSECTION WebKitWebViewSessionState> +WebKitWebViewSessionState +webkit_web_view_session_state_new +webkit_web_view_session_state_ref +webkit_web_view_session_state_unref +webkit_web_view_session_state_serialize + <SUBSECTION Standard> WebKitWebViewClass WEBKIT_WEB_VIEW @@ -175,11 +249,13 @@ WEBKIT_IS_WEB_VIEW_CLASS WEBKIT_WEB_VIEW_GET_CLASS WEBKIT_TYPE_JAVASCRIPT_RESULT WEBKIT_TYPE_SCRIPT_DIALOG +WEBKIT_TYPE_WEB_VIEW_SESSION_STATE <SUBSECTION Private> webkit_web_view_get_type webkit_javascript_result_get_type webkit_script_dialog_get_type +webkit_web_view_session_state_get_type WebKitWebViewPrivate </SECTION> @@ -375,6 +451,8 @@ webkit_settings_get_enable_spatial_navigation webkit_settings_set_enable_spatial_navigation webkit_settings_get_enable_mediasource webkit_settings_set_enable_mediasource +webkit_settings_get_allow_file_access_from_file_urls +webkit_settings_set_allow_file_access_from_file_urls <SUBSECTION Standard> WebKitSettingsClass @@ -396,6 +474,7 @@ WebKitURIRequest webkit_uri_request_new webkit_uri_request_get_uri webkit_uri_request_set_uri +webkit_uri_request_get_http_method webkit_uri_request_get_http_headers <SUBSECTION Standard> @@ -420,6 +499,7 @@ webkit_uri_response_get_status_code webkit_uri_response_get_content_length webkit_uri_response_get_mime_type webkit_uri_response_get_suggested_filename +webkit_uri_response_get_http_headers <SUBSECTION Standard> WebKitURIResponseClass @@ -473,6 +553,8 @@ webkit_download_get_estimated_progress webkit_download_get_elapsed_time webkit_download_get_received_data_length webkit_download_get_web_view +webkit_download_get_allow_overwrite +webkit_download_set_allow_overwrite <SUBSECTION Standard> WebKitDownloadClass @@ -524,6 +606,104 @@ webkit_geolocation_permission_request_get_type </SECTION> <SECTION> +<FILE>WebKitInstallMissingMediaPluginsPermissionRequest</FILE> +WebKitInstallMissingMediaPluginsPermissionRequest +webkit_install_missing_media_plugins_permission_request_get_description + +<SUBSECTION Standard> +WebKitInstallMissingMediaPluginsPermissionRequestClass +WEBKIT_TYPE_INSTALL_MISSING_MEDIA_PLUGINS_PERMISSION_REQUEST +WEBKIT_INSTALL_MISSING_MEDIA_PLUGINS_PERMISSION_REQUEST +WEBKIT_IS_INSTALL_MISSING_MEDIA_PLUGINS_PERMISSION_REQUEST +WEBKIT_INSTALL_MISSING_MEDIA_PLUGINS_PERMISSION_REQUEST_CLASS +WEBKIT_IS_INSTALL_MISSING_MEDIA_PLUGINS_PERMISSION_REQUEST_CLASS +WEBKIT_INSTALL_MISSING_MEDIA_PLUGINS_PERMISSION_REQUEST_GET_CLASS + +<SUBSECTION Private> +WebKitInstallMissingMediaPluginsPermissionRequestPrivate +webkit_install_missing_media_plugins_permission_request_get_type +</SECTION> + +<SECTION> +<FILE>WebKitNavigationAction</FILE> +WebKitNavigationAction +webkit_navigation_action_copy +webkit_navigation_action_free +webkit_navigation_action_get_navigation_type +webkit_navigation_action_get_mouse_button +webkit_navigation_action_get_modifiers +webkit_navigation_action_get_request +webkit_navigation_action_is_user_gesture + +<SUBSECTION Standard> +WEBKIT_TYPE_NAVIGATION_ACTION + +<SUBSECTION Private> +webkit_navigation_action_get_type +</SECTION> + +<SECTION> +<FILE>WebKitUserMediaPermissionRequest</FILE> +WebKitUserMediaPermissionRequest +webkit_user_media_permission_is_for_audio_device +webkit_user_media_permission_is_for_video_device + +<SUBSECTION Standard> +WebKitUserMediaPermissionRequestClass +WEBKIT_TYPE_USER_MEDIA_PERMISSION_REQUEST +WEBKIT_USER_MEDIA_PERMISSION_REQUEST +WEBKIT_IS_USER_MEDIA_PERMISSION_REQUEST +WEBKIT_USER_MEDIA_PERMISSION_REQUEST_CLASS +WEBKIT_IS_USER_MEDIA_PERMISSION_REQUEST_CLASS +WEBKIT_USER_MEDIA_PERMISSION_REQUEST_GET_CLASS + +<SUBSECTION Private> +WebKitUserMediaPermissionRequestPrivate +webkit_user_media_permission_request_get_type +</SECTION> + +<SECTION> +<FILE>WebKitNotification</FILE> +WebKitNotification +webkit_notification_get_id +webkit_notification_get_title +webkit_notification_get_body +webkit_notification_close +webkit_notification_clicked + +<SUBSECTION Standard> +WebKitNotificationClass +WEBKIT_TYPE_NOTIFICATION +WEBKIT_IS_NOTIFICATION +WEBKIT_NOTIFICATION +WEBKIT_NOTIFICATION_CLASS +WEBKIT_IS_NOTIFICATION_CLASS +WEBKIT_NOTIFICATION_GET_CLASS + +<SUBSECTION Private> +WebKitNotificationPrivate +webkit_notification_get_type +</SECTION> + +<SECTION> +<FILE>WebKitNotificationPermissionRequest</FILE> +WebKitNotificationPermissionRequest + +<SUBSECTION Standard> +WebKitNotificationPermissionRequestClass +WEBKIT_TYPE_NOTIFICATION_PERMISSION_REQUEST +WEBKIT_NOTIFICATION_PERMISSION_REQUEST +WEBKIT_IS_NOTIFICATION_PERMISSION_REQUEST +WEBKIT_NOTIFICATION_PERMISSION_REQUEST_CLASS +WEBKIT_IS_NOTIFICATION_PERMISSION_REQUEST_CLASS +WEBKIT_NOTIFICATION_PERMISSION_REQUEST_GET_CLASS + +<SUBSECTION Private> +WebKitNotificationPermissionRequestPrivate +webkit_notification_permission_request_get_type +</SECTION> + +<SECTION> <FILE>WebKitPolicyDecision</FILE> WebKitPolicyDecision webkit_policy_decision_download @@ -548,6 +728,7 @@ webkit_policy_decision_get_type <FILE>WebKitNavigationPolicyDecision</FILE> WebKitNavigationPolicyDecision WebKitNavigationType +webkit_navigation_policy_decision_get_navigation_action webkit_navigation_policy_decision_get_frame_name webkit_navigation_policy_decision_get_modifiers webkit_navigation_policy_decision_get_mouse_button @@ -598,6 +779,7 @@ webkit_hit_test_result_context_is_link webkit_hit_test_result_context_is_image webkit_hit_test_result_context_is_media webkit_hit_test_result_context_is_editable +webkit_hit_test_result_context_is_selection webkit_hit_test_result_get_link_uri webkit_hit_test_result_get_link_title webkit_hit_test_result_get_link_label @@ -620,6 +802,26 @@ webkit_hit_test_result_get_type </SECTION> <SECTION> +<FILE>WebKitEditorState</FILE> +WebKitEditorState +WebKitEditorTypingAttributes +webkit_editor_state_get_typing_attributes + +<SUBSECTION Standard> +WebKitEditorStateClass +WEBKIT_TYPE_EDITOR_STATE +WEBKIT_EDITOR_STATE +WEBKIT_IS_EDITOR_STATE +WEBKIT_EDITOR_STATE_CLASS +WEBKIT_IS_EDITOR_STATE_CLASS +WEBKIT_EDITOR_STATE_GET_CLASS + +<SUBSECTION Private> +WebKitEditorStatePrivate +webkit_editor_state_get_type +</SECTION> + +<SECTION> <FILE>WebKitPrintOperation</FILE> WebKitPrintOperation WebKitPrintOperationResponse @@ -834,6 +1036,7 @@ WebKitPluginPrivate WebKitWebInspector webkit_web_inspector_get_web_view webkit_web_inspector_get_inspected_uri +webkit_web_inspector_get_can_attach webkit_web_inspector_is_attached webkit_web_inspector_attach webkit_web_inspector_detach @@ -908,6 +1111,8 @@ webkit_context_menu_last webkit_context_menu_get_item_at_position webkit_context_menu_remove webkit_context_menu_remove_all +webkit_context_menu_set_user_data +webkit_context_menu_get_user_data <SUBSECTION Standard> WebKitContextMenuClass @@ -1003,28 +1208,29 @@ webkit_security_manager_get_type </SECTION> <SECTION> -<FILE>WebKitWebViewGroup</FILE> -WebKitWebViewGroup -WebKitInjectedContentFrames -webkit_web_view_group_new -webkit_web_view_group_get_name -webkit_web_view_group_get_settings -webkit_web_view_group_set_settings -webkit_web_view_group_add_user_style_sheet -webkit_web_view_group_remove_all_user_style_sheets +<FILE>WebKitWebsiteDataManager</FILE> +WebKitWebsiteDataManager +webkit_website_data_manager_new +webkit_website_data_manager_get_base_data_directory +webkit_website_data_manager_get_base_cache_directory +webkit_website_data_manager_get_local_storage_directory +webkit_website_data_manager_get_disk_cache_directory +webkit_website_data_manager_get_offline_application_cache_directory +webkit_website_data_manager_get_indexeddb_directory +webkit_website_data_manager_get_websql_directory <SUBSECTION Standard> -WebKitWebViewGroupClass -WEBKIT_TYPE_WEB_VIEW_GROUP -WEBKIT_WEB_VIEW_GROUP -WEBKIT_IS_WEB_VIEW_GROUP -WEBKIT_WEB_VIEW_GROUP_CLASS -WEBKIT_IS_WEB_VIEW_GROUP_CLASS -WEBKIT_WEB_VIEW_GROUP_GET_CLASS +WebKitWebsiteDataManagerClass +WEBKIT_TYPE_WEBSITE_DATA_MANAGER +WEBKIT_WEBSITE_DATA_MANAGER +WEBKIT_IS_WEBSITE_DATA_MANAGER +WEBKIT_WEBSITE_DATA_MANAGER_CLASS +WEBKIT_IS_WEBSITE_DATA_MANAGER_CLASS +WEBKIT_WEBSITE_DATA_MANAGER_GET_CLASS <SUBSECTION Private> -WebKitWebViewGroupPrivate -webkit_web_view_group_get_type +WebKitWebsiteDataManagerPrivate +webkit_website_data_manager_get_type </SECTION> <SECTION> @@ -1055,6 +1261,7 @@ webkit_web_page_get_dom_document webkit_web_page_get_id webkit_web_page_get_uri webkit_web_page_get_main_frame +webkit_web_page_get_editor <SUBSECTION Standard> WebKitWebPageClass @@ -1071,6 +1278,25 @@ webkit_web_page_get_type </SECTION> <SECTION> +<FILE>WebKitWebEditor</FILE> +WebKitWebEditor +webkit_web_editor_get_page + +<SUBSECTION Standard> +WebKitWebEditorClass +WEBKIT_TYPE_WEB_EDITOR +WEBKIT_WEB_EDITOR +WEBKIT_IS_WEB_EDITOR +WEBKIT_WEB_EDITOR_CLASS +WEBKIT_IS_WEB_EDITOR_CLASS +WEBKIT_WEB_EDITOR_GET_CLASS + +<SUBSECTION Private> +WebKitWebEditorPrivate +webkit_web_editor_get_type +</SECTION> + +<SECTION> <FILE>WebKitFrame</FILE> WebKitFrame webkit_frame_is_main_frame @@ -1113,16 +1339,63 @@ webkit_script_world_get_type </SECTION> <SECTION> -<FILE>WebKitCertificateInfo</FILE> -WebKitCertificateInfo -webkit_certificate_info_copy -webkit_certificate_info_free -webkit_certificate_info_get_tls_certificate -webkit_certificate_info_get_tls_errors +<FILE>WebKitWebHitTestResult</FILE> +WebKitWebHitTestResult +webkit_web_hit_test_result_get_node + +<SUBSECTION Standard> +WebKitWebHitTestResultClass +WEBKIT_TYPE_WEB_HIT_TEST_RESULT +WEBKIT_WEB_HIT_TEST_RESULT +WEBKIT_IS_WEB_HIT_TEST_RESULT +WEBKIT_WEB_HIT_TEST_RESULT_CLASS +WEBKIT_IS_WEB_HIT_TEST_RESULT_CLASS +WEBKIT_WEB_HIT_TEST_RESULT_GET_CLASS + +<SUBSECTION Private> +WebKitWebHitTestResultPrivate +webkit_web_hit_test_result_get_type +</SECTION> + +<SECTION> +<FILE>WebKitConsoleMessage</FILE> +WebKitConsoleMessage +WebKitConsoleMessageSource +WebKitConsoleMessageLevel +webkit_console_message_copy +webkit_console_message_free +webkit_console_message_get_source +webkit_console_message_get_level +webkit_console_message_get_text +webkit_console_message_get_line +webkit_console_message_get_source_id + +<SUBSECTION Standard> +WEBKIT_TYPE_CONSOLE_MESSAGE + +<SUBSECTION Private> +webkit_console_message_get_type +</SECTION> + +<SECTION> +<FILE>WebKitColorChooserRequest</FILE> +WebKitColorChooserRequest +webkit_color_chooser_request_get_rgba +webkit_color_chooser_request_set_rgba +webkit_color_chooser_request_get_element_rectangle +webkit_color_chooser_request_finish +webkit_color_chooser_request_cancel <SUBSECTION Standard> -WEBKIT_TYPE_CERTIFICATE_INFO +WebKitColorChooserRequestClass +WEBKIT_TYPE_COLOR_CHOOSER_REQUEST +WEBKIT_COLOR_CHOOSER_REQUEST +WEBKIT_IS_COLOR_CHOOSER_REQUEST +WEBKIT_COLOR_CHOOSER_REQUEST_CLASS +WEBKIT_IS_COLOR_CHOOSER_REQUEST_CLASS +WEBKIT_COLOR_CHOOSER_REQUEST_GET_CLASS <SUBSECTION Private> -webkit_certificate_info_get_type +WebKitColorChooserRequestPrivate +webkit_color_chooser_request_get_type </SECTION> diff --git a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk.types b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0.types index 4b583bad9..262e07a7e 100644 --- a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk.types +++ b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0.types @@ -21,10 +21,16 @@ webkit_web_inspector_get_type webkit_uri_scheme_request_get_type webkit_context_menu_get_type webkit_context_menu_item_get_type -webkit_web_view_group_get_type webkit_web_extension_get_type webkit_web_page_get_type webkit_authentication_request_get_type webkit_credential_get_type webkit_frame_get_type webkit_certificate_info_get_type +webkit_user_content_manager_get_type +webkit_web_hit_test_result_get_type +webkit_website_data_manager_get_type +webkit_editor_state_get_type +webkit_install_missing_media_plugins_permission_request_get_type +webkit_console_message_get_type +webkit_web_view_session_state_get_type diff --git a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml index e3cf9a68c..f8f42dcd9 100644 --- a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml +++ b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml @@ -23,14 +23,19 @@ <xi:include href="xml/WebKitDownload.xml"/> <xi:include href="xml/WebKitPermissionRequest.xml"/> <xi:include href="xml/WebKitGeolocationPermissionRequest.xml"/> + <xi:include href="xml/WebKitInstallMissingMediaPluginsPermissionRequest.xml"/> + <xi:include href="xml/WebKitNavigationAction.xml"/> + <xi:include href="xml/WebKitUserMediaPermissionRequest.xml"/> <xi:include href="xml/WebKitPolicyDecision.xml"/> <xi:include href="xml/WebKitNavigationPolicyDecision.xml"/> <xi:include href="xml/WebKitResponsePolicyDecision.xml"/> <xi:include href="xml/WebKitHitTestResult.xml"/> + <xi:include href="xml/WebKitEditorState.xml"/> <xi:include href="xml/WebKitPrintOperation.xml"/> <xi:include href="xml/WebKitWebResource.xml"/> <xi:include href="xml/WebKitError.xml"/> <xi:include href="xml/WebKitFaviconDatabase.xml"/> + <xi:include href="xml/WebKitColorChooserRequest.xml"/> <xi:include href="xml/WebKitFileChooserRequest.xml"/> <xi:include href="xml/WebKitFindController.xml"/> <xi:include href="xml/WebKitCookieManager.xml"/> @@ -42,8 +47,11 @@ <xi:include href="xml/WebKitContextMenuItem.xml"/> <xi:include href="xml/WebKitFormSubmissionRequest.xml"/> <xi:include href="xml/WebKitSecurityManager.xml"/> - <xi:include href="xml/WebKitWebViewGroup.xml"/> - <xi:include href="xml/WebKitCertificateInfo.xml"/> + <xi:include href="xml/WebKitUserContentManager.xml"/> + <xi:include href="xml/WebKitUserContent.xml"/> + <xi:include href="xml/WebKitNotification.xml"/> + <xi:include href="xml/WebKitNotificationPermissionRequest.xml"/> + <xi:include href="xml/WebKitWebsiteDataManager.xml"/> </chapter> <chapter> @@ -52,21 +60,49 @@ <xi:include href="xml/WebKitWebPage.xml"/> <xi:include href="xml/WebKitFrame.xml"/> <xi:include href="xml/WebKitScriptWorld.xml"/> + <xi:include href="xml/WebKitWebHitTestResult.xml"/> + <xi:include href="xml/WebKitWebEditor.xml"/> + <xi:include href="xml/WebKitConsoleMessage.xml"/> </chapter> <index id="index-all"> <title>Index</title> </index> - + + <index id="api-index-deprecated" role="deprecated"> + <title>Index of deprecated symbols</title> + <xi:include href="xml/api-index-deprecated.xml"><xi:fallback /></xi:include> + </index> + <index id="api-index-2-2" role="2.2"> <title>Index of new symbols in 2.2</title> <xi:include href="xml/api-index-2.2.xml"><xi:fallback /></xi:include> - </index> + </index> <index id="api-index-2-4" role="2.4"> <title>Index of new symbols in 2.4</title> <xi:include href="xml/api-index-2.4.xml"><xi:fallback /></xi:include> </index> + <index id="api-index-2-6" role="2.6"> + <title>Index of new symbols in 2.6</title> + <xi:include href="xml/api-index-2.6.xml"><xi:fallback /></xi:include> + </index> + + <index id="api-index-2-8" role="2.8"> + <title>Index of new symbols in 2.8</title> + <xi:include href="xml/api-index-2.8.xml"><xi:fallback /></xi:include> + </index> + + <index id="api-index-2-10" role="2.10"> + <title>Index of new symbols in 2.10</title> + <xi:include href="xml/api-index-2.10.xml"><xi:fallback /></xi:include> + </index> + + <index id="api-index-2-12" role="2.12"> + <title>Index of new symbols in 2.12</title> + <xi:include href="xml/api-index-2.12.xml"><xi:fallback /></xi:include> + </index> + <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include> </book> diff --git a/Source/WebKit2/UIProcess/API/gtk/webkit2.h b/Source/WebKit2/UIProcess/API/gtk/webkit2.h index c18538a63..3e44d6094 100644 --- a/Source/WebKit2/UIProcess/API/gtk/webkit2.h +++ b/Source/WebKit2/UIProcess/API/gtk/webkit2.h @@ -30,7 +30,6 @@ #include <webkit2/WebKitAuthenticationRequest.h> #include <webkit2/WebKitBackForwardList.h> #include <webkit2/WebKitBackForwardListItem.h> -#include <webkit2/WebKitCertificateInfo.h> #include <webkit2/WebKitContextMenu.h> #include <webkit2/WebKitContextMenuActions.h> #include <webkit2/WebKitContextMenuItem.h> @@ -39,17 +38,23 @@ #include <webkit2/WebKitDefines.h> #include <webkit2/WebKitDownload.h> #include <webkit2/WebKitEditingCommands.h> +#include <webkit2/WebKitEditorState.h> #include <webkit2/WebKitEnumTypes.h> #include <webkit2/WebKitError.h> #include <webkit2/WebKitFaviconDatabase.h> +#include <webkit2/WebKitColorChooserRequest.h> #include <webkit2/WebKitFileChooserRequest.h> #include <webkit2/WebKitFindController.h> #include <webkit2/WebKitFormSubmissionRequest.h> #include <webkit2/WebKitGeolocationPermissionRequest.h> #include <webkit2/WebKitHitTestResult.h> +#include <webkit2/WebKitInstallMissingMediaPluginsPermissionRequest.h> #include <webkit2/WebKitJavascriptResult.h> #include <webkit2/WebKitMimeInfo.h> +#include <webkit2/WebKitNavigationAction.h> #include <webkit2/WebKitNavigationPolicyDecision.h> +#include <webkit2/WebKitNotification.h> +#include <webkit2/WebKitNotificationPermissionRequest.h> #include <webkit2/WebKitPermissionRequest.h> #include <webkit2/WebKitPlugin.h> #include <webkit2/WebKitPrintOperation.h> @@ -60,15 +65,21 @@ #include <webkit2/WebKitURIRequest.h> #include <webkit2/WebKitURIResponse.h> #include <webkit2/WebKitURISchemeRequest.h> +#include <webkit2/WebKitUserContent.h> +#include <webkit2/WebKitUserContentManager.h> +#include <webkit2/WebKitUserMediaPermissionRequest.h> #include <webkit2/WebKitVersion.h> #include <webkit2/WebKitWebContext.h> #include <webkit2/WebKitWebInspector.h> #include <webkit2/WebKitWebResource.h> #include <webkit2/WebKitWebView.h> #include <webkit2/WebKitWebViewBase.h> -#include <webkit2/WebKitWebViewGroup.h> +#include <webkit2/WebKitWebViewSessionState.h> +#include <webkit2/WebKitWebsiteDataManager.h> #include <webkit2/WebKitWindowProperties.h> +#include <webkit2/WebKitAutocleanups.h> + #undef __WEBKIT2_H_INSIDE__ #endif /* __WEBKIT2_H__ */ diff --git a/Source/WebKit2/UIProcess/API/gtk/webkit2marshal.list b/Source/WebKit2/UIProcess/API/gtk/webkit2marshal.list index e1cfe0721..d638661f4 100644 --- a/Source/WebKit2/UIProcess/API/gtk/webkit2marshal.list +++ b/Source/WebKit2/UIProcess/API/gtk/webkit2marshal.list @@ -1,6 +1,5 @@ BOOLEAN:BOXED BOOLEAN:BOXED,STRING -BOOLEAN:ENUM,STRING,POINTER BOOLEAN:OBJECT BOOLEAN:OBJECT,BOXED,OBJECT BOOLEAN:OBJECT,ENUM diff --git a/Source/WebKit2/UIProcess/ApplicationStateTracker.h b/Source/WebKit2/UIProcess/ApplicationStateTracker.h new file mode 100644 index 000000000..5af49dfda --- /dev/null +++ b/Source/WebKit2/UIProcess/ApplicationStateTracker.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ApplicationStateTracker_h +#define ApplicationStateTracker_h + +#if PLATFORM(IOS) + +#import "WeakObjCPtr.h" +#import <wtf/Forward.h> +#import <wtf/WeakPtr.h> + +OBJC_CLASS BKSApplicationStateMonitor; +OBJC_CLASS UIView; + +namespace WebKit { + +class ApplicationStateTracker { +public: + ApplicationStateTracker(UIView *, SEL didEnterBackgroundSelector, SEL willEnterForegroundSelector); + ~ApplicationStateTracker(); + + bool isInBackground() const { return m_isInBackground; } + +private: + void applicationDidEnterBackground(); + void applicationWillEnterForeground(); + + WeakObjCPtr<UIView> m_view; + SEL m_didEnterBackgroundSelector; + SEL m_willEnterForegroundSelector; + + bool m_isInBackground; + + WeakPtrFactory<ApplicationStateTracker> m_weakPtrFactory; + + RetainPtr<BKSApplicationStateMonitor> m_applicationStateMonitor; + + id m_didEnterBackgroundObserver; + id m_willEnterForegroundObserver; +}; + +} + +#endif + +#endif // ApplicationStateTracker_h diff --git a/Source/WebKit2/UIProcess/Authentication/AuthenticationChallengeProxy.cpp b/Source/WebKit2/UIProcess/Authentication/AuthenticationChallengeProxy.cpp index 8c5d26fc7..9bdd73b44 100644 --- a/Source/WebKit2/UIProcess/Authentication/AuthenticationChallengeProxy.cpp +++ b/Source/WebKit2/UIProcess/Authentication/AuthenticationChallengeProxy.cpp @@ -62,15 +62,19 @@ void AuthenticationChallengeProxy::useCredential(WebCredential* credential) if (!m_challengeID) return; - if (!credential) - m_connection->send(Messages::AuthenticationManager::ContinueWithoutCredentialForChallenge(m_challengeID), 0); - else { - WebCertificateInfo* certificateInfo = credential->certificateInfo(); - WebCore::CertificateInfo platformInfo = certificateInfo ? certificateInfo->certificateInfo() : WebCore::CertificateInfo(); - m_connection->send(Messages::AuthenticationManager::UseCredentialForChallenge(m_challengeID, credential->core(), platformInfo), 0); + uint64_t challengeID = m_challengeID; + m_challengeID = 0; + + if (!credential) { + m_connection->send(Messages::AuthenticationManager::ContinueWithoutCredentialForChallenge(challengeID), 0); + return; } - m_challengeID = 0; + WebCore::CertificateInfo certificateInfo; + if (credential->certificateInfo()) + certificateInfo = credential->certificateInfo()->certificateInfo(); + + m_connection->send(Messages::AuthenticationManager::UseCredentialForChallenge(challengeID, credential->credential(), certificateInfo), 0); } void AuthenticationChallengeProxy::cancel() @@ -83,6 +87,26 @@ void AuthenticationChallengeProxy::cancel() m_challengeID = 0; } +void AuthenticationChallengeProxy::performDefaultHandling() +{ + if (!m_challengeID) + return; + + m_connection->send(Messages::AuthenticationManager::PerformDefaultHandling(m_challengeID), 0); + + m_challengeID = 0; +} + +void AuthenticationChallengeProxy::rejectProtectionSpaceAndContinue() +{ + if (!m_challengeID) + return; + + m_connection->send(Messages::AuthenticationManager::RejectProtectionSpaceAndContinue(m_challengeID), 0); + + m_challengeID = 0; +} + WebCredential* AuthenticationChallengeProxy::proposedCredential() const { if (!m_webCredential) diff --git a/Source/WebKit2/UIProcess/Authentication/AuthenticationChallengeProxy.h b/Source/WebKit2/UIProcess/Authentication/AuthenticationChallengeProxy.h index a549d5188..9bac83f40 100644 --- a/Source/WebKit2/UIProcess/Authentication/AuthenticationChallengeProxy.h +++ b/Source/WebKit2/UIProcess/Authentication/AuthenticationChallengeProxy.h @@ -43,15 +43,17 @@ class WebProtectionSpace; class AuthenticationChallengeProxy : public API::ObjectImpl<API::Object::Type::AuthenticationChallenge> { public: - static PassRefPtr<AuthenticationChallengeProxy> create(const WebCore::AuthenticationChallenge& authenticationChallenge, uint64_t challengeID, IPC::Connection* connection) + static Ref<AuthenticationChallengeProxy> create(const WebCore::AuthenticationChallenge& authenticationChallenge, uint64_t challengeID, IPC::Connection* connection) { - return adoptRef(new AuthenticationChallengeProxy(authenticationChallenge, challengeID, connection)); + return adoptRef(*new AuthenticationChallengeProxy(authenticationChallenge, challengeID, connection)); } ~AuthenticationChallengeProxy(); void useCredential(WebCredential*); void cancel(); + void performDefaultHandling(); + void rejectProtectionSpaceAndContinue(); AuthenticationDecisionListener* listener() const { return m_listener.get(); } WebCredential* proposedCredential() const; diff --git a/Source/WebKit2/UIProcess/Authentication/AuthenticationDecisionListener.cpp b/Source/WebKit2/UIProcess/Authentication/AuthenticationDecisionListener.cpp index 00cd8748c..8bde289e3 100644 --- a/Source/WebKit2/UIProcess/Authentication/AuthenticationDecisionListener.cpp +++ b/Source/WebKit2/UIProcess/Authentication/AuthenticationDecisionListener.cpp @@ -52,6 +52,18 @@ void AuthenticationDecisionListener::cancel() m_challengeProxy->cancel(); } +void AuthenticationDecisionListener::performDefaultHandling() +{ + if (m_challengeProxy) + m_challengeProxy->performDefaultHandling(); +} + +void AuthenticationDecisionListener::rejectProtectionSpaceAndContinue() +{ + if (m_challengeProxy) + m_challengeProxy->rejectProtectionSpaceAndContinue(); +} + void AuthenticationDecisionListener::detachChallenge() { m_challengeProxy = 0; diff --git a/Source/WebKit2/UIProcess/Authentication/AuthenticationDecisionListener.h b/Source/WebKit2/UIProcess/Authentication/AuthenticationDecisionListener.h index 057ddd8cd..b5bd2b09a 100644 --- a/Source/WebKit2/UIProcess/Authentication/AuthenticationDecisionListener.h +++ b/Source/WebKit2/UIProcess/Authentication/AuthenticationDecisionListener.h @@ -37,14 +37,16 @@ class WebCredential; class AuthenticationDecisionListener : public API::ObjectImpl<API::Object::Type::AuthenticationDecisionListener> { public: - static PassRefPtr<AuthenticationDecisionListener> create(AuthenticationChallengeProxy* authenticationChallenge) + static Ref<AuthenticationDecisionListener> create(AuthenticationChallengeProxy* authenticationChallenge) { - return adoptRef(new AuthenticationDecisionListener(authenticationChallenge)); + return adoptRef(*new AuthenticationDecisionListener(authenticationChallenge)); } void useCredential(WebCredential*); void cancel(); - + void performDefaultHandling(); + void rejectProtectionSpaceAndContinue(); + void detachChallenge(); private: diff --git a/Source/WebKit2/UIProcess/Authentication/WebCredential.cpp b/Source/WebKit2/UIProcess/Authentication/WebCredential.cpp index a69d509c7..a2d1d17cd 100644 --- a/Source/WebKit2/UIProcess/Authentication/WebCredential.cpp +++ b/Source/WebKit2/UIProcess/Authentication/WebCredential.cpp @@ -49,14 +49,9 @@ WebCertificateInfo* WebCredential::certificateInfo() return m_certificateInfo.get(); } -const WebCore::Credential& WebCredential::core() +const WebCore::Credential& WebCredential::credential() { return m_coreCredential; } -const String& WebCredential::user() const -{ - return m_coreCredential.user(); -} - } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/Authentication/WebCredential.h b/Source/WebKit2/UIProcess/Authentication/WebCredential.h index efff6548c..eaaa1f70c 100644 --- a/Source/WebKit2/UIProcess/Authentication/WebCredential.h +++ b/Source/WebKit2/UIProcess/Authentication/WebCredential.h @@ -29,7 +29,6 @@ #include "APIObject.h" #include "APIString.h" #include <WebCore/Credential.h> -#include <wtf/PassRefPtr.h> namespace WebKit { @@ -39,27 +38,20 @@ class WebCredential : public API::ObjectImpl<API::Object::Type::Credential> { public: ~WebCredential(); - static PassRefPtr<WebCredential> create(const WebCore::Credential& credential) + static Ref<WebCredential> create(const WebCore::Credential& credential) { - return adoptRef(new WebCredential(credential)); + return adoptRef(*new WebCredential(credential)); } - static PassRefPtr<WebCredential> create(API::String* username, API::String* password, WebCore::CredentialPersistence persistence) + static Ref<WebCredential> create(WebCertificateInfo* certificateInfo) { - return adoptRef(new WebCredential(WebCore::Credential(username->string(), password->string(), persistence))); - } - - static PassRefPtr<WebCredential> create(WebCertificateInfo* certificateInfo) - { - return adoptRef(new WebCredential(certificateInfo)); + return adoptRef(*new WebCredential(certificateInfo)); } WebCertificateInfo* certificateInfo(); - const WebCore::Credential& core(); + const WebCore::Credential& credential(); - const String& user() const; - private: explicit WebCredential(const WebCore::Credential&); explicit WebCredential(WebCertificateInfo*); diff --git a/Source/WebKit2/UIProcess/Authentication/WebProtectionSpace.h b/Source/WebKit2/UIProcess/Authentication/WebProtectionSpace.h index 95ad0bb57..28beba6e8 100644 --- a/Source/WebKit2/UIProcess/Authentication/WebProtectionSpace.h +++ b/Source/WebKit2/UIProcess/Authentication/WebProtectionSpace.h @@ -28,15 +28,14 @@ #include "APIObject.h" #include <WebCore/ProtectionSpace.h> -#include <wtf/PassRefPtr.h> namespace WebKit { class WebProtectionSpace : public API::ObjectImpl<API::Object::Type::ProtectionSpace> { public: - static PassRefPtr<WebProtectionSpace> create(const WebCore::ProtectionSpace& protectionSpace) + static Ref<WebProtectionSpace> create(const WebCore::ProtectionSpace& protectionSpace) { - return adoptRef(new WebProtectionSpace(protectionSpace)); + return adoptRef(*new WebProtectionSpace(protectionSpace)); } const String& protocol() const; diff --git a/Source/WebKit2/UIProcess/AutoCorrectionCallback.h b/Source/WebKit2/UIProcess/AutoCorrectionCallback.h index 90cf9284e..752e4cc58 100644 --- a/Source/WebKit2/UIProcess/AutoCorrectionCallback.h +++ b/Source/WebKit2/UIProcess/AutoCorrectionCallback.h @@ -30,98 +30,13 @@ #include "GenericCallback.h" #include "WKAPICast.h" #include <wtf/HashMap.h> -#include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> namespace WebKit { -class AutocorrectionDataCallback : public CallbackBase { -public: - typedef void (*CallbackFunction)(const Vector<WebCore::FloatRect>&, const String&, double, uint64_t, WKErrorRef, void*); - - static PassRefPtr<AutocorrectionDataCallback> create(void* context, CallbackFunction callback) - { - return adoptRef(new AutocorrectionDataCallback(context, callback)); - } - - virtual ~AutocorrectionDataCallback() - { - ASSERT(!m_callback); - } - - void performCallbackWithReturnValue(const Vector<WebCore::FloatRect>& returnValue1, const String& returnValue2, double returnValue3, uint64_t returnValue4) - { - ASSERT(m_callback); - - m_callback(returnValue1, returnValue2, returnValue3, returnValue4, 0, context()); - - m_callback = 0; - } - - void invalidate() - { - ASSERT(m_callback); - - RefPtr<API::Error> error = API::Error::create(); - m_callback(Vector<WebCore::FloatRect>(), String(), 0, 0, toAPI(error.get()), context()); - - m_callback = 0; - } - -private: - AutocorrectionDataCallback(void* context, CallbackFunction callback) - : CallbackBase(context) - , m_callback(callback) - { - ASSERT(m_callback); - } - - CallbackFunction m_callback; -}; - -class AutocorrectionContextCallback : public CallbackBase { -public: - typedef void (*CallbackFunction)(const String&, const String&, const String&, const String&, uint64_t, uint64_t, WKErrorRef, void*); - - static PassRefPtr<AutocorrectionContextCallback> create(void* context, CallbackFunction callback) - { - return adoptRef(new AutocorrectionContextCallback(context, callback)); - } - - virtual ~AutocorrectionContextCallback() - { - ASSERT(!m_callback); - } - - void performCallbackWithReturnValue(const String& returnValue1, const String& returnValue2, const String& returnValue3, const String& returnValue4, uint64_t returnValue5, uint64_t returnValue6) - { - ASSERT(m_callback); - - m_callback(returnValue1, returnValue2, returnValue3, returnValue4, returnValue5, returnValue6, 0, context()); - - m_callback = 0; - } - - void invalidate() - { - ASSERT(m_callback); - - RefPtr<API::Error> error = API::Error::create(); - m_callback(String(), String(), String(), String(), 0, 0, toAPI(error.get()), context()); - - m_callback = 0; - } - -private: - AutocorrectionContextCallback(void* context, CallbackFunction callback) - : CallbackBase(context) - , m_callback(callback) - { - ASSERT(m_callback); - } - - CallbackFunction m_callback; -}; +typedef GenericCallback<const Vector<WebCore::FloatRect>&, const String&, double, uint64_t> AutocorrectionDataCallback; +typedef GenericCallback<const String&, const String&, const String&, const String&, uint64_t, uint64_t> AutocorrectionContextCallback; +typedef GenericCallback<const String&, const String&, const String&> DictationContextCallback; } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/BackingStore.cpp b/Source/WebKit2/UIProcess/BackingStore.cpp index aae29858c..f90d91cff 100644 --- a/Source/WebKit2/UIProcess/BackingStore.cpp +++ b/Source/WebKit2/UIProcess/BackingStore.cpp @@ -33,7 +33,7 @@ using namespace WebCore; namespace WebKit { -BackingStore::BackingStore(const IntSize& size, float deviceScaleFactor, WebPageProxy* webPageProxy) +BackingStore::BackingStore(const IntSize& size, float deviceScaleFactor, WebPageProxy& webPageProxy) : m_size(size) , m_deviceScaleFactor(deviceScaleFactor) , m_webPageProxy(webPageProxy) diff --git a/Source/WebKit2/UIProcess/BackingStore.h b/Source/WebKit2/UIProcess/BackingStore.h index 0a9fe9a6f..14de1f424 100644 --- a/Source/WebKit2/UIProcess/BackingStore.h +++ b/Source/WebKit2/UIProcess/BackingStore.h @@ -30,8 +30,7 @@ #include <wtf/Noncopyable.h> #if USE(CAIRO) -#include <RefPtrCairo.h> -#include <WebCore/WidgetBackingStore.h> +#include <WebCore/BackingStoreBackendCairo.h> #endif namespace WebKit { @@ -44,7 +43,7 @@ class BackingStore { WTF_MAKE_NONCOPYABLE(BackingStore); public: - BackingStore(const WebCore::IntSize&, float deviceScaleFactor, WebPageProxy*); + BackingStore(const WebCore::IntSize&, float deviceScaleFactor, WebPageProxy&); ~BackingStore(); const WebCore::IntSize& size() const { return m_size; } @@ -61,12 +60,15 @@ private: void incorporateUpdate(ShareableBitmap*, const UpdateInfo&); void scroll(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset); +#if USE(CAIRO) + std::unique_ptr<WebCore::BackingStoreBackendCairo> createBackend(); +#endif + WebCore::IntSize m_size; float m_deviceScaleFactor; - WebPageProxy* m_webPageProxy; - + WebPageProxy& m_webPageProxy; #if USE(CAIRO) - OwnPtr<WebCore::WidgetBackingStore> m_backingStore; + std::unique_ptr<WebCore::BackingStoreBackendCairo> m_backend; #endif }; diff --git a/Source/WebKit2/UIProcess/ChildProcessProxy.cpp b/Source/WebKit2/UIProcess/ChildProcessProxy.cpp new file mode 100644 index 000000000..fe2a6dec2 --- /dev/null +++ b/Source/WebKit2/UIProcess/ChildProcessProxy.cpp @@ -0,0 +1,226 @@ +/* + * Copyright (C) 2012 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ChildProcessProxy.h" + +#include "ChildProcessMessages.h" +#include <wtf/RunLoop.h> + +namespace WebKit { + +ChildProcessProxy::ChildProcessProxy() +{ +} + +ChildProcessProxy::~ChildProcessProxy() +{ + if (m_connection) + m_connection->invalidate(); + + if (m_processLauncher) { + m_processLauncher->invalidate(); + m_processLauncher = nullptr; + } +} + +ChildProcessProxy* ChildProcessProxy::fromConnection(IPC::Connection* connection) +{ + ASSERT(connection); + + ChildProcessProxy* childProcessProxy = static_cast<ChildProcessProxy*>(connection->client()); + ASSERT(childProcessProxy->connection() == connection); + + return childProcessProxy; +} + +void ChildProcessProxy::getLaunchOptions(ProcessLauncher::LaunchOptions& launchOptions) +{ + if (const char* userDirectorySuffix = getenv("DIRHELPER_USER_DIR_SUFFIX")) + launchOptions.extraInitializationData.add(ASCIILiteral("user-directory-suffix"), userDirectorySuffix); + +#if !defined(NDEBUG) && (PLATFORM(GTK) || PLATFORM(EFL)) + const char* varname; + switch (launchOptions.processType) { + case ProcessLauncher::ProcessType::Web: + varname = "WEB_PROCESS_CMD_PREFIX"; + break; +#if ENABLE(NETSCAPE_PLUGIN_API) + case ProcessLauncher::ProcessType::Plugin64: + case ProcessLauncher::ProcessType::Plugin32: + varname = "PLUGIN_PROCESS_CMD_PREFIX"; + break; +#endif + case ProcessLauncher::ProcessType::Network: + varname = "NETWORK_PROCESS_CMD_PREFIX"; + break; +#if ENABLE(DATABASE_PROCESS) + case ProcessLauncher::ProcessType::Database: + varname = "DATABASE_PROCESS_CMD_PREFIX"; + break; +#endif + } + const char* processCmdPrefix = getenv(varname); + if (processCmdPrefix && *processCmdPrefix) + launchOptions.processCmdPrefix = String::fromUTF8(processCmdPrefix); +#endif // !defined(NDEBUG) && (PLATFORM(GTK) || PLATFORM(EFL) +} + +void ChildProcessProxy::connect() +{ + ASSERT(!m_processLauncher); + ProcessLauncher::LaunchOptions launchOptions; + getLaunchOptions(launchOptions); + m_processLauncher = ProcessLauncher::create(this, launchOptions); +} + +void ChildProcessProxy::terminate() +{ +#if PLATFORM(COCOA) + if (m_connection && m_connection->kill()) + return; +#endif + + // FIXME: We should really merge process launching into IPC connection creation and get rid of the process launcher. + if (m_processLauncher) + m_processLauncher->terminateProcess(); +} + +ChildProcessProxy::State ChildProcessProxy::state() const +{ + if (m_processLauncher && m_processLauncher->isLaunching()) + return ChildProcessProxy::State::Launching; + + if (!m_connection) + return ChildProcessProxy::State::Terminated; + + return ChildProcessProxy::State::Running; +} + +bool ChildProcessProxy::sendMessage(std::unique_ptr<IPC::MessageEncoder> encoder, unsigned messageSendFlags) +{ + switch (state()) { + case State::Launching: + // If we're waiting for the child process to launch, we need to stash away the messages so we can send them once we have a connection. + m_pendingMessages.append(std::make_pair(WTFMove(encoder), messageSendFlags)); + return true; + + case State::Running: + return connection()->sendMessage(WTFMove(encoder), messageSendFlags); + + case State::Terminated: + return false; + } + + return false; +} + +void ChildProcessProxy::addMessageReceiver(IPC::StringReference messageReceiverName, IPC::MessageReceiver& messageReceiver) +{ + m_messageReceiverMap.addMessageReceiver(messageReceiverName, messageReceiver); +} + +void ChildProcessProxy::addMessageReceiver(IPC::StringReference messageReceiverName, uint64_t destinationID, IPC::MessageReceiver& messageReceiver) +{ + m_messageReceiverMap.addMessageReceiver(messageReceiverName, destinationID, messageReceiver); +} + +void ChildProcessProxy::removeMessageReceiver(IPC::StringReference messageReceiverName, uint64_t destinationID) +{ + m_messageReceiverMap.removeMessageReceiver(messageReceiverName, destinationID); +} + +void ChildProcessProxy::removeMessageReceiver(IPC::StringReference messageReceiverName) +{ + m_messageReceiverMap.removeMessageReceiver(messageReceiverName); +} + +bool ChildProcessProxy::dispatchMessage(IPC::Connection& connection, IPC::MessageDecoder& decoder) +{ + return m_messageReceiverMap.dispatchMessage(connection, decoder); +} + +bool ChildProcessProxy::dispatchSyncMessage(IPC::Connection& connection, IPC::MessageDecoder& decoder, std::unique_ptr<IPC::MessageEncoder>& replyEncoder) +{ + return m_messageReceiverMap.dispatchSyncMessage(connection, decoder, replyEncoder); +} + +void ChildProcessProxy::didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier connectionIdentifier) +{ + ASSERT(!m_connection); + + m_connection = IPC::Connection::createServerConnection(connectionIdentifier, *this); +#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED <= 101000 + m_connection->setShouldCloseConnectionOnMachExceptions(); +#endif + + connectionWillOpen(*m_connection); + m_connection->open(); + + for (size_t i = 0; i < m_pendingMessages.size(); ++i) { + std::unique_ptr<IPC::MessageEncoder> message = WTFMove(m_pendingMessages[i].first); + unsigned messageSendFlags = m_pendingMessages[i].second; + m_connection->sendMessage(WTFMove(message), messageSendFlags); + } + + m_pendingMessages.clear(); +} + +void ChildProcessProxy::shutDownProcess() +{ + switch (state()) { + case State::Launching: + m_processLauncher->invalidate(); + m_processLauncher = nullptr; + break; + case State::Running: +#if PLATFORM(IOS) + // On iOS deploy a watchdog in the UI process, since the child process may be suspended. + // If 30s is insufficient for any outstanding activity to complete cleanly, then it will be killed. + ASSERT(m_connection); + m_connection->terminateSoon(30); +#endif + break; + case State::Terminated: + return; + } + + if (!m_connection) + return; + + processWillShutDown(*m_connection); + + if (canSendMessage()) + send(Messages::ChildProcess::ShutDown(), 0); + + m_connection->invalidate(); + m_connection = nullptr; +} + +void ChildProcessProxy::connectionWillOpen(IPC::Connection&) +{ +} + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/ChildProcessProxy.h b/Source/WebKit2/UIProcess/ChildProcessProxy.h new file mode 100644 index 000000000..752075a2c --- /dev/null +++ b/Source/WebKit2/UIProcess/ChildProcessProxy.h @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2012 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ChildProcessProxy_h +#define ChildProcessProxy_h + +#include "Connection.h" +#include "MessageReceiverMap.h" +#include "ProcessLauncher.h" + +#include <wtf/ThreadSafeRefCounted.h> + +namespace WebKit { + +class ChildProcessProxy : ProcessLauncher::Client, public IPC::Connection::Client, public ThreadSafeRefCounted<ChildProcessProxy> { + WTF_MAKE_NONCOPYABLE(ChildProcessProxy); + +public: + ChildProcessProxy(); + virtual ~ChildProcessProxy(); + + // FIXME: This function does an unchecked upcast, and it is only used in a deprecated code path. Would like to get rid of it. + static ChildProcessProxy* fromConnection(IPC::Connection*); + + void connect(); + void terminate(); + + template<typename T> bool send(T&& message, uint64_t destinationID, unsigned messageSendFlags = 0); + template<typename T> bool sendSync(T&& message, typename T::Reply&&, uint64_t destinationID, std::chrono::milliseconds timeout = std::chrono::seconds(1), unsigned sendSyncFlags = 0); + + IPC::Connection* connection() const + { + ASSERT(m_connection); + return m_connection.get(); + } + + void addMessageReceiver(IPC::StringReference messageReceiverName, IPC::MessageReceiver&); + void addMessageReceiver(IPC::StringReference messageReceiverName, uint64_t destinationID, IPC::MessageReceiver&); + void removeMessageReceiver(IPC::StringReference messageReceiverName, uint64_t destinationID); + void removeMessageReceiver(IPC::StringReference messageReceiverName); + + enum class State { + Launching, + Running, + Terminated, + }; + State state() const; + + pid_t processIdentifier() const { return m_processLauncher->processIdentifier(); } + + bool canSendMessage() const { return state() != State::Terminated;} + bool sendMessage(std::unique_ptr<IPC::MessageEncoder>, unsigned messageSendFlags); + + void shutDownProcess(); + +protected: + // ProcessLauncher::Client + virtual void didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier) override; + + bool dispatchMessage(IPC::Connection&, IPC::MessageDecoder&); + bool dispatchSyncMessage(IPC::Connection&, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&); + + virtual void getLaunchOptions(ProcessLauncher::LaunchOptions&); + +private: + virtual void connectionWillOpen(IPC::Connection&); + virtual void processWillShutDown(IPC::Connection&) = 0; + + Vector<std::pair<std::unique_ptr<IPC::MessageEncoder>, unsigned>> m_pendingMessages; + RefPtr<ProcessLauncher> m_processLauncher; + RefPtr<IPC::Connection> m_connection; + IPC::MessageReceiverMap m_messageReceiverMap; +}; + +template<typename T> +bool ChildProcessProxy::send(T&& message, uint64_t destinationID, unsigned messageSendFlags) +{ + COMPILE_ASSERT(!T::isSync, AsyncMessageExpected); + + auto encoder = std::make_unique<IPC::MessageEncoder>(T::receiverName(), T::name(), destinationID); + encoder->encode(message.arguments()); + + return sendMessage(WTFMove(encoder), messageSendFlags); +} + +template<typename U> +bool ChildProcessProxy::sendSync(U&& message, typename U::Reply&& reply, uint64_t destinationID, std::chrono::milliseconds timeout, unsigned sendSyncFlags) +{ + COMPILE_ASSERT(U::isSync, SyncMessageExpected); + + if (!m_connection) + return false; + + return connection()->sendSync(std::forward<U>(message), WTFMove(reply), destinationID, timeout, sendSyncFlags); +} + +} // namespace WebKit + +#endif // ChildProcessProxy_h diff --git a/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedDrawingAreaProxy.cpp b/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedDrawingAreaProxy.cpp new file mode 100644 index 000000000..512b89a18 --- /dev/null +++ b/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedDrawingAreaProxy.cpp @@ -0,0 +1,239 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if USE(COORDINATED_GRAPHICS) +#include "CoordinatedDrawingAreaProxy.h" + +#include "CoordinatedLayerTreeHostProxy.h" +#include "DrawingAreaMessages.h" +#include "DrawingAreaProxyMessages.h" +#include "LayerTreeContext.h" +#include "UpdateInfo.h" +#include "WebPageGroup.h" +#include "WebPageProxy.h" +#include "WebPreferences.h" +#include "WebProcessProxy.h" +#include <WebCore/Region.h> + +using namespace WebCore; + +namespace WebKit { + +CoordinatedDrawingAreaProxy::CoordinatedDrawingAreaProxy(WebPageProxy& webPageProxy) + : DrawingAreaProxy(DrawingAreaTypeCoordinated, webPageProxy) + , m_currentBackingStoreStateID(0) + , m_nextBackingStoreStateID(0) + , m_isWaitingForDidUpdateBackingStoreState(false) + , m_hasReceivedFirstUpdate(false) +{ + // Construct the proxy early to allow messages to be sent to the web process while AC is entered there. + m_coordinatedLayerTreeHostProxy = std::make_unique<CoordinatedLayerTreeHostProxy>(this); +} + +CoordinatedDrawingAreaProxy::~CoordinatedDrawingAreaProxy() +{ + // Make sure to exit accelerated compositing mode. + if (isInAcceleratedCompositingMode()) + exitAcceleratedCompositingMode(); +} + +void CoordinatedDrawingAreaProxy::updateViewport() +{ + m_webPageProxy.setViewNeedsDisplay(viewportVisibleRect()); +} + +WebCore::IntRect CoordinatedDrawingAreaProxy::contentsRect() const +{ + return IntRect(IntPoint::zero(), m_webPageProxy.viewSize()); +} + +void CoordinatedDrawingAreaProxy::sizeDidChange() +{ + backingStoreStateDidChange(RespondImmediately); +} + +void CoordinatedDrawingAreaProxy::deviceScaleFactorDidChange() +{ + backingStoreStateDidChange(RespondImmediately); +} + +void CoordinatedDrawingAreaProxy::visibilityDidChange() +{ + // If we don't have a backing store, go ahead and mark the backing store as being changed so + // that when paint we'll actually wait for something to paint and not flash white. + if (m_layerTreeContext.isEmpty()) + backingStoreStateDidChange(DoNotRespondImmediately); +} + +void CoordinatedDrawingAreaProxy::waitForBackingStoreUpdateOnNextPaint() +{ + m_hasReceivedFirstUpdate = true; +} + +void CoordinatedDrawingAreaProxy::didUpdateBackingStoreState(uint64_t backingStoreStateID, const UpdateInfo& updateInfo, const LayerTreeContext& layerTreeContext) +{ + ASSERT_ARG(backingStoreStateID, backingStoreStateID <= m_nextBackingStoreStateID); + ASSERT_ARG(backingStoreStateID, backingStoreStateID > m_currentBackingStoreStateID); + m_currentBackingStoreStateID = backingStoreStateID; + + m_isWaitingForDidUpdateBackingStoreState = false; + + // Stop the responsiveness timer that was started in sendUpdateBackingStoreState. + m_webPageProxy.process().responsivenessTimer().stop(); + + if (layerTreeContext != m_layerTreeContext) { + if (!m_layerTreeContext.isEmpty()) { + exitAcceleratedCompositingMode(); + ASSERT(m_layerTreeContext.isEmpty()); + } + + if (!layerTreeContext.isEmpty()) { + enterAcceleratedCompositingMode(layerTreeContext); + ASSERT(layerTreeContext == m_layerTreeContext); + } + } + + if (m_nextBackingStoreStateID != m_currentBackingStoreStateID) + sendUpdateBackingStoreState(RespondImmediately); + else + m_hasReceivedFirstUpdate = true; +} + +void CoordinatedDrawingAreaProxy::enterAcceleratedCompositingMode(uint64_t backingStoreStateID, const LayerTreeContext& layerTreeContext) +{ + ASSERT_ARG(backingStoreStateID, backingStoreStateID <= m_currentBackingStoreStateID); + if (backingStoreStateID < m_currentBackingStoreStateID) + return; + + enterAcceleratedCompositingMode(layerTreeContext); +} + +void CoordinatedDrawingAreaProxy::exitAcceleratedCompositingMode(uint64_t backingStoreStateID, const UpdateInfo& updateInfo) +{ + ASSERT_ARG(backingStoreStateID, backingStoreStateID <= m_currentBackingStoreStateID); + if (backingStoreStateID < m_currentBackingStoreStateID) + return; + + exitAcceleratedCompositingMode(); +} + +void CoordinatedDrawingAreaProxy::updateAcceleratedCompositingMode(uint64_t backingStoreStateID, const LayerTreeContext& layerTreeContext) +{ + ASSERT_ARG(backingStoreStateID, backingStoreStateID <= m_currentBackingStoreStateID); + if (backingStoreStateID < m_currentBackingStoreStateID) + return; + + updateAcceleratedCompositingMode(layerTreeContext); +} + +void CoordinatedDrawingAreaProxy::backingStoreStateDidChange(RespondImmediatelyOrNot respondImmediatelyOrNot) +{ + ++m_nextBackingStoreStateID; + sendUpdateBackingStoreState(respondImmediatelyOrNot); +} + +void CoordinatedDrawingAreaProxy::sendUpdateBackingStoreState(RespondImmediatelyOrNot respondImmediatelyOrNot) +{ + ASSERT(m_currentBackingStoreStateID < m_nextBackingStoreStateID); + + if (!m_webPageProxy.isValid()) + return; + + if (m_isWaitingForDidUpdateBackingStoreState) + return; + + if (m_webPageProxy.viewSize().isEmpty() && !m_webPageProxy.useFixedLayout()) + return; + + m_isWaitingForDidUpdateBackingStoreState = respondImmediatelyOrNot == RespondImmediately; + + m_webPageProxy.process().send(Messages::DrawingArea::UpdateBackingStoreState(m_nextBackingStoreStateID, respondImmediatelyOrNot == RespondImmediately, m_webPageProxy.deviceScaleFactor(), m_size, m_scrollOffset), m_webPageProxy.pageID()); + m_scrollOffset = IntSize(); + + if (m_isWaitingForDidUpdateBackingStoreState) { + // Start the responsiveness timer. We will stop it when we hear back from the WebProcess + // in didUpdateBackingStoreState. + m_webPageProxy.process().responsivenessTimer().start(); + } + + if (m_isWaitingForDidUpdateBackingStoreState && !m_layerTreeContext.isEmpty()) { + // Wait for the DidUpdateBackingStoreState message. Normally we do this in CoordinatedDrawingAreaProxy::paint, but that + // function is never called when in accelerated compositing mode. + waitForAndDispatchDidUpdateBackingStoreState(); + } +} + +void CoordinatedDrawingAreaProxy::waitForAndDispatchDidUpdateBackingStoreState() +{ + ASSERT(m_isWaitingForDidUpdateBackingStoreState); + + if (!m_webPageProxy.isValid()) + return; + if (m_webPageProxy.process().state() == WebProcessProxy::State::Launching) + return; + + // FIXME: waitForAndDispatchImmediately will always return the oldest DidUpdateBackingStoreState message that + // hasn't yet been processed. But it might be better to skip ahead to some other DidUpdateBackingStoreState + // message, if multiple DidUpdateBackingStoreState messages are waiting to be processed. For instance, we could + // choose the most recent one, or the one that is closest to our current size. + + // The timeout, in seconds, we use when waiting for a DidUpdateBackingStoreState message when we're asked to paint. + m_webPageProxy.process().connection()->waitForAndDispatchImmediately<Messages::DrawingAreaProxy::DidUpdateBackingStoreState>(m_webPageProxy.pageID(), std::chrono::milliseconds(500)); +} + +void CoordinatedDrawingAreaProxy::enterAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext) +{ + ASSERT(!isInAcceleratedCompositingMode()); + + m_layerTreeContext = layerTreeContext; + m_webPageProxy.enterAcceleratedCompositingMode(layerTreeContext); +} + +void CoordinatedDrawingAreaProxy::setVisibleContentsRect(const WebCore::FloatRect& visibleContentsRect, const WebCore::FloatPoint& trajectoryVector) +{ + m_coordinatedLayerTreeHostProxy->setVisibleContentsRect(visibleContentsRect, trajectoryVector); +} + +void CoordinatedDrawingAreaProxy::exitAcceleratedCompositingMode() +{ + ASSERT(isInAcceleratedCompositingMode()); + + m_layerTreeContext = LayerTreeContext(); + m_webPageProxy.exitAcceleratedCompositingMode(); +} + +void CoordinatedDrawingAreaProxy::updateAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext) +{ + ASSERT(isInAcceleratedCompositingMode()); + + m_layerTreeContext = layerTreeContext; + m_webPageProxy.updateAcceleratedCompositingMode(layerTreeContext); +} + +} // namespace WebKit +#endif // USE(COORDINATED_GRAPHICS) diff --git a/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedDrawingAreaProxy.h b/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedDrawingAreaProxy.h new file mode 100644 index 000000000..bef7730d0 --- /dev/null +++ b/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedDrawingAreaProxy.h @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef CoordinatedDrawingAreaProxy_h +#define CoordinatedDrawingAreaProxy_h + +#if USE(COORDINATED_GRAPHICS) + +#include "BackingStore.h" +#include "DrawingAreaProxy.h" +#include "LayerTreeContext.h" +#include <wtf/RunLoop.h> + +namespace WebCore { +class Region; +} + +namespace WebKit { + +class CoordinatedLayerTreeHostProxy; + +class CoordinatedDrawingAreaProxy : public DrawingAreaProxy { +public: + explicit CoordinatedDrawingAreaProxy(WebPageProxy&); + virtual ~CoordinatedDrawingAreaProxy(); + + bool isInAcceleratedCompositingMode() const { return !m_layerTreeContext.isEmpty(); } + void visibilityDidChange(); + + void setVisibleContentsRect(const WebCore::FloatRect& visibleContentsRect, const WebCore::FloatPoint& trajectory); + + bool hasReceivedFirstUpdate() const { return m_hasReceivedFirstUpdate; } + + CoordinatedLayerTreeHostProxy& coordinatedLayerTreeHostProxy() const { return *m_coordinatedLayerTreeHostProxy.get(); } + + WebCore::IntRect viewportVisibleRect() const { return contentsRect(); } + WebCore::IntRect contentsRect() const; + void updateViewport(); + + WebPageProxy& page() { return m_webPageProxy; } +private: + // DrawingAreaProxy + virtual void sizeDidChange(); + virtual void deviceScaleFactorDidChange(); + + virtual void waitForBackingStoreUpdateOnNextPaint(); + + // IPC message handlers + virtual void didUpdateBackingStoreState(uint64_t backingStoreStateID, const UpdateInfo&, const LayerTreeContext&); + virtual void enterAcceleratedCompositingMode(uint64_t backingStoreStateID, const LayerTreeContext&); + virtual void exitAcceleratedCompositingMode(uint64_t backingStoreStateID, const UpdateInfo&); + virtual void updateAcceleratedCompositingMode(uint64_t backingStoreStateID, const LayerTreeContext&); + + enum RespondImmediatelyOrNot { DoNotRespondImmediately, RespondImmediately }; + void backingStoreStateDidChange(RespondImmediatelyOrNot); + void sendUpdateBackingStoreState(RespondImmediatelyOrNot); + void waitForAndDispatchDidUpdateBackingStoreState(); + + void enterAcceleratedCompositingMode(const LayerTreeContext&); + void exitAcceleratedCompositingMode(); + void updateAcceleratedCompositingMode(const LayerTreeContext&); + + std::unique_ptr<CoordinatedLayerTreeHostProxy> m_coordinatedLayerTreeHostProxy; + + // The state ID corresponding to our current backing store. Updated whenever we allocate + // a new backing store. Any messages received that correspond to an earlier state are ignored, + // as they don't apply to our current backing store. + uint64_t m_currentBackingStoreStateID; + + // The next backing store state ID we will request the web process update to. Incremented + // whenever our state changes in a way that will require a new backing store to be allocated. + uint64_t m_nextBackingStoreStateID; + + // The current layer tree context. + LayerTreeContext m_layerTreeContext; + + // Whether we've sent a UpdateBackingStoreState message and are now waiting for a DidUpdateBackingStoreState message. + // Used to throttle UpdateBackingStoreState messages so we don't send them faster than the Web process can handle. + bool m_isWaitingForDidUpdateBackingStoreState; + + // For a new Drawing Area don't draw anything until the WebProcess has sent over the first content. + bool m_hasReceivedFirstUpdate; +}; + +} // namespace WebKit + +#endif // USE(COORDINATED_GRAPHICS) +#endif // CoordinatedDrawingAreaProxy_h diff --git a/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.cpp b/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.cpp new file mode 100644 index 000000000..de1f0af8e --- /dev/null +++ b/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.cpp @@ -0,0 +1,99 @@ +/* + Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies) + Copyright (C) 2013 Company 100, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if USE(COORDINATED_GRAPHICS) +#include "CoordinatedLayerTreeHostProxy.h" + +#include "CoordinatedDrawingAreaProxy.h" +#include "CoordinatedLayerTreeHostMessages.h" +#include "CoordinatedLayerTreeHostProxyMessages.h" +#include "WebPageProxy.h" +#include "WebProcessProxy.h" +#include <WebCore/CoordinatedGraphicsState.h> + +namespace WebKit { + +using namespace WebCore; + +CoordinatedLayerTreeHostProxy::CoordinatedLayerTreeHostProxy(CoordinatedDrawingAreaProxy* drawingAreaProxy) + : m_drawingAreaProxy(drawingAreaProxy) + , m_scene(adoptRef(new CoordinatedGraphicsScene(this))) +{ + m_drawingAreaProxy->page().process().addMessageReceiver(Messages::CoordinatedLayerTreeHostProxy::messageReceiverName(), m_drawingAreaProxy->page().pageID(), *this); +} + +CoordinatedLayerTreeHostProxy::~CoordinatedLayerTreeHostProxy() +{ + m_drawingAreaProxy->page().process().removeMessageReceiver(Messages::CoordinatedLayerTreeHostProxy::messageReceiverName(), m_drawingAreaProxy->page().pageID()); + m_scene->detach(); +} + +void CoordinatedLayerTreeHostProxy::updateViewport() +{ + m_drawingAreaProxy->updateViewport(); +} + +void CoordinatedLayerTreeHostProxy::dispatchUpdate(std::function<void()> function) +{ + m_scene->appendUpdate(WTFMove(function)); +} + +void CoordinatedLayerTreeHostProxy::commitCoordinatedGraphicsState(const CoordinatedGraphicsState& graphicsState) +{ + RefPtr<CoordinatedGraphicsScene> sceneProtector(m_scene); + dispatchUpdate([=] { + sceneProtector->commitSceneState(graphicsState); + }); + + updateViewport(); +#if USE(COORDINATED_GRAPHICS_MULTIPROCESS) + m_drawingAreaProxy->page().didRenderFrame(graphicsState.contentsSize, graphicsState.coveredRect); +#endif +} + +void CoordinatedLayerTreeHostProxy::setVisibleContentsRect(const FloatRect& rect, const FloatPoint& trajectoryVector) +{ + if (rect == m_lastSentVisibleRect && trajectoryVector == m_lastSentTrajectoryVector) + return; + + m_drawingAreaProxy->page().process().send(Messages::CoordinatedLayerTreeHost::SetVisibleContentsRect(rect, trajectoryVector), m_drawingAreaProxy->page().pageID()); + m_lastSentVisibleRect = rect; + m_lastSentTrajectoryVector = trajectoryVector; +} + +void CoordinatedLayerTreeHostProxy::renderNextFrame() +{ + m_drawingAreaProxy->page().process().send(Messages::CoordinatedLayerTreeHost::RenderNextFrame(), m_drawingAreaProxy->page().pageID()); +} + +void CoordinatedLayerTreeHostProxy::purgeBackingStores() +{ + m_drawingAreaProxy->page().process().send(Messages::CoordinatedLayerTreeHost::PurgeBackingStores(), m_drawingAreaProxy->page().pageID()); +} + +void CoordinatedLayerTreeHostProxy::commitScrollOffset(uint32_t layerID, const IntSize& offset) +{ + m_drawingAreaProxy->page().process().send(Messages::CoordinatedLayerTreeHost::CommitScrollOffset(layerID, offset), m_drawingAreaProxy->page().pageID()); +} + +} +#endif // USE(COORDINATED_GRAPHICS) diff --git a/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.h b/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.h new file mode 100644 index 000000000..4655423f6 --- /dev/null +++ b/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.h @@ -0,0 +1,74 @@ +/* + Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies) + Copyright (C) 2013 Company 100, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef CoordinatedLayerTreeHostProxy_h +#define CoordinatedLayerTreeHostProxy_h + +#if USE(COORDINATED_GRAPHICS) + +#include "CoordinatedGraphicsArgumentCoders.h" +#include "CoordinatedGraphicsScene.h" +#include "MessageReceiver.h" +#include <functional> + +namespace WebCore { +struct CoordinatedGraphicsState; +class IntSize; +} + +namespace WebKit { + +class CoordinatedDrawingAreaProxy; + +class CoordinatedLayerTreeHostProxy : public CoordinatedGraphicsSceneClient, public IPC::MessageReceiver { + WTF_MAKE_NONCOPYABLE(CoordinatedLayerTreeHostProxy); + WTF_MAKE_FAST_ALLOCATED; +public: + explicit CoordinatedLayerTreeHostProxy(CoordinatedDrawingAreaProxy*); + virtual ~CoordinatedLayerTreeHostProxy(); + + void commitCoordinatedGraphicsState(const WebCore::CoordinatedGraphicsState&); + + void setVisibleContentsRect(const WebCore::FloatRect&, const WebCore::FloatPoint& trajectoryVector); + CoordinatedGraphicsScene* coordinatedGraphicsScene() const { return m_scene.get(); } + + virtual void updateViewport() override; + virtual void renderNextFrame() override; + virtual void purgeBackingStores() override; + + virtual void commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset) override; + +protected: + void dispatchUpdate(std::function<void()>); + + // IPC::MessageReceiver + virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override; + + CoordinatedDrawingAreaProxy* m_drawingAreaProxy; + RefPtr<CoordinatedGraphicsScene> m_scene; + WebCore::FloatRect m_lastSentVisibleRect; + WebCore::FloatPoint m_lastSentTrajectoryVector; +}; + +} // namespace WebKit + +#endif // USE(COORDINATED_GRAPHICS) + +#endif // CoordinatedLayerTreeHostProxy_h diff --git a/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.messages.in b/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.messages.in new file mode 100644 index 000000000..edb2f0f77 --- /dev/null +++ b/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.messages.in @@ -0,0 +1,26 @@ +# +# Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies) +# Copyright (C) 2013 Company 100, Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public License +# along with this library; see the file COPYING.LIB. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. +# + +#if USE(COORDINATED_GRAPHICS) +messages -> CoordinatedLayerTreeHostProxy { + + CommitCoordinatedGraphicsState(struct WebCore::CoordinatedGraphicsState state) +} +#endif diff --git a/Source/WebKit2/UIProcess/CoordinatedGraphics/PageViewportController.cpp b/Source/WebKit2/UIProcess/CoordinatedGraphics/PageViewportController.cpp new file mode 100644 index 000000000..1715657b8 --- /dev/null +++ b/Source/WebKit2/UIProcess/CoordinatedGraphics/PageViewportController.cpp @@ -0,0 +1,367 @@ +/* + * Copyright (C) 2011, 2012 Nokia Corporation and/or its subsidiary(-ies) + * Copyright (C) 2011 Benjamin Poulain <benjamin@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this program; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" +#include "PageViewportController.h" + +#include "CoordinatedDrawingAreaProxy.h" +#include "PageViewportControllerClient.h" +#include "WebPageProxy.h" +#include <WebCore/FloatRect.h> +#include <WebCore/FloatSize.h> +#include <wtf/MathExtras.h> + +using namespace WebCore; + +namespace WebKit { + +PageViewportController::PageViewportController(WebKit::WebPageProxy* proxy, PageViewportControllerClient& client) + : m_webPageProxy(proxy) + , m_client(client) + , m_allowsUserScaling(false) + , m_minimumScaleToFit(1) + , m_initiallyFitToViewport(true) + , m_hadUserInteraction(false) + , m_pageScaleFactor(1) + , m_pendingPositionChange(false) + , m_pendingScaleChange(false) + , m_layerTreeStateIsFrozen(false) +{ + // Initializing Viewport Raw Attributes to avoid random negative or infinity scale factors + // if there is a race condition between the first layout and setting the viewport attributes for the first time. + m_rawAttributes.minimumScale = 1; + m_rawAttributes.maximumScale = 1; + m_rawAttributes.userScalable = m_allowsUserScaling; + + // The initial scale might be implicit and set to -1, in this case we have to infer it + // using the viewport size and the final layout size. + // To be able to assert for valid scale we initialize it to -1. + m_rawAttributes.initialScale = -1; +} + +float PageViewportController::innerBoundedViewportScale(float viewportScale) const +{ + return clampTo(viewportScale, m_minimumScaleToFit, m_rawAttributes.maximumScale); +} + +float PageViewportController::outerBoundedViewportScale(float viewportScale) const +{ + if (m_allowsUserScaling) { + // Bounded by [0.1, 10.0] like the viewport meta code in WebCore. + float hardMin = std::max<float>(0.1, 0.5 * m_minimumScaleToFit); + float hardMax = std::min<float>(10, 2 * m_rawAttributes.maximumScale); + return clampTo(viewportScale, hardMin, hardMax); + } + return innerBoundedViewportScale(viewportScale); +} + +float PageViewportController::deviceScaleFactor() const +{ + return m_webPageProxy->deviceScaleFactor(); +} + +static inline bool isIntegral(float value) +{ + return static_cast<int>(value) == value; +} + +FloatPoint PageViewportController::pixelAlignedFloatPoint(const FloatPoint& framePosition) +{ +#if PLATFORM(EFL) + float effectiveScale = m_pageScaleFactor * deviceScaleFactor(); + if (!isIntegral(effectiveScale)) { + // To avoid blurryness, modify the position so that it maps into a discrete device position. + FloatPoint scaledPos(framePosition); + + // Scale by the effective scale factor to compute the screen-relative position. + scaledPos.scale(effectiveScale, effectiveScale); + + // Round to integer boundaries. + FloatPoint alignedPos = roundedIntPoint(scaledPos); + + // Convert back to CSS coordinates. + alignedPos.scale(1 / effectiveScale, 1 / effectiveScale); + + return alignedPos; + } +#endif + + return framePosition; +} + +FloatPoint PageViewportController::boundContentsPositionAtScale(const WebCore::FloatPoint& framePosition, float scale) +{ + // We need to floor the viewport here as to allow aligning the content in device units. If not, + // it might not be possible to scroll the last pixel and that affects fixed position elements. + FloatRect bounds; + bounds.setWidth(std::max(0.f, m_contentsSize.width() - floorf(m_viewportSize.width() / scale))); + bounds.setHeight(std::max(0.f, m_contentsSize.height() - floorf(m_viewportSize.height() / scale))); + + FloatPoint position; + position.setX(clampTo(framePosition.x(), bounds.x(), bounds.width())); + position.setY(clampTo(framePosition.y(), bounds.y(), bounds.height())); + + return position; +} + +FloatPoint PageViewportController::boundContentsPosition(const WebCore::FloatPoint& framePosition) +{ + return boundContentsPositionAtScale(framePosition, m_pageScaleFactor); +} + +void PageViewportController::didCommitLoad() +{ + // Do not count the previous committed page contents as covered. + m_lastFrameCoveredRect = FloatRect(); + + // Do not continue to use the content size of the previous page. + m_contentsSize = IntSize(); + + m_contentsPosition = FloatPoint(); + + m_layerTreeStateIsFrozen = true; + + m_initiallyFitToViewport = true; + + // Reset the position to the top, page/history scroll requests may override this before we re-enable rendering. + applyPositionAfterRenderingContents(FloatPoint()); +} + +void PageViewportController::didChangeContentsSize(const IntSize& newSize) +{ + m_contentsSize = newSize; + + bool minimumScaleUpdated = updateMinimumScaleToFit(false); + + if (m_initiallyFitToViewport) { + // Restrict scale factors to m_minimumScaleToFit. + ASSERT(m_minimumScaleToFit > 0); + m_rawAttributes.initialScale = m_minimumScaleToFit; + WebCore::restrictScaleFactorToInitialScaleIfNotUserScalable(m_rawAttributes); + } + + if (minimumScaleUpdated) + m_client.didChangeViewportAttributes(); + + // We might have pending position change which is now possible. + syncVisibleContents(); +} + +void PageViewportController::didRenderFrame(const IntSize& contentsSize, const IntRect& coveredRect) +{ + if (m_clientContentsSize != contentsSize) { + m_clientContentsSize = contentsSize; + // Only update the viewport's contents dimensions along with its render if the + // size actually changed since animations on the page trigger DidRenderFrame + // messages without causing dimension changes. + m_client.didChangeContentsSize(contentsSize); + } + + m_lastFrameCoveredRect = coveredRect; + + // Apply any scale or scroll position we locked to be set on the viewport + // only when there is something to display there. The scale goes first to + // avoid offsetting our deferred position by scaling at the viewport center. + // All position and scale changes resulting from a web process event should + // go through here to be applied on the viewport to avoid showing incomplete + // tiles to the user during a few milliseconds. + + if (m_pendingScaleChange) { + m_pendingScaleChange = false; + m_client.setPageScaleFactor(m_pageScaleFactor); + + // The scale changed, we have to re-pixel align. + m_pendingPositionChange = true; + FloatPoint currentDiscretePos = roundedIntPoint(m_contentsPosition); + FloatPoint pixelAlignedPos = pixelAlignedFloatPoint(currentDiscretePos); + m_contentsPosition = boundContentsPosition(pixelAlignedPos); + + m_webPageProxy->scalePage(m_pageScaleFactor, roundedIntPoint(m_contentsPosition)); + } + + // There might be rendered frames not covering our requested position yet, wait for it. + FloatRect endVisibleContentRect(m_contentsPosition, visibleContentsSize()); + if (m_pendingPositionChange && endVisibleContentRect.intersects(coveredRect)) { + m_client.setViewportPosition(m_contentsPosition); + m_pendingPositionChange = false; + } + + m_layerTreeStateIsFrozen = false; +} + +void PageViewportController::pageTransitionViewportReady() +{ + if (!m_rawAttributes.layoutSize.isEmpty() && m_initiallyFitToViewport) { + m_hadUserInteraction = false; + float initialScale = m_initiallyFitToViewport ? m_minimumScaleToFit : m_rawAttributes.initialScale; + applyScaleAfterRenderingContents(innerBoundedViewportScale(initialScale)); + } + +#if USE(COORDINATED_GRAPHICS_MULTIPROCESS) + // At this point we should already have received the first viewport arguments and the requested scroll + // position for the newly loaded page and sent our reactions to the web process. It's now safe to tell + // the web process to start rendering the new page contents and possibly re-use the current tiles. + // This assumes that all messages have been handled in order and that nothing has been pushed back on the event loop. + m_webPageProxy->commitPageTransitionViewport(); +#endif +} + +void PageViewportController::pageDidRequestScroll(const IntPoint& cssPosition) +{ + // Ignore the request if suspended. Can only happen due to delay in event delivery. + if (m_webPageProxy->areActiveDOMObjectsAndAnimationsSuspended()) + return; + + FloatPoint boundPosition = boundContentsPosition(FloatPoint(cssPosition)); + FloatPoint alignedPosition = pixelAlignedFloatPoint(boundPosition); + FloatRect endVisibleContentRect(alignedPosition, visibleContentsSize()); + + if (m_lastFrameCoveredRect.intersects(endVisibleContentRect)) + m_client.setViewportPosition(alignedPosition); + else { + // Keep the unbound position in case the contents size is changed later on. + FloatPoint position = pixelAlignedFloatPoint(FloatPoint(cssPosition)); + applyPositionAfterRenderingContents(position); + } +} + +void PageViewportController::didChangeViewportSize(const FloatSize& newSize) +{ + if (newSize.isEmpty()) + return; + + m_viewportSize = newSize; +} + +void PageViewportController::didChangeContentsVisibility(const FloatPoint& position, float scale, const FloatPoint& trajectoryVector) +{ + if (!m_pendingPositionChange) + m_contentsPosition = position; + if (!m_pendingScaleChange) + applyScaleAfterRenderingContents(scale); + + syncVisibleContents(trajectoryVector); +} + +bool PageViewportController::syncVisibleContents(const FloatPoint& trajectoryVector) +{ + CoordinatedDrawingAreaProxy* drawingArea = static_cast<CoordinatedDrawingAreaProxy*>(m_webPageProxy->drawingArea()); + if (!drawingArea || m_viewportSize.isEmpty() || m_contentsSize.isEmpty()) + return false; + + FloatRect visibleContentsRect(boundContentsPosition(m_contentsPosition), visibleContentsSize()); + visibleContentsRect.intersect(FloatRect(FloatPoint::zero(), m_contentsSize)); + drawingArea->setVisibleContentsRect(visibleContentsRect, trajectoryVector); + + if (!m_layerTreeStateIsFrozen) + m_client.didChangeVisibleContents(); + + return true; +} + +void PageViewportController::didChangeViewportAttributes(const WebCore::ViewportAttributes& newAttributes) +{ + if (!m_initiallyFitToViewport) + return; + + if (newAttributes.layoutSize.isEmpty()) + return; + + m_rawAttributes = newAttributes; + m_allowsUserScaling = !!m_rawAttributes.userScalable; + m_initiallyFitToViewport = (m_rawAttributes.initialScale < 0); + + if (!m_initiallyFitToViewport) + WebCore::restrictScaleFactorToInitialScaleIfNotUserScalable(m_rawAttributes); + + updateMinimumScaleToFit(true); + + // As the viewport attributes are calculated when loading pages, after load, or after + // viewport resize, it is important that we inform the client of the new scale and + // position, so that the content can be positioned correctly and pixel aligned. + m_pendingPositionChange = true; + m_pendingScaleChange = true; + + m_client.didChangeViewportAttributes(); +} + +FloatSize PageViewportController::visibleContentsSize() const +{ + return FloatSize(m_viewportSize.width() / m_pageScaleFactor, m_viewportSize.height() / m_pageScaleFactor); +} + +void PageViewportController::applyScaleAfterRenderingContents(float scale) +{ + if (m_pageScaleFactor == scale) + return; + + float oldPageScaleFactor = m_pageScaleFactor; + m_pageScaleFactor = scale; + m_pendingScaleChange = true; + if (!syncVisibleContents()) { + m_pageScaleFactor = oldPageScaleFactor; + m_webPageProxy->scalePage(m_pageScaleFactor, roundedIntPoint(m_contentsPosition)); + } +} + +void PageViewportController::applyPositionAfterRenderingContents(const FloatPoint& pos) +{ + if (m_contentsPosition == pos) + return; + + m_contentsPosition = pos; + m_pendingPositionChange = true; + syncVisibleContents(); +} + +bool PageViewportController::updateMinimumScaleToFit(bool userInitiatedUpdate) +{ + if (m_viewportSize.isEmpty() || m_contentsSize.isEmpty() || !m_initiallyFitToViewport || m_hadUserInteraction) + return false; + + // FIXME: Why this arbitrary precision? We likely want to omit the third argument so that + // std::numeric_limits<float>::epsilon() is used instead, similarly to Mac / iOS. + bool currentlyScaledToFit = WTF::areEssentiallyEqual(m_pageScaleFactor, m_minimumScaleToFit, 0.0001f); + float minimumScale = WebCore::computeMinimumScaleFactorForContentContained(m_rawAttributes, WebCore::roundedIntSize(m_viewportSize), WebCore::roundedIntSize(m_contentsSize)); + + if (minimumScale <= 0) + return false; + + if (!WTF::areEssentiallyEqual(minimumScale, m_minimumScaleToFit, 0.0001f)) { + m_minimumScaleToFit = minimumScale; + + if (!m_webPageProxy->areActiveDOMObjectsAndAnimationsSuspended()) { + if (!m_hadUserInteraction || (userInitiatedUpdate && currentlyScaledToFit)) + applyScaleAfterRenderingContents(m_minimumScaleToFit); + else { + // Ensure the effective scale stays within bounds. + float boundedScale = innerBoundedViewportScale(m_pageScaleFactor); + if (!WTF::areEssentiallyEqual(boundedScale, m_pageScaleFactor, 0.0001f)) + applyScaleAfterRenderingContents(boundedScale); + } + } + + return true; + } + return false; +} + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/CoordinatedGraphics/PageViewportController.h b/Source/WebKit2/UIProcess/CoordinatedGraphics/PageViewportController.h new file mode 100644 index 000000000..e02d7671d --- /dev/null +++ b/Source/WebKit2/UIProcess/CoordinatedGraphics/PageViewportController.h @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2011, 2012 Nokia Corporation and/or its subsidiary(-ies) + * Copyright (C) 2011 Benjamin Poulain <benjamin@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this program; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef PageViewportController_h +#define PageViewportController_h + +#include <WebCore/FloatPoint.h> +#include <WebCore/FloatRect.h> +#include <WebCore/FloatSize.h> +#include <WebCore/ViewportArguments.h> +#include <wtf/Noncopyable.h> + +namespace WebCore { +class IntPoint; +class IntSize; +} + +namespace WebKit { + +class WebPageProxy; +class PageViewportController; +class PageViewportControllerClient; + +class PageViewportController { + WTF_MAKE_NONCOPYABLE(PageViewportController); + +public: + PageViewportController(WebKit::WebPageProxy*, PageViewportControllerClient&); + virtual ~PageViewportController() { } + + float innerBoundedViewportScale(float) const; + float outerBoundedViewportScale(float) const; + + WebCore::FloatPoint pixelAlignedFloatPoint(const WebCore::FloatPoint&); + + WebCore::FloatPoint boundContentsPosition(const WebCore::FloatPoint&); + WebCore::FloatPoint boundContentsPositionAtScale(const WebCore::FloatPoint&, float scale); + + WebCore::FloatSize visibleContentsSize() const; + + bool hadUserInteraction() const { return m_hadUserInteraction; } + bool allowsUserScaling() const { return m_allowsUserScaling; } + + WebCore::FloatSize contentsLayoutSize() const { return m_rawAttributes.layoutSize; } + float deviceScaleFactor() const; + float minimumScale() const { return m_minimumScaleToFit; } + float maximumScale() const { return m_rawAttributes.maximumScale; } + float currentScale() const { return m_pageScaleFactor; } + + void setHadUserInteraction(bool didUserInteract) { m_hadUserInteraction = didUserInteract; } + void setInitiallyFitToViewport(bool initiallyFit) { m_initiallyFitToViewport = initiallyFit; } + + // Notifications from the viewport. + void didChangeViewportSize(const WebCore::FloatSize& newSize); + void didChangeContentsVisibility(const WebCore::FloatPoint&, float scale, const WebCore::FloatPoint& trajectoryVector = WebCore::FloatPoint::zero()); + + // Notifications from the WebProcess. + void didCommitLoad(); + void didChangeContentsSize(const WebCore::IntSize& newSize); + void didChangeViewportAttributes(const WebCore::ViewportAttributes&); + void didRenderFrame(const WebCore::IntSize& contentsSize, const WebCore::IntRect& coveredRect); + void pageTransitionViewportReady(); + void pageDidRequestScroll(const WebCore::IntPoint& cssPosition); + +private: + bool syncVisibleContents(const WebCore::FloatPoint &trajectoryVector = WebCore::FloatPoint::zero()); + void applyScaleAfterRenderingContents(float scale); + void applyPositionAfterRenderingContents(const WebCore::FloatPoint& pos); + bool updateMinimumScaleToFit(bool userInitiatedUpdate); + + WebPageProxy* const m_webPageProxy; + PageViewportControllerClient& m_client; + + WebCore::ViewportAttributes m_rawAttributes; + + bool m_allowsUserScaling; + float m_minimumScaleToFit; + bool m_initiallyFitToViewport; + + bool m_hadUserInteraction; + + WebCore::FloatPoint m_contentsPosition; + WebCore::FloatSize m_contentsSize; + WebCore::FloatSize m_viewportSize; + WebCore::IntSize m_clientContentsSize; + float m_pageScaleFactor; + + bool m_pendingPositionChange; + bool m_pendingScaleChange; + bool m_layerTreeStateIsFrozen; + WebCore::FloatRect m_lastFrameCoveredRect; +}; + +} // namespace WebKit + +#endif // PageViewportController_h diff --git a/Source/WebKit2/UIProcess/CoordinatedGraphics/WKCoordinatedSceneAPICast.h b/Source/WebKit2/UIProcess/CoordinatedGraphics/WKCoordinatedSceneAPICast.h new file mode 100644 index 000000000..d33dcdaea --- /dev/null +++ b/Source/WebKit2/UIProcess/CoordinatedGraphics/WKCoordinatedSceneAPICast.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies) + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKCoordinatedSceneAPICast_h +#define WKCoordinatedSceneAPICast_h + +#include <WebKit/WKCoordinatedScene.h> + +namespace WebCore { +class TextureMapperLayer; +} + +namespace WebKit { + +class CoordinatedGraphicsScene; + +inline WebKit::CoordinatedGraphicsScene* toImpl(WKCoordinatedScene scene) +{ + return reinterpret_cast<WebKit::CoordinatedGraphicsScene*>(scene); +} + +inline WKCoordinatedScene toAPI(WebKit::CoordinatedGraphicsScene* scene) +{ + return reinterpret_cast<WKCoordinatedScene>(scene); +} + +inline WebCore::TextureMapperLayer* toImpl(WKCoordinatedSceneLayer layer) +{ + return reinterpret_cast<WebCore::TextureMapperLayer*>(layer); +} + +inline WKCoordinatedSceneLayer toAPI(WebCore::TextureMapperLayer* layer) +{ + return reinterpret_cast<WKCoordinatedSceneLayer>(layer); +} + +} // namespace WebKit + +#endif // WKCoordinatedSceneAPICast_h diff --git a/Source/WebKit2/UIProcess/WebDatabaseManagerProxyClient.cpp b/Source/WebKit2/UIProcess/CoordinatedGraphics/WebPageProxyCoordinatedGraphics.cpp index 4e932d218..ad73d369f 100644 --- a/Source/WebKit2/UIProcess/WebDatabaseManagerProxyClient.cpp +++ b/Source/WebKit2/UIProcess/CoordinatedGraphics/WebPageProxyCoordinatedGraphics.cpp @@ -1,5 +1,6 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies) + * Copyright (C) 2013 Samsung Electronics. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -24,26 +25,33 @@ */ #include "config.h" -#include "WebDatabaseManagerProxyClient.h" +#if USE(COORDINATED_GRAPHICS) -#include "WKAPICast.h" +#include "WebPageProxy.h" + +#include "PageClient.h" +#include "WebPageMessages.h" +#include "WebProcessProxy.h" + +using namespace WebCore; namespace WebKit { -void WebDatabaseManagerProxyClient::didModifyOrigin(WebDatabaseManagerProxy* databaseManager, WebSecurityOrigin* origin) +#if USE(COORDINATED_GRAPHICS_MULTIPROCESS) +void WebPageProxy::findZoomableAreaForPoint(const IntPoint& point, const IntSize& area) { - if (!m_client.didModifyOrigin) + if (!isValid()) return; - m_client.didModifyOrigin(toAPI(databaseManager), toAPI(origin), m_client.base.clientInfo); + m_process->send(Messages::WebPage::FindZoomableAreaForPoint(point, area), m_pageID); } -void WebDatabaseManagerProxyClient::didModifyDatabase(WebDatabaseManagerProxy* databaseManager, WebSecurityOrigin* origin, const String& databaseIdentifier) +void WebPageProxy::didFindZoomableArea(const IntPoint& target, const IntRect& area) { - if (!m_client.didModifyDatabase) - return; - - m_client.didModifyDatabase(toAPI(databaseManager), toAPI(origin), toAPI(databaseIdentifier.impl()), m_client.base.clientInfo); + m_pageClient.didFindZoomableArea(target, area); } +#endif } // namespace WebKit + +#endif // USE(COORDINATED_GRAPHICS) diff --git a/Source/WebKit2/UIProcess/Databases/DatabaseProcessProxy.cpp b/Source/WebKit2/UIProcess/Databases/DatabaseProcessProxy.cpp new file mode 100644 index 000000000..7ed02d6dc --- /dev/null +++ b/Source/WebKit2/UIProcess/Databases/DatabaseProcessProxy.cpp @@ -0,0 +1,215 @@ +/* + * Copyright (C) 2013 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "DatabaseProcessProxy.h" + +#include "DatabaseProcessMessages.h" +#include "DatabaseProcessProxyMessages.h" +#include "WebProcessPool.h" +#include "WebsiteData.h" +#include <WebCore/NotImplemented.h> + +#if ENABLE(DATABASE_PROCESS) + +using namespace WebCore; + +namespace WebKit { + +static uint64_t generateCallbackID() +{ + static uint64_t callbackID; + + return ++callbackID; +} + +Ref<DatabaseProcessProxy> DatabaseProcessProxy::create(WebProcessPool* processPool) +{ + return adoptRef(*new DatabaseProcessProxy(processPool)); +} + +DatabaseProcessProxy::DatabaseProcessProxy(WebProcessPool* processPool) + : m_processPool(processPool) + , m_numPendingConnectionRequests(0) +{ + connect(); +} + +DatabaseProcessProxy::~DatabaseProcessProxy() +{ + ASSERT(m_pendingFetchWebsiteDataCallbacks.isEmpty()); + ASSERT(m_pendingDeleteWebsiteDataCallbacks.isEmpty()); + ASSERT(m_pendingDeleteWebsiteDataForOriginsCallbacks.isEmpty()); +} + +void DatabaseProcessProxy::getLaunchOptions(ProcessLauncher::LaunchOptions& launchOptions) +{ + launchOptions.processType = ProcessLauncher::ProcessType::Database; + ChildProcessProxy::getLaunchOptions(launchOptions); +} + +void DatabaseProcessProxy::processWillShutDown(IPC::Connection& connection) +{ + ASSERT_UNUSED(connection, this->connection() == &connection); +} + +void DatabaseProcessProxy::didReceiveMessage(IPC::Connection& connection, IPC::MessageDecoder& decoder) +{ + if (decoder.messageReceiverName() == Messages::DatabaseProcessProxy::messageReceiverName()) { + didReceiveDatabaseProcessProxyMessage(connection, decoder); + return; + } +} + +void DatabaseProcessProxy::fetchWebsiteData(SessionID sessionID, WebsiteDataTypes dataTypes, std::function<void (WebsiteData)> completionHandler) +{ + ASSERT(canSendMessage()); + + uint64_t callbackID = generateCallbackID(); + m_pendingFetchWebsiteDataCallbacks.add(callbackID, WTFMove(completionHandler)); + + send(Messages::DatabaseProcess::FetchWebsiteData(sessionID, dataTypes, callbackID), 0); +} + +void DatabaseProcessProxy::deleteWebsiteData(WebCore::SessionID sessionID, WebsiteDataTypes dataTypes, std::chrono::system_clock::time_point modifiedSince, std::function<void ()> completionHandler) +{ + auto callbackID = generateCallbackID(); + + m_pendingDeleteWebsiteDataCallbacks.add(callbackID, WTFMove(completionHandler)); + send(Messages::DatabaseProcess::DeleteWebsiteData(sessionID, dataTypes, modifiedSince, callbackID), 0); +} + +void DatabaseProcessProxy::deleteWebsiteDataForOrigins(SessionID sessionID, WebsiteDataTypes dataTypes, const Vector<RefPtr<WebCore::SecurityOrigin>>& origins, std::function<void ()> completionHandler) +{ + ASSERT(canSendMessage()); + + uint64_t callbackID = generateCallbackID(); + m_pendingDeleteWebsiteDataForOriginsCallbacks.add(callbackID, WTFMove(completionHandler)); + + Vector<SecurityOriginData> originData; + for (auto& origin : origins) + originData.append(SecurityOriginData::fromSecurityOrigin(*origin)); + + send(Messages::DatabaseProcess::DeleteWebsiteDataForOrigins(sessionID, dataTypes, originData, callbackID), 0); +} + +void DatabaseProcessProxy::getDatabaseProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetDatabaseProcessConnection::DelayedReply> reply) +{ + m_pendingConnectionReplies.append(reply); + + if (state() == State::Launching) { + m_numPendingConnectionRequests++; + return; + } + + connection()->send(Messages::DatabaseProcess::CreateDatabaseToWebProcessConnection(), 0, IPC::DispatchMessageEvenWhenWaitingForSyncReply); +} + +void DatabaseProcessProxy::didClose(IPC::Connection&) +{ + // The database process must have crashed or exited, so send any pending sync replies we might have. + while (!m_pendingConnectionReplies.isEmpty()) { + auto reply = m_pendingConnectionReplies.takeFirst(); + +#if USE(UNIX_DOMAIN_SOCKETS) + reply->send(IPC::Attachment()); +#elif OS(DARWIN) + reply->send(IPC::Attachment(0, MACH_MSG_TYPE_MOVE_SEND)); +#else + notImplemented(); +#endif + } + + for (const auto& callback : m_pendingFetchWebsiteDataCallbacks.values()) + callback(WebsiteData()); + m_pendingFetchWebsiteDataCallbacks.clear(); + + for (const auto& callback : m_pendingDeleteWebsiteDataCallbacks.values()) + callback(); + m_pendingDeleteWebsiteDataCallbacks.clear(); + + for (const auto& callback : m_pendingDeleteWebsiteDataForOriginsCallbacks.values()) + callback(); + m_pendingDeleteWebsiteDataForOriginsCallbacks.clear(); + + // Tell ProcessPool to forget about this database process. This may cause us to be deleted. + m_processPool->databaseProcessCrashed(this); +} + +void DatabaseProcessProxy::didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference messageReceiverName, IPC::StringReference messageName) +{ +} + +void DatabaseProcessProxy::didCreateDatabaseToWebProcessConnection(const IPC::Attachment& connectionIdentifier) +{ + ASSERT(!m_pendingConnectionReplies.isEmpty()); + + RefPtr<Messages::WebProcessProxy::GetDatabaseProcessConnection::DelayedReply> reply = m_pendingConnectionReplies.takeFirst(); + +#if USE(UNIX_DOMAIN_SOCKETS) + reply->send(connectionIdentifier); +#elif OS(DARWIN) + reply->send(IPC::Attachment(connectionIdentifier.port(), MACH_MSG_TYPE_MOVE_SEND)); +#else + notImplemented(); +#endif +} + +void DatabaseProcessProxy::didFetchWebsiteData(uint64_t callbackID, const WebsiteData& websiteData) +{ + auto callback = m_pendingFetchWebsiteDataCallbacks.take(callbackID); + callback(websiteData); +} + +void DatabaseProcessProxy::didDeleteWebsiteData(uint64_t callbackID) +{ + auto callback = m_pendingDeleteWebsiteDataCallbacks.take(callbackID); + callback(); +} + +void DatabaseProcessProxy::didDeleteWebsiteDataForOrigins(uint64_t callbackID) +{ + auto callback = m_pendingDeleteWebsiteDataForOriginsCallbacks.take(callbackID); + callback(); +} + +void DatabaseProcessProxy::didFinishLaunching(ProcessLauncher* launcher, IPC::Connection::Identifier connectionIdentifier) +{ + ChildProcessProxy::didFinishLaunching(launcher, connectionIdentifier); + + if (IPC::Connection::identifierIsNull(connectionIdentifier)) { + // FIXME: Do better cleanup here. + return; + } + + for (unsigned i = 0; i < m_numPendingConnectionRequests; ++i) + connection()->send(Messages::DatabaseProcess::CreateDatabaseToWebProcessConnection(), 0); + + m_numPendingConnectionRequests = 0; +} + +} // namespace WebKit + +#endif // ENABLE(DATABASE_PROCESS) diff --git a/Source/WebKit2/UIProcess/Databases/DatabaseProcessProxy.h b/Source/WebKit2/UIProcess/Databases/DatabaseProcessProxy.h new file mode 100644 index 000000000..c37f3a263 --- /dev/null +++ b/Source/WebKit2/UIProcess/Databases/DatabaseProcessProxy.h @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2013 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef DatabaseProcessProxy_h +#define DatabaseProcessProxy_h + +#if ENABLE(DATABASE_PROCESS) + +#include "ChildProcessProxy.h" +#include "ProcessLauncher.h" +#include "WebProcessProxyMessages.h" +#include "WebsiteDataTypes.h" +#include <wtf/Deque.h> + +namespace WebCore { +class SecurityOrigin; +class SessionID; +} + +namespace WebKit { + +class WebProcessPool; + +class DatabaseProcessProxy : public ChildProcessProxy { +public: + static Ref<DatabaseProcessProxy> create(WebProcessPool*); + ~DatabaseProcessProxy(); + + void fetchWebsiteData(WebCore::SessionID, WebsiteDataTypes, std::function<void (WebsiteData)> completionHandler); + void deleteWebsiteData(WebCore::SessionID, WebsiteDataTypes, std::chrono::system_clock::time_point modifiedSince, std::function<void ()> completionHandler); + void deleteWebsiteDataForOrigins(WebCore::SessionID, WebsiteDataTypes, const Vector<RefPtr<WebCore::SecurityOrigin>>& origins, std::function<void ()> completionHandler); + + void getDatabaseProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetDatabaseProcessConnection::DelayedReply>); + +private: + DatabaseProcessProxy(WebProcessPool*); + + // ChildProcessProxy + virtual void getLaunchOptions(ProcessLauncher::LaunchOptions&) override; + virtual void processWillShutDown(IPC::Connection&) override; + + // IPC::Connection::Client + virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override; + virtual void didClose(IPC::Connection&) override; + virtual void didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override; + virtual IPC::ProcessType localProcessType() override { return IPC::ProcessType::UI; } + virtual IPC::ProcessType remoteProcessType() override { return IPC::ProcessType::Database; } + + void didReceiveDatabaseProcessProxyMessage(IPC::Connection&, IPC::MessageDecoder&); + + // Message handlers + void didCreateDatabaseToWebProcessConnection(const IPC::Attachment&); + void didFetchWebsiteData(uint64_t callbackID, const WebsiteData&); + void didDeleteWebsiteData(uint64_t callbackID); + void didDeleteWebsiteDataForOrigins(uint64_t callbackID); + + // ProcessLauncher::Client + virtual void didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier) override; + + WebProcessPool* m_processPool; + + unsigned m_numPendingConnectionRequests; + Deque<RefPtr<Messages::WebProcessProxy::GetDatabaseProcessConnection::DelayedReply>> m_pendingConnectionReplies; + + HashMap<uint64_t, std::function<void (WebsiteData)>> m_pendingFetchWebsiteDataCallbacks; + HashMap<uint64_t, std::function<void ()>> m_pendingDeleteWebsiteDataCallbacks; + HashMap<uint64_t, std::function<void ()>> m_pendingDeleteWebsiteDataForOriginsCallbacks; +}; + +} // namespace WebKit + +#endif // ENABLE(DATABASE_PROCESS) + +#endif // DatabaseProcessProxy_h diff --git a/Source/WebKit2/UIProcess/WebNetworkInfoManagerProxy.messages.in b/Source/WebKit2/UIProcess/Databases/DatabaseProcessProxy.messages.in index b6acdc26b..1986cd445 100644 --- a/Source/WebKit2/UIProcess/WebNetworkInfoManagerProxy.messages.in +++ b/Source/WebKit2/UIProcess/Databases/DatabaseProcessProxy.messages.in @@ -1,4 +1,4 @@ -# Copyright (C) 2012 Intel Corporation. All rights reserved. +# Copyright (C) 2013 Apple Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -20,14 +20,14 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#if ENABLE(NETWORK_INFO) +#if ENABLE(DATABASE_PROCESS) -messages -> WebNetworkInfoManagerProxy { - StartUpdating(); - StopUpdating(); +messages -> DatabaseProcessProxy LegacyReceiver { + DidCreateDatabaseToWebProcessConnection(IPC::Attachment connectionIdentifier) - GetBandwidth() -> (double bandwidth); - IsMetered() -> (bool metered); + DidFetchWebsiteData(uint64_t callbackID, struct WebKit::WebsiteData websiteData) + DidDeleteWebsiteData(uint64_t callbackID) + DidDeleteWebsiteDataForOrigins(uint64_t callbackID) } -#endif +#endif // ENABLE(DATABASE_PROCESS) diff --git a/Source/WebKit2/UIProcess/Downloads/DownloadProxy.cpp b/Source/WebKit2/UIProcess/Downloads/DownloadProxy.cpp index 01f53bbe8..283adf6c8 100644 --- a/Source/WebKit2/UIProcess/Downloads/DownloadProxy.cpp +++ b/Source/WebKit2/UIProcess/Downloads/DownloadProxy.cpp @@ -27,19 +27,18 @@ #include "DownloadProxy.h" #include "APIData.h" +#include "APIDownloadClient.h" #include "AuthenticationChallengeProxy.h" #include "DataReference.h" #include "DownloadProxyMap.h" -#include "WebContext.h" +#include "NetworkProcessMessages.h" +#include "NetworkProcessProxy.h" #include "WebProcessMessages.h" +#include "WebProcessPool.h" +#include "WebProtectionSpace.h" #include <wtf/text/CString.h> #include <wtf/text/WTFString.h> -#if ENABLE(NETWORK_PROCESS) -#include "NetworkProcessMessages.h" -#include "NetworkProcessProxy.h" -#endif - using namespace WebCore; namespace WebKit { @@ -50,107 +49,135 @@ static uint64_t generateDownloadID() return ++uniqueDownloadID; } -PassRefPtr<DownloadProxy> DownloadProxy::create(DownloadProxyMap& downloadProxyMap, WebContext& webContext) +PassRefPtr<DownloadProxy> DownloadProxy::create(DownloadProxyMap& downloadProxyMap, WebProcessPool& processPool, const ResourceRequest& resourceRequest) { - return adoptRef(new DownloadProxy(downloadProxyMap, webContext)); + return adoptRef(new DownloadProxy(downloadProxyMap, processPool, resourceRequest)); } -DownloadProxy::DownloadProxy(DownloadProxyMap& downloadProxyMap, WebContext& webContext) +DownloadProxy::DownloadProxy(DownloadProxyMap& downloadProxyMap, WebProcessPool& processPool, const ResourceRequest& resourceRequest) : m_downloadProxyMap(downloadProxyMap) - , m_webContext(&webContext) + , m_processPool(&processPool) , m_downloadID(generateDownloadID()) + , m_request(resourceRequest) { } DownloadProxy::~DownloadProxy() { - ASSERT(!m_webContext); + ASSERT(!m_processPool); } void DownloadProxy::cancel() { - if (!m_webContext) + if (!m_processPool) return; -#if ENABLE(NETWORK_PROCESS) - if (m_webContext->usesNetworkProcess()) { - if (NetworkProcessProxy* networkProcess = m_webContext->networkProcess()) - networkProcess->connection()->send(Messages::NetworkProcess::CancelDownload(m_downloadID), 0); - return; - } -#endif - - m_webContext->sendToAllProcesses(Messages::WebProcess::CancelDownload(m_downloadID)); + if (NetworkProcessProxy* networkProcess = m_processPool->networkProcess()) + networkProcess->connection()->send(Messages::NetworkProcess::CancelDownload(m_downloadID), 0); } void DownloadProxy::invalidate() { - ASSERT(m_webContext); - m_webContext = 0; + ASSERT(m_processPool); + m_processPool = nullptr; } void DownloadProxy::processDidClose() { - if (!m_webContext) + if (!m_processPool) return; - m_webContext->downloadClient().processDidCrash(m_webContext.get(), this); + m_processPool->downloadClient().processDidCrash(m_processPool.get(), this); } void DownloadProxy::didStart(const ResourceRequest& request) { m_request = request; - if (!m_webContext) + if (!m_processPool) return; - m_webContext->downloadClient().didStart(m_webContext.get(), this); + m_processPool->downloadClient().didStart(m_processPool.get(), this); } void DownloadProxy::didReceiveAuthenticationChallenge(const AuthenticationChallenge& authenticationChallenge, uint64_t challengeID) { - if (!m_webContext) + if (!m_processPool) return; - RefPtr<AuthenticationChallengeProxy> authenticationChallengeProxy = AuthenticationChallengeProxy::create(authenticationChallenge, challengeID, m_webContext->networkingProcessConnection()); + RefPtr<AuthenticationChallengeProxy> authenticationChallengeProxy = AuthenticationChallengeProxy::create(authenticationChallenge, challengeID, m_processPool->networkingProcessConnection()); - m_webContext->downloadClient().didReceiveAuthenticationChallenge(m_webContext.get(), this, authenticationChallengeProxy.get()); + m_processPool->downloadClient().didReceiveAuthenticationChallenge(m_processPool.get(), this, authenticationChallengeProxy.get()); } +#if USE(NETWORK_SESSION) +void DownloadProxy::canAuthenticateAgainstProtectionSpace(const ProtectionSpace& protectionSpace) +{ + if (!m_processPool) + return; + + auto* networkProcessProxy = m_processPool->networkProcess(); + if (!networkProcessProxy) + return; + + bool result = m_processPool->downloadClient().canAuthenticateAgainstProtectionSpace(getPtr(WebProtectionSpace::create(protectionSpace))); + + networkProcessProxy->connection()->send(Messages::NetworkProcess::ContinueCanAuthenticateAgainstProtectionSpace(m_downloadID, result), 0); +} + +void DownloadProxy::willSendRequest(const ResourceRequest& proposedRequest, const ResourceResponse& redirectResponse) +{ + if (!m_processPool) + return; + + RefPtr<DownloadProxy> protectedThis(this); + m_processPool->downloadClient().willSendRequest(proposedRequest, redirectResponse, [protectedThis](const ResourceRequest& newRequest) { + if (!protectedThis->m_processPool) + return; + + auto* networkProcessProxy = protectedThis->m_processPool->networkProcess(); + if (!networkProcessProxy) + return; + + networkProcessProxy->connection()->send(Messages::NetworkProcess::ContinueWillSendRequest(protectedThis->m_downloadID, newRequest), 0); + }); +} +#endif + void DownloadProxy::didReceiveResponse(const ResourceResponse& response) { - if (!m_webContext) + if (!m_processPool) return; - m_webContext->downloadClient().didReceiveResponse(m_webContext.get(), this, response); + m_processPool->downloadClient().didReceiveResponse(m_processPool.get(), this, response); } void DownloadProxy::didReceiveData(uint64_t length) { - if (!m_webContext) + if (!m_processPool) return; - m_webContext->downloadClient().didReceiveData(m_webContext.get(), this, length); + m_processPool->downloadClient().didReceiveData(m_processPool.get(), this, length); } void DownloadProxy::shouldDecodeSourceDataOfMIMEType(const String& mimeType, bool& result) { result = false; - if (!m_webContext) + if (!m_processPool) return; - result = m_webContext->downloadClient().shouldDecodeSourceDataOfMIMEType(m_webContext.get(), this, mimeType); + result = m_processPool->downloadClient().shouldDecodeSourceDataOfMIMEType(m_processPool.get(), this, mimeType); } void DownloadProxy::decideDestinationWithSuggestedFilename(const String& filename, String& destination, bool& allowOverwrite, SandboxExtension::Handle& sandboxExtensionHandle) { allowOverwrite = false; - if (!m_webContext) + if (!m_processPool) return; - destination = m_webContext->downloadClient().decideDestinationWithSuggestedFilename(m_webContext.get(), this, filename, allowOverwrite); + destination = m_processPool->downloadClient().decideDestinationWithSuggestedFilename(m_processPool.get(), this, filename, allowOverwrite); if (!destination.isNull()) SandboxExtension::createHandle(destination, SandboxExtension::ReadWrite, sandboxExtensionHandle); @@ -158,24 +185,24 @@ void DownloadProxy::decideDestinationWithSuggestedFilename(const String& filenam void DownloadProxy::didCreateDestination(const String& path) { - if (!m_webContext) + if (!m_processPool) return; - m_webContext->downloadClient().didCreateDestination(m_webContext.get(), this, path); + m_processPool->downloadClient().didCreateDestination(m_processPool.get(), this, path); } void DownloadProxy::didFinish() { - if (!m_webContext) + if (!m_processPool) return; - m_webContext->downloadClient().didFinish(m_webContext.get(), this); + m_processPool->downloadClient().didFinish(m_processPool.get(), this); // This can cause the DownloadProxy object to be deleted. m_downloadProxyMap.downloadFinished(this); } -static PassRefPtr<API::Data> createData(const IPC::DataReference& data) +static RefPtr<API::Data> createData(const IPC::DataReference& data) { if (data.isEmpty()) return 0; @@ -185,12 +212,12 @@ static PassRefPtr<API::Data> createData(const IPC::DataReference& data) void DownloadProxy::didFail(const ResourceError& error, const IPC::DataReference& resumeData) { - if (!m_webContext) + if (!m_processPool) return; m_resumeData = createData(resumeData); - m_webContext->downloadClient().didFail(m_webContext.get(), this, error); + m_processPool->downloadClient().didFail(m_processPool.get(), this, error); // This can cause the DownloadProxy object to be deleted. m_downloadProxyMap.downloadFinished(this); @@ -200,7 +227,7 @@ void DownloadProxy::didCancel(const IPC::DataReference& resumeData) { m_resumeData = createData(resumeData); - m_webContext->downloadClient().didCancel(m_webContext.get(), this); + m_processPool->downloadClient().didCancel(m_processPool.get(), this); // This can cause the DownloadProxy object to be deleted. m_downloadProxyMap.downloadFinished(this); diff --git a/Source/WebKit2/UIProcess/Downloads/DownloadProxy.h b/Source/WebKit2/UIProcess/Downloads/DownloadProxy.h index 6f8536146..d795baa01 100644 --- a/Source/WebKit2/UIProcess/Downloads/DownloadProxy.h +++ b/Source/WebKit2/UIProcess/Downloads/DownloadProxy.h @@ -28,6 +28,7 @@ #include "APIObject.h" #include "Connection.h" +#include "DownloadID.h" #include "SandboxExtension.h" #include <WebCore/ResourceRequest.h> #include <wtf/Forward.h> @@ -38,23 +39,24 @@ class Data; } namespace WebCore { - class AuthenticationChallenge; - class ResourceError; - class ResourceResponse; +class AuthenticationChallenge; +class ProtectionSpace; +class ResourceError; +class ResourceResponse; } namespace WebKit { class DownloadProxyMap; -class WebContext; class WebPageProxy; +class WebProcessPool; class DownloadProxy : public API::ObjectImpl<API::Object::Type::Download>, public IPC::MessageReceiver { public: - static PassRefPtr<DownloadProxy> create(DownloadProxyMap&, WebContext&); + static PassRefPtr<DownloadProxy> create(DownloadProxyMap&, WebProcessPool&, const WebCore::ResourceRequest&); ~DownloadProxy(); - uint64_t downloadID() const { return m_downloadID; } + DownloadID downloadID() const { return m_downloadID; } const WebCore::ResourceRequest& request() const { return m_request; } API::Data* resumeData() const { return m_resumeData.get(); } @@ -63,15 +65,15 @@ public: void invalidate(); void processDidClose(); - void didReceiveDownloadProxyMessage(IPC::Connection*, IPC::MessageDecoder&); - void didReceiveSyncDownloadProxyMessage(IPC::Connection*, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&); + void didReceiveDownloadProxyMessage(IPC::Connection&, IPC::MessageDecoder&); + void didReceiveSyncDownloadProxyMessage(IPC::Connection&, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&); private: - explicit DownloadProxy(DownloadProxyMap&, WebContext&); + explicit DownloadProxy(DownloadProxyMap&, WebProcessPool&, const WebCore::ResourceRequest&); // IPC::MessageReceiver - virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; - virtual void didReceiveSyncMessage(IPC::Connection*, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override; + virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override; + virtual void didReceiveSyncMessage(IPC::Connection&, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override; // Message handlers. void didStart(const WebCore::ResourceRequest&); @@ -84,10 +86,14 @@ private: void didFinish(); void didFail(const WebCore::ResourceError&, const IPC::DataReference& resumeData); void didCancel(const IPC::DataReference& resumeData); +#if USE(NETWORK_SESSION) + void canAuthenticateAgainstProtectionSpace(const WebCore::ProtectionSpace&); + void willSendRequest(const WebCore::ResourceRequest& redirectRequest, const WebCore::ResourceResponse& redirectResponse); +#endif DownloadProxyMap& m_downloadProxyMap; - RefPtr<WebContext> m_webContext; - uint64_t m_downloadID; + RefPtr<WebProcessPool> m_processPool; + DownloadID m_downloadID; RefPtr<API::Data> m_resumeData; WebCore::ResourceRequest m_request; diff --git a/Source/WebKit2/UIProcess/Downloads/DownloadProxy.messages.in b/Source/WebKit2/UIProcess/Downloads/DownloadProxy.messages.in index 37ef52fd7..9c8ec2269 100644 --- a/Source/WebKit2/UIProcess/Downloads/DownloadProxy.messages.in +++ b/Source/WebKit2/UIProcess/Downloads/DownloadProxy.messages.in @@ -23,6 +23,10 @@ messages -> DownloadProxy { DidStart(WebCore::ResourceRequest request) DidReceiveAuthenticationChallenge(WebCore::AuthenticationChallenge challenge, uint64_t challengeID) +#if USE(NETWORK_SESSION) + WillSendRequest(WebCore::ResourceRequest redirectRequest, WebCore::ResourceResponse redirectResponse)); + CanAuthenticateAgainstProtectionSpace(WebCore::ProtectionSpace protectionSpace) +#endif DidReceiveResponse(WebCore::ResourceResponse response) DidReceiveData(uint64_t length) diff --git a/Source/WebKit2/UIProcess/Downloads/DownloadProxyMap.cpp b/Source/WebKit2/UIProcess/Downloads/DownloadProxyMap.cpp index e6246b2a3..7509ddedb 100644 --- a/Source/WebKit2/UIProcess/Downloads/DownloadProxyMap.cpp +++ b/Source/WebKit2/UIProcess/Downloads/DownloadProxyMap.cpp @@ -44,38 +44,38 @@ DownloadProxyMap::~DownloadProxyMap() ASSERT(m_downloads.isEmpty()); } -DownloadProxy* DownloadProxyMap::createDownloadProxy(WebContext& webContext) +DownloadProxy* DownloadProxyMap::createDownloadProxy(WebProcessPool& processPool, const WebCore::ResourceRequest& resourceRequest) { - RefPtr<DownloadProxy> downloadProxy = DownloadProxy::create(*this, webContext); + RefPtr<DownloadProxy> downloadProxy = DownloadProxy::create(*this, processPool, resourceRequest); m_downloads.set(downloadProxy->downloadID(), downloadProxy); - m_process->addMessageReceiver(Messages::DownloadProxy::messageReceiverName(), downloadProxy->downloadID(), *downloadProxy); + m_process->addMessageReceiver(Messages::DownloadProxy::messageReceiverName(), downloadProxy->downloadID().downloadID(), *downloadProxy); return downloadProxy.get(); } void DownloadProxyMap::downloadFinished(DownloadProxy* downloadProxy) { - uint64_t downloadID = downloadProxy->downloadID(); + auto downloadID = downloadProxy->downloadID(); ASSERT(m_downloads.contains(downloadID)); + m_process->removeMessageReceiver(Messages::DownloadProxy::messageReceiverName(), downloadID.downloadID()); downloadProxy->invalidate(); m_downloads.remove(downloadID); - - m_process->removeMessageReceiver(Messages::DownloadProxy::messageReceiverName(), downloadID); } void DownloadProxyMap::processDidClose() { // Invalidate all outstanding downloads. - for (HashMap<uint64_t, RefPtr<DownloadProxy>>::iterator::Values it = m_downloads.begin().values(), end = m_downloads.end().values(); it != end; ++it) { - (*it)->processDidClose(); - (*it)->invalidate(); + for (const auto& download : m_downloads.values()) { + download->processDidClose(); + download->invalidate(); + m_process->removeMessageReceiver(Messages::DownloadProxy::messageReceiverName(), download->downloadID().downloadID()); } m_downloads.clear(); - m_process = 0; + m_process = nullptr; } } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/Downloads/DownloadProxyMap.h b/Source/WebKit2/UIProcess/Downloads/DownloadProxyMap.h index 66f5f41d8..d60e5a8e9 100644 --- a/Source/WebKit2/UIProcess/Downloads/DownloadProxyMap.h +++ b/Source/WebKit2/UIProcess/Downloads/DownloadProxyMap.h @@ -26,15 +26,20 @@ #ifndef DownloadProxyMap_h #define DownloadProxyMap_h +#include "DownloadID.h" #include <wtf/HashMap.h> #include <wtf/Noncopyable.h> #include <wtf/PassRefPtr.h> +namespace WebCore { +class ResourceRequest; +} + namespace WebKit { class ChildProcessProxy; class DownloadProxy; -class WebContext; +class WebProcessPool; class DownloadProxyMap { WTF_MAKE_NONCOPYABLE(DownloadProxyMap); @@ -43,7 +48,7 @@ public: explicit DownloadProxyMap(ChildProcessProxy*); ~DownloadProxyMap(); - DownloadProxy* createDownloadProxy(WebContext&); + DownloadProxy* createDownloadProxy(WebProcessPool&, const WebCore::ResourceRequest&); void downloadFinished(DownloadProxy*); bool isEmpty() const { return m_downloads.isEmpty(); } @@ -52,7 +57,7 @@ public: private: ChildProcessProxy* m_process; - HashMap<uint64_t, RefPtr<DownloadProxy>> m_downloads; + HashMap<DownloadID, RefPtr<DownloadProxy>> m_downloads; }; } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/DrawingAreaProxy.cpp b/Source/WebKit2/UIProcess/DrawingAreaProxy.cpp index d15d3e00d..3d5b9e2e1 100644 --- a/Source/WebKit2/UIProcess/DrawingAreaProxy.cpp +++ b/Source/WebKit2/UIProcess/DrawingAreaProxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2010, 2014 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -35,20 +35,20 @@ using namespace WebCore; namespace WebKit { -DrawingAreaProxy::DrawingAreaProxy(DrawingAreaType type, WebPageProxy* webPageProxy) +DrawingAreaProxy::DrawingAreaProxy(DrawingAreaType type, WebPageProxy& webPageProxy) : m_type(type) , m_webPageProxy(webPageProxy) - , m_size(webPageProxy->viewSize()) + , m_size(webPageProxy.viewSize()) #if PLATFORM(MAC) - , m_exposedRectChangedTimer(this, &DrawingAreaProxy::exposedRectChangedTimerFired) + , m_exposedRectChangedTimer(RunLoop::main(), this, &DrawingAreaProxy::exposedRectChangedTimerFired) #endif { - m_webPageProxy->process().addMessageReceiver(Messages::DrawingAreaProxy::messageReceiverName(), webPageProxy->pageID(), *this); + m_webPageProxy.process().addMessageReceiver(Messages::DrawingAreaProxy::messageReceiverName(), m_webPageProxy.pageID(), *this); } DrawingAreaProxy::~DrawingAreaProxy() { - m_webPageProxy->process().removeMessageReceiver(Messages::DrawingAreaProxy::messageReceiverName(), m_webPageProxy->pageID()); + m_webPageProxy.process().removeMessageReceiver(Messages::DrawingAreaProxy::messageReceiverName(), m_webPageProxy.pageID()); } void DrawingAreaProxy::setSize(const IntSize& size, const IntSize& layerPosition, const IntSize& scrollOffset) @@ -65,7 +65,7 @@ void DrawingAreaProxy::setSize(const IntSize& size, const IntSize& layerPosition #if PLATFORM(MAC) void DrawingAreaProxy::setExposedRect(const FloatRect& exposedRect) { - if (!m_webPageProxy->isValid()) + if (!m_webPageProxy.isValid()) return; m_exposedRect = exposedRect; @@ -74,25 +74,17 @@ void DrawingAreaProxy::setExposedRect(const FloatRect& exposedRect) m_exposedRectChangedTimer.startOneShot(0); } -void DrawingAreaProxy::exposedRectChangedTimerFired(Timer<DrawingAreaProxy>*) +void DrawingAreaProxy::exposedRectChangedTimerFired() { - if (!m_webPageProxy->isValid()) + if (!m_webPageProxy.isValid()) return; if (m_exposedRect == m_lastSentExposedRect) return; - m_webPageProxy->process().send(Messages::DrawingArea::SetExposedRect(m_exposedRect), m_webPageProxy->pageID()); + m_webPageProxy.process().send(Messages::DrawingArea::SetExposedRect(m_exposedRect), m_webPageProxy.pageID()); m_lastSentExposedRect = m_exposedRect; } - -void DrawingAreaProxy::setCustomFixedPositionRect(const FloatRect& fixedPositionRect) -{ - if (!m_webPageProxy->isValid()) - return; - - m_webPageProxy->process().send(Messages::DrawingArea::SetCustomFixedPositionRect(fixedPositionRect), m_webPageProxy->pageID()); -} -#endif +#endif // PLATFORM(MAC) } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/DrawingAreaProxy.h b/Source/WebKit2/UIProcess/DrawingAreaProxy.h index 81cf05990..7973df1a1 100644 --- a/Source/WebKit2/UIProcess/DrawingAreaProxy.h +++ b/Source/WebKit2/UIProcess/DrawingAreaProxy.h @@ -28,14 +28,16 @@ #define DrawingAreaProxy_h #include "DrawingAreaInfo.h" +#include "GenericCallback.h" #include "MessageReceiver.h" #include <WebCore/FloatRect.h> #include <WebCore/IntRect.h> #include <WebCore/IntSize.h> -#include <WebCore/Timer.h> #include <chrono> #include <stdint.h> #include <wtf/Noncopyable.h> +#include <wtf/RunLoop.h> +#include <wtf/TypeCasts.h> namespace WebKit { @@ -74,25 +76,41 @@ public: virtual void commitTransientZoom(double, WebCore::FloatPoint) { } #if PLATFORM(MAC) - void setExposedRect(const WebCore::FloatRect&); + virtual void setExposedRect(const WebCore::FloatRect&); WebCore::FloatRect exposedRect() const { return m_exposedRect; } - void exposedRectChangedTimerFired(WebCore::Timer<DrawingAreaProxy>*); - - void setCustomFixedPositionRect(const WebCore::FloatRect&); #endif +#if PLATFORM(COCOA) + void exposedRectChangedTimerFired(); +#endif + + virtual void updateDebugIndicator() { } + + virtual void waitForDidUpdateViewState() { } + + virtual void dispatchAfterEnsuringDrawing(std::function<void (CallbackBase::Error)>) { ASSERT_NOT_REACHED(); } + + // Hide the content until the currently pending update arrives. + virtual void hideContentUntilPendingUpdate() { ASSERT_NOT_REACHED(); } + + // Hide the content until any update arrives. + virtual void hideContentUntilAnyUpdate() { ASSERT_NOT_REACHED(); } + + virtual bool hasVisibleContent() const { return true; } + + virtual void willSendUpdateGeometry() { } protected: - explicit DrawingAreaProxy(DrawingAreaType, WebPageProxy*); + explicit DrawingAreaProxy(DrawingAreaType, WebPageProxy&); DrawingAreaType m_type; - WebPageProxy* m_webPageProxy; + WebPageProxy& m_webPageProxy; WebCore::IntSize m_size; WebCore::IntSize m_layerPosition; WebCore::IntSize m_scrollOffset; // IPC::MessageReceiver - virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; + virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override; private: virtual void sizeDidChange() = 0; @@ -101,21 +119,27 @@ private: // FIXME: These should be pure virtual. virtual void update(uint64_t /* backingStoreStateID */, const UpdateInfo&) { } virtual void didUpdateBackingStoreState(uint64_t /* backingStoreStateID */, const UpdateInfo&, const LayerTreeContext&) { } -#if USE(ACCELERATED_COMPOSITING) virtual void enterAcceleratedCompositingMode(uint64_t /* backingStoreStateID */, const LayerTreeContext&) { } virtual void exitAcceleratedCompositingMode(uint64_t /* backingStoreStateID */, const UpdateInfo&) { } virtual void updateAcceleratedCompositingMode(uint64_t /* backingStoreStateID */, const LayerTreeContext&) { } -#endif -#if PLATFORM(MAC) + virtual void willEnterAcceleratedCompositingMode(uint64_t /* backingStoreStateID */) { } +#if PLATFORM(COCOA) virtual void didUpdateGeometry() { } - virtual void intrinsicContentSizeDidChange(const WebCore::IntSize& newIntrinsicContentSize) { } + virtual void intrinsicContentSizeDidChange(const WebCore::IntSize&) { } - WebCore::Timer<DrawingAreaProxy> m_exposedRectChangedTimer; +#if PLATFORM(MAC) + RunLoop::Timer<DrawingAreaProxy> m_exposedRectChangedTimer; WebCore::FloatRect m_exposedRect; WebCore::FloatRect m_lastSentExposedRect; +#endif // PLATFORM(MAC) #endif }; } // namespace WebKit +#define SPECIALIZE_TYPE_TRAITS_DRAWING_AREA_PROXY(ToValueTypeName, ProxyType) \ +SPECIALIZE_TYPE_TRAITS_BEGIN(WebKit::ToValueTypeName) \ + static bool isType(const WebKit::DrawingAreaProxy& proxy) { return proxy.type() == WebKit::ProxyType; } \ +SPECIALIZE_TYPE_TRAITS_END() + #endif // DrawingAreaProxy_h diff --git a/Source/WebKit2/UIProcess/DrawingAreaProxy.messages.in b/Source/WebKit2/UIProcess/DrawingAreaProxy.messages.in index a272cb59d..8d51cdefd 100644 --- a/Source/WebKit2/UIProcess/DrawingAreaProxy.messages.in +++ b/Source/WebKit2/UIProcess/DrawingAreaProxy.messages.in @@ -23,13 +23,12 @@ messages -> DrawingAreaProxy { Update(uint64_t stateID, WebKit::UpdateInfo updateInfo) DidUpdateBackingStoreState(uint64_t backingStoreStateID, WebKit::UpdateInfo updateInfo, WebKit::LayerTreeContext context) -#if USE(ACCELERATED_COMPOSITING) EnterAcceleratedCompositingMode(uint64_t backingStoreStateID, WebKit::LayerTreeContext context) ExitAcceleratedCompositingMode(uint64_t backingStoreStateID, WebKit::UpdateInfo updateInfo) UpdateAcceleratedCompositingMode(uint64_t backingStoreStateID, WebKit::LayerTreeContext context) -#endif + WillEnterAcceleratedCompositingMode(uint64_t backingStoreStateID) -#if PLATFORM(MAC) +#if PLATFORM(COCOA) // Used by TiledCoreAnimationDrawingAreaProxy. DidUpdateGeometry() IntrinsicContentSizeDidChange(WebCore::IntSize newIntrinsicContentSize) diff --git a/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.cpp b/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.cpp index e8c45a709..6c41a0ee6 100644 --- a/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.cpp +++ b/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.cpp @@ -40,7 +40,7 @@ using namespace WebCore; namespace WebKit { -DrawingAreaProxyImpl::DrawingAreaProxyImpl(WebPageProxy* webPageProxy) +DrawingAreaProxyImpl::DrawingAreaProxyImpl(WebPageProxy& webPageProxy) : DrawingAreaProxy(DrawingAreaTypeImpl, webPageProxy) , m_currentBackingStoreStateID(0) , m_nextBackingStoreStateID(0) @@ -53,11 +53,9 @@ DrawingAreaProxyImpl::DrawingAreaProxyImpl(WebPageProxy* webPageProxy) DrawingAreaProxyImpl::~DrawingAreaProxyImpl() { -#if USE(ACCELERATED_COMPOSITING) // Make sure to exit accelerated compositing mode. if (isInAcceleratedCompositingMode()) exitAcceleratedCompositingMode(); -#endif } void DrawingAreaProxyImpl::paint(BackingStore::PlatformGraphicsContext context, const IntRect& rect, Region& unpaintedRegion) @@ -139,7 +137,7 @@ void DrawingAreaProxyImpl::update(uint64_t backingStoreStateID, const UpdateInfo // FIXME: Handle the case where the view is hidden. incorporateUpdate(updateInfo); - m_webPageProxy->process().send(Messages::DrawingArea::DidUpdate(), m_webPageProxy->pageID()); + m_webPageProxy.process().send(Messages::DrawingArea::DidUpdate(), m_webPageProxy.pageID()); } void DrawingAreaProxyImpl::didUpdateBackingStoreState(uint64_t backingStoreStateID, const UpdateInfo& updateInfo, const LayerTreeContext& layerTreeContext) @@ -151,9 +149,8 @@ void DrawingAreaProxyImpl::didUpdateBackingStoreState(uint64_t backingStoreState m_isWaitingForDidUpdateBackingStoreState = false; // Stop the responsiveness timer that was started in sendUpdateBackingStoreState. - m_webPageProxy->process().responsivenessTimer()->stop(); + m_webPageProxy.process().responsivenessTimer().stop(); -#if USE(ACCELERATED_COMPOSITING) if (layerTreeContext != m_layerTreeContext) { if (!m_layerTreeContext.isEmpty()) { exitAcceleratedCompositingMode(); @@ -165,21 +162,16 @@ void DrawingAreaProxyImpl::didUpdateBackingStoreState(uint64_t backingStoreState ASSERT(layerTreeContext == m_layerTreeContext); } } -#endif if (m_nextBackingStoreStateID != m_currentBackingStoreStateID) sendUpdateBackingStoreState(RespondImmediately); else m_hasReceivedFirstUpdate = true; -#if USE(ACCELERATED_COMPOSITING) if (isInAcceleratedCompositingMode()) { ASSERT(!m_backingStore); return; } -#else - UNUSED_PARAM(layerTreeContext); -#endif // If we have a backing store the right size, reuse it. if (m_backingStore && (m_backingStore->size() != updateInfo.viewSize || m_backingStore->deviceScaleFactor() != updateInfo.deviceScaleFactor)) @@ -193,11 +185,7 @@ void DrawingAreaProxyImpl::enterAcceleratedCompositingMode(uint64_t backingStore if (backingStoreStateID < m_currentBackingStoreStateID) return; -#if USE(ACCELERATED_COMPOSITING) enterAcceleratedCompositingMode(layerTreeContext); -#else - UNUSED_PARAM(layerTreeContext); -#endif } void DrawingAreaProxyImpl::exitAcceleratedCompositingMode(uint64_t backingStoreStateID, const UpdateInfo& updateInfo) @@ -206,9 +194,7 @@ void DrawingAreaProxyImpl::exitAcceleratedCompositingMode(uint64_t backingStoreS if (backingStoreStateID < m_currentBackingStoreStateID) return; -#if USE(ACCELERATED_COMPOSITING) exitAcceleratedCompositingMode(); -#endif incorporateUpdate(updateInfo); } @@ -219,11 +205,16 @@ void DrawingAreaProxyImpl::updateAcceleratedCompositingMode(uint64_t backingStor if (backingStoreStateID < m_currentBackingStoreStateID) return; -#if USE(ACCELERATED_COMPOSITING) updateAcceleratedCompositingMode(layerTreeContext); -#else - UNUSED_PARAM(layerTreeContext); -#endif +} + +void DrawingAreaProxyImpl::willEnterAcceleratedCompositingMode(uint64_t backingStoreStateID) +{ + // WillEnterAcceleratedCompositingMode message is sent when the LayerTreeHost is created in the Web Process. + // This can happen while there's still a DidUpdateBackingStoreState pending, in which case we are receiving + // here the new backingStoreStateID, but m_currentBackingStoreStateID hasn't been updated yet. + ASSERT_ARG(backingStoreStateID, backingStoreStateID <= m_nextBackingStoreStateID); + m_webPageProxy.willEnterAcceleratedCompositingMode(); } void DrawingAreaProxyImpl::incorporateUpdate(const UpdateInfo& updateInfo) @@ -241,17 +232,17 @@ void DrawingAreaProxyImpl::incorporateUpdate(const UpdateInfo& updateInfo) bool shouldScroll = !updateInfo.scrollRect.isEmpty(); if (shouldScroll) - m_webPageProxy->scrollView(updateInfo.scrollRect, updateInfo.scrollOffset); + m_webPageProxy.scrollView(updateInfo.scrollRect, updateInfo.scrollOffset); - if (shouldScroll && !m_webPageProxy->canScrollView()) - m_webPageProxy->setViewNeedsDisplay(IntRect(IntPoint(), m_webPageProxy->viewSize())); + if (shouldScroll && !m_webPageProxy.canScrollView()) + m_webPageProxy.setViewNeedsDisplay(IntRect(IntPoint(), m_webPageProxy.viewSize())); else { for (size_t i = 0; i < updateInfo.updateRects.size(); ++i) - m_webPageProxy->setViewNeedsDisplay(updateInfo.updateRects[i]); + m_webPageProxy.setViewNeedsDisplay(updateInfo.updateRects[i]); } if (shouldScroll) - m_webPageProxy->displayView(); + m_webPageProxy.displayView(); } void DrawingAreaProxyImpl::backingStoreStateDidChange(RespondImmediatelyOrNot respondImmediatelyOrNot) @@ -264,63 +255,81 @@ void DrawingAreaProxyImpl::sendUpdateBackingStoreState(RespondImmediatelyOrNot r { ASSERT(m_currentBackingStoreStateID < m_nextBackingStoreStateID); - if (!m_webPageProxy->isValid()) + if (!m_webPageProxy.isValid()) return; if (m_isWaitingForDidUpdateBackingStoreState) return; - if (m_webPageProxy->viewSize().isEmpty() && !m_webPageProxy->useFixedLayout()) + if (m_webPageProxy.viewSize().isEmpty() && !m_webPageProxy.useFixedLayout()) return; m_isWaitingForDidUpdateBackingStoreState = respondImmediatelyOrNot == RespondImmediately; - m_webPageProxy->process().send(Messages::DrawingArea::UpdateBackingStoreState(m_nextBackingStoreStateID, respondImmediatelyOrNot == RespondImmediately, m_webPageProxy->deviceScaleFactor(), m_size, m_scrollOffset), m_webPageProxy->pageID()); + m_webPageProxy.process().send(Messages::DrawingArea::UpdateBackingStoreState(m_nextBackingStoreStateID, respondImmediatelyOrNot == RespondImmediately, m_webPageProxy.deviceScaleFactor(), m_size, m_scrollOffset), m_webPageProxy.pageID()); m_scrollOffset = IntSize(); if (m_isWaitingForDidUpdateBackingStoreState) { // Start the responsiveness timer. We will stop it when we hear back from the WebProcess // in didUpdateBackingStoreState. - m_webPageProxy->process().responsivenessTimer()->start(); + m_webPageProxy.process().responsivenessTimer().start(); } -#if USE(ACCELERATED_COMPOSITING) if (m_isWaitingForDidUpdateBackingStoreState && !m_layerTreeContext.isEmpty()) { // Wait for the DidUpdateBackingStoreState message. Normally we do this in DrawingAreaProxyImpl::paint, but that // function is never called when in accelerated compositing mode. waitForAndDispatchDidUpdateBackingStoreState(); } -#endif } void DrawingAreaProxyImpl::waitForAndDispatchDidUpdateBackingStoreState() { ASSERT(m_isWaitingForDidUpdateBackingStoreState); - if (!m_webPageProxy->isValid()) + if (!m_webPageProxy.isValid()) return; - if (m_webPageProxy->process().isLaunching()) + if (m_webPageProxy.process().state() == WebProcessProxy::State::Launching) return; -#if USE(ACCELERATED_COMPOSITING) // FIXME: waitForAndDispatchImmediately will always return the oldest DidUpdateBackingStoreState message that // hasn't yet been processed. But it might be better to skip ahead to some other DidUpdateBackingStoreState // message, if multiple DidUpdateBackingStoreState messages are waiting to be processed. For instance, we could // choose the most recent one, or the one that is closest to our current size. // The timeout we use when waiting for a DidUpdateBackingStoreState message when we're asked to paint is 500 milliseconds. - m_webPageProxy->process().connection()->waitForAndDispatchImmediately<Messages::DrawingAreaProxy::DidUpdateBackingStoreState>(m_webPageProxy->pageID(), std::chrono::milliseconds(500)); -#endif + m_webPageProxy.process().connection()->waitForAndDispatchImmediately<Messages::DrawingAreaProxy::DidUpdateBackingStoreState>(m_webPageProxy.pageID(), std::chrono::milliseconds(500)); } -#if USE(ACCELERATED_COMPOSITING) void DrawingAreaProxyImpl::enterAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext) { ASSERT(!isInAcceleratedCompositingMode()); m_backingStore = nullptr; m_layerTreeContext = layerTreeContext; - m_webPageProxy->enterAcceleratedCompositingMode(layerTreeContext); + m_webPageProxy.enterAcceleratedCompositingMode(layerTreeContext); +} + +#if USE(TEXTURE_MAPPER) && PLATFORM(GTK) +void DrawingAreaProxyImpl::setNativeSurfaceHandleForCompositing(uint64_t handle) +{ + m_webPageProxy.process().send(Messages::DrawingArea::SetNativeSurfaceHandleForCompositing(handle), m_webPageProxy.pageID()); +} + +void DrawingAreaProxyImpl::destroyNativeSurfaceHandleForCompositing() +{ + bool handled; + m_webPageProxy.process().sendSync(Messages::DrawingArea::DestroyNativeSurfaceHandleForCompositing(), Messages::DrawingArea::DestroyNativeSurfaceHandleForCompositing::Reply(handled), m_webPageProxy.pageID()); +} +#endif + +void DrawingAreaProxyImpl::dispatchAfterEnsuringDrawing(std::function<void (CallbackBase::Error)> callbackFunction) +{ + if (!m_webPageProxy.isValid()) { + callbackFunction(CallbackBase::Error::OwnerWasInvalidated); + return; + } + + RunLoop::main().dispatch([callbackFunction] { callbackFunction(CallbackBase::Error::None); }); } void DrawingAreaProxyImpl::exitAcceleratedCompositingMode() @@ -328,7 +337,7 @@ void DrawingAreaProxyImpl::exitAcceleratedCompositingMode() ASSERT(isInAcceleratedCompositingMode()); m_layerTreeContext = LayerTreeContext(); - m_webPageProxy->exitAcceleratedCompositingMode(); + m_webPageProxy.exitAcceleratedCompositingMode(); } void DrawingAreaProxyImpl::updateAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext) @@ -336,9 +345,8 @@ void DrawingAreaProxyImpl::updateAcceleratedCompositingMode(const LayerTreeConte ASSERT(isInAcceleratedCompositingMode()); m_layerTreeContext = layerTreeContext; - m_webPageProxy->updateAcceleratedCompositingMode(layerTreeContext); + m_webPageProxy.updateAcceleratedCompositingMode(layerTreeContext); } -#endif void DrawingAreaProxyImpl::discardBackingStoreSoon() { diff --git a/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.h b/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.h index 224ea9109..24da66a65 100644 --- a/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.h +++ b/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.h @@ -29,7 +29,6 @@ #include "BackingStore.h" #include "DrawingAreaProxy.h" #include "LayerTreeContext.h" -#include <wtf/OwnPtr.h> #include <wtf/RunLoop.h> namespace WebCore { @@ -40,31 +39,37 @@ namespace WebKit { class DrawingAreaProxyImpl : public DrawingAreaProxy { public: - explicit DrawingAreaProxyImpl(WebPageProxy*); + explicit DrawingAreaProxyImpl(WebPageProxy&); virtual ~DrawingAreaProxyImpl(); void paint(BackingStore::PlatformGraphicsContext, const WebCore::IntRect&, WebCore::Region& unpaintedRegion); -#if USE(ACCELERATED_COMPOSITING) bool isInAcceleratedCompositingMode() const { return !m_layerTreeContext.isEmpty(); } -#endif bool hasReceivedFirstUpdate() const { return m_hasReceivedFirstUpdate; } +#if USE(TEXTURE_MAPPER) && PLATFORM(GTK) + void setNativeSurfaceHandleForCompositing(uint64_t); + void destroyNativeSurfaceHandleForCompositing(); +#endif + + virtual void dispatchAfterEnsuringDrawing(std::function<void (CallbackBase::Error)>) override; + private: // DrawingAreaProxy - virtual void sizeDidChange(); - virtual void deviceScaleFactorDidChange(); + virtual void sizeDidChange() override; + virtual void deviceScaleFactorDidChange() override; - virtual void setBackingStoreIsDiscardable(bool); - virtual void waitForBackingStoreUpdateOnNextPaint(); + virtual void setBackingStoreIsDiscardable(bool) override; + virtual void waitForBackingStoreUpdateOnNextPaint() override; // IPC message handlers - virtual void update(uint64_t backingStoreStateID, const UpdateInfo&); - virtual void didUpdateBackingStoreState(uint64_t backingStoreStateID, const UpdateInfo&, const LayerTreeContext&); - virtual void enterAcceleratedCompositingMode(uint64_t backingStoreStateID, const LayerTreeContext&); - virtual void exitAcceleratedCompositingMode(uint64_t backingStoreStateID, const UpdateInfo&); - virtual void updateAcceleratedCompositingMode(uint64_t backingStoreStateID, const LayerTreeContext&); + virtual void update(uint64_t backingStoreStateID, const UpdateInfo&) override; + virtual void didUpdateBackingStoreState(uint64_t backingStoreStateID, const UpdateInfo&, const LayerTreeContext&) override; + virtual void enterAcceleratedCompositingMode(uint64_t backingStoreStateID, const LayerTreeContext&) override; + virtual void exitAcceleratedCompositingMode(uint64_t backingStoreStateID, const UpdateInfo&) override; + virtual void updateAcceleratedCompositingMode(uint64_t backingStoreStateID, const LayerTreeContext&) override; + virtual void willEnterAcceleratedCompositingMode(uint64_t backingStoreStateID) override; void incorporateUpdate(const UpdateInfo&); @@ -73,13 +78,9 @@ private: void sendUpdateBackingStoreState(RespondImmediatelyOrNot); void waitForAndDispatchDidUpdateBackingStoreState(); -#if USE(ACCELERATED_COMPOSITING) void enterAcceleratedCompositingMode(const LayerTreeContext&); void exitAcceleratedCompositingMode(); void updateAcceleratedCompositingMode(const LayerTreeContext&); -#else - bool isInAcceleratedCompositingMode() const { return false; } -#endif void discardBackingStoreSoon(); void discardBackingStore(); @@ -93,10 +94,8 @@ private: // whenever our state changes in a way that will require a new backing store to be allocated. uint64_t m_nextBackingStoreStateID; -#if USE(ACCELERATED_COMPOSITING) // The current layer tree context. LayerTreeContext m_layerTreeContext; -#endif // Whether we've sent a UpdateBackingStoreState message and are now waiting for a DidUpdateBackingStoreState message. // Used to throttle UpdateBackingStoreState messages so we don't send them faster than the Web process can handle. diff --git a/Source/WebKit2/UIProcess/FindIndicator.cpp b/Source/WebKit2/UIProcess/FindIndicator.cpp deleted file mode 100644 index 2ad193f1b..000000000 --- a/Source/WebKit2/UIProcess/FindIndicator.cpp +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Copyright (C) 2010 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "FindIndicator.h" - -#include "ShareableBitmap.h" -#include <WebCore/Gradient.h> -#include <WebCore/GraphicsContext.h> -#include <WebCore/IntRect.h> -#include <WebCore/Path.h> - -using namespace WebCore; - -static const float cornerRadius = 3.0; - -static const float shadowOffsetX = 0.0; -static const float shadowOffsetY = 1.0; -static const float shadowBlurRadius = 3.0; - -static const int shadowRed = 0; -static const int shadowGreen = 0; -static const int shadowBlue = 0; -static const int shadowAlpha = 204; - -static const float lightBorderThickness = 1.0; -static const float horizontalPaddingInsideLightBorder = 3.0; -static const float verticalPaddingInsideLightBorder = 1.0; - -static const float horizontalBorderInsideShadow = lightBorderThickness + horizontalPaddingInsideLightBorder; -static const float verticalBorderInsideShadow = lightBorderThickness + verticalPaddingInsideLightBorder; - -static const float leftBorderThickness = horizontalBorderInsideShadow + shadowOffsetX + shadowBlurRadius / 2.0; -static const float topBorderThickness = verticalBorderInsideShadow - shadowOffsetY + shadowBlurRadius / 2.0; -static const float rightBorderThickness = horizontalBorderInsideShadow - shadowOffsetX + shadowBlurRadius / 2.0; -static const float bottomBorderThickness = verticalBorderInsideShadow + shadowOffsetY + shadowBlurRadius / 2.0; - -static const float horizontalOutsetToCenterOfLightBorder = horizontalBorderInsideShadow - lightBorderThickness / 2.0; -static const float verticalOutsetToCenterOfLightBorder = verticalBorderInsideShadow - lightBorderThickness / 2.0; - -static const int lightBorderRed = 245; -static const int lightBorderGreen = 230; -static const int lightBorderBlue = 0; -static const int lightBorderAlpha = 255; - -static const int gradientDarkRed = 237; -static const int gradientDarkGreen = 204; -static const int gradientDarkBlue = 0; -static const int gradientDarkAlpha = 255; - -static const int gradientLightRed = 242; -static const int gradientLightGreen = 239; -static const int gradientLightBlue = 0; -static const int gradientLightAlpha = 255; - -namespace WebKit { - -PassRefPtr<FindIndicator> FindIndicator::create(const FloatRect& selectionRectInWindowCoordinates, const Vector<FloatRect>& textRectsInSelectionRectCoordinates, float contentImageScaleFactor, const ShareableBitmap::Handle& contentImageHandle) -{ - RefPtr<ShareableBitmap> contentImage = ShareableBitmap::create(contentImageHandle); - if (!contentImage) - return 0; - ASSERT(contentImageScaleFactor != 1 || contentImage->size() == enclosingIntRect(selectionRectInWindowCoordinates).size()); - - return adoptRef(new FindIndicator(selectionRectInWindowCoordinates, textRectsInSelectionRectCoordinates, contentImageScaleFactor, contentImage.release())); -} - -static bool findIndicatorsForTextRectsOverlap(const Vector<FloatRect>& textRects) -{ - size_t count = textRects.size(); - if (count <= 1) - return false; - - Vector<FloatRect> indicatorRects; - indicatorRects.reserveInitialCapacity(count); - - for (size_t i = 0; i < count; ++i) { - FloatRect indicatorRect = textRects[i]; - indicatorRect.move(-leftBorderThickness, -topBorderThickness); - indicatorRect.expand(leftBorderThickness + rightBorderThickness, topBorderThickness + bottomBorderThickness); - - for (size_t j = indicatorRects.size(); j; ) { - --j; - if (indicatorRect.intersects(indicatorRects[j])) - return true; - } - - indicatorRects.uncheckedAppend(indicatorRect); - } - - return false; -} - -FindIndicator::FindIndicator(const WebCore::FloatRect& selectionRectInWindowCoordinates, const Vector<WebCore::FloatRect>& textRectsInSelectionRectCoordinates, float contentImageScaleFactor, PassRefPtr<ShareableBitmap> contentImage) - : m_selectionRectInWindowCoordinates(selectionRectInWindowCoordinates) - , m_textRectsInSelectionRectCoordinates(textRectsInSelectionRectCoordinates) - , m_contentImageScaleFactor(contentImageScaleFactor) - , m_contentImage(contentImage) -{ - if (findIndicatorsForTextRectsOverlap(m_textRectsInSelectionRectCoordinates)) { - m_textRectsInSelectionRectCoordinates[0] = unionRect(m_textRectsInSelectionRectCoordinates); - m_textRectsInSelectionRectCoordinates.shrink(1); - } -} - -FindIndicator::~FindIndicator() -{ -} - -static FloatRect inflateRect(const FloatRect& rect, float inflateX, float inflateY) -{ - FloatRect inflatedRect = rect; - inflatedRect.inflateX(inflateX); - inflatedRect.inflateY(inflateY); - - return inflatedRect; -} - -FloatRect FindIndicator::frameRect() const -{ - return FloatRect(m_selectionRectInWindowCoordinates.x() - leftBorderThickness, m_selectionRectInWindowCoordinates.y() - topBorderThickness, - m_selectionRectInWindowCoordinates.width() + rightBorderThickness + leftBorderThickness, - m_selectionRectInWindowCoordinates.height() + topBorderThickness + bottomBorderThickness); -} - -static Color lightBorderColor() -{ - return Color(lightBorderRed, lightBorderGreen, lightBorderBlue, lightBorderAlpha); -} - -static Color shadowColor() -{ - return Color(shadowRed, shadowGreen, shadowBlue, shadowAlpha); -} - -static Color gradientLightColor() -{ - return Color(gradientLightRed, gradientLightGreen, gradientLightBlue, gradientLightAlpha); -} - -static Color gradientDarkColor() -{ - return Color(gradientDarkRed, gradientDarkGreen, gradientDarkBlue, gradientDarkAlpha); -} - -static Path pathWithRoundedRect(const FloatRect& pathRect, float radius) -{ - Path path; - path.addRoundedRect(pathRect, FloatSize(radius, radius)); - - return path; -} - -void FindIndicator::draw(GraphicsContext& graphicsContext, const IntRect& /*dirtyRect*/) -{ - for (size_t i = 0; i < m_textRectsInSelectionRectCoordinates.size(); ++i) { - FloatRect textRect = m_textRectsInSelectionRectCoordinates[i]; - textRect.move(leftBorderThickness, topBorderThickness); - - FloatRect outerPathRect = inflateRect(textRect, horizontalOutsetToCenterOfLightBorder, verticalOutsetToCenterOfLightBorder); - FloatRect innerPathRect = inflateRect(textRect, horizontalPaddingInsideLightBorder, verticalPaddingInsideLightBorder); - - { - GraphicsContextStateSaver stateSaver(graphicsContext); - graphicsContext.setShadow(FloatSize(shadowOffsetX, shadowOffsetY), shadowBlurRadius, shadowColor(), ColorSpaceSRGB); - graphicsContext.setFillColor(lightBorderColor(), ColorSpaceDeviceRGB); - graphicsContext.fillPath(pathWithRoundedRect(outerPathRect, cornerRadius)); - } - - { - GraphicsContextStateSaver stateSaver(graphicsContext); - graphicsContext.clip(pathWithRoundedRect(innerPathRect, cornerRadius)); - RefPtr<Gradient> gradient = Gradient::create(FloatPoint(innerPathRect.x(), innerPathRect.y()), FloatPoint(innerPathRect.x(), innerPathRect.maxY())); - gradient->addColorStop(0, gradientLightColor()); - gradient->addColorStop(1, gradientDarkColor()); - graphicsContext.setFillGradient(gradient); - graphicsContext.fillRect(outerPathRect); - } - - { - GraphicsContextStateSaver stateSaver(graphicsContext); - graphicsContext.translate(FloatSize(roundf(leftBorderThickness), roundf(topBorderThickness))); - - IntRect contentImageRect = enclosingIntRect(m_textRectsInSelectionRectCoordinates[i]); - m_contentImage->paint(graphicsContext, m_contentImageScaleFactor, contentImageRect.location(), contentImageRect); - } - } -} - -} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/FrameLoadState.h b/Source/WebKit2/UIProcess/FrameLoadState.h index 547811e9b..2d359b8d1 100644 --- a/Source/WebKit2/UIProcess/FrameLoadState.h +++ b/Source/WebKit2/UIProcess/FrameLoadState.h @@ -51,10 +51,14 @@ public: void didSameDocumentNotification(const String&); + State state() const { return m_state; } + const String& url() const { return m_url; } + const String& provisionalURL() const { return m_provisionalURL; } + void setUnreachableURL(const String&); + const String& unreachableURL() const { return m_unreachableURL; } - // FIXME: These should all be private, and FrameLoadState should - // provide state transition member functions. +private: State m_state; String m_url; String m_provisionalURL; diff --git a/Source/WebKit2/UIProcess/GenericCallback.h b/Source/WebKit2/UIProcess/GenericCallback.h index 907e61589..84ce3de04 100644 --- a/Source/WebKit2/UIProcess/GenericCallback.h +++ b/Source/WebKit2/UIProcess/GenericCallback.h @@ -27,231 +27,195 @@ #define GenericCallback_h #include "APIError.h" +#include "APISerializedScriptValue.h" +#include "ProcessThrottler.h" #include "ShareableBitmap.h" #include "WKAPICast.h" +#include <functional> #include <wtf/HashMap.h> #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> +#include <wtf/RunLoop.h> namespace WebKit { class CallbackBase : public RefCounted<CallbackBase> { public: + enum class Error { + None, + Unknown, + ProcessExited, + OwnerWasInvalidated, + }; + virtual ~CallbackBase() { } uint64_t callbackID() const { return m_callbackID; } + template<class T> + T* as() + { + if (T::type() == m_type) + return static_cast<T*>(this); + + return nullptr; + } + + virtual void invalidate(Error) = 0; + protected: - explicit CallbackBase(void* context) - : m_context(context) + struct TypeTag { }; + typedef const TypeTag* Type; + + explicit CallbackBase(Type type, const ProcessThrottler::BackgroundActivityToken& activityToken) + : m_type(type) , m_callbackID(generateCallbackID()) + , m_activityToken(activityToken) { } - void* context() const { return m_context; } - private: static uint64_t generateCallbackID() { + ASSERT(RunLoop::isMain()); static uint64_t uniqueCallbackID = 1; return uniqueCallbackID++; } - void* m_context; + Type m_type; uint64_t m_callbackID; + ProcessThrottler::BackgroundActivityToken m_activityToken; }; -class VoidCallback : public CallbackBase { +template<typename... T> +class GenericCallback : public CallbackBase { public: - typedef void (*CallbackFunction)(WKErrorRef, void*); + typedef std::function<void (T..., Error)> CallbackFunction; - static PassRefPtr<VoidCallback> create(void* context, CallbackFunction callback) + static PassRefPtr<GenericCallback> create(CallbackFunction callback, const ProcessThrottler::BackgroundActivityToken& activityToken = nullptr) { - return adoptRef(new VoidCallback(context, callback)); + return adoptRef(new GenericCallback(callback, activityToken)); } - virtual ~VoidCallback() + virtual ~GenericCallback() { ASSERT(!m_callback); } - void performCallback() + void performCallbackWithReturnValue(T... returnValue) { if (!m_callback) return; - m_callback(0, context()); + m_callback(returnValue..., Error::None); - m_callback = 0; - } - - void invalidate() - { - if (!m_callback) - return; - - RefPtr<API::Error> error = API::Error::create(); - m_callback(toAPI(error.get()), context()); - - m_callback = 0; - } - -private: - VoidCallback(void* context, CallbackFunction callback) - : CallbackBase(context) - , m_callback(callback) - { + m_callback = nullptr; } - CallbackFunction m_callback; -}; - -template<typename APIReturnValueType, typename InternalReturnValueType = typename APITypeInfo<APIReturnValueType>::ImplType> -class GenericCallback : public CallbackBase { -public: - typedef void (*CallbackFunction)(APIReturnValueType, WKErrorRef, void*); - - static PassRefPtr<GenericCallback> create(void* context, CallbackFunction callback) - { - return adoptRef(new GenericCallback(context, callback)); - } - - virtual ~GenericCallback() + void performCallback() { - ASSERT(!m_callback); + performCallbackWithReturnValue(); } - void performCallbackWithReturnValue(InternalReturnValueType returnValue) + virtual void invalidate(Error error = Error::Unknown) override final { - ASSERT(m_callback); - - m_callback(toAPI(returnValue), 0, context()); + if (!m_callback) + return; - m_callback = 0; - } - - void invalidate() - { - ASSERT(m_callback); + m_callback(typename std::remove_reference<T>::type()..., error); - RefPtr<API::Error> error = API::Error::create(); - m_callback(0, toAPI(error.get()), context()); - - m_callback = 0; + m_callback = nullptr; } private: - GenericCallback(void* context, CallbackFunction callback) - : CallbackBase(context) + GenericCallback(CallbackFunction callback, const ProcessThrottler::BackgroundActivityToken& activityToken) + : CallbackBase(type(), activityToken) , m_callback(callback) { } - CallbackFunction m_callback; -}; - -// FIXME: Make a version of CallbackBase with two arguments, and define ComputedPagesCallback as a specialization. -class ComputedPagesCallback : public CallbackBase { -public: - typedef void (*CallbackFunction)(const Vector<WebCore::IntRect>&, double, WKErrorRef, void*); - - static PassRefPtr<ComputedPagesCallback> create(void* context, CallbackFunction callback) - { - return adoptRef(new ComputedPagesCallback(context, callback)); - } - - virtual ~ComputedPagesCallback() + friend class CallbackBase; + static Type type() { - ASSERT(!m_callback); + static TypeTag tag; + return &tag; } - void performCallbackWithReturnValue(const Vector<WebCore::IntRect>& returnValue1, double returnValue2) - { - ASSERT(m_callback); + CallbackFunction m_callback; +}; - m_callback(returnValue1, returnValue2, 0, context()); +template<typename APIReturnValueType, typename InternalReturnValueType = typename APITypeInfo<APIReturnValueType>::ImplType*> +static typename GenericCallback<InternalReturnValueType>::CallbackFunction toGenericCallbackFunction(void* context, void (*callback)(APIReturnValueType, WKErrorRef, void*)) +{ + return [context, callback](InternalReturnValueType returnValue, CallbackBase::Error error) { + callback(toAPI(returnValue), error != CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context); + }; +} - m_callback = 0; - } - - void invalidate() - { - ASSERT(m_callback); +typedef GenericCallback<> VoidCallback; +typedef GenericCallback<const Vector<WebCore::IntRect>&, double> ComputedPagesCallback; +typedef GenericCallback<const ShareableBitmap::Handle&> ImageCallback; - RefPtr<API::Error> error = API::Error::create(); - m_callback(Vector<WebCore::IntRect>(), 0, toAPI(error.get()), context()); - - m_callback = 0; - } +template<typename T> +void invalidateCallbackMap(HashMap<uint64_t, T>& callbackMap, CallbackBase::Error error) +{ + Vector<T> callbacks; + copyValuesToVector(callbackMap, callbacks); + for (auto& callback : callbacks) + callback->invalidate(error); -private: + callbackMap.clear(); +} - ComputedPagesCallback(void* context, CallbackFunction callback) - : CallbackBase(context) - , m_callback(callback) +class CallbackMap { +public: + uint64_t put(PassRefPtr<CallbackBase> callback) { - } + ASSERT(!m_map.contains(callback->callbackID())); - CallbackFunction m_callback; -}; + uint64_t callbackID = callback->callbackID(); + m_map.set(callbackID, callback); + return callbackID; + } -class ImageCallback : public CallbackBase { -public: - typedef void (*CallbackFunction)(const ShareableBitmap::Handle&, WKErrorRef, void*); + template<unsigned I, typename T, typename... U> + struct GenericCallbackType { + typedef typename GenericCallbackType<I - 1, U..., T>::type type; + }; - static PassRefPtr<ImageCallback> create(void* context, CallbackFunction callback) - { - return adoptRef(new ImageCallback(context, callback)); - } + template<typename... U> + struct GenericCallbackType<1, CallbackBase::Error, U...> { + typedef GenericCallback<U...> type; + }; - virtual ~ImageCallback() + template<typename... T> + uint64_t put(std::function<void (T...)> function, const ProcessThrottler::BackgroundActivityToken& activityToken) { - ASSERT(!m_callback); + auto callback = GenericCallbackType<sizeof...(T), T...>::type::create(WTFMove(function), activityToken); + return put(callback); } - void performCallbackWithReturnValue(const ShareableBitmap::Handle& returnValue1) + template<class T> + RefPtr<T> take(uint64_t callbackID) { - ASSERT(m_callback); + RefPtr<CallbackBase> base = m_map.take(callbackID); + if (!base) + return nullptr; - m_callback(returnValue1, 0, context()); - - m_callback = 0; + return adoptRef(base.release().leakRef()->as<T>()); } - void invalidate() + void invalidate(CallbackBase::Error error) { - ASSERT(m_callback); - - RefPtr<API::Error> error = API::Error::create(); - ShareableBitmap::Handle handle; - m_callback(handle, toAPI(error.get()), context()); - - m_callback = 0; + invalidateCallbackMap(m_map, error); } private: - - ImageCallback(void* context, CallbackFunction callback) - : CallbackBase(context) - , m_callback(callback) - { - } - - CallbackFunction m_callback; + HashMap<uint64_t, RefPtr<CallbackBase>> m_map; }; -template<typename T> -void invalidateCallbackMap(HashMap<uint64_t, T>& map) -{ - Vector<T> callbacksVector; - copyValuesToVector(map, callbacksVector); - for (size_t i = 0, size = callbacksVector.size(); i < size; ++i) - callbacksVector[i]->invalidate(); - map.clear(); -} - } // namespace WebKit #endif // GenericCallback_h diff --git a/Source/WebKit2/UIProcess/GeolocationPermissionRequestManagerProxy.cpp b/Source/WebKit2/UIProcess/GeolocationPermissionRequestManagerProxy.cpp index 71047f302..205a0f06c 100644 --- a/Source/WebKit2/UIProcess/GeolocationPermissionRequestManagerProxy.cpp +++ b/Source/WebKit2/UIProcess/GeolocationPermissionRequestManagerProxy.cpp @@ -39,7 +39,7 @@ GeolocationPermissionRequestManagerProxy::GeolocationPermissionRequestManagerPro void GeolocationPermissionRequestManagerProxy::invalidateRequests() { - for (auto request : m_pendingRequests.values()) + for (auto& request : m_pendingRequests.values()) request->invalidate(); m_pendingRequests.clear(); diff --git a/Source/WebKit2/UIProcess/GeolocationPermissionRequestProxy.h b/Source/WebKit2/UIProcess/GeolocationPermissionRequestProxy.h index ef718fe2a..03e72965d 100644 --- a/Source/WebKit2/UIProcess/GeolocationPermissionRequestProxy.h +++ b/Source/WebKit2/UIProcess/GeolocationPermissionRequestProxy.h @@ -35,9 +35,9 @@ class GeolocationPermissionRequestManagerProxy; class GeolocationPermissionRequestProxy : public API::ObjectImpl<API::Object::Type::GeolocationPermissionRequest> { public: - static PassRefPtr<GeolocationPermissionRequestProxy> create(GeolocationPermissionRequestManagerProxy* manager, uint64_t geolocationID) + static Ref<GeolocationPermissionRequestProxy> create(GeolocationPermissionRequestManagerProxy* manager, uint64_t geolocationID) { - return adoptRef(new GeolocationPermissionRequestProxy(manager, geolocationID)); + return adoptRef(*new GeolocationPermissionRequestProxy(manager, geolocationID)); } void allow(); diff --git a/Source/WebKit2/UIProcess/InspectorServer/HTTPRequest.cpp b/Source/WebKit2/UIProcess/InspectorServer/HTTPRequest.cpp index c026d7744..5be2e9d2f 100644 --- a/Source/WebKit2/UIProcess/InspectorServer/HTTPRequest.cpp +++ b/Source/WebKit2/UIProcess/InspectorServer/HTTPRequest.cpp @@ -82,7 +82,7 @@ size_t HTTPRequest::parseHeaders(const char* data, size_t length, String& failur { const char* p = data; const char* end = data + length; - AtomicString name; + String name; String value; for (; p < data + length; p++) { size_t consumedLength = parseHTTPHeader(p, end - p, failureReason, name, value); diff --git a/Source/WebKit2/UIProcess/InspectorServer/HTTPRequest.h b/Source/WebKit2/UIProcess/InspectorServer/HTTPRequest.h index ecda14e99..ffb317ec8 100644 --- a/Source/WebKit2/UIProcess/InspectorServer/HTTPRequest.h +++ b/Source/WebKit2/UIProcess/InspectorServer/HTTPRequest.h @@ -43,8 +43,8 @@ namespace WebKit { class HTTPRequest : public RefCounted<HTTPRequest> { public: - static PassRefPtr<HTTPRequest> create() { return adoptRef(new HTTPRequest()); } - static PassRefPtr<HTTPRequest> create(const String& requestMethod, const WebCore::URL& url, WebCore::HTTPVersion version) { return adoptRef(new HTTPRequest(requestMethod, url, version)); } + static Ref<HTTPRequest> create() { return adoptRef(*new HTTPRequest()); } + static Ref<HTTPRequest> create(const String& requestMethod, const WebCore::URL& url, WebCore::HTTPVersion version) { return adoptRef(*new HTTPRequest(requestMethod, url, version)); } static PassRefPtr<HTTPRequest> parseHTTPRequestFromBuffer(const char* data, size_t length, String& failureReason); virtual ~HTTPRequest(); diff --git a/Source/WebKit2/UIProcess/InspectorServer/WebInspectorServer.cpp b/Source/WebKit2/UIProcess/InspectorServer/WebInspectorServer.cpp index 8f689ac67..663877485 100644 --- a/Source/WebKit2/UIProcess/InspectorServer/WebInspectorServer.cpp +++ b/Source/WebKit2/UIProcess/InspectorServer/WebInspectorServer.cpp @@ -30,6 +30,7 @@ #include "WebInspectorServer.h" +#include "HTTPHeaderNames.h" #include "HTTPRequest.h" #include "WebInspectorProxy.h" #include "WebSocketServerConnection.h" @@ -50,7 +51,7 @@ static unsigned pageIdFromRequestPath(const String& path) return number; } -WebInspectorServer& WebInspectorServer::shared() +WebInspectorServer& WebInspectorServer::singleton() { static WebInspectorServer& server = *new WebInspectorServer; return server; @@ -124,10 +125,10 @@ void WebInspectorServer::didReceiveUnrecognizedHTTPRequest(WebSocketServerConnec bool found = platformResourceForPath(path, body, contentType); HTTPHeaderMap headerFields; - headerFields.set("Connection", "close"); - headerFields.set("Content-Length", String::number(body.size())); + headerFields.set(HTTPHeaderName::Connection, "close"); + headerFields.set(HTTPHeaderName::ContentLength, String::number(body.size())); if (found) - headerFields.set("Content-Type", contentType); + headerFields.set(HTTPHeaderName::ContentType, contentType); // Send when ready and close immediately afterwards. connection->sendHTTPResponseHeader(found ? 200 : 404, found ? "OK" : "Not Found", headerFields); @@ -140,7 +141,7 @@ bool WebInspectorServer::didReceiveWebSocketUpgradeHTTPRequest(WebSocketServerCo String path = request->url(); // NOTE: Keep this in sync with WebCore/inspector/front-end/inspector.js. - DEFINE_STATIC_LOCAL(const String, inspectorWebSocketConnectionPathPrefix, (ASCIILiteral("/devtools/page/"))); + DEPRECATED_DEFINE_STATIC_LOCAL(const String, inspectorWebSocketConnectionPathPrefix, (ASCIILiteral("/devtools/page/"))); // Unknown path requested. if (!path.startsWith(inspectorWebSocketConnectionPathPrefix)) diff --git a/Source/WebKit2/UIProcess/InspectorServer/WebInspectorServer.h b/Source/WebKit2/UIProcess/InspectorServer/WebInspectorServer.h index 19675b2b9..13299b16e 100644 --- a/Source/WebKit2/UIProcess/InspectorServer/WebInspectorServer.h +++ b/Source/WebKit2/UIProcess/InspectorServer/WebInspectorServer.h @@ -41,7 +41,7 @@ class WebInspectorProxy; class WebInspectorServer : public WebSocketServer, public WebSocketServerClient { public: typedef HashMap<unsigned, WebInspectorProxy*> ClientMap; - static WebInspectorServer& shared(); + static WebInspectorServer& singleton(); // Page registry to manage known pages. int registerPage(WebInspectorProxy* client); diff --git a/Source/WebKit2/UIProcess/InspectorServer/WebSocketServer.cpp b/Source/WebKit2/UIProcess/InspectorServer/WebSocketServer.cpp index a78835d38..c534b4fcb 100644 --- a/Source/WebKit2/UIProcess/InspectorServer/WebSocketServer.cpp +++ b/Source/WebKit2/UIProcess/InspectorServer/WebSocketServer.cpp @@ -32,7 +32,6 @@ #include "WebSocketServerConnection.h" #include <WebCore/SocketStreamHandle.h> -#include <wtf/PassOwnPtr.h> using namespace WebCore; @@ -78,20 +77,20 @@ void WebSocketServer::close() m_bindAddress = String(); } -void WebSocketServer::didAcceptConnection(PassOwnPtr<WebSocketServerConnection> connection) +void WebSocketServer::didAcceptConnection(std::unique_ptr<WebSocketServerConnection> connection) { - m_connections.append(connection); + m_connections.append(WTFMove(connection)); } void WebSocketServer::didCloseWebSocketServerConnection(WebSocketServerConnection* connection) { - Deque<OwnPtr<WebSocketServerConnection> >::iterator end = m_connections.end(); - for (Deque<OwnPtr<WebSocketServerConnection> >::iterator it = m_connections.begin(); it != end; ++it) { + for (auto it = m_connections.begin(), end = m_connections.end(); it != end; ++it) { if (it->get() == connection) { m_connections.remove(it); return; } } + ASSERT_NOT_REACHED(); } diff --git a/Source/WebKit2/UIProcess/InspectorServer/WebSocketServer.h b/Source/WebKit2/UIProcess/InspectorServer/WebSocketServer.h index a331dda3f..2e227ef00 100644 --- a/Source/WebKit2/UIProcess/InspectorServer/WebSocketServer.h +++ b/Source/WebKit2/UIProcess/InspectorServer/WebSocketServer.h @@ -29,13 +29,13 @@ #if ENABLE(INSPECTOR_SERVER) +#include <memory> #include <wtf/Deque.h> -#include <wtf/OwnPtr.h> #include <wtf/text/WTFString.h> #if USE(SOUP) #include <gio/gio.h> -#include <wtf/gobject/GRefPtr.h> +#include <wtf/glib/GRefPtr.h> #endif namespace WebCore { @@ -61,7 +61,7 @@ public: void close(); WebSocketServerClient* client() const { return m_client; } - void didAcceptConnection(PassOwnPtr<WebSocketServerConnection>); + void didAcceptConnection(std::unique_ptr<WebSocketServerConnection>); private: void didCloseWebSocketServerConnection(WebSocketServerConnection*); @@ -71,7 +71,7 @@ private: void platformClose(); ServerState m_state; - Deque<OwnPtr<WebSocketServerConnection> > m_connections; + Deque<std::unique_ptr<WebSocketServerConnection>> m_connections; WebSocketServerClient* m_client; String m_bindAddress; unsigned short m_port; diff --git a/Source/WebKit2/UIProcess/InspectorServer/WebSocketServerConnection.cpp b/Source/WebKit2/UIProcess/InspectorServer/WebSocketServerConnection.cpp index a33855546..94a24c90c 100644 --- a/Source/WebKit2/UIProcess/InspectorServer/WebSocketServerConnection.cpp +++ b/Source/WebKit2/UIProcess/InspectorServer/WebSocketServerConnection.cpp @@ -30,6 +30,7 @@ #include "WebSocketServerConnection.h" +#include "HTTPHeaderNames.h" #include "HTTPRequest.h" #include "WebSocketServer.h" #include "WebSocketServerClient.h" @@ -125,7 +126,7 @@ void WebSocketServerConnection::sendRawData(const char* data, size_t length) void WebSocketServerConnection::didCloseSocketStream(SocketStreamHandle*) { // Destroy the SocketStreamHandle now to prevent closing an already closed socket later. - m_socket.clear(); + m_socket = nullptr; // Web Socket Mode. if (m_mode == WebSocket) @@ -177,7 +178,7 @@ void WebSocketServerConnection::readHTTPMessage() // If this is a WebSocket request, perform the WebSocket Handshake. const HTTPHeaderMap& headers = request->headerFields(); - String upgradeHeaderValue = headers.get("Upgrade"); + String upgradeHeaderValue = headers.get(HTTPHeaderName::Upgrade); if (upgradeHeaderValue == "websocket") { upgradeToWebSocketServerConnection(request); return; @@ -206,10 +207,10 @@ void WebSocketServerConnection::upgradeToWebSocketServerConnection(PassRefPtr<HT // Build and send the WebSocket handshake response. const HTTPHeaderMap& requestHeaders = protectedRequest->headerFields(); - String accept = WebSocketHandshake::getExpectedWebSocketAccept(requestHeaders.get("Sec-WebSocket-Key")); + String accept = WebSocketHandshake::getExpectedWebSocketAccept(requestHeaders.get(HTTPHeaderName::SecWebSocketKey)); HTTPHeaderMap responseHeaders; - responseHeaders.add("Upgrade", requestHeaders.get("Upgrade")); - responseHeaders.add("Connection", requestHeaders.get("Connection")); + responseHeaders.add("Upgrade", requestHeaders.get(HTTPHeaderName::Upgrade)); + responseHeaders.add("Connection", requestHeaders.get(HTTPHeaderName::Connection)); responseHeaders.add("Sec-WebSocket-Accept", accept); sendHTTPResponseHeader(101, "WebSocket Protocol Handshake", responseHeaders); diff --git a/Source/WebKit2/UIProcess/InspectorServer/gtk/WebInspectorServerGtk.cpp b/Source/WebKit2/UIProcess/InspectorServer/gtk/WebInspectorServerGtk.cpp index 5011666b3..c5393a47d 100644 --- a/Source/WebKit2/UIProcess/InspectorServer/gtk/WebInspectorServerGtk.cpp +++ b/Source/WebKit2/UIProcess/InspectorServer/gtk/WebInspectorServerGtk.cpp @@ -33,7 +33,7 @@ #include <WebCore/MIMETypeRegistry.h> #include <gio/gio.h> #include <glib.h> -#include <wtf/gobject/GUniquePtr.h> +#include <wtf/glib/GUniquePtr.h> #include <wtf/text/CString.h> #include <wtf/text/StringBuilder.h> #include <wtf/text/StringConcatenate.h> @@ -94,7 +94,7 @@ void WebInspectorServer::buildPageList(Vector<char>& data, String& contentType) builder.appendLiteral("[ "); ClientMap::iterator end = m_clientMap.end(); for (ClientMap::iterator it = m_clientMap.begin(); it != end; ++it) { - WebPageProxy* webPage = it->value->page(); + WebPageProxy* webPage = it->value->inspectedPage(); if (it != m_clientMap.begin()) builder.appendLiteral(", "); builder.appendLiteral("{ \"id\": "); diff --git a/Source/WebKit2/UIProcess/InspectorServer/soup/WebSocketServerSoup.cpp b/Source/WebKit2/UIProcess/InspectorServer/soup/WebSocketServerSoup.cpp index f3ad13ac2..22071a41a 100644 --- a/Source/WebKit2/UIProcess/InspectorServer/soup/WebSocketServerSoup.cpp +++ b/Source/WebKit2/UIProcess/InspectorServer/soup/WebSocketServerSoup.cpp @@ -31,8 +31,7 @@ #include <WebCore/SocketStreamHandle.h> #include <gio/gio.h> #include <glib.h> -#include <wtf/PassOwnPtr.h> -#include <wtf/gobject/GUniquePtr.h> +#include <wtf/glib/GUniquePtr.h> #include <wtf/text/CString.h> using namespace WebCore; @@ -47,9 +46,9 @@ static gboolean connectionCallback(GSocketService* /*service*/, GSocketConnectio LOG(InspectorServer, "New Connection from %s:%d.", addressString.get(), g_inet_socket_address_get_port(G_INET_SOCKET_ADDRESS(socketAddress.get()))); #endif - OwnPtr<WebSocketServerConnection> webSocketConnection = adoptPtr(new WebSocketServerConnection(server->client(), server)); + auto webSocketConnection = std::make_unique<WebSocketServerConnection>(server->client(), server); webSocketConnection->setSocketHandle(SocketStreamHandle::create(connection, webSocketConnection.get())); - server->didAcceptConnection(webSocketConnection.release()); + server->didAcceptConnection(WTFMove(webSocketConnection)); return TRUE; } diff --git a/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.cpp b/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.cpp index f20c19c5a..da2b80e64 100644 --- a/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.cpp +++ b/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.cpp @@ -26,14 +26,15 @@ #include "config.h" #include "ProcessLauncher.h" -#include "WorkQueue.h" #include <wtf/StdLibExtras.h> +#include <wtf/WorkQueue.h> namespace WebKit { -static WorkQueue* processLauncherWorkQueue() +static WorkQueue& processLauncherWorkQueue() { - static WorkQueue* processLauncherWorkQueue = WorkQueue::create("com.apple.WebKit.ProcessLauncher").leakRef(); + + static WorkQueue& processLauncherWorkQueue = WorkQueue::create("com.apple.WebKit.ProcessLauncher").leakRef(); return processLauncherWorkQueue; } @@ -42,26 +43,25 @@ ProcessLauncher::ProcessLauncher(Client* client, const LaunchOptions& launchOpti , m_launchOptions(launchOptions) , m_processIdentifier(0) { - // Launch the process. m_isLaunching = true; - processLauncherWorkQueue()->dispatch(bind(&ProcessLauncher::launchProcess, this)); + + RefPtr<ProcessLauncher> processLauncher(this); + processLauncherWorkQueue().dispatch([processLauncher] { + processLauncher->launchProcess(); + }); } -void ProcessLauncher::didFinishLaunchingProcess(PlatformProcessIdentifier processIdentifier, IPC::Connection::Identifier identifier) +void ProcessLauncher::didFinishLaunchingProcess(pid_t processIdentifier, IPC::Connection::Identifier identifier) { m_processIdentifier = processIdentifier; m_isLaunching = false; if (!m_client) { // FIXME: Make Identifier a move-only object and release port rights/connections in the destructor. -#if PLATFORM(MAC) +#if OS(DARWIN) && !PLATFORM(GTK) + // FIXME: Should really be something like USE(MACH) if (identifier.port) mach_port_mod_refs(mach_task_self(), identifier.port, MACH_PORT_RIGHT_RECEIVE, -1); - - if (identifier.xpcConnection) { - xpc_release(identifier.xpcConnection); - identifier.xpcConnection = 0; - } #endif return; } @@ -75,57 +75,4 @@ void ProcessLauncher::invalidate() platformInvalidate(); } -const char* ProcessLauncher::processTypeAsString(ProcessType processType) -{ - switch (processType) { - case WebProcess: - return "webprocess"; -#if ENABLE(NETSCAPE_PLUGIN_API) - case PluginProcess: - return "pluginprocess"; -#endif -#if ENABLE(NETWORK_PROCESS) - case NetworkProcess: - return "networkprocess"; -#endif -#if ENABLE(DATABASE_PROCESS) - case DatabaseProcess: - return "databaseprocess"; -#endif - } - - ASSERT_NOT_REACHED(); - return 0; -} - -bool ProcessLauncher::getProcessTypeFromString(const char* string, ProcessType& processType) -{ - if (!strcmp(string, "webprocess")) { - processType = WebProcess; - return true; - } - -#if ENABLE(NETSCAPE_PLUGIN_API) - if (!strcmp(string, "pluginprocess")) { - processType = PluginProcess; - return true; - } -#endif - -#if ENABLE(NETWORK_PROCESS) - if (!strcmp(string, "networkprocess")) { - processType = NetworkProcess; - return true; - } -#endif - -#if ENABLE(DATABASE_PROCESS) - if (!strcmp(string, "databaseprocess")) { - processType = DatabaseProcess; - return true; - } -#endif - return false; -} - } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.h b/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.h index 6996bfe64..05e7947b6 100644 --- a/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.h +++ b/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.h @@ -27,7 +27,6 @@ #define WebProcessLauncher_h #include "Connection.h" -#include "PlatformProcessIdentifier.h" #include <wtf/HashMap.h> #include <wtf/RefPtr.h> #include <wtf/Threading.h> @@ -45,54 +44,43 @@ public: virtual void didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier) = 0; }; - enum ProcessType { - WebProcess, + enum class ProcessType { + Web, #if ENABLE(NETSCAPE_PLUGIN_API) - PluginProcess, -#endif -#if ENABLE(NETWORK_PROCESS) - NetworkProcess, + Plugin32, + Plugin64, #endif + Network, #if ENABLE(DATABASE_PROCESS) - DatabaseProcess, + Database, #endif }; struct LaunchOptions { ProcessType processType; HashMap<String, String> extraInitializationData; -#if PLATFORM(MAC) - static const cpu_type_t MatchCurrentArchitecture = 0; - cpu_type_t architecture; - bool executableHeap; - bool useXPC; -#endif -#if PLATFORM(EFL) || PLATFORM(GTK) -#ifndef NDEBUG + +#if (PLATFORM(EFL) || PLATFORM(GTK)) && !defined(NDEBUG) String processCmdPrefix; #endif -#endif }; - static PassRefPtr<ProcessLauncher> create(Client* client, const LaunchOptions& launchOptions) + static Ref<ProcessLauncher> create(Client* client, const LaunchOptions& launchOptions) { - return adoptRef(new ProcessLauncher(client, launchOptions)); + return adoptRef(*new ProcessLauncher(client, launchOptions)); } bool isLaunching() const { return m_isLaunching; } - PlatformProcessIdentifier processIdentifier() const { return m_processIdentifier; } + pid_t processIdentifier() const { return m_processIdentifier; } void terminateProcess(); void invalidate(); - static bool getProcessTypeFromString(const char*, ProcessType&); - static const char* processTypeAsString(ProcessType); - private: ProcessLauncher(Client*, const LaunchOptions& launchOptions); void launchProcess(); - void didFinishLaunchingProcess(PlatformProcessIdentifier, IPC::Connection::Identifier); + void didFinishLaunchingProcess(pid_t, IPC::Connection::Identifier); void platformInvalidate(); @@ -100,7 +88,7 @@ private: const LaunchOptions m_launchOptions; bool m_isLaunching; - PlatformProcessIdentifier m_processIdentifier; + pid_t m_processIdentifier; }; } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp b/Source/WebKit2/UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp index 89d367c77..6cc951025 100644 --- a/Source/WebKit2/UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp +++ b/Source/WebKit2/UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp @@ -38,10 +38,10 @@ #include <glib.h> #include <locale.h> #include <wtf/RunLoop.h> +#include <wtf/glib/GLibUtilities.h> +#include <wtf/glib/GUniquePtr.h> #include <wtf/text/CString.h> #include <wtf/text/WTFString.h> -#include <wtf/gobject/GUniquePtr.h> -#include <wtf/gobject/GlibUtilities.h> using namespace WebCore; @@ -62,18 +62,28 @@ void ProcessLauncher::launchProcess() String executablePath, pluginPath; CString realExecutablePath, realPluginPath; switch (m_launchOptions.processType) { - case WebProcess: + case ProcessLauncher::ProcessType::Web: executablePath = executablePathOfWebProcess(); break; - case PluginProcess: +#if ENABLE(NETSCAPE_PLUGIN_API) + case ProcessLauncher::ProcessType::Plugin64: + case ProcessLauncher::ProcessType::Plugin32: executablePath = executablePathOfPluginProcess(); +#if ENABLE(PLUGIN_PROCESS_GTK2) + if (m_launchOptions.extraInitializationData.contains("requires-gtk2")) + executablePath.append('2'); +#endif pluginPath = m_launchOptions.extraInitializationData.get("plugin-path"); realPluginPath = fileSystemRepresentation(pluginPath); break; -#if ENABLE(NETWORK_PROCESS) - case NetworkProcess: +#endif + case ProcessLauncher::ProcessType::Network: executablePath = executablePathOfNetworkProcess(); break; +#if ENABLE(DATABASE_PROCESS) + case ProcessLauncher::ProcessType::Database: + executablePath = executablePathOfDatabaseProcess(); + break; #endif default: ASSERT_NOT_REACHED(); @@ -122,7 +132,11 @@ void ProcessLauncher::launchProcess() m_processIdentifier = pid; // We've finished launching the process, message back to the main run loop. - RunLoop::main()->dispatch(bind(&ProcessLauncher::didFinishLaunchingProcess, this, m_processIdentifier, socketPair.server)); + RefPtr<ProcessLauncher> protector(this); + IPC::Connection::Identifier serverSocket = socketPair.server; + RunLoop::main().dispatch([protector, pid, serverSocket] { + protector->didFinishLaunchingProcess(pid, serverSocket); + }); } void ProcessLauncher::terminateProcess() diff --git a/Source/WebKit2/UIProcess/LegacySessionStateCoding.h b/Source/WebKit2/UIProcess/LegacySessionStateCoding.h new file mode 100644 index 000000000..2321a2ecd --- /dev/null +++ b/Source/WebKit2/UIProcess/LegacySessionStateCoding.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LegacySessionStateCoding_h +#define LegacySessionStateCoding_h + +#include <wtf/Forward.h> + +namespace API { +class Data; +} + +namespace WebKit { + +struct FrameState; +struct SessionState; + +RefPtr<API::Data> encodeLegacySessionState(const SessionState&); +bool decodeLegacySessionState(const uint8_t* data, size_t, SessionState&); + +} // namespace WebKit + +#endif // LegacySessionStateCoding_h diff --git a/Source/WebKit2/UIProcess/LegacySessionStateCodingNone.cpp b/Source/WebKit2/UIProcess/LegacySessionStateCodingNone.cpp new file mode 100644 index 000000000..4627bc990 --- /dev/null +++ b/Source/WebKit2/UIProcess/LegacySessionStateCodingNone.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "LegacySessionStateCoding.h" + +#include "APIData.h" +#include "ArgumentDecoder.h" +#include "ArgumentEncoder.h" +#include "SessionState.h" +#include "WebCoreArgumentCoders.h" + +namespace WebKit { + +RefPtr<API::Data> encodeLegacySessionState(const SessionState& sessionState) +{ + IPC::ArgumentEncoder encoder; + encoder << sessionState.backForwardListState; + encoder << sessionState.renderTreeSize; + encoder << sessionState.provisionalURL; + return API::Data::create(encoder.buffer(), encoder.bufferSize()); +} + +bool decodeLegacySessionState(const uint8_t* data, size_t dataSize, SessionState& sessionState) +{ + IPC::ArgumentDecoder decoder(data, dataSize); + if (!decoder.decode(sessionState.backForwardListState)) + return false; + if (!decoder.decode(sessionState.renderTreeSize)) + return false; + if (!decoder.decode(sessionState.provisionalURL)) + return false; + return true; +} + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/Network/CustomProtocols/CustomProtocolManagerProxy.h b/Source/WebKit2/UIProcess/Network/CustomProtocols/CustomProtocolManagerProxy.h index 9615a510b..6600a277f 100644 --- a/Source/WebKit2/UIProcess/Network/CustomProtocols/CustomProtocolManagerProxy.h +++ b/Source/WebKit2/UIProcess/Network/CustomProtocols/CustomProtocolManagerProxy.h @@ -26,11 +26,9 @@ #ifndef CustomProtocolManagerProxy_h #define CustomProtocolManagerProxy_h -#if ENABLE(CUSTOM_PROTOCOLS) - #include "MessageReceiver.h" -#if PLATFORM(MAC) +#if PLATFORM(COCOA) #include <wtf/HashMap.h> #include <wtf/RetainPtr.h> OBJC_CLASS WKCustomProtocolLoader; @@ -43,23 +41,24 @@ class ResourceRequest; namespace WebKit { class ChildProcessProxy; -class WebContext; +class WebProcessPool; class CustomProtocolManagerProxy : public IPC::MessageReceiver { public: - explicit CustomProtocolManagerProxy(ChildProcessProxy*, WebContext&); + CustomProtocolManagerProxy(ChildProcessProxy*, WebProcessPool&); + ~CustomProtocolManagerProxy(); void startLoading(uint64_t customProtocolID, const WebCore::ResourceRequest&); void stopLoading(uint64_t customProtocolID); private: // IPC::MessageReceiver - virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; + virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override; ChildProcessProxy* m_childProcessProxy; - WebContext& m_webContext; + WebProcessPool& m_processPool; -#if PLATFORM(MAC) +#if PLATFORM(COCOA) typedef HashMap<uint64_t, RetainPtr<WKCustomProtocolLoader>> LoaderMap; LoaderMap m_loaderMap; #endif @@ -67,6 +66,4 @@ private: } // namespace WebKit -#endif // ENABLE(CUSTOM_PROTOCOLS) - #endif // CustomProtocolManagerProxy_h diff --git a/Source/WebKit2/UIProcess/Network/CustomProtocols/CustomProtocolManagerProxy.messages.in b/Source/WebKit2/UIProcess/Network/CustomProtocols/CustomProtocolManagerProxy.messages.in index 7aef0e0e7..93c0ad435 100644 --- a/Source/WebKit2/UIProcess/Network/CustomProtocols/CustomProtocolManagerProxy.messages.in +++ b/Source/WebKit2/UIProcess/Network/CustomProtocols/CustomProtocolManagerProxy.messages.in @@ -20,11 +20,7 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#if ENABLE(CUSTOM_PROTOCOLS) - messages -> CustomProtocolManagerProxy { StartLoading(uint64_t customProtocolID, WebCore::ResourceRequest request) StopLoading(uint64_t customProtocolID) } - -#endif // ENABLE(CUSTOM_PROTOCOLS) diff --git a/Source/WebKit2/UIProcess/Network/CustomProtocols/soup/CustomProtocolManagerProxySoup.cpp b/Source/WebKit2/UIProcess/Network/CustomProtocols/soup/CustomProtocolManagerProxySoup.cpp index a6b437d04..059f46583 100644 --- a/Source/WebKit2/UIProcess/Network/CustomProtocols/soup/CustomProtocolManagerProxySoup.cpp +++ b/Source/WebKit2/UIProcess/Network/CustomProtocols/soup/CustomProtocolManagerProxySoup.cpp @@ -20,35 +20,36 @@ #include "config.h" #include "CustomProtocolManagerProxy.h" -#if ENABLE(CUSTOM_PROTOCOLS) - #include "ChildProcessProxy.h" #include "CustomProtocolManagerMessages.h" #include "CustomProtocolManagerProxyMessages.h" -#include "WebContext.h" +#include "WebProcessPool.h" #include "WebSoupCustomProtocolRequestManager.h" #include <WebCore/ResourceRequest.h> namespace WebKit { -CustomProtocolManagerProxy::CustomProtocolManagerProxy(ChildProcessProxy* childProcessProxy, WebContext& webContext) +CustomProtocolManagerProxy::CustomProtocolManagerProxy(ChildProcessProxy* childProcessProxy, WebProcessPool& processPool) : m_childProcessProxy(childProcessProxy) - , m_webContext(webContext) + , m_processPool(processPool) { ASSERT(m_childProcessProxy); m_childProcessProxy->addMessageReceiver(Messages::CustomProtocolManagerProxy::messageReceiverName(), *this); } +CustomProtocolManagerProxy::~CustomProtocolManagerProxy() +{ + m_childProcessProxy->removeMessageReceiver(Messages::CustomProtocolManagerProxy::messageReceiverName()); +} + void CustomProtocolManagerProxy::startLoading(uint64_t customProtocolID, const WebCore::ResourceRequest& request) { - m_webContext.supplement<WebSoupCustomProtocolRequestManager>()->startLoading(customProtocolID, request); + m_processPool.supplement<WebSoupCustomProtocolRequestManager>()->startLoading(customProtocolID, request); } void CustomProtocolManagerProxy::stopLoading(uint64_t customProtocolID) { - m_webContext.supplement<WebSoupCustomProtocolRequestManager>()->stopLoading(customProtocolID); + m_processPool.supplement<WebSoupCustomProtocolRequestManager>()->stopLoading(customProtocolID); } } // namespace WebKit - -#endif // ENABLE(CUSTOM_PROTOCOLS) diff --git a/Source/WebKit2/UIProcess/Network/CustomProtocols/soup/WebSoupCustomProtocolRequestManager.cpp b/Source/WebKit2/UIProcess/Network/CustomProtocols/soup/WebSoupCustomProtocolRequestManager.cpp index ad73ad494..b655e4351 100644 --- a/Source/WebKit2/UIProcess/Network/CustomProtocols/soup/WebSoupCustomProtocolRequestManager.cpp +++ b/Source/WebKit2/UIProcess/Network/CustomProtocols/soup/WebSoupCustomProtocolRequestManager.cpp @@ -20,17 +20,17 @@ #include "config.h" #include "WebSoupCustomProtocolRequestManager.h" -#if ENABLE(CUSTOM_PROTOCOLS) - #include "APIData.h" #include "CustomProtocolManagerMessages.h" -#include "WebContext.h" +#include "WebProcessPool.h" #include <WebCore/ResourceError.h> #include <WebCore/ResourceRequest.h> #include <WebCore/ResourceResponse.h> #if PLATFORM(GTK) #include <WebCore/ErrorsGtk.h> +#elif PLATFORM(EFL) +#include <WebCore/ErrorsEfl.h> #endif namespace WebKit { @@ -40,13 +40,13 @@ const char* WebSoupCustomProtocolRequestManager::supplementName() return "WebSoupCustomProtocolRequestManager"; } -PassRefPtr<WebSoupCustomProtocolRequestManager> WebSoupCustomProtocolRequestManager::create(WebContext* context) +Ref<WebSoupCustomProtocolRequestManager> WebSoupCustomProtocolRequestManager::create(WebProcessPool* processPool) { - return adoptRef(new WebSoupCustomProtocolRequestManager(context)); + return adoptRef(*new WebSoupCustomProtocolRequestManager(processPool)); } -WebSoupCustomProtocolRequestManager::WebSoupCustomProtocolRequestManager(WebContext* context) - : WebContextSupplement(context) +WebSoupCustomProtocolRequestManager::WebSoupCustomProtocolRequestManager(WebProcessPool* processPool) + : WebContextSupplement(processPool) { } @@ -60,7 +60,7 @@ void WebSoupCustomProtocolRequestManager::initializeClient(const WKSoupCustomPro } // WebContextSupplement -void WebSoupCustomProtocolRequestManager::contextDestroyed() +void WebSoupCustomProtocolRequestManager::processPoolDestroyed() { } @@ -80,24 +80,27 @@ void WebSoupCustomProtocolRequestManager::derefWebContextSupplement() void WebSoupCustomProtocolRequestManager::registerSchemeForCustomProtocol(const String& scheme) { - if (!context()) + ASSERT(!scheme.isNull()); + if (m_registeredSchemes.contains(scheme)) + return; + + if (!processPool()) return; - context()->registerSchemeForCustomProtocol(scheme); + processPool()->registerSchemeForCustomProtocol(scheme); - ASSERT(!m_registeredSchemes.contains(scheme)); m_registeredSchemes.append(scheme); } void WebSoupCustomProtocolRequestManager::unregisterSchemeForCustomProtocol(const String& scheme) { - if (!context()) + if (!processPool()) return; - context()->unregisterSchemeForCustomProtocol(scheme); + processPool()->unregisterSchemeForCustomProtocol(scheme); - ASSERT(m_registeredSchemes.contains(scheme)); - m_registeredSchemes.remove(m_registeredSchemes.find(scheme)); + bool removed = m_registeredSchemes.removeFirst(scheme); + ASSERT_UNUSED(removed, removed); } void WebSoupCustomProtocolRequestManager::startLoading(uint64_t customProtocolID, const WebCore::ResourceRequest& request) @@ -113,36 +116,34 @@ void WebSoupCustomProtocolRequestManager::stopLoading(uint64_t customProtocolID) void WebSoupCustomProtocolRequestManager::didReceiveResponse(uint64_t customProtocolID, const WebCore::ResourceResponse& response) { - if (!context()) + if (!processPool()) return; - context()->networkingProcessConnection()->send(Messages::CustomProtocolManager::DidReceiveResponse(customProtocolID, response, 0), 0); + processPool()->networkingProcessConnection()->send(Messages::CustomProtocolManager::DidReceiveResponse(customProtocolID, response, 0), 0); } void WebSoupCustomProtocolRequestManager::didLoadData(uint64_t customProtocolID, const API::Data* data) { - if (!context()) + if (!processPool()) return; - context()->networkingProcessConnection()->send(Messages::CustomProtocolManager::DidLoadData(customProtocolID, data->dataReference()), 0); + processPool()->networkingProcessConnection()->send(Messages::CustomProtocolManager::DidLoadData(customProtocolID, data->dataReference()), 0); } void WebSoupCustomProtocolRequestManager::didFailWithError(uint64_t customProtocolID, const WebCore::ResourceError& error) { - if (!context()) + if (!processPool()) return; - context()->networkingProcessConnection()->send(Messages::CustomProtocolManager::DidFailWithError(customProtocolID, error), 0); + processPool()->networkingProcessConnection()->send(Messages::CustomProtocolManager::DidFailWithError(customProtocolID, error), 0); } void WebSoupCustomProtocolRequestManager::didFinishLoading(uint64_t customProtocolID) { - if (!context()) + if (!processPool()) return; - context()->networkingProcessConnection()->send(Messages::CustomProtocolManager::DidFinishLoading(customProtocolID), 0); + processPool()->networkingProcessConnection()->send(Messages::CustomProtocolManager::DidFinishLoading(customProtocolID), 0); } } // namespace WebKit - -#endif // ENABLE(CUSTOM_PROTOCOLS) diff --git a/Source/WebKit2/UIProcess/Network/CustomProtocols/soup/WebSoupCustomProtocolRequestManager.h b/Source/WebKit2/UIProcess/Network/CustomProtocols/soup/WebSoupCustomProtocolRequestManager.h index a140925d1..e14306a38 100644 --- a/Source/WebKit2/UIProcess/Network/CustomProtocols/soup/WebSoupCustomProtocolRequestManager.h +++ b/Source/WebKit2/UIProcess/Network/CustomProtocols/soup/WebSoupCustomProtocolRequestManager.h @@ -20,8 +20,6 @@ #ifndef WebSoupCustomProtocolRequestManager_h #define WebSoupCustomProtocolRequestManager_h -#if ENABLE(CUSTOM_PROTOCOLS) - #include "APIObject.h" #include "WebContextSupplement.h" #include "WebSoupCustomProtocolRequestManagerClient.h" @@ -41,13 +39,13 @@ class ResourceResponse; namespace WebKit { -class WebContext; +class WebProcessPool; class WebSoupCustomProtocolRequestManager : public API::ObjectImpl<API::Object::Type::SoupCustomProtocolRequestManager>, public WebContextSupplement { public: static const char* supplementName(); - static PassRefPtr<WebSoupCustomProtocolRequestManager> create(WebContext*); + static Ref<WebSoupCustomProtocolRequestManager> create(WebProcessPool*); virtual ~WebSoupCustomProtocolRequestManager(); void initializeClient(const WKSoupCustomProtocolRequestManagerClientBase*); @@ -69,10 +67,10 @@ public: using API::Object::deref; private: - WebSoupCustomProtocolRequestManager(WebContext*); + WebSoupCustomProtocolRequestManager(WebProcessPool*); // WebContextSupplement - virtual void contextDestroyed() override; + virtual void processPoolDestroyed() override; virtual void processDidClose(WebProcessProxy*) override; virtual void refWebContextSupplement() override; virtual void derefWebContextSupplement() override; @@ -83,6 +81,4 @@ private: } // namespace WebKit -#endif // ENABLE(CUSTOM_PROTOCOLS) - #endif // WebSoupCustomProtocolRequestManager_h diff --git a/Source/WebKit2/UIProcess/Network/CustomProtocols/soup/WebSoupCustomProtocolRequestManagerClient.cpp b/Source/WebKit2/UIProcess/Network/CustomProtocols/soup/WebSoupCustomProtocolRequestManagerClient.cpp index 80d43c5a3..c4def6287 100644 --- a/Source/WebKit2/UIProcess/Network/CustomProtocols/soup/WebSoupCustomProtocolRequestManagerClient.cpp +++ b/Source/WebKit2/UIProcess/Network/CustomProtocols/soup/WebSoupCustomProtocolRequestManagerClient.cpp @@ -20,7 +20,7 @@ #include "config.h" #include "WebSoupCustomProtocolRequestManagerClient.h" -#if ENABLE(CUSTOM_PROTOCOLS) +#include "WebSoupCustomProtocolRequestManager.h" namespace WebKit { @@ -29,8 +29,8 @@ bool WebSoupCustomProtocolRequestManagerClient::startLoading(WebSoupCustomProtoc if (!m_client.startLoading) return false; - RefPtr<API::URLRequest> urlRequest = API::URLRequest::create(request); - m_client.startLoading(toAPI(soupRequestManager), customProtocolID, toAPI(urlRequest.get()), m_client.base.clientInfo); + Ref<API::URLRequest> urlRequest = API::URLRequest::create(request); + m_client.startLoading(toAPI(soupRequestManager), customProtocolID, toAPI(urlRequest.ptr()), m_client.base.clientInfo); return true; } @@ -41,5 +41,3 @@ void WebSoupCustomProtocolRequestManagerClient::stopLoading(WebSoupCustomProtoco } } // namespace WebKit - -#endif // ENABLE(CUSTOM_PROTOCOLS) diff --git a/Source/WebKit2/UIProcess/Network/CustomProtocols/soup/WebSoupCustomProtocolRequestManagerClient.h b/Source/WebKit2/UIProcess/Network/CustomProtocols/soup/WebSoupCustomProtocolRequestManagerClient.h index e14332141..debb221f6 100644 --- a/Source/WebKit2/UIProcess/Network/CustomProtocols/soup/WebSoupCustomProtocolRequestManagerClient.h +++ b/Source/WebKit2/UIProcess/Network/CustomProtocols/soup/WebSoupCustomProtocolRequestManagerClient.h @@ -20,8 +20,6 @@ #ifndef WebSoupCustomProtocolRequestManagerClient_h #define WebSoupCustomProtocolRequestManagerClient_h -#if ENABLE(CUSTOM_PROTOCOLS) - #include "APIClient.h" #include "WKAPICast.h" #include "WKSoupCustomProtocolRequestManager.h" @@ -49,6 +47,4 @@ public: } // namespace WebKit -#endif // ENABLE(CUSTOM_PROTOCOLS) - #endif // WebSoupCustomProtocolRequestManagerClient_h diff --git a/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.cpp b/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.cpp index e9b4e7964..3fb4855d8 100644 --- a/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.cpp +++ b/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.cpp @@ -26,68 +26,83 @@ #include "config.h" #include "NetworkProcessProxy.h" -#if ENABLE(NETWORK_PROCESS) - #include "AuthenticationChallengeProxy.h" #include "CustomProtocolManagerProxyMessages.h" #include "DownloadProxyMessages.h" #include "NetworkProcessCreationParameters.h" #include "NetworkProcessMessages.h" -#include "WebContext.h" #include "WebProcessMessages.h" +#include "WebProcessPool.h" +#include "WebsiteData.h" #include <wtf/RunLoop.h> #if ENABLE(SEC_ITEM_SHIM) #include "SecItemShimProxy.h" #endif +#if PLATFORM(IOS) +#include <wtf/spi/darwin/XPCSPI.h> +#endif + #define MESSAGE_CHECK(assertion) MESSAGE_CHECK_BASE(assertion, connection()) using namespace WebCore; namespace WebKit { -PassRefPtr<NetworkProcessProxy> NetworkProcessProxy::create(WebContext& webContext) +static uint64_t generateCallbackID() +{ + static uint64_t callbackID; + + return ++callbackID; +} + +Ref<NetworkProcessProxy> NetworkProcessProxy::create(WebProcessPool& processPool) { - return adoptRef(new NetworkProcessProxy(webContext)); + return adoptRef(*new NetworkProcessProxy(processPool)); } -NetworkProcessProxy::NetworkProcessProxy(WebContext& webContext) - : m_webContext(webContext) +NetworkProcessProxy::NetworkProcessProxy(WebProcessPool& processPool) + : m_processPool(processPool) , m_numPendingConnectionRequests(0) -#if ENABLE(CUSTOM_PROTOCOLS) - , m_customProtocolManagerProxy(this, webContext) -#endif + , m_customProtocolManagerProxy(this, processPool) + , m_throttler(*this) { connect(); } NetworkProcessProxy::~NetworkProcessProxy() { + ASSERT(m_pendingFetchWebsiteDataCallbacks.isEmpty()); + ASSERT(m_pendingDeleteWebsiteDataCallbacks.isEmpty()); + ASSERT(m_pendingDeleteWebsiteDataForOriginsCallbacks.isEmpty()); } void NetworkProcessProxy::getLaunchOptions(ProcessLauncher::LaunchOptions& launchOptions) { - launchOptions.processType = ProcessLauncher::NetworkProcess; - platformGetLaunchOptions(launchOptions); + launchOptions.processType = ProcessLauncher::ProcessType::Network; + ChildProcessProxy::getLaunchOptions(launchOptions); } -void NetworkProcessProxy::connectionWillOpen(IPC::Connection* connection) +void NetworkProcessProxy::connectionWillOpen(IPC::Connection& connection) { #if ENABLE(SEC_ITEM_SHIM) - SecItemShimProxy::shared().initializeConnection(connection); + SecItemShimProxy::singleton().initializeConnection(connection); +#else + UNUSED_PARAM(connection); #endif } -void NetworkProcessProxy::connectionWillClose(IPC::Connection*) +void NetworkProcessProxy::processWillShutDown(IPC::Connection& connection) { + ASSERT_UNUSED(connection, this->connection() == &connection); } void NetworkProcessProxy::getNetworkProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply> reply) { m_pendingConnectionReplies.append(reply); - if (isLaunching()) { + if (state() == State::Launching) { m_numPendingConnectionRequests++; return; } @@ -95,12 +110,55 @@ void NetworkProcessProxy::getNetworkProcessConnection(PassRefPtr<Messages::WebPr connection()->send(Messages::NetworkProcess::CreateNetworkConnectionToWebProcess(), 0, IPC::DispatchMessageEvenWhenWaitingForSyncReply); } -DownloadProxy* NetworkProcessProxy::createDownloadProxy() +DownloadProxy* NetworkProcessProxy::createDownloadProxy(const ResourceRequest& resourceRequest) { if (!m_downloadProxyMap) - m_downloadProxyMap = adoptPtr(new DownloadProxyMap(this)); + m_downloadProxyMap = std::make_unique<DownloadProxyMap>(this); - return m_downloadProxyMap->createDownloadProxy(m_webContext); + return m_downloadProxyMap->createDownloadProxy(m_processPool, resourceRequest); +} + +void NetworkProcessProxy::fetchWebsiteData(SessionID sessionID, WebsiteDataTypes dataTypes, std::function<void (WebsiteData)> completionHandler) +{ + ASSERT(canSendMessage()); + + uint64_t callbackID = generateCallbackID(); + auto token = throttler().backgroundActivityToken(); + + m_pendingFetchWebsiteDataCallbacks.add(callbackID, [token, completionHandler](WebsiteData websiteData) { + completionHandler(WTFMove(websiteData)); + }); + + send(Messages::WebProcess::FetchWebsiteData(sessionID, dataTypes, callbackID), 0); +} + +void NetworkProcessProxy::deleteWebsiteData(WebCore::SessionID sessionID, WebsiteDataTypes dataTypes, std::chrono::system_clock::time_point modifiedSince, std::function<void ()> completionHandler) +{ + auto callbackID = generateCallbackID(); + auto token = throttler().backgroundActivityToken(); + + m_pendingDeleteWebsiteDataCallbacks.add(callbackID, [token, completionHandler] { + completionHandler(); + }); + send(Messages::NetworkProcess::DeleteWebsiteData(sessionID, dataTypes, modifiedSince, callbackID), 0); +} + +void NetworkProcessProxy::deleteWebsiteDataForOrigins(SessionID sessionID, WebsiteDataTypes dataTypes, const Vector<RefPtr<WebCore::SecurityOrigin>>& origins, const Vector<String>& cookieHostNames, std::function<void ()> completionHandler) +{ + ASSERT(canSendMessage()); + + uint64_t callbackID = generateCallbackID(); + auto token = throttler().backgroundActivityToken(); + + m_pendingDeleteWebsiteDataForOriginsCallbacks.add(callbackID, [token, completionHandler] { + completionHandler(); + }); + + Vector<SecurityOriginData> originData; + for (auto& origin : origins) + originData.append(SecurityOriginData::fromSecurityOrigin(*origin)); + + send(Messages::NetworkProcess::DeleteWebsiteDataForOrigins(sessionID, dataTypes, originData, cookieHostNames, callbackID), 0); } void NetworkProcessProxy::networkProcessCrashedOrFailedToLaunch() @@ -109,31 +167,43 @@ void NetworkProcessProxy::networkProcessCrashedOrFailedToLaunch() while (!m_pendingConnectionReplies.isEmpty()) { RefPtr<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply> reply = m_pendingConnectionReplies.takeFirst(); -#if PLATFORM(MAC) - reply->send(IPC::Attachment(0, MACH_MSG_TYPE_MOVE_SEND)); -#elif USE(UNIX_DOMAIN_SOCKETS) +#if USE(UNIX_DOMAIN_SOCKETS) reply->send(IPC::Attachment()); +#elif OS(DARWIN) + reply->send(IPC::Attachment(0, MACH_MSG_TYPE_MOVE_SEND)); #else notImplemented(); #endif } + for (const auto& callback : m_pendingFetchWebsiteDataCallbacks.values()) + callback(WebsiteData()); + m_pendingFetchWebsiteDataCallbacks.clear(); + + for (const auto& callback : m_pendingDeleteWebsiteDataCallbacks.values()) + callback(); + m_pendingDeleteWebsiteDataCallbacks.clear(); + + for (const auto& callback : m_pendingDeleteWebsiteDataForOriginsCallbacks.values()) + callback(); + m_pendingDeleteWebsiteDataForOriginsCallbacks.clear(); + // Tell the network process manager to forget about this network process proxy. This may cause us to be deleted. - m_webContext.networkProcessCrashed(this); + m_processPool.networkProcessCrashed(this); } -void NetworkProcessProxy::didReceiveMessage(IPC::Connection* connection, IPC::MessageDecoder& decoder) +void NetworkProcessProxy::didReceiveMessage(IPC::Connection& connection, IPC::MessageDecoder& decoder) { if (dispatchMessage(connection, decoder)) return; - if (m_webContext.dispatchMessage(connection, decoder)) + if (m_processPool.dispatchMessage(connection, decoder)) return; didReceiveNetworkProcessProxyMessage(connection, decoder); } -void NetworkProcessProxy::didReceiveSyncMessage(IPC::Connection* connection, IPC::MessageDecoder& decoder, std::unique_ptr<IPC::MessageEncoder>& replyEncoder) +void NetworkProcessProxy::didReceiveSyncMessage(IPC::Connection& connection, IPC::MessageDecoder& decoder, std::unique_ptr<IPC::MessageEncoder>& replyEncoder) { if (dispatchSyncMessage(connection, decoder, replyEncoder)) return; @@ -141,16 +211,18 @@ void NetworkProcessProxy::didReceiveSyncMessage(IPC::Connection* connection, IPC ASSERT_NOT_REACHED(); } -void NetworkProcessProxy::didClose(IPC::Connection*) +void NetworkProcessProxy::didClose(IPC::Connection&) { if (m_downloadProxyMap) m_downloadProxyMap->processDidClose(); + m_tokenForHoldingLockedFiles = nullptr; + // This may cause us to be deleted. networkProcessCrashedOrFailedToLaunch(); } -void NetworkProcessProxy::didReceiveInvalidMessage(IPC::Connection*, IPC::StringReference, IPC::StringReference) +void NetworkProcessProxy::didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference, IPC::StringReference) { } @@ -161,10 +233,10 @@ void NetworkProcessProxy::didCreateNetworkConnectionToWebProcess(const IPC::Atta // Grab the first pending connection reply. RefPtr<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply> reply = m_pendingConnectionReplies.takeFirst(); -#if PLATFORM(MAC) - reply->send(IPC::Attachment(connectionIdentifier.port(), MACH_MSG_TYPE_MOVE_SEND)); -#elif USE(UNIX_DOMAIN_SOCKETS) +#if USE(UNIX_DOMAIN_SOCKETS) reply->send(connectionIdentifier); +#elif OS(DARWIN) + reply->send(IPC::Attachment(connectionIdentifier.port(), MACH_MSG_TYPE_MOVE_SEND)); #else notImplemented(); #endif @@ -179,6 +251,24 @@ void NetworkProcessProxy::didReceiveAuthenticationChallenge(uint64_t pageID, uin page->didReceiveAuthenticationChallengeProxy(frameID, authenticationChallenge.release()); } +void NetworkProcessProxy::didFetchWebsiteData(uint64_t callbackID, const WebsiteData& websiteData) +{ + auto callback = m_pendingFetchWebsiteDataCallbacks.take(callbackID); + callback(websiteData); +} + +void NetworkProcessProxy::didDeleteWebsiteData(uint64_t callbackID) +{ + auto callback = m_pendingDeleteWebsiteDataCallbacks.take(callbackID); + callback(); +} + +void NetworkProcessProxy::didDeleteWebsiteDataForOrigins(uint64_t callbackID) +{ + auto callback = m_pendingDeleteWebsiteDataForOriginsCallbacks.take(callbackID); + callback(); +} + void NetworkProcessProxy::didFinishLaunching(ProcessLauncher* launcher, IPC::Connection::Identifier connectionIdentifier) { ChildProcessProxy::didFinishLaunching(launcher, connectionIdentifier); @@ -193,12 +283,94 @@ void NetworkProcessProxy::didFinishLaunching(ProcessLauncher* launcher, IPC::Con m_numPendingConnectionRequests = 0; -#if PLATFORM(MAC) - if (m_webContext.processSuppressionEnabled()) +#if PLATFORM(COCOA) + if (m_processPool.processSuppressionEnabled()) setProcessSuppressionEnabled(true); #endif + +#if PLATFORM(IOS) + if (xpc_connection_t connection = this->connection()->xpcConnection()) + m_throttler.didConnectToProcess(xpc_connection_get_pid(connection)); +#endif } -} // namespace WebKit +void NetworkProcessProxy::logSampledDiagnosticMessage(uint64_t pageID, const String& message, const String& description) +{ + WebPageProxy* page = WebProcessProxy::webPage(pageID); + // FIXME: We do this null-check because by the time the decision to log is made, the page may be gone. We should refactor to avoid this, + // but for now we simply drop the message in the rare case this happens. + if (!page) + return; + + page->logSampledDiagnosticMessage(message, description); +} + +void NetworkProcessProxy::logSampledDiagnosticMessageWithResult(uint64_t pageID, const String& message, const String& description, uint32_t result) +{ + WebPageProxy* page = WebProcessProxy::webPage(pageID); + // FIXME: We do this null-check because by the time the decision to log is made, the page may be gone. We should refactor to avoid this, + // but for now we simply drop the message in the rare case this happens. + if (!page) + return; + + page->logSampledDiagnosticMessageWithResult(message, description, result); +} + +void NetworkProcessProxy::logSampledDiagnosticMessageWithValue(uint64_t pageID, const String& message, const String& description, const String& value) +{ + WebPageProxy* page = WebProcessProxy::webPage(pageID); + // FIXME: We do this null-check because by the time the decision to log is made, the page may be gone. We should refactor to avoid this, + // but for now we simply drop the message in the rare case this happens. + if (!page) + return; + + page->logSampledDiagnosticMessageWithValue(message, description, value); +} + +void NetworkProcessProxy::sendProcessWillSuspendImminently() +{ + if (!canSendMessage()) + return; + + bool handled = false; + sendSync(Messages::NetworkProcess::ProcessWillSuspendImminently(), Messages::NetworkProcess::ProcessWillSuspendImminently::Reply(handled), 0, std::chrono::seconds(1)); +} + +void NetworkProcessProxy::sendPrepareToSuspend() +{ + if (canSendMessage()) + send(Messages::NetworkProcess::PrepareToSuspend(), 0); +} + +void NetworkProcessProxy::sendCancelPrepareToSuspend() +{ + if (canSendMessage()) + send(Messages::NetworkProcess::CancelPrepareToSuspend(), 0); +} + +void NetworkProcessProxy::sendProcessDidResume() +{ + if (canSendMessage()) + send(Messages::NetworkProcess::ProcessDidResume(), 0); +} + +void NetworkProcessProxy::processReadyToSuspend() +{ + m_throttler.processReadyToSuspend(); +} -#endif // ENABLE(NETWORK_PROCESS) +void NetworkProcessProxy::didSetAssertionState(AssertionState) +{ +} + +void NetworkProcessProxy::setIsHoldingLockedFiles(bool isHoldingLockedFiles) +{ + if (!isHoldingLockedFiles) { + m_tokenForHoldingLockedFiles = nullptr; + return; + } + if (!m_tokenForHoldingLockedFiles) + m_tokenForHoldingLockedFiles = m_throttler.backgroundActivityToken(); +} + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.h b/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.h index ad13c702c..b2414e141 100644 --- a/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.h +++ b/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.h @@ -26,80 +26,107 @@ #ifndef NetworkProcessProxy_h #define NetworkProcessProxy_h -#if ENABLE(NETWORK_PROCESS) - #include "ChildProcessProxy.h" +#include "CustomProtocolManagerProxy.h" #include "ProcessLauncher.h" +#include "ProcessThrottler.h" +#include "ProcessThrottlerClient.h" #include "WebProcessProxyMessages.h" +#include "WebsiteDataTypes.h" +#include <memory> #include <wtf/Deque.h> -#if ENABLE(CUSTOM_PROTOCOLS) -#include "CustomProtocolManagerProxy.h" -#endif - namespace WebCore { class AuthenticationChallenge; +class ResourceRequest; +class SecurityOrigin; +class SessionID; } namespace WebKit { class DownloadProxy; class DownloadProxyMap; -class WebContext; +class WebProcessPool; struct NetworkProcessCreationParameters; -class NetworkProcessProxy : public ChildProcessProxy { +class NetworkProcessProxy : public ChildProcessProxy, private ProcessThrottlerClient { public: - static PassRefPtr<NetworkProcessProxy> create(WebContext&); + static Ref<NetworkProcessProxy> create(WebProcessPool&); ~NetworkProcessProxy(); void getNetworkProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply>); - DownloadProxy* createDownloadProxy(); + DownloadProxy* createDownloadProxy(const WebCore::ResourceRequest&); + + void fetchWebsiteData(WebCore::SessionID, WebsiteDataTypes, std::function<void (WebsiteData)> completionHandler); + void deleteWebsiteData(WebCore::SessionID, WebsiteDataTypes, std::chrono::system_clock::time_point modifiedSince, std::function<void ()> completionHandler); + void deleteWebsiteDataForOrigins(WebCore::SessionID, WebsiteDataTypes, const Vector<RefPtr<WebCore::SecurityOrigin>>& origins, const Vector<String>& cookieHostNames, std::function<void ()> completionHandler); -#if PLATFORM(MAC) +#if PLATFORM(COCOA) void setProcessSuppressionEnabled(bool); #endif + void processReadyToSuspend(); + + void setIsHoldingLockedFiles(bool); + + ProcessThrottler& throttler() { return m_throttler; } + private: - NetworkProcessProxy(WebContext&); + NetworkProcessProxy(WebProcessPool&); // ChildProcessProxy virtual void getLaunchOptions(ProcessLauncher::LaunchOptions&) override; - virtual void connectionWillOpen(IPC::Connection*) override; - virtual void connectionWillClose(IPC::Connection*) override; + virtual void connectionWillOpen(IPC::Connection&) override; + virtual void processWillShutDown(IPC::Connection&) override; - void platformGetLaunchOptions(ProcessLauncher::LaunchOptions&); void networkProcessCrashedOrFailedToLaunch(); + // ProcessThrottlerClient + void sendProcessWillSuspendImminently() override; + void sendPrepareToSuspend() override; + void sendCancelPrepareToSuspend() override; + void sendProcessDidResume() override; + void didSetAssertionState(AssertionState) override; + // IPC::Connection::Client - virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; - virtual void didReceiveSyncMessage(IPC::Connection*, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override; - virtual void didClose(IPC::Connection*) override; - virtual void didReceiveInvalidMessage(IPC::Connection*, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override; + virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override; + virtual void didReceiveSyncMessage(IPC::Connection&, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override; + virtual void didClose(IPC::Connection&) override; + virtual void didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override; + virtual IPC::ProcessType localProcessType() override { return IPC::ProcessType::UI; } + virtual IPC::ProcessType remoteProcessType() override { return IPC::ProcessType::Network; } // Message handlers - void didReceiveNetworkProcessProxyMessage(IPC::Connection*, IPC::MessageDecoder&); + void didReceiveNetworkProcessProxyMessage(IPC::Connection&, IPC::MessageDecoder&); void didCreateNetworkConnectionToWebProcess(const IPC::Attachment&); void didReceiveAuthenticationChallenge(uint64_t pageID, uint64_t frameID, const WebCore::AuthenticationChallenge&, uint64_t challengeID); + void didFetchWebsiteData(uint64_t callbackID, const WebsiteData&); + void didDeleteWebsiteData(uint64_t callbackID); + void didDeleteWebsiteDataForOrigins(uint64_t callbackID); + void logSampledDiagnosticMessage(uint64_t pageID, const String& message, const String& description); + void logSampledDiagnosticMessageWithResult(uint64_t pageID, const String& message, const String& description, uint32_t result); + void logSampledDiagnosticMessageWithValue(uint64_t pageID, const String& message, const String& description, const String& value); // ProcessLauncher::Client - virtual void didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier); + virtual void didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier) override; - WebContext& m_webContext; + WebProcessPool& m_processPool; unsigned m_numPendingConnectionRequests; Deque<RefPtr<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply>> m_pendingConnectionReplies; - OwnPtr<DownloadProxyMap> m_downloadProxyMap; + HashMap<uint64_t, std::function<void (WebsiteData)>> m_pendingFetchWebsiteDataCallbacks; + HashMap<uint64_t, std::function<void ()>> m_pendingDeleteWebsiteDataCallbacks; + HashMap<uint64_t, std::function<void ()>> m_pendingDeleteWebsiteDataForOriginsCallbacks; -#if ENABLE(CUSTOM_PROTOCOLS) + std::unique_ptr<DownloadProxyMap> m_downloadProxyMap; CustomProtocolManagerProxy m_customProtocolManagerProxy; -#endif + ProcessThrottler m_throttler; + ProcessThrottler::BackgroundActivityToken m_tokenForHoldingLockedFiles; }; } // namespace WebKit -#endif // ENABLE(NETWORK_PROCESS) - #endif // NetworkProcessProxy_h diff --git a/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.messages.in b/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.messages.in index 3b41a540a..dc93b8481 100644 --- a/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.messages.in +++ b/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.messages.in @@ -20,12 +20,20 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#if ENABLE(NETWORK_PROCESS) - messages -> NetworkProcessProxy LegacyReceiver { DidCreateNetworkConnectionToWebProcess(IPC::Attachment connectionIdentifier) DidReceiveAuthenticationChallenge(uint64_t pageID, uint64_t frameID, WebCore::AuthenticationChallenge challenge, uint64_t challengeID) -} -#endif // ENABLE(NETWORK_PROCESS) + DidFetchWebsiteData(uint64_t callbackID, struct WebKit::WebsiteData websiteData) + DidDeleteWebsiteData(uint64_t callbackID) + DidDeleteWebsiteDataForOrigins(uint64_t callbackID) + + ProcessReadyToSuspend() + SetIsHoldingLockedFiles(bool isHoldingLockedFiles) + + # Diagnostic messages logging + LogSampledDiagnosticMessage(uint64_t pageID, String message, String description) + LogSampledDiagnosticMessageWithResult(uint64_t pageID, String message, String description, uint32_t result) + LogSampledDiagnosticMessageWithValue(uint64_t pageID, String message, String description, String value) +} diff --git a/Source/WebKit2/UIProcess/Notifications/NotificationPermissionRequest.cpp b/Source/WebKit2/UIProcess/Notifications/NotificationPermissionRequest.cpp index 25d37da4b..2128627c5 100644 --- a/Source/WebKit2/UIProcess/Notifications/NotificationPermissionRequest.cpp +++ b/Source/WebKit2/UIProcess/Notifications/NotificationPermissionRequest.cpp @@ -30,9 +30,9 @@ namespace WebKit { -PassRefPtr<NotificationPermissionRequest> NotificationPermissionRequest::create(WebKit::NotificationPermissionRequestManagerProxy *manager, uint64_t notificationID) +Ref<NotificationPermissionRequest> NotificationPermissionRequest::create(WebKit::NotificationPermissionRequestManagerProxy *manager, uint64_t notificationID) { - return adoptRef(new NotificationPermissionRequest(manager, notificationID)); + return adoptRef(*new NotificationPermissionRequest(manager, notificationID)); } NotificationPermissionRequest::NotificationPermissionRequest(NotificationPermissionRequestManagerProxy* manager, uint64_t notificationID) diff --git a/Source/WebKit2/UIProcess/Notifications/NotificationPermissionRequest.h b/Source/WebKit2/UIProcess/Notifications/NotificationPermissionRequest.h index fdc5294ec..e04840659 100644 --- a/Source/WebKit2/UIProcess/Notifications/NotificationPermissionRequest.h +++ b/Source/WebKit2/UIProcess/Notifications/NotificationPermissionRequest.h @@ -35,7 +35,7 @@ class NotificationPermissionRequestManagerProxy; class NotificationPermissionRequest : public API::ObjectImpl<API::Object::Type::NotificationPermissionRequest> { public: - static PassRefPtr<NotificationPermissionRequest> create(NotificationPermissionRequestManagerProxy*, uint64_t notificationID); + static Ref<NotificationPermissionRequest> create(NotificationPermissionRequestManagerProxy*, uint64_t notificationID); void allow(); void deny(); diff --git a/Source/WebKit2/UIProcess/Notifications/NotificationPermissionRequestManagerProxy.cpp b/Source/WebKit2/UIProcess/Notifications/NotificationPermissionRequestManagerProxy.cpp index e9b8d8ceb..0b2a63297 100644 --- a/Source/WebKit2/UIProcess/Notifications/NotificationPermissionRequestManagerProxy.cpp +++ b/Source/WebKit2/UIProcess/Notifications/NotificationPermissionRequestManagerProxy.cpp @@ -40,7 +40,7 @@ NotificationPermissionRequestManagerProxy::NotificationPermissionRequestManagerP void NotificationPermissionRequestManagerProxy::invalidateRequests() { - for (auto request : m_pendingRequests.values()) + for (auto& request : m_pendingRequests.values()) request->invalidate(); m_pendingRequests.clear(); diff --git a/Source/WebKit2/UIProcess/Notifications/WebNotification.cpp b/Source/WebKit2/UIProcess/Notifications/WebNotification.cpp index 3705fb064..3d7bc00fe 100644 --- a/Source/WebKit2/UIProcess/Notifications/WebNotification.cpp +++ b/Source/WebKit2/UIProcess/Notifications/WebNotification.cpp @@ -40,7 +40,7 @@ WebNotification::WebNotification(const String& title, const String& body, const , m_tag(tag) , m_lang(lang) , m_dir(dir) - , m_origin(WebSecurityOrigin::createFromString(originString)) + , m_origin(API::SecurityOrigin::createFromString(originString)) , m_notificationID(notificationID) { } diff --git a/Source/WebKit2/UIProcess/Notifications/WebNotification.h b/Source/WebKit2/UIProcess/Notifications/WebNotification.h index 3682b4f9d..5fd3da718 100644 --- a/Source/WebKit2/UIProcess/Notifications/WebNotification.h +++ b/Source/WebKit2/UIProcess/Notifications/WebNotification.h @@ -27,7 +27,7 @@ #define WebNotification_h #include "APIObject.h" -#include "WebSecurityOrigin.h" +#include "APISecurityOrigin.h" #include <wtf/PassRefPtr.h> #include <wtf/RefPtr.h> #include <wtf/text/WTFString.h> @@ -43,9 +43,9 @@ namespace WebKit { class WebNotification : public API::ObjectImpl<API::Object::Type::Notification> { public: - static PassRefPtr<WebNotification> create(const String& title, const String& body, const String& iconURL, const String& tag, const String& lang, const String& dir, const String& originString, uint64_t notificationID) + static Ref<WebNotification> create(const String& title, const String& body, const String& iconURL, const String& tag, const String& lang, const String& dir, const String& originString, uint64_t notificationID) { - return adoptRef(new WebNotification(title, body, iconURL, tag, lang, dir, originString, notificationID)); + return adoptRef(*new WebNotification(title, body, iconURL, tag, lang, dir, originString, notificationID)); } const String& title() const { return m_title; } @@ -54,7 +54,7 @@ public: const String& tag() const { return m_tag; } const String& lang() const { return m_lang; } const String& dir() const { return m_dir; } - WebSecurityOrigin* origin() const { return m_origin.get(); } + API::SecurityOrigin* origin() const { return m_origin.get(); } uint64_t notificationID() const { return m_notificationID; } @@ -67,7 +67,7 @@ private: String m_tag; String m_lang; String m_dir; - RefPtr<WebSecurityOrigin> m_origin; + RefPtr<API::SecurityOrigin> m_origin; uint64_t m_notificationID; }; diff --git a/Source/WebKit2/UIProcess/Notifications/WebNotificationManagerProxy.cpp b/Source/WebKit2/UIProcess/Notifications/WebNotificationManagerProxy.cpp index 39809fd50..626351687 100644 --- a/Source/WebKit2/UIProcess/Notifications/WebNotificationManagerProxy.cpp +++ b/Source/WebKit2/UIProcess/Notifications/WebNotificationManagerProxy.cpp @@ -27,16 +27,14 @@ #include "WebNotificationManagerProxy.h" #include "APIArray.h" -#include "ImmutableDictionary.h" -#include "WebContext.h" +#include "APIDictionary.h" +#include "APISecurityOrigin.h" #include "WebNotification.h" #include "WebNotificationManagerMessages.h" #include "WebPageProxy.h" +#include "WebProcessPool.h" #include "WebProcessProxy.h" -#include "WebSecurityOrigin.h" -using namespace std; -using namespace WTF; using namespace WebCore; namespace WebKit { @@ -52,13 +50,13 @@ const char* WebNotificationManagerProxy::supplementName() return "WebNotificationManagerProxy"; } -PassRefPtr<WebNotificationManagerProxy> WebNotificationManagerProxy::create(WebContext* context) +Ref<WebNotificationManagerProxy> WebNotificationManagerProxy::create(WebProcessPool* processPool) { - return adoptRef(new WebNotificationManagerProxy(context)); + return adoptRef(*new WebNotificationManagerProxy(processPool)); } -WebNotificationManagerProxy::WebNotificationManagerProxy(WebContext* context) - : WebContextSupplement(context) +WebNotificationManagerProxy::WebNotificationManagerProxy(WebProcessPool* processPool) + : WebContextSupplement(processPool) { } @@ -70,7 +68,7 @@ void WebNotificationManagerProxy::initializeProvider(const WKNotificationProvide // WebContextSupplement -void WebNotificationManagerProxy::contextDestroyed() +void WebNotificationManagerProxy::processPoolDestroyed() { m_provider.removeNotificationManager(this); } @@ -87,13 +85,13 @@ void WebNotificationManagerProxy::derefWebContextSupplement() void WebNotificationManagerProxy::populateCopyOfNotificationPermissions(HashMap<String, bool>& permissions) { - RefPtr<ImmutableDictionary> knownPermissions = m_provider.notificationPermissions(); + RefPtr<API::Dictionary> knownPermissions = m_provider.notificationPermissions(); if (!knownPermissions) return; permissions.clear(); - RefPtr<API::Array> knownOrigins = knownPermissions->keys(); + Ref<API::Array> knownOrigins = knownPermissions->keys(); for (size_t i = 0; i < knownOrigins->size(); ++i) { API::String* origin = knownOrigins->at<API::String>(i); permissions.set(origin->string(), knownPermissions->get<API::Boolean>(origin->string())->value()); @@ -217,7 +215,7 @@ void WebNotificationManagerProxy::providerDidCloseNotifications(API::Array* glob if (pageIt == pageNotificationIDs.end()) { Vector<uint64_t> newVector; newVector.reserveInitialCapacity(size); - pageIt = pageNotificationIDs.add(webPage, newVector).iterator; + pageIt = pageNotificationIDs.add(webPage, WTFMove(newVector)).iterator; } uint64_t pageNotificationID = it->value.second; @@ -232,17 +230,17 @@ void WebNotificationManagerProxy::providerDidCloseNotifications(API::Array* glob it->key->process().send(Messages::WebNotificationManager::DidCloseNotifications(it->value), 0); } -void WebNotificationManagerProxy::providerDidUpdateNotificationPolicy(const WebSecurityOrigin* origin, bool allowed) +void WebNotificationManagerProxy::providerDidUpdateNotificationPolicy(const API::SecurityOrigin* origin, bool allowed) { - if (!context()) + if (!processPool()) return; - context()->sendToAllProcesses(Messages::WebNotificationManager::DidUpdateNotificationDecision(origin->toString(), allowed)); + processPool()->sendToAllProcesses(Messages::WebNotificationManager::DidUpdateNotificationDecision(origin->securityOrigin().toString(), allowed)); } void WebNotificationManagerProxy::providerDidRemoveNotificationPolicies(API::Array* origins) { - if (!context()) + if (!processPool()) return; size_t size = origins->size(); @@ -253,9 +251,9 @@ void WebNotificationManagerProxy::providerDidRemoveNotificationPolicies(API::Arr originStrings.reserveInitialCapacity(size); for (size_t i = 0; i < size; ++i) - originStrings.append(origins->at<WebSecurityOrigin>(i)->toString()); + originStrings.append(origins->at<API::SecurityOrigin>(i)->securityOrigin().toString()); - context()->sendToAllProcesses(Messages::WebNotificationManager::DidRemoveNotificationDecisions(originStrings)); + processPool()->sendToAllProcesses(Messages::WebNotificationManager::DidRemoveNotificationDecisions(originStrings)); } } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/Notifications/WebNotificationManagerProxy.h b/Source/WebKit2/UIProcess/Notifications/WebNotificationManagerProxy.h index 591df5b1d..02a2269e5 100644 --- a/Source/WebKit2/UIProcess/Notifications/WebNotificationManagerProxy.h +++ b/Source/WebKit2/UIProcess/Notifications/WebNotificationManagerProxy.h @@ -32,26 +32,25 @@ #include "WebNotificationProvider.h" #include <WebCore/NotificationClient.h> #include <wtf/HashMap.h> -#include <wtf/OwnPtr.h> #include <wtf/PassRefPtr.h> #include <wtf/text/StringHash.h> namespace API { class Array; +class SecurityOrigin; } namespace WebKit { -class WebContext; class WebPageProxy; -class WebSecurityOrigin; +class WebProcessPool; class WebNotificationManagerProxy : public API::ObjectImpl<API::Object::Type::NotificationManager>, public WebContextSupplement { public: static const char* supplementName(); - static PassRefPtr<WebNotificationManagerProxy> create(WebContext*); + static Ref<WebNotificationManagerProxy> create(WebProcessPool*); void initializeProvider(const WKNotificationProviderBase*); void populateCopyOfNotificationPermissions(HashMap<String, bool>&); @@ -65,20 +64,20 @@ public: void providerDidShowNotification(uint64_t notificationID); void providerDidClickNotification(uint64_t notificationID); void providerDidCloseNotifications(API::Array* notificationIDs); - void providerDidUpdateNotificationPolicy(const WebSecurityOrigin*, bool allowed); + void providerDidUpdateNotificationPolicy(const API::SecurityOrigin*, bool allowed); void providerDidRemoveNotificationPolicies(API::Array* origins); using API::Object::ref; using API::Object::deref; private: - explicit WebNotificationManagerProxy(WebContext*); + explicit WebNotificationManagerProxy(WebProcessPool*); typedef bool (*NotificationFilterFunction)(uint64_t pageID, uint64_t pageNotificationID, uint64_t desiredPageID, const Vector<uint64_t>& desiredPageNotificationIDs); void clearNotifications(WebPageProxy*, const Vector<uint64_t>& pageNotificationIDs, NotificationFilterFunction); // WebContextSupplement - virtual void contextDestroyed() override; + virtual void processPoolDestroyed() override; virtual void refWebContextSupplement() override; virtual void derefWebContextSupplement() override; diff --git a/Source/WebKit2/UIProcess/Notifications/WebNotificationProvider.cpp b/Source/WebKit2/UIProcess/Notifications/WebNotificationProvider.cpp index 545e4153d..a2a83ada0 100644 --- a/Source/WebKit2/UIProcess/Notifications/WebNotificationProvider.cpp +++ b/Source/WebKit2/UIProcess/Notifications/WebNotificationProvider.cpp @@ -27,12 +27,13 @@ #include "WebNotificationProvider.h" #include "APIArray.h" +#include "APIDictionary.h" #include "APINumber.h" -#include "ImmutableDictionary.h" +#include "APISecurityOrigin.h" #include "WKAPICast.h" #include "WebNotification.h" #include "WebNotificationManagerProxy.h" -#include "WebSecurityOrigin.h" +#include "WebPageProxy.h" namespace WebKit { @@ -71,7 +72,7 @@ void WebNotificationProvider::clearNotifications(const Vector<uint64_t>& notific for (const auto& notificationID : notificationIDs) arrayIDs.uncheckedAppend(API::UInt64::create(notificationID)); - m_client.clearNotifications(toAPI(API::Array::create(std::move(arrayIDs)).get()), m_client.base.clientInfo); + m_client.clearNotifications(toAPI(API::Array::create(WTFMove(arrayIDs)).ptr()), m_client.base.clientInfo); } void WebNotificationProvider::addNotificationManager(WebNotificationManagerProxy* manager) @@ -90,10 +91,10 @@ void WebNotificationProvider::removeNotificationManager(WebNotificationManagerPr m_client.removeNotificationManager(toAPI(manager), m_client.base.clientInfo); } -PassRefPtr<ImmutableDictionary> WebNotificationProvider::notificationPermissions() +PassRefPtr<API::Dictionary> WebNotificationProvider::notificationPermissions() { if (!m_client.notificationPermissions) - return ImmutableDictionary::create(); + return API::Dictionary::create(); return adoptRef(toImpl(m_client.notificationPermissions(m_client.base.clientInfo))); } diff --git a/Source/WebKit2/UIProcess/Notifications/WebNotificationProvider.h b/Source/WebKit2/UIProcess/Notifications/WebNotificationProvider.h index b48d43346..14fabe16c 100644 --- a/Source/WebKit2/UIProcess/Notifications/WebNotificationProvider.h +++ b/Source/WebKit2/UIProcess/Notifications/WebNotificationProvider.h @@ -32,6 +32,9 @@ #include <wtf/Vector.h> namespace API { + +class Dictionary; + template<> struct ClientTraits<WKNotificationProviderBase> { typedef std::tuple<WKNotificationProviderV0> Versions; }; @@ -39,11 +42,9 @@ template<> struct ClientTraits<WKNotificationProviderBase> { namespace WebKit { -class ImmutableDictionary; class WebNotification; class WebNotificationManagerProxy; class WebPageProxy; -class WebSecurityOrigin; class WebNotificationProvider : public API::Client<WKNotificationProviderBase> { public: @@ -55,7 +56,7 @@ public: void addNotificationManager(WebNotificationManagerProxy*); void removeNotificationManager(WebNotificationManagerProxy*); - PassRefPtr<ImmutableDictionary> notificationPermissions(); + PassRefPtr<API::Dictionary> notificationPermissions(); }; } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/PageClient.h b/Source/WebKit2/UIProcess/PageClient.h index 018b1baf9..b5760b749 100644 --- a/Source/WebKit2/UIProcess/PageClient.h +++ b/Source/WebKit2/UIProcess/PageClient.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2011 Apple Inc. All rights reserved. + * Copyright (C) 2010, 2011, 2016 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -34,7 +34,7 @@ #include <WebCore/EditorClient.h> #include <wtf/Forward.h> -#if PLATFORM(MAC) +#if PLATFORM(COCOA) #include "PluginComplexTextInputState.h" OBJC_CLASS CALayer; @@ -46,15 +46,22 @@ OBJC_CLASS NSTextAlternatives; #endif namespace WebCore { - class Cursor; - struct ViewportAttributes; +class Cursor; +class TextIndicator; +class WebMediaSessionManager; +enum class TextIndicatorWindowLifetime : uint8_t; +enum class TextIndicatorWindowDismissalAnimation : uint8_t; +struct Highlight; +struct ViewportAttributes; } namespace WebKit { class DrawingAreaProxy; -class FindIndicator; class NativeWebKeyboardEvent; +class NativeWebMouseEvent; +class RemoteLayerTreeTransaction; +class ViewSnapshot; class WebContextMenuProxy; class WebEditCommandProxy; class WebPopupMenuProxy; @@ -71,7 +78,11 @@ class WebColorPicker; class WebFullScreenManagerProxyClient; #endif -#if PLATFORM(MAC) +#if USE(GSTREAMER) +class InstallMissingMediaPluginsPermissionRequest; +#endif + +#if PLATFORM(COCOA) struct ColorSpaceData; #endif @@ -92,6 +103,8 @@ public: virtual bool canScrollView() = 0; // Tell the view to scroll scrollRect by scrollOffset. virtual void scrollView(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset) = 0; + // Tell the view to scroll to the given position, and whether this was a programmatic scroll. + virtual void requestScroll(const WebCore::FloatPoint& scrollPosition, const WebCore::IntPoint& scrollOrigin, bool isProgrammaticScroll) = 0; // Return the size of the view the page is associated with. virtual WebCore::IntSize viewSize() = 0; @@ -105,6 +118,9 @@ public: // Return whether the view is visible. virtual bool isViewVisible() = 0; + // Return whether the view is visible, or occluded by another window. + virtual bool isViewVisibleOrOccluded() { return isViewVisible(); } + // Return whether the view is in a window. virtual bool isViewInWindow() = 0; @@ -112,9 +128,9 @@ public: virtual bool isVisuallyIdle() { return !isViewVisible(); } // Return the layer hosting mode for the view. - virtual LayerHostingMode viewLayerHostingMode() { return LayerHostingModeDefault; } + virtual LayerHostingMode viewLayerHostingMode() { return LayerHostingMode::InProcess; } - virtual void processDidCrash() = 0; + virtual void processDidExit() = 0; virtual void didRelaunchProcess() = 0; virtual void pageClosed() = 0; @@ -122,33 +138,29 @@ public: virtual void toolTipChanged(const String&, const String&) = 0; - virtual bool decidePolicyForGeolocationPermissionRequest(WebFrameProxy&, WebSecurityOrigin&, GeolocationPermissionRequestProxy&) + virtual bool decidePolicyForGeolocationPermissionRequest(WebFrameProxy&, API::SecurityOrigin&, GeolocationPermissionRequestProxy&) { return false; } - virtual void didCommitLoadForMainFrame() = 0; + virtual void didCommitLoadForMainFrame(const String& mimeType, bool useCustomContentProvider) = 0; -#if USE(TILED_BACKING_STORE) +#if USE(COORDINATED_GRAPHICS_MULTIPROCESS) virtual void pageDidRequestScroll(const WebCore::IntPoint&) = 0; virtual void didRenderFrame(const WebCore::IntSize& contentsSize, const WebCore::IntRect& coveredRect) = 0; virtual void pageTransitionViewportReady() = 0; -#endif -#if USE(COORDINATED_GRAPHICS) virtual void didFindZoomableArea(const WebCore::IntPoint&, const WebCore::IntRect&) = 0; #endif -#if PLATFORM(EFL) || PLATFORM(GTK) +#if PLATFORM(EFL) virtual void updateTextInputState() = 0; -#endif // PLATFORM(EFL) || PLATOFRM(GTK) +#endif // PLATFORM(EFL) -#if PLATFORM(EFL) || PLATFORM(GTK) virtual void handleDownloadRequest(DownloadProxy*) = 0; -#endif // PLATFORM(EFL) || PLATFORM(GTK) -#if PLATFORM(EFL) || PLATFORM(IOS) + virtual bool handleRunOpenPanel(WebPageProxy*, WebFrameProxy*, WebOpenPanelParameters*, WebOpenPanelResultListenerProxy*) { return false; } + virtual void didChangeContentSize(const WebCore::IntSize&) = 0; -#endif #if PLATFORM(GTK) && ENABLE(DRAG_SUPPORT) virtual void startDrag(const WebCore::DragData&, PassRefPtr<ShareableBitmap> dragImage) = 0; @@ -162,69 +174,99 @@ public: virtual void clearAllEditCommands() = 0; virtual bool canUndoRedo(WebPageProxy::UndoOrRedo) = 0; virtual void executeUndoRedo(WebPageProxy::UndoOrRedo) = 0; -#if PLATFORM(MAC) +#if PLATFORM(COCOA) virtual void accessibilityWebProcessTokenReceived(const IPC::DataReference&) = 0; - virtual bool interpretKeyEvent(const NativeWebKeyboardEvent&, Vector<WebCore::KeypressCommand>&) = 0; virtual bool executeSavedCommandBySelector(const String& selector) = 0; virtual void setDragImage(const WebCore::IntPoint& clientPosition, PassRefPtr<ShareableBitmap> dragImage, bool isLinkDrag) = 0; virtual void updateSecureInputState() = 0; virtual void resetSecureInputState() = 0; virtual void notifyInputContextAboutDiscardedComposition() = 0; virtual void makeFirstResponder() = 0; - virtual void setAcceleratedCompositingRootLayer(CALayer *) = 0; - virtual CALayer *acceleratedCompositingRootLayer() const = 0; - virtual RetainPtr<CGImageRef> takeViewSnapshot() = 0; + virtual void setAcceleratedCompositingRootLayer(LayerOrView *) = 0; + virtual LayerOrView *acceleratedCompositingRootLayer() const = 0; + virtual PassRefPtr<ViewSnapshot> takeViewSnapshot() = 0; virtual void wheelEventWasNotHandledByWebCore(const NativeWebWheelEvent&) = 0; +#if ENABLE(MAC_GESTURE_EVENTS) + virtual void gestureEventWasNotHandledByWebCore(const NativeWebGestureEvent&) = 0; +#endif +#endif + +#if PLATFORM(COCOA) || PLATFORM(GTK) + virtual void selectionDidChange() = 0; #endif #if USE(APPKIT) - virtual void setPromisedData(const String& pasteboardName, PassRefPtr<WebCore::SharedBuffer> imageBuffer, const String& filename, const String& extension, const String& title, + virtual void setPromisedDataForImage(const String& pasteboardName, PassRefPtr<WebCore::SharedBuffer> imageBuffer, const String& filename, const String& extension, const String& title, const String& url, const String& visibleUrl, PassRefPtr<WebCore::SharedBuffer> archiveBuffer) = 0; -#endif +#if ENABLE(ATTACHMENT_ELEMENT) + virtual void setPromisedDataForAttachment(const String& pasteboardName, const String& filename, const String& extension, const String& title, + const String& url, const String& visibleUrl) = 0; -#if PLATFORM(GTK) - virtual void getEditorCommandsForKeyEvent(const NativeWebKeyboardEvent&, const AtomicString&, Vector<WTF::String>&) = 0; #endif +#endif + virtual WebCore::FloatRect convertToDeviceSpace(const WebCore::FloatRect&) = 0; virtual WebCore::FloatRect convertToUserSpace(const WebCore::FloatRect&) = 0; - virtual WebCore::IntPoint screenToWindow(const WebCore::IntPoint&) = 0; - virtual WebCore::IntRect windowToScreen(const WebCore::IntRect&) = 0; + virtual WebCore::IntPoint screenToRootView(const WebCore::IntPoint&) = 0; + virtual WebCore::IntRect rootViewToScreen(const WebCore::IntRect&) = 0; +#if PLATFORM(IOS) + virtual WebCore::IntPoint accessibilityScreenToRootView(const WebCore::IntPoint&) = 0; + virtual WebCore::IntRect rootViewToAccessibilityScreen(const WebCore::IntRect&) = 0; + virtual void didNotHandleTapAsClick(const WebCore::IntPoint&) = 0; +#endif virtual void doneWithKeyEvent(const NativeWebKeyboardEvent&, bool wasEventHandled) = 0; #if ENABLE(TOUCH_EVENTS) virtual void doneWithTouchEvent(const NativeWebTouchEvent&, bool wasEventHandled) = 0; #endif - virtual PassRefPtr<WebPopupMenuProxy> createPopupMenuProxy(WebPageProxy*) = 0; - virtual PassRefPtr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy*) = 0; + virtual RefPtr<WebPopupMenuProxy> createPopupMenuProxy(WebPageProxy&) = 0; +#if ENABLE(CONTEXT_MENUS) + virtual std::unique_ptr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy&, const ContextMenuContextData&, const UserData&) = 0; +#endif #if ENABLE(INPUT_TYPE_COLOR) - virtual PassRefPtr<WebColorPicker> createColorPicker(WebPageProxy*, const WebCore::Color& initialColor, const WebCore::IntRect&) = 0; + virtual RefPtr<WebColorPicker> createColorPicker(WebPageProxy*, const WebCore::Color& initialColor, const WebCore::IntRect&) = 0; #endif - virtual void setFindIndicator(PassRefPtr<FindIndicator>, bool fadeOut, bool animate) = 0; +#if PLATFORM(COCOA) + virtual void setTextIndicator(Ref<WebCore::TextIndicator>, WebCore::TextIndicatorWindowLifetime) = 0; + virtual void clearTextIndicator(WebCore::TextIndicatorWindowDismissalAnimation) = 0; + virtual void setTextIndicatorAnimationProgress(float) = 0; +#endif -#if USE(ACCELERATED_COMPOSITING) virtual void enterAcceleratedCompositingMode(const LayerTreeContext&) = 0; virtual void exitAcceleratedCompositingMode() = 0; virtual void updateAcceleratedCompositingMode(const LayerTreeContext&) = 0; -#endif + virtual void willEnterAcceleratedCompositingMode() = 0; -#if !PLATFORM(IOS) && PLATFORM(MAC) +#if PLATFORM(MAC) virtual void pluginFocusOrWindowFocusChanged(uint64_t pluginComplexTextInputIdentifier, bool pluginHasFocusAndWindowHasFocus) = 0; virtual void setPluginComplexTextInputState(uint64_t pluginComplexTextInputIdentifier, PluginComplexTextInputState) = 0; - virtual void didPerformDictionaryLookup(const AttributedString&, const DictionaryPopupInfo&) = 0; - virtual void dismissDictionaryLookupPanel() = 0; + virtual void didPerformDictionaryLookup(const WebCore::DictionaryPopupInfo&) = 0; + virtual void dismissContentRelativeChildWindows(bool withAnimation = true) = 0; virtual void showCorrectionPanel(WebCore::AlternativeTextType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings) = 0; virtual void dismissCorrectionPanel(WebCore::ReasonForDismissingAlternativeText) = 0; virtual String dismissCorrectionPanelSoon(WebCore::ReasonForDismissingAlternativeText) = 0; virtual void recordAutocorrectionResponse(WebCore::AutocorrectionResponseType, const String& replacedString, const String& replacementString) = 0; - virtual void recommendedScrollbarStyleDidChange(int32_t newStyle) = 0; + virtual void recommendedScrollbarStyleDidChange(WebCore::ScrollbarStyle) = 0; + virtual void removeNavigationGestureSnapshot() = 0; + + virtual CGRect boundsOfLayerInLayerBackedWindowCoordinates(CALayer *) const = 0; virtual ColorSpaceData colorSpace() = 0; + virtual void showPlatformContextMenu(NSMenu *, WebCore::IntPoint) = 0; + + virtual void startWindowDrag() = 0; + virtual NSWindow *platformWindow() = 0; + +#if WK_API_ENABLED + virtual NSView *inspectorAttachmentView() = 0; + virtual _WKRemoteObjectRegistry *remoteObjectRegistry() = 0; +#endif + #if USE(APPKIT) - virtual WKView* wkView() const = 0; virtual void intrinsicContentSizeDidChange(const WebCore::IntSize& intrinsicContentSize) = 0; #if USE(DICTATION_ALTERNATIVES) virtual uint64_t addDictationAlternatives(const RetainPtr<NSTextAlternatives>&) = 0; @@ -232,27 +274,95 @@ public: virtual void showDictationAlternativeUI(const WebCore::FloatRect& boundingBoxOfDictatedText, uint64_t dictationContext) = 0; virtual Vector<String> dictationAlternatives(uint64_t dictationContext) = 0; #endif // USE(DICTATION_ALTERNATIVES) +#if USE(INSERTION_UNDO_GROUPING) + virtual void registerInsertionUndoGrouping() = 0; +#endif // USE(INSERTION_UNDO_GROUPING) #endif // USE(APPKIT) #endif // PLATFORM(MAC) #if PLATFORM(IOS) - virtual void mainDocumentDidReceiveMobileDocType() = 0; - + virtual void commitPotentialTapFailed() = 0; virtual 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) = 0; - virtual void didChangeViewportArguments(const WebCore::ViewportArguments&) = 0; + virtual void didCommitLayerTree(const RemoteLayerTreeTransaction&) = 0; + virtual void dynamicViewportUpdateChangedTarget(double newScale, const WebCore::FloatPoint& newScrollPosition, uint64_t transactionID) = 0; + virtual void couldNotRestorePageState() = 0; + virtual void restorePageState(const WebCore::FloatRect&, double) = 0; + virtual void restorePageCenterAndScale(const WebCore::FloatPoint&, double) = 0; - virtual void startAssistingNode(const WebCore::IntRect&, bool hasNextFocusable, bool hasPreviousFocusable) = 0; + virtual void startAssistingNode(const AssistedNodeInformation&, bool userIsInteracting, bool blurPreviousNode, API::Object* userData) = 0; virtual void stopAssistingNode() = 0; - virtual void selectionDidChange() = 0; + virtual bool isAssistingNode() = 0; virtual bool interpretKeyEvent(const NativeWebKeyboardEvent&, bool isCharEvent) = 0; virtual void positionInformationDidChange(const InteractionInformationAtPosition&) = 0; + virtual void saveImageToLibrary(PassRefPtr<WebCore::SharedBuffer>) = 0; + virtual void didUpdateBlockSelectionWithTouch(uint32_t touch, uint32_t flags, float growThreshold, float shrinkThreshold) = 0; + virtual void showPlaybackTargetPicker(bool hasVideo, const WebCore::IntRect& elementRect) = 0; + virtual void zoomToRect(WebCore::FloatRect, double minimumScale, double maximumScale) = 0; + virtual void disableDoubleTapGesturesDuringTapIfNecessary(uint64_t requestID) = 0; + virtual double minimumZoomScale() const = 0; + virtual WebCore::FloatRect documentRect() const = 0; + virtual void overflowScrollViewWillStartPanGesture() = 0; + virtual void overflowScrollViewDidScroll() = 0; + virtual void overflowScrollWillStartScroll() = 0; + virtual void overflowScrollDidEndScroll() = 0; + virtual void didFinishDrawingPagesToPDF(const IPC::DataReference&) = 0; + virtual Vector<String> mimeTypesWithCustomContentProviders() = 0; + + virtual void showInspectorHighlight(const WebCore::Highlight&) = 0; + virtual void hideInspectorHighlight() = 0; + + virtual void showInspectorIndication() = 0; + virtual void hideInspectorIndication() = 0; + + virtual void enableInspectorNodeSearch() = 0; + virtual void disableInspectorNodeSearch() = 0; #endif // Auxiliary Client Creation #if ENABLE(FULLSCREEN_API) virtual WebFullScreenManagerProxyClient& fullScreenManagerProxyClient() = 0; #endif + + // Custom representations. + virtual void didFinishLoadingDataForCustomContentProvider(const String& suggestedFilename, const IPC::DataReference&) = 0; + + virtual void navigationGestureDidBegin() = 0; + virtual void navigationGestureWillEnd(bool willNavigate, WebBackForwardListItem&) = 0; + virtual void navigationGestureDidEnd(bool willNavigate, WebBackForwardListItem&) = 0; + virtual void navigationGestureDidEnd() = 0; + virtual void willRecordNavigationSnapshot(WebBackForwardListItem&) = 0; + virtual void didRemoveNavigationGestureSnapshot() = 0; + + virtual void didFirstVisuallyNonEmptyLayoutForMainFrame() = 0; + virtual void didFinishLoadForMainFrame() = 0; + virtual void didFailLoadForMainFrame() = 0; + virtual void didSameDocumentNavigationForMainFrame(SameDocumentNavigationType) = 0; + + virtual void didChangeBackgroundColor() = 0; + +#if PLATFORM(MAC) + virtual void didPerformImmediateActionHitTest(const WebHitTestResultData&, bool contentPreventsDefault, API::Object*) = 0; + + virtual void* immediateActionAnimationControllerForHitTestResult(RefPtr<API::HitTestResult>, uint64_t, RefPtr<API::Object>) = 0; + + virtual void didHandleAcceptedCandidate() = 0; +#endif + +#if ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS) + virtual WebCore::WebMediaSessionManager& mediaSessionManager() = 0; +#endif + + virtual void refView() = 0; + virtual void derefView() = 0; + +#if ENABLE(VIDEO) && USE(GSTREAMER) + virtual bool decidePolicyForInstallMissingMediaPluginsPermissionRequest(InstallMissingMediaPluginsPermissionRequest&) = 0; +#endif + + virtual void didRestoreScrollPosition() = 0; + + virtual bool windowIsFrontWindowUnderMouse(const NativeWebMouseEvent&) { return false; } }; } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/PageLoadState.cpp b/Source/WebKit2/UIProcess/PageLoadState.cpp index d4044165c..8b501bf11 100644 --- a/Source/WebKit2/UIProcess/PageLoadState.cpp +++ b/Source/WebKit2/UIProcess/PageLoadState.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Apple Inc. All rights reserved. + * Copyright (C) 2013-2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,13 +26,16 @@ #include "config.h" #include "PageLoadState.h" +#include "WebPageProxy.h" + namespace WebKit { // Progress always starts at this value. This helps provide feedback as soon as a load starts. static const double initialProgressValue = 0.1; -PageLoadState::PageLoadState() - : m_mayHaveUncommittedChanges(false) +PageLoadState::PageLoadState(WebPageProxy& webPageProxy) + : m_webPageProxy(webPageProxy) + , m_mayHaveUncommittedChanges(false) , m_outstandingTransactionCount(0) { } @@ -42,6 +45,26 @@ PageLoadState::~PageLoadState() ASSERT(m_observers.isEmpty()); } +PageLoadState::Transaction::Transaction(PageLoadState& pageLoadState) + : m_webPageProxy(&pageLoadState.m_webPageProxy) + , m_pageLoadState(&pageLoadState) +{ + m_pageLoadState->beginTransaction(); +} + +PageLoadState::Transaction::Transaction(Transaction&& other) + : m_webPageProxy(WTFMove(other.m_webPageProxy)) + , m_pageLoadState(other.m_pageLoadState) +{ + other.m_pageLoadState = nullptr; +} + +PageLoadState::Transaction::~Transaction() +{ + if (m_pageLoadState) + m_pageLoadState->endTransaction(); +} + void PageLoadState::addObserver(Observer& observer) { ASSERT(!m_observers.contains(&observer)); @@ -51,10 +74,8 @@ void PageLoadState::addObserver(Observer& observer) void PageLoadState::removeObserver(Observer& observer) { - ASSERT(m_observers.contains(&observer)); - - size_t index = m_observers.find(&observer); - m_observers.remove(index); + bool removed = m_observers.removeFirst(&observer); + ASSERT_UNUSED(removed, removed); } void PageLoadState::endTransaction() @@ -72,12 +93,20 @@ void PageLoadState::commitChanges() m_mayHaveUncommittedChanges = false; + bool canGoBackChanged = m_committedState.canGoBack != m_uncommittedState.canGoBack; + bool canGoForwardChanged = m_committedState.canGoForward != m_uncommittedState.canGoForward; bool titleChanged = m_committedState.title != m_uncommittedState.title; - bool isLoadingChanged = isLoadingState(m_committedState.state) != isLoadingState(m_uncommittedState.state); + bool isLoadingChanged = isLoading(m_committedState) != isLoading(m_uncommittedState); bool activeURLChanged = activeURL(m_committedState) != activeURL(m_uncommittedState); bool hasOnlySecureContentChanged = hasOnlySecureContent(m_committedState) != hasOnlySecureContent(m_uncommittedState); bool estimatedProgressChanged = estimatedProgress(m_committedState) != estimatedProgress(m_uncommittedState); + bool networkRequestsInProgressChanged = m_committedState.networkRequestsInProgress != m_uncommittedState.networkRequestsInProgress; + bool certificateInfoChanged = m_committedState.certificateInfo != m_uncommittedState.certificateInfo; + if (canGoBackChanged) + callObserverCallback(&Observer::willChangeCanGoBack); + if (canGoForwardChanged) + callObserverCallback(&Observer::willChangeCanGoForward); if (titleChanged) callObserverCallback(&Observer::willChangeTitle); if (isLoadingChanged) @@ -88,10 +117,18 @@ void PageLoadState::commitChanges() callObserverCallback(&Observer::willChangeHasOnlySecureContent); if (estimatedProgressChanged) callObserverCallback(&Observer::willChangeEstimatedProgress); + if (networkRequestsInProgressChanged) + callObserverCallback(&Observer::willChangeNetworkRequestsInProgress); + if (certificateInfoChanged) + callObserverCallback(&Observer::willChangeCertificateInfo); m_committedState = m_uncommittedState; // The "did" ordering is the reverse of the "will". This is a requirement of Cocoa Key-Value Observing. + if (certificateInfoChanged) + callObserverCallback(&Observer::didChangeCertificateInfo); + if (networkRequestsInProgressChanged) + callObserverCallback(&Observer::didChangeNetworkRequestsInProgress); if (estimatedProgressChanged) callObserverCallback(&Observer::didChangeEstimatedProgress); if (hasOnlySecureContentChanged) @@ -102,6 +139,10 @@ void PageLoadState::commitChanges() callObserverCallback(&Observer::didChangeIsLoading); if (titleChanged) callObserverCallback(&Observer::didChangeTitle); + if (canGoForwardChanged) + callObserverCallback(&Observer::didChangeCanGoForward); + if (canGoBackChanged) + callObserverCallback(&Observer::didChangeCanGoBack); } void PageLoadState::reset(const Transaction::Token& token) @@ -121,11 +162,12 @@ void PageLoadState::reset(const Transaction::Token& token) m_uncommittedState.title = String(); m_uncommittedState.estimatedProgress = 0; + m_uncommittedState.networkRequestsInProgress = false; } bool PageLoadState::isLoading() const { - return isLoadingState(m_committedState.state); + return isLoading(m_committedState); } String PageLoadState::activeURL(const Data& data) @@ -161,7 +203,7 @@ bool PageLoadState::hasOnlySecureContent(const Data& data) if (data.hasInsecureContent) return false; - return data.url.startsWith("https:", false); + return WebCore::protocolIs(data.url, "https"); } bool PageLoadState::hasOnlySecureContent() const @@ -230,13 +272,14 @@ void PageLoadState::didFailProvisionalLoad(const Transaction::Token& token) m_uncommittedState.unreachableURL = m_lastUnreachableURL; } -void PageLoadState::didCommitLoad(const Transaction::Token& token) +void PageLoadState::didCommitLoad(const Transaction::Token& token, WebCertificateInfo& certificateInfo, bool hasInsecureContent) { ASSERT_UNUSED(token, &token.m_pageLoadState == this); ASSERT(m_uncommittedState.state == State::Provisional); m_uncommittedState.state = State::Committed; - m_uncommittedState.hasInsecureContent = false; + m_uncommittedState.hasInsecureContent = hasInsecureContent; + m_uncommittedState.certificateInfo = &certificateInfo; m_uncommittedState.url = m_uncommittedState.provisionalURL; m_uncommittedState.provisionalURL = String(); @@ -295,6 +338,28 @@ void PageLoadState::setTitle(const Transaction::Token& token, const String& titl m_uncommittedState.title = title; } +bool PageLoadState::canGoBack() const +{ + return m_committedState.canGoBack; +} + +void PageLoadState::setCanGoBack(const Transaction::Token& token, bool canGoBack) +{ + ASSERT_UNUSED(token, &token.m_pageLoadState == this); + m_uncommittedState.canGoBack = canGoBack; +} + +bool PageLoadState::canGoForward() const +{ + return m_committedState.canGoForward; +} + +void PageLoadState::setCanGoForward(const Transaction::Token& token, bool canGoForward) +{ + ASSERT_UNUSED(token, &token.m_pageLoadState == this); + m_uncommittedState.canGoForward = canGoForward; +} + void PageLoadState::didStartProgress(const Transaction::Token& token) { ASSERT_UNUSED(token, &token.m_pageLoadState == this); @@ -313,9 +378,18 @@ void PageLoadState::didFinishProgress(const Transaction::Token& token) m_uncommittedState.estimatedProgress = 1; } -bool PageLoadState::isLoadingState(State state) +void PageLoadState::setNetworkRequestsInProgress(const Transaction::Token& token, bool networkRequestsInProgress) +{ + ASSERT_UNUSED(token, &token.m_pageLoadState == this); + m_uncommittedState.networkRequestsInProgress = networkRequestsInProgress; +} + +bool PageLoadState::isLoading(const Data& data) { - switch (state) { + if (!data.pendingAPIRequestURL.isNull()) + return true; + + switch (data.state) { case State::Provisional: case State::Committed: return true; @@ -328,6 +402,16 @@ bool PageLoadState::isLoadingState(State state) return false; } +void PageLoadState::willChangeProcessIsResponsive() +{ + callObserverCallback(&Observer::willChangeWebProcessIsResponsive); +} + +void PageLoadState::didChangeProcessIsResponsive() +{ + callObserverCallback(&Observer::didChangeWebProcessIsResponsive); +} + void PageLoadState::callObserverCallback(void (Observer::*callback)()) { for (auto* observer : m_observers) diff --git a/Source/WebKit2/UIProcess/PageLoadState.h b/Source/WebKit2/UIProcess/PageLoadState.h index 0501e4500..402c97f58 100644 --- a/Source/WebKit2/UIProcess/PageLoadState.h +++ b/Source/WebKit2/UIProcess/PageLoadState.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Apple Inc. All rights reserved. + * Copyright (C) 2013-2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,13 +26,17 @@ #ifndef PageLoadState_h #define PageLoadState_h +#include "WebCertificateInfo.h" #include <wtf/text/WTFString.h> namespace WebKit { +class WebCertificateInfo; +class WebPageProxy; + class PageLoadState { public: - PageLoadState(); + explicit PageLoadState(WebPageProxy&); ~PageLoadState(); enum class State { @@ -59,31 +63,33 @@ public: virtual void willChangeEstimatedProgress() = 0; virtual void didChangeEstimatedProgress() = 0; + + virtual void willChangeCanGoBack() = 0; + virtual void didChangeCanGoBack() = 0; + + virtual void willChangeCanGoForward() = 0; + virtual void didChangeCanGoForward() = 0; + + virtual void willChangeNetworkRequestsInProgress() = 0; + virtual void didChangeNetworkRequestsInProgress() = 0; + + virtual void willChangeCertificateInfo() = 0; + virtual void didChangeCertificateInfo() = 0; + + virtual void willChangeWebProcessIsResponsive() = 0; + virtual void didChangeWebProcessIsResponsive() = 0; }; class Transaction { WTF_MAKE_NONCOPYABLE(Transaction); public: - Transaction(Transaction&& other) - : m_pageLoadState(other.m_pageLoadState) - { - other.m_pageLoadState = nullptr; - } - - ~Transaction() - { - if (m_pageLoadState) - m_pageLoadState->endTransaction(); - } + Transaction(Transaction&&); + ~Transaction(); private: friend class PageLoadState; - explicit Transaction(PageLoadState& pageLoadState) - : m_pageLoadState(&pageLoadState) - { - m_pageLoadState->beginTransaction(); - } + explicit Transaction(PageLoadState&); class Token { public: @@ -100,6 +106,7 @@ public: #endif }; + RefPtr<WebPageProxy> m_webPageProxy; PageLoadState* m_pageLoadState; }; @@ -122,6 +129,9 @@ public: bool hasOnlySecureContent() const; double estimatedProgress() const; + bool networkRequestsInProgress() const { return m_committedState.networkRequestsInProgress; } + + WebCertificateInfo* certificateInfo() const { return m_committedState.certificateInfo.get(); } const String& pendingAPIRequestURL() const; void setPendingAPIRequestURL(const Transaction::Token&, const String&); @@ -131,7 +141,7 @@ public: void didReceiveServerRedirectForProvisionalLoad(const Transaction::Token&, const String& url); void didFailProvisionalLoad(const Transaction::Token&); - void didCommitLoad(const Transaction::Token&); + void didCommitLoad(const Transaction::Token&, WebCertificateInfo&, bool hasInsecureContent); void didFinishLoad(const Transaction::Token&); void didFailLoad(const Transaction::Token&); @@ -144,13 +154,23 @@ public: const String& title() const; void setTitle(const Transaction::Token&, const String&); + bool canGoBack() const; + void setCanGoBack(const Transaction::Token&, bool); + + bool canGoForward() const; + void setCanGoForward(const Transaction::Token&, bool); + void didStartProgress(const Transaction::Token&); void didChangeProgress(const Transaction::Token&, double); void didFinishProgress(const Transaction::Token&); + void setNetworkRequestsInProgress(const Transaction::Token&, bool); -private: - static bool isLoadingState(State); + // FIXME: We piggy-back off PageLoadState::Observer so that both WKWebView and WKObservablePageState + // can listen for changes. Once we get rid of WKObservablePageState these could just be part of API::NavigationClient. + void willChangeProcessIsResponsive(); + void didChangeProcessIsResponsive(); +private: void beginTransaction() { ++m_outstandingTransactionCount; } void endTransaction(); @@ -162,7 +182,10 @@ private: Data() : state(State::Finished) , hasInsecureContent(false) + , canGoBack(false) + , canGoForward(false) , estimatedProgress(0) + , networkRequestsInProgress(false) { } @@ -178,13 +201,22 @@ private: String title; + bool canGoBack; + bool canGoForward; + double estimatedProgress; + bool networkRequestsInProgress; + + RefPtr<WebCertificateInfo> certificateInfo; }; + static bool isLoading(const Data&); static String activeURL(const Data&); static bool hasOnlySecureContent(const Data&); static double estimatedProgress(const Data&); + WebPageProxy& m_webPageProxy; + Data m_committedState; Data m_uncommittedState; diff --git a/Source/WebKit2/UIProcess/PageViewportControllerClient.h b/Source/WebKit2/UIProcess/PageViewportControllerClient.h new file mode 100644 index 000000000..4ad7ce506 --- /dev/null +++ b/Source/WebKit2/UIProcess/PageViewportControllerClient.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this program; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef PageViewportControllerClient_h +#define PageViewportControllerClient_h + +#include <wtf/Noncopyable.h> + +namespace WebCore { +class FloatPoint; +class IntSize; +} + +namespace WebKit { + +class PageViewportControllerClient { + WTF_MAKE_NONCOPYABLE(PageViewportControllerClient); +public: + PageViewportControllerClient() { } + virtual ~PageViewportControllerClient() { } + + virtual void setViewportPosition(const WebCore::FloatPoint&) = 0; + virtual void setPageScaleFactor(float) = 0; + + virtual void didChangeContentsSize(const WebCore::IntSize&) = 0; + virtual void didChangeVisibleContents() = 0; + virtual void didChangeViewportAttributes() = 0; +}; + +} // namespace WebKit + +#endif // PageViewportControllerClient_h diff --git a/Source/WebKit2/UIProcess/Plugins/PlugInAutoStartProvider.cpp b/Source/WebKit2/UIProcess/Plugins/PlugInAutoStartProvider.cpp index e5724032d..25075924e 100644 --- a/Source/WebKit2/UIProcess/Plugins/PlugInAutoStartProvider.cpp +++ b/Source/WebKit2/UIProcess/Plugins/PlugInAutoStartProvider.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012, 2013 Apple Inc. All rights reserved. + * Copyright (C) 2012-2014 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,10 +27,10 @@ #include "PlugInAutoStartProvider.h" #include "APIArray.h" -#include "ImmutableDictionary.h" -#include "WebContext.h" +#include "APIDictionary.h" #include "WebContextClient.h" #include "WebProcessMessages.h" +#include "WebProcessPool.h" #include <wtf/CurrentTime.h> using namespace WebCore; @@ -39,9 +39,11 @@ static const double plugInAutoStartExpirationTimeThreshold = 30 * 24 * 60 * 60; namespace WebKit { -PlugInAutoStartProvider::PlugInAutoStartProvider(WebContext* context) - : m_context(context) +PlugInAutoStartProvider::PlugInAutoStartProvider(WebProcessPool* processPool) + : m_processPool(processPool) { + m_hashToOriginMap.add(SessionID::defaultSessionID(), HashMap<unsigned, String>()); + m_autoStartTable.add(SessionID::defaultSessionID(), AutoStartTable()); } static double expirationTimeFromNow() @@ -49,64 +51,68 @@ static double expirationTimeFromNow() return currentTime() + plugInAutoStartExpirationTimeThreshold; } -void PlugInAutoStartProvider::addAutoStartOriginHash(const String& pageOrigin, unsigned plugInOriginHash) +void PlugInAutoStartProvider::addAutoStartOriginHash(const String& pageOrigin, unsigned plugInOriginHash, SessionID sessionID) { - if (m_hashToOriginMap.contains(plugInOriginHash)) + auto sessionIterator = m_hashToOriginMap.find(sessionID); + if (sessionIterator == m_hashToOriginMap.end()) { + if (m_hashToOriginMap.get(SessionID::defaultSessionID()).contains(plugInOriginHash)) + return; + sessionIterator = m_hashToOriginMap.set(sessionID, HashMap<unsigned, String>()).iterator; + } else if (sessionIterator->value.contains(plugInOriginHash) || m_hashToOriginMap.get(SessionID::defaultSessionID()).contains(plugInOriginHash)) return; - AutoStartTable::iterator it = m_autoStartTable.find(pageOrigin); - if (it == m_autoStartTable.end()) - it = m_autoStartTable.add(pageOrigin, PlugInAutoStartOriginHash()).iterator; + AutoStartTable::iterator it = m_autoStartTable.add(sessionID, AutoStartTable()).iterator->value.add(pageOrigin, PlugInAutoStartOriginMap()).iterator; double expirationTime = expirationTimeFromNow(); it->value.set(plugInOriginHash, expirationTime); - m_hashToOriginMap.set(plugInOriginHash, pageOrigin); + sessionIterator->value.set(plugInOriginHash, pageOrigin); - m_context->sendToAllProcesses(Messages::WebProcess::DidAddPlugInAutoStartOriginHash(plugInOriginHash, expirationTime)); - m_context->client().plugInAutoStartOriginHashesChanged(m_context); + m_processPool->sendToAllProcesses(Messages::WebProcess::DidAddPlugInAutoStartOriginHash(plugInOriginHash, expirationTime, sessionID)); + + if (!sessionID.isEphemeral()) + m_processPool->client().plugInAutoStartOriginHashesChanged(m_processPool); } -PlugInAutoStartOriginHash PlugInAutoStartProvider::autoStartOriginHashesCopy() const +SessionPlugInAutoStartOriginMap PlugInAutoStartProvider::autoStartOriginHashesCopy() const { - PlugInAutoStartOriginHash copyMap; - AutoStartTable::const_iterator end = m_autoStartTable.end(); - for (AutoStartTable::const_iterator it = m_autoStartTable.begin(); it != end; ++it) { - PlugInAutoStartOriginHash::const_iterator mapEnd = it->value.end(); - for (PlugInAutoStartOriginHash::const_iterator mapIt = it->value.begin(); mapIt != mapEnd; ++mapIt) - copyMap.set(mapIt->key, mapIt->value); + SessionPlugInAutoStartOriginMap sessionMap; + + for (const auto& sessionKeyOriginHash : m_autoStartTable) { + PlugInAutoStartOriginMap& map = sessionMap.add(sessionKeyOriginHash.key, PlugInAutoStartOriginMap()).iterator->value; + for (const auto& keyOriginHash : sessionKeyOriginHash.value) { + for (const auto& originHash : keyOriginHash.value) + map.set(originHash.key, originHash.value); + } } - return copyMap; + return sessionMap; } -PassRefPtr<ImmutableDictionary> PlugInAutoStartProvider::autoStartOriginsTableCopy() const +Ref<API::Dictionary> PlugInAutoStartProvider::autoStartOriginsTableCopy() const { - ImmutableDictionary::MapType map; - AutoStartTable::const_iterator end = m_autoStartTable.end(); + API::Dictionary::MapType map; + double now = currentTime(); - for (AutoStartTable::const_iterator it = m_autoStartTable.begin(); it != end; ++it) { - ImmutableDictionary::MapType hashMap; - PlugInAutoStartOriginHash::const_iterator valueEnd = it->value.end(); - for (PlugInAutoStartOriginHash::const_iterator valueIt = it->value.begin(); valueIt != valueEnd; ++valueIt) { - if (now > valueIt->value) - continue; - hashMap.set(String::number(valueIt->key), API::Double::create(valueIt->value)); + for (const auto& stringOriginHash : m_autoStartTable.get(SessionID::defaultSessionID())) { + API::Dictionary::MapType hashMap; + for (const auto& originHash : stringOriginHash.value) { + if (now <= originHash.value) + hashMap.set(String::number(originHash.key), API::Double::create(originHash.value)); } - if (hashMap.size()) - map.set(it->key, ImmutableDictionary::create(std::move(hashMap))); + map.set(stringOriginHash.key, API::Dictionary::create(WTFMove(hashMap))); } - return ImmutableDictionary::create(std::move(map)); + return API::Dictionary::create(WTFMove(map)); } -void PlugInAutoStartProvider::setAutoStartOriginsTable(ImmutableDictionary& table) +void PlugInAutoStartProvider::setAutoStartOriginsTable(API::Dictionary& table) { setAutoStartOriginsTableWithItemsPassingTest(table, [](double) { return true; }); } -void PlugInAutoStartProvider::setAutoStartOriginsFilteringOutEntriesAddedAfterTime(ImmutableDictionary& table, double time) +void PlugInAutoStartProvider::setAutoStartOriginsFilteringOutEntriesAddedAfterTime(API::Dictionary& table, double time) { double adjustedTimestamp = time + plugInAutoStartExpirationTimeThreshold; setAutoStartOriginsTableWithItemsPassingTest(table, [adjustedTimestamp](double expirationTimestamp) { @@ -114,66 +120,72 @@ void PlugInAutoStartProvider::setAutoStartOriginsFilteringOutEntriesAddedAfterTi }); } -void PlugInAutoStartProvider::setAutoStartOriginsTableWithItemsPassingTest(ImmutableDictionary& table, std::function<bool(double expirationTimestamp)> isExpirationTimeAcceptable) +void PlugInAutoStartProvider::setAutoStartOriginsTableWithItemsPassingTest(API::Dictionary& table, std::function<bool(double expirationTimestamp)> isExpirationTimeAcceptable) { ASSERT(isExpirationTimeAcceptable); m_hashToOriginMap.clear(); m_autoStartTable.clear(); HashMap<unsigned, double> hashMap; + HashMap<unsigned, String>& hashToOriginMap = m_hashToOriginMap.add(SessionID::defaultSessionID(), HashMap<unsigned, String>()).iterator->value; + AutoStartTable& ast = m_autoStartTable.add(SessionID::defaultSessionID(), AutoStartTable()).iterator->value; - ImmutableDictionary::MapType::const_iterator end = table.map().end(); - for (ImmutableDictionary::MapType::const_iterator it = table.map().begin(); it != end; ++it) { - PlugInAutoStartOriginHash hashes; - ImmutableDictionary* hashesForPage = static_cast<ImmutableDictionary*>(it->value.get()); - ImmutableDictionary::MapType::const_iterator hashEnd = hashesForPage->map().end(); - for (ImmutableDictionary::MapType::const_iterator hashIt = hashesForPage->map().begin(); hashIt != hashEnd; ++hashIt) { + for (auto& strDict : table.map()) { + PlugInAutoStartOriginMap hashes; + for (auto& hashTime : static_cast<API::Dictionary*>(strDict.value.get())->map()) { bool ok; - unsigned hash = hashIt->key.toUInt(&ok); + unsigned hash = hashTime.key.toUInt(&ok); if (!ok) continue; - if (hashIt->value->type() != API::Double::APIType) + if (hashTime.value->type() != API::Double::APIType) continue; - double expirationTime = static_cast<API::Double*>(hashIt->value.get())->value(); + double expirationTime = static_cast<API::Double*>(hashTime.value.get())->value(); if (!isExpirationTimeAcceptable(expirationTime)) continue; hashes.set(hash, expirationTime); hashMap.set(hash, expirationTime); - m_hashToOriginMap.set(hash, it->key); + hashToOriginMap.set(hash, strDict.key); } if (!hashes.isEmpty()) - m_autoStartTable.set(it->key, hashes); + ast.set(strDict.key, hashes); } - m_context->sendToAllProcesses(Messages::WebProcess::ResetPlugInAutoStartOriginHashes(hashMap)); + m_processPool->sendToAllProcesses(Messages::WebProcess::ResetPlugInAutoStartOriginDefaultHashes(hashMap)); } void PlugInAutoStartProvider::setAutoStartOriginsArray(API::Array& originList) { m_autoStartOrigins.clear(); - for (size_t i = 0, length = originList.size(); i < length; ++i) { - if (originList.at(i)->type() != API::String::APIType) - continue; - m_autoStartOrigins.append(static_cast<API::String*>(originList.at(i))->string()); - } + for (const auto& string : originList.elementsOfType<API::String>()) + m_autoStartOrigins.append(string->string()); } -void PlugInAutoStartProvider::didReceiveUserInteraction(unsigned plugInOriginHash) +void PlugInAutoStartProvider::didReceiveUserInteraction(unsigned plugInOriginHash, SessionID sessionID) { - HashMap<unsigned, String>::const_iterator it = m_hashToOriginMap.find(plugInOriginHash); - if (it == m_hashToOriginMap.end()) { - ASSERT_NOT_REACHED(); - return; + HashMap<WebCore::SessionID, HashMap<unsigned, String>>::const_iterator sessionIterator = m_hashToOriginMap.find(sessionID); + HashMap<unsigned, String>::const_iterator it; + bool contains = false; + if (sessionIterator != m_hashToOriginMap.end()) { + it = sessionIterator->value.find(plugInOriginHash); + contains = it != sessionIterator->value.end(); + } + if (!contains) { + sessionIterator = m_hashToOriginMap.find(SessionID::defaultSessionID()); + it = sessionIterator->value.find(plugInOriginHash); + if (it == sessionIterator->value.end()) { + ASSERT_NOT_REACHED(); + return; + } } double newExpirationTime = expirationTimeFromNow(); - m_autoStartTable.find(it->value)->value.set(plugInOriginHash, newExpirationTime); - m_context->sendToAllProcesses(Messages::WebProcess::DidAddPlugInAutoStartOriginHash(plugInOriginHash, newExpirationTime)); - m_context->client().plugInAutoStartOriginHashesChanged(m_context); + m_autoStartTable.add(sessionID, AutoStartTable()).iterator->value.add(it->value, PlugInAutoStartOriginMap()).iterator->value.set(plugInOriginHash, newExpirationTime); + m_processPool->sendToAllProcesses(Messages::WebProcess::DidAddPlugInAutoStartOriginHash(plugInOriginHash, newExpirationTime, sessionID)); + m_processPool->client().plugInAutoStartOriginHashesChanged(m_processPool); } } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/Plugins/PlugInAutoStartProvider.h b/Source/WebKit2/UIProcess/Plugins/PlugInAutoStartProvider.h index c3b390272..fe6bc6f56 100644 --- a/Source/WebKit2/UIProcess/Plugins/PlugInAutoStartProvider.h +++ b/Source/WebKit2/UIProcess/Plugins/PlugInAutoStartProvider.h @@ -26,6 +26,7 @@ #ifndef PlugInAutoStartProvider_h #define PlugInAutoStartProvider_h +#include <WebCore/SessionID.h> #include <functional> #include <wtf/HashMap.h> #include <wtf/HashSet.h> @@ -36,41 +37,43 @@ namespace API { class Array; +class Dictionary; } namespace WebKit { -class ImmutableDictionary; -class WebContext; +class WebProcessPool; -typedef HashMap<unsigned, double> PlugInAutoStartOriginHash; +typedef HashMap<unsigned, double> PlugInAutoStartOriginMap; +typedef HashMap<WebCore::SessionID, PlugInAutoStartOriginMap> SessionPlugInAutoStartOriginMap; typedef Vector<String> PlugInAutoStartOrigins; class PlugInAutoStartProvider { WTF_MAKE_NONCOPYABLE(PlugInAutoStartProvider); public: - explicit PlugInAutoStartProvider(WebContext*); + explicit PlugInAutoStartProvider(WebProcessPool*); - void addAutoStartOriginHash(const String& pageOrigin, unsigned plugInOriginHash); - void didReceiveUserInteraction(unsigned plugInOriginHash); + void addAutoStartOriginHash(const String& pageOrigin, unsigned plugInOriginHash, WebCore::SessionID); + void didReceiveUserInteraction(unsigned plugInOriginHash, WebCore::SessionID); - PassRefPtr<ImmutableDictionary> autoStartOriginsTableCopy() const; - void setAutoStartOriginsTable(ImmutableDictionary&); - void setAutoStartOriginsFilteringOutEntriesAddedAfterTime(ImmutableDictionary&, double time); + Ref<API::Dictionary> autoStartOriginsTableCopy() const; + void setAutoStartOriginsTable(API::Dictionary&); + void setAutoStartOriginsFilteringOutEntriesAddedAfterTime(API::Dictionary&, double time); void setAutoStartOriginsArray(API::Array&); - PlugInAutoStartOriginHash autoStartOriginHashesCopy() const; + SessionPlugInAutoStartOriginMap autoStartOriginHashesCopy() const; const PlugInAutoStartOrigins& autoStartOrigins() const { return m_autoStartOrigins; } private: - WebContext* m_context; + WebProcessPool* m_processPool; - void setAutoStartOriginsTableWithItemsPassingTest(ImmutableDictionary&, std::function<bool(double expirationTimestamp)>); + void setAutoStartOriginsTableWithItemsPassingTest(API::Dictionary&, std::function<bool(double expirationTimestamp)>); - typedef HashMap<String, PlugInAutoStartOriginHash, CaseFoldingHash> AutoStartTable; - AutoStartTable m_autoStartTable; + typedef HashMap<String, PlugInAutoStartOriginMap, ASCIICaseInsensitiveHash> AutoStartTable; + typedef HashMap<WebCore::SessionID, AutoStartTable> SessionAutoStartTable; + SessionAutoStartTable m_autoStartTable; - HashMap<unsigned, String> m_hashToOriginMap; + HashMap<WebCore::SessionID, HashMap<unsigned, String>> m_hashToOriginMap; PlugInAutoStartOrigins m_autoStartOrigins; }; diff --git a/Source/WebKit2/UIProcess/Plugins/PluginInfoStore.cpp b/Source/WebKit2/UIProcess/Plugins/PluginInfoStore.cpp index 0dde1a093..8a98c6201 100644 --- a/Source/WebKit2/UIProcess/Plugins/PluginInfoStore.cpp +++ b/Source/WebKit2/UIProcess/Plugins/PluginInfoStore.cpp @@ -68,7 +68,7 @@ void PluginInfoStore::loadPluginsIfNecessary() if (m_pluginListIsUpToDate) return; - ListHashSet<String, 32> uniquePluginPaths; + ListHashSet<String> uniquePluginPaths; // First, load plug-ins from the additional plug-ins directories specified. for (size_t i = 0; i < m_additionalPluginsDirectories.size(); ++i) @@ -115,15 +115,12 @@ Vector<PluginModuleInfo> PluginInfoStore::plugins() PluginModuleInfo PluginInfoStore::findPluginForMIMEType(const String& mimeType, PluginData::AllowedPluginTypes allowedPluginTypes) const { ASSERT(!mimeType.isNull()); - - for (size_t i = 0; i < m_plugins.size(); ++i) { - const PluginModuleInfo& plugin = m_plugins[i]; + for (const auto& plugin : m_plugins) { if (allowedPluginTypes == PluginData::OnlyApplicationPlugins && !plugin.info.isApplicationPlugin) continue; - - for (size_t j = 0; j < plugin.info.mimes.size(); ++j) { - const MimeClassInfo& mimeClassInfo = plugin.info.mimes[j]; + + for (const auto& mimeClassInfo : plugin.info.mimes) { if (mimeClassInfo.type == mimeType) return plugin; } @@ -135,19 +132,13 @@ PluginModuleInfo PluginInfoStore::findPluginForMIMEType(const String& mimeType, PluginModuleInfo PluginInfoStore::findPluginForExtension(const String& extension, String& mimeType, PluginData::AllowedPluginTypes allowedPluginTypes) const { ASSERT(!extension.isNull()); - - for (size_t i = 0; i < m_plugins.size(); ++i) { - const PluginModuleInfo& plugin = m_plugins[i]; + for (const auto& plugin : m_plugins) { if (allowedPluginTypes == PluginData::OnlyApplicationPlugins && !plugin.info.isApplicationPlugin) continue; - for (size_t j = 0; j < plugin.info.mimes.size(); ++j) { - const MimeClassInfo& mimeClassInfo = plugin.info.mimes[j]; - - const Vector<String>& extensions = mimeClassInfo.extensions; - - if (std::find(extensions.begin(), extensions.end(), extension) != extensions.end()) { + for (const auto& mimeClassInfo : plugin.info.mimes) { + if (mimeClassInfo.extensions.contains(extension)) { // We found a supported extension, set the correct MIME type. mimeType = mimeClassInfo.type; return plugin; @@ -163,15 +154,15 @@ static inline String pathExtension(const URL& url) String extension; String filename = url.lastPathComponent(); if (!filename.endsWith('/')) { - int extensionPos = filename.reverseFind('.'); - if (extensionPos != -1) + size_t extensionPos = filename.reverseFind('.'); + if (extensionPos != notFound) extension = filename.substring(extensionPos + 1); } - - return extension; + return extension.convertToASCIILowercase(); } -#if !PLATFORM(MAC) +#if !PLATFORM(COCOA) + PluginModuleLoadPolicy PluginInfoStore::defaultLoadPolicyForPlugin(const PluginModuleInfo&) { return PluginModuleLoadNormally; @@ -197,7 +188,7 @@ PluginModuleInfo PluginInfoStore::findPlugin(String& mimeType, const URL& url, P } // Next, check if any plug-ins claim to support the URL extension. - String extension = pathExtension(url).lower(); + String extension = pathExtension(url); if (!extension.isNull() && mimeType.isEmpty()) { PluginModuleInfo plugin = findPluginForExtension(extension, mimeType, allowedPluginTypes); if (!plugin.path.isNull()) @@ -219,11 +210,11 @@ PluginModuleInfo PluginInfoStore::findPlugin(String& mimeType, const URL& url, P PluginModuleInfo PluginInfoStore::infoForPluginWithPath(const String& pluginPath) const { - for (size_t i = 0; i < m_plugins.size(); ++i) { - if (m_plugins[i].path == pluginPath) - return m_plugins[i]; + for (const auto& plugin : m_plugins) { + if (plugin.path == pluginPath) + return plugin; } - + ASSERT_NOT_REACHED(); return PluginModuleInfo(); } diff --git a/Source/WebKit2/UIProcess/Plugins/PluginProcessManager.cpp b/Source/WebKit2/UIProcess/Plugins/PluginProcessManager.cpp index 156fb6de4..47eaa0950 100644 --- a/Source/WebKit2/UIProcess/Plugins/PluginProcessManager.cpp +++ b/Source/WebKit2/UIProcess/Plugins/PluginProcessManager.cpp @@ -29,20 +29,22 @@ #if ENABLE(NETSCAPE_PLUGIN_API) #include "PluginProcessProxy.h" -#include "WebContext.h" #include <wtf/CryptographicallyRandomNumber.h> #include <wtf/StdLibExtras.h> #include <wtf/text/WTFString.h> namespace WebKit { -PluginProcessManager& PluginProcessManager::shared() +PluginProcessManager& PluginProcessManager::singleton() { static NeverDestroyed<PluginProcessManager> pluginProcessManager; return pluginProcessManager; } PluginProcessManager::PluginProcessManager() +#if PLATFORM(COCOA) + : m_processSuppressionDisabledForPageCounter([this](bool value) { updateProcessSuppressionDisabled(value); }) +#endif { } @@ -71,7 +73,7 @@ uint64_t PluginProcessManager::pluginProcessToken(const PluginModuleInfo& plugin attributes.processType = pluginProcessType; attributes.sandboxPolicy = pluginProcessSandboxPolicy; - m_pluginProcessTokens.append(std::make_pair(std::move(attributes), token)); + m_pluginProcessTokens.append(std::make_pair(WTFMove(attributes), token)); m_knownTokens.add(token); return token; @@ -93,16 +95,24 @@ void PluginProcessManager::removePluginProcessProxy(PluginProcessProxy* pluginPr m_pluginProcesses.remove(vectorIndex); } -void PluginProcessManager::getSitesWithData(const PluginModuleInfo& plugin, WebPluginSiteDataManager* webPluginSiteDataManager, uint64_t callbackID) +void PluginProcessManager::fetchWebsiteData(const PluginModuleInfo& plugin, std::function<void (Vector<String>)> completionHandler) { PluginProcessProxy* pluginProcess = getOrCreatePluginProcess(pluginProcessToken(plugin, PluginProcessTypeNormal, PluginProcessSandboxPolicyNormal)); - pluginProcess->getSitesWithData(webPluginSiteDataManager, callbackID); + + pluginProcess->fetchWebsiteData(WTFMove(completionHandler)); +} + +void PluginProcessManager::deleteWebsiteData(const PluginModuleInfo& plugin, std::chrono::system_clock::time_point modifiedSince, std::function<void ()> completionHandler) +{ + PluginProcessProxy* pluginProcess = getOrCreatePluginProcess(pluginProcessToken(plugin, PluginProcessTypeNormal, PluginProcessSandboxPolicyNormal)); + + pluginProcess->deleteWebsiteData(modifiedSince, WTFMove(completionHandler)); } -void PluginProcessManager::clearSiteData(const PluginModuleInfo& plugin, WebPluginSiteDataManager* webPluginSiteDataManager, const Vector<String>& sites, uint64_t flags, uint64_t maxAgeInSeconds, uint64_t callbackID) +void PluginProcessManager::deleteWebsiteDataForHostNames(const PluginModuleInfo& plugin, const Vector<String>& hostNames, std::function<void ()> completionHandler) { PluginProcessProxy* pluginProcess = getOrCreatePluginProcess(pluginProcessToken(plugin, PluginProcessTypeNormal, PluginProcessSandboxPolicyNormal)); - pluginProcess->clearSiteData(webPluginSiteDataManager, sites, flags, maxAgeInSeconds, callbackID); + pluginProcess->deleteWebsiteDataForHostNames(hostNames, WTFMove(completionHandler)); } PluginProcessProxy* PluginProcessManager::getOrCreatePluginProcess(uint64_t pluginProcessToken) diff --git a/Source/WebKit2/UIProcess/Plugins/PluginProcessManager.h b/Source/WebKit2/UIProcess/Plugins/PluginProcessManager.h index 0c59a764a..8152125da 100644 --- a/Source/WebKit2/UIProcess/Plugins/PluginProcessManager.h +++ b/Source/WebKit2/UIProcess/Plugins/PluginProcessManager.h @@ -31,11 +31,13 @@ #include "PluginModuleInfo.h" #include "PluginProcess.h" #include "PluginProcessAttributes.h" +#include "ProcessThrottler.h" #include "WebProcessProxyMessages.h" #include <wtf/Forward.h> #include <wtf/HashSet.h> #include <wtf/NeverDestroyed.h> #include <wtf/Noncopyable.h> +#include <wtf/RefCounter.h> #include <wtf/Vector.h> namespace IPC { @@ -47,24 +49,26 @@ namespace WebKit { class PluginInfoStore; class PluginProcessProxy; class WebProcessProxy; -class WebPluginSiteDataManager; class PluginProcessManager { WTF_MAKE_NONCOPYABLE(PluginProcessManager); friend class NeverDestroyed<PluginProcessManager>; public: - static PluginProcessManager& shared(); + static PluginProcessManager& singleton(); uint64_t pluginProcessToken(const PluginModuleInfo&, PluginProcessType, PluginProcessSandboxPolicy); void getPluginProcessConnection(uint64_t pluginProcessToken, PassRefPtr<Messages::WebProcessProxy::GetPluginProcessConnection::DelayedReply>); void removePluginProcessProxy(PluginProcessProxy*); - void getSitesWithData(const PluginModuleInfo&, WebPluginSiteDataManager*, uint64_t callbackID); - void clearSiteData(const PluginModuleInfo&, WebPluginSiteDataManager*, const Vector<String>& sites, uint64_t flags, uint64_t maxAgeInSeconds, uint64_t callbackID); + void fetchWebsiteData(const PluginModuleInfo&, std::function<void (Vector<String>)> completionHandler); + void deleteWebsiteData(const PluginModuleInfo&, std::chrono::system_clock::time_point modifiedSince, std::function<void ()> completionHandler); + void deleteWebsiteDataForHostNames(const PluginModuleInfo&, const Vector<String>& hostNames, std::function<void ()> completionHandler); -#if PLATFORM(MAC) - void setProcessSuppressionEnabled(bool); +#if PLATFORM(COCOA) + inline ProcessSuppressionDisabledToken processSuppressionDisabledToken(); + inline bool processSuppressionDisabled() const; + void updateProcessSuppressionDisabled(bool); #endif private: @@ -76,8 +80,24 @@ private: HashSet<uint64_t> m_knownTokens; Vector<RefPtr<PluginProcessProxy>> m_pluginProcesses; + +#if PLATFORM(COCOA) + RefCounter m_processSuppressionDisabledForPageCounter; +#endif }; +#if PLATFORM(COCOA) +inline ProcessSuppressionDisabledToken PluginProcessManager::processSuppressionDisabledToken() +{ + return m_processSuppressionDisabledForPageCounter.token<ProcessSuppressionDisabledTokenType>(); +} + +inline bool PluginProcessManager::processSuppressionDisabled() const +{ + return m_processSuppressionDisabledForPageCounter.value(); +} +#endif + } // namespace WebKit #endif // ENABLE(NETSCAPE_PLUGIN_API) diff --git a/Source/WebKit2/UIProcess/Plugins/PluginProcessProxy.cpp b/Source/WebKit2/UIProcess/Plugins/PluginProcessProxy.cpp index 27772f561..8f505a675 100644 --- a/Source/WebKit2/UIProcess/Plugins/PluginProcessProxy.cpp +++ b/Source/WebKit2/UIProcess/Plugins/PluginProcessProxy.cpp @@ -32,17 +32,12 @@ #include "PluginProcessCreationParameters.h" #include "PluginProcessManager.h" #include "PluginProcessMessages.h" -#include "WebContext.h" #include "WebCoreArgumentCoders.h" -#include "WebPluginSiteDataManager.h" +#include "WebProcessPool.h" #include "WebProcessProxy.h" #include <WebCore/NotImplemented.h> #include <wtf/RunLoop.h> -#if PLATFORM(MAC) -#include "MachPort.h" -#endif - using namespace WebCore; namespace WebKit { @@ -53,9 +48,16 @@ static const double snapshottingMinimumLifetime = 30; static const double shutdownTimeout = 1 * 60; static const double snapshottingShutdownTimeout = 15; -PassRefPtr<PluginProcessProxy> PluginProcessProxy::create(PluginProcessManager* PluginProcessManager, const PluginProcessAttributes& pluginProcessAttributes, uint64_t pluginProcessToken) +static uint64_t generateCallbackID() { - return adoptRef(new PluginProcessProxy(PluginProcessManager, pluginProcessAttributes, pluginProcessToken)); + static uint64_t callbackID; + + return ++callbackID; +} + +Ref<PluginProcessProxy> PluginProcessProxy::create(PluginProcessManager* PluginProcessManager, const PluginProcessAttributes& pluginProcessAttributes, uint64_t pluginProcessToken) +{ + return adoptRef(*new PluginProcessProxy(PluginProcessManager, pluginProcessAttributes, pluginProcessToken)); } PluginProcessProxy::PluginProcessProxy(PluginProcessManager* PluginProcessManager, const PluginProcessAttributes& pluginProcessAttributes, uint64_t pluginProcessToken) @@ -63,7 +65,7 @@ PluginProcessProxy::PluginProcessProxy(PluginProcessManager* PluginProcessManage , m_pluginProcessAttributes(pluginProcessAttributes) , m_pluginProcessToken(pluginProcessToken) , m_numPendingConnectionRequests(0) -#if PLATFORM(MAC) +#if PLATFORM(COCOA) , m_modalWindowIsShowing(false) , m_fullscreenWindowIsShowing(false) , m_preFullscreenAppPresentationOptions(0) @@ -74,21 +76,30 @@ PluginProcessProxy::PluginProcessProxy(PluginProcessManager* PluginProcessManage PluginProcessProxy::~PluginProcessProxy() { + ASSERT(m_pendingFetchWebsiteDataRequests.isEmpty()); + ASSERT(m_pendingFetchWebsiteDataCallbacks.isEmpty()); + ASSERT(m_pendingDeleteWebsiteDataRequests.isEmpty()); + ASSERT(m_pendingDeleteWebsiteDataCallbacks.isEmpty()); } void PluginProcessProxy::getLaunchOptions(ProcessLauncher::LaunchOptions& launchOptions) { - launchOptions.processType = ProcessLauncher::PluginProcess; + ChildProcessProxy::getLaunchOptions(launchOptions); platformGetLaunchOptions(launchOptions, m_pluginProcessAttributes); } +void PluginProcessProxy::processWillShutDown(IPC::Connection& connection) +{ + ASSERT_UNUSED(connection, this->connection() == &connection); +} + // Asks the plug-in process to create a new connection to a web process. The connection identifier will be // encoded in the given argument encoder and sent back to the connection of the given web process. void PluginProcessProxy::getPluginProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetPluginProcessConnection::DelayedReply> reply) { m_pendingConnectionReplies.append(reply); - if (isLaunching()) { + if (state() == State::Launching) { m_numPendingConnectionRequests++; return; } @@ -98,37 +109,43 @@ void PluginProcessProxy::getPluginProcessConnection(PassRefPtr<Messages::WebProc m_connection->send(Messages::PluginProcess::CreateWebProcessConnection(), 0, IPC::DispatchMessageEvenWhenWaitingForSyncReply); } -void PluginProcessProxy::getSitesWithData(WebPluginSiteDataManager* webPluginSiteDataManager, uint64_t callbackID) +void PluginProcessProxy::fetchWebsiteData(std::function<void (Vector<String>)> completionHandler) { - ASSERT(!m_pendingGetSitesReplies.contains(callbackID)); - m_pendingGetSitesReplies.set(callbackID, webPluginSiteDataManager); + uint64_t callbackID = generateCallbackID(); + m_pendingFetchWebsiteDataCallbacks.set(callbackID, WTFMove(completionHandler)); - if (isLaunching()) { - m_pendingGetSitesRequests.append(callbackID); + if (state() == State::Launching) { + m_pendingFetchWebsiteDataRequests.append(callbackID); return; } - // Ask the plug-in process for the sites with data. m_connection->send(Messages::PluginProcess::GetSitesWithData(callbackID), 0); } -void PluginProcessProxy::clearSiteData(WebPluginSiteDataManager* webPluginSiteDataManager, const Vector<String>& sites, uint64_t flags, uint64_t maxAgeInSeconds, uint64_t callbackID) +void PluginProcessProxy::deleteWebsiteData(std::chrono::system_clock::time_point modifiedSince, std::function<void ()> completionHandler) { - ASSERT(!m_pendingClearSiteDataReplies.contains(callbackID)); - m_pendingClearSiteDataReplies.set(callbackID, webPluginSiteDataManager); - - if (isLaunching()) { - ClearSiteDataRequest request; - request.sites = sites; - request.flags = flags; - request.maxAgeInSeconds = maxAgeInSeconds; - request.callbackID = callbackID; - m_pendingClearSiteDataRequests.append(request); + uint64_t callbackID = generateCallbackID(); + m_pendingDeleteWebsiteDataCallbacks.set(callbackID, WTFMove(completionHandler)); + + if (state() == State::Launching) { + m_pendingDeleteWebsiteDataRequests.append({ modifiedSince, callbackID }); return; } - // Ask the plug-in process to clear the site data. - m_connection->send(Messages::PluginProcess::ClearSiteData(sites, flags, maxAgeInSeconds, callbackID), 0); + m_connection->send(Messages::PluginProcess::DeleteWebsiteData(modifiedSince, callbackID), 0); +} + +void PluginProcessProxy::deleteWebsiteDataForHostNames(const Vector<String>& hostNames, std::function<void ()> completionHandler) +{ + uint64_t callbackID = generateCallbackID(); + m_pendingDeleteWebsiteDataForHostNamesCallbacks.set(callbackID, WTFMove(completionHandler)); + + if (state() == State::Launching) { + m_pendingDeleteWebsiteDataForHostNamesRequests.append({ hostNames, callbackID }); + return; + } + + m_connection->send(Messages::PluginProcess::DeleteWebsiteDataForHostNames(hostNames, callbackID), 0); } void PluginProcessProxy::pluginProcessCrashedOrFailedToLaunch() @@ -137,28 +154,37 @@ void PluginProcessProxy::pluginProcessCrashedOrFailedToLaunch() while (!m_pendingConnectionReplies.isEmpty()) { RefPtr<Messages::WebProcessProxy::GetPluginProcessConnection::DelayedReply> reply = m_pendingConnectionReplies.takeFirst(); -#if PLATFORM(MAC) - reply->send(IPC::Attachment(0, MACH_MSG_TYPE_MOVE_SEND), false); -#elif USE(UNIX_DOMAIN_SOCKETS) +#if USE(UNIX_DOMAIN_SOCKETS) reply->send(IPC::Attachment(), false); +#elif OS(DARWIN) + reply->send(IPC::Attachment(0, MACH_MSG_TYPE_MOVE_SEND), false); #else notImplemented(); #endif } - while (!m_pendingGetSitesReplies.isEmpty()) - didGetSitesWithData(Vector<String>(), m_pendingGetSitesReplies.begin()->key); + m_pendingFetchWebsiteDataRequests.clear(); + for (const auto& callback : m_pendingFetchWebsiteDataCallbacks.values()) + callback({ }); + m_pendingFetchWebsiteDataCallbacks.clear(); + + m_pendingDeleteWebsiteDataRequests.clear(); + for (const auto& callback : m_pendingDeleteWebsiteDataCallbacks.values()) + callback(); + m_pendingDeleteWebsiteDataRequests.clear(); - while (!m_pendingClearSiteDataReplies.isEmpty()) - didClearSiteData(m_pendingClearSiteDataReplies.begin()->key); + m_pendingDeleteWebsiteDataForHostNamesRequests.clear(); + for (const auto& callback : m_pendingDeleteWebsiteDataForHostNamesCallbacks.values()) + callback(); + m_pendingDeleteWebsiteDataForHostNamesCallbacks.clear(); // Tell the plug-in process manager to forget about this plug-in process proxy. This may cause us to be deleted. m_pluginProcessManager->removePluginProcessProxy(this); } -void PluginProcessProxy::didClose(IPC::Connection*) +void PluginProcessProxy::didClose(IPC::Connection&) { -#if PLATFORM(MAC) +#if PLATFORM(COCOA) if (m_modalWindowIsShowing) endModal(); @@ -166,15 +192,15 @@ void PluginProcessProxy::didClose(IPC::Connection*) exitFullscreen(); #endif - const Vector<WebContext*>& contexts = WebContext::allContexts(); - for (size_t i = 0; i < contexts.size(); ++i) - contexts[i]->sendToAllProcesses(Messages::PluginProcessConnectionManager::PluginProcessCrashed(m_pluginProcessToken)); + const Vector<WebProcessPool*>& processPools = WebProcessPool::allProcessPools(); + for (size_t i = 0; i < processPools.size(); ++i) + processPools[i]->sendToAllProcesses(Messages::PluginProcessConnectionManager::PluginProcessCrashed(m_pluginProcessToken)); // This will cause us to be deleted. pluginProcessCrashedOrFailedToLaunch(); } -void PluginProcessProxy::didReceiveInvalidMessage(IPC::Connection*, IPC::StringReference, IPC::StringReference) +void PluginProcessProxy::didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference, IPC::StringReference) { } @@ -187,8 +213,8 @@ void PluginProcessProxy::didFinishLaunching(ProcessLauncher*, IPC::Connection::I return; } - m_connection = IPC::Connection::createServerConnection(connectionIdentifier, this, RunLoop::main()); -#if PLATFORM(MAC) + m_connection = IPC::Connection::createServerConnection(connectionIdentifier, *this); +#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED <= 101000 m_connection->setShouldCloseConnectionOnMachExceptions(); #endif @@ -208,28 +234,29 @@ void PluginProcessProxy::didFinishLaunching(ProcessLauncher*, IPC::Connection::I // Initialize the plug-in host process. m_connection->send(Messages::PluginProcess::InitializePluginProcess(parameters), 0); -#if PLATFORM(MAC) +#if PLATFORM(COCOA) m_connection->send(Messages::PluginProcess::SetQOS(pluginProcessLatencyQOS(), pluginProcessThroughputQOS()), 0); #endif - // Send all our pending requests. - for (size_t i = 0; i < m_pendingGetSitesRequests.size(); ++i) - m_connection->send(Messages::PluginProcess::GetSitesWithData(m_pendingGetSitesRequests[i]), 0); - m_pendingGetSitesRequests.clear(); + for (auto callbackID : m_pendingFetchWebsiteDataRequests) + m_connection->send(Messages::PluginProcess::GetSitesWithData(callbackID), 0); + m_pendingFetchWebsiteDataRequests.clear(); - for (size_t i = 0; i < m_pendingClearSiteDataRequests.size(); ++i) { - const ClearSiteDataRequest& request = m_pendingClearSiteDataRequests[i]; - m_connection->send(Messages::PluginProcess::ClearSiteData(request.sites, request.flags, request.maxAgeInSeconds, request.callbackID), 0); - } - m_pendingClearSiteDataRequests.clear(); + for (auto& request : m_pendingDeleteWebsiteDataRequests) + m_connection->send(Messages::PluginProcess::DeleteWebsiteData(request.modifiedSince, request.callbackID), 0); + m_pendingDeleteWebsiteDataRequests.clear(); + + for (auto& request : m_pendingDeleteWebsiteDataForHostNamesRequests) + m_connection->send(Messages::PluginProcess::DeleteWebsiteDataForHostNames(request.hostNames, request.callbackID), 0); + m_pendingDeleteWebsiteDataForHostNamesRequests.clear(); for (unsigned i = 0; i < m_numPendingConnectionRequests; ++i) m_connection->send(Messages::PluginProcess::CreateWebProcessConnection(), 0); m_numPendingConnectionRequests = 0; -#if PLATFORM(MAC) - if (WebContext::processSuppressionIsEnabledForAllContexts()) +#if PLATFORM(COCOA) + if (!PluginProcessManager::singleton().processSuppressionDisabled()) setProcessSuppressionEnabled(true); #endif } @@ -241,10 +268,10 @@ void PluginProcessProxy::didCreateWebProcessConnection(const IPC::Attachment& co // Grab the first pending connection reply. RefPtr<Messages::WebProcessProxy::GetPluginProcessConnection::DelayedReply> reply = m_pendingConnectionReplies.takeFirst(); -#if PLATFORM(MAC) - reply->send(IPC::Attachment(connectionIdentifier.port(), MACH_MSG_TYPE_MOVE_SEND), supportsAsynchronousPluginInitialization); -#elif USE(UNIX_DOMAIN_SOCKETS) +#if USE(UNIX_DOMAIN_SOCKETS) reply->send(connectionIdentifier, supportsAsynchronousPluginInitialization); +#elif OS(DARWIN) + reply->send(IPC::Attachment(connectionIdentifier.port(), MACH_MSG_TYPE_MOVE_SEND), supportsAsynchronousPluginInitialization); #else notImplemented(); #endif @@ -252,18 +279,20 @@ void PluginProcessProxy::didCreateWebProcessConnection(const IPC::Attachment& co void PluginProcessProxy::didGetSitesWithData(const Vector<String>& sites, uint64_t callbackID) { - RefPtr<WebPluginSiteDataManager> webPluginSiteDataManager = m_pendingGetSitesReplies.take(callbackID); - ASSERT(webPluginSiteDataManager); + auto callback = m_pendingFetchWebsiteDataCallbacks.take(callbackID); + callback(sites); +} - webPluginSiteDataManager->didGetSitesWithDataForSinglePlugin(sites, callbackID); +void PluginProcessProxy::didDeleteWebsiteData(uint64_t callbackID) +{ + auto callback = m_pendingDeleteWebsiteDataCallbacks.take(callbackID); + callback(); } -void PluginProcessProxy::didClearSiteData(uint64_t callbackID) +void PluginProcessProxy::didDeleteWebsiteDataForHostNames(uint64_t callbackID) { - RefPtr<WebPluginSiteDataManager> webPluginSiteDataManager = m_pendingClearSiteDataReplies.take(callbackID); - ASSERT(webPluginSiteDataManager); - - webPluginSiteDataManager->didClearSiteDataForSinglePlugin(callbackID); + auto callback = m_pendingDeleteWebsiteDataForHostNamesCallbacks.take(callbackID); + callback(); } } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/Plugins/PluginProcessProxy.h b/Source/WebKit2/UIProcess/Plugins/PluginProcessProxy.h index 484a20c29..b43b78353 100644 --- a/Source/WebKit2/UIProcess/Plugins/PluginProcessProxy.h +++ b/Source/WebKit2/UIProcess/Plugins/PluginProcessProxy.h @@ -37,21 +37,15 @@ #include "WebProcessProxyMessages.h" #include <wtf/Deque.h> -#if PLATFORM(MAC) +#if PLATFORM(COCOA) #include <wtf/RetainPtr.h> OBJC_CLASS NSObject; OBJC_CLASS WKPlaceholderModalWindow; #endif -// FIXME: This is platform specific. -namespace IPC { - class MachPort; -} - namespace WebKit { class PluginProcessManager; -class WebPluginSiteDataManager; class WebProcessProxy; struct PluginProcessCreationParameters; @@ -60,17 +54,21 @@ struct RawPluginMetaData { String name; String description; String mimeDescription; + +#if PLATFORM(GTK) + bool requiresGtk2; +#endif }; #endif -#if PLATFORM(MAC) +#if PLATFORM(COCOA) int pluginProcessLatencyQOS(); int pluginProcessThroughputQOS(); #endif class PluginProcessProxy : public ChildProcessProxy { public: - static PassRefPtr<PluginProcessProxy> create(PluginProcessManager*, const PluginProcessAttributes&, uint64_t pluginProcessToken); + static Ref<PluginProcessProxy> create(PluginProcessManager*, const PluginProcessAttributes&, uint64_t pluginProcessToken); ~PluginProcessProxy(); const PluginProcessAttributes& pluginProcessAttributes() const { return m_pluginProcessAttributes; } @@ -79,25 +77,23 @@ public: // Asks the plug-in process to create a new connection to a web process. The connection identifier will be // encoded in the given argument encoder and sent back to the connection of the given web process. void getPluginProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetPluginProcessConnection::DelayedReply>); - - // Asks the plug-in process to get a list of domains for which the plug-in has data stored. - void getSitesWithData(WebPluginSiteDataManager*, uint64_t callbackID); - // Asks the plug-in process to clear the data for the given sites. - void clearSiteData(WebPluginSiteDataManager*, const Vector<String>& sites, uint64_t flags, uint64_t maxAgeInSeconds, uint64_t callbackID); + void fetchWebsiteData(std::function<void (Vector<String>)> completionHandler); + void deleteWebsiteData(std::chrono::system_clock::time_point modifiedSince, std::function<void ()> completionHandler); + void deleteWebsiteDataForHostNames(const Vector<String>& hostNames, std::function<void ()> completionHandler); bool isValid() const { return m_connection; } -#if PLATFORM(MAC) +#if PLATFORM(COCOA) void setProcessSuppressionEnabled(bool); - // Returns whether the plug-in needs the heap to be marked executable. - static bool pluginNeedsExecutableHeap(const PluginModuleInfo&); - +#if __MAC_OS_X_VERSION_MIN_REQUIRED <= 101000 // Creates a property list in ~/Library/Preferences that contains all the MIME types supported by the plug-in. static bool createPropertyListFile(const PluginModuleInfo&); #endif +#endif + #if PLUGIN_ARCHITECTURE(X11) static bool scanPlugin(const String& pluginPath, RawPluginMetaData& result); #endif @@ -107,25 +103,29 @@ private: virtual void getLaunchOptions(ProcessLauncher::LaunchOptions&) override; void platformGetLaunchOptions(ProcessLauncher::LaunchOptions&, const PluginProcessAttributes&); + virtual void processWillShutDown(IPC::Connection&) override; void pluginProcessCrashedOrFailedToLaunch(); // IPC::Connection::Client - virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; - virtual void didReceiveSyncMessage(IPC::Connection*, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override; + virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override; + virtual void didReceiveSyncMessage(IPC::Connection&, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override; - virtual void didClose(IPC::Connection*) override; - virtual void didReceiveInvalidMessage(IPC::Connection*, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override; + virtual void didClose(IPC::Connection&) override; + virtual void didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override; + virtual IPC::ProcessType localProcessType() override { return IPC::ProcessType::UI; } + virtual IPC::ProcessType remoteProcessType() override { return IPC::ProcessType::Plugin; } // ProcessLauncher::Client - virtual void didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier); + virtual void didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier) override; // Message handlers void didCreateWebProcessConnection(const IPC::Attachment&, bool supportsAsynchronousPluginInitialization); void didGetSitesWithData(const Vector<String>& sites, uint64_t callbackID); - void didClearSiteData(uint64_t callbackID); + void didDeleteWebsiteData(uint64_t callbackID); + void didDeleteWebsiteDataForHostNames(uint64_t callbackID); -#if PLATFORM(MAC) +#if PLATFORM(COCOA) bool getPluginProcessSerialNumber(ProcessSerialNumber&); void makePluginProcessTheFrontProcess(); void makeUIProcessTheFrontProcess(); @@ -139,7 +139,6 @@ private: void endModal(); void applicationDidBecomeActive(); - void openPluginPreferencePane(); void launchProcess(const String& launchPath, const Vector<String>& arguments, bool& result); void launchApplicationAtURL(const String& urlString, const Vector<String>& arguments, bool& result); void openURL(const String& url, bool& result, int32_t& status, String& launchedURLString); @@ -159,23 +158,28 @@ private: Deque<RefPtr<Messages::WebProcessProxy::GetPluginProcessConnection::DelayedReply>> m_pendingConnectionReplies; - Vector<uint64_t> m_pendingGetSitesRequests; - HashMap<uint64_t, RefPtr<WebPluginSiteDataManager>> m_pendingGetSitesReplies; + Vector<uint64_t> m_pendingFetchWebsiteDataRequests; + HashMap<uint64_t, std::function<void (Vector<String>)>> m_pendingFetchWebsiteDataCallbacks; + + struct DeleteWebsiteDataRequest { + std::chrono::system_clock::time_point modifiedSince; + uint64_t callbackID; + }; + Vector<DeleteWebsiteDataRequest> m_pendingDeleteWebsiteDataRequests; + HashMap<uint64_t, std::function<void ()>> m_pendingDeleteWebsiteDataCallbacks; - struct ClearSiteDataRequest { - Vector<String> sites; - uint64_t flags; - uint64_t maxAgeInSeconds; + struct DeleteWebsiteDataForHostNamesRequest { + Vector<String> hostNames; uint64_t callbackID; }; - Vector<ClearSiteDataRequest> m_pendingClearSiteDataRequests; - HashMap<uint64_t, RefPtr<WebPluginSiteDataManager>> m_pendingClearSiteDataReplies; + Vector<DeleteWebsiteDataForHostNamesRequest> m_pendingDeleteWebsiteDataForHostNamesRequests; + HashMap<uint64_t, std::function<void ()>> m_pendingDeleteWebsiteDataForHostNamesCallbacks; // If createPluginConnection is called while the process is still launching we'll keep count of it and send a bunch of requests // when the process finishes launching. unsigned m_numPendingConnectionRequests; -#if PLATFORM(MAC) +#if PLATFORM(COCOA) RetainPtr<NSObject> m_activationObserver; RetainPtr<WKPlaceholderModalWindow *> m_placeholderWindow; bool m_modalWindowIsShowing; diff --git a/Source/WebKit2/UIProcess/Plugins/PluginProcessProxy.messages.in b/Source/WebKit2/UIProcess/Plugins/PluginProcessProxy.messages.in index 25afc5d67..e18e55eb0 100644 --- a/Source/WebKit2/UIProcess/Plugins/PluginProcessProxy.messages.in +++ b/Source/WebKit2/UIProcess/Plugins/PluginProcessProxy.messages.in @@ -26,15 +26,13 @@ messages -> PluginProcessProxy { DidCreateWebProcessConnection(IPC::Attachment connectionIdentifier, bool supportsAsynchronousPluginInitialization) DidGetSitesWithData(Vector<String> sites, uint64_t callbackID) - DidClearSiteData(uint64_t callbackID) + DidDeleteWebsiteData(uint64_t callbackID) + DidDeleteWebsiteDataForHostNames(uint64_t callbackID) -#if PLATFORM(MAC) +#if PLATFORM(COCOA) SetModalWindowIsShowing(bool modalWindowIsShowing) SetFullscreenWindowIsShowing(bool fullscreenWindowIsShowing) - # Open the plug-ins preference pane (as specified in the plug-in's Info.plist file). - OpenPluginPreferencePane() - # Returns true if the UI process launched the process. LaunchProcess(String launchPath, Vector<String> arguments) -> (bool result) diff --git a/Source/WebKit2/UIProcess/Plugins/WebPluginSiteDataManager.cpp b/Source/WebKit2/UIProcess/Plugins/WebPluginSiteDataManager.cpp deleted file mode 100644 index acfa80241..000000000 --- a/Source/WebKit2/UIProcess/Plugins/WebPluginSiteDataManager.cpp +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "WebPluginSiteDataManager.h" - -#if ENABLE(NETSCAPE_PLUGIN_API) - -#include "APIArray.h" -#include "PluginProcessManager.h" -#include "WebContext.h" -#include "WebProcessMessages.h" - -using namespace WebCore; - -namespace WebKit { - -class WebPluginSiteDataManager::GetSitesWithDataState { -public: - explicit GetSitesWithDataState(WebPluginSiteDataManager* webPluginSiteDataManager, uint64_t callbackID) - : m_webPluginSiteDataManager(webPluginSiteDataManager) - , m_callbackID(callbackID) - , m_plugins(webPluginSiteDataManager->m_webContext->pluginInfoStore().plugins()) - { - } - - void getSitesWithDataForNextPlugin() - { - if (m_plugins.isEmpty()) { - Vector<String> sites; - copyToVector(m_sites, sites); - - m_webPluginSiteDataManager->didGetSitesWithDataForAllPlugins(sites, m_callbackID); - return; - } - - PluginProcessManager::shared().getSitesWithData(m_plugins.last(), m_webPluginSiteDataManager, m_callbackID); - m_plugins.removeLast(); - } - - void didGetSitesWithDataForSinglePlugin(const Vector<String>& sites) - { - for (size_t i = 0; i < sites.size(); ++i) - m_sites.add(sites[i]); - - getSitesWithDataForNextPlugin(); - } - -private: - WebPluginSiteDataManager* m_webPluginSiteDataManager; - uint64_t m_callbackID; - Vector<PluginModuleInfo> m_plugins; - HashSet<String> m_sites; -}; - -class WebPluginSiteDataManager::ClearSiteDataState { -public: - explicit ClearSiteDataState(WebPluginSiteDataManager* webPluginSiteDataManager, const Vector<String>& sites, uint64_t flags, uint64_t maxAgeInSeconds, uint64_t callbackID) - : m_webPluginSiteDataManager(webPluginSiteDataManager) - , m_sites(sites) - , m_flags(flags) - , m_maxAgeInSeconds(maxAgeInSeconds) - , m_callbackID(callbackID) - , m_plugins(webPluginSiteDataManager->m_webContext->pluginInfoStore().plugins()) - { - } - - void clearSiteDataForNextPlugin() - { - if (m_plugins.isEmpty()) { - m_webPluginSiteDataManager->didClearSiteDataForAllPlugins(m_callbackID); - return; - } - - PluginProcessManager::shared().clearSiteData(m_plugins.last(), m_webPluginSiteDataManager, m_sites, m_flags, m_maxAgeInSeconds, m_callbackID); - m_plugins.removeLast(); - } - - void didClearSiteDataForSinglePlugin() - { - clearSiteDataForNextPlugin(); - } - -private: - WebPluginSiteDataManager* m_webPluginSiteDataManager; - Vector<String> m_sites; - uint64_t m_flags; - uint64_t m_maxAgeInSeconds; - uint64_t m_callbackID; - Vector<PluginModuleInfo> m_plugins; -}; - -PassRefPtr<WebPluginSiteDataManager> WebPluginSiteDataManager::create(WebContext* webContext) -{ - return adoptRef(new WebPluginSiteDataManager(webContext)); -} - -WebPluginSiteDataManager::WebPluginSiteDataManager(WebContext* webContext) - : m_webContext(webContext) -{ -} - -WebPluginSiteDataManager::~WebPluginSiteDataManager() -{ - ASSERT(m_arrayCallbacks.isEmpty()); - ASSERT(m_voidCallbacks.isEmpty()); - ASSERT(m_pendingGetSitesWithData.isEmpty()); - ASSERT(m_pendingClearSiteData.isEmpty()); -} - -void WebPluginSiteDataManager::invalidate() -{ - invalidateCallbackMap(m_arrayCallbacks); - - m_pendingGetSitesWithData.clear(); - m_pendingClearSiteData.clear(); -} - -void WebPluginSiteDataManager::getSitesWithData(PassRefPtr<ArrayCallback> prpCallback) -{ - RefPtr<ArrayCallback> callback = prpCallback; - - if (!m_webContext) { - callback->invalidate(); - return; - } - - uint64_t callbackID = callback->callbackID(); - m_arrayCallbacks.set(callbackID, callback.release()); - - ASSERT(!m_pendingGetSitesWithData.contains(callbackID)); - - GetSitesWithDataState* state = new GetSitesWithDataState(this, callbackID); - m_pendingGetSitesWithData.set(callbackID, adoptPtr(state)); - state->getSitesWithDataForNextPlugin(); -} - -void WebPluginSiteDataManager::didGetSitesWithData(const Vector<String>& sites, uint64_t callbackID) -{ - RefPtr<ArrayCallback> callback = m_arrayCallbacks.take(callbackID); - if (!callback) { - // FIXME: Log error or assert. - return; - } - - callback->performCallbackWithReturnValue(API::Array::createStringArray(sites).get()); -} - -void WebPluginSiteDataManager::clearSiteData(API::Array* sites, uint64_t flags, uint64_t maxAgeInSeconds, PassRefPtr<VoidCallback> prpCallback) -{ - RefPtr<VoidCallback> callback = prpCallback; - if (!m_webContext) { - callback->invalidate(); - return; - } - - Vector<String> sitesVector; - - // If the array is empty, don't do anything. - if (sites) { - if (!sites->size()) { - callback->performCallback(); - return; - } - - for (size_t i = 0; i < sites->size(); ++i) { - if (API::String* site = sites->at<API::String>(i)) - sitesVector.append(site->string()); - } - } - - uint64_t callbackID = callback->callbackID(); - m_voidCallbacks.set(callbackID, callback.release()); - - ASSERT(!m_pendingClearSiteData.contains(callbackID)); - - ClearSiteDataState* state = new ClearSiteDataState(this, sitesVector, flags, maxAgeInSeconds, callbackID); - m_pendingClearSiteData.set(callbackID, adoptPtr(state)); - state->clearSiteDataForNextPlugin(); -} - -void WebPluginSiteDataManager::didClearSiteData(uint64_t callbackID) -{ - RefPtr<VoidCallback> callback = m_voidCallbacks.take(callbackID); - if (!callback) { - // FIXME: Log error or assert. - return; - } - - callback->performCallback(); -} - -void WebPluginSiteDataManager::didGetSitesWithDataForSinglePlugin(const Vector<String>& sites, uint64_t callbackID) -{ - GetSitesWithDataState* state = m_pendingGetSitesWithData.get(callbackID); - ASSERT(state); - - state->didGetSitesWithDataForSinglePlugin(sites); -} - -void WebPluginSiteDataManager::didGetSitesWithDataForAllPlugins(const Vector<String>& sites, uint64_t callbackID) -{ - OwnPtr<GetSitesWithDataState> state = m_pendingGetSitesWithData.take(callbackID); - ASSERT(state); - - didGetSitesWithData(sites, callbackID); -} - -void WebPluginSiteDataManager::didClearSiteDataForSinglePlugin(uint64_t callbackID) -{ - ClearSiteDataState* state = m_pendingClearSiteData.get(callbackID); - ASSERT(state); - - state->didClearSiteDataForSinglePlugin(); -} - -void WebPluginSiteDataManager::didClearSiteDataForAllPlugins(uint64_t callbackID) -{ - OwnPtr<ClearSiteDataState> state = m_pendingClearSiteData.take(callbackID); - ASSERT(state); - - didClearSiteData(callbackID); -} - -} // namespace WebKit - -#endif // ENABLE(NETSCAPE_PLUGIN_API) diff --git a/Source/WebKit2/UIProcess/Plugins/WebPluginSiteDataManager.h b/Source/WebKit2/UIProcess/Plugins/WebPluginSiteDataManager.h deleted file mode 100644 index f6918f959..000000000 --- a/Source/WebKit2/UIProcess/Plugins/WebPluginSiteDataManager.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef WebPluginSiteDataManager_h -#define WebPluginSiteDataManager_h - -#if ENABLE(NETSCAPE_PLUGIN_API) - -#include "APIObject.h" -#include "Arguments.h" -#include "GenericCallback.h" -#include <wtf/HashMap.h> -#include <wtf/PassRefPtr.h> - -namespace WebKit { - -class WebContext; -class WebProcessProxy; - -typedef GenericCallback<WKArrayRef> ArrayCallback; - -class WebPluginSiteDataManager : public API::ObjectImpl<API::Object::Type::PluginSiteDataManager> { -public: - static PassRefPtr<WebPluginSiteDataManager> create(WebContext*); - virtual ~WebPluginSiteDataManager(); - - void invalidate(); - void clearContext() { m_webContext = 0; } - - void getSitesWithData(PassRefPtr<ArrayCallback>); - void didGetSitesWithData(const Vector<String>& sites, uint64_t callbackID); - - void clearSiteData(API::Array* sites, uint64_t flags, uint64_t maxAgeInSeconds, PassRefPtr<VoidCallback>); - void didClearSiteData(uint64_t callbackID); - - void didGetSitesWithDataForSinglePlugin(const Vector<String>& sites, uint64_t callbackID); - void didClearSiteDataForSinglePlugin(uint64_t callbackID); - -private: - explicit WebPluginSiteDataManager(WebContext*); - - WebContext* m_webContext; - HashMap<uint64_t, RefPtr<ArrayCallback>> m_arrayCallbacks; - HashMap<uint64_t, RefPtr<VoidCallback>> m_voidCallbacks; - - void didGetSitesWithDataForAllPlugins(const Vector<String>& sites, uint64_t callbackID); - void didClearSiteDataForAllPlugins(uint64_t callbackID); - - class GetSitesWithDataState; - HashMap<uint64_t, OwnPtr<GetSitesWithDataState>> m_pendingGetSitesWithData; - - class ClearSiteDataState; - HashMap<uint64_t, OwnPtr<ClearSiteDataState>> m_pendingClearSiteData; -}; - -} // namespace WebKit - -#endif // ENABLE(NETSCAPE_PLUGIN_API) - -#endif // WebPluginSiteDataManager_h diff --git a/Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.cpp b/Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.cpp index c6e46524d..93450335f 100644 --- a/Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.cpp +++ b/Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.cpp @@ -34,9 +34,9 @@ namespace WebKit { -static const unsigned gSchemaVersion = 1; +static const unsigned gSchemaVersion = 2; -PluginInfoCache& PluginInfoCache::shared() +PluginInfoCache& PluginInfoCache::singleton() { static NeverDestroyed<PluginInfoCache> pluginInfoCache; return pluginInfoCache; @@ -44,9 +44,11 @@ PluginInfoCache& PluginInfoCache::shared() PluginInfoCache::PluginInfoCache() : m_cacheFile(g_key_file_new()) - , m_saveToFileIdleId(0) + , m_saveToFileIdle(RunLoop::main(), this, &PluginInfoCache::saveToFile) , m_readOnlyMode(false) { + m_saveToFileIdle.setPriority(G_PRIORITY_DEFAULT_IDLE); + GUniquePtr<char> cacheDirectory(g_build_filename(g_get_user_cache_dir(), "webkitgtk", nullptr)); if (WebCore::makeAllDirectories(cacheDirectory.get())) { m_cachePath.reset(g_build_filename(cacheDirectory.get(), "plugins", nullptr)); @@ -72,23 +74,10 @@ PluginInfoCache::PluginInfoCache() PluginInfoCache::~PluginInfoCache() { - if (m_saveToFileIdleId) { - g_source_remove(m_saveToFileIdleId); - saveToFile(); - } -} - -gboolean PluginInfoCache::saveToFileIdleCallback(PluginInfoCache* cache) -{ - cache->saveToFile(); - return FALSE; } void PluginInfoCache::saveToFile() { - std::lock_guard<std::mutex> lock(m_mutex); - m_saveToFileIdleId = 0; - gsize dataLength; GUniquePtr<char> data(g_key_file_to_data(m_cacheFile.get(), &dataLength, nullptr)); if (!data) @@ -124,6 +113,8 @@ bool PluginInfoCache::getPluginInfo(const String& pluginPath, PluginModuleInfo& NetscapePluginModule::parseMIMEDescription(String::fromUTF8(stringValue.get()), plugin.info.mimes); #endif + plugin.requiresGtk2 = g_key_file_get_boolean(m_cacheFile.get(), pluginGroup.data(), "requires-gtk2", nullptr); + return true; } @@ -143,14 +134,15 @@ void PluginInfoCache::updatePluginInfo(const String& pluginPath, const PluginMod g_key_file_set_string(m_cacheFile.get(), pluginGroup.data(), "mime-description", mimeDescription.utf8().data()); #endif + g_key_file_set_boolean(m_cacheFile.get(), pluginGroup.data(), "requires-gtk2", plugin.requiresGtk2); + if (m_cachePath && !m_readOnlyMode) { // Save the cache file in an idle to make sure it happens in the main thread and // it's done only once when this is called multiple times in a very short time. - std::lock_guard<std::mutex> lock(m_mutex); - if (m_saveToFileIdleId) + if (m_saveToFileIdle.isActive()) return; - m_saveToFileIdleId = g_idle_add(reinterpret_cast<GSourceFunc>(PluginInfoCache::saveToFileIdleCallback), this); + m_saveToFileIdle.startOneShot(0); } } diff --git a/Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.h b/Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.h index 872f1eb01..1af7085e2 100644 --- a/Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.h +++ b/Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.h @@ -29,9 +29,9 @@ #if ENABLE(NETSCAPE_PLUGIN_API) #include "PluginModuleInfo.h" -#include <mutex> #include <wtf/NeverDestroyed.h> -#include <wtf/gobject/GUniquePtr.h> +#include <wtf/RunLoop.h> +#include <wtf/glib/GUniquePtr.h> namespace WebKit { @@ -39,7 +39,7 @@ class PluginInfoCache { WTF_MAKE_NONCOPYABLE(PluginInfoCache); friend class NeverDestroyed<PluginInfoCache>; public: - static PluginInfoCache& shared(); + static PluginInfoCache& singleton(); bool getPluginInfo(const String& pluginPath, PluginModuleInfo&); void updatePluginInfo(const String& pluginPath, const PluginModuleInfo&); @@ -49,13 +49,11 @@ private: ~PluginInfoCache(); void saveToFile(); - static gboolean saveToFileIdleCallback(PluginInfoCache*); GUniquePtr<GKeyFile> m_cacheFile; GUniquePtr<char> m_cachePath; - unsigned m_saveToFileIdleId; + RunLoop::Timer<PluginInfoCache> m_saveToFileIdle; bool m_readOnlyMode; - std::mutex m_mutex; }; } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/Plugins/unix/PluginInfoStoreUnix.cpp b/Source/WebKit2/UIProcess/Plugins/unix/PluginInfoStoreUnix.cpp index a9685618f..cfe9bd7b4 100644 --- a/Source/WebKit2/UIProcess/Plugins/unix/PluginInfoStoreUnix.cpp +++ b/Source/WebKit2/UIProcess/Plugins/unix/PluginInfoStoreUnix.cpp @@ -32,7 +32,7 @@ #include "PluginInfoStore.h" #include "NetscapePluginModule.h" -#include "PluginDatabase.h" +#include "PluginSearchPath.h" #include <WebCore/FileSystem.h> #if PLATFORM(GTK) @@ -45,41 +45,7 @@ namespace WebKit { Vector<String> PluginInfoStore::pluginsDirectories() { - Vector<String> result; - - result.append(homeDirectoryPath() + "/.mozilla/plugins"); - result.append(homeDirectoryPath() + "/.netscape/plugins"); - result.append("/usr/lib/browser/plugins"); - result.append("/usr/local/lib/mozilla/plugins"); - result.append("/usr/lib/firefox/plugins"); - result.append("/usr/lib64/browser-plugins"); - result.append("/usr/lib/browser-plugins"); - result.append("/usr/lib/mozilla/plugins"); - result.append("/usr/local/netscape/plugins"); - result.append("/opt/mozilla/plugins"); - result.append("/opt/mozilla/lib/plugins"); - result.append("/opt/netscape/plugins"); - result.append("/opt/netscape/communicator/plugins"); - result.append("/usr/lib/netscape/plugins"); - result.append("/usr/lib/netscape/plugins-libc5"); - result.append("/usr/lib/netscape/plugins-libc6"); - result.append("/usr/lib64/netscape/plugins"); - result.append("/usr/lib64/mozilla/plugins"); - result.append("/usr/lib/nsbrowser/plugins"); - result.append("/usr/lib64/nsbrowser/plugins"); - - String mozillaHome(getenv("MOZILLA_HOME")); - if (!mozillaHome.isEmpty()) - result.append(mozillaHome + "/plugins"); - - String mozillaPaths(getenv("MOZ_PLUGIN_PATH")); - if (!mozillaPaths.isEmpty()) { - Vector<String> paths; - mozillaPaths.split(UChar(':'), /* allowEmptyEntries */ false, paths); - result.appendVector(paths); - } - - return result; + return WebKit::pluginsDirectories(); } Vector<String> PluginInfoStore::pluginPathsInDirectory(const String& directory) @@ -103,11 +69,11 @@ Vector<String> PluginInfoStore::individualPluginPaths() bool PluginInfoStore::getPluginInfo(const String& pluginPath, PluginModuleInfo& plugin) { #if PLATFORM(GTK) - if (PluginInfoCache::shared().getPluginInfo(pluginPath, plugin)) + if (PluginInfoCache::singleton().getPluginInfo(pluginPath, plugin)) return true; if (NetscapePluginModule::getPluginInfo(pluginPath, plugin)) { - PluginInfoCache::shared().updatePluginInfo(pluginPath, plugin); + PluginInfoCache::singleton().updatePluginInfo(pluginPath, plugin); return true; } return false; diff --git a/Source/WebKit2/UIProcess/Plugins/unix/PluginProcessProxyUnix.cpp b/Source/WebKit2/UIProcess/Plugins/unix/PluginProcessProxyUnix.cpp index 18e15864f..8569450ba 100644 --- a/Source/WebKit2/UIProcess/Plugins/unix/PluginProcessProxyUnix.cpp +++ b/Source/WebKit2/UIProcess/Plugins/unix/PluginProcessProxyUnix.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 Igalia S.L. + * Copyright (C) 2011, 2014 Igalia S.L. * Copyright (C) 2011 Apple Inc. * Copyright (C) 2012 Samsung Electronics * @@ -33,14 +33,18 @@ #include "PluginProcessCreationParameters.h" #include "ProcessExecutablePath.h" #include <WebCore/FileSystem.h> +#include <sys/wait.h> #include <wtf/text/CString.h> #include <wtf/text/WTFString.h> + #if PLATFORM(GTK) || PLATFORM(EFL) #include <glib.h> -#include <wtf/gobject/GUniquePtr.h> +#include <wtf/glib/GUniquePtr.h> #endif -#include <sys/wait.h> +#if PLATFORM(GTK) +#include "Module.h" +#endif using namespace WebCore; @@ -48,33 +52,52 @@ namespace WebKit { void PluginProcessProxy::platformGetLaunchOptions(ProcessLauncher::LaunchOptions& launchOptions, const PluginProcessAttributes& pluginProcessAttributes) { -#if PLATFORM(EFL) && !defined(NDEBUG) - const char* commandPrefix = getenv("PLUGIN_PROCESS_COMMAND_PREFIX"); - if (commandPrefix && *commandPrefix) - launchOptions.processCmdPrefix = String::fromUTF8(commandPrefix); -#endif + launchOptions.processType = ProcessLauncher::ProcessType::Plugin64; launchOptions.extraInitializationData.add("plugin-path", pluginProcessAttributes.moduleInfo.path); +#if PLATFORM(GTK) + if (pluginProcessAttributes.moduleInfo.requiresGtk2) + launchOptions.extraInitializationData.add("requires-gtk2", emptyString()); +#endif } void PluginProcessProxy::platformInitializePluginProcess(PluginProcessCreationParameters&) { } +#if PLATFORM(GTK) +static bool pluginRequiresGtk2(const String& pluginPath) +{ + std::unique_ptr<Module> module = std::make_unique<Module>(pluginPath); + if (!module->load()) + return false; + return module->functionPointer<gpointer>("gtk_object_get_type"); +} +#endif + #if PLUGIN_ARCHITECTURE(X11) bool PluginProcessProxy::scanPlugin(const String& pluginPath, RawPluginMetaData& result) { #if PLATFORM(GTK) || PLATFORM(EFL) - CString binaryPath = fileSystemRepresentation(executablePathOfPluginProcess()); + String pluginProcessPath = executablePathOfPluginProcess(); + +#if PLATFORM(GTK) + bool requiresGtk2 = pluginRequiresGtk2(pluginPath); + if (requiresGtk2) +#if ENABLE(PLUGIN_PROCESS_GTK2) + pluginProcessPath.append('2'); +#else + return false; +#endif +#endif + + CString binaryPath = fileSystemRepresentation(pluginProcessPath); CString pluginPathCString = fileSystemRepresentation(pluginPath); char* argv[4]; argv[0] = const_cast<char*>(binaryPath.data()); argv[1] = const_cast<char*>("-scanPlugin"); argv[2] = const_cast<char*>(pluginPathCString.data()); - argv[3] = 0; - - int status; - GUniqueOutPtr<char> stdOut; + argv[3] = nullptr; // If the disposition of SIGCLD signal is set to SIG_IGN (default) // then the signal will be ignored and g_spawn_sync() will not be @@ -90,23 +113,38 @@ bool PluginProcessProxy::scanPlugin(const String& pluginPath, RawPluginMetaData& } #endif - if (!g_spawn_sync(0, argv, 0, G_SPAWN_STDERR_TO_DEV_NULL, 0, 0, &stdOut.outPtr(), 0, &status, 0)) + int status; + GUniqueOutPtr<char> stdOut; + GUniqueOutPtr<GError> error; + if (!g_spawn_sync(nullptr, argv, nullptr, G_SPAWN_STDERR_TO_DEV_NULL, nullptr, nullptr, &stdOut.outPtr(), nullptr, &status, &error.outPtr())) { + WTFLogAlways("Failed to launch %s: %s", argv[0], error->message); return false; + } - if (!WIFEXITED(status) || WEXITSTATUS(status) != EXIT_SUCCESS || !stdOut) + if (!WIFEXITED(status) || WEXITSTATUS(status) != EXIT_SUCCESS) { + WTFLogAlways("Error scanning plugin %s, %s returned %d exit status", argv[2], argv[0], status); return false; + } - String stdOutString = String::fromUTF8(stdOut.get()); + if (!stdOut) { + WTFLogAlways("Error scanning plugin %s, %s didn't write any output to stdout", argv[2], argv[0]); + return false; + } Vector<String> lines; - stdOutString.split(UChar('\n'), true, lines); + String::fromUTF8(stdOut.get()).split(UChar('\n'), true, lines); - if (lines.size() < 3) + if (lines.size() < 3) { + WTFLogAlways("Error scanning plugin %s, too few lines of output provided", argv[2]); return false; + } result.name.swap(lines[0]); result.description.swap(lines[1]); result.mimeDescription.swap(lines[2]); +#if PLATFORM(GTK) + result.requiresGtk2 = requiresGtk2; +#endif return !result.mimeDescription.isEmpty(); #else // PLATFORM(GTK) || PLATFORM(EFL) return false; diff --git a/Source/WebKit2/UIProcess/ProcessAssertion.cpp b/Source/WebKit2/UIProcess/ProcessAssertion.cpp new file mode 100644 index 000000000..e0279bd8a --- /dev/null +++ b/Source/WebKit2/UIProcess/ProcessAssertion.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ProcessAssertion.h" + +#if !PLATFORM(IOS) + +namespace WebKit { + +ProcessAssertion::ProcessAssertion(pid_t, AssertionState assertionState) + : m_assertionState(assertionState) +{ +} + +ProcessAssertion::~ProcessAssertion() +{ +} + +void ProcessAssertion::setState(AssertionState assertionState) +{ + if (m_assertionState == assertionState) + return; + + m_assertionState = assertionState; +} + +ProcessAndUIAssertion::ProcessAndUIAssertion(pid_t pid, AssertionState assertionState) + : ProcessAssertion(pid, assertionState) +{ +} + +ProcessAndUIAssertion::~ProcessAndUIAssertion() +{ +} + +void ProcessAndUIAssertion::setState(AssertionState assertionState) +{ + ProcessAssertion::setState(assertionState); +} + +void ProcessAndUIAssertion::setClient(ProcessAssertionClient& client) +{ + ProcessAssertion::setClient(client); +} + +} + +#endif // !PLATFORM(IOS) diff --git a/Source/WebKit2/UIProcess/ProcessAssertion.h b/Source/WebKit2/UIProcess/ProcessAssertion.h new file mode 100644 index 000000000..95c97c13e --- /dev/null +++ b/Source/WebKit2/UIProcess/ProcessAssertion.h @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ProcessAssertion_h +#define ProcessAssertion_h + +#if PLATFORM(IOS) && !PLATFORM(IOS_SIMULATOR) +#include <wtf/RetainPtr.h> +OBJC_CLASS BKSProcessAssertion; +#endif + +namespace WebKit { + +enum class AssertionState { + Suspended, + Background, + Foreground +}; + +class ProcessAssertionClient { +public: + virtual ~ProcessAssertionClient() { }; + virtual void assertionWillExpireImminently() = 0; +}; + +class ProcessAssertion { +public: + ProcessAssertion(pid_t, AssertionState); + ~ProcessAssertion(); + + void setClient(ProcessAssertionClient& client) { m_client = &client; } + ProcessAssertionClient* client() { return m_client; } + + AssertionState state() const { return m_assertionState; } + void setState(AssertionState); + +private: +#if PLATFORM(IOS) && !PLATFORM(IOS_SIMULATOR) + RetainPtr<BKSProcessAssertion> m_assertion; +#endif + AssertionState m_assertionState; + ProcessAssertionClient* m_client { nullptr }; +}; + +class ProcessAndUIAssertion : public ProcessAssertion { +public: + ProcessAndUIAssertion(pid_t, AssertionState); + ~ProcessAndUIAssertion(); + + void setClient(ProcessAssertionClient&); + + void setState(AssertionState); +}; + +} + +#endif // ProcessAssertion_h diff --git a/Source/WebKit2/UIProcess/ProcessThrottler.cpp b/Source/WebKit2/UIProcess/ProcessThrottler.cpp new file mode 100644 index 000000000..b4b017960 --- /dev/null +++ b/Source/WebKit2/UIProcess/ProcessThrottler.cpp @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO , PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ProcessThrottler.h" + +#include "ProcessThrottlerClient.h" + +namespace WebKit { + +static const unsigned processSuspensionTimeout = 30; + +ProcessThrottler::ProcessThrottler(ProcessThrottlerClient& process) + : m_process(process) + , m_suspendTimer(RunLoop::main(), this, &ProcessThrottler::suspendTimerFired) + , m_foregroundCounter([this](bool) { updateAssertion(); }) + , m_backgroundCounter([this](bool) { updateAssertion(); }) + , m_suspendMessageCount(0) +{ +} + +AssertionState ProcessThrottler::assertionState() +{ + ASSERT(!m_suspendTimer.isActive()); + + if (m_foregroundCounter.value()) + return AssertionState::Foreground; + if (m_backgroundCounter.value()) + return AssertionState::Background; + return AssertionState::Suspended; +} + +void ProcessThrottler::updateAssertionNow() +{ + m_suspendTimer.stop(); + if (m_assertion) { + m_assertion->setState(assertionState()); + m_process.didSetAssertionState(assertionState()); + } +} + +void ProcessThrottler::updateAssertion() +{ + // If the process is currently runnable but will be suspended then first give it a chance to complete what it was doing + // and clean up - move it to the background and send it a message to notify. Schedule a timeout so it can't stay running + // in the background for too long. + if (m_assertion && m_assertion->state() != AssertionState::Suspended && !m_foregroundCounter.value() && !m_backgroundCounter.value()) { + ++m_suspendMessageCount; + m_process.sendPrepareToSuspend(); + m_suspendTimer.startOneShot(processSuspensionTimeout); + m_assertion->setState(AssertionState::Background); + m_process.didSetAssertionState(AssertionState::Background); + return; + } + + bool shouldBeRunnable = m_foregroundCounter.value() || m_backgroundCounter.value(); + + // If we're currently waiting for the Web process to do suspension cleanup, but no longer need to be suspended, tell the Web process to cancel the cleanup. + if (m_suspendTimer.isActive() && shouldBeRunnable) + m_process.sendCancelPrepareToSuspend(); + + if (m_assertion && m_assertion->state() == AssertionState::Suspended && shouldBeRunnable) + m_process.sendProcessDidResume(); + + updateAssertionNow(); +} + +void ProcessThrottler::didConnectToProcess(pid_t pid) +{ + m_suspendTimer.stop(); + m_assertion = std::make_unique<ProcessAndUIAssertion>(pid, assertionState()); + m_process.didSetAssertionState(assertionState()); + m_assertion->setClient(*this); +} + +void ProcessThrottler::suspendTimerFired() +{ + updateAssertionNow(); +} + +void ProcessThrottler::processReadyToSuspend() +{ + if (!--m_suspendMessageCount) + updateAssertionNow(); + ASSERT(m_suspendMessageCount >= 0); +} + +void ProcessThrottler::didCancelProcessSuspension() +{ + if (!--m_suspendMessageCount) + updateAssertionNow(); + ASSERT(m_suspendMessageCount >= 0); +} + +void ProcessThrottler::assertionWillExpireImminently() +{ + m_process.sendProcessWillSuspendImminently(); +} + +} diff --git a/Source/WebKit2/UIProcess/ProcessThrottler.h b/Source/WebKit2/UIProcess/ProcessThrottler.h new file mode 100644 index 000000000..3878d0ae8 --- /dev/null +++ b/Source/WebKit2/UIProcess/ProcessThrottler.h @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ProcessThrottler_h +#define ProcessThrottler_h + +#include "ProcessAssertion.h" + +#include <wtf/RefCounter.h> +#include <wtf/RunLoop.h> +#include <wtf/WeakPtr.h> + +namespace WebKit { + +enum UserObservablePageTokenType { }; +typedef RefCounter::Token<UserObservablePageTokenType> UserObservablePageToken; +enum ProcessSuppressionDisabledTokenType { }; +typedef RefCounter::Token<ProcessSuppressionDisabledTokenType> ProcessSuppressionDisabledToken; + +class ProcessThrottlerClient; + +class ProcessThrottler : private ProcessAssertionClient { +public: + enum ForegroundActivityTokenType { }; + typedef RefCounter::Token<ForegroundActivityTokenType> ForegroundActivityToken; + enum BackgroundActivityTokenType { }; + typedef RefCounter::Token<BackgroundActivityTokenType> BackgroundActivityToken; + + ProcessThrottler(ProcessThrottlerClient&); + + inline ForegroundActivityToken foregroundActivityToken() const; + inline BackgroundActivityToken backgroundActivityToken() const; + + void didConnectToProcess(pid_t); + void processReadyToSuspend(); + void didCancelProcessSuspension(); + +private: + AssertionState assertionState(); + void updateAssertion(); + void updateAssertionNow(); + void suspendTimerFired(); + + // ProcessAssertionClient + void assertionWillExpireImminently() override; + + ProcessThrottlerClient& m_process; + std::unique_ptr<ProcessAndUIAssertion> m_assertion; + RunLoop::Timer<ProcessThrottler> m_suspendTimer; + RefCounter m_foregroundCounter; + RefCounter m_backgroundCounter; + int m_suspendMessageCount; +}; + +inline ProcessThrottler::ForegroundActivityToken ProcessThrottler::foregroundActivityToken() const +{ + return ForegroundActivityToken(m_foregroundCounter.token<ForegroundActivityTokenType>()); +} + +inline ProcessThrottler::BackgroundActivityToken ProcessThrottler::backgroundActivityToken() const +{ + return BackgroundActivityToken(m_backgroundCounter.token<BackgroundActivityTokenType>()); +} + +} + +#endif // ProcessThrottler_h diff --git a/Source/WebKit2/UIProcess/ProcessThrottlerClient.h b/Source/WebKit2/UIProcess/ProcessThrottlerClient.h new file mode 100644 index 000000000..75ab75726 --- /dev/null +++ b/Source/WebKit2/UIProcess/ProcessThrottlerClient.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ProcessThrottlerClient_h +#define ProcessThrottlerClient_h + +#include "ProcessAssertion.h" + +namespace WebKit { + +class ProcessThrottlerClient { +public: + virtual ~ProcessThrottlerClient() { } + + virtual void sendProcessWillSuspendImminently() = 0; + virtual void sendPrepareToSuspend() = 0; + virtual void sendCancelPrepareToSuspend() = 0; + virtual void sendProcessDidResume() = 0; + + virtual void didSetAssertionState(AssertionState) = 0; +}; + +} // namespace WebKit + +#endif // ProcessThrottlerClient_h + diff --git a/Source/WebKit2/UIProcess/ResponsivenessTimer.cpp b/Source/WebKit2/UIProcess/ResponsivenessTimer.cpp index 9739fa3a1..c3cc981ad 100644 --- a/Source/WebKit2/UIProcess/ResponsivenessTimer.cpp +++ b/Source/WebKit2/UIProcess/ResponsivenessTimer.cpp @@ -30,7 +30,7 @@ namespace WebKit { static const double responsivenessTimeout = 3; -ResponsivenessTimer::ResponsivenessTimer(ResponsivenessTimer::Client* client) +ResponsivenessTimer::ResponsivenessTimer(ResponsivenessTimer::Client& client) : m_client(client) , m_isResponsive(true) , m_timer(RunLoop::main(), this, &ResponsivenessTimer::timerFired) @@ -49,13 +49,14 @@ void ResponsivenessTimer::invalidate() void ResponsivenessTimer::timerFired() { - if (m_isResponsive) { - m_isResponsive = false; - m_client->didBecomeUnresponsive(this); - } else { - // The timer fired while unresponsive. - m_client->interactionOccurredWhileUnresponsive(this); - } + if (!m_isResponsive) + return; + + m_client.willChangeIsResponsive(); + m_isResponsive = false; + m_client.didChangeIsResponsive(); + + m_client.didBecomeUnresponsive(); } void ResponsivenessTimer::start() @@ -69,12 +70,21 @@ void ResponsivenessTimer::start() void ResponsivenessTimer::stop() { if (!m_isResponsive) { - // We got a life sign from the web process! - m_client->didBecomeResponsive(this); + // We got a life sign from the web process. + m_client.willChangeIsResponsive(); m_isResponsive = true; + m_client.didChangeIsResponsive(); + + m_client.didBecomeResponsive(); } m_timer.stop(); } +void ResponsivenessTimer::processTerminated() +{ + // Since there is no web process, we must not be waiting for it anymore. + stop(); +} + } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/ResponsivenessTimer.h b/Source/WebKit2/UIProcess/ResponsivenessTimer.h index f75c0a998..6d2bd4e3b 100644 --- a/Source/WebKit2/UIProcess/ResponsivenessTimer.h +++ b/Source/WebKit2/UIProcess/ResponsivenessTimer.h @@ -35,12 +35,14 @@ public: class Client { public: virtual ~Client() { } - virtual void didBecomeUnresponsive(ResponsivenessTimer*) = 0; - virtual void interactionOccurredWhileUnresponsive(ResponsivenessTimer*) = 0; - virtual void didBecomeResponsive(ResponsivenessTimer*) = 0; + virtual void didBecomeUnresponsive() = 0; + virtual void didBecomeResponsive() = 0; + + virtual void willChangeIsResponsive() = 0; + virtual void didChangeIsResponsive() = 0; }; - explicit ResponsivenessTimer(ResponsivenessTimer::Client*); + explicit ResponsivenessTimer(ResponsivenessTimer::Client&); ~ResponsivenessTimer(); void start(); @@ -50,10 +52,12 @@ public: bool isResponsive() { return m_isResponsive; } + void processTerminated(); + private: void timerFired(); - ResponsivenessTimer::Client* m_client; + ResponsivenessTimer::Client& m_client; bool m_isResponsive; RunLoop::Timer<ResponsivenessTimer> m_timer; diff --git a/Source/WebKit2/UIProcess/Scrolling/RemoteScrollingCoordinatorProxy.cpp b/Source/WebKit2/UIProcess/Scrolling/RemoteScrollingCoordinatorProxy.cpp new file mode 100644 index 000000000..4b4373320 --- /dev/null +++ b/Source/WebKit2/UIProcess/Scrolling/RemoteScrollingCoordinatorProxy.cpp @@ -0,0 +1,192 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "RemoteScrollingCoordinatorProxy.h" + +#if ENABLE(ASYNC_SCROLLING) + +#include "ArgumentCoders.h" +#include "MessageDecoder.h" +#include "MessageEncoder.h" +#include "RemoteLayerTreeDrawingAreaProxy.h" +#include "RemoteScrollingCoordinator.h" +#include "RemoteScrollingCoordinatorMessages.h" +#include "RemoteScrollingCoordinatorTransaction.h" +#include "WebPageProxy.h" +#include "WebProcessProxy.h" +#include <WebCore/ScrollingStateFrameScrollingNode.h> +#include <WebCore/ScrollingStateOverflowScrollingNode.h> +#include <WebCore/ScrollingStateTree.h> +#include <WebCore/ScrollingTreeScrollingNode.h> + +using namespace WebCore; + +namespace WebKit { + +RemoteScrollingCoordinatorProxy::RemoteScrollingCoordinatorProxy(WebPageProxy& webPageProxy) + : m_webPageProxy(webPageProxy) + , m_scrollingTree(RemoteScrollingTree::create(*this)) + , m_requestedScrollInfo(nullptr) + , m_propagatesMainFrameScrolls(true) +{ +} + +RemoteScrollingCoordinatorProxy::~RemoteScrollingCoordinatorProxy() +{ +} + +ScrollingNodeID RemoteScrollingCoordinatorProxy::rootScrollingNodeID() const +{ + if (!m_scrollingTree->rootNode()) + return 0; + + return m_scrollingTree->rootNode()->scrollingNodeID(); +} + +const RemoteLayerTreeHost* RemoteScrollingCoordinatorProxy::layerTreeHost() const +{ + DrawingAreaProxy* drawingArea = m_webPageProxy.drawingArea(); + if (!is<RemoteLayerTreeDrawingAreaProxy>(drawingArea)) { + ASSERT_NOT_REACHED(); + return nullptr; + } + + RemoteLayerTreeDrawingAreaProxy& remoteDrawingArea = downcast<RemoteLayerTreeDrawingAreaProxy>(*drawingArea); + return &remoteDrawingArea.remoteLayerTreeHost(); +} + +void RemoteScrollingCoordinatorProxy::updateScrollingTree(const RemoteScrollingCoordinatorTransaction& transaction, RequestedScrollInfo& requestedScrollInfo) +{ + m_requestedScrollInfo = &requestedScrollInfo; + + // FIXME: There must be a better idiom for this. + std::unique_ptr<ScrollingStateTree> stateTree(const_cast<RemoteScrollingCoordinatorTransaction&>(transaction).scrollingStateTree().release()); + + const RemoteLayerTreeHost* layerTreeHost = this->layerTreeHost(); + if (!layerTreeHost) { + ASSERT_NOT_REACHED(); + return; + } + + connectStateNodeLayers(*stateTree, *layerTreeHost); + m_scrollingTree->commitNewTreeState(WTFMove(stateTree)); + + m_requestedScrollInfo = nullptr; +} + +#if !PLATFORM(IOS) +void RemoteScrollingCoordinatorProxy::connectStateNodeLayers(ScrollingStateTree& stateTree, const RemoteLayerTreeHost& layerTreeHost) +{ + for (auto& currNode : stateTree.nodeMap().values()) { + if (currNode->hasChangedProperty(ScrollingStateNode::ScrollLayer)) + currNode->setLayer(layerTreeHost.getLayer(currNode->layer())); + + switch (currNode->nodeType()) { + case FrameScrollingNode: { + ScrollingStateFrameScrollingNode& scrollingStateNode = downcast<ScrollingStateFrameScrollingNode>(*currNode); + + if (scrollingStateNode.hasChangedProperty(ScrollingStateFrameScrollingNode::ScrolledContentsLayer)) + scrollingStateNode.setScrolledContentsLayer(layerTreeHost.getLayer(scrollingStateNode.scrolledContentsLayer())); + + if (scrollingStateNode.hasChangedProperty(ScrollingStateFrameScrollingNode::CounterScrollingLayer)) + scrollingStateNode.setCounterScrollingLayer(layerTreeHost.getLayer(scrollingStateNode.counterScrollingLayer())); + + if (scrollingStateNode.hasChangedProperty(ScrollingStateFrameScrollingNode::InsetClipLayer)) + scrollingStateNode.setInsetClipLayer(layerTreeHost.getLayer(scrollingStateNode.insetClipLayer())); + + if (scrollingStateNode.hasChangedProperty(ScrollingStateFrameScrollingNode::ContentShadowLayer)) + scrollingStateNode.setContentShadowLayer(layerTreeHost.getLayer(scrollingStateNode.contentShadowLayer())); + + // FIXME: we should never have header and footer layers coming from the WebProcess. + if (scrollingStateNode.hasChangedProperty(ScrollingStateFrameScrollingNode::HeaderLayer)) + scrollingStateNode.setHeaderLayer(layerTreeHost.getLayer(scrollingStateNode.headerLayer())); + + if (scrollingStateNode.hasChangedProperty(ScrollingStateFrameScrollingNode::FooterLayer)) + scrollingStateNode.setFooterLayer(layerTreeHost.getLayer(scrollingStateNode.footerLayer())); + break; + } + case OverflowScrollingNode: { + ScrollingStateOverflowScrollingNode& scrollingStateNode = downcast<ScrollingStateOverflowScrollingNode>(*currNode); + + if (scrollingStateNode.hasChangedProperty(ScrollingStateOverflowScrollingNode::ScrolledContentsLayer)) + scrollingStateNode.setScrolledContentsLayer(layerTreeHost.getLayer(scrollingStateNode.scrolledContentsLayer())); + break; + } + case FixedNode: + case StickyNode: + break; + } + } +} +#endif + +bool RemoteScrollingCoordinatorProxy::handleWheelEvent(const PlatformWheelEvent& event) +{ + ScrollingTree::EventResult result = m_scrollingTree->tryToHandleWheelEvent(event); + return result == ScrollingTree::DidHandleEvent; // FIXME: handle other values. +} + +bool RemoteScrollingCoordinatorProxy::isPointInNonFastScrollableRegion(const IntPoint& p) const +{ + return m_scrollingTree->isPointInNonFastScrollableRegion(p); +} + +void RemoteScrollingCoordinatorProxy::viewportChangedViaDelegatedScrolling(ScrollingNodeID nodeID, const FloatRect& fixedPositionRect, double scale) +{ + m_scrollingTree->viewportChangedViaDelegatedScrolling(nodeID, fixedPositionRect, scale); +} + +void RemoteScrollingCoordinatorProxy::currentSnapPointIndicesDidChange(WebCore::ScrollingNodeID nodeID, unsigned horizontal, unsigned vertical) +{ + m_webPageProxy.send(Messages::RemoteScrollingCoordinator::CurrentSnapPointIndicesChangedForNode(nodeID, horizontal, vertical)); +} + +// This comes from the scrolling tree. +void RemoteScrollingCoordinatorProxy::scrollingTreeNodeDidScroll(ScrollingNodeID scrolledNodeID, const FloatPoint& newScrollPosition, SetOrSyncScrollingLayerPosition scrollingLayerPositionAction) +{ + // Scroll updates for the main frame are sent via WebPageProxy::updateVisibleContentRects() + // so don't send them here. + if (!m_propagatesMainFrameScrolls && scrolledNodeID == rootScrollingNodeID()) + return; + +#if PLATFORM(IOS) + m_webPageProxy.overflowScrollViewDidScroll(); +#endif + m_webPageProxy.send(Messages::RemoteScrollingCoordinator::ScrollPositionChangedForNode(scrolledNodeID, newScrollPosition, scrollingLayerPositionAction)); +} + +void RemoteScrollingCoordinatorProxy::scrollingTreeNodeRequestsScroll(ScrollingNodeID scrolledNodeID, const FloatPoint& scrollPosition, bool representsProgrammaticScroll) +{ + if (scrolledNodeID == rootScrollingNodeID() && m_requestedScrollInfo) { + m_requestedScrollInfo->requestsScrollPositionUpdate = true; + m_requestedScrollInfo->requestIsProgrammaticScroll = representsProgrammaticScroll; + m_requestedScrollInfo->requestedScrollPosition = scrollPosition; + } +} + +} // namespace WebKit + +#endif // ENABLE(ASYNC_SCROLLING) diff --git a/Source/WebKit2/UIProcess/Scrolling/RemoteScrollingCoordinatorProxy.h b/Source/WebKit2/UIProcess/Scrolling/RemoteScrollingCoordinatorProxy.h new file mode 100644 index 000000000..a7bb60fb8 --- /dev/null +++ b/Source/WebKit2/UIProcess/Scrolling/RemoteScrollingCoordinatorProxy.h @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2014-2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef RemoteScrollingCoordinatorProxy_h +#define RemoteScrollingCoordinatorProxy_h + +#if ENABLE(ASYNC_SCROLLING) + +#include "MessageReceiver.h" +#include "RemoteScrollingCoordinator.h" +#include "RemoteScrollingTree.h" +#include <wtf/Noncopyable.h> +#include <wtf/RefPtr.h> + +namespace WebCore { +class FloatPoint; +class PlatformWheelEvent; +} + +namespace WebKit { + +class RemoteLayerTreeHost; +class RemoteScrollingCoordinatorTransaction; +class RemoteScrollingTree; +class WebPageProxy; + +class RemoteScrollingCoordinatorProxy { + WTF_MAKE_NONCOPYABLE(RemoteScrollingCoordinatorProxy); +public: + explicit RemoteScrollingCoordinatorProxy(WebPageProxy&); + virtual ~RemoteScrollingCoordinatorProxy(); + + // Inform the web process that the scroll position changed (called from the scrolling tree) + void scrollingTreeNodeDidScroll(WebCore::ScrollingNodeID, const WebCore::FloatPoint& newScrollPosition, WebCore::SetOrSyncScrollingLayerPosition); + void scrollingTreeNodeRequestsScroll(WebCore::ScrollingNodeID, const WebCore::FloatPoint& scrollPosition, bool representsProgrammaticScroll); + + bool isPointInNonFastScrollableRegion(const WebCore::IntPoint&) const; + + // Called externally when native views move around. + void viewportChangedViaDelegatedScrolling(WebCore::ScrollingNodeID, const WebCore::FloatRect& fixedPositionRect, double scale); + + void currentSnapPointIndicesDidChange(WebCore::ScrollingNodeID, unsigned horizontal, unsigned vertical); + + // FIXME: expose the tree and pass this to that? + bool handleWheelEvent(const WebCore::PlatformWheelEvent&); + + WebCore::ScrollingNodeID rootScrollingNodeID() const; + + const RemoteLayerTreeHost* layerTreeHost() const; + + struct RequestedScrollInfo { + bool requestsScrollPositionUpdate { }; + bool requestIsProgrammaticScroll { }; + WebCore::FloatPoint requestedScrollPosition; + }; + void updateScrollingTree(const RemoteScrollingCoordinatorTransaction&, RequestedScrollInfo&); + + void setPropagatesMainFrameScrolls(bool propagatesMainFrameScrolls) { m_propagatesMainFrameScrolls = propagatesMainFrameScrolls; } + bool propagatesMainFrameScrolls() const { return m_propagatesMainFrameScrolls; } + bool hasFixedOrSticky() const { return m_scrollingTree->hasFixedOrSticky(); } + +#if PLATFORM(IOS) + WebCore::FloatRect customFixedPositionRect() const; + void scrollingTreeNodeWillStartPanGesture(); + void scrollingTreeNodeWillStartScroll(); + void scrollingTreeNodeDidEndScroll(); +#if ENABLE(CSS_SCROLL_SNAP) + void adjustTargetContentOffsetForSnapping(CGSize maxScrollDimensions, CGPoint velocity, CGFloat topInset, CGPoint* targetContentOffset); + bool hasActiveSnapPoint() const; + CGPoint nearestActiveContentInsetAdjustedSnapPoint(CGFloat topInset, const CGPoint&) const; + bool shouldSetScrollViewDecelerationRateFast() const; +#endif +#endif + +private: + void connectStateNodeLayers(WebCore::ScrollingStateTree&, const RemoteLayerTreeHost&); +#if ENABLE(CSS_SCROLL_SNAP) + bool shouldSnapForMainFrameScrolling(WebCore::ScrollEventAxis) const; + float closestSnapOffsetForMainFrameScrolling(WebCore::ScrollEventAxis, float scrollDestination, float velocity, unsigned& closestIndex) const; +#endif + + WebPageProxy& m_webPageProxy; + RefPtr<RemoteScrollingTree> m_scrollingTree; + RequestedScrollInfo* m_requestedScrollInfo; +#if ENABLE(CSS_SCROLL_SNAP) + unsigned m_currentHorizontalSnapPointIndex { 0 }; + unsigned m_currentVerticalSnapPointIndex { 0 }; +#endif + bool m_propagatesMainFrameScrolls; +}; + +} // namespace WebKit + +#endif // ENABLE(ASYNC_SCROLLING) + +#endif // RemoteScrollingCoordinatorProxy_h diff --git a/Source/WebKit2/UIProcess/Scrolling/RemoteScrollingTree.cpp b/Source/WebKit2/UIProcess/Scrolling/RemoteScrollingTree.cpp new file mode 100644 index 000000000..a3b9407a1 --- /dev/null +++ b/Source/WebKit2/UIProcess/Scrolling/RemoteScrollingTree.cpp @@ -0,0 +1,144 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "RemoteScrollingTree.h" + +#if ENABLE(ASYNC_SCROLLING) + +#include "RemoteLayerTreeHost.h" +#include "RemoteScrollingCoordinatorProxy.h" +#include <WebCore/ScrollingTreeFixedNode.h> +#include <WebCore/ScrollingTreeStickyNode.h> + +#if PLATFORM(IOS) +#include "ScrollingTreeOverflowScrollingNodeIOS.h" +#include <WebCore/ScrollingTreeFrameScrollingNodeIOS.h> +#else +#include <WebCore/ScrollingTreeFrameScrollingNodeMac.h> +#endif + +using namespace WebCore; + +namespace WebKit { + +Ref<RemoteScrollingTree> RemoteScrollingTree::create(RemoteScrollingCoordinatorProxy& scrollingCoordinator) +{ + return adoptRef(*new RemoteScrollingTree(scrollingCoordinator)); +} + +RemoteScrollingTree::RemoteScrollingTree(RemoteScrollingCoordinatorProxy& scrollingCoordinator) + : m_scrollingCoordinatorProxy(scrollingCoordinator) +{ +} + +RemoteScrollingTree::~RemoteScrollingTree() +{ +} + +ScrollingTree::EventResult RemoteScrollingTree::tryToHandleWheelEvent(const PlatformWheelEvent& wheelEvent) +{ + if (shouldHandleWheelEventSynchronously(wheelEvent)) + return SendToMainThread; + + if (willWheelEventStartSwipeGesture(wheelEvent)) + return DidNotHandleEvent; + + handleWheelEvent(wheelEvent); + return DidHandleEvent; +} + +#if PLATFORM(MAC) +void RemoteScrollingTree::handleWheelEventPhase(PlatformWheelEventPhase phase) +{ + // FIXME: hand off to m_scrollingCoordinatorProxy? +} +#endif + +#if PLATFORM(IOS) +WebCore::FloatRect RemoteScrollingTree::fixedPositionRect() +{ + return m_scrollingCoordinatorProxy.customFixedPositionRect(); +} + +void RemoteScrollingTree::scrollingTreeNodeWillStartPanGesture() +{ + m_scrollingCoordinatorProxy.scrollingTreeNodeWillStartPanGesture(); +} + +void RemoteScrollingTree::scrollingTreeNodeWillStartScroll() +{ + m_scrollingCoordinatorProxy.scrollingTreeNodeWillStartScroll(); +} + +void RemoteScrollingTree::scrollingTreeNodeDidEndScroll() +{ + m_scrollingCoordinatorProxy.scrollingTreeNodeDidEndScroll(); +} + +#endif + +void RemoteScrollingTree::scrollingTreeNodeDidScroll(ScrollingNodeID nodeID, const FloatPoint& scrollPosition, SetOrSyncScrollingLayerPosition scrollingLayerPositionAction) +{ + m_scrollingCoordinatorProxy.scrollingTreeNodeDidScroll(nodeID, scrollPosition, scrollingLayerPositionAction); +} + +void RemoteScrollingTree::scrollingTreeNodeRequestsScroll(ScrollingNodeID nodeID, const FloatPoint& scrollPosition, bool representsProgrammaticScroll) +{ + m_scrollingCoordinatorProxy.scrollingTreeNodeRequestsScroll(nodeID, scrollPosition, representsProgrammaticScroll); +} + +PassRefPtr<ScrollingTreeNode> RemoteScrollingTree::createScrollingTreeNode(ScrollingNodeType nodeType, ScrollingNodeID nodeID) +{ + switch (nodeType) { + case FrameScrollingNode: +#if PLATFORM(IOS) + return ScrollingTreeFrameScrollingNodeIOS::create(*this, nodeID); +#else + return ScrollingTreeFrameScrollingNodeMac::create(*this, nodeID); +#endif + case OverflowScrollingNode: +#if PLATFORM(IOS) + return ScrollingTreeOverflowScrollingNodeIOS::create(*this, nodeID); +#else + ASSERT_NOT_REACHED(); + return nullptr; +#endif + case FixedNode: + return ScrollingTreeFixedNode::create(*this, nodeID); + case StickyNode: + return ScrollingTreeStickyNode::create(*this, nodeID); + } + return nullptr; +} + +void RemoteScrollingTree::currentSnapPointIndicesDidChange(ScrollingNodeID nodeID, unsigned horizontal, unsigned vertical) +{ + m_scrollingCoordinatorProxy.currentSnapPointIndicesDidChange(nodeID, horizontal, vertical); +} + +} // namespace WebKit + +#endif // ENABLE(ASYNC_SCROLLING) diff --git a/Source/WebKit2/UIProcess/Scrolling/RemoteScrollingTree.h b/Source/WebKit2/UIProcess/Scrolling/RemoteScrollingTree.h new file mode 100644 index 000000000..cb1e930cb --- /dev/null +++ b/Source/WebKit2/UIProcess/Scrolling/RemoteScrollingTree.h @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef RemoteScrollingTree_h +#define RemoteScrollingTree_h + +#if ENABLE(ASYNC_SCROLLING) + +#include "RemoteScrollingCoordinator.h" +#include <WebCore/ScrollingConstraints.h> +#include <WebCore/ScrollingTree.h> + +namespace WebKit { + +class RemoteScrollingCoordinatorProxy; + +class RemoteScrollingTree : public WebCore::ScrollingTree { +public: + static Ref<RemoteScrollingTree> create(RemoteScrollingCoordinatorProxy&); + virtual ~RemoteScrollingTree(); + + virtual bool isRemoteScrollingTree() const override { return true; } + virtual EventResult tryToHandleWheelEvent(const WebCore::PlatformWheelEvent&) override; + + const RemoteScrollingCoordinatorProxy& scrollingCoordinatorProxy() const { return m_scrollingCoordinatorProxy; } + + virtual void scrollingTreeNodeDidScroll(WebCore::ScrollingNodeID, const WebCore::FloatPoint& scrollPosition, WebCore::SetOrSyncScrollingLayerPosition = WebCore::SyncScrollingLayerPosition) override; + virtual void scrollingTreeNodeRequestsScroll(WebCore::ScrollingNodeID, const WebCore::FloatPoint& scrollPosition, bool representsProgrammaticScroll) override; + void currentSnapPointIndicesDidChange(WebCore::ScrollingNodeID, unsigned horizontal, unsigned vertical) override; + +private: + explicit RemoteScrollingTree(RemoteScrollingCoordinatorProxy&); + +#if PLATFORM(MAC) + virtual void handleWheelEventPhase(WebCore::PlatformWheelEventPhase) override; +#endif + +#if PLATFORM(IOS) + virtual WebCore::FloatRect fixedPositionRect() override; + virtual void scrollingTreeNodeWillStartPanGesture() override; + virtual void scrollingTreeNodeWillStartScroll() override; + virtual void scrollingTreeNodeDidEndScroll() override; +#endif + + virtual PassRefPtr<WebCore::ScrollingTreeNode> createScrollingTreeNode(WebCore::ScrollingNodeType, WebCore::ScrollingNodeID) override; + + RemoteScrollingCoordinatorProxy& m_scrollingCoordinatorProxy; +}; + +} // namespace WebKit + +SPECIALIZE_TYPE_TRAITS_SCROLLING_TREE(WebKit::RemoteScrollingTree, isRemoteScrollingTree()); + +#endif // ENABLE(ASYNC_SCROLLING) + +#endif // RemoteScrollingTree_h diff --git a/Source/WebKit2/UIProcess/StatisticsRequest.cpp b/Source/WebKit2/UIProcess/StatisticsRequest.cpp index 3223da5fd..bf51d234b 100644 --- a/Source/WebKit2/UIProcess/StatisticsRequest.cpp +++ b/Source/WebKit2/UIProcess/StatisticsRequest.cpp @@ -27,7 +27,7 @@ #include "StatisticsRequest.h" #include "APIArray.h" -#include "MutableDictionary.h" +#include "APIDictionary.h" namespace WebKit { @@ -51,17 +51,17 @@ uint64_t StatisticsRequest::addOutstandingRequest() return requestID; } -static void addToDictionaryFromHashMap(MutableDictionary* dictionary, const HashMap<String, uint64_t>& map) +static void addToDictionaryFromHashMap(API::Dictionary* dictionary, const HashMap<String, uint64_t>& map) { HashMap<String, uint64_t>::const_iterator end = map.end(); for (HashMap<String, uint64_t>::const_iterator it = map.begin(); it != end; ++it) dictionary->set(it->key, RefPtr<API::UInt64>(API::UInt64::create(it->value)).get()); } -static PassRefPtr<MutableDictionary> createDictionaryFromHashMap(const HashMap<String, uint64_t>& map) +static Ref<API::Dictionary> createDictionaryFromHashMap(const HashMap<String, uint64_t>& map) { - RefPtr<MutableDictionary> result = MutableDictionary::create(); - addToDictionaryFromHashMap(result.get(), map); + Ref<API::Dictionary> result = API::Dictionary::create(); + addToDictionaryFromHashMap(result.ptr(), map); return result; } @@ -71,7 +71,7 @@ void StatisticsRequest::completedRequest(uint64_t requestID, const StatisticsDat m_outstandingRequests.remove(requestID); if (!m_responseDictionary) - m_responseDictionary = MutableDictionary::create(); + m_responseDictionary = API::Dictionary::create(); // FIXME (Multi-WebProcess) <rdar://problem/13200059>: This code overwrites any previous response data received. // When getting responses from multiple WebProcesses we need to combine items instead of clobbering them. @@ -79,9 +79,9 @@ void StatisticsRequest::completedRequest(uint64_t requestID, const StatisticsDat addToDictionaryFromHashMap(m_responseDictionary.get(), data.statisticsNumbers); if (!data.javaScriptProtectedObjectTypeCounts.isEmpty()) - m_responseDictionary->set("JavaScriptProtectedObjectTypeCounts", createDictionaryFromHashMap(data.javaScriptProtectedObjectTypeCounts).get()); + m_responseDictionary->set("JavaScriptProtectedObjectTypeCounts", createDictionaryFromHashMap(data.javaScriptProtectedObjectTypeCounts)); if (!data.javaScriptObjectTypeCounts.isEmpty()) - m_responseDictionary->set("JavaScriptObjectTypeCounts", createDictionaryFromHashMap(data.javaScriptObjectTypeCounts).get()); + m_responseDictionary->set("JavaScriptObjectTypeCounts", createDictionaryFromHashMap(data.javaScriptObjectTypeCounts)); if (!data.webCoreCacheStatistics.isEmpty()) { Vector<RefPtr<API::Object>> cacheStatistics; @@ -90,12 +90,12 @@ void StatisticsRequest::completedRequest(uint64_t requestID, const StatisticsDat for (const auto& statistic : data.webCoreCacheStatistics) cacheStatistics.uncheckedAppend(createDictionaryFromHashMap(statistic)); - m_responseDictionary->set("WebCoreCacheStatistics", API::Array::create(std::move(cacheStatistics)).get()); + m_responseDictionary->set("WebCoreCacheStatistics", API::Array::create(WTFMove(cacheStatistics))); } if (m_outstandingRequests.isEmpty()) { m_callback->performCallbackWithReturnValue(m_responseDictionary.get()); - m_callback = 0; + m_callback = nullptr; } } diff --git a/Source/WebKit2/UIProcess/StatisticsRequest.h b/Source/WebKit2/UIProcess/StatisticsRequest.h index bf9c37bbe..c5f03c887 100644 --- a/Source/WebKit2/UIProcess/StatisticsRequest.h +++ b/Source/WebKit2/UIProcess/StatisticsRequest.h @@ -35,7 +35,7 @@ namespace WebKit { struct StatisticsData; -typedef GenericCallback<WKDictionaryRef> DictionaryCallback; +typedef GenericCallback<API::Dictionary*> DictionaryCallback; enum StatisticsRequestType { StatisticsRequestTypeWebContent = 0x00000001, @@ -61,7 +61,7 @@ private: HashSet<uint64_t> m_outstandingRequests; RefPtr<DictionaryCallback> m_callback; - RefPtr<MutableDictionary> m_responseDictionary; + RefPtr<API::Dictionary> m_responseDictionary; }; } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp b/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp index 2595f074b..1367438af 100644 --- a/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp +++ b/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp @@ -27,13 +27,14 @@ #include "LocalStorageDatabase.h" #include "LocalStorageDatabaseTracker.h" -#include "WorkQueue.h" #include <WebCore/FileSystem.h> #include <WebCore/SQLiteStatement.h> #include <WebCore/SQLiteTransaction.h> #include <WebCore/SecurityOrigin.h> #include <WebCore/StorageMap.h> +#include <WebCore/SuddenTermination.h> #include <wtf/PassRefPtr.h> +#include <wtf/WorkQueue.h> #include <wtf/text/StringHash.h> #include <wtf/text/WTFString.h> @@ -45,16 +46,16 @@ static const int maximumItemsToUpdate = 100; namespace WebKit { -PassRefPtr<LocalStorageDatabase> LocalStorageDatabase::create(PassRefPtr<WorkQueue> queue, PassRefPtr<LocalStorageDatabaseTracker> tracker, PassRefPtr<SecurityOrigin> securityOrigin) +PassRefPtr<LocalStorageDatabase> LocalStorageDatabase::create(PassRefPtr<WorkQueue> queue, PassRefPtr<LocalStorageDatabaseTracker> tracker, Ref<SecurityOrigin>&& securityOrigin) { - return adoptRef(new LocalStorageDatabase(queue, tracker, securityOrigin)); + return adoptRef(new LocalStorageDatabase(queue, tracker, WTFMove(securityOrigin))); } -LocalStorageDatabase::LocalStorageDatabase(PassRefPtr<WorkQueue> queue, PassRefPtr<LocalStorageDatabaseTracker> tracker, PassRefPtr<SecurityOrigin> securityOrigin) +LocalStorageDatabase::LocalStorageDatabase(PassRefPtr<WorkQueue> queue, PassRefPtr<LocalStorageDatabaseTracker> tracker, Ref<SecurityOrigin>&& securityOrigin) : m_queue(queue) , m_tracker(tracker) - , m_securityOrigin(securityOrigin) - , m_databasePath(m_tracker->databasePath(m_securityOrigin.get())) + , m_securityOrigin(WTFMove(securityOrigin)) + , m_databasePath(m_tracker->databasePath(m_securityOrigin.ptr())) , m_failedToOpenDatabase(false) , m_didImportItems(false) , m_isClosed(false) @@ -79,7 +80,7 @@ void LocalStorageDatabase::openDatabase(DatabaseOpeningStrategy openingStrategy) } if (m_database.isOpen()) - m_tracker->didOpenDatabaseWithOrigin(m_securityOrigin.get()); + m_tracker->didOpenDatabaseWithOrigin(m_securityOrigin.ptr()); } bool LocalStorageDatabase::tryToOpenDatabase(DatabaseOpeningStrategy openingStrategy) @@ -171,7 +172,7 @@ void LocalStorageDatabase::importItems(StorageMap& storageMap) return; SQLiteStatement query(m_database, "SELECT key, value FROM ItemTable"); - if (query.prepare() != SQLResultOk) { + if (query.prepare() != SQLITE_OK) { LOG_ERROR("Unable to select items from ItemTable for local storage"); return; } @@ -179,12 +180,12 @@ void LocalStorageDatabase::importItems(StorageMap& storageMap) HashMap<String, String> items; int result = query.step(); - while (result == SQLResultRow) { + while (result == SQLITE_ROW) { items.set(query.getColumnText(0), query.getColumnBlobAsString(1)); result = query.step(); } - if (result != SQLResultDone) { + if (result != SQLITE_DONE) { LOG_ERROR("Error reading items from ItemTable for local storage"); return; } @@ -226,7 +227,7 @@ void LocalStorageDatabase::close() m_database.close(); if (isEmpty) - m_tracker->deleteDatabaseWithOrigin(m_securityOrigin.get()); + m_tracker->deleteDatabaseWithOrigin(m_securityOrigin.ptr()); } void LocalStorageDatabase::itemDidChange(const String& key, const String& value) @@ -240,8 +241,15 @@ void LocalStorageDatabase::scheduleDatabaseUpdate() if (m_didScheduleDatabaseUpdate) return; + if (!m_disableSuddenTerminationWhileWritingToLocalStorage) + m_disableSuddenTerminationWhileWritingToLocalStorage = std::make_unique<SuddenTerminationDisabler>(); + m_didScheduleDatabaseUpdate = true; - m_queue->dispatchAfter(databaseUpdateInterval, bind(&LocalStorageDatabase::updateDatabase, this)); + + RefPtr<LocalStorageDatabase> localStorageDatabase(this); + m_queue->dispatchAfter(databaseUpdateInterval, [localStorageDatabase] { + localStorageDatabase->updateDatabase(); + }); } void LocalStorageDatabase::updateDatabase() @@ -256,6 +264,8 @@ void LocalStorageDatabase::updateDatabase() if (m_changedItems.size() <= maximumItemsToUpdate) { // There are few enough changed items that we can just always write all of them. m_changedItems.swap(changedItems); + updateDatabaseWithChangedItems(changedItems); + m_disableSuddenTerminationWhileWritingToLocalStorage = nullptr; } else { for (int i = 0; i < maximumItemsToUpdate; ++i) { auto it = m_changedItems.begin(); @@ -268,9 +278,8 @@ void LocalStorageDatabase::updateDatabase() // Reschedule the update for the remaining items. scheduleDatabaseUpdate(); + updateDatabaseWithChangedItems(changedItems); } - - updateDatabaseWithChangedItems(changedItems); } void LocalStorageDatabase::updateDatabaseWithChangedItems(const HashMap<String, String>& changedItems) @@ -284,26 +293,26 @@ void LocalStorageDatabase::updateDatabaseWithChangedItems(const HashMap<String, m_shouldClearItems = false; SQLiteStatement clearStatement(m_database, "DELETE FROM ItemTable"); - if (clearStatement.prepare() != SQLResultOk) { + if (clearStatement.prepare() != SQLITE_OK) { LOG_ERROR("Failed to prepare clear statement - cannot write to local storage database"); return; } int result = clearStatement.step(); - if (result != SQLResultDone) { + if (result != SQLITE_DONE) { LOG_ERROR("Failed to clear all items in the local storage database - %i", result); return; } } SQLiteStatement insertStatement(m_database, "INSERT INTO ItemTable VALUES (?, ?)"); - if (insertStatement.prepare() != SQLResultOk) { + if (insertStatement.prepare() != SQLITE_OK) { LOG_ERROR("Failed to prepare insert statement - cannot write to local storage database"); return; } SQLiteStatement deleteStatement(m_database, "DELETE FROM ItemTable WHERE key=?"); - if (deleteStatement.prepare() != SQLResultOk) { + if (deleteStatement.prepare() != SQLITE_OK) { LOG_ERROR("Failed to prepare delete statement - cannot write to local storage database"); return; } @@ -322,7 +331,7 @@ void LocalStorageDatabase::updateDatabaseWithChangedItems(const HashMap<String, statement.bindBlob(2, it->value); int result = statement.step(); - if (result != SQLResultDone) { + if (result != SQLITE_DONE) { LOG_ERROR("Failed to update item in the local storage database - %i", result); break; } @@ -339,13 +348,13 @@ bool LocalStorageDatabase::databaseIsEmpty() return false; SQLiteStatement query(m_database, "SELECT COUNT(*) FROM ItemTable"); - if (query.prepare() != SQLResultOk) { + if (query.prepare() != SQLITE_OK) { LOG_ERROR("Unable to count number of rows in ItemTable for local storage"); return false; } int result = query.step(); - if (result != SQLResultRow) { + if (result != SQLITE_ROW) { LOG_ERROR("No results when counting number of rows in ItemTable for local storage"); return false; } diff --git a/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.h b/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.h index 1acd6b253..3340ef714 100644 --- a/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.h +++ b/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.h @@ -31,12 +31,12 @@ #include <wtf/HashMap.h> #include <wtf/RefPtr.h> #include <wtf/ThreadSafeRefCounted.h> - -class WorkQueue; +#include <wtf/WorkQueue.h> namespace WebCore { class SecurityOrigin; class StorageMap; +class SuddenTerminationDisabler; } namespace WebKit { @@ -45,7 +45,7 @@ class LocalStorageDatabaseTracker; class LocalStorageDatabase : public ThreadSafeRefCounted<LocalStorageDatabase> { public: - static PassRefPtr<LocalStorageDatabase> create(PassRefPtr<WorkQueue>, PassRefPtr<LocalStorageDatabaseTracker>, PassRefPtr<WebCore::SecurityOrigin>); + static PassRefPtr<LocalStorageDatabase> create(PassRefPtr<WorkQueue>, PassRefPtr<LocalStorageDatabaseTracker>, Ref<WebCore::SecurityOrigin>&&); ~LocalStorageDatabase(); // Will block until the import is complete. @@ -59,7 +59,7 @@ public: void close(); private: - LocalStorageDatabase(PassRefPtr<WorkQueue>, PassRefPtr<LocalStorageDatabaseTracker>, PassRefPtr<WebCore::SecurityOrigin>); + LocalStorageDatabase(PassRefPtr<WorkQueue>, PassRefPtr<LocalStorageDatabaseTracker>, Ref<WebCore::SecurityOrigin>&&); enum DatabaseOpeningStrategy { CreateIfNonExistent, @@ -80,7 +80,7 @@ private: RefPtr<WorkQueue> m_queue; RefPtr<LocalStorageDatabaseTracker> m_tracker; - RefPtr<WebCore::SecurityOrigin> m_securityOrigin; + Ref<WebCore::SecurityOrigin> m_securityOrigin; String m_databasePath; WebCore::SQLiteDatabase m_database; @@ -91,6 +91,8 @@ private: bool m_didScheduleDatabaseUpdate; bool m_shouldClearItems; HashMap<String, String> m_changedItems; + + std::unique_ptr<WebCore::SuddenTerminationDisabler> m_disableSuddenTerminationWhileWritingToLocalStorage; }; diff --git a/Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.cpp b/Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.cpp index d0f771e7c..ad81e146d 100644 --- a/Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.cpp +++ b/Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.cpp @@ -26,38 +26,39 @@ #include "config.h" #include "LocalStorageDatabaseTracker.h" -#include "WorkQueue.h" #include <WebCore/FileSystem.h> #include <WebCore/SQLiteStatement.h> #include <WebCore/SecurityOrigin.h> +#include <WebCore/TextEncoding.h> +#include <wtf/WorkQueue.h> #include <wtf/text/CString.h> using namespace WebCore; namespace WebKit { -PassRefPtr<LocalStorageDatabaseTracker> LocalStorageDatabaseTracker::create(PassRefPtr<WorkQueue> queue) +PassRefPtr<LocalStorageDatabaseTracker> LocalStorageDatabaseTracker::create(PassRefPtr<WorkQueue> queue, const String& localStorageDirectory) { - return adoptRef(new LocalStorageDatabaseTracker(queue)); + return adoptRef(new LocalStorageDatabaseTracker(queue, localStorageDirectory)); } -LocalStorageDatabaseTracker::LocalStorageDatabaseTracker(PassRefPtr<WorkQueue> queue) +LocalStorageDatabaseTracker::LocalStorageDatabaseTracker(PassRefPtr<WorkQueue> queue, const String& localStorageDirectory) : m_queue(queue) + , m_localStorageDirectory(localStorageDirectory.isolatedCopy()) { -} + ASSERT(!m_localStorageDirectory.isEmpty()); -LocalStorageDatabaseTracker::~LocalStorageDatabaseTracker() -{ + // Make sure the encoding is initialized before we start dispatching things to the queue. + UTF8Encoding(); + + RefPtr<LocalStorageDatabaseTracker> localStorageDatabaseTracker(this); + m_queue->dispatch([localStorageDatabaseTracker] { + localStorageDatabaseTracker->importOriginIdentifiers(); + }); } -void LocalStorageDatabaseTracker::setLocalStorageDirectory(const String& localStorageDirectory) +LocalStorageDatabaseTracker::~LocalStorageDatabaseTracker() { - // FIXME: We should come up with a better idiom for safely copying strings across threads. - RefPtr<StringImpl> copiedLocalStorageDirectory; - if (localStorageDirectory.impl()) - copiedLocalStorageDirectory = localStorageDirectory.impl()->isolatedCopy(); - - m_queue->dispatch(bind(&LocalStorageDatabaseTracker::setLocalStorageDirectoryInternal, this, copiedLocalStorageDirectory.release())); } String LocalStorageDatabaseTracker::databasePath(SecurityOrigin* securityOrigin) const @@ -84,19 +85,19 @@ void LocalStorageDatabaseTracker::deleteAllDatabases() return; SQLiteStatement statement(m_database, "SELECT origin, path FROM Origins"); - if (statement.prepare() != SQLResultOk) { + if (statement.prepare() != SQLITE_OK) { LOG_ERROR("Failed to prepare statement."); return; } int result; - while ((result = statement.step()) == SQLResultRow) { + while ((result = statement.step()) == SQLITE_ROW) { deleteFile(statement.getColumnText(1)); // FIXME: Call out to the client. } - if (result != SQLResultDone) + if (result != SQLITE_DONE) LOG_ERROR("Failed to read in all origins from the database."); if (m_database.isOpen()) @@ -110,7 +111,7 @@ void LocalStorageDatabaseTracker::deleteAllDatabases() return; SQLiteStatement deleteStatement(m_database, "DELETE FROM Origins"); - if (deleteStatement.prepare() != SQLResultOk) { + if (deleteStatement.prepare() != SQLITE_OK) { LOG_ERROR("Unable to prepare deletion of all origins"); return; } @@ -123,32 +124,81 @@ void LocalStorageDatabaseTracker::deleteAllDatabases() deleteEmptyDirectory(m_localStorageDirectory); } -Vector<RefPtr<WebCore::SecurityOrigin>> LocalStorageDatabaseTracker::origins() const +static Optional<time_t> fileCreationTime(const String& filePath) +{ + time_t time; + return getFileCreationTime(filePath, time) ? time : Optional<time_t>(Nullopt); +} + +static Optional<time_t> fileModificationTime(const String& filePath) +{ + time_t time; + if (!getFileModificationTime(filePath, time)) + return Nullopt; + + return time; +} + +Vector<Ref<SecurityOrigin>> LocalStorageDatabaseTracker::deleteDatabasesModifiedSince(std::chrono::system_clock::time_point time) +{ + Vector<String> originIdentifiersToDelete; + + for (const String& origin : m_origins) { + String filePath = pathForDatabaseWithOriginIdentifier(origin); + + auto modificationTime = fileModificationTime(filePath); + if (!modificationTime) + continue; + + if (modificationTime.value() >= std::chrono::system_clock::to_time_t(time)) + originIdentifiersToDelete.append(origin); + } + + Vector<Ref<SecurityOrigin>> deletedDatabaseOrigins; + deletedDatabaseOrigins.reserveInitialCapacity(originIdentifiersToDelete.size()); + + for (const auto& originIdentifier : originIdentifiersToDelete) { + removeDatabaseWithOriginIdentifier(originIdentifier); + + deletedDatabaseOrigins.uncheckedAppend(SecurityOrigin::createFromDatabaseIdentifier(originIdentifier)); + } + + return deletedDatabaseOrigins; +} + +Vector<Ref<WebCore::SecurityOrigin>> LocalStorageDatabaseTracker::origins() const { - Vector<RefPtr<SecurityOrigin>> origins; + Vector<Ref<SecurityOrigin>> origins; origins.reserveInitialCapacity(m_origins.size()); - for (HashSet<String>::const_iterator it = m_origins.begin(), end = m_origins.end(); it != end; ++it) - origins.uncheckedAppend(SecurityOrigin::createFromDatabaseIdentifier(*it)); + for (const String& origin : m_origins) + origins.uncheckedAppend(SecurityOrigin::createFromDatabaseIdentifier(origin)); return origins; } -void LocalStorageDatabaseTracker::setLocalStorageDirectoryInternal(StringImpl* localStorageDirectory) +Vector<LocalStorageDatabaseTracker::OriginDetails> LocalStorageDatabaseTracker::originDetails() { - if (m_database.isOpen()) - m_database.close(); + Vector<OriginDetails> result; + result.reserveInitialCapacity(m_origins.size()); - m_localStorageDirectory = localStorageDirectory; - m_origins.clear(); + for (const String& origin : m_origins) { + String filePath = pathForDatabaseWithOriginIdentifier(origin); + + OriginDetails details; + details.originIdentifier = origin.isolatedCopy(); + details.creationTime = fileCreationTime(filePath); + details.modificationTime = fileModificationTime(filePath); + result.uncheckedAppend(details); + } - m_queue->dispatch(bind(&LocalStorageDatabaseTracker::importOriginIdentifiers, this)); + return result; } String LocalStorageDatabaseTracker::databasePath(const String& filename) const { if (!makeAllDirectories(m_localStorageDirectory)) { - LOG_ERROR("Unabled to create LocalStorage database path %s", m_localStorageDirectory.utf8().data()); + LOG_ERROR("Unable to create LocalStorage database path %s", m_localStorageDirectory.utf8().data()); return String(); } @@ -192,17 +242,17 @@ void LocalStorageDatabaseTracker::importOriginIdentifiers() if (m_database.isOpen()) { SQLiteStatement statement(m_database, "SELECT origin FROM Origins"); - if (statement.prepare() != SQLResultOk) { + if (statement.prepare() != SQLITE_OK) { LOG_ERROR("Failed to prepare statement."); return; } int result; - while ((result = statement.step()) == SQLResultRow) + while ((result = statement.step()) == SQLITE_ROW) m_origins.add(statement.getColumnText(0)); - if (result != SQLResultDone) { + if (result != SQLITE_DONE) { LOG_ERROR("Failed to read in all origins from the database."); return; } @@ -250,7 +300,7 @@ void LocalStorageDatabaseTracker::addDatabaseWithOriginIdentifier(const String& return; SQLiteStatement statement(m_database, "INSERT INTO Origins VALUES (?, ?)"); - if (statement.prepare() != SQLResultOk) { + if (statement.prepare() != SQLITE_OK) { LOG_ERROR("Unable to establish origin '%s' in the tracker", originIdentifier.utf8().data()); return; } @@ -258,7 +308,7 @@ void LocalStorageDatabaseTracker::addDatabaseWithOriginIdentifier(const String& statement.bindText(1, originIdentifier); statement.bindText(2, databasePath); - if (statement.step() != SQLResultDone) + if (statement.step() != SQLITE_DONE) LOG_ERROR("Unable to establish origin '%s' in the tracker", originIdentifier.utf8().data()); m_origins.add(originIdentifier); @@ -277,7 +327,7 @@ void LocalStorageDatabaseTracker::removeDatabaseWithOriginIdentifier(const Strin return; SQLiteStatement deleteStatement(m_database, "DELETE FROM Origins where origin=?"); - if (deleteStatement.prepare() != SQLResultOk) { + if (deleteStatement.prepare() != SQLITE_OK) { LOG_ERROR("Unable to prepare deletion of origin '%s'", originIdentifier.ascii().data()); return; } @@ -291,7 +341,7 @@ void LocalStorageDatabaseTracker::removeDatabaseWithOriginIdentifier(const Strin m_origins.remove(originIdentifier); if (m_origins.isEmpty()) { - // There are no origins left, go ahead and delete the tracker database. + // There are no origins left; delete the tracker database. m_database.close(); deleteFile(trackerDatabasePath()); deleteEmptyDirectory(m_localStorageDirectory); @@ -306,7 +356,7 @@ String LocalStorageDatabaseTracker::pathForDatabaseWithOriginIdentifier(const St return String(); SQLiteStatement pathStatement(m_database, "SELECT path FROM Origins WHERE origin=?"); - if (pathStatement.prepare() != SQLResultOk) { + if (pathStatement.prepare() != SQLITE_OK) { LOG_ERROR("Unable to prepare selection of path for origin '%s'", originIdentifier.utf8().data()); return String(); } @@ -314,7 +364,7 @@ String LocalStorageDatabaseTracker::pathForDatabaseWithOriginIdentifier(const St pathStatement.bindText(1, originIdentifier); int result = pathStatement.step(); - if (result != SQLResultRow) + if (result != SQLITE_ROW) return String(); return pathStatement.getColumnText(0); diff --git a/Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.h b/Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.h index e16428907..04f61fd0b 100644 --- a/Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.h +++ b/Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.h @@ -28,9 +28,11 @@ #include <WebCore/SQLiteDatabase.h> #include <wtf/HashSet.h> +#include <wtf/Optional.h> #include <wtf/PassRefPtr.h> #include <wtf/RefPtr.h> #include <wtf/ThreadSafeRefCounted.h> +#include <wtf/WorkQueue.h> #include <wtf/text/StringHash.h> #include <wtf/text/WTFString.h> @@ -38,28 +40,35 @@ namespace WebCore { class SecurityOrigin; } -class WorkQueue; - namespace WebKit { +struct LocalStorageDetails; + class LocalStorageDatabaseTracker : public ThreadSafeRefCounted<LocalStorageDatabaseTracker> { public: - static PassRefPtr<LocalStorageDatabaseTracker> create(PassRefPtr<WorkQueue>); + static PassRefPtr<LocalStorageDatabaseTracker> create(PassRefPtr<WorkQueue>, const String& localStorageDirectory); ~LocalStorageDatabaseTracker(); - void setLocalStorageDirectory(const String&); String databasePath(WebCore::SecurityOrigin*) const; void didOpenDatabaseWithOrigin(WebCore::SecurityOrigin*); void deleteDatabaseWithOrigin(WebCore::SecurityOrigin*); void deleteAllDatabases(); - Vector<RefPtr<WebCore::SecurityOrigin>> origins() const; + // Returns a vector of the origins whose databases have been deleted. + Vector<Ref<WebCore::SecurityOrigin>> deleteDatabasesModifiedSince(std::chrono::system_clock::time_point); -private: - explicit LocalStorageDatabaseTracker(PassRefPtr<WorkQueue>); + Vector<Ref<WebCore::SecurityOrigin>> origins() const; - void setLocalStorageDirectoryInternal(StringImpl*); + struct OriginDetails { + String originIdentifier; + Optional<time_t> creationTime; + Optional<time_t> modificationTime; + }; + Vector<OriginDetails> originDetails(); + +private: + LocalStorageDatabaseTracker(PassRefPtr<WorkQueue>, const String& localStorageDirectory); String databasePath(const String& filename) const; String trackerDatabasePath() const; diff --git a/Source/WebKit2/UIProcess/Storage/StorageManager.cpp b/Source/WebKit2/UIProcess/Storage/StorageManager.cpp index c08acc4ad..fdc8196d4 100644 --- a/Source/WebKit2/UIProcess/Storage/StorageManager.cpp +++ b/Source/WebKit2/UIProcess/Storage/StorageManager.cpp @@ -28,14 +28,16 @@ #include "LocalStorageDatabase.h" #include "LocalStorageDatabaseTracker.h" -#include "SecurityOriginData.h" #include "StorageAreaMapMessages.h" #include "StorageManagerMessages.h" #include "WebProcessProxy.h" -#include "WorkQueue.h" +#include <WebCore/SecurityOriginData.h> #include <WebCore/SecurityOriginHash.h> #include <WebCore/StorageMap.h> #include <WebCore/TextEncoding.h> +#include <memory> +#include <wtf/WorkQueue.h> +#include <wtf/threads/BinarySemaphore.h> using namespace WebCore; @@ -43,15 +45,15 @@ namespace WebKit { class StorageManager::StorageArea : public ThreadSafeRefCounted<StorageManager::StorageArea> { public: - static PassRefPtr<StorageArea> create(LocalStorageNamespace*, PassRefPtr<SecurityOrigin>, unsigned quotaInBytes); + static Ref<StorageArea> create(LocalStorageNamespace*, Ref<SecurityOrigin>&&, unsigned quotaInBytes); ~StorageArea(); - SecurityOrigin* securityOrigin() const { return m_securityOrigin.get(); } + SecurityOrigin& securityOrigin() { return m_securityOrigin.get(); } - void addListener(IPC::Connection*, uint64_t storageMapID); - void removeListener(IPC::Connection*, uint64_t storageMapID); + void addListener(IPC::Connection&, uint64_t storageMapID); + void removeListener(IPC::Connection&, uint64_t storageMapID); - PassRefPtr<StorageArea> clone() const; + Ref<StorageArea> clone() const; void setItem(IPC::Connection* sourceConnection, uint64_t sourceStorageAreaID, const String& key, const String& value, const String& urlString, bool& quotaException); void removeItem(IPC::Connection* sourceConnection, uint64_t sourceStorageAreaID, const String& key, const String& urlString); @@ -60,8 +62,10 @@ public: const HashMap<String, String>& items(); void clear(); + bool isSessionStorage() const { return !m_localStorageNamespace; } + private: - explicit StorageArea(LocalStorageNamespace*, PassRefPtr<SecurityOrigin>, unsigned quotaInBytes); + explicit StorageArea(LocalStorageNamespace*, Ref<SecurityOrigin>&&, unsigned quotaInBytes); void openDatabaseAndImportItemsIfNeeded(); @@ -72,7 +76,7 @@ private: RefPtr<LocalStorageDatabase> m_localStorageDatabase; bool m_didImportItemsFromDatabase; - RefPtr<SecurityOrigin> m_securityOrigin; + Ref<SecurityOrigin> m_securityOrigin; unsigned m_quotaInBytes; RefPtr<StorageMap> m_storageMap; @@ -81,15 +85,15 @@ private: class StorageManager::LocalStorageNamespace : public ThreadSafeRefCounted<LocalStorageNamespace> { public: - static PassRefPtr<LocalStorageNamespace> create(StorageManager*, uint64_t storageManagerID); + static Ref<LocalStorageNamespace> create(StorageManager*, uint64_t storageManagerID); ~LocalStorageNamespace(); StorageManager* storageManager() const { return m_storageManager; } - PassRefPtr<StorageArea> getOrCreateStorageArea(PassRefPtr<SecurityOrigin>); + Ref<StorageArea> getOrCreateStorageArea(Ref<SecurityOrigin>&&); void didDestroyStorageArea(StorageArea*); - void clearStorageAreasMatchingOrigin(SecurityOrigin*); + void clearStorageAreasMatchingOrigin(const SecurityOrigin&); void clearAllStorageAreas(); private: @@ -103,15 +107,74 @@ private: HashMap<RefPtr<SecurityOrigin>, StorageArea*> m_storageAreaMap; }; -PassRefPtr<StorageManager::StorageArea> StorageManager::StorageArea::create(LocalStorageNamespace* localStorageNamespace, PassRefPtr<SecurityOrigin> securityOrigin, unsigned quotaInBytes) +class StorageManager::TransientLocalStorageNamespace : public ThreadSafeRefCounted<TransientLocalStorageNamespace> { +public: + static Ref<TransientLocalStorageNamespace> create() + { + return adoptRef(*new TransientLocalStorageNamespace()); + } + + ~TransientLocalStorageNamespace() + { + } + + Ref<StorageArea> getOrCreateStorageArea(Ref<SecurityOrigin>&& securityOrigin) + { + auto& slot = m_storageAreaMap.add(securityOrigin.ptr(), nullptr).iterator->value; + if (slot) + return *slot; + + auto storageArea = StorageArea::create(nullptr, WTFMove(securityOrigin), m_quotaInBytes); + slot = &storageArea.get(); + + return storageArea; + } + + Vector<Ref<SecurityOrigin>> origins() const + { + Vector<Ref<SecurityOrigin>> origins; + + for (const auto& storageArea : m_storageAreaMap.values()) { + if (!storageArea->items().isEmpty()) + origins.append(storageArea->securityOrigin()); + } + + return origins; + } + + void clearStorageAreasMatchingOrigin(const SecurityOrigin& securityOrigin) + { + for (auto& storageArea : m_storageAreaMap.values()) { + if (storageArea->securityOrigin().equal(&securityOrigin)) + storageArea->clear(); + } + } + + void clearAllStorageAreas() + { + for (auto& storageArea : m_storageAreaMap.values()) + storageArea->clear(); + } + +private: + explicit TransientLocalStorageNamespace() + { + } + + const unsigned m_quotaInBytes = 5 * 1024 * 1024; + + HashMap<RefPtr<SecurityOrigin>, RefPtr<StorageArea>> m_storageAreaMap; +}; + +Ref<StorageManager::StorageArea> StorageManager::StorageArea::create(LocalStorageNamespace* localStorageNamespace, Ref<SecurityOrigin>&& securityOrigin, unsigned quotaInBytes) { - return adoptRef(new StorageArea(localStorageNamespace, securityOrigin, quotaInBytes)); + return adoptRef(*new StorageArea(localStorageNamespace, WTFMove(securityOrigin), quotaInBytes)); } -StorageManager::StorageArea::StorageArea(LocalStorageNamespace* localStorageNamespace, PassRefPtr<SecurityOrigin> securityOrigin, unsigned quotaInBytes) +StorageManager::StorageArea::StorageArea(LocalStorageNamespace* localStorageNamespace, Ref<SecurityOrigin>&& securityOrigin, unsigned quotaInBytes) : m_localStorageNamespace(localStorageNamespace) , m_didImportItemsFromDatabase(false) - , m_securityOrigin(securityOrigin) + , m_securityOrigin(WTFMove(securityOrigin)) , m_quotaInBytes(quotaInBytes) , m_storageMap(StorageMap::create(m_quotaInBytes)) { @@ -128,26 +191,26 @@ StorageManager::StorageArea::~StorageArea() m_localStorageNamespace->didDestroyStorageArea(this); } -void StorageManager::StorageArea::addListener(IPC::Connection* connection, uint64_t storageMapID) +void StorageManager::StorageArea::addListener(IPC::Connection& connection, uint64_t storageMapID) { - ASSERT(!m_eventListeners.contains(std::make_pair(connection, storageMapID))); - m_eventListeners.add(std::make_pair(connection, storageMapID)); + ASSERT(!m_eventListeners.contains(std::make_pair(&connection, storageMapID))); + m_eventListeners.add(std::make_pair(&connection, storageMapID)); } -void StorageManager::StorageArea::removeListener(IPC::Connection* connection, uint64_t storageMapID) +void StorageManager::StorageArea::removeListener(IPC::Connection& connection, uint64_t storageMapID) { - ASSERT(m_eventListeners.contains(std::make_pair(connection, storageMapID))); - m_eventListeners.remove(std::make_pair(connection, storageMapID)); + ASSERT(isSessionStorage() || m_eventListeners.contains(std::make_pair(&connection, storageMapID))); + m_eventListeners.remove(std::make_pair(&connection, storageMapID)); } -PassRefPtr<StorageManager::StorageArea> StorageManager::StorageArea::clone() const +Ref<StorageManager::StorageArea> StorageManager::StorageArea::clone() const { ASSERT(!m_localStorageNamespace); - RefPtr<StorageArea> storageArea = StorageArea::create(0, m_securityOrigin, m_quotaInBytes); + auto storageArea = StorageArea::create(0, m_securityOrigin.copyRef(), m_quotaInBytes); storageArea->m_storageMap = m_storageMap; - return storageArea.release(); + return storageArea; } void StorageManager::StorageArea::setItem(IPC::Connection* sourceConnection, uint64_t sourceStorageAreaID, const String& key, const String& value, const String& urlString, bool& quotaException) @@ -229,7 +292,7 @@ void StorageManager::StorageArea::openDatabaseAndImportItemsIfNeeded() // We open the database here even if we've already imported our items to ensure that the database is open if we need to write to it. if (!m_localStorageDatabase) - m_localStorageDatabase = LocalStorageDatabase::create(m_localStorageNamespace->storageManager()->m_queue, m_localStorageNamespace->storageManager()->m_localStorageDatabaseTracker, m_securityOrigin.get()); + m_localStorageDatabase = LocalStorageDatabase::create(m_localStorageNamespace->storageManager()->m_queue, m_localStorageNamespace->storageManager()->m_localStorageDatabaseTracker, m_securityOrigin.copyRef()); if (m_didImportItemsFromDatabase) return; @@ -247,9 +310,9 @@ void StorageManager::StorageArea::dispatchEvents(IPC::Connection* sourceConnecti } } -PassRefPtr<StorageManager::LocalStorageNamespace> StorageManager::LocalStorageNamespace::create(StorageManager* storageManager, uint64_t storageNamespaceID) +Ref<StorageManager::LocalStorageNamespace> StorageManager::LocalStorageNamespace::create(StorageManager* storageManager, uint64_t storageNamespaceID) { - return adoptRef(new LocalStorageNamespace(storageManager, storageNamespaceID)); + return adoptRef(*new LocalStorageNamespace(storageManager, storageNamespaceID)); } // FIXME: The quota value is copied from GroupSettings.cpp. @@ -266,23 +329,23 @@ StorageManager::LocalStorageNamespace::~LocalStorageNamespace() ASSERT(m_storageAreaMap.isEmpty()); } -PassRefPtr<StorageManager::StorageArea> StorageManager::LocalStorageNamespace::getOrCreateStorageArea(PassRefPtr<SecurityOrigin> securityOrigin) +Ref<StorageManager::StorageArea> StorageManager::LocalStorageNamespace::getOrCreateStorageArea(Ref<SecurityOrigin>&& securityOrigin) { - auto result = m_storageAreaMap.add(securityOrigin, nullptr); - if (!result.isNewEntry) - return result.iterator->value; + auto& slot = m_storageAreaMap.add(securityOrigin.ptr(), nullptr).iterator->value; + if (slot) + return *slot; - RefPtr<StorageArea> storageArea = StorageArea::create(this, result.iterator->key, m_quotaInBytes); - result.iterator->value = storageArea.get(); + auto storageArea = StorageArea::create(this, WTFMove(securityOrigin), m_quotaInBytes); + slot = &storageArea.get(); - return storageArea.release(); + return storageArea; } void StorageManager::LocalStorageNamespace::didDestroyStorageArea(StorageArea* storageArea) { - ASSERT(m_storageAreaMap.contains(storageArea->securityOrigin())); + ASSERT(m_storageAreaMap.contains(&storageArea->securityOrigin())); - m_storageAreaMap.remove(storageArea->securityOrigin()); + m_storageAreaMap.remove(&storageArea->securityOrigin()); if (!m_storageAreaMap.isEmpty()) return; @@ -290,11 +353,11 @@ void StorageManager::LocalStorageNamespace::didDestroyStorageArea(StorageArea* s m_storageManager->m_localStorageNamespaces.remove(m_storageNamespaceID); } -void StorageManager::LocalStorageNamespace::clearStorageAreasMatchingOrigin(SecurityOrigin* securityOrigin) +void StorageManager::LocalStorageNamespace::clearStorageAreasMatchingOrigin(const SecurityOrigin& securityOrigin) { - for (auto it = m_storageAreaMap.begin(), end = m_storageAreaMap.end(); it != end; ++it) { - if (it->key->equal(securityOrigin)) - it->value->clear(); + for (const auto& originAndStorageArea : m_storageAreaMap) { + if (originAndStorageArea.key->equal(&securityOrigin)) + originAndStorageArea.value->clear(); } } @@ -306,7 +369,7 @@ void StorageManager::LocalStorageNamespace::clearAllStorageAreas() class StorageManager::SessionStorageNamespace : public ThreadSafeRefCounted<SessionStorageNamespace> { public: - static PassRefPtr<SessionStorageNamespace> create(IPC::Connection* allowedConnection, unsigned quotaInBytes); + static Ref<SessionStorageNamespace> create(unsigned quotaInBytes); ~SessionStorageNamespace(); bool isEmpty() const { return m_storageAreaMap.isEmpty(); } @@ -314,12 +377,38 @@ public: IPC::Connection* allowedConnection() const { return m_allowedConnection.get(); } void setAllowedConnection(IPC::Connection*); - PassRefPtr<StorageArea> getOrCreateStorageArea(PassRefPtr<SecurityOrigin>); + Ref<StorageArea> getOrCreateStorageArea(Ref<SecurityOrigin>&&); void cloneTo(SessionStorageNamespace& newSessionStorageNamespace); + Vector<Ref<SecurityOrigin>> origins() const + { + Vector<Ref<SecurityOrigin>> origins; + + for (const auto& storageArea : m_storageAreaMap.values()) { + if (!storageArea->items().isEmpty()) + origins.append(storageArea->securityOrigin()); + } + + return origins; + } + + void clearStorageAreasMatchingOrigin(const SecurityOrigin& securityOrigin) + { + for (auto& storageArea : m_storageAreaMap.values()) { + if (storageArea->securityOrigin().equal(&securityOrigin)) + storageArea->clear(); + } + } + + void clearAllStorageAreas() + { + for (auto& storageArea : m_storageAreaMap.values()) + storageArea->clear(); + } + private: - SessionStorageNamespace(IPC::Connection* allowedConnection, unsigned quotaInBytes); + explicit SessionStorageNamespace(unsigned quotaInBytes); RefPtr<IPC::Connection> m_allowedConnection; unsigned m_quotaInBytes; @@ -327,14 +416,13 @@ private: HashMap<RefPtr<SecurityOrigin>, RefPtr<StorageArea>> m_storageAreaMap; }; -PassRefPtr<StorageManager::SessionStorageNamespace> StorageManager::SessionStorageNamespace::create(IPC::Connection* allowedConnection, unsigned quotaInBytes) +Ref<StorageManager::SessionStorageNamespace> StorageManager::SessionStorageNamespace::create(unsigned quotaInBytes) { - return adoptRef(new SessionStorageNamespace(allowedConnection, quotaInBytes)); + return adoptRef(*new SessionStorageNamespace(quotaInBytes)); } -StorageManager::SessionStorageNamespace::SessionStorageNamespace(IPC::Connection* allowedConnection, unsigned quotaInBytes) - : m_allowedConnection(allowedConnection) - , m_quotaInBytes(quotaInBytes) +StorageManager::SessionStorageNamespace::SessionStorageNamespace(unsigned quotaInBytes) + : m_quotaInBytes(quotaInBytes) { } @@ -349,13 +437,13 @@ void StorageManager::SessionStorageNamespace::setAllowedConnection(IPC::Connecti m_allowedConnection = allowedConnection; } -PassRefPtr<StorageManager::StorageArea> StorageManager::SessionStorageNamespace::getOrCreateStorageArea(PassRefPtr<SecurityOrigin> securityOrigin) +Ref<StorageManager::StorageArea> StorageManager::SessionStorageNamespace::getOrCreateStorageArea(Ref<SecurityOrigin>&& securityOrigin) { - auto result = m_storageAreaMap.add(securityOrigin, nullptr); - if (result.isNewEntry) - result.iterator->value = StorageArea::create(0, result.iterator->key, m_quotaInBytes); + auto& slot = m_storageAreaMap.add(securityOrigin.ptr(), nullptr).iterator->value; + if (!slot) + slot = StorageArea::create(0, WTFMove(securityOrigin), m_quotaInBytes); - return result.iterator->value; + return *slot; } void StorageManager::SessionStorageNamespace::cloneTo(SessionStorageNamespace& newSessionStorageNamespace) @@ -366,14 +454,14 @@ void StorageManager::SessionStorageNamespace::cloneTo(SessionStorageNamespace& n newSessionStorageNamespace.m_storageAreaMap.add(it->key, it->value->clone()); } -PassRefPtr<StorageManager> StorageManager::create() +Ref<StorageManager> StorageManager::create(const String& localStorageDirectory) { - return adoptRef(new StorageManager); + return adoptRef(*new StorageManager(localStorageDirectory)); } -StorageManager::StorageManager() +StorageManager::StorageManager(const String& localStorageDirectory) : m_queue(WorkQueue::create("com.apple.WebKit.StorageManager")) - , m_localStorageDatabaseTracker(LocalStorageDatabaseTracker::create(m_queue)) + , m_localStorageDatabaseTracker(LocalStorageDatabaseTracker::create(m_queue, localStorageDirectory)) { // Make sure the encoding is initialized before we start dispatching things to the queue. UTF8Encoding(); @@ -383,61 +471,233 @@ StorageManager::~StorageManager() { } -void StorageManager::setLocalStorageDirectory(const String& localStorageDirectory) +void StorageManager::createSessionStorageNamespace(uint64_t storageNamespaceID, unsigned quotaInBytes) { - m_localStorageDatabaseTracker->setLocalStorageDirectory(localStorageDirectory); -} + RefPtr<StorageManager> storageManager(this); -void StorageManager::createSessionStorageNamespace(uint64_t storageNamespaceID, IPC::Connection* allowedConnection, unsigned quotaInBytes) -{ - m_queue->dispatch(bind(&StorageManager::createSessionStorageNamespaceInternal, this, storageNamespaceID, RefPtr<IPC::Connection>(allowedConnection), quotaInBytes)); + m_queue->dispatch([storageManager, storageNamespaceID, quotaInBytes] { + ASSERT(!storageManager->m_sessionStorageNamespaces.contains(storageNamespaceID)); + + storageManager->m_sessionStorageNamespaces.set(storageNamespaceID, SessionStorageNamespace::create(quotaInBytes)); + }); } void StorageManager::destroySessionStorageNamespace(uint64_t storageNamespaceID) { - m_queue->dispatch(bind(&StorageManager::destroySessionStorageNamespaceInternal, this, storageNamespaceID)); + RefPtr<StorageManager> storageManager(this); + + m_queue->dispatch([storageManager, storageNamespaceID] { + ASSERT(storageManager->m_sessionStorageNamespaces.contains(storageNamespaceID)); + storageManager->m_sessionStorageNamespaces.remove(storageNamespaceID); + }); } void StorageManager::setAllowedSessionStorageNamespaceConnection(uint64_t storageNamespaceID, IPC::Connection* allowedConnection) { - m_queue->dispatch(bind(&StorageManager::setAllowedSessionStorageNamespaceConnectionInternal, this, storageNamespaceID, RefPtr<IPC::Connection>(allowedConnection))); + RefPtr<StorageManager> storageManager(this); + RefPtr<IPC::Connection> connection(allowedConnection); + + m_queue->dispatch([storageManager, connection, storageNamespaceID] { + ASSERT(storageManager->m_sessionStorageNamespaces.contains(storageNamespaceID)); + + storageManager->m_sessionStorageNamespaces.get(storageNamespaceID)->setAllowedConnection(connection.get()); + }); } void StorageManager::cloneSessionStorageNamespace(uint64_t storageNamespaceID, uint64_t newStorageNamespaceID) { - m_queue->dispatch(bind(&StorageManager::cloneSessionStorageNamespaceInternal, this, storageNamespaceID, newStorageNamespaceID)); + RefPtr<StorageManager> storageManager(this); + + m_queue->dispatch([storageManager, storageNamespaceID, newStorageNamespaceID] { + SessionStorageNamespace* sessionStorageNamespace = storageManager->m_sessionStorageNamespaces.get(storageNamespaceID); + if (!sessionStorageNamespace) { + // FIXME: We can get into this situation if someone closes the originating page from within a + // createNewPage callback. We bail for now, but we should really find a way to keep the session storage alive + // so we we'll clone the session storage correctly. + return; + } + + SessionStorageNamespace* newSessionStorageNamespace = storageManager->m_sessionStorageNamespaces.get(newStorageNamespaceID); + ASSERT(newSessionStorageNamespace); + + sessionStorageNamespace->cloneTo(*newSessionStorageNamespace); + }); +} + +void StorageManager::processWillOpenConnection(WebProcessProxy&, IPC::Connection& connection) +{ + connection.addWorkQueueMessageReceiver(Messages::StorageManager::messageReceiverName(), m_queue.get(), this); +} + +void StorageManager::processDidCloseConnection(WebProcessProxy&, IPC::Connection& connection) +{ + connection.removeWorkQueueMessageReceiver(Messages::StorageManager::messageReceiverName()); + + RefPtr<StorageManager> storageManager(this); + RefPtr<IPC::Connection> protectedConnection(&connection); + + m_queue->dispatch([storageManager, protectedConnection] { + Vector<std::pair<RefPtr<IPC::Connection>, uint64_t>> connectionAndStorageMapIDPairsToRemove; + auto storageAreasByConnection = storageManager->m_storageAreasByConnection; + + for (auto it = storageAreasByConnection.begin(), end = storageAreasByConnection.end(); it != end; ++it) { + if (it->key.first != protectedConnection) + continue; + + it->value->removeListener(*it->key.first, it->key.second); + connectionAndStorageMapIDPairsToRemove.append(it->key); + } + + for (size_t i = 0; i < connectionAndStorageMapIDPairsToRemove.size(); ++i) + storageManager->m_storageAreasByConnection.remove(connectionAndStorageMapIDPairsToRemove[i]); + }); +} + +void StorageManager::getSessionStorageOrigins(std::function<void (HashSet<RefPtr<WebCore::SecurityOrigin>>&&)> completionHandler) +{ + RefPtr<StorageManager> storageManager(this); + + m_queue->dispatch([storageManager, completionHandler] { + HashSet<RefPtr<SecurityOrigin>> origins; + + for (const auto& sessionStorageNamespace : storageManager->m_sessionStorageNamespaces.values()) { + for (auto& origin : sessionStorageNamespace->origins()) + origins.add(WTFMove(origin)); + } + + RunLoop::main().dispatch([origins, completionHandler]() mutable { + completionHandler(WTFMove(origins)); + }); + }); } -void StorageManager::processWillOpenConnection(WebProcessProxy* webProcessProxy) +void StorageManager::deleteSessionStorageOrigins(std::function<void ()> completionHandler) { - webProcessProxy->connection()->addWorkQueueMessageReceiver(Messages::StorageManager::messageReceiverName(), m_queue.get(), this); + RefPtr<StorageManager> storageManager(this); + + m_queue->dispatch([storageManager, completionHandler] { + for (auto& sessionStorageNamespace : storageManager->m_sessionStorageNamespaces.values()) + sessionStorageNamespace->clearAllStorageAreas(); + + RunLoop::main().dispatch(completionHandler); + }); } -void StorageManager::processWillCloseConnection(WebProcessProxy* webProcessProxy) +void StorageManager::deleteSessionStorageEntriesForOrigins(const Vector<RefPtr<WebCore::SecurityOrigin>>& origins, std::function<void ()> completionHandler) { - webProcessProxy->connection()->removeWorkQueueMessageReceiver(Messages::StorageManager::messageReceiverName()); + Vector<RefPtr<WebCore::SecurityOrigin>> copiedOrigins; + copiedOrigins.reserveInitialCapacity(origins.size()); + + for (auto& origin : origins) + copiedOrigins.uncheckedAppend(origin->isolatedCopy()); + + RefPtr<StorageManager> storageManager(this); + m_queue->dispatch([storageManager, copiedOrigins, completionHandler] { + for (auto& origin : copiedOrigins) { + for (auto& sessionStorageNamespace : storageManager->m_sessionStorageNamespaces.values()) + sessionStorageNamespace->clearStorageAreasMatchingOrigin(*origin); + } - m_queue->dispatch(bind(&StorageManager::invalidateConnectionInternal, this, RefPtr<IPC::Connection>(webProcessProxy->connection()))); + RunLoop::main().dispatch(completionHandler); + }); } -void StorageManager::getOrigins(FunctionDispatcher* callbackDispatcher, void* context, void (*callback)(const Vector<RefPtr<WebCore::SecurityOrigin>>& securityOrigins, void* context)) +void StorageManager::getLocalStorageOrigins(std::function<void (HashSet<RefPtr<WebCore::SecurityOrigin>>&&)> completionHandler) { - m_queue->dispatch(bind(&StorageManager::getOriginsInternal, this, RefPtr<FunctionDispatcher>(callbackDispatcher), context, callback)); + RefPtr<StorageManager> storageManager(this); + + m_queue->dispatch([storageManager, completionHandler] { + HashSet<RefPtr<SecurityOrigin>> origins; + + for (auto& origin : storageManager->m_localStorageDatabaseTracker->origins()) + origins.add(WTFMove(origin)); + + for (auto& transientLocalStorageNamespace : storageManager->m_transientLocalStorageNamespaces.values()) { + for (auto& origin : transientLocalStorageNamespace->origins()) + origins.add(WTFMove(origin)); + } + + RunLoop::main().dispatch([origins, completionHandler]() mutable { + completionHandler(WTFMove(origins)); + }); + }); } -void StorageManager::deleteEntriesForOrigin(SecurityOrigin* securityOrigin) +void StorageManager::getLocalStorageOriginDetails(std::function<void (Vector<LocalStorageDatabaseTracker::OriginDetails>)> completionHandler) { - m_queue->dispatch(bind(&StorageManager::deleteEntriesForOriginInternal, this, RefPtr<SecurityOrigin>(securityOrigin))); + RefPtr<StorageManager> storageManager(this); + + m_queue->dispatch([storageManager, completionHandler] { + auto originDetails = storageManager->m_localStorageDatabaseTracker->originDetails(); + + RunLoop::main().dispatch([originDetails, completionHandler]() mutable { + completionHandler(WTFMove(originDetails)); + }); + }); } -void StorageManager::deleteAllEntries() +void StorageManager::deleteLocalStorageEntriesForOrigin(const SecurityOrigin& securityOrigin) { - m_queue->dispatch(bind(&StorageManager::deleteAllEntriesInternal, this)); + RefPtr<StorageManager> storageManager(this); + + RefPtr<SecurityOrigin> copiedOrigin = securityOrigin.isolatedCopy(); + m_queue->dispatch([storageManager, copiedOrigin] { + for (auto& localStorageNamespace : storageManager->m_localStorageNamespaces.values()) + localStorageNamespace->clearStorageAreasMatchingOrigin(*copiedOrigin); + + for (auto& transientLocalStorageNamespace : storageManager->m_transientLocalStorageNamespaces.values()) + transientLocalStorageNamespace->clearStorageAreasMatchingOrigin(*copiedOrigin); + + storageManager->m_localStorageDatabaseTracker->deleteDatabaseWithOrigin(copiedOrigin.get()); + }); } -void StorageManager::createLocalStorageMap(IPC::Connection* connection, uint64_t storageMapID, uint64_t storageNamespaceID, const SecurityOriginData& securityOriginData) +void StorageManager::deleteLocalStorageOriginsModifiedSince(std::chrono::system_clock::time_point time, std::function<void ()> completionHandler) { - std::pair<RefPtr<IPC::Connection>, uint64_t> connectionAndStorageMapIDPair(connection, storageMapID); + RefPtr<StorageManager> storageManager(this); + + m_queue->dispatch([storageManager, time, completionHandler] { + auto deletedOrigins = storageManager->m_localStorageDatabaseTracker->deleteDatabasesModifiedSince(time); + + for (const auto& origin : deletedOrigins) { + for (auto& localStorageNamespace : storageManager->m_localStorageNamespaces.values()) + localStorageNamespace->clearStorageAreasMatchingOrigin(origin.get()); + } + + for (auto& transientLocalStorageNamespace : storageManager->m_transientLocalStorageNamespaces.values()) + transientLocalStorageNamespace->clearAllStorageAreas(); + + RunLoop::main().dispatch(completionHandler); + }); +} + +void StorageManager::deleteLocalStorageEntriesForOrigins(const Vector<RefPtr<WebCore::SecurityOrigin>>& origins, std::function<void ()> completionHandler) +{ + Vector<RefPtr<WebCore::SecurityOrigin>> copiedOrigins; + copiedOrigins.reserveInitialCapacity(origins.size()); + + for (auto& origin : origins) + copiedOrigins.uncheckedAppend(origin->isolatedCopy()); + + RefPtr<StorageManager> storageManager(this); + m_queue->dispatch([storageManager, copiedOrigins, completionHandler] { + for (auto& origin : copiedOrigins) { + for (auto& localStorageNamespace : storageManager->m_localStorageNamespaces.values()) + localStorageNamespace->clearStorageAreasMatchingOrigin(*origin); + + for (auto& transientLocalStorageNamespace : storageManager->m_transientLocalStorageNamespaces.values()) + transientLocalStorageNamespace->clearStorageAreasMatchingOrigin(*origin); + + storageManager->m_localStorageDatabaseTracker->deleteDatabaseWithOrigin(origin.get()); + } + + RunLoop::main().dispatch(completionHandler); + }); +} + +void StorageManager::createLocalStorageMap(IPC::Connection& connection, uint64_t storageMapID, uint64_t storageNamespaceID, const SecurityOriginData& securityOriginData) +{ + std::pair<RefPtr<IPC::Connection>, uint64_t> connectionAndStorageMapIDPair(&connection, storageMapID); // FIXME: This should be a message check. ASSERT((HashMap<std::pair<RefPtr<IPC::Connection>, uint64_t>, RefPtr<StorageArea>>::isValidKey(connectionAndStorageMapIDPair))); @@ -459,10 +719,47 @@ void StorageManager::createLocalStorageMap(IPC::Connection* connection, uint64_t result.iterator->value = storageArea.release(); } -void StorageManager::createSessionStorageMap(IPC::Connection* connection, uint64_t storageMapID, uint64_t storageNamespaceID, const SecurityOriginData& securityOriginData) +void StorageManager::createTransientLocalStorageMap(IPC::Connection& connection, uint64_t storageMapID, uint64_t storageNamespaceID, const SecurityOriginData& topLevelOriginData, const SecurityOriginData& securityOriginData) +{ + // FIXME: This should be a message check. + ASSERT(m_storageAreasByConnection.isValidKey({ &connection, storageMapID })); + + Ref<SecurityOrigin> origin = securityOriginData.securityOrigin(); + + // See if we already have session storage for this connection/origin combo. + // If so, update the map with the new ID, otherwise keep on trucking. + for (auto it = m_storageAreasByConnection.begin(), end = m_storageAreasByConnection.end(); it != end; ++it) { + if (it->key.first != &connection) + continue; + Ref<StorageArea> area = *it->value; + if (!area->isSessionStorage()) + continue; + if (!origin->isSameSchemeHostPort(&area->securityOrigin())) + continue; + area->addListener(connection, storageMapID); + m_storageAreasByConnection.remove(it); + m_storageAreasByConnection.add({ &connection, storageMapID }, WTFMove(area)); + return; + } + + auto& slot = m_storageAreasByConnection.add({ &connection, storageMapID }, nullptr).iterator->value; + + // FIXME: This should be a message check. + ASSERT(!slot); + + TransientLocalStorageNamespace* transientLocalStorageNamespace = getOrCreateTransientLocalStorageNamespace(storageNamespaceID, topLevelOriginData.securityOrigin()); + + auto storageArea = transientLocalStorageNamespace->getOrCreateStorageArea(securityOriginData.securityOrigin()); + storageArea->addListener(connection, storageMapID); + + slot = WTFMove(storageArea); +} + +void StorageManager::createSessionStorageMap(IPC::Connection& connection, uint64_t storageMapID, uint64_t storageNamespaceID, const SecurityOriginData& securityOriginData) { // FIXME: This should be a message check. - ASSERT((HashMap<uint64_t, RefPtr<SessionStorageNamespace>>::isValidKey(storageNamespaceID))); + ASSERT(m_sessionStorageNamespaces.isValidKey(storageNamespaceID)); + SessionStorageNamespace* sessionStorageNamespace = m_sessionStorageNamespaces.get(storageNamespaceID); if (!sessionStorageNamespace) { // We're getting an incoming message from the web process that's for session storage for a web page @@ -470,43 +767,46 @@ void StorageManager::createSessionStorageMap(IPC::Connection* connection, uint64 return; } - std::pair<RefPtr<IPC::Connection>, uint64_t> connectionAndStorageMapIDPair(connection, storageMapID); - // FIXME: This should be a message check. - ASSERT((HashMap<std::pair<RefPtr<IPC::Connection>, uint64_t>, RefPtr<StorageArea>>::isValidKey(connectionAndStorageMapIDPair))); + ASSERT(m_storageAreasByConnection.isValidKey({ &connection, storageMapID })); - HashMap<std::pair<RefPtr<IPC::Connection>, uint64_t>, RefPtr<StorageArea>>::AddResult result = m_storageAreasByConnection.add(connectionAndStorageMapIDPair, nullptr); + auto& slot = m_storageAreasByConnection.add({ &connection, storageMapID }, nullptr).iterator->value; // FIXME: This should be a message check. - ASSERT(result.isNewEntry); + ASSERT(!slot); // FIXME: This should be a message check. - ASSERT(connection == sessionStorageNamespace->allowedConnection()); + ASSERT(&connection == sessionStorageNamespace->allowedConnection()); - RefPtr<StorageArea> storageArea = sessionStorageNamespace->getOrCreateStorageArea(securityOriginData.securityOrigin()); + auto storageArea = sessionStorageNamespace->getOrCreateStorageArea(securityOriginData.securityOrigin()); storageArea->addListener(connection, storageMapID); - result.iterator->value = storageArea.release(); + slot = WTFMove(storageArea); } -void StorageManager::destroyStorageMap(IPC::Connection* connection, uint64_t storageMapID) +void StorageManager::destroyStorageMap(IPC::Connection& connection, uint64_t storageMapID) { - std::pair<RefPtr<IPC::Connection>, uint64_t> connectionAndStorageMapIDPair(connection, storageMapID); + std::pair<RefPtr<IPC::Connection>, uint64_t> connectionAndStorageMapIDPair(&connection, storageMapID); // FIXME: This should be a message check. - ASSERT((HashMap<std::pair<RefPtr<IPC::Connection>, uint64_t>, RefPtr<StorageArea>>::isValidKey(connectionAndStorageMapIDPair))); + ASSERT(m_storageAreasByConnection.isValidKey(connectionAndStorageMapIDPair)); - HashMap<std::pair<RefPtr<IPC::Connection>, uint64_t>, RefPtr<StorageArea>>::iterator it = m_storageAreasByConnection.find(connectionAndStorageMapIDPair); + auto it = m_storageAreasByConnection.find(connectionAndStorageMapIDPair); if (it == m_storageAreasByConnection.end()) { // The connection has been removed because the last page was closed. return; } it->value->removeListener(connection, storageMapID); + + // Don't remove session storage maps. The web process may reconnect and expect the data to still be around. + if (it->value->isSessionStorage()) + return; + m_storageAreasByConnection.remove(connectionAndStorageMapIDPair); } -void StorageManager::getValues(IPC::Connection* connection, uint64_t storageMapID, uint64_t storageMapSeed, HashMap<String, String>& values) +void StorageManager::getValues(IPC::Connection& connection, uint64_t storageMapID, uint64_t storageMapSeed, HashMap<String, String>& values) { StorageArea* storageArea = findStorageArea(connection, storageMapID); if (!storageArea) { @@ -515,10 +815,10 @@ void StorageManager::getValues(IPC::Connection* connection, uint64_t storageMapI } values = storageArea->items(); - connection->send(Messages::StorageAreaMap::DidGetValues(storageMapSeed), storageMapID); + connection.send(Messages::StorageAreaMap::DidGetValues(storageMapSeed), storageMapID); } -void StorageManager::setItem(IPC::Connection* connection, uint64_t storageMapID, uint64_t sourceStorageAreaID, uint64_t storageMapSeed, const String& key, const String& value, const String& urlString) +void StorageManager::setItem(IPC::Connection& connection, uint64_t storageMapID, uint64_t sourceStorageAreaID, uint64_t storageMapSeed, const String& key, const String& value, const String& urlString) { StorageArea* storageArea = findStorageArea(connection, storageMapID); if (!storageArea) { @@ -527,11 +827,11 @@ void StorageManager::setItem(IPC::Connection* connection, uint64_t storageMapID, } bool quotaError; - storageArea->setItem(connection, sourceStorageAreaID, key, value, urlString, quotaError); - connection->send(Messages::StorageAreaMap::DidSetItem(storageMapSeed, key, quotaError), storageMapID); + storageArea->setItem(&connection, sourceStorageAreaID, key, value, urlString, quotaError); + connection.send(Messages::StorageAreaMap::DidSetItem(storageMapSeed, key, quotaError), storageMapID); } -void StorageManager::removeItem(IPC::Connection* connection, uint64_t storageMapID, uint64_t sourceStorageAreaID, uint64_t storageMapSeed, const String& key, const String& urlString) +void StorageManager::removeItem(IPC::Connection& connection, uint64_t storageMapID, uint64_t sourceStorageAreaID, uint64_t storageMapSeed, const String& key, const String& urlString) { StorageArea* storageArea = findStorageArea(connection, storageMapID); if (!storageArea) { @@ -539,11 +839,11 @@ void StorageManager::removeItem(IPC::Connection* connection, uint64_t storageMap return; } - storageArea->removeItem(connection, sourceStorageAreaID, key, urlString); - connection->send(Messages::StorageAreaMap::DidRemoveItem(storageMapSeed, key), storageMapID); + storageArea->removeItem(&connection, sourceStorageAreaID, key, urlString); + connection.send(Messages::StorageAreaMap::DidRemoveItem(storageMapSeed, key), storageMapID); } -void StorageManager::clear(IPC::Connection* connection, uint64_t storageMapID, uint64_t sourceStorageAreaID, uint64_t storageMapSeed, const String& urlString) +void StorageManager::clear(IPC::Connection& connection, uint64_t storageMapID, uint64_t sourceStorageAreaID, uint64_t storageMapSeed, const String& urlString) { StorageArea* storageArea = findStorageArea(connection, storageMapID); if (!storageArea) { @@ -551,105 +851,60 @@ void StorageManager::clear(IPC::Connection* connection, uint64_t storageMapID, u return; } - storageArea->clear(connection, sourceStorageAreaID, urlString); - connection->send(Messages::StorageAreaMap::DidClear(storageMapSeed), storageMapID); -} - -void StorageManager::createSessionStorageNamespaceInternal(uint64_t storageNamespaceID, IPC::Connection* allowedConnection, unsigned quotaInBytes) -{ - ASSERT(!m_sessionStorageNamespaces.contains(storageNamespaceID)); - - m_sessionStorageNamespaces.set(storageNamespaceID, SessionStorageNamespace::create(allowedConnection, quotaInBytes)); -} - -void StorageManager::destroySessionStorageNamespaceInternal(uint64_t storageNamespaceID) -{ - ASSERT(m_sessionStorageNamespaces.contains(storageNamespaceID)); - m_sessionStorageNamespaces.remove(storageNamespaceID); -} - -void StorageManager::setAllowedSessionStorageNamespaceConnectionInternal(uint64_t storageNamespaceID, IPC::Connection* allowedConnection) -{ - ASSERT(m_sessionStorageNamespaces.contains(storageNamespaceID)); - - m_sessionStorageNamespaces.get(storageNamespaceID)->setAllowedConnection(allowedConnection); + storageArea->clear(&connection, sourceStorageAreaID, urlString); + connection.send(Messages::StorageAreaMap::DidClear(storageMapSeed), storageMapID); } -void StorageManager::cloneSessionStorageNamespaceInternal(uint64_t storageNamespaceID, uint64_t newStorageNamespaceID) +void StorageManager::applicationWillTerminate() { - SessionStorageNamespace* sessionStorageNamespace = m_sessionStorageNamespaces.get(storageNamespaceID); - ASSERT(sessionStorageNamespace); + BinarySemaphore semaphore; + m_queue->dispatch([this, &semaphore] { + Vector<std::pair<RefPtr<IPC::Connection>, uint64_t>> connectionAndStorageMapIDPairsToRemove; + for (auto& connectionStorageAreaPair : m_storageAreasByConnection) { + connectionStorageAreaPair.value->removeListener(*connectionStorageAreaPair.key.first, connectionStorageAreaPair.key.second); + connectionAndStorageMapIDPairsToRemove.append(connectionStorageAreaPair.key); + } - SessionStorageNamespace* newSessionStorageNamespace = m_sessionStorageNamespaces.get(newStorageNamespaceID); - ASSERT(newSessionStorageNamespace); + for (auto& connectionStorageAreaPair : connectionAndStorageMapIDPairsToRemove) + m_storageAreasByConnection.remove(connectionStorageAreaPair); - sessionStorageNamespace->cloneTo(*newSessionStorageNamespace); + semaphore.signal(); + }); + semaphore.wait(std::numeric_limits<double>::max()); } -void StorageManager::invalidateConnectionInternal(IPC::Connection* connection) +StorageManager::StorageArea* StorageManager::findStorageArea(IPC::Connection& connection, uint64_t storageMapID) const { - Vector<std::pair<RefPtr<IPC::Connection>, uint64_t>> connectionAndStorageMapIDPairsToRemove; - HashMap<std::pair<RefPtr<IPC::Connection>, uint64_t>, RefPtr<StorageArea>> storageAreasByConnection = m_storageAreasByConnection; - for (HashMap<std::pair<RefPtr<IPC::Connection>, uint64_t>, RefPtr<StorageArea>>::const_iterator it = storageAreasByConnection.begin(), end = storageAreasByConnection.end(); it != end; ++it) { - if (it->key.first != connection) - continue; + std::pair<IPC::Connection*, uint64_t> connectionAndStorageMapIDPair(&connection, storageMapID); - it->value->removeListener(it->key.first.get(), it->key.second); - connectionAndStorageMapIDPairsToRemove.append(it->key); - } - - for (size_t i = 0; i < connectionAndStorageMapIDPairsToRemove.size(); ++i) - m_storageAreasByConnection.remove(connectionAndStorageMapIDPairsToRemove[i]); -} - -StorageManager::StorageArea* StorageManager::findStorageArea(IPC::Connection* connection, uint64_t storageMapID) const -{ - std::pair<IPC::Connection*, uint64_t> connectionAndStorageMapIDPair(connection, storageMapID); - if (!HashMap<std::pair<RefPtr<IPC::Connection>, uint64_t>, RefPtr<StorageArea>>::isValidKey(connectionAndStorageMapIDPair)) - return 0; + if (!m_storageAreasByConnection.isValidKey(connectionAndStorageMapIDPair)) + return nullptr; return m_storageAreasByConnection.get(connectionAndStorageMapIDPair); } StorageManager::LocalStorageNamespace* StorageManager::getOrCreateLocalStorageNamespace(uint64_t storageNamespaceID) { - if (!HashMap<uint64_t, RefPtr<LocalStorageNamespace>>::isValidKey(storageNamespaceID)) + if (!m_localStorageNamespaces.isValidKey(storageNamespaceID)) return 0; - HashMap<uint64_t, RefPtr<LocalStorageNamespace>>::AddResult result = m_localStorageNamespaces.add(storageNamespaceID, nullptr); - if (result.isNewEntry) - result.iterator->value = LocalStorageNamespace::create(this, storageNamespaceID); - - return result.iterator->value.get(); -} + auto& slot = m_localStorageNamespaces.add(storageNamespaceID, nullptr).iterator->value; + if (!slot) + slot = LocalStorageNamespace::create(this, storageNamespaceID); -static void callCallbackFunction(void* context, void (*callbackFunction)(const Vector<RefPtr<WebCore::SecurityOrigin>>& securityOrigins, void* context), Vector<RefPtr<WebCore::SecurityOrigin>>* securityOriginsPtr) -{ - OwnPtr<Vector<RefPtr<WebCore::SecurityOrigin>>> securityOrigins = adoptPtr(securityOriginsPtr); - callbackFunction(*securityOrigins, context); + return slot.get(); } -void StorageManager::getOriginsInternal(FunctionDispatcher* dispatcher, void* context, void (*callbackFunction)(const Vector<RefPtr<WebCore::SecurityOrigin>>& securityOrigins, void* context)) +StorageManager::TransientLocalStorageNamespace* StorageManager::getOrCreateTransientLocalStorageNamespace(uint64_t storageNamespaceID, WebCore::SecurityOrigin& topLevelOrigin) { - OwnPtr<Vector<RefPtr<WebCore::SecurityOrigin>>> securityOrigins = adoptPtr(new Vector<RefPtr<WebCore::SecurityOrigin>>(m_localStorageDatabaseTracker->origins())); - dispatcher->dispatch(bind(callCallbackFunction, context, callbackFunction, securityOrigins.leakPtr())); -} + if (!m_transientLocalStorageNamespaces.isValidKey({ storageNamespaceID, &topLevelOrigin })) + return nullptr; -void StorageManager::deleteEntriesForOriginInternal(SecurityOrigin* securityOrigin) -{ - for (auto it = m_localStorageNamespaces.begin(), end = m_localStorageNamespaces.end(); it != end; ++it) - it->value->clearStorageAreasMatchingOrigin(securityOrigin); + auto& slot = m_transientLocalStorageNamespaces.add({ storageNamespaceID, &topLevelOrigin }, nullptr).iterator->value; + if (!slot) + slot = TransientLocalStorageNamespace::create(); - m_localStorageDatabaseTracker->deleteDatabaseWithOrigin(securityOrigin); + return slot.get(); } -void StorageManager::deleteAllEntriesInternal() -{ - for (auto it = m_localStorageNamespaces.begin(), end = m_localStorageNamespaces.end(); it != end; ++it) - it->value->clearAllStorageAreas(); - - m_localStorageDatabaseTracker->deleteAllDatabases(); -} - - } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/Storage/StorageManager.h b/Source/WebKit2/UIProcess/Storage/StorageManager.h index 93bb66c55..a0f179313 100644 --- a/Source/WebKit2/UIProcess/Storage/StorageManager.h +++ b/Source/WebKit2/UIProcess/Storage/StorageManager.h @@ -27,83 +27,84 @@ #define StorageManager_h #include "Connection.h" +#include "LocalStorageDatabaseTracker.h" +#include <WebCore/SecurityOriginHash.h> +#include <chrono> #include <wtf/Forward.h> -#include <wtf/PassRefPtr.h> +#include <wtf/HashSet.h> #include <wtf/ThreadSafeRefCounted.h> #include <wtf/text/StringHash.h> -class WorkQueue; - namespace WebCore { class SecurityOrigin; +struct SecurityOriginData; } namespace WebKit { -struct SecurityOriginData; class LocalStorageDatabaseTracker; class WebProcessProxy; class StorageManager : public IPC::Connection::WorkQueueMessageReceiver { public: - static PassRefPtr<StorageManager> create(); + static Ref<StorageManager> create(const String& localStorageDirectory); ~StorageManager(); - void setLocalStorageDirectory(const String&); - - void createSessionStorageNamespace(uint64_t storageNamespaceID, IPC::Connection* allowedConnection, unsigned quotaInBytes); + void createSessionStorageNamespace(uint64_t storageNamespaceID, unsigned quotaInBytes); void destroySessionStorageNamespace(uint64_t storageNamespaceID); void setAllowedSessionStorageNamespaceConnection(uint64_t storageNamespaceID, IPC::Connection* allowedConnection); void cloneSessionStorageNamespace(uint64_t storageNamespaceID, uint64_t newStorageNamespaceID); - void processWillOpenConnection(WebProcessProxy*); - void processWillCloseConnection(WebProcessProxy*); + void processWillOpenConnection(WebProcessProxy&, IPC::Connection&); + void processDidCloseConnection(WebProcessProxy&, IPC::Connection&); + void applicationWillTerminate(); + + void getSessionStorageOrigins(std::function<void (HashSet<RefPtr<WebCore::SecurityOrigin>>&&)> completionHandler); + void deleteSessionStorageOrigins(std::function<void ()> completionHandler); + void deleteSessionStorageEntriesForOrigins(const Vector<RefPtr<WebCore::SecurityOrigin>>&, std::function<void ()> completionHandler); - // FIXME: Instead of a context + C function, this should take a WTF::Function, but we currently don't - // support arguments in functions. - void getOrigins(FunctionDispatcher* callbackDispatcher, void* context, void (*callback)(const Vector<RefPtr<WebCore::SecurityOrigin>>& securityOrigins, void* context)); - void deleteEntriesForOrigin(WebCore::SecurityOrigin*); - void deleteAllEntries(); + void getLocalStorageOrigins(std::function<void (HashSet<RefPtr<WebCore::SecurityOrigin>>&&)> completionHandler); + void deleteLocalStorageEntriesForOrigin(const WebCore::SecurityOrigin&); + + void deleteLocalStorageOriginsModifiedSince(std::chrono::system_clock::time_point, std::function<void ()> completionHandler); + void deleteLocalStorageEntriesForOrigins(const Vector<RefPtr<WebCore::SecurityOrigin>>&, std::function<void ()> completionHandler); + + void getLocalStorageOriginDetails(std::function<void (Vector<LocalStorageDatabaseTracker::OriginDetails>)> completionHandler); private: - StorageManager(); + explicit StorageManager(const String& localStorageDirectory); // IPC::Connection::WorkQueueMessageReceiver. - virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; - virtual void didReceiveSyncMessage(IPC::Connection*, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>& replyEncoder) override; + virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override; + virtual void didReceiveSyncMessage(IPC::Connection&, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>& replyEncoder) override; // Message handlers. - void createLocalStorageMap(IPC::Connection*, uint64_t storageMapID, uint64_t storageNamespaceID, const SecurityOriginData&); - void createSessionStorageMap(IPC::Connection*, uint64_t storageMapID, uint64_t storageNamespaceID, const SecurityOriginData&); - void destroyStorageMap(IPC::Connection*, uint64_t storageMapID); - - void getValues(IPC::Connection*, uint64_t storageMapID, uint64_t storageMapSeed, HashMap<String, String>& values); - void setItem(IPC::Connection*, uint64_t storageAreaID, uint64_t sourceStorageAreaID, uint64_t storageMapSeed, const String& key, const String& value, const String& urlString); - void removeItem(IPC::Connection*, uint64_t storageMapID, uint64_t sourceStorageAreaID, uint64_t storageMapSeed, const String& key, const String& urlString); - void clear(IPC::Connection*, uint64_t storageMapID, uint64_t sourceStorageAreaID, uint64_t storageMapSeed, const String& urlString); + void createLocalStorageMap(IPC::Connection&, uint64_t storageMapID, uint64_t storageNamespaceID, const WebCore::SecurityOriginData&); + void createTransientLocalStorageMap(IPC::Connection&, uint64_t storageMapID, uint64_t storageNamespaceID, const WebCore::SecurityOriginData& topLevelOriginData, const WebCore::SecurityOriginData&); + void createSessionStorageMap(IPC::Connection&, uint64_t storageMapID, uint64_t storageNamespaceID, const WebCore::SecurityOriginData&); + void destroyStorageMap(IPC::Connection&, uint64_t storageMapID); - void createSessionStorageNamespaceInternal(uint64_t storageNamespaceID, IPC::Connection* allowedConnection, unsigned quotaInBytes); - void destroySessionStorageNamespaceInternal(uint64_t storageNamespaceID); - void setAllowedSessionStorageNamespaceConnectionInternal(uint64_t storageNamespaceID, IPC::Connection* allowedConnection); - void cloneSessionStorageNamespaceInternal(uint64_t storageNamespaceID, uint64_t newStorageNamespaceID); - - void invalidateConnectionInternal(IPC::Connection*); + void getValues(IPC::Connection&, uint64_t storageMapID, uint64_t storageMapSeed, HashMap<String, String>& values); + void setItem(IPC::Connection&, uint64_t storageAreaID, uint64_t sourceStorageAreaID, uint64_t storageMapSeed, const String& key, const String& value, const String& urlString); + void removeItem(IPC::Connection&, uint64_t storageMapID, uint64_t sourceStorageAreaID, uint64_t storageMapSeed, const String& key, const String& urlString); + void clear(IPC::Connection&, uint64_t storageMapID, uint64_t sourceStorageAreaID, uint64_t storageMapSeed, const String& urlString); class StorageArea; - StorageArea* findStorageArea(IPC::Connection*, uint64_t) const; + StorageArea* findStorageArea(IPC::Connection&, uint64_t) const; class LocalStorageNamespace; LocalStorageNamespace* getOrCreateLocalStorageNamespace(uint64_t storageNamespaceID); - void getOriginsInternal(FunctionDispatcher* callbackDispatcher, void* context, void (*callback)(const Vector<RefPtr<WebCore::SecurityOrigin>>& securityOrigins, void* context)); - void deleteEntriesForOriginInternal(WebCore::SecurityOrigin*); - void deleteAllEntriesInternal(); + class TransientLocalStorageNamespace; + TransientLocalStorageNamespace* getOrCreateTransientLocalStorageNamespace(uint64_t storageNamespaceID, WebCore::SecurityOrigin& topLevelOrigin); RefPtr<WorkQueue> m_queue; RefPtr<LocalStorageDatabaseTracker> m_localStorageDatabaseTracker; HashMap<uint64_t, RefPtr<LocalStorageNamespace>> m_localStorageNamespaces; + HashMap<std::pair<uint64_t, RefPtr<WebCore::SecurityOrigin>>, RefPtr<TransientLocalStorageNamespace>> m_transientLocalStorageNamespaces; + class SessionStorageNamespace; HashMap<uint64_t, RefPtr<SessionStorageNamespace>> m_sessionStorageNamespaces; diff --git a/Source/WebKit2/UIProcess/Storage/StorageManager.messages.in b/Source/WebKit2/UIProcess/Storage/StorageManager.messages.in index 59b8f3639..25789f74c 100644 --- a/Source/WebKit2/UIProcess/Storage/StorageManager.messages.in +++ b/Source/WebKit2/UIProcess/Storage/StorageManager.messages.in @@ -21,8 +21,9 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. messages -> StorageManager { - CreateLocalStorageMap(uint64_t storageMapID, uint64_t storageNamespaceID, WebKit::SecurityOriginData securityOriginData) WantsConnection - CreateSessionStorageMap(uint64_t storageMapID, uint64_t storageNamespaceID, WebKit::SecurityOriginData securityOriginData) WantsConnection + CreateLocalStorageMap(uint64_t storageMapID, uint64_t storageNamespaceID, struct WebCore::SecurityOriginData securityOriginData) WantsConnection + CreateTransientLocalStorageMap(uint64_t storageMapID, uint64_t storageNamespaceID, struct WebCore::SecurityOriginData topLevelSecurityOriginData, struct WebCore::SecurityOriginData securityOriginData) WantsConnection + CreateSessionStorageMap(uint64_t storageMapID, uint64_t storageNamespaceID, struct WebCore::SecurityOriginData securityOriginData) WantsConnection DestroyStorageMap(uint64_t storageMapID) WantsConnection GetValues(uint64_t storageMapID, uint64_t storageMapSeed) -> (HashMap<String, String> values) WantsConnection diff --git a/Source/WebKit2/UIProcess/TextChecker.h b/Source/WebKit2/UIProcess/TextChecker.h index bd08d354d..5f1d7101c 100644 --- a/Source/WebKit2/UIProcess/TextChecker.h +++ b/Source/WebKit2/UIProcess/TextChecker.h @@ -43,7 +43,7 @@ public: static void setContinuousSpellCheckingEnabled(bool); static void setGrammarCheckingEnabled(bool); -#if PLATFORM(MAC) +#if PLATFORM(COCOA) static void setAutomaticSpellingCorrectionEnabled(bool); static void setAutomaticQuoteSubstitutionEnabled(bool); static void setAutomaticDashSubstitutionEnabled(bool); @@ -62,15 +62,20 @@ public: static void toggleSubstitutionsPanelIsShowing(); #endif +#if PLATFORM(GTK) + static void setSpellCheckingLanguages(const Vector<String>&); + static Vector<String> loadedSpellCheckingLanguages(); +#endif + static void continuousSpellCheckingEnabledStateChanged(bool); static void grammarCheckingEnabledStateChanged(bool); static int64_t uniqueSpellDocumentTag(WebPageProxy*); static void closeSpellDocumentWithTag(int64_t); #if USE(UNIFIED_TEXT_CHECKING) - static Vector<WebCore::TextCheckingResult> checkTextOfParagraph(int64_t spellDocumentTag, const UChar* text, int length, uint64_t checkingTypes); + static Vector<WebCore::TextCheckingResult> checkTextOfParagraph(int64_t spellDocumentTag, StringView text, uint64_t checkingTypes); #endif - static void checkSpellingOfString(int64_t spellDocumentTag, const UChar* text, uint32_t length, int32_t& misspellingLocation, int32_t& misspellingLength); - static void checkGrammarOfString(int64_t spellDocumentTag, const UChar* text, uint32_t length, Vector<WebCore::GrammarDetail>&, int32_t& badGrammarLocation, int32_t& badGrammarLength); + static void checkSpellingOfString(int64_t spellDocumentTag, StringView text, int32_t& misspellingLocation, int32_t& misspellingLength); + static void checkGrammarOfString(int64_t spellDocumentTag, StringView text, Vector<WebCore::GrammarDetail>&, int32_t& badGrammarLocation, int32_t& badGrammarLength); static bool spellingUIIsShowing(); static void toggleSpellingUIIsShowing(); static void updateSpellingUIWithMisspelledWord(int64_t spellDocumentTag, const String& misspelledWord); diff --git a/Source/WebKit2/UIProcess/UserContent/WebScriptMessageHandler.cpp b/Source/WebKit2/UIProcess/UserContent/WebScriptMessageHandler.cpp new file mode 100644 index 000000000..bfacf041a --- /dev/null +++ b/Source/WebKit2/UIProcess/UserContent/WebScriptMessageHandler.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebScriptMessageHandler.h" + +#include "ArgumentCoders.h" + +namespace WebKit { + +void WebScriptMessageHandlerHandle::encode(IPC::ArgumentEncoder& encoder) const +{ + encoder << identifier; + encoder << name; +} + +bool WebScriptMessageHandlerHandle::decode(IPC::ArgumentDecoder& decoder, WebScriptMessageHandlerHandle& handle) +{ + if (!decoder.decode(handle.identifier)) + return false; + + if (!decoder.decode(handle.name)) + return false; + + return true; +} + +static uint64_t generateIdentifier() +{ + static uint64_t identifier; + + return ++identifier; +} + +PassRefPtr<WebScriptMessageHandler> WebScriptMessageHandler::create(std::unique_ptr<Client> client, const String& name) +{ + return adoptRef(new WebScriptMessageHandler(WTFMove(client), name)); +} + +WebScriptMessageHandler::WebScriptMessageHandler(std::unique_ptr<Client> client, const String& name) + : m_identifier(generateIdentifier()) + , m_client(WTFMove(client)) + , m_name(name) +{ +} + +WebScriptMessageHandler::~WebScriptMessageHandler() +{ +} + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/FindIndicator.h b/Source/WebKit2/UIProcess/UserContent/WebScriptMessageHandler.h index a34973b84..22d73bbcc 100644 --- a/Source/WebKit2/UIProcess/FindIndicator.h +++ b/Source/WebKit2/UIProcess/UserContent/WebScriptMessageHandler.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2014 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -23,42 +23,63 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef FindIndicator_h -#define FindIndicator_h +#ifndef WebScriptMessageHandler_h +#define WebScriptMessageHandler_h -#include "ShareableBitmap.h" -#include <WebCore/FloatRect.h> #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> -#include <wtf/Vector.h> +#include <wtf/text/WTFString.h> + +namespace IPC { +class ArgumentDecoder; +class ArgumentEncoder; +} namespace WebCore { - class GraphicsContext; +struct SecurityOriginData; +class SerializedScriptValue; } namespace WebKit { -class FindIndicator : public RefCounted<FindIndicator> { +class WebPageProxy; +class WebFrameProxy; + +struct WebScriptMessageHandlerHandle { + void encode(IPC::ArgumentEncoder&) const; + static bool decode(IPC::ArgumentDecoder&, WebScriptMessageHandlerHandle&); + + uint64_t identifier; + String name; +}; + +class WebScriptMessageHandler : public RefCounted<WebScriptMessageHandler> { public: - static PassRefPtr<FindIndicator> create(const WebCore::FloatRect& selectionRectInWindowCoordinates, const Vector<WebCore::FloatRect>& textRectsInSelectionRectCoordinates, float contentImageScaleFactor, const ShareableBitmap::Handle& contentImageHandle); - ~FindIndicator(); + class Client { + public: + virtual ~Client() { } + virtual void didPostMessage(WebPageProxy&, WebFrameProxy&, const WebCore::SecurityOriginData&, WebCore::SerializedScriptValue&) = 0; + }; - WebCore::FloatRect selectionRectInWindowCoordinates() const { return m_selectionRectInWindowCoordinates; } - WebCore::FloatRect frameRect() const; + static PassRefPtr<WebScriptMessageHandler> create(std::unique_ptr<Client>, const String& name); + virtual ~WebScriptMessageHandler(); - ShareableBitmap* contentImage() const { return m_contentImage.get(); } + WebScriptMessageHandlerHandle handle() { return { m_identifier, m_name }; } - void draw(WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect); + uint64_t identifier() const { return m_identifier; } + String name() const { return m_name; } + + Client& client() const { return *m_client; } private: - FindIndicator(const WebCore::FloatRect& selectionRect, const Vector<WebCore::FloatRect>& textRects, float contentImageScaleFactor, PassRefPtr<ShareableBitmap> contentImage); + WebScriptMessageHandler(std::unique_ptr<Client>, const String&); + + uint64_t m_identifier; - WebCore::FloatRect m_selectionRectInWindowCoordinates; - Vector<WebCore::FloatRect> m_textRectsInSelectionRectCoordinates; - float m_contentImageScaleFactor; - RefPtr<ShareableBitmap> m_contentImage; + std::unique_ptr<Client> m_client; + String m_name; }; -} // namespace WebKit - -#endif // FindIndicator_h +} // namespace API + +#endif // WebScriptMessageHandler_h diff --git a/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.cpp b/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.cpp new file mode 100644 index 000000000..b40662f06 --- /dev/null +++ b/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.cpp @@ -0,0 +1,233 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebUserContentControllerProxy.h" + +#include "APIArray.h" +#include "APIUserScript.h" +#include "APIUserStyleSheet.h" +#include "DataReference.h" +#include "WebProcessProxy.h" +#include "WebScriptMessageHandler.h" +#include "WebUserContentControllerMessages.h" +#include "WebUserContentControllerProxyMessages.h" +#include <WebCore/SerializedScriptValue.h> + +#if ENABLE(CONTENT_EXTENSIONS) +#include "APIUserContentExtension.h" +#include "WebCompiledContentExtension.h" +#endif + +namespace WebKit { + +static uint64_t generateIdentifier() +{ + static uint64_t identifier; + + return ++identifier; +} + +WebUserContentControllerProxy::WebUserContentControllerProxy() + : m_identifier(generateIdentifier()) + , m_userScripts(API::Array::create()) + , m_userStyleSheets(API::Array::create()) +{ +} + +WebUserContentControllerProxy::~WebUserContentControllerProxy() +{ + for (WebProcessProxy* process : m_processes) { + process->removeMessageReceiver(Messages::WebUserContentControllerProxy::messageReceiverName(), m_identifier); + process->didDestroyWebUserContentControllerProxy(*this); + } +} + +void WebUserContentControllerProxy::addProcess(WebProcessProxy& webProcessProxy) +{ + ASSERT(webProcessProxy.state() == WebProcessProxy::State::Running); + + if (!m_processes.add(&webProcessProxy).isNewEntry) + return; + + webProcessProxy.addMessageReceiver(Messages::WebUserContentControllerProxy::messageReceiverName(), m_identifier, *this); + + Vector<WebCore::UserScript> userScripts; + for (const auto& userScript : m_userScripts->elementsOfType<API::UserScript>()) + userScripts.append(userScript->userScript()); + webProcessProxy.connection()->send(Messages::WebUserContentController::AddUserScripts(userScripts), m_identifier); + + Vector<WebCore::UserStyleSheet> userStyleSheets; + for (const auto& userStyleSheet : m_userStyleSheets->elementsOfType<API::UserStyleSheet>()) + userStyleSheets.append(userStyleSheet->userStyleSheet()); + webProcessProxy.connection()->send(Messages::WebUserContentController::AddUserStyleSheets(userStyleSheets), m_identifier); + + Vector<WebScriptMessageHandlerHandle> messageHandlerHandles; + for (auto& handler : m_scriptMessageHandlers.values()) + messageHandlerHandles.append(handler->handle()); + webProcessProxy.connection()->send(Messages::WebUserContentController::AddUserScriptMessageHandlers(messageHandlerHandles), m_identifier); + +#if ENABLE(CONTENT_EXTENSIONS) + Vector<std::pair<String, WebCompiledContentExtensionData>> userContentExtensions; + for (const auto& userContentExtension : m_userContentExtensions.values()) + userContentExtensions.append(std::make_pair(userContentExtension->name(), userContentExtension->compiledExtension().data())); + webProcessProxy.connection()->send(Messages::WebUserContentController::AddUserContentExtensions(userContentExtensions), m_identifier); +#endif +} + +void WebUserContentControllerProxy::removeProcess(WebProcessProxy& webProcessProxy) +{ + ASSERT(m_processes.contains(&webProcessProxy)); + + m_processes.remove(&webProcessProxy); + webProcessProxy.removeMessageReceiver(Messages::WebUserContentControllerProxy::messageReceiverName(), m_identifier); +} + +void WebUserContentControllerProxy::addUserScript(API::UserScript& userScript) +{ + m_userScripts->elements().append(&userScript); + + for (WebProcessProxy* process : m_processes) + process->connection()->send(Messages::WebUserContentController::AddUserScripts({ userScript.userScript() }), m_identifier); +} + +void WebUserContentControllerProxy::removeUserScript(const API::UserScript& userScript) +{ + for (WebProcessProxy* process : m_processes) + process->connection()->send(Messages::WebUserContentController::RemoveUserScript({ userScript.userScript().url().string() }), m_identifier); + + m_userScripts->elements().removeAll(&userScript); +} + +void WebUserContentControllerProxy::removeAllUserScripts() +{ + m_userScripts->elements().clear(); + + for (WebProcessProxy* process : m_processes) + process->connection()->send(Messages::WebUserContentController::RemoveAllUserScripts(), m_identifier); +} + +void WebUserContentControllerProxy::addUserStyleSheet(API::UserStyleSheet& userStyleSheet) +{ + m_userStyleSheets->elements().append(&userStyleSheet); + + for (WebProcessProxy* process : m_processes) + process->connection()->send(Messages::WebUserContentController::AddUserStyleSheets({ userStyleSheet.userStyleSheet() }), m_identifier); +} + +void WebUserContentControllerProxy::removeUserStyleSheet(const API::UserStyleSheet& userStyleSheet) +{ + for (WebProcessProxy* process : m_processes) + process->connection()->send(Messages::WebUserContentController::RemoveUserStyleSheet({ userStyleSheet.userStyleSheet().url().string() }), m_identifier); + + m_userStyleSheets->elements().removeAll(&userStyleSheet); +} + +void WebUserContentControllerProxy::removeAllUserStyleSheets() +{ + m_userStyleSheets->elements().clear(); + + for (WebProcessProxy* process : m_processes) + process->connection()->send(Messages::WebUserContentController::RemoveAllUserStyleSheets(), m_identifier); +} + +bool WebUserContentControllerProxy::addUserScriptMessageHandler(WebScriptMessageHandler* handler) +{ + for (auto& existingHandler : m_scriptMessageHandlers.values()) { + if (existingHandler->name() == handler->name()) + return false; + } + + m_scriptMessageHandlers.add(handler->identifier(), handler); + + for (WebProcessProxy* process : m_processes) + process->connection()->send(Messages::WebUserContentController::AddUserScriptMessageHandlers({ handler->handle() }), m_identifier); + + return true; +} + +void WebUserContentControllerProxy::removeUserMessageHandlerForName(const String& name) +{ + for (auto it = m_scriptMessageHandlers.begin(), end = m_scriptMessageHandlers.end(); it != end; ++it) { + if (it->value->name() == name) { + for (WebProcessProxy* process : m_processes) + process->connection()->send(Messages::WebUserContentController::RemoveUserScriptMessageHandler(it->value->identifier()), m_identifier); + m_scriptMessageHandlers.remove(it); + return; + } + } +} + +void WebUserContentControllerProxy::didPostMessage(IPC::Connection& connection, uint64_t pageID, uint64_t frameID, const WebCore::SecurityOriginData& securityOrigin, uint64_t messageHandlerID, const IPC::DataReference& dataReference) +{ + WebPageProxy* page = WebProcessProxy::webPage(pageID); + if (!page) + return; + + WebProcessProxy* webProcess = WebProcessProxy::fromConnection(&connection); + WebFrameProxy* frame = webProcess->webFrame(frameID); + if (!frame) + return; + + if (!HashMap<uint64_t, RefPtr<WebScriptMessageHandler>>::isValidKey(messageHandlerID)) + return; + + RefPtr<WebScriptMessageHandler> handler = m_scriptMessageHandlers.get(messageHandlerID); + if (!handler) + return; + + handler->client().didPostMessage(*page, *frame, securityOrigin, + WebCore::SerializedScriptValue::adopt(dataReference.vector())); +} + +#if ENABLE(CONTENT_EXTENSIONS) +void WebUserContentControllerProxy::addUserContentExtension(API::UserContentExtension& userContentExtension) +{ + m_userContentExtensions.set(userContentExtension.name(), &userContentExtension); + + auto pair = std::make_pair(userContentExtension.name(), userContentExtension.compiledExtension().data()); + + for (WebProcessProxy* process : m_processes) + process->connection()->send(Messages::WebUserContentController::AddUserContentExtensions({ pair }), m_identifier); +} + +void WebUserContentControllerProxy::removeUserContentExtension(const String& name) +{ + m_userContentExtensions.remove(name); + + for (WebProcessProxy* process : m_processes) + process->connection()->send(Messages::WebUserContentController::RemoveUserContentExtension(name), m_identifier); +} + +void WebUserContentControllerProxy::removeAllUserContentExtensions() +{ + m_userContentExtensions.clear(); + + for (WebProcessProxy* process : m_processes) + process->connection()->send(Messages::WebUserContentController::RemoveAllUserContentExtensions(), m_identifier); +} +#endif + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.h b/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.h new file mode 100644 index 000000000..e9ff9a92e --- /dev/null +++ b/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.h @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebUserContentControllerProxy_h +#define WebUserContentControllerProxy_h + +#include "APIObject.h" +#include "MessageReceiver.h" +#include <wtf/Forward.h> +#include <wtf/HashMap.h> +#include <wtf/HashSet.h> +#include <wtf/PassRefPtr.h> +#include <wtf/Ref.h> +#include <wtf/RefCounted.h> +#include <wtf/Vector.h> +#include <wtf/text/StringHash.h> + +namespace API { +class Array; +class UserContentExtension; +class UserScript; +class UserStyleSheet; +} + +namespace IPC { +class DataReference; +} + +namespace WebCore { +struct SecurityOriginData; +} + +namespace WebKit { + +class WebProcessProxy; +class WebScriptMessageHandler; + +class WebUserContentControllerProxy : public API::ObjectImpl<API::Object::Type::UserContentController>, private IPC::MessageReceiver { +public: + static Ref<WebUserContentControllerProxy> create() + { + return adoptRef(*new WebUserContentControllerProxy); + } + explicit WebUserContentControllerProxy(); + ~WebUserContentControllerProxy(); + + uint64_t identifier() const { return m_identifier; } + + void addProcess(WebProcessProxy&); + void removeProcess(WebProcessProxy&); + + API::Array& userScripts() { return m_userScripts.get(); } + void addUserScript(API::UserScript&); + void removeUserScript(const API::UserScript&); + void removeAllUserScripts(); + + API::Array& userStyleSheets() { return m_userStyleSheets.get(); } + void addUserStyleSheet(API::UserStyleSheet&); + void removeUserStyleSheet(const API::UserStyleSheet&); + void removeAllUserStyleSheets(); + + // Returns false if there was a name conflict. + bool addUserScriptMessageHandler(WebScriptMessageHandler*); + void removeUserMessageHandlerForName(const String&); + +#if ENABLE(CONTENT_EXTENSIONS) + void addUserContentExtension(API::UserContentExtension&); + void removeUserContentExtension(const String&); + void removeAllUserContentExtensions(); +#endif + +private: + // IPC::MessageReceiver. + virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override; + + void didPostMessage(IPC::Connection&, uint64_t pageID, uint64_t frameID, const WebCore::SecurityOriginData&, uint64_t messageHandlerID, const IPC::DataReference&); + + uint64_t m_identifier; + HashSet<WebProcessProxy*> m_processes; + Ref<API::Array> m_userScripts; + Ref<API::Array> m_userStyleSheets; + HashMap<uint64_t, RefPtr<WebScriptMessageHandler>> m_scriptMessageHandlers; + +#if ENABLE(CONTENT_EXTENSIONS) + HashMap<String, RefPtr<API::UserContentExtension>> m_userContentExtensions; +#endif +}; + +} // namespace WebKit + +#endif // WebUserContentControllerProxy_h diff --git a/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.messages.in b/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.messages.in new file mode 100644 index 000000000..3536d799d --- /dev/null +++ b/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.messages.in @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +messages -> WebUserContentControllerProxy { + DidPostMessage(uint64_t pageID, uint64_t frameID, struct WebCore::SecurityOriginData frameSecurityOrigin, uint64_t messageHandlerID, IPC::DataReference message) WantsConnection +} diff --git a/Source/WebKit2/UIProcess/UserMediaPermissionCheckProxy.cpp b/Source/WebKit2/UIProcess/UserMediaPermissionCheckProxy.cpp new file mode 100644 index 000000000..340d88d15 --- /dev/null +++ b/Source/WebKit2/UIProcess/UserMediaPermissionCheckProxy.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "UserMediaPermissionCheckProxy.h" + +#include "UserMediaPermissionRequestManagerProxy.h" + +namespace WebKit { + +UserMediaPermissionCheckProxy::UserMediaPermissionCheckProxy(UserMediaPermissionRequestManagerProxy& manager, uint64_t userMediaID) + : m_manager(&manager) + , m_userMediaID(userMediaID) +{ +} + +void UserMediaPermissionCheckProxy::setHasPersistentPermission(bool allowed) +{ + ASSERT(m_manager); + if (!m_manager) + return; + + m_manager->didCompleteUserMediaPermissionCheck(m_userMediaID, allowed); + m_manager = nullptr; +} + +void UserMediaPermissionCheckProxy::invalidate() +{ + m_manager = nullptr; +} + +} // namespace WebKit + diff --git a/Source/WebKit2/UIProcess/UserMediaPermissionCheckProxy.h b/Source/WebKit2/UIProcess/UserMediaPermissionCheckProxy.h new file mode 100644 index 000000000..bb1a0a3a4 --- /dev/null +++ b/Source/WebKit2/UIProcess/UserMediaPermissionCheckProxy.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef UserMediaPermissionCheckProxy_h +#define UserMediaPermissionCheckProxy_h + +#include "APIObject.h" +#include <WebCore/RealtimeMediaSource.h> +#include <wtf/Vector.h> +#include <wtf/text/WTFString.h> + +namespace WebKit { + +class UserMediaPermissionRequestManagerProxy; + +class UserMediaPermissionCheckProxy : public API::ObjectImpl<API::Object::Type::UserMediaPermissionCheck> { +public: + static Ref<UserMediaPermissionCheckProxy> create(UserMediaPermissionRequestManagerProxy& manager, uint64_t userMediaID) + { + return adoptRef(*new UserMediaPermissionCheckProxy(manager, userMediaID)); + } + + void setHasPersistentPermission(bool allowed); + void invalidate(); + +private: + UserMediaPermissionCheckProxy(UserMediaPermissionRequestManagerProxy&, uint64_t userMediaID); + + UserMediaPermissionRequestManagerProxy* m_manager; + uint64_t m_userMediaID; +}; + +} // namespace WebKit + +#endif // UserMediaPermissionCheckProxy_h diff --git a/Source/WebKit2/UIProcess/UserMediaPermissionRequestManagerProxy.cpp b/Source/WebKit2/UIProcess/UserMediaPermissionRequestManagerProxy.cpp new file mode 100644 index 000000000..cde35fab6 --- /dev/null +++ b/Source/WebKit2/UIProcess/UserMediaPermissionRequestManagerProxy.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2014 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "UserMediaPermissionRequestManagerProxy.h" + +#include "WebPageMessages.h" +#include "WebPageProxy.h" +#include "WebProcessProxy.h" + +namespace WebKit { + +UserMediaPermissionRequestManagerProxy::UserMediaPermissionRequestManagerProxy(WebPageProxy& page) + : m_page(page) +{ +} + +void UserMediaPermissionRequestManagerProxy::invalidateRequests() +{ + for (auto& request : m_pendingUserMediaRequests.values()) + request->invalidate(); + + m_pendingUserMediaRequests.clear(); +} + +Ref<UserMediaPermissionRequestProxy> UserMediaPermissionRequestManagerProxy::createRequest(uint64_t userMediaID, const Vector<String>& audioDeviceUIDs, const Vector<String>& videoDeviceUIDs) +{ + Ref<UserMediaPermissionRequestProxy> request = UserMediaPermissionRequestProxy::create(*this, userMediaID, audioDeviceUIDs, videoDeviceUIDs); + m_pendingUserMediaRequests.add(userMediaID, request.ptr()); + return request; +} + +void UserMediaPermissionRequestManagerProxy::didReceiveUserMediaPermissionDecision(uint64_t userMediaID, bool allowed, const String& audioDeviceUID, const String& videoDeviceUID) +{ + if (!m_page.isValid()) + return; + + if (!m_pendingUserMediaRequests.take(userMediaID)) + return; + +#if ENABLE(MEDIA_STREAM) + m_page.process().send(Messages::WebPage::DidReceiveUserMediaPermissionDecision(userMediaID, allowed, audioDeviceUID, videoDeviceUID), m_page.pageID()); +#else + UNUSED_PARAM(allowed); +#endif +} + +Ref<UserMediaPermissionCheckProxy> UserMediaPermissionRequestManagerProxy::createUserMediaPermissionCheck(uint64_t userMediaID) +{ + Ref<UserMediaPermissionCheckProxy> request = UserMediaPermissionCheckProxy::create(*this, userMediaID); + m_pendingDeviceRequests.add(userMediaID, request.ptr()); + return request; +} + +void UserMediaPermissionRequestManagerProxy::didCompleteUserMediaPermissionCheck(uint64_t userMediaID, bool allowed) +{ + if (!m_page.isValid()) + return; + + if (!m_pendingDeviceRequests.take(userMediaID)) + return; + +#if ENABLE(MEDIA_STREAM) + m_page.process().send(Messages::WebPage::DidCompleteUserMediaPermissionCheck(userMediaID, allowed), m_page.pageID()); +#else + UNUSED_PARAM(allowed); +#endif +} + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/UserMediaPermissionRequestManagerProxy.h b/Source/WebKit2/UIProcess/UserMediaPermissionRequestManagerProxy.h new file mode 100644 index 000000000..88d4563b9 --- /dev/null +++ b/Source/WebKit2/UIProcess/UserMediaPermissionRequestManagerProxy.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2014 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef UserMediaPermissionRequestManagerProxy_h +#define UserMediaPermissionRequestManagerProxy_h + +#include "UserMediaPermissionCheckProxy.h" +#include "UserMediaPermissionRequestProxy.h" +#include <wtf/HashMap.h> + +namespace WebKit { + +class WebPageProxy; + +class UserMediaPermissionRequestManagerProxy { +public: + explicit UserMediaPermissionRequestManagerProxy(WebPageProxy&); + + void invalidateRequests(); + + Ref<UserMediaPermissionRequestProxy> createRequest(uint64_t userMediaID, const Vector<String>& audioDeviceUIDs, const Vector<String>& videoDeviceUIDs); + void didReceiveUserMediaPermissionDecision(uint64_t, bool allow, const String& audioDeviceUID, const String& videoDeviceUID); + + + Ref<UserMediaPermissionCheckProxy> createUserMediaPermissionCheck(uint64_t userMediaID); + void didCompleteUserMediaPermissionCheck(uint64_t, bool allow); + +private: + HashMap<uint64_t, RefPtr<UserMediaPermissionRequestProxy>> m_pendingUserMediaRequests; + HashMap<uint64_t, RefPtr<UserMediaPermissionCheckProxy>> m_pendingDeviceRequests; + WebPageProxy& m_page; +}; + +} // namespace WebKit + +#endif // UserMediaPermissionRequestManagerProxy_h diff --git a/Source/WebKit2/UIProcess/UserMediaPermissionRequestProxy.cpp b/Source/WebKit2/UIProcess/UserMediaPermissionRequestProxy.cpp new file mode 100644 index 000000000..1da57f96c --- /dev/null +++ b/Source/WebKit2/UIProcess/UserMediaPermissionRequestProxy.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2014 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "UserMediaPermissionRequestProxy.h" + +#include "UserMediaPermissionRequestManagerProxy.h" +#include <WebCore/MediaStreamTrackSourcesRequestClient.h> +#include <WebCore/RealtimeMediaSourceCenter.h> +#include <wtf/text/StringHash.h> + +namespace WebKit { + +UserMediaPermissionRequestProxy::UserMediaPermissionRequestProxy(UserMediaPermissionRequestManagerProxy& manager, uint64_t userMediaID, const Vector<String>& audioDeviceUIDs, const Vector<String>& videoDeviceUIDs) + : m_manager(&manager) + , m_userMediaID(userMediaID) + , m_videoDeviceUIDs(videoDeviceUIDs) + , m_audioDeviceUIDs(audioDeviceUIDs) +{ +} + +void UserMediaPermissionRequestProxy::allow(const String& audioDeviceUID, const String& videoDeviceUID) +{ + ASSERT(m_manager); + if (!m_manager) + return; + + m_manager->didReceiveUserMediaPermissionDecision(m_userMediaID, true, audioDeviceUID, videoDeviceUID); + m_manager = nullptr; +} + +void UserMediaPermissionRequestProxy::deny() +{ + ASSERT(m_manager); + if (!m_manager) + return; + + m_manager->didReceiveUserMediaPermissionDecision(m_userMediaID, false, emptyString(), emptyString()); + m_manager = nullptr; +} + +void UserMediaPermissionRequestProxy::invalidate() +{ + m_manager = nullptr; +} + +} // namespace WebKit + diff --git a/Source/WebKit2/UIProcess/UserMediaPermissionRequestProxy.h b/Source/WebKit2/UIProcess/UserMediaPermissionRequestProxy.h new file mode 100644 index 000000000..47cd9c249 --- /dev/null +++ b/Source/WebKit2/UIProcess/UserMediaPermissionRequestProxy.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2014 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef UserMediaPermissionRequestProxy_h +#define UserMediaPermissionRequestProxy_h + +#include "APIObject.h" +#include <WebCore/RealtimeMediaSource.h> +#include <wtf/Vector.h> +#include <wtf/text/WTFString.h> + +namespace WebKit { + +class UserMediaPermissionRequestManagerProxy; + +class UserMediaPermissionRequestProxy : public API::ObjectImpl<API::Object::Type::UserMediaPermissionRequest> { +public: + static Ref<UserMediaPermissionRequestProxy> create(UserMediaPermissionRequestManagerProxy& manager, uint64_t userMediaID, const Vector<String>& videoDeviceUIDs, const Vector<String>& audioDeviceUIDs) + { + return adoptRef(*new UserMediaPermissionRequestProxy(manager, userMediaID, videoDeviceUIDs, audioDeviceUIDs)); + } + + void allow(const String& videoDeviceUID, const String& audioDeviceUID); + void deny(); + + void invalidate(); + + bool requiresAudio() const { return m_audioDeviceUIDs.size(); } + bool requiresVideo() const { return m_videoDeviceUIDs.size(); } + + const Vector<String>& videoDeviceUIDs() const { return m_videoDeviceUIDs; } + const Vector<String>& audioDeviceUIDs() const { return m_audioDeviceUIDs; } + + const String& firstVideoDeviceUID() const { return !videoDeviceUIDs().isEmpty() ? videoDeviceUIDs().at(0) : emptyString(); } + const String& firstAudioDeviceUID() const { return !audioDeviceUIDs().isEmpty() ? audioDeviceUIDs().at(0) : emptyString(); } + +private: + UserMediaPermissionRequestProxy(UserMediaPermissionRequestManagerProxy&, uint64_t userMediaID, const Vector<String>& videoDeviceUIDs, const Vector<String>& audioDeviceUIDs); + + UserMediaPermissionRequestManagerProxy* m_manager; + uint64_t m_userMediaID; + Vector<String> m_videoDeviceUIDs; + Vector<String> m_audioDeviceUIDs; +}; + +} // namespace WebKit + +#endif // UserMediaPermissionRequestProxy_h diff --git a/Source/WebKit2/UIProcess/ViewGestureController.cpp b/Source/WebKit2/UIProcess/ViewGestureController.cpp new file mode 100644 index 000000000..135151f81 --- /dev/null +++ b/Source/WebKit2/UIProcess/ViewGestureController.cpp @@ -0,0 +1,285 @@ +/* + * Copyright (C) 2013-2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import "config.h" +#import "ViewGestureController.h" + +#import "Logging.h" +#import "RemoteLayerTreeDrawingAreaProxy.h" +#import "ViewGestureControllerMessages.h" +#import "WebPageProxy.h" +#import "WebProcessProxy.h" +#import <wtf/MathExtras.h> + +using namespace WebCore; + +namespace WebKit { + +static const std::chrono::seconds swipeSnapshotRemovalWatchdogAfterFirstVisuallyNonEmptyLayoutDuration = 3_s; +static const std::chrono::milliseconds swipeSnapshotRemovalActiveLoadMonitoringInterval = 250_ms; + +#if PLATFORM(MAC) +static const std::chrono::seconds swipeSnapshotRemovalWatchdogDuration = 5_s; +#else +static const std::chrono::seconds swipeSnapshotRemovalWatchdogDuration = 3_s; +#endif + +static HashMap<uint64_t, ViewGestureController*>& viewGestureControllersForAllPages() +{ + // The key in this map is the associated page ID. + static NeverDestroyed<HashMap<uint64_t, ViewGestureController*>> viewGestureControllers; + return viewGestureControllers.get(); +} + +ViewGestureController::ViewGestureController(WebPageProxy& webPageProxy) + : m_webPageProxy(webPageProxy) + , m_swipeActiveLoadMonitoringTimer(RunLoop::main(), this, &ViewGestureController::checkForActiveLoads) +#if PLATFORM(MAC) + , m_pendingSwipeTracker(webPageProxy, std::bind(&ViewGestureController::trackSwipeGesture, this, std::placeholders::_1, std::placeholders::_2)) +#endif +{ + m_webPageProxy.process().addMessageReceiver(Messages::ViewGestureController::messageReceiverName(), m_webPageProxy.pageID(), *this); + + viewGestureControllersForAllPages().add(webPageProxy.pageID(), this); +} + +ViewGestureController::~ViewGestureController() +{ + platformTeardown(); + + viewGestureControllersForAllPages().remove(m_webPageProxy.pageID()); + + m_webPageProxy.process().removeMessageReceiver(Messages::ViewGestureController::messageReceiverName(), m_webPageProxy.pageID()); +} + +ViewGestureController* ViewGestureController::gestureControllerForPage(uint64_t pageID) +{ + auto gestureControllerIter = viewGestureControllersForAllPages().find(pageID); + if (gestureControllerIter == viewGestureControllersForAllPages().end()) + return nullptr; + return gestureControllerIter->value; +} + +void ViewGestureController::didFirstVisuallyNonEmptyLayoutForMainFrame() +{ + if (!m_snapshotRemovalTracker.eventOccurred(SnapshotRemovalTracker::VisuallyNonEmptyLayout)) + return; + + m_snapshotRemovalTracker.cancelOutstandingEvent(SnapshotRemovalTracker::MainFrameLoad); + m_snapshotRemovalTracker.cancelOutstandingEvent(SnapshotRemovalTracker::SubresourceLoads); + m_snapshotRemovalTracker.startWatchdog(swipeSnapshotRemovalWatchdogAfterFirstVisuallyNonEmptyLayoutDuration); +} + +void ViewGestureController::didRepaintAfterNavigation() +{ + m_snapshotRemovalTracker.eventOccurred(SnapshotRemovalTracker::RepaintAfterNavigation); +} + +void ViewGestureController::didHitRenderTreeSizeThreshold() +{ + m_snapshotRemovalTracker.eventOccurred(SnapshotRemovalTracker::RenderTreeSizeThreshold); +} + +void ViewGestureController::didRestoreScrollPosition() +{ + m_snapshotRemovalTracker.eventOccurred(SnapshotRemovalTracker::ScrollPositionRestoration); +} + +void ViewGestureController::didReachMainFrameLoadTerminalState() +{ + if (!m_snapshotRemovalTracker.eventOccurred(SnapshotRemovalTracker::MainFrameLoad)) + return; + + // Coming back from the page cache will result in getting a load event, but no first visually non-empty layout. + // WebCore considers a loaded document enough to be considered visually non-empty, so that's good + // enough for us too. + m_snapshotRemovalTracker.cancelOutstandingEvent(SnapshotRemovalTracker::VisuallyNonEmptyLayout); + + // With Web-process scrolling, we check if the scroll position restoration succeeded by comparing the + // requested and actual scroll position. It's possible that we will never succeed in restoring + // the exact scroll position we wanted, in the case of a dynamic page, but we know that by + // main frame load time that we've gotten as close as we're going to get, so stop waiting. + // We don't want to do this with UI-side scrolling because scroll position restoration is baked into the transaction. + // FIXME: It seems fairly dirty to type-check the DrawingArea like this. + if (auto drawingArea = m_webPageProxy.drawingArea()) { + if (is<RemoteLayerTreeDrawingAreaProxy>(drawingArea)) + m_snapshotRemovalTracker.cancelOutstandingEvent(SnapshotRemovalTracker::ScrollPositionRestoration); + } + + checkForActiveLoads(); +} + +void ViewGestureController::didSameDocumentNavigationForMainFrame(SameDocumentNavigationType type) +{ + bool cancelledOutstandingEvent = false; + + // Same-document navigations don't have a main frame load or first visually non-empty layout. + cancelledOutstandingEvent |= m_snapshotRemovalTracker.cancelOutstandingEvent(SnapshotRemovalTracker::MainFrameLoad); + cancelledOutstandingEvent |= m_snapshotRemovalTracker.cancelOutstandingEvent(SnapshotRemovalTracker::VisuallyNonEmptyLayout); + + if (!cancelledOutstandingEvent) + return; + + if (type != SameDocumentNavigationSessionStateReplace && type != SameDocumentNavigationSessionStatePop) + return; + + checkForActiveLoads(); +} + +void ViewGestureController::checkForActiveLoads() +{ + if (m_webPageProxy.pageLoadState().isLoading()) { + if (!m_swipeActiveLoadMonitoringTimer.isActive()) + m_swipeActiveLoadMonitoringTimer.startRepeating(swipeSnapshotRemovalActiveLoadMonitoringInterval); + return; + } + + m_swipeActiveLoadMonitoringTimer.stop(); + m_snapshotRemovalTracker.eventOccurred(SnapshotRemovalTracker::SubresourceLoads); +} + +ViewGestureController::SnapshotRemovalTracker::SnapshotRemovalTracker() + : m_watchdogTimer(RunLoop::main(), this, &SnapshotRemovalTracker::watchdogTimerFired) +{ +} + +String ViewGestureController::SnapshotRemovalTracker::eventsDescription(Events event) +{ + StringBuilder description; + + if (event & ViewGestureController::SnapshotRemovalTracker::VisuallyNonEmptyLayout) + description.append("VisuallyNonEmptyLayout "); + + if (event & ViewGestureController::SnapshotRemovalTracker::RenderTreeSizeThreshold) + description.append("RenderTreeSizeThreshold "); + + if (event & ViewGestureController::SnapshotRemovalTracker::RepaintAfterNavigation) + description.append("RepaintAfterNavigation "); + + if (event & ViewGestureController::SnapshotRemovalTracker::MainFrameLoad) + description.append("MainFrameLoad "); + + if (event & ViewGestureController::SnapshotRemovalTracker::SubresourceLoads) + description.append("SubresourceLoads "); + + if (event & ViewGestureController::SnapshotRemovalTracker::ScrollPositionRestoration) + description.append("ScrollPositionRestoration "); + + return description.toString(); +} + + +void ViewGestureController::SnapshotRemovalTracker::log(const String& log) const +{ +#if !LOG_DISABLED + auto now = std::chrono::steady_clock::now(); + double millisecondsSinceStart = std::chrono::duration_cast<std::chrono::duration<double, std::milli>>(now - m_startTime).count(); +#endif + LOG(ViewGestures, "Swipe Snapshot Removal (%0.2f ms) - %s", millisecondsSinceStart, log.utf8().data()); +} + +void ViewGestureController::SnapshotRemovalTracker::start(Events desiredEvents, std::function<void()> removalCallback) +{ + m_outstandingEvents = desiredEvents; + m_removalCallback = WTFMove(removalCallback); + m_startTime = std::chrono::steady_clock::now(); + + log("start"); + + startWatchdog(swipeSnapshotRemovalWatchdogDuration); +} + +void ViewGestureController::SnapshotRemovalTracker::reset() +{ + if (m_outstandingEvents) + log("reset; had outstanding events: " + eventsDescription(m_outstandingEvents)); + m_outstandingEvents = 0; + m_watchdogTimer.stop(); + m_removalCallback = nullptr; +} + +bool ViewGestureController::SnapshotRemovalTracker::stopWaitingForEvent(Events event, const String& logReason) +{ + ASSERT(hasOneBitSet(event)); + + if (!(m_outstandingEvents & event)) + return false; + +#if LOG_DISABLED + UNUSED_PARAM(logReason); +#endif + log(logReason + eventsDescription(event)); + + m_outstandingEvents &= ~event; + + fireRemovalCallbackIfPossible(); + return true; +} + +bool ViewGestureController::SnapshotRemovalTracker::eventOccurred(Events event) +{ + return stopWaitingForEvent(event, "outstanding event occurred: "); +} + +bool ViewGestureController::SnapshotRemovalTracker::cancelOutstandingEvent(Events event) +{ + return stopWaitingForEvent(event, "wait for event cancelled: "); +} + +void ViewGestureController::SnapshotRemovalTracker::fireRemovalCallbackIfPossible() +{ + if (m_outstandingEvents) { + log("deferring removal; had outstanding events: " + eventsDescription(m_outstandingEvents)); + return; + } + + fireRemovalCallbackImmediately(); +} + +void ViewGestureController::SnapshotRemovalTracker::fireRemovalCallbackImmediately() +{ + m_watchdogTimer.stop(); + + auto removalCallback = WTFMove(m_removalCallback); + if (removalCallback) { + log("removing snapshot"); + reset(); + removalCallback(); + } +} + +void ViewGestureController::SnapshotRemovalTracker::watchdogTimerFired() +{ + log("watchdog timer fired"); + fireRemovalCallbackImmediately(); +} + +void ViewGestureController::SnapshotRemovalTracker::startWatchdog(std::chrono::seconds duration) +{ + log(String::format("(re)started watchdog timer for %lld seconds", duration.count())); + m_watchdogTimer.startOneShot(duration.count()); +} + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/VisitedLinkProvider.cpp b/Source/WebKit2/UIProcess/VisitedLinkProvider.cpp deleted file mode 100644 index 7ecae847c..000000000 --- a/Source/WebKit2/UIProcess/VisitedLinkProvider.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (C) 2010 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "VisitedLinkProvider.h" - -#include "SharedMemory.h" -#include "VisitedLinkTable.h" -#include "WebContext.h" -#include "WebProcessMessages.h" - -using namespace WebCore; - -namespace WebKit { - -static const int VisitedLinkTableMaxLoad = 2; - -VisitedLinkProvider::VisitedLinkProvider(WebContext* context) - : m_context(context) - , m_visitedLinksPopulated(false) - , m_keyCount(0) - , m_tableSize(0) - , m_pendingVisitedLinksTimer(RunLoop::main(), this, &VisitedLinkProvider::pendingVisitedLinksTimerFired) -{ -} - -void VisitedLinkProvider::processDidFinishLaunching(WebProcessProxy* process) -{ - m_processesWithoutVisitedLinkState.add(process); - - if (m_keyCount) - m_pendingVisitedLinksTimer.startOneShot(0); - - if (m_visitedLinksPopulated) - return; - - m_context->populateVisitedLinks(); - - m_visitedLinksPopulated = true; -} - -void VisitedLinkProvider::addVisitedLink(LinkHash linkHash) -{ - m_pendingVisitedLinks.add(linkHash); - - if (!m_pendingVisitedLinksTimer.isActive()) - m_pendingVisitedLinksTimer.startOneShot(0); -} - -void VisitedLinkProvider::processDidClose(WebProcessProxy* process) -{ - m_processesWithVisitedLinkState.remove(process); - m_processesWithoutVisitedLinkState.remove(process); -} - -static unsigned nextPowerOf2(unsigned v) -{ - // Taken from http://www.cs.utk.edu/~vose/c-stuff/bithacks.html - // Devised by Sean Anderson, Sepember 14, 2001 - - v--; - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; - v |= v >> 16; - v++; - - return v; -} - -static unsigned tableSizeForKeyCount(unsigned keyCount) -{ - // We want the table to be at least half empty. - unsigned tableSize = nextPowerOf2(keyCount * VisitedLinkTableMaxLoad); - - // Ensure that the table size is at least the size of a page. - size_t minimumTableSize = SharedMemory::systemPageSize() / sizeof(LinkHash); - if (tableSize < minimumTableSize) - return minimumTableSize; - - return tableSize; -} - -void VisitedLinkProvider::pendingVisitedLinksTimerFired() -{ - Vector<WebCore::LinkHash> pendingVisitedLinks; - copyToVector(m_pendingVisitedLinks, pendingVisitedLinks); - m_pendingVisitedLinks.clear(); - - unsigned currentTableSize = m_tableSize; - - // Upper bound on needed size - some of the links may be duplicates, in which case we could have done with less. - unsigned newTableSize = tableSizeForKeyCount(m_keyCount + pendingVisitedLinks.size()); - - // Never decrease table size when adding to it, to avoid unneeded churn. - newTableSize = std::max(currentTableSize, newTableSize); - - // Links that were added. - Vector<WebCore::LinkHash> addedVisitedLinks; - - // VisitedLinkTable remains internally consistent when adding, so it's OK to modify it in place - // even if a web process is accessing it at the same time. - if (currentTableSize != newTableSize) { - RefPtr<SharedMemory> newTableMemory = SharedMemory::create(newTableSize * sizeof(LinkHash)); - - // We failed to create the shared memory. - if (!newTableMemory) { - LOG_ERROR("Could not allocate shared memory for visited link table"); - return; - } - - memset(newTableMemory->data(), 0, newTableMemory->size()); - - RefPtr<SharedMemory> currentTableMemory = m_table.sharedMemory(); - - m_table.setSharedMemory(newTableMemory); - m_tableSize = newTableSize; - - if (currentTableMemory) { - ASSERT(currentTableMemory->size() == currentTableSize * sizeof(LinkHash)); - - // Go through the current hash table and re-add all entries to the new hash table. - const LinkHash* currentLinkHashes = static_cast<const LinkHash*>(currentTableMemory->data()); - for (unsigned i = 0; i < currentTableSize; ++i) { - LinkHash linkHash = currentLinkHashes[i]; - - if (!linkHash) - continue; - - // It should always be possible to add the link hash to a new table. - if (!m_table.addLinkHash(linkHash)) - ASSERT_NOT_REACHED(); - } - } - } - - for (size_t i = 0; i < pendingVisitedLinks.size(); ++i) { - if (m_table.addLinkHash(pendingVisitedLinks[i])) - addedVisitedLinks.append(pendingVisitedLinks[i]); - } - - m_keyCount += pendingVisitedLinks.size(); - - - for (HashSet<WebProcessProxy*>::iterator iter = m_processesWithVisitedLinkState.begin(); iter != m_processesWithVisitedLinkState.end(); ++iter) { - WebProcessProxy* process = *iter; - if (currentTableSize != newTableSize) { - // In the rare case of needing to resize the table, we'll bypass the VisitedLinkStateChanged optimization, - // and unconditionally use AllVisitedLinkStateChanged for the process. - m_processesWithoutVisitedLinkState.add(process); - continue; - } - - if (addedVisitedLinks.size() <= 20) - process->send(Messages::WebProcess::VisitedLinkStateChanged(addedVisitedLinks), 0); - else - process->send(Messages::WebProcess::AllVisitedLinkStateChanged(), 0); - } - - for (HashSet<WebProcessProxy*>::iterator iter = m_processesWithoutVisitedLinkState.begin(); iter != m_processesWithoutVisitedLinkState.end(); ++iter) { - WebProcessProxy* process = *iter; - - SharedMemory::Handle handle; - if (!m_table.sharedMemory()->createHandle(handle, SharedMemory::ReadOnly)) - return; - - process->send(Messages::WebProcess::SetVisitedLinkTable(handle), 0); - process->send(Messages::WebProcess::AllVisitedLinkStateChanged(), 0); - - m_processesWithVisitedLinkState.add(process); - } - - m_processesWithoutVisitedLinkState.clear(); -} - -} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/VisitedLinkStore.cpp b/Source/WebKit2/UIProcess/VisitedLinkStore.cpp new file mode 100644 index 000000000..a3fb770f5 --- /dev/null +++ b/Source/WebKit2/UIProcess/VisitedLinkStore.cpp @@ -0,0 +1,259 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "VisitedLinkStore.h" + +#include "SharedMemory.h" +#include "VisitedLinkStoreMessages.h" +#include "VisitedLinkTable.h" +#include "VisitedLinkTableControllerMessages.h" +#include "WebProcessMessages.h" +#include "WebProcessPool.h" +#include "WebProcessProxy.h" + +using namespace WebCore; + +namespace WebKit { + +static const int visitedLinkTableMaxLoad = 2; + +static uint64_t generateIdentifier() +{ + static uint64_t identifier; + + return ++identifier; +} + +Ref<VisitedLinkStore> VisitedLinkStore::create() +{ + return adoptRef(*new VisitedLinkStore); +} + +VisitedLinkStore::~VisitedLinkStore() +{ + for (WebProcessProxy* process : m_processes) { + process->removeMessageReceiver(Messages::VisitedLinkStore::messageReceiverName(), m_identifier); + process->didDestroyVisitedLinkStore(*this); + } +} + +VisitedLinkStore::VisitedLinkStore() + : m_identifier(generateIdentifier()) + , m_keyCount(0) + , m_tableSize(0) + , m_pendingVisitedLinksTimer(RunLoop::main(), this, &VisitedLinkStore::pendingVisitedLinksTimerFired) +{ +} + +void VisitedLinkStore::addProcess(WebProcessProxy& process) +{ + ASSERT(process.state() == WebProcessProxy::State::Running); + + if (!m_processes.add(&process).isNewEntry) + return; + + process.addMessageReceiver(Messages::VisitedLinkStore::messageReceiverName(), m_identifier, *this); + + if (!m_keyCount) + return; + + ASSERT(m_table.sharedMemory()); + + sendTable(process); +} + +void VisitedLinkStore::removeProcess(WebProcessProxy& process) +{ + ASSERT(m_processes.contains(&process)); + + m_processes.remove(&process); + process.removeMessageReceiver(Messages::VisitedLinkStore::messageReceiverName(), m_identifier); +} + +void VisitedLinkStore::addVisitedLinkHash(LinkHash linkHash) +{ + m_pendingVisitedLinks.add(linkHash); + + if (!m_pendingVisitedLinksTimer.isActive()) + m_pendingVisitedLinksTimer.startOneShot(0); +} + +void VisitedLinkStore::removeAll() +{ + m_pendingVisitedLinksTimer.stop(); + m_pendingVisitedLinks.clear(); + m_keyCount = 0; + m_tableSize = 0; + m_table.clear(); + + for (WebProcessProxy* process : m_processes) { + ASSERT(process->processPool().processes().contains(process)); + process->connection()->send(Messages::VisitedLinkTableController::RemoveAllVisitedLinks(), m_identifier); + } +} + +void VisitedLinkStore::webProcessWillOpenConnection(WebProcessProxy&, IPC::Connection&) +{ + // FIXME: Implement. +} + +void VisitedLinkStore::webProcessDidCloseConnection(WebProcessProxy&, IPC::Connection&) +{ + // FIXME: Implement. +} + +void VisitedLinkStore::addVisitedLinkHashFromPage(uint64_t pageID, LinkHash linkHash) +{ + if (WebPageProxy* webPageProxy = WebProcessProxy::webPage(pageID)) { + if (!webPageProxy->addsVisitedLinks()) + return; + } + + addVisitedLinkHash(linkHash); +} + +static unsigned nextPowerOf2(unsigned v) +{ + // Taken from http://www.cs.utk.edu/~vose/c-stuff/bithacks.html + // Devised by Sean Anderson, Sepember 14, 2001 + + v--; + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + v++; + + return v; +} + +static unsigned tableSizeForKeyCount(unsigned keyCount) +{ + // We want the table to be at least half empty. + unsigned tableSize = nextPowerOf2(keyCount * visitedLinkTableMaxLoad); + + // Ensure that the table size is at least the size of a page. + size_t minimumTableSize = SharedMemory::systemPageSize() / sizeof(LinkHash); + if (tableSize < minimumTableSize) + return minimumTableSize; + + return tableSize; +} + +void VisitedLinkStore::pendingVisitedLinksTimerFired() +{ + unsigned currentTableSize = m_tableSize; + unsigned newTableSize = tableSizeForKeyCount(m_keyCount + m_pendingVisitedLinks.size()); + + newTableSize = std::max(currentTableSize, newTableSize); + + if (currentTableSize != newTableSize) { + resizeTable(newTableSize); + return; + } + + Vector<WebCore::LinkHash> addedVisitedLinks; + + for (auto& linkHash : m_pendingVisitedLinks) { + if (m_table.addLinkHash(linkHash)) { + addedVisitedLinks.append(linkHash); + ++m_keyCount; + } + } + + m_pendingVisitedLinks.clear(); + + if (addedVisitedLinks.isEmpty()) + return; + + for (WebProcessProxy* process : m_processes) { + ASSERT(process->processPool().processes().contains(process)); + + if (addedVisitedLinks.size() > 20) + process->connection()->send(Messages::VisitedLinkTableController::AllVisitedLinkStateChanged(), m_identifier); + else + process->connection()->send(Messages::VisitedLinkTableController::VisitedLinkStateChanged(addedVisitedLinks), m_identifier); + } +} + +void VisitedLinkStore::resizeTable(unsigned newTableSize) +{ + RefPtr<SharedMemory> newTableMemory = SharedMemory::allocate(newTableSize * sizeof(LinkHash)); + + if (!newTableMemory) { + LOG_ERROR("Could not allocate shared memory for visited link table"); + return; + } + + memset(newTableMemory->data(), 0, newTableMemory->size()); + + RefPtr<SharedMemory> currentTableMemory = m_table.sharedMemory(); + unsigned currentTableSize = m_tableSize; + + m_table.setSharedMemory(newTableMemory); + m_tableSize = newTableSize; + + if (currentTableMemory) { + ASSERT_UNUSED(currentTableSize, currentTableMemory->size() == currentTableSize * sizeof(LinkHash)); + + // Go through the current hash table and re-add all entries to the new hash table. + const LinkHash* currentLinkHashes = static_cast<const LinkHash*>(currentTableMemory->data()); + for (unsigned i = 0; i < currentTableSize; ++i) { + LinkHash linkHash = currentLinkHashes[i]; + + if (!linkHash) + continue; + + bool didAddLinkHash = m_table.addLinkHash(linkHash); + + // It should always be possible to add the link hash to a new table. + ASSERT_UNUSED(didAddLinkHash, didAddLinkHash); + } + } + + for (auto& linkHash : m_pendingVisitedLinks) { + if (m_table.addLinkHash(linkHash)) + m_keyCount++; + } + m_pendingVisitedLinks.clear(); + + for (WebProcessProxy* process : m_processes) + sendTable(*process); +} + +void VisitedLinkStore::sendTable(WebProcessProxy& process) +{ + ASSERT(process.processPool().processes().contains(&process)); + + SharedMemory::Handle handle; + if (!m_table.sharedMemory()->createHandle(handle, SharedMemory::Protection::ReadOnly)) + return; + + process.connection()->send(Messages::VisitedLinkTableController::SetVisitedLinkTable(handle), m_identifier); +} + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/VisitedLinkProvider.h b/Source/WebKit2/UIProcess/VisitedLinkStore.h index c0d4ec963..06a4b2cf3 100644 --- a/Source/WebKit2/UIProcess/VisitedLinkProvider.h +++ b/Source/WebKit2/UIProcess/VisitedLinkStore.h @@ -23,46 +23,66 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef VisitedLinkProvider_h -#define VisitedLinkProvider_h +#ifndef VisitedLinkStore_h +#define VisitedLinkStore_h +#include "APIObject.h" +#include "MessageReceiver.h" #include "VisitedLinkTable.h" +#include "WebProcessLifetimeObserver.h" #include <WebCore/LinkHash.h> #include <wtf/Forward.h> #include <wtf/HashSet.h> +#include <wtf/RefCounted.h> #include <wtf/RunLoop.h> namespace WebKit { -class WebContext; +class WebPageProxy; class WebProcessProxy; -class VisitedLinkProvider { - WTF_MAKE_NONCOPYABLE(VisitedLinkProvider); +class VisitedLinkStore final : public API::ObjectImpl<API::Object::Type::VisitedLinkStore>, private IPC::MessageReceiver, public WebProcessLifetimeObserver { public: - explicit VisitedLinkProvider(WebContext*); + static Ref<VisitedLinkStore> create(); - void addVisitedLink(WebCore::LinkHash); + explicit VisitedLinkStore(); + virtual ~VisitedLinkStore(); - void processDidFinishLaunching(WebProcessProxy*); - void processDidClose(WebProcessProxy*); + uint64_t identifier() const { return m_identifier; } + + void addProcess(WebProcessProxy&); + void removeProcess(WebProcessProxy&); + + void addVisitedLinkHash(WebCore::LinkHash); + void removeAll(); private: + // IPC::MessageReceiver + virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override; + + // WebProcessLifetimeObserver + virtual void webProcessWillOpenConnection(WebProcessProxy&, IPC::Connection&) override; + virtual void webProcessDidCloseConnection(WebProcessProxy&, IPC::Connection&) override; + + void addVisitedLinkHashFromPage(uint64_t pageID, WebCore::LinkHash); + void pendingVisitedLinksTimerFired(); - WebContext* m_context; - bool m_visitedLinksPopulated; - HashSet<WebProcessProxy*> m_processesWithVisitedLinkState; - HashSet<WebProcessProxy*> m_processesWithoutVisitedLinkState; + void resizeTable(unsigned newTableSize); + void sendTable(WebProcessProxy&); + + HashSet<WebProcessProxy*> m_processes; + + uint64_t m_identifier; unsigned m_keyCount; unsigned m_tableSize; VisitedLinkTable m_table; HashSet<WebCore::LinkHash, WebCore::LinkHashHash> m_pendingVisitedLinks; - RunLoop::Timer<VisitedLinkProvider> m_pendingVisitedLinksTimer; + RunLoop::Timer<VisitedLinkStore> m_pendingVisitedLinksTimer; }; } // namespace WebKit -#endif // VisitedLinkProvider_h +#endif // VisitedLinkStore_h diff --git a/Source/WebKit2/UIProcess/soup/WebSoupRequestManagerProxy.messages.in b/Source/WebKit2/UIProcess/VisitedLinkStore.messages.in index 18058f5c7..e7862e365 100644 --- a/Source/WebKit2/UIProcess/soup/WebSoupRequestManagerProxy.messages.in +++ b/Source/WebKit2/UIProcess/VisitedLinkStore.messages.in @@ -1,4 +1,4 @@ -# Copyright (C) 2012 Igalia S.L. +# Copyright (C) 2014 Apple Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -20,6 +20,6 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -messages -> WebSoupRequestManagerProxy { - DidFailToLoadURIRequest(uint64_t requestID); +messages -> VisitedLinkStore { + AddVisitedLinkHashFromPage(uint64_t pageID, uint64_t linkHash) } diff --git a/Source/WebKit2/UIProcess/WKImagePreviewViewController.h b/Source/WebKit2/UIProcess/WKImagePreviewViewController.h new file mode 100644 index 000000000..852931b6b --- /dev/null +++ b/Source/WebKit2/UIProcess/WKImagePreviewViewController.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if PLATFORM(IOS) + +#import <UIKit/UIKit.h> + +#import <wtf/RetainPtr.h> + +@class _WKActivatedElementInfo; +@class _WKElementAction; + +@interface WKImagePreviewViewController : UIViewController { +@private + RetainPtr<NSArray> _imageActions; + RetainPtr<_WKActivatedElementInfo> _activatedElementInfo; +} + +- (id)initWithCGImage:(RetainPtr<CGImageRef>)image defaultActions:(RetainPtr<NSArray>)actions elementInfo:(RetainPtr<_WKActivatedElementInfo>)elementInfo; +@end + +#endif // PLATFORM(IOS) diff --git a/Source/WebKit2/UIProcess/WKInspectorHighlightView.h b/Source/WebKit2/UIProcess/WKInspectorHighlightView.h new file mode 100644 index 000000000..117660cb3 --- /dev/null +++ b/Source/WebKit2/UIProcess/WKInspectorHighlightView.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if PLATFORM(IOS) + +#import <UIKit/UIKit.h> + +namespace WebCore { +struct Highlight; +} + +@interface WKInspectorHighlightView : UIView { + NSMutableArray *_layers; // CAShapeLayers. +} +- (void)update:(const WebCore::Highlight&)highlight; +@end + +#endif diff --git a/Source/WebKit2/UIProcess/WebApplicationCacheManagerProxy.cpp b/Source/WebKit2/UIProcess/WebApplicationCacheManagerProxy.cpp deleted file mode 100644 index dcb8137eb..000000000 --- a/Source/WebKit2/UIProcess/WebApplicationCacheManagerProxy.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) 2011, 2013 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "WebApplicationCacheManagerProxy.h" - -#include "SecurityOriginData.h" -#include "WebApplicationCacheManagerMessages.h" -#include "WebApplicationCacheManagerProxyMessages.h" -#include "WebContext.h" -#include "WebSecurityOrigin.h" - -namespace WebKit { - -const char* WebApplicationCacheManagerProxy::supplementName() -{ - return "WebApplicationCacheManagerProxy"; -} - -PassRefPtr<WebApplicationCacheManagerProxy> WebApplicationCacheManagerProxy::create(WebContext* context) -{ - return adoptRef(new WebApplicationCacheManagerProxy(context)); -} - -WebApplicationCacheManagerProxy::WebApplicationCacheManagerProxy(WebContext* context) - : WebContextSupplement(context) -{ - context->addMessageReceiver(Messages::WebApplicationCacheManagerProxy::messageReceiverName(), *this); -} - -WebApplicationCacheManagerProxy::~WebApplicationCacheManagerProxy() -{ -} - - -void WebApplicationCacheManagerProxy::contextDestroyed() -{ - invalidateCallbackMap(m_arrayCallbacks); -} - -void WebApplicationCacheManagerProxy::processDidClose(WebProcessProxy*) -{ - invalidateCallbackMap(m_arrayCallbacks); -} - -bool WebApplicationCacheManagerProxy::shouldTerminate(WebProcessProxy*) const -{ - return m_arrayCallbacks.isEmpty(); -} - -void WebApplicationCacheManagerProxy::refWebContextSupplement() -{ - API::Object::ref(); -} - -void WebApplicationCacheManagerProxy::derefWebContextSupplement() -{ - API::Object::deref(); -} - -void WebApplicationCacheManagerProxy::getApplicationCacheOrigins(PassRefPtr<ArrayCallback> prpCallback) -{ - if (!context()) - return; - - RefPtr<ArrayCallback> callback = prpCallback; - - uint64_t callbackID = callback->callbackID(); - m_arrayCallbacks.set(callbackID, callback.release()); - - // FIXME (Multi-WebProcess): <rdar://problem/12239765> Make manipulating cache information work with per-tab WebProcess. - context()->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebApplicationCacheManager::GetApplicationCacheOrigins(callbackID)); -} - -void WebApplicationCacheManagerProxy::didGetApplicationCacheOrigins(const Vector<SecurityOriginData>& originDatas, uint64_t callbackID) -{ - RefPtr<ArrayCallback> callback = m_arrayCallbacks.take(callbackID); - performAPICallbackWithSecurityOriginDataVector(originDatas, callback.get()); -} - -void WebApplicationCacheManagerProxy::deleteEntriesForOrigin(WebSecurityOrigin* origin) -{ - if (!context()) - return; - - SecurityOriginData securityOriginData; - securityOriginData.protocol = origin->protocol(); - securityOriginData.host = origin->host(); - securityOriginData.port = origin->port(); - - // FIXME (Multi-WebProcess): <rdar://problem/12239765> Make manipulating cache information work with per-tab WebProcess. - context()->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebApplicationCacheManager::DeleteEntriesForOrigin(securityOriginData)); -} - -void WebApplicationCacheManagerProxy::deleteAllEntries() -{ - if (!context()) - return; - - // FIXME (Multi-WebProcess): <rdar://problem/12239765> Make manipulating cache information work with per-tab WebProcess. - context()->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebApplicationCacheManager::DeleteAllEntries()); -} - -} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebApplicationCacheManagerProxy.h b/Source/WebKit2/UIProcess/WebApplicationCacheManagerProxy.h deleted file mode 100644 index 824c21110..000000000 --- a/Source/WebKit2/UIProcess/WebApplicationCacheManagerProxy.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2011, 2013 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef WebApplicationCacheManagerProxy_h -#define WebApplicationCacheManagerProxy_h - -#include "APIObject.h" -#include "GenericCallback.h" -#include "MessageReceiver.h" -#include "WebContextSupplement.h" -#include <wtf/PassRefPtr.h> -#include <wtf/RefPtr.h> -#include <wtf/Vector.h> - -namespace IPC { - class Connection; -} - -namespace WebKit { - -class WebSecurityOrigin; -struct SecurityOriginData; - -typedef GenericCallback<WKArrayRef> ArrayCallback; - -class WebApplicationCacheManagerProxy : public API::ObjectImpl<API::Object::Type::ApplicationCacheManager>, public WebContextSupplement, private IPC::MessageReceiver { -public: - static const char* supplementName(); - - static PassRefPtr<WebApplicationCacheManagerProxy> create(WebContext*); - virtual ~WebApplicationCacheManagerProxy(); - - void getApplicationCacheOrigins(PassRefPtr<ArrayCallback>); - void deleteEntriesForOrigin(WebSecurityOrigin*); - void deleteAllEntries(); - - using API::Object::ref; - using API::Object::deref; - -private: - explicit WebApplicationCacheManagerProxy(WebContext*); - - void didGetApplicationCacheOrigins(const Vector<SecurityOriginData>&, uint64_t callbackID); - - // WebContextSupplement - virtual void contextDestroyed() override; - virtual void processDidClose(WebProcessProxy*) override; - virtual bool shouldTerminate(WebProcessProxy*) const override; - virtual void refWebContextSupplement() override; - virtual void derefWebContextSupplement() override; - - // IPC::MessageReceiver - virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; - - HashMap<uint64_t, RefPtr<ArrayCallback>> m_arrayCallbacks; -}; - -} // namespace WebKit - -#endif // WebApplicationCacheManagerProxy_h diff --git a/Source/WebKit2/UIProcess/WebApplicationCacheManagerProxy.messages.in b/Source/WebKit2/UIProcess/WebApplicationCacheManagerProxy.messages.in deleted file mode 100644 index 2aa0f670e..000000000 --- a/Source/WebKit2/UIProcess/WebApplicationCacheManagerProxy.messages.in +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright (C) 2011 Apple Inc. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR -# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -messages -> WebApplicationCacheManagerProxy { - DidGetApplicationCacheOrigins(Vector<WebKit::SecurityOriginData> originIdentifiers, uint64_t callbackID); -} diff --git a/Source/WebKit2/UIProcess/WebAutomationSession.cpp b/Source/WebKit2/UIProcess/WebAutomationSession.cpp new file mode 100644 index 000000000..44258a7e6 --- /dev/null +++ b/Source/WebKit2/UIProcess/WebAutomationSession.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebAutomationSession.h" + +#include "APIAutomationSessionClient.h" + +namespace WebKit { + +WebAutomationSession::WebAutomationSession() + : m_client(std::make_unique<API::AutomationSessionClient>()) +{ +} + +WebAutomationSession::~WebAutomationSession() +{ + ASSERT(!m_client); +} + +void WebAutomationSession::setClient(std::unique_ptr<API::AutomationSessionClient> client) +{ + m_client = WTFMove(client); +} + +// NOTE: this class could be split at some point to support local and remote automation sessions. +// For now, it only works with a remote automation driver over a RemoteInspector connection. + +#if ENABLE(REMOTE_INSPECTOR) + +// Inspector::RemoteAutomationTarget API + +void WebAutomationSession::dispatchMessageFromRemote(const String&) +{ + // FIXME: to be implemented. +} + +void WebAutomationSession::connect(Inspector::FrontendChannel* channel, bool isAutomaticConnection) +{ + UNUSED_PARAM(isAutomaticConnection); + + m_remoteChannel = channel; + setIsPaired(true); +} + +void WebAutomationSession::disconnect(Inspector::FrontendChannel* channel) +{ + m_remoteChannel = nullptr; + setIsPaired(false); +} + +#endif // ENABLE(REMOTE_INSPECTOR) + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebAutomationSession.h b/Source/WebKit2/UIProcess/WebAutomationSession.h new file mode 100644 index 000000000..8835efd6c --- /dev/null +++ b/Source/WebKit2/UIProcess/WebAutomationSession.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebAutomationSession_h +#define WebAutomationSession_h + +#include "APIObject.h" +#include <wtf/Forward.h> + +#if ENABLE(REMOTE_INSPECTOR) +#include <JavaScriptCore/RemoteAutomationTarget.h> +#endif + +namespace API { +class AutomationSessionClient; +} + +namespace WebKit { + +class WebAutomationSessionClient; + +class WebAutomationSession final : public API::ObjectImpl<API::Object::Type::AutomationSession> +#if ENABLE(REMOTE_INSPECTOR) + , public Inspector::RemoteAutomationTarget +#endif +{ +public: + WebAutomationSession(); + ~WebAutomationSession(); + + void setClient(std::unique_ptr<API::AutomationSessionClient>); + + void setSessionIdentifier(const String& sessionIdentifier) { m_sessionIdentifier = sessionIdentifier; } + String sessionIdentifier() const { return m_sessionIdentifier; } + +#if ENABLE(REMOTE_INSPECTOR) + // Inspector::RemoteAutomationTarget API + virtual String name() const override { return m_sessionIdentifier; } + virtual void dispatchMessageFromRemote(const String& message) override; + virtual void connect(Inspector::FrontendChannel*, bool isAutomaticConnection = false) override; + virtual void disconnect(Inspector::FrontendChannel*) override; +#endif + +private: + std::unique_ptr<API::AutomationSessionClient> m_client; + String m_sessionIdentifier { ASCIILiteral("Untitled Session") }; + +#if ENABLE(REMOTE_INSPECTOR) + Inspector::FrontendChannel* m_remoteChannel { nullptr }; +#endif +}; + +} // namespace WebKit + +#endif // WebAutomationSession_h diff --git a/Source/WebKit2/UIProcess/WebBackForwardList.cpp b/Source/WebKit2/UIProcess/WebBackForwardList.cpp index 411ea56c4..273431232 100644 --- a/Source/WebKit2/UIProcess/WebBackForwardList.cpp +++ b/Source/WebKit2/UIProcess/WebBackForwardList.cpp @@ -27,10 +27,25 @@ #include "WebBackForwardList.h" #include "APIArray.h" +#include "SessionState.h" #include "WebPageProxy.h" +#include <WebCore/DiagnosticLoggingKeys.h> namespace WebKit { +// FIXME: Make this static once WebBackForwardListCF.cpp is no longer using it. +uint64_t generateWebBackForwardItemID(); + +uint64_t generateWebBackForwardItemID() +{ + // These IDs exist in the UIProcess for items created by the UIProcess. + // The IDs generated here need to never collide with the IDs created in WebBackForwardListProxy in the WebProcess. + // We accomplish this by starting from 2, and only ever using even ids. + static uint64_t uniqueHistoryItemID = 0; + uniqueHistoryItemID += 2; + return uniqueHistoryItemID; +} + static const unsigned DefaultCapacity = 100; WebBackForwardList::WebBackForwardList(WebPageProxy& page) @@ -58,7 +73,8 @@ void WebBackForwardList::pageClosed() ASSERT(m_entries[i]); if (!m_entries[i]) continue; - m_page->backForwardRemovedItem(m_entries[i]->itemID()); + + didRemoveItem(*m_entries[i]); } } @@ -74,14 +90,16 @@ void WebBackForwardList::addItem(WebBackForwardListItem* newItem) if (!m_capacity || !newItem || !m_page) return; - Vector<RefPtr<API::Object>> removedItems; + Vector<RefPtr<WebBackForwardListItem>> removedItems; if (m_hasCurrentIndex) { + m_page->recordNavigationSnapshot(); + // Toss everything in the forward list. unsigned targetSize = m_currentIndex + 1; removedItems.reserveCapacity(m_entries.size() - targetSize); while (m_entries.size() > targetSize) { - m_page->backForwardRemovedItem(m_entries.last()->itemID()); + didRemoveItem(*m_entries.last()); removedItems.append(m_entries.last().release()); m_entries.removeLast(); } @@ -89,7 +107,7 @@ void WebBackForwardList::addItem(WebBackForwardListItem* newItem) // Toss the first item if the list is getting too big, as long as we're not using it // (or even if we are, if we only want 1 entry). if (m_entries.size() == m_capacity && (m_currentIndex || m_capacity == 1)) { - m_page->backForwardRemovedItem(m_entries[0]->itemID()); + didRemoveItem(*m_entries[0]); removedItems.append(m_entries[0].release()); m_entries.remove(0); @@ -108,26 +126,41 @@ void WebBackForwardList::addItem(WebBackForwardListItem* newItem) ASSERT(m_entries[i]); if (!m_entries[i]) continue; - m_page->backForwardRemovedItem(m_entries[i]->itemID()); + didRemoveItem(*m_entries[i]); removedItems.append(m_entries[i].release()); } m_entries.clear(); } - + + bool shouldKeepCurrentItem = true; + if (!m_hasCurrentIndex) { ASSERT(m_entries.isEmpty()); m_currentIndex = 0; m_hasCurrentIndex = true; - } else - m_currentIndex++; + } else { + shouldKeepCurrentItem = m_page->shouldKeepCurrentBackForwardListItemInList(m_entries[m_currentIndex].get()); + if (shouldKeepCurrentItem) + m_currentIndex++; + } - // m_current never be pointing more than 1 past the end of the entries Vector. - // If it is, something has gone wrong and we should not try to insert the new item. - ASSERT(m_currentIndex <= m_entries.size()); - if (m_currentIndex <= m_entries.size()) - m_entries.insert(m_currentIndex, newItem); + if (!shouldKeepCurrentItem) { + // m_current should never be pointing past the end of the entries Vector. + // If it is, something has gone wrong and we should not try to swap in the new item. + ASSERT(m_currentIndex < m_entries.size()); - m_page->didChangeBackForwardList(newItem, &removedItems); + removedItems.append(m_entries[m_currentIndex]); + m_entries[m_currentIndex] = newItem; + } else { + // m_current should never be pointing more than 1 past the end of the entries Vector. + // If it is, something has gone wrong and we should not try to insert the new item. + ASSERT(m_currentIndex <= m_entries.size()); + + if (m_currentIndex <= m_entries.size()) + m_entries.insert(m_currentIndex, newItem); + } + + m_page->didChangeBackForwardList(newItem, WTFMove(removedItems)); } void WebBackForwardList::goToItem(WebBackForwardListItem* item) @@ -136,16 +169,40 @@ void WebBackForwardList::goToItem(WebBackForwardListItem* item) if (!m_entries.size() || !item || !m_page || !m_hasCurrentIndex) return; - - unsigned index = 0; - for (; index < m_entries.size(); ++index) { - if (m_entries[index] == item) - break; + + size_t targetIndex = m_entries.find(item); + + // If the target item wasn't even in the list, there's nothing else to do. + if (targetIndex == notFound) + return; + + if (targetIndex < m_currentIndex) { + unsigned delta = m_entries.size() - targetIndex - 1; + String deltaValue = delta > 10 ? ASCIILiteral("over10") : String::number(delta); + m_page->logDiagnosticMessageWithValue(WebCore::DiagnosticLoggingKeys::backNavigationKey(), WebCore::DiagnosticLoggingKeys::deltaKey(), deltaValue, false /* shouldSample */); } - if (index < m_entries.size()) { - m_currentIndex = index; - m_page->didChangeBackForwardList(0, 0); + + // If we're going to an item different from the current item, ask the client if the current + // item should remain in the list. + WebBackForwardListItem* currentItem = m_entries[m_currentIndex].get(); + bool shouldKeepCurrentItem = true; + if (currentItem != item) { + m_page->recordNavigationSnapshot(); + shouldKeepCurrentItem = m_page->shouldKeepCurrentBackForwardListItemInList(m_entries[m_currentIndex].get()); } + + // If the client said to remove the current item, remove it and then update the target index. + Vector<RefPtr<WebBackForwardListItem>> removedItems; + if (!shouldKeepCurrentItem) { + removedItems.append(currentItem); + m_entries.remove(m_currentIndex); + targetIndex = m_entries.find(item); + + ASSERT(targetIndex != notFound); + } + + m_currentIndex = targetIndex; + m_page->didChangeBackForwardList(nullptr, removedItems); } WebBackForwardListItem* WebBackForwardList::currentItem() const @@ -200,7 +257,17 @@ int WebBackForwardList::forwardListCount() const return m_page && m_hasCurrentIndex ? m_entries.size() - (m_currentIndex + 1) : 0; } -PassRefPtr<API::Array> WebBackForwardList::backListAsAPIArrayWithLimit(unsigned limit) const +Ref<API::Array> WebBackForwardList::backList() const +{ + return backListAsAPIArrayWithLimit(backListCount()); +} + +Ref<API::Array> WebBackForwardList::forwardList() const +{ + return forwardListAsAPIArrayWithLimit(forwardListCount()); +} + +Ref<API::Array> WebBackForwardList::backListAsAPIArrayWithLimit(unsigned limit) const { ASSERT(!m_hasCurrentIndex || m_currentIndex < m_entries.size()); @@ -221,10 +288,10 @@ PassRefPtr<API::Array> WebBackForwardList::backListAsAPIArrayWithLimit(unsigned vector.uncheckedAppend(m_entries[i].get()); } - return API::Array::create(std::move(vector)); + return API::Array::create(WTFMove(vector)); } -PassRefPtr<API::Array> WebBackForwardList::forwardListAsAPIArrayWithLimit(unsigned limit) const +Ref<API::Array> WebBackForwardList::forwardListAsAPIArrayWithLimit(unsigned limit) const { ASSERT(!m_hasCurrentIndex || m_currentIndex < m_entries.size()); @@ -245,7 +312,27 @@ PassRefPtr<API::Array> WebBackForwardList::forwardListAsAPIArrayWithLimit(unsign vector.uncheckedAppend(m_entries[i].get()); } - return API::Array::create(std::move(vector)); + return API::Array::create(WTFMove(vector)); +} + +void WebBackForwardList::removeAllItems() +{ + ASSERT(!m_hasCurrentIndex || m_currentIndex < m_entries.size()); + + Vector<RefPtr<WebBackForwardListItem>> removedItems; + + for (auto& entry : m_entries) { + ASSERT(entry); + if (!entry) + continue; + + didRemoveItem(*entry); + removedItems.append(WTFMove(entry)); + } + + m_entries.clear(); + m_hasCurrentIndex = false; + m_page->didChangeBackForwardList(nullptr, WTFMove(removedItems)); } void WebBackForwardList::clear() @@ -257,7 +344,7 @@ void WebBackForwardList::clear() return; RefPtr<WebBackForwardListItem> currentItem = this->currentItem(); - Vector<RefPtr<API::Object>> removedItems; + Vector<RefPtr<WebBackForwardListItem>> removedItems; if (!currentItem) { // We should only ever have no current item if we also have no current item index. @@ -269,13 +356,13 @@ void WebBackForwardList::clear() if (!m_entries[i]) continue; - m_page->backForwardRemovedItem(m_entries[i]->itemID()); + didRemoveItem(*m_entries[i]); removedItems.append(m_entries[i].release()); } m_entries.clear(); m_hasCurrentIndex = false; - m_page->didChangeBackForwardList(0, &removedItems); + m_page->didChangeBackForwardList(nullptr, WTFMove(removedItems)); return; } @@ -283,7 +370,7 @@ void WebBackForwardList::clear() for (size_t i = 0; i < size; ++i) { ASSERT(m_entries[i]); if (m_entries[i] && m_entries[i] != currentItem) - m_page->backForwardRemovedItem(m_entries[i]->itemID()); + didRemoveItem(*m_entries[i]); } removedItems.reserveCapacity(size - 1); @@ -302,7 +389,69 @@ void WebBackForwardList::clear() m_hasCurrentIndex = false; } - m_page->didChangeBackForwardList(0, &removedItems); + m_page->didChangeBackForwardList(nullptr, WTFMove(removedItems)); +} + +BackForwardListState WebBackForwardList::backForwardListState(const std::function<bool (WebBackForwardListItem&)>& filter) const +{ + ASSERT(!m_hasCurrentIndex || m_currentIndex < m_entries.size()); + + BackForwardListState backForwardListState; + if (m_hasCurrentIndex) + backForwardListState.currentIndex = m_currentIndex; + + for (size_t i = 0; i < m_entries.size(); ++i) { + auto& entry = *m_entries[i]; + + if (filter && !filter(entry)) { + auto& currentIndex = backForwardListState.currentIndex; + if (currentIndex && i <= currentIndex.value() && currentIndex.value()) + --currentIndex.value(); + + continue; + } + + backForwardListState.items.append(entry.itemState()); + } + + if (backForwardListState.items.isEmpty()) + backForwardListState.currentIndex = Nullopt; + + return backForwardListState; +} + +void WebBackForwardList::restoreFromState(BackForwardListState backForwardListState) +{ + Vector<RefPtr<WebBackForwardListItem>> items; + items.reserveInitialCapacity(backForwardListState.items.size()); + + for (auto& backForwardListItemState : backForwardListState.items) { + backForwardListItemState.identifier = generateWebBackForwardItemID(); + items.uncheckedAppend(WebBackForwardListItem::create(WTFMove(backForwardListItemState), m_page->pageID())); + } + m_hasCurrentIndex = !!backForwardListState.currentIndex; + m_currentIndex = backForwardListState.currentIndex.valueOr(0); + m_entries = WTFMove(items); +} + +Vector<BackForwardListItemState> WebBackForwardList::itemStates() const +{ + Vector<BackForwardListItemState> itemStates; + itemStates.reserveInitialCapacity(m_entries.size()); + + for (const auto& entry : m_entries) + itemStates.uncheckedAppend(entry->itemState()); + + return itemStates; +} + +void WebBackForwardList::didRemoveItem(WebBackForwardListItem& backForwardListItem) +{ + m_page->backForwardRemovedItem(backForwardListItem.itemID()); + +#if PLATFORM(COCOA) + backForwardListItem.setSnapshot(nullptr); +#endif } } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebBackForwardList.h b/Source/WebKit2/UIProcess/WebBackForwardList.h index bf13d3b59..178f07e87 100644 --- a/Source/WebKit2/UIProcess/WebBackForwardList.h +++ b/Source/WebKit2/UIProcess/WebBackForwardList.h @@ -29,7 +29,7 @@ #include "APIObject.h" #include "WebBackForwardListItem.h" #include "WebPageProxy.h" -#include <wtf/PassRef.h> +#include <wtf/Ref.h> #include <wtf/RefPtr.h> #include <wtf/Vector.h> #if USE(CF) @@ -38,15 +38,11 @@ namespace WebKit { -/* - * Current - * |---------*--------------| Entries - * Back Forward - */ +struct BackForwardListState; class WebBackForwardList : public API::ObjectImpl<API::Object::Type::BackForwardList> { public: - static PassRef<WebBackForwardList> create(WebPageProxy& page) + static Ref<WebBackForwardList> create(WebPageProxy& page) { return adoptRef(*new WebBackForwardList(page)); } @@ -56,32 +52,36 @@ public: void addItem(WebBackForwardListItem*); void goToItem(WebBackForwardListItem*); + void removeAllItems(); void clear(); WebBackForwardListItem* currentItem() const; WebBackForwardListItem* backItem() const; WebBackForwardListItem* forwardItem() const; WebBackForwardListItem* itemAtIndex(int) const; - + const BackForwardListItemVector& entries() const { return m_entries; } uint32_t currentIndex() const { return m_currentIndex; } int backListCount() const; int forwardListCount() const; - PassRefPtr<API::Array> backListAsAPIArrayWithLimit(unsigned limit) const; - PassRefPtr<API::Array> forwardListAsAPIArrayWithLimit(unsigned limit) const; + Ref<API::Array> backList() const; + Ref<API::Array> forwardList() const; -#if USE(CF) - CFDictionaryRef createCFDictionaryRepresentation(WebPageProxy::WebPageProxySessionStateFilterCallback, void* context) const; - bool restoreFromCFDictionaryRepresentation(CFDictionaryRef); - bool restoreFromV0CFDictionaryRepresentation(CFDictionaryRef); - bool restoreFromV1CFDictionaryRepresentation(CFDictionaryRef); -#endif + Ref<API::Array> backListAsAPIArrayWithLimit(unsigned limit) const; + Ref<API::Array> forwardListAsAPIArrayWithLimit(unsigned limit) const; + + BackForwardListState backForwardListState(const std::function<bool (WebBackForwardListItem&)>&) const; + void restoreFromState(BackForwardListState); + + Vector<BackForwardListItemState> itemStates() const; private: explicit WebBackForwardList(WebPageProxy&); + void didRemoveItem(WebBackForwardListItem&); + WebPageProxy* m_page; BackForwardListItemVector m_entries; diff --git a/Source/WebKit2/UIProcess/WebBatteryManagerProxy.cpp b/Source/WebKit2/UIProcess/WebBatteryManagerProxy.cpp index 00075daae..4caa76e3f 100644 --- a/Source/WebKit2/UIProcess/WebBatteryManagerProxy.cpp +++ b/Source/WebKit2/UIProcess/WebBatteryManagerProxy.cpp @@ -30,7 +30,7 @@ #include "WebBatteryManagerMessages.h" #include "WebBatteryManagerProxyMessages.h" -#include "WebContext.h" +#include "WebProcessPool.h" namespace WebKit { @@ -39,16 +39,16 @@ const char* WebBatteryManagerProxy::supplementName() return "WebBatteryManagerProxy"; } -PassRefPtr<WebBatteryManagerProxy> WebBatteryManagerProxy::create(WebContext* context) +Ref<WebBatteryManagerProxy> WebBatteryManagerProxy::create(WebProcessPool* processPool) { - return adoptRef(new WebBatteryManagerProxy(context)); + return adoptRef(*new WebBatteryManagerProxy(processPool)); } -WebBatteryManagerProxy::WebBatteryManagerProxy(WebContext* context) - : WebContextSupplement(context) +WebBatteryManagerProxy::WebBatteryManagerProxy(WebProcessPool* processPool) + : WebContextSupplement(processPool) , m_isUpdating(false) { - WebContextSupplement::context()->addMessageReceiver(Messages::WebBatteryManagerProxy::messageReceiverName(), *this); + WebContextSupplement::processPool()->addMessageReceiver(Messages::WebBatteryManagerProxy::messageReceiverName(), *this); } WebBatteryManagerProxy::~WebBatteryManagerProxy() @@ -63,23 +63,23 @@ void WebBatteryManagerProxy::initializeProvider(const WKBatteryProviderBase* pro void WebBatteryManagerProxy::providerDidChangeBatteryStatus(const WTF::AtomicString& eventType, WebBatteryStatus* status) { - if (!context()) + if (!processPool()) return; - context()->sendToAllProcesses(Messages::WebBatteryManager::DidChangeBatteryStatus(eventType, status->data())); + processPool()->sendToAllProcesses(Messages::WebBatteryManager::DidChangeBatteryStatus(eventType, status->data())); } void WebBatteryManagerProxy::providerUpdateBatteryStatus(WebBatteryStatus* status) { - if (!context()) + if (!processPool()) return; - context()->sendToAllProcesses(Messages::WebBatteryManager::UpdateBatteryStatus(status->data())); + processPool()->sendToAllProcesses(Messages::WebBatteryManager::UpdateBatteryStatus(status->data())); } // WebContextSupplement -void WebBatteryManagerProxy::contextDestroyed() +void WebBatteryManagerProxy::processPoolDestroyed() { stopUpdating(); } diff --git a/Source/WebKit2/UIProcess/WebBatteryManagerProxy.h b/Source/WebKit2/UIProcess/WebBatteryManagerProxy.h index b71872329..c4cc32928 100644 --- a/Source/WebKit2/UIProcess/WebBatteryManagerProxy.h +++ b/Source/WebKit2/UIProcess/WebBatteryManagerProxy.h @@ -36,14 +36,14 @@ namespace WebKit { -class WebContext; +class WebProcessPool; class WebBatteryStatus; class WebBatteryManagerProxy : public API::ObjectImpl<API::Object::Type::BatteryManager>, public WebContextSupplement, private IPC::MessageReceiver { public: static const char* supplementName(); - static PassRefPtr<WebBatteryManagerProxy> create(WebContext*); + static Ref<WebBatteryManagerProxy> create(WebProcessPool*); virtual ~WebBatteryManagerProxy(); void initializeProvider(const WKBatteryProviderBase*); @@ -55,16 +55,16 @@ public: using API::Object::deref; private: - explicit WebBatteryManagerProxy(WebContext*); + explicit WebBatteryManagerProxy(WebProcessPool*); // WebContextSupplement - virtual void contextDestroyed() override; + virtual void processPoolDestroyed() override; virtual void processDidClose(WebProcessProxy*) override; virtual void refWebContextSupplement() override; virtual void derefWebContextSupplement() override; // IPC::MessageReceiver - virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; + virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override; void startUpdating(); void stopUpdating(); diff --git a/Source/WebKit2/UIProcess/WebConnectionToWebProcess.cpp b/Source/WebKit2/UIProcess/WebConnectionToWebProcess.cpp index d3aa27e1c..e8e08500f 100644 --- a/Source/WebKit2/UIProcess/WebConnectionToWebProcess.cpp +++ b/Source/WebKit2/UIProcess/WebConnectionToWebProcess.cpp @@ -27,7 +27,6 @@ #include "WebConnectionToWebProcess.h" #include "WebConnectionMessages.h" -#include "WebContextUserMessageCoders.h" #include "WebProcessProxy.h" namespace WebKit { @@ -45,20 +44,21 @@ WebConnectionToWebProcess::WebConnectionToWebProcess(WebProcessProxy* process) void WebConnectionToWebProcess::invalidate() { + m_process->removeMessageReceiver(Messages::WebConnection::messageReceiverName()); + m_process = 0; } // WebConnection -void WebConnectionToWebProcess::encodeMessageBody(IPC::ArgumentEncoder& encoder, API::Object* messageBody) +RefPtr<API::Object> WebConnectionToWebProcess::transformHandlesToObjects(API::Object* object) { - encoder << WebContextUserMessageEncoder(messageBody, *m_process); + return m_process->transformHandlesToObjects(object); } -bool WebConnectionToWebProcess::decodeMessageBody(IPC::ArgumentDecoder& decoder, RefPtr<API::Object>& messageBody) +RefPtr<API::Object> WebConnectionToWebProcess::transformObjectsToHandles(API::Object* object) { - WebContextUserMessageDecoder messageBodyDecoder(messageBody, *m_process); - return decoder.decode(messageBodyDecoder); + return m_process->transformObjectsToHandles(object); } bool WebConnectionToWebProcess::hasValidConnection() const diff --git a/Source/WebKit2/UIProcess/WebConnectionToWebProcess.h b/Source/WebKit2/UIProcess/WebConnectionToWebProcess.h index a13c5872f..a3664be5a 100644 --- a/Source/WebKit2/UIProcess/WebConnectionToWebProcess.h +++ b/Source/WebKit2/UIProcess/WebConnectionToWebProcess.h @@ -44,8 +44,8 @@ private: WebConnectionToWebProcess(WebProcessProxy*); // WebConnection - virtual void encodeMessageBody(IPC::ArgumentEncoder&, API::Object*) override; - virtual bool decodeMessageBody(IPC::ArgumentDecoder&, RefPtr<API::Object>&) override; + virtual RefPtr<API::Object> transformHandlesToObjects(API::Object*) override; + virtual RefPtr<API::Object> transformObjectsToHandles(API::Object*) override; virtual bool hasValidConnection() const override; // IPC::MessageSender diff --git a/Source/WebKit2/UIProcess/WebContext.cpp b/Source/WebKit2/UIProcess/WebContext.cpp deleted file mode 100644 index a463498ca..000000000 --- a/Source/WebKit2/UIProcess/WebContext.cpp +++ /dev/null @@ -1,1380 +0,0 @@ -/* - * Copyright (C) 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "WebContext.h" - -#include "APIArray.h" -#include "DownloadProxy.h" -#include "DownloadProxyMessages.h" -#include "Logging.h" -#include "MutableDictionary.h" -#include "SandboxExtension.h" -#include "SessionTracker.h" -#include "StatisticsData.h" -#include "TextChecker.h" -#include "WKContextPrivate.h" -#include "WebApplicationCacheManagerProxy.h" -#include "WebContextMessageKinds.h" -#include "WebContextMessages.h" -#include "WebContextSupplement.h" -#include "WebContextUserMessageCoders.h" -#include "WebCookieManagerProxy.h" -#include "WebCoreArgumentCoders.h" -#include "WebDatabaseManagerProxy.h" -#include "WebGeolocationManagerProxy.h" -#include "WebIconDatabase.h" -#include "WebKeyValueStorageManager.h" -#include "WebKit2Initialize.h" -#include "WebMediaCacheManagerProxy.h" -#include "WebNotificationManagerProxy.h" -#include "WebPluginSiteDataManager.h" -#include "WebPageGroup.h" -#include "WebPreferences.h" -#include "WebMemorySampler.h" -#include "WebProcessCreationParameters.h" -#include "WebProcessMessages.h" -#include "WebProcessProxy.h" -#include "WebResourceCacheManagerProxy.h" -#include <WebCore/Language.h> -#include <WebCore/LinkHash.h> -#include <WebCore/Logging.h> -#include <WebCore/ResourceRequest.h> -#include <runtime/Operations.h> -#include <wtf/CurrentTime.h> -#include <wtf/MainThread.h> -#include <wtf/NeverDestroyed.h> -#include <wtf/RunLoop.h> - -#if ENABLE(BATTERY_STATUS) -#include "WebBatteryManagerProxy.h" -#endif - -#if ENABLE(NETWORK_INFO) -#include "WebNetworkInfoManagerProxy.h" -#endif - -#if ENABLE(DATABASE_PROCESS) -#include "DatabaseProcessCreationParameters.h" -#include "DatabaseProcessMessages.h" -#endif - -#if ENABLE(NETWORK_PROCESS) -#include "NetworkProcessCreationParameters.h" -#include "NetworkProcessMessages.h" -#include "NetworkProcessProxy.h" -#endif - -#if ENABLE(CUSTOM_PROTOCOLS) -#include "CustomProtocolManagerMessages.h" -#endif - -#if USE(SOUP) -#if ENABLE(CUSTOM_PROTOCOLS) -#include "WebSoupCustomProtocolRequestManager.h" -#else -#include "WebSoupRequestManagerProxy.h" -#endif -#endif - -#ifndef NDEBUG -#include <wtf/RefCountedLeakCounter.h> -#endif - -using namespace WebCore; - -namespace WebKit { - -static const double sharedSecondaryProcessShutdownTimeout = 60; - -DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, webContextCounter, ("WebContext")); - -PassRefPtr<WebContext> WebContext::create(const String& injectedBundlePath) -{ - InitializeWebKit2(); - return adoptRef(new WebContext(injectedBundlePath)); -} - -static Vector<WebContext*>& contexts() -{ - static NeverDestroyed<Vector<WebContext*>> contexts; - return contexts; -} - -const Vector<WebContext*>& WebContext::allContexts() -{ - return contexts(); -} - -WebContext::WebContext(const String& injectedBundlePath) - : m_processModel(ProcessModelSharedSecondaryProcess) - , m_webProcessCountLimit(UINT_MAX) - , m_haveInitialEmptyProcess(false) - , m_processWithPageCache(0) - , m_defaultPageGroup(WebPageGroup::createNonNull()) - , m_injectedBundlePath(injectedBundlePath) - , m_visitedLinkProvider(this) - , m_plugInAutoStartProvider(this) - , m_alwaysUsesComplexTextCodePath(false) - , m_shouldUseFontSmoothing(true) - , m_cacheModel(CacheModelDocumentViewer) - , m_memorySamplerEnabled(false) - , m_memorySamplerInterval(1400.0) - , m_storageManager(StorageManager::create()) -#if USE(SOUP) - , m_initialHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicyOnlyFromMainDocumentDomain) -#endif - , m_shouldUseTestingNetworkSession(false) - , m_processTerminationEnabled(true) -#if ENABLE(NETWORK_PROCESS) - , m_usesNetworkProcess(false) -#endif -#if USE(SOUP) - , m_ignoreTLSErrors(true) -#endif - , m_memoryCacheDisabled(false) -{ - platformInitialize(); - - addMessageReceiver(Messages::WebContext::messageReceiverName(), *this); - addMessageReceiver(WebContextLegacyMessages::messageReceiverName(), *this); - - // NOTE: These sub-objects must be initialized after m_messageReceiverMap.. - m_iconDatabase = WebIconDatabase::create(this); -#if ENABLE(NETSCAPE_PLUGIN_API) - m_pluginSiteDataManager = WebPluginSiteDataManager::create(this); -#endif // ENABLE(NETSCAPE_PLUGIN_API) - - addSupplement<WebApplicationCacheManagerProxy>(); - addSupplement<WebCookieManagerProxy>(); - addSupplement<WebGeolocationManagerProxy>(); - addSupplement<WebKeyValueStorageManager>(); - addSupplement<WebMediaCacheManagerProxy>(); - addSupplement<WebNotificationManagerProxy>(); - addSupplement<WebResourceCacheManagerProxy>(); -#if ENABLE(SQL_DATABASE) - addSupplement<WebDatabaseManagerProxy>(); -#endif -#if USE(SOUP) -#if ENABLE(CUSTOM_PROTOCOLS) - addSupplement<WebSoupCustomProtocolRequestManager>(); -#else - addSupplement<WebSoupRequestManagerProxy>(); -#endif -#endif -#if ENABLE(BATTERY_STATUS) - addSupplement<WebBatteryManagerProxy>(); -#endif -#if ENABLE(NETWORK_INFO) - addSupplement<WebNetworkInfoManagerProxy>(); -#endif - - contexts().append(this); - - addLanguageChangeObserver(this, languageChanged); - -#if !LOG_DISABLED - WebCore::initializeLoggingChannelsIfNecessary(); - WebKit::initializeLogChannelsIfNecessary(); -#endif // !LOG_DISABLED - -#if ENABLE(NETSCAPE_PLUGIN_API) - m_pluginInfoStore.setClient(this); -#endif - -#ifndef NDEBUG - webContextCounter.increment(); -#endif - - m_storageManager->setLocalStorageDirectory(localStorageDirectory()); -} - -#if !PLATFORM(MAC) -void WebContext::platformInitialize() -{ -} -#endif - -WebContext::~WebContext() -{ - ASSERT(contexts().find(this) != notFound); - contexts().remove(contexts().find(this)); - - removeLanguageChangeObserver(this); - - m_messageReceiverMap.invalidate(); - - WebContextSupplementMap::const_iterator it = m_supplements.begin(); - WebContextSupplementMap::const_iterator end = m_supplements.end(); - for (; it != end; ++it) { - it->value->contextDestroyed(); - it->value->clearContext(); - } - - m_iconDatabase->invalidate(); - m_iconDatabase->clearContext(); - -#if ENABLE(NETSCAPE_PLUGIN_API) - m_pluginSiteDataManager->invalidate(); - m_pluginSiteDataManager->clearContext(); -#endif - - invalidateCallbackMap(m_dictionaryCallbacks); - - platformInvalidateContext(); - -#if ENABLE(NETSCAPE_PLUGIN_API) - m_pluginInfoStore.setClient(0); -#endif - -#ifndef NDEBUG - webContextCounter.decrement(); -#endif -} - -void WebContext::initializeClient(const WKContextClientBase* client) -{ - m_client.initialize(client); -} - -void WebContext::initializeInjectedBundleClient(const WKContextInjectedBundleClientBase* client) -{ - m_injectedBundleClient.initialize(client); -} - -void WebContext::initializeConnectionClient(const WKContextConnectionClientBase* client) -{ - m_connectionClient.initialize(client); -} - -void WebContext::initializeHistoryClient(const WKContextHistoryClientBase* client) -{ - m_historyClient.initialize(client); - - sendToAllProcesses(Messages::WebProcess::SetShouldTrackVisitedLinks(m_historyClient.shouldTrackVisitedLinks())); -} - -void WebContext::initializeDownloadClient(const WKContextDownloadClientBase* client) -{ - m_downloadClient.initialize(client); -} - -void WebContext::setProcessModel(ProcessModel processModel) -{ - // Guard against API misuse. - if (!m_processes.isEmpty()) - CRASH(); - if (processModel != ProcessModelSharedSecondaryProcess && !m_messagesToInjectedBundlePostedToEmptyContext.isEmpty()) - CRASH(); - - m_processModel = processModel; -} - -void WebContext::setMaximumNumberOfProcesses(unsigned maximumNumberOfProcesses) -{ - // Guard against API misuse. - if (!m_processes.isEmpty()) - CRASH(); - - if (maximumNumberOfProcesses == 0) - m_webProcessCountLimit = UINT_MAX; - else - m_webProcessCountLimit = maximumNumberOfProcesses; -} - -IPC::Connection* WebContext::networkingProcessConnection() -{ - switch (m_processModel) { - case ProcessModelSharedSecondaryProcess: -#if ENABLE(NETWORK_PROCESS) - if (m_usesNetworkProcess) - return m_networkProcess->connection(); -#endif - return m_processes[0]->connection(); - case ProcessModelMultipleSecondaryProcesses: -#if ENABLE(NETWORK_PROCESS) - ASSERT(m_usesNetworkProcess); - return m_networkProcess->connection(); -#else - break; -#endif - } - ASSERT_NOT_REACHED(); - return 0; -} - -void WebContext::languageChanged(void* context) -{ - static_cast<WebContext*>(context)->languageChanged(); -} - -void WebContext::languageChanged() -{ - sendToAllProcesses(Messages::WebProcess::UserPreferredLanguagesChanged(userPreferredLanguages())); -#if USE(SOUP) && ENABLE(NETWORK_PROCESS) - if (m_usesNetworkProcess && m_networkProcess) - m_networkProcess->send(Messages::NetworkProcess::UserPreferredLanguagesChanged(userPreferredLanguages()), 0); -#endif -} - -void WebContext::fullKeyboardAccessModeChanged(bool fullKeyboardAccessEnabled) -{ - sendToAllProcesses(Messages::WebProcess::FullKeyboardAccessModeChanged(fullKeyboardAccessEnabled)); -} - -void WebContext::textCheckerStateChanged() -{ - sendToAllProcesses(Messages::WebProcess::SetTextCheckerState(TextChecker::state())); -} - -void WebContext::setUsesNetworkProcess(bool usesNetworkProcess) -{ -#if ENABLE(NETWORK_PROCESS) - m_usesNetworkProcess = usesNetworkProcess; -#else - UNUSED_PARAM(usesNetworkProcess); -#endif -} - -bool WebContext::usesNetworkProcess() const -{ -#if ENABLE(NETWORK_PROCESS) - return m_usesNetworkProcess; -#else - return false; -#endif -} - -#if ENABLE(NETWORK_PROCESS) -void WebContext::ensureNetworkProcess() -{ - if (m_networkProcess) - return; - - m_networkProcess = NetworkProcessProxy::create(*this); - - NetworkProcessCreationParameters parameters; - - parameters.privateBrowsingEnabled = WebPreferences::anyPageGroupsAreUsingPrivateBrowsing(); - - parameters.cacheModel = m_cacheModel; - - parameters.diskCacheDirectory = diskCacheDirectory(); - if (!parameters.diskCacheDirectory.isEmpty()) - SandboxExtension::createHandleForReadWriteDirectory(parameters.diskCacheDirectory, parameters.diskCacheDirectoryExtensionHandle); - - parameters.shouldUseTestingNetworkSession = m_shouldUseTestingNetworkSession; - - // Add any platform specific parameters - platformInitializeNetworkProcess(parameters); - - // Initialize the network process. - m_networkProcess->send(Messages::NetworkProcess::InitializeNetworkProcess(parameters), 0); - -#if PLATFORM(MAC) - m_networkProcess->send(Messages::NetworkProcess::SetQOS(networkProcessLatencyQOS(), networkProcessThroughputQOS()), 0); -#endif -} - -void WebContext::networkProcessCrashed(NetworkProcessProxy* networkProcessProxy) -{ - ASSERT(m_networkProcess); - ASSERT(networkProcessProxy == m_networkProcess.get()); - - WebContextSupplementMap::const_iterator it = m_supplements.begin(); - WebContextSupplementMap::const_iterator end = m_supplements.end(); - for (; it != end; ++it) - it->value->processDidClose(networkProcessProxy); - - m_networkProcess = nullptr; - - m_client.networkProcessDidCrash(this); -} - -void WebContext::getNetworkProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply> reply) -{ - ASSERT(reply); - - ensureNetworkProcess(); - ASSERT(m_networkProcess); - - m_networkProcess->getNetworkProcessConnection(reply); -} -#endif - -#if ENABLE(DATABASE_PROCESS) -void WebContext::ensureDatabaseProcess() -{ - if (m_databaseProcess) - return; - - m_databaseProcess = DatabaseProcessProxy::create(this); - - DatabaseProcessCreationParameters parameters; - - // Indexed databases exist in a subdirectory of the "database directory path." - // Currently, the top level of that directory contains entities related to WebSQL databases. - // We should fix this, and move WebSQL into a subdirectory (https://bugs.webkit.org/show_bug.cgi?id=124807) - // In the meantime, an entity name prefixed with three underscores will not conflict with any WebSQL entities. - parameters.indexedDatabaseDirectory = pathByAppendingComponent(databaseDirectory(), "___IndexedDB"); - - m_databaseProcess->send(Messages::DatabaseProcess::InitializeDatabaseProcess(parameters), 0); -} - -void WebContext::getDatabaseProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetDatabaseProcessConnection::DelayedReply> reply) -{ - ASSERT(reply); - - ensureDatabaseProcess(); - - m_databaseProcess->getDatabaseProcessConnection(reply); -} -#endif - -void WebContext::willStartUsingPrivateBrowsing() -{ - const Vector<WebContext*>& contexts = allContexts(); - for (size_t i = 0, count = contexts.size(); i < count; ++i) - contexts[i]->setAnyPageGroupMightHavePrivateBrowsingEnabled(true); -} - -void WebContext::willStopUsingPrivateBrowsing() -{ - const Vector<WebContext*>& contexts = allContexts(); - for (size_t i = 0, count = contexts.size(); i < count; ++i) - contexts[i]->setAnyPageGroupMightHavePrivateBrowsingEnabled(false); -} - -void WebContext::windowServerConnectionStateChanged() -{ - size_t processCount = m_processes.size(); - for (size_t i = 0; i < processCount; ++i) - m_processes[i]->windowServerConnectionStateChanged(); -} - -void WebContext::setAnyPageGroupMightHavePrivateBrowsingEnabled(bool privateBrowsingEnabled) -{ - m_iconDatabase->setPrivateBrowsingEnabled(privateBrowsingEnabled); - -#if ENABLE(NETWORK_PROCESS) - if (usesNetworkProcess() && networkProcess()) { - if (privateBrowsingEnabled) - networkProcess()->send(Messages::NetworkProcess::EnsurePrivateBrowsingSession(SessionTracker::legacyPrivateSessionID), 0); - else - networkProcess()->send(Messages::NetworkProcess::DestroyPrivateBrowsingSession(SessionTracker::legacyPrivateSessionID), 0); - } -#endif // ENABLED(NETWORK_PROCESS) - - if (privateBrowsingEnabled) - sendToAllProcesses(Messages::WebProcess::EnsurePrivateBrowsingSession(SessionTracker::legacyPrivateSessionID)); - else - sendToAllProcesses(Messages::WebProcess::DestroyPrivateBrowsingSession(SessionTracker::legacyPrivateSessionID)); -} - -void (*s_invalidMessageCallback)(WKStringRef messageName); - -void WebContext::setInvalidMessageCallback(void (*invalidMessageCallback)(WKStringRef messageName)) -{ - s_invalidMessageCallback = invalidMessageCallback; -} - -void WebContext::didReceiveInvalidMessage(const IPC::StringReference& messageReceiverName, const IPC::StringReference& messageName) -{ - if (!s_invalidMessageCallback) - return; - - StringBuilder messageNameStringBuilder; - messageNameStringBuilder.append(messageReceiverName.data(), messageReceiverName.size()); - messageNameStringBuilder.append("."); - messageNameStringBuilder.append(messageName.data(), messageName.size()); - - s_invalidMessageCallback(toAPI(API::String::create(messageNameStringBuilder.toString()).get())); -} - -void WebContext::processDidCachePage(WebProcessProxy* process) -{ - if (m_processWithPageCache && m_processWithPageCache != process) - m_processWithPageCache->releasePageCache(); - m_processWithPageCache = process; -} - -WebProcessProxy& WebContext::ensureSharedWebProcess() -{ - ASSERT(m_processModel == ProcessModelSharedSecondaryProcess); - if (m_processes.isEmpty()) - createNewWebProcess(); - return *m_processes[0]; -} - -WebProcessProxy& WebContext::createNewWebProcess() -{ -#if ENABLE(NETWORK_PROCESS) - if (m_usesNetworkProcess) - ensureNetworkProcess(); -#endif - - RefPtr<WebProcessProxy> process = WebProcessProxy::create(*this); - - WebProcessCreationParameters parameters; - - parameters.injectedBundlePath = injectedBundlePath(); - if (!parameters.injectedBundlePath.isEmpty()) - SandboxExtension::createHandle(parameters.injectedBundlePath, SandboxExtension::ReadOnly, parameters.injectedBundlePathExtensionHandle); - - parameters.applicationCacheDirectory = applicationCacheDirectory(); - if (!parameters.applicationCacheDirectory.isEmpty()) - SandboxExtension::createHandleForReadWriteDirectory(parameters.applicationCacheDirectory, parameters.applicationCacheDirectoryExtensionHandle); - - parameters.databaseDirectory = databaseDirectory(); - if (!parameters.databaseDirectory.isEmpty()) - SandboxExtension::createHandleForReadWriteDirectory(parameters.databaseDirectory, parameters.databaseDirectoryExtensionHandle); - - parameters.localStorageDirectory = localStorageDirectory(); - if (!parameters.localStorageDirectory.isEmpty()) - SandboxExtension::createHandleForReadWriteDirectory(parameters.localStorageDirectory, parameters.localStorageDirectoryExtensionHandle); - - parameters.diskCacheDirectory = diskCacheDirectory(); - if (!parameters.diskCacheDirectory.isEmpty()) - SandboxExtension::createHandleForReadWriteDirectory(parameters.diskCacheDirectory, parameters.diskCacheDirectoryExtensionHandle); - - parameters.cookieStorageDirectory = cookieStorageDirectory(); - if (!parameters.cookieStorageDirectory.isEmpty()) - SandboxExtension::createHandleForReadWriteDirectory(parameters.cookieStorageDirectory, parameters.cookieStorageDirectoryExtensionHandle); - - parameters.shouldUseTestingNetworkSession = m_shouldUseTestingNetworkSession; - - parameters.shouldTrackVisitedLinks = m_historyClient.shouldTrackVisitedLinks(); - parameters.cacheModel = m_cacheModel; - parameters.languages = userPreferredLanguages(); - - copyToVector(m_schemesToRegisterAsEmptyDocument, parameters.urlSchemesRegistererdAsEmptyDocument); - copyToVector(m_schemesToRegisterAsSecure, parameters.urlSchemesRegisteredAsSecure); - copyToVector(m_schemesToSetDomainRelaxationForbiddenFor, parameters.urlSchemesForWhichDomainRelaxationIsForbidden); - copyToVector(m_schemesToRegisterAsLocal, parameters.urlSchemesRegisteredAsLocal); - copyToVector(m_schemesToRegisterAsNoAccess, parameters.urlSchemesRegisteredAsNoAccess); - copyToVector(m_schemesToRegisterAsDisplayIsolated, parameters.urlSchemesRegisteredAsDisplayIsolated); - copyToVector(m_schemesToRegisterAsCORSEnabled, parameters.urlSchemesRegisteredAsCORSEnabled); - - parameters.shouldAlwaysUseComplexTextCodePath = m_alwaysUsesComplexTextCodePath; - parameters.shouldUseFontSmoothing = m_shouldUseFontSmoothing; - - parameters.iconDatabaseEnabled = !iconDatabasePath().isEmpty(); - - parameters.terminationTimeout = (m_processModel == ProcessModelSharedSecondaryProcess) ? sharedSecondaryProcessShutdownTimeout : 0; - - parameters.textCheckerState = TextChecker::state(); - - parameters.fullKeyboardAccessEnabled = WebProcessProxy::fullKeyboardAccessEnabled(); - - parameters.defaultRequestTimeoutInterval = API::URLRequest::defaultTimeoutInterval(); - -#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) - // FIXME: There should be a generic way for supplements to add to the intialization parameters. - supplement<WebNotificationManagerProxy>()->populateCopyOfNotificationPermissions(parameters.notificationPermissions); -#endif - -#if ENABLE(NETWORK_PROCESS) - parameters.usesNetworkProcess = m_usesNetworkProcess; -#endif - - parameters.plugInAutoStartOriginHashes = m_plugInAutoStartProvider.autoStartOriginHashesCopy(); - copyToVector(m_plugInAutoStartProvider.autoStartOrigins(), parameters.plugInAutoStartOrigins); - - parameters.memoryCacheDisabled = m_memoryCacheDisabled; - - // Add any platform specific parameters - platformInitializeWebProcess(parameters); - - RefPtr<API::Object> injectedBundleInitializationUserData = m_injectedBundleClient.getInjectedBundleInitializationUserData(this); - if (!injectedBundleInitializationUserData) - injectedBundleInitializationUserData = m_injectedBundleInitializationUserData; - process->send(Messages::WebProcess::InitializeWebProcess(parameters, WebContextUserMessageEncoder(injectedBundleInitializationUserData.get(), *process)), 0); - -#if PLATFORM(MAC) - process->send(Messages::WebProcess::SetQOS(webProcessLatencyQOS(), webProcessThroughputQOS()), 0); -#endif - - if (WebPreferences::anyPageGroupsAreUsingPrivateBrowsing()) - process->send(Messages::WebProcess::EnsurePrivateBrowsingSession(SessionTracker::legacyPrivateSessionID), 0); - - m_processes.append(process); - - if (m_processModel == ProcessModelSharedSecondaryProcess) { - for (size_t i = 0; i != m_messagesToInjectedBundlePostedToEmptyContext.size(); ++i) { - std::pair<String, RefPtr<API::Object>>& message = m_messagesToInjectedBundlePostedToEmptyContext[i]; - - IPC::ArgumentEncoder messageData; - - messageData.encode(message.first); - messageData.encode(WebContextUserMessageEncoder(message.second.get(), *process)); - process->send(Messages::WebProcess::PostInjectedBundleMessage(IPC::DataReference(messageData.buffer(), messageData.bufferSize())), 0); - } - m_messagesToInjectedBundlePostedToEmptyContext.clear(); - } else - ASSERT(m_messagesToInjectedBundlePostedToEmptyContext.isEmpty()); - - return *process; -} - -void WebContext::warmInitialProcess() -{ - if (m_haveInitialEmptyProcess) { - ASSERT(!m_processes.isEmpty()); - return; - } - - if (m_processes.size() >= m_webProcessCountLimit) - return; - - createNewWebProcess(); - m_haveInitialEmptyProcess = true; -} - -void WebContext::enableProcessTermination() -{ - m_processTerminationEnabled = true; - Vector<RefPtr<WebProcessProxy>> processes = m_processes; - for (size_t i = 0; i < processes.size(); ++i) { - if (shouldTerminate(processes[i].get())) - processes[i]->terminate(); - } -} - -bool WebContext::shouldTerminate(WebProcessProxy* process) -{ - ASSERT(m_processes.contains(process)); - - if (!m_processTerminationEnabled) - return false; - - for (const auto& supplement : m_supplements.values()) { - if (!supplement->shouldTerminate(process)) - return false; - } - - return true; -} - -void WebContext::processWillOpenConnection(WebProcessProxy* process) -{ - m_storageManager->processWillOpenConnection(process); -} - -void WebContext::processWillCloseConnection(WebProcessProxy* process) -{ - m_storageManager->processWillCloseConnection(process); -} - -void WebContext::processDidFinishLaunching(WebProcessProxy* process) -{ - ASSERT(m_processes.contains(process)); - - m_visitedLinkProvider.processDidFinishLaunching(process); - - // Sometimes the memorySampler gets initialized after process initialization has happened but before the process has finished launching - // so check if it needs to be started here - if (m_memorySamplerEnabled) { - SandboxExtension::Handle sampleLogSandboxHandle; - double now = WTF::currentTime(); - String sampleLogFilePath = String::format("WebProcess%llupid%d", static_cast<unsigned long long>(now), process->processIdentifier()); - sampleLogFilePath = SandboxExtension::createHandleForTemporaryFile(sampleLogFilePath, SandboxExtension::ReadWrite, sampleLogSandboxHandle); - - process->send(Messages::WebProcess::StartMemorySampler(sampleLogSandboxHandle, sampleLogFilePath, m_memorySamplerInterval), 0); - } - - m_connectionClient.didCreateConnection(this, process->webConnection()); -} - -void WebContext::disconnectProcess(WebProcessProxy* process) -{ - ASSERT(m_processes.contains(process)); - - m_visitedLinkProvider.processDidClose(process); - - if (m_haveInitialEmptyProcess && process == m_processes.last()) - m_haveInitialEmptyProcess = false; - - // FIXME (Multi-WebProcess): <rdar://problem/12239765> Some of the invalidation calls below are still necessary in multi-process mode, but they should only affect data structures pertaining to the process being disconnected. - // Clearing everything causes assertion failures, so it's less trouble to skip that for now. - if (m_processModel != ProcessModelSharedSecondaryProcess) { - RefPtr<WebProcessProxy> protect(process); - if (m_processWithPageCache == process) - m_processWithPageCache = 0; - - static_cast<WebContextSupplement*>(supplement<WebGeolocationManagerProxy>())->processDidClose(process); - - m_processes.remove(m_processes.find(process)); - return; - } - - WebContextSupplementMap::const_iterator it = m_supplements.begin(); - WebContextSupplementMap::const_iterator end = m_supplements.end(); - for (; it != end; ++it) - it->value->processDidClose(process); - - // The vector may have the last reference to process proxy, which in turn may have the last reference to the context. - // Since vector elements are destroyed in place, we would recurse into WebProcessProxy destructor - // if it were invoked from Vector::remove(). RefPtr delays destruction until it's safe. - RefPtr<WebProcessProxy> protect(process); - if (m_processWithPageCache == process) - m_processWithPageCache = 0; - m_processes.remove(m_processes.find(process)); -} - -WebProcessProxy& WebContext::createNewWebProcessRespectingProcessCountLimit() -{ - if (m_processes.size() < m_webProcessCountLimit) - return createNewWebProcess(); - - // Choose a process with fewest pages, to achieve flat distribution. - WebProcessProxy* result = nullptr; - unsigned fewestPagesSeen = UINT_MAX; - for (unsigned i = 0; i < m_processes.size(); ++i) { - if (fewestPagesSeen > m_processes[i]->pages().size()) { - result = m_processes[i].get(); - fewestPagesSeen = m_processes[i]->pages().size(); - } - } - return *result; -} - -PassRefPtr<WebPageProxy> WebContext::createWebPage(PageClient& pageClient, WebPageConfiguration configuration) -{ - if (!configuration.pageGroup) - configuration.pageGroup = &m_defaultPageGroup.get(); - if (!configuration.session) - configuration.session = configuration.pageGroup->preferences()->privateBrowsingEnabled() ? &API::Session::legacyPrivateSession() : &API::Session::defaultSession(); - - RefPtr<WebProcessProxy> process; - if (m_processModel == ProcessModelSharedSecondaryProcess) { - process = &ensureSharedWebProcess(); - } else { - if (m_haveInitialEmptyProcess) { - process = m_processes.last(); - m_haveInitialEmptyProcess = false; - } else if (configuration.relatedPage) { - // Sharing processes, e.g. when creating the page via window.open(). - process = &configuration.relatedPage->process(); - } else - process = &createNewWebProcessRespectingProcessCountLimit(); - } - - return process->createWebPage(pageClient, std::move(configuration)); -} - -DownloadProxy* WebContext::download(WebPageProxy* initiatingPage, const ResourceRequest& request) -{ - DownloadProxy* downloadProxy = createDownloadProxy(); - uint64_t initiatingPageID = initiatingPage ? initiatingPage->pageID() : 0; - -#if ENABLE(NETWORK_PROCESS) - if (usesNetworkProcess() && networkProcess()) { - // FIXME (NetworkProcess): Replicate whatever FrameLoader::setOriginalURLForDownloadRequest does with the request here. - networkProcess()->send(Messages::NetworkProcess::DownloadRequest(downloadProxy->downloadID(), request), 0); - return downloadProxy; - } -#endif - - m_processes[0]->send(Messages::WebProcess::DownloadRequest(downloadProxy->downloadID(), initiatingPageID, request), 0); - return downloadProxy; -} - -void WebContext::postMessageToInjectedBundle(const String& messageName, API::Object* messageBody) -{ - if (m_processes.isEmpty()) { - if (m_processModel == ProcessModelSharedSecondaryProcess) - m_messagesToInjectedBundlePostedToEmptyContext.append(std::make_pair(messageName, messageBody)); - return; - } - - for (auto process : m_processes) { - // FIXME: Return early if the message body contains any references to WKPageRefs/WKFrameRefs etc. since they're local to a process. - IPC::ArgumentEncoder messageData; - messageData.encode(messageName); - messageData.encode(WebContextUserMessageEncoder(messageBody, *process.get())); - - process->send(Messages::WebProcess::PostInjectedBundleMessage(IPC::DataReference(messageData.buffer(), messageData.bufferSize())), 0); - } -} - -// InjectedBundle client - -void WebContext::didReceiveMessageFromInjectedBundle(const String& messageName, API::Object* messageBody) -{ - m_injectedBundleClient.didReceiveMessageFromInjectedBundle(this, messageName, messageBody); -} - -void WebContext::didReceiveSynchronousMessageFromInjectedBundle(const String& messageName, API::Object* messageBody, RefPtr<API::Object>& returnData) -{ - m_injectedBundleClient.didReceiveSynchronousMessageFromInjectedBundle(this, messageName, messageBody, returnData); -} - -void WebContext::populateVisitedLinks() -{ - m_historyClient.populateVisitedLinks(this); -} - -WebContext::Statistics& WebContext::statistics() -{ - static Statistics statistics = Statistics(); - - return statistics; -} - -#if ENABLE(NETSCAPE_PLUGIN_API) -void WebContext::setAdditionalPluginsDirectory(const String& directory) -{ - Vector<String> directories; - directories.append(directory); - - m_pluginInfoStore.setAdditionalPluginsDirectories(directories); -} -#endif // ENABLE(NETSCAPE_PLUGIN_API) - -void WebContext::setAlwaysUsesComplexTextCodePath(bool alwaysUseComplexText) -{ - m_alwaysUsesComplexTextCodePath = alwaysUseComplexText; - sendToAllProcesses(Messages::WebProcess::SetAlwaysUsesComplexTextCodePath(alwaysUseComplexText)); -} - -void WebContext::setShouldUseFontSmoothing(bool useFontSmoothing) -{ - m_shouldUseFontSmoothing = useFontSmoothing; - sendToAllProcesses(Messages::WebProcess::SetShouldUseFontSmoothing(useFontSmoothing)); -} - -void WebContext::registerURLSchemeAsEmptyDocument(const String& urlScheme) -{ - m_schemesToRegisterAsEmptyDocument.add(urlScheme); - sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsEmptyDocument(urlScheme)); -} - -void WebContext::registerURLSchemeAsSecure(const String& urlScheme) -{ - m_schemesToRegisterAsSecure.add(urlScheme); - sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsSecure(urlScheme)); -} - -void WebContext::setDomainRelaxationForbiddenForURLScheme(const String& urlScheme) -{ - m_schemesToSetDomainRelaxationForbiddenFor.add(urlScheme); - sendToAllProcesses(Messages::WebProcess::SetDomainRelaxationForbiddenForURLScheme(urlScheme)); -} - -void WebContext::registerURLSchemeAsLocal(const String& urlScheme) -{ - m_schemesToRegisterAsLocal.add(urlScheme); - sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsLocal(urlScheme)); -} - -void WebContext::registerURLSchemeAsNoAccess(const String& urlScheme) -{ - m_schemesToRegisterAsNoAccess.add(urlScheme); - sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsNoAccess(urlScheme)); -} - -void WebContext::registerURLSchemeAsDisplayIsolated(const String& urlScheme) -{ - m_schemesToRegisterAsDisplayIsolated.add(urlScheme); - sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsDisplayIsolated(urlScheme)); -} - -void WebContext::registerURLSchemeAsCORSEnabled(const String& urlScheme) -{ - m_schemesToRegisterAsCORSEnabled.add(urlScheme); - sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsCORSEnabled(urlScheme)); -} - -#if ENABLE(CUSTOM_PROTOCOLS) -HashSet<String>& WebContext::globalURLSchemesWithCustomProtocolHandlers() -{ - static NeverDestroyed<HashSet<String>> set; - return set; -} - -void WebContext::registerGlobalURLSchemeAsHavingCustomProtocolHandlers(const String& urlScheme) -{ - if (!urlScheme) - return; - - String schemeLower = urlScheme.lower(); - globalURLSchemesWithCustomProtocolHandlers().add(schemeLower); - for (auto* context : allContexts()) - context->registerSchemeForCustomProtocol(schemeLower); -} - -void WebContext::unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers(const String& urlScheme) -{ - if (!urlScheme) - return; - - String schemeLower = urlScheme.lower(); - globalURLSchemesWithCustomProtocolHandlers().remove(schemeLower); - for (auto* context : allContexts()) - context->unregisterSchemeForCustomProtocol(schemeLower); -} -#endif - -void WebContext::setCacheModel(CacheModel cacheModel) -{ - m_cacheModel = cacheModel; - sendToAllProcesses(Messages::WebProcess::SetCacheModel(static_cast<uint32_t>(m_cacheModel))); - - // FIXME: Inform the Network Process if in use. -} - -void WebContext::setDefaultRequestTimeoutInterval(double timeoutInterval) -{ - sendToAllProcesses(Messages::WebProcess::SetDefaultRequestTimeoutInterval(timeoutInterval)); -} - -void WebContext::addVisitedLink(const String& visitedURL) -{ - if (visitedURL.isEmpty()) - return; - - LinkHash linkHash = visitedLinkHash(visitedURL); - addVisitedLinkHash(linkHash); -} - -void WebContext::addVisitedLinkHash(LinkHash linkHash) -{ - m_visitedLinkProvider.addVisitedLink(linkHash); -} - -DownloadProxy* WebContext::createDownloadProxy() -{ -#if ENABLE(NETWORK_PROCESS) - if (usesNetworkProcess()) { - ensureNetworkProcess(); - ASSERT(m_networkProcess); - return m_networkProcess->createDownloadProxy(); - } -#endif - - return ensureSharedWebProcess().createDownloadProxy(); -} - -void WebContext::addMessageReceiver(IPC::StringReference messageReceiverName, IPC::MessageReceiver& messageReceiver) -{ - m_messageReceiverMap.addMessageReceiver(messageReceiverName, messageReceiver); -} - -void WebContext::addMessageReceiver(IPC::StringReference messageReceiverName, uint64_t destinationID, IPC::MessageReceiver& messageReceiver) -{ - m_messageReceiverMap.addMessageReceiver(messageReceiverName, destinationID, messageReceiver); -} - -void WebContext::removeMessageReceiver(IPC::StringReference messageReceiverName, uint64_t destinationID) -{ - m_messageReceiverMap.removeMessageReceiver(messageReceiverName, destinationID); -} - -bool WebContext::dispatchMessage(IPC::Connection* connection, IPC::MessageDecoder& decoder) -{ - return m_messageReceiverMap.dispatchMessage(connection, decoder); -} - -bool WebContext::dispatchSyncMessage(IPC::Connection* connection, IPC::MessageDecoder& decoder, std::unique_ptr<IPC::MessageEncoder>& replyEncoder) -{ - return m_messageReceiverMap.dispatchSyncMessage(connection, decoder, replyEncoder); -} - -void WebContext::didReceiveMessage(IPC::Connection* connection, IPC::MessageDecoder& decoder) -{ - if (decoder.messageReceiverName() == Messages::WebContext::messageReceiverName()) { - didReceiveWebContextMessage(connection, decoder); - return; - } - - if (decoder.messageReceiverName() == WebContextLegacyMessages::messageReceiverName() - && decoder.messageName() == WebContextLegacyMessages::postMessageMessageName()) { - String messageName; - RefPtr<API::Object> messageBody; - WebContextUserMessageDecoder messageBodyDecoder(messageBody, *WebProcessProxy::fromConnection(connection)); - if (!decoder.decode(messageName)) - return; - if (!decoder.decode(messageBodyDecoder)) - return; - - didReceiveMessageFromInjectedBundle(messageName, messageBody.get()); - return; - } - - ASSERT_NOT_REACHED(); -} - -void WebContext::didReceiveSyncMessage(IPC::Connection* connection, IPC::MessageDecoder& decoder, std::unique_ptr<IPC::MessageEncoder>& replyEncoder) -{ - if (decoder.messageReceiverName() == Messages::WebContext::messageReceiverName()) { - didReceiveSyncWebContextMessage(connection, decoder, replyEncoder); - return; - } - - if (decoder.messageReceiverName() == WebContextLegacyMessages::messageReceiverName() - && decoder.messageName() == WebContextLegacyMessages::postSynchronousMessageMessageName()) { - // FIXME: We should probably encode something in the case that the arguments do not decode correctly. - - WebProcessProxy* process = WebProcessProxy::fromConnection(connection); - - String messageName; - RefPtr<API::Object> messageBody; - WebContextUserMessageDecoder messageBodyDecoder(messageBody, *process); - if (!decoder.decode(messageName)) - return; - if (!decoder.decode(messageBodyDecoder)) - return; - - RefPtr<API::Object> returnData; - didReceiveSynchronousMessageFromInjectedBundle(messageName, messageBody.get(), returnData); - replyEncoder->encode(WebContextUserMessageEncoder(returnData.get(), *process)); - return; - } - - ASSERT_NOT_REACHED(); -} - -void WebContext::setEnhancedAccessibility(bool flag) -{ - sendToAllProcesses(Messages::WebProcess::SetEnhancedAccessibility(flag)); -} - -void WebContext::startMemorySampler(const double interval) -{ - // For new WebProcesses we will also want to start the Memory Sampler - m_memorySamplerEnabled = true; - m_memorySamplerInterval = interval; - - // For UIProcess -#if ENABLE(MEMORY_SAMPLER) - WebMemorySampler::shared()->start(interval); -#endif - - // For WebProcess - SandboxExtension::Handle sampleLogSandboxHandle; - double now = WTF::currentTime(); - String sampleLogFilePath = String::format("WebProcess%llu", static_cast<unsigned long long>(now)); - sampleLogFilePath = SandboxExtension::createHandleForTemporaryFile(sampleLogFilePath, SandboxExtension::ReadWrite, sampleLogSandboxHandle); - - sendToAllProcesses(Messages::WebProcess::StartMemorySampler(sampleLogSandboxHandle, sampleLogFilePath, interval)); -} - -void WebContext::stopMemorySampler() -{ - // For WebProcess - m_memorySamplerEnabled = false; - - // For UIProcess -#if ENABLE(MEMORY_SAMPLER) - WebMemorySampler::shared()->stop(); -#endif - - sendToAllProcesses(Messages::WebProcess::StopMemorySampler()); -} - -String WebContext::applicationCacheDirectory() const -{ - if (!m_overrideApplicationCacheDirectory.isEmpty()) - return m_overrideApplicationCacheDirectory; - - return platformDefaultApplicationCacheDirectory(); -} - -String WebContext::databaseDirectory() const -{ - if (!m_overrideDatabaseDirectory.isEmpty()) - return m_overrideDatabaseDirectory; - - return platformDefaultDatabaseDirectory(); -} - -void WebContext::setIconDatabasePath(const String& path) -{ - m_overrideIconDatabasePath = path; - m_iconDatabase->setDatabasePath(path); -} - -String WebContext::iconDatabasePath() const -{ - if (!m_overrideIconDatabasePath.isEmpty()) - return m_overrideIconDatabasePath; - - return platformDefaultIconDatabasePath(); -} - -void WebContext::setLocalStorageDirectory(const String& directory) -{ - m_overrideLocalStorageDirectory = directory; - m_storageManager->setLocalStorageDirectory(localStorageDirectory()); -} - -String WebContext::localStorageDirectory() const -{ - if (!m_overrideLocalStorageDirectory.isEmpty()) - return m_overrideLocalStorageDirectory; - - return platformDefaultLocalStorageDirectory(); -} - -String WebContext::diskCacheDirectory() const -{ - if (!m_overrideDiskCacheDirectory.isEmpty()) - return m_overrideDiskCacheDirectory; - - return platformDefaultDiskCacheDirectory(); -} - -String WebContext::cookieStorageDirectory() const -{ - if (!m_overrideCookieStorageDirectory.isEmpty()) - return m_overrideCookieStorageDirectory; - - return platformDefaultCookieStorageDirectory(); -} - -void WebContext::useTestingNetworkSession() -{ - ASSERT(m_processes.isEmpty()); -#if ENABLE(NETWORK_PROCESS) - ASSERT(!m_networkProcess); - - if (m_networkProcess) - return; -#endif - - if (!m_processes.isEmpty()) - return; - - m_shouldUseTestingNetworkSession = true; -} - -void WebContext::allowSpecificHTTPSCertificateForHost(const WebCertificateInfo* certificate, const String& host) -{ -#if ENABLE(NETWORK_PROCESS) - if (m_usesNetworkProcess && m_networkProcess) { - m_networkProcess->send(Messages::NetworkProcess::AllowSpecificHTTPSCertificateForHost(certificate->certificateInfo(), host), 0); - return; - } -#endif - -#if USE(SOUP) - m_processes[0]->send(Messages::WebProcess::AllowSpecificHTTPSCertificateForHost(certificate->certificateInfo(), host), 0); - return; -#else - UNUSED_PARAM(certificate); - UNUSED_PARAM(host); -#endif - -#if !PLATFORM(IOS) - ASSERT_NOT_REACHED(); -#endif -} - -void WebContext::setHTTPPipeliningEnabled(bool enabled) -{ -#if PLATFORM(MAC) - ResourceRequest::setHTTPPipeliningEnabled(enabled); -#else - UNUSED_PARAM(enabled); -#endif -} - -bool WebContext::httpPipeliningEnabled() const -{ -#if PLATFORM(MAC) - return ResourceRequest::httpPipeliningEnabled(); -#else - return false; -#endif -} - -void WebContext::getStatistics(uint32_t statisticsMask, PassRefPtr<DictionaryCallback> callback) -{ - if (!statisticsMask) { - callback->invalidate(); - return; - } - - RefPtr<StatisticsRequest> request = StatisticsRequest::create(callback); - - if (statisticsMask & StatisticsRequestTypeWebContent) - requestWebContentStatistics(request.get()); - - if (statisticsMask & StatisticsRequestTypeNetworking) - requestNetworkingStatistics(request.get()); -} - -void WebContext::requestWebContentStatistics(StatisticsRequest* request) -{ - if (m_processModel == ProcessModelSharedSecondaryProcess) { - if (m_processes.isEmpty()) - return; - - uint64_t requestID = request->addOutstandingRequest(); - m_statisticsRequests.set(requestID, request); - m_processes[0]->send(Messages::WebProcess::GetWebCoreStatistics(requestID), 0); - - } else { - // FIXME (Multi-WebProcess) <rdar://problem/13200059>: Make getting statistics from multiple WebProcesses work. - } -} - -void WebContext::requestNetworkingStatistics(StatisticsRequest* request) -{ - bool networkProcessUnavailable; -#if ENABLE(NETWORK_PROCESS) - networkProcessUnavailable = !m_usesNetworkProcess || !m_networkProcess; -#else - networkProcessUnavailable = true; -#endif - - if (networkProcessUnavailable) { - LOG_ERROR("Attempt to get NetworkProcess statistics but the NetworkProcess is unavailable"); - return; - } - -#if ENABLE(NETWORK_PROCESS) - uint64_t requestID = request->addOutstandingRequest(); - m_statisticsRequests.set(requestID, request); - m_networkProcess->send(Messages::NetworkProcess::GetNetworkProcessStatistics(requestID), 0); -#else - UNUSED_PARAM(request); -#endif -} - -#if !PLATFORM(MAC) -void WebContext::dummy(bool&) -{ -} -#endif - -void WebContext::didGetStatistics(const StatisticsData& statisticsData, uint64_t requestID) -{ - RefPtr<StatisticsRequest> request = m_statisticsRequests.take(requestID); - if (!request) { - LOG_ERROR("Cannot report networking statistics."); - return; - } - - request->completedRequest(requestID, statisticsData); -} - -void WebContext::garbageCollectJavaScriptObjects() -{ - sendToAllProcesses(Messages::WebProcess::GarbageCollectJavaScriptObjects()); -} - -void WebContext::setJavaScriptGarbageCollectorTimerEnabled(bool flag) -{ - sendToAllProcesses(Messages::WebProcess::SetJavaScriptGarbageCollectorTimerEnabled(flag)); -} - -void WebContext::addPlugInAutoStartOriginHash(const String& pageOrigin, unsigned plugInOriginHash) -{ - m_plugInAutoStartProvider.addAutoStartOriginHash(pageOrigin, plugInOriginHash); -} - -void WebContext::plugInDidReceiveUserInteraction(unsigned plugInOriginHash) -{ - m_plugInAutoStartProvider.didReceiveUserInteraction(plugInOriginHash); -} - -PassRefPtr<ImmutableDictionary> WebContext::plugInAutoStartOriginHashes() const -{ - return m_plugInAutoStartProvider.autoStartOriginsTableCopy(); -} - -void WebContext::setPlugInAutoStartOriginHashes(ImmutableDictionary& dictionary) -{ - m_plugInAutoStartProvider.setAutoStartOriginsTable(dictionary); -} - -void WebContext::setPlugInAutoStartOrigins(API::Array& array) -{ - m_plugInAutoStartProvider.setAutoStartOriginsArray(array); -} - -void WebContext::setPlugInAutoStartOriginsFilteringOutEntriesAddedAfterTime(ImmutableDictionary& dictionary, double time) -{ - m_plugInAutoStartProvider.setAutoStartOriginsFilteringOutEntriesAddedAfterTime(dictionary, time); -} - -#if ENABLE(CUSTOM_PROTOCOLS) -void WebContext::registerSchemeForCustomProtocol(const String& scheme) -{ - sendToNetworkingProcess(Messages::CustomProtocolManager::RegisterScheme(scheme)); -} - -void WebContext::unregisterSchemeForCustomProtocol(const String& scheme) -{ - sendToNetworkingProcess(Messages::CustomProtocolManager::UnregisterScheme(scheme)); -} -#endif - -#if ENABLE(NETSCAPE_PLUGIN_API) -void WebContext::pluginInfoStoreDidLoadPlugins(PluginInfoStore* store) -{ -#ifdef NDEBUG - UNUSED_PARAM(store); -#endif - ASSERT(store == &m_pluginInfoStore); - - Vector<PluginModuleInfo> pluginModules = m_pluginInfoStore.plugins(); - - Vector<RefPtr<API::Object>> plugins; - plugins.reserveInitialCapacity(pluginModules.size()); - - for (const auto& pluginModule : pluginModules) { - ImmutableDictionary::MapType map; - map.set(ASCIILiteral("path"), API::String::create(pluginModule.path)); - map.set(ASCIILiteral("name"), API::String::create(pluginModule.info.name)); - map.set(ASCIILiteral("file"), API::String::create(pluginModule.info.file)); - map.set(ASCIILiteral("desc"), API::String::create(pluginModule.info.desc)); - - Vector<RefPtr<API::Object>> mimeTypes; - mimeTypes.reserveInitialCapacity(pluginModule.info.mimes.size()); - for (const auto& mimeClassInfo : pluginModule.info.mimes) - mimeTypes.uncheckedAppend(API::String::create(mimeClassInfo.type)); - map.set(ASCIILiteral("mimes"), API::Array::create(std::move(mimeTypes))); - -#if PLATFORM(MAC) - map.set(ASCIILiteral("bundleId"), API::String::create(pluginModule.bundleIdentifier)); - map.set(ASCIILiteral("version"), API::String::create(pluginModule.versionString)); -#endif - - plugins.uncheckedAppend(ImmutableDictionary::create(std::move(map))); - } - - m_client.plugInInformationBecameAvailable(this, API::Array::create(std::move(plugins)).get()); -} -#endif - -void WebContext::setMemoryCacheDisabled(bool disabled) -{ - m_memoryCacheDisabled = disabled; - sendToAllProcesses(Messages::WebProcess::SetMemoryCacheDisabled(disabled)); -} - -} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebContextClient.cpp b/Source/WebKit2/UIProcess/WebContextClient.cpp index fc718d92a..46b36d196 100644 --- a/Source/WebKit2/UIProcess/WebContextClient.cpp +++ b/Source/WebKit2/UIProcess/WebContextClient.cpp @@ -27,27 +27,27 @@ #include "WebContextClient.h" #include "APIArray.h" -#include "WebContext.h" +#include "WebProcessPool.h" namespace WebKit { -void WebContextClient::plugInAutoStartOriginHashesChanged(WebContext* context) +void WebContextClient::plugInAutoStartOriginHashesChanged(WebProcessPool* processPool) { if (!m_client.plugInAutoStartOriginHashesChanged) return; - m_client.plugInAutoStartOriginHashesChanged(toAPI(context), m_client.base.clientInfo); + m_client.plugInAutoStartOriginHashesChanged(toAPI(processPool), m_client.base.clientInfo); } -void WebContextClient::networkProcessDidCrash(WebContext* context) +void WebContextClient::networkProcessDidCrash(WebProcessPool* processPool) { if (!m_client.networkProcessDidCrash) return; - m_client.networkProcessDidCrash(toAPI(context), m_client.base.clientInfo); + m_client.networkProcessDidCrash(toAPI(processPool), m_client.base.clientInfo); } -void WebContextClient::plugInInformationBecameAvailable(WebContext* context, API::Array* plugInInfo) +void WebContextClient::plugInInformationBecameAvailable(WebProcessPool* processPool, API::Array* plugInInfo) { if (!m_client.plugInInformationBecameAvailable) return; @@ -55,7 +55,15 @@ void WebContextClient::plugInInformationBecameAvailable(WebContext* context, API // FIXME: The API contract expects us to hand a reference to the array here. This is wrong. plugInInfo->ref(); - m_client.plugInInformationBecameAvailable(toAPI(context), toAPI(plugInInfo), m_client.base.clientInfo); + m_client.plugInInformationBecameAvailable(toAPI(processPool), toAPI(plugInInfo), m_client.base.clientInfo); +} + +PassRefPtr<API::Data> WebContextClient::copyWebCryptoMasterKey(WebProcessPool* processPool) +{ + if (!m_client.copyWebCryptoMasterKey) + return nullptr; + + return adoptRef(toImpl(m_client.copyWebCryptoMasterKey(toAPI(processPool), m_client.base.clientInfo))); } } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebContextClient.h b/Source/WebKit2/UIProcess/WebContextClient.h index 03cdf5132..44d43cdfa 100644 --- a/Source/WebKit2/UIProcess/WebContextClient.h +++ b/Source/WebKit2/UIProcess/WebContextClient.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Apple Inc. All rights reserved. + * Copyright (C) 2012, 2014 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,25 +27,28 @@ #define WebContextClient_h #include "APIClient.h" +#include "APIData.h" #include "WKContext.h" namespace API { class Array; template<> struct ClientTraits<WKContextClientBase> { - typedef std::tuple<WKContextClientV0> Versions; + typedef std::tuple<WKContextClientV0, WKContextClientV1> Versions; }; } + namespace WebKit { -class WebContext; +class WebProcessPool; class WebContextClient : public API::Client<WKContextClientBase> { public: - void plugInAutoStartOriginHashesChanged(WebContext*); - void networkProcessDidCrash(WebContext*); - void plugInInformationBecameAvailable(WebContext*, API::Array*); + void plugInAutoStartOriginHashesChanged(WebProcessPool*); + void networkProcessDidCrash(WebProcessPool*); + void plugInInformationBecameAvailable(WebProcessPool*, API::Array*); + PassRefPtr<API::Data> copyWebCryptoMasterKey(WebProcessPool*); }; } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebContextConnectionClient.cpp b/Source/WebKit2/UIProcess/WebContextConnectionClient.cpp index 336e44967..3b47d0e13 100644 --- a/Source/WebKit2/UIProcess/WebContextConnectionClient.cpp +++ b/Source/WebKit2/UIProcess/WebContextConnectionClient.cpp @@ -27,15 +27,16 @@ #include "WebContextConnectionClient.h" #include "WKAPICast.h" +#include "WebProcessPool.h" namespace WebKit { -void WebContextConnectionClient::didCreateConnection(WebContext* context, WebConnection* connection) +void WebContextConnectionClient::didCreateConnection(WebProcessPool* processPool, WebConnection* connection) { if (!m_client.didCreateConnection) return; - m_client.didCreateConnection(toAPI(context), toAPI(connection), m_client.base.clientInfo); + m_client.didCreateConnection(toAPI(processPool), toAPI(connection), m_client.base.clientInfo); } } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebContextConnectionClient.h b/Source/WebKit2/UIProcess/WebContextConnectionClient.h index 11e1ccf2c..23bddf0a6 100644 --- a/Source/WebKit2/UIProcess/WebContextConnectionClient.h +++ b/Source/WebKit2/UIProcess/WebContextConnectionClient.h @@ -38,11 +38,11 @@ template<> struct ClientTraits<WKContextConnectionClientBase> { namespace WebKit { class WebConnection; -class WebContext; +class WebProcessPool; class WebContextConnectionClient : public API::Client<WKContextConnectionClientBase> { public: - void didCreateConnection(WebContext*, WebConnection*); + void didCreateConnection(WebProcessPool*, WebConnection*); }; } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebContextInjectedBundleClient.cpp b/Source/WebKit2/UIProcess/WebContextInjectedBundleClient.cpp index 9baf4f71b..c68a163ee 100644 --- a/Source/WebKit2/UIProcess/WebContextInjectedBundleClient.cpp +++ b/Source/WebKit2/UIProcess/WebContextInjectedBundleClient.cpp @@ -27,36 +27,37 @@ #include "WebContextInjectedBundleClient.h" #include "WKAPICast.h" +#include "WebProcessPool.h" #include <wtf/text/WTFString.h> using namespace WebCore; namespace WebKit { -void WebContextInjectedBundleClient::didReceiveMessageFromInjectedBundle(WebContext* context, const String& messageName, API::Object* messageBody) +void WebContextInjectedBundleClient::didReceiveMessageFromInjectedBundle(WebProcessPool* processPool, const String& messageName, API::Object* messageBody) { if (!m_client.didReceiveMessageFromInjectedBundle) return; - m_client.didReceiveMessageFromInjectedBundle(toAPI(context), toAPI(messageName.impl()), toAPI(messageBody), m_client.base.clientInfo); + m_client.didReceiveMessageFromInjectedBundle(toAPI(processPool), toAPI(messageName.impl()), toAPI(messageBody), m_client.base.clientInfo); } -void WebContextInjectedBundleClient::didReceiveSynchronousMessageFromInjectedBundle(WebContext* context, const String& messageName, API::Object* messageBody, RefPtr<API::Object>& returnData) +void WebContextInjectedBundleClient::didReceiveSynchronousMessageFromInjectedBundle(WebProcessPool* processPool, const String& messageName, API::Object* messageBody, RefPtr<API::Object>& returnData) { if (!m_client.didReceiveSynchronousMessageFromInjectedBundle) return; WKTypeRef returnDataRef = 0; - m_client.didReceiveSynchronousMessageFromInjectedBundle(toAPI(context), toAPI(messageName.impl()), toAPI(messageBody), &returnDataRef, m_client.base.clientInfo); + m_client.didReceiveSynchronousMessageFromInjectedBundle(toAPI(processPool), toAPI(messageName.impl()), toAPI(messageBody), &returnDataRef, m_client.base.clientInfo); returnData = adoptRef(toImpl(returnDataRef)); } -PassRefPtr<API::Object> WebContextInjectedBundleClient::getInjectedBundleInitializationUserData(WebContext* context) +PassRefPtr<API::Object> WebContextInjectedBundleClient::getInjectedBundleInitializationUserData(WebProcessPool* processPool) { if (!m_client.getInjectedBundleInitializationUserData) return 0; - return toImpl(m_client.getInjectedBundleInitializationUserData(toAPI(context), m_client.base.clientInfo)); + return adoptRef(toImpl(m_client.getInjectedBundleInitializationUserData(toAPI(processPool), m_client.base.clientInfo))); } } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebContextInjectedBundleClient.h b/Source/WebKit2/UIProcess/WebContextInjectedBundleClient.h index f24c66f8e..c934fe8b7 100644 --- a/Source/WebKit2/UIProcess/WebContextInjectedBundleClient.h +++ b/Source/WebKit2/UIProcess/WebContextInjectedBundleClient.h @@ -40,13 +40,13 @@ template<> struct ClientTraits<WKContextInjectedBundleClientBase> { namespace WebKit { -class WebContext; +class WebProcessPool; class WebContextInjectedBundleClient : public API::Client<WKContextInjectedBundleClientBase> { public: - void didReceiveMessageFromInjectedBundle(WebContext*, const String&, API::Object*); - void didReceiveSynchronousMessageFromInjectedBundle(WebContext*, const String&, API::Object*, RefPtr<API::Object>& returnData); - PassRefPtr<API::Object> getInjectedBundleInitializationUserData(WebContext*); + void didReceiveMessageFromInjectedBundle(WebProcessPool*, const String&, API::Object*); + void didReceiveSynchronousMessageFromInjectedBundle(WebProcessPool*, const String&, API::Object*, RefPtr<API::Object>& returnData); + PassRefPtr<API::Object> getInjectedBundleInitializationUserData(WebProcessPool*); }; } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebContextMenuProxy.cpp b/Source/WebKit2/UIProcess/WebContextMenuProxy.cpp index 4c4cb26c0..1764c4615 100644 --- a/Source/WebKit2/UIProcess/WebContextMenuProxy.cpp +++ b/Source/WebKit2/UIProcess/WebContextMenuProxy.cpp @@ -26,9 +26,13 @@ #include "config.h" #include "WebContextMenuProxy.h" +#if ENABLE(CONTEXT_MENUS) + namespace WebKit { -WebContextMenuProxy::WebContextMenuProxy() +WebContextMenuProxy::WebContextMenuProxy(const ContextMenuContextData& context, const UserData& userData) + : m_context(context) + , m_userData(userData) { } @@ -37,3 +41,5 @@ WebContextMenuProxy::~WebContextMenuProxy() } } // namespace WebKit + +#endif diff --git a/Source/WebKit2/UIProcess/WebContextMenuProxy.h b/Source/WebKit2/UIProcess/WebContextMenuProxy.h index 098552d3a..0a849addc 100644 --- a/Source/WebKit2/UIProcess/WebContextMenuProxy.h +++ b/Source/WebKit2/UIProcess/WebContextMenuProxy.h @@ -26,29 +26,31 @@ #ifndef WebContextMenuProxy_h #define WebContextMenuProxy_h -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> -#include <wtf/Vector.h> +#if ENABLE(CONTEXT_MENUS) -namespace WebCore { - class IntPoint; -} +#include "ContextMenuContextData.h" +#include "UserData.h" +#include <wtf/RefCounted.h> namespace WebKit { -class WebContextMenuItemData; +class WebContextMenuItem; -class WebContextMenuProxy : public RefCounted<WebContextMenuProxy> { +class WebContextMenuProxy { public: virtual ~WebContextMenuProxy(); - virtual void showContextMenu(const WebCore::IntPoint&, const Vector<WebContextMenuItemData>& items) = 0; - virtual void hideContextMenu() = 0; + virtual void show() = 0; protected: - WebContextMenuProxy(); + WebContextMenuProxy(const ContextMenuContextData&, const UserData&); + + const ContextMenuContextData m_context; + const UserData m_userData; }; } // namespace WebKit +#endif + #endif // WebPopupMenuProxy_h diff --git a/Source/WebKit2/UIProcess/WebContextSupplement.h b/Source/WebKit2/UIProcess/WebContextSupplement.h index 69f87e4e4..31fe9c4a0 100644 --- a/Source/WebKit2/UIProcess/WebContextSupplement.h +++ b/Source/WebKit2/UIProcess/WebContextSupplement.h @@ -28,14 +28,15 @@ namespace WebKit { +class DatabaseProcessProxy; class NetworkProcessProxy; -class WebContext; +class WebProcessPool; class WebProcessProxy; class WebContextSupplement { public: - WebContextSupplement(WebContext* context) - : m_context(context) + WebContextSupplement(WebProcessPool* processPool) + : m_processPool(processPool) { } @@ -43,7 +44,7 @@ public: { } - virtual void contextDestroyed() + virtual void processPoolDestroyed() { } @@ -55,13 +56,12 @@ public: { } - virtual bool shouldTerminate(WebProcessProxy*) const + virtual void processDidClose(DatabaseProcessProxy*) { - return true; } - WebContext* context() const { return m_context; } - void clearContext() { m_context = 0; } + WebProcessPool* processPool() const { return m_processPool; } + void clearProcessPool() { m_processPool = nullptr; } void ref() { refWebContextSupplement(); } void deref() { derefWebContextSupplement(); } @@ -70,7 +70,7 @@ private: virtual void refWebContextSupplement() = 0; virtual void derefWebContextSupplement() = 0; - WebContext* m_context; + WebProcessPool* m_processPool; }; } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebContextUserMessageCoders.h b/Source/WebKit2/UIProcess/WebContextUserMessageCoders.h deleted file mode 100644 index f3c147a1e..000000000 --- a/Source/WebKit2/UIProcess/WebContextUserMessageCoders.h +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (C) 2010 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "UserMessageCoders.h" -#include "WebContext.h" -#include "WebFrameProxy.h" -#include "WebPageGroup.h" -#include "WebPageGroupData.h" -#include "WebPageProxy.h" - -#if PLATFORM(MAC) -#include "ObjCObjectGraphCoders.h" -#endif - -namespace WebKit { - -// Adds -// - Page -> BundlePage -// - Frame -> BundleFrame -// - PageGroup -> BundlePageGroup - -class WebContextUserMessageEncoder : public UserMessageEncoder<WebContextUserMessageEncoder> { -public: - typedef UserMessageEncoder<WebContextUserMessageEncoder> Base; - - explicit WebContextUserMessageEncoder(API::Object* root, WebProcessProxy& process) - : Base(root) - , m_process(process) - { - } - - WebContextUserMessageEncoder(const WebContextUserMessageEncoder& userMessageEncoder, API::Object* root) - : Base(root) - , m_process(userMessageEncoder.m_process) - { - } - - void encode(IPC::ArgumentEncoder& encoder) const - { - API::Object::Type type = API::Object::Type::Null; - if (baseEncode(encoder, *this, type)) - return; - - switch (type) { - case API::Object::Type::Page: { - WebPageProxy* page = static_cast<WebPageProxy*>(m_root); - encoder << page->pageID(); - break; - } - case API::Object::Type::Frame: { - WebFrameProxy* frame = static_cast<WebFrameProxy*>(m_root); - encoder << frame->frameID(); - break; - } - case API::Object::Type::PageGroup: { - WebPageGroup* pageGroup = static_cast<WebPageGroup*>(m_root); - encoder << pageGroup->data(); - break; - } -#if PLATFORM(MAC) - case API::Object::Type::ObjCObjectGraph: { - ObjCObjectGraph* objectGraph = static_cast<ObjCObjectGraph*>(m_root); - encoder << WebContextObjCObjectGraphEncoder(objectGraph, m_process); - break; - } -#endif - default: - ASSERT_NOT_REACHED(); - break; - } - } - -private: - WebProcessProxy& m_process; -}; - -// Adds -// - Page -> BundlePage -// - Frame -> BundleFrame -// - PageGroup -> BundlePageGroup - -class WebContextUserMessageDecoder : public UserMessageDecoder<WebContextUserMessageDecoder> { -public: - typedef UserMessageDecoder<WebContextUserMessageDecoder> Base; - - WebContextUserMessageDecoder(RefPtr<API::Object>& root, WebProcessProxy& process) - : Base(root) - , m_process(process) - { - } - - WebContextUserMessageDecoder(WebContextUserMessageDecoder& userMessageDecoder, RefPtr<API::Object>& root) - : Base(root) - , m_process(userMessageDecoder.m_process) - { - } - - static bool decode(IPC::ArgumentDecoder& decoder, WebContextUserMessageDecoder& coder) - { - API::Object::Type type = API::Object::Type::Null; - if (!Base::baseDecode(decoder, coder, type)) - return false; - - if (coder.m_root || type == API::Object::Type::Null) - return true; - - switch (type) { - case API::Object::Type::BundlePage: { - uint64_t pageID; - if (!decoder.decode(pageID)) - return false; - coder.m_root = coder.m_process.webPage(pageID); - break; - } - case API::Object::Type::BundleFrame: { - uint64_t frameID; - if (!decoder.decode(frameID)) - return false; - coder.m_root = coder.m_process.webFrame(frameID); - break; - } - case API::Object::Type::BundlePageGroup: { - uint64_t pageGroupID; - if (!decoder.decode(pageGroupID)) - return false; - coder.m_root = WebPageGroup::get(pageGroupID); - break; - } -#if PLATFORM(MAC) - case API::Object::Type::ObjCObjectGraph: { - RefPtr<ObjCObjectGraph> objectGraph; - WebContextObjCObjectGraphDecoder objectGraphDecoder(objectGraph, coder.m_process); - if (!decoder.decode(objectGraphDecoder)) - return false; - coder.m_root = objectGraph.get(); - break; - } -#endif - default: - return false; - } - - return true; - } - -private: - WebProcessProxy& m_process; -}; - -} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebCookieManagerProxy.cpp b/Source/WebKit2/UIProcess/WebCookieManagerProxy.cpp index 091b96549..977f5f634 100644 --- a/Source/WebKit2/UIProcess/WebCookieManagerProxy.cpp +++ b/Source/WebKit2/UIProcess/WebCookieManagerProxy.cpp @@ -27,11 +27,11 @@ #include "WebCookieManagerProxy.h" #include "APIArray.h" -#include "SecurityOriginData.h" -#include "WebContext.h" +#include "APISecurityOrigin.h" #include "WebCookieManagerMessages.h" #include "WebCookieManagerProxyMessages.h" -#include "WebSecurityOrigin.h" +#include "WebProcessPool.h" +#include <WebCore/SecurityOriginData.h> namespace WebKit { @@ -40,18 +40,18 @@ const char* WebCookieManagerProxy::supplementName() return "WebCookieManagerProxy"; } -PassRefPtr<WebCookieManagerProxy> WebCookieManagerProxy::create(WebContext* context) +PassRefPtr<WebCookieManagerProxy> WebCookieManagerProxy::create(WebProcessPool* processPool) { - return adoptRef(new WebCookieManagerProxy(context)); + return adoptRef(new WebCookieManagerProxy(processPool)); } -WebCookieManagerProxy::WebCookieManagerProxy(WebContext* context) - : WebContextSupplement(context) +WebCookieManagerProxy::WebCookieManagerProxy(WebProcessPool* processPool) + : WebContextSupplement(processPool) #if USE(SOUP) , m_cookiePersistentStorageType(SoupCookiePersistentStorageSQLite) #endif { - WebContextSupplement::context()->addMessageReceiver(Messages::WebCookieManagerProxy::messageReceiverName(), *this); + WebContextSupplement::processPool()->addMessageReceiver(Messages::WebCookieManagerProxy::messageReceiverName(), *this); } WebCookieManagerProxy::~WebCookieManagerProxy() @@ -65,28 +65,22 @@ void WebCookieManagerProxy::initializeClient(const WKCookieManagerClientBase* cl // WebContextSupplement -void WebCookieManagerProxy::contextDestroyed() +void WebCookieManagerProxy::processPoolDestroyed() { - invalidateCallbackMap(m_arrayCallbacks); - invalidateCallbackMap(m_httpCookieAcceptPolicyCallbacks); + invalidateCallbackMap(m_arrayCallbacks, CallbackBase::Error::OwnerWasInvalidated); + invalidateCallbackMap(m_httpCookieAcceptPolicyCallbacks, CallbackBase::Error::OwnerWasInvalidated); } void WebCookieManagerProxy::processDidClose(WebProcessProxy*) { - invalidateCallbackMap(m_arrayCallbacks); - invalidateCallbackMap(m_httpCookieAcceptPolicyCallbacks); + invalidateCallbackMap(m_arrayCallbacks, CallbackBase::Error::ProcessExited); + invalidateCallbackMap(m_httpCookieAcceptPolicyCallbacks, CallbackBase::Error::ProcessExited); } void WebCookieManagerProxy::processDidClose(NetworkProcessProxy*) { - invalidateCallbackMap(m_arrayCallbacks); - invalidateCallbackMap(m_httpCookieAcceptPolicyCallbacks); -} - -bool WebCookieManagerProxy::shouldTerminate(WebProcessProxy*) const -{ - return context()->processModel() != ProcessModelSharedSecondaryProcess - || (m_arrayCallbacks.isEmpty() && m_httpCookieAcceptPolicyCallbacks.isEmpty()); + invalidateCallbackMap(m_arrayCallbacks, CallbackBase::Error::ProcessExited); + invalidateCallbackMap(m_httpCookieAcceptPolicyCallbacks, CallbackBase::Error::ProcessExited); } void WebCookieManagerProxy::refWebContextSupplement() @@ -99,13 +93,13 @@ void WebCookieManagerProxy::derefWebContextSupplement() API::Object::deref(); } -void WebCookieManagerProxy::getHostnamesWithCookies(PassRefPtr<ArrayCallback> prpCallback) +void WebCookieManagerProxy::getHostnamesWithCookies(std::function<void (API::Array*, CallbackBase::Error)> callbackFunction) { - RefPtr<ArrayCallback> callback = prpCallback; + RefPtr<ArrayCallback> callback = ArrayCallback::create(WTFMove(callbackFunction)); uint64_t callbackID = callback->callbackID(); m_arrayCallbacks.set(callbackID, callback.release()); - context()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::GetHostnamesWithCookies(callbackID)); + processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::GetHostnamesWithCookies(callbackID)); } void WebCookieManagerProxy::didGetHostnamesWithCookies(const Vector<String>& hostnames, uint64_t callbackID) @@ -116,27 +110,32 @@ void WebCookieManagerProxy::didGetHostnamesWithCookies(const Vector<String>& hos return; } - callback->performCallbackWithReturnValue(API::Array::createStringArray(hostnames).get()); + callback->performCallbackWithReturnValue(API::Array::createStringArray(hostnames).ptr()); } void WebCookieManagerProxy::deleteCookiesForHostname(const String& hostname) { - context()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::DeleteCookiesForHostname(hostname)); + processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::DeleteCookiesForHostname(hostname)); } void WebCookieManagerProxy::deleteAllCookies() { - context()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::DeleteAllCookies()); + processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::DeleteAllCookies()); +} + +void WebCookieManagerProxy::deleteAllCookiesModifiedSince(std::chrono::system_clock::time_point time) +{ + processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::DeleteAllCookiesModifiedSince(time)); } void WebCookieManagerProxy::startObservingCookieChanges() { - context()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::StartObservingCookieChanges()); + processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::StartObservingCookieChanges()); } void WebCookieManagerProxy::stopObservingCookieChanges() { - context()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::StopObservingCookieChanges()); + processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::StopObservingCookieChanges()); } void WebCookieManagerProxy::cookiesDidChange() @@ -146,24 +145,29 @@ void WebCookieManagerProxy::cookiesDidChange() void WebCookieManagerProxy::setHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicy policy) { -#if PLATFORM(MAC) - persistHTTPCookieAcceptPolicy(policy); +#if PLATFORM(COCOA) + if (!processPool()->isUsingTestingNetworkSession()) + persistHTTPCookieAcceptPolicy(policy); #endif #if USE(SOUP) - context()->setInitialHTTPCookieAcceptPolicy(policy); + processPool()->setInitialHTTPCookieAcceptPolicy(policy); #endif - context()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::SetHTTPCookieAcceptPolicy(policy)); + // The policy is not sent to newly created processes (only Soup does that via setInitialHTTPCookieAcceptPolicy()). This is not a serious problem, because: + // - When testing, we only have one WebProcess and one NetworkProcess, and WebKitTestRunner never restarts them; + // - When not testing, Cocoa has the policy persisted, and thus new processes use it (even for ephemeral sessions). + processPool()->sendToAllProcesses(Messages::WebCookieManager::SetHTTPCookieAcceptPolicy(policy)); + processPool()->sendToNetworkingProcess(Messages::WebCookieManager::SetHTTPCookieAcceptPolicy(policy)); } -void WebCookieManagerProxy::getHTTPCookieAcceptPolicy(PassRefPtr<HTTPCookieAcceptPolicyCallback> prpCallback) +void WebCookieManagerProxy::getHTTPCookieAcceptPolicy(std::function<void (HTTPCookieAcceptPolicy, CallbackBase::Error)> callbackFunction) { - RefPtr<HTTPCookieAcceptPolicyCallback> callback = prpCallback; + RefPtr<HTTPCookieAcceptPolicyCallback> callback = HTTPCookieAcceptPolicyCallback::create(WTFMove(callbackFunction)); uint64_t callbackID = callback->callbackID(); m_httpCookieAcceptPolicyCallbacks.set(callbackID, callback.release()); - context()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::GetHTTPCookieAcceptPolicy(callbackID)); + processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::GetHTTPCookieAcceptPolicy(callbackID)); } void WebCookieManagerProxy::didGetHTTPCookieAcceptPolicy(uint32_t policy, uint64_t callbackID) diff --git a/Source/WebKit2/UIProcess/WebCookieManagerProxy.h b/Source/WebKit2/UIProcess/WebCookieManagerProxy.h index cc15f7f17..e1aa527bb 100644 --- a/Source/WebKit2/UIProcess/WebCookieManagerProxy.h +++ b/Source/WebKit2/UIProcess/WebCookieManagerProxy.h @@ -43,29 +43,31 @@ namespace API { class Array; } + namespace WebKit { -class WebContext; +class WebProcessPool; class WebProcessProxy; -typedef GenericCallback<WKArrayRef> ArrayCallback; -typedef GenericCallback<WKHTTPCookieAcceptPolicy, HTTPCookieAcceptPolicy> HTTPCookieAcceptPolicyCallback; +typedef GenericCallback<API::Array*> ArrayCallback; +typedef GenericCallback<HTTPCookieAcceptPolicy> HTTPCookieAcceptPolicyCallback; class WebCookieManagerProxy : public API::ObjectImpl<API::Object::Type::CookieManager>, public WebContextSupplement, private IPC::MessageReceiver { public: static const char* supplementName(); - static PassRefPtr<WebCookieManagerProxy> create(WebContext*); + static PassRefPtr<WebCookieManagerProxy> create(WebProcessPool*); virtual ~WebCookieManagerProxy(); void initializeClient(const WKCookieManagerClientBase*); - void getHostnamesWithCookies(PassRefPtr<ArrayCallback>); + void getHostnamesWithCookies(std::function<void (API::Array*, CallbackBase::Error)>); void deleteCookiesForHostname(const String& hostname); void deleteAllCookies(); + void deleteAllCookiesModifiedSince(std::chrono::system_clock::time_point); void setHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicy); - void getHTTPCookieAcceptPolicy(PassRefPtr<HTTPCookieAcceptPolicyCallback>); + void getHTTPCookieAcceptPolicy(std::function<void (HTTPCookieAcceptPolicy, CallbackBase::Error)>); void startObservingCookieChanges(); void stopObservingCookieChanges(); @@ -79,7 +81,7 @@ public: using API::Object::deref; private: - WebCookieManagerProxy(WebContext*); + WebCookieManagerProxy(WebProcessPool*); void didGetHostnamesWithCookies(const Vector<String>&, uint64_t callbackID); void didGetHTTPCookieAcceptPolicy(uint32_t policy, uint64_t callbackID); @@ -87,17 +89,16 @@ private: void cookiesDidChange(); // WebContextSupplement - virtual void contextDestroyed() override; + virtual void processPoolDestroyed() override; virtual void processDidClose(WebProcessProxy*) override; virtual void processDidClose(NetworkProcessProxy*) override; - virtual bool shouldTerminate(WebProcessProxy*) const override; virtual void refWebContextSupplement() override; virtual void derefWebContextSupplement() override; // IPC::MessageReceiver - virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; + virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override; -#if PLATFORM(MAC) +#if PLATFORM(COCOA) void persistHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicy); #endif diff --git a/Source/WebKit2/UIProcess/WebCookieManagerProxyClient.cpp b/Source/WebKit2/UIProcess/WebCookieManagerProxyClient.cpp index 088f36cec..79c660f81 100644 --- a/Source/WebKit2/UIProcess/WebCookieManagerProxyClient.cpp +++ b/Source/WebKit2/UIProcess/WebCookieManagerProxyClient.cpp @@ -27,6 +27,7 @@ #include "WebCookieManagerProxyClient.h" #include "WKAPICast.h" +#include "WebCookieManagerProxy.h" namespace WebKit { diff --git a/Source/WebKit2/UIProcess/WebDatabaseManagerProxy.cpp b/Source/WebKit2/UIProcess/WebDatabaseManagerProxy.cpp deleted file mode 100644 index afa7dc8e7..000000000 --- a/Source/WebKit2/UIProcess/WebDatabaseManagerProxy.cpp +++ /dev/null @@ -1,268 +0,0 @@ -/* - * Copyright (C) 2010, 2013 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "WebDatabaseManagerProxy.h" - -#if ENABLE(SQL_DATABASE) - -#include "APIArray.h" -#include "ImmutableDictionary.h" -#include "WebContext.h" -#include "WebDatabaseManagerMessages.h" -#include "WebDatabaseManagerProxyMessages.h" -#include "WebSecurityOrigin.h" -#include <wtf/NeverDestroyed.h> - -using namespace WebCore; - -namespace WebKit { - -const char* WebDatabaseManagerProxy::supplementName() -{ - return "WebDatabaseManagerProxy"; -} - -String WebDatabaseManagerProxy::originKey() -{ - static NeverDestroyed<String> key(ASCIILiteral("WebDatabaseManagerOriginKey")); - return key; -} - -String WebDatabaseManagerProxy::originQuotaKey() -{ - static NeverDestroyed<String> key(ASCIILiteral("WebDatabaseManagerOriginQuotaKey")); - return key; -} - -String WebDatabaseManagerProxy::originUsageKey() -{ - static NeverDestroyed<String> key(ASCIILiteral("WebDatabaseManagerOriginUsageKey")); - return key; -} - -String WebDatabaseManagerProxy::databaseDetailsKey() -{ - static NeverDestroyed<String> key(ASCIILiteral("WebDatabaseManagerDatabaseDetailsKey")); - return key; -} - -String WebDatabaseManagerProxy::databaseDetailsNameKey() -{ - static NeverDestroyed<String> key(ASCIILiteral("WebDatabaseManagerDatabaseDetailsNameKey")); - return key; -} - -String WebDatabaseManagerProxy::databaseDetailsDisplayNameKey() -{ - static NeverDestroyed<String> key(ASCIILiteral("WebDatabaseManagerDatabaseDetailsDisplayNameKey")); - return key; -} - -String WebDatabaseManagerProxy::databaseDetailsExpectedUsageKey() -{ - static NeverDestroyed<String> key(ASCIILiteral("WebDatabaseManagerDatabaseDetailsExpectedUsageKey")); - return key; -} - -String WebDatabaseManagerProxy::databaseDetailsCurrentUsageKey() -{ - static NeverDestroyed<String> key(ASCIILiteral("WebDatabaseManagerDatabaseDetailsCurrentUsageKey")); - return key; -} - -String WebDatabaseManagerProxy::databaseDetailsCreationTimeKey() -{ - static NeverDestroyed<String> key(ASCIILiteral("WebDatabaseManagerDatabaseDetailsCreationTimeKey")); - return key; -} - -String WebDatabaseManagerProxy::databaseDetailsModificationTimeKey() -{ - static NeverDestroyed<String> key(ASCIILiteral("WebDatabaseManagerDatabaseDetailsModificationTimeKey")); - return key; -} - -PassRefPtr<WebDatabaseManagerProxy> WebDatabaseManagerProxy::create(WebContext* webContext) -{ - return adoptRef(new WebDatabaseManagerProxy(webContext)); -} - -WebDatabaseManagerProxy::WebDatabaseManagerProxy(WebContext* webContext) - : WebContextSupplement(webContext) -{ - WebContextSupplement::context()->addMessageReceiver(Messages::WebDatabaseManagerProxy::messageReceiverName(), *this); -} - -WebDatabaseManagerProxy::~WebDatabaseManagerProxy() -{ -} - -void WebDatabaseManagerProxy::initializeClient(const WKDatabaseManagerClientBase* client) -{ - m_client.initialize(client); -} - -// WebContextSupplement - -void WebDatabaseManagerProxy::contextDestroyed() -{ - invalidateCallbackMap(m_arrayCallbacks); -} - -void WebDatabaseManagerProxy::processDidClose(WebProcessProxy*) -{ - invalidateCallbackMap(m_arrayCallbacks); -} - -bool WebDatabaseManagerProxy::shouldTerminate(WebProcessProxy*) const -{ - return m_arrayCallbacks.isEmpty(); -} - -void WebDatabaseManagerProxy::refWebContextSupplement() -{ - API::Object::ref(); -} - -void WebDatabaseManagerProxy::derefWebContextSupplement() -{ - API::Object::deref(); -} - -void WebDatabaseManagerProxy::getDatabasesByOrigin(PassRefPtr<ArrayCallback> prpCallback) -{ - RefPtr<ArrayCallback> callback = prpCallback; - uint64_t callbackID = callback->callbackID(); - m_arrayCallbacks.set(callbackID, callback.release()); - - context()->sendToOneProcess(Messages::WebDatabaseManager::GetDatabasesByOrigin(callbackID)); -} - -void WebDatabaseManagerProxy::didGetDatabasesByOrigin(const Vector<OriginAndDatabases>& originAndDatabasesVector, uint64_t callbackID) -{ - RefPtr<ArrayCallback> callback = m_arrayCallbacks.take(callbackID); - if (!callback) { - // FIXME: Log error or assert. - return; - } - - Vector<RefPtr<API::Object>> result; - result.reserveInitialCapacity(originAndDatabasesVector.size()); - - for (const auto& originAndDatabases : originAndDatabasesVector) { - RefPtr<API::Object> origin = WebSecurityOrigin::createFromDatabaseIdentifier(originAndDatabases.originIdentifier); - - Vector<RefPtr<API::Object>> databases; - databases.reserveInitialCapacity(originAndDatabases.databases.size()); - - for (const auto& databaseDetails : originAndDatabases.databases) { - HashMap<String, RefPtr<API::Object>> detailsMap; - - detailsMap.set(databaseDetailsNameKey(), API::String::create(databaseDetails.name())); - detailsMap.set(databaseDetailsDisplayNameKey(), API::String::create(databaseDetails.displayName())); - detailsMap.set(databaseDetailsExpectedUsageKey(), API::UInt64::create(databaseDetails.expectedUsage())); - detailsMap.set(databaseDetailsCurrentUsageKey(), API::UInt64::create(databaseDetails.currentUsage())); - if (databaseDetails.creationTime()) - detailsMap.set(databaseDetailsCreationTimeKey(), API::Double::create(databaseDetails.creationTime())); - if (databaseDetails.modificationTime()) - detailsMap.set(databaseDetailsModificationTimeKey(), API::Double::create(databaseDetails.modificationTime())); - - databases.uncheckedAppend(ImmutableDictionary::create(std::move(detailsMap))); - } - - HashMap<String, RefPtr<API::Object>> originAndDatabasesMap; - originAndDatabasesMap.set(originKey(), origin); - originAndDatabasesMap.set(originQuotaKey(), API::UInt64::create(originAndDatabases.originQuota)); - originAndDatabasesMap.set(originUsageKey(), API::UInt64::create(originAndDatabases.originUsage)); - originAndDatabasesMap.set(databaseDetailsKey(), API::Array::create(std::move(databases))); - - result.uncheckedAppend(ImmutableDictionary::create(std::move(originAndDatabasesMap))); - } - - callback->performCallbackWithReturnValue(API::Array::create(std::move(result)).get()); -} - -void WebDatabaseManagerProxy::getDatabaseOrigins(PassRefPtr<ArrayCallback> prpCallback) -{ - RefPtr<ArrayCallback> callback = prpCallback; - uint64_t callbackID = callback->callbackID(); - m_arrayCallbacks.set(callbackID, callback.release()); - - context()->sendToOneProcess(Messages::WebDatabaseManager::GetDatabaseOrigins(callbackID)); -} - -void WebDatabaseManagerProxy::didGetDatabaseOrigins(const Vector<String>& originIdentifiers, uint64_t callbackID) -{ - RefPtr<ArrayCallback> callback = m_arrayCallbacks.take(callbackID); - if (!callback) { - // FIXME: Log error or assert. - return; - } - - Vector<RefPtr<API::Object>> securityOrigins; - securityOrigins.reserveInitialCapacity(originIdentifiers.size()); - - for (const auto& originIdentifier : originIdentifiers) - securityOrigins.uncheckedAppend(WebSecurityOrigin::createFromDatabaseIdentifier(originIdentifier)); - - callback->performCallbackWithReturnValue(API::Array::create(std::move(securityOrigins)).get()); -} - -void WebDatabaseManagerProxy::deleteDatabaseWithNameForOrigin(const String& databaseIdentifier, WebSecurityOrigin* origin) -{ - context()->sendToOneProcess(Messages::WebDatabaseManager::DeleteDatabaseWithNameForOrigin(databaseIdentifier, origin->databaseIdentifier())); -} - -void WebDatabaseManagerProxy::deleteDatabasesForOrigin(WebSecurityOrigin* origin) -{ - context()->sendToOneProcess(Messages::WebDatabaseManager::DeleteDatabasesForOrigin(origin->databaseIdentifier())); -} - -void WebDatabaseManagerProxy::deleteAllDatabases() -{ - context()->sendToOneProcess(Messages::WebDatabaseManager::DeleteAllDatabases()); -} - -void WebDatabaseManagerProxy::setQuotaForOrigin(WebSecurityOrigin* origin, uint64_t quota) -{ - context()->sendToOneProcess(Messages::WebDatabaseManager::SetQuotaForOrigin(origin->databaseIdentifier(), quota)); -} - -void WebDatabaseManagerProxy::didModifyOrigin(const String& originIdentifier) -{ - RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::createFromDatabaseIdentifier(originIdentifier); - m_client.didModifyOrigin(this, origin.get()); -} - -void WebDatabaseManagerProxy::didModifyDatabase(const String& originIdentifier, const String& databaseIdentifier) -{ - RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::createFromDatabaseIdentifier(originIdentifier); - m_client.didModifyDatabase(this, origin.get(), databaseIdentifier); -} - -} // namespace WebKit - -#endif // ENABLE(SQL_DATABASE) diff --git a/Source/WebKit2/UIProcess/WebDatabaseManagerProxy.h b/Source/WebKit2/UIProcess/WebDatabaseManagerProxy.h deleted file mode 100644 index b32f2ab81..000000000 --- a/Source/WebKit2/UIProcess/WebDatabaseManagerProxy.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (C) 2010, 2013 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef WebDatabaseManagerProxy_h -#define WebDatabaseManagerProxy_h - -#if ENABLE(SQL_DATABASE) - -#include "APIObject.h" -#include "Arguments.h" -#include "GenericCallback.h" -#include "MessageReceiver.h" -#include "OriginAndDatabases.h" -#include "WebContextSupplement.h" -#include "WebDatabaseManagerProxyClient.h" -#include <wtf/HashMap.h> -#include <wtf/PassRefPtr.h> - -namespace WebKit { - -class WebContext; -class WebProcessProxy; -class WebSecurityOrigin; - -typedef GenericCallback<WKArrayRef> ArrayCallback; - -class WebDatabaseManagerProxy : public API::ObjectImpl<API::Object::Type::DatabaseManager>, public WebContextSupplement, private IPC::MessageReceiver { -public: - static const char* supplementName(); - - static PassRefPtr<WebDatabaseManagerProxy> create(WebContext*); - virtual ~WebDatabaseManagerProxy(); - - void initializeClient(const WKDatabaseManagerClientBase*); - - void getDatabasesByOrigin(PassRefPtr<ArrayCallback>); - void getDatabaseOrigins(PassRefPtr<ArrayCallback>); - void deleteDatabaseWithNameForOrigin(const String& databaseIdentifier, WebSecurityOrigin*); - void deleteDatabasesForOrigin(WebSecurityOrigin*); - void deleteAllDatabases(); - void setQuotaForOrigin(WebSecurityOrigin*, uint64_t quota); - - static String originKey(); - static String originQuotaKey(); - static String originUsageKey(); - static String databaseDetailsKey(); - static String databaseDetailsNameKey(); - static String databaseDetailsDisplayNameKey(); - static String databaseDetailsExpectedUsageKey(); - static String databaseDetailsCurrentUsageKey(); - static String databaseDetailsCreationTimeKey(); - static String databaseDetailsModificationTimeKey(); - - using API::Object::ref; - using API::Object::deref; - -private: - explicit WebDatabaseManagerProxy(WebContext*); - - // WebContextSupplement - virtual void contextDestroyed() override; - virtual void processDidClose(WebProcessProxy*) override; - virtual bool shouldTerminate(WebProcessProxy*) const override; - virtual void refWebContextSupplement() override; - virtual void derefWebContextSupplement() override; - - // IPC::MessageReceiver - virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; - - // Message handlers. - void didGetDatabasesByOrigin(const Vector<OriginAndDatabases>& originAndDatabases, uint64_t callbackID); - void didGetDatabaseOrigins(const Vector<String>& originIdentifiers, uint64_t callbackID); - void didModifyOrigin(const String& originIdentifier); - void didModifyDatabase(const String& originIdentifier, const String& databaseIdentifier); - - HashMap<uint64_t, RefPtr<ArrayCallback>> m_arrayCallbacks; - WebDatabaseManagerProxyClient m_client; -}; - -} // namespace WebKit - -#endif // ENABLE(SQL_DATABASE) - -#endif // DatabaseManagerProxy_h diff --git a/Source/WebKit2/UIProcess/WebDownloadClient.cpp b/Source/WebKit2/UIProcess/WebDownloadClient.cpp deleted file mode 100644 index 58b84507a..000000000 --- a/Source/WebKit2/UIProcess/WebDownloadClient.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) 2010 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "WebDownloadClient.h" - -#include "APIURLResponse.h" -#include "WKAPICast.h" -#include "WKRetainPtr.h" - -using namespace WebCore; - -namespace WebKit { - -void WebDownloadClient::didStart(WebContext* webContext, DownloadProxy* downloadProxy) -{ - if (!m_client.didStart) - return; - - m_client.didStart(toAPI(webContext), toAPI(downloadProxy), m_client.base.clientInfo); -} - -void WebDownloadClient::didReceiveAuthenticationChallenge(WebContext* webContext, DownloadProxy* downloadProxy, AuthenticationChallengeProxy* authenticationChallengeProxy) -{ - if (!m_client.didReceiveAuthenticationChallenge) - return; - - m_client.didReceiveAuthenticationChallenge(toAPI(webContext), toAPI(downloadProxy), toAPI(authenticationChallengeProxy), m_client.base.clientInfo); -} - -void WebDownloadClient::didReceiveResponse(WebContext* webContext, DownloadProxy* downloadProxy, const ResourceResponse& response) -{ - if (!m_client.didReceiveResponse) - return; - - m_client.didReceiveResponse(toAPI(webContext), toAPI(downloadProxy), toAPI(API::URLResponse::create(response).get()), m_client.base.clientInfo); -} - -void WebDownloadClient::didReceiveData(WebContext* webContext, DownloadProxy* downloadProxy, uint64_t length) -{ - if (!m_client.didReceiveData) - return; - - m_client.didReceiveData(toAPI(webContext), toAPI(downloadProxy), length, m_client.base.clientInfo); -} - -bool WebDownloadClient::shouldDecodeSourceDataOfMIMEType(WebContext* webContext, DownloadProxy* downloadProxy, const String& mimeType) -{ - if (!m_client.shouldDecodeSourceDataOfMIMEType) - return true; - - return m_client.shouldDecodeSourceDataOfMIMEType(toAPI(webContext), toAPI(downloadProxy), toAPI(mimeType.impl()), m_client.base.clientInfo); -} - -String WebDownloadClient::decideDestinationWithSuggestedFilename(WebContext* webContext, DownloadProxy* downloadProxy, const String& filename, bool& allowOverwrite) -{ - if (!m_client.decideDestinationWithSuggestedFilename) - return String(); - - WKRetainPtr<WKStringRef> destination(AdoptWK, m_client.decideDestinationWithSuggestedFilename(toAPI(webContext), toAPI(downloadProxy), toAPI(filename.impl()), &allowOverwrite, m_client.base.clientInfo)); - return toWTFString(destination.get()); -} - -void WebDownloadClient::didCreateDestination(WebContext* webContext, DownloadProxy* downloadProxy, const String& path) -{ - if (!m_client.didCreateDestination) - return; - - m_client.didCreateDestination(toAPI(webContext), toAPI(downloadProxy), toAPI(path.impl()), m_client.base.clientInfo); -} - -void WebDownloadClient::didFinish(WebContext* webContext, DownloadProxy* downloadProxy) -{ - if (!m_client.didFinish) - return; - - m_client.didFinish(toAPI(webContext), toAPI(downloadProxy), m_client.base.clientInfo); -} - -void WebDownloadClient::didFail(WebContext* webContext, DownloadProxy* downloadProxy, const ResourceError& error) -{ - if (!m_client.didFail) - return; - - m_client.didFail(toAPI(webContext), toAPI(downloadProxy), toAPI(error), m_client.base.clientInfo); -} - -void WebDownloadClient::didCancel(WebContext* webContext, DownloadProxy* downloadProxy) -{ - if (!m_client.didCancel) - return; - - m_client.didCancel(toAPI(webContext), toAPI(downloadProxy), m_client.base.clientInfo); -} - -void WebDownloadClient::processDidCrash(WebContext* webContext, DownloadProxy* downloadProxy) -{ - if (!m_client.processDidCrash) - return; - - m_client.processDidCrash(toAPI(webContext), toAPI(downloadProxy), m_client.base.clientInfo); -} - -} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebDownloadClient.h b/Source/WebKit2/UIProcess/WebDownloadClient.h deleted file mode 100644 index ec70c8468..000000000 --- a/Source/WebKit2/UIProcess/WebDownloadClient.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2010 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef WebDownloadClient_h -#define WebDownloadClient_h - -#include "APIClient.h" -#include "WKContext.h" -#include <wtf/Forward.h> - -namespace API { -template<> struct ClientTraits<WKContextDownloadClientBase> { - typedef std::tuple<WKContextDownloadClientV0> Versions; -}; -} - -namespace WebCore { - class ResourceError; - class ResourceResponse; -} - -namespace WebKit { - -class AuthenticationChallengeProxy; -class DownloadProxy; -class WebContext; - -class WebDownloadClient : public API::Client<WKContextDownloadClientBase> { -public: - void didStart(WebContext*, DownloadProxy*); - void didReceiveAuthenticationChallenge(WebContext*, DownloadProxy*, AuthenticationChallengeProxy*); - void didReceiveResponse(WebContext*, DownloadProxy*, const WebCore::ResourceResponse&); - void didReceiveData(WebContext*, DownloadProxy*, uint64_t length); - bool shouldDecodeSourceDataOfMIMEType(WebContext*, DownloadProxy*, const String& mimeType); - String decideDestinationWithSuggestedFilename(WebContext*, DownloadProxy*, const String& filename, bool& allowOverwrite); - void didCreateDestination(WebContext*, DownloadProxy*, const String& path); - void didFinish(WebContext*, DownloadProxy*); - void didFail(WebContext*, DownloadProxy*, const WebCore::ResourceError&); - void didCancel(WebContext*, DownloadProxy*); - void processDidCrash(WebContext*, DownloadProxy*); -}; - -} // namespace WebKit - -#endif // WebDownloadClient_h diff --git a/Source/WebKit2/UIProcess/WebEditCommandProxy.cpp b/Source/WebKit2/UIProcess/WebEditCommandProxy.cpp index d3e858438..878559546 100644 --- a/Source/WebKit2/UIProcess/WebEditCommandProxy.cpp +++ b/Source/WebKit2/UIProcess/WebEditCommandProxy.cpp @@ -70,9 +70,12 @@ void WebEditCommandProxy::reapply() String WebEditCommandProxy::nameForEditAction(EditAction editAction) { + // FIXME: This is identical to code in WebKit's WebEditorClient class; would be nice to share the strings instead of having two copies. switch (editAction) { case EditActionUnspecified: return String(); + case EditActionInsert: + return String(); case EditActionSetColor: return WEB_UI_STRING_KEY("Set Color", "Set Color (Undo action name)", "Undo action name"); case EditActionSetBackgroundColor: @@ -129,12 +132,10 @@ String WebEditCommandProxy::nameForEditAction(EditAction editAction) return WEB_UI_STRING_KEY("Bold", "Bold (Undo action name)", "Undo action name"); case EditActionItalics: return WEB_UI_STRING_KEY("Italics", "Italics (Undo action name)", "Undo action name"); -#if PLATFORM(IOS) case EditActionDelete: return WEB_UI_STRING_KEY("Delete", "Delete (Undo action name)", "Undo action name"); case EditActionDictation: return WEB_UI_STRING_KEY("Dictation", "Dictation (Undo action name)", "Undo action name"); -#endif case EditActionPaste: return WEB_UI_STRING_KEY("Paste", "Paste (Undo action name)", "Undo action name"); case EditActionPasteFont: diff --git a/Source/WebKit2/UIProcess/WebFormClient.cpp b/Source/WebKit2/UIProcess/WebFormClient.cpp index 271e9eaa2..716b7bd60 100644 --- a/Source/WebKit2/UIProcess/WebFormClient.cpp +++ b/Source/WebKit2/UIProcess/WebFormClient.cpp @@ -26,24 +26,31 @@ #include "config.h" #include "WebFormClient.h" +#include "APIDictionary.h" #include "APIString.h" -#include "ImmutableDictionary.h" #include "WKAPICast.h" +#include "WebFormSubmissionListenerProxy.h" +#include "WebPageProxy.h" namespace WebKit { -bool WebFormClient::willSubmitForm(WebPageProxy* page, WebFrameProxy* frame, WebFrameProxy* sourceFrame, const Vector<std::pair<String, String>>& textFieldValues, API::Object* userData, WebFormSubmissionListenerProxy* listener) +WebFormClient::WebFormClient(const WKPageFormClientBase* wkClient) { - if (!m_client.willSubmitForm) - return false; + initialize(wkClient); +} + +void WebFormClient::willSubmitForm(WebPageProxy& page, WebFrameProxy& frame, WebFrameProxy& sourceFrame, const Vector<std::pair<String, String>>& textFieldValues, API::Object* userData, Ref<WebFormSubmissionListenerProxy>&& listener) +{ + if (!m_client.willSubmitForm) { + listener->continueSubmission(); + return; + } - ImmutableDictionary::MapType map; + API::Dictionary::MapType map; for (size_t i = 0; i < textFieldValues.size(); ++i) map.set(textFieldValues[i].first, API::String::create(textFieldValues[i].second)); - RefPtr<ImmutableDictionary> textFieldsMap = ImmutableDictionary::create(std::move(map)); - - m_client.willSubmitForm(toAPI(page), toAPI(frame), toAPI(sourceFrame), toAPI(textFieldsMap.get()), toAPI(userData), toAPI(listener), m_client.base.clientInfo); - return true; + Ref<API::Dictionary> textFieldsMap = API::Dictionary::create(WTFMove(map)); + m_client.willSubmitForm(toAPI(&page), toAPI(&frame), toAPI(&sourceFrame), toAPI(textFieldsMap.ptr()), toAPI(userData), toAPI(&listener.get()), m_client.base.clientInfo); } } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebFormClient.h b/Source/WebKit2/UIProcess/WebFormClient.h index 38e12ddd3..66fefed9d 100644 --- a/Source/WebKit2/UIProcess/WebFormClient.h +++ b/Source/WebKit2/UIProcess/WebFormClient.h @@ -27,14 +27,10 @@ #define WebFormClient_h #include "APIClient.h" -#include "WKPage.h" -#include <utility> -#include <wtf/Forward.h> -#include <wtf/Vector.h> +#include "APIFormClient.h" +#include "WKPageFormClient.h" namespace API { -class Object; - template<> struct ClientTraits<WKPageFormClientBase> { typedef std::tuple<WKPageFormClientV0> Versions; }; @@ -42,13 +38,11 @@ template<> struct ClientTraits<WKPageFormClientBase> { namespace WebKit { -class WebPageProxy; -class WebFrameProxy; -class WebFormSubmissionListenerProxy; - -class WebFormClient : public API::Client<WKPageFormClientBase> { +class WebFormClient : public API::FormClient, API::Client<WKPageFormClientBase> { public: - bool willSubmitForm(WebPageProxy*, WebFrameProxy*, WebFrameProxy*, const Vector<std::pair<String, String>>& textFieldValues, API::Object* userData, WebFormSubmissionListenerProxy*); + explicit WebFormClient(const WKPageFormClientBase*); + + virtual void willSubmitForm(WebPageProxy&, WebFrameProxy&, WebFrameProxy&, const Vector<std::pair<String, String>>& textFieldValues, API::Object* userData, Ref<WebFormSubmissionListenerProxy>&&) override; }; } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebFormSubmissionListenerProxy.h b/Source/WebKit2/UIProcess/WebFormSubmissionListenerProxy.h index 48420b2b6..70bac5e52 100644 --- a/Source/WebKit2/UIProcess/WebFormSubmissionListenerProxy.h +++ b/Source/WebKit2/UIProcess/WebFormSubmissionListenerProxy.h @@ -28,11 +28,11 @@ #include "WebFrameListenerProxy.h" -#if PLATFORM(MAC) +#if PLATFORM(COCOA) #include "WKFoundation.h" #endif -#define DELEGATE_REF_COUNTING_TO_COCOA (PLATFORM(MAC) && WK_API_ENABLED) +#define DELEGATE_REF_COUNTING_TO_COCOA (PLATFORM(COCOA) && WK_API_ENABLED) namespace WebKit { diff --git a/Source/WebKit2/UIProcess/WebFrameListenerProxy.cpp b/Source/WebKit2/UIProcess/WebFrameListenerProxy.cpp index b998f5836..4061dd529 100644 --- a/Source/WebKit2/UIProcess/WebFrameListenerProxy.cpp +++ b/Source/WebKit2/UIProcess/WebFrameListenerProxy.cpp @@ -42,7 +42,7 @@ WebFrameListenerProxy::~WebFrameListenerProxy() void WebFrameListenerProxy::invalidate() { - m_frame = 0; + m_frame = nullptr; } void WebFrameListenerProxy::receivedPolicyDecision(WebCore::PolicyAction action) @@ -50,8 +50,8 @@ void WebFrameListenerProxy::receivedPolicyDecision(WebCore::PolicyAction action) if (!m_frame) return; - m_frame->receivedPolicyDecision(action, m_listenerID); - m_frame = 0; + m_frame->receivedPolicyDecision(action, m_listenerID, m_navigation.get()); + m_frame = nullptr; } } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebFrameListenerProxy.h b/Source/WebKit2/UIProcess/WebFrameListenerProxy.h index 8b3ee3653..6a87f6e34 100644 --- a/Source/WebKit2/UIProcess/WebFrameListenerProxy.h +++ b/Source/WebKit2/UIProcess/WebFrameListenerProxy.h @@ -26,9 +26,11 @@ #ifndef WebFrameListenerProxy_h #define WebFrameListenerProxy_h +#include "APINavigation.h" #include "APIObject.h" #include <WebCore/FrameLoaderTypes.h> #include <wtf/PassRefPtr.h> +#include <wtf/Ref.h> #include <wtf/RefPtr.h> namespace WebKit { @@ -42,6 +44,9 @@ public: void invalidate(); uint64_t listenerID() const { return m_listenerID; } + API::Navigation* navigation() { return m_navigation.get(); } + void setNavigation(Ref<API::Navigation>&& navigation) { m_navigation = WTFMove(navigation); } + protected: WebFrameListenerProxy(WebFrameProxy*, uint64_t listenerID); @@ -50,6 +55,7 @@ protected: private: RefPtr<WebFrameProxy> m_frame; uint64_t m_listenerID; + RefPtr<API::Navigation> m_navigation; }; } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebFramePolicyListenerProxy.h b/Source/WebKit2/UIProcess/WebFramePolicyListenerProxy.h index 6f1367354..1b9b64c55 100644 --- a/Source/WebKit2/UIProcess/WebFramePolicyListenerProxy.h +++ b/Source/WebKit2/UIProcess/WebFramePolicyListenerProxy.h @@ -28,11 +28,11 @@ #include "WebFrameListenerProxy.h" -#if PLATFORM(MAC) +#if PLATFORM(COCOA) #include "WKFoundation.h" #endif -#define DELEGATE_REF_COUNTING_TO_COCOA (PLATFORM(MAC) && WK_API_ENABLED) +#define DELEGATE_REF_COUNTING_TO_COCOA (PLATFORM(COCOA) && WK_API_ENABLED) namespace WebKit { diff --git a/Source/WebKit2/UIProcess/WebFrameProxy.cpp b/Source/WebKit2/UIProcess/WebFrameProxy.cpp index ea26db29d..15b8e28f2 100644 --- a/Source/WebKit2/UIProcess/WebFrameProxy.cpp +++ b/Source/WebKit2/UIProcess/WebFrameProxy.cpp @@ -27,11 +27,11 @@ #include "WebFrameProxy.h" #include "WebCertificateInfo.h" -#include "WebContext.h" #include "WebFormSubmissionListenerProxy.h" #include "WebFramePolicyListenerProxy.h" #include "WebPageMessages.h" #include "WebPageProxy.h" +#include "WebProcessPool.h" #include <WebCore/DOMImplementation.h> #include <WebCore/Image.h> #include <WebCore/MIMETypeRegistry.h> @@ -47,21 +47,21 @@ WebFrameProxy::WebFrameProxy(WebPageProxy* page, uint64_t frameID) , m_isFrameSet(false) , m_frameID(frameID) { - WebContext::statistics().wkFrameCount++; + WebProcessPool::statistics().wkFrameCount++; } WebFrameProxy::~WebFrameProxy() { - WebContext::statistics().wkFrameCount--; + WebProcessPool::statistics().wkFrameCount--; } -void WebFrameProxy::disconnect() +void WebFrameProxy::webProcessWillShutDown() { - m_page = 0; + m_page = nullptr; if (m_activeListener) { m_activeListener->invalidate(); - m_activeListener = 0; + m_activeListener = nullptr; } } @@ -110,6 +110,11 @@ bool WebFrameProxy::isDisplayingStandaloneImageDocument() const return Image::supportsType(m_MIMEType); } +bool WebFrameProxy::isDisplayingStandaloneMediaDocument() const +{ + return MIMETypeRegistry::isSupportedMediaMIMEType(m_MIMEType); +} + bool WebFrameProxy::isDisplayingMarkupDocument() const { // FIXME: This check should be moved to somewhere in WebCore. @@ -139,14 +144,15 @@ void WebFrameProxy::didFailProvisionalLoad() m_frameLoadState.didFailProvisionalLoad(); } -void WebFrameProxy::didCommitLoad(const String& contentType, const WebCore::CertificateInfo& certificateInfo) +void WebFrameProxy::didCommitLoad(const String& contentType, WebCertificateInfo& certificateInfo, bool containsPluginDocument) { m_frameLoadState.didCommitLoad(); m_title = String(); m_MIMEType = contentType; m_isFrameSet = false; - m_certificateInfo = WebCertificateInfo::create(certificateInfo); + m_certificateInfo = &certificateInfo; + m_containsPluginDocument = containsPluginDocument; } void WebFrameProxy::didFinishLoad() @@ -169,60 +175,60 @@ void WebFrameProxy::didChangeTitle(const String& title) m_title = title; } -void WebFrameProxy::receivedPolicyDecision(WebCore::PolicyAction action, uint64_t listenerID) +void WebFrameProxy::receivedPolicyDecision(WebCore::PolicyAction action, uint64_t listenerID, API::Navigation* navigation) { if (!m_page) return; ASSERT(m_activeListener); ASSERT(m_activeListener->listenerID() == listenerID); - m_page->receivedPolicyDecision(action, this, listenerID); + m_page->receivedPolicyDecision(action, this, listenerID, navigation); } -WebFramePolicyListenerProxy* WebFrameProxy::setUpPolicyListenerProxy(uint64_t listenerID) +WebFramePolicyListenerProxy& WebFrameProxy::setUpPolicyListenerProxy(uint64_t listenerID) { if (m_activeListener) m_activeListener->invalidate(); m_activeListener = WebFramePolicyListenerProxy::create(this, listenerID); - return static_cast<WebFramePolicyListenerProxy*>(m_activeListener.get()); + return *static_cast<WebFramePolicyListenerProxy*>(m_activeListener.get()); } -WebFormSubmissionListenerProxy* WebFrameProxy::setUpFormSubmissionListenerProxy(uint64_t listenerID) +WebFormSubmissionListenerProxy& WebFrameProxy::setUpFormSubmissionListenerProxy(uint64_t listenerID) { if (m_activeListener) m_activeListener->invalidate(); m_activeListener = WebFormSubmissionListenerProxy::create(this, listenerID); - return static_cast<WebFormSubmissionListenerProxy*>(m_activeListener.get()); + return *static_cast<WebFormSubmissionListenerProxy*>(m_activeListener.get()); } -void WebFrameProxy::getWebArchive(PassRefPtr<DataCallback> callback) +void WebFrameProxy::getWebArchive(std::function<void (API::Data*, CallbackBase::Error)> callbackFunction) { if (!m_page) { - callback->invalidate(); + callbackFunction(nullptr, CallbackBase::Error::Unknown); return; } - m_page->getWebArchiveOfFrame(this, callback); + m_page->getWebArchiveOfFrame(this, callbackFunction); } -void WebFrameProxy::getMainResourceData(PassRefPtr<DataCallback> callback) +void WebFrameProxy::getMainResourceData(std::function<void (API::Data*, CallbackBase::Error)> callbackFunction) { if (!m_page) { - callback->invalidate(); + callbackFunction(nullptr, CallbackBase::Error::Unknown); return; } - m_page->getMainResourceDataOfFrame(this, callback); + m_page->getMainResourceDataOfFrame(this, callbackFunction); } -void WebFrameProxy::getResourceData(API::URL* resourceURL, PassRefPtr<DataCallback> callback) +void WebFrameProxy::getResourceData(API::URL* resourceURL, std::function<void (API::Data*, CallbackBase::Error)> callbackFunction) { if (!m_page) { - callback->invalidate(); + callbackFunction(nullptr, CallbackBase::Error::Unknown); return; } - m_page->getResourceDataFromFrame(this, resourceURL, callback); + m_page->getResourceDataFromFrame(this, resourceURL, callbackFunction); } void WebFrameProxy::setUnreachableURL(const String& unreachableURL) @@ -230,4 +236,25 @@ void WebFrameProxy::setUnreachableURL(const String& unreachableURL) m_frameLoadState.setUnreachableURL(unreachableURL); } +#if ENABLE(CONTENT_FILTERING) +bool WebFrameProxy::didHandleContentFilterUnblockNavigation(const WebCore::ResourceRequest& request) +{ + if (!m_contentFilterUnblockHandler.canHandleRequest(request)) { + m_contentFilterUnblockHandler = { }; + return false; + } + + RefPtr<WebPageProxy> page { m_page }; + ASSERT(page); + m_contentFilterUnblockHandler.requestUnblockAsync([page](bool unblocked) { + if (unblocked) { + const bool reloadFromOrigin = false; + const bool contentBlockersEnabled = true; + page->reload(reloadFromOrigin, contentBlockersEnabled); + } + }); + return true; +} +#endif + } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebFrameProxy.h b/Source/WebKit2/UIProcess/WebFrameProxy.h index d82decbbe..2ee80489b 100644 --- a/Source/WebKit2/UIProcess/WebFrameProxy.h +++ b/Source/WebKit2/UIProcess/WebFrameProxy.h @@ -35,22 +35,27 @@ #include <wtf/PassRefPtr.h> #include <wtf/text/WTFString.h> +#if ENABLE(CONTENT_FILTERING) +#include <WebCore/ContentFilterUnblockHandler.h> +#endif + +namespace API { +class Navigation; +} + + namespace IPC { class ArgumentDecoder; class Connection; } -namespace WebCore { -class CertificateInfo; -} - namespace WebKit { class WebCertificateInfo; class WebFormSubmissionListenerProxy; class WebFramePolicyListenerProxy; class WebPageProxy; -typedef GenericCallback<WKDataRef> DataCallback; +typedef GenericCallback<API::Data*> DataCallback; class WebFrameProxy : public API::ObjectImpl<API::Object::Type::Frame> { public: @@ -64,7 +69,7 @@ public: uint64_t frameID() const { return m_frameID; } WebPageProxy* page() const { return m_page; } - void disconnect(); + void webProcessWillShutDown(); bool isMainFrame() const; @@ -76,13 +81,14 @@ public: void loadURL(const String&); void stopLoading() const; - const String& url() const { return m_frameLoadState.m_url; } - const String& provisionalURL() const { return m_frameLoadState.m_provisionalURL; } + const String& url() const { return m_frameLoadState.url(); } + const String& provisionalURL() const { return m_frameLoadState.provisionalURL(); } void setUnreachableURL(const String&); - const String& unreachableURL() const { return m_frameLoadState.m_unreachableURL; } + const String& unreachableURL() const { return m_frameLoadState.unreachableURL(); } const String& mimeType() const { return m_MIMEType; } + bool containsPluginDocument() const { return m_containsPluginDocument; } const String& title() const { return m_title; } @@ -92,26 +98,32 @@ public: bool canShowMIMEType(const String& mimeType) const; bool isDisplayingStandaloneImageDocument() const; + bool isDisplayingStandaloneMediaDocument() const; bool isDisplayingMarkupDocument() const; bool isDisplayingPDFDocument() const; - void getWebArchive(PassRefPtr<DataCallback>); - void getMainResourceData(PassRefPtr<DataCallback>); - void getResourceData(API::URL*, PassRefPtr<DataCallback>); + void getWebArchive(std::function<void (API::Data*, CallbackBase::Error)>); + void getMainResourceData(std::function<void (API::Data*, CallbackBase::Error)>); + void getResourceData(API::URL*, std::function<void (API::Data*, CallbackBase::Error)>); void didStartProvisionalLoad(const String& url); void didReceiveServerRedirectForProvisionalLoad(const String& url); void didFailProvisionalLoad(); - void didCommitLoad(const String& contentType, const WebCore::CertificateInfo&); + void didCommitLoad(const String& contentType, WebCertificateInfo&, bool containsPluginDocument); void didFinishLoad(); void didFailLoad(); void didSameDocumentNavigation(const String&); // eg. anchor navigation, session state change. void didChangeTitle(const String&); // Policy operations. - void receivedPolicyDecision(WebCore::PolicyAction, uint64_t listenerID); - WebFramePolicyListenerProxy* setUpPolicyListenerProxy(uint64_t listenerID); - WebFormSubmissionListenerProxy* setUpFormSubmissionListenerProxy(uint64_t listenerID); + void receivedPolicyDecision(WebCore::PolicyAction, uint64_t listenerID, API::Navigation* = nullptr); + WebFramePolicyListenerProxy& setUpPolicyListenerProxy(uint64_t listenerID); + WebFormSubmissionListenerProxy& setUpFormSubmissionListenerProxy(uint64_t listenerID); + +#if ENABLE(CONTENT_FILTERING) + void contentFilterDidBlockLoad(WebCore::ContentFilterUnblockHandler contentFilterUnblockHandler) { m_contentFilterUnblockHandler = WTFMove(contentFilterUnblockHandler); } + bool didHandleContentFilterUnblockNavigation(const WebCore::ResourceRequest&); +#endif private: WebFrameProxy(WebPageProxy* page, uint64_t frameID); @@ -123,9 +135,14 @@ private: String m_MIMEType; String m_title; bool m_isFrameSet; + bool m_containsPluginDocument { false }; RefPtr<WebCertificateInfo> m_certificateInfo; RefPtr<WebFrameListenerProxy> m_activeListener; uint64_t m_frameID; + +#if ENABLE(CONTENT_FILTERING) + WebCore::ContentFilterUnblockHandler m_contentFilterUnblockHandler; +#endif }; } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebFullScreenManagerProxy.h b/Source/WebKit2/UIProcess/WebFullScreenManagerProxy.h index 74342eac4..864531780 100644 --- a/Source/WebKit2/UIProcess/WebFullScreenManagerProxy.h +++ b/Source/WebKit2/UIProcess/WebFullScreenManagerProxy.h @@ -81,8 +81,8 @@ private: void beganEnterFullScreen(const WebCore::IntRect& initialFrame, const WebCore::IntRect& finalFrame); void beganExitFullScreen(const WebCore::IntRect& initialFrame, const WebCore::IntRect& finalFrame); - virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; - virtual void didReceiveSyncMessage(IPC::Connection*, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override; + virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override; + virtual void didReceiveSyncMessage(IPC::Connection&, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override; WebPageProxy* m_page; WebFullScreenManagerProxyClient* m_client; diff --git a/Source/WebKit2/UIProcess/WebGeolocationManagerProxy.cpp b/Source/WebKit2/UIProcess/WebGeolocationManagerProxy.cpp index a420b908f..740be469b 100644 --- a/Source/WebKit2/UIProcess/WebGeolocationManagerProxy.cpp +++ b/Source/WebKit2/UIProcess/WebGeolocationManagerProxy.cpp @@ -26,9 +26,9 @@ #include "config.h" #include "WebGeolocationManagerProxy.h" -#include "WebContext.h" #include "WebGeolocationManagerMessages.h" #include "WebGeolocationManagerProxyMessages.h" +#include "WebProcessPool.h" namespace WebKit { @@ -37,15 +37,15 @@ const char* WebGeolocationManagerProxy::supplementName() return "WebGeolocationManagerProxy"; } -PassRefPtr<WebGeolocationManagerProxy> WebGeolocationManagerProxy::create(WebContext* context) +PassRefPtr<WebGeolocationManagerProxy> WebGeolocationManagerProxy::create(WebProcessPool* processPool) { - return adoptRef(new WebGeolocationManagerProxy(context)); + return adoptRef(new WebGeolocationManagerProxy(processPool)); } -WebGeolocationManagerProxy::WebGeolocationManagerProxy(WebContext* context) - : WebContextSupplement(context) +WebGeolocationManagerProxy::WebGeolocationManagerProxy(WebProcessPool* processPool) + : WebContextSupplement(processPool) { - WebContextSupplement::context()->addMessageReceiver(Messages::WebGeolocationManagerProxy::messageReceiverName(), *this); + WebContextSupplement::processPool()->addMessageReceiver(Messages::WebGeolocationManagerProxy::messageReceiverName(), *this); } void WebGeolocationManagerProxy::initializeProvider(const WKGeolocationProviderBase* provider) @@ -55,10 +55,14 @@ void WebGeolocationManagerProxy::initializeProvider(const WKGeolocationProviderB // WebContextSupplement -void WebGeolocationManagerProxy::contextDestroyed() +void WebGeolocationManagerProxy::processPoolDestroyed() { + bool wasUpdating = isUpdating(); m_updateRequesters.clear(); - m_provider.stopUpdating(this); + + ASSERT(!isUpdating()); + if (wasUpdating) + m_provider.stopUpdating(this); } void WebGeolocationManagerProxy::processDidClose(WebProcessProxy* webProcessProxy) @@ -78,40 +82,40 @@ void WebGeolocationManagerProxy::derefWebContextSupplement() void WebGeolocationManagerProxy::providerDidChangePosition(WebGeolocationPosition* position) { - if (!context()) + if (!processPool()) return; - context()->sendToAllProcesses(Messages::WebGeolocationManager::DidChangePosition(position->data())); + processPool()->sendToAllProcesses(Messages::WebGeolocationManager::DidChangePosition(position->data())); } void WebGeolocationManagerProxy::providerDidFailToDeterminePosition(const String& errorMessage) { - if (!context()) + if (!processPool()) return; - context()->sendToAllProcesses(Messages::WebGeolocationManager::DidFailToDeterminePosition(errorMessage)); + processPool()->sendToAllProcesses(Messages::WebGeolocationManager::DidFailToDeterminePosition(errorMessage)); } #if PLATFORM(IOS) void WebGeolocationManagerProxy::resetPermissions() { - context()->sendToAllProcesses(Messages::WebGeolocationManager::ResetPermissions()); + processPool()->sendToAllProcesses(Messages::WebGeolocationManager::ResetPermissions()); } #endif -void WebGeolocationManagerProxy::startUpdating(IPC::Connection* connection) +void WebGeolocationManagerProxy::startUpdating(IPC::Connection& connection) { bool wasUpdating = isUpdating(); - m_updateRequesters.add(connection->client()); + m_updateRequesters.add(connection.client()); if (!wasUpdating) { m_provider.setEnableHighAccuracy(this, isHighAccuracyEnabled()); m_provider.startUpdating(this); } } -void WebGeolocationManagerProxy::stopUpdating(IPC::Connection* connection) +void WebGeolocationManagerProxy::stopUpdating(IPC::Connection& connection) { - removeRequester(connection->client()); + removeRequester(connection.client()); } void WebGeolocationManagerProxy::removeRequester(const IPC::Connection::Client* client) @@ -131,14 +135,14 @@ void WebGeolocationManagerProxy::removeRequester(const IPC::Connection::Client* } } -void WebGeolocationManagerProxy::setEnableHighAccuracy(IPC::Connection* connection, bool enabled) +void WebGeolocationManagerProxy::setEnableHighAccuracy(IPC::Connection& connection, bool enabled) { bool highAccuracyWasEnabled = isHighAccuracyEnabled(); if (enabled) - m_highAccuracyRequesters.add(connection->client()); + m_highAccuracyRequesters.add(connection.client()); else - m_highAccuracyRequesters.remove(connection->client()); + m_highAccuracyRequesters.remove(connection.client()); bool highAccuracyShouldBeEnabled = isHighAccuracyEnabled(); if (isUpdating() && highAccuracyWasEnabled != highAccuracyShouldBeEnabled) diff --git a/Source/WebKit2/UIProcess/WebGeolocationManagerProxy.h b/Source/WebKit2/UIProcess/WebGeolocationManagerProxy.h index 5668f9189..fa50846a5 100644 --- a/Source/WebKit2/UIProcess/WebGeolocationManagerProxy.h +++ b/Source/WebKit2/UIProcess/WebGeolocationManagerProxy.h @@ -36,14 +36,14 @@ namespace WebKit { -class WebContext; class WebGeolocationPosition; +class WebProcessPool; class WebGeolocationManagerProxy : public API::ObjectImpl<API::Object::Type::GeolocationManager>, public WebContextSupplement, private IPC::MessageReceiver { public: static const char* supplementName(); - static PassRefPtr<WebGeolocationManagerProxy> create(WebContext*); + static PassRefPtr<WebGeolocationManagerProxy> create(WebProcessPool*); void initializeProvider(const WKGeolocationProviderBase*); @@ -57,24 +57,24 @@ public: using API::Object::deref; private: - explicit WebGeolocationManagerProxy(WebContext*); + explicit WebGeolocationManagerProxy(WebProcessPool*); // WebContextSupplement - virtual void contextDestroyed() override; + virtual void processPoolDestroyed() override; virtual void processDidClose(WebProcessProxy*) override; virtual void refWebContextSupplement() override; virtual void derefWebContextSupplement() override; // IPC::MessageReceiver - virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; + virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override; bool isUpdating() const { return !m_updateRequesters.isEmpty(); } bool isHighAccuracyEnabled() const { return !m_highAccuracyRequesters.isEmpty(); } - void startUpdating(IPC::Connection*); - void stopUpdating(IPC::Connection*); + void startUpdating(IPC::Connection&); + void stopUpdating(IPC::Connection&); void removeRequester(const IPC::Connection::Client*); - void setEnableHighAccuracy(IPC::Connection*, bool); + void setEnableHighAccuracy(IPC::Connection&, bool); HashSet<const IPC::Connection::Client*> m_updateRequesters; HashSet<const IPC::Connection::Client*> m_highAccuracyRequesters; diff --git a/Source/WebKit2/UIProcess/WebGrammarDetail.cpp b/Source/WebKit2/UIProcess/WebGrammarDetail.cpp index 064fc3568..0fe1bfb31 100644 --- a/Source/WebKit2/UIProcess/WebGrammarDetail.cpp +++ b/Source/WebKit2/UIProcess/WebGrammarDetail.cpp @@ -55,13 +55,13 @@ WebGrammarDetail::WebGrammarDetail(int location, int length, API::Array* guesses m_grammarDetail.userDescription = userDescription; } -PassRefPtr<API::Array> WebGrammarDetail::guesses() const +Ref<API::Array> WebGrammarDetail::guesses() const { size_t numGuesses = m_grammarDetail.guesses.size(); Vector<RefPtr<API::Object> > wkGuesses(numGuesses); for (unsigned i = 0; i < numGuesses; ++i) wkGuesses[i] = API::String::create(m_grammarDetail.guesses[i]); - return API::Array::create(std::move(wkGuesses)); + return API::Array::create(WTFMove(wkGuesses)); } WebGrammarDetail::WebGrammarDetail(const WebCore::GrammarDetail& grammarDetail) diff --git a/Source/WebKit2/UIProcess/WebGrammarDetail.h b/Source/WebKit2/UIProcess/WebGrammarDetail.h index cbb81738f..7d1770570 100644 --- a/Source/WebKit2/UIProcess/WebGrammarDetail.h +++ b/Source/WebKit2/UIProcess/WebGrammarDetail.h @@ -41,7 +41,7 @@ public: int location() const { return m_grammarDetail.location; } int length() const { return m_grammarDetail.length; } - PassRefPtr<API::Array> guesses() const; + Ref<API::Array> guesses() const; const String& userDescription() const { return m_grammarDetail.userDescription; } const WebCore::GrammarDetail& grammarDetail() { return m_grammarDetail; } diff --git a/Source/WebKit2/UIProcess/WebHistoryClient.cpp b/Source/WebKit2/UIProcess/WebHistoryClient.cpp deleted file mode 100644 index d52297f09..000000000 --- a/Source/WebKit2/UIProcess/WebHistoryClient.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2010 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "WebHistoryClient.h" - -#include "APINavigationData.h" -#include "WKAPICast.h" -#include <wtf/RefPtr.h> - -using namespace WebCore; - -namespace WebKit { - -void WebHistoryClient::didNavigateWithNavigationData(WebContext* context, WebPageProxy* page, const WebNavigationDataStore& navigationDataStore, WebFrameProxy* frame) -{ - if (!m_client.didNavigateWithNavigationData) - return; - - RefPtr<API::NavigationData> navigationData = API::NavigationData::create(navigationDataStore); - m_client.didNavigateWithNavigationData(toAPI(context), toAPI(page), toAPI(navigationData.get()), toAPI(frame), m_client.base.clientInfo); -} - -void WebHistoryClient::didPerformClientRedirect(WebContext* context, WebPageProxy* page, const String& sourceURL, const String& destinationURL, WebFrameProxy* frame) -{ - if (!m_client.didPerformClientRedirect) - return; - - m_client.didPerformClientRedirect(toAPI(context), toAPI(page), toURLRef(sourceURL.impl()), toURLRef(destinationURL.impl()), toAPI(frame), m_client.base.clientInfo); -} - -void WebHistoryClient::didPerformServerRedirect(WebContext* context, WebPageProxy* page, const String& sourceURL, const String& destinationURL, WebFrameProxy* frame) -{ - if (!m_client.didPerformServerRedirect) - return; - - m_client.didPerformServerRedirect(toAPI(context), toAPI(page), toURLRef(sourceURL.impl()), toURLRef(destinationURL.impl()), toAPI(frame), m_client.base.clientInfo); -} - -void WebHistoryClient::didUpdateHistoryTitle(WebContext* context, WebPageProxy* page, const String& title, const String& url, WebFrameProxy* frame) -{ - if (!m_client.didUpdateHistoryTitle) - return; - - m_client.didUpdateHistoryTitle(toAPI(context), toAPI(page), toAPI(title.impl()), toURLRef(url.impl()), toAPI(frame), m_client.base.clientInfo); -} - -void WebHistoryClient::populateVisitedLinks(WebContext* context) -{ - if (!m_client.populateVisitedLinks) - return; - - m_client.populateVisitedLinks(toAPI(context), m_client.base.clientInfo); -} - -} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebIconDatabase.cpp b/Source/WebKit2/UIProcess/WebIconDatabase.cpp index 8ed610a24..56f5da1a2 100644 --- a/Source/WebKit2/UIProcess/WebIconDatabase.cpp +++ b/Source/WebKit2/UIProcess/WebIconDatabase.cpp @@ -26,42 +26,40 @@ #include "config.h" #include "WebIconDatabase.h" -#include "DataReference.h" #include "Logging.h" -#include "WebContext.h" #include "WebIconDatabaseMessages.h" #include "WebIconDatabaseProxyMessages.h" -#include "WebPreferences.h" +#include "WebProcessPool.h" #include <WebCore/FileSystem.h> #include <WebCore/IconDatabase.h> -#include <WebCore/IconDatabaseBase.h> -#include <wtf/text/CString.h> -#include <wtf/text/WTFString.h> +#include <WebCore/Image.h> +#include <WebCore/SharedBuffer.h> using namespace WebCore; namespace WebKit { -PassRefPtr<WebIconDatabase> WebIconDatabase::create(WebContext* context) +PassRefPtr<WebIconDatabase> WebIconDatabase::create(WebProcessPool* processPool) { - return adoptRef(new WebIconDatabase(context)); + return adoptRef(new WebIconDatabase(*processPool)); } WebIconDatabase::~WebIconDatabase() { } -WebIconDatabase::WebIconDatabase(WebContext* context) - : m_webContext(context) +WebIconDatabase::WebIconDatabase(WebProcessPool& processPool) + : m_processPool(&processPool) , m_urlImportCompleted(false) , m_databaseCleanupDisabled(false) + , m_shouldDerefWhenAppropriate(false) { - m_webContext->addMessageReceiver(Messages::WebIconDatabase::messageReceiverName(), *this); + m_processPool->addMessageReceiver(Messages::WebIconDatabase::messageReceiverName(), *this); } void WebIconDatabase::invalidate() { - setGlobalIconDatabase(0); + setGlobalIconDatabase(nullptr); } void WebIconDatabase::setDatabasePath(const String& path) @@ -71,20 +69,20 @@ void WebIconDatabase::setDatabasePath(const String& path) return; } - m_iconDatabaseImpl = IconDatabase::create(); + m_iconDatabaseImpl = std::make_unique<IconDatabase>(); m_iconDatabaseImpl->setClient(this); IconDatabase::delayDatabaseCleanup(); m_databaseCleanupDisabled = true; m_iconDatabaseImpl->setEnabled(true); - // FIXME: WebIconDatabases are per-WebContext but WebContext's don't have their own notion of the current private browsing setting. + // FIXME: WebIconDatabases are per-ProcessPool but ProcessPools's don't have their own notion of the current private browsing setting. // As we clean up private browsing throughout the stack we need to clean it up here. - m_iconDatabaseImpl->setPrivateBrowsingEnabled(WebPreferences::anyPageGroupsAreUsingPrivateBrowsing()); + m_iconDatabaseImpl->setPrivateBrowsingEnabled(WebPreferences::anyPagesAreUsingPrivateBrowsing()); if (!m_iconDatabaseImpl->open(directoryName(path), pathGetFileName(path))) { LOG_ERROR("Unable to open WebKit2 icon database on disk"); - m_iconDatabaseImpl.clear(); - setGlobalIconDatabase(0); + m_iconDatabaseImpl = nullptr; + setGlobalIconDatabase(nullptr); IconDatabase::allowDatabaseCleanup(); m_databaseCleanupDisabled = false; } @@ -103,7 +101,7 @@ void WebIconDatabase::enableDatabaseCleanup() ASSERT_NOT_REACHED(); return; } - + IconDatabase::allowDatabaseCleanup(); m_databaseCleanupDisabled = false; } @@ -132,9 +130,7 @@ void WebIconDatabase::setIconDataForIconURL(const IPC::DataReference& iconData, LOG(IconDatabase, "WK2 UIProcess setting icon data (%i bytes) for page URL %s", (int)iconData.size(), iconURL.ascii().data()); if (!m_iconDatabaseImpl) return; - - RefPtr<SharedBuffer> buffer = SharedBuffer::create(iconData.data(), iconData.size()); - m_iconDatabaseImpl->setIconDataForIconURL(buffer.release(), iconURL); + m_iconDatabaseImpl->setIconDataForIconURL(SharedBuffer::create(iconData.data(), iconData.size()), iconURL); } void WebIconDatabase::synchronousIconDataForPageURL(const String&, IPC::DataReference& iconData) @@ -148,7 +144,6 @@ void WebIconDatabase::synchronousIconURLForPageURL(const String& pageURL, String iconURL = String(); return; } - iconURL = m_iconDatabaseImpl->synchronousIconURLForPageURL(pageURL); } @@ -166,12 +161,12 @@ void WebIconDatabase::getLoadDecisionForIconURL(const String& iconURL, uint64_t { LOG(IconDatabase, "WK2 UIProcess getting load decision for icon URL %s with callback ID %lli", iconURL.ascii().data(), static_cast<long long>(callbackID)); - if (!m_webContext) + if (!m_processPool) return; if (!m_iconDatabaseImpl || !m_iconDatabaseImpl->isOpen() || iconURL.isEmpty()) { // FIXME (Multi-WebProcess): <rdar://problem/12240223> We need to know which connection to send this message to. - m_webContext->sendToAllProcesses(Messages::WebIconDatabaseProxy::ReceivedIconLoadDecision(static_cast<int>(IconLoadNo), callbackID)); + m_processPool->sendToAllProcesses(Messages::WebIconDatabaseProxy::ReceivedIconLoadDecision(static_cast<int>(IconLoadNo), callbackID)); return; } @@ -182,11 +177,11 @@ void WebIconDatabase::getLoadDecisionForIconURL(const String& iconURL, uint64_t ASSERT(!m_urlImportCompleted); m_pendingLoadDecisionURLMap.set(callbackID, iconURL); - return; + return; } // FIXME (Multi-WebProcess): <rdar://problem/12240223> We need to know which connection to send this message to. - m_webContext->sendToAllProcesses(Messages::WebIconDatabaseProxy::ReceivedIconLoadDecision((int)decision, callbackID)); + m_processPool->sendToAllProcesses(Messages::WebIconDatabaseProxy::ReceivedIconLoadDecision((int)decision, callbackID)); } void WebIconDatabase::didReceiveIconForPageURL(const String& pageURL) @@ -194,20 +189,20 @@ void WebIconDatabase::didReceiveIconForPageURL(const String& pageURL) notifyIconDataReadyForPageURL(pageURL); } -Image* WebIconDatabase::imageForPageURL(const String& pageURL, const WebCore::IntSize& iconSize) +Image* WebIconDatabase::imageForPageURL(const String& pageURL, const IntSize& iconSize) { - if (!m_webContext || !m_iconDatabaseImpl || !m_iconDatabaseImpl->isOpen() || pageURL.isEmpty()) - return 0; + if (!m_processPool || !m_iconDatabaseImpl || !m_iconDatabaseImpl->isOpen() || pageURL.isEmpty()) + return nullptr; // The WebCore IconDatabase ignores the passed in size parameter. // If that changes we'll need to rethink how this API is exposed. return m_iconDatabaseImpl->synchronousIconForPageURL(pageURL, iconSize); } -WebCore::NativeImagePtr WebIconDatabase::nativeImageForPageURL(const String& pageURL, const WebCore::IntSize& iconSize) +NativeImagePtr WebIconDatabase::nativeImageForPageURL(const String& pageURL, const IntSize& iconSize) { - if (!m_webContext || !m_iconDatabaseImpl || !m_iconDatabaseImpl->isOpen() || pageURL.isEmpty()) - return 0; + if (!m_processPool || !m_iconDatabaseImpl || !m_iconDatabaseImpl->isOpen() || pageURL.isEmpty()) + return nullptr; return m_iconDatabaseImpl->synchronousNativeIconForPageURL(pageURL, iconSize); } @@ -224,7 +219,7 @@ bool WebIconDatabase::isUrlImportCompleted() void WebIconDatabase::removeAllIcons() { - m_iconDatabaseImpl->removeAllIcons(); + m_iconDatabaseImpl->removeAllIcons(); } void WebIconDatabase::checkIntegrityBeforeOpening() @@ -257,7 +252,7 @@ void WebIconDatabase::didImportIconDataForPageURL(const String& pageURL) void WebIconDatabase::didChangeIconForPageURL(const String& pageURL) { - m_iconDatabaseClient.didChangeIconForPageURL(this, API::URL::create(pageURL).get()); + m_iconDatabaseClient.didChangeIconForPageURL(this, API::URL::create(pageURL).ptr()); } void WebIconDatabase::didRemoveAllIcons() @@ -267,35 +262,50 @@ void WebIconDatabase::didRemoveAllIcons() void WebIconDatabase::didFinishURLImport() { - if (!m_webContext) + if (!m_processPool) return; - + ASSERT(!m_urlImportCompleted); LOG(IconDatabase, "WK2 UIProcess URL import complete, notifying all %i pending page URL load decisions", m_pendingLoadDecisionURLMap.size()); - - HashMap<uint64_t, String>::iterator i = m_pendingLoadDecisionURLMap.begin(); - HashMap<uint64_t, String>::iterator end = m_pendingLoadDecisionURLMap.end(); - for (; i != end; ++i) { - LOG(IconDatabase, "WK2 UIProcess performing delayed callback on callback ID %i for page url %s", (int)i->key, i->value.ascii().data()); - IconLoadDecision decision = m_iconDatabaseImpl->synchronousLoadDecisionForIconURL(i->value, 0); + for (auto& slot : m_pendingLoadDecisionURLMap) { + LOG(IconDatabase, "WK2 UIProcess performing delayed callback on callback ID %i for page url %s", (int)slot.key, slot.value.ascii().data()); + IconLoadDecision decision = m_iconDatabaseImpl->synchronousLoadDecisionForIconURL(slot.value, nullptr); - // Decisions should never be unknown after the inital import is complete + // Decisions should never be unknown after the inital import is complete. ASSERT(decision != IconLoadUnknown); // FIXME (Multi-WebProcess): <rdar://problem/12240223> We need to know which connection to send this message to. - m_webContext->sendToAllProcesses(Messages::WebIconDatabaseProxy::ReceivedIconLoadDecision(static_cast<int>(decision), i->key)); + m_processPool->sendToAllProcesses(Messages::WebIconDatabaseProxy::ReceivedIconLoadDecision(static_cast<int>(decision), slot.key)); } - + m_pendingLoadDecisionURLMap.clear(); - + m_urlImportCompleted = true; } +void WebIconDatabase::didClose() +{ + if (!m_shouldDerefWhenAppropriate) + return; + + deref(); +} + +void WebIconDatabase::derefWhenAppropriate() +{ + if (m_iconDatabaseImpl && m_iconDatabaseImpl->isOpen()) { + m_shouldDerefWhenAppropriate = true; + return; + } + + deref(); +} + void WebIconDatabase::notifyIconDataReadyForPageURL(const String& pageURL) { - m_iconDatabaseClient.iconDataReadyForPageURL(this, API::URL::create(pageURL).get()); + m_iconDatabaseClient.iconDataReadyForPageURL(this, API::URL::create(pageURL).ptr()); didChangeIconForPageURL(pageURL); } @@ -305,4 +315,23 @@ void WebIconDatabase::setPrivateBrowsingEnabled(bool privateBrowsingEnabled) m_iconDatabaseImpl->setPrivateBrowsingEnabled(privateBrowsingEnabled); } +PassRefPtr<API::Data> WebIconDatabase::iconDataForPageURL(const String& pageURL) +{ + auto* image = imageForPageURL(pageURL); + if (!image) + return nullptr; + + SharedBuffer* sharedBuffer = image->data(); + if (!sharedBuffer) + return nullptr; + + // Balanced by deref() below. + sharedBuffer->ref(); + return API::Data::createWithoutCopying(reinterpret_cast<const unsigned char*>(sharedBuffer->data()), sharedBuffer->size(), + [](unsigned char*, const void* untypedSharedBuffer) { + // Balanced by ref() above. + static_cast<SharedBuffer*>(const_cast<void*>(untypedSharedBuffer))->deref(); + }, sharedBuffer); +} + } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebIconDatabase.h b/Source/WebKit2/UIProcess/WebIconDatabase.h index 816b20d4b..7d8b6025f 100644 --- a/Source/WebKit2/UIProcess/WebIconDatabase.h +++ b/Source/WebKit2/UIProcess/WebIconDatabase.h @@ -27,21 +27,14 @@ #define WebIconDatabase_h #include "APIObject.h" - #include "Connection.h" #include "WebIconDatabaseClient.h" #include <WebCore/IconDatabaseClient.h> -#include <WebCore/ImageSource.h> #include <WebCore/IntSize.h> -#include <wtf/Forward.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefPtr.h> -#include <wtf/Vector.h> -#include <wtf/text/StringHash.h> - -namespace IPC { -class ArgumentDecoder; -class DataReference; +#include <WebCore/NativeImagePtr.h> + +namespace API { +class Data; } namespace WebCore { @@ -51,15 +44,15 @@ class Image; namespace WebKit { -class WebContext; +class WebProcessPool; -class WebIconDatabase : public API::ObjectImpl<API::Object::Type::IconDatabase>, public WebCore::IconDatabaseClient, private IPC::MessageReceiver { +class WebIconDatabase : public API::ObjectImpl<API::Object::Type::IconDatabase>, private WebCore::IconDatabaseClient, private IPC::MessageReceiver { public: - static PassRefPtr<WebIconDatabase> create(WebContext*); + static PassRefPtr<WebIconDatabase> create(WebProcessPool*); virtual ~WebIconDatabase(); void invalidate(); - void clearContext() { m_webContext = 0; } + void clearProcessPool() { m_processPool = nullptr; } void setDatabasePath(const String&); void enableDatabaseCleanup(); @@ -67,17 +60,19 @@ public: void releaseIconForPageURL(const String&); void setIconURLForPageURL(const String&, const String&); void setIconDataForIconURL(const IPC::DataReference&, const String&); - + void synchronousIconDataForPageURL(const String&, IPC::DataReference&); void synchronousIconURLForPageURL(const String&, String&); void synchronousIconDataKnownForIconURL(const String&, bool&) const; void synchronousLoadDecisionForIconURL(const String&, int&) const; - + void getLoadDecisionForIconURL(const String&, uint64_t callbackID); void didReceiveIconForPageURL(const String&); WebCore::Image* imageForPageURL(const String&, const WebCore::IntSize& iconSize = WebCore::IntSize(32, 32)); WebCore::NativeImagePtr nativeImageForPageURL(const String&, const WebCore::IntSize& iconSize = WebCore::IntSize(32, 32)); + PassRefPtr<API::Data> iconDataForPageURL(const String& pageURL); + bool isOpen(); bool isUrlImportCompleted(); @@ -88,28 +83,35 @@ public: void initializeIconDatabaseClient(const WKIconDatabaseClientBase*); void setPrivateBrowsingEnabled(bool); - + + // Called when the WebProcessPool is through with this WebIconDatabase but the + // WebCore::IconDatabase possibly isn't done shutting down. + // In that case this WebIconDatabase will deref() itself when the time is right. + void derefWhenAppropriate(); + private: - WebIconDatabase(WebContext*); + explicit WebIconDatabase(WebProcessPool&); // WebCore::IconDatabaseClient - virtual void didImportIconURLForPageURL(const String&); - virtual void didImportIconDataForPageURL(const String&); - virtual void didChangeIconForPageURL(const String&); - virtual void didRemoveAllIcons(); - virtual void didFinishURLImport(); + virtual void didImportIconURLForPageURL(const String&) override; + virtual void didImportIconDataForPageURL(const String&) override; + virtual void didChangeIconForPageURL(const String&) override; + virtual void didRemoveAllIcons() override; + virtual void didFinishURLImport() override; + virtual void didClose() override; // IPC::MessageReceiver - virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; - virtual void didReceiveSyncMessage(IPC::Connection*, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override; + virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override; + virtual void didReceiveSyncMessage(IPC::Connection&, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override; void notifyIconDataReadyForPageURL(const String&); - WebContext* m_webContext; - - OwnPtr<WebCore::IconDatabase> m_iconDatabaseImpl; + WebProcessPool* m_processPool; + + std::unique_ptr<WebCore::IconDatabase> m_iconDatabaseImpl; bool m_urlImportCompleted; bool m_databaseCleanupDisabled; + bool m_shouldDerefWhenAppropriate; HashMap<uint64_t, String> m_pendingLoadDecisionURLMap; WebIconDatabaseClient m_iconDatabaseClient; diff --git a/Source/WebKit2/UIProcess/WebIconDatabase.messages.in b/Source/WebKit2/UIProcess/WebIconDatabase.messages.in index 37052b5d8..f5b96fd1f 100644 --- a/Source/WebKit2/UIProcess/WebIconDatabase.messages.in +++ b/Source/WebKit2/UIProcess/WebIconDatabase.messages.in @@ -21,8 +21,6 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. messages -> WebIconDatabase { - RetainIconForPageURL(String pageURL) - ReleaseIconForPageURL(String pageURL) SetIconURLForPageURL(String iconURL, String pageURL) SetIconDataForIconURL(IPC::DataReference iconData, String iconURL) diff --git a/Source/WebKit2/UIProcess/WebIconDatabaseClient.cpp b/Source/WebKit2/UIProcess/WebIconDatabaseClient.cpp index 0cc148e89..9555bc233 100644 --- a/Source/WebKit2/UIProcess/WebIconDatabaseClient.cpp +++ b/Source/WebKit2/UIProcess/WebIconDatabaseClient.cpp @@ -28,6 +28,7 @@ #include "WKAPICast.h" #include "WKSharedAPICast.h" +#include "WebIconDatabase.h" namespace WebKit { diff --git a/Source/WebKit2/UIProcess/WebInspectorProxy.cpp b/Source/WebKit2/UIProcess/WebInspectorProxy.cpp index 2d2297f8c..fa84acd7c 100644 --- a/Source/WebKit2/UIProcess/WebInspectorProxy.cpp +++ b/Source/WebKit2/UIProcess/WebInspectorProxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2010, 2014 Apple Inc. All rights reserved. * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,19 +27,22 @@ #include "config.h" #include "WebInspectorProxy.h" -#if ENABLE(INSPECTOR) - +#include "APIProcessPoolConfiguration.h" #include "APIURLRequest.h" +#include "WKArray.h" +#include "WKContextMenuItem.h" +#include "WKMutableArray.h" #include "WebFramePolicyListenerProxy.h" #include "WebFrameProxy.h" #include "WebInspectorMessages.h" #include "WebInspectorProxyMessages.h" -#include "WebPageCreationParameters.h" +#include "WebInspectorUIMessages.h" #include "WebPageGroup.h" #include "WebPageProxy.h" #include "WebPreferences.h" +#include "WebProcessPool.h" #include "WebProcessProxy.h" -#include <WebCore/SchemeRegistry.h> +#include <WebCore/NotImplemented.h> #include <wtf/NeverDestroyed.h> #if ENABLE(INSPECTOR_SERVER) @@ -50,129 +53,73 @@ using namespace WebCore; namespace WebKit { -const unsigned WebInspectorProxy::minimumWindowWidth = 750; +const unsigned WebInspectorProxy::minimumWindowWidth = 500; const unsigned WebInspectorProxy::minimumWindowHeight = 400; const unsigned WebInspectorProxy::initialWindowWidth = 1000; const unsigned WebInspectorProxy::initialWindowHeight = 650; -const unsigned WebInspectorProxy::minimumAttachedWidth = 750; -const unsigned WebInspectorProxy::minimumAttachedHeight = 250; - -class WebInspectorPageGroups { -public: - static WebInspectorPageGroups& shared() - { - static NeverDestroyed<WebInspectorPageGroups> instance; - return instance; - } - - unsigned inspectorLevel(WebPageGroup& inspectedPageGroup) - { - return isInspectorPageGroup(inspectedPageGroup) ? inspectorPageGroupLevel(inspectedPageGroup) + 1 : 1; - } - - bool isInspectorPageGroup(WebPageGroup& group) - { - return m_pageGroupLevel.contains(&group); - } - - unsigned inspectorPageGroupLevel(WebPageGroup& group) - { - ASSERT(isInspectorPageGroup(group)); - return m_pageGroupLevel.get(&group); - } +typedef HashMap<WebPageProxy*, unsigned> PageLevelMap; - WebPageGroup* inspectorPageGroupForLevel(unsigned level) - { - // The level is the key of the HashMap, so it cannot be 0. - ASSERT(level); - - auto iterator = m_pageGroupByLevel.find(level); - if (iterator != m_pageGroupByLevel.end()) - return iterator->value.get(); - - RefPtr<WebPageGroup> group = createInspectorPageGroup(level); - m_pageGroupByLevel.set(level, group.get()); - m_pageGroupLevel.set(group.get(), level); - return group.get(); - } - -private: - static PassRefPtr<WebPageGroup> createInspectorPageGroup(unsigned level) - { - RefPtr<WebPageGroup> pageGroup = WebPageGroup::create(String::format("__WebInspectorPageGroupLevel%u__", level), false, false); +static PageLevelMap& pageLevelMap() +{ + static NeverDestroyed<PageLevelMap> map; + return map; +} -#ifndef NDEBUG - // Allow developers to inspect the Web Inspector in debug builds. - pageGroup->preferences()->setDeveloperExtrasEnabled(true); - pageGroup->preferences()->setLogsPageMessagesToSystemConsoleEnabled(true); +WebInspectorProxy::WebInspectorProxy(WebPageProxy* inspectedPage) + : m_inspectedPage(inspectedPage) +#if PLATFORM(MAC) && WK_API_ENABLED + , m_closeTimer(RunLoop::main(), this, &WebInspectorProxy::closeTimerFired) #endif +{ + m_inspectedPage->process().addMessageReceiver(Messages::WebInspectorProxy::messageReceiverName(), m_inspectedPage->pageID(), *this); +} - pageGroup->preferences()->setApplicationChromeModeEnabled(true); - - return pageGroup.release(); - } +WebInspectorProxy::~WebInspectorProxy() +{ +} - typedef HashMap<unsigned, RefPtr<WebPageGroup> > PageGroupByLevelMap; - typedef HashMap<WebPageGroup*, unsigned> PageGroupLevelMap; - - PageGroupByLevelMap m_pageGroupByLevel; - PageGroupLevelMap m_pageGroupLevel; -}; - -WebInspectorProxy::WebInspectorProxy(WebPageProxy* page) - : m_page(page) - , m_isVisible(false) - , m_isAttached(false) - , m_isDebuggingJavaScript(false) - , m_isProfilingJavaScript(false) - , m_isProfilingPage(false) - , m_showMessageSent(false) - , m_createdInspectorPage(false) - , m_ignoreFirstBringToFront(false) - , m_attachmentSide(AttachmentSideBottom) -#if PLATFORM(GTK) || PLATFORM(EFL) - , m_inspectorView(0) - , m_inspectorWindow(0) -#endif -#if ENABLE(INSPECTOR_SERVER) - , m_remoteInspectionPageId(0) -#endif +unsigned WebInspectorProxy::inspectionLevel() const { - m_level = WebInspectorPageGroups::shared().inspectorLevel(m_page->pageGroup()); - m_page->process().addMessageReceiver(Messages::WebInspectorProxy::messageReceiverName(), m_page->pageID(), *this); + auto findResult = pageLevelMap().find(inspectedPage()); + if (findResult != pageLevelMap().end()) + return findResult->value + 1; + + return 1; } -WebInspectorProxy::~WebInspectorProxy() +String WebInspectorProxy::inspectorPageGroupIdentifier() const { + return String::format("__WebInspectorPageGroupLevel%u__", inspectionLevel()); } -WebPageGroup* WebInspectorProxy::inspectorPageGroup() const +WebPreferences& WebInspectorProxy::inspectorPagePreferences() const { - return WebInspectorPageGroups::shared().inspectorPageGroupForLevel(m_level); + ASSERT(m_inspectorPage); + return m_inspectorPage->pageGroup().preferences(); } void WebInspectorProxy::invalidate() { #if ENABLE(INSPECTOR_SERVER) if (m_remoteInspectionPageId) - WebInspectorServer::shared().unregisterPage(m_remoteInspectionPageId); + WebInspectorServer::singleton().unregisterPage(m_remoteInspectionPageId); #endif - m_page->process().removeMessageReceiver(Messages::WebInspectorProxy::messageReceiverName(), m_page->pageID()); - - m_page->close(); + m_inspectedPage->process().removeMessageReceiver(Messages::WebInspectorProxy::messageReceiverName(), m_inspectedPage->pageID()); didClose(); + platformInvalidate(); - m_page = 0; + pageLevelMap().remove(m_inspectedPage); + m_inspectedPage = nullptr; } // Public APIs bool WebInspectorProxy::isFront() { - if (!m_page) + if (!m_inspectedPage) return false; return platformIsFront(); @@ -180,7 +127,7 @@ bool WebInspectorProxy::isFront() void WebInspectorProxy::connect() { - if (!m_page) + if (!m_inspectedPage) return; if (m_showMessageSent) @@ -189,12 +136,14 @@ void WebInspectorProxy::connect() m_showMessageSent = true; m_ignoreFirstBringToFront = true; - m_page->process().send(Messages::WebInspector::Show(), m_page->pageID()); + eagerlyCreateInspectorPage(); + + m_inspectedPage->process().send(Messages::WebInspector::Show(), m_inspectedPage->pageID()); } void WebInspectorProxy::show() { - if (!m_page) + if (!m_inspectedPage) return; if (isConnected()) { @@ -210,7 +159,7 @@ void WebInspectorProxy::show() void WebInspectorProxy::hide() { - if (!m_page) + if (!m_inspectedPage) return; m_isVisible = false; @@ -220,68 +169,87 @@ void WebInspectorProxy::hide() void WebInspectorProxy::close() { - if (!m_page) + if (!m_inspectedPage) return; - m_page->process().send(Messages::WebInspector::Close(), m_page->pageID()); + m_inspectedPage->process().send(Messages::WebInspector::Close(), m_inspectedPage->pageID()); didClose(); } +void WebInspectorProxy::didRelaunchInspectorPageProcess() +{ + m_inspectorPage->process().addMessageReceiver(Messages::WebInspectorProxy::messageReceiverName(), m_inspectedPage->pageID(), *this); + m_inspectorPage->process().assumeReadAccessToBaseURL(WebInspectorProxy::inspectorBaseURL()); + + // When didRelaunchInspectorPageProcess is called we can assume it is during a load request. + // Any messages we would have sent to a terminated process need to be re-sent. + + m_inspectorPage->process().send(Messages::WebInspectorUI::EstablishConnection(m_connectionIdentifier, m_inspectedPage->pageID(), m_underTest, inspectionLevel()), m_inspectorPage->pageID()); +} + void WebInspectorProxy::showConsole() { - if (!m_page) + if (!m_inspectedPage) return; - m_page->process().send(Messages::WebInspector::ShowConsole(), m_page->pageID()); + eagerlyCreateInspectorPage(); + + m_inspectedPage->process().send(Messages::WebInspector::ShowConsole(), m_inspectedPage->pageID()); } void WebInspectorProxy::showResources() { - if (!m_page) + if (!m_inspectedPage) return; - m_page->process().send(Messages::WebInspector::ShowResources(), m_page->pageID()); + eagerlyCreateInspectorPage(); + + m_inspectedPage->process().send(Messages::WebInspector::ShowResources(), m_inspectedPage->pageID()); } void WebInspectorProxy::showMainResourceForFrame(WebFrameProxy* frame) { - if (!m_page) + if (!m_inspectedPage) return; - m_page->process().send(Messages::WebInspector::ShowMainResourceForFrame(frame->frameID()), m_page->pageID()); + eagerlyCreateInspectorPage(); + + m_inspectedPage->process().send(Messages::WebInspector::ShowMainResourceForFrame(frame->frameID()), m_inspectedPage->pageID()); } void WebInspectorProxy::attachBottom() { - attach(AttachmentSideBottom); + attach(AttachmentSide::Bottom); } void WebInspectorProxy::attachRight() { - attach(AttachmentSideRight); + attach(AttachmentSide::Right); } void WebInspectorProxy::attach(AttachmentSide side) { - if (!m_page || !canAttach()) + if (!m_inspectedPage || !canAttach()) return; m_isAttached = true; m_attachmentSide = side; - inspectorPageGroup()->preferences()->setInspectorAttachmentSide(side); + inspectorPagePreferences().setInspectorAttachmentSide(static_cast<uint32_t>(side)); if (m_isVisible) - inspectorPageGroup()->preferences()->setInspectorStartsAttached(true); + inspectorPagePreferences().setInspectorStartsAttached(true); + + m_inspectedPage->process().send(Messages::WebInspector::SetAttached(true), m_inspectedPage->pageID()); switch (m_attachmentSide) { - case AttachmentSideBottom: - m_page->process().send(Messages::WebInspector::AttachedBottom(), m_page->pageID()); + case AttachmentSide::Bottom: + m_inspectorPage->process().send(Messages::WebInspectorUI::AttachedBottom(), m_inspectorPage->pageID()); break; - case AttachmentSideRight: - m_page->process().send(Messages::WebInspector::AttachedRight(), m_page->pageID()); + case AttachmentSide::Right: + m_inspectorPage->process().send(Messages::WebInspectorUI::AttachedRight(), m_inspectorPage->pageID()); break; } @@ -290,87 +258,99 @@ void WebInspectorProxy::attach(AttachmentSide side) void WebInspectorProxy::detach() { - if (!m_page) + if (!m_inspectedPage) return; m_isAttached = false; if (m_isVisible) - inspectorPageGroup()->preferences()->setInspectorStartsAttached(false); + inspectorPagePreferences().setInspectorStartsAttached(false); - m_page->process().send(Messages::WebInspector::Detached(), m_page->pageID()); + m_inspectedPage->process().send(Messages::WebInspector::SetAttached(false), m_inspectedPage->pageID()); + m_inspectorPage->process().send(Messages::WebInspectorUI::Detached(), m_inspectorPage->pageID()); platformDetach(); } void WebInspectorProxy::setAttachedWindowHeight(unsigned height) { - inspectorPageGroup()->preferences()->setInspectorAttachedHeight(height); + inspectorPagePreferences().setInspectorAttachedHeight(height); platformSetAttachedWindowHeight(height); } void WebInspectorProxy::setAttachedWindowWidth(unsigned width) { - inspectorPageGroup()->preferences()->setInspectorAttachedWidth(width); + inspectorPagePreferences().setInspectorAttachedWidth(width); platformSetAttachedWindowWidth(width); } -void WebInspectorProxy::toggleJavaScriptDebugging() +void WebInspectorProxy::startWindowDrag() { - if (!m_page) - return; - - if (m_isDebuggingJavaScript) - m_page->process().send(Messages::WebInspector::StopJavaScriptDebugging(), m_page->pageID()); - else - m_page->process().send(Messages::WebInspector::StartJavaScriptDebugging(), m_page->pageID()); - - // FIXME: have the WebProcess notify us on state changes. - m_isDebuggingJavaScript = !m_isDebuggingJavaScript; + platformStartWindowDrag(); } -void WebInspectorProxy::toggleJavaScriptProfiling() +void WebInspectorProxy::togglePageProfiling() { - if (!m_page) + if (!m_inspectedPage) return; - if (m_isProfilingJavaScript) - m_page->process().send(Messages::WebInspector::StopJavaScriptProfiling(), m_page->pageID()); + if (m_isProfilingPage) + m_inspectedPage->process().send(Messages::WebInspector::StopPageProfiling(), m_inspectedPage->pageID()); else - m_page->process().send(Messages::WebInspector::StartJavaScriptProfiling(), m_page->pageID()); + m_inspectedPage->process().send(Messages::WebInspector::StartPageProfiling(), m_inspectedPage->pageID()); // FIXME: have the WebProcess notify us on state changes. - m_isProfilingJavaScript = !m_isProfilingJavaScript; + m_isProfilingPage = !m_isProfilingPage; } -void WebInspectorProxy::togglePageProfiling() -{ - if (!m_page) - return; +static WebProcessPool* s_mainInspectorProcessPool; +static WebProcessPool* s_nestedInspectorProcessPool; - if (m_isProfilingPage) - m_page->process().send(Messages::WebInspector::StopPageProfiling(), m_page->pageID()); - else - m_page->process().send(Messages::WebInspector::StartPageProfiling(), m_page->pageID()); +WebProcessPool& WebInspectorProxy::inspectorProcessPool(unsigned inspectionLevel) +{ + // Having our own process pool removes us from the main process pool and + // guarantees no process sharing for our user interface. + WebProcessPool*& pool = inspectionLevel == 1 ? s_mainInspectorProcessPool : s_nestedInspectorProcessPool; + if (!pool) { + auto configuration = API::ProcessPoolConfiguration::createWithLegacyOptions(); + pool = &WebProcessPool::create(configuration.get()).leakRef(); + } + return *pool; +} - // FIXME: have the WebProcess notify us on state changes. - m_isProfilingPage = !m_isProfilingPage; +bool WebInspectorProxy::isInspectorProcessPool(WebProcessPool& processPool) +{ + return (s_mainInspectorProcessPool && s_mainInspectorProcessPool == &processPool) + || (s_nestedInspectorProcessPool && s_nestedInspectorProcessPool == &processPool); } -bool WebInspectorProxy::isInspectorPage(WebPageProxy& page) +bool WebInspectorProxy::isInspectorPage(WebPageProxy& webPage) { - return WebInspectorPageGroups::shared().isInspectorPageGroup(page.pageGroup()); + return pageLevelMap().contains(&webPage); } -static bool isMainInspectorPage(const WebInspectorProxy* webInspectorProxy, WKURLRequestRef requestRef) +static bool isMainOrTestInspectorPage(WKURLRequestRef requestRef) { - // Use URL so we can compare just the paths. - URL inspectorURL(URL(), webInspectorProxy->inspectorPageURL()); - URL requestURL(URL(), toImpl(requestRef)->resourceRequest().url()); + // Use URL so we can compare the paths and protocols. + const URL& requestURL = toImpl(requestRef)->resourceRequest().url(); + URL mainPageURL(URL(), WebInspectorProxy::inspectorPageURL()); + if (requestURL.protocol() == mainPageURL.protocol() && decodeURLEscapeSequences(requestURL.path()) == decodeURLEscapeSequences(mainPageURL.path())) + return true; + + // We might not have a Test URL in Production builds. + String testPageURLString = WebInspectorProxy::inspectorTestPageURL(); + if (testPageURLString.isNull()) + return false; - ASSERT(WebCore::SchemeRegistry::shouldTreatURLSchemeAsLocal(inspectorURL.protocol())); + URL testPageURL(URL(), testPageURLString); + return requestURL.protocol() == testPageURL.protocol() && decodeURLEscapeSequences(requestURL.path()) == decodeURLEscapeSequences(testPageURL.path()); +} - return WebCore::SchemeRegistry::shouldTreatURLSchemeAsLocal(requestURL.protocol()) && decodeURLEscapeSequences(requestURL.path()) == decodeURLEscapeSequences(inspectorURL.path()); +static void processDidCrash(WKPageRef, const void* clientInfo) +{ + WebInspectorProxy* webInspectorProxy = static_cast<WebInspectorProxy*>(const_cast<void*>(clientInfo)); + ASSERT(webInspectorProxy); + webInspectorProxy->close(); } static void decidePolicyForNavigationAction(WKPageRef, WKFrameRef frameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKFrameRef, WKURLRequestRef requestRef, WKFramePolicyListenerRef listenerRef, WKTypeRef, const void* clientInfo) @@ -385,7 +365,7 @@ static void decidePolicyForNavigationAction(WKPageRef, WKFrameRef frameRef, WKFr ASSERT(webInspectorProxy); // Allow loading of the main inspector file. - if (isMainInspectorPage(webInspectorProxy, requestRef)) { + if (isMainOrTestInspectorPage(requestRef)) { toImpl(listenerRef)->use(); return; } @@ -394,90 +374,187 @@ static void decidePolicyForNavigationAction(WKPageRef, WKFrameRef frameRef, WKFr toImpl(listenerRef)->ignore(); // And instead load it in the inspected page. - webInspectorProxy->page()->loadRequest(toImpl(requestRef)->resourceRequest()); + webInspectorProxy->inspectedPage()->loadRequest(toImpl(requestRef)->resourceRequest()); +} + +static void getContextMenuFromProposedMenu(WKPageRef pageRef, WKArrayRef proposedMenuRef, WKArrayRef* newMenuRef, WKHitTestResultRef, WKTypeRef, const void*) +{ + WKMutableArrayRef menuItems = WKMutableArrayCreate(); + + size_t count = WKArrayGetSize(proposedMenuRef); + for (size_t i = 0; i < count; ++i) { + WKContextMenuItemRef contextMenuItem = static_cast<WKContextMenuItemRef>(WKArrayGetItemAtIndex(proposedMenuRef, i)); + switch (WKContextMenuItemGetTag(contextMenuItem)) { + case kWKContextMenuItemTagOpenLinkInNewWindow: + case kWKContextMenuItemTagOpenImageInNewWindow: + case kWKContextMenuItemTagOpenFrameInNewWindow: + case kWKContextMenuItemTagOpenMediaInNewWindow: + case kWKContextMenuItemTagDownloadLinkToDisk: + case kWKContextMenuItemTagDownloadImageToDisk: + break; + default: + WKArrayAppendItem(menuItems, contextMenuItem); + break; + } + } + + *newMenuRef = menuItems; } #if ENABLE(INSPECTOR_SERVER) void WebInspectorProxy::enableRemoteInspection() { if (!m_remoteInspectionPageId) - m_remoteInspectionPageId = WebInspectorServer::shared().registerPage(this); + m_remoteInspectionPageId = WebInspectorServer::singleton().registerPage(this); } void WebInspectorProxy::remoteFrontendConnected() { - m_page->process().send(Messages::WebInspector::RemoteFrontendConnected(), m_page->pageID()); + m_inspectedPage->process().send(Messages::WebInspector::RemoteFrontendConnected(), m_inspectedPage->pageID()); } void WebInspectorProxy::remoteFrontendDisconnected() { - m_page->process().send(Messages::WebInspector::RemoteFrontendDisconnected(), m_page->pageID()); + m_inspectedPage->process().send(Messages::WebInspector::RemoteFrontendDisconnected(), m_inspectedPage->pageID()); } void WebInspectorProxy::dispatchMessageFromRemoteFrontend(const String& message) { - m_page->process().send(Messages::WebInspector::DispatchMessageFromRemoteFrontend(message), m_page->pageID()); + m_inspectedPage->process().send(Messages::WebInspector::SendMessageToBackend(message), m_inspectedPage->pageID()); } #endif -// Called by WebInspectorProxy messages -void WebInspectorProxy::createInspectorPage(uint64_t& inspectorPageID, WebPageCreationParameters& inspectorPageParameters) +void WebInspectorProxy::eagerlyCreateInspectorPage() { - inspectorPageID = 0; - - if (!m_page) + if (m_inspectorPage) return; - m_isAttached = shouldOpenAttached(); - m_attachmentSide = static_cast<AttachmentSide>(inspectorPageGroup()->preferences()->inspectorAttachmentSide()); - - WebPageProxy* inspectorPage = platformCreateInspectorPage(); - ASSERT(inspectorPage); - if (!inspectorPage) + m_inspectorPage = platformCreateInspectorPage(); + ASSERT(m_inspectorPage); + if (!m_inspectorPage) return; - inspectorPageID = inspectorPage->pageID(); - inspectorPageParameters = inspectorPage->creationParameters(); + pageLevelMap().set(m_inspectorPage, inspectionLevel()); WKPagePolicyClientV1 policyClient = { { 1, this }, - 0, /* decidePolicyForNavigationAction_deprecatedForUseWithV0 */ - 0, /* decidePolicyForNewWindowAction */ - 0, /* decidePolicyForResponse_deprecatedForUseWithV0 */ - 0, /* unableToImplementPolicy */ + nullptr, // decidePolicyForNavigationAction_deprecatedForUseWithV0 + nullptr, // decidePolicyForNewWindowAction + nullptr, // decidePolicyForResponse_deprecatedForUseWithV0 + nullptr, // unableToImplementPolicy decidePolicyForNavigationAction, - 0, /* decidePolicyForResponse */ + nullptr, // decidePolicyForResponse }; - WKPageSetPagePolicyClient(toAPI(inspectorPage), &policyClient.base); + WKPageLoaderClientV5 loaderClient = { + { 5, this }, + nullptr, // didStartProvisionalLoadForFrame + nullptr, // didReceiveServerRedirectForProvisionalLoadForFrame + nullptr, // didFailProvisionalLoadWithErrorForFrame + nullptr, // didCommitLoadForFrame + nullptr, // didFinishDocumentLoadForFrame + nullptr, // didFinishLoadForFrame + nullptr, // didFailLoadWithErrorForFrame + nullptr, // didSameDocumentNavigationForFrame + nullptr, // didReceiveTitleForFrame + nullptr, // didFirstLayoutForFrame + nullptr, // didFirstVisuallyNonEmptyLayoutForFrame + nullptr, // didRemoveFrameFromHierarchy + nullptr, // didDisplayInsecureContentForFrame + nullptr, // didRunInsecureContentForFrame + nullptr, // canAuthenticateAgainstProtectionSpaceInFrame + nullptr, // didReceiveAuthenticationChallengeInFrame + nullptr, // didStartProgress + nullptr, // didChangeProgress + nullptr, // didFinishProgress + nullptr, // didBecomeUnresponsive + nullptr, // didBecomeResponsive + processDidCrash, + nullptr, // didChangeBackForwardList + nullptr, // shouldGoToBackForwardListItem + nullptr, // didFailToInitializePlugin_deprecatedForUseWithV0 + nullptr, // didDetectXSSForFrame + nullptr, // didNewFirstVisuallyNonEmptyLayout_unavailable + nullptr, // willGoToBackForwardListItem + nullptr, // interactionOccurredWhileProcessUnresponsive + nullptr, // pluginDidFail_deprecatedForUseWithV1 + nullptr, // didReceiveIntentForFrame_unavailable + nullptr, // registerIntentServiceForFrame_unavailable + nullptr, // didLayout + nullptr, // pluginLoadPolicy_deprecatedForUseWithV2 + nullptr, // pluginDidFail + nullptr, // pluginLoadPolicy + nullptr, // webGLLoadPolicy + nullptr, // resolveWebGLLoadPolicy + nullptr, // shouldKeepCurrentBackForwardListItemInList + }; - String url = inspectorPageURL(); + WKPageContextMenuClientV3 contextMenuClient = { + { 3, this }, + 0, // getContextMenuFromProposedMenu_deprecatedForUseWithV0 + 0, // customContextMenuItemSelected + 0, // contextMenuDismissed + getContextMenuFromProposedMenu, + 0, // showContextMenu + 0, // hideContextMenu + }; - url.append("?dockSide="); + WKPageSetPagePolicyClient(toAPI(m_inspectorPage), &policyClient.base); + WKPageSetPageLoaderClient(toAPI(m_inspectorPage), &loaderClient.base); + WKPageSetPageContextMenuClient(toAPI(m_inspectorPage), &contextMenuClient.base); - if (m_isAttached) { - switch (m_attachmentSide) { - case AttachmentSideBottom: - url.append("bottom"); - m_page->process().send(Messages::WebInspector::AttachedBottom(), m_page->pageID()); - break; - case AttachmentSideRight: - url.append("right"); - m_page->process().send(Messages::WebInspector::AttachedRight(), m_page->pageID()); - break; - } - } else - url.append("undocked"); + m_inspectorPage->process().addMessageReceiver(Messages::WebInspectorProxy::messageReceiverName(), m_inspectedPage->pageID(), *this); + m_inspectorPage->process().assumeReadAccessToBaseURL(WebInspectorProxy::inspectorBaseURL()); +} + +// Called by WebInspectorProxy messages +void WebInspectorProxy::createInspectorPage(IPC::Attachment connectionIdentifier, bool canAttach, bool underTest) +{ + if (!m_inspectedPage) + return; + + m_underTest = underTest; + eagerlyCreateInspectorPage(); + + ASSERT(m_inspectorPage); + if (!m_inspectorPage) + return; + + m_connectionIdentifier = WTFMove(connectionIdentifier); + + m_inspectorPage->process().send(Messages::WebInspectorUI::EstablishConnection(m_connectionIdentifier, m_inspectedPage->pageID(), m_underTest, inspectionLevel()), m_inspectorPage->pageID()); - m_page->process().assumeReadAccessToBaseURL(inspectorBaseURL()); + if (!m_underTest) { + m_canAttach = platformCanAttach(canAttach); + m_isAttached = shouldOpenAttached(); + m_attachmentSide = static_cast<AttachmentSide>(inspectorPagePreferences().inspectorAttachmentSide()); - inspectorPage->loadRequest(URL(URL(), url)); + m_inspectedPage->process().send(Messages::WebInspector::SetAttached(m_isAttached), m_inspectedPage->pageID()); - m_createdInspectorPage = true; + if (m_isAttached) { + switch (m_attachmentSide) { + case AttachmentSide::Bottom: + m_inspectorPage->process().send(Messages::WebInspectorUI::AttachedBottom(), m_inspectorPage->pageID()); + break; + + case AttachmentSide::Right: + m_inspectorPage->process().send(Messages::WebInspectorUI::AttachedRight(), m_inspectorPage->pageID()); + break; + } + } else + m_inspectorPage->process().send(Messages::WebInspectorUI::Detached(), m_inspectorPage->pageID()); + + m_inspectorPage->process().send(Messages::WebInspectorUI::SetDockingUnavailable(!m_canAttach), m_inspectorPage->pageID()); + } + + m_inspectorPage->loadRequest(URL(URL(), m_underTest ? WebInspectorProxy::inspectorTestPageURL() : WebInspectorProxy::inspectorPageURL())); } void WebInspectorProxy::open() { + if (m_underTest) + return; + m_isVisible = true; platformOpen(); @@ -485,20 +562,27 @@ void WebInspectorProxy::open() void WebInspectorProxy::didClose() { - if (!m_createdInspectorPage) + if (!m_inspectorPage) return; + m_inspectorPage->process().removeMessageReceiver(Messages::WebInspectorProxy::messageReceiverName(), m_inspectedPage->pageID()); + m_isVisible = false; - m_isDebuggingJavaScript = false; - m_isProfilingJavaScript = false; m_isProfilingPage = false; - m_createdInspectorPage = false; m_showMessageSent = false; m_ignoreFirstBringToFront = false; if (m_isAttached) platformDetach(); + + // Null out m_inspectorPage after platformDetach(), so the views can be cleaned up correctly. + m_inspectorPage = nullptr; + m_isAttached = false; + m_canAttach = false; + m_underTest = false; + + m_connectionIdentifier = IPC::Attachment(); platformDidClose(); } @@ -521,7 +605,17 @@ void WebInspectorProxy::bringToFront() void WebInspectorProxy::attachAvailabilityChanged(bool available) { - platformAttachAvailabilityChanged(available); + bool previousCanAttach = m_canAttach; + + m_canAttach = platformCanAttach(available); + + if (previousCanAttach == m_canAttach) + return; + + if (m_inspectorPage && !m_underTest) + m_inspectorPage->process().send(Messages::WebInspectorUI::SetDockingUnavailable(!m_canAttach), m_inspectorPage->pageID()); + + platformAttachAvailabilityChanged(m_canAttach); } void WebInspectorProxy::inspectedURLChanged(const String& urlString) @@ -539,41 +633,135 @@ void WebInspectorProxy::append(const String& filename, const String& content) platformAppend(filename, content); } -bool WebInspectorProxy::canAttach() +bool WebInspectorProxy::shouldOpenAttached() { - // Keep this in sync with InspectorFrontendClientLocal::canAttachWindow. There are two implementations - // to make life easier in the multi-process world we have. WebInspectorProxy uses canAttach to decide if - // we can attach on open (on the UI process side). And InspectorFrontendClientLocal::canAttachWindow is - // used to decide if we can attach when the attach button is pressed (on the WebProcess side). + return inspectorPagePreferences().inspectorStartsAttached() && canAttach(); +} - // If we are already attached, allow attaching again to allow switching sides. - if (m_isAttached) - return true; +#if ENABLE(INSPECTOR_SERVER) +void WebInspectorProxy::sendMessageToRemoteFrontend(const String& message) +{ + ASSERT(m_remoteInspectionPageId); + WebInspectorServer::singleton().sendMessageOverConnection(m_remoteInspectionPageId, message); +} +#endif - // Don't allow attaching to another inspector -- two inspectors in one window is too much! - if (m_level > 1) - return false; +// Unsupported configurations can use the stubs provided here. - // Don't allow the attach if the window would be too small to accommodate the minimum inspector height. - unsigned inspectedPageHeight = platformInspectedWindowHeight(); - unsigned inspectedPageWidth = platformInspectedWindowWidth(); - unsigned maximumAttachedHeight = inspectedPageHeight * 3 / 4; - return minimumAttachedHeight <= maximumAttachedHeight && minimumAttachedWidth <= inspectedPageWidth; +#if PLATFORM(IOS) || (PLATFORM(MAC) && !WK_API_ENABLED) + +WebPageProxy* WebInspectorProxy::platformCreateInspectorPage() +{ + notImplemented(); + return nullptr; } -bool WebInspectorProxy::shouldOpenAttached() +void WebInspectorProxy::platformOpen() { - return inspectorPageGroup()->preferences()->inspectorStartsAttached() && canAttach(); + notImplemented(); } -#if ENABLE(INSPECTOR_SERVER) -void WebInspectorProxy::sendMessageToRemoteFrontend(const String& message) +void WebInspectorProxy::platformDidClose() { - ASSERT(m_remoteInspectionPageId); - WebInspectorServer::shared().sendMessageOverConnection(m_remoteInspectionPageId, message); + notImplemented(); } -#endif -} // namespace WebKit +void WebInspectorProxy::platformInvalidate() +{ + notImplemented(); +} + +void WebInspectorProxy::platformBringToFront() +{ + notImplemented(); +} + +void WebInspectorProxy::platformHide() +{ + notImplemented(); +} + +bool WebInspectorProxy::platformIsFront() +{ + notImplemented(); + return false; +} -#endif // ENABLE(INSPECTOR) +void WebInspectorProxy::platformInspectedURLChanged(const String&) +{ + notImplemented(); +} + +void WebInspectorProxy::platformSave(const String& suggestedURL, const String& content, bool base64Encoded, bool forceSaveDialog) +{ + notImplemented(); +} + +void WebInspectorProxy::platformAppend(const String& suggestedURL, const String& content) +{ + notImplemented(); +} + +unsigned WebInspectorProxy::platformInspectedWindowHeight() +{ + notImplemented(); + return 0; +} + +unsigned WebInspectorProxy::platformInspectedWindowWidth() +{ + notImplemented(); + return 0; +} + +void WebInspectorProxy::platformAttach() +{ + notImplemented(); +} + +void WebInspectorProxy::platformDetach() +{ + notImplemented(); +} + +void WebInspectorProxy::platformSetAttachedWindowHeight(unsigned) +{ + notImplemented(); +} + +void WebInspectorProxy::platformStartWindowDrag() +{ + notImplemented(); +} + +String WebInspectorProxy::inspectorPageURL() +{ + notImplemented(); + return String(); +} + +String WebInspectorProxy::inspectorTestPageURL() +{ + notImplemented(); + return String(); +} + +String WebInspectorProxy::inspectorBaseURL() +{ + notImplemented(); + return String(); +} + +void WebInspectorProxy::platformSetAttachedWindowWidth(unsigned) +{ + notImplemented(); +} + +void WebInspectorProxy::platformAttachAvailabilityChanged(bool) +{ + notImplemented(); +} + +#endif // PLATFORM(IOS) || (PLATFORM(MAC) && !WK_API_ENABLED) + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebInspectorProxy.h b/Source/WebKit2/UIProcess/WebInspectorProxy.h index 0457c471f..cffa26698 100644 --- a/Source/WebKit2/UIProcess/WebInspectorProxy.h +++ b/Source/WebKit2/UIProcess/WebInspectorProxy.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2010, 2014 Apple Inc. All rights reserved. * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,12 +27,10 @@ #ifndef WebInspectorProxy_h #define WebInspectorProxy_h -#if ENABLE(INSPECTOR) - #include "APIObject.h" +#include "Attachment.h" #include "MessageReceiver.h" #include <wtf/Forward.h> -#include <wtf/PassRefPtr.h> #include <wtf/RefPtr.h> #include <wtf/text/WTFString.h> @@ -40,12 +38,13 @@ #include "WKGeometry.h" #include <wtf/HashMap.h> #include <wtf/RetainPtr.h> +#include <wtf/RunLoop.h> -OBJC_CLASS NSButton; OBJC_CLASS NSURL; +OBJC_CLASS NSView; OBJC_CLASS NSWindow; OBJC_CLASS WKWebInspectorProxyObjCAdapter; -OBJC_CLASS WKWebInspectorWKView; +OBJC_CLASS WKWebInspectorWKWebView; #endif #if PLATFORM(GTK) @@ -60,20 +59,20 @@ OBJC_CLASS WKWebInspectorWKView; namespace WebKit { class WebFrameProxy; -class WebPageGroup; class WebPageProxy; -struct WebPageCreationParameters; +class WebPreferences; +class WebProcessPool; -enum AttachmentSide { - AttachmentSideBottom, - AttachmentSideRight +enum class AttachmentSide { + Bottom, + Right }; class WebInspectorProxy : public API::ObjectImpl<API::Object::Type::Inspector>, public IPC::MessageReceiver { public: - static PassRefPtr<WebInspectorProxy> create(WebPageProxy* page) + static Ref<WebInspectorProxy> create(WebPageProxy* inspectedPage) { - return adoptRef(new WebInspectorProxy(page)); + return adoptRef(*new WebInspectorProxy(inspectedPage)); } ~WebInspectorProxy(); @@ -81,9 +80,9 @@ public: void invalidate(); // Public APIs - WebPageProxy* page() const { return m_page; } + WebPageProxy* inspectedPage() const { return m_inspectedPage; } - bool isConnected() const { return m_createdInspectorPage; } + bool isConnected() const { return !!m_inspectorPage; } bool isVisible() const { return m_isVisible; } bool isFront(); @@ -92,16 +91,23 @@ public: void show(); void hide(); void close(); - -#if PLATFORM(MAC) + + void didRelaunchInspectorPageProcess(); + +#if PLATFORM(MAC) && WK_API_ENABLED void createInspectorWindow(); void updateInspectorWindowTitle() const; void inspectedViewFrameDidChange(CGFloat = 0); void windowFrameDidChange(); + void windowFullScreenDidChange(); NSWindow* inspectorWindow() const { return m_inspectorWindow.get(); } void setInspectorWindowFrame(WKRect&); WKRect inspectorWindowFrame(); + + void closeTimerFired(); + + void attachmentViewDidChange(NSView *oldView, NSView *newView); #endif #if PLATFORM(GTK) @@ -113,30 +119,28 @@ public: void showResources(); void showMainResourceForFrame(WebFrameProxy*); + AttachmentSide attachmentSide() const { return m_attachmentSide; } bool isAttached() const { return m_isAttached; } void attachRight(); void attachBottom(); - void attach(AttachmentSide = AttachmentSideBottom); + void attach(AttachmentSide = AttachmentSide::Bottom); void detach(); void setAttachedWindowHeight(unsigned); void setAttachedWindowWidth(unsigned); - void setToolbarHeight(unsigned height) { platformSetToolbarHeight(height); } - bool isDebuggingJavaScript() const { return m_isDebuggingJavaScript; } - void toggleJavaScriptDebugging(); - - bool isProfilingJavaScript() const { return m_isProfilingJavaScript; } - void toggleJavaScriptProfiling(); + void startWindowDrag(); bool isProfilingPage() const { return m_isProfilingPage; } void togglePageProfiling(); + static bool isInspectorProcessPool(WebProcessPool&); static bool isInspectorPage(WebPageProxy&); - // Implemented the platform WebInspectorProxy file - String inspectorPageURL() const; - String inspectorBaseURL() const; + // Provided by platform WebInspectorProxy implementations. + static String inspectorPageURL(); + static String inspectorTestPageURL(); + static String inspectorBaseURL(); #if ENABLE(INSPECTOR_SERVER) void enableRemoteInspection(); @@ -149,13 +153,17 @@ public: private: explicit WebInspectorProxy(WebPageProxy*); + static WebProcessPool& inspectorProcessPool(unsigned inspectionLevel); + + void eagerlyCreateInspectorPage(); + // IPC::MessageReceiver - virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; - virtual void didReceiveSyncMessage(IPC::Connection*, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override; + virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override; WebPageProxy* platformCreateInspectorPage(); void platformOpen(); void platformDidClose(); + void platformInvalidate(); void platformBringToFront(); void platformHide(); bool platformIsFront(); @@ -167,12 +175,18 @@ private: void platformDetach(); void platformSetAttachedWindowHeight(unsigned); void platformSetAttachedWindowWidth(unsigned); - void platformSetToolbarHeight(unsigned); + void platformStartWindowDrag(); void platformSave(const String& filename, const String& content, bool base64Encoded, bool forceSaveAs); void platformAppend(const String& filename, const String& content); +#if PLATFORM(MAC) && WK_API_ENABLED + bool platformCanAttach(bool webProcessCanAttach); +#else + bool platformCanAttach(bool webProcessCanAttach) { return webProcessCanAttach; } +#endif + // Called by WebInspectorProxy messages - void createInspectorPage(uint64_t& inspectorPageID, WebPageCreationParameters&); + void createInspectorPage(IPC::Attachment, bool canAttach, bool underTest); void didClose(); void bringToFront(); void attachAvailabilityChanged(bool); @@ -185,68 +199,71 @@ private: void sendMessageToRemoteFrontend(const String& message); #endif - bool canAttach(); + bool canAttach() const { return m_canAttach; } bool shouldOpenAttached(); + bool isUnderTest() const { return m_underTest; } + void open(); - WebPageGroup* inspectorPageGroup() const; + // The inspection level is used to give different preferences to each inspector + // by setting a per-level page group identifier. Local storage settings in the frontend + // also use the inspection level in the key prefix to disambiguate persistent view state. + unsigned inspectionLevel() const; + String inspectorPageGroupIdentifier() const; + WebPreferences& inspectorPagePreferences() const; #if PLATFORM(GTK) || PLATFORM(EFL) void createInspectorWindow(); #endif +#if PLATFORM(GTK) + void updateInspectorWindowTitle() const; +#endif + static const unsigned minimumWindowWidth; static const unsigned minimumWindowHeight; static const unsigned initialWindowWidth; static const unsigned initialWindowHeight; - // Keep this in sync with the value in InspectorFrontendClientLocal. - static const unsigned minimumAttachedWidth; - static const unsigned minimumAttachedHeight; + WebPageProxy* m_inspectedPage {nullptr}; + WebPageProxy* m_inspectorPage {nullptr}; - WebPageProxy* m_page; + bool m_underTest {false}; + bool m_isVisible {false}; + bool m_isAttached {false}; + bool m_canAttach {false}; + bool m_isProfilingPage {false}; + bool m_showMessageSent {false}; + bool m_ignoreFirstBringToFront {false}; - bool m_isVisible; - bool m_isAttached; - bool m_isDebuggingJavaScript; - bool m_isProfilingJavaScript; - bool m_isProfilingPage; - bool m_showMessageSent; - bool m_createdInspectorPage; - bool m_ignoreFirstBringToFront; + IPC::Attachment m_connectionIdentifier; - // The debugger stops all the pages in the same PageGroup. Having - // all the inspectors in the same group will make it impossible to debug - // the inspector code, so we use the level to make different page groups. - unsigned m_level; + AttachmentSide m_attachmentSide {AttachmentSide::Bottom}; - AttachmentSide m_attachmentSide; - -#if PLATFORM(MAC) - RetainPtr<WKWebInspectorWKView> m_inspectorView; +#if PLATFORM(MAC) && WK_API_ENABLED + RetainPtr<WKWebInspectorWKWebView> m_inspectorView; RetainPtr<NSWindow> m_inspectorWindow; - RetainPtr<NSButton> m_dockBottomButton; - RetainPtr<NSButton> m_dockRightButton; RetainPtr<WKWebInspectorProxyObjCAdapter> m_inspectorProxyObjCAdapter; - String m_urlString; HashMap<String, RetainPtr<NSURL>> m_suggestedToActualURLMap; + RunLoop::Timer<WebInspectorProxy> m_closeTimer; + String m_urlString; #elif PLATFORM(GTK) WebInspectorClientGtk m_client; - GtkWidget* m_inspectorView; - GtkWidget* m_inspectorWindow; + GtkWidget* m_inspectorView {nullptr}; + GtkWidget* m_inspectorWindow {nullptr}; + GtkWidget* m_headerBar {nullptr}; + String m_inspectedURLString; #elif PLATFORM(EFL) - Evas_Object* m_inspectorView; - Ecore_Evas* m_inspectorWindow; + Evas_Object* m_inspectorView {nullptr}; + Ecore_Evas* m_inspectorWindow {nullptr}; #endif #if ENABLE(INSPECTOR_SERVER) - int m_remoteInspectionPageId; + int m_remoteInspectionPageId {0}; #endif }; } // namespace WebKit -#endif // ENABLE(INSPECTOR) - #endif // WebInspectorProxy_h diff --git a/Source/WebKit2/UIProcess/WebInspectorProxy.messages.in b/Source/WebKit2/UIProcess/WebInspectorProxy.messages.in index 2add42f30..7f13b67d2 100644 --- a/Source/WebKit2/UIProcess/WebInspectorProxy.messages.in +++ b/Source/WebKit2/UIProcess/WebInspectorProxy.messages.in @@ -1,4 +1,4 @@ -# Copyright (C) 2010 Apple Inc. All rights reserved. +# Copyright (C) 2010, 2014 Apple Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -20,12 +20,12 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#if ENABLE(INSPECTOR) - messages -> WebInspectorProxy { - CreateInspectorPage() -> (uint64_t inspectorPageID, WebKit::WebPageCreationParameters inspectorPageParameters) + CreateInspectorPage(IPC::Attachment connectionIdentifier, bool canAttach, bool underTest) + DidClose() BringToFront() + InspectedURLChanged(String urlString) Save(String filename, String content, bool base64Encoded, bool forceSaveAs) @@ -34,15 +34,15 @@ messages -> WebInspectorProxy { AttachBottom() AttachRight() Detach() + AttachAvailabilityChanged(bool available) SetAttachedWindowHeight(unsigned height) SetAttachedWindowWidth(unsigned width) - SetToolbarHeight(unsigned height) + + StartWindowDrag() #if ENABLE(INSPECTOR_SERVER) SendMessageToRemoteFrontend(String message) #endif } - -#endif diff --git a/Source/WebKit2/UIProcess/WebKeyValueStorageManager.cpp b/Source/WebKit2/UIProcess/WebKeyValueStorageManager.cpp deleted file mode 100644 index b478ad11b..000000000 --- a/Source/WebKit2/UIProcess/WebKeyValueStorageManager.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2011, 2013 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "WebKeyValueStorageManager.h" - -#include "APIArray.h" -#include "SecurityOriginData.h" -#include "WebContext.h" -#include "WebSecurityOrigin.h" - -using namespace WebCore; - -namespace WebKit { - -const char* WebKeyValueStorageManager::supplementName() -{ - return "WebKeyValueStorageManager"; -} - -PassRefPtr<WebKeyValueStorageManager> WebKeyValueStorageManager::create(WebContext* context) -{ - return adoptRef(new WebKeyValueStorageManager(context)); -} - -WebKeyValueStorageManager::WebKeyValueStorageManager(WebContext* context) - : WebContextSupplement(context) -{ -} - -WebKeyValueStorageManager::~WebKeyValueStorageManager() -{ -} - -// WebContextSupplement - -void WebKeyValueStorageManager::refWebContextSupplement() -{ - API::Object::ref(); -} - -void WebKeyValueStorageManager::derefWebContextSupplement() -{ - API::Object::deref(); -} - -static void didGetKeyValueStorageOrigins(const Vector<RefPtr<WebCore::SecurityOrigin>>& securityOrigins, void* context) -{ - RefPtr<ArrayCallback> callback = adoptRef(static_cast<ArrayCallback*>(context)); - - Vector<RefPtr<API::Object>> webSecurityOrigins; - webSecurityOrigins.reserveInitialCapacity(securityOrigins.size()); - - for (unsigned i = 0; i < securityOrigins.size(); ++i) - webSecurityOrigins.uncheckedAppend(WebSecurityOrigin::create(securityOrigins[i])); - - callback->performCallbackWithReturnValue(API::Array::create(std::move(webSecurityOrigins)).get()); -} - -void WebKeyValueStorageManager::getKeyValueStorageOrigins(PassRefPtr<ArrayCallback> prpCallback) -{ - context()->storageManager().getOrigins(RunLoop::main(), prpCallback.leakRef(), didGetKeyValueStorageOrigins); -} - -void WebKeyValueStorageManager::deleteEntriesForOrigin(WebSecurityOrigin* origin) -{ - context()->storageManager().deleteEntriesForOrigin(origin->securityOrigin()); -} - -void WebKeyValueStorageManager::deleteAllEntries() -{ - context()->storageManager().deleteAllEntries(); -} - -} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebMediaCacheManagerProxy.cpp b/Source/WebKit2/UIProcess/WebMediaCacheManagerProxy.cpp deleted file mode 100644 index 781a7f07a..000000000 --- a/Source/WebKit2/UIProcess/WebMediaCacheManagerProxy.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (C) 2011, 2013 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "WebMediaCacheManagerProxy.h" - -#include "APIArray.h" -#include "WebContext.h" -#include "WebMediaCacheManagerMessages.h" -#include "WebMediaCacheManagerProxyMessages.h" -#include "WebSecurityOrigin.h" - -namespace WebKit { - -const char* WebMediaCacheManagerProxy::supplementName() -{ - return "WebMediaCacheManagerProxy"; -} - -PassRefPtr<WebMediaCacheManagerProxy> WebMediaCacheManagerProxy::create(WebContext* context) -{ - return adoptRef(new WebMediaCacheManagerProxy(context)); -} - -WebMediaCacheManagerProxy::WebMediaCacheManagerProxy(WebContext* context) - : WebContextSupplement(context) -{ - WebContextSupplement::context()->addMessageReceiver(Messages::WebMediaCacheManagerProxy::messageReceiverName(), *this); -} - -WebMediaCacheManagerProxy::~WebMediaCacheManagerProxy() -{ -} - -// WebContextSupplement - -void WebMediaCacheManagerProxy::contextDestroyed() -{ - invalidateCallbackMap(m_arrayCallbacks); -} - -void WebMediaCacheManagerProxy::processDidClose(WebProcessProxy*) -{ - invalidateCallbackMap(m_arrayCallbacks); -} - -bool WebMediaCacheManagerProxy::shouldTerminate(WebProcessProxy*) const -{ - return m_arrayCallbacks.isEmpty(); -} - -void WebMediaCacheManagerProxy::refWebContextSupplement() -{ - API::Object::ref(); -} - -void WebMediaCacheManagerProxy::derefWebContextSupplement() -{ - API::Object::deref(); -} - -void WebMediaCacheManagerProxy::getHostnamesWithMediaCache(PassRefPtr<ArrayCallback> prpCallback) -{ - RefPtr<ArrayCallback> callback = prpCallback; - uint64_t callbackID = callback->callbackID(); - m_arrayCallbacks.set(callbackID, callback.release()); - - // FIXME (Multi-WebProcess): <rdar://problem/12239765> When we're sending this to multiple processes, we need to aggregate the callback data when it comes back. - context()->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebMediaCacheManager::GetHostnamesWithMediaCache(callbackID)); -} - -void WebMediaCacheManagerProxy::didGetHostnamesWithMediaCache(const Vector<String>& hostnames, uint64_t callbackID) -{ - RefPtr<ArrayCallback> callback = m_arrayCallbacks.take(callbackID); - if (!callback) { - // FIXME: Log error or assert. - return; - } - - callback->performCallbackWithReturnValue(API::Array::createStringArray(hostnames).get()); -} - -void WebMediaCacheManagerProxy::clearCacheForHostname(const String& hostname) -{ - context()->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebMediaCacheManager::ClearCacheForHostname(hostname)); -} - -void WebMediaCacheManagerProxy::clearCacheForAllHostnames() -{ - context()->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebMediaCacheManager::ClearCacheForAllHostnames()); -} - -} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebMediaCacheManagerProxy.messages.in b/Source/WebKit2/UIProcess/WebMediaCacheManagerProxy.messages.in deleted file mode 100644 index 13a72cf5c..000000000 --- a/Source/WebKit2/UIProcess/WebMediaCacheManagerProxy.messages.in +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright (C) 2011 Apple Inc. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR -# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -messages -> WebMediaCacheManagerProxy { - DidGetHostnamesWithMediaCache(Vector<String> hostnames, uint64_t callbackID); -} diff --git a/Source/WebKit2/UIProcess/WebMediaSessionFocusManager.cpp b/Source/WebKit2/UIProcess/WebMediaSessionFocusManager.cpp new file mode 100644 index 000000000..4bf626e78 --- /dev/null +++ b/Source/WebKit2/UIProcess/WebMediaSessionFocusManager.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebMediaSessionFocusManager.h" + +#if ENABLE(MEDIA_SESSION) + +#include "WebProcessPool.h" + +namespace WebKit { + +const char* WebMediaSessionFocusManager::supplementName() +{ + return "WebMediaSessionFocusManager"; +} + +PassRefPtr<WebMediaSessionFocusManager> WebMediaSessionFocusManager::create(WebProcessPool* processPool) +{ + return adoptRef(new WebMediaSessionFocusManager(processPool)); +} + +WebMediaSessionFocusManager::WebMediaSessionFocusManager(WebProcessPool* processPool) + : WebContextSupplement(processPool) { } + +// WebContextSupplement + +void WebMediaSessionFocusManager::refWebContextSupplement() +{ + API::Object::ref(); +} + +void WebMediaSessionFocusManager::derefWebContextSupplement() +{ + API::Object::deref(); +} + +void WebMediaSessionFocusManager::initializeClient(const WKMediaSessionFocusManagerClientBase* client) +{ + m_client.initialize(client); +} + +bool WebMediaSessionFocusManager::valueForPlaybackAttribute(WKMediaSessionFocusManagerPlaybackAttribute attribute) const +{ + if (!m_focusedMediaElement) + return false; + + return m_playbackAttributes & attribute; +} + +void WebMediaSessionFocusManager::updatePlaybackAttribute(WKMediaSessionFocusManagerPlaybackAttribute attribute, bool value) +{ + if (value) + m_playbackAttributes |= attribute; + else + m_playbackAttributes &= ~attribute; + + m_client.didChangePlaybackAttribute(this, attribute, value); +} + +void WebMediaSessionFocusManager::setVolumeOfFocusedMediaElement(double volume) +{ + if (!m_focusedMediaElement) + return; + + if (WebPageProxy* proxy = m_focusedMediaElement->first) + proxy->setVolumeOfMediaElement(volume, m_focusedMediaElement->second); +} + +void WebMediaSessionFocusManager::updatePlaybackAttributesFromMediaState(WebPageProxy* proxy, uint64_t elementID, WebCore::MediaProducer::MediaStateFlags flags) +{ + if (m_focusedMediaElement) { + if (proxy == m_focusedMediaElement->first && elementID == m_focusedMediaElement->second) { + updatePlaybackAttribute(IsPlaying, flags & WebCore::MediaProducer::IsSourceElementPlaying); + updatePlaybackAttribute(IsNextTrackControlEnabled, flags & WebCore::MediaProducer::IsNextTrackControlEnabled); + updatePlaybackAttribute(IsPreviousTrackControlEnabled, flags & WebCore::MediaProducer::IsPreviousTrackControlEnabled); + } + } +} + +void WebMediaSessionFocusManager::setFocusedMediaElement(WebPageProxy& proxy, uint64_t elementID) +{ + m_focusedMediaElement = std::make_unique<FocusedMediaElement>(&proxy, elementID); +} + +void WebMediaSessionFocusManager::clearFocusedMediaElement() +{ + m_focusedMediaElement = nullptr; +} + +} // namespace WebKit + +#endif // ENABLE(MEDIA_SESSION) diff --git a/Source/WebKit2/UIProcess/WebMediaCacheManagerProxy.h b/Source/WebKit2/UIProcess/WebMediaSessionFocusManager.h index 44f583bae..d3bfd4519 100644 --- a/Source/WebKit2/UIProcess/WebMediaCacheManagerProxy.h +++ b/Source/WebKit2/UIProcess/WebMediaSessionFocusManager.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011, 2013 Apple Inc. All rights reserved. + * Copyright (C) 2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -23,56 +23,54 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef WebMediaCacheManagerProxy_h -#define WebMediaCacheManagerProxy_h +#ifndef WebMediaSessionFocusManager_h +#define WebMediaSessionFocusManager_h + +#if ENABLE(MEDIA_SESSION) #include "APIObject.h" -#include "GenericCallback.h" -#include "MessageReceiver.h" #include "WebContextSupplement.h" -#include <wtf/PassRefPtr.h> -#include <wtf/RefPtr.h> -#include <wtf/Vector.h> +#include "WebMediaSessionFocusManagerClient.h" +#include "WebPageProxy.h" namespace WebKit { -class WebContext; -class WebProcessProxy; - -typedef GenericCallback<WKArrayRef> ArrayCallback; +typedef std::pair<WebPageProxy*, uint64_t> FocusedMediaElement; -class WebMediaCacheManagerProxy : public API::ObjectImpl<API::Object::Type::MediaCacheManager>, public WebContextSupplement, private IPC::MessageReceiver { +class WebMediaSessionFocusManager : public API::ObjectImpl<API::Object::Type::MediaSessionFocusManager>, public WebContextSupplement { public: static const char* supplementName(); - static PassRefPtr<WebMediaCacheManagerProxy> create(WebContext*); - virtual ~WebMediaCacheManagerProxy(); - - void getHostnamesWithMediaCache(PassRefPtr<ArrayCallback>); - void clearCacheForHostname(const String&); - void clearCacheForAllHostnames(); + static PassRefPtr<WebMediaSessionFocusManager> create(WebProcessPool*); + + void initializeClient(const WKMediaSessionFocusManagerClientBase*); + + bool valueForPlaybackAttribute(WKMediaSessionFocusManagerPlaybackAttribute) const; + void updatePlaybackAttributesFromMediaState(WebPageProxy*, uint64_t, WebCore::MediaProducer::MediaStateFlags); + void setVolumeOfFocusedMediaElement(double); + + void setFocusedMediaElement(WebPageProxy&, uint64_t); + void clearFocusedMediaElement(); using API::Object::ref; using API::Object::deref; private: - explicit WebMediaCacheManagerProxy(WebContext*); - - void didGetHostnamesWithMediaCache(const Vector<String>&, uint64_t callbackID); + explicit WebMediaSessionFocusManager(WebProcessPool*); // WebContextSupplement - virtual void contextDestroyed() override; - virtual void processDidClose(WebProcessProxy*) override; - virtual bool shouldTerminate(WebProcessProxy*) const override; virtual void refWebContextSupplement() override; virtual void derefWebContextSupplement() override; - // IPC::MessageReceiver - virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; + void updatePlaybackAttribute(WKMediaSessionFocusManagerPlaybackAttribute, bool); - HashMap<uint64_t, RefPtr<ArrayCallback>> m_arrayCallbacks; + std::unique_ptr<FocusedMediaElement> m_focusedMediaElement; + WKMediaSessionFocusManagerPlaybackAttributes m_playbackAttributes { 0 }; + WebMediaSessionFocusManagerClient m_client; }; } // namespace WebKit -#endif // WebMediaCacheManagerProxy_h +#endif // ENABLE(MEDIA_SESSION) + +#endif /* WebMediaSessionFocusManager_h */ diff --git a/Source/WebKit2/UIProcess/WebMediaSessionFocusManagerClient.cpp b/Source/WebKit2/UIProcess/WebMediaSessionFocusManagerClient.cpp new file mode 100644 index 000000000..54a6f3782 --- /dev/null +++ b/Source/WebKit2/UIProcess/WebMediaSessionFocusManagerClient.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebMediaSessionFocusManagerClient.h" + +#if ENABLE(MEDIA_SESSION) + +#include "WKAPICast.h" +#include "WebMediaSessionFocusManager.h" + +namespace WebKit { + +void WebMediaSessionFocusManagerClient::didChangePlaybackAttribute(WebMediaSessionFocusManager* manager, WKMediaSessionFocusManagerPlaybackAttribute playbackAttribute, bool value) +{ + if (!m_client.didChangePlaybackAttribute) + return; + + m_client.didChangePlaybackAttribute(toAPI(manager), playbackAttribute, value, m_client.base.clientInfo); +} + +} // namespace WebKit + +#endif // ENABLE(MEDIA_SESSION) diff --git a/Source/WebKit2/UIProcess/WebNetworkInfoProvider.h b/Source/WebKit2/UIProcess/WebMediaSessionFocusManagerClient.h index 785aa80ea..ef69a6690 100644 --- a/Source/WebKit2/UIProcess/WebNetworkInfoProvider.h +++ b/Source/WebKit2/UIProcess/WebMediaSessionFocusManagerClient.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Intel Corporation. All rights reserved. + * Copyright (C) 2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -23,36 +23,32 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef WebNetworkInfoProvider_h -#define WebNetworkInfoProvider_h +#ifndef WebMediaSessionFocusManagerClient_h +#define WebMediaSessionFocusManagerClient_h -#if ENABLE(NETWORK_INFO) +#if ENABLE(MEDIA_SESSION) #include "APIClient.h" -#include "WKNetworkInfoManager.h" +#include "WKMediaSessionFocusManager.h" #include <wtf/Forward.h> namespace API { -template<> struct ClientTraits<WKNetworkInfoProviderBase> { - typedef std::tuple<WKNetworkInfoProviderV0> Versions; +template<> struct ClientTraits<WKMediaSessionFocusManagerClientBase> { + typedef std::tuple<WKMediaSessionFocusManagerClientV0> Versions; }; } namespace WebKit { -class WebNetworkInfoManagerProxy; +class WebMediaSessionFocusManager; -class WebNetworkInfoProvider : public API::Client<WKNetworkInfoProviderBase> { +class WebMediaSessionFocusManagerClient : public API::Client<WKMediaSessionFocusManagerClientBase> { public: - void startUpdating(WebNetworkInfoManagerProxy*); - void stopUpdating(WebNetworkInfoManagerProxy*); - - double bandwidth(WebNetworkInfoManagerProxy*) const; - bool isMetered(WebNetworkInfoManagerProxy*) const; + void didChangePlaybackAttribute(WebMediaSessionFocusManager*, WKMediaSessionFocusManagerPlaybackAttribute, bool); }; } // namespace WebKit -#endif // ENABLE(NETWORK_INFO) +#endif // ENABLE(MEDIA_SESSION) -#endif // WebNetworkInfoProvider_h +#endif // WebMediaSessionFocusManagerClient_h diff --git a/Source/WebKit2/UIProcess/WebNavigationState.cpp b/Source/WebKit2/UIProcess/WebNavigationState.cpp new file mode 100644 index 000000000..43d57ccbb --- /dev/null +++ b/Source/WebKit2/UIProcess/WebNavigationState.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebNavigationState.h" + +#include "APINavigation.h" +#include "WebPageProxy.h" +#include <WebCore/ResourceRequest.h> + +namespace WebKit { + +WebNavigationState::WebNavigationState() +{ +} + +WebNavigationState::~WebNavigationState() +{ +} + +Ref<API::Navigation> WebNavigationState::createLoadRequestNavigation(const WebCore::ResourceRequest& request) +{ + auto navigation = API::Navigation::create(*this, request); + + m_navigations.set(navigation->navigationID(), navigation.ptr()); + + return navigation; +} + +Ref<API::Navigation> WebNavigationState::createBackForwardNavigation() +{ + auto navigation = API::Navigation::create(*this); + + m_navigations.set(navigation->navigationID(), navigation.ptr()); + + return navigation; +} + +Ref<API::Navigation> WebNavigationState::createReloadNavigation() +{ + auto navigation = API::Navigation::create(*this); + + m_navigations.set(navigation->navigationID(), navigation.ptr()); + + return navigation; +} + +Ref<API::Navigation> WebNavigationState::createLoadDataNavigation() +{ + auto navigation = API::Navigation::create(*this); + + m_navigations.set(navigation->navigationID(), navigation.ptr()); + + return navigation; +} + +API::Navigation& WebNavigationState::navigation(uint64_t navigationID) +{ + ASSERT(navigationID); + + return *m_navigations.get(navigationID); +} + +Ref<API::Navigation> WebNavigationState::takeNavigation(uint64_t navigationID) +{ + ASSERT(navigationID); + + return m_navigations.take(navigationID).releaseNonNull(); +} + +void WebNavigationState::didDestroyNavigation(uint64_t navigationID) +{ + ASSERT(navigationID); + + m_navigations.remove(navigationID); +} + +void WebNavigationState::clearAllNavigations() +{ + m_navigations.clear(); +} + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebFindClient.h b/Source/WebKit2/UIProcess/WebNavigationState.h index d05bd47e8..13b0c9727 100644 --- a/Source/WebKit2/UIProcess/WebFindClient.h +++ b/Source/WebKit2/UIProcess/WebNavigationState.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -23,43 +23,50 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef WebFindClient_h -#define WebFindClient_h +#ifndef WebNavigationState_h +#define WebNavigationState_h -#include "APIClient.h" -#include "WKPage.h" -#include <wtf/Forward.h> +#include <wtf/HashMap.h> +#include <wtf/Ref.h> namespace API { -class Array; - -template<> struct ClientTraits<WKPageFindClientBase> { - typedef std::tuple<WKPageFindClientV0> Versions; -}; +class Navigation; +} -template<> struct ClientTraits<WKPageFindMatchesClientBase> { - typedef std::tuple<WKPageFindMatchesClientV0> Versions; -}; +namespace WebCore { +class ResourceRequest; } namespace WebKit { class WebPageProxy; -class WebImage; +class WebBackForwardListItem; -class WebFindClient : public API::Client<WKPageFindClientBase> { +class WebNavigationState { public: - void didFindString(WebPageProxy*, const String&, uint32_t matchCount); - void didFailToFindString(WebPageProxy*, const String&); - void didCountStringMatches(WebPageProxy*, const String&, uint32_t matchCount); -}; + explicit WebNavigationState(); + ~WebNavigationState(); -class WebFindMatchesClient : public API::Client<WKPageFindMatchesClientBase> { -public: - void didFindStringMatches(WebPageProxy*, const String&, API::Array*, int); - void didGetImageForMatchResult(WebPageProxy*, WebImage*, uint32_t); + Ref<API::Navigation> createBackForwardNavigation(); + Ref<API::Navigation> createLoadRequestNavigation(const WebCore::ResourceRequest&); + Ref<API::Navigation> createReloadNavigation(); + Ref<API::Navigation> createLoadDataNavigation(); + + API::Navigation& navigation(uint64_t navigationID); + Ref<API::Navigation> takeNavigation(uint64_t navigationID); + void didDestroyNavigation(uint64_t navigationID); + void clearAllNavigations(); + + uint64_t generateNavigationID() + { + return ++m_navigationID; + } + +private: + HashMap<uint64_t, RefPtr<API::Navigation>> m_navigations; + uint64_t m_navigationID { 0 }; }; } // namespace WebKit -#endif // WebFindClient_h +#endif // WebNavigationState_h diff --git a/Source/WebKit2/UIProcess/WebNetworkInfoManagerProxy.cpp b/Source/WebKit2/UIProcess/WebNetworkInfoManagerProxy.cpp deleted file mode 100644 index b9b960b64..000000000 --- a/Source/WebKit2/UIProcess/WebNetworkInfoManagerProxy.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) 2012 Intel Corporation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "WebNetworkInfoManagerProxy.h" - -#if ENABLE(NETWORK_INFO) - -#include "WebContext.h" -#include "WebNetworkInfo.h" -#include "WebNetworkInfoManagerMessages.h" -#include "WebNetworkInfoManagerProxyMessages.h" - -namespace WebKit { - -const char* WebNetworkInfoManagerProxy::supplementName() -{ - return "WebNetworkInfoManagerProxy"; -} - -PassRefPtr<WebNetworkInfoManagerProxy> WebNetworkInfoManagerProxy::create(WebContext* context) -{ - return adoptRef(new WebNetworkInfoManagerProxy(context)); -} - -WebNetworkInfoManagerProxy::WebNetworkInfoManagerProxy(WebContext* context) - : WebContextSupplement(context) - , m_isUpdating(false) -{ - WebContextSupplement::context()->addMessageReceiver(Messages::WebNetworkInfoManagerProxy::messageReceiverName(), *this); -} - -WebNetworkInfoManagerProxy::~WebNetworkInfoManagerProxy() -{ -} - -void WebNetworkInfoManagerProxy::initializeProvider(const WKNetworkInfoProviderBase* provider) -{ - m_provider.initialize(provider); -} - -void WebNetworkInfoManagerProxy::providerDidChangeNetworkInformation(const AtomicString& eventType, WebNetworkInfo* networkInformation) -{ - if (!context()) - return; - - context()->sendToAllProcesses(Messages::WebNetworkInfoManager::DidChangeNetworkInformation(eventType, networkInformation->data())); -} - -// WebContextSupplement - -void WebNetworkInfoManagerProxy::contextDestroyed() -{ - stopUpdating(); -} - -void WebNetworkInfoManagerProxy::processDidClose(WebProcessProxy*) -{ - stopUpdating(); -} - -void WebNetworkInfoManagerProxy::refWebContextSupplement() -{ - API::Object::ref(); -} - -void WebNetworkInfoManagerProxy::derefWebContextSupplement() -{ - API::Object::deref(); -} - -void WebNetworkInfoManagerProxy::startUpdating() -{ - if (m_isUpdating) - return; - - m_provider.startUpdating(this); - m_isUpdating = true; -} - -void WebNetworkInfoManagerProxy::stopUpdating() -{ - if (!m_isUpdating) - return; - - m_provider.stopUpdating(this); - m_isUpdating = false; -} - -void WebNetworkInfoManagerProxy::getBandwidth(double& bandwidth) -{ - bandwidth = m_provider.bandwidth(this); -} - -void WebNetworkInfoManagerProxy::isMetered(bool& isMetered) -{ - isMetered = m_provider.isMetered(this); -} - -} // namespace WebKit - -#endif // ENABLE(NETWORK_INFO) diff --git a/Source/WebKit2/UIProcess/WebNetworkInfoManagerProxy.h b/Source/WebKit2/UIProcess/WebNetworkInfoManagerProxy.h deleted file mode 100644 index d8ed157f5..000000000 --- a/Source/WebKit2/UIProcess/WebNetworkInfoManagerProxy.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) 2012 Intel Corporation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef WebNetworkInfoManagerProxy_h -#define WebNetworkInfoManagerProxy_h - -#if ENABLE(NETWORK_INFO) - -#include "APIObject.h" -#include "MessageReceiver.h" -#include "WebContextSupplement.h" -#include "WebNetworkInfoProvider.h" -#include <wtf/Forward.h> - -namespace WebKit { - -class WebContext; -class WebNetworkInfo; - -class WebNetworkInfoManagerProxy : public API::ObjectImpl<API::Object::Type::NetworkInfoManager>, public WebContextSupplement, private IPC::MessageReceiver { -public: - static const char* supplementName(); - - static PassRefPtr<WebNetworkInfoManagerProxy> create(WebContext*); - virtual ~WebNetworkInfoManagerProxy(); - - void initializeProvider(const WKNetworkInfoProviderBase*); - - void providerDidChangeNetworkInformation(const WTF::AtomicString& eventType, WebNetworkInfo*); - - using API::Object::ref; - using API::Object::deref; - -private: - explicit WebNetworkInfoManagerProxy(WebContext*); - - // WebContextSupplement - virtual void contextDestroyed() override; - virtual void processDidClose(WebProcessProxy*) override; - virtual void refWebContextSupplement() override; - virtual void derefWebContextSupplement() override; - - // IPC::MessageReceiver - virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; - virtual void didReceiveSyncMessage(IPC::Connection*, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override; - - void startUpdating(); - void stopUpdating(); - - void getBandwidth(double&); - void isMetered(bool&); - - bool m_isUpdating; - - WebContext* m_context; - WebNetworkInfoProvider m_provider; -}; - -} // namespace WebKit - -#endif // ENABLE(NETWORK_INFO) - -#endif // WebNetworkInfoManagerProxy_h diff --git a/Source/WebKit2/UIProcess/WebOpenPanelResultListenerProxy.cpp b/Source/WebKit2/UIProcess/WebOpenPanelResultListenerProxy.cpp index f63f5f72d..a377e4af0 100644 --- a/Source/WebKit2/UIProcess/WebOpenPanelResultListenerProxy.cpp +++ b/Source/WebKit2/UIProcess/WebOpenPanelResultListenerProxy.cpp @@ -27,6 +27,7 @@ #include "WebOpenPanelResultListenerProxy.h" #include "APIArray.h" +#include "APIString.h" #include "WebPageProxy.h" #include <WebCore/URL.h> #include <wtf/Vector.h> @@ -44,25 +45,38 @@ WebOpenPanelResultListenerProxy::~WebOpenPanelResultListenerProxy() { } -void WebOpenPanelResultListenerProxy::chooseFiles(API::Array* fileURLsArray) +static Vector<String> filePathsFromFileURLs(const API::Array& fileURLs) { - if (!m_page) - return; - - size_t size = fileURLsArray->size(); - Vector<String> filePaths; + + size_t size = fileURLs.size(); filePaths.reserveInitialCapacity(size); for (size_t i = 0; i < size; ++i) { - API::URL* apiURL = fileURLsArray->at<API::URL>(i); - if (apiURL) { - URL url(URL(), apiURL->string()); - filePaths.uncheckedAppend(url.fileSystemPath()); - } + API::URL* apiURL = fileURLs.at<API::URL>(i); + if (apiURL) + filePaths.uncheckedAppend(URL(URL(), apiURL->string()).fileSystemPath()); } - m_page->didChooseFilesForOpenPanel(filePaths); + return filePaths; +} + +#if PLATFORM(IOS) +void WebOpenPanelResultListenerProxy::chooseFiles(API::Array* fileURLsArray, API::String* displayString, const API::Data* iconImageData) +{ + if (!m_page) + return; + + m_page->didChooseFilesForOpenPanelWithDisplayStringAndIcon(filePathsFromFileURLs(*fileURLsArray), displayString ? displayString->string() : String(), iconImageData); +} +#endif + +void WebOpenPanelResultListenerProxy::chooseFiles(API::Array* fileURLsArray) +{ + if (!m_page) + return; + + m_page->didChooseFilesForOpenPanel(filePathsFromFileURLs(*fileURLsArray)); } void WebOpenPanelResultListenerProxy::cancel() @@ -75,7 +89,7 @@ void WebOpenPanelResultListenerProxy::cancel() void WebOpenPanelResultListenerProxy::invalidate() { - m_page = 0; + m_page = nullptr; } } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebOpenPanelResultListenerProxy.h b/Source/WebKit2/UIProcess/WebOpenPanelResultListenerProxy.h index ad4bf8f43..ae6eaf788 100644 --- a/Source/WebKit2/UIProcess/WebOpenPanelResultListenerProxy.h +++ b/Source/WebKit2/UIProcess/WebOpenPanelResultListenerProxy.h @@ -32,6 +32,8 @@ namespace API { class Array; +class Data; +class String; } namespace WebKit { @@ -47,6 +49,9 @@ public: virtual ~WebOpenPanelResultListenerProxy(); +#if PLATFORM(IOS) + void chooseFiles(API::Array*, API::String* displayString, const API::Data* iconImageData); +#endif void chooseFiles(API::Array*); void cancel(); diff --git a/Source/WebKit2/UIProcess/WebOriginDataManagerProxy.cpp b/Source/WebKit2/UIProcess/WebOriginDataManagerProxy.cpp deleted file mode 100644 index 1595d1bae..000000000 --- a/Source/WebKit2/UIProcess/WebOriginDataManagerProxy.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (C) 2011, 2013 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "WebOriginDataManagerProxy.h" - -#include "SecurityOriginData.h" -#include "WebContext.h" -#include "WebOriginDataManagerMessages.h" -#include "WebOriginDataManagerProxyMessages.h" -#include "WebSecurityOrigin.h" - -namespace WebKit { - -const char* WebOriginDataManagerProxy::supplementName() -{ - return "WebOriginDataManagerProxy"; -} - -PassRefPtr<WebOriginDataManagerProxy> WebOriginDataManagerProxy::create(WebContext* context) -{ - return adoptRef(new WebOriginDataManagerProxy(context)); -} - -WebOriginDataManagerProxy::WebOriginDataManagerProxy(WebContext* context) - : WebContextSupplement(context) -{ - context->addMessageReceiver(Messages::WebOriginDataManagerProxy::messageReceiverName(), *this); -} - -WebOriginDataManagerProxy::~WebOriginDataManagerProxy() -{ -} - - -void WebOriginDataManagerProxy::contextDestroyed() -{ - invalidateCallbackMap(m_arrayCallbacks); -} - -void WebOriginDataManagerProxy::processDidClose(WebProcessProxy*) -{ - invalidateCallbackMap(m_arrayCallbacks); -} - -bool WebOriginDataManagerProxy::shouldTerminate(WebProcessProxy*) const -{ - return m_arrayCallbacks.isEmpty(); -} - -void WebOriginDataManagerProxy::refWebContextSupplement() -{ - API::Object::ref(); -} - -void WebOriginDataManagerProxy::derefWebContextSupplement() -{ - API::Object::deref(); -} - -void WebOriginDataManagerProxy::getOrigins(WKOriginDataTypes types, PassRefPtr<ArrayCallback> prpCallback) -{ - if (!context()) - return; - - RefPtr<ArrayCallback> callback = prpCallback; - - uint64_t callbackID = callback->callbackID(); - m_arrayCallbacks.set(callbackID, callback.release()); - - // FIXME (Multi-WebProcess): <rdar://problem/12239765> Make manipulating cache information work with per-tab WebProcess. - context()->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebOriginDataManager::GetOrigins(types, callbackID)); -} - -void WebOriginDataManagerProxy::didGetOrigins(const Vector<SecurityOriginData>& originDatas, uint64_t callbackID) -{ - RefPtr<ArrayCallback> callback = m_arrayCallbacks.take(callbackID); - performAPICallbackWithSecurityOriginDataVector(originDatas, callback.get()); -} - -void WebOriginDataManagerProxy::deleteEntriesForOrigin(WKOriginDataTypes types, WebSecurityOrigin* origin) -{ - if (!context()) - return; - - SecurityOriginData securityOriginData; - securityOriginData.protocol = origin->protocol(); - securityOriginData.host = origin->host(); - securityOriginData.port = origin->port(); - - // FIXME (Multi-WebProcess): <rdar://problem/12239765> Make manipulating cache information work with per-tab WebProcess. - context()->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebOriginDataManager::DeleteEntriesForOrigin(types, securityOriginData)); -} - -void WebOriginDataManagerProxy::deleteAllEntries(WKOriginDataTypes types) -{ - if (!context()) - return; - - // FIXME (Multi-WebProcess): <rdar://problem/12239765> Make manipulating cache information work with per-tab WebProcess. - context()->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebOriginDataManager::DeleteAllEntries(types)); -} - -void WebOriginDataManagerProxy::startObservingChanges(WKOriginDataTypes types) -{ - if (!context()) - return; - - context()->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebOriginDataManager::StartObservingChanges(types)); -} - -void WebOriginDataManagerProxy::stopObservingChanges(WKOriginDataTypes types) -{ - if (!context()) - return; - - context()->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebOriginDataManager::StartObservingChanges(types)); -} - -void WebOriginDataManagerProxy::setChangeClient(const WKOriginDataManagerChangeClientBase *client) -{ - m_client.initialize(client); -} - -void WebOriginDataManagerProxy::didChange() -{ - m_client.didChange(this); -} - -} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebOriginDataManagerProxy.h b/Source/WebKit2/UIProcess/WebOriginDataManagerProxy.h deleted file mode 100644 index c5709c8b5..000000000 --- a/Source/WebKit2/UIProcess/WebOriginDataManagerProxy.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2011, 2013 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef WebOriginDataManagerProxy_h -#define WebOriginDataManagerProxy_h - -#include "APIObject.h" -#include "GenericCallback.h" -#include "MessageReceiver.h" -#include "WKOriginDataManager.h" -#include "WebContextSupplement.h" -#include "WebOriginDataManagerProxyChangeClient.h" -#include <wtf/PassRefPtr.h> -#include <wtf/RefPtr.h> -#include <wtf/Vector.h> - -namespace IPC { -class Connection; -} - -namespace WebKit { - -class WebSecurityOrigin; -struct SecurityOriginData; - -typedef GenericCallback<WKArrayRef> ArrayCallback; - -class WebOriginDataManagerProxy : public API::ObjectImpl<API::Object::Type::OriginDataManager>, public WebContextSupplement, private IPC::MessageReceiver { -public: - static const char* supplementName(); - - static PassRefPtr<WebOriginDataManagerProxy> create(WebContext*); - virtual ~WebOriginDataManagerProxy(); - - void getOrigins(WKOriginDataTypes, PassRefPtr<ArrayCallback>); - void deleteEntriesForOrigin(WKOriginDataTypes, WebSecurityOrigin*); - void deleteAllEntries(WKOriginDataTypes); - - void startObservingChanges(WKOriginDataTypes); - void stopObservingChanges(WKOriginDataTypes); - void setChangeClient(const WKOriginDataManagerChangeClientBase*); - - using API::Object::ref; - using API::Object::deref; - -private: - explicit WebOriginDataManagerProxy(WebContext*); - - void didGetOrigins(const Vector<SecurityOriginData>&, uint64_t callbackID); - void didChange(); - - // WebContextSupplement - virtual void contextDestroyed() override; - virtual void processDidClose(WebProcessProxy*) override; - virtual bool shouldTerminate(WebProcessProxy*) const override; - virtual void refWebContextSupplement() override; - virtual void derefWebContextSupplement() override; - - // IPC::MessageReceiver - virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; - - HashMap<uint64_t, RefPtr<ArrayCallback>> m_arrayCallbacks; - - WebOriginDataManagerProxyChangeClient m_client; -}; - -} // namespace WebKit - -#endif // WebOriginDataManagerProxy_h diff --git a/Source/WebKit2/UIProcess/WebOriginDataManagerProxy.messages.in b/Source/WebKit2/UIProcess/WebOriginDataManagerProxy.messages.in deleted file mode 100644 index 76d76b4c8..000000000 --- a/Source/WebKit2/UIProcess/WebOriginDataManagerProxy.messages.in +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright (C) 2011 Apple Inc. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR -# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -messages -> WebOriginDataManagerProxy { - DidGetOrigins(Vector<WebKit::SecurityOriginData> originIdentifiers, uint64_t callbackID); - DidChange() -} diff --git a/Source/WebKit2/UIProcess/WebPageContextMenuClient.cpp b/Source/WebKit2/UIProcess/WebPageContextMenuClient.cpp deleted file mode 100644 index 2fc340f67..000000000 --- a/Source/WebKit2/UIProcess/WebPageContextMenuClient.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (C) 2010 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" - -#if ENABLE(CONTEXT_MENUS) - -#include "WebPageContextMenuClient.h" - -#include "APIArray.h" -#include "Logging.h" -#include "WebContextMenuItem.h" -#include "WKAPICast.h" -#include "WKSharedAPICast.h" - -namespace WebKit { - -bool WebPageContextMenuClient::getContextMenuFromProposedMenu(WebPageProxy* page, const Vector<WebContextMenuItemData>& proposedMenuVector, Vector<WebContextMenuItemData>& customMenu, const WebHitTestResult::Data& hitTestResultData, API::Object* userData) -{ - if (!m_client.getContextMenuFromProposedMenu && !m_client.getContextMenuFromProposedMenu_deprecatedForUseWithV0) - return false; - - if (m_client.base.version >= 2 && !m_client.getContextMenuFromProposedMenu) - return false; - - Vector<RefPtr<API::Object>> proposedMenuItems; - proposedMenuItems.reserveInitialCapacity(proposedMenuVector.size()); - - for (const auto& menuItem : proposedMenuVector) - proposedMenuItems.uncheckedAppend(WebContextMenuItem::create(menuItem)); - - WKArrayRef newMenu = nullptr; - if (m_client.base.version >= 2) { - RefPtr<WebHitTestResult> webHitTestResult = WebHitTestResult::create(hitTestResultData); - m_client.getContextMenuFromProposedMenu(toAPI(page), toAPI(API::Array::create(std::move(proposedMenuItems)).get()), &newMenu, toAPI(webHitTestResult.get()), toAPI(userData), m_client.base.clientInfo); - } else - m_client.getContextMenuFromProposedMenu_deprecatedForUseWithV0(toAPI(page), toAPI(API::Array::create(std::move(proposedMenuItems)).get()), &newMenu, toAPI(userData), m_client.base.clientInfo); - - RefPtr<API::Array> array = adoptRef(toImpl(newMenu)); - - customMenu.clear(); - - size_t newSize = array ? array->size() : 0; - for (size_t i = 0; i < newSize; ++i) { - WebContextMenuItem* item = array->at<WebContextMenuItem>(i); - if (!item) { - LOG(ContextMenu, "New menu entry at index %i is not a WebContextMenuItem", (int)i); - continue; - } - - customMenu.append(*item->data()); - } - - return true; -} - -void WebPageContextMenuClient::customContextMenuItemSelected(WebPageProxy* page, const WebContextMenuItemData& itemData) -{ - if (!m_client.customContextMenuItemSelected) - return; - - RefPtr<WebContextMenuItem> item = WebContextMenuItem::create(itemData); - m_client.customContextMenuItemSelected(toAPI(page), toAPI(item.get()), m_client.base.clientInfo); -} - -void WebPageContextMenuClient::contextMenuDismissed(WebPageProxy* page) -{ - if (!m_client.contextMenuDismissed) - return; - - m_client.contextMenuDismissed(toAPI(page), m_client.base.clientInfo); -} - -bool WebPageContextMenuClient::showContextMenu(WebPageProxy* page, const WebCore::IntPoint& menuLocation, const Vector<WebContextMenuItemData>& menuItemsVector) -{ - if (!m_client.showContextMenu) - return false; - - Vector<RefPtr<API::Object>> menuItems; - menuItems.reserveInitialCapacity(menuItemsVector.size()); - - for (const auto& menuItem : menuItemsVector) - menuItems.uncheckedAppend(WebContextMenuItem::create(menuItem)); - - m_client.showContextMenu(toAPI(page), toAPI(menuLocation), toAPI(API::Array::create(std::move(menuItems)).get()), m_client.base.clientInfo); - - return true; -} - -bool WebPageContextMenuClient::hideContextMenu(WebPageProxy* page) -{ - if (!m_client.hideContextMenu) - return false; - - m_client.hideContextMenu(toAPI(page), m_client.base.clientInfo); - - return true; -} - -} // namespace WebKit -#endif // ENABLE(CONTEXT_MENUS) diff --git a/Source/WebKit2/UIProcess/WebFindClient.cpp b/Source/WebKit2/UIProcess/WebPageDiagnosticLoggingClient.cpp index 42e21c798..d8e4263cd 100644 --- a/Source/WebKit2/UIProcess/WebFindClient.cpp +++ b/Source/WebKit2/UIProcess/WebPageDiagnosticLoggingClient.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -24,51 +24,41 @@ */ #include "config.h" -#include "WebFindClient.h" +#include "WebPageDiagnosticLoggingClient.h" + #include "WKAPICast.h" +#include "WebPageProxy.h" #include <wtf/text/WTFString.h> namespace WebKit { -void WebFindClient::didFindString(WebPageProxy* page, const String& string, uint32_t matchCount) -{ - if (!m_client.didFindString) - return; - - m_client.didFindString(toAPI(page), toAPI(string.impl()), matchCount, m_client.base.clientInfo); - -} - -void WebFindClient::didFailToFindString(WebPageProxy* page, const String& string) +WebPageDiagnosticLoggingClient::WebPageDiagnosticLoggingClient(const WKPageDiagnosticLoggingClientBase* client) { - if (!m_client.didFailToFindString) - return; - - m_client.didFailToFindString(toAPI(page), toAPI(string.impl()), m_client.base.clientInfo); + initialize(client); } -void WebFindClient::didCountStringMatches(WebPageProxy* page, const String& string, uint32_t matchCount) +void WebPageDiagnosticLoggingClient::logDiagnosticMessage(WebPageProxy* page, const String& message, const String& description) { - if (!m_client.didCountStringMatches) + if (!m_client.logDiagnosticMessage) return; - m_client.didCountStringMatches(toAPI(page), toAPI(string.impl()), matchCount, m_client.base.clientInfo); + m_client.logDiagnosticMessage(toAPI(page), toAPI(message.impl()), toAPI(description.impl()), m_client.base.clientInfo); } -void WebFindMatchesClient::didFindStringMatches(WebPageProxy* page, const String& string, API::Array* matches, int firstIndex) +void WebPageDiagnosticLoggingClient::logDiagnosticMessageWithResult(WebPageProxy* page, const String& message, const String& description, WebCore::DiagnosticLoggingResultType result) { - if (!m_client.didFindStringMatches) + if (!m_client.logDiagnosticMessageWithResult) return; - m_client.didFindStringMatches(toAPI(page), toAPI(string.impl()), toAPI(matches), firstIndex, m_client.base.clientInfo); + m_client.logDiagnosticMessageWithResult(toAPI(page), toAPI(message.impl()), toAPI(description.impl()), toAPI(result), m_client.base.clientInfo); } -void WebFindMatchesClient::didGetImageForMatchResult(WebPageProxy* page, WebImage* image, uint32_t index) +void WebPageDiagnosticLoggingClient::logDiagnosticMessageWithValue(WebPageProxy* page, const String& message, const String& description, const String& value) { - if (!m_client.didGetImageForMatchResult) + if (!m_client.logDiagnosticMessageWithValue) return; - m_client.didGetImageForMatchResult(toAPI(page), toAPI(image), index, m_client.base.clientInfo); + + m_client.logDiagnosticMessageWithValue(toAPI(page), toAPI(message.impl()), toAPI(description.impl()), toAPI(value.impl()), m_client.base.clientInfo); } } // namespace WebKit - diff --git a/Source/WebKit2/UIProcess/WebPageContextMenuClient.h b/Source/WebKit2/UIProcess/WebPageDiagnosticLoggingClient.h index eb96712e5..41c834f4c 100644 --- a/Source/WebKit2/UIProcess/WebPageContextMenuClient.h +++ b/Source/WebKit2/UIProcess/WebPageDiagnosticLoggingClient.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -23,38 +23,36 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef WebPageContextMenuClient_h -#define WebPageContextMenuClient_h - -#if ENABLE(CONTEXT_MENUS) +#ifndef WebPageDiagnosticLoggingClient_h +#define WebPageDiagnosticLoggingClient_h #include "APIClient.h" -#include "WebHitTestResult.h" +#include "APIDiagnosticLoggingClient.h" #include "WKPage.h" -#include <WebCore/IntPoint.h> -#include <wtf/Vector.h> +#include <WebCore/DiagnosticLoggingResultType.h> +#include <wtf/Forward.h> namespace API { -template<> struct ClientTraits<WKPageContextMenuClientBase> { - typedef std::tuple<WKPageContextMenuClientV0, WKPageContextMenuClientV1, WKPageContextMenuClientV2, WKPageContextMenuClientV3> Versions; + +template<> struct ClientTraits<WKPageDiagnosticLoggingClientBase> { + typedef std::tuple<WKPageDiagnosticLoggingClientV0> Versions; }; -} + +} // namespace API namespace WebKit { -class WebContextMenuItemData; class WebPageProxy; -class WebPageContextMenuClient : public API::Client<WKPageContextMenuClientBase> { +class WebPageDiagnosticLoggingClient final : public API::Client<WKPageDiagnosticLoggingClientBase>, public API::DiagnosticLoggingClient { public: - bool getContextMenuFromProposedMenu(WebPageProxy*, const Vector<WebContextMenuItemData>& proposedMenu, Vector<WebContextMenuItemData>& customMenu, const WebHitTestResult::Data&, API::Object* userData); - void customContextMenuItemSelected(WebPageProxy*, const WebContextMenuItemData&); - void contextMenuDismissed(WebPageProxy*); - bool showContextMenu(WebPageProxy*, const WebCore::IntPoint&, const Vector<WebContextMenuItemData>&); - bool hideContextMenu(WebPageProxy*); + explicit WebPageDiagnosticLoggingClient(const WKPageDiagnosticLoggingClientBase*); + + virtual void logDiagnosticMessage(WebPageProxy*, const String& message, const String& description) override; + virtual void logDiagnosticMessageWithResult(WebPageProxy*, const String& message, const String& description, WebCore::DiagnosticLoggingResultType) override; + virtual void logDiagnosticMessageWithValue(WebPageProxy*, const String& message, const String& description, const String& value) override; }; } // namespace WebKit -#endif // ENABLE(CONTEXT_MENUS) -#endif // WebPageContextMenuClient_h +#endif // WebPageDiagnosticLoggingClient_h diff --git a/Source/WebKit2/UIProcess/WebPageGroup.cpp b/Source/WebKit2/UIProcess/WebPageGroup.cpp index 59cc1ff5d..c8db22493 100644 --- a/Source/WebKit2/UIProcess/WebPageGroup.cpp +++ b/Source/WebKit2/UIProcess/WebPageGroup.cpp @@ -27,6 +27,8 @@ #include "WebPageGroup.h" #include "APIArray.h" +#include "APIUserContentExtension.h" +#include "WebCompiledContentExtension.h" #include "WebPageGroupProxyMessages.h" #include "WebPageProxy.h" #include "WebPreferences.h" @@ -55,7 +57,7 @@ PassRefPtr<WebPageGroup> WebPageGroup::create(const String& identifier, bool vis return adoptRef(new WebPageGroup(identifier, visibleToInjectedBundle, visibleToHistoryClient)); } -PassRef<WebPageGroup> WebPageGroup::createNonNull(const String& identifier, bool visibleToInjectedBundle, bool visibleToHistoryClient) +Ref<WebPageGroup> WebPageGroup::createNonNull(const String& identifier, bool visibleToInjectedBundle, bool visibleToHistoryClient) { return adoptRef(*new WebPageGroup(identifier, visibleToInjectedBundle, visibleToHistoryClient)); } @@ -65,25 +67,34 @@ WebPageGroup* WebPageGroup::get(uint64_t pageGroupID) return webPageGroupMap().get(pageGroupID); } -WebPageGroup::WebPageGroup(const String& identifier, bool visibleToInjectedBundle, bool visibleToHistoryClient) +static WebPageGroupData pageGroupData(const String& identifier, bool visibleToInjectedBundle, bool visibleToHistoryClient) { - m_data.pageGroupID = generatePageGroupID(); + WebPageGroupData data; + + data.pageGroupID = generatePageGroupID(); if (!identifier.isEmpty()) - m_data.identifer = identifier; + data.identifier = identifier; else - m_data.identifer = m_data.identifer = makeString("__uniquePageGroupID-", String::number(m_data.pageGroupID)); + data.identifier = makeString("__uniquePageGroupID-", String::number(data.pageGroupID)); + + data.visibleToInjectedBundle = visibleToInjectedBundle; + data.visibleToHistoryClient = visibleToHistoryClient; + + return data; +} - m_data.visibleToInjectedBundle = visibleToInjectedBundle; - m_data.visibleToHistoryClient = visibleToHistoryClient; - +// FIXME: Why does the WebPreferences object here use ".WebKit2" instead of "WebKit2." which all the other constructors use. +// If it turns out that it's wrong, we can change it to to "WebKit2." and get rid of the globalDebugKeyPrefix from WebPreferences. +WebPageGroup::WebPageGroup(const String& identifier, bool visibleToInjectedBundle, bool visibleToHistoryClient) + : m_data(pageGroupData(identifier, visibleToInjectedBundle, visibleToHistoryClient)) + , m_preferences(WebPreferences::createWithLegacyDefaults(m_data.identifier, ".WebKit2", "WebKit2.")) +{ webPageGroupMap().set(m_data.pageGroupID, this); } WebPageGroup::~WebPageGroup() { - if (m_preferences) - m_preferences->removePageGroup(this); webPageGroupMap().remove(pageGroupID()); } @@ -102,28 +113,15 @@ void WebPageGroup::setPreferences(WebPreferences* preferences) if (preferences == m_preferences) return; - if (!m_preferences) { - m_preferences = preferences; - m_preferences->addPageGroup(this); - } else { - m_preferences->removePageGroup(this); - m_preferences = preferences; - m_preferences->addPageGroup(this); + m_preferences = preferences; - preferencesDidChange(); - } + for (auto& webPageProxy : m_pages) + webPageProxy->setPreferences(*m_preferences); } -WebPreferences* WebPageGroup::preferences() const +WebPreferences& WebPageGroup::preferences() const { - if (!m_preferences) { - if (!m_data.identifer.isNull()) - m_preferences = WebPreferences::create(m_data.identifer); - else - m_preferences = WebPreferences::create(); - m_preferences->addPageGroup(const_cast<WebPageGroup*>(this)); - } - return m_preferences.get(); + return *m_preferences; } void WebPageGroup::preferencesDidChange() @@ -175,4 +173,24 @@ void WebPageGroup::removeAllUserContent() sendToAllProcessesInGroup(Messages::WebPageGroupProxy::RemoveAllUserContent(), m_data.pageGroupID); } +#if ENABLE(CONTENT_EXTENSIONS) +void WebPageGroup::addUserContentExtension(const API::UserContentExtension& userContentExtension) +{ + m_data.userContentExtensions.set(userContentExtension.name(), userContentExtension.compiledExtension().data()); + sendToAllProcessesInGroup(Messages::WebPageGroupProxy::AddUserContentExtension(userContentExtension.name(), userContentExtension.compiledExtension().data()), m_data.pageGroupID); +} + +void WebPageGroup::removeUserContentExtension(const String& contentExtensionName) +{ + m_data.userContentExtensions.remove(contentExtensionName); + sendToAllProcessesInGroup(Messages::WebPageGroupProxy::RemoveUserContentExtension(contentExtensionName), m_data.pageGroupID); +} + +void WebPageGroup::removeAllUserContentExtensions() +{ + m_data.userContentExtensions.clear(); + sendToAllProcessesInGroup(Messages::WebPageGroupProxy::RemoveAllUserContentExtensions(), m_data.pageGroupID); +} +#endif + } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebPageGroup.h b/Source/WebKit2/UIProcess/WebPageGroup.h index 46027c5af..472993859 100644 --- a/Source/WebKit2/UIProcess/WebPageGroup.h +++ b/Source/WebKit2/UIProcess/WebPageGroup.h @@ -32,6 +32,7 @@ #include "WebProcessProxy.h" #include <wtf/Forward.h> #include <wtf/HashSet.h> +#include <wtf/text/WTFString.h> namespace WebKit { @@ -42,7 +43,7 @@ class WebPageGroup : public API::ObjectImpl<API::Object::Type::PageGroup> { public: WebPageGroup(const String& identifier = String(), bool visibleToInjectedBundle = true, bool visibleToHistoryClient = true); static PassRefPtr<WebPageGroup> create(const String& identifier = String(), bool visibleToInjectedBundle = true, bool visibleToHistoryClient = true); - static PassRef<WebPageGroup> createNonNull(const String& identifier = String(), bool visibleToInjectedBundle = true, bool visibleToHistoryClient = true); + static Ref<WebPageGroup> createNonNull(const String& identifier = String(), bool visibleToInjectedBundle = true, bool visibleToHistoryClient = true); static WebPageGroup* get(uint64_t pageGroupID); virtual ~WebPageGroup(); @@ -50,13 +51,13 @@ public: void addPage(WebPageProxy*); void removePage(WebPageProxy*); - const String& identifier() const { return m_data.identifer; } + const String& identifier() const { return m_data.identifier; } uint64_t pageGroupID() const { return m_data.pageGroupID; } - const WebPageGroupData& data() { return m_data; } + const WebPageGroupData& data() const { return m_data; } void setPreferences(WebPreferences*); - WebPreferences* preferences() const; + WebPreferences& preferences() const; void preferencesDidChange(); void addUserStyleSheet(const String& source, const String& baseURL, API::Array* whitelist, API::Array* blacklist, WebCore::UserContentInjectedFrames, WebCore::UserStyleLevel); @@ -65,11 +66,17 @@ public: void removeAllUserScripts(); void removeAllUserContent(); +#if ENABLE(CONTENT_EXTENSIONS) + void addUserContentExtension(const API::UserContentExtension&); + void removeUserContentExtension(const String&); + void removeAllUserContentExtensions(); +#endif + private: template<typename T> void sendToAllProcessesInGroup(const T&, uint64_t destinationID); WebPageGroupData m_data; - mutable RefPtr<WebPreferences> m_preferences; + RefPtr<WebPreferences> m_preferences; HashSet<WebPageProxy*> m_pages; }; diff --git a/Source/WebKit2/UIProcess/WebPageInjectedBundleClient.cpp b/Source/WebKit2/UIProcess/WebPageInjectedBundleClient.cpp new file mode 100644 index 000000000..a89357533 --- /dev/null +++ b/Source/WebKit2/UIProcess/WebPageInjectedBundleClient.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebPageInjectedBundleClient.h" + +#include "WKAPICast.h" +#include "WebProcessPool.h" +#include <wtf/text/WTFString.h> + +using namespace WebCore; + +namespace WebKit { + +void WebPageInjectedBundleClient::didReceiveMessageFromInjectedBundle(WebPageProxy* page, const String& messageName, API::Object* messageBody) +{ + if (!m_client.didReceiveMessageFromInjectedBundle) + return; + + m_client.didReceiveMessageFromInjectedBundle(toAPI(page), toAPI(messageName.impl()), toAPI(messageBody), m_client.base.clientInfo); +} + +void WebPageInjectedBundleClient::didReceiveSynchronousMessageFromInjectedBundle(WebPageProxy* page, const String& messageName, API::Object* messageBody, RefPtr<API::Object>& returnData) +{ + if (!m_client.didReceiveSynchronousMessageFromInjectedBundle) + return; + + WKTypeRef returnDataRef = 0; + m_client.didReceiveSynchronousMessageFromInjectedBundle(toAPI(page), toAPI(messageName.impl()), toAPI(messageBody), &returnDataRef, m_client.base.clientInfo); + returnData = adoptRef(toImpl(returnDataRef)); +} + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebDatabaseManagerProxyClient.h b/Source/WebKit2/UIProcess/WebPageInjectedBundleClient.h index 0e5091a29..30c7f354c 100644 --- a/Source/WebKit2/UIProcess/WebDatabaseManagerProxyClient.h +++ b/Source/WebKit2/UIProcess/WebPageInjectedBundleClient.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -23,30 +23,31 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef WebDatabaseManagerProxyClient_h -#define WebDatabaseManagerProxyClient_h +#ifndef WebPageInjectedBundleClient_h +#define WebPageInjectedBundleClient_h #include "APIClient.h" -#include "WKDatabaseManager.h" +#include "WKPage.h" #include <wtf/Forward.h> namespace API { -template<> struct ClientTraits<WKDatabaseManagerClientBase> { - typedef std::tuple<WKDatabaseManagerClientV0> Versions; +class Object; + +template<> struct ClientTraits<WKPageInjectedBundleClientBase> { + typedef std::tuple<WKPageInjectedBundleClientV0> Versions; }; } namespace WebKit { -class WebDatabaseManagerProxy; -class WebSecurityOrigin; +class WebPageProxy; -class WebDatabaseManagerProxyClient : public API::Client<WKDatabaseManagerClientBase> { +class WebPageInjectedBundleClient : public API::Client<WKPageInjectedBundleClientBase> { public: - void didModifyOrigin(WebDatabaseManagerProxy*, WebSecurityOrigin*); - void didModifyDatabase(WebDatabaseManagerProxy*, WebSecurityOrigin*, const String& databaseIdentifier); + void didReceiveMessageFromInjectedBundle(WebPageProxy*, const String&, API::Object*); + void didReceiveSynchronousMessageFromInjectedBundle(WebPageProxy*, const String&, API::Object*, RefPtr<API::Object>& returnData); }; } // namespace WebKit -#endif // WebDatabaseManagerProxyClient_h +#endif // WebPageInjectedBundleClient_h diff --git a/Source/WebKit2/UIProcess/WebPageProxy.cpp b/Source/WebKit2/UIProcess/WebPageProxy.cpp index bb8578dc7..e643c9042 100644 --- a/Source/WebKit2/UIProcess/WebPageProxy.cpp +++ b/Source/WebKit2/UIProcess/WebPageProxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2011 Apple Inc. All rights reserved. + * Copyright (C) 2010, 2011, 2015-2016 Apple Inc. All rights reserved. * Copyright (C) 2012 Intel Corporation. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,8 +28,24 @@ #include "WebPageProxy.h" #include "APIArray.h" +#include "APIContextMenuClient.h" +#include "APIFindClient.h" +#include "APIFindMatchesClient.h" +#include "APIFormClient.h" +#include "APIFrameInfo.h" +#include "APIGeometry.h" +#include "APIHistoryClient.h" +#include "APIHitTestResult.h" +#include "APILegacyContextHistoryClient.h" #include "APILoaderClient.h" +#include "APINavigation.h" +#include "APINavigationAction.h" +#include "APINavigationClient.h" +#include "APINavigationResponse.h" +#include "APIPageConfiguration.h" #include "APIPolicyClient.h" +#include "APISecurityOrigin.h" +#include "APIUIClient.h" #include "APIURLRequest.h" #include "AuthenticationChallengeProxy.h" #include "AuthenticationDecisionListener.h" @@ -38,29 +54,28 @@ #include "DrawingAreaProxy.h" #include "DrawingAreaProxyMessages.h" #include "EventDispatcherMessages.h" -#include "FindIndicator.h" #include "Logging.h" +#include "NativeWebGestureEvent.h" #include "NativeWebKeyboardEvent.h" #include "NativeWebMouseEvent.h" #include "NativeWebWheelEvent.h" #include "NavigationActionData.h" +#include "NetworkProcessMessages.h" #include "NotificationPermissionRequest.h" #include "NotificationPermissionRequestManager.h" #include "PageClient.h" #include "PluginInformation.h" #include "PluginProcessManager.h" #include "PrintInfo.h" -#include "SessionState.h" #include "TextChecker.h" #include "TextCheckerState.h" +#include "UserMediaPermissionRequestProxy.h" #include "WKContextPrivate.h" #include "WebBackForwardList.h" #include "WebBackForwardListItem.h" #include "WebCertificateInfo.h" -#include "WebColorPickerResultListenerProxy.h" -#include "WebContext.h" +#include "WebContextMenuItem.h" #include "WebContextMenuProxy.h" -#include "WebContextUserMessageCoders.h" #include "WebCoreArgumentCoders.h" #include "WebEditCommandProxy.h" #include "WebEvent.h" @@ -69,9 +84,12 @@ #include "WebFramePolicyListenerProxy.h" #include "WebFullScreenManagerProxy.h" #include "WebFullScreenManagerProxyMessages.h" +#include "WebImage.h" #include "WebInspectorProxy.h" #include "WebInspectorProxyMessages.h" +#include "WebNavigationState.h" #include "WebNotificationManagerProxy.h" +#include "WebOpenPanelParameters.h" #include "WebOpenPanelResultListenerProxy.h" #include "WebPageCreationParameters.h" #include "WebPageGroup.h" @@ -82,37 +100,37 @@ #include "WebPopupMenuProxy.h" #include "WebPreferences.h" #include "WebProcessMessages.h" +#include "WebProcessPool.h" #include "WebProcessProxy.h" #include "WebProtectionSpace.h" -#include "WebSecurityOrigin.h" +#include "WebUserContentControllerProxy.h" +#include "WebsiteDataStore.h" +#include <WebCore/BitmapImage.h> +#include <WebCore/DiagnosticLoggingClient.h> #include <WebCore/DragController.h> #include <WebCore/DragData.h> -#include <WebCore/DragSession.h> #include <WebCore/FloatRect.h> #include <WebCore/FocusDirection.h> +#include <WebCore/JSDOMBinding.h> #include <WebCore/MIMETypeRegistry.h> #include <WebCore/RenderEmbeddedObject.h> +#include <WebCore/SerializedCryptoKeyWrap.h> #include <WebCore/TextCheckerClient.h> +#include <WebCore/TextIndicator.h> +#include <WebCore/URL.h> #include <WebCore/WindowFeatures.h> -#include <wtf/NeverDestroyed.h> #include <stdio.h> +#include <wtf/NeverDestroyed.h> +#include <wtf/text/StringView.h> #if ENABLE(ASYNC_SCROLLING) #include "RemoteScrollingCoordinatorProxy.h" #endif -#if USE(COORDINATED_GRAPHICS) +#if USE(COORDINATED_GRAPHICS_MULTIPROCESS) #include "CoordinatedLayerTreeHostProxyMessages.h" #endif -#if PLATFORM(GTK) -#include "ArgumentCodersGtk.h" -#endif - -#if USE(SOUP) && !ENABLE(CUSTOM_PROTOCOLS) -#include "WebSoupRequestManagerProxy.h" -#endif - #if ENABLE(VIBRATION) #include "WebVibrationProxy.h" #endif @@ -121,18 +139,36 @@ #include <wtf/RefCountedLeakCounter.h> #endif -#if ENABLE(NETWORK_PROCESS) -#include "NetworkProcessMessages.h" -#endif - -#if PLATFORM(MAC) +#if PLATFORM(COCOA) +#include "RemoteLayerTreeDrawingAreaProxy.h" +#include "RemoteLayerTreeScrollingPerformanceData.h" #include "ViewSnapshotStore.h" +#include "WebVideoFullscreenManagerProxy.h" +#include "WebVideoFullscreenManagerProxyMessages.h" +#include <WebCore/MachSendRight.h> +#include <WebCore/RunLoopObserver.h> +#include <WebCore/TextIndicatorWindow.h> #endif #if USE(CAIRO) #include <WebCore/CairoUtilities.h> #endif +#if ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS) +#include <WebCore/MediaPlaybackTarget.h> +#include <WebCore/WebMediaSessionManager.h> +#endif + +#if ENABLE(MEDIA_SESSION) +#include "WebMediaSessionFocusManager.h" +#include "WebMediaSessionMetadata.h" +#include <WebCore/MediaSessionMetadata.h> +#endif + +#if USE(APPLE_INTERNAL_SDK) +#include <WebKitAdditions/WebPageProxyIncludes.h> +#endif + // This controls what strategy we use for mouse wheel coalescing. #define MERGE_WHEEL_EVENTS 1 @@ -164,37 +200,37 @@ public: RefPtr<Messages::WebPageProxy::ExceededDatabaseQuota::DelayedReply> reply; }; - static ExceededDatabaseQuotaRecords& shared(); + static ExceededDatabaseQuotaRecords& singleton(); - PassOwnPtr<Record> createRecord(uint64_t frameID, String originIdentifier, + std::unique_ptr<Record> createRecord(uint64_t frameID, String originIdentifier, String databaseName, String displayName, uint64_t currentQuota, uint64_t currentOriginUsage, uint64_t currentDatabaseUsage, uint64_t expectedUsage, PassRefPtr<Messages::WebPageProxy::ExceededDatabaseQuota::DelayedReply>); - void add(PassOwnPtr<Record>); - bool areBeingProcessed() const { return m_currentRecord; } + void add(std::unique_ptr<Record>); + bool areBeingProcessed() const { return !!m_currentRecord; } Record* next(); private: ExceededDatabaseQuotaRecords() { } ~ExceededDatabaseQuotaRecords() { } - Deque<OwnPtr<Record>> m_records; - OwnPtr<Record> m_currentRecord; + Deque<std::unique_ptr<Record>> m_records; + std::unique_ptr<Record> m_currentRecord; }; -ExceededDatabaseQuotaRecords& ExceededDatabaseQuotaRecords::shared() +ExceededDatabaseQuotaRecords& ExceededDatabaseQuotaRecords::singleton() { static NeverDestroyed<ExceededDatabaseQuotaRecords> records; return records; } -PassOwnPtr<ExceededDatabaseQuotaRecords::Record> ExceededDatabaseQuotaRecords::createRecord( +std::unique_ptr<ExceededDatabaseQuotaRecords::Record> ExceededDatabaseQuotaRecords::createRecord( uint64_t frameID, String originIdentifier, String databaseName, String displayName, uint64_t currentQuota, uint64_t currentOriginUsage, uint64_t currentDatabaseUsage, uint64_t expectedUsage, PassRefPtr<Messages::WebPageProxy::ExceededDatabaseQuota::DelayedReply> reply) { - OwnPtr<Record> record = adoptPtr(new Record); + auto record = std::make_unique<Record>(); record->frameID = frameID; record->originIdentifier = originIdentifier; record->databaseName = databaseName; @@ -204,17 +240,17 @@ PassOwnPtr<ExceededDatabaseQuotaRecords::Record> ExceededDatabaseQuotaRecords::c record->currentDatabaseUsage = currentDatabaseUsage; record->expectedUsage = expectedUsage; record->reply = reply; - return record.release(); + return record; } -void ExceededDatabaseQuotaRecords::add(PassOwnPtr<ExceededDatabaseQuotaRecords::Record> record) +void ExceededDatabaseQuotaRecords::add(std::unique_ptr<ExceededDatabaseQuotaRecords::Record> record) { - m_records.append(record); + m_records.append(WTFMove(record)); } ExceededDatabaseQuotaRecords::Record* ExceededDatabaseQuotaRecords::next() { - m_currentRecord.clear(); + m_currentRecord = nullptr; if (!m_records.isEmpty()) m_currentRecord = m_records.takeFirst(); return m_currentRecord.get(); @@ -243,40 +279,90 @@ static const char* webKeyboardEventTypeString(WebEvent::Type type) } #endif // !LOG_DISABLED -PassRefPtr<WebPageProxy> WebPageProxy::create(PageClient& pageClient, WebProcessProxy& process, uint64_t pageID, const WebPageConfiguration& configuration) +class PageClientProtector { + WTF_MAKE_NONCOPYABLE(PageClientProtector); +public: + PageClientProtector(PageClient& pageClient) + : m_pageClient(pageClient) + { + m_pageClient.refView(); + } + + ~PageClientProtector() + { + m_pageClient.derefView(); + } + +private: + PageClient& m_pageClient; +}; + +Ref<WebPageProxy> WebPageProxy::create(PageClient& pageClient, WebProcessProxy& process, uint64_t pageID, Ref<API::PageConfiguration>&& configuration) { - return adoptRef(new WebPageProxy(pageClient, process, pageID, configuration)); + return adoptRef(*new WebPageProxy(pageClient, process, pageID, WTFMove(configuration))); } -WebPageProxy::WebPageProxy(PageClient& pageClient, WebProcessProxy& process, uint64_t pageID, const WebPageConfiguration& configuration) +WebPageProxy::WebPageProxy(PageClient& pageClient, WebProcessProxy& process, uint64_t pageID, Ref<API::PageConfiguration>&& configuration) : m_pageClient(pageClient) + , m_configuration(WTFMove(configuration)) , m_loaderClient(std::make_unique<API::LoaderClient>()) , m_policyClient(std::make_unique<API::PolicyClient>()) + , m_formClient(std::make_unique<API::FormClient>()) + , m_uiClient(std::make_unique<API::UIClient>()) + , m_findClient(std::make_unique<API::FindClient>()) + , m_findMatchesClient(std::make_unique<API::FindMatchesClient>()) + , m_diagnosticLoggingClient(std::make_unique<API::DiagnosticLoggingClient>()) +#if ENABLE(CONTEXT_MENUS) + , m_contextMenuClient(std::make_unique<API::ContextMenuClient>()) +#endif + , m_navigationState(std::make_unique<WebNavigationState>()) , m_process(process) - , m_pageGroup(*configuration.pageGroup) + , m_pageGroup(*m_configuration->pageGroup()) + , m_preferences(*m_configuration->preferences()) + , m_userContentController(m_configuration->userContentController()) + , m_visitedLinkStore(*m_configuration->visitedLinkStore()) + , m_websiteDataStore(m_configuration->websiteDataStore()->websiteDataStore()) , m_mainFrame(nullptr) , m_userAgent(standardUserAgent()) + , m_treatsSHA1CertificatesAsInsecure(m_configuration->treatsSHA1SignedCertificatesAsInsecure()) +#if PLATFORM(IOS) + , m_hasReceivedLayerTreeTransactionAfterDidCommitLoad(true) + , m_firstLayerTreeTransactionIdAfterDidCommitLoad(0) + , m_deviceOrientation(0) + , m_dynamicViewportSizeUpdateWaitingForTarget(false) + , m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit(false) + , m_dynamicViewportSizeUpdateLayerTreeTransactionID(0) + , m_layerTreeTransactionIdAtLastTouchStart(0) + , m_hasNetworkRequestsOnSuspended(false) +#endif , m_geolocationPermissionRequestManager(*this) , m_notificationPermissionRequestManager(*this) + , m_userMediaPermissionRequestManager(*this) , m_viewState(ViewState::NoFlags) + , m_viewWasEverInWindow(false) +#if PLATFORM(IOS) + , m_alwaysRunsAtForegroundPriority(m_configuration->alwaysRunsAtForegroundPriority()) +#endif , m_backForwardList(WebBackForwardList::create(*this)) - , m_loadStateAtProcessExit(FrameLoadState::State::Finished) - , m_temporarilyClosedComposition(false) + , m_maintainsInactiveSelection(false) + , m_isEditable(false) , m_textZoomFactor(1) , m_pageZoomFactor(1) , m_pageScaleFactor(1) + , m_pluginZoomFactor(1) + , m_pluginScaleFactor(1) , m_intrinsicDeviceScaleFactor(1) , m_customDeviceScaleFactor(0) - , m_layerHostingMode(LayerHostingModeDefault) + , m_topContentInset(0) + , m_layerHostingMode(LayerHostingMode::InProcess) , m_drawsBackground(true) - , m_drawsTransparentBackground(false) - , m_areMemoryCacheClientCallsEnabled(true) , m_useFixedLayout(false) , m_suppressScrollbarAnimations(false) , m_paginationMode(Pagination::Unpaginated) , m_paginationBehavesLikeColumns(false) , m_pageLength(0) , m_gapBetweenPages(0) + , m_paginationLineGridEnabled(false) , m_isValid(true) , m_isClosed(false) , m_canRunModal(false) @@ -293,46 +379,78 @@ WebPageProxy::WebPageProxy(PageClient& pageClient, WebProcessProxy& process, uin , m_syncNavigationActionPolicyDownloadID(0) , m_processingMouseMoveEvent(false) #if ENABLE(TOUCH_EVENTS) - , m_needTouchEvents(false) + , m_isTrackingTouchEvents(false) #endif , m_pageID(pageID) - , m_session(*configuration.session) + , m_sessionID(m_configuration->sessionID()) , m_isPageSuspended(false) -#if PLATFORM(MAC) + , m_addsVisitedLinks(true) +#if ENABLE(REMOTE_INSPECTOR) + , m_allowsRemoteInspection(true) +#endif +#if PLATFORM(COCOA) , m_isSmartInsertDeleteEnabled(TextChecker::isSmartInsertDeleteEnabled()) #endif +#if PLATFORM(GTK) + , m_backgroundColor(Color::white) +#endif , m_spellDocumentTag(0) , m_hasSpellDocumentTag(false) , m_pendingLearnOrIgnoreWordMessageCount(0) + , m_mainFrameHasCustomContentProvider(false) +#if ENABLE(DRAG_SUPPORT) + , m_currentDragOperation(DragOperationNone) + , m_currentDragIsOverFileInput(false) + , m_currentDragNumberOfFilesToBeAccepted(0) +#endif + , m_pageLoadState(*this) + , m_delegatesScrolling(false) , m_mainFrameHasHorizontalScrollbar(false) , m_mainFrameHasVerticalScrollbar(false) , m_canShortCircuitHorizontalWheelEvents(true) - , m_mainFrameIsPinnedToLeftSide(false) - , m_mainFrameIsPinnedToRightSide(false) - , m_mainFrameIsPinnedToTopSide(false) - , m_mainFrameIsPinnedToBottomSide(false) - , m_useLegacyImplicitRubberBandControl(false) + , m_mainFrameIsPinnedToLeftSide(true) + , m_mainFrameIsPinnedToRightSide(true) + , m_mainFrameIsPinnedToTopSide(true) + , m_mainFrameIsPinnedToBottomSide(true) + , m_shouldUseImplicitRubberBandControl(false) , m_rubberBandsAtLeft(true) , m_rubberBandsAtRight(true) , m_rubberBandsAtTop(true) , m_rubberBandsAtBottom(true) + , m_enableVerticalRubberBanding(true) + , m_enableHorizontalRubberBanding(true) , m_backgroundExtendsBeyondPage(false) - , m_mainFrameInViewSourceMode(false) , m_shouldRecordNavigationSnapshots(false) + , m_isShowingNavigationGestureSnapshot(false) , m_pageCount(0) , m_renderTreeSize(0) - , m_shouldSendEventsSynchronously(false) + , m_sessionRestorationRenderTreeSize(0) + , m_wantsSessionRestorationRenderTreeSizeThresholdEvent(false) + , m_hitRenderTreeSizeThreshold(false) , m_suppressVisibilityUpdates(false) , m_autoSizingShouldExpandToViewHeight(false) , m_mediaVolume(1) + , m_muted(false) , m_mayStartMediaWhenInWindow(true) , m_waitingForDidUpdateViewState(false) +#if PLATFORM(COCOA) + , m_scrollPerformanceDataCollectionEnabled(false) +#endif , m_scrollPinningBehavior(DoNotPin) + , m_navigationID(0) + , m_configurationPreferenceValues(m_configuration->preferenceValues()) + , m_potentiallyChangedViewStateFlags(ViewState::NoFlags) + , m_viewStateChangeWantsSynchronousReply(false) { - updateViewState(); + m_webProcessLifetimeTracker.addObserver(m_visitedLinkStore); + m_webProcessLifetimeTracker.addObserver(m_websiteDataStore); -#if HAVE(LAYER_HOSTING_IN_WINDOW_SERVER) - m_layerHostingMode = m_viewState & ViewState::IsInWindow ? m_pageClient.viewLayerHostingMode() : LayerHostingModeInWindowServer; + updateViewState(); + updateActivityToken(); + updateProccessSuppressionState(); + +#if HAVE(OUT_OF_PROCESS_LAYER_HOSTING) + m_layerHostingMode = m_viewState & ViewState::IsInWindow ? m_pageClient.viewLayerHostingMode() : LayerHostingMode::OutOfProcess; #endif platformInitialize(); @@ -341,37 +459,58 @@ WebPageProxy::WebPageProxy(PageClient& pageClient, WebProcessProxy& process, uin webPageProxyCounter.increment(); #endif - WebContext::statistics().wkPageCount++; + WebProcessPool::statistics().wkPageCount++; + m_preferences->addPage(*this); m_pageGroup->addPage(this); -#if ENABLE(INSPECTOR) m_inspector = WebInspectorProxy::create(this); -#endif #if ENABLE(FULLSCREEN_API) m_fullScreenManager = WebFullScreenManagerProxy::create(*this, m_pageClient.fullScreenManagerProxyClient()); #endif +#if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)) + m_videoFullscreenManager = WebVideoFullscreenManagerProxy::create(*this); +#endif #if ENABLE(VIBRATION) m_vibration = WebVibrationProxy::create(this); #endif +#if USE(APPLE_INTERNAL_SDK) +#include <WebKitAdditions/WebPageProxyInitialization.cpp> +#endif + m_process->addMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_pageID, *this); - // FIXME: If we ever expose the session storage size as a preference, we need to pass it here. - m_process->context().storageManager().createSessionStorageNamespace(m_pageID, m_process->isValid() ? m_process->connection() : 0, std::numeric_limits<unsigned>::max()); - setSession(*configuration.session); + if (m_sessionID.isEphemeral()) { + m_process->processPool().sendToNetworkingProcess(Messages::NetworkProcess::EnsurePrivateBrowsingSession(m_sessionID)); + m_process->processPool().sendToAllProcesses(Messages::WebProcess::EnsurePrivateBrowsingSession(m_sessionID)); + } + +#if PLATFORM(COCOA) + const CFIndex viewStateChangeRunLoopOrder = (CFIndex)RunLoopObserver::WellKnownRunLoopOrders::CoreAnimationCommit - 1; + m_viewStateChangeDispatcher = std::make_unique<RunLoopObserver>(viewStateChangeRunLoopOrder, [this] { + this->dispatchViewStateChange(); + }); +#endif } WebPageProxy::~WebPageProxy() { + ASSERT(m_process->webPage(m_pageID) != this); +#if !ASSERT_DISABLED + for (WebPageProxy* page : m_process->pages()) + ASSERT(page != this); +#endif + if (!m_isClosed) close(); - WebContext::statistics().wkPageCount--; + WebProcessPool::statistics().wkPageCount--; if (m_hasSpellDocumentTag) TextChecker::closeSpellDocumentWithTag(m_spellDocumentTag); + m_preferences->removePage(*this); m_pageGroup->removePage(this); #ifndef NDEBUG @@ -379,7 +518,12 @@ WebPageProxy::~WebPageProxy() #endif } -PlatformProcessIdentifier WebPageProxy::processIdentifier() const +const API::PageConfiguration& WebPageProxy::configuration() const +{ + return m_configuration.get(); +} + +pid_t WebPageProxy::processIdentifier() const { if (m_isClosed) return 0; @@ -396,20 +540,26 @@ bool WebPageProxy::isValid() const return m_isValid; } -PassRefPtr<API::Array> WebPageProxy::relatedPages() const +void WebPageProxy::setPreferences(WebPreferences& preferences) { - // pages() returns a list of pages in WebProcess, so this page may or may not be among them - a client can use a reference to WebPageProxy after the page has closed. - Vector<WebPageProxy*> pages = m_process->pages(); + if (&preferences == m_preferences.ptr()) + return; - Vector<RefPtr<API::Object>> result; - result.reserveInitialCapacity(pages.size()); + m_preferences->removePage(*this); + m_preferences = preferences; + m_preferences->addPage(*this); - for (const auto& page : pages) { - if (page != this) - result.uncheckedAppend(page); - } + preferencesDidChange(); +} + +void WebPageProxy::setHistoryClient(std::unique_ptr<API::HistoryClient> historyClient) +{ + m_historyClient = WTFMove(historyClient); +} - return API::Array::create(std::move(result)); +void WebPageProxy::setNavigationClient(std::unique_ptr<API::NavigationClient> navigationClient) +{ + m_navigationClient = WTFMove(navigationClient); } void WebPageProxy::setLoaderClient(std::unique_ptr<API::LoaderClient> loaderClient) @@ -419,7 +569,7 @@ void WebPageProxy::setLoaderClient(std::unique_ptr<API::LoaderClient> loaderClie return; } - m_loaderClient = std::move(loaderClient); + m_loaderClient = WTFMove(loaderClient); } void WebPageProxy::setPolicyClient(std::unique_ptr<API::PolicyClient> policyClient) @@ -429,65 +579,139 @@ void WebPageProxy::setPolicyClient(std::unique_ptr<API::PolicyClient> policyClie return; } - m_policyClient = std::move(policyClient); + m_policyClient = WTFMove(policyClient); } -void WebPageProxy::initializeFormClient(const WKPageFormClientBase* formClient) +void WebPageProxy::setFormClient(std::unique_ptr<API::FormClient> formClient) { - m_formClient.initialize(formClient); + if (!formClient) { + m_formClient = std::make_unique<API::FormClient>(); + return; + } + + m_formClient = WTFMove(formClient); } -void WebPageProxy::initializeUIClient(const WKPageUIClientBase* client) +void WebPageProxy::setUIClient(std::unique_ptr<API::UIClient> uiClient) { + if (!uiClient) { + m_uiClient = std::make_unique<API::UIClient>(); + return; + } + + m_uiClient = WTFMove(uiClient); + if (!isValid()) return; - m_uiClient.initialize(client); + m_process->send(Messages::WebPage::SetCanRunBeforeUnloadConfirmPanel(m_uiClient->canRunBeforeUnloadConfirmPanel()), m_pageID); + setCanRunModal(m_uiClient->canRunModal()); +} - m_process->send(Messages::WebPage::SetCanRunBeforeUnloadConfirmPanel(m_uiClient.canRunBeforeUnloadConfirmPanel()), m_pageID); - setCanRunModal(m_uiClient.canRunModal()); +void WebPageProxy::setFindClient(std::unique_ptr<API::FindClient> findClient) +{ + if (!findClient) { + m_findClient = std::make_unique<API::FindClient>(); + return; + } + + m_findClient = WTFMove(findClient); } -void WebPageProxy::initializeFindClient(const WKPageFindClientBase* client) +void WebPageProxy::setFindMatchesClient(std::unique_ptr<API::FindMatchesClient> findMatchesClient) { - m_findClient.initialize(client); + if (!findMatchesClient) { + m_findMatchesClient = std::make_unique<API::FindMatchesClient>(); + return; + } + + m_findMatchesClient = WTFMove(findMatchesClient); } -void WebPageProxy::initializeFindMatchesClient(const WKPageFindMatchesClientBase* client) +void WebPageProxy::setDiagnosticLoggingClient(std::unique_ptr<API::DiagnosticLoggingClient> diagnosticLoggingClient) { - m_findMatchesClient.initialize(client); + if (!diagnosticLoggingClient) { + m_diagnosticLoggingClient = std::make_unique<API::DiagnosticLoggingClient>(); + return; + } + + m_diagnosticLoggingClient = WTFMove(diagnosticLoggingClient); } #if ENABLE(CONTEXT_MENUS) -void WebPageProxy::initializeContextMenuClient(const WKPageContextMenuClientBase* client) +void WebPageProxy::setContextMenuClient(std::unique_ptr<API::ContextMenuClient> contextMenuClient) { - m_contextMenuClient.initialize(client); + if (!contextMenuClient) { + m_contextMenuClient = std::make_unique<API::ContextMenuClient>(); + return; + } + + m_contextMenuClient = WTFMove(contextMenuClient); } #endif +void WebPageProxy::setInjectedBundleClient(const WKPageInjectedBundleClientBase* client) +{ + if (!client) { + m_injectedBundleClient = nullptr; + return; + } + + m_injectedBundleClient = std::make_unique<WebPageInjectedBundleClient>(); + m_injectedBundleClient->initialize(client); +} + +void WebPageProxy::handleMessage(IPC::Connection& connection, const String& messageName, const WebKit::UserData& messageBody) +{ + auto* webProcessProxy = WebProcessProxy::fromConnection(&connection); + if (!webProcessProxy || !m_injectedBundleClient) + return; + m_injectedBundleClient->didReceiveMessageFromInjectedBundle(this, messageName, webProcessProxy->transformHandlesToObjects(messageBody.object()).get()); +} + +void WebPageProxy::handleSynchronousMessage(IPC::Connection& connection, const String& messageName, const UserData& messageBody, UserData& returnUserData) +{ + if (!WebProcessProxy::fromConnection(&connection) || !m_injectedBundleClient) + return; + + RefPtr<API::Object> returnData; + m_injectedBundleClient->didReceiveSynchronousMessageFromInjectedBundle(this, messageName, WebProcessProxy::fromConnection(&connection)->transformHandlesToObjects(messageBody.object()).get(), returnData); + returnUserData = UserData(WebProcessProxy::fromConnection(&connection)->transformObjectsToHandles(returnData.get())); +} + + void WebPageProxy::reattachToWebProcess() { + ASSERT(!m_isClosed); ASSERT(!isValid()); - ASSERT(!m_process->isValid()); - ASSERT(!m_process->isLaunching()); - - updateViewState(); + ASSERT(m_process->state() == WebProcessProxy::State::Terminated); m_isValid = true; + m_process->removeWebPage(m_pageID); + m_process->removeMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_pageID); - if (m_process->context().processModel() == ProcessModelSharedSecondaryProcess) - m_process = m_process->context().ensureSharedWebProcess(); - else - m_process = m_process->context().createNewWebProcessRespectingProcessCountLimit(); + m_process = m_process->processPool().createNewWebProcessRespectingProcessCountLimit(); + + ASSERT(m_process->state() != ChildProcessProxy::State::Terminated); + if (m_process->state() == ChildProcessProxy::State::Running) + processDidFinishLaunching(); m_process->addExistingWebPage(this, m_pageID); m_process->addMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_pageID, *this); -#if ENABLE(INSPECTOR) + updateViewState(); + updateActivityToken(); + m_inspector = WebInspectorProxy::create(this); -#endif #if ENABLE(FULLSCREEN_API) m_fullScreenManager = WebFullScreenManagerProxy::create(*this, m_pageClient.fullScreenManagerProxyClient()); #endif +#if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)) + m_videoFullscreenManager = WebVideoFullscreenManagerProxy::create(*this); +#endif + +#if USE(APPLE_INTERNAL_SDK) +#include <WebKitAdditions/WebPageProxyInitialization.cpp> +#endif initializeWebPage(); @@ -495,28 +719,58 @@ void WebPageProxy::reattachToWebProcess() m_drawingArea->waitForBackingStoreUpdateOnNextPaint(); } -void WebPageProxy::reattachToWebProcessWithItem(WebBackForwardListItem* item) +RefPtr<API::Navigation> WebPageProxy::reattachToWebProcessForReload() { - if (item && item != m_backForwardList->currentItem()) - m_backForwardList->goToItem(item); + if (m_isClosed) + return nullptr; + ASSERT(!isValid()); + reattachToWebProcess(); + + if (!m_backForwardList->currentItem()) + return nullptr; + + auto navigation = m_navigationState->createReloadNavigation(); + + // We allow stale content when reloading a WebProcess that's been killed or crashed. + m_process->send(Messages::WebPage::GoToBackForwardItem(navigation->navigationID(), m_backForwardList->currentItem()->itemID()), m_pageID); + m_process->responsivenessTimer().start(); + + return WTFMove(navigation); +} + +RefPtr<API::Navigation> WebPageProxy::reattachToWebProcessWithItem(WebBackForwardListItem* item) +{ + if (m_isClosed) + return nullptr; + + ASSERT(!isValid()); reattachToWebProcess(); if (!item) - return; + return nullptr; + + if (item != m_backForwardList->currentItem()) + m_backForwardList->goToItem(item); - m_process->send(Messages::WebPage::GoToBackForwardItem(item->itemID()), m_pageID); - m_process->responsivenessTimer()->start(); + auto navigation = m_navigationState->createBackForwardNavigation(); + + m_process->send(Messages::WebPage::GoToBackForwardItem(navigation->navigationID(), item->itemID()), m_pageID); + m_process->responsivenessTimer().start(); + + return WTFMove(navigation); } -void WebPageProxy::setSession(API::Session& session) +void WebPageProxy::setSessionID(SessionID sessionID) { - m_session = session; - m_process->send(Messages::WebPage::SetSessionID(session.getID()), m_pageID); + if (!isValid()) + return; -#if ENABLE(NETWORK_PROCESS) - m_process->context().sendToNetworkingProcess(Messages::NetworkProcess::EnsurePrivateBrowsingSession(session.getID())); -#endif + m_sessionID = sessionID; + m_process->send(Messages::WebPage::SetSessionID(sessionID), m_pageID); + + if (sessionID.isEphemeral()) + m_process->processPool().sendToNetworkingProcess(Messages::NetworkProcess::EnsurePrivateBrowsingSession(sessionID)); } void WebPageProxy::initializeWebPage() @@ -531,59 +785,85 @@ void WebPageProxy::initializeWebPage() ASSERT(m_drawingArea); #if ENABLE(ASYNC_SCROLLING) - if (m_drawingArea->type() == DrawingAreaTypeRemoteLayerTree) + if (m_drawingArea->type() == DrawingAreaTypeRemoteLayerTree) { m_scrollingCoordinatorProxy = std::make_unique<RemoteScrollingCoordinatorProxy>(*this); +#if PLATFORM(IOS) + // On iOS, main frame scrolls are sent in terms of visible rect updates. + m_scrollingCoordinatorProxy->setPropagatesMainFrameScrolls(false); +#endif + } #endif #if ENABLE(INSPECTOR_SERVER) - if (pageGroup().preferences()->developerExtrasEnabled()) + if (m_preferences->developerExtrasEnabled()) inspector()->enableRemoteInspection(); #endif process().send(Messages::WebProcess::CreateWebPage(m_pageID, creationParameters()), 0); -#if PLATFORM(MAC) +#if PLATFORM(COCOA) send(Messages::WebPage::SetSmartInsertDeleteEnabled(m_isSmartInsertDeleteEnabled)); #endif + + m_needsToFinishInitializingWebPageAfterProcessLaunch = true; + finishInitializingWebPageAfterProcessLaunch(); } -bool WebPageProxy::isProcessSuppressible() const +void WebPageProxy::finishInitializingWebPageAfterProcessLaunch() { - return (m_viewState & ViewState::IsVisuallyIdle) && m_pageGroup->preferences()->pageVisibilityBasedProcessSuppressionEnabled(); + if (!m_needsToFinishInitializingWebPageAfterProcessLaunch) + return; + if (m_process->state() != WebProcessProxy::State::Running) + return; + + m_needsToFinishInitializingWebPageAfterProcessLaunch = false; + + if (m_userContentController) + m_process->addWebUserContentControllerProxy(*m_userContentController); + m_process->addVisitedLinkStore(m_visitedLinkStore); } void WebPageProxy::close() { - if (!isValid()) + if (m_isClosed) return; m_isClosed = true; + if (m_activePopupMenu) + m_activePopupMenu->cancelTracking(); + +#if ENABLE(CONTEXT_MENUS) + m_activeContextMenu = nullptr; +#endif + m_backForwardList->pageClosed(); m_pageClient.pageClosed(); m_process->disconnectFramesFromPage(this); - resetState(); + resetState(ResetStateReason::PageInvalidated); - m_loaderClient = nullptr; - m_policyClient = nullptr; - m_formClient.initialize(0); - m_uiClient.initialize(0); + m_loaderClient = std::make_unique<API::LoaderClient>(); + m_policyClient = std::make_unique<API::PolicyClient>(); + m_formClient = std::make_unique<API::FormClient>(); + m_uiClient = std::make_unique<API::UIClient>(); #if PLATFORM(EFL) - m_uiPopupMenuClient.initialize(0); + m_uiPopupMenuClient.initialize(nullptr); #endif - m_findClient.initialize(0); - m_findMatchesClient.initialize(0); + m_findClient = std::make_unique<API::FindClient>(); + m_findMatchesClient = std::make_unique<API::FindMatchesClient>(); + m_diagnosticLoggingClient = std::make_unique<API::DiagnosticLoggingClient>(); #if ENABLE(CONTEXT_MENUS) - m_contextMenuClient.initialize(0); + m_contextMenuClient = std::make_unique<API::ContextMenuClient>(); #endif + m_webProcessLifetimeTracker.pageWasInvalidated(); + m_process->send(Messages::WebPage::Close(), m_pageID); m_process->removeWebPage(m_pageID); m_process->removeMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_pageID); - m_process->context().storageManager().destroySessionStorageNamespace(m_pageID); - m_process->context().supplement<WebNotificationManagerProxy>()->clearNotifications(this); + m_process->processPool().supplement<WebNotificationManagerProxy>()->clearNotifications(this); } bool WebPageProxy::tryClose() @@ -591,8 +871,13 @@ bool WebPageProxy::tryClose() if (!isValid()) return true; + // Close without delay if the process allows it. Our goal is to terminate + // the process, so we check a per-process status bit. + if (m_process->isSuddenTerminationEnabled()) + return true; + m_process->send(Messages::WebPage::TryClose(), m_pageID); - m_process->responsivenessTimer()->start(); + m_process->responsivenessTimer().start(); return false; } @@ -604,17 +889,20 @@ bool WebPageProxy::maybeInitializeSandboxExtensionHandle(const URL& url, Sandbox if (m_process->hasAssumedReadAccessToURL(url)) return false; -#if ENABLE(INSPECTOR) // Inspector resources are in a directory with assumed access. ASSERT_WITH_SECURITY_IMPLICATION(!WebInspectorProxy::isInspectorPage(*this)); -#endif SandboxExtension::createHandle("/", SandboxExtension::ReadOnly, sandboxExtensionHandle); return true; } -void WebPageProxy::loadRequest(const ResourceRequest& request, API::Object* userData) +RefPtr<API::Navigation> WebPageProxy::loadRequest(const ResourceRequest& request, ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy, API::Object* userData) { + if (m_isClosed) + return nullptr; + + auto navigation = m_navigationState->createLoadRequestNavigation(request); + auto transaction = m_pageLoadState.transaction(); m_pageLoadState.setPendingAPIRequestURL(transaction, request.url()); @@ -626,18 +914,23 @@ void WebPageProxy::loadRequest(const ResourceRequest& request, API::Object* user bool createdExtension = maybeInitializeSandboxExtensionHandle(request.url(), sandboxExtensionHandle); if (createdExtension) m_process->willAcquireUniversalFileReadSandboxExtension(); - m_process->send(Messages::WebPage::LoadRequest(request, sandboxExtensionHandle, WebContextUserMessageEncoder(userData, process())), m_pageID); - m_process->responsivenessTimer()->start(); + m_process->send(Messages::WebPage::LoadRequest(navigation->navigationID(), request, sandboxExtensionHandle, (uint64_t)shouldOpenExternalURLsPolicy, UserData(process().transformObjectsToHandles(userData).get())), m_pageID); + m_process->responsivenessTimer().start(); + + return WTFMove(navigation); } -void WebPageProxy::loadFile(const String& fileURLString, const String& resourceDirectoryURLString, API::Object* userData) +RefPtr<API::Navigation> WebPageProxy::loadFile(const String& fileURLString, const String& resourceDirectoryURLString, API::Object* userData) { + if (m_isClosed) + return nullptr; + if (!isValid()) reattachToWebProcess(); URL fileURL = URL(URL(), fileURLString); if (!fileURL.isLocalFile()) - return; + return nullptr; URL resourceDirectoryURL; if (resourceDirectoryURLString.isNull()) @@ -645,71 +938,140 @@ void WebPageProxy::loadFile(const String& fileURLString, const String& resourceD else { resourceDirectoryURL = URL(URL(), resourceDirectoryURLString); if (!resourceDirectoryURL.isLocalFile()) - return; + return nullptr; } + auto navigation = m_navigationState->createLoadRequestNavigation(ResourceRequest(fileURL)); + + auto transaction = m_pageLoadState.transaction(); + + m_pageLoadState.setPendingAPIRequestURL(transaction, fileURLString); + String resourceDirectoryPath = resourceDirectoryURL.fileSystemPath(); SandboxExtension::Handle sandboxExtensionHandle; SandboxExtension::createHandle(resourceDirectoryPath, SandboxExtension::ReadOnly, sandboxExtensionHandle); m_process->assumeReadAccessToBaseURL(resourceDirectoryURL); - m_process->send(Messages::WebPage::LoadRequest(fileURL, sandboxExtensionHandle, WebContextUserMessageEncoder(userData, process())), m_pageID); - m_process->responsivenessTimer()->start(); + m_process->send(Messages::WebPage::LoadRequest(navigation->navigationID(), fileURL, sandboxExtensionHandle, (uint64_t)ShouldOpenExternalURLsPolicy::ShouldNotAllow, UserData(process().transformObjectsToHandles(userData).get())), m_pageID); + m_process->responsivenessTimer().start(); + + return WTFMove(navigation); } -void WebPageProxy::loadData(API::Data* data, const String& MIMEType, const String& encoding, const String& baseURL, API::Object* userData) +RefPtr<API::Navigation> WebPageProxy::loadData(API::Data* data, const String& MIMEType, const String& encoding, const String& baseURL, API::Object* userData) { + if (m_isClosed) + return nullptr; + + auto navigation = m_navigationState->createLoadDataNavigation(); + + auto transaction = m_pageLoadState.transaction(); + + m_pageLoadState.setPendingAPIRequestURL(transaction, !baseURL.isEmpty() ? baseURL : blankURL().string()); + if (!isValid()) reattachToWebProcess(); m_process->assumeReadAccessToBaseURL(baseURL); - m_process->send(Messages::WebPage::LoadData(data->dataReference(), MIMEType, encoding, baseURL, WebContextUserMessageEncoder(userData, process())), m_pageID); - m_process->responsivenessTimer()->start(); + m_process->send(Messages::WebPage::LoadData(navigation->navigationID(), data->dataReference(), MIMEType, encoding, baseURL, UserData(process().transformObjectsToHandles(userData).get())), m_pageID); + m_process->responsivenessTimer().start(); + + return WTFMove(navigation); } -void WebPageProxy::loadHTMLString(const String& htmlString, const String& baseURL, API::Object* userData) +// FIXME: Get rid of loadHTMLString and just use loadData instead. +RefPtr<API::Navigation> WebPageProxy::loadHTMLString(const String& htmlString, const String& baseURL, API::Object* userData) { + if (m_isClosed) + return nullptr; + + auto navigation = m_navigationState->createLoadDataNavigation(); + + auto transaction = m_pageLoadState.transaction(); + + m_pageLoadState.setPendingAPIRequestURL(transaction, !baseURL.isEmpty() ? baseURL : blankURL().string()); + if (!isValid()) reattachToWebProcess(); m_process->assumeReadAccessToBaseURL(baseURL); - m_process->send(Messages::WebPage::LoadHTMLString(htmlString, baseURL, WebContextUserMessageEncoder(userData, process())), m_pageID); - m_process->responsivenessTimer()->start(); + m_process->send(Messages::WebPage::LoadHTMLString(navigation->navigationID(), htmlString, baseURL, UserData(process().transformObjectsToHandles(userData).get())), m_pageID); + m_process->responsivenessTimer().start(); + + return WTFMove(navigation); } void WebPageProxy::loadAlternateHTMLString(const String& htmlString, const String& baseURL, const String& unreachableURL, API::Object* userData) { + // When the UIProcess is in the process of handling a failing provisional load, do not attempt to + // start a second alternative HTML load as this will prevent the page load state from being + // handled properly. + if (m_isClosed || m_isLoadingAlternateHTMLStringForFailingProvisionalLoad) + return; + + if (!m_failingProvisionalLoadURL.isEmpty()) + m_isLoadingAlternateHTMLStringForFailingProvisionalLoad = true; + if (!isValid()) reattachToWebProcess(); auto transaction = m_pageLoadState.transaction(); + m_pageLoadState.setPendingAPIRequestURL(transaction, unreachableURL); m_pageLoadState.setUnreachableURL(transaction, unreachableURL); if (m_mainFrame) m_mainFrame->setUnreachableURL(unreachableURL); m_process->assumeReadAccessToBaseURL(baseURL); - m_process->send(Messages::WebPage::LoadAlternateHTMLString(htmlString, baseURL, unreachableURL, WebContextUserMessageEncoder(userData, process())), m_pageID); - m_process->responsivenessTimer()->start(); + m_process->assumeReadAccessToBaseURL(unreachableURL); + m_process->send(Messages::WebPage::LoadAlternateHTMLString(htmlString, baseURL, unreachableURL, m_failingProvisionalLoadURL, UserData(process().transformObjectsToHandles(userData).get())), m_pageID); + m_process->responsivenessTimer().start(); } void WebPageProxy::loadPlainTextString(const String& string, API::Object* userData) { + if (m_isClosed) + return; + if (!isValid()) reattachToWebProcess(); - m_process->send(Messages::WebPage::LoadPlainTextString(string, WebContextUserMessageEncoder(userData, process())), m_pageID); - m_process->responsivenessTimer()->start(); + auto transaction = m_pageLoadState.transaction(); + m_pageLoadState.setPendingAPIRequestURL(transaction, blankURL().string()); + + m_process->send(Messages::WebPage::LoadPlainTextString(string, UserData(process().transformObjectsToHandles(userData).get())), m_pageID); + m_process->responsivenessTimer().start(); } void WebPageProxy::loadWebArchiveData(API::Data* webArchiveData, API::Object* userData) { + if (m_isClosed) + return; + + if (!isValid()) + reattachToWebProcess(); + + auto transaction = m_pageLoadState.transaction(); + m_pageLoadState.setPendingAPIRequestURL(transaction, blankURL().string()); + + m_process->send(Messages::WebPage::LoadWebArchiveData(webArchiveData->dataReference(), UserData(process().transformObjectsToHandles(userData).get())), m_pageID); + m_process->responsivenessTimer().start(); +} + +void WebPageProxy::navigateToPDFLinkWithSimulatedClick(const String& url, IntPoint documentPoint, IntPoint screenPoint) +{ + if (m_isClosed) + return; + + if (WebCore::protocolIsJavaScript(url)) + return; + if (!isValid()) reattachToWebProcess(); - m_process->send(Messages::WebPage::LoadWebArchiveData(webArchiveData->dataReference(), WebContextUserMessageEncoder(userData, process())), m_pageID); - m_process->responsivenessTimer()->start(); + m_process->send(Messages::WebPage::NavigateToPDFLinkWithSimulatedClick(url, documentPoint, screenPoint), m_pageID); + m_process->responsivenessTimer().start(); } void WebPageProxy::stopLoading() @@ -718,15 +1080,18 @@ void WebPageProxy::stopLoading() return; m_process->send(Messages::WebPage::StopLoading(), m_pageID); - m_process->responsivenessTimer()->start(); + m_process->responsivenessTimer().start(); } -void WebPageProxy::reload(bool reloadFromOrigin) +RefPtr<API::Navigation> WebPageProxy::reload(bool reloadFromOrigin, bool contentBlockersEnabled) { SandboxExtension::Handle sandboxExtensionHandle; - if (m_backForwardList->currentItem()) { - String url = m_backForwardList->currentItem()->url(); + String url = m_pageLoadState.activeURL(); + if (url.isEmpty() && m_backForwardList->currentItem()) + url = m_backForwardList->currentItem()->url(); + + if (!url.isEmpty()) { auto transaction = m_pageLoadState.transaction(); m_pageLoadState.setPendingAPIRequestURL(transaction, url); @@ -736,82 +1101,98 @@ void WebPageProxy::reload(bool reloadFromOrigin) m_process->willAcquireUniversalFileReadSandboxExtension(); } - if (!isValid()) { - reattachToWebProcessWithItem(m_backForwardList->currentItem()); - return; - } + if (!isValid()) + return reattachToWebProcessForReload(); + + auto navigation = m_navigationState->createReloadNavigation(); - m_process->send(Messages::WebPage::Reload(reloadFromOrigin, sandboxExtensionHandle), m_pageID); - m_process->responsivenessTimer()->start(); + m_process->send(Messages::WebPage::Reload(navigation->navigationID(), reloadFromOrigin, contentBlockersEnabled, sandboxExtensionHandle), m_pageID); + m_process->responsivenessTimer().start(); + + return WTFMove(navigation); } void WebPageProxy::recordNavigationSnapshot() { - if (!m_shouldRecordNavigationSnapshots) + if (WebBackForwardListItem* item = m_backForwardList->currentItem()) + recordNavigationSnapshot(*item); +} + +void WebPageProxy::recordNavigationSnapshot(WebBackForwardListItem& item) +{ + if (!m_shouldRecordNavigationSnapshots || m_suppressNavigationSnapshotting) return; -#if PLATFORM(MAC) && !PLATFORM(IOS) - ViewSnapshotStore::shared().recordSnapshot(*this); +#if PLATFORM(COCOA) + ViewSnapshotStore::singleton().recordSnapshot(*this, item); +#else + UNUSED_PARAM(item); #endif } -void WebPageProxy::goForward() +RefPtr<API::Navigation> WebPageProxy::goForward() { WebBackForwardListItem* forwardItem = m_backForwardList->forwardItem(); if (!forwardItem) - return; - - recordNavigationSnapshot(); + return nullptr; auto transaction = m_pageLoadState.transaction(); m_pageLoadState.setPendingAPIRequestURL(transaction, forwardItem->url()); - if (!isValid()) { - reattachToWebProcessWithItem(forwardItem); - return; - } + if (!isValid()) + return reattachToWebProcessWithItem(forwardItem); + + RefPtr<API::Navigation> navigation; + if (!m_backForwardList->currentItem()->itemIsInSameDocument(*forwardItem)) + navigation = m_navigationState->createBackForwardNavigation(); + + m_process->send(Messages::WebPage::GoForward(navigation ? navigation->navigationID() : 0, forwardItem->itemID()), m_pageID); + m_process->responsivenessTimer().start(); - m_process->send(Messages::WebPage::GoForward(forwardItem->itemID()), m_pageID); - m_process->responsivenessTimer()->start(); + return navigation; } -void WebPageProxy::goBack() +RefPtr<API::Navigation> WebPageProxy::goBack() { WebBackForwardListItem* backItem = m_backForwardList->backItem(); if (!backItem) - return; - - recordNavigationSnapshot(); + return nullptr; auto transaction = m_pageLoadState.transaction(); m_pageLoadState.setPendingAPIRequestURL(transaction, backItem->url()); - if (!isValid()) { - reattachToWebProcessWithItem(backItem); - return; - } + if (!isValid()) + return reattachToWebProcessWithItem(backItem); + + RefPtr<API::Navigation> navigation; + if (!m_backForwardList->currentItem()->itemIsInSameDocument(*backItem)) + navigation = m_navigationState->createBackForwardNavigation(); + + m_process->send(Messages::WebPage::GoBack(navigation ? navigation->navigationID() : 0, backItem->itemID()), m_pageID); + m_process->responsivenessTimer().start(); - m_process->send(Messages::WebPage::GoBack(backItem->itemID()), m_pageID); - m_process->responsivenessTimer()->start(); + return navigation; } -void WebPageProxy::goToBackForwardItem(WebBackForwardListItem* item) +RefPtr<API::Navigation> WebPageProxy::goToBackForwardItem(WebBackForwardListItem* item) { - if (!isValid()) { - reattachToWebProcessWithItem(item); - return; - } + if (!isValid()) + return reattachToWebProcessWithItem(item); - recordNavigationSnapshot(); - auto transaction = m_pageLoadState.transaction(); m_pageLoadState.setPendingAPIRequestURL(transaction, item->url()); - m_process->send(Messages::WebPage::GoToBackForwardItem(item->itemID()), m_pageID); - m_process->responsivenessTimer()->start(); + RefPtr<API::Navigation> navigation; + if (!m_backForwardList->currentItem()->itemIsInSameDocument(*item)) + navigation = m_navigationState->createBackForwardNavigation(); + + m_process->send(Messages::WebPage::GoToBackForwardItem(navigation ? navigation->navigationID() : 0, item->itemID()), m_pageID); + m_process->responsivenessTimer().start(); + + return navigation; } void WebPageProxy::tryRestoreScrollPosition() @@ -822,20 +1203,31 @@ void WebPageProxy::tryRestoreScrollPosition() m_process->send(Messages::WebPage::TryRestoreScrollPosition(), m_pageID); } -void WebPageProxy::didChangeBackForwardList(WebBackForwardListItem* added, Vector<RefPtr<API::Object>>* removed) +void WebPageProxy::didChangeBackForwardList(WebBackForwardListItem* added, Vector<RefPtr<WebBackForwardListItem>> removed) { - m_loaderClient->didChangeBackForwardList(this, added, removed); + PageClientProtector protector(m_pageClient); + + m_loaderClient->didChangeBackForwardList(*this, added, WTFMove(removed)); + + auto transaction = m_pageLoadState.transaction(); + + m_pageLoadState.setCanGoBack(transaction, m_backForwardList->backItem()); + m_pageLoadState.setCanGoForward(transaction, m_backForwardList->forwardItem()); } -void WebPageProxy::willGoToBackForwardListItem(uint64_t itemID, IPC::MessageDecoder& decoder) +void WebPageProxy::willGoToBackForwardListItem(uint64_t itemID, const UserData& userData) { - RefPtr<API::Object> userData; - WebContextUserMessageDecoder messageDecoder(userData, process()); - if (!decoder.decode(messageDecoder)) - return; + PageClientProtector protector(m_pageClient); if (WebBackForwardListItem* item = m_process->webBackForwardItem(itemID)) - m_loaderClient->willGoToBackForwardListItem(this, item, userData.get()); + m_loaderClient->willGoToBackForwardListItem(*this, item, m_process->transformHandlesToObjects(userData.object()).get()); +} + +bool WebPageProxy::shouldKeepCurrentBackForwardListItemInList(WebBackForwardListItem* item) +{ + PageClientProtector protector(m_pageClient); + + return m_loaderClient->shouldKeepCurrentBackForwardListItemInList(*this, item); } bool WebPageProxy::canShowMIMEType(const String& mimeType) @@ -845,20 +1237,45 @@ bool WebPageProxy::canShowMIMEType(const String& mimeType) #if ENABLE(NETSCAPE_PLUGIN_API) String newMimeType = mimeType; - PluginModuleInfo plugin = m_process->context().pluginInfoStore().findPlugin(newMimeType, URL()); - if (!plugin.path.isNull() && m_pageGroup->preferences()->pluginsEnabled()) + PluginModuleInfo plugin = m_process->processPool().pluginInfoStore().findPlugin(newMimeType, URL()); + if (!plugin.path.isNull() && m_preferences->pluginsEnabled()) return true; #endif // ENABLE(NETSCAPE_PLUGIN_API) -#if PLATFORM(MAC) +#if PLATFORM(COCOA) // On Mac, we can show PDFs. - if (MIMETypeRegistry::isPDFOrPostScriptMIMEType(mimeType) && !WebContext::omitPDFSupport()) + if (MIMETypeRegistry::isPDFOrPostScriptMIMEType(mimeType) && !WebProcessPool::omitPDFSupport()) return true; -#endif // PLATFORM(MAC) +#endif // PLATFORM(COCOA) return false; } +#if ENABLE(REMOTE_INSPECTOR) +void WebPageProxy::setAllowsRemoteInspection(bool allow) +{ + if (m_allowsRemoteInspection == allow) + return; + + m_allowsRemoteInspection = allow; + + if (isValid()) + m_process->send(Messages::WebPage::SetAllowsRemoteInspection(allow), m_pageID); +} + +void WebPageProxy::setRemoteInspectionNameOverride(const String& name) +{ + if (m_remoteInspectionNameOverride == name) + return; + + m_remoteInspectionNameOverride = name; + + if (isValid()) + m_process->send(Messages::WebPage::SetRemoteInspectionNameOverride(m_remoteInspectionNameOverride), m_pageID); +} + +#endif + void WebPageProxy::setDrawsBackground(bool drawsBackground) { if (m_drawsBackground == drawsBackground) @@ -870,15 +1287,15 @@ void WebPageProxy::setDrawsBackground(bool drawsBackground) m_process->send(Messages::WebPage::SetDrawsBackground(drawsBackground), m_pageID); } -void WebPageProxy::setDrawsTransparentBackground(bool drawsTransparentBackground) +void WebPageProxy::setTopContentInset(float contentInset) { - if (m_drawsTransparentBackground == drawsTransparentBackground) + if (m_topContentInset == contentInset) return; - m_drawsTransparentBackground = drawsTransparentBackground; + m_topContentInset = contentInset; if (isValid()) - m_process->send(Messages::WebPage::SetDrawsTransparentBackground(drawsTransparentBackground), m_pageID); + m_process->send(Messages::WebPage::SetTopContentInset(contentInset), m_pageID); } void WebPageProxy::setUnderlayColor(const Color& color) @@ -896,7 +1313,7 @@ void WebPageProxy::viewWillStartLiveResize() { if (!isValid()) return; -#if ENABLE(INPUT_TYPE_COLOR_POPOVER) +#if ENABLE(INPUT_TYPE_COLOR_POPOVER) && ENABLE(INPUT_TYPE_COLOR) if (m_colorPicker) endColorPicker(); #endif @@ -930,6 +1347,26 @@ void WebPageProxy::scrollView(const IntRect& scrollRect, const IntSize& scrollOf m_pageClient.scrollView(scrollRect, scrollOffset); } +void WebPageProxy::requestScroll(const FloatPoint& scrollPosition, const IntPoint& scrollOrigin, bool isProgrammaticScroll) +{ + m_pageClient.requestScroll(scrollPosition, scrollOrigin, isProgrammaticScroll); +} + +void WebPageProxy::setSuppressVisibilityUpdates(bool flag) +{ + if (m_suppressVisibilityUpdates == flag) + return; + m_suppressVisibilityUpdates = flag; + + if (!m_suppressVisibilityUpdates) { +#if PLATFORM(COCOA) + m_viewStateChangeDispatcher->schedule(); +#else + dispatchViewStateChange(); +#endif + } +} + void WebPageProxy::updateViewState(ViewState::Flags flagsToUpdate) { m_viewState &= ~flagsToUpdate; @@ -939,73 +1376,177 @@ void WebPageProxy::updateViewState(ViewState::Flags flagsToUpdate) m_viewState |= ViewState::WindowIsActive; if (flagsToUpdate & ViewState::IsVisible && m_pageClient.isViewVisible()) m_viewState |= ViewState::IsVisible; + if (flagsToUpdate & ViewState::IsVisibleOrOccluded && m_pageClient.isViewVisibleOrOccluded()) + m_viewState |= ViewState::IsVisibleOrOccluded; if (flagsToUpdate & ViewState::IsInWindow && m_pageClient.isViewInWindow()) m_viewState |= ViewState::IsInWindow; if (flagsToUpdate & ViewState::IsVisuallyIdle && m_pageClient.isVisuallyIdle()) m_viewState |= ViewState::IsVisuallyIdle; } -void WebPageProxy::viewStateDidChange(ViewState::Flags mayHaveChanged, WantsReplyOrNot wantsReply) +void WebPageProxy::viewStateDidChange(ViewState::Flags mayHaveChanged, bool wantsSynchronousReply, ViewStateChangeDispatchMode dispatchMode) +{ + m_potentiallyChangedViewStateFlags |= mayHaveChanged; + m_viewStateChangeWantsSynchronousReply = m_viewStateChangeWantsSynchronousReply || wantsSynchronousReply; + + if (m_suppressVisibilityUpdates && dispatchMode != ViewStateChangeDispatchMode::Immediate) + return; + +#if PLATFORM(COCOA) + bool isNewlyInWindow = !isInWindow() && (mayHaveChanged & ViewState::IsInWindow) && m_pageClient.isViewInWindow(); + if (dispatchMode == ViewStateChangeDispatchMode::Immediate || isNewlyInWindow) { + dispatchViewStateChange(); + return; + } + m_viewStateChangeDispatcher->schedule(); +#else + UNUSED_PARAM(dispatchMode); + dispatchViewStateChange(); +#endif +} + +void WebPageProxy::viewDidLeaveWindow() +{ +#if ENABLE(INPUT_TYPE_COLOR_POPOVER) && ENABLE(INPUT_TYPE_COLOR) + // When leaving the current page, close the popover color well. + if (m_colorPicker) + endColorPicker(); +#endif +#if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)) + // When leaving the current page, close the video fullscreen. + if (m_videoFullscreenManager) + m_videoFullscreenManager->requestHideAndExitFullscreen(); +#endif +} + +void WebPageProxy::viewDidEnterWindow() { + LayerHostingMode layerHostingMode = m_pageClient.viewLayerHostingMode(); + if (m_layerHostingMode != layerHostingMode) { + m_layerHostingMode = layerHostingMode; + m_process->send(Messages::WebPage::SetLayerHostingMode(static_cast<unsigned>(layerHostingMode)), m_pageID); + } +} + +void WebPageProxy::dispatchViewStateChange() +{ +#if PLATFORM(COCOA) + m_viewStateChangeDispatcher->invalidate(); +#endif + if (!isValid()) return; - // If the visibility state may have changed, then so may the visually idle. - if (mayHaveChanged & ViewState::IsVisible) - mayHaveChanged |= ViewState::IsVisuallyIdle; + // If the visibility state may have changed, then so may the visually idle & occluded agnostic state. + if (m_potentiallyChangedViewStateFlags & ViewState::IsVisible) + m_potentiallyChangedViewStateFlags |= ViewState::IsVisibleOrOccluded | ViewState::IsVisuallyIdle; // Record the prior view state, update the flags that may have changed, // and check which flags have actually changed. ViewState::Flags previousViewState = m_viewState; - updateViewState(mayHaveChanged); + updateViewState(m_potentiallyChangedViewStateFlags); ViewState::Flags changed = m_viewState ^ previousViewState; - if (changed) - m_process->send(Messages::WebPage::SetViewState(m_viewState, wantsReply == WantsReplyOrNot::DoesWantReply), m_pageID); + bool isNowInWindow = (changed & ViewState::IsInWindow) && isInWindow(); + // We always want to wait for the Web process to reply if we've been in-window before and are coming back in-window. + if (m_viewWasEverInWindow && isNowInWindow && m_drawingArea->hasVisibleContent()) + m_viewStateChangeWantsSynchronousReply = true; - if (changed & ViewState::IsVisuallyIdle) - m_process->pageSuppressibilityChanged(this); + // Don't wait synchronously if the view state is not visible. (This matters in particular on iOS, where a hidden page may be suspended.) + if (!(m_viewState & ViewState::IsVisible)) + m_viewStateChangeWantsSynchronousReply = false; + + if (changed || m_viewStateChangeWantsSynchronousReply || !m_nextViewStateChangeCallbacks.isEmpty()) + m_process->send(Messages::WebPage::SetViewState(m_viewState, m_viewStateChangeWantsSynchronousReply, m_nextViewStateChangeCallbacks), m_pageID); + + m_nextViewStateChangeCallbacks.clear(); + + // This must happen after the SetViewState message is sent, to ensure the page visibility event can fire. + updateActivityToken(); // If we've started the responsiveness timer as part of telling the web process to update the backing store // state, it might not send back a reply (since it won't paint anything if the web page is hidden) so we // stop the unresponsiveness timer here. if ((changed & ViewState::IsVisible) && !isViewVisible()) - m_process->responsivenessTimer()->stop(); + m_process->responsivenessTimer().stop(); - if ((mayHaveChanged & ViewState::IsInWindow) && (m_viewState & ViewState::IsInWindow)) { - LayerHostingMode layerHostingMode = m_pageClient.viewLayerHostingMode(); - if (m_layerHostingMode != layerHostingMode) { - m_layerHostingMode = layerHostingMode; - m_process->send(Messages::WebPage::SetLayerHostingMode(layerHostingMode), m_pageID); - } + if (changed & ViewState::IsInWindow) { + if (isInWindow()) + viewDidEnterWindow(); + else + viewDidLeaveWindow(); } -#if ENABLE(INPUT_TYPE_COLOR_POPOVER) - if ((mayHaveChanged & ViewState::IsInWindow) && !(m_viewState & ViewState::IsInWindow)) { - // When leaving the current page, close the popover color well. - if (m_colorPicker) - endColorPicker(); - } + updateBackingStoreDiscardableState(); + + if (m_viewStateChangeWantsSynchronousReply) + waitForDidUpdateViewState(); + + m_potentiallyChangedViewStateFlags = ViewState::NoFlags; + m_viewStateChangeWantsSynchronousReply = false; + m_viewWasEverInWindow |= isNowInWindow; +} + +void WebPageProxy::updateActivityToken() +{ + if (m_viewState & ViewState::IsVisuallyIdle) + m_pageIsUserObservableCount = nullptr; + else if (!m_pageIsUserObservableCount) + m_pageIsUserObservableCount = m_process->processPool().userObservablePageCount(); + +#if PLATFORM(IOS) + if (!isViewVisible() && !m_alwaysRunsAtForegroundPriority) + m_activityToken = nullptr; + else if (!m_activityToken) + m_activityToken = m_process->throttler().foregroundActivityToken(); #endif +} - updateBackingStoreDiscardableState(); +void WebPageProxy::updateProccessSuppressionState() +{ + if (m_preferences->pageVisibilityBasedProcessSuppressionEnabled()) + m_preventProcessSuppressionCount = nullptr; + else if (!m_preventProcessSuppressionCount) + m_preventProcessSuppressionCount = m_process->processPool().processSuppressionDisabledForPageCount(); +} + +void WebPageProxy::layerHostingModeDidChange() +{ + if (!isValid()) + return; + + LayerHostingMode layerHostingMode = m_pageClient.viewLayerHostingMode(); + if (m_layerHostingMode == layerHostingMode) + return; + + m_layerHostingMode = layerHostingMode; + m_process->send(Messages::WebPage::SetLayerHostingMode(static_cast<unsigned>(layerHostingMode)), m_pageID); } void WebPageProxy::waitForDidUpdateViewState() { + if (!isValid()) + return; + + if (m_process->state() != WebProcessProxy::State::Running) + return; + // If we have previously timed out with no response from the WebProcess, don't block the UIProcess again until it starts responding. if (m_waitingForDidUpdateViewState) return; - if (!isValid()) +#if PLATFORM(IOS) + // Hail Mary check. Should not be possible (dispatchViewStateChange should force async if not visible, + // and if visible we should be holding an assertion) - but we should never block on a suspended process. + if (!m_activityToken) { + ASSERT_NOT_REACHED(); return; + } +#endif m_waitingForDidUpdateViewState = true; - if (!m_process->isLaunching()) { - auto viewStateUpdateTimeout = std::chrono::milliseconds(250); - m_process->connection()->waitForAndDispatchImmediately<Messages::WebPageProxy::DidUpdateViewState>(m_pageID, viewStateUpdateTimeout); - } + m_drawingArea->waitForDidUpdateViewState(); } IntSize WebPageProxy::viewSize() const @@ -1013,36 +1554,39 @@ IntSize WebPageProxy::viewSize() const return m_pageClient.viewSize(); } -void WebPageProxy::setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent& keyboardEvent) +void WebPageProxy::setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent& keyboardEvent, std::function<void (CallbackBase::Error)> callbackFunction) { - if (!isValid()) + if (!isValid()) { + callbackFunction(CallbackBase::Error::OwnerWasInvalidated); return; - m_process->send(Messages::WebPage::SetInitialFocus(forward, isKeyboardEventValid, keyboardEvent), m_pageID); + } + + uint64_t callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken()); + m_process->send(Messages::WebPage::SetInitialFocus(forward, isKeyboardEventValid, keyboardEvent, callbackID), m_pageID); } -void WebPageProxy::setWindowResizerSize(const IntSize& windowResizerSize) +void WebPageProxy::clearSelection() { if (!isValid()) return; - m_process->send(Messages::WebPage::SetWindowResizerSize(windowResizerSize), m_pageID); + m_process->send(Messages::WebPage::ClearSelection(), m_pageID); } - -void WebPageProxy::clearSelection() + +void WebPageProxy::restoreSelectionInFocusedEditableElement() { if (!isValid()) return; - m_process->send(Messages::WebPage::ClearSelection(), m_pageID); + m_process->send(Messages::WebPage::RestoreSelectionInFocusedEditableElement(), m_pageID); } -void WebPageProxy::validateCommand(const String& commandName, PassRefPtr<ValidateCommandCallback> callback) +void WebPageProxy::validateCommand(const String& commandName, std::function<void (const String&, bool, int32_t, CallbackBase::Error)> callbackFunction) { if (!isValid()) { - callback->invalidate(); + callbackFunction(String(), false, 0, CallbackBase::Error::Unknown); return; } - uint64_t callbackID = callback->callbackID(); - m_validateCommandCallbacks.set(callbackID, callback.get()); + uint64_t callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken()); m_process->send(Messages::WebPage::ValidateCommand(commandName, callbackID), m_pageID); } @@ -1051,7 +1595,7 @@ void WebPageProxy::setMaintainsInactiveSelection(bool newValue) m_maintainsInactiveSelection = newValue; } -void WebPageProxy::executeEditCommand(const String& commandName) +void WebPageProxy::executeEditCommand(const String& commandName, const String& argument) { static NeverDestroyed<String> ignoreSpellingCommandName(ASCIILiteral("ignoreSpelling")); @@ -1061,16 +1605,23 @@ void WebPageProxy::executeEditCommand(const String& commandName) if (commandName == ignoreSpellingCommandName) ++m_pendingLearnOrIgnoreWordMessageCount; - m_process->send(Messages::WebPage::ExecuteEditCommand(commandName), m_pageID); + m_process->send(Messages::WebPage::ExecuteEditCommand(commandName, argument), m_pageID); } - -#if USE(TILED_BACKING_STORE) -void WebPageProxy::commitPageTransitionViewport() + +void WebPageProxy::setEditable(bool editable) { + if (editable == m_isEditable) + return; if (!isValid()) return; - process().send(Messages::WebPage::CommitPageTransitionViewport(), m_pageID); + m_isEditable = editable; + m_process->send(Messages::WebPage::SetEditable(editable), m_pageID); +} + +#if !PLATFORM(IOS) +void WebPageProxy::didCommitLayerTree(const RemoteLayerTreeTransaction&) +{ } #endif @@ -1096,9 +1647,9 @@ void WebPageProxy::dragExited(DragData& dragData, const String& dragStorageName) performDragControllerAction(DragControllerActionExited, dragData, dragStorageName, sandboxExtensionHandle, sandboxExtensionHandleEmptyArray); } -void WebPageProxy::performDrag(DragData& dragData, const String& dragStorageName, const SandboxExtension::Handle& sandboxExtensionHandle, const SandboxExtension::HandleArray& sandboxExtensionsForUpload) +void WebPageProxy::performDragOperation(DragData& dragData, const String& dragStorageName, const SandboxExtension::Handle& sandboxExtensionHandle, const SandboxExtension::HandleArray& sandboxExtensionsForUpload) { - performDragControllerAction(DragControllerActionPerformDrag, dragData, dragStorageName, sandboxExtensionHandle, sandboxExtensionsForUpload); + performDragControllerAction(DragControllerActionPerformDragOperation, dragData, dragStorageName, sandboxExtensionHandle, sandboxExtensionsForUpload); } void WebPageProxy::performDragControllerAction(DragControllerAction action, DragData& dragData, const String& dragStorageName, const SandboxExtension::Handle& sandboxExtensionHandle, const SandboxExtension::HandleArray& sandboxExtensionsForUpload) @@ -1106,7 +1657,11 @@ void WebPageProxy::performDragControllerAction(DragControllerAction action, Drag if (!isValid()) return; #if PLATFORM(GTK) - String url = dragData.asURL(nullptr); + UNUSED_PARAM(dragStorageName); + UNUSED_PARAM(sandboxExtensionHandle); + UNUSED_PARAM(sandboxExtensionsForUpload); + + String url = dragData.asURL(); if (!url.isEmpty()) m_process->assumeReadAccessToBaseURL(url); m_process->send(Messages::WebPage::PerformDragControllerAction(action, dragData), m_pageID); @@ -1115,9 +1670,13 @@ void WebPageProxy::performDragControllerAction(DragControllerAction action, Drag #endif } -void WebPageProxy::didPerformDragControllerAction(WebCore::DragSession dragSession) +void WebPageProxy::didPerformDragControllerAction(uint64_t dragOperation, bool mouseIsOverFileInput, unsigned numberOfItemsToBeAccepted) { - m_currentDragSession = dragSession; + MESSAGE_CHECK(dragOperation <= DragOperationDelete); + + m_currentDragOperation = static_cast<DragOperation>(dragOperation); + m_currentDragIsOverFileInput = mouseIsOverFileInput; + m_currentDragNumberOfFilesToBeAccepted = numberOfItemsToBeAccepted; } #if PLATFORM(GTK) @@ -1147,12 +1706,15 @@ void WebPageProxy::handleMouseEvent(const NativeWebMouseEvent& event) if (!isValid()) return; + if (m_pageClient.windowIsFrontWindowUnderMouse(event)) + setToolTip(String()); + // NOTE: This does not start the responsiveness timer because mouse move should not indicate interaction. if (event.type() != WebEvent::MouseMove) - m_process->responsivenessTimer()->start(); + m_process->responsivenessTimer().start(); else { if (m_processingMouseMoveEvent) { - m_nextMouseMoveEvent = adoptPtr(new NativeWebMouseEvent(event)); + m_nextMouseMoveEvent = std::make_unique<NativeWebMouseEvent>(event); return; } @@ -1164,14 +1726,9 @@ void WebPageProxy::handleMouseEvent(const NativeWebMouseEvent& event) // we fake a mouse up event by using this stored down event. This event gets cleared // when the mouse up message is received from WebProcess. if (event.type() == WebEvent::MouseDown) - m_currentlyProcessedMouseDownEvent = adoptPtr(new NativeWebMouseEvent(event)); + m_currentlyProcessedMouseDownEvent = std::make_unique<NativeWebMouseEvent>(event); - if (m_shouldSendEventsSynchronously) { - bool handled = false; - m_process->sendSync(Messages::WebPage::MouseEventSyncForTesting(event), Messages::WebPage::MouseEventSyncForTesting::Reply(handled), m_pageID); - didReceiveEvent(event.type(), handled); - } else - m_process->send(Messages::WebPage::MouseEvent(event), m_pageID); + m_process->send(Messages::WebPage::MouseEvent(event), m_pageID); } #if MERGE_WHEEL_EVENTS @@ -1185,7 +1742,7 @@ static bool canCoalesce(const WebWheelEvent& a, const WebWheelEvent& b) return false; if (a.granularity() != b.granularity()) return false; -#if PLATFORM(MAC) +#if PLATFORM(COCOA) if (a.phase() != b.phase()) return false; if (a.momentumPhase() != b.momentumPhase()) @@ -1204,7 +1761,7 @@ static WebWheelEvent coalesce(const WebWheelEvent& a, const WebWheelEvent& b) FloatSize mergedDelta = a.delta() + b.delta(); FloatSize mergedWheelTicks = a.wheelTicks() + b.wheelTicks(); -#if PLATFORM(MAC) +#if PLATFORM(COCOA) FloatSize mergedUnacceleratedScrollingDelta = a.unacceleratedScrollingDelta() + b.unacceleratedScrollingDelta(); return WebWheelEvent(WebEvent::Wheel, b.position(), b.globalPosition(), mergedDelta, mergedWheelTicks, b.granularity(), b.directionInvertedFromDevice(), b.phase(), b.momentumPhase(), b.hasPreciseScrollingDeltas(), b.scrollCount(), mergedUnacceleratedScrollingDelta, b.modifiers(), b.timestamp()); @@ -1260,40 +1817,35 @@ void WebPageProxy::handleWheelEvent(const NativeWebWheelEvent& event) return; } - OwnPtr<Vector<NativeWebWheelEvent>> coalescedWheelEvent = adoptPtr(new Vector<NativeWebWheelEvent>); + auto coalescedWheelEvent = std::make_unique<Vector<NativeWebWheelEvent>>(); coalescedWheelEvent->append(event); - m_currentlyProcessedWheelEvents.append(coalescedWheelEvent.release()); + m_currentlyProcessedWheelEvents.append(WTFMove(coalescedWheelEvent)); sendWheelEvent(event); } void WebPageProxy::processNextQueuedWheelEvent() { - OwnPtr<Vector<NativeWebWheelEvent>> nextCoalescedEvent = adoptPtr(new Vector<NativeWebWheelEvent>); + auto nextCoalescedEvent = std::make_unique<Vector<NativeWebWheelEvent>>(); WebWheelEvent nextWheelEvent = coalescedWheelEvent(m_wheelEventQueue, *nextCoalescedEvent.get()); - m_currentlyProcessedWheelEvents.append(nextCoalescedEvent.release()); + m_currentlyProcessedWheelEvents.append(WTFMove(nextCoalescedEvent)); sendWheelEvent(nextWheelEvent); } void WebPageProxy::sendWheelEvent(const WebWheelEvent& event) { - m_process->responsivenessTimer()->start(); - - if (m_shouldSendEventsSynchronously) { - bool handled = false; - m_process->sendSync(Messages::WebPage::WheelEventSyncForTesting(event), Messages::WebPage::WheelEventSyncForTesting::Reply(handled), m_pageID); - didReceiveEvent(event.type(), handled); - return; - } - m_process->send( Messages::EventDispatcher::WheelEvent( m_pageID, event, - m_useLegacyImplicitRubberBandControl ? !m_backForwardList->backItem() : rubberBandsAtLeft(), - m_useLegacyImplicitRubberBandControl ? !m_backForwardList->forwardItem() : rubberBandsAtRight(), + shouldUseImplicitRubberBandControl() ? !m_backForwardList->backItem() : rubberBandsAtLeft(), + shouldUseImplicitRubberBandControl() ? !m_backForwardList->forwardItem() : rubberBandsAtRight(), rubberBandsAtTop(), rubberBandsAtBottom() ), 0); + + // Manually ping the web process to check for responsiveness since our wheel + // event will dispatch to a non-main thread, which always responds. + m_process->isResponsive(nullptr); } void WebPageProxy::handleKeyboardEvent(const NativeWebKeyboardEvent& event) @@ -1305,25 +1857,35 @@ void WebPageProxy::handleKeyboardEvent(const NativeWebKeyboardEvent& event) m_keyEventQueue.append(event); - m_process->responsivenessTimer()->start(); - if (m_shouldSendEventsSynchronously) { - bool handled = false; - m_process->sendSync(Messages::WebPage::KeyEventSyncForTesting(event), Messages::WebPage::KeyEventSyncForTesting::Reply(handled), m_pageID); - didReceiveEvent(event.type(), handled); - } else if (m_keyEventQueue.size() == 1) // Otherwise, sent from DidReceiveEvent message handler. + m_process->responsivenessTimer().start(); + if (m_keyEventQueue.size() == 1) // Otherwise, sent from DidReceiveEvent message handler. m_process->send(Messages::WebPage::KeyEvent(event), m_pageID); } +WebPreferencesStore WebPageProxy::preferencesStore() const +{ + if (m_configurationPreferenceValues.isEmpty()) + return m_preferences->store(); + + WebPreferencesStore store = m_preferences->store(); + for (const auto& preference : m_configurationPreferenceValues) + store.m_values.set(preference.key, preference.value); + + return store; +} + #if ENABLE(NETSCAPE_PLUGIN_API) void WebPageProxy::findPlugin(const String& mimeType, uint32_t processType, const String& urlString, const String& frameURLString, const String& pageURLString, bool allowOnlyApplicationPlugins, uint64_t& pluginProcessToken, String& newMimeType, uint32_t& pluginLoadPolicy, String& unavailabilityDescription) { + PageClientProtector protector(m_pageClient); + MESSAGE_CHECK_URL(urlString); - newMimeType = mimeType.lower(); + newMimeType = mimeType.convertToASCIILowercase(); pluginLoadPolicy = PluginModuleLoadNormally; PluginData::AllowedPluginTypes allowedPluginTypes = allowOnlyApplicationPlugins ? PluginData::OnlyApplicationPlugins : PluginData::AllPlugins; - PluginModuleInfo plugin = m_process->context().pluginInfoStore().findPlugin(newMimeType, URL(URL(), urlString), allowedPluginTypes); + PluginModuleInfo plugin = m_process->processPool().pluginInfoStore().findPlugin(newMimeType, URL(URL(), urlString), allowedPluginTypes); if (!plugin.path) { pluginProcessToken = 0; return; @@ -1331,9 +1893,12 @@ void WebPageProxy::findPlugin(const String& mimeType, uint32_t processType, cons pluginLoadPolicy = PluginInfoStore::defaultLoadPolicyForPlugin(plugin); -#if PLATFORM(MAC) - RefPtr<ImmutableDictionary> pluginInformation = createPluginInformationDictionary(plugin, frameURLString, String(), pageURLString, String(), String()); - pluginLoadPolicy = m_loaderClient->pluginLoadPolicy(this, static_cast<PluginModuleLoadPolicy>(pluginLoadPolicy), pluginInformation.get(), unavailabilityDescription); +#if PLATFORM(COCOA) + RefPtr<API::Dictionary> pluginInformation = createPluginInformationDictionary(plugin, frameURLString, String(), pageURLString, String(), String()); + if (m_navigationClient) + pluginLoadPolicy = m_navigationClient->decidePolicyForPluginLoad(*this, static_cast<PluginModuleLoadPolicy>(pluginLoadPolicy), pluginInformation.get(), unavailabilityDescription); + else + pluginLoadPolicy = m_loaderClient->pluginLoadPolicy(*this, static_cast<PluginModuleLoadPolicy>(pluginLoadPolicy), pluginInformation.get(), unavailabilityDescription); #else UNUSED_PARAM(frameURLString); UNUSED_PARAM(pageURLString); @@ -1349,34 +1914,108 @@ void WebPageProxy::findPlugin(const String& mimeType, uint32_t processType, cons pluginProcessSandboxPolicy = PluginProcessSandboxPolicyUnsandboxed; break; - case PluginModuleBlocked: + case PluginModuleBlockedForSecurity: + case PluginModuleBlockedForCompatibility: pluginProcessToken = 0; return; } - pluginProcessToken = PluginProcessManager::shared().pluginProcessToken(plugin, static_cast<PluginProcessType>(processType), pluginProcessSandboxPolicy); + pluginProcessToken = PluginProcessManager::singleton().pluginProcessToken(plugin, static_cast<PluginProcessType>(processType), pluginProcessSandboxPolicy); } #endif // ENABLE(NETSCAPE_PLUGIN_API) #if ENABLE(TOUCH_EVENTS) + +bool WebPageProxy::shouldStartTrackingTouchEvents(const WebTouchEvent& touchStartEvent) const +{ +#if ENABLE(ASYNC_SCROLLING) + for (auto& touchPoint : touchStartEvent.touchPoints()) { + if (m_scrollingCoordinatorProxy->isPointInNonFastScrollableRegion(touchPoint.location())) + return true; + } + + return false; +#else + UNUSED_PARAM(touchStartEvent); +#endif // ENABLE(ASYNC_SCROLLING) + return true; +} + +#endif + +#if ENABLE(MAC_GESTURE_EVENTS) +void WebPageProxy::handleGestureEvent(const NativeWebGestureEvent& event) +{ + if (!isValid()) + return; + + m_gestureEventQueue.append(event); + // FIXME: Consider doing some coalescing here. + m_process->responsivenessTimer().start(); + + m_process->send(Messages::EventDispatcher::GestureEvent(m_pageID, event), 0); +} +#endif + +#if ENABLE(IOS_TOUCH_EVENTS) +void WebPageProxy::handleTouchEventSynchronously(const NativeWebTouchEvent& event) +{ + if (!isValid()) + return; + + if (event.type() == WebEvent::TouchStart) { + m_isTrackingTouchEvents = shouldStartTrackingTouchEvents(event); + m_layerTreeTransactionIdAtLastTouchStart = downcast<RemoteLayerTreeDrawingAreaProxy>(*drawingArea()).lastCommittedLayerTreeTransactionID(); + } + + if (!m_isTrackingTouchEvents) + return; + + m_process->responsivenessTimer().start(); + bool handled = false; + m_process->sendSync(Messages::WebPage::TouchEventSync(event), Messages::WebPage::TouchEventSync::Reply(handled), m_pageID); + didReceiveEvent(event.type(), handled); + m_pageClient.doneWithTouchEvent(event, handled); + m_process->responsivenessTimer().stop(); + + if (event.allTouchPointsAreReleased()) + m_isTrackingTouchEvents = false; +} + +void WebPageProxy::handleTouchEventAsynchronously(const NativeWebTouchEvent& event) +{ + if (!isValid()) + return; + + if (!m_isTrackingTouchEvents) + return; + + m_process->send(Messages::EventDispatcher::TouchEvent(m_pageID, event), 0); + + if (event.allTouchPointsAreReleased()) + m_isTrackingTouchEvents = false; +} + +#elif ENABLE(TOUCH_EVENTS) void WebPageProxy::handleTouchEvent(const NativeWebTouchEvent& event) { if (!isValid()) return; + if (event.type() == WebEvent::TouchStart) + m_isTrackingTouchEvents = shouldStartTrackingTouchEvents(event); + + if (!m_isTrackingTouchEvents) + return; + // If the page is suspended, which should be the case during panning, pinching // and animation on the page itself (kinetic scrolling, tap to zoom) etc, then // we do not send any of the events to the page even if is has listeners. - if (m_needTouchEvents && !m_isPageSuspended) { + if (!m_isPageSuspended) { m_touchEventQueue.append(event); - m_process->responsivenessTimer()->start(); - if (m_shouldSendEventsSynchronously) { - bool handled = false; - m_process->sendSync(Messages::WebPage::TouchEventSyncForTesting(event), Messages::WebPage::TouchEventSyncForTesting::Reply(handled), m_pageID); - didReceiveEvent(event.type(), handled); - } else - m_process->send(Messages::WebPage::TouchEvent(event), m_pageID); + m_process->responsivenessTimer().start(); + m_process->send(Messages::WebPage::TouchEvent(event), m_pageID); } else { if (m_touchEventQueue.isEmpty()) { bool isEventHandled = false; @@ -1388,8 +2027,11 @@ void WebPageProxy::handleTouchEvent(const NativeWebTouchEvent& event) lastEvent.deferredTouchEvents.append(event); } } + + if (event.allTouchPointsAreReleased()) + m_isTrackingTouchEvents = false; } -#endif +#endif // ENABLE(TOUCH_EVENTS) void WebPageProxy::scrollBy(ScrollDirection direction, ScrollGranularity granularity) { @@ -1407,7 +2049,7 @@ void WebPageProxy::centerSelectionInVisibleArea() m_process->send(Messages::WebPage::CenterSelectionInVisibleArea(), m_pageID); } -void WebPageProxy::receivedPolicyDecision(PolicyAction action, WebFrameProxy* frame, uint64_t listenerID) +void WebPageProxy::receivedPolicyDecision(PolicyAction action, WebFrameProxy* frame, uint64_t listenerID, API::Navigation* navigation) { if (!isValid()) return; @@ -1417,15 +2059,14 @@ void WebPageProxy::receivedPolicyDecision(PolicyAction action, WebFrameProxy* fr if (action == PolicyIgnore) m_pageLoadState.clearPendingAPIRequestURL(transaction); - uint64_t downloadID = 0; + DownloadID downloadID = { }; if (action == PolicyDownload) { // Create a download proxy. - DownloadProxy* download = m_process->context().createDownloadProxy(); + // FIXME: We should ensure that the downloadRequest is never empty. + const ResourceRequest& downloadRequest = m_decidePolicyForResponseRequest ? *m_decidePolicyForResponseRequest : ResourceRequest(); + DownloadProxy* download = m_process->processPool().createDownloadProxy(downloadRequest); downloadID = download->downloadID(); -#if PLATFORM(EFL) || PLATFORM(GTK) - // Our design does not suppport downloads without a WebPage. handleDownloadRequest(download); -#endif } // If we received a policy decision while in decidePolicyForResponse the decision will @@ -1446,7 +2087,7 @@ void WebPageProxy::receivedPolicyDecision(PolicyAction action, WebFrameProxy* fr return; } - m_process->send(Messages::WebPage::DidReceivePolicyDecision(frame->frameID(), listenerID, action, downloadID), m_pageID); + m_process->send(Messages::WebPage::DidReceivePolicyDecision(frame->frameID(), listenerID, action, navigation ? navigation->navigationID() : 0, downloadID), m_pageID); } void WebPageProxy::setUserAgent(const String& userAgent) @@ -1526,6 +2167,11 @@ void WebPageProxy::setCustomTextEncodingName(const String& encodingName) void WebPageProxy::terminateProcess() { + // requestTermination() is a no-op for launching processes, so we get into an inconsistent state by calling resetStateAfterProcessExited(). + // FIXME: A client can terminate the page at any time, so we should do something more meaningful than assert and fall apart in release builds. + // See also <https://bugs.webkit.org/show_bug.cgi?id=136012>. + ASSERT(m_process->state() != WebProcessProxy::State::Launching); + // NOTE: This uses a check of m_isValid rather than calling isValid() since // we want this to run even for pages being closed or that already closed. if (!m_isValid) @@ -1535,18 +2181,61 @@ void WebPageProxy::terminateProcess() resetStateAfterProcessExited(); } -#if !USE(CF) -PassRefPtr<API::Data> WebPageProxy::sessionStateData(WebPageProxySessionStateFilterCallback, void* /*context*/) const +SessionState WebPageProxy::sessionState(const std::function<bool (WebBackForwardListItem&)>& filter) const { - // FIXME: Return session state data for saving Page state. - return 0; + SessionState sessionState; + + sessionState.backForwardListState = m_backForwardList->backForwardListState(filter); + + String provisionalURLString = m_pageLoadState.pendingAPIRequestURL(); + if (provisionalURLString.isEmpty()) + provisionalURLString = m_pageLoadState.provisionalURL(); + + if (!provisionalURLString.isEmpty()) + sessionState.provisionalURL = URL(URL(), provisionalURLString); + + sessionState.renderTreeSize = renderTreeSize(); + return sessionState; } -void WebPageProxy::restoreFromSessionStateData(API::Data*) +RefPtr<API::Navigation> WebPageProxy::restoreFromSessionState(SessionState sessionState, bool navigate) { - // FIXME: Restore the Page from the passed in session state data. + m_sessionRestorationRenderTreeSize = 0; + m_hitRenderTreeSizeThreshold = false; + + bool hasBackForwardList = !!sessionState.backForwardListState.currentIndex; + + if (hasBackForwardList) { + m_backForwardList->restoreFromState(WTFMove(sessionState.backForwardListState)); + + for (const auto& entry : m_backForwardList->entries()) + process().registerNewWebBackForwardListItem(entry.get()); + + process().send(Messages::WebPage::RestoreSession(m_backForwardList->itemStates()), m_pageID); + + // The back / forward list was restored from a sessionState so we don't want to snapshot the current + // page when navigating away. Suppress navigation snapshotting until the next load has committed. + m_suppressNavigationSnapshotting = true; + } + + // FIXME: Navigating should be separate from state restoration. + if (navigate) { + m_sessionRestorationRenderTreeSize = sessionState.renderTreeSize; + if (!m_sessionRestorationRenderTreeSize) + m_hitRenderTreeSizeThreshold = true; // If we didn't get data on renderTreeSize, just don't fire the milestone. + + if (!sessionState.provisionalURL.isNull()) + return loadRequest(sessionState.provisionalURL); + + if (hasBackForwardList) { + // FIXME: Do we have to null check the back forward list item here? + if (WebBackForwardListItem* item = m_backForwardList->currentItem()) + return goToBackForwardItem(item); + } + } + + return nullptr; } -#endif bool WebPageProxy::supportsTextZoom() const { @@ -1594,8 +2283,28 @@ void WebPageProxy::setPageAndTextZoomFactors(double pageZoomFactor, double textZ m_process->send(Messages::WebPage::SetPageAndTextZoomFactors(m_pageZoomFactor, m_textZoomFactor), m_pageID); } +double WebPageProxy::pageZoomFactor() const +{ + // Zoom factor for non-PDF pages persists across page loads. We maintain a separate member variable for PDF + // zoom which ensures that we don't use the PDF zoom for a normal page. + if (m_mainFramePluginHandlesPageScaleGesture) + return m_pluginZoomFactor; + return m_pageZoomFactor; +} + +double WebPageProxy::pageScaleFactor() const +{ + // PDF documents use zoom and scale factors to size themselves appropriately in the window. We store them + // separately but decide which to return based on the main frame. + if (m_mainFramePluginHandlesPageScaleGesture) + return m_pluginScaleFactor; + return m_pageScaleFactor; +} + void WebPageProxy::scalePage(double scale, const IntPoint& origin) { + ASSERT(scale > 0); + if (!isValid()) return; @@ -1603,6 +2312,28 @@ void WebPageProxy::scalePage(double scale, const IntPoint& origin) m_process->send(Messages::WebPage::ScalePage(scale, origin), m_pageID); } +void WebPageProxy::scalePageInViewCoordinates(double scale, const IntPoint& centerInViewCoordinates) +{ + ASSERT(scale > 0); + + if (!isValid()) + return; + + m_pageScaleFactor = scale; + m_process->send(Messages::WebPage::ScalePageInViewCoordinates(scale, centerInViewCoordinates), m_pageID); +} + +void WebPageProxy::scaleView(double scale) +{ + ASSERT(scale > 0); + + if (!isValid()) + return; + + m_viewScaleFactor = scale; + m_process->send(Messages::WebPage::ScaleView(scale), m_pageID); +} + void WebPageProxy::setIntrinsicDeviceScaleFactor(float scaleFactor) { if (m_intrinsicDeviceScaleFactor == scaleFactor) @@ -1683,17 +2414,12 @@ void WebPageProxy::listenForLayoutMilestones(WebCore::LayoutMilestones milestone { if (!isValid()) return; + + m_wantsSessionRestorationRenderTreeSizeThresholdEvent = milestones & WebCore::ReachedSessionRestorationRenderTreeSizeThreshold; m_process->send(Messages::WebPage::ListenForLayoutMilestones(milestones), m_pageID); } -void WebPageProxy::setVisibilityStatePrerender() -{ - if (!isValid()) - return; - m_process->send(Messages::WebPage::SetVisibilityStatePrerender(), m_pageID); -} - void WebPageProxy::setSuppressScrollbarAnimations(bool suppressAnimations) { if (!isValid()) @@ -1745,6 +2471,40 @@ void WebPageProxy::setRubberBandsAtBottom(bool rubberBandsAtBottom) { m_rubberBandsAtBottom = rubberBandsAtBottom; } + +void WebPageProxy::setEnableVerticalRubberBanding(bool enableVerticalRubberBanding) +{ + if (enableVerticalRubberBanding == m_enableVerticalRubberBanding) + return; + + m_enableVerticalRubberBanding = enableVerticalRubberBanding; + + if (!isValid()) + return; + m_process->send(Messages::WebPage::SetEnableVerticalRubberBanding(enableVerticalRubberBanding), m_pageID); +} + +bool WebPageProxy::verticalRubberBandingIsEnabled() const +{ + return m_enableVerticalRubberBanding; +} + +void WebPageProxy::setEnableHorizontalRubberBanding(bool enableHorizontalRubberBanding) +{ + if (enableHorizontalRubberBanding == m_enableHorizontalRubberBanding) + return; + + m_enableHorizontalRubberBanding = enableHorizontalRubberBanding; + + if (!isValid()) + return; + m_process->send(Messages::WebPage::SetEnableHorizontalRubberBanding(enableHorizontalRubberBanding), m_pageID); +} + +bool WebPageProxy::horizontalRubberBandingIsEnabled() const +{ + return m_enableHorizontalRubberBanding; +} void WebPageProxy::setBackgroundExtendsBeyondPage(bool backgroundExtendsBeyondPage) { @@ -1811,26 +2571,31 @@ void WebPageProxy::setGapBetweenPages(double gap) m_process->send(Messages::WebPage::SetGapBetweenPages(gap), m_pageID); } +void WebPageProxy::setPaginationLineGridEnabled(bool lineGridEnabled) +{ + if (lineGridEnabled == m_paginationLineGridEnabled) + return; + + m_paginationLineGridEnabled = lineGridEnabled; + + if (!isValid()) + return; + m_process->send(Messages::WebPage::SetPaginationLineGridEnabled(lineGridEnabled), m_pageID); +} + void WebPageProxy::pageScaleFactorDidChange(double scaleFactor) { m_pageScaleFactor = scaleFactor; } -void WebPageProxy::pageZoomFactorDidChange(double zoomFactor) +void WebPageProxy::pluginScaleFactorDidChange(double pluginScaleFactor) { - m_pageZoomFactor = zoomFactor; + m_pluginScaleFactor = pluginScaleFactor; } -void WebPageProxy::setMemoryCacheClientCallsEnabled(bool memoryCacheClientCallsEnabled) +void WebPageProxy::pluginZoomFactorDidChange(double pluginZoomFactor) { - if (!isValid()) - return; - - if (m_areMemoryCacheClientCallsEnabled == memoryCacheClientCallsEnabled) - return; - - m_areMemoryCacheClientCallsEnabled = memoryCacheClientCallsEnabled; - m_process->send(Messages::WebPage::SetMemoryCacheMessagesEnabled(memoryCacheClientCallsEnabled), m_pageID); + m_pluginZoomFactor = pluginZoomFactor; } void WebPageProxy::findStringMatches(const String& string, FindOptions options, unsigned maxMatchCount) @@ -1871,137 +2636,142 @@ void WebPageProxy::countStringMatches(const String& string, FindOptions options, m_process->send(Messages::WebPage::CountStringMatches(string, options, maxMatchCount), m_pageID); } -void WebPageProxy::runJavaScriptInMainFrame(const String& script, PassRefPtr<ScriptValueCallback> prpCallback) +void WebPageProxy::runJavaScriptInMainFrame(const String& script, std::function<void (API::SerializedScriptValue*, bool hadException, const ExceptionDetails&, CallbackBase::Error)> callbackFunction) { - RefPtr<ScriptValueCallback> callback = prpCallback; if (!isValid()) { - callback->invalidate(); + callbackFunction(nullptr, false, { }, CallbackBase::Error::Unknown); return; } - uint64_t callbackID = callback->callbackID(); - m_scriptValueCallbacks.set(callbackID, callback.get()); + uint64_t callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken()); m_process->send(Messages::WebPage::RunJavaScriptInMainFrame(script, callbackID), m_pageID); } -void WebPageProxy::getRenderTreeExternalRepresentation(PassRefPtr<StringCallback> prpCallback) +void WebPageProxy::getRenderTreeExternalRepresentation(std::function<void (const String&, CallbackBase::Error)> callbackFunction) { - RefPtr<StringCallback> callback = prpCallback; if (!isValid()) { - callback->invalidate(); + callbackFunction(String(), CallbackBase::Error::Unknown); return; } - uint64_t callbackID = callback->callbackID(); - m_stringCallbacks.set(callbackID, callback.get()); + uint64_t callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken()); m_process->send(Messages::WebPage::GetRenderTreeExternalRepresentation(callbackID), m_pageID); } -void WebPageProxy::getSourceForFrame(WebFrameProxy* frame, PassRefPtr<StringCallback> prpCallback) +void WebPageProxy::getSourceForFrame(WebFrameProxy* frame, std::function<void (const String&, CallbackBase::Error)> callbackFunction) { - RefPtr<StringCallback> callback = prpCallback; if (!isValid()) { - callback->invalidate(); + callbackFunction(String(), CallbackBase::Error::Unknown); return; } - uint64_t callbackID = callback->callbackID(); + uint64_t callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken()); m_loadDependentStringCallbackIDs.add(callbackID); - m_stringCallbacks.set(callbackID, callback.get()); m_process->send(Messages::WebPage::GetSourceForFrame(frame->frameID(), callbackID), m_pageID); } -void WebPageProxy::getContentsAsString(PassRefPtr<StringCallback> prpCallback) +void WebPageProxy::getContentsAsString(std::function<void (const String&, CallbackBase::Error)> callbackFunction) { - RefPtr<StringCallback> callback = prpCallback; if (!isValid()) { - callback->invalidate(); + callbackFunction(String(), CallbackBase::Error::Unknown); return; } - uint64_t callbackID = callback->callbackID(); + uint64_t callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken()); m_loadDependentStringCallbackIDs.add(callbackID); - m_stringCallbacks.set(callbackID, callback.get()); m_process->send(Messages::WebPage::GetContentsAsString(callbackID), m_pageID); } +void WebPageProxy::getBytecodeProfile(std::function<void (const String&, CallbackBase::Error)> callbackFunction) +{ + if (!isValid()) { + callbackFunction(String(), CallbackBase::Error::Unknown); + return; + } + + uint64_t callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken()); + m_loadDependentStringCallbackIDs.add(callbackID); + m_process->send(Messages::WebPage::GetBytecodeProfile(callbackID), m_pageID); +} + +void WebPageProxy::isWebProcessResponsive(std::function<void (bool isWebProcessResponsive)> callbackFunction) +{ + if (!isValid()) { + RunLoop::main().dispatch([callbackFunction] { + bool isWebProcessResponsive = true; + callbackFunction(isWebProcessResponsive); + }); + return; + } + + m_process->isResponsive(callbackFunction); +} + #if ENABLE(MHTML) -void WebPageProxy::getContentsAsMHTMLData(PassRefPtr<DataCallback> prpCallback, bool useBinaryEncoding) +void WebPageProxy::getContentsAsMHTMLData(std::function<void (API::Data*, CallbackBase::Error)> callbackFunction) { - RefPtr<DataCallback> callback = prpCallback; if (!isValid()) { - callback->invalidate(); + callbackFunction(nullptr, CallbackBase::Error::Unknown); return; } - uint64_t callbackID = callback->callbackID(); - m_dataCallbacks.set(callbackID, callback.get()); - m_process->send(Messages::WebPage::GetContentsAsMHTMLData(callbackID, useBinaryEncoding), m_pageID); + uint64_t callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken()); + m_process->send(Messages::WebPage::GetContentsAsMHTMLData(callbackID), m_pageID); } #endif -void WebPageProxy::getSelectionOrContentsAsString(PassRefPtr<StringCallback> prpCallback) +void WebPageProxy::getSelectionOrContentsAsString(std::function<void (const String&, CallbackBase::Error)> callbackFunction) { - RefPtr<StringCallback> callback = prpCallback; if (!isValid()) { - callback->invalidate(); + callbackFunction(String(), CallbackBase::Error::Unknown); return; } - uint64_t callbackID = callback->callbackID(); - m_stringCallbacks.set(callbackID, callback.get()); + uint64_t callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken()); m_process->send(Messages::WebPage::GetSelectionOrContentsAsString(callbackID), m_pageID); } -void WebPageProxy::getSelectionAsWebArchiveData(PassRefPtr<DataCallback> prpCallback) +void WebPageProxy::getSelectionAsWebArchiveData(std::function<void (API::Data*, CallbackBase::Error)> callbackFunction) { - RefPtr<DataCallback> callback = prpCallback; if (!isValid()) { - callback->invalidate(); + callbackFunction(nullptr, CallbackBase::Error::Unknown); return; } - uint64_t callbackID = callback->callbackID(); - m_dataCallbacks.set(callbackID, callback.get()); + uint64_t callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken()); m_process->send(Messages::WebPage::GetSelectionAsWebArchiveData(callbackID), m_pageID); } -void WebPageProxy::getMainResourceDataOfFrame(WebFrameProxy* frame, PassRefPtr<DataCallback> prpCallback) +void WebPageProxy::getMainResourceDataOfFrame(WebFrameProxy* frame, std::function<void (API::Data*, CallbackBase::Error)> callbackFunction) { - RefPtr<DataCallback> callback = prpCallback; - if (!isValid()) { - callback->invalidate(); + if (!isValid() || !frame) { + callbackFunction(nullptr, CallbackBase::Error::Unknown); return; } - uint64_t callbackID = callback->callbackID(); - m_dataCallbacks.set(callbackID, callback.get()); + uint64_t callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken()); m_process->send(Messages::WebPage::GetMainResourceDataOfFrame(frame->frameID(), callbackID), m_pageID); } -void WebPageProxy::getResourceDataFromFrame(WebFrameProxy* frame, API::URL* resourceURL, PassRefPtr<DataCallback> prpCallback) +void WebPageProxy::getResourceDataFromFrame(WebFrameProxy* frame, API::URL* resourceURL, std::function<void (API::Data*, CallbackBase::Error)> callbackFunction) { - RefPtr<DataCallback> callback = prpCallback; if (!isValid()) { - callback->invalidate(); + callbackFunction(nullptr, CallbackBase::Error::Unknown); return; } - uint64_t callbackID = callback->callbackID(); - m_dataCallbacks.set(callbackID, callback.get()); + uint64_t callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken()); m_process->send(Messages::WebPage::GetResourceDataFromFrame(frame->frameID(), resourceURL->string(), callbackID), m_pageID); } -void WebPageProxy::getWebArchiveOfFrame(WebFrameProxy* frame, PassRefPtr<DataCallback> prpCallback) +void WebPageProxy::getWebArchiveOfFrame(WebFrameProxy* frame, std::function<void (API::Data*, CallbackBase::Error)> callbackFunction) { - RefPtr<DataCallback> callback = prpCallback; if (!isValid()) { - callback->invalidate(); + callbackFunction(nullptr, CallbackBase::Error::Unknown); return; } - uint64_t callbackID = callback->callbackID(); - m_dataCallbacks.set(callbackID, callback.get()); + uint64_t callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken()); m_process->send(Messages::WebPage::GetWebArchiveOfFrame(frame->frameID(), callbackID), m_pageID); } @@ -2009,12 +2779,13 @@ void WebPageProxy::forceRepaint(PassRefPtr<VoidCallback> prpCallback) { RefPtr<VoidCallback> callback = prpCallback; if (!isValid()) { - callback->invalidate(); + // FIXME: If the page is invalid we should not call the callback. It'd be better to just return false from forceRepaint. + callback->invalidate(CallbackBase::Error::OwnerWasInvalidated); return; } uint64_t callbackID = callback->callbackID(); - m_voidCallbacks.set(callbackID, callback.get()); + m_callbacks.put(callback); m_drawingArea->waitForBackingStoreUpdateOnNextPaint(); m_process->send(Messages::WebPage::ForceRepaint(callbackID), m_pageID); } @@ -2025,11 +2796,11 @@ void WebPageProxy::preferencesDidChange() return; #if ENABLE(INSPECTOR_SERVER) - if (m_pageGroup->preferences()->developerExtrasEnabled()) + if (m_preferences->developerExtrasEnabled()) inspector()->enableRemoteInspection(); #endif - m_process->pagePreferencesChanged(this); + updateProccessSuppressionState(); m_pageClient.preferencesDidChange(); @@ -2038,11 +2809,13 @@ void WebPageProxy::preferencesDidChange() // even if nothing changed in UI process, so that overrides get removed. // Preferences need to be updated during synchronous printing to make "print backgrounds" preference work when toggled from a print dialog checkbox. - m_process->send(Messages::WebPage::PreferencesDidChange(pageGroup().preferences()->store()), m_pageID, m_isPerformingDOMPrintOperation ? IPC::DispatchMessageEvenWhenWaitingForSyncReply : 0); + m_process->send(Messages::WebPage::PreferencesDidChange(preferencesStore()), m_pageID, m_isPerformingDOMPrintOperation ? IPC::DispatchMessageEvenWhenWaitingForSyncReply : 0); } void WebPageProxy::didCreateMainFrame(uint64_t frameID) { + PageClientProtector protector(m_pageClient); + MESSAGE_CHECK(!m_mainFrame); MESSAGE_CHECK(m_process->canCreateFrame(frameID)); @@ -2054,6 +2827,8 @@ void WebPageProxy::didCreateMainFrame(uint64_t frameID) void WebPageProxy::didCreateSubframe(uint64_t frameID) { + PageClientProtector protector(m_pageClient); + MESSAGE_CHECK(m_mainFrame); MESSAGE_CHECK(m_process->canCreateFrame(frameID)); @@ -2070,69 +2845,95 @@ double WebPageProxy::estimatedProgress() const void WebPageProxy::didStartProgress() { + PageClientProtector protector(m_pageClient); + auto transaction = m_pageLoadState.transaction(); m_pageLoadState.didStartProgress(transaction); m_pageLoadState.commitChanges(); - m_loaderClient->didStartProgress(this); + m_loaderClient->didStartProgress(*this); } void WebPageProxy::didChangeProgress(double value) { + PageClientProtector protector(m_pageClient); + auto transaction = m_pageLoadState.transaction(); m_pageLoadState.didChangeProgress(transaction, value); m_pageLoadState.commitChanges(); - m_loaderClient->didChangeProgress(this); + m_loaderClient->didChangeProgress(*this); } void WebPageProxy::didFinishProgress() { + PageClientProtector protector(m_pageClient); + auto transaction = m_pageLoadState.transaction(); m_pageLoadState.didFinishProgress(transaction); m_pageLoadState.commitChanges(); - m_loaderClient->didFinishProgress(this); + m_loaderClient->didFinishProgress(*this); } -void WebPageProxy::didStartProvisionalLoadForFrame(uint64_t frameID, const String& url, const String& unreachableURL, IPC::MessageDecoder& decoder) +void WebPageProxy::setNetworkRequestsInProgress(bool networkRequestsInProgress) { auto transaction = m_pageLoadState.transaction(); + m_pageLoadState.setNetworkRequestsInProgress(transaction, networkRequestsInProgress); +} - m_pageLoadState.clearPendingAPIRequestURL(transaction); +void WebPageProxy::didDestroyNavigation(uint64_t navigationID) +{ + PageClientProtector protector(m_pageClient); - RefPtr<API::Object> userData; - WebContextUserMessageDecoder messageDecoder(userData, process()); - if (!decoder.decode(messageDecoder)) - return; + // FIXME: Message check the navigationID. + m_navigationState->didDestroyNavigation(navigationID); +} + +void WebPageProxy::didStartProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, const String& url, const String& unreachableURL, const UserData& userData) +{ + PageClientProtector protector(m_pageClient); + + auto transaction = m_pageLoadState.transaction(); + + m_pageLoadState.clearPendingAPIRequestURL(transaction); WebFrameProxy* frame = m_process->webFrame(frameID); MESSAGE_CHECK(frame); MESSAGE_CHECK_URL(url); - if (frame->isMainFrame()) { - recordNavigationSnapshot(); + // FIXME: We should message check that navigationID is not zero here, but it's currently zero for some navigations through the page cache. + RefPtr<API::Navigation> navigation; + if (frame->isMainFrame() && navigationID) + navigation = &navigationState().navigation(navigationID); + + if (frame->isMainFrame()) m_pageLoadState.didStartProvisionalLoad(transaction, url, unreachableURL); - } frame->setUnreachableURL(unreachableURL); frame->didStartProvisionalLoad(url); m_pageLoadState.commitChanges(); - m_loaderClient->didStartProvisionalLoadForFrame(this, frame, userData.get()); + if (m_navigationClient) { + if (frame->isMainFrame()) + m_navigationClient->didStartProvisionalNavigation(*this, navigation.get(), m_process->transformHandlesToObjects(userData.object()).get()); + } else + m_loaderClient->didStartProvisionalLoadForFrame(*this, *frame, navigation.get(), m_process->transformHandlesToObjects(userData.object()).get()); } -void WebPageProxy::didReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, const String& url, IPC::MessageDecoder& decoder) +void WebPageProxy::didReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, const String& url, const UserData& userData) { - RefPtr<API::Object> userData; - WebContextUserMessageDecoder messageDecoder(userData, process()); - if (!decoder.decode(messageDecoder)) - return; + PageClientProtector protector(m_pageClient); WebFrameProxy* frame = m_process->webFrame(frameID); MESSAGE_CHECK(frame); MESSAGE_CHECK_URL(url); + // FIXME: We should message check that navigationID is not zero here, but it's currently zero for some navigations through the page cache. + RefPtr<API::Navigation> navigation; + if (frame->isMainFrame() && navigationID) + navigation = &navigationState().navigation(navigationID); + auto transaction = m_pageLoadState.transaction(); if (frame->isMainFrame()) @@ -2141,19 +2942,44 @@ void WebPageProxy::didReceiveServerRedirectForProvisionalLoadForFrame(uint64_t f frame->didReceiveServerRedirectForProvisionalLoad(url); m_pageLoadState.commitChanges(); - m_loaderClient->didReceiveServerRedirectForProvisionalLoadForFrame(this, frame, userData.get()); + if (m_navigationClient) { + if (frame->isMainFrame()) + m_navigationClient->didReceiveServerRedirectForProvisionalNavigation(*this, navigation.get(), m_process->transformHandlesToObjects(userData.object()).get()); + } else + m_loaderClient->didReceiveServerRedirectForProvisionalLoadForFrame(*this, *frame, navigation.get(), m_process->transformHandlesToObjects(userData.object()).get()); } -void WebPageProxy::didFailProvisionalLoadForFrame(uint64_t frameID, const ResourceError& error, IPC::MessageDecoder& decoder) +void WebPageProxy::didChangeProvisionalURLForFrame(uint64_t frameID, uint64_t, const String& url) { - RefPtr<API::Object> userData; - WebContextUserMessageDecoder messageDecoder(userData, process()); - if (!decoder.decode(messageDecoder)) - return; + PageClientProtector protector(m_pageClient); + + WebFrameProxy* frame = m_process->webFrame(frameID); + MESSAGE_CHECK(frame); + MESSAGE_CHECK(frame->frameLoadState().state() == FrameLoadState::State::Provisional); + MESSAGE_CHECK_URL(url); + + auto transaction = m_pageLoadState.transaction(); + + // Internally, we handle this the same way we handle a server redirect. There are no client callbacks + // for this, but if this is the main frame, clients may observe a change to the page's URL. + if (frame->isMainFrame()) + m_pageLoadState.didReceiveServerRedirectForProvisionalLoad(transaction, url); + + frame->didReceiveServerRedirectForProvisionalLoad(url); +} + +void WebPageProxy::didFailProvisionalLoadForFrame(uint64_t frameID, const SecurityOriginData& frameSecurityOrigin, uint64_t navigationID, const String& provisionalURL, const ResourceError& error, const UserData& userData) +{ + PageClientProtector protector(m_pageClient); WebFrameProxy* frame = m_process->webFrame(frameID); MESSAGE_CHECK(frame); + // FIXME: We should message check that navigationID is not zero here, but it's currently zero for some navigations through the page cache. + RefPtr<API::Navigation> navigation; + if (frame->isMainFrame() && navigationID) + navigation = navigationState().takeNavigation(navigationID); + auto transaction = m_pageLoadState.transaction(); if (frame->isMainFrame()) @@ -2162,7 +2988,21 @@ void WebPageProxy::didFailProvisionalLoadForFrame(uint64_t frameID, const Resour frame->didFailProvisionalLoad(); m_pageLoadState.commitChanges(); - m_loaderClient->didFailProvisionalLoadWithErrorForFrame(this, frame, error, userData.get()); + + ASSERT(!m_failingProvisionalLoadURL); + m_failingProvisionalLoadURL = provisionalURL; + + if (m_navigationClient) { + if (frame->isMainFrame()) + m_navigationClient->didFailProvisionalNavigationWithError(*this, *frame, navigation.get(), error, m_process->transformHandlesToObjects(userData.object()).get()); + else { + // FIXME: Get the main frame's current navigation. + m_navigationClient->didFailProvisionalLoadInSubframeWithError(*this, *frame, frameSecurityOrigin, nullptr, error, m_process->transformHandlesToObjects(userData.object()).get()); + } + } else + m_loaderClient->didFailProvisionalLoadWithErrorForFrame(*this, *frame, navigation.get(), error, m_process->transformHandlesToObjects(userData.object()).get()); + + m_failingProvisionalLoadURL = { }; } void WebPageProxy::clearLoadDependentCallbacks() @@ -2172,138 +3012,212 @@ void WebPageProxy::clearLoadDependentCallbacks() m_loadDependentStringCallbackIDs.clear(); for (size_t i = 0; i < callbackIDsCopy.size(); ++i) { - RefPtr<StringCallback> callback = m_stringCallbacks.take(callbackIDsCopy[i]); + auto callback = m_callbacks.take<StringCallback>(callbackIDsCopy[i]); if (callback) callback->invalidate(); } } -void WebPageProxy::didCommitLoadForFrame(uint64_t frameID, const String& mimeType, uint32_t opaqueFrameLoadType, const WebCore::CertificateInfo& certificateInfo, IPC::MessageDecoder& decoder) +void WebPageProxy::didCommitLoadForFrame(uint64_t frameID, uint64_t navigationID, const String& mimeType, bool frameHasCustomContentProvider, bool pluginHandlesPageScaleGesture, uint32_t opaqueFrameLoadType, const WebCore::CertificateInfo& certificateInfo, bool containsPluginDocument, const UserData& userData) { - RefPtr<API::Object> userData; - WebContextUserMessageDecoder messageDecoder(userData, process()); - if (!decoder.decode(messageDecoder)) - return; + PageClientProtector protector(m_pageClient); WebFrameProxy* frame = m_process->webFrame(frameID); MESSAGE_CHECK(frame); - auto transaction = m_pageLoadState.transaction(); + // FIXME: We should message check that navigationID is not zero here, but it's currently zero for some navigations through the page cache. + RefPtr<API::Navigation> navigation; + if (frame->isMainFrame() && navigationID) + navigation = &navigationState().navigation(navigationID); +#if PLATFORM(IOS) if (frame->isMainFrame()) { - m_pageLoadState.didCommitLoad(transaction); - m_pageClient.didCommitLoadForMainFrame(); + m_hasReceivedLayerTreeTransactionAfterDidCommitLoad = false; + m_firstLayerTreeTransactionIdAfterDidCommitLoad = downcast<RemoteLayerTreeDrawingAreaProxy>(*drawingArea()).nextLayerTreeTransactionID(); } +#endif + + auto transaction = m_pageLoadState.transaction(); + bool markPageInsecure = m_treatsSHA1CertificatesAsInsecure && certificateInfo.containsNonRootSHA1SignedCertificate(); + Ref<WebCertificateInfo> webCertificateInfo = WebCertificateInfo::create(certificateInfo); + if (frame->isMainFrame()) { + m_pageLoadState.didCommitLoad(transaction, webCertificateInfo, markPageInsecure); + m_suppressNavigationSnapshotting = false; + } else if (markPageInsecure) + m_pageLoadState.didDisplayOrRunInsecureContent(transaction); #if USE(APPKIT) // FIXME (bug 59111): didCommitLoadForFrame comes too late when restoring a page from b/f cache, making us disable secure event mode in password fields. // FIXME: A load going on in one frame shouldn't affect text editing in other frames on the page. m_pageClient.resetSecureInputState(); - dismissCorrectionPanel(ReasonForDismissingAlternativeTextIgnored); - m_pageClient.dismissDictionaryLookupPanel(); + m_pageClient.dismissContentRelativeChildWindows(); #endif clearLoadDependentCallbacks(); - frame->didCommitLoad(mimeType, certificateInfo); + frame->didCommitLoad(mimeType, webCertificateInfo, containsPluginDocument); + + if (frame->isMainFrame()) { + m_mainFrameHasCustomContentProvider = frameHasCustomContentProvider; + + if (m_mainFrameHasCustomContentProvider) { + // Always assume that the main frame is pinned here, since the custom representation view will handle + // any wheel events and dispatch them to the WKView when necessary. + m_mainFrameIsPinnedToLeftSide = true; + m_mainFrameIsPinnedToRightSide = true; + m_mainFrameIsPinnedToTopSide = true; + m_mainFrameIsPinnedToBottomSide = true; + + m_uiClient->pinnedStateDidChange(*this); + } + m_pageClient.didCommitLoadForMainFrame(mimeType, frameHasCustomContentProvider); + } // Even if WebPage has the default pageScaleFactor (and therefore doesn't reset it), // WebPageProxy's cache of the value can get out of sync (e.g. in the case where a // plugin is handling page scaling itself) so we should reset it to the default // for standard main frame loads. - if (frame->isMainFrame() && static_cast<FrameLoadType>(opaqueFrameLoadType) == FrameLoadTypeStandard) - m_pageScaleFactor = 1; + if (frame->isMainFrame()) { + m_mainFramePluginHandlesPageScaleGesture = pluginHandlesPageScaleGesture; + + if (static_cast<FrameLoadType>(opaqueFrameLoadType) == FrameLoadType::Standard) { + m_pageScaleFactor = 1; + m_pluginScaleFactor = 1; + } + } m_pageLoadState.commitChanges(); - m_loaderClient->didCommitLoadForFrame(this, frame, userData.get()); + if (m_navigationClient) { + if (frame->isMainFrame()) + m_navigationClient->didCommitNavigation(*this, navigation.get(), m_process->transformHandlesToObjects(userData.object()).get()); + } else + m_loaderClient->didCommitLoadForFrame(*this, *frame, navigation.get(), m_process->transformHandlesToObjects(userData.object()).get()); } -void WebPageProxy::didFinishDocumentLoadForFrame(uint64_t frameID, IPC::MessageDecoder& decoder) +void WebPageProxy::didFinishDocumentLoadForFrame(uint64_t frameID, uint64_t navigationID, const UserData& userData) { - RefPtr<API::Object> userData; - WebContextUserMessageDecoder messageDecoder(userData, process()); - if (!decoder.decode(messageDecoder)) - return; + PageClientProtector protector(m_pageClient); WebFrameProxy* frame = m_process->webFrame(frameID); MESSAGE_CHECK(frame); - m_loaderClient->didFinishDocumentLoadForFrame(this, frame, userData.get()); + // FIXME: We should message check that navigationID is not zero here, but it's currently zero for some navigations through the page cache. + RefPtr<API::Navigation> navigation; + if (frame->isMainFrame() && navigationID) + navigation = &navigationState().navigation(navigationID); + + if (m_navigationClient) { + if (frame->isMainFrame()) + m_navigationClient->didFinishDocumentLoad(*this, navigation.get(), m_process->transformHandlesToObjects(userData.object()).get()); + } else + m_loaderClient->didFinishDocumentLoadForFrame(*this, *frame, navigation.get(), m_process->transformHandlesToObjects(userData.object()).get()); } -void WebPageProxy::didFinishLoadForFrame(uint64_t frameID, IPC::MessageDecoder& decoder) +void WebPageProxy::didFinishLoadForFrame(uint64_t frameID, uint64_t navigationID, const UserData& userData) { - RefPtr<API::Object> userData; - WebContextUserMessageDecoder messageDecoder(userData, process()); - if (!decoder.decode(messageDecoder)) - return; + PageClientProtector protector(m_pageClient); WebFrameProxy* frame = m_process->webFrame(frameID); MESSAGE_CHECK(frame); + // FIXME: We should message check that navigationID is not zero here, but it's currently zero for some navigations through the page cache. + RefPtr<API::Navigation> navigation; + if (frame->isMainFrame() && navigationID) + navigation = &navigationState().navigation(navigationID); + auto transaction = m_pageLoadState.transaction(); - if (frame->isMainFrame()) + bool isMainFrame = frame->isMainFrame(); + if (isMainFrame) m_pageLoadState.didFinishLoad(transaction); frame->didFinishLoad(); m_pageLoadState.commitChanges(); - m_loaderClient->didFinishLoadForFrame(this, frame, userData.get()); + if (m_navigationClient) { + if (isMainFrame) + m_navigationClient->didFinishNavigation(*this, navigation.get(), m_process->transformHandlesToObjects(userData.object()).get()); + } else + m_loaderClient->didFinishLoadForFrame(*this, *frame, navigation.get(), m_process->transformHandlesToObjects(userData.object()).get()); + + if (isMainFrame) + m_pageClient.didFinishLoadForMainFrame(); + + m_isLoadingAlternateHTMLStringForFailingProvisionalLoad = false; } -void WebPageProxy::didFailLoadForFrame(uint64_t frameID, const ResourceError& error, IPC::MessageDecoder& decoder) +void WebPageProxy::didFailLoadForFrame(uint64_t frameID, uint64_t navigationID, const ResourceError& error, const UserData& userData) { - RefPtr<API::Object> userData; - WebContextUserMessageDecoder messageDecoder(userData, process()); - if (!decoder.decode(messageDecoder)) - return; + PageClientProtector protector(m_pageClient); WebFrameProxy* frame = m_process->webFrame(frameID); MESSAGE_CHECK(frame); + // FIXME: We should message check that navigationID is not zero here, but it's currently zero for some navigations through the page cache. + RefPtr<API::Navigation> navigation; + if (frame->isMainFrame() && navigationID) + navigation = &navigationState().navigation(navigationID); + clearLoadDependentCallbacks(); auto transaction = m_pageLoadState.transaction(); - if (frame->isMainFrame()) + bool isMainFrame = frame->isMainFrame(); + + if (isMainFrame) m_pageLoadState.didFailLoad(transaction); frame->didFailLoad(); m_pageLoadState.commitChanges(); - m_loaderClient->didFailLoadWithErrorForFrame(this, frame, error, userData.get()); + if (m_navigationClient) { + if (frame->isMainFrame()) + m_navigationClient->didFailNavigationWithError(*this, *frame, navigation.get(), error, m_process->transformHandlesToObjects(userData.object()).get()); + } else + m_loaderClient->didFailLoadWithErrorForFrame(*this, *frame, navigation.get(), error, m_process->transformHandlesToObjects(userData.object()).get()); + + if (isMainFrame) + m_pageClient.didFailLoadForMainFrame(); } -void WebPageProxy::didSameDocumentNavigationForFrame(uint64_t frameID, uint32_t opaqueSameDocumentNavigationType, const String& url, IPC::MessageDecoder& decoder) +void WebPageProxy::didSameDocumentNavigationForFrame(uint64_t frameID, uint64_t navigationID, uint32_t opaqueSameDocumentNavigationType, const String& url, const UserData& userData) { - RefPtr<API::Object> userData; - WebContextUserMessageDecoder messageDecoder(userData, process()); - if (!decoder.decode(messageDecoder)) - return; + PageClientProtector protector(m_pageClient); WebFrameProxy* frame = m_process->webFrame(frameID); MESSAGE_CHECK(frame); MESSAGE_CHECK_URL(url); + // FIXME: We should message check that navigationID is not zero here, but it's currently zero for some navigations through the page cache. + RefPtr<API::Navigation> navigation; + if (frame->isMainFrame() && navigationID) + navigation = &navigationState().navigation(navigationID); + auto transaction = m_pageLoadState.transaction(); - if (frame->isMainFrame()) + bool isMainFrame = frame->isMainFrame(); + if (isMainFrame) m_pageLoadState.didSameDocumentNavigation(transaction, url); m_pageLoadState.clearPendingAPIRequestURL(transaction); frame->didSameDocumentNavigation(url); m_pageLoadState.commitChanges(); - m_loaderClient->didSameDocumentNavigationForFrame(this, frame, static_cast<SameDocumentNavigationType>(opaqueSameDocumentNavigationType), userData.get()); + + SameDocumentNavigationType navigationType = static_cast<SameDocumentNavigationType>(opaqueSameDocumentNavigationType); + if (m_navigationClient) { + if (isMainFrame) + m_navigationClient->didSameDocumentNavigation(*this, navigation.get(), navigationType, m_process->transformHandlesToObjects(userData.object()).get()); + } else + m_loaderClient->didSameDocumentNavigationForFrame(*this, *frame, navigation.get(), navigationType, m_process->transformHandlesToObjects(userData.object()).get()); + + if (isMainFrame) + m_pageClient.didSameDocumentNavigationForMainFrame(navigationType); } -void WebPageProxy::didReceiveTitleForFrame(uint64_t frameID, const String& title, IPC::MessageDecoder& decoder) +void WebPageProxy::didReceiveTitleForFrame(uint64_t frameID, const String& title, const UserData& userData) { - RefPtr<API::Object> userData; - WebContextUserMessageDecoder messageDecoder(userData, process()); - if (!decoder.decode(messageDecoder)) - return; + PageClientProtector protector(m_pageClient); WebFrameProxy* frame = m_process->webFrame(frameID); MESSAGE_CHECK(frame); @@ -2316,64 +3230,50 @@ void WebPageProxy::didReceiveTitleForFrame(uint64_t frameID, const String& title frame->didChangeTitle(title); m_pageLoadState.commitChanges(); - m_loaderClient->didReceiveTitleForFrame(this, title, frame, userData.get()); + m_loaderClient->didReceiveTitleForFrame(*this, title, *frame, m_process->transformHandlesToObjects(userData.object()).get()); } -void WebPageProxy::didFirstLayoutForFrame(uint64_t frameID, IPC::MessageDecoder& decoder) +void WebPageProxy::didFirstLayoutForFrame(uint64_t frameID, const UserData& userData) { - RefPtr<API::Object> userData; - WebContextUserMessageDecoder messageDecoder(userData, process()); - if (!decoder.decode(messageDecoder)) - return; + PageClientProtector protector(m_pageClient); WebFrameProxy* frame = m_process->webFrame(frameID); MESSAGE_CHECK(frame); - m_loaderClient->didFirstLayoutForFrame(this, frame, userData.get()); + m_loaderClient->didFirstLayoutForFrame(*this, *frame, m_process->transformHandlesToObjects(userData.object()).get()); } -void WebPageProxy::didFirstVisuallyNonEmptyLayoutForFrame(uint64_t frameID, IPC::MessageDecoder& decoder) +void WebPageProxy::didFirstVisuallyNonEmptyLayoutForFrame(uint64_t frameID, const UserData& userData) { - RefPtr<API::Object> userData; - WebContextUserMessageDecoder messageDecoder(userData, process()); - if (!decoder.decode(messageDecoder)) - return; + PageClientProtector protector(m_pageClient); WebFrameProxy* frame = m_process->webFrame(frameID); MESSAGE_CHECK(frame); - m_loaderClient->didFirstVisuallyNonEmptyLayoutForFrame(this, frame, userData.get()); + m_loaderClient->didFirstVisuallyNonEmptyLayoutForFrame(*this, *frame, m_process->transformHandlesToObjects(userData.object()).get()); + + if (frame->isMainFrame()) + m_pageClient.didFirstVisuallyNonEmptyLayoutForMainFrame(); } -void WebPageProxy::didLayout(uint32_t layoutMilestones, IPC::MessageDecoder& decoder) +void WebPageProxy::didLayoutForCustomContentProvider() { - RefPtr<API::Object> userData; - WebContextUserMessageDecoder messageDecoder(userData, process()); - if (!decoder.decode(messageDecoder)) - return; - - m_loaderClient->didLayout(this, static_cast<LayoutMilestones>(layoutMilestones), userData.get()); + didLayout(DidFirstLayout | DidFirstVisuallyNonEmptyLayout | DidHitRelevantRepaintedObjectsAreaThreshold); } -void WebPageProxy::didRemoveFrameFromHierarchy(uint64_t frameID, IPC::MessageDecoder& decoder) +void WebPageProxy::didLayout(uint32_t layoutMilestones) { - RefPtr<API::Object> userData; - WebContextUserMessageDecoder messageDecoder(userData, process()); - if (!decoder.decode(messageDecoder)) - return; + PageClientProtector protector(m_pageClient); - WebFrameProxy* frame = m_process->webFrame(frameID); - MESSAGE_CHECK(frame); - - m_loaderClient->didRemoveFrameFromHierarchy(this, frame, userData.get()); + if (m_navigationClient) + m_navigationClient->renderingProgressDidChange(*this, static_cast<LayoutMilestones>(layoutMilestones)); + else + m_loaderClient->didLayout(*this, static_cast<LayoutMilestones>(layoutMilestones)); } -void WebPageProxy::didDisplayInsecureContentForFrame(uint64_t frameID, IPC::MessageDecoder& decoder) +void WebPageProxy::didDisplayInsecureContentForFrame(uint64_t frameID, const UserData& userData) { - RefPtr<API::Object> userData; - WebContextUserMessageDecoder messageDecoder(userData, process()); - if (!decoder.decode(messageDecoder)) - return; + PageClientProtector protector(m_pageClient); WebFrameProxy* frame = m_process->webFrame(frameID); MESSAGE_CHECK(frame); @@ -2382,15 +3282,12 @@ void WebPageProxy::didDisplayInsecureContentForFrame(uint64_t frameID, IPC::Mess m_pageLoadState.didDisplayOrRunInsecureContent(transaction); m_pageLoadState.commitChanges(); - m_loaderClient->didDisplayInsecureContentForFrame(this, frame, userData.get()); + m_loaderClient->didDisplayInsecureContentForFrame(*this, *frame, m_process->transformHandlesToObjects(userData.object()).get()); } -void WebPageProxy::didRunInsecureContentForFrame(uint64_t frameID, IPC::MessageDecoder& decoder) +void WebPageProxy::didRunInsecureContentForFrame(uint64_t frameID, const UserData& userData) { - RefPtr<API::Object> userData; - WebContextUserMessageDecoder messageDecoder(userData, process()); - if (!decoder.decode(messageDecoder)) - return; + PageClientProtector protector(m_pageClient); WebFrameProxy* frame = m_process->webFrame(frameID); MESSAGE_CHECK(frame); @@ -2399,24 +3296,23 @@ void WebPageProxy::didRunInsecureContentForFrame(uint64_t frameID, IPC::MessageD m_pageLoadState.didDisplayOrRunInsecureContent(transaction); m_pageLoadState.commitChanges(); - m_loaderClient->didRunInsecureContentForFrame(this, frame, userData.get()); + m_loaderClient->didRunInsecureContentForFrame(*this, *frame, m_process->transformHandlesToObjects(userData.object()).get()); } -void WebPageProxy::didDetectXSSForFrame(uint64_t frameID, IPC::MessageDecoder& decoder) +void WebPageProxy::didDetectXSSForFrame(uint64_t frameID, const UserData& userData) { - RefPtr<API::Object> userData; - WebContextUserMessageDecoder messageDecoder(userData, process()); - if (!decoder.decode(messageDecoder)) - return; + PageClientProtector protector(m_pageClient); WebFrameProxy* frame = m_process->webFrame(frameID); MESSAGE_CHECK(frame); - m_loaderClient->didDetectXSSForFrame(this, frame, userData.get()); + m_loaderClient->didDetectXSSForFrame(*this, *frame, m_process->transformHandlesToObjects(userData.object()).get()); } void WebPageProxy::frameDidBecomeFrameSet(uint64_t frameID, bool value) { + PageClientProtector protector(m_pageClient); + WebFrameProxy* frame = m_process->webFrame(frameID); MESSAGE_CHECK(frame); @@ -2425,12 +3321,9 @@ void WebPageProxy::frameDidBecomeFrameSet(uint64_t frameID, bool value) m_frameSetLargestFrame = value ? m_mainFrame : 0; } -void WebPageProxy::decidePolicyForNavigationAction(uint64_t frameID, const NavigationActionData& navigationActionData, uint64_t originatingFrameID, const WebCore::ResourceRequest& originalRequest, const ResourceRequest& request, uint64_t listenerID, IPC::MessageDecoder& decoder, bool& receivedPolicyAction, uint64_t& policyAction, uint64_t& downloadID) +void WebPageProxy::decidePolicyForNavigationAction(uint64_t frameID, const SecurityOriginData& frameSecurityOrigin, uint64_t navigationID, const NavigationActionData& navigationActionData, uint64_t originatingFrameID, const SecurityOriginData& originatingFrameSecurityOrigin, const WebCore::ResourceRequest& originalRequest, const ResourceRequest& request, uint64_t listenerID, const UserData& userData, bool& receivedPolicyAction, uint64_t& newNavigationID, uint64_t& policyAction, DownloadID& downloadID) { - RefPtr<API::Object> userData; - WebContextUserMessageDecoder messageDecoder(userData, process()); - if (!decoder.decode(messageDecoder)) - return; + PageClientProtector protector(m_pageClient); auto transaction = m_pageLoadState.transaction(); @@ -2444,15 +3337,47 @@ void WebPageProxy::decidePolicyForNavigationAction(uint64_t frameID, const Navig WebFrameProxy* originatingFrame = m_process->webFrame(originatingFrameID); - RefPtr<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID); + Ref<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID); + if (!navigationID && frame->isMainFrame()) { + auto navigation = m_navigationState->createLoadRequestNavigation(request); + newNavigationID = navigation->navigationID(); + listener->setNavigation(WTFMove(navigation)); + } + +#if ENABLE(CONTENT_FILTERING) + if (frame->didHandleContentFilterUnblockNavigation(request)) { + receivedPolicyAction = true; + policyAction = PolicyIgnore; + return; + } +#endif ASSERT(!m_inDecidePolicyForNavigationAction); m_inDecidePolicyForNavigationAction = true; m_syncNavigationActionPolicyActionIsValid = false; - m_policyClient->decidePolicyForNavigationAction(this, frame, navigationActionData, originatingFrame, originalRequest, request, listener.get(), userData.get()); + if (m_navigationClient) { + RefPtr<API::FrameInfo> destinationFrameInfo; + RefPtr<API::FrameInfo> sourceFrameInfo; + + if (frame) + destinationFrameInfo = API::FrameInfo::create(*frame, frameSecurityOrigin.securityOrigin()); + + if (originatingFrame == frame) + sourceFrameInfo = destinationFrameInfo; + else if (originatingFrame) + sourceFrameInfo = API::FrameInfo::create(*originatingFrame, originatingFrameSecurityOrigin.securityOrigin()); + bool shouldOpenAppLinks = !m_shouldSuppressAppLinksInNextNavigationPolicyDecision && (!destinationFrameInfo || destinationFrameInfo->isMainFrame()) && !hostsAreEqual(URL(ParsedURLString, m_mainFrame->url()), request.url()); + + auto navigationAction = API::NavigationAction::create(navigationActionData, sourceFrameInfo.get(), destinationFrameInfo.get(), request, originalRequest.url(), shouldOpenAppLinks); + + m_navigationClient->decidePolicyForNavigationAction(*this, navigationAction.get(), WTFMove(listener), m_process->transformHandlesToObjects(userData.object()).get()); + } else + m_policyClient->decidePolicyForNavigationAction(*this, frame, navigationActionData, originatingFrame, originalRequest, request, WTFMove(listener), m_process->transformHandlesToObjects(userData.object()).get()); + + m_shouldSuppressAppLinksInNextNavigationPolicyDecision = false; m_inDecidePolicyForNavigationAction = false; // Check if we received a policy decision already. If we did, we can just pass it back. @@ -2463,48 +3388,59 @@ void WebPageProxy::decidePolicyForNavigationAction(uint64_t frameID, const Navig } } -void WebPageProxy::decidePolicyForNewWindowAction(uint64_t frameID, const NavigationActionData& navigationActionData, const ResourceRequest& request, const String& frameName, uint64_t listenerID, IPC::MessageDecoder& decoder) +void WebPageProxy::decidePolicyForNewWindowAction(uint64_t frameID, const SecurityOriginData& frameSecurityOrigin, const NavigationActionData& navigationActionData, const ResourceRequest& request, const String& frameName, uint64_t listenerID, const UserData& userData) { - RefPtr<API::Object> userData; - WebContextUserMessageDecoder messageDecoder(userData, process()); - if (!decoder.decode(messageDecoder)) - return; + PageClientProtector protector(m_pageClient); WebFrameProxy* frame = m_process->webFrame(frameID); MESSAGE_CHECK(frame); MESSAGE_CHECK_URL(request.url()); - RefPtr<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID); + Ref<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID); - m_policyClient->decidePolicyForNewWindowAction(this, frame, navigationActionData.navigationType, navigationActionData.modifiers, navigationActionData.mouseButton, request, frameName, listener.get(), userData.get()); + if (m_navigationClient) { + RefPtr<API::FrameInfo> sourceFrameInfo; + if (frame) + sourceFrameInfo = API::FrameInfo::create(*frame, frameSecurityOrigin.securityOrigin()); + + bool shouldOpenAppLinks = !hostsAreEqual(URL(ParsedURLString, m_mainFrame->url()), request.url()); + auto navigationAction = API::NavigationAction::create(navigationActionData, sourceFrameInfo.get(), nullptr, request, request.url(), shouldOpenAppLinks); + + m_navigationClient->decidePolicyForNavigationAction(*this, navigationAction.get(), WTFMove(listener), m_process->transformHandlesToObjects(userData.object()).get()); + + } else + m_policyClient->decidePolicyForNewWindowAction(*this, *frame, navigationActionData, request, frameName, WTFMove(listener), m_process->transformHandlesToObjects(userData.object()).get()); } -void WebPageProxy::decidePolicyForResponse(uint64_t frameID, const ResourceResponse& response, const ResourceRequest& request, bool canShowMIMEType, uint64_t listenerID, IPC::MessageDecoder& decoder) +void WebPageProxy::decidePolicyForResponse(uint64_t frameID, const SecurityOriginData& frameSecurityOrigin, const ResourceResponse& response, const ResourceRequest& request, bool canShowMIMEType, uint64_t listenerID, const UserData& userData) { - RefPtr<API::Object> userData; - WebContextUserMessageDecoder messageDecoder(userData, process()); - if (!decoder.decode(messageDecoder)) - return; + PageClientProtector protector(m_pageClient); WebFrameProxy* frame = m_process->webFrame(frameID); MESSAGE_CHECK(frame); MESSAGE_CHECK_URL(request.url()); MESSAGE_CHECK_URL(response.url()); - RefPtr<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID); + Ref<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID); - m_policyClient->decidePolicyForResponse(this, frame, response, request, canShowMIMEType, listener.get(), userData.get()); + if (m_navigationClient) { + auto navigationResponse = API::NavigationResponse::create(API::FrameInfo::create(*frame, frameSecurityOrigin.securityOrigin()).get(), request, response, canShowMIMEType); + m_navigationClient->decidePolicyForNavigationResponse(*this, navigationResponse.get(), WTFMove(listener), m_process->transformHandlesToObjects(userData.object()).get()); + } else + m_policyClient->decidePolicyForResponse(*this, *frame, response, request, canShowMIMEType, WTFMove(listener), m_process->transformHandlesToObjects(userData.object()).get()); } -void WebPageProxy::decidePolicyForResponseSync(uint64_t frameID, const ResourceResponse& response, const ResourceRequest& request, bool canShowMIMEType, uint64_t listenerID, IPC::MessageDecoder& decoder, bool& receivedPolicyAction, uint64_t& policyAction, uint64_t& downloadID) +void WebPageProxy::decidePolicyForResponseSync(uint64_t frameID, const SecurityOriginData& frameSecurityOrigin, const ResourceResponse& response, const ResourceRequest& request, bool canShowMIMEType, uint64_t listenerID, const UserData& userData, bool& receivedPolicyAction, uint64_t& policyAction, DownloadID& downloadID) { + PageClientProtector protector(m_pageClient); + ASSERT(!m_inDecidePolicyForResponseSync); m_inDecidePolicyForResponseSync = true; m_decidePolicyForResponseRequest = &request; m_syncMimeTypePolicyActionIsValid = false; - decidePolicyForResponse(frameID, response, request, canShowMIMEType, listenerID, decoder); + decidePolicyForResponse(frameID, frameSecurityOrigin, response, request, canShowMIMEType, listenerID, userData); m_inDecidePolicyForResponseSync = false; m_decidePolicyForResponseRequest = 0; @@ -2517,44 +3453,118 @@ void WebPageProxy::decidePolicyForResponseSync(uint64_t frameID, const ResourceR } } -void WebPageProxy::unableToImplementPolicy(uint64_t frameID, const ResourceError& error, IPC::MessageDecoder& decoder) +void WebPageProxy::unableToImplementPolicy(uint64_t frameID, const ResourceError& error, const UserData& userData) { - RefPtr<API::Object> userData; - WebContextUserMessageDecoder messageDecoder(userData, process()); - if (!decoder.decode(messageDecoder)) - return; - + PageClientProtector protector(m_pageClient); + WebFrameProxy* frame = m_process->webFrame(frameID); MESSAGE_CHECK(frame); - m_policyClient->unableToImplementPolicy(this, frame, error, userData.get()); + m_policyClient->unableToImplementPolicy(*this, *frame, error, m_process->transformHandlesToObjects(userData.object()).get()); } // FormClient -void WebPageProxy::willSubmitForm(uint64_t frameID, uint64_t sourceFrameID, const Vector<std::pair<String, String>>& textFieldValues, uint64_t listenerID, IPC::MessageDecoder& decoder) +void WebPageProxy::willSubmitForm(uint64_t frameID, uint64_t sourceFrameID, const Vector<std::pair<String, String>>& textFieldValues, uint64_t listenerID, const UserData& userData) { - RefPtr<API::Object> userData; - WebContextUserMessageDecoder messageDecoder(userData, process()); - if (!decoder.decode(messageDecoder)) - return; - WebFrameProxy* frame = m_process->webFrame(frameID); MESSAGE_CHECK(frame); WebFrameProxy* sourceFrame = m_process->webFrame(sourceFrameID); MESSAGE_CHECK(sourceFrame); - RefPtr<WebFormSubmissionListenerProxy> listener = frame->setUpFormSubmissionListenerProxy(listenerID); - if (!m_formClient.willSubmitForm(this, frame, sourceFrame, textFieldValues, userData.get(), listener.get())) - listener->continueSubmission(); + Ref<WebFormSubmissionListenerProxy> listener = frame->setUpFormSubmissionListenerProxy(listenerID); + m_formClient->willSubmitForm(*this, *frame, *sourceFrame, textFieldValues, m_process->transformHandlesToObjects(userData.object()).get(), listener.get()); +} + +void WebPageProxy::didNavigateWithNavigationData(const WebNavigationDataStore& store, uint64_t frameID) +{ + PageClientProtector protector(m_pageClient); + + WebFrameProxy* frame = m_process->webFrame(frameID); + MESSAGE_CHECK(frame); + MESSAGE_CHECK(frame->page() == this); + + if (m_historyClient) { + if (frame->isMainFrame()) + m_historyClient->didNavigateWithNavigationData(*this, store); + } else + m_loaderClient->didNavigateWithNavigationData(*this, store, *frame); + process().processPool().historyClient().didNavigateWithNavigationData(process().processPool(), *this, store, *frame); +} + +void WebPageProxy::didPerformClientRedirect(const String& sourceURLString, const String& destinationURLString, uint64_t frameID) +{ + PageClientProtector protector(m_pageClient); + + if (sourceURLString.isEmpty() || destinationURLString.isEmpty()) + return; + + WebFrameProxy* frame = m_process->webFrame(frameID); + MESSAGE_CHECK(frame); + MESSAGE_CHECK(frame->page() == this); + + MESSAGE_CHECK_URL(sourceURLString); + MESSAGE_CHECK_URL(destinationURLString); + + if (m_historyClient) { + if (frame->isMainFrame()) + m_historyClient->didPerformClientRedirect(*this, sourceURLString, destinationURLString); + } else + m_loaderClient->didPerformClientRedirect(*this, sourceURLString, destinationURLString, *frame); + process().processPool().historyClient().didPerformClientRedirect(process().processPool(), *this, sourceURLString, destinationURLString, *frame); +} + +void WebPageProxy::didPerformServerRedirect(const String& sourceURLString, const String& destinationURLString, uint64_t frameID) +{ + PageClientProtector protector(m_pageClient); + + if (sourceURLString.isEmpty() || destinationURLString.isEmpty()) + return; + + WebFrameProxy* frame = m_process->webFrame(frameID); + MESSAGE_CHECK(frame); + MESSAGE_CHECK(frame->page() == this); + + MESSAGE_CHECK_URL(sourceURLString); + MESSAGE_CHECK_URL(destinationURLString); + + if (m_historyClient) { + if (frame->isMainFrame()) + m_historyClient->didPerformServerRedirect(*this, sourceURLString, destinationURLString); + } else + m_loaderClient->didPerformServerRedirect(*this, sourceURLString, destinationURLString, *frame); + process().processPool().historyClient().didPerformServerRedirect(process().processPool(), *this, sourceURLString, destinationURLString, *frame); +} + +void WebPageProxy::didUpdateHistoryTitle(const String& title, const String& url, uint64_t frameID) +{ + PageClientProtector protector(m_pageClient); + + WebFrameProxy* frame = m_process->webFrame(frameID); + MESSAGE_CHECK(frame); + MESSAGE_CHECK(frame->page() == this); + + MESSAGE_CHECK_URL(url); + + if (m_historyClient) { + if (frame->isMainFrame()) + m_historyClient->didUpdateHistoryTitle(*this, title, url); + } else + m_loaderClient->didUpdateHistoryTitle(*this, title, url, *frame); + process().processPool().historyClient().didUpdateHistoryTitle(process().processPool(), *this, title, url, *frame); } // UIClient -void WebPageProxy::createNewPage(const ResourceRequest& request, const WindowFeatures& windowFeatures, uint32_t opaqueModifiers, int32_t opaqueMouseButton, uint64_t& newPageID, WebPageCreationParameters& newPageParameters) +void WebPageProxy::createNewPage(uint64_t frameID, const SecurityOriginData& securityOriginData, const ResourceRequest& request, const WindowFeatures& windowFeatures, const NavigationActionData& navigationActionData, uint64_t& newPageID, WebPageCreationParameters& newPageParameters) { - RefPtr<WebPageProxy> newPage = m_uiClient.createNewPage(this, request, windowFeatures, static_cast<WebEvent::Modifiers>(opaqueModifiers), static_cast<WebMouseEvent::Button>(opaqueMouseButton)); + WebFrameProxy* frame = m_process->webFrame(frameID); + MESSAGE_CHECK(frame); + + auto mainFrameURL = m_mainFrame->url(); + + RefPtr<WebPageProxy> newPage = m_uiClient->createNewPage(this, frame, securityOriginData, request, windowFeatures, navigationActionData); if (!newPage) { newPageID = 0; return; @@ -2562,93 +3572,103 @@ void WebPageProxy::createNewPage(const ResourceRequest& request, const WindowFea newPageID = newPage->pageID(); newPageParameters = newPage->creationParameters(); - process().context().storageManager().cloneSessionStorageNamespace(m_pageID, newPage->pageID()); + + WebsiteDataStore::cloneSessionData(*this, *newPage); + newPage->m_shouldSuppressAppLinksInNextNavigationPolicyDecision = hostsAreEqual(URL(ParsedURLString, mainFrameURL), request.url()); } void WebPageProxy::showPage() { - m_uiClient.showPage(this); + m_uiClient->showPage(this); +} + +void WebPageProxy::fullscreenMayReturnToInline() +{ + m_uiClient->fullscreenMayReturnToInline(this); +} + +void WebPageProxy::didEnterFullscreen() +{ + m_uiClient->didEnterFullscreen(this); +} + +void WebPageProxy::didExitFullscreen() +{ + m_uiClient->didExitFullscreen(this); } void WebPageProxy::closePage(bool stopResponsivenessTimer) { if (stopResponsivenessTimer) - m_process->responsivenessTimer()->stop(); + m_process->responsivenessTimer().stop(); m_pageClient.clearAllEditCommands(); - m_uiClient.close(this); + m_uiClient->close(this); } -void WebPageProxy::runJavaScriptAlert(uint64_t frameID, const String& message) +void WebPageProxy::runJavaScriptAlert(uint64_t frameID, const SecurityOriginData& securityOrigin, const String& message, RefPtr<Messages::WebPageProxy::RunJavaScriptAlert::DelayedReply> reply) { WebFrameProxy* frame = m_process->webFrame(frameID); MESSAGE_CHECK(frame); // Since runJavaScriptAlert() can spin a nested run loop we need to turn off the responsiveness timer. - m_process->responsivenessTimer()->stop(); + m_process->responsivenessTimer().stop(); - m_uiClient.runJavaScriptAlert(this, message, frame); + m_uiClient->runJavaScriptAlert(this, message, frame, securityOrigin, [reply]{ reply->send(); }); } -void WebPageProxy::runJavaScriptConfirm(uint64_t frameID, const String& message, bool& result) +void WebPageProxy::runJavaScriptConfirm(uint64_t frameID, const SecurityOriginData& securityOrigin, const String& message, RefPtr<Messages::WebPageProxy::RunJavaScriptConfirm::DelayedReply> reply) { WebFrameProxy* frame = m_process->webFrame(frameID); MESSAGE_CHECK(frame); // Since runJavaScriptConfirm() can spin a nested run loop we need to turn off the responsiveness timer. - m_process->responsivenessTimer()->stop(); + m_process->responsivenessTimer().stop(); - result = m_uiClient.runJavaScriptConfirm(this, message, frame); + m_uiClient->runJavaScriptConfirm(this, message, frame, securityOrigin, [reply](bool result) { reply->send(result); }); } -void WebPageProxy::runJavaScriptPrompt(uint64_t frameID, const String& message, const String& defaultValue, String& result) +void WebPageProxy::runJavaScriptPrompt(uint64_t frameID, const SecurityOriginData& securityOrigin, const String& message, const String& defaultValue, RefPtr<Messages::WebPageProxy::RunJavaScriptPrompt::DelayedReply> reply) { WebFrameProxy* frame = m_process->webFrame(frameID); MESSAGE_CHECK(frame); // Since runJavaScriptPrompt() can spin a nested run loop we need to turn off the responsiveness timer. - m_process->responsivenessTimer()->stop(); - - result = m_uiClient.runJavaScriptPrompt(this, message, defaultValue, frame); -} - -void WebPageProxy::shouldInterruptJavaScript(bool& result) -{ - // Since shouldInterruptJavaScript() can spin a nested run loop we need to turn off the responsiveness timer. - m_process->responsivenessTimer()->stop(); + m_process->responsivenessTimer().stop(); - result = m_uiClient.shouldInterruptJavaScript(this); + m_uiClient->runJavaScriptPrompt(this, message, defaultValue, frame, securityOrigin, [reply](const String& result) { reply->send(result); }); } void WebPageProxy::setStatusText(const String& text) { - m_uiClient.setStatusText(this, text); + m_uiClient->setStatusText(this, text); } -void WebPageProxy::mouseDidMoveOverElement(const WebHitTestResult::Data& hitTestResultData, uint32_t opaqueModifiers, IPC::MessageDecoder& decoder) +void WebPageProxy::mouseDidMoveOverElement(const WebHitTestResultData& hitTestResultData, uint32_t opaqueModifiers, const UserData& userData) { - RefPtr<API::Object> userData; - WebContextUserMessageDecoder messageDecoder(userData, process()); - if (!decoder.decode(messageDecoder)) - return; + m_lastMouseMoveHitTestResult = API::HitTestResult::create(hitTestResultData); WebEvent::Modifiers modifiers = static_cast<WebEvent::Modifiers>(opaqueModifiers); - m_uiClient.mouseDidMoveOverElement(this, hitTestResultData, modifiers, userData.get()); + m_uiClient->mouseDidMoveOverElement(this, hitTestResultData, modifiers, m_process->transformHandlesToObjects(userData.object()).get()); } -void WebPageProxy::connectionWillOpen(IPC::Connection* connection) +void WebPageProxy::connectionWillOpen(IPC::Connection& connection) { - ASSERT(connection == m_process->connection()); + ASSERT(&connection == m_process->connection()); - m_process->context().storageManager().setAllowedSessionStorageNamespaceConnection(m_pageID, connection); + m_webProcessLifetimeTracker.connectionWillOpen(connection); } -void WebPageProxy::connectionWillClose(IPC::Connection* connection) +void WebPageProxy::webProcessWillShutDown() { - ASSERT_UNUSED(connection, connection == m_process->connection()); + m_webProcessLifetimeTracker.webProcessWillShutDown(); +} - m_process->context().storageManager().setAllowedSessionStorageNamespaceConnection(m_pageID, 0); +void WebPageProxy::processDidFinishLaunching() +{ + ASSERT(m_process->state() == WebProcessProxy::State::Running); + finishInitializingWebPageAfterProcessLaunch(); } #if ENABLE(NETSCAPE_PLUGIN_API) @@ -2659,9 +3679,9 @@ void WebPageProxy::unavailablePluginButtonClicked(uint32_t opaquePluginUnavailab MESSAGE_CHECK_URL(frameURLString); MESSAGE_CHECK_URL(pageURLString); - RefPtr<ImmutableDictionary> pluginInformation; + RefPtr<API::Dictionary> pluginInformation; String newMimeType = mimeType; - PluginModuleInfo plugin = m_process->context().pluginInfoStore().findPlugin(newMimeType, URL(URL(), pluginURLString)); + PluginModuleInfo plugin = m_process->processPool().pluginInfoStore().findPlugin(newMimeType, URL(URL(), pluginURLString)); pluginInformation = createPluginInformationDictionary(plugin, frameURLString, mimeType, pageURLString, pluginspageAttributeURLString, pluginURLString); WKPluginUnavailabilityReason pluginUnavailabilityReason = kWKPluginUnavailabilityReasonPluginMissing; @@ -2679,89 +3699,106 @@ void WebPageProxy::unavailablePluginButtonClicked(uint32_t opaquePluginUnavailab ASSERT_NOT_REACHED(); } - m_uiClient.unavailablePluginButtonClicked(this, pluginUnavailabilityReason, pluginInformation.get()); + m_uiClient->unavailablePluginButtonClicked(this, pluginUnavailabilityReason, pluginInformation.get()); } #endif // ENABLE(NETSCAPE_PLUGIN_API) #if ENABLE(WEBGL) void WebPageProxy::webGLPolicyForURL(const String& url, uint32_t& loadPolicy) { - loadPolicy = static_cast<uint32_t>(m_loaderClient->webGLLoadPolicy(this, url)); + loadPolicy = static_cast<uint32_t>(m_loaderClient->webGLLoadPolicy(*this, url)); +} + +void WebPageProxy::resolveWebGLPolicyForURL(const String& url, uint32_t& loadPolicy) +{ + loadPolicy = static_cast<uint32_t>(m_loaderClient->resolveWebGLLoadPolicy(*this, url)); } #endif // ENABLE(WEBGL) void WebPageProxy::setToolbarsAreVisible(bool toolbarsAreVisible) { - m_uiClient.setToolbarsAreVisible(this, toolbarsAreVisible); + m_uiClient->setToolbarsAreVisible(this, toolbarsAreVisible); } void WebPageProxy::getToolbarsAreVisible(bool& toolbarsAreVisible) { - toolbarsAreVisible = m_uiClient.toolbarsAreVisible(this); + toolbarsAreVisible = m_uiClient->toolbarsAreVisible(this); } void WebPageProxy::setMenuBarIsVisible(bool menuBarIsVisible) { - m_uiClient.setMenuBarIsVisible(this, menuBarIsVisible); + m_uiClient->setMenuBarIsVisible(this, menuBarIsVisible); } void WebPageProxy::getMenuBarIsVisible(bool& menuBarIsVisible) { - menuBarIsVisible = m_uiClient.menuBarIsVisible(this); + menuBarIsVisible = m_uiClient->menuBarIsVisible(this); } void WebPageProxy::setStatusBarIsVisible(bool statusBarIsVisible) { - m_uiClient.setStatusBarIsVisible(this, statusBarIsVisible); + m_uiClient->setStatusBarIsVisible(this, statusBarIsVisible); } void WebPageProxy::getStatusBarIsVisible(bool& statusBarIsVisible) { - statusBarIsVisible = m_uiClient.statusBarIsVisible(this); + statusBarIsVisible = m_uiClient->statusBarIsVisible(this); } void WebPageProxy::setIsResizable(bool isResizable) { - m_uiClient.setIsResizable(this, isResizable); + m_uiClient->setIsResizable(this, isResizable); } void WebPageProxy::getIsResizable(bool& isResizable) { - isResizable = m_uiClient.isResizable(this); + isResizable = m_uiClient->isResizable(this); } void WebPageProxy::setWindowFrame(const FloatRect& newWindowFrame) { - m_uiClient.setWindowFrame(this, m_pageClient.convertToDeviceSpace(newWindowFrame)); + m_uiClient->setWindowFrame(this, m_pageClient.convertToDeviceSpace(newWindowFrame)); } void WebPageProxy::getWindowFrame(FloatRect& newWindowFrame) { - newWindowFrame = m_pageClient.convertToUserSpace(m_uiClient.windowFrame(this)); + newWindowFrame = m_pageClient.convertToUserSpace(m_uiClient->windowFrame(this)); } -void WebPageProxy::screenToWindow(const IntPoint& screenPoint, IntPoint& windowPoint) +void WebPageProxy::screenToRootView(const IntPoint& screenPoint, IntPoint& windowPoint) { - windowPoint = m_pageClient.screenToWindow(screenPoint); + windowPoint = m_pageClient.screenToRootView(screenPoint); } -void WebPageProxy::windowToScreen(const IntRect& viewRect, IntRect& result) +void WebPageProxy::rootViewToScreen(const IntRect& viewRect, IntRect& result) { - result = m_pageClient.windowToScreen(viewRect); + result = m_pageClient.rootViewToScreen(viewRect); } -void WebPageProxy::runBeforeUnloadConfirmPanel(const String& message, uint64_t frameID, bool& shouldClose) +#if PLATFORM(IOS) +void WebPageProxy::accessibilityScreenToRootView(const IntPoint& screenPoint, IntPoint& windowPoint) +{ + windowPoint = m_pageClient.accessibilityScreenToRootView(screenPoint); +} + +void WebPageProxy::rootViewToAccessibilityScreen(const IntRect& viewRect, IntRect& result) +{ + result = m_pageClient.rootViewToAccessibilityScreen(viewRect); +} +#endif + +void WebPageProxy::runBeforeUnloadConfirmPanel(const String& message, uint64_t frameID, RefPtr<Messages::WebPageProxy::RunBeforeUnloadConfirmPanel::DelayedReply> reply) { WebFrameProxy* frame = m_process->webFrame(frameID); MESSAGE_CHECK(frame); // Since runBeforeUnloadConfirmPanel() can spin a nested run loop we need to turn off the responsiveness timer. - m_process->responsivenessTimer()->stop(); + m_process->responsivenessTimer().stop(); - shouldClose = m_uiClient.runBeforeUnloadConfirmPanel(this, message, frame); + m_uiClient->runBeforeUnloadConfirmPanel(this, message, frame, [reply](bool result) { reply->send(result); }); } -#if USE(TILED_BACKING_STORE) +#if USE(COORDINATED_GRAPHICS_MULTIPROCESS) void WebPageProxy::pageDidRequestScroll(const IntPoint& point) { m_pageClient.pageDidRequestScroll(point); @@ -2777,6 +3814,13 @@ void WebPageProxy::didRenderFrame(const WebCore::IntSize& contentsSize, const We m_pageClient.didRenderFrame(contentsSize, coveredRect); } +void WebPageProxy::commitPageTransitionViewport() +{ + if (!isValid()) + return; + + process().send(Messages::WebPage::CommitPageTransitionViewport(), m_pageID); +} #endif void WebPageProxy::didChangeViewportProperties(const ViewportAttributes& attr) @@ -2786,17 +3830,14 @@ void WebPageProxy::didChangeViewportProperties(const ViewportAttributes& attr) void WebPageProxy::pageDidScroll() { - m_uiClient.pageDidScroll(this); -#if !PLATFORM(IOS) && PLATFORM(MAC) - dismissCorrectionPanel(ReasonForDismissingAlternativeTextIgnored); -#endif + m_uiClient->pageDidScroll(this); } void WebPageProxy::runOpenPanel(uint64_t frameID, const FileChooserSettings& settings) { if (m_openPanelResultListener) { m_openPanelResultListener->invalidate(); - m_openPanelResultListener = 0; + m_openPanelResultListener = nullptr; } WebFrameProxy* frame = m_process->webFrame(frameID); @@ -2806,10 +3847,12 @@ void WebPageProxy::runOpenPanel(uint64_t frameID, const FileChooserSettings& set m_openPanelResultListener = WebOpenPanelResultListenerProxy::create(this); // Since runOpenPanel() can spin a nested run loop we need to turn off the responsiveness timer. - m_process->responsivenessTimer()->stop(); + m_process->responsivenessTimer().stop(); - if (!m_uiClient.runOpenPanel(this, frame, parameters.get(), m_openPanelResultListener.get())) - didCancelForOpenPanel(); + if (!m_uiClient->runOpenPanel(this, frame, parameters.get(), m_openPanelResultListener.get())) { + if (!m_pageClient.handleRunOpenPanel(this, frame, parameters.get(), m_openPanelResultListener.get())) + didCancelForOpenPanel(); + } } void WebPageProxy::printFrame(uint64_t frameID) @@ -2820,7 +3863,7 @@ void WebPageProxy::printFrame(uint64_t frameID) WebFrameProxy* frame = m_process->webFrame(frameID); MESSAGE_CHECK(frame); - m_uiClient.printFrame(this, frame); + m_uiClient->printFrame(this, frame); endPrinting(); // Send a message synchronously while m_isPerformingDOMPrintOperation is still true. m_isPerformingDOMPrintOperation = false; @@ -2844,6 +3887,37 @@ void WebPageProxy::setMediaVolume(float volume) m_process->send(Messages::WebPage::SetMediaVolume(volume), m_pageID); } +void WebPageProxy::setMuted(bool muted) +{ + if (m_muted == muted) + return; + + m_muted = muted; + + if (!isValid()) + return; + + m_process->send(Messages::WebPage::SetMuted(muted), m_pageID); +} + +#if ENABLE(MEDIA_SESSION) +void WebPageProxy::handleMediaEvent(MediaEventType eventType) +{ + if (!isValid()) + return; + + m_process->send(Messages::WebPage::HandleMediaEvent(eventType), m_pageID); +} + +void WebPageProxy::setVolumeOfMediaElement(double volume, uint64_t elementID) +{ + if (!isValid()) + return; + + m_process->send(Messages::WebPage::SetVolumeOfMediaElement(volume, elementID), m_pageID); +} +#endif + void WebPageProxy::setMayStartMediaWhenInWindow(bool mayStartMedia) { if (mayStartMedia == m_mayStartMediaWhenInWindow) @@ -2857,26 +3931,15 @@ void WebPageProxy::setMayStartMediaWhenInWindow(bool mayStartMedia) process().send(Messages::WebPage::SetMayStartMediaWhenInWindow(mayStartMedia), m_pageID); } -#if PLATFORM(EFL) || PLATFORM(GTK) void WebPageProxy::handleDownloadRequest(DownloadProxy* download) { m_pageClient.handleDownloadRequest(download); } -#endif // PLATFORM(EFL) || PLATFORM(GTK) -#if PLATFORM(EFL) || PLATFORM(IOS) void WebPageProxy::didChangeContentSize(const IntSize& size) { m_pageClient.didChangeContentSize(size); } -#endif - -#if ENABLE(TOUCH_EVENTS) -void WebPageProxy::needTouchEvents(bool needTouchEvents) -{ - m_needTouchEvents = needTouchEvents; -} -#endif #if ENABLE(INPUT_TYPE_COLOR) void WebPageProxy::showColorPicker(const WebCore::Color& initialColor, const IntRect& elementRect) @@ -2884,7 +3947,7 @@ void WebPageProxy::showColorPicker(const WebCore::Color& initialColor, const Int #if ENABLE(INPUT_TYPE_COLOR_POPOVER) // A new popover color well needs to be created (and the previous one destroyed) for // each activation of a color element. - m_colorPicker = 0; + m_colorPicker = nullptr; #endif if (!m_colorPicker) m_colorPicker = m_pageClient.createColorPicker(this, initialColor, elementRect); @@ -2918,24 +3981,18 @@ void WebPageProxy::didEndColorPicker() if (!isValid()) return; +#if ENABLE(INPUT_TYPE_COLOR) if (m_colorPicker) { m_colorPicker->invalidate(); m_colorPicker = nullptr; } +#endif m_process->send(Messages::WebPage::DidEndColorPicker(), m_pageID); } #endif -void WebPageProxy::didDraw() -{ - m_uiClient.didDraw(this); -} - // Inspector - -#if ENABLE(INSPECTOR) - WebInspectorProxy* WebPageProxy::inspector() { if (isClosed() || !isValid()) @@ -2943,14 +4000,35 @@ WebInspectorProxy* WebPageProxy::inspector() return m_inspector.get(); } -#endif - #if ENABLE(FULLSCREEN_API) WebFullScreenManagerProxy* WebPageProxy::fullScreenManager() { return m_fullScreenManager.get(); } #endif + +#if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)) +RefPtr<WebVideoFullscreenManagerProxy> WebPageProxy::videoFullscreenManager() +{ + return m_videoFullscreenManager; +} +#endif + +#if PLATFORM(IOS) +bool WebPageProxy::allowsMediaDocumentInlinePlayback() const +{ + return m_allowsMediaDocumentInlinePlayback; +} + +void WebPageProxy::setAllowsMediaDocumentInlinePlayback(bool allows) +{ + if (m_allowsMediaDocumentInlinePlayback == allows) + return; + m_allowsMediaDocumentInlinePlayback = allows; + + m_process->send(Messages::WebPage::SetAllowsMediaDocumentInlinePlayback(allows), m_pageID); +} +#endif // BackForwardList @@ -2987,41 +4065,12 @@ void WebPageProxy::backForwardForwardListCount(int32_t& count) count = m_backForwardList->forwardListCount(); } -void WebPageProxy::editorStateChanged(const EditorState& editorState) +void WebPageProxy::compositionWasCanceled(const EditorState& editorState) { -#if PLATFORM(MAC) - bool couldChangeSecureInputState = m_editorState.isInPasswordField != editorState.isInPasswordField || m_editorState.selectionIsNone; - bool closedComposition = !editorState.shouldIgnoreCompositionSelectionChange && !editorState.hasComposition && (m_editorState.hasComposition || m_temporarilyClosedComposition); - m_temporarilyClosedComposition = editorState.shouldIgnoreCompositionSelectionChange && (m_temporarilyClosedComposition || m_editorState.hasComposition) && !editorState.hasComposition; -#endif - - m_editorState = editorState; - -#if PLATFORM(MAC) - // Selection being none is a temporary state when editing. Flipping secure input state too quickly was causing trouble (not fully understood). - if (couldChangeSecureInputState && !editorState.selectionIsNone) - m_pageClient.updateSecureInputState(); - - if (editorState.shouldIgnoreCompositionSelectionChange) - return; - - if (closedComposition) - m_pageClient.notifyInputContextAboutDiscardedComposition(); - if (editorState.hasComposition) { - // Abandon the current inline input session if selection changed for any other reason but an input method changing the composition. - // FIXME: This logic should be in WebCore, no need to round-trip to UI process to cancel the composition. - cancelComposition(); - m_pageClient.notifyInputContextAboutDiscardedComposition(); - } -#if PLATFORM(IOS) - else { - // We need to notify the client on iOS to make sure the selection is redrawn. - notifyRevealedSelection(); - } -#endif -#elif PLATFORM(EFL) || PLATFORM(GTK) - m_pageClient.updateTextInputState(); +#if PLATFORM(COCOA) + m_pageClient.notifyInputContextAboutDiscardedComposition(); #endif + editorStateChanged(editorState); } // Undo management @@ -3030,6 +4079,13 @@ void WebPageProxy::registerEditCommandForUndo(uint64_t commandID, uint32_t editA { registerEditCommand(WebEditCommandProxy::create(commandID, static_cast<EditAction>(editAction), this), Undo); } + +void WebPageProxy::registerInsertionUndoGrouping() +{ +#if USE(INSERTION_UNDO_GROUPING) + m_pageClient.registerInsertionUndoGrouping(); +#endif +} void WebPageProxy::canUndoRedo(uint32_t action, bool& result) { @@ -3049,51 +4105,60 @@ void WebPageProxy::clearAllEditCommands() void WebPageProxy::didCountStringMatches(const String& string, uint32_t matchCount) { - m_findClient.didCountStringMatches(this, string, matchCount); + m_findClient->didCountStringMatches(this, string, matchCount); } void WebPageProxy::didGetImageForFindMatch(const ShareableBitmap::Handle& contentImageHandle, uint32_t matchIndex) { - m_findMatchesClient.didGetImageForMatchResult(this, WebImage::create(ShareableBitmap::create(contentImageHandle)).get(), matchIndex); + m_findMatchesClient->didGetImageForMatchResult(this, WebImage::create(ShareableBitmap::create(contentImageHandle)).get(), matchIndex); } -void WebPageProxy::setFindIndicator(const FloatRect& selectionRectInWindowCoordinates, const Vector<FloatRect>& textRectsInSelectionRectCoordinates, float contentImageScaleFactor, const ShareableBitmap::Handle& contentImageHandle, bool fadeOut, bool animate) +void WebPageProxy::setTextIndicator(const TextIndicatorData& indicatorData, uint64_t lifetime) { - RefPtr<FindIndicator> findIndicator = FindIndicator::create(selectionRectInWindowCoordinates, textRectsInSelectionRectCoordinates, contentImageScaleFactor, contentImageHandle); - m_pageClient.setFindIndicator(findIndicator.release(), fadeOut, animate); + // FIXME: Make TextIndicatorWindow a platform-independent presentational thing ("TextIndicatorPresentation"?). +#if PLATFORM(COCOA) + m_pageClient.setTextIndicator(TextIndicator::create(indicatorData), static_cast<TextIndicatorWindowLifetime>(lifetime)); +#else + ASSERT_NOT_REACHED(); +#endif } -void WebPageProxy::didFindString(const String& string, uint32_t matchCount) +void WebPageProxy::clearTextIndicator() { - m_findClient.didFindString(this, string, matchCount); +#if PLATFORM(COCOA) + m_pageClient.clearTextIndicator(TextIndicatorWindowDismissalAnimation::FadeOut); +#else + ASSERT_NOT_REACHED(); +#endif } -void WebPageProxy::didFindStringMatches(const String& string, Vector<Vector<WebCore::IntRect>> matchRects, int32_t firstIndexAfterSelection) +void WebPageProxy::setTextIndicatorAnimationProgress(float progress) { - Vector<RefPtr<API::Object>> matches; - matches.reserveInitialCapacity(matchRects.size()); - - for (const auto& rects : matchRects) { - Vector<RefPtr<API::Object>> apiRects; - apiRects.reserveInitialCapacity(rects.size()); - - for (const auto& rect : rects) - apiRects.uncheckedAppend(API::Rect::create(toAPI(rect))); +#if PLATFORM(COCOA) + m_pageClient.setTextIndicatorAnimationProgress(progress); +#else + ASSERT_NOT_REACHED(); +#endif +} - matches.uncheckedAppend(API::Array::create(std::move(apiRects))); - } +void WebPageProxy::didFindString(const String& string, const Vector<WebCore::IntRect>& matchRects, uint32_t matchCount, int32_t matchIndex) +{ + m_findClient->didFindString(this, string, matchRects, matchCount, matchIndex); +} - m_findMatchesClient.didFindStringMatches(this, string, API::Array::create(std::move(matches)).get(), firstIndexAfterSelection); +void WebPageProxy::didFindStringMatches(const String& string, const Vector<Vector<WebCore::IntRect>>& matchRects, int32_t firstIndexAfterSelection) +{ + m_findMatchesClient->didFindStringMatches(this, string, matchRects, firstIndexAfterSelection); } void WebPageProxy::didFailToFindString(const String& string) { - m_findClient.didFailToFindString(this, string); + m_findClient->didFailToFindString(this, string); } bool WebPageProxy::sendMessage(std::unique_ptr<IPC::MessageEncoder> encoder, unsigned messageSendFlags) { - return m_process->sendMessage(std::move(encoder), messageSendFlags); + return m_process->sendMessage(WTFMove(encoder), messageSendFlags); } IPC::Connection* WebPageProxy::messageSenderConnection() @@ -3123,7 +4188,7 @@ NativeWebMouseEvent* WebPageProxy::currentlyProcessedMouseDownEvent() void WebPageProxy::postMessageToInjectedBundle(const String& messageName, API::Object* messageBody) { - process().send(Messages::WebPage::PostInjectedBundleMessage(messageName, WebContextUserMessageEncoder(messageBody, process())), m_pageID); + process().send(Messages::WebPage::PostInjectedBundleMessage(messageName, UserData(process().transformObjectsToHandles(messageBody).get())), m_pageID); } #if PLATFORM(GTK) @@ -3142,29 +4207,25 @@ void WebPageProxy::showPopupMenu(const IntRect& rect, uint64_t textDirection, co m_activePopupMenu->hidePopupMenu(); #endif m_activePopupMenu->invalidate(); - m_activePopupMenu = 0; + m_activePopupMenu = nullptr; } - m_activePopupMenu = m_pageClient.createPopupMenuProxy(this); + m_activePopupMenu = m_pageClient.createPopupMenuProxy(*this); if (!m_activePopupMenu) return; // Since showPopupMenu() can spin a nested run loop we need to turn off the responsiveness timer. - m_process->responsivenessTimer()->stop(); + m_process->responsivenessTimer().stop(); #if PLATFORM(EFL) UNUSED_PARAM(data); m_uiPopupMenuClient.showPopupMenu(this, m_activePopupMenu.get(), rect, static_cast<TextDirection>(textDirection), m_pageScaleFactor, items, selectedIndex); #else - RefPtr<WebPopupMenuProxy> protectedActivePopupMenu = m_activePopupMenu; - protectedActivePopupMenu->showPopupMenu(rect, static_cast<TextDirection>(textDirection), m_pageScaleFactor, items, data, selectedIndex); - - // Since Efl doesn't use a nested mainloop to show the popup and get the answer, we need to keep the client pointer valid. - // FIXME: The above comment doesn't make any sense since this code is compiled out for EFL. - protectedActivePopupMenu->invalidate(); - protectedActivePopupMenu = 0; + // Showing a popup menu runs a nested runloop, which can handle messages that cause |this| to get closed. + Ref<WebPageProxy> protect(*this); + m_activePopupMenu->showPopupMenu(rect, static_cast<TextDirection>(textDirection), m_pageScaleFactor, items, data, selectedIndex); #endif } @@ -3179,59 +4240,44 @@ void WebPageProxy::hidePopupMenu() m_activePopupMenu->hidePopupMenu(); #endif m_activePopupMenu->invalidate(); - m_activePopupMenu = 0; + m_activePopupMenu = nullptr; } #if ENABLE(CONTEXT_MENUS) -void WebPageProxy::showContextMenu(const IntPoint& menuLocation, const WebHitTestResult::Data& hitTestResultData, const Vector<WebContextMenuItemData>& proposedItems, IPC::MessageDecoder& decoder) +void WebPageProxy::showContextMenu(const ContextMenuContextData& contextMenuContextData, const UserData& userData) { - internalShowContextMenu(menuLocation, hitTestResultData, proposedItems, decoder); + // Showing a context menu runs a nested runloop, which can handle messages that cause |this| to get closed. + Ref<WebPageProxy> protect(*this); + + internalShowContextMenu(contextMenuContextData, userData); // No matter the result of internalShowContextMenu, always notify the WebProcess that the menu is hidden so it starts handling mouse events again. m_process->send(Messages::WebPage::ContextMenuHidden(), m_pageID); } -void WebPageProxy::internalShowContextMenu(const IntPoint& menuLocation, const WebHitTestResult::Data& hitTestResultData, const Vector<WebContextMenuItemData>& proposedItems, IPC::MessageDecoder& decoder) +void WebPageProxy::internalShowContextMenu(const ContextMenuContextData& contextMenuContextData, const UserData& userData) { - RefPtr<API::Object> userData; - WebContextUserMessageDecoder messageDecoder(userData, process()); - if (!decoder.decode(messageDecoder)) - return; - - m_activeContextMenuHitTestResultData = hitTestResultData; - - if (!m_contextMenuClient.hideContextMenu(this) && m_activeContextMenu) { - m_activeContextMenu->hideContextMenu(); - m_activeContextMenu = 0; - } + m_activeContextMenuContextData = contextMenuContextData; - m_activeContextMenu = m_pageClient.createContextMenuProxy(this); + m_activeContextMenu = m_pageClient.createContextMenuProxy(*this, contextMenuContextData, userData); if (!m_activeContextMenu) return; // Since showContextMenu() can spin a nested run loop we need to turn off the responsiveness timer. - m_process->responsivenessTimer()->stop(); - - // Give the PageContextMenuClient one last swipe at changing the menu. - Vector<WebContextMenuItemData> items; - if (!m_contextMenuClient.getContextMenuFromProposedMenu(this, proposedItems, items, hitTestResultData, userData.get())) { - if (!m_contextMenuClient.showContextMenu(this, menuLocation, proposedItems)) - m_activeContextMenu->showContextMenu(menuLocation, proposedItems); - } else if (!m_contextMenuClient.showContextMenu(this, menuLocation, items)) - m_activeContextMenu->showContextMenu(menuLocation, items); - - m_contextMenuClient.contextMenuDismissed(this); + m_process->responsivenessTimer().stop(); + + m_activeContextMenu->show(); } void WebPageProxy::contextMenuItemSelected(const WebContextMenuItemData& item) { // Application custom items don't need to round-trip through to WebCore in the WebProcess. if (item.action() >= ContextMenuItemBaseApplicationTag) { - m_contextMenuClient.customContextMenuItemSelected(this, item); + m_contextMenuClient->customContextMenuItemSelected(*this, item); return; } -#if PLATFORM(MAC) +#if PLATFORM(COCOA) if (item.action() == ContextMenuItemTagSmartCopyPaste) { setSmartInsertDeleteEnabled(!isSmartInsertDeleteEnabled()); return; @@ -3267,15 +4313,15 @@ void WebPageProxy::contextMenuItemSelected(const WebContextMenuItemData& item) } #endif if (item.action() == ContextMenuItemTagDownloadImageToDisk) { - m_process->context().download(this, URL(URL(), m_activeContextMenuHitTestResultData.absoluteImageURL)); + m_process->processPool().download(this, URL(URL(), m_activeContextMenuContextData.webHitTestResultData().absoluteImageURL)); return; } if (item.action() == ContextMenuItemTagDownloadLinkToDisk) { - m_process->context().download(this, URL(URL(), m_activeContextMenuHitTestResultData.absoluteLinkURL)); + m_process->processPool().download(this, URL(URL(), m_activeContextMenuContextData.webHitTestResultData().absoluteLinkURL)); return; } if (item.action() == ContextMenuItemTagDownloadMediaToDisk) { - m_process->context().download(this, URL(URL(), m_activeContextMenuHitTestResultData.absoluteMediaURL)); + m_process->processPool().download(this, URL(URL(), m_activeContextMenuContextData.webHitTestResultData().absoluteMediaURL)); return; } if (item.action() == ContextMenuItemTagCheckSpellingWhileTyping) { @@ -3301,12 +4347,13 @@ void WebPageProxy::contextMenuItemSelected(const WebContextMenuItemData& item) } #endif // ENABLE(CONTEXT_MENUS) -void WebPageProxy::didChooseFilesForOpenPanel(const Vector<String>& fileURLs) +#if PLATFORM(IOS) +void WebPageProxy::didChooseFilesForOpenPanelWithDisplayStringAndIcon(const Vector<String>& fileURLs, const String& displayString, const API::Data* iconData) { if (!isValid()) return; -#if ENABLE(WEB_PROCESS_SANDBOX) +#if ENABLE(SANDBOX_EXTENSIONS) // FIXME: The sandbox extensions should be sent with the DidChooseFilesForOpenPanel message. This // is gated on a way of passing SandboxExtension::Handles in a Vector. for (size_t i = 0; i < fileURLs.size(); ++i) { @@ -3316,10 +4363,38 @@ void WebPageProxy::didChooseFilesForOpenPanel(const Vector<String>& fileURLs) } #endif + m_process->send(Messages::WebPage::DidChooseFilesForOpenPanelWithDisplayStringAndIcon(fileURLs, displayString, iconData ? iconData->dataReference() : IPC::DataReference()), m_pageID); + + m_openPanelResultListener->invalidate(); + m_openPanelResultListener = nullptr; +} +#endif + +void WebPageProxy::didChooseFilesForOpenPanel(const Vector<String>& fileURLs) +{ + if (!isValid()) + return; + +#if ENABLE(SANDBOX_EXTENSIONS) + // FIXME: The sandbox extensions should be sent with the DidChooseFilesForOpenPanel message. This + // is gated on a way of passing SandboxExtension::Handles in a Vector. + for (size_t i = 0; i < fileURLs.size(); ++i) { + SandboxExtension::Handle sandboxExtensionHandle; + bool createdExtension = SandboxExtension::createHandle(fileURLs[i], SandboxExtension::ReadOnly, sandboxExtensionHandle); + if (!createdExtension) { + // This can legitimately fail if a directory containing the file is deleted after the file was chosen. + // We also have reports of cases where this likely fails for some unknown reason, <rdar://problem/10156710>. + WTFLogAlways("WebPageProxy::didChooseFilesForOpenPanel: could not create a sandbox extension for '%s'\n", fileURLs[i].utf8().data()); + continue; + } + m_process->send(Messages::WebPage::ExtendSandboxForFileFromOpenPanel(sandboxExtensionHandle), m_pageID); + } +#endif + m_process->send(Messages::WebPage::DidChooseFilesForOpenPanel(fileURLs), m_pageID); m_openPanelResultListener->invalidate(); - m_openPanelResultListener = 0; + m_openPanelResultListener = nullptr; } void WebPageProxy::didCancelForOpenPanel() @@ -3330,7 +4405,7 @@ void WebPageProxy::didCancelForOpenPanel() m_process->send(Messages::WebPage::DidCancelForOpenPanel(), m_pageID); m_openPanelResultListener->invalidate(); - m_openPanelResultListener = 0; + m_openPanelResultListener = nullptr; } void WebPageProxy::advanceToNextMisspelling(bool startBeforeSelection) @@ -3383,18 +4458,18 @@ int64_t WebPageProxy::spellDocumentTag() #if USE(UNIFIED_TEXT_CHECKING) void WebPageProxy::checkTextOfParagraph(const String& text, uint64_t checkingTypes, Vector<TextCheckingResult>& results) { - results = TextChecker::checkTextOfParagraph(spellDocumentTag(), text.deprecatedCharacters(), text.length(), checkingTypes); + results = TextChecker::checkTextOfParagraph(spellDocumentTag(), text, checkingTypes); } #endif void WebPageProxy::checkSpellingOfString(const String& text, int32_t& misspellingLocation, int32_t& misspellingLength) { - TextChecker::checkSpellingOfString(spellDocumentTag(), text.deprecatedCharacters(), text.length(), misspellingLocation, misspellingLength); + TextChecker::checkSpellingOfString(spellDocumentTag(), text, misspellingLocation, misspellingLength); } void WebPageProxy::checkGrammarOfString(const String& text, Vector<GrammarDetail>& grammarDetails, int32_t& badGrammarLocation, int32_t& badGrammarLength) { - TextChecker::checkGrammarOfString(spellDocumentTag(), text.deprecatedCharacters(), text.length(), grammarDetails, badGrammarLocation, badGrammarLength); + TextChecker::checkGrammarOfString(spellDocumentTag(), text, grammarDetails, badGrammarLocation, badGrammarLength); } void WebPageProxy::spellingUIIsShowing(bool& isShowing) @@ -3452,14 +4527,14 @@ void WebPageProxy::didCancelCheckingText(uint64_t requestID) void WebPageProxy::setFocus(bool focused) { if (focused) - m_uiClient.focus(this); + m_uiClient->focus(this); else - m_uiClient.unfocus(this); + m_uiClient->unfocus(this); } void WebPageProxy::takeFocus(uint32_t direction) { - m_uiClient.takeFocus(this, (static_cast<FocusDirection>(direction) == FocusDirectionForward) ? kWKFocusDirectionForward : kWKFocusDirectionBackward); + m_uiClient->takeFocus(this, (static_cast<FocusDirection>(direction) == FocusDirectionForward) ? kWKFocusDirectionForward : kWKFocusDirectionBackward); } void WebPageProxy::setToolTip(const String& toolTip) @@ -3489,11 +4564,14 @@ void WebPageProxy::didReceiveEvent(uint32_t opaqueType, bool handled) switch (type) { case WebEvent::NoType: case WebEvent::MouseMove: + case WebEvent::Wheel: break; case WebEvent::MouseDown: case WebEvent::MouseUp: - case WebEvent::Wheel: + case WebEvent::MouseForceChanged: + case WebEvent::MouseForceDown: + case WebEvent::MouseForceUp: case WebEvent::KeyDown: case WebEvent::KeyUp: case WebEvent::RawKeyDown: @@ -3504,7 +4582,12 @@ void WebPageProxy::didReceiveEvent(uint32_t opaqueType, bool handled) case WebEvent::TouchEnd: case WebEvent::TouchCancel: #endif - m_process->responsivenessTimer()->stop(); +#if ENABLE(MAC_GESTURE_EVENTS) + case WebEvent::GestureStart: + case WebEvent::GestureChange: + case WebEvent::GestureEnd: +#endif + m_process->responsivenessTimer().stop(); break; } @@ -3513,27 +4596,29 @@ void WebPageProxy::didReceiveEvent(uint32_t opaqueType, bool handled) break; case WebEvent::MouseMove: m_processingMouseMoveEvent = false; - if (m_nextMouseMoveEvent) { - handleMouseEvent(*m_nextMouseMoveEvent); - m_nextMouseMoveEvent = nullptr; - } + if (m_nextMouseMoveEvent) + handleMouseEvent(*std::exchange(m_nextMouseMoveEvent, nullptr)); break; case WebEvent::MouseDown: break; case WebEvent::MouseUp: m_currentlyProcessedMouseDownEvent = nullptr; break; + case WebEvent::MouseForceChanged: + case WebEvent::MouseForceDown: + case WebEvent::MouseForceUp: + break; case WebEvent::Wheel: { MESSAGE_CHECK(!m_currentlyProcessedWheelEvents.isEmpty()); - OwnPtr<Vector<NativeWebWheelEvent>> oldestCoalescedEvent = m_currentlyProcessedWheelEvents.takeFirst(); + std::unique_ptr<Vector<NativeWebWheelEvent>> oldestCoalescedEvent = m_currentlyProcessedWheelEvents.takeFirst(); // FIXME: Dispatch additional events to the didNotHandleWheelEvent client function. if (!handled) { - if (m_uiClient.implementsDidNotHandleWheelEvent()) - m_uiClient.didNotHandleWheelEvent(this, oldestCoalescedEvent->last()); -#if PLATFORM(MAC) + if (m_uiClient->implementsDidNotHandleWheelEvent()) + m_uiClient->didNotHandleWheelEvent(this, oldestCoalescedEvent->last()); +#if PLATFORM(COCOA) m_pageClient.wheelEventWasNotHandledByWebCore(oldestCoalescedEvent->last()); #endif } @@ -3557,15 +4642,40 @@ void WebPageProxy::didReceiveEvent(uint32_t opaqueType, bool handled) if (!m_keyEventQueue.isEmpty()) m_process->send(Messages::WebPage::KeyEvent(m_keyEventQueue.first()), m_pageID); + // The call to doneWithKeyEvent may close this WebPage. + // Protect against this being destroyed. + Ref<WebPageProxy> protect(*this); + m_pageClient.doneWithKeyEvent(event, handled); if (handled) break; - if (m_uiClient.implementsDidNotHandleKeyEvent()) - m_uiClient.didNotHandleKeyEvent(this, event); + if (m_uiClient->implementsDidNotHandleKeyEvent()) + m_uiClient->didNotHandleKeyEvent(this, event); break; } -#if ENABLE(TOUCH_EVENTS) +#if ENABLE(MAC_GESTURE_EVENTS) + case WebEvent::GestureStart: + case WebEvent::GestureChange: + case WebEvent::GestureEnd: { + MESSAGE_CHECK(!m_gestureEventQueue.isEmpty()); + NativeWebGestureEvent event = m_gestureEventQueue.takeFirst(); + + MESSAGE_CHECK(type == event.type()); + + if (!handled) + m_pageClient.gestureEventWasNotHandledByWebCore(event); + break; + } + break; +#endif +#if ENABLE(IOS_TOUCH_EVENTS) + case WebEvent::TouchStart: + case WebEvent::TouchMove: + case WebEvent::TouchEnd: + case WebEvent::TouchCancel: + break; +#elif ENABLE(TOUCH_EVENTS) case WebEvent::TouchStart: case WebEvent::TouchMove: case WebEvent::TouchEnd: @@ -3588,12 +4698,12 @@ void WebPageProxy::didReceiveEvent(uint32_t opaqueType, bool handled) void WebPageProxy::stopResponsivenessTimer() { - m_process->responsivenessTimer()->stop(); + m_process->responsivenessTimer().stop(); } void WebPageProxy::voidCallback(uint64_t callbackID) { - RefPtr<VoidCallback> callback = m_voidCallbacks.take(callbackID); + auto callback = m_callbacks.take<VoidCallback>(callbackID); if (!callback) { // FIXME: Log error or assert. return; @@ -3604,18 +4714,18 @@ void WebPageProxy::voidCallback(uint64_t callbackID) void WebPageProxy::dataCallback(const IPC::DataReference& dataReference, uint64_t callbackID) { - RefPtr<DataCallback> callback = m_dataCallbacks.take(callbackID); + auto callback = m_callbacks.take<DataCallback>(callbackID); if (!callback) { // FIXME: Log error or assert. return; } - callback->performCallbackWithReturnValue(API::Data::create(dataReference.data(), dataReference.size()).get()); + callback->performCallbackWithReturnValue(API::Data::create(dataReference.data(), dataReference.size()).ptr()); } void WebPageProxy::imageCallback(const ShareableBitmap::Handle& bitmapHandle, uint64_t callbackID) { - RefPtr<ImageCallback> callback = m_imageCallbacks.take(callbackID); + auto callback = m_callbacks.take<ImageCallback>(callbackID); if (!callback) { // FIXME: Log error or assert. return; @@ -3626,7 +4736,7 @@ void WebPageProxy::imageCallback(const ShareableBitmap::Handle& bitmapHandle, ui void WebPageProxy::stringCallback(const String& resultString, uint64_t callbackID) { - RefPtr<StringCallback> callback = m_stringCallbacks.take(callbackID); + auto callback = m_callbacks.take<StringCallback>(callbackID); if (!callback) { // FIXME: Log error or assert. // this can validly happen if a load invalidated the callback, though @@ -3638,24 +4748,29 @@ void WebPageProxy::stringCallback(const String& resultString, uint64_t callbackI callback->performCallbackWithReturnValue(resultString.impl()); } -void WebPageProxy::scriptValueCallback(const IPC::DataReference& dataReference, uint64_t callbackID) +void WebPageProxy::scriptValueCallback(const IPC::DataReference& dataReference, bool hadException, const ExceptionDetails& details, uint64_t callbackID) { - RefPtr<ScriptValueCallback> callback = m_scriptValueCallbacks.take(callbackID); + auto callback = m_callbacks.take<ScriptValueCallback>(callbackID); if (!callback) { // FIXME: Log error or assert. return; } + if (dataReference.isEmpty()) { + callback->performCallbackWithReturnValue(nullptr, hadException, details); + return; + } + Vector<uint8_t> data; data.reserveInitialCapacity(dataReference.size()); data.append(dataReference.data(), dataReference.size()); - callback->performCallbackWithReturnValue(data.size() ? WebSerializedScriptValue::adopt(data).get() : 0); + callback->performCallbackWithReturnValue(API::SerializedScriptValue::adopt(WTFMove(data)).ptr(), hadException, details); } void WebPageProxy::computedPagesCallback(const Vector<IntRect>& pageRects, double totalScaleFactorForPrinting, uint64_t callbackID) { - RefPtr<ComputedPagesCallback> callback = m_computedPagesCallbacks.take(callbackID); + auto callback = m_callbacks.take<ComputedPagesCallback>(callbackID); if (!callback) { // FIXME: Log error or assert. return; @@ -3666,7 +4781,7 @@ void WebPageProxy::computedPagesCallback(const Vector<IntRect>& pageRects, doubl void WebPageProxy::validateCommandCallback(const String& commandName, bool isEnabled, int state, uint64_t callbackID) { - RefPtr<ValidateCommandCallback> callback = m_validateCommandCallbacks.take(callbackID); + auto callback = m_callbacks.take<ValidateCommandCallback>(callbackID); if (!callback) { // FIXME: Log error or assert. return; @@ -3675,24 +4790,113 @@ void WebPageProxy::validateCommandCallback(const String& commandName, bool isEna callback->performCallbackWithReturnValue(commandName.impl(), isEnabled, state); } +void WebPageProxy::unsignedCallback(uint64_t result, uint64_t callbackID) +{ + auto callback = m_callbacks.take<UnsignedCallback>(callbackID); + if (!callback) { + // FIXME: Log error or assert. + // this can validly happen if a load invalidated the callback, though + return; + } + + callback->performCallbackWithReturnValue(result); +} + +void WebPageProxy::editingRangeCallback(const EditingRange& range, uint64_t callbackID) +{ + MESSAGE_CHECK(range.isValid()); + + auto callback = m_callbacks.take<EditingRangeCallback>(callbackID); + if (!callback) { + // FIXME: Log error or assert. + // this can validly happen if a load invalidated the callback, though + return; + } + + callback->performCallbackWithReturnValue(range); +} + +#if PLATFORM(COCOA) +void WebPageProxy::machSendRightCallback(const MachSendRight& sendRight, uint64_t callbackID) +{ + auto callback = m_callbacks.take<MachSendRightCallback>(callbackID); + if (!callback) + return; + + callback->performCallbackWithReturnValue(sendRight); +} +#endif + +void WebPageProxy::logDiagnosticMessage(const String& message, const String& description, bool shouldSample) +{ + if (!DiagnosticLoggingClient::shouldLogAfterSampling(shouldSample ? ShouldSample::Yes : ShouldSample::No)) + return; + + logSampledDiagnosticMessage(message, description); +} + +void WebPageProxy::logDiagnosticMessageWithResult(const String& message, const String& description, uint32_t result, bool shouldSample) +{ + if (!DiagnosticLoggingClient::shouldLogAfterSampling(shouldSample ? ShouldSample::Yes : ShouldSample::No)) + return; + + logSampledDiagnosticMessageWithResult(message, description, static_cast<WebCore::DiagnosticLoggingResultType>(result)); +} + +void WebPageProxy::logDiagnosticMessageWithValue(const String& message, const String& description, const String& value, bool shouldSample) +{ + if (!DiagnosticLoggingClient::shouldLogAfterSampling(shouldSample ? ShouldSample::Yes : ShouldSample::No)) + return; + + logSampledDiagnosticMessageWithValue(message, description, value); +} + +void WebPageProxy::logSampledDiagnosticMessage(const String& message, const String& description) +{ + m_diagnosticLoggingClient->logDiagnosticMessage(this, message, description); +} + +void WebPageProxy::logSampledDiagnosticMessageWithResult(const String& message, const String& description, uint32_t result) +{ + m_diagnosticLoggingClient->logDiagnosticMessageWithResult(this, message, description, static_cast<WebCore::DiagnosticLoggingResultType>(result)); +} + +void WebPageProxy::logSampledDiagnosticMessageWithValue(const String& message, const String& description, const String& value) +{ + m_diagnosticLoggingClient->logDiagnosticMessageWithValue(this, message, description, value); +} + +void WebPageProxy::rectForCharacterRangeCallback(const IntRect& rect, const EditingRange& actualRange, uint64_t callbackID) +{ + MESSAGE_CHECK(actualRange.isValid()); + + auto callback = m_callbacks.take<RectForCharacterRangeCallback>(callbackID); + if (!callback) { + // FIXME: Log error or assert. + // this can validly happen if a load invalidated the callback, though + return; + } + + callback->performCallbackWithReturnValue(rect, actualRange); +} + #if PLATFORM(GTK) void WebPageProxy::printFinishedCallback(const ResourceError& printError, uint64_t callbackID) { - RefPtr<PrintFinishedCallback> callback = m_printFinishedCallbacks.take(callbackID); + auto callback = m_callbacks.take<PrintFinishedCallback>(callbackID); if (!callback) { // FIXME: Log error or assert. return; } - RefPtr<API::Error> error = API::Error::create(printError); - callback->performCallbackWithReturnValue(error.get()); + callback->performCallbackWithReturnValue(API::Error::create(printError).ptr()); } #endif void WebPageProxy::focusedFrameChanged(uint64_t frameID) { if (!frameID) { - m_focusedFrame = 0; + m_focusedFrame = nullptr; return; } @@ -3705,7 +4909,7 @@ void WebPageProxy::focusedFrameChanged(uint64_t frameID) void WebPageProxy::frameSetLargestFrameChanged(uint64_t frameID) { if (!frameID) { - m_frameSetLargestFrame = 0; + m_frameSetLargestFrame = nullptr; return; } @@ -3722,53 +4926,87 @@ void WebPageProxy::processDidBecomeUnresponsive() updateBackingStoreDiscardableState(); - m_loaderClient->processDidBecomeUnresponsive(this); + if (m_navigationClient) + m_navigationClient->processDidBecomeUnresponsive(*this); + else + m_loaderClient->processDidBecomeUnresponsive(*this); } -void WebPageProxy::interactionOccurredWhileProcessUnresponsive() +void WebPageProxy::processDidBecomeResponsive() { if (!isValid()) return; + + updateBackingStoreDiscardableState(); - m_loaderClient->interactionOccurredWhileProcessUnresponsive(this); + if (m_navigationClient) + m_navigationClient->processDidBecomeResponsive(*this); + else + m_loaderClient->processDidBecomeResponsive(*this); } -void WebPageProxy::processDidBecomeResponsive() +void WebPageProxy::willChangeProcessIsResponsive() { - if (!isValid()) - return; - - updateBackingStoreDiscardableState(); + m_pageLoadState.willChangeProcessIsResponsive(); +} - m_loaderClient->processDidBecomeResponsive(this); +void WebPageProxy::didChangeProcessIsResponsive() +{ + m_pageLoadState.didChangeProcessIsResponsive(); } void WebPageProxy::processDidCrash() { ASSERT(m_isValid); + // There is a nested transaction in resetStateAfterProcessExited() that we don't want to commit before the client call. + PageLoadState::Transaction transaction = m_pageLoadState.transaction(); + resetStateAfterProcessExited(); - auto transaction = m_pageLoadState.transaction(); + navigationState().clearAllNavigations(); - m_pageLoadState.reset(transaction); + if (m_navigationClient) + m_navigationClient->processDidCrash(*this); + else + m_loaderClient->processDidCrash(*this); +} - m_pageClient.processDidCrash(); +#if PLATFORM(IOS) +void WebPageProxy::processWillBecomeSuspended() +{ + if (!isValid()) + return; - m_loaderClient->processDidCrash(this); + m_hasNetworkRequestsOnSuspended = m_pageLoadState.networkRequestsInProgress(); + if (m_hasNetworkRequestsOnSuspended) + setNetworkRequestsInProgress(false); } -void WebPageProxy::resetState() +void WebPageProxy::processWillBecomeForeground() +{ + if (!isValid()) + return; + + if (m_hasNetworkRequestsOnSuspended) { + setNetworkRequestsInProgress(true); + m_hasNetworkRequestsOnSuspended = false; + } +} +#endif + +void WebPageProxy::resetState(ResetStateReason resetStateReason) { m_mainFrame = nullptr; +#if PLATFORM(COCOA) + m_scrollingPerformanceData = nullptr; +#endif m_drawingArea = nullptr; -#if ENABLE(INSPECTOR) if (m_inspector) { m_inspector->invalidate(); m_inspector = nullptr; } -#endif #if ENABLE(FULLSCREEN_API) if (m_fullScreenManager) { @@ -3786,6 +5024,10 @@ void WebPageProxy::resetState() m_openPanelResultListener = nullptr; } +#if ENABLE(TOUCH_EVENTS) + m_isTrackingTouchEvents = false; +#endif + #if ENABLE(INPUT_TYPE_COLOR) if (m_colorPicker) { m_colorPicker->invalidate(); @@ -3796,6 +5038,9 @@ void WebPageProxy::resetState() #if ENABLE(GEOLOCATION) m_geolocationPermissionRequestManager.invalidateRequests(); #endif +#if ENABLE(MEDIA_STREAM) + m_userMediaPermissionRequestManager.invalidateRequests(); +#endif m_notificationPermissionRequestManager.invalidateRequests(); @@ -3804,38 +5049,59 @@ void WebPageProxy::resetState() m_mainFrameHasHorizontalScrollbar = false; m_mainFrameHasVerticalScrollbar = false; - m_mainFrameIsPinnedToLeftSide = false; - m_mainFrameIsPinnedToRightSide = false; - m_mainFrameIsPinnedToTopSide = false; - m_mainFrameIsPinnedToBottomSide = false; + m_mainFrameIsPinnedToLeftSide = true; + m_mainFrameIsPinnedToRightSide = true; + m_mainFrameIsPinnedToTopSide = true; + m_mainFrameIsPinnedToBottomSide = true; m_visibleScrollerThumbRect = IntRect(); - invalidateCallbackMap(m_voidCallbacks); - invalidateCallbackMap(m_dataCallbacks); - invalidateCallbackMap(m_imageCallbacks); - invalidateCallbackMap(m_stringCallbacks); - m_loadDependentStringCallbackIDs.clear(); - invalidateCallbackMap(m_scriptValueCallbacks); - invalidateCallbackMap(m_computedPagesCallbacks); - invalidateCallbackMap(m_validateCommandCallbacks); +#if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)) + if (m_videoFullscreenManager) { + m_videoFullscreenManager->invalidate(); + m_videoFullscreenManager = nullptr; + } +#endif + #if PLATFORM(IOS) - invalidateCallbackMap(m_gestureCallbacks); - invalidateCallbackMap(m_touchesCallbacks); - invalidateCallbackMap(m_autocorrectionCallbacks); - invalidateCallbackMap(m_autocorrectionContextCallbacks); + m_lastVisibleContentRectUpdate = VisibleContentRectUpdateInfo(); + m_dynamicViewportSizeUpdateWaitingForTarget = false; + m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit = false; + m_dynamicViewportSizeUpdateLayerTreeTransactionID = 0; + m_layerTreeTransactionIdAtLastTouchStart = 0; + m_hasNetworkRequestsOnSuspended = false; #endif -#if PLATFORM(GTK) - invalidateCallbackMap(m_printFinishedCallbacks); + +#if ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS) + m_pageClient.mediaSessionManager().removeAllPlaybackTargetPickerClients(*this); #endif +#if USE(APPLE_INTERNAL_SDK) +#include <WebKitAdditions/WebPageProxyInvalidation.cpp> +#endif + + CallbackBase::Error error; + switch (resetStateReason) { + case ResetStateReason::PageInvalidated: + error = CallbackBase::Error::OwnerWasInvalidated; + break; + + case ResetStateReason::WebProcessExited: + error = CallbackBase::Error::ProcessExited; + break; + } + + m_callbacks.invalidate(error); + m_loadDependentStringCallbackIDs.clear(); + Vector<WebEditCommandProxy*> editCommandVector; copyToVector(m_editCommandSet, editCommandVector); m_editCommandSet.clear(); for (size_t i = 0, size = editCommandVector.size(); i < size; ++i) editCommandVector[i]->invalidate(); - m_activePopupMenu = 0; + m_activePopupMenu = nullptr; + m_mediaState = MediaProducer::IsNotPlaying; } void WebPageProxy::resetStateAfterProcessExited() @@ -3843,18 +5109,24 @@ void WebPageProxy::resetStateAfterProcessExited() if (!isValid()) return; - m_process->removeMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_pageID); + // FIXME: It's weird that resetStateAfterProcessExited() is called even though the process is launching. + ASSERT(m_process->state() == WebProcessProxy::State::Launching || m_process->state() == WebProcessProxy::State::Terminated); + +#if PLATFORM(IOS) + m_activityToken = nullptr; +#endif + m_pageIsUserObservableCount = nullptr; m_isValid = false; m_isPageSuspended = false; - m_waitingForDidUpdateViewState = false; - if (m_mainFrame) { - m_urlAtProcessExit = m_mainFrame->url(); - m_loadStateAtProcessExit = m_mainFrame->frameLoadState().m_state; - } + m_needsToFinishInitializingWebPageAfterProcessLaunch = false; + + m_editorState = EditorState(); + + m_pageClient.processDidExit(); - resetState(); + resetState(ResetStateReason::WebProcessExited); m_pageClient.clearAllEditCommands(); m_pendingLearnOrIgnoreWordMessageCount = 0; @@ -3869,19 +5141,18 @@ void WebPageProxy::resetStateAfterProcessExited() m_processingMouseMoveEvent = false; -#if ENABLE(TOUCH_EVENTS) - m_needTouchEvents = false; +#if ENABLE(TOUCH_EVENTS) && !ENABLE(IOS_TOUCH_EVENTS) m_touchEventQueue.clear(); #endif - // FIXME: Reset m_editorState. - // FIXME: Notify input methods about abandoned composition. - m_temporarilyClosedComposition = false; - -#if !PLATFORM(IOS) && PLATFORM(MAC) - dismissCorrectionPanel(ReasonForDismissingAlternativeTextIgnored); - m_pageClient.dismissDictionaryLookupPanel(); +#if PLATFORM(MAC) + m_pageClient.dismissContentRelativeChildWindows(); #endif + + PageLoadState::Transaction transaction = m_pageLoadState.transaction(); + m_pageLoadState.reset(transaction); + + m_process->responsivenessTimer().processTerminated(); } WebPageCreationParameters WebPageProxy::creationParameters() @@ -3891,12 +5162,11 @@ WebPageCreationParameters WebPageProxy::creationParameters() parameters.viewSize = m_pageClient.viewSize(); parameters.viewState = m_viewState; parameters.drawingAreaType = m_drawingArea->type(); - parameters.store = m_pageGroup->preferences()->store(); + parameters.store = preferencesStore(); parameters.pageGroupData = m_pageGroup->data(); parameters.drawsBackground = m_drawsBackground; - parameters.drawsTransparentBackground = m_drawsTransparentBackground; + parameters.isEditable = m_isEditable; parameters.underlayColor = m_underlayColor; - parameters.areMemoryCacheClientCallsEnabled = m_areMemoryCacheClientCallsEnabled; parameters.useFixedLayout = m_useFixedLayout; parameters.fixedLayoutSize = m_fixedLayoutSize; parameters.suppressScrollbarAnimations = m_suppressScrollbarAnimations; @@ -3904,28 +5174,55 @@ WebPageCreationParameters WebPageProxy::creationParameters() parameters.paginationBehavesLikeColumns = m_paginationBehavesLikeColumns; parameters.pageLength = m_pageLength; parameters.gapBetweenPages = m_gapBetweenPages; + parameters.paginationLineGridEnabled = m_paginationLineGridEnabled; parameters.userAgent = userAgent(); - parameters.sessionState = SessionState(m_backForwardList->entries(), m_backForwardList->currentIndex()); + parameters.itemStates = m_backForwardList->itemStates(); + parameters.sessionID = m_sessionID; parameters.highestUsedBackForwardItemID = WebBackForwardListItem::highedUsedItemID(); - parameters.canRunBeforeUnloadConfirmPanel = m_uiClient.canRunBeforeUnloadConfirmPanel(); + parameters.userContentControllerID = m_userContentController ? m_userContentController->identifier() : 0; + parameters.visitedLinkTableID = m_visitedLinkStore->identifier(); + parameters.websiteDataStoreID = m_websiteDataStore->identifier(); + parameters.canRunBeforeUnloadConfirmPanel = m_uiClient->canRunBeforeUnloadConfirmPanel(); parameters.canRunModal = m_canRunModal; parameters.deviceScaleFactor = deviceScaleFactor(); + parameters.viewScaleFactor = m_viewScaleFactor; + parameters.topContentInset = m_topContentInset; parameters.mediaVolume = m_mediaVolume; + parameters.muted = m_muted; parameters.mayStartMediaWhenInWindow = m_mayStartMediaWhenInWindow; parameters.minimumLayoutSize = m_minimumLayoutSize; parameters.autoSizingShouldExpandToViewHeight = m_autoSizingShouldExpandToViewHeight; parameters.scrollPinningBehavior = m_scrollPinningBehavior; + if (m_scrollbarOverlayStyle) + parameters.scrollbarOverlayStyle = m_scrollbarOverlayStyle.value(); + else + parameters.scrollbarOverlayStyle = Nullopt; parameters.backgroundExtendsBeyondPage = m_backgroundExtendsBeyondPage; parameters.layerHostingMode = m_layerHostingMode; - -#if PLATFORM(MAC) && !PLATFORM(IOS) +#if ENABLE(REMOTE_INSPECTOR) + parameters.allowsRemoteInspection = m_allowsRemoteInspection; + parameters.remoteInspectionNameOverride = m_remoteInspectionNameOverride; +#endif +#if PLATFORM(MAC) parameters.colorSpace = m_pageClient.colorSpace(); #endif +#if PLATFORM(IOS) + parameters.screenSize = screenSize(); + parameters.availableScreenSize = availableScreenSize(); + parameters.textAutosizingWidth = textAutosizingWidth(); + parameters.mimeTypesWithCustomContentProviders = m_pageClient.mimeTypesWithCustomContentProviders(); +#endif + +#if PLATFORM(MAC) + parameters.appleMailPaginationQuirkEnabled = appleMailPaginationQuirkEnabled(); +#else + parameters.appleMailPaginationQuirkEnabled = false; +#endif + parameters.shouldScaleViewToFitDocument = m_shouldScaleViewToFitDocument; return parameters; } -#if USE(ACCELERATED_COMPOSITING) void WebPageProxy::enterAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext) { m_pageClient.enterAcceleratedCompositingMode(layerTreeContext); @@ -3940,7 +5237,11 @@ void WebPageProxy::updateAcceleratedCompositingMode(const LayerTreeContext& laye { m_pageClient.updateAcceleratedCompositingMode(layerTreeContext); } -#endif // USE(ACCELERATED_COMPOSITING) + +void WebPageProxy::willEnterAcceleratedCompositingMode() +{ + m_pageClient.willEnterAcceleratedCompositingMode(); +} void WebPageProxy::backForwardClear() { @@ -3954,7 +5255,10 @@ void WebPageProxy::canAuthenticateAgainstProtectionSpaceInFrame(uint64_t frameID RefPtr<WebProtectionSpace> protectionSpace = WebProtectionSpace::create(coreProtectionSpace); - canAuthenticate = m_loaderClient->canAuthenticateAgainstProtectionSpaceInFrame(this, frame, protectionSpace.get()); + if (m_navigationClient) + canAuthenticate = m_navigationClient->canAuthenticateAgainstProtectionSpace(*this, protectionSpace.get()); + else + canAuthenticate = m_loaderClient->canAuthenticateAgainstProtectionSpaceInFrame(*this, *frame, protectionSpace.get()); } void WebPageProxy::didReceiveAuthenticationChallenge(uint64_t frameID, const AuthenticationChallenge& coreChallenge, uint64_t challengeID) @@ -3970,16 +5274,19 @@ void WebPageProxy::didReceiveAuthenticationChallengeProxy(uint64_t frameID, Pass MESSAGE_CHECK(frame); RefPtr<AuthenticationChallengeProxy> authenticationChallenge = prpAuthenticationChallenge; - m_loaderClient->didReceiveAuthenticationChallengeInFrame(this, frame, authenticationChallenge.get()); + if (m_navigationClient) + m_navigationClient->didReceiveAuthenticationChallenge(*this, authenticationChallenge.get()); + else + m_loaderClient->didReceiveAuthenticationChallengeInFrame(*this, *frame, authenticationChallenge.get()); } void WebPageProxy::exceededDatabaseQuota(uint64_t frameID, const String& originIdentifier, const String& databaseName, const String& displayName, uint64_t currentQuota, uint64_t currentOriginUsage, uint64_t currentDatabaseUsage, uint64_t expectedUsage, PassRefPtr<Messages::WebPageProxy::ExceededDatabaseQuota::DelayedReply> reply) { - ExceededDatabaseQuotaRecords& records = ExceededDatabaseQuotaRecords::shared(); - OwnPtr<ExceededDatabaseQuotaRecords::Record> newRecord = records.createRecord(frameID, + ExceededDatabaseQuotaRecords& records = ExceededDatabaseQuotaRecords::singleton(); + std::unique_ptr<ExceededDatabaseQuotaRecords::Record> newRecord = records.createRecord(frameID, originIdentifier, databaseName, displayName, currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage, reply); - records.add(newRecord.release()); + records.add(WTFMove(newRecord)); if (records.areBeingProcessed()) return; @@ -3989,27 +5296,33 @@ void WebPageProxy::exceededDatabaseQuota(uint64_t frameID, const String& originI WebFrameProxy* frame = m_process->webFrame(record->frameID); MESSAGE_CHECK(frame); - RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::createFromDatabaseIdentifier(record->originIdentifier); - - uint64_t newQuota = m_uiClient.exceededDatabaseQuota(this, frame, origin.get(), + RefPtr<API::SecurityOrigin> origin = API::SecurityOrigin::create(SecurityOrigin::createFromDatabaseIdentifier(record->originIdentifier)); + auto currentReply = record->reply; + m_uiClient->exceededDatabaseQuota(this, frame, origin.get(), record->databaseName, record->displayName, record->currentQuota, - record->currentOriginUsage, record->currentDatabaseUsage, record->expectedUsage); + record->currentOriginUsage, record->currentDatabaseUsage, record->expectedUsage, + [currentReply](unsigned long long newQuota) { currentReply->send(newQuota); }); - record->reply->send(newQuota); record = records.next(); } } +void WebPageProxy::reachedApplicationCacheOriginQuota(const String& originIdentifier, uint64_t currentQuota, uint64_t totalBytesNeeded, PassRefPtr<Messages::WebPageProxy::ReachedApplicationCacheOriginQuota::DelayedReply> reply) +{ + Ref<SecurityOrigin> securityOrigin = SecurityOrigin::createFromDatabaseIdentifier(originIdentifier); + m_uiClient->reachedApplicationCacheOriginQuota(this, securityOrigin.get(), currentQuota, totalBytesNeeded, [reply](unsigned long long newQuota) { reply->send(newQuota); }); +} + void WebPageProxy::requestGeolocationPermissionForFrame(uint64_t geolocationID, uint64_t frameID, String originIdentifier) { WebFrameProxy* frame = m_process->webFrame(frameID); MESSAGE_CHECK(frame); // FIXME: Geolocation should probably be using toString() as its string representation instead of databaseIdentifier(). - RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::createFromDatabaseIdentifier(originIdentifier); + RefPtr<API::SecurityOrigin> origin = API::SecurityOrigin::create(SecurityOrigin::createFromDatabaseIdentifier(originIdentifier)); RefPtr<GeolocationPermissionRequestProxy> request = m_geolocationPermissionRequestManager.createRequest(geolocationID); - if (m_uiClient.decidePolicyForGeolocationPermissionRequest(this, frame, origin.get(), request.get())) + if (m_uiClient->decidePolicyForGeolocationPermissionRequest(this, frame, origin.get(), request.get())) return; if (m_pageClient.decidePolicyForGeolocationPermissionRequest(*frame, *origin, *request)) @@ -4018,70 +5331,94 @@ void WebPageProxy::requestGeolocationPermissionForFrame(uint64_t geolocationID, request->deny(); } +void WebPageProxy::requestUserMediaPermissionForFrame(uint64_t userMediaID, uint64_t frameID, String originIdentifier, const Vector<String>& audioDeviceUIDs, const Vector<String>& videoDeviceUIDs) +{ + WebFrameProxy* frame = m_process->webFrame(frameID); + MESSAGE_CHECK(frame); + + RefPtr<API::SecurityOrigin> origin = API::SecurityOrigin::create(SecurityOrigin::createFromDatabaseIdentifier(originIdentifier)); + RefPtr<UserMediaPermissionRequestProxy> request = m_userMediaPermissionRequestManager.createRequest(userMediaID, audioDeviceUIDs, videoDeviceUIDs); + + if (!m_uiClient->decidePolicyForUserMediaPermissionRequest(*this, *frame, *origin.get(), *request.get())) + request->deny(); +} + +void WebPageProxy::checkUserMediaPermissionForFrame(uint64_t userMediaID, uint64_t frameID, String originIdentifier) +{ + WebFrameProxy* frame = m_process->webFrame(frameID); + MESSAGE_CHECK(frame); + + RefPtr<API::SecurityOrigin> origin = API::SecurityOrigin::create(SecurityOrigin::createFromDatabaseIdentifier(originIdentifier)); + RefPtr<UserMediaPermissionCheckProxy> request = m_userMediaPermissionRequestManager.createUserMediaPermissionCheck(userMediaID); + + if (!m_uiClient->checkUserMediaPermissionForOrigin(*this, *frame, *origin.get(), *request.get())) + request->setHasPersistentPermission(false); +} + void WebPageProxy::requestNotificationPermission(uint64_t requestID, const String& originString) { if (!isRequestIDValid(requestID)) return; - RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::createFromString(originString); + RefPtr<API::SecurityOrigin> origin = API::SecurityOrigin::createFromString(originString); RefPtr<NotificationPermissionRequest> request = m_notificationPermissionRequestManager.createRequest(requestID); - if (!m_uiClient.decidePolicyForNotificationPermissionRequest(this, origin.get(), request.get())) + if (!m_uiClient->decidePolicyForNotificationPermissionRequest(this, origin.get(), request.get())) request->deny(); } void WebPageProxy::showNotification(const String& title, const String& body, const String& iconURL, const String& tag, const String& lang, const String& dir, const String& originString, uint64_t notificationID) { - m_process->context().supplement<WebNotificationManagerProxy>()->show(this, title, body, iconURL, tag, lang, dir, originString, notificationID); + m_process->processPool().supplement<WebNotificationManagerProxy>()->show(this, title, body, iconURL, tag, lang, dir, originString, notificationID); } void WebPageProxy::cancelNotification(uint64_t notificationID) { - m_process->context().supplement<WebNotificationManagerProxy>()->cancel(this, notificationID); + m_process->processPool().supplement<WebNotificationManagerProxy>()->cancel(this, notificationID); } void WebPageProxy::clearNotifications(const Vector<uint64_t>& notificationIDs) { - m_process->context().supplement<WebNotificationManagerProxy>()->clearNotifications(this, notificationIDs); + m_process->processPool().supplement<WebNotificationManagerProxy>()->clearNotifications(this, notificationIDs); } void WebPageProxy::didDestroyNotification(uint64_t notificationID) { - m_process->context().supplement<WebNotificationManagerProxy>()->didDestroyNotification(this, notificationID); + m_process->processPool().supplement<WebNotificationManagerProxy>()->didDestroyNotification(this, notificationID); } float WebPageProxy::headerHeight(WebFrameProxy* frame) { if (frame->isDisplayingPDFDocument()) return 0; - return m_uiClient.headerHeight(this, frame); + return m_uiClient->headerHeight(this, frame); } float WebPageProxy::footerHeight(WebFrameProxy* frame) { if (frame->isDisplayingPDFDocument()) return 0; - return m_uiClient.footerHeight(this, frame); + return m_uiClient->footerHeight(this, frame); } void WebPageProxy::drawHeader(WebFrameProxy* frame, const FloatRect& rect) { if (frame->isDisplayingPDFDocument()) return; - m_uiClient.drawHeader(this, frame, rect); + m_uiClient->drawHeader(this, frame, rect); } void WebPageProxy::drawFooter(WebFrameProxy* frame, const FloatRect& rect) { if (frame->isDisplayingPDFDocument()) return; - m_uiClient.drawFooter(this, frame, rect); + m_uiClient->drawFooter(this, frame, rect); } void WebPageProxy::runModal() { // Since runModal() can (and probably will) spin a nested run loop we need to turn off the responsiveness timer. - m_process->responsivenessTimer()->stop(); + m_process->responsivenessTimer().stop(); // Our Connection's run loop might have more messages waiting to be handled after this RunModal message. // To make sure they are handled inside of the the nested modal run loop we must first signal the Connection's @@ -4089,7 +5426,7 @@ void WebPageProxy::runModal() // See http://webkit.org/b/89590 for more discussion. m_process->connection()->wakeUpRunLoop(); - m_uiClient.runModal(this); + m_uiClient->runModal(this); } void WebPageProxy::notifyScrollerThumbIsVisibleInRect(const IntRect& scrollerThumb) @@ -4100,7 +5437,7 @@ void WebPageProxy::notifyScrollerThumbIsVisibleInRect(const IntRect& scrollerThu void WebPageProxy::recommendedScrollbarStyleDidChange(int32_t newStyle) { #if USE(APPKIT) - m_pageClient.recommendedScrollbarStyleDidChange(newStyle); + m_pageClient.recommendedScrollbarStyleDidChange(static_cast<WebCore::ScrollbarStyle>(newStyle)); #else UNUSED_PARAM(newStyle); #endif @@ -4118,6 +5455,8 @@ void WebPageProxy::didChangeScrollOffsetPinningForMainFrame(bool pinnedToLeftSid m_mainFrameIsPinnedToRightSide = pinnedToRightSide; m_mainFrameIsPinnedToTopSide = pinnedToTopSide; m_mainFrameIsPinnedToBottomSide = pinnedToBottomSide; + + m_uiClient->pinnedStateDidChange(*this); } void WebPageProxy::didChangePageCount(unsigned pageCount) @@ -4125,19 +5464,24 @@ void WebPageProxy::didChangePageCount(unsigned pageCount) m_pageCount = pageCount; } +void WebPageProxy::pageExtendedBackgroundColorDidChange(const Color& backgroundColor) +{ + m_pageExtendedBackgroundColor = backgroundColor; +} + #if ENABLE(NETSCAPE_PLUGIN_API) void WebPageProxy::didFailToInitializePlugin(const String& mimeType, const String& frameURLString, const String& pageURLString) { - m_loaderClient->didFailToInitializePlugin(this, createPluginInformationDictionary(mimeType, frameURLString, pageURLString).get()); + m_loaderClient->didFailToInitializePlugin(*this, createPluginInformationDictionary(mimeType, frameURLString, pageURLString).ptr()); } void WebPageProxy::didBlockInsecurePluginVersion(const String& mimeType, const String& pluginURLString, const String& frameURLString, const String& pageURLString, bool replacementObscured) { - RefPtr<ImmutableDictionary> pluginInformation; + RefPtr<API::Dictionary> pluginInformation; -#if PLATFORM(MAC) && ENABLE(NETSCAPE_PLUGIN_API) +#if PLATFORM(COCOA) && ENABLE(NETSCAPE_PLUGIN_API) String newMimeType = mimeType; - PluginModuleInfo plugin = m_process->context().pluginInfoStore().findPlugin(newMimeType, URL(URL(), pluginURLString)); + PluginModuleInfo plugin = m_process->processPool().pluginInfoStore().findPlugin(newMimeType, URL(URL(), pluginURLString)); pluginInformation = createPluginInformationDictionary(plugin, frameURLString, mimeType, pageURLString, String(), String(), replacementObscured); #else UNUSED_PARAM(mimeType); @@ -4147,7 +5491,7 @@ void WebPageProxy::didBlockInsecurePluginVersion(const String& mimeType, const S UNUSED_PARAM(replacementObscured); #endif - m_loaderClient->didBlockInsecurePluginVersion(this, pluginInformation.get()); + m_loaderClient->didBlockInsecurePluginVersion(*this, pluginInformation.get()); } #endif // ENABLE(NETSCAPE_PLUGIN_API) @@ -4156,8 +5500,14 @@ bool WebPageProxy::willHandleHorizontalScrollEvents() const return !m_canShortCircuitHorizontalWheelEvents; } +void WebPageProxy::didFinishLoadingDataForCustomContentProvider(const String& suggestedFilename, const IPC::DataReference& dataReference) +{ + m_pageClient.didFinishLoadingDataForCustomContentProvider(suggestedFilename, dataReference); +} + void WebPageProxy::backForwardRemovedItem(uint64_t itemID) { + m_process->removeBackForwardItem(itemID); m_process->send(Messages::WebPage::DidRemoveBackForwardItem(itemID), m_pageID); } @@ -4169,7 +5519,7 @@ void WebPageProxy::setCanRunModal(bool canRunModal) // It's only possible to change the state for a WebPage which // already qualifies for running modal child web pages, otherwise // there's no other possibility than not allowing it. - m_canRunModal = m_uiClient.canRunModal() && canRunModal; + m_canRunModal = m_uiClient->canRunModal() && canRunModal; m_process->send(Messages::WebPage::SetCanRunModal(m_canRunModal), m_pageID); } @@ -4205,12 +5555,12 @@ void WebPageProxy::computePagesForPrinting(WebFrameProxy* frame, const PrintInfo } uint64_t callbackID = callback->callbackID(); - m_computedPagesCallbacks.set(callbackID, callback.get()); + m_callbacks.put(callback); m_isInPrintingMode = true; m_process->send(Messages::WebPage::ComputePagesForPrinting(frame->frameID(), printInfo, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? IPC::DispatchMessageEvenWhenWaitingForSyncReply : 0); } -#if PLATFORM(MAC) +#if PLATFORM(COCOA) void WebPageProxy::drawRectToImage(WebFrameProxy* frame, const PrintInfo& printInfo, const IntRect& rect, const WebCore::IntSize& imageSize, PassRefPtr<ImageCallback> prpCallback) { RefPtr<ImageCallback> callback = prpCallback; @@ -4220,7 +5570,7 @@ void WebPageProxy::drawRectToImage(WebFrameProxy* frame, const PrintInfo& printI } uint64_t callbackID = callback->callbackID(); - m_imageCallbacks.set(callbackID, callback.get()); + m_callbacks.put(callback); m_process->send(Messages::WebPage::DrawRectToImage(frame->frameID(), printInfo, rect, imageSize, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? IPC::DispatchMessageEvenWhenWaitingForSyncReply : 0); } @@ -4233,7 +5583,7 @@ void WebPageProxy::drawPagesToPDF(WebFrameProxy* frame, const PrintInfo& printIn } uint64_t callbackID = callback->callbackID(); - m_dataCallbacks.set(callbackID, callback.get()); + m_callbacks.put(callback); m_process->send(Messages::WebPage::DrawPagesToPDF(frame->frameID(), printInfo, first, count, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? IPC::DispatchMessageEvenWhenWaitingForSyncReply : 0); } #elif PLATFORM(GTK) @@ -4246,7 +5596,7 @@ void WebPageProxy::drawPagesForPrinting(WebFrameProxy* frame, const PrintInfo& p } uint64_t callbackID = callback->callbackID(); - m_printFinishedCallbacks.set(callbackID, callback.get()); + m_callbacks.put(callback); m_isInPrintingMode = true; m_process->send(Messages::WebPage::DrawPagesForPrinting(frame->frameID(), printInfo, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? IPC::DispatchMessageEvenWhenWaitingForSyncReply : 0); } @@ -4258,7 +5608,7 @@ void WebPageProxy::updateBackingStoreDiscardableState() bool isDiscardable; - if (!m_process->responsivenessTimer()->isResponsive()) + if (!m_process->responsivenessTimer().isResponsive()) isDiscardable = false; else isDiscardable = !m_pageClient.isViewWindowActive() || !isViewVisible(); @@ -4268,7 +5618,7 @@ void WebPageProxy::updateBackingStoreDiscardableState() void WebPageProxy::saveDataToFileInDownloadsFolder(const String& suggestedFilename, const String& mimeType, const String& originatingURLString, API::Data* data) { - m_uiClient.saveDataToFileInDownloadsFolder(this, suggestedFilename, mimeType, originatingURLString, data); + m_uiClient->saveDataToFileInDownloadsFolder(this, suggestedFilename, mimeType, originatingURLString, data); } void WebPageProxy::savePDFToFileInDownloadsFolder(const String& suggestedFilename, const String& originatingURLString, const IPC::DataReference& dataReference) @@ -4276,9 +5626,8 @@ void WebPageProxy::savePDFToFileInDownloadsFolder(const String& suggestedFilenam if (!suggestedFilename.endsWith(".pdf", false)) return; - RefPtr<API::Data> data = API::Data::create(dataReference.data(), dataReference.size()); - - saveDataToFileInDownloadsFolder(suggestedFilename, "application/pdf", originatingURLString, data.get()); + saveDataToFileInDownloadsFolder(suggestedFilename, "application/pdf", originatingURLString, + API::Data::create(dataReference.data(), dataReference.size()).ptr()); } void WebPageProxy::setMinimumLayoutSize(const IntSize& minimumLayoutSize) @@ -4313,7 +5662,7 @@ void WebPageProxy::setAutoSizingShouldExpandToViewHeight(bool shouldExpand) m_process->send(Messages::WebPage::SetAutoSizingShouldExpandToViewHeight(shouldExpand), m_pageID, 0); } -#if !PLATFORM(IOS) && PLATFORM(MAC) +#if PLATFORM(MAC) void WebPageProxy::substitutionsPanelIsShowing(bool& isShowing) { @@ -4363,22 +5712,15 @@ void WebPageProxy::dictationAlternatives(uint64_t dictationContext, Vector<Strin } #endif -#endif // !PLATFORM(IOS) && PLATFORM(MAC) +#endif // PLATFORM(MAC) -#if PLATFORM(MAC) -RetainPtr<CGImageRef> WebPageProxy::takeViewSnapshot() +#if PLATFORM(COCOA) +PassRefPtr<ViewSnapshot> WebPageProxy::takeViewSnapshot() { return m_pageClient.takeViewSnapshot(); } #endif -#if USE(SOUP) && !ENABLE(CUSTOM_PROTOCOLS) -void WebPageProxy::didReceiveURIRequest(String uriString, uint64_t requestID) -{ - m_process->context().supplement<WebSoupRequestManagerProxy>()->didReceiveURIRequest(uriString, this, requestID); -} -#endif - #if PLATFORM(GTK) void WebPageProxy::setComposition(const String& text, Vector<CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeEnd) { @@ -4406,17 +5748,6 @@ void WebPageProxy::cancelComposition() } #endif // PLATFORM(GTK) -void WebPageProxy::setMainFrameInViewSourceMode(bool mainFrameInViewSourceMode) -{ - if (m_mainFrameInViewSourceMode == mainFrameInViewSourceMode) - return; - - m_mainFrameInViewSourceMode = mainFrameInViewSourceMode; - - if (isValid()) - m_process->send(Messages::WebPage::SetMainFrameInViewSourceMode(mainFrameInViewSourceMode), m_pageID); -} - void WebPageProxy::didSaveToPageCache() { m_process->didSaveToPageCache(); @@ -4433,4 +5764,436 @@ void WebPageProxy::setScrollPinningBehavior(ScrollPinningBehavior pinning) m_process->send(Messages::WebPage::SetScrollPinningBehavior(pinning), m_pageID); } +void WebPageProxy::setOverlayScrollbarStyle(WTF::Optional<WebCore::ScrollbarOverlayStyle> scrollbarStyle) +{ + if (!m_scrollbarOverlayStyle && !scrollbarStyle) + return; + + if ((m_scrollbarOverlayStyle && scrollbarStyle) && m_scrollbarOverlayStyle.value() == scrollbarStyle.value()) + return; + + m_scrollbarOverlayStyle = scrollbarStyle; + + WTF::Optional<uint32_t> scrollbarStyleForMessage; + if (scrollbarStyle) + scrollbarStyleForMessage = static_cast<ScrollbarOverlayStyle>(scrollbarStyle.value()); + + if (isValid()) + m_process->send(Messages::WebPage::SetScrollbarOverlayStyle(scrollbarStyleForMessage), m_pageID); +} + +#if ENABLE(SUBTLE_CRYPTO) +void WebPageProxy::wrapCryptoKey(const Vector<uint8_t>& key, bool& succeeded, Vector<uint8_t>& wrappedKey) +{ + PageClientProtector protector(m_pageClient); + + Vector<uint8_t> masterKey; + + if (m_navigationClient) { + if (RefPtr<API::Data> keyData = m_navigationClient->webCryptoMasterKey(*this)) + masterKey = keyData->dataReference().vector(); + } else if (RefPtr<API::Data> keyData = m_loaderClient->webCryptoMasterKey(*this)) + masterKey = keyData->dataReference().vector(); + else if (!getDefaultWebCryptoMasterKey(masterKey)) { + succeeded = false; + return; + } + + succeeded = wrapSerializedCryptoKey(masterKey, key, wrappedKey); +} + +void WebPageProxy::unwrapCryptoKey(const Vector<uint8_t>& wrappedKey, bool& succeeded, Vector<uint8_t>& key) +{ + PageClientProtector protector(m_pageClient); + + Vector<uint8_t> masterKey; + + if (m_navigationClient) { + if (RefPtr<API::Data> keyData = m_navigationClient->webCryptoMasterKey(*this)) + masterKey = keyData->dataReference().vector(); + } else if (RefPtr<API::Data> keyData = m_loaderClient->webCryptoMasterKey(*this)) + masterKey = keyData->dataReference().vector(); + else if (!getDefaultWebCryptoMasterKey(masterKey)) { + succeeded = false; + return; + } + + succeeded = unwrapSerializedCryptoKey(masterKey, wrappedKey, key); +} +#endif + +void WebPageProxy::addMIMETypeWithCustomContentProvider(const String& mimeType) +{ + m_process->send(Messages::WebPage::AddMIMETypeWithCustomContentProvider(mimeType), m_pageID); +} + +#if PLATFORM(COCOA) + +void WebPageProxy::insertTextAsync(const String& text, const EditingRange& replacementRange, bool registerUndoGroup, EditingRangeIsRelativeTo editingRangeIsRelativeTo) +{ + if (!isValid()) + return; + + process().send(Messages::WebPage::InsertTextAsync(text, replacementRange, registerUndoGroup, static_cast<uint32_t>(editingRangeIsRelativeTo)), m_pageID); +} + +void WebPageProxy::getMarkedRangeAsync(std::function<void (EditingRange, CallbackBase::Error)> callbackFunction) +{ + if (!isValid()) { + callbackFunction(EditingRange(), CallbackBase::Error::Unknown); + return; + } + + uint64_t callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken()); + process().send(Messages::WebPage::GetMarkedRangeAsync(callbackID), m_pageID); +} + +void WebPageProxy::getSelectedRangeAsync(std::function<void (EditingRange, CallbackBase::Error)> callbackFunction) +{ + if (!isValid()) { + callbackFunction(EditingRange(), CallbackBase::Error::Unknown); + return; + } + + uint64_t callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken()); + process().send(Messages::WebPage::GetSelectedRangeAsync(callbackID), m_pageID); +} + +void WebPageProxy::characterIndexForPointAsync(const WebCore::IntPoint& point, std::function<void (uint64_t, CallbackBase::Error)> callbackFunction) +{ + if (!isValid()) { + callbackFunction(0, CallbackBase::Error::Unknown); + return; + } + + uint64_t callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken()); + process().send(Messages::WebPage::CharacterIndexForPointAsync(point, callbackID), m_pageID); +} + +void WebPageProxy::firstRectForCharacterRangeAsync(const EditingRange& range, std::function<void (const WebCore::IntRect&, const EditingRange&, CallbackBase::Error)> callbackFunction) +{ + if (!isValid()) { + callbackFunction(WebCore::IntRect(), EditingRange(), CallbackBase::Error::Unknown); + return; + } + + uint64_t callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken()); + process().send(Messages::WebPage::FirstRectForCharacterRangeAsync(range, callbackID), m_pageID); +} + +void WebPageProxy::setCompositionAsync(const String& text, Vector<CompositionUnderline> underlines, const EditingRange& selectionRange, const EditingRange& replacementRange) +{ + if (!isValid()) { + // If this fails, we should call -discardMarkedText on input context to notify the input method. + // This will happen naturally later, as part of reloading the page. + return; + } + + process().send(Messages::WebPage::SetCompositionAsync(text, underlines, selectionRange, replacementRange), m_pageID); +} + +void WebPageProxy::confirmCompositionAsync() +{ + if (!isValid()) + return; + + process().send(Messages::WebPage::ConfirmCompositionAsync(), m_pageID); +} + +void WebPageProxy::setScrollPerformanceDataCollectionEnabled(bool enabled) +{ + if (enabled == m_scrollPerformanceDataCollectionEnabled) + return; + + m_scrollPerformanceDataCollectionEnabled = enabled; + + if (m_scrollPerformanceDataCollectionEnabled && !m_scrollingPerformanceData) + m_scrollingPerformanceData = std::make_unique<RemoteLayerTreeScrollingPerformanceData>(downcast<RemoteLayerTreeDrawingAreaProxy>(*m_drawingArea)); + else if (!m_scrollPerformanceDataCollectionEnabled) + m_scrollingPerformanceData = nullptr; +} +#endif + +void WebPageProxy::takeSnapshot(IntRect rect, IntSize bitmapSize, SnapshotOptions options, std::function<void (const ShareableBitmap::Handle&, CallbackBase::Error)> callbackFunction) +{ + if (!isValid()) { + callbackFunction(ShareableBitmap::Handle(), CallbackBase::Error::Unknown); + return; + } + + uint64_t callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken()); + m_process->send(Messages::WebPage::TakeSnapshot(rect, bitmapSize, options, callbackID), m_pageID); +} + +void WebPageProxy::navigationGestureDidBegin() +{ + PageClientProtector protector(m_pageClient); + + m_isShowingNavigationGestureSnapshot = true; + m_pageClient.navigationGestureDidBegin(); + + if (m_navigationClient) + m_navigationClient->didBeginNavigationGesture(*this); + else + m_loaderClient->navigationGestureDidBegin(*this); +} + +void WebPageProxy::navigationGestureWillEnd(bool willNavigate, WebBackForwardListItem& item) +{ + PageClientProtector protector(m_pageClient); + + m_pageClient.navigationGestureWillEnd(willNavigate, item); + + if (m_navigationClient) + m_navigationClient->willEndNavigationGesture(*this, willNavigate, item); + else + m_loaderClient->navigationGestureWillEnd(*this, willNavigate, item); +} + +void WebPageProxy::navigationGestureDidEnd(bool willNavigate, WebBackForwardListItem& item) +{ + PageClientProtector protector(m_pageClient); + + m_pageClient.navigationGestureDidEnd(willNavigate, item); + + if (m_navigationClient) + m_navigationClient->didEndNavigationGesture(*this, willNavigate, item); + else + m_loaderClient->navigationGestureDidEnd(*this, willNavigate, item); +} + +void WebPageProxy::navigationGestureDidEnd() +{ + PageClientProtector protector(m_pageClient); + + m_pageClient.navigationGestureDidEnd(); +} + +void WebPageProxy::willRecordNavigationSnapshot(WebBackForwardListItem& item) +{ + PageClientProtector protector(m_pageClient); + + m_pageClient.willRecordNavigationSnapshot(item); +} + +void WebPageProxy::navigationGestureSnapshotWasRemoved() +{ + m_isShowingNavigationGestureSnapshot = false; + + m_pageClient.didRemoveNavigationGestureSnapshot(); + + if (m_navigationClient) + m_navigationClient->didRemoveNavigationGestureSnapshot(*this); +} + +void WebPageProxy::isPlayingMediaDidChange(MediaProducer::MediaStateFlags state, uint64_t sourceElementID) +{ +#if ENABLE(MEDIA_SESSION) + WebMediaSessionFocusManager* focusManager = process().processPool().supplement<WebMediaSessionFocusManager>(); + ASSERT(focusManager); + focusManager->updatePlaybackAttributesFromMediaState(this, sourceElementID, state); +#endif + + if (state == m_mediaState) + return; + + MediaProducer::MediaStateFlags oldState = m_mediaState; + m_mediaState = state; + + if ((oldState & MediaProducer::IsPlayingAudio) == (m_mediaState & MediaProducer::IsPlayingAudio)) + return; + + m_uiClient->isPlayingAudioDidChange(*this); +} + +#if ENABLE(MEDIA_SESSION) +void WebPageProxy::hasMediaSessionWithActiveMediaElementsDidChange(bool state) +{ + m_hasMediaSessionWithActiveMediaElements = state; +} + +void WebPageProxy::mediaSessionMetadataDidChange(const WebCore::MediaSessionMetadata& metadata) +{ + Ref<WebMediaSessionMetadata> webMetadata = WebMediaSessionMetadata::create(metadata); + m_uiClient->mediaSessionMetadataDidChange(*this, webMetadata.ptr()); +} + +void WebPageProxy::focusedContentMediaElementDidChange(uint64_t elementID) +{ + WebMediaSessionFocusManager* focusManager = process().processPool().supplement<WebMediaSessionFocusManager>(); + ASSERT(focusManager); + focusManager->setFocusedMediaElement(*this, elementID); +} +#endif + +#if PLATFORM(MAC) +void WebPageProxy::removeNavigationGestureSnapshot() +{ + m_pageClient.removeNavigationGestureSnapshot(); +} + +void WebPageProxy::performImmediateActionHitTestAtLocation(FloatPoint point) +{ + m_process->send(Messages::WebPage::PerformImmediateActionHitTestAtLocation(point), m_pageID); +} + +void WebPageProxy::immediateActionDidUpdate() +{ + m_process->send(Messages::WebPage::ImmediateActionDidUpdate(), m_pageID); +} + +void WebPageProxy::immediateActionDidCancel() +{ + m_process->send(Messages::WebPage::ImmediateActionDidCancel(), m_pageID); +} + +void WebPageProxy::immediateActionDidComplete() +{ + m_process->send(Messages::WebPage::ImmediateActionDidComplete(), m_pageID); +} + +void WebPageProxy::didPerformImmediateActionHitTest(const WebHitTestResultData& result, bool contentPreventsDefault, const UserData& userData) +{ + m_pageClient.didPerformImmediateActionHitTest(result, contentPreventsDefault, m_process->transformHandlesToObjects(userData.object()).get()); +} + +void* WebPageProxy::immediateActionAnimationControllerForHitTestResult(RefPtr<API::HitTestResult> hitTestResult, uint64_t type, RefPtr<API::Object> userData) +{ + return m_pageClient.immediateActionAnimationControllerForHitTestResult(hitTestResult, type, userData); +} + +void WebPageProxy::installViewStateChangeCompletionHandler(void (^completionHandler)()) +{ + if (!isValid()) { + completionHandler(); + return; + } + + auto copiedCompletionHandler = Block_copy(completionHandler); + RefPtr<VoidCallback> voidCallback = VoidCallback::create([copiedCompletionHandler] (CallbackBase::Error) { + copiedCompletionHandler(); + Block_release(copiedCompletionHandler); + }, m_process->throttler().backgroundActivityToken()); + uint64_t callbackID = m_callbacks.put(voidCallback.release()); + m_nextViewStateChangeCallbacks.append(callbackID); +} + +void WebPageProxy::handleAcceptedCandidate(WebCore::TextCheckingResult acceptedCandidate) +{ + m_process->send(Messages::WebPage::HandleAcceptedCandidate(acceptedCandidate), m_pageID); +} + +void WebPageProxy::didHandleAcceptedCandidate() +{ + m_pageClient.didHandleAcceptedCandidate(); +} +#endif + +void WebPageProxy::imageOrMediaDocumentSizeChanged(const WebCore::IntSize& newSize) +{ + m_uiClient->imageOrMediaDocumentSizeChanged(newSize); +} + +void WebPageProxy::setShouldDispatchFakeMouseMoveEvents(bool shouldDispatchFakeMouseMoveEvents) +{ + m_process->send(Messages::WebPage::SetShouldDispatchFakeMouseMoveEvents(shouldDispatchFakeMouseMoveEvents), m_pageID); +} + +void WebPageProxy::handleAutoFillButtonClick(const UserData& userData) +{ + m_uiClient->didClickAutoFillButton(*this, m_process->transformHandlesToObjects(userData.object()).get()); +} + +#if ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS) +void WebPageProxy::addPlaybackTargetPickerClient(uint64_t contextId) +{ + m_pageClient.mediaSessionManager().addPlaybackTargetPickerClient(*this, contextId); +} + +void WebPageProxy::removePlaybackTargetPickerClient(uint64_t contextId) +{ + m_pageClient.mediaSessionManager().removePlaybackTargetPickerClient(*this, contextId); +} + +void WebPageProxy::showPlaybackTargetPicker(uint64_t contextId, const WebCore::FloatRect& rect, bool hasVideo) +{ + m_pageClient.mediaSessionManager().showPlaybackTargetPicker(*this, contextId, m_pageClient.rootViewToScreen(IntRect(rect)), hasVideo); +} + +void WebPageProxy::playbackTargetPickerClientStateDidChange(uint64_t contextId, WebCore::MediaProducer::MediaStateFlags state) +{ + m_pageClient.mediaSessionManager().clientStateDidChange(*this, contextId, state); +} + +void WebPageProxy::setMockMediaPlaybackTargetPickerEnabled(bool enabled) +{ + m_pageClient.mediaSessionManager().setMockMediaPlaybackTargetPickerEnabled(enabled); +} + +void WebPageProxy::setMockMediaPlaybackTargetPickerState(const String& name, WebCore::MediaPlaybackTargetContext::State state) +{ + m_pageClient.mediaSessionManager().setMockMediaPlaybackTargetPickerState(name, state); +} + +void WebPageProxy::setPlaybackTarget(uint64_t contextId, Ref<MediaPlaybackTarget>&& target) +{ + if (!isValid()) + return; + + m_process->send(Messages::WebPage::PlaybackTargetSelected(contextId, target->targetContext()), m_pageID); +} + +void WebPageProxy::externalOutputDeviceAvailableDidChange(uint64_t contextId, bool available) +{ + if (!isValid()) + return; + + m_process->send(Messages::WebPage::PlaybackTargetAvailabilityDidChange(contextId, available), m_pageID); +} + +void WebPageProxy::setShouldPlayToPlaybackTarget(uint64_t contextId, bool shouldPlay) +{ + if (!isValid()) + return; + + m_process->send(Messages::WebPage::SetShouldPlayToPlaybackTarget(contextId, shouldPlay), m_pageID); +} +#endif + +void WebPageProxy::didChangeBackgroundColor() +{ + m_pageClient.didChangeBackgroundColor(); +} + +void WebPageProxy::clearWheelEventTestTrigger() +{ + if (!isValid()) + return; + + m_process->send(Messages::WebPage::ClearWheelEventTestTrigger(), m_pageID); +} + +void WebPageProxy::callAfterNextPresentationUpdate(std::function<void (CallbackBase::Error)> callback) +{ + m_drawingArea->dispatchAfterEnsuringDrawing(callback); +} + +void WebPageProxy::setShouldScaleViewToFitDocument(bool shouldScaleViewToFitDocument) +{ + if (m_shouldScaleViewToFitDocument == shouldScaleViewToFitDocument) + return; + + m_shouldScaleViewToFitDocument = shouldScaleViewToFitDocument; + + if (!isValid()) + return; + + m_process->send(Messages::WebPage::SetShouldScaleViewToFitDocument(shouldScaleViewToFitDocument), m_pageID); +} + +void WebPageProxy::didRestoreScrollPosition() +{ + m_pageClient.didRestoreScrollPosition(); +} + } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebPageProxy.h b/Source/WebKit2/UIProcess/WebPageProxy.h index ae0a5a543..29c77012d 100644 --- a/Source/WebKit2/UIProcess/WebPageProxy.h +++ b/Source/WebKit2/UIProcess/WebPageProxy.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2011 Apple Inc. All rights reserved. + * Copyright (C) 2010, 2011, 2014-2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,59 +28,66 @@ #include "APIObject.h" #include "APISession.h" +#include "AssistedNodeInformation.h" #include "AutoCorrectionCallback.h" #include "Connection.h" +#include "ContextMenuContextData.h" +#include "DownloadID.h" #include "DragControllerAction.h" #include "DrawingAreaProxy.h" +#include "EditingRange.h" #include "EditorState.h" #include "GeolocationPermissionRequestManagerProxy.h" -#include "InteractionInformationAtPosition.h" #include "LayerTreeContext.h" #include "MessageSender.h" #include "NotificationPermissionRequestManagerProxy.h" #include "PageLoadState.h" -#include "PlatformProcessIdentifier.h" +#include "ProcessThrottler.h" #include "SandboxExtension.h" #include "ShareableBitmap.h" +#include "UserMediaPermissionRequestManagerProxy.h" +#include "VisibleContentRectUpdateInfo.h" #include "WKBase.h" #include "WKPagePrivate.h" #include "WebColorPicker.h" #include "WebContextMenuItemData.h" #include "WebCoreArgumentCoders.h" -#include "WebFindClient.h" -#include "WebFormClient.h" #include "WebFrameProxy.h" -#include "WebHistoryClient.h" -#include "WebHitTestResult.h" -#include "WebPageContextMenuClient.h" #include "WebPageCreationParameters.h" +#include "WebPageDiagnosticLoggingClient.h" +#include "WebPageInjectedBundleClient.h" +#include "WebPreferences.h" #include <WebCore/AlternativeTextClient.h> // FIXME: Needed by WebPageProxyMessages.h for DICTATION_ALTERNATIVES. #include "WebPageProxyMessages.h" #include "WebPopupMenuProxy.h" -#include "WebUIClient.h" +#include "WebProcessLifetimeTracker.h" #include <WebCore/Color.h> #include <WebCore/DragActions.h> -#include <WebCore/DragSession.h> +#include <WebCore/FrameLoaderTypes.h> #include <WebCore/HitTestResult.h> +#include <WebCore/MediaProducer.h> #include <WebCore/Page.h> #include <WebCore/PlatformScreen.h> #include <WebCore/ScrollTypes.h> +#include <WebCore/SearchPopupMenu.h> #include <WebCore/TextChecking.h> #include <WebCore/TextGranularity.h> #include <WebCore/ViewState.h> +#include <WebCore/VisibleSelection.h> +#include <memory> #include <wtf/HashMap.h> #include <wtf/HashSet.h> -#include <wtf/OwnPtr.h> -#include <wtf/PassOwnPtr.h> #include <wtf/PassRefPtr.h> #include <wtf/Ref.h> #include <wtf/RefPtr.h> #include <wtf/Vector.h> #include <wtf/text/WTFString.h> +OBJC_CLASS NSView; +OBJC_CLASS _WKRemoteObjectRegistry; + #if ENABLE(DRAG_SUPPORT) #include <WebCore/DragActions.h> -#include <WebCore/DragSession.h> #endif #if ENABLE(TOUCH_EVENTS) @@ -93,13 +100,48 @@ #include <Evas.h> #endif +#if PLATFORM(COCOA) +#include "LayerRepresentation.h" +#endif + #if PLATFORM(MAC) -#include <WebCore/PlatformLayer.h> +#include "AttributedString.h" +#endif + +#if PLATFORM(IOS) +#include "ProcessThrottler.h" +#endif + +#if PLATFORM(GTK) +#include "ArgumentCodersGtk.h" +#endif + +#if ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS) +#include <WebCore/MediaPlaybackTargetPicker.h> +#include <WebCore/WebMediaSessionManagerClient.h> +#endif + +#if USE(APPLE_INTERNAL_SDK) +#include <WebKitAdditions/WebPageProxyIncludes.h> +#endif + +#if ENABLE(MEDIA_SESSION) +namespace WebCore { +class MediaSessionMetadata; +} #endif namespace API { +class ContextMenuClient; +class FindClient; +class FindMatchesClient; +class FormClient; +class HistoryClient; class LoaderClient; +class Navigation; +class NavigationClient; class PolicyClient; +class UIClient; class URLRequest; } @@ -115,19 +157,21 @@ class DragData; class FloatRect; class GraphicsLayer; class IntSize; +class MediaConstraintsImpl; class ProtectionSpace; +class RunLoopObserver; class SharedBuffer; +class TextIndicator; +struct DictionaryPopupInfo; +struct ExceptionDetails; struct FileChooserSettings; +struct SecurityOriginData; struct TextAlternativeWithRange; struct TextCheckingResult; struct ViewportAttributes; struct WindowFeatures; } -#if USE(APPKIT) -OBJC_CLASS WKView; -#endif - #if PLATFORM(GTK) typedef GtkWidget* PlatformWidget; #endif @@ -135,27 +179,36 @@ typedef GtkWidget* PlatformWidget; namespace WebKit { class CertificateInfo; +class NativeWebGestureEvent; class NativeWebKeyboardEvent; class NativeWebMouseEvent; class NativeWebWheelEvent; class PageClient; +class RemoteLayerTreeScrollingPerformanceData; +class RemoteLayerTreeTransaction; class RemoteScrollingCoordinatorProxy; class StringPairVector; +class UserData; +class ViewSnapshot; +class VisitedLinkStore; class WebBackForwardList; class WebBackForwardListItem; -class WebColorPickerResultListenerProxy; class WebContextMenuProxy; class WebEditCommandProxy; class WebFullScreenManagerProxy; +class WebNavigationState; +class WebVideoFullscreenManagerProxy; class WebKeyboardEvent; class WebMouseEvent; class WebOpenPanelResultListenerProxy; class WebPageGroup; class WebProcessProxy; +class WebUserContentControllerProxy; class WebWheelEvent; +class WebsiteDataStore; struct AttributedString; struct ColorSpaceData; -struct DictionaryPopupInfo; +struct EditingRange; struct EditorState; struct PlatformPopupMenuData; struct PrintInfo; @@ -165,11 +218,17 @@ struct WebPopupItem; class WebVibrationProxy; #endif -typedef GenericCallback<WKStringRef, StringImpl*> StringCallback; -typedef GenericCallback<WKSerializedScriptValueRef, WebSerializedScriptValue*> ScriptValueCallback; +#if USE(QUICK_LOOK) +class QuickLookDocumentData; +#endif + +typedef GenericCallback<uint64_t> UnsignedCallback; +typedef GenericCallback<EditingRange> EditingRangeCallback; +typedef GenericCallback<const String&> StringCallback; +typedef GenericCallback<API::SerializedScriptValue*, bool, const WebCore::ExceptionDetails&> ScriptValueCallback; #if PLATFORM(GTK) -typedef GenericCallback<WKErrorRef> PrintFinishedCallback; +typedef GenericCallback<API::Error*> PrintFinishedCallback; #endif #if ENABLE(TOUCH_EVENTS) @@ -183,179 +242,83 @@ struct QueuedTouchEvents { }; #endif -// FIXME: Make a version of CallbackBase with three arguments, and define ValidateCommandCallback as a specialization. -class ValidateCommandCallback : public CallbackBase { -public: - typedef void (*CallbackFunction)(WKStringRef, bool, int32_t, WKErrorRef, void*); - - static PassRefPtr<ValidateCommandCallback> create(void* context, CallbackFunction callback) - { - return adoptRef(new ValidateCommandCallback(context, callback)); - } - - virtual ~ValidateCommandCallback() - { - ASSERT(!m_callback); - } - - void performCallbackWithReturnValue(StringImpl* returnValue1, bool returnValue2, int returnValue3) - { - ASSERT(m_callback); - - m_callback(toAPI(returnValue1), returnValue2, returnValue3, 0, context()); - - m_callback = 0; - } - - void invalidate() - { - ASSERT(m_callback); - - RefPtr<API::Error> error = API::Error::create(); - m_callback(0, 0, 0, toAPI(error.get()), context()); - - m_callback = 0; - } - -private: - - ValidateCommandCallback(void* context, CallbackFunction callback) - : CallbackBase(context) - , m_callback(callback) - { - } +typedef GenericCallback<const String&, bool, int32_t> ValidateCommandCallback; +typedef GenericCallback<const WebCore::IntRect&, const EditingRange&> RectForCharacterRangeCallback; - CallbackFunction m_callback; -}; +#if PLATFORM(MAC) +typedef GenericCallback<const AttributedString&, const EditingRange&> AttributedStringForCharacterRangeCallback; +typedef GenericCallback<const String&, double, bool> FontAtSelectionCallback; +#endif #if PLATFORM(IOS) -class GestureCallback : public CallbackBase { -public: - typedef void (*CallbackFunction)(const WebCore::IntPoint&, uint32_t, uint32_t, uint32_t, WKErrorRef, void*); - - static PassRefPtr<GestureCallback> create(void* context, CallbackFunction callback) - { - return adoptRef(new GestureCallback(context, callback)); - } - - virtual ~GestureCallback() - { - ASSERT(!m_callback); - } - - void performCallbackWithReturnValue(const WebCore::IntPoint& returnValue1, uint32_t returnValue2, uint32_t returnValue3, uint32_t returnValue4) - { - ASSERT(m_callback); - - m_callback(returnValue1, returnValue2, returnValue3, returnValue4, 0, context()); - - m_callback = 0; - } - - void invalidate() - { - ASSERT(m_callback); - - RefPtr<API::Error> error = API::Error::create(); - m_callback(WebCore::IntPoint(), 0, 0, 0, toAPI(error.get()), context()); - - m_callback = 0; - } - -private: - - GestureCallback(void* context, CallbackFunction callback) - : CallbackBase(context) - , m_callback(callback) - { - ASSERT(m_callback); - } - - CallbackFunction m_callback; -}; - -class TouchesCallback : public CallbackBase { -public: - typedef void (*CallbackFunction)(const WebCore::IntPoint&, uint32_t, WKErrorRef, void*); - - static PassRefPtr<TouchesCallback> create(void* context, CallbackFunction callback) - { - return adoptRef(new TouchesCallback(context, callback)); - } - - virtual ~TouchesCallback() - { - ASSERT(!m_callback); - } - - void performCallbackWithReturnValue(const WebCore::IntPoint& returnValue1, uint32_t returnValue2) - { - ASSERT(m_callback); - - m_callback(returnValue1, returnValue2, 0, context()); - - m_callback = 0; - } - - void invalidate() - { - ASSERT(m_callback); - - RefPtr<API::Error> error = API::Error::create(); - m_callback(WebCore::IntPoint(), 0, toAPI(error.get()), context()); - - m_callback = 0; - } - -private: - - TouchesCallback(void* context, CallbackFunction callback) - : CallbackBase(context) - , m_callback(callback) - { - ASSERT(m_callback); - } - - CallbackFunction m_callback; +typedef GenericCallback<const WebCore::IntPoint&, uint32_t, uint32_t, uint32_t> GestureCallback; +typedef GenericCallback<const WebCore::IntPoint&, uint32_t> TouchesCallback; +struct NodeAssistanceArguments { + AssistedNodeInformation m_nodeInformation; + bool m_userIsInteracting; + bool m_blurPreviousNode; + RefPtr<API::Object> m_userData; }; #endif -struct WebPageConfiguration { - WebPageGroup* pageGroup = nullptr; - API::Session* session = nullptr; - WebPageProxy* relatedPage = nullptr; -}; +#if PLATFORM(COCOA) +typedef GenericCallback<const WebCore::MachSendRight&> MachSendRightCallback; +#endif class WebPageProxy : public API::ObjectImpl<API::Object::Type::Page> #if ENABLE(INPUT_TYPE_COLOR) , public WebColorPicker::Client #endif +#if ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS) + , public WebCore::WebMediaSessionManagerClient +#endif , public WebPopupMenuProxy::Client , public IPC::MessageReceiver , public IPC::MessageSender { public: - static PassRefPtr<WebPageProxy> create(PageClient&, WebProcessProxy&, uint64_t pageID, const WebPageConfiguration&); + static Ref<WebPageProxy> create(PageClient&, WebProcessProxy&, uint64_t pageID, Ref<API::PageConfiguration>&&); virtual ~WebPageProxy(); - void setSession(API::Session&); + const API::PageConfiguration& configuration() const; uint64_t pageID() const { return m_pageID; } - uint64_t sessionID() const { return m_session->getID(); } + WebCore::SessionID sessionID() const { return m_sessionID; } + void setSessionID(WebCore::SessionID); WebFrameProxy* mainFrame() const { return m_mainFrame.get(); } WebFrameProxy* focusedFrame() const { return m_focusedFrame.get(); } WebFrameProxy* frameSetLargestFrame() const { return m_frameSetLargestFrame.get(); } DrawingAreaProxy* drawingArea() const { return m_drawingArea.get(); } - + + WebNavigationState& navigationState() { return *m_navigationState.get(); } + + WebsiteDataStore& websiteDataStore() { return m_websiteDataStore; } + +#if ENABLE(DATA_DETECTION) + NSArray *dataDetectionResults() { return m_dataDetectionResults.get(); } +#endif + #if ENABLE(ASYNC_SCROLLING) RemoteScrollingCoordinatorProxy* scrollingCoordinatorProxy() const { return m_scrollingCoordinatorProxy.get(); } #endif - WebBackForwardList& backForwardList() { return m_backForwardList.get(); } + WebBackForwardList& backForwardList() { return m_backForwardList; } + + bool addsVisitedLinks() const { return m_addsVisitedLinks; } + void setAddsVisitedLinks(bool addsVisitedLinks) { m_addsVisitedLinks = addsVisitedLinks; } + + void fullscreenMayReturnToInline(); + void didEnterFullscreen(); + void didExitFullscreen(); -#if ENABLE(INSPECTOR) WebInspectorProxy* inspector(); + +#if ENABLE(REMOTE_INSPECTOR) + bool allowsRemoteInspection() const { return m_allowsRemoteInspection; } + void setAllowsRemoteInspection(bool); + String remoteInspectionNameOverride() const { return m_remoteInspectionNameOverride; } + void setRemoteInspectionNameOverride(const String&); #endif #if ENABLE(VIBRATION) @@ -365,16 +328,35 @@ public: #if ENABLE(FULLSCREEN_API) WebFullScreenManagerProxy* fullScreenManager(); #endif +#if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)) + RefPtr<WebVideoFullscreenManagerProxy> videoFullscreenManager(); +#endif -#if ENABLE(CONTEXT_MENUS) - void initializeContextMenuClient(const WKPageContextMenuClientBase*); +#if PLATFORM(IOS) + bool allowsMediaDocumentInlinePlayback() const; + void setAllowsMediaDocumentInlinePlayback(bool); #endif - void initializeFindClient(const WKPageFindClientBase*); - void initializeFindMatchesClient(const WKPageFindMatchesClientBase*); - void initializeFormClient(const WKPageFormClientBase*); + +#if ENABLE(CONTEXT_MENUS) + API::ContextMenuClient& contextMenuClient() { return *m_contextMenuClient; } + void setContextMenuClient(std::unique_ptr<API::ContextMenuClient>); +#endif + API::FindClient& findClient() { return *m_findClient; } + void setFindClient(std::unique_ptr<API::FindClient>); + API::FindMatchesClient& findMatchesClient() { return *m_findMatchesClient; } + void setFindMatchesClient(std::unique_ptr<API::FindMatchesClient>); + API::DiagnosticLoggingClient& diagnosticLoggingClient() { return *m_diagnosticLoggingClient; } + void setDiagnosticLoggingClient(std::unique_ptr<API::DiagnosticLoggingClient>); + void setFormClient(std::unique_ptr<API::FormClient>); + void setNavigationClient(std::unique_ptr<API::NavigationClient>); + void setHistoryClient(std::unique_ptr<API::HistoryClient>); void setLoaderClient(std::unique_ptr<API::LoaderClient>); void setPolicyClient(std::unique_ptr<API::PolicyClient>); - void initializeUIClient(const WKPageUIClientBase*); + void setInjectedBundleClient(const WKPageInjectedBundleClientBase*); + WebPageInjectedBundleClient* injectedBundleClient() { return m_injectedBundleClient.get(); } + + API::UIClient& uiClient() { return *m_uiClient; } + void setUIClient(std::unique_ptr<API::UIClient>); #if PLATFORM(EFL) void initializeUIPopupMenuClient(const WKPageUIPopupMenuClientBase*); #endif @@ -385,24 +367,27 @@ public: bool tryClose(); bool isClosed() const { return m_isClosed; } - void loadRequest(const WebCore::ResourceRequest&, API::Object* userData = nullptr); - void loadFile(const String& fileURL, const String& resourceDirectoryURL, API::Object* userData = nullptr); - void loadData(API::Data*, const String& MIMEType, const String& encoding, const String& baseURL, API::Object* userData = nullptr); - void loadHTMLString(const String& htmlString, const String& baseURL, API::Object* userData = nullptr); + RefPtr<API::Navigation> loadRequest(const WebCore::ResourceRequest&, WebCore::ShouldOpenExternalURLsPolicy = WebCore::ShouldOpenExternalURLsPolicy::ShouldAllowExternalSchemes, API::Object* userData = nullptr); + RefPtr<API::Navigation> loadFile(const String& fileURL, const String& resourceDirectoryURL, API::Object* userData = nullptr); + RefPtr<API::Navigation> loadData(API::Data*, const String& MIMEType, const String& encoding, const String& baseURL, API::Object* userData = nullptr); + RefPtr<API::Navigation> loadHTMLString(const String& htmlString, const String& baseURL, API::Object* userData = nullptr); void loadAlternateHTMLString(const String& htmlString, const String& baseURL, const String& unreachableURL, API::Object* userData = nullptr); void loadPlainTextString(const String&, API::Object* userData = nullptr); void loadWebArchiveData(API::Data*, API::Object* userData = nullptr); + void navigateToPDFLinkWithSimulatedClick(const String& url, WebCore::IntPoint documentPoint, WebCore::IntPoint screenPoint); void stopLoading(); - void reload(bool reloadFromOrigin); + RefPtr<API::Navigation> reload(bool reloadFromOrigin, bool contentBlockersEnabled); - void goForward(); - void goBack(); + RefPtr<API::Navigation> goForward(); + RefPtr<API::Navigation> goBack(); - void goToBackForwardItem(WebBackForwardListItem*); + RefPtr<API::Navigation> goToBackForwardItem(WebBackForwardListItem*); void tryRestoreScrollPosition(); - void didChangeBackForwardList(WebBackForwardListItem* addedItem, Vector<RefPtr<API::Object>>* removedItems); - void willGoToBackForwardListItem(uint64_t itemID, IPC::MessageDecoder&); + void didChangeBackForwardList(WebBackForwardListItem* addedItem, Vector<RefPtr<WebBackForwardListItem>> removed); + void willGoToBackForwardListItem(uint64_t itemID, const UserData&); + + bool shouldKeepCurrentBackForwardListItemInList(WebBackForwardListItem*); bool willHandleHorizontalScrollEvents() const; @@ -411,50 +396,50 @@ public: bool drawsBackground() const { return m_drawsBackground; } void setDrawsBackground(bool); - bool drawsTransparentBackground() const { return m_drawsTransparentBackground; } - void setDrawsTransparentBackground(bool); + float topContentInset() const { return m_topContentInset; } + void setTopContentInset(float); WebCore::Color underlayColor() const { return m_underlayColor; } void setUnderlayColor(const WebCore::Color&); + // At this time, m_pageExtendedBackgroundColor can be set via pageExtendedBackgroundColorDidChange() which is a message + // from the UIProcess, or by didCommitLayerTree(). When PLATFORM(MAC) adopts UI side compositing, we should get rid of + // the message entirely. + WebCore::Color pageExtendedBackgroundColor() const { return m_pageExtendedBackgroundColor; } + void viewWillStartLiveResize(); void viewWillEndLiveResize(); - void setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent&); - void setWindowResizerSize(const WebCore::IntSize&); + void setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent&, std::function<void (CallbackBase::Error)>); void clearSelection(); + void restoreSelectionInFocusedEditableElement(); void setViewNeedsDisplay(const WebCore::IntRect&); void displayView(); bool canScrollView(); - void scrollView(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset); + void scrollView(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset); // FIXME: CoordinatedGraphics should use requestScroll(). + void requestScroll(const WebCore::FloatPoint& scrollPosition, const WebCore::IntPoint& scrollOrigin, bool isProgrammaticScroll); + + void setDelegatesScrolling(bool delegatesScrolling) { m_delegatesScrolling = delegatesScrolling; } + bool delegatesScrolling() const { return m_delegatesScrolling; } - enum class WantsReplyOrNot { DoesNotWantReply, DoesWantReply }; - void viewStateDidChange(WebCore::ViewState::Flags mayHaveChanged, WantsReplyOrNot = WantsReplyOrNot::DoesNotWantReply); + enum class ViewStateChangeDispatchMode { Deferrable, Immediate }; + void viewStateDidChange(WebCore::ViewState::Flags mayHaveChanged, bool wantsSynchronousReply = false, ViewStateChangeDispatchMode = ViewStateChangeDispatchMode::Deferrable); bool isInWindow() const { return m_viewState & WebCore::ViewState::IsInWindow; } void waitForDidUpdateViewState(); + void didUpdateViewState() { m_waitingForDidUpdateViewState = false; } + + void layerHostingModeDidChange(); WebCore::IntSize viewSize() const; bool isViewVisible() const { return m_viewState & WebCore::ViewState::IsVisible; } bool isViewWindowActive() const; - bool isProcessSuppressible() const; - void executeEditCommand(const String& commandName); - void validateCommand(const String& commandName, PassRefPtr<ValidateCommandCallback>); -#if PLATFORM(IOS) - void selectWithGesture(const WebCore::IntPoint, WebCore::TextGranularity, uint32_t gestureType, uint32_t gestureState, PassRefPtr<GestureCallback>); - void updateSelectionWithTouches(const WebCore::IntPoint, uint32_t touches, bool baseIsStart, PassRefPtr<TouchesCallback>); - void selectWithTwoTouches(const WebCore::IntPoint from, const WebCore::IntPoint to, uint32_t gestureType, uint32_t gestureState, PassRefPtr<GestureCallback>); - void extendSelection(WebCore::TextGranularity); - void requestAutocorrectionData(const String& textForAutocorrection, PassRefPtr<AutocorrectionDataCallback>); - void applyAutocorrection(const String& correction, const String& originalText, PassRefPtr<StringCallback>); - void requestAutocorrectionContext(PassRefPtr<AutocorrectionContextCallback>); - void getAutocorrectionContext(String& contextBefore, String& markedText, String& selectedText, String& contextAfter, uint64_t& location, uint64_t& length); - void didReceivePositionInformation(const InteractionInformationAtPosition&); - void getPositionInformation(const WebCore::IntPoint&, InteractionInformationAtPosition&); - void requestPositionInformation(const WebCore::IntPoint&); -#endif + void addMIMETypeWithCustomContentProvider(const String& mimeType); + + void executeEditCommand(const String& commandName, const String& argument = String()); + void validateCommand(const String& commandName, std::function<void (const String&, bool, int32_t, CallbackBase::Error)>); const EditorState& editorState() const { return m_editorState; } bool canDelete() const { return hasSelectedRange() && isContentEditable(); } @@ -463,8 +448,88 @@ public: bool maintainsInactiveSelection() const { return m_maintainsInactiveSelection; } void setMaintainsInactiveSelection(bool); -#if USE(TILED_BACKING_STORE) + void setEditable(bool); + bool isEditable() const { return m_isEditable; } + +#if PLATFORM(IOS) + void executeEditCommand(const String& commandName, std::function<void (CallbackBase::Error)>); + double displayedContentScale() const { return m_lastVisibleContentRectUpdate.scale(); } + const WebCore::FloatRect& exposedContentRect() const { return m_lastVisibleContentRectUpdate.exposedRect(); } + const WebCore::FloatRect& unobscuredContentRect() const { return m_lastVisibleContentRectUpdate.unobscuredRect(); } + + void updateVisibleContentRects(const WebCore::FloatRect& exposedRect, const WebCore::FloatRect& unobscuredRect, const WebCore::FloatRect& unobscuredRectInScrollViewCoordinates, const WebCore::FloatRect& customFixedPositionRect, double scale, bool inStableState, bool isChangingObscuredInsetsInteractively, bool allowShrinkToFit, double timestamp, double horizontalVelocity, double verticalVelocity, double scaleChangeRate); + void resendLastVisibleContentRects(); + + enum class UnobscuredRectConstraint { ConstrainedToDocumentRect, Unconstrained }; + WebCore::FloatRect computeCustomFixedPositionRect(const WebCore::FloatRect& unobscuredContentRect, double displayedContentScale, UnobscuredRectConstraint = UnobscuredRectConstraint::Unconstrained) const; + void overflowScrollViewWillStartPanGesture(); + void overflowScrollViewDidScroll(); + void overflowScrollWillStartScroll(); + void overflowScrollDidEndScroll(); + + void dynamicViewportSizeUpdate(const WebCore::FloatSize& minimumLayoutSize, const WebCore::FloatSize& maximumUnobscuredSize, const WebCore::FloatRect& targetExposedContentRect, const WebCore::FloatRect& targetUnobscuredRect, const WebCore::FloatRect& targetUnobscuredRectInScrollViewCoordinates, double targetScale, int32_t deviceOrientation); + void synchronizeDynamicViewportUpdate(); + + void setViewportConfigurationMinimumLayoutSize(const WebCore::FloatSize&); + void setMaximumUnobscuredSize(const WebCore::FloatSize&); + void setDeviceOrientation(int32_t); + int32_t deviceOrientation() const { return m_deviceOrientation; } + void willCommitLayerTree(uint64_t transactionID); + + void selectWithGesture(const WebCore::IntPoint, WebCore::TextGranularity, uint32_t gestureType, uint32_t gestureState, bool isInteractingWithAssistedNode, std::function<void (const WebCore::IntPoint&, uint32_t, uint32_t, uint32_t, CallbackBase::Error)>); + void updateSelectionWithTouches(const WebCore::IntPoint, uint32_t touches, bool baseIsStart, std::function<void (const WebCore::IntPoint&, uint32_t, CallbackBase::Error)>); + void selectWithTwoTouches(const WebCore::IntPoint from, const WebCore::IntPoint to, uint32_t gestureType, uint32_t gestureState, std::function<void (const WebCore::IntPoint&, uint32_t, uint32_t, uint32_t, CallbackBase::Error)>); + void updateBlockSelectionWithTouch(const WebCore::IntPoint, uint32_t touch, uint32_t handlePosition); + void extendSelection(WebCore::TextGranularity); + void selectWordBackward(); + void moveSelectionByOffset(int32_t offset, std::function<void (CallbackBase::Error)>); + void selectTextWithGranularityAtPoint(const WebCore::IntPoint, WebCore::TextGranularity, bool isInteractingWithAssistedNode, std::function<void (CallbackBase::Error)>); + void selectPositionAtPoint(const WebCore::IntPoint, bool isInteractingWithAssistedNode, std::function<void (CallbackBase::Error)>); + void selectPositionAtBoundaryWithDirection(const WebCore::IntPoint, WebCore::TextGranularity, WebCore::SelectionDirection, bool isInteractingWithAssistedNode, std::function<void (CallbackBase::Error)>); + void moveSelectionAtBoundaryWithDirection(WebCore::TextGranularity, WebCore::SelectionDirection, std::function<void(CallbackBase::Error)>); + void beginSelectionInDirection(WebCore::SelectionDirection, std::function<void (uint64_t, CallbackBase::Error)>); + void updateSelectionWithExtentPoint(const WebCore::IntPoint, bool isInteractingWithAssistedNode, std::function<void (uint64_t, CallbackBase::Error)>); + void updateSelectionWithExtentPointAndBoundary(const WebCore::IntPoint, WebCore::TextGranularity, bool isInteractingWithAssistedNode, std::function<void(uint64_t, CallbackBase::Error)>); + void requestAutocorrectionData(const String& textForAutocorrection, std::function<void (const Vector<WebCore::FloatRect>&, const String&, double, uint64_t, CallbackBase::Error)>); + void applyAutocorrection(const String& correction, const String& originalText, std::function<void (const String&, CallbackBase::Error)>); + bool applyAutocorrection(const String& correction, const String& originalText); + void requestAutocorrectionContext(std::function<void (const String&, const String&, const String&, const String&, uint64_t, uint64_t, CallbackBase::Error)>); + void getAutocorrectionContext(String& contextBefore, String& markedText, String& selectedText, String& contextAfter, uint64_t& location, uint64_t& length); + void requestDictationContext(std::function<void (const String&, const String&, const String&, CallbackBase::Error)>); + void replaceDictatedText(const String& oldText, const String& newText); + void replaceSelectedText(const String& oldText, const String& newText); + void didReceivePositionInformation(const InteractionInformationAtPosition&); + void getPositionInformation(const WebCore::IntPoint&, InteractionInformationAtPosition&); + void requestPositionInformation(const WebCore::IntPoint&); + void startInteractionWithElementAtPosition(const WebCore::IntPoint&); + void stopInteraction(); + void performActionOnElement(uint32_t action); + void saveImageToLibrary(const SharedMemory::Handle& imageHandle, uint64_t imageSize); + void didUpdateBlockSelectionWithTouch(uint32_t touch, uint32_t flags, float growThreshold, float shrinkThreshold); + void focusNextAssistedNode(bool isForward, std::function<void (CallbackBase::Error)>); + void setAssistedNodeValue(const String&); + void setAssistedNodeValueAsNumber(double); + void setAssistedNodeSelectedIndex(uint32_t index, bool allowMultipleSelection = false); + void applicationDidEnterBackground(); + void applicationWillEnterForeground(); + void applicationWillResignActive(); + void applicationDidBecomeActive(); + void zoomToRect(WebCore::FloatRect, double minimumScale, double maximumScale); + void commitPotentialTapFailed(); + void didNotHandleTapAsClick(const WebCore::IntPoint&); + void disableDoubleTapGesturesDuringTapIfNecessary(uint64_t requestID); + void didFinishDrawingPagesToPDF(const IPC::DataReference&); + void contentSizeCategoryDidChange(const String& contentSizeCategory); + void getLookupContextAtPoint(const WebCore::IntPoint&, std::function<void(const String&, CallbackBase::Error)>); +#endif +#if ENABLE(DATA_DETECTION) + void setDataDetectionResult(const DataDetectionResult&); +#endif + void didCommitLayerTree(const WebKit::RemoteLayerTreeTransaction&); + +#if USE(COORDINATED_GRAPHICS_MULTIPROCESS) void didRenderFrame(const WebCore::IntSize& contentsSize, const WebCore::IntRect& coveredRect); + void commitPageTransitionViewport(); #endif #if PLATFORM(EFL) void setThemePath(const String&); @@ -480,51 +545,78 @@ public: void setInputMethodState(bool enabled); #endif -#if PLATFORM(MAC) +#if PLATFORM (GTK) && HAVE(GTK_GESTURES) + void getCenterForZoomGesture(const WebCore::IntPoint& centerInViewCoordinates, WebCore::IntPoint& center); +#endif + +#if PLATFORM(COCOA) void windowAndViewFramesChanged(const WebCore::FloatRect& viewFrameInWindowCoordinates, const WebCore::FloatPoint& accessibilityViewCoordinates); void setMainFrameIsScrollable(bool); - void setComposition(const String& text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeEnd); - void confirmComposition(); - void cancelComposition(); - bool insertText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd); - bool insertDictatedText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd, const Vector<WebCore::TextAlternativeWithRange>& dictationAlternatives); - void getMarkedRange(uint64_t& location, uint64_t& length); - void getSelectedRange(uint64_t& location, uint64_t& length); - void getAttributedSubstringFromRange(uint64_t location, uint64_t length, AttributedString&); - uint64_t characterIndexForPoint(const WebCore::IntPoint); - WebCore::IntRect firstRectForCharacterRange(uint64_t, uint64_t); - bool executeKeypressCommands(const Vector<WebCore::KeypressCommand>&); - void sendComplexTextInputToPlugin(uint64_t pluginComplexTextInputIdentifier, const String& textInput); bool shouldDelayWindowOrderingForEvent(const WebMouseEvent&); bool acceptsFirstMouse(int eventNumber, const WebMouseEvent&); - void setAcceleratedCompositingRootLayer(PlatformLayer* rootLayer); - PlatformLayer* acceleratedCompositingRootLayer() const; + void setAcceleratedCompositingRootLayer(LayerOrView*); + LayerOrView* acceleratedCompositingRootLayer() const; -#if USE(APPKIT) - WKView* wkView() const; - void intrinsicContentSizeDidChange(const WebCore::IntSize& intrinsicContentSize); + void insertTextAsync(const String& text, const EditingRange& replacementRange, bool registerUndoGroup = false, EditingRangeIsRelativeTo = EditingRangeIsRelativeTo::EditableRoot); + void getMarkedRangeAsync(std::function<void (EditingRange, CallbackBase::Error)>); + void getSelectedRangeAsync(std::function<void (EditingRange, CallbackBase::Error)>); + void characterIndexForPointAsync(const WebCore::IntPoint&, std::function<void (uint64_t, CallbackBase::Error)>); + void firstRectForCharacterRangeAsync(const EditingRange&, std::function<void (const WebCore::IntRect&, const EditingRange&, CallbackBase::Error)>); + void setCompositionAsync(const String& text, Vector<WebCore::CompositionUnderline> underlines, const EditingRange& selectionRange, const EditingRange& replacementRange); + void confirmCompositionAsync(); + + void setScrollPerformanceDataCollectionEnabled(bool); + bool scrollPerformanceDataCollectionEnabled() const { return m_scrollPerformanceDataCollectionEnabled; } + RemoteLayerTreeScrollingPerformanceData* scrollingPerformanceData() { return m_scrollingPerformanceData.get(); } +#endif // PLATFORM(COCOA) + +#if PLATFORM(MAC) + void insertDictatedTextAsync(const String& text, const EditingRange& replacementRange, const Vector<WebCore::TextAlternativeWithRange>& dictationAlternatives, bool registerUndoGroup); + void attributedSubstringForCharacterRangeAsync(const EditingRange&, std::function<void (const AttributedString&, const EditingRange&, CallbackBase::Error)>); + void setFont(const String& fontFamily, double fontSize, uint64_t fontTraits); + void fontAtSelection(std::function<void (const String&, double, bool, CallbackBase::Error)>); + + void startWindowDrag(); + NSWindow *platformWindow(); + +#if WK_API_ENABLED + NSView *inspectorAttachmentView(); + _WKRemoteObjectRegistry *remoteObjectRegistry(); #endif + + void intrinsicContentSizeDidChange(const WebCore::IntSize& intrinsicContentSize); + CGRect boundsOfLayerInLayerBackedWindowCoordinates(CALayer *) const; #endif // PLATFORM(MAC) + #if PLATFORM(EFL) void handleInputMethodKeydown(bool& handled); void confirmComposition(const String&); void setComposition(const String&, Vector<WebCore::CompositionUnderline>&, int); void cancelComposition(); #endif + #if PLATFORM(GTK) PlatformWidget viewWidget(); -#endif -#if USE(TILED_BACKING_STORE) - void commitPageTransitionViewport(); + const WebCore::Color& backgroundColor() const { return m_backgroundColor; } + void setBackgroundColor(const WebCore::Color& color) { m_backgroundColor = color; } #endif void handleMouseEvent(const NativeWebMouseEvent&); void handleWheelEvent(const NativeWebWheelEvent&); void handleKeyboardEvent(const NativeWebKeyboardEvent&); -#if ENABLE(TOUCH_EVENTS) + +#if ENABLE(MAC_GESTURE_EVENTS) + void handleGestureEvent(const NativeWebGestureEvent&); +#endif + +#if ENABLE(IOS_TOUCH_EVENTS) + void handleTouchEventSynchronously(const NativeWebTouchEvent&); + void handleTouchEventAsynchronously(const NativeWebTouchEvent&); + +#elif ENABLE(TOUCH_EVENTS) void handleTouchEvent(const NativeWebTouchEvent&); #endif @@ -552,20 +644,23 @@ public: void terminateProcess(); - typedef bool (*WebPageProxySessionStateFilterCallback)(WKPageRef, WKStringRef type, WKTypeRef object, void* context); - PassRefPtr<API::Data> sessionStateData(WebPageProxySessionStateFilterCallback, void* context) const; - void restoreFromSessionStateData(API::Data*); + SessionState sessionState(const std::function<bool (WebBackForwardListItem&)>& = nullptr) const; + RefPtr<API::Navigation> restoreFromSessionState(SessionState, bool navigate); bool supportsTextZoom() const; double textZoomFactor() const { return m_textZoomFactor; } void setTextZoomFactor(double); - double pageZoomFactor() const { return m_pageZoomFactor; } + double pageZoomFactor() const; void setPageZoomFactor(double); void setPageAndTextZoomFactors(double pageZoomFactor, double textZoomFactor); void scalePage(double scale, const WebCore::IntPoint& origin); - double pageScaleFactor() const { return m_pageScaleFactor; } - + void scalePageInViewCoordinates(double scale, const WebCore::IntPoint& centerInViewCoordinates); + double pageScaleFactor() const; + double viewScaleFactor() const { return m_viewScaleFactor; } + void scaleView(double scale); + void setShouldScaleViewToFitDocument(bool); + float deviceScaleFactor() const; void setIntrinsicDeviceScaleFactor(float); void setCustomDeviceScaleFactor(float); @@ -578,9 +673,6 @@ public: void listenForLayoutMilestones(WebCore::LayoutMilestones); - void setVisibilityStatePrerender(); - void didUpdateViewState() { m_waitingForDidUpdateViewState = false; } - bool hasHorizontalScrollbar() const { return m_mainFrameHasHorizontalScrollbar; } bool hasVerticalScrollbar() const { return m_mainFrameHasVerticalScrollbar; } @@ -601,6 +693,14 @@ public: bool rubberBandsAtBottom() const; void setRubberBandsAtBottom(bool); + void setShouldUseImplicitRubberBandControl(bool shouldUseImplicitRubberBandControl) { m_shouldUseImplicitRubberBandControl = shouldUseImplicitRubberBandControl; } + bool shouldUseImplicitRubberBandControl() const { return m_shouldUseImplicitRubberBandControl; } + + void setEnableVerticalRubberBanding(bool); + bool verticalRubberBandingIsEnabled() const; + void setEnableHorizontalRubberBanding(bool); + bool horizontalRubberBandingIsEnabled() const; + void setBackgroundExtendsBeyondPage(bool); bool backgroundExtendsBeyondPage() const; @@ -612,25 +712,30 @@ public: double pageLength() const { return m_pageLength; } void setGapBetweenPages(double); double gapBetweenPages() const { return m_gapBetweenPages; } + void setPaginationLineGridEnabled(bool); + bool paginationLineGridEnabled() const { return m_paginationLineGridEnabled; } unsigned pageCount() const { return m_pageCount; } -#if PLATFORM(MAC) +#if PLATFORM(COCOA) // Called by the web process through a message. void registerWebProcessAccessibilityToken(const IPC::DataReference&); // Called by the UI process when it is ready to send its tokens to the web process. void registerUIProcessAccessibilityTokens(const IPC::DataReference& elemenToken, const IPC::DataReference& windowToken); bool readSelectionFromPasteboard(const String& pasteboardName); String stringSelectionForPasteboard(); - PassRefPtr<WebCore::SharedBuffer> dataSelectionForPasteboard(const String& pasteboardType); + RefPtr<WebCore::SharedBuffer> dataSelectionForPasteboard(const String& pasteboardType); void makeFirstResponder(); ColorSpaceData colorSpace(); #endif - void pageScaleFactorDidChange(double); - void pageZoomFactorDidChange(double); +#if ENABLE(SERVICE_CONTROLS) + void replaceSelectionWithPasteboardData(const Vector<String>& types, const IPC::DataReference&); +#endif - void setMemoryCacheClientCallsEnabled(bool); + void pageScaleFactorDidChange(double); + void pluginScaleFactorDidChange(double); + void pluginZoomFactorDidChange(double); // Find. void findString(const String&, FindOptions, unsigned maxMatchCount); @@ -641,23 +746,28 @@ public: void hideFindUI(); void countStringMatches(const String&, FindOptions, unsigned maxMatchCount); void didCountStringMatches(const String&, uint32_t matchCount); - void setFindIndicator(const WebCore::FloatRect& selectionRectInWindowCoordinates, const Vector<WebCore::FloatRect>& textRectsInSelectionRectCoordinates, float contentImageScaleFactor, const ShareableBitmap::Handle& contentImageHandle, bool fadeOut, bool animate); - void didFindString(const String&, uint32_t matchCount); + void setTextIndicator(const WebCore::TextIndicatorData&, uint64_t /* WebCore::TextIndicatorWindowLifetime */ lifetime = 0 /* Permanent */); + void setTextIndicatorAnimationProgress(float); + void clearTextIndicator(); + void didFindString(const String&, const Vector<WebCore::IntRect>&, uint32_t matchCount, int32_t matchIndex); void didFailToFindString(const String&); - void didFindStringMatches(const String&, Vector<Vector<WebCore::IntRect>> matchRects, int32_t firstIndexAfterSelection); + void didFindStringMatches(const String&, const Vector<Vector<WebCore::IntRect>>& matchRects, int32_t firstIndexAfterSelection); + + void getContentsAsString(std::function<void (const String&, CallbackBase::Error)>); + void getBytecodeProfile(std::function<void (const String&, CallbackBase::Error)>); + void isWebProcessResponsive(std::function<void (bool isWebProcessResponsive)>); - void getContentsAsString(PassRefPtr<StringCallback>); #if ENABLE(MHTML) - void getContentsAsMHTMLData(PassRefPtr<DataCallback>, bool useBinaryEncoding); -#endif - void getMainResourceDataOfFrame(WebFrameProxy*, PassRefPtr<DataCallback>); - void getResourceDataFromFrame(WebFrameProxy*, API::URL*, PassRefPtr<DataCallback>); - void getRenderTreeExternalRepresentation(PassRefPtr<StringCallback>); - void getSelectionOrContentsAsString(PassRefPtr<StringCallback>); - void getSelectionAsWebArchiveData(PassRefPtr<DataCallback>); - void getSourceForFrame(WebFrameProxy*, PassRefPtr<StringCallback>); - void getWebArchiveOfFrame(WebFrameProxy*, PassRefPtr<DataCallback>); - void runJavaScriptInMainFrame(const String&, PassRefPtr<ScriptValueCallback>); + void getContentsAsMHTMLData(std::function<void (API::Data*, CallbackBase::Error)>); +#endif + void getMainResourceDataOfFrame(WebFrameProxy*, std::function<void (API::Data*, CallbackBase::Error)>); + void getResourceDataFromFrame(WebFrameProxy*, API::URL*, std::function<void (API::Data*, CallbackBase::Error)>); + void getRenderTreeExternalRepresentation(std::function<void (const String&, CallbackBase::Error)>); + void getSelectionOrContentsAsString(std::function<void (const String&, CallbackBase::Error)>); + void getSelectionAsWebArchiveData(std::function<void (API::Data*, CallbackBase::Error)>); + void getSourceForFrame(WebFrameProxy*, std::function<void (const String&, CallbackBase::Error)>); + void getWebArchiveOfFrame(WebFrameProxy*, std::function<void (API::Data*, CallbackBase::Error)>); + void runJavaScriptInMainFrame(const String&, std::function<void (API::SerializedScriptValue*, bool hadException, const WebCore::ExceptionDetails&, CallbackBase::Error)> callbackFunction); void forceRepaint(PassRefPtr<VoidCallback>); float headerHeight(WebFrameProxy*); @@ -665,12 +775,13 @@ public: void drawHeader(WebFrameProxy*, const WebCore::FloatRect&); void drawFooter(WebFrameProxy*, const WebCore::FloatRect&); -#if PLATFORM(MAC) +#if PLATFORM(COCOA) // Dictionary. void performDictionaryLookupAtLocation(const WebCore::FloatPoint&); + void performDictionaryLookupOfCurrentSelection(); #endif - void receivedPolicyDecision(WebCore::PolicyAction, WebFrameProxy*, uint64_t listenerID); + void receivedPolicyDecision(WebCore::PolicyAction, WebFrameProxy*, uint64_t listenerID, API::Navigation* navigationID); void backForwardRemovedItem(uint64_t itemID); @@ -679,14 +790,17 @@ public: void dragEntered(WebCore::DragData&, const String& dragStorageName = String()); void dragUpdated(WebCore::DragData&, const String& dragStorageName = String()); void dragExited(WebCore::DragData&, const String& dragStorageName = String()); - void performDrag(WebCore::DragData&, const String& dragStorageName, const SandboxExtension::Handle&, const SandboxExtension::HandleArray&); + void performDragOperation(WebCore::DragData&, const String& dragStorageName, const SandboxExtension::Handle&, const SandboxExtension::HandleArray&); - void didPerformDragControllerAction(WebCore::DragSession); + void didPerformDragControllerAction(uint64_t dragOperation, bool mouseIsOverFileInput, unsigned numberOfItemsToBeAccepted); void dragEnded(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition, uint64_t operation); -#if PLATFORM(MAC) +#if PLATFORM(COCOA) void setDragImage(const WebCore::IntPoint& clientPosition, const ShareableBitmap::Handle& dragImageHandle, bool isLinkDrag); - void setPromisedData(const String& pasteboardName, const SharedMemory::Handle& imageHandle, uint64_t imageSize, const String& filename, const String& extension, + void setPromisedDataForImage(const String& pasteboardName, const SharedMemory::Handle& imageHandle, uint64_t imageSize, const String& filename, const String& extension, const String& title, const String& url, const String& visibleURL, const SharedMemory::Handle& archiveHandle, uint64_t archiveSize); +#if ENABLE(ATTACHMENT_ELEMENT) + void setPromisedDataForAttachment(const String& pasteboardName, const String& filename, const String& extension, const String& title, const String& url, const String& visibleURL); +#endif #endif #if PLATFORM(GTK) void startDrag(const WebCore::DragData&, const ShareableBitmap::Handle& dragImage); @@ -694,17 +808,20 @@ public: #endif void processDidBecomeUnresponsive(); - void interactionOccurredWhileProcessUnresponsive(); void processDidBecomeResponsive(); void processDidCrash(); + void willChangeProcessIsResponsive(); + void didChangeProcessIsResponsive(); + +#if PLATFORM(IOS) + void processWillBecomeSuspended(); + void processWillBecomeForeground(); +#endif -#if USE(ACCELERATED_COMPOSITING) virtual void enterAcceleratedCompositingMode(const LayerTreeContext&); virtual void exitAcceleratedCompositingMode(); virtual void updateAcceleratedCompositingMode(const LayerTreeContext&); -#endif - - void didDraw(); + void willEnterAcceleratedCompositingMode(); enum UndoOrRedo { Undo, Redo }; void addEditCommand(WebEditCommandProxy*); @@ -712,26 +829,31 @@ public: bool isValidEditCommand(WebEditCommandProxy*); void registerEditCommand(PassRefPtr<WebEditCommandProxy>, UndoOrRedo); -#if PLATFORM(MAC) +#if PLATFORM(COCOA) void registerKeypressCommandName(const String& name) { m_knownKeypressCommandNames.add(name); } bool isValidKeypressCommandName(const String& name) const { return m_knownKeypressCommandNames.contains(name); } #endif - WebProcessProxy& process() { return m_process.get(); } - PlatformProcessIdentifier processIdentifier() const; - - WebPageGroup& pageGroup() { return m_pageGroup.get(); } + WebProcessProxy& process() { return m_process; } + pid_t processIdentifier() const; - bool isValid() const; + WebPreferences& preferences() { return m_preferences; } + void setPreferences(WebPreferences&); - PassRefPtr<API::Array> relatedPages() const; + WebPageGroup& pageGroup() { return m_pageGroup; } - const String& urlAtProcessExit() const { return m_urlAtProcessExit; } - FrameLoadState::State loadStateAtProcessExit() const { return m_loadStateAtProcessExit; } + bool isValid() const; #if ENABLE(DRAG_SUPPORT) - WebCore::DragSession dragSession() const { return m_currentDragSession; } - void resetDragOperation() { m_currentDragSession = WebCore::DragSession(); } + WebCore::DragOperation currentDragOperation() const { return m_currentDragOperation; } + bool currentDragIsOverFileInput() const { return m_currentDragIsOverFileInput; } + unsigned currentDragNumberOfFilesToBeAccepted() const { return m_currentDragNumberOfFilesToBeAccepted; } + void resetCurrentDragInformation() + { + m_currentDragOperation = WebCore::DragOperationNone; + m_currentDragIsOverFileInput = false; + m_currentDragNumberOfFilesToBeAccepted = 0; + } #endif void preferencesDidChange(); @@ -742,18 +864,19 @@ public: #endif // Called by the WebOpenPanelResultListenerProxy. +#if PLATFORM(IOS) + void didChooseFilesForOpenPanelWithDisplayStringAndIcon(const Vector<String>&, const String& displayString, const API::Data* iconData); +#endif void didChooseFilesForOpenPanel(const Vector<String>&); void didCancelForOpenPanel(); WebPageCreationParameters creationParameters(); -#if USE(COORDINATED_GRAPHICS) +#if USE(COORDINATED_GRAPHICS_MULTIPROCESS) void findZoomableAreaForPoint(const WebCore::IntPoint&, const WebCore::IntSize&); #endif -#if PLATFORM(EFL) || PLATFORM(GTK) void handleDownloadRequest(DownloadProxy*); -#endif void advanceToNextMisspelling(bool startBeforeSelection); void changeSpellingToWord(const String& word); @@ -763,7 +886,7 @@ public: void capitalizeWord(); #endif -#if PLATFORM(MAC) +#if PLATFORM(COCOA) bool isSmartInsertDeleteEnabled() const { return m_isSmartInsertDeleteEnabled; } void setSmartInsertDeleteEnabled(bool); #endif @@ -778,7 +901,7 @@ public: void beginPrinting(WebFrameProxy*, const PrintInfo&); void endPrinting(); void computePagesForPrinting(WebFrameProxy*, const PrintInfo&, PassRefPtr<ComputedPagesCallback>); -#if PLATFORM(MAC) +#if PLATFORM(COCOA) void drawRectToImage(WebFrameProxy*, const PrintInfo&, const WebCore::IntRect&, const WebCore::IntSize&, PassRefPtr<ImageCallback>); void drawPagesToPDF(WebFrameProxy*, const PrintInfo&, uint32_t first, uint32_t count, PassRefPtr<DataCallback>); #elif PLATFORM(GTK) @@ -787,13 +910,13 @@ public: PageLoadState& pageLoadState() { return m_pageLoadState; } -#if PLATFORM(MAC) +#if PLATFORM(COCOA) void handleAlternativeTextUIResult(const String& result); #endif void saveDataToFileInDownloadsFolder(const String& suggestedFilename, const String& mimeType, const String& originatingURLString, API::Data*); void savePDFToFileInDownloadsFolder(const String& suggestedFilename, const String& originatingURLString, const IPC::DataReference&); -#if PLATFORM(MAC) +#if PLATFORM(COCOA) void savePDFToTemporaryFolderAndOpenWithNativeApplicationRaw(const String& suggestedFilename, const String& originatingURLString, const uint8_t* data, unsigned long size, const String& pdfUUID); void savePDFToTemporaryFolderAndOpenWithNativeApplication(const String& suggestedFilename, const String& originatingURLString, const IPC::DataReference&, const String& pdfUUID); void openPDFFromTemporaryFolderWithNativeApplication(const String& pdfUUID); @@ -803,28 +926,36 @@ public: uint64_t renderTreeSize() const { return m_renderTreeSize; } - void setShouldSendEventsSynchronously(bool sync) { m_shouldSendEventsSynchronously = sync; }; - void printMainFrame(); void setMediaVolume(float); + void setMuted(bool); void setMayStartMediaWhenInWindow(bool); + bool mayStartMediaWhenInWindow() const { return m_mayStartMediaWhenInWindow; } + +#if ENABLE(MEDIA_SESSION) + bool hasMediaSessionWithActiveMediaElements() const { return m_hasMediaSessionWithActiveMediaElements; } + void handleMediaEvent(WebCore::MediaEventType); + void setVolumeOfMediaElement(double, uint64_t); +#endif // WebPopupMenuProxy::Client - virtual NativeWebMouseEvent* currentlyProcessedMouseDownEvent(); + virtual NativeWebMouseEvent* currentlyProcessedMouseDownEvent() override; -#if PLATFORM(GTK) && USE(TEXTURE_MAPPER_GL) - void setAcceleratedCompositingWindowId(uint64_t nativeWindowId); -#endif - - void setSuppressVisibilityUpdates(bool flag) { m_suppressVisibilityUpdates = flag; } + void setSuppressVisibilityUpdates(bool flag); bool suppressVisibilityUpdates() { return m_suppressVisibilityUpdates; } #if PLATFORM(IOS) - void didFinishScrolling(const WebCore::FloatPoint& contentOffset); - void didFinishZooming(float newScale); + void willStartUserTriggeredZooming(); + void potentialTapAtPosition(const WebCore::FloatPoint&, uint64_t& requestID); + void commitPotentialTap(); + void cancelPotentialTap(); void tapHighlightAtPosition(const WebCore::FloatPoint&, uint64_t& requestID); + void handleTap(const WebCore::FloatPoint&); + + void inspectorNodeSearchMovedToPosition(const WebCore::FloatPoint&); + void inspectorNodeSearchEndedAtPosition(const WebCore::FloatPoint&); void blurAssistedNode(); #endif @@ -842,45 +973,144 @@ public: bool autoSizingShouldExpandToViewHeight() const { return m_autoSizingShouldExpandToViewHeight; } void setAutoSizingShouldExpandToViewHeight(bool); - bool mainFrameInViewSourceMode() const { return m_mainFrameInViewSourceMode; } - void setMainFrameInViewSourceMode(bool); - void didReceiveAuthenticationChallengeProxy(uint64_t frameID, PassRefPtr<AuthenticationChallengeProxy>); int64_t spellDocumentTag(); void didFinishCheckingText(uint64_t requestID, const Vector<WebCore::TextCheckingResult>&); void didCancelCheckingText(uint64_t requestID); - void connectionWillOpen(IPC::Connection*); - void connectionWillClose(IPC::Connection*); + void connectionWillOpen(IPC::Connection&); + void webProcessWillShutDown(); + + void processDidFinishLaunching(); void didSaveToPageCache(); void setScrollPinningBehavior(WebCore::ScrollPinningBehavior); - WebCore::ScrollPinningBehavior scrollPinningBehavior() { return m_scrollPinningBehavior; } + WebCore::ScrollPinningBehavior scrollPinningBehavior() const { return m_scrollPinningBehavior; } + + void setOverlayScrollbarStyle(WTF::Optional<WebCore::ScrollbarOverlayStyle>); + WTF::Optional<WebCore::ScrollbarOverlayStyle> overlayScrollbarStyle() const { return m_scrollbarOverlayStyle; } bool shouldRecordNavigationSnapshots() const { return m_shouldRecordNavigationSnapshots; } void setShouldRecordNavigationSnapshots(bool shouldRecordSnapshots) { m_shouldRecordNavigationSnapshots = shouldRecordSnapshots; } void recordNavigationSnapshot(); + void recordNavigationSnapshot(WebBackForwardListItem&); + +#if PLATFORM(COCOA) + PassRefPtr<ViewSnapshot> takeViewSnapshot(); +#endif + +#if ENABLE(SUBTLE_CRYPTO) + void wrapCryptoKey(const Vector<uint8_t>&, bool& succeeded, Vector<uint8_t>&); + void unwrapCryptoKey(const Vector<uint8_t>&, bool& succeeded, Vector<uint8_t>&); +#endif + + void takeSnapshot(WebCore::IntRect, WebCore::IntSize bitmapSize, SnapshotOptions, std::function<void (const ShareableBitmap::Handle&, CallbackBase::Error)>); + + void navigationGestureDidBegin(); + void navigationGestureWillEnd(bool willNavigate, WebBackForwardListItem&); + void navigationGestureDidEnd(bool willNavigate, WebBackForwardListItem&); + void navigationGestureDidEnd(); + void navigationGestureSnapshotWasRemoved(); + void willRecordNavigationSnapshot(WebBackForwardListItem&); + + bool isShowingNavigationGestureSnapshot() const { return m_isShowingNavigationGestureSnapshot; } + + bool isPlayingAudio() const { return !!(m_mediaState & WebCore::MediaProducer::IsPlayingAudio); } + void isPlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags, uint64_t); + +#if ENABLE(MEDIA_SESSION) + void hasMediaSessionWithActiveMediaElementsDidChange(bool); + void mediaSessionMetadataDidChange(const WebCore::MediaSessionMetadata&); + void focusedContentMediaElementDidChange(uint64_t); +#endif #if PLATFORM(MAC) - RetainPtr<CGImageRef> takeViewSnapshot(); + void removeNavigationGestureSnapshot(); + + API::HitTestResult* lastMouseMoveHitTestResult() const { return m_lastMouseMoveHitTestResult.get(); } + void performImmediateActionHitTestAtLocation(WebCore::FloatPoint); + + void immediateActionDidUpdate(); + void immediateActionDidCancel(); + void immediateActionDidComplete(); + + void* immediateActionAnimationControllerForHitTestResult(RefPtr<API::HitTestResult>, uint64_t, RefPtr<API::Object>); + + void installViewStateChangeCompletionHandler(void(^completionHandler)()); + + void handleAcceptedCandidate(WebCore::TextCheckingResult); + void didHandleAcceptedCandidate(); +#endif + +#if PLATFORM(EFL) && HAVE(ACCESSIBILITY) && defined(HAVE_ECORE_X) + bool accessibilityObjectReadByPoint(const WebCore::IntPoint&); + bool accessibilityObjectReadPrevious(); + bool accessibilityObjectReadNext(); +#endif + +#if USE(UNIFIED_TEXT_CHECKING) + void checkTextOfParagraph(const String& text, uint64_t checkingTypes, Vector<WebCore::TextCheckingResult>& results); #endif + void getGuessesForWord(const String& word, const String& context, Vector<String>& guesses); + + void setShouldDispatchFakeMouseMoveEvents(bool); + + // Diagnostic messages logging. + void logDiagnosticMessage(const String& message, const String& description, bool shouldSample); + void logDiagnosticMessageWithResult(const String& message, const String& description, uint32_t result, bool shouldSample); + void logDiagnosticMessageWithValue(const String& message, const String& description, const String& value, bool shouldSample); + void logSampledDiagnosticMessage(const String& message, const String& description); + void logSampledDiagnosticMessageWithResult(const String& message, const String& description, uint32_t result); + void logSampledDiagnosticMessageWithValue(const String& message, const String& description, const String& value); + +#if ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS) + void addPlaybackTargetPickerClient(uint64_t); + void removePlaybackTargetPickerClient(uint64_t); + void showPlaybackTargetPicker(uint64_t, const WebCore::FloatRect&, bool hasVideo); + void playbackTargetPickerClientStateDidChange(uint64_t, WebCore::MediaProducer::MediaStateFlags); + void setMockMediaPlaybackTargetPickerEnabled(bool); + void setMockMediaPlaybackTargetPickerState(const String&, WebCore::MediaPlaybackTargetContext::State); + + // WebMediaSessionManagerClient + virtual void setPlaybackTarget(uint64_t, Ref<WebCore::MediaPlaybackTarget>&&) override; + virtual void externalOutputDeviceAvailableDidChange(uint64_t, bool) override; + virtual void setShouldPlayToPlaybackTarget(uint64_t, bool) override; +#endif + + void didChangeBackgroundColor(); + void didLayoutForCustomContentProvider(); + + // For testing + void clearWheelEventTestTrigger(); + void callAfterNextPresentationUpdate(std::function<void (CallbackBase::Error)>); + + void didLayout(uint32_t layoutMilestones); + + void didRestoreScrollPosition(); private: - WebPageProxy(PageClient&, WebProcessProxy&, uint64_t pageID, const WebPageConfiguration&); + WebPageProxy(PageClient&, WebProcessProxy&, uint64_t pageID, Ref<API::PageConfiguration>&&); void platformInitialize(); void updateViewState(WebCore::ViewState::Flags flagsToUpdate = WebCore::ViewState::AllFlags); - - void resetState(); + void updateActivityToken(); + void updateProccessSuppressionState(); + + enum class ResetStateReason { + PageInvalidated, + WebProcessExited, + }; + void resetState(ResetStateReason); void resetStateAfterProcessExited(); void setUserAgent(const String&); // IPC::MessageReceiver - virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; - virtual void didReceiveSyncMessage(IPC::Connection*, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override; + // Implemented in generated WebPageProxyMessageReceiver.cpp + virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override; + virtual void didReceiveSyncMessage(IPC::Connection&, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override; // IPC::MessageSender virtual bool sendMessage(std::unique_ptr<IPC::MessageEncoder>, unsigned messageSendFlags) override; @@ -888,63 +1118,68 @@ private: virtual uint64_t messageSenderDestinationID() override; // WebPopupMenuProxy::Client - virtual void valueChangedForPopupMenu(WebPopupMenuProxy*, int32_t newSelectedIndex); - virtual void setTextFromItemForPopupMenu(WebPopupMenuProxy*, int32_t index); + virtual void valueChangedForPopupMenu(WebPopupMenuProxy*, int32_t newSelectedIndex) override; + virtual void setTextFromItemForPopupMenu(WebPopupMenuProxy*, int32_t index) override; #if PLATFORM(GTK) - virtual void failedToShowPopupMenu(); + virtual void failedToShowPopupMenu() override; #endif - // Implemented in generated WebPageProxyMessageReceiver.cpp - void didReceiveWebPageProxyMessage(IPC::Connection*, IPC::MessageDecoder&); - void didReceiveSyncWebPageProxyMessage(IPC::Connection*, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&); - void didCreateMainFrame(uint64_t frameID); void didCreateSubframe(uint64_t frameID); - void didStartProvisionalLoadForFrame(uint64_t frameID, const String& url, const String& unreachableURL, IPC::MessageDecoder&); - void didReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, const String&, IPC::MessageDecoder&); - void didFailProvisionalLoadForFrame(uint64_t frameID, const WebCore::ResourceError&, IPC::MessageDecoder&); - void didCommitLoadForFrame(uint64_t frameID, const String& mimeType, uint32_t frameLoadType, const WebCore::CertificateInfo&, IPC::MessageDecoder&); - void didFinishDocumentLoadForFrame(uint64_t frameID, IPC::MessageDecoder&); - void didFinishLoadForFrame(uint64_t frameID, IPC::MessageDecoder&); - void didFailLoadForFrame(uint64_t frameID, const WebCore::ResourceError&, IPC::MessageDecoder&); - void didSameDocumentNavigationForFrame(uint64_t frameID, uint32_t sameDocumentNavigationType, const String&, IPC::MessageDecoder&); - void didReceiveTitleForFrame(uint64_t frameID, const String&, IPC::MessageDecoder&); - void didFirstLayoutForFrame(uint64_t frameID, IPC::MessageDecoder&); - void didFirstVisuallyNonEmptyLayoutForFrame(uint64_t frameID, IPC::MessageDecoder&); - void didLayout(uint32_t layoutMilestones, IPC::MessageDecoder&); - void didRemoveFrameFromHierarchy(uint64_t frameID, IPC::MessageDecoder&); - void didDisplayInsecureContentForFrame(uint64_t frameID, IPC::MessageDecoder&); - void didRunInsecureContentForFrame(uint64_t frameID, IPC::MessageDecoder&); - void didDetectXSSForFrame(uint64_t frameID, IPC::MessageDecoder&); + void didStartProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, const String& url, const String& unreachableURL, const UserData&); + void didReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, const String&, const UserData&); + void didChangeProvisionalURLForFrame(uint64_t frameID, uint64_t navigationID, const String& url); + void didFailProvisionalLoadForFrame(uint64_t frameID, const WebCore::SecurityOriginData& frameSecurityOrigin, uint64_t navigationID, const String& provisionalURL, const WebCore::ResourceError&, const UserData&); + void didCommitLoadForFrame(uint64_t frameID, uint64_t navigationID, const String& mimeType, bool frameHasCustomContentProvider, bool mainFramePluginHandlesPageScaleGesture, uint32_t frameLoadType, const WebCore::CertificateInfo&, bool containsPluginDocument, const UserData&); + void didFinishDocumentLoadForFrame(uint64_t frameID, uint64_t navigationID, const UserData&); + void didFinishLoadForFrame(uint64_t frameID, uint64_t navigationID, const UserData&); + void didFailLoadForFrame(uint64_t frameID, uint64_t navigationID, const WebCore::ResourceError&, const UserData&); + void didSameDocumentNavigationForFrame(uint64_t frameID, uint64_t navigationID, uint32_t sameDocumentNavigationType, const String&, const UserData&); + void didReceiveTitleForFrame(uint64_t frameID, const String&, const UserData&); + void didFirstLayoutForFrame(uint64_t frameID, const UserData&); + void didFirstVisuallyNonEmptyLayoutForFrame(uint64_t frameID, const UserData&); + void didDisplayInsecureContentForFrame(uint64_t frameID, const UserData&); + void didRunInsecureContentForFrame(uint64_t frameID, const UserData&); + void didDetectXSSForFrame(uint64_t frameID, const UserData&); void frameDidBecomeFrameSet(uint64_t frameID, bool); void didStartProgress(); void didChangeProgress(double); void didFinishProgress(); + void setNetworkRequestsInProgress(bool); + + void didDestroyNavigation(uint64_t navigationID); - void decidePolicyForNavigationAction(uint64_t frameID, const NavigationActionData&, uint64_t originatingFrameID, const WebCore::ResourceRequest& originalRequest, const WebCore::ResourceRequest&, uint64_t listenerID, IPC::MessageDecoder&, bool& receivedPolicyAction, uint64_t& policyAction, uint64_t& downloadID); - void decidePolicyForNewWindowAction(uint64_t frameID, const NavigationActionData&, const WebCore::ResourceRequest&, const String& frameName, uint64_t listenerID, IPC::MessageDecoder&); - void decidePolicyForResponse(uint64_t frameID, const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, bool canShowMIMEType, uint64_t listenerID, IPC::MessageDecoder&); - void decidePolicyForResponseSync(uint64_t frameID, const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, bool canShowMIMEType, uint64_t listenerID, IPC::MessageDecoder&, bool& receivedPolicyAction, uint64_t& policyAction, uint64_t& downloadID); - void unableToImplementPolicy(uint64_t frameID, const WebCore::ResourceError&, IPC::MessageDecoder&); + void decidePolicyForNavigationAction(uint64_t frameID, const WebCore::SecurityOriginData& frameSecurityOrigin, uint64_t navigationID, const NavigationActionData&, uint64_t originatingFrameID, const WebCore::SecurityOriginData& originatingFrameSecurityOrigin, const WebCore::ResourceRequest& originalRequest, const WebCore::ResourceRequest&, uint64_t listenerID, const UserData&, bool& receivedPolicyAction, uint64_t& newNavigationID, uint64_t& policyAction, DownloadID&); + void decidePolicyForNewWindowAction(uint64_t frameID, const WebCore::SecurityOriginData& frameSecurityOrigin, const NavigationActionData&, const WebCore::ResourceRequest&, const String& frameName, uint64_t listenerID, const UserData&); + void decidePolicyForResponse(uint64_t frameID, const WebCore::SecurityOriginData& frameSecurityOrigin, const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, bool canShowMIMEType, uint64_t listenerID, const UserData&); + void decidePolicyForResponseSync(uint64_t frameID, const WebCore::SecurityOriginData& frameSecurityOrigin, const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, bool canShowMIMEType, uint64_t listenerID, const UserData&, bool& receivedPolicyAction, uint64_t& policyAction, DownloadID&); + void unableToImplementPolicy(uint64_t frameID, const WebCore::ResourceError&, const UserData&); - void willSubmitForm(uint64_t frameID, uint64_t sourceFrameID, const Vector<std::pair<String, String>>& textFieldValues, uint64_t listenerID, IPC::MessageDecoder&); + void willSubmitForm(uint64_t frameID, uint64_t sourceFrameID, const Vector<std::pair<String, String>>& textFieldValues, uint64_t listenerID, const UserData&); + + // History client + void didNavigateWithNavigationData(const WebNavigationDataStore&, uint64_t frameID); + void didPerformClientRedirect(const String& sourceURLString, const String& destinationURLString, uint64_t frameID); + void didPerformServerRedirect(const String& sourceURLString, const String& destinationURLString, uint64_t frameID); + void didUpdateHistoryTitle(const String& title, const String& url, uint64_t frameID); // UI client - void createNewPage(const WebCore::ResourceRequest&, const WebCore::WindowFeatures&, uint32_t modifiers, int32_t mouseButton, uint64_t& newPageID, WebPageCreationParameters&); + void createNewPage(uint64_t frameID, const WebCore::SecurityOriginData&, const WebCore::ResourceRequest&, const WebCore::WindowFeatures&, const NavigationActionData&, uint64_t& newPageID, WebPageCreationParameters&); void showPage(); void closePage(bool stopResponsivenessTimer); - void runJavaScriptAlert(uint64_t frameID, const String&); - void runJavaScriptConfirm(uint64_t frameID, const String&, bool& result); - void runJavaScriptPrompt(uint64_t frameID, const String&, const String&, String& result); - void shouldInterruptJavaScript(bool& result); + void runJavaScriptAlert(uint64_t frameID, const WebCore::SecurityOriginData&, const String&, RefPtr<Messages::WebPageProxy::RunJavaScriptAlert::DelayedReply>); + void runJavaScriptConfirm(uint64_t frameID, const WebCore::SecurityOriginData&, const String&, RefPtr<Messages::WebPageProxy::RunJavaScriptConfirm::DelayedReply>); + void runJavaScriptPrompt(uint64_t frameID, const WebCore::SecurityOriginData&, const String&, const String&, RefPtr<Messages::WebPageProxy::RunJavaScriptPrompt::DelayedReply>); void setStatusText(const String&); - void mouseDidMoveOverElement(const WebHitTestResult::Data& hitTestResultData, uint32_t modifiers, IPC::MessageDecoder&); + void mouseDidMoveOverElement(const WebHitTestResultData&, uint32_t modifiers, const UserData&); + #if ENABLE(NETSCAPE_PLUGIN_API) void unavailablePluginButtonClicked(uint32_t opaquePluginUnavailabilityReason, const String& mimeType, const String& pluginURLString, const String& pluginsPageURLString, const String& frameURLString, const String& pageURLString); #endif // ENABLE(NETSCAPE_PLUGIN_API) #if ENABLE(WEBGL) void webGLPolicyForURL(const String& url, uint32_t& loadPolicy); + void resolveWebGLPolicyForURL(const String& url, uint32_t& loadPolicy); #endif // ENABLE(WEBGL) void setToolbarsAreVisible(bool toolbarsAreVisible); void getToolbarsAreVisible(bool& toolbarsAreVisible); @@ -956,21 +1191,31 @@ private: void getIsResizable(bool& isResizable); void setWindowFrame(const WebCore::FloatRect&); void getWindowFrame(WebCore::FloatRect&); - void screenToWindow(const WebCore::IntPoint& screenPoint, WebCore::IntPoint& windowPoint); - void windowToScreen(const WebCore::IntRect& viewRect, WebCore::IntRect& result); - void runBeforeUnloadConfirmPanel(const String& message, uint64_t frameID, bool& shouldClose); + void screenToRootView(const WebCore::IntPoint& screenPoint, WebCore::IntPoint& windowPoint); + void rootViewToScreen(const WebCore::IntRect& viewRect, WebCore::IntRect& result); +#if PLATFORM(IOS) + void accessibilityScreenToRootView(const WebCore::IntPoint& screenPoint, WebCore::IntPoint& windowPoint); + void rootViewToAccessibilityScreen(const WebCore::IntRect& viewRect, WebCore::IntRect& result); +#endif + void runBeforeUnloadConfirmPanel(const String& message, uint64_t frameID, RefPtr<Messages::WebPageProxy::RunBeforeUnloadConfirmPanel::DelayedReply>); void didChangeViewportProperties(const WebCore::ViewportAttributes&); void pageDidScroll(); void runOpenPanel(uint64_t frameID, const WebCore::FileChooserSettings&); void printFrame(uint64_t frameID); void exceededDatabaseQuota(uint64_t frameID, const String& originIdentifier, const String& databaseName, const String& displayName, uint64_t currentQuota, uint64_t currentOriginUsage, uint64_t currentDatabaseUsage, uint64_t expectedUsage, PassRefPtr<Messages::WebPageProxy::ExceededDatabaseQuota::DelayedReply>); + void reachedApplicationCacheOriginQuota(const String& originIdentifier, uint64_t currentQuota, uint64_t totalBytesNeeded, PassRefPtr<Messages::WebPageProxy::ReachedApplicationCacheOriginQuota::DelayedReply>); void requestGeolocationPermissionForFrame(uint64_t geolocationID, uint64_t frameID, String originIdentifier); + + void requestUserMediaPermissionForFrame(uint64_t userMediaID, uint64_t frameID, String originIdentifier, const Vector<String>& audioDeviceUIDs, const Vector<String>& videoDeviceUIDs); + void checkUserMediaPermissionForFrame(uint64_t userMediaID, uint64_t frameID, String originIdentifier); + void runModal(); void notifyScrollerThumbIsVisibleInRect(const WebCore::IntRect&); void recommendedScrollbarStyleDidChange(int32_t newStyle); void didChangeScrollbarsForMainFrame(bool hasHorizontalScrollbar, bool hasVerticalScrollbar); void didChangeScrollOffsetPinningForMainFrame(bool pinnedToLeftSide, bool pinnedToRightSide, bool pinnedToTopSide, bool pinnedToBottomSide); void didChangePageCount(unsigned); + void pageExtendedBackgroundColorDidChange(const WebCore::Color&); #if ENABLE(NETSCAPE_PLUGIN_API) void didFailToInitializePlugin(const String& mimeType, const String& frameURLString, const String& pageURLString); void didBlockInsecurePluginVersion(const String& mimeType, const String& pluginURLString, const String& frameURLString, const String& pageURLString, bool replacementObscured); @@ -978,7 +1223,8 @@ private: void setCanShortCircuitHorizontalWheelEvents(bool canShortCircuitHorizontalWheelEvents) { m_canShortCircuitHorizontalWheelEvents = canShortCircuitHorizontalWheelEvents; } void reattachToWebProcess(); - void reattachToWebProcessWithItem(WebBackForwardListItem*); + RefPtr<API::Navigation> reattachToWebProcessForReload(); + RefPtr<API::Navigation> reattachToWebProcessWithItem(WebBackForwardListItem*); void requestNotificationPermission(uint64_t notificationID, const String& originString); void showNotification(const String& title, const String& body, const String& iconURL, const String& tag, const String& lang, const String& dir, const String& originString, uint64_t notificationID); @@ -986,28 +1232,22 @@ private: void clearNotifications(const Vector<uint64_t>& notificationIDs); void didDestroyNotification(uint64_t notificationID); -#if USE(TILED_BACKING_STORE) +#if USE(COORDINATED_GRAPHICS_MULTIPROCESS) void pageDidRequestScroll(const WebCore::IntPoint&); void pageTransitionViewportReady(); -#endif -#if USE(COORDINATED_GRAPHICS) void didFindZoomableArea(const WebCore::IntPoint&, const WebCore::IntRect&); #endif -#if PLATFORM(EFL) || PLATFORM(IOS) - void didChangeContentSize(const WebCore::IntSize&); -#endif -#if ENABLE(TOUCH_EVENTS) - void needTouchEvents(bool); -#endif + void didChangeContentSize(const WebCore::IntSize&); #if ENABLE(INPUT_TYPE_COLOR) void showColorPicker(const WebCore::Color& initialColor, const WebCore::IntRect&); - void didChooseColor(const WebCore::Color&); - void didEndColorPicker(); + virtual void didChooseColor(const WebCore::Color&) override; + virtual void didEndColorPicker() override; #endif void editorStateChanged(const EditorState&); + void compositionWasCanceled(const EditorState&); // Back/Forward list management void backForwardAddItem(uint64_t itemID); @@ -1019,13 +1259,13 @@ private: // Undo management void registerEditCommandForUndo(uint64_t commandID, uint32_t editAction); + void registerInsertionUndoGrouping(); void clearAllEditCommands(); void canUndoRedo(uint32_t action, bool& result); void executeUndoRedo(uint32_t action, bool& result); // Keyboard handling -#if PLATFORM(MAC) - void interpretQueuedKeyEvent(const EditorState&, bool& handled, Vector<WebCore::KeypressCommand>&); +#if PLATFORM(COCOA) void executeSavedCommandBySelector(const String& selector, bool& handled); #endif @@ -1042,16 +1282,21 @@ private: void hidePopupMenu(); #if ENABLE(CONTEXT_MENUS) - // Context Menu. - void showContextMenu(const WebCore::IntPoint& menuLocation, const WebHitTestResult::Data&, const Vector<WebContextMenuItemData>&, IPC::MessageDecoder&); - void internalShowContextMenu(const WebCore::IntPoint& menuLocation, const WebHitTestResult::Data&, const Vector<WebContextMenuItemData>&, IPC::MessageDecoder&); + void showContextMenu(const ContextMenuContextData&, const UserData&); + void internalShowContextMenu(const ContextMenuContextData&, const UserData&); +#endif + +#if ENABLE(TELEPHONE_NUMBER_DETECTION) +#if PLATFORM(MAC) + void showTelephoneNumberMenu(const String& telephoneNumber, const WebCore::IntPoint&); +#endif #endif // Search popup results - void saveRecentSearches(const String&, const Vector<String>&); - void loadRecentSearches(const String&, Vector<String>&); + void saveRecentSearches(const String&, const Vector<WebCore::RecentSearch>&); + void loadRecentSearches(const String&, Vector<WebCore::RecentSearch>&); -#if PLATFORM(MAC) +#if PLATFORM(COCOA) // Speech. void getIsSpeaking(bool&); void speak(const String&); @@ -1063,19 +1308,19 @@ private: void searchTheWeb(const String&); // Dictionary. - void didPerformDictionaryLookup(const AttributedString&, const DictionaryPopupInfo&); + void didPerformDictionaryLookup(const WebCore::DictionaryPopupInfo&); #endif - // Spelling and grammar. -#if USE(UNIFIED_TEXT_CHECKING) - void checkTextOfParagraph(const String& text, uint64_t checkingTypes, Vector<WebCore::TextCheckingResult>& results); +#if PLATFORM(MAC) + bool appleMailPaginationQuirkEnabled(); #endif + + // Spelling and grammar. void checkSpellingOfString(const String& text, int32_t& misspellingLocation, int32_t& misspellingLength); void checkGrammarOfString(const String& text, Vector<WebCore::GrammarDetail>&, int32_t& badGrammarLocation, int32_t& badGrammarLength); void spellingUIIsShowing(bool&); void updateSpellingUIWithMisspelledWord(const String& misspelledWord); void updateSpellingUIWithGrammarString(const String& badGrammarPhrase, const WebCore::GrammarDetail&); - void getGuessesForWord(const String& word, const String& context, Vector<String>& guesses); void learnWord(const String& word); void ignoreWord(const String& word); void requestCheckingOfString(uint64_t requestID, const WebCore::TextCheckingRequestData&); @@ -1093,15 +1338,27 @@ private: void dataCallback(const IPC::DataReference&, uint64_t); void imageCallback(const ShareableBitmap::Handle&, uint64_t); void stringCallback(const String&, uint64_t); - void scriptValueCallback(const IPC::DataReference&, uint64_t); + void scriptValueCallback(const IPC::DataReference&, bool hadException, const WebCore::ExceptionDetails&, uint64_t); void computedPagesCallback(const Vector<WebCore::IntRect>&, double totalScaleFactorForPrinting, uint64_t); void validateCommandCallback(const String&, bool, int, uint64_t); + void unsignedCallback(uint64_t, uint64_t); + void editingRangeCallback(const EditingRange&, uint64_t); +#if PLATFORM(COCOA) + void machSendRightCallback(const WebCore::MachSendRight&, uint64_t); +#endif + void rectForCharacterRangeCallback(const WebCore::IntRect&, const EditingRange&, uint64_t); +#if PLATFORM(MAC) + void attributedStringForCharacterRangeCallback(const AttributedString&, const EditingRange&, uint64_t); + void fontAtSelectionCallback(const String&, double, bool, uint64_t); +#endif #if PLATFORM(IOS) void gestureCallback(const WebCore::IntPoint&, uint32_t, uint32_t, uint32_t, uint64_t); void touchesCallback(const WebCore::IntPoint&, uint32_t, uint64_t); void autocorrectionDataCallback(const Vector<WebCore::FloatRect>&, const String&, float, uint64_t, uint64_t); void autocorrectionContextCallback(const String&, const String&, const String&, const String&, uint64_t, uint64_t, uint64_t); + void dictationContextCallback(const String&, const String&, const String&, uint64_t); void interpretKeyEvent(const EditorState&, bool isCharEvent, bool& handled); + void showPlaybackTargetPicker(bool hasVideo, const WebCore::IntRect& elementRect); #endif #if PLATFORM(GTK) void printFinishedCallback(const WebCore::ResourceError&, uint64_t); @@ -1113,14 +1370,16 @@ private: void canAuthenticateAgainstProtectionSpaceInFrame(uint64_t frameID, const WebCore::ProtectionSpace&, bool& canAuthenticate); void didReceiveAuthenticationChallenge(uint64_t frameID, const WebCore::AuthenticationChallenge&, uint64_t challengeID); -#if PLATFORM(MAC) + void didFinishLoadingDataForCustomContentProvider(const String& suggestedFilename, const IPC::DataReference&); + +#if PLATFORM(COCOA) void pluginFocusOrWindowFocusChanged(uint64_t pluginComplexTextInputIdentifier, bool pluginHasFocusAndWindowHasFocus); void setPluginComplexTextInputState(uint64_t pluginComplexTextInputIdentifier, uint64_t complexTextInputState); #endif bool maybeInitializeSandboxExtensionHandle(const WebCore::URL&, SandboxExtension::Handle&); -#if PLATFORM(MAC) && !PLATFORM(IOS) +#if PLATFORM(MAC) void substitutionsPanelIsShowing(bool&); void showCorrectionPanel(int32_t panelType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings); void dismissCorrectionPanel(int32_t reason); @@ -1132,22 +1391,35 @@ private: void removeDictationAlternatives(uint64_t dictationContext); void dictationAlternatives(uint64_t dictationContext, Vector<String>& result); #endif -#endif // PLATFORM(MAC) && !PLATFORM(IOS) +#endif // PLATFORM(MAC) #if PLATFORM(IOS) - void mainDocumentDidReceiveMobileDocType(); + WebCore::FloatSize screenSize(); + WebCore::FloatSize availableScreenSize(); + float textAutosizingWidth(); - void didGetTapHighlightGeometries(uint64_t requestID, const WebCore::Color& color, const Vector<WebCore::FloatQuad>& geometries, const WebCore::IntSize& topLeftRadius, const WebCore::IntSize& topRightRadius, const WebCore::IntSize& bottomLeftRadius, const WebCore::IntSize& bottomRightRadius); + void dynamicViewportUpdateChangedTarget(double newTargetScale, const WebCore::FloatPoint& newScrollPosition, uint64_t dynamicViewportSizeUpdateID); + void couldNotRestorePageState(); + void restorePageState(const WebCore::FloatRect&, double scale); + void restorePageCenterAndScale(const WebCore::FloatPoint&, double scale); - void didChangeViewportArguments(const WebCore::ViewportArguments& viewportArguments); + void didGetTapHighlightGeometries(uint64_t requestID, const WebCore::Color& color, const Vector<WebCore::FloatQuad>& geometries, const WebCore::IntSize& topLeftRadius, const WebCore::IntSize& topRightRadius, const WebCore::IntSize& bottomLeftRadius, const WebCore::IntSize& bottomRightRadius); - void startAssistingNode(const WebCore::IntRect&, bool hasNextFocusable, bool hasPreviousFocusable); + void startAssistingNode(const AssistedNodeInformation&, bool userIsInteracting, bool blurPreviousNode, const UserData&); void stopAssistingNode(); - void notifyRevealedSelection(); + + void showInspectorHighlight(const WebCore::Highlight&); + void hideInspectorHighlight(); + + void showInspectorIndication(); + void hideInspectorIndication(); + + void enableInspectorNodeSearch(); + void disableInspectorNodeSearch(); #endif // PLATFORM(IOS) -#if USE(SOUP) && !ENABLE(CUSTOM_PROTOCOLS) - void didReceiveURIRequest(String uriString, uint64_t requestID); +#if ENABLE(DATA_DETECTION) + RetainPtr<NSArray> m_dataDetectionResults; #endif void clearLoadDependentCallbacks(); @@ -1167,23 +1439,75 @@ private: void processNextQueuedWheelEvent(); void sendWheelEvent(const WebWheelEvent&); +#if ENABLE(TOUCH_EVENTS) + bool shouldStartTrackingTouchEvents(const WebTouchEvent&) const; +#endif + #if ENABLE(NETSCAPE_PLUGIN_API) void findPlugin(const String& mimeType, uint32_t processType, const String& urlString, const String& frameURLString, const String& pageURLString, bool allowOnlyApplicationPlugins, uint64_t& pluginProcessToken, String& newMIMEType, uint32_t& pluginLoadPolicy, String& unavailabilityDescription); #endif +#if USE(QUICK_LOOK) + void didStartLoadForQuickLookDocumentInMainFrame(const String& fileName, const String& uti); + void didFinishLoadForQuickLookDocumentInMainFrame(const QuickLookDocumentData&); +#endif + +#if ENABLE(CONTENT_FILTERING) + void contentFilterDidBlockLoadForFrame(const WebCore::ContentFilterUnblockHandler&, uint64_t frameID); +#endif + + uint64_t generateNavigationID(); + + WebPreferencesStore preferencesStore() const; + + void dispatchViewStateChange(); + void viewDidLeaveWindow(); + void viewDidEnterWindow(); + +#if PLATFORM(MAC) + void didPerformImmediateActionHitTest(const WebHitTestResultData&, bool contentPreventsDefault, const UserData&); +#endif + + void useFixedLayoutDidChange(bool useFixedLayout) { m_useFixedLayout = useFixedLayout; } + void fixedLayoutSizeDidChange(WebCore::IntSize fixedLayoutSize) { m_fixedLayoutSize = fixedLayoutSize; } + + void imageOrMediaDocumentSizeChanged(const WebCore::IntSize&); +#if ENABLE(VIDEO) +#if USE(GSTREAMER) + void requestInstallMissingMediaPlugins(const String& details, const String& description); +#endif +#endif + + void handleAutoFillButtonClick(const UserData&); + + void finishInitializingWebPageAfterProcessLaunch(); + + void handleMessage(IPC::Connection&, const String& messageName, const UserData& messageBody); + void handleSynchronousMessage(IPC::Connection&, const String& messageName, const UserData& messageBody, UserData& returnUserData); + PageClient& m_pageClient; + Ref<API::PageConfiguration> m_configuration; + std::unique_ptr<API::LoaderClient> m_loaderClient; std::unique_ptr<API::PolicyClient> m_policyClient; - WebFormClient m_formClient; - WebUIClient m_uiClient; + std::unique_ptr<API::NavigationClient> m_navigationClient; + std::unique_ptr<API::HistoryClient> m_historyClient; + std::unique_ptr<API::FormClient> m_formClient; + std::unique_ptr<API::UIClient> m_uiClient; #if PLATFORM(EFL) WebUIPopupMenuClient m_uiPopupMenuClient; #endif - WebFindClient m_findClient; - WebFindMatchesClient m_findMatchesClient; + std::unique_ptr<API::FindClient> m_findClient; + std::unique_ptr<API::FindMatchesClient> m_findMatchesClient; + std::unique_ptr<API::DiagnosticLoggingClient> m_diagnosticLoggingClient; #if ENABLE(CONTEXT_MENUS) - WebPageContextMenuClient m_contextMenuClient; + std::unique_ptr<API::ContextMenuClient> m_contextMenuClient; #endif + std::unique_ptr<WebPageInjectedBundleClient> m_injectedBundleClient; + + std::unique_ptr<WebNavigationState> m_navigationState; + String m_failingProvisionalLoadURL; + bool m_isLoadingAlternateHTMLStringForFailingProvisionalLoad { false }; std::unique_ptr<DrawingAreaProxy> m_drawingArea; #if ENABLE(ASYNC_SCROLLING) @@ -1192,6 +1516,14 @@ private: Ref<WebProcessProxy> m_process; Ref<WebPageGroup> m_pageGroup; + Ref<WebPreferences> m_preferences; + + WebProcessLifetimeTracker m_webProcessLifetimeTracker { *this }; + + const RefPtr<WebUserContentControllerProxy> m_userContentController; + Ref<VisitedLinkStore> m_visitedLinkStore; + Ref<WebsiteDataStore> m_websiteDataStore; + RefPtr<WebFrameProxy> m_mainFrame; RefPtr<WebFrameProxy> m_focusedFrame; RefPtr<WebFrameProxy> m_frameSetLargestFrame; @@ -1201,79 +1533,92 @@ private: String m_customUserAgent; String m_customTextEncodingName; -#if ENABLE(INSPECTOR) + bool m_treatsSHA1CertificatesAsInsecure; + RefPtr<WebInspectorProxy> m_inspector; -#endif #if ENABLE(FULLSCREEN_API) RefPtr<WebFullScreenManagerProxy> m_fullScreenManager; #endif +#if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)) + RefPtr<WebVideoFullscreenManagerProxy> m_videoFullscreenManager; +#endif +#if PLATFORM(IOS) + VisibleContentRectUpdateInfo m_lastVisibleContentRectUpdate; + bool m_hasReceivedLayerTreeTransactionAfterDidCommitLoad; + uint64_t m_firstLayerTreeTransactionIdAfterDidCommitLoad; + int32_t m_deviceOrientation; + bool m_dynamicViewportSizeUpdateWaitingForTarget; + bool m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit; + uint64_t m_dynamicViewportSizeUpdateLayerTreeTransactionID; + uint64_t m_layerTreeTransactionIdAtLastTouchStart; + uint64_t m_currentDynamicViewportSizeUpdateID { 0 }; + bool m_hasNetworkRequestsOnSuspended; +#endif #if ENABLE(VIBRATION) RefPtr<WebVibrationProxy> m_vibration; #endif - HashMap<uint64_t, RefPtr<VoidCallback>> m_voidCallbacks; - HashMap<uint64_t, RefPtr<DataCallback>> m_dataCallbacks; - HashMap<uint64_t, RefPtr<ImageCallback>> m_imageCallbacks; - HashMap<uint64_t, RefPtr<StringCallback>> m_stringCallbacks; - HashSet<uint64_t> m_loadDependentStringCallbackIDs; - HashMap<uint64_t, RefPtr<ScriptValueCallback>> m_scriptValueCallbacks; - HashMap<uint64_t, RefPtr<ComputedPagesCallback>> m_computedPagesCallbacks; - HashMap<uint64_t, RefPtr<ValidateCommandCallback>> m_validateCommandCallbacks; -#if PLATFORM(IOS) - HashMap<uint64_t, RefPtr<GestureCallback>> m_gestureCallbacks; - HashMap<uint64_t, RefPtr<TouchesCallback>> m_touchesCallbacks; - HashMap<uint64_t, RefPtr<AutocorrectionDataCallback>> m_autocorrectionCallbacks; - HashMap<uint64_t, RefPtr<AutocorrectionContextCallback>> m_autocorrectionContextCallbacks; -#endif -#if PLATFORM(GTK) - HashMap<uint64_t, RefPtr<PrintFinishedCallback>> m_printFinishedCallbacks; +#if USE(APPLE_INTERNAL_SDK) +#include <WebKitAdditions/WebPageProxyMembers.h> #endif + CallbackMap m_callbacks; + HashSet<uint64_t> m_loadDependentStringCallbackIDs; + HashSet<WebEditCommandProxy*> m_editCommandSet; -#if PLATFORM(MAC) +#if PLATFORM(COCOA) HashSet<String> m_knownKeypressCommandNames; #endif RefPtr<WebPopupMenuProxy> m_activePopupMenu; - RefPtr<WebContextMenuProxy> m_activeContextMenu; - WebHitTestResult::Data m_activeContextMenuHitTestResultData; +#if ENABLE(CONTEXT_MENUS) + std::unique_ptr<WebContextMenuProxy> m_activeContextMenu; + ContextMenuContextData m_activeContextMenuContextData; +#endif + RefPtr<API::HitTestResult> m_lastMouseMoveHitTestResult; + RefPtr<WebOpenPanelResultListenerProxy> m_openPanelResultListener; GeolocationPermissionRequestManagerProxy m_geolocationPermissionRequestManager; NotificationPermissionRequestManagerProxy m_notificationPermissionRequestManager; - WebCore::ViewState::Flags m_viewState; + UserMediaPermissionRequestManagerProxy m_userMediaPermissionRequestManager; - bool m_canGoBack; - bool m_canGoForward; + WebCore::ViewState::Flags m_viewState; + bool m_viewWasEverInWindow; +#if PLATFORM(IOS) + bool m_allowsMediaDocumentInlinePlayback { false }; + bool m_alwaysRunsAtForegroundPriority; + ProcessThrottler::ForegroundActivityToken m_activityToken; +#endif + Ref<WebBackForwardList> m_backForwardList; - + bool m_maintainsInactiveSelection; String m_toolTip; - String m_urlAtProcessExit; - FrameLoadState::State m_loadStateAtProcessExit; - EditorState m_editorState; - bool m_temporarilyClosedComposition; // Editor state changed from hasComposition to !hasComposition, but that was only with shouldIgnoreCompositionSelectionChange yet. + bool m_isEditable; double m_textZoomFactor; double m_pageZoomFactor; double m_pageScaleFactor; + double m_pluginZoomFactor; + double m_pluginScaleFactor; + double m_viewScaleFactor { 1 }; float m_intrinsicDeviceScaleFactor; float m_customDeviceScaleFactor; + float m_topContentInset; LayerHostingMode m_layerHostingMode; bool m_drawsBackground; - bool m_drawsTransparentBackground; WebCore::Color m_underlayColor; - - bool m_areMemoryCacheClientCallsEnabled; + WebCore::Color m_pageExtendedBackgroundColor; bool m_useFixedLayout; WebCore::IntSize m_fixedLayoutSize; @@ -1284,7 +1629,8 @@ private: bool m_paginationBehavesLikeColumns; double m_pageLength; double m_gapBetweenPages; - + bool m_paginationLineGridEnabled; + // If the process backing the web page is alive and kicking. bool m_isValid; @@ -1294,6 +1640,8 @@ private: // Whether it can run modal child web pages. bool m_canRunModal; + bool m_needsToFinishInitializingWebPageAfterProcessLaunch { false }; + bool m_isInPrintingMode; bool m_isPerformingDOMPrintOperation; @@ -1301,52 +1649,73 @@ private: const WebCore::ResourceRequest* m_decidePolicyForResponseRequest; bool m_syncMimeTypePolicyActionIsValid; WebCore::PolicyAction m_syncMimeTypePolicyAction; - uint64_t m_syncMimeTypePolicyDownloadID; + DownloadID m_syncMimeTypePolicyDownloadID; bool m_inDecidePolicyForNavigationAction; bool m_syncNavigationActionPolicyActionIsValid; WebCore::PolicyAction m_syncNavigationActionPolicyAction; - uint64_t m_syncNavigationActionPolicyDownloadID; + DownloadID m_syncNavigationActionPolicyDownloadID; + bool m_shouldSuppressAppLinksInNextNavigationPolicyDecision { false }; Deque<NativeWebKeyboardEvent> m_keyEventQueue; Deque<NativeWebWheelEvent> m_wheelEventQueue; - Deque<OwnPtr<Vector<NativeWebWheelEvent>>> m_currentlyProcessedWheelEvents; + Deque<std::unique_ptr<Vector<NativeWebWheelEvent>>> m_currentlyProcessedWheelEvents; +#if ENABLE(MAC_GESTURE_EVENTS) + Deque<NativeWebGestureEvent> m_gestureEventQueue; +#endif bool m_processingMouseMoveEvent; - OwnPtr<NativeWebMouseEvent> m_nextMouseMoveEvent; - OwnPtr<NativeWebMouseEvent> m_currentlyProcessedMouseDownEvent; + std::unique_ptr<NativeWebMouseEvent> m_nextMouseMoveEvent; + std::unique_ptr<NativeWebMouseEvent> m_currentlyProcessedMouseDownEvent; #if ENABLE(TOUCH_EVENTS) - bool m_needTouchEvents; + bool m_isTrackingTouchEvents; +#endif +#if ENABLE(TOUCH_EVENTS) && !ENABLE(IOS_TOUCH_EVENTS) Deque<QueuedTouchEvents> m_touchEventQueue; #endif + #if ENABLE(INPUT_TYPE_COLOR) RefPtr<WebColorPicker> m_colorPicker; - RefPtr<WebColorPickerResultListenerProxy> m_colorPickerResultListener; #endif - uint64_t m_pageID; - Ref<API::Session> m_session; + const uint64_t m_pageID; + WebCore::SessionID m_sessionID; bool m_isPageSuspended; + bool m_addsVisitedLinks; -#if PLATFORM(MAC) +#if ENABLE(REMOTE_INSPECTOR) + bool m_allowsRemoteInspection; + String m_remoteInspectionNameOverride; +#endif + +#if PLATFORM(COCOA) bool m_isSmartInsertDeleteEnabled; #endif #if PLATFORM(GTK) String m_accessibilityPlugID; + WebCore::Color m_backgroundColor; #endif int64_t m_spellDocumentTag; bool m_hasSpellDocumentTag; unsigned m_pendingLearnOrIgnoreWordMessageCount; + bool m_mainFrameHasCustomContentProvider; + #if ENABLE(DRAG_SUPPORT) - WebCore::DragSession m_currentDragSession; + // Current drag destination details are delivered as an asynchronous response, + // so we preserve them to be used when the next dragging delegate call is made. + WebCore::DragOperation m_currentDragOperation; + bool m_currentDragIsOverFileInput; + unsigned m_currentDragNumberOfFilesToBeAccepted; #endif PageLoadState m_pageLoadState; + + bool m_delegatesScrolling; bool m_mainFrameHasHorizontalScrollbar; bool m_mainFrameHasVerticalScrollbar; @@ -1359,40 +1728,78 @@ private: bool m_mainFrameIsPinnedToTopSide; bool m_mainFrameIsPinnedToBottomSide; - bool m_useLegacyImplicitRubberBandControl; + bool m_shouldUseImplicitRubberBandControl; bool m_rubberBandsAtLeft; bool m_rubberBandsAtRight; bool m_rubberBandsAtTop; bool m_rubberBandsAtBottom; + + bool m_enableVerticalRubberBanding; + bool m_enableHorizontalRubberBanding; bool m_backgroundExtendsBeyondPage; - bool m_mainFrameInViewSourceMode; - bool m_shouldRecordNavigationSnapshots; + bool m_isShowingNavigationGestureSnapshot; + + bool m_mainFramePluginHandlesPageScaleGesture { false }; unsigned m_pageCount; WebCore::IntRect m_visibleScrollerThumbRect; uint64_t m_renderTreeSize; - - bool m_shouldSendEventsSynchronously; + uint64_t m_sessionRestorationRenderTreeSize; + bool m_wantsSessionRestorationRenderTreeSizeThresholdEvent; + bool m_hitRenderTreeSizeThreshold; bool m_suppressVisibilityUpdates; bool m_autoSizingShouldExpandToViewHeight; WebCore::IntSize m_minimumLayoutSize; float m_mediaVolume; + bool m_muted; bool m_mayStartMediaWhenInWindow; bool m_waitingForDidUpdateViewState; -#if PLATFORM(MAC) + bool m_shouldScaleViewToFitDocument { false }; + bool m_suppressNavigationSnapshotting { false }; + +#if PLATFORM(COCOA) HashMap<String, String> m_temporaryPDFFiles; + std::unique_ptr<WebCore::RunLoopObserver> m_viewStateChangeDispatcher; + + std::unique_ptr<RemoteLayerTreeScrollingPerformanceData> m_scrollingPerformanceData; + bool m_scrollPerformanceDataCollectionEnabled; #endif + UserObservablePageToken m_pageIsUserObservableCount; + ProcessSuppressionDisabledToken m_preventProcessSuppressionCount; WebCore::ScrollPinningBehavior m_scrollPinningBehavior; + WTF::Optional<WebCore::ScrollbarOverlayStyle> m_scrollbarOverlayStyle; + + uint64_t m_navigationID; + + WebPreferencesStore::ValueMap m_configurationPreferenceValues; + WebCore::ViewState::Flags m_potentiallyChangedViewStateFlags; + bool m_viewStateChangeWantsSynchronousReply; + Vector<uint64_t> m_nextViewStateChangeCallbacks; + + WebCore::MediaProducer::MediaStateFlags m_mediaState { WebCore::MediaProducer::IsNotPlaying }; + +#if ENABLE(MEDIA_SESSION) + bool m_hasMediaSessionWithActiveMediaElements { false }; +#endif + +#if ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS) + bool m_requiresTargetMonitoring { false }; +#endif + +#if PLATFORM(IOS) + bool m_hasDeferredStartAssistingNode { false }; + std::unique_ptr<NodeAssistanceArguments> m_deferredNodeAssistanceArguments; +#endif }; } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebPageProxy.messages.in b/Source/WebKit2/UIProcess/WebPageProxy.messages.in index 871760a03..92eb56a9f 100644 --- a/Source/WebKit2/UIProcess/WebPageProxy.messages.in +++ b/Source/WebKit2/UIProcess/WebPageProxy.messages.in @@ -22,21 +22,22 @@ messages -> WebPageProxy { # UI messages - CreateNewPage(WebCore::ResourceRequest request, WebCore::WindowFeatures windowFeatures, uint32_t modifiers, int32_t mouseButton) -> (uint64_t newPageID, WebKit::WebPageCreationParameters newPageParameters) + CreateNewPage(uint64_t frameID, struct WebCore::SecurityOriginData frameSecurityOrigin, WebCore::ResourceRequest request, struct WebCore::WindowFeatures windowFeatures, struct WebKit::NavigationActionData navigationActionData) -> (uint64_t newPageID, struct WebKit::WebPageCreationParameters newPageParameters) ShowPage() ClosePage(bool stopResponsivenessTimer) - RunJavaScriptAlert(uint64_t frameID, String message) -> () - RunJavaScriptConfirm(uint64_t frameID, String message) -> (bool result) - RunJavaScriptPrompt(uint64_t frameID, String message, String defaultValue) -> (String result) - ShouldInterruptJavaScript() -> (bool shouldInterupt) - MouseDidMoveOverElement(WebKit::WebHitTestResult::Data hitTestResultData, uint32_t modifiers, WebKit::InjectedBundleUserMessageEncoder userData) Variadic + RunJavaScriptAlert(uint64_t frameID, struct WebCore::SecurityOriginData frameSecurityOrigin, String message) -> () Delayed + RunJavaScriptConfirm(uint64_t frameID, struct WebCore::SecurityOriginData frameSecurityOrigin, String message) -> (bool result) Delayed + RunJavaScriptPrompt(uint64_t frameID, struct WebCore::SecurityOriginData frameSecurityOrigin, String message, String defaultValue) -> (String result) Delayed + MouseDidMoveOverElement(struct WebKit::WebHitTestResultData hitTestResultData, uint32_t modifiers, WebKit::UserData userData) + #if ENABLE(NETSCAPE_PLUGIN_API) UnavailablePluginButtonClicked(uint32_t pluginUnavailabilityReason, String mimeType, String pluginURLString, String pluginspageAttributeURLString, String frameURLString, String pageURLString) #endif // ENABLE(NETSCAPE_PLUGIN_API) #if ENABLE(WEBGL) WebGLPolicyForURL(String url) -> (uint32_t loadPolicy) + ResolveWebGLPolicyForURL(String url) -> (uint32_t loadPolicy) #endif // ENABLE(WEBGL) - DidChangeViewportProperties(WebCore::ViewportAttributes attributes) + DidChangeViewportProperties(struct WebCore::ViewportAttributes attributes) DidReceiveEvent(uint32_t type, bool handled) StopResponsivenessTimer() #if !PLATFORM(IOS) @@ -60,18 +61,25 @@ messages -> WebPageProxy { GetIsResizable() -> (bool isResizable) SetWindowFrame(WebCore::FloatRect windowFrame) GetWindowFrame() -> (WebCore::FloatRect windowFrame) - ScreenToWindow(WebCore::IntPoint screenPoint) -> (WebCore::IntPoint windowPoint) - WindowToScreen(WebCore::IntRect rect) -> (WebCore::IntRect screenFrame) - RunBeforeUnloadConfirmPanel(String message, uint64_t frameID) -> (bool shouldClose) + ScreenToRootView(WebCore::IntPoint screenPoint) -> (WebCore::IntPoint windowPoint) + RootViewToScreen(WebCore::IntRect rect) -> (WebCore::IntRect screenFrame) + +#if PLATFORM(IOS) + AccessibilityScreenToRootView(WebCore::IntPoint screenPoint) -> (WebCore::IntPoint windowPoint) + RootViewToAccessibilityScreen(WebCore::IntRect rect) -> (WebCore::IntRect screenFrame) +#endif + + RunBeforeUnloadConfirmPanel(String message, uint64_t frameID) -> (bool shouldClose) Delayed PageDidScroll() - RunOpenPanel(uint64_t frameID, WebCore::FileChooserSettings parameters) + RunOpenPanel(uint64_t frameID, struct WebCore::FileChooserSettings parameters) PrintFrame(uint64_t frameID) -> () RunModal() NotifyScrollerThumbIsVisibleInRect(WebCore::IntRect scrollerThumb) RecommendedScrollbarStyleDidChange(int32_t newStyle) DidChangeScrollbarsForMainFrame(bool hasHorizontalScrollbar, bool hasVerticalScrollbar) DidChangeScrollOffsetPinningForMainFrame(bool pinnedToLeftSide, bool pinnedToRightSide, bool pinnedToTopSide, bool pinnedToBottomSide) - DidChangePageCount(unsigned pageCount); + DidChangePageCount(unsigned pageCount) + PageExtendedBackgroundColorDidChange(WebCore::Color backgroundColor) #if ENABLE(NETSCAPE_PLUGIN_API) DidFailToInitializePlugin(String mimeType, String frameURLString, String pageURLString) DidBlockInsecurePluginVersion(String mimeType, String pluginURLString, String frameURLString, String pageURLString, bool replacementObscured) @@ -82,21 +90,13 @@ messages -> WebPageProxy { HandleInputMethodKeydown() -> (bool handled) #endif -#if USE(TILED_BACKING_STORE) +#if USE(COORDINATED_GRAPHICS_MULTIPROCESS) PageDidRequestScroll(WebCore::IntPoint point) PageTransitionViewportReady() -#endif -#if USE(COORDINATED_GRAPHICS) DidFindZoomableArea(WebCore::IntPoint target, WebCore::IntRect area) #endif -#if PLATFORM(EFL) || PLATFORM(IOS) DidChangeContentSize(WebCore::IntSize newSize) -#endif - -#if ENABLE(TOUCH_EVENTS) - NeedTouchEvents(bool needTouchEvents) -#endif #if ENABLE(INPUT_TYPE_COLOR) ShowColorPicker(WebCore::Color initialColor, WebCore::IntRect elementRect); @@ -105,70 +105,102 @@ messages -> WebPageProxy { #endif # Policy messages - DecidePolicyForResponseSync(uint64_t frameID, WebCore::ResourceResponse response, WebCore::ResourceRequest request, bool canShowMIMEType, uint64_t listenerID, WebKit::InjectedBundleUserMessageEncoder userData) -> (bool receivedPolicyAction, uint64_t policyAction, uint64_t downloadID) Variadic - DecidePolicyForNavigationAction(uint64_t frameID, WebKit::NavigationActionData navigationActionData, uint64_t originatingFrameID, WebCore::ResourceRequest originalRequest, WebCore::ResourceRequest request, uint64_t listenerID, WebKit::InjectedBundleUserMessageEncoder userData) -> (bool receivedPolicyAction, uint64_t policyAction, uint64_t downloadID) Variadic - DecidePolicyForNewWindowAction(uint64_t frameID, WebKit::NavigationActionData navigationActionData, WebCore::ResourceRequest request, String frameName, uint64_t listenerID, WebKit::InjectedBundleUserMessageEncoder userData) Variadic - UnableToImplementPolicy(uint64_t frameID, WebCore::ResourceError error, WebKit::InjectedBundleUserMessageEncoder userData) Variadic + DecidePolicyForResponseSync(uint64_t frameID, struct WebCore::SecurityOriginData frameSecurityOrigin, WebCore::ResourceResponse response, WebCore::ResourceRequest request, bool canShowMIMEType, uint64_t listenerID, WebKit::UserData userData) -> (bool receivedPolicyAction, uint64_t policyAction, WebKit::DownloadID downloadID) + DecidePolicyForNavigationAction(uint64_t frameID, struct WebCore::SecurityOriginData frameSecurityOrigin, uint64_t navigationID, struct WebKit::NavigationActionData navigationActionData, uint64_t originatingFrameID, struct WebCore::SecurityOriginData originatingFrameSecurityOrigin, WebCore::ResourceRequest originalRequest, WebCore::ResourceRequest request, uint64_t listenerID, WebKit::UserData userData) -> (bool receivedPolicyAction, uint64_t newNavigationID, uint64_t policyAction, WebKit::DownloadID downloadID) + DecidePolicyForNewWindowAction(uint64_t frameID, struct WebCore::SecurityOriginData frameSecurityOrigin, struct WebKit::NavigationActionData navigationActionData, WebCore::ResourceRequest request, String frameName, uint64_t listenerID, WebKit::UserData userData) + UnableToImplementPolicy(uint64_t frameID, WebCore::ResourceError error, WebKit::UserData userData) # Progress messages DidChangeProgress(double value) DidFinishProgress() DidStartProgress() + SetNetworkRequestsInProgress(bool networkRequestsInProgress) + # Frame lifetime messages DidCreateMainFrame(uint64_t frameID) DidCreateSubframe(uint64_t frameID) # Frame load messages - DidCommitLoadForFrame(uint64_t frameID, String mimeType, uint32_t loadType, WebCore::CertificateInfo certificateInfo, WebKit::InjectedBundleUserMessageEncoder userData) Variadic - DidFailLoadForFrame(uint64_t frameID, WebCore::ResourceError error, WebKit::InjectedBundleUserMessageEncoder userData) Variadic - DidFailProvisionalLoadForFrame(uint64_t frameID, WebCore::ResourceError error, WebKit::InjectedBundleUserMessageEncoder userData) Variadic - DidFinishDocumentLoadForFrame(uint64_t frameID, WebKit::InjectedBundleUserMessageEncoder userData) Variadic - DidFinishLoadForFrame(uint64_t frameID, WebKit::InjectedBundleUserMessageEncoder userData) Variadic - DidFirstLayoutForFrame(uint64_t frameID, WebKit::InjectedBundleUserMessageEncoder userData) Variadic - DidFirstVisuallyNonEmptyLayoutForFrame(uint64_t frameID, WebKit::InjectedBundleUserMessageEncoder userData) Variadic - DidLayout(uint32_t type, WebKit::InjectedBundleUserMessageEncoder userData) Variadic - DidReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, String url, WebKit::InjectedBundleUserMessageEncoder userData) Variadic - DidRemoveFrameFromHierarchy(uint64_t frameID, WebKit::InjectedBundleUserMessageEncoder userData) Variadic - DidStartProvisionalLoadForFrame(uint64_t frameID, String url, String unreachableURL, WebKit::InjectedBundleUserMessageEncoder userData) Variadic - DidReceiveTitleForFrame(uint64_t frameID, String title, WebKit::InjectedBundleUserMessageEncoder userData) Variadic - DidDisplayInsecureContentForFrame(uint64_t frameID, WebKit::InjectedBundleUserMessageEncoder userData) Variadic - DidRunInsecureContentForFrame(uint64_t frameID, WebKit::InjectedBundleUserMessageEncoder userData) Variadic - DidDetectXSSForFrame(uint64_t frameID, WebKit::InjectedBundleUserMessageEncoder userData) Variadic - DidSameDocumentNavigationForFrame(uint64_t frameID, uint32_t type, String url, WebKit::InjectedBundleUserMessageEncoder userData) Variadic + DidStartProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, String url, String unreachableURL, WebKit::UserData userData) + DidReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, String url, WebKit::UserData userData) + DidChangeProvisionalURLForFrame(uint64_t frameID, uint64_t navigationID, String url) + DidFailProvisionalLoadForFrame(uint64_t frameID, struct WebCore::SecurityOriginData frameSecurityOrigin, uint64_t navigationID, String provisionalURL, WebCore::ResourceError error, WebKit::UserData userData) + DidCommitLoadForFrame(uint64_t frameID, uint64_t navigationID, String mimeType, bool hasCustomContentProvider, bool pluginHandlesPageScaleGesture, uint32_t loadType, WebCore::CertificateInfo certificateInfo, bool containsPluginDocument, WebKit::UserData userData) + DidFailLoadForFrame(uint64_t frameID, uint64_t navigationID, WebCore::ResourceError error, WebKit::UserData userData) + DidFinishDocumentLoadForFrame(uint64_t frameID, uint64_t navigationID, WebKit::UserData userData) + DidFinishLoadForFrame(uint64_t frameID, uint64_t navigationID, WebKit::UserData userData) + DidFirstLayoutForFrame(uint64_t frameID, WebKit::UserData userData) + DidFirstVisuallyNonEmptyLayoutForFrame(uint64_t frameID, WebKit::UserData userData) + DidLayout(uint32_t type) + DidReceiveTitleForFrame(uint64_t frameID, String title, WebKit::UserData userData) + DidDisplayInsecureContentForFrame(uint64_t frameID, WebKit::UserData userData) + DidRunInsecureContentForFrame(uint64_t frameID, WebKit::UserData userData) + DidDetectXSSForFrame(uint64_t frameID, WebKit::UserData userData) + DidSameDocumentNavigationForFrame(uint64_t frameID, uint64_t navigationID, uint32_t type, String url, WebKit::UserData userData) + DidDestroyNavigation(uint64_t navigationID) FrameDidBecomeFrameSet(uint64_t frameID, bool value) + # History client messages. + DidNavigateWithNavigationData(struct WebKit::WebNavigationDataStore store, uint64_t frameID) + DidPerformClientRedirect(String sourceURLString, String destinationURLString, uint64_t frameID) + DidPerformServerRedirect(String sourceURLString, String destinationURLString, uint64_t frameID) + DidUpdateHistoryTitle(String title, String url, uint64_t frameID) + + # Custom representations + DidFinishLoadingDataForCustomContentProvider(String suggestedFilename, IPC::DataReference data) + # Forms messages - WillSubmitForm(uint64_t frameID, uint64_t sourceFrameID, Vector<std::pair<String, String>> textFieldValues, uint64_t listenerID, WebKit::InjectedBundleUserMessageEncoder userData) Variadic + WillSubmitForm(uint64_t frameID, uint64_t sourceFrameID, Vector<std::pair<String, String>> textFieldValues, uint64_t listenerID, WebKit::UserData userData) # Callback messages VoidCallback(uint64_t callbackID) DataCallback(IPC::DataReference resultData, uint64_t callbackID) ImageCallback(WebKit::ShareableBitmap::Handle bitmapHandle, uint64_t callbackID) StringCallback(String resultString, uint64_t callbackID) - ScriptValueCallback(IPC::DataReference resultData, uint64_t callbackID) + ScriptValueCallback(IPC::DataReference resultData, bool hadException, struct WebCore::ExceptionDetails details, uint64_t callbackID) ComputedPagesCallback(Vector<WebCore::IntRect> pageRects, double totalScaleFactorForPrinting, uint64_t callbackID) ValidateCommandCallback(String command, bool isEnabled, int32_t state, uint64_t callbackID) + EditingRangeCallback(struct WebKit::EditingRange range, uint64_t callbackID) + UnsignedCallback(uint64_t result, uint64_t callbackID) + RectForCharacterRangeCallback(WebCore::IntRect rect, struct WebKit::EditingRange actualRange, uint64_t callbackID) +#if PLATFORM(MAC) + AttributedStringForCharacterRangeCallback(struct WebKit::AttributedString string, struct WebKit::EditingRange actualRange, uint64_t callbackID) + FontAtSelectionCallback(String fontName, double fontSize, bool selectioHasMultipleFonts, uint64_t callbackID) +#endif #if PLATFORM(IOS) GestureCallback(WebCore::IntPoint point, uint32_t gestureType, uint32_t gestureState, uint32_t flags, uint64_t callbackID) TouchesCallback(WebCore::IntPoint point, uint32_t touches, uint64_t callbackID) AutocorrectionDataCallback(Vector<WebCore::FloatRect> textRects, String fontName, double fontSize, uint64_t traits, uint64_t callbackID) AutocorrectionContextCallback(String beforeText, String markedText, String selectedText, String afterText, uint64_t location, uint64_t length, uint64_t callbackID) - InterpretKeyEvent(WebKit::EditorState state, bool isCharEvent) -> (bool handled) - DidReceivePositionInformation(WebKit::InteractionInformationAtPosition information) + DictationContextCallback(String selectedText, String beforeText, String afterText, uint64_t callbackID) + InterpretKeyEvent(struct WebKit::EditorState state, bool isCharEvent) -> (bool handled) + DidReceivePositionInformation(struct WebKit::InteractionInformationAtPosition information) + SaveImageToLibrary(WebKit::SharedMemory::Handle handle, uint64_t size) + DidUpdateBlockSelectionWithTouch(uint32_t touch, uint32_t flags, float growThreshold, float shrinkThreshold) + ShowPlaybackTargetPicker(bool hasVideo, WebCore::IntRect elementRect) + ZoomToRect(WebCore::FloatRect rect, double minimumScale, double maximumScale) + CommitPotentialTapFailed() + DidNotHandleTapAsClick(WebCore::IntPoint point) + DisableDoubleTapGesturesDuringTapIfNecessary(uint64_t requestID) + DidFinishDrawingPagesToPDF(IPC::DataReference pdfData) +#endif +#if ENABLE(DATA_DETECTION) + SetDataDetectionResult(struct WebKit::DataDetectionResult dataDetectionResult) #endif #if PLATFORM(GTK) PrintFinishedCallback(WebCore::ResourceError error, uint64_t callbackID) #endif +#if PLATFORM(COCOA) + MachSendRightCallback(WebCore::MachSendRight sendRight, uint64_t callbackID) +#endif PageScaleFactorDidChange(double scaleFactor) - PageZoomFactorDidChange(double zoomFactor) + PluginScaleFactorDidChange(double zoomFactor) + PluginZoomFactorDidChange(double zoomFactor) #if PLATFORM(GTK) - # Support for GTK+ platform keybindings - GetEditorCommandsForKeyEvent(AtomicString eventType) -> (Vector<String> commandsList) - # Support for connecting the Accessibility worlds of the UI and the Web processes BindAccessibilityTree(String plugID) @@ -182,32 +214,39 @@ messages -> WebPageProxy { BackForwardBackListCount() -> (int32_t count) BackForwardForwardListCount() -> (int32_t count) BackForwardClear() - WillGoToBackForwardListItem(uint64_t itemID, WebKit::InjectedBundleUserMessageEncoder userData) Variadic + WillGoToBackForwardListItem(uint64_t itemID, WebKit::UserData userData) # Undo/Redo messages RegisterEditCommandForUndo(uint64_t commandID, uint32_t editAction) ClearAllEditCommands() + RegisterInsertionUndoGrouping() CanUndoRedo(uint32_t action) -> (bool result) ExecuteUndoRedo(uint32_t action) -> (bool result) + # Diagnostic messages logging + LogSampledDiagnosticMessage(String message, String description) + LogSampledDiagnosticMessageWithResult(String message, String description, uint32_t result) + LogSampledDiagnosticMessageWithValue(String message, String description, String value) + # Editor notifications - EditorStateChanged(WebKit::EditorState editorState) + EditorStateChanged(struct WebKit::EditorState editorState) + CompositionWasCanceled(struct WebKit::EditorState editorState) # Find messages DidCountStringMatches(String string, uint32_t matchCount) - SetFindIndicator(WebCore::FloatRect selectionRect, Vector<WebCore::FloatRect> textRects, float contentImageScaleFactor, WebKit::ShareableBitmap::Handle contentImageHandle, bool fadeOut, bool animate) - DidFindString(String string, uint32_t matchCount) + SetTextIndicator(struct WebCore::TextIndicatorData indicator, uint64_t lifetime) + ClearTextIndicator() + DidFindString(String string, Vector<WebCore::IntRect> matchRect, uint32_t matchCount, int32_t matchIndex) DidFailToFindString(String string) DidFindStringMatches(String string, Vector<Vector<WebCore::IntRect>> matches, int32_t firstIndexAfterSelection) DidGetImageForFindMatch(WebKit::ShareableBitmap::Handle contentImageHandle, uint32_t matchIndex) # PopupMenu messages - ShowPopupMenu(WebCore::IntRect rect, uint64_t textDirection, Vector<WebKit::WebPopupItem> items, int32_t selectedIndex, WebKit::PlatformPopupMenuData data) + ShowPopupMenu(WebCore::IntRect rect, uint64_t textDirection, Vector<WebKit::WebPopupItem> items, int32_t selectedIndex, struct WebKit::PlatformPopupMenuData data) HidePopupMenu() #if ENABLE(CONTEXT_MENUS) - # ContextMenu messages - ShowContextMenu(WebCore::IntPoint menuLocation, WebKit::WebHitTestResult::Data hitTestResultData, Vector<WebKit::WebContextMenuItemData> items, WebKit::InjectedBundleUserMessageEncoder userData) Variadic + ShowContextMenu(WebKit::ContextMenuContextData contextMenuContextData, WebKit::UserData userData) #endif # Authentication messages @@ -217,9 +256,18 @@ messages -> WebPageProxy { # Database messages ExceededDatabaseQuota(uint64_t frameID, String originIdentifier, String databaseName, String databaseDisplayName, uint64_t currentQuota, uint64_t currentOriginUsage, uint64_t currentDatabaseUsage, uint64_t expectedUsage) -> (uint64_t newQuota) Delayed + # Application cache messages + ReachedApplicationCacheOriginQuota(String originIdentifier, uint64_t currentQuota, uint64_t totalBytesNeeded) -> (uint64_t newQuota) Delayed + # Geolocation messages RequestGeolocationPermissionForFrame(uint64_t geolocationID, uint64_t frameID, String originIdentifier) +#if ENABLE(MEDIA_STREAM) + # MediaSteam messages + RequestUserMediaPermissionForFrame(uint64_t userMediaID, uint64_t frameID, String originIdentifier, Vector<String> audioDeviceUIDs, Vector<String> videoDeviceUIDs) + CheckUserMediaPermissionForFrame(uint64_t userMediaID, uint64_t frameID, String originIdentifier) +#endif + # Notification messages RequestNotificationPermission(uint64_t requestID, String originIdentifier) ShowNotification(String title, String body, String iconURL, String tag, String lang, String dir, String originIdentifier, uint64_t notificationID) @@ -235,7 +283,7 @@ messages -> WebPageProxy { CheckGrammarOfString(String text) -> (Vector<WebCore::GrammarDetail> results, int32_t badGrammarLocation, int32_t badGrammarLength) SpellingUIIsShowing() -> (bool isShowing) UpdateSpellingUIWithMisspelledWord(String misspelledWord) - UpdateSpellingUIWithGrammarString(String badGrammarPhrase, WebCore::GrammarDetail grammarDetail) + UpdateSpellingUIWithGrammarString(String badGrammarPhrase, struct WebCore::GrammarDetail grammarDetail) GetGuessesForWord(String word, String context) -> (Vector<String> guesses) LearnWord(String word); IgnoreWord(String word); @@ -243,22 +291,24 @@ messages -> WebPageProxy { # Drag and drop messages #if ENABLE(DRAG_SUPPORT) - DidPerformDragControllerAction(WebCore::DragSession dragSession) + DidPerformDragControllerAction(uint64_t dragOperation, bool mouseIsOverFileInput, unsigned numberOfItemsToBeAccepted) #endif -#if PLATFORM(MAC) && ENABLE(DRAG_SUPPORT) +#if PLATFORM(COCOA) && ENABLE(DRAG_SUPPORT) SetDragImage(WebCore::IntPoint clientPosition, WebKit::ShareableBitmap::Handle dragImage, bool linkDrag) - SetPromisedData(String pasteboardName, WebKit::SharedMemory::Handle imageHandle, uint64_t imageSize, String filename, String extension, String title, String url, String visibleURL, WebKit::SharedMemory::Handle archiveHandle, uint64_t archiveSize) + SetPromisedDataForImage(String pasteboardName, WebKit::SharedMemory::Handle imageHandle, uint64_t imageSize, String filename, String extension, String title, String url, String visibleURL, WebKit::SharedMemory::Handle archiveHandle, uint64_t archiveSize) +#if ENABLE(ATTACHMENT_ELEMENT) + SetPromisedDataForAttachment(String pasteboardName, String filename, String extension, String title, String url, String visibleURL) +#endif #endif #if PLATFORM(GTK) && ENABLE(DRAG_SUPPORT) StartDrag(WebCore::DragData dragData, WebKit::ShareableBitmap::Handle dragImage) #endif -#if PLATFORM(MAC) +#if PLATFORM(COCOA) # Dictionary support. - DidPerformDictionaryLookup(WebKit::AttributedString text, WebKit::DictionaryPopupInfo dictionaryPopupInfo) + DidPerformDictionaryLookup(struct WebCore::DictionaryPopupInfo dictionaryPopupInfo) # Keyboard input support messages - InterpretQueuedKeyEvent(WebKit::EditorState state) -> (bool handled, Vector<WebCore::KeypressCommand> savedCommands) ExecuteSavedCommandBySelector(String selector) -> (bool handled) # Remote accessibility messages @@ -284,7 +334,7 @@ messages -> WebPageProxy { #if USE(APPKIT) SubstitutionsPanelIsShowing() -> (bool isShowing) #endif -#if !PLATFORM(IOS) && PLATFORM(MAC) +#if PLATFORM(MAC) # Autocorrection messages ShowCorrectionPanel(int32_t panelType, WebCore::FloatRect boundingBoxOfReplacedString, String replacedString, String replacementString, Vector<String> alternativeReplacementStrings) DismissCorrectionPanel(int32_t reason) @@ -306,30 +356,33 @@ messages -> WebPageProxy { #endif #if PLATFORM(IOS) - MainDocumentDidReceiveMobileDocType(); - + DynamicViewportUpdateChangedTarget(double newTargetScale, WebCore::FloatPoint newScrollPosition, uint64_t dynamicViewportSizeUpdateID) + CouldNotRestorePageState() + RestorePageState(WebCore::FloatRect exposedRect, double scale) + RestorePageCenterAndScale(WebCore::FloatPoint unobscuredCenter, double scale) DidGetTapHighlightGeometries(uint64_t requestID, WebCore::Color color, Vector<WebCore::FloatQuad> geometries, WebCore::IntSize topLeftRadius, WebCore::IntSize topRightRadius, WebCore::IntSize bottomLeftRadius, WebCore::IntSize bottomRightRadius) - DidChangeViewportArguments(WebCore::ViewportArguments viewportArguments) - StartAssistingNode(WebCore::IntRect scrollRect, bool hasNextFocusable, bool hasPreviousFocusable) + StartAssistingNode(struct WebKit::AssistedNodeInformation information, bool userIsInteracting, bool blurPreviousNode, WebKit::UserData userData) StopAssistingNode() - NotifyRevealedSelection() -#endif + OverflowScrollWillStartScroll() + OverflowScrollDidEndScroll() + ShowInspectorHighlight(struct WebCore::Highlight highlight) + HideInspectorHighlight() - # Search popup menus - SaveRecentSearches(String name, Vector<String> searchItems) - LoadRecentSearches(String name) -> (Vector<String> result) + ShowInspectorIndication() + HideInspectorIndication() -#if USE(SOUP) -#if !ENABLE(CUSTOM_PROTOCOLS) - # Soup custom URI request messages - DidReceiveURIRequest(String uriString, uint64_t requestID); -#endif + EnableInspectorNodeSearch() + DisableInspectorNodeSearch() #endif + # Search popup menus + SaveRecentSearches(String name, Vector<WebCore::RecentSearch> searchItems) + LoadRecentSearches(String name) -> (Vector<WebCore::RecentSearch> result) + SavePDFToFileInDownloadsFolder(String suggestedFilename, String originatingURLString, IPC::DataReference data) -#if PLATFORM(MAC) +#if PLATFORM(COCOA) SavePDFToTemporaryFolderAndOpenWithNativeApplication(String suggestedFilename, String originatingURLString, IPC::DataReference data, String pdfUUID) OpenPDFFromTemporaryFolderWithNativeApplication(String pdfUUID) #endif @@ -341,4 +394,65 @@ messages -> WebPageProxy { DidUpdateViewState() DidSaveToPageCache() + +#if ENABLE(SUBTLE_CRYPTO) + WrapCryptoKey(Vector<uint8_t> key) -> (bool succeeded, Vector<uint8_t> wrappedKey) + UnwrapCryptoKey(Vector<uint8_t> wrappedKey) -> (bool succeeded, Vector<uint8_t> key) +#endif + + +#if ENABLE(TELEPHONE_NUMBER_DETECTION) +#if PLATFORM(MAC) + ShowTelephoneNumberMenu(String telephoneNumber, WebCore::IntPoint point) +#endif +#endif + +#if USE(QUICK_LOOK) + DidStartLoadForQuickLookDocumentInMainFrame(String fileName, String uti) + DidFinishLoadForQuickLookDocumentInMainFrame(WebKit::QuickLookDocumentData data) +#endif + +#if ENABLE(CONTENT_FILTERING) + ContentFilterDidBlockLoadForFrame(WebCore::ContentFilterUnblockHandler unblockHandler, uint64_t frameID) +#endif + + IsPlayingMediaDidChange(unsigned state, uint64_t sourceElementID) + +#if ENABLE(MEDIA_SESSION) + HasMediaSessionWithActiveMediaElementsDidChange(bool state) + MediaSessionMetadataDidChange(WebCore::MediaSessionMetadata metadata); + FocusedContentMediaElementDidChange(uint64_t elementID) +#endif + +#if PLATFORM(MAC) + DidPerformImmediateActionHitTest(struct WebKit::WebHitTestResultData result, bool contentPreventsDefault, WebKit::UserData userData) +#endif + HandleMessage(String messageName, WebKit::UserData messageBody) WantsConnection + HandleSynchronousMessage(String messageName, WebKit::UserData messageBody) -> (WebKit::UserData returnData) WantsConnection + + HandleAutoFillButtonClick(WebKit::UserData userData); + +#if ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS) + AddPlaybackTargetPickerClient(uint64_t contextId) + RemovePlaybackTargetPickerClient(uint64_t contextId) + ShowPlaybackTargetPicker(uint64_t clientId, WebCore::FloatRect pickerLocation, bool hasVideo) + PlaybackTargetPickerClientStateDidChange(uint64_t contextId, unsigned mediaState) + SetMockMediaPlaybackTargetPickerEnabled(bool enabled) + SetMockMediaPlaybackTargetPickerState(String name, unsigned pickerState) +#endif + + ImageOrMediaDocumentSizeChanged(WebCore::IntSize newSize) + + UseFixedLayoutDidChange(bool useFixedLayout) + FixedLayoutSizeDidChange(WebCore::IntSize fixedLayoutSize) + +#if ENABLE(VIDEO) && USE(GSTREAMER) + RequestInstallMissingMediaPlugins(String details, String description) +#endif + + DidRestoreScrollPosition() + +#if PLATFORM(MAC) + DidHandleAcceptedCandidate() +#endif } diff --git a/Source/WebKit2/UIProcess/WebPasteboardProxy.cpp b/Source/WebKit2/UIProcess/WebPasteboardProxy.cpp new file mode 100644 index 000000000..9097cb52b --- /dev/null +++ b/Source/WebKit2/UIProcess/WebPasteboardProxy.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebPasteboardProxy.h" + +#include "WebPasteboardProxyMessages.h" +#include "WebProcessProxy.h" +#include <mutex> + +namespace WebKit { + +WebPasteboardProxy& WebPasteboardProxy::singleton() +{ + static std::once_flag onceFlag; + static LazyNeverDestroyed<WebPasteboardProxy> proxy; + + std::call_once(onceFlag, [] { + proxy.construct(); + }); + + return proxy; +} + +WebPasteboardProxy::WebPasteboardProxy() +{ +} + +void WebPasteboardProxy::addWebProcessProxy(WebProcessProxy& webProcessProxy) +{ + // FIXME: Can we handle all of these on a background queue? + webProcessProxy.addMessageReceiver(Messages::WebPasteboardProxy::messageReceiverName(), *this); +} + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebPasteboardProxy.h b/Source/WebKit2/UIProcess/WebPasteboardProxy.h new file mode 100644 index 000000000..494aac9f8 --- /dev/null +++ b/Source/WebKit2/UIProcess/WebPasteboardProxy.h @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebPasteboardProxy_h +#define WebPasteboardProxy_h + +#include "MessageReceiver.h" +#include "SharedMemory.h" +#include <wtf/Forward.h> +#include <wtf/NeverDestroyed.h> +#include <wtf/Vector.h> + +namespace WebCore { +class Color; +struct PasteboardImage; +struct PasteboardWebContent; +} + +namespace WebKit { + +class WebProcessProxy; + +class WebPasteboardProxy : public IPC::MessageReceiver { + WTF_MAKE_NONCOPYABLE(WebPasteboardProxy); + friend class LazyNeverDestroyed<WebPasteboardProxy>; +public: + static WebPasteboardProxy& singleton(); + + void addWebProcessProxy(WebProcessProxy&); + +private: + WebPasteboardProxy(); + + virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override; + virtual void didReceiveSyncMessage(IPC::Connection&, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override; + +#if PLATFORM(IOS) + void writeWebContentToPasteboard(const WebCore::PasteboardWebContent&); + void writeImageToPasteboard(const WebCore::PasteboardImage&); + void writeStringToPasteboard(const String& pasteboardType, const String&); + void readStringFromPasteboard(uint64_t index, const String& pasteboardType, WTF::String&); + void readURLFromPasteboard(uint64_t index, const String& pasteboardType, String&); + void readBufferFromPasteboard(uint64_t index, const String& pasteboardType, SharedMemory::Handle&, uint64_t& size); + void getPasteboardItemsCount(uint64_t& itemsCount); +#endif +#if PLATFORM(COCOA) + void getPasteboardTypes(const String& pasteboardName, Vector<String>& pasteboardTypes); + void getPasteboardPathnamesForType(const String& pasteboardName, const String& pasteboardType, Vector<String>& pathnames); + void getPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, String&); + void getPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, SharedMemory::Handle&, uint64_t& size); + void pasteboardCopy(const String& fromPasteboard, const String& toPasteboard, uint64_t& newChangeCount); + void getPasteboardChangeCount(const String& pasteboardName, uint64_t& changeCount); + void getPasteboardUniqueName(String& pasteboardName); + void getPasteboardColor(const String& pasteboardName, WebCore::Color&); + void getPasteboardURL(const String& pasteboardName, WTF::String&); + void addPasteboardTypes(const String& pasteboardName, const Vector<String>& pasteboardTypes, uint64_t& newChangeCount); + void setPasteboardTypes(const String& pasteboardName, const Vector<String>& pasteboardTypes, uint64_t& newChangeCount); + void setPasteboardPathnamesForType(const String& pasteboardName, const String& pasteboardType, const Vector<String>& pathnames, uint64_t& newChangeCount); + void setPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, const String&, uint64_t& newChangeCount); + void setPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, const SharedMemory::Handle&, uint64_t size, uint64_t& newChangeCount); +#endif +}; + +} // namespace WebKit + +#endif // WebPasteboardProxy_h diff --git a/Source/WebKit2/UIProcess/WebContext.messages.in b/Source/WebKit2/UIProcess/WebPasteboardProxy.messages.in index 056088c4e..d0d9fa12e 100644 --- a/Source/WebKit2/UIProcess/WebContext.messages.in +++ b/Source/WebKit2/UIProcess/WebPasteboardProxy.messages.in @@ -1,4 +1,4 @@ -# Copyright (C) 2010 Apple Inc. All rights reserved. +# Copyright (C) 2014 Apple Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -20,16 +20,10 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -messages -> WebContext LegacyReceiver { - - # Visited link provider messages. - AddVisitedLinkHash(uint64_t linkHash) - - DidGetStatistics(WebKit::StatisticsData statisticsData, uint64_t callbackID) - +messages -> WebPasteboardProxy { #if PLATFORM(IOS) - WriteWebContentToPasteboard(WebCore::PasteboardWebContent content) - WriteImageToPasteboard(WebCore::PasteboardImage pasteboardImage) + WriteWebContentToPasteboard(struct WebCore::PasteboardWebContent content) + WriteImageToPasteboard(struct WebCore::PasteboardImage pasteboardImage) WriteStringToPasteboard(String pasteboardType, String text) ReadStringFromPasteboard(uint64_t index, String pasteboardType) -> (String string) ReadURLFromPasteboard(uint64_t index, String pasteboardType) -> (String string) @@ -37,7 +31,7 @@ messages -> WebContext LegacyReceiver { GetPasteboardItemsCount() -> (uint64_t itemsCount) #endif -#if PLATFORM(MAC) +#if PLATFORM(COCOA) # Pasteboard messages. GetPasteboardTypes(String pasteboardName) -> (Vector<String> types) GetPasteboardPathnamesForType(String pasteboardName, String pasteboardType) -> (Vector<String> pathnames) @@ -54,14 +48,4 @@ messages -> WebContext LegacyReceiver { SetPasteboardStringForType(String pasteboardName, String pasteboardType, String string) -> (uint64_t changeCount) SetPasteboardBufferForType(String pasteboardName, String pasteboardType, WebKit::SharedMemory::Handle handle, uint64_t size) -> (uint64_t changeCount) #endif - -#if !PLATFORM(MAC) - // FIXME: This a dummy message, to avoid breaking the build for platforms that don't require - // any synchronous messages, and should be removed when <rdar://problem/8775115> is fixed. - Dummy() -> (bool dummyReturn) -#endif - - # Plug-in messages. - void AddPlugInAutoStartOriginHash(String pageOrigin, uint32_t hash) - void PlugInDidReceiveUserInteraction(uint32_t hash) } diff --git a/Source/WebKit2/UIProcess/WebPopupMenuProxy.h b/Source/WebKit2/UIProcess/WebPopupMenuProxy.h index 4c5c8e0c0..f934acc4b 100644 --- a/Source/WebKit2/UIProcess/WebPopupMenuProxy.h +++ b/Source/WebKit2/UIProcess/WebPopupMenuProxy.h @@ -26,7 +26,7 @@ #ifndef WebPopupMenuProxy_h #define WebPopupMenuProxy_h -#include <WebCore/TextDirection.h> +#include <WebCore/WritingMode.h> #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> #include <wtf/Vector.h> @@ -66,12 +66,13 @@ public: virtual void showPopupMenu(const WebCore::IntRect& rect, WebCore::TextDirection, double pageScaleFactor, const Vector<WebPopupItem>& items, const PlatformPopupMenuData&, int32_t selectedIndex) = 0; virtual void hidePopupMenu() = 0; #endif + virtual void cancelTracking() { } void invalidate() { m_client = 0; } protected: - explicit WebPopupMenuProxy(Client* client) - : m_client(client) + explicit WebPopupMenuProxy(Client& client) + : m_client(&client) { } diff --git a/Source/WebKit2/UIProcess/WebPreferences.cpp b/Source/WebKit2/UIProcess/WebPreferences.cpp index a4c4b796a..e1c390ec8 100644 --- a/Source/WebKit2/UIProcess/WebPreferences.cpp +++ b/Source/WebKit2/UIProcess/WebPreferences.cpp @@ -26,62 +26,89 @@ #include "config.h" #include "WebPreferences.h" -#include "WebContext.h" #include "WebPageGroup.h" +#include "WebPreferencesKeys.h" +#include "WebProcessPool.h" #include <wtf/ThreadingPrimitives.h> namespace WebKit { // FIXME: Manipulating this variable is not thread safe. // Instead of tracking private browsing state as a boolean preference, we should let the client provide storage sessions explicitly. -static unsigned privateBrowsingPageGroupCount; +static unsigned privateBrowsingPageCount; -WebPreferences::WebPreferences() +Ref<WebPreferences> WebPreferences::create(const String& identifier, const String& keyPrefix, const String& globalDebugKeyPrefix) { - platformInitializeStore(); + return adoptRef(*new WebPreferences(identifier, keyPrefix, globalDebugKeyPrefix)); +} + +PassRefPtr<WebPreferences> WebPreferences::createWithLegacyDefaults(const String& identifier, const String& keyPrefix, const String& globalDebugKeyPrefix) +{ + RefPtr<WebPreferences> preferences = adoptRef(new WebPreferences(identifier, keyPrefix, globalDebugKeyPrefix)); + // FIXME: The registerDefault...ValueForKey machinery is unnecessarily heavyweight and complicated. + // We can just compute different defaults for modern and legacy APIs in WebPreferencesDefinitions.h macros. + preferences->registerDefaultBoolValueForKey(WebPreferencesKey::javaEnabledKey(), true); + preferences->registerDefaultBoolValueForKey(WebPreferencesKey::javaEnabledForLocalFilesKey(), true); + preferences->registerDefaultBoolValueForKey(WebPreferencesKey::pluginsEnabledKey(), true); + preferences->registerDefaultUInt32ValueForKey(WebPreferencesKey::storageBlockingPolicyKey(), WebCore::SecurityOrigin::AllowAllStorage); + return preferences.release(); } -WebPreferences::WebPreferences(const String& identifier) +WebPreferences::WebPreferences(const String& identifier, const String& keyPrefix, const String& globalDebugKeyPrefix) : m_identifier(identifier) + , m_keyPrefix(keyPrefix) + , m_globalDebugKeyPrefix(globalDebugKeyPrefix) { platformInitializeStore(); } WebPreferences::WebPreferences(const WebPreferences& other) - : m_store(other.m_store) + : m_keyPrefix(other.m_keyPrefix) + , m_globalDebugKeyPrefix(other.m_globalDebugKeyPrefix) + , m_store(other.m_store) { platformInitializeStore(); } WebPreferences::~WebPreferences() { - ASSERT(m_pageGroups.isEmpty()); + ASSERT(m_pages.isEmpty()); } -void WebPreferences::addPageGroup(WebPageGroup* pageGroup) +PassRefPtr<WebPreferences> WebPreferences::copy() const { - bool didAddPageGroup = m_pageGroups.add(pageGroup).isNewEntry; - if (didAddPageGroup && privateBrowsingEnabled()) { - if (!privateBrowsingPageGroupCount) - WebContext::willStartUsingPrivateBrowsing(); - ++privateBrowsingPageGroupCount; + return adoptRef(new WebPreferences(*this)); +} + +void WebPreferences::addPage(WebPageProxy& webPageProxy) +{ + ASSERT(!m_pages.contains(&webPageProxy)); + m_pages.add(&webPageProxy); + + if (privateBrowsingEnabled()) { + if (!privateBrowsingPageCount) + WebProcessPool::willStartUsingPrivateBrowsing(); + + ++privateBrowsingPageCount; } } -void WebPreferences::removePageGroup(WebPageGroup* pageGroup) +void WebPreferences::removePage(WebPageProxy& webPageProxy) { - bool didRemovePageGroup = m_pageGroups.remove(pageGroup); - if (didRemovePageGroup && privateBrowsingEnabled()) { - --privateBrowsingPageGroupCount; - if (!privateBrowsingPageGroupCount) - WebContext::willStopUsingPrivateBrowsing(); + ASSERT(m_pages.contains(&webPageProxy)); + m_pages.remove(&webPageProxy); + + if (privateBrowsingEnabled()) { + --privateBrowsingPageCount; + if (!privateBrowsingPageCount) + WebProcessPool::willStopUsingPrivateBrowsing(); } } void WebPreferences::update() { - for (HashSet<WebPageGroup*>::iterator it = m_pageGroups.begin(), end = m_pageGroups.end(); it != end; ++it) - (*it)->preferencesDidChange(); + for (auto& webPageProxy : m_pages) + webPageProxy->preferencesDidChange(); } void WebPreferences::updateStringValueForKey(const String& key, const String& value) @@ -123,23 +150,23 @@ void WebPreferences::updatePrivateBrowsingValue(bool value) { platformUpdateBoolValueForKey(WebPreferencesKey::privateBrowsingEnabledKey(), value); - unsigned pageGroupsChanged = m_pageGroups.size(); - if (!pageGroupsChanged) + unsigned pagesChanged = m_pages.size(); + if (!pagesChanged) return; if (value) { - if (!privateBrowsingPageGroupCount) - WebContext::willStartUsingPrivateBrowsing(); - privateBrowsingPageGroupCount += pageGroupsChanged; + if (!privateBrowsingPageCount) + WebProcessPool::willStartUsingPrivateBrowsing(); + privateBrowsingPageCount += pagesChanged; } update(); // FIXME: Only send over the changed key and value. if (!value) { - ASSERT(privateBrowsingPageGroupCount >= pageGroupsChanged); - privateBrowsingPageGroupCount -= pageGroupsChanged; - if (!privateBrowsingPageGroupCount) - WebContext::willStopUsingPrivateBrowsing(); + ASSERT(privateBrowsingPageCount >= pagesChanged); + privateBrowsingPageCount -= pagesChanged; + if (!privateBrowsingPageCount) + WebProcessPool::willStopUsingPrivateBrowsing(); } } @@ -158,12 +185,29 @@ void WebPreferences::updatePrivateBrowsingValue(bool value) } \ FOR_EACH_WEBKIT_PREFERENCE(DEFINE_PREFERENCE_GETTER_AND_SETTERS) +FOR_EACH_WEBKIT_DEBUG_PREFERENCE(DEFINE_PREFERENCE_GETTER_AND_SETTERS) #undef DEFINE_PREFERENCE_GETTER_AND_SETTERS -bool WebPreferences::anyPageGroupsAreUsingPrivateBrowsing() +bool WebPreferences::anyPagesAreUsingPrivateBrowsing() +{ + return privateBrowsingPageCount; +} + +void WebPreferences::registerDefaultBoolValueForKey(const String& key, bool value) +{ + m_store.setOverrideDefaultsBoolValueForKey(key, value); + bool userValue; + if (platformGetBoolUserValueForKey(key, userValue)) + m_store.setBoolValueForKey(key, userValue); +} + +void WebPreferences::registerDefaultUInt32ValueForKey(const String& key, uint32_t value) { - return privateBrowsingPageGroupCount; + m_store.setOverrideDefaultsUInt32ValueForKey(key, value); + uint32_t userValue; + if (platformGetUInt32UserValueForKey(key, userValue)) + m_store.setUInt32ValueForKey(key, userValue); } } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebPreferences.h b/Source/WebKit2/UIProcess/WebPreferences.h index 725d6113d..018173878 100644 --- a/Source/WebKit2/UIProcess/WebPreferences.h +++ b/Source/WebKit2/UIProcess/WebPreferences.h @@ -28,6 +28,7 @@ #include "APIObject.h" #include "FontSmoothingLevel.h" +#include "WebPreferencesDefinitions.h" #include "WebPreferencesStore.h" #include <wtf/HashSet.h> #include <wtf/PassRefPtr.h> @@ -39,28 +40,22 @@ namespace WebKit { -class WebPageGroup; +class WebPageProxy; class WebPreferences : public API::ObjectImpl<API::Object::Type::Preferences> { public: - static PassRefPtr<WebPreferences> create() - { - return adoptRef(new WebPreferences); - } - static PassRefPtr<WebPreferences> create(const String& identifier) - { - return adoptRef(new WebPreferences(identifier)); - } - - static PassRefPtr<WebPreferences> create(const WebPreferences& other) - { - return adoptRef(new WebPreferences(other)); - } + static Ref<WebPreferences> create(const String& identifier, const String& keyPrefix, const String& globalDebugKeyPrefix); + static PassRefPtr<WebPreferences> createWithLegacyDefaults(const String& identifier, const String& keyPrefix, const String& globalDebugKeyPrefix); + + explicit WebPreferences(const String& identifier, const String& keyPrefix, const String& globalDebugKeyPrefix); + WebPreferences(const WebPreferences&); virtual ~WebPreferences(); - void addPageGroup(WebPageGroup*); - void removePageGroup(WebPageGroup*); + PassRefPtr<WebPreferences> copy() const; + + void addPage(WebPageProxy&); + void removePage(WebPageProxy&); const WebPreferencesStore& store() const { return m_store; } @@ -69,19 +64,16 @@ public: Type KeyLower() const; \ FOR_EACH_WEBKIT_PREFERENCE(DECLARE_PREFERENCE_GETTER_AND_SETTERS) + FOR_EACH_WEBKIT_DEBUG_PREFERENCE(DECLARE_PREFERENCE_GETTER_AND_SETTERS) #undef DECLARE_PREFERENCE_GETTER_AND_SETTERS // Exposed for WebKitTestRunner use only. void forceUpdate() { update(); } - static bool anyPageGroupsAreUsingPrivateBrowsing(); + static bool anyPagesAreUsingPrivateBrowsing(); private: - WebPreferences(); - explicit WebPreferences(const String&); - WebPreferences(const WebPreferences&); - void platformInitializeStore(); void update(); @@ -99,9 +91,20 @@ private: void updatePrivateBrowsingValue(bool value); - HashSet<WebPageGroup*> m_pageGroups; + void registerDefaultBoolValueForKey(const String&, bool); + void registerDefaultUInt32ValueForKey(const String&, uint32_t); + + bool platformGetStringUserValueForKey(const String& key, String& userValue); + bool platformGetBoolUserValueForKey(const String&, bool&); + bool platformGetUInt32UserValueForKey(const String&, uint32_t&); + bool platformGetDoubleUserValueForKey(const String&, double&); + + const String m_identifier; + const String m_keyPrefix; + const String m_globalDebugKeyPrefix; WebPreferencesStore m_store; - String m_identifier; + + HashSet<WebPageProxy*> m_pages; }; } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebProcessLifetimeObserver.cpp b/Source/WebKit2/UIProcess/WebProcessLifetimeObserver.cpp new file mode 100644 index 000000000..c36474f2b --- /dev/null +++ b/Source/WebKit2/UIProcess/WebProcessLifetimeObserver.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebProcessLifetimeObserver.h" + +#include "WebPageProxy.h" +#include "WebProcessProxy.h" + +namespace WebKit { + +WebProcessLifetimeObserver::WebProcessLifetimeObserver() +{ +} + +WebProcessLifetimeObserver::~WebProcessLifetimeObserver() +{ +} + +void WebProcessLifetimeObserver::addWebPage(WebPageProxy& webPageProxy) +{ + auto& process = webPageProxy.process(); + + ASSERT(process.state() == WebProcessProxy::State::Running); + + if (m_processes.add(&process).isNewEntry) + webProcessWillOpenConnection(process, *process.connection()); + + webPageWillOpenConnection(webPageProxy, *process.connection()); +} + +void WebProcessLifetimeObserver::removeWebPage(WebPageProxy& webPageProxy) +{ + auto& process = webPageProxy.process(); + + // FIXME: This should assert that the page is either closed or that the process is no longer running, + // but we have to make sure that removeWebPage is called after the connection has been removed in that case. + ASSERT(m_processes.contains(&process)); + + webPageDidCloseConnection(webPageProxy, *process.connection()); + + if (m_processes.remove(&process)) + webProcessDidCloseConnection(process, *process.connection()); +} + +WTF::IteratorRange<HashCountedSet<WebProcessProxy*>::const_iterator::Keys> WebProcessLifetimeObserver::processes() const +{ + ASSERT(std::all_of(m_processes.begin().keys(), m_processes.end().keys(), [](WebProcessProxy* process) { + return process->state() == WebProcessProxy::State::Running; + })); + + return makeIteratorRange(m_processes.begin().keys(), m_processes.end().keys()); +} + +} diff --git a/Source/WebKit2/UIProcess/WebProcessLifetimeObserver.h b/Source/WebKit2/UIProcess/WebProcessLifetimeObserver.h new file mode 100644 index 000000000..5c5bfeae3 --- /dev/null +++ b/Source/WebKit2/UIProcess/WebProcessLifetimeObserver.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebProcessLifetimeObserver_h +#define WebProcessLifetimeObserver_h + +#include <wtf/HashCountedSet.h> +#include <wtf/IteratorRange.h> + +namespace IPC { +class Connection; +} + +namespace WebKit { + +class WebPageProxy; +class WebProcessProxy; + +class WebProcessLifetimeObserver { +public: + WebProcessLifetimeObserver(); + virtual ~WebProcessLifetimeObserver(); + + void addWebPage(WebPageProxy&); + void removeWebPage(WebPageProxy&); + + WTF::IteratorRange<HashCountedSet<WebProcessProxy*>::const_iterator::Keys> processes() const; + +private: + friend class WebProcessLifetimeTracker; + + virtual void webPageWasAdded(WebPageProxy&) { } + virtual void webProcessWillOpenConnection(WebProcessProxy&, IPC::Connection&) { } + virtual void webPageWillOpenConnection(WebPageProxy&, IPC::Connection&) { } + virtual void webPageDidCloseConnection(WebPageProxy&, IPC::Connection&) { } + virtual void webProcessDidCloseConnection(WebProcessProxy&, IPC::Connection&) { } + virtual void webPageWasRemoved(WebPageProxy&) { } + + HashCountedSet<WebProcessProxy*> m_processes; +}; + +} + +#endif // WebProcessLifetimeObserver_h diff --git a/Source/WebKit2/UIProcess/WebNetworkInfoProvider.cpp b/Source/WebKit2/UIProcess/WebProcessLifetimeTracker.cpp index fffdf0d35..b080cc81c 100644 --- a/Source/WebKit2/UIProcess/WebNetworkInfoProvider.cpp +++ b/Source/WebKit2/UIProcess/WebProcessLifetimeTracker.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Intel Corporation. All rights reserved. + * Copyright (C) 2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -24,49 +24,65 @@ */ #include "config.h" -#include "WebNetworkInfoProvider.h" +#include "WebProcessLifetimeTracker.h" -#if ENABLE(NETWORK_INFO) - -#include "WKAPICast.h" -#include "WebNetworkInfoManagerProxy.h" -#include <limits.h> +#include "WebProcessLifetimeObserver.h" +#include "WebProcessProxy.h" namespace WebKit { -void WebNetworkInfoProvider::startUpdating(WebNetworkInfoManagerProxy* networkInfoManager) +WebProcessLifetimeTracker::WebProcessLifetimeTracker(WebPageProxy& webPageProxy) + : m_webPageProxy(webPageProxy) { - if (!m_client.startUpdating) - return; +} - m_client.startUpdating(toAPI(networkInfoManager), m_client.base.clientInfo); +WebProcessLifetimeTracker::~WebProcessLifetimeTracker() +{ } -void WebNetworkInfoProvider::stopUpdating(WebNetworkInfoManagerProxy* networkInfoManager) +void WebProcessLifetimeTracker::addObserver(WebProcessLifetimeObserver& observer) { - if (!m_client.stopUpdating) - return; + ASSERT(!m_observers.contains(&observer)); + + m_observers.add(&observer); + + observer.webPageWasAdded(m_webPageProxy); + + if (processIsRunning()) + observer.addWebPage(m_webPageProxy); +} + +void WebProcessLifetimeTracker::connectionWillOpen(IPC::Connection&) +{ + ASSERT(processIsRunning()); - m_client.stopUpdating(toAPI(networkInfoManager), m_client.base.clientInfo); + for (auto& observer : m_observers) + observer->addWebPage(m_webPageProxy); } -double WebNetworkInfoProvider::bandwidth(WebNetworkInfoManagerProxy* networkInfoManager) const +void WebProcessLifetimeTracker::webProcessWillShutDown() { - // The spec indicates that we should return "infinity" if the bandwidth is unknown. - if (!m_client.bandwidth) - return std::numeric_limits<double>::infinity(); + ASSERT(processIsRunning()); - return m_client.bandwidth(toAPI(networkInfoManager), m_client.base.clientInfo); + for (auto& observer : m_observers) + observer->removeWebPage(m_webPageProxy); } -bool WebNetworkInfoProvider::isMetered(WebNetworkInfoManagerProxy* networkInfoManager) const +void WebProcessLifetimeTracker::pageWasInvalidated() { - if (!m_client.isMetered) - return false; + if (!processIsRunning()) + return; - return m_client.isMetered(toAPI(networkInfoManager), m_client.base.clientInfo); + for (auto& observer : m_observers) { + observer->removeWebPage(m_webPageProxy); + + observer->webPageWasRemoved(m_webPageProxy); + } } -} // namespace WebKit +bool WebProcessLifetimeTracker::processIsRunning() +{ + return m_webPageProxy.process().state() == WebProcessProxy::State::Running; +} -#endif // ENABLE(NETWORK_INFO) +} diff --git a/Source/WebKit2/UIProcess/WebProcessLifetimeTracker.h b/Source/WebKit2/UIProcess/WebProcessLifetimeTracker.h new file mode 100644 index 000000000..7a73b7367 --- /dev/null +++ b/Source/WebKit2/UIProcess/WebProcessLifetimeTracker.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebProcessLifetimeTracker_h +#define WebProcessLifetimeTracker_h + +#include <wtf/HashSet.h> + +namespace IPC { +class Connection; +} + +namespace WebKit { + +class WebPageProxy; +class WebProcessLifetimeObserver; + +class WebProcessLifetimeTracker { +public: + explicit WebProcessLifetimeTracker(WebPageProxy&); + ~WebProcessLifetimeTracker(); + + void addObserver(WebProcessLifetimeObserver&); + + void connectionWillOpen(IPC::Connection&); + void webProcessWillShutDown(); + + void pageWasInvalidated(); + +private: + bool processIsRunning(); + + WebPageProxy& m_webPageProxy; + + HashSet<WebProcessLifetimeObserver*> m_observers; +}; + +} + +#endif // WebProcessLifetimeTracker_h diff --git a/Source/WebKit2/UIProcess/WebProcessPool.cpp b/Source/WebKit2/UIProcess/WebProcessPool.cpp new file mode 100644 index 000000000..ebfd03858 --- /dev/null +++ b/Source/WebKit2/UIProcess/WebProcessPool.cpp @@ -0,0 +1,1323 @@ +/* + * Copyright (C) 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebProcessPool.h" + +#include "APIArray.h" +#include "APIAutomationClient.h" +#include "APIDownloadClient.h" +#include "APILegacyContextHistoryClient.h" +#include "APIPageConfiguration.h" +#include "APIProcessPoolConfiguration.h" +#include "CustomProtocolManagerMessages.h" +#include "DownloadProxy.h" +#include "DownloadProxyMessages.h" +#include "Logging.h" +#include "NetworkProcessCreationParameters.h" +#include "NetworkProcessMessages.h" +#include "NetworkProcessProxy.h" +#include "SandboxExtension.h" +#include "StatisticsData.h" +#include "TextChecker.h" +#include "WKContextPrivate.h" +#include "WebAutomationSession.h" +#include "WebCertificateInfo.h" +#include "WebContextSupplement.h" +#include "WebCookieManagerProxy.h" +#include "WebCoreArgumentCoders.h" +#include "WebGeolocationManagerProxy.h" +#include "WebIconDatabase.h" +#include "WebKit2Initialize.h" +#include "WebMemorySampler.h" +#include "WebNotificationManagerProxy.h" +#include "WebPageGroup.h" +#include "WebPreferences.h" +#include "WebProcessCreationParameters.h" +#include "WebProcessMessages.h" +#include "WebProcessPoolMessages.h" +#include "WebProcessProxy.h" +#include "WebsiteDataStore.h" +#include <WebCore/ApplicationCacheStorage.h> +#include <WebCore/Language.h> +#include <WebCore/LinkHash.h> +#include <WebCore/Logging.h> +#include <WebCore/ResourceRequest.h> +#include <WebCore/SessionID.h> +#include <runtime/JSCInlines.h> +#include <wtf/CurrentTime.h> +#include <wtf/MainThread.h> +#include <wtf/NeverDestroyed.h> +#include <wtf/RunLoop.h> + +#if ENABLE(BATTERY_STATUS) +#include "WebBatteryManagerProxy.h" +#endif + +#if ENABLE(DATABASE_PROCESS) +#include "DatabaseProcessCreationParameters.h" +#include "DatabaseProcessMessages.h" +#endif + +#if ENABLE(SERVICE_CONTROLS) +#include "ServicesController.h" +#endif + +#if ENABLE(REMOTE_INSPECTOR) +#include <JavaScriptCore/RemoteInspector.h> +#endif + +#if USE(SOUP) +#include "WebSoupCustomProtocolRequestManager.h" +#endif + +#ifndef NDEBUG +#include <wtf/RefCountedLeakCounter.h> +#endif + +using namespace WebCore; +using namespace WebKit; + +namespace WebKit { + +DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, processPoolCounter, ("WebProcessPool")); + +Ref<WebProcessPool> WebProcessPool::create(API::ProcessPoolConfiguration& configuration) +{ + InitializeWebKit2(); + return adoptRef(*new WebProcessPool(configuration)); +} + +static Vector<WebProcessPool*>& processPools() +{ + static NeverDestroyed<Vector<WebProcessPool*>> processPools; + return processPools; +} + +const Vector<WebProcessPool*>& WebProcessPool::allProcessPools() +{ + return processPools(); +} + +static WebsiteDataStore::Configuration legacyWebsiteDataStoreConfiguration(API::ProcessPoolConfiguration& processPoolConfiguration) +{ + WebsiteDataStore::Configuration configuration; + + configuration.localStorageDirectory = processPoolConfiguration.localStorageDirectory(); + configuration.webSQLDatabaseDirectory = processPoolConfiguration.webSQLDatabaseDirectory(); + configuration.applicationCacheDirectory = WebProcessPool::legacyPlatformDefaultApplicationCacheDirectory(); + configuration.mediaKeysStorageDirectory = WebProcessPool::legacyPlatformDefaultMediaKeysStorageDirectory(); + configuration.networkCacheDirectory = WebProcessPool::legacyPlatformDefaultNetworkCacheDirectory(); + + return configuration; +} + +WebProcessPool::WebProcessPool(API::ProcessPoolConfiguration& configuration) + : m_configuration(configuration.copy()) + , m_haveInitialEmptyProcess(false) + , m_processWithPageCache(0) + , m_defaultPageGroup(WebPageGroup::createNonNull()) + , m_automationClient(std::make_unique<API::AutomationClient>()) + , m_downloadClient(std::make_unique<API::DownloadClient>()) + , m_historyClient(std::make_unique<API::LegacyContextHistoryClient>()) + , m_visitedLinkStore(VisitedLinkStore::create()) + , m_visitedLinksPopulated(false) + , m_plugInAutoStartProvider(this) + , m_alwaysUsesComplexTextCodePath(false) + , m_shouldUseFontSmoothing(true) + , m_memorySamplerEnabled(false) + , m_memorySamplerInterval(1400.0) + , m_websiteDataStore(m_configuration->shouldHaveLegacyDataStore() ? API::WebsiteDataStore::create(legacyWebsiteDataStoreConfiguration(m_configuration)).ptr() : nullptr) +#if USE(SOUP) + , m_initialHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicyOnlyFromMainDocumentDomain) +#endif + , m_shouldUseTestingNetworkSession(false) + , m_processTerminationEnabled(true) + , m_canHandleHTTPSServerTrustEvaluation(true) + , m_didNetworkProcessCrash(false) + , m_memoryCacheDisabled(false) + , m_userObservablePageCounter([this](bool) { updateProcessSuppressionState(); }) + , m_processSuppressionDisabledForPageCounter([this](bool) { updateProcessSuppressionState(); }) +{ + for (auto& scheme : m_configuration->alwaysRevalidatedURLSchemes()) + m_schemesToRegisterAsAlwaysRevalidated.add(scheme); + +#if ENABLE(CACHE_PARTITIONING) + for (const auto& urlScheme : m_configuration->cachePartitionedURLSchemes()) + m_schemesToRegisterAsCachePartitioned.add(urlScheme); +#endif + + platformInitialize(); + + addMessageReceiver(Messages::WebProcessPool::messageReceiverName(), *this); + + // NOTE: These sub-objects must be initialized after m_messageReceiverMap.. + m_iconDatabase = WebIconDatabase::create(this); + + addSupplement<WebCookieManagerProxy>(); + addSupplement<WebGeolocationManagerProxy>(); + addSupplement<WebNotificationManagerProxy>(); +#if USE(SOUP) + addSupplement<WebSoupCustomProtocolRequestManager>(); +#endif +#if ENABLE(BATTERY_STATUS) + addSupplement<WebBatteryManagerProxy>(); +#endif +#if ENABLE(MEDIA_SESSION) + addSupplement<WebMediaSessionFocusManager>(); +#endif + + processPools().append(this); + + addLanguageChangeObserver(this, languageChanged); + +#if !LOG_DISABLED + WebCore::initializeLoggingChannelsIfNecessary(); + WebKit::initializeLogChannelsIfNecessary(); +#endif // !LOG_DISABLED + +#if ENABLE(NETSCAPE_PLUGIN_API) + m_pluginInfoStore.setClient(this); +#endif + +#ifndef NDEBUG + processPoolCounter.increment(); +#endif +} + +#if !PLATFORM(COCOA) +void WebProcessPool::platformInitialize() +{ +} +#endif + +WebProcessPool::~WebProcessPool() +{ + bool removed = processPools().removeFirst(this); + ASSERT_UNUSED(removed, removed); + + removeLanguageChangeObserver(this); + + m_messageReceiverMap.invalidate(); + + WebContextSupplementMap::const_iterator it = m_supplements.begin(); + WebContextSupplementMap::const_iterator end = m_supplements.end(); + for (; it != end; ++it) { + it->value->processPoolDestroyed(); + it->value->clearProcessPool(); + } + + m_iconDatabase->invalidate(); + m_iconDatabase->clearProcessPool(); + WebIconDatabase* rawIconDatabase = m_iconDatabase.release().leakRef(); + rawIconDatabase->derefWhenAppropriate(); + + invalidateCallbackMap(m_dictionaryCallbacks, CallbackBase::Error::OwnerWasInvalidated); + + platformInvalidateContext(); + +#if ENABLE(NETSCAPE_PLUGIN_API) + m_pluginInfoStore.setClient(0); +#endif + +#ifndef NDEBUG + processPoolCounter.decrement(); +#endif + + if (m_networkProcess) + m_networkProcess->shutDownProcess(); +} + +void WebProcessPool::initializeClient(const WKContextClientBase* client) +{ + m_client.initialize(client); +} + +void WebProcessPool::initializeInjectedBundleClient(const WKContextInjectedBundleClientBase* client) +{ + m_injectedBundleClient.initialize(client); +} + +void WebProcessPool::initializeConnectionClient(const WKContextConnectionClientBase* client) +{ + m_connectionClient.initialize(client); +} + +void WebProcessPool::setHistoryClient(std::unique_ptr<API::LegacyContextHistoryClient> historyClient) +{ + if (!historyClient) + m_historyClient = std::make_unique<API::LegacyContextHistoryClient>(); + else + m_historyClient = WTFMove(historyClient); +} + +void WebProcessPool::setDownloadClient(std::unique_ptr<API::DownloadClient> downloadClient) +{ + if (!downloadClient) + m_downloadClient = std::make_unique<API::DownloadClient>(); + else + m_downloadClient = WTFMove(downloadClient); +} + +void WebProcessPool::setAutomationClient(std::unique_ptr<API::AutomationClient> automationClient) +{ + if (!automationClient) + m_automationClient = std::make_unique<API::AutomationClient>(); + else + m_automationClient = WTFMove(automationClient); +} + +void WebProcessPool::setMaximumNumberOfProcesses(unsigned maximumNumberOfProcesses) +{ + // Guard against API misuse. + if (!m_processes.isEmpty()) + CRASH(); + + m_configuration->setMaximumProcessCount(maximumNumberOfProcesses); +} + +IPC::Connection* WebProcessPool::networkingProcessConnection() +{ + return m_networkProcess->connection(); +} + +void WebProcessPool::languageChanged(void* context) +{ + static_cast<WebProcessPool*>(context)->languageChanged(); +} + +void WebProcessPool::languageChanged() +{ + sendToAllProcesses(Messages::WebProcess::UserPreferredLanguagesChanged(userPreferredLanguages())); +#if USE(SOUP) + if (m_networkProcess) + m_networkProcess->send(Messages::NetworkProcess::UserPreferredLanguagesChanged(userPreferredLanguages()), 0); +#endif +} + +void WebProcessPool::fullKeyboardAccessModeChanged(bool fullKeyboardAccessEnabled) +{ + sendToAllProcesses(Messages::WebProcess::FullKeyboardAccessModeChanged(fullKeyboardAccessEnabled)); +} + +void WebProcessPool::textCheckerStateChanged() +{ + sendToAllProcesses(Messages::WebProcess::SetTextCheckerState(TextChecker::state())); +} + +NetworkProcessProxy& WebProcessPool::ensureNetworkProcess() +{ + if (m_networkProcess) + return *m_networkProcess; + + m_networkProcess = NetworkProcessProxy::create(*this); + + NetworkProcessCreationParameters parameters; + + parameters.privateBrowsingEnabled = WebPreferences::anyPagesAreUsingPrivateBrowsing(); + + parameters.cacheModel = cacheModel(); + parameters.diskCacheSizeOverride = m_configuration->diskCacheSizeOverride(); + parameters.canHandleHTTPSServerTrustEvaluation = m_canHandleHTTPSServerTrustEvaluation; + + parameters.diskCacheDirectory = m_configuration->diskCacheDirectory(); + if (!parameters.diskCacheDirectory.isEmpty()) + SandboxExtension::createHandleForReadWriteDirectory(parameters.diskCacheDirectory, parameters.diskCacheDirectoryExtensionHandle); + +#if ENABLE(SECCOMP_FILTERS) + parameters.cookieStorageDirectory = this->cookieStorageDirectory(); +#endif + +#if PLATFORM(IOS) + String cookieStorageDirectory = this->cookieStorageDirectory(); + if (!cookieStorageDirectory.isEmpty()) + SandboxExtension::createHandleForReadWriteDirectory(cookieStorageDirectory, parameters.cookieStorageDirectoryExtensionHandle); + + String containerCachesDirectory = this->networkingCachesDirectory(); + if (!containerCachesDirectory.isEmpty()) + SandboxExtension::createHandleForReadWriteDirectory(containerCachesDirectory, parameters.containerCachesDirectoryExtensionHandle); + + String parentBundleDirectory = this->parentBundleDirectory(); + if (!parentBundleDirectory.isEmpty()) + SandboxExtension::createHandle(parentBundleDirectory, SandboxExtension::ReadOnly, parameters.parentBundleDirectoryExtensionHandle); +#endif + + parameters.shouldUseTestingNetworkSession = m_shouldUseTestingNetworkSession; + + // Add any platform specific parameters + platformInitializeNetworkProcess(parameters); + + // Initialize the network process. + m_networkProcess->send(Messages::NetworkProcess::InitializeNetworkProcess(parameters), 0); + +#if PLATFORM(COCOA) + m_networkProcess->send(Messages::NetworkProcess::SetQOS(networkProcessLatencyQOS(), networkProcessThroughputQOS()), 0); +#endif + + if (m_didNetworkProcessCrash) { + m_didNetworkProcessCrash = false; + for (auto& process : m_processes) + process->reinstateNetworkProcessAssertionState(*m_networkProcess); + } + + return *m_networkProcess; +} + +void WebProcessPool::networkProcessCrashed(NetworkProcessProxy* networkProcessProxy) +{ + ASSERT(m_networkProcess); + ASSERT(networkProcessProxy == m_networkProcess.get()); + m_didNetworkProcessCrash = true; + + WebContextSupplementMap::const_iterator it = m_supplements.begin(); + WebContextSupplementMap::const_iterator end = m_supplements.end(); + for (; it != end; ++it) + it->value->processDidClose(networkProcessProxy); + + m_client.networkProcessDidCrash(this); + + // Leave the process proxy around during client call, so that the client could query the process identifier. + m_networkProcess = nullptr; +} + +void WebProcessPool::getNetworkProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply> reply) +{ + ASSERT(reply); + + ensureNetworkProcess(); + ASSERT(m_networkProcess); + + m_networkProcess->getNetworkProcessConnection(reply); +} + +#if ENABLE(DATABASE_PROCESS) +void WebProcessPool::ensureDatabaseProcess() +{ + if (m_databaseProcess) + return; + + m_databaseProcess = DatabaseProcessProxy::create(this); + + // ********* + // IMPORTANT: Do not change the directory structure for indexed databases on disk without first consulting a reviewer from Apple (<rdar://problem/17454712>) + // ********* + DatabaseProcessCreationParameters parameters; +#if ENABLE(INDEXED_DATABASE) + ASSERT(!m_configuration->indexedDBDatabaseDirectory().isEmpty()); + parameters.indexedDatabaseDirectory = m_configuration->indexedDBDatabaseDirectory(); + + SandboxExtension::createHandleForReadWriteDirectory(parameters.indexedDatabaseDirectory, parameters.indexedDatabaseDirectoryExtensionHandle); +#endif + + m_databaseProcess->send(Messages::DatabaseProcess::InitializeDatabaseProcess(parameters), 0); +} + +void WebProcessPool::getDatabaseProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetDatabaseProcessConnection::DelayedReply> reply) +{ + ASSERT(reply); + + ensureDatabaseProcess(); + + m_databaseProcess->getDatabaseProcessConnection(reply); +} + +void WebProcessPool::databaseProcessCrashed(DatabaseProcessProxy* databaseProcessProxy) +{ + ASSERT(m_databaseProcess); + ASSERT(databaseProcessProxy == m_databaseProcess.get()); + + for (auto& supplement : m_supplements) + supplement.value->processDidClose(databaseProcessProxy); + + m_databaseProcess = nullptr; +} +#endif + +void WebProcessPool::willStartUsingPrivateBrowsing() +{ + for (auto* processPool : allProcessPools()) + processPool->setAnyPageGroupMightHavePrivateBrowsingEnabled(true); +} + +void WebProcessPool::willStopUsingPrivateBrowsing() +{ + for (auto* processPool : allProcessPools()) + processPool->setAnyPageGroupMightHavePrivateBrowsingEnabled(false); +} + +void WebProcessPool::windowServerConnectionStateChanged() +{ + size_t processCount = m_processes.size(); + for (size_t i = 0; i < processCount; ++i) + m_processes[i]->windowServerConnectionStateChanged(); +} + +void WebProcessPool::setAnyPageGroupMightHavePrivateBrowsingEnabled(bool privateBrowsingEnabled) +{ + m_iconDatabase->setPrivateBrowsingEnabled(privateBrowsingEnabled); + + if (networkProcess()) { + if (privateBrowsingEnabled) + networkProcess()->send(Messages::NetworkProcess::EnsurePrivateBrowsingSession(SessionID::legacyPrivateSessionID()), 0); + else + networkProcess()->send(Messages::NetworkProcess::DestroyPrivateBrowsingSession(SessionID::legacyPrivateSessionID()), 0); + } + + if (privateBrowsingEnabled) + sendToAllProcesses(Messages::WebProcess::EnsurePrivateBrowsingSession(SessionID::legacyPrivateSessionID())); + else + sendToAllProcesses(Messages::WebProcess::DestroyPrivateBrowsingSession(SessionID::legacyPrivateSessionID())); +} + +void (*s_invalidMessageCallback)(WKStringRef messageName); + +void WebProcessPool::setInvalidMessageCallback(void (*invalidMessageCallback)(WKStringRef messageName)) +{ + s_invalidMessageCallback = invalidMessageCallback; +} + +void WebProcessPool::didReceiveInvalidMessage(const IPC::StringReference& messageReceiverName, const IPC::StringReference& messageName) +{ + if (!s_invalidMessageCallback) + return; + + StringBuilder messageNameStringBuilder; + messageNameStringBuilder.append(messageReceiverName.data(), messageReceiverName.size()); + messageNameStringBuilder.append('.'); + messageNameStringBuilder.append(messageName.data(), messageName.size()); + + s_invalidMessageCallback(toAPI(API::String::create(messageNameStringBuilder.toString()).ptr())); +} + +void WebProcessPool::processDidCachePage(WebProcessProxy* process) +{ + if (m_processWithPageCache && m_processWithPageCache != process) + m_processWithPageCache->releasePageCache(); + m_processWithPageCache = process; +} + +WebProcessProxy& WebProcessPool::createNewWebProcess() +{ + ensureNetworkProcess(); + + Ref<WebProcessProxy> process = WebProcessProxy::create(*this); + + WebProcessCreationParameters parameters; + + parameters.injectedBundlePath = injectedBundlePath(); + if (!parameters.injectedBundlePath.isEmpty()) + SandboxExtension::createHandle(parameters.injectedBundlePath, SandboxExtension::ReadOnly, parameters.injectedBundlePathExtensionHandle); + + parameters.applicationCacheDirectory = m_configuration->applicationCacheDirectory(); + if (!parameters.applicationCacheDirectory.isEmpty()) + SandboxExtension::createHandleForReadWriteDirectory(parameters.applicationCacheDirectory, parameters.applicationCacheDirectoryExtensionHandle); + + parameters.webSQLDatabaseDirectory = m_configuration->webSQLDatabaseDirectory(); + if (!parameters.webSQLDatabaseDirectory.isEmpty()) + SandboxExtension::createHandleForReadWriteDirectory(parameters.webSQLDatabaseDirectory, parameters.webSQLDatabaseDirectoryExtensionHandle); + +#if ENABLE(SECCOMP_FILTERS) + parameters.cookieStorageDirectory = this->cookieStorageDirectory(); +#endif + +#if PLATFORM(IOS) + String cookieStorageDirectory = this->cookieStorageDirectory(); + if (!cookieStorageDirectory.isEmpty()) + SandboxExtension::createHandleForReadWriteDirectory(cookieStorageDirectory, parameters.cookieStorageDirectoryExtensionHandle); + + String containerCachesDirectory = this->webContentCachesDirectory(); + if (!containerCachesDirectory.isEmpty()) + SandboxExtension::createHandleForReadWriteDirectory(containerCachesDirectory, parameters.containerCachesDirectoryExtensionHandle); + + String containerTemporaryDirectory = this->containerTemporaryDirectory(); + if (!containerTemporaryDirectory.isEmpty()) + SandboxExtension::createHandleForReadWriteDirectory(containerTemporaryDirectory, parameters.containerTemporaryDirectoryExtensionHandle); +#endif + + parameters.mediaKeyStorageDirectory = m_configuration->mediaKeysStorageDirectory(); + if (!parameters.mediaKeyStorageDirectory.isEmpty()) + SandboxExtension::createHandleForReadWriteDirectory(parameters.mediaKeyStorageDirectory, parameters.mediaKeyStorageDirectoryExtensionHandle); + + parameters.shouldUseTestingNetworkSession = m_shouldUseTestingNetworkSession; + + parameters.cacheModel = cacheModel(); + parameters.languages = userPreferredLanguages(); + + copyToVector(m_schemesToRegisterAsEmptyDocument, parameters.urlSchemesRegisteredAsEmptyDocument); + copyToVector(m_schemesToRegisterAsSecure, parameters.urlSchemesRegisteredAsSecure); + copyToVector(m_schemesToRegisterAsBypassingContentSecurityPolicy, parameters.urlSchemesRegisteredAsBypassingContentSecurityPolicy); + copyToVector(m_schemesToSetDomainRelaxationForbiddenFor, parameters.urlSchemesForWhichDomainRelaxationIsForbidden); + copyToVector(m_schemesToRegisterAsLocal, parameters.urlSchemesRegisteredAsLocal); + copyToVector(m_schemesToRegisterAsNoAccess, parameters.urlSchemesRegisteredAsNoAccess); + copyToVector(m_schemesToRegisterAsDisplayIsolated, parameters.urlSchemesRegisteredAsDisplayIsolated); + copyToVector(m_schemesToRegisterAsCORSEnabled, parameters.urlSchemesRegisteredAsCORSEnabled); + copyToVector(m_schemesToRegisterAsAlwaysRevalidated, parameters.urlSchemesRegisteredAsAlwaysRevalidated); +#if ENABLE(CACHE_PARTITIONING) + copyToVector(m_schemesToRegisterAsCachePartitioned, parameters.urlSchemesRegisteredAsCachePartitioned); +#endif + + parameters.shouldAlwaysUseComplexTextCodePath = m_alwaysUsesComplexTextCodePath; + parameters.shouldUseFontSmoothing = m_shouldUseFontSmoothing; + + // FIXME: This leaves UI process and WebProcess disagreeing about the state if the client hasn't set the path. + // iconDatabasePath is non-empty by default, but m_iconDatabase isn't enabled in UI process unless setDatabasePath is called explicitly. + parameters.iconDatabaseEnabled = !iconDatabasePath().isEmpty(); + + parameters.terminationTimeout = 0; + + parameters.textCheckerState = TextChecker::state(); + + parameters.fullKeyboardAccessEnabled = WebProcessProxy::fullKeyboardAccessEnabled(); + + parameters.defaultRequestTimeoutInterval = API::URLRequest::defaultTimeoutInterval(); + +#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) + // FIXME: There should be a generic way for supplements to add to the intialization parameters. + supplement<WebNotificationManagerProxy>()->populateCopyOfNotificationPermissions(parameters.notificationPermissions); +#endif + + parameters.plugInAutoStartOriginHashes = m_plugInAutoStartProvider.autoStartOriginHashesCopy(); + copyToVector(m_plugInAutoStartProvider.autoStartOrigins(), parameters.plugInAutoStartOrigins); + + parameters.memoryCacheDisabled = m_memoryCacheDisabled; + +#if ENABLE(SERVICE_CONTROLS) + auto& serviceController = ServicesController::singleton(); + parameters.hasImageServices = serviceController.hasImageServices(); + parameters.hasSelectionServices = serviceController.hasSelectionServices(); + parameters.hasRichContentServices = serviceController.hasRichContentServices(); + serviceController.refreshExistingServices(); +#endif + +#if ENABLE(NETSCAPE_PLUGIN_API) + parameters.pluginLoadClientPolicies = m_pluginLoadClientPolicies; +#endif + +#if OS(LINUX) + parameters.shouldEnableMemoryPressureReliefLogging = true; +#endif + + // Add any platform specific parameters + platformInitializeWebProcess(parameters); + + RefPtr<API::Object> injectedBundleInitializationUserData = m_injectedBundleClient.getInjectedBundleInitializationUserData(this); + if (!injectedBundleInitializationUserData) + injectedBundleInitializationUserData = m_injectedBundleInitializationUserData; + parameters.initializationUserData = UserData(process->transformObjectsToHandles(injectedBundleInitializationUserData.get())); + + process->send(Messages::WebProcess::InitializeWebProcess(parameters), 0); + +#if PLATFORM(COCOA) + process->send(Messages::WebProcess::SetQOS(webProcessLatencyQOS(), webProcessThroughputQOS()), 0); +#endif +#if PLATFORM(IOS) + ApplicationCacheStorage::singleton().setDefaultOriginQuota(25ULL * 1024 * 1024); +#endif + + if (WebPreferences::anyPagesAreUsingPrivateBrowsing()) + process->send(Messages::WebProcess::EnsurePrivateBrowsingSession(SessionID::legacyPrivateSessionID()), 0); + + m_processes.append(process.ptr()); + + ASSERT(m_messagesToInjectedBundlePostedToEmptyContext.isEmpty()); + +#if ENABLE(REMOTE_INSPECTOR) + // Initialize remote inspector connection now that we have a sub-process that is hosting one of our web views. + Inspector::RemoteInspector::singleton(); +#endif + + return process; +} + +void WebProcessPool::warmInitialProcess() +{ + if (m_haveInitialEmptyProcess) { + ASSERT(!m_processes.isEmpty()); + return; + } + + if (m_processes.size() >= maximumNumberOfProcesses()) + return; + + createNewWebProcess(); + m_haveInitialEmptyProcess = true; +} + +void WebProcessPool::enableProcessTermination() +{ + m_processTerminationEnabled = true; + Vector<RefPtr<WebProcessProxy>> processes = m_processes; + for (size_t i = 0; i < processes.size(); ++i) { + if (shouldTerminate(processes[i].get())) + processes[i]->terminate(); + } +} + +bool WebProcessPool::shouldTerminate(WebProcessProxy* process) +{ + ASSERT(m_processes.contains(process)); + + if (!m_processTerminationEnabled) + return false; + + return true; +} + +void WebProcessPool::processDidFinishLaunching(WebProcessProxy* process) +{ + ASSERT(m_processes.contains(process)); + + if (!m_visitedLinksPopulated) { + populateVisitedLinks(); + m_visitedLinksPopulated = true; + } + + // Sometimes the memorySampler gets initialized after process initialization has happened but before the process has finished launching + // so check if it needs to be started here + if (m_memorySamplerEnabled) { + SandboxExtension::Handle sampleLogSandboxHandle; + double now = WTF::currentTime(); + String sampleLogFilePath = String::format("WebProcess%llupid%d", static_cast<unsigned long long>(now), process->processIdentifier()); + sampleLogFilePath = SandboxExtension::createHandleForTemporaryFile(sampleLogFilePath, SandboxExtension::ReadWrite, sampleLogSandboxHandle); + + process->send(Messages::WebProcess::StartMemorySampler(sampleLogSandboxHandle, sampleLogFilePath, m_memorySamplerInterval), 0); + } + + if (m_configuration->fullySynchronousModeIsAllowedForTesting()) + process->connection()->allowFullySynchronousModeForTesting(); + + m_connectionClient.didCreateConnection(this, process->webConnection()); +} + +void WebProcessPool::disconnectProcess(WebProcessProxy* process) +{ + ASSERT(m_processes.contains(process)); + + if (m_haveInitialEmptyProcess && process == m_processes.last()) + m_haveInitialEmptyProcess = false; + + // FIXME (Multi-WebProcess): <rdar://problem/12239765> Some of the invalidation calls of the other supplements are still necessary in multi-process mode, but they should only affect data structures pertaining to the process being disconnected. + // Clearing everything causes assertion failures, so it's less trouble to skip that for now. + RefPtr<WebProcessProxy> protect(process); + if (m_processWithPageCache == process) + m_processWithPageCache = nullptr; + + static_cast<WebContextSupplement*>(supplement<WebGeolocationManagerProxy>())->processDidClose(process); + + m_processes.removeFirst(process); +} + +WebProcessProxy& WebProcessPool::createNewWebProcessRespectingProcessCountLimit() +{ + if (m_processes.size() < maximumNumberOfProcesses()) + return createNewWebProcess(); + + // Choose the process with fewest pages. + auto& process = *std::min_element(m_processes.begin(), m_processes.end(), [](const RefPtr<WebProcessProxy>& a, const RefPtr<WebProcessProxy>& b) { + return a->pageCount() < b->pageCount(); + }); + + return *process; +} + +Ref<WebPageProxy> WebProcessPool::createWebPage(PageClient& pageClient, Ref<API::PageConfiguration>&& pageConfiguration) +{ + if (!pageConfiguration->pageGroup()) + pageConfiguration->setPageGroup(m_defaultPageGroup.ptr()); + if (!pageConfiguration->preferences()) + pageConfiguration->setPreferences(&pageConfiguration->pageGroup()->preferences()); + if (!pageConfiguration->visitedLinkStore()) + pageConfiguration->setVisitedLinkStore(m_visitedLinkStore.ptr()); + if (!pageConfiguration->websiteDataStore()) { + ASSERT(!pageConfiguration->sessionID().isValid()); + pageConfiguration->setWebsiteDataStore(m_websiteDataStore.get()); + pageConfiguration->setSessionID(pageConfiguration->preferences()->privateBrowsingEnabled() ? SessionID::legacyPrivateSessionID() : SessionID::defaultSessionID()); + } + + RefPtr<WebProcessProxy> process; + if (m_haveInitialEmptyProcess) { + process = m_processes.last(); + m_haveInitialEmptyProcess = false; + } else if (pageConfiguration->relatedPage()) { + // Sharing processes, e.g. when creating the page via window.open(). + process = &pageConfiguration->relatedPage()->process(); + } else + process = &createNewWebProcessRespectingProcessCountLimit(); + + return process->createWebPage(pageClient, WTFMove(pageConfiguration)); +} + +DownloadProxy* WebProcessPool::download(WebPageProxy* initiatingPage, const ResourceRequest& request) +{ + DownloadProxy* downloadProxy = createDownloadProxy(request); + SessionID sessionID = initiatingPage ? initiatingPage->sessionID() : SessionID::defaultSessionID(); + + if (networkProcess()) { + // FIXME (NetworkProcess): Replicate whatever FrameLoader::setOriginalURLForDownloadRequest does with the request here. + networkProcess()->send(Messages::NetworkProcess::DownloadRequest(sessionID, downloadProxy->downloadID(), request), 0); + return downloadProxy; + } + + return downloadProxy; +} + +DownloadProxy* WebProcessPool::resumeDownload(const API::Data* resumeData, const String& path) +{ + DownloadProxy* downloadProxy = createDownloadProxy(ResourceRequest()); + + SandboxExtension::Handle sandboxExtensionHandle; + if (!path.isEmpty()) + SandboxExtension::createHandle(path, SandboxExtension::ReadWrite, sandboxExtensionHandle); + + if (networkProcess()) { + // FIXME: If we started a download in an ephemeral session and that session still exists, we should find a way to use that same session. + networkProcess()->send(Messages::NetworkProcess::ResumeDownload(SessionID::defaultSessionID(), downloadProxy->downloadID(), resumeData->dataReference(), path, sandboxExtensionHandle), 0); + return downloadProxy; + } + + return downloadProxy; +} + +void WebProcessPool::postMessageToInjectedBundle(const String& messageName, API::Object* messageBody) +{ + for (auto& process : m_processes) { + // FIXME: Return early if the message body contains any references to WKPageRefs/WKFrameRefs etc. since they're local to a process. + process->send(Messages::WebProcess::HandleInjectedBundleMessage(messageName, UserData(process->transformObjectsToHandles(messageBody).get())), 0); + } +} + +void WebProcessPool::populateVisitedLinks() +{ + m_historyClient->populateVisitedLinks(*this); +} + +WebProcessPool::Statistics& WebProcessPool::statistics() +{ + static Statistics statistics = Statistics(); + + return statistics; +} + +#if ENABLE(NETSCAPE_PLUGIN_API) +void WebProcessPool::setAdditionalPluginsDirectory(const String& directory) +{ + Vector<String> directories; + directories.append(directory); + + m_pluginInfoStore.setAdditionalPluginsDirectories(directories); +} +#endif // ENABLE(NETSCAPE_PLUGIN_API) + +pid_t WebProcessPool::networkProcessIdentifier() +{ + if (!m_networkProcess) + return 0; + + return m_networkProcess->processIdentifier(); +} + +void WebProcessPool::setAlwaysUsesComplexTextCodePath(bool alwaysUseComplexText) +{ + m_alwaysUsesComplexTextCodePath = alwaysUseComplexText; + sendToAllProcesses(Messages::WebProcess::SetAlwaysUsesComplexTextCodePath(alwaysUseComplexText)); +} + +void WebProcessPool::setShouldUseFontSmoothing(bool useFontSmoothing) +{ + m_shouldUseFontSmoothing = useFontSmoothing; + sendToAllProcesses(Messages::WebProcess::SetShouldUseFontSmoothing(useFontSmoothing)); +} + +void WebProcessPool::registerURLSchemeAsEmptyDocument(const String& urlScheme) +{ + m_schemesToRegisterAsEmptyDocument.add(urlScheme); + sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsEmptyDocument(urlScheme)); +} + +void WebProcessPool::registerURLSchemeAsSecure(const String& urlScheme) +{ + m_schemesToRegisterAsSecure.add(urlScheme); + sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsSecure(urlScheme)); +} + +void WebProcessPool::registerURLSchemeAsBypassingContentSecurityPolicy(const String& urlScheme) +{ + m_schemesToRegisterAsBypassingContentSecurityPolicy.add(urlScheme); + sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsBypassingContentSecurityPolicy(urlScheme)); +} + +void WebProcessPool::setDomainRelaxationForbiddenForURLScheme(const String& urlScheme) +{ + m_schemesToSetDomainRelaxationForbiddenFor.add(urlScheme); + sendToAllProcesses(Messages::WebProcess::SetDomainRelaxationForbiddenForURLScheme(urlScheme)); +} + +void WebProcessPool::setCanHandleHTTPSServerTrustEvaluation(bool value) +{ + m_canHandleHTTPSServerTrustEvaluation = value; + if (m_networkProcess) { + m_networkProcess->send(Messages::NetworkProcess::SetCanHandleHTTPSServerTrustEvaluation(value), 0); + return; + } +} + +void WebProcessPool::registerURLSchemeAsLocal(const String& urlScheme) +{ + m_schemesToRegisterAsLocal.add(urlScheme); + sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsLocal(urlScheme)); +} + +void WebProcessPool::registerURLSchemeAsNoAccess(const String& urlScheme) +{ + m_schemesToRegisterAsNoAccess.add(urlScheme); + sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsNoAccess(urlScheme)); +} + +void WebProcessPool::registerURLSchemeAsDisplayIsolated(const String& urlScheme) +{ + m_schemesToRegisterAsDisplayIsolated.add(urlScheme); + sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsDisplayIsolated(urlScheme)); +} + +void WebProcessPool::registerURLSchemeAsCORSEnabled(const String& urlScheme) +{ + m_schemesToRegisterAsCORSEnabled.add(urlScheme); + sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsCORSEnabled(urlScheme)); +} + +HashSet<String, ASCIICaseInsensitiveHash>& WebProcessPool::globalURLSchemesWithCustomProtocolHandlers() +{ + static NeverDestroyed<HashSet<String, ASCIICaseInsensitiveHash>> set; + return set; +} + +void WebProcessPool::registerGlobalURLSchemeAsHavingCustomProtocolHandlers(const String& urlScheme) +{ + if (!urlScheme) + return; + + globalURLSchemesWithCustomProtocolHandlers().add(urlScheme); + for (auto* processPool : allProcessPools()) + processPool->registerSchemeForCustomProtocol(urlScheme); +} + +void WebProcessPool::unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers(const String& urlScheme) +{ + if (!urlScheme) + return; + + globalURLSchemesWithCustomProtocolHandlers().remove(urlScheme); + for (auto* processPool : allProcessPools()) + processPool->unregisterSchemeForCustomProtocol(urlScheme); +} + +#if ENABLE(CACHE_PARTITIONING) +void WebProcessPool::registerURLSchemeAsCachePartitioned(const String& urlScheme) +{ + m_schemesToRegisterAsCachePartitioned.add(urlScheme); + sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsCachePartitioned(urlScheme)); +} +#endif + +void WebProcessPool::setCacheModel(CacheModel cacheModel) +{ + m_configuration->setCacheModel(cacheModel); + sendToAllProcesses(Messages::WebProcess::SetCacheModel(cacheModel)); + + if (m_networkProcess) + m_networkProcess->send(Messages::NetworkProcess::SetCacheModel(cacheModel), 0); +} + +void WebProcessPool::setDefaultRequestTimeoutInterval(double timeoutInterval) +{ + sendToAllProcesses(Messages::WebProcess::SetDefaultRequestTimeoutInterval(timeoutInterval)); +} + +DownloadProxy* WebProcessPool::createDownloadProxy(const ResourceRequest& request) +{ + return ensureNetworkProcess().createDownloadProxy(request); +} + +void WebProcessPool::addMessageReceiver(IPC::StringReference messageReceiverName, IPC::MessageReceiver& messageReceiver) +{ + m_messageReceiverMap.addMessageReceiver(messageReceiverName, messageReceiver); +} + +void WebProcessPool::addMessageReceiver(IPC::StringReference messageReceiverName, uint64_t destinationID, IPC::MessageReceiver& messageReceiver) +{ + m_messageReceiverMap.addMessageReceiver(messageReceiverName, destinationID, messageReceiver); +} + +void WebProcessPool::removeMessageReceiver(IPC::StringReference messageReceiverName, uint64_t destinationID) +{ + m_messageReceiverMap.removeMessageReceiver(messageReceiverName, destinationID); +} + +bool WebProcessPool::dispatchMessage(IPC::Connection& connection, IPC::MessageDecoder& decoder) +{ + return m_messageReceiverMap.dispatchMessage(connection, decoder); +} + +bool WebProcessPool::dispatchSyncMessage(IPC::Connection& connection, IPC::MessageDecoder& decoder, std::unique_ptr<IPC::MessageEncoder>& replyEncoder) +{ + return m_messageReceiverMap.dispatchSyncMessage(connection, decoder, replyEncoder); +} + +void WebProcessPool::setEnhancedAccessibility(bool flag) +{ + sendToAllProcesses(Messages::WebProcess::SetEnhancedAccessibility(flag)); +} + +void WebProcessPool::startMemorySampler(const double interval) +{ + // For new WebProcesses we will also want to start the Memory Sampler + m_memorySamplerEnabled = true; + m_memorySamplerInterval = interval; + + // For UIProcess +#if ENABLE(MEMORY_SAMPLER) + WebMemorySampler::singleton()->start(interval); +#endif + + // For WebProcess + SandboxExtension::Handle sampleLogSandboxHandle; + double now = WTF::currentTime(); + String sampleLogFilePath = String::format("WebProcess%llu", static_cast<unsigned long long>(now)); + sampleLogFilePath = SandboxExtension::createHandleForTemporaryFile(sampleLogFilePath, SandboxExtension::ReadWrite, sampleLogSandboxHandle); + + sendToAllProcesses(Messages::WebProcess::StartMemorySampler(sampleLogSandboxHandle, sampleLogFilePath, interval)); +} + +void WebProcessPool::stopMemorySampler() +{ + // For WebProcess + m_memorySamplerEnabled = false; + + // For UIProcess +#if ENABLE(MEMORY_SAMPLER) + WebMemorySampler::singleton()->stop(); +#endif + + sendToAllProcesses(Messages::WebProcess::StopMemorySampler()); +} + +void WebProcessPool::setIconDatabasePath(const String& path) +{ + m_overrideIconDatabasePath = path; + if (!m_overrideIconDatabasePath.isEmpty()) { + // This implicitly enables the database on UI process side. + m_iconDatabase->setDatabasePath(path); + } +} + +String WebProcessPool::iconDatabasePath() const +{ + if (!m_overrideIconDatabasePath.isNull()) + return m_overrideIconDatabasePath; + + return platformDefaultIconDatabasePath(); +} + +#if ENABLE(SECCOMP_FILTERS) +String WebProcessPool::cookieStorageDirectory() const +{ + if (!m_overrideCookieStorageDirectory.isEmpty()) + return m_overrideCookieStorageDirectory; + + // FIXME: This doesn't make much sense. Is this function used at all? We used to call platform code, but no existing platforms implemented that function. + return emptyString(); +} +#endif + +void WebProcessPool::useTestingNetworkSession() +{ + ASSERT(m_processes.isEmpty()); + ASSERT(!m_networkProcess); + + if (m_networkProcess) + return; + + if (!m_processes.isEmpty()) + return; + + m_shouldUseTestingNetworkSession = true; +} + +void WebProcessPool::clearCachedCredentials() +{ + sendToAllProcesses(Messages::WebProcess::ClearCachedCredentials()); + if (m_networkProcess) + m_networkProcess->send(Messages::NetworkProcess::ClearCachedCredentials(), 0); +} + +void WebProcessPool::terminateDatabaseProcess() +{ +#if ENABLE(DATABASE_PROCESS) + ASSERT(m_processes.isEmpty()); + if (!m_databaseProcess) + return; + + m_databaseProcess->terminate(); + m_databaseProcess = nullptr; +#endif +} + +void WebProcessPool::allowSpecificHTTPSCertificateForHost(const WebCertificateInfo* certificate, const String& host) +{ + if (m_networkProcess) + m_networkProcess->send(Messages::NetworkProcess::AllowSpecificHTTPSCertificateForHost(certificate->certificateInfo(), host), 0); +} + +void WebProcessPool::updateAutomationCapabilities() const +{ +#if ENABLE(REMOTE_INSPECTOR) + Inspector::RemoteInspector::singleton().clientCapabilitiesDidChange(); +#endif +} + +void WebProcessPool::setAutomationSession(RefPtr<WebAutomationSession>&& automationSession) +{ + m_automationSession = WTFMove(automationSession); + +#if ENABLE(REMOTE_INSPECTOR) + if (m_automationSession) + m_automationSession->init(); +#endif +} + +void WebProcessPool::setHTTPPipeliningEnabled(bool enabled) +{ +#if PLATFORM(COCOA) + ResourceRequest::setHTTPPipeliningEnabled(enabled); +#else + UNUSED_PARAM(enabled); +#endif +} + +bool WebProcessPool::httpPipeliningEnabled() const +{ +#if PLATFORM(COCOA) + return ResourceRequest::httpPipeliningEnabled(); +#else + return false; +#endif +} + +void WebProcessPool::getStatistics(uint32_t statisticsMask, std::function<void (API::Dictionary*, CallbackBase::Error)> callbackFunction) +{ + if (!statisticsMask) { + callbackFunction(nullptr, CallbackBase::Error::Unknown); + return; + } + + RefPtr<StatisticsRequest> request = StatisticsRequest::create(DictionaryCallback::create(WTFMove(callbackFunction))); + + if (statisticsMask & StatisticsRequestTypeWebContent) + requestWebContentStatistics(request.get()); + + if (statisticsMask & StatisticsRequestTypeNetworking) + requestNetworkingStatistics(request.get()); +} + +void WebProcessPool::requestWebContentStatistics(StatisticsRequest* request) +{ + // FIXME (Multi-WebProcess) <rdar://problem/13200059>: Make getting statistics from multiple WebProcesses work. +} + +void WebProcessPool::requestNetworkingStatistics(StatisticsRequest* request) +{ + if (!m_networkProcess) { + LOG_ERROR("Attempt to get NetworkProcess statistics but the NetworkProcess is unavailable"); + return; + } + + uint64_t requestID = request->addOutstandingRequest(); + m_statisticsRequests.set(requestID, request); + m_networkProcess->send(Messages::NetworkProcess::GetNetworkProcessStatistics(requestID), 0); +} + +void WebProcessPool::handleMessage(IPC::Connection& connection, const String& messageName, const WebKit::UserData& messageBody) +{ + auto* webProcessProxy = WebProcessProxy::fromConnection(&connection); + if (!webProcessProxy) + return; + m_injectedBundleClient.didReceiveMessageFromInjectedBundle(this, messageName, webProcessProxy->transformHandlesToObjects(messageBody.object()).get()); +} + +void WebProcessPool::handleSynchronousMessage(IPC::Connection& connection, const String& messageName, const UserData& messageBody, UserData& returnUserData) +{ + auto* webProcessProxy = WebProcessProxy::fromConnection(&connection); + if (!webProcessProxy) + return; + + RefPtr<API::Object> returnData; + m_injectedBundleClient.didReceiveSynchronousMessageFromInjectedBundle(this, messageName, webProcessProxy->transformHandlesToObjects(messageBody.object()).get(), returnData); + returnUserData = UserData(webProcessProxy->transformObjectsToHandles(returnData.get())); +} + +void WebProcessPool::didGetStatistics(const StatisticsData& statisticsData, uint64_t requestID) +{ + RefPtr<StatisticsRequest> request = m_statisticsRequests.take(requestID); + if (!request) { + LOG_ERROR("Cannot report networking statistics."); + return; + } + + request->completedRequest(requestID, statisticsData); +} + +void WebProcessPool::garbageCollectJavaScriptObjects() +{ + sendToAllProcesses(Messages::WebProcess::GarbageCollectJavaScriptObjects()); +} + +void WebProcessPool::setJavaScriptGarbageCollectorTimerEnabled(bool flag) +{ + sendToAllProcesses(Messages::WebProcess::SetJavaScriptGarbageCollectorTimerEnabled(flag)); +} + +void WebProcessPool::addPlugInAutoStartOriginHash(const String& pageOrigin, unsigned plugInOriginHash, SessionID sessionID) +{ + m_plugInAutoStartProvider.addAutoStartOriginHash(pageOrigin, plugInOriginHash, sessionID); +} + +void WebProcessPool::plugInDidReceiveUserInteraction(unsigned plugInOriginHash, SessionID sessionID) +{ + m_plugInAutoStartProvider.didReceiveUserInteraction(plugInOriginHash, sessionID); +} + +PassRefPtr<API::Dictionary> WebProcessPool::plugInAutoStartOriginHashes() const +{ + return m_plugInAutoStartProvider.autoStartOriginsTableCopy(); +} + +void WebProcessPool::setPlugInAutoStartOriginHashes(API::Dictionary& dictionary) +{ + m_plugInAutoStartProvider.setAutoStartOriginsTable(dictionary); +} + +void WebProcessPool::setPlugInAutoStartOrigins(API::Array& array) +{ + m_plugInAutoStartProvider.setAutoStartOriginsArray(array); +} + +void WebProcessPool::setPlugInAutoStartOriginsFilteringOutEntriesAddedAfterTime(API::Dictionary& dictionary, double time) +{ + m_plugInAutoStartProvider.setAutoStartOriginsFilteringOutEntriesAddedAfterTime(dictionary, time); +} + +void WebProcessPool::registerSchemeForCustomProtocol(const String& scheme) +{ + sendToNetworkingProcess(Messages::CustomProtocolManager::RegisterScheme(scheme)); +} + +void WebProcessPool::unregisterSchemeForCustomProtocol(const String& scheme) +{ + sendToNetworkingProcess(Messages::CustomProtocolManager::UnregisterScheme(scheme)); +} + +#if ENABLE(NETSCAPE_PLUGIN_API) +void WebProcessPool::pluginInfoStoreDidLoadPlugins(PluginInfoStore* store) +{ +#ifdef NDEBUG + UNUSED_PARAM(store); +#endif + ASSERT(store == &m_pluginInfoStore); + + Vector<PluginModuleInfo> pluginModules = m_pluginInfoStore.plugins(); + + Vector<RefPtr<API::Object>> plugins; + plugins.reserveInitialCapacity(pluginModules.size()); + + for (const auto& pluginModule : pluginModules) { + API::Dictionary::MapType map; + map.set(ASCIILiteral("path"), API::String::create(pluginModule.path)); + map.set(ASCIILiteral("name"), API::String::create(pluginModule.info.name)); + map.set(ASCIILiteral("file"), API::String::create(pluginModule.info.file)); + map.set(ASCIILiteral("desc"), API::String::create(pluginModule.info.desc)); + + Vector<RefPtr<API::Object>> mimeTypes; + mimeTypes.reserveInitialCapacity(pluginModule.info.mimes.size()); + for (const auto& mimeClassInfo : pluginModule.info.mimes) + mimeTypes.uncheckedAppend(API::String::create(mimeClassInfo.type)); + map.set(ASCIILiteral("mimes"), API::Array::create(WTFMove(mimeTypes))); + +#if PLATFORM(COCOA) + map.set(ASCIILiteral("bundleId"), API::String::create(pluginModule.bundleIdentifier)); + map.set(ASCIILiteral("version"), API::String::create(pluginModule.versionString)); +#endif + + plugins.uncheckedAppend(API::Dictionary::create(WTFMove(map))); + } + + m_client.plugInInformationBecameAvailable(this, API::Array::create(WTFMove(plugins)).ptr()); +} + +void WebProcessPool::setPluginLoadClientPolicy(WebCore::PluginLoadClientPolicy policy, const String& host, const String& bundleIdentifier, const String& versionString) +{ +#if ENABLE(NETSCAPE_PLUGIN_API) + HashMap<String, HashMap<String, uint8_t>> policiesByIdentifier; + if (m_pluginLoadClientPolicies.contains(host)) + policiesByIdentifier = m_pluginLoadClientPolicies.get(host); + + HashMap<String, uint8_t> versionsToPolicies; + if (policiesByIdentifier.contains(bundleIdentifier)) + versionsToPolicies = policiesByIdentifier.get(bundleIdentifier); + + versionsToPolicies.set(versionString, policy); + policiesByIdentifier.set(bundleIdentifier, versionsToPolicies); + m_pluginLoadClientPolicies.set(host, policiesByIdentifier); +#endif + + sendToAllProcesses(Messages::WebProcess::SetPluginLoadClientPolicy(policy, host, bundleIdentifier, versionString)); +} + +void WebProcessPool::clearPluginClientPolicies() +{ +#if ENABLE(NETSCAPE_PLUGIN_API) + m_pluginLoadClientPolicies.clear(); +#endif + sendToAllProcesses(Messages::WebProcess::ClearPluginClientPolicies()); +} +#endif + +void WebProcessPool::setMemoryCacheDisabled(bool disabled) +{ + m_memoryCacheDisabled = disabled; + sendToAllProcesses(Messages::WebProcess::SetMemoryCacheDisabled(disabled)); +} + +void WebProcessPool::setFontWhitelist(API::Array* array) +{ + m_fontWhitelist.clear(); + if (array) { + for (size_t i = 0; i < array->size(); ++i) { + if (API::String* font = array->at<API::String>(i)) + m_fontWhitelist.append(font->string()); + } + } +} + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebContext.h b/Source/WebKit2/UIProcess/WebProcessPool.h index 14bb90ab3..f3ea40a2d 100644 --- a/Source/WebKit2/UIProcess/WebContext.h +++ b/Source/WebKit2/UIProcess/WebProcessPool.h @@ -23,32 +23,34 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef WebContext_h -#define WebContext_h +#ifndef WebProcessPool_h +#define WebProcessPool_h +#include "APIDictionary.h" #include "APIObject.h" +#include "APIProcessPoolConfiguration.h" +#include "APIWebsiteDataStore.h" #include "DownloadProxyMap.h" #include "GenericCallback.h" -#include "ImmutableDictionary.h" #include "MessageReceiver.h" #include "MessageReceiverMap.h" +#include "NetworkProcessProxy.h" #include "PlugInAutoStartProvider.h" #include "PluginInfoStore.h" -#include "ProcessModel.h" +#include "ProcessThrottler.h" #include "StatisticsRequest.h" -#include "StorageManager.h" -#include "VisitedLinkProvider.h" +#include "VisitedLinkStore.h" #include "WebContextClient.h" #include "WebContextConnectionClient.h" #include "WebContextInjectedBundleClient.h" -#include "WebDownloadClient.h" -#include "WebHistoryClient.h" #include "WebProcessProxy.h" #include <WebCore/LinkHash.h> +#include <WebCore/SessionID.h> #include <wtf/Forward.h> #include <wtf/HashMap.h> #include <wtf/HashSet.h> #include <wtf/PassRefPtr.h> +#include <wtf/RefCounter.h> #include <wtf/RefPtr.h> #include <wtf/text/StringHash.h> #include <wtf/text/WTFString.h> @@ -57,54 +59,58 @@ #include "DatabaseProcessProxy.h" #endif -#if ENABLE(NETWORK_PROCESS) -#include "NetworkProcessProxy.h" +#if ENABLE(MEDIA_SESSION) +#include "WebMediaSessionFocusManager.h" #endif -#if PLATFORM(MAC) +#if PLATFORM(COCOA) +OBJC_CLASS NSMutableDictionary; OBJC_CLASS NSObject; OBJC_CLASS NSString; #endif +namespace API { +class AutomationClient; +class DownloadClient; +class LegacyContextHistoryClient; +class PageConfiguration; +} + namespace WebKit { class DownloadProxy; +class WebAutomationSession; class WebContextSupplement; class WebIconDatabase; class WebPageGroup; class WebPageProxy; +struct NetworkProcessCreationParameters; struct StatisticsData; -struct WebPageConfiguration; struct WebProcessCreationParameters; -typedef GenericCallback<WKDictionaryRef> DictionaryCallback; +typedef GenericCallback<API::Dictionary*> DictionaryCallback; -#if ENABLE(NETWORK_INFO) -class WebNetworkInfoManagerProxy; -#endif -#if ENABLE(NETWORK_PROCESS) -struct NetworkProcessCreationParameters; -#endif - -#if PLATFORM(MAC) +#if PLATFORM(COCOA) int networkProcessLatencyQOS(); int networkProcessThroughputQOS(); int webProcessLatencyQOS(); int webProcessThroughputQOS(); #endif -class WebContext : public API::ObjectImpl<API::Object::Type::Context>, private IPC::MessageReceiver +class WebProcessPool final : public API::ObjectImpl<API::Object::Type::ProcessPool>, private IPC::MessageReceiver #if ENABLE(NETSCAPE_PLUGIN_API) , private PluginInfoStoreClient #endif { public: - WebContext(const String& injectedBundlePath); + static Ref<WebProcessPool> create(API::ProcessPoolConfiguration&); + + explicit WebProcessPool(API::ProcessPoolConfiguration&); + virtual ~WebProcessPool(); - static PassRefPtr<WebContext> create(const String& injectedBundlePath); - virtual ~WebContext(); + API::ProcessPoolConfiguration& configuration() { return m_configuration.get(); } - static const Vector<WebContext*>& allContexts(); + static const Vector<WebProcessPool*>& allProcessPools(); template <typename T> T* supplement() @@ -122,20 +128,20 @@ public: void addMessageReceiver(IPC::StringReference messageReceiverName, uint64_t destinationID, IPC::MessageReceiver&); void removeMessageReceiver(IPC::StringReference messageReceiverName, uint64_t destinationID); - bool dispatchMessage(IPC::Connection*, IPC::MessageDecoder&); - bool dispatchSyncMessage(IPC::Connection*, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&); + bool dispatchMessage(IPC::Connection&, IPC::MessageDecoder&); + bool dispatchSyncMessage(IPC::Connection&, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&); void initializeClient(const WKContextClientBase*); void initializeInjectedBundleClient(const WKContextInjectedBundleClientBase*); void initializeConnectionClient(const WKContextConnectionClientBase*); - void initializeHistoryClient(const WKContextHistoryClientBase*); - void initializeDownloadClient(const WKContextDownloadClientBase*); - - void setProcessModel(ProcessModel); // Can only be called when there are no processes running. - ProcessModel processModel() const { return m_processModel; } + void setHistoryClient(std::unique_ptr<API::LegacyContextHistoryClient>); + void setDownloadClient(std::unique_ptr<API::DownloadClient>); + void setAutomationClient(std::unique_ptr<API::AutomationClient>); void setMaximumNumberOfProcesses(unsigned); // Can only be called when there are no processes running. - unsigned maximumNumberOfProcesses() const { return m_webProcessCountLimit; } + unsigned maximumNumberOfProcesses() const { return !m_configuration->maximumProcessCount() ? UINT_MAX : m_configuration->maximumProcessCount(); } + + const Vector<RefPtr<WebProcessProxy>>& processes() const { return m_processes; } // WebProcess or NetworkProcess as approporiate for current process model. The connection must be non-null. IPC::Connection* networkingProcessConnection(); @@ -148,57 +154,60 @@ public: template<typename T> void sendToNetworkingProcess(T&& message); template<typename T> void sendToNetworkingProcessRelaunchingIfNecessary(T&& message); - void processWillOpenConnection(WebProcessProxy*); - void processWillCloseConnection(WebProcessProxy*); + // Sends the message to WebProcess or DatabaseProcess as approporiate for current process model. + template<typename T> void sendToDatabaseProcessRelaunchingIfNecessary(T&& message); + void processDidFinishLaunching(WebProcessProxy*); // Disconnect the process from the context. void disconnectProcess(WebProcessProxy*); - StorageManager& storageManager() const { return *m_storageManager; } + API::WebsiteDataStore* websiteDataStore() const { return m_websiteDataStore.get(); } - PassRefPtr<WebPageProxy> createWebPage(PageClient&, WebPageConfiguration); + Ref<WebPageProxy> createWebPage(PageClient&, Ref<API::PageConfiguration>&&); - const String& injectedBundlePath() const { return m_injectedBundlePath; } + const String& injectedBundlePath() const { return m_configuration->injectedBundlePath(); } DownloadProxy* download(WebPageProxy* initiatingPage, const WebCore::ResourceRequest&); + DownloadProxy* resumeDownload(const API::Data* resumeData, const String& path); void setInjectedBundleInitializationUserData(PassRefPtr<API::Object> userData) { m_injectedBundleInitializationUserData = userData; } void postMessageToInjectedBundle(const String&, API::Object*); - // InjectedBundle client - void didReceiveMessageFromInjectedBundle(const String&, API::Object*); - void didReceiveSynchronousMessageFromInjectedBundle(const String&, API::Object*, RefPtr<API::Object>& returnData); - void populateVisitedLinks(); #if ENABLE(NETSCAPE_PLUGIN_API) void setAdditionalPluginsDirectory(const String&); PluginInfoStore& pluginInfoStore() { return m_pluginInfoStore; } + + void setPluginLoadClientPolicy(WebCore::PluginLoadClientPolicy, const String& host, const String& bundleIdentifier, const String& versionString); + void clearPluginClientPolicies(); #endif + pid_t networkProcessIdentifier(); + void setAlwaysUsesComplexTextCodePath(bool); void setShouldUseFontSmoothing(bool); void registerURLSchemeAsEmptyDocument(const String&); void registerURLSchemeAsSecure(const String&); + void registerURLSchemeAsBypassingContentSecurityPolicy(const String&); void setDomainRelaxationForbiddenForURLScheme(const String&); + void setCanHandleHTTPSServerTrustEvaluation(bool); void registerURLSchemeAsLocal(const String&); void registerURLSchemeAsNoAccess(const String&); void registerURLSchemeAsDisplayIsolated(const String&); void registerURLSchemeAsCORSEnabled(const String&); +#if ENABLE(CACHE_PARTITIONING) + void registerURLSchemeAsCachePartitioned(const String&); +#endif - void addVisitedLink(const String&); - void addVisitedLinkHash(WebCore::LinkHash); - - // MessageReceiver. - virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; - virtual void didReceiveSyncMessage(IPC::Connection*, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override; + VisitedLinkStore& visitedLinkStore() { return m_visitedLinkStore.get(); } void setCacheModel(CacheModel); - CacheModel cacheModel() const { return m_cacheModel; } + CacheModel cacheModel() const { return m_configuration->cacheModel(); } void setDefaultRequestTimeoutInterval(double); @@ -211,16 +220,13 @@ public: void setEnhancedAccessibility(bool); // Downloads. - DownloadProxy* createDownloadProxy(); - WebDownloadClient& downloadClient() { return m_downloadClient; } + DownloadProxy* createDownloadProxy(const WebCore::ResourceRequest&); + API::DownloadClient& downloadClient() { return *m_downloadClient; } - WebHistoryClient& historyClient() { return m_historyClient; } + API::LegacyContextHistoryClient& historyClient() { return *m_historyClient; } WebContextClient& client() { return m_client; } WebIconDatabase* iconDatabase() const { return m_iconDatabase.get(); } -#if ENABLE(NETSCAPE_PLUGIN_API) - WebPluginSiteDataManager* pluginSiteDataManager() const { return m_pluginSiteDataManager.get(); } -#endif struct Statistics { unsigned wkViewCount; @@ -229,19 +235,18 @@ public: }; static Statistics& statistics(); - void setApplicationCacheDirectory(const String& dir) { m_overrideApplicationCacheDirectory = dir; } - void setDatabaseDirectory(const String& dir) { m_overrideDatabaseDirectory = dir; } void setIconDatabasePath(const String&); String iconDatabasePath() const; - void setLocalStorageDirectory(const String&); - void setDiskCacheDirectory(const String& dir) { m_overrideDiskCacheDirectory = dir; } void setCookieStorageDirectory(const String& dir) { m_overrideCookieStorageDirectory = dir; } void useTestingNetworkSession(); + bool isUsingTestingNetworkSession() const { return m_shouldUseTestingNetworkSession; } + + void clearCachedCredentials(); + void terminateDatabaseProcess(); void allowSpecificHTTPSCertificateForHost(const WebCertificateInfo*, const String& host); - WebProcessProxy& ensureSharedWebProcess(); WebProcessProxy& createNewWebProcessRespectingProcessCountLimit(); // Will return an existing one if limit is met. void warmInitialProcess(); @@ -250,16 +255,19 @@ public: void disableProcessTermination() { m_processTerminationEnabled = false; } void enableProcessTermination(); + void updateAutomationCapabilities() const; + void setAutomationSession(RefPtr<WebAutomationSession>&&); + // Defaults to false. void setHTTPPipeliningEnabled(bool); bool httpPipeliningEnabled() const; - void getStatistics(uint32_t statisticsMask, PassRefPtr<DictionaryCallback>); + void getStatistics(uint32_t statisticsMask, std::function<void (API::Dictionary*, CallbackBase::Error)>); void garbageCollectJavaScriptObjects(); void setJavaScriptGarbageCollectorTimerEnabled(bool flag); -#if PLATFORM(MAC) +#if PLATFORM(COCOA) static bool omitPDFSupport(); #endif @@ -267,32 +275,27 @@ public: void textCheckerStateChanged(); - PassRefPtr<ImmutableDictionary> plugInAutoStartOriginHashes() const; - void setPlugInAutoStartOriginHashes(ImmutableDictionary&); + PassRefPtr<API::Dictionary> plugInAutoStartOriginHashes() const; + void setPlugInAutoStartOriginHashes(API::Dictionary&); void setPlugInAutoStartOrigins(API::Array&); - void setPlugInAutoStartOriginsFilteringOutEntriesAddedAfterTime(ImmutableDictionary&, double time); + void setPlugInAutoStartOriginsFilteringOutEntriesAddedAfterTime(API::Dictionary&, double time); // Network Process Management - - void setUsesNetworkProcess(bool); - bool usesNetworkProcess() const; - -#if ENABLE(NETWORK_PROCESS) - void ensureNetworkProcess(); + NetworkProcessProxy& ensureNetworkProcess(); NetworkProcessProxy* networkProcess() { return m_networkProcess.get(); } void networkProcessCrashed(NetworkProcessProxy*); void getNetworkProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply>); -#endif #if ENABLE(DATABASE_PROCESS) void ensureDatabaseProcess(); + DatabaseProcessProxy* databaseProcess() { return m_databaseProcess.get(); } void getDatabaseProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetDatabaseProcessConnection::DelayedReply>); + void databaseProcessCrashed(DatabaseProcessProxy*); #endif -#if PLATFORM(MAC) +#if PLATFORM(COCOA) bool processSuppressionEnabled() const; - static bool processSuppressionIsEnabledForAllContexts(); #endif void windowServerConnectionStateChanged(); @@ -300,8 +303,6 @@ public: static void willStartUsingPrivateBrowsing(); static void willStopUsingPrivateBrowsing(); - static bool isEphemeralSession(uint64_t sessionID); - #if USE(SOUP) void setIgnoreTLSErrors(bool); bool ignoreTLSErrors() const { return m_ignoreTLSErrors; } @@ -314,21 +315,45 @@ public: bool isURLKnownHSTSHost(const String& urlString, bool privateBrowsingEnabled) const; void resetHSTSHosts(); + void resetHSTSHostsAddedAfterDate(double startDateIntervalSince1970); -#if ENABLE(CUSTOM_PROTOCOLS) void registerSchemeForCustomProtocol(const String&); void unregisterSchemeForCustomProtocol(const String&); - static HashSet<String>& globalURLSchemesWithCustomProtocolHandlers(); + static HashSet<String, ASCIICaseInsensitiveHash>& globalURLSchemesWithCustomProtocolHandlers(); static void registerGlobalURLSchemeAsHavingCustomProtocolHandlers(const String&); static void unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers(const String&); -#endif -#if PLATFORM(MAC) - void updateProcessSuppressionState() const; +#if PLATFORM(COCOA) + void updateProcessSuppressionState(); + + NSMutableDictionary *ensureBundleParameters(); + NSMutableDictionary *bundleParameters() { return m_bundleParameters.get(); } +#else + void updateProcessSuppressionState() const { } #endif void setMemoryCacheDisabled(bool); + void setFontWhitelist(API::Array*); + + UserObservablePageToken userObservablePageCount() + { + return m_userObservablePageCounter.token<UserObservablePageTokenType>(); + } + + ProcessSuppressionDisabledToken processSuppressionDisabledForPageCount() + { + return m_processSuppressionDisabledForPageCounter.token<ProcessSuppressionDisabledTokenType>(); + } + + // FIXME: Move these to API::WebsiteDataStore. + static String legacyPlatformDefaultLocalStorageDirectory(); + static String legacyPlatformDefaultIndexedDBDatabaseDirectory(); + static String legacyPlatformDefaultWebSQLDatabaseDirectory(); + static String legacyPlatformDefaultMediaKeysStorageDirectory(); + static String legacyPlatformDefaultApplicationCacheDirectory(); + static String legacyPlatformDefaultNetworkCacheDirectory(); + static bool isNetworkCacheEnabled(); private: void platformInitialize(); @@ -341,75 +366,41 @@ private: void requestWebContentStatistics(StatisticsRequest*); void requestNetworkingStatistics(StatisticsRequest*); -#if ENABLE(NETWORK_PROCESS) void platformInitializeNetworkProcess(NetworkProcessCreationParameters&); -#endif - -#if PLATFORM(MAC) -#if PLATFORM(IOS) - void writeWebContentToPasteboard(const WebCore::PasteboardWebContent&); - void writeImageToPasteboard(const WebCore::PasteboardImage&); - void writeStringToPasteboard(const String& pasteboardType, const String&); - void readStringFromPasteboard(uint64_t index, const String& pasteboardType, WTF::String&); - void readURLFromPasteboard(uint64_t index, const String& pasteboardType, String&); - void readBufferFromPasteboard(uint64_t index, const String& pasteboardType, SharedMemory::Handle&, uint64_t& size); - void getPasteboardItemsCount(uint64_t& itemsCount); -#endif - void getPasteboardTypes(const String& pasteboardName, Vector<String>& pasteboardTypes); - void getPasteboardPathnamesForType(const String& pasteboardName, const String& pasteboardType, Vector<String>& pathnames); - void getPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, String&); - void getPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, SharedMemory::Handle&, uint64_t& size); - void pasteboardCopy(const String& fromPasteboard, const String& toPasteboard, uint64_t& newChangeCount); - void getPasteboardChangeCount(const String& pasteboardName, uint64_t& changeCount); - void getPasteboardUniqueName(String& pasteboardName); - void getPasteboardColor(const String& pasteboardName, WebCore::Color&); - void getPasteboardURL(const String& pasteboardName, WTF::String&); - void addPasteboardTypes(const String& pasteboardName, const Vector<String>& pasteboardTypes, uint64_t& newChangeCount); - void setPasteboardTypes(const String& pasteboardName, const Vector<String>& pasteboardTypes, uint64_t& newChangeCount); - void setPasteboardPathnamesForType(const String& pasteboardName, const String& pasteboardType, const Vector<String>& pathnames, uint64_t& newChangeCount); - void setPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, const String&, uint64_t& newChangeCount); - void setPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, const SharedMemory::Handle&, uint64_t size, uint64_t& newChangeCount); -#endif -#if !PLATFORM(MAC) - // FIXME: This a dummy message, to avoid breaking the build for platforms that don't require - // any synchronous messages, and should be removed when <rdar://problem/8775115> is fixed. - void dummy(bool&); -#endif + void handleMessage(IPC::Connection&, const String& messageName, const UserData& messageBody); + void handleSynchronousMessage(IPC::Connection&, const String& messageName, const UserData& messageBody, UserData& returnUserData); void didGetStatistics(const StatisticsData&, uint64_t callbackID); - - // Implemented in generated WebContextMessageReceiver.cpp - void didReceiveWebContextMessage(IPC::Connection*, IPC::MessageDecoder&); - void didReceiveSyncWebContextMessage(IPC::Connection*, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&); + + // IPC::MessageReceiver. + // Implemented in generated WebProcessPoolMessageReceiver.cpp + virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override; + virtual void didReceiveSyncMessage(IPC::Connection&, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override; static void languageChanged(void* context); void languageChanged(); - String applicationCacheDirectory() const; - String platformDefaultApplicationCacheDirectory() const; - - String databaseDirectory() const; - String platformDefaultDatabaseDirectory() const; - String platformDefaultIconDatabasePath() const; - String localStorageDirectory() const; - String platformDefaultLocalStorageDirectory() const; - - String diskCacheDirectory() const; - String platformDefaultDiskCacheDirectory() const; - +#if PLATFORM(IOS) || ENABLE(SECCOMP_FILTERS) String cookieStorageDirectory() const; - String platformDefaultCookieStorageDirectory() const; +#endif -#if PLATFORM(MAC) +#if PLATFORM(IOS) + String parentBundleDirectory() const; + String networkingCachesDirectory() const; + String webContentCachesDirectory() const; + String containerTemporaryDirectory() const; +#endif + +#if PLATFORM(COCOA) void registerNotificationObservers(); void unregisterNotificationObservers(); #endif - void addPlugInAutoStartOriginHash(const String& pageOrigin, unsigned plugInOriginHash); - void plugInDidReceiveUserInteraction(unsigned plugInOriginHash); + void addPlugInAutoStartOriginHash(const String& pageOrigin, unsigned plugInOriginHash, WebCore::SessionID); + void plugInDidReceiveUserInteraction(unsigned plugInOriginHash, WebCore::SessionID); void setAnyPageGroupMightHavePrivateBrowsingEnabled(bool); @@ -418,11 +409,10 @@ private: virtual void pluginInfoStoreDidLoadPlugins(PluginInfoStore*) override; #endif + Ref<API::ProcessPoolConfiguration> m_configuration; + IPC::MessageReceiverMap m_messageReceiverMap; - ProcessModel m_processModel; - unsigned m_webProcessCountLimit; // The limit has no effect when process model is ProcessModelSharedSecondaryProcess. - Vector<RefPtr<WebProcessProxy>> m_processes; bool m_haveInitialEmptyProcess; @@ -431,46 +421,52 @@ private: Ref<WebPageGroup> m_defaultPageGroup; RefPtr<API::Object> m_injectedBundleInitializationUserData; - String m_injectedBundlePath; WebContextInjectedBundleClient m_injectedBundleClient; WebContextClient m_client; WebContextConnectionClient m_connectionClient; - WebDownloadClient m_downloadClient; - WebHistoryClient m_historyClient; + std::unique_ptr<API::AutomationClient> m_automationClient; + std::unique_ptr<API::DownloadClient> m_downloadClient; + std::unique_ptr<API::LegacyContextHistoryClient> m_historyClient; + + RefPtr<WebAutomationSession> m_automationSession; #if ENABLE(NETSCAPE_PLUGIN_API) PluginInfoStore m_pluginInfoStore; #endif - VisitedLinkProvider m_visitedLinkProvider; + Ref<VisitedLinkStore> m_visitedLinkStore; + bool m_visitedLinksPopulated; + PlugInAutoStartProvider m_plugInAutoStartProvider; HashSet<String> m_schemesToRegisterAsEmptyDocument; HashSet<String> m_schemesToRegisterAsSecure; + HashSet<String> m_schemesToRegisterAsBypassingContentSecurityPolicy; HashSet<String> m_schemesToSetDomainRelaxationForbiddenFor; HashSet<String> m_schemesToRegisterAsLocal; HashSet<String> m_schemesToRegisterAsNoAccess; HashSet<String> m_schemesToRegisterAsDisplayIsolated; HashSet<String> m_schemesToRegisterAsCORSEnabled; + HashSet<String> m_schemesToRegisterAsAlwaysRevalidated; +#if ENABLE(CACHE_PARTITIONING) + HashSet<String> m_schemesToRegisterAsCachePartitioned; +#endif bool m_alwaysUsesComplexTextCodePath; bool m_shouldUseFontSmoothing; + Vector<String> m_fontWhitelist; + // Messages that were posted before any pages were created. // The client should use initialization messages instead, so that a restarted process would get the same state. Vector<std::pair<String, RefPtr<API::Object>>> m_messagesToInjectedBundlePostedToEmptyContext; - CacheModel m_cacheModel; - bool m_memorySamplerEnabled; double m_memorySamplerInterval; RefPtr<WebIconDatabase> m_iconDatabase; -#if ENABLE(NETSCAPE_PLUGIN_API) - RefPtr<WebPluginSiteDataManager> m_pluginSiteDataManager; -#endif - RefPtr<StorageManager> m_storageManager; + const RefPtr<API::WebsiteDataStore> m_websiteDataStore; typedef HashMap<const char*, RefPtr<WebContextSupplement>, PtrHash<const char*>> WebContextSupplementMap; WebContextSupplementMap m_supplements; @@ -483,27 +479,20 @@ private: RetainPtr<NSObject> m_enhancedAccessibilityObserver; RetainPtr<NSObject> m_automaticTextReplacementNotificationObserver; RetainPtr<NSObject> m_automaticSpellingCorrectionNotificationObserver; -#if !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 RetainPtr<NSObject> m_automaticQuoteSubstitutionNotificationObserver; RetainPtr<NSObject> m_automaticDashSubstitutionNotificationObserver; #endif -#endif - String m_overrideApplicationCacheDirectory; - String m_overrideDatabaseDirectory; String m_overrideIconDatabasePath; - String m_overrideLocalStorageDirectory; - String m_overrideDiskCacheDirectory; String m_overrideCookieStorageDirectory; bool m_shouldUseTestingNetworkSession; bool m_processTerminationEnabled; -#if ENABLE(NETWORK_PROCESS) - bool m_usesNetworkProcess; + bool m_canHandleHTTPSServerTrustEvaluation; + bool m_didNetworkProcessCrash; RefPtr<NetworkProcessProxy> m_networkProcess; -#endif #if ENABLE(DATABASE_PROCESS) RefPtr<DatabaseProcessProxy> m_databaseProcess; @@ -513,68 +502,55 @@ private: HashMap<uint64_t, RefPtr<StatisticsRequest>> m_statisticsRequests; #if USE(SOUP) - bool m_ignoreTLSErrors; + bool m_ignoreTLSErrors { true }; #endif bool m_memoryCacheDisabled; + + RefCounter m_userObservablePageCounter; + RefCounter m_processSuppressionDisabledForPageCounter; + +#if PLATFORM(COCOA) + RetainPtr<NSMutableDictionary> m_bundleParameters; + ProcessSuppressionDisabledToken m_pluginProcessManagerProcessSuppressionDisabledToken; +#endif + +#if ENABLE(CONTENT_EXTENSIONS) + HashMap<String, String> m_encodedContentExtensions; +#endif + +#if ENABLE(NETSCAPE_PLUGIN_API) + HashMap<String, HashMap<String, HashMap<String, uint8_t>>> m_pluginLoadClientPolicies; +#endif }; template<typename T> -void WebContext::sendToNetworkingProcess(T&& message) +void WebProcessPool::sendToNetworkingProcess(T&& message) { - switch (m_processModel) { - case ProcessModelSharedSecondaryProcess: -#if ENABLE(NETWORK_PROCESS) - if (m_usesNetworkProcess) { - if (m_networkProcess && m_networkProcess->canSendMessage()) - m_networkProcess->send(std::forward<T>(message), 0); - return; - } -#endif - if (!m_processes.isEmpty() && m_processes[0]->canSendMessage()) - m_processes[0]->send(std::forward<T>(message), 0); - return; - case ProcessModelMultipleSecondaryProcesses: -#if ENABLE(NETWORK_PROCESS) - if (m_networkProcess && m_networkProcess->canSendMessage()) - m_networkProcess->send(std::forward<T>(message), 0); - return; -#else - break; -#endif - } - ASSERT_NOT_REACHED(); + if (m_networkProcess && m_networkProcess->canSendMessage()) + m_networkProcess->send(std::forward<T>(message), 0); } template<typename T> -void WebContext::sendToNetworkingProcessRelaunchingIfNecessary(T&& message) +void WebProcessPool::sendToNetworkingProcessRelaunchingIfNecessary(T&& message) { - switch (m_processModel) { - case ProcessModelSharedSecondaryProcess: -#if ENABLE(NETWORK_PROCESS) - if (m_usesNetworkProcess) { - ensureNetworkProcess(); - m_networkProcess->send(std::forward<T>(message), 0); - return; - } -#endif - ensureSharedWebProcess(); - m_processes[0]->send(std::forward<T>(message), 0); - return; - case ProcessModelMultipleSecondaryProcesses: -#if ENABLE(NETWORK_PROCESS) - ensureNetworkProcess(); - m_networkProcess->send(std::forward<T>(message), 0); - return; + ensureNetworkProcess(); + m_networkProcess->send(std::forward<T>(message), 0); +} + +template<typename T> +void WebProcessPool::sendToDatabaseProcessRelaunchingIfNecessary(T&& message) +{ +#if ENABLE(DATABASE_PROCESS) + ensureDatabaseProcess(); + m_databaseProcess->send(std::forward<T>(message), 0); #else - break; + sendToAllProcessesRelaunchingThemIfNecessary(std::forward<T>(message)); #endif - } - ASSERT_NOT_REACHED(); } template<typename T> -void WebContext::sendToAllProcesses(const T& message) +void WebProcessPool::sendToAllProcesses(const T& message) { size_t processCount = m_processes.size(); for (size_t i = 0; i < processCount; ++i) { @@ -585,20 +561,15 @@ void WebContext::sendToAllProcesses(const T& message) } template<typename T> -void WebContext::sendToAllProcessesRelaunchingThemIfNecessary(const T& message) +void WebProcessPool::sendToAllProcessesRelaunchingThemIfNecessary(const T& message) { -// FIXME (Multi-WebProcess): WebContext doesn't track processes that have exited, so it cannot relaunch these. Perhaps this functionality won't be needed in this mode. - if (m_processModel == ProcessModelSharedSecondaryProcess) - ensureSharedWebProcess(); + // FIXME (Multi-WebProcess): WebProcessPool doesn't track processes that have exited, so it cannot relaunch these. Perhaps this functionality won't be needed in this mode. sendToAllProcesses(message); } template<typename T> -void WebContext::sendToOneProcess(T&& message) +void WebProcessPool::sendToOneProcess(T&& message) { - if (m_processModel == ProcessModelSharedSecondaryProcess) - ensureSharedWebProcess(); - bool messageSent = false; size_t processCount = m_processes.size(); for (size_t i = 0; i < processCount; ++i) { @@ -610,7 +581,7 @@ void WebContext::sendToOneProcess(T&& message) } } - if (!messageSent && m_processModel == ProcessModelMultipleSecondaryProcesses) { + if (!messageSent) { warmInitialProcess(); RefPtr<WebProcessProxy> process = m_processes.last(); if (process->canSendMessage()) @@ -620,4 +591,4 @@ void WebContext::sendToOneProcess(T&& message) } // namespace WebKit -#endif // WebContext_h +#endif // UIProcessPool_h diff --git a/Source/WebKit2/UIProcess/WebDatabaseManagerProxy.messages.in b/Source/WebKit2/UIProcess/WebProcessPool.messages.in index b399cab43..76b75cff6 100644 --- a/Source/WebKit2/UIProcess/WebDatabaseManagerProxy.messages.in +++ b/Source/WebKit2/UIProcess/WebProcessPool.messages.in @@ -20,13 +20,13 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#if ENABLE(SQL_DATABASE) +messages -> WebProcessPool { + HandleMessage(String messageName, WebKit::UserData messageBody) WantsConnection + HandleSynchronousMessage(String messageName, WebKit::UserData messageBody) -> (WebKit::UserData returnData) WantsConnection -messages -> WebDatabaseManagerProxy { - DidGetDatabasesByOrigin(Vector<WebKit::OriginAndDatabases> originAndDatabases, uint64_t callbackID); - DidGetDatabaseOrigins(Vector<String> originIdentifiers, uint64_t callbackID) - DidModifyOrigin(String originIdentifier) - DidModifyDatabase(String originIdentifier, String databaseIdentifier) -} + DidGetStatistics(struct WebKit::StatisticsData statisticsData, uint64_t callbackID) -#endif // ENABLE(SQL_DATABASE) + # Plug-in messages. + void AddPlugInAutoStartOriginHash(String pageOrigin, uint32_t hash, WebCore::SessionID sessionID) + void PlugInDidReceiveUserInteraction(uint32_t hash, WebCore::SessionID sessionID) +} diff --git a/Source/WebKit2/UIProcess/WebProcessProxy.cpp b/Source/WebKit2/UIProcess/WebProcessProxy.cpp index be18b2c35..62df9d38d 100644 --- a/Source/WebKit2/UIProcess/WebProcessProxy.cpp +++ b/Source/WebKit2/UIProcess/WebProcessProxy.cpp @@ -27,6 +27,8 @@ #include "WebProcessProxy.h" #include "APIFrameHandle.h" +#include "APIPageGroupHandle.h" +#include "APIPageHandle.h" #include "CustomProtocolManagerProxyMessages.h" #include "DataReference.h" #include "DownloadProxyMap.h" @@ -36,13 +38,18 @@ #include "TextCheckerState.h" #include "UserData.h" #include "WebBackForwardListItem.h" -#include "WebContext.h" +#include "WebIconDatabase.h" +#include "WebInspectorProxy.h" #include "WebNavigationDataStore.h" #include "WebNotificationManagerProxy.h" +#include "WebPageGroup.h" #include "WebPageProxy.h" -#include "WebPluginSiteDataManager.h" +#include "WebPasteboardProxy.h" #include "WebProcessMessages.h" +#include "WebProcessPool.h" #include "WebProcessProxyMessages.h" +#include "WebUserContentControllerProxy.h" +#include "WebsiteData.h" #include <WebCore/SuddenTermination.h> #include <WebCore/URL.h> #include <stdio.h> @@ -51,7 +58,8 @@ #include <wtf/text/CString.h> #include <wtf/text/WTFString.h> -#if PLATFORM(MAC) +#if PLATFORM(COCOA) +#include "ObjCObjectGraph.h" #include "PDFPlugin.h" #endif @@ -72,6 +80,13 @@ static uint64_t generatePageID() return ++uniquePageID; } +static uint64_t generateCallbackID() +{ + static uint64_t callbackID; + + return ++callbackID; +} + static WebProcessProxy::WebPageProxyMap& globalPageMap() { ASSERT(RunLoop::isMain()); @@ -79,28 +94,32 @@ static WebProcessProxy::WebPageProxyMap& globalPageMap() return pageMap; } -PassRefPtr<WebProcessProxy> WebProcessProxy::create(WebContext& context) +Ref<WebProcessProxy> WebProcessProxy::create(WebProcessPool& processPool) { - return adoptRef(new WebProcessProxy(context)); + return adoptRef(*new WebProcessProxy(processPool)); } -WebProcessProxy::WebProcessProxy(WebContext& context) - : m_responsivenessTimer(this) - , m_context(context) +WebProcessProxy::WebProcessProxy(WebProcessPool& processPool) + : m_responsivenessTimer(*this) + , m_processPool(processPool) , m_mayHaveUniversalFileReadSandboxExtension(false) -#if ENABLE(CUSTOM_PROTOCOLS) - , m_customProtocolManagerProxy(this, context) -#endif -#if PLATFORM(MAC) - , m_processSuppressionEnabled(false) -#endif + , m_customProtocolManagerProxy(this, processPool) , m_numberOfTimesSuddenTerminationWasDisabled(0) + , m_throttler(*this) + , m_isResponsive(NoOrMaybe::Maybe) { + WebPasteboardProxy::singleton().addWebProcessProxy(*this); + connect(); } WebProcessProxy::~WebProcessProxy() { + ASSERT(m_pendingFetchWebsiteDataCallbacks.isEmpty()); + ASSERT(m_pendingDeleteWebsiteDataCallbacks.isEmpty()); + ASSERT(m_pendingDeleteWebsiteDataForOriginsCallbacks.isEmpty()); + ASSERT(m_pageURLRetainCountMap.isEmpty()); + if (m_webConnection) m_webConnection->invalidate(); @@ -110,37 +129,62 @@ WebProcessProxy::~WebProcessProxy() void WebProcessProxy::getLaunchOptions(ProcessLauncher::LaunchOptions& launchOptions) { - launchOptions.processType = ProcessLauncher::WebProcess; - platformGetLaunchOptions(launchOptions); + launchOptions.processType = ProcessLauncher::ProcessType::Web; + + ChildProcessProxy::getLaunchOptions(launchOptions); + + if (WebInspectorProxy::isInspectorProcessPool(m_processPool)) + launchOptions.extraInitializationData.add(ASCIILiteral("inspector-process"), ASCIILiteral("1")); + + auto overrideLanguages = m_processPool->configuration().overrideLanguages(); + if (overrideLanguages.size()) { + StringBuilder languageString; + for (size_t i = 0; i < overrideLanguages.size(); ++i) { + if (i) + languageString.append(','); + languageString.append(overrideLanguages[i]); + } + launchOptions.extraInitializationData.add(ASCIILiteral("OverrideLanguages"), languageString.toString()); + } } -void WebProcessProxy::connectionWillOpen(IPC::Connection* connection) +void WebProcessProxy::connectionWillOpen(IPC::Connection& connection) { - ASSERT(this->connection() == connection); + ASSERT(this->connection() == &connection); #if ENABLE(SEC_ITEM_SHIM) - SecItemShimProxy::shared().initializeConnection(connection); + SecItemShimProxy::singleton().initializeConnection(connection); #endif - for (WebPageProxyMap::iterator it = m_pageMap.begin(), end = m_pageMap.end(); it != end; ++it) - it->value->connectionWillOpen(connection); - - m_context->processWillOpenConnection(this); + for (auto& page : m_pageMap.values()) + page->connectionWillOpen(connection); } -void WebProcessProxy::connectionWillClose(IPC::Connection* connection) +void WebProcessProxy::processWillShutDown(IPC::Connection& connection) { - ASSERT(this->connection() == connection); + ASSERT_UNUSED(connection, this->connection() == &connection); - for (WebPageProxyMap::iterator it = m_pageMap.begin(), end = m_pageMap.end(); it != end; ++it) - it->value->connectionWillClose(connection); + for (const auto& callback : m_pendingFetchWebsiteDataCallbacks.values()) + callback(WebsiteData()); + m_pendingFetchWebsiteDataCallbacks.clear(); - m_context->processWillCloseConnection(this); + for (const auto& callback : m_pendingDeleteWebsiteDataCallbacks.values()) + callback(); + m_pendingDeleteWebsiteDataCallbacks.clear(); + + for (const auto& callback : m_pendingDeleteWebsiteDataForOriginsCallbacks.values()) + callback(); + m_pendingDeleteWebsiteDataForOriginsCallbacks.clear(); + + for (auto& page : m_pageMap.values()) + page->webProcessWillShutDown(); + + releaseRemainingIconsForPageURLs(); } -void WebProcessProxy::disconnect() +void WebProcessProxy::shutDown() { - clearConnection(); + shutDownProcess(); if (m_webConnection) { m_webConnection->invalidate(); @@ -148,18 +192,24 @@ void WebProcessProxy::disconnect() } m_responsivenessTimer.invalidate(); + m_tokenForHoldingLockedFiles = nullptr; Vector<RefPtr<WebFrameProxy>> frames; copyValuesToVector(m_frameMap, frames); for (size_t i = 0, size = frames.size(); i < size; ++i) - frames[i]->disconnect(); + frames[i]->webProcessWillShutDown(); m_frameMap.clear(); - if (m_downloadProxyMap) - m_downloadProxyMap->processDidClose(); + for (VisitedLinkStore* visitedLinkStore : m_visitedLinkStores) + visitedLinkStore->removeProcess(*this); + m_visitedLinkStores.clear(); + + for (WebUserContentControllerProxy* webUserContentControllerProxy : m_webUserContentControllerProxies) + webUserContentControllerProxy->removeProcess(*this); + m_webUserContentControllerProxies.clear(); - m_context->disconnectProcess(this); + m_processPool->disconnectProcess(this); } WebPageProxy* WebProcessProxy::webPage(uint64_t pageID) @@ -167,53 +217,69 @@ WebPageProxy* WebProcessProxy::webPage(uint64_t pageID) return globalPageMap().get(pageID); } -PassRefPtr<WebPageProxy> WebProcessProxy::createWebPage(PageClient& pageClient, const WebPageConfiguration& configuration) +Ref<WebPageProxy> WebProcessProxy::createWebPage(PageClient& pageClient, Ref<API::PageConfiguration>&& pageConfiguration) { uint64_t pageID = generatePageID(); - RefPtr<WebPageProxy> webPage = WebPageProxy::create(pageClient, *this, pageID, configuration); - m_pageMap.set(pageID, webPage.get()); - globalPageMap().set(pageID, webPage.get()); -#if PLATFORM(MAC) - if (webPage->isProcessSuppressible()) - m_processSuppressiblePages.add(pageID); - updateProcessSuppressionState(); -#endif - return webPage.release(); + Ref<WebPageProxy> webPage = WebPageProxy::create(pageClient, *this, pageID, WTFMove(pageConfiguration)); + + m_pageMap.set(pageID, webPage.ptr()); + globalPageMap().set(pageID, webPage.ptr()); + + return webPage; } void WebProcessProxy::addExistingWebPage(WebPageProxy* webPage, uint64_t pageID) { + ASSERT(!m_pageMap.contains(pageID)); + ASSERT(!globalPageMap().contains(pageID)); + m_pageMap.set(pageID, webPage); globalPageMap().set(pageID, webPage); -#if PLATFORM(MAC) - if (webPage->isProcessSuppressible()) - m_processSuppressiblePages.add(pageID); - updateProcessSuppressionState(); -#endif } void WebProcessProxy::removeWebPage(uint64_t pageID) { m_pageMap.remove(pageID); globalPageMap().remove(pageID); -#if PLATFORM(MAC) - m_processSuppressiblePages.remove(pageID); - updateProcessSuppressionState(); -#endif + + Vector<uint64_t> itemIDsToRemove; + for (auto& idAndItem : m_backForwardListItemMap) { + if (idAndItem.value->pageID() == pageID) + itemIDsToRemove.append(idAndItem.key); + } + for (auto itemID : itemIDsToRemove) + m_backForwardListItemMap.remove(itemID); // If this was the last WebPage open in that web process, and we have no other reason to keep it alive, let it go. // We only allow this when using a network process, as otherwise the WebProcess needs to preserve its session state. - if (m_context->usesNetworkProcess() && canTerminateChildProcess()) { - abortProcessLaunchIfNeeded(); - disconnect(); - } + if (state() == State::Terminated || !canTerminateChildProcess()) + return; + + shutDown(); } -Vector<WebPageProxy*> WebProcessProxy::pages() const +void WebProcessProxy::addVisitedLinkStore(VisitedLinkStore& store) { - Vector<WebPageProxy*> result; - copyValuesToVector(m_pageMap, result); - return result; + m_visitedLinkStores.add(&store); + store.addProcess(*this); +} + +void WebProcessProxy::addWebUserContentControllerProxy(WebUserContentControllerProxy& proxy) +{ + m_webUserContentControllerProxies.add(&proxy); + proxy.addProcess(*this); +} + +void WebProcessProxy::didDestroyVisitedLinkStore(VisitedLinkStore& store) +{ + ASSERT(m_visitedLinkStores.contains(&store)); + m_visitedLinkStores.remove(&store); +} + +void WebProcessProxy::didDestroyWebUserContentControllerProxy(WebUserContentControllerProxy& proxy) +{ + ASSERT(m_webUserContentControllerProxies.contains(&proxy)); + m_webUserContentControllerProxies.remove(&proxy); } WebBackForwardListItem* WebProcessProxy::webBackForwardItem(uint64_t itemID) const @@ -230,6 +296,11 @@ void WebProcessProxy::registerNewWebBackForwardListItem(WebBackForwardListItem* m_backForwardListItemMap.set(item->itemID(), item); } +void WebProcessProxy::removeBackForwardItem(uint64_t itemID) +{ + m_backForwardListItemMap.remove(itemID); +} + void WebProcessProxy::assumeReadAccessToBaseURL(const String& urlString) { URL url(URL(), urlString); @@ -285,9 +356,11 @@ bool WebProcessProxy::checkURLReceivedFromWebProcess(const URL& url) // One case where we don't have sandbox extensions for file URLs in b/f list is if the list has been reinstated after a crash or a browser restart. String path = url.fileSystemPath(); for (WebBackForwardListItemMap::iterator iter = m_backForwardListItemMap.begin(), end = m_backForwardListItemMap.end(); iter != end; ++iter) { - if (URL(URL(), iter->value->url()).fileSystemPath() == path) + URL itemURL(URL(), iter->value->url()); + if (itemURL.isLocalFile() && itemURL.fileSystemPath() == path) return true; - if (URL(URL(), iter->value->originalURL()).fileSystemPath() == path) + URL itemOriginalURL(URL(), iter->value->originalURL()); + if (itemOriginalURL.isLocalFile() && itemOriginalURL.fileSystemPath() == path) return true; } @@ -296,44 +369,44 @@ bool WebProcessProxy::checkURLReceivedFromWebProcess(const URL& url) return false; } -#if !PLATFORM(MAC) +#if !PLATFORM(COCOA) bool WebProcessProxy::fullKeyboardAccessEnabled() { return false; } #endif -void WebProcessProxy::addBackForwardItem(uint64_t itemID, const String& originalURL, const String& url, const String& title, const IPC::DataReference& backForwardData) +void WebProcessProxy::addBackForwardItem(uint64_t itemID, uint64_t pageID, const PageState& pageState) { - MESSAGE_CHECK_URL(originalURL); - MESSAGE_CHECK_URL(url); - - WebBackForwardListItemMap::AddResult result = m_backForwardListItemMap.add(itemID, nullptr); - if (result.isNewEntry) { - result.iterator->value = WebBackForwardListItem::create(originalURL, url, title, backForwardData.data(), backForwardData.size(), itemID); + MESSAGE_CHECK_URL(pageState.mainFrameState.originalURLString); + MESSAGE_CHECK_URL(pageState.mainFrameState.urlString); + + auto& backForwardListItem = m_backForwardListItemMap.add(itemID, nullptr).iterator->value; + if (!backForwardListItem) { + BackForwardListItemState backForwardListItemState; + backForwardListItemState.identifier = itemID; + backForwardListItemState.pageState = pageState; + backForwardListItem = WebBackForwardListItem::create(WTFMove(backForwardListItemState), pageID); return; } // Update existing item. - result.iterator->value->setOriginalURL(originalURL); - result.iterator->value->setURL(url); - result.iterator->value->setTitle(title); - result.iterator->value->setBackForwardData(backForwardData.data(), backForwardData.size()); + backForwardListItem->setPageState(pageState); } #if ENABLE(NETSCAPE_PLUGIN_API) void WebProcessProxy::getPlugins(bool refresh, Vector<PluginInfo>& plugins, Vector<PluginInfo>& applicationPlugins) { if (refresh) - m_context->pluginInfoStore().refresh(); + m_processPool->pluginInfoStore().refresh(); - Vector<PluginModuleInfo> pluginModules = m_context->pluginInfoStore().plugins(); + Vector<PluginModuleInfo> pluginModules = m_processPool->pluginInfoStore().plugins(); for (size_t i = 0; i < pluginModules.size(); ++i) plugins.append(pluginModules[i].info); #if ENABLE(PDFKIT_PLUGIN) // Add built-in PDF last, so that it's not used when a real plug-in is installed. - if (!m_context->omitPDFSupport()) { + if (!m_processPool->omitPDFSupport()) { plugins.append(PDFPlugin::pluginInfo()); applicationPlugins.append(PDFPlugin::pluginInfo()); } @@ -346,30 +419,75 @@ void WebProcessProxy::getPlugins(bool refresh, Vector<PluginInfo>& plugins, Vect #if ENABLE(NETSCAPE_PLUGIN_API) void WebProcessProxy::getPluginProcessConnection(uint64_t pluginProcessToken, PassRefPtr<Messages::WebProcessProxy::GetPluginProcessConnection::DelayedReply> reply) { - PluginProcessManager::shared().getPluginProcessConnection(pluginProcessToken, reply); + PluginProcessManager::singleton().getPluginProcessConnection(pluginProcessToken, reply); } #endif -#if ENABLE(NETWORK_PROCESS) void WebProcessProxy::getNetworkProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply> reply) { - m_context->getNetworkProcessConnection(reply); + m_processPool->getNetworkProcessConnection(reply); } -#endif // ENABLE(NETWORK_PROCESS) #if ENABLE(DATABASE_PROCESS) void WebProcessProxy::getDatabaseProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetDatabaseProcessConnection::DelayedReply> reply) { - m_context->getDatabaseProcessConnection(reply); + m_processPool->getDatabaseProcessConnection(reply); } #endif // ENABLE(DATABASE_PROCESS) -void WebProcessProxy::didReceiveMessage(IPC::Connection* connection, IPC::MessageDecoder& decoder) +void WebProcessProxy::retainIconForPageURL(const String& pageURL) +{ + WebIconDatabase* iconDatabase = processPool().iconDatabase(); + if (!iconDatabase || pageURL.isEmpty()) + return; + + // Track retain counts so we can release them if the WebProcess terminates early. + auto result = m_pageURLRetainCountMap.add(pageURL, 1); + if (!result.isNewEntry) + ++result.iterator->value; + + iconDatabase->retainIconForPageURL(pageURL); +} + +void WebProcessProxy::releaseIconForPageURL(const String& pageURL) +{ + WebIconDatabase* iconDatabase = processPool().iconDatabase(); + if (!iconDatabase || pageURL.isEmpty()) + return; + + // Track retain counts so we can release them if the WebProcess terminates early. + auto result = m_pageURLRetainCountMap.find(pageURL); + if (result == m_pageURLRetainCountMap.end()) + return; + + --result->value; + if (!result->value) + m_pageURLRetainCountMap.remove(result); + + iconDatabase->releaseIconForPageURL(pageURL); +} + +void WebProcessProxy::releaseRemainingIconsForPageURLs() +{ + WebIconDatabase* iconDatabase = processPool().iconDatabase(); + if (!iconDatabase) + return; + + for (auto& entry : m_pageURLRetainCountMap) { + uint64_t count = entry.value; + for (uint64_t i = 0; i < count; ++i) + iconDatabase->releaseIconForPageURL(entry.key); + } + + m_pageURLRetainCountMap.clear(); +} + +void WebProcessProxy::didReceiveMessage(IPC::Connection& connection, IPC::MessageDecoder& decoder) { if (dispatchMessage(connection, decoder)) return; - if (m_context->dispatchMessage(connection, decoder)) + if (m_processPool->dispatchMessage(connection, decoder)) return; if (decoder.messageReceiverName() == Messages::WebProcessProxy::messageReceiverName()) { @@ -380,12 +498,12 @@ void WebProcessProxy::didReceiveMessage(IPC::Connection* connection, IPC::Messag // FIXME: Add unhandled message logging. } -void WebProcessProxy::didReceiveSyncMessage(IPC::Connection* connection, IPC::MessageDecoder& decoder, std::unique_ptr<IPC::MessageEncoder>& replyEncoder) +void WebProcessProxy::didReceiveSyncMessage(IPC::Connection& connection, IPC::MessageDecoder& decoder, std::unique_ptr<IPC::MessageEncoder>& replyEncoder) { if (dispatchSyncMessage(connection, decoder, replyEncoder)) return; - if (m_context->dispatchSyncMessage(connection, decoder, replyEncoder)) + if (m_processPool->dispatchSyncMessage(connection, decoder, replyEncoder)) return; if (decoder.messageReceiverName() == Messages::WebProcessProxy::messageReceiverName()) { @@ -396,7 +514,7 @@ void WebProcessProxy::didReceiveSyncMessage(IPC::Connection* connection, IPC::Me // FIXME: Add unhandled message logging. } -void WebProcessProxy::didClose(IPC::Connection*) +void WebProcessProxy::didClose(IPC::Connection&) { // Protect ourselves, as the call to disconnect() below may otherwise cause us // to be deleted before we can finish our work. @@ -407,18 +525,18 @@ void WebProcessProxy::didClose(IPC::Connection*) Vector<RefPtr<WebPageProxy>> pages; copyValuesToVector(m_pageMap, pages); - disconnect(); + shutDown(); for (size_t i = 0, size = pages.size(); i < size; ++i) pages[i]->processDidCrash(); } -void WebProcessProxy::didReceiveInvalidMessage(IPC::Connection* connection, IPC::StringReference messageReceiverName, IPC::StringReference messageName) +void WebProcessProxy::didReceiveInvalidMessage(IPC::Connection& connection, IPC::StringReference messageReceiverName, IPC::StringReference messageName) { WTFLogAlways("Received an invalid message \"%s.%s\" from the web process.\n", messageReceiverName.toString().data(), messageName.toString().data()); - WebContext::didReceiveInvalidMessage(messageReceiverName, messageName); + WebProcessPool::didReceiveInvalidMessage(messageReceiverName, messageName); // Terminate the WebProcess. terminate(); @@ -428,40 +546,66 @@ void WebProcessProxy::didReceiveInvalidMessage(IPC::Connection* connection, IPC: didClose(connection); } -void WebProcessProxy::didBecomeUnresponsive(ResponsivenessTimer*) +void WebProcessProxy::didBecomeUnresponsive() { + m_isResponsive = NoOrMaybe::No; + Vector<RefPtr<WebPageProxy>> pages; copyValuesToVector(m_pageMap, pages); - for (size_t i = 0, size = pages.size(); i < size; ++i) - pages[i]->processDidBecomeUnresponsive(); + + auto isResponsiveCallbacks = WTFMove(m_isResponsiveCallbacks); + + for (auto& page : pages) + page->processDidBecomeUnresponsive(); + + bool isWebProcessResponsive = false; + for (auto& callback : isResponsiveCallbacks) + callback(isWebProcessResponsive); } -void WebProcessProxy::interactionOccurredWhileUnresponsive(ResponsivenessTimer*) +void WebProcessProxy::didBecomeResponsive() { + m_isResponsive = NoOrMaybe::Maybe; + Vector<RefPtr<WebPageProxy>> pages; copyValuesToVector(m_pageMap, pages); - for (size_t i = 0, size = pages.size(); i < size; ++i) - pages[i]->interactionOccurredWhileProcessUnresponsive(); + for (auto& page : pages) + page->processDidBecomeResponsive(); } -void WebProcessProxy::didBecomeResponsive(ResponsivenessTimer*) +void WebProcessProxy::willChangeIsResponsive() { Vector<RefPtr<WebPageProxy>> pages; copyValuesToVector(m_pageMap, pages); - for (size_t i = 0, size = pages.size(); i < size; ++i) - pages[i]->processDidBecomeResponsive(); + for (auto& page : pages) + page->willChangeProcessIsResponsive(); +} + +void WebProcessProxy::didChangeIsResponsive() +{ + Vector<RefPtr<WebPageProxy>> pages; + copyValuesToVector(m_pageMap, pages); + for (auto& page : pages) + page->didChangeProcessIsResponsive(); } void WebProcessProxy::didFinishLaunching(ProcessLauncher* launcher, IPC::Connection::Identifier connectionIdentifier) { ChildProcessProxy::didFinishLaunching(launcher, connectionIdentifier); + for (WebPageProxy* page : m_pageMap.values()) { + ASSERT(this == &page->process()); + page->processDidFinishLaunching(); + } + m_webConnection = WebConnectionToWebProcess::create(this); - m_context->processDidFinishLaunching(this); + m_processPool->processDidFinishLaunching(this); -#if PLATFORM(MAC) - updateProcessSuppressionState(); +#if PLATFORM(IOS) + xpc_connection_t xpcConnection = connection()->xpcConnection(); + ASSERT(xpcConnection); + m_throttler.didConnectToProcess(xpc_connection_get_pid(xpcConnection)); #endif } @@ -499,7 +643,7 @@ void WebProcessProxy::disconnectFramesFromPage(WebPageProxy* page) copyValuesToVector(m_frameMap, frames); for (size_t i = 0, size = frames.size(); i < size; ++i) { if (frames[i]->page() == page) - frames[i]->disconnect(); + frames[i]->webProcessWillShutDown(); } } @@ -518,10 +662,10 @@ bool WebProcessProxy::canTerminateChildProcess() if (!m_pageMap.isEmpty()) return false; - if (m_downloadProxyMap && !m_downloadProxyMap->isEmpty()) + if (!m_pendingDeleteWebsiteDataCallbacks.isEmpty()) return false; - if (!m_context->shouldTerminate(this)) + if (!m_processPool->shouldTerminate(this)) return false; return true; @@ -531,180 +675,352 @@ void WebProcessProxy::shouldTerminate(bool& shouldTerminate) { shouldTerminate = canTerminateChildProcess(); if (shouldTerminate) { - // We know that the web process is going to terminate so disconnect it from the context. - disconnect(); + // We know that the web process is going to terminate so start shutting it down in the UI process. + shutDown(); } } +void WebProcessProxy::didFetchWebsiteData(uint64_t callbackID, const WebsiteData& websiteData) +{ + auto callback = m_pendingFetchWebsiteDataCallbacks.take(callbackID); + callback(websiteData); +} + +void WebProcessProxy::didDeleteWebsiteData(uint64_t callbackID) +{ + auto callback = m_pendingDeleteWebsiteDataCallbacks.take(callbackID); + callback(); +} + +void WebProcessProxy::didDeleteWebsiteDataForOrigins(uint64_t callbackID) +{ + auto callback = m_pendingDeleteWebsiteDataForOriginsCallbacks.take(callbackID); + callback(); +} + void WebProcessProxy::updateTextCheckerState() { if (canSendMessage()) send(Messages::WebProcess::SetTextCheckerState(TextChecker::state()), 0); } -DownloadProxy* WebProcessProxy::createDownloadProxy() +void WebProcessProxy::didSaveToPageCache() { -#if ENABLE(NETWORK_PROCESS) - ASSERT(!m_context->usesNetworkProcess()); -#endif + m_processPool->processDidCachePage(this); +} - if (!m_downloadProxyMap) - m_downloadProxyMap = adoptPtr(new DownloadProxyMap(this)); +void WebProcessProxy::releasePageCache() +{ + if (canSendMessage()) + send(Messages::WebProcess::ReleasePageCache(), 0); +} - return m_downloadProxyMap->createDownloadProxy(m_context.get()); +void WebProcessProxy::windowServerConnectionStateChanged() +{ + for (const auto& page : m_pageMap.values()) + page->viewStateDidChange(ViewState::IsVisuallyIdle); } -void WebProcessProxy::didNavigateWithNavigationData(uint64_t pageID, const WebNavigationDataStore& store, uint64_t frameID) +void WebProcessProxy::fetchWebsiteData(SessionID sessionID, WebsiteDataTypes dataTypes, std::function<void (WebsiteData)> completionHandler) { - WebPageProxy* page = webPage(pageID); - if (!page) - return; - - WebFrameProxy* frame = webFrame(frameID); - MESSAGE_CHECK(frame); - MESSAGE_CHECK(frame->page() == page); - - m_context->historyClient().didNavigateWithNavigationData(&m_context.get(), page, store, frame); + ASSERT(canSendMessage()); + + uint64_t callbackID = generateCallbackID(); + auto token = throttler().backgroundActivityToken(); + + m_pendingFetchWebsiteDataCallbacks.add(callbackID, [token, completionHandler](WebsiteData websiteData) { + completionHandler(WTFMove(websiteData)); + }); + + send(Messages::WebProcess::FetchWebsiteData(sessionID, dataTypes, callbackID), 0); } -void WebProcessProxy::didPerformClientRedirect(uint64_t pageID, const String& sourceURLString, const String& destinationURLString, uint64_t frameID) +void WebProcessProxy::deleteWebsiteData(SessionID sessionID, WebsiteDataTypes dataTypes, std::chrono::system_clock::time_point modifiedSince, std::function<void ()> completionHandler) { - WebPageProxy* page = webPage(pageID); - if (!page) - return; + ASSERT(canSendMessage()); - if (sourceURLString.isEmpty() || destinationURLString.isEmpty()) - return; - - WebFrameProxy* frame = webFrame(frameID); - MESSAGE_CHECK(frame); - MESSAGE_CHECK(frame->page() == page); - MESSAGE_CHECK_URL(sourceURLString); - MESSAGE_CHECK_URL(destinationURLString); + uint64_t callbackID = generateCallbackID(); + auto token = throttler().backgroundActivityToken(); - m_context->historyClient().didPerformClientRedirect(&m_context.get(), page, sourceURLString, destinationURLString, frame); + m_pendingDeleteWebsiteDataCallbacks.add(callbackID, [token, completionHandler] { + completionHandler(); + }); + send(Messages::WebProcess::DeleteWebsiteData(sessionID, dataTypes, modifiedSince, callbackID), 0); } -void WebProcessProxy::didPerformServerRedirect(uint64_t pageID, const String& sourceURLString, const String& destinationURLString, uint64_t frameID) +void WebProcessProxy::deleteWebsiteDataForOrigins(SessionID sessionID, WebsiteDataTypes dataTypes, const Vector<RefPtr<WebCore::SecurityOrigin>>& origins, std::function<void ()> completionHandler) { - WebPageProxy* page = webPage(pageID); - if (!page) - return; - - if (sourceURLString.isEmpty() || destinationURLString.isEmpty()) + ASSERT(canSendMessage()); + + uint64_t callbackID = generateCallbackID(); + auto token = throttler().backgroundActivityToken(); + + m_pendingDeleteWebsiteDataForOriginsCallbacks.add(callbackID, [token, completionHandler] { + completionHandler(); + }); + + Vector<SecurityOriginData> originData; + for (auto& origin : origins) + originData.append(SecurityOriginData::fromSecurityOrigin(*origin)); + + send(Messages::WebProcess::DeleteWebsiteDataForOrigins(sessionID, dataTypes, originData, callbackID), 0); +} + +void WebProcessProxy::requestTermination() +{ + if (state() != State::Running) return; - - WebFrameProxy* frame = webFrame(frameID); - MESSAGE_CHECK(frame); - MESSAGE_CHECK(frame->page() == page); - MESSAGE_CHECK_URL(sourceURLString); - MESSAGE_CHECK_URL(destinationURLString); - m_context->historyClient().didPerformServerRedirect(&m_context.get(), page, sourceURLString, destinationURLString, frame); + ChildProcessProxy::terminate(); + + if (webConnection()) + webConnection()->didClose(); + + shutDown(); } -void WebProcessProxy::didUpdateHistoryTitle(uint64_t pageID, const String& title, const String& url, uint64_t frameID) +void WebProcessProxy::enableSuddenTermination() { - WebPageProxy* page = webPage(pageID); - if (!page) + if (state() != State::Running) return; - WebFrameProxy* frame = webFrame(frameID); - MESSAGE_CHECK(frame); - MESSAGE_CHECK(frame->page() == page); - MESSAGE_CHECK_URL(url); + ASSERT(m_numberOfTimesSuddenTerminationWasDisabled); + WebCore::enableSuddenTermination(); + --m_numberOfTimesSuddenTerminationWasDisabled; +} - m_context->historyClient().didUpdateHistoryTitle(&m_context.get(), page, title, url, frame); +void WebProcessProxy::disableSuddenTermination() +{ + if (state() != State::Running) + return; + + WebCore::disableSuddenTermination(); + ++m_numberOfTimesSuddenTerminationWasDisabled; } -void WebProcessProxy::pageSuppressibilityChanged(WebKit::WebPageProxy *page) +RefPtr<API::Object> WebProcessProxy::transformHandlesToObjects(API::Object* object) { -#if PLATFORM(MAC) - if (page->isProcessSuppressible()) - m_processSuppressiblePages.add(page->pageID()); - else - m_processSuppressiblePages.remove(page->pageID()); - updateProcessSuppressionState(); -#else - UNUSED_PARAM(page); + struct Transformer final : UserData::Transformer { + Transformer(WebProcessProxy& webProcessProxy) + : m_webProcessProxy(webProcessProxy) + { + } + + virtual bool shouldTransformObject(const API::Object& object) const override + { + switch (object.type()) { + case API::Object::Type::FrameHandle: + return static_cast<const API::FrameHandle&>(object).isAutoconverting(); + + case API::Object::Type::PageHandle: + return static_cast<const API::PageHandle&>(object).isAutoconverting(); + + case API::Object::Type::PageGroupHandle: +#if PLATFORM(COCOA) + case API::Object::Type::ObjCObjectGraph: +#endif + return true; + + default: + return false; + } + } + + virtual RefPtr<API::Object> transformObject(API::Object& object) const override + { + switch (object.type()) { + case API::Object::Type::FrameHandle: + ASSERT(static_cast<API::FrameHandle&>(object).isAutoconverting()); + return m_webProcessProxy.webFrame(static_cast<API::FrameHandle&>(object).frameID()); + + case API::Object::Type::PageGroupHandle: + return WebPageGroup::get(static_cast<API::PageGroupHandle&>(object).webPageGroupData().pageGroupID); + + case API::Object::Type::PageHandle: + ASSERT(static_cast<API::PageHandle&>(object).isAutoconverting()); + return m_webProcessProxy.webPage(static_cast<API::PageHandle&>(object).pageID()); + +#if PLATFORM(COCOA) + case API::Object::Type::ObjCObjectGraph: + return m_webProcessProxy.transformHandlesToObjects(static_cast<ObjCObjectGraph&>(object)); #endif + default: + return &object; + } + } + + WebProcessProxy& m_webProcessProxy; + }; + + return UserData::transform(object, Transformer(*this)); } -void WebProcessProxy::pagePreferencesChanged(WebKit::WebPageProxy *page) +RefPtr<API::Object> WebProcessProxy::transformObjectsToHandles(API::Object* object) { -#if PLATFORM(MAC) - if (page->isProcessSuppressible()) - m_processSuppressiblePages.add(page->pageID()); - else - m_processSuppressiblePages.remove(page->pageID()); - updateProcessSuppressionState(); -#else - UNUSED_PARAM(page); + struct Transformer final : UserData::Transformer { + virtual bool shouldTransformObject(const API::Object& object) const override + { + switch (object.type()) { + case API::Object::Type::Frame: + case API::Object::Type::Page: + case API::Object::Type::PageGroup: +#if PLATFORM(COCOA) + case API::Object::Type::ObjCObjectGraph: #endif + return true; + + default: + return false; + } + } + + virtual RefPtr<API::Object> transformObject(API::Object& object) const override + { + switch (object.type()) { + case API::Object::Type::Frame: + return API::FrameHandle::createAutoconverting(static_cast<const WebFrameProxy&>(object).frameID()); + + case API::Object::Type::Page: + return API::PageHandle::createAutoconverting(static_cast<const WebPageProxy&>(object).pageID()); + + case API::Object::Type::PageGroup: + return API::PageGroupHandle::create(WebPageGroupData(static_cast<const WebPageGroup&>(object).data())); + +#if PLATFORM(COCOA) + case API::Object::Type::ObjCObjectGraph: + return transformObjectsToHandles(static_cast<ObjCObjectGraph&>(object)); +#endif + + default: + return &object; + } + } + }; + + return UserData::transform(object, Transformer()); } -void WebProcessProxy::didSaveToPageCache() +void WebProcessProxy::sendProcessWillSuspendImminently() { - m_context->processDidCachePage(this); + if (!canSendMessage()) + return; + + bool handled = false; + sendSync(Messages::WebProcess::ProcessWillSuspendImminently(), Messages::WebProcess::ProcessWillSuspendImminently::Reply(handled), 0, std::chrono::seconds(1)); } -void WebProcessProxy::releasePageCache() +void WebProcessProxy::sendPrepareToSuspend() { if (canSendMessage()) - send(Messages::WebProcess::ReleasePageCache(), 0); + send(Messages::WebProcess::PrepareToSuspend(), 0); } -void WebProcessProxy::windowServerConnectionStateChanged() +void WebProcessProxy::sendCancelPrepareToSuspend() { - for (const auto& page : m_pageMap.values()) - page->viewStateDidChange(ViewState::IsVisuallyIdle); + if (canSendMessage()) + send(Messages::WebProcess::CancelPrepareToSuspend(), 0); } -void WebProcessProxy::requestTermination() +void WebProcessProxy::sendProcessDidResume() { - if (!isValid()) - return; + if (canSendMessage()) + send(Messages::WebProcess::ProcessDidResume(), 0); +} - ChildProcessProxy::terminate(); +void WebProcessProxy::processReadyToSuspend() +{ + m_throttler.processReadyToSuspend(); +} - if (webConnection()) - webConnection()->didClose(); +void WebProcessProxy::didCancelProcessSuspension() +{ + m_throttler.didCancelProcessSuspension(); +} - disconnect(); +void WebProcessProxy::reinstateNetworkProcessAssertionState(NetworkProcessProxy& newNetworkProcessProxy) +{ +#if PLATFORM(IOS) + ASSERT(!m_backgroundTokenForNetworkProcess || !m_foregroundTokenForNetworkProcess); + + // The network process crashed; take new tokens for the new network process. + if (m_backgroundTokenForNetworkProcess) + m_backgroundTokenForNetworkProcess = newNetworkProcessProxy.throttler().backgroundActivityToken(); + else if (m_foregroundTokenForNetworkProcess) + m_foregroundTokenForNetworkProcess = newNetworkProcessProxy.throttler().foregroundActivityToken(); +#else + UNUSED_PARAM(newNetworkProcessProxy); +#endif } -void WebProcessProxy::enableSuddenTermination() +void WebProcessProxy::didSetAssertionState(AssertionState state) { - if (!isValid()) - return; +#if PLATFORM(IOS) + ASSERT(!m_backgroundTokenForNetworkProcess || !m_foregroundTokenForNetworkProcess); + + switch (state) { + case AssertionState::Suspended: + m_foregroundTokenForNetworkProcess = nullptr; + m_backgroundTokenForNetworkProcess = nullptr; + for (auto& page : m_pageMap.values()) + page->processWillBecomeSuspended(); + break; + + case AssertionState::Background: + m_backgroundTokenForNetworkProcess = processPool().ensureNetworkProcess().throttler().backgroundActivityToken(); + m_foregroundTokenForNetworkProcess = nullptr; + break; + + case AssertionState::Foreground: + m_foregroundTokenForNetworkProcess = processPool().ensureNetworkProcess().throttler().foregroundActivityToken(); + m_backgroundTokenForNetworkProcess = nullptr; + for (auto& page : m_pageMap.values()) + page->processWillBecomeForeground(); + break; + } - ASSERT(m_numberOfTimesSuddenTerminationWasDisabled); - WebCore::enableSuddenTermination(); - --m_numberOfTimesSuddenTerminationWasDisabled; + ASSERT(!m_backgroundTokenForNetworkProcess || !m_foregroundTokenForNetworkProcess); +#else + UNUSED_PARAM(state); +#endif +} + +void WebProcessProxy::setIsHoldingLockedFiles(bool isHoldingLockedFiles) +{ + if (!isHoldingLockedFiles) { + m_tokenForHoldingLockedFiles = nullptr; + return; + } + if (!m_tokenForHoldingLockedFiles) + m_tokenForHoldingLockedFiles = m_throttler.backgroundActivityToken(); } -void WebProcessProxy::disableSuddenTermination() +void WebProcessProxy::isResponsive(std::function<void(bool isWebProcessResponsive)> callback) { - if (!isValid()) + if (m_isResponsive == NoOrMaybe::No) { + if (callback) { + RunLoop::main().dispatch([callback] { + bool isWebProcessResponsive = false; + callback(isWebProcessResponsive); + }); + } return; + } - WebCore::disableSuddenTermination(); - ++m_numberOfTimesSuddenTerminationWasDisabled; + if (callback) + m_isResponsiveCallbacks.append(callback); + + responsivenessTimer().start(); + send(Messages::WebProcess::MainThreadPing(), 0); } -RefPtr<API::Object> WebProcessProxy::apiObjectByConvertingToHandles(API::Object* object) +void WebProcessProxy::didReceiveMainThreadPing() { - return UserData::transform(object, [](const API::Object& object) -> RefPtr<API::Object> { - switch (object.type()) { - case API::Object::Type::Frame: { - auto& frame = static_cast<const WebFrameProxy&>(object); - return API::FrameHandle::create(frame.frameID()); - } + responsivenessTimer().stop(); - default: - return nullptr; - } - }); + auto isResponsiveCallbacks = WTFMove(m_isResponsiveCallbacks); + bool isWebProcessResponsive = true; + for (auto& callback : isResponsiveCallbacks) + callback(isWebProcessResponsive); } } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebProcessProxy.h b/Source/WebKit2/UIProcess/WebProcessProxy.h index a6d872241..c57449885 100644 --- a/Source/WebKit2/UIProcess/WebProcessProxy.h +++ b/Source/WebKit2/UIProcess/WebProcessProxy.h @@ -28,44 +28,48 @@ #include "APISession.h" #include "ChildProcessProxy.h" +#include "CustomProtocolManagerProxy.h" #include "MessageReceiverMap.h" -#include "PlatformProcessIdentifier.h" #include "PluginInfoStore.h" #include "ProcessLauncher.h" +#include "ProcessThrottlerClient.h" #include "ResponsivenessTimer.h" #include "WebConnectionToWebProcess.h" #include "WebPageProxy.h" #include "WebProcessProxyMessages.h" +#include "WebsiteDataTypes.h" #include <WebCore/LinkHash.h> +#include <memory> #include <wtf/Forward.h> #include <wtf/HashMap.h> #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> -#if ENABLE(CUSTOM_PROTOCOLS) -#include "CustomProtocolManagerProxy.h" +#if PLATFORM(IOS) +#include "ProcessThrottler.h" #endif namespace WebCore { +class ResourceRequest; class URL; struct PluginInfo; }; namespace WebKit { -class DownloadProxyMap; +class NetworkProcessProxy; class WebBackForwardListItem; -class WebContext; class WebPageGroup; +class WebProcessPool; struct WebNavigationDataStore; - -class WebProcessProxy : public ChildProcessProxy, ResponsivenessTimer::Client { + +class WebProcessProxy : public ChildProcessProxy, ResponsivenessTimer::Client, private ProcessThrottlerClient { public: typedef HashMap<uint64_t, RefPtr<WebBackForwardListItem>> WebBackForwardListItemMap; typedef HashMap<uint64_t, RefPtr<WebFrameProxy>> WebFrameProxyMap; typedef HashMap<uint64_t, WebPageProxy*> WebPageProxyMap; - static PassRefPtr<WebProcessProxy> create(WebContext&); + static Ref<WebProcessProxy> create(WebProcessPool&); ~WebProcessProxy(); static WebProcessProxy* fromConnection(IPC::Connection* connection) @@ -75,17 +79,24 @@ public: WebConnection* webConnection() const { return m_webConnection.get(); } - WebContext& context() { return m_context.get(); } + WebProcessPool& processPool() { return m_processPool; } static WebPageProxy* webPage(uint64_t pageID); - PassRefPtr<WebPageProxy> createWebPage(PageClient&, const WebPageConfiguration&); + Ref<WebPageProxy> createWebPage(PageClient&, Ref<API::PageConfiguration>&&); void addExistingWebPage(WebPageProxy*, uint64_t pageID); void removeWebPage(uint64_t pageID); - Vector<WebPageProxy*> pages() const; + + WTF::IteratorRange<WebPageProxyMap::const_iterator::Values> pages() const { return m_pageMap.values(); } + unsigned pageCount() const { return m_pageMap.size(); } + + void addVisitedLinkStore(VisitedLinkStore&); + void addWebUserContentControllerProxy(WebUserContentControllerProxy&); + void didDestroyVisitedLinkStore(VisitedLinkStore&); + void didDestroyWebUserContentControllerProxy(WebUserContentControllerProxy&); WebBackForwardListItem* webBackForwardItem(uint64_t itemID) const; - ResponsivenessTimer* responsivenessTimer() { return &m_responsivenessTimer; } + ResponsivenessTimer& responsivenessTimer() { return m_responsivenessTimer; } WebFrameProxy* webFrame(uint64_t) const; bool canCreateFrame(uint64_t frameID) const; @@ -96,6 +107,7 @@ public: void updateTextCheckerState(); void registerNewWebBackForwardListItem(WebBackForwardListItem*); + void removeBackForwardItem(uint64_t); void willAcquireUniversalFileReadSandboxExtension() { m_mayHaveUniversalFileReadSandboxExtension = true; } void assumeReadAccessToBaseURL(const String&); @@ -106,47 +118,63 @@ public: static bool fullKeyboardAccessEnabled(); - DownloadProxy* createDownloadProxy(); - - void pageSuppressibilityChanged(WebPageProxy*); - void pagePreferencesChanged(WebPageProxy*); - void didSaveToPageCache(); void releasePageCache(); -#if PLATFORM(MAC) - bool allPagesAreProcessSuppressible() const; - void updateProcessSuppressionState(); -#endif + void fetchWebsiteData(WebCore::SessionID, WebsiteDataTypes, std::function<void (WebsiteData)> completionHandler); + void deleteWebsiteData(WebCore::SessionID, WebsiteDataTypes, std::chrono::system_clock::time_point modifiedSince, std::function<void ()> completionHandler); + void deleteWebsiteDataForOrigins(WebCore::SessionID, WebsiteDataTypes, const Vector<RefPtr<WebCore::SecurityOrigin>>& origins, std::function<void ()> completionHandler); void enableSuddenTermination(); void disableSuddenTermination(); + bool isSuddenTerminationEnabled() { return !m_numberOfTimesSuddenTerminationWasDisabled; } void requestTermination(); - RefPtr<API::Object> apiObjectByConvertingToHandles(API::Object*); + RefPtr<API::Object> transformHandlesToObjects(API::Object*); + static RefPtr<API::Object> transformObjectsToHandles(API::Object*); + +#if PLATFORM(COCOA) + RefPtr<ObjCObjectGraph> transformHandlesToObjects(ObjCObjectGraph&); + static RefPtr<ObjCObjectGraph> transformObjectsToHandles(ObjCObjectGraph&); +#endif void windowServerConnectionStateChanged(); + void processReadyToSuspend(); + void didCancelProcessSuspension(); + + void setIsHoldingLockedFiles(bool); + + ProcessThrottler& throttler() { return m_throttler; } + + void reinstateNetworkProcessAssertionState(NetworkProcessProxy&); + + void isResponsive(std::function<void(bool isWebProcessResponsive)>); + void didReceiveMainThreadPing(); + private: - explicit WebProcessProxy(WebContext&); + explicit WebProcessProxy(WebProcessPool&); // From ChildProcessProxy virtual void getLaunchOptions(ProcessLauncher::LaunchOptions&) override; - void platformGetLaunchOptions(ProcessLauncher::LaunchOptions&); - virtual void connectionWillOpen(IPC::Connection*) override; - virtual void connectionWillClose(IPC::Connection*) override; + virtual void connectionWillOpen(IPC::Connection&) override; + virtual void processWillShutDown(IPC::Connection&) override; // Called when the web process has crashed or we know that it will terminate soon. // Will potentially cause the WebProcessProxy object to be freed. - void disconnect(); + void shutDown(); // IPC message handlers. - void addBackForwardItem(uint64_t itemID, const String& originalURLString, const String& urlString, const String& title, const IPC::DataReference& backForwardData); + void addBackForwardItem(uint64_t itemID, uint64_t pageID, const PageState&); void didDestroyFrame(uint64_t); void shouldTerminate(bool& shouldTerminate); + void didFetchWebsiteData(uint64_t callbackID, const WebsiteData&); + void didDeleteWebsiteData(uint64_t callbackID); + void didDeleteWebsiteDataForOrigins(uint64_t callbackID); + // Plugins #if ENABLE(NETSCAPE_PLUGIN_API) void getPlugins(bool refresh, Vector<WebCore::PluginInfo>& plugins, Vector<WebCore::PluginInfo>& applicationPlugins); @@ -154,44 +182,50 @@ private: #if ENABLE(NETSCAPE_PLUGIN_API) void getPluginProcessConnection(uint64_t pluginProcessToken, PassRefPtr<Messages::WebProcessProxy::GetPluginProcessConnection::DelayedReply>); #endif -#if ENABLE(NETWORK_PROCESS) void getNetworkProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply>); -#endif #if ENABLE(DATABASE_PROCESS) void getDatabaseProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetDatabaseProcessConnection::DelayedReply>); #endif + void retainIconForPageURL(const String& pageURL); + void releaseIconForPageURL(const String& pageURL); + void releaseRemainingIconsForPageURLs(); + // IPC::Connection::Client friend class WebConnectionToWebProcess; - virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; - virtual void didReceiveSyncMessage(IPC::Connection*, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override; - virtual void didClose(IPC::Connection*) override; - virtual void didReceiveInvalidMessage(IPC::Connection*, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override; + virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override; + virtual void didReceiveSyncMessage(IPC::Connection&, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override; + virtual void didClose(IPC::Connection&) override; + virtual void didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override; + virtual IPC::ProcessType localProcessType() override { return IPC::ProcessType::UI; } + virtual IPC::ProcessType remoteProcessType() override { return IPC::ProcessType::Web; } // ResponsivenessTimer::Client - void didBecomeUnresponsive(ResponsivenessTimer*) override; - void interactionOccurredWhileUnresponsive(ResponsivenessTimer*) override; - void didBecomeResponsive(ResponsivenessTimer*) override; + void didBecomeUnresponsive() override; + void didBecomeResponsive() override; + virtual void willChangeIsResponsive() override; + virtual void didChangeIsResponsive() override; + + // ProcessThrottlerClient + void sendProcessWillSuspendImminently() override; + void sendPrepareToSuspend() override; + void sendCancelPrepareToSuspend() override; + void sendProcessDidResume() override; + void didSetAssertionState(AssertionState) override; // ProcessLauncher::Client virtual void didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier) override; - // History client - void didNavigateWithNavigationData(uint64_t pageID, const WebNavigationDataStore&, uint64_t frameID); - void didPerformClientRedirect(uint64_t pageID, const String& sourceURLString, const String& destinationURLString, uint64_t frameID); - void didPerformServerRedirect(uint64_t pageID, const String& sourceURLString, const String& destinationURLString, uint64_t frameID); - void didUpdateHistoryTitle(uint64_t pageID, const String& title, const String& url, uint64_t frameID); - // Implemented in generated WebProcessProxyMessageReceiver.cpp - void didReceiveWebProcessProxyMessage(IPC::Connection*, IPC::MessageDecoder&); - void didReceiveSyncWebProcessProxyMessage(IPC::Connection*, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&); + void didReceiveWebProcessProxyMessage(IPC::Connection&, IPC::MessageDecoder&); + void didReceiveSyncWebProcessProxyMessage(IPC::Connection&, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&); bool canTerminateChildProcess(); ResponsivenessTimer m_responsivenessTimer; RefPtr<WebConnectionToWebProcess> m_webConnection; - Ref<WebContext> m_context; + Ref<WebProcessPool> m_processPool; bool m_mayHaveUniversalFileReadSandboxExtension; // True if a read extension for "/" was ever granted - we don't track whether WebProcess still has it. HashSet<String> m_localPathsWithAssumedReadAccess; @@ -200,20 +234,29 @@ private: WebFrameProxyMap m_frameMap; WebBackForwardListItemMap m_backForwardListItemMap; - OwnPtr<DownloadProxyMap> m_downloadProxyMap; + HashSet<VisitedLinkStore*> m_visitedLinkStores; + HashSet<WebUserContentControllerProxy*> m_webUserContentControllerProxies; -#if ENABLE(CUSTOM_PROTOCOLS) CustomProtocolManagerProxy m_customProtocolManagerProxy; -#endif -#if PLATFORM(MAC) - HashSet<uint64_t> m_processSuppressiblePages; - bool m_processSuppressionEnabled; -#endif + HashMap<uint64_t, std::function<void (WebsiteData)>> m_pendingFetchWebsiteDataCallbacks; + HashMap<uint64_t, std::function<void ()>> m_pendingDeleteWebsiteDataCallbacks; + HashMap<uint64_t, std::function<void ()>> m_pendingDeleteWebsiteDataForOriginsCallbacks; int m_numberOfTimesSuddenTerminationWasDisabled; + ProcessThrottler m_throttler; + ProcessThrottler::BackgroundActivityToken m_tokenForHoldingLockedFiles; +#if PLATFORM(IOS) + ProcessThrottler::ForegroundActivityToken m_foregroundTokenForNetworkProcess; + ProcessThrottler::BackgroundActivityToken m_backgroundTokenForNetworkProcess; +#endif + + HashMap<String, uint64_t> m_pageURLRetainCountMap; + + enum class NoOrMaybe { No, Maybe } m_isResponsive; + Vector<std::function<void(bool webProcessIsResponsive)>> m_isResponsiveCallbacks; }; - + } // namespace WebKit #endif // WebProcessProxy_h diff --git a/Source/WebKit2/UIProcess/WebProcessProxy.messages.in b/Source/WebKit2/UIProcess/WebProcessProxy.messages.in index 9d49736b8..3fa636273 100644 --- a/Source/WebKit2/UIProcess/WebProcessProxy.messages.in +++ b/Source/WebKit2/UIProcess/WebProcessProxy.messages.in @@ -21,14 +21,7 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. messages -> WebProcessProxy LegacyReceiver { - - # History client messages. - DidNavigateWithNavigationData(uint64_t pageID, WebKit::WebNavigationDataStore store, uint64_t frameID) - DidPerformClientRedirect(uint64_t pageID, String sourceURLString, String destinationURLString, uint64_t frameID) - DidPerformServerRedirect(uint64_t pageID, String sourceURLString, String destinationURLString, uint64_t frameID) - DidUpdateHistoryTitle(uint64_t pageID, String title, String url, uint64_t frameID) - - AddBackForwardItem(uint64_t itemID, String originalURL, String url, String title, IPC::DataReference backForwardData) + AddBackForwardItem(uint64_t itemID, uint64_t pageID, struct WebKit::PageState pageState) DidDestroyFrame(uint64_t frameID) ShouldTerminate() -> (bool shouldTerminate) @@ -36,15 +29,26 @@ messages -> WebProcessProxy LegacyReceiver { EnableSuddenTermination() DisableSuddenTermination() + DidFetchWebsiteData(uint64_t callbackID, struct WebKit::WebsiteData websiteData) + DidDeleteWebsiteData(uint64_t callbackID) + DidDeleteWebsiteDataForOrigins(uint64_t callbackID) + # Plugin messages. #if ENABLE(NETSCAPE_PLUGIN_API) GetPlugins(bool refresh) -> (Vector<WebCore::PluginInfo> plugins, Vector<WebCore::PluginInfo> applicationPlugins) GetPluginProcessConnection(uint64_t pluginProcessToken) -> (IPC::Attachment connectionHandle, bool supportsAsynchronousInitialization) Delayed #endif -#if ENABLE(NETWORK_PROCESS) GetNetworkProcessConnection() -> (IPC::Attachment connectionHandle) Delayed -#endif #if ENABLE(DATABASE_PROCESS) GetDatabaseProcessConnection() -> (IPC::Attachment connectionHandle) Delayed #endif + ProcessReadyToSuspend() + DidCancelProcessSuspension() + + SetIsHoldingLockedFiles(bool isHoldingLockedFiles) + + RetainIconForPageURL(String pageURL) + ReleaseIconForPageURL(String pageURL) + + DidReceiveMainThreadPing() } diff --git a/Source/WebKit2/UIProcess/WebResourceCacheManagerProxy.cpp b/Source/WebKit2/UIProcess/WebResourceCacheManagerProxy.cpp deleted file mode 100644 index 7691812fd..000000000 --- a/Source/WebKit2/UIProcess/WebResourceCacheManagerProxy.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (C) 2011, 2013 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "WebResourceCacheManagerProxy.h" - -#include "ImmutableDictionary.h" -#include "SecurityOriginData.h" -#include "WebContext.h" -#include "WebResourceCacheManagerMessages.h" -#include "WebResourceCacheManagerProxyMessages.h" -#include "WebSecurityOrigin.h" - -#if ENABLE(NETWORK_PROCESS) -#include "NetworkProcessMessages.h" -#endif - -using namespace WebCore; - -namespace WebKit { - -const char* WebResourceCacheManagerProxy::supplementName() -{ - return "WebResourceCacheManagerProxy"; -} - -PassRefPtr<WebResourceCacheManagerProxy> WebResourceCacheManagerProxy::create(WebContext* webContext) -{ - return adoptRef(new WebResourceCacheManagerProxy(webContext)); -} - -WebResourceCacheManagerProxy::WebResourceCacheManagerProxy(WebContext* webContext) - : WebContextSupplement(webContext) -{ - WebContextSupplement::context()->addMessageReceiver(Messages::WebResourceCacheManagerProxy::messageReceiverName(), *this); -} - -WebResourceCacheManagerProxy::~WebResourceCacheManagerProxy() -{ -} - -// WebContextSupplement - -void WebResourceCacheManagerProxy::contextDestroyed() -{ - invalidateCallbackMap(m_arrayCallbacks); -} - -void WebResourceCacheManagerProxy::processDidClose(WebProcessProxy*) -{ - invalidateCallbackMap(m_arrayCallbacks); -} - -bool WebResourceCacheManagerProxy::shouldTerminate(WebProcessProxy*) const -{ - return m_arrayCallbacks.isEmpty(); -} - -void WebResourceCacheManagerProxy::refWebContextSupplement() -{ - API::Object::ref(); -} - -void WebResourceCacheManagerProxy::derefWebContextSupplement() -{ - API::Object::deref(); -} - -void WebResourceCacheManagerProxy::getCacheOrigins(PassRefPtr<ArrayCallback> prpCallback) -{ - RefPtr<ArrayCallback> callback = prpCallback; - uint64_t callbackID = callback->callbackID(); - m_arrayCallbacks.set(callbackID, callback.release()); - - // FIXME (Multi-WebProcess): <rdar://problem/12239765> When multi-process is enabled, we need to aggregate the callback data from all processes. - context()->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebResourceCacheManager::GetCacheOrigins(callbackID)); -} - -void WebResourceCacheManagerProxy::didGetCacheOrigins(const Vector<SecurityOriginData>& origins, uint64_t callbackID) -{ - RefPtr<ArrayCallback> callback = m_arrayCallbacks.take(callbackID); - performAPICallbackWithSecurityOriginDataVector(origins, callback.get()); -} - -void WebResourceCacheManagerProxy::clearCacheForOrigin(WebSecurityOrigin* origin, ResourceCachesToClear cachesToClear) -{ - SecurityOriginData securityOrigin; - securityOrigin.protocol = origin->protocol(); - securityOrigin.host = origin->host(); - securityOrigin.port = origin->port(); - - // FIXME (Multi-WebProcess): <rdar://problem/12239765> There is no need to relaunch all processes. One process to take care of persistent cache is enough. - context()->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebResourceCacheManager::ClearCacheForOrigin(securityOrigin, cachesToClear)); -} - -void WebResourceCacheManagerProxy::clearCacheForAllOrigins(ResourceCachesToClear cachesToClear) -{ -#if ENABLE(NETWORK_PROCESS) - context()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::NetworkProcess::ClearCacheForAllOrigins(cachesToClear)); -#endif - - // FIXME (Multi-WebProcess): <rdar://problem/12239765> There is no need to relaunch all processes. One process to take care of persistent cache is enough. - context()->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebResourceCacheManager::ClearCacheForAllOrigins(cachesToClear)); -} - -} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebResourceCacheManagerProxy.h b/Source/WebKit2/UIProcess/WebResourceCacheManagerProxy.h deleted file mode 100644 index e3f520a91..000000000 --- a/Source/WebKit2/UIProcess/WebResourceCacheManagerProxy.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2011, 2013 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef WebResourceCacheManagerProxy_h -#define WebResourceCacheManagerProxy_h - -#include "APIObject.h" -#include "Arguments.h" -#include "GenericCallback.h" -#include "MessageReceiver.h" -#include "ResourceCachesToClear.h" -#include "WebContextSupplement.h" -#include <wtf/HashMap.h> -#include <wtf/PassRefPtr.h> - -namespace WebKit { - -struct SecurityOriginData; -class WebContext; -class WebProcessProxy; -class WebSecurityOrigin; - -typedef GenericCallback<WKArrayRef> ArrayCallback; - -class WebResourceCacheManagerProxy : public API::ObjectImpl<API::Object::Type::CacheManager>, public WebContextSupplement, private IPC::MessageReceiver { -public: - static const char* supplementName(); - - static PassRefPtr<WebResourceCacheManagerProxy> create(WebContext*); - virtual ~WebResourceCacheManagerProxy(); - - void getCacheOrigins(PassRefPtr<ArrayCallback>); - void clearCacheForOrigin(WebSecurityOrigin*, ResourceCachesToClear); - void clearCacheForAllOrigins(ResourceCachesToClear); - - using API::Object::ref; - using API::Object::deref; - -private: - explicit WebResourceCacheManagerProxy(WebContext*); - - // WebContextSupplement - virtual void contextDestroyed() override; - virtual void processDidClose(WebProcessProxy*) override; - virtual bool shouldTerminate(WebProcessProxy*) const override; - virtual void refWebContextSupplement() override; - virtual void derefWebContextSupplement() override; - - // IPC::MessageReceiver - virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; - - // Message handlers. - void didGetCacheOrigins(const Vector<SecurityOriginData>& originIdentifiers, uint64_t callbackID); - - HashMap<uint64_t, RefPtr<ArrayCallback>> m_arrayCallbacks; -}; - -} // namespace WebKit - -#endif // DatabaseManagerProxy_h diff --git a/Source/WebKit2/UIProcess/WebResourceCacheManagerProxy.messages.in b/Source/WebKit2/UIProcess/WebResourceCacheManagerProxy.messages.in deleted file mode 100644 index c1e73a9af..000000000 --- a/Source/WebKit2/UIProcess/WebResourceCacheManagerProxy.messages.in +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright (C) 2011 Apple Inc. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR -# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -messages -> WebResourceCacheManagerProxy { - DidGetCacheOrigins(Vector<WebKit::SecurityOriginData> originIdentifiers, uint64_t callbackID) -} diff --git a/Source/WebKit2/UIProcess/WebTextChecker.cpp b/Source/WebKit2/UIProcess/WebTextChecker.cpp index 934c58941..8a85434ea 100644 --- a/Source/WebKit2/UIProcess/WebTextChecker.cpp +++ b/Source/WebKit2/UIProcess/WebTextChecker.cpp @@ -28,12 +28,12 @@ #include "TextChecker.h" #include "WKAPICast.h" -#include "WebContext.h" +#include "WebProcessPool.h" #include <wtf/RefPtr.h> namespace WebKit { -WebTextChecker* WebTextChecker::shared() +WebTextChecker* WebTextChecker::singleton() { static WebTextChecker* textChecker = adoptRef(new WebTextChecker).leakRef(); return textChecker; @@ -50,7 +50,7 @@ void WebTextChecker::setClient(const WKTextCheckerClientBase* client) static void updateStateForAllContexts() { - const Vector<WebContext*>& contexts = WebContext::allContexts(); + const Vector<WebProcessPool*>& contexts = WebProcessPool::allProcessPools(); for (size_t i = 0; i < contexts.size(); ++i) contexts[i]->textCheckerStateChanged(); } diff --git a/Source/WebKit2/UIProcess/WebTextChecker.h b/Source/WebKit2/UIProcess/WebTextChecker.h index 359e81ee5..7c945c726 100644 --- a/Source/WebKit2/UIProcess/WebTextChecker.h +++ b/Source/WebKit2/UIProcess/WebTextChecker.h @@ -37,7 +37,7 @@ class WebPageProxy; class WebTextChecker : public API::ObjectImpl<API::Object::Type::TextChecker> { public: - static WebTextChecker* shared(); + static WebTextChecker* singleton(); void setClient(const WKTextCheckerClientBase*); WebTextCheckerClient& client() { return m_client; } diff --git a/Source/WebKit2/UIProcess/WebUIClient.cpp b/Source/WebKit2/UIProcess/WebUIClient.cpp deleted file mode 100644 index 513889c3f..000000000 --- a/Source/WebKit2/UIProcess/WebUIClient.cpp +++ /dev/null @@ -1,459 +0,0 @@ -/* - * Copyright (C) 2010, 2011 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "WebUIClient.h" - -#include "APINumber.h" -#include "ImmutableDictionary.h" -#include "NativeWebKeyboardEvent.h" -#include "NativeWebWheelEvent.h" -#include "NotificationPermissionRequest.h" -#include "PluginInformation.h" -#include "WKAPICast.h" -#include "WebColorPickerResultListenerProxy.h" -#include "WebOpenPanelResultListenerProxy.h" -#include "WebPageProxy.h" -#include <WebCore/FloatRect.h> -#include <WebCore/IntSize.h> -#include <WebCore/WindowFeatures.h> -#include <string.h> -#include <wtf/text/WTFString.h> - -using namespace WebCore; - -namespace WebKit { - -PassRefPtr<WebPageProxy> WebUIClient::createNewPage(WebPageProxy* page, const ResourceRequest& resourceRequest, const WindowFeatures& windowFeatures, WebEvent::Modifiers modifiers, WebMouseEvent::Button button) -{ - if (!m_client.base.version && !m_client.createNewPage_deprecatedForUseWithV0) - return 0; - - if (m_client.base.version > 0 && !m_client.createNewPage) - return 0; - - ImmutableDictionary::MapType map; - if (windowFeatures.xSet) - map.set("x", API::Double::create(windowFeatures.x)); - if (windowFeatures.ySet) - map.set("y", API::Double::create(windowFeatures.y)); - if (windowFeatures.widthSet) - map.set("width", API::Double::create(windowFeatures.width)); - if (windowFeatures.heightSet) - map.set("height", API::Double::create(windowFeatures.height)); - map.set("menuBarVisible", API::Boolean::create(windowFeatures.menuBarVisible)); - map.set("statusBarVisible", API::Boolean::create(windowFeatures.statusBarVisible)); - map.set("toolBarVisible", API::Boolean::create(windowFeatures.toolBarVisible)); - map.set("locationBarVisible", API::Boolean::create(windowFeatures.locationBarVisible)); - map.set("scrollbarsVisible", API::Boolean::create(windowFeatures.scrollbarsVisible)); - map.set("resizable", API::Boolean::create(windowFeatures.resizable)); - map.set("fullscreen", API::Boolean::create(windowFeatures.fullscreen)); - map.set("dialog", API::Boolean::create(windowFeatures.dialog)); - RefPtr<ImmutableDictionary> featuresMap = ImmutableDictionary::create(std::move(map)); - - if (!m_client.base.version) - return adoptRef(toImpl(m_client.createNewPage_deprecatedForUseWithV0(toAPI(page), toAPI(featuresMap.get()), toAPI(modifiers), toAPI(button), m_client.base.clientInfo))); - - RefPtr<API::URLRequest> request = API::URLRequest::create(resourceRequest); - return adoptRef(toImpl(m_client.createNewPage(toAPI(page), toAPI(request.get()), toAPI(featuresMap.get()), toAPI(modifiers), toAPI(button), m_client.base.clientInfo))); -} - -void WebUIClient::showPage(WebPageProxy* page) -{ - if (!m_client.showPage) - return; - - m_client.showPage(toAPI(page), m_client.base.clientInfo); -} - -void WebUIClient::close(WebPageProxy* page) -{ - if (!m_client.close) - return; - - m_client.close(toAPI(page), m_client.base.clientInfo); -} - -void WebUIClient::takeFocus(WebPageProxy* page, WKFocusDirection direction) -{ - if (!m_client.takeFocus) - return; - - m_client.takeFocus(toAPI(page), direction, m_client.base.clientInfo); -} - -void WebUIClient::focus(WebPageProxy* page) -{ - if (!m_client.focus) - return; - - m_client.focus(toAPI(page), m_client.base.clientInfo); -} - -void WebUIClient::unfocus(WebPageProxy* page) -{ - if (!m_client.unfocus) - return; - - m_client.unfocus(toAPI(page), m_client.base.clientInfo); -} - -void WebUIClient::runJavaScriptAlert(WebPageProxy* page, const String& message, WebFrameProxy* frame) -{ - if (!m_client.runJavaScriptAlert) - return; - - m_client.runJavaScriptAlert(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo); -} - -bool WebUIClient::runJavaScriptConfirm(WebPageProxy* page, const String& message, WebFrameProxy* frame) -{ - if (!m_client.runJavaScriptConfirm) - return false; - - return m_client.runJavaScriptConfirm(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo); -} - -String WebUIClient::runJavaScriptPrompt(WebPageProxy* page, const String& message, const String& defaultValue, WebFrameProxy* frame) -{ - if (!m_client.runJavaScriptPrompt) - return String(); - - API::String* string = toImpl(m_client.runJavaScriptPrompt(toAPI(page), toAPI(message.impl()), toAPI(defaultValue.impl()), toAPI(frame), m_client.base.clientInfo)); - if (!string) - return String(); - - String result = string->string(); - string->deref(); - - return result; -} - -void WebUIClient::setStatusText(WebPageProxy* page, const String& text) -{ - if (!m_client.setStatusText) - return; - - m_client.setStatusText(toAPI(page), toAPI(text.impl()), m_client.base.clientInfo); -} - -void WebUIClient::mouseDidMoveOverElement(WebPageProxy* page, const WebHitTestResult::Data& data, WebEvent::Modifiers modifiers, API::Object* userData) -{ - if (!m_client.mouseDidMoveOverElement && !m_client.mouseDidMoveOverElement_deprecatedForUseWithV0) - return; - - if (m_client.base.version > 0 && !m_client.mouseDidMoveOverElement) - return; - - if (!m_client.base.version) { - m_client.mouseDidMoveOverElement_deprecatedForUseWithV0(toAPI(page), toAPI(modifiers), toAPI(userData), m_client.base.clientInfo); - return; - } - - RefPtr<WebHitTestResult> webHitTestResult = WebHitTestResult::create(data); - m_client.mouseDidMoveOverElement(toAPI(page), toAPI(webHitTestResult.get()), toAPI(modifiers), toAPI(userData), m_client.base.clientInfo); -} - -#if ENABLE(NETSCAPE_PLUGIN_API) -void WebUIClient::unavailablePluginButtonClicked(WebPageProxy* page, WKPluginUnavailabilityReason pluginUnavailabilityReason, ImmutableDictionary* pluginInformation) -{ - if (pluginUnavailabilityReason == kWKPluginUnavailabilityReasonPluginMissing) { - if (m_client.missingPluginButtonClicked_deprecatedForUseWithV0) - m_client.missingPluginButtonClicked_deprecatedForUseWithV0( - toAPI(page), - toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), - toAPI(pluginInformation->get<API::String>(pluginInformationPluginURLKey())), - toAPI(pluginInformation->get<API::String>(pluginInformationPluginspageAttributeURLKey())), - m_client.base.clientInfo); - } - - if (m_client.unavailablePluginButtonClicked_deprecatedForUseWithV1) - m_client.unavailablePluginButtonClicked_deprecatedForUseWithV1( - toAPI(page), - pluginUnavailabilityReason, - toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), - toAPI(pluginInformation->get<API::String>(pluginInformationPluginURLKey())), - toAPI(pluginInformation->get<API::String>(pluginInformationPluginspageAttributeURLKey())), - m_client.base.clientInfo); - - if (m_client.unavailablePluginButtonClicked) - m_client.unavailablePluginButtonClicked( - toAPI(page), - pluginUnavailabilityReason, - toAPI(pluginInformation), - m_client.base.clientInfo); -} -#endif // ENABLE(NETSCAPE_PLUGIN_API) - -bool WebUIClient::implementsDidNotHandleKeyEvent() const -{ - return m_client.didNotHandleKeyEvent; -} - -void WebUIClient::didNotHandleKeyEvent(WebPageProxy* page, const NativeWebKeyboardEvent& event) -{ - if (!m_client.didNotHandleKeyEvent) - return; - m_client.didNotHandleKeyEvent(toAPI(page), event.nativeEvent(), m_client.base.clientInfo); -} - -bool WebUIClient::implementsDidNotHandleWheelEvent() const -{ - return m_client.didNotHandleWheelEvent; -} - -void WebUIClient::didNotHandleWheelEvent(WebPageProxy* page, const NativeWebWheelEvent& event) -{ - if (!m_client.didNotHandleWheelEvent) - return; - m_client.didNotHandleWheelEvent(toAPI(page), event.nativeEvent(), m_client.base.clientInfo); -} - -bool WebUIClient::toolbarsAreVisible(WebPageProxy* page) -{ - if (!m_client.toolbarsAreVisible) - return true; - return m_client.toolbarsAreVisible(toAPI(page), m_client.base.clientInfo); - -} -void WebUIClient::setToolbarsAreVisible(WebPageProxy* page, bool visible) -{ - if (!m_client.setToolbarsAreVisible) - return; - m_client.setToolbarsAreVisible(toAPI(page), visible, m_client.base.clientInfo); -} - -bool WebUIClient::menuBarIsVisible(WebPageProxy* page) -{ - if (!m_client.menuBarIsVisible) - return true; - return m_client.menuBarIsVisible(toAPI(page), m_client.base.clientInfo); -} - -void WebUIClient::setMenuBarIsVisible(WebPageProxy* page, bool visible) -{ - if (!m_client.setMenuBarIsVisible) - return; - m_client.setMenuBarIsVisible(toAPI(page), visible, m_client.base.clientInfo); -} - -bool WebUIClient::statusBarIsVisible(WebPageProxy* page) -{ - if (!m_client.statusBarIsVisible) - return true; - return m_client.statusBarIsVisible(toAPI(page), m_client.base.clientInfo); -} - -void WebUIClient::setStatusBarIsVisible(WebPageProxy* page, bool visible) -{ - if (!m_client.setStatusBarIsVisible) - return; - m_client.setStatusBarIsVisible(toAPI(page), visible, m_client.base.clientInfo); -} - -bool WebUIClient::isResizable(WebPageProxy* page) -{ - if (!m_client.isResizable) - return true; - return m_client.isResizable(toAPI(page), m_client.base.clientInfo); -} - -void WebUIClient::setIsResizable(WebPageProxy* page, bool resizable) -{ - if (!m_client.setIsResizable) - return; - m_client.setIsResizable(toAPI(page), resizable, m_client.base.clientInfo); -} - -void WebUIClient::setWindowFrame(WebPageProxy* page, const FloatRect& frame) -{ - if (!m_client.setWindowFrame) - return; - - m_client.setWindowFrame(toAPI(page), toAPI(frame), m_client.base.clientInfo); -} - -FloatRect WebUIClient::windowFrame(WebPageProxy* page) -{ - if (!m_client.getWindowFrame) - return FloatRect(); - - return toFloatRect(m_client.getWindowFrame(toAPI(page), m_client.base.clientInfo)); -} - -bool WebUIClient::canRunBeforeUnloadConfirmPanel() const -{ - return m_client.runBeforeUnloadConfirmPanel; -} - -bool WebUIClient::runBeforeUnloadConfirmPanel(WebPageProxy* page, const String& message, WebFrameProxy* frame) -{ - if (!m_client.runBeforeUnloadConfirmPanel) - return true; - - return m_client.runBeforeUnloadConfirmPanel(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo); -} - -void WebUIClient::didDraw(WebPageProxy* page) -{ - if (!m_client.didDraw) - return; - - m_client.didDraw(toAPI(page), m_client.base.clientInfo); -} - -void WebUIClient::pageDidScroll(WebPageProxy* page) -{ - if (!m_client.pageDidScroll) - return; - - m_client.pageDidScroll(toAPI(page), m_client.base.clientInfo); -} - -unsigned long long WebUIClient::exceededDatabaseQuota(WebPageProxy* page, WebFrameProxy* frame, WebSecurityOrigin* origin, const String& databaseName, const String& databaseDisplayName, unsigned long long currentQuota, unsigned long long currentOriginUsage, unsigned long long currentDatabaseUsage, unsigned long long expectedUsage) -{ - if (!m_client.exceededDatabaseQuota) - return currentQuota; - - return m_client.exceededDatabaseQuota(toAPI(page), toAPI(frame), toAPI(origin), toAPI(databaseName.impl()), toAPI(databaseDisplayName.impl()), currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage, m_client.base.clientInfo); -} - -bool WebUIClient::runOpenPanel(WebPageProxy* page, WebFrameProxy* frame, WebOpenPanelParameters* parameters, WebOpenPanelResultListenerProxy* listener) -{ - if (!m_client.runOpenPanel) - return false; - - m_client.runOpenPanel(toAPI(page), toAPI(frame), toAPI(parameters), toAPI(listener), m_client.base.clientInfo); - return true; -} - -bool WebUIClient::decidePolicyForGeolocationPermissionRequest(WebPageProxy* page, WebFrameProxy* frame, WebSecurityOrigin* origin, GeolocationPermissionRequestProxy* permissionRequest) -{ - if (!m_client.decidePolicyForGeolocationPermissionRequest) - return false; - - m_client.decidePolicyForGeolocationPermissionRequest(toAPI(page), toAPI(frame), toAPI(origin), toAPI(permissionRequest), m_client.base.clientInfo); - return true; -} - -bool WebUIClient::decidePolicyForNotificationPermissionRequest(WebPageProxy* page, WebSecurityOrigin* origin, NotificationPermissionRequest* permissionRequest) -{ - if (!m_client.decidePolicyForNotificationPermissionRequest) - return false; - - m_client.decidePolicyForNotificationPermissionRequest(toAPI(page), toAPI(origin), toAPI(permissionRequest), m_client.base.clientInfo); - return true; -} - -float WebUIClient::headerHeight(WebPageProxy* page, WebFrameProxy* frame) -{ - if (!m_client.headerHeight) - return 0; - - return m_client.headerHeight(toAPI(page), toAPI(frame), m_client.base.clientInfo); -} - -float WebUIClient::footerHeight(WebPageProxy* page, WebFrameProxy* frame) -{ - if (!m_client.footerHeight) - return 0; - - return m_client.footerHeight(toAPI(page), toAPI(frame), m_client.base.clientInfo); -} - -void WebUIClient::drawHeader(WebPageProxy* page, WebFrameProxy* frame, const WebCore::FloatRect& rect) -{ - if (!m_client.drawHeader) - return; - - m_client.drawHeader(toAPI(page), toAPI(frame), toAPI(rect), m_client.base.clientInfo); -} - -void WebUIClient::drawFooter(WebPageProxy* page, WebFrameProxy* frame, const WebCore::FloatRect& rect) -{ - if (!m_client.drawFooter) - return; - - m_client.drawFooter(toAPI(page), toAPI(frame), toAPI(rect), m_client.base.clientInfo); -} - -void WebUIClient::printFrame(WebPageProxy* page, WebFrameProxy* frame) -{ - if (!m_client.printFrame) - return; - - m_client.printFrame(toAPI(page), toAPI(frame), m_client.base.clientInfo); -} - -bool WebUIClient::canRunModal() const -{ - return m_client.runModal; -} - -void WebUIClient::runModal(WebPageProxy* page) -{ - if (!m_client.runModal) - return; - - m_client.runModal(toAPI(page), m_client.base.clientInfo); -} - -void WebUIClient::saveDataToFileInDownloadsFolder(WebPageProxy* page, const String& suggestedFilename, const String& mimeType, const String& originatingURLString, API::Data* data) -{ - if (!m_client.saveDataToFileInDownloadsFolder) - return; - - m_client.saveDataToFileInDownloadsFolder(toAPI(page), toAPI(suggestedFilename.impl()), toAPI(mimeType.impl()), toURLRef(originatingURLString.impl()), toAPI(data), m_client.base.clientInfo); -} - -bool WebUIClient::shouldInterruptJavaScript(WebPageProxy* page) -{ - if (!m_client.shouldInterruptJavaScript) - return false; - - return m_client.shouldInterruptJavaScript(toAPI(page), m_client.base.clientInfo); -} - -#if ENABLE(INPUT_TYPE_COLOR) -bool WebUIClient::showColorPicker(WebPageProxy* page, const String& initialColor, WebColorPickerResultListenerProxy* listener) -{ - if (!m_client.showColorPicker) - return false; - - m_client.showColorPicker(toAPI(page), toAPI(initialColor.impl()), toAPI(listener), m_client.base.clientInfo); - return true; -} - -bool WebUIClient::hideColorPicker(WebPageProxy* page) -{ - if (!m_client.hideColorPicker) - return false; - - m_client.hideColorPicker(toAPI(page), m_client.base.clientInfo); - return true; -} -#endif - -} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebUIClient.h b/Source/WebKit2/UIProcess/WebUIClient.h deleted file mode 100644 index 27c6bde49..000000000 --- a/Source/WebKit2/UIProcess/WebUIClient.h +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (C) 2010, 2011 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef WebUIClient_h -#define WebUIClient_h - -#include "APIClient.h" -#include "WKPage.h" -#include "WebEvent.h" -#include "WebHitTestResult.h" -#include "WebOpenPanelParameters.h" -#include <wtf/Forward.h> -#include <wtf/PassRefPtr.h> - -namespace API { -class Data; - -template<> struct ClientTraits<WKPageUIClientBase> { - typedef std::tuple<WKPageUIClientV0, WKPageUIClientV1, WKPageUIClientV2> Versions; -}; -} - -namespace WebCore { - class FloatRect; - class IntSize; - class ResourceRequest; - struct WindowFeatures; -} - -namespace WebKit { - -class GeolocationPermissionRequestProxy; -class ImmutableDictionary; -class NativeWebKeyboardEvent; -class NativeWebWheelEvent; -class NotificationPermissionRequest; -class WebColorPickerResultListenerProxy; -class WebFrameProxy; -class WebPageProxy; -class WebSecurityOrigin; -class WebOpenPanelResultListenerProxy; - -class WebUIClient : public API::Client<WKPageUIClientBase> { -public: - PassRefPtr<WebPageProxy> createNewPage(WebPageProxy*, const WebCore::ResourceRequest&, const WebCore::WindowFeatures&, WebEvent::Modifiers, WebMouseEvent::Button); - void showPage(WebPageProxy*); - void close(WebPageProxy*); - - void takeFocus(WebPageProxy*, WKFocusDirection); - void focus(WebPageProxy*); - void unfocus(WebPageProxy*); - - void runJavaScriptAlert(WebPageProxy*, const String&, WebFrameProxy*); - bool runJavaScriptConfirm(WebPageProxy*, const String&, WebFrameProxy*); - String runJavaScriptPrompt(WebPageProxy*, const String&, const String&, WebFrameProxy*); - - void setStatusText(WebPageProxy*, const String&); - void mouseDidMoveOverElement(WebPageProxy*, const WebHitTestResult::Data&, WebEvent::Modifiers, API::Object*); -#if ENABLE(NETSCAPE_PLUGIN_API) - void unavailablePluginButtonClicked(WebPageProxy*, WKPluginUnavailabilityReason, ImmutableDictionary*); -#endif // ENABLE(NETSCAPE_PLUGIN_API) - - bool implementsDidNotHandleKeyEvent() const; - void didNotHandleKeyEvent(WebPageProxy*, const NativeWebKeyboardEvent&); - - bool implementsDidNotHandleWheelEvent() const; - void didNotHandleWheelEvent(WebPageProxy*, const NativeWebWheelEvent&); - - bool toolbarsAreVisible(WebPageProxy*); - void setToolbarsAreVisible(WebPageProxy*, bool); - bool menuBarIsVisible(WebPageProxy*); - void setMenuBarIsVisible(WebPageProxy*, bool); - bool statusBarIsVisible(WebPageProxy*); - void setStatusBarIsVisible(WebPageProxy*, bool); - bool isResizable(WebPageProxy*); - void setIsResizable(WebPageProxy*, bool); - - void setWindowFrame(WebPageProxy*, const WebCore::FloatRect&); - WebCore::FloatRect windowFrame(WebPageProxy*); - - bool canRunBeforeUnloadConfirmPanel() const; - bool runBeforeUnloadConfirmPanel(WebPageProxy*, const String&, WebFrameProxy*); - - void didDraw(WebPageProxy*); - void pageDidScroll(WebPageProxy*); - - unsigned long long exceededDatabaseQuota(WebPageProxy*, WebFrameProxy*, WebSecurityOrigin*, const String& databaseName, const String& databaseDisplayName, unsigned long long currentQuota, unsigned long long currentOriginUsage, unsigned long long currentDatabaseUsage, unsigned long long expectedUsage); - - bool runOpenPanel(WebPageProxy*, WebFrameProxy*, WebOpenPanelParameters*, WebOpenPanelResultListenerProxy*); - bool decidePolicyForGeolocationPermissionRequest(WebPageProxy*, WebFrameProxy*, WebSecurityOrigin*, GeolocationPermissionRequestProxy*); - bool decidePolicyForNotificationPermissionRequest(WebPageProxy*, WebSecurityOrigin*, NotificationPermissionRequest*); - - // Printing. - float headerHeight(WebPageProxy*, WebFrameProxy*); - float footerHeight(WebPageProxy*, WebFrameProxy*); - void drawHeader(WebPageProxy*, WebFrameProxy*, const WebCore::FloatRect&); - void drawFooter(WebPageProxy*, WebFrameProxy*, const WebCore::FloatRect&); - void printFrame(WebPageProxy*, WebFrameProxy*); - - bool canRunModal() const; - void runModal(WebPageProxy*); - - void saveDataToFileInDownloadsFolder(WebPageProxy*, const String& suggestedFilename, const String& mimeType, const String& originatingURLString, API::Data*); - - bool shouldInterruptJavaScript(WebPageProxy*); - -#if ENABLE(INPUT_TYPE_COLOR) - bool showColorPicker(WebPageProxy*, const String&, WebColorPickerResultListenerProxy*); - bool hideColorPicker(WebPageProxy*); -#endif -}; - -} // namespace WebKit - -#endif // WebUIClient_h diff --git a/Source/WebKit2/UIProcess/WebVibrationProxy.cpp b/Source/WebKit2/UIProcess/WebVibrationProxy.cpp index 282257b03..48d290ce3 100644 --- a/Source/WebKit2/UIProcess/WebVibrationProxy.cpp +++ b/Source/WebKit2/UIProcess/WebVibrationProxy.cpp @@ -28,27 +28,27 @@ #if ENABLE(VIBRATION) -#include "WebContext.h" #include "WebPageProxy.h" +#include "WebProcessPool.h" #include "WebProcessProxy.h" #include "WebVibrationProxyMessages.h" namespace WebKit { -PassRefPtr<WebVibrationProxy> WebVibrationProxy::create(WebPageProxy* page) +Ref<WebVibrationProxy> WebVibrationProxy::create(WebPageProxy* page) { - return adoptRef(new WebVibrationProxy(page)); + return adoptRef(*new WebVibrationProxy(page)); } WebVibrationProxy::WebVibrationProxy(WebPageProxy* page) : m_page(page) { - m_page->process().context().addMessageReceiver(Messages::WebVibrationProxy::messageReceiverName(), m_page->pageID(), *this); + m_page->process().processPool().addMessageReceiver(Messages::WebVibrationProxy::messageReceiverName(), m_page->pageID(), *this); } WebVibrationProxy::~WebVibrationProxy() { - m_page->process().context().removeMessageReceiver(Messages::WebVibrationProxy::messageReceiverName(), m_page->pageID()); + m_page->process().processPool().removeMessageReceiver(Messages::WebVibrationProxy::messageReceiverName(), m_page->pageID()); } void WebVibrationProxy::invalidate() diff --git a/Source/WebKit2/UIProcess/WebVibrationProxy.h b/Source/WebKit2/UIProcess/WebVibrationProxy.h index 5f65be651..7385660d6 100644 --- a/Source/WebKit2/UIProcess/WebVibrationProxy.h +++ b/Source/WebKit2/UIProcess/WebVibrationProxy.h @@ -39,7 +39,7 @@ class WebPageProxy; class WebVibrationProxy : public API::ObjectImpl<API::Object::Type::Vibration>, private IPC::MessageReceiver { public: - static PassRefPtr<WebVibrationProxy> create(WebPageProxy*); + static Ref<WebVibrationProxy> create(WebPageProxy*); virtual ~WebVibrationProxy(); void invalidate(); @@ -50,7 +50,7 @@ private: explicit WebVibrationProxy(WebPageProxy*); // IPC::MessageReceiver - virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; + virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override; void vibrate(uint32_t vibrationTime); void cancelVibration(); diff --git a/Source/WebKit2/UIProcess/WebViewportAttributes.cpp b/Source/WebKit2/UIProcess/WebViewportAttributes.cpp new file mode 100644 index 000000000..64b4a7679 --- /dev/null +++ b/Source/WebKit2/UIProcess/WebViewportAttributes.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2013 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebViewportAttributes.h" + +namespace WebKit { + +WebViewportAttributes::WebViewportAttributes(const WebCore::ViewportAttributes& attributes) + : m_attributes(attributes) +{ +} + +WebViewportAttributes::~WebViewportAttributes() +{ +} + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebViewportAttributes.h b/Source/WebKit2/UIProcess/WebViewportAttributes.h new file mode 100644 index 000000000..a31065fe4 --- /dev/null +++ b/Source/WebKit2/UIProcess/WebViewportAttributes.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2013 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list Viewof conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebViewportAttributes_h +#define WebViewportAttributes_h + +#include "APIObject.h" +#include <WebCore/ViewportArguments.h> +#include <wtf/PassRefPtr.h> + +namespace WebKit { + +class WebViewportAttributes : public API::ObjectImpl<API::Object::Type::ViewportAttributes> { +public: + static Ref<WebViewportAttributes> create(const WebCore::ViewportAttributes& attributes) + { + return adoptRef(*new WebViewportAttributes(attributes)); + } + + virtual ~WebViewportAttributes(); + + const WebCore::ViewportAttributes& originalAttributes() const { return m_attributes; } + +private: + explicit WebViewportAttributes(const WebCore::ViewportAttributes&); + + WebCore::ViewportAttributes m_attributes; +}; + +} // namespace WebKit + +#endif // WebViewportAttributes_h diff --git a/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataRecord.cpp b/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataRecord.cpp new file mode 100644 index 000000000..1aa2c0eb7 --- /dev/null +++ b/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataRecord.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebsiteDataRecord.h" + +#include <WebCore/LocalizedStrings.h> +#include <WebCore/PublicSuffix.h> +#include <WebCore/SecurityOrigin.h> + +#if PLATFORM(COCOA) +#import <WebCore/CFNetworkSPI.h> +#endif + +static String displayNameForLocalFiles() +{ + return WEB_UI_STRING("Local documents on your computer", "'Website' name displayed when local documents have stored local data"); +} + +namespace WebKit { + +String WebsiteDataRecord::displayNameForCookieHostName(const String& hostName) +{ +#if PLATFORM(COCOA) + if (hostName == String(kCFHTTPCookieLocalFileDomain)) + return displayNameForLocalFiles(); +#endif + +#if ENABLE(PUBLIC_SUFFIX_LIST) + return WebCore::topPrivatelyControlledDomain(hostName.startsWith('.') ? hostName.substring(1) : hostName); +#endif + + return String(); +} + +#if ENABLE(NETSCAPE_PLUGIN_API) +String WebsiteDataRecord::displayNameForPluginDataHostName(const String& hostName) +{ +#if ENABLE(PUBLIC_SUFFIX_LIST) + return WebCore::topPrivatelyControlledDomain(hostName); +#endif + + return String(); +} +#endif + +String WebsiteDataRecord::displayNameForOrigin(const WebCore::SecurityOrigin& securityOrigin) +{ + const auto& protocol = securityOrigin.protocol(); + + if (protocol == "file") + return displayNameForLocalFiles(); + +#if ENABLE(PUBLIC_SUFFIX_LIST) + if (protocol == "http" || protocol == "https") + return WebCore::topPrivatelyControlledDomain(securityOrigin.host()); +#endif + + return String(); +} + +void WebsiteDataRecord::add(WebsiteDataTypes type, RefPtr<WebCore::SecurityOrigin>&& origin) +{ + types |= type; + + origins.add(WTFMove(origin)); +} + +void WebsiteDataRecord::addCookieHostName(const String& hostName) +{ + types |= WebsiteDataTypeCookies; + + cookieHostNames.add(hostName); +} + +#if ENABLE(NETSCAPE_PLUGIN_API) +void WebsiteDataRecord::addPluginDataHostName(const String& hostName) +{ + types |= WebsiteDataTypePlugInData; + + pluginDataHostNames.add(hostName); +} +#endif + +} diff --git a/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataRecord.h b/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataRecord.h new file mode 100644 index 000000000..58b3f9184 --- /dev/null +++ b/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataRecord.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebsiteDataRecord_h +#define WebsiteDataRecord_h + +#include "WebsiteDataTypes.h" +#include <WebCore/SecurityOriginHash.h> +#include <wtf/HashSet.h> +#include <wtf/text/StringHash.h> +#include <wtf/text/WTFString.h> + +namespace WebCore { +class SecurityOrigin; +} + +namespace WebKit { + +struct WebsiteDataRecord { + static String displayNameForCookieHostName(const String& hostName); +#if ENABLE(NETSCAPE_PLUGIN_API) + static String displayNameForPluginDataHostName(const String& hostName); +#endif + static String displayNameForOrigin(const WebCore::SecurityOrigin&); + + void add(WebsiteDataTypes, RefPtr<WebCore::SecurityOrigin>&&); + void addCookieHostName(const String& hostName); +#if ENABLE(NETSCAPE_PLUGIN_API) + void addPluginDataHostName(const String& hostName); +#endif + + String displayName; + unsigned types { 0 }; + HashSet<RefPtr<WebCore::SecurityOrigin>> origins; + HashSet<String> cookieHostNames; +#if ENABLE(NETSCAPE_PLUGIN_API) + HashSet<String> pluginDataHostNames; +#endif +}; + +} + +#endif // WebsiteDataRecord_h diff --git a/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp b/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp new file mode 100644 index 000000000..1191e7af3 --- /dev/null +++ b/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp @@ -0,0 +1,1080 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebsiteDataStore.h" + +#include "APIProcessPoolConfiguration.h" +#include "APIWebsiteDataRecord.h" +#include "NetworkProcessMessages.h" +#include "StorageManager.h" +#include "WebProcessPool.h" +#include "WebsiteData.h" +#include <WebCore/ApplicationCacheStorage.h> +#include <WebCore/DatabaseTracker.h> +#include <WebCore/OriginLock.h> +#include <WebCore/SecurityOrigin.h> +#include <wtf/RunLoop.h> + +#if ENABLE(NETSCAPE_PLUGIN_API) +#include "PluginProcessManager.h" +#endif + +namespace WebKit { + +static WebCore::SessionID generateNonPersistentSessionID() +{ + // FIXME: We count backwards here to not conflict with API::Session. + static uint64_t sessionID = std::numeric_limits<uint64_t>::max(); + + return WebCore::SessionID(--sessionID); +} + +static uint64_t generateIdentifier() +{ + static uint64_t identifier; + + return ++identifier; +} + +Ref<WebsiteDataStore> WebsiteDataStore::createNonPersistent() +{ + return adoptRef(*new WebsiteDataStore(generateNonPersistentSessionID())); +} + +Ref<WebsiteDataStore> WebsiteDataStore::create(Configuration configuration) +{ + return adoptRef(*new WebsiteDataStore(WTFMove(configuration))); +} + +WebsiteDataStore::WebsiteDataStore(Configuration configuration) + : m_identifier(generateIdentifier()) + , m_sessionID(WebCore::SessionID::defaultSessionID()) + , m_networkCacheDirectory(WTFMove(configuration.networkCacheDirectory)) + , m_applicationCacheDirectory(WTFMove(configuration.applicationCacheDirectory)) + , m_webSQLDatabaseDirectory(WTFMove(configuration.webSQLDatabaseDirectory)) + , m_mediaKeysStorageDirectory(WTFMove(configuration.mediaKeysStorageDirectory)) + , m_storageManager(StorageManager::create(WTFMove(configuration.localStorageDirectory))) + , m_queue(WorkQueue::create("com.apple.WebKit.WebsiteDataStore")) +{ + platformInitialize(); +} + +WebsiteDataStore::WebsiteDataStore(WebCore::SessionID sessionID) + : m_identifier(generateIdentifier()) + , m_sessionID(sessionID) + , m_queue(WorkQueue::create("com.apple.WebKit.WebsiteDataStore")) +{ + platformInitialize(); +} + +WebsiteDataStore::~WebsiteDataStore() +{ + platformDestroy(); + + if (m_sessionID.isEphemeral()) { + for (auto& processPool : WebProcessPool::allProcessPools()) + processPool->sendToNetworkingProcess(Messages::NetworkProcess::DestroyPrivateBrowsingSession(m_sessionID)); + } +} + +void WebsiteDataStore::cloneSessionData(WebPageProxy& sourcePage, WebPageProxy& newPage) +{ + auto& sourceDataStore = sourcePage.websiteDataStore(); + auto& newDataStore = newPage.websiteDataStore(); + + // FIXME: Handle this. + if (&sourceDataStore != &newDataStore) + return; + + if (!sourceDataStore.m_storageManager) + return; + + sourceDataStore.m_storageManager->cloneSessionStorageNamespace(sourcePage.pageID(), newPage.pageID()); +} + +enum class ProcessAccessType { + None, + OnlyIfLaunched, + Launch, +}; + +static ProcessAccessType computeNetworkProcessAccessTypeForDataFetch(WebsiteDataTypes dataTypes, bool isNonPersistentStore) +{ + ProcessAccessType processAccessType = ProcessAccessType::None; + + if (dataTypes & WebsiteDataTypeCookies) { + if (isNonPersistentStore) + processAccessType = std::max(processAccessType, ProcessAccessType::OnlyIfLaunched); + else + processAccessType = std::max(processAccessType, ProcessAccessType::Launch); + } + + if (dataTypes & WebsiteDataTypeDiskCache && !isNonPersistentStore) + processAccessType = std::max(processAccessType, ProcessAccessType::Launch); + + return processAccessType; +} + +static ProcessAccessType computeWebProcessAccessTypeForDataFetch(WebsiteDataTypes dataTypes, bool isNonPersistentStore) +{ + UNUSED_PARAM(isNonPersistentStore); + + ProcessAccessType processAccessType = ProcessAccessType::None; + + if (dataTypes & WebsiteDataTypeMemoryCache) + return ProcessAccessType::OnlyIfLaunched; + + return processAccessType; +} + +void WebsiteDataStore::fetchData(WebsiteDataTypes dataTypes, std::function<void (Vector<WebsiteDataRecord>)> completionHandler) +{ + struct CallbackAggregator final : ThreadSafeRefCounted<CallbackAggregator> { + explicit CallbackAggregator(std::function<void (Vector<WebsiteDataRecord>)> completionHandler) + : completionHandler(WTFMove(completionHandler)) + { + } + + ~CallbackAggregator() + { + ASSERT(!pendingCallbacks); + } + + void addPendingCallback() + { + pendingCallbacks++; + } + + void removePendingCallback(WebsiteData websiteData) + { + ASSERT(pendingCallbacks); + --pendingCallbacks; + + for (auto& entry : websiteData.entries) { + auto displayName = WebsiteDataRecord::displayNameForOrigin(*entry.origin); + if (!displayName) + continue; + + auto& record = m_websiteDataRecords.add(displayName, WebsiteDataRecord { }).iterator->value; + if (!record.displayName) + record.displayName = WTFMove(displayName); + + record.add(entry.type, WTFMove(entry.origin)); + } + + for (auto& hostName : websiteData.hostNamesWithCookies) { + auto displayName = WebsiteDataRecord::displayNameForCookieHostName(hostName); + if (!displayName) + continue; + + auto& record = m_websiteDataRecords.add(displayName, WebsiteDataRecord { }).iterator->value; + if (!record.displayName) + record.displayName = WTFMove(displayName); + + record.addCookieHostName(hostName); + } + +#if ENABLE(NETSCAPE_PLUGIN_API) + for (auto& hostName : websiteData.hostNamesWithPluginData) { + auto displayName = WebsiteDataRecord::displayNameForPluginDataHostName(hostName); + if (!displayName) + continue; + + auto& record = m_websiteDataRecords.add(displayName, WebsiteDataRecord { }).iterator->value; + if (!record.displayName) + record.displayName = WTFMove(displayName); + + record.addPluginDataHostName(hostName); + } +#endif + + callIfNeeded(); + } + + void callIfNeeded() + { + if (pendingCallbacks) + return; + + RefPtr<CallbackAggregator> callbackAggregator(this); + RunLoop::main().dispatch([callbackAggregator] { + + WTF::Vector<WebsiteDataRecord> records; + records.reserveInitialCapacity(callbackAggregator->m_websiteDataRecords.size()); + + for (auto& record : callbackAggregator->m_websiteDataRecords.values()) + records.uncheckedAppend(WTFMove(record)); + + callbackAggregator->completionHandler(WTFMove(records)); + }); + } + + unsigned pendingCallbacks = 0; + std::function<void (Vector<WebsiteDataRecord>)> completionHandler; + + HashMap<String, WebsiteDataRecord> m_websiteDataRecords; + }; + + RefPtr<CallbackAggregator> callbackAggregator = adoptRef(new CallbackAggregator(WTFMove(completionHandler))); + + auto networkProcessAccessType = computeNetworkProcessAccessTypeForDataFetch(dataTypes, !isPersistent()); + if (networkProcessAccessType != ProcessAccessType::None) { + for (auto& processPool : processPools()) { + switch (networkProcessAccessType) { + case ProcessAccessType::OnlyIfLaunched: + if (!processPool->networkProcess()) + continue; + break; + + case ProcessAccessType::Launch: + processPool->ensureNetworkProcess(); + break; + + case ProcessAccessType::None: + ASSERT_NOT_REACHED(); + } + + callbackAggregator->addPendingCallback(); + processPool->networkProcess()->fetchWebsiteData(m_sessionID, dataTypes, [callbackAggregator, processPool](WebsiteData websiteData) { + callbackAggregator->removePendingCallback(WTFMove(websiteData)); + }); + } + } + + auto webProcessAccessType = computeWebProcessAccessTypeForDataFetch(dataTypes, !isPersistent()); + if (webProcessAccessType != ProcessAccessType::None) { + for (auto& process : processes()) { + switch (webProcessAccessType) { + case ProcessAccessType::OnlyIfLaunched: + if (!process->canSendMessage()) + continue; + break; + + case ProcessAccessType::Launch: + // FIXME: Handle this. + ASSERT_NOT_REACHED(); + break; + + case ProcessAccessType::None: + ASSERT_NOT_REACHED(); + } + + callbackAggregator->addPendingCallback(); + process->fetchWebsiteData(m_sessionID, dataTypes, [callbackAggregator](WebsiteData websiteData) { + callbackAggregator->removePendingCallback(WTFMove(websiteData)); + }); + } + } + + if (dataTypes & WebsiteDataTypeSessionStorage && m_storageManager) { + callbackAggregator->addPendingCallback(); + + m_storageManager->getSessionStorageOrigins([callbackAggregator](HashSet<RefPtr<WebCore::SecurityOrigin>>&& origins) { + WebsiteData websiteData; + + while (!origins.isEmpty()) + websiteData.entries.append(WebsiteData::Entry { origins.takeAny(), WebsiteDataTypeSessionStorage }); + + callbackAggregator->removePendingCallback(WTFMove(websiteData)); + }); + } + + if (dataTypes & WebsiteDataTypeLocalStorage && m_storageManager) { + callbackAggregator->addPendingCallback(); + + m_storageManager->getLocalStorageOrigins([callbackAggregator](HashSet<RefPtr<WebCore::SecurityOrigin>>&& origins) { + WebsiteData websiteData; + + while (!origins.isEmpty()) + websiteData.entries.append(WebsiteData::Entry { origins.takeAny(), WebsiteDataTypeLocalStorage }); + + callbackAggregator->removePendingCallback(WTFMove(websiteData)); + }); + } + + if (dataTypes & WebsiteDataTypeOfflineWebApplicationCache && isPersistent()) { + StringCapture applicationCacheDirectory { m_applicationCacheDirectory }; + + callbackAggregator->addPendingCallback(); + + m_queue->dispatch([applicationCacheDirectory, callbackAggregator] { + auto storage = WebCore::ApplicationCacheStorage::create(applicationCacheDirectory.string(), "ApplicationCache"); + + HashSet<RefPtr<WebCore::SecurityOrigin>> origins; + storage->getOriginsWithCache(origins); + + WTF::RunLoop::main().dispatch([callbackAggregator, origins]() mutable { + WebsiteData websiteData; + + for (auto& origin : origins) + websiteData.entries.append(WebsiteData::Entry { origin, WebsiteDataTypeOfflineWebApplicationCache }); + + callbackAggregator->removePendingCallback(WTFMove(websiteData)); + }); + }); + } + + if (dataTypes & WebsiteDataTypeWebSQLDatabases && isPersistent()) { + StringCapture webSQLDatabaseDirectory { m_webSQLDatabaseDirectory }; + + callbackAggregator->addPendingCallback(); + + m_queue->dispatch([webSQLDatabaseDirectory, callbackAggregator] { + Vector<RefPtr<WebCore::SecurityOrigin>> origins; + WebCore::DatabaseTracker::trackerWithDatabasePath(webSQLDatabaseDirectory.string())->origins(origins); + + RunLoop::main().dispatch([callbackAggregator, origins]() mutable { + WebsiteData websiteData; + for (auto& origin : origins) + websiteData.entries.append(WebsiteData::Entry { WTFMove(origin), WebsiteDataTypeWebSQLDatabases }); + + callbackAggregator->removePendingCallback(WTFMove(websiteData)); + }); + }); + } + +#if ENABLE(DATABASE_PROCESS) + if (dataTypes & WebsiteDataTypeIndexedDBDatabases && isPersistent()) { + for (auto& processPool : processPools()) { + processPool->ensureDatabaseProcess(); + + callbackAggregator->addPendingCallback(); + processPool->databaseProcess()->fetchWebsiteData(m_sessionID, dataTypes, [callbackAggregator, processPool](WebsiteData websiteData) { + callbackAggregator->removePendingCallback(WTFMove(websiteData)); + }); + } + } +#endif + + if (dataTypes & WebsiteDataTypeMediaKeys && isPersistent()) { + StringCapture mediaKeysStorageDirectory { m_mediaKeysStorageDirectory }; + + callbackAggregator->addPendingCallback(); + + m_queue->dispatch([mediaKeysStorageDirectory, callbackAggregator] { + auto origins = mediaKeyOrigins(mediaKeysStorageDirectory.string()); + + RunLoop::main().dispatch([callbackAggregator, origins]() mutable { + WebsiteData websiteData; + for (auto& origin : origins) + websiteData.entries.append(WebsiteData::Entry { WTFMove(origin), WebsiteDataTypeMediaKeys }); + + callbackAggregator->removePendingCallback(WTFMove(websiteData)); + }); + }); + } + +#if ENABLE(NETSCAPE_PLUGIN_API) + if (dataTypes & WebsiteDataTypePlugInData && isPersistent()) { + class State { + public: + static void fetchData(Ref<CallbackAggregator>&& callbackAggregator, Vector<PluginModuleInfo>&& plugins) + { + new State(WTFMove(callbackAggregator), WTFMove(plugins)); + } + + private: + State(Ref<CallbackAggregator>&& callbackAggregator, Vector<PluginModuleInfo>&& plugins) + : m_callbackAggregator(WTFMove(callbackAggregator)) + , m_plugins(WTFMove(plugins)) + { + m_callbackAggregator->addPendingCallback(); + + fetchWebsiteDataForNextPlugin(); + } + + ~State() + { + ASSERT(m_plugins.isEmpty()); + } + + void fetchWebsiteDataForNextPlugin() + { + if (m_plugins.isEmpty()) { + WebsiteData websiteData; + websiteData.hostNamesWithPluginData = WTFMove(m_hostNames); + + m_callbackAggregator->removePendingCallback(WTFMove(websiteData)); + + delete this; + return; + } + + auto plugin = m_plugins.takeLast(); + PluginProcessManager::singleton().fetchWebsiteData(plugin, [this](Vector<String> hostNames) { + for (auto& hostName : hostNames) + m_hostNames.add(WTFMove(hostName)); + fetchWebsiteDataForNextPlugin(); + }); + } + + Ref<CallbackAggregator> m_callbackAggregator; + Vector<PluginModuleInfo> m_plugins; + HashSet<String> m_hostNames; + }; + + State::fetchData(*callbackAggregator, plugins()); + } +#endif + + callbackAggregator->callIfNeeded(); +} + +static ProcessAccessType computeNetworkProcessAccessTypeForDataRemoval(WebsiteDataTypes dataTypes, bool isNonPersistentStore) +{ + ProcessAccessType processAccessType = ProcessAccessType::None; + + if (dataTypes & WebsiteDataTypeCookies) { + if (isNonPersistentStore) + processAccessType = std::max(processAccessType, ProcessAccessType::OnlyIfLaunched); + else + processAccessType = std::max(processAccessType, ProcessAccessType::Launch); + } + + if (dataTypes & WebsiteDataTypeDiskCache && !isNonPersistentStore) + processAccessType = std::max(processAccessType, ProcessAccessType::Launch); + + if (dataTypes & WebsiteDataTypeHSTSCache) + processAccessType = std::max(processAccessType, ProcessAccessType::Launch); + + return processAccessType; +} + +static ProcessAccessType computeWebProcessAccessTypeForDataRemoval(WebsiteDataTypes dataTypes, bool isNonPersistentStore) +{ + UNUSED_PARAM(isNonPersistentStore); + + ProcessAccessType processAccessType = ProcessAccessType::None; + + if (dataTypes & WebsiteDataTypeMemoryCache) + processAccessType = std::max(processAccessType, ProcessAccessType::OnlyIfLaunched); + + return processAccessType; +} + +void WebsiteDataStore::removeData(WebsiteDataTypes dataTypes, std::chrono::system_clock::time_point modifiedSince, std::function<void ()> completionHandler) +{ + struct CallbackAggregator : ThreadSafeRefCounted<CallbackAggregator> { + explicit CallbackAggregator (std::function<void ()> completionHandler) + : completionHandler(WTFMove(completionHandler)) + { + } + + void addPendingCallback() + { + pendingCallbacks++; + } + + void removePendingCallback() + { + ASSERT(pendingCallbacks); + --pendingCallbacks; + + callIfNeeded(); + } + + void callIfNeeded() + { + if (!pendingCallbacks) + RunLoop::main().dispatch(WTFMove(completionHandler)); + } + + unsigned pendingCallbacks = 0; + std::function<void ()> completionHandler; + }; + + RefPtr<CallbackAggregator> callbackAggregator = adoptRef(new CallbackAggregator(WTFMove(completionHandler))); + + auto networkProcessAccessType = computeNetworkProcessAccessTypeForDataRemoval(dataTypes, !isPersistent()); + if (networkProcessAccessType != ProcessAccessType::None) { + for (auto& processPool : processPools()) { + switch (networkProcessAccessType) { + case ProcessAccessType::OnlyIfLaunched: + if (!processPool->networkProcess()) + continue; + break; + + case ProcessAccessType::Launch: + processPool->ensureNetworkProcess(); + break; + + case ProcessAccessType::None: + ASSERT_NOT_REACHED(); + } + + callbackAggregator->addPendingCallback(); + processPool->networkProcess()->deleteWebsiteData(m_sessionID, dataTypes, modifiedSince, [callbackAggregator, processPool] { + callbackAggregator->removePendingCallback(); + }); + } + } + + auto webProcessAccessType = computeWebProcessAccessTypeForDataRemoval(dataTypes, !isPersistent()); + if (webProcessAccessType != ProcessAccessType::None) { + for (auto& process : processes()) { + switch (webProcessAccessType) { + case ProcessAccessType::OnlyIfLaunched: + if (!process->canSendMessage()) + continue; + break; + + case ProcessAccessType::Launch: + // FIXME: Handle this. + ASSERT_NOT_REACHED(); + break; + + case ProcessAccessType::None: + ASSERT_NOT_REACHED(); + } + + callbackAggregator->addPendingCallback(); + process->deleteWebsiteData(m_sessionID, dataTypes, modifiedSince, [callbackAggregator] { + callbackAggregator->removePendingCallback(); + }); + } + } + + if (dataTypes & WebsiteDataTypeSessionStorage && m_storageManager) { + callbackAggregator->addPendingCallback(); + + m_storageManager->deleteSessionStorageOrigins([callbackAggregator] { + callbackAggregator->removePendingCallback(); + }); + } + + if (dataTypes & WebsiteDataTypeLocalStorage && m_storageManager) { + callbackAggregator->addPendingCallback(); + + m_storageManager->deleteLocalStorageOriginsModifiedSince(modifiedSince, [callbackAggregator] { + callbackAggregator->removePendingCallback(); + }); + } + + if (dataTypes & WebsiteDataTypeOfflineWebApplicationCache && isPersistent()) { + StringCapture applicationCacheDirectory { m_applicationCacheDirectory }; + + callbackAggregator->addPendingCallback(); + + m_queue->dispatch([applicationCacheDirectory, callbackAggregator] { + auto storage = WebCore::ApplicationCacheStorage::create(applicationCacheDirectory.string(), "ApplicationCache"); + + storage->deleteAllCaches(); + + WTF::RunLoop::main().dispatch([callbackAggregator] { + callbackAggregator->removePendingCallback(); + }); + }); + } + + if (dataTypes & WebsiteDataTypeWebSQLDatabases && isPersistent()) { + StringCapture webSQLDatabaseDirectory { m_webSQLDatabaseDirectory }; + + callbackAggregator->addPendingCallback(); + + m_queue->dispatch([webSQLDatabaseDirectory, callbackAggregator, modifiedSince] { + WebCore::DatabaseTracker::trackerWithDatabasePath(webSQLDatabaseDirectory.string())->deleteDatabasesModifiedSince(modifiedSince); + + RunLoop::main().dispatch([callbackAggregator] { + callbackAggregator->removePendingCallback(); + }); + }); + } + +#if ENABLE(DATABASE_PROCESS) + if (dataTypes & WebsiteDataTypeIndexedDBDatabases && isPersistent()) { + for (auto& processPool : processPools()) { + processPool->ensureDatabaseProcess(); + + callbackAggregator->addPendingCallback(); + processPool->databaseProcess()->deleteWebsiteData(m_sessionID, dataTypes, modifiedSince, [callbackAggregator, processPool] { + callbackAggregator->removePendingCallback(); + }); + } + } +#endif + + if (dataTypes & WebsiteDataTypeMediaKeys && isPersistent()) { + StringCapture mediaKeysStorageDirectory { m_mediaKeysStorageDirectory }; + + callbackAggregator->addPendingCallback(); + + m_queue->dispatch([mediaKeysStorageDirectory, callbackAggregator, modifiedSince] { + removeMediaKeys(mediaKeysStorageDirectory.string(), modifiedSince); + + RunLoop::main().dispatch([callbackAggregator] { + callbackAggregator->removePendingCallback(); + }); + }); + } + + if (dataTypes & WebsiteDataTypeSearchFieldRecentSearches && isPersistent()) { + callbackAggregator->addPendingCallback(); + + m_queue->dispatch([modifiedSince, callbackAggregator] { + platformRemoveRecentSearches(modifiedSince); + + RunLoop::main().dispatch([callbackAggregator] { + callbackAggregator->removePendingCallback(); + }); + }); + } + +#if ENABLE(NETSCAPE_PLUGIN_API) + if (dataTypes & WebsiteDataTypePlugInData && isPersistent()) { + class State { + public: + static void deleteData(Ref<CallbackAggregator>&& callbackAggregator, Vector<PluginModuleInfo>&& plugins, std::chrono::system_clock::time_point modifiedSince) + { + new State(WTFMove(callbackAggregator), WTFMove(plugins), modifiedSince); + } + + private: + State(Ref<CallbackAggregator>&& callbackAggregator, Vector<PluginModuleInfo>&& plugins, std::chrono::system_clock::time_point modifiedSince) + : m_callbackAggregator(WTFMove(callbackAggregator)) + , m_plugins(WTFMove(plugins)) + , m_modifiedSince(modifiedSince) + { + m_callbackAggregator->addPendingCallback(); + + deleteWebsiteDataForNextPlugin(); + } + + ~State() + { + ASSERT(m_plugins.isEmpty()); + } + + void deleteWebsiteDataForNextPlugin() + { + if (m_plugins.isEmpty()) { + m_callbackAggregator->removePendingCallback(); + + delete this; + return; + } + + auto plugin = m_plugins.takeLast(); + PluginProcessManager::singleton().deleteWebsiteData(plugin, m_modifiedSince, [this] { + deleteWebsiteDataForNextPlugin(); + }); + } + + Ref<CallbackAggregator> m_callbackAggregator; + Vector<PluginModuleInfo> m_plugins; + std::chrono::system_clock::time_point m_modifiedSince; + }; + + State::deleteData(*callbackAggregator, plugins(), modifiedSince); + } +#endif + + // There's a chance that we don't have any pending callbacks. If so, we want to dispatch the completion handler right away. + callbackAggregator->callIfNeeded(); +} + +void WebsiteDataStore::removeData(WebsiteDataTypes dataTypes, const Vector<WebsiteDataRecord>& dataRecords, std::function<void ()> completionHandler) +{ + Vector<RefPtr<WebCore::SecurityOrigin>> origins; + + for (const auto& dataRecord : dataRecords) { + for (auto& origin : dataRecord.origins) + origins.append(origin); + } + + struct CallbackAggregator : ThreadSafeRefCounted<CallbackAggregator> { + explicit CallbackAggregator (std::function<void ()> completionHandler) + : completionHandler(WTFMove(completionHandler)) + { + } + + void addPendingCallback() + { + pendingCallbacks++; + } + + void removePendingCallback() + { + ASSERT(pendingCallbacks); + --pendingCallbacks; + + callIfNeeded(); + } + + void callIfNeeded() + { + if (!pendingCallbacks) + RunLoop::main().dispatch(WTFMove(completionHandler)); + } + + unsigned pendingCallbacks = 0; + std::function<void ()> completionHandler; + }; + + RefPtr<CallbackAggregator> callbackAggregator = adoptRef(new CallbackAggregator(WTFMove(completionHandler))); + + auto networkProcessAccessType = computeNetworkProcessAccessTypeForDataRemoval(dataTypes, !isPersistent()); + if (networkProcessAccessType != ProcessAccessType::None) { + for (auto& processPool : processPools()) { + switch (networkProcessAccessType) { + case ProcessAccessType::OnlyIfLaunched: + if (!processPool->networkProcess()) + continue; + break; + + case ProcessAccessType::Launch: + processPool->ensureNetworkProcess(); + break; + + case ProcessAccessType::None: + ASSERT_NOT_REACHED(); + } + + Vector<String> cookieHostNames; + for (const auto& dataRecord : dataRecords) { + for (auto& hostName : dataRecord.cookieHostNames) + cookieHostNames.append(hostName); + } + + callbackAggregator->addPendingCallback(); + processPool->networkProcess()->deleteWebsiteDataForOrigins(m_sessionID, dataTypes, origins, cookieHostNames, [callbackAggregator, processPool] { + callbackAggregator->removePendingCallback(); + }); + } + } + + auto webProcessAccessType = computeWebProcessAccessTypeForDataRemoval(dataTypes, !isPersistent()); + if (webProcessAccessType != ProcessAccessType::None) { + for (auto& process : processes()) { + switch (webProcessAccessType) { + case ProcessAccessType::OnlyIfLaunched: + if (!process->canSendMessage()) + continue; + break; + + case ProcessAccessType::Launch: + // FIXME: Handle this. + ASSERT_NOT_REACHED(); + break; + + case ProcessAccessType::None: + ASSERT_NOT_REACHED(); + } + + callbackAggregator->addPendingCallback(); + + process->deleteWebsiteDataForOrigins(m_sessionID, dataTypes, origins, [callbackAggregator] { + callbackAggregator->removePendingCallback(); + }); + } + } + + if (dataTypes & WebsiteDataTypeSessionStorage && m_storageManager) { + callbackAggregator->addPendingCallback(); + + m_storageManager->deleteSessionStorageEntriesForOrigins(origins, [callbackAggregator] { + callbackAggregator->removePendingCallback(); + }); + } + + if (dataTypes & WebsiteDataTypeLocalStorage && m_storageManager) { + callbackAggregator->addPendingCallback(); + + m_storageManager->deleteLocalStorageEntriesForOrigins(origins, [callbackAggregator] { + callbackAggregator->removePendingCallback(); + }); + } + + if (dataTypes & WebsiteDataTypeOfflineWebApplicationCache && isPersistent()) { + StringCapture applicationCacheDirectory { m_applicationCacheDirectory }; + + HashSet<RefPtr<WebCore::SecurityOrigin>> origins; + for (const auto& dataRecord : dataRecords) { + for (const auto& origin : dataRecord.origins) + origins.add(origin); + } + + callbackAggregator->addPendingCallback(); + m_queue->dispatch([origins, applicationCacheDirectory, callbackAggregator] { + auto storage = WebCore::ApplicationCacheStorage::create(applicationCacheDirectory.string(), "ApplicationCache"); + + for (const auto& origin : origins) + storage->deleteCacheForOrigin(*origin); + + WTF::RunLoop::main().dispatch([callbackAggregator] { + callbackAggregator->removePendingCallback(); + }); + }); + } + + if (dataTypes & WebsiteDataTypeWebSQLDatabases && isPersistent()) { + StringCapture webSQLDatabaseDirectory { m_webSQLDatabaseDirectory }; + + HashSet<RefPtr<WebCore::SecurityOrigin>> origins; + for (const auto& dataRecord : dataRecords) { + for (const auto& origin : dataRecord.origins) + origins.add(origin); + } + + callbackAggregator->addPendingCallback(); + m_queue->dispatch([origins, callbackAggregator, webSQLDatabaseDirectory] { + auto databaseTracker = WebCore::DatabaseTracker::trackerWithDatabasePath(webSQLDatabaseDirectory.string()); + + for (const auto& origin : origins) + databaseTracker->deleteOrigin(origin.get()); + + RunLoop::main().dispatch([callbackAggregator] { + callbackAggregator->removePendingCallback(); + }); + }); + } + +#if ENABLE(DATABASE_PROCESS) + if (dataTypes & WebsiteDataTypeIndexedDBDatabases && isPersistent()) { + for (auto& processPool : processPools()) { + processPool->ensureDatabaseProcess(); + + callbackAggregator->addPendingCallback(); + processPool->databaseProcess()->deleteWebsiteDataForOrigins(m_sessionID, dataTypes, origins, [callbackAggregator, processPool] { + callbackAggregator->removePendingCallback(); + }); + } + } +#endif + + if (dataTypes & WebsiteDataTypeMediaKeys && isPersistent()) { + StringCapture mediaKeysStorageDirectory { m_mediaKeysStorageDirectory }; + HashSet<RefPtr<WebCore::SecurityOrigin>> origins; + for (const auto& dataRecord : dataRecords) { + for (const auto& origin : dataRecord.origins) + origins.add(origin); + } + + callbackAggregator->addPendingCallback(); + m_queue->dispatch([mediaKeysStorageDirectory, callbackAggregator, origins] { + + removeMediaKeys(mediaKeysStorageDirectory.string(), origins); + + RunLoop::main().dispatch([callbackAggregator] { + callbackAggregator->removePendingCallback(); + }); + }); + } + +#if ENABLE(NETSCAPE_PLUGIN_API) + if (dataTypes & WebsiteDataTypePlugInData && isPersistent()) { + Vector<String> hostNames; + for (const auto& dataRecord : dataRecords) { + for (const auto& hostName : dataRecord.pluginDataHostNames) + hostNames.append(hostName); + } + + + class State { + public: + static void deleteData(Ref<CallbackAggregator>&& callbackAggregator, Vector<PluginModuleInfo>&& plugins, Vector<String>&& hostNames) + { + new State(WTFMove(callbackAggregator), WTFMove(plugins), WTFMove(hostNames)); + } + + private: + State(Ref<CallbackAggregator>&& callbackAggregator, Vector<PluginModuleInfo>&& plugins, Vector<String>&& hostNames) + : m_callbackAggregator(WTFMove(callbackAggregator)) + , m_plugins(WTFMove(plugins)) + , m_hostNames(WTFMove(hostNames)) + { + m_callbackAggregator->addPendingCallback(); + + deleteWebsiteDataForNextPlugin(); + } + + ~State() + { + ASSERT(m_plugins.isEmpty()); + } + + void deleteWebsiteDataForNextPlugin() + { + if (m_plugins.isEmpty()) { + m_callbackAggregator->removePendingCallback(); + + delete this; + return; + } + + auto plugin = m_plugins.takeLast(); + PluginProcessManager::singleton().deleteWebsiteDataForHostNames(plugin, m_hostNames, [this] { + deleteWebsiteDataForNextPlugin(); + }); + } + + Ref<CallbackAggregator> m_callbackAggregator; + Vector<PluginModuleInfo> m_plugins; + Vector<String> m_hostNames; + }; + + State::deleteData(*callbackAggregator, plugins(), WTFMove(hostNames)); + } +#endif + + // There's a chance that we don't have any pending callbacks. If so, we want to dispatch the completion handler right away. + callbackAggregator->callIfNeeded(); +} + +void WebsiteDataStore::webPageWasAdded(WebPageProxy& webPageProxy) +{ + if (m_storageManager) + m_storageManager->createSessionStorageNamespace(webPageProxy.pageID(), std::numeric_limits<unsigned>::max()); +} + +void WebsiteDataStore::webPageWasRemoved(WebPageProxy& webPageProxy) +{ + if (m_storageManager) + m_storageManager->destroySessionStorageNamespace(webPageProxy.pageID()); +} + +void WebsiteDataStore::webProcessWillOpenConnection(WebProcessProxy& webProcessProxy, IPC::Connection& connection) +{ + if (m_storageManager) + m_storageManager->processWillOpenConnection(webProcessProxy, connection); +} + +void WebsiteDataStore::webPageWillOpenConnection(WebPageProxy& webPageProxy, IPC::Connection& connection) +{ + if (m_storageManager) + m_storageManager->setAllowedSessionStorageNamespaceConnection(webPageProxy.pageID(), &connection); +} + +void WebsiteDataStore::webPageDidCloseConnection(WebPageProxy& webPageProxy, IPC::Connection&) +{ + if (m_storageManager) + m_storageManager->setAllowedSessionStorageNamespaceConnection(webPageProxy.pageID(), nullptr); +} + +void WebsiteDataStore::webProcessDidCloseConnection(WebProcessProxy& webProcessProxy, IPC::Connection& connection) +{ + if (m_storageManager) + m_storageManager->processDidCloseConnection(webProcessProxy, connection); +} + +HashSet<RefPtr<WebProcessPool>> WebsiteDataStore::processPools() const +{ + HashSet<RefPtr<WebProcessPool>> processPools; + for (auto& process : processes()) + processPools.add(&process->processPool()); + + if (processPools.isEmpty()) { + // Check if we're one of the legacy data stores. + for (auto& processPool : WebProcessPool::allProcessPools()) { + if (auto dataStore = processPool->websiteDataStore()) { + if (&dataStore->websiteDataStore() == this) { + processPools.add(processPool); + break; + } + } + } + } + + if (processPools.isEmpty()) { + auto processPool = WebProcessPool::create(API::ProcessPoolConfiguration::create()); + + processPools.add(processPool.ptr()); + } + + return processPools; +} + +#if ENABLE(NETSCAPE_PLUGIN_API) +Vector<PluginModuleInfo> WebsiteDataStore::plugins() const +{ + Vector<PluginModuleInfo> plugins; + + for (auto& processPool : processPools()) { + for (auto& plugin : processPool->pluginInfoStore().plugins()) + plugins.append(plugin); + } + + return plugins; +} +#endif + +static String computeMediaKeyFile(const String& mediaKeyDirectory) +{ + return WebCore::pathByAppendingComponent(mediaKeyDirectory, "SecureStop.plist"); +} + +Vector<RefPtr<WebCore::SecurityOrigin>> WebsiteDataStore::mediaKeyOrigins(const String& mediaKeysStorageDirectory) +{ + ASSERT(!mediaKeysStorageDirectory.isEmpty()); + + Vector<RefPtr<WebCore::SecurityOrigin>> origins; + + for (const auto& originPath : WebCore::listDirectory(mediaKeysStorageDirectory, "*")) { + auto mediaKeyFile = computeMediaKeyFile(originPath); + if (!WebCore::fileExists(mediaKeyFile)) + continue; + + auto mediaKeyIdentifier = WebCore::pathGetFileName(originPath); + + if (auto securityOrigin = WebCore::SecurityOrigin::maybeCreateFromDatabaseIdentifier(mediaKeyIdentifier)) + origins.append(WTFMove(securityOrigin)); + } + + return origins; +} + +void WebsiteDataStore::removeMediaKeys(const String& mediaKeysStorageDirectory, std::chrono::system_clock::time_point modifiedSince) +{ + ASSERT(!mediaKeysStorageDirectory.isEmpty()); + + for (const auto& mediaKeyDirectory : WebCore::listDirectory(mediaKeysStorageDirectory, "*")) { + auto mediaKeyFile = computeMediaKeyFile(mediaKeyDirectory); + + time_t modificationTime; + if (!WebCore::getFileModificationTime(mediaKeyFile, modificationTime)) + continue; + + if (std::chrono::system_clock::from_time_t(modificationTime) < modifiedSince) + continue; + + WebCore::deleteFile(mediaKeyFile); + WebCore::deleteEmptyDirectory(mediaKeyDirectory); + } +} + +void WebsiteDataStore::removeMediaKeys(const String& mediaKeysStorageDirectory, const HashSet<RefPtr<WebCore::SecurityOrigin>>& origins) +{ + ASSERT(!mediaKeysStorageDirectory.isEmpty()); + + for (const auto& origin : origins) { + auto mediaKeyDirectory = WebCore::pathByAppendingComponent(mediaKeysStorageDirectory, origin->databaseIdentifier()); + auto mediaKeyFile = computeMediaKeyFile(mediaKeyDirectory); + + WebCore::deleteFile(mediaKeyFile); + WebCore::deleteEmptyDirectory(mediaKeyDirectory); + } +} + +} diff --git a/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.h b/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.h new file mode 100644 index 000000000..0c829da94 --- /dev/null +++ b/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.h @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebsiteDataStore_h +#define WebsiteDataStore_h + +#include "WebProcessLifetimeObserver.h" +#include "WebsiteDataTypes.h" +#include <WebCore/SecurityOriginHash.h> +#include <WebCore/SessionID.h> +#include <functional> +#include <wtf/HashSet.h> +#include <wtf/RefCounted.h> +#include <wtf/RefPtr.h> +#include <wtf/WorkQueue.h> +#include <wtf/text/WTFString.h> + +namespace WebCore { +class SecurityOrigin; +} + +namespace WebKit { + +class StorageManager; +class WebPageProxy; +class WebProcessPool; +struct WebsiteDataRecord; + +#if ENABLE(NETSCAPE_PLUGIN_API) +struct PluginModuleInfo; +#endif + +class WebsiteDataStore : public RefCounted<WebsiteDataStore>, public WebProcessLifetimeObserver { +public: + struct Configuration { + String networkCacheDirectory; + String applicationCacheDirectory; + + String webSQLDatabaseDirectory; + String localStorageDirectory; + String mediaKeysStorageDirectory; + }; + static Ref<WebsiteDataStore> createNonPersistent(); + static Ref<WebsiteDataStore> create(Configuration); + virtual ~WebsiteDataStore(); + + uint64_t identifier() const { return m_identifier; } + + bool isPersistent() const { return !m_sessionID.isEphemeral(); } + WebCore::SessionID sessionID() const { return m_sessionID; } + + static void cloneSessionData(WebPageProxy& sourcePage, WebPageProxy& newPage); + + void fetchData(WebsiteDataTypes, std::function<void (Vector<WebsiteDataRecord>)> completionHandler); + void removeData(WebsiteDataTypes, std::chrono::system_clock::time_point modifiedSince, std::function<void ()> completionHandler); + void removeData(WebsiteDataTypes, const Vector<WebsiteDataRecord>&, std::function<void ()> completionHandler); + + StorageManager* storageManager() { return m_storageManager.get(); } + +private: + explicit WebsiteDataStore(WebCore::SessionID); + explicit WebsiteDataStore(Configuration); + + // WebProcessLifetimeObserver. + virtual void webPageWasAdded(WebPageProxy&) override; + virtual void webPageWasRemoved(WebPageProxy&) override; + virtual void webProcessWillOpenConnection(WebProcessProxy&, IPC::Connection&) override; + virtual void webPageWillOpenConnection(WebPageProxy&, IPC::Connection&) override; + virtual void webPageDidCloseConnection(WebPageProxy&, IPC::Connection&) override; + virtual void webProcessDidCloseConnection(WebProcessProxy&, IPC::Connection&) override; + + void platformInitialize(); + void platformDestroy(); + static void platformRemoveRecentSearches(std::chrono::system_clock::time_point); + + HashSet<RefPtr<WebProcessPool>> processPools() const; + +#if ENABLE(NETSCAPE_PLUGIN_API) + Vector<PluginModuleInfo> plugins() const; +#endif + + static Vector<RefPtr<WebCore::SecurityOrigin>> mediaKeyOrigins(const String& mediaKeysStorageDirectory); + static void removeMediaKeys(const String& mediaKeysStorageDirectory, std::chrono::system_clock::time_point modifiedSince); + static void removeMediaKeys(const String& mediaKeysStorageDirectory, const HashSet<RefPtr<WebCore::SecurityOrigin>>&); + + const uint64_t m_identifier; + const WebCore::SessionID m_sessionID; + + const String m_networkCacheDirectory; + const String m_applicationCacheDirectory; + + const String m_webSQLDatabaseDirectory; + const String m_mediaKeysStorageDirectory; + const RefPtr<StorageManager> m_storageManager; + + Ref<WorkQueue> m_queue; +}; + +} + +#endif // WebsiteDataStore_h diff --git a/Source/WebKit2/UIProcess/WebsiteData/unix/WebsiteDataStoreUnix.cpp b/Source/WebKit2/UIProcess/WebsiteData/unix/WebsiteDataStoreUnix.cpp new file mode 100644 index 000000000..76956fd75 --- /dev/null +++ b/Source/WebKit2/UIProcess/WebsiteData/unix/WebsiteDataStoreUnix.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2015 University of Szeged. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebsiteDataStore.h" + +namespace WebKit { + +void WebsiteDataStore::platformInitialize() +{ +} + +void WebsiteDataStore::platformDestroy() +{ +} + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/_WKWebViewPrintFormatter.h b/Source/WebKit2/UIProcess/_WKWebViewPrintFormatter.h new file mode 100644 index 000000000..befdcc78b --- /dev/null +++ b/Source/WebKit2/UIProcess/_WKWebViewPrintFormatter.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if TARGET_OS_IPHONE + +#import <UIKit/UIPrintFormatter.h> + +@class _WKFrameHandle; + +@interface _WKWebViewPrintFormatter : UIViewPrintFormatter + +@property (nonatomic, strong) _WKFrameHandle *frameToPrint; + +@end + +#endif diff --git a/Source/WebKit2/UIProcess/cairo/BackingStoreCairo.cpp b/Source/WebKit2/UIProcess/cairo/BackingStoreCairo.cpp index 89968ae59..df4b7470d 100644 --- a/Source/WebKit2/UIProcess/cairo/BackingStoreCairo.cpp +++ b/Source/WebKit2/UIProcess/cairo/BackingStoreCairo.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2011 Apple Inc. All rights reserved. - * Copyright (C) 2011 Igalia S.L. + * Copyright (C) 2011,2014 Igalia S.L. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -30,64 +30,88 @@ #include "ShareableBitmap.h" #include "UpdateInfo.h" #include "WebPageProxy.h" +#include <WebCore/BackingStoreBackendCairoImpl.h> +#include <WebCore/CairoUtilities.h> #include <WebCore/GraphicsContext.h> -#include <WebCore/WidgetBackingStoreCairo.h> +#include <WebCore/RefPtrCairo.h> #include <cairo.h> -#if PLATFORM(GTK) && PLATFORM(X11) && defined(GDK_WINDOWING_X11) -#include <WebCore/WidgetBackingStoreGtkX11.h> -#include <gdk/gdkx.h> +#if PLATFORM(GTK) +#include <gtk/gtk.h> #endif -#if PLATFORM(EFL) -#include "EwkView.h" +#if PLATFORM(GTK) && PLATFORM(X11) && defined(GDK_WINDOWING_X11) +#include <WebCore/BackingStoreBackendCairoX11.h> +#include <WebCore/PlatformDisplayX11.h> +#include <gdk/gdkx.h> #endif using namespace WebCore; namespace WebKit { -#if PLATFORM(GTK) -static OwnPtr<WidgetBackingStore> createBackingStoreForGTK(GtkWidget* widget, const IntSize& size, float deviceScaleFactor) +std::unique_ptr<BackingStoreBackendCairo> BackingStore::createBackend() { -#if PLATFORM(X11) && defined(GDK_WINDOWING_X11) - GdkDisplay* display = gdk_display_manager_get_default_display(gdk_display_manager_get()); - if (GDK_IS_X11_DISPLAY(display)) - return WebCore::WidgetBackingStoreGtkX11::create(widget, size, deviceScaleFactor); +#if PLATFORM(GTK) && PLATFORM(X11) && defined(GDK_WINDOWING_X11) + const auto& sharedDisplay = PlatformDisplay::sharedDisplay(); + if (is<PlatformDisplayX11>(sharedDisplay)) { + GdkVisual* visual = gtk_widget_get_visual(m_webPageProxy.viewWidget()); + GdkScreen* screen = gdk_visual_get_screen(visual); + ASSERT(downcast<PlatformDisplayX11>(sharedDisplay).native() == GDK_SCREEN_XDISPLAY(screen)); + return std::make_unique<BackingStoreBackendCairoX11>(GDK_WINDOW_XID(gdk_screen_get_root_window(screen)), + GDK_VISUAL_XVISUAL(visual), gdk_visual_get_depth(visual), m_size, m_deviceScaleFactor); + } #endif - return WebCore::WidgetBackingStoreCairo::create(widget, size, deviceScaleFactor); -} + + IntSize scaledSize = m_size; + scaledSize.scale(m_deviceScaleFactor); + +#if PLATFORM(GTK) + RefPtr<cairo_surface_t> surface = adoptRef(gdk_window_create_similar_surface(gtk_widget_get_window(m_webPageProxy.viewWidget()), + CAIRO_CONTENT_COLOR_ALPHA, scaledSize.width(), scaledSize.height())); +#else + RefPtr<cairo_surface_t> surface = adoptRef(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, scaledSize.width(), scaledSize.height())); #endif + cairoSurfaceSetDeviceScale(surface.get(), m_deviceScaleFactor, m_deviceScaleFactor); + return std::make_unique<BackingStoreBackendCairoImpl>(surface.get(), m_size); +} + void BackingStore::paint(cairo_t* context, const IntRect& rect) { - ASSERT(m_backingStore); + ASSERT(m_backend); + cairo_save(context); cairo_set_operator(context, CAIRO_OPERATOR_SOURCE); - cairo_set_source_surface(context, m_backingStore->cairoSurface(), 0, 0); + cairo_set_source_surface(context, m_backend->surface(), 0, 0); cairo_rectangle(context, rect.x(), rect.y(), rect.width(), rect.height()); cairo_fill(context); + cairo_restore(context); } void BackingStore::incorporateUpdate(ShareableBitmap* bitmap, const UpdateInfo& updateInfo) { - if (!m_backingStore) -#if PLATFORM(EFL) - m_backingStore = WidgetBackingStoreCairo::create(EwkView::toEvasObject(toAPI(m_webPageProxy)), size(), deviceScaleFactor()); -#else - m_backingStore = createBackingStoreForGTK(m_webPageProxy->viewWidget(), size(), deviceScaleFactor()); -#endif + if (!m_backend) + m_backend = createBackend(); scroll(updateInfo.scrollRect, updateInfo.scrollOffset); // Paint all update rects. IntPoint updateRectLocation = updateInfo.updateRectBounds.location(); - RefPtr<cairo_t> context(adoptRef(cairo_create(m_backingStore->cairoSurface()))); + RefPtr<cairo_t> context = adoptRef(cairo_create(m_backend->surface())); GraphicsContext graphicsContext(context.get()); - for (size_t i = 0; i < updateInfo.updateRects.size(); ++i) { - IntRect updateRect = updateInfo.updateRects[i]; + for (const auto& updateRect : updateInfo.updateRects) { IntRect srcRect = updateRect; srcRect.move(-updateRectLocation.x(), -updateRectLocation.y()); +#if PLATFORM(GTK) + if (!m_webPageProxy.drawsBackground()) { + const WebCore::Color color = m_webPageProxy.backgroundColor(); + if (color.hasAlpha()) + graphicsContext.clearRect(srcRect); + if (color.alpha() > 0) + graphicsContext.fillRect(srcRect, color); + } +#endif bitmap->paint(graphicsContext, deviceScaleFactor(), updateRect.location(), srcRect); } } @@ -97,8 +121,8 @@ void BackingStore::scroll(const IntRect& scrollRect, const IntSize& scrollOffset if (scrollOffset.isZero()) return; - ASSERT(m_backingStore); - m_backingStore->scroll(scrollRect, scrollOffset); + ASSERT(m_backend); + m_backend->scroll(scrollRect, scrollOffset); } } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/gstreamer/InstallMissingMediaPluginsPermissionRequest.cpp b/Source/WebKit2/UIProcess/gstreamer/InstallMissingMediaPluginsPermissionRequest.cpp new file mode 100644 index 000000000..11d759e1c --- /dev/null +++ b/Source/WebKit2/UIProcess/gstreamer/InstallMissingMediaPluginsPermissionRequest.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2015 Igalia S.L. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "InstallMissingMediaPluginsPermissionRequest.h" + +#if ENABLE(VIDEO) && USE(GSTREAMER) +#include "WebPageMessages.h" +#include "WebPageProxy.h" +#include <wtf/text/CString.h> + +namespace WebKit { + +InstallMissingMediaPluginsPermissionRequest::InstallMissingMediaPluginsPermissionRequest(WebPageProxy& page, const String& details, const String& description) + : m_page(&page) + , m_details(details) + , m_description(description) +{ +} + +InstallMissingMediaPluginsPermissionRequest::~InstallMissingMediaPluginsPermissionRequest() +{ +} + +void InstallMissingMediaPluginsPermissionRequest::allow(GUniquePtr<GstInstallPluginsContext>&& context) +{ + if (!m_page->isValid()) + return; + + CString detail = m_details.utf8(); + const char* detailArray[2] = { detail.data(), nullptr }; + ref(); + GstInstallPluginsReturn result = gst_install_plugins_async(detailArray, context.get(), [](GstInstallPluginsReturn result, gpointer userData) { + RefPtr<InstallMissingMediaPluginsPermissionRequest> request = adoptRef(static_cast<InstallMissingMediaPluginsPermissionRequest*>(userData)); + request->didEndRequestInstallMissingMediaPlugins(static_cast<uint32_t>(result)); + }, this); + + if (result != GST_INSTALL_PLUGINS_STARTED_OK) { + // If the installer didn't start, the callback will not be called, so remove the ref manually. + deref(); + didEndRequestInstallMissingMediaPlugins(static_cast<uint32_t>(result)); + WTFLogAlways("Missing GStreamer Plugin: %s\n", detail.data()); + } +} + +void InstallMissingMediaPluginsPermissionRequest::deny() +{ + didEndRequestInstallMissingMediaPlugins(static_cast<uint32_t>(GST_INSTALL_PLUGINS_USER_ABORT)); +} + +void InstallMissingMediaPluginsPermissionRequest::didEndRequestInstallMissingMediaPlugins(uint32_t result) +{ + if (!m_page->isValid()) + return; + + m_page->send(Messages::WebPage::DidEndRequestInstallMissingMediaPlugins(result)); +} + +} // namespace WebKit + +#endif // ENABLE(VIDEO) && USE(GSTREAMER) diff --git a/Source/WebKit2/UIProcess/gstreamer/InstallMissingMediaPluginsPermissionRequest.h b/Source/WebKit2/UIProcess/gstreamer/InstallMissingMediaPluginsPermissionRequest.h new file mode 100644 index 000000000..5416014cb --- /dev/null +++ b/Source/WebKit2/UIProcess/gstreamer/InstallMissingMediaPluginsPermissionRequest.h @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2015 Igalia S.L. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef InstallMissingMediaPluginsPermissionRequest_h +#define InstallMissingMediaPluginsPermissionRequest_h + +#if ENABLE(VIDEO) && USE(GSTREAMER) +#include <WebCore/GUniquePtrGStreamer.h> +#include <wtf/RefCounted.h> +#include <wtf/RefPtr.h> +#include <wtf/text/WTFString.h> + +namespace WebKit { + +class WebPageProxy; + +class InstallMissingMediaPluginsPermissionRequest : public RefCounted<InstallMissingMediaPluginsPermissionRequest> { +public: + static Ref<InstallMissingMediaPluginsPermissionRequest> create(WebPageProxy& page, const String& details, const String& description) + { + return adoptRef(*new InstallMissingMediaPluginsPermissionRequest(page, details, description)); + } + ~InstallMissingMediaPluginsPermissionRequest(); + + void allow(GUniquePtr<GstInstallPluginsContext>&& = nullptr); + void deny(); + + WebPageProxy& page() const { return *m_page; } + const String& details() const { return m_details; } + const String& description() const { return m_description; } + +private: + InstallMissingMediaPluginsPermissionRequest(WebPageProxy&, const String& details, const String& description); + + void didEndRequestInstallMissingMediaPlugins(uint32_t result); + + RefPtr<WebPageProxy> m_page; + String m_details; + String m_description; +}; + +} // namespace WebKit + +#else + +namespace WebKit { +class InstallMissingMediaPluginsPermissionRequest; +} // namespace WebKit + +#endif // ENABLE(VIDEO) && USE(GSTREAMER) +#endif // InstallMissingMediaPluginsPermissionRequest_h diff --git a/Source/WebKit2/UIProcess/WebColorPickerResultListenerProxy.cpp b/Source/WebKit2/UIProcess/gstreamer/WebPageProxyGStreamer.cpp index c0c2c2221..2ed9c34cf 100644 --- a/Source/WebKit2/UIProcess/WebColorPickerResultListenerProxy.cpp +++ b/Source/WebKit2/UIProcess/gstreamer/WebPageProxyGStreamer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Samsung Electronics. All rights reserved. + * Copyright (C) 2015 Igalia S.L. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -10,7 +10,7 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS AS IS'' + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS @@ -24,37 +24,23 @@ */ #include "config.h" -#include "WebColorPickerResultListenerProxy.h" - -#if ENABLE(INPUT_TYPE_COLOR) - #include "WebPageProxy.h" -namespace WebKit { - -WebColorPickerResultListenerProxy::WebColorPickerResultListenerProxy(WebPageProxy* page) - : m_page(page) -{ -} - -WebColorPickerResultListenerProxy::~WebColorPickerResultListenerProxy() -{ -} +#if ENABLE(VIDEO) && USE(GSTREAMER) +#include "InstallMissingMediaPluginsPermissionRequest.h" +#include "PageClient.h" -void WebColorPickerResultListenerProxy::invalidate() -{ - m_page = 0; -} +namespace WebKit { -void WebColorPickerResultListenerProxy::setColor(const String& color) +void WebPageProxy::requestInstallMissingMediaPlugins(const String& details, const String& description) { - if (!m_page) + RefPtr<InstallMissingMediaPluginsPermissionRequest> request = InstallMissingMediaPluginsPermissionRequest::create(*this, details, description); + if (m_pageClient.decidePolicyForInstallMissingMediaPluginsPermissionRequest(*request)) return; - m_page->setColorPickerColor(WebCore::Color(color)); - m_page->endColorPicker(); + request->deny(); } } // namespace WebKit -#endif // ENABLE(INPUT_TYPE_COLOR) +#endif // ENABLE(VIDEO) && USE(GSTREAMER) diff --git a/Source/WebKit2/UIProcess/gtk/DragAndDropHandler.cpp b/Source/WebKit2/UIProcess/gtk/DragAndDropHandler.cpp new file mode 100644 index 000000000..8423ed76f --- /dev/null +++ b/Source/WebKit2/UIProcess/gtk/DragAndDropHandler.cpp @@ -0,0 +1,312 @@ +/* + * Copyright (C) 2014 Igalia S.L. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "DragAndDropHandler.h" + +#if ENABLE(DRAG_SUPPORT) + +#include "WebPageProxy.h" +#include <WebCore/DataObjectGtk.h> +#include <WebCore/DragData.h> +#include <WebCore/GRefPtrGtk.h> +#include <WebCore/GtkUtilities.h> +#include <WebCore/PasteboardHelper.h> +#include <gtk/gtk.h> +#include <wtf/RunLoop.h> +#include <wtf/glib/GUniquePtr.h> + +using namespace WebCore; + +namespace WebKit { + +DragAndDropHandler::DragAndDropHandler(WebPageProxy& page) + : m_page(page) +#if GTK_CHECK_VERSION(3, 16, 0) + , m_dragContext(nullptr) +#endif +{ +} + +DragAndDropHandler::DroppingContext::DroppingContext(GdkDragContext* gdkContext, const IntPoint& position) + : gdkContext(gdkContext) + , dataObject(DataObjectGtk::create()) + , lastMotionPosition(position) + , dropHappened(false) +{ +} + +static inline GdkDragAction dragOperationToGdkDragActions(DragOperation coreAction) +{ + GdkDragAction gdkAction = static_cast<GdkDragAction>(0); + if (coreAction == DragOperationNone) + return gdkAction; + + if (coreAction & DragOperationCopy) + gdkAction = static_cast<GdkDragAction>(GDK_ACTION_COPY | gdkAction); + if (coreAction & DragOperationMove) + gdkAction = static_cast<GdkDragAction>(GDK_ACTION_MOVE | gdkAction); + if (coreAction & DragOperationLink) + gdkAction = static_cast<GdkDragAction>(GDK_ACTION_LINK | gdkAction); + if (coreAction & DragOperationPrivate) + gdkAction = static_cast<GdkDragAction>(GDK_ACTION_PRIVATE | gdkAction); + + return gdkAction; +} + +static inline GdkDragAction dragOperationToSingleGdkDragAction(DragOperation coreAction) +{ + if (coreAction == DragOperationEvery || coreAction & DragOperationCopy) + return GDK_ACTION_COPY; + if (coreAction & DragOperationMove) + return GDK_ACTION_MOVE; + if (coreAction & DragOperationLink) + return GDK_ACTION_LINK; + if (coreAction & DragOperationPrivate) + return GDK_ACTION_PRIVATE; + return static_cast<GdkDragAction>(0); +} + +static inline DragOperation gdkDragActionToDragOperation(GdkDragAction gdkAction) +{ + // We have no good way to detect DragOperationEvery other than + // to use it when all applicable flags are on. + if (gdkAction & GDK_ACTION_COPY + && gdkAction & GDK_ACTION_MOVE + && gdkAction & GDK_ACTION_LINK + && gdkAction & GDK_ACTION_PRIVATE) + return DragOperationEvery; + + unsigned action = DragOperationNone; + if (gdkAction & GDK_ACTION_COPY) + action |= DragOperationCopy; + if (gdkAction & GDK_ACTION_MOVE) + action |= DragOperationMove; + if (gdkAction & GDK_ACTION_LINK) + action |= DragOperationLink; + if (gdkAction & GDK_ACTION_PRIVATE) + action |= DragOperationPrivate; + return static_cast<DragOperation>(action); +} + +void DragAndDropHandler::startDrag(const DragData& dragData, PassRefPtr<ShareableBitmap> dragImage) +{ +#if GTK_CHECK_VERSION(3, 16, 0) + m_draggingDataObject = adoptRef(dragData.platformData()); + GRefPtr<GtkTargetList> targetList = adoptGRef(PasteboardHelper::singleton().targetListForDataObject(m_draggingDataObject.get())); +#else + RefPtr<DataObjectGtk> dataObject = adoptRef(dragData.platformData()); + GRefPtr<GtkTargetList> targetList = adoptGRef(PasteboardHelper::singleton().targetListForDataObject(dataObject.get())); +#endif + + GUniquePtr<GdkEvent> currentEvent(gtk_get_current_event()); + GdkDragContext* context = gtk_drag_begin(m_page.viewWidget(), targetList.get(), dragOperationToGdkDragActions(dragData.draggingSourceOperationMask()), + GDK_BUTTON_PRIMARY, currentEvent.get()); + +#if GTK_CHECK_VERSION(3, 16, 0) + // WebCore::EventHandler does not support more than one DnD operation at the same time for + // a given page, so we should cancel any previous operation whose context we might have + // stored, should we receive a new startDrag event before finishing a previous DnD operation. + if (m_dragContext) + gtk_drag_cancel(m_dragContext.get()); + m_dragContext = context; +#else + // We don't have gtk_drag_cancel() in GTK+ < 3.16, so we use the old code. + // See https://bugs.webkit.org/show_bug.cgi?id=138468 + m_draggingDataObjects.set(context, dataObject.get()); +#endif + + if (dragImage) { + RefPtr<cairo_surface_t> image(dragImage->createCairoSurface()); + // Use the center of the drag image as hotspot. + cairo_surface_set_device_offset(image.get(), -cairo_image_surface_get_width(image.get()) / 2, -cairo_image_surface_get_height(image.get()) / 2); + gtk_drag_set_icon_surface(context, image.get()); + } else + gtk_drag_set_icon_default(context); +} + +void DragAndDropHandler::fillDragData(GdkDragContext* context, GtkSelectionData* selectionData, unsigned info) +{ +#if GTK_CHECK_VERSION(3, 16, 0) + // This can happen when attempting to call finish drag from webkitWebViewBaseDragDataGet() + // for a obsolete DnD operation that got previously cancelled in startDrag(). + if (m_dragContext.get() != context) + return; + + ASSERT(m_draggingDataObject); + PasteboardHelper::singleton().fillSelectionData(selectionData, info, m_draggingDataObject.get()); +#else + if (DataObjectGtk* dataObject = m_draggingDataObjects.get(context)) + PasteboardHelper::singleton().fillSelectionData(selectionData, info, dataObject); +#endif +} + +void DragAndDropHandler::finishDrag(GdkDragContext* context) +{ +#if GTK_CHECK_VERSION(3, 16, 0) + // This can happen when attempting to call finish drag from webkitWebViewBaseDragEnd() + // for a obsolete DnD operation that got previously cancelled in startDrag(). + if (m_dragContext.get() != context) + return; + + if (!m_draggingDataObject) + return; + + m_dragContext = nullptr; + m_draggingDataObject = nullptr; +#else + if (!m_draggingDataObjects.remove(context)) + return; +#endif + + GdkDevice* device = gdk_drag_context_get_device(context); + int x = 0, y = 0; + gdk_device_get_window_at_position(device, &x, &y); + int xRoot = 0, yRoot = 0; + gdk_device_get_position(device, nullptr, &xRoot, &yRoot); + m_page.dragEnded(IntPoint(x, y), IntPoint(xRoot, yRoot), gdkDragActionToDragOperation(gdk_drag_context_get_selected_action(context))); +} + +DataObjectGtk* DragAndDropHandler::dataObjectForDropData(GdkDragContext* context, GtkSelectionData* selectionData, unsigned info, IntPoint& position) +{ + DroppingContext* droppingContext = m_droppingContexts.get(context); + if (!droppingContext) + return nullptr; + + droppingContext->pendingDataRequests--; + PasteboardHelper::singleton().fillDataObjectFromDropData(selectionData, info, droppingContext->dataObject.get()); + if (droppingContext->pendingDataRequests) + return nullptr; + + // The coordinates passed to drag-data-received signal are sometimes + // inaccurate in WTR, so use the coordinates of the last motion event. + position = droppingContext->lastMotionPosition; + + // If there are no more pending requests, start sending dragging data to WebCore. + return droppingContext->dataObject.get(); +} + +void DragAndDropHandler::dragEntered(GdkDragContext* context, GtkSelectionData* selectionData, unsigned info, unsigned time) +{ + IntPoint position; + DataObjectGtk* dataObject = dataObjectForDropData(context, selectionData, info, position); + if (!dataObject) + return; + + DragData dragData(dataObject, position, convertWidgetPointToScreenPoint(m_page.viewWidget(), position), gdkDragActionToDragOperation(gdk_drag_context_get_actions(context))); + m_page.resetCurrentDragInformation(); + m_page.dragEntered(dragData); + DragOperation operation = m_page.currentDragOperation(); + gdk_drag_status(context, dragOperationToSingleGdkDragAction(operation), time); +} + +DataObjectGtk* DragAndDropHandler::requestDragData(GdkDragContext* context, const IntPoint& position, unsigned time) +{ + std::unique_ptr<DroppingContext>& droppingContext = m_droppingContexts.add(context, nullptr).iterator->value; + if (!droppingContext) { + GtkWidget* widget = m_page.viewWidget(); + droppingContext = std::make_unique<DroppingContext>(context, position); + Vector<GdkAtom> acceptableTargets(PasteboardHelper::singleton().dropAtomsForContext(widget, droppingContext->gdkContext)); + droppingContext->pendingDataRequests = acceptableTargets.size(); + for (auto& target : acceptableTargets) + gtk_drag_get_data(widget, droppingContext->gdkContext, target, time); + } else + droppingContext->lastMotionPosition = position; + + // Don't send any drag information to WebCore until we've retrieved all the data for this drag operation. + // Otherwise we'd have to block to wait for the drag's data. + if (droppingContext->pendingDataRequests > 0) + return nullptr; + + return droppingContext->dataObject.get(); +} + +void DragAndDropHandler::dragMotion(GdkDragContext* context, const IntPoint& position, unsigned time) +{ + DataObjectGtk* dataObject = requestDragData(context, position, time); + if (!dataObject) + return; + + DragData dragData(dataObject, position, convertWidgetPointToScreenPoint(m_page.viewWidget(), position), gdkDragActionToDragOperation(gdk_drag_context_get_actions(context))); + m_page.dragUpdated(dragData); + DragOperation operation = m_page.currentDragOperation(); + gdk_drag_status(context, dragOperationToSingleGdkDragAction(operation), time); +} + +void DragAndDropHandler::dragLeave(GdkDragContext* context) +{ + DroppingContext* droppingContext = m_droppingContexts.get(context); + if (!droppingContext) + return; + + // During a drop GTK+ will fire a drag-leave signal right before firing + // the drag-drop signal. We want the actions for drag-leave to happen after + // those for drag-drop, so schedule them to happen asynchronously here. + RunLoop::main().dispatch([this, droppingContext]() { + auto it = m_droppingContexts.find(droppingContext->gdkContext); + if (it == m_droppingContexts.end()) + return; + + // If the view doesn't know about the drag yet (there are still pending data requests), + // don't update it with information about the drag. + if (droppingContext->pendingDataRequests) + return; + + if (!droppingContext->dropHappened) { + // Don't call dragExited if we have just received a drag-drop signal. This + // happens in the case of a successful drop onto the view. + const IntPoint& position = droppingContext->lastMotionPosition; + DragData dragData(droppingContext->dataObject.get(), position, convertWidgetPointToScreenPoint(m_page.viewWidget(), position), DragOperationNone); + m_page.dragExited(dragData); + m_page.resetCurrentDragInformation(); + } + + m_droppingContexts.remove(it); + }); +} + +bool DragAndDropHandler::drop(GdkDragContext* context, const IntPoint& position, unsigned time) +{ + DroppingContext* droppingContext = m_droppingContexts.get(context); + if (!droppingContext) + return false; + + droppingContext->dropHappened = true; + + DataObjectGtk* dataObject = droppingContext->dataObject.get(); + if (!dataObject) + return false; + + DragData dragData(dataObject, position, convertWidgetPointToScreenPoint(m_page.viewWidget(), position), gdkDragActionToDragOperation(gdk_drag_context_get_actions(context))); + SandboxExtension::Handle handle; + SandboxExtension::HandleArray sandboxExtensionForUpload; + m_page.performDragOperation(dragData, String(), handle, sandboxExtensionForUpload); + gtk_drag_finish(context, TRUE, FALSE, time); + return true; +} + +} // namespace WebKit + +#endif // ENABLE(DRAG_SUPPORT) diff --git a/Source/WebKit2/UIProcess/gtk/DragAndDropHandler.h b/Source/WebKit2/UIProcess/gtk/DragAndDropHandler.h new file mode 100644 index 000000000..5020b9c1e --- /dev/null +++ b/Source/WebKit2/UIProcess/gtk/DragAndDropHandler.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2014 Igalia S.L. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef DragAndDropHandler_h +#define DragAndDropHandler_h + +#if ENABLE(DRAG_SUPPORT) + +#include <WebCore/DataObjectGtk.h> +#include <WebCore/IntPoint.h> +#include <gtk/gtk.h> +#include <wtf/HashMap.h> +#include <wtf/Noncopyable.h> + +typedef struct _GdkDragContext GdkDragContext; +typedef struct _GtkSelectionData GtkSelectionData; + +namespace WebCore { +class DragData; +} + +namespace WebKit { + +class ShareableBitmap; +class WebPageProxy; + +class DragAndDropHandler { + WTF_MAKE_NONCOPYABLE(DragAndDropHandler); +public: + DragAndDropHandler(WebPageProxy&); + + void startDrag(const WebCore::DragData&, PassRefPtr<ShareableBitmap> dragImage); + void fillDragData(GdkDragContext*, GtkSelectionData*, unsigned info); + void finishDrag(GdkDragContext*); + + void dragEntered(GdkDragContext*, GtkSelectionData*, unsigned info, unsigned time); + void dragMotion(GdkDragContext*, const WebCore::IntPoint& position, unsigned time); + void dragLeave(GdkDragContext*); + bool drop(GdkDragContext*, const WebCore::IntPoint& position, unsigned time); + +private: + struct DroppingContext { + DroppingContext(GdkDragContext*, const WebCore::IntPoint& position); + + GdkDragContext* gdkContext; + RefPtr<WebCore::DataObjectGtk> dataObject; + WebCore::IntPoint lastMotionPosition; + unsigned pendingDataRequests; + bool dropHappened; + }; + + WebCore::DataObjectGtk* dataObjectForDropData(GdkDragContext*, GtkSelectionData*, unsigned info, WebCore::IntPoint& position); + WebCore::DataObjectGtk* requestDragData(GdkDragContext*, const WebCore::IntPoint& position, unsigned time); + + WebPageProxy& m_page; + HashMap<GdkDragContext*, std::unique_ptr<DroppingContext>> m_droppingContexts; + +#if GTK_CHECK_VERSION(3, 16, 0) + GRefPtr<GdkDragContext> m_dragContext; + RefPtr<WebCore::DataObjectGtk> m_draggingDataObject; +#else + // We don't have gtk_drag_cancel() in GTK+ < 3.16, so we use the old code. + // See https://bugs.webkit.org/show_bug.cgi?id=138468 + HashMap<GdkDragContext*, RefPtr<WebCore::DataObjectGtk>> m_draggingDataObjects; +#endif +}; + +} // namespace WebKit + +#endif // ENABLE(DRAG_SUPPORT) + +#endif // DragAndDropHandler_h diff --git a/Source/WebKit2/UIProcess/gtk/ExperimentalFeatures.cpp b/Source/WebKit2/UIProcess/gtk/ExperimentalFeatures.cpp index 1b69302ac..2b45fb61f 100644 --- a/Source/WebKit2/UIProcess/gtk/ExperimentalFeatures.cpp +++ b/Source/WebKit2/UIProcess/gtk/ExperimentalFeatures.cpp @@ -39,7 +39,6 @@ struct Setting { }; static Setting settings[] = { - { ExperimentalFeatures::CSSGridLayout, "CSS_GRID_LAYOUT", false }, { ExperimentalFeatures::RegionBasedColumns, "REGION_BASED_COLUMNS", false } }; diff --git a/Source/WebKit2/UIProcess/gtk/ExperimentalFeatures.h b/Source/WebKit2/UIProcess/gtk/ExperimentalFeatures.h index 59603cbf8..eb0422884 100644 --- a/Source/WebKit2/UIProcess/gtk/ExperimentalFeatures.h +++ b/Source/WebKit2/UIProcess/gtk/ExperimentalFeatures.h @@ -37,7 +37,6 @@ namespace WebKit { class ExperimentalFeatures { public: enum Feature { - CSSGridLayout, RegionBasedColumns }; diff --git a/Source/WebKit2/UIProcess/gtk/GestureController.cpp b/Source/WebKit2/UIProcess/gtk/GestureController.cpp new file mode 100644 index 000000000..7e1577cba --- /dev/null +++ b/Source/WebKit2/UIProcess/gtk/GestureController.cpp @@ -0,0 +1,224 @@ +/* + * Copyright (C) 2014 Igalia S.L. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "GestureController.h" + +#if HAVE(GTK_GESTURES) + +#include "NativeWebMouseEvent.h" +#include "NativeWebWheelEvent.h" +#include "WebPageProxy.h" +#include <WebCore/FloatPoint.h> +#include <WebCore/Scrollbar.h> +#include <gtk/gtk.h> + +using namespace WebCore; + +namespace WebKit { + +GestureController::GestureController(WebPageProxy& page) + : m_dragGesture(page) + , m_zoomGesture(page) +{ +} + +bool GestureController::handleEvent(const GdkEvent* event) +{ + bool wasProcessingGestures = isProcessingGestures(); + m_dragGesture.handleEvent(event); + m_zoomGesture.handleEvent(event); + return event->type == GDK_TOUCH_END ? wasProcessingGestures : isProcessingGestures(); +} + +bool GestureController::isProcessingGestures() const +{ + return m_dragGesture.isActive() || m_zoomGesture.isActive(); +} + +GestureController::Gesture::Gesture(GtkGesture* gesture, WebPageProxy& page) + : m_gesture(adoptGRef(gesture)) + , m_page(page) +{ + gtk_event_controller_set_propagation_phase(GTK_EVENT_CONTROLLER(m_gesture.get()), GTK_PHASE_NONE); +} + +bool GestureController::Gesture::isActive() const +{ + return gtk_gesture_is_active(m_gesture.get()); +} + +void GestureController::Gesture::handleEvent(const GdkEvent* event) +{ + gtk_event_controller_handle_event(GTK_EVENT_CONTROLLER(m_gesture.get()), event); +} + +void GestureController::DragGesture::handleDrag(const GdkEvent* event, double x, double y) +{ + ASSERT(m_inDrag); + GUniquePtr<GdkEvent> scrollEvent(gdk_event_new(GDK_SCROLL)); + scrollEvent->scroll.time = event->touch.time; + scrollEvent->scroll.x = m_start.x(); + scrollEvent->scroll.y = m_start.y(); + scrollEvent->scroll.x_root = event->touch.x_root; + scrollEvent->scroll.y_root = event->touch.y_root; + scrollEvent->scroll.direction = GDK_SCROLL_SMOOTH; + scrollEvent->scroll.delta_x = (m_offset.x() - x) / Scrollbar::pixelsPerLineStep(); + scrollEvent->scroll.delta_y = (m_offset.y() - y) / Scrollbar::pixelsPerLineStep(); + scrollEvent->scroll.state = event->touch.state; + m_page.handleWheelEvent(NativeWebWheelEvent(scrollEvent.get())); +} + +void GestureController::DragGesture::handleTap(const GdkEvent* event) +{ + ASSERT(!m_inDrag); + GUniquePtr<GdkEvent> pointerEvent(gdk_event_new(GDK_MOTION_NOTIFY)); + pointerEvent->motion.time = event->touch.time; + pointerEvent->motion.x = event->touch.x; + pointerEvent->motion.y = event->touch.y; + pointerEvent->motion.x_root = event->touch.x_root; + pointerEvent->motion.y_root = event->touch.y_root; + pointerEvent->motion.state = event->touch.state; + m_page.handleMouseEvent(NativeWebMouseEvent(pointerEvent.get(), 0)); + + pointerEvent.reset(gdk_event_new(GDK_BUTTON_PRESS)); + pointerEvent->button.button = 1; + pointerEvent->button.time = event->touch.time; + pointerEvent->button.x = event->touch.x; + pointerEvent->button.y = event->touch.y; + pointerEvent->button.x_root = event->touch.x_root; + pointerEvent->button.y_root = event->touch.y_root; + m_page.handleMouseEvent(NativeWebMouseEvent(pointerEvent.get(), 1)); + + pointerEvent->type = GDK_BUTTON_RELEASE; + m_page.handleMouseEvent(NativeWebMouseEvent(pointerEvent.get(), 0)); +} + +void GestureController::DragGesture::begin(DragGesture* dragGesture, double x, double y, GtkGesture* gesture) +{ + GdkEventSequence* sequence = gtk_gesture_single_get_current_sequence(GTK_GESTURE_SINGLE(gesture)); + gtk_gesture_set_sequence_state(gesture, sequence, GTK_EVENT_SEQUENCE_CLAIMED); + dragGesture->m_inDrag = false; + dragGesture->m_start.set(x, y); + dragGesture->m_offset.set(0, 0); + + GtkWidget* widget = gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture)); + unsigned delay; + g_object_get(gtk_widget_get_settings(widget), "gtk-long-press-time", &delay, nullptr); + dragGesture->m_longPressTimeout.startOneShot(delay / 1000.0); +} + +void GestureController::DragGesture::update(DragGesture* dragGesture, double x, double y, GtkGesture* gesture) +{ + GdkEventSequence* sequence = gtk_gesture_single_get_current_sequence(GTK_GESTURE_SINGLE(gesture)); + gtk_gesture_set_sequence_state(gesture, sequence, GTK_EVENT_SEQUENCE_CLAIMED); + + GtkWidget* widget = gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture)); + if (!dragGesture->m_inDrag && gtk_drag_check_threshold(widget, dragGesture->m_start.x(), dragGesture->m_start.y(), dragGesture->m_start.x() + x, dragGesture->m_start.y() + y)) { + dragGesture->m_inDrag = true; + dragGesture->m_longPressTimeout.stop(); + } + + if (dragGesture->m_inDrag) + dragGesture->handleDrag(gtk_gesture_get_last_event(gesture, sequence), x, y); + dragGesture->m_offset.set(x, y); +} + +void GestureController::DragGesture::end(DragGesture* dragGesture, GdkEventSequence* sequence, GtkGesture* gesture) +{ + dragGesture->m_longPressTimeout.stop(); + if (!dragGesture->m_inDrag) { + dragGesture->handleTap(gtk_gesture_get_last_event(gesture, sequence)); + gtk_gesture_set_state(gesture, GTK_EVENT_SEQUENCE_DENIED); + } else if (!gtk_gesture_handles_sequence(gesture, sequence)) + gtk_gesture_set_state(gesture, GTK_EVENT_SEQUENCE_DENIED); +} + +void GestureController::DragGesture::longPressFired() +{ + m_inDrag = true; +} + +GestureController::DragGesture::DragGesture(WebPageProxy& page) + : Gesture(gtk_gesture_drag_new(page.viewWidget()), page) + , m_longPressTimeout(RunLoop::main(), this, &GestureController::DragGesture::longPressFired) + , m_inDrag(false) +{ + gtk_gesture_single_set_touch_only(GTK_GESTURE_SINGLE(m_gesture.get()), TRUE); + g_signal_connect_swapped(m_gesture.get(), "drag-begin", G_CALLBACK(begin), this); + g_signal_connect_swapped(m_gesture.get(), "drag-update", G_CALLBACK(update), this); + g_signal_connect_swapped(m_gesture.get(), "end", G_CALLBACK(end), this); +} + +IntPoint GestureController::ZoomGesture::center() const +{ + double x, y; + gtk_gesture_get_bounding_box_center(m_gesture.get(), &x, &y); + return IntPoint(x, y); +} + +void GestureController::ZoomGesture::begin(ZoomGesture* zoomGesture, GdkEventSequence*, GtkGesture* gesture) +{ + gtk_gesture_set_state(gesture, GTK_EVENT_SEQUENCE_CLAIMED); + + zoomGesture->m_initialScale = zoomGesture->m_page.pageScaleFactor(); + zoomGesture->m_page.getCenterForZoomGesture(zoomGesture->center(), zoomGesture->m_initialPoint); +} + +void GestureController::ZoomGesture::handleZoom() +{ + IntPoint scaledOriginOffset = m_viewPoint; + scaledOriginOffset.scale(1 / m_scale, 1 / m_scale); + + IntPoint newOrigin = m_initialPoint; + newOrigin.moveBy(-scaledOriginOffset); + newOrigin.scale(m_scale, m_scale); + + m_page.scalePage(m_scale, newOrigin); +} + +void GestureController::ZoomGesture::scaleChanged(ZoomGesture* zoomGesture, double scale, GtkGesture*) +{ + zoomGesture->m_scale = zoomGesture->m_initialScale * scale; + zoomGesture->m_viewPoint = zoomGesture->center(); + if (zoomGesture->m_idle.isActive()) + return; + + zoomGesture->m_idle.startOneShot(0); +} + +GestureController::ZoomGesture::ZoomGesture(WebPageProxy& page) + : Gesture(gtk_gesture_zoom_new(page.viewWidget()), page) + , m_initialScale(0) + , m_scale(0) + , m_idle(RunLoop::main(), this, &GestureController::ZoomGesture::handleZoom) +{ + g_signal_connect_swapped(m_gesture.get(), "begin", G_CALLBACK(begin), this); + g_signal_connect_swapped(m_gesture.get(), "scale-changed", G_CALLBACK(scaleChanged), this); +} + +} // namespace WebKit + +#endif // HAVE(GTK_GESTURES) diff --git a/Source/WebKit2/UIProcess/gtk/GestureController.h b/Source/WebKit2/UIProcess/gtk/GestureController.h new file mode 100644 index 000000000..86792df42 --- /dev/null +++ b/Source/WebKit2/UIProcess/gtk/GestureController.h @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2014 Igalia S.L. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef GestureController_h +#define GestureController_h + +#if HAVE(GTK_GESTURES) + +#include <WebCore/FloatPoint.h> +#include <wtf/Noncopyable.h> +#include <wtf/RunLoop.h> +#include <wtf/glib/GRefPtr.h> + +typedef union _GdkEvent GdkEvent; +typedef struct _GdkEventSequence GdkEventSequence; +typedef struct _GtkGesture GtkGesture; + +namespace WebKit { +class WebPageProxy; + +class GestureController { + WTF_MAKE_NONCOPYABLE(GestureController); + +public: + GestureController(WebPageProxy&); + + bool isProcessingGestures() const; + bool handleEvent(const GdkEvent*); + +private: + class Gesture { + public: + bool isActive() const; + void handleEvent(const GdkEvent*); + + protected: + Gesture(GtkGesture*, WebPageProxy&); + + GRefPtr<GtkGesture> m_gesture; + WebPageProxy& m_page; + }; + + class DragGesture final : public Gesture { + public: + DragGesture(WebPageProxy&); + + private: + void handleDrag(const GdkEvent*, double x, double y); + void handleTap(const GdkEvent*); + void longPressFired(); + + static void begin(DragGesture*, double x, double y, GtkGesture*); + static void update(DragGesture*, double x, double y, GtkGesture*); + static void end(DragGesture*, GdkEventSequence*, GtkGesture*); + + WebCore::FloatPoint m_start; + WebCore::FloatPoint m_offset; + RunLoop::Timer<DragGesture> m_longPressTimeout; + GRefPtr<GtkGesture> m_longPress; + bool m_inDrag; + }; + + class ZoomGesture final : public Gesture { + public: + ZoomGesture(WebPageProxy&); + + private: + WebCore::IntPoint center() const; + void handleZoom(); + + static void begin(ZoomGesture*, GdkEventSequence*, GtkGesture*); + static void scaleChanged(ZoomGesture*, double scale, GtkGesture*); + + gdouble m_initialScale; + gdouble m_scale; + WebCore::IntPoint m_initialPoint; + WebCore::IntPoint m_viewPoint; + RunLoop::Timer<ZoomGesture> m_idle; + }; + + DragGesture m_dragGesture; + ZoomGesture m_zoomGesture; +}; + +} // namespace WebKit + +#endif // HAVE(GTK_GESTURES) + +#endif // GestureController_h diff --git a/Source/WebKit2/UIProcess/gtk/InputMethodFilter.cpp b/Source/WebKit2/UIProcess/gtk/InputMethodFilter.cpp new file mode 100644 index 000000000..fc098ac67 --- /dev/null +++ b/Source/WebKit2/UIProcess/gtk/InputMethodFilter.cpp @@ -0,0 +1,456 @@ +/* + * Copyright (C) 2012, 2014 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "InputMethodFilter.h" + +#include "NativeWebKeyboardEvent.h" +#include "WebPageProxy.h" +#include <WebCore/Color.h> +#include <WebCore/CompositionResults.h> +#include <WebCore/Editor.h> +#include <WebCore/GUniquePtrGtk.h> +#include <WebCore/IntRect.h> +#include <gdk/gdkkeysyms.h> +#include <gtk/gtk.h> +#include <wtf/Vector.h> +#include <wtf/glib/GUniquePtr.h> + +using namespace WebCore; + +namespace WebKit { + +void InputMethodFilter::handleCommitCallback(InputMethodFilter* filter, const char* compositionString) +{ + filter->handleCommit(compositionString); +} + +void InputMethodFilter::handlePreeditStartCallback(InputMethodFilter* filter) +{ + filter->handlePreeditStart(); +} + +void InputMethodFilter::handlePreeditChangedCallback(InputMethodFilter* filter) +{ + filter->handlePreeditChanged(); +} + +void InputMethodFilter::handlePreeditEndCallback(InputMethodFilter* filter) +{ + filter->handlePreeditEnd(); +} + +InputMethodFilter::InputMethodFilter() + : m_context(adoptGRef(gtk_im_multicontext_new())) + , m_page(nullptr) + , m_enabled(false) + , m_composingTextCurrently(false) + , m_filteringKeyEvent(false) + , m_preeditChanged(false) + , m_preventNextCommit(false) + , m_justSentFakeKeyUp(false) + , m_cursorOffset(0) + , m_lastFilteredKeyPressCodeWithNoResults(GDK_KEY_VoidSymbol) +#if ENABLE(API_TESTS) + , m_testingMode(false) +#endif +{ + g_signal_connect_swapped(m_context.get(), "commit", G_CALLBACK(handleCommitCallback), this); + g_signal_connect_swapped(m_context.get(), "preedit-start", G_CALLBACK(handlePreeditStartCallback), this); + g_signal_connect_swapped(m_context.get(), "preedit-changed", G_CALLBACK(handlePreeditChangedCallback), this); + g_signal_connect_swapped(m_context.get(), "preedit-end", G_CALLBACK(handlePreeditEndCallback), this); +} + +InputMethodFilter::~InputMethodFilter() +{ + g_signal_handlers_disconnect_matched(m_context.get(), G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, this); +} + +void InputMethodFilter::setEnabled(bool enabled) +{ + ASSERT(m_page); + + // Notify focus out before changing the m_enabled. + if (!enabled) + notifyFocusedOut(); + m_enabled = enabled; + if (enabled) + notifyFocusedIn(); +} + +void InputMethodFilter::setCursorRect(const IntRect& cursorRect) +{ + ASSERT(m_page); + + if (!m_enabled) + return; + + // Don't move the window unless the cursor actually moves more than 10 + // pixels. This prevents us from making the window flash during minor + // cursor adjustments. + static const int windowMovementThreshold = 10 * 10; + if (cursorRect.location().distanceSquaredToPoint(m_lastCareLocation) < windowMovementThreshold) + return; + + m_lastCareLocation = cursorRect.location(); + IntRect translatedRect = cursorRect; + + GtkAllocation allocation; + gtk_widget_get_allocation(m_page->viewWidget(), &allocation); + translatedRect.move(allocation.x, allocation.y); + + GdkRectangle gdkCursorRect = translatedRect; + gtk_im_context_set_cursor_location(m_context.get(), &gdkCursorRect); +} + +void InputMethodFilter::handleKeyboardEvent(GdkEventKey* event, const String& simpleString, EventFakedForComposition faked) +{ +#if ENABLE(API_TESTS) + if (m_testingMode) { + logHandleKeyboardEventForTesting(event, simpleString, faked); + return; + } +#endif + + if (m_filterKeyEventCompletionHandler) { + m_filterKeyEventCompletionHandler(CompositionResults(simpleString), faked); + m_filterKeyEventCompletionHandler = nullptr; + } else + m_page->handleKeyboardEvent(NativeWebKeyboardEvent(reinterpret_cast<GdkEvent*>(event), CompositionResults(simpleString), faked, Vector<String>())); +} + +void InputMethodFilter::handleKeyboardEventWithCompositionResults(GdkEventKey* event, ResultsToSend resultsToSend, EventFakedForComposition faked) +{ +#if ENABLE(API_TESTS) + if (m_testingMode) { + logHandleKeyboardEventWithCompositionResultsForTesting(event, resultsToSend, faked); + return; + } +#endif + + if (m_filterKeyEventCompletionHandler) { + m_filterKeyEventCompletionHandler(CompositionResults(CompositionResults::WillSendCompositionResultsSoon), faked); + m_filterKeyEventCompletionHandler = nullptr; + } else + m_page->handleKeyboardEvent(NativeWebKeyboardEvent(reinterpret_cast<GdkEvent*>(event), CompositionResults(CompositionResults::WillSendCompositionResultsSoon), faked, Vector<String>())); + if (resultsToSend & Composition && !m_confirmedComposition.isNull()) + m_page->confirmComposition(m_confirmedComposition, -1, 0); + + if (resultsToSend & Preedit && !m_preedit.isNull()) { + m_page->setComposition(m_preedit, Vector<CompositionUnderline>{ CompositionUnderline(0, m_preedit.length(), Color(1, 1, 1), false) }, + m_cursorOffset, m_cursorOffset, 0 /* replacement start */, 0 /* replacement end */); + } +} + +void InputMethodFilter::filterKeyEvent(GdkEventKey* event, FilterKeyEventCompletionHandler&& completionHandler) +{ +#if ENABLE(API_TESTS) + ASSERT(m_page || m_testingMode); +#else + ASSERT(m_page); +#endif + m_filterKeyEventCompletionHandler = WTFMove(completionHandler); + if (!m_enabled) { + handleKeyboardEvent(event); + return; + } + + m_preeditChanged = false; + m_filteringKeyEvent = true; + + unsigned lastFilteredKeyPressCodeWithNoResults = m_lastFilteredKeyPressCodeWithNoResults; + m_lastFilteredKeyPressCodeWithNoResults = GDK_KEY_VoidSymbol; + + bool filtered = gtk_im_context_filter_keypress(m_context.get(), event); + m_filteringKeyEvent = false; + + bool justSentFakeKeyUp = m_justSentFakeKeyUp; + m_justSentFakeKeyUp = false; + if (justSentFakeKeyUp && event->type == GDK_KEY_RELEASE) + return; + + // Simple input methods work such that even normal keystrokes fire the + // commit signal. We detect those situations and treat them as normal + // key events, supplying the commit string as the key character. + if (filtered && !m_composingTextCurrently && !m_preeditChanged && m_confirmedComposition.length() == 1) { + handleKeyboardEvent(event, m_confirmedComposition); + m_confirmedComposition = String(); + return; + } + + if (filtered && event->type == GDK_KEY_PRESS) { + if (!m_preeditChanged && m_confirmedComposition.isNull()) { + m_composingTextCurrently = true; + m_lastFilteredKeyPressCodeWithNoResults = event->keyval; + return; + } + + handleKeyboardEventWithCompositionResults(event); + if (!m_confirmedComposition.isEmpty()) { + m_composingTextCurrently = false; + m_confirmedComposition = String(); + } + return; + } + + // If we previously filtered a key press event and it yielded no results. Suppress + // the corresponding key release event to avoid confusing the web content. + if (event->type == GDK_KEY_RELEASE && lastFilteredKeyPressCodeWithNoResults == event->keyval) + return; + + // At this point a keystroke was either: + // 1. Unfiltered + // 2. A filtered keyup event. As the IME code in EditorClient.h doesn't + // ever look at keyup events, we send any composition results before + // the key event. + // Both might have composition results or not. + // + // It's important to send the composition results before the event + // because some IM modules operate that way. For example (taken from + // the Chromium source), the latin-post input method gives this sequence + // when you press 'a' and then backspace: + // 1. keydown 'a' (filtered) + // 2. preedit changed to "a" + // 3. keyup 'a' (unfiltered) + // 4. keydown Backspace (unfiltered) + // 5. commit "a" + // 6. preedit end + if (!m_confirmedComposition.isEmpty()) + confirmComposition(); + if (m_preeditChanged) + updatePreedit(); + handleKeyboardEvent(event); +} + +void InputMethodFilter::confirmComposition() +{ +#if ENABLE(API_TESTS) + if (m_testingMode) { + logConfirmCompositionForTesting(); + m_confirmedComposition = String(); + return; + } +#endif + m_page->confirmComposition(m_confirmedComposition, -1, 0); + m_confirmedComposition = String(); +} + +void InputMethodFilter::updatePreedit() +{ +#if ENABLE(API_TESTS) + if (m_testingMode) { + logSetPreeditForTesting(); + return; + } +#endif + // FIXME: We should parse the PangoAttrList that we get from the IM context here. + m_page->setComposition(m_preedit, Vector<CompositionUnderline>{ CompositionUnderline(0, m_preedit.length(), Color(1, 1, 1), false) }, + m_cursorOffset, m_cursorOffset, 0 /* replacement start */, 0 /* replacement end */); + m_preeditChanged = false; +} + +void InputMethodFilter::notifyFocusedIn() +{ +#if ENABLE(API_TESTS) + ASSERT(m_page || m_testingMode); +#else + ASSERT(m_page); +#endif + if (!m_enabled) + return; + + gtk_im_context_focus_in(m_context.get()); +} + +void InputMethodFilter::notifyFocusedOut() +{ +#if ENABLE(API_TESTS) + ASSERT(m_page || m_testingMode); +#else + ASSERT(m_page); +#endif + if (!m_enabled) + return; + + confirmCurrentComposition(); + cancelContextComposition(); + gtk_im_context_focus_out(m_context.get()); +} + +void InputMethodFilter::notifyMouseButtonPress() +{ +#if ENABLE(API_TESTS) + ASSERT(m_page || m_testingMode); +#else + ASSERT(m_page); +#endif + + // Confirming the composition may trigger a selection change, which + // might trigger further unwanted actions on the context, so we prevent + // that by setting m_composingTextCurrently to false. + confirmCurrentComposition(); + cancelContextComposition(); +} + +void InputMethodFilter::confirmCurrentComposition() +{ + if (!m_composingTextCurrently) + return; + m_page->confirmComposition(String(), -1, 0); + m_composingTextCurrently = false; +} + +void InputMethodFilter::cancelContextComposition() +{ + m_preventNextCommit = !m_preedit.isEmpty(); + + gtk_im_context_reset(m_context.get()); + + m_composingTextCurrently = false; + m_justSentFakeKeyUp = false; + m_preedit = String(); + m_confirmedComposition = String(); +} + +void InputMethodFilter::sendCompositionAndPreeditWithFakeKeyEvents(ResultsToSend resultsToSend) +{ + // The Windows composition key event code is 299 or VK_PROCESSKEY. We need to + // emit this code for web compatibility reasons when key events trigger + // composition results. GDK doesn't have an equivalent, so we send VoidSymbol + // here to WebCore. PlatformKeyEvent knows to convert this code into + // VK_PROCESSKEY. + static const int compositionEventKeyCode = GDK_KEY_VoidSymbol; + + GUniquePtr<GdkEvent> event(gdk_event_new(GDK_KEY_PRESS)); + event->key.time = GDK_CURRENT_TIME; + event->key.keyval = compositionEventKeyCode; + handleKeyboardEventWithCompositionResults(&event->key, resultsToSend, EventFaked); + + m_confirmedComposition = String(); + if (resultsToSend & Composition) + m_composingTextCurrently = false; + + event->type = GDK_KEY_RELEASE; + handleKeyboardEvent(&event->key, String(), EventFaked); + m_justSentFakeKeyUp = true; +} + +void InputMethodFilter::handleCommit(const char* compositionString) +{ + if (m_preventNextCommit) { + m_preventNextCommit = false; + return; + } + + if (!m_enabled) + return; + + m_confirmedComposition.append(String::fromUTF8(compositionString)); + + // If the commit was triggered outside of a key event, just send + // the IME event now. If we are handling a key event, we'll decide + // later how to handle this. + if (!m_filteringKeyEvent) + sendCompositionAndPreeditWithFakeKeyEvents(Composition); +} + +void InputMethodFilter::handlePreeditStart() +{ + if (m_preventNextCommit || !m_enabled) + return; + m_preeditChanged = true; + m_preedit = emptyString(); +} + +void InputMethodFilter::handlePreeditChanged() +{ + if (!m_enabled) + return; + + GUniqueOutPtr<gchar> newPreedit; + gtk_im_context_get_preedit_string(m_context.get(), &newPreedit.outPtr(), nullptr, &m_cursorOffset); + + if (m_preventNextCommit) { + if (strlen(newPreedit.get()) > 0) + m_preventNextCommit = false; + else + return; + } + + m_preedit = String::fromUTF8(newPreedit.get()); + m_cursorOffset = std::min(std::max(m_cursorOffset, 0), static_cast<int>(m_preedit.length())); + + m_composingTextCurrently = !m_preedit.isEmpty(); + m_preeditChanged = true; + + if (!m_filteringKeyEvent) + sendCompositionAndPreeditWithFakeKeyEvents(Preedit); +} + +void InputMethodFilter::handlePreeditEnd() +{ + if (m_preventNextCommit || !m_enabled) + return; + + m_preedit = String(); + m_cursorOffset = 0; + m_preeditChanged = true; + + if (!m_filteringKeyEvent) + updatePreedit(); +} + +#if ENABLE(API_TESTS) +void InputMethodFilter::logHandleKeyboardEventForTesting(GdkEventKey* event, const String& eventString, EventFakedForComposition faked) +{ + const char* eventType = event->type == GDK_KEY_RELEASE ? "release" : "press"; + const char* fakedString = faked == EventFaked ? " (faked)" : ""; + if (!eventString.isNull()) + m_events.append(String::format("sendSimpleKeyEvent type=%s keycode=%x text='%s'%s", eventType, event->keyval, eventString.utf8().data(), fakedString)); + else + m_events.append(String::format("sendSimpleKeyEvent type=%s keycode=%x%s", eventType, event->keyval, fakedString)); +} + +void InputMethodFilter::logHandleKeyboardEventWithCompositionResultsForTesting(GdkEventKey* event, ResultsToSend resultsToSend, EventFakedForComposition faked) +{ + const char* eventType = event->type == GDK_KEY_RELEASE ? "release" : "press"; + const char* fakedString = faked == EventFaked ? " (faked)" : ""; + m_events.append(String::format("sendKeyEventWithCompositionResults type=%s keycode=%u%s", eventType, event->keyval, fakedString)); + + if (resultsToSend & Composition && !m_confirmedComposition.isNull()) + logConfirmCompositionForTesting(); + if (resultsToSend & Preedit && !m_preedit.isNull()) + logSetPreeditForTesting(); +} + +void InputMethodFilter::logConfirmCompositionForTesting() +{ + if (m_confirmedComposition.isEmpty()) + m_events.append(String("confirmCurrentcomposition")); + else + m_events.append(String::format("confirmComposition '%s'", m_confirmedComposition.utf8().data())); +} + +void InputMethodFilter::logSetPreeditForTesting() +{ + m_events.append(String::format("setPreedit text='%s' cursorOffset=%i", m_preedit.utf8().data(), m_cursorOffset)); +} +#endif // ENABLE(API_TESTS) + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/gtk/InputMethodFilter.h b/Source/WebKit2/UIProcess/gtk/InputMethodFilter.h new file mode 100644 index 000000000..6d2cee6b5 --- /dev/null +++ b/Source/WebKit2/UIProcess/gtk/InputMethodFilter.h @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2012, 2014 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef InputMethodFilter_h +#define InputMethodFilter_h + +#include <WebCore/IntPoint.h> +#include <functional> +#include <wtf/Noncopyable.h> +#include <wtf/glib/GRefPtr.h> +#include <wtf/text/WTFString.h> + +typedef struct _GdkEventKey GdkEventKey; +typedef struct _GtkIMContext GtkIMContext; + +namespace WebCore { +struct CompositionResults; +class IntRect; +} + +namespace WebKit { + +class WebPageProxy; + +class InputMethodFilter { + WTF_MAKE_NONCOPYABLE(InputMethodFilter); +public: + enum EventFakedForComposition { + EventFaked, + EventNotFaked + }; + + InputMethodFilter(); + ~InputMethodFilter(); + + GtkIMContext* context() const { return m_context.get(); } + + void setPage(WebPageProxy* page) { m_page = page; } + + void setEnabled(bool); + void setCursorRect(const WebCore::IntRect&); + + using FilterKeyEventCompletionHandler = std::function<void (const WebCore::CompositionResults&, InputMethodFilter::EventFakedForComposition)>; + void filterKeyEvent(GdkEventKey*, FilterKeyEventCompletionHandler&& = nullptr); + void notifyFocusedIn(); + void notifyFocusedOut(); + void notifyMouseButtonPress(); + +#if ENABLE(API_TESTS) + void setTestingMode(bool enable) { m_testingMode = enable; } + const Vector<String>& events() const { return m_events; } +#endif + +private: + enum ResultsToSend { + Preedit = 1 << 1, + Composition = 1 << 2, + PreeditAndComposition = Preedit | Composition + }; + + static void handleCommitCallback(InputMethodFilter*, const char* compositionString); + static void handlePreeditStartCallback(InputMethodFilter*); + static void handlePreeditChangedCallback(InputMethodFilter*); + static void handlePreeditEndCallback(InputMethodFilter*); + + void handleCommit(const char* compositionString); + void handlePreeditChanged(); + void handlePreeditStart(); + void handlePreeditEnd(); + + void handleKeyboardEvent(GdkEventKey*, const String& eventString = String(), EventFakedForComposition = EventNotFaked); + void handleKeyboardEventWithCompositionResults(GdkEventKey*, ResultsToSend = PreeditAndComposition, EventFakedForComposition = EventNotFaked); + + void sendCompositionAndPreeditWithFakeKeyEvents(ResultsToSend); + void confirmComposition(); + void updatePreedit(); + void confirmCurrentComposition(); + void cancelContextComposition(); + +#if ENABLE(API_TESTS) + void logHandleKeyboardEventForTesting(GdkEventKey*, const String&, EventFakedForComposition); + void logHandleKeyboardEventWithCompositionResultsForTesting(GdkEventKey*, ResultsToSend, EventFakedForComposition); + void logConfirmCompositionForTesting(); + void logSetPreeditForTesting(); +#endif + + GRefPtr<GtkIMContext> m_context; + WebPageProxy* m_page; + unsigned m_enabled : 1; + unsigned m_composingTextCurrently : 1; + unsigned m_filteringKeyEvent : 1; + unsigned m_preeditChanged : 1; + unsigned m_preventNextCommit : 1; + unsigned m_justSentFakeKeyUp : 1; + int m_cursorOffset; + unsigned m_lastFilteredKeyPressCodeWithNoResults; + WebCore::IntPoint m_lastCareLocation; + String m_confirmedComposition; + String m_preedit; + + FilterKeyEventCompletionHandler m_filterKeyEventCompletionHandler; + +#if ENABLE(API_TESTS) + bool m_testingMode; + Vector<String> m_events; +#endif +}; + +} // namespace WebKit + +#endif // InputMethodFilter_h diff --git a/Source/WebKit2/UIProcess/gtk/KeyBindingTranslator.cpp b/Source/WebKit2/UIProcess/gtk/KeyBindingTranslator.cpp new file mode 100644 index 000000000..f179f16f0 --- /dev/null +++ b/Source/WebKit2/UIProcess/gtk/KeyBindingTranslator.cpp @@ -0,0 +1,218 @@ +/* + * Copyright (C) 2010, 2011 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "KeyBindingTranslator.h" + +#include <gdk/gdkkeysyms.h> +#include <gtk/gtk.h> + +namespace WebKit { + +static void backspaceCallback(GtkWidget* widget, KeyBindingTranslator* translator) +{ + g_signal_stop_emission_by_name(widget, "backspace"); + translator->addPendingEditorCommand("DeleteBackward"); +} + +static void selectAllCallback(GtkWidget* widget, gboolean select, KeyBindingTranslator* translator) +{ + g_signal_stop_emission_by_name(widget, "select-all"); + translator->addPendingEditorCommand(select ? "SelectAll" : "Unselect"); +} + +static void cutClipboardCallback(GtkWidget* widget, KeyBindingTranslator* translator) +{ + g_signal_stop_emission_by_name(widget, "cut-clipboard"); + translator->addPendingEditorCommand("Cut"); +} + +static void copyClipboardCallback(GtkWidget* widget, KeyBindingTranslator* translator) +{ + g_signal_stop_emission_by_name(widget, "copy-clipboard"); + translator->addPendingEditorCommand("Copy"); +} + +static void pasteClipboardCallback(GtkWidget* widget, KeyBindingTranslator* translator) +{ + g_signal_stop_emission_by_name(widget, "paste-clipboard"); + translator->addPendingEditorCommand("Paste"); +} + +static void toggleOverwriteCallback(GtkWidget* widget, KeyBindingTranslator* translator) +{ + g_signal_stop_emission_by_name(widget, "toggle-overwrite"); + translator->addPendingEditorCommand("OverWrite"); +} + +// GTK+ will still send these signals to the web view. So we can safely stop signal +// emission without breaking accessibility. +static void popupMenuCallback(GtkWidget* widget, KeyBindingTranslator*) +{ + g_signal_stop_emission_by_name(widget, "popup-menu"); +} + +static void showHelpCallback(GtkWidget* widget, KeyBindingTranslator*) +{ + g_signal_stop_emission_by_name(widget, "show-help"); +} + +static const char* const gtkDeleteCommands[][2] = { + { "DeleteBackward", "DeleteForward" }, // Characters + { "DeleteWordBackward", "DeleteWordForward" }, // Word ends + { "DeleteWordBackward", "DeleteWordForward" }, // Words + { "DeleteToBeginningOfLine", "DeleteToEndOfLine" }, // Lines + { "DeleteToBeginningOfLine", "DeleteToEndOfLine" }, // Line ends + { "DeleteToBeginningOfParagraph", "DeleteToEndOfParagraph" }, // Paragraph ends + { "DeleteToBeginningOfParagraph", "DeleteToEndOfParagraph" }, // Paragraphs + { 0, 0 } // Whitespace (M-\ in Emacs) +}; + +static void deleteFromCursorCallback(GtkWidget* widget, GtkDeleteType deleteType, gint count, KeyBindingTranslator* translator) +{ + g_signal_stop_emission_by_name(widget, "delete-from-cursor"); + int direction = count > 0 ? 1 : 0; + + // Ensuring that deleteType <= G_N_ELEMENTS here results in a compiler warning + // that the condition is always true. + + if (deleteType == GTK_DELETE_WORDS) { + if (!direction) { + translator->addPendingEditorCommand("MoveWordForward"); + translator->addPendingEditorCommand("MoveWordBackward"); + } else { + translator->addPendingEditorCommand("MoveWordBackward"); + translator->addPendingEditorCommand("MoveWordForward"); + } + } else if (deleteType == GTK_DELETE_DISPLAY_LINES) { + if (!direction) + translator->addPendingEditorCommand("MoveToBeginningOfLine"); + else + translator->addPendingEditorCommand("MoveToEndOfLine"); + } else if (deleteType == GTK_DELETE_PARAGRAPHS) { + if (!direction) + translator->addPendingEditorCommand("MoveToBeginningOfParagraph"); + else + translator->addPendingEditorCommand("MoveToEndOfParagraph"); + } + + const char* rawCommand = gtkDeleteCommands[deleteType][direction]; + if (!rawCommand) + return; + + for (int i = 0; i < abs(count); i++) + translator->addPendingEditorCommand(rawCommand); +} + +static const char* const gtkMoveCommands[][4] = { + { "MoveBackward", "MoveForward", + "MoveBackwardAndModifySelection", "MoveForwardAndModifySelection" }, // Forward/backward grapheme + { "MoveLeft", "MoveRight", + "MoveBackwardAndModifySelection", "MoveForwardAndModifySelection" }, // Left/right grapheme + { "MoveWordBackward", "MoveWordForward", + "MoveWordBackwardAndModifySelection", "MoveWordForwardAndModifySelection" }, // Forward/backward word + { "MoveUp", "MoveDown", + "MoveUpAndModifySelection", "MoveDownAndModifySelection" }, // Up/down line + { "MoveToBeginningOfLine", "MoveToEndOfLine", + "MoveToBeginningOfLineAndModifySelection", "MoveToEndOfLineAndModifySelection" }, // Up/down line ends + { 0, 0, + "MoveParagraphBackwardAndModifySelection", "MoveParagraphForwardAndModifySelection" }, // Up/down paragraphs + { "MoveToBeginningOfParagraph", "MoveToEndOfParagraph", + "MoveToBeginningOfParagraphAndModifySelection", "MoveToEndOfParagraphAndModifySelection" }, // Up/down paragraph ends. + { "MovePageUp", "MovePageDown", + "MovePageUpAndModifySelection", "MovePageDownAndModifySelection" }, // Up/down page + { "MoveToBeginningOfDocument", "MoveToEndOfDocument", + "MoveToBeginningOfDocumentAndModifySelection", "MoveToEndOfDocumentAndModifySelection" }, // Begin/end of buffer + { 0, 0, + 0, 0 } // Horizontal page movement +}; + +static void moveCursorCallback(GtkWidget* widget, GtkMovementStep step, gint count, gboolean extendSelection, KeyBindingTranslator* translator) +{ + g_signal_stop_emission_by_name(widget, "move-cursor"); + int direction = count > 0 ? 1 : 0; + if (extendSelection) + direction += 2; + + if (static_cast<unsigned>(step) >= G_N_ELEMENTS(gtkMoveCommands)) + return; + + const char* rawCommand = gtkMoveCommands[step][direction]; + if (!rawCommand) + return; + + for (int i = 0; i < abs(count); i++) + translator->addPendingEditorCommand(rawCommand); +} + +KeyBindingTranslator::KeyBindingTranslator() + : m_nativeWidget(gtk_text_view_new()) +{ + g_signal_connect(m_nativeWidget.get(), "backspace", G_CALLBACK(backspaceCallback), this); + g_signal_connect(m_nativeWidget.get(), "cut-clipboard", G_CALLBACK(cutClipboardCallback), this); + g_signal_connect(m_nativeWidget.get(), "copy-clipboard", G_CALLBACK(copyClipboardCallback), this); + g_signal_connect(m_nativeWidget.get(), "paste-clipboard", G_CALLBACK(pasteClipboardCallback), this); + g_signal_connect(m_nativeWidget.get(), "select-all", G_CALLBACK(selectAllCallback), this); + g_signal_connect(m_nativeWidget.get(), "move-cursor", G_CALLBACK(moveCursorCallback), this); + g_signal_connect(m_nativeWidget.get(), "delete-from-cursor", G_CALLBACK(deleteFromCursorCallback), this); + g_signal_connect(m_nativeWidget.get(), "toggle-overwrite", G_CALLBACK(toggleOverwriteCallback), this); + g_signal_connect(m_nativeWidget.get(), "popup-menu", G_CALLBACK(popupMenuCallback), this); + g_signal_connect(m_nativeWidget.get(), "show-help", G_CALLBACK(showHelpCallback), this); +} + +struct KeyCombinationEntry { + unsigned gdkKeyCode; + unsigned state; + const char* name; +}; + +static const KeyCombinationEntry customKeyBindings[] = { + { GDK_KEY_b, GDK_CONTROL_MASK, "ToggleBold" }, + { GDK_KEY_i, GDK_CONTROL_MASK, "ToggleItalic" }, + { GDK_KEY_Escape, 0, "Cancel" }, + { GDK_KEY_greater, GDK_CONTROL_MASK, "Cancel" }, + { GDK_KEY_Tab, 0, "InsertTab" }, + { GDK_KEY_Tab, GDK_SHIFT_MASK, "InsertBacktab" }, +}; + +Vector<String> KeyBindingTranslator::commandsForKeyEvent(GdkEventKey* event) +{ + ASSERT(m_pendingEditorCommands.isEmpty()); + + gtk_bindings_activate_event(G_OBJECT(m_nativeWidget.get()), event); + if (!m_pendingEditorCommands.isEmpty()) + return WTFMove(m_pendingEditorCommands); + + // Special-case enter keys for we want them to work regardless of modifier. + if ((event->keyval == GDK_KEY_Return || event->keyval == GDK_KEY_KP_Enter || event->keyval == GDK_KEY_ISO_Enter)) + return { "InsertNewLine" }; + + // For keypress events, we want charCode(), but keyCode() does that. + unsigned mapKey = event->state << 16 | event->keyval; + if (!mapKey) + return { }; + + for (unsigned i = 0; i < G_N_ELEMENTS(customKeyBindings); ++i) { + if (mapKey == (customKeyBindings[i].state << 16 | customKeyBindings[i].gdkKeyCode)) + return { customKeyBindings[i].name }; + } + + return { }; +} + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/gtk/KeyBindingTranslator.h b/Source/WebKit2/UIProcess/gtk/KeyBindingTranslator.h new file mode 100644 index 000000000..b2ded5de6 --- /dev/null +++ b/Source/WebKit2/UIProcess/gtk/KeyBindingTranslator.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2010, 2011 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef KeyBindingTranslator_h +#define KeyBindingTranslator_h + +#include <WebCore/GRefPtrGtk.h> +#include <wtf/Vector.h> +#include <wtf/text/WTFString.h> + +typedef struct _GdkEventKey GdkEventKey; + +namespace WebKit { + +class KeyBindingTranslator { +public: + KeyBindingTranslator(); + + Vector<String> commandsForKeyEvent(GdkEventKey*); + void addPendingEditorCommand(const char* command) { m_pendingEditorCommands.append(command); } + +private: + GRefPtr<GtkWidget> m_nativeWidget; + Vector<String> m_pendingEditorCommands; +}; + +} // namespace WebKit + +#endif + + diff --git a/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.cpp b/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.cpp new file mode 100644 index 000000000..62abab5b0 --- /dev/null +++ b/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.cpp @@ -0,0 +1,286 @@ +/* + * Copyright (C) 2012,2014 Igalia S.L. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "RedirectedXCompositeWindow.h" + +#if USE(REDIRECTED_XCOMPOSITE_WINDOW) + +#include <WebCore/CairoUtilities.h> +#include <WebCore/PlatformDisplayX11.h> +#include <X11/Xlib.h> +#include <X11/extensions/Xcomposite.h> +#include <X11/extensions/Xdamage.h> +#include <cairo-xlib.h> +#include <gdk/gdkx.h> +#include <glib.h> +#include <gtk/gtk.h> +#include <wtf/HashMap.h> +#include <wtf/NeverDestroyed.h> + +using namespace WebCore; + +namespace WebKit { + +class XDamageNotifier { + WTF_MAKE_NONCOPYABLE(XDamageNotifier); + WTF_MAKE_FAST_ALLOCATED; +public: + static int s_damageEventBase; + + XDamageNotifier() + { + } + + void add(Window window, std::function<void()> notifyFunction) + { + if (m_notifyFunctions.isEmpty()) + gdk_window_add_filter(nullptr, reinterpret_cast<GdkFilterFunc>(&filterXDamageEvent), this); + m_notifyFunctions.add(window, WTFMove(notifyFunction)); + } + + void remove(Window window) + { + m_notifyFunctions.remove(window); + if (m_notifyFunctions.isEmpty()) + gdk_window_remove_filter(nullptr, reinterpret_cast<GdkFilterFunc>(&filterXDamageEvent), this); + } + +private: + static GdkFilterReturn filterXDamageEvent(GdkXEvent* event, GdkEvent*, XDamageNotifier* notifier) + { + return notifier->filterXEvent(static_cast<XEvent*>(event)); + } + + GdkFilterReturn filterXEvent(XEvent* event) const + { + if (event->type != s_damageEventBase + XDamageNotify) + return GDK_FILTER_CONTINUE; + + XDamageNotifyEvent* damageEvent = reinterpret_cast<XDamageNotifyEvent*>(event); + if (const auto& notifyFunction = m_notifyFunctions.get(damageEvent->drawable)) { + notifyFunction(); + XDamageSubtract(event->xany.display, damageEvent->damage, None, None); + return GDK_FILTER_REMOVE; + } + + return GDK_FILTER_CONTINUE; + } + + HashMap<Window, std::function<void()>> m_notifyFunctions; +}; + +int XDamageNotifier::s_damageEventBase = 0; + +static XDamageNotifier& xDamageNotifier() +{ + static NeverDestroyed<XDamageNotifier> notifier; + return notifier; +} + +static bool supportsXDamageAndXComposite(GdkWindow* window) +{ + static bool initialized = false; + static bool hasExtensions = false; + + if (initialized) + return hasExtensions; + + initialized = true; + Display* display = GDK_DISPLAY_XDISPLAY(gdk_window_get_display(window)); + + int errorBase; + if (!XDamageQueryExtension(display, &XDamageNotifier::s_damageEventBase, &errorBase)) + return false; + + int eventBase; + if (!XCompositeQueryExtension(display, &eventBase, &errorBase)) + return false; + + // We need to support XComposite version 0.2. + int major, minor; + XCompositeQueryVersion(display, &major, &minor); + if (major < 0 || (!major && minor < 2)) + return false; + + hasExtensions = true; + return true; +} + +std::unique_ptr<RedirectedXCompositeWindow> RedirectedXCompositeWindow::create(GdkWindow* parentWindow, std::function<void()> damageNotify) +{ + ASSERT(GDK_IS_WINDOW(parentWindow)); + return supportsXDamageAndXComposite(parentWindow) ? std::unique_ptr<RedirectedXCompositeWindow>(new RedirectedXCompositeWindow(parentWindow, damageNotify)) : nullptr; +} + +RedirectedXCompositeWindow::RedirectedXCompositeWindow(GdkWindow* parentWindow, std::function<void()> damageNotify) + : m_display(GDK_DISPLAY_XDISPLAY(gdk_window_get_display(parentWindow))) + , m_needsNewPixmapAfterResize(false) + , m_deviceScale(1) +{ + ASSERT(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native() == m_display); + Screen* screen = DefaultScreenOfDisplay(m_display); + + GdkVisual* visual = gdk_window_get_visual(parentWindow); + XUniqueColormap colormap(XCreateColormap(m_display, RootWindowOfScreen(screen), GDK_VISUAL_XVISUAL(visual), AllocNone)); + + // This is based on code from Chromium: src/content/common/gpu/image_transport_surface_linux.cc + XSetWindowAttributes windowAttributes; + windowAttributes.override_redirect = True; + windowAttributes.colormap = colormap.get(); + + // CWBorderPixel must be present when the depth doesn't match the parent's one. + // See http://cgit.freedesktop.org/xorg/xserver/tree/dix/window.c?id=xorg-server-1.16.0#n703. + windowAttributes.border_pixel = 0; + + m_parentWindow = XCreateWindow(m_display, + RootWindowOfScreen(screen), + WidthOfScreen(screen) + 1, 0, 1, 1, + 0, + gdk_visual_get_depth(visual), + InputOutput, + GDK_VISUAL_XVISUAL(visual), + CWOverrideRedirect | CWColormap | CWBorderPixel, + &windowAttributes); + XMapWindow(m_display, m_parentWindow.get()); + + windowAttributes.event_mask = StructureNotifyMask; + windowAttributes.override_redirect = False; + // Create the window of at last 1x1 since X doesn't allow to create empty windows. + m_window = XCreateWindow(m_display, + m_parentWindow.get(), + 0, 0, + std::max(1, m_size.width()), + std::max(1, m_size.height()), + 0, + CopyFromParent, + InputOutput, + CopyFromParent, + CWEventMask, + &windowAttributes); + XMapWindow(m_display, m_window.get()); + + xDamageNotifier().add(m_window.get(), WTFMove(damageNotify)); + + while (1) { + XEvent event; + XWindowEvent(m_display, m_window.get(), StructureNotifyMask, &event); + if (event.type == MapNotify && event.xmap.window == m_window.get()) + break; + } + XSelectInput(m_display, m_window.get(), NoEventMask); + XCompositeRedirectWindow(m_display, m_window.get(), CompositeRedirectManual); + m_damage = XDamageCreate(m_display, m_window.get(), XDamageReportNonEmpty); +} + +RedirectedXCompositeWindow::~RedirectedXCompositeWindow() +{ + ASSERT(m_display); + ASSERT(m_damage); + ASSERT(m_window); + ASSERT(m_parentWindow); + + xDamageNotifier().remove(m_window.get()); + + // Explicitly reset these because we need to ensure it happens in this order. + m_damage.reset(); + m_window.reset(); + m_parentWindow.reset(); +} + +void RedirectedXCompositeWindow::resize(const IntSize& size) +{ + IntSize scaledSize(size); + scaledSize.scale(m_deviceScale); + + if (scaledSize == m_size) + return; + + // Resize the window to at last 1x1 since X doesn't allow to create empty windows. + XResizeWindow(m_display, m_window.get(), std::max(1, scaledSize.width()), std::max(1, scaledSize.height())); + XFlush(m_display); + + m_size = scaledSize; + m_needsNewPixmapAfterResize = true; + if (m_size.isEmpty()) + cleanupPixmapAndPixmapSurface(); +} + +void RedirectedXCompositeWindow::cleanupPixmapAndPixmapSurface() +{ + if (!m_pixmap) + return; + + m_surface = nullptr; + m_pixmap.reset(); +} + +cairo_surface_t* RedirectedXCompositeWindow::surface() +{ + // This should never be called with an empty size (not in Accelerated Compositing mode). + ASSERT(!m_size.isEmpty()); + + if (!m_needsNewPixmapAfterResize && m_surface) + return m_surface.get(); + + m_needsNewPixmapAfterResize = false; + + XUniquePixmap newPixmap(XCompositeNameWindowPixmap(m_display, m_window.get())); + if (!newPixmap) { + cleanupPixmapAndPixmapSurface(); + return nullptr; + } + + XWindowAttributes windowAttributes; + if (!XGetWindowAttributes(m_display, m_window.get(), &windowAttributes)) { + cleanupPixmapAndPixmapSurface(); + return nullptr; + } + + RefPtr<cairo_surface_t> newSurface = adoptRef(cairo_xlib_surface_create(m_display, newPixmap.get(), windowAttributes.visual, m_size.width(), m_size.height())); + cairoSurfaceSetDeviceScale(newSurface.get(), m_deviceScale, m_deviceScale); + + // Nvidia drivers seem to prepare their redirected window pixmap asynchronously, so for a few fractions + // of a second after each resize, while doing continuous resizing (which constantly destroys and creates + // pixmap window-backings), the pixmap memory is uninitialized. To work around this issue, paint the old + // pixmap to the new one to properly initialize it. + if (m_surface) { + RefPtr<cairo_t> cr = adoptRef(cairo_create(newSurface.get())); + cairo_set_source_rgb(cr.get(), 1, 1, 1); + cairo_paint(cr.get()); + cairo_set_source_surface(cr.get(), m_surface.get(), 0, 0); + cairo_paint(cr.get()); + } + + cleanupPixmapAndPixmapSurface(); + m_pixmap = WTFMove(newPixmap); + m_surface = newSurface; + return m_surface.get(); +} + +} // namespace WebCore + +#endif // USE(REDIRECTED_XCOMPOSITE_WINDOW) diff --git a/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.h b/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.h new file mode 100644 index 000000000..bfc2a14d0 --- /dev/null +++ b/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2012 Igalia S.L. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef RedirectedXCompositeWindow_h +#define RedirectedXCompositeWindow_h + +#if USE(REDIRECTED_XCOMPOSITE_WINDOW) + +#include <WebCore/IntSize.h> +#include <WebCore/RefPtrCairo.h> +#include <WebCore/XUniqueResource.h> +#include <functional> + +typedef struct _GdkWindow GdkWindow; +typedef struct _XDisplay Display; +typedef unsigned long Window; + +namespace WebKit { + +class RedirectedXCompositeWindow { +public: + static std::unique_ptr<RedirectedXCompositeWindow> create(GdkWindow*, std::function<void()> damageNotify); + ~RedirectedXCompositeWindow(); + + Window windowID() const { return m_window.get(); } + void resize(const WebCore::IntSize&); + void setDeviceScaleFactor(float scale) { m_deviceScale = scale; } + cairo_surface_t* surface(); + +private: + RedirectedXCompositeWindow(GdkWindow*, std::function<void()> damageNotify); + void cleanupPixmapAndPixmapSurface(); + + Display* m_display; + WebCore::IntSize m_size; + WebCore::XUniqueWindow m_window; + WebCore::XUniqueWindow m_parentWindow; + WebCore::XUniquePixmap m_pixmap; + WebCore::XUniqueDamage m_damage; + RefPtr<cairo_surface_t> m_surface; + bool m_needsNewPixmapAfterResize; + float m_deviceScale; +}; + +} // namespace WebKit + +#endif // USE(REDIRECTED_XCOMPOSITE_WINDOW) + +#endif // RedirectedXCompositeWindow_h diff --git a/Source/WebKit2/UIProcess/gtk/TextCheckerGtk.cpp b/Source/WebKit2/UIProcess/gtk/TextCheckerGtk.cpp index 6bc419079..1592cd70b 100644 --- a/Source/WebKit2/UIProcess/gtk/TextCheckerGtk.cpp +++ b/Source/WebKit2/UIProcess/gtk/TextCheckerGtk.cpp @@ -1,6 +1,7 @@ /* * Copyright (C) 2010 Apple Inc. All rights reserved. * Portions Copyright (c) 2010 Motorola Mobility, Inc. All rights reserved. + * Copyright (C) 2011-2013 Samsung Electronics * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,120 +28,277 @@ #include "config.h" #include "TextChecker.h" +#include "TextBreakIterator.h" #include "TextCheckerState.h" -#include "WebTextChecker.h" +#include "WebProcessPool.h" #include <WebCore/NotImplemented.h> +#include <WebCore/TextCheckerEnchant.h> +#include <wtf/NeverDestroyed.h> using namespace WebCore; - + namespace WebKit { -static TextCheckerState textCheckerState; +#if ENABLE(SPELLCHECK) +static WebCore::TextCheckerEnchant& enchantTextChecker() +{ + static NeverDestroyed<WebCore::TextCheckerEnchant> checker; + return checker; +} +#endif -const TextCheckerState& TextChecker::state() +TextCheckerState& checkerState() { - static bool didInitializeState = false; - if (didInitializeState) - return textCheckerState; + static TextCheckerState textCheckerState; + static std::once_flag onceFlag; + std::call_once(onceFlag, [] { + textCheckerState.isContinuousSpellCheckingEnabled = false; + textCheckerState.isGrammarCheckingEnabled = false; + }); - WebTextCheckerClient& client = WebTextChecker::shared()->client(); - textCheckerState.isContinuousSpellCheckingEnabled = client.continuousSpellCheckingEnabled(); - textCheckerState.isGrammarCheckingEnabled = client.grammarCheckingEnabled(); + return textCheckerState; +} - didInitializeState = true; +const TextCheckerState& TextChecker::state() +{ + return checkerState(); +} - return textCheckerState; +#if ENABLE(SPELLCHECK) +static void updateStateForAllProcessPools() +{ + for (const auto& processPool : WebProcessPool::allProcessPools()) + processPool->textCheckerStateChanged(); } - +#endif + bool TextChecker::isContinuousSpellCheckingAllowed() { - return WebTextChecker::shared()->client().continuousSpellCheckingAllowed(); +#if ENABLE(SPELLCHECK) + return true; +#else + return false; +#endif } void TextChecker::setContinuousSpellCheckingEnabled(bool isContinuousSpellCheckingEnabled) { - if (state().isContinuousSpellCheckingEnabled == isContinuousSpellCheckingEnabled) +#if ENABLE(SPELLCHECK) + if (checkerState().isContinuousSpellCheckingEnabled == isContinuousSpellCheckingEnabled) return; - textCheckerState.isContinuousSpellCheckingEnabled = isContinuousSpellCheckingEnabled; - WebTextChecker::shared()->client().setContinuousSpellCheckingEnabled(isContinuousSpellCheckingEnabled); + checkerState().isContinuousSpellCheckingEnabled = isContinuousSpellCheckingEnabled; + updateStateForAllProcessPools(); +#else + UNUSED_PARAM(isContinuousSpellCheckingEnabled); +#endif } void TextChecker::setGrammarCheckingEnabled(bool isGrammarCheckingEnabled) { - if (state().isGrammarCheckingEnabled == isGrammarCheckingEnabled) +#if ENABLE(SPELLCHECK) + if (checkerState().isGrammarCheckingEnabled == isGrammarCheckingEnabled) return; - textCheckerState.isGrammarCheckingEnabled = isGrammarCheckingEnabled; - WebTextChecker::shared()->client().setGrammarCheckingEnabled(isGrammarCheckingEnabled); + checkerState().isGrammarCheckingEnabled = isGrammarCheckingEnabled; + updateStateForAllProcessPools(); +#else + UNUSED_PARAM(isGrammarCheckingEnabled); +#endif } void TextChecker::continuousSpellCheckingEnabledStateChanged(bool enabled) { - textCheckerState.isContinuousSpellCheckingEnabled = enabled; +#if ENABLE(SPELLCHECK) + checkerState().isContinuousSpellCheckingEnabled = enabled; +#else + UNUSED_PARAM(enabled); +#endif } void TextChecker::grammarCheckingEnabledStateChanged(bool enabled) { - textCheckerState.isGrammarCheckingEnabled = enabled; +#if ENABLE(SPELLCHECK) + checkerState().isGrammarCheckingEnabled = enabled; +#else + UNUSED_PARAM(enabled); +#endif } -int64_t TextChecker::uniqueSpellDocumentTag(WebPageProxy* page) +int64_t TextChecker::uniqueSpellDocumentTag(WebPageProxy*) { - return WebTextChecker::shared()->client().uniqueSpellDocumentTag(page); + return 0; } -void TextChecker::closeSpellDocumentWithTag(int64_t tag) +void TextChecker::closeSpellDocumentWithTag(int64_t /* tag */) { - WebTextChecker::shared()->client().closeSpellDocumentWithTag(tag); } -void TextChecker::checkSpellingOfString(int64_t spellDocumentTag, const UChar* text, uint32_t length, int32_t& misspellingLocation, int32_t& misspellingLength) +void TextChecker::checkSpellingOfString(int64_t /* spellDocumentTag */, StringView text, int32_t& misspellingLocation, int32_t& misspellingLength) { - WebTextChecker::shared()->client().checkSpellingOfString(spellDocumentTag, String(text, length), misspellingLocation, misspellingLength); +#if ENABLE(SPELLCHECK) + misspellingLocation = -1; + misspellingLength = 0; + enchantTextChecker().checkSpellingOfString(text.toStringWithoutCopying(), misspellingLocation, misspellingLength); +#else + UNUSED_PARAM(text); + UNUSED_PARAM(misspellingLocation); + UNUSED_PARAM(misspellingLength); +#endif } -void TextChecker::checkGrammarOfString(int64_t spellDocumentTag, const UChar* text, uint32_t length, Vector<WebCore::GrammarDetail>& grammarDetails, int32_t& badGrammarLocation, int32_t& badGrammarLength) +void TextChecker::checkGrammarOfString(int64_t /* spellDocumentTag */, StringView /* text */, Vector<WebCore::GrammarDetail>& /* grammarDetails */, int32_t& /* badGrammarLocation */, int32_t& /* badGrammarLength */) { - WebTextChecker::shared()->client().checkGrammarOfString(spellDocumentTag, String(text, length), grammarDetails, badGrammarLocation, badGrammarLength); } bool TextChecker::spellingUIIsShowing() { - return WebTextChecker::shared()->client().spellingUIIsShowing(); + return false; } void TextChecker::toggleSpellingUIIsShowing() { - WebTextChecker::shared()->client().toggleSpellingUIIsShowing(); } -void TextChecker::updateSpellingUIWithMisspelledWord(int64_t spellDocumentTag, const String& misspelledWord) +void TextChecker::updateSpellingUIWithMisspelledWord(int64_t /* spellDocumentTag */, const String& /* misspelledWord */) +{ +} + +void TextChecker::updateSpellingUIWithGrammarString(int64_t /* spellDocumentTag */, const String& /* badGrammarPhrase */, const GrammarDetail& /* grammarDetail */) +{ +} + +void TextChecker::getGuessesForWord(int64_t /* spellDocumentTag */, const String& word, const String& /* context */, Vector<String>& guesses) { - WebTextChecker::shared()->client().updateSpellingUIWithMisspelledWord(spellDocumentTag, misspelledWord); +#if ENABLE(SPELLCHECK) + guesses = enchantTextChecker().getGuessesForWord(word); +#else + UNUSED_PARAM(word); + UNUSED_PARAM(guesses); +#endif } -void TextChecker::updateSpellingUIWithGrammarString(int64_t spellDocumentTag, const String& badGrammarPhrase, const GrammarDetail& grammarDetail) +void TextChecker::learnWord(int64_t /* spellDocumentTag */, const String& word) { - WebTextChecker::shared()->client().updateSpellingUIWithGrammarString(spellDocumentTag, badGrammarPhrase, grammarDetail); +#if ENABLE(SPELLCHECK) + enchantTextChecker().learnWord(word); +#else + UNUSED_PARAM(word); +#endif } -void TextChecker::getGuessesForWord(int64_t spellDocumentTag, const String& word, const String& context, Vector<String>& guesses) +void TextChecker::ignoreWord(int64_t /* spellDocumentTag */, const String& word) { - WebTextChecker::shared()->client().guessesForWord(spellDocumentTag, word, guesses); +#if ENABLE(SPELLCHECK) + enchantTextChecker().ignoreWord(word); +#else + UNUSED_PARAM(word); +#endif } -void TextChecker::learnWord(int64_t spellDocumentTag, const String& word) +void TextChecker::requestCheckingOfString(PassRefPtr<TextCheckerCompletion> completion) { - WebTextChecker::shared()->client().learnWord(spellDocumentTag, word); +#if ENABLE(SPELLCHECK) + if (!completion) + return; + + TextCheckingRequestData request = completion->textCheckingRequestData(); + ASSERT(request.sequence() != unrequestedTextCheckingSequence); + ASSERT(request.mask() != TextCheckingTypeNone); + + completion->didFinishCheckingText(checkTextOfParagraph(completion->spellDocumentTag(), request.text(), request.mask())); +#else + UNUSED_PARAM(completion); +#endif +} + +#if USE(UNIFIED_TEXT_CHECKING) && ENABLE(SPELLCHECK) +static unsigned nextWordOffset(StringView text, unsigned currentOffset) +{ + // FIXME: avoid creating textIterator object here, it could be passed as a parameter. + // isTextBreak() leaves the iterator pointing to the first boundary position at + // or after "offset" (ubrk_isBoundary side effect). + // For many word separators, the method doesn't properly determine the boundaries + // without resetting the iterator. + TextBreakIterator* textIterator = wordBreakIterator(text); + if (!textIterator) + return currentOffset; + + unsigned wordOffset = currentOffset; + while (wordOffset < text.length() && isTextBreak(textIterator, wordOffset)) + ++wordOffset; + + // Do not treat the word's boundary as a separator. + if (!currentOffset && wordOffset == 1) + return currentOffset; + + // Omit multiple separators. + if ((wordOffset - currentOffset) > 1) + --wordOffset; + + return wordOffset; +} +#endif + +#if USE(UNIFIED_TEXT_CHECKING) +Vector<TextCheckingResult> TextChecker::checkTextOfParagraph(int64_t spellDocumentTag, StringView text, uint64_t checkingTypes) +{ +#if ENABLE(SPELLCHECK) + if (!(checkingTypes & TextCheckingTypeSpelling)) + return Vector<TextCheckingResult>(); + + TextBreakIterator* textIterator = wordBreakIterator(text); + if (!textIterator) + return Vector<TextCheckingResult>(); + + // Omit the word separators at the beginning/end of the text to don't unnecessarily + // involve the client to check spelling for them. + unsigned offset = nextWordOffset(text, 0); + unsigned lengthStrip = text.length(); + while (lengthStrip > 0 && isTextBreak(textIterator, lengthStrip - 1)) + --lengthStrip; + + Vector<TextCheckingResult> paragraphCheckingResult; + while (offset < lengthStrip) { + int32_t misspellingLocation = -1; + int32_t misspellingLength = 0; + checkSpellingOfString(spellDocumentTag, text.substring(offset, lengthStrip - offset), misspellingLocation, misspellingLength); + if (!misspellingLength) + break; + + TextCheckingResult misspellingResult; + misspellingResult.type = TextCheckingTypeSpelling; + misspellingResult.location = offset + misspellingLocation; + misspellingResult.length = misspellingLength; + paragraphCheckingResult.append(misspellingResult); + offset += misspellingLocation + misspellingLength; + // Generally, we end up checking at the word separator, move to the adjacent word. + offset = nextWordOffset(text.substring(0, lengthStrip), offset); + } + return paragraphCheckingResult; +#else + UNUSED_PARAM(spellDocumentTag); + UNUSED_PARAM(text); + UNUSED_PARAM(checkingTypes); + return Vector<TextCheckingResult>(); +#endif // ENABLE(SPELLCHECK) } +#endif // USE(UNIFIED_TEXT_CHECKING) -void TextChecker::ignoreWord(int64_t spellDocumentTag, const String& word) +void TextChecker::setSpellCheckingLanguages(const Vector<String>& languages) { - WebTextChecker::shared()->client().ignoreWord(spellDocumentTag, word); +#if ENABLE(SPELLCHECK) + enchantTextChecker().updateSpellCheckingLanguages(languages); +#else + UNUSED_PARAM(languages); +#endif } -void TextChecker::requestCheckingOfString(PassRefPtr<TextCheckerCompletion>) +Vector<String> TextChecker::loadedSpellCheckingLanguages() { - notImplemented(); +#if ENABLE(SPELLCHECK) + return enchantTextChecker().loadedSpellCheckingLanguages(); +#else + return Vector<String>(); +#endif } } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/gtk/WebColorPickerGtk.cpp b/Source/WebKit2/UIProcess/gtk/WebColorPickerGtk.cpp new file mode 100644 index 000000000..32dfe82ec --- /dev/null +++ b/Source/WebKit2/UIProcess/gtk/WebColorPickerGtk.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2015 Igalia S.L. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebColorPickerGtk.h" + +#if ENABLE(INPUT_TYPE_COLOR) + +#include "WebPageProxy.h" +#include <WebCore/GtkUtilities.h> +#include <glib/gi18n-lib.h> +#include <gtk/gtk.h> + +using namespace WebCore; + +namespace WebKit { + +Ref<WebColorPickerGtk> WebColorPickerGtk::create(WebPageProxy& page, const Color& initialColor, const IntRect& rect) +{ + return adoptRef(*new WebColorPickerGtk(page, initialColor, rect)); +} + +WebColorPickerGtk::WebColorPickerGtk(WebPageProxy& page, const Color& initialColor, const IntRect&) + : WebColorPicker(&page) + , m_initialColor(initialColor) + , m_webView(page.viewWidget()) + , m_colorChooser(nullptr) +{ +} + +WebColorPickerGtk::~WebColorPickerGtk() +{ + endPicker(); +} + +void WebColorPickerGtk::cancel() +{ + setSelectedColor(m_initialColor); +} + +void WebColorPickerGtk::endPicker() +{ + if (!m_colorChooser) + return; + + gtk_widget_destroy(m_colorChooser); + m_colorChooser = nullptr; +} + +void WebColorPickerGtk::didChooseColor(const Color& color) +{ + if (!m_client) + return; + + m_client->didChooseColor(color); +} + +void WebColorPickerGtk::colorChooserDialogRGBAChangedCallback(GtkColorChooser* colorChooser, GParamSpec*, WebColorPickerGtk* colorPicker) +{ + GdkRGBA rgba; + gtk_color_chooser_get_rgba(colorChooser, &rgba); + colorPicker->didChooseColor(rgba); +} + +void WebColorPickerGtk::colorChooserDialogResponseCallback(GtkColorChooser*, int responseID, WebColorPickerGtk* colorPicker) +{ + if (responseID != GTK_RESPONSE_OK) + colorPicker->cancel(); + colorPicker->endPicker(); +} + +void WebColorPickerGtk::showColorPicker(const Color& color) +{ + if (!m_client) + return; + + m_initialColor = color; + + if (!m_colorChooser) { + GtkWidget* toplevel = gtk_widget_get_toplevel(m_webView); + m_colorChooser = gtk_color_chooser_dialog_new(_("Select Color"), WebCore::widgetIsOnscreenToplevelWindow(toplevel) ? GTK_WINDOW(toplevel) : nullptr); + gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(m_colorChooser), &m_initialColor); + g_signal_connect(m_colorChooser, "notify::rgba", G_CALLBACK(WebColorPickerGtk::colorChooserDialogRGBAChangedCallback), this); + g_signal_connect(m_colorChooser, "response", G_CALLBACK(WebColorPickerGtk::colorChooserDialogResponseCallback), this); + } else + gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(m_colorChooser), &m_initialColor); + + gtk_widget_show(m_colorChooser); +} + +} // namespace WebKit + +#endif // ENABLE(INPUT_TYPE_COLOR) diff --git a/Source/WebKit2/UIProcess/gtk/WebColorPickerGtk.h b/Source/WebKit2/UIProcess/gtk/WebColorPickerGtk.h new file mode 100644 index 000000000..05a84de4b --- /dev/null +++ b/Source/WebKit2/UIProcess/gtk/WebColorPickerGtk.h @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2015 Igalia S.L. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebColorPickerGtk_h +#define WebColorPickerGtk_h + +#if ENABLE(INPUT_TYPE_COLOR) + +#include "WebColorPicker.h" +#include <gdk/gdk.h> + +typedef struct _GtkColorChooser GtkColorChooser; + +namespace WebCore { +class Color; +class IntRect; +} + +namespace WebKit { + +class WebColorPickerGtk : public WebColorPicker { +public: + static Ref<WebColorPickerGtk> create(WebPageProxy&, const WebCore::Color&, const WebCore::IntRect&); + virtual ~WebColorPickerGtk(); + + virtual void endPicker() override; + virtual void showColorPicker(const WebCore::Color&) override; + + void cancel(); + + const GdkRGBA* initialColor() const { return &m_initialColor; } + +protected: + WebColorPickerGtk(WebPageProxy&, const WebCore::Color&, const WebCore::IntRect&); + + void didChooseColor(const WebCore::Color&); + + GdkRGBA m_initialColor; + GtkWidget* m_webView; + +private: + static void colorChooserDialogRGBAChangedCallback(GtkColorChooser*, GParamSpec*, WebColorPickerGtk*); + static void colorChooserDialogResponseCallback(GtkColorChooser*, int /*responseID*/, WebColorPickerGtk*); + + GtkWidget* m_colorChooser; +}; + +} // namespace WebKit + +#endif // ENABLE(INPUT_TYPE_COLOR) +#endif // WebColorPickerGtk_h diff --git a/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.cpp b/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.cpp index cc25e644b..23acbed3b 100644 --- a/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.cpp +++ b/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.cpp @@ -28,10 +28,13 @@ #if ENABLE(CONTEXT_MENUS) +#include "APIContextMenuClient.h" #include "NativeWebMouseEvent.h" +#include "WebContextMenuItem.h" #include "WebContextMenuItemData.h" #include "WebKitWebViewBasePrivate.h" #include "WebPageProxy.h" +#include "WebProcessProxy.h" #include <WebCore/GtkUtilities.h> #include <gtk/gtk.h> #include <wtf/text/CString.h> @@ -46,14 +49,14 @@ namespace WebKit { static void contextMenuItemActivatedCallback(GtkAction* action, WebPageProxy* page) { gboolean isToggle = GTK_IS_TOGGLE_ACTION(action); - WebKit::WebContextMenuItemData item(isToggle ? WebCore::CheckableActionType : WebCore::ActionType, - static_cast<WebCore::ContextMenuAction>(GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), gContextMenuActionId))), + WebContextMenuItemData item(isToggle ? CheckableActionType : ActionType, + static_cast<ContextMenuAction>(GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), gContextMenuActionId))), String::fromUTF8(gtk_action_get_label(action)), gtk_action_get_sensitive(action), isToggle ? gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)) : false); page->contextMenuItemSelected(item); } -static void contextMenuItemVisibilityChanged(GtkAction* action, GParamSpec*, WebContextMenuProxyGtk* contextMenuProxy) +static void contextMenuItemVisibilityChanged(GtkAction*, GParamSpec*, WebContextMenuProxyGtk* contextMenuProxy) { GtkMenu* menu = contextMenuProxy->gtkMenu(); if (!menu) @@ -82,98 +85,128 @@ static void contextMenuItemVisibilityChanged(GtkAction* action, GParamSpec*, Web gtk_widget_hide(lastItemVisibleSeparator); } -void WebContextMenuProxyGtk::append(ContextMenuItem& menuItem) +void WebContextMenuProxyGtk::append(GtkMenu* menu, const WebContextMenuItemGtk& menuItem) { unsigned long signalHandlerId; - GtkAction* action = menuItem.gtkAction(); - if (action) { + GtkWidget* gtkMenuItem; + if (GtkAction* action = menuItem.gtkAction()) { + gtkMenuItem = gtk_action_create_menu_item(action); + switch (menuItem.type()) { case ActionType: case CheckableActionType: g_object_set_data(G_OBJECT(action), gContextMenuActionId, GINT_TO_POINTER(menuItem.action())); signalHandlerId = g_signal_connect(action, "activate", G_CALLBACK(contextMenuItemActivatedCallback), m_page); m_signalHandlers.set(signalHandlerId, action); - // Fall through. - case SubmenuType: signalHandlerId = g_signal_connect(action, "notify::visible", G_CALLBACK(contextMenuItemVisibilityChanged), this); m_signalHandlers.set(signalHandlerId, action); break; + case SubmenuType: { + signalHandlerId = g_signal_connect(action, "notify::visible", G_CALLBACK(contextMenuItemVisibilityChanged), this); + m_signalHandlers.set(signalHandlerId, action); + GtkMenu* submenu = GTK_MENU(gtk_menu_new()); + for (const auto& item : menuItem.submenuItems()) + append(submenu, item); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(gtkMenuItem), GTK_WIDGET(submenu)); + break; + } case SeparatorType: + ASSERT_NOT_REACHED(); break; } + } else { + ASSERT(menuItem.type() == SeparatorType); + gtkMenuItem = gtk_separator_menu_item_new(); } - m_menu.appendItem(menuItem); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), gtkMenuItem); + gtk_widget_show(gtkMenuItem); } // Populate the context menu ensuring that: // - There aren't separators next to each other. // - There aren't separators at the beginning of the menu. // - There aren't separators at the end of the menu. -void WebContextMenuProxyGtk::populate(Vector<ContextMenuItem>& items) +void WebContextMenuProxyGtk::populate(Vector<WebContextMenuItemGtk>& items) { bool previousIsSeparator = false; bool isEmpty = true; for (size_t i = 0; i < items.size(); i++) { - ContextMenuItem& menuItem = items.at(i); + WebContextMenuItemGtk& menuItem = items.at(i); if (menuItem.type() == SeparatorType) { previousIsSeparator = true; continue; } if (previousIsSeparator && !isEmpty) - append(items.at(i - 1)); + append(m_menu, items.at(i - 1)); previousIsSeparator = false; - append(menuItem); + append(m_menu, menuItem); isEmpty = false; } } -void WebContextMenuProxyGtk::populate(const Vector<WebContextMenuItemData>& items) +void WebContextMenuProxyGtk::populate(const Vector<RefPtr<WebContextMenuItem>>& items) { - for (size_t i = 0; i < items.size(); i++) { - ContextMenuItem menuitem = items.at(i).core(); - append(menuitem); + for (const auto& item : items) { + WebContextMenuItemGtk menuitem(item->data()); + append(m_menu, menuitem); } } -void WebContextMenuProxyGtk::showContextMenu(const WebCore::IntPoint& position, const Vector<WebContextMenuItemData>& items) +void WebContextMenuProxyGtk::show() { + Vector<RefPtr<WebContextMenuItem>> proposedAPIItems; + for (auto& item : m_context.menuItems()) { + if (item.action() != ContextMenuItemTagShareMenu) + proposedAPIItems.append(WebContextMenuItem::create(item)); + } + + Vector<RefPtr<WebContextMenuItem>> clientItems; + bool useProposedItems = true; + + if (m_page->contextMenuClient().getContextMenuFromProposedMenu(*m_page, proposedAPIItems, clientItems, m_context.webHitTestResultData(), m_page->process().transformHandlesToObjects(m_userData.object()).get())) + useProposedItems = false; + + const Vector<RefPtr<WebContextMenuItem>>& items = useProposedItems ? proposedAPIItems : clientItems; + if (!items.isEmpty()) populate(items); - if (!m_menu.itemCount()) + unsigned childCount = 0; + gtk_container_foreach(GTK_CONTAINER(m_menu), [](GtkWidget*, gpointer data) { (*static_cast<unsigned*>(data))++; }, &childCount); + if (!childCount) return; - m_popupPosition = convertWidgetPointToScreenPoint(m_webView, position); + m_popupPosition = convertWidgetPointToScreenPoint(m_webView, m_context.menuLocation()); // Display menu initiated by right click (mouse button pressed = 3). NativeWebMouseEvent* mouseEvent = m_page->currentlyProcessedMouseDownEvent(); const GdkEvent* event = mouseEvent ? mouseEvent->nativeEvent() : 0; - gtk_menu_attach_to_widget(m_menu.platformDescription(), GTK_WIDGET(m_webView), 0); - gtk_menu_popup(m_menu.platformDescription(), 0, 0, reinterpret_cast<GtkMenuPositionFunc>(menuPositionFunction), this, + gtk_menu_attach_to_widget(m_menu, GTK_WIDGET(m_webView), nullptr); + gtk_menu_popup(m_menu, nullptr, nullptr, reinterpret_cast<GtkMenuPositionFunc>(menuPositionFunction), this, event ? event->button.button : 3, event ? event->button.time : GDK_CURRENT_TIME); } -void WebContextMenuProxyGtk::hideContextMenu() -{ - gtk_menu_popdown(m_menu.platformDescription()); -} - -WebContextMenuProxyGtk::WebContextMenuProxyGtk(GtkWidget* webView, WebPageProxy* page) - : m_webView(webView) - , m_page(page) +WebContextMenuProxyGtk::WebContextMenuProxyGtk(GtkWidget* webView, WebPageProxy& page, const ContextMenuContextData& context, const UserData& userData) + : WebContextMenuProxy(context, userData) + , m_webView(webView) + , m_page(&page) + , m_menu(GTK_MENU(gtk_menu_new())) { webkitWebViewBaseSetActiveContextMenuProxy(WEBKIT_WEB_VIEW_BASE(m_webView), this); } WebContextMenuProxyGtk::~WebContextMenuProxyGtk() { - for (auto iter = m_signalHandlers.begin(); iter != m_signalHandlers.end(); ++iter) - g_signal_handler_disconnect(iter->value, iter->key); + gtk_menu_popdown(m_menu); + + for (auto& handler : m_signalHandlers) + g_signal_handler_disconnect(handler.value, handler.key); + m_signalHandlers.clear(); - webkitWebViewBaseSetActiveContextMenuProxy(WEBKIT_WEB_VIEW_BASE(m_webView), 0); + gtk_widget_destroy(GTK_WIDGET(m_menu)); } void WebContextMenuProxyGtk::menuPositionFunction(GtkMenu* menu, gint* x, gint* y, gboolean* pushIn, WebContextMenuProxyGtk* popupMenu) diff --git a/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.h b/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.h index ded4b7a84..9c8893e6a 100644 --- a/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.h +++ b/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.h @@ -28,40 +28,34 @@ #if ENABLE(CONTEXT_MENUS) +#include "WebContextMenuItemGtk.h" #include "WebContextMenuProxy.h" -#include <WebCore/ContextMenu.h> #include <WebCore/IntPoint.h> #include <wtf/HashMap.h> namespace WebKit { +class WebContextMenuItem; class WebContextMenuItemData; class WebPageProxy; class WebContextMenuProxyGtk : public WebContextMenuProxy { public: - static PassRefPtr<WebContextMenuProxyGtk> create(GtkWidget* webView, WebPageProxy* page) - { - return adoptRef(new WebContextMenuProxyGtk(webView, page)); - } + WebContextMenuProxyGtk(GtkWidget*, WebPageProxy&, const ContextMenuContextData&, const UserData&); ~WebContextMenuProxyGtk(); - virtual void showContextMenu(const WebCore::IntPoint&, const Vector<WebContextMenuItemData>&); - virtual void hideContextMenu(); - - void populate(Vector<WebCore::ContextMenuItem>&); - GtkMenu* gtkMenu() const { return m_menu.platformDescription(); } + void populate(Vector<WebContextMenuItemGtk>&); + GtkMenu* gtkMenu() const { return m_menu; } private: - WebContextMenuProxyGtk(GtkWidget*, WebPageProxy*); - - void append(WebCore::ContextMenuItem&); - void populate(const Vector<WebContextMenuItemData>&); + virtual void show() override; + void append(GtkMenu*, const WebContextMenuItemGtk&); + void populate(const Vector<RefPtr<WebContextMenuItem>>&); static void menuPositionFunction(GtkMenu*, gint*, gint*, gboolean*, WebContextMenuProxyGtk*); GtkWidget* m_webView; WebPageProxy* m_page; - WebCore::ContextMenu m_menu; + GtkMenu* m_menu; WebCore::IntPoint m_popupPosition; HashMap<unsigned long, GtkAction*> m_signalHandlers; }; diff --git a/Source/WebKit2/UIProcess/gtk/WebInspectorClientGtk.cpp b/Source/WebKit2/UIProcess/gtk/WebInspectorClientGtk.cpp index 5884c32ad..f42473345 100644 --- a/Source/WebKit2/UIProcess/gtk/WebInspectorClientGtk.cpp +++ b/Source/WebKit2/UIProcess/gtk/WebInspectorClientGtk.cpp @@ -27,7 +27,7 @@ #include "WebInspectorClientGtk.h" #include "WKAPICast.h" -#include "WKSharedAPICast.h" +#include "WebInspectorProxy.h" #include <wtf/text/WTFString.h> namespace WebKit { @@ -88,4 +88,11 @@ void WebInspectorClientGtk::didChangeAttachedWidth(WebInspectorProxy* inspector, m_client.didChangeAttachedWidth(toAPI(inspector), width, m_client.base.clientInfo); } +void WebInspectorClientGtk::didChangeAttachAvailability(WebInspectorProxy* inspector, bool available) +{ + if (!m_client.didChangeAttachAvailability) + return; + m_client.didChangeAttachAvailability(toAPI(inspector), available, m_client.base.clientInfo); +} + } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/gtk/WebInspectorClientGtk.h b/Source/WebKit2/UIProcess/gtk/WebInspectorClientGtk.h index 9d7b0eb68..42123b7d0 100644 --- a/Source/WebKit2/UIProcess/gtk/WebInspectorClientGtk.h +++ b/Source/WebKit2/UIProcess/gtk/WebInspectorClientGtk.h @@ -53,6 +53,7 @@ public: bool detach(WebInspectorProxy*); void didChangeAttachedHeight(WebInspectorProxy*, unsigned height); void didChangeAttachedWidth(WebInspectorProxy*, unsigned width); + void didChangeAttachAvailability(WebInspectorProxy*, bool available); }; } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/gtk/WebInspectorProxyGtk.cpp b/Source/WebKit2/UIProcess/gtk/WebInspectorProxyGtk.cpp index 231bc4ffb..776008a25 100644 --- a/Source/WebKit2/UIProcess/gtk/WebInspectorProxyGtk.cpp +++ b/Source/WebKit2/UIProcess/gtk/WebInspectorProxyGtk.cpp @@ -29,16 +29,16 @@ #include "config.h" #include "WebInspectorProxy.h" -#if ENABLE(INSPECTOR) - #include "WebKitWebViewBasePrivate.h" +#include "WebPageGroup.h" +#include "WebProcessPool.h" #include "WebProcessProxy.h" #include <WebCore/FileSystem.h> #include <WebCore/GtkUtilities.h> #include <WebCore/NotImplemented.h> #include <glib/gi18n-lib.h> #include <gtk/gtk.h> -#include <wtf/gobject/GUniquePtr.h> +#include <wtf/glib/GUniquePtr.h> #include <wtf/text/CString.h> #include <wtf/text/WTFString.h> @@ -53,6 +53,11 @@ static void inspectorViewDestroyed(GtkWidget*, gpointer userData) inspectorProxy->close(); } +static unsigned long long exceededDatabaseQuota(WKPageRef, WKFrameRef, WKSecurityOriginRef, WKStringRef, WKStringRef, unsigned long long, unsigned long long, unsigned long long currentDatabaseUsage, unsigned long long expectedUsage, const void*) +{ + return std::max<unsigned long long>(expectedUsage, currentDatabaseUsage * 1.25); +} + void WebInspectorProxy::initializeInspectorClientGtk(const WKInspectorClientGtkBase* inspectorClient) { m_client.initialize(inspectorClient); @@ -60,11 +65,81 @@ void WebInspectorProxy::initializeInspectorClientGtk(const WKInspectorClientGtkB WebPageProxy* WebInspectorProxy::platformCreateInspectorPage() { - ASSERT(m_page); + ASSERT(inspectedPage()); ASSERT(!m_inspectorView); - m_inspectorView = GTK_WIDGET(webkitWebViewBaseCreate(&page()->process().context(), inspectorPageGroup(), m_page)); + + RefPtr<WebPreferences> preferences = WebPreferences::create(String(), "WebKit2.", "WebKit2."); +#ifndef NDEBUG + // Allow developers to inspect the Web Inspector in debug builds without changing settings. + preferences->setDeveloperExtrasEnabled(true); + preferences->setLogsPageMessagesToSystemConsoleEnabled(true); +#endif + preferences->setJavaScriptRuntimeFlags({ + }); + RefPtr<WebPageGroup> pageGroup = WebPageGroup::create(inspectorPageGroupIdentifier(), false, false); + + auto pageConfiguration = API::PageConfiguration::create(); + pageConfiguration->setProcessPool(&inspectorProcessPool(inspectionLevel())); + pageConfiguration->setPreferences(preferences.get()); + pageConfiguration->setPageGroup(pageGroup.get()); + m_inspectorView = GTK_WIDGET(webkitWebViewBaseCreate(*pageConfiguration.ptr())); g_object_add_weak_pointer(G_OBJECT(m_inspectorView), reinterpret_cast<void**>(&m_inspectorView)); - return webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(m_inspectorView)); + + WKPageUIClientV2 uiClient = { + { 2, this }, + nullptr, // createNewPage_deprecatedForUseWithV0 + nullptr, // showPage + nullptr, // closePage + nullptr, // takeFocus + nullptr, // focus + nullptr, // unfocus + nullptr, // runJavaScriptAlert + nullptr, // runJavaScriptConfirm + nullptr, // runJavaScriptPrompt + nullptr, // setStatusText + nullptr, // mouseDidMoveOverElement_deprecatedForUseWithV0 + nullptr, // missingPluginButtonClicked_deprecatedForUseWithV0 + nullptr, // didNotHandleKeyEvent + nullptr, // didNotHandleWheelEvent + nullptr, // areToolbarsVisible + nullptr, // setToolbarsVisible + nullptr, // isMenuBarVisible + nullptr, // setMenuBarVisible + nullptr, // isStatusBarVisible + nullptr, // setStatusBarVisible + nullptr, // isResizable + nullptr, // setResizable + nullptr, // getWindowFrame, + nullptr, // setWindowFrame, + nullptr, // runBeforeUnloadConfirmPanel + nullptr, // didDraw + nullptr, // pageDidScroll + exceededDatabaseQuota, + nullptr, // runOpenPanel, + nullptr, // decidePolicyForGeolocationPermissionRequest + nullptr, // headerHeight + nullptr, // footerHeight + nullptr, // drawHeader + nullptr, // drawFooter + nullptr, // printFrame + nullptr, // runModal + nullptr, // unused + nullptr, // saveDataToFileInDownloadsFolder + nullptr, // shouldInterruptJavaScript + nullptr, // createPage + nullptr, // mouseDidMoveOverElement + nullptr, // decidePolicyForNotificationPermissionRequest + nullptr, // unavailablePluginButtonClicked_deprecatedForUseWithV1 + nullptr, // showColorPicker + nullptr, // hideColorPicker + nullptr, // unavailablePluginButtonClicked + }; + + WebPageProxy* inspectorPage = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(m_inspectorView)); + ASSERT(inspectorPage); + WKPageSetPageUIClient(toAPI(inspectorPage), &uiClient.base); + + return inspectorPage; } void WebInspectorProxy::createInspectorWindow() @@ -75,11 +150,18 @@ void WebInspectorProxy::createInspectorWindow() ASSERT(!m_inspectorWindow); m_inspectorWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); - GtkWidget* inspectedViewParent = gtk_widget_get_toplevel(m_page->viewWidget()); + GtkWidget* inspectedViewParent = gtk_widget_get_toplevel(inspectedPage()->viewWidget()); if (WebCore::widgetIsOnscreenToplevelWindow(inspectedViewParent)) gtk_window_set_transient_for(GTK_WINDOW(m_inspectorWindow), GTK_WINDOW(inspectedViewParent)); - gtk_window_set_title(GTK_WINDOW(m_inspectorWindow), _("Web Inspector")); +#if GTK_CHECK_VERSION(3, 10, 0) + m_headerBar = gtk_header_bar_new(); + gtk_header_bar_set_show_close_button(GTK_HEADER_BAR(m_headerBar), TRUE); + gtk_window_set_titlebar(GTK_WINDOW(m_inspectorWindow), m_headerBar); + gtk_widget_show(m_headerBar); +#endif + + updateInspectorWindowTitle(); gtk_window_set_default_size(GTK_WINDOW(m_inspectorWindow), initialWindowWidth, initialWindowHeight); gtk_container_add(GTK_CONTAINER(m_inspectorWindow), m_inspectorView); @@ -89,6 +171,23 @@ void WebInspectorProxy::createInspectorWindow() gtk_window_present(GTK_WINDOW(m_inspectorWindow)); } +void WebInspectorProxy::updateInspectorWindowTitle() const +{ + ASSERT(m_inspectorWindow); + if (m_inspectedURLString.isEmpty()) { + gtk_window_set_title(GTK_WINDOW(m_inspectorWindow), _("Web Inspector")); + return; + } + +#if GTK_CHECK_VERSION(3, 10, 0) + gtk_header_bar_set_title(GTK_HEADER_BAR(m_headerBar), _("Web Inspector")); + gtk_header_bar_set_subtitle(GTK_HEADER_BAR(m_headerBar), m_inspectedURLString.utf8().data()); +#else + GUniquePtr<gchar> title(g_strdup_printf("%s - %s", _("Web Inspector"), m_inspectedURLString.utf8().data())); + gtk_window_set_title(GTK_WINDOW(m_inspectorWindow), title.get()); +#endif +} + void WebInspectorProxy::platformOpen() { ASSERT(!m_inspectorWindow); @@ -115,6 +214,10 @@ void WebInspectorProxy::platformDidClose() m_inspectorView = 0; } +void WebInspectorProxy::platformInvalidate() +{ +} + void WebInspectorProxy::platformHide() { notImplemented(); @@ -140,32 +243,36 @@ bool WebInspectorProxy::platformIsFront() void WebInspectorProxy::platformInspectedURLChanged(const String& url) { + m_inspectedURLString = url; m_client.inspectedURLChanged(this, url); - if (!m_inspectorWindow) - return; - GUniquePtr<gchar> title(g_strdup_printf("%s - %s", _("Web Inspector"), url.utf8().data())); - gtk_window_set_title(GTK_WINDOW(m_inspectorWindow), title.get()); + if (m_inspectorWindow) + updateInspectorWindowTitle(); } -String WebInspectorProxy::inspectorPageURL() const +String WebInspectorProxy::inspectorPageURL() { return String("resource:///org/webkitgtk/inspector/UserInterface/Main.html"); } -String WebInspectorProxy::inspectorBaseURL() const +String WebInspectorProxy::inspectorTestPageURL() +{ + return String("resource:///org/webkitgtk/inspector/UserInterface/Test.html"); +} + +String WebInspectorProxy::inspectorBaseURL() { return String("resource:///org/webkitgtk/inspector/UserInterface/"); } unsigned WebInspectorProxy::platformInspectedWindowHeight() { - return gtk_widget_get_allocated_height(m_page->viewWidget()); + return gtk_widget_get_allocated_height(inspectedPage()->viewWidget()); } unsigned WebInspectorProxy::platformInspectedWindowWidth() { - return gtk_widget_get_allocated_width(m_page->viewWidget()); + return gtk_widget_get_allocated_width(inspectedPage()->viewWidget()); } void WebInspectorProxy::platformAttach() @@ -177,9 +284,12 @@ void WebInspectorProxy::platformAttach() m_inspectorWindow = 0; } - // Set a default attached size based on InspectorFrontendClientLocal. + // Set a default sizes based on InspectorFrontendClientLocal. static const unsigned defaultAttachedSize = 300; - if (m_attachmentSide == AttachmentSideBottom) { + static const unsigned minimumAttachedWidth = 750; + static const unsigned minimumAttachedHeight = 250; + + if (m_attachmentSide == AttachmentSide::Bottom) { unsigned maximumAttachedHeight = platformInspectedWindowHeight() * 3 / 4; platformSetAttachedWindowHeight(std::max(minimumAttachedHeight, std::min(defaultAttachedSize, maximumAttachedHeight))); } else { @@ -190,24 +300,33 @@ void WebInspectorProxy::platformAttach() if (m_client.attach(this)) return; - webkitWebViewBaseAddWebInspector(WEBKIT_WEB_VIEW_BASE(m_page->viewWidget()), m_inspectorView, m_attachmentSide); + webkitWebViewBaseAddWebInspector(WEBKIT_WEB_VIEW_BASE(inspectedPage()->viewWidget()), m_inspectorView, m_attachmentSide); gtk_widget_show(m_inspectorView); } void WebInspectorProxy::platformDetach() { - if (!m_page->isValid()) + if (!inspectedPage()->isValid()) return; GRefPtr<GtkWidget> inspectorView = m_inspectorView; if (!m_client.detach(this)) { - GtkWidget* parent = gtk_widget_get_parent(m_inspectorView); - ASSERT(parent); - gtk_container_remove(GTK_CONTAINER(parent), m_inspectorView); + // Detach is called when m_isAttached is true, but it could called before + // the inspector is opened if the inspector is shown/closed quickly. So, + // we might not have a parent yet. + if (GtkWidget* parent = gtk_widget_get_parent(m_inspectorView)) + gtk_container_remove(GTK_CONTAINER(parent), m_inspectorView); } - if (!m_isVisible) + // Return early if we are not visible. This means the inspector was closed while attached + // and we should not create and show the inspector window. + if (!m_isVisible) { + // The inspector view will be destroyed, but we don't need to notify the web process to close the + // inspector in this case, since it's already closed. + g_signal_handlers_disconnect_by_func(m_inspectorView, reinterpret_cast<void*>(inspectorViewDestroyed), this); + m_inspectorView = nullptr; return; + } createInspectorWindow(); } @@ -218,7 +337,7 @@ void WebInspectorProxy::platformSetAttachedWindowHeight(unsigned height) return; m_client.didChangeAttachedHeight(this, height); - webkitWebViewBaseSetInspectorViewSize(WEBKIT_WEB_VIEW_BASE(m_page->viewWidget()), height); + webkitWebViewBaseSetInspectorViewSize(WEBKIT_WEB_VIEW_BASE(inspectedPage()->viewWidget()), height); } void WebInspectorProxy::platformSetAttachedWindowWidth(unsigned width) @@ -227,10 +346,10 @@ void WebInspectorProxy::platformSetAttachedWindowWidth(unsigned width) return; m_client.didChangeAttachedWidth(this, width); - webkitWebViewBaseSetInspectorViewSize(WEBKIT_WEB_VIEW_BASE(m_page->viewWidget()), width); + webkitWebViewBaseSetInspectorViewSize(WEBKIT_WEB_VIEW_BASE(inspectedPage()->viewWidget()), width); } -void WebInspectorProxy::platformSetToolbarHeight(unsigned) +void WebInspectorProxy::platformStartWindowDrag() { notImplemented(); } @@ -245,11 +364,9 @@ void WebInspectorProxy::platformAppend(const String&, const String&) notImplemented(); } -void WebInspectorProxy::platformAttachAvailabilityChanged(bool) +void WebInspectorProxy::platformAttachAvailabilityChanged(bool available) { - notImplemented(); + m_client.didChangeAttachAvailability(this, available); } } // namespace WebKit - -#endif // ENABLE(INSPECTOR) diff --git a/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp b/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp index ac5ba7352..2dbae0582 100644 --- a/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp +++ b/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp @@ -27,14 +27,15 @@ #include "config.h" #include "WebPageProxy.h" -#include "NativeWebKeyboardEvent.h" #include "NotImplemented.h" #include "PageClientImpl.h" #include "WebKitWebViewBasePrivate.h" #include "WebPageMessages.h" #include "WebProcessProxy.h" +#include "WebsiteDataStore.h" #include <WebCore/UserAgentGtk.h> #include <gtk/gtkx.h> +#include <wtf/NeverDestroyed.h> namespace WebKit { @@ -52,34 +53,40 @@ String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent return WebCore::standardUserAgent(applicationNameForUserAgent); } -void WebPageProxy::getEditorCommandsForKeyEvent(const AtomicString& eventType, Vector<WTF::String>& commandsList) +void WebPageProxy::bindAccessibilityTree(const String& plugID) { - // When the keyboard event is started in the WebProcess side (e.g. from the Inspector) - // it will arrive without a GdkEvent associated, so the keyEventQueue will be empty. - if (!m_keyEventQueue.isEmpty()) - m_pageClient.getEditorCommandsForKeyEvent(m_keyEventQueue.first(), eventType, commandsList); + m_accessibilityPlugID = plugID; } -void WebPageProxy::bindAccessibilityTree(const String& plugID) +void WebPageProxy::saveRecentSearches(const String&, const Vector<WebCore::RecentSearch>&) { - m_accessibilityPlugID = plugID; + notImplemented(); } -void WebPageProxy::saveRecentSearches(const String&, const Vector<String>&) +void WebPageProxy::loadRecentSearches(const String&, Vector<WebCore::RecentSearch>&) { notImplemented(); } -void WebPageProxy::loadRecentSearches(const String&, Vector<String>&) +void WebsiteDataStore::platformRemoveRecentSearches(std::chrono::system_clock::time_point oldestTimeToRemove) { notImplemented(); } +void WebPageProxy::editorStateChanged(const EditorState& editorState) +{ + m_editorState = editorState; + + if (editorState.shouldIgnoreCompositionSelectionChange) + return; + m_pageClient.selectionDidChange(); +} + #if PLUGIN_ARCHITECTURE(X11) typedef HashMap<uint64_t, GtkWidget* > PluginWindowMap; static PluginWindowMap& pluginWindowMap() { - DEFINE_STATIC_LOCAL(PluginWindowMap, map, ()); + static NeverDestroyed<PluginWindowMap> map; return map; } @@ -134,10 +141,10 @@ void WebPageProxy::setInputMethodState(bool enabled) webkitWebViewBaseSetInputMethodState(WEBKIT_WEB_VIEW_BASE(viewWidget()), enabled); } -#if USE(TEXTURE_MAPPER_GL) -void WebPageProxy::setAcceleratedCompositingWindowId(uint64_t nativeWindowId) +#if HAVE(GTK_GESTURES) +void WebPageProxy::getCenterForZoomGesture(const WebCore::IntPoint& centerInViewCoordinates, WebCore::IntPoint& center) { - process().send(Messages::WebPage::SetAcceleratedCompositingWindowId(nativeWindowId), m_pageID); + process().sendSync(Messages::WebPage::GetCenterForZoomGesture(centerInViewCoordinates), Messages::WebPage::GetCenterForZoomGesture::Reply(center), m_pageID); } #endif diff --git a/Source/WebKit2/UIProcess/gtk/WebPopupMenuProxyGtk.cpp b/Source/WebKit2/UIProcess/gtk/WebPopupMenuProxyGtk.cpp index 782730de7..dc198d858 100644 --- a/Source/WebKit2/UIProcess/gtk/WebPopupMenuProxyGtk.cpp +++ b/Source/WebKit2/UIProcess/gtk/WebPopupMenuProxyGtk.cpp @@ -29,27 +29,28 @@ #include "NativeWebMouseEvent.h" #include "WebPopupItem.h" #include <WebCore/GtkUtilities.h> +#include <WebCore/IntRect.h> #include <gtk/gtk.h> -#include <wtf/gobject/GUniquePtr.h> +#include <wtf/glib/GUniquePtr.h> #include <wtf/text/CString.h> using namespace WebCore; namespace WebKit { -WebPopupMenuProxyGtk::WebPopupMenuProxyGtk(GtkWidget* webView, WebPopupMenuProxy::Client* client) +WebPopupMenuProxyGtk::WebPopupMenuProxyGtk(GtkWidget* webView, WebPopupMenuProxy::Client& client) : WebPopupMenuProxy(client) , m_webView(webView) - , m_activeItem(-1) + , m_popup(gtk_menu_new()) + , m_dismissMenuTimer(RunLoop::main(), this, &WebPopupMenuProxyGtk::dismissMenuTimerFired) { + g_signal_connect(m_popup, "key-press-event", G_CALLBACK(keyPressEventCallback), this); + g_signal_connect(m_popup, "unmap", G_CALLBACK(menuUnmappedCallback), this); } WebPopupMenuProxyGtk::~WebPopupMenuProxyGtk() { - if (m_popup) { - g_signal_handlers_disconnect_matched(m_popup->platformMenu(), G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this); - hidePopupMenu(); - } + cancelTracking(); } GtkAction* WebPopupMenuProxyGtk::createGtkActionForMenuItem(const WebPopupItem& item, int itemIndex) @@ -63,74 +64,214 @@ GtkAction* WebPopupMenuProxyGtk::createGtkActionForMenuItem(const WebPopupItem& return action; } -void WebPopupMenuProxyGtk::showPopupMenu(const IntRect& rect, TextDirection textDirection, double pageScaleFactor, const Vector<WebPopupItem>& items, const PlatformPopupMenuData& data, int32_t selectedIndex) +void WebPopupMenuProxyGtk::populatePopupMenu(const Vector<WebPopupItem>& items) { - if (m_popup) - m_popup->clear(); - else - m_popup = GtkPopupMenu::create(); - - const int size = items.size(); - for (int i = 0; i < size; i++) { - if (items[i].m_type == WebPopupItem::Separator) - m_popup->appendSeparator(); - else { - GRefPtr<GtkAction> action = adoptGRef(createGtkActionForMenuItem(items[i], i)); - m_popup->appendItem(action.get()); + int itemIndex = 0; + for (const auto& item : items) { + if (item.m_type == WebPopupItem::Separator) { + GtkWidget* menuItem = gtk_separator_menu_item_new(); + gtk_menu_shell_append(GTK_MENU_SHELL(m_popup), menuItem); + gtk_widget_show(menuItem); + } else { + GRefPtr<GtkAction> action = adoptGRef(createGtkActionForMenuItem(item, itemIndex)); + GtkWidget* menuItem = gtk_action_create_menu_item(action.get()); + gtk_widget_set_tooltip_text(menuItem, gtk_action_get_tooltip(action.get())); + g_signal_connect(menuItem, "select", G_CALLBACK(selectItemCallback), this); + gtk_menu_shell_append(GTK_MENU_SHELL(m_popup), menuItem); + + if (gtk_action_is_visible(action.get())) + gtk_widget_show(menuItem); } + itemIndex++; } +} + +void WebPopupMenuProxyGtk::showPopupMenu(const IntRect& rect, TextDirection, double /* pageScaleFactor */, const Vector<WebPopupItem>& items, const PlatformPopupMenuData&, int32_t selectedIndex) +{ + m_dismissMenuTimer.stop(); + + populatePopupMenu(items); + gtk_menu_set_active(GTK_MENU(m_popup), selectedIndex); + + resetTypeAheadFindState(); IntPoint menuPosition = convertWidgetPointToScreenPoint(m_webView, rect.location()); menuPosition.move(0, rect.height()); - gulong unmapHandler = g_signal_connect(m_popup->platformMenu(), "unmap", G_CALLBACK(menuUnmapped), this); - m_popup->popUp(rect.size(), menuPosition, size, selectedIndex, m_client->currentlyProcessedMouseDownEvent() ? m_client->currentlyProcessedMouseDownEvent()->nativeEvent() : 0); + // This approach follows the one in gtkcombobox.c. + GtkRequisition requisition; + gtk_widget_set_size_request(m_popup, -1, -1); + gtk_widget_get_preferred_size(m_popup, &requisition, nullptr); + gtk_widget_set_size_request(m_popup, std::max(rect.width(), requisition.width), -1); + + if (int itemCount = items.size()) { + GUniquePtr<GList> children(gtk_container_get_children(GTK_CONTAINER(m_popup))); + int i; + GList* child; + for (i = 0, child = children.get(); i < itemCount; i++, child = g_list_next(child)) { + if (i > selectedIndex) + break; + + GtkWidget* item = GTK_WIDGET(child->data); + GtkRequisition itemRequisition; + gtk_widget_get_preferred_size(item, &itemRequisition, nullptr); + menuPosition.setY(menuPosition.y() - itemRequisition.height); + } + } else { + // Center vertically the empty popup in the combo box area. + menuPosition.setY(menuPosition.y() - rect.height() / 2); + } + + const GdkEvent* event = m_client->currentlyProcessedMouseDownEvent() ? m_client->currentlyProcessedMouseDownEvent()->nativeEvent() : nullptr; + gtk_menu_popup_for_device(GTK_MENU(m_popup), event ? gdk_event_get_device(event) : nullptr, nullptr, nullptr, + [](GtkMenu*, gint* x, gint* y, gboolean* pushIn, gpointer userData) { + // We can pass a pointer to the menuPosition local variable because the nested main loop ensures this is called in the function context. + IntPoint* menuPosition = static_cast<IntPoint*>(userData); + *x = menuPosition->x(); + *y = menuPosition->y(); + *pushIn = menuPosition->y() < 0; + }, &menuPosition, nullptr, event && event->type == GDK_BUTTON_PRESS ? event->button.button : 1, + event ? gdk_event_get_time(event) : GDK_CURRENT_TIME); + + // Now that the menu has a position, schedule a resize to make sure it's resized to fit vertically in the work area. + gtk_widget_queue_resize(m_popup); // PopupMenu can fail to open when there is no mouse grab. // Ensure WebCore does not go into some pesky state. - if (!gtk_widget_get_visible(m_popup->platformMenu())) { + if (!gtk_widget_get_visible(m_popup)) { m_client->failedToShowPopupMenu(); return; } +} - // WebPageProxy expects the menu to run in a nested run loop, since it invalidates the - // menu right after calling WebPopupMenuProxy::showPopupMenu(). - m_runLoop = adoptGRef(g_main_loop_new(0, FALSE)); +void WebPopupMenuProxyGtk::hidePopupMenu() +{ + gtk_menu_popdown(GTK_MENU(m_popup)); + resetTypeAheadFindState(); +} - gdk_threads_leave(); - g_main_loop_run(m_runLoop.get()); - gdk_threads_enter(); +void WebPopupMenuProxyGtk::cancelTracking() +{ + if (!m_popup) + return; - m_runLoop.clear(); + m_dismissMenuTimer.stop(); + g_signal_handlers_disconnect_matched(m_popup, G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, this); + hidePopupMenu(); + gtk_widget_destroy(m_popup); + m_popup = nullptr; +} - g_signal_handler_disconnect(m_popup->platformMenu(), unmapHandler); +bool WebPopupMenuProxyGtk::typeAheadFind(GdkEventKey* event) +{ + // If we were given a non-printable character just skip it. + gunichar unicodeCharacter = gdk_keyval_to_unicode(event->keyval); + if (!g_unichar_isprint(unicodeCharacter)) { + resetTypeAheadFindState(); + return false; + } - if (!m_client) - return; + glong charactersWritten; + GUniquePtr<gunichar2> utf16String(g_ucs4_to_utf16(&unicodeCharacter, 1, nullptr, &charactersWritten, nullptr)); + if (!utf16String) { + resetTypeAheadFindState(); + return false; + } - m_client->valueChangedForPopupMenu(this, m_activeItem); + // If the character is the same as the last character, the user is probably trying to + // cycle through the menulist entries. This matches the WebCore behavior for collapsed menulists. + static const uint32_t searchTimeoutMs = 1000; + bool repeatingCharacter = unicodeCharacter != m_previousKeyEventCharacter; + if (event->time - m_previousKeyEventTimestamp > searchTimeoutMs) + m_currentSearchString = String(reinterpret_cast<UChar*>(utf16String.get()), charactersWritten); + else if (repeatingCharacter) + m_currentSearchString.append(String(reinterpret_cast<UChar*>(utf16String.get()), charactersWritten)); + + m_previousKeyEventTimestamp = event->time; + m_previousKeyEventCharacter = unicodeCharacter; + + GUniquePtr<GList> children(gtk_container_get_children(GTK_CONTAINER(m_popup))); + if (!children) + return true; + + // We case fold before searching, because strncmp does not handle non-ASCII characters. + GUniquePtr<gchar> searchStringWithCaseFolded(g_utf8_casefold(m_currentSearchString.utf8().data(), -1)); + size_t prefixLength = strlen(searchStringWithCaseFolded.get()); + + // If a menu item has already been selected, start searching from the current + // item down the list. This will make multiple key presses of the same character + // advance the selection. + GList* currentChild = children.get(); + if (m_currentlySelectedMenuItem) { + currentChild = g_list_find(children.get(), m_currentlySelectedMenuItem); + if (!currentChild) { + m_currentlySelectedMenuItem = nullptr; + currentChild = children.get(); + } + + // Repeating characters should iterate. + if (repeatingCharacter) { + if (GList* nextChild = g_list_next(currentChild)) + currentChild = nextChild; + } + } + + GList* firstChild = currentChild; + do { + currentChild = g_list_next(currentChild); + if (!currentChild) + currentChild = children.get(); + + GUniquePtr<gchar> itemText(g_utf8_casefold(gtk_menu_item_get_label(GTK_MENU_ITEM(currentChild->data)), -1)); + if (!strncmp(searchStringWithCaseFolded.get(), itemText.get(), prefixLength)) { + gtk_menu_shell_select_item(GTK_MENU_SHELL(m_popup), GTK_WIDGET(currentChild->data)); + break; + } + } while (currentChild != firstChild); + + return true; } -void WebPopupMenuProxyGtk::hidePopupMenu() +void WebPopupMenuProxyGtk::resetTypeAheadFindState() { - m_popup->popDown(); + m_currentlySelectedMenuItem = nullptr; + m_previousKeyEventCharacter = 0; + m_previousKeyEventTimestamp = 0; + m_currentSearchString = emptyString(); } -void WebPopupMenuProxyGtk::shutdownRunLoop() +void WebPopupMenuProxyGtk::menuItemActivated(GtkAction* action, WebPopupMenuProxyGtk* popupMenu) { - if (g_main_loop_is_running(m_runLoop.get())) - g_main_loop_quit(m_runLoop.get()); + popupMenu->m_dismissMenuTimer.stop(); + if (popupMenu->m_client) + popupMenu->m_client->valueChangedForPopupMenu(popupMenu, GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "popup-menu-action-index"))); } -void WebPopupMenuProxyGtk::menuItemActivated(GtkAction* action, WebPopupMenuProxyGtk* popupMenu) +void WebPopupMenuProxyGtk::dismissMenuTimerFired() +{ + if (m_client) + m_client->valueChangedForPopupMenu(this, -1); +} + +void WebPopupMenuProxyGtk::menuUnmappedCallback(GtkWidget*, WebPopupMenuProxyGtk* popupMenu) +{ + if (!popupMenu->m_client) + return; + + // When an item is activated, the menu is first hidden and then activate signal is emitted, so at this point we don't know + // if the menu has been hidden because an item has been selected or because the menu has been dismissed. Wait until the next + // main loop iteration to dismiss the menu, if an item is activated the timer will be cancelled. + popupMenu->m_dismissMenuTimer.startOneShot(0); +} + +void WebPopupMenuProxyGtk::selectItemCallback(GtkWidget* item, WebPopupMenuProxyGtk* popupMenu) { - popupMenu->setActiveItem(GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "popup-menu-action-index"))); - popupMenu->shutdownRunLoop(); + popupMenu->setCurrentlySelectedMenuItem(item); } -void WebPopupMenuProxyGtk::menuUnmapped(GtkWidget*, WebPopupMenuProxyGtk* popupMenu) +gboolean WebPopupMenuProxyGtk::keyPressEventCallback(GtkWidget*, GdkEventKey* event, WebPopupMenuProxyGtk* popupMenu) { - popupMenu->shutdownRunLoop(); + return popupMenu->typeAheadFind(event); } } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/gtk/WebPopupMenuProxyGtk.h b/Source/WebKit2/UIProcess/gtk/WebPopupMenuProxyGtk.h index 4b335bcde..9c639fef8 100644 --- a/Source/WebKit2/UIProcess/gtk/WebPopupMenuProxyGtk.h +++ b/Source/WebKit2/UIProcess/gtk/WebPopupMenuProxyGtk.h @@ -21,11 +21,16 @@ #define WebPopupMenuProxyGtk_h #include "WebPopupMenuProxy.h" -#include <WebCore/GtkPopupMenu.h> -#include <WebCore/IntRect.h> -#include <wtf/gobject/GRefPtr.h> +#include <wtf/RunLoop.h> +#include <wtf/glib/GRefPtr.h> +#include <wtf/text/WTFString.h> typedef struct _GMainLoop GMainLoop; +typedef struct _GdkEventKey GdkEventKey; + +namespace WebCore { +class IntRect; +} namespace WebKit { @@ -33,28 +38,42 @@ class WebPageProxy; class WebPopupMenuProxyGtk : public WebPopupMenuProxy { public: - static PassRefPtr<WebPopupMenuProxyGtk> create(GtkWidget* webView, WebPopupMenuProxy::Client* client) + static Ref<WebPopupMenuProxyGtk> create(GtkWidget* webView, WebPopupMenuProxy::Client& client) { - return adoptRef(new WebPopupMenuProxyGtk(webView, client)); + return adoptRef(*new WebPopupMenuProxyGtk(webView, client)); } ~WebPopupMenuProxyGtk(); - virtual void showPopupMenu(const WebCore::IntRect&, WebCore::TextDirection, double pageScaleFactor, const Vector<WebPopupItem>&, const PlatformPopupMenuData&, int32_t selectedIndex); - virtual void hidePopupMenu(); + virtual void showPopupMenu(const WebCore::IntRect&, WebCore::TextDirection, double pageScaleFactor, const Vector<WebPopupItem>&, const PlatformPopupMenuData&, int32_t selectedIndex) override; + virtual void hidePopupMenu() override; + virtual void cancelTracking() override; private: - WebPopupMenuProxyGtk(GtkWidget*, WebPopupMenuProxy::Client*); - void shutdownRunLoop(); - void setActiveItem(int activeItem) { m_activeItem = activeItem; } + WebPopupMenuProxyGtk(GtkWidget*, WebPopupMenuProxy::Client&); + + void setCurrentlySelectedMenuItem(GtkWidget* item) { m_currentlySelectedMenuItem = item; } GtkAction* createGtkActionForMenuItem(const WebPopupItem&, int itemIndex); + void populatePopupMenu(const Vector<WebPopupItem>&); + void dismissMenuTimerFired(); + + bool typeAheadFind(GdkEventKey*); + void resetTypeAheadFindState(); static void menuItemActivated(GtkAction*, WebPopupMenuProxyGtk*); - static void menuUnmapped(GtkWidget*, WebPopupMenuProxyGtk*); + static void selectItemCallback(GtkWidget*, WebPopupMenuProxyGtk*); + static gboolean keyPressEventCallback(GtkWidget*, GdkEventKey*, WebPopupMenuProxyGtk*); + static void menuUnmappedCallback(GtkWidget*, WebPopupMenuProxyGtk*); + + GtkWidget* m_webView { nullptr }; + GtkWidget* m_popup { nullptr }; + + RunLoop::Timer<WebPopupMenuProxyGtk> m_dismissMenuTimer; - GtkWidget* m_webView; - OwnPtr<WebCore::GtkPopupMenu> m_popup; - int m_activeItem; - GRefPtr<GMainLoop> m_runLoop; + // Typeahead find. + unsigned m_previousKeyEventCharacter { 0 }; + uint32_t m_previousKeyEventTimestamp { 0 }; + GtkWidget* m_currentlySelectedMenuItem { nullptr }; + String m_currentSearchString; }; } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/gtk/WebPreferencesGtk.cpp b/Source/WebKit2/UIProcess/gtk/WebPreferencesGtk.cpp index 321a9cfcc..ae14e9ea0 100644 --- a/Source/WebKit2/UIProcess/gtk/WebPreferencesGtk.cpp +++ b/Source/WebKit2/UIProcess/gtk/WebPreferencesGtk.cpp @@ -28,12 +28,30 @@ #include "WebPreferences.h" #include <WebCore/NotImplemented.h> +#include <WebCore/PlatformDisplay.h> namespace WebKit { void WebPreferences::platformInitializeStore() { - notImplemented(); +#if PLATFORM(WAYLAND) + if (WebCore::PlatformDisplay::sharedDisplay().type() == WebCore::PlatformDisplay::Type::Wayland) { + // FIXME: Accelerated compositing under Wayland is not yet supported. + // https://bugs.webkit.org/show_bug.cgi?id=115803 + setAcceleratedCompositingEnabled(false); + } +#endif +#if USE(COORDINATED_GRAPHICS_THREADED) + setForceCompositingMode(true); +#endif +#if !ENABLE(OPENGL) + setAcceleratedCompositingEnabled(false); +#else + if (getenv("WEBKIT_FORCE_COMPOSITING_MODE")) + setForceCompositingMode(true); + if (getenv("WEBKIT_DISABLE_COMPOSITING_MODE")) + setAcceleratedCompositingEnabled(false); +#endif } void WebPreferences::platformUpdateStringValueForKey(const String&, const String&) @@ -61,4 +79,28 @@ void WebPreferences::platformUpdateFloatValueForKey(const String&, float) notImplemented(); } +bool WebPreferences::platformGetStringUserValueForKey(const String&, String&) +{ + notImplemented(); + return false; +} + +bool WebPreferences::platformGetBoolUserValueForKey(const String&, bool&) +{ + notImplemented(); + return false; +} + +bool WebPreferences::platformGetUInt32UserValueForKey(const String&, uint32_t&) +{ + notImplemented(); + return false; +} + +bool WebPreferences::platformGetDoubleUserValueForKey(const String&, double&) +{ + notImplemented(); + return false; +} + } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/gtk/WebContextGtk.cpp b/Source/WebKit2/UIProcess/gtk/WebProcessPoolGtk.cpp index fbddf8f67..4efce39d9 100644 --- a/Source/WebKit2/UIProcess/gtk/WebContextGtk.cpp +++ b/Source/WebKit2/UIProcess/gtk/WebProcessPoolGtk.cpp @@ -26,9 +26,11 @@ */ #include "config.h" -#include "WebContext.h" +#include "WebProcessPool.h" +#include "APIProcessPoolConfiguration.h" #include "Logging.h" +#include "NetworkProcessMessages.h" #include "WebCookieManagerProxy.h" #include "WebInspectorServer.h" #include "WebProcessCreationParameters.h" @@ -37,13 +39,9 @@ #include <WebCore/FileSystem.h> #include <WebCore/NotImplemented.h> #include <WebCore/SchemeRegistry.h> -#include <wtf/gobject/GUniquePtr.h> +#include <wtf/glib/GUniquePtr.h> #include <wtf/text/CString.h> -#if ENABLE(NETWORK_PROCESS) -#include "NetworkProcessMessages.h" -#endif - namespace WebKit { static void initInspectorServer() @@ -61,7 +59,7 @@ static void initInspectorServer() unsigned short port = 2999; Vector<String> result; - serverAddress.split(":", result); + serverAddress.split(':', result); if (result.size() == 2) { bindAddress = result[0]; @@ -74,7 +72,7 @@ static void initInspectorServer() } else LOG_ERROR("Couldn't parse %s, wrong format? Use 127.0.0.1:2999 instead.", serverAddress.utf8().data()); - if (!WebInspectorServer::shared().listen(bindAddress, port)) + if (!WebInspectorServer::singleton().listen(bindAddress, port)) LOG_ERROR("Couldn't start listening on: IP address=%s, port=%d.", bindAddress.utf8().data(), port); return; } @@ -83,77 +81,57 @@ static void initInspectorServer() #endif } -WTF::String WebContext::platformDefaultApplicationCacheDirectory() const +WTF::String WebProcessPool::legacyPlatformDefaultApplicationCacheDirectory() { - GUniquePtr<gchar> cacheDirectory(g_build_filename(g_get_user_cache_dir(), "webkitgtk", "applications", nullptr)); - return WebCore::filenameToString(cacheDirectory.get()); + return API::WebsiteDataStore::defaultApplicationCacheDirectory(); } -void WebContext::platformInitializeWebProcess(WebProcessCreationParameters& parameters) +void WebProcessPool::platformInitializeWebProcess(WebProcessCreationParameters& parameters) { initInspectorServer(); + parameters.memoryCacheDisabled = m_memoryCacheDisabled || cacheModel() == CacheModelDocumentViewer; +} - if (!parameters.urlSchemesRegisteredAsLocal.contains("resource")) { - WebCore::SchemeRegistry::registerURLSchemeAsLocal("resource"); - parameters.urlSchemesRegisteredAsLocal.append("resource"); - } - - if (!usesNetworkProcess()) { - parameters.urlSchemesRegisteredForCustomProtocols = supplement<WebSoupCustomProtocolRequestManager>()->registeredSchemesForCustomProtocols(); - - supplement<WebCookieManagerProxy>()->getCookiePersistentStorage(parameters.cookiePersistentStoragePath, parameters.cookiePersistentStorageType); - parameters.cookieAcceptPolicy = m_initialHTTPCookieAcceptPolicy; - - parameters.ignoreTLSErrors = m_ignoreTLSErrors; - } - - parameters.shouldTrackVisitedLinks = true; +void WebProcessPool::platformInvalidateContext() +{ } -void WebContext::platformInvalidateContext() +String WebProcessPool::legacyPlatformDefaultWebSQLDatabaseDirectory() { + return API::WebsiteDataStore::defaultWebSQLDatabaseDirectory(); } -String WebContext::platformDefaultDatabaseDirectory() const +String WebProcessPool::legacyPlatformDefaultIndexedDBDatabaseDirectory() { - GUniquePtr<gchar> databaseDirectory(g_build_filename(g_get_user_data_dir(), "webkitgtk", "databases", nullptr)); - return WebCore::filenameToString(databaseDirectory.get()); + return API::WebsiteDataStore::defaultIndexedDBDatabaseDirectory(); } -String WebContext::platformDefaultIconDatabasePath() const +String WebProcessPool::platformDefaultIconDatabasePath() const { GUniquePtr<gchar> databaseDirectory(g_build_filename(g_get_user_cache_dir(), "webkitgtk", "icondatabase", nullptr)); return WebCore::filenameToString(databaseDirectory.get()); } -String WebContext::platformDefaultLocalStorageDirectory() const +String WebProcessPool::legacyPlatformDefaultLocalStorageDirectory() { - GUniquePtr<gchar> storageDirectory(g_build_filename(g_get_user_data_dir(), "webkitgtk", "localstorage", nullptr)); - return WebCore::filenameToString(storageDirectory.get()); + return API::WebsiteDataStore::defaultLocalStorageDirectory(); } -String WebContext::platformDefaultDiskCacheDirectory() const +String WebProcessPool::legacyPlatformDefaultMediaKeysStorageDirectory() { - GUniquePtr<char> diskCacheDirectory(g_build_filename(g_get_user_cache_dir(), g_get_prgname(), nullptr)); - return WebCore::filenameToString(diskCacheDirectory.get()); + return API::WebsiteDataStore::defaultMediaKeysStorageDirectory(); } -String WebContext::platformDefaultCookieStorageDirectory() const +String WebProcessPool::legacyPlatformDefaultNetworkCacheDirectory() { - notImplemented(); - return String(); + return API::WebsiteDataStore::defaultNetworkCacheDirectory(); } -void WebContext::setIgnoreTLSErrors(bool ignoreTLSErrors) +void WebProcessPool::setIgnoreTLSErrors(bool ignoreTLSErrors) { m_ignoreTLSErrors = ignoreTLSErrors; -#if ENABLE(NETWORK_PROCESS) - if (usesNetworkProcess() && networkProcess()) { + if (networkProcess()) networkProcess()->send(Messages::NetworkProcess::SetIgnoreTLSErrors(m_ignoreTLSErrors), 0); - return; - } -#endif - sendToAllProcesses(Messages::WebProcess::SetIgnoreTLSErrors(m_ignoreTLSErrors)); } } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/soup/WebCookieManagerProxySoup.cpp b/Source/WebKit2/UIProcess/soup/WebCookieManagerProxySoup.cpp index 457e0370f..af443eca6 100644 --- a/Source/WebKit2/UIProcess/soup/WebCookieManagerProxySoup.cpp +++ b/Source/WebKit2/UIProcess/soup/WebCookieManagerProxySoup.cpp @@ -26,14 +26,14 @@ #include "config.h" #include "WebCookieManagerProxy.h" -#include "WebContext.h" #include "WebCookieManagerMessages.h" +#include "WebProcessPool.h" namespace WebKit { void WebCookieManagerProxy::setCookiePersistentStorage(const String& storagePath, uint32_t storageType) { - context()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::SetCookiePersistentStorage(storagePath, storageType)); + processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::SetCookiePersistentStorage(storagePath, storageType)); m_cookiePersistentStoragePath = storagePath; m_cookiePersistentStorageType = static_cast<SoupCookiePersistentStorageType>(storageType); diff --git a/Source/WebKit2/UIProcess/soup/WebContextSoup.cpp b/Source/WebKit2/UIProcess/soup/WebProcessPoolSoup.cpp index 43ee6719a..72682edc4 100644 --- a/Source/WebKit2/UIProcess/soup/WebContextSoup.cpp +++ b/Source/WebKit2/UIProcess/soup/WebProcessPoolSoup.cpp @@ -24,8 +24,7 @@ */ #include "config.h" -#if ENABLE(NETWORK_PROCESS) -#include "WebContext.h" +#include "WebProcessPool.h" #include "NetworkProcessCreationParameters.h" #include "WebCookieManagerProxy.h" @@ -34,17 +33,16 @@ namespace WebKit { -void WebContext::platformInitializeNetworkProcess(NetworkProcessCreationParameters& parameters) +void WebProcessPool::platformInitializeNetworkProcess(NetworkProcessCreationParameters& parameters) { supplement<WebCookieManagerProxy>()->getCookiePersistentStorage(parameters.cookiePersistentStoragePath, parameters.cookiePersistentStorageType); parameters.cookieAcceptPolicy = m_initialHTTPCookieAcceptPolicy; parameters.ignoreTLSErrors = m_ignoreTLSErrors; parameters.languages = WebCore::userPreferredLanguages(); -#if ENABLE(CUSTOM_PROTOCOLS) parameters.urlSchemesRegisteredForCustomProtocols = supplement<WebSoupCustomProtocolRequestManager>()->registeredSchemesForCustomProtocols(); +#if ENABLE(NETWORK_CACHE) + parameters.shouldEnableNetworkCacheEfficacyLogging = false; #endif } } - -#endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebViewBaseInputMethodFilter.h b/Source/WebKit2/UIProcess/soup/WebSoupRequestManagerClient.h index 9cde8b12d..1b9d4a6a1 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebViewBaseInputMethodFilter.h +++ b/Source/WebKit2/UIProcess/soup/WebSoupRequestManagerClient.h @@ -17,33 +17,31 @@ * Boston, MA 02110-1301, USA. */ -#ifndef WebViewBaseInputMethodFilter_h -#define WebViewBaseInputMethodFilter_h +#ifndef WebSoupRequestManagerClient_h +#define WebSoupRequestManagerClient_h -#include "GtkInputMethodFilter.h" -#include "WebPageProxy.h" +#include "APIClient.h" +#include "WKAPICast.h" +#include "WKSoupRequestManager.h" -typedef struct _WebKitWebViewBase WebKitWebViewBase; +namespace API { +class URL; + +template<> struct ClientTraits<WKSoupRequestManagerClientBase> { + typedef std::tuple<WKSoupRequestManagerClientV0> Versions; +}; +} namespace WebKit { -class WebViewBaseInputMethodFilter : public WebCore::GtkInputMethodFilter { +class WebSoupRequestManagerProxy; + +class WebSoupRequestManagerClient : public API::Client<WKSoupRequestManagerClientBase> { public: - void setWebView(WebKitWebViewBase*); - -protected: - virtual bool sendSimpleKeyEvent(GdkEventKey*, WTF::String eventString, EventFakedForComposition); - virtual bool sendKeyEventWithCompositionResults(GdkEventKey*, ResultsToSend, EventFakedForComposition); - virtual bool canEdit(); - virtual void confirmCompositionText(String); - virtual void confirmCurrentComposition(); - virtual void cancelCurrentComposition(); - virtual void setPreedit(String, int cursorOffset); - -private: - WebPageProxy* m_webPageProxy; + bool didReceiveURIRequest(WebSoupRequestManagerProxy*, API::URL*, WebPageProxy*, uint64_t requestID); + void didFailToLoadURIRequest(WebSoupRequestManagerProxy*, uint64_t requestID); }; } // namespace WebKit -#endif // WebViewBaseInputMethodFilter_h +#endif // WebSoupRequestManagerClient_h diff --git a/Source/WebKit2/UIProcess/soup/WebSoupRequestManagerProxy.h b/Source/WebKit2/UIProcess/soup/WebSoupRequestManagerProxy.h new file mode 100644 index 000000000..87c18a4c5 --- /dev/null +++ b/Source/WebKit2/UIProcess/soup/WebSoupRequestManagerProxy.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2012 Igalia S.L. + * Copyright (C) 2013 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef WebSoupRequestManagerProxy_h +#define WebSoupRequestManagerProxy_h + +#include "APIObject.h" +#include "MessageReceiver.h" +#include "WebContextSupplement.h" +#include "WebSoupRequestManagerClient.h" +#include <wtf/PassRefPtr.h> +#include <wtf/RefPtr.h> +#include <wtf/text/WTFString.h> + +namespace API { +class Data; +} + +namespace WebKit { + +class WebProcessPool; + +class WebSoupRequestManagerProxy : public API::ObjectImpl<API::Object::Type::SoupRequestManager>, public WebContextSupplement, private IPC::MessageReceiver { +public: + static const char* supplementName(); + + static PassRefPtr<WebSoupRequestManagerProxy> create(WebProcessPool*); + virtual ~WebSoupRequestManagerProxy(); + + void initializeClient(const WKSoupRequestManagerClientBase*); + + void registerURIScheme(const String& scheme); + void didHandleURIRequest(const API::Data*, uint64_t contentLength, const String& mimeType, uint64_t requestID); + void didReceiveURIRequestData(const API::Data*, uint64_t requestID); + void didReceiveURIRequest(const String& uriString, WebPageProxy*, uint64_t requestID); + void didFailURIRequest(const WebCore::ResourceError&, uint64_t requestID); + + const Vector<String>& registeredURISchemes() const { return m_registeredURISchemes; } + + using API::Object::ref; + using API::Object::deref; + +private: + WebSoupRequestManagerProxy(WebProcessPool*); + + // WebContextSupplement + virtual void contextDestroyed() override; + virtual void processDidClose(WebProcessProxy*) override; + virtual void refWebContextSupplement() override; + virtual void derefWebContextSupplement() override; + + // IPC::MessageReceiver + virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; + + void didFailToLoadURIRequest(uint64_t requestID); + + WebSoupRequestManagerClient m_client; + bool m_loadFailed; + Vector<String> m_registeredURISchemes; +}; + +} // namespace WebKit + +#endif // WebSoupRequestManagerProxy_h |
