Bug 791147: Patch 2 - Hook up bluetooth pairing replies to oop; r=bent
authorKyle Machulis <kyle@nonpolynomial.com>
Wed, 19 Sep 2012 16:37:49 -0700
changeset 107669 1d50132603340f7c72929079034ca60a852839b6
parent 107668 3f09f3b9188952cd1a035cd735b151ba2b7f2b2a
child 107670 447705d3945665cbf6b0bee4491e404b5ac287b9
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersbent
bugs791147
milestone18.0a1
Bug 791147: Patch 2 - Hook up bluetooth pairing replies to oop; r=bent
dom/bluetooth/ipc/BluetoothChild.cpp
dom/bluetooth/ipc/BluetoothChild.h
dom/bluetooth/ipc/BluetoothMessageUtils.h
dom/bluetooth/ipc/BluetoothParent.cpp
dom/bluetooth/ipc/BluetoothParent.h
dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp
dom/bluetooth/ipc/BluetoothServiceChildProcess.h
dom/bluetooth/ipc/PBluetooth.ipdl
--- a/dom/bluetooth/ipc/BluetoothChild.cpp
+++ b/dom/bluetooth/ipc/BluetoothChild.cpp
@@ -1,8 +1,10 @@
+/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "base/basictypes.h"
 
 #include "BluetoothChild.h"
 
--- a/dom/bluetooth/ipc/BluetoothChild.h
+++ b/dom/bluetooth/ipc/BluetoothChild.h
@@ -1,8 +1,10 @@
+/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_bluetooth_ipc_bluetoothchild_h__
 #define mozilla_dom_bluetooth_ipc_bluetoothchild_h__
 
 #include "mozilla/dom/bluetooth/BluetoothCommon.h"
--- a/dom/bluetooth/ipc/BluetoothMessageUtils.h
+++ b/dom/bluetooth/ipc/BluetoothMessageUtils.h
@@ -1,8 +1,10 @@
+/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_bluetooth_ipc_bluetoothmessageutils_h__
 #define mozilla_dom_bluetooth_ipc_bluetoothmessageutils_h__
 
 #include "mozilla/dom/bluetooth/BluetoothCommon.h"
--- a/dom/bluetooth/ipc/BluetoothParent.cpp
+++ b/dom/bluetooth/ipc/BluetoothParent.cpp
@@ -1,8 +1,10 @@
+/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "base/basictypes.h"
 
 #include "BluetoothParent.h"
 
@@ -178,36 +180,47 @@ BluetoothParent::RecvPBluetoothRequestCo
 {
   BluetoothRequestParent* actor = static_cast<BluetoothRequestParent*>(aActor);
 
 #ifdef DEBUG
   actor->mRequestType = aRequest.type();
 #endif
 
   switch (aRequest.type()) {
-     case Request::TDefaultAdapterPathRequest:
-       return actor->DoRequest(aRequest.get_DefaultAdapterPathRequest());
-     case Request::TSetPropertyRequest:
-       return actor->DoRequest(aRequest.get_SetPropertyRequest());
-     case Request::TGetPropertyRequest:
-       return actor->DoRequest(aRequest.get_GetPropertyRequest());
-     case Request::TStartDiscoveryRequest:
-       return actor->DoRequest(aRequest.get_StartDiscoveryRequest());
-     case Request::TStopDiscoveryRequest:
-       return actor->DoRequest(aRequest.get_StopDiscoveryRequest());
-     case Request::TPairRequest:
-       return actor->DoRequest(aRequest.get_PairRequest());
-     case Request::TUnpairRequest:
-       return actor->DoRequest(aRequest.get_UnpairRequest());
-     case Request::TDevicePropertiesRequest:
-       return actor->DoRequest(aRequest.get_DevicePropertiesRequest());
-
-     default:
-       MOZ_NOT_REACHED("Unknown type!");
-       return false;
+    case Request::TDefaultAdapterPathRequest:
+      return actor->DoRequest(aRequest.get_DefaultAdapterPathRequest());
+    case Request::TSetPropertyRequest:
+      return actor->DoRequest(aRequest.get_SetPropertyRequest());
+    case Request::TGetPropertyRequest:
+      return actor->DoRequest(aRequest.get_GetPropertyRequest());
+    case Request::TStartDiscoveryRequest:
+      return actor->DoRequest(aRequest.get_StartDiscoveryRequest());
+    case Request::TStopDiscoveryRequest:
+      return actor->DoRequest(aRequest.get_StopDiscoveryRequest());
+    case Request::TPairRequest:
+      return actor->DoRequest(aRequest.get_PairRequest());
+    case Request::TUnpairRequest:
+      return actor->DoRequest(aRequest.get_UnpairRequest());
+    case Request::TDevicePropertiesRequest:
+      return actor->DoRequest(aRequest.get_DevicePropertiesRequest());
+    case Request::TSetPinCodeRequest:
+      return actor->DoRequest(aRequest.get_SetPinCodeRequest());
+    case Request::TSetPasskeyRequest:
+      return actor->DoRequest(aRequest.get_SetPasskeyRequest());
+    case Request::TConfirmPairingConfirmationRequest:
+      return actor->DoRequest(aRequest.get_ConfirmPairingConfirmationRequest());
+    case Request::TConfirmAuthorizationRequest:
+      return actor->DoRequest(aRequest.get_ConfirmAuthorizationRequest());
+    case Request::TDenyPairingConfirmationRequest:
+      return actor->DoRequest(aRequest.get_DenyPairingConfirmationRequest());
+    case Request::TDenyAuthorizationRequest:
+      return actor->DoRequest(aRequest.get_DenyAuthorizationRequest());
+    default:
+      MOZ_NOT_REACHED("Unknown type!");
+      return false;
   }
 
   MOZ_NOT_REACHED("Should never get here!");
   return false;
 }
 
 PBluetoothRequestParent*
 BluetoothParent::AllocPBluetoothRequest(const Request& aRequest)
