darin@apple.com | a30d12d | 2008-01-19 05:49:02 +0000 | [diff] [blame] | 1 | /* |
bfulgham@apple.com | d7fd9fd | 2015-08-20 00:00:38 +0000 | [diff] [blame] | 2 | * Copyright (C) 2007, 2015 Apple Inc. All rights reserved. |
darin@apple.com | a30d12d | 2008-01-19 05:49:02 +0000 | [diff] [blame] | 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. |
mjs@apple.com | 9204733 | 2014-03-15 04:08:27 +0000 | [diff] [blame] | 13 | * 3. Neither the name of Apple Inc. ("Apple") nor the names of |
darin@apple.com | a30d12d | 2008-01-19 05:49:02 +0000 | [diff] [blame] | 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 | |
darin@apple.com | a30d12d | 2008-01-19 05:49:02 +0000 | [diff] [blame] | 29 | #include "WebSecurityOrigin.h" |
| 30 | #include "WebKitDLL.h" |
| 31 | |
bfulgham@apple.com | df492ef | 2014-12-19 01:00:23 +0000 | [diff] [blame] | 32 | #include "MarshallingHelpers.h" |
darin@apple.com | a30d12d | 2008-01-19 05:49:02 +0000 | [diff] [blame] | 33 | #include <WebCore/BString.h> |
darin@apple.com | 389af86 | 2016-11-14 03:22:31 +0000 | [diff] [blame] | 34 | #include <WebCore/DatabaseTracker.h> |
commit-queue@webkit.org | 7f2065c | 2016-11-15 06:08:12 +0000 | [diff] [blame] | 35 | #include <WebCore/SecurityOriginData.h> |
keith_miller@apple.com | bb2f61c | 2018-12-01 03:28:36 +0000 | [diff] [blame] | 36 | #include <wtf/URL.h> |
darin@apple.com | a30d12d | 2008-01-19 05:49:02 +0000 | [diff] [blame] | 37 | |
| 38 | using namespace WebCore; |
| 39 | |
| 40 | // WebSecurityOrigin --------------------------------------------------------------- |
| 41 | WebSecurityOrigin* WebSecurityOrigin::createInstance(SecurityOrigin* securityOrigin) |
| 42 | { |
| 43 | WebSecurityOrigin* origin = new WebSecurityOrigin(securityOrigin); |
| 44 | origin->AddRef(); |
| 45 | return origin; |
| 46 | } |
| 47 | |
| 48 | WebSecurityOrigin::WebSecurityOrigin(SecurityOrigin* securityOrigin) |
bfulgham@apple.com | d7fd9fd | 2015-08-20 00:00:38 +0000 | [diff] [blame] | 49 | : m_securityOrigin(securityOrigin) |
darin@apple.com | a30d12d | 2008-01-19 05:49:02 +0000 | [diff] [blame] | 50 | { |
| 51 | gClassCount++; |
bfulgham@apple.com | 1a016fb | 2014-09-26 00:39:20 +0000 | [diff] [blame] | 52 | gClassNameCount().add("WebSecurityOrigin"); |
darin@apple.com | a30d12d | 2008-01-19 05:49:02 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | WebSecurityOrigin::~WebSecurityOrigin() |
| 56 | { |
| 57 | gClassCount--; |
bfulgham@apple.com | 1a016fb | 2014-09-26 00:39:20 +0000 | [diff] [blame] | 58 | gClassNameCount().remove("WebSecurityOrigin"); |
darin@apple.com | a30d12d | 2008-01-19 05:49:02 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | // IUnknown ------------------------------------------------------------------------ |
bfulgham@apple.com | d7fd9fd | 2015-08-20 00:00:38 +0000 | [diff] [blame] | 62 | HRESULT WebSecurityOrigin::QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject) |
darin@apple.com | a30d12d | 2008-01-19 05:49:02 +0000 | [diff] [blame] | 63 | { |
bfulgham@apple.com | d7fd9fd | 2015-08-20 00:00:38 +0000 | [diff] [blame] | 64 | if (!ppvObject) |
| 65 | return E_POINTER; |
| 66 | *ppvObject = nullptr; |
darin@apple.com | a30d12d | 2008-01-19 05:49:02 +0000 | [diff] [blame] | 67 | if (IsEqualGUID(riid, IID_IUnknown)) |
bfulgham@apple.com | 7ed1ef8 | 2015-07-16 01:45:49 +0000 | [diff] [blame] | 68 | *ppvObject = static_cast<IWebSecurityOrigin2*>(this); |
darin@apple.com | a30d12d | 2008-01-19 05:49:02 +0000 | [diff] [blame] | 69 | else if (IsEqualGUID(riid, IID_IWebSecurityOrigin)) |
| 70 | *ppvObject = static_cast<IWebSecurityOrigin*>(this); |
bfulgham@apple.com | 7ed1ef8 | 2015-07-16 01:45:49 +0000 | [diff] [blame] | 71 | else if (IsEqualGUID(riid, IID_IWebSecurityOrigin2)) |
| 72 | *ppvObject = static_cast<IWebSecurityOrigin2*>(this); |
darin@apple.com | a30d12d | 2008-01-19 05:49:02 +0000 | [diff] [blame] | 73 | 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.com | df492ef | 2014-12-19 01:00:23 +0000 | [diff] [blame] | 82 | ULONG WebSecurityOrigin::AddRef() |
darin@apple.com | a30d12d | 2008-01-19 05:49:02 +0000 | [diff] [blame] | 83 | { |
| 84 | return ++m_refCount; |
| 85 | } |
| 86 | |
bfulgham@apple.com | df492ef | 2014-12-19 01:00:23 +0000 | [diff] [blame] | 87 | ULONG WebSecurityOrigin::Release() |
darin@apple.com | a30d12d | 2008-01-19 05:49:02 +0000 | [diff] [blame] | 88 | { |
| 89 | ULONG newRef = --m_refCount; |
| 90 | if (!newRef) |
| 91 | delete this; |
| 92 | |
| 93 | return newRef; |
| 94 | } |
| 95 | |
| 96 | // IWebSecurityOrigin -------------------------------------------------------------- |
| 97 | |
bfulgham@apple.com | d7fd9fd | 2015-08-20 00:00:38 +0000 | [diff] [blame] | 98 | HRESULT WebSecurityOrigin::protocol(__deref_opt_out BSTR* result) |
darin@apple.com | a30d12d | 2008-01-19 05:49:02 +0000 | [diff] [blame] | 99 | { |
| 100 | if (!result) |
| 101 | return E_POINTER; |
| 102 | |
| 103 | *result = BString(m_securityOrigin->protocol()).release(); |
| 104 | |
| 105 | return S_OK; |
| 106 | } |
| 107 | |
bfulgham@apple.com | d7fd9fd | 2015-08-20 00:00:38 +0000 | [diff] [blame] | 108 | HRESULT WebSecurityOrigin::host(__deref_opt_out BSTR* result) |
darin@apple.com | a30d12d | 2008-01-19 05:49:02 +0000 | [diff] [blame] | 109 | { |
| 110 | if (!result) |
| 111 | return E_POINTER; |
| 112 | |
| 113 | *result = BString(m_securityOrigin->host()).release(); |
| 114 | |
| 115 | return S_OK; |
| 116 | } |
| 117 | |
bfulgham@apple.com | d7fd9fd | 2015-08-20 00:00:38 +0000 | [diff] [blame] | 118 | HRESULT WebSecurityOrigin::port(_Out_ unsigned short* result) |
darin@apple.com | a30d12d | 2008-01-19 05:49:02 +0000 | [diff] [blame] | 119 | { |
| 120 | if (!result) |
| 121 | return E_POINTER; |
| 122 | |
cdumez@apple.com | 6eda1ab | 2018-12-20 20:23:18 +0000 | [diff] [blame^] | 123 | *result = m_securityOrigin->port().valueOr(0); |
darin@apple.com | a30d12d | 2008-01-19 05:49:02 +0000 | [diff] [blame] | 124 | |
| 125 | return S_OK; |
| 126 | } |
| 127 | |
bfulgham@apple.com | d7fd9fd | 2015-08-20 00:00:38 +0000 | [diff] [blame] | 128 | HRESULT WebSecurityOrigin::usage(_Out_ unsigned long long* result) |
darin@apple.com | a30d12d | 2008-01-19 05:49:02 +0000 | [diff] [blame] | 129 | { |
| 130 | if (!result) |
| 131 | return E_POINTER; |
| 132 | |
cdumez@apple.com | 7e9b8cf | 2018-03-26 18:03:40 +0000 | [diff] [blame] | 133 | *result = DatabaseTracker::singleton().usage(m_securityOrigin->data()); |
darin@apple.com | a30d12d | 2008-01-19 05:49:02 +0000 | [diff] [blame] | 134 | |
| 135 | return S_OK; |
| 136 | } |
| 137 | |
bfulgham@apple.com | d7fd9fd | 2015-08-20 00:00:38 +0000 | [diff] [blame] | 138 | HRESULT WebSecurityOrigin::quota(_Out_ unsigned long long* result) |
darin@apple.com | a30d12d | 2008-01-19 05:49:02 +0000 | [diff] [blame] | 139 | { |
| 140 | if (!result) |
| 141 | return E_POINTER; |
| 142 | |
cdumez@apple.com | 7e9b8cf | 2018-03-26 18:03:40 +0000 | [diff] [blame] | 143 | *result = DatabaseTracker::singleton().quota(m_securityOrigin->data()); |
darin@apple.com | a30d12d | 2008-01-19 05:49:02 +0000 | [diff] [blame] | 144 | return S_OK; |
| 145 | } |
| 146 | |
bfulgham@apple.com | d7fd9fd | 2015-08-20 00:00:38 +0000 | [diff] [blame] | 147 | HRESULT WebSecurityOrigin::setQuota(unsigned long long quota) |
darin@apple.com | a30d12d | 2008-01-19 05:49:02 +0000 | [diff] [blame] | 148 | { |
cdumez@apple.com | 7e9b8cf | 2018-03-26 18:03:40 +0000 | [diff] [blame] | 149 | DatabaseTracker::singleton().setQuota(m_securityOrigin->data(), quota); |
darin@apple.com | a30d12d | 2008-01-19 05:49:02 +0000 | [diff] [blame] | 150 | |
| 151 | return S_OK; |
| 152 | } |
bfulgham@apple.com | df492ef | 2014-12-19 01:00:23 +0000 | [diff] [blame] | 153 | |
bfulgham@apple.com | 7ed1ef8 | 2015-07-16 01:45:49 +0000 | [diff] [blame] | 154 | // IWebSecurityOrigin2 -------------------------------------------------------------- |
| 155 | |
bfulgham@apple.com | d7fd9fd | 2015-08-20 00:00:38 +0000 | [diff] [blame] | 156 | HRESULT WebSecurityOrigin::initWithURL(_In_ BSTR urlBstr) |
bfulgham@apple.com | df492ef | 2014-12-19 01:00:23 +0000 | [diff] [blame] | 157 | { |
| 158 | m_securityOrigin = WebCore::SecurityOrigin::create(MarshallingHelpers::BSTRToKURL(urlBstr)); |
| 159 | |
| 160 | return S_OK; |
| 161 | } |