Browse Source

Firefox: implement toolbar button and popup

pull/2/head
Deathamns 10 years ago
committed by gorhill
parent
commit
4f7070cf5d
  1. 24
      platform/firefox/frameModule.js

24
platform/firefox/frameModule.js

@ -1,14 +1,18 @@
/* global Services, Components, XPCOMUtils */ /* global Services, Components, XPCOMUtils */
/* exported EXPORTED_SYMBOLS, isTabbed */
'use strict'; 'use strict';
var EXPORTED_SYMBOLS = ['contentPolicy', 'docObserver'];
this.EXPORTED_SYMBOLS = ['contentPolicy', 'docObserver'];
Components.utils['import']('resource://gre/modules/Services.jsm'); Components.utils['import']('resource://gre/modules/Services.jsm');
Components.utils['import']('resource://gre/modules/XPCOMUtils.jsm'); Components.utils['import']('resource://gre/modules/XPCOMUtils.jsm');
const Ci = Components.interfaces, appName = 'ublock';
const Ci = Components.interfaces;
var appName;
try { throw new Error; } catch (ex) {
appName = ex.fileName.match(/:\/\/([^\/]+)/)[1];
}
let getMessager = function(win) { let getMessager = function(win) {
try { try {
@ -33,9 +37,10 @@ let getMessager = function(win) {
let contentPolicy = { let contentPolicy = {
classDescription: 'ContentPolicy implementation', classDescription: 'ContentPolicy implementation',
classID: Components.ID('{e6d173c8-8dbf-4189-a6fd-189e8acffd27}'), classID: Components.ID('{e6d173c8-8dbf-4189-a6fd-189e8acffd27}'),
contractID: '@ublock/content-policy;1',
contractID: '@' + appName + '/content-policy;1',
ACCEPT: Ci.nsIContentPolicy.ACCEPT, ACCEPT: Ci.nsIContentPolicy.ACCEPT,
REJECT: Ci.nsIContentPolicy.REJECT_REQUEST, REJECT: Ci.nsIContentPolicy.REJECT_REQUEST,
requestMessageName: appName + ':onBeforeRequest',
get componentRegistrar() { get componentRegistrar() {
return Components.manager.QueryInterface(Ci.nsIComponentRegistrar); return Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
}, },
@ -89,7 +94,7 @@ let contentPolicy = {
return this.ACCEPT; return this.ACCEPT;
} }
let result = getMessager(win).sendSyncMessage('ublock:onBeforeRequest', {
let result = getMessager(win).sendSyncMessage(this.requestMessageName, {
url: location.spec, url: location.spec,
type: type, type: type,
tabId: -1, tabId: -1,
@ -105,7 +110,7 @@ let contentPolicy = {
}; };
let docObserver = { let docObserver = {
contentBaseURI: 'chrome://ublock/content/js/',
contentBaseURI: 'chrome://' + appName + '/content/js/',
initContext: function(win, sandbox) { initContext: function(win, sandbox) {
let messager = getMessager(win); let messager = getMessager(win);
@ -115,6 +120,8 @@ let docObserver = {
wantComponents: false, wantComponents: false,
wantXHRConstructor: false wantXHRConstructor: false
}); });
win.self = win;
} }
win.sendAsyncMessage = messager.sendAsyncMessage; win.sendAsyncMessage = messager.sendAsyncMessage;
@ -151,10 +158,6 @@ let docObserver = {
lss(this.contentBaseURI + 'vapi-client.js', win); lss(this.contentBaseURI + 'vapi-client.js', win);
lss(this.contentBaseURI + 'contentscript-start.js', win); lss(this.contentBaseURI + 'contentscript-start.js', win);
if (doc.readyState === 'interactive' || doc.readyState === 'complete') {
lss(this.contentBaseURI + 'contentscript-end.js', win);
}
else {
let docReady = function(e) { let docReady = function(e) {
this.removeEventListener(e.type, docReady, true); this.removeEventListener(e.type, docReady, true);
lss(docObserver.contentBaseURI + 'contentscript-end.js', win); lss(docObserver.contentBaseURI + 'contentscript-end.js', win);
@ -162,7 +165,6 @@ let docObserver = {
doc.addEventListener('DOMContentLoaded', docReady, true); doc.addEventListener('DOMContentLoaded', docReady, true);
} }
}
}; };
contentPolicy.register(); contentPolicy.register();

Loading…
Cancel
Save