Browse files

Add files

  • Loading branch information...
1 parent 3b73ab5 commit c1db0472ed1ab97afceb6b6cd61ab5a629aadd0b @gavinsharp committed Jan 15, 2013
Showing with 92 additions and 0 deletions.
  1. +74 −0 bootstrap.js
  2. +18 −0 install.rdf
View
74 bootstrap.js
@@ -0,0 +1,74 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var Cu = Components.utils;
+
+Cu.import("resource://gre/modules/Services.jsm");
+
+function startup(aData, aReason) {
+ // Monkeypatch all browser windows, current and future
+ watchWindows(function (window) {
+ });
+}
+
+function shutdown(aData, aReason) {
+ if (aReason != APP_SHUTDOWN) {
+ unloaders.forEach(function (f) {
+ try {
+ f();
+ } catch (ex) {}
+ });
+ }
+}
+
+function install(aData, aReason) { }
+
+function uninstall(aData, aReason) { }
+
+
+/* Code from: https://github.com/Mardak/restartless/blob/watchWindows/bootstrap.js */
+let unloaders = [];
+
+function watchWindows(callback) {
+ // Wrap the callback in a function that ignores failures
+ function watcher(window) {
+ try {
+ // Now that the window has loaded, only handle browser windows
+ let documentElement = window.document.documentElement;
+ if (documentElement.getAttribute("windowtype") == "navigator:browser")
+ callback(window);
+ }
+ catch(ex) {}
+ }
+
+ // Wait for the window to finish loading before running the callback
+ function runOnLoad(window) {
+ // Listen for one load event before checking the window type
+ window.addEventListener("load", function runOnce() {
+ window.removeEventListener("load", runOnce, false);
+ watcher(window);
+ }, false);
+ }
+
+ // Add functionality to existing windows
+ let windows = Services.wm.getEnumerator(null);
+ while (windows.hasMoreElements()) {
+ // Only run the watcher immediately if the window is completely loaded
+ let window = windows.getNext();
+ if (window.document.readyState == "complete")
+ watcher(window);
+ // Wait for the window to load before continuing
+ else
+ runOnLoad(window);
+ }
+
+ // Watch for new browser windows opening then wait for it to load
+ function windowWatcher(subject, topic) {
+ if (topic == "domwindowopened")
+ runOnLoad(subject);
+ }
+ Services.ww.registerNotification(windowWatcher);
+ unloaders.push(function() Services.ww.unregisterNotification(windowWatcher));
+}
+
View
18 install.rdf
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
+ <Description about="urn:mozilla:install-manifest">
+ <em:id>saveasfilename@gavinsharp.com</em:id>
+ <em:type>2</em:type>
+ <em:name>SaveAsFilename</em:name>
+ <em:version>0.1</em:version>
+ <em:bootstrap>true</em:bootstrap>
+ <em:creator>Gavin Sharp</em:creator>
+ <em:targetApplication>
+ <Description>
+ <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
+ <em:minVersion>18.0</em:minVersion>
+ <em:maxVersion>21.*</em:maxVersion>
+ </Description>
+ </em:targetApplication>
+ </Description>
+</RDF>

0 comments on commit c1db047

Please sign in to comment.