@@ -370,8 +383,106 @@ BluetoothRequestParent::DoRequest(const 
 
   nsresult rv =
     mService->GetPairedDevicePropertiesInternal(aRequest.addresses(),
                                                 mReplyRunnable.get());
   NS_ENSURE_SUCCESS(rv, false);
 
   return true;
 }
+
+bool
+BluetoothRequestParent::DoRequest(const SetPinCodeRequest& aRequest)
+{
+  MOZ_ASSERT(mService);
+  MOZ_ASSERT(mRequestType == Request::TSetPinCodeRequest);
+
+  nsresult rv =
+    mService->SetPinCodeInternal(aRequest.path(),
+                                 aRequest.pincode(),
+                                 mReplyRunnable.get());
+
+  NS_ENSURE_SUCCESS(rv, false);
+
+  return true;
+}
+
+bool
+BluetoothRequestParent::DoRequest(const SetPasskeyRequest& aRequest)
+{
+  MOZ_ASSERT(mService);
+  MOZ_ASSERT(mRequestType == Request::TSetPasskeyRequest);
+
+  nsresult rv =
+    mService->SetPasskeyInternal(aRequest.path(),
+                                 aRequest.passkey(),
+                                 mReplyRunnable.get());
+
+  NS_ENSURE_SUCCESS(rv, false);
+
+  return true;
+}
+
+bool
+BluetoothRequestParent::DoRequest(const ConfirmPairingConfirmationRequest&
+                                  aRequest)
+{
+  MOZ_ASSERT(mService);
+  MOZ_ASSERT(mRequestType == Request::TConfirmPairingConfirmationRequest);
+
+  nsresult rv =
+    mService->SetPairingConfirmationInternal(aRequest.path(),
+                                             true,
+                                             mReplyRunnable.get());
+
+  NS_ENSURE_SUCCESS(rv, false);
+
+  return true;
+}
+
+bool
+BluetoothRequestParent::DoRequest(const ConfirmAuthorizationRequest& aRequest)
+{
+  MOZ_ASSERT(mService);
+  MOZ_ASSERT(mRequestType == Request::TConfirmAuthorizationRequest);
+
+  nsresult rv =
+    mService->SetAuthorizationInternal(aRequest.path(),
+                                       true,
+                                       mReplyRunnable.get());
+
+  NS_ENSURE_SUCCESS(rv, false);
+
+  return true;
+}
+
+bool
+BluetoothRequestParent::DoRequest(const DenyPairingConfirmationRequest&
+                                  aRequest)
+{
+  MOZ_ASSERT(mService);
+  MOZ_ASSERT(mRequestType == Request::TDenyPairingConfirmationRequest);
+
+  nsresult rv =
+    mService->SetPairingConfirmationInternal(aRequest.path(),
+                                             false,
+                                             mReplyRunnable.get());
+
+  NS_ENSURE_SUCCESS(rv, false);
+
+  return true;
+}
+
+bool
+BluetoothRequestParent::DoRequest(const DenyAuthorizationRequest& aRequest)
+{
+  MOZ_ASSERT(mService);
+  MOZ_ASSERT(mRequestType == Request::TDenyAuthorizationRequest);
+
+  nsresult rv =
+    mService->SetAuthorizationInternal(aRequest.path(),
+                                       false,
+                                       mReplyRunnable.get());
+
+  NS_ENSURE_SUCCESS(rv, false);
+
+  return true;
+}
--- a/dom/bluetooth/ipc/BluetoothParent.h
+++ b/dom/bluetooth/ipc/BluetoothParent.h
@@ -1,8 +1,10 @@
+/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_bluetooth_ipc_bluetoothparent_h__
 #define mozilla_dom_bluetooth_ipc_bluetoothparent_h__
 
 #include "mozilla/dom/bluetooth/BluetoothCommon.h"
