static bool SendAsyncMessageToParent(void* aCallbackData, const nsAString& aMessage, const StructuredCloneData& aData) { TabChild* tabChild = static_cast<TabChild*>(aCallbackData); ContentChild* cc = static_cast<ContentChild*>(tabChild->Manager()); ClonedMessageData data; SerializedStructuredCloneBuffer& buffer = data.data(); buffer.data = aData.mData; buffer.dataLength = aData.mDataLength; const nsTArray<nsCOMPtr<nsIDOMBlob> >& blobs = aData.mClosure.mBlobs; if (!blobs.IsEmpty()) { InfallibleTArray<PBlobChild*>& blobChildList = data.blobsChild(); PRUint32 length = blobs.Length(); blobChildList.SetCapacity(length); for (PRUint32 i = 0; i < length; ++i) { BlobChild* blobChild = cc->GetOrCreateActorForBlob(blobs[i]); if (!blobChild) { return false; } blobChildList.AppendElement(blobChild); } } return tabChild->SendAsyncMessage(nsString(aMessage), data); }
already_AddRefed<Promise> BluetoothMapRequestHandle::ReplyToMessagesListing(long aMasId, Blob& aBlob, bool aNewMessage, const nsAString& aTimestamp, int aSize, ErrorResult& aRv) { nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject()); if (!global) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } nsRefPtr<Promise> promise = Promise::Create(global, aRv); NS_ENSURE_TRUE(!aRv.Failed(), nullptr); BluetoothService* bs = BluetoothService::Get(); if (!bs) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } if (XRE_GetProcessType() == GeckoProcessType_Default) { // In-process reply bs->ReplyToMapMessagesListing(aMasId, &aBlob, aNewMessage, aTimestamp, aSize, new BluetoothVoidReplyRunnable(nullptr, promise)); } else { ContentChild *cc = ContentChild::GetSingleton(); if (!cc) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } BlobChild* actor = cc->GetOrCreateActorForBlob(&aBlob); if (!actor) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } bs->ReplyToMapMessagesListing(nullptr, actor, aMasId, aNewMessage, aTimestamp, aSize, new BluetoothVoidReplyRunnable(nullptr, promise)); } return promise.forget(); }
already_AddRefed<DOMRequest> BluetoothPbapRequestHandle::ReplyToPhonebookPulling(Blob& aBlob, uint16_t phonebookSize, ErrorResult& aRv) { nsCOMPtr<nsPIDOMWindow> win = GetParentObject(); if (!win) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } RefPtr<DOMRequest> request = new DOMRequest(win); RefPtr<BluetoothVoidReplyRunnable> result = new BluetoothVoidReplyRunnable(request); BluetoothService* bs = BluetoothService::Get(); if (!bs) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } if (XRE_GetProcessType() == GeckoProcessType_Default) { // In-process reply bs->ReplyToPhonebookPulling(&aBlob, phonebookSize, result); } else { ContentChild *cc = ContentChild::GetSingleton(); if (!cc) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } BlobChild* actor = cc->GetOrCreateActorForBlob(&aBlob); if (!actor) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } bs->ReplyToPhonebookPulling(nullptr, actor, phonebookSize, result); } return request.forget(); }
already_AddRefed<DOMRequest> BluetoothAdapter::SendFile(const nsAString& aDeviceAddress, File& aBlob, ErrorResult& aRv) { nsCOMPtr<nsPIDOMWindow> win = GetOwner(); if (!win) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } nsRefPtr<DOMRequest> request = new DOMRequest(win); nsRefPtr<BluetoothVoidReplyRunnable> results = new BluetoothVoidReplyRunnable(request); BluetoothService* bs = BluetoothService::Get(); if (!bs) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } if (XRE_GetProcessType() == GeckoProcessType_Default) { // In-process transfer bs->SendFile(aDeviceAddress, &aBlob, results); } else { ContentChild *cc = ContentChild::GetSingleton(); if (!cc) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } BlobChild* actor = cc->GetOrCreateActorForBlob(&aBlob); if (!actor) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } bs->SendFile(aDeviceAddress, nullptr, actor, results); } return request.forget(); }