Bug 561085 - Make wyciwyg channel work in e10s. r=dwitte sr=biesi

--HG--
rename : content/html/document/public/nsIWyciwygChannel.idl => netwerk/protocol/wyciwyg/nsIWyciwygChannel.idl
rename : content/html/document/src/nsWyciwygChannel.cpp => netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp
rename : content/html/document/src/nsWyciwygChannel.h => netwerk/protocol/wyciwyg/nsWyciwygChannel.h
rename : content/html/document/src/nsWyciwygProtocolHandler.cpp => netwerk/protocol/wyciwyg/nsWyciwygProtocolHandler.cpp
rename : content/html/document/src/nsWyciwygProtocolHandler.h => netwerk/protocol/wyciwyg/nsWyciwygProtocolHandler.h
This commit is contained in:
Michal Novotny 2010-10-11 13:35:10 +02:00
parent 10b39d0f10
commit cb302b8fbb
36 changed files with 1572 additions and 41 deletions

View File

@ -5000,7 +5000,7 @@ NSS_DISABLE_DBM=
NECKO_WIFI=1
NECKO_COOKIES=1
NECKO_DISK_CACHE=1
NECKO_PROTOCOLS_DEFAULT="about data file ftp http res viewsource"
NECKO_PROTOCOLS_DEFAULT="about data file ftp http res viewsource wyciwyg"
USE_ARM_KUSER=
BUILD_CTYPES=1
XPC_IDISPATCH_SUPPORT=

View File

