summaryrefslogtreecommitdiffstats
path: root/netwerk/base/ReferrerPolicy.h
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /netwerk/base/ReferrerPolicy.h
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'netwerk/base/ReferrerPolicy.h')
-rw-r--r--netwerk/base/ReferrerPolicy.h186
1 files changed, 186 insertions, 0 deletions
diff --git a/netwerk/base/ReferrerPolicy.h b/netwerk/base/ReferrerPolicy.h
new file mode 100644
index 000000000..591b9daf0
--- /dev/null
+++ b/netwerk/base/ReferrerPolicy.h
@@ -0,0 +1,186 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef ReferrerPolicy_h__
+#define ReferrerPolicy_h__
+
+#include "nsStringGlue.h"
+#include "nsIHttpChannel.h"
+#include "nsUnicharUtils.h"
+
+namespace mozilla { namespace net {
+
+enum ReferrerPolicy {
+ /* spec tokens: never no-referrer */
+ RP_No_Referrer = nsIHttpChannel::REFERRER_POLICY_NO_REFERRER,
+
+ /* spec tokens: origin */
+ RP_Origin = nsIHttpChannel::REFERRER_POLICY_ORIGIN,
+
+ /* spec tokens: default no-referrer-when-downgrade */
+ RP_No_Referrer_When_Downgrade = nsIHttpChannel::REFERRER_POLICY_NO_REFERRER_WHEN_DOWNGRADE,
+ RP_Default = nsIHttpChannel::REFERRER_POLICY_DEFAULT,
+
+ /* spec tokens: origin-when-cross-origin */
+ RP_Origin_When_Crossorigin = nsIHttpChannel::REFERRER_POLICY_ORIGIN_WHEN_XORIGIN,
+
+ /* spec tokens: always unsafe-url */
+ RP_Unsafe_URL = nsIHttpChannel::REFERRER_POLICY_UNSAFE_URL,
+
+ /* spec tokens: same-origin */
+ RP_Same_Origin = nsIHttpChannel::REFERRER_POLICY_SAME_ORIGIN,
+
+ /* spec tokens: strict-origin */
+ RP_Strict_Origin = nsIHttpChannel::REFERRER_POLICY_STRICT_ORIGIN,
+
+ /* spec tokens: strict-origin-when-cross-origin */
+ RP_Strict_Origin_When_Cross_Origin = nsIHttpChannel::REFERRER_POLICY_STRICT_ORIGIN_WHEN_XORIGIN,
+
+ /* spec tokens: empty string */
+ /* The empty string "" corresponds to no referrer policy, or unset policy */
+ RP_Unset = nsIHttpChannel::REFERRER_POLICY_UNSET,
+};
+
+/* spec tokens: never no-referrer */
+const char kRPS_Never[] = "never";
+const char kRPS_No_Referrer[] = "no-referrer";
+
+/* spec tokens: origin */
+const char kRPS_Origin[] = "origin";
+
+/* spec tokens: default no-referrer-when-downgrade */
+const char kRPS_Default[] = "default";
+const char kRPS_No_Referrer_When_Downgrade[] = "no-referrer-when-downgrade";
+
+/* spec tokens: origin-when-cross-origin */
+const char kRPS_Origin_When_Cross_Origin[] = "origin-when-cross-origin";
+const char kRPS_Origin_When_Crossorigin[] = "origin-when-crossorigin";
+
+/* spec tokens: same-origin */
+const char kRPS_Same_Origin[] = "same-origin";
+
+/* spec tokens: strict-origin */
+const char kRPS_Strict_Origin[] = "strict-origin";
+
+/* spec tokens: strict-origin-when-cross-origin */
+const char kRPS_Strict_Origin_When_Cross_Origin[] = "strict-origin-when-cross-origin";
+
+/* spec tokens: always unsafe-url */
+const char kRPS_Always[] = "always";
+const char kRPS_Unsafe_URL[] = "unsafe-url";
+
+inline ReferrerPolicy
+ReferrerPolicyFromString(const nsAString& content)
+{
+ if (content.IsEmpty()) {
+ return RP_No_Referrer;
+ }
+
+ nsString lowerContent(content);
+ ToLowerCase(lowerContent);
+ // This is implemented step by step as described in the Referrer Policy
+ // specification, section "Determine token's Policy".
+ if (lowerContent.EqualsLiteral(kRPS_Never) ||
+ lowerContent.EqualsLiteral(kRPS_No_Referrer)) {
+ return RP_No_Referrer;
+ }
+ if (lowerContent.EqualsLiteral(kRPS_Origin)) {
+ return RP_Origin;
+ }
+ if (lowerContent.EqualsLiteral(kRPS_Default) ||
+ lowerContent.EqualsLiteral(kRPS_No_Referrer_When_Downgrade)) {
+ return RP_No_Referrer_When_Downgrade;
+ }
+ if (lowerContent.EqualsLiteral(kRPS_Origin_When_Cross_Origin) ||
+ lowerContent.EqualsLiteral(kRPS_Origin_When_Crossorigin)) {
+ return RP_Origin_When_Crossorigin;
+ }
+ if (lowerContent.EqualsLiteral(kRPS_Same_Origin)) {
+ return RP_Same_Origin;
+ }
+ if (lowerContent.EqualsLiteral(kRPS_Strict_Origin)) {
+ return RP_Strict_Origin;
+ }
+ if (lowerContent.EqualsLiteral(kRPS_Strict_Origin_When_Cross_Origin)) {
+ return RP_Strict_Origin_When_Cross_Origin;
+ }
+ if (lowerContent.EqualsLiteral(kRPS_Always) ||
+ lowerContent.EqualsLiteral(kRPS_Unsafe_URL)) {
+ return RP_Unsafe_URL;
+ }
+ // Spec says if none of the previous match, use empty string.
+ return RP_Unset;
+
+}
+
+inline bool
+IsValidReferrerPolicy(const nsAString& content)
+{
+ if (content.IsEmpty()) {
+ return true;
+ }
+
+ nsString lowerContent(content);
+ ToLowerCase(lowerContent);
+
+ return lowerContent.EqualsLiteral(kRPS_Never)
+ || lowerContent.EqualsLiteral(kRPS_No_Referrer)
+ || lowerContent.EqualsLiteral(kRPS_Origin)
+ || lowerContent.EqualsLiteral(kRPS_Default)
+ || lowerContent.EqualsLiteral(kRPS_No_Referrer_When_Downgrade)
+ || lowerContent.EqualsLiteral(kRPS_Origin_When_Cross_Origin)
+ || lowerContent.EqualsLiteral(kRPS_Origin_When_Crossorigin)
+ || lowerContent.EqualsLiteral(kRPS_Same_Origin)
+ || lowerContent.EqualsLiteral(kRPS_Strict_Origin)
+ || lowerContent.EqualsLiteral(kRPS_Strict_Origin_When_Cross_Origin)
+ || lowerContent.EqualsLiteral(kRPS_Always)
+ || lowerContent.EqualsLiteral(kRPS_Unsafe_URL);
+}
+
+inline ReferrerPolicy
+AttributeReferrerPolicyFromString(const nsAString& content)
+{
+ // Specs : https://html.spec.whatwg.org/multipage/infrastructure.html#referrer-policy-attribute
+ // Spec says the empty string "" corresponds to no referrer policy, or RP_Unset
+ if (content.IsEmpty()) {
+ return RP_Unset;
+ }
+
+ nsString lowerContent(content);
+ ToLowerCase(lowerContent);
+
+ if (lowerContent.EqualsLiteral(kRPS_No_Referrer)) {
+ return RP_No_Referrer;
+ }
+ if (lowerContent.EqualsLiteral(kRPS_Origin)) {
+ return RP_Origin;
+ }
+ if (lowerContent.EqualsLiteral(kRPS_No_Referrer_When_Downgrade)) {
+ return RP_No_Referrer_When_Downgrade;
+ }
+ if (lowerContent.EqualsLiteral(kRPS_Origin_When_Cross_Origin)) {
+ return RP_Origin_When_Crossorigin;
+ }
+ if (lowerContent.EqualsLiteral(kRPS_Unsafe_URL)) {
+ return RP_Unsafe_URL;
+ }
+ if (lowerContent.EqualsLiteral(kRPS_Strict_Origin)) {
+ return RP_Strict_Origin;
+ }
+ if (lowerContent.EqualsLiteral(kRPS_Same_Origin)) {
+ return RP_Same_Origin;
+ }
+ if (lowerContent.EqualsLiteral(kRPS_Strict_Origin_When_Cross_Origin)) {
+ return RP_Strict_Origin_When_Cross_Origin;
+ }
+
+ // Spec says invalid value default is empty string state
+ // So, return RP_Unset if none of the previous match, return RP_Unset
+ return RP_Unset;
+}
+
+} // namespace net
+} // namespace mozilla
+
+#endif