Backed out changeset dc164758f576 (bug 1220121)
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Thu, 12 Nov 2015 11:48:57 +0100
changeset 272203 b43033569b6d2f492f02d148e33cd1a6b3e8c92d
parent 272202 5c56d35d83f1303cbcbe96a90fe43d8641f5682c
child 272204 3297bbb798c4fd6ae35ef04bdf5f7947b5a66064
push id18635
push usercbook@mozilla.com
push dateThu, 12 Nov 2015 10:49:25 +0000
treeherderb2g-inbound@7a433bf9bb08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1220121
milestone45.0a1
backs outdc164758f57664bd548e6b25eefb6084ea7b427b
Backed out changeset dc164758f576 (bug 1220121)
dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
dom/bluetooth/bluedroid/BluetoothServiceBluedroid.h
dom/bluetooth/bluez/BluetoothDBusService.cpp
dom/bluetooth/bluez/BluetoothDBusService.h
dom/bluetooth/common/BluetoothCommon.h
dom/bluetooth/common/BluetoothService.h
dom/bluetooth/common/BluetoothUtils.cpp
dom/bluetooth/common/BluetoothUtils.h
dom/bluetooth/common/webapi/BluetoothPairingHandle.cpp
dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp
dom/bluetooth/ipc/BluetoothServiceChildProcess.h
dom/bluetooth/ipc/PBluetooth.ipdl
--- a/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
@@ -1394,29 +1394,36 @@ public:
 
 private:
   BluetoothReplyRunnable* mRunnable;
 };
 
 void
 BluetoothServiceBluedroid::PinReplyInternal(
   const BluetoothAddress& aDeviceAddress, bool aAccept,
-  const BluetoothPinCode& aPinCode, BluetoothReplyRunnable* aRunnable)
+  const nsAString& aPinCode, BluetoothReplyRunnable* aRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   ENSURE_BLUETOOTH_IS_READY_VOID(aRunnable);
 
-  sBtInterface->PinReply(aDeviceAddress, aAccept, aPinCode,
+  BluetoothPinCode pinCode;
+  auto rv = StringToPinCode(aPinCode, pinCode);
+  if (NS_FAILED(rv)) {
+    DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
+    return;
+  }
+
+  sBtInterface->PinReply(aDeviceAddress, aAccept, pinCode,
                          new PinReplyResultHandler(aRunnable));
 }
 
 void
 BluetoothServiceBluedroid::SetPinCodeInternal(
-  const BluetoothAddress& aDeviceAddress, const BluetoothPinCode& aPinCode,
+  const BluetoothAddress& aDeviceAddress, const nsAString& aPinCode,
   BluetoothReplyRunnable* aRunnable)
 {
   // Legacy method used by BlueZ only.
 }
 
 void
 BluetoothServiceBluedroid::SetPasskeyInternal(
   const BluetoothAddress& aDeviceAddress, uint32_t aPasskey,
--- a/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.h
+++ b/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.h
@@ -82,27 +82,27 @@ public:
 
   virtual nsresult
   RemoveDeviceInternal(const BluetoothAddress& aDeviceAddress,
                        BluetoothReplyRunnable* aRunnable);
 
   virtual void
   PinReplyInternal(const BluetoothAddress& aDeviceAddress,
                    bool aAccept,
-                   const BluetoothPinCode& aPinCode,
+                   const nsAString& aPinCode,
                    BluetoothReplyRunnable* aRunnable);
 
   virtual void
   SspReplyInternal(const BluetoothAddress& aDeviceAddress,
                    BluetoothSspVariant aVariant,
                    bool aAccept,
                    BluetoothReplyRunnable* aRunnable);
   virtual void
   SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
-                     const BluetoothPinCode& aPinCode,
+                     const nsAString& aPinCode,
                      BluetoothReplyRunnable* aRunnable);
 
   virtual void
   SetPasskeyInternal(const BluetoothAddress& aDeviceAddress,
                      uint32_t aPasskey,
                      BluetoothReplyRunnable* aRunnable);
 
   virtual void
