1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/metro/base/content/helperui/IndexedDB.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,89 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +/** 1.9 + * Helper class for IndexedDB, parent part. Listens to 1.10 + * messages from the child and shows prompts for them. 1.11 + */ 1.12 +let IndexedDB = { 1.13 + _permissionsPrompt: "indexedDB-permissions-prompt", 1.14 + _permissionsResponse: "indexedDB-permissions-response", 1.15 + 1.16 + _quotaPrompt: "indexedDB-quota-prompt", 1.17 + _quotaResponse: "indexedDB-quota-response", 1.18 + _quotaCancel: "indexedDB-quota-cancel", 1.19 + 1.20 + _notificationIcon: "indexedDB-notification-icon", 1.21 + 1.22 + receiveMessage: function(aMessage) { 1.23 + switch (aMessage.name) { 1.24 + case "IndexedDB:Prompt": 1.25 + this.showPrompt(aMessage); 1.26 + } 1.27 + }, 1.28 + 1.29 + showPrompt: function(aMessage) { 1.30 + let browser = aMessage.target; 1.31 + let payload = aMessage.json; 1.32 + let host = payload.host; 1.33 + let topic = payload.topic; 1.34 + let type; 1.35 + 1.36 + if (topic == this._permissionsPrompt) { 1.37 + type = "indexedDB"; 1.38 + payload.responseTopic = this._permissionsResponse; 1.39 + } else if (topic == this._quotaPrompt) { 1.40 + type = "indexedDBQuota"; 1.41 + payload.responseTopic = this._quotaResponse; 1.42 + } else if (topic == this._quotaCancel) { 1.43 + payload.permission = Ci.nsIPermissionManager.UNKNOWN_ACTION; 1.44 + browser.messageManager.sendAsyncMessage("IndexedDB:Response", payload); 1.45 + // XXX Need to actually save this? 1.46 + return; 1.47 + } 1.48 + 1.49 + let prompt = Cc["@mozilla.org/content-permission/prompt;1"].createInstance(Ci.nsIContentPermissionPrompt); 1.50 + let types = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray); 1.51 + let promptType = { 1.52 + type: type, 1.53 + access: "unused", 1.54 + QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPermissionType]) 1.55 + }; 1.56 + types.appendElement(promptType, false); 1.57 + 1.58 + // If the user waits a long time before responding, we default to UNKNOWN_ACTION. 1.59 + let timeoutId = setTimeout(function() { 1.60 + payload.permission = Ci.nsIPermissionManager.UNKNOWN_ACTION; 1.61 + browser.messageManager.sendAsyncMessage("IndexedDB:Response", payload); 1.62 + timeoutId = null; 1.63 + }, 30000); 1.64 + 1.65 + function checkTimeout() { 1.66 + if (timeoutId === null) return true; 1.67 + clearTimeout(timeoutId); 1.68 + timeoutId = null; 1.69 + return false; 1.70 + } 1.71 + 1.72 + prompt.prompt({ 1.73 + types: types, 1.74 + uri: Services.io.newURI(payload.location, null, null), 1.75 + window: null, 1.76 + element: aMessage.target, 1.77 + 1.78 + cancel: function() { 1.79 + if (checkTimeout()) return; 1.80 + payload.permission = Ci.nsIPermissionManager.DENY_ACTION; 1.81 + browser.messageManager.sendAsyncMessage("IndexedDB:Response", payload); 1.82 + }, 1.83 + 1.84 + allow: function() { 1.85 + if (checkTimeout()) return; 1.86 + payload.permission = Ci.nsIPermissionManager.ALLOW_ACTION; 1.87 + browser.messageManager.sendAsyncMessage("IndexedDB:Response", payload); 1.88 + }, 1.89 + }); 1.90 + }, 1.91 +}; 1.92 +