michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_domrequest_h__ michael@0: #define mozilla_dom_domrequest_h__ michael@0: michael@0: #include "nsIDOMDOMRequest.h" michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/DOMEventTargetHelper.h" michael@0: #include "mozilla/dom/DOMRequestBinding.h" michael@0: michael@0: #include "nsCOMPtr.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: class DOMRequest : public DOMEventTargetHelper, michael@0: public nsIDOMDOMRequest michael@0: { michael@0: protected: michael@0: JS::Heap mResult; michael@0: nsCOMPtr mError; michael@0: bool mDone; michael@0: michael@0: public: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_NSIDOMDOMREQUEST michael@0: NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper) michael@0: michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(DOMRequest, michael@0: DOMEventTargetHelper) michael@0: michael@0: // WrapperCache michael@0: nsPIDOMWindow* GetParentObject() const michael@0: { michael@0: return GetOwner(); michael@0: } michael@0: michael@0: virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: // WebIDL Interface michael@0: DOMRequestReadyState ReadyState() const michael@0: { michael@0: return mDone ? DOMRequestReadyState::Done michael@0: : DOMRequestReadyState::Pending; michael@0: } michael@0: michael@0: void GetResult(JSContext*, JS::MutableHandle aRetval) const michael@0: { michael@0: NS_ASSERTION(mDone || mResult == JSVAL_VOID, michael@0: "Result should be undefined when pending"); michael@0: JS::ExposeValueToActiveJS(mResult); michael@0: aRetval.set(mResult); michael@0: } michael@0: michael@0: nsISupports* GetError() const michael@0: { michael@0: NS_ASSERTION(mDone || !mError, michael@0: "Error should be null when pending"); michael@0: return mError; michael@0: } michael@0: michael@0: IMPL_EVENT_HANDLER(success) michael@0: IMPL_EVENT_HANDLER(error) michael@0: michael@0: michael@0: void FireSuccess(JS::Handle aResult); michael@0: void FireError(const nsAString& aError); michael@0: void FireError(nsresult aError); michael@0: void FireDetailedError(nsISupports* aError); michael@0: michael@0: DOMRequest(nsPIDOMWindow* aWindow); michael@0: michael@0: virtual ~DOMRequest() michael@0: { michael@0: mResult = JSVAL_VOID; michael@0: mozilla::DropJSObjects(this); michael@0: } michael@0: michael@0: protected: michael@0: void FireEvent(const nsAString& aType, bool aBubble, bool aCancelable); michael@0: michael@0: void RootResultVal(); michael@0: }; michael@0: michael@0: class DOMRequestService MOZ_FINAL : public nsIDOMRequestService michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIDOMREQUESTSERVICE michael@0: michael@0: // Returns an owning reference! No one should call this but the factory. michael@0: static DOMRequestService* FactoryCreate() michael@0: { michael@0: DOMRequestService* res = new DOMRequestService; michael@0: NS_ADDREF(res); michael@0: return res; michael@0: } michael@0: }; michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: #define DOMREQUEST_SERVICE_CONTRACTID "@mozilla.org/dom/dom-request-service;1" michael@0: michael@0: #endif // mozilla_dom_domrequest_h__