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
)
21 BluetoothReplyRunnable::SetReply(BluetoothReply
* aReply
)
27 BluetoothReplyRunnable::ReleaseMembers()
29 mDOMRequest
= nullptr;
32 BluetoothReplyRunnable::~BluetoothReplyRunnable()
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());
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
);
58 BluetoothReplyRunnable::Run()
60 MOZ_ASSERT(NS_IsMainThread());
61 MOZ_ASSERT(mDOMRequest
);
67 JS::Rooted
<JS::Value
> v(cx
, JSVAL_VOID
);
69 if (mReply
->type() != BluetoothReply::TBluetoothReplySuccess
) {
72 if (!ParseSuccessfulReply(&v
)) {
73 rv
= FireErrorString();
80 BT_WARNING("Could not fire DOMRequest!");
84 MOZ_ASSERT(!mDOMRequest
,
85 "mDOMRequest still alive! Deriving class should call "
86 "BluetoothReplyRunnable::ReleaseMembers()!");
91 BluetoothVoidReplyRunnable::BluetoothVoidReplyRunnable(nsIDOMDOMRequest
* aReq
)
92 : BluetoothReplyRunnable(aReq
)
95 BluetoothVoidReplyRunnable::~BluetoothVoidReplyRunnable()