forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://bugs.webkit.org/show_bug.cgi?id=279142 rdar://135297138 Reviewed by Ben Nham. This will make it easier to test webpushd functionalities. Tests: WebPushD.WKWebPushDaemonConnectionRequestPushPermission WebPushD.WKWebPushDaemonConnectionPushSubscription * Source/WebKit/Shared/API/APIObject.h: * Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h: * Source/WebKit/Shared/Cocoa/APIObject.mm: (API::Object::newObject): * Source/WebKit/Sources.txt: * Source/WebKit/SourcesCocoa.txt: * Source/WebKit/UIProcess/API/APIWebPushDaemonConnection.cpp: Added. (API::WebPushDaemonConnection::WebPushDaemonConnection): (API::WebPushDaemonConnection::getPushPermissionState): (API::WebPushDaemonConnection::requestPushPermission): (API::WebPushDaemonConnection::setAppBadge): (API::WebPushDaemonConnection::subscribeToPushService): (API::WebPushDaemonConnection::unsubscribeFromPushService): (API::WebPushDaemonConnection::getPushSubscription): (API::WebPushDaemonConnection::getNextPendingPushMessage): * Source/WebKit/UIProcess/API/APIWebPushDaemonConnection.h: Added. * Source/WebKit/UIProcess/API/APIWebPushMessage.h: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h. * Source/WebKit/UIProcess/API/APIWebPushSubscriptionData.h: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h. * Source/WebKit/UIProcess/API/Cocoa/_WKWebPushDaemonConnection.h: Added. * Source/WebKit/UIProcess/API/Cocoa/_WKWebPushDaemonConnection.mm: Added. (-[_WKWebPushDaemonConnectionConfiguration init]): (-[_WKWebPushDaemonConnection initWithConfiguration:]): (toWKPermissionsState): (-[_WKWebPushDaemonConnection getPushPermissionStateForOrigin:completionHandler:]): (-[_WKWebPushDaemonConnection requestPushPermissionForOrigin:completionHandler:]): (-[_WKWebPushDaemonConnection setAppBadge:origin:]): (-[_WKWebPushDaemonConnection subscribeToPushServiceForScope:applicationServerKey:completionHandler:]): (-[_WKWebPushDaemonConnection unsubscribeFromPushServiceForScope:completionHandler:]): (-[_WKWebPushDaemonConnection getSubscriptionForScope:completionHandler:]): (-[_WKWebPushDaemonConnection getNextPendingPushMessage:]): (-[_WKWebPushDaemonConnection _apiObject]): * Source/WebKit/UIProcess/API/Cocoa/_WKWebPushDaemonConnectionInternal.h: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h. * Source/WebKit/UIProcess/API/Cocoa/_WKWebPushMessage.h: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h. * Source/WebKit/UIProcess/API/Cocoa/_WKWebPushMessage.mm: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h. (-[_WKWebPushMessage dealloc]): (-[_WKWebPushMessage data]): (-[_WKWebPushMessage scope]): (-[_WKWebPushMessage partition]): (-[_WKWebPushMessage _apiObject]): * Source/WebKit/UIProcess/API/Cocoa/_WKWebPushMessageInternal.h: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h. * Source/WebKit/UIProcess/API/Cocoa/_WKWebPushSubscriptionData.h: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h. * Source/WebKit/UIProcess/API/Cocoa/_WKWebPushSubscriptionData.mm: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h. (-[_WKWebPushSubscriptionData dealloc]): (-[_WKWebPushSubscriptionData endpoint]): (-[_WKWebPushSubscriptionData applicationServerKey]): (-[_WKWebPushSubscriptionData authenticationSecret]): (-[_WKWebPushSubscriptionData ecdhPublicKey]): (-[_WKWebPushSubscriptionData _apiObject]): * Source/WebKit/UIProcess/API/Cocoa/_WKWebPushSubscriptionDataInternal.h: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h. * Source/WebKit/UIProcess/API/ios/WKWebViewTestingIOS.mm: * Source/WebKit/WebKit.xcodeproj/project.pbxproj: * Tools/TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm: (TestWebKitAPI::(WebPushD, WKWebPushDaemonConnectionRequestPushPermission)): (TestWebKitAPI::(WebPushD, WKWebPushDaemonConnectionPushSubscription)): Canonical link: https://commits.webkit.org/283218@main
- Loading branch information
Showing
21 changed files
with
983 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
Source/WebKit/UIProcess/API/APIWebPushDaemonConnection.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright (C) 2024 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 "APIWebPushDaemonConnection.h" | ||
|
||
#include "MessageSenderInlines.h" | ||
#include "PushClientConnectionMessages.h" | ||
#include "WebPushMessage.h" | ||
#include <WebCore/ExceptionData.h> | ||
#include <WebCore/PushPermissionState.h> | ||
#include <WebCore/PushSubscriptionData.h> | ||
|
||
namespace API { | ||
|
||
WebPushDaemonConnection::WebPushDaemonConnection(const WTF::String& machServiceName, const WTF::String& partition, const WTF::String& bundleIdentifier) | ||
#if ENABLE(WEB_PUSH_NOTIFICATIONS) | ||
: m_connection(makeUniqueRef<WebKit::WebPushD::Connection>(machServiceName.utf8(), WebKit::WebPushD::WebPushDaemonConnectionConfiguration { { }, bundleIdentifier, partition, { } })) | ||
#endif | ||
{ | ||
} | ||
|
||
void WebPushDaemonConnection::getPushPermissionState(const WTF::URL& scopeURL, CompletionHandler<void(WebCore::PushPermissionState)>&& completionHandler) | ||
{ | ||
#if ENABLE(WEB_PUSH_NOTIFICATIONS) | ||
m_connection->sendWithAsyncReplyWithoutUsingIPCConnection(Messages::PushClientConnection::GetPushPermissionState(SecurityOriginData::fromURL(scopeURL)), WTFMove(completionHandler)); | ||
#else | ||
completionHandler(WebCore::PushPermissionState::Denied); | ||
#endif | ||
} | ||
|
||
void WebPushDaemonConnection::requestPushPermission(const WTF::URL& scopeURL, CompletionHandler<void(bool)>&& completionHandler) | ||
{ | ||
#if ENABLE(WEB_PUSH_NOTIFICATIONS) | ||
m_connection->sendWithAsyncReplyWithoutUsingIPCConnection(Messages::PushClientConnection::RequestPushPermission(SecurityOriginData::fromURL(scopeURL)), WTFMove(completionHandler)); | ||
#else | ||
completionHandler(false); | ||
#endif | ||
} | ||
|
||
void WebPushDaemonConnection::setAppBadge(const WTF::URL& scopeURL, std::optional<uint64_t> badge) | ||
{ | ||
#if ENABLE(WEB_PUSH_NOTIFICATIONS) | ||
m_connection->sendWithoutUsingIPCConnection(Messages::PushClientConnection::SetAppBadge(SecurityOriginData::fromURL(scopeURL), badge)); | ||
#endif | ||
} | ||
|
||
void WebPushDaemonConnection::subscribeToPushService(const WTF::URL& scopeURL, const Vector<uint8_t>& applicationServerKey, CompletionHandler<void(const Expected<WebCore::PushSubscriptionData, WebCore::ExceptionData>&)>&& completionHandler) | ||
{ | ||
#if ENABLE(WEB_PUSH_NOTIFICATIONS) | ||
m_connection->sendWithAsyncReplyWithoutUsingIPCConnection(Messages::PushClientConnection::SubscribeToPushService(scopeURL, applicationServerKey), WTFMove(completionHandler)); | ||
#else | ||
completionHandler(makeUnexpected(WebCore::ExceptionData { WebCore::ExceptionCode::UnknownError, "Cannot subscribe to push service"_s })); | ||
#endif | ||
} | ||
|
||
void WebPushDaemonConnection::unsubscribeFromPushService(const WTF::URL& scopeURL, CompletionHandler<void(const Expected<bool, WebCore::ExceptionData>&)>&& completionHandler) | ||
{ | ||
#if ENABLE(WEB_PUSH_NOTIFICATIONS) | ||
m_connection->sendWithAsyncReplyWithoutUsingIPCConnection(Messages::PushClientConnection::UnsubscribeFromPushService(scopeURL, std::nullopt), WTFMove(completionHandler)); | ||
#else | ||
completionHandler(false); | ||
#endif | ||
} | ||
|
||
void WebPushDaemonConnection::getPushSubscription(const WTF::URL& scopeURL, CompletionHandler<void(const Expected<std::optional<WebCore::PushSubscriptionData>, WebCore::ExceptionData>&)>&& completionHandler) | ||
{ | ||
#if ENABLE(WEB_PUSH_NOTIFICATIONS) | ||
m_connection->sendWithAsyncReplyWithoutUsingIPCConnection(Messages::PushClientConnection::GetPushSubscription(WTFMove(scopeURL)), WTFMove(completionHandler)); | ||
#else | ||
completionHandler(std::optional<WebCore::PushSubscriptionData> { }); | ||
#endif | ||
} | ||
|
||
void WebPushDaemonConnection::getNextPendingPushMessage(CompletionHandler<void(const std::optional<WebKit::WebPushMessage>&)>&& completionHandler) | ||
{ | ||
#if ENABLE(WEB_PUSH_NOTIFICATIONS) | ||
m_connection->sendWithAsyncReplyWithoutUsingIPCConnection(Messages::PushClientConnection::GetPendingPushMessage(), WTFMove(completionHandler)); | ||
#else | ||
completionHandler(std::nullopt); | ||
#endif | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (C) 2024 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "APIObject.h" | ||
#include "WebPushDaemonConnection.h" | ||
|
||
namespace WebCore { | ||
enum class PushPermissionState : uint8_t; | ||
struct ExceptionData; | ||
struct PushSubscriptionData; | ||
} | ||
|
||
namespace WebKit { | ||
namespace WebPushD { | ||
class Connection; | ||
} | ||
struct WebPushMessage; | ||
} | ||
|
||
namespace API { | ||
|
||
class WebPushDaemonConnection final : public ObjectImpl<Object::Type::WebPushDaemonConnection> { | ||
public: | ||
WebPushDaemonConnection(const WTF::String& machServiceName, const WTF::String& partition, const WTF::String& bundleIdentifier); | ||
|
||
void getPushPermissionState(const WTF::URL&, CompletionHandler<void(WebCore::PushPermissionState)>&&); | ||
void requestPushPermission(const WTF::URL&, CompletionHandler<void(bool)>&&); | ||
void setAppBadge(const WTF::URL&, std::optional<uint64_t>); | ||
void subscribeToPushService(const WTF::URL&, const Vector<uint8_t>& applicationServerKey, CompletionHandler<void(const Expected<WebCore::PushSubscriptionData, WebCore::ExceptionData>&)>&&); | ||
void unsubscribeFromPushService(const WTF::URL&, CompletionHandler<void(const Expected<bool, WebCore::ExceptionData>&)>&&); | ||
void getPushSubscription(const WTF::URL&, CompletionHandler<void(const Expected<std::optional<WebCore::PushSubscriptionData>, WebCore::ExceptionData>&)>&&); | ||
void getNextPendingPushMessage(CompletionHandler<void(const std::optional<WebKit::WebPushMessage>&)>&&); | ||
|
||
private: | ||
#if ENABLE(WEB_PUSH_NOTIFICATIONS) | ||
UniqueRef<WebKit::WebPushD::Connection> m_connection; | ||
#endif | ||
}; | ||
|
||
} // namespace API |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (C) 2024 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "APIObject.h" | ||
#include "WebPushMessage.h" | ||
|
||
namespace API { | ||
|
||
class WebPushMessage final : public ObjectImpl<Object::Type::WebPushMessage> { | ||
public: | ||
static Ref<WebPushMessage> create(WebKit::WebPushMessage&& message) | ||
{ | ||
return adoptRef(*new WebPushMessage(WTFMove(message))); | ||
} | ||
|
||
explicit WebPushMessage(WebKit::WebPushMessage&& message) | ||
: m_message(WTFMove(message)) { } | ||
|
||
std::optional<Vector<uint8_t>> data() const { return m_message.pushData; }; | ||
WTF::URL scope() const { return m_message.registrationURL; } | ||
WTF::String partition() const { return m_message.pushPartitionString; } | ||
|
||
private: | ||
WebKit::WebPushMessage m_message; | ||
}; | ||
|
||
} // namespace API |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (C) 2024 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "APIObject.h" | ||
#include <WebCore/PushSubscriptionData.h> | ||
|
||
namespace API { | ||
|
||
class WebPushSubscriptionData final : public ObjectImpl<Object::Type::WebPushSubscriptionData> { | ||
public: | ||
static Ref<WebPushSubscriptionData> create(WebCore::PushSubscriptionData&& data) | ||
{ | ||
return adoptRef(*new WebPushSubscriptionData(WTFMove(data))); | ||
} | ||
|
||
explicit WebPushSubscriptionData(WebCore::PushSubscriptionData&& data) | ||
: m_data(WTFMove(data)) { } | ||
|
||
WTF::URL endpoint() const { return WTF::URL { m_data.endpoint }; } | ||
Vector<uint8_t> applicationServerKey() const { return m_data.serverVAPIDPublicKey; } | ||
Vector<uint8_t> clientECDHPublicKey() const { return m_data.clientECDHPublicKey; } | ||
Vector<uint8_t> sharedAuthenticationSecret() const { return m_data.sharedAuthenticationSecret; } | ||
|
||
private: | ||
const WebCore::PushSubscriptionData m_data; | ||
}; | ||
|
||
} // namespace API |
Oops, something went wrong.