@ -69,11 +69,6 @@
0x5d0fcdd0, 0x4daa, 0x11d2, \
{0xb3, 0x28, 0x00, 0x80, 0x5f, 0x8a, 0x38, 0x59}}
#define NS_WYCIWYGPROTOCOLHANDLER_CID \
{ /* e7509b46-2eB2-410a-9d7c-c3ce73284d01 */ \
0xe7509b46, 0x2eb2, 0x410a, \
{0x9d, 0x7c, 0xc3, 0xce, 0x73, 0x28, 0x4d, 0x01}}
#define NS_XMLDOCUMENT_CID \
{ /* a6cf9063-15b3-11d2-932e-00805f8add32 */ \
0xa6cf9063, 0x15b3, 0x11d2, \

View File

@ -47,7 +47,6 @@ XPIDL_MODULE = content_htmldoc
XPIDLSRCS = \
nsIImageDocument.idl \
nsIWyciwygChannel.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -54,8 +54,6 @@ CPPSRCS = \
nsImageDocument.cpp \
nsMediaDocument.cpp \
nsPluginDocument.cpp \
nsWyciwygChannel.cpp \
nsWyciwygProtocolHandler.cpp \
$(NULL)
ifdef MOZ_MEDIA

View File

@ -65,6 +65,7 @@ IPDLDIRS = \
layout/ipc \
netwerk/ipc \
netwerk/protocol/http \
netwerk/protocol/wyciwyg \
netwerk/cookie \
$(NULL)
##-----------------------------------------------------------------------------

View File

@ -86,7 +86,6 @@
#include "nsXMLContentSerializer.h"
#include "nsXHTMLContentSerializer.h"
#include "nsRuleNode.h"
#include "nsWyciwygProtocolHandler.h"
#include "nsContentAreaDragDrop.h"
#include "nsContentList.h"
#include "nsSyncLoadService.h"
@ -571,7 +570,6 @@ MAKE_CTOR(CreateEventListenerService, nsIEventListenerService, NS_NewEve
MAKE_CTOR(CreateGlobalMessageManager, nsIChromeFrameMessageManager,NS_NewGlobalMessageManager)
MAKE_CTOR(CreateParentMessageManager, nsIFrameMessageManager,NS_NewParentProcessMessageManager)
MAKE_CTOR(CreateChildMessageManager, nsISyncMessageSender,NS_NewChildProcessMessageManager)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWyciwygProtocolHandler)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDataDocumentContentPolicy)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsNoDataProtocolContentPolicy)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSyncLoadService)
@ -825,7 +823,6 @@ NS_DEFINE_NAMED_CID(NS_XTFSERVICE_CID);
NS_DEFINE_NAMED_CID(NS_XMLCONTENTBUILDER_CID);
#endif
NS_DEFINE_NAMED_CID(NS_CONTENT_DOCUMENT_LOADER_FACTORY_CID);
NS_DEFINE_NAMED_CID(NS_WYCIWYGPROTOCOLHANDLER_CID);
NS_DEFINE_NAMED_CID(NS_SYNCLOADDOMSERVICE_CID);
NS_DEFINE_NAMED_CID(NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
NS_DEFINE_NAMED_CID(NS_BASE_DOM_EXCEPTION_CID);
@ -976,7 +973,6 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
{ &kNS_XMLCONTENTBUILDER_CID, false, NULL, CreateXMLContentBuilder },
#endif
{ &kNS_CONTENT_DOCUMENT_LOADER_FACTORY_CID, false, NULL, CreateContentDLF },
{ &kNS_WYCIWYGPROTOCOLHANDLER_CID, false, NULL, nsWyciwygProtocolHandlerConstructor },
{ &kNS_SYNCLOADDOMSERVICE_CID, false, NULL, nsSyncLoadServiceConstructor },
{ &kNS_DOM_SCRIPT_OBJECT_FACTORY_CID, false, NULL, nsDOMScriptObjectFactoryConstructor },
{ &kNS_BASE_DOM_EXCEPTION_CID, false, NULL, nsBaseDOMExceptionConstructor },
@ -1129,7 +1125,6 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = {
{ NS_XMLCONTENTBUILDER_CONTRACTID, &kNS_XMLCONTENTBUILDER_CID },
#endif
{ CONTENT_DLF_CONTRACTID, &kNS_CONTENT_DOCUMENT_LOADER_FACTORY_CID },
{ NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "wyciwyg", &kNS_WYCIWYGPROTOCOLHANDLER_CID },
{ NS_SYNCLOADDOMSERVICE_CONTRACTID, &kNS_SYNCLOADDOMSERVICE_CID },
{ NS_JSPROTOCOLHANDLER_CONTRACTID, &kNS_JSPROTOCOLHANDLER_CID },
{ NS_WINDOWCONTROLLER_CONTRACTID, &kNS_WINDOWCONTROLLER_CID },

View File

@ -36,6 +36,11 @@
*
* ***** END LICENSE BLOCK ***** */
#ifdef MOZ_IPC
#include "IPCMessageUtils.h"
#include "mozilla/net/NeckoMessageUtils.h"
#endif
#include "nsSimpleNestedURI.h"
#include "nsIObjectInputStream.h"
#include "nsIObjectOutputStream.h"
@ -85,6 +90,37 @@ nsSimpleNestedURI::Write(nsIObjectOutputStream* aStream)
return rv;
}
// nsIIPCSerializable
PRBool
nsSimpleNestedURI::Read(const IPC::Message *aMsg, void **aIter)
{
#ifdef MOZ_IPC
if (!nsSimpleURI::Read(aMsg, aIter))
return PR_FALSE;
IPC::URI uri;
if (!ReadParam(aMsg, aIter, &uri))
return PR_FALSE;
mInnerURI = uri;
return PR_TRUE;
#endif
return PR_FALSE;
}
void
nsSimpleNestedURI::Write(IPC::Message *aMsg)
{
#ifdef MOZ_IPC
nsSimpleURI::Write(aMsg);
IPC::URI uri(mInnerURI);
WriteParam(aMsg, uri);
#endif
}
// nsINestedURI
NS_IMETHODIMP

View File

@ -69,6 +69,7 @@ public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSINESTEDURI
NS_DECL_NSIIPCSERIALIZABLE
// Overrides for various methods nsSimpleURI implements follow.

View File

@ -38,6 +38,10 @@
*
* ***** END LICENSE BLOCK ***** */
#ifdef MOZ_IPC
#include "IPCMessageUtils.h"
#endif
#include "nsSimpleURI.h"
#include "nscore.h"
#include "nsCRT.h"
@ -72,7 +76,7 @@ nsSimpleURI::~nsSimpleURI()
NS_IMPL_ADDREF(nsSimpleURI)
NS_IMPL_RELEASE(nsSimpleURI)
NS_INTERFACE_TABLE_HEAD(nsSimpleURI)
NS_INTERFACE_TABLE4(nsSimpleURI, nsIURI, nsISerializable, nsIClassInfo, nsIMutable)
NS_INTERFACE_TABLE5(nsSimpleURI, nsIURI, nsISerializable, nsIIPCSerializable, nsIClassInfo, nsIMutable)
NS_INTERFACE_TABLE_TO_MAP_SEGUE
if (aIID.Equals(kThisSimpleURIImplementationCID))
foundInterface = static_cast<nsIURI*>(this);
@ -116,6 +120,36 @@ nsSimpleURI::Write(nsIObjectOutputStream* aStream)
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsIIPCSerializable methods:
PRBool
nsSimpleURI::Read(const IPC::Message *aMsg, void **aIter)
{
#ifdef MOZ_IPC
bool isMutable;
if (!ReadParam(aMsg, aIter, &isMutable) ||
!ReadParam(aMsg, aIter, &mScheme) ||
!ReadParam(aMsg, aIter, &mPath))
return PR_FALSE;
mMutable = isMutable;
return PR_TRUE;
#else
return PR_FALSE;
#endif
}
void
nsSimpleURI::Write(IPC::Message *aMsg)
{
#ifdef MOZ_IPC
WriteParam(aMsg, bool(mMutable));
WriteParam(aMsg, mScheme);
WriteParam(aMsg, mPath);
#endif
}
////////////////////////////////////////////////////////////////////////////////
// nsIURI methods:

View File

@ -41,6 +41,7 @@
#include "nsIURL.h"
#include "nsAgg.h"
#include "nsISerializable.h"
#include "nsIIPCSerializable.h"
#include "nsString.h"
#include "nsIClassInfo.h"
#include "nsIMutable.h"
@ -55,6 +56,7 @@
class nsSimpleURI : public nsIURI,
public nsISerializable,
public nsIIPCSerializable,
public nsIClassInfo,
public nsIMutable
{
@ -62,6 +64,7 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIURI
NS_DECL_NSISERIALIZABLE
NS_DECL_NSIIPCSERIALIZABLE
NS_DECL_NSICLASSINFO
NS_DECL_NSIMUTABLE

View File

@ -685,6 +685,18 @@
{0xae, 0xa8, 0x8f, 0xcc, 0x07, 0x93, 0xe9, 0x7f} \
}
/******************************************************************************
* netwerk/protocol/wyciwyg/ classes
*/
#define NS_WYCIWYGPROTOCOLHANDLER_CID \
{ /* {0xe7509b46-2eB2-410a-9d7c-c3ce73284d01} */ \
0xe7509b46, \
0x2eb2, \
0x410a, \
{0x9d, 0x7c, 0xc3, 0xce, 0x73, 0x28, 0x4d, 0x01} \
}
/******************************************************************************
* netwerk/protocol/about/ classes
*/

View File

@ -269,6 +269,11 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsViewSourceHandler)
#include "nsDataHandler.h"
#endif
#ifdef NECKO_PROTOCOL_wyciwyg
#include "nsWyciwygProtocolHandler.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWyciwygProtocolHandler)
#endif
///////////////////////////////////////////////////////////////////////////////
#include "nsURIChecker.h"
@ -721,6 +726,9 @@ NS_DEFINE_NAMED_CID(NS_DEVICEPROTOCOLHANDLER_CID);
#ifdef NECKO_PROTOCOL_viewsource
NS_DEFINE_NAMED_CID(NS_VIEWSOURCEHANDLER_CID);
#endif
#ifdef NECKO_PROTOCOL_wyciwyg
NS_DEFINE_NAMED_CID(NS_WYCIWYGPROTOCOLHANDLER_CID);
#endif
#if defined(XP_WIN)
NS_DEFINE_NAMED_CID(NS_NETWORK_LINK_SERVICE_CID);
#elif defined(MOZ_WIDGET_COCOA)
@ -842,6 +850,9 @@ static const mozilla::Module::CIDEntry kNeckoCIDs[] = {
#ifdef NECKO_PROTOCOL_viewsource
{ &kNS_VIEWSOURCEHANDLER_CID, false, NULL, nsViewSourceHandlerConstructor },
#endif
#ifdef NECKO_PROTOCOL_wyciwyg
{ &kNS_WYCIWYGPROTOCOLHANDLER_CID, false, NULL, nsWyciwygProtocolHandlerConstructor },
#endif
#if defined(XP_WIN)
{ &kNS_NETWORK_LINK_SERVICE_CID, false, NULL, nsNotifyAddrListenerConstructor },
#elif defined(MOZ_WIDGET_COCOA)
@ -970,6 +981,9 @@ static const mozilla::Module::ContractIDEntry kNeckoContracts[] = {
#ifdef NECKO_PROTOCOL_viewsource
{ NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "view-source", &kNS_VIEWSOURCEHANDLER_CID },
#endif
#ifdef NECKO_PROTOCOL_wyciwyg
{ NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "wyciwyg", &kNS_WYCIWYGPROTOCOLHANDLER_CID },
#endif
#if defined(XP_WIN)
{ NS_NETWORK_LINK_SERVICE_CONTRACTID, &kNS_NETWORK_LINK_SERVICE_CID },
#elif defined(MOZ_WIDGET_COCOA)

View File

@ -44,6 +44,7 @@
#include "mozilla/dom/ContentChild.h"
#include "mozilla/net/HttpChannelChild.h"
#include "mozilla/net/CookieServiceChild.h"
#include "mozilla/net/WyciwygChannelChild.h"
namespace mozilla {
namespace net {
@ -129,5 +130,23 @@ NeckoChild::DeallocPCookieService(PCookieServiceChild* cs)
return true;
}
PWyciwygChannelChild*
NeckoChild::AllocPWyciwygChannel()
{
WyciwygChannelChild *p = new WyciwygChannelChild();
p->AddIPDLReference();
return p;
}
bool
NeckoChild::DeallocPWyciwygChannel(PWyciwygChannelChild* channel)
{
NS_ABORT_IF_FALSE(IsNeckoChild(), "DeallocPWyciwygChannel called by non-child!");
WyciwygChannelChild *p = static_cast<WyciwygChannelChild*>(channel);
p->ReleaseIPDLReference();
return true;
}
}} // mozilla::net

View File

@ -63,6 +63,8 @@ protected:
virtual bool DeallocPHttpChannel(PHttpChannelChild*);
virtual PCookieServiceChild* AllocPCookieService();
virtual bool DeallocPCookieService(PCookieServiceChild*);
virtual PWyciwygChannelChild* AllocPWyciwygChannel();
virtual bool DeallocPWyciwygChannel(PWyciwygChannelChild*);
};
/**

View File

@ -42,6 +42,7 @@
#include "mozilla/net/NeckoParent.h"
#include "mozilla/net/HttpChannelParent.h"
#include "mozilla/net/CookieServiceParent.h"
#include "mozilla/net/WyciwygChannelParent.h"
#include "nsHTMLDNSPrefetch.h"
@ -86,6 +87,22 @@ NeckoParent::DeallocPCookieService(PCookieServiceParent* cs)
return true;
}
PWyciwygChannelParent*
NeckoParent::AllocPWyciwygChannel()
{
WyciwygChannelParent *p = new WyciwygChannelParent();
p->AddRef();
return p;
}
bool
NeckoParent::DeallocPWyciwygChannel(PWyciwygChannelParent* channel)
{
WyciwygChannelParent *p = static_cast<WyciwygChannelParent *>(channel);
p->Release();
return true;
}
bool
NeckoParent::RecvHTMLDNSPrefetch(const nsString& hostname,
const PRUint16& flags)

View File

@ -60,6 +60,8 @@ protected:
virtual bool DeallocPHttpChannel(PHttpChannelParent*);
virtual PCookieServiceParent* AllocPCookieService();
virtual bool DeallocPCookieService(PCookieServiceParent*);
virtual PWyciwygChannelParent* AllocPWyciwygChannel();
virtual bool DeallocPWyciwygChannel(PWyciwygChannelParent*);
virtual bool RecvHTMLDNSPrefetch(const nsString& hostname,
const PRUint16& flags);
};

View File

@ -42,6 +42,7 @@ include protocol PContent;
include protocol PHttpChannel;
include protocol PCookieService;
include protocol PBrowser;
include protocol PWyciwygChannel;
namespace mozilla {
namespace net {
@ -53,11 +54,13 @@ sync protocol PNecko
manager PContent;
manages PHttpChannel;
manages PCookieService;
manages PWyciwygChannel;
parent:
__delete__();
PCookieService();
PWyciwygChannel();
HTMLDNSPrefetch(nsString hostname, PRUint16 flags);

View File

@ -51,5 +51,6 @@
#undef NECKO_PROTOCOL_http
#undef NECKO_PROTOCOL_res
#undef NECKO_PROTOCOL_viewsource
#undef NECKO_PROTOCOL_wyciwyg
#endif

View File

@ -51,6 +51,7 @@ PARALLEL_DIRS = \
http \
res \
viewsource \
wyciwyg \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -66,6 +66,8 @@ LOCAL_INCLUDES = \
-I$(srcdir)/../../base/src \
$(NULL)
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/ipc/chromium/chromium-config.mk
include $(topsrcdir)/config/rules.mk
DEFINES += -DIMPL_NS_NET

View File

@ -36,6 +36,11 @@
*
* ***** END LICENSE BLOCK ***** */
#ifdef MOZ_IPC
#include "IPCMessageUtils.h"
#include "mozilla/net/NeckoMessageUtils.h"
#endif
#include "nsAboutProtocolHandler.h"
#include "nsIURI.h"
#include "nsIIOService.h"
@ -322,6 +327,36 @@ nsNestedAboutURI::Write(nsIObjectOutputStream* aStream)
return NS_OK;
}
// nsIIPCSerializable
PRBool
nsNestedAboutURI::Read(const IPC::Message *aMsg, void **aIter)
{
#ifdef MOZ_IPC
if (!nsSimpleNestedURI::Read(aMsg, aIter))
return PR_FALSE;
IPC::URI uri;
if (!ReadParam(aMsg, aIter, &uri))
return PR_FALSE;
mBaseURI = uri;
return PR_TRUE;
#endif
return PR_FALSE;
}
void
nsNestedAboutURI::Write(IPC::Message *aMsg)
{
#ifdef MOZ_IPC
nsSimpleNestedURI::Write(aMsg);
IPC::URI uri(mBaseURI);
WriteParam(aMsg, uri);
#endif
}
// nsSimpleURI
/* virtual */ nsSimpleURI*
nsNestedAboutURI::StartClone()

