LeoZ BloG

WebKit new attribute cheat sheet

This is a step list explaining how to implement a new HTML attribute for WebKit. I'm going to use QtWebKit for this execise but this approach is generic enough to be used for any other backend. Here is a note for building Qt and QtWebKit on Ubuntu Linux.

First, check if we could build WebKit and test the build with MiniBrowser.

Build WebKit

cd ~/Projects/qt_build/qt5/qtwebkit
sudo make install

Test WebKit

cd ~/Projects/qt_build/qt5/qtwebkit/Tools/MiniBrowser/qt
cd ~/Projects/qt_build/qt5/qtwebkit/bin

Now let's start implementing the new attribute. I'm going to add this new attribute to the HTML object element

The code we are going to modify lives here: Source/WebCore/html

Add token for the new attribute

In file HTMLAttributeNames.in add line:


Add rule for the new attribute

In file HTMLObjectElement.idl add line:

[Reflect, URL] attribute DOMString altsrc;

Add code to support the new attribute

In file HTMLObjectElement.h add:

void setAltSrcAttr(const String&);

In file HTMLObjectElement.cpp add a new method HTMLObjectElement::setAltSrcAttr :

void HTMLObjectElement::setAltSrcAttr(const String& value)
    dataLogF("alt src is: %s\n", value.utf8().data());

and change HTMLObjectElement::parseAttribute method to support the new attribute:

void HTMLObjectElement::parseAttribute(const QualifiedName& name,
                                       const AtomicString& value)

    else if (name == altsrcAttr)



Create a new file index.html

<object width="400" height="400" data="helloworld.swf" altsrc="myfile.bmp">

and place it somewhere

ls ~/Projects/html/index.html

Build and install WebKit with all our changes.

sudo make install

Run MiniBrowser.

cd ~/Projects/qt_build/qt5/qtwebkit/bin
./MiniBrowser ../../../../html/index.html

You should see this console output:

alt src is: myfile.bmp
Leonid Zolotarev 01 September 2013
blog comments powered by Disqus