WebError.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 "WebError.h"
  28. #include "WebKit.h"
  29. #include <WebCore/BString.h>
  30. #if USE(CFNETWORK)
  31. #include <WebKitSystemInterface/WebKitSystemInterface.h>
  32. #endif
  33. using namespace WebCore;
  34. // WebError ---------------------------------------------------------------------
  35. WebError::WebError(const ResourceError& error, IPropertyBag* userInfo)
  36. : m_refCount(0)
  37. , m_error(error)
  38. , m_userInfo(userInfo)
  39. {
  40. gClassCount++;
  41. gClassNameCount.add("WebError");
  42. }
  43. WebError::~WebError()
  44. {
  45. gClassCount--;
  46. gClassNameCount.remove("WebError");
  47. }
  48. WebError* WebError::createInstance(const ResourceError& error, IPropertyBag* userInfo)
  49. {
  50. WebError* instance = new WebError(error, userInfo);
  51. instance->AddRef();
  52. return instance;
  53. }
  54. WebError* WebError::createInstance()
  55. {
  56. return createInstance(ResourceError());
  57. }
  58. // IUnknown -------------------------------------------------------------------
  59. HRESULT STDMETHODCALLTYPE WebError::QueryInterface(REFIID riid, void** ppvObject)
  60. {
  61. *ppvObject = 0;
  62. if (IsEqualGUID(riid, IID_IUnknown))
  63. *ppvObject = static_cast<IWebError*>(this);
  64. else if (IsEqualGUID(riid, CLSID_WebError))
  65. *ppvObject = static_cast<WebError*>(this);
  66. else if (IsEqualGUID(riid, IID_IWebError))
  67. *ppvObject = static_cast<IWebError*>(this);
  68. else if (IsEqualGUID(riid, IID_IWebErrorPrivate))
  69. *ppvObject = static_cast<IWebErrorPrivate*>(this);
  70. else
  71. return E_NOINTERFACE;
  72. AddRef();
  73. return S_OK;
  74. }
  75. ULONG STDMETHODCALLTYPE WebError::AddRef(void)
  76. {
  77. return ++m_refCount;
  78. }
  79. ULONG STDMETHODCALLTYPE WebError::Release(void)
  80. {
  81. ULONG newRef = --m_refCount;
  82. if (!newRef)
  83. delete(this);
  84. return newRef;
  85. }
  86. // IWebError ------------------------------------------------------------------
  87. HRESULT STDMETHODCALLTYPE WebError::init(
  88. /* [in] */ BSTR domain,
  89. /* [in] */ int code,
  90. /* [in] */ BSTR url)
  91. {
  92. m_error = ResourceError(String(domain, SysStringLen(domain)), code, String(url, SysStringLen(url)), String());
  93. return S_OK;
  94. }
  95. HRESULT STDMETHODCALLTYPE WebError::code(
  96. /* [retval][out] */ int* result)
  97. {
  98. *result = m_error.errorCode();
  99. return S_OK;
  100. }
  101. HRESULT STDMETHODCALLTYPE WebError::domain(
  102. /* [retval][out] */ BSTR* result)
  103. {
  104. if (!result)
  105. return E_POINTER;
  106. *result = BString(m_error.domain()).release();
  107. return S_OK;
  108. }
  109. HRESULT STDMETHODCALLTYPE WebError::localizedDescription(
  110. /* [retval][out] */ BSTR* result)
  111. {
  112. if (!result)
  113. return E_POINTER;
  114. *result = BString(m_error.localizedDescription()).release();
  115. #if USE(CFNETWORK)
  116. if (!*result) {
  117. if (int code = m_error.errorCode())
  118. *result = BString(wkCFNetworkErrorGetLocalizedDescription(code)).release();
  119. }
  120. #endif
  121. return S_OK;
  122. }
  123. HRESULT STDMETHODCALLTYPE WebError::localizedFailureReason(
  124. /* [retval][out] */ BSTR* /*result*/)
  125. {
  126. ASSERT_NOT_REACHED();
  127. return E_NOTIMPL;
  128. }
  129. HRESULT STDMETHODCALLTYPE WebError::localizedRecoveryOptions(
  130. /* [retval][out] */ IEnumVARIANT** /*result*/)
  131. {
  132. ASSERT_NOT_REACHED();
  133. return E_NOTIMPL;
  134. }
  135. HRESULT STDMETHODCALLTYPE WebError::localizedRecoverySuggestion(
  136. /* [retval][out] */ BSTR* /*result*/)
  137. {
  138. ASSERT_NOT_REACHED();
  139. return E_NOTIMPL;
  140. }
  141. HRESULT STDMETHODCALLTYPE WebError::recoverAttempter(
  142. /* [retval][out] */ IUnknown** /*result*/)
  143. {
  144. ASSERT_NOT_REACHED();
  145. return E_NOTIMPL;
  146. }
  147. HRESULT STDMETHODCALLTYPE WebError::userInfo(
  148. /* [retval][out] */ IPropertyBag** result)
  149. {
  150. if (!result)
  151. return E_POINTER;
  152. *result = 0;
  153. if (!m_userInfo)
  154. return E_FAIL;
  155. return m_userInfo.copyRefTo(result);
  156. }
  157. HRESULT STDMETHODCALLTYPE WebError::failingURL(
  158. /* [retval][out] */ BSTR* result)
  159. {
  160. if (!result)
  161. return E_POINTER;
  162. *result = BString(m_error.failingURL()).release();
  163. return S_OK;
  164. }
  165. HRESULT STDMETHODCALLTYPE WebError::isPolicyChangeError(
  166. /* [retval][out] */ BOOL *result)
  167. {
  168. if (!result)
  169. return E_POINTER;
  170. *result = m_error.domain() == String(WebKitErrorDomain)
  171. && m_error.errorCode() == WebKitErrorFrameLoadInterruptedByPolicyChange;
  172. return S_OK;
  173. }
  174. HRESULT STDMETHODCALLTYPE WebError::sslPeerCertificate(
  175. /* [retval][out] */ OLE_HANDLE* result)
  176. {
  177. if (!result)
  178. return E_POINTER;
  179. *result = 0;
  180. #if USE(CFNETWORK)
  181. if (!m_cfErrorUserInfoDict) {
  182. // copy userinfo from CFErrorRef
  183. CFErrorRef cfError = m_error;
  184. m_cfErrorUserInfoDict = adoptCF(CFErrorCopyUserInfo(cfError));
  185. }
  186. if (!m_cfErrorUserInfoDict)
  187. return E_FAIL;
  188. void* data = wkGetSSLPeerCertificateDataBytePtr(m_cfErrorUserInfoDict.get());
  189. if (!data)
  190. return E_FAIL;
  191. *result = (OLE_HANDLE)(ULONG64)data;
  192. #endif
  193. return *result ? S_OK : E_FAIL;
  194. }
  195. const ResourceError& WebError::resourceError() const
  196. {
  197. return m_error;
  198. }