Version 12 (modified by, 10 years ago) (diff)



The Web IDL is a language that defines how WebCore interfaces are bound to external languages such as JavaScriptCore, V8, ObjC, GObject and CPP. We need to write IDL files (e.g. XMLHttpRequest.idl, Element.idl, etc) to expose WebCore interfaces to those external languages. When WebKit is built, the IDL files are parsed, and the code to bind WebCore implementations and JavaScriptCore/V8/ObjC/GObject/CPP interfaces is automatically generated.

This page describes practical information about how the IDL binding works and how we can write IDL files in WebKit. The syntax of IDL files is fairly well documented in the Web IDL spec, but it is too formal to read:-) and there are several differences between the Web IDL spec and the WebKit IDL due to implementation issues.

Basics of the IDL

How the IDL binding works






IDL attributes


The [Supplemental] IDL helps WebKit modularization. The [Supplemental] IDL makes it possible to add XXX's APIs (e.g. XXX=WebAudio, WebSocket, Blob, GamePad, ...etc) without modifying code outside of WebCore/Modules/XXX/. This helps make XXX a "self-contained module".

Here is an example. Without the [Supplemental] IDL, if we want to add XXX's attributes or methods to DOMWindow,

  • we need to modify WebCore/page/DOMWindow.idl to add the IDLs of the XXX's attributes or methods
  • we need to modify WebCore/page/DOMWindow.{h,cpp} to add the C++ implementation of the attribute getters and setters or the method callbacks.

On the other hand, in the modularized world with the [Supplemental] IDL, we just need to modify the code under WebCore/Modules/XXX/, like this:

  • WebCore/Modules/XXX/DOMWindowXXX.idl
       interface [
           Supplemental=DOMWindow    // The attributes and methods of this interface are exposed as those of DOMWindow.
       ] DOMWindowXXX {
           attribute foo;
           void bar();
  • WebCore/Modules/XXX/DOMWindowXXX.h
       DOMWindowXXX::foo(...) { ... }   // The C++ implementation of the foo attribute getter.
       DOMWindowXXX::setFoo(...) { ... }   // The C++ implementation of the foo attribute setter.
       DOMWindowXXX::bar(...) { ... }   // The C++ implementation of the bar method callback.

As shown above, [Supplemental=DOMWindow] indicates that all the attributes and methods of DOMWindowXXX should be exposed on DOMWindow, but should be implemented in DOMWindowXXX. In this way, we can implement the attributes and methods without modifying code of DOMWindow.{h,cpp,idl}.

If you want to add APIs whose implementations are likely to be independent from WebCore, it is strongly recommended to put the APIs and .h/.cpp files into WebCore/Modules/XXX/ using the [Supplemental] IDL.