LCOV - code coverage report
Current view: top level - dom/base - nsContentPermissionHelper.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 13 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 6 0.0 %
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 nsContentPermissionHelper_h
       8             : #define nsContentPermissionHelper_h
       9             : 
      10             : #include "nsIContentPermissionPrompt.h"
      11             : #include "nsTArray.h"
      12             : #include "nsIMutableArray.h"
      13             : #include "mozilla/dom/PContentPermissionRequestChild.h"
      14             : #include "mozilla/dom/ipc/IdType.h"
      15             : #include "nsIDOMEventListener.h"
      16             : 
      17             : // Microsoft's API Name hackery sucks
      18             : // XXXbz Doing this in a header is a gigantic footgun. See
      19             : // https://bugzilla.mozilla.org/show_bug.cgi?id=932421#c3 for why.
      20             : #undef LoadImage
      21             : 
      22             : class nsPIDOMWindowInner;
      23             : class nsContentPermissionRequestProxy;
      24             : class VisibilityChangeListener;
      25             : 
      26             : // Forward declare IPC::Principal here which is defined in
      27             : // PermissionMessageUtils.h. Include this file will transitively includes
      28             : // "windows.h" and it defines
      29             : //   #define CreateEvent CreateEventW
      30             : //   #define LoadImage LoadImageW
      31             : // That will mess up windows build.
      32             : namespace IPC {
      33             : class Principal;
      34             : } // namespace IPC
      35             : 
      36             : namespace mozilla {
      37             : namespace dom {
      38             : 
      39             : class Element;
      40             : class PermissionRequest;
      41             : class ContentPermissionRequestParent;
      42             : class PContentPermissionRequestParent;
      43             : 
      44             : class ContentPermissionType : public nsIContentPermissionType
      45             : {
      46             : public:
      47             :   NS_DECL_ISUPPORTS
      48             :   NS_DECL_NSICONTENTPERMISSIONTYPE
      49             : 
      50             :   ContentPermissionType(const nsACString& aType,
      51             :                         const nsACString& aAccess,
      52             :                         const nsTArray<nsString>& aOptions);
      53             : 
      54             : protected:
      55             :   virtual ~ContentPermissionType();
      56             : 
      57             :   nsCString mType;
      58             :   nsCString mAccess;
      59             :   nsTArray<nsString> mOptions;
      60             : };
      61             : 
      62             : class nsContentPermissionUtils
      63             : {
      64             : public:
      65             :   static uint32_t
      66             :   ConvertPermissionRequestToArray(nsTArray<PermissionRequest>& aSrcArray,
      67             :                                   nsIMutableArray* aDesArray);
      68             : 
      69             :   static uint32_t
      70             :   ConvertArrayToPermissionRequest(nsIArray* aSrcArray,
      71             :                                   nsTArray<PermissionRequest>& aDesArray);
      72             : 
      73             :   static nsresult
      74             :   CreatePermissionArray(const nsACString& aType,
      75             :                         const nsACString& aAccess,
      76             :                         const nsTArray<nsString>& aOptions,
      77             :                         nsIArray** aTypesArray);
      78             : 
      79             :   static PContentPermissionRequestParent*
      80             :   CreateContentPermissionRequestParent(const nsTArray<PermissionRequest>& aRequests,
      81             :                                        Element* element,
      82             :                                        const IPC::Principal& principal,
      83             :                                        const TabId& aTabId);
      84             : 
      85             :   static nsresult
      86             :   AskPermission(nsIContentPermissionRequest* aRequest,
      87             :                 nsPIDOMWindowInner* aWindow);
      88             : 
      89             :   static nsTArray<PContentPermissionRequestParent*>
      90             :   GetContentPermissionRequestParentById(const TabId& aTabId);
      91             : 
      92             :   static void
      93             :   NotifyRemoveContentPermissionRequestParent(PContentPermissionRequestParent* aParent);
      94             : 
      95             :   static nsTArray<PContentPermissionRequestChild*>
      96             :   GetContentPermissionRequestChildById(const TabId& aTabId);
      97             : 
      98             :   static void
      99             :   NotifyRemoveContentPermissionRequestChild(PContentPermissionRequestChild* aChild);
     100             : };
     101             : 
     102             : class nsContentPermissionRequester final : public nsIContentPermissionRequester
     103             : {
     104             : public:
     105             :   NS_DECL_ISUPPORTS
     106             :   NS_DECL_NSICONTENTPERMISSIONREQUESTER
     107             : 
     108             :   explicit nsContentPermissionRequester(nsPIDOMWindowInner* aWindow);
     109             : 
     110             : private:
     111             :   virtual ~nsContentPermissionRequester();
     112             : 
     113             :   nsWeakPtr mWindow;
     114             :   RefPtr<VisibilityChangeListener> mListener;
     115             : };
     116             : 
     117             : } // namespace dom
     118             : } // namespace mozilla
     119             : 
     120             : using mozilla::dom::ContentPermissionRequestParent;
     121             : 
     122             : class nsContentPermissionRequestProxy : public nsIContentPermissionRequest
     123             : {
     124             : public:
     125             :   NS_DECL_ISUPPORTS
     126             :   NS_DECL_NSICONTENTPERMISSIONREQUEST
     127             : 
     128             :   nsContentPermissionRequestProxy();
     129             : 
     130             :   nsresult Init(const nsTArray<mozilla::dom::PermissionRequest>& requests,
     131             :                 ContentPermissionRequestParent* parent);
     132             : 
     133             :   void OnParentDestroyed();
     134             : 
     135             :   void NotifyVisibility(const bool& aIsVisible);
     136             : 
     137             : private:
     138             :   class nsContentPermissionRequesterProxy final : public nsIContentPermissionRequester {
     139             :   public:
     140             :     NS_DECL_ISUPPORTS
     141             :     NS_DECL_NSICONTENTPERMISSIONREQUESTER
     142             : 
     143           0 :     explicit nsContentPermissionRequesterProxy(ContentPermissionRequestParent* aParent)
     144           0 :       : mParent(aParent)
     145           0 :       , mWaitGettingResult(false) {}
     146             : 
     147             :     void NotifyVisibilityResult(const bool& aIsVisible);
     148             : 
     149             :   private:
     150           0 :     virtual ~nsContentPermissionRequesterProxy() {}
     151             : 
     152             :     ContentPermissionRequestParent* mParent;
     153             :     bool mWaitGettingResult;
     154             :     nsCOMPtr<nsIContentPermissionRequestCallback> mGetCallback;
     155             :     nsCOMPtr<nsIContentPermissionRequestCallback> mOnChangeCallback;
     156             :   };
     157             : 
     158             :   virtual ~nsContentPermissionRequestProxy();
     159             : 
     160             :   // Non-owning pointer to the ContentPermissionRequestParent object which owns this proxy.
     161             :   ContentPermissionRequestParent* mParent;
     162             :   nsTArray<mozilla::dom::PermissionRequest> mPermissionRequests;
     163             :   RefPtr<nsContentPermissionRequesterProxy> mRequester;
     164             : };
     165             : 
     166             : /**
     167             :  * RemotePermissionRequest will send a prompt ipdl request to b2g process.
     168             :  */
     169             : class RemotePermissionRequest final : public nsIContentPermissionRequestCallback
     170             :                                     , public mozilla::dom::PContentPermissionRequestChild
     171             : {
     172             : public:
     173             :   NS_DECL_ISUPPORTS
     174             :   NS_DECL_NSICONTENTPERMISSIONREQUESTCALLBACK
     175             : 
     176             :   RemotePermissionRequest(nsIContentPermissionRequest* aRequest,
     177             :                           nsPIDOMWindowInner* aWindow);
     178             : 
     179             :   // It will be called when prompt dismissed.
     180             :   virtual mozilla::ipc::IPCResult RecvNotifyResult(const bool &aAllow,
     181             :                                                    InfallibleTArray<PermissionChoice>&& aChoices) override;
     182             : 
     183             :   virtual mozilla::ipc::IPCResult RecvGetVisibility() override;
     184             : 
     185           0 :   void IPDLAddRef()
     186             :   {
     187           0 :     mIPCOpen = true;
     188           0 :     AddRef();
     189           0 :   }
     190             : 
     191           0 :   void IPDLRelease()
     192             :   {
     193           0 :     mIPCOpen = false;
     194           0 :     Release();
     195           0 :   }
     196             : 
     197             :   void Destroy();
     198             : 
     199           0 :   bool IPCOpen() const { return mIPCOpen && !mDestroyed; }
     200             : 
     201             : private:
     202             :   virtual ~RemotePermissionRequest();
     203             : 
     204             :   void DoAllow(JS::HandleValue aChoices);
     205             :   void DoCancel();
     206             : 
     207             :   nsCOMPtr<nsIContentPermissionRequest> mRequest;
     208             :   nsCOMPtr<nsPIDOMWindowInner>          mWindow;
     209             :   bool                                  mIPCOpen;
     210             :   bool                                  mDestroyed;
     211             :   RefPtr<VisibilityChangeListener>    mListener;
     212             : };
     213             : 
     214             : #endif // nsContentPermissionHelper_h
     215             : 

Generated by: LCOV version 1.13