URLExtraData.cpp (1662B)
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/. */ 6 7 /* thread-safe container of information for resolving url values */ 8 9 #include "mozilla/URLExtraData.h" 10 11 #include "ReferrerInfo.h" 12 #include "mozilla/NullPrincipal.h" 13 #include "nsAboutProtocolUtils.h" 14 15 namespace mozilla { 16 17 StaticRefPtr<URLExtraData> URLExtraData::sDummy; 18 StaticRefPtr<URLExtraData> URLExtraData::sDummyChrome; 19 20 /* static */ 21 void URLExtraData::Init() { 22 RefPtr<nsIURI> baseURI = NullPrincipal::CreateURI(); 23 nsCOMPtr<nsIReferrerInfo> referrerInfo = new dom::ReferrerInfo(nullptr); 24 sDummy = new URLExtraData(do_AddRef(baseURI), do_AddRef(referrerInfo), 25 NullPrincipal::CreateWithoutOriginAttributes()); 26 27 sDummyChrome = 28 new URLExtraData(baseURI.forget(), referrerInfo.forget(), 29 NullPrincipal::CreateWithoutOriginAttributes()); 30 sDummyChrome->mChromeRulesEnabled = true; 31 } 32 33 bool URLExtraData::ChromeRulesEnabled(nsIURI* aURI) { 34 if (!aURI) { 35 return false; 36 } 37 return aURI->SchemeIs("chrome") || aURI->SchemeIs("resource") || 38 (aURI->SchemeIs("about") && !NS_IsContentAccessibleAboutURI(aURI)); 39 } 40 41 /* static */ 42 void URLExtraData::Shutdown() { 43 sDummy = nullptr; 44 sDummyChrome = nullptr; 45 } 46 47 URLExtraData::~URLExtraData() = default; 48 49 StaticRefPtr<URLExtraData> 50 URLExtraData::sShared[size_t(BuiltInStyleSheet::Count)]; 51 52 } // namespace mozilla