1/*
2 * Copyright (C) 2012, 2013 Apple Inc. All rights reserved.
3 * Copyright (C) 2017 Igalia S.L.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 * THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include "config.h"
28#include "LegacyCustomProtocolManager.h"
29
30#include "LegacyCustomProtocolManagerMessages.h"
31#include "LegacyCustomProtocolManagerProxyMessages.h"
32#include "NetworkProcess.h"
33#include "NetworkProcessCreationParameters.h"
34#include "WebCoreArgumentCoders.h"
35#include <WebCore/ResourceRequest.h>
36
37namespace WebKit {
38
39static uint64_t generateCustomProtocolID()
40{
41 static uint64_t uniqueCustomProtocolID = 0;
42 return ++uniqueCustomProtocolID;
43}
44
45const char* LegacyCustomProtocolManager::supplementName()
46{
47 return "LegacyCustomProtocolManager";
48}
49
50LegacyCustomProtocolManager::LegacyCustomProtocolManager(NetworkProcess& networkProcess)
51 : m_networkProcess(networkProcess)
52{
53 m_networkProcess.addMessageReceiver(Messages::LegacyCustomProtocolManager::messageReceiverName(), *this);
54}
55
56void LegacyCustomProtocolManager::initialize(const NetworkProcessCreationParameters& parameters)
57{
58 registerProtocolClass();
59
60 for (const auto& scheme : parameters.urlSchemesRegisteredForCustomProtocols)
61 registerScheme(scheme);
62}
63
64uint64_t LegacyCustomProtocolManager::addCustomProtocol(CustomProtocol&& customProtocol)
65{
66 LockHolder locker(m_customProtocolMapMutex);
67 auto customProtocolID = generateCustomProtocolID();
68 m_customProtocolMap.add(customProtocolID, WTFMove(customProtocol));
69 return customProtocolID;
70}
71
72void LegacyCustomProtocolManager::removeCustomProtocol(uint64_t customProtocolID)
73{
74 LockHolder locker(m_customProtocolMapMutex);
75 m_customProtocolMap.remove(customProtocolID);
76}
77
78void LegacyCustomProtocolManager::startLoading(uint64_t customProtocolID, const WebCore::ResourceRequest& request)
79{
80 m_networkProcess.send(Messages::LegacyCustomProtocolManagerProxy::StartLoading(customProtocolID, request));
81}
82
83void LegacyCustomProtocolManager::stopLoading(uint64_t customProtocolID)
84{
85 m_networkProcess.send(Messages::LegacyCustomProtocolManagerProxy::StopLoading(customProtocolID), 0);
86}
87
88} // namespace WebKit
89