Backed out changeset 1b14354719c0 (bug 1895254) for causing bustages on NavigationTra...
[gecko.git] / layout / style / URLExtraData.h
blobc63cbc4ca14c2c0ef1bfb0d7bc491a28cdc11536
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 "nsCOMPtr.h"
17 #include "nsIPrincipal.h"
18 #include "nsIReferrerInfo.h"
19 #include "nsIURI.h"
21 namespace mozilla {
23 struct URLExtraData {
24 static bool ChromeRulesEnabled(nsIURI* aURI);
26 URLExtraData(already_AddRefed<nsIURI> aBaseURI,
27 already_AddRefed<nsIReferrerInfo> aReferrerInfo,
28 already_AddRefed<nsIPrincipal> aPrincipal)
29 : mBaseURI(std::move(aBaseURI)),
30 mReferrerInfo(std::move(aReferrerInfo)),
31 mPrincipal(std::move(aPrincipal)) {
32 MOZ_ASSERT(mBaseURI);
33 MOZ_ASSERT(mPrincipal);
34 MOZ_ASSERT(mReferrerInfo);
35 // When we hold the URI data of a style sheet, referrer is always
36 // equal to the sheet URI.
37 nsCOMPtr<nsIURI> referrer = mReferrerInfo->GetOriginalReferrer();
38 mChromeRulesEnabled = ChromeRulesEnabled(referrer);
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