From b88dc31fa225cf07150a90d93a1fc0af2bb00a62 Mon Sep 17 00:00:00 2001 From: Ben Turner Date: Thu, 9 Sep 2010 15:15:40 -0700 Subject: [PATCH] Bug 591516 - 'IndexedDB: Add some UI to prompt for IndexedDB permissions'. r=sicking+gavin. --- browser/base/content/browser.css | 1 + browser/base/content/browser.js | 88 +++++++ browser/base/content/browser.xul | 1 + .../en-US/chrome/browser/browser.properties | 4 + .../themes/gnomestripe/browser/browser.css | 9 + browser/themes/pinstripe/browser/browser.css | 9 + browser/themes/winstripe/browser/browser.css | 9 + dom/base/nsGlobalWindow.cpp | 11 +- dom/base/nsGlobalWindow.h | 7 +- dom/base/nsPIDOMWindow.h | 7 + dom/indexedDB/AsyncConnectionHelper.cpp | 7 + dom/indexedDB/AsyncConnectionHelper.h | 6 + dom/indexedDB/CheckPermissionsHelper.cpp | 198 +++++++++++++++ dom/indexedDB/CheckPermissionsHelper.h | 93 +++++++ dom/indexedDB/CheckQuotaHelper.cpp | 226 ++++++++++++++++++ dom/indexedDB/CheckQuotaHelper.h | 92 +++++++ dom/indexedDB/IDBDatabase.cpp | 67 +++++- dom/indexedDB/IDBDatabase.h | 8 + dom/indexedDB/IDBFactory.cpp | 215 ++++++++++++++--- dom/indexedDB/IDBFactory.h | 15 +- dom/indexedDB/IDBTransaction.cpp | 14 +- dom/indexedDB/Makefile.in | 3 + dom/indexedDB/test/helpers.js | 8 + modules/libpref/src/init/all.js | 5 + 24 files changed, 1048 insertions(+), 55 deletions(-) create mode 100644 dom/indexedDB/CheckPermissionsHelper.cpp create mode 100644 dom/indexedDB/CheckPermissionsHelper.h create mode 100644 dom/indexedDB/CheckQuotaHelper.cpp create mode 100644 dom/indexedDB/CheckQuotaHelper.h diff --git a/browser/base/content/browser.css b/browser/base/content/browser.css index 00780019b4d9..4cd789851c15 100644 --- a/browser/base/content/browser.css +++ b/browser/base/content/browser.css @@ -366,6 +366,7 @@ window[chromehidden~="toolbar"] toolbar:not(.toolbar-primary):not(.chromeclass-m } #notification-popup-box[anchorid="geo-notification-icon"] > #geo-notification-icon, +#notification-popup-box[anchorid="indexedDB-notification-icon"] > #indexedDB-notification-icon, #notification-popup-box[anchorid="addons-notification-icon"] > #addons-notification-icon { display: -moz-box; } diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 98c22782c01c..f13f9863ccbd 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -1321,6 +1321,7 @@ function delayedStartup(isLoadingBlank, mustLoadSidebar) { BrowserOffline.init(); OfflineApps.init(); + IndexedDBPromptHelper.init(); gBrowser.addEventListener("pageshow", function(evt) { setTimeout(pageShowEventHandlers, 0, evt); }, true); @@ -1580,6 +1581,7 @@ function BrowserShutdown() OfflineApps.uninit(); DownloadMonitorPanel.uninit(); gPrivateBrowsingUI.uninit(); + IndexedDBPromptHelper.uninit(); var enumerator = Services.wm.getEnumerator(null); enumerator.getNext(); @@ -5852,6 +5854,92 @@ var OfflineApps = { } }; +var IndexedDBPromptHelper = { + _permissionsPrompt: "indexedDB-permissions-prompt", + _permissionsResponse: "indexedDB-permissions-response", + + _quotaPrompt: "indexedDB-quota-prompt", + _quotaResponse: "indexedDB-quota-response", + + _notificationIcon: "indexedDB-notification-icon", + + init: + function IndexedDBPromptHelper_init() { + Services.obs.addObserver(this, this._permissionsPrompt, false); + Services.obs.addObserver(this, this._quotaPrompt, false); + }, + + uninit: + function IndexedDBPromptHelper_uninit() { + Services.obs.removeObserver(this, this._permissionsPrompt, false); + Services.obs.removeObserver(this, this._quotaPrompt, false); + }, + + observe: + function IndexedDBPromptHelper_observe(subject, topic, data) { + if (topic != this._permissionsPrompt && + topic != this._quotaPrompt) { + throw new Error("Unexpected topic!"); + } + + var requestor = subject.QueryInterface(Ci.nsIInterfaceRequestor); + + var contentWindow = requestor.getInterface(Ci.nsIDOMWindow); + var contentDocument = contentWindow.document; + var browserWindow = + OfflineApps._getBrowserWindowForContentWindow(contentWindow); + var browser = + OfflineApps._getBrowserForContentWindow(browserWindow, contentWindow); + + if (!browser) { + // Must belong to some other window. + return; + } + + var host = contentDocument.documentURIObject.asciiHost; + + var message; + var responseTopic; + if (topic == this._permissionsPrompt) { + message = gNavigatorBundle.getFormattedString("offlineApps.available", + [ host ]); + responseTopic = this._permissionsResponse; + } + else if (topic == this._quotaPrompt) { + message = gNavigatorBundle.getFormattedString("indexedDB.usage", + [ host, data ]); + responseTopic = this._quotaResponse; + } + + var self = this; + var observer = requestor.getInterface(Ci.nsIObserver); + + var mainAction = { + label: gNavigatorBundle.getString("offlineApps.allow"), + accessKey: gNavigatorBundle.getString("offlineApps.allowAccessKey"), + callback: function() { + observer.observe(null, responseTopic, + Ci.nsIPermissionManager.ALLOW_ACTION); + } + }; + + var secondaryActions = [ + { + label: gNavigatorBundle.getString("offlineApps.never"), + accessKey: gNavigatorBundle.getString("offlineApps.neverAccessKey"), + callback: function() { + observer.observe(null, responseTopic, + Ci.nsIPermissionManager.DENY_ACTION); + } + } + ]; + + PopupNotifications.show(browser, topic, message, this._notificationIcon, + mainAction, secondaryActions); + + } +}; + function WindowIsClosing() { var reallyClose = closeWindow(false, warnAboutClosingWindow); diff --git a/browser/base/content/browser.xul b/browser/base/content/browser.xul index 7ac3732855de..3fecf9c282fe 100644 --- a/browser/base/content/browser.xul +++ b/browser/base/content/browser.xul @@ -875,6 +875,7 @@