--- a/dom/ipc/IFrameEmbedding.ipdl
+++ b/dom/ipc/IFrameEmbedding.ipdl
@@ -1,15 +1,15 @@
using MagicWindowHandle;
using PRUint32;
-sync protocol IFrameEmbedding
+protocol IFrameEmbedding
{
child:
- sync init(MagicWindowHandle parentWidget);
+ init(MagicWindowHandle parentWidget);
- loadURL(String uri);
+ loadURL(nsCString uri);
move(PRUint32 x,
PRUint32 y,
PRUint32 width,
PRUint32 height);
};
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -68,21 +68,21 @@ TabChild::Recvinit(const MagicWindowHand
mWebNav = do_QueryInterface(webBrowser);
// TODObz: create and embed a window!
//return NS_ERROR_NOT_IMPLEMENTED;
return NS_OK;
}
nsresult
-TabChild::RecvloadURL(const String& uri)
+TabChild::RecvloadURL(const nsCString& uri)
{
- printf("loading %s, %d\n", uri.c_str(), NS_IsMainThread());
+ printf("loading %s, %d\n", uri.get(), NS_IsMainThread());
- return mWebNav->LoadURI(NS_ConvertUTF8toUTF16(uri.c_str()).get(),
+ return mWebNav->LoadURI(NS_ConvertUTF8toUTF16(uri).get(),
nsIWebNavigation::LOAD_FLAGS_NONE,
NULL, NULL, NULL);
}
nsresult
TabChild::Recvmove(const PRUint32& x,
const PRUint32& y,
const PRUint32& width,
--- a/dom/ipc/TabChild.h
+++ b/dom/ipc/TabChild.h
@@ -10,27 +10,24 @@
#include "nsCOMPtr.h"
namespace mozilla {
namespace tabs {
class TabChild
: public IFrameEmbeddingProtocolChild
{
-private:
- typedef mozilla::ipc::String String;
-
public:
TabChild();
virtual ~TabChild();
bool Init(MessageLoop* aIOLoop, IPC::Channel* aChannel);
virtual nsresult Recvinit(const MagicWindowHandle& parentWidget);
- virtual nsresult RecvloadURL(const String& uri);
+ virtual nsresult RecvloadURL(const nsCString& uri);
virtual nsresult Recvmove(const PRUint32& x,
const PRUint32& y,
const PRUint32& width,
const PRUint32& height);
private:
MagicWindowHandle mWidget;
nsCOMPtr<nsIWebNavigation> mWebNav;
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -23,17 +23,17 @@ TabParent::~TabParent()
}
void
TabParent::LoadURL(nsIURI* aURI)
{
nsCString spec;
aURI->GetSpec(spec);
- SendloadURL(spec.get());
+ SendloadURL(spec);
}
void
TabParent::Move(PRUint32 x, PRUint32 y, PRUint32 width, PRUint32 height)
{
Sendmove(x, y, width, height);
}
--- a/dom/plugins/NPAPI.ipdl
+++ b/dom/plugins/NPAPI.ipdl
@@ -1,29 +1,31 @@
include "npapi.h";
+include "nsTArray.h";
include protocol "NPP.ipdl";
//include protocol "NPObject.ipdl";
using NPError;
+using nsTArray<nsCString>;
namespace mozilla {
namespace plugins {
rpc protocol NPAPI
{
manages NPP;
// manages NPObject;
child:
rpc NP_Initialize() returns (NPError rv);
- rpc NPP(String aMimeType,
- uint16_t aMode,
- StringArray aNames,
- StringArray aValues) returns (NPError rv);
+ rpc NPP(nsCString aMimeType,
+ uint16_t aMode,
+ nsTArray<nsCString> aNames,
+ nsTArray<nsCString> aValues) returns (NPError rv);
rpc ~NPP() returns (NPError rv);
// rpc in TradeNPPsForSomeReason(NPP n) returns (NPP n2);
};
} // namespace plugins
} // namespace mozilla
--- a/dom/plugins/NPAPIPluginChild.cpp
+++ b/dom/plugins/NPAPIPluginChild.cpp
@@ -908,74 +908,65 @@ NPAPIPluginChild::AnswerNP_Initialize(NP
*_retval = mInitializeFunc(&sBrowserFuncs);
return NS_OK;
#else
# error Please implement me for your platform
#endif
}
NPPProtocolChild*
-NPAPIPluginChild::NPPConstructor(const String& aMimeType,
+NPAPIPluginChild::NPPConstructor(const nsCString& aMimeType,
const uint16_t& aMode,
- const StringArray& aNames,
- const StringArray& aValues,
+ const nsTArray<nsCString>& aNames,
+ const nsTArray<nsCString>& aValues,
NPError* rv)
{
_MOZ_LOG(__FUNCTION__);
// create our wrapper instance
nsAutoPtr<NPPInstanceChild> childInstance(
new NPPInstanceChild(&mFunctions));
if (!childInstance->Initialize()) {
*rv = NPERR_GENERIC_ERROR;
return 0;
}
// unpack the arguments into a C format
- int argc = aNames.size();
- NS_ASSERTION(argc == (int) aValues.size(),
+ int argc = aNames.Length();
+ NS_ASSERTION(argc == (int) aValues.Length(),
"argn.length != argv.length");
- char** argn = (char**) calloc(1 + argc, sizeof(char*));
- char** argv = (char**) calloc(1 + argc, sizeof(char*));
+ nsAutoArrayPtr<char*> argn(new char*[1 + argc]);
+ nsAutoArrayPtr<char*> argv(new char*[1 + argc]);
argn[argc] = 0;
argv[argc] = 0;
printf ("(plugin args: ");
for (int i = 0; i < argc; ++i) {
- argn[i] = strdup(aNames[i].c_str());
- argv[i] = strdup(aValues[i].c_str());
+ argn[i] = const_cast<char*>(aNames[i].get());
+ argv[i] = const_cast<char*>(aValues[i].get());
printf("%s=%s, ", argn[i], argv[i]);
}
printf(")\n");
NPP npp = childInstance->GetNPP();
// FIXME/cjones: use SAFE_CALL stuff
- *rv = mFunctions.newp((char*) aMimeType.c_str(),
+ *rv = mFunctions.newp((char*)aMimeType.get(),
npp,
aMode,
argc,
argn,
argv,
0);
if (NPERR_NO_ERROR != *rv) {
- childInstance = 0;
- goto out;
+ return nsnull;
}
-out:
printf ("[NPAPIPluginChild] %s: returning %hd\n", __FUNCTION__, *rv);
- for (int i = 0; i < argc; ++i) {
- free(argn[i]);
- free(argv[i]);
- }
- free(argn);
- free(argv);
-
return childInstance.forget();
}
nsresult
NPAPIPluginChild::NPPDestructor(NPPProtocolChild* actor, NPError* rv)
{
_MOZ_LOG(__FUNCTION__);
--- a/dom/plugins/NPAPIPluginChild.h
+++ b/dom/plugins/NPAPIPluginChild.h
@@ -96,20 +96,20 @@ namespace plugins {
class NPAPIPluginChild : public NPAPIProtocolChild
{
protected:
// Implement the NPAPIProtocolChild interface
virtual nsresult AnswerNP_Initialize(NPError* rv);
virtual NPPProtocolChild* NPPConstructor(
- const String& aMimeType,
+ const nsCString& aMimeType,
const uint16_t& aMode,
- const StringArray& aNames,
- const StringArray& aValues,
+ const nsTArray<nsCString>& aNames,
+ const nsTArray<nsCString>& aValues,
NPError* rv);
virtual nsresult NPPDestructor(
NPPProtocolChild* actor,
NPError* rv);
public:
NPAPIPluginChild();
--- a/dom/plugins/NPAPIPluginParent.cpp
+++ b/dom/plugins/NPAPIPluginParent.cpp
@@ -66,20 +66,20 @@ NPAPIPluginParent::NPAPIPluginParent(con
NPAPIPluginParent::~NPAPIPluginParent()
{
_MOZ_LOG(" (closing Shim ...)");
delete mShim;
}
NPPProtocolParent*
-NPAPIPluginParent::NPPConstructor(const String& aMimeType,
+NPAPIPluginParent::NPPConstructor(const nsCString& aMimeType,
const uint16_t& aMode,
- const StringArray& aNames,
- const StringArray& aValues,
+ const nsTArray<nsCString>& aNames,
+ const nsTArray<nsCString>& aValues,
NPError* rv)
{
_MOZ_LOG(__FUNCTION__);
return new NPPInstanceParent(mNPNIface);
}
nsresult
NPAPIPluginParent::NPPDestructor(NPPProtocolParent* __a,
@@ -149,37 +149,40 @@ NPAPIPluginParent::NP_GetEntryPoints(NPP
NS_ASSERTION(nppIface, "Null pointer!");
SetPluginFuncs(nppIface);
return NPERR_NO_ERROR;
}
#endif
NPError
-NPAPIPluginParent::NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode,
- int16_t argc, char* argn[], char* argv[],
+NPAPIPluginParent::NPP_New(NPMIMEType pluginType,
+ NPP instance,
+ uint16_t mode,
+ int16_t argc,
+ char* argn[],
+ char* argv[],
NPSavedData* saved)
{
_MOZ_LOG(__FUNCTION__);
// create the instance on the other side
- StringArray names;
- StringArray values;
+ nsTArray<nsCString> names;
+ nsTArray<nsCString> values;
for (int i = 0; i < argc; ++i) {
- names.push_back(argn[i]);
- values.push_back(argv[i]);
+ names.AppendElement(nsDependentCString(argn[i]));
+ values.AppendElement(nsDependentCString(argv[i]));
}
NPError prv;
nsAutoPtr<NPPInstanceParent> parentInstance(
- static_cast<NPPInstanceParent*>(CallNPPConstructor(pluginType,
- mode, names,
- values,
- &prv)));
+ static_cast<NPPInstanceParent*>(
+ CallNPPConstructor(nsDependentCString(pluginType), mode, names,
+ values, &prv)));
printf ("[NPAPIPluginParent] %s: got return value %hd\n", __FUNCTION__,
prv);
if (NPERR_NO_ERROR != prv)
return prv;
NS_ASSERTION(parentInstance,
"if there's no parentInstance, there should be an error");
--- a/dom/plugins/NPAPIPluginParent.h
+++ b/dom/plugins/NPAPIPluginParent.h
@@ -79,20 +79,20 @@ namespace plugins {
*/
class NPAPIPluginParent : public NPAPIProtocolParent
{
private:
typedef mozilla::SharedLibrary SharedLibrary;
protected:
NPPProtocolParent* NPPConstructor(
- const String& aMimeType,
+ const nsCString& aMimeType,
const uint16_t& aMode,
- const StringArray& aNames,
- const StringArray& aValues,
+ const nsTArray<nsCString>& aNames,
+ const nsTArray<nsCString>& aValues,
NPError* rv);
virtual nsresult NPPDestructor(
NPPProtocolParent* __a,
NPError* rv);
public:
NPAPIPluginParent(const char* aFilePath);
--- a/dom/plugins/NPP.ipdl
+++ b/dom/plugins/NPP.ipdl
@@ -12,16 +12,16 @@ namespace plugins {
rpc protocol NPP
{
manager NPAPI;
// manages NPStream;
child:
rpc NPP_SetWindow(NPWindow window) returns (NPError rv);
- rpc NPP_GetValue(String key) returns (String value);
+ rpc NPP_GetValue(nsString key) returns (nsString value);
parent:
- rpc NPN_GetValue(String key) returns (String value);
+ rpc NPN_GetValue(nsString key) returns (nsString value);
};
} // namespace plugins
} // namespace mozilla
--- a/dom/plugins/NPPInstanceChild.cpp
+++ b/dom/plugins/NPPInstanceChild.cpp
@@ -124,17 +124,17 @@ NPPInstanceChild::NPN_GetValue(NPNVariab
default:
printf(" unhandled var %s\n", NPNVariableToString(aVar));
return NPERR_GENERIC_ERROR;
}
}
nsresult
-NPPInstanceChild::AnswerNPP_GetValue(const String& key, String* value)
+NPPInstanceChild::AnswerNPP_GetValue(const nsString& key, nsString* value)
{
return NPERR_GENERIC_ERROR;
}
nsresult
NPPInstanceChild::AnswerNPP_SetWindow(const NPWindow& aWindow, NPError* rv)
{
printf("[NPPInstanceChild] NPP_SetWindow(%lx, %d, %d)\n",
--- a/dom/plugins/NPPInstanceChild.h
+++ b/dom/plugins/NPPInstanceChild.h
@@ -57,17 +57,17 @@ class NPPInstanceChild : public NPPProto
UINT message,
WPARAM wParam,
LPARAM lParam);
#endif
protected:
virtual nsresult AnswerNPP_SetWindow(const NPWindow& window, NPError* rv);
- virtual nsresult AnswerNPP_GetValue(const String& key, String* value);
+ virtual nsresult AnswerNPP_GetValue(const nsString& key, nsString* value);
public:
NPPInstanceChild(const NPPluginFuncs* aPluginIface) :
mPluginIface(aPluginIface)
#if defined(OS_LINUX)
, mPlug(0)
#elif defined(OS_WIN)
, mPluginWindowHWND(0)
--- a/dom/plugins/NPPInstanceParent.h
+++ b/dom/plugins/NPPInstanceParent.h
@@ -60,17 +60,17 @@ public:
}
virtual ~NPPInstanceParent()
{
}
- virtual nsresult AnswerNPN_GetValue(const String& in, String* out)
+ virtual nsresult AnswerNPN_GetValue(const nsString& in, nsString* out)
{
return NS_OK;
}
NPError NPP_SetWindow(NPWindow* aWindow);
NPError NPP_GetValue(NPPVariable variable, void *ret_value);
NPError NPP_SetValue(NPNVariable variable, void *value)
--- a/ipc/glue/IPCMessageUtils.h
+++ b/ipc/glue/IPCMessageUtils.h
@@ -44,84 +44,35 @@
#include "nsTArray.h"
#include "IPCMessageStart.h"
COMPILE_ASSERT(LastMsgIndex <= 16, need_to_update_IPC_MESSAGE_MACRO);
namespace IPC {
-
-// FIXME/cjones: PRInt16 traits had a stack corruption bug that took
-// a long time to find. putting these on ice until we need them
-#if 0
-
-template <>
-struct ParamTraits<PRUint8>
-{
- typedef PRUint8 paramType;
-
- static void Write(Message* aMsg, const paramType& aParam)
- {
- aMsg->WriteBytes(&aParam, sizeof(aParam));
- }
-
- static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
- {
- return aMsg->ReadBytes(aIter, reinterpret_cast<const char**>(aResult),
- sizeof(*aResult));
- }
-
- static void Log(const paramType& aParam, std::wstring* aLog)
- {
- aLog->append(StringPrintf(L"%u", aParam));
- }
-};
-
-template <>
-struct ParamTraits<PRInt8>
-{
- typedef PRInt8 paramType;
-
- static void Write(Message* aMsg, const paramType& aParam)
- {
- aMsg->WriteBytes(&aParam, sizeof(aParam));
- }
-
- static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
- {
- return aMsg->ReadBytes(aIter, reinterpret_cast<const char**>(aResult),
- sizeof(*aResult));
- }
-
- static void Log(const paramType& aParam, std::wstring* aLog)
- {
- aLog->append(StringPrintf(L"%d", aParam));
- }
-};
-
template <>
struct ParamTraits<nsACString>
{
typedef nsACString paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
PRUint32 length = aParam.Length();
WriteParam(aMsg, length);
aMsg->WriteBytes(aParam.BeginReading(), length);
}
- static bool Read(const Message* aMsg, void** aIter, paramType& aResult)
+ static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
PRUint32 length;
if (ReadParam(aMsg, aIter, &length)) {
const char* buf;
if (aMsg->ReadBytes(aIter, &buf, length)) {
- aResult.Assign(buf, length);
+ aResult->Assign(buf, length);
return true;
}
}
return false;
}
static void Log(const paramType& aParam, std::wstring* aLog)
{
@@ -136,24 +87,24 @@ struct ParamTraits<nsAString>
static void Write(Message* aMsg, const paramType& aParam)
{
PRUint32 length = aParam.Length();
WriteParam(aMsg, length);
aMsg->WriteBytes(aParam.BeginReading(), length * sizeof(PRUnichar));
}
- static bool Read(const Message* aMsg, void** aIter, paramType& aResult)
+ static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
PRUint32 length;
if (ReadParam(aMsg, aIter, &length)) {
const PRUnichar* buf;
if (aMsg->ReadBytes(aIter, reinterpret_cast<const char**>(&buf),
length * sizeof(PRUnichar))) {
- aResult.Assign(buf, length);
+ aResult->Assign(buf, length);
return true;
}
}
return false;
}
static void Log(const paramType& aParam, std::wstring* aLog)
{
@@ -163,54 +114,66 @@ struct ParamTraits<nsAString>
PRUint32 length = aParam.Length();
for (PRUint32 index = 0; index < length; index++) {
aLog->push_back(std::wstring::value_type(aParam[index]));
}
#endif
}
};
+template <>
+struct ParamTraits<nsCString> : ParamTraits<nsACString>
+{
+ typedef nsCString paramType;
+};
+
+template <>
+struct ParamTraits<nsString> : ParamTraits<nsAString>
+{
+ typedef nsString paramType;
+};
+
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]);
}
}
- static bool Read(const Message* aMsg, void** aIter, paramType& aResult)
+ static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
PRUint32 length;
if (!ReadParam(aMsg, aIter, &length)) {
return false;
}
// Check to make sure the message is valid before requesting a huge chunk
// of memory.
if (aMsg->IteratorHasRoomFor(*aIter, length * sizeof(E)) &&
- aResult.SetCapacity(length)) {
+ aResult->SetCapacity(length)) {
for (PRUint32 index = 0; index < length; index++) {
if (!ReadParam(aMsg, aIter, &aResult[index])) {
return false;
}
}
}
else {
// Push elements individually.
- aResult.Clear();
+ aResult->Clear();
E element;
for (PRUint32 index = 0; index < length; index++) {
if (!ReadParam(aMsg, aIter, &element) ||
- !aResult.AppendElement(element)) {
+ !aResult->AppendElement(element)) {
return false;
}
}
}
return true;
}
@@ -220,13 +183,11 @@ struct ParamTraits<nsTArray<E> >
if (index) {
aLog->append(L" ");
}
LogParam(aParam[index], aLog);
}
}
};
-#endif
-
} /* namespace IPC */
#endif /* __IPC_GLUE_IPCMESSAGEUTILS_H__ */
--- a/ipc/glue/Makefile.in
+++ b/ipc/glue/Makefile.in
@@ -52,17 +52,16 @@ EXPORTS_NAMESPACES = IPC mozilla/ipc
EXPORTS_IPC = \
IPCMessageUtils.h \
$(NULL)
EXPORTS_mozilla/ipc = \
AsyncChannel.h \
GeckoChildProcessHost.h \
GeckoThread.h \
- MessageTypes.h \
ProtocolUtils.h \
RPCChannel.h \
SyncChannel.h \
ScopedXREEmbed.h \
$(NULL)
ENABLE_CXX_EXCEPTIONS = 1
deleted file mode 100644
--- a/ipc/glue/MessageTypes.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- * vim: sw=4 ts=4 et :
- * ***** 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 Plugin App.
- *
- * The Initial Developer of the Original Code is
- * Chris Jones <jones.chris.g@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 mozilla_ipc_MessageTypes_h
-#define mozilla_ipc_MessageTypes_h 1
-
-// FIXME/cjones: maybe not the best basic types in the long run. what else?
-#include <string>
-#include <vector>
-
-namespace mozilla {
-namespace ipc {
-
-typedef std::string String;
-typedef std::vector<String> StringArray;
-
-} // namespace ipc
-} // namespace mozilla
-
-#endif // ifndef mozilla_ipc_MessageTypes_h
--- a/ipc/ipdl/ipdl/builtin.py
+++ b/ipc/ipdl/ipdl/builtin.py
@@ -52,20 +52,20 @@ Types = (
'int32_t',
'uint32_t',
'int64_t',
'uint64_t',
'intptr_t',
'uintptr_t',
# Mozilla types: "less" standard things we know how serialize/deserialize
- 'mozilla::ipc::String',
- 'mozilla::ipc::StringArray',
+ 'nsString',
+ 'nsCString',
)
Includes = (
'base/basictypes.h',
'nscore.h',
'IPC/IPCMessageUtils.h',
- 'mozilla/ipc/MessageTypes.h',
+ 'nsStringGlue.h',
'mozilla/ipc/ProtocolUtils.h',
)
--- a/ipc/testshell/Makefile.in
+++ b/ipc/testshell/Makefile.in
@@ -58,15 +58,20 @@ EXPORTS_mozilla/ipc = \
CPPSRCS += \
TestShellChild.cpp \
TestShellParent.cpp \
TestShellThread.cpp \
XPCShellEnvironment.cpp \
$(NULL)
-LOCAL_INCLUDES += -I$(topsrcdir)/js/src/xpconnect/shell
+
+# For xpcshell error messages and nsDependentJSString
+LOCAL_INCLUDES += \
+ -I$(topsrcdir)/js/src/xpconnect/shell \
+ -I$(topsrcdir)/dom/base \
+ $(NULL)
TOOL_DIRS += app
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/ipc/chromium/chromium-config.mk
include $(topsrcdir)/config/rules.mk
--- a/ipc/testshell/TestShell.ipdl
+++ b/ipc/testshell/TestShell.ipdl
@@ -35,14 +35,14 @@
* ***** END LICENSE BLOCK ***** */
namespace mozilla {
namespace ipc {
sync protocol TestShell
{
child:
- async SendCommand(String aCommand);
- sync SendCommandWithResponse(String aCommand) returns (String aResponse);
+ async SendCommand(nsString aCommand);
+ sync SendCommandWithResponse(nsString aCommand) returns (nsString aResponse);
};
} // namespace ipc
} // namespace mozilla
--- a/ipc/testshell/TestShellChild.cpp
+++ b/ipc/testshell/TestShellChild.cpp
@@ -48,29 +48,29 @@ TestShellChild::TestShellChild()
}
TestShellChild::~TestShellChild()
{
}
nsresult
-TestShellChild::RecvSendCommand(const String& aCommand)
+TestShellChild::RecvSendCommand(const nsString& aCommand)
{
if (mXPCShell->IsQuitting()) {
NS_WARNING("Commands sent after quit command issued!");
return NS_ERROR_UNEXPECTED;
}
return mXPCShell->EvaluateString(aCommand) ? NS_OK : NS_ERROR_FAILURE;
}
nsresult
-TestShellChild::RecvSendCommandWithResponse(const String& aCommand,
- String* aResponse)
+TestShellChild::RecvSendCommandWithResponse(const nsString& aCommand,
+ nsString* aResponse)
{
if (mXPCShell->IsQuitting()) {
NS_WARNING("Commands sent after quit command issued!");
return NS_ERROR_UNEXPECTED;
}
return mXPCShell->EvaluateString(aCommand, aResponse) ?
NS_OK :
--- a/ipc/testshell/TestShellChild.h
+++ b/ipc/testshell/TestShellChild.h
@@ -42,24 +42,22 @@
namespace mozilla {
namespace ipc {
class XPCShellEnvironment;
class TestShellChild : public TestShellProtocolChild
{
public:
- typedef mozilla::ipc::String String;
-
TestShellChild();
virtual ~TestShellChild();
- virtual nsresult RecvSendCommand(const String& aCommand);
- virtual nsresult RecvSendCommandWithResponse(const String& aCommand,
- String* aResponse);
+ virtual nsresult RecvSendCommand(const nsString& aCommand);
+ virtual nsresult RecvSendCommandWithResponse(const nsString& aCommand,
+ nsString* aResponse);
void SetXPCShell(XPCShellEnvironment* aXPCShell) {
mXPCShell = aXPCShell;
}
private:
XPCShellEnvironment* mXPCShell;
};
--- a/ipc/testshell/TestShellParent.h
+++ b/ipc/testshell/TestShellParent.h
@@ -40,18 +40,16 @@
#include "mozilla/ipc/TestShellProtocolParent.h"
namespace mozilla {
namespace ipc {
class TestShellParent : public TestShellProtocolParent
{
public:
- typedef mozilla::ipc::String String;
-
TestShellParent();
~TestShellParent();
};
} /* namespace ipc */
} /* namespace mozilla */
#endif /* _IPC_TESTSHELL_TESTSHELLPARENT_H_ */
--- a/ipc/testshell/XPCShellEnvironment.cpp
+++ b/ipc/testshell/XPCShellEnvironment.cpp
@@ -58,16 +58,17 @@
#include "nsIJSContextStack.h"
#include "nsIJSRuntimeService.h"
#include "nsIPrincipal.h"
#include "nsIScriptSecurityManager.h"
#include "nsIURI.h"
#include "nsIXPConnect.h"
#include "nsIXPCScriptable.h"
+#include "nsJSUtils.h"
#include "nsXULAppAPI.h"
#include "TestShellChild.h"
#include "TestShellParent.h"
#define EXITCODE_RUNTIME_ERROR 3
#define EXITCODE_FILE_NOT_FOUND 4
@@ -1430,18 +1431,17 @@ SendCommand(JSContext *cx,
}
JSString* str = JS_ValueToString(cx, argv[0]);
if (!str) {
JS_ReportError(cx, "Could not convert argument to string!");
return JS_FALSE;
}
- mozilla::ipc::String command(JS_GetStringBytes(str));
-
+ nsDependentJSString command(str);
if (!Environment(cx)->DoSendCommand(command)) {
JS_ReportError(cx, "Failed to send command!");
return JS_FALSE;
}
return JS_TRUE;
}
@@ -1458,25 +1458,24 @@ SendCommandWithResponse(JSContext *cx,
}
JSString* str = JS_ValueToString(cx, argv[0]);
if (!str) {
JS_ReportError(cx, "Could not convert argument to string!");
return JS_FALSE;
}
- mozilla::ipc::String command(JS_GetStringBytes(str));
- mozilla::ipc::String result;
-
+ nsDependentJSString command(str);
+ nsAutoString result;
if (!Environment(cx)->DoSendCommand(command, &result)) {
JS_ReportError(cx, "Failed to send command!");
return JS_FALSE;
}
- JSString* resultStr = JS_NewStringCopyN(cx, result.c_str(), result.length());
+ JSString* resultStr = JS_NewUCStringCopyN(cx, result.get(), result.Length());
if (!resultStr) {
JS_ReportError(cx, "Failed to convert response to string!");
return JS_FALSE;
}
*rval = STRING_TO_JSVAL(resultStr);
return JS_TRUE;
}
@@ -1516,62 +1515,58 @@ XPCShellEnvironment::DefineIPCCommands(T
NS_WARNING("Failed to define sendCommandWithResponse function!");
return false;
}
return true;
}
JSBool
-XPCShellEnvironment::DoSendCommand(const mozilla::ipc::String& aCommand,
- mozilla::ipc::String* aResult)
+XPCShellEnvironment::DoSendCommand(const nsString& aCommand,
+ nsString* aResult)
{
nsresult rv = aResult ?
mParent->SendSendCommandWithResponse(aCommand, aResult) :
mParent->SendSendCommand(aCommand);
return NS_SUCCEEDED(rv) ? JS_TRUE : JS_FALSE;
}
bool
-XPCShellEnvironment::EvaluateString(const mozilla::ipc::String& aString,
- mozilla::ipc::String* aResult)
+XPCShellEnvironment::EvaluateString(const nsString& aString,
+ nsString* aResult)
{
JSAutoRequest ar(mCx);
JS_ClearPendingException(mCx);
JSObject* global = GetGlobalObject();
JSScript* script =
- JS_CompileScriptForPrincipals(mCx, global, GetPrincipal(),
- aString.c_str(), aString.length(),
- "typein", 0);
+ JS_CompileUCScriptForPrincipals(mCx, global, GetPrincipal(),
+ aString.get(), aString.Length(),
+ "typein", 0);
if (!script) {
return false;
}
if (!ShouldCompileOnly()) {
if (aResult) {
- aResult->clear();
+ aResult->Truncate();
}
jsval result;
JSBool ok = JS_ExecuteScript(mCx, global, script, &result);
if (ok && result != JSVAL_VOID) {
JSErrorReporter old = JS_SetErrorReporter(mCx, NULL);
JSString* str = JS_ValueToString(mCx, result);
JS_SetErrorReporter(mCx, old);
- if (str) {
- const char* bytes = JS_GetStringBytes(str);
- fprintf(stdout, "%s\n", bytes);
- if (aResult) {
- aResult->assign(bytes);
- }
+ if (str && aResult) {
+ aResult->Assign(nsDependentJSString(str));
}
}
}
JS_DestroyScript(mCx, script);
return true;
}
--- a/ipc/testshell/XPCShellEnvironment.h
+++ b/ipc/testshell/XPCShellEnvironment.h
@@ -66,21 +66,21 @@ public:
static void DestroyEnvironment(XPCShellEnvironment* aEnv);
void Process(const char* aFilename = nsnull,
JSBool aIsInteractive = JS_FALSE);
bool DefineIPCCommands(TestShellChild* aChild);
bool DefineIPCCommands(TestShellParent* aParent);
- JSBool DoSendCommand(const mozilla::ipc::String& aCommand,
- mozilla::ipc::String* aResult = nsnull);
+ JSBool DoSendCommand(const nsString& aCommand,
+ nsString* aResult = nsnull);
- bool EvaluateString(const mozilla::ipc::String& aString,
- mozilla::ipc::String* aResult = nsnull);
+ bool EvaluateString(const nsString& aString,
+ nsString* aResult = nsnull);
JSPrincipals* GetPrincipal() {
return mJSPrincipals;
}
JSObject* GetGlobalObject() {
return mGlobalHolder.ToJSObject();
}