Bug 580576 - Clicking 'Share your location' in Fennec fails with an error in GeolocationPrompt.js [r=mfinkle]

This commit is contained in:
Vivien Nicolas 2010-07-22 01:41:25 +02:00
Родитель 033385d8dd
Коммит dac27aaeeb
1 изменённых файлов: 45 добавлений и 40 удалений

Просмотреть файл

@ -10,45 +10,45 @@ const kCountBeforeWeRemember = 5;
function GeolocationPrompt() {}
GeolocationPrompt.prototype = {
classID: Components.ID("{C6E8C44D-9F39-4AF7-BCC0-76E38A8310F5}"),
classID: Components.ID("{C6E8C44D-9F39-4AF7-BCC0-76E38A8310F5}"),
QueryInterface: XPCOMUtils.generateQI([Ci.nsIGeolocationPrompt]),
prompt: function(request) {
var result = Services.perms.testExactPermission(request.requestingURI, "geo");
prompt: function(aRequest) {
let pm = Services.perms;
let result = pm.testExactPermission(aRequest.requestingURI, "geo");
if (result == Ci.nsIPermissionManager.ALLOW_ACTION) {
request.allow();
aRequest.allow();
return;
}
if (result == Ci.nsIPermissionManager.DENY_ACTION) {
request.cancel();
} else if (result == Ci.nsIPermissionManager.DENY_ACTION) {
aRequest.cancel();
return;
}
function setPagePermission(uri, allow) {
var prefService = Services.prefs;
if (! prefService.hasPref(request.requestingURI, "geo.request.remember"))
prefService.setPref(request.requestingURI, "geo.request.remember", 0);
var count = prefService.getPref(request.requestingURI, "geo.request.remember");
if (allow == false)
function setPagePermission(aUri, aAllow) {
let contentPrefs = Services.contentPrefs;
if (!contentPrefs.hasPref(aRequest.requestingURI, "geo.request.remember"))
contentPrefs.setPref(aRequest.requestingURI, "geo.request.remember", 0);
let count = contentPrefs.getPref(aRequest.requestingURI, "geo.request.remember");
if (aAllow == false)
count--;
else
count++;
prefService.setPref(request.requestingURI, "geo.request.remember", count);
contentPrefs.setPref(aRequest.requestingURI, "geo.request.remember", count);
if (count == kCountBeforeWeRemember)
pm.add(uri, "geo", Ci.nsIPermissionManager.ALLOW_ACTION);
pm.add(aUri, "geo", Ci.nsIPermissionManager.ALLOW_ACTION);
else if (count == -kCountBeforeWeRemember)
pm.add(uri, "geo", Ci.nsIPermissionManager.DENY_ACTION);
pm.add(aUri, "geo", Ci.nsIPermissionManager.DENY_ACTION);
}
function getChromeWindow(aWindow) {
var chromeWin = aWindow
let chromeWin = aWindow
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)
@ -59,42 +59,47 @@ GeolocationPrompt.prototype = {
return chromeWin;
}
var requestingWindow = request.requestingWindow.top;
var chromeWin = getChromeWindow(requestingWindow).wrappedJSObject;
let notificationBox = null;
if (aRequest.requestingWindow) {
let requestingWindow = aRequest.requestingWindow.top;
let chromeWin = getChromeWindow(requestingWindow).wrappedJSObject;
notificationBox = chromeWin.getNotificationBox(requestingWindow);
} else {
let chromeWin = aRequest.requestingElement.ownerDocument.defaultView;
notificationBox = chromeWin.Browser.getNotificationBox();
}
var notificationBox = chromeWin.getNotificationBox(requestingWindow);
var notification = notificationBox.getNotificationWithValue("geolocation");
let notification = notificationBox.getNotificationWithValue("geolocation");
if (!notification) {
var browserBundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
let browserBundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
var buttons = [{
let buttons = [{
label: browserBundle.GetStringFromName("geolocation.share"),
accessKey: null,
callback: function(notification) {
setPagePermission(request.requestingURI, true);
request.allow();
setPagePermission(aRequest.requestingURI, true);
aRequest.allow();
},
},
{
label: browserBundle.GetStringFromName("geolocation.dontShare"),
accessKey: null,
callback: function(notification) {
setPagePermission(request.requestingURI, false);
request.cancel();
setPagePermission(aRequest.requestingURI, false);
aRequest.cancel();
},
}];
var message = browserBundle.formatStringFromName("geolocation.siteWantsToKnow",
[request.requestingURI.host], 1);
var newBar = notificationBox.appendNotification(message,
let message = browserBundle.formatStringFromName("geolocation.siteWantsToKnow",
[aRequest.requestingURI.host], 1);
let newBar = notificationBox.appendNotification(message,
"geolocation",
"chrome://browser/skin/images/geo-16.png",
notificationBox.PRIORITY_WARNING_MEDIUM,
buttons);
// Make this a geolocation notification.
newBar.setAttribute("type", "geo");
newBar.setAttribute("type", "geo");
}
}
};