Permalink
Browse files

Uses Services.jsm more and ready to test on mobile

* Since I started using Services.jsm, I decided to apply it more
uniformly and get it in other areas where it is useful.
* Moved the about: page component to a module, which is loaded
dynamically on mobile.
* Made the generated installers more reliable.
* Added small version of the add-on icon.
* This all needs testing on Windows, Linux and Android.
  • Loading branch information...
1 parent a3b0b26 commit 11b6aebfa5974e5f08c1a7a11d1415e61f5c0801 @jvillalobos committed Jan 22, 2013
View
@@ -72,6 +72,7 @@ xpi_built := install.rdf \
bootstrap.js \
chrome.manifest \
icon.png \
+ icon64.png \
$(wildcard content/*.js) \
$(wildcard content/*.xul) \
$(wildcard content/*.xml) \
@@ -90,6 +91,12 @@ $(xpi_file): $(xpi_built)
@$(ZIP) $(xpi_file) $(xpi_built)
@echo "Creating XPI file. Done!"
+# This builds the extension XPI file and copies it to a mounted Android device.
+.PHONY: android
+android: all
+ @adb push $(xpi_file) /mnt/sdcard/Download
+ @echo "Copied to device."
+
.PHONY: install
install: $(xpi_file)
@echo "Installing in profile folder: $(profile_location)"
View
@@ -32,33 +32,74 @@ function shutdown(aData, aReason) {
}
let RXM = {
+ _logger : null,
+
+ init : function() {
+ Components.utils.import("resource://gre/modules/Services.jsm");
+ Components.utils.import("chrome://rxm-modules/content/rxmCommon.js");
+
+ this._logger = RXULM.getLogger("RXM");
+ this._logger.debug("init");
+ this.windowListener._logger = RXULM.getLogger("RXM.windowListener");
+
+ let enumerator = Services.wm.getEnumerator("navigator:browser");
+
+ while (enumerator.hasMoreElements()) {
+ this.windowListener.addUI(enumerator.getNext());
+ }
+
+ Services.wm.addListener(this.windowListener);
+ },
+
+ uninit : function() {
+ this._logger.debug("uninit");
+
+ let enumerator = Services.wm.getEnumerator("navigator:browser");
+
+ Services.wm.removeListener(this.windowListener);
+
+ while (enumerator.hasMoreElements()) {
+ this.windowListener.removeUI(enumerator.getNext());
+ }
+
+ Components.utils.unload("chrome://rxm-modules/content/rxmCommon.js");
+ Components.utils.unload("resource://gre/modules/Services.jsm");
+ },
+
windowListener :
{
- stringBundle : null,
+ _logger : null,
/**
- * Adds the menu items used to open the RXM window.
+ * Adds the menu items used to open the RXM window, and the about: page
+ * for mobile devices.
*/
addUI : function(aWindow) {
- this.stringBundle =
- Cc["@mozilla.org/intl/stringbundle;1"].
- getService(Ci.nsIStringBundleService).
- createBundle("chrome://remotexulmanager/locale/rxm.properties");
+ this._logger.debug("addUI");
- // fullFirefox menu
+ // full Firefox menu
this.tryToAddMenuItemAt(aWindow, "menuWebDeveloperPopup");
// Firefox app menu
this.tryToAddMenuItemAt(aWindow, "appmenu_webDeveloper_popup");
// SeaMonkey menu
this.tryToAddMenuItemAt(aWindow, "toolsPopup");
// Komodo menu
this.tryToAddMenuItemAt(aWindow, "popup_tools");
+
+ // add an about: page for mobile devices. This is a simplified version
+ // of the UI.
+ if (RXULM.isMobile()) {
+ Components.utils.import("chrome://rxm-modules/content/rxmAbout.js");
+ registerAboutPage();
+ }
},
/**
* Tries to add a menu item at the specified location.
*/
tryToAddMenuItemAt : function(aWindow, aParentId) {
+ this._logger.debug("tryToAddMenuItemAt");
+
let doc = aWindow.document;
let parent = doc.getElementById(aParentId);
@@ -67,19 +108,16 @@ let RXM = {
menuitem.setAttribute("id", "rxm-menu-" + aParentId);
menuitem.setAttribute(
- "label", this.stringBundle.GetStringFromName("rxm.menu.label"));
+ "label", RXULM.stringBundle.GetStringFromName("rxm.menu.label"));
menuitem.setAttribute(
"accesskey",
- this.stringBundle.GetStringFromName("rxm.menu.accesskey"));
+ RXULM.stringBundle.GetStringFromName("rxm.menu.accesskey"));
menuitem.addEventListener(
"command",
function () {
- let windowManager =
- Cc['@mozilla.org/appshell/window-mediator;1'].
- getService(Ci.nsIWindowMediator);
let win =
- windowManager.
+ Services.wm.
getMostRecentWindow("remotexulmanager-manager-dialog");
// check if a window is already open.
@@ -105,14 +143,29 @@ let RXM = {
}
},
+ /**
+ * Removes all added UI elements.
+ */
removeUI : function(aWindow) {
- this.tryToRemoveMenuItemAt(aWindow, "menuWebDeveloperPopup");
- this.tryToRemoveMenuItemAt(aWindow, "appmenu_webDeveloper_popup");
- this.tryToRemoveMenuItemAt(aWindow, "toolsPopup");
- this.tryToRemoveMenuItemAt(aWindow, "popup_tools");
+ this._logger.debug("removeUI");
+
+ this.tryToRemoveMenuItem(aWindow, "menuWebDeveloperPopup");
+ this.tryToRemoveMenuItem(aWindow, "appmenu_webDeveloper_popup");
+ this.tryToRemoveMenuItem(aWindow, "toolsPopup");
+ this.tryToRemoveMenuItem(aWindow, "popup_tools");
+
+ if (RXULM.isMobile()) {
+ unregisterAboutPage();
+ Components.utils.unload("chrome://rxm-modules/content/rxmAbout.js");
+ }
},
- tryToRemoveMenuItemAt : function(aWindow, aId) {
+ /**
+ * Tries to remove the specified menuitem.
+ */
+ tryToRemoveMenuItem : function(aWindow, aId) {
+ this._logger.debug("tryToRemoveMenuItem");
+
let doc = aWindow.document;
let menuitem = doc.getElementById("rxm-menu-" + aId);
@@ -122,6 +175,8 @@ let RXM = {
},
onOpenWindow : function(xulWindow) {
+ this._logger.debug("onOpenWindow");
+
// A new window has opened.
let that = this;
let domWindow =
@@ -142,31 +197,5 @@ let RXM = {
},
onCloseWindow : function(xulwindow) {},
onWindowTitleChange: function(xulWindow, newTitle) {}
- },
-
- init : function() {
- let wm =
- Cc["@mozilla.org/appshell/window-mediator;1"].
- getService(Ci.nsIWindowMediator);
- let enumerator = wm.getEnumerator("navigator:browser");
-
- while (enumerator.hasMoreElements()) {
- this.windowListener.addUI(enumerator.getNext());
- }
-
- wm.addListener(this.windowListener);
- },
-
- uninit : function() {
- let wm =
- Cc["@mozilla.org/appshell/window-mediator;1"].
- getService(Ci.nsIWindowMediator);
- let enumerator = wm.getEnumerator("navigator:browser");
-
- wm.removeListener(this.windowListener);
-
- while (enumerator.hasMoreElements()) {
- this.windowListener.removeUI(enumerator.getNext());
}
- }
};
@@ -27,7 +27,3 @@ locale remotexulmanager fr locale/fr/
locale remotexulmanager ja-JP locale/ja-JP/
locale remotexulmanager sv-SE locale/sv-SE/
locale remotexulmanager zh-CN locale/zh-CN/
-
-# Mobile Firefox.
-component {aa76f1c0-a902-4afe-ab37-e51d8c6d2e68} components/aboutRXM.js application={a23983c0-fd0e-11dc-95ff-0800200c9a66}
-contract @mozilla.org/network/protocol/about;1?what=remotexul {aa76f1c0-a902-4afe-ab37-e51d8c6d2e68} application={a23983c0-fd0e-11dc-95ff-0800200c9a66}
@@ -19,9 +19,6 @@ const Ci = Components.interfaces;
const INSTALLER_EXTENSION = "xpi";
-Components.utils.import("chrome://rxm-modules/content/rxmCommon.js");
-Components.utils.import("chrome://rxm-modules/content/rxmGenerator.js");
-
/**
* RXULMChrome namespace.
*/
@@ -41,11 +38,24 @@ RXULMChrome.Generator = {
* Initializes the object.
*/
init : function() {
+ Components.utils.import("resource://gre/modules/Services.jsm");
+ Components.utils.import("chrome://rxm-modules/content/rxmCommon.js");
+ Components.utils.import("chrome://rxm-modules/content/rxmGenerator.js");
+
this._logger = RXULM.getLogger("RXULMChrome.Generator");
this._logger.debug("init");
this._loadPermissions();
},
+ /**
+ * Uninitializes the object.
+ */
+ uninit : function() {
+ Components.utils.unload("chrome://rxm-modules/content/rxmGenerator.js");
+ Components.utils.unload("chrome://rxm-modules/content/rxmCommon.js");
+ Components.utils.unload("resource://gre/modules/Services.jsm");
+ },
+
/**
* Load the permission list from the datasource.
*/
@@ -113,9 +123,6 @@ RXULMChrome.Generator = {
if (0 < domains.length) {
try {
- // only import the script when necessary.
- Components.utils.import("chrome://rxm-modules/content/rxmGenerator.js");
-
let fp =
Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
let winResult;
@@ -146,11 +153,7 @@ RXULMChrome.Generator = {
this._logger.error("generateInstaller\n" + e);
// if an error happens, alert the user.
- let promptService =
- Cc["@mozilla.org/embedcomp/prompt-service;1"].
- getService(Ci.nsIPromptService);
-
- promptService.alert(
+ Services.prompt.alert(
window,
RXULM.stringBundle.GetStringFromName("rxm.generateInstaller.title"),
RXULM.stringBundle.GetStringFromName("rxm.generateError.label"));
@@ -166,3 +169,5 @@ RXULMChrome.Generator = {
window.addEventListener(
"load", function() { RXULMChrome.Generator.init(); }, false);
+window.addEventListener(
+ "unload", function() { RXULMChrome.Generator.uninit(); }, false);
@@ -17,9 +17,6 @@
const Cc = Components.classes;
const Ci = Components.interfaces;
-Components.utils.import("chrome://rxm-modules/content/rxmCommon.js");
-Components.utils.import("chrome://rxm-modules/content/rxmPermissions.js");
-
/**
* RXULMChrome namespace.
*/
@@ -34,35 +31,30 @@ RXULMChrome.Manager = {
/* Logger for this object. */
_logger : null,
- /* Cached prompt service object. */
- _promptService : null,
-
- /**
- * Lazy getter for the prompt service component.
- * @return prompt service component.
- */
- get promptService() {
- this._logger.trace("get promptService");
-
- if (null == this._promptService) {
- this._promptService =
- Cc["@mozilla.org/embedcomp/prompt-service;1"].
- getService(Ci.nsIPromptService);
- }
-
- return this._promptService;
- },
/**
* Initializes the object.
*/
init : function() {
+ Components.utils.import("resource://gre/modules/Services.jsm");
+ Components.utils.import("chrome://rxm-modules/content/rxmCommon.js");
+ Components.utils.import("chrome://rxm-modules/content/rxmPermissions.js");
+
this._logger = RXULM.getLogger("RXULMChrome.Manager");
this._logger.debug("init");
this._migrateFilePreference();
this._loadPermissions();
},
+ /**
+ * Uninitializes the object.
+ */
+ uninit : function() {
+ Components.utils.unload("chrome://rxm-modules/content/rxmPermissions.js");
+ Components.utils.unload("chrome://rxm-modules/content/rxmCommon.js");
+ Components.utils.unload("resource://gre/modules/Services.jsm");
+ },
+
/**
* Load the permission list from the datasource.
*/
@@ -135,7 +127,7 @@ RXULMChrome.Manager = {
let promptResponse;
promptResponse =
- this.promptService.prompt(
+ Services.prompt.prompt(
window, RXULM.stringBundle.GetStringFromName("rxm.addDomain.title"),
RXULM.stringBundle.formatStringFromName(
"rxm.enterDomain.label", [ RXULM.Permissions.LOCAL_FILES ], 1),
@@ -170,7 +162,7 @@ RXULMChrome.Manager = {
let item;
doRemove =
- this.promptService.confirm(
+ Services.prompt.confirm(
window, RXULM.stringBundle.GetStringFromName("rxm.removeDomain.title"),
message);
@@ -326,7 +318,7 @@ RXULMChrome.Manager = {
"rxm.import.invalidMany.label", [ failCount ], 1));
}
- this.promptService.alert(
+ Services.prompt.alert(
window, RXULM.stringBundle.GetStringFromName("rxm.import.title"),
message);
}
@@ -350,11 +342,8 @@ RXULMChrome.Manager = {
launchGenerator : function(aEvent) {
this._logger.debug("launchGenerator");
- let windowManager =
- Cc['@mozilla.org/appshell/window-mediator;1'].
- getService(Ci.nsIWindowMediator);
let win =
- windowManager.getMostRecentWindow("remotexulmanager-generator-dialog");
+ Services.wm.getMostRecentWindow("remotexulmanager-generator-dialog");
// check if a window is already open.
if ((null != win) && !win.closed) {
@@ -375,11 +364,13 @@ RXULMChrome.Manager = {
_alert : function(aTitleKey, aContentKey) {
this._logger.trace("_alert");
- this.promptService.alert(
+ Services.prompt.alert(
window, RXULM.stringBundle.GetStringFromName(aTitleKey),
RXULM.stringBundle.GetStringFromName(aContentKey));
}
};
window.addEventListener(
"load", function() { RXULMChrome.Manager.init(); }, false);
+window.addEventListener(
+ "unload", function() { RXULMChrome.Manager.uninit(); }, false);
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.

0 comments on commit 11b6aeb

Please sign in to comment.