2 * Copyright (C) 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "WebKitDLL.h"
29 #include "WebURLProtectionSpace.h"
31 #include <WebCore/BString.h>
33 using namespace WebCore;
35 // WebURLProtectionSpace ----------------------------------------------------------------
37 WebURLProtectionSpace::WebURLProtectionSpace(const ProtectionSpace& protectionSpace)
39 , m_protectionSpace(protectionSpace)
42 gClassNameCount.add("WebURLProtectionSpace");
45 WebURLProtectionSpace::~WebURLProtectionSpace()
48 gClassNameCount.remove("WebURLProtectionSpace");
51 WebURLProtectionSpace* WebURLProtectionSpace::createInstance()
53 WebURLProtectionSpace* instance = new WebURLProtectionSpace(ProtectionSpace());
58 WebURLProtectionSpace* WebURLProtectionSpace::createInstance(const ProtectionSpace& protectionSpace)
60 WebURLProtectionSpace* instance = new WebURLProtectionSpace(protectionSpace);
65 // IUnknown -------------------------------------------------------------------
67 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::QueryInterface(REFIID riid, void** ppvObject)
70 if (IsEqualGUID(riid, IID_IUnknown))
71 *ppvObject = static_cast<IUnknown*>(this);
72 else if (IsEqualGUID(riid, CLSID_WebURLProtectionSpace))
73 *ppvObject = static_cast<WebURLProtectionSpace*>(this);
74 else if (IsEqualGUID(riid, IID_IWebURLProtectionSpace))
75 *ppvObject = static_cast<IWebURLProtectionSpace*>(this);
83 ULONG STDMETHODCALLTYPE WebURLProtectionSpace::AddRef(void)
88 ULONG STDMETHODCALLTYPE WebURLProtectionSpace::Release(void)
90 ULONG newRef = --m_refCount;
97 // IWebURLProtectionSpace -------------------------------------------------------------------
99 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::authenticationMethod(
100 /* [out, retval] */ BSTR* result)
102 switch (m_protectionSpace.authenticationScheme()) {
103 case ProtectionSpaceAuthenticationSchemeDefault:
104 *result = SysAllocString(WebURLAuthenticationMethodDefault);
106 case ProtectionSpaceAuthenticationSchemeHTTPBasic:
107 *result = SysAllocString(WebURLAuthenticationMethodHTTPBasic);
109 case ProtectionSpaceAuthenticationSchemeHTTPDigest:
110 *result = SysAllocString(WebURLAuthenticationMethodHTTPDigest);
112 case ProtectionSpaceAuthenticationSchemeHTMLForm:
113 *result = SysAllocString(WebURLAuthenticationMethodHTMLForm);
116 ASSERT_NOT_REACHED();
122 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::host(
123 /* [out, retval] */ BSTR* result)
125 BString str = m_protectionSpace.host();
126 *result = str.release();
130 static ProtectionSpaceAuthenticationScheme coreScheme(BSTR authenticationMethod)
132 ProtectionSpaceAuthenticationScheme scheme = ProtectionSpaceAuthenticationSchemeDefault;
133 if (BString(authenticationMethod) == BString(WebURLAuthenticationMethodDefault))
134 scheme = ProtectionSpaceAuthenticationSchemeDefault;
135 else if (BString(authenticationMethod) == BString(WebURLAuthenticationMethodHTTPBasic))
136 scheme = ProtectionSpaceAuthenticationSchemeHTTPBasic;
137 else if (BString(authenticationMethod) == BString(WebURLAuthenticationMethodHTTPDigest))
138 scheme = ProtectionSpaceAuthenticationSchemeHTTPDigest;
139 else if (BString(authenticationMethod) == BString(WebURLAuthenticationMethodHTMLForm))
140 scheme = ProtectionSpaceAuthenticationSchemeHTMLForm;
142 ASSERT_NOT_REACHED();
146 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::initWithHost(
147 /* [in] */ BSTR host,
149 /* [in] */ BSTR protocol,
150 /* [in] */ BSTR realm,
151 /* [in] */ BSTR authenticationMethod)
153 static BString& webURLProtectionSpaceHTTPBString = *new BString(WebURLProtectionSpaceHTTP);
154 static BString& webURLProtectionSpaceHTTPSBString = *new BString(WebURLProtectionSpaceHTTPS);
155 static BString& webURLProtectionSpaceFTPBString = *new BString(WebURLProtectionSpaceFTP);
156 static BString& webURLProtectionSpaceFTPSBString = *new BString(WebURLProtectionSpaceFTPS);
158 ProtectionSpaceServerType serverType = ProtectionSpaceServerHTTP;
159 if (BString(protocol) == webURLProtectionSpaceHTTPBString)
160 serverType = ProtectionSpaceServerHTTP;
161 else if (BString(protocol) == webURLProtectionSpaceHTTPSBString)
162 serverType = ProtectionSpaceServerHTTPS;
163 else if (BString(protocol) == webURLProtectionSpaceFTPBString)
164 serverType = ProtectionSpaceServerFTP;
165 else if (BString(protocol) == webURLProtectionSpaceFTPSBString)
166 serverType = ProtectionSpaceServerFTPS;
168 m_protectionSpace = ProtectionSpace(String(host, SysStringLen(host)), port, serverType,
169 String(realm, SysStringLen(realm)), coreScheme(authenticationMethod));
174 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::initWithProxyHost(
175 /* [in] */ BSTR host,
177 /* [in] */ BSTR proxyType,
178 /* [in] */ BSTR realm,
179 /* [in] */ BSTR authenticationMethod)
181 static BString& webURLProtectionSpaceHTTPProxyBString = *new BString(WebURLProtectionSpaceHTTPProxy);
182 static BString& webURLProtectionSpaceHTTPSProxyBString = *new BString(WebURLProtectionSpaceHTTPSProxy);
183 static BString& webURLProtectionSpaceFTPProxyBString = *new BString(WebURLProtectionSpaceFTPProxy);
184 static BString& webURLProtectionSpaceSOCKSProxyBString = *new BString(WebURLProtectionSpaceSOCKSProxy);
186 ProtectionSpaceServerType serverType = ProtectionSpaceProxyHTTP;
187 if (BString(proxyType) == webURLProtectionSpaceHTTPProxyBString)
188 serverType = ProtectionSpaceProxyHTTP;
189 else if (BString(proxyType) == webURLProtectionSpaceHTTPSProxyBString)
190 serverType = ProtectionSpaceProxyHTTPS;
191 else if (BString(proxyType) == webURLProtectionSpaceFTPProxyBString)
192 serverType = ProtectionSpaceProxyFTP;
193 else if (BString(proxyType) == webURLProtectionSpaceSOCKSProxyBString)
194 serverType = ProtectionSpaceProxySOCKS;
196 ASSERT_NOT_REACHED();
198 m_protectionSpace = ProtectionSpace(String(host, SysStringLen(host)), port, serverType,
199 String(realm, SysStringLen(realm)), coreScheme(authenticationMethod));
204 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::isProxy(
205 /* [out, retval] */ BOOL* result)
207 *result = m_protectionSpace.isProxy();
211 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::port(
212 /* [out, retval] */ int* result)
214 *result = m_protectionSpace.port();
218 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::protocol(
219 /* [out, retval] */ BSTR* result)
221 switch (m_protectionSpace.serverType()) {
222 case ProtectionSpaceServerHTTP:
223 *result = SysAllocString(WebURLProtectionSpaceHTTP);
225 case ProtectionSpaceServerHTTPS:
226 *result = SysAllocString(WebURLProtectionSpaceHTTPS);
228 case ProtectionSpaceServerFTP:
229 *result = SysAllocString(WebURLProtectionSpaceFTP);
231 case ProtectionSpaceServerFTPS:
232 *result = SysAllocString(WebURLProtectionSpaceFTPS);
235 ASSERT_NOT_REACHED();
241 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::proxyType(
242 /* [out, retval] */ BSTR* result)
244 switch (m_protectionSpace.serverType()) {
245 case ProtectionSpaceProxyHTTP:
246 *result = SysAllocString(WebURLProtectionSpaceHTTPProxy);
248 case ProtectionSpaceProxyHTTPS:
249 *result = SysAllocString(WebURLProtectionSpaceHTTPSProxy);
251 case ProtectionSpaceProxyFTP:
252 *result = SysAllocString(WebURLProtectionSpaceFTPProxy);
254 case ProtectionSpaceProxySOCKS:
255 *result = SysAllocString(WebURLProtectionSpaceSOCKSProxy);
258 ASSERT_NOT_REACHED();
264 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::realm(
265 /* [out, retval] */ BSTR* result)
267 BString bstring = m_protectionSpace.realm();
268 *result = bstring.release();
272 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::receivesCredentialSecurely(
273 /* [out, retval] */ BOOL* result)
275 *result = m_protectionSpace.receivesCredentialSecurely();
279 // WebURLProtectionSpace -------------------------------------------------------------------
280 const ProtectionSpace& WebURLProtectionSpace::protectionSpace() const
282 return m_protectionSpace;