Bug 891986 - Keep the source ArrayBuffer to a decodeAudioData call alive until the...
[gecko.git] / dom / base / DOMRequest.h
blobe91ad5aca2f03df0ccab4952d0175dd4f4f11872
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"
16 #include "nsCOMPtr.h"
18 namespace mozilla {
19 namespace dom {
21 class DOMRequest : public nsDOMEventTargetHelper,
22 public nsIDOMDOMRequest
24 protected:
25 JS::Heap<JS::Value> mResult;
26 nsCOMPtr<nsISupports> mError;
27 bool mDone;
28 bool mRooted;
30 public:
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)
38 // WrapperCache
39 nsPIDOMWindow* GetParentObject() const
41 return GetOwner();
44 virtual JSObject* WrapObject(JSContext* aCx,
45 JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
47 // WebIDL Interface
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");
58 return mResult;
61 nsISupports* GetError() const
63 NS_ASSERTION(mDone || !mError,
64 "Error should be null when pending");
65 return mError;
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);
78 DOMRequest();
80 virtual ~DOMRequest()
82 if (mRooted) {
83 UnrootResultVal();
87 protected:
88 void FireEvent(const nsAString& aType, bool aBubble, bool aCancelable);
90 void RootResultVal();
91 void UnrootResultVal();
93 void Init(nsIDOMWindow* aWindow);
96 class DOMRequestService MOZ_FINAL : public nsIDOMRequestService
98 public:
99 NS_DECL_ISUPPORTS
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;
106 NS_ADDREF(res);
107 return res;
111 } // namespace dom
112 } // namespace mozilla
114 #define DOMREQUEST_SERVICE_CONTRACTID "@mozilla.org/dom/dom-request-service;1"
116 #endif // mozilla_dom_domrequest_h__