2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
32 #include "public/web/WebSecurityOrigin.h"
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"
43 class WebSecurityOriginPrivate : public SecurityOrigin {
46 WebSecurityOrigin WebSecurityOrigin::createFromDatabaseIdentifier(const WebString& databaseIdentifier)
48 return WebSecurityOrigin(createSecurityOriginFromDatabaseIdentifier(databaseIdentifier));
51 WebSecurityOrigin WebSecurityOrigin::createFromString(const WebString& origin)
53 return WebSecurityOrigin(SecurityOrigin::createFromString(origin));
56 WebSecurityOrigin WebSecurityOrigin::create(const WebURL& url)
58 return WebSecurityOrigin(SecurityOrigin::create(url));
61 void WebSecurityOrigin::reset()
66 void WebSecurityOrigin::assign(const WebSecurityOrigin& other)
68 WebSecurityOriginPrivate* p = const_cast<WebSecurityOriginPrivate*>(other.m_private);
74 WebString WebSecurityOrigin::protocol() const
77 return m_private->protocol();
80 WebString WebSecurityOrigin::host() const
83 return m_private->host();
86 unsigned short WebSecurityOrigin::port() const
89 return m_private->port();
92 bool WebSecurityOrigin::isUnique() const
95 return m_private->isUnique();
98 bool WebSecurityOrigin::canAccess(const WebSecurityOrigin& other) const
101 ASSERT(other.m_private);
102 return m_private->canAccess(other.m_private);
105 bool WebSecurityOrigin::canRequest(const WebURL& url) const
108 return m_private->canRequest(url);
111 bool WebSecurityOrigin::canAccessFeatureRequiringSecureOrigin(WebString& errorMessage) const
114 WTF::String message(errorMessage);
115 bool result = m_private->canAccessFeatureRequiringSecureOrigin(message);
116 errorMessage = message;
120 WebString WebSecurityOrigin::toString() const
123 return m_private->toString();
126 WebString WebSecurityOrigin::databaseIdentifier() const
129 return createDatabaseIdentifierFromSecurityOrigin(m_private);
132 bool WebSecurityOrigin::canAccessPasswordManager() const
135 return m_private->canAccessPasswordManager();
138 WebSecurityOrigin::WebSecurityOrigin(const WTF::PassRefPtr<SecurityOrigin>& origin)
139 : m_private(static_cast<WebSecurityOriginPrivate*>(origin.leakRef()))
143 WebSecurityOrigin& WebSecurityOrigin::operator=(const WTF::PassRefPtr<SecurityOrigin>& origin)
145 assign(static_cast<WebSecurityOriginPrivate*>(origin.leakRef()));
149 WebSecurityOrigin::operator WTF::PassRefPtr<SecurityOrigin>() const
151 return PassRefPtr<SecurityOrigin>(const_cast<WebSecurityOriginPrivate*>(m_private));
154 SecurityOrigin* WebSecurityOrigin::get() const
159 void WebSecurityOrigin::assign(WebSecurityOriginPrivate* p)
161 // p is already ref'd for us by the caller
167 void WebSecurityOrigin::grantLoadLocalResources() const
169 get()->grantLoadLocalResources();