Re: reading firefox history file: ascii conversion API - Mozilla

This is a discussion on Re: reading firefox history file: ascii conversion API - Mozilla ; ----- Original Message ---- > From: newbiegalore > To: dev-extensions@lists.mozilla.org > Sent: Thursday, May 8, 2008 9:30:53 PM > Subject: reading firefox history file: ascii conversion API > > Hello all :-), > I am learning JS and extension programming ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Re: reading firefox history file: ascii conversion API

  1. Re: reading firefox history file: ascii conversion API



    ----- Original Message ----
    > From: newbiegalore
    > To: dev-extensions@lists.mozilla.org
    > Sent: Thursday, May 8, 2008 9:30:53 PM
    > Subject: reading firefox history file: ascii conversion API
    >
    > Hello all :-),
    > I am learning JS and extension programming and so am
    > facing a few hurdles. I would greatly appreciate any pointers/code-
    > samples/links to possible solutions.
    >
    > My extension needs to read the history.dat file from the user's
    > profile. I am trying to read the data stream and will need to extract
    > the URLs from the file. Is there some easy/standard command/API to do
    > this? I guess it must be a commonly implemented feature.
    >
    > I have tried using String.fromCharCode(a-decimal-number); and written
    > some functions based on code I saw on prodigynet.co.uk, they are
    > listed at the very end of this post. I have not come across an API
    > which could extract the URLs from the firefox history file. It would
    > be great if someone could please point me in the right direction


    For firefox 3:
    http://developer.mozilla.org/en/docs...istory_service

    HTH,
    Eric


    __________________________________________________ __________________________________
    Be a better friend, newshound, and
    know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i...Dypao8Wcj9tAcJ

  2. Re: reading firefox history file: ascii conversion API

    On May 8, 6:57 pm, "Eric H. Jung" wrote:
    > ----- Original Message ----
    > > From: newbiegalore
    > > To: dev-extensi...@lists.mozilla.org
    > > Sent: Thursday, May 8, 2008 9:30:53 PM
    > > Subject: reading firefox history file: ascii conversion API

    >
    > > Hello all :-),
    > > I am learning JS and extension programming and so am
    > > facing a few hurdles. I would greatly appreciate any pointers/code-
    > > samples/links to possible solutions.

    >
    > > My extension needs to read the history.dat file from the user's
    > > profile. I am trying to read the data stream and will need to extract
    > > the URLs from the file. Is there some easy/standard command/API to do
    > > this? I guess it must be a commonly implemented feature.

    >
    > > I have tried using String.fromCharCode(a-decimal-number); and written
    > > some functions based on code I saw on prodigynet.co.uk, they are
    > > listed at the very end of this post. I have not come across an API
    > > which could extract the URLs from the firefox history file. It would
    > > be great if someone could please point me in the right direction

    >
    > For firefox 3:http://developer.mozilla.org/en/docs...istory_service
    >
    > HTH,
    > Eric
    >
    > __________________________________________________ __________________________________
    > Be a better friend, newshound, and
    > know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i...Dypao8Wcj9tAcJ


    Thanks Eric for the pointer.

    I tried

    var jaalhistoryService = Components.classes["@mozilla.org/browser/nav-
    history-service;1"]
    .getService(Components.interfaces.nsINavHistorySer vice);

    // no query parameters will get all history
    // XXX default sorting is... ?
    var ffhistoptions = jaalhistoryService.getNewQueryOptions();

    // no query parameters will return everything
    var ffhistquery = jaalhistoryService.getNewQuery();

    // execute the query
    var fftexto = jaalhistoryService.executeQuery(ffhistquery,
    ffhistoptions);
    alert(fftexto);


    But nothing pops up on screen. The places description says that
    without using any query parameters I can get everything in a flat file
    format.. yet I don't seem to receive any data. Any ideas?

  3. Re: reading firefox history file: ascii conversion API

    On May 8, 8:08 pm, newbiegalore wrote:
    > On May 8, 6:57 pm, "Eric H. Jung" wrote:
    >
    >
    >
    > > ----- Original Message ----
    > > > From: newbiegalore
    > > > To: dev-extensi...@lists.mozilla.org
    > > > Sent: Thursday, May 8, 2008 9:30:53 PM
    > > > Subject: reading firefox history file: ascii conversion API

    >
    > > > Hello all :-),
    > > > I am learning JS and extension programming and so am
    > > > facing a few hurdles. I would greatly appreciate any pointers/code-
    > > > samples/links to possible solutions.

    >
    > > > My extension needs to read the history.dat file from the user's
    > > > profile. I am trying to read the data stream and will need to extract
    > > > the URLs from the file. Is there some easy/standard command/API to do
    > > > this? I guess it must be a commonly implemented feature.

    >
    > > > I have tried using String.fromCharCode(a-decimal-number); and written
    > > > some functions based on code I saw on prodigynet.co.uk, they are
    > > > listed at the very end of this post. I have not come across an API
    > > > which could extract the URLs from the firefox history file. It would
    > > > be great if someone could please point me in the right direction

    >
    > > For firefox 3:http://developer.mozilla.org/en/docs...istory_service

    >
    > > HTH,
    > > Eric

    >
    > > __________________________________________________ __________________________________
    > > Be a better friend, newshound, and
    > > know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i...Dypao8Wcj9tAcJ

    >
    > Thanks Eric for the pointer.
    >
    > I tried
    >
    > var jaalhistoryService = Components.classes["@mozilla.org/browser/nav-
    > history-service;1"]
    > .getService(Components.interfaces.nsINavHistorySer vice);
    >
    > // no query parameters will get all history
    > // XXX default sorting is... ?
    > var ffhistoptions = jaalhistoryService.getNewQueryOptions();
    >
    > // no query parameters will return everything
    > var ffhistquery = jaalhistoryService.getNewQuery();
    >
    > // execute the query
    > var fftexto = jaalhistoryService.executeQuery(ffhistquery,
    > ffhistoptions);
    > alert(fftexto);
    >
    > But nothing pops up on screen. The places description says that
    > without using any query parameters I can get everything in a flat file
    > format.. yet I don't seem to receive any data. Any ideas?


    Update: I tried out the following code


    alert('hello');

    //using standard history query mechanism
    var jaalhistoryService =
    Components.classes["@mozilla.org/browser/nav-history-service;
    1"].getService(Components.interfaces.nsINavHistorySer vice);

    var ffhistoptions = jaalhistoryService.getNewQueryOptions(); //
    line1

    var ffhistquery =
    jaalhistoryService.getNewQuery(); //line2

    var fftexto = jaalhistoryService.executeQuery(ffhistquery,
    ffhistoptions); //line3

    var cont = fftexto.root;
    var n = cont.childCount;
    alert(n);
    n =Math.min(n, 3);
    cont.containerOpen = true;
    for (var i = 0; i < n; i ++) {
    var node = cont.getChild(i);
    alert(node.title + "\n");
    }
    cont.containerOpen = false;


    The first alert('hello') works fine when its at the beginning as
    presented here, when I try to move it between lines 1/2/3 it does not
    fire. Also later in the code, alert('n') denoting the childcount does
    not get fired. In the original example on MDC, dump was used instead
    of alert, but that shouldn't be the only reason, right?

    I linked this code to run whenever I click on a page and it seems that
    something is happening in the background because the response time
    slows down a little. So it could be running the query but not dumping
    on the screen.. Do I have to use some kind of Views as in Places:Views
    for accessing the history data?

    Again thanks for all the great help :-)

  4. Re: reading firefox history file: ascii conversion API

    On May 9, 11:03*am, newbiegalore wrote:
    > On May 8, 8:08 pm, newbiegalore wrote:
    >
    >
    >
    >
    >
    > > On May 8, 6:57 pm, "Eric H. Jung" wrote:

    >
    > > > ----- Original Message ----
    > > > > From: newbiegalore
    > > > > To: dev-extensi...@lists.mozilla.org
    > > > > Sent: Thursday, May 8, 2008 9:30:53 PM
    > > > > Subject: reading firefox history file: ascii conversion API

    >
    > > > > Hello all :-),
    > > > > * * * * * * * * *I am learning JS and extension programming and so am
    > > > > facing a few hurdles. I would greatly appreciate any pointers/code-
    > > > > samples/links to possible solutions.

    >
    > > > > My extension needs to read the history.dat file from the user's
    > > > > profile. I am trying to read the data stream and will need to extract
    > > > > the URLs from the file. Is there some easy/standard command/API to do
    > > > > this? I guess it must be a commonly implemented feature.

    >
    > > > > I have tried using String.fromCharCode(a-decimal-number); and written
    > > > > some functions based on code I saw on prodigynet.co.uk, they are
    > > > > listed at the very end of this post. I have not come across an API
    > > > > which could extract the URLs from the firefox history file. It would
    > > > > be great if someone could please point me in the right direction

    >
    > > > For firefox 3:http://developer.mozilla.org/en/docs...istory_service

    >
    > > > HTH,
    > > > Eric

    >
    > > > * * * __________________________________________________ _________________________*_________
    > > > Be a better friend, newshound, and
    > > > know-it-all with Yahoo! Mobile. *Try it now. *http://mobile.yahoo.com/;_ylt=Ahu06i...Dypao8Wcj9tAcJ

    >
    > > Thanks Eric for the pointer.

    >
    > > *I tried

    >
    > > var jaalhistoryService = Components.classes["@mozilla.org/browser/nav-
    > > history-service;1"]
    > > * * * * * * * * * * * * * * * *.getService(Components.interfaces.nsINavHistorySe rvice);

    >
    > > * *// no query parameters will get all history
    > > * *// XXX default sorting is... ?
    > > * *var ffhistoptions = jaalhistoryService.getNewQueryOptions();

    >
    > > * *// no query parameters will return everything
    > > * *var ffhistquery = jaalhistoryService.getNewQuery();

    >
    > > * *// execute the query
    > > * *var fftexto = jaalhistoryService.executeQuery(ffhistquery,
    > > ffhistoptions);
    > > * *alert(fftexto);

    >
    > > But nothing pops up on screen. The places description says that
    > > without using any query parameters I can get everything in a flat file
    > > format.. yet I don't seem to receive any data. Any ideas?

    >
    > Update: I tried out the following code
    >
    > * * * *alert('hello');
    >
    > * * * *//using standard history query mechanism
    > * * * *var jaalhistoryService =
    > Components.classes["@mozilla.org/browser/nav-history-service;
    > 1"].getService(Components.interfaces.nsINavHistorySer vice);
    >
    > * * * * var ffhistoptions = jaalhistoryService.getNewQueryOptions(); //
    > line1
    >
    > * * * * var ffhistquery =
    > jaalhistoryService.getNewQuery(); * * * * * * *//line2
    >
    > * * * * var fftexto = jaalhistoryService.executeQuery(ffhistquery,
    > ffhistoptions); //line3
    >
    > * * * * var cont = fftexto.root;
    > * * * * var n = cont.childCount;
    > * * * * alert(n);
    > * * * * n =Math.min(n, 3);
    > * * * * cont.containerOpen = true;
    > * * * * for (var i = 0; i < n; i ++) {
    > * * * * * * *var node = cont.getChild(i);
    > * * * * * * *alert(node.title + "\n");
    > * * * * }
    > * * * * cont.containerOpen = false;
    >
    > The first alert('hello') works fine when its at the beginning as
    > presented here, when I try to move it between lines 1/2/3 it does not
    > fire. Also later in the code, alert('n') denoting the childcount does
    > not get fired. In the original example on MDC, dump was used instead
    > of alert, but that shouldn't be the only reason, right?
    >
    > I linked this code to run whenever I click on a page and it seems that
    > something is happening in the background because the response time
    > slows down a little. So it could be running the query but not dumping
    > on the screen.. Do I have to use some kind of Views as in Places:Views
    > for accessing the history data?
    >
    > Again thanks for all the great help :-)- Hide quoted text -
    >
    > - Show quoted text -


    Update: Could someone *please* let me know how to convert an ascii
    stream read from a file to a text blob.

    I am writing to a file using

    var jaalcachefile = Components.classes["@mozilla.org/file/
    directory_service;1"]
    .getService(Components.interfaces.nsIProperties)
    .get("ProfD", Components.interfaces.nsIFile);
    //point to cache file
    jaalcachefile.append("cache-classified.txt");

    jaalcachefile.createUnique(Components.interfaces.n sIFile.NORMAL_FILE_TYPE,
    0666);
    //package data to push in file
    var shorturl = snipurl(window.content.document.location.href);

    //cache file should contain shorturl, fullurl, safety-
    analysis and date
    var date1 = new Date() ;
    var pushdata = shorturl + "@" +
    window.content.document.location.href + "@" + analysis + "@" +
    date1.getTime();

    // Write in cache file
    var cacheStream = Components.classes["@mozilla.org/network/file-
    output-stream;
    1"].createInstance(Components.interfaces.nsIFileOutpu tStream);

    cacheStream.init(jaalcachefile, 0x02 | 0x10 | 0x20, 0666, 0);
    cacheStream.write(pushdata, pushdata.length);
    cacheStream.close();



    This writes the data fine to a file, but when I read it its
    104,61,56,.. basically ascii values,
    I tried using the following code from MDC and it also works fine
    writing the characters in the file,

    var charset = "UTF-8"; // Can be any character encoding name that
    Mozilla supports
    var os = Components.classes["@mozilla.org/intl/converter-output-stream;
    1"]
    .createInstance(Components.interfaces.nsIConverter OutputStream);

    // This assumes that fos is the nsIOutputStream you want to write to
    os.init(cacheStream, charset, 0, 0x0000);
    os.writeString("Umlaute: \u00FC \u00E4\n");
    os.writeString("Hebrew: \u05D0 \u05D1\n");
    os.close();



    but when I read it back using the following, again, (inspired by MDC
    code) I got back 104,61,56,.. in the alert box.

    var jaalcacheios = Components.classes["@mozilla.org/network/io-service;
    1"].getService(Components.interfaces.nsIIOService);
    var jaalcachefileURI = jaalcacheios.newFileURI(jaalcachefile);
    var jaalcachechannel =
    jaalcacheios.newChannelFromURI(jaalcachefileURI);
    var jaalcacheobserver = {
    onStreamComplete : function(aLoader, aContext, aStatus,
    aLength, aResult)
    {

    alert(aResult);
    };
    var jaalcachesl = Components.classes["@mozilla.org/network/stream-
    loader;1"]
    .createInstance(Components.interfaces.nsIStreamLoa der);
    jaalcachesl.init(jaalcachechannel, jaalcacheobserver, null);

    I have also tried to use code from the first 3 highlighted boxes on
    http://developer.mozilla.org/en/docs...g_textual_data and
    specified UTF-8 as the encoding but the alerts just don't fire.

    Can someone please point me to an API to convert the output from the
    file reading (aResult) into a text based blob that I can parse. This
    would also help solve my previous problem of not being able to parse
    the history.dat file. Somehow I am failing to use containers
    properly.

    Thanks again,
    -A

  5. Re: reading firefox history file: ascii conversion API

    On May 9, 6:52*pm, newbiegalore wrote:
    > On May 9, 11:03*am, newbiegalore wrote:
    >
    >
    >
    >
    >
    > > On May 8, 8:08 pm, newbiegalore wrote:

    >
    > > > On May 8, 6:57 pm, "Eric H. Jung" wrote:

    >
    > > > > ----- Original Message ----
    > > > > > From: newbiegalore
    > > > > > To: dev-extensi...@lists.mozilla.org
    > > > > > Sent: Thursday, May 8, 2008 9:30:53 PM
    > > > > > Subject: reading firefox history file: ascii conversion API

    >
    > > > > > Hello all :-),
    > > > > > * * * * * * * * *I am learning JS and extension programming and so am
    > > > > > facing a few hurdles. I would greatly appreciate any pointers/code-
    > > > > > samples/links to possible solutions.

    >
    > > > > > My extension needs to read the history.dat file from the user's
    > > > > > profile. I am trying to read the data stream and will need to extract
    > > > > > the URLs from the file. Is there some easy/standard command/API todo
    > > > > > this? I guess it must be a commonly implemented feature.

    >
    > > > > > I have tried using String.fromCharCode(a-decimal-number); and written
    > > > > > some functions based on code I saw on prodigynet.co.uk, they are
    > > > > > listed at the very end of this post. I have not come across an API
    > > > > > which could extract the URLs from the firefox history file. It would
    > > > > > be great if someone could please point me in the right direction

    >
    > > > > For firefox 3:http://developer.mozilla.org/en/docs...istory_service

    >
    > > > > HTH,
    > > > > Eric

    >
    > > > > * * * __________________________________________________ _________________________**_________
    > > > > Be a better friend, newshound, and
    > > > > know-it-all with Yahoo! Mobile. *Try it now. *http://mobile.yahoo.com/;_ylt=Ahu06i...Dypao8Wcj9tAcJ

    >
    > > > Thanks Eric for the pointer.

    >
    > > > *I tried

    >
    > > > var jaalhistoryService = Components.classes["@mozilla.org/browser/nav-
    > > > history-service;1"]
    > > > * * * * * * * * * * * * * * * *.getService(Components.interfaces.nsINavHistorySe rvice);

    >
    > > > * *// no query parameters will get all history
    > > > * *// XXX default sorting is... ?
    > > > * *var ffhistoptions = jaalhistoryService.getNewQueryOptions();

    >
    > > > * *// no query parameters will return everything
    > > > * *var ffhistquery = jaalhistoryService.getNewQuery();

    >
    > > > * *// execute the query
    > > > * *var fftexto = jaalhistoryService.executeQuery(ffhistquery,
    > > > ffhistoptions);
    > > > * *alert(fftexto);

    >
    > > > But nothing pops up on screen. The places description says that
    > > > without using any query parameters I can get everything in a flat file
    > > > format.. yet I don't seem to receive any data. Any ideas?

    >
    > > Update: I tried out the following code

    >
    > > * * * *alert('hello');

    >
    > > * * * *//using standard history query mechanism
    > > * * * *var jaalhistoryService =
    > > Components.classes["@mozilla.org/browser/nav-history-service;
    > > 1"].getService(Components.interfaces.nsINavHistorySer vice);

    >
    > > * * * * var ffhistoptions = jaalhistoryService.getNewQueryOptions(); //
    > > line1

    >
    > > * * * * var ffhistquery =
    > > jaalhistoryService.getNewQuery(); * * * * * * *//line2

    >
    > > * * * * var fftexto = jaalhistoryService.executeQuery(ffhistquery,
    > > ffhistoptions); //line3

    >
    > > * * * * var cont = fftexto.root;
    > > * * * * var n = cont.childCount;
    > > * * * * alert(n);
    > > * * * * n =Math.min(n, 3);
    > > * * * * cont.containerOpen = true;
    > > * * * * for (var i = 0; i < n; i ++) {
    > > * * * * * * *var node = cont.getChild(i);
    > > * * * * * * *alert(node.title + "\n");
    > > * * * * }
    > > * * * * cont.containerOpen = false;

    >
    > > The first alert('hello') works fine when its at the beginning as
    > > presented here, when I try to move it between lines 1/2/3 it does not
    > > fire. Also later in the code, alert('n') denoting the childcount does
    > > not get fired. In the original example on MDC, dump was used instead
    > > of alert, but that shouldn't be the only reason, right?

    >
    > > I linked this code to run whenever I click on a page and it seems that
    > > something is happening in the background because the response time
    > > slows down a little. So it could be running the query but not dumping
    > > on the screen.. Do I have to use some kind of Views as in Places:Views
    > > for accessing the history data?

    >
    > > Again thanks for all the great help :-)- Hide quoted text -

    >
    > > - Show quoted text -

    >
    > Update: Could someone *please* let me know how to convert an ascii
    > stream read from a file to a text blob.
    >
    > I am writing to a file using
    >
    > var jaalcachefile = Components.classes["@mozilla.org/file/
    > directory_service;1"]
    > * * * * * * * * * * *.getService(Components.interfaces.nsIProperties)
    > * * * * * * * * * * *.get("ProfD", Components.interfaces.nsIFile);
    > //point to cache file
    > jaalcachefile.append("cache-classified.txt");
    >
    > jaalcachefile.createUnique(Components.interfaces.n sIFile.NORMAL_FILE_TYPE,
    > 0666);
    > * *//package data to push in file
    > * *var shorturl = snipurl(window.content.document.location.href);
    >
    > * * * * * * * *//cache file should contain shorturl, fullurl, safety-
    > analysis and date
    > * *var date1 = new Date() ;
    > * * * * * * * * var pushdata = shorturl + "@" +
    > window.content.document.location.href + "@" + analysis + "@" +
    > date1.getTime();
    >
    > * * * * * * * * // Write in cache file
    > * *var cacheStream = Components.classes["@mozilla.org/network/file-
    > output-stream;
    > 1"].createInstance(Components.interfaces.nsIFileOutpu tStream);
    >
    > * *cacheStream.init(jaalcachefile, 0x02 | 0x10 | 0x20, 0666, 0);
    > * *cacheStream.write(pushdata, pushdata.length);
    > * *cacheStream.close();
    >
    > This writes the data fine to a file, but when I read it its
    > 104,61,56,.. basically ascii values,
    > I tried using the following code from MDC and it also works fine
    > writing the characters in the file,
    >
    > var charset = "UTF-8"; // Can be any character encoding name that
    > Mozilla supports
    > var os = Components.classes["@mozilla.org/intl/converter-output-stream;
    > 1"]
    > * * * * * * *.createInstance(Components.interfaces.nsIConverte rOutputStream);
    >
    > *// This assumes that fos is the nsIOutputStream you want to write to
    > *os.init(cacheStream, charset, 0, 0x0000);
    > *os.writeString("Umlaute: \u00FC \u00E4\n");
    > *os.writeString("Hebrew: *\u05D0 \u05D1\n");
    > *os.close();
    >
    > but when I read it back using the following, again, (inspired by MDC
    > code) I got back 104,61,56,.. in the alert box.
    >
    > var jaalcacheios = Components.classes["@mozilla.org/network/io-service;
    > 1"].getService(Components.interfaces.nsIIOService);
    > var jaalcachefileURI = jaalcacheios.newFileURI(jaalcachefile);
    > var jaalcachechannel =
    > jaalcacheios.newChannelFromURI(jaalcachefileURI);
    > var jaalcacheobserver = {
    > * * * *onStreamComplete : function(aLoader, aContext, aStatus,
    > aLength, aResult)
    > * * * * *{
    >
    > * * * * * alert(aResult);
    > * * * *};
    > var jaalcachesl = Components.classes["@mozilla.org/network/stream-
    > loader;1"]
    > * * * * * * * * * *.createInstance(Components.interfaces.nsIStreamLo ader);
    > *jaalcachesl.init(jaalcachechannel, jaalcacheobserver, null);
    >
    > I have also tried to use code from the first 3 highlighted boxes onhttp://developer.mozilla.org/en/docs/Reading_textual_dataand
    > specified UTF-8 as the encoding but the alerts just don't fire.
    >
    > Can someone please point me to an API to convert the output from the
    > file reading (aResult) into a text based blob that I can parse. This
    > would also help solve my previous problem of not being able to parse
    > the history.dat file. Somehow I am failing to use containers
    > properly.
    >
    > Thanks again,
    > -A- Hide quoted text -
    >
    > - Show quoted text -


    Solved by using aRead[offset] instead of aRead.charAt(offset)..

+ Reply to Thread