LCOV - code coverage report
Current view: top level - netwerk/protocol/res - ExtensionProtocolHandler.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 3 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 15 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #ifndef ExtensionProtocolHandler_h___
       7             : #define ExtensionProtocolHandler_h___
       8             : 
       9             : #include "mozilla/net/NeckoParent.h"
      10             : #include "mozilla/LazyIdleThread.h"
      11             : #include "SubstitutingProtocolHandler.h"
      12             : 
      13             : namespace mozilla {
      14             : namespace net {
      15             : 
      16             : class ExtensionProtocolHandler final : public nsISubstitutingProtocolHandler,
      17             :                                        public nsIProtocolHandlerWithDynamicFlags,
      18             :                                        public SubstitutingProtocolHandler,
      19             :                                        public nsSupportsWeakReference
      20             : {
      21             : public:
      22             :   NS_DECL_ISUPPORTS_INHERITED
      23             :   NS_DECL_NSIPROTOCOLHANDLERWITHDYNAMICFLAGS
      24           0 :   NS_FORWARD_NSIPROTOCOLHANDLER(SubstitutingProtocolHandler::)
      25           0 :   NS_FORWARD_NSISUBSTITUTINGPROTOCOLHANDLER(SubstitutingProtocolHandler::)
      26             : 
      27             :   static already_AddRefed<ExtensionProtocolHandler> GetSingleton();
      28             : 
      29             :   /**
      30             :    * To be called in the parent process to obtain an input stream for a
      31             :    * a web accessible resource from an unpacked WebExtension dir.
      32             :    *
      33             :    * @param aChildURI a moz-extension URI sent from the child that refers
      34             :    *        to a web accessible resource file in an enabled unpacked extension
      35             :    * @param aChildLoadInfo the loadinfo for the request sent from the child
      36             :    * @param aTerminateSender out param set to true when the params are invalid
      37             :    *        and indicate the child should be terminated. If |aChildURI| is
      38             :    *        not a moz-extension URI, the child is in an invalid state and
      39             :    *        should be terminated.
      40             :    * @return NS_OK with |aTerminateSender| set to false on success. On
      41             :    *         failure, returns an error and sets |aTerminateSender| to indicate
      42             :    *         whether or not the child process should be terminated.
      43             :    *         A moz-extension URI from the child that doesn't resolve to a
      44             :    *         resource file within the extension could be the result of a bug
      45             :    *         in the extension and doesn't result in |aTerminateSender| being
      46             :    *         set to true.
      47             :    */
      48             :   Result<nsCOMPtr<nsIInputStream>, nsresult> NewStream(nsIURI* aChildURI,
      49             :                                                        nsILoadInfo* aChildLoadInfo,
      50             :                                                        bool* aTerminateSender);
      51             : 
      52             :   /**
      53             :    * To be called in the parent process to obtain a file descriptor for an
      54             :    * enabled WebExtension JAR file.
      55             :    *
      56             :    * @param aChildURI a moz-extension URI sent from the child that refers
      57             :    *        to a web accessible resource file in an enabled unpacked extension
      58             :    * @param aChildLoadInfo the loadinfo for the request sent from the child
      59             :    * @param aTerminateSender out param set to true when the params are invalid
      60             :    *        and indicate the child should be terminated. If |aChildURI| is
      61             :    *        not a moz-extension URI, the child is in an invalid state and
      62             :    *        should be terminated.
      63             :    * @param aPromise a promise that will be resolved asynchronously when the
      64             :    *        file descriptor is available.
      65             :    * @return NS_OK with |aTerminateSender| set to false on success. On
      66             :    *         failure, returns an error and sets |aTerminateSender| to indicate
      67             :    *         whether or not the child process should be terminated.
      68             :    *         A moz-extension URI from the child that doesn't resolve to an
      69             :    *         enabled WebExtension JAR could be the result of a bug in the
      70             :    *         extension and doesn't result in |aTerminateSender| being
      71             :    *         set to true.
      72             :    */
      73             :   Result<Ok, nsresult> NewFD(nsIURI* aChildURI,
      74             :                              nsILoadInfo* aChildLoadInfo,
      75             :                              bool* aTerminateSender,
      76             :                              NeckoParent::GetExtensionFDResolver& aResolve);
      77             : 
      78             : protected:
      79           0 :   ~ExtensionProtocolHandler() {}
      80             : 
      81             : private:
      82             :   explicit ExtensionProtocolHandler();
      83             : 
      84             :   MOZ_MUST_USE bool ResolveSpecialCases(const nsACString& aHost,
      85             :                                         const nsACString& aPath,
      86             :                                         const nsACString& aPathname,
      87             :                                         nsACString& aResult) override;
      88             : 
      89             :   // |result| is an inout param.  On entry to this function, *result
      90             :   // is expected to be non-null and already addrefed.  This function
      91             :   // may release the object stored in *result on entry and write
      92             :   // a new pointer to an already addrefed channel to *result.
      93             :   virtual MOZ_MUST_USE nsresult SubstituteChannel(nsIURI* uri,
      94             :                                                   nsILoadInfo* aLoadInfo,
      95             :                                                   nsIChannel** result) override;
      96             : 
      97             :   /**
      98             :    * For moz-extension URI's that resolve to file or JAR URI's, replaces
      99             :    * the provided channel with a channel that will proxy the load to the
     100             :    * parent process. For moz-extension URI's that resolve to other types
     101             :    * of URI's (not file or JAR), the provide channel is not replaced and
     102             :    * NS_OK is returned.
     103             :    *
     104             :    * @param aURI the moz-extension URI
     105             :    * @param aLoadInfo the loadinfo for the request
     106             :    * @param aRetVal in/out channel param referring to the channel that
     107             :    *        might need to be substituted with a remote channel.
     108             :    * @return NS_OK if the channel does not need to be substituted or
     109             :    *         or the replacement channel was created successfully.
     110             :    *         Otherwise returns an error.
     111             :    */
     112             :   Result<Ok, nsresult> SubstituteRemoteChannel(nsIURI* aURI,
     113             :                                                nsILoadInfo* aLoadInfo,
     114             :                                                nsIChannel** aRetVal);
     115             : 
     116             :   /**
     117             :    * Replaces a file channel with a remote file channel for loading a
     118             :    * web accessible resource for an unpacked extension from the parent.
     119             :    *
     120             :    * @param aURI the moz-extension URI
     121             :    * @param aLoadInfo the loadinfo for the request
     122             :    * @param aResolvedFileSpec the resolved URI spec for the file.
     123             :    * @param aRetVal in/out param referring to the new remote channel.
     124             :    *        The reference to the input param file channel is dropped and
     125             :    *        replaced with a reference to a new channel that remotes
     126             :    *        the file access. The new channel encapsulates a request to
     127             :    *        the parent for an IPCStream for the file.
     128             :    */
     129             :   void SubstituteRemoteFileChannel(nsIURI* aURI,
     130             :                                    nsILoadInfo* aLoadinfo,
     131             :                                    nsACString& aResolvedFileSpec,
     132             :                                    nsIChannel** aRetVal);
     133             : 
     134             :   /**
     135             :    * Replaces a JAR channel with a remote JAR channel for loading a
     136             :    * an extension JAR file from the parent.
     137             :    *
     138             :    * @param aURI the moz-extension URI
     139             :    * @param aLoadInfo the loadinfo for the request
     140             :    * @param aResolvedFileSpec the resolved URI spec for the file.
     141             :    * @param aRetVal in/out param referring to the new remote channel.
     142             :    *        The input param JAR channel is replaced with a new channel
     143             :    *        that remotes the JAR file access. The new channel encapsulates
     144             :    *        a request to the parent for the JAR file FD.
     145             :    */
     146             :   Result<Ok, nsresult> SubstituteRemoteJarChannel(nsIURI* aURI,
     147             :                                                   nsILoadInfo* aLoadinfo,
     148             :                                                   nsACString& aResolvedSpec,
     149             :                                                   nsIChannel** aRetVal);
     150             : 
     151             : #if !defined(XP_WIN) && defined(MOZ_CONTENT_SANDBOX)
     152             :   /**
     153             :    * Sets the aResult outparam to true if we are a developer build with the
     154             :    * repo dir environment variable set and the requested file resides in the
     155             :    * repo dir. Developer builds may load system extensions with web-accessible
     156             :    * resources that are symlinks to files in the repo dir. This method is for
     157             :    * checking if an unpacked resource requested by the child is from the repo.
     158             :    * The requested file must be already Normalized().
     159             :    *
     160             :    * @param aRequestedFile the requested web-accessible resource file. Argument
     161             :    *        must be an nsIFile for which Normalize() has already been called.
     162             :    * @param aResult outparam set to true on development builds when the
     163             :    *        requested file resides in the repo
     164             :    */
     165             :   Result<Ok, nsresult> DevRepoContains(nsIFile* aRequestedFile, bool *aResult);
     166             : 
     167             :   // On development builds, this points to development repo. Lazily set.
     168             :   nsCOMPtr<nsIFile> mDevRepo;
     169             : 
     170             :   // Set to true once we've already tried to load the dev repo path,
     171             :   // allowing for lazy initialization of |mDevRepo|.
     172             :   bool mAlreadyCheckedDevRepo;
     173             : #endif /* !defined(XP_WIN) && defined(MOZ_CONTENT_SANDBOX) */
     174             : 
     175             :   // Used for opening JAR files off the main thread when we just need to
     176             :   // obtain a file descriptor to send back to the child.
     177             :   RefPtr<mozilla::LazyIdleThread> mFileOpenerThread;
     178             : 
     179             :   // To allow parent IPDL actors to invoke methods on this handler when
     180             :   // handling moz-extension requests from the child.
     181             :   static StaticRefPtr<ExtensionProtocolHandler> sSingleton;
     182             : 
     183             :   // Set to true when this instance of the handler must proxy loads of
     184             :   // extension web-accessible resources to the parent process.
     185             :   bool mUseRemoteFileChannels;
     186             : };
     187             : 
     188             : } // namespace net
     189             : } // namespace mozilla
     190             : 
     191             : #endif /* ExtensionProtocolHandler_h___ */

Generated by: LCOV version 1.13