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"
21 class DOMRequest
: public DOMEventTargetHelper
,
22 public nsIDOMDOMRequest
25 JS::Heap
<JS::Value
> mResult
;
26 nsRefPtr
<DOMError
> mError
;
30 NS_DECL_ISUPPORTS_INHERITED
31 NS_DECL_NSIDOMDOMREQUEST
32 NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper
)
34 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(DOMRequest
,
38 nsPIDOMWindow
* GetParentObject() const
43 virtual JSObject
* WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
46 DOMRequestReadyState
ReadyState() const
48 return mDone
? DOMRequestReadyState::Done
49 : DOMRequestReadyState::Pending
;
52 void GetResult(JSContext
*, JS::MutableHandle
<JS::Value
> aRetval
) const
54 NS_ASSERTION(mDone
|| mResult
== JSVAL_VOID
,
55 "Result should be undefined when pending");
56 JS::ExposeValueToActiveJS(mResult
);
60 DOMError
* GetError() const
62 NS_ASSERTION(mDone
|| !mError
,
63 "Error should be null when pending");
67 IMPL_EVENT_HANDLER(success
)
68 IMPL_EVENT_HANDLER(error
)
71 void FireSuccess(JS::Handle
<JS::Value
> aResult
);
72 void FireError(const nsAString
& aError
);
73 void FireError(nsresult aError
);
74 void FireDetailedError(DOMError
* aError
);
76 explicit DOMRequest(nsPIDOMWindow
* aWindow
);
82 mozilla::DropJSObjects(this);
85 void FireEvent(const nsAString
& aType
, bool aBubble
, bool aCancelable
);
90 class DOMRequestService MOZ_FINAL
: public nsIDOMRequestService
92 ~DOMRequestService() {}
96 NS_DECL_NSIDOMREQUESTSERVICE
98 // Returns an owning reference! No one should call this but the factory.
99 static DOMRequestService
* FactoryCreate()
101 DOMRequestService
* res
= new DOMRequestService
;
108 } // namespace mozilla
110 #define DOMREQUEST_SERVICE_CONTRACTID "@mozilla.org/dom/dom-request-service;1"
112 #endif // mozilla_dom_domrequest_h__