/src/mozilla-central/dom/base/nsContentPermissionHelper.h
Line | Count | Source (jump to first uncovered line) |
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* aElement, |
82 | | const IPC::Principal& aPrincipal, |
83 | | const bool aIsHandlingUserInput, |
84 | | const TabId& aTabId); |
85 | | |
86 | | static nsresult |
87 | | AskPermission(nsIContentPermissionRequest* aRequest, |
88 | | nsPIDOMWindowInner* aWindow); |
89 | | |
90 | | static nsTArray<PContentPermissionRequestParent*> |
91 | | GetContentPermissionRequestParentById(const TabId& aTabId); |
92 | | |
93 | | static void |
94 | | NotifyRemoveContentPermissionRequestParent(PContentPermissionRequestParent* aParent); |
95 | | |
96 | | static nsTArray<PContentPermissionRequestChild*> |
97 | | GetContentPermissionRequestChildById(const TabId& aTabId); |
98 | | |
99 | | static void |
100 | | NotifyRemoveContentPermissionRequestChild(PContentPermissionRequestChild* aChild); |
101 | | }; |
102 | | |
103 | | class nsContentPermissionRequester final : public nsIContentPermissionRequester |
104 | | { |
105 | | public: |
106 | | NS_DECL_ISUPPORTS |
107 | | NS_DECL_NSICONTENTPERMISSIONREQUESTER |
108 | | |
109 | | explicit nsContentPermissionRequester(nsPIDOMWindowInner* aWindow); |
110 | | |
111 | | private: |
112 | | virtual ~nsContentPermissionRequester(); |
113 | | |
114 | | nsWeakPtr mWindow; |
115 | | RefPtr<VisibilityChangeListener> mListener; |
116 | | }; |
117 | | |
118 | | } // namespace dom |
119 | | } // namespace mozilla |
120 | | |
121 | | using mozilla::dom::ContentPermissionRequestParent; |
122 | | |
123 | | class nsContentPermissionRequestProxy : public nsIContentPermissionRequest |
124 | | { |
125 | | public: |
126 | | NS_DECL_ISUPPORTS |
127 | | NS_DECL_NSICONTENTPERMISSIONREQUEST |
128 | | |
129 | | explicit nsContentPermissionRequestProxy(ContentPermissionRequestParent* parent); |
130 | | |
131 | | nsresult Init(const nsTArray<mozilla::dom::PermissionRequest>& requests); |
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 | | explicit nsContentPermissionRequesterProxy(ContentPermissionRequestParent* aParent) |
144 | | : 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 | | void IPDLAddRef() |
186 | 0 | { |
187 | 0 | mIPCOpen = true; |
188 | 0 | AddRef(); |
189 | 0 | } |
190 | | |
191 | | void IPDLRelease() |
192 | 0 | { |
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 | | |