blob: 57ca80e173dd9b5325f92f349fa894d1ae642684 [file] [log] [blame]
darin@apple.coma30d12d2008-01-19 05:49:02 +00001/*
bfulgham@apple.comd7fd9fd2015-08-20 00:00:38 +00002 * Copyright (C) 2007, 2015 Apple Inc. All rights reserved.
darin@apple.coma30d12d2008-01-19 05:49:02 +00003 *
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.
mjs@apple.com92047332014-03-15 04:08:27 +000013 * 3. Neither the name of Apple Inc. ("Apple") nor the names of
darin@apple.coma30d12d2008-01-19 05:49:02 +000014 * 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
darin@apple.coma30d12d2008-01-19 05:49:02 +000029#include "WebSecurityOrigin.h"
30#include "WebKitDLL.h"
31
bfulgham@apple.comdf492ef2014-12-19 01:00:23 +000032#include "MarshallingHelpers.h"
darin@apple.coma30d12d2008-01-19 05:49:02 +000033#include <WebCore/BString.h>
darin@apple.com389af862016-11-14 03:22:31 +000034#include <WebCore/DatabaseTracker.h>
commit-queue@webkit.org7f2065c2016-11-15 06:08:12 +000035#include <WebCore/SecurityOriginData.h>
keith_miller@apple.combb2f61c2018-12-01 03:28:36 +000036#include <wtf/URL.h>
darin@apple.coma30d12d2008-01-19 05:49:02 +000037
38using namespace WebCore;
39
40// WebSecurityOrigin ---------------------------------------------------------------
41WebSecurityOrigin* WebSecurityOrigin::createInstance(SecurityOrigin* securityOrigin)
42{
43 WebSecurityOrigin* origin = new WebSecurityOrigin(securityOrigin);
44 origin->AddRef();
45 return origin;
46}
47
48WebSecurityOrigin::WebSecurityOrigin(SecurityOrigin* securityOrigin)
bfulgham@apple.comd7fd9fd2015-08-20 00:00:38 +000049 : m_securityOrigin(securityOrigin)
darin@apple.coma30d12d2008-01-19 05:49:02 +000050{
51 gClassCount++;
bfulgham@apple.com1a016fb2014-09-26 00:39:20 +000052 gClassNameCount().add("WebSecurityOrigin");
darin@apple.coma30d12d2008-01-19 05:49:02 +000053}
54
55WebSecurityOrigin::~WebSecurityOrigin()
56{
57 gClassCount--;
bfulgham@apple.com1a016fb2014-09-26 00:39:20 +000058 gClassNameCount().remove("WebSecurityOrigin");
darin@apple.coma30d12d2008-01-19 05:49:02 +000059}
60
61// IUnknown ------------------------------------------------------------------------
bfulgham@apple.comd7fd9fd2015-08-20 00:00:38 +000062HRESULT WebSecurityOrigin::QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject)
darin@apple.coma30d12d2008-01-19 05:49:02 +000063{
bfulgham@apple.comd7fd9fd2015-08-20 00:00:38 +000064 if (!ppvObject)
65 return E_POINTER;
66 *ppvObject = nullptr;
darin@apple.coma30d12d2008-01-19 05:49:02 +000067 if (IsEqualGUID(riid, IID_IUnknown))
bfulgham@apple.com7ed1ef82015-07-16 01:45:49 +000068 *ppvObject = static_cast<IWebSecurityOrigin2*>(this);
darin@apple.coma30d12d2008-01-19 05:49:02 +000069 else if (IsEqualGUID(riid, IID_IWebSecurityOrigin))
70 *ppvObject = static_cast<IWebSecurityOrigin*>(this);
bfulgham@apple.com7ed1ef82015-07-16 01:45:49 +000071 else if (IsEqualGUID(riid, IID_IWebSecurityOrigin2))
72 *ppvObject = static_cast<IWebSecurityOrigin2*>(this);
darin@apple.coma30d12d2008-01-19 05:49:02 +000073 else if (IsEqualGUID(riid, __uuidof(this)))
74 *ppvObject = this;
75 else
76 return E_NOINTERFACE;
77
78 AddRef();
79 return S_OK;
80}
81
bfulgham@apple.comdf492ef2014-12-19 01:00:23 +000082ULONG WebSecurityOrigin::AddRef()
darin@apple.coma30d12d2008-01-19 05:49:02 +000083{
84 return ++m_refCount;
85}
86
bfulgham@apple.comdf492ef2014-12-19 01:00:23 +000087ULONG WebSecurityOrigin::Release()
darin@apple.coma30d12d2008-01-19 05:49:02 +000088{
89 ULONG newRef = --m_refCount;
90 if (!newRef)
91 delete this;
92
93 return newRef;
94}
95
96// IWebSecurityOrigin --------------------------------------------------------------
97
bfulgham@apple.comd7fd9fd2015-08-20 00:00:38 +000098HRESULT WebSecurityOrigin::protocol(__deref_opt_out BSTR* result)
darin@apple.coma30d12d2008-01-19 05:49:02 +000099{
100 if (!result)
101 return E_POINTER;
102
103 *result = BString(m_securityOrigin->protocol()).release();
104
105 return S_OK;
106}
107
bfulgham@apple.comd7fd9fd2015-08-20 00:00:38 +0000108HRESULT WebSecurityOrigin::host(__deref_opt_out BSTR* result)
darin@apple.coma30d12d2008-01-19 05:49:02 +0000109{
110 if (!result)
111 return E_POINTER;
112
113 *result = BString(m_securityOrigin->host()).release();
114
115 return S_OK;
116}
117
bfulgham@apple.comd7fd9fd2015-08-20 00:00:38 +0000118HRESULT WebSecurityOrigin::port(_Out_ unsigned short* result)
darin@apple.coma30d12d2008-01-19 05:49:02 +0000119{
120 if (!result)
121 return E_POINTER;
122
cdumez@apple.com6eda1ab2018-12-20 20:23:18 +0000123 *result = m_securityOrigin->port().valueOr(0);
darin@apple.coma30d12d2008-01-19 05:49:02 +0000124
125 return S_OK;
126}
127
bfulgham@apple.comd7fd9fd2015-08-20 00:00:38 +0000128HRESULT WebSecurityOrigin::usage(_Out_ unsigned long long* result)
darin@apple.coma30d12d2008-01-19 05:49:02 +0000129{
130 if (!result)
131 return E_POINTER;
132
cdumez@apple.com7e9b8cf2018-03-26 18:03:40 +0000133 *result = DatabaseTracker::singleton().usage(m_securityOrigin->data());
darin@apple.coma30d12d2008-01-19 05:49:02 +0000134
135 return S_OK;
136}
137
bfulgham@apple.comd7fd9fd2015-08-20 00:00:38 +0000138HRESULT WebSecurityOrigin::quota(_Out_ unsigned long long* result)
darin@apple.coma30d12d2008-01-19 05:49:02 +0000139{
140 if (!result)
141 return E_POINTER;
142
cdumez@apple.com7e9b8cf2018-03-26 18:03:40 +0000143 *result = DatabaseTracker::singleton().quota(m_securityOrigin->data());
darin@apple.coma30d12d2008-01-19 05:49:02 +0000144 return S_OK;
145}
146
bfulgham@apple.comd7fd9fd2015-08-20 00:00:38 +0000147HRESULT WebSecurityOrigin::setQuota(unsigned long long quota)
darin@apple.coma30d12d2008-01-19 05:49:02 +0000148{
cdumez@apple.com7e9b8cf2018-03-26 18:03:40 +0000149 DatabaseTracker::singleton().setQuota(m_securityOrigin->data(), quota);
darin@apple.coma30d12d2008-01-19 05:49:02 +0000150
151 return S_OK;
152}
bfulgham@apple.comdf492ef2014-12-19 01:00:23 +0000153
bfulgham@apple.com7ed1ef82015-07-16 01:45:49 +0000154// IWebSecurityOrigin2 --------------------------------------------------------------
155
bfulgham@apple.comd7fd9fd2015-08-20 00:00:38 +0000156HRESULT WebSecurityOrigin::initWithURL(_In_ BSTR urlBstr)
bfulgham@apple.comdf492ef2014-12-19 01:00:23 +0000157{
158 m_securityOrigin = WebCore::SecurityOrigin::create(MarshallingHelpers::BSTRToKURL(urlBstr));
159
160 return S_OK;
161}