1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef nsContentPermissionHelper_h
6 #define nsContentPermissionHelper_h
8 #include "nsIContentPermissionPrompt.h"
10 #include "nsIMutableArray.h"
11 #include "mozilla/dom/PContentPermissionRequestChild.h"
12 // Microsoft's API Name hackery sucks
13 // XXXbz Doing this in a header is a gigantic footgun. See
14 // https://bugzilla.mozilla.org/show_bug.cgi?id=932421#c3 for why.
18 class nsContentPermissionRequestProxy
;
20 // Forward declare IPC::Principal here which is defined in
21 // PermissionMessageUtils.h. Include this file will transitively includes
22 // "windows.h" and it defines
23 // #define CreateEvent CreateEventW
24 // #define LoadImage LoadImageW
25 // That will mess up windows build.
34 class PermissionRequest
;
35 class ContentPermissionRequestParent
;
36 class PContentPermissionRequestParent
;
38 class ContentPermissionType
: public nsIContentPermissionType
42 NS_DECL_NSICONTENTPERMISSIONTYPE
44 ContentPermissionType(const nsACString
& aType
,
45 const nsACString
& aAccess
,
46 const nsTArray
<nsString
>& aOptions
);
49 virtual ~ContentPermissionType();
53 nsTArray
<nsString
> mOptions
;
56 class nsContentPermissionUtils
60 ConvertPermissionRequestToArray(nsTArray
<PermissionRequest
>& aSrcArray
,
61 nsIMutableArray
* aDesArray
);
64 ConvertArrayToPermissionRequest(nsIArray
* aSrcArray
,
65 nsTArray
<PermissionRequest
>& aDesArray
);
68 CreatePermissionArray(const nsACString
& aType
,
69 const nsACString
& aAccess
,
70 const nsTArray
<nsString
>& aOptions
,
71 nsIArray
** aTypesArray
);
73 static PContentPermissionRequestParent
*
74 CreateContentPermissionRequestParent(const nsTArray
<PermissionRequest
>& aRequests
,
76 const IPC::Principal
& principal
);
79 AskPermission(nsIContentPermissionRequest
* aRequest
, nsPIDOMWindow
* aWindow
);
83 } // namespace mozilla
85 class nsContentPermissionRequestProxy
: public nsIContentPermissionRequest
89 NS_DECL_NSICONTENTPERMISSIONREQUEST
91 nsContentPermissionRequestProxy();
93 nsresult
Init(const nsTArray
<mozilla::dom::PermissionRequest
>& requests
,
94 mozilla::dom::ContentPermissionRequestParent
* parent
);
96 void OnParentDestroyed();
99 virtual ~nsContentPermissionRequestProxy();
101 // Non-owning pointer to the ContentPermissionRequestParent object which owns this proxy.
102 mozilla::dom::ContentPermissionRequestParent
* mParent
;
103 nsTArray
<mozilla::dom::PermissionRequest
> mPermissionRequests
;
107 * RemotePermissionRequest will send a prompt ipdl request to b2g process.
109 class RemotePermissionRequest MOZ_FINAL
: public nsISupports
110 , public mozilla::dom::PContentPermissionRequestChild
115 RemotePermissionRequest(nsIContentPermissionRequest
* aRequest
,
116 nsPIDOMWindow
* aWindow
);
118 // It will be called when prompt dismissed.
119 virtual bool Recv__delete__(const bool &aAllow
,
120 const nsTArray
<PermissionChoice
>& aChoices
) MOZ_OVERRIDE
;
135 virtual ~RemotePermissionRequest()
137 MOZ_ASSERT(!mIPCOpen
, "Protocol must not be open when RemotePermissionRequest is destroyed.");
140 void DoAllow(JS::HandleValue aChoices
);
143 nsCOMPtr
<nsIContentPermissionRequest
> mRequest
;
144 nsCOMPtr
<nsPIDOMWindow
> mWindow
;
148 #endif // nsContentPermissionHelper_h