Bumping manifests a=b2g-bump
[gecko.git] / dom / base / DOMRequest.h
blobcd19dc02adcac7a2155c7cbc99bd67d861d7bc87
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"
16 #include "nsCOMPtr.h"
18 namespace mozilla {
19 namespace dom {
21 class DOMRequest : public DOMEventTargetHelper,
22 public nsIDOMDOMRequest
24 protected:
25 JS::Heap<JS::Value> mResult;
26 nsRefPtr<DOMError> mError;
27 bool mDone;
29 public:
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,
35 DOMEventTargetHelper)
37 // WrapperCache
38 nsPIDOMWindow* GetParentObject() const
40 return GetOwner();
43 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
45 // WebIDL Interface
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);
57 aRetval.set(mResult);
60 DOMError* GetError() const
62 NS_ASSERTION(mDone || !mError,
63 "Error should be null when pending");
64 return mError;
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);
78 protected:
79 virtual ~DOMRequest()
81 mResult = JSVAL_VOID;
82 mozilla::DropJSObjects(this);
85 void FireEvent(const nsAString& aType, bool aBubble, bool aCancelable);
87 void RootResultVal();
90 class DOMRequestService MOZ_FINAL : public nsIDOMRequestService
92 ~DOMRequestService() {}
94 public:
95 NS_DECL_ISUPPORTS
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;
102 NS_ADDREF(res);
103 return res;
107 } // namespace dom
108 } // namespace mozilla
110 #define DOMREQUEST_SERVICE_CONTRACTID "@mozilla.org/dom/dom-request-service;1"
112 #endif // mozilla_dom_domrequest_h__