@@ -140,13 +142,31 @@ protected:
   bool
   DoRequest(const PairRequest& aRequest);
 
   bool
   DoRequest(const UnpairRequest& aRequest);
 
   bool
   DoRequest(const DevicePropertiesRequest& aRequest);
+
+  bool
+  DoRequest(const SetPinCodeRequest& aRequest);
+
+  bool
+  DoRequest(const SetPasskeyRequest& aRequest);
+
+  bool
+  DoRequest(const ConfirmPairingConfirmationRequest& aRequest);
+
+  bool
+  DoRequest(const DenyPairingConfirmationRequest& aRequest);
+
+  bool
+  DoRequest(const ConfirmAuthorizationRequest& aRequest);
+
+  bool
+  DoRequest(const DenyAuthorizationRequest& aRequest);
 };
 
 END_BLUETOOTH_NAMESPACE
 
 #endif // mozilla_dom_bluetooth_ipc_bluetoothparent_h__
--- a/dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp
+++ b/dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp
@@ -102,17 +102,17 @@ BluetoothServiceChildProcess::GetDefault
   return NS_OK;
 }
 
 nsresult
 BluetoothServiceChildProcess::GetDevicePropertiesInternal(
                                                    const nsAString& aDevicePath,
                                                    const nsAString& aSignalPath)
 {
-  MOZ_NOT_REACHED("Implement me!");
+  MOZ_NOT_REACHED("Should never be called from child");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 nsresult
 BluetoothServiceChildProcess::GetPairedDevicePropertiesInternal(
                                      const nsTArray<nsString>& aDeviceAddresses,
                                      BluetoothReplyRunnable* aRunnable)
 {
@@ -221,47 +221,65 @@ BluetoothServiceChildProcess::CloseSocke
 {
   MOZ_NOT_REACHED("Implement me!");
   return false;
 }
 
 bool
 BluetoothServiceChildProcess::SetPinCodeInternal(
                                                 const nsAString& aDeviceAddress,
-                                                const nsAString& aPinCode)
+                                                const nsAString& aPinCode,
+                                                BluetoothReplyRunnable* aRunnable)
 {
-  MOZ_NOT_REACHED("Implement me!");
-  return false;
+  SendRequest(aRunnable,
+              SetPinCodeRequest(nsString(aDeviceAddress), nsString(aPinCode)));
+  return NS_OK;
 }
 
 bool
 BluetoothServiceChildProcess::SetPasskeyInternal(
                                                 const nsAString& aDeviceAddress,
-                                                uint32_t aPasskey)
+                                                uint32_t aPasskey,
+                                                BluetoothReplyRunnable* aRunnable)
 {
-  MOZ_NOT_REACHED("Implement me!");
-  return false;
+  SendRequest(aRunnable,
+              SetPasskeyRequest(nsString(aDeviceAddress), aPasskey));
+  return NS_OK;
 }
 
 bool
 BluetoothServiceChildProcess::SetPairingConfirmationInternal(
                                                 const nsAString& aDeviceAddress,
-                                                bool aConfirm)
+                                                bool aConfirm,
+                                                BluetoothReplyRunnable* aRunnable)
 {
-  MOZ_NOT_REACHED("Implement me!");
-  return false;
+  if(aConfirm) {
+    SendRequest(aRunnable,
+                ConfirmPairingConfirmationRequest(nsString(aDeviceAddress)));
+  } else {
+    SendRequest(aRunnable,
+                DenyPairingConfirmationRequest(nsString(aDeviceAddress)));
+  }
+  return NS_OK;
 }
 
 bool
 BluetoothServiceChildProcess::SetAuthorizationInternal(
                                                 const nsAString& aDeviceAddress,
-                                                bool aAllow)
+                                                bool aAllow,
+                                                BluetoothReplyRunnable* aRunnable)
 {
-  MOZ_NOT_REACHED("Implement me!");
-  return false;
+  if(aAllow) {
+    SendRequest(aRunnable,
+                ConfirmAuthorizationRequest(nsString(aDeviceAddress)));
+  } else {
+    SendRequest(aRunnable,
+                DenyAuthorizationRequest(nsString(aDeviceAddress)));
+  }
+  return NS_OK;
 }
 
 nsresult
 BluetoothServiceChildProcess::HandleStartup()
 {
   // Don't need to do anything here for startup since our Create function takes
   // care of the actor machinery.
   return NS_OK;
--- a/dom/bluetooth/ipc/BluetoothServiceChildProcess.h
+++ b/dom/bluetooth/ipc/BluetoothServiceChildProcess.h
@@ -57,20 +57,16 @@ public:
                          BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
 
   virtual nsresult
   GetProperties(BluetoothObjectType aType,
                 const nsAString& aPath,
                 BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
 
   virtual nsresult
-  GetDevicePropertiesInternal(const nsAString& aDevicePath,
-                              const nsAString& aSignalPath) MOZ_OVERRIDE;
-
-  virtual nsresult
   SetProperty(BluetoothObjectType aType,
               const nsAString& aPath,
               const BluetoothNamedValue& aValue,
               BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
 
   virtual bool
   GetDevicePath(const nsAString& aAdapterPath,
                 const nsAString& aDeviceAddress,
@@ -95,29 +91,34 @@ public:
                       bool aEncrypt,
                       BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
 
   virtual bool
   CloseSocket(int aFd, BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
 
   virtual bool
   SetPinCodeInternal(const nsAString& aDeviceAddress,
-                     const nsAString& aPinCode) MOZ_OVERRIDE;
+                     const nsAString& aPinCode,
+                     BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
 
   virtual bool
   SetPasskeyInternal(const nsAString& aDeviceAddress,
-                     uint32_t aPasskey) MOZ_OVERRIDE;
+                     uint32_t aPasskey,
+                     BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
 
   virtual bool
   SetPairingConfirmationInternal(const nsAString& aDeviceAddress,
-                                 bool aConfirm) MOZ_OVERRIDE;
+                                 bool aConfirm,
+                                 BluetoothReplyRunnable* aRunnable)
+    MOZ_OVERRIDE;
 
   virtual bool
   SetAuthorizationInternal(const nsAString& aDeviceAddress,
-                           bool aAllow) MOZ_OVERRIDE;
+                           bool aAllow,
+                           BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
 
 protected:
   BluetoothServiceChildProcess();
   virtual ~BluetoothServiceChildProcess();
 
   void
   NoteDeadActor();
 
@@ -133,13 +134,20 @@ protected:
 private:
   // This method should never be called.
   virtual nsresult
   StartInternal() MOZ_OVERRIDE;
 
   // This method should never be called.
   virtual nsresult
   StopInternal() MOZ_OVERRIDE;
+
+  // Should never be called from the child
+  virtual nsresult
+  GetDevicePropertiesInternal(const nsAString& aDevicePath,
+                              const nsAString& aSignalPath) MOZ_OVERRIDE;
+
+
 };
 
 END_BLUETOOTH_NAMESPACE
 
 #endif // mozilla_dom_bluetooth_ipc_bluetoothservicechildprocess_h__
--- a/dom/bluetooth/ipc/PBluetooth.ipdl
+++ b/dom/bluetooth/ipc/PBluetooth.ipdl
@@ -55,30 +55,68 @@ struct PairRequest
 };
 
 struct UnpairRequest
 {
   nsString path;
   nsString address;
 };
 
+struct SetPinCodeRequest
+{
+  nsString path;
+  nsString pincode;
+};
+
+struct SetPasskeyRequest
+{
+  nsString path;
+  uint32_t passkey;
+};
+
+struct ConfirmPairingConfirmationRequest
+{
+  nsString path;
+};
+
+struct DenyPairingConfirmationRequest
+{
+  nsString path;
+};
+
+struct ConfirmAuthorizationRequest
+{
+  nsString path;
+};
+
+struct DenyAuthorizationRequest
+{
+  nsString path;
+};
+
 struct DevicePropertiesRequest
 {
   nsString[] addresses;
 };
 
 union Request
 {
   DefaultAdapterPathRequest;
   SetPropertyRequest;
   GetPropertyRequest;
   StartDiscoveryRequest;
   StopDiscoveryRequest;
   PairRequest;
   UnpairRequest;
+  SetPinCodeRequest;
+  SetPasskeyRequest;
+  ConfirmPairingConfirmationRequest;
+  DenyPairingConfirmationRequest;
+  ConfirmAuthorizationRequest;
+  DenyAuthorizationRequest;
   DevicePropertiesRequest;
 };
 
 protocol PBluetooth
 {
   manager PContent;
   manages PBluetoothRequest;