Domanda

I am on project right now which is a very simple parental control software, but, I want to know what is the url requested in firefox to take respond based on it ... if you may help because I don't know how to let my software know what is the url requested by firefox .. How to do that? I have to use C++ in most of my software.. but if there are better language to do this task please advice me

È stato utile?

Soluzione

In Firefox you need to use XPCOM component called nsIHTTPChannel. This script below will block abort all rqeuests to google. The channel is opened but aborted before opening connection to server.

var {classes: Cc, results: Cr, utils: Cu} = Components;
Cu.import('resource://gre/modules/Services.jsm');

var httpRequestObserver = 
{
    observe: function(subject, topic, data)
    {
        var httpChannel, requestURL;

        if (topic == 'http-on-modify-request') {
            httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
            requestURL = httpChannel.URI.spec;

            if (/google\.com/.test(requestURL)) {
                httpChanel.cancel(Cr.NS_BINDING_ABORTED);
            }

            return;
        }
    }
};

Services.obs.addObserver(httpRequestObserver, 'http-on-modify-request', false);
//Services.obs.removeObserver(httpRequestObserver, "http-on-modify-request", false); //run this to remove observer

Altri suggerimenti

Can I suggest an alternative approach? Instead of writing an extension for Firefox and an extension for Chrome and an extension for IE... listen on the OS network interfaces for traffic and block undesirable URLS.

This is traditionally the job of a firewall. Using an existing solution will provide the most efficient means of solving your problem. I'm not familiar with the capabilities of the built in Windows firewall or 3rd party alternatives but something like this would be trivial with iptables (Linux).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top