diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /netwerk/protocol/data | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'netwerk/protocol/data')
-rw-r--r-- | netwerk/protocol/data/DataChannelChild.cpp | 77 | ||||
-rw-r--r-- | netwerk/protocol/data/DataChannelChild.h | 43 | ||||
-rw-r--r-- | netwerk/protocol/data/DataChannelParent.cpp | 89 | ||||
-rw-r--r-- | netwerk/protocol/data/DataChannelParent.h | 41 | ||||
-rw-r--r-- | netwerk/protocol/data/moz.build | 24 | ||||
-rw-r--r-- | netwerk/protocol/data/nsDataChannel.cpp | 91 | ||||
-rw-r--r-- | netwerk/protocol/data/nsDataChannel.h | 28 | ||||
-rw-r--r-- | netwerk/protocol/data/nsDataHandler.cpp | 250 | ||||
-rw-r--r-- | netwerk/protocol/data/nsDataHandler.h | 41 | ||||
-rw-r--r-- | netwerk/protocol/data/nsDataModule.cpp | 21 |
10 files changed, 705 insertions, 0 deletions
diff --git a/netwerk/protocol/data/DataChannelChild.cpp b/netwerk/protocol/data/DataChannelChild.cpp new file mode 100644 index 000000000..137eb74b6 --- /dev/null +++ b/netwerk/protocol/data/DataChannelChild.cpp @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* vim: set ts=4 sw=4 sts=4 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 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "DataChannelChild.h" + +#include "mozilla/Unused.h" +#include "mozilla/net/NeckoChild.h" + +namespace mozilla { +namespace net { + +NS_IMPL_ISUPPORTS_INHERITED(DataChannelChild, nsDataChannel, nsIChildChannel) + +DataChannelChild::DataChannelChild(nsIURI* aURI) + : nsDataChannel(aURI) + , mIPCOpen(false) +{ +} + +DataChannelChild::~DataChannelChild() +{ +} + +NS_IMETHODIMP +DataChannelChild::ConnectParent(uint32_t aId) +{ + if (!gNeckoChild->SendPDataChannelConstructor(this, aId)) { + return NS_ERROR_FAILURE; + } + + // IPC now has a ref to us. + AddIPDLReference(); + return NS_OK; +} + +NS_IMETHODIMP +DataChannelChild::CompleteRedirectSetup(nsIStreamListener *aListener, + nsISupports *aContext) +{ + nsresult rv; + if (mLoadInfo && mLoadInfo->GetEnforceSecurity()) { + MOZ_ASSERT(!aContext, "aContext should be null!"); + rv = AsyncOpen2(aListener); + } + else { + rv = AsyncOpen(aListener, aContext); + } + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; + } + + if (mIPCOpen) { + Unused << Send__delete__(this); + } + return NS_OK; +} + +void +DataChannelChild::AddIPDLReference() +{ + AddRef(); + mIPCOpen = true; +} + +void +DataChannelChild::ActorDestroy(ActorDestroyReason why) +{ + MOZ_ASSERT(mIPCOpen); + mIPCOpen = false; + Release(); +} + +} // namespace net +} // namespace mozilla diff --git a/netwerk/protocol/data/DataChannelChild.h b/netwerk/protocol/data/DataChannelChild.h new file mode 100644 index 000000000..8fa42177a --- /dev/null +++ b/netwerk/protocol/data/DataChannelChild.h @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* vim: set ts=4 sw=4 sts=4 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 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef NS_DATACHANNELCHILD_H +#define NS_DATACHANNELCHILD_H + +#include "nsDataChannel.h" +#include "nsIChildChannel.h" +#include "nsISupportsImpl.h" + +#include "mozilla/net/PDataChannelChild.h" + +namespace mozilla { +namespace net { + +class DataChannelChild : public nsDataChannel + , public nsIChildChannel + , public PDataChannelChild +{ +public: + explicit DataChannelChild(nsIURI *uri); + + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_NSICHILDCHANNEL + +protected: + virtual void ActorDestroy(ActorDestroyReason why) override; + +private: + ~DataChannelChild(); + + void AddIPDLReference(); + + bool mIPCOpen; +}; + +} // namespace net +} // namespace mozilla + +#endif /* NS_DATACHANNELCHILD_H */ diff --git a/netwerk/protocol/data/DataChannelParent.cpp b/netwerk/protocol/data/DataChannelParent.cpp new file mode 100644 index 000000000..e1db0ab36 --- /dev/null +++ b/netwerk/protocol/data/DataChannelParent.cpp @@ -0,0 +1,89 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* vim: set ts=4 sw=4 sts=4 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 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "DataChannelParent.h" +#include "mozilla/Assertions.h" +#include "nsNetUtil.h" +#include "nsIChannel.h" + +namespace mozilla { +namespace net { + +NS_IMPL_ISUPPORTS(DataChannelParent, nsIParentChannel, nsIStreamListener) + +DataChannelParent::~DataChannelParent() +{ +} + +bool +DataChannelParent::Init(const uint32_t &channelId) +{ + nsCOMPtr<nsIChannel> channel; + MOZ_ALWAYS_SUCCEEDS( + NS_LinkRedirectChannels(channelId, this, getter_AddRefs(channel))); + + return true; +} + +NS_IMETHODIMP +DataChannelParent::SetParentListener(HttpChannelParentListener* aListener) +{ + // Nothing to do. + return NS_OK; +} + +NS_IMETHODIMP +DataChannelParent::NotifyTrackingProtectionDisabled() +{ + // Nothing to do. + return NS_OK; +} + +NS_IMETHODIMP +DataChannelParent::Delete() +{ + // Nothing to do. + return NS_OK; +} + +void +DataChannelParent::ActorDestroy(ActorDestroyReason why) +{ +} + +NS_IMETHODIMP +DataChannelParent::OnStartRequest(nsIRequest *aRequest, + nsISupports *aContext) +{ + // We don't have a way to prevent nsBaseChannel from calling AsyncOpen on + // the created nsDataChannel. We don't have anywhere to send the data in the + // parent, so abort the binding. + return NS_BINDING_ABORTED; +} + +NS_IMETHODIMP +DataChannelParent::OnStopRequest(nsIRequest *aRequest, + nsISupports *aContext, + nsresult aStatusCode) +{ + // See above. + MOZ_ASSERT(NS_FAILED(aStatusCode)); + return NS_OK; +} + +NS_IMETHODIMP +DataChannelParent::OnDataAvailable(nsIRequest *aRequest, + nsISupports *aContext, + nsIInputStream *aInputStream, + uint64_t aOffset, + uint32_t aCount) +{ + // See above. + MOZ_CRASH("Should never be called"); +} + +} // namespace net +} // namespace mozilla diff --git a/netwerk/protocol/data/DataChannelParent.h b/netwerk/protocol/data/DataChannelParent.h new file mode 100644 index 000000000..415672a44 --- /dev/null +++ b/netwerk/protocol/data/DataChannelParent.h @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* vim: set ts=4 sw=4 sts=4 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 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef NS_DATACHANNELPARENT_H +#define NS_DATACHANNELPARENT_H + +#include "nsIParentChannel.h" +#include "nsISupportsImpl.h" + +#include "mozilla/net/PDataChannelParent.h" + +namespace mozilla { +namespace net { + +// In order to support HTTP redirects to data:, we need to implement the HTTP +// redirection API, which requires a class that implements nsIParentChannel +// and which calls NS_LinkRedirectChannels. +class DataChannelParent : public nsIParentChannel + , public PDataChannelParent +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIPARENTCHANNEL + NS_DECL_NSIREQUESTOBSERVER + NS_DECL_NSISTREAMLISTENER + + MOZ_MUST_USE bool Init(const uint32_t& aArgs); + +private: + ~DataChannelParent(); + + virtual void ActorDestroy(ActorDestroyReason why) override; +}; + +} // namespace net +} // namespace mozilla + +#endif /* NS_DATACHANNELPARENT_H */ diff --git a/netwerk/protocol/data/moz.build b/netwerk/protocol/data/moz.build new file mode 100644 index 000000000..0958118fa --- /dev/null +++ b/netwerk/protocol/data/moz.build @@ -0,0 +1,24 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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 +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +EXPORTS.mozilla.net += [ + 'DataChannelParent.h', +] + +UNIFIED_SOURCES += [ + 'DataChannelChild.cpp', + 'DataChannelParent.cpp', + 'nsDataChannel.cpp', + 'nsDataHandler.cpp', +] + +include('/ipc/chromium/chromium-config.mozbuild') + +FINAL_LIBRARY = 'xul' +LOCAL_INCLUDES += [ + '/netwerk/base', +] + diff --git a/netwerk/protocol/data/nsDataChannel.cpp b/netwerk/protocol/data/nsDataChannel.cpp new file mode 100644 index 000000000..608a6c6e0 --- /dev/null +++ b/netwerk/protocol/data/nsDataChannel.cpp @@ -0,0 +1,91 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* 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 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// data implementation + +#include "nsDataChannel.h" + +#include "mozilla/Base64.h" +#include "nsIOService.h" +#include "nsDataHandler.h" +#include "nsIPipe.h" +#include "nsIInputStream.h" +#include "nsIOutputStream.h" +#include "nsEscape.h" + +using namespace mozilla; + +nsresult +nsDataChannel::OpenContentStream(bool async, nsIInputStream **result, + nsIChannel** channel) +{ + NS_ENSURE_TRUE(URI(), NS_ERROR_NOT_INITIALIZED); + + nsresult rv; + + nsAutoCString spec; + rv = URI()->GetAsciiSpec(spec); + if (NS_FAILED(rv)) return rv; + + nsCString contentType, contentCharset, dataBuffer; + bool lBase64; + rv = nsDataHandler::ParseURI(spec, contentType, &contentCharset, + lBase64, &dataBuffer); + if (NS_FAILED(rv)) + return rv; + + NS_UnescapeURL(dataBuffer); + + if (lBase64) { + // Don't allow spaces in base64-encoded content. This is only + // relevant for escaped spaces; other spaces are stripped in + // NewURI. + dataBuffer.StripWhitespace(); + } + + nsCOMPtr<nsIInputStream> bufInStream; + nsCOMPtr<nsIOutputStream> bufOutStream; + + // create an unbounded pipe. + rv = NS_NewPipe(getter_AddRefs(bufInStream), + getter_AddRefs(bufOutStream), + nsIOService::gDefaultSegmentSize, + UINT32_MAX, + async, true); + if (NS_FAILED(rv)) + return rv; + + uint32_t contentLen; + if (lBase64) { + const uint32_t dataLen = dataBuffer.Length(); + int32_t resultLen = 0; + if (dataLen >= 1 && dataBuffer[dataLen-1] == '=') { + if (dataLen >= 2 && dataBuffer[dataLen-2] == '=') + resultLen = dataLen-2; + else + resultLen = dataLen-1; + } else { + resultLen = dataLen; + } + resultLen = ((resultLen * 3) / 4); + + nsAutoCString decodedData; + rv = Base64Decode(dataBuffer, decodedData); + NS_ENSURE_SUCCESS(rv, rv); + rv = bufOutStream->Write(decodedData.get(), resultLen, &contentLen); + } else { + rv = bufOutStream->Write(dataBuffer.get(), dataBuffer.Length(), &contentLen); + } + if (NS_FAILED(rv)) + return rv; + + SetContentType(contentType); + SetContentCharset(contentCharset); + mContentLength = contentLen; + + bufInStream.forget(result); + + return NS_OK; +} diff --git a/netwerk/protocol/data/nsDataChannel.h b/netwerk/protocol/data/nsDataChannel.h new file mode 100644 index 000000000..c986fba1e --- /dev/null +++ b/netwerk/protocol/data/nsDataChannel.h @@ -0,0 +1,28 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* 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 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// data implementation header + +#ifndef nsDataChannel_h___ +#define nsDataChannel_h___ + +#include "nsBaseChannel.h" + +class nsIInputStream; + +class nsDataChannel : public nsBaseChannel +{ +public: + explicit nsDataChannel(nsIURI *uri) { + SetURI(uri); + } + +protected: + virtual MOZ_MUST_USE nsresult OpenContentStream(bool async, + nsIInputStream **result, + nsIChannel** channel); +}; + +#endif /* nsDataChannel_h___ */ diff --git a/netwerk/protocol/data/nsDataHandler.cpp b/netwerk/protocol/data/nsDataHandler.cpp new file mode 100644 index 000000000..b84b50d5b --- /dev/null +++ b/netwerk/protocol/data/nsDataHandler.cpp @@ -0,0 +1,250 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* 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 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsDataChannel.h" +#include "nsDataHandler.h" +#include "nsNetCID.h" +#include "nsError.h" +#include "DataChannelChild.h" +#include "plstr.h" + +static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID); + +//////////////////////////////////////////////////////////////////////////////// + +nsDataHandler::nsDataHandler() { +} + +nsDataHandler::~nsDataHandler() { +} + +NS_IMPL_ISUPPORTS(nsDataHandler, nsIProtocolHandler, nsISupportsWeakReference) + +nsresult +nsDataHandler::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult) { + + nsDataHandler* ph = new nsDataHandler(); + if (ph == nullptr) + return NS_ERROR_OUT_OF_MEMORY; + NS_ADDREF(ph); + nsresult rv = ph->QueryInterface(aIID, aResult); + NS_RELEASE(ph); + return rv; +} + +//////////////////////////////////////////////////////////////////////////////// +// nsIProtocolHandler methods: + +NS_IMETHODIMP +nsDataHandler::GetScheme(nsACString &result) { + result.AssignLiteral("data"); + return NS_OK; +} + +NS_IMETHODIMP +nsDataHandler::GetDefaultPort(int32_t *result) { + // no ports for data protocol + *result = -1; + return NS_OK; +} + +NS_IMETHODIMP +nsDataHandler::GetProtocolFlags(uint32_t *result) { + *result = URI_NORELATIVE | URI_NOAUTH | URI_INHERITS_SECURITY_CONTEXT | + URI_LOADABLE_BY_ANYONE | URI_NON_PERSISTABLE | URI_IS_LOCAL_RESOURCE | + URI_SYNC_LOAD_IS_OK; + return NS_OK; +} + +NS_IMETHODIMP +nsDataHandler::NewURI(const nsACString &aSpec, + const char *aCharset, // ignore charset info + nsIURI *aBaseURI, + nsIURI **result) { + nsresult rv; + RefPtr<nsIURI> uri; + + nsCString spec(aSpec); + + if (aBaseURI && !spec.IsEmpty() && spec[0] == '#') { + // Looks like a reference instead of a fully-specified URI. + // --> initialize |uri| as a clone of |aBaseURI|, with ref appended. + rv = aBaseURI->Clone(getter_AddRefs(uri)); + if (NS_FAILED(rv)) + return rv; + rv = uri->SetRef(spec); + } else { + // Otherwise, we'll assume |spec| is a fully-specified data URI + nsAutoCString contentType; + bool base64; + rv = ParseURI(spec, contentType, /* contentCharset = */ nullptr, + base64, /* dataBuffer = */ nullptr); + if (NS_FAILED(rv)) + return rv; + + // Strip whitespace unless this is text, where whitespace is important + // Don't strip escaped whitespace though (bug 391951) + if (base64 || (strncmp(contentType.get(),"text/",5) != 0 && + contentType.Find("xml") == kNotFound)) { + // it's ascii encoded binary, don't let any spaces in + if (!spec.StripWhitespace(mozilla::fallible)) { + return NS_ERROR_OUT_OF_MEMORY; + } + } + + uri = do_CreateInstance(kSimpleURICID, &rv); + if (NS_FAILED(rv)) + return rv; + rv = uri->SetSpec(spec); + } + + if (NS_FAILED(rv)) + return rv; + + uri.forget(result); + return rv; +} + +NS_IMETHODIMP +nsDataHandler::NewChannel2(nsIURI* uri, + nsILoadInfo* aLoadInfo, + nsIChannel** result) +{ + NS_ENSURE_ARG_POINTER(uri); + nsDataChannel* channel; + if (XRE_IsParentProcess()) { + channel = new nsDataChannel(uri); + } else { + channel = new mozilla::net::DataChannelChild(uri); + } + NS_ADDREF(channel); + + nsresult rv = channel->Init(); + if (NS_FAILED(rv)) { + NS_RELEASE(channel); + return rv; + } + + // set the loadInfo on the new channel + rv = channel->SetLoadInfo(aLoadInfo); + if (NS_FAILED(rv)) { + NS_RELEASE(channel); + return rv; + } + + *result = channel; + return NS_OK; +} + +NS_IMETHODIMP +nsDataHandler::NewChannel(nsIURI* uri, nsIChannel* *result) +{ + return NewChannel2(uri, nullptr, result); +} + +NS_IMETHODIMP +nsDataHandler::AllowPort(int32_t port, const char *scheme, bool *_retval) { + // don't override anything. + *_retval = false; + return NS_OK; +} + +#define BASE64_EXTENSION ";base64" + +nsresult +nsDataHandler::ParseURI(nsCString& spec, + nsCString& contentType, + nsCString* contentCharset, + bool& isBase64, + nsCString* dataBuffer) +{ + isBase64 = false; + + // move past "data:" + const char* roBuffer = (const char*) PL_strcasestr(spec.get(), "data:"); + if (!roBuffer) { + // malformed uri + return NS_ERROR_MALFORMED_URI; + } + roBuffer += sizeof("data:") - 1; + + // First, find the start of the data + const char* roComma = strchr(roBuffer, ','); + const char* roHash = strchr(roBuffer, '#'); + if (!roComma || (roHash && roHash < roComma)) { + return NS_ERROR_MALFORMED_URI; + } + + if (roComma == roBuffer) { + // nothing but data + contentType.AssignLiteral("text/plain"); + if (contentCharset) { + contentCharset->AssignLiteral("US-ASCII"); + } + } else { + // Make a copy of the non-data part so we can null out parts of it as + // we go. This copy will be a small number of chars, in contrast to the + // data which may be large. + char* buffer = PL_strndup(roBuffer, roComma - roBuffer); + + // determine if the data is base64 encoded. + char* base64 = PL_strcasestr(buffer, BASE64_EXTENSION); + if (base64) { + char *beyond = base64 + sizeof(BASE64_EXTENSION) - 1; + // Per the RFC 2397 grammar, "base64" MUST be at the end of the + // non-data part. + // + // But we also allow it in between parameters so a subsequent ";" + // is ok as well (this deals with *broken* data URIs, see bug + // 781693 for an example). Anything after "base64" in the non-data + // part will be discarded in this case, however. + if (*beyond == '\0' || *beyond == ';') { + isBase64 = true; + *base64 = '\0'; + } + } + + // everything else is content type + char *semiColon = (char *) strchr(buffer, ';'); + if (semiColon) + *semiColon = '\0'; + + if (semiColon == buffer || base64 == buffer) { + // there is no content type, but there are other parameters + contentType.AssignLiteral("text/plain"); + } else { + contentType.Assign(buffer); + ToLowerCase(contentType); + if (!contentType.StripWhitespace(mozilla::fallible)) { + return NS_ERROR_OUT_OF_MEMORY; + } + } + + if (semiColon && contentCharset) { + char *charset = PL_strcasestr(semiColon + 1, "charset="); + if (charset) { + contentCharset->Assign(charset + sizeof("charset=") - 1); + if (!contentCharset->StripWhitespace(mozilla::fallible)) { + return NS_ERROR_OUT_OF_MEMORY; + } + } + } + + free(buffer); + } + + if (dataBuffer) { + // Split encoded data from terminal "#ref" (if present) + const char* roData = roComma + 1; + bool ok = !roHash + ? dataBuffer->Assign(roData, mozilla::fallible) + : dataBuffer->Assign(roData, roHash - roData, mozilla::fallible); + if (!ok) { + return NS_ERROR_OUT_OF_MEMORY; + } + } + + return NS_OK; +} diff --git a/netwerk/protocol/data/nsDataHandler.h b/netwerk/protocol/data/nsDataHandler.h new file mode 100644 index 000000000..75f873e17 --- /dev/null +++ b/netwerk/protocol/data/nsDataHandler.h @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* 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 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef nsDataHandler_h___ +#define nsDataHandler_h___ + +#include "nsIProtocolHandler.h" +#include "nsWeakReference.h" + +class nsDataHandler : public nsIProtocolHandler + , public nsSupportsWeakReference +{ + virtual ~nsDataHandler(); + +public: + NS_DECL_ISUPPORTS + + // nsIProtocolHandler methods: + NS_DECL_NSIPROTOCOLHANDLER + + // nsDataHandler methods: + nsDataHandler(); + + // Define a Create method to be used with a factory: + static MOZ_MUST_USE nsresult + Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult); + + // Parse a data: URI and return the individual parts + // (the given spec will temporarily be modified but will be returned + // to the original before returning) + // contentCharset and dataBuffer can be nullptr if they are not needed. + static MOZ_MUST_USE nsresult ParseURI(nsCString& spec, + nsCString& contentType, + nsCString* contentCharset, + bool& isBase64, + nsCString* dataBuffer); +}; + +#endif /* nsDataHandler_h___ */ diff --git a/netwerk/protocol/data/nsDataModule.cpp b/netwerk/protocol/data/nsDataModule.cpp new file mode 100644 index 000000000..f96db8c2e --- /dev/null +++ b/netwerk/protocol/data/nsDataModule.cpp @@ -0,0 +1,21 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* 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 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsIModule.h" +#include "nsIGenericFactory.h" +#include "nsDataHandler.h" + +// The list of components we register +static const nsModuleComponentInfo components[] = { + { "Data Protocol Handler", + NS_DATAHANDLER_CID, + NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "data", + nsDataHandler::Create}, +}; + +NS_IMPL_NSGETMODULE(nsDataProtocolModule, components) + + + |