Bug 1059702 - Use wifi.tethering.interface for wifi AP if it does exist. r=vchang
[gecko.git] / dom / bluetooth / BluetoothReplyRunnable.cpp
blobd2e2f3771b93d49e4552f14464537c8ce8d6fb8b
1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "base/basictypes.h"
8 #include "BluetoothReplyRunnable.h"
9 #include "DOMRequest.h"
10 #include "mozilla/dom/ScriptSettings.h"
11 #include "mozilla/dom/bluetooth/BluetoothTypes.h"
12 #include "nsServiceManagerUtils.h"
14 USING_BLUETOOTH_NAMESPACE
16 BluetoothReplyRunnable::BluetoothReplyRunnable(nsIDOMDOMRequest* aReq)
17 : mDOMRequest(aReq)
20 void
21 BluetoothReplyRunnable::SetReply(BluetoothReply* aReply)
23 mReply = aReply;
26 void
27 BluetoothReplyRunnable::ReleaseMembers()
29 mDOMRequest = nullptr;
32 BluetoothReplyRunnable::~BluetoothReplyRunnable()
35 nsresult
36 BluetoothReplyRunnable::FireReply(JS::Handle<JS::Value> aVal)
38 nsCOMPtr<nsIDOMRequestService> rs =
39 do_GetService(DOMREQUEST_SERVICE_CONTRACTID);
40 NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE);
42 return mReply->type() == BluetoothReply::TBluetoothReplySuccess ?
43 rs->FireSuccessAsync(mDOMRequest, aVal) :
44 rs->FireErrorAsync(mDOMRequest, mReply->get_BluetoothReplyError().error());
47 nsresult
48 BluetoothReplyRunnable::FireErrorString()
50 nsCOMPtr<nsIDOMRequestService> rs =
51 do_GetService("@mozilla.org/dom/dom-request-service;1");
52 NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE);
54 return rs->FireErrorAsync(mDOMRequest, mErrorString);
57 NS_IMETHODIMP
58 BluetoothReplyRunnable::Run()
60 MOZ_ASSERT(NS_IsMainThread());
61 MOZ_ASSERT(mDOMRequest);
62 MOZ_ASSERT(mReply);
64 nsresult rv;
66 AutoSafeJSContext cx;
67 JS::Rooted<JS::Value> v(cx, JSVAL_VOID);
69 if (mReply->type() != BluetoothReply::TBluetoothReplySuccess) {
70 rv = FireReply(v);
71 } else {
72 if (!ParseSuccessfulReply(&v)) {
73 rv = FireErrorString();
74 } else {
75 rv = FireReply(v);
79 if (NS_FAILED(rv)) {
80 BT_WARNING("Could not fire DOMRequest!");
83 ReleaseMembers();
84 MOZ_ASSERT(!mDOMRequest,
85 "mDOMRequest still alive! Deriving class should call "
86 "BluetoothReplyRunnable::ReleaseMembers()!");
88 return rv;
91 BluetoothVoidReplyRunnable::BluetoothVoidReplyRunnable(nsIDOMDOMRequest* aReq)
92 : BluetoothReplyRunnable(aReq)
95 BluetoothVoidReplyRunnable::~BluetoothVoidReplyRunnable()