Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Make AVIM restartless #132

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2a9aa37
First pass on restartlessness
1ec5 Apr 12, 2015
382ae8a
DTD → properties
1ec5 Apr 12, 2015
a1acea9
Reinternationalized menu items
1ec5 Apr 12, 2015
f2b981f
Toolbar button
1ec5 Apr 13, 2015
6785ce6
bootstrap.js is not vendored
1ec5 Apr 13, 2015
9118c65
Status bar panel
1ec5 Apr 13, 2015
739df03
Refactored string bundle usage
1ec5 Apr 13, 2015
e37e511
Consolidated per-app overlay hooks
1ec5 Apr 13, 2015
b986bdb
Removed GUI test harness
1ec5 Apr 13, 2015
3f1af78
Fixed tests
1ec5 Apr 13, 2015
8958e5f
Removed Charamel/Silvermel specializations
1ec5 Apr 13, 2015
2154a5d
Progress towards proper uninstallation
1ec5 Apr 13, 2015
2daf5c0
Fixed test
1ec5 Apr 13, 2015
65ac055
Fixed some linter errors
1ec5 Apr 13, 2015
2e97020
Fixed more linter errors
1ec5 Apr 13, 2015
45656f2
Correctly unload/reload UI elements
1ec5 Apr 14, 2015
ce951f0
Include bootstrap.js in builds
1ec5 Apr 15, 2015
3e1efe9
Consolidated event handling buildup/teardown
1ec5 Apr 19, 2015
0286eaf
Fixed JSHint errors
1ec5 Apr 19, 2015
3c0cbc3
Show toggle popup upon installation
1ec5 Apr 20, 2015
1518173
Fixed JSHint errors
1ec5 Apr 20, 2015
60fa4e7
Hide toolbar button in toolbar-less JavaScript windows
1ec5 Apr 20, 2015
f9d40e6
Apply stylesheet globally from XPCOM component too
1ec5 Apr 25, 2015
8851734
Started fixing toolbar customization
1ec5 Apr 25, 2015
d1213d6
Correctly tear down toolbar button on disable
1ec5 Apr 25, 2015
6ab78df
Always show toggle popup when toolbar button is overflowed
1ec5 Apr 25, 2015
2f1d6a8
Fixed JSHint error
1ec5 Apr 25, 2015
70ac567
Removed about:addons XUL overlay
1ec5 Apr 27, 2015
4985ef7
Attach on DOMContentLoaded
1ec5 Apr 28, 2015
d3cba98
Reimplemented options window overlays
1ec5 Apr 28, 2015
cce539d
Fixed typo
1ec5 Apr 28, 2015
65092cf
Fixed input in e10s tabs
1ec5 May 31, 2015
36fad96
Fixed e10s window teardown
1ec5 May 31, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bootstrap.js linguist-vendored=false
182 changes: 182 additions & 0 deletions bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/* global Services, ADDON_INSTALL, ADDON_ENABLE, APP_SHUTDOWN */
/* exported startup, shutdown, install, uninstall */
"use strict";

const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;

Cu.import("resource://gre/modules/Services.jsm");

