[Pkg-mozext-commits] [spdy-indicator] 02/02: Imported Upstream version 2.1
Dmitry Smirnov
onlyjob at moszumanska.debian.org
Tue Nov 18 15:36:28 UTC 2014
This is an automated email from the git hooks/post-receive script.
onlyjob pushed a commit to branch upstream
in repository spdy-indicator.
commit 1e9e8fe (upstream)
Author: Dmitry Smirnov <onlyjob at member.fsf.org>
Date: Tue Nov 18 02:35:18 2014
Imported Upstream version 2.1
---
README.md | 22 +++
bootstrap.js | 22 +++
chrome.manifest | 3 +
chrome/content/indicator.jsm | 321 ++++++++++++++++++++++++++++++++++++
chrome/locale/en-US/overlay.dtd | 3 +
chrome/skin/icon-spdy-active.png | Bin 0 -> 383 bytes
chrome/skin/icon-spdy-subactive.png | Bin 0 -> 402 bytes
chrome/skin/overlay.css | 9 +
icon.png | Bin 0 -> 3589 bytes
install.rdf | 23 +++
10 files changed, 403 insertions(+)
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..43c778c
--- /dev/null
+++ b/README.md
@@ -0,0 +1,22 @@
+Firefox extension to add an SPDY support indicator in the address bar.
+
+Inspired by http://www.devthought.com/2012/03/10/chrome-spdy-indicator/
+This extension is [now on AMO](https://addons.mozilla.org/en-US/firefox/addon/spdy-indicator/).
+
+Address bar icon by http://glyphicons.com/ - CC license.
+
+## License
+
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ Version 2, December 2004
+
+ Copyright (C) 2004 Sam Hocevar <sam at hocevar.net>
+
+ Everyone is permitted to copy and distribute verbatim or modified
+ copies of this license document, and changing it is allowed as long
+ as the name is changed.
+
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
diff --git a/bootstrap.js b/bootstrap.js
new file mode 100644
index 0000000..8d67e57
--- /dev/null
+++ b/bootstrap.js
@@ -0,0 +1,22 @@
+const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
+Cu.import("resource://gre/modules/Services.jsm");
+
+function startup(data, reason) {
+ Cu.import("chrome://spdyindicator/content/indicator.jsm");
+ SPDYManager.startup();
+}
+
+function shutdown(data, reason) {
+ if (reason == APP_SHUTDOWN) return;
+
+ Cu.import("chrome://spdyindicator/content/indicator.jsm");
+ SPDYManager.shutdown();
+ Cu.unload("chrome://spdyindicator/content/indicator.jsm");
+}
+
+function install(data, reason) {
+ // o hai there new friend! :D
+}
+function uninstall(data, reason) {
+ // y u do this to me :(
+}
diff --git a/chrome.manifest b/chrome.manifest
new file mode 100644
index 0000000..402a5a5
--- /dev/null
+++ b/chrome.manifest
@@ -0,0 +1,3 @@
+content spdyindicator chrome/content/
+locale spdyindicator en-US chrome/locale/en-US/
+skin spdyindicator default chrome/skin/
diff --git a/chrome/content/indicator.jsm b/chrome/content/indicator.jsm
new file mode 100644
index 0000000..3577323
--- /dev/null
+++ b/chrome/content/indicator.jsm
@@ -0,0 +1,321 @@
+var EXPORTED_SYMBOLS = ["SPDYManager"];
+
+const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
+Cu.import("resource://gre/modules/Services.jsm");
+
+// this is kludgy: in order to prevent unbounded memory growth,
+// we limit the number of SPDY-requested prePaths to this number
+const SPDYREQUESTS_MAXSIZE = 20;
+
+function getLoadContext(request) {
+ let loadContext = null;
+ try {
+ loadContext = request.QueryInterface(Ci.nsIChannel)
+ .notificationCallbacks
+ .getInterface(Ci.nsILoadContext);
+ } catch (e) {
+ try {
+ loadContext = request.loadGroup
+ .notificationCallbacks
+ .getInterface(Ci.nsILoadContext);
+ } catch (e) {}
+ }
+
+ if (!loadContext) return null;
+ return loadContext.associatedWindow;
+}
+
+// get the chrome window from a content window
+function getChromeWindow(domWindow) {
+ return domWindow.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIWebNavigation)
+ .QueryInterface(Ci.nsIDocShellTreeItem)
+ .rootTreeItem
+ .QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDOMWindow);
+}
+
+const prefBranchName = "extensions.spdyindicator.";
+var SPDYManager = {
+ // private
+ indicators: [],
+ branch: Services.prefs.getBranch(prefBranchName),
+
+ createIndicator: function (window) {
+ let indicator = new SPDYIndicator(window);
+ indicator.start();
+ this.indicators.push(indicator);
+ return indicator;
+ },
+
+ newWindowListener: function (subject, topic, data) {
+ let window = subject.QueryInterface(Ci.nsIDOMWindow);
+ switch (topic) {
+ case "domwindowopened":
+ let self = this;
+ window.addEventListener('load', function onLoad() {
+ window.removeEventListener('load', onLoad, false);
+ if (window.document.documentElement.getAttribute('windowtype') === "navigator:browser") {
+ self.createIndicator(window);
+ }
+ }, false);
+ break;
+ case "domwindowclosed":
+ for (let i in this.indicators) {
+ if (this.indicators[i].window === window) {
+ this.indicators[i].stop();
+ this.indicators.splice(i, 1);
+ break;
+ }
+ }
+ break;
+ }
+ },
+
+ setDefaultPrefs: function () {
+ let defaultBranch = Services.prefs.getDefaultBranch(prefBranchName);
+ defaultBranch.setIntPref("minShowState", 2);
+ defaultBranch.setBoolPref("showDebug", false);
+ },
+
+ observe: function (subject, topic, data) {
+ switch (topic) {
+ case "http-on-examine-response":
+ case "http-on-examine-cached-response":
+ case "http-on-examine-merged-response":
+ subject.QueryInterface(Ci.nsIHttpChannel);
+
+ // make sure we are requested via SPDY
+ let spdyHeader = null;
+ try {
+ spdyHeader = subject.getResponseHeader("X-Firefox-Spdy");
+ } catch (e) {}
+ if (!spdyHeader || !spdyHeader.length) return;
+
+ // find the browser which this request originated from
+ let domWindow = getLoadContext(subject);
+ if (!domWindow) return;
+ let window = getChromeWindow(domWindow);
+
+ // notify the appropriate indicator
+ let indicator = null;
+ for (let i in this.indicators) {
+ if (this.indicators[i].window === window) {
+ indicator = this.indicators[i];
+ break;
+ }
+ }
+ if (!indicator) {
+ debug("Could not find indicator from chrome window for request");
+ } else {
+ indicator.spdyRequested(domWindow, subject.URI);
+ }
+ break;
+ }
+ },
+
+ // used by bootstrap.js
+ startup: function (browser) {
+ this.setDefaultPrefs();
+
+ // add response header observers
+ Services.obs.addObserver(this, "http-on-examine-response", false);
+ Services.obs.addObserver(this, "http-on-examine-merged-response", false);
+ Services.obs.addObserver(this, "http-on-examine-cached-response", false);
+
+ // add indicators for existing windows
+ let browserEnum = Services.wm.getEnumerator("navigator:browser");
+ while (browserEnum.hasMoreElements()) {
+ this.createIndicator(browserEnum.getNext());
+ }
+ // listen for window open/close events
+ Services.ww.registerNotification(this.newWindowListener.bind(this));
+ },
+
+ shutdown: function () {
+ // remove response header observers
+ Services.obs.removeObserver(this, "http-on-examine-response");
+ Services.obs.removeObserver(this, "http-on-examine-merged-response");
+ Services.obs.removeObserver(this, "http-on-examine-cached-response");
+
+ // stop and destroy indicators for existing windows
+ for (let i in this.indicators) {
+ this.indicators[i].stop();
+ }
+ this.indicators = [];
+ // stop listening for window open/close events
+ Services.ww.unregisterNotification(this.newWindowListener);
+ },
+
+ // used by SPDYIndicator
+ indicatorStates: [
+ {
+ name: "unknown",
+ tooltip: "SPDY state unknown",
+ }, {
+ name: "inactive",
+ tooltip: "SPDY is inactive",
+ }, {
+ name: "subactive",
+ tooltip: "SPDY is active for some sub-documents included in the top-level document",
+ }, {
+ name: "active",
+ tooltip: "SPDY is active for the top-level document",
+ }
+ ],
+
+ getMinShowState: function () {
+ return this.branch.getIntPref("minShowState");
+ },
+ getShowDebug: function () {
+ return this.branch.getBoolPref("showDebug");
+ }
+};
+
+function debug(s) {
+ if (SPDYManager.getShowDebug()) {
+ try {
+ throw new Error("dummy");
+ } catch (e) {
+ var stack = e.stack.split('\n');
+ stack.splice(0, 1);
+ Services.console.logStringMessage("SPDYIndicator: " + s + "\n" + stack.join('\n'));
+ }
+ }
+}
+
+function SPDYIndicator(window) {
+ this.window = window;
+ this.browser = window.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDOMWindow)
+ .gBrowser;
+ this._update_bound = this.update.bind(this);
+ this.tabProgressListener.onLocationChange = this.tabProgressListener.onLocationChange.bind(this);
+ debug("SPDYIndicator created");
+}
+
+SPDYIndicator.prototype = {
+ piStylesheet: null,
+
+ start: function () {
+ // insert our stylesheet
+ this.piStylesheet = this.window.document.createProcessingInstruction('xml-stylesheet',
+ 'href="chrome://spdyindicator/skin/overlay.css" type="text/css"');
+ this.window.document.insertBefore(this.piStylesheet, this.window.document.firstChild);
+
+ // create icon
+ let spdyIndicator = this.window.document.createElement('image');
+ spdyIndicator.id = 'spdyindicator-icon';
+ spdyIndicator.className = 'urlbar-icon';
+
+ // insert icon in urlbar
+ let urlbarIcons = this.window.document.getElementById('urlbar-icons');
+ urlbarIcons.insertBefore(spdyIndicator, urlbarIcons.firstChild);
+
+ // add browser event listeners
+ this.browser.addEventListener("pageshow", this._update_bound, true);
+ this.browser.addEventListener("select", this._update_bound, false);
+
+ // add tab location listener
+ this.browser.addTabsProgressListener(this.tabProgressListener);
+
+ debug("SPDYIndicator started");
+ this.update();
+ },
+
+ stop: function () {
+ // remove stylesheet
+ if (this.piStylesheet.parentNode) {
+ this.piStylesheet.parentNode.removeChild(this.piStylesheet);
+ } else {
+ debug("SPDYIndicator could not find stylesheet");
+ }
+
+
+ // remove icon
+ let spdyIndicator = this.window.document.getElementById('spdyindicator-icon');
+ if (spdyIndicator.parentNode) {
+ spdyIndicator.parentNode.removeChild(spdyIndicator);
+ } else {
+ debug("SPDYIndicator could not find icon");
+ }
+
+ // remove browser event listeners
+ this.browser.removeEventListener("pageshow", this._update_bound, true);
+ this.browser.removeEventListener("select", this._update_bound, false);
+
+ // remove tab location listener
+ this.browser.removeTabsProgressListener(this.tabProgressListener);
+
+ debug("SPDYIndicator stopped");
+ },
+
+ getState: function (browser) {
+ return browser.getUserData("__spdyindicator_state") || 0;
+ },
+ setState: function (browser, newState) {
+ browser.setUserData("__spdyindicator_state", newState, null);
+ this.update();
+ },
+ updateState: function (browser, newState) {
+ let oldState = this.getState(browser);
+ if (newState > oldState)
+ this.setState(browser, newState);
+ },
+
+ isTopLevelSPDY: function (browser) {
+ let spdyRequests = browser.getUserData("__spdyindicator_spdyrequests");
+ let currentPath = browser.getUserData("__spdyindicator_path") ||
+ browser.currentURI.prePath;
+ return (spdyRequests && spdyRequests.indexOf(currentPath) !== -1);
+ },
+
+ update: function () {
+ let state = this.getState(this.browser.selectedBrowser);
+ // change indicator state
+ let indicator = this.window.document.getElementById("spdyindicator-icon");
+ let indicatorState = SPDYManager.indicatorStates[state];
+ indicator.setAttribute("hidden", state < SPDYManager.getMinShowState());
+ indicator.setAttribute("state", indicatorState.name);
+ indicator.setAttribute("tooltiptext", indicatorState.tooltip);
+ },
+ _update_bound: null,
+
+ spdyRequested: function (domWindow, uri) {
+ debug("Requested " + uri.asciiSpec);
+
+ let browser = this.browser.getBrowserForDocument(domWindow.top.document);
+ if (!browser) return;
+
+ let spdyRequests = browser.getUserData("__spdyindicator_spdyrequests") || [];
+ if (spdyRequests.indexOf(uri.prePath) === -1) {
+ spdyRequests.push(uri.prePath);
+ }
+ if (spdyRequests.length > SPDYREQUESTS_MAXSIZE) {
+ spdyRequests.splice(0, spdyRequests.length - SPDYREQUESTS_MAXSIZE);
+ }
+ browser.setUserData("__spdyindicator_spdyrequests", spdyRequests, null);
+
+ if (this.isTopLevelSPDY(browser)) {
+ this.updateState(browser, 3);
+ } else {
+ this.updateState(browser, 2);
+ }
+ },
+
+ tabProgressListener: {
+ onLocationChange: function (browser, webProgress, request, URI, flags) {
+ browser.setUserData("__spdyindicator_path", URI.prePath, null);
+ this.setState(browser, 0);
+ if (this.isTopLevelSPDY(browser)) {
+ this.updateState(browser, 3);
+ }
+ },
+ onProgressChange: function () {},
+ onSecurityChange: function () {},
+ onStateChange: function () {},
+ onStatusChange: function () {}
+ },
+};
+
+// vim: filetype=javascript
diff --git a/chrome/locale/en-US/overlay.dtd b/chrome/locale/en-US/overlay.dtd
new file mode 100644
index 0000000..bc64b06
--- /dev/null
+++ b/chrome/locale/en-US/overlay.dtd
@@ -0,0 +1,3 @@
+<!ENTITY spdyindicator.tooltipInactive "SPDY is inactive">
+<!ENTITY spdyindicator.tooltipActive "SPDY is active for the top-level document">
+<!ENTITY spdyindicator.tooltipSubactive "SPDY is active for sub-documents included in the top-level document">
diff --git a/chrome/skin/icon-spdy-active.png b/chrome/skin/icon-spdy-active.png
new file mode 100644
index 0000000..89d9140
Binary files /dev/null and b/chrome/skin/icon-spdy-active.png differ
diff --git a/chrome/skin/icon-spdy-subactive.png b/chrome/skin/icon-spdy-subactive.png
new file mode 100644
index 0000000..f102447
Binary files /dev/null and b/chrome/skin/icon-spdy-subactive.png differ
diff --git a/chrome/skin/overlay.css b/chrome/skin/overlay.css
new file mode 100644
index 0000000..1fb1e92
--- /dev/null
+++ b/chrome/skin/overlay.css
@@ -0,0 +1,9 @@
+#spdyindicator-icon[state=active] {
+ list-style-image: url("chrome://spdyindicator/skin/icon-spdy-active.png");
+}
+#spdyindicator-icon[state=subactive] {
+ list-style-image: url("chrome://spdyindicator/skin/icon-spdy-subactive.png");
+}
+#spdyindicator-icon {
+ cursor: default;
+}
diff --git a/icon.png b/icon.png
new file mode 100644
index 0000000..e3decd6
Binary files /dev/null and b/icon.png differ
diff --git a/install.rdf b/install.rdf
new file mode 100644
index 0000000..21dfacb
--- /dev/null
+++ b/install.rdf
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+<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>spdyindicator at chengsun.github.com</em:id>
+ <em:version>2.1</em:version>
+ <em:type>2</em:type>
+ <em:bootstrap>true</em:bootstrap>
+
+ <em:targetApplication>
+ <Description>
+ <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
+ <em:minVersion>10.*</em:minVersion>
+ <em:maxVersion>15.0a1</em:maxVersion>
+ </Description>
+ </em:targetApplication>
+
+ <em:name>SPDY indicator</em:name>
+ <em:description>An indicator showing SPDY support in the address bar.</em:description>
+ <em:creator>Cheng Sun</em:creator>
+ <em:homepageURL>http://github.com/chengsun/moz-spdy-indicator</em:homepageURL>
+ </Description>
+</RDF>
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/spdy-indicator.git
More information about the Pkg-mozext-commits
mailing list