Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2009 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 "SecurityOrigin.h"
     35 #include "WebString.h"
     36 #include <wtf/PassRefPtr.h>
     37 
     38 using namespace WebCore;
     39 
     40 namespace WebKit {
     41 
     42 class WebSecurityOriginPrivate : public SecurityOrigin {
     43 };
     44 
     45 WebSecurityOrigin* WebSecurityOrigin::createFromDatabaseIdentifier(const WebString& databaseIdentifier)
     46 {
     47     return new WebSecurityOrigin(SecurityOrigin::createFromDatabaseIdentifier(databaseIdentifier));
     48 }
     49 
     50 WebSecurityOrigin WebSecurityOrigin::createFromString(const WebString& origin)
     51 {
     52     return WebSecurityOrigin(SecurityOrigin::createFromString(origin));
     53 }
     54 
     55 void WebSecurityOrigin::reset()
     56 {
     57     assign(0);
     58 }
     59 
     60 void WebSecurityOrigin::assign(const WebSecurityOrigin& other)
     61 {
     62     WebSecurityOriginPrivate* p = const_cast<WebSecurityOriginPrivate*>(other.m_private);
     63     if (p)
     64         p->ref();
     65     assign(p);
     66 }
     67 
     68 WebString WebSecurityOrigin::protocol() const
     69 {
     70     ASSERT(m_private);
     71     return m_private->protocol();
     72 }
     73 
     74 WebString WebSecurityOrigin::host() const
     75 {
     76     ASSERT(m_private);
     77     return m_private->host();
     78 }
     79 
     80 unsigned short WebSecurityOrigin::port() const
     81 {
     82     ASSERT(m_private);
     83     return m_private->port();
     84 }
     85 
     86 bool WebSecurityOrigin::isEmpty() const
     87 {
     88     ASSERT(m_private);
     89     return m_private->isEmpty();
     90 }
     91 
     92 WebString WebSecurityOrigin::toString() const
     93 {
     94     ASSERT(m_private);
     95     return m_private->toString();
     96 }
     97 
     98 WebString WebSecurityOrigin::databaseIdentifier()
     99 {
    100     ASSERT(m_private);
    101     return m_private->databaseIdentifier();
    102 }
    103 
    104 WebSecurityOrigin::WebSecurityOrigin(const WTF::PassRefPtr<WebCore::SecurityOrigin>& origin)
    105     : m_private(static_cast<WebSecurityOriginPrivate*>(origin.releaseRef()))
    106 {
    107 }
    108 
    109 WebSecurityOrigin& WebSecurityOrigin::operator=(const WTF::PassRefPtr<WebCore::SecurityOrigin>& origin)
    110 {
    111     assign(static_cast<WebSecurityOriginPrivate*>(origin.releaseRef()));
    112     return *this;
    113 }
    114 
    115 WebSecurityOrigin::operator WTF::PassRefPtr<WebCore::SecurityOrigin>() const
    116 {
    117     return PassRefPtr<SecurityOrigin>(const_cast<WebSecurityOriginPrivate*>(m_private));
    118 }
    119 
    120 void WebSecurityOrigin::assign(WebSecurityOriginPrivate* p)
    121 {
    122     // p is already ref'd for us by the caller
    123     if (m_private)
    124         m_private->deref();
    125     m_private = p;
    126 }
    127 
    128 } // namespace WebKit
    129