Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM PushManager.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #ifndef mozilla_dom_PushManagerBinding_h
4 : #define mozilla_dom_PushManagerBinding_h
5 :
6 : #include "js/RootingAPI.h"
7 : #include "jsfriendapi.h"
8 : #include "jspubtd.h"
9 : #include "mozilla/ErrorResult.h"
10 : #include "mozilla/dom/BindingDeclarations.h"
11 : #include "mozilla/dom/CallbackInterface.h"
12 : #include "mozilla/dom/FakeString.h"
13 : #include "mozilla/dom/Nullable.h"
14 : #include "mozilla/dom/ToJSValue.h"
15 : #include "mozilla/dom/TypedArray.h"
16 : #include "mozilla/dom/UnionMember.h"
17 : #include "nsWeakReference.h"
18 :
19 : namespace mozilla {
20 : namespace dom {
21 :
22 : class ArrayBufferViewOrArrayBufferOrString;
23 : struct NativePropertyHooks;
24 : class OwningArrayBufferViewOrArrayBufferOrString;
25 : class Promise;
26 : class ProtoAndIfaceCache;
27 : class PushManager;
28 : struct PushManagerAtoms;
29 : class PushManagerImpl;
30 : struct PushManagerImplAtoms;
31 : struct PushSubscriptionOptionsInit;
32 : struct PushSubscriptionOptionsInitAtoms;
33 :
34 : } // namespace dom
35 : } // namespace mozilla
36 :
37 : namespace mozilla {
38 : namespace dom {
39 :
40 : enum class PushPermissionState : uint8_t {
41 : Granted,
42 : Denied,
43 : Prompt,
44 : EndGuard_
45 : };
46 :
47 : namespace PushPermissionStateValues {
48 : extern const EnumEntry strings[4];
49 : } // namespace PushPermissionStateValues
50 :
51 : bool
52 : ToJSValue(JSContext* aCx, PushPermissionState aArgument, JS::MutableHandle<JS::Value> aValue);
53 :
54 :
55 : class ArrayBufferViewOrArrayBufferOrString
56 : {
57 : friend class ArrayBufferViewOrArrayBufferOrStringArgument;
58 : enum Type
59 : {
60 : eUninitialized,
61 : eArrayBufferView,
62 : eArrayBuffer,
63 : eString
64 : };
65 :
66 : union Value
67 : {
68 : UnionMember<RootedTypedArray<ArrayBufferView> > mArrayBufferView;
69 : UnionMember<RootedTypedArray<ArrayBuffer> > mArrayBuffer;
70 : UnionMember<binding_detail::FakeString > mString;
71 :
72 : };
73 :
74 : Type mType;
75 : Value mValue;
76 :
77 : ArrayBufferViewOrArrayBufferOrString(const ArrayBufferViewOrArrayBufferOrString&) = delete;
78 : ArrayBufferViewOrArrayBufferOrString& operator=(const ArrayBufferViewOrArrayBufferOrString&) = delete;
79 : public:
80 : explicit inline ArrayBufferViewOrArrayBufferOrString()
81 : : mType(eUninitialized)
82 : {
83 : }
84 :
85 : inline ~ArrayBufferViewOrArrayBufferOrString()
86 : {
87 : Uninit();
88 : }
89 :
90 : inline RootedTypedArray<ArrayBufferView>&
91 : RawSetAsArrayBufferView(JSContext* cx)
92 : {
93 : if (mType == eArrayBufferView) {
94 : return mValue.mArrayBufferView.Value();
95 : }
96 : MOZ_ASSERT(mType == eUninitialized);
97 : mType = eArrayBufferView;
98 : return mValue.mArrayBufferView.SetValue(cx);
99 : }
100 :
101 : inline RootedTypedArray<ArrayBufferView>&
102 : SetAsArrayBufferView(JSContext* cx)
103 : {
104 : if (mType == eArrayBufferView) {
105 : return mValue.mArrayBufferView.Value();
106 : }
107 : Uninit();
108 : mType = eArrayBufferView;
109 : return mValue.mArrayBufferView.SetValue(cx);
110 : }
111 :
112 : inline bool
113 : IsArrayBufferView() const
114 : {
115 : return mType == eArrayBufferView;
116 : }
117 :
118 : inline RootedTypedArray<ArrayBufferView>&
119 : GetAsArrayBufferView()
120 : {
121 : MOZ_ASSERT(IsArrayBufferView(), "Wrong type!");
122 : return mValue.mArrayBufferView.Value();
123 : }
124 :
125 : inline ArrayBufferView const &
126 : GetAsArrayBufferView() const
127 : {
128 : MOZ_ASSERT(IsArrayBufferView(), "Wrong type!");
129 : return mValue.mArrayBufferView.Value();
130 : }
131 :
132 : inline RootedTypedArray<ArrayBuffer>&
133 : RawSetAsArrayBuffer(JSContext* cx)
134 : {
135 : if (mType == eArrayBuffer) {
136 : return mValue.mArrayBuffer.Value();
137 : }
138 : MOZ_ASSERT(mType == eUninitialized);
139 : mType = eArrayBuffer;
140 : return mValue.mArrayBuffer.SetValue(cx);
141 : }
142 :
143 : inline RootedTypedArray<ArrayBuffer>&
144 : SetAsArrayBuffer(JSContext* cx)
145 : {
146 : if (mType == eArrayBuffer) {
147 : return mValue.mArrayBuffer.Value();
148 : }
149 : Uninit();
150 : mType = eArrayBuffer;
151 : return mValue.mArrayBuffer.SetValue(cx);
152 : }
153 :
154 : inline bool
155 : IsArrayBuffer() const
156 : {
157 : return mType == eArrayBuffer;
158 : }
159 :
160 : inline RootedTypedArray<ArrayBuffer>&
161 : GetAsArrayBuffer()
162 : {
163 : MOZ_ASSERT(IsArrayBuffer(), "Wrong type!");
164 : return mValue.mArrayBuffer.Value();
165 : }
166 :
167 : inline ArrayBuffer const &
168 : GetAsArrayBuffer() const
169 : {
170 : MOZ_ASSERT(IsArrayBuffer(), "Wrong type!");
171 : return mValue.mArrayBuffer.Value();
172 : }
173 :
174 : inline binding_detail::FakeString&
175 : RawSetAsString()
176 : {
177 : if (mType == eString) {
178 : return mValue.mString.Value();
179 : }
180 : MOZ_ASSERT(mType == eUninitialized);
181 : mType = eString;
182 : return mValue.mString.SetValue();
183 : }
184 :
185 : inline binding_detail::FakeString&
186 : SetAsString()
187 : {
188 : if (mType == eString) {
189 : return mValue.mString.Value();
190 : }
191 : Uninit();
192 : mType = eString;
193 : return mValue.mString.SetValue();
194 : }
195 :
196 : inline bool
197 : IsString() const
198 : {
199 : return mType == eString;
200 : }
201 :
202 : inline binding_detail::FakeString&
203 : GetAsString()
204 : {
205 : MOZ_ASSERT(IsString(), "Wrong type!");
206 : return mValue.mString.Value();
207 : }
208 :
209 : inline const nsAString&
210 : GetAsString() const
211 : {
212 : MOZ_ASSERT(IsString(), "Wrong type!");
213 : return mValue.mString.Value();
214 : }
215 :
216 : inline void
217 : Uninit()
218 : {
219 : switch (mType) {
220 : case eUninitialized: {
221 : break;
222 : }
223 : case eArrayBufferView: {
224 : DestroyArrayBufferView();
225 : break;
226 : }
227 : case eArrayBuffer: {
228 : DestroyArrayBuffer();
229 : break;
230 : }
231 : case eString: {
232 : DestroyString();
233 : break;
234 : }
235 : }
236 : }
237 :
238 : bool
239 : ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const;
240 :
241 : private:
242 : inline void
243 : DestroyArrayBufferView()
244 : {
245 : MOZ_ASSERT(IsArrayBufferView(), "Wrong type!");
246 : mValue.mArrayBufferView.Destroy();
247 : mType = eUninitialized;
248 : }
249 :
250 : inline void
251 : DestroyArrayBuffer()
252 : {
253 : MOZ_ASSERT(IsArrayBuffer(), "Wrong type!");
254 : mValue.mArrayBuffer.Destroy();
255 : mType = eUninitialized;
256 : }
257 :
258 : inline void
259 : DestroyString()
260 : {
261 : MOZ_ASSERT(IsString(), "Wrong type!");
262 : mValue.mString.Destroy();
263 : mType = eUninitialized;
264 : }
265 : };
266 :
267 :
268 : class OwningArrayBufferViewOrArrayBufferOrString : public AllOwningUnionBase
269 : {
270 : friend void ImplCycleCollectionUnlink(OwningArrayBufferViewOrArrayBufferOrString& aUnion);
271 : enum Type
272 : {
273 : eUninitialized,
274 : eArrayBufferView,
275 : eArrayBuffer,
276 : eString
277 : };
278 :
279 0 : union Value
280 : {
281 : UnionMember<ArrayBufferView > mArrayBufferView;
282 : UnionMember<ArrayBuffer > mArrayBuffer;
283 : UnionMember<nsString > mString;
284 :
285 : };
286 :
287 : Type mType;
288 : Value mValue;
289 :
290 : OwningArrayBufferViewOrArrayBufferOrString(const OwningArrayBufferViewOrArrayBufferOrString&) = delete;
291 : OwningArrayBufferViewOrArrayBufferOrString& operator=(const OwningArrayBufferViewOrArrayBufferOrString&) = delete;
292 : public:
293 0 : explicit inline OwningArrayBufferViewOrArrayBufferOrString()
294 0 : : mType(eUninitialized)
295 : {
296 0 : }
297 :
298 0 : inline ~OwningArrayBufferViewOrArrayBufferOrString()
299 0 : {
300 0 : Uninit();
301 0 : }
302 :
303 : ArrayBufferView&
304 : RawSetAsArrayBufferView();
305 :
306 : ArrayBufferView&
307 : SetAsArrayBufferView();
308 :
309 : bool
310 : TrySetToArrayBufferView(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
311 :
312 : inline bool
313 0 : IsArrayBufferView() const
314 : {
315 0 : return mType == eArrayBufferView;
316 : }
317 :
318 : inline ArrayBufferView&
319 : GetAsArrayBufferView()
320 : {
321 : MOZ_ASSERT(IsArrayBufferView(), "Wrong type!");
322 : return mValue.mArrayBufferView.Value();
323 : }
324 :
325 : inline ArrayBufferView const &
326 0 : GetAsArrayBufferView() const
327 : {
328 0 : MOZ_ASSERT(IsArrayBufferView(), "Wrong type!");
329 0 : return mValue.mArrayBufferView.Value();
330 : }
331 :
332 : ArrayBuffer&
333 : RawSetAsArrayBuffer();
334 :
335 : ArrayBuffer&
336 : SetAsArrayBuffer();
337 :
338 : bool
339 : TrySetToArrayBuffer(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
340 :
341 : inline bool
342 0 : IsArrayBuffer() const
343 : {
344 0 : return mType == eArrayBuffer;
345 : }
346 :
347 : inline ArrayBuffer&
348 : GetAsArrayBuffer()
349 : {
350 : MOZ_ASSERT(IsArrayBuffer(), "Wrong type!");
351 : return mValue.mArrayBuffer.Value();
352 : }
353 :
354 : inline ArrayBuffer const &
355 0 : GetAsArrayBuffer() const
356 : {
357 0 : MOZ_ASSERT(IsArrayBuffer(), "Wrong type!");
358 0 : return mValue.mArrayBuffer.Value();
359 : }
360 :
361 : nsString&
362 : RawSetAsString();
363 :
364 : nsString&
365 : SetAsString();
366 :
367 : bool
368 : TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
369 :
370 : inline void
371 : SetStringData(const nsString::char_type* aData, nsString::size_type aLength)
372 : {
373 : RawSetAsString().Assign(aData, aLength);
374 : }
375 :
376 : inline bool
377 0 : IsString() const
378 : {
379 0 : return mType == eString;
380 : }
381 :
382 : inline nsString&
383 : GetAsString()
384 : {
385 : MOZ_ASSERT(IsString(), "Wrong type!");
386 : return mValue.mString.Value();
387 : }
388 :
389 : inline nsString const &
390 0 : GetAsString() const
391 : {
392 0 : MOZ_ASSERT(IsString(), "Wrong type!");
393 0 : return mValue.mString.Value();
394 : }
395 :
396 : void
397 : Uninit();
398 :
399 : bool
400 : ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const;
401 :
402 : void
403 : TraceUnion(JSTracer* trc);
404 :
405 : private:
406 : void
407 : DestroyArrayBufferView();
408 :
409 : void
410 : DestroyArrayBuffer();
411 :
412 : void
413 : DestroyString();
414 : };
415 :
416 :
417 0 : struct PushSubscriptionOptionsInit : public DictionaryBase
418 : {
419 : MOZ_INIT_OUTSIDE_CTOR Nullable<OwningArrayBufferViewOrArrayBufferOrString > mApplicationServerKey;
420 :
421 : PushSubscriptionOptionsInit();
422 :
423 0 : explicit inline PushSubscriptionOptionsInit(const FastDictionaryInitializer& )
424 0 : {
425 : // Do nothing here; this is used by our "Fast" subclass
426 0 : }
427 :
428 : private:
429 : PushSubscriptionOptionsInit(const PushSubscriptionOptionsInit&) = delete;
430 : PushSubscriptionOptionsInit& operator=(const PushSubscriptionOptionsInit&) = delete;
431 :
432 : static bool
433 : InitIds(JSContext* cx, PushSubscriptionOptionsInitAtoms* atomsCache);
434 :
435 : public:
436 : bool
437 : Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
438 :
439 : bool
440 : ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const;
441 :
442 : void
443 : TraceDictionary(JSTracer* trc);
444 : };
445 :
446 : namespace binding_detail {
447 0 : struct FastPushSubscriptionOptionsInit : public PushSubscriptionOptionsInit
448 : {
449 0 : inline FastPushSubscriptionOptionsInit()
450 0 : : PushSubscriptionOptionsInit(FastDictionaryInitializer())
451 : {
452 : // Doesn't matter what int we pass to the parent constructor
453 0 : }
454 : };
455 : } // namespace binding_detail
456 :
457 :
458 : namespace PushManagerBinding {
459 :
460 : typedef mozilla::dom::PushManager NativeType;
461 :
462 : bool
463 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj);
464 :
465 : JSObject*
466 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal);
467 :
468 : const JSClass*
469 : GetJSClass();
470 :
471 : bool
472 : Wrap(JSContext* aCx, mozilla::dom::PushManager* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector);
473 :
474 : template <class T>
475 0 : inline JSObject* Wrap(JSContext* aCx, T* aObject, JS::Handle<JSObject*> aGivenProto)
476 : {
477 0 : JS::Rooted<JSObject*> reflector(aCx);
478 0 : return Wrap(aCx, aObject, aObject, aGivenProto, &reflector) ? reflector.get() : nullptr;
479 : }
480 :
481 : // We declare this as an array so that retrieving a pointer to this
482 : // binding's property hooks only requires compile/link-time resolvable
483 : // address arithmetic. Declaring it as a pointer instead would require
484 : // doing a run-time load to fetch a pointer to this binding's property
485 : // hooks. And then structures which embedded a pointer to this structure
486 : // would require a run-time load for proper initialization, which would
487 : // then induce static constructors. Lots of static constructors.
488 : extern const NativePropertyHooks sNativePropertyHooks[];
489 :
490 : void
491 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal);
492 :
493 : JS::Handle<JSObject*>
494 : GetProtoObjectHandle(JSContext* aCx);
495 :
496 : JS::Handle<JSObject*>
497 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal = true);
498 :
499 : JSObject*
500 : GetConstructorObject(JSContext* aCx);
501 :
502 : } // namespace PushManagerBinding
503 :
504 :
505 :
506 : namespace PushManagerImplBinding {
507 :
508 : typedef mozilla::dom::PushManagerImpl NativeType;
509 :
510 : bool
511 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj);
512 :
513 : JSObject*
514 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal);
515 :
516 : const JSClass*
517 : GetJSClass();
518 :
519 : bool
520 : Wrap(JSContext* aCx, mozilla::dom::PushManagerImpl* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector);
521 :
522 : template <class T>
523 0 : inline JSObject* Wrap(JSContext* aCx, T* aObject, JS::Handle<JSObject*> aGivenProto)
524 : {
525 0 : JS::Rooted<JSObject*> reflector(aCx);
526 0 : return Wrap(aCx, aObject, aObject, aGivenProto, &reflector) ? reflector.get() : nullptr;
527 : }
528 :
529 : // We declare this as an array so that retrieving a pointer to this
530 : // binding's property hooks only requires compile/link-time resolvable
531 : // address arithmetic. Declaring it as a pointer instead would require
532 : // doing a run-time load to fetch a pointer to this binding's property
533 : // hooks. And then structures which embedded a pointer to this structure
534 : // would require a run-time load for proper initialization, which would
535 : // then induce static constructors. Lots of static constructors.
536 : extern const NativePropertyHooks sNativePropertyHooks[];
537 :
538 : void
539 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal);
540 :
541 : JS::Handle<JSObject*>
542 : GetProtoObjectHandle(JSContext* aCx);
543 :
544 : JS::Handle<JSObject*>
545 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal = true);
546 :
547 : JSObject*
548 : GetConstructorObject(JSContext* aCx);
549 :
550 : } // namespace PushManagerImplBinding
551 :
552 :
553 :
554 0 : class PushManagerImplJSImpl : public CallbackInterface
555 : {
556 : public:
557 0 : explicit inline PushManagerImplJSImpl(JSContext* aCx, JS::Handle<JSObject*> aCallback, nsIGlobalObject* aIncumbentGlobal)
558 0 : : CallbackInterface(aCx, aCallback, aIncumbentGlobal)
559 : {
560 0 : }
561 :
562 : explicit inline PushManagerImplJSImpl(JS::Handle<JSObject*> aCallback, const FastCallbackConstructor& )
563 : : CallbackInterface(aCallback, FastCallbackConstructor())
564 : {
565 : }
566 :
567 : explicit inline PushManagerImplJSImpl(JS::Handle<JSObject*> aCallback, JS::Handle<JSObject*> aAsyncStack, nsIGlobalObject* aIncumbentGlobal)
568 : : CallbackInterface(aCallback, aAsyncStack, aIncumbentGlobal)
569 : {
570 : }
571 :
572 : already_AddRefed<Promise> Subscribe(const PushSubscriptionOptionsInit& options, ErrorResult& aRv, JSCompartment* aCompartment = nullptr);
573 :
574 : already_AddRefed<Promise> GetSubscription(ErrorResult& aRv, JSCompartment* aCompartment = nullptr);
575 :
576 : already_AddRefed<Promise> PermissionState(const PushSubscriptionOptionsInit& options, ErrorResult& aRv, JSCompartment* aCompartment = nullptr);
577 :
578 : void __Init(const nsAString& scope, ErrorResult& aRv, JSCompartment* aCompartment = nullptr);
579 :
580 : inline bool
581 : operator==(const PushManagerImplJSImpl& aOther) const
582 : {
583 : return CallbackInterface::operator==(aOther);
584 : }
585 :
586 : private:
587 : static bool
588 : InitIds(JSContext* cx, PushManagerImplAtoms* atomsCache);
589 : };
590 :
591 :
592 : class PushManagerImpl final : public nsSupportsWeakReference,
593 : public nsWrapperCache
594 : {
595 : public:
596 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
597 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(PushManagerImpl)
598 :
599 : private:
600 : RefPtr<PushManagerImplJSImpl> mImpl;
601 : nsCOMPtr<nsISupports> mParent;
602 :
603 : public:
604 : PushManagerImpl(JS::Handle<JSObject*> aJSImplObject, nsIGlobalObject* aParent);
605 :
606 : private:
607 : ~PushManagerImpl();
608 :
609 : public:
610 : nsISupports* GetParentObject() const;
611 :
612 : virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
613 :
614 : static already_AddRefed<PushManagerImpl> Constructor(const GlobalObject& global, JSContext* cx, const nsAString& scope, ErrorResult& aRv);
615 :
616 : // Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
617 : already_AddRefed<Promise> Subscribe(const PushSubscriptionOptionsInit& options, ErrorResult& aRv, JSCompartment* aCompartment = nullptr);
618 :
619 : // Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
620 : already_AddRefed<Promise> GetSubscription(ErrorResult& aRv, JSCompartment* aCompartment = nullptr);
621 :
622 : // Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
623 : already_AddRefed<Promise> PermissionState(const PushSubscriptionOptionsInit& options, ErrorResult& aRv, JSCompartment* aCompartment = nullptr);
624 :
625 : static bool
626 : _Create(JSContext* cx, unsigned argc, JS::Value* vp);
627 : };
628 :
629 :
630 : } // namespace dom
631 : } // namespace mozilla
632 :
633 : #endif // mozilla_dom_PushManagerBinding_h
|