no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / quota / OriginParser.h
blobcc4d0d1a11e53110ccff6ea1b125e3e65517f697
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"
13 #include "nsString.h"
14 #include "nsTArray.h"
16 namespace mozilla {
18 class OriginAttributes;
20 namespace dom::quota {
22 class MOZ_STACK_CLASS OriginParser final {
23 public:
24 enum ResultType { InvalidOrigin, ObsoleteOrigin, ValidOrigin };
26 private:
27 using Tokenizer =
28 nsCCharSeparatedTokenizerTemplate<NS_TokenizerIgnoreNothing>;
30 enum SchemeType { eNone, eFile, eAbout, eChrome };
32 enum State {
33 eExpectingAppIdOrScheme,
34 eExpectingInMozBrowser,
35 eExpectingScheme,
36 eExpectingEmptyToken1,
37 eExpectingEmptyToken2,
38 eExpectingEmptyTokenOrUniversalFileOrigin,
39 eExpectingHost,
40 eExpectingPort,
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
51 // with that.
52 eExpectingIPV6Token,
53 eComplete,
54 eHandledTrailingSeparator
57 const nsCString mOrigin;
58 Tokenizer mTokenizer;
60 nsCString mScheme;
61 nsCString mHost;
62 Nullable<uint32_t> mPort;
63 nsTArray<nsCString> mPathnameComponents;
64 nsCString mHandledTokens;
66 SchemeType mSchemeType;
67 State mState;
68 bool mInIsolatedMozBrowser;
69 bool mUniversalFileOrigin;
70 bool mMaybeDriveLetter;
71 bool mError;
72 bool mMaybeObsolete;
74 // Number of group which a IPv6 address has. Should be less than 9.
75 uint8_t mIPGroup;
77 public:
78 explicit OriginParser(const nsACString& aOrigin)
79 : mOrigin(aOrigin),
80 mTokenizer(aOrigin, '+'),
81 mSchemeType(eNone),
82 mState(eExpectingAppIdOrScheme),
83 mInIsolatedMozBrowser(false),
84 mUniversalFileOrigin(false),
85 mMaybeDriveLetter(false),
86 mError(false),
87 mMaybeObsolete(false),
88 mIPGroup(0) {}
90 static ResultType ParseOrigin(const nsACString& aOrigin, nsCString& aSpec,
91 OriginAttributes* aAttrs,
92 nsCString& aOriginalSuffix);
94 ResultType Parse(nsACString& aSpec);
96 private:
97 void HandleScheme(const nsDependentCSubstring& aToken);
99 void HandlePathnameComponent(const nsDependentCSubstring& aToken);
101 void HandleToken(const nsDependentCSubstring& aToken);
103 void HandleTrailingSeparator();
106 bool IsUUIDOrigin(const nsCString& aOrigin);
108 } // namespace dom::quota
109 } // namespace mozilla
111 #endif // DOM_QUOTA_ORIGINPARSER_H_