Archive for the ‘mozilla’ Category

Some progress and some difficulties

March 1, 2009

I have managed to hook the extra option into the ‘right click’ menu. Below is the screenshot.

I referred to the code of Ubiquity in checking which context was being clicked on. I managed to filter the case such that the option only appears when a text field is being clicked on by using document.popupNode.onTextInput. I also found an example in mozilla documentation that can check whether an image is being clicked on by using instanceof Components.interfaces.nsIImageLoadingContent.

I have been trying to search for a similar example to check for a password field, but I couldn’t find one. I checked out a few websites using DOMinspector¬† and noticed that the ‘type’ for the password field is usually “password”,¬† so I used this as one of the condition to determine whether the option should be disabled.

var passValue = document.popupNode.value;
var isHidden = ! (gContextMenu.isContentSelection() || gContextMenu.onTextInput);
var isDisabled = !(type == “password” && passValue);

One possible problem is that the option will be enabled whenever there is value in the password field, i.e it is not empty. Previously, I had wanted to enable it only when there is a password saved on this webpage. But I haven’t been able to do that. Not sure if this is a good way to do it. Please feel free to point out to me if there is a better way.

I have been looking at the passwordmanager related code in the /toolkit/component. As expected, they are not easy to understand. I managed to find a related XPCOM interface nsiLoginManager which provides methods to manage logins.¬† PasswordManager.js seems to be leveraging on this interface to remove the logins. But there are other parts of the code that I couldn’t really understand the purpose.

Instead, I tried to directly make use of the nsiLoginManager interface. It seemed to be able to delete the passwords saved. What I am trying to do is to use the findLogins() method to find the related logins saved for this webpage that is being visited, and then delete using the removeLogin() method.

I am having difficulty in using the findLogins() to retrieve the password. The arguments needed to search for the logins are ‘hostname’, ‘formSubmitURL’ and ‘httpRealm’. As I am currently only working on logins obtained from HTML form, so httpRealm can be set to null. I haven’t been able to retrieve the hostname of the webpage. Tried ‘document.URL’ and ‘window.location’ and they don’t seem to work. As for the formSubmitURL, I tried using ‘document.popupNode.form.action’ but it returns a full path of the form which is different with what is required.

Lastly, I am not very sure whether using the interface directly would introduce bugs or break other parts of the code. If anyone has any idea, please feel free to let me know.