1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "StorageOriginAttributes.h"
10 #include "nsURLHelper.h"
11 #include "mozilla/Assertions.h"
12 #include "mozilla/dom/quota/QuotaManager.h"
16 void StorageOriginAttributes::CreateSuffix(nsACString
& aStr
) const {
22 if (mInIsolatedMozBrowser
) {
23 params
.Set(u
"inBrowser"_ns
, u
"1"_ns
);
28 params
.Serialize(value
, true);
29 if (!value
.IsEmpty()) {
30 str1
.AppendLiteral("^");
31 str1
.Append(NS_ConvertUTF16toUTF8(value
));
34 // Make sure that the string don't contain characters that would get replaced
35 // with the plus character by quota manager, potentially causing ambiguity.
36 MOZ_ASSERT(str1
.FindCharInSet(dom::quota::QuotaManager::kReplaceChars
) ==
39 // Let OriginAttributes::CreateSuffix serialize other origin attributes.
41 mOriginAttributes
.CreateSuffix(str2
);
55 // If both strings are not empty, we need to combine them.
58 aStr
.Append(Substring(str2
, 1, str2
.Length() - 1));
61 bool StorageOriginAttributes::PopulateFromSuffix(const nsACString
& aStr
) {
71 URLParams::Parse(Substring(aStr
, 1, aStr
.Length() - 1),
72 [this](const nsAString
& aName
, const nsAString
& aValue
) {
73 if (aName
.EqualsLiteral("inBrowser")) {
74 if (!aValue
.EqualsLiteral("1")) {
78 mInIsolatedMozBrowser
= true;
82 // Let OriginAttributes::PopulateFromSuffix parse other
90 return mOriginAttributes
.PopulateFromSuffix(aStr
);
93 bool StorageOriginAttributes::PopulateFromOrigin(const nsACString
& aOrigin
,
94 nsACString
& aOriginNoSuffix
) {
95 // RFindChar is only available on nsCString.
96 nsCString
origin(aOrigin
);
97 int32_t pos
= origin
.RFindChar('^');
99 if (pos
== kNotFound
) {
100 aOriginNoSuffix
= origin
;
104 aOriginNoSuffix
= Substring(origin
, 0, pos
);
105 return PopulateFromSuffix(Substring(origin
, pos
));
108 } // namespace mozilla