forked from mozilla/pdf.js
-
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.
Fix special powers add-on for firefox.
- Loading branch information
1 parent
36d63a2
commit da522d4
Showing
11 changed files
with
3,346 additions
and
518 deletions.
There are no files selected for viewing
5 changes: 3 additions & 2 deletions
5
test/resources/firefox/extensions/special-powers@mozilla.org/chrome.manifest
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
content specialpowers chrome/specialpowers/content/ | ||
category profile-after-change @mozilla.org/special-powers-observer;1 @mozilla.org/special-powers-observer;1 | ||
component {59a52458-13e0-4d93-9d85-a637344f29a1} components/SpecialPowersObserver.js | ||
content specialpowers chrome/specialpowers/content/ | ||
contract @mozilla.org/special-powers-observer;1 {59a52458-13e0-4d93-9d85-a637344f29a1} | ||
category profile-after-change @mozilla.org/special-powers-observer;1 @mozilla.org/special-powers-observer;1 | ||
resource specialpowers chrome/specialpowers/modules/ |
121 changes: 121 additions & 0 deletions
121
...refox/extensions/special-powers@mozilla.org/chrome/specialpowers/content/MozillaLogger.js
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,121 @@ | ||
/** | ||
* MozillaLogger, a base class logger that just logs to stdout. | ||
*/ | ||
|
||
function MozillaLogger(aPath) { | ||
} | ||
|
||
MozillaLogger.prototype = { | ||
|
||
init : function(path) {}, | ||
|
||
getLogCallback : function() { | ||
return function (msg) { | ||
var data = msg.num + " " + msg.level + " " + msg.info.join(' ') + "\n"; | ||
dump(data); | ||
} | ||
}, | ||
|
||
log : function(msg) { | ||
dump(msg); | ||
}, | ||
|
||
close : function() {} | ||
}; | ||
|
||
|
||
/** | ||
* SpecialPowersLogger, inherits from MozillaLogger and utilizes SpecialPowers. | ||
* intented to be used in content scripts to write to a file | ||
*/ | ||
function SpecialPowersLogger(aPath) { | ||
// Call the base constructor | ||
MozillaLogger.call(this); | ||
this.prototype = new MozillaLogger(aPath); | ||
this.init(aPath); | ||
} | ||
|
||
SpecialPowersLogger.prototype = { | ||
init : function (path) { | ||
SpecialPowers.setLogFile(path); | ||
}, | ||
|
||
getLogCallback : function () { | ||
return function (msg) { | ||
var data = msg.num + " " + msg.level + " " + msg.info.join(' ') + "\n"; | ||
SpecialPowers.log(data); | ||
|
||
if (data.indexOf("SimpleTest FINISH") >= 0) { | ||
SpecialPowers.closeLogFile(); | ||
} | ||
} | ||
}, | ||
|
||
log : function (msg) { | ||
SpecialPowers.log(msg); | ||
}, | ||
|
||
close : function () { | ||
SpecialPowers.closeLogFile(); | ||
} | ||
}; | ||
|
||
|
||
/** | ||
* MozillaFileLogger, a log listener that can write to a local file. | ||
* intended to be run from chrome space | ||
*/ | ||
|
||
/** Init the file logger with the absolute path to the file. | ||
It will create and append if the file already exists **/ | ||
function MozillaFileLogger(aPath) { | ||
// Call the base constructor | ||
MozillaLogger.call(this); | ||
this.prototype = new MozillaLogger(aPath); | ||
this.init(aPath); | ||
} | ||
|
||
MozillaFileLogger.prototype = { | ||
|
||
init : function (path) { | ||
var PR_WRITE_ONLY = 0x02; // Open for writing only. | ||
var PR_CREATE_FILE = 0x08; | ||
var PR_APPEND = 0x10; | ||
this._file = Components.classes["@mozilla.org/file/local;1"]. | ||
createInstance(Components.interfaces.nsILocalFile); | ||
this._file.initWithPath(path); | ||
this._foStream = Components.classes["@mozilla.org/network/file-output-stream;1"]. | ||
createInstance(Components.interfaces.nsIFileOutputStream); | ||
this._foStream.init(this._file, PR_WRITE_ONLY | PR_CREATE_FILE | PR_APPEND, | ||
0664, 0); | ||
}, | ||
|
||
getLogCallback : function() { | ||
return function (msg) { | ||
var data = msg.num + " " + msg.level + " " + msg.info.join(' ') + "\n"; | ||
if (MozillaFileLogger._foStream) | ||
this._foStream.write(data, data.length); | ||
|
||
if (data.indexOf("SimpleTest FINISH") >= 0) { | ||
MozillaFileLogger.close(); | ||
} | ||
} | ||
}, | ||
|
||
log : function(msg) { | ||
if (this._foStream) | ||
this._foStream.write(msg, msg.length); | ||
}, | ||
|
||
close : function() { | ||
if(this._foStream) | ||
this._foStream.close(); | ||
|
||
this._foStream = null; | ||
this._file = null; | ||
} | ||
}; | ||
|
||
this.MozillaLogger = MozillaLogger; | ||
this.SpecialPowersLogger = SpecialPowersLogger; | ||
this.MozillaFileLogger = MozillaFileLogger; |
Oops, something went wrong.