17

Nel mio addon corrente i intercettando tutte le richieste HTTP su Firefox con http-on-modify-requestFirefox - Identificare che ha avviato la richiesta HTTP

In realtà con il mio codice attuale io sono in grado di separare le richieste provenienti dalla pagina web/schede e tutto il resto proveniente da (ad esempio, aggiornamenti feed RSS, richieste gestore estensioni, richieste XHR da componenti XPCOM, ecc.)

Vorrei identificare chi avvia una richiesta oltre al traffico Web con precisione non solo per l'intero gruppo (aggiornamenti feed RSS, estensione richieste di manager, richieste XHR da componenti XPCOM, ecc.)?

Esempio: una variabile personalizzata requestRequestor avrebbe un valore per identificare un addon specifico o RSS aggiornamento ecc

ho Fould questa domanda silimar Identify requests coming from PageWorker senza una soluzione.

codice corrente per identificare l'intero gruppo (getting the browser that fires the http-on-modify-request notification) è simile a:

Components.utils.import('resource://gre/modules/Services.jsm'); 
Services.obs.addObserver(httpObs, 'http-on-modify-request', false); 
//Services.obs.removeObserver(httpObs, 'http-on-modify-request'); //uncomment this line, or run this line when you want to remove the observer 

var httpObs = { 
    observe: function (aSubject, aTopic, aData) { 
     if (aTopic == 'http-on-modify-request') { 
      /*start - do not edit here*/ 
      var oHttp = aSubject.QueryInterface(Components.interfaces.nsIHttpChannel); //i used nsIHttpChannel but i guess you can use nsIChannel, im not sure why though 
      var interfaceRequestor = oHttp.notificationCallbacks.QueryInterface(Components.interfaces.nsIInterfaceRequestor); 
      //var DOMWindow = interfaceRequestor.getInterface(Components.interfaces.nsIDOMWindow); //not to be done anymore because: https://developer.mozilla.org/en-US/docs/Updating_extensions_for_Firefox_3.5#Getting_a_load_context_from_a_request //instead do the loadContext stuff below 
      var loadContext; 
      try { 
       loadContext = interfaceRequestor.getInterface(Components.interfaces.nsILoadContext); 
      } catch (ex) { 
       try { 
        loadContext = aSubject.loadGroup.notificationCallbacks.getInterface(Components.interfaces.nsILoadContext); 
        //in ff26 aSubject.loadGroup.notificationCallbacks was null for me, i couldnt find a situation where it wasnt null, but whenever this was null, and i knew a loadContext is supposed to be there, i found that "interfaceRequestor.getInterface(Components.interfaces.nsILoadContext);" worked fine, so im thinking in ff26 it doesnt use aSubject.loadGroup.notificationCallbacks anymore, but im not sure 
       } catch (ex2) { 
        loadContext = null; 
        //this is a problem i dont know why it would get here 
       } 
      } 
      /*end do not edit here*/ 
      /*start - do all your edits below here*/ 
      var url = oHttp.URI.spec; //can get url without needing loadContext 
      if (loadContext) { 
       var contentWindow = loadContext.associatedWindow; //this is the HTML window of the page that just loaded 
       //aDOMWindow this is the firefox window holding the tab 
       var aDOMWindow = contentWindow.top.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation).QueryInterface(Ci.nsIDocShellTreeItem).rootTreeItem.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow); 
       var gBrowser = aDOMWindow.gBrowser; //this is the gBrowser object of the firefox window this tab is in 
       var aTab = gBrowser._getTabForContentWindow(contentWindow.top); //this is the clickable tab xul element, the one found in the tab strip of the firefox window, aTab.linkedBrowser is same as browser var above //can stylize tab like aTab.style.backgroundColor = 'blue'; //can stylize the tab like aTab.style.fontColor = 'red'; 
       var browser = aTab.linkedBrowser; //this is the browser within the tab //this is what the example in the previous section gives 
       //end getting other useful stuff 
      } else { 
       Components.utils.reportError('EXCEPTION: Load Context Not Found!!'); 
       //this is likely no big deal as the channel proably has no associated window, ie: the channel was loading some resource. but if its an ajax call you may end up here 
      } 
     } 
    } 
}; 

Grazie per il vostro tempo

+3

Wow lavoro fantastico qui, hai visto questo argomento: http://stackoverflow.com/questions/27483651/firefox-addon-monitoring-network/27492685#27492685 È più di un argomento che potresti essere in grado di contribuire a Sono molto interessato a vedere come stai identificando le fonti finora. – Noitidart

+1

Grazie bro per il tuo collegamento più informazioni ho sulle richieste di firefox ecc. Più il mio addon sarà migliore, lavorando su un addon di sicurezza avanzato, non facile però, (è solo un hobby che l'addon sarà pubblico;) lascerò sai su github) – intika

+0

pubblicherò il mio codice sulla domanda che hai linkato in seguito;) – intika

risposta

1

È necessario guardare User Agent all'interno dell'intestazione HTTP. Fornisce dettagli sul sistema del cliente.

speranza che questo aiuta:

https://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx (stringa user-agent comprensione),

http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_nav_all (esempio di user-agent)

PS: Ho voluto pubblicare come un commento, ma io didn vediamo l'opzione

+0

L'agente utente riguarda il client che non ha fatto la richiesta – intika