// https://developer.mozilla.org/en-US/Add-ons/How_to_convert_an_overlay_extension_to_restartless#Step_4.3A_Manually_handle_default_preferences
///// Unicode getCharPref
//function getUCharPref(prefName, branch) {
// branch = branch ? branch : Services.prefs;
// return branch.getComplexValue(prefName, Ci.nsISupportsString).data;
//}
/// Unicode setCharPref
function setUCharPref(prefName, text, branch) {
var string = Cc["@mozilla.org/supports-string;1"]
.createInstance(Ci.nsISupportsString);
string.data = text;
branch = branch ? branch : Services.prefs;
branch.setComplexValue(prefName, Ci.nsISupportsString, string);
}
//function getGenericPref(branch, prefName) {
// switch (branch.getPrefType(prefName)) {
// default:
// case 0: return undefined; // PREF_INVALID
// case 32: return getUCharPref(prefName,branch); // PREF_STRING
// case 64: return branch.getIntPref(prefName); // PREF_INT
// case 128: return branch.getBoolPref(prefName); // PREF_BOOL
// }
//}
function setGenericPref(branch, prefName, prefValue) {
switch (typeof prefValue) {
case "string":
setUCharPref(prefName, prefValue, branch);
break;
case "number":
branch.setIntPref(prefName, prefValue);
break;
case "boolean":
branch.setBoolPref(prefName, prefValue);
break;
}
}
function setDefaultPref(prefName, prefValue) {
var defaultBranch = Services.prefs.getDefaultBranch(null);
setGenericPref(defaultBranch, prefName, prefValue);
}

/**
* Loads a script at the given URI.
*
* @param uri {string} Location of the script.
* @param target {object} A collection of properties to expose to the
* script as its globals.
*
* @see http://dxr.mozilla.org/mozilla-central/source/addon-sdk/source/lib/sdk/content/sandbox.js (importScripts())
*/
function loadSubScript(uri, target) {
if ("loadSubScriptWithOptions" in Services.scriptloader) {
let options = {
charset: "UTF-8",
// $if{Debug}
ignoreCache: true,
// $endif{}
};
if (target) options.target = target;
Services.scriptloader.loadSubScriptWithOptions(uri, options);
}
else Services.scriptloader.loadSubScript(uri, target, "UTF-8");
}

const ffxID = "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}";
const flockID = "{a463f10c-3994-11da-9945-000d60ca027b}";

function hasMacBrowserOverlay() {
return Services.appinfo.OS === "Darwin" &&
(Services.appinfo.ID === ffxID || Services.appinfo.ID === flockID);
}

