mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1225384 - Change how the default resource "host names" are handled. r=michal
The meaning of resource:///, resource://app/ and resource://gre/ needs to remain constant. Unfortunately, the model of the resource protocol handler is that it is possible to set substitutions that change their meaning. So, we forbid setting overwriting the substitutions for those three special "host names". Unfortunately, with e10s, the full list of substitutions is also sent to the content process, which then sets substitutions, making it harder to know in which cases SetSubstitution is valid for those three "host names" or not. So instead of trying to find the right heuristics, use the recently added SubstitutingProtocolHandler::ResolveSpecialCases API to handle the three "host names" instead of storing them as "normal" substitutions. Still actively reject SetSubstitution with the three special "host names" so as to find issues such as bug 1224000 instead of allowing the chrome manifest entry and have it silently ignored.
This commit is contained in:
parent
a5f6f00ee0
commit
802df4ef5e
@ -21,46 +21,27 @@ using mozilla::dom::ContentParent;
|
||||
using mozilla::LogLevel;
|
||||
using mozilla::Unused;
|
||||
|
||||
#define kAPP NS_LITERAL_CSTRING("app")
|
||||
#define kGRE NS_LITERAL_CSTRING("gre")
|
||||
#define kAPP "app"
|
||||
#define kGRE "gre"
|
||||
|
||||
nsresult
|
||||
nsResProtocolHandler::Init()
|
||||
{
|
||||
nsresult rv;
|
||||
nsAutoCString appURI, greURI;
|
||||
rv = mozilla::Omnijar::GetURIString(mozilla::Omnijar::APP, appURI);
|
||||
rv = mozilla::Omnijar::GetURIString(mozilla::Omnijar::APP, mAppURI);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = mozilla::Omnijar::GetURIString(mozilla::Omnijar::GRE, greURI);
|
||||
rv = mozilla::Omnijar::GetURIString(mozilla::Omnijar::GRE, mGREURI);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
//
|
||||
// make resource:/// point to the application directory or omnijar
|
||||
//
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = NS_NewURI(getter_AddRefs(uri), appURI.Length() ? appURI : greURI);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = SetSubstitution(EmptyCString(), uri);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
//
|
||||
// make resource://app/ point to the application directory or omnijar
|
||||
//
|
||||
rv = SetSubstitution(kAPP, uri);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
//
|
||||
// make resource://gre/ point to the GRE directory
|
||||
//
|
||||
if (appURI.Length()) { // We already have greURI in uri if appURI.Length() is 0.
|
||||
rv = NS_NewURI(getter_AddRefs(uri), greURI);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
// mozilla::Omnijar::GetURIString always returns a string ending with /,
|
||||
// and we want to remove it.
|
||||
mGREURI.Truncate(mGREURI.Length() - 1);
|
||||
if (mAppURI.Length()) {
|
||||
mAppURI.Truncate(mAppURI.Length() - 1);
|
||||
} else {
|
||||
mAppURI = mGREURI;
|
||||
}
|
||||
|
||||
rv = SetSubstitution(kGRE, uri);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
//XXXbsmedberg Neil wants a resource://pchrome/ for the profile chrome dir...
|
||||
// but once I finish multiple chrome registration I'm not sure that it is needed
|
||||
|
||||
@ -100,3 +81,28 @@ nsResProtocolHandler::GetSubstitutionInternal(const nsACString& root, nsIURI **r
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool
|
||||
nsResProtocolHandler::ResolveSpecialCases(const nsACString& aHost,
|
||||
const nsACString& aPath,
|
||||
nsACString& aResult)
|
||||
{
|
||||
if (aHost.Equals("") || aHost.Equals(kAPP)) {
|
||||
aResult.Assign(mAppURI);
|
||||
} else if (aHost.Equals(kGRE)) {
|
||||
aResult.Assign(mGREURI);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
aResult.Append(aPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsResProtocolHandler::SetSubstitution(const nsACString& aRoot, nsIURI* aBaseURI)
|
||||
{
|
||||
MOZ_ASSERT(!aRoot.Equals(""));
|
||||
MOZ_ASSERT(!aRoot.Equals(kAPP));
|
||||
MOZ_ASSERT(!aRoot.Equals(kGRE));
|
||||
return SubstitutingProtocolHandler::SetSubstitution(aRoot, aBaseURI);
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ public:
|
||||
NS_DECL_NSIRESPROTOCOLHANDLER
|
||||
|
||||
NS_FORWARD_NSIPROTOCOLHANDLER(mozilla::SubstitutingProtocolHandler::)
|
||||
NS_FORWARD_NSISUBSTITUTINGPROTOCOLHANDLER(mozilla::SubstitutingProtocolHandler::)
|
||||
|
||||
nsResProtocolHandler()
|
||||
: SubstitutingProtocolHandler("resource", URI_STD | URI_IS_UI_RESOURCE | URI_IS_LOCAL_RESOURCE,
|
||||
@ -32,9 +31,33 @@ public:
|
||||
|
||||
nsresult Init();
|
||||
|
||||
NS_IMETHOD SetSubstitution(const nsACString& aRoot, nsIURI* aBaseURI) override;
|
||||
|
||||
NS_IMETHOD GetSubstitution(const nsACString& aRoot, nsIURI** aResult) override
|
||||
{
|
||||
return mozilla::SubstitutingProtocolHandler::GetSubstitution(aRoot, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHOD HasSubstitution(const nsACString& aRoot, bool* aResult) override
|
||||
{
|
||||
return mozilla::SubstitutingProtocolHandler::HasSubstitution(aRoot, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHOD ResolveURI(nsIURI *aResURI, nsACString& aResult) override
|
||||
{
|
||||
return mozilla::SubstitutingProtocolHandler::ResolveURI(aResURI, aResult);
|
||||
}
|
||||
|
||||
protected:
|
||||
nsresult GetSubstitutionInternal(const nsACString& aRoot, nsIURI** aResult) override;
|
||||
virtual ~nsResProtocolHandler() {}
|
||||
|
||||
bool ResolveSpecialCases(const nsACString& aHost, const nsACString& aPath,
|
||||
nsACString& aResult) override;
|
||||
|
||||
private:
|
||||
nsCString mAppURI;
|
||||
nsCString mGREURI;
|
||||
};
|
||||
|
||||
#endif /* nsResProtocolHandler_h___ */
|
||||
|
Loading…
Reference in New Issue
Block a user