Changeset 123634 in webkit


Ignore:
Timestamp:
Jul 25, 2012 10:50:44 AM (12 years ago)
Author:
kpiascik@rim.com
Message:

Web Inspector: Geolocation override
https://bugs.webkit.org/show_bug.cgi?id=89365

Reviewed by Pavel Feldman.

Source/WebCore:

Re-added the m_page member variable for GeolocationController since
it's now being used by InspectorInstrumentaiton.

Added a way to override the GeolocationPosition and GeolocationError
using Web Inspector. Curretnly only PositionError can be set.

This will be hidden behind the experiments flag for now.

Tests: inspector/geolocation-error.html

inspector/geolocation-success.html
inspector/geolocation-watchPosition.html

  • English.lproj/localizedStrings.js:
  • Modules/geolocation/GeolocationController.cpp:

(WebCore::GeolocationController::GeolocationController):
(WebCore::GeolocationController::positionChanged):

  • Modules/geolocation/GeolocationController.h:

(GeolocationController):

  • inspector/Inspector.json:
  • inspector/InspectorInstrumentation.cpp:

(WebCore):
(WebCore::InspectorInstrumentation::overrideGeolocationPositionImpl):

  • inspector/InspectorInstrumentation.h:

(WebCore):
(InspectorInstrumentation):
(WebCore::InspectorInstrumentation::overrideGeolocationPosition):

  • inspector/InspectorPageAgent.cpp:

(WebCore::InspectorPageAgent::InspectorPageAgent):
(WebCore::InspectorPageAgent::setGeolocationOverride):
(WebCore):
(WebCore::InspectorPageAgent::clearGeolocationOverride):
(WebCore::InspectorPageAgent::canOverrideGeolocation):
(WebCore::InspectorPageAgent::overrideGeolocationPosition):

  • inspector/InspectorPageAgent.h:
  • inspector/front-end/Settings.js:
  • inspector/front-end/SettingsScreen.js:

(WebInspector.UserAgentSettingsTab):
(WebInspector.UserAgentSettingsTab.prototype._createDeviceMetricsElement):
(WebInspector.UserAgentSettingsTab.prototype._onGeolocationOverrideCheckboxClicked):
(WebInspector.UserAgentSettingsTab.prototype._applyGeolocationUserInput):
(WebInspector.UserAgentSettingsTab.prototype._setGeolocationPosition.set if):
(WebInspector.UserAgentSettingsTab.prototype._setGeolocationPosition):
(WebInspector.UserAgentSettingsTab.prototype._createGeolocationOverrideElement.createInput):
(WebInspector.UserAgentSettingsTab.prototype._createGeolocationOverrideElement):

  • inspector/front-end/UserAgentSupport.js:

(WebInspector.UserAgentSupport.GeolocationPosition):
(WebInspector.UserAgentSupport.GeolocationPosition.prototype.toSetting):
(WebInspector.UserAgentSupport.GeolocationPosition.parseSetting):
(WebInspector.UserAgentSupport.GeolocationPosition.parseUserInput):
(WebInspector.UserAgentSupport.GeolocationPosition.clearGeolocationOverride):

  • inspector/front-end/inspector.js:

(WebInspector.doLoadedDone):

LayoutTests:

Added new tests.

  • inspector/geolocation-error-expected.txt: Added.
  • inspector/geolocation-error.html: Added.
  • inspector/geolocation-success-expected.txt: Added.
  • inspector/geolocation-success.html: Added.
  • inspector/geolocation-watchPosition-expected.txt: Added.
  • inspector/geolocation-watchPosition.html: Added.
