Bug 1117337 - Properly serialize moz-icon URIs. r=bent

This commit is contained in:
Blake Kaplan 2015-02-11 15:11:33 -08:00
parent 9d7e9f8b0b
commit 8a266a93d6
5 changed files with 87 additions and 1 deletions

View File

@ -10,6 +10,10 @@ XPIDL_SOURCES += [
XPIDL_MODULE = 'imgicon'
EXPORTS += [
'nsIconURI.h',
]
UNIFIED_SOURCES += [
'nsIconModule.cpp',
'nsIconProtocolHandler.cpp',
@ -20,6 +24,8 @@ FAIL_ON_WARNINGS = True
FINAL_LIBRARY = 'xul'
include('/ipc/chromium/chromium-config.mozbuild')
platform = None
if CONFIG['MOZ_WIDGET_GTK']:

View File

@ -1,4 +1,5 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: set sw=2 sts=2 ts=2 et 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
@ -6,6 +7,8 @@
#include "mozilla/ArrayUtils.h"
#include "mozilla/ipc/URIUtils.h"
#include "nsIconURI.h"
#include "nsNetUtil.h"
#include "nsIIOService.h"
@ -15,6 +18,7 @@
#include <stdlib.h>
using namespace mozilla;
using namespace mozilla::ipc;
#define DEFAULT_IMAGE_SIZE 16
@ -59,7 +63,7 @@ nsMozIconURI::nsMozIconURI()
nsMozIconURI::~nsMozIconURI()
{ }
NS_IMPL_ISUPPORTS(nsMozIconURI, nsIMozIconURI, nsIURI)
NS_IMPL_ISUPPORTS(nsMozIconURI, nsIMozIconURI, nsIURI, nsIIPCSerializableURI)
#define MOZICON_SCHEME "moz-icon:"
#define MOZICON_SCHEME_LEN (sizeof(MOZICON_SCHEME) - 1)
@ -582,3 +586,59 @@ nsMozIconURI::GetIconState(nsACString& aState)
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsIIPCSerializableURI methods:
void
nsMozIconURI::Serialize(URIParams& aParams)
{
IconURIParams params;
if (mIconURL) {
URIParams iconURLParams;
SerializeURI(mIconURL, iconURLParams);
if (iconURLParams.type() == URIParams::T__None) {
// Serialization failed, bail.
return;
}
params.uri() = iconURLParams;
} else {
params.uri() = void_t();
}
params.size() = mSize;
params.fileName() = mFileName;
params.stockIcon() = mStockIcon;
params.iconSize() = mIconSize;
params.iconState() = mIconState;
aParams = params;
}
bool
nsMozIconURI::Deserialize(const URIParams& aParams)
{
if (aParams.type() != URIParams::TIconURIParams) {
MOZ_ASSERT_UNREACHABLE("Received unknown URI from other process!");
return false;
}
const IconURIParams& params = aParams.get_IconURIParams();
if (params.uri().type() != OptionalURIParams::Tvoid_t) {
nsCOMPtr<nsIURI> uri = DeserializeURI(params.uri().get_URIParams());
mIconURL = do_QueryInterface(uri);
if (!mIconURL) {
MOZ_ASSERT_UNREACHABLE("bad nsIURI passed");
return false;
}
}
mSize = params.size();
mContentType = params.contentType();
mFileName = params.fileName();
mStockIcon = params.stockIcon();
mIconSize = params.iconSize();
mIconState = params.iconState();
return true;
}

View File

@ -10,6 +10,7 @@
#include "nsIIconURI.h"
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsIIPCSerializableURI.h"
#define NS_MOZICONURI_CID \
{ \
@ -20,11 +21,13 @@
}
class nsMozIconURI MOZ_FINAL : public nsIMozIconURI
, public nsIIPCSerializableURI
{
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIURI
NS_DECL_NSIMOZICONURI
NS_DECL_NSIIPCSERIALIZABLEURI
// nsMozIconURI
nsMozIconURI();

View File

@ -53,11 +53,23 @@ struct JARURIParams
nsCString charset;
};
struct IconURIParams
{
OptionalURIParams uri;
uint32_t size;
nsCString contentType;
nsCString fileName;
nsCString stockIcon;
int32_t iconSize;
int32_t iconState;
};
union URIParams
{
SimpleURIParams;
StandardURLParams;
JARURIParams;
IconURIParams;
};
union OptionalURIParams

View File

@ -12,6 +12,7 @@
#include "nsDebug.h"
#include "nsID.h"
#include "nsJARURI.h"
#include "nsIconURI.h"
#include "nsNetCID.h"
#include "nsNetUtil.h"
#include "nsThreadUtils.h"
@ -84,6 +85,10 @@ DeserializeURI(const URIParams& aParams)
serializable = do_CreateInstance(kJARURICID);
break;
case URIParams::TIconURIParams:
serializable = new nsMozIconURI();
break;
default:
MOZ_CRASH("Unknown params!");
}