私はFirefox用にブートストラップされた拡張機能を持っています。 そして今、nsIContentPolicy XPCOMコンポーネントを実装したいと思います。 コンポーネントモジュールコードを書きました。 これでこのコンポーネントを登録します。 私がコンポーネントを登録したい理由は、 "content-policy"カテゴリのnsICategoryManager.addCategoryEntry
に自分のコンポーネントを追加したいということです。ブートストラップされたFirefoxエクステンションにXPCOMコンポーネント(nsIContentPolicy)を実装する方法
var {Cc, Ci, Cu} = require("chrome");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
//console.error("Running interceptor");
function Interceptor()
}
Interceptor.prototype = {
classDescription: "DeferredTo HTTP requests Interceptor",
classID: "{B5B3D9A0-08FC-11E3-8253-5EF06188709B}",
contractID: "@deferredto.com/Interceptor;1",
QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPolicy]),
shouldLoad : function dt_shouldLoad(aContentType, aContentLocation, aRequestOrigin, aContext, aMimeTypeGuess, aExtra) {
console.log("dt_shouldLoad");
if (contentLocation.scheme != "http" && contentLocation.scheme != "https")
return Ci.nsIContentPolicy.ACCEPT;
let result = Ci.nsIContentPolicy.ACCEPT;
// we should check for TYPE_SUBDOCUMENT as well if we want frames.
if ((Ci.nsIContentPolicy.TYPE_DOCUMENT == aContentType) &&
SOME_REGULAR_EXPRESSION.test(aContentLocation.spec)) {
// do stuff here, possibly changing result.
}
return result;
},
shouldProcess: function ILO_shouldProcess() Ci.nsIContentPolicy.ACCEPT,
_xpcom_categories: [
{ category: "content-policy", service: true }
],
classInfo: XPCOMUtils.generateCI(
{classID: Components.ID("{B5B3D9A0-08FC-11E3-8253-5EF06188709B}"),
contractID: "@deferredto.com/Interceptor;1",
classDescription: "Interceptor implements nsIContentPolicy to block images that are not yet at screen @DeferredTo",
interfaces: [
Ci.nsIContentPolicy,
],
flags: Ci.nsIClassInfo.SINGLETON})
}
var components = [Interceptor];
var NSGetFactory = XPCOMUtils.generateNSGetFactory([Interceptor]);
質問:
- それはブートストラップ拡張子からコンポーネントを登録することは可能ですか?
- コンポーネントを再起動しない拡張機能から登録することはできますか?
- コンポーネントなしでnsICategoryManager.addCategoryEntry "content-policy"を使用することはできますか?
- ブートストラップされた内線番号でコンポーネントを登録するか、何らかの形で 新しい「content-policy」カテゴリエントリを追加するにはどうすればよいですか? )))私は多くのパスを試してみました「VEの
var {Cc, Ci, Cu} = require("chrome"); Cu.import("resource://deferredto/lib/interceptor.js");
しかしなし:
は、私が活用-options.jsし、私はモジュールをインポートしようとする方法である
"requirements": {
"sdk/page-mod": "sdk/page-mod",
"sdk/self": "sdk/self",
"chrome": "chrome"},
追加しました働くchrome.manifestファイルのリソースエントリは、ブートストラップされた拡張機能には許可されません。コンポーネントモジュールファイルへのパスは次のとおりです。restartlessですが、ちょうどあなたのSDKが希望のように、SDK、実行時にregisters an nsIContentPolicy
implementationを使用していない resources/deferredto/lib/interceptor.js
最後に、私はこのためのFirefoxアドオンSDKの解決策を見つけました。 mozilla.org/en-US/developers/docs/sdk/latest/modules/sdk/platform/xpcom.html)。 –
それを知らなかった。知っておいてよかった。カテゴリに関するコメント、特にアンロード部分は依然として存在します。 ;) – nmaier
おそらく、この新しいモジュールです。私は前にこの問題を調査し、アドオンSDKが最初に確認していました。 –