• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 Apple Inc.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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.
24  */
25 
26 #include "config.h"
27 #include "WebKit.h"
28 #include "WebKitDLL.h"
29 #include "WebURLProtectionSpace.h"
30 
31 #pragma warning(push, 0)
32 #include <WebCore/BString.h>
33 #pragma warning(pop)
34 
35 using namespace WebCore;
36 
37 // WebURLProtectionSpace ----------------------------------------------------------------
38 
WebURLProtectionSpace(const ProtectionSpace & protectionSpace)39 WebURLProtectionSpace::WebURLProtectionSpace(const ProtectionSpace& protectionSpace)
40     : m_refCount(0)
41     , m_protectionSpace(protectionSpace)
42 {
43     gClassCount++;
44     gClassNameCount.add("WebURLProtectionSpace");
45 }
46 
~WebURLProtectionSpace()47 WebURLProtectionSpace::~WebURLProtectionSpace()
48 {
49     gClassCount--;
50     gClassNameCount.remove("WebURLProtectionSpace");
51 }
52 
createInstance()53 WebURLProtectionSpace* WebURLProtectionSpace::createInstance()
54 {
55     WebURLProtectionSpace* instance = new WebURLProtectionSpace(ProtectionSpace());
56     instance->AddRef();
57     return instance;
58 }
59 
createInstance(const ProtectionSpace & protectionSpace)60 WebURLProtectionSpace* WebURLProtectionSpace::createInstance(const ProtectionSpace& protectionSpace)
61 {
62     WebURLProtectionSpace* instance = new WebURLProtectionSpace(protectionSpace);
63     instance->AddRef();
64     return instance;
65 }
66 
67 // IUnknown -------------------------------------------------------------------
68 
QueryInterface(REFIID riid,void ** ppvObject)69 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::QueryInterface(REFIID riid, void** ppvObject)
70 {
71     *ppvObject = 0;
72     if (IsEqualGUID(riid, IID_IUnknown))
73         *ppvObject = static_cast<IUnknown*>(this);
74     else if (IsEqualGUID(riid, CLSID_WebURLProtectionSpace))
75         *ppvObject = static_cast<WebURLProtectionSpace*>(this);
76     else if (IsEqualGUID(riid, IID_IWebURLProtectionSpace))
77         *ppvObject = static_cast<IWebURLProtectionSpace*>(this);
78     else
79         return E_NOINTERFACE;
80 
81     AddRef();
82     return S_OK;
83 }
84 
AddRef(void)85 ULONG STDMETHODCALLTYPE WebURLProtectionSpace::AddRef(void)
86 {
87     return ++m_refCount;
88 }
89 
Release(void)90 ULONG STDMETHODCALLTYPE WebURLProtectionSpace::Release(void)
91 {
92     ULONG newRef = --m_refCount;
93     if (!newRef)
94         delete(this);
95 
96     return newRef;
97 }
98 
99 // IWebURLProtectionSpace -------------------------------------------------------------------
100 
authenticationMethod(BSTR * result)101 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::authenticationMethod(
102     /* [out, retval] */ BSTR* result)
103 {
104     switch (m_protectionSpace.authenticationScheme()) {
105     case ProtectionSpaceAuthenticationSchemeDefault:
106         *result = SysAllocString(WebURLAuthenticationMethodDefault);
107         break;
108     case ProtectionSpaceAuthenticationSchemeHTTPBasic:
109         *result = SysAllocString(WebURLAuthenticationMethodHTTPBasic);
110         break;
111     case ProtectionSpaceAuthenticationSchemeHTTPDigest:
112         *result = SysAllocString(WebURLAuthenticationMethodHTTPDigest);
113         break;
114     case ProtectionSpaceAuthenticationSchemeHTMLForm:
115         *result = SysAllocString(WebURLAuthenticationMethodHTMLForm);
116         break;
117     default:
118         ASSERT_NOT_REACHED();
119         return E_FAIL;
120     }
121     return S_OK;
122 }
123 
host(BSTR * result)124 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::host(
125     /* [out, retval] */ BSTR* result)
126 {
127     BString str = m_protectionSpace.host();
128     *result = str.release();
129     return S_OK;
130 }
131 
coreScheme(BSTR authenticationMethod)132 static ProtectionSpaceAuthenticationScheme coreScheme(BSTR authenticationMethod)
133 {
134     ProtectionSpaceAuthenticationScheme scheme = ProtectionSpaceAuthenticationSchemeDefault;
135     if (BString(authenticationMethod) == BString(WebURLAuthenticationMethodDefault))
136         scheme = ProtectionSpaceAuthenticationSchemeDefault;
137     else if (BString(authenticationMethod) == BString(WebURLAuthenticationMethodHTTPBasic))
138         scheme = ProtectionSpaceAuthenticationSchemeHTTPBasic;
139     else if (BString(authenticationMethod) == BString(WebURLAuthenticationMethodHTTPDigest))
140         scheme = ProtectionSpaceAuthenticationSchemeHTTPDigest;
141     else if (BString(authenticationMethod) == BString(WebURLAuthenticationMethodHTMLForm))
142         scheme = ProtectionSpaceAuthenticationSchemeHTMLForm;
143     else
144         ASSERT_NOT_REACHED();
145     return scheme;
146 }
147 
initWithHost(BSTR host,int port,BSTR protocol,BSTR realm,BSTR authenticationMethod)148 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::initWithHost(
149     /* [in] */ BSTR host,
150     /* [in] */ int port,
151     /* [in] */ BSTR protocol,
152     /* [in] */ BSTR realm,
153     /* [in] */ BSTR authenticationMethod)
154 {
155     static BString& webURLProtectionSpaceHTTPBString = *new BString(WebURLProtectionSpaceHTTP);
156     static BString& webURLProtectionSpaceHTTPSBString = *new BString(WebURLProtectionSpaceHTTPS);
157     static BString& webURLProtectionSpaceFTPBString = *new BString(WebURLProtectionSpaceFTP);
158     static BString& webURLProtectionSpaceFTPSBString = *new BString(WebURLProtectionSpaceFTPS);
159 
160     ProtectionSpaceServerType serverType = ProtectionSpaceServerHTTP;
161     if (BString(protocol) == webURLProtectionSpaceHTTPBString)
162         serverType = ProtectionSpaceServerHTTP;
163     else if (BString(protocol) == webURLProtectionSpaceHTTPSBString)
164         serverType = ProtectionSpaceServerHTTPS;
165     else if (BString(protocol) == webURLProtectionSpaceFTPBString)
166         serverType = ProtectionSpaceServerFTP;
167     else if (BString(protocol) == webURLProtectionSpaceFTPSBString)
168         serverType = ProtectionSpaceServerFTPS;
169     else
170         ASSERT_NOT_REACHED();
171 
172     m_protectionSpace = ProtectionSpace(String(host, SysStringLen(host)), port, serverType,
173         String(realm, SysStringLen(realm)), coreScheme(authenticationMethod));
174 
175     return S_OK;
176 }
177 
initWithProxyHost(BSTR host,int port,BSTR proxyType,BSTR realm,BSTR authenticationMethod)178 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::initWithProxyHost(
179     /* [in] */ BSTR host,
180     /* [in] */ int port,
181     /* [in] */ BSTR proxyType,
182     /* [in] */ BSTR realm,
183     /* [in] */ BSTR authenticationMethod)
184 {
185     static BString& webURLProtectionSpaceHTTPProxyBString = *new BString(WebURLProtectionSpaceHTTPProxy);
186     static BString& webURLProtectionSpaceHTTPSProxyBString = *new BString(WebURLProtectionSpaceHTTPSProxy);
187     static BString& webURLProtectionSpaceFTPProxyBString = *new BString(WebURLProtectionSpaceFTPProxy);
188     static BString& webURLProtectionSpaceSOCKSProxyBString = *new BString(WebURLProtectionSpaceSOCKSProxy);
189 
190     ProtectionSpaceServerType serverType = ProtectionSpaceProxyHTTP;
191     if (BString(proxyType) == webURLProtectionSpaceHTTPProxyBString)
192         serverType = ProtectionSpaceProxyHTTP;
193     else if (BString(proxyType) == webURLProtectionSpaceHTTPSProxyBString)
194         serverType = ProtectionSpaceProxyHTTPS;
195     else if (BString(proxyType) == webURLProtectionSpaceFTPProxyBString)
196         serverType = ProtectionSpaceProxyFTP;
197     else if (BString(proxyType) == webURLProtectionSpaceSOCKSProxyBString)
198         serverType = ProtectionSpaceProxySOCKS;
199     else
200         ASSERT_NOT_REACHED();
201 
202     m_protectionSpace = ProtectionSpace(String(host, SysStringLen(host)), port, serverType,
203         String(realm, SysStringLen(realm)), coreScheme(authenticationMethod));
204 
205     return S_OK;
206 }
207 
isProxy(BOOL * result)208 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::isProxy(
209     /* [out, retval] */ BOOL* result)
210 {
211     *result = m_protectionSpace.isProxy();
212     return S_OK;
213 }
214 
port(int * result)215 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::port(
216     /* [out, retval] */ int* result)
217 {
218     *result = m_protectionSpace.port();
219     return S_OK;
220 }
221 
protocol(BSTR * result)222 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::protocol(
223     /* [out, retval] */ BSTR* result)
224 {
225     switch (m_protectionSpace.serverType()) {
226     case ProtectionSpaceServerHTTP:
227         *result = SysAllocString(WebURLProtectionSpaceHTTP);
228         break;
229     case ProtectionSpaceServerHTTPS:
230         *result = SysAllocString(WebURLProtectionSpaceHTTPS);
231         break;
232     case ProtectionSpaceServerFTP:
233         *result = SysAllocString(WebURLProtectionSpaceFTP);
234         break;
235     case ProtectionSpaceServerFTPS:
236         *result = SysAllocString(WebURLProtectionSpaceFTPS);
237         break;
238     default:
239         ASSERT_NOT_REACHED();
240         return E_FAIL;
241     }
242     return S_OK;
243 }
244 
proxyType(BSTR * result)245 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::proxyType(
246     /* [out, retval] */ BSTR* result)
247 {
248     switch (m_protectionSpace.serverType()) {
249     case ProtectionSpaceProxyHTTP:
250         *result = SysAllocString(WebURLProtectionSpaceHTTPProxy);
251         break;
252     case ProtectionSpaceProxyHTTPS:
253         *result = SysAllocString(WebURLProtectionSpaceHTTPSProxy);
254         break;
255     case ProtectionSpaceProxyFTP:
256         *result = SysAllocString(WebURLProtectionSpaceFTPProxy);
257         break;
258     case ProtectionSpaceProxySOCKS:
259         *result = SysAllocString(WebURLProtectionSpaceSOCKSProxy);
260         break;
261     default:
262         ASSERT_NOT_REACHED();
263         return E_FAIL;
264     }
265     return S_OK;
266 }
267 
realm(BSTR * result)268 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::realm(
269     /* [out, retval] */ BSTR* result)
270 {
271     BString bstring = m_protectionSpace.realm();
272     *result = bstring.release();
273     return S_OK;
274 }
275 
receivesCredentialSecurely(BOOL * result)276 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::receivesCredentialSecurely(
277     /* [out, retval] */ BOOL* result)
278 {
279     *result = m_protectionSpace.receivesCredentialSecurely();
280     return S_OK;
281 }
282 
283 // WebURLProtectionSpace -------------------------------------------------------------------
protectionSpace() const284 const ProtectionSpace& WebURLProtectionSpace::protectionSpace() const
285 {
286     return m_protectionSpace;
287 }
288