--- a/dom/bluetooth/bluez/BluetoothDBusService.cpp
+++ b/dom/bluetooth/bluez/BluetoothDBusService.cpp
@@ -3242,17 +3242,17 @@ BluetoothDBusService::RemoveDeviceIntern
 
   return NS_OK;
 }
 
 class SetPinCodeTask : public Task
 {
 public:
   SetPinCodeTask(const BluetoothAddress& aDeviceAddress,
-                 const BluetoothPinCode& aPinCode,
+                 const nsACString& aPinCode,
                  BluetoothReplyRunnable* aRunnable)
     : mDeviceAddress(aDeviceAddress)
     , mPinCode(aPinCode)
     , mRunnable(aRunnable)
   {
     MOZ_ASSERT(!mDeviceAddress.IsCleared());
     MOZ_ASSERT(mRunnable);
   }
@@ -3276,29 +3276,17 @@ public:
     if (!reply) {
       BT_WARNING("%s: Memory can't be allocated for the message.", __FUNCTION__);
       dbus_message_unref(msg);
       errorStr.AssignLiteral("Memory can't be allocated for the message.");
       DispatchBluetoothReply(mRunnable, v, errorStr);
       return;
     }
 
-    nsAutoString pinCodeStr;
-    if (NS_FAILED(PinCodeToString(mPinCode, pinCodeStr))) {
-      BT_WARNING("%s: Cannot convert pin code to string.", __FUNCTION__);
-      dbus_message_unref(msg);
-      dbus_message_unref(reply);
-      errorStr.AssignLiteral("Cannot convert pin code to string.");
-      DispatchBluetoothReply(mRunnable, v, errorStr);
-      return;
-    }
-
-    auto utf8PinCodeStr = NS_ConvertUTF16toUTF8(pinCodeStr);
-
-    const char* pinCode = utf8PinCodeStr.get();
+    const char* pinCode = mPinCode.get();
 
     if (!dbus_message_append_args(reply,
                                   DBUS_TYPE_STRING, &pinCode,
                                   DBUS_TYPE_INVALID)) {
       BT_WARNING("%s: Couldn't append arguments to dbus message.", __FUNCTION__);
       errorStr.AssignLiteral("Couldn't append arguments to dbus message.");
     } else {
       MOZ_ASSERT(sDBusConnection);
@@ -3309,42 +3297,44 @@ public:
     dbus_message_unref(reply);
 
     sPairingReqTable->Remove(mDeviceAddress);
     DispatchBluetoothReply(mRunnable, v, errorStr);
   }
 
 private:
   const BluetoothAddress mDeviceAddress;
-  const BluetoothPinCode mPinCode;
+  const nsCString mPinCode;
   RefPtr<BluetoothReplyRunnable> mRunnable;
 };
 
 void
 BluetoothDBusService::PinReplyInternal(
   const BluetoothAddress& aDeviceAddress, bool aAccept,
-  const BluetoothPinCode& aPinCode, BluetoothReplyRunnable* aRunnable)
+  const nsAString& aPinCode, BluetoothReplyRunnable* aRunnable)
 {
   // Legacy interface used by Bluedroid only.
 }
 
 void
 BluetoothDBusService::SspReplyInternal(
   const BluetoothAddress& aDeviceAddress, BluetoothSspVariant aVariant,
   bool aAccept, BluetoothReplyRunnable* aRunnable)
 {
   // Legacy interface used by Bluedroid only.
 }
 
 void
 BluetoothDBusService::SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
