2009-09-21 19:02:15 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set sw=2 ts=8 et tw=80 : */
|
2009-06-29 11:38:29 -07:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla IPC.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Ben Turner <bent.mozilla@gmail.com>.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef __IPC_GLUE_IPCMESSAGEUTILS_H__
|
|
|
|
#define __IPC_GLUE_IPCMESSAGEUTILS_H__
|
|
|
|
|
|
|
|
#include "chrome/common/ipc_message_utils.h"
|
|
|
|
|
|
|
|
#include "prtypes.h"
|
|
|
|
#include "nsStringGlue.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
|
2009-07-13 09:14:56 -07:00
|
|
|
#include "IPCMessageStart.h"
|
2009-06-29 11:38:29 -07:00
|
|
|
|
2009-10-12 12:04:40 -07:00
|
|
|
COMPILE_ASSERT(LastMsgIndex <= 64, need_to_update_IPC_MESSAGE_MACRO);
|
2009-06-29 11:38:29 -07:00
|
|
|
|
|
|
|
namespace IPC {
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ParamTraits<nsACString>
|
|
|
|
{
|
|
|
|
typedef nsACString paramType;
|
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
2009-09-21 19:02:15 -07:00
|
|
|
bool isVoid = aParam.IsVoid();
|
|
|
|
aMsg->WriteBool(isVoid);
|
|
|
|
|
|
|
|
if (isVoid)
|
|
|
|
// represents a NULL pointer
|
|
|
|
return;
|
|
|
|
|
2009-06-29 11:38:29 -07:00
|
|
|
PRUint32 length = aParam.Length();
|
|
|
|
WriteParam(aMsg, length);
|
|
|
|
aMsg->WriteBytes(aParam.BeginReading(), length);
|
|
|
|
}
|
|
|
|
|
2009-07-29 14:12:15 -07:00
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
2009-06-29 11:38:29 -07:00
|
|
|
{
|
2009-09-21 19:02:15 -07:00
|
|
|
bool isVoid;
|
|
|
|
if (!aMsg->ReadBool(aIter, &isVoid))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (isVoid) {
|
|
|
|
aResult->SetIsVoid(PR_TRUE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-06-29 11:38:29 -07:00
|
|
|
PRUint32 length;
|
|
|
|
if (ReadParam(aMsg, aIter, &length)) {
|
|
|
|
const char* buf;
|
|
|
|
if (aMsg->ReadBytes(aIter, &buf, length)) {
|
2009-07-29 14:12:15 -07:00
|
|
|
aResult->Assign(buf, length);
|
2009-06-29 11:38:29 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
|
|
{
|
2009-09-21 19:02:15 -07:00
|
|
|
if (aParam.IsVoid())
|
|
|
|
aLog->append(L"(NULL)");
|
|
|
|
else
|
|
|
|
aLog->append(UTF8ToWide(aParam.BeginReading()));
|
2009-06-29 11:38:29 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ParamTraits<nsAString>
|
|
|
|
{
|
|
|
|
typedef nsAString paramType;
|
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
2009-09-21 19:02:15 -07:00
|
|
|
bool isVoid = aParam.IsVoid();
|
|
|
|
aMsg->WriteBool(isVoid);
|
|
|
|
|
|
|
|
if (isVoid)
|
|
|
|
// represents a NULL pointer
|
|
|
|
return;
|
|
|
|
|
2009-06-29 11:38:29 -07:00
|
|
|
PRUint32 length = aParam.Length();
|
|
|
|
WriteParam(aMsg, length);
|
|
|
|
aMsg->WriteBytes(aParam.BeginReading(), length * sizeof(PRUnichar));
|
|
|
|
}
|
|
|
|
|
2009-07-29 14:12:15 -07:00
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
2009-06-29 11:38:29 -07:00
|
|
|
{
|
2009-09-21 19:02:15 -07:00
|
|
|
bool isVoid;
|
|
|
|
if (!aMsg->ReadBool(aIter, &isVoid))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (isVoid) {
|
|
|
|
aResult->SetIsVoid(PR_TRUE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-06-29 11:38:29 -07:00
|
|
|
PRUint32 length;
|
|
|
|
if (ReadParam(aMsg, aIter, &length)) {
|
|
|
|
const PRUnichar* buf;
|
|
|
|
if (aMsg->ReadBytes(aIter, reinterpret_cast<const char**>(&buf),
|
|
|
|
length * sizeof(PRUnichar))) {
|
2009-07-29 14:12:15 -07:00
|
|
|
aResult->Assign(buf, length);
|
2009-06-29 11:38:29 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
|
|
{
|
2009-09-21 19:02:15 -07:00
|
|
|
if (aParam.IsVoid())
|
|
|
|
aLog->append(L"(NULL)");
|
|
|
|
else {
|
2009-06-29 11:38:29 -07:00
|
|
|
#ifdef WCHAR_T_IS_UTF16
|
2009-09-21 19:02:15 -07:00
|
|
|
aLog->append(reinterpret_cast<const wchar_t*>(aParam.BeginReading()));
|
2009-06-29 11:38:29 -07:00
|
|
|
#else
|
2009-09-21 19:02:15 -07:00
|
|
|
PRUint32 length = aParam.Length();
|
|
|
|
for (PRUint32 index = 0; index < length; index++) {
|
|
|
|
aLog->push_back(std::wstring::value_type(aParam[index]));
|
|
|
|
}
|
2009-06-29 11:38:29 -07:00
|
|
|
#endif
|
2009-09-21 19:02:15 -07:00
|
|
|
}
|
2009-06-29 11:38:29 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-07-29 14:12:15 -07:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<nsCString> : ParamTraits<nsACString>
|
|
|
|
{
|
|
|
|
typedef nsCString paramType;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ParamTraits<nsString> : ParamTraits<nsAString>
|
|
|
|
{
|
|
|
|
typedef nsString paramType;
|
|
|
|
};
|
|
|
|
|
2009-06-29 11:38:29 -07:00
|
|
|
template <typename E>
|
|
|
|
struct ParamTraits<nsTArray<E> >
|
|
|
|
{
|
|
|
|
typedef nsTArray<E> paramType;
|
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
PRUint32 length = aParam.Length();
|
|
|
|
WriteParam(aMsg, length);
|
|
|
|
for (PRUint32 index = 0; index < length; index++) {
|
|
|
|
WriteParam(aMsg, aParam[index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-29 14:12:15 -07:00
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
2009-06-29 11:38:29 -07:00
|
|
|
{
|
|
|
|
PRUint32 length;
|
|
|
|
if (!ReadParam(aMsg, aIter, &length)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-10-19 14:06:13 -07:00
|
|
|
for (PRUint32 index = 0; index < length; index++) {
|
|
|
|
E* element = aResult->AppendElement();
|
|
|
|
if (!(element && ReadParam(aMsg, aIter, element))) {
|
2009-08-05 15:36:33 -07:00
|
|
|
return false;
|
2009-06-29 11:38:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
|
|
{
|
|
|
|
for (PRUint32 index = 0; index < aParam.Length(); index++) {
|
|
|
|
if (index) {
|
|
|
|
aLog->append(L" ");
|
|
|
|
}
|
|
|
|
LogParam(aParam[index], aLog);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace IPC */
|
|
|
|
|
|
|
|
#endif /* __IPC_GLUE_IPCMESSAGEUTILS_H__ */
|