Bug 847744: Part 1 - Create MmsService for content process. r=vicamo
authorPatrick Wang <kk1fff@patrickz.net>
Wed, 10 Apr 2013 20:18:32 +0800
changeset 128304 1bc493a828f6fcd4b0ad73a82bf2723f46b8d894
parent 128274 ee5ca214e87c483e65e45dbf4c3e2d323c976003
child 128305 17549598a514bfbcf167059fcb022562cb712b8c
push idunknown
push userunknown
push dateunknown
reviewersvicamo
bugs847744
milestone23.0a1
Bug 847744: Part 1 - Create MmsService for content process. r=vicamo
dom/mms/interfaces/nsIMmsService.idl
dom/mobilemessage/src/Makefile.in
dom/mobilemessage/src/MobileMessageManager.cpp
dom/mobilemessage/src/SmsServicesFactory.cpp
dom/mobilemessage/src/SmsServicesFactory.h
dom/mobilemessage/src/android/MmsService.cpp
dom/mobilemessage/src/android/MmsService.h
dom/mobilemessage/src/fallback/MmsService.cpp
dom/mobilemessage/src/fallback/MmsService.h
dom/mobilemessage/src/ipc/SmsIPCService.cpp
dom/mobilemessage/src/ipc/SmsIPCService.h
layout/build/nsLayoutModule.cpp
--- a/dom/mms/interfaces/nsIMmsService.idl
+++ b/dom/mms/interfaces/nsIMmsService.idl
@@ -2,17 +2,19 @@
  * 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 "nsISupports.idl"
 interface nsIMobileMessageCallback;
 interface nsIDOMBlob;
 
 %{C++
-#define RIL_MMSSERVICE_CONTRACTID "@mozilla.org/mms/rilmmsservice;1"
+#define MMS_SERVICE_CID { 0x06d9124b, 0x80e0, 0x40ed, \
+  { 0x98, 0x71, 0x4d, 0x23, 0x4a, 0x0f, 0xd4, 0x31 } }
+#define MMS_SERVICE_CONTRACTID "@mozilla.org/mms/mmsservice;1"
 %}
 
 [scriptable, uuid(e5ef630a-eab7-425a-ac42-650ef5c4fcef)]
 interface nsIMmsService : nsISupports
 {
   void send(in jsval parameters /* MmsParameters */,
             in nsIMobileMessageCallback request);
 
--- a/dom/mobilemessage/src/Makefile.in
+++ b/dom/mobilemessage/src/Makefile.in
@@ -87,18 +87,20 @@ LOCAL_INCLUDES += \
 
 EXTRA_COMPONENTS = \
   ril/MobileMessageDatabaseService.js \
   ril/MobileMessageDatabaseService.manifest \
   $(NULL)
 else
 EXPORTS_mozilla/dom/mobilemessage += \
   MobileMessageDatabaseService.h \
+  MmsService.h \
   $(NULL)
 
 CPPSRCS += \
   MobileMessageDatabaseService.cpp \
+  MmsService.cpp \
   $(NULL)
 endif
 
 include $(topsrcdir)/config/config.mk
 include $(topsrcdir)/ipc/chromium/chromium-config.mk
 include $(topsrcdir)/config/rules.mk
--- a/dom/mobilemessage/src/MobileMessageManager.cpp
+++ b/dom/mobilemessage/src/MobileMessageManager.cpp
@@ -188,17 +188,17 @@ MobileMessageManager::Send(const JS::Val
   NS_ENSURE_TRUE(aReturn->isObject(), NS_ERROR_FAILURE);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 MobileMessageManager::SendMMS(const JS::Value& aParams, nsIDOMDOMRequest** aRequest)
 {
-  nsCOMPtr<nsIMmsService> mmsService = do_GetService(RIL_MMSSERVICE_CONTRACTID);
+  nsCOMPtr<nsIMmsService> mmsService = do_GetService(MMS_SERVICE_CONTRACTID);
   NS_ENSURE_TRUE(mmsService, NS_ERROR_FAILURE);
 
   nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
   nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
   nsresult rv = mmsService->Send(aParams, msgCallback);
   NS_ENSURE_SUCCESS(rv, rv);
 
   request.forget(aRequest);
--- a/dom/mobilemessage/src/SmsServicesFactory.cpp
+++ b/dom/mobilemessage/src/SmsServicesFactory.cpp
@@ -4,19 +4,21 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "SmsServicesFactory.h"
 #include "nsXULAppAPI.h"
 #include "SmsService.h"
 #include "SmsIPCService.h"
 #ifndef MOZ_B2G_RIL
 #include "MobileMessageDatabaseService.h"
+#include "MmsService.h"
 #endif
 #include "nsServiceManagerUtils.h"
 
+#define RIL_MMSSERVICE_CONTRACTID "@mozilla.org/mms/rilmmsservice;1"
 #define RIL_MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID "@mozilla.org/mobilemessage/rilmobilemessagedatabaseservice;1"
 
 namespace mozilla {
 namespace dom {
 namespace mobilemessage {
 
 /* static */ already_AddRefed<nsISmsService>
 SmsServicesFactory::CreateSmsService()
@@ -44,11 +46,29 @@ SmsServicesFactory::CreateMobileMessageD
 #else
     mobileMessageDBService = new MobileMessageDatabaseService();
 #endif
   }
 
   return mobileMessageDBService.forget();
 }
 
+/* static */ already_AddRefed<nsIMmsService>
+SmsServicesFactory::CreateMmsService()
+{
+  nsCOMPtr<nsIMmsService> mmsService;
+
+  if (XRE_GetProcessType() == GeckoProcessType_Content) {
+    mmsService = new SmsIPCService();
+  } else {
+#ifdef MOZ_B2G_RIL
+    mmsService = do_CreateInstance(RIL_MMSSERVICE_CONTRACTID);
+#else
+    mmsService = new MmsService();
+#endif
+  }
+
+  return mmsService.forget();
+}
+
 } // namespace mobilemessage
 } // namespace dom
 } // namespace mozilla
--- a/dom/mobilemessage/src/SmsServicesFactory.h
+++ b/dom/mobilemessage/src/SmsServicesFactory.h
@@ -4,26 +4,28 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_mobilemessage_SmsServicesFactory_h
 #define mozilla_dom_mobilemessage_SmsServicesFactory_h
 
 #include "nsCOMPtr.h"
 
 class nsISmsService;
+class nsIMmsService;
 class nsIMobileMessageDatabaseService;
 
 namespace mozilla {
 namespace dom {
 namespace mobilemessage {
 
 class SmsServicesFactory
 {
 public:
   static already_AddRefed<nsISmsService> CreateSmsService();
   static already_AddRefed<nsIMobileMessageDatabaseService> CreateMobileMessageDatabaseService();
+  static already_AddRefed<nsIMmsService> CreateMmsService();
 };
 
 } // namespace mobilemessage
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_mobilemessage_SmsServicesFactory_h
new file mode 100644
--- /dev/null
+++ b/dom/mobilemessage/src/android/MmsService.cpp
@@ -0,0 +1,27 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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 "MobileMessageCallback.h"
+#include "MmsService.h"
+#include "AndroidBridge.h"
+#include "jsapi.h"
+
+namespace mozilla {
+namespace dom {
+namespace mobilemessage {
+
+NS_IMPL_ISUPPORTS1(MmsService, nsIMmsService)
+
+NS_IMETHODIMP
+MmsService::Send(const JS::Value& aParameters,
+                 nsIMobileMessageCallback *aRequest)
+{
+  NS_NOTYETIMPLEMENTED("Implement me!");
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+} // namespace mobilemessage
+} // namespace dom
+} // namespace mozilla
copy from dom/mobilemessage/src/SmsServicesFactory.h
copy to dom/mobilemessage/src/android/MmsService.h
--- a/dom/mobilemessage/src/SmsServicesFactory.h
+++ b/dom/mobilemessage/src/android/MmsService.h
@@ -1,29 +1,26 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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_mobilemessage_SmsServicesFactory_h
-#define mozilla_dom_mobilemessage_SmsServicesFactory_h
+#ifndef mozilla_dom_mobilemessage_MmsService_h
+#define mozilla_dom_mobilemessage_MmsService_h
 
-#include "nsCOMPtr.h"
-
-class nsISmsService;
-class nsIMobileMessageDatabaseService;
+#include "nsIMmsService.h"
 
 namespace mozilla {
 namespace dom {
 namespace mobilemessage {
 
-class SmsServicesFactory
+class MmsService MOZ_FINAL : public nsIMmsService
 {
 public:
-  static already_AddRefed<nsISmsService> CreateSmsService();
-  static already_AddRefed<nsIMobileMessageDatabaseService> CreateMobileMessageDatabaseService();
+  NS_DECL_ISUPPORTS
+  NS_DECL_NSIMMSSERVICE
 };
 
 } // namespace mobilemessage
 } // namespace dom
 } // namespace mozilla
 
-#endif // mozilla_dom_mobilemessage_SmsServicesFactory_h
+#endif // mozilla_dom_mobilemessage_MmsService_h
new file mode 100644
--- /dev/null
+++ b/dom/mobilemessage/src/fallback/MmsService.cpp
@@ -0,0 +1,26 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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 "MobileMessageCallback.h"
+#include "MmsService.h"
+#include "jsapi.h"
+
+namespace mozilla {
+namespace dom {
+namespace mobilemessage {
+
+NS_IMPL_ISUPPORTS1(MmsService, nsIMmsService)
+
+NS_IMETHODIMP
+MmsService::Send(const JS::Value& aParameters,
+                 nsIMobileMessageCallback *aRequest)
+{
+  NS_NOTYETIMPLEMENTED("Implement me!");
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+} // namespace mobilemessage
+} // namespace dom
+} // namespace mozilla
copy from dom/mobilemessage/src/SmsServicesFactory.h
copy to dom/mobilemessage/src/fallback/MmsService.h
--- a/dom/mobilemessage/src/SmsServicesFactory.h
+++ b/dom/mobilemessage/src/fallback/MmsService.h
@@ -1,29 +1,26 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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_mobilemessage_SmsServicesFactory_h
-#define mozilla_dom_mobilemessage_SmsServicesFactory_h
+#ifndef mozilla_dom_mobilemessage_MmsService_h
+#define mozilla_dom_mobilemessage_MmsService_h
 
-#include "nsCOMPtr.h"
-
-class nsISmsService;
-class nsIMobileMessageDatabaseService;
+#include "nsIMmsService.h"
 
 namespace mozilla {
 namespace dom {
 namespace mobilemessage {
 
-class SmsServicesFactory
+class MmsService MOZ_FINAL : public nsIMmsService
 {
 public:
-  static already_AddRefed<nsISmsService> CreateSmsService();
-  static already_AddRefed<nsIMobileMessageDatabaseService> CreateMobileMessageDatabaseService();
+  NS_DECL_ISUPPORTS
+  NS_DECL_NSIMMSSERVICE
 };
 
 } // namespace mobilemessage
 } // namespace dom
 } // namespace mozilla
 
-#endif // mozilla_dom_mobilemessage_SmsServicesFactory_h
+#endif // mozilla_dom_mobilemessage_MmsService_h
--- a/dom/mobilemessage/src/ipc/SmsIPCService.cpp
+++ b/dom/mobilemessage/src/ipc/SmsIPCService.cpp
@@ -66,19 +66,20 @@ SendCursorRequest(const IPCMobileMessage
   smsChild->SendPMobileMessageCursorConstructor(actor, aRequest);
 
   actor.forget(aResult);
   return NS_OK;
 }
 
 } // anonymous namespace
 
-NS_IMPL_ISUPPORTS2(SmsIPCService,
+NS_IMPL_ISUPPORTS3(SmsIPCService,
                    nsISmsService,
-                   nsIMobileMessageDatabaseService);
+                   nsIMmsService,
+                   nsIMobileMessageDatabaseService)
 
 /*
  * Implementation of nsISmsService.
  */
 NS_IMETHODIMP
 SmsIPCService::HasSupport(bool* aHasSupport)
 {
   PSmsChild* smsChild = GetSmsChild();
@@ -154,8 +155,16 @@ SmsIPCService::MarkMessageRead(int32_t a
 
 NS_IMETHODIMP
 SmsIPCService::CreateThreadCursor(nsIMobileMessageCursorCallback* aCursorCallback,
                                   nsICursorContinueCallback** aResult)
 {
   return SendCursorRequest(CreateThreadCursorRequest(), aCursorCallback,
                            aResult);
 }
+
+NS_IMETHODIMP
+SmsIPCService::Send(const JS::Value& aParameters,
+                    nsIMobileMessageCallback *aRequest)
+{
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
--- a/dom/mobilemessage/src/ipc/SmsIPCService.h
+++ b/dom/mobilemessage/src/ipc/SmsIPCService.h
@@ -2,31 +2,34 @@
 /* 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_mobilemessage_SmsIPCService_h
 #define mozilla_dom_mobilemessage_SmsIPCService_h
 
 #include "nsISmsService.h"
+#include "nsIMmsService.h"
 #include "nsIMobileMessageDatabaseService.h"
 #include "mozilla/Attributes.h"
 
 namespace mozilla {
 namespace dom {
 namespace mobilemessage {
 
 class PSmsChild;
 
 class SmsIPCService MOZ_FINAL : public nsISmsService
+                              , public nsIMmsService
                               , public nsIMobileMessageDatabaseService
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSISMSSERVICE
+  NS_DECL_NSIMMSSERVICE
   NS_DECL_NSIMOBILEMESSAGEDATABASESERVICE
 };
 
 } // namespace mobilemessage
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_mobilemessage_SmsIPCService_h
--- a/layout/build/nsLayoutModule.cpp
+++ b/layout/build/nsLayoutModule.cpp
@@ -217,16 +217,17 @@ static void Shutdown();
 
 #include "nsGeolocation.h"
 #include "nsDeviceSensors.h"
 #ifdef MOZ_GAMEPAD
 #include "mozilla/dom/GamepadService.h"
 #endif
 #include "nsCSPService.h"
 #include "nsISmsService.h"
+#include "nsIMmsService.h"
 #include "nsIMobileMessageService.h"
 #include "nsIMobileMessageDatabaseService.h"
 #include "mozilla/dom/mobilemessage/MobileMessageService.h"
 #include "mozilla/dom/mobilemessage/SmsServicesFactory.h"
 #include "nsIPowerManagerService.h"
 #include "nsIAlarmHalService.h"
 #include "nsIMediaManager.h"
 #include "nsMixedContentBlocker.h"
@@ -312,16 +313,18 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceS
 #ifndef MOZ_WIDGET_GONK
 #if defined(ANDROID) || defined(MOZ_PLATFORM_MAEMO)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsHapticFeedback)
 #endif
 #endif
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(ThirdPartyUtil, Init)
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsISmsService,
                                          SmsServicesFactory::CreateSmsService)
+NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIMmsService,
+                                         SmsServicesFactory::CreateMmsService)
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIMobileMessageService,
                                          MobileMessageService::GetInstance)
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIMobileMessageDatabaseService,
                                          SmsServicesFactory::CreateMobileMessageDatabaseService)
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIPowerManagerService,
                                          PowerManagerService::GetInstance)
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIAlarmHalService,
                                          AlarmHalService::GetInstance)
@@ -820,16 +823,17 @@ NS_DEFINE_NAMED_CID(NS_STRUCTUREDCLONECO
 NS_DEFINE_NAMED_CID(NS_DEVICE_SENSORS_CID);
 
 #ifndef MOZ_WIDGET_GONK
 #if defined(ANDROID) || defined(MOZ_PLATFORM_MAEMO)
 NS_DEFINE_NAMED_CID(NS_HAPTICFEEDBACK_CID);
 #endif
 #endif
 NS_DEFINE_NAMED_CID(SMS_SERVICE_CID);
+NS_DEFINE_NAMED_CID(MMS_SERVICE_CID);
 NS_DEFINE_NAMED_CID(MOBILE_MESSAGE_SERVICE_CID);
 NS_DEFINE_NAMED_CID(MOBILE_MESSAGE_DATABASE_SERVICE_CID);
 NS_DEFINE_NAMED_CID(NS_POWERMANAGERSERVICE_CID);
 NS_DEFINE_NAMED_CID(OSFILECONSTANTSSERVICE_CID);
 NS_DEFINE_NAMED_CID(NS_ALARMHALSERVICE_CID);
 NS_DEFINE_NAMED_CID(TCPSOCKETCHILD_CID);
 NS_DEFINE_NAMED_CID(NS_TIMESERVICE_CID);
 #ifdef MOZ_WIDGET_GONK
@@ -1105,16 +1109,17 @@ static const mozilla::Module::CIDEntry k
 #ifndef MOZ_WIDGET_GONK
 #if defined(ANDROID) || defined(MOZ_PLATFORM_MAEMO)
   { &kNS_HAPTICFEEDBACK_CID, false, NULL, nsHapticFeedbackConstructor },
 #endif
 #endif
   { &kTHIRDPARTYUTIL_CID, false, NULL, ThirdPartyUtilConstructor },
   { &kNS_STRUCTUREDCLONECONTAINER_CID, false, NULL, nsStructuredCloneContainerConstructor },
   { &kSMS_SERVICE_CID, false, NULL, nsISmsServiceConstructor },
+  { &kMMS_SERVICE_CID, false, NULL, nsIMmsServiceConstructor },
   { &kMOBILE_MESSAGE_SERVICE_CID, false, NULL, nsIMobileMessageServiceConstructor },
   { &kMOBILE_MESSAGE_DATABASE_SERVICE_CID, false, NULL, nsIMobileMessageDatabaseServiceConstructor },
   { &kNS_POWERMANAGERSERVICE_CID, false, NULL, nsIPowerManagerServiceConstructor },
   { &kOSFILECONSTANTSSERVICE_CID, true, NULL, OSFileConstantsServiceConstructor },
   { &kNS_ALARMHALSERVICE_CID, false, NULL, nsIAlarmHalServiceConstructor },
   { &kTCPSOCKETCHILD_CID, false, NULL, TCPSocketChildConstructor },
   { &kNS_TIMESERVICE_CID, false, NULL, nsITimeServiceConstructor },
 #ifdef MOZ_WIDGET_GONK
@@ -1253,16 +1258,17 @@ static const mozilla::Module::ContractID
 #ifndef MOZ_WIDGET_GONK
 #if defined(ANDROID) || defined(MOZ_PLATFORM_MAEMO)
   { "@mozilla.org/widget/hapticfeedback;1", &kNS_HAPTICFEEDBACK_CID },
 #endif
 #endif
   { THIRDPARTYUTIL_CONTRACTID, &kTHIRDPARTYUTIL_CID },
   { NS_STRUCTUREDCLONECONTAINER_CONTRACTID, &kNS_STRUCTUREDCLONECONTAINER_CID },
   { SMS_SERVICE_CONTRACTID, &kSMS_SERVICE_CID },
+  { MMS_SERVICE_CONTRACTID, &kMMS_SERVICE_CID },
   { MOBILE_MESSAGE_SERVICE_CONTRACTID, &kMOBILE_MESSAGE_SERVICE_CID },
   { MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID, &kMOBILE_MESSAGE_DATABASE_SERVICE_CID },
   { POWERMANAGERSERVICE_CONTRACTID, &kNS_POWERMANAGERSERVICE_CID },
   { OSFILECONSTANTSSERVICE_CONTRACTID, &kOSFILECONSTANTSSERVICE_CID },
   { ALARMHALSERVICE_CONTRACTID, &kNS_ALARMHALSERVICE_CID },
   { "@mozilla.org/tcp-socket-child;1", &kTCPSOCKETCHILD_CID },
   { TIMESERVICE_CONTRACTID, &kNS_TIMESERVICE_CID },
 #ifdef MOZ_WIDGET_GONK