From 1e7d4167bafe4ee8ce8d9379ebbf80bd9a85fc72 Mon Sep 17 00:00:00 2001 From: Doug Turner Date: Wed, 3 Sep 2008 15:05:15 -0700 Subject: [PATCH] Bug 444642 - Hookup geolocation prompt to notification prompt. r=gavin/mconnor --- browser/base/content/browser.js | 59 +++++++++++++++++++ .../en-US/chrome/browser/browser.properties | 9 +++ 2 files changed, 68 insertions(+) diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index e3d637ff404..dfc95e9429c 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -910,6 +910,61 @@ function prepareForStartup() { gBrowser.addEventListener("DOMLinkAdded", DOMLinkHandler, false); } +function setupGeolocationPrompt() +{ + var geolocationService = Cc["@mozilla.org/geolocation/service;1"].getService(Ci.nsIGeolocationService); + + if (geolocationService.prompt) + return; + + geolocationService.prompt = function(request) { + + function getChromeWindow(aWindow) { + var chromeWin = aWindow + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebNavigation) + .QueryInterface(Ci.nsIDocShellTreeItem) + .rootTreeItem + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDOMWindow) + .QueryInterface(Ci.nsIDOMChromeWindow); + return chromeWin; + } + + var requestingWindow = request.requestingWindow.top; + var tabbrowser = getChromeWindow(requestingWindow).wrappedJSObject.gBrowser; + var browser = tabbrowser.getBrowserForDocument(requestingWindow.document); + var notificationBox = tabbrowser.getNotificationBox(browser); + + var notification = notificationBox.getNotificationWithValue("geolocation"); + if (!notification) { + + var buttons = [{ + label: gNavigatorBundle.getString("geolocation.exactLocation"), + accessKey: gNavigatorBundle.getString("geolocation.exactLocationKey"), + callback: function() request.allow() , + }, + { + label: gNavigatorBundle.getString("geolocation.neighborhoodLocation"), + accessKey: gNavigatorBundle.getString("geolocation.neighborhoodLocationKey"), + callback: function() request.allowButFuzz() , + }, + { + label: gNavigatorBundle.getString("geolocation.nothingLocation"), + accessKey: gNavigatorBundle.getString("geolocation.nothingLocationKey"), + callback: function() request.cancel() , + }]; + + var message = gNavigatorBundle.getFormattedString("geolocation.requestMessage", [request.requestingURI.spec]); + notificationBox.appendNotification(message, + "geolocation", + "chrome://browser/skin/Info.png", + notificationBox.PRIORITY_INFO_HIGH, + buttons); + } + }; +} + function delayedStartup(isLoadingBlank, mustLoadSidebar) { var os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService); os.addObserver(gSessionHistoryObserver, "browser:purge-session-history", false); @@ -1105,6 +1160,10 @@ function delayedStartup(isLoadingBlank, mustLoadSidebar) { placesContext.addEventListener("popupshowing", updateEditUIVisibility, false); placesContext.addEventListener("popuphiding", updateEditUIVisibility, false); #endif + + // hook up the geolocation prompt to our notificationBox + setupGeolocationPrompt(); + } function BrowserShutdown() diff --git a/browser/locales/en-US/chrome/browser/browser.properties b/browser/locales/en-US/chrome/browser/browser.properties index fa551306bb7..55e375aaa12 100644 --- a/browser/locales/en-US/chrome/browser/browser.properties +++ b/browser/locales/en-US/chrome/browser/browser.properties @@ -135,3 +135,12 @@ editBookmarkPanel.pageBookmarkedTitle=Page Bookmarked editBookmarkPanel.pageBookmarkedDescription=%S will always remember this page for you. editBookmarkPanel.bookmarkedRemovedTitle=Bookmark Removed editBookmarkPanel.editBookmarkTitle=Edit This Bookmark + +# Geolocation UI +geolocation.exactLocation=Exact Location (within 10 feet) +geolocation.exactLocationKey=E +geolocation.neighborhoodLocation=Neighborhood (within 1 mile) +geolocation.neighborhoodLocationKey=N +geolocation.nothingLocation=Nothing +geolocation.nothingLocationKey=o +geolocation.requestMessage=%S wants to know where you are. Tell them: