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 #ifndef DOM_QUOTA_ORIGINPARSER_H_
8 #define DOM_QUOTA_ORIGINPARSER_H_
10 #include "mozilla/Attributes.h"
11 #include "mozilla/dom/Nullable.h"
12 #include "nsCharSeparatedTokenizer.h"
18 class OriginAttributes
;
20 namespace dom::quota
{
22 class MOZ_STACK_CLASS OriginParser final
{
24 enum ResultType
{ InvalidOrigin
, ObsoleteOrigin
, ValidOrigin
};
28 nsCCharSeparatedTokenizerTemplate
<NS_TokenizerIgnoreNothing
>;
30 enum SchemeType
{ eNone
, eFile
, eAbout
, eChrome
};
33 eExpectingAppIdOrScheme
,
34 eExpectingInMozBrowser
,
36 eExpectingEmptyToken1
,
37 eExpectingEmptyToken2
,
38 eExpectingEmptyTokenOrUniversalFileOrigin
,
41 eExpectingEmptyTokenOrDriveLetterOrPathnameComponent
,
42 eExpectingEmptyTokenOrPathnameComponent
,
43 eExpectingEmptyToken1OrHost
,
45 // We transit from eExpectingHost to this state when we encounter a host
46 // beginning with "[" which indicates an IPv6 literal. Because we mangle the
47 // IPv6 ":" delimiter to be a "+", we will receive separate tokens for each
48 // portion of the IPv6 address, including a final token that ends with "]".
49 // (Note that we do not mangle "[" or "]".) Note that the URL spec
50 // explicitly disclaims support for "<zone_id>" and so we don't have to deal
54 eHandledTrailingSeparator
57 const nsCString mOrigin
;
62 Nullable
<uint32_t> mPort
;
63 nsTArray
<nsCString
> mPathnameComponents
;
64 nsCString mHandledTokens
;
66 SchemeType mSchemeType
;
68 bool mUniversalFileOrigin
;
69 bool mMaybeDriveLetter
;
73 // Number of group which a IPv6 address has. Should be less than 9.
77 explicit OriginParser(const nsACString
& aOrigin
)
79 mTokenizer(aOrigin
, '+'),
81 mState(eExpectingAppIdOrScheme
),
82 mUniversalFileOrigin(false),
83 mMaybeDriveLetter(false),
85 mMaybeObsolete(false),
88 static ResultType
ParseOrigin(const nsACString
& aOrigin
, nsCString
& aSpec
,
89 OriginAttributes
* aAttrs
,
90 nsCString
& aOriginalSuffix
);
92 ResultType
Parse(nsACString
& aSpec
);
95 void HandleScheme(const nsDependentCSubstring
& aToken
);
97 void HandlePathnameComponent(const nsDependentCSubstring
& aToken
);
99 void HandleToken(const nsDependentCSubstring
& aToken
);
101 void HandleTrailingSeparator();
104 bool IsUUIDOrigin(const nsCString
& aOrigin
);
106 } // namespace dom::quota
107 } // namespace mozilla
109 #endif // DOM_QUOTA_ORIGINPARSER_H_