Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @constructor | |
| 7 * @param {number} latitude | |
| 8 * @param {number} longitude | |
| 9 * @param {string} error | |
| 10 */ | |
| 11 WebInspector.Geolocation = function(latitude, longitude, error) | |
|
pfeldman
2016/01/27 17:53:18
ditto
| |
| 12 { | |
| 13 this.latitude = latitude; | |
| 14 this.longitude = longitude; | |
| 15 this.error = error; | |
| 16 } | |
| 17 | |
| 18 WebInspector.Geolocation.prototype = { | |
| 19 /** | |
| 20 * @return {string} | |
| 21 */ | |
| 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.Type.Page)) { | |
| 30 if (this.error) | |
| 31 target.emulationAgent().setGeolocationOverride(); | |
| 32 else | |
| 33 target.emulationAgent().setGeolocationOverride(this.latitude, th is.longitude, 150); | |
| 34 | |
| 35 } | |
| 36 }, | |
| 37 | |
| 38 clear: function() | |
| 39 { | |
| 40 for (var target of WebInspector.targetManager.targets(WebInspector.Targe t.Type.Page)) | |
| 41 target.emulationAgent().clearGeolocationOverride(); | |
| 42 } | |
| 43 } | |
| 44 | |
| 45 /** | |
| 46 * @return {!WebInspector.Geolocation} | |
| 47 */ | |
| 48 WebInspector.Geolocation.parseSetting = function(value) | |
| 49 { | |
| 50 if (value) { | |
| 51 var splitError = value.split(":"); | |
| 52 if (splitError.length === 2) { | |
| 53 var splitPosition = splitError[0].split("@"); | |
| 54 if (splitPosition.length === 2) | |
| 55 return new WebInspector.Geolocation(parseFloat(splitPosition[0]) , parseFloat(splitPosition[1]), splitError[1]); | |
| 56 } | |
| 57 } | |
| 58 return new WebInspector.Geolocation(0, 0, ""); | |
| 59 } | |
| 60 | |
| 61 /** | |
| 62 * @return {?WebInspector.Geolocation} | |
| 63 */ | |
| 64 WebInspector.Geolocation.parseUserInput = function(latitudeString, longitudeStri ng, errorStatus) | |
| 65 { | |
| 66 function isUserInputValid(value) | |
| 67 { | |
| 68 if (!value) | |
| 69 return true; | |
| 70 return /^[-]?[0-9]*[.]?[0-9]*$/.test(value); | |
| 71 } | |
| 72 | |
| 73 if (!latitudeString && !longitudeString) | |
| 74 return null; | |
| 75 | |
| 76 var isLatitudeValid = isUserInputValid(latitudeString); | |
| 77 var isLongitudeValid = isUserInputValid(longitudeString); | |
| 78 | |
| 79 if (!isLatitudeValid && !isLongitudeValid) | |
| 80 return null; | |
| 81 | |
| 82 var latitude = isLatitudeValid ? parseFloat(latitudeString) : -1; | |
| 83 var longitude = isLongitudeValid ? parseFloat(longitudeString) : -1; | |
| 84 | |
| 85 return new WebInspector.Geolocation(latitude, longitude, errorStatus ? "Posi tionUnavailable" : ""); | |
| 86 } | |
| OLD | NEW |