diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /netwerk/protocol/res/SubstitutingProtocolHandler.h | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'netwerk/protocol/res/SubstitutingProtocolHandler.h')
-rw-r--r-- | netwerk/protocol/res/SubstitutingProtocolHandler.h | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/netwerk/protocol/res/SubstitutingProtocolHandler.h b/netwerk/protocol/res/SubstitutingProtocolHandler.h new file mode 100644 index 000000000..a59c5595d --- /dev/null +++ b/netwerk/protocol/res/SubstitutingProtocolHandler.h @@ -0,0 +1,107 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef SubstitutingProtocolHandler_h___ +#define SubstitutingProtocolHandler_h___ + +#include "nsISubstitutingProtocolHandler.h" + +#include "nsInterfaceHashtable.h" +#include "nsIOService.h" +#include "nsStandardURL.h" +#include "mozilla/chrome/RegistryMessageUtils.h" +#include "mozilla/Maybe.h" + +class nsIIOService; + +namespace mozilla { +namespace net { + +// +// Base class for resource://-like substitution protocols. +// +// If you add a new protocol, make sure to change nsChromeRegistryChrome +// to properly invoke CollectSubstitutions at the right time. +class SubstitutingProtocolHandler +{ +public: + SubstitutingProtocolHandler(const char* aScheme, uint32_t aFlags, bool aEnforceFileOrJar = true); + explicit SubstitutingProtocolHandler(const char* aScheme); + + NS_INLINE_DECL_REFCOUNTING(SubstitutingProtocolHandler); + NS_DECL_NON_VIRTUAL_NSIPROTOCOLHANDLER; + NS_DECL_NON_VIRTUAL_NSISUBSTITUTINGPROTOCOLHANDLER; + + bool HasSubstitution(const nsACString& aRoot) const { return mSubstitutions.Get(aRoot, nullptr); } + + nsresult CollectSubstitutions(InfallibleTArray<SubstitutionMapping>& aResources); + +protected: + virtual ~SubstitutingProtocolHandler() {} + void ConstructInternal(); + + nsresult SendSubstitution(const nsACString& aRoot, nsIURI* aBaseURI); + + // Override this in the subclass to try additional lookups after checking + // mSubstitutions. + virtual nsresult GetSubstitutionInternal(const nsACString& aRoot, nsIURI** aResult) + { + *aResult = nullptr; + return NS_ERROR_NOT_AVAILABLE; + } + + // Override this in the subclass to check for special case when resolving URIs + // _before_ checking substitutions. + virtual bool ResolveSpecialCases(const nsACString& aHost, + const nsACString& aPath, + const nsACString& aPathname, + nsACString& aResult) + { + return false; + } + + // Override this in the subclass to check for special case when opening + // channels. + virtual nsresult SubstituteChannel(nsIURI* uri, nsILoadInfo* aLoadInfo, nsIChannel** result) + { + return NS_OK; + } + + nsIIOService* IOService() { return mIOService; } + +private: + nsCString mScheme; + Maybe<uint32_t> mFlags; + nsInterfaceHashtable<nsCStringHashKey,nsIURI> mSubstitutions; + nsCOMPtr<nsIIOService> mIOService; + + // In general, we expect the principal of a document loaded from a + // substituting URI to be a codebase principal for that URI (rather than + // a principal for whatever is underneath). However, this only works if + // the protocol handler for the underlying URI doesn't set an explicit + // owner (which chrome:// does, for example). So we want to require that + // substituting URIs only map to other URIs of the same type, or to + // file:// and jar:// URIs. + // + // Enforcing this for ye olde resource:// URIs could carry compat risks, so + // we just try to enforce it on new protocols going forward. + bool mEnforceFileOrJar; +}; + +// SubstitutingURL : overrides nsStandardURL::GetFile to provide nsIFile resolution +class SubstitutingURL : public nsStandardURL +{ +public: + SubstitutingURL() : nsStandardURL(true) {} + virtual nsStandardURL* StartClone(); + virtual nsresult EnsureFile(); + NS_IMETHOD GetClassIDNoAlloc(nsCID *aCID); +}; + +} // namespace net +} // namespace mozilla + +#endif /* SubstitutingProtocolHandler_h___ */ |