Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 792675. Part 4: Refactor nsBlobURI/nsBlobProtocolHandler to nsHos…
Browse files Browse the repository at this point in the history
…tObjectURI/nsHostObjectProtocolHandler. r=sicking

The code to handle MediaStream URIs is almost the same as for Blobs, so share it.
nsHostObjectProtocolHandler is modified a bit to simplify method names. Also
we make nsHostObjectProtocolHandler::AddDataEntry take responsibility for
generating the URI to avoid duplicating that code later.
We need separate subclasses for each kind of host object protocol handler,
but we don't need separate subclasses for each kind of host object URI.
  • Loading branch information
rocallahan committed Sep 25, 2012
1 parent 9b3cb26 commit f0e7441
Show file tree
Hide file tree
Showing 17 changed files with 411 additions and 367 deletions.
2 changes: 1 addition & 1 deletion content/base/public/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ nsReferencedElement.h \
nsTreeSanitizer.h \
nsXMLNameSpaceMap.h \
nsIXFormsUtilityService.h \
nsBlobProtocolHandler.h \
nsHostObjectProtocolHandler.h \
$(NULL)

EXPORTS_NAMESPACES = mozilla/dom mozilla
Expand Down
51 changes: 0 additions & 51 deletions content/base/public/nsBlobProtocolHandler.h

This file was deleted.

60 changes: 60 additions & 0 deletions content/base/public/nsHostObjectProtocolHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* 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 nsHostObjectProtocolHandler_h
#define nsHostObjectProtocolHandler_h

#include "nsIProtocolHandler.h"
#include "nsIURI.h"
#include "nsCOMPtr.h"

#define BLOBURI_SCHEME "blob"

class nsIDOMBlob;
class nsIPrincipal;
class nsIInputStream;

class nsHostObjectProtocolHandler : public nsIProtocolHandler
{
public:
NS_DECL_ISUPPORTS

// nsIProtocolHandler methods, except for GetScheme which is only defined
// in subclasses.
NS_IMETHOD GetDefaultPort(int32_t *aDefaultPort);
NS_IMETHOD GetProtocolFlags(uint32_t *aProtocolFlags);
NS_IMETHOD NewURI(const nsACString & aSpec, const char * aOriginCharset, nsIURI *aBaseURI, nsIURI * *_retval);
NS_IMETHOD NewChannel(nsIURI *aURI, nsIChannel * *_retval);
NS_IMETHOD AllowPort(int32_t port, const char * scheme, bool *_retval);

// Methods for managing uri->object mapping
// AddDataEntry creates the URI with the given scheme and returns it in aUri
static nsresult AddDataEntry(const nsACString& aScheme,
nsISupports* aObject,
nsIPrincipal* aPrincipal,
nsACString& aUri);
static void RemoveDataEntry(const nsACString& aUri);
static nsIPrincipal* GetDataEntryPrincipal(const nsACString& aUri);
};

class nsBlobProtocolHandler : public nsHostObjectProtocolHandler
{
public:
NS_IMETHOD GetScheme(nsACString &result);
};

inline bool IsBlobURI(nsIURI* aUri)
{
bool isBlob;
return NS_SUCCEEDED(aUri->SchemeIs(BLOBURI_SCHEME, &isBlob)) && isBlob;
}

extern nsresult
NS_GetStreamForBlobURI(nsIURI* aURI, nsIInputStream** aStream);

#define NS_BLOBPROTOCOLHANDLER_CID \
{ 0xb43964aa, 0xa078, 0x44b2, \
{ 0xb0, 0x6b, 0xfd, 0x4d, 0x1b, 0x17, 0x2e, 0x66 } }

#endif /* nsHostObjectProtocolHandler_h */
12 changes: 6 additions & 6 deletions content/base/public/nsIDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class Element;
} // namespace mozilla

#define NS_IDOCUMENT_IID \
{ 0x0e1324c9, 0xc997, 0x447e, \
{ 0xbc, 0xd9, 0xa6, 0x57, 0x80, 0x29, 0x91, 0xe4 } }
{ 0x20d19edb, 0xa74c, 0x4ce4, \
{ 0xb2, 0x7c, 0x5b, 0xdd, 0x6f, 0xbd, 0x2b, 0x66 } }

// Flag for AddStyleSheet().
#define NS_STYLESHEET_FROM_CATALOG (1 << 0)
Expand Down Expand Up @@ -1557,13 +1557,13 @@ class nsIDocument : public nsINode
virtual nsISupports* GetCurrentContentSink() = 0;

/**
* Register/Unregister a filedata uri as being "owned" by this document.
* Register/Unregister a hostobject uri as being "owned" by this document.
* I.e. that its lifetime is connected with this document. When the document
* goes away it should "kill" the uri by calling
* nsBlobProtocolHandler::RemoveFileDataEntry
* nsHostObjectProtocolHandler::RemoveDataEntry
*/
virtual void RegisterFileDataUri(const nsACString& aUri) = 0;
virtual void UnregisterFileDataUri(const nsACString& aUri) = 0;
virtual void RegisterHostObjectUri(const nsACString& aUri) = 0;
virtual void UnregisterHostObjectUri(const nsACString& aUri) = 0;

virtual void SetScrollToRef(nsIURI *aDocumentURI) = 0;
virtual void ScrollToRef() = 0;
Expand Down
4 changes: 2 additions & 2 deletions content/base/src/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ CPPSRCS = \
nsXMLNameSpaceMap.cpp \
FragmentOrElement.cpp \
Link.cpp \
nsBlobProtocolHandler.cpp \
nsBlobURI.cpp \
nsHostObjectProtocolHandler.cpp \
nsHostObjectURI.cpp \
nsFrameMessageManager.cpp \
nsInProcessTabChildGlobal.cpp \
ThirdPartyUtil.cpp \
Expand Down
217 changes: 0 additions & 217 deletions content/base/src/nsBlobProtocolHandler.cpp

This file was deleted.

Loading

0 comments on commit f0e7441

Please sign in to comment.