aboutsummaryrefslogtreecommitdiff
path: root/src/js/chrome
diff options
context:
space:
mode:
authorGravatar Trevor Elliott <trevor@galois.com>2013-06-07 11:59:57 -0700
committerGravatar Trevor Elliott <trevor@galois.com>2013-06-07 11:59:57 -0700
commit8690d56ff0bbd1031e8cc6788dd2159aac6b7adb (patch)
treed573336305dc756f357f20dd986f77cb3ceafb9b /src/js/chrome
parentf42930c2226d07482725b03ad522c106c0bdec8b (diff)
Reorganize the build system
* Move all javascript source to src/js * Update the test runner, etc. * Do less javascript compilation
Diffstat (limited to 'src/js/chrome')
-rw-r--r--src/js/chrome/background.html38
-rw-r--r--src/js/chrome/build.mk48
-rw-r--r--src/js/chrome/injected/platform-compute.js27
-rw-r--r--src/js/chrome/injected/platform-ui.js27
-rw-r--r--src/js/chrome/js/platform-ajax.js39
-rw-r--r--src/js/chrome/js/platform-background.js165
-rw-r--r--src/js/chrome/js/platform-options.js48
-rw-r--r--src/js/chrome/js/platform-port.js70
-rw-r--r--src/js/chrome/manifest.json30
9 files changed, 492 insertions, 0 deletions
diff --git a/src/js/chrome/background.html b/src/js/chrome/background.html
new file mode 100644
index 0000000..8ca54fd
--- /dev/null
+++ b/src/js/chrome/background.html
@@ -0,0 +1,38 @@
+<!--
+ * Module : chrome/background.html
+ * Copyright : (c) 2011-2012, Galois, Inc.
+ *
+ * Maintainer :
+ * Stability : Provisional
+ * Portability: Not Portable (Chrome Only)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ -->
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Background Page</title>
+ <script src="underscore.js"></script>
+ <script src="backbone.js"></script>
+ <script src="js/set.js"></script>
+ <script src="js/background.js"></script>
+ <script src="js/url-pat.js"></script>
+ <script src="js/settings.js"></script>
+ <script src="js/messenger.js"></script>
+ <script src="js/state.js"></script>
+ <script src="js/rules.js"></script>
+ <script src="js/platform-port.js"></script>
+ <script src="js/platform-background.js"></script>
+ </head>
+ <body/>
+</html>
diff --git a/src/js/chrome/build.mk b/src/js/chrome/build.mk
new file mode 100644
index 0000000..b93cc6f
--- /dev/null
+++ b/src/js/chrome/build.mk
@@ -0,0 +1,48 @@
+
+
+# Chrome Extension #############################################################
+
+all: $(build-dir)/fiveui.crx
+
+chrome-dir := $(path)
+
+chrome-build := $(build-dir)/chrome
+
+
+# Generic Extension Parts ######################################################
+
+# pull in the base fiveui extension
+$(eval $(call stage-fiveui,$(chrome-build),$(build-dir)/fiveui.crx))
+
+
+# Chrome File Staging ##########################################################
+
+# copy over scripts from the chrome extension
+$(chrome-build)/data/js/%: $(chrome-dir)/js/% | $(chrome-build)/data/js
+ $(call cmd,cp)
+
+$(chrome-build)/data/injected/%: $(chrome-dir)/injected/% | $(chrome-build)/data/injected
+ $(call cmd,cp)
+
+$(chrome-build)/data/%: $(chrome-dir)/% | $(chrome-build)/data
+ $(call cmd,cp)
+
+$(chrome-build)/%: $(chrome-dir)/% | $(chrome-build)
+ $(call cmd,cp)
+
+$(chrome-build): | $(build-dir)
+ $(call cmd,mkdir)
+
+
+# Packaging ####################################################################
+
+# generate the executable after copying over all files
+$(build-dir)/fiveui.crx: $(chrome-build)/manifest.json \
+ $(chrome-build)/data/background.html \
+ $(chrome-build)/data/js/platform-port.js \
+ $(chrome-build)/data/js/platform-background.js \
+ | $(chrome-build)
+ $(call label,MAKECRX $(call drop-prefix,$@)) ( cd $(build-dir) \
+ && $(topdir)/tools/bin/makecrx $(chrome-build) \
+ $(topdir)/fiveui.pem fiveui \
+ $(redir) )
diff --git a/src/js/chrome/injected/platform-compute.js b/src/js/chrome/injected/platform-compute.js
new file mode 100644
index 0000000..a372913
--- /dev/null
+++ b/src/js/chrome/injected/platform-compute.js
@@ -0,0 +1,27 @@
+/*
+ * Module : chrome/chrome-injected-compute.js
+ * Copyright : (c) 2011-2012, Galois, Inc.
+ *
+ * Maintainer :
+ * Stability : Provisional
+ * Portability: Not Portable (Chrome Only)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @return {{on: function(!string, function(*)), emit: function(!string, *)}}
+ */
+var obtainComputePort = function() {
+ return new fiveui.ChromePort(chrome.extension.connect({ name: 'compute' }));
+};
diff --git a/src/js/chrome/injected/platform-ui.js b/src/js/chrome/injected/platform-ui.js
new file mode 100644
index 0000000..939a62d
--- /dev/null
+++ b/src/js/chrome/injected/platform-ui.js
@@ -0,0 +1,27 @@
+/*
+ * Module : chrome/chrome-injected-ui.js
+ * Copyright : (c) 2011-2012, Galois, Inc.
+ *
+ * Maintainer :
+ * Stability : Provisional
+ * Portability: Not Portable (Chrome Only)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @return {{on: function(!string, function(*)), emit: function(!string, *)}}
+ */
+var obtainPort = function() {
+ return new fiveui.ChromePort(chrome.extension.connect({ name: 'ui' }));
+};
diff --git a/src/js/chrome/js/platform-ajax.js b/src/js/chrome/js/platform-ajax.js
new file mode 100644
index 0000000..68ced39
--- /dev/null
+++ b/src/js/chrome/js/platform-ajax.js
@@ -0,0 +1,39 @@
+
+
+var fiveui = fiveui || {};
+
+(function() {
+
+fiveui.ajax = fiveui.ajax || {};
+
+/**
+ * Use jQuery to get the resource, calling the success or error continuations
+ * when the result is returned. This always retrieves as text, leaving any
+ * further processing to the success continuation.
+ */
+fiveui.ajax.get = function(url, options) {
+
+ _.defaults(options, {
+ success:function() {},
+ error: function() {}
+ });
+
+ jQuery.ajax(url, {
+
+ dataType: 'text',
+
+ success:function(text) {
+ // strip out everything else from the args
+ options.success(text);
+ },
+
+ error:function() {
+ // call with no context
+ options.error();
+ },
+
+ });
+
+};
+
+})();
diff --git a/src/js/chrome/js/platform-background.js b/src/js/chrome/js/platform-background.js
new file mode 100644
index 0000000..6ffecf8
--- /dev/null
+++ b/src/js/chrome/js/platform-background.js
@@ -0,0 +1,165 @@
+/*
+ * Module : chrome/background.js
+ * Copyright : (c) 2011-2012, Galois, Inc.
+ *
+ * Maintainer :
+ * Stability : Provisional
+ * Portability: Not Portable (Chrome Only)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var fiveui = fiveui || {};
+
+(function() {
+
+fiveui.chrome = fiveui.chrome || {};
+
+/**
+ * The primary entry point for the FiveUI Chrome background page.
+ */
+fiveui.chrome.background = function() {
+
+ /**
+ * Inject code and resources into the specified tab's web page.
+ *
+ * @param {!number} tabid The id of the tab to load scripts into.
+ * @param {!Array.<string>} inScripts The list of scripts to load in
+ * order.
+ * @param {!boolean} inFrames Whether or not to inject into iFrames.
+ * @return {void}
+ */
+ var loadScripts = function(tabid, inScripts, inFrames) {
+ var chromeScripts = [dataLoader('js/platform-port.js')];
+ if(inFrames) {
+ chromeScripts.push(dataLoader('injected/platform-compute.js'));
+ } else {
+ chromeScripts.push(dataLoader('injected/platform-ui.js'));
+ }
+ var scripts = _.flatten([chromeScripts, inScripts]);
+
+ var end = function() {};
+
+ var loop = function() {
+ var next = loop;
+ if (scripts.length == 1) {
+ next = end;
+ }
+
+ var script = scripts.shift();
+
+ // console.log('injecting: ' + script);
+
+ if (/css$/.test(script)) {
+ chrome.tabs.insertCSS(tabid, { 'file' : script }, next);
+ } else {
+ chrome.tabs.executeScript(tabid, { 'file' : script }, next);
+ }
+ };
+
+ loop();
+ };
+
+ /**
+ * Set the current widget icon.
+ *
+ * @param {!string} iconPath The local path to the icon to use.
+ * @return {void}
+ */
+ var setIcon = function(iconPath) {
+ chrome.tabs.getSelected(null,
+ function(tab) {
+ chrome.browserAction.setIcon({
+ path: iconPath,
+ tabId: tab.id
+ });
+ });
+ };
+
+ /**
+ * Change the text undearneath the fiveui icon.
+ *
+ * @param {!fiveui.TabState} tabState The tab state object to update.
+ * @return {void}
+ */
+ var updateIconText = function(tabState) {
+ var tabId = tabState.tabId;
+ var probs = tabState.problems.length;
+ var text = '';
+ if (probs > 0) {
+ if (probs > 99) {
+ text = '99+';
+ } else {
+ text = probs.toString();
+ }
+ }
+ chrome.browserAction.setBadgeText({ text: text, tabId: tabId });
+ };
+
+ var updateWidget = function(tabState) {
+ if(null == tabState) {
+ setIcon('images/fiveui-icon-disabled.png');
+ } else {
+ setIcon('images/fiveui-icon-enabled.png');
+ updateIconText(tabState);
+ }
+ };
+
+ // launch the generic background script
+ var dataLoader = function (path) {
+ return "data/"+path;
+ };
+ var settings = new fiveui.Settings(localStorage);
+ background = new fiveui.Background(settings, updateWidget,
+ loadScripts, dataLoader);
+
+ // notify the generic background about a new content script connection.
+ chrome.extension.onConnect.addListener(
+ function(chPort) {
+ var port = new fiveui.ChromePort(chPort);
+ var tabId = chPort.sender.tab.id;
+ var url = chPort.sender.tab.url;
+
+ background.connect(tabId, port, url, chPort.name == 'ui');
+ });
+
+
+ chrome.tabs.onCreated.addListener(function(tab) {
+ // console.log('in oncreated');
+ if (tab.url) {
+ background.pageLoad(tab.id, tab.url);
+ }
+ });
+ // check page load events against the generic background
+ chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
+ if (changeInfo.status == 'complete') {
+ background.pageLoad(tabId, tab.url);
+ }
+ });
+
+ chrome.tabs.onRemoved.addListener(function(tabId, removeInfo) {
+ background.removeTab(tabId);
+ });
+
+ // show the browser widget when the fiveui button is clicked.
+ chrome.browserAction.onClicked.addListener(function(tab) {
+ background.showUI(tab.id);
+ });
+};
+
+// Add event listeners once the DOM has fully loaded by listening for the
+// `DOMContentLoaded` event on the document, and adding your listeners to
+// specific elements when it triggers.
+fiveui.chrome.background();
+
+})();
diff --git a/src/js/chrome/js/platform-options.js b/src/js/chrome/js/platform-options.js
new file mode 100644
index 0000000..b049122
--- /dev/null
+++ b/src/js/chrome/js/platform-options.js
@@ -0,0 +1,48 @@
+/*
+ * Module : chrome/chrome-options.js
+ * Copyright : (c) 2011-2012, Galois, Inc.
+ *
+ * Maintainer :
+ * Stability : Provisional
+ * Portability: Not Portable (Chrome Only)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var fiveui = fiveui || {};
+
+(function() {
+
+fiveui.chrome = fiveui.chrome || {};
+fiveui.chrome.options = fiveui.chrome.options || {};
+
+
+_.extend(fiveui.chrome.options, {
+ init: function() {
+ var optionsChan = new fiveui.Chan();
+ var storageChan = new fiveui.Chan();
+
+ optionsChan.chan = storageChan;
+ storageChan.chan = optionsChan;
+
+ var settings = new fiveui.Settings(localStorage);
+
+ fiveui.Settings.manager(storageChan, settings);
+ fiveui.options.init(optionsChan);
+ }
+});
+
+// run the init function when the page loads
+jQuery(fiveui.chrome.options.init);
+
+})();
diff --git a/src/js/chrome/js/platform-port.js b/src/js/chrome/js/platform-port.js
new file mode 100644
index 0000000..8a5aeae
--- /dev/null
+++ b/src/js/chrome/js/platform-port.js
@@ -0,0 +1,70 @@
+/*
+ * Module : chrome/chrome-port.js
+ * Copyright : (c) 2011-2012, Galois, Inc.
+ *
+ * Maintainer :
+ * Stability : Provisional
+ * Portability: Not Portable (Chrome Only)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+if (typeof goog != 'undefined') {
+ goog.provide('fiveui.ChromePort');
+} else {
+ var fiveui = fiveui || {};
+}
+
+/**
+ * @constructor
+ * @param {!{onMessage:Object,postMessage:function(*):void}} port The connection to manage.
+ */
+fiveui.ChromePort = function(port) {
+ var events = {};
+
+ this._port = port;
+ this._events = events;
+
+ this._port.onMessage.addListener(function(obj) {
+ var evt = obj.type;
+ var cb = events[evt];
+ if(null != evt && null != cb) {
+ cb(obj.payload);
+ }
+ });
+};
+
+/**
+ * Listen to incoming messages.
+ *
+ * @param {!string} evt The event to listen for.
+ * @param {!function(*)} cb The callback to invoke.
+ * @return {void}
+ */
+fiveui.ChromePort.prototype.on = function(evt, cb) {
+ this._events[evt] = cb;
+};
+
+/**
+ * Send a message to the background.
+ *
+ * @param {!string} evt The event to fire.
+ * @param {?Object} obj The data to associate with the event.
+ * @return {void}
+ */
+fiveui.ChromePort.prototype.emit = function(evt, obj) {
+ // console.log('chromeport.emit: '+evt);
+ // console.log(obj);
+ this._port.postMessage({ type: evt, payload: obj });
+ // console.log('chromeport.emit: '+evt+' done');
+};
diff --git a/src/js/chrome/manifest.json b/src/js/chrome/manifest.json
new file mode 100644
index 0000000..9202276
--- /dev/null
+++ b/src/js/chrome/manifest.json
@@ -0,0 +1,30 @@
+{
+ "manifest_version": 2,
+
+ "name": "Five UI",
+ "version": "0.2",
+ "description": "UI Constraint Checker",
+
+ "icons": { "16": "data/images/fiveui-icon-16.png",
+ "48": "data/images/fiveui-icon-48.png",
+ "128": "data/images/fiveui-icon-128.png"
+ },
+
+ "background": {
+ "persistent": true,
+ "page": "data/background.html"
+ },
+
+ "options_page": "data/options.html",
+
+ "browser_action": {
+ "default_icon": "data/images/fiveui-icon-disabled.png",
+ "default_title": "Five UI"
+ },
+ "permissions": [
+ "tabs", "http://*/*", "https://*/*", "history"
+ ],
+
+ // We have to relax the content security policy to allow rules to be evaluated:
+ "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
+}