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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« tests/html/html.status ('K') | « tools/dom/scripts/systemhtml.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 part of $LIBRARYNAME;
6
7 @DocsEditable
8 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
9
10 @DomName('Geolocation.getCurrentPosition')
11 Future<Geoposition> getCurrentPosition({bool enableHighAccuracy,
12 Duration timeout, Duration maximumAge}) {
13 var options = {};
14 if (enableHighAccuracy != null) {
15 options['enableHighAccuracy'] = enableHighAccuracy;
16 }
17 if (timeout != null) {
18 options['timeout'] = timeout.inMilliseconds;
19 }
20 if (maximumAge != null) {
21 options['maximumAge'] = maximumAge.inMilliseconds;
22 }
23 var completer = new Completer<Geoposition>();
24 try {
25 $dom_getCurrentPosition(
26 (position) {
27 completer.complete(_ensurePosition(position));
28 },
29 (error) {
30 completer.completeError(error);
31 },
32 options);
33 } catch (e, stacktrace) {
34 completer.completeError(e, stacktrace);
35 }
36 return completer.future;
37 }
38
39 @DomName('Geolocation.watchPosition')
40 Stream<Geoposition> watchPosition({bool enableHighAccuracy,
41 Duration timeout, Duration maximumAge}) {
42
43 var options = {};
44 if (enableHighAccuracy != null) {
45 options['enableHighAccuracy'] = enableHighAccuracy;
46 }
47 if (timeout != null) {
48 options['timeout'] = timeout.inMilliseconds;
49 }
50 if (maximumAge != null) {
51 options['maximumAge'] = maximumAge.inMilliseconds;
52 }
53
54 int watchId;
55 var controller;
56 controller = new StreamController<Geoposition>(
57 onSubscriptionStateChange: () {
58 if (controller.hasSubscribers) {
59 assert(watchId == null);
60 watchId = $dom_watchPosition(
61 (position) {
62 controller.add(_ensurePosition(position));
63 },
64 (error) {
65 controller.signalError(error);
66 },
67 options);
68 } else {
69 assert(watchId != null);
70 $dom_clearWatch(watchId);
71 }
72 });
73
74 return controller.stream;
75 }
76
77 Geoposition _ensurePosition(domPosition) {
78 try {
79 // Firefox may throw on this.
80 if (domPosition is Geoposition) {
81 return domPosition;
82 }
83 } catch(e) {}
84 return new _GeopositionWrapper(domPosition);
85 }
86 $!MEMBERS}
87
88 $if DART2JS
89 /**
90 * Wrapper for FireFox- it returns an object which we cannot map correctly.
Emily Fortuna 2013/02/19 19:53:00 nit: "Firefox"
91 * Basically FireFox was returning a [xpconnect wrapped nsIDOMGeoPosition] but
92 * which has further oddities.
93 */
94 class _GeopositionWrapper implements Geoposition {
95 var _ptr;
96 _GeopositionWrapper(this._ptr);
97
98 Coordinates get coords => JS('Coordinates', '#.coords', _ptr);
99 int get timestamp => JS('int', '#.timestamp', _ptr);
100 }
101 $endif
102
103
OLDNEW
« 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