Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM U2F.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #ifndef mozilla_dom_U2FBinding_h
4 : #define mozilla_dom_U2FBinding_h
5 :
6 : #include "js/RootingAPI.h"
7 : #include "jspubtd.h"
8 : #include "mozilla/ErrorResult.h"
9 : #include "mozilla/dom/BindingDeclarations.h"
10 : #include "mozilla/dom/CallbackFunction.h"
11 : #include "mozilla/dom/Nullable.h"
12 : #include "mozilla/dom/ToJSValue.h"
13 :
14 : namespace mozilla {
15 : namespace dom {
16 :
17 : struct NativePropertyHooks;
18 : class ProtoAndIfaceCache;
19 : struct RegisterRequestAtoms;
20 : struct RegisterResponse;
21 : struct RegisterResponseAtoms;
22 : struct RegisteredKeyAtoms;
23 : struct SignResponse;
24 : struct SignResponseAtoms;
25 : class U2F;
26 : struct U2FAtoms;
27 : struct U2FClientDataAtoms;
28 : class U2FRegisterCallback;
29 : class U2FSignCallback;
30 :
31 : } // namespace dom
32 : } // namespace mozilla
33 :
34 : namespace mozilla {
35 : namespace dom {
36 :
37 : enum class Transport : uint8_t {
38 : Bt,
39 : Ble,
40 : Nfc,
41 : Usb,
42 : EndGuard_
43 : };
44 :
45 : namespace TransportValues {
46 : extern const EnumEntry strings[5];
47 : } // namespace TransportValues
48 :
49 : bool
50 : ToJSValue(JSContext* aCx, Transport aArgument, JS::MutableHandle<JS::Value> aValue);
51 :
52 :
53 0 : struct RegisterRequest : public DictionaryBase
54 : {
55 : MOZ_INIT_OUTSIDE_CTOR Optional<nsString> mChallenge;
56 : MOZ_INIT_OUTSIDE_CTOR Optional<nsString> mVersion;
57 :
58 : RegisterRequest();
59 :
60 : explicit inline RegisterRequest(const FastDictionaryInitializer& )
61 : {
62 : // Do nothing here; this is used by our "Fast" subclass
63 : }
64 :
65 : explicit inline RegisterRequest(const RegisterRequest& aOther)
66 : {
67 : *this = aOther;
68 : }
69 :
70 : bool
71 : Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
72 :
73 : bool
74 : Init(const nsAString& aJSON);
75 :
76 : bool
77 : ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const;
78 :
79 : bool
80 : ToJSON(nsAString& aJSON) const;
81 :
82 : void
83 : TraceDictionary(JSTracer* trc);
84 :
85 : RegisterRequest&
86 : operator=(const RegisterRequest& aOther);
87 :
88 : private:
89 : static bool
90 : InitIds(JSContext* cx, RegisterRequestAtoms* atomsCache);
91 : };
92 :
93 : namespace binding_detail {
94 : struct FastRegisterRequest : public RegisterRequest
95 : {
96 : inline FastRegisterRequest()
97 : : RegisterRequest(FastDictionaryInitializer())
98 : {
99 : // Doesn't matter what int we pass to the parent constructor
100 : }
101 : };
102 : } // namespace binding_detail
103 :
104 :
105 0 : struct RegisterResponse : public DictionaryBase
106 : {
107 : MOZ_INIT_OUTSIDE_CTOR Optional<nsString> mClientData;
108 : MOZ_INIT_OUTSIDE_CTOR Optional<Nullable<uint16_t>> mErrorCode;
109 : MOZ_INIT_OUTSIDE_CTOR Optional<nsString> mErrorMessage;
110 : MOZ_INIT_OUTSIDE_CTOR Optional<nsString> mRegistrationData;
111 : MOZ_INIT_OUTSIDE_CTOR Optional<nsString> mVersion;
112 :
113 : RegisterResponse();
114 :
115 : explicit inline RegisterResponse(const FastDictionaryInitializer& )
116 : {
117 : // Do nothing here; this is used by our "Fast" subclass
118 : }
119 :
120 : explicit inline RegisterResponse(const RegisterResponse& aOther)
121 : {
122 : *this = aOther;
123 : }
124 :
125 : bool
126 : Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
127 :
128 : bool
129 : Init(const nsAString& aJSON);
130 :
131 : bool
132 : ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const;
133 :
134 : bool
135 : ToJSON(nsAString& aJSON) const;
136 :
137 : void
138 : TraceDictionary(JSTracer* trc);
139 :
140 : RegisterResponse&
141 : operator=(const RegisterResponse& aOther);
142 :
143 : private:
144 : static bool
145 : InitIds(JSContext* cx, RegisterResponseAtoms* atomsCache);
146 : };
147 :
148 : namespace binding_detail {
149 : struct FastRegisterResponse : public RegisterResponse
150 : {
151 : inline FastRegisterResponse()
152 : : RegisterResponse(FastDictionaryInitializer())
153 : {
154 : // Doesn't matter what int we pass to the parent constructor
155 : }
156 : };
157 : } // namespace binding_detail
158 :
159 :
160 0 : struct RegisteredKey : public DictionaryBase
161 : {
162 : MOZ_INIT_OUTSIDE_CTOR Optional<nsString> mAppId;
163 : MOZ_INIT_OUTSIDE_CTOR Optional<nsString> mKeyHandle;
164 : MOZ_INIT_OUTSIDE_CTOR Optional<Nullable<Sequence<Transport>>> mTransports;
165 : MOZ_INIT_OUTSIDE_CTOR Optional<nsString> mVersion;
166 :
167 : RegisteredKey();
168 :
169 : explicit inline RegisteredKey(const FastDictionaryInitializer& )
170 : {
171 : // Do nothing here; this is used by our "Fast" subclass
172 : }
173 :
174 : explicit inline RegisteredKey(const RegisteredKey& aOther)
175 : {
176 : *this = aOther;
177 : }
178 :
179 : bool
180 : Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
181 :
182 : bool
183 : Init(const nsAString& aJSON);
184 :
185 : bool
186 : ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const;
187 :
188 : bool
189 : ToJSON(nsAString& aJSON) const;
190 :
191 : void
192 : TraceDictionary(JSTracer* trc);
193 :
194 : RegisteredKey&
195 : operator=(const RegisteredKey& aOther);
196 :
197 : private:
198 : static bool
199 : InitIds(JSContext* cx, RegisteredKeyAtoms* atomsCache);
200 : };
201 :
202 : namespace binding_detail {
203 : struct FastRegisteredKey : public RegisteredKey
204 : {
205 : inline FastRegisteredKey()
206 : : RegisteredKey(FastDictionaryInitializer())
207 : {
208 : // Doesn't matter what int we pass to the parent constructor
209 : }
210 : };
211 : } // namespace binding_detail
212 :
213 :
214 0 : struct SignResponse : public DictionaryBase
215 : {
216 : MOZ_INIT_OUTSIDE_CTOR Optional<nsString> mClientData;
217 : MOZ_INIT_OUTSIDE_CTOR Optional<Nullable<uint16_t>> mErrorCode;
218 : MOZ_INIT_OUTSIDE_CTOR Optional<nsString> mErrorMessage;
219 : MOZ_INIT_OUTSIDE_CTOR Optional<nsString> mKeyHandle;
220 : MOZ_INIT_OUTSIDE_CTOR Optional<nsString> mSignatureData;
221 :
222 : SignResponse();
223 :
224 : explicit inline SignResponse(const FastDictionaryInitializer& )
225 : {
226 : // Do nothing here; this is used by our "Fast" subclass
227 : }
228 :
229 : explicit inline SignResponse(const SignResponse& aOther)
230 : {
231 : *this = aOther;
232 : }
233 :
234 : bool
235 : Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
236 :
237 : bool
238 : Init(const nsAString& aJSON);
239 :
240 : bool
241 : ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const;
242 :
243 : bool
244 : ToJSON(nsAString& aJSON) const;
245 :
246 : void
247 : TraceDictionary(JSTracer* trc);
248 :
249 : SignResponse&
250 : operator=(const SignResponse& aOther);
251 :
252 : private:
253 : static bool
254 : InitIds(JSContext* cx, SignResponseAtoms* atomsCache);
255 : };
256 :
257 : namespace binding_detail {
258 : struct FastSignResponse : public SignResponse
259 : {
260 : inline FastSignResponse()
261 : : SignResponse(FastDictionaryInitializer())
262 : {
263 : // Doesn't matter what int we pass to the parent constructor
264 : }
265 : };
266 : } // namespace binding_detail
267 :
268 :
269 0 : struct U2FClientData : public DictionaryBase
270 : {
271 : MOZ_INIT_OUTSIDE_CTOR Optional<nsString> mChallenge;
272 : MOZ_INIT_OUTSIDE_CTOR Optional<nsString> mOrigin;
273 : MOZ_INIT_OUTSIDE_CTOR Optional<nsString> mTyp;
274 :
275 : U2FClientData();
276 :
277 : explicit inline U2FClientData(const FastDictionaryInitializer& )
278 : {
279 : // Do nothing here; this is used by our "Fast" subclass
280 : }
281 :
282 : explicit inline U2FClientData(const U2FClientData& aOther)
283 : {
284 : *this = aOther;
285 : }
286 :
287 : bool
288 : Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
289 :
290 : bool
291 : Init(const nsAString& aJSON);
292 :
293 : bool
294 : ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const;
295 :
296 : bool
297 : ToJSON(nsAString& aJSON) const;
298 :
299 : void
300 : TraceDictionary(JSTracer* trc);
301 :
302 : U2FClientData&
303 : operator=(const U2FClientData& aOther);
304 :
305 : private:
306 : static bool
307 : InitIds(JSContext* cx, U2FClientDataAtoms* atomsCache);
308 : };
309 :
310 : namespace binding_detail {
311 : struct FastU2FClientData : public U2FClientData
312 : {
313 : inline FastU2FClientData()
314 : : U2FClientData(FastDictionaryInitializer())
315 : {
316 : // Doesn't matter what int we pass to the parent constructor
317 : }
318 : };
319 : } // namespace binding_detail
320 :
321 :
322 0 : class U2FRegisterCallback : public CallbackFunction
323 : {
324 : public:
325 : explicit inline U2FRegisterCallback(JSContext* aCx, JS::Handle<JSObject*> aCallback, nsIGlobalObject* aIncumbentGlobal)
326 : : CallbackFunction(aCx, aCallback, aIncumbentGlobal)
327 : {
328 : MOZ_ASSERT(JS::IsCallable(mCallback));
329 : }
330 :
331 0 : explicit inline U2FRegisterCallback(JS::Handle<JSObject*> aCallback, const FastCallbackConstructor& )
332 0 : : CallbackFunction(aCallback, FastCallbackConstructor())
333 : {
334 0 : MOZ_ASSERT(JS::IsCallable(mCallback));
335 0 : }
336 :
337 : explicit inline U2FRegisterCallback(JS::Handle<JSObject*> aCallback, JS::Handle<JSObject*> aAsyncStack, nsIGlobalObject* aIncumbentGlobal)
338 : : CallbackFunction(aCallback, aAsyncStack, aIncumbentGlobal)
339 : {
340 : MOZ_ASSERT(JS::IsCallable(mCallback));
341 : }
342 :
343 : explicit inline U2FRegisterCallback(CallbackFunction* aOther)
344 : : CallbackFunction(aOther)
345 : {
346 : }
347 :
348 : template <typename T>
349 : inline void
350 : Call(const T& thisVal, const RegisterResponse& response, ErrorResult& aRv, const char* aExecutionReason = nullptr, ExceptionHandling aExceptionHandling = eReportExceptions, JSCompartment* aCompartment = nullptr)
351 : {
352 : MOZ_ASSERT(!aRv.Failed(), "Don't pass an already-failed ErrorResult to a callback!");
353 : if (!aExecutionReason) {
354 : aExecutionReason = "U2FRegisterCallback";
355 : }
356 : CallSetup s(this, aRv, aExecutionReason, aExceptionHandling, aCompartment);
357 : if (!s.GetContext()) {
358 : MOZ_ASSERT(aRv.Failed());
359 : return;
360 : }
361 : JS::Rooted<JS::Value> thisValJS(s.GetContext());
362 : if (!ToJSValue(s.GetContext(), thisVal, &thisValJS)) {
363 : aRv.Throw(NS_ERROR_FAILURE);
364 : return;
365 : }
366 : return Call(s.GetContext(), thisValJS, response, aRv);
367 : }
368 :
369 : inline void
370 0 : Call(const RegisterResponse& response, ErrorResult& aRv, const char* aExecutionReason = nullptr, ExceptionHandling aExceptionHandling = eReportExceptions, JSCompartment* aCompartment = nullptr)
371 : {
372 0 : MOZ_ASSERT(!aRv.Failed(), "Don't pass an already-failed ErrorResult to a callback!");
373 0 : if (!aExecutionReason) {
374 0 : aExecutionReason = "U2FRegisterCallback";
375 : }
376 0 : CallSetup s(this, aRv, aExecutionReason, aExceptionHandling, aCompartment);
377 0 : if (!s.GetContext()) {
378 0 : MOZ_ASSERT(aRv.Failed());
379 0 : return;
380 : }
381 0 : return Call(s.GetContext(), JS::UndefinedHandleValue, response, aRv);
382 : }
383 :
384 : template <typename T>
385 : inline void
386 : Call(const T& thisVal, const RegisterResponse& response, const char* aExecutionReason = nullptr)
387 : {
388 : IgnoredErrorResult rv;
389 : return Call(thisVal, response, rv, aExecutionReason);
390 : }
391 :
392 : inline void
393 : Call(const RegisterResponse& response, const char* aExecutionReason = nullptr)
394 : {
395 : IgnoredErrorResult rv;
396 : return Call(response, rv, aExecutionReason, eReportExceptions, nullptr);
397 : }
398 :
399 : inline bool
400 : operator==(const U2FRegisterCallback& aOther) const
401 : {
402 : return CallbackFunction::operator==(aOther);
403 : }
404 :
405 : private:
406 : void Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, const RegisterResponse& response, ErrorResult& aRv);
407 : };
408 :
409 :
410 0 : class U2FSignCallback : public CallbackFunction
411 : {
412 : public:
413 : explicit inline U2FSignCallback(JSContext* aCx, JS::Handle<JSObject*> aCallback, nsIGlobalObject* aIncumbentGlobal)
414 : : CallbackFunction(aCx, aCallback, aIncumbentGlobal)
415 : {
416 : MOZ_ASSERT(JS::IsCallable(mCallback));
417 : }
418 :
419 0 : explicit inline U2FSignCallback(JS::Handle<JSObject*> aCallback, const FastCallbackConstructor& )
420 0 : : CallbackFunction(aCallback, FastCallbackConstructor())
421 : {
422 0 : MOZ_ASSERT(JS::IsCallable(mCallback));
423 0 : }
424 :
425 : explicit inline U2FSignCallback(JS::Handle<JSObject*> aCallback, JS::Handle<JSObject*> aAsyncStack, nsIGlobalObject* aIncumbentGlobal)
426 : : CallbackFunction(aCallback, aAsyncStack, aIncumbentGlobal)
427 : {
428 : MOZ_ASSERT(JS::IsCallable(mCallback));
429 : }
430 :
431 : explicit inline U2FSignCallback(CallbackFunction* aOther)
432 : : CallbackFunction(aOther)
433 : {
434 : }
435 :
436 : template <typename T>
437 : inline void
438 : Call(const T& thisVal, const SignResponse& response, ErrorResult& aRv, const char* aExecutionReason = nullptr, ExceptionHandling aExceptionHandling = eReportExceptions, JSCompartment* aCompartment = nullptr)
439 : {
440 : MOZ_ASSERT(!aRv.Failed(), "Don't pass an already-failed ErrorResult to a callback!");
441 : if (!aExecutionReason) {
442 : aExecutionReason = "U2FSignCallback";
443 : }
444 : CallSetup s(this, aRv, aExecutionReason, aExceptionHandling, aCompartment);
445 : if (!s.GetContext()) {
446 : MOZ_ASSERT(aRv.Failed());
447 : return;
448 : }
449 : JS::Rooted<JS::Value> thisValJS(s.GetContext());
450 : if (!ToJSValue(s.GetContext(), thisVal, &thisValJS)) {
451 : aRv.Throw(NS_ERROR_FAILURE);
452 : return;
453 : }
454 : return Call(s.GetContext(), thisValJS, response, aRv);
455 : }
456 :
457 : inline void
458 0 : Call(const SignResponse& response, ErrorResult& aRv, const char* aExecutionReason = nullptr, ExceptionHandling aExceptionHandling = eReportExceptions, JSCompartment* aCompartment = nullptr)
459 : {
460 0 : MOZ_ASSERT(!aRv.Failed(), "Don't pass an already-failed ErrorResult to a callback!");
461 0 : if (!aExecutionReason) {
462 0 : aExecutionReason = "U2FSignCallback";
463 : }
464 0 : CallSetup s(this, aRv, aExecutionReason, aExceptionHandling, aCompartment);
465 0 : if (!s.GetContext()) {
466 0 : MOZ_ASSERT(aRv.Failed());
467 0 : return;
468 : }
469 0 : return Call(s.GetContext(), JS::UndefinedHandleValue, response, aRv);
470 : }
471 :
472 : template <typename T>
473 : inline void
474 : Call(const T& thisVal, const SignResponse& response, const char* aExecutionReason = nullptr)
475 : {
476 : IgnoredErrorResult rv;
477 : return Call(thisVal, response, rv, aExecutionReason);
478 : }
479 :
480 : inline void
481 : Call(const SignResponse& response, const char* aExecutionReason = nullptr)
482 : {
483 : IgnoredErrorResult rv;
484 : return Call(response, rv, aExecutionReason, eReportExceptions, nullptr);
485 : }
486 :
487 : inline bool
488 : operator==(const U2FSignCallback& aOther) const
489 : {
490 : return CallbackFunction::operator==(aOther);
491 : }
492 :
493 : private:
494 : void Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, const SignResponse& response, ErrorResult& aRv);
495 : };
496 :
497 :
498 : namespace binding_detail {
499 0 : class FastU2FRegisterCallback : public U2FRegisterCallback
500 : {
501 : public:
502 0 : explicit inline FastU2FRegisterCallback(JS::Handle<JSObject*> aCallback)
503 0 : : U2FRegisterCallback(aCallback, FastCallbackConstructor())
504 : {
505 0 : }
506 :
507 : inline void
508 0 : Trace(JSTracer* aTracer)
509 : {
510 0 : U2FRegisterCallback::Trace(aTracer);
511 0 : }
512 :
513 : inline void
514 0 : FinishSlowJSInitIfMoreThanOneOwner(JSContext* aCx)
515 : {
516 0 : U2FRegisterCallback::FinishSlowJSInitIfMoreThanOneOwner(aCx);
517 0 : }
518 : };
519 : } // namespace binding_detail
520 :
521 :
522 : namespace binding_detail {
523 0 : class FastU2FSignCallback : public U2FSignCallback
524 : {
525 : public:
526 0 : explicit inline FastU2FSignCallback(JS::Handle<JSObject*> aCallback)
527 0 : : U2FSignCallback(aCallback, FastCallbackConstructor())
528 : {
529 0 : }
530 :
531 : inline void
532 0 : Trace(JSTracer* aTracer)
533 : {
534 0 : U2FSignCallback::Trace(aTracer);
535 0 : }
536 :
537 : inline void
538 0 : FinishSlowJSInitIfMoreThanOneOwner(JSContext* aCx)
539 : {
540 0 : U2FSignCallback::FinishSlowJSInitIfMoreThanOneOwner(aCx);
541 0 : }
542 : };
543 : } // namespace binding_detail
544 :
545 :
546 : namespace U2FBinding {
547 :
548 : typedef mozilla::dom::U2F NativeType;
549 :
550 : bool
551 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj);
552 :
553 : JSObject*
554 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal);
555 :
556 : const JSClass*
557 : GetJSClass();
558 :
559 : bool
560 : Wrap(JSContext* aCx, mozilla::dom::U2F* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector);
561 :
562 : template <class T>
563 0 : inline JSObject* Wrap(JSContext* aCx, T* aObject, JS::Handle<JSObject*> aGivenProto)
564 : {
565 0 : JS::Rooted<JSObject*> reflector(aCx);
566 0 : return Wrap(aCx, aObject, aObject, aGivenProto, &reflector) ? reflector.get() : nullptr;
567 : }
568 :
569 : // We declare this as an array so that retrieving a pointer to this
570 : // binding's property hooks only requires compile/link-time resolvable
571 : // address arithmetic. Declaring it as a pointer instead would require
572 : // doing a run-time load to fetch a pointer to this binding's property
573 : // hooks. And then structures which embedded a pointer to this structure
574 : // would require a run-time load for proper initialization, which would
575 : // then induce static constructors. Lots of static constructors.
576 : extern const NativePropertyHooks sNativePropertyHooks[];
577 :
578 : void
579 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal);
580 :
581 : JS::Handle<JSObject*>
582 : GetProtoObjectHandle(JSContext* aCx);
583 :
584 : JS::Handle<JSObject*>
585 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal = true);
586 :
587 : JSObject*
588 : GetConstructorObject(JSContext* aCx);
589 :
590 : } // namespace U2FBinding
591 :
592 :
593 :
594 : } // namespace dom
595 : } // namespace mozilla
596 :
597 : #endif // mozilla_dom_U2FBinding_h
|