# HG changeset patch # User Atul Varma # Date 1249599024 25200 # Node ID 413435fc62027d58036fb81efe5e6556ec4227ec # Parent 889c2fd4c9cf0d8bc9ea4254a6ca0f99860843d7 We now show a notification box when a page calls window.powerbox.request(). diff -r 889c2fd4c9cf -r 413435fc6202 extension/modules/content-injector.js --- a/extension/modules/content-injector.js Thu Aug 06 14:53:41 2009 -0700 +++ b/extension/modules/content-injector.js Thu Aug 06 15:50:24 2009 -0700 @@ -4,8 +4,45 @@ const Ci = Components.interfaces; const Cu = Components.utils; +const REQUEST_BOX_NAME = "powerbox_superpower_request"; +const REQUEST_BOX_TEXT = "This web page wants superpowers."; +const REQUEST_BOX_BUTTON_TEXT = "Huh?"; + Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); +function getParentChromeWindow(window) { + var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebNavigation) + .QueryInterface(Ci.nsIDocShellTreeItem) + .rootTreeItem + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDOMWindow); + return mainWindow.wrappedJSObject; +} + +function showRequestNotificationBox(window, caps, callback) { + var tabbrowser = getParentChromeWindow(window).getBrowser(); + var browser = tabbrowser.getBrowserForDocument(window.document); + + if (browser) { + var nBox = tabbrowser.getNotificationBox(browser); + + var oldNotification = nBox.getNotificationWithValue(REQUEST_BOX_NAME); + if (oldNotification) + nBox.removeNotification(oldNotification); + + nBox.appendNotification(REQUEST_BOX_TEXT, + REQUEST_BOX_NAME, + null, + nBox.PRIORITY_INFO_MEDIUM, + [{accessKey: null, + // TODO: Implement a real callback. + callback: function() {}, + label: REQUEST_BOX_BUTTON_TEXT, + popup: null}]); + } +} + function buildRequestor(window) { return function request(caps, callback) { if (!(typeof(caps) == "object" || @@ -19,7 +56,7 @@ caps = new XPCSafeJSObjectWrapper(caps); callback = new XPCSafeJSObjectWrapper(callback); - // TODO: Present UI to user and inject requested capabilities. + showRequestNotificationBox(window, caps, callback); }; }