1 /* 2 * Copyright (C) 2010 Google 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 are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #include "config.h" 32 #include "public/web/WebSecurityOrigin.h" 33 34 #include "platform/weborigin/DatabaseIdentifier.h" 35 #include "platform/weborigin/KURL.h" 36 #include "platform/weborigin/SecurityOrigin.h" 37 #include "public/platform/WebString.h" 38 #include "public/platform/WebURL.h" 39 #include "wtf/PassRefPtr.h" 40 41 namespace blink { 42 43 class WebSecurityOriginPrivate : public SecurityOrigin { 44 }; 45 46 WebSecurityOrigin WebSecurityOrigin::createFromDatabaseIdentifier(const WebString& databaseIdentifier) 47 { 48 return WebSecurityOrigin(createSecurityOriginFromDatabaseIdentifier(databaseIdentifier)); 49 } 50 51 WebSecurityOrigin WebSecurityOrigin::createFromString(const WebString& origin) 52 { 53 return WebSecurityOrigin(SecurityOrigin::createFromString(origin)); 54 } 55 56 WebSecurityOrigin WebSecurityOrigin::create(const WebURL& url) 57 { 58 return WebSecurityOrigin(SecurityOrigin::create(url)); 59 } 60 61 void WebSecurityOrigin::reset() 62 { 63 assign(0); 64 } 65 66 void WebSecurityOrigin::assign(const WebSecurityOrigin& other) 67 { 68 WebSecurityOriginPrivate* p = const_cast<WebSecurityOriginPrivate*>(other.m_private); 69 if (p) 70 p->ref(); 71 assign(p); 72 } 73 74 WebString WebSecurityOrigin::protocol() const 75 { 76 ASSERT(m_private); 77 return m_private->protocol(); 78 } 79 80 WebString WebSecurityOrigin::host() const 81 { 82 ASSERT(m_private); 83 return m_private->host(); 84 } 85 86 unsigned short WebSecurityOrigin::port() const 87 { 88 ASSERT(m_private); 89 return m_private->port(); 90 } 91 92 bool WebSecurityOrigin::isUnique() const 93 { 94 ASSERT(m_private); 95 return m_private->isUnique(); 96 } 97 98 bool WebSecurityOrigin::canAccess(const WebSecurityOrigin& other) const 99 { 100 ASSERT(m_private); 101 ASSERT(other.m_private); 102 return m_private->canAccess(other.m_private); 103 } 104 105 bool WebSecurityOrigin::canRequest(const WebURL& url) const 106 { 107 ASSERT(m_private); 108 return m_private->canRequest(url); 109 } 110 111 bool WebSecurityOrigin::canAccessFeatureRequiringSecureOrigin(WebString& errorMessage) const 112 { 113 ASSERT(m_private); 114 WTF::String message(errorMessage); 115 bool result = m_private->canAccessFeatureRequiringSecureOrigin(message); 116 errorMessage = message; 117 return result; 118 } 119 120 WebString WebSecurityOrigin::toString() const 121 { 122 ASSERT(m_private); 123 return m_private->toString(); 124 } 125 126 WebString WebSecurityOrigin::databaseIdentifier() const 127 { 128 ASSERT(m_private); 129 return createDatabaseIdentifierFromSecurityOrigin(m_private); 130 } 131 132 bool WebSecurityOrigin::canAccessPasswordManager() const 133 { 134 ASSERT(m_private); 135 return m_private->canAccessPasswordManager(); 136 } 137 138 WebSecurityOrigin::WebSecurityOrigin(const WTF::PassRefPtr<SecurityOrigin>& origin) 139 : m_private(static_cast<WebSecurityOriginPrivate*>(origin.leakRef())) 140 { 141 } 142 143 WebSecurityOrigin& WebSecurityOrigin::operator=(const WTF::PassRefPtr<SecurityOrigin>& origin) 144 { 145 assign(static_cast<WebSecurityOriginPrivate*>(origin.leakRef())); 146 return *this; 147 } 148 149 WebSecurityOrigin::operator WTF::PassRefPtr<SecurityOrigin>() const 150 { 151 return PassRefPtr<SecurityOrigin>(const_cast<WebSecurityOriginPrivate*>(m_private)); 152 } 153 154 SecurityOrigin* WebSecurityOrigin::get() const 155 { 156 return m_private; 157 } 158 159 void WebSecurityOrigin::assign(WebSecurityOriginPrivate* p) 160 { 161 // p is already ref'd for us by the caller 162 if (m_private) 163 m_private->deref(); 164 m_private = p; 165 } 166 167 void WebSecurityOrigin::grantLoadLocalResources() const 168 { 169 get()->grantLoadLocalResources(); 170 } 171 172 } // namespace blink 173