나는 NsIContentPolicy을 읽고 NsIContentPolicy를 구현하기위한 적절한 자습서 전체 Stackoverflow를 검색했지만 모두 헛된 것입니다. Adblock이 NsIContentPolicy를 주요 무기로 사용한다는 것을 알고 있습니다. 리버스 엔지니어링 Adblock은 NsIContentPolicy를 구현하는 방법을 이해하는 데 도움이되지 않았습니다. 학습을 위해 NsIContentPolicy를 사용하는 단순한 애드온이나 NsIContentPolicy의 유용한 튜토리얼이 있습니까?firefox addon에 대한 nsIContentPolicy의 예는 무엇입니까?
3
A
답변
9
나는 어떤 좋은 튜토리얼을 인식하지 오전하지만 난 당신에게 최소한의 예제 코드를 제공 할 수 있습니다 :
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
let policy =
{
classDescription: "Test content policy",
classID: Components.ID("{12345678-1234-1234-1234-123456789abc}"),
contractID: "@adblockplus.org/test-policy;1",
xpcom_categories: ["content-policy"],
init: function()
{
let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
registrar.registerFactory(this.classID, this.classDescription, this.contractID, this);
let catMan = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
for each (let category in this.xpcom_categories)
catMan.addCategoryEntry(category, this.contractID, this.contractID, false, true);
onShutdown.add((function()
{
for each (let category in this.xpcom_categories)
catMan.deleteCategoryEntry(category, this.contractID, false);
// This needs to run asynchronously, see bug 753687
Services.tm.currentThread.dispatch(function()
{
registrar.unregisterFactory(this.classID, this);
}.bind(this), Ci.nsIEventTarget.DISPATCH_NORMAL);
}).bind(this));
},
// nsIContentPolicy interface implementation
shouldLoad: function(contentType, contentLocation, requestOrigin, node, mimeTypeGuess, extra)
{
dump("shouldLoad: " + contentType + " " +
(contentLocation ? contentLocation.spec : "null") + " " +
(requestOrigin ? requestOrigin.spec : "null") + " " +
node + " " +
mimeTypeGuess + "\n");
return Ci.nsIContentPolicy.ACCEPT;
},
shouldProcess: function(contentType, contentLocation, requestOrigin, node, mimeTypeGuess, extra)
{
dump("shouldProcess: " + contentType + " " +
(contentLocation ? contentLocation.spec : "null") + " " +
(requestOrigin ? requestOrigin.spec : "null") + " " +
node + " " +
mimeTypeGuess + "\n");
return Ci.nsIContentPolicy.ACCEPT;
},
// nsIFactory interface implementation
createInstance: function(outer, iid)
{
if (outer)
throw Cr.NS_ERROR_NO_AGGREGATION;
return this.QueryInterface(iid);
},
// nsISupports interface implementation
QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPolicy, Ci.nsIFactory])
};
policy.init();
이 내가 콘텐츠 정책 구현에 문제를보고 사용하는 최소한의 콘텐츠 정책의 구현에서 온다 -을 모든 콘텐츠 정책 호출을 콘솔에 덤프하는 것 외에는 아무 것도하지 않습니다 (window.dump
documentation). 실제 구현에서 필드 classDescription
, classID
및 contractID
은 분명히 적절한 것으로 변경되어야합니다. onShutdown
은 내가 사용하고있는 개인 프레임 워크에 속합니다.이 확장 프로그램은 "수동으로"구성 요소를 등록해야하는 이유 때문에이 확장 프로그램을 다시 시작하지 않으며 브라우저 세션 중에 종료되면이 코드를 실행하여 제거합니다.
전체 내선 번호 (testpolicy.xpi)를 다운로드 할 수도 있습니다.
관련 문제
- 1. Simplistic Firefox Addon에 대한 자습서
- 2. firefox addon에 대한 홈페이지 링크를 추가하는 방법
- 3. Firefox Addon에 "두뇌"가 하나 있습니까?
- 4. iPhone의 ofVideoPlayer에 대한 예는 무엇입니까?
- 5. 왜 firefox addon에 래핑 된 userscript가 greasemonkey에서 같은 스크립트보다 느린가요?
- 6. C++ 라이브러리에 대한 C 인터페이스의 예는 무엇입니까?
- 7. 구조체 멤버에 대한 파일 입력의 예는 무엇입니까?
- 8. 실제 ACID의 예는 무엇입니까?
- 9. Wicket ChoiceFilteredPropertyColumn의 예는 무엇입니까?
- 10. IronPython에서 ctypes의 예는 무엇입니까?
- 11. Firefox addon에 내장 된 XPCOM 구성 요소를 덮어 쓰는 방법은 무엇입니까?
- 12. 휴면 오류의 예는 무엇입니까?
- 13. 다이얼을 만드는 예는 무엇입니까?
- 14. xslt의 우아한 예는 무엇입니까?
- 15. 예는
- 16. 잘못된 utf8 문자열의 예는 무엇입니까?
- 17. RemoteIO에서 오디오를 저장하는 예는 무엇입니까?
- 18. Firefox (firefox 4)에서 keyframe animation css3에 대한 도움이 필요합니다.
- 19. 의견 양식에 대한 모달 대화 상자의 예는 무엇입니까?
- 20. 양식의 값으로 js 확인 팝업을 표시하는 방법에 대한 예는 무엇입니까?
- 21. 이 데이터 형식을 JSON으로 변환하는 방법에 대한 예는 무엇입니까?
- 22. Google TV jQuery 라이브러리에 대한 독립형 동영상 컨트롤의 예는 무엇입니까?
- 23. 컬렉션 클래스에 대한 __eq__ 메서드의 좋은 예는 무엇입니까?
- 24. 서비스 위치 프로토콜에 대한 클라이언트 구현의 예는 무엇입니까?
- 25. Single Responsibility Principle 위반에 대한 가장 좋은 예는 무엇입니까?
- 26. Single Responsibility Principle의 예는 무엇입니까?
- 27. 병렬 계산의 표준 예는 무엇입니까?
- 28. StringBuffer를 사용하는 실제적인 예는 무엇입니까?
- 29. grails cucumber plugin의 예는 무엇입니까?
- 30. Python 라이브러리의 좋은 예는 무엇입니까?
블라디미르는, 그 testpolicy.xpi 내가가 :) 감사 찾던 정확히 많은 : –
예를 들어 링크가 깨진이,
수입은 여전히,이 블록 만 네트워크 콘텐츠 및 방법 변경에 대한 업데이트,는하지만, 될 필요가 돔 나무? – msangel@msangel : 링크를 업데이트했습니다. 여기 코드는 간단한 부트 스트랩 된 확장의 예제 일뿐입니다. 확장이 SDK 기반 인 경우 조정할 수 있으므로 자유롭게 조정할 수 있지만 게시물을 편집하지 마십시오. 문제는 네트워크 요청을 차단하는 데 유용한 콘텐츠 정책에 대한 것이지만 DOM 수정은 다른 방법으로 이루어져야합니다. –