Bug 1173214. Be a little more more careful with moz-icon URIs. r=bzbarsky

This commit is contained in:
Gijs Kruitbosch 2015-07-16 15:24:51 +01:00
parent c03238a338
commit 1f2429ca3f
3 changed files with 59 additions and 4 deletions

View File

@ -67,13 +67,22 @@ nsIconProtocolHandler::NewURI(const nsACString& aSpec,
nsIURI* aBaseURI,
nsIURI** result)
{
nsCOMPtr<nsIURI> uri = new nsMozIconURI();
nsCOMPtr<nsIMozIconURI> uri = new nsMozIconURI();
if (!uri) return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = uri->SetSpec(aSpec);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIURL> iconURL;
uri->GetIconURL(getter_AddRefs(iconURL));
if (iconURL) {
//XXXgijs: is just assigning a new thing here OK?
uri = new nsNestedMozIconURI();
if (!uri) return NS_ERROR_OUT_OF_MEMORY;
rv = uri->SetSpec(aSpec);
if (NS_FAILED(rv)) return rv;
}
NS_ADDREF(*result = uri);
return NS_OK;
}

View File

@ -15,6 +15,7 @@
#include "prprf.h"
#include "plstr.h"
#include <stdlib.h>
#include "nsNetUtil.h"
using namespace mozilla;
using namespace mozilla::ipc;
@ -641,3 +642,29 @@ nsMozIconURI::Deserialize(const URIParams& aParams)
return true;
}
////////////////////////////////////////////////////////////
// Nested version of nsIconURI
nsNestedMozIconURI::nsNestedMozIconURI()
{ }
nsNestedMozIconURI::~nsNestedMozIconURI()
{ }
NS_IMPL_ISUPPORTS_INHERITED(nsNestedMozIconURI, nsMozIconURI, nsINestedURI)
NS_IMETHODIMP
nsNestedMozIconURI::GetInnerURI(nsIURI** aURI)
{
*aURI = mIconURL;
NS_IF_ADDREF(*aURI);
return NS_OK;
}
NS_IMETHODIMP
nsNestedMozIconURI::GetInnermostURI(nsIURI** aURI)
{
return NS_ImplGetInnermostURI(this, aURI);
}

View File

@ -11,9 +11,10 @@
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsIIPCSerializableURI.h"
#include "nsINestedURI.h"
class nsMozIconURI final : public nsIMozIconURI
, public nsIIPCSerializableURI
class nsMozIconURI : public nsIMozIconURI
, public nsIIPCSerializableURI
{
public:
NS_DECL_THREADSAFE_ISUPPORTS
@ -40,4 +41,22 @@ protected:
// kStateStrings
};
class nsNestedMozIconURI : public nsMozIconURI
, public nsINestedURI
{
NS_DECL_ISUPPORTS_INHERITED
NS_FORWARD_NSIURI(nsMozIconURI::)
NS_FORWARD_NSIMOZICONURI(nsMozIconURI::)
NS_FORWARD_NSIIPCSERIALIZABLEURI(nsMozIconURI::)
NS_DECL_NSINESTEDURI
// nsNestedMozIconURI
nsNestedMozIconURI();
protected:
virtual ~nsNestedMozIconURI();
};
#endif // mozilla_image_decoders_icon_nsIconURI_h