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 **

1
2
3
4
5

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

** Test WebKit **

1
2
3
4
5
6
7

cd ~/Projects/qt_build/qt5/qtwebkit/Tools/MiniBrowser/qt
qmake
make
cd ~/Projects/qt_build/qt5/qtwebkit/bin
./MiniBrowser

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:

++
1
2
3

altsrc

** Add rule for the new attribute **

In file
HTMLObjectElement.idl
add line:

++
1
2
3

[Reflect, URL] attribute DOMString altsrc;

** Add code to support the new attribute **

In file
HTMLObjectElement.h
add:

++
1
2
3

void setAltSrcAttr(const String&);

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

++
1
2
3
4
5
6

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:

++
1
2
3
4
5
6
7
8
9
10
11
12

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

else if (name == altsrcAttr)
setAltSrcAttr(value);

...
}

** Test **

Create a new file index.html

1
2
3
4

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

and place it somewhere

1
2
3

ls ~/Projects/html/index.html

Build and install WebKit with all our changes.

1
2
3
4

make
sudo make install

Run MiniBrowser.

1
2
3
4

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

You should see this console output:

1
2
3

alt src is: myfile.bmp

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×