KonquerorIt is an embedded browser that runs mainly on Linux and BSD operating systems. I used it for a while and let me see it.
1 Konqueror/embedded Overview
Currently, embedded browsers have gradually become standard configurations for high-end mobile phones and PDAs. Most of the existing embedded browsers are commercial, such as opera and MS explorer, while Konqueror/embedded is a free software compliant with the GNU terms. Konqueror/embedded is derived from Konqueror, a browser in KDE, a well-known desktop operating environment, for embedded Linux. Konqueror/embedded inherits the KHTML, SSL, Javascript, and other content in Konqueror, simplifies the definition of many classes in Konqueror, and removes the dependency on KDElib, to adapt to porting and running on different embedded platforms. Both are based on Qt, so Konqueror/embedded can also run in the Qt/X11 environment. Konqueror/embedded fully supports HTML4 and css1 (partially supports css2), JavaScript (ECMAScript 262), cookies, SSL, and IPv6; supports and manages XBEL-compatible bookmarks, and can well support Chinese Web browsing; can use Konqueror/embedded as a flash player, pppdialer or file manager. 2. Composition of Konqueror/embedded
Figure 1 Konqueror/embedded the hierarchy of Konqueror/embedded consists of the underlying network connection, graphical user interface, and KHTML-based engine.
2 I/OSlaves
The underlying communication protocol implementation of the I/OSlaves implementation process is implemented based on the KIO/Slave mechanism. The GUI uses the Kparts component technology and the basic components in Qt; KHTML, the core of Konqueror/embedded, uses the APIS provided by the Document Object Model (DOM) and mounts the javascript engine, CSS parser, and rendering engine on the DOM tree.
3 key technologies in Konqueror/embedded
3.1 Implementation of underlying communication protocols-I/OSlave Mechanism
Use the I/OSlaves System in KDE to access various data. Konqueror/embedded follows this method to implement complete browser functions through the I/OSlaves and inter-process pipeline communication mechanism. I/OSlaves is also used in the Konqueror Based on Qt/X11. Simply put, I/OSlaves are the processes that obtain files or directories from the network. They rely on the Desktop communication Protocol DCOP (Desktop Communications Protocol) to communicate with other processes. However, the implementation of DCOP depends on the X11 ICE (Inter Client Exchange) Library. Porting a large X11 lib on an embedded platform is unrealistic. Konqueror/embedded uses another inter-process communication mechanism: the main process and other I/OSlaves sub-processes communicate through the pipeline (pipe.
After KDE1.X, KDE's file manager and Konqueror and other applications have the network transparency feature, and Konqueror/embedded also inherits this feature. Konqueror/embedded identifies both local files and remote files by using URLs (Uniform Resource Locator. Network transparency allows application users to process remote files in the same way as local files. The KDE file selector can list remote directories by means of FTP, SMB, or Webdav (in KDE3. Network transparency and I/OSlaves mechanisms are implemented by KIO classes. The KIO class provides almost all file management functions. KIO javasnetaccess provides simple synchronization access functions such as file download, upload, and Creation or Deletion of temporary files. This is a blocking call method. If you use Konqueror/embedded to download data on the network, the current process will be blocked before the data is fully loaded. After the data stream is fully loaded, the webpage can be rendered or refreshed again. KIO merge Job provides complex asynchronous functions, including opening, creating, copying, deleting, renaming, and other operations related to files or directories. Konqueror/embedded relies on KIO merge Job to Implement Asynchronous webpage access. Once a job is started, it runs in the background and does not block the parent process. Various protocols in Konqueror/embedded, such as HTTP and FTP, are implemented by some independent processes. These independent processes are called Slaves. Slave is a subclass of KIO worker lavebase. KIO worker Slavebase defines some virtual functions. Different Slave must overload these interfaces. Slave exists in the system as a function library and is provided for corresponding job calls. Slaveinterface runs on the application end (job), and Slavebase runs on the Slave end. Generally, the created job is in the queue. When the event is cyclically processed to the job, KIO allocates an appropriate Slave for the job in the queue. Slave management and scheduling are executed by the scheduler. scheduler adds the job Queue to the appropriate protocol (Slave. When the job ends, the Slave process does not stop immediately and will wait for a certain period of time in the idle area. The advantage of this mechanism is that if several jobs access the same host, you do not need to restart the new process and do not need to shake hands again. For the same network protocol at the same time, only three Slave processes can be started in the system. If the number of jobs that reference this protocol exceeds this limit, redundant jobs will be added to the queue until idle Slave processes are available. Figure 2 describes the implementation of the underlying protocol (Slave) and task (job) in Konqueror/embedded.
3.2implementation of Gui-Kparts
Component Technology (1) components in Konqueror/embedded
Although the Konqueror/embedded UI directly inherits QMainWindow, the functions and layout of the UI are implemented by components, and QMainWindow is only the host of these components. When Konqueror/embedded starts initialization, it first loads a special component named KHTMLPART. KHTMLPART is responsible for loading and managing other components (such as Kflashpart and Kplaintextpart. The Kparts component programming technology can extend the functions of Konqueror/embedded without modifying the underlying code. It also enhances the customization of Konqueror/embedded. Konqueror/embedded embeds Web browsers, flsahpalyer, text editors, and simple audio players as Kparts components into the main window. Kparts component programming technology allows applications that require the same function to share a component by embedding graphical components in the application window. The Kparts component consists of read-only components and read/write components. The ReadOnlyPart class of the read-only component provides a public framework for any type of viewer. If a File URL is provided, all these viewers can display the file and prevent any modifications to the file. In Konqueror/embedded, Web browsers, flashpalyer, and simple audio players all belong to read-only components. The ReadWritePart class is an extension of ReadOnlyPart. It adds the possibility of modifying and saving documents, such as the text editor embedded in Konqueror/embedded. It is a read/write component.
(2) component implementation technology in Konqueror/embedded
Taking the Kplaintextpart component in Konqueror/embedded as an example, the component must consist of three elements, including window components, component functions, and user interfaces. The window component must be a child of QWidget. The text editor in Konqueror/embedded inherits from the QmultiLineEdit class. Besides the window component, the component also needs to provide functions, in Konqueror/embedded, the text editor provides additional features such as forward, backward, cut, copy, and full selection. Of course, it also provides user interfaces for accessing those features (operations and XML files ). The text editor in Konqueror/embedded only provides menu items for the window component function. Define the layout of the user interface in the XML format file Kplaintextpart. rc, which is separate from the application code. When the text editor is embedded in Konqueror/embedded, the component menu is merged with the original user interface using the XMLGUI technology.
The text editor component in Konqueror/embedded is shown in 3.
Figure 3 the main feature of the Kparts component in the text editor component structure is its reusability. To achieve this, you must compile the component into the shared library. Applications that want to dynamically open the shared library use the KLibLoader class. Locate, open, and call the initialization function of the KLibLoader processing database. The initialization function is the entry point of the database. This initialization function creates a factory where components are created. The specific implementation method 4 is shown in.
3.3implementation of the khtml Rendering Engine
As the core of Konqueror/embedded, The KHTML engine contains seven sub-directories, dom, xml, html, css, rendering, misc, and ecma. The functions of these sub-directories are shown in step 5.
From the functional structure, we can see that the KHTML engine of Konqueror/embedded is built based on the DOM technology of XML, which is similar to the architecture of most browsers. DOM is a collection of nodes or information fragments organized by hierarchies. In this hierarchy, you can use the navigator to search for specific information. At the same time, DOM also provides a set of APIs that can be implemented using JAVA, C ++, or C.
Currently, the most common methods for parsing XML files are: Document Object Model (DOM, Document Object Model) and Simple API for XML (SAX, Simple API for XML), JDOM, and Java APIs for XML Parsing (JAXP, Java API for XML Parsing ). They have their own advantages and weaknesses, so they are applicable to different occasions. The DOM technology is used in Konqueror/embedded. It provides interfaces and methods to add and delete the nodes of the constructed DOM tree, and even delete several parts of the tree. You can also arrange the tree and add new branches. However, because DOM builds a tree where the entire document resides in the memory, if the document is large, it requires a huge amount of memory, which is a challenge for embedded devices with little memory. In addition, DOM constructs each node and element of the entire document. If you only care about a part of the content
Figure 4 component creation steps Figure 5 composition of Konqueror/embedded will cause a waste of resources. Meanwhile, DOM loads the entire document before the user obtains control. If the document is large, there will be significant latency. The biggest advantage of using DOM technology to parse HTML/XML in Konqueror/embedded is that DOM automatically saves the parsed documents, you do not need to parse the document again when you want to browse the history.
Konqueror/embedded adopts the DOM2 level specification, which is divided into DOM2 Core and DOM2 HTML. Compared with DOM Level1, DOM2 adds some interfaces and methods for processing XML documents:
View, which provides the link between the view and the document;
Style sheet provides methods to access and modify a style sheet;
Cascading Style Sheets (CSS2), providing methods compatible with CSS2;
Events, which provide interfaces for various events;
Document traversal provides an interface to traverse the document hierarchy;
Document range provides interfaces for splitting document ranges.