aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2011-04-29 01:22:18 +0200
committerMatěj Cepl <mcepl@redhat.com>2011-04-29 01:32:27 +0200
commite3989a9404d19fb5164b39f7f6c78e64cc85b137 (patch)
treeb2ceedb4a43b2e85a4d083933a6ca5678b32236f /lib
parentaf9a8239914fb783ddd41a9dc571bd5fb2126050 (diff)
downloadbugzilla-triage-e3989a9404d19fb5164b39f7f6c78e64cc85b137.tar.gz
All XML-RPC calls are rewritten as JSON-RPC ones.
* also MakeJSONRPCall is a functional call now * reorganization for dealing with the history.
Diffstat (limited to 'lib')
-rw-r--r--lib/libbugzilla.js87
-rw-r--r--lib/main.js11
2 files changed, 67 insertions, 31 deletions
diff --git a/lib/libbugzilla.js b/lib/libbugzilla.js
index c85d331..aa2d0b7 100644
--- a/lib/libbugzilla.js
+++ b/lib/libbugzilla.js
@@ -40,7 +40,7 @@ function log(msg) {
/**
* parse XML object out of string working around various bugs in Gecko
* implementation see https://developer.mozilla.org/en/E4X for more information
- *
+ *
* @param inStr
* String with unparsed XML string
* @return XML object
@@ -57,7 +57,7 @@ function parseXMLfromString (inStuff) {
/**
* In case URL contains alias, not the real bug number, get the real bug no from
* the XML representation. Sets correct value to this.bugNo.
- *
+ *
* This is a slow variant for bugs other than actual window
*/
function getRealBugNoSlow(bugNo, location, callback) {
@@ -144,10 +144,10 @@ exports.changeJSONURL = function changeJSONURL() {
};
/**
- *
+ *
* libbz.getInstalledPackages(msg.data, function (pkgsMsg) {
* worker.postMessage(pkgsMsg);
- *
+ *
* locationLoginObj: { location: window.location.href, login: getLogin() }
*/
exports.getInstalledPackages = function getInstalledPackages(locationLoginObj, callback) {
@@ -288,36 +288,63 @@ exports.createUpstreamBug = function createUpstreamBug(urlStr, subject, comment)
exports.makeXMLRPCCall = function makeXMLRPCCall(url, login, method, params, callback) {
var urlObj = urlMod.URL(url);
getPassword(login,
- urlObj.schema + "://" + urlObj.host,
- function (passwObj) {
- if (!passwObj.password) {
- // TODO this should happen, only when user presses Escape in password
- // prompt
- return null;
- }
+ urlObj.schema + "://" + urlObj.host,
+ function (passwObj) {
+ if (!passwObj.password) {
+ // TODO this should happen, only when user presses Escape in password
+ // prompt
+ return null;
+ }
- var msg = new xrpc.XMLRPCMessage(method);
- params.forEach(function (par) {
- msg.addParameter(par);
- });
- msg.addParameter(login);
- msg.addParameter(passwObj.password);
-
- Request({
- url: url,
- onComplete: function(response) {
- if (response.status == 200) {
- var resp = parseXMLfromString(response.text);
- callback(resp.toXMLString());
- }
- },
- content: msg.xml(),
- contentType: "text/xml"
- }).post();
- }
+ var msg = new xrpc.XMLRPCMessage(method);
+ params.forEach(function (par) {
+ msg.addParameter(par);
+ });
+ msg.addParameter(login);
+ msg.addParameter(passwObj.password);
+
+ Request({
+ url: url,
+ onComplete: function(response) {
+ if (response.status == 200) {
+ var resp = parseXMLfromString(response.text);
+ callback(resp.toXMLString());
+ }
+ },
+ content: msg.xml(),
+ contentType: "text/xml"
+ }).post();
+ }
);
};
+// Make a JSONL-RPC call ... most of the business logic should stay in the
+// content script
+// http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html
+exports.makeJSONRPCCall = function makeJSONRPCCall(url, method, params, callback) {
+
+// {"version":"1.1", "method":"Bug.history", "params":{ "ids":[12345] } }
+ var msg = {
+ "version": "1.1",
+ "method": method,
+ "params": params
+ };
+
+ console.myDebug("makeJSONRPCCall: out = " + JSON.stringify(msg));
+
+ Request({
+ url: url,
+ onComplete: function(response) {
+ if (response.status == 200) {
+ console.myDebug("makeJSONRPCCall: in = " + response.text);
+ callback(response.json.result);
+ }
+ },
+ content: JSON.stringify(msg),
+ contentType: "application/json"
+ }).post();
+};
+
exports.initialize = function initialize(config, callback) {
var prefName = BTSPrefNS+"JSONURL";
var urlStr = "";
diff --git a/lib/main.js b/lib/main.js
index c7fe2fd..302dda8 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -99,6 +99,15 @@ var messageHandler = exports.messageHandler = function messageHandler(
ret));
});
break;
+ case "MakeJSONRPCall":
+ // url, login, method, params, callback
+ libbz
+ .makeJSONRPCCall(msg.data.url, 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) {
@@ -123,7 +132,7 @@ var contentScriptLibraries = [
self.data.url("lib/util.js"),
self.data.url("lib/jumpNextBug.js"),
self.data.url("lib/queries.js"),
- self.data.url("lib/preprocessDuplicates.js"),
+ self.data.url("tweaks/preprocessDuplicates.js"),
self.data.url("tweaks/viewSource.js"),
self.data.url("lib/color.js"),
self.data.url("tweaks/addNewLinks.js"),