Re-schedule the callback into original browser thread.
authorJaroslav Tulach <jtulach@netbeans.org>
Mon, 01 Sep 2014 15:36:39 +0200
changeset 85022dca1d9c7b2
parent 849 823748ec4342
child 851 69ed96e7f41b
Re-schedule the callback into original browser thread.
geo/src/main/java/org/netbeans/html/geo/spi/GLProvider.java
     1.1 --- a/geo/src/main/java/org/netbeans/html/geo/spi/GLProvider.java	Thu Aug 28 14:27:34 2014 +0200
     1.2 +++ b/geo/src/main/java/org/netbeans/html/geo/spi/GLProvider.java	Mon Sep 01 15:36:39 2014 +0200
     1.3 @@ -154,6 +154,10 @@
     1.4       * a failure (when <code>ex</code> argument is non-<code>null</code>).
     1.5       * A successful requests leads in a call to {@link Handle#onLocation(net.java.html.geo.Position)}
     1.6       * while an error report leads to a call to {@link Handle#onError(java.lang.Exception)}.
     1.7 +     * The actual call is sent to {@link BrwsrCtx#execute(java.lang.Runnable)} of
     1.8 +     * context recorded when the {@link Query} was created to guarantee it
     1.9 +     * happens on the right browser thread - however it may happen "later"
    1.10 +     * when this method has already finished.
    1.11       * 
    1.12       * @param c the query as provided when {@link #start(org.netbeans.html.geo.spi.GLProvider.Query) starting}
    1.13       *   the request
    1.14 @@ -166,15 +170,20 @@
    1.15       *   when one notifies the successfully obtained <code>position</code>
    1.16       */
    1.17      protected final void callback(
    1.18 -        Query c,
    1.19 -        long timestamp, Coords position,
    1.20 -        Exception ex
    1.21 +        final Query c,
    1.22 +        final long timestamp, final Coords position,
    1.23 +        final Exception ex
    1.24      ) {
    1.25 -        if (ex == null) {
    1.26 -            c.peer.onLocation(new Position(timestamp, new CoordImpl<Coords>(position, this)));
    1.27 -        } else {
    1.28 -            c.peer.onError(ex);
    1.29 -        }
    1.30 +        c.ctx.execute(new Runnable() {
    1.31 +            @Override
    1.32 +            public void run() {
    1.33 +                if (ex == null) {
    1.34 +                    c.peer.onLocation(new Position(timestamp, new CoordImpl<Coords>(position, GLProvider.this)));
    1.35 +                } else {
    1.36 +                    c.peer.onError(ex);
    1.37 +                }
    1.38 +            }
    1.39 +        });
    1.40      }
    1.41  
    1.42      /** Extracts value for {@link Coordinates#getLatitude()}.
    1.43 @@ -240,6 +249,7 @@
    1.44          private final boolean enableHighAccuracy;
    1.45          private final long timeout;
    1.46          private final long maximumAge;
    1.47 +        private final BrwsrCtx ctx;
    1.48          final Accessor peer;
    1.49  
    1.50          Query(Accessor peer, boolean oneTime, boolean enableHighAccuracy, long timeout, long maximumAge) {
    1.51 @@ -248,6 +258,7 @@
    1.52              this.enableHighAccuracy = enableHighAccuracy;
    1.53              this.timeout = timeout;
    1.54              this.maximumAge = maximumAge;
    1.55 +            ctx = BrwsrCtx.findDefault(Query.class);
    1.56          }
    1.57          
    1.58          /**