How to CHANGE Firefox behaviour, not ADD - Mozilla

This is a discussion on How to CHANGE Firefox behaviour, not ADD - Mozilla ; Hi, I'm updating an extension I developed, and I'd need to somehow alter the behaviour of the code used when the user does a search using the Search Bar: normally, if your preferences are to open pages in new tabs, ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: How to CHANGE Firefox behaviour, not ADD

  1. How to CHANGE Firefox behaviour, not ADD

    Hi,
    I'm updating an extension I developed, and I'd need to somehow alter the
    behaviour of the code used when the user does a search using the Search
    Bar: normally, if your preferences are to open pages in new tabs, and
    you enter a search term and press Alt+Enter (on a Mac, I suppose on Win
    it's similar), the search results are opened in a new tab.
    I need to intercept this "new tab" call, check the content of the
    *current* tab, and then, based on the check result, open the search
    results in the current tab or in a new one.

    As far as I could see, there are three spots where I could theoretically
    insert my code:

    1. The whereToOpenLink function in utilityOverlay.js.

    2. The handleSearchCommand or doSearch methods in search.xml.

    3. The BrowserSearch_search function in browser.js.

    What is the best and correct way to proceed in such cases? I suppose
    "overwriting" the original functions is not a great idea. Is there a
    suitable progress listener? What else?

    Most examples deal with ADDING something to the browser, so I'm pretty
    lost regarding how to MODIFY its behaviour instead :-/. I already had
    successful results with the previous version of my extension, but I'd
    like to be sure I'm doing it right this time.
    I've read quite a few docs, asked on IRC, asked on Mozillazine... to no
    avail.

    Thanks a lot for any pointers.

    --
    Ciao,
    Marco.

  2. Re: How to CHANGE Firefox behaviour, not ADD

    On Mar 5, 5:31 pm, Marco De Vitis wrote:
    > Hi,
    > I'm updating an extension I developed, and I'd need to somehow alter the
    > behaviour of the code used when the user does a search using the Search
    > Bar: normally, if your preferences are to open pages in new tabs, and
    > you enter a search term and press Alt+Enter (on a Mac, I suppose on Win
    > it's similar), the search results are opened in a new tab.
    > I need to intercept this "new tab" call, check the content of the
    > *current* tab, and then, based on the check result, open the search
    > results in the current tab or in a new one.
    >
    > As far as I could see, there are three spots where I could theoretically
    > insert my code:
    >
    > 1. The whereToOpenLink function in utilityOverlay.js.
    >
    > 2. The handleSearchCommand or doSearch methods in search.xml.
    >
    > 3. The BrowserSearch_search function in browser.js.
    >
    > What is the best and correct way to proceed in such cases? I suppose
    > "overwriting" the original functions is not a great idea. Is there a
    > suitable progress listener? What else?
    >
    > Most examples deal with ADDING something to the browser, so I'm pretty
    > lost regarding how to MODIFY its behaviour instead :-/. I already had
    > successful results with the previous version of my extension, but I'd
    > like to be sure I'm doing it right this time.
    > I've read quite a few docs, asked on IRC, asked on Mozillazine... to no
    > avail.
    >
    > Thanks a lot for any pointers.
    >
    > --
    > Ciao,
    > Marco.


    If you are just concerned with writing your codes on tab switches, you
    can very well use the Tab Event Listeners. See the link :
    http://developer.mozilla.org/en/docs...Tabbed_browser
    for details. In each event object you can get the event._tPos to get
    the positional index of the tab that fired the particular event.

    HTH

  3. Re: How to CHANGE Firefox behaviour, not ADD

    Il 8-03-2008 23:12, stony_dreams ha scritto:

    > If you are just concerned with writing your codes on tab switches, you
    > can very well use the Tab Event Listeners. See the link :


    Well, I'm not sure that's what I need, because I'm interested in
    listening for searches from the searchbar... if I listen for tab
    operations, wouldn't it be too late to change the "where to open
    results" behaviour, now that the open tab event has been fired?

    Thanks anyway, I'm browsing developer.mozilla.org since a few days and
    maybe I'm (very) slowly getting the hang of it, mostly thanks to real
    world examples (i.e. other extensions), although I would strongly prefer
    to have more official documentation, and that's a real pity; I do not
    like to just imitate other people's work, I like doing it the right way.

    --
    Ciao,
    Marco.

  4. Re: How to CHANGE Firefox behaviour, not ADD

    Probably just add an event listener on the search bar, so each time
    some interaction occurs on this textbox, ur event handler would be
    notified...

    HTH

    On Mar 8, 7:40 pm, Marco De Vitis wrote:
    > Il 8-03-2008 23:12, stony_dreams ha scritto:
    >
    > > If you are just concerned with writing your codes on tab switches, you
    > > can very well use the Tab Event Listeners. See the link :

    >
    > Well, I'm not sure that's what I need, because I'm interested in
    > listening for searches from the searchbar... if I listen for tab
    > operations, wouldn't it be too late to change the "where to open
    > results" behaviour, now that the open tab event has been fired?
    >
    > Thanks anyway, I'm browsing developer.mozilla.org since a few days and
    > maybe I'm (very) slowly getting the hang of it, mostly thanks to real
    > world examples (i.e. other extensions), although I would strongly prefer
    > to have more official documentation, and that's a real pity; I do not
    > like to just imitate other people's work, I like doing it the right way.
    >
    > --
    > Ciao,
    > Marco.



  5. Re: How to CHANGE Firefox behaviour, not ADD

    Il 10-03-2008 22:38, stony_dreams ha scritto:

    > Probably just add an event listener on the search bar, so each time
    > some interaction occurs on this textbox, ur event handler would be
    > notified...


    And how can it be done?
    I see lots of examples for "load page" progress listeners, but I have no
    idea how could I "add an event listener on the search bar".

    Also, when looking at code from other extensions which modify the way
    tabs are opened, I see stuff like this, where original Firefox code is
    being somehow "overwritten":

    > eval("gBrowser.addTab = " + gBrowser.addTab.toString().replace(
    > 'if (t.previousSibling.selected)',
    > 'if (tabsopenrelative_ignoreNext) { \
    > tabsopenrelative_ignoreNext = false; \
    > } \
    > else { \
    > this.moveTabTo(t, this.mCurrentTab._tPos + tabsopenrelative_nextTab); \
    > tabsopenrelative_nextTab++; \
    > } \
    > if (t.previousSibling.selected)'
    > ));


    Is this the correct way to do such things? This is the same I've been
    doing, after all, just a bit more elegant...

    Thanks.

    --
    Ciao,
    Marco.

  6. Re: How to CHANGE Firefox behaviour, not ADD

    On Mar 10, 6:45 pm, Marco De Vitis wrote:
    > Il 10-03-2008 22:38, stony_dreams ha scritto:
    >
    > > Probably just add an event listener on the search bar, so each time
    > > some interaction occurs on this textbox, ur event handler would be
    > > notified...

    >
    > And how can it be done?


    Just see the browser.xul or the xul overlay file for the search bar
    and get its id... After this u can do a document.getElementById() and
    on that element you can perform an addEventListener() and add a
    keypressed event... After this you can check for the "enter" presses
    or whatever key u want and write your own functionality.

    -Stony_Dreams

+ Reply to Thread