1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 var position_initialized
= false;
9 var position_updated
= false;
11 function sendString(string
) {
12 window
.domAutomationController
.send(string
);
14 function geoSuccessCallback(position
) {
15 last_position
= position
;
17 function geoErrorCallback(error
) {
20 function geoSuccessCallbackWithResponse(position
) {
21 last_position
= position
;
23 if (!position_initialized
) { // First time callback invoked.
24 position_initialized
= true;
25 sendString('request-callback-success');
29 if (!position_updated
) { // Second time callback invoked.
30 position_updated
= true;
31 sendString('geoposition-updated');
34 function geoErrorCallbackWithResponse(error
) {
36 sendString('request-callback-error');
39 watch_id
= navigator
.geolocation
.watchPosition(
40 geoSuccessCallback
, geoErrorCallback
,
41 {maximumAge
:600000, timeout
:100000, enableHighAccuracy
:true});
44 function geoStartWithAsyncResponse() {
45 navigator
.geolocation
.watchPosition(
46 geoSuccessCallbackWithResponse
, geoErrorCallbackWithResponse
,
47 {maximumAge
:600000, timeout
:100000, enableHighAccuracy
:true});
49 function geoStartWithSyncResponse() {
50 navigator
.geolocation
.watchPosition(
51 geoSuccessCallback
, geoErrorCallback
,
52 {maximumAge
:600000, timeout
:100000, enableHighAccuracy
:true});
53 sendString('requested');
55 function checkIfGeopositionUpdated() {
57 sendString('geoposition-updated');
59 function geoGetLastPositionLatitude() {
60 return "" + last_position
.coords
.latitude
;
62 function geoGetLastPositionLongitude() {
63 return "" + last_position
.coords
.longitude
;
65 function geoGetLastError() {
66 return "" + (last_error
? last_error
.code
: 0);
68 function geoAccessNavigatorGeolocation() {
69 return "" + typeof(navigator
.geolocation
);