WebURLCredential.cpp 5.2 KB

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