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.
31 #ifndef WebSecurityOrigin_h
32 #define WebSecurityOrigin_h
34 // TODO(tasak): WebSecurityOrigin should be in public/platform.
35 // However, we could not move this file soon, because
36 // content depends on public/web/WebSecurityOrigin. So firstly
37 // (1) fix and create another WebSecurityOrigin.h in public/platform,
38 // and copy the WebSecurityOrigin.h here.
39 // (2) fix content side to use public/platform/WebSecurityOrigin after
41 // (3) remove this public/web/WebSecurityOrigin.h.
43 #include "public/platform/WebCommon.h"
46 #include "wtf/PassRefPtr.h"
52 class WebSecurityOriginPrivate
;
56 class WebSecurityOrigin
{
58 ~WebSecurityOrigin() { reset(); }
60 WebSecurityOrigin() : m_private(0) { }
61 WebSecurityOrigin(const WebSecurityOrigin
& s
) : m_private(0) { assign(s
); }
62 WebSecurityOrigin
& operator=(const WebSecurityOrigin
& s
)
68 BLINK_PLATFORM_EXPORT
static WebSecurityOrigin
createFromDatabaseIdentifier(const WebString
& databaseIdentifier
);
69 BLINK_PLATFORM_EXPORT
static WebSecurityOrigin
createFromString(const WebString
&);
70 BLINK_PLATFORM_EXPORT
static WebSecurityOrigin
create(const WebURL
&);
72 BLINK_PLATFORM_EXPORT
void reset();
73 BLINK_PLATFORM_EXPORT
void assign(const WebSecurityOrigin
&);
75 bool isNull() const { return !m_private
; }
77 BLINK_PLATFORM_EXPORT WebString
protocol() const;
78 BLINK_PLATFORM_EXPORT WebString
host() const;
79 BLINK_PLATFORM_EXPORT
unsigned short port() const;
81 // A unique WebSecurityOrigin is the least privileged WebSecurityOrigin.
82 BLINK_PLATFORM_EXPORT
bool isUnique() const;
84 // Returns true if this WebSecurityOrigin can script objects in the given
85 // SecurityOrigin. For example, call this function before allowing
86 // script from one security origin to read or write objects from
87 // another SecurityOrigin.
88 BLINK_PLATFORM_EXPORT
bool canAccess(const WebSecurityOrigin
&) const;
90 // Returns true if this WebSecurityOrigin can read content retrieved from
91 // the given URL. For example, call this function before allowing script
92 // from a given security origin to receive contents from a given URL.
93 BLINK_PLATFORM_EXPORT
bool canRequest(const WebURL
&) const;
95 // Returns true if the origin loads resources either from the local
96 // machine or over the network from a
97 // cryptographically-authenticated origin, as described in
98 // https://w3c.github.io/webappsec/specs/powerfulfeatures/#is-origin-trustworthy.
99 BLINK_PLATFORM_EXPORT
bool isPotentiallyTrustworthy(WebString
& errorMessage
) const;
101 // Returns a string representation of the WebSecurityOrigin. The empty
102 // WebSecurityOrigin is represented by "null". The representation of a
103 // non-empty WebSecurityOrigin resembles a standard URL.
104 BLINK_PLATFORM_EXPORT WebString
toString() const;
106 // Returns a string representation of this WebSecurityOrigin that can
107 // be used as a file. Should be used in storage APIs only.
108 BLINK_PLATFORM_EXPORT WebString
databaseIdentifier() const;
110 // Returns true if this WebSecurityOrigin can access usernames and
111 // passwords stored in password manager.
112 BLINK_PLATFORM_EXPORT
bool canAccessPasswordManager() const;
114 // Allows this WebSecurityOrigin access to local resources.
115 BLINK_PLATFORM_EXPORT
void grantLoadLocalResources() const;
118 BLINK_PLATFORM_EXPORT
WebSecurityOrigin(const WTF::PassRefPtr
<SecurityOrigin
>&);
119 BLINK_PLATFORM_EXPORT WebSecurityOrigin
& operator=(const WTF::PassRefPtr
<SecurityOrigin
>&);
120 BLINK_PLATFORM_EXPORT
operator WTF::PassRefPtr
<SecurityOrigin
>() const;
121 BLINK_PLATFORM_EXPORT SecurityOrigin
* get() const;
125 void assign(WebSecurityOriginPrivate
*);
126 WebSecurityOriginPrivate
* m_private
;