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