author | Jim Chen <nchen@mozilla.com> |
Thu, 04 Aug 2016 09:17:54 -0400 | |
changeset 308207 | d327a34d94d723c5af2fdedb56bab22e6b7bc463 |
parent 308206 | 79374eef5dcee186392595e1de8a4eea1c69ce67 |
child 308208 | d8ed6dd3fbbd4e3c3a80fef36b12b102934fc0ef |
push id | 31092 |
push user | cbook@mozilla.com |
push date | Fri, 05 Aug 2016 10:16:59 +0000 |
treeherder | autoland@b97dd7dd3cb9 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | snorp |
bugs | 1288821 |
milestone | 51.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
new file mode 100644 --- /dev/null +++ b/widget/android/AndroidAlerts.cpp @@ -0,0 +1,102 @@ +/* -*- Mode: c++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 4; -*- */ +/* 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 "AndroidAlerts.h" +#include "GeneratedJNIWrappers.h" +#include "nsAlertsUtils.h" +#include "nsAppShell.h" + +namespace mozilla { +namespace widget { + +NS_IMPL_ISUPPORTS(AndroidAlerts, nsIAlertsService) + +NS_IMETHODIMP +AndroidAlerts::ShowAlertNotification(const nsAString & aImageUrl, + const nsAString & aAlertTitle, + const nsAString & aAlertText, + bool aAlertTextClickable, + const nsAString & aAlertCookie, + nsIObserver * aAlertListener, + const nsAString & aAlertName, + const nsAString & aBidi, + const nsAString & aLang, + const nsAString & aData, + nsIPrincipal * aPrincipal, + bool aInPrivateBrowsing) +{ + MOZ_ASSERT_UNREACHABLE("Should be implemented by nsAlertsService."); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +AndroidAlerts::ShowAlert(nsIAlertNotification* aAlert, + nsIObserver* aAlertListener) +{ + return ShowPersistentNotification(EmptyString(), aAlert, aAlertListener); +} + +NS_IMETHODIMP +AndroidAlerts::ShowPersistentNotification(const nsAString& aPersistentData, + nsIAlertNotification* aAlert, + nsIObserver* aAlertListener) +{ + // nsAlertsService disables our alerts backend if we ever return failure + // here. To keep the backend enabled, we always return NS_OK even if we + // encounter an error here. + nsresult rv; + + nsAutoString imageUrl; + rv = aAlert->GetImageURL(imageUrl); + NS_ENSURE_SUCCESS(rv, NS_OK); + + nsAutoString title; + rv = aAlert->GetTitle(title); + NS_ENSURE_SUCCESS(rv, NS_OK); + + nsAutoString text; + rv = aAlert->GetText(text); + NS_ENSURE_SUCCESS(rv, NS_OK); + + nsAutoString cookie; + rv = aAlert->GetCookie(cookie); + NS_ENSURE_SUCCESS(rv, NS_OK); + + nsAutoString name; + rv = aAlert->GetName(name); + NS_ENSURE_SUCCESS(rv, NS_OK); + + nsCOMPtr<nsIPrincipal> principal; + rv = aAlert->GetPrincipal(getter_AddRefs(principal)); + NS_ENSURE_SUCCESS(rv, NS_OK); + + nsAutoString host; + nsAlertsUtils::GetSourceHostPort(principal, host); + + if (!aPersistentData.IsEmpty()) { + java::GeckoAppShell::ShowPersistentAlertNotificationWrapper( + aPersistentData, imageUrl, title, text, cookie, name, host); + } else { + if (aAlertListener) { + // This will remove any observers already registered for this id + nsAppShell::PostEvent(AndroidGeckoEvent::MakeAddObserver(name, aAlertListener)); + } + + java::GeckoAppShell::ShowAlertNotificationWrapper( + imageUrl, title, text, cookie, name, host); + } + return NS_OK; +} + +NS_IMETHODIMP +AndroidAlerts::CloseAlert(const nsAString& aAlertName, + nsIPrincipal* aPrincipal) +{ + java::GeckoAppShell::CloseNotification(aAlertName); + return NS_OK; +} + +} // namespace widget +} // namespace mozilla
new file mode 100644 --- /dev/null +++ b/widget/android/AndroidAlerts.h @@ -0,0 +1,29 @@ +/* -*- Mode: c++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 4; -*- */ +/* 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_widget_AndroidAlerts_h__ +#define mozilla_widget_AndroidAlerts_h__ + +#include "nsIAlertsService.h" + +namespace mozilla { +namespace widget { + +class AndroidAlerts : public nsIAlertsService +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIALERTSSERVICE + + AndroidAlerts() {} + +protected: + virtual ~AndroidAlerts() {} +}; + +} // namespace widget +} // namespace mozilla + +#endif // nsAndroidAlerts_h__
--- a/widget/android/moz.build +++ b/widget/android/moz.build @@ -19,16 +19,17 @@ EXPORTS += [ 'AndroidBridge.h', 'AndroidJavaWrappers.h', 'AndroidJNIWrapper.h', 'GeneratedJNINatives.h', 'GeneratedJNIWrappers.h', ] UNIFIED_SOURCES += [ + 'AndroidAlerts.cpp', 'AndroidBridge.cpp', 'AndroidContentController.cpp', 'AndroidDirectTexture.cpp', 'AndroidGraphicBuffer.cpp', 'AndroidJavaWrappers.cpp', 'AndroidJNI.cpp', 'AndroidJNIWrapper.cpp', 'ANRReporter.cpp',
--- a/widget/android/nsWidgetFactory.cpp +++ b/widget/android/nsWidgetFactory.cpp @@ -22,16 +22,19 @@ #include "nsTransferable.h" #include "nsPrintOptionsAndroid.h" #include "nsPrintSession.h" #include "nsDeviceContextAndroid.h" #include "nsHTMLFormatConverter.h" #include "nsXULAppAPI.h" #include "nsAndroidProtocolHandler.h" +#include "nsToolkitCompsCID.h" +#include "AndroidAlerts.h" + NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindow) NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerAndroid) NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIdleServiceAndroid, nsIdleServiceAndroid::GetInstance) NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable) NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard) NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintOptionsAndroid, Init) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintSession, Init) @@ -40,16 +43,17 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFor NS_GENERIC_FACTORY_CONSTRUCTOR(nsAndroidBridge) NS_GENERIC_FACTORY_CONSTRUCTOR(nsAndroidProtocolHandler) #include "GfxInfo.h" namespace mozilla { namespace widget { // This constructor should really be shared with all platforms. NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(GfxInfo, Init) +NS_GENERIC_FACTORY_CONSTRUCTOR(AndroidAlerts) } } NS_DEFINE_NAMED_CID(NS_APPSHELL_CID); NS_DEFINE_NAMED_CID(NS_WINDOW_CID); NS_DEFINE_NAMED_CID(NS_CHILD_CID); NS_DEFINE_NAMED_CID(NS_SCREENMANAGER_CID); NS_DEFINE_NAMED_CID(NS_IDLE_SERVICE_CID); @@ -58,16 +62,17 @@ NS_DEFINE_NAMED_CID(NS_CLIPBOARD_CID); NS_DEFINE_NAMED_CID(NS_CLIPBOARDHELPER_CID); NS_DEFINE_NAMED_CID(NS_PRINTSETTINGSSERVICE_CID); NS_DEFINE_NAMED_CID(NS_PRINTSESSION_CID); NS_DEFINE_NAMED_CID(NS_DEVICE_CONTEXT_SPEC_CID); NS_DEFINE_NAMED_CID(NS_HTMLFORMATCONVERTER_CID); NS_DEFINE_NAMED_CID(NS_GFXINFO_CID); NS_DEFINE_NAMED_CID(NS_ANDROIDBRIDGE_CID); NS_DEFINE_NAMED_CID(NS_ANDROIDPROTOCOLHANDLER_CID); +NS_DEFINE_NAMED_CID(NS_SYSTEMALERTSSERVICE_CID); static const mozilla::Module::CIDEntry kWidgetCIDs[] = { { &kNS_WINDOW_CID, false, nullptr, nsWindowConstructor }, { &kNS_CHILD_CID, false, nullptr, nsWindowConstructor }, { &kNS_APPSHELL_CID, false, nullptr, nsAppShellConstructor }, { &kNS_SCREENMANAGER_CID, false, nullptr, nsScreenManagerAndroidConstructor }, { &kNS_IDLE_SERVICE_CID, false, nullptr, nsIdleServiceAndroidConstructor }, { &kNS_TRANSFERABLE_CID, false, nullptr, nsTransferableConstructor }, @@ -75,16 +80,17 @@ static const mozilla::Module::CIDEntry k { &kNS_CLIPBOARDHELPER_CID, false, nullptr, nsClipboardHelperConstructor }, { &kNS_PRINTSETTINGSSERVICE_CID, false, nullptr, nsPrintOptionsAndroidConstructor }, { &kNS_PRINTSESSION_CID, false, nullptr, nsPrintSessionConstructor }, { &kNS_DEVICE_CONTEXT_SPEC_CID, false, nullptr, nsDeviceContextSpecAndroidConstructor }, { &kNS_HTMLFORMATCONVERTER_CID, false, nullptr, nsHTMLFormatConverterConstructor }, { &kNS_GFXINFO_CID, false, nullptr, mozilla::widget::GfxInfoConstructor }, { &kNS_ANDROIDBRIDGE_CID, false, nullptr, nsAndroidBridgeConstructor }, { &kNS_ANDROIDPROTOCOLHANDLER_CID, false, nullptr, nsAndroidProtocolHandlerConstructor }, + { &kNS_SYSTEMALERTSSERVICE_CID, false, nullptr, mozilla::widget::AndroidAlertsConstructor }, { nullptr } }; static const mozilla::Module::ContractIDEntry kWidgetContracts[] = { { "@mozilla.org/widgets/window/android;1", &kNS_WINDOW_CID }, { "@mozilla.org/widgets/child_window/android;1", &kNS_CHILD_CID }, { "@mozilla.org/widget/appshell/android;1", &kNS_APPSHELL_CID }, { "@mozilla.org/gfx/screenmanager;1", &kNS_SCREENMANAGER_CID }, @@ -94,16 +100,17 @@ static const mozilla::Module::ContractID { "@mozilla.org/widget/clipboardhelper;1", &kNS_CLIPBOARDHELPER_CID }, { "@mozilla.org/gfx/printsettings-service;1", &kNS_PRINTSETTINGSSERVICE_CID }, { "@mozilla.org/gfx/printsession;1", &kNS_PRINTSESSION_CID }, { "@mozilla.org/gfx/devicecontextspec;1", &kNS_DEVICE_CONTEXT_SPEC_CID }, { "@mozilla.org/widget/htmlformatconverter;1", &kNS_HTMLFORMATCONVERTER_CID }, { "@mozilla.org/gfx/info;1", &kNS_GFXINFO_CID }, { "@mozilla.org/android/bridge;1", &kNS_ANDROIDBRIDGE_CID }, { NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "android", &kNS_ANDROIDPROTOCOLHANDLER_CID }, + { NS_SYSTEMALERTSERVICE_CONTRACTID, &kNS_SYSTEMALERTSSERVICE_CID }, { nullptr } }; static void nsWidgetAndroidModuleDtor() { // Shutdown all XP level widget classes. mozilla::widget::WidgetUtils::Shutdown();