diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index 1d3f41bfa36..bb986530308 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -69,6 +69,7 @@ #include "mozilla/Preferences.h" #include "mozilla/Telemetry.h" #include "BatteryManager.h" +#include "SmsManager.h" // This should not be in the namespace. DOMCI_DATA(Navigator, mozilla::dom::Navigator) @@ -146,6 +147,10 @@ Navigator::SetDocShell(nsIDocShell* aDocShell) mBatteryManager->Shutdown(); mBatteryManager = nsnull; } + + if (mSmsManager) { + mSmsManager = nsnull; + } } //***************************************************************************** @@ -526,6 +531,10 @@ Navigator::LoadingNewDocument() mBatteryManager->Shutdown(); mBatteryManager = nsnull; } + + if (mSmsManager) { + mSmsManager = nsnull; + } } nsresult @@ -780,7 +789,11 @@ Navigator::GetMozBattery(nsIDOMMozBatteryManager** aBattery) NS_IMETHODIMP Navigator::GetMozSms(nsIDOMMozSmsManager** aSmsManager) { - *aSmsManager = nsnull; + if (!mSmsManager) { + mSmsManager = new sms::SmsManager(); + } + + NS_ADDREF(*aSmsManager = mSmsManager); return NS_OK; } diff --git a/dom/base/Navigator.h b/dom/base/Navigator.h index b17f0b0ceb9..517ffb9f2df 100644 --- a/dom/base/Navigator.h +++ b/dom/base/Navigator.h @@ -50,6 +50,7 @@ #include "nsIDOMNavigatorBattery.h" #include "nsIDOMNavigatorSms.h" #include "nsAutoPtr.h" +#include "nsIDOMSmsManager.h" class nsPluginArray; class nsMimeTypeArray; @@ -110,6 +111,7 @@ private: nsRefPtr mGeolocation; nsRefPtr mNotification; nsRefPtr mBatteryManager; + nsCOMPtr mSmsManager; nsIDocShell* mDocShell; // weak reference }; diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 0ad892c2800..5e7f9bd2b20 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -511,6 +511,7 @@ #include "nsIDOMBatteryManager.h" #include "BatteryManager.h" +#include "nsIDOMSmsManager.h" using namespace mozilla; using namespace mozilla::dom; @@ -1388,6 +1389,9 @@ static nsDOMClassInfoData sClassInfoData[] = { NS_DEFINE_CLASSINFO_DATA(MozBatteryManager, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) + NS_DEFINE_CLASSINFO_DATA(MozSmsManager, nsDOMGenericSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS) + NS_DEFINE_CLASSINFO_DATA(CSSFontFaceRule, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) NS_DEFINE_CLASSINFO_DATA(CSSFontFaceStyleDecl, nsCSSStyleDeclSH, @@ -3872,6 +3876,10 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) DOM_CLASSINFO_MAP_END + DOM_CLASSINFO_MAP_BEGIN(MozSmsManager, nsIDOMMozSmsManager) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozSmsManager) + DOM_CLASSINFO_MAP_END + DOM_CLASSINFO_MAP_BEGIN(CSSFontFaceRule, nsIDOMCSSFontFaceRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSFontFaceRule) DOM_CLASSINFO_MAP_END diff --git a/dom/base/nsDOMClassInfoClasses.h b/dom/base/nsDOMClassInfoClasses.h index 20a5530209c..f31279d77ba 100644 --- a/dom/base/nsDOMClassInfoClasses.h +++ b/dom/base/nsDOMClassInfoClasses.h @@ -428,6 +428,8 @@ DOMCI_CLASS(GeoPositionError) DOMCI_CLASS(MozBatteryManager) +DOMCI_CLASS(MozSmsManager) + // @font-face in CSS DOMCI_CLASS(CSSFontFaceRule) DOMCI_CLASS(CSSFontFaceStyleDecl) diff --git a/dom/sms/src/Makefile.in b/dom/sms/src/Makefile.in index 0f7dac73a9e..a5cb16bb81e 100644 --- a/dom/sms/src/Makefile.in +++ b/dom/sms/src/Makefile.in @@ -53,6 +53,7 @@ EXPORTS_mozilla/dom/sms = \ $(NULL) CPPSRCS = \ + SmsManager.cpp \ $(NULL) LOCAL_INCLUDES = \ diff --git a/dom/sms/src/SmsManager.cpp b/dom/sms/src/SmsManager.cpp new file mode 100644 index 00000000000..0a032d03abf --- /dev/null +++ b/dom/sms/src/SmsManager.cpp @@ -0,0 +1,58 @@ +/* -*- 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 "SmsManager.h" +#include "nsIDOMClassInfo.h" + +DOMCI_DATA(MozSmsManager, mozilla::dom::sms::SmsManager) + +namespace mozilla { +namespace dom { +namespace sms { + +NS_INTERFACE_MAP_BEGIN(SmsManager) + NS_INTERFACE_MAP_ENTRY(nsIDOMMozSmsManager) + NS_INTERFACE_MAP_ENTRY(nsISupports) + NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozSmsManager) +NS_INTERFACE_MAP_END + +NS_IMPL_ADDREF(SmsManager) +NS_IMPL_RELEASE(SmsManager) + +} // namespace sms +} // namespace dom +} // namespace mozilla diff --git a/dom/sms/src/SmsManager.h b/dom/sms/src/SmsManager.h new file mode 100644 index 00000000000..5965250964d --- /dev/null +++ b/dom/sms/src/SmsManager.h @@ -0,0 +1,58 @@ +/* -*- 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_SmsManager_h +#define mozilla_dom_sms_SmsManager_h + +#include "nsIDOMSmsManager.h" + +namespace mozilla { +namespace dom { +namespace sms { + +class SmsManager : public nsIDOMMozSmsManager +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIDOMMOZSMSMANAGER +}; + +} // namespace sms +} // namespace dom +} // namespace mozilla + +#endif // mozilla_dom_sms_SmsManager_h diff --git a/dom/sms/tests/test_sms_basics.html b/dom/sms/tests/test_sms_basics.html index f5eeb03411b..f867a52e99e 100644 --- a/dom/sms/tests/test_sms_basics.html +++ b/dom/sms/tests/test_sms_basics.html @@ -19,11 +19,15 @@ function checkInterface(aInterface) { ok(("Moz" + aInterface) in window, aInterface + " should be prefixed"); } -ok('mozSms' in navigator, "navigator.mozSms should exist"); - checkInterface("SmsManager"); checkInterface("NavigatorSms"); +ok('mozSms' in navigator, "navigator.mozSms should exist"); + +ok(navigator.mozSms, "navigator.mozSms returns an object"); + +ok(navigator.mozSms instanceof MozSmsManager, "navigator.mozSms is an SmsManager object"); +