michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /** michael@0: * Helper class for IndexedDB, parent part. Listens to michael@0: * messages from the child and shows prompts for them. michael@0: */ michael@0: let IndexedDB = { michael@0: _permissionsPrompt: "indexedDB-permissions-prompt", michael@0: _permissionsResponse: "indexedDB-permissions-response", michael@0: michael@0: _quotaPrompt: "indexedDB-quota-prompt", michael@0: _quotaResponse: "indexedDB-quota-response", michael@0: _quotaCancel: "indexedDB-quota-cancel", michael@0: michael@0: _notificationIcon: "indexedDB-notification-icon", michael@0: michael@0: receiveMessage: function(aMessage) { michael@0: switch (aMessage.name) { michael@0: case "IndexedDB:Prompt": michael@0: this.showPrompt(aMessage); michael@0: } michael@0: }, michael@0: michael@0: showPrompt: function(aMessage) { michael@0: let browser = aMessage.target; michael@0: let payload = aMessage.json; michael@0: let host = payload.host; michael@0: let topic = payload.topic; michael@0: let type; michael@0: michael@0: if (topic == this._permissionsPrompt) { michael@0: type = "indexedDB"; michael@0: payload.responseTopic = this._permissionsResponse; michael@0: } else if (topic == this._quotaPrompt) { michael@0: type = "indexedDBQuota"; michael@0: payload.responseTopic = this._quotaResponse; michael@0: } else if (topic == this._quotaCancel) { michael@0: payload.permission = Ci.nsIPermissionManager.UNKNOWN_ACTION; michael@0: browser.messageManager.sendAsyncMessage("IndexedDB:Response", payload); michael@0: // XXX Need to actually save this? michael@0: return; michael@0: } michael@0: michael@0: let prompt = Cc["@mozilla.org/content-permission/prompt;1"].createInstance(Ci.nsIContentPermissionPrompt); michael@0: let types = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray); michael@0: let promptType = { michael@0: type: type, michael@0: access: "unused", michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPermissionType]) michael@0: }; michael@0: types.appendElement(promptType, false); michael@0: michael@0: // If the user waits a long time before responding, we default to UNKNOWN_ACTION. michael@0: let timeoutId = setTimeout(function() { michael@0: payload.permission = Ci.nsIPermissionManager.UNKNOWN_ACTION; michael@0: browser.messageManager.sendAsyncMessage("IndexedDB:Response", payload); michael@0: timeoutId = null; michael@0: }, 30000); michael@0: michael@0: function checkTimeout() { michael@0: if (timeoutId === null) return true; michael@0: clearTimeout(timeoutId); michael@0: timeoutId = null; michael@0: return false; michael@0: } michael@0: michael@0: prompt.prompt({ michael@0: types: types, michael@0: uri: Services.io.newURI(payload.location, null, null), michael@0: window: null, michael@0: element: aMessage.target, michael@0: michael@0: cancel: function() { michael@0: if (checkTimeout()) return; michael@0: payload.permission = Ci.nsIPermissionManager.DENY_ACTION; michael@0: browser.messageManager.sendAsyncMessage("IndexedDB:Response", payload); michael@0: }, michael@0: michael@0: allow: function() { michael@0: if (checkTimeout()) return; michael@0: payload.permission = Ci.nsIPermissionManager.ALLOW_ACTION; michael@0: browser.messageManager.sendAsyncMessage("IndexedDB:Response", payload); michael@0: }, michael@0: }); michael@0: }, michael@0: }; michael@0: