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