[EFL] Enable custom URI schemes with CustomProtocols
[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 #if ENABLE(CUSTOM_PROTOCOLS)
24
25 #include "APIData.h"
26 #include "CustomProtocolManagerMessages.h"
27 #include "WebContext.h"
28 #include <WebCore/ResourceError.h>
29 #include <WebCore/ResourceRequest.h>
30 #include <WebCore/ResourceResponse.h>
31
32 #if PLATFORM(GTK)
33 #include <WebCore/ErrorsGtk.h>
34 #elif PLATFORM(EFL)
35 #include <WebCore/ErrorsEfl.h>
36 #endif
37
38 namespace WebKit {
39
40 const char* WebSoupCustomProtocolRequestManager::supplementName()
41 {
42     return "WebSoupCustomProtocolRequestManager";
43 }
44
45 PassRefPtr<WebSoupCustomProtocolRequestManager> WebSoupCustomProtocolRequestManager::create(WebContext* context)
46 {
47     return adoptRef(new WebSoupCustomProtocolRequestManager(context));
48 }
49
50 WebSoupCustomProtocolRequestManager::WebSoupCustomProtocolRequestManager(WebContext* context)
51     : WebContextSupplement(context)
52 {
53 }
54
55 WebSoupCustomProtocolRequestManager::~WebSoupCustomProtocolRequestManager()
56 {
57 }
58
59 void WebSoupCustomProtocolRequestManager::initializeClient(const WKSoupCustomProtocolRequestManagerClientBase* client)
60 {
61     m_client.initialize(client);
62 }
63
64 // WebContextSupplement
65 void WebSoupCustomProtocolRequestManager::contextDestroyed()
66 {
67 }
68
69 void WebSoupCustomProtocolRequestManager::processDidClose(WebProcessProxy*)
70 {
71 }
72
73 void WebSoupCustomProtocolRequestManager::refWebContextSupplement()
74 {
75     API::Object::ref();
76 }
77
78 void WebSoupCustomProtocolRequestManager::derefWebContextSupplement()
79 {
80     API::Object::deref();
81 }
82
83 void WebSoupCustomProtocolRequestManager::registerSchemeForCustomProtocol(const String& scheme)
84 {
85     if (!context())
86         return;
87
88     context()->registerSchemeForCustomProtocol(scheme);
89
90     ASSERT(!m_registeredSchemes.contains(scheme));
91     m_registeredSchemes.append(scheme);
92 }
93
94 void WebSoupCustomProtocolRequestManager::unregisterSchemeForCustomProtocol(const String& scheme)
95 {
96     if (!context())
97         return;
98
99     context()->unregisterSchemeForCustomProtocol(scheme);
100
101     ASSERT(m_registeredSchemes.contains(scheme));
102     m_registeredSchemes.remove(m_registeredSchemes.find(scheme));
103 }
104
105 void WebSoupCustomProtocolRequestManager::startLoading(uint64_t customProtocolID, const WebCore::ResourceRequest& request)
106 {
107     if (!m_client.startLoading(this, customProtocolID, request))
108         didFailWithError(customProtocolID, WebCore::cannotShowURLError(request));
109 }
110
111 void WebSoupCustomProtocolRequestManager::stopLoading(uint64_t customProtocolID)
112 {
113     m_client.stopLoading(this, customProtocolID);
114 }
115
116 void WebSoupCustomProtocolRequestManager::didReceiveResponse(uint64_t customProtocolID, const WebCore::ResourceResponse& response)
117 {
118     if (!context())
119         return;
120
121     context()->networkingProcessConnection()->send(Messages::CustomProtocolManager::DidReceiveResponse(customProtocolID, response, 0), 0);
122 }
123
124 void WebSoupCustomProtocolRequestManager::didLoadData(uint64_t customProtocolID, const API::Data* data)
125 {
126     if (!context())
127         return;
128
129     context()->networkingProcessConnection()->send(Messages::CustomProtocolManager::DidLoadData(customProtocolID, data->dataReference()), 0);
130 }
131
132 void WebSoupCustomProtocolRequestManager::didFailWithError(uint64_t customProtocolID, const WebCore::ResourceError& error)
133 {
134     if (!context())
135         return;
136
137     context()->networkingProcessConnection()->send(Messages::CustomProtocolManager::DidFailWithError(customProtocolID, error), 0);
138 }
139
140 void WebSoupCustomProtocolRequestManager::didFinishLoading(uint64_t customProtocolID)
141 {
142     if (!context())
143         return;
144
145     context()->networkingProcessConnection()->send(Messages::CustomProtocolManager::DidFinishLoading(customProtocolID), 0);
146 }
147
148 } // namespace WebKit
149
150 #endif // ENABLE(CUSTOM_PROTOCOLS)