Diff
Modified: trunk/LayoutTests/ChangeLog (123633 => 123634)
--- trunk/LayoutTests/ChangeLog 2012-07-25 17:43:51 UTC (rev 123633)
+++ trunk/LayoutTests/ChangeLog 2012-07-25 17:50:44 UTC (rev 123634)
@@ -1,3 +1,19 @@
+2012-07-25 Konrad Piascik <kpias...@rim.com>
+
+ Web Inspector: Geolocation override
+ https://bugs.webkit.org/show_bug.cgi?id=89365
+
+ Reviewed by Pavel Feldman.
+
+ 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.
+
2012-07-25 Caio Marcelo de Oliveira Filho <caio.olive...@openbossa.org>
[Qt] css2.1/t* tests needs rebaseline after new testfonts
Added: trunk/LayoutTests/inspector/geolocation-error-expected.txt (0 => 123634)
--- trunk/LayoutTests/inspector/geolocation-error-expected.txt (rev 0)
+++ trunk/LayoutTests/inspector/geolocation-error-expected.txt 2012-07-25 17:50:44 UTC (rev 123634)
@@ -0,0 +1,3 @@
+CONSOLE MESSAGE: line 26: Error: 2
+CONSOLE MESSAGE: line 22: lat: 51.478, long: -0.166
+
Added: trunk/LayoutTests/inspector/geolocation-error.html (0 => 123634)
--- trunk/LayoutTests/inspector/geolocation-error.html (rev 0)
+++ trunk/LayoutTests/inspector/geolocation-error.html 2012-07-25 17:50:44 UTC (rev 123634)
@@ -0,0 +1,55 @@
+<html>
+<head>
+<script src=""
+<script>
+
+var mockLatitude = 51.478;
+var mockLongitude = -0.166;
+var mockAccuracy = 100;
+
+if (window.testRunner) {
+ testRunner.setGeolocationPermission(true);
+ testRunner.setMockGeolocationPosition(mockLatitude,
+ mockLongitude,
+ mockAccuracy);
+} else
+ debug('This test can not be run without the LayoutTestController');
+
+function getGeolocation()
+{
+ function printLocation(pos)
+ {
+ console.log('lat: ' + pos.coords.latitude + ', long: ' + pos.coords.longitude);
+ }
+ function printError(err)
+ {
+ console.log('Error: ' + err.code);
+ }
+ navigator.geolocation.getCurrentPosition(printLocation, printError, [])
+}
+
+function test()
+{
+ function callbackComplete()
+ {
+ InspectorTest.completeTest();
+ }
+ function callback()
+ {
+ PageAgent.clearGeolocationOverride();
+ InspectorTest.evaluateInPage("getGeolocation()", callbackComplete);
+ }
+ PageAgent.setGeolocationOverride();
+ InspectorTest.evaluateInPage("getGeolocation()", callback);
+}
+
+
+</script>
+</head>
+
+<body _onload_="runTest()">
+<p>
+</p>
+
+</body>
+</html>
Added: trunk/LayoutTests/inspector/geolocation-success-expected.txt (0 => 123634)
--- trunk/LayoutTests/inspector/geolocation-success-expected.txt (rev 0)
+++ trunk/LayoutTests/inspector/geolocation-success-expected.txt 2012-07-25 17:50:44 UTC (rev 123634)
@@ -0,0 +1,3 @@
+CONSOLE MESSAGE: line 22: lat: 43.476093, long: -80.540299
+CONSOLE MESSAGE: line 22: lat: 51.478, long: -0.166
+
Added: trunk/LayoutTests/inspector/geolocation-success.html (0 => 123634)
--- trunk/LayoutTests/inspector/geolocation-success.html (rev 0)
+++ trunk/LayoutTests/inspector/geolocation-success.html 2012-07-25 17:50:44 UTC (rev 123634)
@@ -0,0 +1,55 @@
+<html>
+<head>
+<script src=""
+<script>
+
+var mockLatitude = 51.478;
+var mockLongitude = -0.166;
+var mockAccuracy = 100;
+
+if (window.testRunner) {
+ testRunner.setGeolocationPermission(true);
+ testRunner.setMockGeolocationPosition(mockLatitude,
+ mockLongitude,
+ mockAccuracy);
+} else
+ debug('This test can not be run without the LayoutTestController');
+
+function getGeolocation()
+{
+ function printLocation(pos)
+ {
+ console.log('lat: ' + pos.coords.latitude + ', long: ' + pos.coords.longitude);
+ }
+ function printError(err)
+ {
+ console.log('Error: ' + err.code);
+ }
+ navigator.geolocation.getCurrentPosition(printLocation, printError, [])
+}
+
+function test()
+{
+ function callbackComplete()
+ {
+ InspectorTest.completeTest();
+ }
+ function callback()
+ {
+ PageAgent.clearGeolocationOverride();
+ InspectorTest.evaluateInPage("getGeolocation()", callbackComplete);
+ }
+ PageAgent.setGeolocationOverride(43.476093, -80.540299, 150);
+ InspectorTest.evaluateInPage("getGeolocation()", callback);
+}
+
+
+</script>
+</head>
+
+<body _onload_="runTest()">
+<p>
+</p>
+
+</body>
+</html>
Added: trunk/LayoutTests/inspector/geolocation-watchPosition-expected.txt (0 => 123634)
--- trunk/LayoutTests/inspector/geolocation-watchPosition-expected.txt (rev 0)
+++ trunk/LayoutTests/inspector/geolocation-watchPosition-expected.txt 2012-07-25 17:50:44 UTC (rev 123634)
@@ -0,0 +1,5 @@
+CONSOLE MESSAGE: line 23: lat: 51.478, long: -0.166
+CONSOLE MESSAGE: line 23: lat: 43.476093, long: -80.540299
+CONSOLE MESSAGE: line 27: Error: 2
+CONSOLE MESSAGE: line 23: lat: 51.478, long: -0.166
+
Added: trunk/LayoutTests/inspector/geolocation-watchPosition.html (0 => 123634)
--- trunk/LayoutTests/inspector/geolocation-watchPosition.html (rev 0)
+++ trunk/LayoutTests/inspector/geolocation-watchPosition.html 2012-07-25 17:50:44 UTC (rev 123634)
@@ -0,0 +1,69 @@
+<html>
+<head>
+<script src=""
+<script>
+
+var mockLatitude = 51.478;
+var mockLongitude = -0.166;
+var mockAccuracy = 100;
+
+if (window.testRunner) {
+ testRunner.setGeolocationPermission(true);
+ testRunner.setMockGeolocationPosition(mockLatitude,
+ mockLongitude,
+ mockAccuracy);
+} else
+ debug('This test can not be run without the LayoutTestController');
+
+var watch = 0;
+function getGeolocation()
+{
+ function printLocation(pos)
+ {
+ console.log('lat: ' + pos.coords.latitude + ', long: ' + pos.coords.longitude);
+ }
+ function printError(err)
+ {
+ console.log('Error: ' + err.code);
+ }
+ watch = navigator.geolocation.watchPosition(printLocation, printError, [])
+}
+function clearWatch()
+{
+ navigator.geolocation.clearWatch(watch);
+}
+
+function test()
+{
+ function callbackComplete()
+ {
+ InspectorTest.completeTest();
+ }
+ function callback()
+ {
+ InspectorTest.evaluateInPage("clearWatch()", callbackComplete);
+ }
+ function clearData()
+ {
+ PageAgent.clearGeolocationOverride();
+ setTimeout(callback, 1);
+ }
+ function setError()
+ {
+ PageAgent.setGeolocationOverride();
+ setTimeout(clearData, 1);
+ }
+ function setPosition()
+ {
+ PageAgent.setGeolocationOverride(43.476093, -80.540299, 150);
+ setTimeout(setError, 1);
+ }
+ InspectorTest.evaluateInPage("getGeolocation()", setPosition);
+}
+</script>
+</head>
+<body _onload_="runTest()">
+<p>
+</p>
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (123633 => 123634)
--- trunk/Source/WebCore/ChangeLog 2012-07-25 17:43:51 UTC (rev 123633)
+++ trunk/Source/WebCore/ChangeLog 2012-07-25 17:50:44 UTC (rev 123634)
@@ -1,3 +1,63 @@
+2012-07-25 Konrad Piascik <kpias...@rim.com>
+
+ Web Inspector: Geolocation override
+ https://bugs.webkit.org/show_bug.cgi?id=89365
+
+ Reviewed by Pavel Feldman.
+
+ 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):
+
2012-07-25 Shawn Singh <shawnsi...@chromium.org>
[chromium] Build fix for clang builds after r123628
Modified: trunk/Source/WebCore/English.lproj/localizedStrings.js (123633 => 123634)
--- trunk/Source/WebCore/English.lproj/localizedStrings.js 2012-07-25 17:43:51 UTC (rev 123633)
+++ trunk/Source/WebCore/English.lproj/localizedStrings.js 2012-07-25 17:50:44 UTC (rev 123634)
@@ -722,3 +722,6 @@
localizedStrings["Replace All"] = "Replace All";
localizedStrings["Previous"] = "Previous";
localizedStrings["Paused in debugger"] = "Paused in debugger";
+localizedStrings["Emulate position unavailable"] = "Emulate position unavailable";
+localizedStrings["Override Geolocation"] = "Override Geolocation";
+localizedStrings["Geolocation Position"] = "Geolocation Position";
Modified: trunk/Source/WebCore/Modules/geolocation/GeolocationController.cpp (123633 => 123634)
--- trunk/Source/WebCore/Modules/geolocation/GeolocationController.cpp 2012-07-25 17:43:51 UTC (rev 123633)
+++ trunk/Source/WebCore/Modules/geolocation/GeolocationController.cpp 2012-07-25 17:50:44 UTC (rev 123634)
@@ -29,12 +29,15 @@
#if ENABLE(GEOLOCATION)
#include "GeolocationClient.h"
+#include "GeolocationError.h"
#include "GeolocationPosition.h"
+#include "InspectorInstrumentation.h"
namespace WebCore {
-GeolocationController::GeolocationController(Page*, GeolocationClient* client)
+GeolocationController::GeolocationController(Page* page, GeolocationClient* client)
: m_client(client)
+ , m_page(page)
{
}
@@ -98,6 +101,11 @@
void GeolocationController::positionChanged(GeolocationPosition* position)
{
+ position = InspectorInstrumentation::overrideGeolocationPosition(m_page, position);
+ if (!position) {
+ errorOccurred(GeolocationError::create(GeolocationError::PositionUnavailable, "PositionUnavailable").get());
+ return;
+ }
m_lastPosition = position;
Vector<RefPtr<Geolocation> > observersVector;
copyToVector(m_observers, observersVector);
Modified: trunk/Source/WebCore/Modules/geolocation/GeolocationController.h (123633 => 123634)
--- trunk/Source/WebCore/Modules/geolocation/GeolocationController.h 2012-07-25 17:43:51 UTC (rev 123633)
+++ trunk/Source/WebCore/Modules/geolocation/GeolocationController.h 2012-07-25 17:50:44 UTC (rev 123634)
@@ -68,6 +68,7 @@
GeolocationController(Page*, GeolocationClient*);
GeolocationClient* m_client;
+ Page* m_page;
RefPtr<GeolocationPosition> m_lastPosition;
typedef HashSet<RefPtr<Geolocation> > ObserversSet;
Modified: trunk/Source/WebCore/inspector/Inspector.json (123633 => 123634)
--- trunk/Source/WebCore/inspector/Inspector.json 2012-07-25 17:43:51 UTC (rev 123633)
+++ trunk/Source/WebCore/inspector/Inspector.json 2012-07-25 17:50:44 UTC (rev 123634)
@@ -350,6 +350,29 @@
"parameters": [
{ "name": "value", "type": "boolean", "description": "Whether script execution should be disabled in the page." }
]
+ },
+ {
+ "name": "setGeolocationOverride",
+ "description": "Overrides the Geolocation Position or Error.",
+ "parameters": [
+ { "name": "latitude", "type": "number", "optional": true, "description": "Mock longitude"},
+ { "name": "longitude", "type": "number", "optional": true, "description": "Mock latitude"},
+ { "name": "accuracy", "type": "number", "optional": true, "description": "Mock accuracy"}
+ ],
+ "hidden": true
+ },
+ {
+ "name": "clearGeolocationOverride",
+ "description": "Clears the overriden Geolocation Position and Error.",
+ "hidden": true
+ },
+ {
+ "name": "canOverrideGeolocation",
+ "description": "Checks if Geolocation can be overridden.",
+ "returns": [
+ { "name": "result", "type": "boolean", "description": "True if browser can ovrride Geolocation." }
+ ],
+ "hidden": true
}
],
"events": [
Modified: trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp (123633 => 123634)
--- trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp 2012-07-25 17:43:51 UTC (rev 123633)
+++ trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp 2012-07-25 17:50:44 UTC (rev 123634)
@@ -1174,6 +1174,15 @@
}
#endif
+#if ENABLE(GEOLOCATION)
+GeolocationPosition* InspectorInstrumentation::overrideGeolocationPositionImpl(InstrumentingAgents* instrumentingAgents, GeolocationPosition* position)
+{
+ if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
+ position = pageAgent->overrideGeolocationPosition(position);
+ return position;
+}
+#endif
+
} // namespace WebCore
#endif // !ENABLE(INSPECTOR)
Modified: trunk/Source/WebCore/inspector/InspectorInstrumentation.h (123633 => 123634)
--- trunk/Source/WebCore/inspector/InspectorInstrumentation.h 2012-07-25 17:43:51 UTC (rev 123633)
+++ trunk/Source/WebCore/inspector/InspectorInstrumentation.h 2012-07-25 17:50:44 UTC (rev 123634)
@@ -56,6 +56,7 @@
class Element;
class EventContext;
class DocumentLoader;
+class GeolocationPosition;
class GraphicsContext;
class HitTestResult;
class InspectorCSSAgent;
@@ -258,6 +259,10 @@
static bool collectingHTMLParseErrors(Page*) { return false; }
#endif
+#if ENABLE(GEOLOCATION)
+ static GeolocationPosition* overrideGeolocationPosition(Page*, GeolocationPosition*);
+#endif
+
private:
#if ENABLE(INSPECTOR)
static WTF::ThreadSpecific<InspectorTimelineAgent*>& threadSpecificTimelineAgentForOrphanEvents();
@@ -417,6 +422,10 @@
static void cancelPauseOnNativeEvent(InstrumentingAgents*);
static InspectorTimelineAgent* retrieveTimelineAgent(const InspectorInstrumentationCookie&);
+#if ENABLE(GEOLOCATION)
+ static GeolocationPosition* overrideGeolocationPositionImpl(InstrumentingAgents*, GeolocationPosition*);
+#endif
+
static int s_frontendCounter;
#endif
};
@@ -1364,7 +1373,20 @@
#endif
}
+
+#if ENABLE(GEOLOCATION)
+inline GeolocationPosition* InspectorInstrumentation::overrideGeolocationPosition(Page* page, GeolocationPosition* position)
+{
#if ENABLE(INSPECTOR)
+ FAST_RETURN_IF_NO_FRONTENDS(position);
+ if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForPage(page))
+ return overrideGeolocationPositionImpl(instrumentingAgents, position);
+#endif
+ return position;
+}
+#endif
+
+#if ENABLE(INSPECTOR)
inline bool InspectorInstrumentation::collectingHTMLParseErrors(Page* page)
{
FAST_RETURN_IF_NO_FRONTENDS(false);
Modified: trunk/Source/WebCore/inspector/InspectorPageAgent.cpp (123633 => 123634)
--- trunk/Source/WebCore/inspector/InspectorPageAgent.cpp 2012-07-25 17:43:51 UTC (rev 123633)
+++ trunk/Source/WebCore/inspector/InspectorPageAgent.cpp 2012-07-25 17:50:44 UTC (rev 123634)
@@ -50,6 +50,8 @@
#include "DocumentLoader.h"
#include "Frame.h"
#include "FrameView.h"
+#include "GeolocationController.h"
+#include "GeolocationError.h"
#include "HTMLFrameOwnerElement.h"
#include "HTMLNames.h"
#include "IdentifiersFactory.h"
@@ -319,6 +321,7 @@
, m_lastScriptIdentifier(0)
, m_lastPaintContext(0)
, m_didLoadEventFire(false)
+ , m_geolocationOverridden(false)
{
}
@@ -968,6 +971,67 @@
InspectorInstrumentation::mediaQueryResultChanged(document);
}
+void InspectorPageAgent::setGeolocationOverride(ErrorString* error, const double* latitude, const double* longitude, const double* accuracy)
+{
+#if ENABLE (GEOLOCATION)
+ GeolocationController* controller = GeolocationController::from(m_page);
+ GeolocationPosition* position = 0;
+ if (!controller) {
+ *error = "Internal error: unable to override geolocation.";
+ return;
+ }
+ position = controller->lastPosition();
+ if (!m_geolocationOverridden && position)
+ m_platformGeolocationPosition = position;
+
+ m_geolocationOverridden = true;
+ if (latitude && longitude && accuracy)
+ m_geolocationPosition = GeolocationPosition::create(currentTimeMS(), *latitude, *longitude, *accuracy);
+ else
+ m_geolocationPosition.clear();
+
+ controller->positionChanged(0); // Kick location update.
+#else
+ *error = "Geolocation is not available.";
+#endif
+}
+
+void InspectorPageAgent::clearGeolocationOverride(ErrorString* error)
+{
+ if (!m_geolocationOverridden)
+ return;
+#if ENABLE(GEOLOCATION)
+ ASSERT_UNUSED(error, true);
+ m_geolocationOverridden = false;
+ m_geolocationPosition.clear();
+
+ GeolocationController* controller = GeolocationController::from(m_page);
+ if (controller && m_platformGeolocationPosition.get())
+ controller->positionChanged(m_platformGeolocationPosition.get());
+#else
+ *error = "Geolocation is not available.";
+#endif
+}
+
+void InspectorPageAgent::canOverrideGeolocation(ErrorString*, bool* out_param)
+{
+#if ENABLE(GEOLOCATION)
+ *out_param = true;
+#else
+ *out_param = false;
+#endif
+}
+
+GeolocationPosition* InspectorPageAgent::overrideGeolocationPosition(GeolocationPosition* position)
+{
+ if (m_geolocationOverridden) {
+ if (position)
+ m_platformGeolocationPosition = position;
+ return m_geolocationPosition.get();
+ }
+ return position;
+}
+
} // namespace WebCore
#endif // ENABLE(INSPECTOR)
Modified: trunk/Source/WebCore/inspector/InspectorPageAgent.h (123633 => 123634)
--- trunk/Source/WebCore/inspector/InspectorPageAgent.h 2012-07-25 17:43:51 UTC (rev 123633)
+++ trunk/Source/WebCore/inspector/InspectorPageAgent.h 2012-07-25 17:50:44 UTC (rev 123634)
@@ -34,6 +34,7 @@
#if ENABLE(INSPECTOR)
#include "Frame.h"
+#include "GeolocationPosition.h"
#include "InspectorBaseAgent.h"
#include "InspectorFrontend.h"
#include "PlatformString.h"
@@ -109,7 +110,14 @@
virtual void setShowPaintRects(ErrorString*, bool show);
virtual void getScriptExecutionStatus(ErrorString*, PageCommandHandler::Result::Enum*);
virtual void setScriptExecutionDisabled(ErrorString*, bool);
+ virtual void setGeolocationOverride(ErrorString*, const double*, const double*, const double*);
+ virtual void clearGeolocationOverride(ErrorString*);
+ virtual void canOverrideGeolocation(ErrorString*, bool* out_param);
+
+ // Geolocation override helpers.
+ GeolocationPosition* overrideGeolocationPosition(GeolocationPosition*);
+
// InspectorInstrumentation API
void didClearWindowObjectInWorld(Frame*, DOMWrapperWorld*);
void domContentEventFired();
@@ -158,6 +166,9 @@
GraphicsContext* m_lastPaintContext;
LayoutRect m_lastPaintRect;
bool m_didLoadEventFire;
+ bool m_geolocationOverridden;
+ RefPtr<GeolocationPosition> m_geolocationPosition;
+ RefPtr<GeolocationPosition> m_platformGeolocationPosition;
};
Modified: trunk/Source/WebCore/inspector/front-end/Settings.js (123633 => 123634)
--- trunk/Source/WebCore/inspector/front-end/Settings.js 2012-07-25 17:43:51 UTC (rev 123633)
+++ trunk/Source/WebCore/inspector/front-end/Settings.js 2012-07-25 17:50:44 UTC (rev 123634)
@@ -56,6 +56,7 @@
heapProfilerPresent: false,
canOverrideDeviceMetrics: false,
timelineSupportsFrameInstrumentation: false,
+ canOverrideGeolocation: false,
}
/**
@@ -98,6 +99,7 @@
this.zoomLevel = this.createSetting("zoomLevel", 0);
this.savedURLs = this.createSetting("savedURLs", {});
this._javascript_Disabled = this.createSetting("_javascript_Disabled", false);
+ this.geolocationOverride = this.createSetting("geolocationOverride", "");
// If there are too many breakpoints in a storage, it is likely due to a recent bug that caused
// periodical breakpoints duplication leading to inspector slowness.
@@ -187,6 +189,7 @@
this.liveNativeMemoryChart = this._createExperiment("liveNativeMemoryChart", "Live native memory chart");
this.fileSystemInspection = this._createExperiment("fileSystemInspection", "FileSystem inspection");
this.mainThreadMonitoring = this._createExperiment("mainThreadMonitoring", "Show CPU activity in Timeline");
+ this.geolocationOverride = this._createExperiment("geolocationOverride", "Override Device Geolocation");
this._cleanUpSetting();
}
Modified: trunk/Source/WebCore/inspector/front-end/SettingsScreen.js (123633 => 123634)
--- trunk/Source/WebCore/inspector/front-end/SettingsScreen.js 2012-07-25 17:43:51 UTC (rev 123633)
+++ trunk/Source/WebCore/inspector/front-end/SettingsScreen.js 2012-07-25 17:50:44 UTC (rev 123634)
@@ -349,6 +349,8 @@
p.appendChild(this._createUserAgentControl());
if (Capabilities.canOverrideDeviceMetrics)
p.appendChild(this._createDeviceMetricsControl());
+ if (Capabilities.canOverrideGeolocation && WebInspector.experimentsSettings.geolocationOverride.isEnabled())
+ p.appendChild(this._createGeolocationOverrideControl());
p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Emulate touch events"), WebInspector.settings.emulateTouchEvents));
}
@@ -649,6 +651,116 @@
cellElement.appendChild(this._createCheckboxSetting(WebInspector.UIString("Fit in window"), WebInspector.settings.deviceFitWindow, true, this._fitWindowCheckboxElement));
return fieldsetElement;
+ },
+
+ _createGeolocationOverrideControl: function()
+ {
+ const geolocationSetting = WebInspector.settings.geolocationOverride.get();
+ var geolocation = WebInspector.UserAgentSupport.GeolocationPosition.parseSetting(geolocationSetting);
+ var p = document.createElement("p");
+ var labelElement = p.createChild("label");
+ var checkboxElement = labelElement.createChild("input");
+ checkboxElement.id = "geolocation-override-checkbox";
+ checkboxElement.type = "checkbox";
+ checkboxElement.checked = !geolocation || (((typeof geolocation.latitude === "number") && (typeof geolocation.longitude === "number")) || geolocation.error);
+ checkboxElement.addEventListener("click", this._onGeolocationOverrideCheckboxClicked.bind(this), false);
+ this._geolocationOverrideCheckboxElement = checkboxElement;
+ labelElement.appendChild(document.createTextNode(WebInspector.UIString("Override Geolocation")));
+
+ var geolocationSectionElement = this._createGeolocationOverrideElement(geolocation);
+ p.appendChild(geolocationSectionElement);
+ this._geolocationSectionElement = geolocationSectionElement;
+ this._setGeolocationPosition(geolocation, false, true);
+ return p;
+ },
+
+ _onGeolocationOverrideCheckboxClicked: function()
+ {
+ var controlsDisabled = !this._geolocationOverrideCheckboxElement.checked;
+ this._latitudeElement.disabled = controlsDisabled;
+ this._longitudeElement.disabled = controlsDisabled;
+ this._geolocationErrorElement.disabled = controlsDisabled;
+
+ if (this._geolocationOverrideCheckboxElement.checked) {
+ var geolocation = WebInspector.UserAgentSupport.GeolocationPosition.parseUserInput(this._latitudeElement.value, this._longitudeElement.value, this._geolocationErrorElement.checked);
+ if (geolocation)
+ this._setGeolocationPosition(geolocation, false, false);
+ if (!this._latitudeElement.value)
+ this._latitudeElement.focus();
+ } else
+ WebInspector.UserAgentSupport.GeolocationPosition.clearGeolocationOverride();
+ },
+
+ _applyGeolocationUserInput: function()
+ {
+ this._setGeolocationPosition(WebInspector.UserAgentSupport.GeolocationPosition.parseUserInput(this._latitudeElement.value.trim(), this._longitudeElement.value.trim(), this._geolocationErrorElement.checked), true, false);
+ },
+
+ /**
+ * @param {?WebInspector.UserAgentSupport.GeolocationPosition} geolocation
+ * @param {boolean} userInputModified
+ * @param {boolean} updateCheckbox
+ */
+ _setGeolocationPosition: function(geolocation, userInputModified, updateCheckbox)
+ {
+ if (!geolocation)
+ return;
+
+ if (!userInputModified) {
+ this._latitudeElement.value = geolocation.latitude;
+ this._longitudeElement.value = geolocation.longitude;
+ }
+
+ var value = geolocation.toSetting();
+ WebInspector.settings.geolocationOverride.set(value);
+
+ if (this._geolocationOverrideCheckboxElement && updateCheckbox) {
+ this._geolocationOverrideCheckboxElement.checked = !!geolocation.toSetting();
+ this._onGeolocationOverrideCheckboxClicked();
+ }
+ },
+
+ /**
+ * @param {WebInspector.UserAgentSupport.GeolocationPosition} geolocation
+ */
+ _createGeolocationOverrideElement: function(geolocation)
+ {
+ var fieldsetElement = document.createElement("fieldset");
+ fieldsetElement.id = "geolocation-override-section";
+
+ function createInput(parentElement, id, defaultText)
+ {
+ var element = parentElement.createChild("input");
+ element.id = id;
+ element.maxLength = 12;
+ element.style.width = "80px";
+ element.value = defaultText;
+ element.addEventListener("blur", this._applyGeolocationUserInput.bind(this), false);
+ return element;
+ }
+
+ var tableElement = fieldsetElement.createChild("table");
+
+ var rowElement = tableElement.createChild("tr");
+ var cellElement = rowElement.createChild("td");
+ cellElement.appendChild(document.createTextNode(WebInspector.UIString("Geolocation Position") + ":"));
+ cellElement = rowElement.createChild("td");
+ this._latitudeElement = createInput.call(this, cellElement, "geolocation-override-latitude", String(geolocation.latitude));
+ cellElement.appendChild(document.createTextNode(" , "));
+ this._longitudeElement = createInput.call(this, cellElement, "geolocation-override-longitude", String(geolocation.longitude));
+ rowElement = tableElement.createChild("tr");
+ cellElement = rowElement.createChild("td");
+ var geolocationErrorLabelElement = document.createElement("label");
+ var geolocationErrorCheckboxElement = geolocationErrorLabelElement.createChild("input");
+ geolocationErrorCheckboxElement.id = "geolocation-error";
+ geolocationErrorCheckboxElement.type = "checkbox";
+ geolocationErrorCheckboxElement.checked = !geolocation || geolocation.error;
+ geolocationErrorCheckboxElement.addEventListener("click", this._applyGeolocationUserInput.bind(this), false);
+ geolocationErrorLabelElement.appendChild(document.createTextNode(WebInspector.UIString("Emulate position unavailable")));
+ this._geolocationErrorElement = geolocationErrorCheckboxElement;
+ cellElement.appendChild(geolocationErrorLabelElement);
+
+ return fieldsetElement;
}
}
Modified: trunk/Source/WebCore/inspector/front-end/UserAgentSupport.js (123633 => 123634)
--- trunk/Source/WebCore/inspector/front-end/UserAgentSupport.js 2012-07-25 17:43:51 UTC (rev 123633)
+++ trunk/Source/WebCore/inspector/front-end/UserAgentSupport.js 2012-07-25 17:50:44 UTC (rev 123634)
@@ -37,6 +37,7 @@
this._deviceMetricsChanged();
WebInspector.settings.deviceMetrics.addChangeListener(this._deviceMetricsChanged, this);
WebInspector.settings.deviceFitWindow.addChangeListener(this._deviceMetricsChanged, this);
+ WebInspector.settings.geolocationOverride.addChangeListener(this._geolocationPositionChanged, this);
}
/**
@@ -163,11 +164,91 @@
}
}
+/**
+ * @constructor
+ * @param {number} latitude
+ * @param {number} longitude
+ */
+WebInspector.UserAgentSupport.GeolocationPosition = function(latitude, longitude, error)
+{
+ this.latitude = latitude;
+ this.longitude = longitude;
+ this.error = error;
+}
+
+WebInspector.UserAgentSupport.GeolocationPosition.prototype = {
+ /**
+ * @return {string}
+ */
+ toSetting: function()
+ {
+ return (typeof this.latitude === "number" && typeof this.longitude === "number" && typeof this.error === "string") ? this.latitude + "@" + this.longitude + ":" + this.error : "";
+ }
+}
+
+/**
+ * @return {WebInspector.UserAgentSupport.GeolocationPosition}
+ */
+WebInspector.UserAgentSupport.GeolocationPosition.parseSetting = function(value)
+{
+ if (value) {
+ var splitError = value.split(":");
+ if (splitError.length === 2) {
+ var splitPosition = splitError[0].split("@")
+ if (splitPosition.length === 2)
+ return new WebInspector.UserAgentSupport.GeolocationPosition(parseFloat(splitPosition[0]), parseFloat(splitPosition[1]), splitError[1]);
+ }
+ }
+ return new WebInspector.UserAgentSupport.GeolocationPosition(0, 0, "");
+}
+
+/**
+ * @return {?WebInspector.UserAgentSupport.GeolocationPosition}
+ */
+WebInspector.UserAgentSupport.GeolocationPosition.parseUserInput = function(latitudeString, longitudeString, errorStatus)
+{
+ function isUserInputValid(value)
+ {
+ if (!value)
+ return true;
+ return /^[-]?[0-9]*[.]?[0-9]*$/.test(value);
+ }
+
+ if (!latitudeString ^ !latitudeString)
+ return null;
+
+ var isLatitudeValid = isUserInputValid(latitudeString);
+ var isLongitudeValid = isUserInputValid(longitudeString);
+
+ if (!isLatitudeValid && !isLongitudeValid)
+ return null;
+
+ var latitude = isLatitudeValid ? parseFloat(latitudeString) : -1;
+ var longitude = isLongitudeValid ? parseFloat(longitudeString) : -1;
+
+ return new WebInspector.UserAgentSupport.GeolocationPosition(latitude, longitude, errorStatus ? "PositionUnavailable" : "");
+}
+
+WebInspector.UserAgentSupport.GeolocationPosition.clearGeolocationOverride = function()
+{
+ PageAgent.clearGeolocationOverride();
+}
+
WebInspector.UserAgentSupport.prototype = {
_deviceMetricsChanged: function()
{
var metrics = WebInspector.UserAgentSupport.DeviceMetrics.parseSetting(WebInspector.settings.deviceMetrics.get());
if (metrics.isValid())
PageAgent.setDeviceMetricsOverride(metrics.width, metrics.height, metrics.fontScaleFactor, WebInspector.settings.deviceFitWindow.get());
+ },
+
+ _geolocationPositionChanged: function()
+ {
+ var geolocation = WebInspector.UserAgentSupport.GeolocationPosition.parseSetting(WebInspector.settings.geolocationOverride.get());
+ if (geolocation.error)
+ PageAgent.setGeolocationOverride();
+ else
+ PageAgent.setGeolocationOverride(geolocation.latitude, geolocation.longitude, 150);
}
}
+
Modified: trunk/Source/WebCore/inspector/front-end/inspector.js (123633 => 123634)
--- trunk/Source/WebCore/inspector/front-end/inspector.js 2012-07-25 17:43:51 UTC (rev 123633)
+++ trunk/Source/WebCore/inspector/front-end/inspector.js 2012-07-25 17:50:44 UTC (rev 123634)
@@ -434,7 +434,8 @@
ProfilerAgent.isSampling(WebInspector._initializeCapability.bind(WebInspector, "samplingCPUProfiler", null));
ProfilerAgent.hasHeapProfiler(WebInspector._initializeCapability.bind(WebInspector, "heapProfilerPresent", null));
TimelineAgent.supportsFrameInstrumentation(WebInspector._initializeCapability.bind(WebInspector, "timelineSupportsFrameInstrumentation", null));
- PageAgent.canOverrideDeviceMetrics(WebInspector._initializeCapability.bind(WebInspector, "canOverrideDeviceMetrics", WebInspector._doLoadedDoneWithCapabilities.bind(WebInspector)));
+ PageAgent.canOverrideDeviceMetrics(WebInspector._initializeCapability.bind(WebInspector, "canOverrideDeviceMetrics", null));
+ PageAgent.canOverrideGeolocation(WebInspector._initializeCapability.bind(WebInspector, "canOverrideGeolocation", WebInspector._doLoadedDoneWithCapabilities.bind(WebInspector)));
}
WebInspector._doLoadedDoneWithCapabilities = function()