Firebug 1.7: Architecture Refactoring

From FirebugWiki
Revision as of 17:00, 14 September 2010 by Johnjbarton (Talk | contribs) (Detailed Work Plan For JS Reimplementation)

Jump to: navigation, search

Problems to be Solved by Refactoring

  • Prepare to support remote debugging for mobile and multiprocess browser
    • Server side will be headless
    • Client side will have no access to Firefox data
  • Allow simpler and more robust extensions
    • Javascript oriented loading, no XPCOM loader required
    • Isolation and concentration of extension code
  • Clean up expedient code and clarify the implementation
    • relation to platform window system
    • relation of panels and modules
    • prepare/exploit shift to jetpack

Proposed Changes

Separate Modules and Panels

Broadly speaking Mike Collins' architecture for remote Firebug puts the module code in the server and the panel code in the client (UI side). The Firebug 'context' object (TabContext.js) is passed over the wire between them using CrossFire.

The first step in that direction is to divide all of the source into module and panel files. For example we might have debuggerModule.js and debuggerPanel.js. Then firebug.js would be divided between module dispatch and panel dispatch (dispatchModules.js and dispatchPanels.js?). The API between these objects would be the API CrossFire would remote.

Issue: file names vs folders

I understand the natural appeal of module/debugger.js and panel/debugger.js vs debuggerModule.js and debuggerPanel.js. However in my experience one needs to write with one kind of module plus panel much more often than all of the panels or all of the modules. Creating a subdirectory for each feature, eg debugger/module.js make lots of small folders. Any scheme where the folder is used to disambiguate makes lots of tools hard to use because you end up with a lot of UI selections like "module.js" or "debugger.js" and you can't tell what it means. That is how I ended up with debuggerModule.js and debuggerPanel.js: unambiguous naming with the feature first so alphabetic sort groups by feature.

Components replaced by SharedObjects

We currently have 5 XPCOM components. We need to create two more, Firebug and DOMWindowWatcher (see below). Since these are all in Javascript, the XPCOM infrastructure only exists to arrange common access between Firebug windows. By creating a single SharedObject XPCOM component we can reduce the amount of boiler plate code and clarify the design. This will also prepare for in-place JS editing and dynamic update features in future.

Issue: SharedObject API

Leverage work by CommonJS

This would put us on the same path as jetpack proposals.

As far as I know the CommonJS, as well as Mozilla platform Components.utils.module, supports common code loading, but we want common object sharing. So there may be some additional work on API.

Recode TabWatcher -> DOMWindowWatcher

I think we now pretty much understand TabWatcher, but it is still very heuristic and relies on Firefox idiosyncrasies that can change. Chromebug has its own watcher and even more guesses about the platform. Let's replace all of that with a clean abstraction for nsIXULWindow and nsIDOMWindow lifetime event notifications. Then put it in a SharedObject so we only need one per application and we have clearer API.

This requires platform support

Issue: DOMWindowWatcher API

Ideally we would mimic/influence jetpack here, as they have a subset of the same problem.

Sandboxed Extension Loading

By re-applying the module loading technology we can create a jetpack-like environmental wrapper for Firebug extensions. The extensions would be slightly simpler because they would just be zip files. They would be slightly more robust, because they would be evaled in a scope that only contains Firebug.

Refactor debugger.js <-> firebug-service.js API

Ultimately we want debugger.js to split into a front-end and back-end, with the back-end implementing Crossfire's V8-like protocol. So a start is to shift work between debugger.js and firebug-service.js to be an V8-like API, and use firebug-service.js as an adapter between V8-like protocol and Mozilla jsd. (Note that JSDebugv2 aka js::dbg should have this kind of API).

Workplan items (not yet in order)

  1. Define a new interface Firebug.Middle
    • Functions equivalent to the Crossfire protocol
  2. Define new module mozilla-backend.js
    • Implements Firebug.Middle using jsd
  3. Define new module crossfire-client.js
    • Implements Firebug.Middle using Crossfire
  4. Define new Firefox extension Crossfire-Mozilla
    • Implements Crossfire server, calls mozilla-backend.js
  5. Define new Chrome extension Crossfire-Google
    • Implements Crossfire server, calls google-backend.js
  6. Reimplement debugger.js to calls into Firebug.Middle instead of fbs.
    • At load time Firebug.Middle is implemented using either mozilla-backend.js or crossfire-client.js
  7. Implement FBTest.Middle
    • js unit tests that call into Firebug.Middle
    • FBTest configuration to test mozilla-backend.js and crossfire-client.js looping through server

Detailed Work Plan For JS Reimplementation

  1. Milestone BTI: Interface, Unit Tests, firebug-service encapsulation
    1. Preliminary: move mozilla-specific code from debugger.js to fbs, split out script.js (front end).
    2. Define (initial) BrowserToolsInterface (BTI)
    3. Create unit tests for BTI
    4. Implement BTI with mozilla-backend.js based on firebug-service.js
      • This will only last for FF4.1, it can be a hack job.
  2. Milestone Script.js: in process use of BTI in Firefox
    1. Insert BTI into script.js, calls mozilla-backend.js
      • FBTests pass, the result will be first ship of BTI
  3. Milestone CrossUnit: Unit tests via CrossFire
    1. Implement Crossfire server to BTI calls
    2. Implement Crossfire client from BTI calls
    3. Drive unit tests end to end
  4. Milestone Crossfox: Crossfire from Firefox to Firefox
    1. script.js to BTI to CrossFire Client to Server to mozilla-backend.js
    2. FBTest pass
    3. Fennec prototype
    • the result will be first user value add
  5. Milestone Modularity: script.js usable in Firebug Lite and Firefox
    1. Preliminary: modularity model.
    2. script.js in Firebug Lite -> Firefox mozilla-backend.js
  6. Milestone ChromeUnit: Crossfire into V8
    1. Implement V8 server (or not to start).
    2. Drive unit tests into Chrome / V8
  7. Milestone ChromeScript: Firebug Lite JS debug in Chrome
    1. Firebug Lite script.js drives Chrome/V8
    • Result will be user value add Chrome JS debug with Firebug.

How to participate