See also: API Specification for notifications
Design for desktop notifications
The Desktop Notifications API allows script to request a small toast to appear on the desktop of the user. The contents of the toast can either be specified as iconUrl/title/text strings, or as a URL to a remote resource which contains the contents of the toast.
In Chromium/WebKit, the API is provided to scripts in WebCore by injecting into WebKit (via the Chrome/ChromeClient objects) an implementation of a NotificationPresenter interface, which contains methods to show and cancel toasts, as well as to check and request permission to show toasts. These calls flow via IPC from the renderer process to the browser process, where the toasts are actually created on the screen using a small HtmlView.
For this reason, the renderer process's NotificationPresenter keeps a map of its notification-id values to Notification object pointers; if a Notification pointer goes out of scope, the NotificationPresenter is called and removes that pointer from the map. If the browser subsequently calls with an event on that id it will be ignored.
If a renderer process crashes, the notifications will persist in the browser process and on the screen, but events intended to reach that renderer process will be filtered out in the browser when normal process-lookup fails.
Desktop notification permission is assigned on an origin basis. Chromium stores two PrefLists in the user's profile to accomplish this: OriginsAllowed and OriginsDenied. A script may request permission on a given origin through a JS API which is routed through the NotificationPresenter interface, into the browser process via IPC, and results in an InfoBar offering "Allow" or "Deny". The origin is then stored in the correct PrefList.
When a notification is to be shown, permission must first be checked: this is handled in the same way, invoking the NotificationPresenter in the renderer, jumping via synchronous IPC to the browser, checking the PrefLists and returning.
The same API is available to worker processes and mirrors the behavior for renderers, with IPC messages using a "worker" flag for correct routing of event feedback.
On Mac and Linux, we considered to use 3rd party notification libraries, but have determined that having a unified HTML-capable interface is a better course, so Chrome will render HTML notifications on these platforms as well.
Presently the desktop notifications API will be disabled by default, but can be enabled with the command-line switch --enable-desktop-notifications.
Browser Process Object Flow
v (receives IPC from renderer)
v (object owned by ProfileImpl which handles requests for notifications, also "upcasts" text notification to HTML based on template)
v posts a task
v (global object owned by BrowserProcess which manages the space on the desktop for notification balloons)
v (set of balloons on the screen, handles animations as balloons are added and removed)
(mini window, draws notification chrome and contains HTML contents view, receives "dismiss" click from the user)
Renderer Process Object Flow
NotificationCenter object in WebCore
v (returned by DOMWindow::webkitNotifications()).
v V8 bindings
v (WebKit API object which adapts between WebCore::NotificationPresenter interface and matching WebKit API interface)
(implements WebKit::WebNotificationPresenter interface, object owned by WebViewDelegate implementation; sends IPC messages to browser, allocates IDs, stores map of ID->Notification objects)
v (receives IPC message from browser process regarding an event)
v (post task onto main thread: lookup in notification-id->Notification object map, discard if invalid)
WebKit::WebNotification (PIMPL wrapper in WebKit API for WebCore::Notification object)
v (invoke event listener)
Notification in WebCore