1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_domrequest_h__
8 #define mozilla_dom_domrequest_h__
10 #include "nsIDOMDOMRequest.h"
11 #include "mozilla/Attributes.h"
12 #include "mozilla/DOMEventTargetHelper.h"
13 #include "mozilla/dom/DOMError.h"
14 #include "mozilla/dom/DOMRequestBinding.h"
27 class DOMRequest
: public DOMEventTargetHelper
,
28 public nsIDOMDOMRequest
31 JS::Heap
<JS::Value
> mResult
;
32 nsRefPtr
<DOMError
> mError
;
33 nsRefPtr
<Promise
> mPromise
;
37 NS_DECL_ISUPPORTS_INHERITED
38 NS_DECL_NSIDOMDOMREQUEST
39 NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper
)
41 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(DOMRequest
,
45 nsPIDOMWindow
* GetParentObject() const
50 virtual JSObject
* WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
53 DOMRequestReadyState
ReadyState() const
55 return mDone
? DOMRequestReadyState::Done
56 : DOMRequestReadyState::Pending
;
59 void GetResult(JSContext
*, JS::MutableHandle
<JS::Value
> aRetval
) const
61 NS_ASSERTION(mDone
|| mResult
== JSVAL_VOID
,
62 "Result should be undefined when pending");
63 JS::ExposeValueToActiveJS(mResult
);
67 DOMError
* GetError() const
69 NS_ASSERTION(mDone
|| !mError
,
70 "Error should be null when pending");
74 IMPL_EVENT_HANDLER(success
)
75 IMPL_EVENT_HANDLER(error
)
77 already_AddRefed
<mozilla::dom::Promise
>
78 Then(JSContext
* aCx
, AnyCallback
* aResolveCallback
,
79 AnyCallback
* aRejectCallback
, mozilla::ErrorResult
& aRv
);
81 void FireSuccess(JS::Handle
<JS::Value
> aResult
);
82 void FireError(const nsAString
& aError
);
83 void FireError(nsresult aError
);
84 void FireDetailedError(DOMError
* aError
);
86 explicit DOMRequest(nsPIDOMWindow
* aWindow
);
89 virtual ~DOMRequest();
91 void FireEvent(const nsAString
& aType
, bool aBubble
, bool aCancelable
);
96 class DOMRequestService MOZ_FINAL
: public nsIDOMRequestService
98 ~DOMRequestService() {}
102 NS_DECL_NSIDOMREQUESTSERVICE
104 // Returns an owning reference! No one should call this but the factory.
105 static DOMRequestService
* FactoryCreate()
107 DOMRequestService
* res
= new DOMRequestService
;
114 } // namespace mozilla
116 #define DOMREQUEST_SERVICE_CONTRACTID "@mozilla.org/dom/dom-request-service;1"
118 #endif // mozilla_dom_domrequest_h__