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 "WebSecurityOrigin.h" 33 34#include "KURL.h" 35#include "SecurityOrigin.h" 36#include "WebString.h" 37#include "WebURL.h" 38#include <wtf/PassRefPtr.h> 39 40using namespace WebCore; 41 42namespace WebKit { 43 44class WebSecurityOriginPrivate : public SecurityOrigin { 45}; 46 47WebSecurityOrigin WebSecurityOrigin::createFromDatabaseIdentifier(const WebString& databaseIdentifier) 48{ 49 return WebSecurityOrigin(SecurityOrigin::createFromDatabaseIdentifier(databaseIdentifier)); 50} 51 52WebSecurityOrigin WebSecurityOrigin::createFromString(const WebString& origin) 53{ 54 return WebSecurityOrigin(SecurityOrigin::createFromString(origin)); 55} 56 57WebSecurityOrigin WebSecurityOrigin::create(const WebURL& url) 58{ 59 return WebSecurityOrigin(SecurityOrigin::create(url)); 60} 61 62void WebSecurityOrigin::reset() 63{ 64 assign(0); 65} 66 67void WebSecurityOrigin::assign(const WebSecurityOrigin& other) 68{ 69 WebSecurityOriginPrivate* p = const_cast<WebSecurityOriginPrivate*>(other.m_private); 70 if (p) 71 p->ref(); 72 assign(p); 73} 74 75WebString WebSecurityOrigin::protocol() const 76{ 77 ASSERT(m_private); 78 return m_private->protocol(); 79} 80 81WebString WebSecurityOrigin::host() const 82{ 83 ASSERT(m_private); 84 return m_private->host(); 85} 86 87unsigned short WebSecurityOrigin::port() const 88{ 89 ASSERT(m_private); 90 return m_private->port(); 91} 92 93bool WebSecurityOrigin::isEmpty() const 94{ 95 ASSERT(m_private); 96 return m_private->isEmpty(); 97} 98 99bool WebSecurityOrigin::canAccess(const WebSecurityOrigin& other) const 100{ 101 ASSERT(m_private); 102 ASSERT(other.m_private); 103 return m_private->canAccess(other.m_private); 104} 105 106bool WebSecurityOrigin::canRequest(const WebURL& url) const 107{ 108 ASSERT(m_private); 109 return m_private->canRequest(url); 110} 111 112WebString WebSecurityOrigin::toString() const 113{ 114 ASSERT(m_private); 115 return m_private->toString(); 116} 117 118WebString WebSecurityOrigin::databaseIdentifier() const 119{ 120 ASSERT(m_private); 121 return m_private->databaseIdentifier(); 122} 123 124bool WebSecurityOrigin::canAccessPasswordManager() const 125{ 126 ASSERT(m_private); 127 return m_private->canAccessPasswordManager(); 128} 129 130WebSecurityOrigin::WebSecurityOrigin(const WTF::PassRefPtr<WebCore::SecurityOrigin>& origin) 131 : m_private(static_cast<WebSecurityOriginPrivate*>(origin.releaseRef())) 132{ 133} 134 135WebSecurityOrigin& WebSecurityOrigin::operator=(const WTF::PassRefPtr<WebCore::SecurityOrigin>& origin) 136{ 137 assign(static_cast<WebSecurityOriginPrivate*>(origin.releaseRef())); 138 return *this; 139} 140 141WebSecurityOrigin::operator WTF::PassRefPtr<WebCore::SecurityOrigin>() const 142{ 143 return PassRefPtr<SecurityOrigin>(const_cast<WebSecurityOriginPrivate*>(m_private)); 144} 145 146SecurityOrigin* WebSecurityOrigin::get() const 147{ 148 return m_private; 149} 150 151void WebSecurityOrigin::assign(WebSecurityOriginPrivate* p) 152{ 153 // p is already ref'd for us by the caller 154 if (m_private) 155 m_private->deref(); 156 m_private = p; 157} 158 159} // namespace WebKit 160