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 "WebKitDLL.h"
28 #include "WebURLCredential.h"
29
30 #include "WebKit.h"
31 #pragma warning(push, 0)
32 #include <WebCore/BString.h>
33 #pragma warning(pop)
34
35 using namespace WebCore;
36
37 // WebURLCredential ----------------------------------------------------------------
38
WebURLCredential(const Credential & credential)39 WebURLCredential::WebURLCredential(const Credential& credential)
40 : m_refCount(0)
41 , m_credential(credential)
42 {
43 gClassCount++;
44 gClassNameCount.add("WebURLCredential");
45 }
46
~WebURLCredential()47 WebURLCredential::~WebURLCredential()
48 {
49 gClassCount--;
50 gClassNameCount.remove("WebURLCredential");
51 }
52
createInstance()53 WebURLCredential* WebURLCredential::createInstance()
54 {
55 WebURLCredential* instance = new WebURLCredential(Credential());
56 instance->AddRef();
57 return instance;
58 }
59
createInstance(const Credential & credential)60 WebURLCredential* WebURLCredential::createInstance(const Credential& credential)
61 {
62 WebURLCredential* instance = new WebURLCredential(credential);
63 instance->AddRef();
64 return instance;
65 }
66
67 // IUnknown -------------------------------------------------------------------
68
QueryInterface(REFIID riid,void ** ppvObject)69 HRESULT STDMETHODCALLTYPE WebURLCredential::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, __uuidof(WebURLCredential)))
75 *ppvObject = static_cast<WebURLCredential*>(this);
76 else if (IsEqualGUID(riid, IID_IWebURLCredential))
77 *ppvObject = static_cast<IWebURLCredential*>(this);
78 else
79 return E_NOINTERFACE;
80
81 AddRef();
82 return S_OK;
83 }
84
AddRef(void)85 ULONG STDMETHODCALLTYPE WebURLCredential::AddRef(void)
86 {
87 return ++m_refCount;
88 }
89
Release(void)90 ULONG STDMETHODCALLTYPE WebURLCredential::Release(void)
91 {
92 ULONG newRef = --m_refCount;
93 if (!newRef)
94 delete(this);
95
96 return newRef;
97 }
98
99 // IWebURLCredential -------------------------------------------------------------------
hasPassword(BOOL * result)100 HRESULT STDMETHODCALLTYPE WebURLCredential::hasPassword(
101 /* [out, retval] */ BOOL* result)
102 {
103 *result = m_credential.hasPassword();
104 return S_OK;
105 }
106
initWithUser(BSTR user,BSTR password,WebURLCredentialPersistence persistence)107 HRESULT STDMETHODCALLTYPE WebURLCredential::initWithUser(
108 /* [in] */ BSTR user,
109 /* [in] */ BSTR password,
110 /* [in] */ WebURLCredentialPersistence persistence)
111 {
112 CredentialPersistence corePersistence = CredentialPersistenceNone;
113 switch (persistence) {
114 case WebURLCredentialPersistenceNone:
115 break;
116 case WebURLCredentialPersistenceForSession:
117 corePersistence = CredentialPersistenceForSession;
118 break;
119 case WebURLCredentialPersistencePermanent:
120 corePersistence = CredentialPersistencePermanent;
121 break;
122 default:
123 ASSERT_NOT_REACHED();
124 return E_FAIL;
125 }
126
127 m_credential = Credential(String(user, SysStringLen(user)), String(password, SysStringLen(password)), corePersistence);
128 return S_OK;
129 }
130
password(BSTR * password)131 HRESULT STDMETHODCALLTYPE WebURLCredential::password(
132 /* [out, retval] */ BSTR* password)
133 {
134 BString str = m_credential.password();
135 *password = str.release();
136 return S_OK;
137 }
138
persistence(WebURLCredentialPersistence * result)139 HRESULT STDMETHODCALLTYPE WebURLCredential::persistence(
140 /* [out, retval] */ WebURLCredentialPersistence* result)
141 {
142 switch (m_credential.persistence()) {
143 case CredentialPersistenceNone:
144 *result = WebURLCredentialPersistenceNone;
145 break;
146 case CredentialPersistenceForSession:
147 *result = WebURLCredentialPersistenceForSession;
148 break;
149 case CredentialPersistencePermanent:
150 *result = WebURLCredentialPersistencePermanent;
151 break;
152 default:
153 ASSERT_NOT_REACHED();
154 return E_FAIL;
155 }
156 return S_OK;
157 }
158
user(BSTR * result)159 HRESULT STDMETHODCALLTYPE WebURLCredential::user(
160 /* [out, retval] */ BSTR* result)
161 {
162 BString str = m_credential.user();
163 *result = str.release();
164 return S_OK;
165 }
166
credential() const167 const WebCore::Credential& WebURLCredential::credential() const
168 {
169 return m_credential;
170 }
171
172