LCOV - code coverage report
Current view: top level - dom/file - nsHostObjectProtocolHandler.h (source / functions) Hit Total Coverage
Test: output.info Lines: 2 5 40.0 %
Date: 2017-07-14 16:53:18 Functions: 1 9 11.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #ifndef nsHostObjectProtocolHandler_h
       8             : #define nsHostObjectProtocolHandler_h
       9             : 
      10             : #include "mozilla/Attributes.h"
      11             : #include "nsIProtocolHandler.h"
      12             : #include "nsIURI.h"
      13             : #include "nsCOMPtr.h"
      14             : #include "nsIInputStream.h"
      15             : #include "nsTArray.h"
      16             : 
      17             : #define BLOBURI_SCHEME "blob"
      18             : #define FONTTABLEURI_SCHEME "moz-fonttable"
      19             : #define RTSPURI_SCHEME "rtsp"
      20             : 
      21             : class nsIPrincipal;
      22             : 
      23             : namespace mozilla {
      24             : class BlobURLsReporter;
      25             : class DOMMediaStream;
      26             : 
      27             : namespace dom {
      28             : class BlobImpl;
      29             : class BlobURLRegistrationData;
      30             : class ContentParent;
      31             : class MediaSource;
      32             : } // namespace dom
      33             : } // namespace mozilla
      34             : 
      35             : class nsHostObjectProtocolHandler : public nsIProtocolHandler
      36             :                                   , public nsIProtocolHandlerWithDynamicFlags
      37             : {
      38             : public:
      39             :   nsHostObjectProtocolHandler();
      40             :   NS_DECL_ISUPPORTS
      41             : 
      42             :   // nsIProtocolHandler methods, except for GetScheme which is only defined
      43             :   // in subclasses.
      44             :   NS_IMETHOD GetDefaultPort(int32_t *aDefaultPort) override;
      45             :   NS_IMETHOD GetProtocolFlags(uint32_t *aProtocolFlags) override;
      46             :   NS_IMETHOD NewURI(const nsACString & aSpec, const char * aOriginCharset, nsIURI *aBaseURI, nsIURI * *_retval) override;
      47             :   NS_IMETHOD NewChannel2(nsIURI *aURI, nsILoadInfo *aLoadinfo, nsIChannel * *_retval) override;
      48             :   NS_IMETHOD NewChannel(nsIURI *aURI, nsIChannel * *_retval) override;
      49             :   NS_IMETHOD AllowPort(int32_t port, const char * scheme, bool *_retval) override;
      50             : 
      51             :   // nsIProtocolHandlerWithDynamicFlags methods
      52             :   NS_IMETHOD GetFlagsForURI(nsIURI *aURI, uint32_t *aResult) override;
      53             : 
      54             :   // If principal is not null, its origin will be used to generate the URI.
      55             :   static nsresult GenerateURIString(const nsACString &aScheme,
      56             :                                     nsIPrincipal* aPrincipal,
      57             :                                     nsACString &aUri);
      58             :   static nsresult GenerateURIStringForBlobURL(nsIPrincipal* aPrincipal,
      59             :                                               nsACString &aUri);
      60             : 
      61             :   // Methods for managing uri->object mapping
      62             :   // AddDataEntry creates the URI with the given scheme and returns it in aUri
      63             :   static nsresult AddDataEntry(mozilla::dom::BlobImpl* aBlobImpl,
      64             :                                nsIPrincipal* aPrincipal,
      65             :                                nsACString& aUri);
      66             :   static nsresult AddDataEntry(mozilla::DOMMediaStream* aMediaStream,
      67             :                                nsIPrincipal* aPrincipal,
      68             :                                nsACString& aUri);
      69             :   static nsresult AddDataEntry(mozilla::dom::MediaSource* aMediaSource,
      70             :                                nsIPrincipal* aPrincipal,
      71             :                                nsACString& aUri);
      72             :   // IPC only
      73             :   static nsresult AddDataEntry(const nsACString& aURI,
      74             :                                nsIPrincipal* aPrincipal,
      75             :                                mozilla::dom::BlobImpl* aBlobImpl);
      76             : 
      77             :   static void RemoveDataEntry(const nsACString& aUri,
      78             :                               bool aBroadcastToOTherProcesses = true);
      79             : 
      80             :   // This is for IPC only.
      81             :   static void RemoveDataEntries();
      82             : 
      83             :   static bool HasDataEntry(const nsACString& aUri);
      84             : 
      85             :   static nsIPrincipal* GetDataEntryPrincipal(const nsACString& aUri);
      86             :   static void Traverse(const nsACString& aUri, nsCycleCollectionTraversalCallback& aCallback);
      87             : 
      88             :   static bool
      89             :   GetAllBlobURLEntries(nsTArray<mozilla::dom::BlobURLRegistrationData>& aRegistrations,
      90             :                        mozilla::dom::ContentParent* aCP);
      91             : 
      92             : protected:
      93           0 :   virtual ~nsHostObjectProtocolHandler() {}
      94             : 
      95             : private:
      96             :   static void Init();
      97             : };
      98             : 
      99           0 : class nsBlobProtocolHandler : public nsHostObjectProtocolHandler
     100             : {
     101             : public:
     102             :   NS_IMETHOD GetProtocolFlags(uint32_t *aProtocolFlags) override;
     103             :   NS_IMETHOD GetScheme(nsACString &result) override;
     104             : };
     105             : 
     106           0 : class nsFontTableProtocolHandler : public nsHostObjectProtocolHandler
     107             : {
     108             : public:
     109             :   NS_IMETHOD GetProtocolFlags(uint32_t *aProtocolFlags) override;
     110             :   NS_IMETHOD GetScheme(nsACString &result) override;
     111             :   NS_IMETHOD NewURI(const nsACString & aSpec,
     112             :                     const char *aOriginCharset,
     113             :                     nsIURI *aBaseURI,
     114             :                     nsIURI **_retval) override;
     115             : };
     116             : 
     117             : bool IsBlobURI(nsIURI* aUri);
     118             : bool IsMediaStreamURI(nsIURI* aUri);
     119             : bool IsMediaSourceURI(nsIURI* aUri);
     120             : 
     121             : inline bool IsRtspURI(nsIURI* aUri)
     122             : {
     123             :   bool isRtsp;
     124             :   return NS_SUCCEEDED(aUri->SchemeIs(RTSPURI_SCHEME, &isRtsp)) && isRtsp;
     125             : }
     126             : 
     127          42 : inline bool IsFontTableURI(nsIURI* aUri)
     128             : {
     129             :   bool isFont;
     130          42 :   return NS_SUCCEEDED(aUri->SchemeIs(FONTTABLEURI_SCHEME, &isFont)) && isFont;
     131             : }
     132             : 
     133             : extern nsresult
     134             : NS_GetBlobForBlobURI(nsIURI* aURI, mozilla::dom::BlobImpl** aBlob);
     135             : 
     136             : extern nsresult
     137             : NS_GetBlobForBlobURISpec(const nsACString& aSpec, mozilla::dom::BlobImpl** aBlob);
     138             : 
     139             : extern nsresult
     140             : NS_GetStreamForBlobURI(nsIURI* aURI, nsIInputStream** aStream);
     141             : 
     142             : extern nsresult
     143             : NS_GetStreamForMediaStreamURI(nsIURI* aURI, mozilla::DOMMediaStream** aStream);
     144             : 
     145             : extern nsresult
     146             : NS_GetSourceForMediaSourceURI(nsIURI* aURI, mozilla::dom::MediaSource** aSource);
     147             : 
     148             : #endif /* nsHostObjectProtocolHandler_h */

Generated by: LCOV version 1.13