author | Doug Turner <dougt@dougt.org> |
Thu, 09 Sep 2010 22:00:14 -0700 | |
changeset 52355 | da8eae9cbf24b434524e5b4e562e5f2b7ded1de0 |
parent 52354 | caa83e7f002016bd02fb7d7adac0c62a0ea2881f |
child 52356 | 5a9dc4ef07364c48a6d762755bbc20715f12b07b |
push id | 15607 |
push user | dougt@mozilla.com |
push date | Fri, 10 Sep 2010 05:03:28 +0000 |
treeherder | mozilla-central@5a9dc4ef0736 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | smaug, beltzner |
bugs | 573588 |
milestone | 2.0b6pre |
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
|
--- a/browser/installer/package-manifest.in +++ b/browser/installer/package-manifest.in @@ -144,16 +144,17 @@ @BINPATH@/components/docshell.xpt @BINPATH@/components/dom.xpt @BINPATH@/components/dom_base.xpt @BINPATH@/components/dom_canvas.xpt @BINPATH@/components/dom_core.xpt @BINPATH@/components/dom_css.xpt @BINPATH@/components/dom_events.xpt @BINPATH@/components/dom_geolocation.xpt +@BINPATH@/components/dom_notification.xpt @BINPATH@/components/dom_html.xpt @BINPATH@/components/dom_indexeddb.xpt @BINPATH@/components/dom_offline.xpt @BINPATH@/components/dom_json.xpt @BINPATH@/components/dom_range.xpt @BINPATH@/components/dom_sidebar.xpt @BINPATH@/components/dom_storage.xpt @BINPATH@/components/dom_stylesheets.xpt
--- a/dom/Makefile.in +++ b/dom/Makefile.in @@ -59,16 +59,17 @@ DIRS = \ interfaces/xpath \ interfaces/load-save \ interfaces/xul \ interfaces/storage \ interfaces/json \ interfaces/offline \ interfaces/geolocation \ interfaces/threads \ + interfaces/notification \ $(NULL) ifdef MOZ_SVG DIRS += interfaces/svg endif ifdef MOZ_SMIL DIRS += interfaces/smil
--- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -461,16 +461,19 @@ #include "nsDOMWorker.h" #include "nsDOMFile.h" #include "nsDOMFileReader.h" #include "nsIDOMFileException.h" #include "nsIDOMFileError.h" #include "nsIDOMFormData.h" +#include "nsIDOMDesktopNotification.h" +#include "nsIDOMNavigatorDesktopNotification.h" + // Simple gestures include #include "nsIDOMSimpleGestureEvent.h" #include "nsIDOMNSMouseEvent.h" #include "nsIDOMMozTouchEvent.h" #include "nsIEventListenerService.h" @@ -1437,16 +1440,21 @@ static nsDOMClassInfoData sClassInfoData NS_DEFINE_CLASSINFO_DATA(TransitionEvent, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) NS_DEFINE_CLASSINFO_DATA(ContentFrameMessageManager, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) NS_DEFINE_CLASSINFO_DATA(FormData, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) + NS_DEFINE_CLASSINFO_DATA(DesktopNotification, nsDOMGenericSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS) + NS_DEFINE_CLASSINFO_DATA(DesktopNotificationCenter, nsDOMGenericSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS) + NS_DEFINE_CLASSINFO_DATA(WebSocket, nsEventTargetSH, EVENTTARGET_SCRIPTABLE_FLAGS) NS_DEFINE_CLASSINFO_DATA(CloseEvent, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) NS_DEFINE_CLASSINFO_DATA(IDBFactory, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) @@ -2257,16 +2265,17 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_BEGIN(Location, nsIDOMLocation) DOM_CLASSINFO_MAP_ENTRY(nsIDOMLocation) DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(Navigator, nsIDOMNavigator) DOM_CLASSINFO_MAP_ENTRY(nsIDOMNavigator) DOM_CLASSINFO_MAP_ENTRY(nsIDOMNavigatorGeolocation) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMNavigatorDesktopNotification) DOM_CLASSINFO_MAP_ENTRY(nsIDOMClientInformation) DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(Plugin, nsIDOMPlugin) DOM_CLASSINFO_MAP_ENTRY(nsIDOMPlugin) DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(PluginArray, nsIDOMPluginArray) @@ -4038,16 +4047,24 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsISyncMessageSender) DOM_CLASSINFO_MAP_ENTRY(nsIContentFrameMessageManager) DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(FormData, nsIDOMFormData) DOM_CLASSINFO_MAP_ENTRY(nsIDOMFormData) DOM_CLASSINFO_MAP_END + DOM_CLASSINFO_MAP_BEGIN(DesktopNotification, nsIDOMDesktopNotification) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMDesktopNotification) + DOM_CLASSINFO_MAP_END + + DOM_CLASSINFO_MAP_BEGIN(DesktopNotificationCenter, nsIDOMDesktopNotificationCenter) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMDesktopNotificationCenter) + DOM_CLASSINFO_MAP_END + DOM_CLASSINFO_MAP_BEGIN(WebSocket, nsIWebSocket) DOM_CLASSINFO_MAP_ENTRY(nsIWebSocket) DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget) DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(CloseEvent, nsIDOMCloseEvent) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCloseEvent)
--- a/dom/base/nsDOMClassInfoClasses.h +++ b/dom/base/nsDOMClassInfoClasses.h @@ -480,16 +480,19 @@ DOMCI_CLASS(PopStateEvent) DOMCI_CLASS(EventListenerInfo) DOMCI_CLASS(TransitionEvent) DOMCI_CLASS(ContentFrameMessageManager) DOMCI_CLASS(FormData) +DOMCI_CLASS(DesktopNotification) +DOMCI_CLASS(DesktopNotificationCenter) + // WebSocket DOMCI_CLASS(WebSocket) DOMCI_CLASS(CloseEvent) DOMCI_CLASS(IDBFactory) DOMCI_CLASS(IDBRequest) DOMCI_CLASS(IDBDatabase) DOMCI_CLASS(IDBErrorEvent)
--- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -73,16 +73,17 @@ #include "nsEscape.h" #include "nsStyleCoord.h" #include "nsMimeTypeArray.h" #include "nsNetUtil.h" #include "nsICachingChannel.h" #include "nsPluginArray.h" #include "nsIPluginHost.h" #include "nsGeolocation.h" +#include "nsDesktopNotification.h" #include "nsContentCID.h" #include "nsLayoutStatics.h" #include "nsCycleCollector.h" #include "nsCCUncollectableMarker.h" #include "nsDOMThreadService.h" #include "nsAutoJSValHolder.h" // Interfaces Needed @@ -113,16 +114,17 @@ #include "nsIDOMEvent.h" #include "nsIDOMHTMLAnchorElement.h" #include "nsIDOMKeyEvent.h" #include "nsIDOMMessageEvent.h" #include "nsIDOMPopupBlockedEvent.h" #include "nsIDOMPopStateEvent.h" #include "nsIDOMOfflineResourceList.h" #include "nsIDOMGeoGeolocation.h" +#include "nsIDOMDesktopNotification.h" #include "nsPIDOMStorage.h" #include "nsDOMString.h" #include "nsIEmbeddingSiteWindow2.h" #include "nsThreadUtils.h" #include "nsIEventStateManager.h" #include "nsIHttpProtocolHandler.h" #include "nsIJSContextStack.h" #include "nsIJSRuntimeService.h" @@ -9844,16 +9846,17 @@ nsNavigator::~nsNavigator() DOMCI_DATA(Navigator, nsNavigator) // QueryInterface implementation for nsNavigator NS_INTERFACE_MAP_BEGIN(nsNavigator) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNavigator) NS_INTERFACE_MAP_ENTRY(nsIDOMNavigator) NS_INTERFACE_MAP_ENTRY(nsIDOMClientInformation) NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorGeolocation) + NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorDesktopNotification) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Navigator) NS_INTERFACE_MAP_END NS_IMPL_ADDREF(nsNavigator) NS_IMPL_RELEASE(nsNavigator) @@ -10420,8 +10423,42 @@ NS_IMETHODIMP nsNavigator::GetGeolocatio return NS_ERROR_FAILURE; if (NS_FAILED(mGeolocation->Init(contentDOMWindow))) return NS_ERROR_FAILURE; NS_ADDREF(*_retval = mGeolocation); return NS_OK; } + + +//***************************************************************************** +// nsNavigator::nsIDOMNavigatorDesktopNotification +//***************************************************************************** + +NS_IMETHODIMP nsNavigator::GetMozNotification(nsIDOMDesktopNotificationCenter **aRetVal) +{ + NS_ENSURE_ARG_POINTER(aRetVal); + *aRetVal = nsnull; + + nsCOMPtr<nsPIDOMWindow> window(do_GetInterface(mDocShell)); + NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); + + nsCOMPtr<nsIDocument> document = do_GetInterface(mDocShell); + NS_ENSURE_TRUE(document, NS_ERROR_FAILURE); + + nsIScriptGlobalObject *sgo = document->GetScopeObject(); + NS_ENSURE_TRUE(sgo, NS_ERROR_FAILURE); + + nsIScriptContext *scx = sgo->GetContext(); + NS_ENSURE_TRUE(scx, NS_ERROR_FAILURE); + + nsRefPtr<nsDesktopNotificationCenter> notification = + new nsDesktopNotificationCenter(window->GetCurrentInnerWindow(), + scx); + + if (!notification) { + return NS_ERROR_FAILURE; + } + + *aRetVal = notification.forget().get(); + return NS_OK; +}
--- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -61,16 +61,17 @@ #include "nsIDocShellTreeItem.h" #include "nsIDOMClientInformation.h" #include "nsIDOMViewCSS.h" #include "nsIDOMEventTarget.h" #include "nsIDOM3EventTarget.h" #include "nsIDOMNSEventTarget.h" #include "nsIDOMNavigator.h" #include "nsIDOMNavigatorGeolocation.h" +#include "nsIDOMNavigatorDesktopNotification.h" #include "nsIDOMLocation.h" #include "nsIDOMWindowInternal.h" #include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestorUtils.h" #include "nsIDOMJSWindow.h" #include "nsIDOMChromeWindow.h" #include "nsIScriptGlobalObject.h" #include "nsIScriptContext.h" @@ -924,26 +925,28 @@ protected: //***************************************************************************** // nsNavigator: Script "navigator" object //***************************************************************************** class nsNavigator : public nsIDOMNavigator, public nsIDOMClientInformation, - public nsIDOMNavigatorGeolocation + public nsIDOMNavigatorGeolocation, + public nsIDOMNavigatorDesktopNotification { public: nsNavigator(nsIDocShell *aDocShell); virtual ~nsNavigator(); NS_DECL_ISUPPORTS NS_DECL_NSIDOMNAVIGATOR NS_DECL_NSIDOMCLIENTINFORMATION NS_DECL_NSIDOMNAVIGATORGEOLOCATION + NS_DECL_NSIDOMNAVIGATORDESKTOPNOTIFICATION void SetDocShell(nsIDocShell *aDocShell); nsIDocShell *GetDocShell() { return mDocShell; } void LoadingNewDocument();
--- a/dom/dom-config.mk +++ b/dom/dom-config.mk @@ -1,16 +1,17 @@ MODULE = dom DOM_SRCDIRS = \ dom/base \ dom/src/events \ dom/src/storage \ dom/src/offline \ dom/src/geolocation \ + dom/src/notification \ dom/src/threads \ content/xbl/src \ content/xul/document/src \ content/events/src \ content/base/src \ content/html/content/src \ content/html/document/src \ layout/generic \
new file mode 100644 --- /dev/null +++ b/dom/interfaces/notification/Makefile.in @@ -0,0 +1,54 @@ +# ***** 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 build system. +# +# The Initial Developer of the Original Code is Mozilla Foundation +# Portions created by the Initial Developer are Copyright (C) 2010 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Doug Turner <dougt@dougt.org> +# +# Alternatively, the contents of this file may be used under the terms of +# either 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 ***** + + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = dom +XPIDL_MODULE = dom_notification +GRE_MODULE = 1 + +XPIDLSRCS = nsIDOMNavigatorDesktopNotification.idl \ + nsIDOMDesktopNotification.idl \ + nsIDesktopNotificationPrompt.idl \ + $(NULL) + +include $(topsrcdir)/config/rules.mk
new file mode 100644 --- /dev/null +++ b/dom/interfaces/notification/nsIDOMDesktopNotification.idl @@ -0,0 +1,59 @@ +/* ***** 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 DesktopNotification. + * + * The Initial Developer of the Original Code is Mozilla Foundation + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Doug Turner <dougt@dougt.org> (Original Author) + * + * Alternatively, the contents of this file may be used under the terms of + * either 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 "domstubs.idl" + +interface nsIDOMEventListener; +interface nsIDOMDesktopNotification; + + +[scriptable, function, uuid(CCEA6185-0A3D-45AB-9058-1004DD4B8C50)] +interface nsIDOMDesktopNotificationCenter : nsISupports +{ + nsIDOMDesktopNotification createNotification(in DOMString title, + in DOMString description, + [optional] in DOMString iconURL); +}; + + +[scriptable, function, uuid(9131FD07-A7DB-4B3A-A98B-6D9F3746682F)] +interface nsIDOMDesktopNotification : nsISupports +{ + void show(); + + attribute nsIDOMEventListener onclick; + attribute nsIDOMEventListener onclose; +};
new file mode 100644 --- /dev/null +++ b/dom/interfaces/notification/nsIDOMNavigatorDesktopNotification.idl @@ -0,0 +1,47 @@ +/* ***** 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 DesktopNotification. + * + * The Initial Developer of the Original Code is Mozilla Foundation + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Doug Turner <dougt@dougt.org> (Original Author) + * + * Alternatively, the contents of this file may be used under the terms of + * either 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 "domstubs.idl" +interface nsIDOMDesktopNotificationCenter; + +/** + * Property that extends the navigator object. + */ +[scriptable, uuid(EC2E6E4F-2F65-439C-B6C6-27E89B03B348)] +interface nsIDOMNavigatorDesktopNotification : nsISupports +{ + readonly attribute nsIDOMDesktopNotificationCenter mozNotification; +};
new file mode 100644 --- /dev/null +++ b/dom/interfaces/notification/nsIDesktopNotificationPrompt.idl @@ -0,0 +1,79 @@ +/* ***** 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 DesktopNotification. + * + * The Initial Developer of the Original Code is Mozilla Foundation + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Doug Turner <dougt@dougt.org> (Original Author) + * + * Alternatively, the contents of this file may be used under the terms of + * either 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 "nsISupports.idl" + +interface nsIURI; +interface nsIDOMWindow; +interface nsIDesktopNotificationPrompt; + +%{C++ +/* + This must be implemented by embedders to be able to support DOM DesktopNotification. +*/ +#define NS_DOM_DESKTOP_NOTIFICATION_PROMPT_CONTRACTID "@mozilla.org/dom-desktop-notification/prompt;1" +%} + +/** + * Interface allows access to a notice and is passed to + * the nsIDesktopNotificationPrompt so that the application can approve + * or deny the request. + */ +[scriptable, uuid(A23B1236-9374-4591-97BF-5413FC4813A6)] +interface nsIDOMDesktopNotificationRequest : nsISupports { + + /* + * URI and window corresponding to where this request + * originated. + */ + readonly attribute nsIURI requestingURI; + readonly attribute nsIDOMWindow requestingWindow; + + void cancel(); + void allow(); +}; + +/** + * Interface provides a way for the application to handle + * the UI prompts associated with geo position. + */ +[scriptable, function, uuid(00D49D61-3D08-4AC6-B662-5E421F60CC2F)] +interface nsIDesktopNotificationPrompt : nsISupports { + /** + * Called when a request has been made to access desktop notifications + */ + void prompt(in nsIDOMDesktopNotificationRequest request); +};
--- a/dom/src/Makefile.in +++ b/dom/src/Makefile.in @@ -37,11 +37,11 @@ DEPTH = ../.. topsrcdir = @top_srcdir@ srcdir = @srcdir@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk -DIRS = jsurl events storage offline json geolocation threads +DIRS = jsurl events storage offline json geolocation threads notification include $(topsrcdir)/config/rules.mk
new file mode 100644 --- /dev/null +++ b/dom/src/notification/Makefile.in @@ -0,0 +1,66 @@ +# ***** 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 build system. +# +# The Initial Developer of the Original Code is Mozilla Foundation +# Portions created by the Initial Developer are Copyright (C) 2010 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Doug Turner <dougt@dougt.org> +# +# Alternatively, the contents of this file may be used under the terms of +# either 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 ***** + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = dom +LIBRARY_NAME = jsdomnotification_s +LIBXUL_LIBRARY = 1 + +# we don't want the shared lib, but we want to force the creation of a static lib. +FORCE_STATIC_LIB = 1 + +CPPSRCS = \ + nsDesktopNotification.cpp \ + $(NULL) + +EXTRA_DSO_LDOPTS = \ + $(MOZ_COMPONENT_LIBS) \ + $(NULL) + +LOCAL_INCLUDES = \ + -I$(topsrcdir)/dom/base \ + -I$(topsrcdir)/content/events/src \ + $(NULL) + +include $(topsrcdir)/config/rules.mk + +DEFINES += -D_IMPL_NS_LAYOUT
new file mode 100644 --- /dev/null +++ b/dom/src/notification/nsDesktopNotification.cpp @@ -0,0 +1,287 @@ +/* ***** 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 DesktopNotification. + * + * The Initial Developer of the Original Code is Mozilla Foundation + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Doug Turner <dougt@dougt.org> (Original Author) + * + * Alternatively, the contents of this file may be used under the terms of + * either 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 "nsDesktopNotification.h" + +class nsDesktopNotification; + +/* ------------------------------------------------------------------------ */ +/* NotificationRequestAllowEvent */ +/* For testing mode only. Allows us to send a "okay" request */ +/* ------------------------------------------------------------------------ */ +class NotificationRequestAllowEvent : public nsRunnable +{ +public: + NotificationRequestAllowEvent(nsDOMDesktopNotification* request) + : mRequest(request) + { + } + + NS_IMETHOD Run() + { + mRequest->PostDesktopNotification(); + mRequest = nsnull; + return NS_OK; + } + +private: + PRBool mAllow; + nsRefPtr<nsDOMDesktopNotification> mRequest; +}; + + + +/* ------------------------------------------------------------------------ */ +/* AlertServiceObserver */ +/* ------------------------------------------------------------------------ */ + +NS_IMPL_ISUPPORTS1(AlertServiceObserver, nsIObserver) + +/* ------------------------------------------------------------------------ */ +/* nsDesktopNotification */ +/* ------------------------------------------------------------------------ */ + +void +nsDOMDesktopNotification::PostDesktopNotification() +{ + nsCOMPtr<nsIAlertsService> alerts = do_GetService("@mozilla.org/alerts-service;1"); + if (!alerts) + return; + + if (!mObserver) + mObserver = new AlertServiceObserver(this); + + alerts->ShowAlertNotification(mIconURL, mTitle, mDescription, + true, + EmptyString(), + mObserver, + EmptyString()); +} + +DOMCI_DATA(DesktopNotification, nsDOMDesktopNotification) + +NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMDesktopNotification) + +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsDOMDesktopNotification, nsDOMEventTargetHelper) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnClickCallback) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnCloseCallback) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsDOMDesktopNotification, nsDOMEventTargetHelper) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnClickCallback) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnCloseCallback) +NS_IMPL_CYCLE_COLLECTION_UNLINK_END + +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsDOMDesktopNotification) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMDesktopNotification) + NS_INTERFACE_MAP_ENTRY(nsIDOMDesktopNotification) + NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DesktopNotification) +NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper) + +NS_IMPL_ADDREF_INHERITED(nsDOMDesktopNotification, nsDOMEventTargetHelper) +NS_IMPL_RELEASE_INHERITED(nsDOMDesktopNotification, nsDOMEventTargetHelper) + +nsDOMDesktopNotification::nsDOMDesktopNotification(const nsAString & title, + const nsAString & description, + const nsAString & iconURL, + nsPIDOMWindow *aWindow, + nsIScriptContext* aScriptContext, + nsIURI* uri) + : mTitle(title) + , mDescription(description) + , mIconURL(iconURL) + , mURI(uri) +{ + mOwner = aWindow; + mScriptContext = aScriptContext; +} + +nsDOMDesktopNotification::~nsDOMDesktopNotification() +{ + if (mObserver) { + mObserver->Disconnect(); + } +} + +void +nsDOMDesktopNotification::DispatchNotificationEvent(const nsString& aName) +{ + if (NS_FAILED(CheckInnerWindowCorrectness())) { + return; + } + + nsCOMPtr<nsIDOMEvent> event; + nsresult rv = NS_NewDOMEvent(getter_AddRefs(event), nsnull, nsnull); + if (NS_SUCCEEDED(rv)) { + // it doesn't bubble, and it isn't cancelable + rv = event->InitEvent(aName, PR_FALSE, PR_FALSE); + if (NS_SUCCEEDED(rv)) { + nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(event); + privateEvent->SetTrusted(PR_TRUE); + DispatchDOMEvent(nsnull, event, nsnull, nsnull); + } + } +} + +void +nsDOMDesktopNotification::HandleAlertServiceNotification(const char *aTopic) +{ + if (NS_FAILED(CheckInnerWindowCorrectness())) + return; + + if (!strcmp("alertclickcallback", aTopic)) { + DispatchNotificationEvent(NS_LITERAL_STRING("click")); + } else if (!strcmp("alertfinished", aTopic)) { + DispatchNotificationEvent(NS_LITERAL_STRING("close")); + } +} + +NS_IMETHODIMP +nsDOMDesktopNotification::Show() +{ + nsCOMPtr<nsIRunnable> request; + if (nsContentUtils::GetBoolPref("notification.prompt.testing", PR_FALSE) && + nsContentUtils::GetBoolPref("notification.prompt.testing.allow", PR_TRUE)) { + request = new NotificationRequestAllowEvent(this); + } else { + request = new nsDesktopNotificationRequest(this); + } + + NS_DispatchToMainThread(request); + return NS_OK; +} + +NS_IMETHODIMP +nsDOMDesktopNotification::GetOnclick(nsIDOMEventListener * *aOnclick) +{ + return GetInnerEventListener(mOnClickCallback, aOnclick); +} + +NS_IMETHODIMP nsDOMDesktopNotification::SetOnclick(nsIDOMEventListener * aOnclick) +{ + return RemoveAddEventListener(NS_LITERAL_STRING("click"), + mOnClickCallback, + aOnclick); +} + +NS_IMETHODIMP +nsDOMDesktopNotification::GetOnclose(nsIDOMEventListener * *aOnclose) +{ + return GetInnerEventListener(mOnCloseCallback, aOnclose); +} + +NS_IMETHODIMP nsDOMDesktopNotification::SetOnclose(nsIDOMEventListener * aOnclose) +{ + return RemoveAddEventListener(NS_LITERAL_STRING("close"), + mOnCloseCallback, + aOnclose); +} + +/* ------------------------------------------------------------------------ */ +/* nsDesktopNotificationCenter */ +/* ------------------------------------------------------------------------ */ + +DOMCI_DATA(DesktopNotificationCenter, nsDesktopNotificationCenter) + +NS_INTERFACE_MAP_BEGIN(nsDesktopNotificationCenter) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMDesktopNotificationCenter) + NS_INTERFACE_MAP_ENTRY(nsIDOMDesktopNotificationCenter) + NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DesktopNotificationCenter) +NS_INTERFACE_MAP_END + +NS_IMPL_ADDREF(nsDesktopNotificationCenter) +NS_IMPL_RELEASE(nsDesktopNotificationCenter) + +NS_IMETHODIMP +nsDesktopNotificationCenter::CreateNotification(const nsAString & title, + const nsAString & description, + const nsAString & iconURL, + nsIDOMDesktopNotification **aResult) +{ + nsRefPtr<nsIDOMDesktopNotification> notification = new nsDOMDesktopNotification(title, + description, + iconURL, + mOwner, + mScriptContext, + mURI); + notification.forget(aResult); + return NS_OK; +} + + +/* ------------------------------------------------------------------------ */ +/* nsDesktopNotificationRequest */ +/* ------------------------------------------------------------------------ */ + +NS_IMPL_ISUPPORTS2(nsDesktopNotificationRequest, + nsIDOMDesktopNotificationRequest, + nsIRunnable) + +NS_IMETHODIMP +nsDesktopNotificationRequest::GetRequestingURI(nsIURI * *aRequestingURI) +{ + if (!mDesktopNotification) + return NS_ERROR_NOT_INITIALIZED; + + NS_IF_ADDREF(*aRequestingURI = mDesktopNotification->mURI); + return NS_OK; +} + +NS_IMETHODIMP +nsDesktopNotificationRequest::GetRequestingWindow(nsIDOMWindow * *aRequestingWindow) +{ + if (!mDesktopNotification) + return NS_ERROR_NOT_INITIALIZED; + + nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(mDesktopNotification->mOwner); + NS_IF_ADDREF(*aRequestingWindow = window); + return NS_OK; +} + +NS_IMETHODIMP +nsDesktopNotificationRequest::Cancel() +{ + mDesktopNotification = nsnull; + return NS_OK; +} + +NS_IMETHODIMP +nsDesktopNotificationRequest::Allow() +{ + mDesktopNotification->PostDesktopNotification(); + mDesktopNotification = nsnull; + return NS_OK; +} +
new file mode 100644 --- /dev/null +++ b/dom/src/notification/nsDesktopNotification.h @@ -0,0 +1,197 @@ +/* ***** 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 DesktopNotification. + * + * The Initial Developer of the Original Code is Mozilla Foundation + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Doug Turner <dougt@dougt.org> (Original Author) + * + * Alternatively, the contents of this file may be used under the terms of + * either 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 nsDesktopNotification_h +#define nsDesktopNotification_h + +#include "nsDOMClassInfo.h" +#include "nsIJSContextStack.h" + +#include "nsIAlertsService.h" + +#include "nsIDOMDesktopNotification.h" +#include "nsIDOMEventTarget.h" +#include "nsIDesktopNotificationPrompt.h" + +#include "nsIObserver.h" +#include "nsString.h" +#include "nsWeakPtr.h" +#include "nsCycleCollectionParticipant.h" +#include "nsIDOMWindow.h" +#include "nsThreadUtils.h" + +#include "nsDOMEventTargetHelper.h" +#include "nsIPrivateDOMEvent.h" + +class AlertServiceObserver; + +/* + * nsDesktopNotificationCenter + * Object hangs off of the navigator object and hands out nsDOMDesktopNotification objects + */ +class nsDesktopNotificationCenter : public nsIDOMDesktopNotificationCenter +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIDOMDESKTOPNOTIFICATIONCENTER + + nsDesktopNotificationCenter(nsPIDOMWindow *aWindow, + nsIScriptContext* aScriptContext) + { + mOwner = aWindow; + mScriptContext = aScriptContext; + + // Grab the uri of the document + nsCOMPtr<nsIDOMDocument> domdoc; + mOwner->GetDocument(getter_AddRefs(domdoc)); + nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc); + doc->NodePrincipal()->GetURI(getter_AddRefs(mURI)); + } + + virtual ~nsDesktopNotificationCenter() + { + } + +private: + nsCOMPtr<nsPIDOMWindow> mOwner; + nsCOMPtr<nsIScriptContext> mScriptContext; + nsCOMPtr<nsIURI> mURI; +}; + + +class nsDOMDesktopNotification : public nsDOMEventTargetHelper, + public nsIDOMDesktopNotification +{ + friend class nsDesktopNotificationRequest; + +public: + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMDesktopNotification,nsDOMEventTargetHelper) + NS_DECL_NSIDOMDESKTOPNOTIFICATION + + nsDOMDesktopNotification(const nsAString & title, + const nsAString & description, + const nsAString & iconURL, + nsPIDOMWindow *aWindow, + nsIScriptContext* aScriptContext, + nsIURI* uri); + + virtual ~nsDOMDesktopNotification(); + + /* + * PostDesktopNotification + * Uses alert service to display a notification + */ + void PostDesktopNotification(); + + /* + * Creates and dispatches a dom event of type aName + */ + void DispatchNotificationEvent(const nsString& aName); + + void HandleAlertServiceNotification(const char *aTopic); + +protected: + + nsString mTitle; + nsString mDescription; + nsString mIconURL; + + nsRefPtr<nsDOMEventListenerWrapper> mOnClickCallback; + nsRefPtr<nsDOMEventListenerWrapper> mOnCloseCallback; + + nsRefPtr<AlertServiceObserver> mObserver; + nsCOMPtr<nsIURI> mURI; +}; + +/* + * Simple Request + */ +class nsDesktopNotificationRequest : public nsIDOMDesktopNotificationRequest, + public nsRunnable +{ + public: + NS_DECL_ISUPPORTS + NS_DECL_NSIDOMDESKTOPNOTIFICATIONREQUEST + + nsDesktopNotificationRequest(nsDOMDesktopNotification* notification) + : mDesktopNotification(notification) {} + + NS_IMETHOD Run() + { + nsCOMPtr<nsIDesktopNotificationPrompt> prompt = + do_GetService(NS_DOM_DESKTOP_NOTIFICATION_PROMPT_CONTRACTID); + if (prompt) { + prompt->Prompt(this); + } + return NS_OK; + } + + ~nsDesktopNotificationRequest() + { + } + + nsRefPtr<nsDOMDesktopNotification> mDesktopNotification; +}; + +class AlertServiceObserver: public nsIObserver +{ + public: + NS_DECL_ISUPPORTS + + AlertServiceObserver(nsDOMDesktopNotification* notification) + : mNotification(notification) {} + + virtual ~AlertServiceObserver() {} + + void Disconnect() { mNotification = nsnull; } + + NS_IMETHODIMP + Observe(nsISupports *aSubject, + const char *aTopic, + const PRUnichar *aData) + { + // forward to parent + if (mNotification) + mNotification->HandleAlertServiceNotification(aTopic); + return NS_OK; + }; + + private: + nsDOMDesktopNotification* mNotification; +}; + +#endif /* nsDesktopNotification_h */
--- a/layout/build/Makefile.in +++ b/layout/build/Makefile.in @@ -105,16 +105,17 @@ SHARED_LIBRARY_LIBS = \ $(DEPTH)/view/src/$(LIB_PREFIX)gkview_s.$(LIB_SUFFIX) \ $(DEPTH)/dom/base/$(LIB_PREFIX)jsdombase_s.$(LIB_SUFFIX) \ $(DEPTH)/dom/src/events/$(LIB_PREFIX)jsdomevents_s.$(LIB_SUFFIX) \ $(DEPTH)/dom/src/json/$(LIB_PREFIX)json_s.$(LIB_SUFFIX) \ $(DEPTH)/dom/src/jsurl/$(LIB_PREFIX)jsurl_s.$(LIB_SUFFIX) \ $(DEPTH)/dom/src/storage/$(LIB_PREFIX)jsdomstorage_s.$(LIB_SUFFIX) \ $(DEPTH)/dom/src/offline/$(LIB_PREFIX)jsdomoffline_s.$(LIB_SUFFIX) \ $(DEPTH)/dom/src/geolocation/$(LIB_PREFIX)jsdomgeolocation_s.$(LIB_SUFFIX) \ + $(DEPTH)/dom/src/notification/$(LIB_PREFIX)jsdomnotification_s.$(LIB_SUFFIX) \ $(DEPTH)/dom/system/$(LIB_PREFIX)domsystem_s.$(LIB_SUFFIX) \ $(DEPTH)/dom/src/threads/$(LIB_PREFIX)domthreads_s.$(LIB_SUFFIX) \ $(DEPTH)/dom/indexedDB/$(LIB_PREFIX)dom_indexeddb_s.$(LIB_SUFFIX) \ $(DEPTH)/editor/libeditor/text/$(LIB_PREFIX)texteditor_s.$(LIB_SUFFIX) \ $(DEPTH)/editor/libeditor/base/$(LIB_PREFIX)editorbase_s.$(LIB_SUFFIX) \ $(DEPTH)/parser/html/$(LIB_PREFIX)html5p_s.$(LIB_SUFFIX) \ $(DEPTH)/caps/src/$(LIB_PREFIX)caps_s.$(LIB_SUFFIX) \ $(NULL)