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 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include "config.h"
30 #include "WebSecurityOrigin.h"
31 #include "WebKitDLL.h"
32
33 #include <WebCore/BString.h>
34 #include <WebCore/DatabaseTracker.h>
35
36 #if !ENABLE(DATABASE)
37 #include <wtf/UnusedParam.h>
38 #endif
39
40 using namespace WebCore;
41
42 // WebSecurityOrigin ---------------------------------------------------------------
createInstance(SecurityOrigin * securityOrigin)43 WebSecurityOrigin* WebSecurityOrigin::createInstance(SecurityOrigin* securityOrigin)
44 {
45 WebSecurityOrigin* origin = new WebSecurityOrigin(securityOrigin);
46 origin->AddRef();
47 return origin;
48 }
49
WebSecurityOrigin(SecurityOrigin * securityOrigin)50 WebSecurityOrigin::WebSecurityOrigin(SecurityOrigin* securityOrigin)
51 : m_refCount(0)
52 , m_securityOrigin(securityOrigin)
53 {
54 gClassCount++;
55 gClassNameCount.add("WebSecurityOrigin");
56 }
57
~WebSecurityOrigin()58 WebSecurityOrigin::~WebSecurityOrigin()
59 {
60 gClassCount--;
61 gClassNameCount.remove("WebSecurityOrigin");
62 }
63
64 // IUnknown ------------------------------------------------------------------------
QueryInterface(REFIID riid,void ** ppvObject)65 HRESULT STDMETHODCALLTYPE WebSecurityOrigin::QueryInterface(REFIID riid, void** ppvObject)
66 {
67 *ppvObject = 0;
68 if (IsEqualGUID(riid, IID_IUnknown))
69 *ppvObject = static_cast<IWebSecurityOrigin*>(this);
70 else if (IsEqualGUID(riid, IID_IWebSecurityOrigin))
71 *ppvObject = static_cast<IWebSecurityOrigin*>(this);
72 else if (IsEqualGUID(riid, __uuidof(this)))
73 *ppvObject = this;
74 else
75 return E_NOINTERFACE;
76
77 AddRef();
78 return S_OK;
79 }
80
AddRef()81 ULONG STDMETHODCALLTYPE WebSecurityOrigin::AddRef()
82 {
83 return ++m_refCount;
84 }
85
Release()86 ULONG STDMETHODCALLTYPE WebSecurityOrigin::Release()
87 {
88 ULONG newRef = --m_refCount;
89 if (!newRef)
90 delete this;
91
92 return newRef;
93 }
94
95 // IWebSecurityOrigin --------------------------------------------------------------
96
protocol(BSTR * result)97 HRESULT STDMETHODCALLTYPE WebSecurityOrigin::protocol(
98 /* [retval][out] */ BSTR* result)
99 {
100 if (!result)
101 return E_POINTER;
102
103 *result = BString(m_securityOrigin->protocol()).release();
104
105 return S_OK;
106 }
107
host(BSTR * result)108 HRESULT STDMETHODCALLTYPE WebSecurityOrigin::host(
109 /* [retval][out] */ BSTR* result)
110 {
111 if (!result)
112 return E_POINTER;
113
114 *result = BString(m_securityOrigin->host()).release();
115
116 return S_OK;
117 }
118
port(unsigned short * result)119 HRESULT STDMETHODCALLTYPE WebSecurityOrigin::port(
120 /* [retval][out] */ unsigned short* result)
121 {
122 if (!result)
123 return E_POINTER;
124
125 *result = m_securityOrigin->port();
126
127 return S_OK;
128 }
129
usage(unsigned long long * result)130 HRESULT STDMETHODCALLTYPE WebSecurityOrigin::usage(
131 /* [retval][out] */ unsigned long long* result)
132 {
133 #if ENABLE(DATABASE)
134 if (!result)
135 return E_POINTER;
136
137 *result = DatabaseTracker::tracker().usageForOrigin(m_securityOrigin.get());
138
139 return S_OK;
140 #else
141 UNUSED_PARAM(result);
142 return E_NOTIMPL;
143 #endif
144 }
145
quota(unsigned long long * result)146 HRESULT STDMETHODCALLTYPE WebSecurityOrigin::quota(
147 /* [retval][out] */ unsigned long long* result)
148 {
149 #if ENABLE(DATABASE)
150 if (!result)
151 return E_POINTER;
152
153 *result = DatabaseTracker::tracker().quotaForOrigin(m_securityOrigin.get());
154 return S_OK;
155 #else
156 UNUSED_PARAM(result);
157 return E_NOTIMPL;
158 #endif
159 }
160
setQuota(unsigned long long quota)161 HRESULT STDMETHODCALLTYPE WebSecurityOrigin::setQuota(
162 /* [in] */ unsigned long long quota)
163 {
164 #if ENABLE(DATABASE)
165 DatabaseTracker::tracker().setQuota(m_securityOrigin.get(), quota);
166
167 return S_OK;
168 #else
169 UNUSED_PARAM(quota);
170 return E_NOTIMPL;
171 #endif
172 }
173