Programaticly set home page - Mozilla

This is a discussion on Programaticly set home page - Mozilla ; I'm a Win32 API C++ programmer and everything Firefox related reads like a foreign language to me, even though I can read JavaScript just fine. Reminds me of when I tried to write software for a Mac. If you guys ...

+ Reply to Thread
Results 1 to 8 of 8

Thread: Programaticly set home page

  1. Programaticly set home page

    I'm a Win32 API C++ programmer and everything Firefox related reads
    like a foreign language to me, even though I can read JavaScript just
    fine. Reminds me of when I tried to write software for a Mac. If you
    guys really want to get mainstream (take over IEs market share) it
    would help if you wrote some documentation in our language (you could
    call it "Firefox for Dumb Windows (non-Unix) Programmers" if you want,
    I don't mind).

    Anyway, how the hell do I set the home page for Firefox, from a
    Windows application (using Windows API calls please, for example,
    LoadLibrary if I need to load a Firefox DLL to do this, or
    CoCreateInstance if I need to use COM objects). My application runs
    as a system service and has full access to everything on the PC and
    the user wants me to set their homepage for them (not spyware).
    Internet Explorer makes it very easy by letting me just set one
    registry value. I found the settings in the %appdata% folder, but
    there must be a more robust method than manually editing that file
    (plus it says it will be overwritten if the user is running Firefox
    when I edit it).

    As far as I can tell, I probably need to use XPCOM, and most examples
    are in JavaScript. I got this far (for checking the home page):

    var prefs = Components.classes["@mozilla.org/preferences-service;
    1"].
    getService(Components.interfaces.nsIPrefBranch);

    var homepage;
    if (prefs.getPrefType("browser.startup.homepage") ==
    prefs.PREF_STRING){
    homepage = prefs.getCharPref("browser.startup.homepage");
    }

    alert(homepage);


    But when I try to run that in Windows script host, it doesn't know
    what "Components" is. I assume that code maybe needs to run inside
    Firefox, which is not at all what I want.

    Also, I can't use any 3rd party ActiveX controls or anything that may
    not be installed. I need this to work anytime Firefox is installed
    (although I don't care if I can't support pretty old versions).

    If my program can't set the home page for Firefox I'll have to
    recommend to everyone that they use Internet Explorer... M$ wins =(

  2. Re: Programaticly set home page

    On Nov 21, 3:46*pm, eselk2...@gmail.com wrote:
    > I'm a Win32 API C++ programmer and everything Firefox related reads
    > like a foreign language to me, even though I can read JavaScript just
    > fine. *Reminds me of when I tried to write software for a Mac. *If you
    > guys really want to get mainstream (take over IEs market share) it
    > would help if you wrote some documentation in our language (you could
    > call it "Firefox for Dumb Windows (non-Unix) Programmers" if you want,
    > I don't mind).
    >
    > Anyway, how the hell do I set the home page for Firefox, from a
    > Windows application (using Windows API calls please, for example,
    > LoadLibrary if I need to load a Firefox DLL to do this, or
    > CoCreateInstance if I need to use COM objects). *My application runs
    > as a system service and has full access to everything on the PC and
    > the user wants me to set their homepage for them (not spyware).
    > Internet Explorer makes it very easy by letting me just set one
    > registry value. *I found the settings in the %appdata% folder, but
    > there must be a more robust method than manually editing that file
    > (plus it says it will be overwritten if the user is running Firefox
    > when I edit it).
    >
    > As far as I can tell, I probably need to use XPCOM, and most examples
    > are in JavaScript. *I got this far (for checking the home page):
    >
    > * var prefs = Components.classes["@mozilla.org/preferences-service;
    > 1"].
    > * * * * * * * * getService(Components.interfaces.nsIPrefBranch);
    >
    > * var homepage;
    > * if (prefs.getPrefType("browser.startup.homepage") ==
    > prefs.PREF_STRING){
    > * * homepage = prefs.getCharPref("browser.startup.homepage");
    > * }
    >
    > * alert(homepage);
    >
    > But when I try to run that in Windows script host, it doesn't know
    > what "Components" is. *I assume that code maybe needs to run inside
    > Firefox, which is not at all what I want.
    >
    > Also, I can't use any 3rd party ActiveX controls or anything that may
    > not be installed. *I need this to work anytime Firefox is installed
    > (although I don't care if I can't support pretty old versions).
    >
    > If my program can't set the home page for Firefox I'll have to
    > recommend to everyone that they use Internet Explorer... M$ wins =(


    prefs.js is a flat text file. If you don't mind searching that file
    to see if it is set and changing through a plain old write to the text
    file that would work as well as anything else.

    But I agree with Ron. If you are going to change a person's home
    page, don't do it without their consent. I installed an app earlier
    today which installed the Yahoo! toolbar without even asking me.
    Pissed me off. Explains how the author tries to generate income from
    his otherwise free tool. Fine enough, but don't do it on the sly
    without the user's consent.

    JB

  3. Re: Programaticly set home page

    On Nov 21, 5:55*pm, Fox on the run wrote:
    > prefs.js is a flat text file. *If you don't mind searching that file
    > to see if it is set and changing through a plain old write to the text
    > file that would work as well as anything else.
    >


    I don't think it is just that simple though, I think there can be
    multiple files, some for all users, some for default users, and
    another for current user. Also, the file itself says Firefox will
    overwrite any changes made while Firefox is running, which may be a
    problem for me (especially with XP/Vista having multiple possible
    sessions open so it isn't even enough to just close it if running on
    the current session).

    > But I agree with Ron. *If you are going to change a person's home
    > page, don't do it without their consent. *I installed an app earlier
    > today which installed the Yahoo! toolbar without even asking me.
    > Pissed me off. *Explains how the author tries to generate income from
    > his otherwise free tool. *Fine enough, but don't do it on the sly
    > without the user's consent.


    These days it is hard to say exactly what consent is, is a checkbox on
    a setup wizard enough, even if checked by default.. what font size,
    what color, etc, etc. Is it enough to say "adjust browser settings"
    if there will be several other settings that will also be changed, or
    is a detailed list of possibly 100s of settings required (in which
    case your average user would never read it anyway - remember that no
    one that posts to newsgroups is your average user - unless I'm wrong
    and over 50% of PC users post to newsgroups).

    It sounds like, based on how much trouble I'm having finding a way to
    do this, the Firefox developers have not included an easy way to do
    this in their API/SDK/interfaces. And based on the 2 replies to my
    message, I'm guessing it is for fear of abuse. In my case, I'm pretty
    much just giving a parent a way to set the homepage for all of their
    children (actually just the ones they select) in one shot, to
    something more appropriate for small children. In most cases even if
    I gave the parent detailed instructions they will not be able to do
    this on their own, using the Firefox GUI, and they would need to login
    to each account to change it for each child.

  4. Re: Programaticly set home page

    On Nov 24, 12:27*pm, eselk2...@gmail.com wrote:
    > On Nov 21, 5:55*pm, Fox on the run wrote:
    >
    > > prefs.js is a flat text file. *If you don't mind searching that file
    > > to see if it is set and changing through a plain old write to the text
    > > file that would work as well as anything else.

    >
    > I don't think it is just that simple though, I think there can be
    > multiple files, some for all users, some for default users, and
    > another for current user. *Also, the file itself says Firefox will
    > overwrite any changes made while Firefox is running, which may be a
    > problem for me (especially with XP/Vista having multiple possible
    > sessions open so it isn't even enough to just close it if running on
    > the current session).


    Good point. Firefox will write prefs.js on exit. Well technically it
    writes to prefs-1.js and then once all is good that file is renamed to
    prefs.js. And also a good point that an individual user could have
    user.js file set with their home page.

    But here is a very simple solution to your problem given you are
    trying to do this for kids. Simply create a user.js file with the
    preferences you want set for the kids (be it only the homepage setting
    or more). Then simply copy that over into the profile folder for each
    of the kids. It will override whatever is set in prefs.js. I even
    tried changing my home page and although it retains the new home page
    for the duration of the session. As soon as I close FF the homepage
    in prefs.js is reset to the value I put in user.js (which is not
    editable from within FF so no matter if the kids change it, it will
    get reset each time to whatever Mom & Dad put in user.js).

    JB

  5. Re: Programaticly set home page

    On Nov 24, 11:17*am, Fox on the run wrote:
    > But here is a very simple solution to your problem given you are
    > trying to do this for kids. *Simply create a user.js file with the
    > preferences you want set for the kids (be it only the homepage setting
    > or more). *Then simply copy that over into the profile folder for each
    > of the kids.


    Do you happen to have a link to where I can get more info on user.js,
    like in the Firefox developer's site? Sounds like it may work. I
    don't want to overwrite any settings other than the home page though,
    so I would still have to manually edit the file and always just
    replace it. Also, I want them to be able to change it to something
    else easily if they want, so maybe the user.js will not work, but I
    would like to read more about it, to find out where it is located,
    etc. I know where it is located on my PC, but I need to find the
    "official" way to locate it, I don't want to be writing code that will
    break in the near future or if a user doesn't take the default install
    settings.


  6. Re: Programaticly set home page

    On Nov 26, 2:52*pm, eselk2...@gmail.com wrote:
    > On Nov 24, 11:17*am, Fox on the run wrote:
    >
    > > But here is a very simple solution to your problem given you are
    > > trying to do this for kids. *Simply create a user.js file with the
    > > preferences you want set for the kids (be it only the homepage setting
    > > or more). *Then simply copy that over into the profile folder for each
    > > of the kids.

    >
    > Do you happen to have a link to where I can get more info on user.js,
    > like in the Firefox developer's site? *Sounds like it may work. *I
    > don't want to overwrite any settings other than the home page though,
    > so I would still have to manually edit the file and always just
    > replace it. *Also, I want them to be able to change it to something
    > else easily if they want, so maybe the user.js will not work, but I
    > would like to read more about it, to find out where it is located,
    > etc. *I know where it is located on my PC, but I need to find the
    > "official" way to locate it, I don't want to be writing code that will
    > break in the near future or if a user doesn't take the default install
    > settings.


    You can read more about it at http://kb.mozillazine.org/User.js_file

    Where all you want to set is one preference, then you'd simply create
    a plain ASCII text file called user.js and write that one preference
    to it. Then copy it to the profile folder(s) where you want to set
    the home page statically to that value. user.js is found in the
    user's profile folder (see http://kb.mozillazine.org/Profiles.ini_file
    for more info on the file profiles.ini which contains the list of
    Firefox profiles and the path to their folders - that would be the
    file you'd parse through for the full path of the various profiles).

    If you are still not sure after reading through that contact me
    offline and we can chat further on it.

    JB

  7. Re: Programaticly set home page

    On Nov 26, 3:03*pm, Fox on the run wrote:
    > On Nov 26, 2:52*pm, eselk2...@gmail.com wrote:
    >
    >
    >
    > > On Nov 24, 11:17*am, Fox on the run wrote:

    >
    > > > But here is a very simple solution to your problem given you are
    > > > trying to do this for kids. *Simply create a user.js file with the
    > > > preferences you want set for the kids (be it only the homepage setting
    > > > or more). *Then simply copy that over into the profile folder for each
    > > > of the kids.

    >
    > > Do you happen to have a link to where I can get more info on user.js,
    > > like in the Firefox developer's site? *Sounds like it may work. *I
    > > don't want to overwrite any settings other than the home page though,
    > > so I would still have to manually edit the file and always just
    > > replace it. *Also, I want them to be able to change it to something
    > > else easily if they want, so maybe the user.js will not work, but I
    > > would like to read more about it, to find out where it is located,
    > > etc. *I know where it is located on my PC, but I need to find the
    > > "official" way to locate it, I don't want to be writing code that will
    > > break in the near future or if a user doesn't take the default install
    > > settings.

    >
    > You can read more about it athttp://kb.mozillazine.org/User.js_file
    >
    > Where all you want to set is one preference, then you'd simply create
    > a plain ASCII text file called user.js and write that one preference
    > to it. *Then copy it to the profile folder(s) where you want to set
    > the home page statically to that value. *user.js is found in the
    > user's profile folder (seehttp://kb.mozillazine.org/Profiles.ini_file
    > for more info on the file profiles.ini which contains the list of
    > Firefox profiles and the path to their folders - that would be the
    > file you'd parse through for the full path of the various profiles).
    >
    > If you are still not sure after reading through that contact me
    > offline and we can chat further on it.
    >
    > JB


    Another thought that came to mind. If the system is Windows Vista, it
    supports reparse points (much like symbolic links in Linux). You
    probably could set up a reparse point in the targeted Firefox profiles
    pointing to a single user.js file (assuming you want to use the same
    home page for several kids, but each with their own Firefox profile).
    Your application would then only have to worry about modifying that
    user.js file containing one single line - the preference to set the
    home page. That change would be reflected in all the profiles that
    have a reparse point pointing to that user.js file.

    I knew about user.js but had never really played with it. It has
    value for the scenario you are talking about. It is also very
    practical for the corporate environment where you want preferences for
    users set consistently. The SysAdmin creates a user.js file with the
    preferences of choice and then distributes it to all the profile
    folders of his/her users. The end user that attempts to change those
    preferences via Firefox (whether via the menu or via about:config)
    will only result in a temporary change. As soon as Firefox shuts
    down, the preferences in user.js are re-populated into the prefs.js
    thus overwriting the unauthorized changes made by the end user. Again
    a savvy end user would simply delete user.js or edit it manually. But
    here again using reparse points or access rights that does not permit
    the end user to edit or delete it, just read it, will solve that
    problem.

    I wonder if any adware/malware has used that file as a way of
    overriding a user's homepage selection or other preferences that would
    benefit the malware? If you keep changing your home page and it keeps
    getting changed back on re-start, that could be the culprit...

    JB.

  8. Re: Programaticly set home page

    On Nov 24, 1:17*pm, Fox on the run wrote:
    > On Nov 24, 12:27*pm, eselk2...@gmail.com wrote:
    >
    > > On Nov 21, 5:55*pm, Fox on the run wrote:

    >
    > > > prefs.js is a flat text file. *If you don't mind searching that file
    > > > to see if it is set and changing through a plain old write to the text
    > > > file that would work as well as anything else.

    >
    > > I don't think it is just that simple though, I think there can be
    > > multiple files, some for all users, some for default users, and
    > > another for current user. *Also, the file itself says Firefox will
    > > overwrite any changes made while Firefox is running, which may be a
    > > problem for me (especially with XP/Vista having multiple possible
    > > sessions open so it isn't even enough to just close it if running on
    > > the current session).

    >
    > Good point. *Firefox will write prefs.js on exit. *Well technically it
    > writes to prefs-1.js and then once all is good that file is renamed to
    > prefs.js. *And also a good point that an individual user could have
    > user.js file set with their home page.
    >
    > But here is a very simple solution to your problem given you are
    > trying to do this for kids. *Simply create a user.js file with the
    > preferences you want set for the kids (be it only the homepage setting
    > or more). *Then simply copy that over into the profile folder for each
    > of the kids. *It will override whatever is set in prefs.js. *I even
    > tried changing my home page and although it retains the new home page
    > for the duration of the session. *As soon as I close FF the homepage
    > in prefs.js is reset to the value I put in user.js (which is not
    > editable from within FF so no matter if the kids change it, it will
    > get reset each time to whatever Mom & Dad put in user.js).
    >
    > JB


    I was just thinking, you may want to set other preferences in user.js
    seeing this is for a child. Some that come to mind are the popup
    blocking preference, the history retention preference, the privacy
    preferences (so that they do not clear automatically on exit).
    Formdata preferences and password preference, perhaps even javascript
    if that was a consideration. Of course a child could still go and
    clear their history manually unless the parent took steps to lock down
    rights on places.sqlite to prevent them from deleting it - although we
    are talking about database transactions, not deleting a file so that
    probably wouldn't work anyways.

    At any rate, other preferences to consider in order to assist the
    parents in keeping their child safe and allowing them to check on them
    (again to ensure their safety). By putting them all in user.js it
    locks down those preferences.

    JB

+ Reply to Thread