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 "nsDOMEventTargetHelper.h"
12 #include "mozilla/Attributes.h"
13 #include "mozilla/dom/DOMError.h"
14 #include "mozilla/dom/DOMRequestBinding.h"
21 class DOMRequest
: public nsDOMEventTargetHelper
,
22 public nsIDOMDOMRequest
25 JS::Heap
<JS::Value
> mResult
;
26 nsCOMPtr
<nsISupports
> mError
;
31 NS_DECL_ISUPPORTS_INHERITED
32 NS_DECL_NSIDOMDOMREQUEST
33 NS_REALLY_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetHelper
)
35 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(DOMRequest
,
36 nsDOMEventTargetHelper
)
39 nsPIDOMWindow
* GetParentObject() const
44 virtual JSObject
* WrapObject(JSContext
* aCx
,
45 JS::Handle
<JSObject
*> aScope
) MOZ_OVERRIDE
;
48 DOMRequestReadyState
ReadyState() const
50 return mDone
? DOMRequestReadyState::Done
51 : DOMRequestReadyState::Pending
;
54 JS::Value
Result(JSContext
* = nullptr) const
56 NS_ASSERTION(mDone
|| mResult
== JSVAL_VOID
,
57 "Result should be undefined when pending");
61 nsISupports
* GetError() const
63 NS_ASSERTION(mDone
|| !mError
,
64 "Error should be null when pending");
68 IMPL_EVENT_HANDLER(success
)
69 IMPL_EVENT_HANDLER(error
)
72 void FireSuccess(JS::Handle
<JS::Value
> aResult
);
73 void FireError(const nsAString
& aError
);
74 void FireError(nsresult aError
);
75 void FireDetailedError(nsISupports
* aError
);
77 DOMRequest(nsIDOMWindow
* aWindow
);
88 void FireEvent(const nsAString
& aType
, bool aBubble
, bool aCancelable
);
91 void UnrootResultVal();
93 void Init(nsIDOMWindow
* aWindow
);
96 class DOMRequestService MOZ_FINAL
: public nsIDOMRequestService
100 NS_DECL_NSIDOMREQUESTSERVICE
102 // Returns an owning reference! No one should call this but the factory.
103 static DOMRequestService
* FactoryCreate()
105 DOMRequestService
* res
= new DOMRequestService
;
112 } // namespace mozilla
114 #define DOMREQUEST_SERVICE_CONTRACTID "@mozilla.org/dom/dom-request-service;1"
116 #endif // mozilla_dom_domrequest_h__