function loadOverlay(win) {
const xulTypes = ["text/xul", "application/vnd.mozilla.xul+xml"];
let doc = win.document;
if (!win || !doc.location || doc.location.protocol !== "chrome:" ||
!doc.contentType || xulTypes.indexOf(doc.contentType) < 0) {
return;
}

loadSubScript("chrome://avim/content/avim.js", win);
loadSubScript("chrome://avim/content/frame.js", win);

if (doc.location.href.match(/^chrome:\/\/avim\/content\//) &&
hasMacBrowserOverlay()) {
doc.loadOverlay("chrome://browser/content/macBrowserOverlay.xul", null);

let winUtils = win.getInterface(Ci.nsIDOMWindowUtils);
let styleUri = Services.io.newURI("chrome://browser/skin/preferences/preferences.css",
null, null);
winUtils.loadSheet(styleUri, winUtils.AUTHOR_SHEET);
}
}

function onWindowOpen(win, topic, data) {
if (win.frameElement) return;
win.addEventListener("DOMContentLoaded", function doLoadOverlay(evt) {
win.removeEventListener(evt.type, doLoadOverlay, true);
loadOverlay(win);
}, true);
}

function onAddonsOpen(win, topic, data) {
loadSubScript("chrome://avim/content/addonsOverlay.js", win || {});
}

const resProtocol = Services.io.getProtocolHandler("resource")
.QueryInterface(Ci.nsIResProtocolHandler);

const styleSvc = Cc["@mozilla.org/content/style-sheet-service;1"]
.getService(Ci.nsIStyleSheetService);
const styleUri = Services.io.newURI("chrome://avim/content/skin/avim.css",
null, null);

function startup(data, reason) {
let aliasFile = Cc["@mozilla.org/file/local;1"]
.createInstance(Ci.nsILocalFile);
aliasFile.initWithPath(data.resourceURI.path + "components");
let aliasURI = Services.io.newFileURI(aliasFile);
resProtocol.setSubstitution("avim-components", aliasURI);

aliasFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
aliasFile.initWithPath(data.resourceURI.path + "defaults/preferences");
aliasURI = Services.io.newFileURI(aliasFile);
resProtocol.setSubstitution("avim-preferences", aliasURI);

loadSubScript("resource://avim-preferences/avim.js", {
pref: setDefaultPref,
});

styleSvc.loadAndRegisterSheet(styleUri, styleSvc.AUTHOR_SHEET);

let wins = Services.ww.getWindowEnumerator();
while (wins.hasMoreElements()) {
loadOverlay(wins.getNext().QueryInterface(Ci.nsIDOMWindow));
}
Services.ww.registerNotification(onWindowOpen);
Services.obs.addObserver(onAddonsOpen, "EM-loaded", false);

if (reason === ADDON_INSTALL || reason === ADDON_ENABLE) {
let topWindow = Services.wm.getMostRecentWindow(null);
if (topWindow) {
topWindow.avim.playCueAfterToggle();
topWindow.avim.showTogglePopup(true);
}
}
}

function shutdown(data, reason) {
if (reason === APP_SHUTDOWN) return;

Services.obs.removeObserver(onAddonsOpen, "EM-loaded");
Services.ww.unregisterNotification(onWindowOpen);
let wins = Services.ww.getWindowEnumerator();
while (wins.hasMoreElements()) {
let win = wins.getNext().QueryInterface(Ci.nsIDOMWindow);
win.dispatchEvent(new Event("AVIM:shutdown"));
}

styleSvc.unregisterSheet(styleUri, styleSvc.AUTHOR_SHEET);

Services.obs.notifyObservers(null, "chrome-flush-caches", null);

resProtocol.setSubstitution("avim-components", null);
resProtocol.setSubstitution("avim-preferences", null);
}

function install(data, reason) {
}

function uninstall(data, reason) {
}
2 changes: 1 addition & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def main():

# Files
jar_path = path.join(chrome_dir, "%s.jar" % package_name)
root_files = ROOT_FILES.extend(["install.rdf", "chrome.manifest"])
root_files = ROOT_FILES.extend(["install.rdf", "chrome.manifest", "bootstrap.js"])
omit_files = [".DS_Store", "Thumbs.db", ".gitattributes", ".gitignore"]
if CONFIG is not BuildConfig.L10N:
omit_files.extend(L10N_FILES)
Expand Down
80 changes: 0 additions & 80 deletions chrome.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ locale avim vi locale/vi/
locale avim zh-CN locale/zh-CN/
# locale avim zh-TW locale/zh-TW/

skin avim classic/1.0 skin/classic/
skin avim charamel skin/charamel/
skin avim silvermel skin/charamel/

style chrome://avim/content/generalOverlay.xul chrome://avim/content/skin/avim.css
style chrome://global/content/customizeToolbar.xul chrome://avim/content/skin/avim.css
style chrome://mozapps/content/extensions/extensions.xul chrome://avim/skin/options.css

component {ee7dd176-a684-4dc0-8613-62ddaef5378f} components/avim.js
component {4A373444-8A2A-4641-ADD5-897A88D05185} components/transformer.js

Expand All @@ -27,79 +19,7 @@ contract @1ec5.org/avim/transformer;1 {4A373444-8A2A-4641-ADD5-897A88D05185}

category profile-after-change AVIM @1ec5.org/avim;1

### AVIM #######################################################################

# Mac menu bar in Firefox
overlay chrome://avim/content/optionsOverlay.xul chrome://browser/content/macBrowserOverlay.xul application={ec8030f7-c20a-464f-9b0e-13a3a9e97384} os=Darwin appversion>=3.0a1pre
# Mac menu bar in Flock
overlay chrome://avim/content/optionsOverlay.xul chrome://browser/content/macBrowserOverlay.xul application={a463f10c-3994-11da-9945-000d60ca027b} os=Darwin

# Padding and font sizes
style chrome://avim/content/optionsOverlay.xul chrome://browser/skin/preferences/preferences.css application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
style chrome://avim/content/optionsOverlay.xul chrome://browser/skin/preferences/preferences.css application={a463f10c-3994-11da-9945-000d60ca027b}

# $if{Debug}
overlay chrome://avim/content/test/tester.xul chrome://browser/content/macBrowserOverlay.xul application={ec8030f7-c20a-464f-9b0e-13a3a9e97384} os=Darwin appversion>=3.0a1pre
overlay chrome://avim/content/test/tester.xul chrome://browser/content/macBrowserOverlay.xul application={a463f10c-3994-11da-9945-000d60ca027b} os=Darwin
style chrome://avim/content/test/tester.xul chrome://browser/skin/preferences/preferences.css application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
style chrome://avim/content/test/tester.xul chrome://browser/skin/preferences/preferences.css application={a463f10c-3994-11da-9945-000d60ca027b}
# $endif{}

### Firefox ####################################################################

style chrome://browser/content/browser.xul chrome://avim/content/skin/avim.css

# Browser window
overlay chrome://browser/content/browser.xul chrome://avim/content/generalOverlay.xul appversion<4.0b7
overlay chrome://browser/content/browser.xul chrome://avim/content/moz20Overlay.xul appversion>=4.0b7
overlay chrome://browser/content/browser.xul chrome://avim/content/moz18Overlay.xul appversion<3.0a1pre
override chrome://avim/content/moz20Overlay.xul chrome://avim/content/australisOverlay.xul application={ec8030f7-c20a-464f-9b0e-13a3a9e97384} appversion>=29.0a1
# Preferences window
overlay chrome://browser/content/preferences/preferences.xul chrome://avim/content/generalOverlay.xul
overlay chrome://browser/content/preferences/preferences.xul chrome://avim/content/moz18Overlay.xul appversion<3.0a1pre
# Add-ons window
overlay chrome://mozapps/content/extensions/extensions.xul chrome://avim/content/addonsOverlay.xul application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
overlay about:addons chrome://avim/content/addonsOverlay.xul application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}

### Thunderbird ################################################################

overlay chrome://messenger/content/messenger.xul chrome://avim/content/moz20Overlay.xul appversion>=17

# Preferences and associated dialogs
overlay chrome://messenger/content/preferences/preferences.xul chrome://avim/content/generalOverlay.xul

### Fennec #####################################################################

# Main window
overlay chrome://browser/content/browser.xul chrome://avim/content/fennecOverlay.xul application={a23983c0-fd0e-11dc-95ff-0800200c9a66} appversion>=1.0b4

# Preferences pane
override chrome://avim/content/options.xul chrome://avim/content/fennecOptions.xul application={a23983c0-fd0e-11dc-95ff-0800200c9a66} appversion>=1.0b4

### SeaMonkey ##################################################################

style chrome://navigator/content/navigator.xul chrome://avim/content/skin/avim.css
style chrome://editor/content/editor.xul chrome://avim/content/skin/avim.css

override chrome://avim/content/generalOverlay.xul chrome://avim/content/navigatorOverlay.xul application={92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}

### Sunbird ####################################################################

style chrome://sunbird/content/calendar.xul chrome://avim/content/skin/avim.css

### Prism ######################################################################

style chrome://webrunner/content/webrunner.xul chrome://avim/content/skin/avim.css

### Komodo and Komodo Edit #####################################################

style chrome://komodo/content/komodo.xul chrome://avim/content/skin/avim.css

### BlueGriffon ################################################################

style chrome://bluegriffon/content/xul/bluegriffon.xul chrome://avim/content/skin/avim.css

### Extension <prefwindow>s (#117) #############################################

overlay chrome://dta/content/preferences/prefs.xul chrome://avim/content/generalOverlay.xul
overlay chrome://tabmixplus/content/preferences/preferences.xul chrome://avim/content/generalOverlay.xul
Loading