[EFL][CustomProtocol] Do not add duplicated custom scheme
[WebKit-https.git] / Source / WebKit2 / UIProcess / Network / CustomProtocols / soup / WebSoupCustomProtocolRequestManager.cpp
1 /*
2  * Copyright (C) 2013 Igalia S.L.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #include "config.h"
21 #include "WebSoupCustomProtocolRequestManager.h"
22
23 #include "APIData.h"
24 #include "CustomProtocolManagerMessages.h"
25 #include "WebProcessPool.h"
26 #include <WebCore/ResourceError.h>
27 #include <WebCore/ResourceRequest.h>
28 #include <WebCore/ResourceResponse.h>
29
30 #if PLATFORM(GTK)
31 #include <WebCore/ErrorsGtk.h>
32 #elif PLATFORM(EFL)
33 #include <WebCore/ErrorsEfl.h>
34 #endif
35
36 namespace WebKit {
37
38 const char* WebSoupCustomProtocolRequestManager::supplementName()
39 {
40     return "WebSoupCustomProtocolRequestManager";
41 }
42
43 Ref<WebSoupCustomProtocolRequestManager> WebSoupCustomProtocolRequestManager::create(WebProcessPool* processPool)
44 {
45     return adoptRef(*new WebSoupCustomProtocolRequestManager(processPool));
46 }
47
48 WebSoupCustomProtocolRequestManager::WebSoupCustomProtocolRequestManager(WebProcessPool* processPool)
49     : WebContextSupplement(processPool)
50 {
51 }
52
53 WebSoupCustomProtocolRequestManager::~WebSoupCustomProtocolRequestManager()
54 {
55 }
56
57 void WebSoupCustomProtocolRequestManager::initializeClient(const WKSoupCustomProtocolRequestManagerClientBase* client)
58 {
59     m_client.initialize(client);
60 }
61
62 // WebContextSupplement
63 void WebSoupCustomProtocolRequestManager::processPoolDestroyed()
64 {
65 }
66
67 void WebSoupCustomProtocolRequestManager::processDidClose(WebProcessProxy*)
68 {
69 }
70
71 void WebSoupCustomProtocolRequestManager::refWebContextSupplement()
72 {
73     API::Object::ref();
74 }
75
76 void WebSoupCustomProtocolRequestManager::derefWebContextSupplement()
77 {
78     API::Object::deref();
79 }
80
81 void WebSoupCustomProtocolRequestManager::registerSchemeForCustomProtocol(const String& scheme)
82 {
83     ASSERT(!scheme.isNull());
84     if (m_registeredSchemes.contains(scheme))
85         return;
86
87     if (!processPool())
88         return;
89
90     processPool()->registerSchemeForCustomProtocol(scheme);
91
92     m_registeredSchemes.append(scheme);
93 }
94
95 void WebSoupCustomProtocolRequestManager::unregisterSchemeForCustomProtocol(const String& scheme)
96 {
97     if (!processPool())
98         return;
99
100     processPool()->unregisterSchemeForCustomProtocol(scheme);
101
102     bool removed = m_registeredSchemes.removeFirst(scheme);
103     ASSERT_UNUSED(removed, removed);
104 }
105
106 void WebSoupCustomProtocolRequestManager::startLoading(uint64_t customProtocolID, const WebCore::ResourceRequest& request)
107 {
108     if (!m_client.startLoading(this, customProtocolID, request))
109         didFailWithError(customProtocolID, WebCore::cannotShowURLError(request));
110 }
111
112 void WebSoupCustomProtocolRequestManager::stopLoading(uint64_t customProtocolID)
113 {
114     m_client.stopLoading(this, customProtocolID);
115 }
116
117 void WebSoupCustomProtocolRequestManager::didReceiveResponse(uint64_t customProtocolID, const WebCore::ResourceResponse& response)
118 {
119     if (!processPool())
120         return;
121
122     processPool()->networkingProcessConnection()->send(Messages::CustomProtocolManager::DidReceiveResponse(customProtocolID, response, 0), 0);
123 }
124
125 void WebSoupCustomProtocolRequestManager::didLoadData(uint64_t customProtocolID, const API::Data* data)
126 {
127     if (!processPool())
128         return;
129
130     processPool()->networkingProcessConnection()->send(Messages::CustomProtocolManager::DidLoadData(customProtocolID, data->dataReference()), 0);
131 }
132
133 void WebSoupCustomProtocolRequestManager::didFailWithError(uint64_t customProtocolID, const WebCore::ResourceError& error)
134 {
135     if (!processPool())
136         return;
137
138     processPool()->networkingProcessConnection()->send(Messages::CustomProtocolManager::DidFailWithError(customProtocolID, error), 0);
139 }
140
141 void WebSoupCustomProtocolRequestManager::didFinishLoading(uint64_t customProtocolID)
142 {
143     if (!processPool())
144         return;
145
146     processPool()->networkingProcessConnection()->send(Messages::CustomProtocolManager::DidFinishLoading(customProtocolID), 0);
147 }
148
149 } // namespace WebKit