Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(821)

Unified Diff: tools/dom/templates/html/impl/impl_Window.darttemplate

Issue 12218111: Allowing Window.onBeforeUnload event to work properly. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/dom/templates/html/dartium/html_dartium.darttemplate ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/dom/templates/html/impl/impl_Window.darttemplate
diff --git a/tools/dom/templates/html/impl/impl_Window.darttemplate b/tools/dom/templates/html/impl/impl_Window.darttemplate
index 2f1c19438ab4c468e5fbda46b2cdff58ddf05a0b..74081311ee56338579ba05ecdf29743a739491aa 100644
--- a/tools/dom/templates/html/impl/impl_Window.darttemplate
+++ b/tools/dom/templates/html/impl/impl_Window.darttemplate
@@ -231,10 +231,76 @@ $endif
* lasting storage. This storage cannot be freed without the user's
* permission. Returns a [Future] whose value stores a reference to the
* sandboxed file system for use. Because the file system is sandboxed,
- * applications cannot access file systems created in other web pages.
+ * applications cannot access file systems created in other web pages.
*/
Future<FileSystem> requestFileSystem(int size, {bool persistent: false}) {
return _requestFileSystem(persistent? 1 : 0, size);
}
$!MEMBERS
+
+ @DomName('DOMWindow.beforeunloadEvent')
+ @DocsEditable
+ static const EventStreamProvider<BeforeUnloadEvent> beforeUnloadEvent =
+ const _BeforeUnloadEventStreamProvider('beforeunload');
+
+ @DomName('DOMWindow.onbeforeunload')
+ @DocsEditable
+ Stream<Event> get onBeforeUnload => beforeUnloadEvent.forTarget(this);
+}
+
+/**
+ * Event object that is fired before the window is closed.
+ *
+ * The standard window close behavior can be prevented by setting the
+ * [returnValue]. This will display a dialog to the user confirming that they
+ * want to close the page.
+ */
+abstract class BeforeUnloadEvent implements Event {
+ /**
+ * If set to a non-null value, a dialog will be presented to the user
+ * confirming that they want to close the page.
+ */
+ String returnValue;
+}
+
+class _BeforeUnloadEvent extends _WrappedEvent implements BeforeUnloadEvent {
+ String _returnValue;
+
+ _BeforeUnloadEvent(Event base): super(base);
+
+ String get returnValue => _returnValue;
+
+ void set returnValue(String value) {
+ _returnValue = value;
+$if DART2JS
+ // FF and IE use the value as the return value, Chrome will return this from
+ // the event callback function.
+ if (JS('bool', '("returnValue" in #)', _base)) {
+ JS('void', '#.returnValue = #', _base, value);
+ }
+$endif
+ }
+}
+
+class _BeforeUnloadEventStreamProvider implements
+ EventStreamProvider<BeforeUnloadEvent> {
+ final String _eventType;
+
+ const _BeforeUnloadEventStreamProvider(this._eventType);
+
+ Stream<BeforeUnloadEvent> forTarget(EventTarget e, {bool useCapture: false}) {
+ var controller = new StreamController.broadcast();
+ var stream = new _EventStream(e, _eventType, useCapture);
+ stream.listen((event) {
+ var wrapped = new _BeforeUnloadEvent(event);
+ controller.add(wrapped);
+ return wrapped.returnValue;
+ });
+
+ return controller.stream;
+ }
+
+ String getEventType(EventTarget target) {
+ return _eventType;
+ }
}
« no previous file with comments | « tools/dom/templates/html/dartium/html_dartium.darttemplate ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698