| 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 /** | 4 /** |
| 5 * @unrestricted | 5 * @unrestricted |
| 6 */ | 6 */ |
| 7 WebInspector.Geolocation = class { | 7 Emulation.Geolocation = class { |
| 8 /** | 8 /** |
| 9 * @param {number} latitude | 9 * @param {number} latitude |
| 10 * @param {number} longitude | 10 * @param {number} longitude |
| 11 * @param {boolean} error | 11 * @param {boolean} error |
| 12 */ | 12 */ |
| 13 constructor(latitude, longitude, error) { | 13 constructor(latitude, longitude, error) { |
| 14 this.latitude = latitude; | 14 this.latitude = latitude; |
| 15 this.longitude = longitude; | 15 this.longitude = longitude; |
| 16 this.error = error; | 16 this.error = error; |
| 17 } | 17 } |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * @return {!WebInspector.Geolocation} | 20 * @return {!Emulation.Geolocation} |
| 21 */ | 21 */ |
| 22 static parseSetting(value) { | 22 static parseSetting(value) { |
| 23 if (value) { | 23 if (value) { |
| 24 var splitError = value.split(':'); | 24 var splitError = value.split(':'); |
| 25 if (splitError.length === 2) { | 25 if (splitError.length === 2) { |
| 26 var splitPosition = splitError[0].split('@'); | 26 var splitPosition = splitError[0].split('@'); |
| 27 if (splitPosition.length === 2) | 27 if (splitPosition.length === 2) |
| 28 return new WebInspector.Geolocation( | 28 return new Emulation.Geolocation( |
| 29 parseFloat(splitPosition[0]), parseFloat(splitPosition[1]), splitE
rror[1]); | 29 parseFloat(splitPosition[0]), parseFloat(splitPosition[1]), splitE
rror[1]); |
| 30 } | 30 } |
| 31 } | 31 } |
| 32 return new WebInspector.Geolocation(0, 0, false); | 32 return new Emulation.Geolocation(0, 0, false); |
| 33 } | 33 } |
| 34 | 34 |
| 35 /** | 35 /** |
| 36 * @param {string} latitudeString | 36 * @param {string} latitudeString |
| 37 * @param {string} longitudeString | 37 * @param {string} longitudeString |
| 38 * @param {string} errorStatus | 38 * @param {string} errorStatus |
| 39 * @return {?WebInspector.Geolocation} | 39 * @return {?Emulation.Geolocation} |
| 40 */ | 40 */ |
| 41 static parseUserInput(latitudeString, longitudeString, errorStatus) { | 41 static parseUserInput(latitudeString, longitudeString, errorStatus) { |
| 42 if (!latitudeString && !longitudeString) | 42 if (!latitudeString && !longitudeString) |
| 43 return null; | 43 return null; |
| 44 | 44 |
| 45 var isLatitudeValid = WebInspector.Geolocation.latitudeValidator(latitudeStr
ing); | 45 var isLatitudeValid = Emulation.Geolocation.latitudeValidator(latitudeString
); |
| 46 var isLongitudeValid = WebInspector.Geolocation.longitudeValidator(longitude
String); | 46 var isLongitudeValid = Emulation.Geolocation.longitudeValidator(longitudeStr
ing); |
| 47 | 47 |
| 48 if (!isLatitudeValid && !isLongitudeValid) | 48 if (!isLatitudeValid && !isLongitudeValid) |
| 49 return null; | 49 return null; |
| 50 | 50 |
| 51 var latitude = isLatitudeValid ? parseFloat(latitudeString) : -1; | 51 var latitude = isLatitudeValid ? parseFloat(latitudeString) : -1; |
| 52 var longitude = isLongitudeValid ? parseFloat(longitudeString) : -1; | 52 var longitude = isLongitudeValid ? parseFloat(longitudeString) : -1; |
| 53 return new WebInspector.Geolocation(latitude, longitude, !!errorStatus); | 53 return new Emulation.Geolocation(latitude, longitude, !!errorStatus); |
| 54 } | 54 } |
| 55 | 55 |
| 56 /** | 56 /** |
| 57 * @param {string} value | 57 * @param {string} value |
| 58 * @return {boolean} | 58 * @return {boolean} |
| 59 */ | 59 */ |
| 60 static latitudeValidator(value) { | 60 static latitudeValidator(value) { |
| 61 var numValue = parseFloat(value); | 61 var numValue = parseFloat(value); |
| 62 return /^([+-]?[\d]+(\.\d+)?|[+-]?\.\d+)$/.test(value) && numValue >= -90 &&
numValue <= 90; | 62 return /^([+-]?[\d]+(\.\d+)?|[+-]?\.\d+)$/.test(value) && numValue >= -90 &&
numValue <= 90; |
| 63 } | 63 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 74 /** | 74 /** |
| 75 * @return {string} | 75 * @return {string} |
| 76 */ | 76 */ |
| 77 toSetting() { | 77 toSetting() { |
| 78 return (typeof this.latitude === 'number' && typeof this.longitude === 'numb
er' && typeof this.error === 'string') ? | 78 return (typeof this.latitude === 'number' && typeof this.longitude === 'numb
er' && typeof this.error === 'string') ? |
| 79 this.latitude + '@' + this.longitude + ':' + this.error : | 79 this.latitude + '@' + this.longitude + ':' + this.error : |
| 80 ''; | 80 ''; |
| 81 } | 81 } |
| 82 | 82 |
| 83 apply() { | 83 apply() { |
| 84 for (var target of WebInspector.targetManager.targets(WebInspector.Target.Ca
pability.Browser)) { | 84 for (var target of SDK.targetManager.targets(SDK.Target.Capability.Browser))
{ |
| 85 if (this.error) | 85 if (this.error) |
| 86 target.emulationAgent().setGeolocationOverride(); | 86 target.emulationAgent().setGeolocationOverride(); |
| 87 else | 87 else |
| 88 target.emulationAgent().setGeolocationOverride( | 88 target.emulationAgent().setGeolocationOverride( |
| 89 this.latitude, this.longitude, WebInspector.Geolocation.DefaultMockA
ccuracy); | 89 this.latitude, this.longitude, Emulation.Geolocation.DefaultMockAccu
racy); |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 | 92 |
| 93 clear() { | 93 clear() { |
| 94 for (var target of WebInspector.targetManager.targets(WebInspector.Target.Ca
pability.Browser)) | 94 for (var target of SDK.targetManager.targets(SDK.Target.Capability.Browser)) |
| 95 target.emulationAgent().clearGeolocationOverride(); | 95 target.emulationAgent().clearGeolocationOverride(); |
| 96 } | 96 } |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 | 99 |
| 100 WebInspector.Geolocation.DefaultMockAccuracy = 150; | 100 Emulation.Geolocation.DefaultMockAccuracy = 150; |
| OLD | NEW |