Let us first begin by saying who we are and why we write this. We are a group of 4th year students in our last term of our Computer Science degrees. We are currently enrolled in a course where the goal is to maintain an existing piece of software. The software that our group chose to maintain is the open source project known as Mozilla. Mozilla is the code name for Netscape's open source browser. Our maintenance task was to upgrade the current SaveAs in the File pull down menu so that it saved the images associated with the HTML document as well. This increased functionality would allow users to view web pages while offline.
When we started working with Mozilla, the group was unsure of where to start. Since Mozilla is very object oriented there are numerous layers that the coder can view code. Because of this complexity our group (which took on the name Mozilla One) started searching through the code and coming to the conclusion that we were working at the wrong level or in the wrong part of the code. In one of our phases Mozilla One spent a huge chunk of time working with the Editor's file save. The knowledge we gained from the Editor's File Save was enlightening however it did not accomplish what we had hoped. You could say that this stumbling block was our largest.
The reason for this document is to help others who are trying to work with the beast known as Mozilla and to share with you our findings in the Editor. In particular we wish to discuss the Editor's File Save so that those who come after us do not have to waste their time learning what is going on.
Let us first talk about our understanding of the Editor. There is an object contained within the Editor which is called the D.O.M. (Document Object Model). It is an object that represents the HTML document that is currently being viewed to the screen. There are functions that allow access to the DOM so that information about the HTML document can be gained. There are also functions that allow the DOM to be modified. In the Appendix later on will be some example code of how to use these functions to gain access to the DOM.
One of the reasons that Mozilla One looked at the code in the Editor is because the existing code for the SaveAs in the main browser had been broken and was "being fixed." One of the things about an open source project is that there are many hands and minds touching the code, and if those people no longer have an interested in the code that they broke then its possible that the bug will stay around for a while. This was the experience that Mozilla One was faced with. We needed to work with the main browser's file save but since it was broken we had to wait -- fixing the bug ourselves seemed an ominous task.
The code that we were dealing with could be found in mozilla/editor/base/nsEditor.cpp. In this file there is a function called nsEditor::SaveFile(). In the appendix there is a step by step overview of how we went about changing image tags in the DOM in the section of the code marked "MODIFYING DOM CODE." Our code that we implemented is not specific to this function. It is possible to change the DOM any where in the Editor as long as you get a pointer to it.
nsCOMPtr<nsIDOMDocument> doc; nsresult res = GetDocument( getter_AddRefs(doc)); if ( NS_FAILED(res)) return res; if (!doc) return NS_ERROR_NULL_POINTER;
The above code is what is necessary to get a hold of the DOM. Once we have a pointer to the DOM we can begin to manipulate the DOM.