| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | |
| 5 /** | 4 /** |
| 6 * @constructor | 5 * @unrestricted |
| 7 * @param {number} latitude | |
| 8 * @param {number} longitude | |
| 9 * @param {boolean} error | |
| 10 */ | 6 */ |
| 11 WebInspector.Geolocation = function(latitude, longitude, error) | 7 WebInspector.Geolocation = class { |
| 12 { | 8 /** |
| 9 * @param {number} latitude |
| 10 * @param {number} longitude |
| 11 * @param {boolean} error |
| 12 */ |
| 13 constructor(latitude, longitude, error) { |
| 13 this.latitude = latitude; | 14 this.latitude = latitude; |
| 14 this.longitude = longitude; | 15 this.longitude = longitude; |
| 15 this.error = error; | 16 this.error = error; |
| 16 }; | 17 } |
| 17 | 18 |
| 18 WebInspector.Geolocation.prototype = { | 19 /** |
| 19 /** | 20 * @return {!WebInspector.Geolocation} |
| 20 * @return {string} | 21 */ |
| 21 */ | 22 static parseSetting(value) { |
| 22 toSetting: function() | |
| 23 { | |
| 24 return (typeof this.latitude === "number" && typeof this.longitude === "
number" && typeof this.error === "string") ? this.latitude + "@" + this.longitud
e + ":" + this.error : ""; | |
| 25 }, | |
| 26 | |
| 27 apply: function() | |
| 28 { | |
| 29 for (var target of WebInspector.targetManager.targets(WebInspector.Targe
t.Capability.Browser)) { | |
| 30 if (this.error) | |
| 31 target.emulationAgent().setGeolocationOverride(); | |
| 32 else | |
| 33 target.emulationAgent().setGeolocationOverride(this.latitude, th
is.longitude, WebInspector.Geolocation.DefaultMockAccuracy); | |
| 34 } | |
| 35 }, | |
| 36 | |
| 37 clear: function() | |
| 38 { | |
| 39 for (var target of WebInspector.targetManager.targets(WebInspector.Targe
t.Capability.Browser)) | |
| 40 target.emulationAgent().clearGeolocationOverride(); | |
| 41 } | |
| 42 }; | |
| 43 | |
| 44 /** | |
| 45 * @return {!WebInspector.Geolocation} | |
| 46 */ | |
| 47 WebInspector.Geolocation.parseSetting = function(value) | |
| 48 { | |
| 49 if (value) { | 23 if (value) { |
| 50 var splitError = value.split(":"); | 24 var splitError = value.split(':'); |
| 51 if (splitError.length === 2) { | 25 if (splitError.length === 2) { |
| 52 var splitPosition = splitError[0].split("@"); | 26 var splitPosition = splitError[0].split('@'); |
| 53 if (splitPosition.length === 2) | 27 if (splitPosition.length === 2) |
| 54 return new WebInspector.Geolocation(parseFloat(splitPosition[0])
, parseFloat(splitPosition[1]), splitError[1]); | 28 return new WebInspector.Geolocation( |
| 55 } | 29 parseFloat(splitPosition[0]), parseFloat(splitPosition[1]), splitE
rror[1]); |
| 30 } |
| 56 } | 31 } |
| 57 return new WebInspector.Geolocation(0, 0, false); | 32 return new WebInspector.Geolocation(0, 0, false); |
| 58 }; | 33 } |
| 59 | 34 |
| 60 /** | 35 /** |
| 61 * @param {string} latitudeString | 36 * @param {string} latitudeString |
| 62 * @param {string} longitudeString | 37 * @param {string} longitudeString |
| 63 * @param {string} errorStatus | 38 * @param {string} errorStatus |
| 64 * @return {?WebInspector.Geolocation} | 39 * @return {?WebInspector.Geolocation} |
| 65 */ | 40 */ |
| 66 WebInspector.Geolocation.parseUserInput = function(latitudeString, longitudeStri
ng, errorStatus) | 41 static parseUserInput(latitudeString, longitudeString, errorStatus) { |
| 67 { | |
| 68 if (!latitudeString && !longitudeString) | 42 if (!latitudeString && !longitudeString) |
| 69 return null; | 43 return null; |
| 70 | 44 |
| 71 var isLatitudeValid = WebInspector.Geolocation.latitudeValidator(latitudeStr
ing); | 45 var isLatitudeValid = WebInspector.Geolocation.latitudeValidator(latitudeStr
ing); |
| 72 var isLongitudeValid = WebInspector.Geolocation.longitudeValidator(longitude
String); | 46 var isLongitudeValid = WebInspector.Geolocation.longitudeValidator(longitude
String); |
| 73 | 47 |
| 74 if (!isLatitudeValid && !isLongitudeValid) | 48 if (!isLatitudeValid && !isLongitudeValid) |
| 75 return null; | 49 return null; |
| 76 | 50 |
| 77 var latitude = isLatitudeValid ? parseFloat(latitudeString) : -1; | 51 var latitude = isLatitudeValid ? parseFloat(latitudeString) : -1; |
| 78 var longitude = isLongitudeValid ? parseFloat(longitudeString) : -1; | 52 var longitude = isLongitudeValid ? parseFloat(longitudeString) : -1; |
| 79 return new WebInspector.Geolocation(latitude, longitude, !!errorStatus); | 53 return new WebInspector.Geolocation(latitude, longitude, !!errorStatus); |
| 54 } |
| 55 |
| 56 /** |
| 57 * @param {string} value |
| 58 * @return {boolean} |
| 59 */ |
| 60 static latitudeValidator(value) { |
| 61 var numValue = parseFloat(value); |
| 62 return /^([+-]?[\d]+(\.\d+)?|[+-]?\.\d+)$/.test(value) && numValue >= -90 &&
numValue <= 90; |
| 63 } |
| 64 |
| 65 /** |
| 66 * @param {string} value |
| 67 * @return {boolean} |
| 68 */ |
| 69 static longitudeValidator(value) { |
| 70 var numValue = parseFloat(value); |
| 71 return /^([+-]?[\d]+(\.\d+)?|[+-]?\.\d+)$/.test(value) && numValue >= -180 &
& numValue <= 180; |
| 72 } |
| 73 |
| 74 /** |
| 75 * @return {string} |
| 76 */ |
| 77 toSetting() { |
| 78 return (typeof this.latitude === 'number' && typeof this.longitude === 'numb
er' && typeof this.error === 'string') ? |
| 79 this.latitude + '@' + this.longitude + ':' + this.error : |
| 80 ''; |
| 81 } |
| 82 |
| 83 apply() { |
| 84 for (var target of WebInspector.targetManager.targets(WebInspector.Target.Ca
pability.Browser)) { |
| 85 if (this.error) |
| 86 target.emulationAgent().setGeolocationOverride(); |
| 87 else |
| 88 target.emulationAgent().setGeolocationOverride( |
| 89 this.latitude, this.longitude, WebInspector.Geolocation.DefaultMockA
ccuracy); |
| 90 } |
| 91 } |
| 92 |
| 93 clear() { |
| 94 for (var target of WebInspector.targetManager.targets(WebInspector.Target.Ca
pability.Browser)) |
| 95 target.emulationAgent().clearGeolocationOverride(); |
| 96 } |
| 80 }; | 97 }; |
| 81 | 98 |
| 82 /** | |
| 83 * @param {string} value | |
| 84 * @return {boolean} | |
| 85 */ | |
| 86 WebInspector.Geolocation.latitudeValidator = function(value) | |
| 87 { | |
| 88 var numValue = parseFloat(value); | |
| 89 return /^([+-]?[\d]+(\.\d+)?|[+-]?\.\d+)$/.test(value) && numValue >= -90 &&
numValue <= 90; | |
| 90 }; | |
| 91 | |
| 92 /** | |
| 93 * @param {string} value | |
| 94 * @return {boolean} | |
| 95 */ | |
| 96 WebInspector.Geolocation.longitudeValidator = function(value) | |
| 97 { | |
| 98 var numValue = parseFloat(value); | |
| 99 return /^([+-]?[\d]+(\.\d+)?|[+-]?\.\d+)$/.test(value) && numValue >= -180 &
& numValue <= 180; | |
| 100 }; | |
| 101 | 99 |
| 102 WebInspector.Geolocation.DefaultMockAccuracy = 150; | 100 WebInspector.Geolocation.DefaultMockAccuracy = 150; |
| OLD | NEW |