Bug 1700051: part 48) Slightly simplify `mozInlineSpellWordUtil::FindRealWordContaini...
[gecko.git] / layout / style / URLExtraData.h
blob9b715b523941ab66dfe89021f9196b5f083128c1
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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* thread-safe container of information for resolving url values */
9 #ifndef mozilla_URLExtraData_h
10 #define mozilla_URLExtraData_h
12 #include <utility>
14 #include "mozilla/StaticPtr.h"
15 #include "mozilla/UserAgentStyleSheetID.h"
16 #include "mozilla/dom/URL.h"
17 #include "nsCOMPtr.h"
18 #include "nsIPrincipal.h"
19 #include "nsIReferrerInfo.h"
20 #include "nsIURI.h"
22 namespace mozilla {
24 struct URLExtraData {
25 URLExtraData(already_AddRefed<nsIURI> aBaseURI,
26 already_AddRefed<nsIReferrerInfo> aReferrerInfo,
27 already_AddRefed<nsIPrincipal> aPrincipal)
28 : mBaseURI(std::move(aBaseURI)),
29 mReferrerInfo(std::move(aReferrerInfo)),
30 mPrincipal(std::move(aPrincipal)) {
31 MOZ_ASSERT(mBaseURI);
32 MOZ_ASSERT(mPrincipal);
33 MOZ_ASSERT(mReferrerInfo);
34 // When we hold the URI data of a style sheet, referrer is always
35 // equal to the sheet URI.
36 nsCOMPtr<nsIURI> referrer = mReferrerInfo->GetOriginalReferrer();
37 mChromeRulesEnabled = referrer && (referrer->SchemeIs("chrome") ||
38 referrer->SchemeIs("resource"));
41 URLExtraData(nsIURI* aBaseURI, nsIReferrerInfo* aReferrerInfo,
42 nsIPrincipal* aPrincipal)
43 : URLExtraData(do_AddRef(aBaseURI), do_AddRef(aReferrerInfo),
44 do_AddRef(aPrincipal)) {}
46 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(URLExtraData)
48 nsIURI* BaseURI() const { return mBaseURI; }
49 nsIReferrerInfo* ReferrerInfo() const { return mReferrerInfo; }
50 nsIPrincipal* Principal() const { return mPrincipal; }
52 bool ChromeRulesEnabled() const { return mChromeRulesEnabled; }
54 static URLExtraData* Dummy() {
55 MOZ_ASSERT(sDummy);
56 return sDummy;
59 static URLExtraData* DummyChrome() {
60 MOZ_ASSERT(sDummyChrome);
61 return sDummyChrome;
64 static void Init();
65 static void Shutdown();
67 // URLExtraData objects that shared style sheets use a sheet ID index to
68 // refer to.
69 static StaticRefPtr<URLExtraData>
70 sShared[size_t(UserAgentStyleSheetID::Count)];
72 private:
73 ~URLExtraData();
75 nsCOMPtr<nsIURI> mBaseURI;
76 nsCOMPtr<nsIReferrerInfo> mReferrerInfo;
77 nsCOMPtr<nsIPrincipal> mPrincipal;
79 bool mChromeRulesEnabled;
81 static StaticRefPtr<URLExtraData> sDummy;
82 static StaticRefPtr<URLExtraData> sDummyChrome;
85 } // namespace mozilla
87 #endif // mozilla_URLExtraData_h