summaryrefslogtreecommitdiff
path: root/Source/WebCore/page/SecurityOrigin.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/page/SecurityOrigin.h')
-rw-r--r--Source/WebCore/page/SecurityOrigin.h108
1 files changed, 53 insertions, 55 deletions
diff --git a/Source/WebCore/page/SecurityOrigin.h b/Source/WebCore/page/SecurityOrigin.h
index d11866de0..e63f4bd22 100644
--- a/Source/WebCore/page/SecurityOrigin.h
+++ b/Source/WebCore/page/SecurityOrigin.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2007-2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -10,7 +10,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
@@ -26,8 +26,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef SecurityOrigin_h
-#define SecurityOrigin_h
+#pragma once
#include <wtf/ThreadSafeRefCounted.h>
#include <wtf/text/WTFString.h>
@@ -50,12 +49,11 @@ public:
BlockAllStorage
};
- static PassRefPtr<SecurityOrigin> create(const URL&);
- static PassRefPtr<SecurityOrigin> createUnique();
+ WEBCORE_EXPORT static Ref<SecurityOrigin> create(const URL&);
+ static Ref<SecurityOrigin> createUnique();
- static PassRefPtr<SecurityOrigin> createFromDatabaseIdentifier(const String&);
- static PassRefPtr<SecurityOrigin> createFromString(const String&);
- static PassRefPtr<SecurityOrigin> create(const String& protocol, const String& host, int port);
+ WEBCORE_EXPORT static Ref<SecurityOrigin> createFromString(const String&);
+ WEBCORE_EXPORT static Ref<SecurityOrigin> create(const String& protocol, const String& host, std::optional<uint16_t> port);
// Some URL schemes use nested URLs for their security context. For example,
// filesystem URLs look like the following:
@@ -72,7 +70,7 @@ public:
// Create a deep copy of this SecurityOrigin. This method is useful
// when marshalling a SecurityOrigin to another thread.
- PassRefPtr<SecurityOrigin> isolatedCopy() const;
+ WEBCORE_EXPORT Ref<SecurityOrigin> isolatedCopy() const;
// Set the domain property of this security origin to newDomain. This
// function does not check whether newDomain is a suffix of the current
@@ -80,10 +78,10 @@ public:
void setDomainFromDOM(const String& newDomain);
bool domainWasSetInDOM() const { return m_domainWasSetInDOM; }
- String protocol() const { return m_protocol; }
- String host() const { return m_host; }
- String domain() const { return m_domain; }
- unsigned short port() const { return m_port; }
+ const String& protocol() const { return m_protocol; }
+ const String& host() const { return m_host; }
+ const String& domain() const { return m_domain; }
+ std::optional<uint16_t> port() const { return m_port; }
// Returns true if a given URL is secure, based either directly on its
// own protocol, or, when relevant, on the protocol of its "inner URL"
@@ -94,27 +92,22 @@ public:
// SecurityOrigin. For example, call this function before allowing
// script from one security origin to read or write objects from
// another SecurityOrigin.
- bool canAccess(const SecurityOrigin*) const;
+ WEBCORE_EXPORT bool canAccess(const SecurityOrigin&) const;
// Returns true if this SecurityOrigin can read content retrieved from
// the given URL. For example, call this function before issuing
// XMLHttpRequests.
bool canRequest(const URL&) const;
- // Returns true if drawing an image from this URL taints a canvas from
- // this security origin. For example, call this function before
- // drawing an image onto an HTML canvas element with the drawImage API.
- bool taintsCanvas(const URL&) const;
-
// Returns true if this SecurityOrigin can receive drag content from the
// initiator. For example, call this function before allowing content to be
// dropped onto a target.
- bool canReceiveDragData(const SecurityOrigin* dragInitiator) const;
+ bool canReceiveDragData(const SecurityOrigin& dragInitiator) const;
// Returns true if |document| can display content from the given URL (e.g.,
// in an iframe or as an image). For example, web sites generally cannot
// display content from the user's files system.
- bool canDisplay(const URL&) const;
+ WEBCORE_EXPORT bool canDisplay(const URL&) const;
// Returns true if this SecurityOrigin can load local resources, such
// as images, iframes, and style sheets, and can link to local URLs.
@@ -138,28 +131,28 @@ public:
//
// WARNING: This is an extremely powerful ability. Use with caution!
void grantUniversalAccess();
+ bool hasUniversalAccess() const { return m_universalAccess; }
void setStorageBlockingPolicy(StorageBlockingPolicy policy) { m_storageBlockingPolicy = policy; }
-#if ENABLE(CACHE_PARTITIONING)
- String cachePartition() const;
-#endif
+ void grantStorageAccessFromFileURLsQuirk();
+ bool needsStorageAccessFromFileURLsQuirk() const { return m_needsStorageAccessFromFileURLsQuirk; }
+
+ WEBCORE_EXPORT String domainForCachePartition() const;
- bool canAccessDatabase(const SecurityOrigin* topOrigin = 0) const { return canAccessStorage(topOrigin); };
- bool canAccessSessionStorage(const SecurityOrigin* topOrigin) const { return canAccessStorage(topOrigin, AlwaysAllowFromThirdParty); }
+ bool canAccessDatabase(const SecurityOrigin& topOrigin) const { return canAccessStorage(&topOrigin); };
+ bool canAccessSessionStorage(const SecurityOrigin& topOrigin) const { return canAccessStorage(&topOrigin, AlwaysAllowFromThirdParty); }
bool canAccessLocalStorage(const SecurityOrigin* topOrigin) const { return canAccessStorage(topOrigin); };
- bool canAccessSharedWorkers(const SecurityOrigin* topOrigin) const { return canAccessStorage(topOrigin); }
- bool canAccessPluginStorage(const SecurityOrigin* topOrigin) const { return canAccessStorage(topOrigin); }
- bool canAccessApplicationCache(const SecurityOrigin* topOrigin) const { return canAccessStorage(topOrigin); }
+ bool canAccessPluginStorage(const SecurityOrigin& topOrigin) const { return canAccessStorage(&topOrigin); }
+ bool canAccessApplicationCache(const SecurityOrigin& topOrigin) const { return canAccessStorage(&topOrigin); }
bool canAccessCookies() const { return !isUnique(); }
- bool canAccessPasswordManager() const { return !isUnique(); }
- bool canAccessFileSystem() const { return !isUnique(); }
+ bool canRequestGeolocation() const { return !isUnique(); }
Policy canShowNotifications() const;
// The local SecurityOrigin is the most privileged SecurityOrigin.
// The local SecurityOrigin can script any document, navigate to local
// resources, and can set arbitrary headers on XMLHttpRequests.
- bool isLocal() const;
+ WEBCORE_EXPORT bool isLocal() const;
// The origin is a globally unique identifier assigned when the Document is
// created. http://www.whatwg.org/specs/web-apps/current-work/#sandboxOrigin
@@ -184,28 +177,28 @@ public:
// this SecurityOrigin might have come from a sandboxed iframe, the
// SecurityOrigin might be empty, or we might have explicitly decided that
// we shouldTreatURLSchemeAsNoAccess.
- String toString() const;
+ WEBCORE_EXPORT String toString() const;
// Similar to toString(), but does not take into account any factors that
// could make the string return "null".
- String toRawString() const;
-
- // Serialize the security origin to a string that could be used as part of
- // file names. This format should be used in storage APIs only.
- String databaseIdentifier() const;
+ WEBCORE_EXPORT String toRawString() const;
// This method checks for equality between SecurityOrigins, not whether
// one origin can access another. It is used for hash table keys.
// For access checks, use canAccess().
// FIXME: If this method is really only useful for hash table keys, it
// should be refactored into SecurityOriginHash.
- bool equal(const SecurityOrigin*) const;
+ WEBCORE_EXPORT bool equal(const SecurityOrigin*) const;
// This method checks for equality, ignoring the value of document.domain
// (and whether it was set) but considering the host. It is used for postMessage.
- bool isSameSchemeHostPort(const SecurityOrigin*) const;
+ WEBCORE_EXPORT bool isSameSchemeHostPort(const SecurityOrigin&) const;
+
+ // This method implements the "same origin" algorithm from the HTML Standard:
+ // https://html.spec.whatwg.org/multipage/browsers.html#same-origin
+ WEBCORE_EXPORT bool isSameOriginAs(const SecurityOrigin&) const;
- static String urlWithUniqueSecurityOrigin();
+ static URL urlWithUniqueSecurityOrigin();
private:
SecurityOrigin();
@@ -213,26 +206,31 @@ private:
explicit SecurityOrigin(const SecurityOrigin*);
// FIXME: Rename this function to something more semantic.
- bool passesFileCheck(const SecurityOrigin*) const;
- bool isThirdParty(const SecurityOrigin*) const;
+ bool passesFileCheck(const SecurityOrigin&) const;
+
+ // This method checks that the scheme for this origin is an HTTP-family
+ // scheme, e.g. HTTP and HTTPS.
+ bool isHTTPFamily() const { return m_protocol == "http" || m_protocol == "https"; }
enum ShouldAllowFromThirdParty { AlwaysAllowFromThirdParty, MaybeAllowFromThirdParty };
- bool canAccessStorage(const SecurityOrigin*, ShouldAllowFromThirdParty = MaybeAllowFromThirdParty) const;
+ WEBCORE_EXPORT bool canAccessStorage(const SecurityOrigin*, ShouldAllowFromThirdParty = MaybeAllowFromThirdParty) const;
String m_protocol;
String m_host;
String m_domain;
String m_filePath;
- unsigned short m_port;
- bool m_isUnique;
- bool m_universalAccess;
- bool m_domainWasSetInDOM;
- bool m_canLoadLocalResources;
- StorageBlockingPolicy m_storageBlockingPolicy;
- bool m_enforceFilePathSeparation;
- bool m_needsDatabaseIdentifierQuirkForFiles;
+ std::optional<uint16_t> m_port;
+ bool m_isUnique { false };
+ bool m_universalAccess { false };
+ bool m_domainWasSetInDOM { false };
+ bool m_canLoadLocalResources { false };
+ StorageBlockingPolicy m_storageBlockingPolicy { AllowAllStorage };
+ bool m_enforceFilePathSeparation { false };
+ bool m_needsStorageAccessFromFileURLsQuirk { false };
};
-} // namespace WebCore
+// Returns true if the Origin header values serialized from these two origins would be the same.
+bool originsMatch(const SecurityOrigin&, const SecurityOrigin&);
+bool originsMatch(const SecurityOrigin*, const SecurityOrigin*);
-#endif // SecurityOrigin_h
+} // namespace WebCore