LCOV - code coverage report
Current view: top level - toolkit/components/extensions - ExtensionPolicyService.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 11 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 13 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*-  Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
       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 mozilla_ExtensionPolicyService_h
       7             : #define mozilla_ExtensionPolicyService_h
       8             : 
       9             : #include "mozilla/extensions/WebExtensionPolicy.h"
      10             : #include "nsCOMPtr.h"
      11             : #include "nsCycleCollectionParticipant.h"
      12             : #include "nsHashKeys.h"
      13             : #include "nsIAddonPolicyService.h"
      14             : #include "nsIAtom.h"
      15             : #include "nsIObserver.h"
      16             : #include "nsIObserverService.h"
      17             : #include "nsISupports.h"
      18             : #include "nsPointerHashKeys.h"
      19             : #include "nsRefPtrHashtable.h"
      20             : 
      21             : class nsIChannel;
      22             : class nsIObserverService;
      23             : class nsIDocument;
      24             : class nsIPIDOMWindowOuter;
      25             : 
      26             : namespace mozilla {
      27             : namespace extensions {
      28             :   class DocInfo;
      29             : }
      30             : 
      31             : using extensions::DocInfo;
      32             : using extensions::WebExtensionPolicy;
      33             : 
      34             : class ExtensionPolicyService final : public nsIAddonPolicyService
      35             :                                    , public nsIObserver
      36             : {
      37             : public:
      38           0 :   NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(ExtensionPolicyService,
      39             :                                            nsIAddonPolicyService)
      40             :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
      41             :   NS_DECL_NSIADDONPOLICYSERVICE
      42             :   NS_DECL_NSIOBSERVER
      43             : 
      44             :   static ExtensionPolicyService& GetSingleton();
      45             : 
      46           0 :   static already_AddRefed<ExtensionPolicyService> GetInstance()
      47             :   {
      48           0 :     return do_AddRef(&GetSingleton());
      49             :   }
      50             : 
      51             :   WebExtensionPolicy*
      52           0 :   GetByID(const nsIAtom* aAddonId)
      53             :   {
      54           0 :     return mExtensions.GetWeak(aAddonId);
      55             :   }
      56             : 
      57           0 :   WebExtensionPolicy* GetByID(const nsAString& aAddonId)
      58             :   {
      59           0 :     nsCOMPtr<nsIAtom> atom = NS_AtomizeMainThread(aAddonId);
      60           0 :     return GetByID(atom);
      61             :   }
      62             : 
      63             :   WebExtensionPolicy* GetByURL(const extensions::URLInfo& aURL);
      64             : 
      65           0 :   WebExtensionPolicy* GetByHost(const nsACString& aHost) const
      66             :   {
      67           0 :     return mExtensionHosts.GetWeak(aHost);
      68             :   }
      69             : 
      70             :   void GetAll(nsTArray<RefPtr<WebExtensionPolicy>>& aResult);
      71             : 
      72             :   bool RegisterExtension(WebExtensionPolicy& aPolicy);
      73             :   bool UnregisterExtension(WebExtensionPolicy& aPolicy);
      74             : 
      75             :   void BaseCSP(nsAString& aDefaultCSP) const;
      76             :   void DefaultCSP(nsAString& aDefaultCSP) const;
      77             : 
      78             :   bool IsExtensionProcess() const;
      79             : 
      80             : protected:
      81           0 :   virtual ~ExtensionPolicyService() = default;
      82             : 
      83             : private:
      84             :   ExtensionPolicyService();
      85             : 
      86             :   void RegisterObservers();
      87             :   void UnregisterObservers();
      88             : 
      89             :   void CheckRequest(nsIChannel* aChannel);
      90             :   void CheckDocument(nsIDocument* aDocument);
      91             :   void CheckWindow(nsPIDOMWindowOuter* aWindow);
      92             : 
      93             :   void CheckContentScripts(const DocInfo& aDocInfo, bool aIsPreload);
      94             : 
      95             :   nsRefPtrHashtable<nsPtrHashKey<const nsIAtom>, WebExtensionPolicy> mExtensions;
      96             :   nsRefPtrHashtable<nsCStringHashKey, WebExtensionPolicy> mExtensionHosts;
      97             : 
      98             :   nsCOMPtr<nsIObserverService> mObs;
      99             : 
     100             :   static bool sRemoteExtensions;
     101             : };
     102             : 
     103             : } // namespace mozilla
     104             : 
     105             : #endif // mozilla_ExtensionPolicyService_h

Generated by: LCOV version 1.13