dom/mobilemessage/src/MobileMessageCursorCallback.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     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
    14 namespace mozilla {
    15 namespace dom {
    16 namespace mobilemessage {
    18 NS_IMPL_CYCLE_COLLECTION(MobileMessageCursorCallback, mDOMCursor)
    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
    25 NS_IMPL_CYCLE_COLLECTING_ADDREF(MobileMessageCursorCallback)
    26 NS_IMPL_CYCLE_COLLECTING_RELEASE(MobileMessageCursorCallback)
    28 // nsIMobileMessageCursorCallback
    30 NS_IMETHODIMP
    31 MobileMessageCursorCallback::NotifyCursorError(int32_t aError)
    32 {
    33   MOZ_ASSERT(mDOMCursor);
    35   nsRefPtr<DOMCursor> cursor = mDOMCursor.forget();
    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   }
    54   return NS_OK;
    55 }
    57 NS_IMETHODIMP
    58 MobileMessageCursorCallback::NotifyCursorResult(nsISupports* aResult)
    59 {
    60   MOZ_ASSERT(mDOMCursor);
    62   nsresult rv;
    63   nsIScriptContext* scriptContext = mDOMCursor->GetContextForEventHandlers(&rv);
    64   NS_ENSURE_SUCCESS(rv, rv);
    65   NS_ENSURE_TRUE(scriptContext, NS_ERROR_FAILURE);
    67   AutoPushJSContext cx(scriptContext->GetNativeContext());
    68   NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE);
    70   JS::Rooted<JSObject*> global(cx, scriptContext->GetWindowProxy());
    71   NS_ENSURE_TRUE(global, NS_ERROR_FAILURE);
    73   JSAutoCompartment ac(cx, global);
    75   JS::Rooted<JS::Value> wrappedResult(cx);
    76   rv = nsContentUtils::WrapNative(cx, aResult, &wrappedResult);
    77   NS_ENSURE_SUCCESS(rv, rv);
    79   mDOMCursor->FireSuccess(wrappedResult);
    80   return NS_OK;
    81 }
    83 NS_IMETHODIMP
    84 MobileMessageCursorCallback::NotifyCursorDone()
    85 {
    86   MOZ_ASSERT(mDOMCursor);
    88   nsRefPtr<DOMCursor> cursor = mDOMCursor.forget();
    89   cursor->FireDone();
    91   return NS_OK;
    92 }
    94 } // namespace mobilemessage
    95 } // namespace dom
    96 } // namespace mozilla

mercurial