mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 769285 - Use separate access tokens for private and public geolocation requests. r=dougt
This commit is contained in:
parent
6c42deee0b
commit
5b91db75ab
@ -443,10 +443,6 @@ PrivateBrowsingService.prototype = {
|
||||
let sdr = Cc["@mozilla.org/security/sdr;1"].
|
||||
getService(Ci.nsISecretDecoderRing);
|
||||
sdr.logoutAndTeardown();
|
||||
|
||||
try {
|
||||
this._prefs.deleteBranch("geo.wifi.access_token.");
|
||||
} catch (ex) {}
|
||||
|
||||
if (!this._inPrivateBrowsing) {
|
||||
// Clear the error console
|
||||
|
@ -392,10 +392,15 @@ nsGeolocationRequest::Cancel()
|
||||
NS_IMETHODIMP
|
||||
nsGeolocationRequest::Allow()
|
||||
{
|
||||
nsRefPtr<nsGeolocationService> gs = nsGeolocationService::GetGeolocationService();
|
||||
nsCOMPtr<nsIDOMWindow> window;
|
||||
GetWindow(getter_AddRefs(window));
|
||||
nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(window);
|
||||
nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(webNav);
|
||||
bool isPrivate = loadContext && loadContext->UsePrivateBrowsing();
|
||||
|
||||
// Kick off the geo device, if it isn't already running
|
||||
nsresult rv = gs->StartDevice();
|
||||
nsRefPtr<nsGeolocationService> gs = nsGeolocationService::GetGeolocationService();
|
||||
nsresult rv = gs->StartDevice(isPrivate);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
// Location provider error
|
||||
@ -919,7 +924,7 @@ nsGeolocationService::GetCachedPosition()
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGeolocationService::StartDevice()
|
||||
nsGeolocationService::StartDevice(bool aRequestPrivate)
|
||||
{
|
||||
if (!sGeoEnabled || sGeoInitPending) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
@ -944,7 +949,7 @@ nsGeolocationService::StartDevice()
|
||||
|
||||
for (int32_t i = 0; i < mProviders.Count(); i++) {
|
||||
mProviders[i]->Startup();
|
||||
mProviders[i]->Watch(this);
|
||||
mProviders[i]->Watch(this, aRequestPrivate);
|
||||
obs->NotifyObservers(mProviders[i],
|
||||
"geolocation-device-events",
|
||||
NS_LITERAL_STRING("starting").get());
|
||||
|
@ -125,7 +125,7 @@ public:
|
||||
PRBool IsBetterPosition(nsIDOMGeoPosition *aSomewhere);
|
||||
|
||||
// Find and startup a geolocation device (gps, nmea, etc.)
|
||||
nsresult StartDevice();
|
||||
nsresult StartDevice(bool aRequestPrivate);
|
||||
|
||||
// Stop the started geolocation device (gps, nmea, etc.)
|
||||
void StopDevice();
|
||||
|
@ -121,7 +121,7 @@ GPSDProvider.prototype = {
|
||||
this.transport.close(Components.results.NS_OK);
|
||||
},
|
||||
|
||||
watch: function(c) {
|
||||
watch: function(c, isPrivate) {
|
||||
LOG("watch called\n");
|
||||
try {
|
||||
// Go into "watcher" mode
|
||||
|
@ -16,6 +16,9 @@ const Cc = Components.classes;
|
||||
let gLoggingEnabled = false;
|
||||
let gTestingEnabled = false;
|
||||
|
||||
let gPrivateAccessToken = '';
|
||||
let gPrivateAccessTime = 0;
|
||||
|
||||
function LOG(aMsg) {
|
||||
if (gLoggingEnabled)
|
||||
{
|
||||
@ -58,6 +61,11 @@ WifiGeoPositionObject.prototype = {
|
||||
classDescription: "wifi geo location position object"}),
|
||||
};
|
||||
|
||||
function privateBrowsingObserver(aSubject, aTopic, aData) {
|
||||
gPrivateAccessToken = '';
|
||||
gPrivateAccessTime = 0;
|
||||
}
|
||||
|
||||
function WifiGeoPositionProvider() {
|
||||
try {
|
||||
gLoggingEnabled = Services.prefs.getBoolPref("geo.wifi.logging.enabled");
|
||||
@ -71,6 +79,9 @@ function WifiGeoPositionProvider() {
|
||||
this.timer = null;
|
||||
this.hasSeenWiFi = false;
|
||||
this.started = false;
|
||||
this.lastRequestPrivate = false;
|
||||
|
||||
Services.obs.addObserver(privateBrowsingObserver, "last-pb-context-exited", false);
|
||||
}
|
||||
|
||||
WifiGeoPositionProvider.prototype = {
|
||||
@ -96,16 +107,18 @@ WifiGeoPositionProvider.prototype = {
|
||||
this.timer.initWithCallback(this, 200, this.timer.TYPE_REPEATING_SLACK);
|
||||
},
|
||||
|
||||
watch: function(c) {
|
||||
watch: function(c, requestPrivate) {
|
||||
LOG("watch called");
|
||||
if (!this.wifiService) {
|
||||
this.wifiService = Cc["@mozilla.org/wifi/monitor;1"].getService(Components.interfaces.nsIWifiMonitor);
|
||||
this.wifiService.startWatching(this);
|
||||
this.lastRequestPrivate = requestPrivate;
|
||||
}
|
||||
if (this.hasSeenWiFi) {
|
||||
this.hasSeenWiFi = false;
|
||||
this.wifiService.stopWatching(this);
|
||||
this.wifiService.startWatching(this);
|
||||
this.lastRequestPrivate = requestPrivate;
|
||||
}
|
||||
},
|
||||
|
||||
@ -138,11 +151,20 @@ WifiGeoPositionProvider.prototype = {
|
||||
// check to see if we have an access token:
|
||||
let accessToken = "";
|
||||
try {
|
||||
let accessTokenPrefName = "geo.wifi.access_token." + url;
|
||||
accessToken = Services.prefs.getCharPref(accessTokenPrefName);
|
||||
if (this.lastRequestPrivate) {
|
||||
accessToken = gPrivateAccessToken;
|
||||
} else {
|
||||
let accessTokenPrefName = "geo.wifi.access_token." + url;
|
||||
accessToken = Services.prefs.getCharPref(accessTokenPrefName);
|
||||
}
|
||||
|
||||
// check to see if it has expired
|
||||
let accessTokenDate = Services.prefs.getIntPref(accessTokenPrefName + ".time");
|
||||
let accessTokenDate;
|
||||
if (this.lastRequestPrivate) {
|
||||
accessTokenDate = gPrivateAccessTime;
|
||||
} else {
|
||||
Services.prefs.getIntPref(accessTokenPrefName + ".time");
|
||||
}
|
||||
|
||||
let accessTokenInterval = 1209600; // seconds in 2 weeks
|
||||
try {
|
||||
@ -252,17 +274,26 @@ WifiGeoPositionProvider.prototype = {
|
||||
{
|
||||
let accessToken = "";
|
||||
let accessTokenPrefName = "geo.wifi.access_token." + providerUrlBase;
|
||||
try { accessToken = Services.prefs.getCharPref(accessTokenPrefName); } catch (e) {}
|
||||
if (this.lastRequestPrivate) {
|
||||
accessTokenPrefName = gPrivateAccessToken;
|
||||
} else {
|
||||
try { accessToken = Services.prefs.getCharPref(accessTokenPrefName); } catch (e) {}
|
||||
}
|
||||
|
||||
if (accessToken != newAccessToken) {
|
||||
// no match, lets cache
|
||||
LOG("New Access Token: " + newAccessToken + "\n" + accessTokenPrefName);
|
||||
LOG("New Access Token: " + newAccessToken + "\n" + accessTokenPrefName);
|
||||
if (this.lastRequestPrivate) {
|
||||
gPrivateAccessToken = newAccessToken;
|
||||
gPrivateAccessTime = nowInSeconds();
|
||||
} else {
|
||||
try {
|
||||
Services.prefs.setIntPref(accessTokenPrefName + ".time", nowInSeconds());
|
||||
Services.prefs.setCharPref(accessTokenPrefName, newAccessToken);
|
||||
} catch (x) {
|
||||
// XXX temporary hack for bug 575346 to allow geolocation to function
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, false);
|
||||
|
@ -585,7 +585,7 @@ GonkGPSGeolocationProvider::Startup()
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GonkGPSGeolocationProvider::Watch(nsIGeolocationUpdate* aCallback)
|
||||
GonkGPSGeolocationProvider::Watch(nsIGeolocationUpdate* aCallback, bool aPrivate)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
|
@ -35,7 +35,7 @@ interface nsIGeolocationUpdate : nsISupports {
|
||||
* startup is called, any geo location change should call
|
||||
* callback.update().
|
||||
*/
|
||||
[scriptable, uuid(483BE98B-F747-490A-8AF1-53146D2D5373)]
|
||||
[scriptable, uuid(d32b87b3-fe96-4f42-81ab-2f39f7ec43ff)]
|
||||
interface nsIGeolocationProvider : nsISupports {
|
||||
|
||||
/**
|
||||
@ -46,9 +46,12 @@ interface nsIGeolocationProvider : nsISupports {
|
||||
|
||||
/**
|
||||
* watch
|
||||
* When a location change is observed, notify the callback
|
||||
* When a location change is observed, notify the callback. The privacy
|
||||
* argument informs the provider whether the initiating request came from
|
||||
* a private context; it is up to the provider to use that information
|
||||
* in a sensible manner.
|
||||
*/
|
||||
void watch(in nsIGeolocationUpdate callback);
|
||||
void watch(in nsIGeolocationUpdate callback, in boolean requestPrivate);
|
||||
|
||||
/**
|
||||
* shutdown
|
||||
|
Loading…
Reference in New Issue
Block a user