From e873629acecd34d4ac0de51792b6eeebddb91781 Mon Sep 17 00:00:00 2001 From: Mounir Lamouri Date: Sun, 20 Nov 2011 23:59:46 +0100 Subject: [PATCH] Bug 674725 - Part H - Add a SmsService that handles IPC calls. r=smaug sr=cjones --- dom/sms/src/Makefile.in | 11 ++++- dom/sms/src/SmsServiceFactory.cpp | 63 +++++++++++++++++++++++++++ dom/sms/src/SmsServiceFactory.h | 59 +++++++++++++++++++++++++ dom/sms/src/ipc/PSms.ipdl | 3 ++ dom/sms/src/ipc/SmsIPCService.cpp | 71 +++++++++++++++++++++++++++++++ dom/sms/src/ipc/SmsIPCService.h | 64 ++++++++++++++++++++++++++++ dom/sms/src/ipc/SmsParent.cpp | 59 +++++++++++++++++++++++++ dom/sms/src/ipc/SmsParent.h | 1 + layout/build/nsLayoutModule.cpp | 7 +-- 9 files changed, 334 insertions(+), 4 deletions(-) create mode 100644 dom/sms/src/SmsServiceFactory.cpp create mode 100644 dom/sms/src/SmsServiceFactory.h create mode 100644 dom/sms/src/ipc/SmsIPCService.cpp create mode 100644 dom/sms/src/ipc/SmsIPCService.h create mode 100644 dom/sms/src/ipc/SmsParent.cpp diff --git a/dom/sms/src/Makefile.in b/dom/sms/src/Makefile.in index af5143888a09..856baa2f9086 100644 --- a/dom/sms/src/Makefile.in +++ b/dom/sms/src/Makefile.in @@ -59,17 +59,26 @@ include $(topsrcdir)/dom/dom-config.mk EXPORTS_NAMESPACES = mozilla/dom/sms EXPORTS_mozilla/dom/sms = \ - SmsService.h \ SmsChild.h \ SmsParent.h \ + SmsServiceFactory.h \ $(NULL) CPPSRCS = \ SmsManager.cpp \ SmsService.cpp \ + SmsIPCService.cpp \ + SmsServiceFactory.cpp \ + SmsParent.cpp $(NULL) LOCAL_INCLUDES = \ $(NULL) +# Add VPATH to LOCAL_INCLUDES so we are going to include the correct backend +# subdirectory (and the ipc one). +LOCAL_INCLUDES += $(VPATH:%=-I%) + +include $(topsrcdir)/config/config.mk +include $(topsrcdir)/ipc/chromium/chromium-config.mk include $(topsrcdir)/config/rules.mk diff --git a/dom/sms/src/SmsServiceFactory.cpp b/dom/sms/src/SmsServiceFactory.cpp new file mode 100644 index 000000000000..512fd05a7e22 --- /dev/null +++ b/dom/sms/src/SmsServiceFactory.cpp @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Mozilla Foundation + * Portions created by the Initial Developer are Copyright (C) 2011 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Mounir Lamouri (Original Author) + * + * Alternatively, the contents of this file may be used under the terms of + * either of the GNU General Public License Version 2 or later (the "GPL"), + * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "SmsServiceFactory.h" +#include "nsXULAppAPI.h" +#include "SmsService.h" +#include "SmsIPCService.h" + +namespace mozilla { +namespace dom { +namespace sms { + +/* static */ already_AddRefed +SmsServiceFactory::Create() +{ + nsCOMPtr smsService; + + if (XRE_GetProcessType() == GeckoProcessType_Content) { + smsService = new SmsIPCService(); + } else { + smsService = new SmsService(); + } + + return smsService.forget(); +} + +} // namespace sms +} // namespace dom +} // namespace mozilla diff --git a/dom/sms/src/SmsServiceFactory.h b/dom/sms/src/SmsServiceFactory.h new file mode 100644 index 000000000000..6de7f06a4620 --- /dev/null +++ b/dom/sms/src/SmsServiceFactory.h @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Mozilla Foundation + * Portions created by the Initial Developer are Copyright (C) 2011 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Mounir Lamouri (Original Author) + * + * Alternatively, the contents of this file may be used under the terms of + * either of the GNU General Public License Version 2 or later (the "GPL"), + * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef mozilla_dom_sms_SmsServiceFactory_h +#define mozilla_dom_sms_SmsServiceFactory_h + +#include "nsCOMPtr.h" + +class nsISmsService; + +namespace mozilla { +namespace dom { +namespace sms { + +class SmsServiceFactory +{ +public: + static already_AddRefed Create(); +}; + +} // namespace sms +} // namespace dom +} // namespace mozilla + +#endif // mozilla_dom_sms_SmsServiceFactory_h diff --git a/dom/sms/src/ipc/PSms.ipdl b/dom/sms/src/ipc/PSms.ipdl index c4970659c98a..db9dc8bffa9a 100644 --- a/dom/sms/src/ipc/PSms.ipdl +++ b/dom/sms/src/ipc/PSms.ipdl @@ -47,6 +47,9 @@ sync protocol PSms { manager PContent; parent: + sync HasSupport() + returns (bool aHasSupport); + __delete__(); }; diff --git a/dom/sms/src/ipc/SmsIPCService.cpp b/dom/sms/src/ipc/SmsIPCService.cpp new file mode 100644 index 000000000000..341270b6ec2d --- /dev/null +++ b/dom/sms/src/ipc/SmsIPCService.cpp @@ -0,0 +1,71 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Mozilla Foundation + * Portions created by the Initial Developer are Copyright (C) 2011 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Mounir Lamouri (Original Author) + * + * Alternatively, the contents of this file may be used under the terms of + * either of the GNU General Public License Version 2 or later (the "GPL"), + * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "mozilla/dom/ContentChild.h" +#include "SmsIPCService.h" +#include "nsXULAppAPI.h" +#include "mozilla/dom/sms/SmsChild.h" + +namespace mozilla { +namespace dom { +namespace sms { + +PSmsChild* SmsIPCService::sSmsChild = nsnull; + +NS_IMPL_ISUPPORTS1(SmsIPCService, nsISmsService) + +/* static */ PSmsChild* +SmsIPCService::GetSmsChild() +{ + if (!sSmsChild) { + sSmsChild = ContentChild::GetSingleton()->SendPSmsConstructor(); + } + + return sSmsChild; +} + +NS_IMETHODIMP +SmsIPCService::HasSupport(bool* aHasSupport) +{ + GetSmsChild()->SendHasSupport(aHasSupport); + + return NS_OK; +} + +} // namespace sms +} // namespace dom +} // namespace mozilla diff --git a/dom/sms/src/ipc/SmsIPCService.h b/dom/sms/src/ipc/SmsIPCService.h new file mode 100644 index 000000000000..4273375da00d --- /dev/null +++ b/dom/sms/src/ipc/SmsIPCService.h @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Mozilla Foundation + * Portions created by the Initial Developer are Copyright (C) 2011 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Mounir Lamouri (Original Author) + * + * Alternatively, the contents of this file may be used under the terms of + * either of the GNU General Public License Version 2 or later (the "GPL"), + * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef mozilla_dom_sms_SmsIPCService_h +#define mozilla_dom_sms_SmsIPCService_h + +#include "nsISmsService.h" + +namespace mozilla { +namespace dom { +namespace sms { + +class PSmsChild; + +class SmsIPCService : public nsISmsService +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSISMSSERVICE + +private: + static PSmsChild* GetSmsChild(); + static PSmsChild* sSmsChild; +}; + +} // namespace sms +} // namespace dom +} // namespace mozilla + +#endif // mozilla_dom_sms_SmsIPCService_h diff --git a/dom/sms/src/ipc/SmsParent.cpp b/dom/sms/src/ipc/SmsParent.cpp new file mode 100644 index 000000000000..5b67abd87630 --- /dev/null +++ b/dom/sms/src/ipc/SmsParent.cpp @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Mozilla Foundation + * Portions created by the Initial Developer are Copyright (C) 2011 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Mounir Lamouri (Original Author) + * + * Alternatively, the contents of this file may be used under the terms of + * either of the GNU General Public License Version 2 or later (the "GPL"), + * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "SmsParent.h" +#include "nsISmsService.h" + +namespace mozilla { +namespace dom { +namespace sms { + +bool +SmsParent::RecvHasSupport(bool* aHasSupport) +{ + *aHasSupport = false; + + nsCOMPtr smsService = do_GetService(SMSSERVICE_CONTRACTID); + NS_ENSURE_TRUE(smsService, true); + + smsService->HasSupport(aHasSupport); + return true; +} + +} // namespace sms +} // namespace dom +} // namespace mozilla diff --git a/dom/sms/src/ipc/SmsParent.h b/dom/sms/src/ipc/SmsParent.h index deb324764228..06433d28d8a8 100644 --- a/dom/sms/src/ipc/SmsParent.h +++ b/dom/sms/src/ipc/SmsParent.h @@ -46,6 +46,7 @@ namespace sms { class SmsParent : public PSmsParent { + NS_OVERRIDE virtual bool RecvHasSupport(bool* aHasSupport); }; } // namespace sms diff --git a/layout/build/nsLayoutModule.cpp b/layout/build/nsLayoutModule.cpp index 58090be07868..e8aa9b3bd04e 100644 --- a/layout/build/nsLayoutModule.cpp +++ b/layout/build/nsLayoutModule.cpp @@ -285,7 +285,8 @@ static void Shutdown(); #endif #endif #include "nsCSPService.h" -#include "mozilla/dom/sms/SmsService.h" +#include "nsISmsService.h" +#include "mozilla/dom/sms/SmsServiceFactory.h" using namespace mozilla::dom::sms; @@ -326,7 +327,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsHapticFeedback) #endif #endif NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(ThirdPartyUtil, Init) -NS_GENERIC_FACTORY_CONSTRUCTOR(SmsService) +NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsISmsService, SmsServiceFactory::Create) //----------------------------------------------------------------------------- @@ -989,7 +990,7 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = { #endif { &kTHIRDPARTYUTIL_CID, false, NULL, ThirdPartyUtilConstructor }, { &kNS_STRUCTUREDCLONECONTAINER_CID, false, NULL, nsStructuredCloneContainerConstructor }, - { &kNS_SMSSERVICE_CID, false, NULL, SmsServiceConstructor }, + { &kNS_SMSSERVICE_CID, false, NULL, nsISmsServiceConstructor }, { NULL } };