mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 797345 - send a system message to notify that 'file transfer completed', r=qdot
This commit is contained in:
parent
cb6c0744e7
commit
0d949fabe1
@ -12,6 +12,7 @@
|
||||
#include "BluetoothScoManager.h"
|
||||
#include "BluetoothService.h"
|
||||
#include "BluetoothServiceUuid.h"
|
||||
#include "BluetoothUtils.h"
|
||||
|
||||
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
|
||||
#include "mozilla/Services.h"
|
||||
@ -20,9 +21,6 @@
|
||||
#include "nsIAudioManager.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIRadioInterfaceLayer.h"
|
||||
#include "nsISystemMessagesInternal.h"
|
||||
#include "BluetoothUtils.h"
|
||||
|
||||
#include "nsVariant.h"
|
||||
|
||||
#include <unistd.h> /* usleep() */
|
||||
@ -212,39 +210,6 @@ BluetoothHfpManager::Get()
|
||||
return gBluetoothHfpManager;
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothHfpManager::BroadcastSystemMessage(const nsAString& aType,
|
||||
const InfallibleTArray<BluetoothNamedValue>& aData)
|
||||
{
|
||||
JSContext* cx = nsContentUtils::GetSafeJSContext();
|
||||
NS_ASSERTION(!::JS_IsExceptionPending(cx),
|
||||
"Shouldn't get here when an exception is pending!");
|
||||
|
||||
JSAutoRequest jsar(cx);
|
||||
JSObject* obj = JS_NewObject(cx, NULL, NULL, NULL);
|
||||
if (!obj) {
|
||||
NS_WARNING("Failed to new JSObject for system message!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!SetJsObject(cx, obj, aData)) {
|
||||
NS_WARNING("Failed to set properties of system message!");
|
||||
return false;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISystemMessagesInternal> systemMessenger =
|
||||
do_GetService("@mozilla.org/system-message-internal;1");
|
||||
|
||||
if (!systemMessenger) {
|
||||
NS_WARNING("Failed to get SystemMessenger service!");
|
||||
return false;
|
||||
}
|
||||
|
||||
systemMessenger->BroadcastMessage(aType, OBJECT_TO_JSVAL(obj));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHfpManager::NotifySettings(const bool aConnected)
|
||||
{
|
||||
|
@ -15,7 +15,6 @@
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothReplyRunnable;
|
||||
class BluetoothNamedValue;
|
||||
|
||||
class BluetoothHfpManager : public mozilla::ipc::UnixSocketConsumer
|
||||
, public nsIObserver
|
||||
@ -41,8 +40,6 @@ private:
|
||||
void Cleanup();
|
||||
nsresult HandleVolumeChanged(const nsAString& aData);
|
||||
nsresult HandleShutdown();
|
||||
bool BroadcastSystemMessage(const nsAString& aType,
|
||||
const InfallibleTArray<BluetoothNamedValue>& aData);
|
||||
void NotifyDialer(const nsAString& aCommand);
|
||||
void NotifySettings(const bool aConnected);
|
||||
|
||||
|
@ -10,8 +10,10 @@
|
||||
#include "BluetoothReplyRunnable.h"
|
||||
#include "BluetoothService.h"
|
||||
#include "BluetoothServiceUuid.h"
|
||||
#include "BluetoothUtils.h"
|
||||
#include "ObexBase.h"
|
||||
|
||||
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "nsIInputStream.h"
|
||||
|
||||
@ -20,7 +22,8 @@ using namespace mozilla::ipc;
|
||||
|
||||
static mozilla::RefPtr<BluetoothOppManager> sInstance;
|
||||
static nsCOMPtr<nsIInputStream> stream = nullptr;
|
||||
static uint64_t sSentFileSize = 0;
|
||||
static uint32_t sSentFileSize = 0;
|
||||
static nsString sFileName;
|
||||
|
||||
class ReadFileTask : public nsRunnable
|
||||
{
|
||||
@ -207,13 +210,12 @@ BluetoothOppManager::ReceiveSocketData(UnixSocketRawData* aMessage)
|
||||
*/
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIDOMFile> file = do_QueryInterface(mBlob);
|
||||
nsString fileName;
|
||||
if (file) {
|
||||
rv = file->GetName(fileName);
|
||||
rv = file->GetName(sFileName);
|
||||
}
|
||||
|
||||
if (!file || fileName.IsEmpty()) {
|
||||
fileName.AssignLiteral("Unknown");
|
||||
if (!file || sFileName.IsEmpty()) {
|
||||
sFileName.AssignLiteral("Unknown");
|
||||
}
|
||||
|
||||
uint64_t fileSize;
|
||||
@ -231,7 +233,7 @@ BluetoothOppManager::ReceiveSocketData(UnixSocketRawData* aMessage)
|
||||
|
||||
sSentFileSize = 0;
|
||||
mAbortFlag = false;
|
||||
sInstance->SendPutHeaderRequest(fileName, fileSize);
|
||||
sInstance->SendPutHeaderRequest(sFileName, fileSize);
|
||||
}
|
||||
}
|
||||
} else if (mLastCommand == ObexRequestCode::Disconnect) {
|
||||
@ -263,6 +265,7 @@ BluetoothOppManager::ReceiveSocketData(UnixSocketRawData* aMessage)
|
||||
// FIXME: Needs error handling here
|
||||
NS_WARNING("[OPP] PutFinal failed");
|
||||
} else {
|
||||
FileTransferComplete(true, false, sFileName, sSentFileSize);
|
||||
SendDisconnectRequest();
|
||||
}
|
||||
} else if (mLastCommand == ObexRequestCode::Abort) {
|
||||
@ -270,6 +273,7 @@ BluetoothOppManager::ReceiveSocketData(UnixSocketRawData* aMessage)
|
||||
NS_WARNING("[OPP] Abort failed");
|
||||
}
|
||||
|
||||
FileTransferComplete(false, false, sFileName, sSentFileSize);
|
||||
SendDisconnectRequest();
|
||||
}
|
||||
}
|
||||
@ -397,3 +401,36 @@ BluetoothOppManager::SendAbortRequest()
|
||||
memcpy(s->mData, req, s->mSize);
|
||||
SendSocketData(s);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothOppManager::FileTransferComplete(bool aSuccess,
|
||||
bool aReceived,
|
||||
const nsString& aFileName,
|
||||
uint32_t aFileLength)
|
||||
{
|
||||
nsString type, name;
|
||||
BluetoothValue v;
|
||||
InfallibleTArray<BluetoothNamedValue> parameters;
|
||||
type.AssignLiteral("bluetooth-opp-transfer-complete");
|
||||
|
||||
name.AssignLiteral("success");
|
||||
v = aSuccess;
|
||||
parameters.AppendElement(BluetoothNamedValue(name, v));
|
||||
|
||||
name.AssignLiteral("received");
|
||||
v = aReceived;
|
||||
parameters.AppendElement(BluetoothNamedValue(name, v));
|
||||
|
||||
name.AssignLiteral("filename");
|
||||
v = aFileName;
|
||||
parameters.AppendElement(BluetoothNamedValue(name, v));
|
||||
|
||||
name.AssignLiteral("filelength");
|
||||
v = aFileLength;
|
||||
parameters.AppendElement(BluetoothNamedValue(name, v));
|
||||
|
||||
if (!BroadcastSystemMessage(type, parameters)) {
|
||||
NS_WARNING("Failed to broadcast [bluetooth-opp-transfer-complete]");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -61,6 +61,9 @@ public:
|
||||
|
||||
private:
|
||||
BluetoothOppManager();
|
||||
void UpdateProgress(uint32_t aTotalBytes, uint32_t aSentBytes);
|
||||
void FileTransferComplete(bool aSuccess, bool aReceived,
|
||||
const nsString& aFileName, uint32_t aFileLength);
|
||||
|
||||
bool mConnected;
|
||||
int mConnectionId;
|
||||
|
@ -6,14 +6,17 @@
|
||||
|
||||
#include "base/basictypes.h"
|
||||
|
||||
#include "BluetoothUtils.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "BluetoothDevice.h"
|
||||
#include "BluetoothUtils.h"
|
||||
#include "jsapi.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsString.h"
|
||||
#include "mozilla/Scoped.h"
|
||||
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsISystemMessagesInternal.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsString.h"
|
||||
|
||||
USING_BLUETOOTH_NAMESPACE
|
||||
|
||||
nsresult
|
||||
mozilla::dom::bluetooth::StringArrayToJSArray(JSContext* aCx, JSObject* aGlobal,
|
||||
@ -166,3 +169,37 @@ mozilla::dom::bluetooth::GetAddressFromObjectPath(const nsAString& aObjectPath)
|
||||
return address;
|
||||
}
|
||||
|
||||
bool
|
||||
mozilla::dom::bluetooth::BroadcastSystemMessage(
|
||||
const nsAString& aType,
|
||||
const InfallibleTArray<BluetoothNamedValue>& aData)
|
||||
{
|
||||
JSContext* cx = nsContentUtils::GetSafeJSContext();
|
||||
NS_ASSERTION(!::JS_IsExceptionPending(cx),
|
||||
"Shouldn't get here when an exception is pending!");
|
||||
|
||||
JSAutoRequest jsar(cx);
|
||||
JSObject* obj = JS_NewObject(cx, NULL, NULL, NULL);
|
||||
if (!obj) {
|
||||
NS_WARNING("Failed to new JSObject for system message!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!SetJsObject(cx, obj, aData)) {
|
||||
NS_WARNING("Failed to set properties of system message!");
|
||||
return false;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISystemMessagesInternal> systemMessenger =
|
||||
do_GetService("@mozilla.org/system-message-internal;1");
|
||||
|
||||
if (!systemMessenger) {
|
||||
NS_WARNING("Failed to get SystemMessenger service!");
|
||||
return false;
|
||||
}
|
||||
|
||||
systemMessenger->BroadcastMessage(aType, OBJECT_TO_JSVAL(obj));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,10 @@ GetObjectPathFromAddress(const nsAString& aAdapterPath,
|
||||
nsString
|
||||
GetAddressFromObjectPath(const nsAString& aObjectPath);
|
||||
|
||||
bool
|
||||
BroadcastSystemMessage(const nsAString& aType,
|
||||
const InfallibleTArray<BluetoothNamedValue>& aData);
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user