Version 10 (modified by, 9 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 WebKit uses a bit different syntax 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 attributes or methods of XXX to DOMWindow,

  • we need to modify WebCore/page/DOMWindow.idl to add the IDLs of the attributes or methods
  • we might need to modify WebCore/page/DOMWindow.{h,cpp} to add the C++ implementation of attribute getters and setters or 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 [
       ] 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 in 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.