10bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch/*
20bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch * Copyright (C) 2009 Google Inc. All rights reserved.
30bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch *
40bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch * Redistribution and use in source and binary forms, with or without
50bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch * modification, are permitted provided that the following conditions are
60bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch * met:
70bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch *
80bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch *     * Redistributions of source code must retain the above copyright
90bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch * notice, this list of conditions and the following disclaimer.
100bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch *     * Redistributions in binary form must reproduce the above
110bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch * copyright notice, this list of conditions and the following disclaimer
120bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch * in the documentation and/or other materials provided with the
130bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch * distribution.
140bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch *     * Neither the name of Google Inc. nor the names of its
150bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch * contributors may be used to endorse or promote products derived from
160bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch * this software without specific prior written permission.
170bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch *
180bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
190bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
200bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
210bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
220bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
230bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
240bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
250bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
260bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
270bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
280bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
290bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch */
300bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch
3106ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen#ifndef OriginAccessEntry_h
3206ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen#define OriginAccessEntry_h
330bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch
34231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include "PlatformString.h"
350bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch
360bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdochnamespace WebCore {
370bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch
38231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockclass SecurityOrigin;
39231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
40231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockclass OriginAccessEntry {
41231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockpublic:
42231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    enum SubdomainSetting {
43231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        AllowSubdomains,
44231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        DisallowSubdomains
45231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    };
46231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
47231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    // If host is empty string and SubdomainSetting is AllowSubdomains, the entry will match all domains in the specified protocol.
48231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    OriginAccessEntry(const String& protocol, const String& host, SubdomainSetting);
49231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    bool matchesOrigin(const SecurityOrigin&) const;
50dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block
51dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    const String& protocol() const { return m_protocol; }
52dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    const String& host() const { return m_host; }
53dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    SubdomainSetting subdomainSettings() const { return m_subdomainSettings; }
54dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block
55231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockprivate:
56231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    String m_protocol;
57231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    String m_host;
58231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    SubdomainSetting m_subdomainSettings;
59231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    bool m_hostIsIPAddress;
60231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block};
610bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch
62dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockinline bool operator==(const OriginAccessEntry& a, const OriginAccessEntry& b)
63dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block{
64dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    return equalIgnoringCase(a.protocol(), b.protocol()) && equalIgnoringCase(a.host(), b.host()) && a.subdomainSettings() == b.subdomainSettings();
65dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block}
66dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block
67dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockinline bool operator!=(const OriginAccessEntry& a, const OriginAccessEntry& b)
68dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block{
69dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    return !(a == b);
70dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block}
71dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block
720bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch} // namespace WebCore
730bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch
7406ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen#endif // OriginAccessEntry_h
75