Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | /** |
michael@0 | 6 | * Helper class for IndexedDB, parent part. Listens to |
michael@0 | 7 | * messages from the child and shows prompts for them. |
michael@0 | 8 | */ |
michael@0 | 9 | let IndexedDB = { |
michael@0 | 10 | _permissionsPrompt: "indexedDB-permissions-prompt", |
michael@0 | 11 | _permissionsResponse: "indexedDB-permissions-response", |
michael@0 | 12 | |
michael@0 | 13 | _quotaPrompt: "indexedDB-quota-prompt", |
michael@0 | 14 | _quotaResponse: "indexedDB-quota-response", |
michael@0 | 15 | _quotaCancel: "indexedDB-quota-cancel", |
michael@0 | 16 | |
michael@0 | 17 | _notificationIcon: "indexedDB-notification-icon", |
michael@0 | 18 | |
michael@0 | 19 | receiveMessage: function(aMessage) { |
michael@0 | 20 | switch (aMessage.name) { |
michael@0 | 21 | case "IndexedDB:Prompt": |
michael@0 | 22 | this.showPrompt(aMessage); |
michael@0 | 23 | } |
michael@0 | 24 | }, |
michael@0 | 25 | |
michael@0 | 26 | showPrompt: function(aMessage) { |
michael@0 | 27 | let browser = aMessage.target; |
michael@0 | 28 | let payload = aMessage.json; |
michael@0 | 29 | let host = payload.host; |
michael@0 | 30 | let topic = payload.topic; |
michael@0 | 31 | let type; |
michael@0 | 32 | |
michael@0 | 33 | if (topic == this._permissionsPrompt) { |
michael@0 | 34 | type = "indexedDB"; |
michael@0 | 35 | payload.responseTopic = this._permissionsResponse; |
michael@0 | 36 | } else if (topic == this._quotaPrompt) { |
michael@0 | 37 | type = "indexedDBQuota"; |
michael@0 | 38 | payload.responseTopic = this._quotaResponse; |
michael@0 | 39 | } else if (topic == this._quotaCancel) { |
michael@0 | 40 | payload.permission = Ci.nsIPermissionManager.UNKNOWN_ACTION; |
michael@0 | 41 | browser.messageManager.sendAsyncMessage("IndexedDB:Response", payload); |
michael@0 | 42 | // XXX Need to actually save this? |
michael@0 | 43 | return; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | let prompt = Cc["@mozilla.org/content-permission/prompt;1"].createInstance(Ci.nsIContentPermissionPrompt); |
michael@0 | 47 | let types = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray); |
michael@0 | 48 | let promptType = { |
michael@0 | 49 | type: type, |
michael@0 | 50 | access: "unused", |
michael@0 | 51 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPermissionType]) |
michael@0 | 52 | }; |
michael@0 | 53 | types.appendElement(promptType, false); |
michael@0 | 54 | |
michael@0 | 55 | // If the user waits a long time before responding, we default to UNKNOWN_ACTION. |
michael@0 | 56 | let timeoutId = setTimeout(function() { |
michael@0 | 57 | payload.permission = Ci.nsIPermissionManager.UNKNOWN_ACTION; |
michael@0 | 58 | browser.messageManager.sendAsyncMessage("IndexedDB:Response", payload); |
michael@0 | 59 | timeoutId = null; |
michael@0 | 60 | }, 30000); |
michael@0 | 61 | |
michael@0 | 62 | function checkTimeout() { |
michael@0 | 63 | if (timeoutId === null) return true; |
michael@0 | 64 | clearTimeout(timeoutId); |
michael@0 | 65 | timeoutId = null; |
michael@0 | 66 | return false; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | prompt.prompt({ |
michael@0 | 70 | types: types, |
michael@0 | 71 | uri: Services.io.newURI(payload.location, null, null), |
michael@0 | 72 | window: null, |
michael@0 | 73 | element: aMessage.target, |
michael@0 | 74 | |
michael@0 | 75 | cancel: function() { |
michael@0 | 76 | if (checkTimeout()) return; |
michael@0 | 77 | payload.permission = Ci.nsIPermissionManager.DENY_ACTION; |
michael@0 | 78 | browser.messageManager.sendAsyncMessage("IndexedDB:Response", payload); |
michael@0 | 79 | }, |
michael@0 | 80 | |
michael@0 | 81 | allow: function() { |
michael@0 | 82 | if (checkTimeout()) return; |
michael@0 | 83 | payload.permission = Ci.nsIPermissionManager.ALLOW_ACTION; |
michael@0 | 84 | browser.messageManager.sendAsyncMessage("IndexedDB:Response", payload); |
michael@0 | 85 | }, |
michael@0 | 86 | }); |
michael@0 | 87 | }, |
michael@0 | 88 | }; |
michael@0 | 89 |