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