Bumping manifests a=b2g-bump
[gecko.git] / dom / base / nsContentPermissionHelper.h
blob02c779c7d83704a54cb8992f57a39022a0cc1c8f
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"
9 #include "nsTArray.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.
15 #undef LoadImage
17 class nsPIDOMWindow;
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.
26 namespace IPC {
27 class Principal;
30 namespace mozilla {
31 namespace dom {
33 class Element;
34 class PermissionRequest;
35 class ContentPermissionRequestParent;
36 class PContentPermissionRequestParent;
38 class ContentPermissionType : public nsIContentPermissionType
40 public:
41 NS_DECL_ISUPPORTS
42 NS_DECL_NSICONTENTPERMISSIONTYPE
44 ContentPermissionType(const nsACString& aType,
45 const nsACString& aAccess,
46 const nsTArray<nsString>& aOptions);
48 protected:
49 virtual ~ContentPermissionType();
51 nsCString mType;
52 nsCString mAccess;
53 nsTArray<nsString> mOptions;
56 class nsContentPermissionUtils
58 public:
59 static uint32_t
60 ConvertPermissionRequestToArray(nsTArray<PermissionRequest>& aSrcArray,
61 nsIMutableArray* aDesArray);
63 static uint32_t
64 ConvertArrayToPermissionRequest(nsIArray* aSrcArray,
65 nsTArray<PermissionRequest>& aDesArray);
67 static nsresult
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,
75 Element* element,
76 const IPC::Principal& principal);
78 static nsresult
79 AskPermission(nsIContentPermissionRequest* aRequest, nsPIDOMWindow* aWindow);
82 } // namespace dom
83 } // namespace mozilla
85 class nsContentPermissionRequestProxy : public nsIContentPermissionRequest
87 public:
88 NS_DECL_ISUPPORTS
89 NS_DECL_NSICONTENTPERMISSIONREQUEST
91 nsContentPermissionRequestProxy();
93 nsresult Init(const nsTArray<mozilla::dom::PermissionRequest>& requests,
94 mozilla::dom::ContentPermissionRequestParent* parent);
96 void OnParentDestroyed();
98 private:
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
112 public:
113 NS_DECL_ISUPPORTS
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;
122 void IPDLAddRef()
124 mIPCOpen = true;
125 AddRef();
128 void IPDLRelease()
130 mIPCOpen = false;
131 Release();
134 private:
135 virtual ~RemotePermissionRequest()
137 MOZ_ASSERT(!mIPCOpen, "Protocol must not be open when RemotePermissionRequest is destroyed.");
140 void DoAllow(JS::HandleValue aChoices);
141 void DoCancel();
143 nsCOMPtr<nsIContentPermissionRequest> mRequest;
144 nsCOMPtr<nsPIDOMWindow> mWindow;
145 bool mIPCOpen;
148 #endif // nsContentPermissionHelper_h