- From: Justin DeWitt <dewittj@google.com>
- Date: Mon, 10 Jun 2013 10:16:17 -0700
- To: WG <public-web-notification@w3.org>
- Message-ID: <CAE54qEZFPHXYR2b-DAWNwjopQg6cLNVhN3vjG3SGXaoCL4uJ1Q@mail.gmail.com>
Hi, In continuing to read the spec, I came across the example in Section 6.1[1] where the notification is created using the constructor and then event handlers are attached in the next few lines. Doesn't this introduce a race between the JS context and the user agent? I could imagine this causing an issue if the notification were shown immediately, since the "show" event could fire before the "onshow" event handler was attached. Can we update the constructor to accept the various event handlers in the options dictionary? I suppose it would be something like updating the API section [2] to include the following text (steps 9-12 are new): The Notification(title, options) constructor must run these steps: 1. Let notification be a new notification<https://dvcs.w3.org/hg/notifications/raw-file/tip/Overview.html#concept-notification> represented by a Notification<https://dvcs.w3.org/hg/notifications/raw-file/tip/Overview.html#notification> object. 2. Set notification's title<https://dvcs.w3.org/hg/notifications/raw-file/tip/Overview.html#title> to title. 3. Set notification's direction<https://dvcs.w3.org/hg/notifications/raw-file/tip/Overview.html#direction> to options's dir. 4. If options's lang is a valid BCP 47 language tag, or the empty string, set notification's language<https://dvcs.w3.org/hg/notifications/raw-file/tip/Overview.html#language> to options's lang, or set it to the empty string otherwise. [LANG]<https://dvcs.w3.org/hg/notifications/raw-file/tip/Overview.html#refsLANG> 5. Set notifications's origin<https://dvcs.w3.org/hg/notifications/raw-file/tip/Overview.html#origin> to the current origin<https://dvcs.w3.org/hg/notifications/raw-file/tip/Overview.html#origin> . 6. If options's body is present, set notification's body<https://dvcs.w3.org/hg/notifications/raw-file/tip/Overview.html#body> to body. 7. If options's tag is present, set notification's tag<https://dvcs.w3.org/hg/notifications/raw-file/tip/Overview.html#tag> to tag. 8. If options's icon is present, resolve<http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#resolve-a-url> icon against the entry script<http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#entry-script> 's base URL<http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#script's-base-url>, and if that does not fail, set notification's icon URL<https://dvcs.w3.org/hg/notifications/raw-file/tip/Overview.html#icon-url> to the resulting absolute URL<http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#absolute-url>. (Otherwise icon URL<https://dvcs.w3.org/hg/notifications/raw-file/tip/Overview.html#icon-url> is not set.) 9. If *options*'s onshow is present, set *notification*'s onshow<https://dvcs.w3.org/hg/notifications/raw-file/tip/Overview.html#handler-onshow>handler to onshow. 10. If *options*'s onclose is present, set *notification*'s onclose<https://dvcs.w3.org/hg/notifications/raw-file/tip/Overview.html#handler-onclose>handler to onclose. 11. If *options*'s onerror is present, set *notification*'s onerror<https://dvcs.w3.org/hg/notifications/raw-file/tip/Overview.html#handler-onerror>handler to onerror. 12. If *options*'s onclick is present, set *notification*'s onclick<https://dvcs.w3.org/hg/notifications/raw-file/tip/Overview.html#handler-onclick>handler to onclick. 13. Return notification, but continue running these steps asynchronouusly. 14. If the notification platform supports icons, the user agent may start fetching<http://www.whatwg.org/specs/web-apps/current-work/multipage/fetching-resources.html#fetch> notification's icon URL<https://dvcs.w3.org/hg/notifications/raw-file/tip/Overview.html#icon-url> at this point, if icon URL<https://dvcs.w3.org/hg/notifications/raw-file/tip/Overview.html#icon-url> is set. 15. Run the show steps<https://dvcs.w3.org/hg/notifications/raw-file/tip/Overview.html#show-steps> for notification. Alternately, there could be a handlers object in *options* that contains all the event handlers. Justin [1] https://dvcs.w3.org/hg/notifications/raw-file/tip/Overview.html#using-events [2] https://dvcs.w3.org/hg/notifications/raw-file/tip/Overview.html#api
Received on Monday, 10 June 2013 17:16:44 UTC