-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ff8d71
commit 5dab4b7
Showing
3 changed files
with
78 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/*jslint white: true, todo: true */ | ||
"use strict"; | ||
|
||
var util = require("./util"); | ||
var Ci = require("chrome").Ci; | ||
|
||
var topics = [ | ||
"http-on-modify-request", | ||
"http-on-examine-response", | ||
"http-on-examine-cached-response", | ||
"http-on-examine-merged-response" | ||
]; | ||
|
||
function Controller() { | ||
var me = this; | ||
this.observerService = util.getService("@mozilla.org/observer-service;1", | ||
"nsIObserverService"); | ||
topics.forEach(function(topic) { | ||
me.observerService.addObserver(me, topic, false); | ||
}); | ||
this[" is valid "] = true; | ||
} | ||
|
||
Controller.prototype = { | ||
observe: function(subject, topic) { | ||
var httpChannel; | ||
switch (topic) { | ||
case "http-on-modify-request": | ||
httpChannel = subject.QueryInterface(Ci.nsIHttpChannel); | ||
//TODO | ||
//httpChannel.setRequestHeader("X-Hello", "World", false); | ||
break; | ||
case "http-on-examine-response": | ||
case "http-on-examine-cached-response": | ||
case "http-on-examine-merged-response": | ||
httpChannel = subject.QueryInterface(Ci.nsIHttpChannel); | ||
//TODO | ||
break; | ||
} | ||
return httpChannel; | ||
}, | ||
|
||
isValid: function isValid() { | ||
return !!this[" is valid "]; | ||
}, | ||
|
||
invalidate: function() { | ||
if (!this[" is valid "]) { return; } | ||
this.observerService.removeObserver(this, "http-on-modify-request"); | ||
delete this[" is valid "]; | ||
} | ||
|
||
}; | ||
|
||
exports.Controller = Controller; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/*jslint white: true, todo: true */ | ||
"use strict"; | ||
|
||
// Import Mozilla chrome APIs | ||
var chrome = require("chrome"); | ||
var Cc = chrome.Cc; | ||
var Ci = chrome.Ci; | ||
|
||
exports.createInstance = function createInstance(contractId, iface) { | ||
return Cc[contractId].createInstance(Ci[iface]); | ||
}; | ||
|
||
exports.getService = function getService(contractId, service) { | ||
return Cc[contractId].getService(Ci[service]); | ||
}; | ||
|