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

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

Issue 12274002: Fixing Geolocation on Firefox (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Adding manual test Created 7 years, 10 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
« tests/html/html.status ('K') | « tools/dom/scripts/systemhtml.py ('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_Geolocation.darttemplate
diff --git a/tools/dom/templates/html/impl/impl_Geolocation.darttemplate b/tools/dom/templates/html/impl/impl_Geolocation.darttemplate
new file mode 100644
index 0000000000000000000000000000000000000000..94579191173137e7f08eec9a0b8cdac73d853092
--- /dev/null
+++ b/tools/dom/templates/html/impl/impl_Geolocation.darttemplate
@@ -0,0 +1,103 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+part of $LIBRARYNAME;
+
+@DocsEditable
+$(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
+
+ @DomName('Geolocation.getCurrentPosition')
+ Future<Geoposition> getCurrentPosition({bool enableHighAccuracy,
+ Duration timeout, Duration maximumAge}) {
+ var options = {};
+ if (enableHighAccuracy != null) {
+ options['enableHighAccuracy'] = enableHighAccuracy;
+ }
+ if (timeout != null) {
+ options['timeout'] = timeout.inMilliseconds;
+ }
+ if (maximumAge != null) {
+ options['maximumAge'] = maximumAge.inMilliseconds;
+ }
+ var completer = new Completer<Geoposition>();
+ try {
+ $dom_getCurrentPosition(
+ (position) {
+ completer.complete(_ensurePosition(position));
+ },
+ (error) {
+ completer.completeError(error);
+ },
+ options);
+ } catch (e, stacktrace) {
+ completer.completeError(e, stacktrace);
+ }
+ return completer.future;
+ }
+
+ @DomName('Geolocation.watchPosition')
+ Stream<Geoposition> watchPosition({bool enableHighAccuracy,
+ Duration timeout, Duration maximumAge}) {
+
+ var options = {};
+ if (enableHighAccuracy != null) {
+ options['enableHighAccuracy'] = enableHighAccuracy;
+ }
+ if (timeout != null) {
+ options['timeout'] = timeout.inMilliseconds;
+ }
+ if (maximumAge != null) {
+ options['maximumAge'] = maximumAge.inMilliseconds;
+ }
+
+ int watchId;
+ var controller;
+ controller = new StreamController<Geoposition>(
+ onSubscriptionStateChange: () {
+ if (controller.hasSubscribers) {
+ assert(watchId == null);
+ watchId = $dom_watchPosition(
+ (position) {
+ controller.add(_ensurePosition(position));
+ },
+ (error) {
+ controller.signalError(error);
+ },
+ options);
+ } else {
+ assert(watchId != null);
+ $dom_clearWatch(watchId);
+ }
+ });
+
+ return controller.stream;
+ }
+
+ Geoposition _ensurePosition(domPosition) {
+ try {
+ // Firefox may throw on this.
+ if (domPosition is Geoposition) {
+ return domPosition;
+ }
+ } catch(e) {}
+ return new _GeopositionWrapper(domPosition);
+ }
+$!MEMBERS}
+
+$if DART2JS
+/**
+ * Wrapper for FireFox- it returns an object which we cannot map correctly.
Emily Fortuna 2013/02/19 19:53:00 nit: "Firefox"
+ * Basically FireFox was returning a [xpconnect wrapped nsIDOMGeoPosition] but
+ * which has further oddities.
+ */
+class _GeopositionWrapper implements Geoposition {
+ var _ptr;
+ _GeopositionWrapper(this._ptr);
+
+ Coordinates get coords => JS('Coordinates', '#.coords', _ptr);
+ int get timestamp => JS('int', '#.timestamp', _ptr);
+}
+$endif
+
+
« tests/html/html.status ('K') | « tools/dom/scripts/systemhtml.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698