From dac27aaeeb5ec7c712e9c8440938e4f3a39197a3 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas <21@vingtetun.org> Date: Thu, 22 Jul 2010 01:41:25 +0200 Subject: [PATCH] Bug 580576 - Clicking 'Share your location' in Fennec fails with an error in GeolocationPrompt.js [r=mfinkle] --- mobile/components/GeolocationPrompt.js | 85 ++++++++++++++------------ 1 file changed, 45 insertions(+), 40 deletions(-) diff --git a/mobile/components/GeolocationPrompt.js b/mobile/components/GeolocationPrompt.js index 80370544919..db68c0e1b5b 100644 --- a/mobile/components/GeolocationPrompt.js +++ b/mobile/components/GeolocationPrompt.js @@ -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"); } } };