Bug 792675. Part 5: Extend nsHostObjectProtocolHandler with support for 'mediastream' scheme. r=sicking

--HG--
rename : content/base/public/nsBlobProtocolHandler.h => content/base/public/nsHostObjectProtocolHandler.h
rename : content/base/src/nsBlobProtocolHandler.cpp => content/base/src/nsHostObjectProtocolHandler.cpp
rename : content/base/src/nsBlobURI.h => content/base/src/nsHostObjectURI.h
extra : rebase_source : aea1ab3b9eed985ea238d2e9fb74bf3b2f574756
This commit is contained in:
Robert O'Callahan 2012-09-25 15:24:44 +12:00
parent d723594f8f
commit 5b4fb3c358
4 changed files with 53 additions and 2 deletions

View File

@ -10,8 +10,10 @@
#include "nsCOMPtr.h"
#define BLOBURI_SCHEME "blob"
#define MEDIASTREAMURI_SCHEME "mediastream"
class nsIDOMBlob;
class nsIDOMMediaStream;
class nsIPrincipal;
class nsIInputStream;
@ -44,17 +46,36 @@ public:
NS_IMETHOD GetScheme(nsACString &result);
};
class nsMediaStreamProtocolHandler : public nsHostObjectProtocolHandler
{
public:
NS_IMETHOD GetScheme(nsACString &result);
};
inline bool IsBlobURI(nsIURI* aUri)
{
bool isBlob;
return NS_SUCCEEDED(aUri->SchemeIs(BLOBURI_SCHEME, &isBlob)) && isBlob;
}
inline bool IsMediaStreamURI(nsIURI* aUri)
{
bool isStream;
return NS_SUCCEEDED(aUri->SchemeIs(MEDIASTREAMURI_SCHEME, &isStream)) && isStream;
}
extern nsresult
NS_GetStreamForBlobURI(nsIURI* aURI, nsIInputStream** aStream);
extern nsresult
NS_GetStreamForMediaStreamURI(nsIURI* aURI, nsIDOMMediaStream** aStream);
#define NS_BLOBPROTOCOLHANDLER_CID \
{ 0xb43964aa, 0xa078, 0x44b2, \
{ 0xb0, 0x6b, 0xfd, 0x4d, 0x1b, 0x17, 0x2e, 0x66 } }
#define NS_MEDIASTREAMPROTOCOLHANDLER_CID \
{ 0x27d1fa24, 0x2b73, 0x4db3, \
{ 0xab, 0x48, 0xb9, 0x83, 0x83, 0x40, 0xe0, 0x81 } }
#endif /* nsHostObjectProtocolHandler_h */

View File

@ -9,12 +9,13 @@
#include "nsNetUtil.h"
#include "nsIPrincipal.h"
#include "nsIDOMFile.h"
#include "nsIDOMMediaStream.h"
// -----------------------------------------------------------------------
// Hash table
struct DataInfo
{
// mObject must be an nsIDOMBlob
// mObject must be an nsIDOMBlob or an nsIDOMMediaStream
nsCOMPtr<nsISupports> mObject;
nsCOMPtr<nsIPrincipal> mPrincipal;
};
@ -223,6 +224,13 @@ nsBlobProtocolHandler::GetScheme(nsACString &result)
return NS_OK;
}
NS_IMETHODIMP
nsMediaStreamProtocolHandler::GetScheme(nsACString &result)
{
result.AssignLiteral(MEDIASTREAMURI_SCHEME);
return NS_OK;
}
nsresult
NS_GetStreamForBlobURI(nsIURI* aURI, nsIInputStream** aStream)
{
@ -237,3 +245,20 @@ NS_GetStreamForBlobURI(nsIURI* aURI, nsIInputStream** aStream)
return blob->GetInternalStream(aStream);
}
nsresult
NS_GetStreamForMediaStreamURI(nsIURI* aURI, nsIDOMMediaStream** aStream)
{
NS_ASSERTION(IsMediaStreamURI(aURI), "Only call this with mediastream URIs");
*aStream = nullptr;
nsCOMPtr<nsIDOMMediaStream> stream = do_QueryInterface(GetDataObject(aURI));
if (!stream) {
return NS_ERROR_DOM_BAD_URI;
}
*aStream = stream;
NS_ADDREF(*aStream);
return NS_OK;
}

View File

@ -13,7 +13,8 @@
#include "nsSimpleURI.h"
/**
* These URIs refer to host objects: Blobs, with scheme "blob".
* These URIs refer to host objects: Blobs, with scheme "blob", and
* MediaStreams, with scheme "mediastream".
*/
class nsHostObjectURI : public nsSimpleURI,
public nsIURIWithPrincipal

View File

@ -278,6 +278,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsDOMFileReader, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(ArchiveReader)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFormData)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBlobProtocolHandler)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMediaStreamProtocolHandler)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHostObjectURI)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDOMParser)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsDOMStorageManager,
@ -773,6 +774,7 @@ NS_DEFINE_NAMED_CID(NS_FILEREADER_CID);
NS_DEFINE_NAMED_CID(NS_ARCHIVEREADER_CID);
NS_DEFINE_NAMED_CID(NS_FORMDATA_CID);
NS_DEFINE_NAMED_CID(NS_BLOBPROTOCOLHANDLER_CID);
NS_DEFINE_NAMED_CID(NS_MEDIASTREAMPROTOCOLHANDLER_CID);
NS_DEFINE_NAMED_CID(NS_HOSTOBJECTURI_CID);
NS_DEFINE_NAMED_CID(NS_XMLHTTPREQUEST_CID);
NS_DEFINE_NAMED_CID(NS_EVENTSOURCE_CID);
@ -1058,6 +1060,7 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
{ &kNS_ARCHIVEREADER_CID, false, NULL, ArchiveReaderConstructor },
{ &kNS_FORMDATA_CID, false, NULL, nsFormDataConstructor },
{ &kNS_BLOBPROTOCOLHANDLER_CID, false, NULL, nsBlobProtocolHandlerConstructor },
{ &kNS_MEDIASTREAMPROTOCOLHANDLER_CID, false, NULL, nsMediaStreamProtocolHandlerConstructor },
{ &kNS_HOSTOBJECTURI_CID, false, NULL, nsHostObjectURIConstructor },
{ &kNS_XMLHTTPREQUEST_CID, false, NULL, nsXMLHttpRequestConstructor },
{ &kNS_EVENTSOURCE_CID, false, NULL, nsEventSourceConstructor },
@ -1206,6 +1209,7 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = {
{ NS_ARCHIVEREADER_CONTRACTID, &kNS_ARCHIVEREADER_CID },
{ NS_FORMDATA_CONTRACTID, &kNS_FORMDATA_CID },
{ NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX BLOBURI_SCHEME, &kNS_BLOBPROTOCOLHANDLER_CID },
{ NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX MEDIASTREAMURI_SCHEME, &kNS_MEDIASTREAMPROTOCOLHANDLER_CID },
{ NS_XMLHTTPREQUEST_CONTRACTID, &kNS_XMLHTTPREQUEST_CID },
{ NS_EVENTSOURCE_CONTRACTID, &kNS_EVENTSOURCE_CID },
{ NS_DOMACTIVITY_CONTRACTID, &kNS_DOMACTIVITY_CID },