Firefox 用のブートストラップ拡張機能があります。そして今、nsIContentPolicy XPCOM コンポーネントを実装したいと考えています。コンポーネントモジュールのコードを書きました。そして今、このコンポーネントを登録したいと思います。nsICategoryManager.addCategoryEntry
コンポーネントを登録する理由は、コンポーネントを「コンテンツ ポリシー」カテゴリに追加したいからです 。
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" を使用することは可能ですか?
- ブートストラップされた拡張機能にコンポーネントを登録する方法、または何らかの方法で新しい「コンテンツ ポリシー」カテゴリ エントリを追加する方法は?
Harness-options.js に追加しました
"requirements": {
"sdk/page-mod": "sdk/page-mod",
"sdk/self": "sdk/self",
"chrome": "chrome"},
それが私がモジュールをインポートしようとする方法です:
var {Cc, Ci, Cu} = require("chrome");
Cu.import("resource://deferredto/lib/interceptor.js");
私は多くのパスを試しました)))しかし、どれも機能しません。chrome.manifest ファイルのリソース エントリは、ブートストラップされた拡張機能には許可されていません。コンポーネント モジュール ファイルへのパスは次のとおりです。
resources/deferredto/lib/interceptor.js