Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "MobileMessageCursorCallback.h" |
michael@0 | 7 | #include "nsIDOMDOMRequest.h" |
michael@0 | 8 | #include "nsIDOMMozSmsMessage.h" |
michael@0 | 9 | #include "nsIMobileMessageCallback.h" |
michael@0 | 10 | #include "DOMCursor.h" |
michael@0 | 11 | #include "nsCxPusher.h" |
michael@0 | 12 | #include "nsServiceManagerUtils.h" // for do_GetService |
michael@0 | 13 | |
michael@0 | 14 | namespace mozilla { |
michael@0 | 15 | namespace dom { |
michael@0 | 16 | namespace mobilemessage { |
michael@0 | 17 | |
michael@0 | 18 | NS_IMPL_CYCLE_COLLECTION(MobileMessageCursorCallback, mDOMCursor) |
michael@0 | 19 | |
michael@0 | 20 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MobileMessageCursorCallback) |
michael@0 | 21 | NS_INTERFACE_MAP_ENTRY(nsIMobileMessageCursorCallback) |
michael@0 | 22 | NS_INTERFACE_MAP_ENTRY(nsISupports) |
michael@0 | 23 | NS_INTERFACE_MAP_END |
michael@0 | 24 | |
michael@0 | 25 | NS_IMPL_CYCLE_COLLECTING_ADDREF(MobileMessageCursorCallback) |
michael@0 | 26 | NS_IMPL_CYCLE_COLLECTING_RELEASE(MobileMessageCursorCallback) |
michael@0 | 27 | |
michael@0 | 28 | // nsIMobileMessageCursorCallback |
michael@0 | 29 | |
michael@0 | 30 | NS_IMETHODIMP |
michael@0 | 31 | MobileMessageCursorCallback::NotifyCursorError(int32_t aError) |
michael@0 | 32 | { |
michael@0 | 33 | MOZ_ASSERT(mDOMCursor); |
michael@0 | 34 | |
michael@0 | 35 | nsRefPtr<DOMCursor> cursor = mDOMCursor.forget(); |
michael@0 | 36 | |
michael@0 | 37 | switch (aError) { |
michael@0 | 38 | case nsIMobileMessageCallback::NO_SIGNAL_ERROR: |
michael@0 | 39 | cursor->FireError(NS_LITERAL_STRING("NoSignalError")); |
michael@0 | 40 | break; |
michael@0 | 41 | case nsIMobileMessageCallback::NOT_FOUND_ERROR: |
michael@0 | 42 | cursor->FireError(NS_LITERAL_STRING("NotFoundError")); |
michael@0 | 43 | break; |
michael@0 | 44 | case nsIMobileMessageCallback::UNKNOWN_ERROR: |
michael@0 | 45 | cursor->FireError(NS_LITERAL_STRING("UnknownError")); |
michael@0 | 46 | break; |
michael@0 | 47 | case nsIMobileMessageCallback::INTERNAL_ERROR: |
michael@0 | 48 | cursor->FireError(NS_LITERAL_STRING("InternalError")); |
michael@0 | 49 | break; |
michael@0 | 50 | default: // SUCCESS_NO_ERROR is handled above. |
michael@0 | 51 | MOZ_CRASH("Should never get here!"); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | return NS_OK; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | NS_IMETHODIMP |
michael@0 | 58 | MobileMessageCursorCallback::NotifyCursorResult(nsISupports* aResult) |
michael@0 | 59 | { |
michael@0 | 60 | MOZ_ASSERT(mDOMCursor); |
michael@0 | 61 | |
michael@0 | 62 | nsresult rv; |
michael@0 | 63 | nsIScriptContext* scriptContext = mDOMCursor->GetContextForEventHandlers(&rv); |
michael@0 | 64 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 65 | NS_ENSURE_TRUE(scriptContext, NS_ERROR_FAILURE); |
michael@0 | 66 | |
michael@0 | 67 | AutoPushJSContext cx(scriptContext->GetNativeContext()); |
michael@0 | 68 | NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE); |
michael@0 | 69 | |
michael@0 | 70 | JS::Rooted<JSObject*> global(cx, scriptContext->GetWindowProxy()); |
michael@0 | 71 | NS_ENSURE_TRUE(global, NS_ERROR_FAILURE); |
michael@0 | 72 | |
michael@0 | 73 | JSAutoCompartment ac(cx, global); |
michael@0 | 74 | |
michael@0 | 75 | JS::Rooted<JS::Value> wrappedResult(cx); |
michael@0 | 76 | rv = nsContentUtils::WrapNative(cx, aResult, &wrappedResult); |
michael@0 | 77 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 78 | |
michael@0 | 79 | mDOMCursor->FireSuccess(wrappedResult); |
michael@0 | 80 | return NS_OK; |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | NS_IMETHODIMP |
michael@0 | 84 | MobileMessageCursorCallback::NotifyCursorDone() |
michael@0 | 85 | { |
michael@0 | 86 | MOZ_ASSERT(mDOMCursor); |
michael@0 | 87 | |
michael@0 | 88 | nsRefPtr<DOMCursor> cursor = mDOMCursor.forget(); |
michael@0 | 89 | cursor->FireDone(); |
michael@0 | 90 | |
michael@0 | 91 | return NS_OK; |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | } // namespace mobilemessage |
michael@0 | 95 | } // namespace dom |
michael@0 | 96 | } // namespace mozilla |