michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 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 michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "MobileMessageCursorCallback.h" michael@0: #include "nsIDOMDOMRequest.h" michael@0: #include "nsIDOMMozSmsMessage.h" michael@0: #include "nsIMobileMessageCallback.h" michael@0: #include "DOMCursor.h" michael@0: #include "nsCxPusher.h" michael@0: #include "nsServiceManagerUtils.h" // for do_GetService michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: namespace mobilemessage { michael@0: michael@0: NS_IMPL_CYCLE_COLLECTION(MobileMessageCursorCallback, mDOMCursor) michael@0: michael@0: NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MobileMessageCursorCallback) michael@0: NS_INTERFACE_MAP_ENTRY(nsIMobileMessageCursorCallback) michael@0: NS_INTERFACE_MAP_ENTRY(nsISupports) michael@0: NS_INTERFACE_MAP_END michael@0: michael@0: NS_IMPL_CYCLE_COLLECTING_ADDREF(MobileMessageCursorCallback) michael@0: NS_IMPL_CYCLE_COLLECTING_RELEASE(MobileMessageCursorCallback) michael@0: michael@0: // nsIMobileMessageCursorCallback michael@0: michael@0: NS_IMETHODIMP michael@0: MobileMessageCursorCallback::NotifyCursorError(int32_t aError) michael@0: { michael@0: MOZ_ASSERT(mDOMCursor); michael@0: michael@0: nsRefPtr cursor = mDOMCursor.forget(); michael@0: michael@0: switch (aError) { michael@0: case nsIMobileMessageCallback::NO_SIGNAL_ERROR: michael@0: cursor->FireError(NS_LITERAL_STRING("NoSignalError")); michael@0: break; michael@0: case nsIMobileMessageCallback::NOT_FOUND_ERROR: michael@0: cursor->FireError(NS_LITERAL_STRING("NotFoundError")); michael@0: break; michael@0: case nsIMobileMessageCallback::UNKNOWN_ERROR: michael@0: cursor->FireError(NS_LITERAL_STRING("UnknownError")); michael@0: break; michael@0: case nsIMobileMessageCallback::INTERNAL_ERROR: michael@0: cursor->FireError(NS_LITERAL_STRING("InternalError")); michael@0: break; michael@0: default: // SUCCESS_NO_ERROR is handled above. michael@0: MOZ_CRASH("Should never get here!"); michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: MobileMessageCursorCallback::NotifyCursorResult(nsISupports* aResult) michael@0: { michael@0: MOZ_ASSERT(mDOMCursor); michael@0: michael@0: nsresult rv; michael@0: nsIScriptContext* scriptContext = mDOMCursor->GetContextForEventHandlers(&rv); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: NS_ENSURE_TRUE(scriptContext, NS_ERROR_FAILURE); michael@0: michael@0: AutoPushJSContext cx(scriptContext->GetNativeContext()); michael@0: NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE); michael@0: michael@0: JS::Rooted global(cx, scriptContext->GetWindowProxy()); michael@0: NS_ENSURE_TRUE(global, NS_ERROR_FAILURE); michael@0: michael@0: JSAutoCompartment ac(cx, global); michael@0: michael@0: JS::Rooted wrappedResult(cx); michael@0: rv = nsContentUtils::WrapNative(cx, aResult, &wrappedResult); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: mDOMCursor->FireSuccess(wrappedResult); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: MobileMessageCursorCallback::NotifyCursorDone() michael@0: { michael@0: MOZ_ASSERT(mDOMCursor); michael@0: michael@0: nsRefPtr cursor = mDOMCursor.forget(); michael@0: cursor->FireDone(); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: } // namespace mobilemessage michael@0: } // namespace dom michael@0: } // namespace mozilla