gecko-dev/toolkit/components/extensions/ext-geolocation.js
Kris Maglione 56c459b23c Bug 1350522: Part 6 - Cleanup per-api-instance state logic. r=aswan
MozReview-Commit-ID: 5ixBA34fvFf

--HG--
extra : source : 650808cfe044339ceae30dbd79ef931330f78049
extra : histedit_source : 30316d0b7321bdceaf93fa9dde096579b6251354
2017-03-25 11:36:56 -07:00

31 lines
1.1 KiB
JavaScript

"use strict";
XPCOMUtils.defineLazyModuleGetter(this, "Services",
"resource://gre/modules/Services.jsm");
// If the user has changed the permission on the addon to something other than
// always allow, then we want to preserve that choice. We only set the
// permission if it is not set (unknown_action), and we only remove the
// permission on shutdown if it is always allow.
this.geolocation = class extends ExtensionAPI {
onStartup() {
let {extension} = this;
if (extension.hasPermission("geolocation") &&
Services.perms.testPermission(extension.principal.URI, "geo") == Services.perms.UNKNOWN_ACTION) {
Services.perms.add(extension.principal.URI, "geo",
Services.perms.ALLOW_ACTION,
Services.perms.EXPIRE_SESSION);
}
}
onShutdown() {
let {extension} = this;
if (extension.hasPermission("geolocation") &&
Services.perms.testPermission(extension.principal.URI, "geo") == Services.perms.ALLOW_ACTION) {
Services.perms.remove(extension.principal.URI, "geo");
}
}
};