|
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 "HTTPHeaderPropertyBag.h" |
|
28 |
|
29 #include "HTTPHeaderMap.h" |
|
30 |
|
31 #include <WebCore/BString.h> |
|
32 |
|
33 // HTTPHeaderPropertyBag ----------------------------------------------- |
|
34 |
|
35 HTTPHeaderPropertyBag::HTTPHeaderPropertyBag(WebURLResponse* response) |
|
36 : m_refCount(1) |
|
37 , m_response(response) |
|
38 { |
|
39 } |
|
40 |
|
41 HTTPHeaderPropertyBag* HTTPHeaderPropertyBag::createInstance(WebURLResponse* response) |
|
42 { |
|
43 return new HTTPHeaderPropertyBag(response); |
|
44 } |
|
45 |
|
46 // IUnknown ------------------------------------------------------------------- |
|
47 |
|
48 HRESULT STDMETHODCALLTYPE HTTPHeaderPropertyBag::QueryInterface(REFIID riid, void** ppvObject) |
|
49 { |
|
50 *ppvObject = 0; |
|
51 if (IsEqualGUID(riid, IID_IUnknown)) |
|
52 *ppvObject = static_cast<IPropertyBag*>(this); |
|
53 else if (IsEqualGUID(riid, IID_IPropertyBag)) |
|
54 *ppvObject = static_cast<IPropertyBag*>(this); |
|
55 else if (IsEqualGUID(riid, __uuidof(HTTPHeaderPropertyBag))) |
|
56 *ppvObject = this; |
|
57 else |
|
58 return E_NOINTERFACE; |
|
59 |
|
60 AddRef(); |
|
61 return S_OK; |
|
62 } |
|
63 |
|
64 ULONG STDMETHODCALLTYPE HTTPHeaderPropertyBag::AddRef(void) |
|
65 { |
|
66 return ++m_refCount; |
|
67 } |
|
68 |
|
69 ULONG STDMETHODCALLTYPE HTTPHeaderPropertyBag::Release(void) |
|
70 { |
|
71 ULONG newRef = --m_refCount; |
|
72 if (!newRef) |
|
73 delete this; |
|
74 |
|
75 return newRef; |
|
76 } |
|
77 |
|
78 static inline WebCore::String ConvertFromLPCOLESTRToString(LPCOLESTR pszPropName) |
|
79 { |
|
80 return WebCore::String(pszPropName); |
|
81 } |
|
82 |
|
83 static bool ConvertFromStringToVariant(VARIANT* pVar, const WebCore::String& stringVal) |
|
84 { |
|
85 if (!pVar) |
|
86 return false; |
|
87 |
|
88 if (V_VT(pVar) == VT_BSTR) { |
|
89 V_BSTR(pVar) = WebCore::BString(stringVal); |
|
90 return true; |
|
91 } |
|
92 |
|
93 return false; |
|
94 } |
|
95 |
|
96 // IPropertyBag ------------------------------------------------------------ |
|
97 |
|
98 HRESULT STDMETHODCALLTYPE HTTPHeaderPropertyBag::Read(LPCOLESTR pszPropName, VARIANT* pVar, IErrorLog* /*pErrorLog*/) |
|
99 { |
|
100 if (!pszPropName) |
|
101 return E_POINTER; |
|
102 |
|
103 if (!m_response) |
|
104 return E_FAIL; |
|
105 |
|
106 const WebCore::HTTPHeaderMap& headerMap = m_response->resourceResponse().httpHeaderFields(); |
|
107 WebCore::String key = ConvertFromLPCOLESTRToString(pszPropName); |
|
108 WebCore::String value = headerMap.get(key); |
|
109 |
|
110 if (!ConvertFromStringToVariant(pVar, value)) |
|
111 return E_INVALIDARG; |
|
112 |
|
113 return S_OK; |
|
114 } |
|
115 |
|
116 HRESULT STDMETHODCALLTYPE HTTPHeaderPropertyBag::Write(LPCOLESTR /*pszPropName*/, VARIANT* /*pVar*/) |
|
117 { |
|
118 // We cannot add to the Resource Response's header hash map |
|
119 return E_FAIL; |
|
120 } |