-                                         const BluetoothPinCode& aPinCode,
+                                         const nsAString& aPinCode,
                                          BluetoothReplyRunnable* aRunnable)
 {
-  Task* task = new SetPinCodeTask(aDeviceAddress, aPinCode, aRunnable);
+  Task* task = new SetPinCodeTask(aDeviceAddress,
+                                  NS_ConvertUTF16toUTF8(aPinCode),
+                                  aRunnable);
   DispatchToDBusThread(task);
 }
 
 class SetPasskeyTask : public Task
 {
 public:
   SetPasskeyTask(const BluetoothAddress& aDeviceAddress,
                  uint32_t aPasskey,
--- a/dom/bluetooth/bluez/BluetoothDBusService.h
+++ b/dom/bluetooth/bluez/BluetoothDBusService.h
@@ -94,28 +94,28 @@ public:
 
   virtual nsresult
   RemoveDeviceInternal(const BluetoothAddress& aDeviceAddress,
                        BluetoothReplyRunnable* aRunnable) override;
 
   virtual void
   PinReplyInternal(const BluetoothAddress& aDeviceAddress,
                    bool aAccept,
-                   const BluetoothPinCode& aPinCode,
+                   const nsAString& aPinCode,
                    BluetoothReplyRunnable* aRunnable);
 
   virtual void
   SspReplyInternal(const BluetoothAddress& aDeviceAddress,
                    BluetoothSspVariant aVariant,
                    bool aAccept,
                    BluetoothReplyRunnable* aRunnable);
 
   virtual void
   SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
-                     const BluetoothPinCode& aPinCode,
+                     const nsAString& aPinCode,
                      BluetoothReplyRunnable* aRunnable) override;
 
   virtual void
   SetPasskeyInternal(const BluetoothAddress& aDeviceAddress, uint32_t aPasskey,
                      BluetoothReplyRunnable* aRunnable) override;
 
   virtual void
   SetPairingConfirmationInternal(const BluetoothAddress& aDeviceAddress,
--- a/dom/bluetooth/common/BluetoothCommon.h
+++ b/dom/bluetooth/common/BluetoothCommon.h
@@ -669,34 +669,16 @@ struct BluetoothUuid {
   {
     return BigEndian::readUint16(&mUuid[2]);
   }
 };
 
 struct BluetoothPinCode {
   uint8_t mPinCode[16]; /* not \0-terminated */
   uint8_t mLength;
-
-  BluetoothPinCode()
-    : mLength(0)
-  {
-    std::fill(mPinCode, mPinCode + MOZ_ARRAY_LENGTH(mPinCode), 0);
-  }
-
-  bool operator==(const BluetoothPinCode& aRhs) const
-  {
-    MOZ_ASSERT(mLength <= MOZ_ARRAY_LENGTH(mPinCode));
-    return (mLength == aRhs.mLength) &&
-            std::equal(aRhs.mPinCode, aRhs.mPinCode + aRhs.mLength, mPinCode);
-  }
-
-  bool operator!=(const BluetoothPinCode& aRhs) const
-  {
-    return !operator==(aRhs);
-  }
 };
 
 struct BluetoothServiceName {
   uint8_t mName[255]; /* not \0-terminated */
 };
 
 struct BluetoothServiceRecord {
   BluetoothUuid mUuid;
--- a/dom/bluetooth/common/BluetoothService.h
+++ b/dom/bluetooth/common/BluetoothService.h
@@ -239,31 +239,31 @@ public:
 
   virtual bool
   UpdateSdpRecords(const BluetoothAddress& aDeviceAddress,
                    BluetoothProfileManagerBase* aManager) = 0;
 
   virtual void
   PinReplyInternal(const BluetoothAddress& aDeviceAddress,
                    bool aAccept,
-                   const BluetoothPinCode& aPinCode,
+                   const nsAString& aPinCode,
                    BluetoothReplyRunnable* aRunnable) = 0;
 
   virtual void
   SspReplyInternal(const BluetoothAddress& aDeviceAddress,
                    BluetoothSspVariant aVariant,
                    bool aAccept,
                    BluetoothReplyRunnable* aRunnable) = 0;
 
   /**
    * Legacy method used by bluez only to reply pincode request.
    */
   virtual void
   SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
-                     const BluetoothPinCode& aPinCode,
+                     const nsAString& aPinCode,
                      BluetoothReplyRunnable* aRunnable) = 0;
 
   /**
    * Legacy method used by bluez only to reply passkey entry request.
    */
   virtual void
   SetPasskeyInternal(const BluetoothAddress& aDeviceAddress, uint32_t aPasskey,
                      BluetoothReplyRunnable* aRunnable) = 0;
--- a/dom/bluetooth/common/BluetoothUtils.cpp
+++ b/dom/bluetooth/common/BluetoothUtils.cpp
@@ -57,39 +57,24 @@ StringToAddress(const nsAString& aString
                    &aAddress.mAddr[5]);
   if (res < static_cast<ssize_t>(MOZ_ARRAY_LENGTH(aAddress.mAddr))) {
     return NS_ERROR_ILLEGAL_VALUE;
   }
   return NS_OK;
 }
 
 nsresult
-PinCodeToString(const BluetoothPinCode& aPinCode, nsAString& aString)
-{
-  if (aPinCode.mLength > sizeof(aPinCode.mPinCode)) {
-    BT_LOGR("Pin-code string too long");
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-
-  aString = NS_ConvertUTF8toUTF16(
-    nsCString(reinterpret_cast<const char*>(aPinCode.mPinCode),
-              aPinCode.mLength));
-
-  return NS_OK;
-}
-
-nsresult
 StringToPinCode(const nsAString& aString, BluetoothPinCode& aPinCode)
 {
   NS_ConvertUTF16toUTF8 stringUTF8(aString);
 
   auto len = stringUTF8.Length();
 
   if (len > sizeof(aPinCode.mPinCode)) {
-    BT_LOGR("Pin-code string too long");
+    BT_LOGR("Service-name string too long");
     return NS_ERROR_ILLEGAL_VALUE;
   }
 
   auto str = stringUTF8.get();
 
   memcpy(aPinCode.mPinCode, str, len);
   memset(aPinCode.mPinCode + len, 0, sizeof(aPinCode.mPinCode) - len);
   aPinCode.mLength = len;
--- a/dom/bluetooth/common/BluetoothUtils.h
+++ b/dom/bluetooth/common/BluetoothUtils.h
@@ -33,19 +33,16 @@ AddressToString(const BluetoothAddress& 
 nsresult
 StringToAddress(const nsAString& aString, BluetoothAddress& aAddress);
 
 //
 // Pin code/string conversion
 //
 
 nsresult
-PinCodeToString(const BluetoothPinCode& aPinCode, nsAString& aString);
-
-nsresult
 StringToPinCode(const nsAString& aString, BluetoothPinCode& aPinCode);
 
 //
 // Property type/string conversion
 //
 
 nsresult
 StringToPropertyType(const nsAString& aString, BluetoothPropertyType& aType);
--- a/dom/bluetooth/common/webapi/BluetoothPairingHandle.cpp
+++ b/dom/bluetooth/common/webapi/BluetoothPairingHandle.cpp
@@ -81,25 +81,20 @@ BluetoothPairingHandle::SetPinCode(const
                         NS_ERROR_DOM_INVALID_STATE_ERR);
 
   BluetoothAddress deviceAddress;
   BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToAddress(mDeviceAddress,
                                                      deviceAddress)),
                         promise,
                         NS_ERROR_DOM_INVALID_STATE_ERR);
 
-  BluetoothPinCode pinCode;
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToPinCode(aPinCode, pinCode)),
-                        promise,
-                        NS_ERROR_DOM_INVALID_STATE_ERR);
-
   BluetoothService* bs = BluetoothService::Get();
   BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
 
