source: webkit/trunk/Source/WebKit/webpushd/WebPushDaemon.h@ 286355

Last change on this file since 286355 was 286355, checked in by beidson@apple.com, 3 years ago

Add WKWebsiteDataStore configuration option to enable Mock app bundle testing.
https://bugs.webkit.org/show_bug.cgi?id=233679

Reviewed by Tim Horton.

Source/WebKit:

Covered by API tests.

We're about to land actual implementations of app permissions bundles.
But the mock bundles still have a place for testing.
We need a way to switch between Mock and Native.

This patch takes the opportunity to plumb out a WebPushDaemonConnectionConfiguration object
that can easily be augmented in future patches to add new options without messing with messaging directly.

  • NetworkProcess/NetworkSession.h:

(WebKit::NetworkSession::webpushdUsesMockBundlesForTesting const):

  • NetworkProcess/NetworkSessionCreationParameters.cpp:

(WebKit::NetworkSessionCreationParameters::encode const):
(WebKit::NetworkSessionCreationParameters::decode):

  • NetworkProcess/NetworkSessionCreationParameters.h:
  • NetworkProcess/Notifications/NetworkNotificationManager.cpp:

(WebKit::NetworkNotificationManager::maybeSendConnectionConfiguration const):
(WebKit::NetworkNotificationManager::sendMessage const):
(WebKit::NetworkNotificationManager::sendMessageWithReply const):
(WebKit::NetworkNotificationManager::maybeSendHostAppAuditToken const): Deleted.

  • NetworkProcess/Notifications/NetworkNotificationManager.h:
  • NetworkProcess/cocoa/NetworkSessionCocoa.h:
  • NetworkProcess/cocoa/NetworkSessionCocoa.mm:

(WebKit::NetworkSessionCocoa::NetworkSessionCocoa):

  • Shared/WebPushDaemonConnectionConfiguration.h: Copied from Source/WebKit/Shared/WebPushDaemonConstants.h.

(WebKit::WebPushD::WebPushDaemonConnectionConfiguration::encode const):
(WebKit::WebPushD::WebPushDaemonConnectionConfiguration::decode):

  • Shared/WebPushDaemonConstants.h:

(WebKit::WebPushD::messageTypeSendsReply):

  • UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h:
  • UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm:

(-[_WKWebsiteDataStoreConfiguration webpushdUsesMockBundlesForTesting]):
(-[_WKWebsiteDataStoreConfiguration setWebpushdUsesMockBundlesForTesting:]):

  • UIProcess/WebsiteData/WebsiteDataStore.cpp:

(WebKit::WebsiteDataStore::parameters):

  • UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp:

(WebKit::WebsiteDataStoreConfiguration::copy const):
(WebKit::WebsiteDataStoreConfiguration::webPushDaemonConnectionConfiguration const):

  • UIProcess/WebsiteData/WebsiteDataStoreConfiguration.h:

(WebKit::WebsiteDataStoreConfiguration::webpushdUsesMockBundlesForTesting const):
(WebKit::WebsiteDataStoreConfiguration::setWebpushdUsesMockBundlesForTesting):

  • WebKit.xcodeproj/project.pbxproj:
  • webpushd/AppBundleRequest.mm:

(WebPushD::AppBundleRequest::AppBundleRequest):
(WebPushD::AppBundleRequest::start):

  • webpushd/PushClientConnection.h:

(WebPushD::ClientConnection::hasHostAppAuditToken const):
(WebPushD::ClientConnection::useMockBundlesForTesting const):

  • webpushd/PushClientConnection.mm:

(WebPushD::ClientConnection::updateConnectionConfiguration):
(WebPushD::ClientConnection::setHostAppAuditTokenData):

  • webpushd/WebPushDaemon.h:
  • webpushd/WebPushDaemon.mm:

(WebPushD::Daemon::decodeAndHandleMessage):
(WebPushD::Daemon::getOriginsWithPushAndNotificationPermissions):
(WebPushD::Daemon::setDebugModeIsEnabled):
(WebPushD::Daemon::updateConnectionConfiguration):
(WebPushD::Daemon::setHostAppAuditToken): Deleted.

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm:
File size: 3.3 KB
Line 
1/*
2 * Copyright (C) 2021 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#include "PushClientConnection.h"
29#include "WebPushDaemonConnectionConfiguration.h"
30#include "WebPushDaemonConstants.h"
31#include <wtf/Forward.h>
32#include <wtf/HashMap.h>
33#include <wtf/HashSet.h>
34#include <wtf/OSObjectPtr.h>
35#include <wtf/Span.h>
36#include <wtf/spi/darwin/XPCSPI.h>
37
38
39namespace JSC {
40enum class MessageLevel : uint8_t;
41}
42
43using WebKit::WebPushD::WebPushDaemonConnectionConfiguration;
44
45namespace WebPushD {
46
47using EncodedMessage = Vector<uint8_t>;
48
49class Daemon {
50 friend class WTF::NeverDestroyed<Daemon>;
51public:
52 static Daemon& singleton();
53
54 void connectionEventHandler(xpc_object_t);
55 void connectionAdded(xpc_connection_t);
56 void connectionRemoved(xpc_connection_t);
57
58 // Message handlers
59 void echoTwice(ClientConnection*, const String&, CompletionHandler<void(const String&)>&& replySender);
60 void requestSystemNotificationPermission(ClientConnection*, const String&, CompletionHandler<void(bool)>&& replySender);
61 void getOriginsWithPushAndNotificationPermissions(ClientConnection*, CompletionHandler<void(const Vector<String>&)>&& replySender);
62 void deletePushAndNotificationRegistration(ClientConnection*, const String& originString, CompletionHandler<void(const String&)>&& replySender);
63 void setDebugModeIsEnabled(ClientConnection*, bool);
64 void updateConnectionConfiguration(ClientConnection*, const WebPushDaemonConnectionConfiguration&);
65
66 void broadcastDebugMessage(JSC::MessageLevel, const String&);
67
68private:
69 Daemon() = default;
70
71 CompletionHandler<void(EncodedMessage&&)> createReplySender(WebKit::WebPushD::MessageType, OSObjectPtr<xpc_object_t>&& request);
72 void decodeAndHandleMessage(xpc_connection_t, WebKit::WebPushD::MessageType, Span<const uint8_t> encodedMessage, CompletionHandler<void(EncodedMessage&&)>&&);
73
74 bool canRegisterForNotifications(ClientConnection&);
75
76 ClientConnection* toClientConnection(xpc_connection_t);
77 HashMap<xpc_connection_t, Ref<ClientConnection>> m_connectionMap;
78};
79
80} // namespace WebPushD
Note: See TracBrowser for help on using the repository browser.