mozilla-b2g/gaia — pull request #7753 by janjongboom (2013-01-23 14:07:05+00:00)
Title: Enable remote debugging of Firefox OS devices through Weinre

This is based on the work that Kevin Grandon put into this and shared on the mailing list. In this patch we allow users to build a profile that has Weinre support enabled. Weinre is a remote debugger that allows DOM inspection and javascript execution of a mobile device through a developer machine. By enabling this it gets a lot easier to do HTML/CSS/JS debugging within the emulator or actual device without constantly re-flashing.

Want a video about the coolness of this? [Use Weinre with Firefox OS](http://youtu.be/UiZSEkdAKAA).

**Changes**
* There is a new make option called `WEINRE`, which value has to be set to `host:port` of the machine running the Weinre server.
* Based on this option a file called `system/resources/settings.json` is created with specified whether Winery should be enabled and with what options (a.t.m. only host).
* In `system/index.html` a new file is being loaded that checks the settings file and based on this file loads the winery client script (or does nothing).
* To also support applications to be debugged through Winery the script intercepts all frame creation and appends the Winery options to the src attribute (hash). This is done because of the way Firefox OS does framing of new applications, and the src attribute can be used reliably.
* Client applications can include the winery_client script from `shared/js` that checks whether the hash contains the Winery options, and if so also loads the Winery script. This way each app has a separate session, which matches the way Firefox OS is doing it.

**Potential issues**
* Adding a new file in system/index.html might increase loading time, however the script is deferred so it shouldn't make a lot of difference.
* The script in system/index.html is also loaded when winery support was not specified in make. Don't know how to change that.

**Issues**
* Appending the winery script to the body has a timing issue, remove the `setTimeout` call in the script and you'll see. The current timeout seems fine in the emulator but it's not nice.
* I want to auto-load the winery_app.js script in all applications. However I cannot find a way to do DOM postprocessing for apps. If there is someone with a solution that would be awesome, because manually adding the script isn't ideal. Might end up in GIT etc.