-  bs->PinReplyInternal(deviceAddress, true /* accept */, pinCode,
+  bs->PinReplyInternal(deviceAddress, true /* accept */, aPinCode,
                        new BluetoothVoidReplyRunnable(nullptr, promise));
 
   return promise.forget();
 }
 
 already_AddRefed<Promise>
 BluetoothPairingHandle::Accept(ErrorResult& aRv)
 {
@@ -154,18 +149,17 @@ BluetoothPairingHandle::Reject(ErrorResu
                                                      deviceAddress)),
                         promise,
                         NS_ERROR_DOM_INVALID_STATE_ERR);
 
   BluetoothService* bs = BluetoothService::Get();
   BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
 
   if (mType.EqualsLiteral(PAIRING_REQ_TYPE_ENTERPINCODE)) { // Pin request
-    bs->PinReplyInternal(deviceAddress, false /* aAccept */,
-                         BluetoothPinCode(),
+    bs->PinReplyInternal(deviceAddress, false /* aAccept */, EmptyString(),
                          new BluetoothVoidReplyRunnable(nullptr, promise));
   } else { // Ssp request
     BluetoothSspVariant variant;
     BT_ENSURE_TRUE_REJECT(GetSspVariant(variant),
                           promise,
                           NS_ERROR_DOM_OPERATION_ERR);
 
     bs->SspReplyInternal(deviceAddress, variant, false /* aAccept */,
--- a/dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp
+++ b/dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp
@@ -216,37 +216,41 @@ BluetoothServiceChildProcess::UpdateSdpR
                                                BluetoothProfileManagerBase* aManager)
 {
   MOZ_CRASH("This should never be called!");
 }
 
 void
 BluetoothServiceChildProcess::PinReplyInternal(
   const BluetoothAddress& aDeviceAddress, bool aAccept,
-  const BluetoothPinCode& aPinCode, BluetoothReplyRunnable* aRunnable)
+  const nsAString& aPinCode, BluetoothReplyRunnable* aRunnable)
 {
-  SendRequest(aRunnable, PinReplyRequest(aDeviceAddress, aAccept, aPinCode));
+  SendRequest(aRunnable,
+              PinReplyRequest(aDeviceAddress,
+                              aAccept,
+                              nsString(aPinCode)));
 }
 
 void
 BluetoothServiceChildProcess::SspReplyInternal(
   const BluetoothAddress& aDeviceAddress,
   BluetoothSspVariant aVariant, bool aAccept,
   BluetoothReplyRunnable* aRunnable)
 {
   SendRequest(aRunnable, SspReplyRequest(aDeviceAddress, aVariant, aAccept));
 }
 
 void
 BluetoothServiceChildProcess::SetPinCodeInternal(
   const BluetoothAddress& aDeviceAddress,
-  const BluetoothPinCode& aPinCode,
+  const nsAString& aPinCode,
   BluetoothReplyRunnable* aRunnable)
 {
-  SendRequest(aRunnable, SetPinCodeRequest(aDeviceAddress, aPinCode));
+  SendRequest(aRunnable,
+              SetPinCodeRequest(aDeviceAddress, nsString(aPinCode)));
 }
 
 void
 BluetoothServiceChildProcess::SetPasskeyInternal(
   const BluetoothAddress& aDeviceAddress,
   uint32_t aPasskey,
   BluetoothReplyRunnable* aRunnable)
 {
--- a/dom/bluetooth/ipc/BluetoothServiceChildProcess.h
+++ b/dom/bluetooth/ipc/BluetoothServiceChildProcess.h
@@ -87,34 +87,34 @@ public:
                     BluetoothProfileManagerBase* aManager) override;
 
   virtual bool
   UpdateSdpRecords(const BluetoothAddress& aDeviceAddress,
                    BluetoothProfileManagerBase* aManager) override;
 
   virtual void
   SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
-                     const BluetoothPinCode& aPinCode,
+                     const nsAString& aPinCode,
                      BluetoothReplyRunnable* aRunnable) override;
 
   virtual void
   SetPasskeyInternal(const BluetoothAddress& aDeviceAddress,
                      uint32_t aPasskey,
                      BluetoothReplyRunnable* aRunnable) override;
 
   virtual void
   SetPairingConfirmationInternal(const BluetoothAddress& aDeviceAddress,
                                  bool aConfirm,
                                  BluetoothReplyRunnable* aRunnable)
                                  override;
 
   virtual void
   PinReplyInternal(const BluetoothAddress& aDeviceAddress,
                    bool aAccept,
-                   const BluetoothPinCode& aPinCode,
+                   const nsAString& aPinCode,
                    BluetoothReplyRunnable* aRunnable) override;
 
   virtual void
   SspReplyInternal(const BluetoothAddress& aDeviceAddress,
                    BluetoothSspVariant aVariant,
                    bool aAccept,
                    BluetoothReplyRunnable* aRunnable) override;
 