Location:
trunk
Files:
6 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r123631 r123634  
     12012-07-25  Konrad Piascik  <kpiascik@rim.com>
     2
     3        Web Inspector: Geolocation override
     4        https://bugs.webkit.org/show_bug.cgi?id=89365
     5
     6        Reviewed by Pavel Feldman.
     7
     8        Added new tests.
     9
     10        * inspector/geolocation-error-expected.txt: Added.
     11        * inspector/geolocation-error.html: Added.
     12        * inspector/geolocation-success-expected.txt: Added.
     13        * inspector/geolocation-success.html: Added.
     14        * inspector/geolocation-watchPosition-expected.txt: Added.
     15        * inspector/geolocation-watchPosition.html: Added.
     16
    1172012-07-25  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
    218
  • trunk/Source/WebCore/ChangeLog

    r123633 r123634  
     12012-07-25  Konrad Piascik  <kpiascik@rim.com>
     2
     3        Web Inspector: Geolocation override
     4        https://bugs.webkit.org/show_bug.cgi?id=89365
     5
     6        Reviewed by Pavel Feldman.
     7
     8        Re-added the m_page member variable for GeolocationController since
     9        it's now being used by InspectorInstrumentaiton.
     10
     11        Added a way to override the GeolocationPosition and GeolocationError
     12        using Web Inspector. Curretnly only PositionError can be set.
     13
     14        This will be hidden behind the experiments flag for now.
     15
     16        Tests: inspector/geolocation-error.html
     17               inspector/geolocation-success.html
     18               inspector/geolocation-watchPosition.html
     19
     20        * English.lproj/localizedStrings.js:
     21        * Modules/geolocation/GeolocationController.cpp:
     22        (WebCore::GeolocationController::GeolocationController):
     23        (WebCore::GeolocationController::positionChanged):
     24        * Modules/geolocation/GeolocationController.h:
     25        (GeolocationController):
     26        * inspector/Inspector.json:
     27        * inspector/InspectorInstrumentation.cpp:
     28        (WebCore):
     29        (WebCore::InspectorInstrumentation::overrideGeolocationPositionImpl):
     30        * inspector/InspectorInstrumentation.h:
     31        (WebCore):
     32        (InspectorInstrumentation):
     33        (WebCore::InspectorInstrumentation::overrideGeolocationPosition):
     34        * inspector/InspectorPageAgent.cpp:
     35        (WebCore::InspectorPageAgent::InspectorPageAgent):
     36        (WebCore::InspectorPageAgent::setGeolocationOverride):
     37        (WebCore):
     38        (WebCore::InspectorPageAgent::clearGeolocationOverride):
     39        (WebCore::InspectorPageAgent::canOverrideGeolocation):
     40        (WebCore::InspectorPageAgent::overrideGeolocationPosition):
     41        * inspector/InspectorPageAgent.h:
     42        * inspector/front-end/Settings.js:
     43        * inspector/front-end/SettingsScreen.js:
     44        (WebInspector.UserAgentSettingsTab):
     45        (WebInspector.UserAgentSettingsTab.prototype._createDeviceMetricsElement):
     46        (WebInspector.UserAgentSettingsTab.prototype._onGeolocationOverrideCheckboxClicked):
     47        (WebInspector.UserAgentSettingsTab.prototype._applyGeolocationUserInput):
     48        (WebInspector.UserAgentSettingsTab.prototype._setGeolocationPosition.set if):
     49        (WebInspector.UserAgentSettingsTab.prototype._setGeolocationPosition):
     50        (WebInspector.UserAgentSettingsTab.prototype._createGeolocationOverrideElement.createInput):
     51        (WebInspector.UserAgentSettingsTab.prototype._createGeolocationOverrideElement):
     52        * inspector/front-end/UserAgentSupport.js:
     53        (WebInspector.UserAgentSupport.GeolocationPosition):
     54        (WebInspector.UserAgentSupport.GeolocationPosition.prototype.toSetting):
     55        (WebInspector.UserAgentSupport.GeolocationPosition.parseSetting):
     56        (WebInspector.UserAgentSupport.GeolocationPosition.parseUserInput):
     57        (WebInspector.UserAgentSupport.GeolocationPosition.clearGeolocationOverride):
     58        * inspector/front-end/inspector.js:
     59        (WebInspector.doLoadedDone):
     60
    1612012-07-25  Shawn Singh  <shawnsingh@chromium.org>
    262
  • trunk/Source/WebCore/English.lproj/localizedStrings.js

    r123494 r123634  
    723723localizedStrings["Previous"] = "Previous";
    724724localizedStrings["Paused in debugger"] = "Paused in debugger";
     725localizedStrings["Emulate position unavailable"] = "Emulate position unavailable";
     726localizedStrings["Override Geolocation"] = "Override Geolocation";
     727localizedStrings["Geolocation Position"] = "Geolocation Position";
  • trunk/Source/WebCore/Modules/geolocation/GeolocationController.cpp

    r122532 r123634  
    3030
    3131#include "GeolocationClient.h"
     32#include "GeolocationError.h"
    3233#include "GeolocationPosition.h"
     34#include "InspectorInstrumentation.h"
    3335
    3436namespace WebCore {
    3537
    36 GeolocationController::GeolocationController(Page*, GeolocationClient* client)
     38GeolocationController::GeolocationController(Page* page, GeolocationClient* client)
    3739    : m_client(client)
     40    , m_page(page)
    3841{
    3942}
     
    99102void GeolocationController::positionChanged(GeolocationPosition* position)
    100103{
     104    position = InspectorInstrumentation::overrideGeolocationPosition(m_page, position);
     105    if (!position) {
     106        errorOccurred(GeolocationError::create(GeolocationError::PositionUnavailable, "PositionUnavailable").get());
     107        return;
     108    }
    101109    m_lastPosition = position;
    102110    Vector<RefPtr<Geolocation> > observersVector;
  • trunk/Source/WebCore/Modules/geolocation/GeolocationController.h

    r122532 r123634  
    6969
    7070    GeolocationClient* m_client;
     71    Page* m_page;
    7172
    7273    RefPtr<GeolocationPosition> m_lastPosition;
  • trunk/Source/WebCore/inspector/Inspector.json

    r123612 r123634  
    351351                    { "name": "value", "type": "boolean", "description": "Whether script execution should be disabled in the page." }
    352352                ]
     353            },
     354            {
     355                "name": "setGeolocationOverride",
     356                "description": "Overrides the Geolocation Position or Error.",
     357                "parameters": [
     358                    { "name": "latitude", "type": "number", "optional": true, "description": "Mock longitude"},
     359                    { "name": "longitude", "type": "number", "optional": true, "description": "Mock latitude"},
     360                    { "name": "accuracy", "type": "number", "optional": true, "description": "Mock accuracy"}
     361                ],
     362                "hidden": true
     363            },
     364            {
     365                "name": "clearGeolocationOverride",
     366                "description": "Clears the overriden Geolocation Position and Error.",
     367                "hidden": true
     368            },
     369            {
     370                "name": "canOverrideGeolocation",
     371                "description": "Checks if Geolocation can be overridden.",
     372                "returns": [
     373                    { "name": "result", "type": "boolean", "description": "True if browser can ovrride Geolocation." }
     374                ],
     375                "hidden": true
    353376            }
    354377        ],
  • trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp

    r123223 r123634  
    11751175#endif
    11761176
     1177#if ENABLE(GEOLOCATION)
     1178GeolocationPosition* InspectorInstrumentation::overrideGeolocationPositionImpl(InstrumentingAgents* instrumentingAgents, GeolocationPosition* position)
     1179{
     1180    if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
     1181        position = pageAgent->overrideGeolocationPosition(position);
     1182    return position;
     1183}
     1184#endif
     1185
    11771186} // namespace WebCore
    11781187
  • trunk/Source/WebCore/inspector/InspectorInstrumentation.h

    r123223 r123634  
    5757class EventContext;
    5858class DocumentLoader;
     59class GeolocationPosition;
    5960class GraphicsContext;
    6061class HitTestResult;
     
    259260#endif
    260261
     262#if ENABLE(GEOLOCATION)
     263    static GeolocationPosition* overrideGeolocationPosition(Page*, GeolocationPosition*);
     264#endif
     265
    261266private:
    262267#if ENABLE(INSPECTOR)
     
    418423    static InspectorTimelineAgent* retrieveTimelineAgent(const InspectorInstrumentationCookie&);
    419424
     425#if ENABLE(GEOLOCATION)
     426    static GeolocationPosition* overrideGeolocationPositionImpl(InstrumentingAgents*, GeolocationPosition*);
     427#endif
     428
    420429    static int s_frontendCounter;
    421430#endif
     
    13641373#endif
    13651374}
     1375
     1376
     1377#if ENABLE(GEOLOCATION)
     1378inline GeolocationPosition* InspectorInstrumentation::overrideGeolocationPosition(Page* page, GeolocationPosition* position)
     1379{
     1380#if ENABLE(INSPECTOR)
     1381    FAST_RETURN_IF_NO_FRONTENDS(position);
     1382    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForPage(page))
     1383        return overrideGeolocationPositionImpl(instrumentingAgents, position);
     1384#endif
     1385    return position;
     1386}
     1387#endif
    13661388
    13671389#if ENABLE(INSPECTOR)
  • trunk/Source/WebCore/inspector/InspectorPageAgent.cpp

    r122966 r123634  
    5151#include "Frame.h"
    5252#include "FrameView.h"
     53#include "GeolocationController.h"
     54#include "GeolocationError.h"
    5355#include "HTMLFrameOwnerElement.h"
    5456#include "HTMLNames.h"
     
    320322    , m_lastPaintContext(0)
    321323    , m_didLoadEventFire(false)
     324    , m_geolocationOverridden(false)
    322325{
    323326}
     
    969972}
    970973
     974void InspectorPageAgent::setGeolocationOverride(ErrorString* error, const double* latitude, const double* longitude, const double* accuracy)
     975{
     976#if ENABLE (GEOLOCATION)
     977    GeolocationController* controller = GeolocationController::from(m_page);
     978    GeolocationPosition* position = 0;
     979    if (!controller) {
     980        *error = "Internal error: unable to override geolocation.";
     981        return;
     982    }
     983    position = controller->lastPosition();
     984    if (!m_geolocationOverridden && position)
     985        m_platformGeolocationPosition = position;
     986
     987    m_geolocationOverridden = true;
     988    if (latitude && longitude && accuracy)
     989        m_geolocationPosition = GeolocationPosition::create(currentTimeMS(), *latitude, *longitude, *accuracy);
     990    else
     991        m_geolocationPosition.clear();
     992
     993    controller->positionChanged(0); // Kick location update.
     994#else
     995    *error = "Geolocation is not available.";
     996#endif
     997}
     998
     999void InspectorPageAgent::clearGeolocationOverride(ErrorString* error)
     1000{
     1001    if (!m_geolocationOverridden)
     1002        return;
     1003#if ENABLE(GEOLOCATION)
     1004    ASSERT_UNUSED(error, true);
     1005    m_geolocationOverridden = false;
     1006    m_geolocationPosition.clear();
     1007
     1008    GeolocationController* controller = GeolocationController::from(m_page);
     1009    if (controller && m_platformGeolocationPosition.get())
     1010        controller->positionChanged(m_platformGeolocationPosition.get());
     1011#else
     1012    *error = "Geolocation is not available.";
     1013#endif
     1014}
     1015
     1016void InspectorPageAgent::canOverrideGeolocation(ErrorString*, bool* out_param)
     1017{
     1018#if ENABLE(GEOLOCATION)
     1019    *out_param = true;
     1020#else
     1021    *out_param = false;
     1022#endif
     1023}
     1024
     1025GeolocationPosition* InspectorPageAgent::overrideGeolocationPosition(GeolocationPosition* position)
     1026{
     1027    if (m_geolocationOverridden) {
     1028        if (position)
     1029            m_platformGeolocationPosition = position;
     1030        return m_geolocationPosition.get();
     1031    }
     1032    return position;
     1033}
     1034
    9711035} // namespace WebCore
    9721036
  • trunk/Source/WebCore/inspector/InspectorPageAgent.h

    r122966 r123634  
    3535
    3636#include "Frame.h"
     37#include "GeolocationPosition.h"
    3738#include "InspectorBaseAgent.h"
    3839#include "InspectorFrontend.h"
     
    110111    virtual void getScriptExecutionStatus(ErrorString*, PageCommandHandler::Result::Enum*);
    111112    virtual void setScriptExecutionDisabled(ErrorString*, bool);
     113    virtual void setGeolocationOverride(ErrorString*, const double*, const double*, const double*);
     114    virtual void clearGeolocationOverride(ErrorString*);
     115    virtual void canOverrideGeolocation(ErrorString*, bool* out_param);
     116
     117
     118    // Geolocation override helpers.
     119    GeolocationPosition* overrideGeolocationPosition(GeolocationPosition*);
    112120
    113121    // InspectorInstrumentation API
     
    159167    LayoutRect m_lastPaintRect;
    160168    bool m_didLoadEventFire;
     169    bool m_geolocationOverridden;
     170    RefPtr<GeolocationPosition> m_geolocationPosition;
     171    RefPtr<GeolocationPosition> m_platformGeolocationPosition;
    161172};
    162173
  • trunk/Source/WebCore/inspector/front-end/Settings.js

    r123452 r123634  
    5757    canOverrideDeviceMetrics: false,
    5858    timelineSupportsFrameInstrumentation: false,
     59    canOverrideGeolocation: false,
    5960}
    6061
     
    99100    this.savedURLs = this.createSetting("savedURLs", {});
    100101    this.javaScriptDisabled = this.createSetting("javaScriptDisabled", false);
     102    this.geolocationOverride = this.createSetting("geolocationOverride", "");
    101103
    102104    // If there are too many breakpoints in a storage, it is likely due to a recent bug that caused
     
    188190    this.fileSystemInspection = this._createExperiment("fileSystemInspection", "FileSystem inspection");
    189191    this.mainThreadMonitoring = this._createExperiment("mainThreadMonitoring", "Show CPU activity in Timeline");
     192    this.geolocationOverride = this._createExperiment("geolocationOverride", "Override Device Geolocation");
    190193
    191194    this._cleanUpSetting();
  • trunk/Source/WebCore/inspector/front-end/SettingsScreen.js

    r122532 r123634  
    350350    if (Capabilities.canOverrideDeviceMetrics)
    351351        p.appendChild(this._createDeviceMetricsControl());
     352    if (Capabilities.canOverrideGeolocation && WebInspector.experimentsSettings.geolocationOverride.isEnabled())
     353        p.appendChild(this._createGeolocationOverrideControl());
    352354    p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Emulate touch events"), WebInspector.settings.emulateTouchEvents));
    353355}
     
    650652
    651653        return fieldsetElement;
     654    },
     655
     656    _createGeolocationOverrideControl: function()
     657    {
     658        const geolocationSetting = WebInspector.settings.geolocationOverride.get();
     659        var geolocation = WebInspector.UserAgentSupport.GeolocationPosition.parseSetting(geolocationSetting);
     660        var p = document.createElement("p");
     661        var labelElement = p.createChild("label");
     662        var checkboxElement = labelElement.createChild("input");
     663        checkboxElement.id = "geolocation-override-checkbox";
     664        checkboxElement.type = "checkbox";
     665        checkboxElement.checked = !geolocation || (((typeof geolocation.latitude === "number") && (typeof geolocation.longitude === "number")) || geolocation.error);
     666        checkboxElement.addEventListener("click", this._onGeolocationOverrideCheckboxClicked.bind(this), false);
     667        this._geolocationOverrideCheckboxElement = checkboxElement;
     668        labelElement.appendChild(document.createTextNode(WebInspector.UIString("Override Geolocation")));
     669
     670        var geolocationSectionElement = this._createGeolocationOverrideElement(geolocation);
     671        p.appendChild(geolocationSectionElement);
     672        this._geolocationSectionElement = geolocationSectionElement;
     673        this._setGeolocationPosition(geolocation, false, true);
     674        return p;
     675    },
     676
     677    _onGeolocationOverrideCheckboxClicked: function()
     678    {
     679        var controlsDisabled = !this._geolocationOverrideCheckboxElement.checked;
     680        this._latitudeElement.disabled = controlsDisabled;
     681        this._longitudeElement.disabled = controlsDisabled;
     682        this._geolocationErrorElement.disabled = controlsDisabled;
     683
     684        if (this._geolocationOverrideCheckboxElement.checked) {
     685            var geolocation = WebInspector.UserAgentSupport.GeolocationPosition.parseUserInput(this._latitudeElement.value, this._longitudeElement.value, this._geolocationErrorElement.checked);
     686            if (geolocation)
     687                this._setGeolocationPosition(geolocation, false, false);
     688            if (!this._latitudeElement.value)
     689                this._latitudeElement.focus();
     690        } else
     691            WebInspector.UserAgentSupport.GeolocationPosition.clearGeolocationOverride();
     692    },
     693
     694    _applyGeolocationUserInput: function()
     695    {
     696        this._setGeolocationPosition(WebInspector.UserAgentSupport.GeolocationPosition.parseUserInput(this._latitudeElement.value.trim(), this._longitudeElement.value.trim(), this._geolocationErrorElement.checked), true, false);
     697    },
     698
     699    /**
     700     * @param {?WebInspector.UserAgentSupport.GeolocationPosition} geolocation
     701     * @param {boolean} userInputModified
     702     * @param {boolean} updateCheckbox
     703     */
     704    _setGeolocationPosition: function(geolocation, userInputModified, updateCheckbox)
     705    {
     706        if (!geolocation)
     707            return;
     708
     709        if (!userInputModified) {
     710            this._latitudeElement.value = geolocation.latitude;
     711            this._longitudeElement.value = geolocation.longitude;
     712        }
     713
     714        var value = geolocation.toSetting();
     715        WebInspector.settings.geolocationOverride.set(value);
     716
     717        if (this._geolocationOverrideCheckboxElement && updateCheckbox) {
     718            this._geolocationOverrideCheckboxElement.checked = !!geolocation.toSetting();
     719            this._onGeolocationOverrideCheckboxClicked();
     720        }
     721    },
     722
     723    /**
     724     * @param {WebInspector.UserAgentSupport.GeolocationPosition} geolocation
     725     */
     726    _createGeolocationOverrideElement: function(geolocation)
     727    {
     728        var fieldsetElement = document.createElement("fieldset");
     729        fieldsetElement.id = "geolocation-override-section";
     730
     731        function createInput(parentElement, id, defaultText)
     732        {
     733            var element = parentElement.createChild("input");
     734            element.id = id;
     735            element.maxLength = 12;
     736            element.style.width = "80px";
     737            element.value = defaultText;
     738            element.addEventListener("blur", this._applyGeolocationUserInput.bind(this), false);
     739            return element;
     740        }
     741
     742        var tableElement = fieldsetElement.createChild("table");
     743
     744        var rowElement = tableElement.createChild("tr");
     745        var cellElement = rowElement.createChild("td");
     746        cellElement.appendChild(document.createTextNode(WebInspector.UIString("Geolocation Position") + ":"));
     747        cellElement = rowElement.createChild("td");
     748        this._latitudeElement = createInput.call(this, cellElement, "geolocation-override-latitude", String(geolocation.latitude));
     749        cellElement.appendChild(document.createTextNode(" , "));
     750        this._longitudeElement = createInput.call(this, cellElement, "geolocation-override-longitude", String(geolocation.longitude));
     751        rowElement = tableElement.createChild("tr");
     752        cellElement = rowElement.createChild("td");
     753        var geolocationErrorLabelElement = document.createElement("label");
     754        var geolocationErrorCheckboxElement = geolocationErrorLabelElement.createChild("input");
     755        geolocationErrorCheckboxElement.id = "geolocation-error";
     756        geolocationErrorCheckboxElement.type = "checkbox";
     757        geolocationErrorCheckboxElement.checked = !geolocation || geolocation.error;
     758        geolocationErrorCheckboxElement.addEventListener("click", this._applyGeolocationUserInput.bind(this), false);
     759        geolocationErrorLabelElement.appendChild(document.createTextNode(WebInspector.UIString("Emulate position unavailable")));
     760        this._geolocationErrorElement = geolocationErrorCheckboxElement;
     761        cellElement.appendChild(geolocationErrorLabelElement);
     762
     763        return fieldsetElement;
    652764    }
    653765}
  • trunk/Source/WebCore/inspector/front-end/UserAgentSupport.js

    r122532 r123634  
    3838    WebInspector.settings.deviceMetrics.addChangeListener(this._deviceMetricsChanged, this);
    3939    WebInspector.settings.deviceFitWindow.addChangeListener(this._deviceMetricsChanged, this);
     40    WebInspector.settings.geolocationOverride.addChangeListener(this._geolocationPositionChanged, this);
    4041}
    4142
     
    164165}
    165166
     167/**
     168 * @constructor
     169 * @param {number} latitude
     170 * @param {number} longitude
     171 */
     172WebInspector.UserAgentSupport.GeolocationPosition = function(latitude, longitude, error)
     173{
     174    this.latitude = latitude;
     175    this.longitude = longitude;
     176    this.error = error;
     177}
     178
     179WebInspector.UserAgentSupport.GeolocationPosition.prototype = {
     180    /**
     181     * @return {string}
     182     */
     183    toSetting: function()
     184    {
     185        return (typeof this.latitude === "number" && typeof this.longitude === "number" && typeof this.error === "string") ? this.latitude + "@" + this.longitude + ":" + this.error : "";
     186    }
     187}
     188
     189/**
     190 * @return {WebInspector.UserAgentSupport.GeolocationPosition}
     191 */
     192WebInspector.UserAgentSupport.GeolocationPosition.parseSetting = function(value)
     193{
     194    if (value) {
     195        var splitError = value.split(":");
     196        if (splitError.length === 2) {
     197            var splitPosition = splitError[0].split("@")
     198            if (splitPosition.length === 2)
     199                return new WebInspector.UserAgentSupport.GeolocationPosition(parseFloat(splitPosition[0]), parseFloat(splitPosition[1]), splitError[1]);
     200        }
     201    }
     202    return new WebInspector.UserAgentSupport.GeolocationPosition(0, 0, "");
     203}
     204
     205/**
     206 * @return {?WebInspector.UserAgentSupport.GeolocationPosition}
     207 */
     208WebInspector.UserAgentSupport.GeolocationPosition.parseUserInput = function(latitudeString, longitudeString, errorStatus)
     209{
     210    function isUserInputValid(value)
     211    {
     212        if (!value)
     213            return true;
     214        return /^[-]?[0-9]*[.]?[0-9]*$/.test(value);
     215    }
     216
     217    if (!latitudeString ^ !latitudeString)
     218        return null;
     219
     220    var isLatitudeValid = isUserInputValid(latitudeString);
     221    var isLongitudeValid = isUserInputValid(longitudeString);
     222
     223    if (!isLatitudeValid && !isLongitudeValid)
     224        return null;
     225
     226    var latitude = isLatitudeValid ? parseFloat(latitudeString) : -1;
     227    var longitude = isLongitudeValid ? parseFloat(longitudeString) : -1;
     228
     229    return new WebInspector.UserAgentSupport.GeolocationPosition(latitude, longitude, errorStatus ? "PositionUnavailable" : "");
     230}
     231
     232WebInspector.UserAgentSupport.GeolocationPosition.clearGeolocationOverride = function()
     233{
     234    PageAgent.clearGeolocationOverride();
     235}
     236
    166237WebInspector.UserAgentSupport.prototype = {
    167238    _deviceMetricsChanged: function()
     
    170241        if (metrics.isValid())
    171242            PageAgent.setDeviceMetricsOverride(metrics.width, metrics.height, metrics.fontScaleFactor, WebInspector.settings.deviceFitWindow.get());
    172     }
    173 }
     243    },
     244
     245    _geolocationPositionChanged: function()
     246    {
     247        var geolocation = WebInspector.UserAgentSupport.GeolocationPosition.parseSetting(WebInspector.settings.geolocationOverride.get());
     248        if (geolocation.error)
     249            PageAgent.setGeolocationOverride();
     250        else
     251            PageAgent.setGeolocationOverride(geolocation.latitude, geolocation.longitude, 150);
     252    }
     253}
     254
  • trunk/Source/WebCore/inspector/front-end/inspector.js

    r123223 r123634  
    435435    ProfilerAgent.hasHeapProfiler(WebInspector._initializeCapability.bind(WebInspector, "heapProfilerPresent", null));
    436436    TimelineAgent.supportsFrameInstrumentation(WebInspector._initializeCapability.bind(WebInspector, "timelineSupportsFrameInstrumentation", null));
    437     PageAgent.canOverrideDeviceMetrics(WebInspector._initializeCapability.bind(WebInspector, "canOverrideDeviceMetrics", WebInspector._doLoadedDoneWithCapabilities.bind(WebInspector)));
     437    PageAgent.canOverrideDeviceMetrics(WebInspector._initializeCapability.bind(WebInspector, "canOverrideDeviceMetrics", null));
     438    PageAgent.canOverrideGeolocation(WebInspector._initializeCapability.bind(WebInspector, "canOverrideGeolocation", WebInspector._doLoadedDoneWithCapabilities.bind(WebInspector)));
    438439}
    439440
Note: See TracChangeset for help on using the changeset viewer.