Showing posts with label browser. Show all posts
Showing posts with label browser. Show all posts

Saturday, June 16, 2007

Changing the PATH from a Firefox extension



Since (almost) everything is ready (even my new cool XUL sidebar for recommendation list), I must deal with the install process, don't I?
Everything's ok, all the things are in their place (thanks to the .xpi packaging) except for the BDB XML dlls that have to be visible to the jvm in the browser. We have two options: either we copy the dlls to Program Files/Mozilla, either we set the PATH environment variable to extension directory, where Firefox unzips the .xpi.
Yep, I chose the second...
It's easy to execute a batch file from a firefox extension, you just use a

Components.classes["@mozilla.org/process/util;1"] .createInstance(Components.interfaces.nsIProcess)


initialize it with your script and then run it! (actually, if it wasn't for the extension developer's extension code, I wouldn't have known that now...)

But... how should we write the script? Since I couldn't find out how to execute a script at the moment of the extension install (that is, only once in the lifetime of the extension), I had to run it every time I open the browser so the script is a little more complicated: it must check the PATH for the existence of the directory path I want to add, and, if it's not there, put it. I found out from Merlyn that I can write a batch file in Javascript and, with a little help from Microsoft Tech Net I managed to produce this file:

//command line arguments
var args = WScript.Arguments
var dir = args(0);
//get the env vars
var objShell = WScript.CreateObject("WScript.Shell");
var colUsrEnvVars = objShell.Environment("User");

//TODO: test if path exists, else, create it
var path = colUsrEnvVars("PATH");

//TODO: should use regular expressions
var pathToSearch = ";" + path + ";";
var dirToSearch = ";" + dir + ";";
var index = pathToSearch.indexOf(dirToSearch);

if (index < 0) {
WScript.echo("update...");
var newValue = path + ";" + dir;
colUsrEnvVars("PATH") = newValue;
}

called from this bat:

set DIR_NAME=%1
set SCRIPT_PATH=%2
cscript //nologo "%SCRIPT_PATH%" "%DIR_NAME%"

with DIR_NAME and SCRIPT_PATH passed from the firefox code to match the firefox extension installation paths and the path to the js script.

All fine, until I got the wonderful error:

Execution of the Windows Script Host failed. (Not enough storage is available to complete this operation. )

but thanks God, other people got it too, before myself.

Now it sets the PATH but I still have some issues: the update takes oooooh so long (I kind of stare at the bloody console waiting for it to finish) and, at the first run (when PATH gets actually set), the jvm does not 'see' the PATH, it still fails (maybe it loads before I get to set the path)... A browser restart does it, though, so, until I have some spare time, I guess it's ok in the current state...

P.S: ignore all the "we"'s in this post: I'm actually alone in this, but I got used to the "we" from writing the paper associated to this work.

Wednesday, June 13, 2007

How to shoot yourself in the foot...



How to shoot yourself in the foot in a browser extension environment (let's say... Firefox)?
You first device a niiiice gun overlay, in XUL, styled with CSS, with a trigger interface in like 346524563425 languages using the wonderful firefox i18n mechanism, you connect your gun to some serious killing machine (preferably written in Java) and then, when you're finally done with all these and you shoot your gun:

Security check failed: permission denied to access 'body.lowerbody.foot&side=left' from content at "chrome://gun/content/bigshotgun.xul".

Thursday, February 8, 2007

Updating

There is a line in American Beauty which I love: "In life never trust anyone but yourself" - this is a piece of wisdom passed by Carolyn Burnham to her daughter Jane after Carolyn and Lester argue at dinner (that scene when he throws the asparagus plate at the wall).
I would put it another way: "In software industry never trust any code but your own!". A few days ago I installed the new and fabulous update of Firebug. It's a great extension, indeed "Web development evolved", but the 1.0 version, though is cooler than you ever thought you'll see, it crashes my browser! 1.0.1 is now available too (and I thought: "oh, goodie, bug fix"), but it does the same. Whhhhyyyy? :(( Not to mention that it lacks functionality that the previous version had: console options that allowed me to see my messages (not only errors and warnings) sent from the javascript code inside an extension using Mozilla's console service.
But, until writing my own firebug (:D), I'm still thinking if I should stop using it (as a protest) or just "Restore previous session" again and again and again...


P.S. this post should have been written last night but there was a power failure hence no internet. This seems buggy as well...