View File

@ -76,6 +76,8 @@ private:
// Class to allow us to propagate the base URI to about:blank correctly
class nsNestedAboutURI : public nsSimpleNestedURI {
public:
NS_DECL_NSIIPCSERIALIZABLE
nsNestedAboutURI(nsIURI* aInnerURI, nsIURI* aBaseURI)
: nsSimpleNestedURI(aInnerURI)
, mBaseURI(aBaseURI)

View File

@ -0,0 +1,85 @@
# ***** 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.org build system.
#
# The Initial Developer of the Original Code is Mozilla Foundation
# Portions created by the Initial Developer are Copyright (C) 2010
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Michal Novotny <michal.novotny@gmail.com>
#
# 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 *****
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = necko
LIBRARY_NAME = nkwyciwyg_s
LIBXUL_LIBRARY = 1
XPIDL_MODULE = necko_wyciwyg
GRE_MODULE = 1
FORCE_STATIC_LIB = 1
EXPORTS_NAMESPACES = mozilla/net
XPIDLSRCS = \
nsIWyciwygChannel.idl \
$(NULL)
ifdef MOZ_IPC
EXPORTS_mozilla/net += \
WyciwygChannelParent.h \
WyciwygChannelChild.h \
$(NULL)
endif
CPPSRCS = \
nsWyciwyg.cpp \
nsWyciwygChannel.cpp \
nsWyciwygProtocolHandler.cpp \
$(NULL)
ifdef MOZ_IPC
CPPSRCS += \
WyciwygChannelParent.cpp \
WyciwygChannelChild.cpp \
$(NULL)
endif
LOCAL_INCLUDES = \
-I$(srcdir)/../../base/src \
$(NULL)
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/ipc/chromium/chromium-config.mk
include $(topsrcdir)/config/rules.mk
DEFINES += -DIMPL_NS_NET

View File

@ -0,0 +1,80 @@
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Michal Novotny <michal.novotny@gmail.com>
*
* 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 ***** */
include protocol PNecko;
include "mozilla/net/NeckoMessageUtils.h";
using IPC::URI;
namespace mozilla {
namespace net {
//-------------------------------------------------------------------
protocol PWyciwygChannel
{
manager PNecko;
parent:
__delete__();
Init(URI uri);
AsyncOpen(URI originalURI,
PRUint32 loadFlags);
// methods corresponding to those of nsIWyciwygChannel
WriteToCacheEntry(nsString data);
CloseCacheEntry(nsresult reason);
SetCharsetAndSource(PRInt32 source, nsCString charset);
SetSecurityInfo(nsCString securityInfo);
child:
OnStartRequest(nsresult statusCode,
PRInt32 contentLength,
PRInt32 source,
nsCString charset,
nsCString securityInfo);
OnDataAvailable(nsCString data,
PRUint32 offset);
OnStopRequest(nsresult statusCode);
};
} // namespace net
} // namespace mozilla

View File

@ -0,0 +1,526 @@
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Michal Novotny <michal.novotny@gmail.com>
*
* 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 ***** */
#include "nsWyciwyg.h"
#include "mozilla/net/NeckoChild.h"
#include "WyciwygChannelChild.h"
#include "nsIParser.h"
#include "nsStringStream.h"
#include "nsMimeTypes.h"
#include "nsNetUtil.h"
#include "nsISerializable.h"
#include "nsSerializationHelper.h"
namespace mozilla {
namespace net {
NS_IMPL_ISUPPORTS3(WyciwygChannelChild,
nsIRequest,
nsIChannel,
nsIWyciwygChannel);
WyciwygChannelChild::WyciwygChannelChild()
: mStatus(NS_OK)
, mIsPending(PR_FALSE)
, mLoadFlags(LOAD_NORMAL)
, mContentLength(-1)
, mCharsetSource(kCharsetUninitialized)
, mState(WCC_NEW)
, mIPCOpen(false)
{
LOG(("Creating WyciwygChannelChild @%x\n", this));
}
WyciwygChannelChild::~WyciwygChannelChild()
{
LOG(("Destroying WyciwygChannelChild @%x\n", this));
}
void
WyciwygChannelChild::AddIPDLReference()
{
NS_ABORT_IF_FALSE(!mIPCOpen, "Attempt to retain more than one IPDL reference");
mIPCOpen = true;
AddRef();
}
void
WyciwygChannelChild::ReleaseIPDLReference()
{
NS_ABORT_IF_FALSE(mIPCOpen, "Attempt to release nonexistent IPDL reference");
mIPCOpen = false;
Release();
}
nsresult
WyciwygChannelChild::Init(nsIURI* uri)
{
NS_ENSURE_ARG_POINTER(uri);
mState = WCC_INIT;
mURI = uri;
mOriginalURI = uri;
SendInit(IPC::URI(mURI));
return NS_OK;
}
//-----------------------------------------------------------------------------
// WyciwygChannelChild::PWyciwygChannelChild
//-----------------------------------------------------------------------------
bool
WyciwygChannelChild::RecvOnStartRequest(const nsresult& statusCode,
const PRInt32& contentLength,
const PRInt32& source,
const nsCString& charset,
const nsCString& securityInfo)
{
LOG(("WyciwygChannelChild::RecvOnStartRequest [this=%x]\n", this));
mState = WCC_ONSTART;
mStatus = statusCode;
mContentLength = contentLength;
mCharsetSource = source;
mCharset = charset;
if (!securityInfo.IsEmpty()) {
NS_DeserializeObject(securityInfo, getter_AddRefs(mSecurityInfo));
}
nsresult rv = mListener->OnStartRequest(this, mListenerContext);
if (NS_FAILED(rv)) {
// TODO: Cancel request:
// - Send Cancel msg to parent
// - drop any in flight OnDataAvail msgs we receive
// - make sure we do call OnStopRequest eventually
// - return true here, not false
return false;
}
return true;
}
bool
WyciwygChannelChild::RecvOnDataAvailable(const nsCString& data,
const PRUint32& offset)
{
LOG(("WyciwygChannelChild::RecvOnDataAvailable [this=%x]\n", this));
mState = WCC_ONDATA;
// NOTE: the OnDataAvailable contract requires the client to read all the data
// in the inputstream. This code relies on that ('data' will go away after
// this function). Apparently the previous, non-e10s behavior was to actually
// support only reading part of the data, allowing later calls to read the
// rest.
nsCOMPtr<nsIInputStream> stringStream;
nsresult rv = NS_NewByteInputStream(getter_AddRefs(stringStream),
data.get(),
data.Length(),
NS_ASSIGNMENT_DEPEND);
if (NS_FAILED(rv)) {
// TODO: what to do here? Cancel request? Very unlikely to fail.
return false;
}
rv = mListener->OnDataAvailable(this, mListenerContext,
stringStream, offset, data.Length());
if (NS_FAILED(rv)) {
// TODO: Cancel request: see notes in OnStartRequest
return false;
}
if (mProgressSink && NS_SUCCEEDED(rv) && !(mLoadFlags & LOAD_BACKGROUND))
mProgressSink->OnProgress(this, nsnull, PRUint64(offset + data.Length()),
PRUint64(mContentLength));
return true;
}
bool
WyciwygChannelChild::RecvOnStopRequest(const nsresult& statusCode)
{
LOG(("WyciwygChannelChild::RecvOnStopRequest [this=%x status=%u]\n",
this, statusCode));
mState = WCC_ONSTOP;
mIsPending = PR_FALSE;
mStatus = statusCode;
mListener->OnStopRequest(this, mListenerContext, statusCode);
mListener = 0;
mListenerContext = 0;
if (mLoadGroup)
mLoadGroup->RemoveRequest(this, nsnull, mStatus);
mCallbacks = 0;
mProgressSink = 0;
if (mIPCOpen)
PWyciwygChannelChild::Send__delete__(this);
return true;
}
//-----------------------------------------------------------------------------
// nsIRequest
//-----------------------------------------------------------------------------
/* readonly attribute AUTF8String name; */
NS_IMETHODIMP
WyciwygChannelChild::GetName(nsACString & aName)
{
return mURI->GetSpec(aName);
}
/* boolean isPending (); */
NS_IMETHODIMP
WyciwygChannelChild::IsPending(PRBool *aIsPending)
{
*aIsPending = mIsPending;
return NS_OK;
}
/* readonly attribute nsresult status; */
NS_IMETHODIMP
WyciwygChannelChild::GetStatus(nsresult *aStatus)
{
*aStatus = mStatus;
return NS_OK;
}
/* void cancel (in nsresult aStatus); */
NS_IMETHODIMP
WyciwygChannelChild::Cancel(nsresult aStatus)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void suspend (); */
NS_IMETHODIMP
WyciwygChannelChild::Suspend()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void resume (); */
NS_IMETHODIMP
WyciwygChannelChild::Resume()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute nsILoadGroup loadGroup; */
NS_IMETHODIMP
WyciwygChannelChild::GetLoadGroup(nsILoadGroup * *aLoadGroup)
{
*aLoadGroup = mLoadGroup;
NS_IF_ADDREF(*aLoadGroup);
return NS_OK;
}
NS_IMETHODIMP
WyciwygChannelChild::SetLoadGroup(nsILoadGroup * aLoadGroup)
{
mLoadGroup = aLoadGroup;
NS_QueryNotificationCallbacks(mCallbacks,
mLoadGroup,
NS_GET_IID(nsIProgressEventSink),
getter_AddRefs(mProgressSink));
return NS_OK;
}
/* attribute nsLoadFlags loadFlags; */
NS_IMETHODIMP
WyciwygChannelChild::GetLoadFlags(nsLoadFlags *aLoadFlags)
{
*aLoadFlags = mLoadFlags;
return NS_OK;
}
NS_IMETHODIMP
WyciwygChannelChild::SetLoadFlags(nsLoadFlags aLoadFlags)
{
mLoadFlags = aLoadFlags;
return NS_OK;
}
//-----------------------------------------------------------------------------
// nsIChannel
//-----------------------------------------------------------------------------
/* attribute nsIURI originalURI; */
NS_IMETHODIMP
WyciwygChannelChild::GetOriginalURI(nsIURI * *aOriginalURI)
{
*aOriginalURI = mOriginalURI;
NS_ADDREF(*aOriginalURI);
return NS_OK;
}
NS_IMETHODIMP
WyciwygChannelChild::SetOriginalURI(nsIURI * aOriginalURI)
{
NS_ENSURE_TRUE(mState == WCC_INIT, NS_ERROR_UNEXPECTED);
NS_ENSURE_ARG_POINTER(aOriginalURI);
mOriginalURI = aOriginalURI;
return NS_OK;
}
/* readonly attribute nsIURI URI; */
NS_IMETHODIMP
WyciwygChannelChild::GetURI(nsIURI * *aURI)
{
*aURI = mURI;
NS_IF_ADDREF(*aURI);
return NS_OK;
}
/* attribute nsISupports owner; */
NS_IMETHODIMP
WyciwygChannelChild::GetOwner(nsISupports * *aOwner)
{
NS_PRECONDITION(mOwner, "Must have a principal!");
NS_ENSURE_STATE(mOwner);
NS_ADDREF(*aOwner = mOwner);
return NS_OK;
}
NS_IMETHODIMP
WyciwygChannelChild::SetOwner(nsISupports * aOwner)
{
mOwner = aOwner;
return NS_OK;
}
/* attribute nsIInterfaceRequestor notificationCallbacks; */
NS_IMETHODIMP
WyciwygChannelChild::GetNotificationCallbacks(nsIInterfaceRequestor * *aCallbacks)
{
*aCallbacks = mCallbacks;
NS_IF_ADDREF(*aCallbacks);
return NS_OK;
}
NS_IMETHODIMP
WyciwygChannelChild::SetNotificationCallbacks(nsIInterfaceRequestor * aCallbacks)
{
mCallbacks = aCallbacks;
NS_QueryNotificationCallbacks(mCallbacks,
mLoadGroup,
NS_GET_IID(nsIProgressEventSink),
getter_AddRefs(mProgressSink));
return NS_OK;
}
/* readonly attribute nsISupports securityInfo; */
NS_IMETHODIMP
WyciwygChannelChild::GetSecurityInfo(nsISupports * *aSecurityInfo)
{
NS_IF_ADDREF(*aSecurityInfo = mSecurityInfo);
return NS_OK;
}
/* attribute ACString contentType; */
NS_IMETHODIMP
WyciwygChannelChild::GetContentType(nsACString & aContentType)
{
aContentType.AssignLiteral(WYCIWYG_TYPE);
return NS_OK;
}
NS_IMETHODIMP
WyciwygChannelChild::SetContentType(const nsACString & aContentType)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute ACString contentCharset; */
NS_IMETHODIMP
WyciwygChannelChild::GetContentCharset(nsACString & aContentCharset)
{
aContentCharset.Assign("UTF-16");
return NS_OK;
}
NS_IMETHODIMP
WyciwygChannelChild::SetContentCharset(const nsACString & aContentCharset)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute long contentLength; */
NS_IMETHODIMP
WyciwygChannelChild::GetContentLength(PRInt32 *aContentLength)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
WyciwygChannelChild::SetContentLength(PRInt32 aContentLength)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* nsIInputStream open (); */
NS_IMETHODIMP
WyciwygChannelChild::Open(nsIInputStream **_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void asyncOpen (in nsIStreamListener aListener, in nsISupports aContext); */
NS_IMETHODIMP
WyciwygChannelChild::AsyncOpen(nsIStreamListener *aListener, nsISupports *aContext)
{
LOG(("WyciwygChannelChild::AsyncOpen [this=%x]\n", this));
// The only places creating wyciwyg: channels should be
// HTMLDocument::OpenCommon and session history. Both should be setting an
// owner.
NS_PRECONDITION(mOwner, "Must have a principal");
NS_ENSURE_STATE(mOwner);
NS_ENSURE_ARG_POINTER(aListener);
NS_ENSURE_TRUE(!mIsPending, NS_ERROR_IN_PROGRESS);
mListener = aListener;
mListenerContext = aContext;
mIsPending = PR_TRUE;
if (mLoadGroup)
mLoadGroup->AddRequest(this, nsnull);
SendAsyncOpen(IPC::URI(mOriginalURI), mLoadFlags);
mState = WCC_OPENED;
return NS_OK;
}
//-----------------------------------------------------------------------------
// nsIWyciwygChannel
//-----------------------------------------------------------------------------
/* void writeToCacheEntry (in AString aData); */
NS_IMETHODIMP
WyciwygChannelChild::WriteToCacheEntry(const nsAString & aData)
{
NS_ENSURE_TRUE((mState == WCC_INIT) ||
(mState == WCC_ONWRITE), NS_ERROR_UNEXPECTED);
SendWriteToCacheEntry(PromiseFlatString(aData));
mState = WCC_ONWRITE;
return NS_OK;
}
/* void closeCacheEntry (in nsresult reason); */
NS_IMETHODIMP
WyciwygChannelChild::CloseCacheEntry(nsresult reason)
{
NS_ENSURE_TRUE(mState == WCC_ONWRITE, NS_ERROR_UNEXPECTED);
SendCloseCacheEntry(reason);
mState = WCC_ONCLOSED;
if (mIPCOpen)
PWyciwygChannelChild::Send__delete__(this);
return NS_OK;
}
/* void setSecurityInfo (in nsISupports aSecurityInfo); */
NS_IMETHODIMP
WyciwygChannelChild::SetSecurityInfo(nsISupports *aSecurityInfo)
{
mSecurityInfo = aSecurityInfo;
if (mSecurityInfo) {
nsCOMPtr<nsISerializable> serializable = do_QueryInterface(mSecurityInfo);
if (serializable) {
nsCString secInfoStr;
NS_SerializeToString(serializable, secInfoStr);
SendSetSecurityInfo(secInfoStr);
}
else {
NS_WARNING("Can't serialize security info");
}
}
return NS_OK;
}
/* void setCharsetAndSource (in long aSource, in ACString aCharset); */
NS_IMETHODIMP
WyciwygChannelChild::SetCharsetAndSource(PRInt32 aSource, const nsACString & aCharset)
{
// mState == WCC_ONSTART when reading from the channel
// mState == WCC_INIT when writing to the cache
NS_ENSURE_TRUE((mState == WCC_ONSTART) ||
(mState == WCC_INIT), NS_ERROR_UNEXPECTED);
mCharsetSource = aSource;
mCharset = aCharset;
// TODO ensure that nsWyciwygChannel in the parent has still the cache entry
SendSetCharsetAndSource(mCharsetSource, mCharset);
return NS_OK;
}
/* ACString getCharsetAndSource (out long aSource); */
NS_IMETHODIMP
WyciwygChannelChild::GetCharsetAndSource(PRInt32 *aSource NS_OUTPARAM, nsACString & _retval)
{
NS_ENSURE_TRUE((mState == WCC_ONSTART) ||
(mState == WCC_ONDATA) ||
(mState == WCC_ONSTOP), NS_ERROR_NOT_AVAILABLE);
if (mCharsetSource == kCharsetUninitialized)
return NS_ERROR_NOT_AVAILABLE;
*aSource = mCharsetSource;
_retval = mCharset;
return NS_OK;
}
//------------------------------------------------------------------------------
}} // mozilla::net

View File

@ -0,0 +1,120 @@
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Michal Novotny <michal.novotny@gmail.com>
*
* 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_net_WyciwygChannelChild_h
#define mozilla_net_WyciwygChannelChild_h
#include "mozilla/net/PWyciwygChannelChild.h"
#include "nsIWyciwygChannel.h"
#include "nsIChannel.h"
#include "nsIProgressEventSink.h"
namespace mozilla {
namespace net {
// TODO: replace with IPDL states
enum WyciwygChannelChildState {
WCC_NEW,
WCC_INIT,
// States when reading from the channel
WCC_OPENED,
WCC_ONSTART,
WCC_ONDATA,
WCC_ONSTOP,
// States when writing to the cache
WCC_ONWRITE,
WCC_ONCLOSED
};
// Header file contents
class WyciwygChannelChild : public PWyciwygChannelChild
, public nsIWyciwygChannel
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUEST
NS_DECL_NSICHANNEL
NS_DECL_NSIWYCIWYGCHANNEL
WyciwygChannelChild();
virtual ~WyciwygChannelChild();
void AddIPDLReference();
void ReleaseIPDLReference();
nsresult Init(nsIURI *uri);
protected:
bool RecvOnStartRequest(const nsresult& statusCode,
const PRInt32& contentLength,
const PRInt32& source,
const nsCString& charset,
const nsCString& securityInfo);
bool RecvOnDataAvailable(const nsCString& data,
const PRUint32& offset);
bool RecvOnStopRequest(const nsresult& statusCode);
private:
nsresult mStatus;
PRBool mIsPending;
PRUint32 mLoadFlags;
PRInt32 mContentLength;
PRInt32 mCharsetSource;
nsCString mCharset;
nsCOMPtr<nsIURI> mURI;
nsCOMPtr<nsIURI> mOriginalURI;
nsCOMPtr<nsISupports> mOwner;
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
nsCOMPtr<nsIProgressEventSink> mProgressSink;
nsCOMPtr<nsILoadGroup> mLoadGroup;
nsCOMPtr<nsIStreamListener> mListener;
nsCOMPtr<nsISupports> mListenerContext;
nsCOMPtr<nsISupports> mSecurityInfo;
// FIXME: replace with IPDL states (bug 536319)
enum WyciwygChannelChildState mState;
bool mIPCOpen;
};
} // namespace net
} // namespace mozilla
#endif // mozilla_net_WyciwygChannelChild_h

View File

@ -0,0 +1,249 @@
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Michal Novotny <michal.novotny@gmail.com>
*
* 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 ***** */
#include "nsWyciwyg.h"
#include "mozilla/net/WyciwygChannelParent.h"
#include "nsWyciwygChannel.h"
#include "nsNetUtil.h"
#include "nsISupportsPriority.h"
#include "nsIParser.h"
#include "nsISerializable.h"
#include "nsSerializationHelper.h"
namespace mozilla {
namespace net {
WyciwygChannelParent::WyciwygChannelParent()
: mIPCClosed(false)
{
#if defined(PR_LOGGING)
if (!gWyciwygLog)
gWyciwygLog = PR_NewLogModule("nsWyciwygChannel");
#endif
}
WyciwygChannelParent::~WyciwygChannelParent()
{
}
void
WyciwygChannelParent::ActorDestroy(ActorDestroyReason why)
{
// We may still have refcount>0 if the channel hasn't called OnStopRequest
// yet, but we must not send any more msgs to child.
mIPCClosed = true;
}
//-----------------------------------------------------------------------------
// WyciwygChannelParent::nsISupports
//-----------------------------------------------------------------------------
NS_IMPL_ISUPPORTS2(WyciwygChannelParent,
nsIStreamListener,
nsIRequestObserver);
//-----------------------------------------------------------------------------
// WyciwygChannelParent::PWyciwygChannelParent
//-----------------------------------------------------------------------------
bool
WyciwygChannelParent::RecvInit(const IPC::URI& aURI)
{
nsresult rv;
nsCOMPtr<nsIURI> uri(aURI);
nsCString uriSpec;
uri->GetSpec(uriSpec);
LOG(("WyciwygChannelParent RecvAsyncOpen [this=%x uri=%s]\n",
this, uriSpec.get()));
nsCOMPtr<nsIIOService> ios(do_GetIOService(&rv));
if (NS_FAILED(rv))
return false; // TODO: send fail msg to child, return true
nsCOMPtr<nsIChannel> chan;
rv = NS_NewChannel(getter_AddRefs(chan), uri, ios);
if (NS_FAILED(rv))
return false; // TODO: send fail msg to child, return true
mChannel = do_QueryInterface(chan, &rv);
if (NS_FAILED(rv))
return false; // TODO: send fail msg to child, return true
return true;
}
bool
WyciwygChannelParent::RecvAsyncOpen(const IPC::URI& aOriginal,
const PRUint32& aLoadFlags)
{
nsCOMPtr<nsIURI> original(aOriginal);
nsresult rv;
rv = mChannel->SetOriginalURI(original);
if (NS_FAILED(rv))
return false; // TODO: send fail msg to child, return true
rv = mChannel->SetLoadFlags(aLoadFlags);
if (NS_FAILED(rv))
return false; // TODO: send fail msg to child, return true
rv = mChannel->AsyncOpen(this, nsnull);
if (NS_FAILED(rv))
return false; // TODO: send fail msg to child, return true
return true;
}
bool
WyciwygChannelParent::RecvWriteToCacheEntry(const nsString& data)
{
mChannel->WriteToCacheEntry(data);
return true;
}
bool
WyciwygChannelParent::RecvCloseCacheEntry(const nsresult& reason)
{
mChannel->CloseCacheEntry(reason);
return true;
}
bool
WyciwygChannelParent::RecvSetCharsetAndSource(const PRInt32& aCharsetSource,
const nsCString& aCharset)
{
mChannel->SetCharsetAndSource(aCharsetSource, aCharset);
return true;
}
bool
WyciwygChannelParent::RecvSetSecurityInfo(const nsCString& aSecurityInfo)
{
nsCOMPtr<nsISupports> securityInfo;
NS_DeserializeObject(aSecurityInfo, getter_AddRefs(securityInfo));
mChannel->SetSecurityInfo(securityInfo);
return true;
}
//-----------------------------------------------------------------------------
// WyciwygChannelParent::nsIRequestObserver
//-----------------------------------------------------------------------------
NS_IMETHODIMP
WyciwygChannelParent::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext)
{
LOG(("WyciwygChannelParent::OnStartRequest [this=%x]\n", this));
nsresult rv;
nsCOMPtr<nsIWyciwygChannel> chan = do_QueryInterface(aRequest, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsresult status;
chan->GetStatus(&status);
PRInt32 contentLength = -1;
chan->GetContentLength(&contentLength);
PRInt32 charsetSource = kCharsetUninitialized;
nsCAutoString charset;
chan->GetCharsetAndSource(&charsetSource, charset);
nsCOMPtr<nsISupports> securityInfo;
chan->GetSecurityInfo(getter_AddRefs(securityInfo));
nsCString secInfoStr;
if (securityInfo) {
nsCOMPtr<nsISerializable> serializable = do_QueryInterface(securityInfo);
if (serializable)
NS_SerializeToString(serializable, secInfoStr);
else
NS_WARNING("Can't serialize security info");
}
if (mIPCClosed ||
!SendOnStartRequest(status, contentLength, charsetSource, charset, secInfoStr)) {
return NS_ERROR_UNEXPECTED;
}
return NS_OK;
}
NS_IMETHODIMP
WyciwygChannelParent::OnStopRequest(nsIRequest *aRequest,
nsISupports *aContext,
nsresult aStatusCode)
{
LOG(("WyciwygChannelParent::OnStopRequest: [this=%x status=%ul]\n",
this, aStatusCode));
if (mIPCClosed || !SendOnStopRequest(aStatusCode)) {
return NS_ERROR_UNEXPECTED;
}
return NS_OK;
}
//-----------------------------------------------------------------------------
// WyciwygChannelParent::nsIStreamListener
//-----------------------------------------------------------------------------
NS_IMETHODIMP
WyciwygChannelParent::OnDataAvailable(nsIRequest *aRequest,
nsISupports *aContext,
nsIInputStream *aInputStream,
PRUint32 aOffset,
PRUint32 aCount)
{
LOG(("WyciwygChannelParent::OnDataAvailable [this=%x]\n", this));
nsCString data;
nsresult rv = NS_ReadInputStreamToString(aInputStream, data, aCount);
if (NS_FAILED(rv))
return rv;
if (mIPCClosed || !SendOnDataAvailable(data, aOffset)) {
return NS_ERROR_UNEXPECTED;
}
return NS_OK;
}
}} // mozilla::net

View File

@ -0,0 +1,80 @@
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Michal Novotny <michal.novotny@gmail.com>
*
* 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_net_WyciwygChannelParent_h
#define mozilla_net_WyciwygChannelParent_h
#include "mozilla/net/PWyciwygChannelParent.h"
#include "mozilla/net/NeckoCommon.h"
#include "nsIStreamListener.h"
#include "nsIWyciwygChannel.h"
namespace mozilla {
namespace net {
class WyciwygChannelParent : public PWyciwygChannelParent
, public nsIStreamListener
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
WyciwygChannelParent();
virtual ~WyciwygChannelParent();
protected:
virtual bool RecvInit(const IPC::URI& uri);
virtual bool RecvAsyncOpen(const IPC::URI& original,
const PRUint32& loadFlags);
virtual bool RecvWriteToCacheEntry(const nsString& data);
virtual bool RecvCloseCacheEntry(const nsresult& reason);
virtual bool RecvSetCharsetAndSource(const PRInt32& source,
const nsCString& charset);
virtual bool RecvSetSecurityInfo(const nsCString& securityInfo);
virtual void ActorDestroy(ActorDestroyReason why);
nsCOMPtr<nsIWyciwygChannel> mChannel;
bool mIPCClosed;
};
} // namespace net
} // namespace mozilla
#endif // mozilla_net_WyciwygChannelParent_h

