зеркало из https://github.com/mozilla/gecko-dev.git
Bug 962310 - Support in-process bt file transfer, f=bent, r=gyeh
Currently if an app which lives in chrome process calls SendFile() to send a file via Bluetooth, it would crash.
This commit is contained in:
Родитель
d28660dfff
Коммит
e990369c4b
|
@ -739,20 +739,30 @@ BluetoothAdapter::SendFile(const nsAString& aDeviceAddress,
|
|||
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
||||
new BluetoothVoidReplyRunnable(request);
|
||||
|
||||
BlobChild* actor =
|
||||
ContentChild::GetSingleton()->GetOrCreateActorForBlob(aBlob);
|
||||
if (!actor) {
|
||||
BT_WARNING("Can't create actor");
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
bs->SendFile(aDeviceAddress, nullptr, actor, results);
|
||||
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "mozilla/dom/ipc/Blob.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsClassHashtable.h"
|
||||
#include "nsIDOMFile.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsIThread.h"
|
||||
#include "nsTObserverArray.h"
|
||||
|
@ -229,6 +230,11 @@ public:
|
|||
BlobChild* aBlobChild,
|
||||
BluetoothReplyRunnable* aRunnable) = 0;
|
||||
|
||||
virtual void
|
||||
SendFile(const nsAString& aDeviceAddress,
|
||||
nsIDOMBlob* aBlob,
|
||||
BluetoothReplyRunnable* aRunnable) = 0;
|
||||
|
||||
virtual void
|
||||
StopSendingFile(const nsAString& aDeviceAddress,
|
||||
BluetoothReplyRunnable* aRunnable) = 0;
|
||||
|
|
|
@ -59,11 +59,10 @@ static bool sInShutdown = false;
|
|||
|
||||
class mozilla::dom::bluetooth::SendFileBatch {
|
||||
public:
|
||||
SendFileBatch(const nsAString& aDeviceAddress, BlobParent* aActor)
|
||||
SendFileBatch(const nsAString& aDeviceAddress, nsIDOMBlob* aBlob)
|
||||
: mDeviceAddress(aDeviceAddress)
|
||||
{
|
||||
nsCOMPtr<nsIDOMBlob> blob = aActor->GetBlob();
|
||||
mBlobs.AppendElement(blob);
|
||||
mBlobs.AppendElement(aBlob);
|
||||
}
|
||||
|
||||
nsString mDeviceAddress;
|
||||
|
@ -349,7 +348,18 @@ BluetoothOppManager::SendFile(const nsAString& aDeviceAddress,
|
|||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
AppendBlobToSend(aDeviceAddress, aActor);
|
||||
nsCOMPtr<nsIDOMBlob> blob = aActor->GetBlob();
|
||||
|
||||
return SendFile(aDeviceAddress, blob.get());
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothOppManager::SendFile(const nsAString& aDeviceAddress,
|
||||
nsIDOMBlob* aBlob)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
AppendBlobToSend(aDeviceAddress, aBlob);
|
||||
if (!mSocket) {
|
||||
ProcessNextBatch();
|
||||
}
|
||||
|
@ -359,7 +369,7 @@ BluetoothOppManager::SendFile(const nsAString& aDeviceAddress,
|
|||
|
||||
void
|
||||
BluetoothOppManager::AppendBlobToSend(const nsAString& aDeviceAddress,
|
||||
BlobParent* aActor)
|
||||
nsIDOMBlob* aBlob)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
|
@ -372,11 +382,10 @@ BluetoothOppManager::AppendBlobToSend(const nsAString& aDeviceAddress,
|
|||
*/
|
||||
if (mBatches.IsEmpty() ||
|
||||
aDeviceAddress != mBatches[indexTail].mDeviceAddress) {
|
||||
SendFileBatch batch(aDeviceAddress, aActor);
|
||||
SendFileBatch batch(aDeviceAddress, aBlob);
|
||||
mBatches.AppendElement(batch);
|
||||
} else {
|
||||
nsCOMPtr<nsIDOMBlob> blob = aActor->GetBlob();
|
||||
mBatches[indexTail].mBlobs.AppendElement(blob);
|
||||
mBatches[indexTail].mBlobs.AppendElement(aBlob);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ public:
|
|||
bool Listen();
|
||||
|
||||
bool SendFile(const nsAString& aDeviceAddress, BlobParent* aActor);
|
||||
bool SendFile(const nsAString& aDeviceAddress, nsIDOMBlob* aBlob);
|
||||
bool StopSendingFile();
|
||||
bool ConfirmReceivingFile(bool aConfirm);
|
||||
|
||||
|
@ -95,7 +96,7 @@ private:
|
|||
void NotifyAboutFileChange();
|
||||
bool AcquireSdcardMountLock();
|
||||
void SendObexData(uint8_t* aData, uint8_t aOpcode, int aSize);
|
||||
void AppendBlobToSend(const nsAString& aDeviceAddress, BlobParent* aActor);
|
||||
void AppendBlobToSend(const nsAString& aDeviceAddress, nsIDOMBlob* aBlob);
|
||||
void DiscardBlobsToSend();
|
||||
bool ProcessNextBatch();
|
||||
void ConnectInternal(const nsAString& aDeviceAddress);
|
||||
|
|
|
@ -1237,6 +1237,26 @@ BluetoothServiceBluedroid::SendFile(const nsAString& aDeviceAddress,
|
|||
DispatchBluetoothReply(aRunnable, BluetoothValue(true), errorStr);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothServiceBluedroid::SendFile(const nsAString& aDeviceAddress,
|
||||
nsIDOMBlob* aBlob,
|
||||
BluetoothReplyRunnable* aRunnable)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
// Currently we only support one device sending one file at a time,
|
||||
// so we don't need aDeviceAddress here because the target device
|
||||
// has been determined when calling 'Connect()'. Nevertheless, keep
|
||||
// it for future use.
|
||||
BluetoothOppManager* opp = BluetoothOppManager::Get();
|
||||
nsAutoString errorStr;
|
||||
if (!opp || !opp->SendFile(aDeviceAddress, aBlob)) {
|
||||
errorStr.AssignLiteral("Calling SendFile() failed");
|
||||
}
|
||||
|
||||
DispatchBluetoothReply(aRunnable, BluetoothValue(true), errorStr);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothServiceBluedroid::StopSendingFile(const nsAString& aDeviceAddress,
|
||||
BluetoothReplyRunnable* aRunnable)
|
||||
|
|
|
@ -100,6 +100,11 @@ public:
|
|||
BlobChild* aBlobChild,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual void
|
||||
SendFile(const nsAString& aDeviceAddress,
|
||||
nsIDOMBlob* aBlob,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual void
|
||||
StopSendingFile(const nsAString& aDeviceAddress,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
|
|
@ -59,11 +59,10 @@ static bool sInShutdown = false;
|
|||
|
||||
class mozilla::dom::bluetooth::SendFileBatch {
|
||||
public:
|
||||
SendFileBatch(const nsAString& aDeviceAddress, BlobParent* aActor)
|
||||
SendFileBatch(const nsAString& aDeviceAddress, nsIDOMBlob* aBlob)
|
||||
: mDeviceAddress(aDeviceAddress)
|
||||
{
|
||||
nsCOMPtr<nsIDOMBlob> blob = aActor->GetBlob();
|
||||
mBlobs.AppendElement(blob);
|
||||
mBlobs.AppendElement(aBlob);
|
||||
}
|
||||
|
||||
nsString mDeviceAddress;
|
||||
|
@ -365,7 +364,18 @@ BluetoothOppManager::SendFile(const nsAString& aDeviceAddress,
|
|||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
AppendBlobToSend(aDeviceAddress, aActor);
|
||||
nsCOMPtr<nsIDOMBlob> blob = aActor->GetBlob();
|
||||
|
||||
return SendFile(aDeviceAddress, blob.get());
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothOppManager::SendFile(const nsAString& aDeviceAddress,
|
||||
nsIDOMBlob* aBlob)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
AppendBlobToSend(aDeviceAddress, aBlob);
|
||||
if (!mSocket) {
|
||||
ProcessNextBatch();
|
||||
}
|
||||
|
@ -375,7 +385,7 @@ BluetoothOppManager::SendFile(const nsAString& aDeviceAddress,
|
|||
|
||||
void
|
||||
BluetoothOppManager::AppendBlobToSend(const nsAString& aDeviceAddress,
|
||||
BlobParent* aActor)
|
||||
nsIDOMBlob* aBlob)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
|
@ -388,11 +398,10 @@ BluetoothOppManager::AppendBlobToSend(const nsAString& aDeviceAddress,
|
|||
*/
|
||||
if (mBatches.IsEmpty() ||
|
||||
aDeviceAddress != mBatches[indexTail].mDeviceAddress) {
|
||||
SendFileBatch batch(aDeviceAddress, aActor);
|
||||
SendFileBatch batch(aDeviceAddress, aBlob);
|
||||
mBatches.AppendElement(batch);
|
||||
} else {
|
||||
nsCOMPtr<nsIDOMBlob> blob = aActor->GetBlob();
|
||||
mBatches[indexTail].mBlobs.AppendElement(blob);
|
||||
mBatches[indexTail].mBlobs.AppendElement(aBlob);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ public:
|
|||
bool Listen();
|
||||
|
||||
bool SendFile(const nsAString& aDeviceAddress, BlobParent* aActor);
|
||||
bool SendFile(const nsAString& aDeviceAddress, nsIDOMBlob* aBlob);
|
||||
bool StopSendingFile();
|
||||
bool ConfirmReceivingFile(bool aConfirm);
|
||||
|
||||
|
@ -95,7 +96,7 @@ private:
|
|||
void NotifyAboutFileChange();
|
||||
bool AcquireSdcardMountLock();
|
||||
void SendObexData(uint8_t* aData, uint8_t aOpcode, int aSize);
|
||||
void AppendBlobToSend(const nsAString& aDeviceAddress, BlobParent* aActor);
|
||||
void AppendBlobToSend(const nsAString& aDeviceAddress, nsIDOMBlob* aBlob);
|
||||
void DiscardBlobsToSend();
|
||||
bool ProcessNextBatch();
|
||||
void ConnectInternal(const nsAString& aDeviceAddress);
|
||||
|
|
|
@ -3419,6 +3419,26 @@ BluetoothDBusService::SendFile(const nsAString& aDeviceAddress,
|
|||
DispatchBluetoothReply(aRunnable, BluetoothValue(true), errorStr);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDBusService::SendFile(const nsAString& aDeviceAddress,
|
||||
nsIDOMBlob* aBlob,
|
||||
BluetoothReplyRunnable* aRunnable)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
// Currently we only support one device sending one file at a time,
|
||||
// so we don't need aDeviceAddress here because the target device
|
||||
// has been determined when calling 'Connect()'. Nevertheless, keep
|
||||
// it for future use.
|
||||
BluetoothOppManager* opp = BluetoothOppManager::Get();
|
||||
nsAutoString errorStr;
|
||||
if (!opp || !opp->SendFile(aDeviceAddress, aBlob)) {
|
||||
errorStr.AssignLiteral("Calling SendFile() failed");
|
||||
}
|
||||
|
||||
DispatchBluetoothReply(aRunnable, BluetoothValue(true), errorStr);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDBusService::StopSendingFile(const nsAString& aDeviceAddress,
|
||||
BluetoothReplyRunnable* aRunnable)
|
||||
|
|
|
@ -120,6 +120,11 @@ public:
|
|||
BlobChild* aBlobChild,
|
||||
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
|
||||
|
||||
virtual void
|
||||
SendFile(const nsAString& aDeviceAddress,
|
||||
nsIDOMBlob* aBlob,
|
||||
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
|
||||
|
||||
virtual void
|
||||
StopSendingFile(const nsAString& aDeviceAddress,
|
||||
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
|
||||
|
|
|
@ -256,6 +256,16 @@ BluetoothServiceChildProcess::SendFile(
|
|||
SendFileRequest(nsString(aDeviceAddress), nullptr, aBlobChild));
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothServiceChildProcess::SendFile(
|
||||
const nsAString& aDeviceAddress,
|
||||
nsIDOMBlob* aBlobChild,
|
||||
BluetoothReplyRunnable* aRunnable)
|
||||
{
|
||||
// Parent-process-only method
|
||||
MOZ_CRASH("This should never be called!");
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothServiceChildProcess::StopSendingFile(
|
||||
const nsAString& aDeviceAddress,
|
||||
|
|
|
@ -120,6 +120,11 @@ public:
|
|||
BlobChild* aBlobChild,
|
||||
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
|
||||
|
||||
virtual void
|
||||
SendFile(const nsAString& aDeviceAddress,
|
||||
nsIDOMBlob* aBlob,
|
||||
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
|
||||
|
||||
virtual void
|
||||
StopSendingFile(const nsAString& aDeviceAddress,
|
||||
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
|
||||
|
|
Загрузка…
Ссылка в новой задаче