Greasemonkey のソースをちょっと読む
Greasemonkey の編集に Carbon Emacs を使うで書きました、エディタを開くあたりのコードがどうも気になりまして、ソースをちょっと見てみようかと思いました。
http://greasemonkey.devjavu.com/ にあるように、ソースをチェックアウト。スクリプトがついているのでビルドもしてみます。
[ihara@Macintosh.local:~/work] $ svn co http://svn.devjavu.com/greasemonkey/
[ihara@Macintosh.local:~/work] $ greasemonkey/trunk/src
[ihara@Macintosh.local:~/work/greasemonkey/trunk/src] $ chmod +x build.sh
[ihara@Macintosh.local:~/work/greasemonkey/trunk/src] $ ./build.sh
[ihara@Macintosh.local:~/work/greasemonkey/trunk/src] $ l *.xpi
-rw-r--r-- 1 ihara ihara 62853 1 3 14:07 greasemonkey-0.8.20080103.0.xpi
さくっとでけました。
edit あたりをキーワードに探していくとどうも trunk/src/chrome/chromeFiles/content/utils.js の openInEditor が該当の関数っぽいような。
-
function openInEditor(aFile, promptTitle) {
-
var editor, editorPath;
-
try {
-
editorPath = GM_prefRoot.getValue("editor");
-
} catch(e) {
-
GM_log( "Failed to get 'editor' value:" + e );
-
if (GM_prefRoot.exists("editor")) {
-
GM_log("A value for 'editor' exists, so let's remove it because it's causing problems");
-
GM_prefRoot.remove("editor");
-
}
-
editorPath = false;
-
}
-
if (editorPath) {
-
// check whether the editor path is valid
-
GM_log("Try editor with path " + editorPath);
-
editor = Components.classes["@mozilla.org/file/local;1"]
-
.createInstance(Components.interfaces.nsILocalFile);
-
editor.followLinks = true;
-
editor.initWithPath(editorPath);
-
} else {
-
var nsIFilePicker = Components.interfaces.nsIFilePicker;
-
var filePicker = Components.classes["@mozilla.org/filepicker;1"]
-
.createInstance(nsIFilePicker);
-
-
filePicker.init(window, promptTitle, nsIFilePicker.modeOpen);
-
filePicker.appendFilters(nsIFilePicker.filterApplication);
-
filePicker.appendFilters(nsIFilePicker.filterAll);
-
-
if (filePicker.show() != nsIFilePicker.returnOK) {
-
return false;
-
}
-
editor = filePicker.file;
-
GM_log("User selected: " + editor.path);
-
GM_prefRoot.setValue("editor", editor.path);
-
}
-
-
if (editor.exists() && editor.isExecutable()) {
-
try {
-
GM_log("launching ...");
-
-
var process = Components.classes["@mozilla.org/process/util;1"]
-
.getService(Components.interfaces.nsIProcess);
-
process.init(editor);
-
process.run(false, // non-blocking
-
[aFile.path],
-
1); // number of arguments in second param
-
return true;
-
} catch (e) {
-
GM_log("Failed to launch editor: " + e, true);
-
}
-
} else {
-
GM_log("Editor '" + editorPath + "' does not exist or isn't executable. " +
-
"Put it back, check the permissions, or just give up and reset " +
-
"editor using about:config", true);
-
}
-
return false;
-
};
GM_log の出力を Firefox のエラーコンソールじゃなくて Firebug のコンソールに出しましょうってことで about:config から showChrome あたりで showChromeErrors と showChromeMessage の値をそれぞれ true に変更、んで GM_log('...', true) あたりを埋め込みながら追っていくと、上のソースの 43 行目、process.init(editor) でこけている模様。
Code snippets:Running applications とか nsIProcess あたりを見てみるものの、いまいちわからず。
って、前は少なくともエディタ起動してたのに、この落としてきたソースだと起動すらしないよねって、このソースのバージョンは 0.8、リリース版は 0.7 っつう話ですか。アガガ。
さらに探してみると、openInEditor not working on OS X ってバグを発見。openInEditor 動かんっつってますね。チケット 59 の実装に戻そうみたいな話なので、そのパッチを適用してみると、無事エディタ起動するようになりました。
ハー良かった、てか、実際プロセスを起動するあたりを見たかったのでもうちょっと深いところにいかないとダメみたいです。ムー。
というわけで期せずして手元の Greasemonkey は 0.8 に上がりました。ハイ。
About this entry
You’re currently reading “ Greasemonkey のソースをちょっと読む ,” an entry on forever 5 years old blog
- Published:
- 3pm on 2008/01/03
- Category:
- Javascript, Greasemonkey, Firefox, プログラミング
- Related Posts:

No comments
Jump to comment form | comments rss [?] | trackback uri [?]