Mercurial > powerbox
comparison extension/modules/content-injector.js @ 3:413435fc6202
We now show a notification box when a page calls window.powerbox.request().
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Thu, 06 Aug 2009 15:50:24 -0700 |
parents | 889c2fd4c9cf |
children | 1c02976d8809 |
comparison
equal
deleted
inserted
replaced
2:889c2fd4c9cf | 3:413435fc6202 |
---|---|
2 | 2 |
3 const Cc = Components.classes; | 3 const Cc = Components.classes; |
4 const Ci = Components.interfaces; | 4 const Ci = Components.interfaces; |
5 const Cu = Components.utils; | 5 const Cu = Components.utils; |
6 | 6 |
7 const REQUEST_BOX_NAME = "powerbox_superpower_request"; | |
8 const REQUEST_BOX_TEXT = "This web page wants superpowers."; | |
9 const REQUEST_BOX_BUTTON_TEXT = "Huh?"; | |
10 | |
7 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); | 11 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); |
12 | |
13 function getParentChromeWindow(window) { | |
14 var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor) | |
15 .getInterface(Ci.nsIWebNavigation) | |
16 .QueryInterface(Ci.nsIDocShellTreeItem) | |
17 .rootTreeItem | |
18 .QueryInterface(Ci.nsIInterfaceRequestor) | |
19 .getInterface(Ci.nsIDOMWindow); | |
20 return mainWindow.wrappedJSObject; | |
21 } | |
22 | |
23 function showRequestNotificationBox(window, caps, callback) { | |
24 var tabbrowser = getParentChromeWindow(window).getBrowser(); | |
25 var browser = tabbrowser.getBrowserForDocument(window.document); | |
26 | |
27 if (browser) { | |
28 var nBox = tabbrowser.getNotificationBox(browser); | |
29 | |
30 var oldNotification = nBox.getNotificationWithValue(REQUEST_BOX_NAME); | |
31 if (oldNotification) | |
32 nBox.removeNotification(oldNotification); | |
33 | |
34 nBox.appendNotification(REQUEST_BOX_TEXT, | |
35 REQUEST_BOX_NAME, | |
36 null, | |
37 nBox.PRIORITY_INFO_MEDIUM, | |
38 [{accessKey: null, | |
39 // TODO: Implement a real callback. | |
40 callback: function() {}, | |
41 label: REQUEST_BOX_BUTTON_TEXT, | |
42 popup: null}]); | |
43 } | |
44 } | |
8 | 45 |
9 function buildRequestor(window) { | 46 function buildRequestor(window) { |
10 return function request(caps, callback) { | 47 return function request(caps, callback) { |
11 if (!(typeof(caps) == "object" || | 48 if (!(typeof(caps) == "object" || |
12 typeof(caps) == "string")) | 49 typeof(caps) == "string")) |
17 | 54 |
18 if (typeof(caps) == "object") | 55 if (typeof(caps) == "object") |
19 caps = new XPCSafeJSObjectWrapper(caps); | 56 caps = new XPCSafeJSObjectWrapper(caps); |
20 callback = new XPCSafeJSObjectWrapper(callback); | 57 callback = new XPCSafeJSObjectWrapper(callback); |
21 | 58 |
22 // TODO: Present UI to user and inject requested capabilities. | 59 showRequestNotificationBox(window, caps, callback); |
23 }; | 60 }; |
24 } | 61 } |
25 | 62 |
26 var listener = { | 63 var listener = { |
27 QueryInterface : XPCOMUtils.generateQI([Ci.nsIWebProgressListener, | 64 QueryInterface : XPCOMUtils.generateQI([Ci.nsIWebProgressListener, |