{"id":6,"date":"2009-04-23T17:02:52","date_gmt":"2009-04-24T00:02:52","guid":{"rendered":"http:\/\/blog.mozilla.org\/mrbkap\/?p=6"},"modified":"2009-08-15T03:03:21","modified_gmt":"2009-08-15T10:03:21","slug":"a-brief-history-of-xpconnect","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/mrbkap\/2009\/04\/23\/a-brief-history-of-xpconnect\/","title":{"rendered":"A brief history of XPConnect"},"content":{"rendered":"<p>XPConnect has been around since the beginning of Gecko. However, at the beginning, it was only the bridge between JavaScript <q>chrome<\/q> code (chrome code is the code running in the browser itself, as opposed to content, <q>web page<\/q> code). In those early days, XPConnect-using JavaScript code looked a lot different. Because XPConnect didn&#8217;t know about <code>nsIClassInfo<\/code> properties had to be addressed through their interfaces. So instead of saying <code>docShell.QueryInterface(Ci.nsIWebNavigation).canGoBack<\/code> one might say <code>docShell.nsIWebNavigation.canGoBack<\/code>. Obviously, this wouldn&#8217;t work for web pages, so there had to be another solution.<\/p>\n<p>That other solution was midl.exe. This was a Windows-only program that generated gobs and gobs of C++ glue to connect DOM-facing objects to JavaScript from the <abbr title=\"interface definition language\">IDL<\/abbr>. The generated stub code was put in <code>dom\/src\/*<\/code> and weighed in at over a megabyte. Because midl only ran on Windows, every time a developer wanted to change an <abbr>IDL<\/abbr> file, he would have to find a developer who ran on Windows to generate new stubs for the affected interfaces before proceeding.<\/p>\n<p>In 2001, John Bandhauer (jband) and <a href=\"http:\/\/blog.mozilla.org\/jst\/\">Johnny Stenback (jst)<\/a> started working to teach XPConnect about <code>nsIClassInfo<\/code> and to replace the midl generated code by simply calling functions through <code>xptcall<\/code>. This resulted in a significant codesize reduction and allowed people to change idl files, even if they didn&#8217;t run Windows. Furthermore, in order to support some of the weirder aspects of the DOM (such as setting <code>window.location<\/code> changing the currently shown page) the <code>nsIXPCScriptable<\/code> interface was fleshed out, allowing any C++ code to interact nicely with JavaScript code, instead of just the DOM code. For example, the storage code in Gecko now provides a nice enumeration API for JS to use for-in loops to iterate over query results. Without the magic of <code>nsIXPCScriptable<\/code>, JS would be forced to use uglier function calls.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>XPConnect has been around since the beginning of Gecko. However, at the beginning, it was only the bridge between JavaScript chrome code (chrome code is the code running in the browser itself, as opposed to content, web page code). In those early days, XPConnect-using JavaScript code looked a lot different. Because XPConnect didn&#8217;t know about [&hellip;]<\/p>\n","protected":false},"author":149,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/mrbkap\/wp-json\/wp\/v2\/posts\/6"}],"collection":[{"href":"https:\/\/blog.mozilla.org\/mrbkap\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mozilla.org\/mrbkap\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/mrbkap\/wp-json\/wp\/v2\/users\/149"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/mrbkap\/wp-json\/wp\/v2\/comments?post=6"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/mrbkap\/wp-json\/wp\/v2\/posts\/6\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/mrbkap\/wp-json\/wp\/v2\/media?parent=6"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/mrbkap\/wp-json\/wp\/v2\/categories?post=6"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/mrbkap\/wp-json\/wp\/v2\/tags?post=6"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}