2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
1999-11-23 15:13:33 +03:00
|
|
|
|
2010-03-11 08:33:00 +03:00
|
|
|
#include "mozilla/chrome/RegistryMessageUtils.h"
|
2014-10-07 21:29:40 +04:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
|
|
|
#include "mozilla/unused.h"
|
2010-03-11 08:33:00 +03:00
|
|
|
|
1999-11-23 15:13:33 +03:00
|
|
|
#include "nsResProtocolHandler.h"
|
2000-06-09 11:51:13 +04:00
|
|
|
#include "nsIIOService.h"
|
|
|
|
#include "nsIFile.h"
|
2015-07-07 05:17:00 +03:00
|
|
|
#include "nsNetCID.h"
|
2001-09-10 04:42:50 +04:00
|
|
|
#include "nsNetUtil.h"
|
2002-09-13 23:32:45 +04:00
|
|
|
#include "nsURLHelper.h"
|
2007-02-26 19:57:48 +03:00
|
|
|
#include "nsEscape.h"
|
1999-11-23 15:13:33 +03:00
|
|
|
|
2010-06-23 23:59:59 +04:00
|
|
|
#include "mozilla/Omnijar.h"
|
|
|
|
|
2014-10-07 21:29:40 +04:00
|
|
|
using mozilla::dom::ContentParent;
|
2015-06-04 01:25:57 +03:00
|
|
|
using mozilla::LogLevel;
|
2015-11-02 08:53:26 +03:00
|
|
|
using mozilla::Unused;
|
2014-10-07 21:29:40 +04: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.
Additionally, make GetSubstitution return the URIs for the three special
"host names" through GetSubstitutionInternal, replacing what was originally
added in bug 257162. Those changes from bug 257162 relied on the
resource:app string being handled by nsXREDirProvider::GetFile, but that was
removed in bug 620931, effectively making that code now in
GetSubstitutionInternal useless.
2015-11-17 11:21:03 +03:00
|
|
|
#define kAPP "app"
|
|
|
|
#define kGRE "gre"
|
2009-10-08 22:19:07 +04:00
|
|
|
|
2001-09-20 05:32:16 +04:00
|
|
|
nsresult
|
2003-09-13 21:55:56 +04:00
|
|
|
nsResProtocolHandler::Init()
|
1999-11-23 15:13:33 +03:00
|
|
|
{
|
2001-09-20 05:32:16 +04:00
|
|
|
nsresult rv;
|
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.
Additionally, make GetSubstitution return the URIs for the three special
"host names" through GetSubstitutionInternal, replacing what was originally
added in bug 257162. Those changes from bug 257162 relied on the
resource:app string being handled by nsXREDirProvider::GetFile, but that was
removed in bug 620931, effectively making that code now in
GetSubstitutionInternal useless.
2015-11-17 11:21:03 +03:00
|
|
|
rv = mozilla::Omnijar::GetURIString(mozilla::Omnijar::APP, mAppURI);
|
2011-02-25 14:53:36 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
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.
Additionally, make GetSubstitution return the URIs for the three special
"host names" through GetSubstitutionInternal, replacing what was originally
added in bug 257162. Those changes from bug 257162 relied on the
resource:app string being handled by nsXREDirProvider::GetFile, but that was
removed in bug 620931, effectively making that code now in
GetSubstitutionInternal useless.
2015-11-17 11:21:03 +03:00
|
|
|
rv = mozilla::Omnijar::GetURIString(mozilla::Omnijar::GRE, mGREURI);
|
2011-02-25 14:53:36 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-09-13 21:55:56 +04: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.
Additionally, make GetSubstitution return the URIs for the three special
"host names" through GetSubstitutionInternal, replacing what was originally
added in bug 257162. Those changes from bug 257162 relied on the
resource:app string being handled by nsXREDirProvider::GetFile, but that was
removed in bug 620931, effectively making that code now in
GetSubstitutionInternal useless.
2015-11-17 11:21:03 +03:00
|
|
|
// 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;
|
2011-02-25 14:53:36 +03:00
|
|
|
}
|
|
|
|
|
2003-09-13 21:55:56 +04:00
|
|
|
//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
|
2004-09-07 22:59:07 +04:00
|
|
|
|
2008-10-01 09:15:58 +04:00
|
|
|
// XXX dveditz: resource://pchrome/ defeats profile directory salting
|
|
|
|
// if web content can load it. Tread carefully.
|
|
|
|
|
2004-09-07 22:59:07 +04:00
|
|
|
return rv;
|
1999-11-23 15:13:33 +03:00
|
|
|
}
|
|
|
|
|
2001-09-20 05:32:16 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// nsResProtocolHandler::nsISupports
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2015-07-17 01:50:07 +03:00
|
|
|
NS_IMPL_QUERY_INTERFACE(nsResProtocolHandler, nsIResProtocolHandler,
|
|
|
|
nsISubstitutingProtocolHandler, nsIProtocolHandler,
|
|
|
|
nsISupportsWeakReference)
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsResProtocolHandler, SubstitutingProtocolHandler)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsResProtocolHandler, SubstitutingProtocolHandler)
|
2008-10-01 09:15:58 +04:00
|
|
|
|
2015-07-17 01:50:07 +03:00
|
|
|
nsresult
|
|
|
|
nsResProtocolHandler::GetSubstitutionInternal(const nsACString& root, nsIURI **result)
|
1999-11-23 15:13:33 +03: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.
Additionally, make GetSubstitution return the URIs for the three special
"host names" through GetSubstitutionInternal, replacing what was originally
added in bug 257162. Those changes from bug 257162 relied on the
resource:app string being handled by nsXREDirProvider::GetFile, but that was
removed in bug 620931, effectively making that code now in
GetSubstitutionInternal useless.
2015-11-17 11:21:03 +03:00
|
|
|
nsAutoCString uri;
|
2004-09-07 22:59:07 +04:00
|
|
|
|
2016-07-20 07:54:00 +03:00
|
|
|
if (!ResolveSpecialCases(root, NS_LITERAL_CSTRING("/"), uri)) {
|
2004-09-07 22:59:07 +04:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
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.
Additionally, make GetSubstitution return the URIs for the three special
"host names" through GetSubstitutionInternal, replacing what was originally
added in bug 257162. Those changes from bug 257162 relied on the
resource:app string being handled by nsXREDirProvider::GetFile, but that was
removed in bug 620931, effectively making that code now in
GetSubstitutionInternal useless.
2015-11-17 11:21:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_NewURI(result, uri);
|
|
|
|
}
|
2004-09-07 22:59:07 +04: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.
Additionally, make GetSubstitution return the URIs for the three special
"host names" through GetSubstitutionInternal, replacing what was originally
added in bug 257162. Those changes from bug 257162 relied on the
resource:app string being handled by nsXREDirProvider::GetFile, but that was
removed in bug 620931, effectively making that code now in
GetSubstitutionInternal useless.
2015-11-17 11:21:03 +03:00
|
|
|
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);
|
1999-11-23 15:13:33 +03:00
|
|
|
}
|