mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 19:35:51 +00:00
Bug 886026 - Make ClearWatch work for pending request. r=jdm
This commit is contained in:
parent
1a62fe571b
commit
6ce0a1b25e
@ -433,6 +433,10 @@ nsGeolocationRequest::GetElement(nsIDOMElement * *aRequestingElement)
|
||||
NS_IMETHODIMP
|
||||
nsGeolocationRequest::Cancel()
|
||||
{
|
||||
if (mLocator->ClearPendingRequest(this)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NotifyError(nsIDOMGeoPositionError::PERMISSION_DENIED);
|
||||
return NS_OK;
|
||||
}
|
||||
@ -442,6 +446,10 @@ nsGeolocationRequest::Allow(JS::HandleValue aChoices)
|
||||
{
|
||||
MOZ_ASSERT(aChoices.isUndefined());
|
||||
|
||||
if (mLocator->ClearPendingRequest(this)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Kick off the geo device, if it isn't already running
|
||||
nsRefPtr<nsGeolocationService> gs = nsGeolocationService::GetGeolocationService();
|
||||
nsresult rv = gs->StartDevice(GetPrincipal());
|
||||
@ -1304,6 +1312,28 @@ Geolocation::NotifyError(uint16_t aErrorCode)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool
|
||||
Geolocation::IsAlreadyCleared(nsGeolocationRequest* aRequest)
|
||||
{
|
||||
for (uint32_t i = 0, length = mClearedWatchIDs.Length(); i < length; ++i) {
|
||||
if (mClearedWatchIDs[i] == aRequest->WatchId()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
Geolocation::ClearPendingRequest(nsGeolocationRequest* aRequest)
|
||||
{
|
||||
if (aRequest->IsWatch() && this->IsAlreadyCleared(aRequest)) {
|
||||
this->NotifyAllowedRequest(aRequest);
|
||||
this->ClearWatch(aRequest->WatchId());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
Geolocation::GetCurrentPosition(PositionCallback& aCallback,
|
||||
PositionErrorCallback* aErrorCallback,
|
||||
@ -1489,10 +1519,15 @@ Geolocation::ClearWatch(int32_t aWatchId)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!mClearedWatchIDs.Contains(aWatchId)) {
|
||||
mClearedWatchIDs.AppendElement(aWatchId);
|
||||
}
|
||||
|
||||
for (uint32_t i = 0, length = mWatchingCallbacks.Length(); i < length; ++i) {
|
||||
if (mWatchingCallbacks[i]->WatchId() == aWatchId) {
|
||||
mWatchingCallbacks[i]->Shutdown();
|
||||
RemoveRequest(mWatchingCallbacks[i]);
|
||||
mClearedWatchIDs.RemoveElement(aWatchId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -154,6 +154,10 @@ public:
|
||||
// Remove request from all callbacks arrays
|
||||
void RemoveRequest(nsGeolocationRequest* request);
|
||||
|
||||
// Check if there is already ClearWatch called for current
|
||||
// request & clear if yes
|
||||
bool ClearPendingRequest(nsGeolocationRequest* aRequest);
|
||||
|
||||
// Shutting down.
|
||||
void Shutdown();
|
||||
|
||||
@ -185,6 +189,9 @@ private:
|
||||
nsresult GetCurrentPositionReady(nsGeolocationRequest* aRequest);
|
||||
nsresult WatchPositionReady(nsGeolocationRequest* aRequest);
|
||||
|
||||
// Check if clearWatch is already called
|
||||
bool IsAlreadyCleared(nsGeolocationRequest* aRequest);
|
||||
|
||||
// Two callback arrays. The first |mPendingCallbacks| holds objects for only
|
||||
// one callback and then they are released/removed from the array. The second
|
||||
// |mWatchingCallbacks| holds objects until the object is explictly removed or
|
||||
@ -208,6 +215,9 @@ private:
|
||||
|
||||
// Pending requests are used when the service is not ready
|
||||
nsTArray<nsRefPtr<nsGeolocationRequest> > mPendingRequests;
|
||||
|
||||
// Array containing already cleared watch IDs
|
||||
nsTArray<int32_t> mClearedWatchIDs;
|
||||
};
|
||||
|
||||
class PositionError MOZ_FINAL : public nsIDOMGeoPositionError,
|
||||
|
@ -17,6 +17,8 @@ skip-if = buildapp == 'b2g'
|
||||
skip-if = buildapp == 'b2g'
|
||||
[test_clearWatch.html]
|
||||
skip-if = buildapp == 'b2g' || toolkit == 'android' #TIMED_OUT
|
||||
[test_clearWatchBeforeAllowing.html]
|
||||
skip-if = buildapp == 'b2g' || toolkit == 'android' #TIMED_OUT
|
||||
[test_clearWatch_invalid.html]
|
||||
skip-if = buildapp == 'b2g'
|
||||
[test_errorcheck.html]
|
||||
@ -47,4 +49,4 @@ skip-if = buildapp == 'b2g' || toolkit == 'android' || e10s #TIMED_OUT
|
||||
[test_windowClose.html]
|
||||
skip-if = buildapp == 'b2g' || toolkit == 'android' #TIMED_OUT
|
||||
[test_worseAccuracyDoesNotBlockCallback.html]
|
||||
skip-if = buildapp == 'b2g' || toolkit == 'android' #TIMED_OUT
|
||||
skip-if = buildapp == 'b2g' || toolkit == 'android' #TIMED_OUT
|
@ -0,0 +1,59 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=886026
|
||||
-->
|
||||
<head>
|
||||
<title>Test for getCurrentPosition </title>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="geolocation_common.js"></script>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank"
|
||||
href="https://bugzilla.mozilla.org/show_bug.cgi?id=886026">Mozilla Bug 886026</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
resume_geolocationProvider(function() {
|
||||
force_prompt(true, run_test);
|
||||
});
|
||||
|
||||
function run_test() {
|
||||
var successCallbackCalled = false,
|
||||
errorCallbackCalled = false;
|
||||
|
||||
var watchId = navigator.geolocation.watchPosition(
|
||||
function(pos) {
|
||||
successCallbackCalled = true;
|
||||
}, function(err) {
|
||||
errorCallbackCalled = true;
|
||||
}
|
||||
);
|
||||
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
function(pos) {
|
||||
SimpleTest.executeSoon(function() {
|
||||
ok(successCallbackCalled == false,
|
||||
"getCurrentPosition : Success callback should not have been called");
|
||||
|
||||
ok(errorCallbackCalled == false,
|
||||
"getCurrentPosition : Error callback should not have been called");
|
||||
|
||||
SimpleTest.finish();
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
navigator.geolocation.clearWatch(watchId);
|
||||
}
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user