View File

@ -0,0 +1,41 @@
# ***** 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 Firefox.
#
# The Initial Developer of the Original Code is
# The Mozilla Foundation <http://www.mozilla.org/>.
# Portions created by the Initial Developer are Copyright (C) 2010
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Michal Novotny <michal.novotny@gmail.com>
#
# 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 *****
IPDLSRCS = \
PWyciwygChannel.ipdl \
$(NULL)

View File

@ -0,0 +1,43 @@
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Michal Novotny <michal.novotny@gmail.com>
*
* 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 ***** */
#include "nsWyciwyg.h"
#if defined(PR_LOGGING)
PRLogModuleInfo *gWyciwygLog = nsnull;
#endif

View File

@ -0,0 +1,97 @@
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Michal Novotny <michal.novotny@gmail.com>
*
* 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 nsWyciwyg_h__
#define nsWyciwyg_h__
#if defined(MOZ_LOGGING)
#define FORCE_PR_LOG
#endif
#ifdef MOZ_IPC
// e10s mess: IPDL-generatd headers include chromium which both #includes
// prlog.h, and #defines LOG in conflict with this file.
// Solution: (as described in bug 545995)
// 1) ensure that this file is #included before any IPDL-generated files and
// anything else that #includes prlog.h, so that we can make sure prlog.h
// sees FORCE_PR_LOG if needed.
// 2) #include IPDL boilerplate, and then undef LOG so our LOG wins.
// 3) nsNetModule.cpp does its own crazy stuff with #including prlog.h
// multiple times; allow it to define ALLOW_LATE_NSHTTP_H_INCLUDE to bypass
// check.
#if defined(PR_LOG) && !defined(ALLOW_LATE_NSHTTP_H_INCLUDE)
#error "If nsWyciwyg.h #included it must come before any IPDL-generated files or other files that #include prlog.h"
#endif
#include "mozilla/net/NeckoChild.h"
#undef LOG
#endif // MOZ_IPC
#include "plstr.h"
#include "prlog.h"
#include "prtime.h"
#if defined(PR_LOGGING)
//
// Log module for HTTP Protocol logging...
//
// To enable logging (see prlog.h for full details):
//
// set NSPR_LOG_MODULES=nsWyciwyg:5
// set NSPR_LOG_FILE=wyciwyg.log
//
// this enables PR_LOG_ALWAYS level information and places all output in
// the file wyciwyg.log
//
extern PRLogModuleInfo *gWyciwygLog;
#endif
// http logging
#define LOG1(args) PR_LOG(gWyciwygLog, 1, args)
#define LOG2(args) PR_LOG(gWyciwygLog, 2, args)
#define LOG3(args) PR_LOG(gWyciwygLog, 3, args)
#define LOG4(args) PR_LOG(gWyciwygLog, 4, args)
#define LOG(args) LOG4(args)
#define LOG1_ENABLED() PR_LOG_TEST(gWyciwygLog, 1)
#define LOG2_ENABLED() PR_LOG_TEST(gWyciwygLog, 2)
#define LOG3_ENABLED() PR_LOG_TEST(gWyciwygLog, 3)
#define LOG4_ENABLED() PR_LOG_TEST(gWyciwygLog, 4)
#define LOG_ENABLED() LOG4_ENABLED()
#define WYCIWYG_TYPE "text/html"
#endif // nsWyciwyg_h__

