aboutsummaryrefslogtreecommitdiffstats
path: root/lib/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/main.js')
-rw-r--r--lib/main.js224
1 files changed, 167 insertions, 57 deletions
diff --git a/lib/main.js b/lib/main.js
index 44265ff..3e128ac 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -1,65 +1,175 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (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.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Bugzilla Tweaks.
- *
- * The Initial Developer of the Original Code is Mozilla Foundation.
- * Portions created by the Initial Developer are Copyright (C) 2010
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Johnathan Nightingale <johnath@mozilla.com>
- * Ehsan Akhgari <ehsan@mozilla.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
+<<<<<<< HEAD
+// Released under the MIT/X11 license
+// http://www.opensource.org/licenses/mit-license.php
+//
+// Links to read through
+// http://ehsanakhgari.org/blog/2010-01-07/bugzilla-tweaks-enhanced
+// http://hg.mozilla.org/users/ehsan.akhgari_gmail.com/extensions/file/tip/bugzillatweaks
+// http://hg.mozilla.org/users/ehsan.akhgari_gmail.com/extensions/file/ecfa0f028b81/bugzillatweaks/lib/main.js
+// http://hg.mozilla.org/users/avarma_mozilla.com/atul-packages/file/42ac1e99a107/packages\
+// /facebook-acquaintances/lib/main.js#l11
+// http://ehsanakhgari.org/blog/2010-05-31/my-experience-jetpack-sdk#comment-1253
+//
+"use strict";
+var browser = require("tab-browser");
+var self = require("self");
+var pageMod = require("page-mod");
+var libbz = require("libbugzilla");
+var tabs = require("tabs");
+var logger = require("logger");
+var Message = require("util").Message;
+var contextMenu = require("context-menu");
+
+function isOurPage(window, matchingURLs) {
+ var url = window.location.href;
+
+ // like ["regexp-url1", "regexp-url2"]
+ return matchingURLs.some(function (element,i,a) {
+ return new RegExp(element).test(url);
+ });
+}
+
+/**
*
- * ***** END LICENSE BLOCK ***** */
+ */
+function skipThisPage(doc) {
+ var stemURL = "https://HOSTNAME/show_bug.cgi?id=";
+ var titleElems = doc.getElementsByTagName("title");
+ var titleStr = titleElems[0].textContent;
+ var REArr = new RegExp("[bB]ug\\s+([0-9]+)").exec(titleStr);
+ var hostname = doc.location.hostname;
+ if (REArr) {
+ var bugNo = REArr[1];
+ doc.location = stemURL.replace("HOSTNAME",hostname) + bugNo;
+ }
+}
-var self = require("self"),
- contextMenu = require("context-menu"),
- pageMod = require("page-mod");
+var messageHandler = exports.messageHandler = function messageHandler(worker, msg) {
+ switch (msg.cmd) {
+ case "LogMessage":
+ console.log(msg.data);
+ break;
+ case "ExecCmd":
+ libbz.executeCommand(msg.data);
+ break;
+ case "AddLogRecord":
+ logger.addLogRecord(msg.data);
+ break;
+ case "GenerateTS":
+ logger.generateTimeSheet();
+ break;
+ case "ClearTS":
+ logger.clearTimeSheet();
+ break;
+ case "ImportTS":
+ logger.importTimeSheet();
+ break;
+ case "GetInstalledPackages":
+ // send message with packages back
+ libbz.getInstalledPackages(msg.data, function (pkgsMsg) {
+ worker.postMessage(pkgsMsg);
+ });
+ break;
+ case "GetClipboard":
+ libbz.getClipboard(function (clipboard) {
+ worker.postMessage(new Message(msg.data, clipboard));
+ });
+ break;
+ case "SetClipboard":
+ libbz.setClipboard(msg.data);
+ break;
+ case "ChangeJSONURL":
+ libbz.changeJSONURL();
+ break;
+ case "OpenURLinPanel":
+ libbz.openURLInNewPanel(msg.data);
+ break;
+ case "OpenURLinTab":
+ libbz.openURLInNewTab(msg.data);
+ break;
+ case "OpenStringInPanel":
+ libbz.openStringInNewPanel(msg.data);
+ break;
+ case "MakeXMLRPCall":
+ // url, login, method, params, callback
+ libbz.makeXMLRPCCall(msg.data.url, msg.data.login, msg.data.method,
+ msg.data.params, function(ret) {
+ worker.postMessage(new Message(msg.data.callRPC, ret));
+ });
+ break;
+ case "GetURL":
+ libbz.getURL(msg.data.url, function(stuff) {
+ worker.postMessage(new Message(msg.data.backMessage, stuff));
+ });
+ break;
+ case "OpenBugUpstream":
+ libbz.createUpstreamBug(msg.data.url, msg.data.subject, msg.data.comment);
+ break;
+ case "testReady":
+ // we ignore it here, interesting only in unit test
+ break;
+ default:
+ console.error(msg.toSource());
+ }
+};
+
+var contentScriptLibraries = [
+ self.data.url('js/urltest.js'),
+ self.data.url('js/bug-page-mod.js'),
+ self.data.url("lib/jumpNextBug.js"),
+ self.data.url("lib/util.js"),
+ self.data.url("lib/color.js"),
+ self.data.url("lib/logging-front.js"),
+ self.data.url("lib/rhbzpage.js"),
+ self.data.url("lib/bzpage.js")
+];
-exports.main = function(options, callback) {
+libbz.initialize(libbz.config, function () {
pageMod.PageMod({
- include: ["*.mozilla.org", "*.bugzilla.org"], // filtered further in the page mod script
+ include: [
+ "https://bugzilla.redhat.com/show_bug.cgi?id=*",
+ "https://bugzilla.mozilla.org/show_bug.cgi?id=*",
+ "https://bugzilla.gnome.org/show_bug.cgi?id=*"
+ ],
contentScriptWhen: 'ready',
- contentScriptFile: [self.data.url('js/urltest.js'),
- self.data.url('js/bug-page-mod.js')]
+ contentScriptFile: contentScriptLibraries,
+ onAttach: function onAttach(worker, msg) {
+ worker.on('message', function (msg) {
+ messageHandler(worker, msg);
+ });
+ }
});
+});
- // Allow toggling of CC event displays using a context menu entry
- contextMenu.Item({
- label: "Toggle CC History",
- contentScriptFile: [self.data.url('js/urltest.js'),
- self.data.url('js/cc-context.js')]
- });
+pageMod.PageMod({
+ include: [
+ "https://bugzilla.redhat.com/process_bug.cgi",
+ "https://bugzilla.redhat.com/post_bug.cgi",
+ "https://bugzilla.redhat.com/attachment.cgi",
+ "https://bugzilla.mozilla.org/process_bug.cgi",
+ "https://bugzilla.mozilla.org/post_bug.cgi",
+ "https://bugzilla.mozilla.org/attachment.cgi",
+ "https://bugzilla.gnome.org/process_bug.cgi",
+ "https://bugzilla.gnome.org/post_bug.cgi",
+ "https://bugzilla.gnome.org/attachment.cgi"
+ ],
+ contentScriptWhen: 'ready',
+ contentScriptFile: self.data.url("lib/skip-bug.js")
+});
- contextMenu.Item({
- label: "Copy Check-in Comment",
- contentScriptFile: [self.data.url('js/urltest.js'),
- self.data.url('js/checkin-context.js')],
- onMessage: function (comment) {
- require("clipboard").set(comment);
- }
- });
-};
+
+// Allow toggling of CC event displays using a context menu entry
+contextMenu.Item({
+ label: "Toggle CC History",
+ contentScriptFile: [self.data.url('js/urltest.js'),
+ self.data.url('js/cc-context.js')]
+});
+
+contextMenu.Item({
+ label: "Copy Check-in Comment",
+ contentScriptFile: [self.data.url('js/urltest.js'),
+ self.data.url('js/checkin-context.js')],
+ onMessage: function (comment) {
+ require("clipboard").set(comment);
+ }
+});