|
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 |
|
39 WebURLProtectionSpace::WebURLProtectionSpace(const ProtectionSpace& protectionSpace) |
|
40 : m_refCount(0) |
|
41 , m_protectionSpace(protectionSpace) |
|
42 { |
|
43 gClassCount++; |
|
44 } |
|
45 |
|
46 WebURLProtectionSpace::~WebURLProtectionSpace() |
|
47 { |
|
48 gClassCount--; |
|
49 } |
|
50 |
|
51 WebURLProtectionSpace* WebURLProtectionSpace::createInstance() |
|
52 { |
|
53 WebURLProtectionSpace* instance = new WebURLProtectionSpace(ProtectionSpace()); |
|
54 instance->AddRef(); |
|
55 return instance; |
|
56 } |
|
57 |
|
58 WebURLProtectionSpace* WebURLProtectionSpace::createInstance(const ProtectionSpace& protectionSpace) |
|
59 { |
|
60 WebURLProtectionSpace* instance = new WebURLProtectionSpace(protectionSpace); |
|
61 instance->AddRef(); |
|
62 return instance; |
|
63 } |
|
64 |
|
65 // IUnknown ------------------------------------------------------------------- |
|
66 |
|
67 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::QueryInterface(REFIID riid, void** ppvObject) |
|
68 { |
|
69 *ppvObject = 0; |
|
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); |
|
76 else |
|
77 return E_NOINTERFACE; |
|
78 |
|
79 AddRef(); |
|
80 return S_OK; |
|
81 } |
|
82 |
|
83 ULONG STDMETHODCALLTYPE WebURLProtectionSpace::AddRef(void) |
|
84 { |
|
85 return ++m_refCount; |
|
86 } |
|
87 |
|
88 ULONG STDMETHODCALLTYPE WebURLProtectionSpace::Release(void) |
|
89 { |
|
90 ULONG newRef = --m_refCount; |
|
91 if (!newRef) |
|
92 delete(this); |
|
93 |
|
94 return newRef; |
|
95 } |
|
96 |
|
97 // IWebURLProtectionSpace ------------------------------------------------------------------- |
|
98 |
|
99 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::authenticationMethod( |
|
100 /* [out, retval] */ BSTR* result) |
|
101 { |
|
102 switch (m_protectionSpace.authenticationScheme()) { |
|
103 case ProtectionSpaceAuthenticationSchemeDefault: |
|
104 *result = SysAllocString(WebURLAuthenticationMethodDefault); |
|
105 break; |
|
106 case ProtectionSpaceAuthenticationSchemeHTTPBasic: |
|
107 *result = SysAllocString(WebURLAuthenticationMethodHTTPBasic); |
|
108 break; |
|
109 case ProtectionSpaceAuthenticationSchemeHTTPDigest: |
|
110 *result = SysAllocString(WebURLAuthenticationMethodHTTPDigest); |
|
111 break; |
|
112 case ProtectionSpaceAuthenticationSchemeHTMLForm: |
|
113 *result = SysAllocString(WebURLAuthenticationMethodHTMLForm); |
|
114 break; |
|
115 default: |
|
116 ASSERT_NOT_REACHED(); |
|
117 return E_FAIL; |
|
118 } |
|
119 return S_OK; |
|
120 } |
|
121 |
|
122 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::host( |
|
123 /* [out, retval] */ BSTR* result) |
|
124 { |
|
125 BString str = m_protectionSpace.host(); |
|
126 *result = str.release(); |
|
127 return S_OK; |
|
128 } |
|
129 |
|
130 static ProtectionSpaceAuthenticationScheme coreScheme(BSTR authenticationMethod) |
|
131 { |
|
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; |
|
141 else |
|
142 ASSERT_NOT_REACHED(); |
|
143 return scheme; |
|
144 } |
|
145 |
|
146 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::initWithHost( |
|
147 /* [in] */ BSTR host, |
|
148 /* [in] */ int port, |
|
149 /* [in] */ BSTR protocol, |
|
150 /* [in] */ BSTR realm, |
|
151 /* [in] */ BSTR authenticationMethod) |
|
152 { |
|
153 ProtectionSpaceServerType serverType = ProtectionSpaceServerHTTP; |
|
154 if (BString(protocol) == WebURLProtectionSpaceHTTP) |
|
155 serverType = ProtectionSpaceServerHTTP; |
|
156 else if (BString(protocol) == WebURLProtectionSpaceHTTPS) |
|
157 serverType = ProtectionSpaceServerHTTPS; |
|
158 else if (BString(protocol) == WebURLProtectionSpaceFTP) |
|
159 serverType = ProtectionSpaceServerFTP; |
|
160 else if (BString(protocol) == WebURLProtectionSpaceFTPS) |
|
161 serverType = ProtectionSpaceServerFTPS; |
|
162 else |
|
163 ASSERT_NOT_REACHED(); |
|
164 |
|
165 m_protectionSpace = ProtectionSpace(String(host, SysStringLen(host)), port, serverType, |
|
166 String(realm, SysStringLen(realm)), coreScheme(authenticationMethod)); |
|
167 |
|
168 return S_OK; |
|
169 } |
|
170 |
|
171 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::initWithProxyHost( |
|
172 /* [in] */ BSTR host, |
|
173 /* [in] */ int port, |
|
174 /* [in] */ BSTR proxyType, |
|
175 /* [in] */ BSTR realm, |
|
176 /* [in] */ BSTR authenticationMethod) |
|
177 { |
|
178 ProtectionSpaceServerType serverType = ProtectionSpaceProxyHTTP; |
|
179 if (BString(proxyType) == WebURLProtectionSpaceHTTPProxy) |
|
180 serverType = ProtectionSpaceProxyHTTP; |
|
181 else if (BString(proxyType) == WebURLProtectionSpaceHTTPSProxy) |
|
182 serverType = ProtectionSpaceProxyHTTPS; |
|
183 else if (BString(proxyType) == WebURLProtectionSpaceFTPProxy) |
|
184 serverType = ProtectionSpaceProxyFTP; |
|
185 else if (BString(proxyType) == WebURLProtectionSpaceSOCKSProxy) |
|
186 serverType = ProtectionSpaceProxySOCKS; |
|
187 else |
|
188 ASSERT_NOT_REACHED(); |
|
189 |
|
190 m_protectionSpace = ProtectionSpace(String(host, SysStringLen(host)), port, serverType, |
|
191 String(realm, SysStringLen(realm)), coreScheme(authenticationMethod)); |
|
192 |
|
193 return S_OK; |
|
194 } |
|
195 |
|
196 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::isProxy( |
|
197 /* [out, retval] */ BOOL* result) |
|
198 { |
|
199 *result = m_protectionSpace.isProxy(); |
|
200 return S_OK; |
|
201 } |
|
202 |
|
203 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::port( |
|
204 /* [out, retval] */ int* result) |
|
205 { |
|
206 *result = m_protectionSpace.port(); |
|
207 return S_OK; |
|
208 } |
|
209 |
|
210 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::protocol( |
|
211 /* [out, retval] */ BSTR* result) |
|
212 { |
|
213 switch (m_protectionSpace.serverType()) { |
|
214 case ProtectionSpaceServerHTTP: |
|
215 *result = SysAllocString(WebURLProtectionSpaceHTTP); |
|
216 break; |
|
217 case ProtectionSpaceServerHTTPS: |
|
218 *result = SysAllocString(WebURLProtectionSpaceHTTPS); |
|
219 break; |
|
220 case ProtectionSpaceServerFTP: |
|
221 *result = SysAllocString(WebURLProtectionSpaceFTP); |
|
222 break; |
|
223 case ProtectionSpaceServerFTPS: |
|
224 *result = SysAllocString(WebURLProtectionSpaceFTPS); |
|
225 break; |
|
226 default: |
|
227 ASSERT_NOT_REACHED(); |
|
228 return E_FAIL; |
|
229 } |
|
230 return S_OK; |
|
231 } |
|
232 |
|
233 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::proxyType( |
|
234 /* [out, retval] */ BSTR* result) |
|
235 { |
|
236 switch (m_protectionSpace.serverType()) { |
|
237 case ProtectionSpaceProxyHTTP: |
|
238 *result = SysAllocString(WebURLProtectionSpaceHTTPProxy); |
|
239 break; |
|
240 case ProtectionSpaceProxyHTTPS: |
|
241 *result = SysAllocString(WebURLProtectionSpaceHTTPSProxy); |
|
242 break; |
|
243 case ProtectionSpaceProxyFTP: |
|
244 *result = SysAllocString(WebURLProtectionSpaceFTPProxy); |
|
245 break; |
|
246 case ProtectionSpaceProxySOCKS: |
|
247 *result = SysAllocString(WebURLProtectionSpaceSOCKSProxy); |
|
248 break; |
|
249 default: |
|
250 ASSERT_NOT_REACHED(); |
|
251 return E_FAIL; |
|
252 } |
|
253 return S_OK; |
|
254 } |
|
255 |
|
256 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::realm( |
|
257 /* [out, retval] */ BSTR* result) |
|
258 { |
|
259 BString bstring = m_protectionSpace.realm(); |
|
260 *result = bstring.release(); |
|
261 return S_OK; |
|
262 } |
|
263 |
|
264 HRESULT STDMETHODCALLTYPE WebURLProtectionSpace::receivesCredentialSecurely( |
|
265 /* [out, retval] */ BOOL* result) |
|
266 { |
|
267 *result = m_protectionSpace.receivesCredentialSecurely(); |
|
268 return S_OK; |
|
269 } |
|
270 |
|
271 // WebURLProtectionSpace ------------------------------------------------------------------- |
|
272 const ProtectionSpace& WebURLProtectionSpace::protectionSpace() const |
|
273 { |
|
274 return m_protectionSpace; |
|
275 } |