View File

@ -37,6 +37,7 @@
*
* ***** END LICENSE BLOCK ***** */
#include "nsWyciwyg.h"
#include "nsWyciwygChannel.h"
#include "nsIServiceManager.h"
#include "nsILoadGroup.h"
@ -48,11 +49,6 @@
#include "nsIParser.h"
#include "nsThreadUtils.h"
PRLogModuleInfo * gWyciwygLog = nsnull;
#define wyciwyg_TYPE "text/html"
#define LOG(args) PR_LOG(gWyciwygLog, 4, args)
// nsWyciwygChannel methods
nsWyciwygChannel::nsWyciwygChannel()
: mStatus(NS_OK),
@ -152,6 +148,10 @@ NS_IMETHODIMP
nsWyciwygChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
{
mLoadGroup = aLoadGroup;
NS_QueryNotificationCallbacks(mCallbacks,
mLoadGroup,
NS_GET_IID(nsIProgressEventSink),
getter_AddRefs(mProgressSink));
return NS_OK;
}
@ -226,7 +226,10 @@ NS_IMETHODIMP
nsWyciwygChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallbacks)
{
mCallbacks = aNotificationCallbacks;
mProgressSink = do_GetInterface(mCallbacks);
NS_QueryNotificationCallbacks(mCallbacks,
mLoadGroup,
NS_GET_IID(nsIProgressEventSink),
getter_AddRefs(mProgressSink));
return NS_OK;
}
@ -241,7 +244,7 @@ nsWyciwygChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
NS_IMETHODIMP
nsWyciwygChannel::GetContentType(nsACString &aContentType)
{
aContentType.AssignLiteral(wyciwyg_TYPE);
aContentType.AssignLiteral(WYCIWYG_TYPE);
return NS_OK;
}
@ -267,7 +270,8 @@ nsWyciwygChannel::SetContentCharset(const nsACString &aContentCharset)
NS_IMETHODIMP
nsWyciwygChannel::GetContentLength(PRInt32 *aContentLength)
{
return NS_ERROR_NOT_IMPLEMENTED;
*aContentLength = mContentLength;
return NS_OK;
}
NS_IMETHODIMP
@ -287,15 +291,17 @@ nsWyciwygChannel::Open(nsIInputStream ** aReturn)
NS_IMETHODIMP
nsWyciwygChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx)
{
LOG(("nsWyciwygChannel::AsyncOpen [this=%x]\n", this));
#ifndef MOZ_IPC
// The only places creating wyciwyg: channels should be
// HTMLDocument::OpenCommon and session history. Both should be setting an
// owner.
NS_PRECONDITION(mOwner, "Must have a principal");
LOG(("nsWyciwygChannel::AsyncOpen [this=%x]\n", this));
NS_ENSURE_STATE(mOwner);
#endif
NS_ENSURE_TRUE(!mIsPending, NS_ERROR_IN_PROGRESS);
NS_ENSURE_STATE(mOwner);
NS_ENSURE_ARG_POINTER(listener);
nsCAutoString spec;

View File

@ -43,7 +43,6 @@
#include "nsXPIDLString.h"
#include "nsString.h"
#include "nsCOMPtr.h"
#include "prlog.h"
#include "nsIWyciwygChannel.h"
#include "nsILoadGroup.h"

View File

@ -37,24 +37,37 @@
*
* ***** END LICENSE BLOCK ***** */
#include "nsWyciwyg.h"
#include "nsWyciwygChannel.h"
#include "nsWyciwygProtocolHandler.h"
#include "nsIURL.h"
#include "nsIComponentManager.h"
#include "nsNetCID.h"
#ifdef MOZ_IPC
#include "mozilla/net/NeckoChild.h"
#endif
using namespace mozilla::net;
#ifdef MOZ_IPC
#include "mozilla/net/WyciwygChannelChild.h"
#endif
////////////////////////////////////////////////////////////////////////////////
nsWyciwygProtocolHandler::nsWyciwygProtocolHandler()
{
#if defined(PR_LOGGING)
gWyciwygLog = PR_NewLogModule("nsWyciwygChannel");
if (!gWyciwygLog)
gWyciwygLog = PR_NewLogModule("nsWyciwygChannel");
#endif
LOG(("Creating nsWyciwygProtocolHandler [this=%x].\n", this));
}
nsWyciwygProtocolHandler::~nsWyciwygProtocolHandler()
{
LOG(("Deleting nsWyciwygProtocolHandler [this=%x]\n", this));
}
NS_IMPL_ISUPPORTS1(nsWyciwygProtocolHandler, nsIProtocolHandler)
@ -107,20 +120,44 @@ nsWyciwygProtocolHandler::NewURI(const nsACString &aSpec,
NS_IMETHODIMP
nsWyciwygProtocolHandler::NewChannel(nsIURI* url, nsIChannel* *result)
{
#ifdef MOZ_IPC
if (mozilla::net::IsNeckoChild())
mozilla::net::NeckoChild::InitNeckoChild();
#endif // MOZ_IPC
NS_ENSURE_ARG_POINTER(url);
nsresult rv;
nsWyciwygChannel* channel = new nsWyciwygChannel();
if (!channel)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(channel);
rv = channel->Init(url);
nsCOMPtr<nsIWyciwygChannel> channel;
#ifdef MOZ_IPC
if (IsNeckoChild()) {
NS_ENSURE_TRUE(gNeckoChild != nsnull, NS_ERROR_FAILURE);
WyciwygChannelChild *wcc = static_cast<WyciwygChannelChild *>(
gNeckoChild->SendPWyciwygChannelConstructor());
if (!wcc)
return NS_ERROR_OUT_OF_MEMORY;
channel = wcc;
rv = wcc->Init(url);
if (NS_FAILED(rv))
PWyciwygChannelChild::Send__delete__(wcc);
} else
#endif
{
nsWyciwygChannel *wc = new nsWyciwygChannel();
if (!wc)
return NS_ERROR_OUT_OF_MEMORY;
channel = wc;
rv = wc->Init(url);
}
*result = channel.forget().get();
if (NS_FAILED(rv)) {
NS_RELEASE(channel);
NS_RELEASE(*result);
return rv;
}
*result = channel;
return NS_OK;
}

View File

@ -49,12 +49,8 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPROTOCOLHANDLER
// nsWyciwygProtocolHandler methods:
nsWyciwygProtocolHandler();
virtual ~nsWyciwygProtocolHandler();
// Define a Create method to be used with a factory:
// static NS_METHOD Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
};
#endif /* nsWyciwygProtocolHandler_h___ */