File: RiceBackendProxy.cpp

package info (click to toggle)
webkit2gtk 2.51.90-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 484,192 kB
  • sloc: cpp: 3,930,945; javascript: 197,713; ansic: 167,619; python: 53,160; asm: 21,857; ruby: 18,114; perl: 17,149; xml: 4,631; sh: 2,462; yacc: 2,394; java: 2,032; lex: 1,358; pascal: 372; makefile: 215
file content (118 lines) | stat: -rw-r--r-- 4,412 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 *  Copyright (C) 2025 Igalia S.L. All rights reserved.
 *  Copyright (C) 2025 Metrological Group B.V.
 *
 *  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 "RiceBackendProxy.h"

#if USE(LIBRICE)

#include "NetworkConnectionToWebProcessMessages.h"
#include "NetworkProcessConnection.h"
#include "RiceBackendMessages.h"

#include <WebCore/ExceptionOr.h>
#include <WebCore/RiceUtilities.h>

namespace WebKit {
using namespace WebCore;

RefPtr<RiceBackendProxy> RiceBackendProxy::create(WebPageProxyIdentifier webPageProxyID, WebCore::RiceBackendClient& client)
{
    Ref connection = WebProcess::singleton().ensureNetworkProcessConnection().connection();
    auto sendResult = connection->sendSync(Messages::NetworkConnectionToWebProcess::InitializeRiceBackend(webPageProxyID), 0);
    if (!sendResult.succeeded())
        return nullptr;

    auto [identifier] = sendResult.takeReply();
    if (!identifier)
        return nullptr;

    return adoptRef(*new RiceBackendProxy(WTF::move(connection), webPageProxyID, *identifier, client));
}

RiceBackendProxy::RiceBackendProxy(Ref<IPC::Connection>&& connection, WebPageProxyIdentifier webPageProxyID, RiceBackendIdentifier identifier, WebCore::RiceBackendClient& client)
    : RiceBackend()
    , m_connection(WTF::move(connection))
    , m_webPageProxyID(webPageProxyID)
    , m_client(&client)
    , m_identifier(identifier)
{
    ASSERT(RunLoop::isMain());
    WebProcess::singleton().addRiceBackend(m_identifier, *this);
}

RiceBackendProxy::~RiceBackendProxy()
{
    WebProcess::singleton().removeRiceBackend(m_identifier);
    m_connection->send(Messages::NetworkConnectionToWebProcess::DestroyRiceBackend(m_identifier), 0);
}

IPC::Connection* RiceBackendProxy::messageSenderConnection() const
{
    return m_connection.ptr();
}

uint64_t RiceBackendProxy::messageSenderDestinationID() const
{
    return m_identifier.toUInt64();
}

void RiceBackendProxy::resolveAddress(const String& address, RiceBackend::ResolveAddressCallback&& callback)
{
    m_connection->sendWithAsyncReply(Messages::RiceBackend::ResolveAddress { address }, [callback = WTF::move(callback)](auto&& valueOrException) mutable {
        if (!valueOrException.has_value()) {
            callback(valueOrException.error().toException());
            return;
        }
        callback(WTF::move(*valueOrException));
    }, messageSenderDestinationID());
}

HashMap<WebCore::RiceBackend::Socket, String> RiceBackendProxy::gatherSocketAddresses(WebCore::ScriptExecutionContextIdentifier identifier, unsigned streamId)
{
    HashMap<WebCore::RiceBackend::Socket, String> addresses;
    callOnMainRunLoopAndWait([&] {
        auto sendResult = m_connection->sendSync(Messages::RiceBackend::GatherSocketAddresses { identifier, streamId }, messageSenderDestinationID(), 3_s);
        if (!sendResult.succeeded())
            return;

        auto [reply] = sendResult.takeReply();
        addresses = reply;
    });
    return addresses;
}

void RiceBackendProxy::notifyIncomingData(unsigned streamId, RTCIceProtocol protocol, String&& from, String&& to, WebCore::SharedMemory::Handle&& data)
{
    m_client->notifyIncomingData(streamId, protocol, WTF::move(from), WTF::move(to), WTF::move(data));
}

void RiceBackendProxy::send(unsigned streamId, RTCIceProtocol protocol, String&& from, String&& to, WebCore::SharedMemory::Handle&& data)
{
    MessageSender::send(Messages::RiceBackend::SendData { streamId, protocol, WTF::move(from), WTF::move(to), WTF::move(data) });
}

void RiceBackendProxy::finalizeStream(unsigned streamId)
{
    MessageSender::send(Messages::RiceBackend::FinalizeStream { streamId });
}

} // namespace WebKit

#endif // USE(LIBRICE)