--- a/dom/bluetooth/ipc/PBluetooth.ipdl
+++ b/dom/bluetooth/ipc/PBluetooth.ipdl
@@ -11,18 +11,16 @@ include protocol PContent;
 include BluetoothTypes;
 
 include "mozilla/dom/bluetooth/ipc/BluetoothMessageUtils.h";
 
 using mozilla::dom::bluetooth::BluetoothAddress
   from "mozilla/dom/bluetooth/BluetoothCommon.h";
 using mozilla::dom::bluetooth::BluetoothObjectType
   from "mozilla/dom/bluetooth/BluetoothCommon.h";
-using mozilla::dom::bluetooth::BluetoothPinCode
-  from "mozilla/dom/bluetooth/BluetoothCommon.h";
 
 namespace mozilla {
 namespace dom {
 namespace bluetooth {
 
 /**
  * Bluetooth request types.
  */
@@ -78,30 +76,30 @@ struct UnpairRequest
 {
   BluetoothAddress address;
 };
 
 struct PinReplyRequest
 {
   BluetoothAddress address;
   bool accept;
-  BluetoothPinCode pinCode;
+  nsString pinCode;
 };
 
 struct SspReplyRequest
 {
   BluetoothAddress address;
   BluetoothSspVariant variant;
   bool accept;
 };
 
 struct SetPinCodeRequest
 {
   BluetoothAddress address;
-  BluetoothPinCode pincode;
+  nsString pincode;
 };
 
 struct SetPasskeyRequest
 {
   BluetoothAddress address;
   uint32_t passkey;
 };